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,182 @@
1
+ import { existsSync, statSync } from "node:fs";
2
+ import { join } from "node:path";
3
+
4
+ import type { DoctorIssue } from "./doctor-types.js";
5
+ import { isDbAvailable, _getAdapter } from "./gsd-db.js";
6
+ import { resolveMilestoneFile } from "./paths.js";
7
+ import { deriveState } from "./state.js";
8
+ import { readEvents } from "./workflow-events.js";
9
+ import { renderAllProjections } from "./workflow-projections.js";
10
+
11
+ export async function checkEngineHealth(
12
+ basePath: string,
13
+ issues: DoctorIssue[],
14
+ fixesApplied: string[],
15
+ ): Promise<void> {
16
+ // ── DB constraint violation detection (full doctor only, not pre-dispatch per D-10) ──
17
+ try {
18
+ if (isDbAvailable()) {
19
+ const adapter = _getAdapter()!;
20
+
21
+ // a. Orphaned tasks (task.slice_id points to non-existent slice)
22
+ try {
23
+ const orphanedTasks = adapter
24
+ .prepare(
25
+ `SELECT t.id, t.slice_id, t.milestone_id
26
+ FROM tasks t
27
+ LEFT JOIN slices s ON t.milestone_id = s.milestone_id AND t.slice_id = s.id
28
+ WHERE s.id IS NULL`,
29
+ )
30
+ .all() as Array<{ id: string; slice_id: string; milestone_id: string }>;
31
+
32
+ for (const row of orphanedTasks) {
33
+ issues.push({
34
+ severity: "error",
35
+ code: "db_orphaned_task",
36
+ scope: "task",
37
+ unitId: `${row.milestone_id}/${row.slice_id}/${row.id}`,
38
+ message: `Task ${row.id} references slice ${row.slice_id} in milestone ${row.milestone_id} but no such slice exists in the database`,
39
+ fixable: false,
40
+ });
41
+ }
42
+ } catch {
43
+ // Non-fatal — orphaned task check failed
44
+ }
45
+
46
+ // b. Orphaned slices (slice.milestone_id points to non-existent milestone)
47
+ try {
48
+ const orphanedSlices = adapter
49
+ .prepare(
50
+ `SELECT s.id, s.milestone_id
51
+ FROM slices s
52
+ LEFT JOIN milestones m ON s.milestone_id = m.id
53
+ WHERE m.id IS NULL`,
54
+ )
55
+ .all() as Array<{ id: string; milestone_id: string }>;
56
+
57
+ for (const row of orphanedSlices) {
58
+ issues.push({
59
+ severity: "error",
60
+ code: "db_orphaned_slice",
61
+ scope: "slice",
62
+ unitId: `${row.milestone_id}/${row.id}`,
63
+ message: `Slice ${row.id} references milestone ${row.milestone_id} but no such milestone exists in the database`,
64
+ fixable: false,
65
+ });
66
+ }
67
+ } catch {
68
+ // Non-fatal — orphaned slice check failed
69
+ }
70
+
71
+ // c. Tasks marked complete without summaries
72
+ try {
73
+ const doneTasks = adapter
74
+ .prepare(
75
+ `SELECT id, slice_id, milestone_id FROM tasks
76
+ WHERE status = 'done' AND (summary IS NULL OR summary = '')`,
77
+ )
78
+ .all() as Array<{ id: string; slice_id: string; milestone_id: string }>;
79
+
80
+ for (const row of doneTasks) {
81
+ issues.push({
82
+ severity: "warning",
83
+ code: "db_done_task_no_summary",
84
+ scope: "task",
85
+ unitId: `${row.milestone_id}/${row.slice_id}/${row.id}`,
86
+ message: `Task ${row.id} is marked done but has no summary in the database`,
87
+ fixable: false,
88
+ });
89
+ }
90
+ } catch {
91
+ // Non-fatal — done-task-no-summary check failed
92
+ }
93
+
94
+ // d. Duplicate entity IDs (safety check)
95
+ try {
96
+ const dupMilestones = adapter
97
+ .prepare("SELECT id, COUNT(*) as cnt FROM milestones GROUP BY id HAVING cnt > 1")
98
+ .all() as Array<{ id: string; cnt: number }>;
99
+ for (const row of dupMilestones) {
100
+ issues.push({
101
+ severity: "error",
102
+ code: "db_duplicate_id",
103
+ scope: "milestone",
104
+ unitId: row.id,
105
+ message: `Duplicate milestone ID "${row.id}" appears ${row.cnt} times in the database`,
106
+ fixable: false,
107
+ });
108
+ }
109
+
110
+ const dupSlices = adapter
111
+ .prepare("SELECT id, milestone_id, COUNT(*) as cnt FROM slices GROUP BY id, milestone_id HAVING cnt > 1")
112
+ .all() as Array<{ id: string; milestone_id: string; cnt: number }>;
113
+ for (const row of dupSlices) {
114
+ issues.push({
115
+ severity: "error",
116
+ code: "db_duplicate_id",
117
+ scope: "slice",
118
+ unitId: `${row.milestone_id}/${row.id}`,
119
+ message: `Duplicate slice ID "${row.id}" in milestone ${row.milestone_id} appears ${row.cnt} times`,
120
+ fixable: false,
121
+ });
122
+ }
123
+
124
+ const dupTasks = adapter
125
+ .prepare("SELECT id, slice_id, milestone_id, COUNT(*) as cnt FROM tasks GROUP BY id, slice_id, milestone_id HAVING cnt > 1")
126
+ .all() as Array<{ id: string; slice_id: string; milestone_id: string; cnt: number }>;
127
+ for (const row of dupTasks) {
128
+ issues.push({
129
+ severity: "error",
130
+ code: "db_duplicate_id",
131
+ scope: "task",
132
+ unitId: `${row.milestone_id}/${row.slice_id}/${row.id}`,
133
+ message: `Duplicate task ID "${row.id}" in slice ${row.slice_id} appears ${row.cnt} times`,
134
+ fixable: false,
135
+ });
136
+ }
137
+ } catch {
138
+ // Non-fatal — duplicate ID check failed
139
+ }
140
+ }
141
+ } catch {
142
+ // Non-fatal — DB constraint checks failed entirely
143
+ }
144
+
145
+ // ── Projection drift detection ──────────────────────────────────────────
146
+ // If the DB is available, check whether markdown projections are stale
147
+ // relative to the event log and re-render them.
148
+ try {
149
+ if (isDbAvailable()) {
150
+ const eventLogPath = join(basePath, ".gsd", "event-log.jsonl");
151
+ const events = readEvents(eventLogPath);
152
+ if (events.length > 0) {
153
+ const lastEventTs = new Date(events[events.length - 1]!.ts).getTime();
154
+ const state = await deriveState(basePath);
155
+ for (const milestone of state.registry) {
156
+ if (milestone.status === "complete") continue;
157
+ const roadmapPath = resolveMilestoneFile(basePath, milestone.id, "ROADMAP");
158
+ if (!roadmapPath || !existsSync(roadmapPath)) {
159
+ try {
160
+ await renderAllProjections(basePath, milestone.id);
161
+ fixesApplied.push(`re-rendered missing projections for ${milestone.id}`);
162
+ } catch {
163
+ // Non-fatal — projection re-render failed
164
+ }
165
+ continue;
166
+ }
167
+ const projectionMtime = statSync(roadmapPath).mtimeMs;
168
+ if (lastEventTs > projectionMtime) {
169
+ try {
170
+ await renderAllProjections(basePath, milestone.id);
171
+ fixesApplied.push(`re-rendered stale projections for ${milestone.id}`);
172
+ } catch {
173
+ // Non-fatal — projection re-render failed
174
+ }
175
+ }
176
+ }
177
+ }
178
+ }
179
+ } catch {
180
+ // Non-fatal — projection drift check must never block doctor
181
+ }
182
+ }
@@ -149,21 +149,44 @@ function checkDependenciesInstalled(basePath: string): EnvironmentCheckResult |
149
149
  };
