gsd-pi 2.80.0-dev.2be7caf18 → 2.80.0-dev.3065f7bfa
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 +1 -0
- package/dist/resources/.managed-resources-content-hash +1 -1
- package/dist/resources/extensions/gsd/auto/phases.js +178 -108
- package/dist/resources/extensions/gsd/auto/resolve.js +17 -0
- package/dist/resources/extensions/gsd/auto/run-unit.js +20 -30
- package/dist/resources/extensions/gsd/auto/session.js +8 -0
- package/dist/resources/extensions/gsd/auto-direct-dispatch.js +5 -32
- package/dist/resources/extensions/gsd/auto-dispatch.js +16 -0
- package/dist/resources/extensions/gsd/auto-post-unit.js +17 -4
- package/dist/resources/extensions/gsd/auto-prompts.js +90 -15
- package/dist/resources/extensions/gsd/auto-recovery.js +43 -1
- package/dist/resources/extensions/gsd/auto-start.js +197 -6
- package/dist/resources/extensions/gsd/auto-supervisor.js +8 -1
- package/dist/resources/extensions/gsd/auto-timeout-recovery.js +2 -2
- package/dist/resources/extensions/gsd/auto-worktree.js +111 -1
- package/dist/resources/extensions/gsd/auto.js +79 -24
- package/dist/resources/extensions/gsd/bootstrap/agent-end-recovery.js +42 -2
- package/dist/resources/extensions/gsd/bootstrap/db-tools.js +49 -36
- package/dist/resources/extensions/gsd/bootstrap/dynamic-tools.js +15 -5
- package/dist/resources/extensions/gsd/bootstrap/exec-tools.js +9 -3
- package/dist/resources/extensions/gsd/bootstrap/journal-tools.js +7 -1
- package/dist/resources/extensions/gsd/bootstrap/memory-tools.js +9 -3
- package/dist/resources/extensions/gsd/bootstrap/query-tools.js +8 -2
- package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +238 -28
- package/dist/resources/extensions/gsd/bootstrap/system-context.js +82 -23
- package/dist/resources/extensions/gsd/clean-root-preflight.js +24 -6
- package/dist/resources/extensions/gsd/commands-handlers.js +23 -9
- package/dist/resources/extensions/gsd/context-budget.js +37 -2
- package/dist/resources/extensions/gsd/db/unit-dispatches.js +39 -0
- package/dist/resources/extensions/gsd/db-base-schema.js +4 -2
- package/dist/resources/extensions/gsd/db-migration-steps.js +6 -0
- package/dist/resources/extensions/gsd/ecosystem/gsd-extension-api.js +2 -0
- package/dist/resources/extensions/gsd/git-service.js +36 -4
- package/dist/resources/extensions/gsd/gsd-db.js +46 -13
- package/dist/resources/extensions/gsd/guided-flow.js +66 -32
- package/dist/resources/extensions/gsd/memory-store.js +69 -12
- package/dist/resources/extensions/gsd/native-git-bridge.js +32 -8
- package/dist/resources/extensions/gsd/orphan-stash-audit.js +101 -0
- package/dist/resources/extensions/gsd/parallel-orchestrator.js +13 -3
- package/dist/resources/extensions/gsd/pre-execution-checks.js +22 -0
- package/dist/resources/extensions/gsd/prompt-loader.js +28 -2
- package/dist/resources/extensions/gsd/prompts/complete-milestone.md +16 -13
- package/dist/resources/extensions/gsd/prompts/complete-slice.md +1 -1
- package/dist/resources/extensions/gsd/prompts/execute-task.md +4 -2
- package/dist/resources/extensions/gsd/prompts/plan-slice.md +1 -1
- package/dist/resources/extensions/gsd/prompts/replan-slice.md +2 -2
- package/dist/resources/extensions/gsd/tools/memory-tools.js +1 -0
- package/dist/resources/extensions/gsd/tools/workflow-tool-executors.js +1 -1
- package/dist/resources/extensions/gsd/unit-runtime.js +11 -0
- package/dist/resources/extensions/gsd/workflow-protocol.js +131 -0
- package/dist/resources/extensions/gsd/worktree-resolver.js +68 -21
- 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 +15 -15
- 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 +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 +15 -15
- 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/web/standalone/.next/server/server-reference-manifest.json +1 -1
- package/package.json +3 -3
- package/packages/mcp-server/src/workflow-tools.test.ts +9 -2
- package/packages/native/tsconfig.tsbuildinfo +1 -1
- package/packages/pi-agent-core/dist/agent-loop.d.ts.map +1 -1
- package/packages/pi-agent-core/dist/agent-loop.js +4 -1
- package/packages/pi-agent-core/dist/agent-loop.js.map +1 -1
- package/packages/pi-agent-core/dist/agent.d.ts +5 -0
- package/packages/pi-agent-core/dist/agent.d.ts.map +1 -1
- package/packages/pi-agent-core/dist/agent.js +2 -0
- package/packages/pi-agent-core/dist/agent.js.map +1 -1
- package/packages/pi-agent-core/dist/index.d.ts +1 -0
- package/packages/pi-agent-core/dist/index.d.ts.map +1 -1
- package/packages/pi-agent-core/dist/index.js +2 -0
- package/packages/pi-agent-core/dist/index.js.map +1 -1
- package/packages/pi-agent-core/dist/token-audit.d.ts +47 -0
- package/packages/pi-agent-core/dist/token-audit.d.ts.map +1 -0
- package/packages/pi-agent-core/dist/token-audit.js +221 -0
- package/packages/pi-agent-core/dist/token-audit.js.map +1 -0
- package/packages/pi-agent-core/dist/types.d.ts +9 -0
- package/packages/pi-agent-core/dist/types.d.ts.map +1 -1
- package/packages/pi-agent-core/dist/types.js.map +1 -1
- package/packages/pi-agent-core/src/agent-loop.test.ts +128 -0
- package/packages/pi-agent-core/src/agent-loop.ts +4 -1
- package/packages/pi-agent-core/src/agent.ts +8 -0
- package/packages/pi-agent-core/src/index.ts +2 -0
- package/packages/pi-agent-core/src/token-audit.test.ts +189 -0
- package/packages/pi-agent-core/src/token-audit.ts +287 -0
- package/packages/pi-agent-core/src/types.ts +14 -0
- package/packages/pi-agent-core/tsconfig.tsbuildinfo +1 -1
- package/packages/pi-coding-agent/dist/core/agent-session-abort-order.test.js +32 -0
- package/packages/pi-coding-agent/dist/core/agent-session-abort-order.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/agent-session-tool-refresh.test.js +18 -0
- package/packages/pi-coding-agent/dist/core/agent-session-tool-refresh.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/agent-session.d.ts +12 -0
- package/packages/pi-coding-agent/dist/core/agent-session.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/agent-session.js +41 -7
- package/packages/pi-coding-agent/dist/core/agent-session.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/loader.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/loader.js +8 -0
- package/packages/pi-coding-agent/dist/core/extensions/loader.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/runner.d.ts +2 -0
- package/packages/pi-coding-agent/dist/core/extensions/runner.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/runner.js +3 -6
- package/packages/pi-coding-agent/dist/core/extensions/runner.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/runner.test.js +3 -3
- package/packages/pi-coding-agent/dist/core/extensions/runner.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/types.d.ts +32 -1
- 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/hooks-runner.test.js +2 -0
- package/packages/pi-coding-agent/dist/core/hooks-runner.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/sdk-tool-filter.test.d.ts +2 -0
- package/packages/pi-coding-agent/dist/core/sdk-tool-filter.test.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/core/sdk-tool-filter.test.js +46 -0
- package/packages/pi-coding-agent/dist/core/sdk-tool-filter.test.js.map +1 -0
- package/packages/pi-coding-agent/dist/core/sdk.d.ts +10 -2
- package/packages/pi-coding-agent/dist/core/sdk.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/sdk.js +74 -2
- package/packages/pi-coding-agent/dist/core/sdk.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/skill-tool.test.js +22 -0
- package/packages/pi-coding-agent/dist/core/skill-tool.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/system-prompt.d.ts +6 -7
- package/packages/pi-coding-agent/dist/core/system-prompt.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/system-prompt.js +2 -3
- package/packages/pi-coding-agent/dist/core/system-prompt.js.map +1 -1
- package/packages/pi-coding-agent/src/core/agent-session-abort-order.test.ts +36 -0
- package/packages/pi-coding-agent/src/core/agent-session-tool-refresh.test.ts +25 -0
- package/packages/pi-coding-agent/src/core/agent-session.ts +45 -7
- package/packages/pi-coding-agent/src/core/extensions/loader.ts +10 -0
- package/packages/pi-coding-agent/src/core/extensions/runner.test.ts +3 -3
- package/packages/pi-coding-agent/src/core/extensions/runner.ts +5 -5
- package/packages/pi-coding-agent/src/core/extensions/types.ts +35 -1
- package/packages/pi-coding-agent/src/core/hooks-runner.test.ts +2 -0
- package/packages/pi-coding-agent/src/core/sdk-tool-filter.test.ts +60 -0
- package/packages/pi-coding-agent/src/core/sdk.ts +85 -3
- package/packages/pi-coding-agent/src/core/skill-tool.test.ts +28 -0
- package/packages/pi-coding-agent/src/core/system-prompt.ts +8 -10
- package/packages/pi-coding-agent/tsconfig.tsbuildinfo +1 -1
- package/src/resources/extensions/gsd/auto/loop-deps.ts +2 -2
- package/src/resources/extensions/gsd/auto/phases.ts +251 -172
- package/src/resources/extensions/gsd/auto/resolve.ts +23 -1
- package/src/resources/extensions/gsd/auto/run-unit.ts +25 -30
- package/src/resources/extensions/gsd/auto/session.ts +8 -0
- package/src/resources/extensions/gsd/auto-direct-dispatch.ts +8 -34
- package/src/resources/extensions/gsd/auto-dispatch.ts +16 -0
- package/src/resources/extensions/gsd/auto-post-unit.ts +18 -4
- package/src/resources/extensions/gsd/auto-prompts.ts +95 -14
- package/src/resources/extensions/gsd/auto-recovery.ts +54 -0
- package/src/resources/extensions/gsd/auto-start.ts +230 -9
- package/src/resources/extensions/gsd/auto-supervisor.ts +7 -0
- package/src/resources/extensions/gsd/auto-timeout-recovery.ts +2 -2
- package/src/resources/extensions/gsd/auto-worktree.ts +123 -0
- package/src/resources/extensions/gsd/auto.ts +87 -19
- package/src/resources/extensions/gsd/bootstrap/agent-end-recovery.ts +49 -1
- package/src/resources/extensions/gsd/bootstrap/db-tools.ts +50 -36
- package/src/resources/extensions/gsd/bootstrap/dynamic-tools.ts +16 -5
- package/src/resources/extensions/gsd/bootstrap/exec-tools.ts +10 -3
- package/src/resources/extensions/gsd/bootstrap/journal-tools.ts +8 -1
- package/src/resources/extensions/gsd/bootstrap/memory-tools.ts +10 -3
- package/src/resources/extensions/gsd/bootstrap/query-tools.ts +9 -2
- package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +283 -28
- package/src/resources/extensions/gsd/bootstrap/system-context.ts +90 -22
- package/src/resources/extensions/gsd/clean-root-preflight.ts +32 -7
- package/src/resources/extensions/gsd/commands-handlers.ts +34 -15
- package/src/resources/extensions/gsd/context-budget.ts +44 -2
- package/src/resources/extensions/gsd/db/unit-dispatches.ts +41 -0
- package/src/resources/extensions/gsd/db-base-schema.ts +4 -2
- package/src/resources/extensions/gsd/db-migration-steps.ts +8 -0
- package/src/resources/extensions/gsd/ecosystem/gsd-extension-api.ts +3 -0
- package/src/resources/extensions/gsd/git-service.ts +46 -8
- package/src/resources/extensions/gsd/gsd-db.ts +50 -13
- package/src/resources/extensions/gsd/guided-flow.ts +84 -39
- package/src/resources/extensions/gsd/memory-store.ts +77 -12
- package/src/resources/extensions/gsd/native-git-bridge.ts +39 -6
- package/src/resources/extensions/gsd/orphan-stash-audit.ts +117 -0
- package/src/resources/extensions/gsd/parallel-orchestrator.ts +13 -3
- package/src/resources/extensions/gsd/pre-execution-checks.ts +23 -0
- package/src/resources/extensions/gsd/prompt-loader.ts +27 -2
- package/src/resources/extensions/gsd/prompts/complete-milestone.md +16 -13
- package/src/resources/extensions/gsd/prompts/complete-slice.md +1 -1
- package/src/resources/extensions/gsd/prompts/execute-task.md +4 -2
- package/src/resources/extensions/gsd/prompts/plan-slice.md +1 -1
- package/src/resources/extensions/gsd/prompts/replan-slice.md +2 -2
- package/src/resources/extensions/gsd/tests/artifact-retry-cap.test.ts +2 -2
- package/src/resources/extensions/gsd/tests/auto-loop.test.ts +417 -10
- package/src/resources/extensions/gsd/tests/auto-phases-lifecycle.test.ts +56 -13
- package/src/resources/extensions/gsd/tests/auto-recovery.test.ts +14 -1
- package/src/resources/extensions/gsd/tests/auto-wrapup-inflight-guard.test.ts +168 -6
- package/src/resources/extensions/gsd/tests/clean-root-preflight.test.ts +15 -6
- package/src/resources/extensions/gsd/tests/compaction-snapshot.test.ts +3 -1
- package/src/resources/extensions/gsd/tests/complete-milestone-excerpt.test.ts +31 -0
- package/src/resources/extensions/gsd/tests/complete-slice-composer.test.ts +3 -2
- package/src/resources/extensions/gsd/tests/context-budget.test.ts +10 -1
- package/src/resources/extensions/gsd/tests/context-store.test.ts +7 -1
- package/src/resources/extensions/gsd/tests/custom-engine-loop-integration.test.ts +5 -1
- package/src/resources/extensions/gsd/tests/dispatch-rule-coverage.test.ts +313 -0
- package/src/resources/extensions/gsd/tests/execute-task-rendering.test.ts +5 -2
- package/src/resources/extensions/gsd/tests/fast-forward-reused-milestone-branch.test.ts +219 -0
- package/src/resources/extensions/gsd/tests/finalize-survivor-branch.test.ts +132 -0
- package/src/resources/extensions/gsd/tests/integration/git-service.test.ts +54 -0
- package/src/resources/extensions/gsd/tests/isolation-none-branch-guard.test.ts +6 -3
- package/src/resources/extensions/gsd/tests/journal-integration.test.ts +239 -1
- package/src/resources/extensions/gsd/tests/journal-query-tool.test.ts +32 -0
- package/src/resources/extensions/gsd/tests/knowledge.test.ts +47 -0
- package/src/resources/extensions/gsd/tests/memory-decay-factor.test.ts +90 -0
- package/src/resources/extensions/gsd/tests/merge-conflict-stops-loop.test.ts +1 -0
- package/src/resources/extensions/gsd/tests/milestone-merge-stash-restore.test.ts +242 -0
- package/src/resources/extensions/gsd/tests/native-git-bridge-exec-fallback.test.ts +34 -2
- package/src/resources/extensions/gsd/tests/originalbase-path-comparison.test.ts +3 -0
- package/src/resources/extensions/gsd/tests/orphan-merge-bootstrap.test.ts +133 -0
- package/src/resources/extensions/gsd/tests/orphan-stash-audit.test.ts +201 -0
- package/src/resources/extensions/gsd/tests/parallel-orchestrator-fast-forward.test.ts +113 -0
- package/src/resources/extensions/gsd/tests/pre-execution-checks.test.ts +45 -5
- package/src/resources/extensions/gsd/tests/prompt-duplication-cuts.test.ts +230 -0
- package/src/resources/extensions/gsd/tests/prompt-step-ordering.test.ts +19 -0
- package/src/resources/extensions/gsd/tests/query-tools-db-open.test.ts +3 -3
- package/src/resources/extensions/gsd/tests/restore-tools-after-discuss.test.ts +38 -17
- package/src/resources/extensions/gsd/tests/schema-v27-v28-sequence.test.ts +156 -0
- package/src/resources/extensions/gsd/tests/select-resumable-milestone.test.ts +96 -0
- package/src/resources/extensions/gsd/tests/session-switch-abort-misclassification.test.ts +106 -0
- package/src/resources/extensions/gsd/tests/signal-handlers.test.ts +27 -0
- package/src/resources/extensions/gsd/tests/stalled-tool-recovery.test.ts +49 -1
- package/src/resources/extensions/gsd/tests/start-auto-detached.test.ts +38 -0
- package/src/resources/extensions/gsd/tests/state-corruption-2945.test.ts +1 -0
- package/src/resources/extensions/gsd/tests/system-context-memory.test.ts +112 -0
- package/src/resources/extensions/gsd/tests/system-context-message-routing.test.ts +7 -9
- package/src/resources/extensions/gsd/tests/token-tool-gating.test.ts +291 -0
- package/src/resources/extensions/gsd/tests/unit-dispatches.test.ts +30 -0
- package/src/resources/extensions/gsd/tests/unit-runtime.test.ts +30 -0
- package/src/resources/extensions/gsd/tests/unstructured-continue-context-injection.test.ts +5 -4
- package/src/resources/extensions/gsd/tests/workflow-protocol-excerpt.test.ts +99 -0
- package/src/resources/extensions/gsd/tests/workflow-tool-executors.test.ts +3 -0
- package/src/resources/extensions/gsd/tests/worktree-journal-events.test.ts +1 -0
- package/src/resources/extensions/gsd/tests/worktree-path-injection.test.ts +22 -19
- package/src/resources/extensions/gsd/tests/worktree-project-root-degrade.test.ts +66 -0
- package/src/resources/extensions/gsd/tests/worktree-resolver.test.ts +167 -4
- package/src/resources/extensions/gsd/tools/memory-tools.ts +1 -0
- package/src/resources/extensions/gsd/tools/workflow-tool-executors.ts +1 -1
- package/src/resources/extensions/gsd/unit-runtime.ts +11 -0
- package/src/resources/extensions/gsd/workflow-protocol.ts +160 -0
- package/src/resources/extensions/gsd/worktree-resolver.ts +85 -19
- package/src/resources/extensions/gsd/tests/phases-merge-error-stops-auto.test.ts +0 -97
- /package/dist/web/standalone/.next/static/{3EDDd9ULaybSupPoA_vf- → O2WvnXROue6l7nAp_4dhC}/_buildManifest.js +0 -0
- /package/dist/web/standalone/.next/static/{3EDDd9ULaybSupPoA_vf- → O2WvnXROue6l7nAp_4dhC}/_ssgManifest.js +0 -0
|
@@ -1123,8 +1123,11 @@ export async function postUnitPostVerification(pctx) {
|
|
|
1123
1123
|
return;
|
|
1124
1124
|
}
|
|
1125
1125
|
const strictMode = prefs?.enhanced_verification_strict === true;
|
|
1126
|
-
// Run pre-execution checks
|
|
1127
|
-
|
|
1126
|
+
// Run pre-execution checks against the canonical project root. In
|
|
1127
|
+
// worktree isolation, s.basePath can point at a metadata-only worktree,
|
|
1128
|
+
// while source files remain under the project root.
|
|
1129
|
+
const preExecutionBasePath = s.canonicalProjectRoot;
|
|
1130
|
+
const result = await runPreExecutionChecks(tasks, preExecutionBasePath);
|
|
1128
1131
|
// Log summary to stderr in existing verification output format
|
|
1129
1132
|
const emoji = result.status === "pass" ? "✅" : result.status === "warn" ? "⚠️" : "❌";
|
|
1130
1133
|
process.stderr.write(`gsd-pre-exec: ${emoji} Pre-execution checks ${result.status} for ${mid}/${sid} (${result.durationMs}ms)\n`);
|
|
@@ -1134,12 +1137,12 @@ export async function postUnitPostVerification(pctx) {
|
|
|
1134
1137
|
process.stderr.write(`gsd-pre-exec: ${checkEmoji} [${check.category}] ${check.target}: ${check.message}\n`);
|
|
1135
1138
|
}
|
|
1136
1139
|
// Write evidence JSON to slice artifacts directory
|
|
1137
|
-
const slicePath = resolveSlicePath(
|
|
1140
|
+
const slicePath = resolveSlicePath(preExecutionBasePath, mid, sid);
|
|
1138
1141
|
const evidenceFileName = `${sid}-PRE-EXEC-VERIFY.json`;
|
|
1139
1142
|
let evidencePath = join(".gsd", "milestones", mid, "slices", sid, evidenceFileName);
|
|
1140
1143
|
if (slicePath) {
|
|
1141
1144
|
writePreExecutionEvidence(result, slicePath, mid, sid);
|
|
1142
|
-
evidencePath = relative(
|
|
1145
|
+
evidencePath = relative(preExecutionBasePath, join(slicePath, evidenceFileName)) || evidenceFileName;
|
|
1143
1146
|
}
|
|
1144
1147
|
if (uokFlags.gates) {
|
|
1145
1148
|
const failedChecks = result.checks
|
|
@@ -1187,6 +1190,9 @@ export async function postUnitPostVerification(pctx) {
|
|
|
1187
1190
|
blockingFindings: blockingChecks.map(c => `[${c.category}] ${c.target}: ${c.message}`),
|
|
1188
1191
|
verdictExcerpt: `status=${result.status}; ${blockingCount} blocking issue${blockingCount === 1 ? "" : "s"} detected`,
|
|
1189
1192
|
};
|
|
1193
|
+
// Track consecutive pre-exec failures per slice for loop detection.
|
|
1194
|
+
const retryKey = currentUnit.id;
|
|
1195
|
+
s.preExecRetryCount.set(retryKey, (s.preExecRetryCount.get(retryKey) ?? 0) + 1);
|
|
1190
1196
|
preExecPauseNeeded = true;
|
|
1191
1197
|
}
|
|
1192
1198
|
else if (result.status === "warn") {
|
|
@@ -1199,9 +1205,16 @@ export async function postUnitPostVerification(pctx) {
|
|
|
1199
1205
|
blockingFindings: warnChecks.map(c => `[${c.category}] ${c.target}: ${c.message}`),
|
|
1200
1206
|
verdictExcerpt: `status=${result.status} (strict mode); ${warnChecks.length} warning${warnChecks.length === 1 ? "" : "s"} treated as blocking`,
|
|
1201
1207
|
};
|
|
1208
|
+
const retryKey = currentUnit.id;
|
|
1209
|
+
s.preExecRetryCount.set(retryKey, (s.preExecRetryCount.get(retryKey) ?? 0) + 1);
|
|
1202
1210
|
preExecPauseNeeded = true;
|
|
1203
1211
|
}
|
|
1204
1212
|
}
|
|
1213
|
+
// Reset the retry counter when checks pass — a successful re-plan
|
|
1214
|
+
// should not carry over a stale failure count into future slices.
|
|
1215
|
+
if (result.status === "pass") {
|
|
1216
|
+
s.preExecRetryCount.delete(currentUnit.id);
|
|
1217
|
+
}
|
|
1205
1218
|
debugLog("postUnitPostVerification", {
|
|
1206
1219
|
phase: "pre-execution-checks",
|
|
1207
1220
|
status: result.status,
|
|
@@ -29,12 +29,12 @@ import { resolveSkillManifest, warnIfManifestHasMissingSkills } from "./skill-ma
|
|
|
29
29
|
import { classifyProject } from "./detection.js";
|
|
30
30
|
// ─── Preamble Cap ─────────────────────────────────────────────────────────────
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
32
|
+
* Static ceiling for the preamble cap. Kept as an upper bound even
|
|
33
33
|
* after context-window-aware sizing so large-window users don't suddenly see
|
|
34
|
-
* 10× looser caps than
|
|
34
|
+
* 10× looser caps than needed. Small-window users get a tighter cap derived
|
|
35
35
|
* from their configured executor window.
|
|
36
36
|
*/
|
|
37
|
-
const MAX_PREAMBLE_CHARS =
|
|
37
|
+
const MAX_PREAMBLE_CHARS = 20_000;
|
|
38
38
|
/**
|
|
39
39
|
* Resolve prompt budgets from the configured executor context window.
|
|
40
40
|
*
|
|
@@ -163,8 +163,8 @@ function formatCloseoutReviewInstructions(validationContent, validationRel, curr
|
|
|
163
163
|
].join("\n");
|
|
164
164
|
}
|
|
165
165
|
function capPreamble(preamble) {
|
|
166
|
-
// Cap inlined context at min(
|
|
167
|
-
// The ceiling
|
|
166
|
+
// Cap inlined context at min(static ceiling, scaled inline budget).
|
|
167
|
+
// The ceiling bounds repeated auto prompt payloads; the scaled
|
|
168
168
|
// budget tightens the cap for small-window users whose true safe limit is
|
|
169
169
|
// below 30K. `computeBudgets` allocates 40% of total chars to inline context.
|
|
170
170
|
const budget = Math.min(MAX_PREAMBLE_CHARS, resolvePromptBudgets().inlineContextBudgetChars);
|
|
@@ -571,9 +571,77 @@ export async function buildSliceSummaryExcerpt(absPath, relPath, sid) {
|
|
|
571
571
|
}
|
|
572
572
|
catch {
|
|
573
573
|
// Defensive — any parse failure falls back to full inline.
|
|
574
|
-
return `### ${sid} Summary\nSource: \`${relPath}\`\n\n${content
|
|
574
|
+
return `### ${sid} Summary\nSource: \`${relPath}\`\n\n${capMalformedSummary(content, relPath)}`;
|
|
575
575
|
}
|
|
576
576
|
}
|
|
577
|
+
export async function buildTaskSummaryExcerpt(absPath, relPath, tid, options) {
|
|
578
|
+
const label = options?.blocker ? "Blocker Task Summary" : "Task Summary";
|
|
579
|
+
const header = `### ${label}: ${tid} (excerpt)\nSource: \`${relPath}\``;
|
|
580
|
+
const content = absPath ? await loadFile(absPath) : null;
|
|
581
|
+
if (!content) {
|
|
582
|
+
return `${header}\n\n_(not found — file does not exist yet)_`;
|
|
583
|
+
}
|
|
584
|
+
try {
|
|
585
|
+
const s = parseSummary(content);
|
|
586
|
+
if (!s.frontmatter.id) {
|
|
587
|
+
return `### ${label}: ${tid}\nSource: \`${relPath}\`\n\n${capMalformedSummary(content, relPath)}`;
|
|
588
|
+
}
|
|
589
|
+
const lines = [header, ""];
|
|
590
|
+
if (s.title)
|
|
591
|
+
lines.push(`**Title:** ${s.title}`);
|
|
592
|
+
if (s.oneLiner)
|
|
593
|
+
lines.push(`**One-liner:** ${s.oneLiner}`);
|
|
594
|
+
if (s.frontmatter.verification_result) {
|
|
595
|
+
lines.push(`**Verification:** \`${s.frontmatter.verification_result}\``);
|
|
596
|
+
}
|
|
597
|
+
lines.push(`**Blocker discovered:** ${s.frontmatter.blocker_discovered ? "yes — read full summary if blocker details are insufficient" : "no"}`);
|
|
598
|
+
if (s.frontmatter.provides.length > 0)
|
|
599
|
+
lines.push(`**Provides:** ${s.frontmatter.provides.slice(0, 4).join("; ")}`);
|
|
600
|
+
if (s.frontmatter.key_decisions.length > 0)
|
|
601
|
+
lines.push(`**Key decisions:** ${s.frontmatter.key_decisions.slice(0, 4).join("; ")}`);
|
|
602
|
+
if (s.frontmatter.patterns_established.length > 0)
|
|
603
|
+
lines.push(`**Patterns established:** ${s.frontmatter.patterns_established.slice(0, 4).join("; ")}`);
|
|
604
|
+
if (s.frontmatter.key_files.length > 0) {
|
|
605
|
+
const files = s.frontmatter.key_files.slice(0, 6);
|
|
606
|
+
const more = s.frontmatter.key_files.length > files.length ? ` (+${s.frontmatter.key_files.length - files.length} more)` : "";
|
|
607
|
+
lines.push(`**Key files:** ${files.join(", ")}${more}`);
|
|
608
|
+
}
|
|
609
|
+
const SECTION_CAP_CHARS = 500;
|
|
610
|
+
const capSection = (body) => {
|
|
611
|
+
const trimmed = body.trim();
|
|
612
|
+
if (trimmed.length <= SECTION_CAP_CHARS)
|
|
613
|
+
return trimmed;
|
|
614
|
+
return `${trimmed.slice(0, SECTION_CAP_CHARS)}\n… (truncated — see full \`${relPath}\`)`;
|
|
615
|
+
};
|
|
616
|
+
const verification = extractMarkdownSection(content, "Verification");
|
|
617
|
+
const diagnostics = extractMarkdownSection(content, "Diagnostics");
|
|
618
|
+
const knownIssues = extractMarkdownSection(content, "Known Issues");
|
|
619
|
+
if (verification && verification.trim()) {
|
|
620
|
+
lines.push("", "#### Verification", capSection(verification));
|
|
621
|
+
}
|
|
622
|
+
if (diagnostics && diagnostics.trim()) {
|
|
623
|
+
lines.push("", "#### Diagnostics", capSection(diagnostics));
|
|
624
|
+
}
|
|
625
|
+
if (s.deviations && s.deviations.trim()) {
|
|
626
|
+
lines.push("", "#### Deviations", capSection(s.deviations));
|
|
627
|
+
}
|
|
628
|
+
if (knownIssues && knownIssues.trim()) {
|
|
629
|
+
lines.push("", "#### Known issues", capSection(knownIssues));
|
|
630
|
+
}
|
|
631
|
+
lines.push("", `> **On-demand:** read \`${relPath}\` only when this excerpt is absent/truncated or you need fuller blocker, implementation, or file-change evidence.`);
|
|
632
|
+
return lines.join("\n");
|
|
633
|
+
}
|
|
634
|
+
catch {
|
|
635
|
+
return `### ${label}: ${tid}\nSource: \`${relPath}\`\n\n${capMalformedSummary(content, relPath)}`;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
function capMalformedSummary(content, relPath) {
|
|
639
|
+
const trimmed = content.trim();
|
|
640
|
+
const limit = 1_500;
|
|
641
|
+
if (trimmed.length <= limit)
|
|
642
|
+
return trimmed;
|
|
643
|
+
return `${trimmed.slice(0, limit).trimEnd()}\n\n[Truncated malformed summary — read \`${relPath}\` for full details.]`;
|
|
644
|
+
}
|
|
577
645
|
/**
|
|
578
646
|
* Load and inline dependency slice summaries (full content, not just paths).
|
|
579
647
|
*/
|
|
@@ -826,12 +894,12 @@ export async function inlineKnowledgeScoped(base, keywords) {
|
|
|
826
894
|
* plan-milestone, complete-slice, complete-milestone, validate-milestone,
|
|
827
895
|
* reassess-roadmap) previously injected the full KNOWLEDGE.md (~226KB for a
|
|
828
896
|
* real project) on every invocation. This helper scopes by caller-supplied
|
|
829
|
-
* keywords and caps the payload at `maxChars` (default
|
|
897
|
+
* keywords and caps the payload at `maxChars` (default 12,000 chars).
|
|
830
898
|
*
|
|
831
899
|
* Returns null when no KNOWLEDGE.md exists or no entries match any keyword.
|
|
832
900
|
*/
|
|
833
901
|
export async function inlineKnowledgeBudgeted(base, keywords, options) {
|
|
834
|
-
const DEFAULT_MAX_CHARS =
|
|
902
|
+
const DEFAULT_MAX_CHARS = 12_000;
|
|
835
903
|
const HARD_MAX_CHARS = 100_000;
|
|
836
904
|
const raw = Number(options?.maxChars ?? DEFAULT_MAX_CHARS);
|
|
837
905
|
const maxChars = Number.isFinite(raw)
|
|
@@ -1824,8 +1892,17 @@ export async function buildPlanSlicePrompt(mid, _midTitle, sid, sTitle, base, le
|
|
|
1824
1892
|
`The previous plan-slice attempt was blocked by pre-execution validation.\n` +
|
|
1825
1893
|
`Gate verdict: ${verdictExcerpt}\n\n` +
|
|
1826
1894
|
`Blocked references that must be resolved in this plan:\n${findingsList}\n\n` +
|
|
1827
|
-
|
|
1828
|
-
|
|
1895
|
+
`**How to fix each type of issue:**\n` +
|
|
1896
|
+
`- **"[file] X doesn't exist and isn't created by prior or same-task outputs"**: ` +
|
|
1897
|
+
`Either (a) add an earlier task that creates X on disk before the task that needs it, ` +
|
|
1898
|
+
`or (b) if this task IS the one that creates X, move X from inputs to expected_output. ` +
|
|
1899
|
+
`Do NOT put X in a task's expected_output if that task only reads or verifies X — only tasks that actually write X to disk should list it in expected_output.\n` +
|
|
1900
|
+
`- **"[file] X: Task T_early reads X but it's created by task T_late (sequence violation)"**: ` +
|
|
1901
|
+
`Either (a) reorder tasks so T_late (the creator) runs before T_early (the reader), ` +
|
|
1902
|
+
`or (b) if T_late doesn't actually create X (it only reads/tests it), remove X from T_late's expected_output entirely.\n` +
|
|
1903
|
+
`- **"[package] P not found on npm"**: Either remove the npm install for P, or use the correct package name.\n\n` +
|
|
1904
|
+
`Every file listed in a task's inputs must either exist on disk already or appear in an earlier task's expected_output. ` +
|
|
1905
|
+
`A task's expected_output must only list files it actually writes to disk.`);
|
|
1829
1906
|
}
|
|
1830
1907
|
return renderSlicePrompt({
|
|
1831
1908
|
mid, sid, sTitle, base,
|
|
@@ -2048,11 +2125,9 @@ export async function buildCompleteSlicePrompt(mid, midTitle, sid, sTitle, base,
|
|
|
2048
2125
|
const blocks = [];
|
|
2049
2126
|
for (const file of summaryFiles) {
|
|
2050
2127
|
const absPath = join(tDir, file);
|
|
2051
|
-
const content = await loadFile(absPath);
|
|
2052
|
-
if (!content)
|
|
2053
|
-
continue;
|
|
2054
2128
|
const relPath = `${sRel}/tasks/${file}`;
|
|
2055
|
-
|
|
2129
|
+
const taskId = file.replace(/-SUMMARY\.md$/i, "");
|
|
2130
|
+
blocks.push(await buildTaskSummaryExcerpt(absPath, relPath, taskId));
|
|
2056
2131
|
}
|
|
2057
2132
|
return blocks.length > 0 ? blocks.join("\n\n---\n\n") : null;
|
|
2058
2133
|
}
|
|
@@ -2399,7 +2474,7 @@ export async function buildReplanSlicePrompt(mid, midTitle, sid, sTitle, base) {
|
|
|
2399
2474
|
const relPath = `${sRel}/tasks/${file}`;
|
|
2400
2475
|
if (summary.frontmatter.blocker_discovered) {
|
|
2401
2476
|
blockerTaskId = summary.frontmatter.id || file.replace(/-SUMMARY\.md$/i, "");
|
|
2402
|
-
inlined.push(
|
|
2477
|
+
inlined.push(await buildTaskSummaryExcerpt(absPath, relPath, blockerTaskId, { blocker: true }));
|
|
2403
2478
|
}
|
|
2404
2479
|
}
|
|
2405
2480
|
}
|
|
@@ -30,7 +30,49 @@ import { getProjectResearchStatus } from "./project-research-policy.js";
|
|
|
30
30
|
// Re-export so existing consumers of auto-recovery.ts keep working.
|
|
31
31
|
export { resolveExpectedArtifactPath, diagnoseExpectedArtifact };
|
|
32
32
|
export { classifyMilestoneSummaryContent, } from "./milestone-summary-classifier.js";
|
|
33
|
-
|
|
33
|
+
export function refreshRecoveryDbForArtifact(unitType, unitId) {
|
|
34
|
+
if (unitType !== "plan-slice" && unitType !== "execute-task")
|
|
35
|
+
return { ok: true };
|
|
36
|
+
if (!isDbAvailable())
|
|
37
|
+
return { ok: true };
|
|
38
|
+
if (!refreshOpenDatabaseFromDisk()) {
|
|
39
|
+
return {
|
|
40
|
+
ok: false,
|
|
41
|
+
fatal: unitType === "execute-task",
|
|
42
|
+
reason: `${unitType}-db-refresh-failed`,
|
|
43
|
+
message: `Stuck recovery found ${unitType} ${unitId} artifacts, but the DB refresh failed.`,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
if (unitType !== "execute-task")
|
|
47
|
+
return { ok: true };
|
|
48
|
+
const { milestone: mid, slice: sid, task: tid } = parseUnitId(unitId);
|
|
49
|
+
if (!mid || !sid || !tid) {
|
|
50
|
+
return {
|
|
51
|
+
ok: false,
|
|
52
|
+
fatal: true,
|
|
53
|
+
reason: "execute-task-invalid-unit-id",
|
|
54
|
+
message: `Stuck recovery found execute-task ${unitId} artifacts, but the unit id could not be parsed for DB verification.`,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const task = getTask(mid, sid, tid);
|
|
58
|
+
if (!task) {
|
|
59
|
+
return {
|
|
60
|
+
ok: false,
|
|
61
|
+
fatal: true,
|
|
62
|
+
reason: "execute-task-artifact-db-missing",
|
|
63
|
+
message: `Stuck recovery found execute-task ${unitId} artifacts, but no matching DB task row exists after refresh.`,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
if (!isClosedStatus(task.status)) {
|
|
67
|
+
return {
|
|
68
|
+
ok: false,
|
|
69
|
+
fatal: true,
|
|
70
|
+
reason: "execute-task-artifact-db-mismatch",
|
|
71
|
+
message: `Stuck recovery found execute-task ${unitId} artifacts, but the DB task status is still '${task.status}' after refresh.`,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
return { ok: true };
|
|
75
|
+
}
|
|
34
76
|
function hasCapturedWorkflowPrefs(base) {
|
|
35
77
|
const prefsPath = resolveExpectedArtifactPath("workflow-preferences", "WORKFLOW-PREFS", base);
|
|
36
78
|
if (!prefsPath || !existsSync(prefsPath))
|
|
@@ -34,6 +34,7 @@ import { snapshotSkills } from "./skill-discovery.js";
|
|
|
34
34
|
import { isDbAvailable, getMilestone, openDatabase, getDbStatus } from "./gsd-db.js";
|
|
35
35
|
import { isClosedStatus } from "./status-guards.js";
|
|
36
36
|
import { classifyMilestoneSummaryContent } from "./milestone-summary-classifier.js";
|
|
37
|
+
import { auditOrphanedPreflightStashes } from "./orphan-stash-audit.js";
|
|
37
38
|
import { debugLog, enableDebug, isDebugEnabled, getDebugLogPath, } from "./debug-logger.js";
|
|
38
39
|
import { logWarning, logError } from "./workflow-logger.js";
|
|
39
40
|
import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, } from "node:fs";
|
|
@@ -224,6 +225,139 @@ export function auditOrphanedMilestoneBranches(basePath, isolationMode) {
|
|
|
224
225
|
}
|
|
225
226
|
return { recovered, warnings };
|
|
226
227
|
}
|
|
228
|
+
/**
|
|
229
|
+
* Pure decision function for picking which orphan milestone the auto-loop
|
|
230
|
+
* should resume the merge transition for. Extracted so it can be unit-tested
|
|
231
|
+
* without spinning up a git repo or a SQLite DB.
|
|
232
|
+
*
|
|
233
|
+
* Returns the lexicographically-greatest milestone id (e.g. "M002" beats
|
|
234
|
+
* "M001") whose branch is unmerged AND has commits ahead of main AND whose
|
|
235
|
+
* status is `complete`. Lex-ordering matches the project's M00x convention,
|
|
236
|
+
* which is the most-recently-completed milestone in practice.
|
|
237
|
+
* `isComplete` errors propagate; `commitsAhead` errors are treated as 0.
|
|
238
|
+
*/
|
|
239
|
+
export function _selectResumableMilestone(branchNames, mergedBranches, isComplete, commitsAhead) {
|
|
240
|
+
const candidates = [];
|
|
241
|
+
for (const branch of branchNames) {
|
|
242
|
+
if (!branch.startsWith("milestone/"))
|
|
243
|
+
continue;
|
|
244
|
+
const milestoneId = branch.slice("milestone/".length);
|
|
245
|
+
if (mergedBranches.has(branch))
|
|
246
|
+
continue;
|
|
247
|
+
if (!isComplete(milestoneId))
|
|
248
|
+
continue;
|
|
249
|
+
let ahead = 0;
|
|
250
|
+
try {
|
|
251
|
+
ahead = commitsAhead(branch);
|
|
252
|
+
}
|
|
253
|
+
catch {
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
if (ahead <= 0)
|
|
257
|
+
continue;
|
|
258
|
+
candidates.push(milestoneId);
|
|
259
|
+
}
|
|
260
|
+
if (candidates.length === 0)
|
|
261
|
+
return null;
|
|
262
|
+
candidates.sort();
|
|
263
|
+
return candidates[candidates.length - 1];
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Find the most-recent completed milestone whose branch still has unmerged
|
|
267
|
+
* commits ahead of the integration branch. Used by `bootstrapAutoSession`
|
|
268
|
+
* to seed `s.currentMilestoneId` so the auto-loop's transition guard at
|
|
269
|
+
* `phases.ts:730` fires on the first iteration after a process restart —
|
|
270
|
+
* without this, the in-memory-only `s.currentMilestoneId` is `null` after
|
|
271
|
+
* restart, the guard short-circuits, and the orphaned milestone branch
|
|
272
|
+
* never gets merged into main (#5538-followup).
|
|
273
|
+
*
|
|
274
|
+
* Returns null when isolation is `none`, the DB is unavailable, or no
|
|
275
|
+
* orphan candidate exists. All git failures degrade silently — startup
|
|
276
|
+
* must never block on this defensive lookup.
|
|
277
|
+
*/
|
|
278
|
+
export function findUnmergedCompletedMilestone(basePath, isolationMode) {
|
|
279
|
+
if (isolationMode === "none")
|
|
280
|
+
return null;
|
|
281
|
+
if (!isDbAvailable())
|
|
282
|
+
return null;
|
|
283
|
+
let milestoneBranches;
|
|
284
|
+
try {
|
|
285
|
+
milestoneBranches = nativeBranchList(basePath, "milestone/*");
|
|
286
|
+
}
|
|
287
|
+
catch {
|
|
288
|
+
return null;
|
|
289
|
+
}
|
|
290
|
+
if (milestoneBranches.length === 0)
|
|
291
|
+
return null;
|
|
292
|
+
let mainBranch;
|
|
293
|
+
try {
|
|
294
|
+
mainBranch = nativeDetectMainBranch(basePath);
|
|
295
|
+
}
|
|
296
|
+
catch {
|
|
297
|
+
mainBranch = "main";
|
|
298
|
+
}
|
|
299
|
+
let mergedBranches;
|
|
300
|
+
try {
|
|
301
|
+
mergedBranches = new Set(nativeBranchListMerged(basePath, mainBranch, "milestone/*"));
|
|
302
|
+
}
|
|
303
|
+
catch {
|
|
304
|
+
mergedBranches = new Set();
|
|
305
|
+
}
|
|
306
|
+
return _selectResumableMilestone(milestoneBranches, mergedBranches, (milestoneId) => {
|
|
307
|
+
const row = getMilestone(milestoneId);
|
|
308
|
+
return !!row && row.status === "complete";
|
|
309
|
+
}, (branch) => nativeCommitCountBetween(basePath, mainBranch, branch));
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Run `mergeAndExit` for a milestone whose worktree/branch finalization
|
|
313
|
+
* never completed in a prior session — the active-milestone in phase
|
|
314
|
+
* `complete` with a survivor `milestone/<id>` branch still around.
|
|
315
|
+
*
|
|
316
|
+
* Wraps the call in try/catch so a thrown error from `_mergeBranchMode`
|
|
317
|
+
* (made fail-loud in commit 68ef58a3c) is converted into a user-facing
|
|
318
|
+
* error notify instead of an unhandled exception that propagates through
|
|
319
|
+
* `bootstrapAutoSession` to the slash-command caller's `.catch` block.
|
|
320
|
+
*
|
|
321
|
+
* Returns `{ merged: true }` on success; `{ merged: false, error }` on
|
|
322
|
+
* throw — caller decides whether to abort bootstrap.
|
|
323
|
+
*/
|
|
324
|
+
export function _finalizeSurvivorBranch(resolver, milestoneId, ui) {
|
|
325
|
+
ui.notify(`Milestone ${milestoneId} is complete but branch/worktree was not finalized. Running merge now.`, "info");
|
|
326
|
+
try {
|
|
327
|
+
resolver.mergeAndExit(milestoneId, { notify: ui.notify.bind(ui) });
|
|
328
|
+
return { merged: true };
|
|
329
|
+
}
|
|
330
|
+
catch (err) {
|
|
331
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
332
|
+
ui.notify(`Survivor-branch finalization for ${milestoneId} failed: ${msg}. Resolve manually and re-run /gsd auto.`, "error");
|
|
333
|
+
return { merged: false, error: err };
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Merge a milestone whose DB row is `complete` but whose branch is still
|
|
338
|
+
* unmerged into the integration branch. Called from `bootstrapAutoSession`
|
|
339
|
+
* for orphans surfaced by `findUnmergedCompletedMilestone`.
|
|
340
|
+
*
|
|
341
|
+
* Notifies the user before and after, swallowing errors so a transient git
|
|
342
|
+
* failure never blocks bootstrap. Returns `{ merged: true }` when the
|
|
343
|
+
* underlying `mergeAndExit` completes; `{ merged: false, error }` on throw.
|
|
344
|
+
*
|
|
345
|
+
* Extracted to keep `bootstrapAutoSession` testable: the merge call and the
|
|
346
|
+
* notify shape are exercised against a mock resolver in
|
|
347
|
+
* `tests/orphan-merge-bootstrap.test.ts`.
|
|
348
|
+
*/
|
|
349
|
+
export function _mergeOrphanCompletedMilestone(resolver, orphanId, ui) {
|
|
350
|
+
ui.notify(`Detected unmerged completed milestone ${orphanId}. Merging now.`, "info");
|
|
351
|
+
try {
|
|
352
|
+
resolver.mergeAndExit(orphanId, { notify: ui.notify.bind(ui) });
|
|
353
|
+
return { merged: true };
|
|
354
|
+
}
|
|
355
|
+
catch (err) {
|
|
356
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
357
|
+
ui.notify(`Could not merge orphan milestone ${orphanId}: ${msg}. Resolve manually and re-run /gsd auto.`, "warning");
|
|
358
|
+
return { merged: false, error: err };
|
|
359
|
+
}
|
|
360
|
+
}
|
|
227
361
|
export async function bootstrapAutoSession(s, ctx, pi, base, verboseMode, requestedStepMode, deps, interrupted) {
|
|
228
362
|
const { shouldUseWorktreeIsolation, registerSigtermHandler, lockBase, buildResolver, } = deps;
|
|
229
363
|
const dirCheck = validateDirectory(base);
|
|
@@ -420,6 +554,33 @@ export async function bootstrapAutoSession(s, ctx, pi, base, verboseMode, reques
|
|
|
420
554
|
// Non-fatal — the audit is defensive, never block bootstrap
|
|
421
555
|
logWarning("bootstrap", `orphaned milestone branch audit failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
422
556
|
}
|
|
557
|
+
// ── Orphaned preflight-stash audit (#5538-followup) ──
|
|
558
|
+
// Reapplies pre-merge stashes whose milestone is now complete but whose
|
|
559
|
+
// postflight pop was skipped by an interrupted merge in a prior session.
|
|
560
|
+
// Uses `git stash apply` (not pop) so the entry remains as a backup.
|
|
561
|
+
try {
|
|
562
|
+
if (isDbAvailable()) {
|
|
563
|
+
const stashAudit = auditOrphanedPreflightStashes(base, (milestoneId) => {
|
|
564
|
+
const row = getMilestone(milestoneId);
|
|
565
|
+
return !!row && isClosedStatus(row.status);
|
|
566
|
+
});
|
|
567
|
+
for (const entry of stashAudit.applied) {
|
|
568
|
+
ctx.ui.notify(`Orphan audit: applied preflight stash ${entry.stashRef} for completed milestone ${entry.milestoneId}. The stash entry is preserved as a backup.`, "info");
|
|
569
|
+
}
|
|
570
|
+
for (const msg of stashAudit.warnings) {
|
|
571
|
+
ctx.ui.notify(`Orphan audit: ${msg}`, "warning");
|
|
572
|
+
}
|
|
573
|
+
if (stashAudit.applied.length > 0) {
|
|
574
|
+
debugLog("orphan-stash-audit", {
|
|
575
|
+
applied: stashAudit.applied,
|
|
576
|
+
warnings: stashAudit.warnings,
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
catch (err) {
|
|
582
|
+
logWarning("bootstrap", `orphaned preflight-stash audit failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
583
|
+
}
|
|
423
584
|
let state = await deriveState(base);
|
|
424
585
|
// Stale worktree state recovery (#654)
|
|
425
586
|
if (state.activeMilestone &&
|
|
@@ -476,16 +637,46 @@ export async function bootstrapAutoSession(s, ctx, pi, base, verboseMode, reques
|
|
|
476
637
|
// hasSurvivorBranch after a successful promotion.
|
|
477
638
|
if (decideSurvivorAction(hasSurvivorBranch, state.phase) === "finalize") {
|
|
478
639
|
const mid = state.activeMilestone.id;
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
640
|
+
// Commit 68ef58a3c made `_mergeBranchMode` throw on wrong-branch
|
|
641
|
+
// instead of returning false silently. Wrap the call so the throw is
|
|
642
|
+
// converted into an error notify + clean bootstrap abort, not an
|
|
643
|
+
// unhandled exception propagating to the slash-command caller (#5549
|
|
644
|
+
// post-merge audit, R2).
|
|
645
|
+
const finalize = _finalizeSurvivorBranch(buildResolver(), mid, ctx.ui);
|
|
646
|
+
if (!finalize.merged) {
|
|
647
|
+
return releaseLockAndReturn();
|
|
648
|
+
}
|
|
484
649
|
invalidateAllCaches();
|
|
485
650
|
state = await deriveState(base);
|
|
486
651
|
// Clear survivor flag — finalization is done
|
|
487
652
|
hasSurvivorBranch = false;
|
|
488
653
|
}
|
|
654
|
+
// ── Orphan-completed-milestone merge (#5538-followup) ──
|
|
655
|
+
// A process killed between `complete-milestone` (DB flip + SUMMARY write)
|
|
656
|
+
// and the loop's transition-guard merge strands the milestone branch
|
|
657
|
+
// forever: `s.currentMilestoneId` is in-memory only, so on the next
|
|
658
|
+
// bootstrap the guard at phases.ts:730 sees `mid === s.currentMilestoneId`
|
|
659
|
+
// and short-circuits.
|
|
660
|
+
//
|
|
661
|
+
// The earlier attempt at this fix seeded `s.currentMilestoneId` to the
|
|
662
|
+
// orphan id pre-state-derivation, but the unconditional assignment at
|
|
663
|
+
// line 948 (`s.currentMilestoneId = state.activeMilestone?.id ?? null`)
|
|
664
|
+
// immediately overwrote the seed. Active-merge is the more durable fix:
|
|
665
|
+
// call `mergeAndExit` directly during bootstrap, then re-derive state so
|
|
666
|
+
// the loop's normal flow continues without an in-memory hint.
|
|
667
|
+
//
|
|
668
|
+
// Mirrors the survivor-finalize block above. Failures degrade to a
|
|
669
|
+
// warning notify so a transient git error doesn't block bootstrap.
|
|
670
|
+
{
|
|
671
|
+
const orphan = findUnmergedCompletedMilestone(base, getIsolationMode(base));
|
|
672
|
+
if (orphan && orphan !== state.activeMilestone?.id) {
|
|
673
|
+
const result = _mergeOrphanCompletedMilestone(buildResolver(), orphan, ctx.ui);
|
|
674
|
+
if (result.merged) {
|
|
675
|
+
invalidateAllCaches();
|
|
676
|
+
state = await deriveState(base);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
}
|
|
489
680
|
const effectivePrefs = loadEffectiveGSDPreferences(base)?.preferences;
|
|
490
681
|
const { shouldRunDeepProjectSetup } = await import("./auto-dispatch.js");
|
|
491
682
|
const deepProjectStagePending = shouldRunDeepProjectSetup(state, effectivePrefs, base, { hasSurvivorBranch });
|
|
@@ -590,7 +781,7 @@ export async function bootstrapAutoSession(s, ctx, pi, base, verboseMode, reques
|
|
|
590
781
|
s.resourceVersionOnStart = readResourceVersion();
|
|
591
782
|
s.pendingQuickTasks = [];
|
|
592
783
|
s.currentUnit = null;
|
|
593
|
-
s.currentMilestoneId
|
|
784
|
+
s.currentMilestoneId ??= deepProjectStagePending ? null : state.activeMilestone?.id ?? null;
|
|
594
785
|
s.originalModelId = startModelSnapshot?.id ?? ctx.model?.id ?? null;
|
|
595
786
|
s.originalModelProvider = startModelSnapshot?.provider ?? ctx.model?.provider ?? null;
|
|
596
787
|
s.originalThinkingLevel = startThinkingSnapshot ?? null;
|
|
@@ -24,7 +24,7 @@ let _currentSigtermHandler = null;
|
|
|
24
24
|
*
|
|
25
25
|
* Returns the new handler so the caller can store and deregister it later.
|
|
26
26
|
*/
|
|
27
|
-
export function registerSigtermHandler(currentBasePath, previousHandler) {
|
|
27
|
+
export function registerSigtermHandler(currentBasePath, previousHandler, onSignalCleanup) {
|
|
28
28
|
// Remove the explicitly-passed previous handler
|
|
29
29
|
if (previousHandler) {
|
|
30
30
|
for (const sig of CLEANUP_SIGNALS)
|
|
@@ -37,6 +37,13 @@ export function registerSigtermHandler(currentBasePath, previousHandler) {
|
|
|
37
37
|
process.off(sig, _currentSigtermHandler);
|
|
38
38
|
}
|
|
39
39
|
const handler = () => {
|
|
40
|
+
try {
|
|
41
|
+
onSignalCleanup?.();
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
void 0;
|
|
45
|
+
// Signal cleanup is best-effort; lock cleanup and process exit still run.
|
|
46
|
+
}
|
|
40
47
|
clearLock(currentBasePath);
|
|
41
48
|
releaseSessionLock(currentBasePath);
|
|
42
49
|
process.exit(0);
|
|
@@ -35,13 +35,13 @@ export async function recoverTimedOutUnit(ctx, pi, unitType, unitId, reason, rct
|
|
|
35
35
|
writeUnitRuntimeRecord(basePath, unitType, unitId, currentUnitStartedAt, {
|
|
36
36
|
recovery: status,
|
|
37
37
|
});
|
|
38
|
-
const durableComplete = status.summaryExists && status.taskChecked && status.nextActionAdvanced;
|
|
38
|
+
const durableComplete = status.dbComplete || (status.summaryExists && status.taskChecked && status.nextActionAdvanced);
|
|
39
39
|
if (durableComplete) {
|
|
40
40
|
writeUnitRuntimeRecord(basePath, unitType, unitId, currentUnitStartedAt, {
|
|
41
41
|
phase: "finalized",
|
|
42
42
|
recovery: status,
|
|
43
43
|
});
|
|
44
|
-
ctx.ui.notify(`${reason === "idle" ? "Idle" : "Timeout"} recovery: ${unitType} ${unitId} already completed
|
|
44
|
+
ctx.ui.notify(`${reason === "idle" ? "Idle" : "Timeout"} recovery: ${unitType} ${unitId} already completed. Continuing auto-mode. (attempt ${attemptNumber})`, "info");
|
|
45
45
|
unitRecoveryCount.delete(recoveryKey);
|
|
46
46
|
bumpAndResolveSynthetic(`timeout-recovery:${reason}:${unitType}/${unitId}`);
|
|
47
47
|
return "recovered";
|