@flyingrobots/graft 0.3.5 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/ARCHITECTURE.md +386 -0
  2. package/CHANGELOG.md +69 -0
  3. package/CODE_OF_CONDUCT.md +65 -0
  4. package/README.md +153 -17
  5. package/bin/graft.js +4 -11
  6. package/docs/ADVANCED_GUIDE.md +49 -0
  7. package/docs/CLI.md +43 -0
  8. package/docs/GUIDE.md +321 -32
  9. package/docs/MCP.md +44 -0
  10. package/package.json +17 -4
  11. package/src/adapters/node-fs.ts +4 -0
  12. package/src/adapters/node-git.ts +47 -0
  13. package/src/adapters/node-process-runner.ts +27 -0
  14. package/src/cli/index-cmd.ts +86 -0
  15. package/src/cli/init.ts +808 -57
  16. package/src/cli/main.ts +437 -0
  17. package/src/contracts/capabilities.ts +341 -0
  18. package/src/contracts/causal-ontology.ts +622 -0
  19. package/src/contracts/causal-surface-next-action.ts +18 -0
  20. package/src/contracts/output-schemas.ts +1169 -0
  21. package/src/git/diff.ts +25 -21
  22. package/src/git/target-git-hook-bootstrap.ts +56 -0
  23. package/src/hooks/posttooluse-read.ts +21 -74
  24. package/src/hooks/pretooluse-read.ts +20 -56
  25. package/src/hooks/read-governor.ts +95 -0
  26. package/src/hooks/read-messages.ts +53 -0
  27. package/src/mcp/burden.ts +123 -0
  28. package/src/mcp/cache.ts +51 -0
  29. package/src/mcp/cached-file.ts +10 -8
  30. package/src/mcp/context.ts +67 -2
  31. package/src/mcp/daemon-control-plane.ts +554 -0
  32. package/src/mcp/daemon-job-scheduler.ts +279 -0
  33. package/src/mcp/daemon-repos.ts +216 -0
  34. package/src/mcp/daemon-server.ts +396 -0
  35. package/src/mcp/daemon-worker-pool.ts +310 -0
  36. package/src/mcp/daemon-worker-process.ts +52 -0
  37. package/src/mcp/metrics.ts +108 -1
  38. package/src/mcp/monitor-tick-job.ts +99 -0
  39. package/src/mcp/persisted-local-history.ts +1246 -0
  40. package/src/mcp/persistent-monitor-runtime.ts +549 -0
  41. package/src/mcp/policy.ts +84 -0
  42. package/src/mcp/receipt.ts +82 -12
  43. package/src/mcp/repo-concurrency.ts +318 -0
  44. package/src/mcp/repo-state.ts +777 -0
  45. package/src/mcp/repo-tool-job.ts +302 -0
  46. package/src/mcp/run-capture-config.ts +33 -0
  47. package/src/mcp/runtime-causal-context.ts +72 -0
  48. package/src/mcp/runtime-observability.ts +219 -0
  49. package/src/mcp/runtime-staged-target.ts +161 -0
  50. package/src/mcp/runtime-workspace-overlay.ts +255 -0
  51. package/src/mcp/semantic-transition-guidance.ts +60 -0
  52. package/src/mcp/semantic-transition-summary.ts +130 -0
  53. package/src/mcp/server.ts +704 -45
  54. package/src/mcp/stdio-server.ts +12 -0
  55. package/src/mcp/stdio.ts +2 -5
  56. package/src/mcp/tools/activity-view.ts +325 -0
  57. package/src/mcp/tools/causal-attach.ts +67 -0
  58. package/src/mcp/tools/causal-status.ts +58 -0
  59. package/src/mcp/tools/changed-since.ts +13 -11
  60. package/src/mcp/tools/code-find.ts +164 -0
  61. package/src/mcp/tools/code-refs.ts +466 -0
  62. package/src/mcp/tools/code-show.ts +252 -0
  63. package/src/mcp/tools/daemon-monitors.ts +14 -0
  64. package/src/mcp/tools/daemon-repos.ts +22 -0
  65. package/src/mcp/tools/daemon-sessions.ts +14 -0
  66. package/src/mcp/tools/daemon-status.ts +12 -0
  67. package/src/mcp/tools/doctor.ts +45 -2
  68. package/src/mcp/tools/explain.ts +4 -0
  69. package/src/mcp/tools/file-outline.ts +7 -3
  70. package/src/mcp/tools/git-files.ts +73 -0
  71. package/src/mcp/tools/graft-diff.ts +12 -4
  72. package/src/mcp/tools/map.ts +136 -0
  73. package/src/mcp/tools/monitor-pause.ts +18 -0
  74. package/src/mcp/tools/monitor-resume.ts +18 -0
  75. package/src/mcp/tools/monitor-start.ts +20 -0
  76. package/src/mcp/tools/monitor-stop.ts +18 -0
  77. package/src/mcp/tools/precision-match.ts +51 -0
  78. package/src/mcp/tools/precision-query.ts +127 -0
  79. package/src/mcp/tools/precision.ts +312 -0
  80. package/src/mcp/tools/run-capture.ts +126 -44
  81. package/src/mcp/tools/safe-read.ts +14 -12
  82. package/src/mcp/tools/since.ts +49 -0
  83. package/src/mcp/tools/state.ts +11 -3
  84. package/src/mcp/tools/stats.ts +5 -1
  85. package/src/mcp/tools/workspace-authorizations.ts +14 -0
  86. package/src/mcp/tools/workspace-authorize.ts +20 -0
  87. package/src/mcp/tools/workspace-bind.ts +25 -0
  88. package/src/mcp/tools/workspace-rebind.ts +25 -0
  89. package/src/mcp/tools/workspace-revoke.ts +18 -0
  90. package/src/mcp/tools/workspace-status.ts +12 -0
  91. package/src/mcp/warp-pool.ts +36 -0
  92. package/src/mcp/workspace-router.ts +984 -0
  93. package/src/operations/file-outline.ts +12 -2
  94. package/src/operations/graft-diff.ts +56 -10
  95. package/src/operations/safe-read.ts +27 -4
  96. package/src/operations/state.ts +6 -9
  97. package/src/parser/lang.ts +19 -3
  98. package/src/parser/outline.ts +191 -2
  99. package/src/parser/types.ts +9 -1
  100. package/src/policy/types.ts +4 -3
  101. package/src/ports/filesystem.ts +1 -0
  102. package/src/ports/git.ts +16 -0
  103. package/src/ports/process-runner.ts +22 -0
  104. package/src/release/security-gate.ts +102 -0
  105. package/src/session/tracker.ts +31 -0
  106. package/src/version.ts +3 -0
  107. package/src/warp/indexer.ts +513 -0
  108. package/src/warp/observers.ts +105 -0
  109. package/src/warp/open.ts +31 -0
  110. package/src/warp/plumbing.d.ts +15 -0
  111. package/src/warp/writer-id.ts +30 -0