150
150
  }
151
151
 
152
- // Check if lockfile is newer than node_modules
153
- const lockfiles = ["package-lock.json", "yarn.lock", "pnpm-lock.yaml"];
154
- for (const lockfile of lockfiles) {
155
- const lockPath = join(basePath, lockfile);
152
+ // Check if lockfile is newer than the last install.
153
+ //
154
+ // Each package manager writes a metadata marker inside node_modules on
155
+ // every install. Comparing the lockfile mtime against the marker is
156
+ // reliable; comparing against the node_modules *directory* mtime is not,
157
+ // because directory mtime only changes when entries are added or removed
158
+ // — not when files inside it are updated. (#1974)
159
+ const lockfiles: Array<{ lock: string; markers: string[] }> = [
160
+ { lock: "package-lock.json", markers: ["node_modules/.package-lock.json"] },
161
+ { lock: "yarn.lock", markers: ["node_modules/.yarn-integrity"] },
162
+ { lock: "pnpm-lock.yaml", markers: ["node_modules/.modules.yaml"] },
163
+ ];
164
+
165
+ for (const { lock, markers } of lockfiles) {
166
+ const lockPath = join(basePath, lock);
156
167
  if (!existsSync(lockPath)) continue;
157
168
 
158
169
  try {
159
170
  const lockMtime = statSync(lockPath).mtimeMs;
160
- const nmMtime = statSync(nodeModules).mtimeMs;
161
171
 
162
- if (lockMtime > nmMtime) {
172
+ // Prefer the package manager's marker file; fall back to directory mtime
173
+ // only when no marker exists (e.g., manually created node_modules).
174
+ let installMtime = 0;
175
+ for (const marker of markers) {
176
+ const markerPath = join(basePath, marker);
177
+ if (existsSync(markerPath)) {
178
+ installMtime = Math.max(installMtime, statSync(markerPath).mtimeMs);
179
+ }
180
+ }
181
+ if (installMtime === 0) {
182
+ installMtime = statSync(nodeModules).mtimeMs;
183
+ }
184
+
185
+ if (lockMtime > installMtime) {
163
186
  return {
164
187
  name: "dependencies",
165
188
  status: "warning",
166
- message: `${lockfile} is newer than node_modules — dependencies may be stale`,
189
+ message: `${lock} is newer than node_modules — dependencies may be stale`,
167
190
  detail: `Run npm install / yarn / pnpm install to update`,
168
191
  };
169
192
  }
@@ -0,0 +1,415 @@
1
+ import { existsSync, readdirSync, realpathSync, rmSync, statSync } from "node:fs";
2
+ import { join, sep } from "node:path";
3
+
4
+ import type { DoctorIssue, DoctorIssueCode } from "./doctor-types.js";
5
+ import { loadFile } from "./files.js";
6
+ import { parseRoadmap as parseLegacyRoadmap } from "./parsers-legacy.js";
7
+ import { isDbAvailable, getMilestoneSlices } from "./gsd-db.js";
8
+ import { resolveMilestoneFile } from "./paths.js";
9
+ import { deriveState, isMilestoneComplete } from "./state.js";
10
+ import { listWorktrees, resolveGitDir, worktreesDir } from "./worktree-manager.js";
11
+ import { abortAndReset } from "./git-self-heal.js";
12
+ import { RUNTIME_EXCLUSION_PATHS, resolveMilestoneIntegrationBranch, writeIntegrationBranch } from "./git-service.js";
13
+ import { nativeIsRepo, nativeWorktreeList, nativeWorktreeRemove, nativeBranchList, nativeBranchDelete, nativeLsFiles, nativeRmCached } from "./native-git-bridge.js";
14
+ import { getAllWorktreeHealth } from "./worktree-health.js";
15
+ import { loadEffectiveGSDPreferences } from "./preferences.js";
16
+
17
+ export async function checkGitHealth(
18
+ basePath: string,
19
+ issues: DoctorIssue[],
20
+ fixesApplied: string[],
21
+ shouldFix: (code: DoctorIssueCode) => boolean,
22
+ isolationMode: "none" | "worktree" | "branch" = "none",
23
+ ): Promise<void> {
24
+ // Degrade gracefully if not a git repo
25
+ if (!nativeIsRepo(basePath)) {
26
+ return; // Not a git repo — skip all git health checks
27
+ }
28
+
29
+ const gitDir = resolveGitDir(basePath);
30
+
31
+ // ── Orphaned auto-worktrees & Stale milestone branches ────────────────
32
+ // These checks only apply in worktree/branch modes — skip in none mode
33
+ // where no milestone worktrees or branches are created.
34
+ if (isolationMode !== "none") {
35
+ try {
36
+ const worktrees = listWorktrees(basePath);
37
+ const milestoneWorktrees = worktrees.filter(wt => wt.branch.startsWith("milestone/"));
38
+
39
+ // Load roadmap state once for cross-referencing
40
+ const state = await deriveState(basePath);
41
+
42
+ for (const wt of milestoneWorktrees) {
43
+ // Extract milestone ID from branch name "milestone/M001" → "M001"
44
+ const milestoneId = wt.branch.replace(/^milestone\//, "");
45
+ const milestoneEntry = state.registry.find(m => m.id === milestoneId);
46
+
47
+ // Check if milestone is complete via roadmap
48
+ let isComplete = false;
49
+ if (milestoneEntry) {
50
+ if (isDbAvailable()) {
51
+ const dbSlices = getMilestoneSlices(milestoneId);
52
+ isComplete = dbSlices.length > 0 && dbSlices.every(s => s.status === "complete");
53
+ } else {
54
+ const roadmapPath = resolveMilestoneFile(basePath, milestoneId, "ROADMAP");
55
+ const roadmapContent = roadmapPath ? await loadFile(roadmapPath) : null;
56
+ if (roadmapContent) {
57
+ const roadmap = parseLegacyRoadmap(roadmapContent);
58
+ isComplete = isMilestoneComplete(roadmap);
59
+ }
60
+ }
61
+ // When DB unavailable and no roadmap, isComplete stays false
62
+ }
63
+
64
+ if (isComplete) {
65
+ issues.push({
66
+ severity: "warning",
67
+ code: "orphaned_auto_worktree",
68
+ scope: "milestone",
69
+ unitId: milestoneId,
70
+ message: `Worktree for completed milestone ${milestoneId} still exists at ${wt.path}`,
71
+ fixable: true,
72
+ });
73
+
74
+ if (shouldFix("orphaned_auto_worktree")) {
75
+ // If cwd is inside the worktree, chdir out first — matching the
76
+ // pattern in removeWorktree() (#1946). Without this, git cannot
77
+ // remove the worktree and the doctor enters a deadlock where it
78
+ // detects the orphan every run but never cleans it up.
79
+ const cwd = process.cwd();
80
+ if (wt.path === cwd || cwd.startsWith(wt.path + sep)) {
81
+ try {
82
+ process.chdir(basePath);
83
+ } catch {
84
+ fixesApplied.push(`skipped removing worktree at ${wt.path} (cannot chdir to basePath)`);
85
+ continue;
86
+ }
87
+ }
88
+ try {
89
+ nativeWorktreeRemove(basePath, wt.path, true);
90
+ fixesApplied.push(`removed orphaned worktree ${wt.path}`);
91
+ } catch {
92
+ fixesApplied.push(`failed to remove worktree ${wt.path}`);
93
+ }
94
+ }
95
+ }
96
+ }
97
+
98
+ // ── Stale milestone branches ─────────────────────────────────────────
99
+ try {
100
+ const branches = nativeBranchList(basePath, "milestone/*");
101
+ if (branches.length > 0) {
102
+ const worktreeBranches = new Set(milestoneWorktrees.map(wt => wt.branch));
103
+
104
+ for (const branch of branches) {
105
+ // Skip branches that have a worktree (handled above)
106
+ if (worktreeBranches.has(branch)) continue;
107
+
108
+ const milestoneId = branch.replace(/^milestone\//, "");
109
+ const roadmapPath = resolveMilestoneFile(basePath, milestoneId, "ROADMAP");
110
+ let branchMilestoneComplete = false;
111
+ if (isDbAvailable()) {
112
+ const dbSlices = getMilestoneSlices(milestoneId);
113
+ branchMilestoneComplete = dbSlices.length > 0 && dbSlices.every(s => s.status === "complete");
114
+ } else {
115
+ const roadmapContent = roadmapPath ? await loadFile(roadmapPath) : null;
116
+ if (!roadmapContent) continue;
117
+ const roadmap = parseLegacyRoadmap(roadmapContent);
118
+ branchMilestoneComplete = isMilestoneComplete(roadmap);
119
+ }
120
+ if (branchMilestoneComplete) {
121
+ issues.push({
122
+ severity: "info",
123
+ code: "stale_milestone_branch",
124
+ scope: "milestone",
125
+ unitId: milestoneId,
126
+ message: `Branch ${branch} exists for completed milestone ${milestoneId}`,
127
+ fixable: true,
128
+ });
129
+
130
+ if (shouldFix("stale_milestone_branch")) {
131
+ try {
132
+ nativeBranchDelete(basePath, branch, true);
133
+ fixesApplied.push(`deleted stale branch ${branch}`);
134
+ } catch {
135
+ fixesApplied.push(`failed to delete branch ${branch}`);
136
+ }
137
+ }
138
+ }
139
+ }
140
+ }
141
+ } catch {
142
+ // git branch list failed — skip stale branch check
143
+ }
144
+ } catch {
145
+ // listWorktrees or deriveState failed — skip worktree/branch checks
146
+ }
147
+ } // end isolationMode !== "none"
148
+
149
+ // ── Corrupt merge state ────────────────────────────────────────────────
150
+ try {
151
+ const mergeStateFiles = ["MERGE_HEAD", "SQUASH_MSG"];
152
+ const mergeStateDirs = ["rebase-apply", "rebase-merge"];
153
+ const found: string[] = [];
154
+
155
+ for (const f of mergeStateFiles) {
156
+ if (existsSync(join(gitDir, f))) found.push(f);
157
+ }
158
+ for (const d of mergeStateDirs) {
159
+ if (existsSync(join(gitDir, d))) found.push(d);
160
+ }
161
+
162
+ if (found.length > 0) {
163
+ issues.push({
164
+ severity: "error",
165
+ code: "corrupt_merge_state",
166
+ scope: "project",
167
+ unitId: "project",
168
+ message: `Corrupt merge/rebase state detected: ${found.join(", ")}`,
169
+ fixable: true,
170
+ });
171
+
172
+ if (shouldFix("corrupt_merge_state")) {
173
+ const result = abortAndReset(basePath);
174
+ fixesApplied.push(`cleaned merge state: ${result.cleaned.join(", ")}`);
175
+ }
176
+ }
177
+ } catch {
178
+ // Can't check .git dir — skip
179
+ }
180
+
181
+ // ── Tracked runtime files ──────────────────────────────────────────────
182
+ try {
183
+ const trackedPaths: string[] = [];
184
+ for (const exclusion of RUNTIME_EXCLUSION_PATHS) {
185
+ try {
186
+ const files = nativeLsFiles(basePath, exclusion);
187
+ if (files.length > 0) {
188
+ trackedPaths.push(...files);
189
+ }
190
+ } catch {
191
+ // Individual ls-files can fail — continue
192
+ }
193
+ }
194
+
195
+ if (trackedPaths.length > 0) {
196
+ issues.push({
197
+ severity: "warning",
198
+ code: "tracked_runtime_files",
199
+ scope: "project",
200
+ unitId: "project",
201
+ message: `${trackedPaths.length} runtime file(s) are tracked by git: ${trackedPaths.slice(0, 5).join(", ")}${trackedPaths.length > 5 ? "..." : ""}`,
202
+ fixable: true,
203
+ });
204
+
205
+ if (shouldFix("tracked_runtime_files")) {
206
+ try {
207
+ for (const exclusion of RUNTIME_EXCLUSION_PATHS) {
208
+ nativeRmCached(basePath, [exclusion]);
209
+ }
210
+ fixesApplied.push(`untracked ${trackedPaths.length} runtime file(s)`);
211
+ } catch {
212
+ fixesApplied.push("failed to untrack runtime files");
213
+ }
214
+ }
215
+ }
216
+ } catch {
217
+ // git ls-files failed — skip
218
+ }
219
+
220
+ // ── Legacy slice branches ──────────────────────────────────────────────
221
+ try {
222
+ const branchList = nativeBranchList(basePath, "gsd/*/*")
223
+ .filter((branch) => !branch.startsWith("gsd/quick/"));
224
+ if (branchList.length > 0) {
225
+ issues.push({
226
+ severity: "info",
227
+ code: "legacy_slice_branches",
228
+ scope: "project",
229
+ unitId: "project",
230
+ message: `${branchList.length} legacy slice branch(es) found: ${branchList.slice(0, 3).join(", ")}${branchList.length > 3 ? "..." : ""}. These are no longer used (branchless architecture).`,
231
+ fixable: true,
232
+ });
233
+
234
+ if (shouldFix("legacy_slice_branches")) {
235
+ let deleted = 0;
236
+ for (const branch of branchList) {
237
+ try {
238
+ nativeBranchDelete(basePath, branch, true);
239
+ deleted++;
240
+ } catch { /* skip branches that can't be deleted */ }
241
+ }
242
+ if (deleted > 0) {
243
+ fixesApplied.push(`deleted ${deleted} legacy slice branch(es)`);
244
+ }
245
+ }
246
+ }
247
+ } catch {
248
+ // git branch list failed — skip
249
+ }
250
+
251
+ // ── Integration branch existence ──────────────────────────────────────
252
+ // For each active (non-complete) milestone, verify the stored integration
253
+ // branch still exists in git. A missing integration branch blocks merge-back
254
+ // and causes the next merge operation to fail silently.
255
+ try {
256
+ const state = await deriveState(basePath);
257
+ const gitPrefs = loadEffectiveGSDPreferences()?.preferences?.git ?? {};
258
+ for (const milestone of state.registry) {
259
+ if (milestone.status === "complete") continue;
260
+ const resolution = resolveMilestoneIntegrationBranch(basePath, milestone.id, gitPrefs);
261
+ if (!resolution.recordedBranch) continue; // No stored branch — skip (not yet set)
262
+ if (resolution.status === "fallback" && resolution.effectiveBranch) {
263
+ issues.push({
264
+ severity: "warning",
265
+ code: "integration_branch_missing",
266
+ scope: "milestone",
267
+ unitId: milestone.id,
268
+ message: resolution.reason,
269
+ fixable: true,
270
+ });
271
+ if (shouldFix("integration_branch_missing")) {
272
+ writeIntegrationBranch(basePath, milestone.id, resolution.effectiveBranch);
273
+ fixesApplied.push(`updated integration branch for ${milestone.id} to "${resolution.effectiveBranch}"`);
274
+ }
275
+ continue;
276
+ }
277
+
278
+ if (resolution.status === "missing") {
279
+ issues.push({
280
+ severity: "error",
281
+ code: "integration_branch_missing",
282
+ scope: "milestone",
283
+ unitId: milestone.id,
284
+ message: resolution.reason,
285
+ fixable: false,
286
+ });
287
+ }
288
+ }
289
+ } catch {
290
+ // Non-fatal — integration branch check failed
291
+ }
292
+
293
+ // ── Orphaned worktree directories ────────────────────────────────────
294
+ // Worktree removal can fail after a branch delete, leaving a directory
295
+ // that is no longer registered with git. These orphaned dirs cause
296
+ // "already exists" errors when re-creating the same worktree name.
297
+ try {
298
+ const wtDir = worktreesDir(basePath);
299
+ if (existsSync(wtDir)) {
300
+ // Resolve symlinks and normalize separators so that symlinked .gsd
301
+ // paths (e.g. ~/.gsd/projects/<hash>/worktrees/…) match the paths
302
+ // returned by `git worktree list`.
303
+ const normalizePath = (p: string): string => {
304
+ try { p = realpathSync(p); } catch { /* path may not exist */ }
305
+ return p.replaceAll("\\", "/");
306
+ };
307
+ const registeredPaths = new Set(
308
+ nativeWorktreeList(basePath).map(entry => normalizePath(entry.path)),
309
+ );
310
+ for (const entry of readdirSync(wtDir)) {
311
+ const fullPath = join(wtDir, entry);
312
+ try {
313
+ if (!statSync(fullPath).isDirectory()) continue;
314
+ } catch { continue; }
315
+ const normalizedFullPath = normalizePath(fullPath);
316
+ if (!registeredPaths.has(normalizedFullPath)) {
317
+ issues.push({
318
+ severity: "warning",
319
+ code: "worktree_directory_orphaned",
320
+ scope: "project",
321
+ unitId: entry,
322
+ message: `Worktree directory ${fullPath} exists on disk but is not registered with git. Run "git worktree prune" or doctor --fix to remove it.`,
323
+ fixable: true,
324
+ });
325
+ if (shouldFix("worktree_directory_orphaned")) {
326
+ try {
327
+ rmSync(fullPath, { recursive: true, force: true });
328
+ fixesApplied.push(`removed orphaned worktree directory ${fullPath}`);
329
+ } catch {
330
+ fixesApplied.push(`failed to remove orphaned worktree directory ${fullPath}`);
331
+ }
332
+ }
333
+ }
334
+ }
335
+ }
336
+ } catch {
337
+ // Non-fatal — orphaned worktree directory check failed
338
+ }
339
+
340
+ // ── Worktree lifecycle checks ──────────────────────────────────────────
341
+ // Check GSD-managed worktrees for: merged branches, stale work, dirty
342
+ // state, and unpushed commits. Only worktrees under .gsd/worktrees/.
343
+ try {
344
+ const healthStatuses = getAllWorktreeHealth(basePath);
345
+ const cwd = process.cwd();
346
+
347
+ for (const health of healthStatuses) {
348
+ const wt = health.worktree;
349
+ const isCwd = wt.path === cwd || cwd.startsWith(wt.path + sep);
350
+
351
+ // Branch fully merged into main — safe to remove
352
+ if (health.mergedIntoMain) {
353
+ issues.push({
354
+ severity: "info",
355
+ code: "worktree_branch_merged",
356
+ scope: "project",
357
+ unitId: wt.name,
358
+ message: `Worktree "${wt.name}" (branch ${wt.branch}) is fully merged into main${health.safeToRemove ? " — safe to remove" : ""}`,
359
+ fixable: health.safeToRemove,
360
+ });
361
+
362
+ if (health.safeToRemove && shouldFix("worktree_branch_merged") && !isCwd) {
363
+ try {
364
+ const { removeWorktree } = await import("./worktree-manager.js");
365
+ removeWorktree(basePath, wt.name, { deleteBranch: true, branch: wt.branch });
366
+ fixesApplied.push(`removed merged worktree "${wt.name}" and deleted branch ${wt.branch}`);
367
+ } catch {
368
+ fixesApplied.push(`failed to remove merged worktree "${wt.name}"`);
369
+ }
370
+ }
371
+ // If merged, skip the stale/dirty/unpushed checks — they're irrelevant
372
+ continue;
373
+ }
374
+
375
+ // Stale: no commits in N days, not merged
376
+ if (health.stale) {
377
+ const days = Math.floor(health.lastCommitAgeDays);
378
+ issues.push({
379
+ severity: "warning",
380
+ code: "worktree_stale",
381
+ scope: "project",
382
+ unitId: wt.name,
383
+ message: `Worktree "${wt.name}" has had no commits in ${days} day${days === 1 ? "" : "s"}`,
384
+ fixable: false,
385
+ });
386
+ }
387
+
388
+ // Dirty: uncommitted changes in a worktree (only flag on stale worktrees to avoid noise)
389
+ if (health.dirty && health.stale) {
390
+ issues.push({
391
+ severity: "warning",
392
+ code: "worktree_dirty",
393
+ scope: "project",
394
+ unitId: wt.name,
395
+ message: `Worktree "${wt.name}" has ${health.dirtyFileCount} uncommitted file${health.dirtyFileCount === 1 ? "" : "s"} and is stale`,
396
+ fixable: false,
397
+ });
398
+ }
399
+
400
+ // Unpushed: commits not on any remote (only flag on stale worktrees to avoid noise)
401
+ if (health.unpushedCommits > 0 && health.stale) {
402
+ issues.push({
403
+ severity: "warning",
404
+ code: "worktree_unpushed",
405
+ scope: "project",
406
+ unitId: wt.name,
407
+ message: `Worktree "${wt.name}" has ${health.unpushedCommits} unpushed commit${health.unpushedCommits === 1 ? "" : "s"}`,
408
+ fixable: false,
409
+ });
410
+ }
411
+ }
412
+ } catch {
413
+ // Non-fatal — worktree lifecycle check failed
414
+ }
415
+ }