@tea-agent/loop-agent 0.35.2 → 0.35.3
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/AGENTS.md +2 -0
- package/CHANGELOG.md +31 -0
- package/README.md +1 -1
- package/bin/loop-agent.js +37 -1
- package/dist/build-stamp.json +6 -0
- package/dist/cli/program.js +2 -2
- package/dist/executors/dag-pi-executor.js +44 -0
- package/dist/shared/package-metadata.js +42 -0
- package/dist/worker/console/chat/assistant-content.js +11 -0
- package/dist/worker/console/chat/pi-runtime.js +6 -2
- package/dist/worker/console/chat/turn-process.js +17 -9
- package/dist/worker/console/chat/workspace-landing.js +1 -1
- package/dist/worker/console/static/assets/index-DuVLjCIT.js +57 -0
- package/dist/worker/console/static/index.html +1 -1
- package/dist/worker/console/static-src/app/useRecoveryConsole.js +5 -0
- package/dist/worker/console/static-src/operator-chat/chat-sse-events.js +15 -3
- package/dist/worker/console/static-src/operator-chat/refs.js +3 -0
- package/dist/worker/console/static-src/operator-chat/useChatSessions.js +3 -0
- package/dist/worker/console/static-src/operator-chat/useChatThread.js +1 -0
- package/dist/worker/loop-agent/loop-agent-client.js +17 -3
- package/dist/worker/observability/read-model.js +20 -0
- package/dist/worker/observe/spec-evidence.js +3 -8
- package/dist/worker/observe/static/views/dag-inspector.js +6 -71
- package/dist/worker/preflight.js +2 -1
- package/dist/workflows/dag/backend-test-scenario-param.js +33 -23
- package/dist/workflows/dag/contract-output-registry.js +14 -0
- package/dist/workflows/dag/contract-validator-registrations.js +8 -0
- package/dist/workflows/dag/dynamic-runtime/shared.js +9 -1
- package/dist/workflows/dag/frontend-implementation-contract.js +233 -39
- package/dist/workflows/dag/frontend-prewrite-gate.js +364 -61
- package/dist/workflows/dag/frontend-recovery-plan.js +73 -0
- package/dist/workflows/dag/frontend-recovery-root-manifest.js +123 -0
- package/dist/workflows/dag/frontend-recovery-run.js +539 -0
- package/dist/workflows/dag/frontend-repair.js +219 -18
- package/dist/workflows/dag/frontend-verification-trace.js +47 -32
- package/dist/workflows/dag/frontend-writer-recovery.js +106 -0
- package/dist/workflows/dag/frontend-writer-rollback.js +821 -0
- package/dist/workflows/dag/init-hybrid.js +49 -24
- package/dist/workflows/dag/node-execution.js +89 -0
- package/dist/workflows/dag/recovery-recommendation.js +58 -0
- package/dist/workflows/dag/runner.js +245 -11
- package/dist/workflows/dag/scheduler.js +257 -3
- package/dist/workflows/dag/types.js +130 -2
- package/package.json +4 -3
- package/dist/worker/console/static/assets/index-gVHrlqI9.js +0 -56
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
1
3
|
import { isPauseOnHumanDecisionGate } from "./decision-envelope.js";
|
|
2
4
|
import { evaluateConditionExpression } from "./dynamic-runtime/condition.js";
|
|
5
|
+
import { sha256Hex } from "./frontend-implementation-contract.js";
|
|
6
|
+
import { frontendPrewriteResultV1Schema, FRONTEND_PREWRITE_RESULT_ARTIFACT_NAME, } from "./frontend-prewrite-gate.js";
|
|
7
|
+
import { FRONTEND_RECOVERY_IMPORT_MANIFEST_REL_PATH, FRONTEND_RECOVERY_INTENT_REL_DIR, } from "./frontend-recovery-plan.js";
|
|
3
8
|
export function isConditionSkippedReason(reason) {
|
|
4
9
|
return Boolean(reason?.startsWith("condition "));
|
|
5
10
|
}
|
|
@@ -104,6 +109,58 @@ async function mapConcurrent(items, limit, fn) {
|
|
|
104
109
|
}
|
|
105
110
|
await Promise.all(executing);
|
|
106
111
|
}
|
|
112
|
+
export const FRONTEND_WRITER_NODE_IDS = [
|
|
113
|
+
"frontend-implement-pi",
|
|
114
|
+
"frontend-repair-pi",
|
|
115
|
+
];
|
|
116
|
+
/** Run-relative artifact location written by the prewrite gate generator. */
|
|
117
|
+
export const FRONTEND_PREWRITE_RESULT_SOURCE_ARTIFACT = path.posix.join("contracts", FRONTEND_PREWRITE_RESULT_ARTIFACT_NAME);
|
|
118
|
+
/**
|
|
119
|
+
* Read and validate the frontend-prewrite-result-v1 artifact. Fail-closed:
|
|
120
|
+
* a missing file or invalid payload returns ok:false and never throws.
|
|
121
|
+
*/
|
|
122
|
+
export async function readFrontendPrewriteResult(runDir) {
|
|
123
|
+
const artifactPath = path.join(runDir, "contracts", FRONTEND_PREWRITE_RESULT_ARTIFACT_NAME);
|
|
124
|
+
let raw;
|
|
125
|
+
try {
|
|
126
|
+
raw = await readFile(artifactPath, "utf8");
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
if (error.code === "ENOENT") {
|
|
130
|
+
return {
|
|
131
|
+
ok: false,
|
|
132
|
+
reason: `frontend prewrite result artifact missing: ${artifactPath}`,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
|
+
const artifactHash = sha256Hex(raw);
|
|
138
|
+
let parsed;
|
|
139
|
+
try {
|
|
140
|
+
parsed = JSON.parse(raw);
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
return {
|
|
144
|
+
ok: false,
|
|
145
|
+
reason: `frontend prewrite result artifact is not valid JSON: ${error instanceof Error ? error.message : String(error)}`,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
const result = frontendPrewriteResultV1Schema.safeParse(parsed);
|
|
149
|
+
if (!result.success) {
|
|
150
|
+
return {
|
|
151
|
+
ok: false,
|
|
152
|
+
reason: "frontend prewrite result artifact failed schema validation",
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
return { ok: true, result: result.data, artifactHash };
|
|
156
|
+
}
|
|
157
|
+
/** Authorize only accepted / accepted-normalized classifications. */
|
|
158
|
+
export function isFrontendWriterAuthorized(result) {
|
|
159
|
+
return result.classification === "accepted" ||
|
|
160
|
+
result.classification === "accepted-normalized"
|
|
161
|
+
? "authorized"
|
|
162
|
+
: "denied";
|
|
163
|
+
}
|
|
107
164
|
/** Fail-closed: leave no PENDING nodes that look "still scheduled" after abort. */
|
|
108
165
|
export function markPendingNodesControllerInterrupted(state, reason = "run aborted by controller (abortSignal)") {
|
|
109
166
|
const affected = [];
|
|
@@ -122,8 +179,166 @@ export function markPendingNodesControllerInterrupted(state, reason = "run abort
|
|
|
122
179
|
}
|
|
123
180
|
return affected;
|
|
124
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* True when this run is a candidate-continuation child: it has a recovery
|
|
184
|
+
* lineage whose attemptIndex is >= 1 and whose recovery root is another run.
|
|
185
|
+
* The root/parent keeps `recoveryRootRunId === state.runId`.
|
|
186
|
+
*/
|
|
187
|
+
export function isFrontendRecoveryChild(state) {
|
|
188
|
+
const recovery = state.frontendRecoveryState;
|
|
189
|
+
return Boolean(recovery &&
|
|
190
|
+
recovery.attemptIndex >= 1 &&
|
|
191
|
+
recovery.recoveryRootRunId !== state.runId);
|
|
192
|
+
}
|
|
193
|
+
function isValidFrontendRecoveryActivationMarker(raw) {
|
|
194
|
+
return (raw.schemaVersion === 1 &&
|
|
195
|
+
typeof raw.requestId === "string" &&
|
|
196
|
+
raw.requestId.length > 0 &&
|
|
197
|
+
typeof raw.parentRunId === "string" &&
|
|
198
|
+
raw.parentRunId.length > 0 &&
|
|
199
|
+
typeof raw.recoveryRootRunId === "string" &&
|
|
200
|
+
raw.recoveryRootRunId.length > 0 &&
|
|
201
|
+
typeof raw.childRunId === "string" &&
|
|
202
|
+
raw.childRunId.length > 0 &&
|
|
203
|
+
typeof raw.importManifestSha256 === "string" &&
|
|
204
|
+
/^[a-f0-9]{64}$/.test(raw.importManifestSha256));
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Activation marker gate (phase 3c AC-1). Fail-closed: an active child is only
|
|
208
|
+
* executable when its parent is `child-running`, points at this child, carries
|
|
209
|
+
* a structurally valid activation marker whose lineage matches, and the marker
|
|
210
|
+
* hash matches the child's import manifest. Read-only and never throws.
|
|
211
|
+
*/
|
|
212
|
+
export async function checkFrontendRecoveryActivation(state, childRunDir) {
|
|
213
|
+
if (!isFrontendRecoveryChild(state)) {
|
|
214
|
+
return { applicable: false };
|
|
215
|
+
}
|
|
216
|
+
const recovery = state.frontendRecoveryState;
|
|
217
|
+
const parentRunId = recovery.parentRunId;
|
|
218
|
+
const parentRunDir = path.join(path.dirname(childRunDir), parentRunId);
|
|
219
|
+
let parentState;
|
|
220
|
+
try {
|
|
221
|
+
parentState = JSON.parse(await readFile(path.join(parentRunDir, "state.json"), "utf8"));
|
|
222
|
+
}
|
|
223
|
+
catch {
|
|
224
|
+
return { applicable: true, ok: false, reason: "parent state unreadable" };
|
|
225
|
+
}
|
|
226
|
+
const parentRecovery = parentState.frontendRecoveryState;
|
|
227
|
+
if (parentRecovery?.phase !== "child-running") {
|
|
228
|
+
return {
|
|
229
|
+
applicable: true,
|
|
230
|
+
ok: false,
|
|
231
|
+
reason: "parent phase not child-running",
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
if (parentRecovery.childRunId !== state.runId) {
|
|
235
|
+
return {
|
|
236
|
+
applicable: true,
|
|
237
|
+
ok: false,
|
|
238
|
+
reason: "parent childRunId mismatch",
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
const markerPath = path.join(parentRunDir, FRONTEND_RECOVERY_INTENT_REL_DIR, `${recovery.requestId}.json`);
|
|
242
|
+
let markerRaw;
|
|
243
|
+
try {
|
|
244
|
+
markerRaw = JSON.parse(await readFile(markerPath, "utf8"));
|
|
245
|
+
}
|
|
246
|
+
catch {
|
|
247
|
+
return {
|
|
248
|
+
applicable: true,
|
|
249
|
+
ok: false,
|
|
250
|
+
reason: "activation marker missing",
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
if (typeof markerRaw !== "object" ||
|
|
254
|
+
markerRaw === null ||
|
|
255
|
+
!isValidFrontendRecoveryActivationMarker(markerRaw)) {
|
|
256
|
+
return {
|
|
257
|
+
applicable: true,
|
|
258
|
+
ok: false,
|
|
259
|
+
reason: "activation marker invalid",
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
const marker = markerRaw;
|
|
263
|
+
if (marker.requestId !== recovery.requestId) {
|
|
264
|
+
return {
|
|
265
|
+
applicable: true,
|
|
266
|
+
ok: false,
|
|
267
|
+
reason: "marker requestId mismatch",
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
if (marker.parentRunId !== parentRunId) {
|
|
271
|
+
return {
|
|
272
|
+
applicable: true,
|
|
273
|
+
ok: false,
|
|
274
|
+
reason: "marker parentRunId mismatch",
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
if (marker.recoveryRootRunId !== recovery.recoveryRootRunId) {
|
|
278
|
+
return {
|
|
279
|
+
applicable: true,
|
|
280
|
+
ok: false,
|
|
281
|
+
reason: "marker recoveryRootRunId mismatch",
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
if (marker.childRunId !== state.runId) {
|
|
285
|
+
return {
|
|
286
|
+
applicable: true,
|
|
287
|
+
ok: false,
|
|
288
|
+
reason: "marker childRunId mismatch",
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
let manifestSha256;
|
|
292
|
+
try {
|
|
293
|
+
manifestSha256 = sha256Hex(await readFile(path.join(childRunDir, FRONTEND_RECOVERY_IMPORT_MANIFEST_REL_PATH), "utf8"));
|
|
294
|
+
}
|
|
295
|
+
catch {
|
|
296
|
+
return {
|
|
297
|
+
applicable: true,
|
|
298
|
+
ok: false,
|
|
299
|
+
reason: "import manifest unreadable",
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
if (manifestSha256 !== marker.importManifestSha256) {
|
|
303
|
+
return {
|
|
304
|
+
applicable: true,
|
|
305
|
+
ok: false,
|
|
306
|
+
reason: "import manifest sha256 mismatch",
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
return {
|
|
310
|
+
applicable: true,
|
|
311
|
+
ok: true,
|
|
312
|
+
requestId: recovery.requestId,
|
|
313
|
+
childRunId: state.runId,
|
|
314
|
+
};
|
|
315
|
+
}
|
|
125
316
|
export async function executeDagRanksOnce(input) {
|
|
126
317
|
let pausedByNodeId;
|
|
318
|
+
// Activation marker gate (phase 3c AC-1): a recovery child without a valid
|
|
319
|
+
// activation marker must never be scheduled or executed. Fail-closed before
|
|
320
|
+
// any executeScheduledNode call, so zero writer/provider invocations happen.
|
|
321
|
+
if (input.runDir) {
|
|
322
|
+
const hasPending = Object.values(input.state.nodes).some((node) => node.status === "PENDING");
|
|
323
|
+
if (hasPending) {
|
|
324
|
+
const activation = await checkFrontendRecoveryActivation(input.state, input.runDir);
|
|
325
|
+
if (activation.applicable && !activation.ok) {
|
|
326
|
+
const finishedAt = new Date().toISOString();
|
|
327
|
+
let affected = 0;
|
|
328
|
+
for (const node of Object.values(input.state.nodes)) {
|
|
329
|
+
if (node.status !== "PENDING")
|
|
330
|
+
continue;
|
|
331
|
+
node.status = "SKIPPED";
|
|
332
|
+
node.skippedReason = "frontend-recovery-child-not-activated";
|
|
333
|
+
node.finishedAt = finishedAt;
|
|
334
|
+
affected += 1;
|
|
335
|
+
}
|
|
336
|
+
if (affected > 0)
|
|
337
|
+
await input.persistState();
|
|
338
|
+
return undefined;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
127
342
|
for (const rank of input.ranks) {
|
|
128
343
|
if (input.abortSignal?.aborted) {
|
|
129
344
|
const marked = markPendingNodesControllerInterrupted(input.state, input.abortSignal.reason
|
|
@@ -168,6 +383,45 @@ export async function executeDagRanksOnce(input) {
|
|
|
168
383
|
await input.persistState();
|
|
169
384
|
const conditionSkippedSet = new Set(conditionSettled);
|
|
170
385
|
const actuallyRunnable = runnable.filter((id) => !conditionSkippedSet.has(id));
|
|
386
|
+
const frontendAdmissionSettled = [];
|
|
387
|
+
if (input.runDir) {
|
|
388
|
+
for (const id of actuallyRunnable) {
|
|
389
|
+
if (!FRONTEND_WRITER_NODE_IDS.includes(id))
|
|
390
|
+
continue;
|
|
391
|
+
const node = input.state.nodes[id];
|
|
392
|
+
const checkedAt = new Date().toISOString();
|
|
393
|
+
const admission = await readFrontendPrewriteResult(input.runDir);
|
|
394
|
+
if (!admission.ok) {
|
|
395
|
+
node.status = "SKIPPED";
|
|
396
|
+
node.skippedReason = "frontend-prewrite-not-authorized";
|
|
397
|
+
node.finishedAt = checkedAt;
|
|
398
|
+
frontendAdmissionSettled.push(id);
|
|
399
|
+
continue;
|
|
400
|
+
}
|
|
401
|
+
const decision = isFrontendWriterAuthorized(admission.result);
|
|
402
|
+
node.frontendWriterAdmission = {
|
|
403
|
+
schemaVersion: 1,
|
|
404
|
+
writerNodeId: id,
|
|
405
|
+
decision,
|
|
406
|
+
sourceArtifact: FRONTEND_PREWRITE_RESULT_SOURCE_ARTIFACT,
|
|
407
|
+
artifactHash: admission.artifactHash,
|
|
408
|
+
checkedAt,
|
|
409
|
+
reason: decision === "denied"
|
|
410
|
+
? `classification: ${admission.result.classification}`
|
|
411
|
+
: null,
|
|
412
|
+
};
|
|
413
|
+
if (decision === "denied") {
|
|
414
|
+
node.status = "SKIPPED";
|
|
415
|
+
node.skippedReason = "frontend-prewrite-not-authorized";
|
|
416
|
+
node.finishedAt = checkedAt;
|
|
417
|
+
frontendAdmissionSettled.push(id);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
if (frontendAdmissionSettled.length > 0)
|
|
421
|
+
await input.persistState();
|
|
422
|
+
}
|
|
423
|
+
const frontendAdmissionSkippedSet = new Set(frontendAdmissionSettled);
|
|
424
|
+
const runnableAfterAdmission = actuallyRunnable.filter((id) => !frontendAdmissionSkippedSet.has(id));
|
|
171
425
|
const blocked = pending.filter((id) => {
|
|
172
426
|
const task = input.tasksById.get(id);
|
|
173
427
|
return (dependencyReadiness(task, input.state.nodes, input.tasksById) === "skip");
|
|
@@ -182,12 +436,12 @@ export async function executeDagRanksOnce(input) {
|
|
|
182
436
|
if (blocked.length > 0) {
|
|
183
437
|
await input.persistState();
|
|
184
438
|
}
|
|
185
|
-
const pauseGateRunnable =
|
|
439
|
+
const pauseGateRunnable = runnableAfterAdmission.filter((id) => {
|
|
186
440
|
const task = input.tasksById.get(id);
|
|
187
441
|
return isPauseOnHumanDecisionGate(task);
|
|
188
442
|
});
|
|
189
|
-
const regularRunnable =
|
|
190
|
-
const rankWriterNodeIds =
|
|
443
|
+
const regularRunnable = runnableAfterAdmission.filter((id) => !pauseGateRunnable.includes(id));
|
|
444
|
+
const rankWriterNodeIds = runnableAfterAdmission.filter((id) => {
|
|
191
445
|
const task = input.tasksById.get(id);
|
|
192
446
|
return (task?.executor === "pi" &&
|
|
193
447
|
task.toolProfile === "write" &&
|
|
@@ -654,8 +654,15 @@ export const dagConvergenceSpecSchema = z
|
|
|
654
654
|
chainNodeIds: z.array(z.string()).optional(),
|
|
655
655
|
})
|
|
656
656
|
.optional();
|
|
657
|
-
|
|
658
|
-
|
|
657
|
+
/**
|
|
658
|
+
* Schema ids that may opt a node into producing-node structured contract
|
|
659
|
+
* self-validation. Validators are registered in the contract output registry
|
|
660
|
+
* (src/workflows/dag/contract-output-registry.ts).
|
|
661
|
+
*/
|
|
662
|
+
export const structuredContractOutputSchemaIds = [
|
|
663
|
+
"frontend-implementation-contract-v1",
|
|
664
|
+
];
|
|
665
|
+
export const dagTaskSchema = z.object({ id: z.string().regex(/^[a-z][a-z0-9-]*$/, "task id must be kebab-case"),
|
|
659
666
|
depends_on: z.array(z.string()).default([]),
|
|
660
667
|
/**
|
|
661
668
|
* How SKIPPED upstreams affect readiness.
|
|
@@ -704,6 +711,20 @@ export const dagTaskSchema = z.object({
|
|
|
704
711
|
* on safe read-only Pi nodes before the node becomes ERROR.
|
|
705
712
|
*/
|
|
706
713
|
outputProtocol: dagOutputProtocolSchema.optional(),
|
|
714
|
+
/**
|
|
715
|
+
* Node-level structured contract self-check: after the Pi output is
|
|
716
|
+
* produced, validate it against the named contract schema at the node so
|
|
717
|
+
* schema/typo/null violations become invalid-output (retryable on the node)
|
|
718
|
+
* instead of failing later at a downstream deterministic gate. Validators
|
|
719
|
+
* are resolved via the contract output registry keyed by schemaId.
|
|
720
|
+
*/
|
|
721
|
+
structuredContractOutput: z
|
|
722
|
+
.object({
|
|
723
|
+
schemaId: z.enum(structuredContractOutputSchemaIds),
|
|
724
|
+
retryOnInvalid: z.boolean().default(true),
|
|
725
|
+
})
|
|
726
|
+
.strict()
|
|
727
|
+
.optional(),
|
|
707
728
|
/**
|
|
708
729
|
* Fail-closed outcome/diff consistency contract for bounded Pi writers.
|
|
709
730
|
* The writer must begin with IMPLEMENTATION_OUTCOME: changed,
|
|
@@ -874,6 +895,113 @@ export const dagSpecSchema = z
|
|
|
874
895
|
});
|
|
875
896
|
}
|
|
876
897
|
});
|
|
898
|
+
export const FRONTEND_RECOVERY_STATE_SCHEMA_VERSION = 1;
|
|
899
|
+
export const FRONTEND_RECOVERY_RESULT_SCHEMA_VERSION = 1;
|
|
900
|
+
/**
|
|
901
|
+
* Frontend candidate-continuation recovery phase (decision B, phase-3 subset).
|
|
902
|
+
* Phase 3a parents converge first, so `rollback-pending` is not produced and
|
|
903
|
+
* was removed by AC-1; the phase starts at `child-staging` and ends at
|
|
904
|
+
* `settled`.
|
|
905
|
+
*/
|
|
906
|
+
export const frontendRecoveryPhaseSchema = z.enum([
|
|
907
|
+
"child-staging",
|
|
908
|
+
"child-activating",
|
|
909
|
+
"child-running",
|
|
910
|
+
"settled",
|
|
911
|
+
]);
|
|
912
|
+
/**
|
|
913
|
+
* Single-writer recovery intent/lineage stored on `DagRunState`. The parent run
|
|
914
|
+
* owns the authoritative copy and advances it via revision-guarded CAS writes;
|
|
915
|
+
* the child carries a frozen lineage snapshot so the activation gate can prove
|
|
916
|
+
* it is the reserved child of a child-running parent.
|
|
917
|
+
*
|
|
918
|
+
* Invariants: `attemptIndex ∈ {0,1}`; `continuationCount ∈ {0,1}`; a child's
|
|
919
|
+
* `recoveryRootRunId` always equals the root runId; `revision` is the CAS
|
|
920
|
+
* pre-comparison counter. `revision` monotonicity is enforced at runtime by the
|
|
921
|
+
* runner's `(existing?.revision ?? 0) + 1` CAS write (the schema only bounds it
|
|
922
|
+
* non-negative). `childRunId` may be absent through `child-activating` and must
|
|
923
|
+
* be non-empty from `child-running` onward.
|
|
924
|
+
*/
|
|
925
|
+
export const frontendRecoveryStateSchema = z
|
|
926
|
+
.object({
|
|
927
|
+
schemaVersion: z.literal(FRONTEND_RECOVERY_STATE_SCHEMA_VERSION),
|
|
928
|
+
phase: frontendRecoveryPhaseSchema,
|
|
929
|
+
requestId: z.string().min(1),
|
|
930
|
+
recoveryRootRunId: z.string().min(1),
|
|
931
|
+
parentRunId: z.string().min(1),
|
|
932
|
+
childRunId: z.string().min(1).optional(),
|
|
933
|
+
attemptId: z.string().min(1),
|
|
934
|
+
attemptIndex: z.number().int().min(0).max(1),
|
|
935
|
+
continuationCount: z.number().int().min(0).max(1),
|
|
936
|
+
/** Node id of the reset-closure root: frontend-plan-pi /
|
|
937
|
+
* frontend-plan-revision-pi / frontend-prewrite-gate-shell /
|
|
938
|
+
* frontend-implement-pi (writer partial write). */
|
|
939
|
+
failureSource: z.string().min(1).optional(),
|
|
940
|
+
revision: z.number().int().nonnegative(),
|
|
941
|
+
})
|
|
942
|
+
.strict()
|
|
943
|
+
.superRefine((value, ctx) => {
|
|
944
|
+
const requiresChild = value.phase === "child-running" || value.phase === "settled";
|
|
945
|
+
if (requiresChild && !value.childRunId) {
|
|
946
|
+
ctx.addIssue({
|
|
947
|
+
code: z.ZodIssueCode.custom,
|
|
948
|
+
message: `phase ${value.phase} requires a non-empty childRunId`,
|
|
949
|
+
path: ["childRunId"],
|
|
950
|
+
});
|
|
951
|
+
}
|
|
952
|
+
});
|
|
953
|
+
export const frontendRecoveryOutcomeSchema = z.enum([
|
|
954
|
+
"none",
|
|
955
|
+
"recovered",
|
|
956
|
+
"candidate-contract-invalid",
|
|
957
|
+
"prewrite-blocked",
|
|
958
|
+
"repair-exhausted",
|
|
959
|
+
"auto-recovery-blocked",
|
|
960
|
+
]);
|
|
961
|
+
export const frontendRecoveryOriginSchema = z
|
|
962
|
+
.object({
|
|
963
|
+
kind: z.enum(["frontend-prewrite-gate", "frontend-writer"]),
|
|
964
|
+
parentRunId: z.string().min(1),
|
|
965
|
+
childRunId: z.string().min(1).optional(),
|
|
966
|
+
requestId: z.string().min(1),
|
|
967
|
+
failedNodeId: z.string(),
|
|
968
|
+
})
|
|
969
|
+
.strict();
|
|
970
|
+
export const frontendRecoveryFailureClassSchema = z
|
|
971
|
+
.object({
|
|
972
|
+
code: z.enum([
|
|
973
|
+
"candidate-contract-invalid",
|
|
974
|
+
"prewrite-blocked",
|
|
975
|
+
"staging-failed",
|
|
976
|
+
"writer-transient-partial-write",
|
|
977
|
+
]),
|
|
978
|
+
classification: z.string(),
|
|
979
|
+
reason: z.string(),
|
|
980
|
+
})
|
|
981
|
+
.strict();
|
|
982
|
+
export const frontendRecoveryEvidenceRefSchema = z
|
|
983
|
+
.object({
|
|
984
|
+
runId: z.string().min(1),
|
|
985
|
+
relativePath: z.string().min(1),
|
|
986
|
+
sha256: z.string().min(1),
|
|
987
|
+
})
|
|
988
|
+
.strict();
|
|
989
|
+
/**
|
|
990
|
+
* Terminal frontend recovery result. `failureClass` is absent for `none`,
|
|
991
|
+
* `recovered` and `auto-recovery-blocked` outcomes. The schema intentionally
|
|
992
|
+
* stays permissive (failureClass optional, evidenceRefs may be empty) so it
|
|
993
|
+
* accepts the runner's actual phase-3a products, which do not always carry a
|
|
994
|
+
* failure class or evidence reference.
|
|
995
|
+
*/
|
|
996
|
+
export const frontendRecoveryResultSchema = z
|
|
997
|
+
.object({
|
|
998
|
+
schemaVersion: z.literal(FRONTEND_RECOVERY_RESULT_SCHEMA_VERSION),
|
|
999
|
+
outcome: frontendRecoveryOutcomeSchema,
|
|
1000
|
+
origin: frontendRecoveryOriginSchema,
|
|
1001
|
+
failureClass: frontendRecoveryFailureClassSchema.optional(),
|
|
1002
|
+
evidenceRefs: z.array(frontendRecoveryEvidenceRefSchema),
|
|
1003
|
+
})
|
|
1004
|
+
.strict();
|
|
877
1005
|
export const DEFAULT_DAG_EXECUTOR_MODELS = {
|
|
878
1006
|
pi: {
|
|
879
1007
|
LOW: "gpt-5.3-codex-spark",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tea-agent/loop-agent",
|
|
3
|
-
"version": "0.35.
|
|
3
|
+
"version": "0.35.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"loop-agent": "bin/loop-agent.js",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"pi-prompt": "node --import tsx/esm src/cli.ts pi-prompt",
|
|
46
46
|
"clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
47
47
|
"brand:sync": "node scripts/sync-brand-assets.mjs",
|
|
48
|
-
"build": "npm run brand:sync && npm run clean && tsc -p tsconfig.build.json && node -e \"const fs=require('node:fs');const p='dist/worker/observe/static';fs.mkdirSync(p,{recursive:true});fs.cpSync('src/worker/observe/static',p,{recursive:true});\" && npm run console:build",
|
|
48
|
+
"build": "npm run brand:sync && npm run clean && tsc -p tsconfig.build.json && node -e \"const fs=require('node:fs');const p='dist/worker/observe/static';fs.mkdirSync(p,{recursive:true});fs.cpSync('src/worker/observe/static',p,{recursive:true});\" && npm run console:build && node scripts/write-build-stamp.mjs",
|
|
49
49
|
"console:typecheck": "tsc -p src/worker/console/tsconfig.json",
|
|
50
50
|
"console:build": "npm run console:typecheck && vite build --config src/worker/console/vite.config.ts",
|
|
51
51
|
"prepack": "npm run build",
|
|
@@ -88,5 +88,6 @@
|
|
|
88
88
|
"typescript": "^5.9.3",
|
|
89
89
|
"vite": "^7.0.0",
|
|
90
90
|
"vitest": "^3.2.4"
|
|
91
|
-
}
|
|
91
|
+
},
|
|
92
|
+
"packageManager": "pnpm@10.33.0+sha512.10568bb4a6afb58c9eb3630da90cc9516417abebd3fabbe6739f0ae795728da1491e9db5a544c76ad8eb7570f5c4bb3d6c637b2cb41bfdcdb47fa823c8649319"
|
|
92
93
|
}
|