@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/src/mcp/cache.ts CHANGED
@@ -9,6 +9,16 @@ export function hashContent(content: string): string {
9
9
  return crypto.createHash("sha256").update(content).digest("hex");
10
10
  }
11
11
 
12
+ export interface ObservationSnapshot {
13
+ readonly contentHash: string;
14
+ readonly outline: readonly OutlineEntry[];
15
+ readonly jumpTable: readonly JumpEntry[];
16
+ readonly actual: Readonly<{ lines: number; bytes: number }>;
17
+ readonly readCount: number;
18
+ readonly firstReadAt: string;
19
+ readonly lastReadAt: string;
20
+ }
21
+
12
22
  export class Observation {
13
23
  readonly contentHash: string;
14
24
  readonly outline: readonly OutlineEntry[];
@@ -52,6 +62,22 @@ export class Observation {
52
62
  this._readCount++;
53
63
  this._lastReadAt = new Date().toISOString();
54
64
  }
65
+
66
+ snapshot(): ObservationSnapshot {
67
+ return {
68
+ contentHash: this.contentHash,
69
+ outline: this.outline,
70
+ jumpTable: this.jumpTable,
71
+ actual: this.actual,
72
+ readCount: this.readCount,
73
+ firstReadAt: this.firstReadAt,
74
+ lastReadAt: this.lastReadAt,
75
+ };
76
+ }
77
+
78
+ static fromSnapshot(snapshot: ObservationSnapshot): Observation {
79
+ return new Observation(snapshot);
80
+ }
55
81
  }
56
82
 
57
83
  export type CacheResult =
