@flyingrobots/graft 0.6.0 → 0.6.1

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.
@@ -0,0 +1,52 @@
1
+ # Advanced Guide
2
+
3
+ This guide is the release-facing signpost for operators and
4
+ contributors who need more than setup instructions.
5
+
6
+ ## Use this guide for
7
+
8
+ - understanding the same-user local daemon posture
9
+ - understanding hook/bootstrap coverage and degraded footing
10
+ - understanding the boundary between bounded local `artifact_history`
11
+ and canonical provenance
12
+ - understanding why release prep pauses the repo after a cycle close
13
+
14
+ ## Current advanced topics
15
+
16
+ ### Daemon posture
17
+
18
+ `graft daemon` is a same-user local runtime with explicit workspace
19
+ authorization, session binding, monitor control, and bounded daemon
20
+ inspection surfaces.
21
+
22
+ ### Reactive footing
23
+
24
+ Checkout-boundary footing is explicit. Graft can report installed hook
25
+ coverage, hook-observed transitions, and degraded posture when local
26
+ edit watchers are absent.
27
+
28
+ ### Same-repo concurrency
29
+
30
+ Graft now distinguishes bounded same-repo postures such as
31
+ `exclusive`, `shared_repo_only`, `shared_worktree`,
32
+ `overlapping_actors`, and `divergent_checkout` without pretending
33
+ multi-writer provenance already exists.
34
+
35
+ ### Between-commit activity
36
+
37
+ `activity_view` and `graft diag activity` expose bounded local
38
+ between-commit `artifact_history`. This is not canonical provenance
39
+ and not causal collapse.
40
+
41
+ ## Related docs
42
+
43
+ - [README](./README.md)
44
+ - [Guide](./GUIDE.md)
45
+ - [Setup Guide](./docs/SETUP.md)
46
+ - [CLI Guide](./docs/CLI.md)
47
+ - [MCP Guide](./docs/MCP.md)
48
+ - [Architecture](./ARCHITECTURE.md)
49
+ - [Security Model](./docs/strategy/security-model.md)
50
+ - [Causal Provenance](./docs/strategy/causal-provenance.md)
51
+ - [Bearing](./docs/BEARING.md)
52
+ - [Vision](./docs/VISION.md)
package/CHANGELOG.md CHANGED
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.6.1] - 2026-04-19
11
+
12
+ ### Fixed
13
+
14
+ - **CI test fixes**: release gate test excludes build artifact `dist/`
15
+ from existence check. Package docs test updated for moved doc paths.
16
+
10
17
  ## [0.6.0] - 2026-04-18
11
18
 
12
19
  ### Added