package/docs/GUIDE.md CHANGED
@@ -22,10 +22,126 @@ Scaffolds your project for graft in one command:
22
22
  - Creates `.graftignore` (template with examples)
23
23
  - Adds `.graft/` to `.gitignore`
24
24
  - Generates a `CLAUDE.md` snippet instructing agents to prefer graft tools
25
- - Prints Claude Code hook config for manual setup
25
+ - Prints Claude Code hook and MCP config for manual setup
26
+
27
+ If you use `--write-codex-mcp`, `init` also seeds `AGENTS.md` so Codex
28
+ has a repo-local instruction layer alongside the MCP config.
26
29
 
27
30
  Idempotent — safe to run again without duplicating entries.
28
31
 
32
+ ## Choose Your Setup Path
33
+
34
+ Use this table when you want the shortest path instead of reading the
35
+ whole setup guide front-to-back.
36
+
37
+ | If you want... | Use this path | What happens |
38
+ |---|---|---|
39
+ | Claude Code MCP only in this repo | `npx @flyingrobots/graft init --write-claude-mcp` | Writes or merges `.mcp.json` |
40
+ | Claude Code MCP plus hook enforcement in this repo | `npx @flyingrobots/graft init --write-claude-mcp --write-claude-hooks` | Writes or merges `.mcp.json` and `.claude/settings.json` |
41
+ | Cursor MCP in this repo | `npx @flyingrobots/graft init --write-cursor-mcp` | Writes or merges `.cursor/mcp.json` |
42
+ | Windsurf MCP in this repo | `npx @flyingrobots/graft init --write-windsurf-mcp` | Writes or merges `.codeium/windsurf/mcp_config.json` |
43
+ | Continue MCP in this repo | `npx @flyingrobots/graft init --write-continue-mcp` | Writes or merges `.continue/config.json` |
44
+ | Cline MCP in this repo | `npx @flyingrobots/graft init --write-cline-mcp` | Writes or merges `.vscode/cline_mcp_settings.json` |
45
+ | Codex MCP in this repo | `npx @flyingrobots/graft init --write-codex-mcp` | Writes or merges `.codex/config.toml` and seeds `AGENTS.md` |
46
+ | Manual review before any config file write | `npx @flyingrobots/graft init` | Scaffolds repo files and prints the manual MCP / hook snippets |
47
+ | Global config instead of project-local config | Edit your client's global MCP settings manually | Use the `npx @flyingrobots/graft serve` command + args shown below |
48
+ | Another MCP-compatible client | Add graft manually to that client's MCP config | Use `command = npx`, `args = ["-y", "@flyingrobots/graft", "serve"]` |
49
+
50
+ ## Governed Read Posture By Client
51
+
52
+ MCP availability is not the same thing as a governed default read path.
53
+ Use this table to see what each client actually gets today.
54
+
55
+ | Client path | MCP bootstrap | Repo-local instruction layer | Native read guardrail | Current posture |
56
+ |---|---|---|---|---|
57
+ | Claude Code with hooks | `--write-claude-mcp --write-claude-hooks` | `CLAUDE.md` | Yes, via `PreToolUse` / `PostToolUse` | Closest current default-governed path |
58
+ | Codex | `--write-codex-mcp` | `AGENTS.md` | No | Strong bootstrap guidance plus MCP, but no native-read interception |
59
+ | Cursor / Windsurf / Continue / Cline | `--write-*-mcp` | None written automatically today | No | MCP available, but governed reads still depend on agent choice |
60
+ | Other MCP-compatible clients | Manual MCP config | None written automatically today | No | MCP only |
61
+
62
+ ## Deployment Posture
63
+
64
+ Graft's supported deployment posture today is local-user with two
65
+ distinct runtime paths:
66
+
67
+ - repo-local `serve`: one stdio MCP server per repo checkout plus
68
+ repo-local bootstrap files such as `CLAUDE.md` or `AGENTS.md`
69
+ - `graft daemon`: a separate same-user local runtime on a Unix socket or
70
+ Windows named pipe, with `/mcp` for MCP traffic and `/healthz` for
71
+ liveness
72
+
73
+ The daemon is intentionally not the default editor bootstrap story yet.
74
+ It uses a stricter contract:
75
+
76
+ - daemon sessions start unbound
77
+ - workspace binding requires prior authorization through the daemon
78
+ control plane
79
+ - canonical repo identity, live worktree identity, and session-local
80
+ state remain separate
81
+ - `run_capture` stays default-denied unless an authorized workspace
82
+ explicitly enables it
83
+
84
+ Daemon control-plane inspection now exists through MCP tools:
85
+
86
+ - `daemon_status`
87
+ - `daemon_repos`
88
+ - `daemon_sessions`
89
+ - `daemon_monitors`
90
+ - `monitor_start`
91
+ - `monitor_pause`
92
+ - `monitor_resume`
93
+ - `monitor_stop`
94
+ - `workspace_authorizations`
95
+ - `workspace_authorize`
96
+ - `workspace_revoke`
97
+
98
+ ### One-step bootstrap
99
+
100
+ Write project-local client config directly when you want `init` to do
101
+ the wiring for you:
102
+
103
+ ```bash
104
+ npx @flyingrobots/graft init --write-claude-mcp --write-claude-hooks
105
+ npx @flyingrobots/graft init --write-cursor-mcp
106
+ npx @flyingrobots/graft init --write-windsurf-mcp
107
+ npx @flyingrobots/graft init --write-continue-mcp
108
+ npx @flyingrobots/graft init --write-cline-mcp
109
+ npx @flyingrobots/graft init --write-codex-mcp
110
+ ```
111
+
112
+ Supported write flags:
113
+
114
+ - `--write-claude-mcp` -> writes or merges `.mcp.json`
115
+ - `--write-claude-hooks` -> writes or merges `.claude/settings.json`
116
+ - `--write-cursor-mcp` -> writes or merges `.cursor/mcp.json`
117
+ - `--write-windsurf-mcp` -> writes or merges `.codeium/windsurf/mcp_config.json`
118
+ - `--write-continue-mcp` -> writes or merges `.continue/config.json`
119
+ - `--write-cline-mcp` -> writes or merges `.vscode/cline_mcp_settings.json`
120
+ - `--write-codex-mcp` -> writes or merges `.codex/config.toml` and
121
+ seeds `AGENTS.md`
122
+
123
+ These writes are project-local and idempotent. Existing config is
124
+ preserved, and graft entries are only added when missing.
125
+
126
+ For automation, CLI commands support `--json`:
127
+
128
+ ```bash
129
+ npx @flyingrobots/graft init --json
130
+ npx @flyingrobots/graft index --json
131
+ npx @flyingrobots/graft read safe src/app.ts --json
132
+ npx @flyingrobots/graft struct diff --json
133
+ npx @flyingrobots/graft symbol find 'create*' --json
134
+ npx @flyingrobots/graft diag activity --json
135
+ npx @flyingrobots/graft diag doctor --json
136
+ ```
137
+
138
+ Grouped CLI namespaces:
139
+
140
+ - `read` — `safe`, `outline`, `range`, `changed`
141
+ - `struct` — `diff`, `since`, `map`
142
+ - `symbol` — `show`, `find`
143
+ - `diag` — `activity`, `doctor`, `explain`, `stats`, `capture`
144
+
29
145
  ## MCP Configuration
