@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,238 +0,0 @@
1
- import * as path from "node:path";
2
- import { type z } from "zod";
3
- import { mcpOutputBodySchemas } from "../contracts/output-schema-mcp.js";
4
-
5
- export type DaemonStatusPayload = z.output<typeof mcpOutputBodySchemas.daemon_status>;
6
- export type DaemonSessionsPayload = z.output<typeof mcpOutputBodySchemas.daemon_sessions>;
7
- export type DaemonReposPayload = z.output<typeof mcpOutputBodySchemas.daemon_repos>;
8
- export type DaemonMonitorsPayload = z.output<typeof mcpOutputBodySchemas.daemon_monitors>;
9
- export type WorkspaceStatusPayload = z.output<typeof mcpOutputBodySchemas.workspace_status>;
10
- export type WorkspaceAuthorizationsPayload = z.output<typeof mcpOutputBodySchemas.workspace_authorizations>;
11
-
12
- export interface DaemonStatusReadSnapshot {
13
- readonly status: DaemonStatusPayload;
14
- readonly sessions?: DaemonSessionsPayload | undefined;
15
- readonly currentRepo?: DaemonReposPayload | undefined;
16
- readonly monitors?: DaemonMonitorsPayload | undefined;
17
- readonly workspaceStatus?: WorkspaceStatusPayload | undefined;
18
- readonly authorizations?: WorkspaceAuthorizationsPayload | undefined;
19
- }
20
-
21
- export type UnknownCount = number | "unknown";
22
- export type DaemonHealth = "ok" | "degraded";
23
- export type DaemonCurrentAuthorization = "authorized" | "not_authorized" | "unknown";
24
- export type DaemonCurrentBindState = "bound" | "unbound" | "unknown";
25
- export type DaemonSchedulerPressure = "idle" | "running" | "queued" | "saturated";
26
- export type DaemonWorkerPressure = "idle" | "busy" | "saturated" | "unknown";
27
-
28
- export interface DaemonStatusModel {
29
- readonly command: "daemon_status";
30
- readonly cwd: string;
31
- readonly daemon: {
32
- readonly health: DaemonHealth;
33
- readonly transport: DaemonStatusPayload["transport"];
34
- readonly socketPath: string;
35
- readonly mcpPath: string;
36
- readonly healthPath: string;
37
- readonly startedAt: string;
38
- readonly sameUserOnly: true;
39
- readonly activeWarpRepos: number;
40
- };
41
- readonly sessions: {
42
- readonly total: number;
43
- readonly bound: number;
44
- readonly unbound: number;
45
- readonly listed: UnknownCount;
46
- };
47
- readonly workspaces: {
48
- readonly authorized: number;
49
- readonly authorizedRepos: number;
50
- readonly bound: UnknownCount;
51
- readonly current: {
52
- readonly cwd: string;
53
- readonly authorization: DaemonCurrentAuthorization;
54
- readonly bindState: DaemonCurrentBindState;
55
- readonly repoId: string | null;
56
- readonly worktreeRoot: string | null;
57
- readonly activeSessions: number | null;
58
- };
59
- };
60
- readonly monitors: {
61
- readonly total: number;
62
- readonly running: number;
63
- readonly paused: number;
64
- readonly stopped: number;
65
- readonly failing: number;
66
- readonly backlog: number;
67
- readonly listed: UnknownCount;
68
- };
69
- readonly scheduler: {
70
- readonly maxConcurrentJobs: number;
71
- readonly activeJobs: number;
72
- readonly queuedJobs: number;
73
- readonly interactiveQueuedJobs: number;
74
- readonly backgroundQueuedJobs: number;
75
- readonly longestQueuedWaitMs: number;
76
- readonly pressure: DaemonSchedulerPressure;
77
- };
78
- readonly workers: {
79
- readonly mode: DaemonStatusPayload["workers"]["mode"];
80
- readonly totalWorkers: number;
81
- readonly busyWorkers: number;
82
- readonly idleWorkers: number;
83
- readonly queuedTasks: number;
84
- readonly pressure: DaemonWorkerPressure;
85
- };
86
- readonly degraded: readonly string[];
87
- }
88
-
89
- interface CurrentWorkspacePosture {
90
- readonly authorization: DaemonCurrentAuthorization;
91
- readonly repoId: string | null;
92
- readonly worktreeRoot: string | null;
93
- readonly activeSessions: number | null;
94
- }
95
-
96
- function normalizePath(value: string): string {
97
- return path.resolve(value);
98
- }
99
-
100
- function schedulerPressure(status: DaemonStatusPayload): DaemonSchedulerPressure {
101
- if (status.scheduler.queuedJobs > 0) return "queued";
102
- if (status.scheduler.activeJobs >= status.scheduler.maxConcurrentJobs) return "saturated";
103
- if (status.scheduler.activeJobs > 0) return "running";
104
- return "idle";
105
- }
106
-
107
- function workerPressure(status: DaemonStatusPayload): DaemonWorkerPressure {
108
- if (status.workers.totalWorkers === 0) return "unknown";
109
- if (status.workers.queuedTasks > 0 || status.workers.busyWorkers >= status.workers.totalWorkers) {
110
- return "saturated";
111
- }
112
- if (status.workers.busyWorkers > 0) return "busy";
113
- return "idle";
114
- }
115
-
116
- function buildDegradedReasons(status: DaemonStatusPayload): string[] {
117
- const reasons: string[] = [];
118
- if (status.failingMonitors > 0) reasons.push("failing_monitors");
119
- if (status.backlogMonitors > 0) reasons.push("monitor_backlog");
120
- if (status.scheduler.queuedJobs > 0) reasons.push("scheduler_queue");
121
- if (status.scheduler.failedJobs > 0) reasons.push("scheduler_failures");
122
- if (status.workers.queuedTasks > 0) reasons.push("worker_queue");
123
- if (status.workers.failedTasks > 0) reasons.push("worker_failures");
124
- return reasons;
125
- }
126
-
127
- function currentPosture(
128
- cwd: string,
129
- snapshot: DaemonStatusReadSnapshot,
130
- ): CurrentWorkspacePosture {
131
- const normalizedCwd = normalizePath(cwd);
132
- const currentRepo = snapshot.currentRepo?.repos[0];
133
- const currentWorktree = currentRepo?.worktrees.find((worktree) => {
134
- return normalizePath(worktree.worktreeRoot) === normalizedCwd;
135
- }) ?? currentRepo?.worktrees[0];
136
-
137
- const exactAuthorization = snapshot.authorizations?.workspaces.find((workspace) => {
138
- return normalizePath(workspace.worktreeRoot) === normalizedCwd;
139
- });
140
-
141
- if (currentRepo !== undefined || exactAuthorization !== undefined) {
142
- return {
143
- authorization: "authorized",
144
- repoId: currentRepo?.repoId ?? exactAuthorization?.repoId ?? null,
145
- worktreeRoot: currentWorktree?.worktreeRoot ?? exactAuthorization?.worktreeRoot ?? null,
146
- activeSessions: currentWorktree?.activeSessions ?? exactAuthorization?.activeSessions ?? null,
147
- };
148
- }
149
-
150
- if (snapshot.authorizations !== undefined || snapshot.currentRepo !== undefined) {
151
- return {
152
- authorization: "not_authorized",
153
- repoId: null,
154
- worktreeRoot: null,
155
- activeSessions: null,
156
- };
157
- }
158
-
159
- return {
160
- authorization: "unknown",
161
- repoId: null,
162
- worktreeRoot: null,
163
- activeSessions: null,
164
- };
165
- }
166
-
167
- export function buildDaemonStatusModel(input: {
168
- readonly cwd: string;
169
- readonly snapshot: DaemonStatusReadSnapshot;
170
- }): DaemonStatusModel {
171
- const { cwd, snapshot } = input;
172
- const { status } = snapshot;
173
- const degraded = buildDegradedReasons(status);
174
- const current = currentPosture(cwd, snapshot);
175
-
176
- return {
177
- command: "daemon_status",
178
- cwd,
179
- daemon: {
180
- health: degraded.length === 0 ? "ok" : "degraded",
181
- transport: status.transport,
182
- socketPath: status.socketPath,
183
- mcpPath: status.mcpPath,
184
- healthPath: status.healthPath,
185
- startedAt: status.startedAt,
186
- sameUserOnly: status.sameUserOnly,
187
- activeWarpRepos: status.activeWarpRepos,
188
- },
189
- sessions: {
190
- total: status.activeSessions,
191
- bound: status.boundSessions,
192
- unbound: status.unboundSessions,
193
- listed: snapshot.sessions?.sessions.length ?? "unknown",
194
- },
195
- workspaces: {
196
- authorized: status.authorizedWorkspaces,
197
- authorizedRepos: status.authorizedRepos,
198
- bound: snapshot.authorizations === undefined
199
- ? "unknown"
200
- : snapshot.authorizations.workspaces.filter((workspace) => workspace.activeSessions > 0).length,
201
- current: {
202
- cwd,
203
- authorization: current.authorization,
204
- bindState: snapshot.workspaceStatus?.bindState ?? "unknown",
205
- repoId: current.repoId,
206
- worktreeRoot: current.worktreeRoot,
207
- activeSessions: current.activeSessions,
208
- },
209
- },
210
- monitors: {
211
- total: status.totalMonitors,
212
- running: status.runningMonitors,
213
- paused: status.pausedMonitors,
214
- stopped: status.stoppedMonitors,
215
- failing: status.failingMonitors,
216
- backlog: status.backlogMonitors,
217
- listed: snapshot.monitors?.monitors.length ?? "unknown",
218
- },
219
- scheduler: {
220
- maxConcurrentJobs: status.scheduler.maxConcurrentJobs,
221
- activeJobs: status.scheduler.activeJobs,
222
- queuedJobs: status.scheduler.queuedJobs,
223
- interactiveQueuedJobs: status.scheduler.interactiveQueuedJobs,
224
- backgroundQueuedJobs: status.scheduler.backgroundQueuedJobs,
225
- longestQueuedWaitMs: status.scheduler.longestQueuedWaitMs,
226
- pressure: schedulerPressure(status),
227
- },
228
- workers: {
229
- mode: status.workers.mode,
230
- totalWorkers: status.workers.totalWorkers,
231
- busyWorkers: status.workers.busyWorkers,
232
- idleWorkers: status.workers.idleWorkers,
233
- queuedTasks: status.workers.queuedTasks,
234
- pressure: workerPressure(status),
235
- },
236
- degraded,
237
- };
238
- }
@@ -1,102 +0,0 @@
1
- import { headerBox, table } from "@flyingrobots/bijou";
2
- import { initDefaultContext } from "@flyingrobots/bijou-node";
3
- import type { DaemonStatusModel, UnknownCount } from "./daemon-status-model.js";
4
-
5
- function count(value: UnknownCount): string {
6
- return typeof value === "number" ? String(value) : value;
7
- }
8
-
9
- function currentAuthLabel(value: DaemonStatusModel["workspaces"]["current"]["authorization"]): string {
10
- if (value === "authorized") return "ok";
11
- if (value === "not_authorized") return "none";
12
- return "unknown";
13
- }
14
-
15
- export function renderDaemonStatus(model: DaemonStatusModel): string {
16
- const ctx = initDefaultContext();
17
- const rows = [
18
- [
19
- "runtime",
20
- [
21
- `transport ${model.daemon.transport}`,
22
- `started ${model.daemon.startedAt}`,
23
- `warp repos ${String(model.daemon.activeWarpRepos)}`,
24
- ].join("; "),
25
- ],
26
- [
27
- "sessions",
28
- [
29
- `total ${String(model.sessions.total)}`,
30
- `bound ${String(model.sessions.bound)}`,
31
- `unbound ${String(model.sessions.unbound)}`,
32
- `listed ${count(model.sessions.listed)}`,
33
- ].join("; "),
34
- ],
35
- [
36
- "workspaces",
37
- [
38
- `auth ${String(model.workspaces.authorized)}`,
39
- `repos ${String(model.workspaces.authorizedRepos)}`,
40
- `bound ${count(model.workspaces.bound)}`,
41
- `current ${currentAuthLabel(model.workspaces.current.authorization)}`,
42
- `status-session ${model.workspaces.current.bindState}`,
43
- `active ${model.workspaces.current.activeSessions === null ? "unknown" : String(model.workspaces.current.activeSessions)}`,
44
- ].join("; "),
45
- ],
46
- [
47
- "monitors",
48
- [
49
- `total ${String(model.monitors.total)}`,
50
- `running ${String(model.monitors.running)}`,
51
- `paused ${String(model.monitors.paused)}`,
52
- `stopped ${String(model.monitors.stopped)}`,
53
- `failing ${String(model.monitors.failing)}`,
54
- `backlog ${String(model.monitors.backlog)}`,
55
- `listed ${count(model.monitors.listed)}`,
56
- ].join("; "),
57
- ],
58
- [
59
- "scheduler",
60
- [
61
- model.scheduler.pressure,
62
- `active ${String(model.scheduler.activeJobs)}/${String(model.scheduler.maxConcurrentJobs)}`,
63
- `queued ${String(model.scheduler.queuedJobs)}`,
64
- `interactive ${String(model.scheduler.interactiveQueuedJobs)}`,
65
- `background ${String(model.scheduler.backgroundQueuedJobs)}`,
66
- `longest wait ${String(model.scheduler.longestQueuedWaitMs)}ms`,
67
- ].join("; "),
68
- ],
69
- [
70
- "workers",
71
- [
72
- model.workers.pressure,
73
- model.workers.mode,
74
- `busy ${String(model.workers.busyWorkers)}/${String(model.workers.totalWorkers)}`,
75
- `idle ${String(model.workers.idleWorkers)}`,
76
- `queued ${String(model.workers.queuedTasks)}`,
77
- ].join("; "),
78
- ],
79
- ];
80
-
81
- return [
82
- headerBox("Daemon Status", {
83
- detail: `health: ${model.daemon.health}`,
84
- width: 80,
85
- ctx,
86
- }),
87
- `cwd: ${model.cwd}`,
88
- `socket: ${model.daemon.socketPath}`,
89
- `mcp: ${model.daemon.mcpPath}`,
90
- "",
91
- table({
92
- ctx,
93
- columns: [
94
- { header: "Surface" },
95
- { header: "State" },
96
- ],
97
- rows,
98
- }),
99
- "",
100
- `degraded: ${model.degraded.length === 0 ? "none" : model.degraded.join(", ")}`,
101
- ].join("\n").trimEnd();
102
- }
@@ -1,100 +0,0 @@
1
- import { Client } from "@modelcontextprotocol/sdk/client/index.js";
2
- import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
3
- import { type z } from "zod";
4
- import { mcpOutputBodySchemas } from "../contracts/output-schema-mcp.js";
5
- import { createLocalSocketFetch, ensureDaemonReady } from "../mcp/daemon-stdio-bridge.js";
6
- import { GRAFT_VERSION } from "../version.js";
7
- import type { DaemonStatusReadSnapshot } from "./daemon-status-model.js";
8
-
9
- const MCP_PATH = "/mcp";
10
-
11
- export interface ReadDaemonStatusOptions {
12
- readonly cwd: string;
13
- readonly socketPath?: string | undefined;
14
- }
15
-
16
- function readToolText(result: unknown): string {
17
- const content = (result as { readonly content?: unknown }).content;
18
- if (!Array.isArray(content)) {
19
- throw new Error("Daemon tool returned no content");
20
- }
21
- const text = content.find((item): item is { readonly type: "text"; readonly text: string } => {
22
- return typeof item === "object"
23
- && item !== null
24
- && (item as { readonly type?: unknown }).type === "text"
25
- && typeof (item as { readonly text?: unknown }).text === "string";
26
- });
27
- if (text === undefined) {
28
- throw new Error("Daemon tool returned no text content");
29
- }
30
- return text.text;
31
- }
32
-
33
- function stripMcpCommon(value: unknown): unknown {
34
- if (typeof value !== "object" || value === null) {
35
- return value;
36
- }
37
- const body = { ...(value as Record<string, unknown>) };
38
- delete body["_schema"];
39
- delete body["_receipt"];
40
- delete body["tripwire"];
41
- return body;
42
- }
43
-
44
- function parseToolBody<T>(schema: z.ZodType<T>, result: unknown): T {
45
- return schema.parse(stripMcpCommon(JSON.parse(readToolText(result)) as unknown));
46
- }
47
-
48
- export async function readDaemonStatusSnapshot(
49
- options: ReadDaemonStatusOptions,
50
- ): Promise<DaemonStatusReadSnapshot> {
51
- const socketPath = await ensureDaemonReady({
52
- ...(options.socketPath !== undefined ? { socketPath: options.socketPath } : {}),
53
- spawnIfMissing: false,
54
- });
55
- const transport = new StreamableHTTPClientTransport(
56
- new URL(`http://graft${MCP_PATH}`),
57
- { fetch: createLocalSocketFetch(socketPath) },
58
- );
59
- const client = new Client({
60
- name: "graft-cli-daemon-status",
61
- version: GRAFT_VERSION,
62
- });
63
-
64
- await client.connect(transport as unknown as Parameters<Client["connect"]>[0]);
65
- try {
66
- const call = async <T>(
67
- tool: string,
68
- schema: z.ZodType<T>,
69
- args: Record<string, unknown> = {},
70
- ): Promise<T> => {
71
- const result = await client.callTool({
72
- name: tool,
73
- arguments: args,
74
- });
75
- return parseToolBody(schema, result);
76
- };
77
-
78
- const [status, sessions, currentRepo, monitors, workspaceStatus, authorizations] = await Promise.all([
79
- call("daemon_status", mcpOutputBodySchemas.daemon_status),
80
- call("daemon_sessions", mcpOutputBodySchemas.daemon_sessions),
81
- call("daemon_repos", mcpOutputBodySchemas.daemon_repos, { cwd: options.cwd }),
82
- call("daemon_monitors", mcpOutputBodySchemas.daemon_monitors),
83
- call("workspace_status", mcpOutputBodySchemas.workspace_status),
84
- call("workspace_authorizations", mcpOutputBodySchemas.workspace_authorizations),
85
- ]);
86
-
87
- return {
88
- status,
89
- sessions,
90
- currentRepo,
91
- monitors,
92
- workspaceStatus,
93
- authorizations,
94
- };
95
- } finally {
96
- await client.close().catch(() => {
97
- return undefined;
98
- });
99
- }
100
- }
@@ -1,18 +0,0 @@
1
- import { resolveEntrypointArgs } from "./command-parser.js";
2
- import { runCli } from "./main.js";
3
-
4
- export interface CliEntrypointOptions {
5
- readonly argv?: readonly string[] | undefined;
6
- readonly stdinIsTTY?: boolean | undefined;
7
- readonly stdoutIsTTY?: boolean | undefined;
8
- }
9
-
10
- export async function runCliEntrypoint(options: CliEntrypointOptions = {}): Promise<void> {
11
- await runCli({
12
- args: resolveEntrypointArgs(
13
- options.argv ?? process.argv.slice(2),
14
- options.stdinIsTTY ?? process.stdin.isTTY,
15
- options.stdoutIsTTY ?? process.stdout.isTTY,
16
- ),
17
- });
18
- }
@@ -1,131 +0,0 @@
1
- export type GitGraftEnhanceSemverImpact = "major" | "minor" | "patch" | "none";
2
-
3
- export interface GitGraftEnhanceDiffBucket {
4
- readonly length: number;
5
- }
6
-
7
- export interface GitGraftEnhanceFileDiff {
8
- readonly path: string;
9
- readonly status: string;
10
- readonly summary: string;
11
- readonly diff: {
12
- readonly added: GitGraftEnhanceDiffBucket;
13
- readonly removed: GitGraftEnhanceDiffBucket;
14
- readonly changed: GitGraftEnhanceDiffBucket;
15
- readonly unchangedCount?: number | undefined;
16
- };
17
- }
18
-
19
- export interface GitGraftEnhanceStructuralInput {
20
- readonly base: string;
21
- readonly head: string;
22
- readonly summary: string;
23
- readonly layer: string;
24
- readonly files: readonly GitGraftEnhanceFileDiff[];
25
- readonly refused?: readonly unknown[] | undefined;
26
- }
27
-
28
- export interface GitGraftEnhanceExportsInput {
29
- readonly base: string;
30
- readonly head: string;
31
- readonly added: readonly unknown[];
32
- readonly removed: readonly unknown[];
33
- readonly changed: readonly unknown[];
34
- readonly semverImpact: GitGraftEnhanceSemverImpact;
35
- readonly summary: string;
36
- }
37
-
38
- export interface BuildGitGraftEnhanceModelInput {
39
- readonly since: string;
40
- readonly head: string;
41
- readonly structural: GitGraftEnhanceStructuralInput;
42
- readonly exports: GitGraftEnhanceExportsInput;
43
- }
44
-
45
- export interface GitGraftEnhanceTopFile {
46
- readonly path: string;
47
- readonly status: string;
48
- readonly changeCount: number;
49
- readonly summary: string;
50
- }
51
-
52
- export interface GitGraftEnhanceModel {
53
- readonly range: {
54
- readonly since: string;
55
- readonly head: string;
56
- };
57
- readonly structural: {
58
- readonly changedFiles: number;
59
- readonly addedSymbols: number;
60
- readonly removedSymbols: number;
61
- readonly changedSymbols: number;
62
- readonly topFilesByChangeCount: readonly GitGraftEnhanceTopFile[];
63
- };
64
- readonly exports: {
65
- readonly changed: boolean;
66
- readonly semverImpact: GitGraftEnhanceSemverImpact;
67
- readonly addedExports: number;
68
- readonly removedExports: number;
69
- readonly changedExports: number;
70
- };
71
- readonly warnings: readonly string[];
72
- }
73
-
74
- function fileChangeCount(file: GitGraftEnhanceFileDiff): number {
75
- return file.diff.added.length + file.diff.removed.length + file.diff.changed.length;
76
- }
77
-
78
- function topFiles(files: readonly GitGraftEnhanceFileDiff[]): readonly GitGraftEnhanceTopFile[] {
79
- return [...files]
80
- .map((file) => ({
81
- path: file.path,
82
- status: file.status,
83
- changeCount: fileChangeCount(file),
84
- summary: file.summary,
85
- }))
86
- .sort((a, b) => b.changeCount - a.changeCount || a.path.localeCompare(b.path))
87
- .slice(0, 5);
88
- }
89
-
90
- function buildWarnings(input: BuildGitGraftEnhanceModelInput): readonly string[] {
91
- const warnings: string[] = [];
92
- if (input.structural.files.length === 0) {
93
- warnings.push("No structural changes found for this range.");
94
- }
95
- const refusedCount = input.structural.refused?.length ?? 0;
96
- if (refusedCount > 0) {
97
- warnings.push(`${String(refusedCount)} structural files were refused by policy.`);
98
- }
99
- return warnings;
100
- }
101
-
102
- export function buildGitGraftEnhanceModel(input: BuildGitGraftEnhanceModelInput): GitGraftEnhanceModel {
103
- const addedSymbols = input.structural.files.reduce((total, file) => total + file.diff.added.length, 0);
104
- const removedSymbols = input.structural.files.reduce((total, file) => total + file.diff.removed.length, 0);
105
- const changedSymbols = input.structural.files.reduce((total, file) => total + file.diff.changed.length, 0);
106
- const addedExports = input.exports.added.length;
107
- const removedExports = input.exports.removed.length;
108
- const changedExports = input.exports.changed.length;
109
-
110
- return {
111
- range: {
112
- since: input.since,
113
- head: input.head,
114
- },
115
- structural: {
116
- changedFiles: input.structural.files.length,
117
- addedSymbols,
118
- removedSymbols,
119
- changedSymbols,
120
- topFilesByChangeCount: topFiles(input.structural.files),
121
- },
122
- exports: {
123
- changed: addedExports + removedExports + changedExports > 0,
124
- semverImpact: input.exports.semverImpact,
125
- addedExports,
126
- removedExports,
127
- changedExports,
128
- },
129
- warnings: buildWarnings(input),
130
- };
131
- }
@@ -1,33 +0,0 @@
1
- import type { GitGraftEnhanceModel } from "./git-graft-enhance-model.js";
2
-
3
- export function renderGitGraftEnhance(model: GitGraftEnhanceModel): string {
4
- const lines = [
5
- "Git Graft Enhance",
6
- `range: ${model.range.since}..${model.range.head}`,
7
- "",
8
- "Structural",
9
- `files: ${String(model.structural.changedFiles)}`,
10
- `symbols: +${String(model.structural.addedSymbols)} -${String(model.structural.removedSymbols)} ~${String(model.structural.changedSymbols)}`,
11
- "",
12
- "Exports",
13
- `exports: ${model.exports.changed ? "changed" : "unchanged"}`,
14
- `semver impact: ${model.exports.semverImpact}`,
15
- `export symbols: +${String(model.exports.addedExports)} -${String(model.exports.removedExports)} ~${String(model.exports.changedExports)}`,
16
- ];
17
-
18
- if (model.structural.topFilesByChangeCount.length > 0) {
19
- lines.push("", "Top files");
20
- for (const file of model.structural.topFilesByChangeCount) {
21
- lines.push(`- ${file.path} (${file.status}, ${String(file.changeCount)}): ${file.summary}`);
22
- }
23
- }
24
-
25
- if (model.warnings.length > 0) {
26
- lines.push("", "warnings:");
27
- for (const warning of model.warnings) {
28
- lines.push(`- ${warning}`);
29
- }
30
- }
31
-
32
- return lines.join("\n");
33
- }
@@ -1,54 +0,0 @@
1
- import { CanonicalJsonCodec } from "../adapters/canonical-json.js";
2
- import { attachCliSchemaMeta, validateCliOutput } from "../contracts/output-schemas.js";
3
- import type { JsonObject } from "../contracts/json-object.js";
4
- import type { McpToolName } from "../contracts/capabilities.js";
5
- import {
6
- buildGitGraftEnhanceModel,
7
- type GitGraftEnhanceExportsInput,
8
- type GitGraftEnhanceStructuralInput,
9
- } from "./git-graft-enhance-model.js";
10
- import { renderGitGraftEnhance } from "./git-graft-enhance-render.js";
11
- import { invokePeerCommand, type Writer } from "./peer-command.js";
12
-
13
- const codec = new CanonicalJsonCodec();
14
-
15
- export type GitGraftEnhancePeerInvoker = (
16
- cwd: string,
17
- tool: McpToolName,
18
- args: JsonObject,
19
- ) => Promise<JsonObject>;
20
-
21
- export interface RunGitGraftEnhanceOptions {
22
- readonly cwd: string;
23
- readonly since: string;
24
- readonly head?: string | undefined;
25
- readonly json: boolean;
26
- readonly stdout?: Writer | undefined;
27
- readonly invokePeer?: GitGraftEnhancePeerInvoker | undefined;
28
- }
29
-
30
- function emitJson(model: ReturnType<typeof buildGitGraftEnhanceModel>, writer: Writer): void {
31
- writer.write(`${codec.encode(validateCliOutput("git_graft_enhance", attachCliSchemaMeta("git_graft_enhance", model)))}\n`);
32
- }
33
-
34
- export async function runGitGraftEnhance(options: RunGitGraftEnhanceOptions): Promise<void> {
35
- const stdout = options.stdout ?? process.stdout;
36
- const head = options.head ?? "HEAD";
37
- const invoke = options.invokePeer ?? invokePeerCommand;
38
- const args = { base: options.since, head };
39
- const structural = await invoke(options.cwd, "graft_since", args) as unknown as GitGraftEnhanceStructuralInput;
40
- const exports = await invoke(options.cwd, "graft_exports", args) as unknown as GitGraftEnhanceExportsInput;
41
- const model = buildGitGraftEnhanceModel({
42
- since: options.since,
43
- head,
44
- structural,
45
- exports,
46
- });
47
-
48
- if (options.json) {
49
- emitJson(model, stdout);
50
- return;
51
- }
52
-
53
- stdout.write(`${renderGitGraftEnhance(model)}\n`);
54
- }