@flyingrobots/graft 0.7.0 → 0.7.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.
Files changed (283) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +0 -1
  3. package/bin/graft.js +26 -26
  4. package/dist/cli/init-client-config.d.ts.map +1 -1
  5. package/dist/cli/init-client-config.js +40 -4
  6. package/dist/cli/init-client-config.js.map +1 -1
  7. package/dist/cli/init-model.js +2 -2
  8. package/dist/cli/init-model.js.map +1 -1
  9. package/dist/cli/json-document.d.ts +1 -0
  10. package/dist/cli/json-document.d.ts.map +1 -1
  11. package/dist/cli/json-document.js +3 -0
  12. package/dist/cli/json-document.js.map +1 -1
  13. package/dist/hooks/posttooluse-read.js +1 -1
  14. package/dist/hooks/posttooluse-read.js.map +1 -1
  15. package/dist/hooks/pretooluse-read.js +1 -1
  16. package/dist/hooks/pretooluse-read.js.map +1 -1
  17. package/dist/mcp/daemon-worker-child-pool.d.ts +2 -0
  18. package/dist/mcp/daemon-worker-child-pool.d.ts.map +1 -1
  19. package/dist/mcp/daemon-worker-child-pool.js +10 -3
  20. package/dist/mcp/daemon-worker-child-pool.js.map +1 -1
  21. package/dist/mcp/daemon-worker-pool.d.ts +1 -1
  22. package/dist/mcp/daemon-worker-pool.d.ts.map +1 -1
  23. package/dist/mcp/daemon-worker-pool.js +1 -1
  24. package/dist/mcp/daemon-worker-pool.js.map +1 -1
  25. package/dist/version.d.ts.map +1 -1
  26. package/dist/version.js +3 -1
  27. package/dist/version.js.map +1 -1
  28. package/docs/SETUP.md +11 -7
  29. package/package.json +9 -4
  30. package/src/adapters/canonical-json.ts +0 -56
  31. package/src/adapters/json-text-decoder.ts +0 -11
  32. package/src/adapters/node-fs.ts +0 -43
  33. package/src/adapters/node-git.ts +0 -47
  34. package/src/adapters/node-paths.ts +0 -35
  35. package/src/adapters/node-process-runner.ts +0 -27
  36. package/src/adapters/repo-paths.ts +0 -63
  37. package/src/adapters/rotating-ndjson-log.ts +0 -66
  38. package/src/api/index.ts +0 -107
  39. package/src/api/repo-local-graft.ts +0 -21
  40. package/src/api/repo-workspace.ts +0 -34
  41. package/src/api/tool-bridge.ts +0 -22
  42. package/src/cli/activity-render.ts +0 -112
  43. package/src/cli/cli-error.ts +0 -192
  44. package/src/cli/command-parser.ts +0 -484
  45. package/src/cli/daemon-status-model.ts +0 -238
  46. package/src/cli/daemon-status-render.ts +0 -102
  47. package/src/cli/daemon-status.ts +0 -100
  48. package/src/cli/entrypoint.ts +0 -18
  49. package/src/cli/git-graft-enhance-model.ts +0 -131
  50. package/src/cli/git-graft-enhance-render.ts +0 -33
  51. package/src/cli/git-graft-enhance.ts +0 -54
  52. package/src/cli/index-cmd.ts +0 -90
  53. package/src/cli/index-model.ts +0 -75
  54. package/src/cli/init-bootstrap.ts +0 -47
  55. package/src/cli/init-client-config.ts +0 -428
  56. package/src/cli/init-model.ts +0 -284
  57. package/src/cli/init-render.ts +0 -54
  58. package/src/cli/init-target-hooks.ts +0 -93
  59. package/src/cli/init.ts +0 -124
  60. package/src/cli/json-document.ts +0 -155
  61. package/src/cli/local-history-dag-model.ts +0 -437
  62. package/src/cli/local-history-dag-render.ts +0 -133
  63. package/src/cli/local-history-dag.ts +0 -103
  64. package/src/cli/main.ts +0 -197
  65. package/src/cli/migrate-local-history.ts +0 -119
  66. package/src/cli/peer-command.ts +0 -60
  67. package/src/contracts/capabilities.ts +0 -540
  68. package/src/contracts/causal-ontology.ts +0 -627
  69. package/src/contracts/causal-surface-next-action.ts +0 -18
  70. package/src/contracts/json-object.ts +0 -18
  71. package/src/contracts/mcp-runtime.ts +0 -16
  72. package/src/contracts/output-schema-cli.ts +0 -103
  73. package/src/contracts/output-schema-fragments.ts +0 -881
  74. package/src/contracts/output-schema-mcp.ts +0 -501
  75. package/src/contracts/output-schema-meta.ts +0 -119
  76. package/src/contracts/output-schemas.ts +0 -1524
  77. package/src/git/diff.ts +0 -161
  78. package/src/git/target-git-hook-bootstrap.ts +0 -56
  79. package/src/guards/stream-boundary.ts +0 -110
  80. package/src/hooks/posttooluse-read.ts +0 -54
  81. package/src/hooks/pretooluse-read.ts +0 -52
  82. package/src/hooks/read-governor.ts +0 -95
  83. package/src/hooks/read-messages.ts +0 -53
  84. package/src/hooks/shared.ts +0 -168
  85. package/src/index.ts +0 -1
  86. package/src/mcp/burden.ts +0 -132
  87. package/src/mcp/cache.ts +0 -7
  88. package/src/mcp/cached-file.ts +0 -1
  89. package/src/mcp/context.ts +0 -150
  90. package/src/mcp/control-plane/authz-storage.ts +0 -129
  91. package/src/mcp/control-plane/session-registry.ts +0 -115
  92. package/src/mcp/control-plane/status-projection.ts +0 -76
  93. package/src/mcp/control-plane/types.ts +0 -144
  94. package/src/mcp/daemon-bootstrap.ts +0 -100
  95. package/src/mcp/daemon-control-plane.ts +0 -310
  96. package/src/mcp/daemon-job-scheduler.ts +0 -279
  97. package/src/mcp/daemon-repos.ts +0 -99
  98. package/src/mcp/daemon-server.ts +0 -172
  99. package/src/mcp/daemon-session-host.ts +0 -234
  100. package/src/mcp/daemon-stdio-bridge.ts +0 -262
  101. package/src/mcp/daemon-worker-child-pool.ts +0 -213
  102. package/src/mcp/daemon-worker-inline-pool.ts +0 -46
  103. package/src/mcp/daemon-worker-pool.ts +0 -7
  104. package/src/mcp/daemon-worker-process.ts +0 -52
  105. package/src/mcp/daemon-worker-types.ts +0 -66
  106. package/src/mcp/metrics.ts +0 -176
  107. package/src/mcp/monitor-health.ts +0 -83
  108. package/src/mcp/monitor-persistence.ts +0 -54
  109. package/src/mcp/monitor-tick-job.ts +0 -153
  110. package/src/mcp/monitor-types.ts +0 -103
  111. package/src/mcp/persisted-local-history-graph.ts +0 -592
  112. package/src/mcp/persisted-local-history-policy.ts +0 -501
  113. package/src/mcp/persisted-local-history-views.ts +0 -250
  114. package/src/mcp/persisted-local-history.ts +0 -1621
  115. package/src/mcp/persistent-monitor-runtime.ts +0 -482
  116. package/src/mcp/policy.ts +0 -75
  117. package/src/mcp/receipt.ts +0 -201
  118. package/src/mcp/repo-concurrency.ts +0 -392
  119. package/src/mcp/repo-overview/filter.ts +0 -44
  120. package/src/mcp/repo-overview/types.ts +0 -63
  121. package/src/mcp/repo-overview/view-projection.ts +0 -90
  122. package/src/mcp/repo-state-git.ts +0 -247
  123. package/src/mcp/repo-state-observation.ts +0 -203
  124. package/src/mcp/repo-state-transition.ts +0 -151
  125. package/src/mcp/repo-state-types.ts +0 -107
  126. package/src/mcp/repo-state.ts +0 -146
  127. package/src/mcp/repo-tool-job.ts +0 -102
  128. package/src/mcp/repo-tool-worker-context.ts +0 -215
  129. package/src/mcp/repo-workspace.ts +0 -21
  130. package/src/mcp/run-capture-config.ts +0 -33
  131. package/src/mcp/runtime-causal-context.ts +0 -72
  132. package/src/mcp/runtime-observability.ts +0 -217
  133. package/src/mcp/runtime-staged-target.ts +0 -161
  134. package/src/mcp/runtime-workspace-overlay.ts +0 -255
  135. package/src/mcp/secret-scrub.ts +0 -89
  136. package/src/mcp/semantic-transition-guidance.ts +0 -60
  137. package/src/mcp/semantic-transition-summary.ts +0 -130
  138. package/src/mcp/server-context.ts +0 -236
  139. package/src/mcp/server-invocation.ts +0 -388
  140. package/src/mcp/server-tool-access.ts +0 -148
  141. package/src/mcp/server.ts +0 -270
  142. package/src/mcp/stdio-server.ts +0 -26
  143. package/src/mcp/stdio.ts +0 -3
  144. package/src/mcp/tool-registry.ts +0 -98
  145. package/src/mcp/tools/activity-view.ts +0 -325
  146. package/src/mcp/tools/budget.ts +0 -23
  147. package/src/mcp/tools/causal-attach.ts +0 -67
  148. package/src/mcp/tools/causal-status.ts +0 -58
  149. package/src/mcp/tools/changed-since.ts +0 -71
  150. package/src/mcp/tools/code-find.ts +0 -192
  151. package/src/mcp/tools/code-refs.ts +0 -470
  152. package/src/mcp/tools/code-show.ts +0 -289
  153. package/src/mcp/tools/daemon-monitors.ts +0 -14
  154. package/src/mcp/tools/daemon-repos.ts +0 -22
  155. package/src/mcp/tools/daemon-sessions.ts +0 -14
  156. package/src/mcp/tools/daemon-status.ts +0 -12
  157. package/src/mcp/tools/diagnostic-models.ts +0 -97
  158. package/src/mcp/tools/doctor.ts +0 -83
  159. package/src/mcp/tools/explain.ts +0 -84
  160. package/src/mcp/tools/export-surface-diff.ts +0 -26
  161. package/src/mcp/tools/file-outline.ts +0 -67
  162. package/src/mcp/tools/git-files.ts +0 -73
  163. package/src/mcp/tools/graft-diff.ts +0 -35
  164. package/src/mcp/tools/graft-edit.ts +0 -276
  165. package/src/mcp/tools/knowledge-map.ts +0 -34
  166. package/src/mcp/tools/map-collector.ts +0 -338
  167. package/src/mcp/tools/map.ts +0 -185
  168. package/src/mcp/tools/monitor-nudge.ts +0 -19
  169. package/src/mcp/tools/monitor-pause.ts +0 -18
  170. package/src/mcp/tools/monitor-resume.ts +0 -18
  171. package/src/mcp/tools/monitor-start.ts +0 -20
  172. package/src/mcp/tools/monitor-stop.ts +0 -18
  173. package/src/mcp/tools/precision-live.ts +0 -158
  174. package/src/mcp/tools/precision-match.ts +0 -54
  175. package/src/mcp/tools/precision-paths.ts +0 -59
  176. package/src/mcp/tools/precision-query.ts +0 -127
  177. package/src/mcp/tools/precision-show.ts +0 -86
  178. package/src/mcp/tools/precision-visibility.ts +0 -44
  179. package/src/mcp/tools/precision-warp.ts +0 -101
  180. package/src/mcp/tools/precision.ts +0 -21
  181. package/src/mcp/tools/read-range.ts +0 -28
  182. package/src/mcp/tools/refactor-difficulty.ts +0 -42
  183. package/src/mcp/tools/run-capture.ts +0 -149
  184. package/src/mcp/tools/safe-read.ts +0 -148
  185. package/src/mcp/tools/since.ts +0 -53
  186. package/src/mcp/tools/state.ts +0 -39
  187. package/src/mcp/tools/stats.ts +0 -24
  188. package/src/mcp/tools/structural-blame.ts +0 -55
  189. package/src/mcp/tools/structural-churn.ts +0 -28
  190. package/src/mcp/tools/structural-log.ts +0 -41
  191. package/src/mcp/tools/structural-review.ts +0 -63
  192. package/src/mcp/tools/workspace-authorizations.ts +0 -14
  193. package/src/mcp/tools/workspace-authorize.ts +0 -20
  194. package/src/mcp/tools/workspace-bind.ts +0 -25
  195. package/src/mcp/tools/workspace-rebind.ts +0 -25
  196. package/src/mcp/tools/workspace-revoke.ts +0 -18
  197. package/src/mcp/tools/workspace-status.ts +0 -12
  198. package/src/mcp/warp-pool.ts +0 -36
  199. package/src/mcp/workspace-read-observation-model.ts +0 -48
  200. package/src/mcp/workspace-read-observation.ts +0 -103
  201. package/src/mcp/workspace-router-capability.ts +0 -32
  202. package/src/mcp/workspace-router-history.ts +0 -233
  203. package/src/mcp/workspace-router-model.ts +0 -131
  204. package/src/mcp/workspace-router-resolution.ts +0 -71
  205. package/src/mcp/workspace-router-runtime.ts +0 -246
  206. package/src/mcp/workspace-router.ts +0 -688
  207. package/src/metrics/logger.ts +0 -40
  208. package/src/metrics/types.ts +0 -40
  209. package/src/operations/adaptive-projection.ts +0 -54
  210. package/src/operations/agent-handoff.ts +0 -59
  211. package/src/operations/cached-file.ts +0 -40
  212. package/src/operations/capture-range.ts +0 -64
  213. package/src/operations/conversation-primer.ts +0 -82
  214. package/src/operations/cross-session-resume.ts +0 -104
  215. package/src/operations/deterministic-replay.ts +0 -143
  216. package/src/operations/diff-identity.ts +0 -127
  217. package/src/operations/export-surface-diff.ts +0 -355
  218. package/src/operations/file-outline.ts +0 -48
  219. package/src/operations/footprint-parallelism.ts +0 -98
  220. package/src/operations/graft-diff.ts +0 -169
  221. package/src/operations/horizon-of-readability.ts +0 -60
  222. package/src/operations/import-reference-impact.ts +0 -143
  223. package/src/operations/knowledge-map.ts +0 -96
  224. package/src/operations/observation-cache.ts +0 -165
  225. package/src/operations/projection-safety.ts +0 -111
  226. package/src/operations/read-range.ts +0 -64
  227. package/src/operations/repo-workspace.ts +0 -339
  228. package/src/operations/result-dto.ts +0 -23
  229. package/src/operations/safe-read.ts +0 -118
  230. package/src/operations/semantic-drift.ts +0 -70
  231. package/src/operations/session-filtration.ts +0 -76
  232. package/src/operations/session-replay.ts +0 -73
  233. package/src/operations/sludge-detector.ts +0 -356
  234. package/src/operations/state.ts +0 -66
  235. package/src/operations/structural-blame.ts +0 -197
  236. package/src/operations/structural-review.ts +0 -317
  237. package/src/operations/structured-buffer-compare.ts +0 -429
  238. package/src/operations/structured-buffer-model.ts +0 -456
  239. package/src/operations/structured-buffer-query.ts +0 -794
  240. package/src/operations/structured-buffer.ts +0 -181
  241. package/src/operations/teaching-hints.ts +0 -52
  242. package/src/parser/diff.ts +0 -320
  243. package/src/parser/lang.ts +0 -71
  244. package/src/parser/markdown.ts +0 -197
  245. package/src/parser/outline.ts +0 -316
  246. package/src/parser/runtime.ts +0 -71
  247. package/src/parser/types.ts +0 -75
  248. package/src/policy/evaluate.ts +0 -178
  249. package/src/policy/graftignore.ts +0 -6
  250. package/src/policy/types.ts +0 -87
  251. package/src/ports/codec.ts +0 -13
  252. package/src/ports/filesystem.ts +0 -18
  253. package/src/ports/git.ts +0 -16
  254. package/src/ports/guards.ts +0 -68
  255. package/src/ports/paths.ts +0 -22
  256. package/src/ports/process-runner.ts +0 -22
  257. package/src/release/security-gate.ts +0 -102
  258. package/src/session/tracker.ts +0 -145
  259. package/src/session/types.ts +0 -23
  260. package/src/version.ts +0 -3
  261. package/src/warp/ast-emitter.ts +0 -133
  262. package/src/warp/ast-import-resolver.ts +0 -333
  263. package/src/warp/commit-meta.ts +0 -19
  264. package/src/warp/context.ts +0 -48
  265. package/src/warp/dead-symbols.ts +0 -174
  266. package/src/warp/drift-sentinel.ts +0 -101
  267. package/src/warp/index-head.ts +0 -348
  268. package/src/warp/observers.ts +0 -101
  269. package/src/warp/open.ts +0 -67
  270. package/src/warp/outline-diff-trailer.ts +0 -100
  271. package/src/warp/plumbing.d.ts +0 -24
  272. package/src/warp/refactor-difficulty.ts +0 -257
  273. package/src/warp/references.ts +0 -77
  274. package/src/warp/stale-docs.ts +0 -210
  275. package/src/warp/structural-drift-detection.ts +0 -97
  276. package/src/warp/structural-queries.ts +0 -258
  277. package/src/warp/symbol-timeline.ts +0 -209
  278. package/src/warp/traverse-hydrate.ts +0 -61
  279. package/src/warp/warp-reference-count.ts +0 -47
  280. package/src/warp/warp-structural-blame.ts +0 -65
  281. package/src/warp/warp-structural-churn.ts +0 -309
  282. package/src/warp/warp-structural-log.ts +0 -149
  283. package/src/warp/writer-id.ts +0 -30