package/GUIDE.md ADDED
@@ -0,0 +1,53 @@
1
+ # Guide — Graft
2
+
3
+ This is the developer-level operator guide for Graft. Use it for orientation, the productive-fast path, and to understand how the context governor orchestrates agentic reads.
4
+
5
+ For deep-track doctrine, worldline internals, and repository-wide engineering standards, use [ADVANCED_GUIDE.md](./ADVANCED_GUIDE.md).
6
+
7
+ ## Choose Your Lane
8
+
9
+ ### 1. Initialize a Repository
10
+ Bootstrap a new repo with read policies, git hooks, and agent instructions.
11
+ - **Run**: `npx @flyingrobots/graft init`
12
+ - **Read**: [Setup Guide](./docs/SETUP.md) (Detailed per-editor steps)
13
+
14
+ ### 2. Standalone CLI Usage
15
+ Manually enforce policies or inspect structural history from your terminal.
16
+ - **Read**: [CLI Signpost](./docs/CLI.md)
17
+
18
+ ### 3. Shared Daemon Mode
19
+ Run the central execution authority for multi-repo work and persistent monitors.
20
+ - **Run**: `npx @flyingrobots/graft daemon`
21
+ - **Read**: [docs/SETUP.md](./docs/SETUP.md) (Daemon bootstrap and `workspace_authorize` / `workspace_bind`)
22
+ - **Read**: [Architecture](./ARCHITECTURE.md) (Daemon section)
23
+
24
+ ## Big Picture: System Orchestration
25
+
26
+ Graft is a tiered governor. It manages the context burden across three layers:
27
+
28
+ 1. **Graft Core (Policy)**: Pure TypeScript logic that evaluates file size, language support, and session budgets to decide *what* an agent should see.
29
+ 2. **Parser (Meaning)**: Uses Tree-Sitter WASM to extract structural outlines and compute diffs, turning raw files into actionable meaning.
30
+ 3. **WARP (Memory)**: The Structural Worldline Memory that tracks AST evolution across commits, providing a provenance-aware history of the repository.
31
+
32
+ ## Orientation Checklist
33
+
34
+ - [ ] **I am setting up a new project**: Start with `README.md` Quick Start.
35
+ - [ ] **I am configuring Claude Code**: Use `npx graft init --write-claude-hooks`.
36
+ - [ ] **I am using daemon mode in a generic MCP client**: Read [docs/SETUP.md](./docs/SETUP.md) and expect explicit `workspace_authorize` then `workspace_bind`.
37
+ - [ ] **I am debugging a structural diff**: Use `npx graft struct diff --json`.
38
+ - [ ] **I am contributing to Graft**: Read `METHOD.md` and `docs/BEARING.md`.
39
+
40
+ ## Rule of Thumb
41
+
42
+ If you need a comprehensive tool reference, use the [MCP Signpost](./docs/MCP.md).
43
+
44
+ If you need the daemon trust boundary or handoff model, use
45
+ [docs/strategy/security-model.md](./docs/strategy/security-model.md) and
46
+ [docs/strategy/causal-provenance.md](./docs/strategy/causal-provenance.md).
47
+
48
+ If you need to know "what's true right now," use [docs/BEARING.md](./docs/BEARING.md).
49
+
50
+ If you are just starting, use the [README.md](./README.md) and the setup instructions in [docs/SETUP.md](./docs/SETUP.md).
51
+
52
+ ---
53
+ **The goal is inevitably. Every feature is defined by its tests.**
package/docs/SETUP.md ADDED
@@ -0,0 +1,698 @@
1
+ # Graft Setup Guide
2
+
3
+ ## Install
4
+
5
+ ```bash
6
+ npm install -g @flyingrobots/graft
7
+ ```
8
+
9
+ Or run without installing:
10
+
11
+ ```bash
12
+ npx @flyingrobots/graft
13
+ ```
14
+
15
+ ## Quick setup
16
+
17
+ ```bash
18
+ npx @flyingrobots/graft init
19
+ ```
20
+
21
+ Scaffolds your project for graft in one command:
22
+ - Creates `.graftignore` (template with examples)
23
+ - Adds `.graft/` to `.gitignore`
24
+ - Generates a `CLAUDE.md` snippet instructing agents to prefer graft tools
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.
29
+
30
+ Idempotent — safe to run again without duplicating entries.
31
+
32
+ `init` bootstraps repo-local files and client config. It does not make a
33
+ daemon session implicitly bound later; daemon mode still requires
34
+ explicit authorization and workspace binding through MCP control-plane
35
+ tools.
36
+
37
+ ## Choose Your Setup Path
38
+
39
+ Use this table when you want the shortest path instead of reading the
40
+ whole setup guide front-to-back.
41
+
42
+ | If you want... | Use this path | What happens |
43
+ |---|---|---|
44
+ | Claude Code MCP only in this repo | `npx @flyingrobots/graft init --write-claude-mcp` | Writes or merges `.mcp.json` |
45
+ | 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` |
46
+ | Cursor MCP in this repo | `npx @flyingrobots/graft init --write-cursor-mcp` | Writes or merges `.cursor/mcp.json` |
47
+ | Windsurf MCP in this repo | `npx @flyingrobots/graft init --write-windsurf-mcp` | Writes or merges `.codeium/windsurf/mcp_config.json` |
48
+ | Continue MCP in this repo | `npx @flyingrobots/graft init --write-continue-mcp` | Writes or merges `.continue/config.json` |
49
+ | Cline MCP in this repo | `npx @flyingrobots/graft init --write-cline-mcp` | Writes or merges `.vscode/cline_mcp_settings.json` |
50
+ | Codex MCP in this repo | `npx @flyingrobots/graft init --write-codex-mcp` | Writes or merges `.codex/config.toml` and seeds `AGENTS.md` |
51
+ | Manual review before any config file write | `npx @flyingrobots/graft init` | Scaffolds repo files and prints the manual MCP / hook snippets |
52
+ | 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 |
53
+ | Another MCP-compatible client | Add graft manually to that client's MCP config | Use `command = npx`, `args = ["-y", "@flyingrobots/graft", "serve"]` |
54
+
55
+ ## Governed Read Posture By Client
56
+
57
+ MCP availability is not the same thing as a governed default read path.
58
+ Use this table to see what each client actually gets today.
59
+
60
+ | Client path | MCP bootstrap | Repo-local instruction layer | Native read guardrail | Current posture |
61
+ |---|---|---|---|---|
62
+ | Claude Code with hooks | `--write-claude-mcp --write-claude-hooks` | `CLAUDE.md` | Yes, via `PreToolUse` / `PostToolUse` | Closest current default-governed path |
63
+ | Codex | `--write-codex-mcp` | `AGENTS.md` | No | Strong bootstrap guidance plus MCP, but no native-read interception |
64
+ | Cursor / Windsurf / Continue / Cline | `--write-*-mcp` | None written automatically today | No | MCP available, but governed reads still depend on agent choice |
65
+ | Other MCP-compatible clients | Manual MCP config | None written automatically today | No | MCP only |
66
+
67
+ ## Deployment Posture
68
+
69
+ Graft's supported deployment posture today is local-user with two
70
+ distinct runtime paths:
71
+
72
+ - repo-local `serve`: one stdio MCP server per repo checkout plus
73
+ repo-local bootstrap files such as `CLAUDE.md` or `AGENTS.md`
74
+ - `graft daemon`: a separate same-user local runtime on a Unix socket or
75
+ Windows named pipe, with `/mcp` for MCP traffic and `/healthz` for
76
+ liveness
77
+
78
+ The daemon is intentionally not the default editor bootstrap story yet.
79
+ It uses a stricter contract:
80
+
81
+ - daemon sessions start unbound
82
+ - workspace binding requires prior authorization through the daemon
83
+ control plane
84
+ - canonical repo identity, live worktree identity, and session-local
85
+ state remain separate
86
+ - `run_capture` stays default-denied unless an authorized workspace
87
+ explicitly enables it
88
+
89
+ Daemon control-plane inspection now exists through MCP tools:
90
+
91
+ - `daemon_status`
92
+ - `daemon_repos`
93
+ - `daemon_sessions`
94
+ - `daemon_monitors`
95
+ - `monitor_start`
96
+ - `monitor_pause`
97
+ - `monitor_resume`
98
+ - `monitor_stop`
99
+ - `workspace_authorizations`
100
+ - `workspace_authorize`
101
+ - `workspace_bind`
102
+ - `workspace_status`
103
+ - `workspace_rebind`
104
+ - `workspace_revoke`
105
+
106
+ Practical daemon first-use sequence:
107
+
108
+ 1. start `npx @flyingrobots/graft daemon`
109
+ 2. connect your MCP client to the daemon surface
110
+ 3. call `workspace_authorize` with the target `cwd`
111
+ 4. call `workspace_bind` with the target `cwd`
112
+ 5. then use repository-scoped tools such as `safe_read` or `graft_map`
113
+
114
+ ### One-step bootstrap
115
+
116
+ Write project-local client config directly when you want `init` to do
117
+ the wiring for you:
118
+
119
+ ```bash
120
+ npx @flyingrobots/graft init --write-claude-mcp --write-claude-hooks
121
+ npx @flyingrobots/graft init --write-cursor-mcp
122
+ npx @flyingrobots/graft init --write-windsurf-mcp
123
+ npx @flyingrobots/graft init --write-continue-mcp
124
+ npx @flyingrobots/graft init --write-cline-mcp
125
+ npx @flyingrobots/graft init --write-codex-mcp
126
+ ```
127
+
128
+ Supported write flags:
129
+
130
+ - `--write-claude-mcp` -> writes or merges `.mcp.json`
131
+ - `--write-claude-hooks` -> writes or merges `.claude/settings.json`
132
+ - `--write-cursor-mcp` -> writes or merges `.cursor/mcp.json`
133
+ - `--write-windsurf-mcp` -> writes or merges `.codeium/windsurf/mcp_config.json`
134
+ - `--write-continue-mcp` -> writes or merges `.continue/config.json`
135
+ - `--write-cline-mcp` -> writes or merges `.vscode/cline_mcp_settings.json`
136
+ - `--write-codex-mcp` -> writes or merges `.codex/config.toml` and
137
+ seeds `AGENTS.md`
138
+
139
+ These writes are project-local and idempotent. Existing config is
140
+ preserved, and graft entries are only added when missing.
141
+
142
+ For automation, CLI commands support `--json`:
143
+
144
+ ```bash
145
+ npx @flyingrobots/graft init --json
146
+ npx @flyingrobots/graft index --json
147
+ npx @flyingrobots/graft read safe src/app.ts --json
148
+ npx @flyingrobots/graft struct diff --json
149
+ npx @flyingrobots/graft symbol find 'create*' --json
150
+ npx @flyingrobots/graft diag activity --json
151
+ npx @flyingrobots/graft diag doctor --json
152
+ ```
153
+
154
+ Grouped CLI namespaces:
155
+
156
+ - `read` — `safe`, `outline`, `range`, `changed`
157
+ - `struct` — `diff`, `since`, `map`
158
+ - `symbol` — `show`, `find`
159
+ - `diag` — `activity`, `doctor`, `explain`, `stats`, `capture`
160
+
161
+ ## MCP Configuration
162
+
163
+ Graft runs as an MCP server over stdio. Add it to your editor or
164
+ agent's MCP configuration.
165
+
166
+ ### Claude Code
167
+
168
+ Add to `.mcp.json` in your project root (per-project) or
169
+ `~/.claude.json` (global):
170
+
171
+ ```json
172
+ {
173
+ "mcpServers": {
174
+ "graft": {
175
+ "command": "npx",
176
+ "args": ["-y", "@flyingrobots/graft", "serve"]
177
+ }
178
+ }
179
+ }
180
+ ```
181
+
182
+ Project-local shortcut:
183
+
184
+ ```bash
185
+ npx @flyingrobots/graft init --write-claude-mcp
186
+ ```
187
+
188
+ ### Cursor
189
+
190
+ Add to `.cursor/mcp.json` in your project root:
191
+
192
+ ```json
193
+ {
194
+ "mcpServers": {
195
+ "graft": {
196
+ "command": "npx",
197
+ "args": ["-y", "@flyingrobots/graft", "serve"]
198
+ }
199
+ }
200
+ }
201
+ ```
202
+
203
+ Project-local shortcut:
204
+
205
+ ```bash
206
+ npx @flyingrobots/graft init --write-cursor-mcp
207
+ ```
208
+
209
+ ### Windsurf
210
+
211
+ Add to `.codeium/windsurf/mcp_config.json` in your project root:
212
+
213
+ ```json
214
+ {
215
+ "mcpServers": {
216
+ "graft": {
217
+ "command": "npx",
218
+ "args": ["-y", "@flyingrobots/graft", "serve"]
219
+ }
220
+ }
221
+ }
222
+ ```
223
+
224
+ Project-local shortcut:
225
+
226
+ ```bash
227
+ npx @flyingrobots/graft init --write-windsurf-mcp
228
+ ```
229
+
230
+ ### VS Code + Continue
231
+
232
+ Add to `.continue/config.json`:
233
+
234
+ ```json
235
+ {
236
+ "mcpServers": [
237
+ {
238
+ "name": "graft",
239
+ "command": "npx",
240
+ "args": ["-y", "@flyingrobots/graft", "serve"]
241
+ }
242
+ ]
243
+ }
244
+ ```
245
+
246
+ Project-local shortcut:
247
+
248
+ ```bash
249
+ npx @flyingrobots/graft init --write-continue-mcp
250
+ ```
251
+
252
+ ### Cline
253
+
254
+ Add via Cline's MCP settings UI, or in
255
+ `.vscode/cline_mcp_settings.json`:
256
+
257
+ ```json
258
+ {
259
+ "mcpServers": {
260
+ "graft": {
261
+ "command": "npx",
262
+ "args": ["-y", "@flyingrobots/graft", "serve"]
263
+ }
264
+ }
265
+ }
266
+ ```
267
+
268
+ Project-local shortcut:
269
+
270
+ ```bash
271
+ npx @flyingrobots/graft init --write-cline-mcp
272
+ ```
273
+
274
+ ### Codex
275
+
276
+ Add to `.codex/config.toml` in your project root (per-project) or
277
+ `~/.codex/config.toml` (global):
278
+
279
+ ```toml
280
+ [mcp_servers.graft]
281
+ command = "npx"
282
+ args = ["-y", "@flyingrobots/graft", "serve"]
283
+ startup_timeout_sec = 120
284
+ ```
285
+
286
+ Project-local shortcut:
287
+
288
+ ```bash
289
+ npx @flyingrobots/graft init --write-codex-mcp
290
+ ```
291
+
292
+ That explicit write path also creates or merges `AGENTS.md` with graft
293
+ read guidance so Codex sees repo-local instructions as well as the MCP
294
+ server config.
295
+ If you already have an older graft block in `.codex/config.toml`,
296
+ rerunning that command will add the safer startup timeout without
297
+ duplicating the server entry.
298
+
299
+ The larger startup timeout is intentional. Cold `npx` startup can spend
300
+ enough time in package acquisition and bootstrap to exceed Codex's
301
+ default 30 second budget even when the graft server itself is healthy.
302
+
303
+ **Note:** Codex may ask you to approve external MCP tool calls the
304
+ first time it uses graft. If you trust the local server, choose
305
+ "Always allow" so normal graft tool use does not require a prompt on
306
+ every call.
307
+
308
+ ### Any MCP-compatible client
309
+
310
+ The pattern is the same everywhere:
311
+
312
+ - **Command**: `npx`
313
+ - **Args**: `["-y", "@flyingrobots/graft", "serve"]`
314
+ - **Transport**: stdio (the default for most clients)
315
+
316
+ If your client doesn't support `npx`, install globally and use:
317
+
318
+ - **Command**: `graft`
319
+ - **Args**: `["serve"]`
320
+
321
+ This section shows the repo-local stdio path. If you connect through
322
+ `graft daemon` instead, the MCP session starts `unbound` and needs
323
+ `workspace_authorize` plus `workspace_bind` before repository-scoped
324
+ tool calls.
325
+
326
+ ## Claude Code Hooks
327
+
328
+ Two hooks work together to govern agent reads:
329
+
330
+ - **PreToolUse** — blocks banned files and redirects large JS/TS reads
331
+ before the native read happens
332
+ - **PostToolUse** — backstop education if an oversized code read still
333
+ completes
334
+
335
+ ### Setup
336
+
337
+ Add to `.claude/settings.json` in your project root:
338
+
339
+ ```json
340
+ {
341
+ "hooks": {
342
+ "PreToolUse": [
343
+ {
344
+ "matcher": "Read",
345
+ "hooks": [
346
+ {
347
+ "type": "command",
348
+ "command": "node --import tsx node_modules/@flyingrobots/graft/src/hooks/pretooluse-read.ts"
349
+ }
350
+ ]
351
+ }
352
+ ],
353
+ "PostToolUse": [
354
+ {
355
+ "matcher": "Read",
356
+ "hooks": [
357
+ {
358
+ "type": "command",
359
+ "command": "node --import tsx node_modules/@flyingrobots/graft/src/hooks/posttooluse-read.ts"
360
+ }
361
+ ]
362
+ }
363
+ ]
364
+ }
365
+ }
366
+ ```
367
+
368
+ Project-local shortcut:
369
+
370
+ ```bash
371
+ npx @flyingrobots/graft init --write-claude-hooks
372
+ ```
373
+
374
+ If developing graft itself, replace the `node_modules/...` paths
375
+ with local paths:
376
+
377
+ ```
378
+ src/hooks/pretooluse-read.ts (PreToolUse)
379
+ src/hooks/posttooluse-read.ts (PostToolUse)
380
+ ```
381
+
382
+ ### PreToolUse — ban enforcement
383
+
384
+ When the agent calls `Read(file_path)`, the PreToolUse hook:
385
+
386
+ 1. Evaluates the file against graft's policy
387
+ 2. **Banned files** (binaries, lockfiles, secrets, `.graftignore`
388
+ matches): exits 2 (block) with refusal reason and next steps
389
+ 3. **Large JS/TS files**: exits 2 with a redirect to `safe_read`,
390
+ `file_outline`, and `read_range`
391
+ 4. **Everything else**: exits 0 — lets native Read proceed
392
+
393
+ This is the current "default governed" path for Claude Code: large
394
+ code reads are redirected before the full file lands in context.
395
+ Other file types and other clients still rely on MCP usage or future
396
+ integration work.
397
+
398
+ ### PostToolUse — backstop education
399
+
400
+ After a Read completes, the PostToolUse hook evaluates what
401
+ `safe_read` would have done for large JS/TS files and tells the agent
402
+ the cost:
403
+
404
+ ```
405
+ [graft] This large code read bypassed graft's governed path for src/mcp/server.ts.
406
+ safe_read would have returned a structural outline (2048 bytes) instead of 450 lines (18.0KB),
407
+ saving 16.0KB of context. Threshold: 150 lines / 12KB.
408
+ ```
409
+
410
+ This feedback appears only if an oversized JS/TS read still completes.
411
+ With a working PreToolUse hook, that should be a backstop signal rather
412
+ than the normal path. Small files, non-JS/TS files, and nonexistent
413
+ files produce no feedback. The hook always exits 0 — it never blocks.
414
+
415
+ ### Limitations
416
+
417
+ Both hooks run as standalone processes — they do not share state
418
+ with the MCP server. This means:
419
+
420
+ - No session-depth dynamic caps (early/mid/late)
421
+ - No re-read suppression or cache hits
422
+ - No structural diffs on changed files
423
+ - No metrics tracking or receipts
424
+
425
+ For the full experience, agents should use graft's MCP tools
426
+ (`safe_read`, `file_outline`, `read_range`) directly. The hooks
427
+ make Claude closer to a default-governed path for large code reads, but
428
+ the MCP server remains the full governor and non-Claude clients still
429
+ need explicit integration.
430
+
431
+ ### Disabling
432
+
433
+ To disable hooks locally without removing the project config,
434
+ add to `.claude/settings.local.json`:
435
+
436
+ ```json
437
+ {
438
+ "hooks": {}
439
+ }
440
+ ```
441
+
442
+ ## Tool Reference
443
+
444
+ | Tool | Description |
445
+ |------|-------------|
446
+ | `safe_read` | Policy-enforced file read. Returns full content for small files, structural outline with jump table for large files, or refusal with reason code for banned files. Detects re-reads and returns cached outlines or structural diffs. |
447
+ | `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. |
448
+ | `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. |
449
+ | `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. |
450
+ | `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`. |
451
+ | `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`. |
452
+ | `graft_map` | Structural directory map of files and symbols under a path, with explicit denied-file reporting. |
453
+ | `code_show` | Focus on a symbol by name and return its source with line metadata. |
454
+ | `code_find` | Search symbols across the project by approximate name or glob pattern, with optional kind/path filter. |
455
+ | `code_refs` | Search import sites, callsites, property access, or literal text references with explicit text-fallback provenance, pattern, and scope. |
456
+ | `activity_view` | Bounded between-commit activity for the active workspace, including commit anchor, grouped recent activity, and degraded posture. |
457
+ | `doctor` | Runtime health check including layered-worldline repo state and burden summary. |
458
+ | `stats` | Decision metrics for the current server session, including burden by tool kind. |
459
+ | `explain` | Human-readable meaning and recommended action for a reason code. |
460
+ | `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. |
461
+ | `state_save` | Save session working state (max 8 KB). Use for session bookmarks: current task, files modified, next planned actions. |
462
+ | `state_load` | Load previously saved session state. Returns null if no state has been saved. |
463
+
464
+ MCP responses include versioned `_schema` metadata and `_receipt`
465
+ fields. CLI peer commands also return versioned `_schema` metadata;
466
+ the declared contracts live in `src/contracts/output-schemas.ts`.
467
+ | `doctor` | Runtime health check. Shows project root, parser status, active thresholds, session depth, message count, and a compact burden summary. |
468
+ | `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. |
469
+ | `explain` | Explain a graft reason code. Returns human-readable meaning and recommended next action for any code (e.g., `BINARY`, `BUDGET_CAP`). Case-insensitive. |
470
+ | `stats` | Decision metrics for the current session. Total reads, outlines, refusals, cache hits, bytes avoided, and returned-byte burden by tool kind. |
471
+
472
+ Every MCP tool response includes:
473
+ - `_receipt` — runtime decision metadata
474
+ - `_schema` — versioned output contract metadata
475
+
476
+ Declared output contracts live in `src/contracts/output-schemas.ts`.
477
+ | `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`. |
478
+ | `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`. |
479
+
480
+ ## What the agent sees
481
+
482
+ Once configured, the agent gains 17 MCP tools. Here's what
483
+ happens when it uses them:
484
+
485
+ ### Reading files
486
+
487
+ The agent calls `safe_read` instead of reading files directly.
488
+ Graft decides what to return:
489
+
490
+ - **Small files** (< 150 lines, < 12 KB): full content, as normal.
491
+ - **Large files**: a structural outline showing function signatures,
492
+ class shapes, and exports — with a jump table mapping each symbol
493
+ to its line range. The agent can then use `read_range` to read
494
+ specific sections.
495
+ - **Banned files** (binaries, lockfiles, `.env`, minified bundles,
496
+ build output): refused with a reason code and suggested
497
+ alternatives.
498
+ - **Re-reads**: if the agent reads the same unchanged file twice,
499
+ graft returns the cached outline instead of the full content.
500
+ If the file changed, it returns a structural diff (added/removed/
501
+ changed symbols).
502
+
503
+ ### Structural memory (WARP)
504
+
505
+ `graft_since` shows what changed structurally between any two git
506
+ refs — symbols added, removed, and changed per file. Policy-denied
507
+ files are excluded from the visible file list and reported explicitly
508
+ in `refused`.
509
+
510
+ `graft_map` gives a structural map of any directory — every file
511
+ and its symbols (function signatures, class shapes, exports) in
512
+ one call. Denied files are surfaced explicitly instead of silently
513
+ disappearing.
514
+
515
+ Both tools work on the current working tree. For persistent
516
+ structural indexing across git history, use `graft index` from the
517
+ CLI.
518
+
519
+ ### Structural navigation
520
+
521
+ `file_outline` returns the structural skeleton of any file —
522
+ function signatures, class members, exports — without the bodies.
523
+ Each symbol has a line range so the agent can follow up with
524
+ `read_range` for the specific code it needs.
525
+
526
+ ### Git diffs
527
+
528
+ `graft_diff` shows what changed between git refs at the symbol
529
+ level: "function `foo` gained a parameter" instead of line hunks.
530
+ Denied files are excluded from the visible diff and reported in
531
+ `refused`.
532
+
533
+ ### Budget governor
534
+
535
+ If the agent calls `set_budget(bytes)` at session start, graft
536
+ tracks cumulative bytes consumed and tightens thresholds as the
537
+ budget drains. No single read may consume more than 5% of remaining
538
+ budget. When the budget is exhausted, all reads return outlines.
539
+
540
+ Budget status appears in every receipt:
541
+ ```json
542
+ "budget": { "total": 500000, "consumed": 14345, "remaining": 485655, "fraction": 0.029 }
543
+ ```
544
+
545
+ ### Session awareness
546
+
547
+ Graft tracks the session and tightens policy as context pressure
548
+ grows:
549
+
550
+ | Session stage | Max read size |
551
+ |---------------|---------------|
552
+ | Early (< 100 messages) | 20 KB |
553
+ | Mid (100–500 messages) | 10 KB |
554
+ | Late (> 500 messages) | 4 KB |
555
+
556
+ Tripwires warn when sessions are going off the rails (> 500
557
+ messages, edit-bash loops, runaway tool calls).
558
+
559
+ ### Receipts
560
+
561
+ Every response includes a `_receipt` block with session ID,
562
+ trace ID, sequence number, latency, projection type, bytes
563
+ returned, and cumulative counters. This is for usage analysis and
564
+ correlation — you can usually ignore it.
565
+
566
+ If MCP runtime observability is enabled, `traceId` and `seq` line up
567
+ with `.graft/logs/mcp-runtime.ndjson`. `doctor` also reports the
568
+ current runtime log path and policy.
569
+
570
+ ## Configuration
571
+
572
+ ### .graftignore
573
+
574
+ Create a `.graftignore` file in your project root to ban
575
+ additional file patterns:
576
+
577
+ ```text
578
+ # Generated files
579
+ *.generated.ts
580
+ *.snap
581
+
582
+ # Vendor code
583
+ vendor/**
584
+
585
+ # Large data files
586
+ data/**/*.json
587
+ ```
588
+
589
+ Patterns follow the same syntax as `.gitignore` (glob matching
590
+ via picomatch).
591
+
592
+ ### Policy defaults
593
+
594
+ | Setting | Default | Description |
595
+ |---------|---------|-------------|
596
+ | Line threshold | 150 | Files over this → outline |
597
+ | Byte threshold | 12 KB | Files over this → outline |
598
+ | Max range | 250 lines | read_range cap |
599
+ | State cap | 8 KB | state_save max size |
600
+ | Capture tail | 60 lines | run_capture default |
601
+
602
+ These are not yet configurable at runtime (planned for a future
603
+ release).
604
+
605
+ ### run_capture posture
606
+
607
+ `run_capture` is a diagnostic shell escape hatch, not a bounded-read
608
+ tool. For broader or more sensitive deployments:
609
+
610
+ - set `GRAFT_ENABLE_RUN_CAPTURE=0` to disable execution entirely
611
+ - set `GRAFT_RUN_CAPTURE_PERSIST=0` to avoid writing `.graft/logs/capture.log`
612
+ - persisted capture output is redacted for obvious secret-shaped values
613
+ by default
614
+
615
+ In the local daemon runtime, `run_capture` stays disabled by default and
616
+ requires an explicit operator-authorized capability profile rather than
617
+ inheriting local repo-scoped trust.
618
+
619
+ ### MCP runtime observability
620
+
621
+ MCP runtime observability writes metadata-only session and tool-call
622
+ events to `.graft/logs/mcp-runtime.ndjson`. The log intentionally does
623
+ not include raw file content, query text, or other request payload
624
+ values.
625
+
626
+ - set `GRAFT_ENABLE_MCP_RUNTIME_LOG=0` to disable MCP runtime logging
627
+ - set `GRAFT_MCP_RUNTIME_LOG_PATH=/abs/path/mcp-runtime.ndjson` to move
628
+ the log
629
+ - set `GRAFT_MCP_RUNTIME_LOG_MAX_BYTES=2097152` to change retention size
630
+
631
+ ## Troubleshooting
632
+
633
+ ### "Tool not found" or no graft tools visible
634
+
635
+ - Verify the CLI is installed: `npx @flyingrobots/graft --help`
636
+ - Verify the MCP transport starts: `npx @flyingrobots/graft serve`
637
+ (should start the server; Ctrl+C to stop)
638
+ - Check your MCP config syntax — JSON must be valid
639
+ - Restart your editor/agent after adding MCP config
640
+ - Some clients cache tool lists — try reopening the project
641
+
642
+ ### Codex says `user cancelled MCP tool call`
643
+
644
+ This can be a Codex approval issue rather than a graft failure.
645
+ Codex may require permission for external MCP tool calls. If those
646
+ prompts are denied, or cannot be shown in a non-interactive run, the
647
+ tool call may appear as cancelled.
648
+
649
+ - Run Codex interactively and approve graft tool calls
650
+ - If you trust the server, choose "Always allow" for graft
651
+ - Retry the call after granting permission
652
+ - If graft still fails, run `doctor` first to separate Codex setup
653
+ problems from graft runtime problems
654
+
655
+ ### Agent keeps getting outlines instead of content
656
+
657
+ Your files are over 150 lines or 12 KB. This is intentional.
658
+ The agent should use the jump table from the outline to
659
+ `read_range` the specific section it needs.
660
+
661
+ ### Agent can't read a file (refused)
662
+
663
+ Check the reason code in the response:
664
+ - `BINARY` — binary file, use `ls -lh` or `file` for metadata
665
+ - `LOCKFILE` — read `package.json` instead
666
+ - `SECRET` — `.env` files are banned for safety
667
+ - `BUILD_OUTPUT` — read the source file, not `dist/`
668
+ - `UNSUPPORTED_LANGUAGE` — no parser-backed outline exists for this file type yet; use `read_range` or a full read when appropriate
669
+ - `GRAFTIGNORE` — file matches a `.graftignore` pattern
670
+
671
+ ### run_capture is disabled
672
+
673
+ If `run_capture` returns `run_capture is disabled by configuration`,
674
+ the server was started with shell capture turned off.
675
+
676
+ - local repo-scoped sessions can re-enable it by unsetting
677
+ `GRAFT_ENABLE_RUN_CAPTURE=0`
678
+ - shared or harder security postures should generally leave it disabled
679
+
680
+ ### graft is slow on first call
681
+
682
+ Tree-sitter WASM grammars load on first parse (~200ms). Subsequent
683
+ calls are fast.
684
+
685
+ ## Verify it works
686
+
687
+ After setup, ask your agent to read a large file in your project.
688
+ Instead of dumping the entire file, it should return an outline
689
+ with a jump table. That's graft working.
690
+
691
+ You can also ask the agent to call `doctor` to verify:
692
+
693
+ ```
694
+ Use the doctor tool to check graft's health.
695
+ ```
696
+
697
+ This returns the project root, parser status, active thresholds,
698
+ and session depth.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flyingrobots/graft",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "Context governor and between-commit activity surface for coding agents",
5
5
  "type": "module",
6
6
  "packageManager": "pnpm@10.30.0",
@@ -21,16 +21,17 @@
21
21
  "bin/",
22
22
  "dist/",
23
23
  "src/",
24
+ "ADVANCED_GUIDE.md",
24
25
  "ARCHITECTURE.md",
26
+ "CHANGELOG.md",
25
27
  "CODE_OF_CONDUCT.md",
26
- "docs/ADVANCED_GUIDE.md",
28
+ "GUIDE.md",
27
29
  "docs/CLI.md",
28
- "docs/GUIDE.md",
29
30
  "docs/MCP.md",
31
+ "docs/SETUP.md",
30
32
  "LICENSE",
31
33
  "NOTICE",
32
- "README.md",
33
- "CHANGELOG.md"
34
+ "README.md"
34
35
  ],
35
36
  "scripts": {
36
37
  "graft": "node ./bin/graft.js",