30
146
 
31
147
  Graft runs as an MCP server over stdio. Add it to your editor or
@@ -41,42 +157,60 @@ Add to `.mcp.json` in your project root (per-project) or
41
157
  "mcpServers": {
42
158
  "graft": {
43
159
  "command": "npx",
44
- "args": ["-y", "@flyingrobots/graft"]
160
+ "args": ["-y", "@flyingrobots/graft", "serve"]
45
161
  }
46
162
  }
47
163
  }
48
164
  ```
49
165
 
166
+ Project-local shortcut:
167
+
168
+ ```bash
169
+ npx @flyingrobots/graft init --write-claude-mcp
170
+ ```
171
+
50
172
  ### Cursor
51
173
 
52
- Add to Cursor's MCP settings (Settings → MCP Servers → Add):
174
+ Add to `.cursor/mcp.json` in your project root:
53
175
 
54
176
  ```json
55
177
  {
56
178
  "mcpServers": {
57
179
  "graft": {
58
180
  "command": "npx",
59
- "args": ["-y", "@flyingrobots/graft"]
181
+ "args": ["-y", "@flyingrobots/graft", "serve"]
60
182
  }
61
183
  }
62
184
  }
63
185
  ```
64
186
 
187
+ Project-local shortcut:
188
+
189
+ ```bash
190
+ npx @flyingrobots/graft init --write-cursor-mcp
191
+ ```
192
+
65
193
  ### Windsurf
66
194
 
67
- Add to `~/.codeium/windsurf/mcp_config.json`:
195
+ Add to `.codeium/windsurf/mcp_config.json` in your project root:
68
196
 
69
197
  ```json
