gsd-pi 2.49.0-dev.de3d9f6 → 2.50.0-dev.9476db8

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 (249) hide show
  1. package/dist/headless-ui.js +12 -2
  2. package/dist/headless.js +29 -13
  3. package/dist/resources/extensions/gsd/auto/infra-errors.js +1 -0
  4. package/dist/resources/extensions/gsd/auto/phases.js +11 -11
  5. package/dist/resources/extensions/gsd/auto/resolve.js +2 -2
  6. package/dist/resources/extensions/gsd/auto/run-unit.js +2 -2
  7. package/dist/resources/extensions/gsd/auto/session.js +4 -0
  8. package/dist/resources/extensions/gsd/auto-artifact-paths.js +8 -10
  9. package/dist/resources/extensions/gsd/auto-dashboard.js +6 -3
  10. package/dist/resources/extensions/gsd/auto-dispatch.js +33 -21
  11. package/dist/resources/extensions/gsd/auto-post-unit.js +17 -24
  12. package/dist/resources/extensions/gsd/auto-prompts.js +102 -21
  13. package/dist/resources/extensions/gsd/auto-recovery.js +62 -184
  14. package/dist/resources/extensions/gsd/auto-start.js +4 -31
  15. package/dist/resources/extensions/gsd/auto-timers.js +2 -2
  16. package/dist/resources/extensions/gsd/auto-verification.js +4 -7
  17. package/dist/resources/extensions/gsd/auto-worktree.js +257 -113
  18. package/dist/resources/extensions/gsd/auto.js +7 -5
  19. package/dist/resources/extensions/gsd/bootstrap/db-tools.js +89 -0
  20. package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +8 -1
  21. package/dist/resources/extensions/gsd/branch-patterns.js +13 -0
  22. package/dist/resources/extensions/gsd/doctor-checks.js +5 -1234
  23. package/dist/resources/extensions/gsd/doctor-engine-checks.js +168 -0
  24. package/dist/resources/extensions/gsd/doctor-environment.js +28 -7
  25. package/dist/resources/extensions/gsd/doctor-git-checks.js +405 -0
  26. package/dist/resources/extensions/gsd/doctor-global-checks.js +74 -0
  27. package/dist/resources/extensions/gsd/doctor-runtime-checks.js +600 -0
  28. package/dist/resources/extensions/gsd/doctor.js +9 -1
  29. package/dist/resources/extensions/gsd/extension-manifest.json +1 -1
  30. package/dist/resources/extensions/gsd/git-service.js +9 -10
  31. package/dist/resources/extensions/gsd/gsd-db.js +124 -1
  32. package/dist/resources/extensions/gsd/guided-flow-queue.js +10 -11
  33. package/dist/resources/extensions/gsd/markdown-renderer.js +33 -5
  34. package/dist/resources/extensions/gsd/preferences-types.js +2 -1
  35. package/dist/resources/extensions/gsd/preferences-validation.js +39 -0
  36. package/dist/resources/extensions/gsd/prompts/complete-milestone.md +27 -8
  37. package/dist/resources/extensions/gsd/prompts/complete-slice.md +9 -8
  38. package/dist/resources/extensions/gsd/prompts/execute-task.md +16 -13
  39. package/dist/resources/extensions/gsd/prompts/forensics.md +12 -5
  40. package/dist/resources/extensions/gsd/prompts/gate-evaluate.md +32 -0
  41. package/dist/resources/extensions/gsd/prompts/guided-complete-slice.md +1 -1
  42. package/dist/resources/extensions/gsd/prompts/guided-execute-task.md +1 -1
  43. package/dist/resources/extensions/gsd/prompts/guided-plan-milestone.md +1 -1
  44. package/dist/resources/extensions/gsd/prompts/guided-plan-slice.md +1 -1
  45. package/dist/resources/extensions/gsd/prompts/plan-milestone.md +1 -1
  46. package/dist/resources/extensions/gsd/prompts/plan-slice.md +8 -3
  47. package/dist/resources/extensions/gsd/prompts/reassess-roadmap.md +3 -0
  48. package/dist/resources/extensions/gsd/prompts/replan-slice.md +1 -1
  49. package/dist/resources/extensions/gsd/repo-identity.js +29 -0
  50. package/dist/resources/extensions/gsd/roadmap-slices.js +2 -2
  51. package/dist/resources/extensions/gsd/session-forensics.js +6 -11
  52. package/dist/resources/extensions/gsd/session-lock.js +67 -56
  53. package/dist/resources/extensions/gsd/state.js +34 -7
  54. package/dist/resources/extensions/gsd/templates/milestone-summary.md +8 -0
  55. package/dist/resources/extensions/gsd/templates/plan.md +16 -0
  56. package/dist/resources/extensions/gsd/templates/roadmap.md +13 -0
  57. package/dist/resources/extensions/gsd/templates/slice-summary.md +9 -0
  58. package/dist/resources/extensions/gsd/templates/task-plan.md +24 -0
  59. package/dist/resources/extensions/gsd/tools/plan-slice.js +14 -1
  60. package/dist/resources/extensions/gsd/tools/validate-milestone.js +3 -3
  61. package/dist/resources/extensions/gsd/verdict-parser.js +84 -0
  62. package/dist/resources/extensions/gsd/worktree-resolver.js +24 -0
  63. package/dist/resources/extensions/gsd/worktree.js +3 -2
  64. package/dist/resources/extensions/remote-questions/config.js +3 -5
  65. package/dist/resources/extensions/search-the-web/native-search.js +8 -3
  66. package/dist/resources/extensions/search-the-web/tool-search.js +19 -2
  67. package/dist/resources/skills/github-workflows/references/gh/SKILL.md +22 -1
  68. package/dist/web/standalone/.next/BUILD_ID +1 -1
  69. package/dist/web/standalone/.next/app-path-routes-manifest.json +15 -15
  70. package/dist/web/standalone/.next/build-manifest.json +3 -3
  71. package/dist/web/standalone/.next/prerender-manifest.json +3 -3
  72. package/dist/web/standalone/.next/react-loadable-manifest.json +1 -1
  73. package/dist/web/standalone/.next/required-server-files.json +1 -1
  74. package/dist/web/standalone/.next/server/app/_global-error.html +2 -2
  75. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  76. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  77. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  78. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  79. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  80. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  81. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  82. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  83. package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
  84. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  85. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  86. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  87. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  88. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  89. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  90. package/dist/web/standalone/.next/server/app/index.html +1 -1
  91. package/dist/web/standalone/.next/server/app/index.rsc +1 -1
  92. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  93. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
  94. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  95. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
  96. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  97. package/dist/web/standalone/.next/server/app-paths-manifest.json +15 -15
  98. package/dist/web/standalone/.next/server/chunks/229.js +2 -2
  99. package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
  100. package/dist/web/standalone/.next/server/middleware-react-loadable-manifest.js +1 -1
  101. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  102. package/dist/web/standalone/.next/server/pages/500.html +2 -2
  103. package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
  104. package/dist/web/standalone/.next/static/chunks/4024.7c75ac378de0f2b5.js +9 -0
  105. package/dist/web/standalone/.next/static/chunks/{webpack-0a4cd455ec4197d2.js → webpack-2473ce2c3879fff4.js} +1 -1
  106. package/dist/web/standalone/server.js +1 -1
  107. package/package.json +1 -1
  108. package/packages/pi-agent-core/dist/agent-loop.d.ts.map +1 -1
  109. package/packages/pi-agent-core/dist/agent-loop.js +4 -1
  110. package/packages/pi-agent-core/dist/agent-loop.js.map +1 -1
  111. package/packages/pi-agent-core/src/agent-loop.ts +4 -1
  112. package/packages/pi-ai/dist/providers/openai-codex-responses.js +39 -10
  113. package/packages/pi-ai/dist/providers/openai-codex-responses.js.map +1 -1
  114. package/packages/pi-ai/src/providers/openai-codex-responses.ts +39 -8
  115. package/packages/pi-coding-agent/dist/core/blob-store.d.ts.map +1 -1
  116. package/packages/pi-coding-agent/dist/core/blob-store.js +8 -3
  117. package/packages/pi-coding-agent/dist/core/blob-store.js.map +1 -1
  118. package/packages/pi-coding-agent/dist/core/discovery-cache.d.ts.map +1 -1
  119. package/packages/pi-coding-agent/dist/core/discovery-cache.js +9 -2
  120. package/packages/pi-coding-agent/dist/core/discovery-cache.js.map +1 -1
  121. package/packages/pi-coding-agent/dist/core/retry-handler.js +1 -1
  122. package/packages/pi-coding-agent/dist/core/retry-handler.js.map +1 -1
  123. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  124. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js +7 -32
  125. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js.map +1 -1
  126. package/packages/pi-coding-agent/dist/modes/rpc/jsonl.d.ts.map +1 -1
  127. package/packages/pi-coding-agent/dist/modes/rpc/jsonl.js +5 -0
  128. package/packages/pi-coding-agent/dist/modes/rpc/jsonl.js.map +1 -1
  129. package/packages/pi-coding-agent/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  130. package/packages/pi-coding-agent/dist/modes/rpc/rpc-client.js +0 -1
  131. package/packages/pi-coding-agent/dist/modes/rpc/rpc-client.js.map +1 -1
  132. package/packages/pi-coding-agent/dist/modes/rpc/rpc-mode.js +1 -1
  133. package/packages/pi-coding-agent/dist/modes/rpc/rpc-mode.js.map +1 -1
  134. package/packages/pi-coding-agent/package.json +1 -1
  135. package/packages/pi-coding-agent/src/core/blob-store.ts +6 -3
  136. package/packages/pi-coding-agent/src/core/discovery-cache.ts +9 -2
  137. package/packages/pi-coding-agent/src/core/retry-handler.ts +1 -1
  138. package/packages/pi-coding-agent/src/modes/interactive/interactive-mode.ts +7 -32
  139. package/packages/pi-coding-agent/src/modes/rpc/jsonl.ts +6 -0
  140. package/packages/pi-coding-agent/src/modes/rpc/rpc-client.ts +0 -2
  141. package/packages/pi-coding-agent/src/modes/rpc/rpc-mode.ts +2 -2
  142. package/pkg/package.json +1 -1
  143. package/src/resources/extensions/gsd/auto/infra-errors.ts +1 -0
  144. package/src/resources/extensions/gsd/auto/phases.ts +10 -11
  145. package/src/resources/extensions/gsd/auto/resolve.ts +3 -3
  146. package/src/resources/extensions/gsd/auto/run-unit.ts +2 -2
  147. package/src/resources/extensions/gsd/auto/session.ts +5 -0
  148. package/src/resources/extensions/gsd/auto/types.ts +13 -0
  149. package/src/resources/extensions/gsd/auto-artifact-paths.ts +19 -21
  150. package/src/resources/extensions/gsd/auto-dashboard.ts +5 -2
  151. package/src/resources/extensions/gsd/auto-dispatch.ts +39 -21
  152. package/src/resources/extensions/gsd/auto-loop.ts +1 -1
  153. package/src/resources/extensions/gsd/auto-post-unit.ts +18 -28
  154. package/src/resources/extensions/gsd/auto-prompts.ts +113 -19
  155. package/src/resources/extensions/gsd/auto-recovery.ts +65 -199
  156. package/src/resources/extensions/gsd/auto-start.ts +7 -27
  157. package/src/resources/extensions/gsd/auto-timers.ts +2 -2
  158. package/src/resources/extensions/gsd/auto-verification.ts +4 -7
  159. package/src/resources/extensions/gsd/auto-worktree.ts +305 -108
  160. package/src/resources/extensions/gsd/auto.ts +11 -10
  161. package/src/resources/extensions/gsd/bootstrap/db-tools.ts +93 -0
  162. package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +8 -0
  163. package/src/resources/extensions/gsd/branch-patterns.ts +16 -0
  164. package/src/resources/extensions/gsd/doctor-checks.ts +5 -1291
  165. package/src/resources/extensions/gsd/doctor-engine-checks.ts +182 -0
  166. package/src/resources/extensions/gsd/doctor-environment.ts +30 -7
  167. package/src/resources/extensions/gsd/doctor-git-checks.ts +415 -0
  168. package/src/resources/extensions/gsd/doctor-global-checks.ts +84 -0
  169. package/src/resources/extensions/gsd/doctor-runtime-checks.ts +626 -0
  170. package/src/resources/extensions/gsd/doctor.ts +9 -1
  171. package/src/resources/extensions/gsd/extension-manifest.json +1 -1
  172. package/src/resources/extensions/gsd/git-service.ts +7 -15
  173. package/src/resources/extensions/gsd/gsd-db.ts +150 -2
  174. package/src/resources/extensions/gsd/guided-flow-queue.ts +11 -12
  175. package/src/resources/extensions/gsd/markdown-renderer.ts +37 -4
  176. package/src/resources/extensions/gsd/preferences-types.ts +5 -1
  177. package/src/resources/extensions/gsd/preferences-validation.ts +37 -0
  178. package/src/resources/extensions/gsd/prompts/complete-milestone.md +27 -8
  179. package/src/resources/extensions/gsd/prompts/complete-slice.md +9 -8
  180. package/src/resources/extensions/gsd/prompts/execute-task.md +16 -13
  181. package/src/resources/extensions/gsd/prompts/forensics.md +12 -5
  182. package/src/resources/extensions/gsd/prompts/gate-evaluate.md +32 -0
  183. package/src/resources/extensions/gsd/prompts/guided-complete-slice.md +1 -1
  184. package/src/resources/extensions/gsd/prompts/guided-execute-task.md +1 -1
  185. package/src/resources/extensions/gsd/prompts/guided-plan-milestone.md +1 -1
  186. package/src/resources/extensions/gsd/prompts/guided-plan-slice.md +1 -1
  187. package/src/resources/extensions/gsd/prompts/plan-milestone.md +1 -1
  188. package/src/resources/extensions/gsd/prompts/plan-slice.md +8 -3
  189. package/src/resources/extensions/gsd/prompts/reassess-roadmap.md +3 -0
  190. package/src/resources/extensions/gsd/prompts/replan-slice.md +1 -1
  191. package/src/resources/extensions/gsd/repo-identity.ts +28 -0
  192. package/src/resources/extensions/gsd/roadmap-slices.ts +2 -2
  193. package/src/resources/extensions/gsd/session-forensics.ts +6 -11
  194. package/src/resources/extensions/gsd/session-lock.ts +92 -64
  195. package/src/resources/extensions/gsd/state.ts +38 -5
  196. package/src/resources/extensions/gsd/templates/milestone-summary.md +8 -0
  197. package/src/resources/extensions/gsd/templates/plan.md +16 -0
  198. package/src/resources/extensions/gsd/templates/roadmap.md +13 -0
  199. package/src/resources/extensions/gsd/templates/slice-summary.md +9 -0
  200. package/src/resources/extensions/gsd/templates/task-plan.md +24 -0
  201. package/src/resources/extensions/gsd/tests/agent-end-retry.test.ts +2 -2
  202. package/src/resources/extensions/gsd/tests/auto-loop.test.ts +35 -0
  203. package/src/resources/extensions/gsd/tests/auto-recovery.test.ts +1 -81
  204. package/src/resources/extensions/gsd/tests/complete-slice.test.ts +2 -2
  205. package/src/resources/extensions/gsd/tests/complete-task.test.ts +2 -2
  206. package/src/resources/extensions/gsd/tests/completed-units-metrics-sync.test.ts +9 -12
  207. package/src/resources/extensions/gsd/tests/doctor-environment.test.ts +115 -1
  208. package/src/resources/extensions/gsd/tests/doctor-fixlevel.test.ts +65 -1
  209. package/src/resources/extensions/gsd/tests/doctor-git.test.ts +50 -0
  210. package/src/resources/extensions/gsd/tests/gate-dispatch.test.ts +189 -0
  211. package/src/resources/extensions/gsd/tests/gate-storage.test.ts +156 -0
  212. package/src/resources/extensions/gsd/tests/git-service.test.ts +49 -0
  213. package/src/resources/extensions/gsd/tests/gsd-db.test.ts +1 -1
  214. package/src/resources/extensions/gsd/tests/infra-error.test.ts +12 -2
  215. package/src/resources/extensions/gsd/tests/journal-integration.test.ts +39 -0
  216. package/src/resources/extensions/gsd/tests/md-importer.test.ts +1 -1
  217. package/src/resources/extensions/gsd/tests/memory-store.test.ts +2 -2
  218. package/src/resources/extensions/gsd/tests/quality-gates.test.ts +347 -0
  219. package/src/resources/extensions/gsd/tests/queue-completed-milestone-perf.test.ts +155 -0
  220. package/src/resources/extensions/gsd/tests/replan-slice.test.ts +2 -1
  221. package/src/resources/extensions/gsd/tests/repo-identity-worktree.test.ts +32 -0
  222. package/src/resources/extensions/gsd/tests/roadmap-slices.test.ts +26 -0
  223. package/src/resources/extensions/gsd/tests/run-uat.test.ts +20 -16
  224. package/src/resources/extensions/gsd/tests/session-lock-transient-read.test.ts +223 -0
  225. package/src/resources/extensions/gsd/tests/skill-activation.test.ts +44 -4
  226. package/src/resources/extensions/gsd/tests/tool-naming.test.ts +1 -1
  227. package/src/resources/extensions/gsd/tests/validate-milestone.test.ts +2 -1
  228. package/src/resources/extensions/gsd/tests/verification-gate.test.ts +0 -16
  229. package/src/resources/extensions/gsd/tests/worktree-resolver.test.ts +67 -0
  230. package/src/resources/extensions/gsd/tests/worktree-sync-milestones.test.ts +1 -1
  231. package/src/resources/extensions/gsd/tests/worktree-sync-overwrite-loop.test.ts +204 -0
  232. package/src/resources/extensions/gsd/tools/plan-slice.ts +16 -0
  233. package/src/resources/extensions/gsd/tools/validate-milestone.ts +3 -3
  234. package/src/resources/extensions/gsd/types.ts +30 -0
  235. package/src/resources/extensions/gsd/verdict-parser.ts +95 -0
  236. package/src/resources/extensions/gsd/verification-gate.ts +0 -2
  237. package/src/resources/extensions/gsd/worktree-resolver.ts +31 -0
  238. package/src/resources/extensions/gsd/worktree.ts +3 -2
  239. package/src/resources/extensions/remote-questions/config.ts +3 -5
  240. package/src/resources/extensions/search-the-web/native-search.ts +8 -3
  241. package/src/resources/extensions/search-the-web/tool-search.ts +22 -2
  242. package/src/resources/skills/github-workflows/references/gh/SKILL.md +22 -1
  243. package/dist/resources/extensions/gsd/auto-worktree-sync.js +0 -191
  244. package/dist/resources/extensions/gsd/resource-version.js +0 -97
  245. package/dist/web/standalone/.next/static/chunks/4024.11ca5c01938e5948.js +0 -9
  246. package/src/resources/extensions/gsd/auto-worktree-sync.ts +0 -234
  247. package/src/resources/extensions/gsd/resource-version.ts +0 -101
  248. /package/dist/web/standalone/.next/static/{ceckLbAMjhzHaQ3RPtJnT → MkE9kzqUGny3-cSE0GNnm}/_buildManifest.js +0 -0
  249. /package/dist/web/standalone/.next/static/{ceckLbAMjhzHaQ3RPtJnT → MkE9kzqUGny3-cSE0GNnm}/_ssgManifest.js +0 -0
