@tea-agent/loop-agent 0.51.0-next.1 → 0.51.0-next.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/CHANGELOG.md +33 -1
- package/dist/application/task-lifecycle/advance.js +6 -0
- package/dist/build-stamp.json +3 -3
- package/dist/commands/init.js +12 -3
- package/dist/executors/dag-pi/plan/facts.js +18 -4
- package/dist/executors/dag-pi/plan/record-tools.js +34 -3
- package/dist/executors/dag-pi/sessions/scout-parallel.js +11 -2
- package/dist/executors/dag-pi/sessions/segmented-plan.js +170 -16
- package/dist/executors/dag-pi/tools/contract-read-tool.js +34 -0
- package/dist/executors/dag-pi/tools/scout-evidence-tools.js +9 -7
- package/dist/executors/dag-pi-executor.js +82 -82
- package/dist/shared/pi-context-pressure/checkpoint.js +22 -4
- package/dist/shared/pi-context-pressure/compaction-policy.js +5 -1
- package/dist/shared/pi-context-pressure/extension.js +64 -5
- package/dist/shared/pi-context-pressure/sift-bridge.js +2 -1
- package/dist/shared/pi-context-pressure/telemetry.js +4 -0
- package/dist/shared/pi-context-pressure/tool-result-pruner.js +8 -3
- package/dist/task/source-prepare/completeness.js +2 -2
- package/dist/task/source-prepare/diagnostic.js +76 -0
- package/dist/task/source-prepare/ledger-reconciliation.js +65 -9
- package/dist/task/source-prepare/ledger-review.js +18 -2
- package/dist/task/source-prepare/ledger.js +3 -1
- package/dist/task/source-prepare/prepare.js +23 -3
- package/dist/task/source-prepare/source-fidelity-pi.js +12 -1
- package/dist/task/source-prepare/types.js +1 -1
- package/dist/worker/console/chat/chat-event-projection.js +13 -0
- package/dist/worker/console/chat/chat-event-store.js +1 -0
- package/dist/worker/console/chat/compaction-errors.js +1 -1
- package/dist/worker/console/chat/context-accounting.js +58 -0
- package/dist/worker/console/chat/context-insights.js +131 -22
- package/dist/worker/console/chat/context-usage.js +57 -1
- package/dist/worker/console/chat/pi-runtime/context-edit.js +91 -0
- package/dist/worker/console/chat/pi-runtime.js +36 -3
- package/dist/worker/console/chat/routes.js +3 -0
- package/dist/worker/console/chat/terminal-routes.js +12 -0
- package/dist/worker/console/chat/terminal-sessions.js +6 -0
- package/dist/worker/console/chat/vcp-prompt.js +28 -15
- package/dist/worker/console/recovery-error-copy.js +4 -1
- package/dist/worker/console/static/assets/{abnfDiagram-N423BO3Z-DUtUeeEa.js → abnfDiagram-N423BO3Z-GerMJfMU.js} +1 -1
- package/dist/worker/console/static/assets/{arc-Cs0DSwTY.js → arc-DHRoAcBA.js} +1 -1
- package/dist/worker/console/static/assets/{architectureDiagram-T3A2C74G-C80FSNgl.js → architectureDiagram-T3A2C74G-Bna7kqEi.js} +1 -1
- package/dist/worker/console/static/assets/{blockDiagram-VBNYF7ZC-DFgOZUzn.js → blockDiagram-VBNYF7ZC-B8yw7WTX.js} +1 -1
- package/dist/worker/console/static/assets/{c4Diagram-5PPSVZJV-CB9nkTjT.js → c4Diagram-5PPSVZJV-BaUWiyqi.js} +1 -1
- package/dist/worker/console/static/assets/channel-CLhtAowh.js +1 -0
- package/dist/worker/console/static/assets/{chunk-2GRJ4B5K-DbjpoOrh.js → chunk-2GRJ4B5K-D4iZ2ZNv.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-2Q5K7J3B-BsWVWnWY.js → chunk-2Q5K7J3B-BtQpibwB.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-5RXB4S5H-BwwP_1AG.js → chunk-5RXB4S5H-ez-kfSyS.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-5VM5RSS4-DDEzW9MV.js → chunk-5VM5RSS4-6L4-OV-3.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-6Q2QTUOP-D-fLZDni.js → chunk-6Q2QTUOP-CPUweABC.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-GF5L2VYU-DY9q3jMo.js → chunk-GF5L2VYU-6DTw-5Ov.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-JWPE2WC7-rkUPkzPh.js → chunk-JWPE2WC7-DFAS-DH8.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-KBJHAD2P-Ci9ZksX4.js → chunk-KBJHAD2P-Du7LoER5.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-RYQCIY6F-DKU-3Ef6.js → chunk-RYQCIY6F-D9UugPlg.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-XXDRQBXY-A-xOwXvl.js → chunk-XXDRQBXY-BLh5yptc.js} +1 -1
- package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-DB7nfjpK.js +1 -0
- package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-DB7nfjpK.js +1 -0
- package/dist/worker/console/static/assets/{cose-bilkent-JH36ORCC-Bfs1rphL.js → cose-bilkent-JH36ORCC-DjmHXa8h.js} +1 -1
- package/dist/worker/console/static/assets/{cynefin-VYW2F7L2-BTlXtGR2.js → cynefin-VYW2F7L2-D5jbf1gi.js} +1 -1
- package/dist/worker/console/static/assets/{cynefinDiagram-MW4NZA55-D8c9vCCr.js → cynefinDiagram-MW4NZA55-BudjeLTi.js} +1 -1
- package/dist/worker/console/static/assets/{dagre-VZM6K2ZE-B-e-tfgY.js → dagre-VZM6K2ZE-6YP-wMO0.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-7IWD3JNH-CG_5dIVJ.js → diagram-7IWD3JNH-CA3LtUAB.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-B4RE2ZJO-CmP40HmK.js → diagram-B4RE2ZJO-BAjJeYaD.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-LBJQPF4R-RFt8vi9Y.js → diagram-LBJQPF4R-Dh4zb-ds.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-Q27KOJAE-CM5Sb2jB.js → diagram-Q27KOJAE-aMKj_Gkp.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-UB23O5K3-Bm4zh0WJ.js → diagram-UB23O5K3-D_0_rqQ6.js} +1 -1
- package/dist/worker/console/static/assets/{ebnfDiagram-BXEA7PRR-b3GekSN4.js → ebnfDiagram-BXEA7PRR--C9HfGgB.js} +1 -1
- package/dist/worker/console/static/assets/{erDiagram-JOGREHBK-CFZh4C_o.js → erDiagram-JOGREHBK-BuqX0vmt.js} +1 -1
- package/dist/worker/console/static/assets/{flowDiagram-UKHOOZJN-CzxniD3z.js → flowDiagram-UKHOOZJN-IneEK8zO.js} +1 -1
- package/dist/worker/console/static/assets/{ganttDiagram-PKOTCBZU-Czp6xUXj.js → ganttDiagram-PKOTCBZU-DK2RiNlb.js} +1 -1
- package/dist/worker/console/static/assets/{gitGraphDiagram-DS77QQ5N-B66oX4sn.js → gitGraphDiagram-DS77QQ5N-CuN5z0rP.js} +1 -1
- package/dist/worker/console/static/assets/{index-BVMJjujb.css → index-CzfumEW1.css} +1 -1
- package/dist/worker/console/static/assets/{index-Bq_vMDO3.js → index-DS6dteCl.js} +159 -147
- package/dist/worker/console/static/assets/{infoDiagram-6WML65LV-rTveEtft.js → infoDiagram-6WML65LV-B6enpqSl.js} +1 -1
- package/dist/worker/console/static/assets/{ishikawaDiagram-WSZJBQD7-N2jiPnrD.js → ishikawaDiagram-WSZJBQD7-DepH_7eq.js} +1 -1
- package/dist/worker/console/static/assets/{journeyDiagram-NVQOT4AX-DtnLwtAE.js → journeyDiagram-NVQOT4AX-BftlRwcR.js} +1 -1
- package/dist/worker/console/static/assets/{kanban-definition-27J2QSJJ-t9D_2QMN.js → kanban-definition-27J2QSJJ-CEIZMo9g.js} +1 -1
- package/dist/worker/console/static/assets/{linear-BP6ZG0tB.js → linear-DkgtGbsw.js} +1 -1
- package/dist/worker/console/static/assets/{mermaid.core-Cc5_ZtUy.js → mermaid.core-CIMKKPgL.js} +5 -5
- package/dist/worker/console/static/assets/{mindmap-definition-FAOFIHXS-zztwmHj8.js → mindmap-definition-FAOFIHXS-dzbp1VuW.js} +1 -1
- package/dist/worker/console/static/assets/{pegDiagram-VL7TDLO6-CmXQOyPH.js → pegDiagram-VL7TDLO6-C5b5i7KO.js} +1 -1
- package/dist/worker/console/static/assets/{pieDiagram-7S7Q4E2Y-BodwfpEp.js → pieDiagram-7S7Q4E2Y-Ugdko1lm.js} +1 -1
- package/dist/worker/console/static/assets/{quadrantDiagram-CIZ2JOQS-DIgybsTM.js → quadrantDiagram-CIZ2JOQS-B2s1OZu8.js} +1 -1
- package/dist/worker/console/static/assets/{railroadDiagram-AXF67PYL-CZb_4Cv2.js → railroadDiagram-AXF67PYL-BVafp-Z6.js} +1 -1
- package/dist/worker/console/static/assets/{requirementDiagram-LRYGKXZP-BvRNauBA.js → requirementDiagram-LRYGKXZP-BVxBjdbs.js} +1 -1
- package/dist/worker/console/static/assets/{sankeyDiagram-W5VNT64P-BQ30kRWi.js → sankeyDiagram-W5VNT64P-CorSImxl.js} +1 -1
- package/dist/worker/console/static/assets/{sequenceDiagram-SI44F4Z6-B7sGR3r3.js → sequenceDiagram-SI44F4Z6-eVj3geQV.js} +1 -1
- package/dist/worker/console/static/assets/{sheet-workbook-CK8pzw-q.js → sheet-workbook-DNnJDCal.js} +1 -1
- package/dist/worker/console/static/assets/{sizeCapture-X5ZJPWSS-1HZrTeyl.js → sizeCapture-X5ZJPWSS-OQWfzgrL.js} +1 -1
- package/dist/worker/console/static/assets/{stateDiagram-OKZ733FA-BKCXlJRS.js → stateDiagram-OKZ733FA-DJr_pPmG.js} +1 -1
- package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-Cr-50jJB.js +1 -0
- package/dist/worker/console/static/assets/{swimlanes-SLNWSIFB-BhT8u6Vm.js → swimlanes-SLNWSIFB-CQG0Q9vK.js} +2 -2
- package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-kZpEmem6.js +8 -0
- package/dist/worker/console/static/assets/{timeline-definition-Z64GVDOM-Dnczuw3j.js → timeline-definition-Z64GVDOM-DxWuWIZ5.js} +1 -1
- package/dist/worker/console/static/assets/{vennDiagram-T6HMQDX7-PgJCj-16.js → vennDiagram-T6HMQDX7-BJt03ecs.js} +1 -1
- package/dist/worker/console/static/assets/{wardleyDiagram-T6FBY63Y-BjuszbFn.js → wardleyDiagram-T6FBY63Y-BB3rPfNJ.js} +1 -1
- package/dist/worker/console/static/assets/{xychartDiagram-ELKLHX3M-Dhtjuxrn.js → xychartDiagram-ELKLHX3M-aVR9TCu0.js} +1 -1
- package/dist/worker/console/static/index.html +2 -2
- package/dist/worker/console/static-src/operator-chat/useChatSessions.js +99 -16
- package/dist/worker/console/static-src/operator-chat/useChatThread.js +27 -5
- package/dist/worker/console/static-src/operator-chat/vcp-fonts.js +1 -6
- package/dist/worker/console/workspace-context.js +56 -1
- package/dist/worker/observe/static/dag-history-labels.js +2 -0
- package/dist/worker/observe/static/views/dag.js +28 -0
- package/dist/workflows/dag/frontend-durable-tools.js +5 -2
- package/dist/workflows/dag/frontend-implementation-contract.js +19 -6
- package/dist/workflows/dag/frontend-recovery-run.js +20 -1
- package/dist/workflows/dag/frontend-review-scopes.js +2 -2
- package/dist/workflows/dag/frontend-session-budget.js +1 -1
- package/dist/workflows/dag/frontend-writer-baseline-guard.js +11 -5
- package/dist/workflows/dag/hybrid/templates/frontend.js +35 -5
- package/dist/workflows/dag/prompt.js +8 -2
- package/dist/workflows/dag/rerun-plan.js +50 -3
- package/dist/workflows/dag/rerun-run.js +4 -0
- package/dist/workflows/dag/runner.js +11 -0
- package/package.json +6 -3
- package/dist/worker/console/static/assets/channel-BddnaJc4.js +0 -1
- package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-CqfGeesl.js +0 -1
- package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-CqfGeesl.js +0 -1
- package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-DzDcqZJM.js +0 -1
- package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-DgnnY3K8.js +0 -8
- package/dist/worker/console/static/vcp/fonts/Lanxi-GreatVibes.woff2 +0 -0
- package/dist/worker/console/static/vcp/fonts/Lanxi-MaShanZheng.woff2 +0 -0
- package/dist/worker/console/static/vcp/fonts/Lanxi-/347/202/271/351/273/221.woff2 +0 -0
- package/dist/worker/console/static/vcp/fonts/Lanxi-/351/235/231/351/273/221/350/266/205/347/273/206.woff2 +0 -0
- package/dist/worker/console/static/vcp/fonts/Lanxi-/351/261/274/345/260/276/350/241/214/344/271/246.woff2 +0 -0
|
@@ -3,7 +3,7 @@ import { classifyFrontendPlanRecovery } from "../../../workflows/dag/frontend-pl
|
|
|
3
3
|
import { collectFrontendExecutionGroups } from "../../../workflows/dag/frontend-execution-groups.js";
|
|
4
4
|
import { FRONTEND_SCOPE_TARGET_BYTES, packFrontendInputUnits, parseFrontendInputBlock, projectFrontendContractPrompt, projectFrontendInputScope } from "../../../workflows/dag/frontend-input-projection.js";
|
|
5
5
|
import { observeFrontendFinalization, observeFrontendSession } from "../../../workflows/dag/frontend-session-budget.js";
|
|
6
|
-
import { collectFrontendPlanMissingFacts, collectFrontendPlanPhaseMissingFacts, committedFactFromPlanRecord, planFactStringList } from "../plan/facts.js";
|
|
6
|
+
import { collectFrontendPlanMissingFacts, collectFrontendPlanPhaseMissingFacts, hasCompleteFrontendPlanGlobalPolicy, committedFactFromPlanRecord, planFactStringList } from "../plan/facts.js";
|
|
7
7
|
import { OUTPUT_LIMIT_RETRY_CATEGORY } from "../../../workflows/dag/retry-policy.js";
|
|
8
8
|
import { FRONTEND_PLAN_BATCH_MAX_SESSIONS, FRONTEND_PLAN_COVERAGE_MAX_RECORD_CALLS, FRONTEND_PLAN_SEGMENTS, buildFrontendPlanWorkload, collectFrontendVerificationCommandFiles } from "./plan-batches.js";
|
|
9
9
|
import { compactFrontendPlanLedgerContext, compactFrontendPlanPromptForRequirementSlice } from "./plan-prompts.js";
|
|
@@ -249,6 +249,84 @@ export async function runFrontendContractSegmentedSessions(input) {
|
|
|
249
249
|
input.tools.setActiveRequirementScope(null);
|
|
250
250
|
}
|
|
251
251
|
}
|
|
252
|
+
/** A provider may stop normally after receiving a rejected typed-tool receipt.
|
|
253
|
+
* Track that rejection separately from prose/stderr. Only a successful retry
|
|
254
|
+
* of the same fact identity resolves it; unrelated writes cannot hide it. */
|
|
255
|
+
function trackPlanToolFailures(tools) {
|
|
256
|
+
const failures = new Map();
|
|
257
|
+
const callKeys = new Map();
|
|
258
|
+
// Unexecuted truncated arguments cannot reliably identify a fact. A full
|
|
259
|
+
// successful call of that tool clears only this SDK transport condition.
|
|
260
|
+
const truncatedCalls = new Set();
|
|
261
|
+
const executedCalls = new Set();
|
|
262
|
+
const object = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
263
|
+
const factKey = (name, rawParams) => {
|
|
264
|
+
const params = object(rawParams);
|
|
265
|
+
// A successful bounded read resolves prior pagination/revision guidance,
|
|
266
|
+
// including narrowing an unscoped query to an eventId and field.
|
|
267
|
+
if (name === "read_plan_facts")
|
|
268
|
+
return "read_plan_facts:query";
|
|
269
|
+
const entry = object(params?.entry) ?? object(params?.choice);
|
|
270
|
+
const endpoint = object(params?.endpoint);
|
|
271
|
+
const names = (value) => Array.isArray(value) ? value.map(item => object(item)?.name).filter(item => typeof item === "string").sort() : [];
|
|
272
|
+
const identity = params?.id ?? params?.scopeId ?? entry?.id ?? entry?.purpose ?? entry?.requirementId ?? params?.eventId ?? params?.requirementId ??
|
|
273
|
+
(endpoint ? JSON.stringify([endpoint.method, endpoint.path]) : undefined) ??
|
|
274
|
+
(name === "record_design_input_binding" ? JSON.stringify([entry?.sourcePath, entry?.targetPath]) : undefined) ??
|
|
275
|
+
(name === "record_state_flow" ? JSON.stringify([names(params?.uiStates), names(params?.interactions), planFactStringList(params?.removeUiStateNames).sort(), planFactStringList(params?.removeInteractionNames).sort()]) : undefined);
|
|
276
|
+
const singleton = ["record_dependency", "record_route_selection", "record_state_registry", "record_mock_api", "record_data_flow", "record_design_deviation"].includes(String(name));
|
|
277
|
+
return `${String(name)}:${String(identity ?? (singleton ? "singleton" : JSON.stringify(params)))}`;
|
|
278
|
+
};
|
|
279
|
+
const observeReceipt = (key, result, isError = false, toolName) => {
|
|
280
|
+
const receipt = object(result);
|
|
281
|
+
const details = object(receipt?.details);
|
|
282
|
+
if (isError || receipt?.isError === true || details?.ok === false)
|
|
283
|
+
failures.set(key, String(details?.code ?? details?.error ?? "tool rejected"));
|
|
284
|
+
else if (details?.ok === true) {
|
|
285
|
+
failures.delete(key);
|
|
286
|
+
if (toolName)
|
|
287
|
+
truncatedCalls.delete(toolName);
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
const customTools = tools.map(value => {
|
|
291
|
+
const tool = object(value);
|
|
292
|
+
if (!tool || typeof tool.execute !== "function")
|
|
293
|
+
return value;
|
|
294
|
+
const execute = tool.execute;
|
|
295
|
+
return { ...tool, execute: async (...args) => {
|
|
296
|
+
const key = factKey(tool.name, args[1]);
|
|
297
|
+
executedCalls.add(String(args[0]));
|
|
298
|
+
try {
|
|
299
|
+
const result = await execute.apply(tool, args);
|
|
300
|
+
observeReceipt(key, result, false, String(tool.name));
|
|
301
|
+
return result;
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
failures.set(key, error instanceof Error ? error.message : String(error));
|
|
305
|
+
throw error;
|
|
306
|
+
}
|
|
307
|
+
} };
|
|
308
|
+
});
|
|
309
|
+
// SDK argument validation can reject a call before execute is reached.
|
|
310
|
+
const onSessionEvent = (_line, value) => {
|
|
311
|
+
const event = object(value);
|
|
312
|
+
if (!event || typeof event.toolCallId !== "string")
|
|
313
|
+
return;
|
|
314
|
+
if (event.type === "tool_execution_start")
|
|
315
|
+
callKeys.set(event.toolCallId, factKey(event.toolName, event.args));
|
|
316
|
+
if (event.type === "tool_execution_end") {
|
|
317
|
+
const key = callKeys.get(event.toolCallId) ?? factKey(event.toolName, undefined);
|
|
318
|
+
const content = object(event.result)?.content;
|
|
319
|
+
const truncated = !executedCalls.has(event.toolCallId) && event.isError === true && Array.isArray(content) &&
|
|
320
|
+
content.some(item => object(item)?.text === `Tool call "${String(event.toolName)}" was not executed: the response hit the output token limit, so its arguments may be truncated. Re-issue the tool call with complete arguments.`);
|
|
321
|
+
if (truncated)
|
|
322
|
+
truncatedCalls.add(String(event.toolName));
|
|
323
|
+
else
|
|
324
|
+
observeReceipt(key, event.result, event.isError === true, String(event.toolName));
|
|
325
|
+
callKeys.delete(event.toolCallId);
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
return { customTools, failures, onSessionEvent, truncatedCalls };
|
|
329
|
+
}
|
|
252
330
|
export async function runFrontendPlanSegmentedSessions(input) {
|
|
253
331
|
const queue = [];
|
|
254
332
|
const coverageSegment = FRONTEND_PLAN_SEGMENTS.find((segment) => segment.id === "coverage");
|
|
@@ -261,12 +339,12 @@ export async function runFrontendPlanSegmentedSessions(input) {
|
|
|
261
339
|
? compactFrontendPlanPromptForRequirementSlice(input.basePrompt, scopeIds, {
|
|
262
340
|
includeRequirementText: segment.id === "global-mock-data" || segment.id === "finalize",
|
|
263
341
|
includeVerificationTargets: false,
|
|
264
|
-
includeDesignEvidence: segment.id === "global-dependency-deviation" || segment.id === "finalize",
|
|
342
|
+
includeDesignEvidence: segment.id === "global-route" || segment.id === "global-dependency-deviation" || segment.id === "finalize",
|
|
265
343
|
includeChecklist: false,
|
|
266
344
|
})
|
|
267
345
|
: input.basePrompt;
|
|
268
346
|
const kinds = segment.id === "global-route"
|
|
269
|
-
? ["target-surface"]
|
|
347
|
+
? ["target-surface", "dependency", "design-deviation"]
|
|
270
348
|
: segment.id === "global-mock-data"
|
|
271
349
|
? ["plan-requirement", "plan-verification-target", "state-flow", "data-flow", "mock-api"]
|
|
272
350
|
: segment.id === "global-dependency-deviation"
|
|
@@ -384,6 +462,7 @@ export async function runFrontendPlanSegmentedSessions(input) {
|
|
|
384
462
|
compactFrontendPlanPromptForRequirementSlice(input.basePrompt, allRequirementIds, { includeDesignEvidence: true }),
|
|
385
463
|
"PLAN PHASE — compact local planning for a small frontend request.",
|
|
386
464
|
"Review all listed requirements together and record_state_registry first with one global UX vocabulary. Then record every plan-requirement and verification-target fact, followed by component/state-flow facts and the minimal route, Mock/data, dependency, and design-deviation policy facts needed by the observable behavior. Do not read the repository or task source; use only the committed input above. Do not call finalize_plan in this session.",
|
|
465
|
+
"Before ending, cover EVERY frozen static command with record_plan_verification_target (entry.commandId from the directory, entry.file from planned implementation targets, uiStates: []). Behavior tests do not cover build/typecheck commands. Follow remainingStaticCommandIds in tool receipts.",
|
|
387
466
|
"TOOL-FIRST: your first assistant actions must be record_* tool calls, at most 2-3 facts per message. Do not draft the whole analysis before recording; if a fact is uncertain, record it with an evidence gap instead of reasoning longer.",
|
|
388
467
|
ledger,
|
|
389
468
|
...(missing.length > 0
|
|
@@ -610,6 +689,20 @@ export async function runFrontendPlanSegmentedSessions(input) {
|
|
|
610
689
|
}
|
|
611
690
|
}
|
|
612
691
|
}
|
|
692
|
+
const compactFactsComplete = () => {
|
|
693
|
+
if (!requirementIdsProvided || !input.committedFacts || input.behaviorRequiredRequirementIds === undefined)
|
|
694
|
+
return false;
|
|
695
|
+
const facts = input.committedFacts();
|
|
696
|
+
return collectFrontendPlanMissingFacts({ requirementIds: allRequirementIds, committedFacts: facts }).length === 0 &&
|
|
697
|
+
["ux-registry", "ux-local", "global-mock-data"].every(phase => collectFrontendPlanPhaseMissingFacts({ phase, requirementIds: allRequirementIds,
|
|
698
|
+
committedFacts: facts, behaviorRequiredRequirementIds: input.behaviorRequiredRequirementIds }).length === 0) &&
|
|
699
|
+
hasCompleteFrontendPlanGlobalPolicy({ committedFacts: facts, dependencyPolicyRequired: dependencyDeviationNeeded });
|
|
700
|
+
};
|
|
701
|
+
const runtimeResult = {
|
|
702
|
+
ok: true, failureCategory: "success", exitCode: 0, stdout: "", stderr: "", assistantText: "",
|
|
703
|
+
command: [], durationMs: 0, modelDisplay: "runtime-finalize", parsedEvents: 0, timedOut: false,
|
|
704
|
+
attemptedModels: [], fallbackUsed: false, tokensUsed: 0,
|
|
705
|
+
};
|
|
613
706
|
let accumulated;
|
|
614
707
|
let index = 0;
|
|
615
708
|
let invocationCount = 0;
|
|
@@ -618,6 +711,10 @@ export async function runFrontendPlanSegmentedSessions(input) {
|
|
|
618
711
|
const session = queue[index];
|
|
619
712
|
if (!session)
|
|
620
713
|
break;
|
|
714
|
+
if (input.attempt > 1 && session.id === "compact-local" && compactFactsComplete()) {
|
|
715
|
+
index += 1;
|
|
716
|
+
continue;
|
|
717
|
+
}
|
|
621
718
|
if (input.attempt > 1 && input.committedFacts && session.id === "ux-registry" &&
|
|
622
719
|
collectFrontendPlanPhaseMissingFacts({ phase: "ux-registry", requirementIds: allRequirementIds, committedFacts: input.committedFacts() }).length === 0) {
|
|
623
720
|
index += 1;
|
|
@@ -680,6 +777,16 @@ export async function runFrontendPlanSegmentedSessions(input) {
|
|
|
680
777
|
index += 1;
|
|
681
778
|
continue;
|
|
682
779
|
}
|
|
780
|
+
if (requirementIdsProvided && input.committedFacts && (session.id === "global-policy" && hasCompleteFrontendPlanGlobalPolicy({
|
|
781
|
+
committedFacts: input.committedFacts(), dependencyPolicyRequired: dependencyDeviationNeeded,
|
|
782
|
+
}) || session.id.startsWith("global-mock-data") &&
|
|
783
|
+
collectFrontendPlanPhaseMissingFacts({
|
|
784
|
+
phase: "global-mock-data", requirementIds: session.requirementSlice ?? allRequirementIds,
|
|
785
|
+
committedFacts: input.committedFacts(),
|
|
786
|
+
}).length === 0)) {
|
|
787
|
+
index += 1;
|
|
788
|
+
continue;
|
|
789
|
+
}
|
|
683
790
|
let prompt = session.prompt;
|
|
684
791
|
if (session.coverageOnly && session.coverageSlice) {
|
|
685
792
|
const promptSlice = [...new Set([...remaining, ...preexistingMissing.flatMap(item => item.requirementIds)])];
|
|
@@ -734,14 +841,18 @@ export async function runFrontendPlanSegmentedSessions(input) {
|
|
|
734
841
|
"state-registry": "record_state_registry", "component-choice": "record_component_choice",
|
|
735
842
|
"state-flow": "record_state_flow", "data-flow": "record_data_flow", "mock-api": "record_mock_api",
|
|
736
843
|
};
|
|
737
|
-
const
|
|
844
|
+
const originalTools = input.segmentCustomTools(atomicFocus ? new Set([atomicTools[atomicFocus.kind]]) : session.toolNames);
|
|
845
|
+
const { customTools, failures: toolFailures, onSessionEvent: observeToolEvent, truncatedCalls } = trackPlanToolFailures(originalTools);
|
|
846
|
+
let ledgerFlushed = false;
|
|
847
|
+
let ledgerFlushError = "";
|
|
738
848
|
const result = await observeFrontendSession({
|
|
739
849
|
...input.observation, phase: `plan/${session.id}`, dispatchReason: (session.retryCount ?? 0) > 0 || !!session.missingFacts?.length || /capacity|recovery|split/.test(session.id) ? "correction" : "initial", scopeIds: session.requirementSlice ?? session.coverageSlice ?? allRequirementIds,
|
|
740
|
-
prompt, userMessage: input.sessionOptions.userMessage, customTools, committedCount: input.committedFactCount, durableCommittedCount: () => lastDurableCount,
|
|
850
|
+
prompt, userMessage: input.sessionOptions.userMessage, customTools: originalTools, committedCount: input.committedFactCount, durableCommittedCount: () => lastDurableCount,
|
|
741
851
|
artifactPath: input.observation?.artifactPath ? `${input.observation.artifactPath}-${invocationCount}.json` : undefined,
|
|
742
852
|
}, async (observer) => {
|
|
743
853
|
const result = await input.piStepFn({
|
|
744
854
|
...input.sessionOptions,
|
|
855
|
+
onSessionEvent: (line, event) => { observeToolEvent(line, event); input.sessionOptions.onSessionEvent?.(line, event); },
|
|
745
856
|
onAttemptObservation: observer,
|
|
746
857
|
prompt,
|
|
747
858
|
...(customTools.length > 0
|
|
@@ -756,9 +867,12 @@ export async function runFrontendPlanSegmentedSessions(input) {
|
|
|
756
867
|
try {
|
|
757
868
|
await input.flushLedger();
|
|
758
869
|
lastDurableCount = input.committedFactCount();
|
|
870
|
+
ledgerFlushed = true;
|
|
759
871
|
}
|
|
760
|
-
catch {
|
|
761
|
-
|
|
872
|
+
catch (error) {
|
|
873
|
+
ledgerFlushError = error instanceof Error ? error.message : String(error);
|
|
874
|
+
// The node-level flush can retry persistence, but this session must
|
|
875
|
+
// never claim durable progress or advance to finalization.
|
|
762
876
|
}
|
|
763
877
|
return result;
|
|
764
878
|
});
|
|
@@ -766,10 +880,20 @@ export async function runFrontendPlanSegmentedSessions(input) {
|
|
|
766
880
|
? combineSequentialPiResults(accumulated, result)
|
|
767
881
|
: result;
|
|
768
882
|
const committedAfter = input.committedFactCount();
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
883
|
+
if (classifyFrontendPlanRecovery({ ...result, stopReason: readWriterThinkingExhaustionEvidence(result).stopReason }) === "stop")
|
|
884
|
+
return { ...accumulated, ok: false };
|
|
885
|
+
if (!ledgerFlushed)
|
|
886
|
+
return { ...accumulated, ok: false, failureCategory: "invalid-output",
|
|
887
|
+
stderr: `${accumulated.stderr}\nPLAN_LEDGER_FLUSH_FAILED: ${ledgerFlushError}`.trim() };
|
|
888
|
+
if (truncatedCalls.size > 0 && readWriterThinkingExhaustionEvidence(result).stopReason !== "length" && result.failureCategory !== "output-limit") {
|
|
889
|
+
return { ...accumulated, ok: false, failureCategory: "invalid-output", stderr: `${accumulated.stderr}\nPLAN_TOOL_ERROR: truncated tool calls remain unexecuted`.trim() };
|
|
890
|
+
}
|
|
891
|
+
if (toolFailures.size > 0)
|
|
892
|
+
return { ...accumulated, ok: false, failureCategory: "invalid-output",
|
|
893
|
+
stderr: `${accumulated.stderr}\nPLAN_TOOL_ERROR: ${[...toolFailures.values()].join("; ")}`.trim() };
|
|
894
|
+
const normalEmptyTurn = result.failureCategory === "empty-output" &&
|
|
895
|
+
readWriterThinkingExhaustionEvidence(result).stopReason === "stop" &&
|
|
896
|
+
!(result.assistantText ?? "").trim() && !result.stderr.trim() && !result.timedOut;
|
|
773
897
|
const missingCoverage = session.coverageOnly && session.coverageSlice && input.committedFacts
|
|
774
898
|
? collectFrontendPlanMissingFacts({
|
|
775
899
|
requirementIds: session.coverageSlice,
|
|
@@ -818,6 +942,10 @@ export async function runFrontendPlanSegmentedSessions(input) {
|
|
|
818
942
|
})
|
|
819
943
|
: [];
|
|
820
944
|
const missingPhaseFacts = [...missingCoverage, ...missingPhase];
|
|
945
|
+
const phaseCompletenessKnown = requirementIdsProvided && Boolean(input.committedFacts) && (Boolean(session.coverageOnly && session.coverageSlice?.length) || isCompactLocalSession && compactFactsComplete() ||
|
|
946
|
+
isUxRegistrySession || isUxLocalSession && input.behaviorRequiredRequirementIds !== undefined ||
|
|
947
|
+
session.id.startsWith("global-mock-data") || session.id === "global-policy" &&
|
|
948
|
+
hasCompleteFrontendPlanGlobalPolicy({ committedFacts: input.committedFacts(), dependencyPolicyRequired: dependencyDeviationNeeded }));
|
|
821
949
|
// Frozen verification commands must operate on files the planner has
|
|
822
950
|
// committed verification targets for; otherwise the admission writeSet
|
|
823
951
|
// cannot authorize the file and verify-shell deterministically fails.
|
|
@@ -840,6 +968,7 @@ export async function runFrontendPlanSegmentedSessions(input) {
|
|
|
840
968
|
});
|
|
841
969
|
}
|
|
842
970
|
}
|
|
971
|
+
const committedFactsOnlySuccess = normalEmptyTurn && (committedAfter > committedBefore || phaseCompletenessKnown && missingPhaseFacts.length === 0);
|
|
843
972
|
const promptForMissingPhase = (missing) => session.coverageOnly
|
|
844
973
|
? buildCoveragePrompt(session.coverageSlice ?? [], missing)
|
|
845
974
|
: isCompactLocalSession
|
|
@@ -960,7 +1089,8 @@ export async function runFrontendPlanSegmentedSessions(input) {
|
|
|
960
1089
|
};
|
|
961
1090
|
}
|
|
962
1091
|
if (committedFactsOnlySuccess) {
|
|
963
|
-
//
|
|
1092
|
+
// Tool-only completion needs no new narrative or duplicate writes.
|
|
1093
|
+
// Durable facts and the final compiler remain the authority.
|
|
964
1094
|
if (missingPhaseFacts.length > 0 && (session.retryCount ?? 0) < 2) {
|
|
965
1095
|
queue[index] = {
|
|
966
1096
|
...session,
|
|
@@ -978,6 +1108,7 @@ export async function runFrontendPlanSegmentedSessions(input) {
|
|
|
978
1108
|
failureCategory: "invalid-output",
|
|
979
1109
|
};
|
|
980
1110
|
}
|
|
1111
|
+
accumulated = { ...accumulated, ok: true, failureCategory: "success", exitCode: 0 };
|
|
981
1112
|
index += 1;
|
|
982
1113
|
continue;
|
|
983
1114
|
}
|
|
@@ -1080,6 +1211,14 @@ export async function runFrontendPlanSegmentedSessions(input) {
|
|
|
1080
1211
|
};
|
|
1081
1212
|
}
|
|
1082
1213
|
if (!input.parallelCoverageOnly && input.finalizePlan) {
|
|
1214
|
+
try {
|
|
1215
|
+
await input.flushLedger();
|
|
1216
|
+
lastDurableCount = input.committedFactCount();
|
|
1217
|
+
}
|
|
1218
|
+
catch (error) {
|
|
1219
|
+
return { ...(accumulated ?? runtimeResult), ok: false, failureCategory: "invalid-output",
|
|
1220
|
+
stderr: `${accumulated?.stderr ?? ""}\nPLAN_LEDGER_FLUSH_FAILED: ${error instanceof Error ? error.message : String(error)}`.trim() };
|
|
1221
|
+
}
|
|
1083
1222
|
// Preserve optional closeout context if an earlier correction or future
|
|
1084
1223
|
// ledger producer committed it. The old model-only finalize session was
|
|
1085
1224
|
// the only writer of these fields; runtime-owned finalization must not
|
|
@@ -1122,17 +1261,20 @@ export async function runFrontendPlanSegmentedSessions(input) {
|
|
|
1122
1261
|
input.committedFacts ? compactFrontendPlanLedgerContext({ committedFacts: input.committedFacts(), requirementIds: input.requirementIds ?? [], kinds: ["plan-requirement", "plan-verification-target", "implementation-slice", "state-registry", "component-choice", "state-flow", "data-flow", "mock-api", "design-deviation", "dependency", "target-surface"] }) : "",
|
|
1123
1262
|
].filter(Boolean).join("\n\n");
|
|
1124
1263
|
input.setActiveRequirementScope?.([]);
|
|
1125
|
-
const
|
|
1264
|
+
const originalCorrectionTools = input.segmentCustomTools(null);
|
|
1265
|
+
const { customTools: correctionTools, failures: correctionToolFailures, onSessionEvent: observeCorrectionToolEvent, truncatedCalls: correctionTruncatedCalls } = trackPlanToolFailures(originalCorrectionTools);
|
|
1126
1266
|
const committedCountBeforeCorrection = input.committedFactCount();
|
|
1127
1267
|
let correctionFlushed = false;
|
|
1268
|
+
let correctionFlushError = "";
|
|
1128
1269
|
const correction = await observeFrontendSession({
|
|
1129
1270
|
...input.observation, phase: "plan/finalize-correction", dispatchReason: "correction",
|
|
1130
1271
|
scopeIds: input.requirementIds, prompt: correctionPrompt, userMessage: input.sessionOptions.userMessage,
|
|
1131
|
-
customTools:
|
|
1272
|
+
customTools: originalCorrectionTools, committedCount: input.committedFactCount, durableCommittedCount: () => lastDurableCount,
|
|
1132
1273
|
artifactPath: input.observation?.artifactPath ? `${input.observation.artifactPath}-finalize-correction.json` : undefined,
|
|
1133
1274
|
}, async (observer) => {
|
|
1134
1275
|
const result = await input.piStepFn({
|
|
1135
1276
|
...input.sessionOptions, onAttemptObservation: observer, prompt: correctionPrompt,
|
|
1277
|
+
onSessionEvent: (line, event) => { observeCorrectionToolEvent(line, event); input.sessionOptions.onSessionEvent?.(line, event); },
|
|
1136
1278
|
writerToolPolicy: { requireSdk: true, customTools: correctionTools },
|
|
1137
1279
|
});
|
|
1138
1280
|
try {
|
|
@@ -1140,17 +1282,25 @@ export async function runFrontendPlanSegmentedSessions(input) {
|
|
|
1140
1282
|
lastDurableCount = input.committedFactCount();
|
|
1141
1283
|
correctionFlushed = true;
|
|
1142
1284
|
}
|
|
1143
|
-
catch {
|
|
1285
|
+
catch (error) {
|
|
1286
|
+
correctionFlushError = error instanceof Error ? error.message : String(error);
|
|
1287
|
+
}
|
|
1144
1288
|
return result;
|
|
1145
1289
|
});
|
|
1146
1290
|
accumulated = accumulated
|
|
1147
1291
|
? combineSequentialPiResults(accumulated, correction)
|
|
1148
1292
|
: correction;
|
|
1293
|
+
const correctionStopReason = readWriterThinkingExhaustionEvidence(correction).stopReason;
|
|
1294
|
+
if (classifyFrontendPlanRecovery({ ...correction, stopReason: correctionStopReason }) === "stop")
|
|
1295
|
+
return { ...accumulated, ok: false };
|
|
1296
|
+
if (!correctionFlushed || correctionToolFailures.size > 0 || correctionTruncatedCalls.size > 0)
|
|
1297
|
+
return { ...accumulated, ok: false, failureCategory: "invalid-output",
|
|
1298
|
+
stderr: `${accumulated.stderr}\n${!correctionFlushed ? `PLAN_LEDGER_FLUSH_FAILED: ${correctionFlushError}` : `PLAN_TOOL_ERROR: ${[...correctionToolFailures.values()].join("; ")}`}`.trim() };
|
|
1149
1299
|
if (!correction.ok && !["invalid-output", "empty-output", "success"].includes(correction.failureCategory))
|
|
1150
1300
|
return { ...accumulated, ok: false, failureCategory: correction.failureCategory };
|
|
1151
1301
|
const durableEmptyCorrection = !correction.ok && correction.failureCategory === "empty-output"
|
|
1152
1302
|
&& !correction.timedOut && !correction.assistantText.trim() && !correction.stderr.trim()
|
|
1153
|
-
&&
|
|
1303
|
+
&& correctionStopReason === "stop"
|
|
1154
1304
|
&& correctionFlushed && lastDurableCount > committedCountBeforeCorrection;
|
|
1155
1305
|
if (correction.ok || durableEmptyCorrection) {
|
|
1156
1306
|
finalizeResult = await finalize();
|
|
@@ -1189,6 +1339,10 @@ export async function runFrontendPlanSegmentedSessions(input) {
|
|
|
1189
1339
|
failureCategory: "invalid-output",
|
|
1190
1340
|
};
|
|
1191
1341
|
}
|
|
1342
|
+
return {
|
|
1343
|
+
...(accumulated ?? runtimeResult),
|
|
1344
|
+
ok: true, failureCategory: "success", exitCode: 0,
|
|
1345
|
+
};
|
|
1192
1346
|
}
|
|
1193
1347
|
return mapPlannerExhaustion(accumulated ?? {
|
|
1194
1348
|
ok: false,
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** Read only the frozen, hash-bound contract inventory, never arbitrary paths. */
|
|
2
|
+
export async function createFrontendContractReadTool(inventory) {
|
|
3
|
+
const [{ Type }, { defineTool }] = await Promise.all([
|
|
4
|
+
import("typebox"),
|
|
5
|
+
import("@earendil-works/pi-coding-agent"),
|
|
6
|
+
]);
|
|
7
|
+
const readIds = new Set();
|
|
8
|
+
return defineTool({
|
|
9
|
+
name: "read_frontend_contract",
|
|
10
|
+
label: "read_frontend_contract",
|
|
11
|
+
description: "Read the frozen frontend contract. With no sectionId, list semantic sections and unread IDs. With an exact listed sectionId, return its complete JSON; no character fragments or manual reconstruction. Runtime checks hashes and canonical coverage. Read all sections before implementation.",
|
|
12
|
+
parameters: Type.Object({ sectionId: Type.Optional(Type.String()) }, { additionalProperties: false }),
|
|
13
|
+
async execute(_callId, params) {
|
|
14
|
+
await inventory.validate();
|
|
15
|
+
const section = params.sectionId === undefined ? undefined : inventory.scopes.find(scope => scope.id === params.sectionId);
|
|
16
|
+
if (params.sectionId !== undefined && !section)
|
|
17
|
+
throw new Error("FRONTEND_CONTRACT_SECTION_UNKNOWN: use an exact sectionId from the inventory");
|
|
18
|
+
if (section)
|
|
19
|
+
readIds.add(section.id);
|
|
20
|
+
const details = {
|
|
21
|
+
digest: inventory.digest,
|
|
22
|
+
unreadSectionIds: inventory.scopes.filter(scope => !readIds.has(scope.id)).map(scope => scope.id),
|
|
23
|
+
...(section ? { sectionId: section.id, sha256: section.sha256 } : {}),
|
|
24
|
+
};
|
|
25
|
+
return {
|
|
26
|
+
content: [{ type: "text", text: section?.text ?? JSON.stringify({
|
|
27
|
+
...details,
|
|
28
|
+
sections: inventory.scopes.map(scope => ({ sectionId: scope.id, sha256: scope.sha256, bytes: Buffer.byteLength(scope.text, "utf8"), fields: Object.keys(JSON.parse(scope.text).data ?? {}) })),
|
|
29
|
+
}) }],
|
|
30
|
+
details,
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
}
|
|
@@ -131,7 +131,7 @@ export async function createFrontendScoutEvidenceTools(input) {
|
|
|
131
131
|
const recordTargetSurfaceTool = defineTool({
|
|
132
132
|
name: "record_target_surface",
|
|
133
133
|
label: "record_target_surface",
|
|
134
|
-
description: "Commit an origin=scout target-surface fact with complete/blocked discovery status. A complete surface needs a proven target path and no unresolved paths; blocked surfaces name the unresolved paths instead of guessing. Example: {\"completeness\": \"complete\", \"entrypoint\": \"<file>\", \"implementationPaths\": [\"<dir or file>\"], \"testPaths\": [\"<file>\"], \"allowedPathConflicts\": [], \"unresolvedPaths\": []}",
|
|
134
|
+
description: "Commit an origin=scout target-surface fact with complete/blocked discovery status. entrypoint is one repository-relative file path; put route/mount relationships in routeOrMount. A complete surface needs a proven target path and no unresolved paths; blocked surfaces name the unresolved paths instead of guessing. Example: {\"completeness\": \"complete\", \"entrypoint\": \"<file>\", \"implementationPaths\": [\"<dir or file>\"], \"testPaths\": [\"<file>\"], \"allowedPathConflicts\": [], \"unresolvedPaths\": []}",
|
|
135
135
|
promptSnippet: "Commit an origin=scout target-surface fact.",
|
|
136
136
|
parameters: Type.Object({
|
|
137
137
|
scopeId: Type.Optional(Type.String({ minLength: 1 })),
|
|
@@ -176,13 +176,15 @@ export async function createFrontendScoutEvidenceTools(input) {
|
|
|
176
176
|
...(hasSourceDeclarations ? { sourceDeclaredPaths } : {}),
|
|
177
177
|
...(pathEvidence.length > 0 ? { pathEvidence } : {}),
|
|
178
178
|
};
|
|
179
|
-
|
|
179
|
+
// Validate before acknowledging any complete surface, including parallel
|
|
180
|
+
// unscoped Scout. A rejected submission stays editable in this session.
|
|
181
|
+
if (surface.completeness === "complete") {
|
|
180
182
|
const { readCompleteScoutTargetSurface } = await import("../../../workflows/dag/frontend-committed-facts.js");
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
183
|
+
const check = readCompleteScoutTargetSurface([{ phase: "committed", fact: surface }]);
|
|
184
|
+
if (!check.ok)
|
|
185
|
+
return receipt({ ok: false, code: activeScope ? "SCOUT_SCOPE_INCOMPLETE" : "SCOUT_TARGET_SURFACE_INCOMPLETE", error: check.reason });
|
|
186
|
+
}
|
|
187
|
+
if (activeScope) {
|
|
186
188
|
const saved = await adoptScoutFact("scout-scope", { kind: "scout-scope", origin: "scout", id: params.scopeId, requirementIds: activeScope, surface });
|
|
187
189
|
if (!saved.ok)
|
|
188
190
|
return receipt(saved);
|