70
198
  {
71
199
  "mcpServers": {
72
200
  "graft": {
73
201
  "command": "npx",
74
- "args": ["-y", "@flyingrobots/graft"]
202
+ "args": ["-y", "@flyingrobots/graft", "serve"]
75
203
  }
76
204
  }
77
205
  }
78
206
  ```
79
207
 
208
+ Project-local shortcut:
209
+
210
+ ```bash
211
+ npx @flyingrobots/graft init --write-windsurf-mcp
212
+ ```
213
+
80
214
  ### VS Code + Continue
81
215
 
82
216
  Add to `.continue/config.json`:
@@ -87,12 +221,18 @@ Add to `.continue/config.json`:
87
221
  {
88
222
  "name": "graft",
89
223
  "command": "npx",
90
- "args": ["-y", "@flyingrobots/graft"]
224
+ "args": ["-y", "@flyingrobots/graft", "serve"]
91
225
  }
92
226
  ]
93
227
  }
94
228
  ```
95
229
 
230
+ Project-local shortcut:
231
+
232
+ ```bash
233
+ npx @flyingrobots/graft init --write-continue-mcp
234
+ ```
235
+
96
236
  ### Cline
97
237
 
98
238
  Add via Cline's MCP settings UI, or in
@@ -103,32 +243,73 @@ Add via Cline's MCP settings UI, or in
103
243
  "mcpServers": {
104
244
  "graft": {
105
245
  "command": "npx",
106
- "args": ["-y", "@flyingrobots/graft"]
246
+ "args": ["-y", "@flyingrobots/graft", "serve"]
107
247
  }
108
248
  }
109
249
  }
110
250
  ```
111
251
 
252
+ Project-local shortcut:
253
+
254
+ ```bash
255
+ npx @flyingrobots/graft init --write-cline-mcp
256
+ ```
257
+
258
+ ### Codex
259
+
260
+ Add to `.codex/config.toml` in your project root (per-project) or
261
+ `~/.codex/config.toml` (global):
262
+
263
+ ```toml
264
+ [mcp_servers.graft]
265
+ command = "npx"
266
+ args = ["-y", "@flyingrobots/graft", "serve"]
267
+ startup_timeout_sec = 120
268
+ ```
269
+
270
+ Project-local shortcut:
271
+
272
+ ```bash
273
+ npx @flyingrobots/graft init --write-codex-mcp
274
+ ```
275
+
276
+ That explicit write path also creates or merges `AGENTS.md` with graft
277
+ read guidance so Codex sees repo-local instructions as well as the MCP
278
+ server config.
279
+ If you already have an older graft block in `.codex/config.toml`,
280
+ rerunning that command will add the safer startup timeout without
281
+ duplicating the server entry.
282
+
283
+ The larger startup timeout is intentional. Cold `npx` startup can spend
284
+ enough time in package acquisition and bootstrap to exceed Codex's
285
+ default 30 second budget even when the graft server itself is healthy.
286
+
287
+ **Note:** Codex may ask you to approve external MCP tool calls the
288
+ first time it uses graft. If you trust the local server, choose
289
+ "Always allow" so normal graft tool use does not require a prompt on
290
+ every call.
291
+
112
292
  ### Any MCP-compatible client
113
293
 
114
294
  The pattern is the same everywhere:
115
295
 
116
296
  - **Command**: `npx`
117
- - **Args**: `["-y", "@flyingrobots/graft"]`
297
+ - **Args**: `["-y", "@flyingrobots/graft", "serve"]`
118
298
  - **Transport**: stdio (the default for most clients)
119
299
 
120
300
  If your client doesn't support `npx`, install globally and use:
121
301
 
122
302
  - **Command**: `graft`
123
- - **Args**: (none)
303
+ - **Args**: `["serve"]`
124
304
 
125
305
  ## Claude Code Hooks
126
306
 
127
307
  Two hooks work together to govern agent reads:
128
308
 
129
- - **PreToolUse** — blocks banned files before the read happens
130
- - **PostToolUse** — educates the agent on context cost after large
131
- file reads complete
309
+ - **PreToolUse** — blocks banned files and redirects large JS/TS reads
310
+ before the native read happens
311
+ - **PostToolUse** — backstop education if an oversized code read still
312
+ completes
132
313
 
133
314
  ### Setup
134
315
 
@@ -163,6 +344,12 @@ Add to `.claude/settings.json` in your project root:
163
344
  }
164
345
  ```