@@ -0,0 +1,74 @@
1
+ import { existsSync, readdirSync, rmSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { readRepoMeta, externalProjectsRoot } from "./repo-identity.js";
4
+ /**
5
+ * Check for orphaned project state directories in ~/.gsd/projects/.
6
+ *
7
+ * A project directory is orphaned when its recorded gitRoot no longer exists
8
+ * on disk — the repo was deleted, moved, or the external drive was unmounted.
9
+ * These directories accumulate silently and waste disk space.
10
+ *
11
+ * Severity: info — orphaned state is harmless but takes disk space.
12
+ * Fixable: yes — rmSync the directory. Never auto-fixed at fixLevel="task".
13
+ */
14
+ export async function checkGlobalHealth(issues, fixesApplied, shouldFix) {
15
+ try {
16
+ const projectsDir = externalProjectsRoot();
17
+ if (!existsSync(projectsDir))
18
+ return;
19
+ let entries;
20
+ try {
21
+ entries = readdirSync(projectsDir, { withFileTypes: true })
22
+ .filter(e => e.isDirectory())
23
+ .map(e => e.name);
24
+ }
25
+ catch {
26
+ return; // Can't read directory — skip
27
+ }
28
+ if (entries.length === 0)
29
+ return;
30
+ const orphaned = [];
31
+ let unknownCount = 0;
32
+ for (const hash of entries) {
33
+ const dirPath = join(projectsDir, hash);
34
+ const meta = readRepoMeta(dirPath);
35
+ if (!meta) {
36
+ unknownCount++;
37
+ continue;
38
+ }
39
+ if (!existsSync(meta.gitRoot)) {
40
+ orphaned.push({ hash, gitRoot: meta.gitRoot, remoteUrl: meta.remoteUrl });
41
+ }
42
+ }
43
+ if (orphaned.length === 0)
44
+ return;
45
+ const labels = orphaned.slice(0, 3).map(o => o.gitRoot).join(", ");
46
+ const overflow = orphaned.length > 3 ? ` (+${orphaned.length - 3} more)` : "";
47
+ const unknownNote = unknownCount > 0 ? ` — ${unknownCount} additional director${unknownCount === 1 ? "y" : "ies"} have no metadata yet (open those repos once to register them)` : "";
48
+ issues.push({
49
+ severity: "info",
50
+ code: "orphaned_project_state",
51
+ scope: "project",
52
+ unitId: "global",
53
+ message: `${orphaned.length} orphaned GSD project state director${orphaned.length === 1 ? "y" : "ies"} in ${projectsDir} whose git root no longer exists: ${labels}${overflow}${unknownNote}. Run /gsd cleanup projects to audit or /gsd cleanup projects --fix to reclaim disk space.`,
54
+ file: projectsDir,
55
+ fixable: true,
56
+ });
57
+ if (shouldFix("orphaned_project_state")) {
58
+ let removed = 0;
59
+ for (const { hash } of orphaned) {
60
+ try {
61
+ rmSync(join(projectsDir, hash), { recursive: true, force: true });
62
+ removed++;
63
+ }
64
+ catch {
65
+ // Individual removal failure is non-fatal — continue with remaining
66
+ }
67
+ }
68
+ fixesApplied.push(`removed ${removed} orphaned project state director${removed === 1 ? "y" : "ies"} from ${projectsDir}`);
69
+ }
70
+ }
71
+ catch {
72
+ // Non-fatal — global health check must not block per-project doctor
73
+ }
74
+ }
@@ -0,0 +1,600 @@
1
+ import { existsSync, lstatSync, readdirSync, readFileSync, realpathSync, rmSync, statSync } from "node:fs";
2
+ import { basename, dirname, join } from "node:path";
3
+ import { cleanNumberedGsdVariants } from "./repo-identity.js";
4
+ import { milestonesDir, gsdRoot, resolveGsdRootFile } from "./paths.js";
5
+ import { deriveState } from "./state.js";
6
+ import { saveFile } from "./files.js";
7
+ import { nativeIsRepo, nativeForEachRef, nativeUpdateRef } from "./native-git-bridge.js";
8
+ import { readCrashLock, isLockProcessAlive, clearLock } from "./crash-recovery.js";
9
+ import { ensureGitignore } from "./gitignore.js";
10
+ import { readAllSessionStatuses, isSessionStale, removeSessionStatus } from "./session-status-io.js";
11
+ import { recoverFailedMigration } from "./migrate-external.js";
12
+ export async function checkRuntimeHealth(basePath, issues, fixesApplied, shouldFix) {
13
+ const root = gsdRoot(basePath);
14
+ // ── Stale crash lock ──────────────────────────────────────────────────
15
+ try {
16
+ const lock = readCrashLock(basePath);
17
+ if (lock) {
18
+ const alive = isLockProcessAlive(lock);
19
+ if (!alive) {
20
+ issues.push({
21
+ severity: "error",
22
+ code: "stale_crash_lock",
23
+ scope: "project",
24
+ unitId: "project",
25
+ message: `Stale auto.lock from PID ${lock.pid} (started ${lock.startedAt}, was executing ${lock.unitType} ${lock.unitId}) — process is no longer running`,
26
+ file: ".gsd/auto.lock",
27
+ fixable: true,
28
+ });
29
+ if (shouldFix("stale_crash_lock")) {
30
+ clearLock(basePath);
31
+ fixesApplied.push("cleared stale auto.lock");
32
+ }
33
+ }
34
+ }
35
+ }
36
+ catch {
37
+ // Non-fatal — crash lock check failed
38
+ }
39
+ // ── Stranded lock directory ────────────────────────────────────────────
40
+ // proper-lockfile creates a `.gsd.lock/` directory as the OS-level lock
41
+ // mechanism. If the process was SIGKILLed or crashed hard, this directory
42
+ // can remain on disk without any live process holding it. The next session
43
+ // fails to acquire the lock until the directory is removed (#1245).
44
+ try {
45
+ const lockDir = join(dirname(root), `${basename(root)}.lock`);
46
+ if (existsSync(lockDir)) {
47
+ const statRes = statSync(lockDir);
48
+ if (statRes.isDirectory()) {
49
+ // Check if any live process actually holds this lock
50
+ const lock = readCrashLock(basePath);
51
+ const lockHolderAlive = lock ? isLockProcessAlive(lock) : false;
52
+ if (!lockHolderAlive) {
53
+ issues.push({
54
+ severity: "error",
55
+ code: "stranded_lock_directory",
56
+ scope: "project",
57
+ unitId: "project",
58
+ message: `Stranded lock directory "${lockDir}" exists but no live process holds the session lock. This blocks new auto-mode sessions from starting.`,
59
+ file: lockDir,
60
+ fixable: true,
61
+ });
62
+ if (shouldFix("stranded_lock_directory")) {
63
+ try {
64
+ rmSync(lockDir, { recursive: true, force: true });
65
+ fixesApplied.push(`removed stranded lock directory ${lockDir}`);
66
+ }
67
+ catch {
68
+ fixesApplied.push(`failed to remove stranded lock directory ${lockDir}`);
69
+ }
70
+ }
71
+ }
72
+ }
73
+ }
74
+ }
75
+ catch {
76
+ // Non-fatal — stranded lock directory check failed
77
+ }
78
+ // ── Stale parallel sessions ────────────────────────────────────────────
79
+ try {
80
+ const parallelStatuses = readAllSessionStatuses(basePath);
81
+ for (const status of parallelStatuses) {
82
+ if (isSessionStale(status)) {
83
+ issues.push({
84
+ severity: "warning",
85
+ code: "stale_parallel_session",
86
+ scope: "project",
87
+ unitId: status.milestoneId,
88
+ message: `Stale parallel session for ${status.milestoneId} (PID ${status.pid}, started ${new Date(status.startedAt).toISOString()}, last heartbeat ${new Date(status.lastHeartbeat).toISOString()}) — process is no longer running`,
89
+ file: `.gsd/parallel/${status.milestoneId}.status.json`,
90
+ fixable: true,
91
+ });
92
+ if (shouldFix("stale_parallel_session")) {
93
+ removeSessionStatus(basePath, status.milestoneId);
94
+ fixesApplied.push(`cleaned up stale parallel session for ${status.milestoneId}`);
95
+ }
96
+ }
97
+ }
98
+ }
99
+ catch {
100
+ // Non-fatal — parallel session check failed
101
+ }
102
+ // ── Orphaned completed-units keys ─────────────────────────────────────
103
+ try {
104
+ const completedKeysFile = join(root, "completed-units.json");
105
+ if (existsSync(completedKeysFile)) {
106
+ const raw = readFileSync(completedKeysFile, "utf-8");
107
+ const keys = JSON.parse(raw);
108
+ const orphaned = [];
109
+ for (const key of keys) {
110
+ // Key format: "unitType/unitId" e.g. "execute-task/M001/S01/T01"
111
+ const slashIdx = key.indexOf("/");
112
+ if (slashIdx === -1)
113
+ continue;
114
+ const unitType = key.slice(0, slashIdx);
115
+ const unitId = key.slice(slashIdx + 1);
116
+ // Only validate artifact-producing unit types
117
+ const { verifyExpectedArtifact } = await import("./auto-recovery.js");
118
+ if (!verifyExpectedArtifact(unitType, unitId, basePath)) {
119
+ orphaned.push(key);
120
+ }
121
+ }
122
+ if (orphaned.length > 0) {
123
+ issues.push({
124
+ severity: "warning",
125
+ code: "orphaned_completed_units",
126
+ scope: "project",
127
+ unitId: "project",
128
+ message: `${orphaned.length} completed-unit key(s) reference missing artifacts: ${orphaned.slice(0, 3).join(", ")}${orphaned.length > 3 ? "..." : ""}`,
129
+ file: ".gsd/completed-units.json",
130
+ fixable: true,
131
+ });
132
+ if (shouldFix("orphaned_completed_units")) {
133
+ const orphanedSet = new Set(orphaned);
134
+ const remaining = keys.filter((key) => !orphanedSet.has(key));
135
+ await saveFile(completedKeysFile, JSON.stringify(remaining));
136
+ fixesApplied.push(`removed ${orphaned.length} orphaned completed-unit key(s)`);
137
+ }
138
+ }
139
+ }
140
+ }
141
+ catch {
142
+ // Non-fatal — completed-units check failed
143
+ }
144
+ // ── Stale hook state ──────────────────────────────────────────────────
145
+ try {
146
+ const hookStateFile = join(root, "hook-state.json");
147
+ if (existsSync(hookStateFile)) {
148
+ const raw = readFileSync(hookStateFile, "utf-8");
149
+ const state = JSON.parse(raw);
150
+ const hasCycleCounts = state.cycleCounts && typeof state.cycleCounts === "object"
151
+ && Object.keys(state.cycleCounts).length > 0;
152
+ // Only flag if there are actual cycle counts AND no auto-mode is running
153
+ if (hasCycleCounts) {
154
+ const lock = readCrashLock(basePath);
155
+ const autoRunning = lock ? isLockProcessAlive(lock) : false;
156
+ if (!autoRunning) {
157
+ issues.push({
158
+ severity: "info",
159
+ code: "stale_hook_state",
160
+ scope: "project",
161
+ unitId: "project",
162
+ message: `hook-state.json has ${Object.keys(state.cycleCounts).length} residual cycle count(s) from a previous session`,
163
+ file: ".gsd/hook-state.json",
164
+ fixable: true,
165
+ });
166
+ if (shouldFix("stale_hook_state")) {
167
+ const { clearPersistedHookState } = await import("./post-unit-hooks.js");
168
+ clearPersistedHookState(basePath);
169
+ fixesApplied.push("cleared stale hook-state.json");
170
+ }
171
+ }
172
+ }
173
+ }
174
+ }
175
+ catch {
176
+ // Non-fatal — hook state check failed
177
+ }
178
+ // ── Activity log bloat ────────────────────────────────────────────────
179
+ try {
180
+ const activityDir = join(root, "activity");
181
+ if (existsSync(activityDir)) {
182
+ const files = readdirSync(activityDir);
183
+ let totalSize = 0;
184
+ for (const f of files) {
185
+ try {
186
+ totalSize += statSync(join(activityDir, f)).size;
187
+ }
188
+ catch {
189
+ // stat failed — skip
190
+ }
191
+ }
192
+ const totalMB = totalSize / (1024 * 1024);
193
+ const BLOAT_FILE_THRESHOLD = 500;
194
+ const BLOAT_SIZE_MB = 100;
195
+ if (files.length > BLOAT_FILE_THRESHOLD || totalMB > BLOAT_SIZE_MB) {
196
+ issues.push({
197
+ severity: "warning",
198
+ code: "activity_log_bloat",
199
+ scope: "project",
200
+ unitId: "project",
201
+ message: `Activity logs: ${files.length} files, ${totalMB.toFixed(1)}MB (thresholds: ${BLOAT_FILE_THRESHOLD} files / ${BLOAT_SIZE_MB}MB)`,
202
+ file: ".gsd/activity/",
203
+ fixable: true,
204
+ });
205
+ if (shouldFix("activity_log_bloat")) {
206
+ const { pruneActivityLogs } = await import("./activity-log.js");
207
+ pruneActivityLogs(activityDir, 7); // 7-day retention
208
+ fixesApplied.push("pruned activity logs (7-day retention)");
209
+ }
210
+ }
211
+ }
212
+ }
213
+ catch {
214
+ // Non-fatal — activity log check failed
215
+ }
216
+ // ── STATE.md health ───────────────────────────────────────────────────
217
+ try {
218
+ const stateFilePath = resolveGsdRootFile(basePath, "STATE");
219
+ const milestonesPath = milestonesDir(basePath);
220
+ if (existsSync(milestonesPath)) {
221
+ if (!existsSync(stateFilePath)) {
222
+ issues.push({
223
+ severity: "warning",
224
+ code: "state_file_missing",
225
+ scope: "project",
226
+ unitId: "project",
227
+ message: "STATE.md is missing — state display will not work",
228
+ file: ".gsd/STATE.md",
229
+ fixable: true,
230
+ });
231
+ if (shouldFix("state_file_missing")) {
232
+ const state = await deriveState(basePath);
233
+ await saveFile(stateFilePath, buildStateMarkdownForCheck(state));
234
+ fixesApplied.push("created STATE.md from derived state");
235
+ }
236
+ }
237
+ else {
238
+ // Check if STATE.md is stale by comparing active milestone/slice/phase
239
+ const currentContent = readFileSync(stateFilePath, "utf-8");
240
+ const state = await deriveState(basePath);
241
+ const freshContent = buildStateMarkdownForCheck(state);
242
+ // Extract key fields for comparison — don't compare full content
243
+ // since timestamp/formatting differences are normal
244
+ const extractFields = (content) => {
245
+ const milestone = content.match(/\*\*Active Milestone:\*\*\s*(.+)/)?.[1]?.trim() ?? "";
246
+ const slice = content.match(/\*\*Active Slice:\*\*\s*(.+)/)?.[1]?.trim() ?? "";
247
+ const phase = content.match(/\*\*Phase:\*\*\s*(.+)/)?.[1]?.trim() ?? "";
248
+ return { milestone, slice, phase };
249
+ };
250
+ const current = extractFields(currentContent);
251
+ const fresh = extractFields(freshContent);
252
+ if (current.milestone !== fresh.milestone || current.slice !== fresh.slice || current.phase !== fresh.phase) {
253
+ issues.push({
254
+ severity: "warning",
255
+ code: "state_file_stale",
256
+ scope: "project",
257
+ unitId: "project",
258
+ message: `STATE.md is stale — shows "${current.phase}" but derived state is "${fresh.phase}"`,
259
+ file: ".gsd/STATE.md",
260
+ fixable: true,
261
+ });
262
+ if (shouldFix("state_file_stale")) {
263
+ await saveFile(stateFilePath, freshContent);
264
+ fixesApplied.push("rebuilt STATE.md from derived state");
265
+ }
266
+ }
267
+ }
268
+ }
269
+ }
270
+ catch {
271
+ // Non-fatal — STATE.md check failed
272
+ }
273
+ // ── Gitignore drift ───────────────────────────────────────────────────
274
+ try {
275
+ const gitignorePath = join(basePath, ".gitignore");
276
+ if (existsSync(gitignorePath) && nativeIsRepo(basePath)) {
277
+ const content = readFileSync(gitignorePath, "utf-8");
278
+ const existingLines = new Set(content.split("\n").map(l => l.trim()).filter(l => l && !l.startsWith("#")));
279
+ // Check for critical runtime patterns that must be present
280
+ const criticalPatterns = [
281
+ ".gsd/activity/",
282
+ ".gsd/runtime/",
283
+ ".gsd/auto.lock",
284
+ ".gsd/gsd.db",
285
+ ".gsd/completed-units.json",
286
+ ];
287
+ // If blanket .gsd/ or .gsd is present, all patterns are covered
288
+ const hasBlanketIgnore = existingLines.has(".gsd/") || existingLines.has(".gsd");
289
+ if (!hasBlanketIgnore) {
290
+ const missing = criticalPatterns.filter(p => !existingLines.has(p));
291
+ if (missing.length > 0) {
292
+ issues.push({
293
+ severity: "warning",
294
+ code: "gitignore_missing_patterns",
295
+ scope: "project",
296
+ unitId: "project",
297
+ message: `${missing.length} critical GSD runtime pattern(s) missing from .gitignore: ${missing.join(", ")}`,
298
+ file: ".gitignore",
299
+ fixable: true,
300
+ });
301
+ if (shouldFix("gitignore_missing_patterns")) {
302
+ ensureGitignore(basePath);
303
+ fixesApplied.push("added missing GSD runtime patterns to .gitignore");
304
+ }
305
+ }
306
+ }
307
+ }
308
+ }
309
+ catch {
310
+ // Non-fatal — gitignore check failed
311
+ }
312
+ // ── External state symlink health ──────────────────────────────────────
313
+ try {
314
+ const localGsd = join(basePath, ".gsd");
315
+ if (existsSync(localGsd)) {
316
+ const stat = lstatSync(localGsd);
317
+ // Check for .gsd.migrating (failed migration)
318
+ const migratingPath = join(basePath, ".gsd.migrating");
319
+ if (existsSync(migratingPath)) {
320
+ issues.push({
321
+ severity: "error",
322
+ code: "failed_migration",
323
+ scope: "project",
324
+ unitId: "project",
325
+ message: "Found .gsd.migrating — a previous external state migration failed. State may be incomplete.",
326
+ file: ".gsd.migrating",
327
+ fixable: true,
328
+ });
329
+ if (shouldFix("failed_migration")) {
330
+ if (recoverFailedMigration(basePath)) {
331
+ fixesApplied.push("recovered failed migration (.gsd.migrating → .gsd)");
332
+ }
333
+ }
334
+ }
335
+ // Check symlink target exists
336
+ if (stat.isSymbolicLink()) {
337
+ try {
338
+ realpathSync(localGsd);
339
+ }
340
+ catch {
341
+ issues.push({
342
+ severity: "error",
343
+ code: "broken_symlink",
344
+ scope: "project",
345
+ unitId: "project",
346
+ message: ".gsd symlink target does not exist. External state directory may have been deleted.",
347
+ file: ".gsd",
348
+ fixable: false,
349
+ });
350
+ }
351
+ }
352
+ }
353
+ }
354
+ catch {
355
+ // Non-fatal — external state check failed
356
+ }
357
+ // ── Numbered .gsd collision variants (#2205) ───────────────────────────
358
+ // macOS APFS can create ".gsd 2", ".gsd 3" etc. when a directory blocks
359
+ // symlink creation. These must be removed so the canonical .gsd is used.
360
+ try {
361
+ const variantPattern = /^\.gsd \d+$/;
362
+ const entries = readdirSync(basePath);
363
+ const variants = entries.filter(e => variantPattern.test(e));
364
+ if (variants.length > 0) {
365
+ for (const v of variants) {
366
+ issues.push({
367
+ severity: "warning",
368
+ code: "numbered_gsd_variant",
369
+ scope: "project",
370
+ unitId: "project",
371
+ message: `Found macOS collision variant "${v}" — this can cause GSD state to appear deleted.`,
372
+ file: v,
373
+ fixable: true,
374
+ });
375
+ }
376
+ if (shouldFix("numbered_gsd_variant")) {
377
+ const removed = cleanNumberedGsdVariants(basePath);
378
+ for (const name of removed) {
379
+ fixesApplied.push(`removed numbered .gsd variant: ${name}`);
380
+ }
381
+ }
382
+ }
383
+ }
384
+ catch {
385
+ // Non-fatal — variant check failed
386
+ }
387
+ // ── Metrics ledger integrity ───────────────────────────────────────────
388
+ try {
389
+ const metricsPath = join(root, "metrics.json");
390
+ if (existsSync(metricsPath)) {
391
+ try {
392
+ const raw = readFileSync(metricsPath, "utf-8");
393
+ const ledger = JSON.parse(raw);
394
+ if (ledger.version !== 1 || !Array.isArray(ledger.units)) {
395
+ issues.push({
396
+ severity: "warning",
397
+ code: "metrics_ledger_corrupt",
398
+ scope: "project",
399
+ unitId: "project",
400
+ message: "metrics.json has an unexpected structure (version !== 1 or units is not an array) — metrics data may be unreliable",
401
+ file: ".gsd/metrics.json",
402
+ fixable: false,
403
+ });
404
+ }
405
+ }
406
+ catch {
407
+ issues.push({
408
+ severity: "warning",
409
+ code: "metrics_ledger_corrupt",
410
+ scope: "project",
411
+ unitId: "project",
412
+ message: "metrics.json is not valid JSON — metrics data may be corrupt",
413
+ file: ".gsd/metrics.json",
414
+ fixable: false,
415
+ });
416
+ }
417
+ }
418
+ }
419
+ catch {
420
+ // Non-fatal — metrics check failed
421
+ }
422
+ // ── Metrics ledger bloat ──────────────────────────────────────────────
423
+ // The metrics ledger has no TTL and grows by one entry per completed unit.
424
+ // At 50 units/day a project can accumulate tens of thousands of entries over
425
+ // months of use. Prune to the newest 1500 when the threshold is exceeded.
426
+ try {
427
+ const metricsFilePath = join(root, "metrics.json");
428
+ if (existsSync(metricsFilePath)) {
429
+ try {
430
+ const raw = readFileSync(metricsFilePath, "utf-8");
431
+ const parsed = JSON.parse(raw);
432
+ const BLOAT_UNITS_THRESHOLD = 2000;
433
+ if (parsed.version === 1 && Array.isArray(parsed.units) && parsed.units.length > BLOAT_UNITS_THRESHOLD) {
434
+ const fileSizeMB = (statSync(metricsFilePath).size / (1024 * 1024)).toFixed(1);
435
+ issues.push({
436
+ severity: "warning",
437
+ code: "metrics_ledger_bloat",
438
+ scope: "project",
439
+ unitId: "project",
440
+ message: `metrics.json has ${parsed.units.length} unit entries (${fileSizeMB}MB) — threshold is ${BLOAT_UNITS_THRESHOLD}. Run /gsd doctor --fix to prune to the newest 1500 entries.`,
441
+ file: ".gsd/metrics.json",
442
+ fixable: true,
443
+ });
444
+ if (shouldFix("metrics_ledger_bloat")) {
445
+ const { pruneMetricsLedger } = await import("./metrics.js");
446
+ const removed = pruneMetricsLedger(basePath, 1500);
447
+ fixesApplied.push(`pruned metrics ledger: removed ${removed} oldest entries (${parsed.units.length - removed} remain)`);
448
+ }
449
+ }
450
+ }
451
+ catch {
452
+ // JSON parse failed — already handled by the integrity check above
453
+ }
454
+ }
455
+ }
456
+ catch {
457
+ // Non-fatal — metrics bloat check failed
458
+ }
459
+ // ── Large planning file detection ──────────────────────────────────────
460
+ // Files over 100KB can cause LLM context pressure. Report the worst offenders.
461
+ try {
462
+ const MAX_FILE_BYTES = 100 * 1024; // 100KB
463
+ const milestonesPath = milestonesDir(basePath);
464
+ if (existsSync(milestonesPath)) {
465
+ const largeFiles = [];
466
+ function scanForLargeFiles(dir, depth = 0) {
467
+ if (depth > 6)
468
+ return;
469
+ try {
470
+ for (const entry of readdirSync(dir)) {
471
+ const full = join(dir, entry);
472
+ try {
473
+ const s = statSync(full);
474
+ if (s.isDirectory()) {
475
+ scanForLargeFiles(full, depth + 1);
476
+ continue;
477
+ }
478
+ if (entry.endsWith(".md") && s.size > MAX_FILE_BYTES) {
479
+ largeFiles.push({ path: full.replace(basePath + "/", ""), sizeKB: Math.round(s.size / 1024) });
480
+ }
481
+ }
482
+ catch { /* skip entry */ }
483
+ }
484
+ }
485
+ catch { /* skip dir */ }
486
+ }
487
+ scanForLargeFiles(milestonesPath);
488
+ if (largeFiles.length > 0) {
489
+ largeFiles.sort((a, b) => b.sizeKB - a.sizeKB);
490
+ const worst = largeFiles[0];
491
+ issues.push({
492
+ severity: "warning",
493
+ code: "large_planning_file",
494
+ scope: "project",
495
+ unitId: "project",
496
+ message: `${largeFiles.length} planning file(s) exceed 100KB — largest: ${worst.path} (${worst.sizeKB}KB). Large files cause LLM context pressure.`,
497
+ file: worst.path,
498
+ fixable: false,
499
+ });
500
+ }
501
+ }
502
+ }
503
+ catch {
504
+ // Non-fatal — large file scan failed
505
+ }
506
+ // ── Snapshot ref bloat ────────────────────────────────────────────────
507
+ // refs/gsd/snapshots/ accumulate over time. Prune to newest 5 per label
508
+ // when total count exceeds threshold.
509
+ try {
510
+ if (nativeIsRepo(basePath)) {
511
+ const refs = nativeForEachRef(basePath, "refs/gsd/snapshots/");
512
+ if (refs.length > 50) {
513
+ issues.push({
514
+ severity: "warning",
515
+ code: "snapshot_ref_bloat",
516
+ scope: "project",
517
+ unitId: "project",
518
+ message: `${refs.length} snapshot refs found under refs/gsd/snapshots/ — pruning to newest 5 per label will reclaim git storage`,
519
+ fixable: true,
520
+ });
521
+ if (shouldFix("snapshot_ref_bloat")) {
522
+ const byLabel = new Map();
523
+ for (const ref of refs) {
524
+ const parts = ref.split("/");
525
+ const label = parts.slice(0, -1).join("/");
526
+ if (!byLabel.has(label))
527
+ byLabel.set(label, []);
528
+ byLabel.get(label).push(ref);
529
+ }
530
+ let pruned = 0;
531
+ for (const [, labelRefs] of byLabel) {
532
+ const sorted = labelRefs.sort();
533
+ for (const old of sorted.slice(0, -5)) {
534
+ try {
535
+ nativeUpdateRef(basePath, old);
536
+ pruned++;
537
+ }
538
+ catch { /* skip */ }
539
+ }
540
+ }
541
+ if (pruned > 0) {
542
+ fixesApplied.push(`pruned ${pruned} old snapshot ref(s)`);
543
+ }
544
+ }
545
+ }
546
+ }
547
+ }
548
+ catch {
549
+ // Non-fatal — snapshot ref check failed
550
+ }
551
+ }
552
+ /**
553
+ * Build STATE.md markdown content from derived state.
554
+ * Local helper used by checkRuntimeHealth for STATE.md drift detection and repair.
555
+ */
556
+ function buildStateMarkdownForCheck(state) {
557
+ const lines = [];
558
+ lines.push("# GSD State", "");
559
+ const activeMilestone = state.activeMilestone
560
+ ? `${state.activeMilestone.id}: ${state.activeMilestone.title}`
561
+ : "None";
562
+ const activeSlice = state.activeSlice
563
+ ? `${state.activeSlice.id}: ${state.activeSlice.title}`
564
+ : "None";
565
+ lines.push(`**Active Milestone:** ${activeMilestone}`);
566
+ lines.push(`**Active Slice:** ${activeSlice}`);
567
+ lines.push(`**Phase:** ${state.phase}`);
568
+ if (state.requirements) {
569
+ lines.push(`**Requirements Status:** ${state.requirements.active} active · ${state.requirements.validated} validated · ${state.requirements.deferred} deferred · ${state.requirements.outOfScope} out of scope`);
570
+ }
571
+ lines.push("");
572
+ lines.push("## Milestone Registry");
573
+ for (const entry of state.registry) {
574
+ const glyph = entry.status === "complete" ? "\u2705" : entry.status === "active" ? "\uD83D\uDD04" : entry.status === "parked" ? "\u23F8\uFE0F" : "\u2B1C";
575
+ lines.push(`- ${glyph} **${entry.id}:** ${entry.title}`);
576
+ }
577
+ lines.push("");
578
+ lines.push("## Recent Decisions");
579
+ if (state.recentDecisions.length > 0) {
580
+ for (const decision of state.recentDecisions)
581
+ lines.push(`- ${decision}`);
582
+ }
583
+ else {
584
+ lines.push("- None recorded");
585
+ }
586
+ lines.push("");
587
+ lines.push("## Blockers");
588
+ if (state.blockers.length > 0) {
589
+ for (const blocker of state.blockers)
590
+ lines.push(`- ${blocker}`);
591
+ }
592
+ else {
593
+ lines.push("- None");
594
+ }
595
+ lines.push("");
596
+ lines.push("## Next Action");
597
+ lines.push(state.nextAction || "None");
598
+ lines.push("");
599
+ return lines.join("\n");
600
+ }