|
| 1 | +# M5 — Plugins (manifest + hash pin) + Skill tool + CLI integration |
| 2 | + |
| 3 | +> **Status**: ✅ Foundation shipped — sandbox subprocess deferred to M5.1 |
| 4 | +> **Branch**: `feat/m5-plugins-skill-tool-integration` |
| 5 | +
|
| 6 | +## Shipped |
| 7 | + |
| 8 | +| Module | Lines | Tests | |
| 9 | +|---|---|---| |
| 10 | +| `plugins/manifest.ts` | Manifest parser, SHA-256 hash pinning, trust state JSON, installLocal(), discoverPlugins() with hash drift detection | 175 | 12 | |
| 11 | +| `skills/tool.ts` | `Skill` ToolHandler factory — agent invokes by qualified name, skill body returned as tool_result | 60 | 6 | |
| 12 | +| `apps/cli/src/repl.ts` | Wires memory + skills + output styles + mode/permissions/hooks/approval into the REPL agent loop | +50 | (smoke) | |
| 13 | +| **subtotal** | **~285** | **18** | |
| 14 | + |
| 15 | +Across whole project: 258 tests / 4 skipped / 0 failed (was 240). |
| 16 | + |
| 17 | +## What the CLI REPL now does end-to-end |
| 18 | + |
| 19 | +When user types a message, agent receives: |
| 20 | +1. **System prompt** = default + memory (DEEPCODE.md + ~/.deepcode + AGENTS.md + rules/) + skills description block + output style append |
| 21 | +2. **Tools available** = 6 P0 + `Skill` tool (if any skills loaded) |
| 22 | +3. **Per tool call** = goes through `dispatchToolCall()`: |
| 23 | + - Mode policy (`plan` blocks writes, `dontAsk` rejects ask, etc.) |
| 24 | + - Permission rules (allow/ask/deny patterns) |
| 25 | + - PreToolUse hook chain (JSON output can override) |
| 26 | +4. **`ask` verdict** → REPL prompts user `[y]es/[n]o` |
| 27 | +5. **PostToolUse hook** fires after every tool execution |
| 28 | +6. **Snapshots** captured pre/post Edit/Write for future rewind |
| 29 | + |
| 30 | +## What's NOT in M5 |
| 31 | + |
| 32 | +Per `docs/design/plugin-security.md` we have a deliberate gap: |
| 33 | + |
| 34 | +> **Plugin sandbox subprocess (RPC over stdio) — M5.1.** |
| 35 | +> Right now `discoverPlugins()` finds installed plugins but the agent loop does |
| 36 | +> NOT yet *run* their contributed code in-process. They're discovered, their |
| 37 | +> manifest is verified, but their JS/skills/hooks/MCP servers aren't yet |
| 38 | +> registered into the active registries. That wire-up needs the sandbox |
| 39 | +> subprocess design from `plugin-security.md` §3.5 to land first — running |
| 40 | +> arbitrary plugin code in the host process is the exact RCE vector the design |
| 41 | +> doc enumerated as A1 / A3. |
| 42 | +
|
| 43 | +What works **today** safely: |
| 44 | +- Local install: `installLocal({ sourcePath })` copies + records trust + hashes |
| 45 | +- Discovery on startup: `discoverPlugins()` finds plugins, flags hash drift, returns enabled list |
| 46 | +- Trust manifest at `~/.deepcode/plugins-trust.json` tracks what was installed |
| 47 | +- Hash-pinning catches tampered plugins |
| 48 | + |
| 49 | +What's deferred to M5.1: |
| 50 | +- Subprocess sandbox via bwrap/sandbox-exec (depends on §3.9a sandbox subsystem — M3.5) |
| 51 | +- RPC stdio bridge between host and plugin subprocess |
| 52 | +- GitHub URL install (`gh:user/repo`) |
| 53 | +- Marketplace index + ed25519 signature verification |
| 54 | +- Revoke list pull |
| 55 | +- Loading plugin-bundled skills/agents/hooks into the active registry |
| 56 | + |
| 57 | +## Skill tool |
| 58 | + |
| 59 | +`makeSkillTool(skills)` returns a `ToolHandler` that: |
| 60 | +- Looks up skill by `qualifiedName` (e.g. `code-review` or `plugin-x:do-thing`) |
| 61 | +- Returns the SKILL.md body as tool_result |
| 62 | +- Lets the LLM "decide to invoke" via natural tool calling |
| 63 | +- Errors clearly when skill not found (lists known skills) |
| 64 | + |
| 65 | +Auto-trigger via description matching is implicit — by including `buildSkillsDescriptionBlock(skills)` in the system prompt, the model sees `## Available skills - **code-review** — Review diff for bugs.` and tool-calls Skill when the user asks. |
| 66 | + |
| 67 | +## Tests added |
| 68 | + |
| 69 | +- `plugins/manifest.test.ts` — 12 tests covering: manifest validation, hash determinism, hash sensitivity (manifest + SKILL.md changes), trust round-trip, install, discovery, drift detection, disabled list, untrusted skip |
| 70 | +- `skills/tool.test.ts` — 6 tests covering: tool shape, known skill lookup, args appending, plugin-qualified names, missing skill, missing arg |
| 71 | + |
| 72 | +## Verified |
| 73 | + |
| 74 | +``` |
| 75 | +pnpm typecheck → green |
| 76 | +pnpm build → green |
| 77 | +pnpm test → 258 passed / 4 skipped / 0 failed |
| 78 | +pnpm format:check → conformant |
| 79 | +``` |
| 80 | + |
| 81 | +CLI smoke: `node apps/cli/dist/cli.js --version` → `0.1.0`. Full REPL run not validated end-to-end (would need a live DEEPSEEK_API_KEY); the wiring is type-checked and the unit tests for each piece pass. |
| 82 | + |
| 83 | +## Why deferred to M5.1 is the right call |
| 84 | + |
| 85 | +`docs/design/plugin-security.md` was explicit that running plugins in the host process is the **primary** RCE vector. M5 ships the trust/hash machinery as a foundation, but explicitly **does not** wire plugin code into the live agent — because doing so without sandbox is the headline security mistake we warned ourselves about. The honest M5 is: discover and verify, don't execute. |
| 86 | + |
| 87 | +The user can still benefit from skills (file-based, no code) — those work via the M4 user/project layers — they just don't yet auto-load from installed plugins. |
0 commit comments