165
346
 
347
+ Project-local shortcut:
348
+
349
+ ```bash
350
+ npx @flyingrobots/graft init --write-claude-hooks
351
+ ```
352
+
166
353
  If developing graft itself, replace the `node_modules/...` paths
167
354
  with local paths:
168
355
 
@@ -178,25 +365,31 @@ When the agent calls `Read(file_path)`, the PreToolUse hook:
178
365
  1. Evaluates the file against graft's policy
179
366
  2. **Banned files** (binaries, lockfiles, secrets, `.graftignore`
180
367
  matches): exits 2 (block) with refusal reason and next steps
181
- 3. **Everything else**: exits 0 lets native Read proceed
368
+ 3. **Large JS/TS files**: exits 2 with a redirect to `safe_read`,
369
+ `file_outline`, and `read_range`
370
+ 4. **Everything else**: exits 0 — lets native Read proceed
182
371
 
183
- The PreToolUse hook does NOT block large files. It only enforces
184
- hard bans. Large file governance is handled by the PostToolUse hook.
372
+ This is the current "default governed" path for Claude Code: large
373
+ code reads are redirected before the full file lands in context.
374
+ Other file types and other clients still rely on MCP usage or future
375
+ integration work.
185
376
 
186
- ### PostToolUse — context cost education
377
+ ### PostToolUse — backstop education
187
378
 
188
379
  After a Read completes, the PostToolUse hook evaluates what
189
- `safe_read` would have done and tells the agent the cost:
380
+ `safe_read` would have done for large JS/TS files and tells the agent
381
+ the cost:
190
382
 
191
383
  ```
192
- [graft] You just read 450 lines (18KB) into context.
193
- safe_read would have returned a structural outline (2048 bytes),
384
+ [graft] This large code read bypassed graft's governed path for src/mcp/server.ts.
385
+ safe_read would have returned a structural outline (2048 bytes) instead of 450 lines (18.0KB),
194
386
  saving 16.0KB of context. Threshold: 150 lines / 12KB.
195
387
  ```
196
388
 
197
- This feedback appears for large JS/TS files where an outline was
198
- available. Small files, non-JS/TS files, and nonexistent files
199
- produce no feedback. The hook always exits 0 — it never blocks.
389
+ This feedback appears only if an oversized JS/TS read still completes.
390
+ With a working PreToolUse hook, that should be a backstop signal rather
391
+ than the normal path. Small files, non-JS/TS files, and nonexistent
392
+ files produce no feedback. The hook always exits 0 — it never blocks.
200
393
 
201
394
  ### Limitations
202
395
 
@@ -210,7 +403,9 @@ with the MCP server. This means:
210
403
 
211
404
  For the full experience, agents should use graft's MCP tools
212
405
  (`safe_read`, `file_outline`, `read_range`) directly. The hooks
213
- are a safety net; the MCP server is the full governor.
406
+ make Claude closer to a default-governed path for large code reads, but
407
+ the MCP server remains the full governor and non-Claude clients still
408
+ need explicit integration.
214
409
 
215
410
  ### Disabling
216
411
 
@@ -231,18 +426,39 @@ add to `.claude/settings.local.json`:
231
426
  | `file_outline` | Structural skeleton of a file — function signatures, class shapes, exports. Includes a jump table mapping each symbol to its line range for targeted `read_range` follow-ups. |
232
427
  | `read_range` | Read a bounded range of lines from a file. Maximum 250 lines. Use jump table entries from `file_outline` or `safe_read` to target specific symbols. |
233
428
  | `changed_since` | Check if a file changed since it was last read. Returns structural diff (added/removed/changed symbols) or "unchanged". Peek mode by default; pass `consume: true` to update the observation cache. |
