@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,107 +0,0 @@
1
- export type WorldlineLayer = "commit_worldline" | "ref_view" | "workspace_overlay";
2
- export type RepoTransitionKind = "checkout" | "reset" | "merge" | "rebase";
3
- export type RepoSemanticTransitionKind =
4
- | "index_update"
5
- | "conflict_resolution"
6
- | "merge_phase"
7
- | "rebase_phase"
8
- | "bulk_transition"
9
- | "unknown";
10
- export type RepoSemanticTransitionAuthority =
11
- | "authoritative_git_state"
12
- | "repo_snapshot";
13
- export type RepoSemanticTransitionPhase =
14
- | "started"
15
- | "conflicted"
16
- | "resolved_waiting_commit"
17
- | "continued"
18
- | "completed_or_cleared";
19
-
20
- export interface RepoTransition {
21
- readonly kind: RepoTransitionKind;
22
- readonly fromRef: string | null;
23
- readonly toRef: string | null;
24
- readonly fromCommit: string | null;
25
- readonly toCommit: string | null;
26
- readonly evidence: {
27
- readonly reflogSubject: string | null;
28
- };
29
- }
30
-
31
- export interface RepoSemanticTransition {
32
- readonly kind: RepoSemanticTransitionKind;
33
- readonly authority: RepoSemanticTransitionAuthority;
34
- readonly phase: RepoSemanticTransitionPhase | null;
35
- readonly summary: string;
36
- readonly evidence: {
37
- readonly totalPaths: number;
38
- readonly stagedPaths: number;
39
- readonly changedPaths: number;
40
- readonly untrackedPaths: number;
41
- readonly unmergedPaths: number;
42
- readonly mergeInProgress: boolean;
43
- readonly rebaseInProgress: boolean;
44
- readonly rebaseStep: number | null;
45
- readonly rebaseTotalSteps: number | null;
46
- readonly lastTransitionKind: RepoTransitionKind | null;
47
- readonly reflogSubject: string | null;
48
- };
49
- }
50
-
51
- export interface WorkspaceOverlaySummary {
52
- readonly dirty: true;
53
- readonly totalPaths: number;
54
- readonly stagedPaths: number;
55
- readonly changedPaths: number;
56
- readonly untrackedPaths: number;
57
- readonly actorGuess: "unknown";
58
- readonly confidence: "low";
59
- readonly evidence: {
60
- readonly source: "git status --porcelain";
61
- readonly reflogSubject: string | null;
62
- readonly sample: readonly string[];
63
- };
64
- }
65
-
66
- export interface RepoObservation {
67
- readonly checkoutEpoch: number;
68
- readonly headRef: string | null;
69
- readonly headSha: string | null;
70
- readonly dirty: boolean;
71
- readonly observedAt: string;
72
- readonly lastTransition: RepoTransition | null;
73
- readonly semanticTransition: RepoSemanticTransition | null;
74
- readonly workspaceOverlayId: string | null;
75
- readonly workspaceOverlay: WorkspaceOverlaySummary | null;
76
- readonly statusLines: readonly string[];
77
- }
78
-
79
- export interface RebaseProgressState {
80
- readonly inProgress: boolean;
81
- readonly step: number | null;
82
- readonly total: number | null;
83
- }
84
-
85
- export interface RepoSnapshot {
86
- readonly headRef: string | null;
87
- readonly headSha: string | null;
88
- readonly parentShas: readonly string[];
89
- readonly observedAt: string;
90
- readonly statusLines: readonly string[];
91
- readonly dirty: boolean;
92
- readonly stagedPaths: number;
93
- readonly changedPaths: number;
94
- readonly untrackedPaths: number;
95
- readonly unmergedPaths: number;
96
- readonly mergeInProgress: boolean;
97
- readonly rebase: RebaseProgressState;
98
- readonly headReflog: HeadReflogEntry | null;
99
- }
100
-
101
- export interface HeadReflogEntry {
102
- readonly raw: string;
103
- readonly previousSha: string | null;
104
- readonly nextSha: string | null;
105
- readonly timestampSec: number | null;
106
- readonly subject: string;
107
- }
@@ -1,146 +0,0 @@
1
- import type { GitClient } from "../ports/git.js";
2
- import type { FileSystem } from "../ports/filesystem.js";
3
- import type { RepoObservation, RepoSnapshot } from "./repo-state-types.js";
4
- import { captureSnapshot } from "./repo-state-git.js";
5
- import { detectTransition } from "./repo-state-transition.js";
6
- import { buildObservation, buildSemanticTransition } from "./repo-state-observation.js";
7
-
8
- // Re-export all public types and interfaces for downstream consumers.
9
- export type {
10
- WorldlineLayer,
11
- RepoTransitionKind,
12
- RepoSemanticTransitionKind,
13
- RepoSemanticTransitionAuthority,
14
- RepoSemanticTransitionPhase,
15
- RepoTransition,
16
- RepoSemanticTransition,
17
- WorkspaceOverlaySummary,
18
- RepoObservation,
19
- } from "./repo-state-types.js";
20
-
21
- /**
22
- * Default debounce window in milliseconds for coalescing rapid observe() calls.
23
- * Set to 0 (disabled) by default — callers opt in via constructor options.
24
- */
25
- const DEFAULT_OBSERVE_DEBOUNCE_MS = 0;
26
-
27
- export class RepoStateTracker {
28
- private checkoutEpoch = 0;
29
- private snapshot: RepoSnapshot | null = null;
30
- private observation: RepoObservation = {
31
- checkoutEpoch: 0,
32
- headRef: null,
33
- headSha: null,
34
- dirty: false,
35
- observedAt: new Date(0).toISOString(),
36
- lastTransition: null,
37
- semanticTransition: null,
38
- workspaceOverlayId: null,
39
- workspaceOverlay: null,
40
- statusLines: [],
41
- };
42
- private initialization: Promise<void> | null = null;
43
- private readonly startedAtSec = Math.floor(Date.now() / 1000);
44
- private hasObservedTransition = false;
45
-
46
- /** Pending observe promise used for debounce coalescing. */
47
- private pendingObserve: Promise<RepoObservation> | null = null;
48
- /** Timestamp of the last completed observation (ms since epoch). */
49
- private lastObservedAtMs = 0;
50
-
51
- private readonly debounceMs: number;
52
-
53
- constructor(
54
- private readonly cwd: string,
55
- private readonly fs: FileSystem,
56
- private readonly gitClient: GitClient,
57
- options?: { debounceMs?: number },
58
- ) {
59
- this.debounceMs = options?.debounceMs ?? DEFAULT_OBSERVE_DEBOUNCE_MS;
60
- }
61
-
62
- /**
63
- * Observe the current repo state.
64
- *
65
- * If another observe() call is already in flight, this returns the same
66
- * pending result (coalescing). If a previous observation completed within
67
- * the debounce window, the cached result is returned immediately without
68
- * spawning new git processes.
69
- */
70
- async observe(): Promise<RepoObservation> {
71
- // Coalesce: reuse an in-flight observation.
72
- if (this.pendingObserve !== null) {
73
- return this.pendingObserve;
74
- }
75
-
76
- // Debounce: return cached result if the last observation is fresh.
77
- const elapsed = Date.now() - this.lastObservedAtMs;
78
- if (this.lastObservedAtMs > 0 && elapsed < this.debounceMs) {
79
- return this.observation;
80
- }
81
-
82
- this.pendingObserve = this.performObserve();
83
-
84
- try {
85
- return await this.pendingObserve;
86
- } finally {
87
- this.pendingObserve = null;
88
- }
89
- }
90
-
91
- async initialize(): Promise<void> {
92
- if (this.initialization !== null) {
93
- await this.initialization;
94
- return;
95
- }
96
-
97
- this.initialization = (async () => {
98
- const snapshot = await captureSnapshot(this.cwd, this.fs, this.gitClient);
99
- this.snapshot = snapshot;
100
- this.observation = buildObservation(
101
- snapshot,
102
- this.checkoutEpoch,
103
- null,
104
- buildSemanticTransition(null, snapshot, null),
105
- );
106
- })();
107
-
108
- await this.initialization;
109
- }
110
-
111
- getState(): RepoObservation {
112
- return this.observation;
113
- }
114
-
115
- /** Core observation logic, separated from debounce/coalesce control. */
116
- private async performObserve(): Promise<RepoObservation> {
117
- await this.initialize();
118
- const previousSnapshot = this.snapshot;
119
- if (previousSnapshot === null) {
120
- return this.observation;
121
- }
122
- const nextSnapshot = await captureSnapshot(this.cwd, this.fs, this.gitClient);
123
- const transition = await detectTransition(
124
- this.gitClient,
125
- this.cwd,
126
- previousSnapshot,
127
- nextSnapshot,
128
- this.startedAtSec,
129
- !this.hasObservedTransition,
130
- );
131
- if (transition !== null) {
132
- this.checkoutEpoch++;
133
- this.hasObservedTransition = true;
134
- }
135
-
136
- this.snapshot = nextSnapshot;
137
- this.observation = buildObservation(
138
- nextSnapshot,
139
- this.checkoutEpoch,
140
- transition ?? this.observation.lastTransition,
141
- buildSemanticTransition(previousSnapshot, nextSnapshot, transition),
142
- );
143
- this.lastObservedAtMs = Date.now();
144
- return this.observation;
145
- }
146
- }
@@ -1,102 +0,0 @@
1
- import { z } from "zod";
2
- import type { GovernorTrackerSnapshot } from "../session/tracker.js";
3
- import type { McpToolReceipt, McpToolResult } from "./receipt.js";
4
- import type { ToolDefinition, ToolHandler } from "./context.js";
5
- import type { MetricsDelta, MetricsSnapshot } from "./metrics.js";
6
- import type { ObservationSnapshot } from "./cache.js";
7
- import type { RepoObservation } from "./repo-state.js";
8
- import type { WorkspaceCapabilityProfile } from "./workspace-router.js";
9
- import { graftDiffTool } from "./tools/graft-diff.js";
10
- import { sinceTool } from "./tools/since.js";
11
- import { mapTool } from "./tools/map.js";
12
- import { codeRefsTool } from "./tools/code-refs.js";
13
- import { codeFindTool, runCodeFind } from "./tools/code-find.js";
14
- import { codeShowTool, runCodeShow } from "./tools/code-show.js";
15
- import { safeReadTool } from "./tools/safe-read.js";
16
- import { fileOutlineTool } from "./tools/file-outline.js";
17
- import { changedSinceTool } from "./tools/changed-since.js";
18
- import { buildRepoToolWorkerContext, wrapWithPolicyCheck } from "./repo-tool-worker-context.js";
19
-
20
- const codeFindLiveWorkerTool: ToolDefinition = {
21
- ...codeFindTool,
22
- createHandler(): ToolHandler {
23
- return (args, ctx) => runCodeFind(ctx, args, { allowWarp: false });
24
- },
25
- };
26
-
27
- const codeShowLiveWorkerTool: ToolDefinition = {
28
- ...codeShowTool,
29
- createHandler(): ToolHandler {
30
- return (args, ctx) => runCodeShow(ctx, args, { allowWarp: false });
31
- },
32
- };
33
-
34
- const OFFLOADED_REPO_TOOL_DEFINITIONS = Object.freeze({
35
- safe_read: safeReadTool,
36
- file_outline: fileOutlineTool,
37
- changed_since: changedSinceTool,
38
- graft_diff: graftDiffTool,
39
- graft_since: sinceTool,
40
- graft_map: mapTool,
41
- code_refs: codeRefsTool,
42
- code_find_live: codeFindLiveWorkerTool,
43
- code_show_live: codeShowLiveWorkerTool,
44
- });
45
-
46
- export type OffloadedRepoToolName = keyof typeof OFFLOADED_REPO_TOOL_DEFINITIONS;
47
-
48
- export const OFFLOADED_DAEMON_REPO_TOOL_NAMES = Object.freeze(
49
- Object.keys(OFFLOADED_REPO_TOOL_DEFINITIONS) as OffloadedRepoToolName[],
50
- );
51
-
52
- export interface RepoToolWorkerJob {
53
- readonly sessionId: string;
54
- readonly workspaceSliceId: string;
55
- readonly traceId: string;
56
- readonly seq: number;
57
- readonly startedAtMs: number;
58
- readonly tool: OffloadedRepoToolName;
59
- readonly args: Record<string, unknown>;
60
- readonly projectRoot: string;
61
- readonly graftDir: string;
62
- readonly graftignorePatterns: readonly string[];
63
- readonly repoId: string;
64
- readonly worktreeId: string;
65
- readonly gitCommonDir: string;
66
- readonly writerId: string;
67
- readonly capabilityProfile: WorkspaceCapabilityProfile;
68
- readonly repoState: RepoObservation;
69
- readonly governorSnapshot: GovernorTrackerSnapshot;
70
- readonly metricsSnapshot: MetricsSnapshot;
71
- readonly cacheSnapshots?: Readonly<Record<string, ObservationSnapshot>>;
72
- }
73
-
74
- export interface RepoToolWorkerResult {
75
- readonly result: McpToolResult;
76
- readonly textBytes: number;
77
- readonly receipt: McpToolReceipt;
78
- readonly tripwireSignals: readonly string[];
79
- readonly metricsDelta: MetricsDelta;
80
- readonly cacheUpdates: readonly {
81
- path: string;
82
- observation: ObservationSnapshot | null;
83
- }[];
84
- }
85
-
86
- function resolveRepoToolDefinition(tool: OffloadedRepoToolName): ToolDefinition {
87
- return OFFLOADED_REPO_TOOL_DEFINITIONS[tool];
88
- }
89
-
90
- export async function runRepoToolJob(job: RepoToolWorkerJob): Promise<RepoToolWorkerResult> {
91
- const definition = resolveRepoToolDefinition(job.tool);
92
- const { ctx, takeResponse } = buildRepoToolWorkerContext(job);
93
- const rawHandler = definition.createHandler();
94
- const handler = definition.policyCheck === true ? wrapWithPolicyCheck(definition.name, rawHandler) : rawHandler;
95
-
96
- if (definition.schema !== undefined) {
97
- z.object(definition.schema).strict().parse(job.args);
98
- }
99
-
100
- await handler(job.args, ctx);
101
- return takeResponse();
102
- }
@@ -1,215 +0,0 @@
1
- import { CanonicalJsonCodec } from "../adapters/canonical-json.js";
2
- import { nodeFs } from "../adapters/node-fs.js";
3
- import { nodeGit } from "../adapters/node-git.js";
4
- import { nodeProcessRunner } from "../adapters/node-process-runner.js";
5
- import { createRepoPathResolver } from "../adapters/repo-paths.js";
6
- import { openWarp } from "../warp/open.js";
7
- import { GovernorTracker } from "../session/tracker.js";
8
- import { RefusedResult } from "../policy/types.js";
9
- import type { WorkspaceStatus } from "./workspace-router.js";
10
- import { buildReceiptResult } from "./receipt.js";
11
- import type { ToolContext, ToolDefinition, ToolHandler } from "./context.js";
12
- import { Metrics, diffMetrics } from "./metrics.js";
13
- import { ObservationCache } from "./cache.js";
14
- import { evaluateMcpPolicy } from "./policy.js";
15
- import { resolveRunCaptureConfig } from "./run-capture-config.js";
16
- import { resolveRuntimeObservabilityState } from "./runtime-observability.js";
17
- import { buildRuntimeCausalContext } from "./runtime-causal-context.js";
18
- import type { RepoToolWorkerJob, RepoToolWorkerResult } from "./repo-tool-job.js";
19
-
20
- function unsupported(name: string): never {
21
- throw new Error(`${name} is not available in repo-tool worker mode`);
22
- }
23
-
24
- function workerStatus(job: RepoToolWorkerJob): WorkspaceStatus {
25
- return {
26
- sessionMode: "daemon",
27
- bindState: "bound",
28
- repoId: job.repoId,
29
- worktreeId: job.worktreeId,
30
- worktreeRoot: job.projectRoot,
31
- gitCommonDir: job.gitCommonDir,
32
- graftDir: job.graftDir,
33
- capabilityProfile: job.capabilityProfile,
34
- };
35
- }
36
-
37
- export function wrapWithPolicyCheck(
38
- toolName: ToolDefinition["name"],
39
- inner: ToolHandler,
40
- ): ToolHandler {
41
- return async (args: Record<string, unknown>, ctx: ToolContext) => {
42
- const rawPath = args["path"];
43
- if (typeof rawPath !== "string") return inner(args, ctx);
44
-
45
- const filePath = ctx.resolvePath(rawPath);
46
- let content: string;
47
- try {
48
- content = await ctx.fs.readFile(filePath, "utf-8");
49
- } catch {
50
- return inner(args, ctx);
51
- }
52
-
53
- const actual = { lines: content.split("\n").length, bytes: Buffer.byteLength(content) };
54
- const policy = evaluateMcpPolicy(ctx, filePath, actual);
55
- if (policy instanceof RefusedResult) {
56
- ctx.metrics.recordRefusal();
57
- return ctx.respond(toolName, {
58
- path: filePath,
59
- projection: "refused",
60
- reason: policy.reason,
61
- reasonDetail: policy.reasonDetail,
62
- next: [...policy.next],
63
- actual,
64
- });
65
- }
66
- return inner(args, ctx);
67
- };
68
- }
69
-
70
- export function buildRepoToolWorkerContext(
71
- job: RepoToolWorkerJob,
72
- ): { ctx: ToolContext; takeResponse: () => RepoToolWorkerResult } {
73
- const codec = new CanonicalJsonCodec();
74
- const governor = GovernorTracker.fromSnapshot(job.governorSnapshot);
75
- const metrics = Metrics.fromSnapshot(job.metricsSnapshot);
76
- const cache = ObservationCache.fromSnapshots(job.cacheSnapshots);
77
- const trackedCachePaths = new Set<string>(Object.keys(job.cacheSnapshots ?? {}));
78
- if (typeof job.args["path"] === "string") {
79
- trackedCachePaths.add(createRepoPathResolver(job.projectRoot)(job.args["path"]));
80
- }
81
- let response: Omit<RepoToolWorkerResult, "metricsDelta" | "cacheUpdates"> | null = null;
82
-
83
- const ctx: ToolContext = {
84
- projectRoot: job.projectRoot,
85
- graftDir: job.graftDir,
86
- graftignorePatterns: job.graftignorePatterns,
87
- governor,
88
- cache,
89
- metrics,
90
- fs: nodeFs,
91
- codec,
92
- process: nodeProcessRunner,
93
- git: nodeGit,
94
- runCapture: resolveRunCaptureConfig({}),
95
- observability: resolveRuntimeObservabilityState({ graftDir: job.graftDir }),
96
- respond(tool, data) {
97
- const tripwires = governor.checkTripwires();
98
- const built = buildReceiptResult(tool, data, {
99
- sessionId: job.sessionId,
100
- traceId: job.traceId,
101
- seq: job.seq,
102
- latencyMs: Date.now() - job.startedAtMs,
103
- codec,
104
- metrics: metrics.snapshot(),
105
- tripwires,
106
- budget: governor.getBudget(),
107
- });
108
- response = {
109
- result: built.result,
110
- textBytes: built.textBytes,
111
- receipt: built.receipt,
112
- tripwireSignals: tripwires.map((wire) => wire.signal),
113
- };
114
- return built.result;
115
- },
116
- recordFootprint() {
117
- // Worker-thread footprints are not collected — the main thread
118
- // captures footprint via AsyncLocalStorage in the invocation engine.
119
- },
120
- resolvePath: createRepoPathResolver(job.projectRoot),
121
- async getWarp() {
122
- return { app: await openWarp({ cwd: job.projectRoot, writerId: job.writerId }), strandId: null };
123
- },
124
- getRepoState() {
125
- return job.repoState;
126
- },
127
- getCausalContext() {
128
- return buildRuntimeCausalContext({
129
- transportSessionId: job.sessionId,
130
- workspaceSliceId: job.workspaceSliceId,
131
- repoId: job.repoId,
132
- worktreeId: job.worktreeId,
133
- checkoutEpoch: job.repoState.checkoutEpoch,
134
- warpWriterId: job.writerId,
135
- });
136
- },
137
- getPersistedLocalHistorySummary() {
138
- return unsupported("getPersistedLocalHistorySummary");
139
- },
140
- getPersistedLocalActivityWindow() {
141
- return unsupported("getPersistedLocalActivityWindow");
142
- },
143
- getRepoConcurrencySummary() {
144
- return Promise.resolve(null);
145
- },
146
- getWorkspaceOverlayFooting() {
147
- return unsupported("getWorkspaceOverlayFooting");
148
- },
149
- declareCausalAttach() {
150
- return unsupported("declareCausalAttach");
151
- },
152
- getWorkspaceStatus() {
153
- return workerStatus(job);
154
- },
155
- bindWorkspace() {
156
- return unsupported("bindWorkspace");
157
- },
158
- rebindWorkspace() {
159
- return unsupported("rebindWorkspace");
160
- },
161
- getDaemonStatus() {
162
- return unsupported("getDaemonStatus");
163
- },
164
- listDaemonRepos() {
165
- return unsupported("listDaemonRepos");
166
- },
167
- listDaemonSessions() {
168
- return unsupported("listDaemonSessions");
169
- },
170
- listDaemonMonitors() {
171
- return unsupported("listDaemonMonitors");
172
- },
173
- startMonitor() {
174
- return unsupported("startMonitor");
175
- },
176
- pauseMonitor() {
177
- return unsupported("pauseMonitor");
178
- },
179
- resumeMonitor() {
180
- return unsupported("resumeMonitor");
181
- },
182
- nudgeMonitor() {
183
- return unsupported("nudgeMonitor");
184
- },
185
- stopMonitor() {
186
- return unsupported("stopMonitor");
187
- },
188
- listWorkspaceAuthorizations() {
189
- return unsupported("listWorkspaceAuthorizations");
190
- },
191
- authorizeWorkspace() {
192
- return unsupported("authorizeWorkspace");
193
- },
194
- revokeWorkspace() {
195
- return unsupported("revokeWorkspace");
196
- },
197
- };
198
-
199
- return {
200
- ctx,
201
- takeResponse() {
202
- if (response === null) {
203
- throw new Error(`repo-tool worker ${job.tool} completed without calling respond()`);
204
- }
205
- return {
206
- ...response,
207
- metricsDelta: diffMetrics(job.metricsSnapshot, metrics.snapshot()),
208
- cacheUpdates: [...trackedCachePaths].map((filePath) => ({
209
- path: filePath,
210
- observation: cache.snapshotEntry(filePath),
211
- })),
212
- };
213
- },
214
- };
215
- }
@@ -1,21 +0,0 @@
1
- import { toRepoPolicyPath } from "../adapters/repo-paths.js";
2
- import { RepoWorkspace } from "../operations/repo-workspace.js";
3
- import type { ToolContext } from "./context.js";
4
-
5
- export function createRepoWorkspaceFromToolContext(
6
- ctx: Pick<
7
- ToolContext,
8
- "projectRoot" | "fs" | "codec" | "graftignorePatterns" | "resolvePath" | "governor" | "cache"
9
- >,
10
- ): RepoWorkspace {
11
- return new RepoWorkspace({
12
- projectRoot: ctx.projectRoot,
13
- fs: ctx.fs,
14
- codec: ctx.codec,
15
- graftignorePatterns: ctx.graftignorePatterns,
16
- resolvePath: ctx.resolvePath,
17
- toPolicyPath: (resolvedPath) => toRepoPolicyPath(ctx.projectRoot, resolvedPath),
18
- governor: ctx.governor,
19
- cache: ctx.cache,
20
- });
21
- }
@@ -1,33 +0,0 @@
1
- export interface RunCaptureConfig {
2
- readonly enabled: boolean;
3
- readonly persistLogs: boolean;
4
- readonly redactLogs: boolean;
5
- }
6
-
7
- export interface ResolveRunCaptureConfigOptions {
8
- readonly env?: Readonly<Record<string, string | undefined>>;
9
- readonly overrides?: Partial<RunCaptureConfig>;
10
- }
11
-
12
- function parseBooleanFlag(value: string | undefined, fallback: boolean): boolean {
13
- if (value === undefined) return fallback;
14
- const normalized = value.trim().toLowerCase();
15
- if ([ "0", "false", "no", "off" ].includes(normalized)) return false;
16
- if ([ "1", "true", "yes", "on" ].includes(normalized)) return true;
17
- return fallback;
18
- }
19
-
20
- export function resolveRunCaptureConfig(
21
- options: ResolveRunCaptureConfigOptions = {},
22
- ): RunCaptureConfig {
23
- const env = options.env ?? process.env;
24
- const base: RunCaptureConfig = {
25
- enabled: parseBooleanFlag(env["GRAFT_ENABLE_RUN_CAPTURE"], true),
26
- persistLogs: parseBooleanFlag(env["GRAFT_RUN_CAPTURE_PERSIST"], true),
27
- redactLogs: parseBooleanFlag(env["GRAFT_RUN_CAPTURE_REDACT"], true),
28
- };
29
- return {
30
- ...base,
31
- ...options.overrides,
32
- };
33
- }
@@ -1,72 +0,0 @@
1
- import * as crypto from "node:crypto";
2
-
3
- export interface RuntimeCausalContext {
4
- readonly transportSessionId: string;
5
- readonly workspaceSliceId: string;
6
- readonly causalSessionId: string;
7
- readonly strandId: string;
8
- readonly checkoutEpochId: string;
9
- readonly warpWriterId: string;
10
- readonly stability: "runtime_local";
11
- readonly provenanceLevel: "artifact_history";
12
- }
13
-
14
- function stableId(prefix: string, input: string): string {
15
- return `${prefix}:${crypto.createHash("sha256").update(input).digest("hex").slice(0, 16)}`;
16
- }
17
-
18
- export function buildCheckoutEpochId(
19
- repoId: string,
20
- worktreeId: string,
21
- checkoutEpoch: number,
22
- ): string {
23
- return stableId("epoch", `${repoId}:${worktreeId}:${String(checkoutEpoch)}`);
24
- }
25
-
26
- export function buildCausalSessionId(
27
- repoId: string,
28
- worktreeId: string,
29
- transportSessionId: string,
30
- workspaceSliceId: string,
31
- ): string {
32
- return stableId("causal", `${repoId}:${worktreeId}:${transportSessionId}:${workspaceSliceId}`);
33
- }
34
-
35
- export function buildStrandId(
36
- causalSessionId: string,
37
- checkoutEpochId: string,
38
- warpWriterId: string,
39
- ): string {
40
- return stableId("strand", `${causalSessionId}:${checkoutEpochId}:${warpWriterId}`);
41
- }
42
-
43
- export function buildRuntimeCausalContext(input: {
44
- readonly transportSessionId: string;
45
- readonly workspaceSliceId: string;
46
- readonly repoId: string;
47
- readonly worktreeId: string;
48
- readonly checkoutEpoch: number;
49
- readonly warpWriterId: string;
50
- }): RuntimeCausalContext {
51
- const checkoutEpochId = buildCheckoutEpochId(
52
- input.repoId,
53
- input.worktreeId,
54
- input.checkoutEpoch,
55
- );
56
- const causalSessionId = buildCausalSessionId(
57
- input.repoId,
58
- input.worktreeId,
59
- input.transportSessionId,
60
- input.workspaceSliceId,
61
- );
62
- return {
63
- transportSessionId: input.transportSessionId,
64
- workspaceSliceId: input.workspaceSliceId,
65
- causalSessionId,
66
- strandId: buildStrandId(causalSessionId, checkoutEpochId, input.warpWriterId),
67
- checkoutEpochId,
68
- warpWriterId: input.warpWriterId,
69
- stability: "runtime_local",
70
- provenanceLevel: "artifact_history",
71
- };
72
- }