@tea-agent/loop-agent 0.43.0-next.17 → 0.43.0-next.19
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 +1 -1
- package/CHANGELOG.md +68 -2309
- package/README.md +7 -0
- package/dist/application/dag/args.js +8 -0
- package/dist/application/task-lifecycle/advance.js +38 -7
- package/dist/build-stamp.json +3 -3
- package/dist/cli/command-definitions.js +2 -0
- package/dist/cli/program.js +3 -1
- package/dist/cli/update/init-surface-notifier.js +2 -0
- package/dist/cli/update/policy.js +2 -0
- package/dist/commands/cursor-prompt.js +2 -0
- package/dist/commands/dag-approve.js +2 -0
- package/dist/commands/dag-final-verification.js +2 -0
- package/dist/commands/dag-init-hybrid.js +2 -0
- package/dist/commands/dag-reconcile-tasks.js +2 -0
- package/dist/commands/dag-reject.js +2 -0
- package/dist/commands/dag-report.js +2 -0
- package/dist/commands/dag-rerun.js +2 -0
- package/dist/commands/dag-resume.js +2 -0
- package/dist/commands/dag-workflow-compile.js +2 -0
- package/dist/commands/dag-workflow-plan.js +2 -0
- package/dist/commands/dag-workflow-validate.js +2 -0
- package/dist/commands/delegate.js +2 -0
- package/dist/commands/examples.js +2 -0
- package/dist/commands/import-prd.js +2 -0
- package/dist/commands/init-model-catalog.js +2 -0
- package/dist/commands/init.js +19 -13
- package/dist/commands/instructions.js +2 -0
- package/dist/commands/knowledge.js +2 -0
- package/dist/commands/loop-benchmark.js +2 -0
- package/dist/commands/pi-prompt.js +2 -0
- package/dist/commands/pi-reuse-benchmark.js +2 -0
- package/dist/commands/promote-run.js +2 -0
- package/dist/commands/stats.js +1 -1
- package/dist/commands/study-init.js +2 -0
- package/dist/commands/task-advance.js +34 -0
- package/dist/commands/task-source-prepare.js +2 -0
- package/dist/commands/worktree-create.js +2 -0
- package/dist/commands/worktree-remove.js +2 -0
- package/dist/executors/dag-pi-executor.js +1640 -194
- package/dist/executors/pi-executor.js +85 -3
- package/dist/executors/pi-sdk-executor.js +18 -0
- package/dist/executors/shell-executor.js +92 -7
- package/dist/executors/shell-verification.js +3 -0
- package/dist/governance/exec-plans.js +6 -3
- package/dist/infrastructure/console/app-data.js +6 -0
- package/dist/shared/artifacts-core.js +2 -0
- package/dist/shared/backend-dogfood-preflight.js +47 -0
- package/dist/shared/dag-failure-category.js +3 -0
- package/dist/shared/git-progress.js +2 -0
- package/dist/shared/one-shot-prompt-args.js +2 -0
- package/dist/shared/operator/capabilities.js +180 -0
- package/dist/shared/package-metadata.js +6 -4
- package/dist/shared/pi-context-pressure/sift-bridge.js +1 -1
- package/dist/shared/reference-context.js +2 -0
- package/dist/task/config-types.js +29 -0
- package/dist/task/contract/project.js +9 -0
- package/dist/task/contract/recover.js +6 -0
- package/dist/task/contract/schema.js +17 -0
- package/dist/task/source-prepare/artifact-meta.js +9 -2
- package/dist/task/source-prepare/build-draft.js +60 -0
- package/dist/task/source-prepare/fragment-inventory.js +4 -1
- package/dist/task/source-prepare/parse-intent.js +36 -11
- package/dist/task/task-demand-routing.js +5 -2
- package/dist/worker/console/chat/browser-automation.js +468 -308
- package/dist/worker/console/chat/browser-routes.js +175 -57
- package/dist/worker/console/chat/explore-tools.js +5 -2
- package/dist/worker/console/chat/pi-mode-loop-isolation.js +155 -0
- package/dist/worker/console/chat/pi-runtime/custom-tools/browser-tools.js +115 -20
- package/dist/worker/console/chat/pi-runtime/custom-tools/operator-tools.js +24 -16
- package/dist/worker/console/chat/pi-runtime/custom-tools/scheduled-goal-tools.js +22 -0
- package/dist/worker/console/chat/pi-runtime/progressive-tools.js +195 -0
- package/dist/worker/console/chat/pi-runtime.js +95 -28
- package/dist/worker/console/chat/routes.js +20 -1
- package/dist/worker/console/chat/scheduled-goal-booking.js +59 -0
- package/dist/worker/console/chat/scheduled-goal-delivery.js +27 -0
- package/dist/worker/console/chat/scheduled-goal-request.js +190 -0
- package/dist/worker/console/chat/sdd-data-alignment.js +1 -1
- package/dist/worker/console/chat/session-mode.js +8 -4
- package/dist/worker/console/chat/session-store.js +42 -9
- package/dist/worker/console/chat/tool-preview.js +115 -0
- package/dist/worker/console/chat/tools.js +7 -1
- package/dist/worker/console/chat/turn-order.js +13 -0
- package/dist/worker/console/chat/turn-process.js +32 -30
- package/dist/worker/console/operator-actions.js +50 -0
- package/dist/worker/console/prd-intake-bridge.js +54 -1
- package/dist/worker/console/scheduled-goal-host.js +98 -0
- package/dist/worker/console/scheduled-goal-operation-adapter.js +127 -0
- package/dist/worker/console/server.js +15 -0
- package/dist/worker/console/static/assets/{abnfDiagram-N423BO3Z-C4NXyedy.js → abnfDiagram-N423BO3Z-8-j6y-sd.js} +1 -1
- package/dist/worker/console/static/assets/{arc-NZ3qXvBI.js → arc-eoQiMvuk.js} +1 -1
- package/dist/worker/console/static/assets/{architectureDiagram-T3A2C74G-COZSRvml.js → architectureDiagram-T3A2C74G-C4A3uMcI.js} +1 -1
- package/dist/worker/console/static/assets/{blockDiagram-VBNYF7ZC-Ck0Gxi9C.js → blockDiagram-VBNYF7ZC-D4zD2F-Q.js} +1 -1
- package/dist/worker/console/static/assets/{c4Diagram-5PPSVZJV-BX5HQ4Ox.js → c4Diagram-5PPSVZJV-j1RkJziL.js} +1 -1
- package/dist/worker/console/static/assets/channel-ChE7y-cx.js +1 -0
- package/dist/worker/console/static/assets/{chunk-2GRJ4B5K-CoviemSL.js → chunk-2GRJ4B5K-YBHmhik1.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-2Q5K7J3B-DbOdOkbZ.js → chunk-2Q5K7J3B-COfWyo9P.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-5RXB4S5H-BsG2pmdQ.js → chunk-5RXB4S5H-I99OUkHY.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-5VM5RSS4-DGdvrNm8.js → chunk-5VM5RSS4-XKxoJNJ4.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-6Q2QTUOP-BAy7Yd6y.js → chunk-6Q2QTUOP-DLT_cYx1.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-GF5L2VYU-D9UA7hUb.js → chunk-GF5L2VYU-CxcKZ9mV.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-JWPE2WC7-DPz7SZ8V.js → chunk-JWPE2WC7-V1EqXdjY.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-KBJHAD2P-BmuEOIh7.js → chunk-KBJHAD2P-DebTtdFp.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-RYQCIY6F-CIhBWnd8.js → chunk-RYQCIY6F-B-ivNRDf.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-XXDRQBXY-CScR6mDD.js → chunk-XXDRQBXY-DC_Ds11b.js} +1 -1
- package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-C01TCf2X.js +1 -0
- package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-C01TCf2X.js +1 -0
- package/dist/worker/console/static/assets/{cose-bilkent-JH36ORCC-BjpfWaUr.js → cose-bilkent-JH36ORCC-sWEqKwIb.js} +1 -1
- package/dist/worker/console/static/assets/{cynefin-VYW2F7L2-BFQohJgT.js → cynefin-VYW2F7L2-BXa_dcu4.js} +1 -1
- package/dist/worker/console/static/assets/{cynefinDiagram-MW4NZA55-D3gzRJnS.js → cynefinDiagram-MW4NZA55-C-Mle84F.js} +1 -1
- package/dist/worker/console/static/assets/{dagre-VZM6K2ZE-5eojkhoA.js → dagre-VZM6K2ZE-CXPDBITe.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-7IWD3JNH-CpD8LWu_.js → diagram-7IWD3JNH-CC-WJQfa.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-B4RE2ZJO-B8_4qJ2a.js → diagram-B4RE2ZJO-CDAV5Vs4.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-LBJQPF4R-HOsXf0eu.js → diagram-LBJQPF4R-CmFiAcNz.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-Q27KOJAE-BqwRwiWP.js → diagram-Q27KOJAE-DPBZHuyn.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-UB23O5K3-BRVCNZe1.js → diagram-UB23O5K3-jUlm_Ds3.js} +1 -1
- package/dist/worker/console/static/assets/{ebnfDiagram-BXEA7PRR-Cvb1TgGh.js → ebnfDiagram-BXEA7PRR-DWhQ3mfY.js} +1 -1
- package/dist/worker/console/static/assets/{erDiagram-JOGREHBK-DS0O0qG9.js → erDiagram-JOGREHBK-Tr2gMqet.js} +1 -1
- package/dist/worker/console/static/assets/{flowDiagram-UKHOOZJN-BHIRvRr3.js → flowDiagram-UKHOOZJN-DJjVQHPA.js} +1 -1
- package/dist/worker/console/static/assets/{ganttDiagram-PKOTCBZU-DcCJ1JWx.js → ganttDiagram-PKOTCBZU-D74dQ4u0.js} +1 -1
- package/dist/worker/console/static/assets/{gitGraphDiagram-DS77QQ5N-B9ia5ony.js → gitGraphDiagram-DS77QQ5N-DwW0tZ0X.js} +1 -1
- package/dist/worker/console/static/assets/index-BWkIfcrK.css +1 -0
- package/dist/worker/console/static/assets/{index-wXlQohNs.js → index-Cdkvw_H6.js} +97 -97
- package/dist/worker/console/static/assets/{infoDiagram-6WML65LV-3ogpgegn.js → infoDiagram-6WML65LV-ILCbxJyb.js} +1 -1
- package/dist/worker/console/static/assets/{ishikawaDiagram-WSZJBQD7-4tgpQ5SL.js → ishikawaDiagram-WSZJBQD7-DeuWBQ89.js} +1 -1
- package/dist/worker/console/static/assets/{journeyDiagram-NVQOT4AX-DNfgHqFx.js → journeyDiagram-NVQOT4AX-CF5ih8Fk.js} +1 -1
- package/dist/worker/console/static/assets/{kanban-definition-27J2QSJJ-Dz7ngC8z.js → kanban-definition-27J2QSJJ-C7yOSuRO.js} +1 -1
- package/dist/worker/console/static/assets/{linear-DI7Jv62E.js → linear-BDZ9riWi.js} +1 -1
- package/dist/worker/console/static/assets/{mermaid.core-CQA4Nzmo.js → mermaid.core-7pKqYtpZ.js} +5 -5
- package/dist/worker/console/static/assets/{mindmap-definition-FAOFIHXS-CtsMc8Mf.js → mindmap-definition-FAOFIHXS-LeJDybSU.js} +1 -1
- package/dist/worker/console/static/assets/{pegDiagram-VL7TDLO6-ByppE9yH.js → pegDiagram-VL7TDLO6-BJvT3pMD.js} +1 -1
- package/dist/worker/console/static/assets/{pieDiagram-7S7Q4E2Y-B5PtgFgt.js → pieDiagram-7S7Q4E2Y-_rGqpMan.js} +1 -1
- package/dist/worker/console/static/assets/{quadrantDiagram-CIZ2JOQS-Cq4p0k2K.js → quadrantDiagram-CIZ2JOQS-DPcSv5aA.js} +1 -1
- package/dist/worker/console/static/assets/{railroadDiagram-AXF67PYL-DjfkyljN.js → railroadDiagram-AXF67PYL-Drxx4hkJ.js} +1 -1
- package/dist/worker/console/static/assets/{requirementDiagram-LRYGKXZP-DzynNRSl.js → requirementDiagram-LRYGKXZP-BCTUdU4z.js} +1 -1
- package/dist/worker/console/static/assets/{sankeyDiagram-W5VNT64P-Cj7TCpTJ.js → sankeyDiagram-W5VNT64P-B6wzbZmB.js} +1 -1
- package/dist/worker/console/static/assets/{sequenceDiagram-SI44F4Z6-C73C6ykA.js → sequenceDiagram-SI44F4Z6-BGt8d3QQ.js} +1 -1
- package/dist/worker/console/static/assets/{sizeCapture-X5ZJPWSS-BiNLgN2x.js → sizeCapture-X5ZJPWSS-7nlhJKo7.js} +1 -1
- package/dist/worker/console/static/assets/{stateDiagram-OKZ733FA-UwvjS64-.js → stateDiagram-OKZ733FA-Cv2stqMA.js} +1 -1
- package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-DC7V5vcq.js +1 -0
- package/dist/worker/console/static/assets/{swimlanes-SLNWSIFB-CC7DH98r.js → swimlanes-SLNWSIFB-qDAo4Yc1.js} +2 -2
- package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-Bwy4QUTO.js +8 -0
- package/dist/worker/console/static/assets/{timeline-definition-Z64GVDOM-LSBXTR70.js → timeline-definition-Z64GVDOM-CKbDNKTr.js} +1 -1
- package/dist/worker/console/static/assets/{vennDiagram-T6HMQDX7-BAuxWwGP.js → vennDiagram-T6HMQDX7-DI-9EHic.js} +1 -1
- package/dist/worker/console/static/assets/{wardleyDiagram-T6FBY63Y--E5_gjZx.js → wardleyDiagram-T6FBY63Y-BrzzRDpX.js} +1 -1
- package/dist/worker/console/static/assets/{xychartDiagram-ELKLHX3M-dJWNmyzF.js → xychartDiagram-ELKLHX3M-BclH5hGh.js} +1 -1
- package/dist/worker/console/static/index.html +2 -2
- package/dist/worker/console/static-src/operator-chat/chat-sse-events.js +41 -11
- package/dist/worker/console/static-src/operator-chat/compaction-message.js +3 -17
- package/dist/worker/console/static-src/operator-chat/slash-palette-nav.js +15 -5
- package/dist/worker/console/static-src/operator-chat/timeline-merge.js +29 -0
- package/dist/worker/console/static-src/operator-chat/useChatThread.js +2 -5
- package/dist/worker/console/static-src/operator-chat/useRepoBrowser.js +2 -0
- package/dist/worker/console/static-src/prd-file-import.js +3 -1
- package/dist/worker/console/workspace-context.js +17 -1
- package/dist/worker/delivery/git-transaction.js +2 -0
- package/dist/worker/feature/fullstack-validate.js +2 -0
- package/dist/worker/loop-agent/loop-agent-client.js +8 -2
- package/dist/worker/materialize/harness-task-materializer.js +4 -1
- package/dist/worker/metrics/projector.js +1 -1
- package/dist/worker/observability/event-store.js +4 -1
- package/dist/worker/observability/read-model.js +4 -1
- package/dist/worker/observe/node-transparency.js +23 -1
- package/dist/worker/observe/routes.js +4 -0
- package/dist/worker/observe/static/operator-chrome.js +3 -1
- package/dist/worker/outcomes/declared-artifacts.js +2 -0
- package/dist/worker/preflight.js +3 -0
- package/dist/worker/scheduler/scheduled-goal-dispatch.js +117 -0
- package/dist/worker/scheduler/scheduled-goal-evidence.js +167 -0
- package/dist/worker/scheduler/scheduled-goal-recovery.js +62 -0
- package/dist/worker/scheduler/scheduled-goal-store.js +699 -0
- package/dist/worker/scheduler/scheduled-goal-supervisor.js +132 -0
- package/dist/worker/scheduler/scheduled-goal-time.js +102 -0
- package/dist/worker/scheduler/scheduled-goal-types.js +95 -0
- package/dist/worker/task-spec/validate.js +4 -1
- package/dist/workflows/dag/backend-test-markdown-workflow.js +6 -24
- package/dist/workflows/dag/backend-test-plan-protocol.js +82 -5
- package/dist/workflows/dag/dag-retry-schema.js +11 -0
- package/dist/workflows/dag/decision-envelope.js +2 -0
- package/dist/workflows/dag/dynamic-runtime/shared.js +2 -2
- package/dist/workflows/dag/frontend-closeout.js +4 -2
- package/dist/workflows/dag/frontend-committed-facts.js +461 -0
- package/dist/workflows/dag/frontend-durable-tools.js +15 -3
- package/dist/workflows/dag/frontend-implementation-contract.js +365 -8
- package/dist/workflows/dag/frontend-plan-canary.js +53 -0
- package/dist/workflows/dag/frontend-plan-decision-contract.js +803 -0
- package/dist/workflows/dag/frontend-plan-render.js +0 -2
- package/dist/workflows/dag/frontend-prewrite-gate.js +3 -3
- package/dist/workflows/dag/frontend-provider-capability-matrix.js +8 -61
- package/dist/workflows/dag/frontend-recovery-run.js +57 -0
- package/dist/workflows/dag/frontend-review-context.js +43 -70
- package/dist/workflows/dag/frontend-risk.js +92 -10
- package/dist/workflows/dag/frontend-session-budget.js +117 -3
- package/dist/workflows/dag/frontend-shape.js +11 -55
- package/dist/workflows/dag/frontend-test-execution-evidence.js +35 -10
- package/dist/workflows/dag/frontend-typed-event-store.js +32 -25
- package/dist/workflows/dag/frontend-verification-trace.js +25 -12
- package/dist/workflows/dag/frontend-writer-admission.js +3 -47
- package/dist/workflows/dag/frontend-writer-status.js +0 -23
- package/dist/workflows/dag/init-hybrid.js +202 -111
- package/dist/workflows/dag/interrupt-request.js +2 -0
- package/dist/workflows/dag/lifecycle.js +11 -2
- package/dist/workflows/dag/node-execution.js +50 -13
- package/dist/workflows/dag/reconcile-run.js +2 -0
- package/dist/workflows/dag/repair-artifact.js +3 -1
- package/dist/workflows/dag/report.js +2 -0
- package/dist/workflows/dag/rerun-plan.js +10 -0
- package/dist/workflows/dag/rerun-task.js +79 -1
- package/dist/workflows/dag/retry-policy.js +18 -0
- package/dist/workflows/dag/scheduler.js +2 -4
- package/dist/workflows/dag/types.js +44 -6
- package/dist/workflows/dag/validate.js +4 -0
- package/docs/README.md +1 -0
- package/docs/governance/README.md +1 -0
- package/docs/init-surface.manifest.json +1 -0
- package/docs/operations/README.md +2 -0
- package/docs/templates/README.md +1 -1
- package/docs/templates/agent-dag.schema.json +2 -2
- package/docs/templates/backend-test-dag.json +14 -10
- package/docs/templates/frontend-implementation-contract.schema.json +0 -7
- package/docs/templates/frontend-implementation-dag.json +8 -9
- package/package.json +8 -3
- package/skills/frontend-bounded-implement/SKILL.md +3 -4
- package/skills/frontend-design-review/SKILL.md +7 -12
- package/skills/frontend-design-review/references/review-checklist.md +7 -7
- package/skills/frontend-plan/SKILL.md +8 -18
- package/skills/frontend-plan/references/decision-contract.md +19 -26
- package/skills/frontend-review/SKILL.md +21 -25
- package/skills/frontend-review/references/review-findings.md +48 -24
- package/dist/worker/console/static/assets/channel-BxdTlb_5.js +0 -1
- package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-_ByA1Nf8.js +0 -1
- package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-_ByA1Nf8.js +0 -1
- package/dist/worker/console/static/assets/index-B9goN3S5.css +0 -1
- package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-nLgMZ0D3.js +0 -1
- package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-BcYqTady.js +0 -8
- package/dist/workflows/dag/frontend-shadow-dual-write.js +0 -975
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Turn grouping for Operator Chat inline process UX (pi-web ProcessDetails mind).
|
|
3
3
|
*/
|
|
4
|
+
import { compareChatOrder } from "./turn-order.js";
|
|
4
5
|
import { getDisplayableAssistantBlocks, joinAssistantText, parseAssistantContent, splitFinalAssistantBlocks, } from "./assistant-content.js";
|
|
5
6
|
import { dagProgressActivityForTool, semanticActivityForTool, } from "./semantic-activity.js";
|
|
6
7
|
function emptyGroup(key) {
|
|
@@ -264,13 +265,14 @@ function fillProcessDetails(group) {
|
|
|
264
265
|
items,
|
|
265
266
|
});
|
|
266
267
|
}
|
|
267
|
-
|
|
268
|
+
// Unified order (DSH rule): server seq is the single authoritative key,
|
|
269
|
+
// createdAt falls back, insertion order breaks remaining ties. No
|
|
270
|
+
// "fullySequenced" switch — a partially-sequenced group must not
|
|
271
|
+
// silently re-sort its peers by wall clock when most nodes carry seq.
|
|
268
272
|
nodes.sort((a, b) => {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
if (a.createdAt !== b.createdAt)
|
|
273
|
-
return a.createdAt - b.createdAt;
|
|
273
|
+
const byOrder = compareChatOrder(a, b);
|
|
274
|
+
if (byOrder !== 0)
|
|
275
|
+
return byOrder;
|
|
274
276
|
return a.insertionOrder - b.insertionOrder;
|
|
275
277
|
});
|
|
276
278
|
const processItems = nodes.flatMap((node) => node.items);
|
|
@@ -301,20 +303,7 @@ function fillProcessDetails(group) {
|
|
|
301
303
|
export function buildTurnProcessGroups(input) {
|
|
302
304
|
const visible = input.messages
|
|
303
305
|
.filter((m) => m.role === "user" || m.role === "assistant")
|
|
304
|
-
.sort(
|
|
305
|
-
if (a.eventSeq !== undefined &&
|
|
306
|
-
b.eventSeq !== undefined &&
|
|
307
|
-
a.eventSeq !== b.eventSeq) {
|
|
308
|
-
return a.eventSeq - b.eventSeq;
|
|
309
|
-
}
|
|
310
|
-
if (a.createdAt !== b.createdAt)
|
|
311
|
-
return a.createdAt - b.createdAt;
|
|
312
|
-
if (a.eventSeq !== undefined && b.eventSeq === undefined)
|
|
313
|
-
return 1;
|
|
314
|
-
if (a.eventSeq === undefined && b.eventSeq !== undefined)
|
|
315
|
-
return -1;
|
|
316
|
-
return 0;
|
|
317
|
-
});
|
|
306
|
+
.sort(compareChatOrder);
|
|
318
307
|
const groups = [];
|
|
319
308
|
let current = null;
|
|
320
309
|
const startGroup = (key) => {
|
|
@@ -326,6 +315,8 @@ export function buildTurnProcessGroups(input) {
|
|
|
326
315
|
if (message.role === "user") {
|
|
327
316
|
current = startGroup(`user-${message.id}`);
|
|
328
317
|
current.user = message;
|
|
318
|
+
if (message.turnId)
|
|
319
|
+
current.turnId = message.turnId;
|
|
329
320
|
continue;
|
|
330
321
|
}
|
|
331
322
|
if (message.kind === "compaction") {
|
|
@@ -333,12 +324,16 @@ export function buildTurnProcessGroups(input) {
|
|
|
333
324
|
// prevents it from replacing the previous turn's assistant answer.
|
|
334
325
|
current = startGroup(`compaction-${message.id}`);
|
|
335
326
|
current.assistants.push(message);
|
|
327
|
+
if (message.turnId)
|
|
328
|
+
current.turnId = message.turnId;
|
|
336
329
|
current = null;
|
|
337
330
|
continue;
|
|
338
331
|
}
|
|
339
332
|
if (!current)
|
|
340
333
|
current = startGroup(`assistant-${message.id}`);
|
|
341
334
|
current.assistants.push(message);
|
|
335
|
+
if (current.turnId === undefined && message.turnId)
|
|
336
|
+
current.turnId = message.turnId;
|
|
342
337
|
}
|
|
343
338
|
const assigned = new Set();
|
|
344
339
|
const assistantToGroup = new Map();
|
|
@@ -360,10 +355,10 @@ export function buildTurnProcessGroups(input) {
|
|
|
360
355
|
if (assigned.has(tool.id))
|
|
361
356
|
continue;
|
|
362
357
|
if (tool.turnId) {
|
|
363
|
-
const byTurn = groups.find((group) => group.
|
|
358
|
+
const byTurn = groups.find((group) => group.turnId === tool.turnId ||
|
|
359
|
+
group.user?.turnId === tool.turnId ||
|
|
364
360
|
group.assistants.some((assistant) => assistant.turnId === tool.turnId) ||
|
|
365
361
|
group.tools.some((t) => t.turnId === tool.turnId) ||
|
|
366
|
-
group.key === `turn-${tool.turnId}` ||
|
|
367
362
|
(group.user && `restored-${group.user.id}` === tool.turnId));
|
|
368
363
|
if (byTurn) {
|
|
369
364
|
byTurn.tools.push(tool);
|
|
@@ -379,13 +374,25 @@ export function buildTurnProcessGroups(input) {
|
|
|
379
374
|
}
|
|
380
375
|
}
|
|
381
376
|
}
|
|
377
|
+
// Time-window fallback for legacy rows with neither assistantMessageId nor
|
|
378
|
+
// turnId. The window ends at the NEXT group's first anchor (user OR first
|
|
379
|
+
// assistant) — using POSITIVE_INFINITY would swallow every later group's
|
|
380
|
+
// tools when the very next group has no user message (e.g. compaction or a
|
|
381
|
+
// stand-alone assistant row), dumping one turn's bash cards into another.
|
|
382
382
|
for (const tool of input.toolCalls) {
|
|
383
383
|
if (assigned.has(tool.id))
|
|
384
384
|
continue;
|
|
385
385
|
const windowGroup = groups.find((group, index) => {
|
|
386
386
|
const start = group.user?.createdAt ?? group.assistants[0]?.createdAt ?? 0;
|
|
387
|
-
|
|
388
|
-
|
|
387
|
+
let end = Number.POSITIVE_INFINITY;
|
|
388
|
+
for (let i = index + 1; i < groups.length; i += 1) {
|
|
389
|
+
const next = groups[i];
|
|
390
|
+
const nextAnchor = next?.user?.createdAt ?? next?.assistants[0]?.createdAt;
|
|
391
|
+
if (nextAnchor !== undefined) {
|
|
392
|
+
end = nextAnchor;
|
|
393
|
+
break;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
389
396
|
return tool.createdAt >= start && tool.createdAt < end;
|
|
390
397
|
});
|
|
391
398
|
// Time window only. Never dump unmatched tools onto the latest group:
|
|
@@ -396,12 +403,7 @@ export function buildTurnProcessGroups(input) {
|
|
|
396
403
|
}
|
|
397
404
|
}
|
|
398
405
|
for (const group of groups) {
|
|
399
|
-
group.tools.sort(
|
|
400
|
-
if (a.eventSeq !== undefined && b.eventSeq !== undefined) {
|
|
401
|
-
return a.eventSeq - b.eventSeq;
|
|
402
|
-
}
|
|
403
|
-
return a.createdAt - b.createdAt;
|
|
404
|
-
});
|
|
406
|
+
group.tools.sort(compareChatOrder);
|
|
405
407
|
group.live =
|
|
406
408
|
input.streaming &&
|
|
407
409
|
input.activeAssistantId !== null &&
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { prepareScheduledTask } from "./chat/scheduled-goal-request.js";
|
|
2
|
+
import { ScheduledGoalStore } from "../scheduler/scheduled-goal-store.js";
|
|
3
|
+
import { prepareScheduledGoalBooking, confirmScheduledGoalBooking, getScheduledGoalBooking } from "./chat/scheduled-goal-booking.js";
|
|
1
4
|
import { access, readFile } from "node:fs/promises";
|
|
2
5
|
import { buildOperatorCapabilitiesDocument, OFFICIAL_TAIL_ACTION_IDS, } from "../../shared/operator/capabilities.js";
|
|
3
6
|
import { DAG_RERUN_PROMPT_OVERRIDE_ENV, isDagRerunPromptOverrideEnabled, MAX_DAG_RERUN_PROMPT_OVERRIDE_CHARS, } from "../../shared/dag-prompt-override.js";
|
|
@@ -886,6 +889,52 @@ export async function dispatchOperatorAction(ctx, req) {
|
|
|
886
889
|
}
|
|
887
890
|
return acceptConsoleUpdateAndInit(ctx, req.clientRequestId, channel);
|
|
888
891
|
}
|
|
892
|
+
if (["prepareScheduledTask", "prepareScheduledGoal", "confirmScheduledGoal", "scheduledGoalGet", "scheduledGoalList", "cancelScheduledGoal"].includes(action)) {
|
|
893
|
+
try {
|
|
894
|
+
const goals = new ScheduledGoalStore(ctx.repoRoot);
|
|
895
|
+
const { ChatSessionStore } = await import("./chat/session-store.js");
|
|
896
|
+
const deps = { goals, client: ctx.client, sessions: new ChatSessionStore(ctx.appData) };
|
|
897
|
+
let result;
|
|
898
|
+
if (action === "prepareScheduledTask") {
|
|
899
|
+
if (!ctx.chatSessionRef || Object.keys(p).some((key) => key !== "request"))
|
|
900
|
+
return invalid(action, "requires a host-bound Chat session and request only");
|
|
901
|
+
result = await prepareScheduledTask(p.request, { repoRoot: ctx.repoRoot, preparationRoot: nodePath.join(ctx.appData.staged, "scheduled-tasks"),
|
|
902
|
+
sessionId: ctx.chatSessionRef, client: ctx.client, sessions: deps.sessions });
|
|
903
|
+
}
|
|
904
|
+
else if (action === "prepareScheduledGoal") {
|
|
905
|
+
if (Object.keys(p).some((key) => key !== "booking"))
|
|
906
|
+
return invalid(action, "only booking may be provided");
|
|
907
|
+
result = await prepareScheduledGoalBooking(p.booking, deps);
|
|
908
|
+
}
|
|
909
|
+
else if (action === "confirmScheduledGoal") {
|
|
910
|
+
result = await confirmScheduledGoalBooking(p, deps, { source: req.source, requestId: req.clientRequestId });
|
|
911
|
+
}
|
|
912
|
+
else if (action === "cancelScheduledGoal") {
|
|
913
|
+
if (req.source !== "human-ui" || !req.clientRequestId?.trim())
|
|
914
|
+
return invalid(action, "human cancellation required");
|
|
915
|
+
if (Object.keys(p).some((key) => !["goalId", "stateVersion", "reason"].includes(key)) ||
|
|
916
|
+
typeof p.goalId !== "string" || !Number.isSafeInteger(p.stateVersion) || typeof p.reason !== "string")
|
|
917
|
+
return invalid(action, "goalId, stateVersion and reason required");
|
|
918
|
+
await goals.cancel(p.goalId, p.stateVersion, req.clientRequestId, p.reason);
|
|
919
|
+
result = await getScheduledGoalBooking(p.goalId, goals);
|
|
920
|
+
}
|
|
921
|
+
else if (action === "scheduledGoalGet") {
|
|
922
|
+
if (Object.keys(p).some((key) => key !== "goalId") || typeof p.goalId !== "string")
|
|
923
|
+
return invalid(action, "goalId required");
|
|
924
|
+
result = await getScheduledGoalBooking(p.goalId, goals);
|
|
925
|
+
}
|
|
926
|
+
else {
|
|
927
|
+
if (Object.keys(p).some((key) => key !== "chatSessionRef") || (p.chatSessionRef !== undefined && typeof p.chatSessionRef !== "string"))
|
|
928
|
+
return invalid(action, "only optional chatSessionRef may be provided");
|
|
929
|
+
const records = (await goals.list()).filter((goal) => !p.chatSessionRef || goal.frozen.chatSessionRef === p.chatSessionRef);
|
|
930
|
+
result = await Promise.all(records.map((goal) => getScheduledGoalBooking(goal.goalId, goals)));
|
|
931
|
+
}
|
|
932
|
+
return { kind: "sync", status: 200, body: operatorSucceeded(action, result) };
|
|
933
|
+
}
|
|
934
|
+
catch (error) {
|
|
935
|
+
return invalid(action, error instanceof Error ? error.message : String(error));
|
|
936
|
+
}
|
|
937
|
+
}
|
|
889
938
|
switch (action) {
|
|
890
939
|
case "operatorCapabilities": {
|
|
891
940
|
const doc = buildOperatorCapabilitiesDocument();
|
|
@@ -1077,6 +1126,7 @@ export async function dispatchOperatorAction(ctx, req) {
|
|
|
1077
1126
|
const args = ["dag", "doctor"];
|
|
1078
1127
|
if (runId)
|
|
1079
1128
|
args.push("--run-id", runId);
|
|
1129
|
+
args.push("--json");
|
|
1080
1130
|
const body = await runReadCli(ctx, args, "dag doctor");
|
|
1081
1131
|
return { kind: "sync", status: body.ok ? 200 : 400, body };
|
|
1082
1132
|
}
|
|
@@ -119,6 +119,33 @@ export function parseEngineeringBoundaryFromParams(p) {
|
|
|
119
119
|
};
|
|
120
120
|
const allowedPaths = asList(p.allowedPaths ?? p.allowedPath);
|
|
121
121
|
const forbiddenPaths = asList(p.forbiddenPaths ?? p.forbiddenPath);
|
|
122
|
+
const capabilityBoundaryRaw = p.capabilityBoundary;
|
|
123
|
+
const capabilityBoundary = capabilityBoundaryRaw && typeof capabilityBoundaryRaw === "object" && !Array.isArray(capabilityBoundaryRaw)
|
|
124
|
+
? {
|
|
125
|
+
allowed: Array.isArray(capabilityBoundaryRaw.allowed)
|
|
126
|
+
? capabilityBoundaryRaw.allowed.filter((x) => typeof x === "string" && x.trim().length > 0)
|
|
127
|
+
: undefined,
|
|
128
|
+
forbidden: Array.isArray(capabilityBoundaryRaw.forbidden)
|
|
129
|
+
? capabilityBoundaryRaw.forbidden.filter((x) => typeof x === "string" && x.trim().length > 0)
|
|
130
|
+
: undefined,
|
|
131
|
+
}
|
|
132
|
+
: undefined;
|
|
133
|
+
const interactionIds = asList(p.interactionIds ?? p.interactionId);
|
|
134
|
+
const requirementOwnership = Array.isArray(p.requirementOwnership)
|
|
135
|
+
? p.requirementOwnership
|
|
136
|
+
.map((entry) => ({
|
|
137
|
+
requirementIds: Array.isArray(entry.requirementIds)
|
|
138
|
+
? entry.requirementIds.filter((id) => typeof id === "string" && id.trim().length > 0)
|
|
139
|
+
: [],
|
|
140
|
+
implementationFiles: Array.isArray(entry.implementationFiles)
|
|
141
|
+
? entry.implementationFiles.filter((f) => typeof f === "string" && f.trim().length > 0)
|
|
142
|
+
: undefined,
|
|
143
|
+
verificationFiles: Array.isArray(entry.verificationFiles)
|
|
144
|
+
? entry.verificationFiles.filter((f) => typeof f === "string" && f.trim().length > 0)
|
|
145
|
+
: undefined,
|
|
146
|
+
}))
|
|
147
|
+
.filter((entry) => entry.requirementIds.length > 0)
|
|
148
|
+
: undefined;
|
|
122
149
|
const verifyRaw = p.verifyCommands ?? p.verify;
|
|
123
150
|
const verifyCommands = [];
|
|
124
151
|
if (Array.isArray(verifyRaw)) {
|
|
@@ -175,6 +202,11 @@ export function parseEngineeringBoundaryFromParams(p) {
|
|
|
175
202
|
...(allowedPaths.length > 0 ? { allowedPaths } : {}),
|
|
176
203
|
...(forbiddenPaths.length > 0 ? { forbiddenPaths } : {}),
|
|
177
204
|
...(verifyCommands.length > 0 ? { verifyCommands } : {}),
|
|
205
|
+
...(requirementOwnership?.length ? { requirementOwnership } : {}),
|
|
206
|
+
...(capabilityBoundary && ((capabilityBoundary.allowed?.length ?? 0) + (capabilityBoundary.forbidden?.length ?? 0)) > 0
|
|
207
|
+
? { capabilityBoundary }
|
|
208
|
+
: {}),
|
|
209
|
+
...(interactionIds.length > 0 ? { interactionIds } : {}),
|
|
178
210
|
};
|
|
179
211
|
}
|
|
180
212
|
export function appendEngineeringCliArgs(args, boundary) {
|
|
@@ -187,17 +219,38 @@ export function appendEngineeringCliArgs(args, boundary) {
|
|
|
187
219
|
for (const cmd of boundary.verifyCommands ?? []) {
|
|
188
220
|
args.push("--verify", `${cmd.label}:${cmd.command}`);
|
|
189
221
|
}
|
|
222
|
+
if (boundary.requirementOwnership?.length) {
|
|
223
|
+
args.push("--requirement-ownership", JSON.stringify(boundary.requirementOwnership));
|
|
224
|
+
}
|
|
225
|
+
if (boundary.capabilityBoundary) {
|
|
226
|
+
args.push("--capability-boundary", JSON.stringify(boundary.capabilityBoundary));
|
|
227
|
+
}
|
|
228
|
+
for (const id of boundary.interactionIds ?? []) {
|
|
229
|
+
args.push("--interaction-ids", id);
|
|
230
|
+
}
|
|
190
231
|
}
|
|
191
232
|
export function applyEngineeringBoundaryToDraft(draft, boundary) {
|
|
192
233
|
const allowedPaths = filterPlaceholderPaths(boundary.allowedPaths);
|
|
193
234
|
const forbiddenPaths = filterPlaceholderPaths(boundary.forbiddenPaths);
|
|
194
235
|
if (allowedPaths.length === 0 &&
|
|
195
236
|
forbiddenPaths.length === 0 &&
|
|
196
|
-
!(boundary.verifyCommands?.length)
|
|
237
|
+
!(boundary.verifyCommands?.length) &&
|
|
238
|
+
!(boundary.requirementOwnership?.length) &&
|
|
239
|
+
!boundary.capabilityBoundary &&
|
|
240
|
+
!(boundary.interactionIds?.length)) {
|
|
197
241
|
return draft;
|
|
198
242
|
}
|
|
199
243
|
return {
|
|
200
244
|
...draft,
|
|
245
|
+
...(boundary.requirementOwnership?.length
|
|
246
|
+
? { requirementOwnership: boundary.requirementOwnership }
|
|
247
|
+
: {}),
|
|
248
|
+
...(boundary.capabilityBoundary
|
|
249
|
+
? { capabilityBoundary: boundary.capabilityBoundary }
|
|
250
|
+
: {}),
|
|
251
|
+
...(boundary.interactionIds?.length
|
|
252
|
+
? { interactionIds: boundary.interactionIds }
|
|
253
|
+
: {}),
|
|
201
254
|
constraints: {
|
|
202
255
|
invariants: draft.constraints?.invariants ?? [],
|
|
203
256
|
allowedPaths: allowedPaths.length > 0
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { dispatchScheduledGoalOperation } from "./scheduled-goal-operation-adapter.js";
|
|
2
|
+
import { assessScheduledGoal, continueScheduledGoal } from "../scheduler/scheduled-goal-supervisor.js";
|
|
3
|
+
import { evaluateScheduledGoalWake } from "../scheduler/scheduled-goal-time.js";
|
|
4
|
+
/** Background operation ownership, independent of a browser or an interactive Chat turn.
|
|
5
|
+
* Every wake rebuilds decisions from the ledger; timers carry no authorization.
|
|
6
|
+
* No stale takeover: reserved work is observed, never re-issued.
|
|
7
|
+
*/
|
|
8
|
+
export class ScheduledGoalHost {
|
|
9
|
+
deps;
|
|
10
|
+
timer;
|
|
11
|
+
active;
|
|
12
|
+
stopped = true;
|
|
13
|
+
constructor(deps) {
|
|
14
|
+
this.deps = deps;
|
|
15
|
+
if (deps.intervalMs !== undefined && (!Number.isFinite(deps.intervalMs) || deps.intervalMs < 100))
|
|
16
|
+
throw new Error("invalid scheduled goal wake interval");
|
|
17
|
+
}
|
|
18
|
+
start() {
|
|
19
|
+
if (!this.stopped)
|
|
20
|
+
return;
|
|
21
|
+
this.stopped = false;
|
|
22
|
+
this.wake();
|
|
23
|
+
}
|
|
24
|
+
/** Nonblocking. The host retains the operation promise until it settles. */
|
|
25
|
+
wake() {
|
|
26
|
+
if (this.stopped || this.active)
|
|
27
|
+
return;
|
|
28
|
+
if (this.timer) {
|
|
29
|
+
clearTimeout(this.timer);
|
|
30
|
+
this.timer = undefined;
|
|
31
|
+
}
|
|
32
|
+
this.active = this.tick().catch((error) => this.deps.onError?.(undefined, error)).finally(() => {
|
|
33
|
+
this.active = undefined;
|
|
34
|
+
if (!this.stopped) {
|
|
35
|
+
this.timer = setTimeout(() => { this.timer = undefined; this.wake(); }, this.deps.intervalMs ?? 5000);
|
|
36
|
+
this.timer.unref?.();
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/** Stop future admissions. Existing children keep their operation ownership. */
|
|
41
|
+
stop() {
|
|
42
|
+
this.stopped = true;
|
|
43
|
+
if (this.timer)
|
|
44
|
+
clearTimeout(this.timer);
|
|
45
|
+
this.timer = undefined;
|
|
46
|
+
}
|
|
47
|
+
async waitForIdle() { await this.active; }
|
|
48
|
+
async tick() {
|
|
49
|
+
for (const snapshot of await this.deps.goals.list()) {
|
|
50
|
+
if (this.stopped)
|
|
51
|
+
return;
|
|
52
|
+
try {
|
|
53
|
+
await this.advance(snapshot.goalId);
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
this.deps.onError?.(snapshot.goalId, error);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async advance(goalId) {
|
|
61
|
+
const { goals } = this.deps;
|
|
62
|
+
let goal = await goals.get(goalId);
|
|
63
|
+
if (!goal.approval)
|
|
64
|
+
return;
|
|
65
|
+
const intent = goal.intents.at(-1);
|
|
66
|
+
if (intent && ["dispatching", "associated", "unknown"].includes(intent.state)) {
|
|
67
|
+
await dispatchScheduledGoalOperation(goalId, this.deps);
|
|
68
|
+
goal = await goals.get(goalId);
|
|
69
|
+
}
|
|
70
|
+
if (this.stopped)
|
|
71
|
+
return;
|
|
72
|
+
if (["cancelled", "blocked", "budget_exhausted", "unknown"].includes(goal.state)) {
|
|
73
|
+
await this.deps.deliver?.(goal);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
goal = await goals.refreshAcceptance(goalId);
|
|
77
|
+
goal = await goals.settleIdleGoal(goalId, this.deps.now?.());
|
|
78
|
+
if (["accepted", "cancelled", "blocked", "budget_exhausted", "unknown"].includes(goal.state)) {
|
|
79
|
+
await this.deps.deliver?.(goal);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (goal.assessmentAttempt || goal.supervisions.some((entry) => ["requested", "preparing", "unknown"].includes(entry.state)))
|
|
83
|
+
return;
|
|
84
|
+
const current = goal.intents.at(-1);
|
|
85
|
+
if (!current || current.state === "prepared") {
|
|
86
|
+
if (evaluateScheduledGoalWake(goal.frozen.time, this.deps.now?.() ?? new Date()).kind === "due")
|
|
87
|
+
await dispatchScheduledGoalOperation(goalId, this.deps);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (current.state !== "terminal")
|
|
91
|
+
return;
|
|
92
|
+
if (goal.acceptanceState === "failed") {
|
|
93
|
+
await continueScheduledGoal(goalId, goals, this.deps.client);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
await assessScheduledGoal(goalId, goals, { now: this.deps.now });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { readFile, realpath } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { scheduledGoalHash } from "../scheduler/scheduled-goal-store.js";
|
|
5
|
+
import { evaluateScheduledGoalWake } from "../scheduler/scheduled-goal-time.js";
|
|
6
|
+
import { prepareScheduledGoalDraft } from "../scheduler/scheduled-goal-dispatch.js";
|
|
7
|
+
import { captureScheduledGoalTree } from "../scheduler/scheduled-goal-evidence.js";
|
|
8
|
+
import { runOperation } from "./operation-runner.js";
|
|
9
|
+
/** Only operation facts can settle an intent. Missing associations never authorize a retry. */
|
|
10
|
+
async function observe(goal, intent, deps) {
|
|
11
|
+
const operation = await deps.operations.get(intent.operationId);
|
|
12
|
+
// A second wake can arrive between intent commit and operation save/spawn.
|
|
13
|
+
// Liveness only defers an unknown projection: it never grants execution rights
|
|
14
|
+
// or authorizes takeover (PID reuse can only cause conservative extra waiting).
|
|
15
|
+
const associationPending = !operation || ["queued", "starting", "running"].includes(operation.state);
|
|
16
|
+
if (intent.state === "dispatching" && associationPending && !operation?.dagRunId && intent.dispatchOwnerPid) {
|
|
17
|
+
try {
|
|
18
|
+
process.kill(intent.dispatchOwnerPid, 0);
|
|
19
|
+
return { kind: "observing", operation };
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
if (error.code !== "ESRCH")
|
|
23
|
+
return { kind: "observing", operation };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const state = operation?.state === "succeeded" ? "succeeded"
|
|
27
|
+
: operation?.state === "failed" || operation?.state === "timed-out" ? "failed"
|
|
28
|
+
: operation?.state === "running" ? "running" : "unknown";
|
|
29
|
+
await deps.goals.observeOperation(goal.goalId, intent.intentId, intent.ownerToken, {
|
|
30
|
+
operationId: intent.operationId, runId: operation?.dagRunId, state,
|
|
31
|
+
observedAt: (deps.now?.() ?? new Date()).toISOString(),
|
|
32
|
+
});
|
|
33
|
+
const linkedTerminal = operation?.dagRunId === intent.runId && (state === "succeeded" || state === "failed");
|
|
34
|
+
return { kind: linkedTerminal ? "settled" : "observing", operation };
|
|
35
|
+
}
|
|
36
|
+
function taskDraft(goal, intent) {
|
|
37
|
+
return intent?.derived ? { ...goal.frozen, managedTaskId: intent.derived.managedTaskId, prepared: intent.derived.prepared } : goal.frozen;
|
|
38
|
+
}
|
|
39
|
+
async function verifyPrepared(goal, deps, intent) {
|
|
40
|
+
const frozen = taskDraft(goal, intent);
|
|
41
|
+
if (intent?.derived) {
|
|
42
|
+
const tree = await captureScheduledGoalTree(frozen.worktreeRef, frozen.frozenBase, frozen.allowedPaths, frozen.forbiddenPaths);
|
|
43
|
+
if (tree.treeHash !== intent.derived.treeHash || tree.scopeViolations.length)
|
|
44
|
+
throw new Error("derived dispatch tree drift");
|
|
45
|
+
}
|
|
46
|
+
const identity = deps.client.getIdentity();
|
|
47
|
+
if (!identity || identity.packageFingerprint.value !== frozen.controllerRef)
|
|
48
|
+
throw new Error("scheduled goal controller binding mismatch");
|
|
49
|
+
const root = await realpath(frozen.worktreeRef);
|
|
50
|
+
for (const [ref, expected] of [
|
|
51
|
+
[frozen.prepared.dagPath, frozen.prepared.dagHash],
|
|
52
|
+
[frozen.prepared.contractPath, frozen.prepared.contractHash],
|
|
53
|
+
]) {
|
|
54
|
+
if (path.isAbsolute(ref))
|
|
55
|
+
throw new Error("scheduled goal artifact must be worktree-relative");
|
|
56
|
+
const file = await realpath(path.resolve(root, ref));
|
|
57
|
+
const relative = path.relative(root, file);
|
|
58
|
+
if (!relative || relative === ".." || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative))
|
|
59
|
+
throw new Error("scheduled goal artifact escapes worktree");
|
|
60
|
+
const actual = createHash("sha256").update(await readFile(file)).digest("hex");
|
|
61
|
+
if (actual !== expected)
|
|
62
|
+
throw new Error("scheduled goal prepared artifact drift");
|
|
63
|
+
}
|
|
64
|
+
const { prepared: _prepared, controllerRef: _controllerRef, ...input } = frozen;
|
|
65
|
+
const current = await prepareScheduledGoalDraft(input, deps.client);
|
|
66
|
+
if (scheduledGoalHash(current.prepared) !== scheduledGoalHash(frozen.prepared))
|
|
67
|
+
throw new Error("scheduled goal managed gate drift");
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Headless adapter to the existing operation runner; no second executor.
|
|
71
|
+
* The host awaits this operation in the background. Reopening only observes an
|
|
72
|
+
* already-dispatched intent, even when the operation is queued or missing.
|
|
73
|
+
*/
|
|
74
|
+
export async function dispatchScheduledGoalOperation(goalId, deps) {
|
|
75
|
+
const goal = await deps.goals.get(goalId);
|
|
76
|
+
const prior = goal.intents.at(-1);
|
|
77
|
+
if (prior && prior.state !== "prepared")
|
|
78
|
+
return observe(goal, prior, deps);
|
|
79
|
+
await verifyPrepared(goal, deps, prior);
|
|
80
|
+
const claim = await deps.goals.claim(goalId, deps.now?.());
|
|
81
|
+
if (claim.kind !== "claimed" && claim.kind !== "existing")
|
|
82
|
+
return claim;
|
|
83
|
+
const intent = claim.intent;
|
|
84
|
+
const frozen = taskDraft(goal, intent);
|
|
85
|
+
if (!await deps.goals.beginDispatch(goalId, intent.intentId, intent.ownerToken, deps.now?.()))
|
|
86
|
+
return { kind: "waiting" };
|
|
87
|
+
try {
|
|
88
|
+
// Intent identity is durable before creating an operation. An existing file
|
|
89
|
+
// is evidence of a previous attempt, not permission to call runOperation again.
|
|
90
|
+
if (await deps.operations.get(intent.operationId))
|
|
91
|
+
return observe(goal, intent, deps);
|
|
92
|
+
const cliArgs = ["task", "advance", frozen.managedTaskId, "--approve-gate", frozen.prepared.gateToken,
|
|
93
|
+
"--run-id", intent.runId, "--max-concurrent", "1", "--skip-finalize", "--json"];
|
|
94
|
+
const actionParams = { goalId, goalRevision: goal.goalRevision, intentId: intent.intentId,
|
|
95
|
+
taskRevision: intent.taskRevision, turnSeq: intent.turnSeq, envelopeHash: goal.envelopeHash };
|
|
96
|
+
const operation = {
|
|
97
|
+
schemaVersion: 1, revision: 1, operationId: intent.operationId, clientRequestId: intent.idempotencyKey,
|
|
98
|
+
action: "taskAdvance", actionParams, payloadHash: scheduledGoalHash({ actionParams, cliArgs }),
|
|
99
|
+
state: "queued", createdAt: (deps.now?.() ?? new Date()).toISOString(), taskId: frozen.managedTaskId, cliArgs,
|
|
100
|
+
};
|
|
101
|
+
await deps.operations.save(operation);
|
|
102
|
+
await runOperation(intent.operationId, {
|
|
103
|
+
store: deps.operations, client: deps.client, events: deps.events, repoRoot: goal.frozen.worktreeRef,
|
|
104
|
+
env: deps.env, defaultTimeoutMs: 0,
|
|
105
|
+
runCommand: async (args, options) => {
|
|
106
|
+
await verifyPrepared(goal, deps, intent);
|
|
107
|
+
const current = await deps.goals.get(goalId);
|
|
108
|
+
const owned = current.intents.find((item) => item.intentId === intent.intentId);
|
|
109
|
+
if (current.state !== "admitted" || owned?.state !== "dispatching" || owned.ownerToken !== intent.ownerToken)
|
|
110
|
+
throw new Error("scheduled goal dispatch ownership lost");
|
|
111
|
+
if (evaluateScheduledGoalWake(current.frozen.time, deps.now?.() ?? new Date()).kind !== "due")
|
|
112
|
+
throw new Error("scheduled goal authorization window closed before spawn");
|
|
113
|
+
// LoopAgentClient additionally revalidates binary/package identity before spawn.
|
|
114
|
+
return deps.client.run(args, options);
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
// The durable dispatch may have produced a child. Preserve its reservation
|
|
120
|
+
// and use store facts; never infer "not started" from a missing callback.
|
|
121
|
+
await deps.goals.observeOperation(goalId, intent.intentId, intent.ownerToken, {
|
|
122
|
+
operationId: intent.operationId, state: "unknown", observedAt: (deps.now?.() ?? new Date()).toISOString(),
|
|
123
|
+
});
|
|
124
|
+
return { kind: "observing", operation: await deps.operations.get(intent.operationId) };
|
|
125
|
+
}
|
|
126
|
+
return observe(goal, intent, deps);
|
|
127
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ScheduledGoalStore } from "../scheduler/scheduled-goal-store.js";
|
|
1
2
|
import { randomBytes } from "node:crypto";
|
|
2
3
|
import { spawn } from "node:child_process";
|
|
3
4
|
import { existsSync } from "node:fs";
|
|
@@ -183,6 +184,20 @@ export async function createConsoleServer(options) {
|
|
|
183
184
|
throw new Error(`console serve: failed to create startup workspace context: ${startupResolution.message}`);
|
|
184
185
|
}
|
|
185
186
|
const startup = startupResolution.context;
|
|
187
|
+
// Scheduled authorization belongs to its workspace, not the last browser tab.
|
|
188
|
+
// Restore booked workspaces even when the original Chat/workspace is hidden.
|
|
189
|
+
for (const record of await registry.listAll()) {
|
|
190
|
+
if (record.workspaceId === startupRecord.workspaceId)
|
|
191
|
+
continue;
|
|
192
|
+
try {
|
|
193
|
+
const goals = await new ScheduledGoalStore(record.repoRoot).list();
|
|
194
|
+
if (goals.some((goal) => Boolean(goal.approval)))
|
|
195
|
+
await materializeContext(record);
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
process.stderr.write(`[scheduled-goal] workspace recovery ${record.workspaceId}: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
186
201
|
const requestConsoleHandoff = async (targetVersion) => {
|
|
187
202
|
const packageRoot = resolvePackageRootFromConsole();
|
|
188
203
|
const agentWorkerBin = path.join(packageRoot, "bin", "agent-worker.js");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{g as p,r as u,d as a}from"./chunk-6Q2QTUOP-
|
|
1
|
+
import{g as p,r as u,d as a}from"./chunk-6Q2QTUOP-DLT_cYx1.js";import{p as f}from"./chunk-JWPE2WC7-V1EqXdjY.js";import{_ as n,l as o}from"./mermaid.core-7pKqYtpZ.js";import{M as c,b as d}from"./cynefin-VYW2F7L2-BXa_dcu4.js";import"./index-Cdkvw_H6.js";var v=d().RailroadAbnf.parser.LangiumParser,i=n(e=>{const r=e.alternatives.map(g);return r.length===1?r[0]:{type:"choice",alternatives:r}},"transformAlternation"),g=n(e=>{const r=e.elements.map(y);return r.length===1?r[0]:{type:"sequence",elements:r}},"transformConcatenation"),b=n(e=>{if(e.includes("*")){const[t,s]=e.split("*"),l=t?parseInt(t,10):0,m=s?parseInt(s,10):1/0;return{min:l,max:m}}const r=parseInt(e,10);return{min:r,max:r}},"parseRepeat"),y=n(e=>{const r=A(e.primary);if(!e.repeat)return r;const{min:t,max:s}=b(e.repeat);return t===0&&s===1?{type:"optional",element:r}:{type:"repetition",element:r,min:t,max:s}},"transformElement"),A=n(e=>{switch(e.$type){case"AbnfStringLiteral":return{type:"terminal",value:e.value};case"AbnfNumVal":return{type:"terminal",value:e.value};case"AbnfRuleName":return{type:"nonterminal",name:e.name};case"AbnfGroup":return i(e.element);case"AbnfOptionalGroup":return{type:"optional",element:i(e.element)};default:throw new Error(`Unsupported ABNF primary node: ${e.$type}`)}},"transformPrimary"),P=n(e=>({name:e.name,definition:i(e.definition)}),"transformRule"),h=n(e=>{f(e,a),e.title&&a.setTitle(e.title),e.rules.map(r=>a.addRule(P(r)))},"populateDb"),R={parse:n(e=>{a.clear(),o.debug("[ABNF Parser] Starting Langium parse");const r=v.parse(e);if(r.lexerErrors.length>0||r.parserErrors.length>0)throw new c(r);const t=r.value;o.debug("[ABNF Parser] Parsed rules:",t.rules.length),h(t),o.debug("[ABNF Parser] Parse complete")},"parse"),parser:{yy:a}},B={parser:R,db:a,renderer:u,styles:p};export{B as diagram};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Y as ln,$ as an,a0 as F,a1 as q,a2 as j,a3 as un,a4 as y,a5 as tn,a6 as J,a7 as _,a8 as rn,a9 as o,aa as on,ab as sn,ac as fn}from"./mermaid.core-
|
|
1
|
+
import{Y as ln,$ as an,a0 as F,a1 as q,a2 as j,a3 as un,a4 as y,a5 as tn,a6 as J,a7 as _,a8 as rn,a9 as o,aa as on,ab as sn,ac as fn}from"./mermaid.core-7pKqYtpZ.js";function cn(l){return l.innerRadius}function yn(l){return l.outerRadius}function gn(l){return l.startAngle}function dn(l){return l.endAngle}function mn(l){return l&&l.padAngle}function pn(l,h,I,D,v,A,z,a){var O=I-l,i=D-h,n=z-v,d=a-A,u=d*O-n*i;if(!(u*u<y))return u=(n*(h-A)-d*(l-v))/u,[l+u*O,h+u*i]}function U(l,h,I,D,v,A,z){var a=l-I,O=h-D,i=(z?A:-A)/J(a*a+O*O),n=i*O,d=-i*a,u=l+n,s=h+d,f=I+n,c=D+d,B=(u+f)/2,t=(s+c)/2,m=f-u,g=c-s,R=m*m+g*g,T=v-A,P=u*c-f*s,S=(g<0?-1:1)*J(on(0,T*T*R-P*P)),Y=(P*g-m*S)/R,$=(-P*m-g*S)/R,w=(P*g+m*S)/R,p=(-P*m+g*S)/R,x=Y-B,e=$-t,r=w-B,C=p-t;return x*x+e*e>r*r+C*C&&(Y=w,$=p),{cx:Y,cy:$,x01:-n,y01:-d,x11:Y*(v/T-1),y11:$*(v/T-1)}}function hn(){var l=cn,h=yn,I=j(0),D=null,v=gn,A=dn,z=mn,a=null,O=ln(i);function i(){var n,d,u=+l.apply(this,arguments),s=+h.apply(this,arguments),f=v.apply(this,arguments)-un,c=A.apply(this,arguments)-un,B=rn(c-f),t=c>f;if(a||(a=n=O()),s<u&&(d=s,s=u,u=d),!(s>y))a.moveTo(0,0);else if(B>tn-y)a.moveTo(s*F(f),s*q(f)),a.arc(0,0,s,f,c,!t),u>y&&(a.moveTo(u*F(c),u*q(c)),a.arc(0,0,u,c,f,t));else{var m=f,g=c,R=f,T=c,P=B,S=B,Y=z.apply(this,arguments)/2,$=Y>y&&(D?+D.apply(this,arguments):J(u*u+s*s)),w=_(rn(s-u)/2,+I.apply(this,arguments)),p=w,x=w,e,r;if($>y){var C=sn($/u*q(Y)),K=sn($/s*q(Y));(P-=C*2)>y?(C*=t?1:-1,R+=C,T-=C):(P=0,R=T=(f+c)/2),(S-=K*2)>y?(K*=t?1:-1,m+=K,g-=K):(S=0,m=g=(f+c)/2)}var G=s*F(m),H=s*q(m),L=u*F(T),M=u*q(T);if(w>y){var N=s*F(g),Q=s*q(g),V=u*F(R),W=u*q(R),E;if(B<an)if(E=pn(G,H,V,W,N,Q,L,M)){var X=G-E[0],Z=H-E[1],b=N-E[0],k=Q-E[1],nn=1/q(fn((X*b+Z*k)/(J(X*X+Z*Z)*J(b*b+k*k)))/2),en=J(E[0]*E[0]+E[1]*E[1]);p=_(w,(u-en)/(nn-1)),x=_(w,(s-en)/(nn+1))}else p=x=0}S>y?x>y?(e=U(V,W,G,H,s,x,t),r=U(N,Q,L,M,s,x,t),a.moveTo(e.cx+e.x01,e.cy+e.y01),x<w?a.arc(e.cx,e.cy,x,o(e.y01,e.x01),o(r.y01,r.x01),!t):(a.arc(e.cx,e.cy,x,o(e.y01,e.x01),o(e.y11,e.x11),!t),a.arc(0,0,s,o(e.cy+e.y11,e.cx+e.x11),o(r.cy+r.y11,r.cx+r.x11),!t),a.arc(r.cx,r.cy,x,o(r.y11,r.x11),o(r.y01,r.x01),!t))):(a.moveTo(G,H),a.arc(0,0,s,m,g,!t)):a.moveTo(G,H),!(u>y)||!(P>y)?a.lineTo(L,M):p>y?(e=U(L,M,N,Q,u,-p,t),r=U(G,H,V,W,u,-p,t),a.lineTo(e.cx+e.x01,e.cy+e.y01),p<w?a.arc(e.cx,e.cy,p,o(e.y01,e.x01),o(r.y01,r.x01),!t):(a.arc(e.cx,e.cy,p,o(e.y01,e.x01),o(e.y11,e.x11),!t),a.arc(0,0,u,o(e.cy+e.y11,e.cx+e.x11),o(r.cy+r.y11,r.cx+r.x11),t),a.arc(r.cx,r.cy,p,o(r.y11,r.x11),o(r.y01,r.x01),!t))):a.arc(0,0,u,T,R,t)}if(a.closePath(),n)return a=null,n+""||null}return i.centroid=function(){var n=(+l.apply(this,arguments)+ +h.apply(this,arguments))/2,d=(+v.apply(this,arguments)+ +A.apply(this,arguments))/2-an/2;return[F(d)*n,q(d)*n]},i.innerRadius=function(n){return arguments.length?(l=typeof n=="function"?n:j(+n),i):l},i.outerRadius=function(n){return arguments.length?(h=typeof n=="function"?n:j(+n),i):h},i.cornerRadius=function(n){return arguments.length?(I=typeof n=="function"?n:j(+n),i):I},i.padRadius=function(n){return arguments.length?(D=n==null?null:typeof n=="function"?n:j(+n),i):D},i.startAngle=function(n){return arguments.length?(v=typeof n=="function"?n:j(+n),i):v},i.endAngle=function(n){return arguments.length?(A=typeof n=="function"?n:j(+n),i):A},i.padAngle=function(n){return arguments.length?(z=typeof n=="function"?n:j(+n),i):z},i.context=function(n){return arguments.length?(a=n??null,i):a},i}export{hn as d};
|