234
- | `graft_diff` | Structural diff between two git refs. Shows added, removed, and changed symbols per file — not line hunks. Defaults to working tree vs HEAD. |
235
- | `run_capture` | Execute a shell command and return the last N lines of output (default 60). Full output saved to `.graft/logs/capture.log` for follow-up `read_range` calls. |
429
+ | `graft_diff` | Structural diff between two git refs. Shows added, removed, and changed symbols per file — not line hunks. Defaults to working tree vs HEAD. Policy-denied files are omitted from `files` and surfaced in `refused`. |
430
+ | `graft_since` | Structural changes since a git ref. Shows added/removed/changed symbols per file and a summary line. Policy-denied files are omitted from `files` and surfaced in `refused`. |
431
+ | `graft_map` | Structural directory map of files and symbols under a path, with explicit denied-file reporting. |
432
+ | `code_show` | Focus on a symbol by name and return its source with line metadata. |
433
+ | `code_find` | Search symbols across the project by approximate name or glob pattern, with optional kind/path filter. |
434
+ | `code_refs` | Search import sites, callsites, property access, or literal text references with explicit text-fallback provenance, pattern, and scope. |
435
+ | `activity_view` | Bounded between-commit activity for the active workspace, including commit anchor, grouped recent activity, and degraded posture. |
436
+ | `doctor` | Runtime health check including layered-worldline repo state and burden summary. |
437
+ | `stats` | Decision metrics for the current server session, including burden by tool kind. |
438
+ | `explain` | Human-readable meaning and recommended action for a reason code. |
439
+ | `run_capture` | Execute a shell command and return the last N lines of output (default 60). This tool is outside graft's bounded-read policy contract, responses include an explicit `policyBoundary` marker, log persistence can be disabled, and persisted output is redacted for obvious secrets by default. |
236
440
  | `state_save` | Save session working state (max 8 KB). Use for session bookmarks: current task, files modified, next planned actions. |
237
441
  | `state_load` | Load previously saved session state. Returns null if no state has been saved. |
238
- | `doctor` | Runtime health check. Shows project root, parser status, active thresholds, session depth, and message count. |
442
+
443
+ MCP responses include versioned `_schema` metadata and `_receipt`
444
+ fields. CLI peer commands also return versioned `_schema` metadata;
445
+ the declared contracts live in `src/contracts/output-schemas.ts`.
446
+ | `doctor` | Runtime health check. Shows project root, parser status, active thresholds, session depth, message count, and a compact burden summary. |
239
447
  | `set_budget` | Declare a session byte budget. Graft tightens read thresholds as the budget drains — no single read may consume more than 5% of remaining budget. Call once at session start. |
240
448
  | `explain` | Explain a graft reason code. Returns human-readable meaning and recommended next action for any code (e.g., `BINARY`, `BUDGET_CAP`). Case-insensitive. |
241
- | `stats` | Decision metrics for the current session. Total reads, outlines, refusals, cache hits, and bytes avoided. |
449
+ | `stats` | Decision metrics for the current session. Total reads, outlines, refusals, cache hits, bytes avoided, and returned-byte burden by tool kind. |
450
+
451
+ Every MCP tool response includes:
452
+ - `_receipt` — runtime decision metadata
453
+ - `_schema` — versioned output contract metadata
454
+
455
+ Declared output contracts live in `src/contracts/output-schemas.ts`.
456
+ | `graft_since` | Structural changes since a git ref. Shows symbols added, removed, and changed per file — not line hunks. Includes per-file summary lines. Policy-denied files are omitted from `files` and surfaced in `refused`. |
457
+ | `graft_map` | Structural map of a directory — all files and their symbols (function signatures, class shapes, exports) in one call. Uses tree-sitter to parse the working tree directly. Policy-denied files are omitted from `files` and surfaced in `refused`. |
242
458
 
243
459
  ## What the agent sees
244
460
 
245
- Once configured, the agent gains 12 new tools. Here's what
461
+ Once configured, the agent gains 17 MCP tools. Here's what
246
462
  happens when it uses them:
247
463
 
248
464
  ### Reading files
@@ -263,6 +479,22 @@ Graft decides what to return:
263
479
  If the file changed, it returns a structural diff (added/removed/
264
480
  changed symbols).
265
481
 
482
+ ### Structural memory (WARP)
483
+
484
+ `graft_since` shows what changed structurally between any two git
485
+ refs — symbols added, removed, and changed per file. Policy-denied
486
+ files are excluded from the visible file list and reported explicitly
487
+ in `refused`.
488
+
489
+ `graft_map` gives a structural map of any directory — every file
490
+ and its symbols (function signatures, class shapes, exports) in
491
+ one call. Denied files are surfaced explicitly instead of silently
492
+ disappearing.
493
+
494
+ Both tools work on the current working tree. For persistent
495
+ structural indexing across git history, use `graft index` from the
496
+ CLI.
497
+
266
498
  ### Structural navigation
267
499
 
268
500
  `file_outline` returns the structural skeleton of any file —
@@ -274,6 +506,8 @@ Each symbol has a line range so the agent can follow up with
274
506
 
