gsd-pi 2.79.0-dev.5c910bb05 → 2.79.0-dev.9941c9c24
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/dist/resources/.managed-resources-content-hash +1 -1
- package/dist/resources/extensions/gsd/auto/contracts.js +1 -0
- package/dist/resources/extensions/gsd/auto/orchestrator.js +146 -0
- package/dist/resources/extensions/gsd/auto/phases.js +61 -7
- package/dist/resources/extensions/gsd/auto/session.js +8 -0
- package/dist/resources/extensions/gsd/auto-artifact-paths.js +2 -2
- package/dist/resources/extensions/gsd/auto-dispatch.js +2 -0
- package/dist/resources/extensions/gsd/auto-recovery.js +63 -55
- package/dist/resources/extensions/gsd/auto-runtime-state.js +4 -0
- package/dist/resources/extensions/gsd/auto-start.js +3 -2
- package/dist/resources/extensions/gsd/auto.js +159 -2
- package/dist/resources/extensions/gsd/bootstrap/agent-end-recovery.js +9 -1
- package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +8 -8
- package/dist/resources/extensions/gsd/bootstrap/write-gate.js +8 -8
- package/dist/resources/extensions/gsd/gsd-db.js +34 -1
- package/dist/resources/extensions/gsd/guided-flow.js +40 -0
- package/dist/resources/extensions/gsd/paths.js +5 -1
- package/dist/resources/extensions/gsd/tools/workflow-tool-executors.js +45 -4
- package/dist/resources/extensions/gsd/uok/audit.js +23 -9
- package/dist/resources/extensions/gsd/uok/contracts.js +69 -1
- package/dist/resources/extensions/gsd/uok/dispatch-envelope.js +3 -0
- package/dist/resources/extensions/gsd/uok/loop-adapter.js +48 -33
- package/dist/resources/extensions/gsd/uok/timeline.js +125 -0
- package/dist/resources/extensions/shared/gsd-phase-state.js +45 -3
- package/dist/resources/extensions/shared/interview-ui.js +15 -4
- 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 +14 -14
- 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 +14 -14
- 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 +1 -1
- package/packages/mcp-server/src/workflow-tools.test.ts +13 -2
- package/src/resources/extensions/gsd/auto/contracts.ts +87 -0
- package/src/resources/extensions/gsd/auto/loop-deps.ts +10 -3
- package/src/resources/extensions/gsd/auto/orchestrator.ts +161 -0
- package/src/resources/extensions/gsd/auto/phases.ts +88 -9
- package/src/resources/extensions/gsd/auto/session.ts +11 -0
- package/src/resources/extensions/gsd/auto-artifact-paths.ts +2 -2
- package/src/resources/extensions/gsd/auto-dispatch.ts +1 -0
- package/src/resources/extensions/gsd/auto-recovery.ts +59 -53
- package/src/resources/extensions/gsd/auto-runtime-state.ts +7 -0
- package/src/resources/extensions/gsd/auto-start.ts +3 -2
- package/src/resources/extensions/gsd/auto.ts +167 -1
- package/src/resources/extensions/gsd/bootstrap/agent-end-recovery.ts +14 -1
- package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +11 -8
- package/src/resources/extensions/gsd/bootstrap/tests/write-gate-shouldblock-basepath.test.ts +97 -0
- package/src/resources/extensions/gsd/bootstrap/write-gate.ts +8 -4
- package/src/resources/extensions/gsd/gsd-db.ts +35 -1
- package/src/resources/extensions/gsd/guided-flow.ts +47 -0
- package/src/resources/extensions/gsd/interrupted-session.ts +1 -0
- package/src/resources/extensions/gsd/paths.ts +6 -1
- package/src/resources/extensions/gsd/tests/auto-abort-pause-regression.test.ts +32 -0
- package/src/resources/extensions/gsd/tests/auto-orchestrator.test.ts +353 -0
- package/src/resources/extensions/gsd/tests/auto-recovery.test.ts +108 -1
- package/src/resources/extensions/gsd/tests/auto-runtime-state.test.ts +39 -0
- package/src/resources/extensions/gsd/tests/auto-session-encapsulation.test.ts +3 -0
- package/src/resources/extensions/gsd/tests/check-auto-start-pending-gate.test.ts +203 -0
- package/src/resources/extensions/gsd/tests/check-auto-start-ready-guard.test.ts +148 -0
- package/src/resources/extensions/gsd/tests/deep-planning-mode-dispatch.test.ts +42 -0
- package/src/resources/extensions/gsd/tests/deep-project-auto-loop.test.ts +63 -2
- package/src/resources/extensions/gsd/tests/execute-summary-save-empty-project.test.ts +109 -0
- package/src/resources/extensions/gsd/tests/gsd-db.test.ts +95 -0
- package/src/resources/extensions/gsd/tests/integration/auto-recovery.test.ts +79 -0
- package/src/resources/extensions/gsd/tests/journal-integration.test.ts +134 -0
- package/src/resources/extensions/gsd/tests/paused-session-via-db.test.ts +2 -0
- package/src/resources/extensions/gsd/tests/plan-slice.test.ts +27 -0
- package/src/resources/extensions/gsd/tests/uok-contracts.test.ts +109 -1
- package/src/resources/extensions/gsd/tests/uok-loop-adapter-writer.test.ts +98 -0
- package/src/resources/extensions/gsd/tests/workflow-tool-executors.test.ts +36 -7
- package/src/resources/extensions/gsd/tools/workflow-tool-executors.ts +47 -4
- package/src/resources/extensions/gsd/uok/audit.ts +25 -9
- package/src/resources/extensions/gsd/uok/contracts.ts +105 -0
- package/src/resources/extensions/gsd/uok/dispatch-envelope.ts +4 -0
- package/src/resources/extensions/gsd/uok/loop-adapter.ts +60 -45
- package/src/resources/extensions/gsd/uok/timeline.ts +158 -0
- package/src/resources/extensions/shared/gsd-phase-state.ts +56 -3
- package/src/resources/extensions/shared/interview-ui.ts +18 -5
- package/src/resources/extensions/shared/tests/gsd-phase-state.test.ts +43 -1
- package/src/resources/extensions/shared/tests/interview-notes-loop.test.ts +41 -0
- /package/dist/web/standalone/.next/static/{DSZPSz1kgrF8zPIrV_AMD → zSHLdEn5cpkqivbJZq0Qq}/_buildManifest.js +0 -0
- /package/dist/web/standalone/.next/static/{DSZPSz1kgrF8zPIrV_AMD → zSHLdEn5cpkqivbJZq0Qq}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import type { AutoAdvanceResult, AutoOrchestrationModule, AutoOrchestratorDeps, AutoSessionContext, AutoStatus } from "./contracts.js";
|
|
2
|
+
|
|
3
|
+
function now(): number {
|
|
4
|
+
return Date.now();
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export class AutoOrchestrator implements AutoOrchestrationModule {
|
|
8
|
+
private status: AutoStatus = {
|
|
9
|
+
phase: "idle",
|
|
10
|
+
transitionCount: 0,
|
|
11
|
+
};
|
|
12
|
+
private readonly deps: AutoOrchestratorDeps;
|
|
13
|
+
private lastAdvanceKey: string | null = null;
|
|
14
|
+
|
|
15
|
+
public constructor(deps: AutoOrchestratorDeps) {
|
|
16
|
+
this.deps = deps;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public async start(_sessionContext: AutoSessionContext): Promise<AutoAdvanceResult> {
|
|
20
|
+
this.lastAdvanceKey = null;
|
|
21
|
+
this.status.phase = "running";
|
|
22
|
+
this.bumpTransition();
|
|
23
|
+
await this.deps.runtime.journalTransition({ name: "start" });
|
|
24
|
+
await this.deps.notifications.notifyLifecycle({ name: "start" });
|
|
25
|
+
return this.advance();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public async advance(): Promise<AutoAdvanceResult> {
|
|
29
|
+
try {
|
|
30
|
+
await this.deps.runtime.ensureLockOwnership();
|
|
31
|
+
const gate = await this.deps.health.preAdvanceGate();
|
|
32
|
+
if (!gate.allow) {
|
|
33
|
+
const blocked: AutoAdvanceResult = { kind: "blocked", reason: gate.reason ?? "health gate blocked" };
|
|
34
|
+
await this.deps.runtime.journalTransition({ name: "advance-blocked", reason: blocked.reason });
|
|
35
|
+
await this.deps.health.postAdvanceRecord(blocked);
|
|
36
|
+
return blocked;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const decision = await this.deps.dispatch.decideNextUnit();
|
|
40
|
+
if (!decision) {
|
|
41
|
+
const stopped: AutoAdvanceResult = { kind: "stopped", reason: "no remaining units" };
|
|
42
|
+
this.status.phase = "stopped";
|
|
43
|
+
this.status.activeUnit = undefined;
|
|
44
|
+
this.lastAdvanceKey = null;
|
|
45
|
+
this.bumpTransition();
|
|
46
|
+
await this.deps.runtime.journalTransition({ name: "advance-stopped", reason: stopped.reason });
|
|
47
|
+
await this.deps.health.postAdvanceRecord(stopped);
|
|
48
|
+
return stopped;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const nextKey = `${decision.unitType}:${decision.unitId}`;
|
|
52
|
+
if (this.lastAdvanceKey === nextKey) {
|
|
53
|
+
const blocked: AutoAdvanceResult = { kind: "blocked", reason: "idempotent advance: unit already active" };
|
|
54
|
+
await this.deps.runtime.journalTransition({
|
|
55
|
+
name: "advance-blocked",
|
|
56
|
+
reason: blocked.reason,
|
|
57
|
+
unitType: decision.unitType,
|
|
58
|
+
unitId: decision.unitId,
|
|
59
|
+
});
|
|
60
|
+
await this.deps.health.postAdvanceRecord(blocked);
|
|
61
|
+
return blocked;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
this.status.activeUnit = { unitType: decision.unitType, unitId: decision.unitId };
|
|
65
|
+
this.status.phase = "running";
|
|
66
|
+
this.lastAdvanceKey = nextKey;
|
|
67
|
+
this.bumpTransition();
|
|
68
|
+
|
|
69
|
+
await this.deps.runtime.journalTransition({
|
|
70
|
+
name: "advance",
|
|
71
|
+
reason: decision.reason,
|
|
72
|
+
unitType: decision.unitType,
|
|
73
|
+
unitId: decision.unitId,
|
|
74
|
+
});
|
|
75
|
+
await this.deps.worktree.prepareForUnit(decision.unitType, decision.unitId);
|
|
76
|
+
await this.deps.worktree.syncAfterUnit(decision.unitType, decision.unitId);
|
|
77
|
+
|
|
78
|
+
const advanced: AutoAdvanceResult = { kind: "advanced" };
|
|
79
|
+
await this.deps.health.postAdvanceRecord(advanced);
|
|
80
|
+
return advanced;
|
|
81
|
+
} catch (error) {
|
|
82
|
+
const recovery = await this.deps.recovery.classifyAndRecover({
|
|
83
|
+
error,
|
|
84
|
+
unitType: this.status.activeUnit?.unitType,
|
|
85
|
+
unitId: this.status.activeUnit?.unitId,
|
|
86
|
+
});
|
|
87
|
+
const result: AutoAdvanceResult = recovery.action === "retry"
|
|
88
|
+
? { kind: "paused", reason: recovery.reason }
|
|
89
|
+
: recovery.action === "escalate"
|
|
90
|
+
? { kind: "error", reason: recovery.reason }
|
|
91
|
+
: { kind: "stopped", reason: recovery.reason };
|
|
92
|
+
|
|
93
|
+
if (result.kind === "paused") {
|
|
94
|
+
this.status.phase = "paused";
|
|
95
|
+
} else if (result.kind === "stopped") {
|
|
96
|
+
this.status.phase = "stopped";
|
|
97
|
+
} else {
|
|
98
|
+
this.status.phase = "error";
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (result.kind === "stopped") {
|
|
102
|
+
this.lastAdvanceKey = null;
|
|
103
|
+
this.status.activeUnit = undefined;
|
|
104
|
+
}
|
|
105
|
+
this.bumpTransition();
|
|
106
|
+
|
|
107
|
+
const journalName = result.kind === "paused"
|
|
108
|
+
? "advance-paused"
|
|
109
|
+
: result.kind === "stopped"
|
|
110
|
+
? "advance-stopped"
|
|
111
|
+
: "advance-error";
|
|
112
|
+
await this.deps.runtime.journalTransition({ name: journalName, reason: recovery.reason });
|
|
113
|
+
|
|
114
|
+
if (result.kind === "paused") {
|
|
115
|
+
await this.deps.notifications.notifyLifecycle({ name: "pause", detail: recovery.reason });
|
|
116
|
+
} else if (result.kind === "stopped") {
|
|
117
|
+
await this.deps.notifications.notifyLifecycle({ name: "stopped", detail: recovery.reason });
|
|
118
|
+
} else if (result.kind === "error") {
|
|
119
|
+
await this.deps.notifications.notifyLifecycle({ name: "error", detail: recovery.reason });
|
|
120
|
+
}
|
|
121
|
+
await this.deps.health.postAdvanceRecord(result);
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
public async resume(): Promise<AutoAdvanceResult> {
|
|
127
|
+
this.lastAdvanceKey = null;
|
|
128
|
+
this.status.phase = "running";
|
|
129
|
+
this.bumpTransition();
|
|
130
|
+
await this.deps.runtime.journalTransition({ name: "resume" });
|
|
131
|
+
await this.deps.notifications.notifyLifecycle({ name: "resume" });
|
|
132
|
+
return this.advance();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
public async stop(reason: string): Promise<AutoAdvanceResult> {
|
|
136
|
+
if (this.status.phase === "stopped") {
|
|
137
|
+
return { kind: "stopped", reason };
|
|
138
|
+
}
|
|
139
|
+
await this.deps.worktree.cleanupOnStop(reason);
|
|
140
|
+
this.status.phase = "stopped";
|
|
141
|
+
this.status.activeUnit = undefined;
|
|
142
|
+
this.lastAdvanceKey = null;
|
|
143
|
+
this.bumpTransition();
|
|
144
|
+
await this.deps.runtime.journalTransition({ name: "stop", reason });
|
|
145
|
+
await this.deps.notifications.notifyLifecycle({ name: "stop", detail: reason });
|
|
146
|
+
return { kind: "stopped", reason };
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
public getStatus(): AutoStatus {
|
|
150
|
+
return { ...this.status, activeUnit: this.status.activeUnit ? { ...this.status.activeUnit } : undefined };
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
private bumpTransition(): void {
|
|
154
|
+
this.status.transitionCount += 1;
|
|
155
|
+
this.status.lastTransitionAt = now();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function createAutoOrchestrator(deps: AutoOrchestratorDeps): AutoOrchestrationModule {
|
|
160
|
+
return new AutoOrchestrator(deps);
|
|
161
|
+
}
|
|
@@ -55,7 +55,7 @@ import { writeUnitRuntimeRecord } from "../unit-runtime.js";
|
|
|
55
55
|
import { withTimeout, FINALIZE_PRE_TIMEOUT_MS, FINALIZE_POST_TIMEOUT_MS } from "./finalize-timeout.js";
|
|
56
56
|
import { getEligibleSlices } from "../slice-parallel-eligibility.js";
|
|
57
57
|
import { startSliceParallel } from "../slice-parallel-orchestrator.js";
|
|
58
|
-
import { isDbAvailable, getMilestoneSlices } from "../gsd-db.js";
|
|
58
|
+
import { isDbAvailable, getMilestoneSlices, refreshOpenDatabaseFromDisk } from "../gsd-db.js";
|
|
59
59
|
import type { MinimalModelRegistry } from "../context-budget.js";
|
|
60
60
|
import { ensurePlanV2Graph, isEmptyPlanV2GraphResult, isMissingFinalizedContextResult } from "../uok/plan-v2.js";
|
|
61
61
|
import { resolveUokFlags } from "../uok/flags.js";
|
|
@@ -76,6 +76,12 @@ function isSamePathLocal(a: string, b: string): boolean {
|
|
|
76
76
|
return normalizeWorktreePathForCompare(a) === normalizeWorktreePathForCompare(b);
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
function refreshPlanSliceRecoveryDbIfNeeded(unitType: string): boolean {
|
|
80
|
+
if (unitType !== "plan-slice") return true;
|
|
81
|
+
if (!isDbAvailable()) return true;
|
|
82
|
+
return refreshOpenDatabaseFromDisk();
|
|
83
|
+
}
|
|
84
|
+
|
|
79
85
|
// ─── Session timeout auto-resume state ────────────────────────────────────────
|
|
80
86
|
|
|
81
87
|
let consecutiveSessionTimeouts = 0;
|
|
@@ -232,6 +238,33 @@ async function emitCancelledUnitEnd(
|
|
|
232
238
|
});
|
|
233
239
|
}
|
|
234
240
|
|
|
241
|
+
export function _buildCancelledUnitStopReason(
|
|
242
|
+
unitType: string,
|
|
243
|
+
unitId: string,
|
|
244
|
+
errorContext?: { message: string; category: string },
|
|
245
|
+
): {
|
|
246
|
+
notifyMessage: string;
|
|
247
|
+
stopReason: string;
|
|
248
|
+
loopReason: "session-failed" | "unit-aborted";
|
|
249
|
+
} {
|
|
250
|
+
const cancellationMessage = errorContext?.message ?? "unknown";
|
|
251
|
+
const isSessionCreationFailure = errorContext?.category === "session-failed";
|
|
252
|
+
|
|
253
|
+
if (isSessionCreationFailure) {
|
|
254
|
+
return {
|
|
255
|
+
notifyMessage: `Session creation failed for ${unitType} ${unitId}: ${cancellationMessage}. Stopping auto-mode.`,
|
|
256
|
+
stopReason: `Session creation failed: ${cancellationMessage}`,
|
|
257
|
+
loopReason: "session-failed",
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return {
|
|
262
|
+
notifyMessage: `Unit ${unitType} ${unitId} aborted after dispatch: ${cancellationMessage}. Stopping auto-mode.`,
|
|
263
|
+
stopReason: `Unit aborted: ${cancellationMessage}`,
|
|
264
|
+
loopReason: "unit-aborted",
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
|
|
235
268
|
async function failClosedOnFinalizeTimeout(
|
|
236
269
|
ic: IterationContext,
|
|
237
270
|
iterData: IterationData,
|
|
@@ -994,7 +1027,10 @@ export async function runDispatch(
|
|
|
994
1027
|
// See: https://github.com/gsd-build/gsd-2/issues/2474
|
|
995
1028
|
if (dispatchResult.level === "warning") {
|
|
996
1029
|
ctx.ui.notify(dispatchResult.reason, "warning");
|
|
997
|
-
await deps.pauseAuto(ctx, pi
|
|
1030
|
+
await deps.pauseAuto(ctx, pi, {
|
|
1031
|
+
message: dispatchResult.reason,
|
|
1032
|
+
category: "unknown",
|
|
1033
|
+
});
|
|
998
1034
|
} else {
|
|
999
1035
|
await closeoutAndStop(ctx, pi, s, deps, dispatchResult.reason);
|
|
1000
1036
|
}
|
|
@@ -1065,7 +1101,16 @@ export async function runDispatch(
|
|
|
1065
1101
|
`Stuck recovery: artifact for ${unitType} ${unitId} found on disk. Invalidating caches.`,
|
|
1066
1102
|
"info",
|
|
1067
1103
|
);
|
|
1104
|
+
if (!refreshPlanSliceRecoveryDbIfNeeded(unitType)) {
|
|
1105
|
+
ctx.ui.notify(
|
|
1106
|
+
`Stuck recovery found ${unitType} ${unitId} artifacts, but the DB refresh failed. Keeping stuck state for retry.`,
|
|
1107
|
+
"warning",
|
|
1108
|
+
);
|
|
1109
|
+
return { action: "continue" };
|
|
1110
|
+
}
|
|
1068
1111
|
deps.invalidateAllCaches();
|
|
1112
|
+
loopState.recentUnits.length = 0;
|
|
1113
|
+
loopState.stuckRecoveryAttempts = 0;
|
|
1069
1114
|
return { action: "continue" };
|
|
1070
1115
|
}
|
|
1071
1116
|
ctx.ui.notify(
|
|
@@ -1075,6 +1120,32 @@ export async function runDispatch(
|
|
|
1075
1120
|
deps.invalidateAllCaches();
|
|
1076
1121
|
} else {
|
|
1077
1122
|
// Level 2: hard stop — genuinely stuck
|
|
1123
|
+
deps.invalidateAllCaches();
|
|
1124
|
+
const artifactExists = verifyExpectedArtifact(
|
|
1125
|
+
unitType,
|
|
1126
|
+
unitId,
|
|
1127
|
+
s.basePath,
|
|
1128
|
+
);
|
|
1129
|
+
if (artifactExists && unitType !== "complete-milestone") {
|
|
1130
|
+
debugLog("autoLoop", {
|
|
1131
|
+
phase: "stuck-recovery",
|
|
1132
|
+
level: 2,
|
|
1133
|
+
action: "artifact-found",
|
|
1134
|
+
});
|
|
1135
|
+
ctx.ui.notify(
|
|
1136
|
+
`Stuck recovery: artifact for ${unitType} ${unitId} found on disk after cache invalidation. Continuing.`,
|
|
1137
|
+
"info",
|
|
1138
|
+
);
|
|
1139
|
+
if (refreshPlanSliceRecoveryDbIfNeeded(unitType)) {
|
|
1140
|
+
loopState.recentUnits.length = 0;
|
|
1141
|
+
loopState.stuckRecoveryAttempts = 0;
|
|
1142
|
+
return { action: "continue" };
|
|
1143
|
+
}
|
|
1144
|
+
ctx.ui.notify(
|
|
1145
|
+
`Stuck recovery found ${unitType} ${unitId} artifacts, but the DB refresh failed. Stopping for manual recovery.`,
|
|
1146
|
+
"warning",
|
|
1147
|
+
);
|
|
1148
|
+
}
|
|
1078
1149
|
debugLog("autoLoop", {
|
|
1079
1150
|
phase: "stuck-detected",
|
|
1080
1151
|
unitType,
|
|
@@ -1470,7 +1541,12 @@ export async function runUnitPhase(
|
|
|
1470
1541
|
s.lastGitActionFailure = null;
|
|
1471
1542
|
s.lastGitActionStatus = null;
|
|
1472
1543
|
s.lastUnitAgentEndMessages = null;
|
|
1473
|
-
setCurrentPhase(unitType
|
|
1544
|
+
setCurrentPhase(unitType, {
|
|
1545
|
+
basePath: s.basePath,
|
|
1546
|
+
traceId: ic.flowId,
|
|
1547
|
+
turnId: `iter-${ic.iteration}`,
|
|
1548
|
+
causedBy: "unit-start",
|
|
1549
|
+
});
|
|
1474
1550
|
s.lastToolInvocationError = null; // #2883: clear stale error from previous unit
|
|
1475
1551
|
const unitStartSeq = ic.nextSeq();
|
|
1476
1552
|
deps.emitJournalEvent({ ts: new Date().toISOString(), flowId: ic.flowId, seq: unitStartSeq, eventType: "unit-start", data: { unitType, unitId } });
|
|
@@ -1866,13 +1942,16 @@ export async function runUnitPhase(
|
|
|
1866
1942
|
}
|
|
1867
1943
|
await deps.autoCommitUnit?.(s.basePath, unitType, unitId, ctx);
|
|
1868
1944
|
await emitCancelledUnitEnd(ic, unitType, unitId, unitStartSeq, unitResult.errorContext);
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1945
|
+
|
|
1946
|
+
const cancelledStop = _buildCancelledUnitStopReason(
|
|
1947
|
+
unitType,
|
|
1948
|
+
unitId,
|
|
1949
|
+
unitResult.errorContext,
|
|
1872
1950
|
);
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1951
|
+
ctx.ui.notify(cancelledStop.notifyMessage, "warning");
|
|
1952
|
+
await deps.stopAuto(ctx, pi, cancelledStop.stopReason);
|
|
1953
|
+
debugLog("autoLoop", { phase: "exit", reason: cancelledStop.loopReason });
|
|
1954
|
+
return { action: "break", reason: cancelledStop.loopReason };
|
|
1876
1955
|
}
|
|
1877
1956
|
|
|
1878
1957
|
// ── Immediate unit closeout (metrics, activity log, memory) ────────
|
|
@@ -21,6 +21,7 @@ import type { ExtensionAPI, ExtensionCommandContext } from "@gsd/pi-coding-agent
|
|
|
21
21
|
import type { GitServiceImpl } from "../git-service.js";
|
|
22
22
|
import type { CaptureEntry } from "../captures.js";
|
|
23
23
|
import type { BudgetAlertLevel } from "../auto-budget.js";
|
|
24
|
+
import type { AutoOrchestrationModule } from "./contracts.js";
|
|
24
25
|
import { resolveWorktreeProjectRoot } from "../worktree-root.js";
|
|
25
26
|
import { normalizeRealPath } from "../paths.js";
|
|
26
27
|
import type { MilestoneScope } from "../workspace.js";
|
|
@@ -229,6 +230,9 @@ export class AutoSession {
|
|
|
229
230
|
/** Cleanup function returned by startCommandPolling(); null when not running. */
|
|
230
231
|
commandPollingCleanup: (() => void) | null = null;
|
|
231
232
|
|
|
233
|
+
// ── Orchestration seam ───────────────────────────────────────────────────
|
|
234
|
+
orchestration: AutoOrchestrationModule | null = null;
|
|
235
|
+
|
|
232
236
|
// ── Loop promise state ──────────────────────────────────────────────────
|
|
233
237
|
// Per-unit resolve function and session-switch guard live at module level
|
|
234
238
|
// in auto-loop.ts (_currentResolve, _sessionSwitchInFlight).
|
|
@@ -354,10 +358,14 @@ export class AutoSession {
|
|
|
354
358
|
// Remote command polling — cleanup must be called before reset (auto.ts stopAuto)
|
|
355
359
|
this.commandPollingCleanup = null;
|
|
356
360
|
|
|
361
|
+
// Orchestration seam
|
|
362
|
+
this.orchestration = null;
|
|
363
|
+
|
|
357
364
|
// Loop promise state lives in auto-loop.ts module scope
|
|
358
365
|
}
|
|
359
366
|
|
|
360
367
|
toJSON(): Record<string, unknown> {
|
|
368
|
+
const orchestrationStatus = this.orchestration?.getStatus();
|
|
361
369
|
return {
|
|
362
370
|
active: this.active,
|
|
363
371
|
paused: this.paused,
|
|
@@ -367,6 +375,9 @@ export class AutoSession {
|
|
|
367
375
|
activeRunDir: this.activeRunDir,
|
|
368
376
|
currentMilestoneId: this.currentMilestoneId,
|
|
369
377
|
currentUnit: this.currentUnit,
|
|
378
|
+
orchestrationPhase: orchestrationStatus?.phase,
|
|
379
|
+
orchestrationTransitionCount: orchestrationStatus?.transitionCount,
|
|
380
|
+
orchestrationLastTransitionAt: orchestrationStatus?.lastTransitionAt,
|
|
370
381
|
unitDispatchCount: Object.fromEntries(this.unitDispatchCount),
|
|
371
382
|
};
|
|
372
383
|
}
|
|
@@ -159,9 +159,9 @@ export function diagnoseExpectedArtifact(
|
|
|
159
159
|
}
|
|
160
160
|
return `${relSliceFile(base, mid, sid!, "RESEARCH")} (slice research)`;
|
|
161
161
|
case "plan-slice":
|
|
162
|
-
return `${relSliceFile(base, mid, sid!, "PLAN")} (slice plan)`;
|
|
162
|
+
return `${relSliceFile(base, mid, sid!, "PLAN")} plus tasks/T##-PLAN.md files (slice plan and task plans)`;
|
|
163
163
|
case "refine-slice":
|
|
164
|
-
return `${relSliceFile(base, mid, sid!, "PLAN")} (refined slice plan
|
|
164
|
+
return `${relSliceFile(base, mid, sid!, "PLAN")} plus tasks/T##-PLAN.md files (refined slice plan and task plans)`;
|
|
165
165
|
case "execute-task": {
|
|
166
166
|
return `Task ${tid} marked [x] in ${relSliceFile(base, mid, sid!, "PLAN")} + summary written`;
|
|
167
167
|
}
|
|
@@ -692,6 +692,7 @@ export const DISPATCH_RULES: DispatchRule[] = [
|
|
|
692
692
|
const contextFile = resolveMilestoneFile(basePath, mid, "CONTEXT");
|
|
693
693
|
const hasContext = !!(contextFile && (await loadFile(contextFile)));
|
|
694
694
|
if (hasContext) return null; // fall through to next rule
|
|
695
|
+
if (prefs?.planning_depth === "deep") return null;
|
|
695
696
|
// H6 fix (#4973): keep the non-deep auto-mode bypass, but do not
|
|
696
697
|
// pre-verify deep planning's user-facing milestone approval gate.
|
|
697
698
|
if (shouldBypassMilestoneDepthGateInAuto(prefs)) {
|
|
@@ -14,7 +14,7 @@ import { appendEvent } from "./workflow-events.js";
|
|
|
14
14
|
import { atomicWriteSync } from "./atomic-write.js";
|
|
15
15
|
import { clearParseCache } from "./files.js";
|
|
16
16
|
import { parseRoadmap as parseLegacyRoadmap, parsePlan as parseLegacyPlan } from "./parsers-legacy.js";
|
|
17
|
-
import { isDbAvailable, getTask, getSlice, getSliceTasks, getPendingGates, updateTaskStatus, updateSliceStatus, insertSlice, getMilestone } from "./gsd-db.js";
|
|
17
|
+
import { isDbAvailable, getTask, getSlice, getSliceTasks, getPendingGates, updateTaskStatus, updateSliceStatus, insertSlice, getMilestone, refreshOpenDatabaseFromDisk } from "./gsd-db.js";
|
|
18
18
|
import { isValidationTerminal } from "./state.js";
|
|
19
19
|
import { getErrorMessage } from "./error-utils.js";
|
|
20
20
|
import { logWarning, logError } from "./workflow-logger.js";
|
|
@@ -308,7 +308,7 @@ function scanGsdTaggedCommits(
|
|
|
308
308
|
if (!commitMessageHasGsdTrailer(message)) continue;
|
|
309
309
|
|
|
310
310
|
const commitFiles = getChangedFilesForCommit(basePath, hash);
|
|
311
|
-
if (!commitMatchesMilestone(message, milestoneId, commitFiles)) continue;
|
|
311
|
+
if (!commitMatchesMilestone(basePath, message, milestoneId, commitFiles)) continue;
|
|
312
312
|
|
|
313
313
|
matched = true;
|
|
314
314
|
for (const file of commitFiles) {
|
|
@@ -336,22 +336,36 @@ function commitMessageHasGsdTrailer(message: string): boolean {
|
|
|
336
336
|
return /^GSD-(?:Task|Unit):\s*\S+/m.test(message);
|
|
337
337
|
}
|
|
338
338
|
|
|
339
|
-
function commitMatchesMilestone(message: string, milestoneId: string, files: readonly string[]): boolean {
|
|
339
|
+
function commitMatchesMilestone(basePath: string, message: string, milestoneId: string, files: readonly string[]): boolean {
|
|
340
340
|
if (commitTrailerStartsWithMilestone(message, milestoneId)) return true;
|
|
341
341
|
|
|
342
342
|
// Meaningful execute-task commits currently store task scope as Sxx/Tyy
|
|
343
343
|
// rather than Mxx/Sxx/Tyy. Bind those commits back to the milestone when
|
|
344
344
|
// either the commit touched this milestone's artifacts, or — for projects
|
|
345
345
|
// where .gsd/ is gitignored/external (#5033) — the message explicitly
|
|
346
|
-
// names the milestone.
|
|
346
|
+
// names the milestone or local GSD state proves the task belongs here.
|
|
347
347
|
if (/^GSD-Task:\s*S[^/\s]+\/T\S+/m.test(message)) {
|
|
348
348
|
if (files.some((file) => isMilestoneArtifactPath(file, milestoneId))) return true;
|
|
349
349
|
if (commitMessageMentionsMilestone(message, milestoneId)) return true;
|
|
350
|
+
if (commitTaskTrailerBelongsToMilestone(basePath, message, milestoneId)) return true;
|
|
350
351
|
}
|
|
351
352
|
|
|
352
353
|
return false;
|
|
353
354
|
}
|
|
354
355
|
|
|
356
|
+
function commitTaskTrailerBelongsToMilestone(basePath: string, message: string, milestoneId: string): boolean {
|
|
357
|
+
const match = message.match(/^GSD-Task:\s*(S[^/\s]+)\/(T[^\s]+)/m);
|
|
358
|
+
if (!match) return false;
|
|
359
|
+
const [, sliceId, taskId] = match;
|
|
360
|
+
|
|
361
|
+
if (getTask(milestoneId, sliceId, taskId)) return true;
|
|
362
|
+
|
|
363
|
+
const tasksDir = resolveTasksDir(basePath, milestoneId, sliceId);
|
|
364
|
+
if (!tasksDir) return false;
|
|
365
|
+
return existsSync(join(tasksDir, `${taskId}-PLAN.md`))
|
|
366
|
+
|| existsSync(join(tasksDir, `${taskId}-SUMMARY.md`));
|
|
367
|
+
}
|
|
368
|
+
|
|
355
369
|
function commitMessageMentionsMilestone(message: string, milestoneId: string): boolean {
|
|
356
370
|
if (!MILESTONE_ID_RE.test(milestoneId)) return false;
|
|
357
371
|
|
|
@@ -574,65 +588,32 @@ export function verifyExpectedArtifact(
|
|
|
574
588
|
}
|
|
575
589
|
}
|
|
576
590
|
|
|
577
|
-
// plan-slice
|
|
578
|
-
//
|
|
579
|
-
//
|
|
580
|
-
// unit gets skipped — but deriveState still returns phase:"planning" because the
|
|
581
|
-
// plan has no tasks, creating an infinite skip loop (#699).
|
|
582
|
-
if (unitType === "plan-slice") {
|
|
583
|
-
const planContent = readFileSync(absPath, "utf-8");
|
|
584
|
-
// Accept checkbox-style (- [x] **T01: ...) or heading-style (### T01 -- / ### T01: / ### T01 —)
|
|
585
|
-
const hasCheckboxTask = /^- \[[xX ]\] \*\*T\d+:/m.test(planContent);
|
|
586
|
-
const hasHeadingTask = /^#{2,4}\s+T\d+\s*(?:--|—|:)/m.test(planContent);
|
|
587
|
-
if (!hasCheckboxTask && !hasHeadingTask) {
|
|
588
|
-
logWarning("recovery", `verify-fail ${unitType} ${unitId}: plan has no task checkbox/heading (len=${planContent.length}) at ${absPath}`);
|
|
589
|
-
return false;
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
// execute-task: DB status is authoritative. Fall back to checked-checkbox
|
|
594
|
-
// detection when the DB is unavailable (unmigrated projects), or when the
|
|
595
|
-
// disk artifacts already reflect completion but the DB replay is one beat
|
|
596
|
-
// behind the completion write.
|
|
597
|
-
if (unitType === "execute-task") {
|
|
598
|
-
const { milestone: mid, slice: sid, task: tid } = parseUnitId(unitId);
|
|
599
|
-
if (mid && sid && tid) {
|
|
600
|
-
const dbTask = getTask(mid, sid, tid);
|
|
601
|
-
if (dbTask) {
|
|
602
|
-
if (dbTask.status !== "complete" && dbTask.status !== "done" && !hasCheckedTaskCompletionOnDisk(base, mid, sid, tid)) {
|
|
603
|
-
return false;
|
|
604
|
-
}
|
|
605
|
-
} else if (!isDbAvailable()) {
|
|
606
|
-
// LEGACY: Pre-migration fallback for projects without DB.
|
|
607
|
-
// Require a CHECKED checkbox — a bare heading or unchecked checkbox
|
|
608
|
-
// does not prove gsd_complete_task ran. Summary file on disk alone
|
|
609
|
-
// is not sufficient evidence (could be a rogue write) (#3607).
|
|
610
|
-
if (!hasCheckedTaskCompletionOnDisk(base, mid, sid, tid)) return false;
|
|
611
|
-
} else {
|
|
612
|
-
// DB available but task row not found — completion tool never ran (#3607)
|
|
613
|
-
return false;
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
// plan-slice must also produce individual task plan files for every task listed
|
|
619
|
-
// in the slice plan. Without this check, a plan-slice that wrote S{sid}-PLAN.md
|
|
620
|
-
// but omitted T{tid}-PLAN.md files would be marked complete, causing execute-task
|
|
621
|
-
// to dispatch with a missing task plan (see issue #739).
|
|
591
|
+
// plan-slice verification is DB-primary. The slice plan is a projection, so
|
|
592
|
+
// DB task rows prove the slice was planned even if the rendered markdown no
|
|
593
|
+
// longer uses legacy checkbox/heading syntax.
|
|
622
594
|
if (unitType === "plan-slice") {
|
|
623
595
|
const { milestone: mid, slice: sid } = parseUnitId(unitId);
|
|
624
596
|
if (mid && sid) {
|
|
625
597
|
try {
|
|
626
|
-
// DB primary path — get task IDs to verify task plan files exist
|
|
627
598
|
let taskIds: string[] | null = null;
|
|
628
599
|
if (isDbAvailable()) {
|
|
629
|
-
const
|
|
630
|
-
if (
|
|
600
|
+
const refreshed = refreshOpenDatabaseFromDisk();
|
|
601
|
+
if (refreshed) {
|
|
602
|
+
const tasks = getSliceTasks(mid, sid);
|
|
603
|
+
if (tasks.length > 0) taskIds = tasks.map(t => t.id);
|
|
604
|
+
}
|
|
631
605
|
}
|
|
632
606
|
|
|
633
607
|
if (!taskIds) {
|
|
634
|
-
// LEGACY: DB unavailable or no tasks in DB
|
|
608
|
+
// LEGACY: DB unavailable or no tasks in DB. Require actual task
|
|
609
|
+
// entries so an empty scaffold cannot advance the pipeline (#699).
|
|
635
610
|
const planContent = readFileSync(absPath, "utf-8");
|
|
611
|
+
const hasCheckboxTask = /^\s*- \[[xX ]\] \*\*T\d+:/m.test(planContent);
|
|
612
|
+
const hasHeadingTask = /^\s*#{2,4}\s+T\d+\s*(?:--|—|:)/m.test(planContent);
|
|
613
|
+
if (!hasCheckboxTask && !hasHeadingTask) {
|
|
614
|
+
logWarning("recovery", `verify-fail ${unitType} ${unitId}: plan has no task checkbox/heading (len=${planContent.length}) at ${absPath}`);
|
|
615
|
+
return false;
|
|
616
|
+
}
|
|
636
617
|
const plan = parseLegacyPlan(planContent);
|
|
637
618
|
if (plan.tasks.length > 0) taskIds = plan.tasks.map((t: { id: string }) => t.id);
|
|
638
619
|
}
|
|
@@ -658,6 +639,31 @@ export function verifyExpectedArtifact(
|
|
|
658
639
|
}
|
|
659
640
|
}
|
|
660
641
|
|
|
642
|
+
// execute-task: DB status is authoritative. Fall back to checked-checkbox
|
|
643
|
+
// detection when the DB is unavailable (unmigrated projects), or when the
|
|
644
|
+
// disk artifacts already reflect completion but the DB replay is one beat
|
|
645
|
+
// behind the completion write.
|
|
646
|
+
if (unitType === "execute-task") {
|
|
647
|
+
const { milestone: mid, slice: sid, task: tid } = parseUnitId(unitId);
|
|
648
|
+
if (mid && sid && tid) {
|
|
649
|
+
const dbTask = getTask(mid, sid, tid);
|
|
650
|
+
if (dbTask) {
|
|
651
|
+
if (dbTask.status !== "complete" && dbTask.status !== "done" && !hasCheckedTaskCompletionOnDisk(base, mid, sid, tid)) {
|
|
652
|
+
return false;
|
|
653
|
+
}
|
|
654
|
+
} else if (!isDbAvailable()) {
|
|
655
|
+
// LEGACY: Pre-migration fallback for projects without DB.
|
|
656
|
+
// Require a CHECKED checkbox — a bare heading or unchecked checkbox
|
|
657
|
+
// does not prove gsd_complete_task ran. Summary file on disk alone
|
|
658
|
+
// is not sufficient evidence (could be a rogue write) (#3607).
|
|
659
|
+
if (!hasCheckedTaskCompletionOnDisk(base, mid, sid, tid)) return false;
|
|
660
|
+
} else {
|
|
661
|
+
// DB available but task row not found — completion tool never ran (#3607)
|
|
662
|
+
return false;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
|
|
661
667
|
// complete-slice: DB status is authoritative for whether the slice is done.
|
|
662
668
|
// Fall back to file-based check (roadmap [x]) when DB is unavailable.
|
|
663
669
|
if (unitType === "complete-slice") {
|
|
@@ -16,14 +16,21 @@ export type AutoRuntimeSnapshot = {
|
|
|
16
16
|
paused: boolean;
|
|
17
17
|
currentUnit: CurrentUnit | null;
|
|
18
18
|
basePath: string;
|
|
19
|
+
orchestrationPhase?: "idle" | "running" | "paused" | "stopped" | "error";
|
|
20
|
+
orchestrationTransitionCount?: number;
|
|
21
|
+
orchestrationLastTransitionAt?: number;
|
|
19
22
|
};
|
|
20
23
|
|
|
21
24
|
export function getAutoRuntimeSnapshot(): AutoRuntimeSnapshot {
|
|
25
|
+
const orchestrationStatus = autoSession.orchestration?.getStatus();
|
|
22
26
|
return {
|
|
23
27
|
active: autoSession.active,
|
|
24
28
|
paused: autoSession.paused,
|
|
25
29
|
currentUnit: autoSession.currentUnit ? { ...autoSession.currentUnit } : null,
|
|
26
30
|
basePath: autoSession.basePath,
|
|
31
|
+
orchestrationPhase: orchestrationStatus?.phase,
|
|
32
|
+
orchestrationTransitionCount: orchestrationStatus?.transitionCount,
|
|
33
|
+
orchestrationLastTransitionAt: orchestrationStatus?.lastTransitionAt,
|
|
27
34
|
};
|
|
28
35
|
}
|
|
29
36
|
|
|
@@ -663,9 +663,10 @@ export async function bootstrapAutoSession(
|
|
|
663
663
|
hasSurvivorBranch = false;
|
|
664
664
|
}
|
|
665
665
|
|
|
666
|
+
const effectivePrefs = loadEffectiveGSDPreferences(base)?.preferences;
|
|
666
667
|
const deepProjectStagePending = !hasSurvivorBranch
|
|
667
668
|
? (await import("./auto-dispatch.js")).hasPendingDeepStage(
|
|
668
|
-
|
|
669
|
+
effectivePrefs,
|
|
669
670
|
base,
|
|
670
671
|
)
|
|
671
672
|
: false;
|
|
@@ -714,7 +715,7 @@ export async function bootstrapAutoSession(
|
|
|
714
715
|
const mid = state.activeMilestone!.id;
|
|
715
716
|
const contextFile = resolveMilestoneFile(base, mid, "CONTEXT");
|
|
716
717
|
const hasContext = !!(contextFile && (await loadFile(contextFile)));
|
|
717
|
-
if (!hasContext) {
|
|
718
|
+
if (!hasContext && effectivePrefs?.planning_depth !== "deep") {
|
|
718
719
|
const { showSmartEntry } = await import("./guided-flow.js");
|
|
719
720
|
await showSmartEntry(ctx, pi, base, { step: requestedStepMode });
|
|
720
721
|
|