gsd-pi 2.81.0 → 2.82.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -24
- package/dist/resources/.managed-resources-content-hash +1 -1
- package/dist/resources/extensions/gsd/auto/loop.js +111 -8
- package/dist/resources/extensions/gsd/auto/phases.js +190 -97
- package/dist/resources/extensions/gsd/auto/run-unit.js +66 -3
- package/dist/resources/extensions/gsd/auto/session.js +9 -0
- package/dist/resources/extensions/gsd/auto/verification-retry-policy.js +43 -0
- package/dist/resources/extensions/gsd/auto-dashboard.js +182 -178
- package/dist/resources/extensions/gsd/auto-dispatch.js +14 -11
- package/dist/resources/extensions/gsd/auto-post-unit.js +7 -1
- package/dist/resources/extensions/gsd/auto-recovery.js +6 -181
- package/dist/resources/extensions/gsd/auto-runtime-state.js +5 -0
- package/dist/resources/extensions/gsd/auto-start.js +20 -23
- package/dist/resources/extensions/gsd/auto-unit-closeout.js +33 -5
- package/dist/resources/extensions/gsd/auto-verification.js +12 -6
- package/dist/resources/extensions/gsd/auto-worktree.js +8 -0
- package/dist/resources/extensions/gsd/auto.js +265 -76
- package/dist/resources/extensions/gsd/bootstrap/agent-end-recovery.js +13 -6
- package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +8 -2
- package/dist/resources/extensions/gsd/bootstrap/register-shortcuts.js +4 -8
- package/dist/resources/extensions/gsd/commands/handlers/notifications-handler.js +4 -10
- package/dist/resources/extensions/gsd/commands/handlers/parallel.js +9 -0
- package/dist/resources/extensions/gsd/git-service.js +2 -1
- package/dist/resources/extensions/gsd/gsd-db.js +7 -23
- package/dist/resources/extensions/gsd/health-widget-core.js +1 -1
- package/dist/resources/extensions/gsd/health-widget.js +4 -10
- package/dist/resources/extensions/gsd/markdown-renderer.js +0 -95
- package/dist/resources/extensions/gsd/native-git-bridge.js +14 -14
- package/dist/resources/extensions/gsd/notification-overlay.js +35 -40
- package/dist/resources/extensions/gsd/parallel-merge.js +53 -30
- package/dist/resources/extensions/gsd/parallel-monitor-overlay.js +25 -33
- package/dist/resources/extensions/gsd/prompts/complete-slice.md +14 -12
- package/dist/resources/extensions/gsd/prompts/discuss-headless.md +20 -2
- package/dist/resources/extensions/gsd/prompts/discuss.md +20 -2
- package/dist/resources/extensions/gsd/recovery-classification.js +15 -1
- package/dist/resources/extensions/gsd/session-lock.js +40 -0
- package/dist/resources/extensions/gsd/state-reconciliation/drift/completion.js +131 -0
- package/dist/resources/extensions/gsd/state-reconciliation/drift/merge-state.js +247 -0
- package/dist/resources/extensions/gsd/state-reconciliation/drift/project-md.js +50 -0
- package/dist/resources/extensions/gsd/state-reconciliation/drift/roadmap.js +87 -0
- package/dist/resources/extensions/gsd/state-reconciliation/drift/sketch-flag.js +50 -0
- package/dist/resources/extensions/gsd/state-reconciliation/drift/stale-render.js +124 -0
- package/dist/resources/extensions/gsd/state-reconciliation/drift/stale-worker.js +32 -0
- package/dist/resources/extensions/gsd/state-reconciliation/errors.js +41 -0
- package/dist/resources/extensions/gsd/state-reconciliation/index.js +99 -0
- package/dist/resources/extensions/gsd/state-reconciliation/registry.js +24 -0
- package/dist/resources/extensions/gsd/state-reconciliation/spawn-gate.js +43 -0
- package/dist/resources/extensions/gsd/state-reconciliation/types.js +3 -0
- package/dist/resources/extensions/gsd/state-reconciliation.js +5 -26
- package/dist/resources/extensions/gsd/tui/render-kit.js +74 -0
- package/dist/resources/extensions/gsd/watch/header-renderer.js +92 -69
- package/dist/resources/extensions/gsd/watch/splash-palette.js +10 -0
- package/dist/resources/extensions/gsd/workflow-mcp.js +2 -2
- package/dist/resources/extensions/gsd/worktree-lifecycle.js +722 -316
- package/dist/resources/extensions/gsd/worktree-telemetry.js +3 -1
- package/dist/tsconfig.extensions.tsbuildinfo +1 -1
- package/dist/web/standalone/.next/BUILD_ID +1 -1
- package/dist/web/standalone/.next/app-path-routes-manifest.json +9 -9
- package/dist/web/standalone/.next/build-manifest.json +2 -2
- package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.html +1 -1
- package/dist/web/standalone/.next/server/app/index.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app-paths-manifest.json +9 -9
- package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
- package/dist/web/standalone/.next/server/pages/404.html +1 -1
- package/dist/web/standalone/.next/server/pages/500.html +1 -1
- package/dist/welcome-screen.d.ts +0 -7
- package/dist/welcome-screen.js +60 -69
- package/package.json +1 -1
- package/packages/daemon/package.json +2 -2
- package/packages/mcp-server/package.json +2 -2
- package/packages/native/package.json +1 -1
- package/packages/pi-agent-core/package.json +1 -1
- package/packages/pi-ai/package.json +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/__tests__/assistant-message-design.test.d.ts +2 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/__tests__/assistant-message-design.test.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/__tests__/assistant-message-design.test.js +47 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/__tests__/assistant-message-design.test.js.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/__tests__/tool-execution.test.js +76 -9
- package/packages/pi-coding-agent/dist/modes/interactive/components/__tests__/tool-execution.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/__tests__/user-message-design.test.d.ts +2 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/__tests__/user-message-design.test.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/__tests__/user-message-design.test.js +40 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/__tests__/user-message-design.test.js.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/adaptive-layout.d.ts +0 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/adaptive-layout.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/adaptive-layout.js +30 -29
- package/packages/pi-coding-agent/dist/modes/interactive/components/adaptive-layout.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/adaptive-layout.test.js +10 -3
- package/packages/pi-coding-agent/dist/modes/interactive/components/adaptive-layout.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/assistant-message.js +13 -13
- package/packages/pi-coding-agent/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/bash-execution.d.ts +1 -3
- package/packages/pi-coding-agent/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/bash-execution.js +58 -3
- package/packages/pi-coding-agent/dist/modes/interactive/components/bash-execution.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/diff.d.ts +2 -2
- package/packages/pi-coding-agent/dist/modes/interactive/components/diff.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/diff.js +12 -6
- package/packages/pi-coding-agent/dist/modes/interactive/components/diff.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/footer.js +14 -41
- package/packages/pi-coding-agent/dist/modes/interactive/components/footer.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.d.ts +0 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.js +86 -82
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/transcript-design.d.ts +35 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/transcript-design.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/transcript-design.js +152 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/transcript-design.js.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/tui-style-kit.d.ts +16 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/tui-style-kit.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/tui-style-kit.js +73 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/tui-style-kit.js.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/user-message.d.ts +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/user-message.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/user-message.js +12 -8
- package/packages/pi-coding-agent/dist/modes/interactive/components/user-message.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/theme/theme-highlight.test.d.ts +2 -0
- package/packages/pi-coding-agent/dist/modes/interactive/theme/theme-highlight.test.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/theme/theme-highlight.test.js +17 -0
- package/packages/pi-coding-agent/dist/modes/interactive/theme/theme-highlight.test.js.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/theme/theme.js +105 -1
- package/packages/pi-coding-agent/dist/modes/interactive/theme/theme.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/theme/themes.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/theme/themes.js +27 -26
- package/packages/pi-coding-agent/dist/modes/interactive/theme/themes.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/tui-mode.test.js +9 -6
- package/packages/pi-coding-agent/dist/modes/interactive/tui-mode.test.js.map +1 -1
- package/packages/pi-coding-agent/package.json +1 -1
- package/packages/pi-coding-agent/src/modes/interactive/components/__tests__/assistant-message-design.test.ts +56 -0
- package/packages/pi-coding-agent/src/modes/interactive/components/__tests__/tool-execution.test.ts +113 -9
- package/packages/pi-coding-agent/src/modes/interactive/components/__tests__/user-message-design.test.ts +48 -0
- package/packages/pi-coding-agent/src/modes/interactive/components/adaptive-layout.test.ts +10 -3
- package/packages/pi-coding-agent/src/modes/interactive/components/adaptive-layout.ts +43 -42
- package/packages/pi-coding-agent/src/modes/interactive/components/assistant-message.ts +14 -14
- package/packages/pi-coding-agent/src/modes/interactive/components/bash-execution.ts +64 -3
- package/packages/pi-coding-agent/src/modes/interactive/components/diff.ts +13 -7
- package/packages/pi-coding-agent/src/modes/interactive/components/footer.ts +15 -42
- package/packages/pi-coding-agent/src/modes/interactive/components/tool-execution.ts +84 -104
- package/packages/pi-coding-agent/src/modes/interactive/components/transcript-design.ts +196 -0
- package/packages/pi-coding-agent/src/modes/interactive/components/tui-style-kit.ts +94 -0
- package/packages/pi-coding-agent/src/modes/interactive/components/user-message.ts +14 -9
- package/packages/pi-coding-agent/src/modes/interactive/theme/theme-highlight.test.ts +23 -0
- package/packages/pi-coding-agent/src/modes/interactive/theme/theme.ts +106 -1
- package/packages/pi-coding-agent/src/modes/interactive/theme/themes.ts +27 -26
- package/packages/pi-coding-agent/src/modes/interactive/tui-mode.test.ts +9 -6
- package/packages/pi-coding-agent/tsconfig.tsbuildinfo +1 -1
- package/packages/pi-tui/dist/__tests__/overlay-layout.test.js +14 -1
- package/packages/pi-tui/dist/__tests__/overlay-layout.test.js.map +1 -1
- package/packages/pi-tui/dist/overlay-layout.d.ts.map +1 -1
- package/packages/pi-tui/dist/overlay-layout.js +9 -6
- package/packages/pi-tui/dist/overlay-layout.js.map +1 -1
- package/packages/pi-tui/package.json +1 -1
- package/packages/pi-tui/src/__tests__/overlay-layout.test.ts +20 -1
- package/packages/pi-tui/src/overlay-layout.ts +10 -7
- package/packages/pi-tui/tsconfig.tsbuildinfo +1 -1
- package/packages/rpc-client/package.json +1 -1
- package/pkg/dist/modes/interactive/theme/theme-highlight.test.d.ts +2 -0
- package/pkg/dist/modes/interactive/theme/theme-highlight.test.d.ts.map +1 -0
- package/pkg/dist/modes/interactive/theme/theme-highlight.test.js +17 -0
- package/pkg/dist/modes/interactive/theme/theme-highlight.test.js.map +1 -0
- package/pkg/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/pkg/dist/modes/interactive/theme/theme.js +105 -1
- package/pkg/dist/modes/interactive/theme/theme.js.map +1 -1
- package/pkg/dist/modes/interactive/theme/themes.d.ts.map +1 -1
- package/pkg/dist/modes/interactive/theme/themes.js +27 -26
- package/pkg/dist/modes/interactive/theme/themes.js.map +1 -1
- package/pkg/package.json +1 -1
- package/src/resources/extensions/gsd/auto/loop-deps.ts +9 -5
- package/src/resources/extensions/gsd/auto/loop.ts +113 -9
- package/src/resources/extensions/gsd/auto/phases.ts +144 -19
- package/src/resources/extensions/gsd/auto/run-unit.ts +69 -4
- package/src/resources/extensions/gsd/auto/session.ts +10 -0
- package/src/resources/extensions/gsd/auto/verification-retry-policy.ts +82 -0
- package/src/resources/extensions/gsd/auto-dashboard.ts +230 -183
- package/src/resources/extensions/gsd/auto-dispatch.ts +15 -1
- package/src/resources/extensions/gsd/auto-post-unit.ts +7 -1
- package/src/resources/extensions/gsd/auto-recovery.ts +7 -209
- package/src/resources/extensions/gsd/auto-runtime-state.ts +5 -0
- package/src/resources/extensions/gsd/auto-start.ts +22 -22
- package/src/resources/extensions/gsd/auto-unit-closeout.ts +51 -0
- package/src/resources/extensions/gsd/auto-verification.ts +12 -6
- package/src/resources/extensions/gsd/auto-worktree.ts +8 -0
- package/src/resources/extensions/gsd/auto.ts +295 -75
- package/src/resources/extensions/gsd/bootstrap/agent-end-recovery.ts +21 -6
- package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +6 -2
- package/src/resources/extensions/gsd/bootstrap/register-shortcuts.ts +5 -8
- package/src/resources/extensions/gsd/commands/handlers/notifications-handler.ts +4 -10
- package/src/resources/extensions/gsd/commands/handlers/parallel.ts +12 -0
- package/src/resources/extensions/gsd/git-service.ts +2 -0
- package/src/resources/extensions/gsd/gsd-db.ts +7 -23
- package/src/resources/extensions/gsd/health-widget-core.ts +1 -1
- package/src/resources/extensions/gsd/health-widget.ts +6 -10
- package/src/resources/extensions/gsd/journal.ts +2 -0
- package/src/resources/extensions/gsd/markdown-renderer.ts +4 -95
- package/src/resources/extensions/gsd/native-git-bridge.ts +14 -13
- package/src/resources/extensions/gsd/notification-overlay.ts +50 -46
- package/src/resources/extensions/gsd/parallel-merge.ts +61 -34
- package/src/resources/extensions/gsd/parallel-monitor-overlay.ts +33 -35
- package/src/resources/extensions/gsd/prompts/complete-slice.md +14 -12
- package/src/resources/extensions/gsd/prompts/discuss-headless.md +20 -2
- package/src/resources/extensions/gsd/prompts/discuss.md +20 -2
- package/src/resources/extensions/gsd/recovery-classification.ts +18 -1
- package/src/resources/extensions/gsd/session-lock.ts +41 -0
- package/src/resources/extensions/gsd/state-reconciliation/drift/completion.ts +172 -0
- package/src/resources/extensions/gsd/state-reconciliation/drift/merge-state.ts +337 -0
- package/src/resources/extensions/gsd/state-reconciliation/drift/project-md.ts +69 -0
- package/src/resources/extensions/gsd/state-reconciliation/drift/roadmap.ts +109 -0
- package/src/resources/extensions/gsd/state-reconciliation/drift/sketch-flag.ts +68 -0
- package/src/resources/extensions/gsd/state-reconciliation/drift/stale-render.ts +185 -0
- package/src/resources/extensions/gsd/state-reconciliation/drift/stale-worker.ts +46 -0
- package/src/resources/extensions/gsd/state-reconciliation/errors.ts +67 -0
- package/src/resources/extensions/gsd/state-reconciliation/index.ts +142 -0
- package/src/resources/extensions/gsd/state-reconciliation/registry.ts +27 -0
- package/src/resources/extensions/gsd/state-reconciliation/spawn-gate.ts +60 -0
- package/src/resources/extensions/gsd/state-reconciliation/types.ts +83 -0
- package/src/resources/extensions/gsd/state-reconciliation.ts +21 -53
- package/src/resources/extensions/gsd/tests/artifact-retry-cap.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/auto-dashboard.test.ts +99 -0
- package/src/resources/extensions/gsd/tests/auto-loop.test.ts +654 -176
- package/src/resources/extensions/gsd/tests/auto-paused-ui-cleanup.test.ts +291 -4
- package/src/resources/extensions/gsd/tests/auto-runtime-state.test.ts +16 -1
- package/src/resources/extensions/gsd/tests/auto-start-orphan-bootstrap.test.ts +18 -0
- package/src/resources/extensions/gsd/tests/auto-unit-closeout.test.ts +68 -0
- package/src/resources/extensions/gsd/tests/custom-engine-loop-integration.test.ts +28 -1
- package/src/resources/extensions/gsd/tests/deep-project-auto-loop.test.ts +20 -2
- package/src/resources/extensions/gsd/tests/dispatch-complete-milestone-guard.test.ts +44 -0
- package/src/resources/extensions/gsd/tests/header-renderer.test.ts +40 -0
- package/src/resources/extensions/gsd/tests/headless-milestone-parity.test.ts +10 -0
- package/src/resources/extensions/gsd/tests/health-widget.test.ts +14 -4
- package/src/resources/extensions/gsd/tests/integration/git-service.test.ts +26 -0
- package/src/resources/extensions/gsd/tests/integration/integration-proof.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/integration/parallel-merge.test.ts +116 -24
- package/src/resources/extensions/gsd/tests/journal-integration.test.ts +0 -1
- package/src/resources/extensions/gsd/tests/markdown-renderer.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/merge-conflict-stops-loop.test.ts +46 -11
- package/src/resources/extensions/gsd/tests/notification-overlay.test.ts +78 -41
- package/src/resources/extensions/gsd/tests/notifications-handler.test.ts +44 -0
- package/src/resources/extensions/gsd/tests/originalbase-path-comparison.test.ts +12 -217
- package/src/resources/extensions/gsd/tests/parallel-monitor-overlay.test.ts +38 -6
- package/src/resources/extensions/gsd/tests/post-exec-retry-bypass.test.ts +2 -2
- package/src/resources/extensions/gsd/tests/progressive-planning.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/prompt-contracts.test.ts +24 -1
- package/src/resources/extensions/gsd/tests/resume-dispatch-worktree.test.ts +7 -3
- package/src/resources/extensions/gsd/tests/runtime-invariant-modules.test.ts +6 -3
- package/src/resources/extensions/gsd/tests/session-switch-abort-misclassification.test.ts +24 -0
- package/src/resources/extensions/gsd/tests/state-corruption-2945.test.ts +65 -58
- package/src/resources/extensions/gsd/tests/state-reconciliation-drift.test.ts +952 -0
- package/src/resources/extensions/gsd/tests/token-tool-gating.test.ts +4 -0
- package/src/resources/extensions/gsd/tests/tui-header-lifecycle.test.ts +121 -1
- package/src/resources/extensions/gsd/tests/tui-render-kit.test.ts +66 -0
- package/src/resources/extensions/gsd/tests/verification-retry-policy.test.ts +83 -0
- package/src/resources/extensions/gsd/tests/workflow-mcp.test.ts +6 -0
- package/src/resources/extensions/gsd/tests/worktree-journal-events.test.ts +158 -58
- package/src/resources/extensions/gsd/tests/worktree-lifecycle.test.ts +572 -118
- package/src/resources/extensions/gsd/tests/worktree-telemetry.test.ts +59 -2
- package/src/resources/extensions/gsd/tests/write-gate-planning-unit.test.ts +18 -0
- package/src/resources/extensions/gsd/tui/render-kit.ts +109 -0
- package/src/resources/extensions/gsd/watch/header-renderer.ts +121 -79
- package/src/resources/extensions/gsd/watch/splash-palette.ts +11 -0
- package/src/resources/extensions/gsd/workflow-mcp.ts +2 -2
- package/src/resources/extensions/gsd/worktree-lifecycle.ts +1151 -524
- package/src/resources/extensions/gsd/worktree-telemetry.ts +7 -2
- package/src/resources/extensions/gsd/tests/worktree-resolver.test.ts +0 -1544
- /package/dist/web/standalone/.next/static/{drLMkgfHQ8lzS229_HWYR → S44UQTFCUdA44dkjfYt6S}/_buildManifest.js +0 -0
- /package/dist/web/standalone/.next/static/{drLMkgfHQ8lzS229_HWYR → S44UQTFCUdA44dkjfYt6S}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
// Project/App: GSD-2
|
|
2
|
+
// File Purpose: ADR-017 unmerged-merge-state drift handler. Relocated from
|
|
3
|
+
// auto-recovery.ts as part of issue #5701. Owns:
|
|
4
|
+
// - rebase/cherry-pick/revert leftover cleanup (#4980 HIGH-7)
|
|
5
|
+
// - MERGE_HEAD / SQUASH_MSG reconciliation with auto-resolve of .gsd/
|
|
6
|
+
// conflicts (#530, #2542)
|
|
7
|
+
import { execFileSync } from "node:child_process";
|
|
8
|
+
import { existsSync, unlinkSync } from "node:fs";
|
|
9
|
+
import { isAbsolute, join, resolve } from "node:path";
|
|
10
|
+
import { getErrorMessage } from "../../error-utils.js";
|
|
11
|
+
import { nativeAddPaths, nativeCheckoutTheirs, nativeCommit, nativeConflictFiles, nativeMergeAbort, nativeRebaseAbort, nativeResetHard, } from "../../native-git-bridge.js";
|
|
12
|
+
import { logError, logWarning } from "../../workflow-logger.js";
|
|
13
|
+
const SILENT_NOTIFY = () => { };
|
|
14
|
+
function resolveGitDir(basePath) {
|
|
15
|
+
try {
|
|
16
|
+
const gitDir = execFileSync("git", ["rev-parse", "--git-dir"], {
|
|
17
|
+
cwd: basePath,
|
|
18
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
19
|
+
encoding: "utf-8",
|
|
20
|
+
}).trim();
|
|
21
|
+
if (gitDir.length > 0) {
|
|
22
|
+
return isAbsolute(gitDir) ? gitDir : resolve(basePath, gitDir);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
logWarning("recovery", `gitdir resolution failed: ${getErrorMessage(err)}`);
|
|
27
|
+
}
|
|
28
|
+
return join(basePath, ".git");
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Best-effort abort of a pending merge/squash and hard-reset to HEAD.
|
|
32
|
+
* Handles both real merges (MERGE_HEAD) and squash merges (SQUASH_MSG).
|
|
33
|
+
*/
|
|
34
|
+
function abortAndResetMerge(basePath, hasMergeHead, squashMsgPath) {
|
|
35
|
+
if (hasMergeHead) {
|
|
36
|
+
try {
|
|
37
|
+
nativeMergeAbort(basePath);
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
/* best-effort */
|
|
41
|
+
logWarning("recovery", `git merge-abort failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else if (squashMsgPath) {
|
|
45
|
+
try {
|
|
46
|
+
unlinkSync(squashMsgPath);
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
/* best-effort */
|
|
50
|
+
logWarning("recovery", `file unlink failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
nativeResetHard(basePath);
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
/* best-effort */
|
|
58
|
+
logError("recovery", `git reset failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Detect and abort other in-progress git operations left behind by a SIGKILL'd
|
|
63
|
+
* worker (rebase, cherry-pick, revert). Without this, a killed worker
|
|
64
|
+
* mid-rebase leaves `.git/rebase-merge/` or `.git/CHERRY_PICK_HEAD` and the
|
|
65
|
+
* worktree is wedged until the user manually runs the matching `--abort`.
|
|
66
|
+
*
|
|
67
|
+
* Called before merge-state reconciliation because these states block any
|
|
68
|
+
* subsequent merge/commit operation. (#4980 HIGH-7)
|
|
69
|
+
*/
|
|
70
|
+
function reconcileOtherInProgressGitOps(basePath, notify) {
|
|
71
|
+
const gitDir = resolveGitDir(basePath);
|
|
72
|
+
const states = [
|
|
73
|
+
{
|
|
74
|
+
label: "rebase",
|
|
75
|
+
indicators: [join(gitDir, "rebase-merge"), join(gitDir, "rebase-apply")],
|
|
76
|
+
abort: () => nativeRebaseAbort(basePath),
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
label: "cherry-pick",
|
|
80
|
+
indicators: [join(gitDir, "CHERRY_PICK_HEAD")],
|
|
81
|
+
abort: () => {
|
|
82
|
+
try {
|
|
83
|
+
execFileSync("git", ["cherry-pick", "--abort"], {
|
|
84
|
+
cwd: basePath,
|
|
85
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
86
|
+
encoding: "utf-8",
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
throw new Error(`cherry-pick --abort failed: ${getErrorMessage(err)}`);
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
label: "revert",
|
|
96
|
+
indicators: [join(gitDir, "REVERT_HEAD")],
|
|
97
|
+
abort: () => {
|
|
98
|
+
try {
|
|
99
|
+
execFileSync("git", ["revert", "--abort"], {
|
|
100
|
+
cwd: basePath,
|
|
101
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
102
|
+
encoding: "utf-8",
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
throw new Error(`revert --abort failed: ${getErrorMessage(err)}`);
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
];
|
|
111
|
+
let reconciled = false;
|
|
112
|
+
for (const s of states) {
|
|
113
|
+
const present = s.indicators.some((p) => existsSync(p));
|
|
114
|
+
if (!present)
|
|
115
|
+
continue;
|
|
116
|
+
try {
|
|
117
|
+
s.abort();
|
|
118
|
+
notify(`Detected leftover ${s.label} state from prior session — aborted.`, "warning");
|
|
119
|
+
reconciled = true;
|
|
120
|
+
}
|
|
121
|
+
catch (err) {
|
|
122
|
+
logError("recovery", `${s.label} abort failed: ${getErrorMessage(err)}`);
|
|
123
|
+
notify(`Detected leftover ${s.label} state but auto-abort failed. ` +
|
|
124
|
+
`Run \`git ${s.label} --abort\` manually before retrying.`, "error");
|
|
125
|
+
return "blocked";
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return reconciled ? "reconciled" : "clean";
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Core: detect leftover merge state and reconcile it. Takes a NotifyFn so the
|
|
132
|
+
* legacy reconcileMergeState(basePath, ctx) wrapper and the drift handler can
|
|
133
|
+
* both call it — the drift handler uses SILENT_NOTIFY.
|
|
134
|
+
*/
|
|
135
|
+
function reconcileMergeStateCore(basePath, notify) {
|
|
136
|
+
// First, abort any rebase/cherry-pick/revert left over from a SIGKILL'd
|
|
137
|
+
// worker. Doing this before the merge-state check unblocks any merge that
|
|
138
|
+
// would otherwise refuse with "you have unfinished operation". (HIGH-7)
|
|
139
|
+
const otherOpsResult = reconcileOtherInProgressGitOps(basePath, notify);
|
|
140
|
+
if (otherOpsResult === "blocked")
|
|
141
|
+
return "blocked";
|
|
142
|
+
const gitDir = resolveGitDir(basePath);
|
|
143
|
+
const mergeHeadPath = join(gitDir, "MERGE_HEAD");
|
|
144
|
+
const squashMsgPath = join(gitDir, "SQUASH_MSG");
|
|
145
|
+
const hasMergeHead = existsSync(mergeHeadPath);
|
|
146
|
+
const hasSquashMsg = existsSync(squashMsgPath);
|
|
147
|
+
if (!hasMergeHead && !hasSquashMsg) {
|
|
148
|
+
return otherOpsResult === "reconciled" ? "reconciled" : "clean";
|
|
149
|
+
}
|
|
150
|
+
const conflictedFiles = nativeConflictFiles(basePath);
|
|
151
|
+
if (conflictedFiles.length === 0) {
|
|
152
|
+
// All conflicts resolved — finalize the merge/squash commit
|
|
153
|
+
try {
|
|
154
|
+
const commitSha = nativeCommit(basePath, "chore(gsd): reconcile merge state");
|
|
155
|
+
if (commitSha) {
|
|
156
|
+
const mode = hasMergeHead ? "merge" : "squash commit";
|
|
157
|
+
notify(`Finalized leftover ${mode} from prior session.`, "info");
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
notify("No new commit needed for leftover merge/squash state — already committed.", "info");
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
catch (err) {
|
|
164
|
+
const errorMessage = getErrorMessage(err);
|
|
165
|
+
notify(`Failed to finalize leftover merge/squash commit: ${errorMessage}`, "error");
|
|
166
|
+
return "blocked";
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
// Still conflicted — try auto-resolving .gsd/ state file conflicts (#530)
|
|
171
|
+
const gsdConflicts = conflictedFiles.filter((f) => f.startsWith(".gsd/"));
|
|
172
|
+
const codeConflicts = conflictedFiles.filter((f) => !f.startsWith(".gsd/"));
|
|
173
|
+
if (gsdConflicts.length > 0 && codeConflicts.length === 0) {
|
|
174
|
+
let resolved = true;
|
|
175
|
+
try {
|
|
176
|
+
nativeCheckoutTheirs(basePath, gsdConflicts);
|
|
177
|
+
nativeAddPaths(basePath, gsdConflicts);
|
|
178
|
+
}
|
|
179
|
+
catch (e) {
|
|
180
|
+
logError("recovery", `auto-resolve .gsd/ conflicts failed: ${e.message}`);
|
|
181
|
+
resolved = false;
|
|
182
|
+
}
|
|
183
|
+
if (resolved) {
|
|
184
|
+
try {
|
|
185
|
+
nativeCommit(basePath, "chore: auto-resolve .gsd/ state file conflicts");
|
|
186
|
+
notify(`Auto-resolved ${gsdConflicts.length} .gsd/ state file conflict(s) from prior merge.`, "info");
|
|
187
|
+
}
|
|
188
|
+
catch (e) {
|
|
189
|
+
logError("recovery", `auto-commit .gsd/ conflict resolution failed: ${e.message}`);
|
|
190
|
+
resolved = false;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (!resolved) {
|
|
194
|
+
abortAndResetMerge(basePath, hasMergeHead, squashMsgPath);
|
|
195
|
+
notify("Detected leftover merge state — auto-resolve failed, cleaned up. Re-deriving state.", "warning");
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
// Code conflicts present — fail safe and preserve any manual resolution
|
|
200
|
+
// work instead of discarding it with merge --abort/reset --hard.
|
|
201
|
+
notify("Detected leftover merge state with unresolved code conflicts. Auto-mode will pause without modifying the worktree so manual conflict resolution is preserved.", "error");
|
|
202
|
+
return "blocked";
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return "reconciled";
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Legacy entry point preserved for existing callers (auto.ts, auto/phases.ts
|
|
209
|
+
* via loop-deps, integration tests). New code prefers the drift handler.
|
|
210
|
+
*/
|
|
211
|
+
export function reconcileMergeState(basePath, ctx) {
|
|
212
|
+
return reconcileMergeStateCore(basePath, (message, severity) => ctx.ui.notify(message, severity));
|
|
213
|
+
}
|
|
214
|
+
function hasMergeStateLeftovers(basePath) {
|
|
215
|
+
const gitDir = resolveGitDir(basePath);
|
|
216
|
+
return (existsSync(join(gitDir, "MERGE_HEAD")) ||
|
|
217
|
+
existsSync(join(gitDir, "SQUASH_MSG")) ||
|
|
218
|
+
existsSync(join(gitDir, "rebase-merge")) ||
|
|
219
|
+
existsSync(join(gitDir, "rebase-apply")) ||
|
|
220
|
+
existsSync(join(gitDir, "CHERRY_PICK_HEAD")) ||
|
|
221
|
+
existsSync(join(gitDir, "REVERT_HEAD")));
|
|
222
|
+
}
|
|
223
|
+
export function detectMergeStateDrift(_state, ctx) {
|
|
224
|
+
if (hasMergeStateLeftovers(ctx.basePath)) {
|
|
225
|
+
return [{ kind: "unmerged-merge-state", basePath: ctx.basePath }];
|
|
226
|
+
}
|
|
227
|
+
return [];
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Repair: invoke the reconciliation core with a silent notify. If the
|
|
231
|
+
* underlying reconciliation reports "blocked" (e.g., unresolved code
|
|
232
|
+
* conflicts present), throw so reconcileBeforeDispatch surfaces the drift
|
|
233
|
+
* via ReconciliationFailedError.
|
|
234
|
+
*/
|
|
235
|
+
export function repairMergeStateDrift(record) {
|
|
236
|
+
const result = reconcileMergeStateCore(record.basePath, SILENT_NOTIFY);
|
|
237
|
+
if (result === "blocked") {
|
|
238
|
+
throw new Error(`Merge state reconciliation blocked for ${record.basePath} — likely unresolved code conflicts. Manual intervention required.`);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
export const mergeStateHandler = {
|
|
242
|
+
kind: "unmerged-merge-state",
|
|
243
|
+
detect: detectMergeStateDrift,
|
|
244
|
+
repair: (record) => {
|
|
245
|
+
repairMergeStateDrift(record);
|
|
246
|
+
},
|
|
247
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Project/App: GSD-2
|
|
2
|
+
// File Purpose: ADR-017 unregistered-milestone drift handler. Detects
|
|
3
|
+
// milestones whose on-disk directory has meaningful content (ROADMAP/
|
|
4
|
+
// CONTEXT/SUMMARY) but no DB row, then runs the markdown importer to
|
|
5
|
+
// reconcile. PROJECT.md is the human-facing index — the importer's source
|
|
6
|
+
// of truth is the .gsd/milestones/ directory tree.
|
|
7
|
+
import { existsSync } from "node:fs";
|
|
8
|
+
import { getMilestone, isDbAvailable } from "../../gsd-db.js";
|
|
9
|
+
import { migrateHierarchyToDb } from "../../md-importer.js";
|
|
10
|
+
import { findMilestoneIds } from "../../milestone-ids.js";
|
|
11
|
+
import { resolveMilestoneFile } from "../../paths.js";
|
|
12
|
+
function milestoneHasContent(basePath, milestoneId) {
|
|
13
|
+
const roadmap = resolveMilestoneFile(basePath, milestoneId, "ROADMAP");
|
|
14
|
+
const context = resolveMilestoneFile(basePath, milestoneId, "CONTEXT");
|
|
15
|
+
const summary = resolveMilestoneFile(basePath, milestoneId, "SUMMARY");
|
|
16
|
+
return ((roadmap !== null && existsSync(roadmap)) ||
|
|
17
|
+
(context !== null && existsSync(context)) ||
|
|
18
|
+
(summary !== null && existsSync(summary)));
|
|
19
|
+
}
|
|
20
|
+
export function detectUnregisteredMilestoneDrift(_state, ctx) {
|
|
21
|
+
if (!isDbAvailable())
|
|
22
|
+
return [];
|
|
23
|
+
const drifts = [];
|
|
24
|
+
for (const milestoneId of findMilestoneIds(ctx.basePath)) {
|
|
25
|
+
if (getMilestone(milestoneId))
|
|
26
|
+
continue;
|
|
27
|
+
if (!milestoneHasContent(ctx.basePath, milestoneId))
|
|
28
|
+
continue;
|
|
29
|
+
drifts.push({ kind: "unregistered-milestone", milestoneId });
|
|
30
|
+
}
|
|
31
|
+
return drifts;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Repair: invoke the markdown importer. migrateHierarchyToDb walks the same
|
|
35
|
+
* findMilestoneIds list the detector uses and INSERTs OR IGNOREs every
|
|
36
|
+
* missing milestone (and its slices/tasks) — idempotent under cap=2 retry.
|
|
37
|
+
*
|
|
38
|
+
* Note: even though we receive one record at a time, the importer is a
|
|
39
|
+
* project-wide operation. Repeated invocation across multiple drift records
|
|
40
|
+
* in the same pass is wasteful but safe; a future optimization could
|
|
41
|
+
* coalesce by checking whether the importer has already run this pass.
|
|
42
|
+
*/
|
|
43
|
+
export function repairUnregisteredMilestone(_record, ctx) {
|
|
44
|
+
migrateHierarchyToDb(ctx.basePath);
|
|
45
|
+
}
|
|
46
|
+
export const unregisteredMilestoneHandler = {
|
|
47
|
+
kind: "unregistered-milestone",
|
|
48
|
+
detect: detectUnregisteredMilestoneDrift,
|
|
49
|
+
repair: repairUnregisteredMilestone,
|
|
50
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// Project/App: GSD-2
|
|
2
|
+
// File Purpose: ADR-017 roadmap-divergence drift handler. Detects mismatches
|
|
3
|
+
// between ROADMAP.md (parsed slice sequence + depends declarations) and the
|
|
4
|
+
// DB slice rows for that milestone, then reconciles via the markdown
|
|
5
|
+
// importer plus an explicit junction-table sync.
|
|
6
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
7
|
+
import { getMilestone, getMilestoneSlices, isDbAvailable, syncSliceDependencies, } from "../../gsd-db.js";
|
|
8
|
+
import { migrateHierarchyToDb } from "../../md-importer.js";
|
|
9
|
+
import { findMilestoneIds } from "../../milestone-ids.js";
|
|
10
|
+
import { parseRoadmap } from "../../parsers-legacy.js";
|
|
11
|
+
import { resolveMilestoneFile } from "../../paths.js";
|
|
12
|
+
function arraysEqual(a, b) {
|
|
13
|
+
if (a.length !== b.length)
|
|
14
|
+
return false;
|
|
15
|
+
for (let i = 0; i < a.length; i++)
|
|
16
|
+
if (a[i] !== b[i])
|
|
17
|
+
return false;
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
function milestoneHasDivergence(basePath, milestoneId) {
|
|
21
|
+
const roadmapPath = resolveMilestoneFile(basePath, milestoneId, "ROADMAP");
|
|
22
|
+
if (!roadmapPath || !existsSync(roadmapPath))
|
|
23
|
+
return false;
|
|
24
|
+
let roadmap;
|
|
25
|
+
try {
|
|
26
|
+
roadmap = parseRoadmap(readFileSync(roadmapPath, "utf-8"));
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
const dbSlices = getMilestoneSlices(milestoneId);
|
|
32
|
+
const dbSliceMap = new Map(dbSlices.map((s) => [s.id, s]));
|
|
33
|
+
for (let i = 0; i < roadmap.slices.length; i++) {
|
|
34
|
+
const roadmapSlice = roadmap.slices[i];
|
|
35
|
+
const expectedSequence = i + 1;
|
|
36
|
+
const dbSlice = dbSliceMap.get(roadmapSlice.id);
|
|
37
|
+
if (!dbSlice)
|
|
38
|
+
return true; // Roadmap has a slice the DB doesn't.
|
|
39
|
+
if (dbSlice.sequence !== expectedSequence)
|
|
40
|
+
return true;
|
|
41
|
+
if (!arraysEqual(dbSlice.depends, roadmapSlice.depends))
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
export function detectRoadmapDivergenceDrift(_state, ctx) {
|
|
47
|
+
if (!isDbAvailable())
|
|
48
|
+
return [];
|
|
49
|
+
const drifts = [];
|
|
50
|
+
for (const milestoneId of findMilestoneIds(ctx.basePath)) {
|
|
51
|
+
// Skip milestones that don't yet have a DB row — that's the
|
|
52
|
+
// unregistered-milestone drift handler's responsibility.
|
|
53
|
+
if (!getMilestone(milestoneId))
|
|
54
|
+
continue;
|
|
55
|
+
if (milestoneHasDivergence(ctx.basePath, milestoneId)) {
|
|
56
|
+
drifts.push({ kind: "roadmap-divergence", milestoneId });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return drifts;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Repair a milestone's roadmap divergence:
|
|
63
|
+
* 1. migrateHierarchyToDb upserts slice rows (sequence + depends JSON
|
|
64
|
+
* update via ON CONFLICT DO UPDATE).
|
|
65
|
+
* 2. syncSliceDependencies updates the junction table per slice — the
|
|
66
|
+
* importer only writes the JSON column, not the relational view.
|
|
67
|
+
*/
|
|
68
|
+
export function repairRoadmapDivergence(record, ctx) {
|
|
69
|
+
migrateHierarchyToDb(ctx.basePath);
|
|
70
|
+
const roadmapPath = resolveMilestoneFile(ctx.basePath, record.milestoneId, "ROADMAP");
|
|
71
|
+
if (!roadmapPath || !existsSync(roadmapPath))
|
|
72
|
+
return;
|
|
73
|
+
try {
|
|
74
|
+
const roadmap = parseRoadmap(readFileSync(roadmapPath, "utf-8"));
|
|
75
|
+
for (const slice of roadmap.slices) {
|
|
76
|
+
syncSliceDependencies(record.milestoneId, slice.id, slice.depends);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
/* parse failure: detector will fire again next pass */
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
export const roadmapDivergenceHandler = {
|
|
84
|
+
kind: "roadmap-divergence",
|
|
85
|
+
detect: detectRoadmapDivergenceDrift,
|
|
86
|
+
repair: repairRoadmapDivergence,
|
|
87
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Project/App: GSD-2
|
|
2
|
+
// File Purpose: ADR-017 stale-sketch-flag drift handler. Relocated from
|
|
3
|
+
// gsd-db.ts where autoHealSketchFlags previously lived with zero callers.
|
|
4
|
+
//
|
|
5
|
+
// Recovers from two scenarios (per ADR-011):
|
|
6
|
+
// 1. Crash between gsd_plan_slice's PLAN.md write and the sketch flag flip.
|
|
7
|
+
// 2. Flag-OFF downgrade: when progressive_planning is off, dispatch routes
|
|
8
|
+
// sketch slices to plan-slice, which writes PLAN.md but leaves
|
|
9
|
+
// is_sketch=1 — the next reconciliation pass clears it.
|
|
10
|
+
import { existsSync } from "node:fs";
|
|
11
|
+
import { getSketchedSliceIds, isDbAvailable, setSliceSketchFlag, } from "../../gsd-db.js";
|
|
12
|
+
import { resolveSliceFile } from "../../paths.js";
|
|
13
|
+
export function detectStaleSketchFlags(state, ctx) {
|
|
14
|
+
if (!isDbAvailable())
|
|
15
|
+
return [];
|
|
16
|
+
const mid = state.activeMilestone?.id;
|
|
17
|
+
if (!mid)
|
|
18
|
+
return [];
|
|
19
|
+
const sliceIds = getSketchedSliceIds(mid);
|
|
20
|
+
return sliceIds
|
|
21
|
+
.filter((sid) => {
|
|
22
|
+
const planPath = resolveSliceFile(ctx.basePath, mid, sid, "PLAN");
|
|
23
|
+
return planPath !== null && existsSync(planPath);
|
|
24
|
+
})
|
|
25
|
+
.map((sid) => ({ kind: "stale-sketch-flag", mid, sid }));
|
|
26
|
+
}
|
|
27
|
+
export function repairStaleSketchFlag(record) {
|
|
28
|
+
setSliceSketchFlag(record.mid, record.sid, false);
|
|
29
|
+
}
|
|
30
|
+
export const sketchFlagHandler = {
|
|
31
|
+
kind: "stale-sketch-flag",
|
|
32
|
+
detect: detectStaleSketchFlags,
|
|
33
|
+
repair: (record) => {
|
|
34
|
+
repairStaleSketchFlag(record);
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Legacy entry point preserved for callers that supply a custom hasPlanFile
|
|
39
|
+
* predicate. Prefer the drift handler (sketchFlagHandler) for new code.
|
|
40
|
+
*/
|
|
41
|
+
export function autoHealSketchFlags(milestoneId, hasPlanFile) {
|
|
42
|
+
if (!isDbAvailable())
|
|
43
|
+
return;
|
|
44
|
+
const sliceIds = getSketchedSliceIds(milestoneId);
|
|
45
|
+
for (const sid of sliceIds) {
|
|
46
|
+
if (hasPlanFile(sid)) {
|
|
47
|
+
setSliceSketchFlag(milestoneId, sid, false);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// Project/App: GSD-2
|
|
2
|
+
// File Purpose: ADR-017 stale-render drift handler. Relocated from
|
|
3
|
+
// markdown-renderer.ts as part of issue #5702. detectStaleRenders stays in
|
|
4
|
+
// markdown-renderer.ts (it's a useful diagnostic primitive on its own); only
|
|
5
|
+
// the detect+repair composition moves here. The previous repairStaleRenders
|
|
6
|
+
// had zero callers in production code — wiring it through
|
|
7
|
+
// reconcileBeforeDispatch closes that gap.
|
|
8
|
+
import { detectStaleRenders, renderPlanCheckboxes, renderRoadmapCheckboxes, renderSliceSummary, renderTaskSummary, } from "../../markdown-renderer.js";
|
|
9
|
+
import { logWarning } from "../../workflow-logger.js";
|
|
10
|
+
// ─── Core (basePath-only — usable by both drift API and legacy wrapper) ──────
|
|
11
|
+
function detectStaleRenderDriftFromBasePath(basePath) {
|
|
12
|
+
const entries = detectStaleRenders(basePath);
|
|
13
|
+
if (entries.length === 0)
|
|
14
|
+
return [];
|
|
15
|
+
// detectStaleRenders may emit multiple entries for the same path (one per
|
|
16
|
+
// mismatched checkbox). Dedupe by path; the repair re-renders the whole
|
|
17
|
+
// file in a single call. Prefer a reason the repair dispatcher can handle.
|
|
18
|
+
const seen = new Map();
|
|
19
|
+
for (const entry of entries) {
|
|
20
|
+
const currentReason = seen.get(entry.path);
|
|
21
|
+
if (currentReason === undefined ||
|
|
22
|
+
(!isRepairableStaleRenderReason(currentReason) && isRepairableStaleRenderReason(entry.reason))) {
|
|
23
|
+
seen.set(entry.path, entry.reason);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return Array.from(seen.entries()).map(([renderPath, reason]) => ({
|
|
27
|
+
kind: "stale-render",
|
|
28
|
+
renderPath,
|
|
29
|
+
reason,
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
function isRepairableStaleRenderReason(reason) {
|
|
33
|
+
return (reason.includes("in roadmap") ||
|
|
34
|
+
reason.includes("in plan") ||
|
|
35
|
+
(reason.includes("SUMMARY.md missing") && /^T\d+/.test(reason)) ||
|
|
36
|
+
(reason.includes("SUMMARY.md missing") && /^S\d+/.test(reason)) ||
|
|
37
|
+
reason.includes("UAT.md missing"));
|
|
38
|
+
}
|
|
39
|
+
async function repairStaleRenderFromBasePath(record, basePath) {
|
|
40
|
+
const normPath = record.renderPath.replace(/\\/g, "/");
|
|
41
|
+
const reason = record.reason;
|
|
42
|
+
if (reason.includes("in roadmap")) {
|
|
43
|
+
const milestoneMatch = normPath.match(/milestones\/([^/]+)\//);
|
|
44
|
+
if (!milestoneMatch) {
|
|
45
|
+
throw new Error(`stale-render drift: roadmap path missing milestone segment: ${record.renderPath}`);
|
|
46
|
+
}
|
|
47
|
+
await renderRoadmapCheckboxes(basePath, milestoneMatch[1]);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (reason.includes("in plan")) {
|
|
51
|
+
const pathMatch = normPath.match(/milestones\/([^/]+)\/slices\/([^/]+)\//);
|
|
52
|
+
if (!pathMatch) {
|
|
53
|
+
throw new Error(`stale-render drift: plan path missing milestone/slice segments: ${record.renderPath}`);
|
|
54
|
+
}
|
|
55
|
+
await renderPlanCheckboxes(basePath, pathMatch[1], pathMatch[2]);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (reason.includes("SUMMARY.md missing") && /^T\d+/.test(reason)) {
|
|
59
|
+
const pathMatch = normPath.match(/milestones\/([^/]+)\/slices\/([^/]+)\/tasks\//);
|
|
60
|
+
const taskMatch = reason.match(/^(T\d+)/);
|
|
61
|
+
if (!pathMatch || !taskMatch) {
|
|
62
|
+
throw new Error(`stale-render drift: task summary path/reason malformed: ${record.renderPath} reason=${reason}`);
|
|
63
|
+
}
|
|
64
|
+
await renderTaskSummary(basePath, pathMatch[1], pathMatch[2], taskMatch[1]);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (reason.includes("SUMMARY.md missing") && /^S\d+/.test(reason)) {
|
|
68
|
+
const pathMatch = normPath.match(/milestones\/([^/]+)\/slices\/([^/]+)\//);
|
|
69
|
+
if (!pathMatch) {
|
|
70
|
+
throw new Error(`stale-render drift: slice summary path missing milestone/slice segments: ${record.renderPath}`);
|
|
71
|
+
}
|
|
72
|
+
await renderSliceSummary(basePath, pathMatch[1], pathMatch[2]);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (reason.includes("UAT.md missing")) {
|
|
76
|
+
const pathMatch = normPath.match(/milestones\/([^/]+)\/slices\/([^/]+)\//);
|
|
77
|
+
if (!pathMatch) {
|
|
78
|
+
throw new Error(`stale-render drift: UAT path missing milestone/slice segments: ${record.renderPath}`);
|
|
79
|
+
}
|
|
80
|
+
// renderSliceSummary handles both SUMMARY and UAT.
|
|
81
|
+
await renderSliceSummary(basePath, pathMatch[1], pathMatch[2]);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
throw new Error(`stale-render drift: detector emitted unknown reason "${reason}" for ${record.renderPath}`);
|
|
85
|
+
}
|
|
86
|
+
// ─── Drift Handler API ───────────────────────────────────────────────────────
|
|
87
|
+
export function detectStaleRenderDrift(_state, ctx) {
|
|
88
|
+
return detectStaleRenderDriftFromBasePath(ctx.basePath);
|
|
89
|
+
}
|
|
90
|
+
export async function repairStaleRender(record, ctx) {
|
|
91
|
+
await repairStaleRenderFromBasePath(record, ctx.basePath);
|
|
92
|
+
}
|
|
93
|
+
export const staleRenderHandler = {
|
|
94
|
+
kind: "stale-render",
|
|
95
|
+
detect: detectStaleRenderDrift,
|
|
96
|
+
repair: repairStaleRender,
|
|
97
|
+
};
|
|
98
|
+
// ─── Legacy entry point ──────────────────────────────────────────────────────
|
|
99
|
+
/**
|
|
100
|
+
* Legacy bulk entry preserved for existing tests
|
|
101
|
+
* (tests/markdown-renderer.test.ts, tests/integration/integration-proof.test.ts).
|
|
102
|
+
* New code prefers the drift handler via `reconcileBeforeDispatch`. Matches the
|
|
103
|
+
* pre-ADR-017 behavior: silent per-entry error handling, returns the count of
|
|
104
|
+
* successful repairs.
|
|
105
|
+
*/
|
|
106
|
+
export async function repairStaleRenders(basePath) {
|
|
107
|
+
const drifts = detectStaleRenderDriftFromBasePath(basePath);
|
|
108
|
+
if (drifts.length === 0)
|
|
109
|
+
return 0;
|
|
110
|
+
let repaired = 0;
|
|
111
|
+
for (const drift of drifts) {
|
|
112
|
+
try {
|
|
113
|
+
await repairStaleRenderFromBasePath(drift, basePath);
|
|
114
|
+
repaired++;
|
|
115
|
+
}
|
|
116
|
+
catch (err) {
|
|
117
|
+
logWarning("renderer", `repair failed for ${drift.renderPath}: ${err.message}`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (repaired > 0) {
|
|
121
|
+
process.stderr.write(`markdown-renderer: repaired ${repaired} stale render(s)\n`);
|
|
122
|
+
}
|
|
123
|
+
return repaired;
|
|
124
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Project/App: GSD-2
|
|
2
|
+
// File Purpose: ADR-017 stale-worker drift handler. Detects session-lock
|
|
3
|
+
// artifacts whose owning PID is no longer alive (typical after SIGKILL or
|
|
4
|
+
// laptop sleep where the heartbeat wasn't released cleanly), and clears them
|
|
5
|
+
// before the next dispatch attempts to acquire the lock.
|
|
6
|
+
import { effectiveLockFile, isSessionLockProcessAlive, readSessionLockData, removeStaleSessionLock, } from "../../session-lock.js";
|
|
7
|
+
export function detectStaleWorkerDrift(_state, ctx) {
|
|
8
|
+
const data = readSessionLockData(ctx.basePath);
|
|
9
|
+
if (!data)
|
|
10
|
+
return [];
|
|
11
|
+
if (typeof data.pid !== "number")
|
|
12
|
+
return [];
|
|
13
|
+
if (isSessionLockProcessAlive(data))
|
|
14
|
+
return [];
|
|
15
|
+
return [
|
|
16
|
+
{
|
|
17
|
+
kind: "stale-worker",
|
|
18
|
+
lockPath: effectiveLockFile(),
|
|
19
|
+
pid: data.pid,
|
|
20
|
+
},
|
|
21
|
+
];
|
|
22
|
+
}
|
|
23
|
+
export function repairStaleWorker(_record, ctx) {
|
|
24
|
+
// removeStaleSessionLock is idempotent: it re-reads lock state and is a
|
|
25
|
+
// no-op when the lock is held by an alive process. Safe under cap=2 retry.
|
|
26
|
+
removeStaleSessionLock(ctx.basePath);
|
|
27
|
+
}
|
|
28
|
+
export const staleWorkerHandler = {
|
|
29
|
+
kind: "stale-worker",
|
|
30
|
+
detect: detectStaleWorkerDrift,
|
|
31
|
+
repair: repairStaleWorker,
|
|
32
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Project/App: GSD-2
|
|
2
|
+
// File Purpose: ADR-017 typed reconciliation failure for Recovery Classification.
|
|
3
|
+
/**
|
|
4
|
+
* Thrown by reconcileBeforeDispatch when:
|
|
5
|
+
* - one or more repair functions throw within a pass (`failures` populated), or
|
|
6
|
+
* - drift persists after the cap=2 lifecycle (`persistentDrift` populated).
|
|
7
|
+
*
|
|
8
|
+
* Recovery Classification recognizes this error via instanceof and maps it to
|
|
9
|
+
* failureKind "reconciliation-drift" with action "escalate".
|
|
10
|
+
*/
|
|
11
|
+
export class ReconciliationFailedError extends Error {
|
|
12
|
+
failures;
|
|
13
|
+
detectionFailures;
|
|
14
|
+
persistentDrift;
|
|
15
|
+
pass;
|
|
16
|
+
constructor(opts) {
|
|
17
|
+
super(formatMessage(opts));
|
|
18
|
+
this.name = "ReconciliationFailedError";
|
|
19
|
+
this.failures = opts.failures ?? [];
|
|
20
|
+
this.detectionFailures = opts.detectionFailures ?? [];
|
|
21
|
+
this.persistentDrift = opts.persistentDrift ?? [];
|
|
22
|
+
this.pass = opts.pass;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function formatMessage(opts) {
|
|
26
|
+
if (opts.detectionFailures && opts.detectionFailures.length > 0) {
|
|
27
|
+
const kinds = opts.detectionFailures.map((f) => f.handlerKind).join(", ");
|
|
28
|
+
const passSuffix = opts.pass !== undefined ? ` in pass ${opts.pass}` : "";
|
|
29
|
+
return `Reconciliation detect failed${passSuffix} for handlers: ${kinds}`;
|
|
30
|
+
}
|
|
31
|
+
if (opts.failures && opts.failures.length > 0) {
|
|
32
|
+
const kinds = opts.failures.map((f) => f.drift.kind).join(", ");
|
|
33
|
+
const passSuffix = opts.pass !== undefined ? ` in pass ${opts.pass}` : "";
|
|
34
|
+
return `Reconciliation repair failed${passSuffix} for drift kinds: ${kinds}`;
|
|
35
|
+
}
|
|
36
|
+
if (opts.persistentDrift && opts.persistentDrift.length > 0) {
|
|
37
|
+
const kinds = opts.persistentDrift.map((d) => d.kind).join(", ");
|
|
38
|
+
return `Reconciliation drift persisted after cap=2 passes: ${kinds}`;
|
|
39
|
+
}
|
|
40
|
+
return "Reconciliation failed";
|
|
41
|
+
}
|