275
507
  `graft_diff` shows what changed between git refs at the symbol
276
508
  level: "function `foo` gained a parameter" instead of line hunks.
509
+ Denied files are excluded from the visible diff and reported in
510
+ `refused`.
277
511
 
278
512
  ### Budget governor
279
513
 
@@ -304,8 +538,13 @@ messages, edit-bash loops, runaway tool calls).
304
538
  ### Receipts
305
539
 
306
540
  Every response includes a `_receipt` block with session ID,
307
- sequence number, projection type, bytes returned, and cumulative
308
- counters. This is for usage analysis — you can ignore it.
541
+ trace ID, sequence number, latency, projection type, bytes
542
+ returned, and cumulative counters. This is for usage analysis and
543
+ correlation — you can usually ignore it.
544
+
545
+ If MCP runtime observability is enabled, `traceId` and `seq` line up
546
+ with `.graft/logs/mcp-runtime.ndjson`. `doctor` also reports the
547
+ current runtime log path and policy.
309
548
 
310
549
  ## Configuration
311
550
 
@@ -342,16 +581,56 @@ via picomatch).
342
581
  These are not yet configurable at runtime (planned for a future
343
582
  release).
344
583
 
584
+ ### run_capture posture
585
+
586
+ `run_capture` is a diagnostic shell escape hatch, not a bounded-read
587
+ tool. For broader or more sensitive deployments:
588
+
589
+ - set `GRAFT_ENABLE_RUN_CAPTURE=0` to disable execution entirely
590
+ - set `GRAFT_RUN_CAPTURE_PERSIST=0` to avoid writing `.graft/logs/capture.log`
591
+ - persisted capture output is redacted for obvious secret-shaped values
592
+ by default
593
+
594
+ In the local daemon runtime, `run_capture` stays disabled by default and
595
+ requires an explicit operator-authorized capability profile rather than
596
+ inheriting local repo-scoped trust.
597
+
598
+ ### MCP runtime observability
599
+
600
+ MCP runtime observability writes metadata-only session and tool-call
601
+ events to `.graft/logs/mcp-runtime.ndjson`. The log intentionally does
602
+ not include raw file content, query text, or other request payload
603
+ values.
604
+
605
+ - set `GRAFT_ENABLE_MCP_RUNTIME_LOG=0` to disable MCP runtime logging
606
+ - set `GRAFT_MCP_RUNTIME_LOG_PATH=/abs/path/mcp-runtime.ndjson` to move
607
+ the log
608
+ - set `GRAFT_MCP_RUNTIME_LOG_MAX_BYTES=2097152` to change retention size
609
+
345
610
  ## Troubleshooting
346
611
 
347
612
  ### "Tool not found" or no graft tools visible
348
613
 
349
- - Verify graft is installed: `npx @flyingrobots/graft --help`
614
+ - Verify the CLI is installed: `npx @flyingrobots/graft --help`
615
+ - Verify the MCP transport starts: `npx @flyingrobots/graft serve`
350
616
  (should start the server; Ctrl+C to stop)
351
617
  - Check your MCP config syntax — JSON must be valid
352
618
  - Restart your editor/agent after adding MCP config
353
619
  - Some clients cache tool lists — try reopening the project
354
620
 
621
+ ### Codex says `user cancelled MCP tool call`
622
+
623
+ This can be a Codex approval issue rather than a graft failure.
624
+ Codex may require permission for external MCP tool calls. If those
625
+ prompts are denied, or cannot be shown in a non-interactive run, the
626
+ tool call may appear as cancelled.
627
+
628
+ - Run Codex interactively and approve graft tool calls
629
+ - If you trust the server, choose "Always allow" for graft
630
+ - Retry the call after granting permission
631
+ - If graft still fails, run `doctor` first to separate Codex setup
632
+ problems from graft runtime problems
633
+
355
634
  ### Agent keeps getting outlines instead of content
356
635
 
357
636
  Your files are over 150 lines or 12 KB. This is intentional.
@@ -365,8 +644,18 @@ Check the reason code in the response:
365
644
  - `LOCKFILE` — read `package.json` instead
366
645
  - `SECRET` — `.env` files are banned for safety
367
646
  - `BUILD_OUTPUT` — read the source file, not `dist/`
647
+ - `UNSUPPORTED_LANGUAGE` — no parser-backed outline exists for this file type yet; use `read_range` or a full read when appropriate
368
648
  - `GRAFTIGNORE` — file matches a `.graftignore` pattern
369
649
 
650
+ ### run_capture is disabled
651
+
652
+ If `run_capture` returns `run_capture is disabled by configuration`,
653
+ the server was started with shell capture turned off.
654
+
655
+ - local repo-scoped sessions can re-enable it by unsetting
656
+ `GRAFT_ENABLE_RUN_CAPTURE=0`
657
+ - shared or harder security postures should generally leave it disabled
658
+
370
659
  ### graft is slow on first call