@@ -61,6 +87,19 @@ export type CacheResult =
61
87
  export class ObservationCache {
62
88
  private readonly entries = new Map<string, Observation>();
63
89
 
90
+ static fromSnapshots(
91
+ snapshots: Readonly<Record<string, ObservationSnapshot>> | undefined,
92
+ ): ObservationCache {
93
+ const cache = new ObservationCache();
94
+ if (snapshots === undefined) {
95
+ return cache;
96
+ }
97
+ for (const [filePath, snapshot] of Object.entries(snapshots)) {
98
+ cache.entries.set(filePath, Observation.fromSnapshot(snapshot));
99
+ }
100
+ return cache;
101
+ }
102
+
64
103
  record(
65
104
  filePath: string,
66
105
  contentHash: string,
@@ -91,4 +130,16 @@ export class ObservationCache {
91
130
  get(filePath: string): Observation | undefined {
92
131
  return this.entries.get(filePath);
93
132
  }
133
+
134
+ snapshotEntry(filePath: string): ObservationSnapshot | null {
135
+ return this.entries.get(filePath)?.snapshot() ?? null;
136
+ }
137
+
138
+ applySnapshot(filePath: string, snapshot: ObservationSnapshot | null): void {
139
+ if (snapshot === null) {
140
+ this.entries.delete(filePath);
141
+ return;
142
+ }
143
+ this.entries.set(filePath, Observation.fromSnapshot(snapshot));
144
+ }
94
145
  }
@@ -1,5 +1,6 @@
1
- import { extractOutline } from "../parser/outline.js";
2
- import { detectLang } from "../parser/lang.js";
1
+ import { extractOutlineForFile } from "../parser/outline.js";
2
+ import { detectStructuredFormat } from "../parser/lang.js";
3
+ import type { SupportedStructuredFormat } from "../parser/lang.js";
3
4
  import type { OutlineEntry, JumpEntry } from "../parser/types.js";
4
5
  import { hashContent } from "./cache.js";
5
6
 
@@ -14,6 +15,8 @@ export class CachedFile {
14
15
  readonly path: string;
15
16
  readonly rawContent: string;
16
17
  readonly hash: string;
18
+ readonly lang: SupportedStructuredFormat | null;
19
+ readonly supportsOutline: boolean;
17
20
  readonly outline: readonly OutlineEntry[];
18
21
  readonly jumpTable: readonly JumpEntry[];
19
22
  readonly actual: { readonly lines: number; readonly bytes: number };
@@ -26,12 +29,11 @@ export class CachedFile {
26
29
  lines: rawContent.split("\n").length,
27
30
  bytes: Buffer.byteLength(rawContent),
28
31
  };
29
- // Fallback to "ts" parser for unknown extensions — TS/JS parser handles
30
- // .mjs, .cjs, and other JS-family files that detectLang doesn't cover.
31
- const lang = detectLang(filePath) ?? "ts";
32
- const result = extractOutline(rawContent, lang);
33
- this.outline = result.entries;
34
- this.jumpTable = result.jumpTable ?? [];
32
+ this.lang = detectStructuredFormat(filePath);
33
+ this.supportsOutline = this.lang !== null;
34
+ const result = extractOutlineForFile(filePath, rawContent);
35
+ this.outline = result?.entries ?? [];
36
+ this.jumpTable = result?.jumpTable ?? [];
35
37
  Object.freeze(this.actual);
36
38
  Object.freeze(this);
37
39
  }
@@ -9,13 +9,51 @@ import type { SessionTracker } from "../session/tracker.js";
9
9
  import type { McpToolResult } from "./receipt.js";
10
10
  import type { FileSystem } from "../ports/filesystem.js";
11
11
  import type { JsonCodec } from "../ports/codec.js";
12
+ import type { ProcessRunner } from "../ports/process-runner.js";
13
+ import type { GitClient } from "../ports/git.js";
14
+ import type WarpApp from "@git-stunts/git-warp";
15
+ import type { RepoObservation } from "./repo-state.js";
16
+ import type { RunCaptureConfig } from "./run-capture-config.js";
17
+ import type { RuntimeObservabilityState } from "./runtime-observability.js";
18
+ import type { RuntimeCausalContext } from "./runtime-causal-context.js";
19
+ import type { RuntimeWorkspaceOverlayFooting } from "./runtime-workspace-overlay.js";
20
+ import type {
21
+ PersistedLocalActivityWindow,
22
+ PersistedLocalHistoryAttachDeclaration,
23
+ RepoConcurrencySummary,
24
+ PersistedLocalHistorySummary,
25
+ } from "./persisted-local-history.js";
26
+ import type { McpToolName } from "../contracts/output-schemas.js";
27
+ import type {
28
+ DaemonSessionView,
29
+ DaemonStatusView,
30
+ AuthorizedWorkspaceView,
31
+ WorkspaceAuthorizeRequest,
32
+ WorkspaceAuthorizeResult,
33
+ WorkspaceRevokeResult,
34
+ } from "./daemon-control-plane.js";
35
+ import type {
36
+ DaemonRepoFilter,
37
+ DaemonRepoListView,
38
+ } from "./daemon-repos.js";
39
+ import type {
40
+ MonitorActionResult,
41
+ MonitorStartRequest,
42
+ MonitorStatusView,
43
+ } from "./persistent-monitor-runtime.js";
44
+ import type {
45
+ WorkspaceActionResult,
46
+ CausalAttachResult,
47
+ WorkspaceBindRequest,
48
+ WorkspaceStatus,
49
+ } from "./workspace-router.js";
12
50
 
13
51
  import type { z } from "zod";
14
52
 
15
53
  export type ToolHandler = (args: Record<string, unknown>) => McpToolResult | Promise<McpToolResult>;
16
54
 
17
55
  export interface ToolDefinition {
18
- readonly name: string;
56
+ readonly name: McpToolName;
19
57
  readonly description: string;
20
58
  readonly schema?: Record<string, z.ZodType>;
21
59
  readonly policyCheck?: boolean;
@@ -25,13 +63,40 @@ export interface ToolDefinition {
25
63
  export interface ToolContext {
26
64
  readonly projectRoot: string;
27
65
  readonly graftDir: string;
66
+ readonly graftignorePatterns: readonly string[];
28
67
  readonly session: SessionTracker;
29
68
  readonly cache: ObservationCache;
30
69
  readonly metrics: Metrics;
31
70
  readonly fs: FileSystem;
32
71
  readonly codec: JsonCodec;
33
- respond(tool: string, data: Record<string, unknown>): McpToolResult;
72
+ readonly process: ProcessRunner;
73
+ readonly git: GitClient;
74
+ readonly runCapture: RunCaptureConfig;
75
+ readonly observability: RuntimeObservabilityState;
76
+ respond(tool: McpToolName, data: Record<string, unknown>): McpToolResult;
34
77
  resolvePath(relative: string): string;
78
+ getWarp(): Promise<WarpApp>;
79
+ getRepoState(): RepoObservation;
80
+ getCausalContext(): RuntimeCausalContext;
81
+ getWorkspaceOverlayFooting(): Promise<RuntimeWorkspaceOverlayFooting | null>;
82
+ getPersistedLocalHistorySummary(): Promise<PersistedLocalHistorySummary>;
83
+ getPersistedLocalActivityWindow(limit: number): Promise<PersistedLocalActivityWindow>;
84
+ getRepoConcurrencySummary(): Promise<RepoConcurrencySummary | null>;
85
+ declareCausalAttach(request: PersistedLocalHistoryAttachDeclaration): Promise<CausalAttachResult>;
86
+ getWorkspaceStatus(): WorkspaceStatus;
87
+ bindWorkspace(request: WorkspaceBindRequest, actionName: string): Promise<WorkspaceActionResult>;
88
+ rebindWorkspace(request: WorkspaceBindRequest, actionName: string): Promise<WorkspaceActionResult>;
89
+ getDaemonStatus(): Promise<DaemonStatusView>;
90
+ listDaemonRepos(filter: DaemonRepoFilter): Promise<DaemonRepoListView>;
91
+ listDaemonSessions(): Promise<readonly DaemonSessionView[]>;
92
+ listDaemonMonitors(): Promise<readonly MonitorStatusView[]>;
93
+ startMonitor(request: MonitorStartRequest): Promise<MonitorActionResult>;
94
+ pauseMonitor(request: WorkspaceBindRequest): Promise<MonitorActionResult>;
95
+ resumeMonitor(request: WorkspaceBindRequest): Promise<MonitorActionResult>;
96
+ stopMonitor(request: WorkspaceBindRequest): Promise<MonitorActionResult>;
97
+ listWorkspaceAuthorizations(): Promise<readonly AuthorizedWorkspaceView[]>;
98
+ authorizeWorkspace(request: WorkspaceAuthorizeRequest): Promise<WorkspaceAuthorizeResult>;
99
+ revokeWorkspace(request: WorkspaceBindRequest): Promise<WorkspaceRevokeResult>;
35
100
  }
36
101
 
37
102
  /**