@@ -1,284 +0,0 @@
1
- export type JsonPrimitive = string | number | boolean | null;
2
- export type JsonArrayValue = JsonValue[];
3
- export type JsonValue = JsonPrimitive | JsonArrayValue | JsonObjectValue;
4
-
5
- export interface JsonObjectValue {
6
- [key: string]: JsonValue | undefined;
7
- }
8
-
9
- type InitActionKind = "exists" | "create" | "append";
10
- export type GraftMcpRuntime = "repo-local" | "daemon";
11
-
12
- export class InitAction {
13
- constructor(
14
- readonly action: InitActionKind,
15
- readonly label: string,
16
- readonly detail?: string,
17
- ) {}
18
-
19
- static create(label: string, detail?: string): InitAction {
20
- return new InitAction("create", label, detail);
21
- }
22
-
23
- static append(label: string, detail?: string): InitAction {
24
- return new InitAction("append", label, detail);
25
- }
26
-
27
- static exists(label: string, detail?: string): InitAction {
28
- return new InitAction("exists", label, detail);
29
- }
30
- }
31
-
32
- export class InitFailure {
33
- readonly ok = false;
34
-
35
- constructor(
36
- readonly cwd: string,
37
- readonly error: string,
38
- ) {}
39
-
40
- toJSON(): JsonObjectValue {
41
- return {
42
- ok: this.ok,
43
- cwd: this.cwd,
44
- error: this.error,
45
- };
46
- }
47
- }
48
-
49
- function consumeFlag(args: string[], flag: string): boolean {
50
- const index = args.indexOf(flag);
51
- if (index === -1) {
52
- return false;
53
- }
54
- args.splice(index, 1);
55
- return true;
56
- }
57
-
58
- function consumeOption(args: string[], flag: string): string | undefined {
59
- const index = args.indexOf(flag);
60
- if (index === -1) {
61
- return undefined;
62
- }
63
- if (index === args.length - 1) {
64
- throw new Error(`Missing value for ${flag}`);
65
- }
66
- const [value] = args.splice(index, 2).slice(1);
67
- return value;
68
- }
69
-
70
- function parseMcpRuntime(raw: string | undefined): { runtime: GraftMcpRuntime; explicit: boolean } {
71
- if (raw === undefined) {
72
- return { runtime: "repo-local", explicit: false };
73
- }
74
- if (raw === "repo-local" || raw === "daemon") {
75
- return { runtime: raw, explicit: true };
76
- }
77
- throw new Error(`--mcp-runtime must be repo-local or daemon, got ${raw}`);
78
- }
79
-
80
- export class ParsedInitArgs {
81
- constructor(
82
- readonly json: boolean,
83
- readonly mcpRuntime: GraftMcpRuntime,
84
- readonly mcpRuntimeExplicit: boolean,
85
- readonly writeClaudeMcp: boolean,
86
- readonly writeClaudeHooks: boolean,
87
- readonly writeTargetGitHooks: boolean,
88
- readonly writeCodexMcp: boolean,
89
- readonly writeCursorMcp: boolean,
90
- readonly writeWindsurfMcp: boolean,
91
- readonly writeContinueMcp: boolean,
92
- readonly writeClineMcp: boolean,
93
- ) {}
94
-
95
- static parse(rawArgs: readonly string[]): ParsedInitArgs {
96
- const args = [...rawArgs];
97
- const runtime = parseMcpRuntime(consumeOption(args, "--mcp-runtime"));
98
- const parsed = new ParsedInitArgs(
99
- consumeFlag(args, "--json"),
100
- runtime.runtime,
101
- runtime.explicit,
102
- consumeFlag(args, "--write-claude-mcp"),
103
- consumeFlag(args, "--write-claude-hooks"),
104
- consumeFlag(args, "--write-target-git-hooks"),
105
- consumeFlag(args, "--write-codex-mcp"),
106
- consumeFlag(args, "--write-cursor-mcp"),
107
- consumeFlag(args, "--write-windsurf-mcp"),
108
- consumeFlag(args, "--write-continue-mcp"),
109
- consumeFlag(args, "--write-cline-mcp"),
110
- );
111
-
112
- if (args.length > 0) {
113
- throw new Error(`Unknown init arguments: ${args.join(" ")}`);
114
- }
115
-
116
- return parsed;
117
- }
118
-
119
- get writesAnyMcpConfig(): boolean {
120
- return this.writeClaudeMcp
121
- || this.writeCodexMcp
122
- || this.writeCursorMcp
123
- || this.writeWindsurfMcp
124
- || this.writeContinueMcp
125
- || this.writeClineMcp;
126
- }
127
- }
128
-
129
- export class GraftMcpServer {
130
- readonly name = "graft";
131
- readonly command = "npx";
132
- readonly codexStartupTimeoutSec = 120;
133
-
134
- constructor(readonly runtime: GraftMcpRuntime = "repo-local") {}
135
-
136
- get args(): readonly string[] {
137
- return this.runtime === "daemon"
138
- ? ["-y", "@flyingrobots/graft", "serve", "--runtime", "daemon"]
139
- : ["-y", "@flyingrobots/graft", "serve"];
140
- }
141
-
142
- toJsonServerEntry(): JsonObjectValue {
143
- return {
144
- command: this.command,
145
- args: [...this.args],
146
- };
147
- }
148
-
149
- toJsonMcpConfig(): JsonObjectValue {
150
- return {
151
- mcpServers: {
152
- [this.name]: this.toJsonServerEntry(),
153
- },
154
- };
155
- }
156
-
157
- toContinueServerEntry(): JsonObjectValue {
158
- return {
159
- name: this.name,
160
- command: this.command,
161
- args: [...this.args],
162
- };
163
- }
164
-
165
- toContinueConfig(): JsonObjectValue {
166
- return {
167
- mcpServers: [this.toContinueServerEntry()],
168
- };
169
- }
170
-
171
- toCodexTomlBlock(): string {
172
- return [
173
- "[mcp_servers.graft]",
174
- "command = \"npx\"",
175
- this.toCodexTomlArgsLine(),
176
- `startup_timeout_sec = ${String(this.codexStartupTimeoutSec)}`,
177
- "",
178
- ].join("\n");
179
- }
180
-
181
- toCodexTomlArgsLine(): string {
182
- return `args = [${this.args.map((arg) => `"${arg}"`).join(", ")}]`;
183
- }
184
- }
185
-
186
- export class GraftHookCommand {
187
- constructor(readonly command: string) {}
188
-
189
- toJsonValue(): JsonObjectValue {
190
- return {
191
- type: "command",
192
- command: this.command,
193
- };
194
- }
195
- }
196
-
197
- export class GraftHookMatcher {
198
- constructor(
199
- readonly matcher: "Read",
200
- readonly hooks: readonly GraftHookCommand[],
201
- ) {}
202
-
203
- toJsonValue(): JsonObjectValue {
204
- return {
205
- matcher: this.matcher,
206
- hooks: this.hooks.map((hook) => hook.toJsonValue()),
207
- };
208
- }
209
- }
210
-
211
- export class GraftHooksConfig {
212
- constructor(
213
- readonly preToolUse: GraftHookMatcher,
214
- readonly postToolUse: GraftHookMatcher,
215
- ) {}
216
-
217
- toJsonValue(): JsonObjectValue {
218
- return {
219
- hooks: {
220
- PreToolUse: [this.preToolUse.toJsonValue()],
221
- PostToolUse: [this.postToolUse.toJsonValue()],
222
- },
223
- };
224
- }
225
- }
226
-
227
- export const GRAFT_MCP_SERVER = new GraftMcpServer();
228
- export const GRAFT_HOOKS_CONFIG = new GraftHooksConfig(
229
- new GraftHookMatcher("Read", [
230
- new GraftHookCommand("node --import tsx node_modules/@flyingrobots/graft/src/hooks/pretooluse-read.ts"),
231
- ]),
232
- new GraftHookMatcher("Read", [
233
- new GraftHookCommand("node --import tsx node_modules/@flyingrobots/graft/src/hooks/posttooluse-read.ts"),
234
- ]),
235
- );
236
-
237
- export class InitResult {
238
- readonly ok = true;
239
-
240
- constructor(
241
- readonly cwd: string,
242
- readonly actions: readonly InitAction[],
243
- readonly hooksConfig: GraftHooksConfig,
244
- readonly suggestedMcpServer: GraftMcpServer,
245
- ) {}
246
-
247
- toJSON(): JsonObjectValue {
248
- return {
249
- ok: this.ok,
250
- cwd: this.cwd,
251
- actions: this.actions.map((action) => ({
252
- action: action.action,
253
- label: action.label,
254
- ...(action.detail !== undefined ? { detail: action.detail } : {}),
255
- })),
256
- hooksConfig: this.hooksConfig.toJsonValue(),
257
- suggestedMcpServer: this.suggestedMcpServer.toJsonMcpConfig(),
258
- };
259
- }
260
- }
261
-
262
- export function isJsonObjectValue(value: unknown): value is JsonObjectValue {
263
- return typeof value === "object" && value !== null && !Array.isArray(value);
264
- }
265
-
266
- export function cloneJsonValue<T>(value: T): T {
267
- return JSON.parse(JSON.stringify(value)) as T;
268
- }
269
-
270
- export function isGraftMcpServerEntryForRuntime(
271
- value: JsonValue | undefined,
272
- runtime: GraftMcpRuntime,
273
- ): boolean {
274
- if (!isJsonObjectValue(value)) {
275
- return false;
276
- }
277
- const command = value["command"];
278
- const args = value["args"];
279
- const expected = new GraftMcpServer(runtime);
280
- return command === expected.command
281
- && Array.isArray(args)
282
- && args.length === expected.args.length
283
- && args.every((arg, index) => arg === expected.args[index]);
284
- }
@@ -1,54 +0,0 @@
1
- import { CanonicalJsonCodec } from "../adapters/canonical-json.js";
2
- import { attachCliSchemaMeta, validateCliOutput } from "../contracts/output-schemas.js";
3
- import { GRAFT_HOOKS_CONFIG, InitFailure, InitResult, ParsedInitArgs, type JsonObjectValue } from "./init-model.js";
4
-
5
- const codec = new CanonicalJsonCodec();
6
-
7
- interface Writer {
8
- write(chunk: string): unknown;
9
- }
10
-
11
- function writeLine(writer: Writer, line = ""): void {
12
- writer.write(`${line}\n`);
13
- }
14
-
15
- function indentJson(value: unknown, spaces = 2): string {
16
- const json = JSON.stringify(value, null, spaces);
17
- return json.split("\n").map((line) => ` ${line}`).join("\n");
18
- }
19
-
20
- export function renderInitText(result: InitResult, args: ParsedInitArgs, writer: Writer): void {
21
- writeLine(writer);
22
- writeLine(writer, `Initializing graft in ${result.cwd}`);
23
- writeLine(writer);
24
- for (const action of result.actions) {
25
- const detail = action.detail !== undefined ? ` (${action.detail})` : "";
26
- writeLine(writer, ` ${action.action.padEnd(6)} ${action.label}${detail}`);
27
- }
28
- writeLine(writer);
29
-
30
- if (!args.writeClaudeHooks) {
31
- writeLine(writer, "Add to .claude/settings.json for Claude Code hook integration:");
32
- writeLine(writer);
33
- writeLine(writer, JSON.stringify(GRAFT_HOOKS_CONFIG.toJsonValue(), null, 2));
34
- writeLine(writer);
35
- }
36
-
37
- if (!args.writesAnyMcpConfig) {
38
- writeLine(writer, "Done. Add graft to your MCP config:");
39
- writeLine(writer);
40
- writeLine(writer, indentJson(result.suggestedMcpServer.toJsonMcpConfig()));
41
- writeLine(writer);
42
- writeLine(writer, "Use explicit --write-*-mcp flags or --write-claude-hooks");
43
- writeLine(writer, "or --write-target-git-hooks for one-step bootstrap into project-local config files.");
44
- }
45
-
46
- writeLine(writer);
47
- }
48
-
49
- export function emitInitJson(result: JsonObjectValue | InitFailure, writer: Writer): void {
50
- const payload = result instanceof InitFailure
51
- ? result.toJSON()
52
- : result;
53
- writer.write(`${codec.encode(validateCliOutput("init", attachCliSchemaMeta("init", payload)))}\n`);
54
- }
@@ -1,93 +0,0 @@
1
- import * as fs from "node:fs";
2
- import * as path from "node:path";
3
- import { execFileSync } from "node:child_process";
4
- import {
5
- buildTargetGitHookScript,
6
- isRecognizedTargetGitHook,
7
- resolveGitHooksPath,
8
- TARGET_GIT_TRANSITION_HOOKS,
9
- } from "../git/target-git-hook-bootstrap.js";
10
- import { InitAction } from "./init-model.js";
11
-
12
- function readGitValue(cwd: string, args: readonly string[]): string | null {
13
- try {
14
- const value = execFileSync("git", [...args], {
15
- cwd,
16
- encoding: "utf-8",
17
- stdio: ["ignore", "pipe", "ignore"],
18
- }).trim();
19
- return value.length > 0 ? value : null;
20
- } catch {
21
- return null;
22
- }
23
- }
24
-
25
- function relativeLabel(cwd: string, filePath: string): string {
26
- const relative = path.relative(cwd, filePath);
27
- if (relative.length === 0 || relative.startsWith("..")) {
28
- return filePath;
29
- }
30
- return relative;
31
- }
32
-
33
- function resolveTargetGitHooksDirectory(cwd: string): {
34
- configuredCoreHooksPath: string | null;
35
- resolvedHooksPath: string;
36
- } {
37
- const worktreeRoot = readGitValue(cwd, [
38
- "rev-parse",
39
- "--path-format=absolute",
40
- "--show-toplevel",
41
- ]);
42
- const gitCommonDir = readGitValue(cwd, [
43
- "rev-parse",
44
- "--path-format=absolute",
45
- "--git-common-dir",
46
- ]);
47
- if (worktreeRoot === null || gitCommonDir === null) {
48
- throw new Error("--write-target-git-hooks requires a git worktree");
49
- }
50
-
51
- const configuredCoreHooksPath = readGitValue(cwd, ["config", "--get", "core.hooksPath"]);
52
- return {
53
- configuredCoreHooksPath,
54
- resolvedHooksPath: resolveGitHooksPath(
55
- worktreeRoot,
56
- gitCommonDir,
57
- configuredCoreHooksPath,
58
- ),
59
- };
60
- }
61
-
62
- export function ensureTargetGitHooks(cwd: string): InitAction[] {
63
- const { resolvedHooksPath } = resolveTargetGitHooksDirectory(cwd);
64
- const actions: InitAction[] = [];
65
- fs.mkdirSync(resolvedHooksPath, { recursive: true });
66
-
67
- for (const hookName of TARGET_GIT_TRANSITION_HOOKS) {
68
- const hookPath = path.join(resolvedHooksPath, hookName);
69
- const label = relativeLabel(cwd, hookPath);
70
- const nextContent = buildTargetGitHookScript(hookName);
71
- if (!fs.existsSync(hookPath)) {
72
- fs.writeFileSync(hookPath, nextContent);
73
- fs.chmodSync(hookPath, 0o755);
74
- actions.push(InitAction.create(label, "wrote graft target git hook"));
75
- continue;
76
- }
77
-
78
- const existing = fs.readFileSync(hookPath, "utf-8");
79
- if (existing === nextContent) {
80
- actions.push(InitAction.exists(label, "already has graft target git hook"));
81
- continue;
82
- }
83
- if (isRecognizedTargetGitHook(existing, hookName)) {
84
- fs.writeFileSync(hookPath, nextContent);
85
- fs.chmodSync(hookPath, 0o755);
86
- actions.push(InitAction.append(label, "updated graft target git hook"));
87
- continue;
88
- }
89
- actions.push(InitAction.exists(label, "external hook preserved"));
90
- }
91
-
92
- return actions;
93
- }
package/src/cli/init.ts DELETED
@@ -1,124 +0,0 @@
1
- import * as path from "node:path";
2
- import { appendIfMissing, ensureTargetGitHooks, mergeClaudeHooksConfig, mergeClaudeMcpConfig, mergeClineMcpConfig, mergeCodexMcpConfig, mergeContinueMcpConfig, mergeCursorMcpConfig, mergeWindsurfMcpConfig, writeIfMissing } from "./init-bootstrap.js";
3
- import { writeCliError } from "./cli-error.js";
4
- import { GRAFT_HOOKS_CONFIG, GraftMcpServer, InitFailure, InitResult, ParsedInitArgs } from "./init-model.js";
5
- import { emitInitJson, renderInitText } from "./init-render.js";
6
-
7
- const GRAFTIGNORE_TEMPLATE = `# Graft ignore patterns — files matching these are refused by safe_read.
8
- # Syntax: same as .gitignore (glob matching via picomatch).
9
-
10
- # Examples:
11
- # *.generated.ts
12
- # vendor/**
13
- # data/**/*.json
14
- `;
15
-
16
- const READ_GUIDANCE_MARKER = "## File reads";
17
-
18
- const AGENT_SNIPPET = `## File reads
19
-
20
- This project uses [graft](https://github.com/flyingrobots/graft) as
21
- a context governor. Prefer graft's MCP tools over native file reads:
22
-
23
- - Use \`safe_read\` instead of \`Read\` for file contents
24
- - Use \`file_outline\` to see structure before reading
25
- - Use \`read_range\` with jump table entries for targeted reads
26
- - Use \`graft_diff\` instead of \`git diff\` for structural changes
27
- - Use \`explain\` if you get an unfamiliar reason code
28
- - Call \`set_budget\` at session start if context is tight
29
-
30
- These tools enforce read policy, cache observations, and track
31
- session metrics. Native reads bypass all of that.
32
- `;
33
-
34
- const GITIGNORE_ENTRY = "\n# Graft runtime data\n.graft/\n";
35
-
36
- interface Writer {
37
- write(chunk: string): unknown;
38
- }
39
-
40
- export interface RunInitOptions {
41
- cwd?: string | undefined;
42
- args?: readonly string[] | undefined;
43
- stdout?: Writer | undefined;
44
- stderr?: Writer | undefined;
45
- }
46
-
47
- function initProject(cwd: string, args: ParsedInitArgs): InitResult {
48
- const mcpServer = new GraftMcpServer(args.mcpRuntime);
49
- const updateExistingMcp = args.mcpRuntimeExplicit;
50
- const actions = [
51
- writeIfMissing(path.join(cwd, ".graftignore"), GRAFTIGNORE_TEMPLATE, ".graftignore"),
52
- appendIfMissing(path.join(cwd, ".gitignore"), ".graft/", GITIGNORE_ENTRY, ".gitignore"),
53
- appendIfMissing(path.join(cwd, "CLAUDE.md"), READ_GUIDANCE_MARKER, `\n${AGENT_SNIPPET}`, "CLAUDE.md"),
54
- ];
55
-
56
- if (args.writeClaudeMcp) {
57
- actions.push(mergeClaudeMcpConfig(cwd, mcpServer, updateExistingMcp));
58
- }
59
- if (args.writeClaudeHooks) {
60
- actions.push(mergeClaudeHooksConfig(cwd));
61
- }
62
- if (args.writeTargetGitHooks) {
63
- actions.push(...ensureTargetGitHooks(cwd));
64
- }
65
- if (args.writeCodexMcp) {
66
- actions.push(mergeCodexMcpConfig(cwd, mcpServer, updateExistingMcp));
67
- actions.push(
68
- appendIfMissing(
69
- path.join(cwd, "AGENTS.md"),
70
- READ_GUIDANCE_MARKER,
71
- `\n${AGENT_SNIPPET}`,
72
- "AGENTS.md",
73
- ),
74
- );
75
- }
76
- if (args.writeCursorMcp) {
77
- actions.push(mergeCursorMcpConfig(cwd, mcpServer, updateExistingMcp));
78
- }
79
- if (args.writeWindsurfMcp) {
80
- actions.push(mergeWindsurfMcpConfig(cwd, mcpServer, updateExistingMcp));
81
- }
82
- if (args.writeContinueMcp) {
83
- actions.push(mergeContinueMcpConfig(cwd, mcpServer, updateExistingMcp));
84
- }
85
- if (args.writeClineMcp) {
86
- actions.push(mergeClineMcpConfig(cwd, mcpServer, updateExistingMcp));
87
- }
88
-
89
- return new InitResult(cwd, actions, GRAFT_HOOKS_CONFIG, mcpServer);
90
- }
91
-
92
- export function runInit(options: RunInitOptions = {}): void {
93
- const cwd = options.cwd ?? process.cwd();
94
- const args = options.args ?? process.argv.slice(3);
95
- const stdout = options.stdout ?? process.stdout;
96
- const stderr = options.stderr ?? process.stderr;
97
-
98
- try {
99
- const parsed = ParsedInitArgs.parse(args);
100
- const result = initProject(cwd, parsed);
101
- if (parsed.json) {
102
- emitInitJson(result.toJSON(), stdout);
103
- return;
104
- }
105
- renderInitText(result, parsed, stdout);
106
- } catch (err: unknown) {
107
- const message = err instanceof Error ? err.message : String(err);
108
- process.exitCode = 1;
109
- if (args.includes("--json")) {
110
- emitInitJson(new InitFailure(cwd, message), stdout);
111
- return;
112
- }
113
- writeCliError(stderr, message, {
114
- usage:
115
- "graft init [--json] [--mcp-runtime <repo-local|daemon>] [--write-claude-mcp] [--write-claude-hooks] "
116
- + "[--write-target-git-hooks] [--write-codex-mcp] [--write-cursor-mcp] "
117
- + "[--write-windsurf-mcp] [--write-continue-mcp] [--write-cline-mcp]",
118
- nextSteps: [
119
- "Use explicit --write-*-mcp flags to bootstrap project-local client config files.",
120
- "Use --write-target-git-hooks only inside a git worktree.",
121
- ],
122
- });
123
- }
124
- }
@@ -1,155 +0,0 @@
1
- import * as fs from "node:fs";
2
- import * as path from "node:path";
3
- import {
4
- cloneJsonValue,
5
- isJsonObjectValue,
6
- type JsonArrayValue,
7
- type JsonObjectValue,
8
- type JsonValue,
9
- } from "./init-model.js";
10
-
11
- function formatJsonField(pointer: readonly string[]): string {
12
- return pointer.length === 0 ? "document root" : pointer.join(".");
13
- }
14
-
15
- export class JsonArrayNode {
16
- constructor(
17
- private readonly value: JsonArrayValue,
18
- private readonly label: string,
19
- private readonly pointer: readonly string[] = [],
20
- ) {}
21
-
22
- static fromUnknown(
23
- value: unknown,
24
- label: string,
25
- pointer: readonly string[] = [],
26
- ): JsonArrayNode {
27
- if (!Array.isArray(value)) {
28
- throw new Error(`${label}: expected ${formatJsonField(pointer)} to be an array`);
29
- }
30
- return new JsonArrayNode(value as JsonArrayValue, label, pointer);
31
- }
32
-
33
- objectItems(): JsonObjectNode[] {
34
- return this.value.map((item, index) =>
35
- JsonObjectNode.fromUnknown(item, this.label, [...this.pointer, `[${String(index)}]`]),
36
- );
37
- }
38
-
39
- objectEntries(): { index: number; node: JsonObjectNode }[] {
40
- return this.value.map((item, index) => ({
41
- index,
42
- node: JsonObjectNode.fromUnknown(item, this.label, [...this.pointer, `[${String(index)}]`]),
43
- }));
44
- }
45
-
46
- push(value: JsonValue): void {
47
- this.value.push(cloneJsonValue(value));
48
- }
49
-
50
- set(index: number, value: JsonValue): void {
51
- this.value[index] = cloneJsonValue(value);
52
- }
53
- }
54
-
55
- export class JsonObjectNode {
56
- constructor(
57
- private readonly value: JsonObjectValue,
58
- private readonly label: string,
59
- private readonly pointer: readonly string[] = [],
60
- ) {}
61
-
62
- static fromUnknown(
63
- value: unknown,
64
- label: string,
65
- pointer: readonly string[] = [],
66
- ): JsonObjectNode {
67
- if (!isJsonObjectValue(value)) {
68
- throw new Error(`${label}: expected ${formatJsonField(pointer)} to be an object`);
69
- }
70
- return new JsonObjectNode(value, label, pointer);
71
- }
72
-
73
- has(key: string): boolean {
74
- return this.value[key] !== undefined;
75
- }
76
-
77
- set(key: string, value: JsonValue): void {
78
- this.value[key] = cloneJsonValue(value);
79
- }
80
-
81
- ensureObject(key: string): JsonObjectNode {
82
- const current = this.value[key];
83
- if (current === undefined) {
84
- const created: JsonObjectValue = {};
85
- this.value[key] = created;
86
- return new JsonObjectNode(created, this.label, [...this.pointer, key]);
87
- }
88
- return JsonObjectNode.fromUnknown(current, this.label, [...this.pointer, key]);
89
- }
90
-
91
- ensureArray(key: string): JsonArrayNode {
92
- const current = this.value[key];
93
- if (current === undefined) {
94
- const created: JsonArrayValue = [];
95
- this.value[key] = created;
96
- return new JsonArrayNode(created, this.label, [...this.pointer, key]);
97
- }
98
- return JsonArrayNode.fromUnknown(current, this.label, [...this.pointer, key]);
99
- }
100
-
101
- requireArray(key: string): JsonArrayNode {
102
- const current = this.value[key];
103
- if (current === undefined) {
104
- throw new Error(`${this.label}: expected ${formatJsonField([...this.pointer, key])} to exist`);
105
- }
106
- return JsonArrayNode.fromUnknown(current, this.label, [...this.pointer, key]);
107
- }
108
-
109
- stringValue(key: string): string | undefined {
110
- const current = this.value[key];
111
- return typeof current === "string" ? current : undefined;
112
- }
113
-
114
- toJsonValue(): JsonObjectValue {
115
- return this.value;
116
- }
117
- }
118
-
119
- export class JsonObjectDocument {
120
- constructor(
121
- readonly label: string,
122
- readonly filePath: string,
123
- private readonly rootNode: JsonObjectNode,
124
- ) {}
125
-
126
- static create(
127
- filePath: string,
128
- label: string,
129
- root: JsonObjectValue,
130
- ): JsonObjectDocument {
131
- return new JsonObjectDocument(
132
- label,
133
- filePath,
134
- new JsonObjectNode(cloneJsonValue(root), label),
135
- );
136
- }
137
-
138
- static open(filePath: string, label: string): JsonObjectDocument {
139
- const parsed = JSON.parse(fs.readFileSync(filePath, "utf-8")) as unknown;
140
- return new JsonObjectDocument(
141
- label,
142
- filePath,
143
- JsonObjectNode.fromUnknown(parsed, label),
144
- );
145
- }
146
-
147
- root(): JsonObjectNode {
148
- return this.rootNode;
149
- }
150
-
151
- write(): void {
152
- fs.mkdirSync(path.dirname(this.filePath), { recursive: true });
153
- fs.writeFileSync(this.filePath, JSON.stringify(this.rootNode.toJsonValue(), null, 2));
154
- }
155
- }