371
660
 
372
661
  Tree-sitter WASM grammars load on first parse (~200ms). Subsequent
package/docs/MCP.md ADDED
@@ -0,0 +1,44 @@
1
+ # MCP Guide
2
+
3
+ This is the shortest signpost for Graft's MCP surface.
4
+
5
+ Use MCP when an agent or editor should call Graft directly as a tool
6
+ provider.
7
+
8
+ ## Startup
9
+
10
+ Stdio MCP:
11
+
12
+ ```bash
13
+ npx @flyingrobots/graft serve
14
+ ```
15
+
16
+ Local daemon:
17
+
18
+ ```bash
19
+ npx @flyingrobots/graft daemon
20
+ ```
21
+
22
+ ## Key tool groups
23
+
24
+ - bounded reads: `safe_read`, `file_outline`, `read_range`, `changed_since`
25
+ - structural history: `graft_diff`, `graft_since`, `graft_map`
26
+ - precision: `code_show`, `code_find`, `code_refs`
27
+ - activity and footing: `activity_view`, `causal_status`, `causal_attach`, `doctor`
28
+ - daemon control plane: `daemon_status`, `daemon_repos`, `daemon_sessions`, monitor tools
29
+
30
+ ## Current release-facing truth
31
+
32
+ - MCP is still the primary agent surface
33
+ - responses carry versioned `_schema` metadata
34
+ - `activity_view` is the first honest human-facing between-commit
35
+ surface, but its truth class is still bounded local
36
+ `artifact_history`
37
+
38
+ ## Related docs
39
+
40
+ - [README](../README.md)
41
+ - [Setup Guide](GUIDE.md)
42
+ - [CLI Guide](CLI.md)
43
+ - [Advanced Guide](ADVANCED_GUIDE.md)
44
+ - [Architecture](../ARCHITECTURE.md)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@flyingrobots/graft",
3
- "version": "0.3.5",
4
- "description": "Context governor for coding agents — MCP server with policy-enforced reads, structural outlines, and session tracking",
3
+ "version": "0.5.0",
4
+ "description": "Context governor and between-commit activity surface for coding agents",
5
5
  "type": "module",
6
6
  "packageManager": "pnpm@10.30.0",
7
7
  "bin": {
@@ -11,7 +11,12 @@
11
11
  "files": [
12
12
  "bin/",
13
13
  "src/",
14
+ "ARCHITECTURE.md",
15
+ "CODE_OF_CONDUCT.md",
16
+ "docs/ADVANCED_GUIDE.md",
17
+ "docs/CLI.md",
14
18
  "docs/GUIDE.md",
19
+ "docs/MCP.md",
15
20
  "LICENSE",
16
21
  "NOTICE",
17
22
  "README.md",
@@ -23,7 +28,9 @@
23
28
  "test:watch": "vitest",
24
29
  "lint": "eslint .",
25
30
  "typecheck": "tsc --noEmit",
26
- "pack:check": "pnpm pack --dry-run"
31
+ "pack:check": "pnpm pack --dry-run",
32
+ "security:check": "tsx scripts/check-release-security.ts",
33
+ "release:check": "pnpm lint && pnpm typecheck && pnpm test && pnpm security:check && pnpm pack:check"
27
34
  },
28
35
  "engines": {
29
36
  "node": ">=20.11.0"
@@ -57,6 +64,8 @@
57
64
  "url": "git+https://github.com/flyingrobots/graft.git"
58
65
  },
59
66
  "dependencies": {
67
+ "@git-stunts/git-warp": "^16.0.0",
68
+ "@git-stunts/plumbing": "^2.8.0",
60
69
  "@modelcontextprotocol/sdk": "^1.29.0",
61
70
  "picomatch": "^4.0.4",
62
71
  "tree-sitter-wasms": "0.1.13",
@@ -72,9 +81,13 @@
72
81
  "globals": "^17.4.0",
73
82
  "typescript": "^6.0.2",
74
83
  "typescript-eslint": "^8.58.0",
84
+ "vite": "^8.0.5",
75
85
  "vitest": "^4.1.2"
76
86
  },
77
87
  "pnpm": {
78
- "onlyBuiltDependencies": []
88
+ "onlyBuiltDependencies": [],
89
+ "overrides": {
90
+ "vite": "^8.0.5"
91
+ }
79
92
  }
80
93
  }
@@ -14,6 +14,10 @@ class NodeFileSystem implements FileSystem {
14
14
  return fsp.readFile(path);
15
15
  }
16
16
 
17
+ readdir(path: string): Promise<string[]> {
18
+ return fsp.readdir(path);
19
+ }
20
+
17
21
  writeFile(path: string, data: string, encoding: "utf-8"): Promise<void> {
18
22
  return fsp.writeFile(path, data, encoding);
19
23
  }