gsd-pi 2.63.0 → 2.64.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 +46 -134
- package/dist/cli.js +48 -6
- package/dist/headless-query.js +11 -1
- package/dist/help-text.js +4 -1
- package/dist/onboarding.js +15 -8
- package/dist/resource-loader.js +18 -3
- package/dist/resources/extensions/cmux/index.js +21 -12
- package/dist/resources/extensions/gsd/auto/detect-stuck.js +27 -0
- package/dist/resources/extensions/gsd/auto/finalize-timeout.js +40 -0
- package/dist/resources/extensions/gsd/auto/loop.js +4 -0
- package/dist/resources/extensions/gsd/auto/phases.js +157 -22
- package/dist/resources/extensions/gsd/auto/session.js +12 -0
- package/dist/resources/extensions/gsd/auto-dashboard.js +9 -3
- package/dist/resources/extensions/gsd/auto-model-selection.js +32 -0
- package/dist/resources/extensions/gsd/auto-post-unit.js +124 -10
- package/dist/resources/extensions/gsd/auto-prompts.js +25 -0
- package/dist/resources/extensions/gsd/auto-recovery.js +15 -7
- package/dist/resources/extensions/gsd/auto-start.js +10 -21
- package/dist/resources/extensions/gsd/auto-timers.js +2 -1
- package/dist/resources/extensions/gsd/auto-tool-tracking.js +17 -0
- package/dist/resources/extensions/gsd/auto-worktree.js +13 -7
- package/dist/resources/extensions/gsd/auto.js +19 -2
- package/dist/resources/extensions/gsd/bootstrap/db-tools.js +147 -75
- package/dist/resources/extensions/gsd/bootstrap/dynamic-tools.js +13 -0
- package/dist/resources/extensions/gsd/bootstrap/query-tools.js +85 -0
- package/dist/resources/extensions/gsd/bootstrap/register-extension.js +3 -0
- package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +32 -1
- package/dist/resources/extensions/gsd/bootstrap/sanitize-complete-milestone.js +54 -0
- package/dist/resources/extensions/gsd/bootstrap/system-context.js +30 -2
- package/dist/resources/extensions/gsd/commands-handlers.js +9 -4
- package/dist/resources/extensions/gsd/constants.js +42 -0
- package/dist/resources/extensions/gsd/db-writer.js +72 -4
- package/dist/resources/extensions/gsd/forensics.js +20 -4
- package/dist/resources/extensions/gsd/gsd-db.js +64 -17
- package/dist/resources/extensions/gsd/guided-flow.js +19 -0
- package/dist/resources/extensions/gsd/metrics.js +27 -1
- package/dist/resources/extensions/gsd/native-git-bridge.js +5 -3
- package/dist/resources/extensions/gsd/preferences-types.js +2 -0
- package/dist/resources/extensions/gsd/preferences.js +7 -2
- package/dist/resources/extensions/gsd/prompt-loader.js +7 -0
- package/dist/resources/extensions/gsd/prompts/complete-milestone.md +2 -0
- package/dist/resources/extensions/gsd/prompts/complete-slice.md +2 -0
- package/dist/resources/extensions/gsd/prompts/doctor-heal.md +1 -0
- package/dist/resources/extensions/gsd/prompts/forensics.md +2 -0
- package/dist/resources/extensions/gsd/prompts/reassess-roadmap.md +2 -0
- package/dist/resources/extensions/gsd/prompts/system.md +4 -7
- package/dist/resources/extensions/gsd/prompts/validate-milestone.md +2 -0
- package/dist/resources/extensions/gsd/roadmap-mutations.js +1 -1
- package/dist/resources/extensions/gsd/roadmap-slices.js +9 -5
- package/dist/resources/extensions/gsd/safety/content-validator.js +73 -0
- package/dist/resources/extensions/gsd/safety/destructive-guard.js +34 -0
- package/dist/resources/extensions/gsd/safety/evidence-collector.js +109 -0
- package/dist/resources/extensions/gsd/safety/evidence-cross-ref.js +83 -0
- package/dist/resources/extensions/gsd/safety/file-change-validator.js +71 -0
- package/dist/resources/extensions/gsd/safety/git-checkpoint.js +91 -0
- package/dist/resources/extensions/gsd/safety/safety-harness.js +64 -0
- package/dist/resources/extensions/gsd/slice-parallel-conflict.js +67 -0
- package/dist/resources/extensions/gsd/slice-parallel-eligibility.js +51 -0
- package/dist/resources/extensions/gsd/slice-parallel-orchestrator.js +378 -0
- package/dist/resources/extensions/gsd/state.js +74 -14
- package/dist/resources/extensions/gsd/status-guards.js +11 -0
- package/dist/resources/extensions/gsd/tools/complete-milestone.js +17 -12
- package/dist/resources/extensions/gsd/tools/complete-slice.js +40 -26
- package/dist/resources/extensions/gsd/tools/complete-task.js +12 -12
- package/dist/resources/extensions/gsd/tools/plan-milestone.js +33 -25
- package/dist/resources/extensions/gsd/tools/plan-slice.js +5 -8
- package/dist/resources/extensions/gsd/workflow-projections.js +21 -5
- package/dist/resources/extensions/gsd/worktree-manager.js +82 -29
- package/dist/resources/extensions/gsd/worktree-resolver.js +4 -3
- package/dist/resources/extensions/mcp-client/auth.js +101 -0
- package/dist/resources/extensions/mcp-client/index.js +10 -1
- package/dist/resources/extensions/ollama/index.js +28 -22
- package/dist/resources/extensions/ollama/model-capabilities.js +37 -34
- package/dist/resources/extensions/ollama/ndjson-stream.js +54 -0
- package/dist/resources/extensions/ollama/ollama-chat-provider.js +380 -0
- package/dist/resources/extensions/ollama/ollama-client.js +23 -32
- package/dist/resources/extensions/ollama/ollama-discovery.js +2 -7
- package/dist/resources/extensions/ollama/ollama-tool.js +62 -0
- package/dist/resources/extensions/ollama/thinking-parser.js +104 -0
- package/dist/update-cmd.js +4 -2
- package/dist/web/standalone/.next/BUILD_ID +1 -1
- package/dist/web/standalone/.next/app-path-routes-manifest.json +12 -12
- package/dist/web/standalone/.next/build-manifest.json +2 -2
- package/dist/web/standalone/.next/prerender-manifest.json +3 -3
- package/dist/web/standalone/.next/server/app/_global-error.html +2 -2
- 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/api/boot/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/boot/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/bridge-terminal/input/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/bridge-terminal/input/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/bridge-terminal/resize/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/bridge-terminal/resize/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/bridge-terminal/stream/route.js +2 -2
- package/dist/web/standalone/.next/server/app/api/bridge-terminal/stream/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/captures/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/captures/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/cleanup/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/cleanup/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/doctor/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/doctor/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/export-data/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/export-data/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/files/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/files/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/forensics/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/forensics/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/git/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/git/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/history/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/history/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/hooks/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/hooks/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/inspect/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/inspect/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/knowledge/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/knowledge/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/live-state/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/live-state/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/onboarding/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/onboarding/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/projects/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/projects/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/recovery/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/recovery/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/session/browser/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/session/browser/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/session/command/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/session/command/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/session/events/route.js +2 -2
- package/dist/web/standalone/.next/server/app/api/session/events/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/session/manage/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/session/manage/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/settings-data/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/settings-data/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/skill-health/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/skill-health/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/steer/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/steer/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/switch-root/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/switch-root/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/terminal/sessions/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/terminal/sessions/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/terminal/stream/route.js +2 -2
- package/dist/web/standalone/.next/server/app/api/terminal/stream/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/undo/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/undo/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/visualizer/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/visualizer/route.js.nft.json +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 +12 -12
- package/dist/web/standalone/.next/server/chunks/6897.js +12 -0
- package/dist/web/standalone/.next/server/pages/404.html +1 -1
- package/dist/web/standalone/.next/server/pages/500.html +2 -2
- package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
- package/dist/welcome-screen.js +1 -1
- package/package.json +1 -1
- package/packages/pi-agent-core/dist/agent-loop.d.ts +8 -0
- package/packages/pi-agent-core/dist/agent-loop.d.ts.map +1 -1
- package/packages/pi-agent-core/dist/agent-loop.js +50 -0
- package/packages/pi-agent-core/dist/agent-loop.js.map +1 -1
- package/packages/pi-agent-core/src/agent-loop.test.ts +221 -5
- package/packages/pi-agent-core/src/agent-loop.ts +53 -0
- package/packages/pi-ai/dist/types.d.ts +16 -1
- package/packages/pi-ai/dist/types.d.ts.map +1 -1
- package/packages/pi-ai/dist/types.js.map +1 -1
- package/packages/pi-ai/src/types.ts +18 -1
- package/packages/pi-coding-agent/dist/core/auth-storage.d.ts +9 -0
- package/packages/pi-coding-agent/dist/core/auth-storage.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/auth-storage.js +50 -1
- package/packages/pi-coding-agent/dist/core/auth-storage.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/auth-storage.test.js +41 -0
- package/packages/pi-coding-agent/dist/core/auth-storage.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/loader.d.ts +7 -0
- package/packages/pi-coding-agent/dist/core/extensions/loader.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/loader.js +31 -4
- package/packages/pi-coding-agent/dist/core/extensions/loader.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/loader.test.js +28 -1
- package/packages/pi-coding-agent/dist/core/extensions/loader.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/provider-registration.test.d.ts +2 -0
- package/packages/pi-coding-agent/dist/core/extensions/provider-registration.test.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/core/extensions/provider-registration.test.js +46 -0
- package/packages/pi-coding-agent/dist/core/extensions/provider-registration.test.js.map +1 -0
- package/packages/pi-coding-agent/dist/core/extensions/types.d.ts +2 -0
- package/packages/pi-coding-agent/dist/core/extensions/types.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/types.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/model-registry.d.ts +1 -0
- package/packages/pi-coding-agent/dist/core/model-registry.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/model-registry.js +12 -0
- package/packages/pi-coding-agent/dist/core/model-registry.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/model-resolver.js +3 -3
- package/packages/pi-coding-agent/dist/core/model-resolver.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/resource-loader.d.ts +23 -1
- package/packages/pi-coding-agent/dist/core/resource-loader.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/resource-loader.js +80 -56
- package/packages/pi-coding-agent/dist/core/resource-loader.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/sdk.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/sdk.js +9 -0
- package/packages/pi-coding-agent/dist/core/sdk.js.map +1 -1
- package/packages/pi-coding-agent/package.json +1 -1
- package/packages/pi-coding-agent/src/core/auth-storage.test.ts +53 -0
- package/packages/pi-coding-agent/src/core/auth-storage.ts +66 -1
- package/packages/pi-coding-agent/src/core/extensions/loader.test.ts +39 -1
- package/packages/pi-coding-agent/src/core/extensions/loader.ts +34 -4
- package/packages/pi-coding-agent/src/core/extensions/provider-registration.test.ts +81 -0
- package/packages/pi-coding-agent/src/core/extensions/types.ts +2 -0
- package/packages/pi-coding-agent/src/core/model-registry.ts +14 -0
- package/packages/pi-coding-agent/src/core/model-resolver.ts +3 -3
- package/packages/pi-coding-agent/src/core/resource-loader.ts +89 -56
- package/packages/pi-coding-agent/src/core/sdk.ts +10 -0
- package/pkg/package.json +1 -1
- package/src/resources/extensions/cmux/index.ts +18 -12
- package/src/resources/extensions/gsd/auto/detect-stuck.ts +27 -0
- package/src/resources/extensions/gsd/auto/finalize-timeout.ts +46 -0
- package/src/resources/extensions/gsd/auto/loop.ts +5 -0
- package/src/resources/extensions/gsd/auto/phases.ts +194 -33
- package/src/resources/extensions/gsd/auto/session.ts +14 -0
- package/src/resources/extensions/gsd/auto-dashboard.ts +11 -3
- package/src/resources/extensions/gsd/auto-model-selection.ts +36 -0
- package/src/resources/extensions/gsd/auto-post-unit.ts +141 -12
- package/src/resources/extensions/gsd/auto-prompts.ts +21 -0
- package/src/resources/extensions/gsd/auto-recovery.ts +9 -8
- package/src/resources/extensions/gsd/auto-start.ts +11 -20
- package/src/resources/extensions/gsd/auto-timers.ts +2 -1
- package/src/resources/extensions/gsd/auto-tool-tracking.ts +19 -0
- package/src/resources/extensions/gsd/auto-worktree.ts +14 -6
- package/src/resources/extensions/gsd/auto.ts +22 -1
- package/src/resources/extensions/gsd/bootstrap/db-tools.ts +160 -88
- package/src/resources/extensions/gsd/bootstrap/dynamic-tools.ts +15 -0
- package/src/resources/extensions/gsd/bootstrap/query-tools.ts +98 -0
- package/src/resources/extensions/gsd/bootstrap/register-extension.ts +4 -0
- package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +36 -1
- package/src/resources/extensions/gsd/bootstrap/sanitize-complete-milestone.ts +57 -0
- package/src/resources/extensions/gsd/bootstrap/system-context.ts +31 -2
- package/src/resources/extensions/gsd/commands-handlers.ts +10 -4
- package/src/resources/extensions/gsd/constants.ts +44 -0
- package/src/resources/extensions/gsd/db-writer.ts +78 -4
- package/src/resources/extensions/gsd/forensics.ts +21 -5
- package/src/resources/extensions/gsd/gsd-db.ts +64 -17
- package/src/resources/extensions/gsd/guided-flow.ts +22 -0
- package/src/resources/extensions/gsd/metrics.ts +28 -1
- package/src/resources/extensions/gsd/native-git-bridge.ts +5 -3
- package/src/resources/extensions/gsd/preferences-types.ts +16 -0
- package/src/resources/extensions/gsd/preferences.ts +9 -2
- package/src/resources/extensions/gsd/prompt-loader.ts +8 -0
- package/src/resources/extensions/gsd/prompts/complete-milestone.md +2 -0
- package/src/resources/extensions/gsd/prompts/complete-slice.md +2 -0
- package/src/resources/extensions/gsd/prompts/doctor-heal.md +1 -0
- package/src/resources/extensions/gsd/prompts/forensics.md +2 -0
- package/src/resources/extensions/gsd/prompts/reassess-roadmap.md +2 -0
- package/src/resources/extensions/gsd/prompts/system.md +4 -7
- package/src/resources/extensions/gsd/prompts/validate-milestone.md +2 -0
- package/src/resources/extensions/gsd/roadmap-mutations.ts +1 -1
- package/src/resources/extensions/gsd/roadmap-slices.ts +10 -5
- package/src/resources/extensions/gsd/safety/content-validator.ts +98 -0
- package/src/resources/extensions/gsd/safety/destructive-guard.ts +49 -0
- package/src/resources/extensions/gsd/safety/evidence-collector.ts +151 -0
- package/src/resources/extensions/gsd/safety/evidence-cross-ref.ts +120 -0
- package/src/resources/extensions/gsd/safety/file-change-validator.ts +108 -0
- package/src/resources/extensions/gsd/safety/git-checkpoint.ts +106 -0
- package/src/resources/extensions/gsd/safety/safety-harness.ts +105 -0
- package/src/resources/extensions/gsd/slice-parallel-conflict.ts +86 -0
- package/src/resources/extensions/gsd/slice-parallel-eligibility.ts +73 -0
- package/src/resources/extensions/gsd/slice-parallel-orchestrator.ts +477 -0
- package/src/resources/extensions/gsd/state.ts +67 -12
- package/src/resources/extensions/gsd/status-guards.ts +13 -0
- package/src/resources/extensions/gsd/tests/artifact-corruption-2630.test.ts +288 -0
- package/src/resources/extensions/gsd/tests/auto-loop.test.ts +34 -13
- package/src/resources/extensions/gsd/tests/cmux.test.ts +58 -0
- package/src/resources/extensions/gsd/tests/cold-resume-db-reopen.test.ts +51 -0
- package/src/resources/extensions/gsd/tests/complete-milestone.test.ts +140 -0
- package/src/resources/extensions/gsd/tests/complete-slice-string-coercion.test.ts +211 -0
- package/src/resources/extensions/gsd/tests/complete-task.test.ts +39 -0
- package/src/resources/extensions/gsd/tests/dashboard-model-label-ordering.test.ts +107 -0
- package/src/resources/extensions/gsd/tests/db-access-guardrails.test.ts +109 -0
- package/src/resources/extensions/gsd/tests/db-path-worktree-symlink.test.ts +13 -9
- package/src/resources/extensions/gsd/tests/db-writer.test.ts +134 -0
- package/src/resources/extensions/gsd/tests/deferred-slice-dispatch.test.ts +203 -0
- package/src/resources/extensions/gsd/tests/discuss-tool-scoping.test.ts +130 -0
- package/src/resources/extensions/gsd/tests/doctor-fix-flag.test.ts +92 -0
- package/src/resources/extensions/gsd/tests/finalize-timeout-guard.test.ts +116 -0
- package/src/resources/extensions/gsd/tests/flat-rate-routing-guard.test.ts +50 -0
- package/src/resources/extensions/gsd/tests/forensics-stuck-loops.test.ts +103 -0
- package/src/resources/extensions/gsd/tests/git-checkpoint.test.ts +94 -0
- package/src/resources/extensions/gsd/tests/insert-slice-no-wipe.test.ts +88 -0
- package/src/resources/extensions/gsd/tests/integration/git-service.test.ts +27 -7
- package/src/resources/extensions/gsd/tests/integration/idle-recovery.test.ts +34 -0
- package/src/resources/extensions/gsd/tests/metrics.test.ts +116 -1
- package/src/resources/extensions/gsd/tests/milestone-status-tool.test.ts +201 -0
- package/src/resources/extensions/gsd/tests/plan-milestone-title.test.ts +2 -1
- package/src/resources/extensions/gsd/tests/plan-milestone.test.ts +82 -18
- package/src/resources/extensions/gsd/tests/preferences.test.ts +10 -0
- package/src/resources/extensions/gsd/tests/prompt-contracts.test.ts +25 -0
- package/src/resources/extensions/gsd/tests/roadmap-slices.test.ts +69 -0
- package/src/resources/extensions/gsd/tests/shared-wal.test.ts +30 -0
- package/src/resources/extensions/gsd/tests/slice-context-injection.test.ts +50 -0
- package/src/resources/extensions/gsd/tests/slice-parallel-conflict.test.ts +92 -0
- package/src/resources/extensions/gsd/tests/slice-parallel-eligibility.test.ts +95 -0
- package/src/resources/extensions/gsd/tests/slice-parallel-orchestrator.test.ts +83 -0
- package/src/resources/extensions/gsd/tests/stuck-detection-coverage.test.ts +42 -0
- package/src/resources/extensions/gsd/tests/tool-invocation-error-loop-break.test.ts +103 -0
- package/src/resources/extensions/gsd/tests/tool-param-optionality.test.ts +349 -0
- package/src/resources/extensions/gsd/tests/worktree-health-dispatch.test.ts +35 -2
- package/src/resources/extensions/gsd/tests/worktree-health-monorepo.test.ts +73 -0
- package/src/resources/extensions/gsd/tests/worktree-resolver.test.ts +34 -0
- package/src/resources/extensions/gsd/tests/worktree-submodule-safety.test.ts +1 -1
- package/src/resources/extensions/gsd/tests/worktree-teardown-safety.test.ts +148 -0
- package/src/resources/extensions/gsd/tools/complete-milestone.ts +34 -20
- package/src/resources/extensions/gsd/tools/complete-slice.ts +41 -26
- package/src/resources/extensions/gsd/tools/complete-task.ts +12 -12
- package/src/resources/extensions/gsd/tools/plan-milestone.ts +55 -30
- package/src/resources/extensions/gsd/tools/plan-slice.ts +13 -8
- package/src/resources/extensions/gsd/types.ts +44 -22
- package/src/resources/extensions/gsd/workflow-logger.ts +2 -1
- package/src/resources/extensions/gsd/workflow-projections.ts +23 -5
- package/src/resources/extensions/gsd/worktree-manager.ts +76 -28
- package/src/resources/extensions/gsd/worktree-resolver.ts +4 -3
- package/src/resources/extensions/mcp-client/auth.ts +149 -0
- package/src/resources/extensions/mcp-client/index.ts +16 -1
- package/src/resources/extensions/ollama/index.ts +26 -25
- package/src/resources/extensions/ollama/model-capabilities.ts +41 -34
- package/src/resources/extensions/ollama/ndjson-stream.ts +63 -0
- package/src/resources/extensions/ollama/ollama-auth-mode.test.ts +20 -0
- package/src/resources/extensions/ollama/ollama-chat-provider.ts +459 -0
- package/src/resources/extensions/ollama/ollama-client.ts +30 -30
- package/src/resources/extensions/ollama/ollama-discovery.ts +5 -8
- package/src/resources/extensions/ollama/ollama-tool.ts +69 -0
- package/src/resources/extensions/ollama/tests/ollama-chat-provider-stream.test.ts +82 -0
- package/src/resources/extensions/ollama/tests/ollama-discovery.test.ts +0 -27
- package/src/resources/extensions/ollama/thinking-parser.ts +116 -0
- package/src/resources/extensions/ollama/types.ts +23 -0
- package/dist/web/standalone/.next/server/chunks/2229.js +0 -12
- /package/dist/web/standalone/.next/static/{5FLUBNdqolRyyehCyChPd → eebXKteM9EaWyseHKTjqp}/_buildManifest.js +0 -0
- /package/dist/web/standalone/.next/static/{5FLUBNdqolRyyehCyChPd → eebXKteM9EaWyseHKTjqp}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pre-unit git checkpoint and rollback for auto-mode safety harness.
|
|
3
|
+
* Uses the existing refs/gsd/ namespace (already pruned by doctor).
|
|
4
|
+
*
|
|
5
|
+
* Creates a lightweight ref at HEAD before unit execution. On failure,
|
|
6
|
+
* the ref can be used to rollback the branch to the pre-unit state.
|
|
7
|
+
*
|
|
8
|
+
* Copyright (c) 2026 Jeremy McSpadden <jeremy@fluxlabs.net>
|
|
9
|
+
*/
|
|
10
|
+
import { execFileSync } from "node:child_process";
|
|
11
|
+
import { logWarning } from "../workflow-logger.js";
|
|
12
|
+
// ─── Constants ──────────────────────────────────────────────────────────────
|
|
13
|
+
const CHECKPOINT_PREFIX = "refs/gsd/checkpoints/";
|
|
14
|
+
// ─── Public API ─────────────────────────────────────────────────────────────
|
|
15
|
+
/**
|
|
16
|
+
* Create a checkpoint ref at the current HEAD for the given unit.
|
|
17
|
+
* Returns the SHA of HEAD, or null if the operation fails.
|
|
18
|
+
*/
|
|
19
|
+
export function createCheckpoint(basePath, unitId) {
|
|
20
|
+
try {
|
|
21
|
+
const sha = execFileSync("git", ["rev-parse", "HEAD"], {
|
|
22
|
+
cwd: basePath,
|
|
23
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
24
|
+
encoding: "utf-8",
|
|
25
|
+
}).trim();
|
|
26
|
+
if (!sha || sha.length < 7)
|
|
27
|
+
return null;
|
|
28
|
+
// Sanitize unitId for use in ref path (replace / with -)
|
|
29
|
+
const safeUnitId = unitId.replace(/\//g, "-");
|
|
30
|
+
execFileSync("git", ["update-ref", `${CHECKPOINT_PREFIX}${safeUnitId}`, sha], {
|
|
31
|
+
cwd: basePath,
|
|
32
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
33
|
+
});
|
|
34
|
+
return sha;
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
logWarning("safety", `checkpoint creation failed: ${e.message}`);
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Rollback the current branch to a checkpoint SHA.
|
|
43
|
+
* Returns true on success, false on failure.
|
|
44
|
+
*
|
|
45
|
+
* WARNING: This is a destructive operation — it discards all changes
|
|
46
|
+
* since the checkpoint. Only call when the user has opted in via
|
|
47
|
+
* safety_harness.auto_rollback or an explicit manual trigger.
|
|
48
|
+
*/
|
|
49
|
+
export function rollbackToCheckpoint(basePath, unitId, sha) {
|
|
50
|
+
try {
|
|
51
|
+
// Get current branch name
|
|
52
|
+
const branch = execFileSync("git", ["rev-parse", "--abbrev-ref", "HEAD"], {
|
|
53
|
+
cwd: basePath,
|
|
54
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
55
|
+
encoding: "utf-8",
|
|
56
|
+
}).trim();
|
|
57
|
+
if (!branch || branch === "HEAD") {
|
|
58
|
+
logWarning("safety", "rollback: detached HEAD state, cannot rollback");
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
// Reset branch pointer and working tree to checkpoint SHA in one step.
|
|
62
|
+
// Using `git reset --hard <sha>` works on the currently checked-out branch
|
|
63
|
+
// (unlike `git branch -f` which is rejected for checked-out branches).
|
|
64
|
+
execFileSync("git", ["reset", "--hard", sha], {
|
|
65
|
+
cwd: basePath,
|
|
66
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
67
|
+
});
|
|
68
|
+
// Cleanup checkpoint ref
|
|
69
|
+
cleanupCheckpoint(basePath, unitId);
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
logWarning("safety", `rollback failed: ${e.message}`);
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Remove a checkpoint ref after successful unit completion.
|
|
79
|
+
*/
|
|
80
|
+
export function cleanupCheckpoint(basePath, unitId) {
|
|
81
|
+
try {
|
|
82
|
+
const safeUnitId = unitId.replace(/\//g, "-");
|
|
83
|
+
execFileSync("git", ["update-ref", "-d", `${CHECKPOINT_PREFIX}${safeUnitId}`], {
|
|
84
|
+
cwd: basePath,
|
|
85
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
// Non-fatal — ref may already have been cleaned up
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safety Harness — central module for LLM damage control during auto-mode.
|
|
3
|
+
* Provides types, preference resolution, and orchestration for all safety components.
|
|
4
|
+
*
|
|
5
|
+
* Components:
|
|
6
|
+
* - evidence-collector.ts: Real-time tool call tracking
|
|
7
|
+
* - destructive-guard.ts: Bash command classification
|
|
8
|
+
* - file-change-validator.ts: Post-unit git diff vs plan
|
|
9
|
+
* - evidence-cross-ref.ts: Claimed vs actual verification evidence
|
|
10
|
+
* - git-checkpoint.ts: Pre-unit checkpoints + rollback
|
|
11
|
+
* - content-validator.ts: Output quality validation
|
|
12
|
+
*
|
|
13
|
+
* Copyright (c) 2026 Jeremy McSpadden <jeremy@fluxlabs.net>
|
|
14
|
+
*/
|
|
15
|
+
// ─── Defaults ───────────────────────────────────────────────────────────────
|
|
16
|
+
const DEFAULTS = {
|
|
17
|
+
enabled: true,
|
|
18
|
+
evidence_collection: true,
|
|
19
|
+
file_change_validation: true,
|
|
20
|
+
evidence_cross_reference: true,
|
|
21
|
+
destructive_command_warnings: true,
|
|
22
|
+
content_validation: true,
|
|
23
|
+
checkpoints: true,
|
|
24
|
+
auto_rollback: false,
|
|
25
|
+
timeout_scale_cap: 6,
|
|
26
|
+
};
|
|
27
|
+
// ─── Public API ─────────────────────────────────────────────────────────────
|
|
28
|
+
/**
|
|
29
|
+
* Resolve safety harness configuration from raw preferences.
|
|
30
|
+
* Missing fields fall back to defaults.
|
|
31
|
+
*/
|
|
32
|
+
export function resolveSafetyHarnessConfig(raw) {
|
|
33
|
+
if (!raw)
|
|
34
|
+
return { ...DEFAULTS };
|
|
35
|
+
return {
|
|
36
|
+
enabled: typeof raw.enabled === "boolean" ? raw.enabled : DEFAULTS.enabled,
|
|
37
|
+
evidence_collection: typeof raw.evidence_collection === "boolean" ? raw.evidence_collection : DEFAULTS.evidence_collection,
|
|
38
|
+
file_change_validation: typeof raw.file_change_validation === "boolean" ? raw.file_change_validation : DEFAULTS.file_change_validation,
|
|
39
|
+
evidence_cross_reference: typeof raw.evidence_cross_reference === "boolean" ? raw.evidence_cross_reference : DEFAULTS.evidence_cross_reference,
|
|
40
|
+
destructive_command_warnings: typeof raw.destructive_command_warnings === "boolean" ? raw.destructive_command_warnings : DEFAULTS.destructive_command_warnings,
|
|
41
|
+
content_validation: typeof raw.content_validation === "boolean" ? raw.content_validation : DEFAULTS.content_validation,
|
|
42
|
+
checkpoints: typeof raw.checkpoints === "boolean" ? raw.checkpoints : DEFAULTS.checkpoints,
|
|
43
|
+
auto_rollback: typeof raw.auto_rollback === "boolean" ? raw.auto_rollback : DEFAULTS.auto_rollback,
|
|
44
|
+
timeout_scale_cap: typeof raw.timeout_scale_cap === "number" ? raw.timeout_scale_cap : DEFAULTS.timeout_scale_cap,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Check if the safety harness is enabled.
|
|
49
|
+
* Used as a fast gate at hook registration and phase integration points.
|
|
50
|
+
*/
|
|
51
|
+
export function isHarnessEnabled(raw) {
|
|
52
|
+
if (!raw)
|
|
53
|
+
return DEFAULTS.enabled;
|
|
54
|
+
if (typeof raw.enabled === "boolean")
|
|
55
|
+
return raw.enabled;
|
|
56
|
+
return DEFAULTS.enabled;
|
|
57
|
+
}
|
|
58
|
+
// ─── Re-exports ─────────────────────────────────────────────────────────────
|
|
59
|
+
export { resetEvidence, getEvidence, getBashEvidence, getFilePaths, recordToolCall, recordToolResult, } from "./evidence-collector.js";
|
|
60
|
+
export { classifyCommand } from "./destructive-guard.js";
|
|
61
|
+
export { validateFileChanges } from "./file-change-validator.js";
|
|
62
|
+
export { crossReferenceEvidence } from "./evidence-cross-ref.js";
|
|
63
|
+
export { createCheckpoint, rollbackToCheckpoint, cleanupCheckpoint } from "./git-checkpoint.js";
|
|
64
|
+
export { validateContent } from "./content-validator.js";
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GSD Slice Parallel Conflict Detection — File overlap analysis between slices.
|
|
3
|
+
*
|
|
4
|
+
* Reads PLAN.md for each slice and extracts file paths mentioned in task
|
|
5
|
+
* descriptions. If two slices share more than 5 file paths, they are considered
|
|
6
|
+
* conflicting and should not run in parallel.
|
|
7
|
+
*
|
|
8
|
+
* Conservative by default: missing PLAN = block parallel execution.
|
|
9
|
+
*/
|
|
10
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
// ─── File Path Extraction ─────────────────────────────────────────────────────
|
|
13
|
+
/**
|
|
14
|
+
* Extract file paths from a PLAN.md content string.
|
|
15
|
+
* Matches common patterns like `src/...`, `lib/...`, paths with extensions.
|
|
16
|
+
*/
|
|
17
|
+
function extractFilePaths(content) {
|
|
18
|
+
const paths = new Set();
|
|
19
|
+
// Match file-like patterns: word/word paths with extensions, or src/lib/etc prefixed paths
|
|
20
|
+
const patterns = [
|
|
21
|
+
// Paths like src/foo/bar.ts, lib/utils.js, etc.
|
|
22
|
+
/(?:src|lib|test|tests|app|pkg|cmd|internal|components|pages|api|utils|config|scripts|dist|build)\/[\w./-]+\.\w+/g,
|
|
23
|
+
// Generic path with at least one slash and extension
|
|
24
|
+
/(?<!\w)[\w-]+\/[\w./-]+\.\w{1,5}(?!\w)/g,
|
|
25
|
+
];
|
|
26
|
+
for (const pattern of patterns) {
|
|
27
|
+
const matches = content.matchAll(pattern);
|
|
28
|
+
for (const match of matches) {
|
|
29
|
+
paths.add(match[0]);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return paths;
|
|
33
|
+
}
|
|
34
|
+
// ─── Conflict Detection ──────────────────────────────────────────────────────
|
|
35
|
+
/**
|
|
36
|
+
* Check if two slices have file conflicts that would block parallel execution.
|
|
37
|
+
*
|
|
38
|
+
* @param basePath Project root path.
|
|
39
|
+
* @param mid Milestone ID.
|
|
40
|
+
* @param sliceA First slice ID.
|
|
41
|
+
* @param sliceB Second slice ID.
|
|
42
|
+
* @returns true if parallel is unsafe (>5 shared files or missing plan).
|
|
43
|
+
*/
|
|
44
|
+
export function hasFileConflict(basePath, mid, sliceA, sliceB) {
|
|
45
|
+
const planPathA = join(basePath, ".gsd", "milestones", mid, sliceA, "PLAN.md");
|
|
46
|
+
const planPathB = join(basePath, ".gsd", "milestones", mid, sliceB, "PLAN.md");
|
|
47
|
+
// Conservative: missing PLAN = block
|
|
48
|
+
if (!existsSync(planPathA) || !existsSync(planPathB)) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
const contentA = readFileSync(planPathA, "utf-8");
|
|
52
|
+
const contentB = readFileSync(planPathB, "utf-8");
|
|
53
|
+
const filesA = extractFilePaths(contentA);
|
|
54
|
+
const filesB = extractFilePaths(contentB);
|
|
55
|
+
// If either has no files extracted, no conflict detectable → allow
|
|
56
|
+
if (filesA.size === 0 || filesB.size === 0) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
// Count shared files
|
|
60
|
+
let sharedCount = 0;
|
|
61
|
+
for (const file of filesA) {
|
|
62
|
+
if (filesB.has(file)) {
|
|
63
|
+
sharedCount++;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return sharedCount > 5;
|
|
67
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GSD Slice Parallel Eligibility — Pure function to determine which slices
|
|
3
|
+
* within a milestone can run in parallel based on dependency satisfaction.
|
|
4
|
+
*
|
|
5
|
+
* This is the slice-level equivalent of parallel-eligibility.ts (which operates
|
|
6
|
+
* at milestone scope). The key difference is the positional fallback: slices
|
|
7
|
+
* without explicit dependencies use sequential ordering as an implicit constraint.
|
|
8
|
+
*/
|
|
9
|
+
// ─── Core Logic ───────────────────────────────────────────────────────────────
|
|
10
|
+
/**
|
|
11
|
+
* Determine which slices are eligible for parallel execution.
|
|
12
|
+
*
|
|
13
|
+
* Rules:
|
|
14
|
+
* 1. Done slices are never eligible (nothing to do).
|
|
15
|
+
* 2. A slice with explicit `depends` entries is eligible when ALL deps
|
|
16
|
+
* appear in `completedSliceIds`.
|
|
17
|
+
* 3. A slice with NO `depends` entries uses positional fallback: it is
|
|
18
|
+
* eligible only when every positionally-earlier slice is done.
|
|
19
|
+
* This preserves backward compatibility with roadmaps that don't
|
|
20
|
+
* declare inter-slice dependencies.
|
|
21
|
+
*
|
|
22
|
+
* @param slices All slices in the milestone (ordered by position).
|
|
23
|
+
* @param completedSliceIds Set of slice IDs that are already complete.
|
|
24
|
+
* @returns Array of eligible slice descriptors.
|
|
25
|
+
*/
|
|
26
|
+
export function getEligibleSlices(slices, completedSliceIds) {
|
|
27
|
+
const eligible = [];
|
|
28
|
+
for (let i = 0; i < slices.length; i++) {
|
|
29
|
+
const slice = slices[i];
|
|
30
|
+
// Rule 1: skip done slices
|
|
31
|
+
if (slice.done)
|
|
32
|
+
continue;
|
|
33
|
+
const hasExplicitDeps = slice.depends.length > 0;
|
|
34
|
+
if (hasExplicitDeps) {
|
|
35
|
+
// Rule 2: explicit dependencies — all must be satisfied
|
|
36
|
+
const allDepsSatisfied = slice.depends.every(dep => completedSliceIds.has(dep));
|
|
37
|
+
if (allDepsSatisfied) {
|
|
38
|
+
eligible.push({ id: slice.id });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
// Rule 3: no deps declared — positional fallback
|
|
43
|
+
// Eligible only if all positionally-earlier slices are done
|
|
44
|
+
const allEarlierDone = slices.slice(0, i).every(earlier => earlier.done || completedSliceIds.has(earlier.id));
|
|
45
|
+
if (allEarlierDone) {
|
|
46
|
+
eligible.push({ id: slice.id });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return eligible;
|
|
51
|
+
}
|
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GSD Slice Parallel Orchestrator — Engine for parallel slice execution
|
|
3
|
+
* within a single milestone.
|
|
4
|
+
*
|
|
5
|
+
* Mirrors the existing parallel-orchestrator.ts pattern at slice scope
|
|
6
|
+
* instead of milestone scope. Workers are separate processes spawned via
|
|
7
|
+
* child_process, each running in its own git worktree with GSD_SLICE_LOCK
|
|
8
|
+
* + GSD_MILESTONE_LOCK env vars set.
|
|
9
|
+
*
|
|
10
|
+
* Key differences from milestone-level parallelism:
|
|
11
|
+
* - Scope: slices within one milestone, not milestones within a project
|
|
12
|
+
* - Lock env: GSD_SLICE_LOCK (in addition to GSD_MILESTONE_LOCK)
|
|
13
|
+
* - Conflict check: file overlap between slice plans (slice-parallel-conflict.ts)
|
|
14
|
+
*/
|
|
15
|
+
import { spawn } from "node:child_process";
|
|
16
|
+
import { appendFileSync, existsSync, mkdirSync, } from "node:fs";
|
|
17
|
+
import { join, dirname } from "node:path";
|
|
18
|
+
import { fileURLToPath } from "node:url";
|
|
19
|
+
import { gsdRoot } from "./paths.js";
|
|
20
|
+
import { createWorktree, worktreePath, removeWorktree } from "./worktree-manager.js";
|
|
21
|
+
import { writeSessionStatus, } from "./session-status-io.js";
|
|
22
|
+
import { hasFileConflict } from "./slice-parallel-conflict.js";
|
|
23
|
+
import { getErrorMessage } from "./error-utils.js";
|
|
24
|
+
// ─── Module State ──────────────────────────────────────────────────────────
|
|
25
|
+
let sliceState = null;
|
|
26
|
+
// ─── Public API ────────────────────────────────────────────────────────────
|
|
27
|
+
/**
|
|
28
|
+
* Check whether slice-level parallel is currently active.
|
|
29
|
+
*/
|
|
30
|
+
export function isSliceParallelActive() {
|
|
31
|
+
return sliceState?.active === true;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Get current slice orchestrator state (read-only snapshot).
|
|
35
|
+
*/
|
|
36
|
+
export function getSliceOrchestratorState() {
|
|
37
|
+
return sliceState;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Start parallel execution for eligible slices within a milestone.
|
|
41
|
+
*
|
|
42
|
+
* For each eligible slice: create a worktree, spawn `gsd --mode json --print "/gsd auto"`
|
|
43
|
+
* with env GSD_SLICE_LOCK=<SID> + GSD_MILESTONE_LOCK=<MID> + GSD_PARALLEL_WORKER=1.
|
|
44
|
+
*/
|
|
45
|
+
export async function startSliceParallel(basePath, milestoneId, eligibleSlices, opts = {}) {
|
|
46
|
+
// Prevent nesting: if already a parallel worker, refuse
|
|
47
|
+
if (process.env.GSD_PARALLEL_WORKER) {
|
|
48
|
+
return { started: [], errors: [{ sid: "all", error: "Cannot start slice-parallel from within a parallel worker" }] };
|
|
49
|
+
}
|
|
50
|
+
const maxWorkers = opts.maxWorkers ?? 2;
|
|
51
|
+
const budgetCeiling = opts.budgetCeiling;
|
|
52
|
+
// Initialize orchestrator state
|
|
53
|
+
sliceState = {
|
|
54
|
+
active: true,
|
|
55
|
+
workers: new Map(),
|
|
56
|
+
totalCost: 0,
|
|
57
|
+
budgetCeiling,
|
|
58
|
+
maxWorkers,
|
|
59
|
+
startedAt: Date.now(),
|
|
60
|
+
basePath,
|
|
61
|
+
};
|
|
62
|
+
const started = [];
|
|
63
|
+
const errors = [];
|
|
64
|
+
// Filter out conflicting slices (conservative: check all pairs)
|
|
65
|
+
const safeSlices = filterConflictingSlices(basePath, milestoneId, eligibleSlices);
|
|
66
|
+
// Limit to maxWorkers
|
|
67
|
+
const toSpawn = safeSlices.slice(0, maxWorkers);
|
|
68
|
+
for (const slice of toSpawn) {
|
|
69
|
+
try {
|
|
70
|
+
// Create worktree for this slice
|
|
71
|
+
const wtBranch = `slice/${milestoneId}/${slice.id}`;
|
|
72
|
+
const wtName = `${milestoneId}-${slice.id}`;
|
|
73
|
+
const wtPath = worktreePath(basePath, wtName);
|
|
74
|
+
if (!existsSync(wtPath)) {
|
|
75
|
+
createWorktree(basePath, wtName, { branch: wtBranch });
|
|
76
|
+
}
|
|
77
|
+
// Create worker info
|
|
78
|
+
const worker = {
|
|
79
|
+
milestoneId,
|
|
80
|
+
sliceId: slice.id,
|
|
81
|
+
pid: 0,
|
|
82
|
+
process: null,
|
|
83
|
+
worktreePath: wtPath,
|
|
84
|
+
startedAt: Date.now(),
|
|
85
|
+
state: "running",
|
|
86
|
+
completedUnits: 0,
|
|
87
|
+
cost: 0,
|
|
88
|
+
};
|
|
89
|
+
sliceState.workers.set(slice.id, worker);
|
|
90
|
+
// Spawn worker
|
|
91
|
+
const spawned = spawnSliceWorker(basePath, milestoneId, slice.id);
|
|
92
|
+
if (spawned) {
|
|
93
|
+
started.push(slice.id);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
errors.push({ sid: slice.id, error: "Failed to spawn worker process" });
|
|
97
|
+
worker.state = "error";
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
errors.push({ sid: slice.id, error: getErrorMessage(err) });
|
|
102
|
+
// Best-effort cleanup of partially created worktree
|
|
103
|
+
const wtName = `${milestoneId}-${slice.id}`;
|
|
104
|
+
try {
|
|
105
|
+
removeWorktree(basePath, wtName, { deleteBranch: true, force: true });
|
|
106
|
+
}
|
|
107
|
+
catch { /* ignore cleanup failures */ }
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// If nothing started, deactivate
|
|
111
|
+
if (started.length === 0) {
|
|
112
|
+
sliceState.active = false;
|
|
113
|
+
}
|
|
114
|
+
return { started, errors };
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Stop all slice-parallel workers and deactivate.
|
|
118
|
+
*/
|
|
119
|
+
export function stopSliceParallel() {
|
|
120
|
+
if (!sliceState)
|
|
121
|
+
return;
|
|
122
|
+
for (const worker of sliceState.workers.values()) {
|
|
123
|
+
if (worker.process) {
|
|
124
|
+
try {
|
|
125
|
+
worker.process.kill("SIGTERM");
|
|
126
|
+
}
|
|
127
|
+
catch { /* already dead */ }
|
|
128
|
+
}
|
|
129
|
+
worker.cleanup?.();
|
|
130
|
+
worker.cleanup = undefined;
|
|
131
|
+
worker.process = null;
|
|
132
|
+
worker.state = "stopped";
|
|
133
|
+
// Clean up worktree created for this worker
|
|
134
|
+
const wtName = `${worker.milestoneId}-${worker.sliceId}`;
|
|
135
|
+
try {
|
|
136
|
+
removeWorktree(sliceState.basePath, wtName, { deleteBranch: true, force: true });
|
|
137
|
+
}
|
|
138
|
+
catch { /* best-effort cleanup */ }
|
|
139
|
+
}
|
|
140
|
+
sliceState.active = false;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Get aggregate cost across all slice workers.
|
|
144
|
+
*/
|
|
145
|
+
export function getSliceAggregateCost() {
|
|
146
|
+
if (!sliceState)
|
|
147
|
+
return 0;
|
|
148
|
+
let total = 0;
|
|
149
|
+
for (const w of sliceState.workers.values()) {
|
|
150
|
+
total += w.cost;
|
|
151
|
+
}
|
|
152
|
+
return total;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Check if budget ceiling has been exceeded.
|
|
156
|
+
*/
|
|
157
|
+
export function isSliceBudgetExceeded() {
|
|
158
|
+
if (!sliceState?.budgetCeiling)
|
|
159
|
+
return false;
|
|
160
|
+
return getSliceAggregateCost() >= sliceState.budgetCeiling;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Reset module state (for testing).
|
|
164
|
+
*/
|
|
165
|
+
export function resetSliceOrchestrator() {
|
|
166
|
+
if (sliceState) {
|
|
167
|
+
for (const w of sliceState.workers.values()) {
|
|
168
|
+
w.cleanup?.();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
sliceState = null;
|
|
172
|
+
}
|
|
173
|
+
// ─── Internal: Conflict Filtering ──────────────────────────────────────────
|
|
174
|
+
/**
|
|
175
|
+
* Remove slices that have file conflicts with each other.
|
|
176
|
+
* Greedy: add slices to the safe set in order; skip any that conflict
|
|
177
|
+
* with an already-included slice.
|
|
178
|
+
*/
|
|
179
|
+
function filterConflictingSlices(basePath, milestoneId, slices) {
|
|
180
|
+
const safe = [];
|
|
181
|
+
for (const candidate of slices) {
|
|
182
|
+
let conflictsWithSafe = false;
|
|
183
|
+
for (const existing of safe) {
|
|
184
|
+
if (hasFileConflict(basePath, milestoneId, candidate.id, existing.id)) {
|
|
185
|
+
conflictsWithSafe = true;
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
if (!conflictsWithSafe) {
|
|
190
|
+
safe.push(candidate);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return safe;
|
|
194
|
+
}
|
|
195
|
+
// ─── Internal: Worker Spawning ─────────────────────────────────────────────
|
|
196
|
+
/**
|
|
197
|
+
* Resolve the GSD CLI binary path.
|
|
198
|
+
* Same logic as parallel-orchestrator.ts resolveGsdBin().
|
|
199
|
+
*/
|
|
200
|
+
function resolveGsdBin() {
|
|
201
|
+
if (process.env.GSD_BIN_PATH && existsSync(process.env.GSD_BIN_PATH)) {
|
|
202
|
+
return process.env.GSD_BIN_PATH;
|
|
203
|
+
}
|
|
204
|
+
let thisDir;
|
|
205
|
+
try {
|
|
206
|
+
thisDir = dirname(fileURLToPath(import.meta.url));
|
|
207
|
+
}
|
|
208
|
+
catch {
|
|
209
|
+
thisDir = process.cwd();
|
|
210
|
+
}
|
|
211
|
+
const candidates = [
|
|
212
|
+
join(thisDir, "..", "..", "..", "loader.js"),
|
|
213
|
+
join(thisDir, "..", "..", "..", "..", "dist", "loader.js"),
|
|
214
|
+
];
|
|
215
|
+
for (const candidate of candidates) {
|
|
216
|
+
if (existsSync(candidate))
|
|
217
|
+
return candidate;
|
|
218
|
+
}
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Spawn a worker process for a slice.
|
|
223
|
+
* The worker runs `gsd --mode json --print "/gsd auto"` in the slice's worktree
|
|
224
|
+
* with GSD_SLICE_LOCK, GSD_MILESTONE_LOCK, and GSD_PARALLEL_WORKER set.
|
|
225
|
+
*/
|
|
226
|
+
function spawnSliceWorker(basePath, milestoneId, sliceId) {
|
|
227
|
+
if (!sliceState)
|
|
228
|
+
return false;
|
|
229
|
+
const worker = sliceState.workers.get(sliceId);
|
|
230
|
+
if (!worker)
|
|
231
|
+
return false;
|
|
232
|
+
if (worker.process)
|
|
233
|
+
return true;
|
|
234
|
+
const binPath = resolveGsdBin();
|
|
235
|
+
if (!binPath)
|
|
236
|
+
return false;
|
|
237
|
+
let child;
|
|
238
|
+
try {
|
|
239
|
+
child = spawn(process.execPath, [binPath, "--mode", "json", "--print", "/gsd auto"], {
|
|
240
|
+
cwd: worker.worktreePath,
|
|
241
|
+
env: {
|
|
242
|
+
...process.env,
|
|
243
|
+
GSD_SLICE_LOCK: sliceId,
|
|
244
|
+
GSD_MILESTONE_LOCK: milestoneId,
|
|
245
|
+
GSD_PROJECT_ROOT: basePath,
|
|
246
|
+
GSD_PARALLEL_WORKER: "1",
|
|
247
|
+
},
|
|
248
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
249
|
+
detached: false,
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
catch {
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
child.on("error", () => {
|
|
256
|
+
if (!sliceState)
|
|
257
|
+
return;
|
|
258
|
+
const w = sliceState.workers.get(sliceId);
|
|
259
|
+
if (w) {
|
|
260
|
+
w.process = null;
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
worker.process = child;
|
|
264
|
+
worker.pid = child.pid ?? 0;
|
|
265
|
+
if (!child.pid) {
|
|
266
|
+
worker.process = null;
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
// ── NDJSON stdout monitoring ────────────────────────────────────────
|
|
270
|
+
if (child.stdout) {
|
|
271
|
+
let stdoutBuffer = "";
|
|
272
|
+
child.stdout.on("data", (data) => {
|
|
273
|
+
stdoutBuffer += data.toString();
|
|
274
|
+
const lines = stdoutBuffer.split("\n");
|
|
275
|
+
stdoutBuffer = lines.pop() || "";
|
|
276
|
+
for (const line of lines) {
|
|
277
|
+
processSliceWorkerLine(basePath, milestoneId, sliceId, line);
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
child.stdout.on("close", () => {
|
|
281
|
+
if (stdoutBuffer.trim()) {
|
|
282
|
+
processSliceWorkerLine(basePath, milestoneId, sliceId, stdoutBuffer);
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
if (child.stderr) {
|
|
287
|
+
child.stderr.on("data", (data) => {
|
|
288
|
+
appendSliceWorkerLog(basePath, milestoneId, sliceId, data.toString());
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
// Update session status
|
|
292
|
+
writeSessionStatus(basePath, {
|
|
293
|
+
milestoneId: `${milestoneId}/${sliceId}`,
|
|
294
|
+
pid: worker.pid,
|
|
295
|
+
state: "running",
|
|
296
|
+
currentUnit: null,
|
|
297
|
+
completedUnits: worker.completedUnits,
|
|
298
|
+
cost: worker.cost,
|
|
299
|
+
lastHeartbeat: Date.now(),
|
|
300
|
+
startedAt: worker.startedAt,
|
|
301
|
+
worktreePath: worker.worktreePath,
|
|
302
|
+
});
|
|
303
|
+
// Store cleanup function
|
|
304
|
+
worker.cleanup = () => {
|
|
305
|
+
child.stdout?.removeAllListeners();
|
|
306
|
+
child.stderr?.removeAllListeners();
|
|
307
|
+
child.removeAllListeners();
|
|
308
|
+
};
|
|
309
|
+
// Handle worker exit
|
|
310
|
+
child.on("exit", (code) => {
|
|
311
|
+
if (!sliceState)
|
|
312
|
+
return;
|
|
313
|
+
const w = sliceState.workers.get(sliceId);
|
|
314
|
+
if (!w)
|
|
315
|
+
return;
|
|
316
|
+
w.cleanup?.();
|
|
317
|
+
w.cleanup = undefined;
|
|
318
|
+
w.process = null;
|
|
319
|
+
if (w.state === "stopped")
|
|
320
|
+
return;
|
|
321
|
+
if (code === 0) {
|
|
322
|
+
w.state = "stopped";
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
w.state = "error";
|
|
326
|
+
appendSliceWorkerLog(basePath, milestoneId, sliceId, `\n[slice-orchestrator] worker exited with code ${code ?? "null"}\n`);
|
|
327
|
+
}
|
|
328
|
+
writeSessionStatus(basePath, {
|
|
329
|
+
milestoneId: `${milestoneId}/${sliceId}`,
|
|
330
|
+
pid: w.pid,
|
|
331
|
+
state: w.state,
|
|
332
|
+
currentUnit: null,
|
|
333
|
+
completedUnits: w.completedUnits,
|
|
334
|
+
cost: w.cost,
|
|
335
|
+
lastHeartbeat: Date.now(),
|
|
336
|
+
startedAt: w.startedAt,
|
|
337
|
+
worktreePath: w.worktreePath,
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
return true;
|
|
341
|
+
}
|
|
342
|
+
// ─── NDJSON Processing ──────────────────────────────────────────────────────
|
|
343
|
+
/**
|
|
344
|
+
* Process a single NDJSON line from a slice worker's stdout.
|
|
345
|
+
* Extracts cost from message_end events.
|
|
346
|
+
*/
|
|
347
|
+
function processSliceWorkerLine(_basePath, _milestoneId, sliceId, line) {
|
|
348
|
+
if (!line.trim() || !sliceState)
|
|
349
|
+
return;
|
|
350
|
+
let event;
|
|
351
|
+
try {
|
|
352
|
+
event = JSON.parse(line);
|
|
353
|
+
}
|
|
354
|
+
catch {
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
const type = String(event.type ?? "");
|
|
358
|
+
if (type === "message_end") {
|
|
359
|
+
const worker = sliceState.workers.get(sliceId);
|
|
360
|
+
if (worker) {
|
|
361
|
+
const usage = event.usage;
|
|
362
|
+
if (usage?.cost && typeof usage.cost === "number") {
|
|
363
|
+
worker.cost += usage.cost;
|
|
364
|
+
sliceState.totalCost += usage.cost;
|
|
365
|
+
}
|
|
366
|
+
worker.completedUnits++;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
// ─── Logging ────────────────────────────────────────────────────────────────
|
|
371
|
+
function sliceLogDir(basePath) {
|
|
372
|
+
return join(gsdRoot(basePath), "parallel", "slice-logs");
|
|
373
|
+
}
|
|
374
|
+
function appendSliceWorkerLog(basePath, milestoneId, sliceId, text) {
|
|
375
|
+
const dir = sliceLogDir(basePath);
|
|
376
|
+
mkdirSync(dir, { recursive: true });
|
|
377
|
+
appendFileSync(join(dir, `${milestoneId}-${sliceId}.log`), text);
|
|
378
|
+
}
|