@h-rig/cli 0.0.6-alpha.28 → 0.0.6-alpha.280
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 +6 -28
- package/package.json +11 -28
- package/dist/bin/build-rig-binaries.js +0 -107
- package/dist/bin/rig.js +0 -11739
- package/dist/src/commands/_authority-runs.js +0 -111
- package/dist/src/commands/_cli-format.js +0 -369
- package/dist/src/commands/_connection-state.js +0 -123
- package/dist/src/commands/_doctor-checks.js +0 -507
- package/dist/src/commands/_help-catalog.js +0 -364
- package/dist/src/commands/_operator-surface.js +0 -204
- package/dist/src/commands/_operator-view.js +0 -1147
- package/dist/src/commands/_parsers.js +0 -107
- package/dist/src/commands/_paths.js +0 -50
- package/dist/src/commands/_pi-frontend.js +0 -843
- package/dist/src/commands/_pi-install.js +0 -185
- package/dist/src/commands/_pi-worker-bridge-extension.js +0 -761
- package/dist/src/commands/_policy.js +0 -79
- package/dist/src/commands/_preflight.js +0 -403
- package/dist/src/commands/_probes.js +0 -13
- package/dist/src/commands/_run-driver-helpers.js +0 -289
- package/dist/src/commands/_server-client.js +0 -514
- package/dist/src/commands/_snapshot-upload.js +0 -318
- package/dist/src/commands/_task-picker.js +0 -76
- package/dist/src/commands/agent.js +0 -499
- package/dist/src/commands/browser.js +0 -890
- package/dist/src/commands/connect.js +0 -289
- package/dist/src/commands/dist.js +0 -402
- package/dist/src/commands/doctor.js +0 -517
- package/dist/src/commands/github.js +0 -281
- package/dist/src/commands/inbox.js +0 -482
- package/dist/src/commands/init.js +0 -1563
- package/dist/src/commands/inspect.js +0 -174
- package/dist/src/commands/inspector.js +0 -256
- package/dist/src/commands/plugin.js +0 -167
- package/dist/src/commands/profile-and-review.js +0 -178
- package/dist/src/commands/queue.js +0 -198
- package/dist/src/commands/remote.js +0 -507
- package/dist/src/commands/repo-git-harness.js +0 -221
- package/dist/src/commands/run.js +0 -1808
- package/dist/src/commands/server.js +0 -572
- package/dist/src/commands/setup.js +0 -687
- package/dist/src/commands/task-report-bug.js +0 -1083
- package/dist/src/commands/task-run-driver.js +0 -2600
- package/dist/src/commands/task.js +0 -2606
- package/dist/src/commands/test.js +0 -39
- package/dist/src/commands/workspace.js +0 -123
- package/dist/src/commands.js +0 -11418
- package/dist/src/index.js +0 -11757
- package/dist/src/launcher.js +0 -133
- package/dist/src/report-bug.js +0 -260
- package/dist/src/runner.js +0 -273
- package/dist/src/withMutedConsole.js +0 -42
|
@@ -1,2600 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
// packages/cli/src/commands/task-run-driver.ts
|
|
3
|
-
import { copyFileSync, existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync4, statSync, writeFileSync as writeFileSync2 } from "fs";
|
|
4
|
-
import { resolve as resolve6 } from "path";
|
|
5
|
-
import { spawn, spawnSync } from "child_process";
|
|
6
|
-
import { createInterface as createLineInterface } from "readline";
|
|
7
|
-
|
|
8
|
-
// packages/cli/src/runner.ts
|
|
9
|
-
import { EventBus } from "@rig/runtime/control-plane/runtime/events";
|
|
10
|
-
import { CliError } from "@rig/runtime/control-plane/errors";
|
|
11
|
-
import { evaluate, loadPolicy, resolveAction } from "@rig/runtime/control-plane/runtime/guard";
|
|
12
|
-
import { PluginManager } from "@rig/runtime/control-plane/runtime/plugins";
|
|
13
|
-
import { loadRuntimeContextFromEnv } from "@rig/runtime/control-plane/runtime/context";
|
|
14
|
-
import { buildBinary } from "@rig/runtime/control-plane/runtime/isolation";
|
|
15
|
-
import { CliError as CliError2 } from "@rig/runtime/control-plane/errors";
|
|
16
|
-
function formatCommand(parts) {
|
|
17
|
-
return parts.map((part) => /[^a-zA-Z0-9_./:-]/.test(part) ? JSON.stringify(part) : part).join(" ");
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// packages/cli/src/commands/task-run-driver.ts
|
|
21
|
-
import { loadConfig } from "@rig/core/load-config";
|
|
22
|
-
import {
|
|
23
|
-
listAgentRuntimes,
|
|
24
|
-
startRuntimeSnapshotSidecar
|
|
25
|
-
} from "@rig/runtime/control-plane/runtime/isolation";
|
|
26
|
-
import {
|
|
27
|
-
finalizeTaskRunSnapshot,
|
|
28
|
-
resolveTaskRunSnapshotSidecar
|
|
29
|
-
} from "@rig/runtime/control-plane/runtime/snapshot/task-run";
|
|
30
|
-
import { loadRuntimeSnapshotConfig } from "@rig/runtime/control-plane/runtime/guard";
|
|
31
|
-
import {
|
|
32
|
-
buildClaudeLogsFromRecord,
|
|
33
|
-
flushPendingClaudeToolUseLogs
|
|
34
|
-
} from "@rig/runtime/control-plane/provider/claude-stream-records";
|
|
35
|
-
import {
|
|
36
|
-
buildCodexLogsFromRecord,
|
|
37
|
-
extractCodexAssistantMessageText,
|
|
38
|
-
flushPendingCodexToolUseLogs,
|
|
39
|
-
isCodexExecRecord
|
|
40
|
-
} from "@rig/runtime/control-plane/provider/codex-exec-records";
|
|
41
|
-
import { resolvePreferredShellBinary } from "@rig/runtime/control-plane/native/run-ops";
|
|
42
|
-
import { readAuthorityRun as readAuthorityRun3, readJsonFile as readJsonFile2, resolveTaskArtifactDirs } from "@rig/runtime/control-plane/authority-files";
|
|
43
|
-
import {
|
|
44
|
-
buildTaskRunLifecycleComment
|
|
45
|
-
} from "@rig/runtime/control-plane/tasks/source-lifecycle";
|
|
46
|
-
import {
|
|
47
|
-
closeIssueAfterMergedPr,
|
|
48
|
-
commitRunChanges,
|
|
49
|
-
runPrAutomation
|
|
50
|
-
} from "@rig/runtime/control-plane/native/pr-automation";
|
|
51
|
-
|
|
52
|
-
// packages/cli/src/commands/_run-driver-helpers.ts
|
|
53
|
-
import { readFileSync } from "fs";
|
|
54
|
-
import { resolve as resolve3 } from "path";
|
|
55
|
-
import {
|
|
56
|
-
appendJsonlRecord,
|
|
57
|
-
readAuthorityRun as readAuthorityRun2,
|
|
58
|
-
resolveAuthorityRunDir as resolveAuthorityRunDir2,
|
|
59
|
-
writeJsonFile as writeJsonFile2
|
|
60
|
-
} from "@rig/runtime/control-plane/authority-files";
|
|
61
|
-
import { taskLookup } from "@rig/runtime/control-plane/native/task-ops";
|
|
62
|
-
import { buildProviderTaskRunInstructionLines } from "@rig/runtime/control-plane/provider/runtime-instructions";
|
|
63
|
-
import { loadRigTaskRunSkillBody } from "@rig/runtime/control-plane/provider/rig-task-run-skill";
|
|
64
|
-
|
|
65
|
-
// packages/cli/src/commands/_authority-runs.ts
|
|
66
|
-
import { existsSync } from "fs";
|
|
67
|
-
import { resolve as resolve2 } from "path";
|
|
68
|
-
import {
|
|
69
|
-
readAuthorityRun,
|
|
70
|
-
readJsonlFile,
|
|
71
|
-
resolveAuthorityRunDir,
|
|
72
|
-
writeJsonFile
|
|
73
|
-
} from "@rig/runtime/control-plane/authority-files";
|
|
74
|
-
|
|
75
|
-
// packages/cli/src/commands/_paths.ts
|
|
76
|
-
import { resolve } from "path";
|
|
77
|
-
import { resolveMonorepoRoot } from "@rig/runtime/control-plane/native/utils";
|
|
78
|
-
function resolveControlPlaneMonorepoRoot(projectRoot) {
|
|
79
|
-
return resolveMonorepoRoot(projectRoot);
|
|
80
|
-
}
|
|
81
|
-
function resolveControlPlaneTaskConfigPath(projectRoot) {
|
|
82
|
-
return resolve(resolveControlPlaneMonorepoRoot(projectRoot), ".rig", "task-config.json");
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// packages/cli/src/commands/_authority-runs.ts
|
|
86
|
-
var RIG_WORKSPACE_ID = "rig-local-workspace";
|
|
87
|
-
function normalizeRuntimeAdapter(value) {
|
|
88
|
-
const normalized = value?.trim().toLowerCase();
|
|
89
|
-
if (!normalized) {
|
|
90
|
-
return "pi";
|
|
91
|
-
}
|
|
92
|
-
if (normalized === "codex" || normalized === "codex-cli" || normalized === "codex-app-server" || normalized === "gpt-codex") {
|
|
93
|
-
return "codex";
|
|
94
|
-
}
|
|
95
|
-
if (normalized === "pi" || normalized === "rig-pi" || normalized === "@rig/pi") {
|
|
96
|
-
return "pi";
|
|
97
|
-
}
|
|
98
|
-
return "claude-code";
|
|
99
|
-
}
|
|
100
|
-
function readLatestBeadRecord(projectRoot, taskId) {
|
|
101
|
-
const issuesPath = resolve2(resolveControlPlaneMonorepoRoot(projectRoot), ".beads", "issues.jsonl");
|
|
102
|
-
if (!existsSync(issuesPath)) {
|
|
103
|
-
return null;
|
|
104
|
-
}
|
|
105
|
-
let latest = null;
|
|
106
|
-
for (const issue of readJsonlFile(issuesPath)) {
|
|
107
|
-
if (!issue || typeof issue !== "object") {
|
|
108
|
-
continue;
|
|
109
|
-
}
|
|
110
|
-
const record = issue;
|
|
111
|
-
if (record.id === taskId) {
|
|
112
|
-
latest = record;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return latest;
|
|
116
|
-
}
|
|
117
|
-
function resolveTaskTitleForAuthorityRun(projectRoot, taskId) {
|
|
118
|
-
try {
|
|
119
|
-
const record = readLatestBeadRecord(projectRoot, taskId);
|
|
120
|
-
const title = record && typeof record.title === "string" ? record.title.trim() : "";
|
|
121
|
-
if (title) {
|
|
122
|
-
return title;
|
|
123
|
-
}
|
|
124
|
-
} catch {}
|
|
125
|
-
return null;
|
|
126
|
-
}
|
|
127
|
-
function upsertAgentAuthorityRun(projectRoot, input) {
|
|
128
|
-
const current = readAuthorityRun(projectRoot, input.runId);
|
|
129
|
-
const existing = current;
|
|
130
|
-
const createdAt = existing?.createdAt ?? input.createdAt;
|
|
131
|
-
const runtimeMode = typeof existing?.runtimeMode === "string" ? existing.runtimeMode : "full-access";
|
|
132
|
-
const interactionMode = typeof existing?.interactionMode === "string" ? existing.interactionMode : "default";
|
|
133
|
-
const runMode = typeof existing?.runMode === "string" ? existing.runMode : "autonomous";
|
|
134
|
-
const runtimeAdapter = normalizeRuntimeAdapter(input.runtimeAdapter ?? existing?.runtimeAdapter ?? "claude-code");
|
|
135
|
-
const title = resolveTaskTitleForAuthorityRun(projectRoot, input.taskId) ?? input.taskId;
|
|
136
|
-
const next = {
|
|
137
|
-
...existing ?? {},
|
|
138
|
-
runId: input.runId,
|
|
139
|
-
projectRoot,
|
|
140
|
-
workspaceId: existing?.workspaceId ?? RIG_WORKSPACE_ID,
|
|
141
|
-
taskId: input.taskId,
|
|
142
|
-
threadId: existing?.threadId ?? null,
|
|
143
|
-
mode: "local",
|
|
144
|
-
runtimeAdapter,
|
|
145
|
-
status: input.status,
|
|
146
|
-
createdAt,
|
|
147
|
-
startedAt: input.startedAt ?? existing?.startedAt ?? null,
|
|
148
|
-
completedAt: input.completedAt ?? existing?.completedAt ?? null,
|
|
149
|
-
endpointId: existing?.endpointId ?? null,
|
|
150
|
-
hostId: existing?.hostId ?? null,
|
|
151
|
-
worktreePath: input.worktreePath ?? existing?.worktreePath ?? null,
|
|
152
|
-
artifactRoot: input.artifactRoot ?? existing?.artifactRoot ?? null,
|
|
153
|
-
logRoot: input.logRoot ?? existing?.logRoot ?? null,
|
|
154
|
-
sessionPath: input.sessionPath ?? existing?.sessionPath ?? null,
|
|
155
|
-
sessionLogPath: input.sessionLogPath ?? existing?.sessionLogPath ?? null,
|
|
156
|
-
pid: input.pid ?? existing?.pid ?? null,
|
|
157
|
-
updatedAt: input.createdAt,
|
|
158
|
-
title,
|
|
159
|
-
model: typeof existing?.model === "string" ? existing.model : null,
|
|
160
|
-
runtimeMode,
|
|
161
|
-
interactionMode,
|
|
162
|
-
runMode,
|
|
163
|
-
initialPrompt: typeof existing?.initialPrompt === "string" ? existing.initialPrompt : null
|
|
164
|
-
};
|
|
165
|
-
if (input.errorText !== undefined) {
|
|
166
|
-
next.errorText = input.errorText;
|
|
167
|
-
} else if ("errorText" in next) {
|
|
168
|
-
delete next.errorText;
|
|
169
|
-
}
|
|
170
|
-
writeJsonFile(resolve2(resolveAuthorityRunDir(projectRoot, input.runId), "run.json"), next);
|
|
171
|
-
return next;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// packages/cli/src/commands/_run-driver-helpers.ts
|
|
175
|
-
function patchAuthorityRun(projectRoot, runId, patch) {
|
|
176
|
-
const current = readAuthorityRun2(projectRoot, runId);
|
|
177
|
-
if (!current) {
|
|
178
|
-
throw new CliError2(`Run not found: ${runId}`, 2);
|
|
179
|
-
}
|
|
180
|
-
const next = {
|
|
181
|
-
...current,
|
|
182
|
-
...patch,
|
|
183
|
-
updatedAt: new Date().toISOString()
|
|
184
|
-
};
|
|
185
|
-
writeJsonFile2(resolve3(resolveAuthorityRunDir2(projectRoot, runId), "run.json"), next);
|
|
186
|
-
return next;
|
|
187
|
-
}
|
|
188
|
-
function touchAuthorityRun(projectRoot, runId) {
|
|
189
|
-
const current = readAuthorityRun2(projectRoot, runId);
|
|
190
|
-
if (!current) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
writeJsonFile2(resolve3(resolveAuthorityRunDir2(projectRoot, runId), "run.json"), {
|
|
194
|
-
...current,
|
|
195
|
-
updatedAt: new Date().toISOString()
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
function appendRunTimeline(projectRoot, runId, value) {
|
|
199
|
-
appendJsonlRecord(resolve3(resolveAuthorityRunDir2(projectRoot, runId), "timeline.jsonl"), value);
|
|
200
|
-
touchAuthorityRun(projectRoot, runId);
|
|
201
|
-
}
|
|
202
|
-
function appendRunLog(projectRoot, runId, value) {
|
|
203
|
-
appendJsonlRecord(resolve3(resolveAuthorityRunDir2(projectRoot, runId), "logs.jsonl"), value);
|
|
204
|
-
touchAuthorityRun(projectRoot, runId);
|
|
205
|
-
}
|
|
206
|
-
function appendRunAction(projectRoot, runId, value) {
|
|
207
|
-
appendJsonlRecord(resolve3(resolveAuthorityRunDir2(projectRoot, runId), "timeline.jsonl"), {
|
|
208
|
-
id: value.id,
|
|
209
|
-
type: "action",
|
|
210
|
-
actionType: value.actionType,
|
|
211
|
-
title: value.title,
|
|
212
|
-
detail: value.detail ?? null,
|
|
213
|
-
state: value.state,
|
|
214
|
-
createdAt: value.startedAt,
|
|
215
|
-
completedAt: value.completedAt ?? null,
|
|
216
|
-
payload: value.payload ?? {}
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
function startRunAction(projectRoot, runId, input) {
|
|
220
|
-
const startedAt = new Date().toISOString();
|
|
221
|
-
appendRunAction(projectRoot, runId, {
|
|
222
|
-
id: input.actionId,
|
|
223
|
-
actionType: input.actionType,
|
|
224
|
-
title: input.title,
|
|
225
|
-
detail: input.detail,
|
|
226
|
-
state: "running",
|
|
227
|
-
startedAt,
|
|
228
|
-
payload: input.payload
|
|
229
|
-
});
|
|
230
|
-
emitServerRunEvent({ type: "timeline", runId });
|
|
231
|
-
return {
|
|
232
|
-
startedAt,
|
|
233
|
-
complete: (detail, payload) => {
|
|
234
|
-
appendRunAction(projectRoot, runId, {
|
|
235
|
-
id: input.actionId,
|
|
236
|
-
actionType: input.actionType,
|
|
237
|
-
title: input.title,
|
|
238
|
-
detail: detail ?? input.detail ?? null,
|
|
239
|
-
state: "completed",
|
|
240
|
-
startedAt,
|
|
241
|
-
completedAt: new Date().toISOString(),
|
|
242
|
-
payload: payload ?? input.payload
|
|
243
|
-
});
|
|
244
|
-
emitServerRunEvent({ type: "timeline", runId });
|
|
245
|
-
},
|
|
246
|
-
fail: (detail, payload) => {
|
|
247
|
-
appendRunAction(projectRoot, runId, {
|
|
248
|
-
id: input.actionId,
|
|
249
|
-
actionType: input.actionType,
|
|
250
|
-
title: input.title,
|
|
251
|
-
detail,
|
|
252
|
-
state: "failed",
|
|
253
|
-
startedAt,
|
|
254
|
-
completedAt: new Date().toISOString(),
|
|
255
|
-
payload: payload ?? input.payload
|
|
256
|
-
});
|
|
257
|
-
emitServerRunEvent({ type: "timeline", runId });
|
|
258
|
-
}
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
function emitServerRunEvent(event) {
|
|
262
|
-
console.log(`__RIG_RUN_EVENT__${JSON.stringify({ ...event, at: new Date().toISOString() })}`);
|
|
263
|
-
}
|
|
264
|
-
function buildRunPrompt(input) {
|
|
265
|
-
const initialPrompt = input.initialPrompt?.trim() || null;
|
|
266
|
-
if (!input.taskId) {
|
|
267
|
-
return initialPrompt ?? input.fallbackTitle?.trim() ?? "Continue the requested Rig run and complete the work.";
|
|
268
|
-
}
|
|
269
|
-
const issues = (() => {
|
|
270
|
-
try {
|
|
271
|
-
return taskLookup(input.projectRoot, input.taskId);
|
|
272
|
-
} catch {
|
|
273
|
-
return "";
|
|
274
|
-
}
|
|
275
|
-
})();
|
|
276
|
-
const scopeText = (() => {
|
|
277
|
-
try {
|
|
278
|
-
const parsed = JSON.parse(readFileSync(resolveControlPlaneTaskConfigPath(input.projectRoot), "utf8"));
|
|
279
|
-
const entry = parsed[input.taskId] ?? {};
|
|
280
|
-
const scope = Array.isArray(entry.scope) ? entry.scope.filter((item) => typeof item === "string") : [];
|
|
281
|
-
const validation = Array.isArray(entry.validation) ? entry.validation.filter((item) => typeof item === "string") : [];
|
|
282
|
-
const lines = [];
|
|
283
|
-
if (scope.length > 0)
|
|
284
|
-
lines.push(`Scope:
|
|
285
|
-
- ${scope.join(`
|
|
286
|
-
- `)}`);
|
|
287
|
-
if (validation.length > 0)
|
|
288
|
-
lines.push(`Validation:
|
|
289
|
-
- ${validation.join(`
|
|
290
|
-
- `)}`);
|
|
291
|
-
return lines.join(`
|
|
292
|
-
|
|
293
|
-
`);
|
|
294
|
-
} catch {
|
|
295
|
-
return "";
|
|
296
|
-
}
|
|
297
|
-
})();
|
|
298
|
-
const bead = readLatestBeadRecord(input.projectRoot, input.taskId);
|
|
299
|
-
const sourceTask = input.sourceTask ?? null;
|
|
300
|
-
const sourceDescription = firstPromptString(sourceTask?.description, sourceTask?.body);
|
|
301
|
-
const sourceAcceptance = firstPromptString(sourceTask?.acceptanceCriteria, sourceTask?.acceptance_criteria);
|
|
302
|
-
const sourceValidation = uniqueStrings([...sourceTask?.validation ?? [], ...sourceTask?.validators ?? []]);
|
|
303
|
-
const title = (bead && typeof bead === "object" && typeof bead.title === "string" ? bead.title : null) ?? firstPromptString(sourceTask?.title) ?? input.fallbackTitle ?? issues ?? input.taskId;
|
|
304
|
-
const description = (bead && typeof bead === "object" && typeof bead.description === "string" ? bead.description : null) ?? sourceDescription ?? input.fallbackDescription ?? "";
|
|
305
|
-
const acceptance = bead && typeof bead === "object" && typeof bead.acceptance_criteria === "string" ? bead.acceptance_criteria : sourceAcceptance ?? input.fallbackAcceptanceCriteria ?? "";
|
|
306
|
-
const sourceContractLines = renderSourceTaskContract(sourceTask, sourceValidation);
|
|
307
|
-
const providerLines = buildProviderTaskRunInstructionLines(input.runtimeAdapter);
|
|
308
|
-
const skillBody = loadRigTaskRunSkillBody();
|
|
309
|
-
return [
|
|
310
|
-
`You are working on task ${input.taskId}: ${title}.`,
|
|
311
|
-
description ? `Description:
|
|
312
|
-
${description}` : null,
|
|
313
|
-
acceptance ? `Acceptance criteria:
|
|
314
|
-
${acceptance}` : null,
|
|
315
|
-
sourceContractLines.length > 0 ? `Source task contract:
|
|
316
|
-
${sourceContractLines.join(`
|
|
317
|
-
`)}` : null,
|
|
318
|
-
scopeText || renderSourceScopeValidation(sourceTask, sourceValidation) || null,
|
|
319
|
-
initialPrompt ? `Additional operator guidance:
|
|
320
|
-
${initialPrompt}` : null,
|
|
321
|
-
providerLines.length > 0 ? `Provider-specific runtime tooling:
|
|
322
|
-
${providerLines.join(" ")}` : null,
|
|
323
|
-
skillBody || null
|
|
324
|
-
].filter((value) => Boolean(value)).join(`
|
|
325
|
-
|
|
326
|
-
`);
|
|
327
|
-
}
|
|
328
|
-
function firstPromptString(...values) {
|
|
329
|
-
for (const value of values) {
|
|
330
|
-
const trimmed = typeof value === "string" ? value.trim() : "";
|
|
331
|
-
if (trimmed.length > 0) {
|
|
332
|
-
return trimmed;
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
return null;
|
|
336
|
-
}
|
|
337
|
-
function uniqueStrings(values) {
|
|
338
|
-
return Array.from(new Set(values.map((value) => value.trim()).filter(Boolean)));
|
|
339
|
-
}
|
|
340
|
-
function renderSourceTaskContract(task, validation) {
|
|
341
|
-
if (!task) {
|
|
342
|
-
return [];
|
|
343
|
-
}
|
|
344
|
-
const lines = [];
|
|
345
|
-
const sourceIssueId = firstPromptString(task.sourceIssueId);
|
|
346
|
-
if (sourceIssueId)
|
|
347
|
-
lines.push(`Source issue: ${sourceIssueId}`);
|
|
348
|
-
const status = firstPromptString(task.status);
|
|
349
|
-
if (status)
|
|
350
|
-
lines.push(`Source status: ${status}`);
|
|
351
|
-
const issueType = firstPromptString(task.issueType);
|
|
352
|
-
if (issueType)
|
|
353
|
-
lines.push(`Issue type: ${issueType}`);
|
|
354
|
-
const role = firstPromptString(task.role);
|
|
355
|
-
if (role)
|
|
356
|
-
lines.push(`Role: ${role}`);
|
|
357
|
-
const externalRef = firstPromptString(task.externalRef);
|
|
358
|
-
if (externalRef)
|
|
359
|
-
lines.push(`External ref: ${externalRef}`);
|
|
360
|
-
const labels = uniqueStrings(task.labels ?? []);
|
|
361
|
-
if (labels.length > 0)
|
|
362
|
-
lines.push(`Labels:
|
|
363
|
-
- ${labels.join(`
|
|
364
|
-
- `)}`);
|
|
365
|
-
if (validation.length > 0)
|
|
366
|
-
lines.push(`Validators:
|
|
367
|
-
- ${validation.join(`
|
|
368
|
-
- `)}`);
|
|
369
|
-
return lines;
|
|
370
|
-
}
|
|
371
|
-
function renderSourceScopeValidation(task, validation) {
|
|
372
|
-
if (!task) {
|
|
373
|
-
return "";
|
|
374
|
-
}
|
|
375
|
-
const lines = [];
|
|
376
|
-
const scope = uniqueStrings(task.scope ?? []);
|
|
377
|
-
if (scope.length > 0)
|
|
378
|
-
lines.push(`Scope:
|
|
379
|
-
- ${scope.join(`
|
|
380
|
-
- `)}`);
|
|
381
|
-
if (validation.length > 0)
|
|
382
|
-
lines.push(`Validation:
|
|
383
|
-
- ${validation.join(`
|
|
384
|
-
- `)}`);
|
|
385
|
-
return lines.join(`
|
|
386
|
-
|
|
387
|
-
`);
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
// packages/cli/src/commands/_server-client.ts
|
|
391
|
-
import { existsSync as existsSync3, readFileSync as readFileSync3 } from "fs";
|
|
392
|
-
import { resolve as resolve5 } from "path";
|
|
393
|
-
import { ensureLocalRigServerConnection } from "@rig/runtime/local-server";
|
|
394
|
-
|
|
395
|
-
// packages/cli/src/commands/_connection-state.ts
|
|
396
|
-
import { existsSync as existsSync2, mkdirSync, readFileSync as readFileSync2, writeFileSync } from "fs";
|
|
397
|
-
import { homedir } from "os";
|
|
398
|
-
import { dirname, resolve as resolve4 } from "path";
|
|
399
|
-
function resolveGlobalConnectionsPath(env = process.env) {
|
|
400
|
-
const explicit = env.RIG_CONNECTIONS_FILE?.trim();
|
|
401
|
-
if (explicit)
|
|
402
|
-
return resolve4(explicit);
|
|
403
|
-
const stateDir = env.RIG_GLOBAL_STATE_DIR?.trim();
|
|
404
|
-
if (stateDir)
|
|
405
|
-
return resolve4(stateDir, "connections.json");
|
|
406
|
-
return resolve4(homedir(), ".rig", "connections.json");
|
|
407
|
-
}
|
|
408
|
-
function resolveRepoConnectionPath(projectRoot) {
|
|
409
|
-
return resolve4(projectRoot, ".rig", "state", "connection.json");
|
|
410
|
-
}
|
|
411
|
-
function readJsonFile(path) {
|
|
412
|
-
if (!existsSync2(path))
|
|
413
|
-
return null;
|
|
414
|
-
try {
|
|
415
|
-
return JSON.parse(readFileSync2(path, "utf8"));
|
|
416
|
-
} catch (error) {
|
|
417
|
-
throw new CliError2(`Invalid Rig connection state at ${path}: ${error instanceof Error ? error.message : String(error)}`, 1);
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
function normalizeConnection(value) {
|
|
421
|
-
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
422
|
-
return null;
|
|
423
|
-
const record = value;
|
|
424
|
-
if (record.kind === "local")
|
|
425
|
-
return { kind: "local", mode: "auto" };
|
|
426
|
-
if (record.kind === "remote" && typeof record.baseUrl === "string" && record.baseUrl.trim()) {
|
|
427
|
-
const baseUrl = record.baseUrl.trim().replace(/\/+$/, "");
|
|
428
|
-
return { kind: "remote", baseUrl };
|
|
429
|
-
}
|
|
430
|
-
return null;
|
|
431
|
-
}
|
|
432
|
-
function readGlobalConnections(options = {}) {
|
|
433
|
-
const path = resolveGlobalConnectionsPath(options.env ?? process.env);
|
|
434
|
-
const payload = readJsonFile(path);
|
|
435
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
436
|
-
return { connections: {} };
|
|
437
|
-
}
|
|
438
|
-
const rawConnections = payload.connections;
|
|
439
|
-
const connections = {};
|
|
440
|
-
if (rawConnections && typeof rawConnections === "object" && !Array.isArray(rawConnections)) {
|
|
441
|
-
for (const [alias, raw] of Object.entries(rawConnections)) {
|
|
442
|
-
const connection = normalizeConnection(raw);
|
|
443
|
-
if (connection)
|
|
444
|
-
connections[alias] = connection;
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
return { connections };
|
|
448
|
-
}
|
|
449
|
-
function readRepoConnection(projectRoot) {
|
|
450
|
-
const payload = readJsonFile(resolveRepoConnectionPath(projectRoot));
|
|
451
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
452
|
-
return null;
|
|
453
|
-
const record = payload;
|
|
454
|
-
const selected = typeof record.selected === "string" ? record.selected.trim() : "";
|
|
455
|
-
if (!selected)
|
|
456
|
-
return null;
|
|
457
|
-
return {
|
|
458
|
-
selected,
|
|
459
|
-
project: typeof record.project === "string" ? record.project : undefined,
|
|
460
|
-
linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined
|
|
461
|
-
};
|
|
462
|
-
}
|
|
463
|
-
function resolveSelectedConnection(projectRoot, options = {}) {
|
|
464
|
-
const repo = readRepoConnection(projectRoot);
|
|
465
|
-
if (!repo)
|
|
466
|
-
return null;
|
|
467
|
-
if (repo.selected === "local")
|
|
468
|
-
return { alias: "local", connection: { kind: "local", mode: "auto" } };
|
|
469
|
-
const global = readGlobalConnections(options);
|
|
470
|
-
const connection = global.connections[repo.selected];
|
|
471
|
-
if (!connection) {
|
|
472
|
-
throw new CliError2(`Selected Rig server "${repo.selected}" was not found. Run \`rig server list\` or \`rig server use local\`.`, 1);
|
|
473
|
-
}
|
|
474
|
-
return { alias: repo.selected, connection };
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
// packages/cli/src/commands/_server-client.ts
|
|
478
|
-
var scopedGitHubBearerTokens = new Map;
|
|
479
|
-
function cleanToken(value) {
|
|
480
|
-
const trimmed = value?.trim();
|
|
481
|
-
return trimmed ? trimmed : null;
|
|
482
|
-
}
|
|
483
|
-
function readPrivateRemoteSessionToken(projectRoot) {
|
|
484
|
-
const path = resolve5(projectRoot, ".rig", "state", "github-auth.json");
|
|
485
|
-
if (!existsSync3(path))
|
|
486
|
-
return null;
|
|
487
|
-
try {
|
|
488
|
-
const parsed = JSON.parse(readFileSync3(path, "utf8"));
|
|
489
|
-
return cleanToken(typeof parsed.apiSessionToken === "string" ? parsed.apiSessionToken : typeof parsed.sessionToken === "string" ? parsed.sessionToken : undefined);
|
|
490
|
-
} catch {
|
|
491
|
-
return null;
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
function readGitHubBearerTokenForRemote(projectRoot) {
|
|
495
|
-
const scopedKey = resolve5(projectRoot);
|
|
496
|
-
if (scopedGitHubBearerTokens.has(scopedKey))
|
|
497
|
-
return scopedGitHubBearerTokens.get(scopedKey) ?? null;
|
|
498
|
-
const privateSession = readPrivateRemoteSessionToken(projectRoot);
|
|
499
|
-
if (privateSession)
|
|
500
|
-
return privateSession;
|
|
501
|
-
return cleanToken(process.env.RIG_SERVER_AUTH_TOKEN) ?? cleanToken(process.env.RIG_REMOTE_AUTH_TOKEN);
|
|
502
|
-
}
|
|
503
|
-
async function ensureServerForCli(projectRoot) {
|
|
504
|
-
try {
|
|
505
|
-
const selected = resolveSelectedConnection(projectRoot);
|
|
506
|
-
if (selected?.connection.kind === "remote") {
|
|
507
|
-
return {
|
|
508
|
-
baseUrl: selected.connection.baseUrl,
|
|
509
|
-
authToken: readGitHubBearerTokenForRemote(projectRoot),
|
|
510
|
-
connectionKind: "remote"
|
|
511
|
-
};
|
|
512
|
-
}
|
|
513
|
-
const connection = await ensureLocalRigServerConnection(projectRoot);
|
|
514
|
-
return {
|
|
515
|
-
baseUrl: connection.baseUrl,
|
|
516
|
-
authToken: connection.authToken,
|
|
517
|
-
connectionKind: "local"
|
|
518
|
-
};
|
|
519
|
-
} catch (error) {
|
|
520
|
-
if (error instanceof Error) {
|
|
521
|
-
throw new CliError2(error.message, 1);
|
|
522
|
-
}
|
|
523
|
-
throw error;
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
function mergeHeaders(headers, authToken) {
|
|
527
|
-
const merged = new Headers(headers);
|
|
528
|
-
if (authToken) {
|
|
529
|
-
merged.set("authorization", `Bearer ${authToken}`);
|
|
530
|
-
}
|
|
531
|
-
return merged;
|
|
532
|
-
}
|
|
533
|
-
function diagnosticMessage(payload) {
|
|
534
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
535
|
-
return null;
|
|
536
|
-
const record = payload;
|
|
537
|
-
const diagnostics = Array.isArray(record.diagnostics) ? record.diagnostics : [];
|
|
538
|
-
const messages = diagnostics.flatMap((entry) => {
|
|
539
|
-
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
540
|
-
return [];
|
|
541
|
-
const diagnostic = entry;
|
|
542
|
-
const kind = typeof diagnostic.kind === "string" ? diagnostic.kind : "task-source";
|
|
543
|
-
const message = typeof diagnostic.message === "string" ? diagnostic.message : null;
|
|
544
|
-
return message ? [`${kind}: ${message}`] : [];
|
|
545
|
-
});
|
|
546
|
-
return messages.length > 0 ? messages.join("; ") : null;
|
|
547
|
-
}
|
|
548
|
-
async function requestServerJson(context, pathname, init = {}) {
|
|
549
|
-
const server = await ensureServerForCli(context.projectRoot);
|
|
550
|
-
const response = await fetch(`${server.baseUrl}${pathname}`, {
|
|
551
|
-
...init,
|
|
552
|
-
headers: mergeHeaders(init.headers, server.authToken)
|
|
553
|
-
});
|
|
554
|
-
const text = await response.text();
|
|
555
|
-
const payload = text.trim().length > 0 ? (() => {
|
|
556
|
-
try {
|
|
557
|
-
return JSON.parse(text);
|
|
558
|
-
} catch {
|
|
559
|
-
return null;
|
|
560
|
-
}
|
|
561
|
-
})() : null;
|
|
562
|
-
if (!response.ok) {
|
|
563
|
-
const diagnostics = diagnosticMessage(payload);
|
|
564
|
-
const detail = diagnostics ?? (text || response.statusText);
|
|
565
|
-
throw new CliError2(`Rig server request failed (${response.status}): ${detail}`, 1);
|
|
566
|
-
}
|
|
567
|
-
return payload;
|
|
568
|
-
}
|
|
569
|
-
async function updateWorkspaceTaskViaServer(context, input) {
|
|
570
|
-
const payload = await requestServerJson(context, "/api/tasks/update", {
|
|
571
|
-
method: "POST",
|
|
572
|
-
headers: { "content-type": "application/json" },
|
|
573
|
-
body: JSON.stringify(input)
|
|
574
|
-
});
|
|
575
|
-
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { ok: true };
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
// packages/cli/src/commands/task-run-driver.ts
|
|
579
|
-
var PI_CANONICAL_RUN_STAGES = [
|
|
580
|
-
"Connect",
|
|
581
|
-
"GitHub/task sync",
|
|
582
|
-
"Prepare workspace",
|
|
583
|
-
"Launch Pi",
|
|
584
|
-
"Plan",
|
|
585
|
-
"Implement",
|
|
586
|
-
"Validate",
|
|
587
|
-
"Commit",
|
|
588
|
-
"Open PR",
|
|
589
|
-
"Review/CI",
|
|
590
|
-
"Merge",
|
|
591
|
-
"Complete"
|
|
592
|
-
];
|
|
593
|
-
function canonicalPiRunStages() {
|
|
594
|
-
return [...PI_CANONICAL_RUN_STAGES];
|
|
595
|
-
}
|
|
596
|
-
function looksLikeGitHubToken(value) {
|
|
597
|
-
const token = value?.trim();
|
|
598
|
-
if (!token)
|
|
599
|
-
return false;
|
|
600
|
-
return /^(gh[opusr]_|github_pat_)/.test(token);
|
|
601
|
-
}
|
|
602
|
-
function githubBridgeEnv(token) {
|
|
603
|
-
const clean = token?.trim();
|
|
604
|
-
if (!clean)
|
|
605
|
-
return {};
|
|
606
|
-
return {
|
|
607
|
-
RIG_GITHUB_TOKEN: clean,
|
|
608
|
-
GITHUB_TOKEN: clean,
|
|
609
|
-
GH_TOKEN: clean
|
|
610
|
-
};
|
|
611
|
-
}
|
|
612
|
-
function buildPiRigBridgeEnv(input) {
|
|
613
|
-
const githubToken = input.githubToken?.trim() || (looksLikeGitHubToken(input.authToken) ? input.authToken.trim() : "");
|
|
614
|
-
return {
|
|
615
|
-
RIG_PROJECT_ROOT: input.projectRoot,
|
|
616
|
-
PROJECT_RIG_ROOT: input.projectRoot,
|
|
617
|
-
RIG_RUN_ID: input.runId,
|
|
618
|
-
RIG_SERVER_RUN_ID: input.runId,
|
|
619
|
-
RIG_TASK_ID: input.taskId,
|
|
620
|
-
RIG_RUNTIME_ADAPTER: "pi",
|
|
621
|
-
RIG_STEERING_POLL_MS: "0",
|
|
622
|
-
...input.serverUrl ? { RIG_SERVER_URL: input.serverUrl } : {},
|
|
623
|
-
...input.authToken ? { RIG_AUTH_TOKEN: input.authToken } : {},
|
|
624
|
-
...githubBridgeEnv(githubToken)
|
|
625
|
-
};
|
|
626
|
-
}
|
|
627
|
-
function runGitSync(cwd, args, input) {
|
|
628
|
-
const result = spawnSync("git", [...args], {
|
|
629
|
-
cwd,
|
|
630
|
-
input,
|
|
631
|
-
encoding: "utf8",
|
|
632
|
-
stdio: input === undefined ? ["ignore", "pipe", "pipe"] : ["pipe", "pipe", "pipe"]
|
|
633
|
-
});
|
|
634
|
-
return {
|
|
635
|
-
ok: result.status === 0,
|
|
636
|
-
stdout: result.stdout || "",
|
|
637
|
-
stderr: result.stderr || (result.error instanceof Error ? result.error.message : "")
|
|
638
|
-
};
|
|
639
|
-
}
|
|
640
|
-
function copyUntrackedDirtyFiles(sourceRoot, targetRoot) {
|
|
641
|
-
const listed = runGitSync(sourceRoot, ["ls-files", "--others", "--exclude-standard", "-z"]);
|
|
642
|
-
if (!listed.ok || !listed.stdout)
|
|
643
|
-
return 0;
|
|
644
|
-
let copied = 0;
|
|
645
|
-
for (const relativePath of listed.stdout.split("\x00").filter(Boolean)) {
|
|
646
|
-
const sourcePath = resolve6(sourceRoot, relativePath);
|
|
647
|
-
const targetPath = resolve6(targetRoot, relativePath);
|
|
648
|
-
try {
|
|
649
|
-
if (!statSync(sourcePath).isFile())
|
|
650
|
-
continue;
|
|
651
|
-
mkdirSync2(resolve6(targetPath, ".."), { recursive: true });
|
|
652
|
-
copyFileSync(sourcePath, targetPath);
|
|
653
|
-
copied += 1;
|
|
654
|
-
} catch {}
|
|
655
|
-
}
|
|
656
|
-
return copied;
|
|
657
|
-
}
|
|
658
|
-
function applyDirtyBaselineSnapshot(input) {
|
|
659
|
-
const diff = runGitSync(input.sourceRoot, ["diff", "--binary", "HEAD"]);
|
|
660
|
-
if (!diff.ok) {
|
|
661
|
-
return { applied: false, copiedUntracked: 0, detail: diff.stderr || "git diff failed" };
|
|
662
|
-
}
|
|
663
|
-
let applied = false;
|
|
664
|
-
if (diff.stdout.trim()) {
|
|
665
|
-
const apply = runGitSync(input.targetRoot, ["apply", "--whitespace=nowarn", "-"], diff.stdout);
|
|
666
|
-
if (!apply.ok) {
|
|
667
|
-
return { applied: false, copiedUntracked: 0, detail: apply.stderr || "git apply failed" };
|
|
668
|
-
}
|
|
669
|
-
applied = true;
|
|
670
|
-
}
|
|
671
|
-
const copiedUntracked = copyUntrackedDirtyFiles(input.sourceRoot, input.targetRoot);
|
|
672
|
-
return {
|
|
673
|
-
applied: applied || copiedUntracked > 0,
|
|
674
|
-
copiedUntracked,
|
|
675
|
-
detail: applied || copiedUntracked > 0 ? `Applied dirty baseline snapshot (${copiedUntracked} untracked files).` : "No dirty baseline changes to apply."
|
|
676
|
-
};
|
|
677
|
-
}
|
|
678
|
-
function buildTaskRunReviewEnv(config) {
|
|
679
|
-
const review = config?.review;
|
|
680
|
-
return {
|
|
681
|
-
...review?.mode ? { AI_REVIEW_MODE: review.mode } : {},
|
|
682
|
-
...review?.provider ? { AI_REVIEW_PROVIDER: review.provider } : {}
|
|
683
|
-
};
|
|
684
|
-
}
|
|
685
|
-
function buildDirtyBaselineHandshakeEnv(input) {
|
|
686
|
-
if (input.baselineMode !== "dirty-snapshot")
|
|
687
|
-
return { RIG_BASELINE_MODE: input.baselineMode ?? "head" };
|
|
688
|
-
return {
|
|
689
|
-
RIG_BASELINE_MODE: "dirty-snapshot",
|
|
690
|
-
RIG_DIRTY_BASELINE_READY_FILE: resolve6(input.projectRoot, ".rig", "runs", input.runId, "dirty-baseline.ready.json")
|
|
691
|
-
};
|
|
692
|
-
}
|
|
693
|
-
function positiveInt(value, fallback) {
|
|
694
|
-
return typeof value === "number" && Number.isFinite(value) && value > 0 ? Math.floor(value) : fallback;
|
|
695
|
-
}
|
|
696
|
-
function resolveTaskRunAutomationLimits(config, env = process.env) {
|
|
697
|
-
const configuredValidationAttempts = positiveInt(config?.automation?.maxValidationAttempts, 30);
|
|
698
|
-
const configuredPrFixIterations = positiveInt(config?.automation?.maxPrFixIterations, 100500);
|
|
699
|
-
return {
|
|
700
|
-
maxValidationAttempts: parsePositiveInt(env.RIG_TASK_RUN_MAX_ATTEMPTS, "RIG_TASK_RUN_MAX_ATTEMPTS", configuredValidationAttempts),
|
|
701
|
-
maxPrFixIterations: configuredPrFixIterations
|
|
702
|
-
};
|
|
703
|
-
}
|
|
704
|
-
function classifyPlanningNeed(input) {
|
|
705
|
-
const planning = input.config?.planning ?? {};
|
|
706
|
-
const mode = planning.mode ?? "auto";
|
|
707
|
-
const labels = new Set((input.sourceTask?.labels ?? []).map((label) => label.trim().toLowerCase()).filter(Boolean));
|
|
708
|
-
const requireLabels = planning.requireForLabels ?? ["needs-plan", "epic", "large", "risk:high"];
|
|
709
|
-
const skipLabels = planning.skipForLabels ?? ["no-plan", "small", "trivial"];
|
|
710
|
-
const bodyLength = `${input.sourceTask?.description ?? ""}
|
|
711
|
-
${input.sourceTask?.body ?? ""}
|
|
712
|
-
${input.sourceTask?.acceptanceCriteria ?? input.sourceTask?.acceptance_criteria ?? ""}`.trim().length;
|
|
713
|
-
const forcedLabel = requireLabels.find((label) => labels.has(label.toLowerCase()));
|
|
714
|
-
const skippedLabel = skipLabels.find((label) => labels.has(label.toLowerCase()));
|
|
715
|
-
const highRisk = labels.has("risk:high") || labels.has("security") || labels.has("migration");
|
|
716
|
-
const size = labels.has("large") || bodyLength > 4000 ? "large" : bodyLength > 1000 ? "medium" : "small";
|
|
717
|
-
const risk = highRisk ? "high" : labels.has("risk:medium") || size !== "small" ? "medium" : "low";
|
|
718
|
-
if (mode === "always") {
|
|
719
|
-
return { planningRequired: true, size, risk, reason: "planning.mode=always", policy: "always" };
|
|
720
|
-
}
|
|
721
|
-
if (mode === "off") {
|
|
722
|
-
return { planningRequired: false, size, risk, reason: "planning.mode=off", policy: "off" };
|
|
723
|
-
}
|
|
724
|
-
if (forcedLabel) {
|
|
725
|
-
return { planningRequired: true, size, risk, reason: `label:${forcedLabel}`, policy: "auto" };
|
|
726
|
-
}
|
|
727
|
-
if (skippedLabel && !highRisk) {
|
|
728
|
-
return { planningRequired: false, size, risk, reason: `label:${skippedLabel}`, policy: "auto" };
|
|
729
|
-
}
|
|
730
|
-
const planningRequired = size !== "small" || risk === "high";
|
|
731
|
-
return {
|
|
732
|
-
planningRequired,
|
|
733
|
-
size,
|
|
734
|
-
risk,
|
|
735
|
-
reason: planningRequired ? `auto:${size}/${risk}` : "auto:small/low",
|
|
736
|
-
policy: "auto"
|
|
737
|
-
};
|
|
738
|
-
}
|
|
739
|
-
function buildPiValidationRetrySteeringPrompt(input) {
|
|
740
|
-
return [
|
|
741
|
-
`Retry attempt ${input.attempt + 1}/${input.maxAttempts} for task ${input.taskId}.`,
|
|
742
|
-
"The previous attempt failed Rig validation. Continue from the existing runtime workspace and PR state instead of starting over.",
|
|
743
|
-
"",
|
|
744
|
-
`Latest blocker: ${input.failureDetail}`,
|
|
745
|
-
...input.validationOutput?.trim() ? ["", "Validation output:", input.validationOutput.trim()] : [],
|
|
746
|
-
"",
|
|
747
|
-
"Fix the concrete failure, rerun the relevant validation, and only report completion when the task is accepted."
|
|
748
|
-
].join(`
|
|
749
|
-
`);
|
|
750
|
-
}
|
|
751
|
-
function classifyValidationRetryOutcome(input) {
|
|
752
|
-
return {
|
|
753
|
-
stage: "Validate failed",
|
|
754
|
-
status: input.attempt >= input.maxAttempts ? "needs_attention" : "retry",
|
|
755
|
-
failureDetail: input.failureDetail
|
|
756
|
-
};
|
|
757
|
-
}
|
|
758
|
-
function configuredIssueUpdatesMode(config) {
|
|
759
|
-
const github = config?.github;
|
|
760
|
-
const mode = github && typeof github === "object" && !Array.isArray(github) ? github.issueUpdates : null;
|
|
761
|
-
return mode === "off" || mode === "minimal" || mode === "lifecycle" ? mode : "lifecycle";
|
|
762
|
-
}
|
|
763
|
-
function shouldWriteDriverIssueUpdate(config, status) {
|
|
764
|
-
const mode = configuredIssueUpdatesMode(config);
|
|
765
|
-
if (mode === "off")
|
|
766
|
-
return false;
|
|
767
|
-
if (mode === "lifecycle")
|
|
768
|
-
return true;
|
|
769
|
-
return ["closed", "failed", "needs_attention"].includes(status);
|
|
770
|
-
}
|
|
771
|
-
async function loadTaskRunAutomationConfig(projectRoot) {
|
|
772
|
-
try {
|
|
773
|
-
return await loadConfig(projectRoot);
|
|
774
|
-
} catch {
|
|
775
|
-
return null;
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
function taskRunStageLogId(runId, stage) {
|
|
779
|
-
return `log:${runId}:stage:${stage.toLowerCase().replace(/[^a-z0-9]+/g, "-")}`;
|
|
780
|
-
}
|
|
781
|
-
function appendPiStageLog(input) {
|
|
782
|
-
appendRunLog(input.projectRoot, input.runId, {
|
|
783
|
-
id: taskRunStageLogId(input.runId, input.stage),
|
|
784
|
-
title: input.stage,
|
|
785
|
-
detail: input.detail ?? null,
|
|
786
|
-
tone: input.tone ?? "info",
|
|
787
|
-
status: input.status ?? "running",
|
|
788
|
-
createdAt: new Date().toISOString()
|
|
789
|
-
});
|
|
790
|
-
emitServerRunEvent({ type: "log", runId: input.runId, title: input.stage });
|
|
791
|
-
}
|
|
792
|
-
async function runCheckedCommand(command, args, cwd, label = "git") {
|
|
793
|
-
const result = await command(args, { cwd });
|
|
794
|
-
if (result.exitCode !== 0) {
|
|
795
|
-
throw new Error(`${label} ${args.join(" ")} failed (${result.exitCode}): ${result.stderr ?? result.stdout ?? ""}`.trim());
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
function createCommandRunner(binary) {
|
|
799
|
-
return async (args, options) => {
|
|
800
|
-
const child = spawn(binary, [...args], {
|
|
801
|
-
cwd: options?.cwd,
|
|
802
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
803
|
-
});
|
|
804
|
-
const stdoutChunks = [];
|
|
805
|
-
const stderrChunks = [];
|
|
806
|
-
child.stdout.on("data", (chunk) => stdoutChunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk))));
|
|
807
|
-
child.stderr.on("data", (chunk) => stderrChunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk))));
|
|
808
|
-
return await new Promise((resolve7) => {
|
|
809
|
-
child.once("error", (error) => resolve7({ exitCode: 1, stderr: error.message }));
|
|
810
|
-
child.once("close", (code) => resolve7({
|
|
811
|
-
exitCode: code ?? 1,
|
|
812
|
-
stdout: Buffer.concat(stdoutChunks).toString("utf8"),
|
|
813
|
-
stderr: Buffer.concat(stderrChunks).toString("utf8")
|
|
814
|
-
}));
|
|
815
|
-
});
|
|
816
|
-
};
|
|
817
|
-
}
|
|
818
|
-
async function resolvePostValidationBranch(input) {
|
|
819
|
-
if (!input.configuredBranch.startsWith("task-")) {
|
|
820
|
-
return input.configuredBranch;
|
|
821
|
-
}
|
|
822
|
-
const current = await input.gitCommand(["rev-parse", "--abbrev-ref", "HEAD"], { cwd: input.workspace });
|
|
823
|
-
const currentBranch = current.stdout?.trim();
|
|
824
|
-
if (current.exitCode === 0 && currentBranch && currentBranch !== "HEAD") {
|
|
825
|
-
return currentBranch;
|
|
826
|
-
}
|
|
827
|
-
return input.configuredBranch;
|
|
828
|
-
}
|
|
829
|
-
async function runTaskRunPostValidationLifecycle(input) {
|
|
830
|
-
const taskId = input.taskId?.trim();
|
|
831
|
-
if (!taskId) {
|
|
832
|
-
return { status: "skipped" };
|
|
833
|
-
}
|
|
834
|
-
const configInput = input.config ?? null;
|
|
835
|
-
const config = configInput ?? {};
|
|
836
|
-
const prMode = configInput ? configInput.pr?.mode ?? "auto" : "off";
|
|
837
|
-
if (prMode === "off" || prMode === "ask") {
|
|
838
|
-
input.appendStage?.("Open PR", prMode === "off" ? "PR automation disabled by pr.mode=off." : "PR creation awaiting operator approval by pr.mode=ask.", "skipped", "info");
|
|
839
|
-
input.appendStage?.("Complete", "Validation completed; no PR was opened and the issue was left open.", "completed", "info");
|
|
840
|
-
return { status: "skipped" };
|
|
841
|
-
}
|
|
842
|
-
const workspace = input.runtimeWorkspace || input.projectRoot;
|
|
843
|
-
const ghCommand = input.ghCommand ?? createCommandRunner("gh");
|
|
844
|
-
const gitCommand = input.gitCommand ?? createCommandRunner("git");
|
|
845
|
-
const configuredBranch = input.branch || `rig/${input.runtimeTaskId}-${input.runId}`;
|
|
846
|
-
const branch = await resolvePostValidationBranch({
|
|
847
|
-
workspace,
|
|
848
|
-
configuredBranch,
|
|
849
|
-
gitCommand
|
|
850
|
-
});
|
|
851
|
-
const prAutomation = input.prAutomation ?? runPrAutomation;
|
|
852
|
-
const updateTaskSource = input.updateTaskSource ?? updateTaskSourceWithProjectSync;
|
|
853
|
-
const stage = input.appendStage ?? (() => {
|
|
854
|
-
return;
|
|
855
|
-
});
|
|
856
|
-
const steerPi = input.steerPi ?? (async (message) => {
|
|
857
|
-
appendRunLog(input.projectRoot, input.runId, {
|
|
858
|
-
id: `log:${input.runId}:pr-steering:${Date.now()}`,
|
|
859
|
-
title: "Steering Pi from PR feedback",
|
|
860
|
-
detail: message,
|
|
861
|
-
tone: "info",
|
|
862
|
-
status: "reviewing",
|
|
863
|
-
createdAt: new Date().toISOString()
|
|
864
|
-
});
|
|
865
|
-
emitServerRunEvent({ type: "log", runId: input.runId, title: "Steering Pi from PR feedback" });
|
|
866
|
-
});
|
|
867
|
-
stage("Commit", `Committing changes in ${workspace}.`, "running", "tool");
|
|
868
|
-
const commit = await commitRunChanges({
|
|
869
|
-
cwd: workspace,
|
|
870
|
-
message: `rig: complete task ${taskId}`,
|
|
871
|
-
command: gitCommand
|
|
872
|
-
});
|
|
873
|
-
stage("Commit", commit.committed ? "Committed run workspace changes." : "No workspace changes to commit.", "completed", "tool");
|
|
874
|
-
await runCheckedCommand(gitCommand, ["push", "--set-upstream", "origin", branch], workspace, "git");
|
|
875
|
-
stage("Open PR", `Opening PR from ${branch}.`, "running", "tool");
|
|
876
|
-
const pr = await prAutomation({
|
|
877
|
-
projectRoot: workspace,
|
|
878
|
-
taskId,
|
|
879
|
-
runId: input.runId,
|
|
880
|
-
branch,
|
|
881
|
-
config,
|
|
882
|
-
sourceTask: input.sourceTask,
|
|
883
|
-
uploadedSnapshot: input.uploadedSnapshot,
|
|
884
|
-
artifactRoot: resolve6(input.projectRoot, "artifacts", taskId),
|
|
885
|
-
command: ghCommand,
|
|
886
|
-
gitCommand,
|
|
887
|
-
steerPi,
|
|
888
|
-
lifecycle: {
|
|
889
|
-
onPrOpened: async ({ prUrl }) => {
|
|
890
|
-
stage("Open PR", prUrl, "completed", "tool");
|
|
891
|
-
try {
|
|
892
|
-
if (shouldWriteDriverIssueUpdate(config, "under_review")) {
|
|
893
|
-
await updateTaskSource(input.projectRoot, {
|
|
894
|
-
taskId,
|
|
895
|
-
sourceTask: runSourceTaskIdentity(input.sourceTask),
|
|
896
|
-
update: {
|
|
897
|
-
status: "under_review",
|
|
898
|
-
comment: buildTaskRunLifecycleComment({
|
|
899
|
-
runId: input.runId,
|
|
900
|
-
status: "under_review",
|
|
901
|
-
summary: "Rig opened a pull request for this task.",
|
|
902
|
-
runtimeWorkspace: input.runtimeWorkspace ?? null
|
|
903
|
-
})
|
|
904
|
-
}
|
|
905
|
-
});
|
|
906
|
-
}
|
|
907
|
-
} catch (error) {
|
|
908
|
-
appendRunLog(input.projectRoot, input.runId, {
|
|
909
|
-
id: `log:${input.runId}:task-source-under-review-update`,
|
|
910
|
-
title: "Task source PR status update failed",
|
|
911
|
-
detail: error instanceof Error ? error.message : String(error),
|
|
912
|
-
tone: "error",
|
|
913
|
-
status: "reviewing",
|
|
914
|
-
createdAt: new Date().toISOString()
|
|
915
|
-
});
|
|
916
|
-
}
|
|
917
|
-
},
|
|
918
|
-
onReviewCiStarted: ({ prUrl, iteration }) => stage("Review/CI", `${prUrl} (iteration ${iteration})`, "running", "info"),
|
|
919
|
-
onFeedback: async ({ feedback }) => {
|
|
920
|
-
stage("Review/CI", feedback.join(`
|
|
921
|
-
`), "reviewing", "error");
|
|
922
|
-
if (shouldWriteDriverIssueUpdate(config, "ci_fixing")) {
|
|
923
|
-
await updateTaskSource(input.projectRoot, {
|
|
924
|
-
taskId,
|
|
925
|
-
sourceTask: runSourceTaskIdentity(input.sourceTask),
|
|
926
|
-
update: {
|
|
927
|
-
status: "ci_fixing",
|
|
928
|
-
comment: buildTaskRunLifecycleComment({
|
|
929
|
-
runId: input.runId,
|
|
930
|
-
status: "ci_fixing",
|
|
931
|
-
summary: "Rig is fixing CI/review feedback for this task.",
|
|
932
|
-
runtimeWorkspace: input.runtimeWorkspace ?? null
|
|
933
|
-
})
|
|
934
|
-
}
|
|
935
|
-
});
|
|
936
|
-
}
|
|
937
|
-
},
|
|
938
|
-
onMergeStarted: async ({ prUrl }) => {
|
|
939
|
-
stage("Merge", prUrl, "running", "tool");
|
|
940
|
-
if (shouldWriteDriverIssueUpdate(config, "merging")) {
|
|
941
|
-
await updateTaskSource(input.projectRoot, {
|
|
942
|
-
taskId,
|
|
943
|
-
sourceTask: runSourceTaskIdentity(input.sourceTask),
|
|
944
|
-
update: {
|
|
945
|
-
status: "merging",
|
|
946
|
-
comment: buildTaskRunLifecycleComment({
|
|
947
|
-
runId: input.runId,
|
|
948
|
-
status: "merging",
|
|
949
|
-
summary: "Rig is merging the pull request for this task.",
|
|
950
|
-
runtimeWorkspace: input.runtimeWorkspace ?? null
|
|
951
|
-
})
|
|
952
|
-
}
|
|
953
|
-
});
|
|
954
|
-
}
|
|
955
|
-
},
|
|
956
|
-
onMerged: ({ prUrl }) => stage("Merge", prUrl, "completed", "tool")
|
|
957
|
-
}
|
|
958
|
-
});
|
|
959
|
-
if (pr.status === "opened" && pr.prUrl) {
|
|
960
|
-
stage("Complete", `PR ready without merge: ${pr.prUrl}`, "completed", "info");
|
|
961
|
-
return { status: "completed", pr };
|
|
962
|
-
}
|
|
963
|
-
if (pr.status !== "merged" || !pr.prUrl) {
|
|
964
|
-
const detail = pr.actionableFeedback.join(`
|
|
965
|
-
`) || "PR automation did not merge the PR.";
|
|
966
|
-
stage("Needs attention", detail, "needs_attention", "error");
|
|
967
|
-
if (shouldWriteDriverIssueUpdate(config, "needs_attention")) {
|
|
968
|
-
await updateTaskSource(input.projectRoot, {
|
|
969
|
-
taskId,
|
|
970
|
-
sourceTask: runSourceTaskIdentity(input.sourceTask),
|
|
971
|
-
update: {
|
|
972
|
-
status: "needs_attention",
|
|
973
|
-
comment: buildTaskRunLifecycleComment({
|
|
974
|
-
runId: input.runId,
|
|
975
|
-
status: "needs_attention",
|
|
976
|
-
summary: "Rig needs operator attention before this task can proceed.",
|
|
977
|
-
runtimeWorkspace: input.runtimeWorkspace ?? null,
|
|
978
|
-
errorText: detail
|
|
979
|
-
})
|
|
980
|
-
}
|
|
981
|
-
}).catch((error) => {
|
|
982
|
-
try {
|
|
983
|
-
appendRunLog(input.projectRoot, input.runId, {
|
|
984
|
-
id: `log:${input.runId}:task-source-needs-attention-update`,
|
|
985
|
-
title: "Task source needs-attention update failed",
|
|
986
|
-
detail: error instanceof Error ? error.message : String(error),
|
|
987
|
-
tone: "error",
|
|
988
|
-
status: "needs_attention",
|
|
989
|
-
createdAt: new Date().toISOString()
|
|
990
|
-
});
|
|
991
|
-
} catch {}
|
|
992
|
-
});
|
|
993
|
-
}
|
|
994
|
-
return { status: "needs_attention", pr };
|
|
995
|
-
}
|
|
996
|
-
if (shouldWriteDriverIssueUpdate(config, "closed")) {
|
|
997
|
-
await closeIssueAfterMergedPr({
|
|
998
|
-
projectRoot: input.projectRoot,
|
|
999
|
-
taskId,
|
|
1000
|
-
runId: input.runId,
|
|
1001
|
-
prUrl: pr.prUrl,
|
|
1002
|
-
sourceTask: input.sourceTask,
|
|
1003
|
-
updateTaskSource: async (projectRoot, closeInput) => updateTaskSource(projectRoot, closeInput)
|
|
1004
|
-
});
|
|
1005
|
-
}
|
|
1006
|
-
stage("Complete", `PR merged and issue closed: ${pr.prUrl}`, "completed", "info");
|
|
1007
|
-
return { status: "completed", pr };
|
|
1008
|
-
}
|
|
1009
|
-
function summarizeValidationFailure(projectRoot, taskId) {
|
|
1010
|
-
if (!taskId) {
|
|
1011
|
-
return null;
|
|
1012
|
-
}
|
|
1013
|
-
for (const artifactDir of resolveTaskArtifactDirs(projectRoot, taskId)) {
|
|
1014
|
-
const summary = readJsonFile2(resolve6(artifactDir, "validation-summary.json"), null);
|
|
1015
|
-
if (!summary || summary.status !== "fail") {
|
|
1016
|
-
continue;
|
|
1017
|
-
}
|
|
1018
|
-
const failedCategories = Array.isArray(summary.categories) ? summary.categories.filter((entry) => String(entry?.status ?? "") !== "pass").map((entry) => String(entry?.category ?? "").trim()).filter(Boolean) : [];
|
|
1019
|
-
if (failedCategories.length > 0) {
|
|
1020
|
-
return `Task validation failed: ${failedCategories.join(", ")}`;
|
|
1021
|
-
}
|
|
1022
|
-
return "Task validation failed.";
|
|
1023
|
-
}
|
|
1024
|
-
return null;
|
|
1025
|
-
}
|
|
1026
|
-
function classifyCompletionVerificationLine(line) {
|
|
1027
|
-
const trimmed = line.trim();
|
|
1028
|
-
if (/^=== Completion Verification: /.test(trimmed)) {
|
|
1029
|
-
return { isCompletionLine: true, isVerifierReview: false };
|
|
1030
|
-
}
|
|
1031
|
-
if (/^\[\d+\/\d+\]/.test(trimmed)) {
|
|
1032
|
-
return {
|
|
1033
|
-
isCompletionLine: true,
|
|
1034
|
-
isVerifierReview: /Verifier review/i.test(trimmed)
|
|
1035
|
-
};
|
|
1036
|
-
}
|
|
1037
|
-
return { isCompletionLine: false, isVerifierReview: false };
|
|
1038
|
-
}
|
|
1039
|
-
function createRunLogIdFactory(runId) {
|
|
1040
|
-
let sequence = 0;
|
|
1041
|
-
return () => {
|
|
1042
|
-
sequence += 1;
|
|
1043
|
-
return `log:${runId}:${Date.now()}:${sequence}`;
|
|
1044
|
-
};
|
|
1045
|
-
}
|
|
1046
|
-
function summarizeTaskRunProcessFailure(input) {
|
|
1047
|
-
const fallback = `Task run failed (${String(input.exitCode ?? "unknown")}${input.signal ? ` ${input.signal}` : ""})`;
|
|
1048
|
-
const stderrLines = input.stderrLines ?? [];
|
|
1049
|
-
const meaningfulLines = [...stderrLines].map((line) => line.trim()).filter(Boolean).filter((line) => !/^Task run failed \([^)]*\)$/i.test(line));
|
|
1050
|
-
const taskSourceFailure = meaningfulLines.find((line) => /failed to update task source/i.test(line));
|
|
1051
|
-
if (taskSourceFailure) {
|
|
1052
|
-
return `Task source update failed: ${taskSourceFailure}`;
|
|
1053
|
-
}
|
|
1054
|
-
const moduleFailure = meaningfulLines.find((line) => /cannot find module/i.test(line));
|
|
1055
|
-
if (moduleFailure) {
|
|
1056
|
-
return `Runtime module resolution failed: ${moduleFailure}`;
|
|
1057
|
-
}
|
|
1058
|
-
for (const line of [...meaningfulLines].reverse()) {
|
|
1059
|
-
const trimmed = line.trim();
|
|
1060
|
-
if (/server-managed task run cannot finish successfully/i.test(trimmed)) {
|
|
1061
|
-
return `Task source remained open: ${trimmed}`;
|
|
1062
|
-
}
|
|
1063
|
-
if (/no api key found/i.test(trimmed)) {
|
|
1064
|
-
return `Missing provider credentials: ${trimmed}`;
|
|
1065
|
-
}
|
|
1066
|
-
if (/no claude credentials found/i.test(trimmed)) {
|
|
1067
|
-
return `Missing provider credentials: ${trimmed}`;
|
|
1068
|
-
}
|
|
1069
|
-
if (/unauthorized|authentication failed|invalid api key|api key is invalid/i.test(trimmed)) {
|
|
1070
|
-
return `Provider authentication failed: ${trimmed}`;
|
|
1071
|
-
}
|
|
1072
|
-
if (/command not found|no such file or directory|enoent/i.test(trimmed)) {
|
|
1073
|
-
return `Missing runtime executable: ${trimmed}`;
|
|
1074
|
-
}
|
|
1075
|
-
if (/bubblewrap|\bbwrap\b|sandbox-exec|sandbox/i.test(trimmed) && /missing|not found|failed|denied/i.test(trimmed)) {
|
|
1076
|
-
return `Sandbox backend unavailable: ${trimmed}`;
|
|
1077
|
-
}
|
|
1078
|
-
}
|
|
1079
|
-
return fallback;
|
|
1080
|
-
}
|
|
1081
|
-
function parsePositiveInt(value, option, fallback) {
|
|
1082
|
-
if (!value) {
|
|
1083
|
-
return fallback;
|
|
1084
|
-
}
|
|
1085
|
-
const parsed = Number.parseInt(value, 10);
|
|
1086
|
-
if (!Number.isFinite(parsed) || parsed <= 0) {
|
|
1087
|
-
throw new CliError2(`Invalid ${option} value: ${value}`);
|
|
1088
|
-
}
|
|
1089
|
-
return parsed;
|
|
1090
|
-
}
|
|
1091
|
-
function readTaskRunAcceptedArtifactState(input) {
|
|
1092
|
-
if (!input.taskId || !input.workspaceDir) {
|
|
1093
|
-
return { accepted: false, reason: null };
|
|
1094
|
-
}
|
|
1095
|
-
const artifactDir = resolve6(input.workspaceDir, "artifacts", input.taskId);
|
|
1096
|
-
const reviewStatusPath = resolve6(artifactDir, "review-status.txt");
|
|
1097
|
-
const taskResultPath = resolve6(artifactDir, "task-result.json");
|
|
1098
|
-
const reviewStatus = readTaskRunReviewStatus(reviewStatusPath);
|
|
1099
|
-
if (reviewStatus !== "APPROVED") {
|
|
1100
|
-
return { accepted: false, reason: null };
|
|
1101
|
-
}
|
|
1102
|
-
const taskResult = readJsonFile2(taskResultPath, null);
|
|
1103
|
-
if (taskResult?.status !== "completed") {
|
|
1104
|
-
return { accepted: false, reason: null };
|
|
1105
|
-
}
|
|
1106
|
-
if (typeof input.artifactNotBeforeMs === "number" && Number.isFinite(input.artifactNotBeforeMs)) {
|
|
1107
|
-
try {
|
|
1108
|
-
const reviewStatusMtime = statSync(reviewStatusPath).mtimeMs;
|
|
1109
|
-
if (reviewStatusMtime + 1000 < input.artifactNotBeforeMs) {
|
|
1110
|
-
return { accepted: false, reason: null };
|
|
1111
|
-
}
|
|
1112
|
-
} catch {
|
|
1113
|
-
return { accepted: false, reason: null };
|
|
1114
|
-
}
|
|
1115
|
-
}
|
|
1116
|
-
return {
|
|
1117
|
-
accepted: true,
|
|
1118
|
-
reason: `task-result.json is completed and review-status.txt is APPROVED for task ${input.taskId}`
|
|
1119
|
-
};
|
|
1120
|
-
}
|
|
1121
|
-
function resolvePiAcceptedArtifactExitGraceMs(env = process.env) {
|
|
1122
|
-
const raw = env.RIG_PI_ACCEPTED_ARTIFACT_EXIT_GRACE_MS;
|
|
1123
|
-
if (raw === undefined || raw.trim() === "")
|
|
1124
|
-
return 30000;
|
|
1125
|
-
const parsed = Number.parseInt(raw, 10);
|
|
1126
|
-
if (!Number.isFinite(parsed) || parsed < 0)
|
|
1127
|
-
return 30000;
|
|
1128
|
-
return parsed;
|
|
1129
|
-
}
|
|
1130
|
-
function resolveTaskRunRetryContext(input) {
|
|
1131
|
-
if (!input.taskId || !input.workspaceDir) {
|
|
1132
|
-
return { shouldRetry: false, failureDetail: null, nextPrompt: null };
|
|
1133
|
-
}
|
|
1134
|
-
const artifactDir = resolve6(input.workspaceDir, "artifacts", input.taskId);
|
|
1135
|
-
const reviewStatePath = resolve6(artifactDir, "review-state.json");
|
|
1136
|
-
const reviewFeedbackPath = resolve6(artifactDir, "review-feedback.md");
|
|
1137
|
-
const reviewStatusPath = resolve6(artifactDir, "review-status.txt");
|
|
1138
|
-
const failedApproachesPath = resolve6(input.workspaceDir, ".rig", "state", "failed_approaches.md");
|
|
1139
|
-
const validationSummaryPath = resolve6(artifactDir, "validation-summary.json");
|
|
1140
|
-
const reviewState = readJsonFile2(reviewStatePath, null);
|
|
1141
|
-
const reviewStatus = readTaskRunReviewStatus(reviewStatusPath);
|
|
1142
|
-
const reviewRejected = isTaskRunReviewRejected(reviewState);
|
|
1143
|
-
if (reviewStatus === "APPROVED") {
|
|
1144
|
-
return { shouldRetry: false, failureDetail: null, nextPrompt: null };
|
|
1145
|
-
}
|
|
1146
|
-
if (reviewStatus !== "REJECTED" && !reviewRejected) {
|
|
1147
|
-
return { shouldRetry: false, failureDetail: null, nextPrompt: null };
|
|
1148
|
-
}
|
|
1149
|
-
const failureDetail = summarizeTaskRunReviewFailure(reviewState);
|
|
1150
|
-
if (input.attempt >= input.maxAttempts) {
|
|
1151
|
-
return { shouldRetry: false, failureDetail, nextPrompt: null };
|
|
1152
|
-
}
|
|
1153
|
-
return {
|
|
1154
|
-
shouldRetry: true,
|
|
1155
|
-
failureDetail,
|
|
1156
|
-
nextPrompt: [
|
|
1157
|
-
input.basePrompt,
|
|
1158
|
-
"",
|
|
1159
|
-
`Retry attempt ${input.attempt + 1}/${input.maxAttempts} for task ${input.taskId}.`,
|
|
1160
|
-
"The previous attempt did not satisfy completion verification. Continue from the existing runtime workspace and PR state instead of starting over.",
|
|
1161
|
-
"",
|
|
1162
|
-
`Latest blocker: ${failureDetail}`,
|
|
1163
|
-
"",
|
|
1164
|
-
"Inspect these artifacts first:",
|
|
1165
|
-
`- ${reviewStatusPath}`,
|
|
1166
|
-
`- ${reviewStatePath}`,
|
|
1167
|
-
`- ${reviewFeedbackPath}`,
|
|
1168
|
-
`- ${failedApproachesPath}`,
|
|
1169
|
-
`- ${validationSummaryPath}`,
|
|
1170
|
-
"",
|
|
1171
|
-
"Resolve the concrete issues recorded there, refresh the task artifacts if needed, rerun validation and completion verification, and do not stop until the task is actually accepted. When Greptile review is required, keep iterating until the review verdict is APPROVE with no unresolved comments."
|
|
1172
|
-
].join(`
|
|
1173
|
-
`)
|
|
1174
|
-
};
|
|
1175
|
-
}
|
|
1176
|
-
function summarizeTaskRunReviewFailure(reviewState) {
|
|
1177
|
-
if (!reviewState) {
|
|
1178
|
-
return "Completion verification rejected the task. Read review-feedback.md for required fixes.";
|
|
1179
|
-
}
|
|
1180
|
-
const reasons = [
|
|
1181
|
-
...reviewState.local_reasons ?? [],
|
|
1182
|
-
...reviewState.ai_reasons ?? [],
|
|
1183
|
-
...reviewState.ai_warnings ?? []
|
|
1184
|
-
].map((value) => value.trim()).filter(Boolean);
|
|
1185
|
-
if (reasons.length > 0) {
|
|
1186
|
-
return reasons[0];
|
|
1187
|
-
}
|
|
1188
|
-
if (reviewState.mode === "required" && reviewState.verdict && reviewState.verdict !== "APPROVE") {
|
|
1189
|
-
return `[AI Review] Required mode needs a completed Greptile approval; current verdict is ${reviewState.verdict}.`;
|
|
1190
|
-
}
|
|
1191
|
-
return "Completion verification rejected the task. Read review-feedback.md for required fixes.";
|
|
1192
|
-
}
|
|
1193
|
-
function appendAssistantTimelineFromRecord(input) {
|
|
1194
|
-
let nextAssistantText = input.assistantText;
|
|
1195
|
-
if (input.record.type === "message_update") {
|
|
1196
|
-
const assistantMessageEvent = input.record.assistantMessageEvent && typeof input.record.assistantMessageEvent === "object" ? input.record.assistantMessageEvent : null;
|
|
1197
|
-
if (assistantMessageEvent?.type === "text_delta" && typeof assistantMessageEvent.delta === "string") {
|
|
1198
|
-
nextAssistantText += assistantMessageEvent.delta;
|
|
1199
|
-
}
|
|
1200
|
-
} else if (input.record.type === "stream_event") {
|
|
1201
|
-
const event = input.record.event && typeof input.record.event === "object" ? input.record.event : null;
|
|
1202
|
-
const delta = event?.delta && typeof event.delta === "object" ? event.delta : null;
|
|
1203
|
-
if (delta?.type === "text_delta" && typeof delta.text === "string") {
|
|
1204
|
-
nextAssistantText += delta.text;
|
|
1205
|
-
}
|
|
1206
|
-
} else if (input.record.type === "assistant") {
|
|
1207
|
-
const message = input.record.message && typeof input.record.message === "object" ? input.record.message : input.record;
|
|
1208
|
-
const content = Array.isArray(message.content) ? message.content : [];
|
|
1209
|
-
const fullText = content.map((entry) => entry && typeof entry === "object" && entry.type === "text" ? String(entry.text ?? "") : "").join("");
|
|
1210
|
-
if (fullText.length > nextAssistantText.length)
|
|
1211
|
-
nextAssistantText = fullText;
|
|
1212
|
-
}
|
|
1213
|
-
if (nextAssistantText !== input.assistantText) {
|
|
1214
|
-
appendRunTimeline(input.projectRoot, input.runId, {
|
|
1215
|
-
id: input.messageId,
|
|
1216
|
-
type: "assistant_message",
|
|
1217
|
-
text: nextAssistantText,
|
|
1218
|
-
state: "streaming",
|
|
1219
|
-
createdAt: new Date().toISOString()
|
|
1220
|
-
});
|
|
1221
|
-
}
|
|
1222
|
-
return nextAssistantText;
|
|
1223
|
-
}
|
|
1224
|
-
function appendPiRpcProtocolLogFromRecord(input) {
|
|
1225
|
-
const type = typeof input.record.type === "string" ? input.record.type : "";
|
|
1226
|
-
if (type === "response") {
|
|
1227
|
-
const command = typeof input.record.command === "string" ? input.record.command : "rpc";
|
|
1228
|
-
const success = input.record.success !== false;
|
|
1229
|
-
if (success && command !== "prompt" && command !== "steer" && command !== "follow_up" && command !== "set_session_name") {
|
|
1230
|
-
return true;
|
|
1231
|
-
}
|
|
1232
|
-
appendRunLog(input.projectRoot, input.runId, {
|
|
1233
|
-
id: input.nextRunLogId(),
|
|
1234
|
-
title: success ? "Pi RPC response" : "Pi RPC error",
|
|
1235
|
-
detail: success ? `${command}: accepted` : `${command}: ${String(input.record.error ?? "failed")}`,
|
|
1236
|
-
tone: success ? "tool" : "error",
|
|
1237
|
-
status: input.status,
|
|
1238
|
-
payload: input.record,
|
|
1239
|
-
createdAt: new Date().toISOString()
|
|
1240
|
-
});
|
|
1241
|
-
emitServerRunEvent({ type: "log", runId: input.runId, title: success ? "Pi RPC response" : "Pi RPC error" });
|
|
1242
|
-
return true;
|
|
1243
|
-
}
|
|
1244
|
-
if (type !== "extension_ui_request")
|
|
1245
|
-
return false;
|
|
1246
|
-
const method = typeof input.record.method === "string" ? input.record.method : "ui";
|
|
1247
|
-
let title = "Pi UI event";
|
|
1248
|
-
let detail = method;
|
|
1249
|
-
let tone = "info";
|
|
1250
|
-
if (method === "notify") {
|
|
1251
|
-
title = "Pi notification";
|
|
1252
|
-
detail = String(input.record.message ?? "");
|
|
1253
|
-
tone = input.record.notifyType === "error" ? "error" : "info";
|
|
1254
|
-
} else if (method === "setStatus") {
|
|
1255
|
-
title = "Pi UI status";
|
|
1256
|
-
detail = `${String(input.record.statusKey ?? "status")}: ${String(input.record.statusText ?? "cleared")}`;
|
|
1257
|
-
tone = "tool";
|
|
1258
|
-
} else if (method === "setWidget") {
|
|
1259
|
-
title = "Pi UI widget";
|
|
1260
|
-
const lines = Array.isArray(input.record.widgetLines) ? input.record.widgetLines.map((line) => String(line)).join(" | ") : "cleared";
|
|
1261
|
-
detail = `${String(input.record.widgetKey ?? "widget")}: ${lines}`.slice(0, 500);
|
|
1262
|
-
tone = "tool";
|
|
1263
|
-
} else if (method === "setTitle") {
|
|
1264
|
-
title = "Pi UI title";
|
|
1265
|
-
detail = String(input.record.title ?? "");
|
|
1266
|
-
tone = "tool";
|
|
1267
|
-
} else if (method === "set_editor_text") {
|
|
1268
|
-
title = "Pi editor update";
|
|
1269
|
-
detail = String(input.record.text ?? "").slice(0, 500);
|
|
1270
|
-
tone = "tool";
|
|
1271
|
-
} else {
|
|
1272
|
-
title = "Pi UI request";
|
|
1273
|
-
detail = `${method}: ${String(input.record.title ?? input.record.message ?? "")}`.trim();
|
|
1274
|
-
}
|
|
1275
|
-
appendRunLog(input.projectRoot, input.runId, {
|
|
1276
|
-
id: input.nextRunLogId(),
|
|
1277
|
-
title,
|
|
1278
|
-
detail,
|
|
1279
|
-
tone,
|
|
1280
|
-
status: input.status,
|
|
1281
|
-
payload: input.record,
|
|
1282
|
-
createdAt: new Date().toISOString()
|
|
1283
|
-
});
|
|
1284
|
-
emitServerRunEvent({ type: "log", runId: input.runId, title });
|
|
1285
|
-
return true;
|
|
1286
|
-
}
|
|
1287
|
-
function appendPiToolTimelineFromRecord(input) {
|
|
1288
|
-
const type = typeof input.record.type === "string" ? input.record.type : "";
|
|
1289
|
-
if (type !== "tool_execution_start" && type !== "tool_execution_update" && type !== "tool_execution_end")
|
|
1290
|
-
return false;
|
|
1291
|
-
const toolCallId = typeof input.record.toolCallId === "string" && input.record.toolCallId.trim() ? input.record.toolCallId.trim() : `${Date.now()}`;
|
|
1292
|
-
const toolName = typeof input.record.toolName === "string" && input.record.toolName.trim() ? input.record.toolName.trim() : "tool";
|
|
1293
|
-
const result = input.record.result && typeof input.record.result === "object" && !Array.isArray(input.record.result) ? input.record.result : null;
|
|
1294
|
-
appendRunTimeline(input.projectRoot, input.runId, {
|
|
1295
|
-
id: `tool:${toolCallId}:${type}`,
|
|
1296
|
-
type,
|
|
1297
|
-
toolName,
|
|
1298
|
-
status: type === "tool_execution_end" ? input.record.isError === true || result?.isError === true ? "failed" : "completed" : "running",
|
|
1299
|
-
createdAt: new Date().toISOString()
|
|
1300
|
-
});
|
|
1301
|
-
return true;
|
|
1302
|
-
}
|
|
1303
|
-
function isNonRenderablePiProtocolRecord(record) {
|
|
1304
|
-
const type = typeof record.type === "string" ? record.type : "";
|
|
1305
|
-
return type === "agent_start" || type === "agent_end" || type === "message_start" || type === "message_end" || type === "turn_start" || type === "turn_end" || type === "tool_result" || type === "message_update" && (!record.assistantMessageEvent || typeof record.assistantMessageEvent !== "object" || Array.isArray(record.assistantMessageEvent) || record.assistantMessageEvent.type !== "text_delta");
|
|
1306
|
-
}
|
|
1307
|
-
function appendToolTimelineFromLog(input) {
|
|
1308
|
-
const title = typeof input.log.title === "string" ? input.log.title : "";
|
|
1309
|
-
if (title !== "Tool activity")
|
|
1310
|
-
return;
|
|
1311
|
-
const payload = input.log.payload && typeof input.log.payload === "object" && !Array.isArray(input.log.payload) ? input.log.payload : {};
|
|
1312
|
-
const toolName = typeof payload.toolName === "string" && payload.toolName.trim() ? payload.toolName.trim() : typeof payload.tool_name === "string" && payload.tool_name.trim() ? payload.tool_name.trim() : null;
|
|
1313
|
-
const logId = typeof input.log.id === "string" && input.log.id.trim() ? input.log.id.trim() : `${Date.now()}`;
|
|
1314
|
-
appendRunTimeline(input.projectRoot, input.runId, {
|
|
1315
|
-
id: `tool:${logId}`,
|
|
1316
|
-
type: "tool_execution_update",
|
|
1317
|
-
toolName,
|
|
1318
|
-
status: typeof input.log.status === "string" ? input.log.status : "running",
|
|
1319
|
-
detail: typeof input.log.detail === "string" ? input.log.detail : null,
|
|
1320
|
-
payload,
|
|
1321
|
-
createdAt: typeof input.log.createdAt === "string" ? input.log.createdAt : new Date().toISOString()
|
|
1322
|
-
});
|
|
1323
|
-
}
|
|
1324
|
-
function readTaskRunReviewStatus(reviewStatusPath) {
|
|
1325
|
-
if (!existsSync4(reviewStatusPath)) {
|
|
1326
|
-
return null;
|
|
1327
|
-
}
|
|
1328
|
-
try {
|
|
1329
|
-
const status = readFileSync4(reviewStatusPath, "utf8").trim().toUpperCase();
|
|
1330
|
-
return status === "APPROVED" || status === "REJECTED" ? status : null;
|
|
1331
|
-
} catch {
|
|
1332
|
-
return null;
|
|
1333
|
-
}
|
|
1334
|
-
}
|
|
1335
|
-
function isTaskRunReviewRejected(reviewState) {
|
|
1336
|
-
if (!reviewState) {
|
|
1337
|
-
return false;
|
|
1338
|
-
}
|
|
1339
|
-
if (reviewState.approved === false) {
|
|
1340
|
-
return true;
|
|
1341
|
-
}
|
|
1342
|
-
return reviewState.mode === "required" && !!reviewState.verdict && reviewState.verdict !== "APPROVE";
|
|
1343
|
-
}
|
|
1344
|
-
function runSourceTaskIdentity(sourceTask) {
|
|
1345
|
-
return sourceTask;
|
|
1346
|
-
}
|
|
1347
|
-
function sourceTaskIssueNodeId(sourceTask) {
|
|
1348
|
-
if (!sourceTask || typeof sourceTask !== "object" || Array.isArray(sourceTask))
|
|
1349
|
-
return null;
|
|
1350
|
-
const record = sourceTask;
|
|
1351
|
-
const direct = typeof record.issueNodeId === "string" ? record.issueNodeId : typeof record.nodeId === "string" ? record.nodeId : typeof record.node_id === "string" ? record.node_id : null;
|
|
1352
|
-
if (direct?.trim())
|
|
1353
|
-
return direct.trim();
|
|
1354
|
-
const raw = record.raw && typeof record.raw === "object" && !Array.isArray(record.raw) ? record.raw : null;
|
|
1355
|
-
return typeof raw?.id === "string" && raw.id.trim() ? raw.id.trim() : null;
|
|
1356
|
-
}
|
|
1357
|
-
var updateTaskSourceWithProjectSync = async (projectRoot, input) => {
|
|
1358
|
-
const serverResult = await updateWorkspaceTaskViaServer({ projectRoot }, {
|
|
1359
|
-
id: input.taskId,
|
|
1360
|
-
...input.update.status ? { status: input.update.status } : {},
|
|
1361
|
-
...input.update.comment ? { comment: input.update.comment } : {},
|
|
1362
|
-
...input.update.title ? { title: input.update.title } : {},
|
|
1363
|
-
...typeof input.update.body === "string" ? { body: input.update.body } : {},
|
|
1364
|
-
issueNodeId: sourceTaskIssueNodeId(input.sourceTask)
|
|
1365
|
-
});
|
|
1366
|
-
if (serverResult.ok === false) {
|
|
1367
|
-
throw new Error(typeof serverResult.error === "string" ? serverResult.error : "Rig server task update failed.");
|
|
1368
|
-
}
|
|
1369
|
-
return {
|
|
1370
|
-
updated: serverResult.ok !== false,
|
|
1371
|
-
taskId: input.taskId,
|
|
1372
|
-
status: input.update.status,
|
|
1373
|
-
source: "server",
|
|
1374
|
-
sourceKind: "server",
|
|
1375
|
-
projectSync: serverResult.projectSync
|
|
1376
|
-
};
|
|
1377
|
-
};
|
|
1378
|
-
async function updateTaskSourceAfterDriverRun(projectRoot, runId, taskId, sourceTask, status, summary, input, updateTaskSource = updateTaskSourceWithProjectSync) {
|
|
1379
|
-
if (!taskId)
|
|
1380
|
-
return;
|
|
1381
|
-
const config = await loadTaskRunAutomationConfig(projectRoot);
|
|
1382
|
-
if (!shouldWriteDriverIssueUpdate(config, status))
|
|
1383
|
-
return;
|
|
1384
|
-
const result = await updateTaskSource(projectRoot, {
|
|
1385
|
-
taskId,
|
|
1386
|
-
sourceTask: runSourceTaskIdentity(sourceTask),
|
|
1387
|
-
update: {
|
|
1388
|
-
status,
|
|
1389
|
-
comment: buildTaskRunLifecycleComment({
|
|
1390
|
-
runId,
|
|
1391
|
-
status,
|
|
1392
|
-
summary,
|
|
1393
|
-
runtimeWorkspace: input.latestRuntimeWorkspace,
|
|
1394
|
-
logsDir: input.latestLogsDir,
|
|
1395
|
-
sessionDir: input.latestSessionDir,
|
|
1396
|
-
errorText: input.errorText
|
|
1397
|
-
})
|
|
1398
|
-
}
|
|
1399
|
-
});
|
|
1400
|
-
if (!result.updated && (result.source === "plugin" || result.sourceKind)) {
|
|
1401
|
-
throw new Error(`Configured task source${result.sourceKind ? ` (${result.sourceKind})` : ""} did not accept lifecycle update for ${result.taskId}.`);
|
|
1402
|
-
}
|
|
1403
|
-
}
|
|
1404
|
-
function readRunSourceTaskContract(projectRoot, runId, taskId) {
|
|
1405
|
-
const run = readAuthorityRun3(projectRoot, runId);
|
|
1406
|
-
const raw = run?.sourceTask;
|
|
1407
|
-
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
1408
|
-
return null;
|
|
1409
|
-
}
|
|
1410
|
-
const record = raw;
|
|
1411
|
-
const id = typeof record.id === "string" && record.id.trim() ? record.id.trim() : taskId?.trim();
|
|
1412
|
-
if (!id) {
|
|
1413
|
-
return null;
|
|
1414
|
-
}
|
|
1415
|
-
return {
|
|
1416
|
-
id,
|
|
1417
|
-
...optionalStringField(record, "title"),
|
|
1418
|
-
...optionalStringField(record, "description"),
|
|
1419
|
-
...optionalStringField(record, "body"),
|
|
1420
|
-
...optionalStringField(record, "acceptanceCriteria"),
|
|
1421
|
-
...optionalStringField(record, "acceptance_criteria"),
|
|
1422
|
-
...optionalStringField(record, "sourceIssueId"),
|
|
1423
|
-
...optionalStringField(record, "status"),
|
|
1424
|
-
...optionalStringField(record, "issueType"),
|
|
1425
|
-
...optionalStringField(record, "role"),
|
|
1426
|
-
...optionalStringField(record, "externalRef"),
|
|
1427
|
-
scope: stringArrayField(record, "scope"),
|
|
1428
|
-
validation: stringArrayField(record, "validation"),
|
|
1429
|
-
validators: stringArrayField(record, "validators"),
|
|
1430
|
-
labels: stringArrayField(record, "labels")
|
|
1431
|
-
};
|
|
1432
|
-
}
|
|
1433
|
-
function optionalStringField(record, key) {
|
|
1434
|
-
const value = record[String(key)];
|
|
1435
|
-
return typeof value === "string" ? { [key]: value } : {};
|
|
1436
|
-
}
|
|
1437
|
-
function stringArrayField(record, key) {
|
|
1438
|
-
const value = record[key];
|
|
1439
|
-
return Array.isArray(value) ? value.filter((entry) => typeof entry === "string") : [];
|
|
1440
|
-
}
|
|
1441
|
-
async function executeRigOwnedTaskRun(context, input) {
|
|
1442
|
-
const runtimeTaskId = input.taskId?.trim() || `adhoc-${input.runId}`;
|
|
1443
|
-
const existingRunRecord = readAuthorityRun3(context.projectRoot, input.runId);
|
|
1444
|
-
const resumeMode = process.env.RIG_RUN_RESUME === "1";
|
|
1445
|
-
const resumePreviousStatus = String(existingRunRecord?.status ?? "").toLowerCase();
|
|
1446
|
-
const sourceTask = readRunSourceTaskContract(context.projectRoot, input.runId, input.taskId);
|
|
1447
|
-
let prompt = buildRunPrompt({
|
|
1448
|
-
projectRoot: context.projectRoot,
|
|
1449
|
-
taskId: input.taskId,
|
|
1450
|
-
fallbackTitle: input.title,
|
|
1451
|
-
fallbackDescription: sourceTask?.description ?? sourceTask?.body ?? null,
|
|
1452
|
-
fallbackAcceptanceCriteria: sourceTask?.acceptanceCriteria ?? sourceTask?.acceptance_criteria ?? null,
|
|
1453
|
-
sourceTask,
|
|
1454
|
-
initialPrompt: input.initialPrompt,
|
|
1455
|
-
runtimeAdapter: input.runtimeAdapter
|
|
1456
|
-
});
|
|
1457
|
-
const startedAt = new Date().toISOString();
|
|
1458
|
-
const hostAgentBinary = await resolvePreferredShellBinary(context.projectRoot);
|
|
1459
|
-
const baseAgentArgs = input.runtimeAdapter === "codex" ? [
|
|
1460
|
-
"__rig_codex_app_server_task_run__",
|
|
1461
|
-
"--runtime-mode",
|
|
1462
|
-
input.runtimeMode,
|
|
1463
|
-
"--interaction-mode",
|
|
1464
|
-
input.interactionMode,
|
|
1465
|
-
...input.model ? ["--model", input.model] : [],
|
|
1466
|
-
"--prompt"
|
|
1467
|
-
] : input.runtimeAdapter === "pi" ? [
|
|
1468
|
-
"__rig_pi_session_daemon__",
|
|
1469
|
-
...input.model ? ["--model", input.model] : []
|
|
1470
|
-
] : [
|
|
1471
|
-
"--print",
|
|
1472
|
-
"--verbose",
|
|
1473
|
-
"--output-format",
|
|
1474
|
-
"stream-json",
|
|
1475
|
-
"--dangerously-skip-permissions"
|
|
1476
|
-
];
|
|
1477
|
-
const buildHostAgentCommand = (attemptPrompt) => input.runtimeAdapter === "codex" ? [hostAgentBinary, ...baseAgentArgs, attemptPrompt] : [hostAgentBinary, ...baseAgentArgs];
|
|
1478
|
-
const hostAgentCommand = buildHostAgentCommand(prompt);
|
|
1479
|
-
const hostAgentCommandText = formatCommand(hostAgentCommand);
|
|
1480
|
-
const provisioningAction = startRunAction(context.projectRoot, input.runId, {
|
|
1481
|
-
actionId: `action:${input.runId}:runtime-provision`,
|
|
1482
|
-
actionType: "engine.runtime.provision",
|
|
1483
|
-
title: "Provision dedicated runtime",
|
|
1484
|
-
detail: input.taskId ? `Preparing isolated worktree for ${input.taskId}` : "Preparing isolated runtime",
|
|
1485
|
-
payload: {
|
|
1486
|
-
hostAgentCommand,
|
|
1487
|
-
formattedCommand: hostAgentCommandText,
|
|
1488
|
-
taskId: input.taskId ?? null,
|
|
1489
|
-
mode: "worktree"
|
|
1490
|
-
}
|
|
1491
|
-
});
|
|
1492
|
-
upsertAgentAuthorityRun(context.projectRoot, {
|
|
1493
|
-
runId: input.runId,
|
|
1494
|
-
taskId: runtimeTaskId,
|
|
1495
|
-
createdAt: startedAt,
|
|
1496
|
-
runtimeAdapter: input.runtimeAdapter,
|
|
1497
|
-
status: resumeMode ? "preparing" : "created"
|
|
1498
|
-
});
|
|
1499
|
-
patchAuthorityRun(context.projectRoot, input.runId, {
|
|
1500
|
-
status: "preparing",
|
|
1501
|
-
startedAt,
|
|
1502
|
-
completedAt: null,
|
|
1503
|
-
errorText: null,
|
|
1504
|
-
artifactRoot: resumeMode ? existingRunRecord?.artifactRoot ?? null : null,
|
|
1505
|
-
runtimeAdapter: input.runtimeAdapter,
|
|
1506
|
-
runtimeMode: input.runtimeMode,
|
|
1507
|
-
interactionMode: input.interactionMode,
|
|
1508
|
-
runMode: input.runtimeMode === "full-access" ? "autonomous" : "interactive",
|
|
1509
|
-
initialPrompt: input.initialPrompt ?? null,
|
|
1510
|
-
title: input.taskId ? undefined : input.title ?? `Run ${input.runId}`,
|
|
1511
|
-
pid: process.pid
|
|
1512
|
-
});
|
|
1513
|
-
emitServerRunEvent({
|
|
1514
|
-
type: "status",
|
|
1515
|
-
runId: input.runId,
|
|
1516
|
-
status: "preparing",
|
|
1517
|
-
detail: input.taskId ?? input.title ?? runtimeTaskId
|
|
1518
|
-
});
|
|
1519
|
-
appendRunLog(context.projectRoot, input.runId, {
|
|
1520
|
-
id: `log:${input.runId}:${resumeMode ? "resume" : "start"}`,
|
|
1521
|
-
title: resumeMode ? "Rig task run resumed" : "Rig task run started",
|
|
1522
|
-
detail: resumeMode ? `Continuing the same run lifecycle for ${input.taskId ?? input.title ?? runtimeTaskId}.` : input.taskId ?? input.title ?? runtimeTaskId,
|
|
1523
|
-
tone: "info",
|
|
1524
|
-
status: "preparing",
|
|
1525
|
-
createdAt: startedAt
|
|
1526
|
-
});
|
|
1527
|
-
appendRunLog(context.projectRoot, input.runId, {
|
|
1528
|
-
id: `log:${input.runId}:wrapper-command`,
|
|
1529
|
-
title: "Agent wrapper command",
|
|
1530
|
-
detail: hostAgentCommandText,
|
|
1531
|
-
tone: "tool",
|
|
1532
|
-
status: "preparing",
|
|
1533
|
-
payload: {
|
|
1534
|
-
command: hostAgentCommand,
|
|
1535
|
-
formattedCommand: hostAgentCommandText
|
|
1536
|
-
},
|
|
1537
|
-
createdAt: new Date().toISOString()
|
|
1538
|
-
});
|
|
1539
|
-
emitServerRunEvent({ type: "log", runId: input.runId, title: "Agent wrapper command" });
|
|
1540
|
-
const loadedAutomationConfig = await loadTaskRunAutomationConfig(context.projectRoot);
|
|
1541
|
-
const automationConfig = input.prMode ? { ...loadedAutomationConfig ?? {}, pr: { ...loadedAutomationConfig?.pr ?? {}, mode: input.prMode } } : loadedAutomationConfig;
|
|
1542
|
-
const planningClassification = classifyPlanningNeed({ config: automationConfig, sourceTask });
|
|
1543
|
-
const planningArtifactPath = resolve6("artifacts", runtimeTaskId, "implementation-plan.md");
|
|
1544
|
-
const persistedPlanning = {
|
|
1545
|
-
...planningClassification,
|
|
1546
|
-
classifier: input.runtimeAdapter === "pi" ? "pi-rig-structured-policy" : "rig-structured-policy",
|
|
1547
|
-
artifactPath: planningClassification.planningRequired ? planningArtifactPath : null,
|
|
1548
|
-
classifiedAt: new Date().toISOString()
|
|
1549
|
-
};
|
|
1550
|
-
mkdirSync2(resolve6(context.projectRoot, ".rig", "runs", input.runId), { recursive: true });
|
|
1551
|
-
writeFileSync2(resolve6(context.projectRoot, ".rig", "runs", input.runId, "planning-classification.json"), `${JSON.stringify(persistedPlanning, null, 2)}
|
|
1552
|
-
`, "utf8");
|
|
1553
|
-
patchAuthorityRun(context.projectRoot, input.runId, { planning: persistedPlanning });
|
|
1554
|
-
prompt = `${prompt}
|
|
1555
|
-
|
|
1556
|
-
Rig planning classification:
|
|
1557
|
-
${JSON.stringify(persistedPlanning, null, 2)}
|
|
1558
|
-
${planningClassification.planningRequired ? `Before implementing, write a concise implementation plan to ${planningArtifactPath}. Treat that plan artifact as required acceptance evidence for the Plan stage.` : "Planning is not required for this run; briefly state why before implementation."}`;
|
|
1559
|
-
if (input.runtimeAdapter === "pi") {
|
|
1560
|
-
for (const stage of ["Connect", "GitHub/task sync", "Prepare workspace", "Launch Pi", "Plan", "Implement"]) {
|
|
1561
|
-
appendPiStageLog({
|
|
1562
|
-
projectRoot: context.projectRoot,
|
|
1563
|
-
runId: input.runId,
|
|
1564
|
-
stage,
|
|
1565
|
-
detail: stage === "Launch Pi" ? "Worker Pi SDK session daemon starting; local frontend will attach over Rig-proxied WebSocket." : stage === "Plan" ? `${planningClassification.planningRequired ? "recorded" : "skipped"} (${planningClassification.reason}; size=${planningClassification.size}; risk=${planningClassification.risk})` : stage === "Implement" ? "Pi implementation pass is running in the worker runtime." : null,
|
|
1566
|
-
status: stage === "Implement" || stage === "Launch Pi" ? "running" : "completed"
|
|
1567
|
-
});
|
|
1568
|
-
}
|
|
1569
|
-
}
|
|
1570
|
-
appendRunTimeline(context.projectRoot, input.runId, {
|
|
1571
|
-
id: `message:${input.runId}:user`,
|
|
1572
|
-
type: "user_message",
|
|
1573
|
-
text: prompt,
|
|
1574
|
-
createdAt: startedAt,
|
|
1575
|
-
state: "completed",
|
|
1576
|
-
completedAt: startedAt
|
|
1577
|
-
});
|
|
1578
|
-
emitServerRunEvent({ type: "timeline", runId: input.runId });
|
|
1579
|
-
await context.emitEvent("command.started", {
|
|
1580
|
-
command: [
|
|
1581
|
-
"rig",
|
|
1582
|
-
"server",
|
|
1583
|
-
"task-run",
|
|
1584
|
-
...input.taskId ? ["--task", input.taskId] : [],
|
|
1585
|
-
...input.title ? ["--title", input.title] : []
|
|
1586
|
-
],
|
|
1587
|
-
formattedCommand: input.taskId ? `rig server task-run --task ${input.taskId}` : `rig server task-run --title ${JSON.stringify(input.title ?? `Run ${input.runId}`)}`,
|
|
1588
|
-
startedAt,
|
|
1589
|
-
dryRun: false
|
|
1590
|
-
});
|
|
1591
|
-
const assistantMessageId = `message:${input.runId}:assistant`;
|
|
1592
|
-
let assistantText = "";
|
|
1593
|
-
const pendingClaudeToolUses = new Map;
|
|
1594
|
-
const pendingCodexToolUses = new Map;
|
|
1595
|
-
let launchAction;
|
|
1596
|
-
let verificationAction;
|
|
1597
|
-
let reviewAction;
|
|
1598
|
-
let verificationStarted = false;
|
|
1599
|
-
let reviewStarted = false;
|
|
1600
|
-
let latestRuntimeWorkspace = resumeMode && typeof existingRunRecord?.worktreePath === "string" ? existingRunRecord.worktreePath : null;
|
|
1601
|
-
let latestSessionDir = resumeMode && typeof existingRunRecord?.sessionPath === "string" ? resolve6(existingRunRecord.sessionPath, "..") : null;
|
|
1602
|
-
let latestLogsDir = resumeMode && typeof existingRunRecord?.logRoot === "string" ? existingRunRecord.logRoot : null;
|
|
1603
|
-
let latestProviderCommand = null;
|
|
1604
|
-
let latestRuntimeBranch = resumeMode && typeof existingRunRecord?.branch === "string" ? existingRunRecord.branch : null;
|
|
1605
|
-
let snapshotSidecarPromise = null;
|
|
1606
|
-
let wrapperManagesRuntimeSnapshot = false;
|
|
1607
|
-
let dirtyBaselineApplied = false;
|
|
1608
|
-
const childEnv = {
|
|
1609
|
-
...process.env,
|
|
1610
|
-
...input.runtimeAdapter === "pi" ? buildPiRigBridgeEnv({
|
|
1611
|
-
projectRoot: context.projectRoot,
|
|
1612
|
-
runId: input.runId,
|
|
1613
|
-
taskId: runtimeTaskId,
|
|
1614
|
-
serverUrl: process.env.RIG_SERVER_URL ?? null,
|
|
1615
|
-
authToken: process.env.RIG_AUTH_TOKEN ?? null,
|
|
1616
|
-
githubToken: process.env.RIG_GITHUB_TOKEN ?? process.env.GITHUB_TOKEN ?? process.env.GH_TOKEN ?? null
|
|
1617
|
-
}) : {
|
|
1618
|
-
PROJECT_RIG_ROOT: context.projectRoot,
|
|
1619
|
-
RIG_TASK_ID: runtimeTaskId,
|
|
1620
|
-
RIG_RUNTIME_ADAPTER: input.runtimeAdapter,
|
|
1621
|
-
RIG_SERVER_RUN_ID: input.runId
|
|
1622
|
-
},
|
|
1623
|
-
...sourceTask ? { RIG_SOURCE_TASK_JSON: JSON.stringify(sourceTask) } : {},
|
|
1624
|
-
...resumeMode ? {
|
|
1625
|
-
RIG_RUN_RESUME: "1",
|
|
1626
|
-
RIG_RUNTIME_ARTIFACT_CLEANUP: "preserve"
|
|
1627
|
-
} : {}
|
|
1628
|
-
};
|
|
1629
|
-
Object.assign(childEnv, buildTaskRunReviewEnv(automationConfig));
|
|
1630
|
-
Object.assign(childEnv, buildDirtyBaselineHandshakeEnv({ projectRoot: context.projectRoot, runId: input.runId, baselineMode: input.baselineMode }));
|
|
1631
|
-
const automationLimits = resolveTaskRunAutomationLimits(automationConfig);
|
|
1632
|
-
const maxAttempts = automationLimits.maxValidationAttempts;
|
|
1633
|
-
const promoteToValidating = (detail) => {
|
|
1634
|
-
if (verificationStarted)
|
|
1635
|
-
return;
|
|
1636
|
-
verificationStarted = true;
|
|
1637
|
-
patchAuthorityRun(context.projectRoot, input.runId, { status: "validating" });
|
|
1638
|
-
emitServerRunEvent({ type: "status", runId: input.runId, status: "validating", detail: detail ?? null });
|
|
1639
|
-
verificationAction = startRunAction(context.projectRoot, input.runId, {
|
|
1640
|
-
actionId: `action:${input.runId}:completion-verification`,
|
|
1641
|
-
actionType: "completion-verification",
|
|
1642
|
-
title: "Run completion verification",
|
|
1643
|
-
detail: detail ?? "Rig completion-verification hook is running."
|
|
1644
|
-
});
|
|
1645
|
-
};
|
|
1646
|
-
const promoteToReviewing = (detail) => {
|
|
1647
|
-
if (reviewStarted)
|
|
1648
|
-
return;
|
|
1649
|
-
reviewStarted = true;
|
|
1650
|
-
patchAuthorityRun(context.projectRoot, input.runId, { status: "reviewing" });
|
|
1651
|
-
emitServerRunEvent({ type: "status", runId: input.runId, status: "reviewing", detail: detail ?? null });
|
|
1652
|
-
reviewAction = startRunAction(context.projectRoot, input.runId, {
|
|
1653
|
-
actionId: `action:${input.runId}:review-closeout`,
|
|
1654
|
-
actionType: "run.review",
|
|
1655
|
-
title: "Finalize run review",
|
|
1656
|
-
detail: detail ?? "Verifier review is running."
|
|
1657
|
-
});
|
|
1658
|
-
};
|
|
1659
|
-
const nextRunLogId = createRunLogIdFactory(input.runId);
|
|
1660
|
-
const handleWrapperEvent = (rawPayload) => {
|
|
1661
|
-
let event = null;
|
|
1662
|
-
try {
|
|
1663
|
-
event = JSON.parse(rawPayload);
|
|
1664
|
-
} catch {
|
|
1665
|
-
return false;
|
|
1666
|
-
}
|
|
1667
|
-
if (!event?.type)
|
|
1668
|
-
return false;
|
|
1669
|
-
const payload = event.payload ?? {};
|
|
1670
|
-
if (event.type === "runtime.provision.completed") {
|
|
1671
|
-
latestRuntimeWorkspace = typeof payload.workspaceDir === "string" ? payload.workspaceDir : latestRuntimeWorkspace;
|
|
1672
|
-
latestSessionDir = typeof payload.sessionDir === "string" ? payload.sessionDir : latestSessionDir;
|
|
1673
|
-
latestLogsDir = typeof payload.logsDir === "string" ? payload.logsDir : latestLogsDir;
|
|
1674
|
-
const runtimeId = typeof payload.runtimeId === "string" ? payload.runtimeId : null;
|
|
1675
|
-
wrapperManagesRuntimeSnapshot = payload.snapshotManaged === true;
|
|
1676
|
-
latestRuntimeBranch = runtimeId;
|
|
1677
|
-
provisioningAction.complete(latestRuntimeWorkspace ?? "Runtime ready.", {
|
|
1678
|
-
runtimeId: runtimeId ?? null,
|
|
1679
|
-
workspaceDir: latestRuntimeWorkspace,
|
|
1680
|
-
sessionDir: latestSessionDir,
|
|
1681
|
-
logsDir: latestLogsDir,
|
|
1682
|
-
contextFile: payload.contextFile ?? null
|
|
1683
|
-
});
|
|
1684
|
-
patchAuthorityRun(context.projectRoot, input.runId, {
|
|
1685
|
-
status: "running",
|
|
1686
|
-
worktreePath: latestRuntimeWorkspace,
|
|
1687
|
-
artifactRoot: latestRuntimeWorkspace && input.taskId ? resolve6(latestRuntimeWorkspace, "artifacts", input.taskId) : null,
|
|
1688
|
-
logRoot: latestLogsDir,
|
|
1689
|
-
sessionPath: latestSessionDir ? resolve6(latestSessionDir, "session.json") : null,
|
|
1690
|
-
sessionLogPath: latestLogsDir ? resolve6(latestLogsDir, "agent-stdout.log") : null,
|
|
1691
|
-
branch: runtimeId
|
|
1692
|
-
});
|
|
1693
|
-
if (!dirtyBaselineApplied && input.baselineMode === "dirty-snapshot" && latestRuntimeWorkspace) {
|
|
1694
|
-
dirtyBaselineApplied = true;
|
|
1695
|
-
const dirty = applyDirtyBaselineSnapshot({ sourceRoot: context.projectRoot, targetRoot: latestRuntimeWorkspace });
|
|
1696
|
-
const readyFile = childEnv.RIG_DIRTY_BASELINE_READY_FILE;
|
|
1697
|
-
if (readyFile) {
|
|
1698
|
-
mkdirSync2(resolve6(readyFile, ".."), { recursive: true });
|
|
1699
|
-
writeFileSync2(readyFile, `${JSON.stringify({ ...dirty, workspaceDir: latestRuntimeWorkspace, appliedAt: new Date().toISOString() }, null, 2)}
|
|
1700
|
-
`, "utf8");
|
|
1701
|
-
}
|
|
1702
|
-
appendRunLog(context.projectRoot, input.runId, {
|
|
1703
|
-
id: `log:${input.runId}:dirty-baseline`,
|
|
1704
|
-
title: "Dirty baseline snapshot",
|
|
1705
|
-
detail: dirty.detail,
|
|
1706
|
-
tone: dirty.applied ? "tool" : "info",
|
|
1707
|
-
status: dirty.applied ? "completed" : "skipped",
|
|
1708
|
-
createdAt: new Date().toISOString(),
|
|
1709
|
-
payload: readyFile ? { readyFile } : undefined
|
|
1710
|
-
});
|
|
1711
|
-
emitServerRunEvent({ type: "log", runId: input.runId, title: "Dirty baseline snapshot" });
|
|
1712
|
-
}
|
|
1713
|
-
if (!wrapperManagesRuntimeSnapshot && !snapshotSidecarPromise && runtimeId && loadRuntimeSnapshotConfig(context.projectRoot).enabled) {
|
|
1714
|
-
snapshotSidecarPromise = (async () => {
|
|
1715
|
-
const { sidecar, error } = await resolveTaskRunSnapshotSidecar({
|
|
1716
|
-
projectRoot: context.projectRoot,
|
|
1717
|
-
runtimeId,
|
|
1718
|
-
workspaceDir: latestRuntimeWorkspace,
|
|
1719
|
-
listRuntimes: listAgentRuntimes,
|
|
1720
|
-
startSidecar: (runtime) => startRuntimeSnapshotSidecar(runtime, { instanceId: `${runtime.id}-run-${input.runId}` })
|
|
1721
|
-
});
|
|
1722
|
-
if (!sidecar) {
|
|
1723
|
-
appendRunLog(context.projectRoot, input.runId, {
|
|
1724
|
-
id: `log:${input.runId}:snapshot-unavailable`,
|
|
1725
|
-
title: "Runtime snapshotting unavailable",
|
|
1726
|
-
detail: error ?? `Could not locate runtime metadata for ${runtimeId}.`,
|
|
1727
|
-
tone: "error",
|
|
1728
|
-
status: "running",
|
|
1729
|
-
createdAt: new Date().toISOString()
|
|
1730
|
-
});
|
|
1731
|
-
emitServerRunEvent({ type: "log", runId: input.runId, title: "Runtime snapshotting unavailable" });
|
|
1732
|
-
return null;
|
|
1733
|
-
}
|
|
1734
|
-
return sidecar;
|
|
1735
|
-
})();
|
|
1736
|
-
}
|
|
1737
|
-
emitServerRunEvent({
|
|
1738
|
-
type: "status",
|
|
1739
|
-
runId: input.runId,
|
|
1740
|
-
status: "running",
|
|
1741
|
-
detail: latestRuntimeWorkspace
|
|
1742
|
-
});
|
|
1743
|
-
return true;
|
|
1744
|
-
}
|
|
1745
|
-
if (event.type === "runtime.provision.failed") {
|
|
1746
|
-
const detail = typeof payload.error === "string" ? payload.error : "Runtime provisioning failed.";
|
|
1747
|
-
provisioningAction.fail(detail, payload);
|
|
1748
|
-
emitServerRunEvent({ type: "failed", runId: input.runId, error: detail });
|
|
1749
|
-
return true;
|
|
1750
|
-
}
|
|
1751
|
-
if (event.type === "provider.launch") {
|
|
1752
|
-
const command = Array.isArray(payload.command) ? payload.command.filter((value) => typeof value === "string") : [];
|
|
1753
|
-
latestProviderCommand = command.length > 0 ? command : null;
|
|
1754
|
-
const commandText = command.length > 0 ? formatCommand(command) : String(payload.provider ?? "provider");
|
|
1755
|
-
launchAction = startRunAction(context.projectRoot, input.runId, {
|
|
1756
|
-
actionId: `action:${input.runId}:provider-launch`,
|
|
1757
|
-
actionType: "agent.launch",
|
|
1758
|
-
title: "Launch agent runtime",
|
|
1759
|
-
detail: commandText,
|
|
1760
|
-
payload: {
|
|
1761
|
-
runtimeAdapter: input.runtimeAdapter,
|
|
1762
|
-
runtimeMode: input.runtimeMode,
|
|
1763
|
-
interactionMode: input.interactionMode,
|
|
1764
|
-
workspaceDir: payload.workspaceDir ?? latestRuntimeWorkspace,
|
|
1765
|
-
command,
|
|
1766
|
-
formattedCommand: commandText
|
|
1767
|
-
}
|
|
1768
|
-
});
|
|
1769
|
-
appendRunLog(context.projectRoot, input.runId, {
|
|
1770
|
-
id: `log:${input.runId}:provider-command`,
|
|
1771
|
-
title: "Agent launch command",
|
|
1772
|
-
detail: commandText,
|
|
1773
|
-
tone: "tool",
|
|
1774
|
-
status: "running",
|
|
1775
|
-
payload: {
|
|
1776
|
-
command,
|
|
1777
|
-
formattedCommand: commandText
|
|
1778
|
-
},
|
|
1779
|
-
createdAt: new Date().toISOString()
|
|
1780
|
-
});
|
|
1781
|
-
emitServerRunEvent({ type: "log", runId: input.runId, title: "Agent launch command" });
|
|
1782
|
-
return true;
|
|
1783
|
-
}
|
|
1784
|
-
if (event.type === "provider.completed") {
|
|
1785
|
-
const exitCode = typeof payload.exitCode === "number" ? payload.exitCode : null;
|
|
1786
|
-
if (launchAction) {
|
|
1787
|
-
if (exitCode === 0) {
|
|
1788
|
-
launchAction.complete("Agent runtime finished.");
|
|
1789
|
-
} else {
|
|
1790
|
-
launchAction.fail(`Agent runtime failed (${String(exitCode ?? "unknown")})`, payload);
|
|
1791
|
-
}
|
|
1792
|
-
}
|
|
1793
|
-
return true;
|
|
1794
|
-
}
|
|
1795
|
-
if (event.type === "pi.sessiond.starting" || event.type === "pi.sessiond.ready" || event.type === "pi.session.event_stream.connected" || event.type === "pi.prompt.sent" || event.type === "pi.prompt.waiting" || event.type === "pi.session.agent_end" || event.type === "pi.session.error") {
|
|
1796
|
-
const title = event.type === "pi.sessiond.starting" ? "Starting worker Pi session daemon" : event.type === "pi.sessiond.ready" ? "Worker Pi daemon ready" : event.type === "pi.session.event_stream.connected" ? "Worker Pi event stream connected" : event.type === "pi.prompt.sent" ? "Delivered initial prompt to worker Pi" : event.type === "pi.prompt.waiting" ? "Worker Pi prompt waiting" : event.type === "pi.session.agent_end" ? "Worker Pi turn complete" : "Worker Pi session error";
|
|
1797
|
-
const detail = event.type === "pi.sessiond.ready" ? "Daemon accepted control connection; waiting for SDK session metadata." : event.type === "pi.sessiond.starting" ? String(payload.workspaceDir ?? "worker runtime") : event.type === "pi.prompt.sent" ? `${String(payload.bytes ?? "unknown")} prompt bytes sent.` : event.type === "pi.prompt.waiting" ? String(payload.reason ?? "empty prompt") : event.type === "pi.session.error" ? String(payload.message ?? "session error") : String(payload.sessionId ?? payload.runId ?? "worker Pi session");
|
|
1798
|
-
appendRunLog(context.projectRoot, input.runId, {
|
|
1799
|
-
id: nextRunLogId(),
|
|
1800
|
-
title,
|
|
1801
|
-
detail,
|
|
1802
|
-
tone: event.type === "pi.session.error" ? "error" : "info",
|
|
1803
|
-
status: reviewStarted ? "reviewing" : verificationStarted ? "validating" : "running",
|
|
1804
|
-
payload: {
|
|
1805
|
-
eventType: event.type,
|
|
1806
|
-
runId: typeof payload.runId === "string" ? payload.runId : null,
|
|
1807
|
-
runtimeId: typeof payload.runtimeId === "string" ? payload.runtimeId : null,
|
|
1808
|
-
sessionId: typeof payload.sessionId === "string" ? payload.sessionId : null
|
|
1809
|
-
},
|
|
1810
|
-
createdAt: new Date().toISOString()
|
|
1811
|
-
});
|
|
1812
|
-
emitServerRunEvent({ type: "log", runId: input.runId, title });
|
|
1813
|
-
return true;
|
|
1814
|
-
}
|
|
1815
|
-
if (event.type === "pi.session.ready") {
|
|
1816
|
-
const privateMetadata = payload.privateMetadata && typeof payload.privateMetadata === "object" && !Array.isArray(payload.privateMetadata) ? payload.privateMetadata : null;
|
|
1817
|
-
const publicMetadata = payload.metadata && typeof payload.metadata === "object" && !Array.isArray(payload.metadata) ? payload.metadata : null;
|
|
1818
|
-
if (privateMetadata) {
|
|
1819
|
-
patchAuthorityRun(context.projectRoot, input.runId, {
|
|
1820
|
-
piSession: publicMetadata,
|
|
1821
|
-
piSessionPrivate: privateMetadata
|
|
1822
|
-
});
|
|
1823
|
-
const sessionId = typeof publicMetadata?.sessionId === "string" ? publicMetadata.sessionId : typeof privateMetadata.public === "object" && privateMetadata.public && !Array.isArray(privateMetadata.public) ? String(privateMetadata.public.sessionId ?? "") : "";
|
|
1824
|
-
appendRunLog(context.projectRoot, input.runId, {
|
|
1825
|
-
id: `log:${input.runId}:pi-session-ready`,
|
|
1826
|
-
title: "Worker Pi session ready",
|
|
1827
|
-
detail: sessionId ? `Session ${sessionId} is ready for WebSocket attach.` : "Worker Pi SDK session daemon is ready for WebSocket attach.",
|
|
1828
|
-
tone: "info",
|
|
1829
|
-
status: "running",
|
|
1830
|
-
payload: {
|
|
1831
|
-
sessionId: sessionId || null,
|
|
1832
|
-
runtimeId: typeof payload.runtimeId === "string" ? payload.runtimeId : null
|
|
1833
|
-
},
|
|
1834
|
-
createdAt: new Date().toISOString()
|
|
1835
|
-
});
|
|
1836
|
-
emitServerRunEvent({ type: "log", runId: input.runId, title: "Worker Pi session ready" });
|
|
1837
|
-
}
|
|
1838
|
-
return true;
|
|
1839
|
-
}
|
|
1840
|
-
if (event.type === "pi.rpc.prompt.sent" || event.type === "pi.rpc.steering.delivered" || event.type === "pi.rpc.steering.poll.failed" || event.type === "pi.rpc.extension_ui.cancelled") {
|
|
1841
|
-
const title = event.type === "pi.rpc.prompt.sent" ? "Delivered initial prompt to worker Pi" : event.type === "pi.rpc.steering.delivered" ? "Delivered steering to worker Pi" : event.type === "pi.rpc.steering.poll.failed" ? "Worker Pi steering poll failed" : "Pi RPC UI request auto-cancelled";
|
|
1842
|
-
const detail = event.type === "pi.rpc.prompt.sent" ? `${String(payload.kind ?? "prompt")} prompt (${String(payload.bytes ?? "unknown")} bytes)` : event.type === "pi.rpc.steering.delivered" ? `${String(payload.actor ?? "operator")}: ${String(payload.message ?? "")}`.slice(0, 500) : event.type === "pi.rpc.steering.poll.failed" ? String(payload.error ?? "steering poll failed") : `${String(payload.method ?? "ui")}: ${String(payload.reason ?? "noninteractive worker session")}`;
|
|
1843
|
-
appendRunLog(context.projectRoot, input.runId, {
|
|
1844
|
-
id: nextRunLogId(),
|
|
1845
|
-
title,
|
|
1846
|
-
detail,
|
|
1847
|
-
tone: event.type === "pi.rpc.steering.poll.failed" ? "error" : "info",
|
|
1848
|
-
status: reviewStarted ? "reviewing" : verificationStarted ? "validating" : "running",
|
|
1849
|
-
payload,
|
|
1850
|
-
createdAt: new Date().toISOString()
|
|
1851
|
-
});
|
|
1852
|
-
emitServerRunEvent({ type: "log", runId: input.runId, title });
|
|
1853
|
-
return true;
|
|
1854
|
-
}
|
|
1855
|
-
return false;
|
|
1856
|
-
};
|
|
1857
|
-
const handleAgentStdoutLine = (line) => {
|
|
1858
|
-
const trimmed = line.trim();
|
|
1859
|
-
if (!trimmed)
|
|
1860
|
-
return;
|
|
1861
|
-
if (trimmed.startsWith("__RIG_WRAPPER_EVENT__")) {
|
|
1862
|
-
if (handleWrapperEvent(trimmed.slice("__RIG_WRAPPER_EVENT__".length))) {
|
|
1863
|
-
emitServerRunEvent({ type: "timeline", runId: input.runId });
|
|
1864
|
-
return;
|
|
1865
|
-
}
|
|
1866
|
-
}
|
|
1867
|
-
const completionLine = classifyCompletionVerificationLine(trimmed);
|
|
1868
|
-
if (completionLine.isCompletionLine) {
|
|
1869
|
-
promoteToValidating(trimmed);
|
|
1870
|
-
if (completionLine.isVerifierReview) {
|
|
1871
|
-
if (verificationAction) {
|
|
1872
|
-
verificationAction.complete("Completion verification checks finished.");
|
|
1873
|
-
}
|
|
1874
|
-
promoteToReviewing(trimmed);
|
|
1875
|
-
}
|
|
1876
|
-
appendRunLog(context.projectRoot, input.runId, {
|
|
1877
|
-
id: nextRunLogId(),
|
|
1878
|
-
title: verificationStarted ? "Completion verification" : "Agent output",
|
|
1879
|
-
detail: trimmed,
|
|
1880
|
-
tone: "info",
|
|
1881
|
-
status: reviewStarted ? "reviewing" : verificationStarted ? "validating" : "running",
|
|
1882
|
-
createdAt: new Date().toISOString()
|
|
1883
|
-
});
|
|
1884
|
-
emitServerRunEvent({ type: "log", runId: input.runId, title: verificationStarted ? "Completion verification" : "Agent output" });
|
|
1885
|
-
return;
|
|
1886
|
-
}
|
|
1887
|
-
try {
|
|
1888
|
-
const record = JSON.parse(trimmed);
|
|
1889
|
-
const liveLogStatus = reviewStarted ? "reviewing" : verificationStarted ? "validating" : "running";
|
|
1890
|
-
if (input.runtimeAdapter === "pi" && appendPiRpcProtocolLogFromRecord({
|
|
1891
|
-
projectRoot: context.projectRoot,
|
|
1892
|
-
runId: input.runId,
|
|
1893
|
-
record,
|
|
1894
|
-
status: liveLogStatus,
|
|
1895
|
-
nextRunLogId
|
|
1896
|
-
})) {
|
|
1897
|
-
return;
|
|
1898
|
-
}
|
|
1899
|
-
if (input.runtimeAdapter === "pi" && appendPiToolTimelineFromRecord({ projectRoot: context.projectRoot, runId: input.runId, record })) {
|
|
1900
|
-
emitServerRunEvent({ type: "timeline", runId: input.runId });
|
|
1901
|
-
return;
|
|
1902
|
-
}
|
|
1903
|
-
const providerLogs = input.runtimeAdapter === "codex" ? buildCodexLogsFromRecord({
|
|
1904
|
-
runId: input.runId,
|
|
1905
|
-
record,
|
|
1906
|
-
createdAtFallback: new Date().toISOString(),
|
|
1907
|
-
status: liveLogStatus,
|
|
1908
|
-
pendingToolUses: pendingCodexToolUses
|
|
1909
|
-
}) : buildClaudeLogsFromRecord({
|
|
1910
|
-
runId: input.runId,
|
|
1911
|
-
record,
|
|
1912
|
-
createdAtFallback: new Date().toISOString(),
|
|
1913
|
-
status: liveLogStatus,
|
|
1914
|
-
pendingToolUses: pendingClaudeToolUses
|
|
1915
|
-
});
|
|
1916
|
-
if (providerLogs.length > 0) {
|
|
1917
|
-
for (const providerLog of providerLogs) {
|
|
1918
|
-
appendRunLog(context.projectRoot, input.runId, providerLog);
|
|
1919
|
-
appendToolTimelineFromLog({ projectRoot: context.projectRoot, runId: input.runId, log: providerLog });
|
|
1920
|
-
emitServerRunEvent({ type: "log", runId: input.runId, title: providerLog.title });
|
|
1921
|
-
if (providerLog.title === "Tool activity")
|
|
1922
|
-
emitServerRunEvent({ type: "timeline", runId: input.runId });
|
|
1923
|
-
}
|
|
1924
|
-
}
|
|
1925
|
-
if (input.runtimeAdapter === "codex") {
|
|
1926
|
-
const nextAssistantText = extractCodexAssistantMessageText(record);
|
|
1927
|
-
if (nextAssistantText) {
|
|
1928
|
-
assistantText = nextAssistantText;
|
|
1929
|
-
appendRunTimeline(context.projectRoot, input.runId, {
|
|
1930
|
-
id: assistantMessageId,
|
|
1931
|
-
type: "assistant_message",
|
|
1932
|
-
text: assistantText,
|
|
1933
|
-
state: "streaming",
|
|
1934
|
-
createdAt: new Date().toISOString()
|
|
1935
|
-
});
|
|
1936
|
-
emitServerRunEvent({ type: "timeline", runId: input.runId });
|
|
1937
|
-
return;
|
|
1938
|
-
}
|
|
1939
|
-
if (providerLogs.length > 0 || isCodexExecRecord(record)) {
|
|
1940
|
-
return;
|
|
1941
|
-
}
|
|
1942
|
-
}
|
|
1943
|
-
if (record.type === "message_update") {
|
|
1944
|
-
const assistantMessageEvent = record.assistantMessageEvent && typeof record.assistantMessageEvent === "object" ? record.assistantMessageEvent : null;
|
|
1945
|
-
if (assistantMessageEvent?.type === "text_delta" && typeof assistantMessageEvent.delta === "string") {
|
|
1946
|
-
assistantText += assistantMessageEvent.delta;
|
|
1947
|
-
appendRunTimeline(context.projectRoot, input.runId, {
|
|
1948
|
-
id: assistantMessageId,
|
|
1949
|
-
type: "assistant_message",
|
|
1950
|
-
text: assistantText,
|
|
1951
|
-
state: "streaming",
|
|
1952
|
-
createdAt: new Date().toISOString()
|
|
1953
|
-
});
|
|
1954
|
-
emitServerRunEvent({ type: "timeline", runId: input.runId });
|
|
1955
|
-
return;
|
|
1956
|
-
}
|
|
1957
|
-
}
|
|
1958
|
-
if (record.type === "stream_event") {
|
|
1959
|
-
const event = record.event && typeof record.event === "object" ? record.event : null;
|
|
1960
|
-
const delta = event?.delta && typeof event.delta === "object" ? event.delta : null;
|
|
1961
|
-
if (delta?.type === "text_delta" && typeof delta.text === "string") {
|
|
1962
|
-
assistantText += delta.text;
|
|
1963
|
-
appendRunTimeline(context.projectRoot, input.runId, {
|
|
1964
|
-
id: assistantMessageId,
|
|
1965
|
-
type: "assistant_message",
|
|
1966
|
-
text: assistantText,
|
|
1967
|
-
state: "streaming",
|
|
1968
|
-
createdAt: new Date().toISOString()
|
|
1969
|
-
});
|
|
1970
|
-
emitServerRunEvent({ type: "timeline", runId: input.runId });
|
|
1971
|
-
return;
|
|
1972
|
-
}
|
|
1973
|
-
}
|
|
1974
|
-
if (input.runtimeAdapter === "pi" && isNonRenderablePiProtocolRecord(record)) {
|
|
1975
|
-
return;
|
|
1976
|
-
}
|
|
1977
|
-
if (record.type === "assistant") {
|
|
1978
|
-
const message = record.message && typeof record.message === "object" ? record.message : record;
|
|
1979
|
-
const content = Array.isArray(message.content) ? message.content : [];
|
|
1980
|
-
const nextText = content.map((entry) => entry && typeof entry === "object" && entry.type === "text" ? String(entry.text ?? "") : "").join("");
|
|
1981
|
-
if (nextText.length > assistantText.length) {
|
|
1982
|
-
assistantText = nextText;
|
|
1983
|
-
appendRunTimeline(context.projectRoot, input.runId, {
|
|
1984
|
-
id: assistantMessageId,
|
|
1985
|
-
type: "assistant_message",
|
|
1986
|
-
text: assistantText,
|
|
1987
|
-
state: "streaming",
|
|
1988
|
-
createdAt: new Date().toISOString()
|
|
1989
|
-
});
|
|
1990
|
-
emitServerRunEvent({ type: "timeline", runId: input.runId });
|
|
1991
|
-
}
|
|
1992
|
-
return;
|
|
1993
|
-
}
|
|
1994
|
-
if (providerLogs.length > 0) {
|
|
1995
|
-
return;
|
|
1996
|
-
}
|
|
1997
|
-
} catch {}
|
|
1998
|
-
appendRunLog(context.projectRoot, input.runId, {
|
|
1999
|
-
id: nextRunLogId(),
|
|
2000
|
-
title: verificationStarted ? "Completion verification" : "Agent output",
|
|
2001
|
-
detail: trimmed,
|
|
2002
|
-
tone: "info",
|
|
2003
|
-
status: reviewStarted ? "reviewing" : verificationStarted ? "validating" : "running",
|
|
2004
|
-
createdAt: new Date().toISOString()
|
|
2005
|
-
});
|
|
2006
|
-
emitServerRunEvent({ type: "log", runId: input.runId, title: verificationStarted ? "Completion verification" : "Agent output" });
|
|
2007
|
-
};
|
|
2008
|
-
let currentPrompt = prompt;
|
|
2009
|
-
let exit = null;
|
|
2010
|
-
let reviewFailureDetail = null;
|
|
2011
|
-
const stderrLines = [];
|
|
2012
|
-
const piAcceptedArtifactExitGraceMs = resolvePiAcceptedArtifactExitGraceMs(childEnv);
|
|
2013
|
-
if (resumeMode && ["validating", "reviewing"].includes(resumePreviousStatus)) {
|
|
2014
|
-
appendRunLog(context.projectRoot, input.runId, {
|
|
2015
|
-
id: `log:${input.runId}:resume-closeout-phase`,
|
|
2016
|
-
title: "Resume continuing from closeout phase",
|
|
2017
|
-
detail: `Previous run status was ${resumePreviousStatus}; skipping agent relaunch and continuing validation/PR/merge closeout for the same run.`,
|
|
2018
|
-
tone: "info",
|
|
2019
|
-
status: resumePreviousStatus,
|
|
2020
|
-
createdAt: new Date().toISOString()
|
|
2021
|
-
});
|
|
2022
|
-
emitServerRunEvent({ type: "log", runId: input.runId, title: "Resume continuing from closeout phase" });
|
|
2023
|
-
exit = { code: 0, signal: null };
|
|
2024
|
-
} else if (resumeMode && latestRuntimeWorkspace) {
|
|
2025
|
-
const acceptedArtifactState = readTaskRunAcceptedArtifactState({
|
|
2026
|
-
taskId: input.taskId ?? runtimeTaskId,
|
|
2027
|
-
workspaceDir: latestRuntimeWorkspace
|
|
2028
|
-
});
|
|
2029
|
-
if (acceptedArtifactState.accepted) {
|
|
2030
|
-
appendRunLog(context.projectRoot, input.runId, {
|
|
2031
|
-
id: `log:${input.runId}:resume-accepted-artifacts`,
|
|
2032
|
-
title: "Resume found accepted artifacts; continuing closeout",
|
|
2033
|
-
detail: acceptedArtifactState.reason ?? "Accepted task artifacts are present from the previous run process.",
|
|
2034
|
-
tone: "info",
|
|
2035
|
-
status: "validating",
|
|
2036
|
-
createdAt: new Date().toISOString()
|
|
2037
|
-
});
|
|
2038
|
-
emitServerRunEvent({ type: "log", runId: input.runId, title: "Resume found accepted artifacts; continuing closeout" });
|
|
2039
|
-
exit = { code: 0, signal: null };
|
|
2040
|
-
}
|
|
2041
|
-
}
|
|
2042
|
-
for (let attempt = 1;!exit && attempt <= maxAttempts; attempt += 1) {
|
|
2043
|
-
const attemptHostAgentCommand = buildHostAgentCommand(currentPrompt);
|
|
2044
|
-
const child = spawn(attemptHostAgentCommand[0], attemptHostAgentCommand.slice(1), {
|
|
2045
|
-
cwd: context.projectRoot,
|
|
2046
|
-
env: childEnv,
|
|
2047
|
-
stdio: ["pipe", "pipe", "pipe"]
|
|
2048
|
-
});
|
|
2049
|
-
const forwardSigterm = () => {
|
|
2050
|
-
try {
|
|
2051
|
-
child.kill("SIGTERM");
|
|
2052
|
-
} catch {}
|
|
2053
|
-
};
|
|
2054
|
-
process.once("SIGTERM", forwardSigterm);
|
|
2055
|
-
if (input.runtimeAdapter === "claude-code" || input.runtimeAdapter === "pi") {
|
|
2056
|
-
child.stdin.write(currentPrompt);
|
|
2057
|
-
child.stdin.end();
|
|
2058
|
-
} else {
|
|
2059
|
-
child.stdin.end();
|
|
2060
|
-
}
|
|
2061
|
-
const stdout = createLineInterface({ input: child.stdout });
|
|
2062
|
-
stdout.on("line", handleAgentStdoutLine);
|
|
2063
|
-
const stderr = createLineInterface({ input: child.stderr });
|
|
2064
|
-
stderr.on("line", (line) => {
|
|
2065
|
-
const trimmed = line.trim();
|
|
2066
|
-
if (!trimmed)
|
|
2067
|
-
return;
|
|
2068
|
-
stderrLines.push(trimmed);
|
|
2069
|
-
appendRunLog(context.projectRoot, input.runId, {
|
|
2070
|
-
id: nextRunLogId(),
|
|
2071
|
-
title: "Agent stderr",
|
|
2072
|
-
detail: trimmed,
|
|
2073
|
-
tone: "error",
|
|
2074
|
-
status: reviewStarted ? "reviewing" : verificationStarted ? "validating" : "running",
|
|
2075
|
-
createdAt: new Date().toISOString()
|
|
2076
|
-
});
|
|
2077
|
-
emitServerRunEvent({ type: "log", runId: input.runId, title: "Agent stderr" });
|
|
2078
|
-
});
|
|
2079
|
-
let acceptedArtifactExit = false;
|
|
2080
|
-
let acceptedArtifactObservedAt = null;
|
|
2081
|
-
let acceptedArtifactPollTimer = null;
|
|
2082
|
-
let acceptedArtifactKillTimer = null;
|
|
2083
|
-
const attemptExit = await new Promise((resolve7) => {
|
|
2084
|
-
let settled = false;
|
|
2085
|
-
const settle = (result) => {
|
|
2086
|
-
if (settled)
|
|
2087
|
-
return;
|
|
2088
|
-
settled = true;
|
|
2089
|
-
if (acceptedArtifactPollTimer)
|
|
2090
|
-
clearInterval(acceptedArtifactPollTimer);
|
|
2091
|
-
resolve7(result);
|
|
2092
|
-
};
|
|
2093
|
-
const pollAcceptedArtifacts = () => {
|
|
2094
|
-
const artifactState = readTaskRunAcceptedArtifactState({
|
|
2095
|
-
taskId: input.taskId ?? runtimeTaskId,
|
|
2096
|
-
workspaceDir: latestRuntimeWorkspace,
|
|
2097
|
-
artifactNotBeforeMs: Date.parse(startedAt)
|
|
2098
|
-
});
|
|
2099
|
-
if (!artifactState.accepted) {
|
|
2100
|
-
acceptedArtifactObservedAt = null;
|
|
2101
|
-
return;
|
|
2102
|
-
}
|
|
2103
|
-
acceptedArtifactObservedAt ??= Date.now();
|
|
2104
|
-
if (Date.now() - acceptedArtifactObservedAt < piAcceptedArtifactExitGraceMs || acceptedArtifactExit) {
|
|
2105
|
-
return;
|
|
2106
|
-
}
|
|
2107
|
-
acceptedArtifactExit = true;
|
|
2108
|
-
const detail = [
|
|
2109
|
-
artifactState.reason ?? "Rig accepted task artifacts are present.",
|
|
2110
|
-
`Pi has not exited after ${piAcceptedArtifactExitGraceMs}ms; terminating the stale Pi process so Rig can continue PR/issue closeout.`
|
|
2111
|
-
].join(" ");
|
|
2112
|
-
appendRunLog(context.projectRoot, input.runId, {
|
|
2113
|
-
id: `log:${input.runId}:pi-accepted-artifacts-exit`,
|
|
2114
|
-
title: "Pi accepted artifacts; continuing closeout",
|
|
2115
|
-
detail,
|
|
2116
|
-
tone: "info",
|
|
2117
|
-
status: "running",
|
|
2118
|
-
createdAt: new Date().toISOString()
|
|
2119
|
-
});
|
|
2120
|
-
emitServerRunEvent({ type: "log", runId: input.runId, title: "Pi accepted artifacts; continuing closeout" });
|
|
2121
|
-
try {
|
|
2122
|
-
child.kill("SIGTERM");
|
|
2123
|
-
} catch {}
|
|
2124
|
-
acceptedArtifactKillTimer = setTimeout(() => {
|
|
2125
|
-
try {
|
|
2126
|
-
child.kill("SIGKILL");
|
|
2127
|
-
} catch {}
|
|
2128
|
-
settle({ code: 0, signal: "SIGKILL" });
|
|
2129
|
-
}, 5000);
|
|
2130
|
-
};
|
|
2131
|
-
child.once("error", (error) => {
|
|
2132
|
-
if (acceptedArtifactKillTimer)
|
|
2133
|
-
clearTimeout(acceptedArtifactKillTimer);
|
|
2134
|
-
console.error(`[rig] agent process error: ${error.message}`);
|
|
2135
|
-
settle({ code: 1, signal: null, error });
|
|
2136
|
-
});
|
|
2137
|
-
child.once("close", (code, signal) => {
|
|
2138
|
-
if (acceptedArtifactKillTimer)
|
|
2139
|
-
clearTimeout(acceptedArtifactKillTimer);
|
|
2140
|
-
settle(acceptedArtifactExit ? { code: 0, signal: signal ?? "SIGTERM" } : { code, signal });
|
|
2141
|
-
});
|
|
2142
|
-
if (input.runtimeAdapter === "pi") {
|
|
2143
|
-
acceptedArtifactPollTimer = setInterval(pollAcceptedArtifacts, 5000);
|
|
2144
|
-
acceptedArtifactPollTimer.unref?.();
|
|
2145
|
-
}
|
|
2146
|
-
});
|
|
2147
|
-
await finalizeTaskRunSnapshot({
|
|
2148
|
-
snapshotSidecarPromise,
|
|
2149
|
-
latestProviderCommand,
|
|
2150
|
-
hostAgentCommand: attemptHostAgentCommand,
|
|
2151
|
-
exit: attemptExit
|
|
2152
|
-
});
|
|
2153
|
-
const pendingLogs = input.runtimeAdapter === "codex" ? flushPendingCodexToolUseLogs({
|
|
2154
|
-
runId: input.runId,
|
|
2155
|
-
status: typeof attemptExit.code === "number" && attemptExit.code === 0 ? "completed" : "failed",
|
|
2156
|
-
pendingToolUses: pendingCodexToolUses
|
|
2157
|
-
}) : flushPendingClaudeToolUseLogs({
|
|
2158
|
-
runId: input.runId,
|
|
2159
|
-
status: typeof attemptExit.code === "number" && attemptExit.code === 0 ? "completed" : "failed",
|
|
2160
|
-
pendingToolUses: pendingClaudeToolUses
|
|
2161
|
-
});
|
|
2162
|
-
for (const pendingLog of pendingLogs) {
|
|
2163
|
-
appendRunLog(context.projectRoot, input.runId, pendingLog);
|
|
2164
|
-
appendToolTimelineFromLog({ projectRoot: context.projectRoot, runId: input.runId, log: pendingLog });
|
|
2165
|
-
emitServerRunEvent({ type: "log", runId: input.runId, title: pendingLog.title });
|
|
2166
|
-
if (pendingLog.title === "Tool activity")
|
|
2167
|
-
emitServerRunEvent({ type: "timeline", runId: input.runId });
|
|
2168
|
-
}
|
|
2169
|
-
process.off("SIGTERM", forwardSigterm);
|
|
2170
|
-
if (attemptExit.error) {
|
|
2171
|
-
throw new CliError2(`Task run failed to start: ${attemptExit.error.message}`, 1);
|
|
2172
|
-
}
|
|
2173
|
-
const retryContext = resolveTaskRunRetryContext({
|
|
2174
|
-
projectRoot: context.projectRoot,
|
|
2175
|
-
taskId: input.taskId ?? null,
|
|
2176
|
-
workspaceDir: latestRuntimeWorkspace,
|
|
2177
|
-
attempt,
|
|
2178
|
-
maxAttempts,
|
|
2179
|
-
basePrompt: prompt
|
|
2180
|
-
});
|
|
2181
|
-
if (retryContext.shouldRetry && retryContext.nextPrompt) {
|
|
2182
|
-
const failureDetail = retryContext.failureDetail ?? summarizeValidationFailure(context.projectRoot, input.taskId ?? null) ?? "Rig validation failed.";
|
|
2183
|
-
const retrySteering = buildPiValidationRetrySteeringPrompt({
|
|
2184
|
-
taskId: input.taskId ?? runtimeTaskId,
|
|
2185
|
-
attempt,
|
|
2186
|
-
maxAttempts,
|
|
2187
|
-
failureDetail,
|
|
2188
|
-
validationOutput: summarizeValidationFailure(context.projectRoot, input.taskId ?? null)
|
|
2189
|
-
});
|
|
2190
|
-
currentPrompt = [retryContext.nextPrompt, "", "Rig Pi steering message:", retrySteering].join(`
|
|
2191
|
-
`);
|
|
2192
|
-
reviewFailureDetail = failureDetail;
|
|
2193
|
-
patchAuthorityRun(context.projectRoot, input.runId, {
|
|
2194
|
-
status: "validating",
|
|
2195
|
-
completedAt: null,
|
|
2196
|
-
errorText: null
|
|
2197
|
-
});
|
|
2198
|
-
appendPiStageLog({
|
|
2199
|
-
projectRoot: context.projectRoot,
|
|
2200
|
-
runId: input.runId,
|
|
2201
|
-
stage: "Validate",
|
|
2202
|
-
detail: failureDetail,
|
|
2203
|
-
tone: "error",
|
|
2204
|
-
status: "validating"
|
|
2205
|
-
});
|
|
2206
|
-
appendRunLog(context.projectRoot, input.runId, {
|
|
2207
|
-
id: `log:${input.runId}:retry:${attempt + 1}`,
|
|
2208
|
-
title: `Steering Pi to retry validation (attempt ${attempt + 1}/${maxAttempts})`,
|
|
2209
|
-
detail: retrySteering,
|
|
2210
|
-
tone: "info",
|
|
2211
|
-
status: "running",
|
|
2212
|
-
createdAt: new Date().toISOString()
|
|
2213
|
-
});
|
|
2214
|
-
emitServerRunEvent({
|
|
2215
|
-
type: "status",
|
|
2216
|
-
runId: input.runId,
|
|
2217
|
-
status: "validating",
|
|
2218
|
-
detail: failureDetail
|
|
2219
|
-
});
|
|
2220
|
-
emitServerRunEvent({ type: "log", runId: input.runId, title: "Validate failed" });
|
|
2221
|
-
emitServerRunEvent({ type: "log", runId: input.runId, title: `Steering Pi to retry validation (attempt ${attempt + 1}/${maxAttempts})` });
|
|
2222
|
-
continue;
|
|
2223
|
-
}
|
|
2224
|
-
exit = attemptExit;
|
|
2225
|
-
reviewFailureDetail = retryContext.failureDetail;
|
|
2226
|
-
break;
|
|
2227
|
-
}
|
|
2228
|
-
if (!exit) {
|
|
2229
|
-
throw new CliError2(`Task run for ${runtimeTaskId} exhausted ${maxAttempts} attempts without a terminal result.`, 1);
|
|
2230
|
-
}
|
|
2231
|
-
if (exit.error) {
|
|
2232
|
-
throw new CliError2(`Task run failed to start: ${exit.error.message}`, 1);
|
|
2233
|
-
}
|
|
2234
|
-
if (assistantText.trim()) {
|
|
2235
|
-
appendRunTimeline(context.projectRoot, input.runId, {
|
|
2236
|
-
id: assistantMessageId,
|
|
2237
|
-
type: "assistant_message",
|
|
2238
|
-
text: assistantText,
|
|
2239
|
-
state: "completed",
|
|
2240
|
-
createdAt: new Date().toISOString(),
|
|
2241
|
-
completedAt: new Date().toISOString()
|
|
2242
|
-
});
|
|
2243
|
-
emitServerRunEvent({ type: "timeline", runId: input.runId });
|
|
2244
|
-
}
|
|
2245
|
-
if (exit.code !== 0 || reviewFailureDetail) {
|
|
2246
|
-
const failedAt = new Date().toISOString();
|
|
2247
|
-
const failureDetail = reviewFailureDetail ?? summarizeValidationFailure(context.projectRoot, input.taskId ?? null) ?? summarizeTaskRunProcessFailure({
|
|
2248
|
-
exitCode: exit.code,
|
|
2249
|
-
signal: exit.signal,
|
|
2250
|
-
stderrLines
|
|
2251
|
-
});
|
|
2252
|
-
if (verificationAction && !reviewStarted) {
|
|
2253
|
-
verificationAction.fail(failureDetail);
|
|
2254
|
-
}
|
|
2255
|
-
if (reviewAction) {
|
|
2256
|
-
reviewAction.fail(failureDetail);
|
|
2257
|
-
}
|
|
2258
|
-
let terminalFailureDetail = failureDetail;
|
|
2259
|
-
const terminalRunStatus = reviewFailureDetail ? "needs_attention" : "failed";
|
|
2260
|
-
try {
|
|
2261
|
-
await updateTaskSourceAfterDriverRun(context.projectRoot, input.runId, input.taskId, sourceTask, "failed", terminalRunStatus === "needs_attention" ? "Rig task run needs attention." : "Rig task run failed.", {
|
|
2262
|
-
latestRuntimeWorkspace,
|
|
2263
|
-
latestLogsDir,
|
|
2264
|
-
latestSessionDir,
|
|
2265
|
-
errorText: failureDetail
|
|
2266
|
-
});
|
|
2267
|
-
} catch (error) {
|
|
2268
|
-
terminalFailureDetail = `${failureDetail}
|
|
2269
|
-
Failed to update task source for ${input.taskId ?? runtimeTaskId} to failed: ${error instanceof Error ? error.message : String(error)}`;
|
|
2270
|
-
}
|
|
2271
|
-
patchAuthorityRun(context.projectRoot, input.runId, {
|
|
2272
|
-
status: terminalRunStatus,
|
|
2273
|
-
completedAt: failedAt,
|
|
2274
|
-
errorText: terminalFailureDetail
|
|
2275
|
-
});
|
|
2276
|
-
appendRunLog(context.projectRoot, input.runId, {
|
|
2277
|
-
id: `log:${input.runId}:${terminalRunStatus}`,
|
|
2278
|
-
title: terminalRunStatus === "needs_attention" ? "Task run needs attention" : "Task run failed",
|
|
2279
|
-
detail: terminalFailureDetail,
|
|
2280
|
-
tone: "error",
|
|
2281
|
-
status: terminalRunStatus,
|
|
2282
|
-
createdAt: failedAt
|
|
2283
|
-
});
|
|
2284
|
-
emitServerRunEvent({
|
|
2285
|
-
type: "failed",
|
|
2286
|
-
runId: input.runId,
|
|
2287
|
-
error: terminalFailureDetail
|
|
2288
|
-
});
|
|
2289
|
-
throw new CliError2(terminalFailureDetail, exit.code ?? 1);
|
|
2290
|
-
}
|
|
2291
|
-
if (planningClassification.planningRequired) {
|
|
2292
|
-
const planWorkspace = latestRuntimeWorkspace ?? context.projectRoot;
|
|
2293
|
-
const expectedPlanPath = resolve6(planWorkspace, planningArtifactPath);
|
|
2294
|
-
if (!existsSync4(expectedPlanPath)) {
|
|
2295
|
-
const failedAt = new Date().toISOString();
|
|
2296
|
-
const failureDetail = `Planning was required (${planningClassification.reason}) but ${planningArtifactPath} was not written before implementation completed.`;
|
|
2297
|
-
patchAuthorityRun(context.projectRoot, input.runId, {
|
|
2298
|
-
status: "needs_attention",
|
|
2299
|
-
completedAt: failedAt,
|
|
2300
|
-
errorText: failureDetail
|
|
2301
|
-
});
|
|
2302
|
-
appendRunLog(context.projectRoot, input.runId, {
|
|
2303
|
-
id: `log:${input.runId}:plan-artifact-missing`,
|
|
2304
|
-
title: "Required plan artifact missing",
|
|
2305
|
-
detail: failureDetail,
|
|
2306
|
-
tone: "error",
|
|
2307
|
-
status: "needs_attention",
|
|
2308
|
-
createdAt: failedAt
|
|
2309
|
-
});
|
|
2310
|
-
emitServerRunEvent({ type: "failed", runId: input.runId, error: failureDetail });
|
|
2311
|
-
throw new CliError2(failureDetail, 1);
|
|
2312
|
-
}
|
|
2313
|
-
}
|
|
2314
|
-
if (process.env.RIG_SERVER_OWNS_CLOSEOUT === "1") {
|
|
2315
|
-
appendPiStageLog({
|
|
2316
|
-
projectRoot: context.projectRoot,
|
|
2317
|
-
runId: input.runId,
|
|
2318
|
-
stage: "Validate",
|
|
2319
|
-
detail: "Rig validation accepted the task run; server will continue PR/review/merge closeout.",
|
|
2320
|
-
status: "completed"
|
|
2321
|
-
});
|
|
2322
|
-
if (verificationAction && !reviewStarted) {
|
|
2323
|
-
verificationAction.complete("Completion verification checks finished.");
|
|
2324
|
-
}
|
|
2325
|
-
if (!reviewAction) {
|
|
2326
|
-
promoteToReviewing("Server-owned closeout is queued.");
|
|
2327
|
-
}
|
|
2328
|
-
if (reviewAction) {
|
|
2329
|
-
reviewAction.complete("Provider work accepted; server-owned closeout requested.");
|
|
2330
|
-
}
|
|
2331
|
-
const requestedAt = new Date().toISOString();
|
|
2332
|
-
patchAuthorityRun(context.projectRoot, input.runId, {
|
|
2333
|
-
status: "reviewing",
|
|
2334
|
-
completedAt: null,
|
|
2335
|
-
errorText: null,
|
|
2336
|
-
serverCloseout: {
|
|
2337
|
-
status: "pending",
|
|
2338
|
-
phase: "queued",
|
|
2339
|
-
requestedAt,
|
|
2340
|
-
updatedAt: requestedAt,
|
|
2341
|
-
runtimeWorkspace: latestRuntimeWorkspace,
|
|
2342
|
-
branch: latestRuntimeBranch,
|
|
2343
|
-
taskId: input.taskId ?? runtimeTaskId
|
|
2344
|
-
}
|
|
2345
|
-
});
|
|
2346
|
-
appendRunLog(context.projectRoot, input.runId, {
|
|
2347
|
-
id: `log:${input.runId}:server-closeout-requested`,
|
|
2348
|
-
title: "Server-owned closeout requested",
|
|
2349
|
-
detail: "The CLI provider worker finished validation and handed commit/PR/review/merge closeout back to the Rig server.",
|
|
2350
|
-
tone: "info",
|
|
2351
|
-
status: "reviewing",
|
|
2352
|
-
createdAt: requestedAt,
|
|
2353
|
-
payload: { runtimeWorkspace: latestRuntimeWorkspace, branch: latestRuntimeBranch }
|
|
2354
|
-
});
|
|
2355
|
-
emitServerRunEvent({ type: "log", runId: input.runId, title: "Server-owned closeout requested" });
|
|
2356
|
-
emitServerRunEvent({ type: "status", runId: input.runId, status: "reviewing", detail: "Server-owned closeout requested." });
|
|
2357
|
-
await context.emitEvent("command.finished", {
|
|
2358
|
-
command: [
|
|
2359
|
-
"rig",
|
|
2360
|
-
"server",
|
|
2361
|
-
"task-run",
|
|
2362
|
-
...input.taskId ? ["--task", input.taskId] : [],
|
|
2363
|
-
...input.title ? ["--title", input.title] : []
|
|
2364
|
-
],
|
|
2365
|
-
formattedCommand: input.taskId ? `rig server task-run --task ${input.taskId}` : `rig server task-run --title ${JSON.stringify(input.title ?? `Run ${input.runId}`)}`,
|
|
2366
|
-
exitCode: 0,
|
|
2367
|
-
durationMs: 0,
|
|
2368
|
-
startedAt,
|
|
2369
|
-
finishedAt: requestedAt
|
|
2370
|
-
});
|
|
2371
|
-
process.exit(0);
|
|
2372
|
-
}
|
|
2373
|
-
const runPiPrFeedbackFix = async (message) => {
|
|
2374
|
-
appendPiStageLog({
|
|
2375
|
-
projectRoot: context.projectRoot,
|
|
2376
|
-
runId: input.runId,
|
|
2377
|
-
stage: "Implement",
|
|
2378
|
-
detail: "Pi is applying PR review/CI feedback.",
|
|
2379
|
-
status: "running"
|
|
2380
|
-
});
|
|
2381
|
-
appendRunLog(context.projectRoot, input.runId, {
|
|
2382
|
-
id: `log:${input.runId}:pr-feedback-pi:${Date.now()}`,
|
|
2383
|
-
title: "Steering Pi from PR feedback",
|
|
2384
|
-
detail: message,
|
|
2385
|
-
tone: "info",
|
|
2386
|
-
status: "reviewing",
|
|
2387
|
-
createdAt: new Date().toISOString()
|
|
2388
|
-
});
|
|
2389
|
-
emitServerRunEvent({ type: "log", runId: input.runId, title: "Steering Pi from PR feedback" });
|
|
2390
|
-
const feedbackCommand = buildHostAgentCommand(message);
|
|
2391
|
-
const child = spawn(feedbackCommand[0], feedbackCommand.slice(1), {
|
|
2392
|
-
cwd: latestRuntimeWorkspace ?? context.projectRoot,
|
|
2393
|
-
env: childEnv,
|
|
2394
|
-
stdio: ["pipe", "pipe", "pipe"]
|
|
2395
|
-
});
|
|
2396
|
-
if (input.runtimeAdapter === "claude-code" || input.runtimeAdapter === "pi") {
|
|
2397
|
-
child.stdin.write(message);
|
|
2398
|
-
}
|
|
2399
|
-
child.stdin.end();
|
|
2400
|
-
const feedbackAssistantMessageId = `message:${input.runId}:pr-feedback:${Date.now()}:assistant`;
|
|
2401
|
-
let feedbackAssistantText = "";
|
|
2402
|
-
const feedbackPendingToolUses = new Map;
|
|
2403
|
-
const stdout = createLineInterface({ input: child.stdout });
|
|
2404
|
-
stdout.on("line", (line) => {
|
|
2405
|
-
const trimmed = line.trim();
|
|
2406
|
-
if (!trimmed)
|
|
2407
|
-
return;
|
|
2408
|
-
try {
|
|
2409
|
-
const record = JSON.parse(trimmed);
|
|
2410
|
-
const providerLogs = buildClaudeLogsFromRecord({
|
|
2411
|
-
runId: input.runId,
|
|
2412
|
-
record,
|
|
2413
|
-
createdAtFallback: new Date().toISOString(),
|
|
2414
|
-
status: "reviewing",
|
|
2415
|
-
pendingToolUses: feedbackPendingToolUses
|
|
2416
|
-
});
|
|
2417
|
-
for (const providerLog of providerLogs) {
|
|
2418
|
-
appendRunLog(context.projectRoot, input.runId, providerLog);
|
|
2419
|
-
appendToolTimelineFromLog({ projectRoot: context.projectRoot, runId: input.runId, log: providerLog });
|
|
2420
|
-
emitServerRunEvent({ type: "log", runId: input.runId, title: providerLog.title });
|
|
2421
|
-
if (providerLog.title === "Tool activity")
|
|
2422
|
-
emitServerRunEvent({ type: "timeline", runId: input.runId });
|
|
2423
|
-
}
|
|
2424
|
-
const nextFeedbackAssistantText = appendAssistantTimelineFromRecord({
|
|
2425
|
-
projectRoot: context.projectRoot,
|
|
2426
|
-
runId: input.runId,
|
|
2427
|
-
messageId: feedbackAssistantMessageId,
|
|
2428
|
-
record,
|
|
2429
|
-
assistantText: feedbackAssistantText
|
|
2430
|
-
});
|
|
2431
|
-
const hadAssistantDelta = nextFeedbackAssistantText !== feedbackAssistantText;
|
|
2432
|
-
if (hadAssistantDelta) {
|
|
2433
|
-
feedbackAssistantText = nextFeedbackAssistantText;
|
|
2434
|
-
emitServerRunEvent({ type: "timeline", runId: input.runId });
|
|
2435
|
-
}
|
|
2436
|
-
if (providerLogs.length > 0 || hadAssistantDelta)
|
|
2437
|
-
return;
|
|
2438
|
-
} catch {}
|
|
2439
|
-
appendRunLog(context.projectRoot, input.runId, {
|
|
2440
|
-
id: nextRunLogId(),
|
|
2441
|
-
title: "Pi PR feedback fix output",
|
|
2442
|
-
detail: trimmed,
|
|
2443
|
-
tone: "info",
|
|
2444
|
-
status: "reviewing",
|
|
2445
|
-
createdAt: new Date().toISOString()
|
|
2446
|
-
});
|
|
2447
|
-
emitServerRunEvent({ type: "log", runId: input.runId, title: "Pi PR feedback fix output" });
|
|
2448
|
-
});
|
|
2449
|
-
const stderr = createLineInterface({ input: child.stderr });
|
|
2450
|
-
stderr.on("line", (line) => {
|
|
2451
|
-
const trimmed = line.trim();
|
|
2452
|
-
if (!trimmed)
|
|
2453
|
-
return;
|
|
2454
|
-
appendRunLog(context.projectRoot, input.runId, {
|
|
2455
|
-
id: nextRunLogId(),
|
|
2456
|
-
title: "Pi PR feedback fix stderr",
|
|
2457
|
-
detail: trimmed,
|
|
2458
|
-
tone: "error",
|
|
2459
|
-
status: "reviewing",
|
|
2460
|
-
createdAt: new Date().toISOString()
|
|
2461
|
-
});
|
|
2462
|
-
emitServerRunEvent({ type: "log", runId: input.runId, title: "Pi PR feedback fix stderr" });
|
|
2463
|
-
});
|
|
2464
|
-
const exitCode = await new Promise((resolve7) => {
|
|
2465
|
-
child.once("error", () => resolve7(1));
|
|
2466
|
-
child.once("close", (code) => resolve7(code ?? 1));
|
|
2467
|
-
});
|
|
2468
|
-
for (const pendingLog of flushPendingClaudeToolUseLogs({
|
|
2469
|
-
runId: input.runId,
|
|
2470
|
-
status: exitCode === 0 ? "completed" : "failed",
|
|
2471
|
-
pendingToolUses: feedbackPendingToolUses
|
|
2472
|
-
})) {
|
|
2473
|
-
appendRunLog(context.projectRoot, input.runId, pendingLog);
|
|
2474
|
-
appendToolTimelineFromLog({ projectRoot: context.projectRoot, runId: input.runId, log: pendingLog });
|
|
2475
|
-
emitServerRunEvent({ type: "log", runId: input.runId, title: pendingLog.title });
|
|
2476
|
-
emitServerRunEvent({ type: "timeline", runId: input.runId });
|
|
2477
|
-
}
|
|
2478
|
-
if (feedbackAssistantText.trim()) {
|
|
2479
|
-
appendRunTimeline(context.projectRoot, input.runId, {
|
|
2480
|
-
id: feedbackAssistantMessageId,
|
|
2481
|
-
type: "assistant_message",
|
|
2482
|
-
text: feedbackAssistantText,
|
|
2483
|
-
state: "completed",
|
|
2484
|
-
createdAt: new Date().toISOString(),
|
|
2485
|
-
completedAt: new Date().toISOString()
|
|
2486
|
-
});
|
|
2487
|
-
emitServerRunEvent({ type: "timeline", runId: input.runId });
|
|
2488
|
-
}
|
|
2489
|
-
if (exitCode !== 0) {
|
|
2490
|
-
throw new Error(`Pi PR feedback fix failed with exit code ${exitCode}.`);
|
|
2491
|
-
}
|
|
2492
|
-
};
|
|
2493
|
-
try {
|
|
2494
|
-
appendPiStageLog({
|
|
2495
|
-
projectRoot: context.projectRoot,
|
|
2496
|
-
runId: input.runId,
|
|
2497
|
-
stage: "Validate",
|
|
2498
|
-
detail: "Rig validation accepted the task run.",
|
|
2499
|
-
status: "completed"
|
|
2500
|
-
});
|
|
2501
|
-
const postValidation = await runTaskRunPostValidationLifecycle({
|
|
2502
|
-
projectRoot: context.projectRoot,
|
|
2503
|
-
runId: input.runId,
|
|
2504
|
-
taskId: input.taskId,
|
|
2505
|
-
runtimeTaskId,
|
|
2506
|
-
runtimeWorkspace: latestRuntimeWorkspace,
|
|
2507
|
-
branch: latestRuntimeBranch,
|
|
2508
|
-
config: automationConfig,
|
|
2509
|
-
sourceTask,
|
|
2510
|
-
steerPi: input.runtimeAdapter === "pi" ? runPiPrFeedbackFix : undefined,
|
|
2511
|
-
appendStage: (stage, detail, status, tone) => appendPiStageLog({
|
|
2512
|
-
projectRoot: context.projectRoot,
|
|
2513
|
-
runId: input.runId,
|
|
2514
|
-
stage,
|
|
2515
|
-
detail,
|
|
2516
|
-
status,
|
|
2517
|
-
tone
|
|
2518
|
-
})
|
|
2519
|
-
});
|
|
2520
|
-
if (postValidation.status === "needs_attention") {
|
|
2521
|
-
const failureDetail = postValidation.pr?.actionableFeedback.join(`
|
|
2522
|
-
`) || "PR automation needs attention.";
|
|
2523
|
-
const failedAt = new Date().toISOString();
|
|
2524
|
-
patchAuthorityRun(context.projectRoot, input.runId, {
|
|
2525
|
-
status: "needs_attention",
|
|
2526
|
-
completedAt: failedAt,
|
|
2527
|
-
errorText: failureDetail
|
|
2528
|
-
});
|
|
2529
|
-
emitServerRunEvent({ type: "failed", runId: input.runId, error: failureDetail });
|
|
2530
|
-
throw new CliError2(failureDetail, 1);
|
|
2531
|
-
}
|
|
2532
|
-
} catch (error) {
|
|
2533
|
-
if (error instanceof CliError2) {
|
|
2534
|
-
throw error;
|
|
2535
|
-
}
|
|
2536
|
-
const failureDetail = `Failed to complete PR/issue closeout for ${input.taskId ?? runtimeTaskId}: ${error instanceof Error ? error.message : String(error)}`;
|
|
2537
|
-
const failedAt = new Date().toISOString();
|
|
2538
|
-
patchAuthorityRun(context.projectRoot, input.runId, {
|
|
2539
|
-
status: "failed",
|
|
2540
|
-
completedAt: failedAt,
|
|
2541
|
-
errorText: failureDetail
|
|
2542
|
-
});
|
|
2543
|
-
appendRunLog(context.projectRoot, input.runId, {
|
|
2544
|
-
id: `log:${input.runId}:pr-closeout-failed`,
|
|
2545
|
-
title: "PR/issue closeout failed",
|
|
2546
|
-
detail: failureDetail,
|
|
2547
|
-
tone: "error",
|
|
2548
|
-
status: "failed",
|
|
2549
|
-
createdAt: failedAt
|
|
2550
|
-
});
|
|
2551
|
-
emitServerRunEvent({ type: "failed", runId: input.runId, error: failureDetail });
|
|
2552
|
-
throw new CliError2(failureDetail, 1);
|
|
2553
|
-
}
|
|
2554
|
-
if (verificationAction && !reviewStarted) {
|
|
2555
|
-
verificationAction.complete("Completion verification checks finished.");
|
|
2556
|
-
}
|
|
2557
|
-
if (!reviewAction) {
|
|
2558
|
-
promoteToReviewing("Task finished; finalizing run state.");
|
|
2559
|
-
}
|
|
2560
|
-
if (reviewAction) {
|
|
2561
|
-
reviewAction.complete("Run marked completed.");
|
|
2562
|
-
}
|
|
2563
|
-
patchAuthorityRun(context.projectRoot, input.runId, {
|
|
2564
|
-
status: "completed",
|
|
2565
|
-
completedAt: new Date().toISOString()
|
|
2566
|
-
});
|
|
2567
|
-
emitServerRunEvent({ type: "completed", runId: input.runId });
|
|
2568
|
-
await context.emitEvent("command.finished", {
|
|
2569
|
-
command: [
|
|
2570
|
-
"rig",
|
|
2571
|
-
"server",
|
|
2572
|
-
"task-run",
|
|
2573
|
-
...input.taskId ? ["--task", input.taskId] : [],
|
|
2574
|
-
...input.title ? ["--title", input.title] : []
|
|
2575
|
-
],
|
|
2576
|
-
formattedCommand: input.taskId ? `rig server task-run --task ${input.taskId}` : `rig server task-run --title ${JSON.stringify(input.title ?? `Run ${input.runId}`)}`,
|
|
2577
|
-
exitCode: 0,
|
|
2578
|
-
durationMs: 0,
|
|
2579
|
-
startedAt,
|
|
2580
|
-
finishedAt: new Date().toISOString()
|
|
2581
|
-
});
|
|
2582
|
-
}
|
|
2583
|
-
export {
|
|
2584
|
-
taskRunStageLogId,
|
|
2585
|
-
summarizeTaskRunProcessFailure,
|
|
2586
|
-
runTaskRunPostValidationLifecycle,
|
|
2587
|
-
resolveTaskRunAutomationLimits,
|
|
2588
|
-
readTaskRunAcceptedArtifactState,
|
|
2589
|
-
executeRigOwnedTaskRun,
|
|
2590
|
-
createRunLogIdFactory,
|
|
2591
|
-
classifyValidationRetryOutcome,
|
|
2592
|
-
classifyPlanningNeed,
|
|
2593
|
-
classifyCompletionVerificationLine,
|
|
2594
|
-
canonicalPiRunStages,
|
|
2595
|
-
buildTaskRunReviewEnv,
|
|
2596
|
-
buildPiValidationRetrySteeringPrompt,
|
|
2597
|
-
buildPiRigBridgeEnv,
|
|
2598
|
-
buildDirtyBaselineHandshakeEnv,
|
|
2599
|
-
applyDirtyBaselineSnapshot
|
|
2600
|
-
};
|