@flyingrobots/graft 0.4.0 → 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 +47 -0
  3. package/CODE_OF_CONDUCT.md +65 -0
  4. package/README.md +153 -17
  5. package/bin/graft.js +4 -14
  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 +15 -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 +75 -11
  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 +65 -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 +696 -55
  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 +92 -38
  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 +7 -2
  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 +171 -56
  108. package/src/warp/observers.ts +1 -1
  109. package/src/warp/open.ts +4 -3
  110. package/src/warp/plumbing.d.ts +5 -1
  111. package/src/warp/writer-id.ts +30 -0
@@ -0,0 +1,20 @@
1
+ import { z } from "zod";
2
+ import type { ToolDefinition, ToolContext, ToolHandler } from "../context.js";
3
+
4
+ export const workspaceAuthorizeTool: ToolDefinition = {
5
+ name: "workspace_authorize",
6
+ description:
7
+ "Authorize a workspace for daemon binding and optionally change its daemon capability posture.",
8
+ schema: {
9
+ cwd: z.string(),
10
+ runCapture: z.boolean().optional(),
11
+ },
12
+ createHandler(ctx: ToolContext): ToolHandler {
13
+ return async (args) => {
14
+ return ctx.respond("workspace_authorize", { ...await ctx.authorizeWorkspace({
15
+ cwd: args["cwd"] as string,
16
+ runCapture: args["runCapture"] as boolean | undefined,
17
+ }) });
18
+ };
19
+ },
20
+ };
@@ -0,0 +1,25 @@
1
+ import { z } from "zod";
2
+ import type { ToolDefinition, ToolContext, ToolHandler } from "../context.js";
3
+
4
+ export const workspaceBindTool: ToolDefinition = {
5
+ name: "workspace_bind",
6
+ description:
7
+ "Bind the current daemon session to a workspace by resolving repo and worktree identity server-side.",
8
+ schema: {
9
+ cwd: z.string(),
10
+ worktreeRoot: z.string().optional(),
11
+ gitCommonDir: z.string().optional(),
12
+ repoId: z.string().optional(),
13
+ },
14
+ createHandler(ctx: ToolContext): ToolHandler {
15
+ return async (args) => {
16
+ const result = await ctx.bindWorkspace({
17
+ cwd: args["cwd"] as string,
18
+ worktreeRoot: args["worktreeRoot"] as string | undefined,
19
+ gitCommonDir: args["gitCommonDir"] as string | undefined,
20
+ repoId: args["repoId"] as string | undefined,
21
+ }, "workspace_bind");
22
+ return ctx.respond("workspace_bind", { ...result });
23
+ };
24
+ },
25
+ };
@@ -0,0 +1,25 @@
1
+ import { z } from "zod";
2
+ import type { ToolDefinition, ToolContext, ToolHandler } from "../context.js";
3
+
4
+ export const workspaceRebindTool: ToolDefinition = {
5
+ name: "workspace_rebind",
6
+ description:
7
+ "Rebind the current daemon session to a different workspace and start a fresh session-local slice.",
8
+ schema: {
9
+ cwd: z.string(),
10
+ worktreeRoot: z.string().optional(),
11
+ gitCommonDir: z.string().optional(),
12
+ repoId: z.string().optional(),
13
+ },
14
+ createHandler(ctx: ToolContext): ToolHandler {
15
+ return async (args) => {
16
+ const result = await ctx.rebindWorkspace({
17
+ cwd: args["cwd"] as string,
18
+ worktreeRoot: args["worktreeRoot"] as string | undefined,
19
+ gitCommonDir: args["gitCommonDir"] as string | undefined,
20
+ repoId: args["repoId"] as string | undefined,
21
+ }, "workspace_rebind");
22
+ return ctx.respond("workspace_rebind", { ...result });
23
+ };
24
+ },
25
+ };
@@ -0,0 +1,18 @@
1
+ import { z } from "zod";
2
+ import type { ToolDefinition, ToolContext, ToolHandler } from "../context.js";
3
+
4
+ export const workspaceRevokeTool: ToolDefinition = {
5
+ name: "workspace_revoke",
6
+ description:
7
+ "Revoke daemon authorization for a workspace while leaving any already-open sessions visible to the control plane.",
8
+ schema: {
9
+ cwd: z.string(),
10
+ },
11
+ createHandler(ctx: ToolContext): ToolHandler {
12
+ return async (args) => {
13
+ return ctx.respond("workspace_revoke", { ...await ctx.revokeWorkspace({
14
+ cwd: args["cwd"] as string,
15
+ }) });
16
+ };
17
+ },
18
+ };
@@ -0,0 +1,12 @@
1
+ import type { ToolDefinition, ToolContext, ToolHandler } from "../context.js";
2
+
3
+ export const workspaceStatusTool: ToolDefinition = {
4
+ name: "workspace_status",
5
+ description:
6
+ "Return the current daemon workspace binding state and resolved capability profile.",
7
+ createHandler(ctx: ToolContext): ToolHandler {
8
+ return () => {
9
+ return ctx.respond("workspace_status", { ...ctx.getWorkspaceStatus() });
10
+ };
11
+ },
12
+ };
@@ -0,0 +1,36 @@
1
+ import type WarpApp from "@git-stunts/git-warp";
2
+ import { DEFAULT_WARP_WRITER_ID } from "../warp/writer-id.js";
3
+
4
+ export interface WarpPool {
5
+ getOrOpen(repoId: string, worktreeRoot: string, writerId?: string): Promise<WarpApp>;
6
+ size(): number;
7
+ }
8
+
9
+ export class InMemoryWarpPool implements WarpPool {
10
+ private readonly opened = new Map<string, Map<string, Promise<WarpApp>>>();
11
+
12
+ constructor(private readonly openWarp: (worktreeRoot: string, writerId: string) => Promise<WarpApp>) {}
13
+
14
+ getOrOpen(repoId: string, worktreeRoot: string, writerId: string = DEFAULT_WARP_WRITER_ID): Promise<WarpApp> {
15
+ const repoHandles = this.opened.get(repoId);
16
+ const cached = repoHandles?.get(writerId);
17
+ if (cached !== undefined) return cached;
18
+
19
+ const nextRepoHandles = repoHandles ?? new Map<string, Promise<WarpApp>>();
20
+ const opened = this.openWarp(worktreeRoot, writerId).catch((error: unknown) => {
21
+ const current = this.opened.get(repoId);
22
+ current?.delete(writerId);
23
+ if (current?.size === 0) {
24
+ this.opened.delete(repoId);
25
+ }
26
+ throw error;
27
+ });
28
+ nextRepoHandles.set(writerId, opened);
29
+ this.opened.set(repoId, nextRepoHandles);
30
+ return opened;
31
+ }
32
+
33
+ size(): number {
34
+ return this.opened.size;
35
+ }
36
+ }