specdojo 0.3.0 → 0.3.1
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/CHANGELOG.md +18 -0
- package/dist/catalog-build-references.js +144 -0
- package/dist/catalog-build-render.js +144 -0
- package/dist/catalog-build.js +13 -290
- package/dist/catalog-generate.js +6 -9
- package/dist/catalog-plan-generate.js +2 -2
- package/dist/catalog-plan.js +6 -6
- package/dist/catalog-scaffold.js +4 -4
- package/dist/catalog.js +2 -2
- package/dist/dashboard-exec-records.js +105 -0
- package/dist/dashboard-routines.js +255 -0
- package/dist/dashboard-shared.js +14 -0
- package/dist/dashboard-timeline.js +175 -0
- package/dist/dashboard.js +10 -544
- package/dist/deliverable-trash.js +3 -3
- package/dist/doc-index.js +3 -3
- package/dist/exec-commands.js +557 -0
- package/dist/exec-core.js +457 -0
- package/dist/exec-plans-core.js +693 -0
- package/dist/exec-plans-generation.js +206 -0
- package/dist/exec-plans-storage.js +131 -0
- package/dist/exec-plans.js +3 -1018
- package/dist/exec-repo-integration-git.js +23 -0
- package/dist/exec-repo-integration-sync.js +264 -0
- package/dist/exec-repo-integration.js +4 -281
- package/dist/exec-reporter-output.js +206 -0
- package/dist/exec-reporter.js +2 -206
- package/dist/exec-results.js +22 -15
- package/dist/exec-run-agent-pipeline.js +256 -0
- package/dist/exec-run-agent.js +531 -0
- package/dist/exec-run-in-place.js +541 -0
- package/dist/exec-run-job.js +717 -0
- package/dist/exec-run-lifecycle-commands.js +522 -0
- package/dist/exec-run-mode-shared.js +140 -0
- package/dist/exec-run-register-command.js +244 -0
- package/dist/exec-run-register-core.js +386 -0
- package/dist/exec-run-register-mode.js +206 -0
- package/dist/exec-run-register-resume.js +393 -0
- package/dist/exec-run-register-state.js +322 -0
- package/dist/exec-run-register-worktree.js +509 -0
- package/dist/exec-run-schedule-mode.js +294 -0
- package/dist/exec-run-schedule-prepare.js +353 -0
- package/dist/exec-run-schedule-task.js +572 -0
- package/dist/exec-run-shared.js +399 -0
- package/dist/exec-run.js +11 -6182
- package/dist/exec-shared.js +2 -2
- package/dist/exec-trial-commands.js +558 -0
- package/dist/exec-trial-core.js +371 -0
- package/dist/exec-trial.js +2 -921
- package/dist/exec-worktree-ops-commit.js +707 -0
- package/dist/exec-worktree-ops-lifecycle.js +292 -0
- package/dist/exec-worktree-ops-merge.js +303 -0
- package/dist/exec-worktree-ops.js +3 -1292
- package/dist/exec-worktree.js +32 -4
- package/dist/exec.js +2 -1006
- package/dist/frontmatter-namespace.js +2 -2
- package/dist/grade-apply.js +734 -0
- package/dist/grade-command-apply.js +250 -0
- package/dist/grade-command-inspect.js +138 -0
- package/dist/grade-command-plan.js +101 -0
- package/dist/grade-command-shared.js +68 -0
- package/dist/grade-core.js +307 -0
- package/dist/grade-markdown.js +274 -0
- package/dist/grade-pipeline-state.js +184 -0
- package/dist/grade-plan.js +507 -0
- package/dist/grade-result.js +5 -5
- package/dist/grade-target-discovery.js +265 -0
- package/dist/grade-targets.js +432 -0
- package/dist/grade.js +14 -3188
- package/dist/init-command.js +7 -7
- package/dist/job-definition.js +670 -0
- package/dist/job.js +9 -673
- package/dist/kata-command.js +2 -2
- package/dist/register-command-types.js +1 -0
- package/dist/register-core.js +363 -0
- package/dist/register-create-commands.js +245 -0
- package/dist/register-events.js +4 -4
- package/dist/register-item.js +6 -6
- package/dist/register-maintenance-commands.js +187 -0
- package/dist/register-migration.js +268 -0
- package/dist/register-renumber.js +314 -0
- package/dist/register-transition-commands.js +248 -0
- package/dist/register-update.js +230 -0
- package/dist/register-views.js +256 -0
- package/dist/register.js +61 -2069
- package/dist/review-plan.js +3 -3
- package/dist/routine-definition.js +401 -0
- package/dist/routine.js +6 -402
- package/dist/schedule-approach.js +2 -2
- package/dist/schedule-strategy-generate-document.js +273 -0
- package/dist/schedule-strategy-generate-scope.js +199 -0
- package/dist/schedule-strategy-generate.js +9 -473
- package/dist/schedule.js +4 -4
- package/dist/specdojo-config.js +3 -4
- package/dist/viewpoint-document-kinds-check.js +3 -3
- package/dist/yaml-pages.js +4 -4
- package/dist/yaml.js +28 -0
- package/docs/ja/specdojo/guides/exec-config-guide.md +6 -6
- package/docs/ja/specdojo/guides/orchestrator-operation-guide.md +20 -18
- package/docs/ja/specdojo/guides/routine-operation-guide.md +1 -1
- package/package.json +4 -5
- package/templates/antigravity/README.md +3 -3
- package/templates/antigravity/exec-defaults-snippet.yaml +6 -4
- package/templates/init-exec-defaults.yaml +3 -1
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { basename, join } from "node:path";
|
|
3
|
+
import { createProviderCapacityTracker, loadExecDefaultsConfig } from "./exec-agent-config.js";
|
|
4
|
+
import { activateResolvedProjectPaths, resolveProjectPaths } from "./exec-project.js";
|
|
5
|
+
import { readAllEventFiles, foldEventsToState } from "./exec-events.js";
|
|
6
|
+
import { buildScheduleIndex, findStaleGeneratedTracks } from "./exec-schedule.js";
|
|
7
|
+
import { buildInitialStateFromStrategy } from "./exec-schedule-initial.js";
|
|
8
|
+
import { readReadySnapshot } from "./exec-schedule-ready.js";
|
|
9
|
+
import { specdojoRootDir } from "./specdojo-config.js";
|
|
10
|
+
import { extractLocalId, extractPhaseSuffix } from "./schedule-phase-sets.js";
|
|
11
|
+
import { resolveWorktreeBase } from "./exec-worktree.js";
|
|
12
|
+
import { buildPhaseModeIndex, resolveAgentAssignment, resolveAgentPipeline, resolveApproach, resolveTaskCapabilities, resolveTaskExecution, resolveTaskMode, resolveTaskProficiency, } from "./exec-strategy.js";
|
|
13
|
+
import { SerialAsyncLock, buildTaskPhaseMap, configuredWorktreeBase, parseParallel, resolveExecDefaultsPath, runCompletionDrivenWorkerPool, } from "./exec-run-shared.js";
|
|
14
|
+
import { loadRosterForExecutionPath } from "./exec-run-agent.js";
|
|
15
|
+
import { prepareSingleTask, } from "./exec-run-schedule-prepare.js";
|
|
16
|
+
import { runPreparedTask, runPreparedTaskSafely, } from "./exec-run-schedule-task.js";
|
|
17
|
+
import { spawnIndexBuild, spawnRefresh, spawnScheduleBuild } from "./exec-run-mode-shared.js";
|
|
18
|
+
// Rebuild only generated tracks whose strategy input is missing a generated track or has a newer
|
|
19
|
+
// mtime. The same structured detector feeds exec validate warnings, keeping manual validation and
|
|
20
|
+
// cycle automation on one freshness rule. No output is emitted when every track is fresh.
|
|
21
|
+
export async function rebuildStaleGeneratedTracksForCycle(schedulePath, projectId, dryRun, dependencies = {}) {
|
|
22
|
+
const staleTracks = findStaleGeneratedTracks(schedulePath);
|
|
23
|
+
if (staleTracks.length === 0)
|
|
24
|
+
return { status: "not-needed", tracks: [] };
|
|
25
|
+
const write = dependencies.write ?? ((message) => process.stdout.write(message));
|
|
26
|
+
const buildTrack = dependencies.buildTrack ?? ((track) => spawnScheduleBuild(projectId, track));
|
|
27
|
+
const tracks = [];
|
|
28
|
+
for (const stale of staleTracks) {
|
|
29
|
+
const projectArgs = projectId ? ` --project ${projectId}` : "";
|
|
30
|
+
if (dryRun) {
|
|
31
|
+
write(` [dry-run] specdojo schedule build --track ${stale.track} --force${projectArgs}\n`);
|
|
32
|
+
tracks.push(stale.track);
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
write(`[cycle] step 3/5: rebuild stale schedule track ${basename(stale.strategyFile)} (${stale.reason})\n`);
|
|
36
|
+
if (!(await buildTrack(stale.track))) {
|
|
37
|
+
write(`[cycle] schedule build failed for track ${stale.track} — aborting auto step\n`);
|
|
38
|
+
return { status: "failure", tracks: [...tracks, stale.track] };
|
|
39
|
+
}
|
|
40
|
+
tracks.push(stale.track);
|
|
41
|
+
}
|
|
42
|
+
return { status: "success", tracks };
|
|
43
|
+
}
|
|
44
|
+
export async function runBatchMode(opts) {
|
|
45
|
+
const resolvedPaths = resolveProjectPaths({ project: opts.project });
|
|
46
|
+
activateResolvedProjectPaths(resolvedPaths);
|
|
47
|
+
const { schedulePath, executionPath, catalogPath, rolesPath, viewpointsPath, projectContext } = resolvedPaths;
|
|
48
|
+
// Use the resolved project id (which honors current_project / SPECDOJO_PROJECT), not the raw
|
|
49
|
+
// --project flag. This keeps worktree branches project-qualified even when --project is omitted.
|
|
50
|
+
const projectId = resolvedPaths.projectId ?? opts.project;
|
|
51
|
+
const planGenPaths = { catalogPath, rolesPath, viewpointsPath, projectContext };
|
|
52
|
+
const repoRoot = specdojoRootDir();
|
|
53
|
+
const worktreeBase = resolveWorktreeBase(repoRoot, opts.worktreeBase, configuredWorktreeBase(schedulePath));
|
|
54
|
+
const parallel = parseParallel(opts.parallel);
|
|
55
|
+
const execDefaults = loadExecDefaultsConfig(resolveExecDefaultsPath(opts, schedulePath), executionPath);
|
|
56
|
+
const roster = loadRosterForExecutionPath(executionPath);
|
|
57
|
+
const { localIdToPhaseSets, phaseSetSuffixToId } = buildTaskPhaseMap(schedulePath);
|
|
58
|
+
const readyJsonPath = join(executionPath, "generated", "ready.json");
|
|
59
|
+
const loop = !!opts.loop;
|
|
60
|
+
const maxRounds = opts.maxRounds ? Math.max(1, parseInt(opts.maxRounds, 10) || 1) : null;
|
|
61
|
+
const dryRun = !!opts.dryRun;
|
|
62
|
+
const strategy = opts.strategy ?? "critical-first";
|
|
63
|
+
const prepareReadyTasks = async (capacity, limit) => {
|
|
64
|
+
if (!existsSync(readyJsonPath)) {
|
|
65
|
+
process.stdout.write(`ready.json not found: ${readyJsonPath}\nRun: specdojo exec refresh\n`);
|
|
66
|
+
process.exitCode = 1;
|
|
67
|
+
return { preparedTasks: [], readyCount: 0 };
|
|
68
|
+
}
|
|
69
|
+
const readySnapshot = readReadySnapshot(readyJsonPath);
|
|
70
|
+
const orderedIds = strategy === "fifo"
|
|
71
|
+
? readySnapshot.strategies.fifo.ordered_task_ids
|
|
72
|
+
: readySnapshot.strategies["critical-first"].ordered_task_ids;
|
|
73
|
+
if (orderedIds.length === 0)
|
|
74
|
+
return { preparedTasks: [], readyCount: 0 };
|
|
75
|
+
const taskMap = new Map(readySnapshot.tasks.map((t) => [t.id, t]));
|
|
76
|
+
const preparedTasks = [];
|
|
77
|
+
for (const taskId of orderedIds) {
|
|
78
|
+
if (preparedTasks.length >= limit)
|
|
79
|
+
break;
|
|
80
|
+
const task = taskMap.get(taskId);
|
|
81
|
+
if (!task)
|
|
82
|
+
continue;
|
|
83
|
+
try {
|
|
84
|
+
const prepared = await prepareSingleTask(task, projectId, repoRoot, schedulePath, executionPath, roster, localIdToPhaseSets, phaseSetSuffixToId, opts.by, { edit: opts.editBy, review: opts.reviewBy }, { executor: opts.executorBy, reporter: opts.reporterBy }, opts.by, dryRun, false, worktreeBase, planGenPaths, execDefaults, capacity.hasCapacity);
|
|
85
|
+
// "deferred": every candidate provider is at its cap; try it again after a slot frees.
|
|
86
|
+
if (prepared === "deferred")
|
|
87
|
+
continue;
|
|
88
|
+
if (typeof prepared !== "string") {
|
|
89
|
+
preparedTasks.push(prepared);
|
|
90
|
+
capacity.reserve(prepared.agentCandidates[0]?.provider);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
95
|
+
process.stderr.write(`[run] setup error for ${task.id}: ${message}\n`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return { preparedTasks, readyCount: orderedIds.length };
|
|
99
|
+
};
|
|
100
|
+
if (!loop || dryRun) {
|
|
101
|
+
const capacity = createProviderCapacityTracker(execDefaults);
|
|
102
|
+
const { preparedTasks, readyCount } = await prepareReadyTasks(capacity, parallel);
|
|
103
|
+
if (preparedTasks.length === 0) {
|
|
104
|
+
process.stdout.write(readyCount === 0 ? "[run] no ready tasks — exit\n" : "[run] no executable tasks — exit\n");
|
|
105
|
+
if (readyCount > 0 || process.exitCode)
|
|
106
|
+
process.exitCode = 1;
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const outcomes = await Promise.all(preparedTasks.map((prepared) => runPreparedTaskSafely(prepared, projectId, repoRoot, schedulePath, executionPath, catalogPath, execDefaults, dryRun)));
|
|
110
|
+
const results = outcomes.map((outcome) => outcome.result);
|
|
111
|
+
const completed = results.filter((result) => result === "success").length;
|
|
112
|
+
process.stdout.write(`[run] all ${completed} instance(s) completed\n`);
|
|
113
|
+
if (results.some((result) => result === "failure"))
|
|
114
|
+
process.exitCode = 1;
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const lifecycleLock = new SerialAsyncLock();
|
|
118
|
+
const capacity = createProviderCapacityTracker(execDefaults);
|
|
119
|
+
let schedulingPass = 0;
|
|
120
|
+
let stopNewTasks = false;
|
|
121
|
+
let lastReadyCount = 0;
|
|
122
|
+
const scheduleAvailable = async (openSlots) => {
|
|
123
|
+
if (stopNewTasks || openSlots <= 0)
|
|
124
|
+
return [];
|
|
125
|
+
if (maxRounds !== null && schedulingPass >= maxRounds) {
|
|
126
|
+
process.stdout.write(`[run] reached max-rounds ${maxRounds} — drain running tasks\n`);
|
|
127
|
+
stopNewTasks = true;
|
|
128
|
+
return [];
|
|
129
|
+
}
|
|
130
|
+
schedulingPass++;
|
|
131
|
+
const roundSuffix = ` (round ${schedulingPass}${maxRounds !== null ? `/${maxRounds}` : "/-"})`;
|
|
132
|
+
if (schedulingPass > 1) {
|
|
133
|
+
// Rebuild doc-index before refresh so deliverables created by the previous round (e.g. a
|
|
134
|
+
// newly authored document referenced by wikilink) are resolvable when this round's tasks
|
|
135
|
+
// are prepared, instead of only becoming resolvable on a later, out-of-band index build.
|
|
136
|
+
process.stdout.write(`[run] index build${roundSuffix}...\n`);
|
|
137
|
+
if (!spawnIndexBuild()) {
|
|
138
|
+
process.stdout.write("[run] index build failed — drain running tasks\n");
|
|
139
|
+
process.exitCode = 1;
|
|
140
|
+
stopNewTasks = true;
|
|
141
|
+
return [];
|
|
142
|
+
}
|
|
143
|
+
// Only exec cycle opts into schedule regeneration. A strategy task completed by the prior
|
|
144
|
+
// auto round can therefore expose the next track in this same cycle, while standalone
|
|
145
|
+
// `exec run --auto --loop` keeps its existing refresh-only behavior.
|
|
146
|
+
if (opts.cycleRebuildStaleTracks) {
|
|
147
|
+
const rebuild = await rebuildStaleGeneratedTracksForCycle(schedulePath, projectId, false);
|
|
148
|
+
if (rebuild.status === "failure") {
|
|
149
|
+
process.exitCode = 1;
|
|
150
|
+
stopNewTasks = true;
|
|
151
|
+
return [];
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
process.stdout.write(`[run] exec refresh${roundSuffix}...\n`);
|
|
155
|
+
if (!spawnRefresh(projectId)) {
|
|
156
|
+
process.stdout.write("[run] exec refresh failed — drain running tasks\n");
|
|
157
|
+
process.exitCode = 1;
|
|
158
|
+
stopNewTasks = true;
|
|
159
|
+
return [];
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
const { preparedTasks, readyCount } = await prepareReadyTasks(capacity, openSlots);
|
|
163
|
+
lastReadyCount = readyCount;
|
|
164
|
+
return preparedTasks;
|
|
165
|
+
};
|
|
166
|
+
const poolResult = await runCompletionDrivenWorkerPool({
|
|
167
|
+
maxParallel: parallel,
|
|
168
|
+
fillSlots: (openSlots) => lifecycleLock.runExclusive(() => scheduleAvailable(openSlots)),
|
|
169
|
+
runItem: (prepared) => runPreparedTaskSafely(prepared, projectId, repoRoot, schedulePath, executionPath, catalogPath, execDefaults, dryRun, lifecycleLock),
|
|
170
|
+
onSettled: (prepared, outcome) => {
|
|
171
|
+
capacity.release(prepared.agentCandidates[0]?.provider);
|
|
172
|
+
if (outcome.result === "failure")
|
|
173
|
+
process.exitCode = 1;
|
|
174
|
+
const critical = (prepared.task.cpm?.slack ?? 1) === 0;
|
|
175
|
+
if (critical && outcome.result === "failure") {
|
|
176
|
+
process.stdout.write(`[run] stopping: failure on critical task.\n`);
|
|
177
|
+
process.exitCode = 1;
|
|
178
|
+
stopNewTasks = true;
|
|
179
|
+
return { stop: true };
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
if (poolResult.launched === 0) {
|
|
184
|
+
process.stdout.write(lastReadyCount > 0 ? "[run] no executable tasks — exit\n" : "[run] no ready tasks — exit\n");
|
|
185
|
+
if (lastReadyCount > 0 || process.exitCode)
|
|
186
|
+
process.exitCode = 1;
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
process.stdout.write(`[run] all ${poolResult.completed} of ${poolResult.launched} launched instance(s) completed\n`);
|
|
190
|
+
}
|
|
191
|
+
// For a task already in "doing" state, resume with the actor who claimed it so a re-run does not
|
|
192
|
+
// reselect a different agent. The actor is a roster nickname and its command is resolved later.
|
|
193
|
+
// `resumed` is true only when the claiming actor was adopted, which callers use to skip a claim.
|
|
194
|
+
export function resolveClaimingActor(taskState, byOverride) {
|
|
195
|
+
if (byOverride)
|
|
196
|
+
return { actor: byOverride, resumed: false };
|
|
197
|
+
if (taskState?.state !== "doing" || !taskState.last_by) {
|
|
198
|
+
return { actor: undefined, resumed: false };
|
|
199
|
+
}
|
|
200
|
+
const actor = taskState.last_by;
|
|
201
|
+
process.stdout.write(` Resuming with claiming actor: ${actor}\n`);
|
|
202
|
+
return { actor, resumed: true };
|
|
203
|
+
}
|
|
204
|
+
export async function runManualMode(opts) {
|
|
205
|
+
const taskId = opts.task;
|
|
206
|
+
const resolvedPaths = resolveProjectPaths({ project: opts.project });
|
|
207
|
+
activateResolvedProjectPaths(resolvedPaths);
|
|
208
|
+
const { schedulePath, executionPath, catalogPath, rolesPath, viewpointsPath, projectContext } = resolvedPaths;
|
|
209
|
+
// Use the resolved project id (which honors current_project / SPECDOJO_PROJECT), not the raw
|
|
210
|
+
// --project flag. This keeps worktree branches project-qualified even when --project is omitted.
|
|
211
|
+
const projectId = resolvedPaths.projectId ?? opts.project;
|
|
212
|
+
const planGenPaths = { catalogPath, rolesPath, viewpointsPath, projectContext };
|
|
213
|
+
const repoRoot = specdojoRootDir();
|
|
214
|
+
const worktreeBase = resolveWorktreeBase(repoRoot, opts.worktreeBase, configuredWorktreeBase(schedulePath));
|
|
215
|
+
const execDefaults = loadExecDefaultsConfig(resolveExecDefaultsPath(opts, schedulePath), executionPath);
|
|
216
|
+
const roster = loadRosterForExecutionPath(executionPath);
|
|
217
|
+
const { localIdToPhaseSets, phaseSetSuffixToId } = buildTaskPhaseMap(schedulePath);
|
|
218
|
+
const phaseModeIndex = buildPhaseModeIndex(schedulePath);
|
|
219
|
+
const readyJsonPath = join(executionPath, "generated", "ready.json");
|
|
220
|
+
let task = { id: taskId, schedule_file: "", fifo_rank: 0, critical_first_rank: 0 };
|
|
221
|
+
if (existsSync(readyJsonPath)) {
|
|
222
|
+
const snap = readReadySnapshot(readyJsonPath);
|
|
223
|
+
const found = snap.tasks.find((t) => t.id === taskId);
|
|
224
|
+
if (found)
|
|
225
|
+
task = found;
|
|
226
|
+
}
|
|
227
|
+
// If task not in ready.json (e.g. already "doing"), derive local_id from task id pattern.
|
|
228
|
+
if (!task.local_id) {
|
|
229
|
+
const parts = taskId.split("-");
|
|
230
|
+
const localId = extractLocalId(taskId);
|
|
231
|
+
if (localId && parts[0] === "T" && parts[1]) {
|
|
232
|
+
const track = parts[1];
|
|
233
|
+
task = {
|
|
234
|
+
...task,
|
|
235
|
+
local_id: localId,
|
|
236
|
+
phase_suffix: extractPhaseSuffix(taskId),
|
|
237
|
+
schedule_file: `sch-track-${track.toLowerCase()}.yaml`,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (task.local_id) {
|
|
242
|
+
task = {
|
|
243
|
+
...task,
|
|
244
|
+
mode: task.mode ??
|
|
245
|
+
resolveTaskMode(task.local_id, task.id, phaseModeIndex, task.phase_suffix, task.phase_set),
|
|
246
|
+
execution: task.execution ??
|
|
247
|
+
resolveTaskExecution(task.local_id, task.id, phaseModeIndex, task.phase_suffix, task.phase_set),
|
|
248
|
+
approach: task.approach ??
|
|
249
|
+
resolveApproach(task.local_id, task.id, phaseModeIndex, task.phase_suffix, task.phase_set),
|
|
250
|
+
};
|
|
251
|
+
if (!task.capabilities) {
|
|
252
|
+
const capabilities = resolveTaskCapabilities(task.local_id, task.id, phaseModeIndex, task.phase_suffix, task.phase_set);
|
|
253
|
+
if (capabilities.length > 0)
|
|
254
|
+
task.capabilities = capabilities;
|
|
255
|
+
}
|
|
256
|
+
task.proficiency =
|
|
257
|
+
task.proficiency ??
|
|
258
|
+
resolveTaskProficiency(task.local_id, task.id, phaseModeIndex, task.phase_suffix, task.phase_set);
|
|
259
|
+
task.agent_pipeline =
|
|
260
|
+
task.agent_pipeline ??
|
|
261
|
+
resolveAgentPipeline(task.local_id, task.id, phaseModeIndex, task.phase_suffix, task.phase_set);
|
|
262
|
+
task.agent =
|
|
263
|
+
task.agent ??
|
|
264
|
+
resolveAgentAssignment(task.local_id, task.id, phaseModeIndex, task.phase_suffix, task.phase_set);
|
|
265
|
+
}
|
|
266
|
+
// If the task is already in "doing" state and --by is not specified,
|
|
267
|
+
// use the actor who claimed it and their command to avoid re-selecting a different agent.
|
|
268
|
+
// Read from events directly (not state.json cache) to reflect recent scheduler claims.
|
|
269
|
+
let actorOverride = opts.by;
|
|
270
|
+
let alreadyClaimed = false;
|
|
271
|
+
if (!actorOverride) {
|
|
272
|
+
try {
|
|
273
|
+
const sch = buildScheduleIndex(schedulePath);
|
|
274
|
+
const evts = readAllEventFiles(schedulePath);
|
|
275
|
+
const initTasks = buildInitialStateFromStrategy(schedulePath, sch);
|
|
276
|
+
const snap = foldEventsToState(evts, sch, schedulePath, initTasks);
|
|
277
|
+
const resolved = resolveClaimingActor(snap.tasks?.[taskId], undefined);
|
|
278
|
+
actorOverride = resolved.actor;
|
|
279
|
+
alreadyClaimed = resolved.resumed;
|
|
280
|
+
}
|
|
281
|
+
catch {
|
|
282
|
+
// ignore errors reading state; fall through to normal agent selection
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
const prepared = await prepareSingleTask(task, projectId, repoRoot, schedulePath, executionPath, roster, localIdToPhaseSets, phaseSetSuffixToId, actorOverride, { edit: opts.editBy, review: opts.reviewBy }, { executor: opts.executorBy, reporter: opts.reporterBy }, actorOverride, !!opts.dryRun, alreadyClaimed, worktreeBase, planGenPaths, execDefaults);
|
|
286
|
+
if (typeof prepared === "string") {
|
|
287
|
+
if (prepared === "failure")
|
|
288
|
+
process.exitCode = 1;
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
const result = await runPreparedTask(prepared, projectId, repoRoot, schedulePath, executionPath, catalogPath, execDefaults, !!opts.dryRun);
|
|
292
|
+
if (result === "failure")
|
|
293
|
+
process.exitCode = 1;
|
|
294
|
+
}
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { resolveMemberCommand } from "./exec-agent-config.js";
|
|
3
|
+
import { canCompleteTask, readAllEventFiles, foldEventsToState } from "./exec-events.js";
|
|
4
|
+
import { buildScheduleIndex } from "./exec-schedule.js";
|
|
5
|
+
import { buildInitialStateFromStrategy } from "./exec-schedule-initial.js";
|
|
6
|
+
import { qualifyTaskId, randomHex } from "./exec-shared.js";
|
|
7
|
+
import { generateSinglePlan, finalizeResultSectionsForDeliverable, targetDocIdsForScheduledTask, reviewGradeSubject, } from "./exec-plans.js";
|
|
8
|
+
import { ensureReviewGrade } from "./review-grade.js";
|
|
9
|
+
import { isResultUnfilled, readResultFrontmatterSnapshot, scaffoldResult } from "./exec-results.js";
|
|
10
|
+
import { worktreeNameFromTaskId } from "./exec-worktree.js";
|
|
11
|
+
import { configuredProductRepos, plannedProjectWorktreePath } from "./exec-task-repos.js";
|
|
12
|
+
import { checkpointAndEnsureWorktree, discardStaleExecWorktree } from "./exec-worktree-ops.js";
|
|
13
|
+
import { pipelineStateLocation } from "./exec-pipeline-state.js";
|
|
14
|
+
import { collectBusyActors, pinnedExecutor, pinnedReporter, resolveAgentOverride, resolveTaskPhaseContext, selectCandidates, } from "./exec-run-shared.js";
|
|
15
|
+
import { buildExecutorPrompt, executorRequirements, loadPrompt, reportProductWorktrees, reporterRequirements, resolveReporterAgentCandidates, } from "./exec-run-agent.js";
|
|
16
|
+
import { integrateLogPath, spawnClaim, spawnRelease } from "./exec-run-mode-shared.js";
|
|
17
|
+
export function findClaimEventPath(schedulePath, taskId) {
|
|
18
|
+
const claims = readAllEventFiles(schedulePath).filter((item) => item.event.task_id === taskId && item.event.type === "claim");
|
|
19
|
+
return claims[claims.length - 1]?.path ?? null;
|
|
20
|
+
}
|
|
21
|
+
// review フェーズの前段で runner が対象文書へ grade を実行する(PJR-KCMH、PJR-2ZVS 3.6)。
|
|
22
|
+
// executor には実行させない。評価結果が最新(content_hash 一致)なら再実行しない。
|
|
23
|
+
// grade の失敗は review を止めず、結果を plan に示して review の verdict に委ねる。
|
|
24
|
+
export async function gradeBeforeReviewPlan(params) {
|
|
25
|
+
const { task, projectId } = params;
|
|
26
|
+
if ((task.mode ?? "edit") !== "review" || !projectId)
|
|
27
|
+
return undefined;
|
|
28
|
+
const subject = reviewGradeSubject(params.catalogPath ?? "", task);
|
|
29
|
+
if (!subject) {
|
|
30
|
+
process.stdout.write(" [grade] skipped: grade subject is not resolvable\n");
|
|
31
|
+
return { action: "not-run", detail: "評価対象のパスを解決できない" };
|
|
32
|
+
}
|
|
33
|
+
process.stdout.write(` [grade] checking ${subject.path} (--target ${subject.target})\n`);
|
|
34
|
+
const outcome = await ensureReviewGrade({
|
|
35
|
+
taskId: qualifyTaskId(projectId, task.id),
|
|
36
|
+
projectId,
|
|
37
|
+
subjectPath: subject.path,
|
|
38
|
+
target: subject.target,
|
|
39
|
+
repoRoot: params.repoRoot,
|
|
40
|
+
dryRun: params.dryRun,
|
|
41
|
+
});
|
|
42
|
+
const summary = outcome.action === "skipped"
|
|
43
|
+
? "skipped: content_hash matches the stored grade"
|
|
44
|
+
: outcome.action === "executed"
|
|
45
|
+
? `executed: run id ${outcome.runId}`
|
|
46
|
+
: outcome.action === "failed"
|
|
47
|
+
? `failed: run id ${outcome.runId}; ${outcome.detail}`
|
|
48
|
+
: `not run: ${outcome.detail}`;
|
|
49
|
+
process.stdout.write(` [grade] ${summary}\n`);
|
|
50
|
+
return outcome;
|
|
51
|
+
}
|
|
52
|
+
export async function prepareSingleTask(task, projectId, repoRoot, schedulePath, executionPath, roster, localIdToPhaseSets, phaseSetSuffixToId, agentNicknameOverride, modeAgentOverrides, stageAgentOverrides, actorOverride, dryRun, skipClaim, worktreeBase, planGenPaths, execDefaults, hasProviderCapacity, pipelineResume) {
|
|
53
|
+
const mode = task.mode ?? "edit";
|
|
54
|
+
process.stdout.write(`Task: ${task.id}${task.name ? ` — ${task.name}` : ""} [${mode}]\n`);
|
|
55
|
+
if (!task.agent_pipeline && (stageAgentOverrides.executor || stageAgentOverrides.reporter)) {
|
|
56
|
+
process.stdout.write(" --executor-by / --reporter-by require an agent_pipeline task.\n");
|
|
57
|
+
return "failure";
|
|
58
|
+
}
|
|
59
|
+
// Mode-specific overrides (--edit-by / --review-by) let nightly batch runs route edit and
|
|
60
|
+
// review to different agents (e.g. local LLMs) without editing the roster. They take an agent
|
|
61
|
+
// nickname whose command is resolved from agent-members.yaml; a mode without an override falls back
|
|
62
|
+
// to normal auto-selection.
|
|
63
|
+
const overrideResolution = resolveAgentOverride(mode, task.agent_pipeline
|
|
64
|
+
? (stageAgentOverrides.executor ?? agentNicknameOverride ?? pinnedExecutor(task))
|
|
65
|
+
: (agentNicknameOverride ?? pinnedExecutor(task)), modeAgentOverrides, roster, execDefaults, task.agent_pipeline ? "executor" : undefined);
|
|
66
|
+
if (overrideResolution.kind === "error") {
|
|
67
|
+
process.stdout.write(` ${overrideResolution.message}\n`);
|
|
68
|
+
return "failure";
|
|
69
|
+
}
|
|
70
|
+
const agentCandidates = overrideResolution.kind === "command"
|
|
71
|
+
? [
|
|
72
|
+
{
|
|
73
|
+
command: overrideResolution.command,
|
|
74
|
+
actor: overrideResolution.actor,
|
|
75
|
+
provider: overrideResolution.provider,
|
|
76
|
+
},
|
|
77
|
+
]
|
|
78
|
+
: [];
|
|
79
|
+
let actor = actorOverride ?? "auto-agent";
|
|
80
|
+
if (!actorOverride && overrideResolution.kind === "command" && overrideResolution.actor) {
|
|
81
|
+
actor = overrideResolution.actor;
|
|
82
|
+
}
|
|
83
|
+
if (agentCandidates.length === 0) {
|
|
84
|
+
// Human tasks cannot be run automatically without an explicit registered agent override.
|
|
85
|
+
if ((task.execution ?? "agent") === "human") {
|
|
86
|
+
process.stdout.write(` Task "${task.name ?? task.id}" (${task.id}) has execution: human.\n` +
|
|
87
|
+
` This task requires human execution. Use --by <nickname> to override.\n`);
|
|
88
|
+
return "failure";
|
|
89
|
+
}
|
|
90
|
+
const phaseCtx = resolveTaskPhaseContext(task, localIdToPhaseSets, phaseSetSuffixToId);
|
|
91
|
+
if (!phaseCtx) {
|
|
92
|
+
process.stdout.write(` Cannot resolve phase context for "${task.name ?? task.id}": not found in sch-strategy files\n`);
|
|
93
|
+
return "failure";
|
|
94
|
+
}
|
|
95
|
+
const requirements = executorRequirements(task) ?? {
|
|
96
|
+
capabilities: task.capabilities ?? [],
|
|
97
|
+
proficiency: task.proficiency,
|
|
98
|
+
};
|
|
99
|
+
const busyActors = collectBusyActors(schedulePath);
|
|
100
|
+
const candidates = selectCandidates(requirements, roster, mode, busyActors, execDefaults);
|
|
101
|
+
if (candidates.length === 0) {
|
|
102
|
+
process.stdout.write(` No agents found for mode: ${mode}, capabilities: [${requirements.capabilities.join(", ")}]${requirements.proficiency ? `, proficiency: ${requirements.proficiency}` : ""}${requirements.stage_role ? `, stage_role: ${requirements.stage_role}` : ""}\n`);
|
|
103
|
+
return "failure";
|
|
104
|
+
}
|
|
105
|
+
// Per-provider concurrency caps (exec-defaults providers.<name>.max_concurrency) drop any
|
|
106
|
+
// candidate whose provider already reached its limit this round. If a non-capped provider
|
|
107
|
+
// remains it becomes the primary; if every candidate's provider is at capacity, defer the
|
|
108
|
+
// task to a later round before claiming or setting up its worktree.
|
|
109
|
+
const available = hasProviderCapacity
|
|
110
|
+
? candidates.filter((c) => hasProviderCapacity(c.provider))
|
|
111
|
+
: candidates;
|
|
112
|
+
if (available.length === 0) {
|
|
113
|
+
process.stdout.write(` [run] deferred: ${task.id} — all candidate providers at concurrency cap this round\n`);
|
|
114
|
+
return "deferred";
|
|
115
|
+
}
|
|
116
|
+
// Expand each candidate's launch command. A broken provider template (unresolved
|
|
117
|
+
// placeholder, ambiguous command_params) skips that candidate with a warning so a
|
|
118
|
+
// misconfigured provider does not block fallback to other providers.
|
|
119
|
+
const runnable = [];
|
|
120
|
+
for (const candidate of available) {
|
|
121
|
+
try {
|
|
122
|
+
const command = resolveMemberCommand(execDefaults, candidate);
|
|
123
|
+
if (!command)
|
|
124
|
+
continue;
|
|
125
|
+
agentCandidates.push({
|
|
126
|
+
command,
|
|
127
|
+
actor: candidate.nickname,
|
|
128
|
+
provider: candidate.provider,
|
|
129
|
+
});
|
|
130
|
+
runnable.push(candidate);
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
process.stdout.write(` Skipping ${candidate.nickname}: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (runnable.length === 0) {
|
|
137
|
+
process.stdout.write(` No agent with a resolvable command for mode: ${mode} (check providers.<provider>.command_template in exec-defaults.yaml)\n`);
|
|
138
|
+
return "failure";
|
|
139
|
+
}
|
|
140
|
+
if (!actorOverride)
|
|
141
|
+
actor = runnable[0].nickname;
|
|
142
|
+
process.stdout.write(` Phase: ${phaseCtx.phaseSet}/${phaseCtx.phaseId} Mode: ${mode} Agent: ${runnable[0].nickname}\n`);
|
|
143
|
+
}
|
|
144
|
+
let reporterCandidates;
|
|
145
|
+
if (task.agent_pipeline) {
|
|
146
|
+
const requirements = reporterRequirements(task);
|
|
147
|
+
reporterCandidates = resolveReporterAgentCandidates(task, roster, execDefaults, collectBusyActors(schedulePath), stageAgentOverrides.reporter ?? pinnedReporter(task));
|
|
148
|
+
if (reporterCandidates.length === 0) {
|
|
149
|
+
process.stdout.write(` No agents found for reporter stage${requirements?.proficiency ? `, proficiency: ${requirements.proficiency}` : ""}\n`);
|
|
150
|
+
return "failure";
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
const reviewGradeOutcome = await gradeBeforeReviewPlan({
|
|
154
|
+
task,
|
|
155
|
+
projectId,
|
|
156
|
+
catalogPath: planGenPaths.catalogPath,
|
|
157
|
+
repoRoot,
|
|
158
|
+
dryRun,
|
|
159
|
+
});
|
|
160
|
+
// Plans are generated on demand here; `exec refresh` does not manage them.
|
|
161
|
+
await generateSinglePlan({
|
|
162
|
+
executionPath,
|
|
163
|
+
projectId: projectId ?? "",
|
|
164
|
+
catalogPath: planGenPaths.catalogPath ?? "",
|
|
165
|
+
rolesPath: planGenPaths.rolesPath,
|
|
166
|
+
viewpointsPath: planGenPaths.viewpointsPath,
|
|
167
|
+
projectContext: planGenPaths.projectContext,
|
|
168
|
+
task,
|
|
169
|
+
...(reviewGradeOutcome ? { reviewGradeOutcome } : {}),
|
|
170
|
+
});
|
|
171
|
+
const planPrompt = loadPrompt(executionPath, task.id);
|
|
172
|
+
if (!planPrompt) {
|
|
173
|
+
process.stdout.write(` Plan not found for ${task.id}.\n`);
|
|
174
|
+
return "failure";
|
|
175
|
+
}
|
|
176
|
+
const prompt = task.agent_pipeline
|
|
177
|
+
? buildExecutorPrompt(planPrompt, execDefaults.pipeline?.parent_validations)
|
|
178
|
+
: planPrompt;
|
|
179
|
+
const pipelineRunId = task.agent_pipeline
|
|
180
|
+
? `${new Date().toISOString().replace(/[-:.]/g, "").replace("Z", "Z")}-${randomHex(4)}`
|
|
181
|
+
: undefined;
|
|
182
|
+
const worktreeTaskId = qualifyTaskId(projectId, task.id);
|
|
183
|
+
const worktreeName = worktreeNameFromTaskId(worktreeTaskId);
|
|
184
|
+
// PJR-98G4: repos を宣言した project では <base>/<task>/project/ と <base>/<task>/<repo>/ を作る。
|
|
185
|
+
const products = configuredProductRepos(schedulePath);
|
|
186
|
+
if (dryRun) {
|
|
187
|
+
const worktree = {
|
|
188
|
+
path: plannedProjectWorktreePath(worktreeBase, worktreeTaskId, products),
|
|
189
|
+
branch: `exec/${worktreeName}`,
|
|
190
|
+
name: worktreeName,
|
|
191
|
+
created: false,
|
|
192
|
+
};
|
|
193
|
+
process.stdout.write(` [run] would setup: worktree ${worktree.path} (${worktree.branch})\n`);
|
|
194
|
+
for (const product of products) {
|
|
195
|
+
process.stdout.write(` [run] would setup: worktree ${join(worktreeBase, worktreeName, product.name)} ` +
|
|
196
|
+
`(${worktree.branch} in ${product.repoRoot})\n`);
|
|
197
|
+
}
|
|
198
|
+
const claimMsg = skipClaim
|
|
199
|
+
? ` [dry-run] already claimed: ${task.id} as ${actor} (skip claim)`
|
|
200
|
+
: ` [dry-run] would claim: ${task.id} as ${actor}`;
|
|
201
|
+
process.stdout.write(claimMsg + "\n");
|
|
202
|
+
process.stdout.write(` [dry-run] Command: ${agentCandidates[0]?.command ?? ""}\n`);
|
|
203
|
+
process.stdout.write(` [dry-run] CWD: ${worktree.path}\n`);
|
|
204
|
+
process.stdout.write(` [dry-run] Plan: ${prompt.length} chars\n`);
|
|
205
|
+
return {
|
|
206
|
+
task,
|
|
207
|
+
actor,
|
|
208
|
+
agentCandidates,
|
|
209
|
+
plan: planPrompt,
|
|
210
|
+
prompt,
|
|
211
|
+
worktree,
|
|
212
|
+
pipelineRunId,
|
|
213
|
+
pipelineResumeStage: pipelineResume?.stage,
|
|
214
|
+
pipelineStateRef: pipelineResume?.stateRef,
|
|
215
|
+
reporterCandidates,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
if (skipClaim) {
|
|
219
|
+
process.stdout.write(` Already claimed: ${task.id} as ${actor}\n`);
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
process.stdout.write(` Claiming: ${task.id} as ${actor}\n`);
|
|
223
|
+
if (!spawnClaim(projectId, task.id, actor)) {
|
|
224
|
+
process.stdout.write(` Claim failed: ${task.id}\n`);
|
|
225
|
+
return "failure";
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
const planRef = `exec/plans/${task.id}-plan.md`;
|
|
229
|
+
const startedAt = new Date().toISOString();
|
|
230
|
+
const finalizeSections = task.approach === "finalize" || task.approach === "bootstrap-finalize"
|
|
231
|
+
? finalizeResultSectionsForDeliverable(planGenPaths.catalogPath ?? "", task.local_id, task.approach)
|
|
232
|
+
: undefined;
|
|
233
|
+
const targets = targetDocIdsForScheduledTask(planGenPaths.catalogPath ?? "", task, projectId ?? "");
|
|
234
|
+
const { resultPath } = await scaffoldResult({
|
|
235
|
+
executionPath,
|
|
236
|
+
taskId: task.id,
|
|
237
|
+
mode: task.mode ?? "edit",
|
|
238
|
+
projectId: projectId ?? "",
|
|
239
|
+
planRef,
|
|
240
|
+
agent: actor,
|
|
241
|
+
startedAt,
|
|
242
|
+
...(task.approach ? { approach: task.approach } : {}),
|
|
243
|
+
...(targets ? { targets } : {}),
|
|
244
|
+
...(finalizeSections ? { finalizeSections } : {}),
|
|
245
|
+
});
|
|
246
|
+
// Keep the execution checkpoint visible at root, but commit it only on the exec branch. The
|
|
247
|
+
// successful merge later brings plan/result/claim and deliverables to root in one first-parent
|
|
248
|
+
// commit (see runPreparedTask).
|
|
249
|
+
const claimEventPath = findClaimEventPath(schedulePath, task.id);
|
|
250
|
+
if (!claimEventPath) {
|
|
251
|
+
process.stdout.write(` Claim event not found for ${task.id}\n`);
|
|
252
|
+
return "failure";
|
|
253
|
+
}
|
|
254
|
+
// A fresh claim (not a resume) of a task that still owns an exec worktree/branch means a prior
|
|
255
|
+
// lifecycle left residue. Discard it so the checkpoint commit below runs and the root scaffold is
|
|
256
|
+
// committed instead of stranded as untracked changes that later trip the merge-back guard.
|
|
257
|
+
if (!skipClaim) {
|
|
258
|
+
const discarded = discardStaleExecWorktree({
|
|
259
|
+
context: { repoRoot, schedulePath, executionPath },
|
|
260
|
+
worktreeTaskId,
|
|
261
|
+
products,
|
|
262
|
+
});
|
|
263
|
+
if (discarded) {
|
|
264
|
+
process.stdout.write(` [run] discarded stale worktree/branch: ${discarded}\n`);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
const checkpointPaths = [
|
|
268
|
+
join(executionPath, "exec", "plans", `${task.id}-plan.md`),
|
|
269
|
+
resultPath,
|
|
270
|
+
claimEventPath,
|
|
271
|
+
];
|
|
272
|
+
const checkpointFailureLogPath = pipelineRunId
|
|
273
|
+
? integrateLogPath(pipelineStateLocation({
|
|
274
|
+
repoRoot,
|
|
275
|
+
worktreePath: repoRoot,
|
|
276
|
+
executionPath,
|
|
277
|
+
taskId: task.id,
|
|
278
|
+
runId: pipelineRunId,
|
|
279
|
+
}).path)
|
|
280
|
+
: undefined;
|
|
281
|
+
let worktree;
|
|
282
|
+
try {
|
|
283
|
+
worktree = checkpointAndEnsureWorktree({
|
|
284
|
+
context: { repoRoot, schedulePath, executionPath },
|
|
285
|
+
worktreeTaskId,
|
|
286
|
+
base: worktreeBase,
|
|
287
|
+
checkpointPaths,
|
|
288
|
+
commitMessage: `exec(${task.id}): prepare execution`,
|
|
289
|
+
products,
|
|
290
|
+
failureLogPath: checkpointFailureLogPath,
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
catch (error) {
|
|
294
|
+
// We claimed this task in this call (skipClaim is false); the checkpoint failed, so release the
|
|
295
|
+
// claim (doing → todo). Otherwise the task is stranded in "doing" with no worktree and drops out
|
|
296
|
+
// of ready.json. Resumed tasks (skipClaim) were already doing, so leave their state untouched.
|
|
297
|
+
if (!skipClaim) {
|
|
298
|
+
spawnRelease(projectId, task.id, actor, "rollback: checkpoint failed");
|
|
299
|
+
process.stdout.write(` Claim rolled back (checkpoint failed): ${task.id}\n`);
|
|
300
|
+
}
|
|
301
|
+
throw error;
|
|
302
|
+
}
|
|
303
|
+
const setupAction = worktree.created ? "setup" : "reuse";
|
|
304
|
+
process.stdout.write(` [run] ${setupAction}: worktree ${worktree.path} (${worktree.branch})\n`);
|
|
305
|
+
reportProductWorktrees(worktree);
|
|
306
|
+
return {
|
|
307
|
+
task,
|
|
308
|
+
actor,
|
|
309
|
+
agentCandidates,
|
|
310
|
+
plan: planPrompt,
|
|
311
|
+
prompt,
|
|
312
|
+
worktree,
|
|
313
|
+
resultPath,
|
|
314
|
+
resultScaffold: readResultFrontmatterSnapshot(resultPath),
|
|
315
|
+
checkpointPaths,
|
|
316
|
+
pipelineRunId,
|
|
317
|
+
pipelineResumeStage: pipelineResume?.stage,
|
|
318
|
+
pipelineStateRef: pipelineResume?.stateRef,
|
|
319
|
+
reporterCandidates,
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
// An agent can exit 0 without doing the work (e.g. a permission-denied tool call is fed back as a
|
|
323
|
+
// tool error and the model ends its turn normally). The agent's core duty is to fill the result while
|
|
324
|
+
// preserving its scaffold frontmatter, so treat an incomplete or modified result as a block on exit 0. This
|
|
325
|
+
// mirrors the in-place guard in runInPlaceMode; on the worktree path it also prevents an empty task
|
|
326
|
+
// from being committed, merged, and unblocking downstream tasks. Only a successful run is reconsidered;
|
|
327
|
+
// rate-limit and failure outcomes pass through unchanged.
|
|
328
|
+
export function downgradeUnfilledResult(agentResult, resultPath, mode, scaffoldFrontmatter, originalScaffoldFrontmatter) {
|
|
329
|
+
if (agentResult === "success" &&
|
|
330
|
+
resultPath &&
|
|
331
|
+
isResultUnfilled(resultPath, mode, scaffoldFrontmatter, originalScaffoldFrontmatter)) {
|
|
332
|
+
return { result: "failure", unfilledBlock: true };
|
|
333
|
+
}
|
|
334
|
+
return { result: agentResult, unfilledBlock: false };
|
|
335
|
+
}
|
|
336
|
+
export function checkCompletionBeforeIntegration(schedule, snapshot, taskId, actor) {
|
|
337
|
+
return canCompleteTask(schedule, snapshot, taskId, actor);
|
|
338
|
+
}
|
|
339
|
+
export function readCompletionPreflight(schedulePath, taskId, actor) {
|
|
340
|
+
try {
|
|
341
|
+
const schedule = buildScheduleIndex(schedulePath);
|
|
342
|
+
const events = readAllEventFiles(schedulePath);
|
|
343
|
+
const initialTasks = buildInitialStateFromStrategy(schedulePath, schedule);
|
|
344
|
+
const snapshot = foldEventsToState(events, schedule, schedulePath, initialTasks);
|
|
345
|
+
return checkCompletionBeforeIntegration(schedule, snapshot, taskId, actor);
|
|
346
|
+
}
|
|
347
|
+
catch (error) {
|
|
348
|
+
return {
|
|
349
|
+
ok: false,
|
|
350
|
+
reason: `could not validate current task state: ${error instanceof Error ? error.message : String(error)}`,
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
}
|