@tea-agent/loop-agent 0.1.0-fe-test.3 → 0.1.0-fe-test.5
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 +6 -3
- package/CHANGELOG.md +607 -93
- package/README.md +11 -5
- package/bin/loop-agent.js +7 -3
- package/dist/adapters/context-transfer/optional-pi-handoff.js +31 -0
- package/dist/adapters/context-transfer/pi-session.js +61 -0
- package/dist/application/dag/generate-task-dag.js +90 -21
- package/dist/application/dag/run-dag.js +41 -0
- package/dist/application/task-lifecycle/advance.js +40 -5
- package/dist/application/task-lifecycle/observe.js +171 -17
- package/dist/application/task-lifecycle/plan-transitions.js +42 -7
- package/dist/application/task-lifecycle/recommendations.js +13 -2
- package/dist/build-stamp.json +3 -3
- package/dist/cli/command-definitions.js +44 -10
- package/dist/cli/program.js +82 -6
- package/dist/cli/update/notifier.js +2 -2
- package/dist/cli/update/runtime-activity.js +1 -29
- package/dist/cli.js +2 -1
- package/dist/commands/client-recovery.js +11 -36
- package/dist/commands/dag-artifact.js +284 -0
- package/dist/commands/dag-context.js +184 -0
- package/dist/commands/dag-follow-up.js +138 -0
- package/dist/commands/dag-rerun-task.js +2 -0
- package/dist/commands/dag-rerun.js +261 -2
- package/dist/commands/init-model-catalog.js +486 -0
- package/dist/commands/init-upgrade.js +265 -97
- package/dist/commands/init.js +455 -28
- package/dist/commands/inspect-next.js +8 -0
- package/dist/commands/task-advance.js +73 -1
- package/dist/commands/task-source-prepare.js +5 -0
- package/dist/commands/task-status.js +1 -0
- package/dist/executors/dag-pi-executor.js +4323 -231
- package/dist/executors/pi-event-serializer.js +42 -1
- package/dist/executors/pi-executor.js +70 -6
- package/dist/executors/pi-extension-resolver.js +245 -0
- package/dist/executors/pi-playwright-cli-tool.js +74 -28
- package/dist/executors/pi-read-budget-policy.js +239 -0
- package/dist/executors/pi-sdk-executor.js +263 -59
- package/dist/executors/pi-writer-tool-policy.js +57 -1
- package/dist/executors/shell-executor.js +1456 -240
- package/dist/executors/shell-write-guard.js +14 -0
- package/dist/executors/workspace-write-snapshot.js +68 -0
- package/dist/governance/checks.js +1 -0
- package/dist/{worker → infrastructure}/console/app-data.js +4 -0
- package/dist/infrastructure/console/artifact-revision-store.js +430 -0
- package/dist/infrastructure/console/context-export-store.js +160 -0
- package/dist/infrastructure/console/dir-lock.js +132 -0
- package/dist/infrastructure/console/operation-store.js +417 -0
- package/dist/infrastructure/harness/artifact-store.js +10 -1
- package/dist/infrastructure/harness/atomic-write.js +35 -2
- package/dist/shared/context-transfer/artifact-revision.js +172 -0
- package/dist/shared/context-transfer.js +418 -0
- package/dist/shared/dag-failure-category.js +150 -0
- package/dist/shared/dag-prompt-override.js +27 -0
- package/dist/shared/openspec-spec.js +70 -4
- package/dist/shared/operator/capabilities.js +65 -4
- package/dist/shared/operator/safe-run-summary.js +1 -0
- package/dist/shared/path-safety.js +93 -0
- package/dist/shared/pi-context-pressure/checkpoint.js +116 -0
- package/dist/shared/pi-context-pressure/compaction-policy.js +151 -0
- package/dist/shared/pi-context-pressure/env.js +58 -0
- package/dist/shared/pi-context-pressure/extension.js +100 -0
- package/dist/shared/pi-context-pressure/index.js +7 -0
- package/dist/shared/pi-context-pressure/overflow.js +252 -0
- package/dist/shared/pi-context-pressure/sift-bridge.js +386 -0
- package/dist/shared/pi-context-pressure/telemetry.js +51 -0
- package/dist/shared/playwright-cli-command-policy.js +15 -0
- package/dist/shared/preview.js +28 -4
- package/dist/shared/update/console-notifier.js +100 -0
- package/dist/{cli → shared}/update/npm-client.js +70 -15
- package/dist/{cli → shared}/update/state.js +41 -13
- package/dist/task/config-types.js +125 -6
- package/dist/task/contract/adopt.js +4 -0
- package/dist/task/contract/apply.js +11 -1
- package/dist/task/contract/constants.js +3 -0
- package/dist/task/contract/diff.js +26 -0
- package/dist/task/contract/hash.js +3 -0
- package/dist/task/contract/import-revision.js +4 -0
- package/dist/task/contract/observe.js +25 -4
- package/dist/task/contract/paths.js +2 -1
- package/dist/task/contract/project.js +23 -1
- package/dist/task/contract/schema.js +9 -1
- package/dist/task/contract/transaction.js +12 -0
- package/dist/task/frontend-project-capability.js +203 -20
- package/dist/task/runtime.js +5 -2
- package/dist/task/source-prepare/build-draft.js +18 -3
- package/dist/task/source-prepare/completeness.js +188 -0
- package/dist/task/source-prepare/fragment-inventory.js +513 -0
- package/dist/task/source-prepare/index.js +3 -0
- package/dist/task/source-prepare/ledger-reconciliation.js +127 -0
- package/dist/task/source-prepare/ledger-review.js +214 -0
- package/dist/task/source-prepare/ledger.js +545 -0
- package/dist/task/source-prepare/parse-intent.js +24 -4
- package/dist/task/source-prepare/prepare.js +368 -2
- package/dist/task/source-prepare/semantic-intake.js +25 -5
- package/dist/task/source-prepare/source-fidelity-pi.js +384 -0
- package/dist/task/source-prepare/types.js +22 -0
- package/dist/task/source-references.js +22 -1
- package/dist/task/task-demand-routing.js +3 -0
- package/dist/worker/cli.js +18 -2
- package/dist/worker/console/chat/assistant-content.js +7 -0
- package/dist/worker/console/chat/chat-event-store.js +159 -18
- package/dist/worker/console/chat/chat-ui-policy.js +4 -2
- package/dist/worker/console/chat/context-panel.js +7 -0
- package/dist/worker/console/chat/deferred-turn.js +103 -0
- package/dist/worker/console/chat/goal-round-driver.js +72 -0
- package/dist/worker/console/chat/goals.js +300 -0
- package/dist/worker/console/chat/model-resolver.js +7 -4
- package/dist/worker/console/chat/operation-card.js +8 -1
- package/dist/worker/console/chat/pi-console-config.js +81 -10
- package/dist/worker/console/chat/pi-runtime.js +868 -30
- package/dist/worker/console/chat/provider-error.js +99 -0
- package/dist/worker/console/chat/repo-browser.js +101 -12
- package/dist/worker/console/chat/resource-preferences-store.js +1 -1
- package/dist/worker/console/chat/routes.js +1451 -145
- package/dist/worker/console/chat/sdd-data-alignment.js +222 -0
- package/dist/worker/console/chat/semantic-activity.js +25 -24
- package/dist/worker/console/chat/session-catalog.js +50 -0
- package/dist/worker/console/chat/session-stats.js +275 -0
- package/dist/worker/console/chat/session-store.js +348 -76
- package/dist/worker/console/chat/shortcuts.js +26 -3
- package/dist/worker/console/chat/sift-bridge.js +1 -0
- package/dist/worker/console/chat/todos.js +115 -0
- package/dist/worker/console/chat/tool-preview.js +42 -0
- package/dist/worker/console/chat/turn-process.js +185 -112
- package/dist/worker/console/chat/user-questions.js +266 -0
- package/dist/worker/console/chat/workspace-landing.js +79 -0
- package/dist/worker/console/console-handoff.js +82 -0
- package/dist/worker/console/console-update-and-init.js +115 -0
- package/dist/worker/console/console-update-runtime.js +84 -0
- package/dist/worker/console/context-transfer-diagnostics.js +198 -0
- package/dist/worker/console/dag-confirmation.js +1 -1
- package/dist/worker/console/dag-execution-receipt.js +54 -3
- package/dist/worker/console/doctor.js +1 -1
- package/dist/worker/console/draft-store.js +50 -1
- package/dist/worker/console/frontend-human-decision-adapter.js +19 -0
- package/dist/worker/console/frontend-split-operation-adapter.js +20 -0
- package/dist/worker/console/human-gate-token.js +1 -1
- package/dist/worker/console/index.js +6 -3
- package/dist/worker/console/inspect-split.js +18 -0
- package/dist/worker/console/interview/assessment.js +1 -1
- package/dist/worker/console/interview/session.js +1 -1
- package/dist/worker/console/native-directory-picker.js +13 -0
- package/dist/worker/console/operation-run-facts.js +19 -3
- package/dist/worker/console/operation-runner.js +45 -4
- package/dist/worker/console/operation-sse.js +1 -1
- package/dist/worker/console/operation-wait.js +1 -1
- package/dist/worker/console/operator-actions.js +534 -15
- package/dist/worker/console/operator-selection.js +6 -2
- package/dist/worker/console/operator-surface-health.js +2 -1
- package/dist/worker/console/operator-user-error.js +171 -2
- package/dist/worker/console/pi-plugins.catalog.json +73658 -0
- package/dist/worker/console/pi-plugins.js +238 -0
- package/dist/worker/console/pi-readiness.js +7 -6
- package/dist/worker/console/prd-intake-bridge.js +13 -0
- package/dist/worker/console/recovery-cta.js +4 -4
- package/dist/worker/console/recovery-error-copy.js +4 -4
- package/dist/worker/console/routes.js +1231 -10
- package/dist/worker/console/security.js +102 -13
- package/dist/worker/console/server.js +762 -159
- package/dist/worker/console/static/assets/{abnfDiagram-N423BO3Z-BmOEx0gA.js → abnfDiagram-N423BO3Z-BZogYNl1.js} +1 -1
- package/dist/worker/console/static/assets/{arc-BGiVVe8b.js → arc-DcJTLe2v.js} +1 -1
- package/dist/worker/console/static/assets/{architectureDiagram-T3A2C74G-nDdu4rgJ.js → architectureDiagram-T3A2C74G-B39EQQ9n.js} +1 -1
- package/dist/worker/console/static/assets/{blockDiagram-VBNYF7ZC-Bb5u0BWf.js → blockDiagram-VBNYF7ZC-CitCGV56.js} +1 -1
- package/dist/worker/console/static/assets/{c4Diagram-5PPSVZJV-BlhC0j94.js → c4Diagram-5PPSVZJV-rvWuOHLG.js} +1 -1
- package/dist/worker/console/static/assets/channel-CXqdP5pW.js +1 -0
- package/dist/worker/console/static/assets/{chunk-2GRJ4B5K-Ai8_qQXI.js → chunk-2GRJ4B5K-DGXplIJs.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-2Q5K7J3B-B9gyCjqX.js → chunk-2Q5K7J3B-ur9OqjPn.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-5RXB4S5H-Bzbj3zGH.js → chunk-5RXB4S5H-D1KqU_Vi.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-5VM5RSS4-BT415PvT.js → chunk-5VM5RSS4-BlVZrbtM.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-6Q2QTUOP-D_A5_5QL.js → chunk-6Q2QTUOP-BAzz3nQy.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-GF5L2VYU-srJkaP3f.js → chunk-GF5L2VYU-CP_nYuCV.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-JWPE2WC7-UYGvEP4l.js → chunk-JWPE2WC7-CWvKQ80X.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-KBJHAD2P-B8luBrrz.js → chunk-KBJHAD2P-CyUki8wp.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-RYQCIY6F-DN7wXZSq.js → chunk-RYQCIY6F-5NYzNKfY.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-XXDRQBXY-DXKyMuKS.js → chunk-XXDRQBXY-DHdUgjS-.js} +1 -1
- package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-D9C3agF7.js +1 -0
- package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-D9C3agF7.js +1 -0
- package/dist/worker/console/static/assets/{cose-bilkent-JH36ORCC-dqvoynXj.js → cose-bilkent-JH36ORCC-ANQ5g_t6.js} +1 -1
- package/dist/worker/console/static/assets/{cynefin-VYW2F7L2--PcyL34A.js → cynefin-VYW2F7L2-CruT_4-0.js} +1 -1
- package/dist/worker/console/static/assets/{cynefinDiagram-MW4NZA55-DvWs_hTY.js → cynefinDiagram-MW4NZA55-rbFo77ID.js} +1 -1
- package/dist/worker/console/static/assets/{dagre-VZM6K2ZE-DxeIxbyO.js → dagre-VZM6K2ZE-asstxBQs.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-7IWD3JNH-DPCG61Of.js → diagram-7IWD3JNH-DzTyBZwI.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-B4RE2ZJO-CmuU50-U.js → diagram-B4RE2ZJO-gw8ccH3B.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-LBJQPF4R-B61XLD_v.js → diagram-LBJQPF4R-B8RpZzOf.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-Q27KOJAE-BB7HTRRY.js → diagram-Q27KOJAE-B1zJkCS9.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-UB23O5K3-DvkboAIp.js → diagram-UB23O5K3-B6JLWZmO.js} +1 -1
- package/dist/worker/console/static/assets/{ebnfDiagram-BXEA7PRR-BdJ_y1fL.js → ebnfDiagram-BXEA7PRR-q2iZP-Ps.js} +1 -1
- package/dist/worker/console/static/assets/{erDiagram-JOGREHBK-9bUBZTRi.js → erDiagram-JOGREHBK-B3dbbktQ.js} +1 -1
- package/dist/worker/console/static/assets/{flowDiagram-UKHOOZJN-Dw4L4RBa.js → flowDiagram-UKHOOZJN-C-zc6-kB.js} +1 -1
- package/dist/worker/console/static/assets/{ganttDiagram-PKOTCBZU-Jr82N_QP.js → ganttDiagram-PKOTCBZU-BSolnot9.js} +1 -1
- package/dist/worker/console/static/assets/{gitGraphDiagram-DS77QQ5N-DAz9wFLr.js → gitGraphDiagram-DS77QQ5N-Bo8jGxTk.js} +1 -1
- package/dist/worker/console/static/assets/index-CAZ2fC_X.css +1 -0
- package/dist/worker/console/static/assets/index-DhfjOafu.js +449 -0
- package/dist/worker/console/static/assets/{infoDiagram-6WML65LV-CBB5Np7y.js → infoDiagram-6WML65LV-DQaZqJOH.js} +1 -1
- package/dist/worker/console/static/assets/{ishikawaDiagram-WSZJBQD7-D8IOp94y.js → ishikawaDiagram-WSZJBQD7-DsdX1WnE.js} +1 -1
- package/dist/worker/console/static/assets/{journeyDiagram-NVQOT4AX-Dgd3AHGG.js → journeyDiagram-NVQOT4AX-CP5EYDZL.js} +1 -1
- package/dist/worker/console/static/assets/{kanban-definition-27J2QSJJ-BmYOxLE9.js → kanban-definition-27J2QSJJ-DAm14Dr8.js} +1 -1
- package/dist/worker/console/static/assets/{linear-DfYTEF6J.js → linear-gZECoLc5.js} +1 -1
- package/dist/worker/console/static/assets/{mermaid.core-BjuFPRqa.js → mermaid.core-BRJNIM6p.js} +5 -5
- package/dist/worker/console/static/assets/{mindmap-definition-FAOFIHXS-CLyUViGd.js → mindmap-definition-FAOFIHXS-Cja3kLkR.js} +1 -1
- package/dist/worker/console/static/assets/{pegDiagram-VL7TDLO6-BvX2Di4-.js → pegDiagram-VL7TDLO6-22ZGFisL.js} +1 -1
- package/dist/worker/console/static/assets/{pieDiagram-7S7Q4E2Y-BFj0_OLv.js → pieDiagram-7S7Q4E2Y-BXin0Y1o.js} +1 -1
- package/dist/worker/console/static/assets/{quadrantDiagram-CIZ2JOQS-BIUrD_hx.js → quadrantDiagram-CIZ2JOQS-Cw6T69Yt.js} +1 -1
- package/dist/worker/console/static/assets/{railroadDiagram-AXF67PYL-CHBB48fj.js → railroadDiagram-AXF67PYL-C1-gTieN.js} +1 -1
- package/dist/worker/console/static/assets/{requirementDiagram-LRYGKXZP-sJrYw2Sf.js → requirementDiagram-LRYGKXZP--H5N2iI1.js} +1 -1
- package/dist/worker/console/static/assets/{sankeyDiagram-W5VNT64P-BzHH6fPR.js → sankeyDiagram-W5VNT64P-CgWAPeRz.js} +1 -1
- package/dist/worker/console/static/assets/{sequenceDiagram-SI44F4Z6-7QCnelCt.js → sequenceDiagram-SI44F4Z6-CrKqzGvt.js} +1 -1
- package/dist/worker/console/static/assets/{sizeCapture-X5ZJPWSS-sDYSxn72.js → sizeCapture-X5ZJPWSS-BB3wG06K.js} +1 -1
- package/dist/worker/console/static/assets/{stateDiagram-OKZ733FA-XpiUdwzm.js → stateDiagram-OKZ733FA-DjsGgdgY.js} +1 -1
- package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-Tp7V0U4q.js +1 -0
- package/dist/worker/console/static/assets/{swimlanes-SLNWSIFB-DvqgNPzD.js → swimlanes-SLNWSIFB-DYKEbvAR.js} +2 -2
- package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-DUZWZWi8.js +8 -0
- package/dist/worker/console/static/assets/{timeline-definition-Z64GVDOM-2TyOYNx0.js → timeline-definition-Z64GVDOM-eQOb5k9Y.js} +1 -1
- package/dist/worker/console/static/assets/{vennDiagram-T6HMQDX7-B-nM6wM2.js → vennDiagram-T6HMQDX7-B2-l9FIu.js} +1 -1
- package/dist/worker/console/static/assets/{wardleyDiagram-T6FBY63Y-B86wPdbr.js → wardleyDiagram-T6FBY63Y-BX2Cda3l.js} +1 -1
- package/dist/worker/console/static/assets/{xychartDiagram-ELKLHX3M-Dr1C4AQz.js → xychartDiagram-ELKLHX3M-D9S892ph.js} +1 -1
- package/dist/worker/console/static/index.html +7 -2
- package/dist/worker/console/static-src/active-run-badge.js +17 -0
- package/dist/worker/console/static-src/app/console-types.js +68 -4
- package/dist/worker/console/static-src/app/useConsoleShell.js +30 -12
- package/dist/worker/console/static-src/app/useOperatorActions.js +43 -7
- package/dist/worker/console/static-src/app/useRecoveryActions.js +2 -2
- package/dist/worker/console/static-src/app/useRecoveryConsole.js +45 -10
- package/dist/worker/console/static-src/app/useRunProgress.js +54 -0
- package/dist/worker/console/static-src/app/useTaskWizard.js +74 -2
- package/dist/worker/console/static-src/night/useNightBoard.js +8 -5
- package/dist/worker/console/static-src/operator-chat/cards/failure-category-advice.js +25 -0
- package/dist/worker/console/static-src/operator-chat/chat-sse-events.js +264 -13
- package/dist/worker/console/static-src/operator-chat/compaction-message.js +113 -0
- package/dist/worker/console/static-src/operator-chat/dag-progress-link.js +22 -0
- package/dist/worker/console/static-src/operator-chat/details-dag-actions.js +122 -0
- package/dist/worker/console/static-src/operator-chat/input-history.js +78 -0
- package/dist/worker/console/static-src/operator-chat/mutation-gate.js +1 -1
- package/dist/worker/console/static-src/operator-chat/open-preview-in-browser.js +338 -0
- package/dist/worker/console/static-src/operator-chat/refs.js +3 -0
- package/dist/worker/console/static-src/operator-chat/runtime-selection-labels.js +27 -0
- package/dist/worker/console/static-src/operator-chat/runtime-snapshot-store.js +10 -0
- package/dist/worker/console/static-src/operator-chat/spatial-overlay.js +1 -2
- package/dist/worker/console/static-src/operator-chat/turn-stream-controller.js +33 -1
- package/dist/worker/console/static-src/operator-chat/turn-submission.js +55 -0
- package/dist/worker/console/static-src/operator-chat/useChatSessions.js +448 -109
- package/dist/worker/console/static-src/operator-chat/useChatStream.js +344 -27
- package/dist/worker/console/static-src/operator-chat/useChatThread.js +323 -11
- package/dist/worker/console/static-src/operator-chat/useComposer.js +45 -4
- package/dist/worker/console/static-src/operator-chat/useRepoBrowser.js +97 -13
- package/dist/worker/console/static-src/operator-chat/useRuntimeControls.js +57 -9
- package/dist/worker/console/static-src/operator-chat/useRuntimeSnapshot.js +8 -2
- package/dist/worker/console/static-src/operator-chat/useWorkspaceBrowserGate.js +4 -0
- package/dist/worker/console/static-src/operator-chat/workspace-layout-mode.js +3 -3
- package/dist/worker/console/static-src/operator-chat/workspace-reorder.js +18 -0
- package/dist/worker/console/static-src/pages/tasks/run-id-resolution.js +79 -0
- package/dist/worker/console/static-src/pages/tasks/run-ownership-verify.js +23 -0
- package/dist/worker/console/static-src/pages/tasks/run-panel-progress.js +216 -0
- package/dist/worker/console/static-src/shell/console-update-reload.js +52 -0
- package/dist/worker/console/static-src/shell/useWorkspaces.js +415 -0
- package/dist/worker/console/static-src/shell/workspace-route.js +356 -0
- package/dist/worker/console/workspace-context.js +399 -0
- package/dist/worker/console/workspace-registry.js +487 -0
- package/dist/worker/continuation/worker-continuation.js +278 -0
- package/dist/worker/loop-agent/loop-agent-client.js +7 -3
- package/dist/worker/materialize/frontend-split-task-materializer.js +72 -0
- package/dist/worker/materialize/harness-task-lineage.js +5 -2
- package/dist/worker/observability/init-runtime-activity.js +26 -0
- package/dist/worker/observability/read-model.js +26 -0
- package/dist/worker/observe/health.js +1 -1
- package/dist/worker/observe/node-input.js +160 -3
- package/dist/worker/observe/node-process.js +377 -0
- package/dist/worker/observe/node-transparency.js +572 -0
- package/dist/worker/observe/routes.js +278 -3
- package/dist/worker/observe/server.js +4 -0
- package/dist/worker/observe/shell-handler-keys.js +34 -0
- package/dist/worker/observe/static/api.js +154 -4
- package/dist/worker/observe/static/app.js +18 -70
- package/dist/worker/observe/static/constants.js +26 -19
- package/dist/worker/observe/static/dag-context-reason-labels.d.ts +9 -0
- package/dist/worker/observe/static/dag-context-reason-labels.js +139 -0
- package/dist/worker/observe/static/dag-helpers.js +4 -2
- package/dist/worker/observe/static/dag-history-labels.js +5 -0
- package/dist/worker/observe/static/dag-inspector-humanize.d.ts +16 -0
- package/dist/worker/observe/static/dag-inspector-humanize.js +339 -0
- package/dist/worker/observe/static/dag-node-purpose.d.ts +6 -0
- package/dist/worker/observe/static/dag-node-purpose.js +208 -0
- package/dist/worker/observe/static/format.js +60 -0
- package/dist/worker/observe/static/index.html +10 -5
- package/dist/worker/observe/static/inspect-bootstrap.d.ts +8 -0
- package/dist/worker/observe/static/inspect-bootstrap.js +57 -0
- package/dist/worker/observe/static/inspect-workspace.js +374 -0
- package/dist/worker/observe/static/kpi.js +2 -2
- package/dist/worker/observe/static/markdown-render.js +20 -1
- package/dist/worker/observe/static/operator-chrome.css +168 -24
- package/dist/worker/observe/static/operator-chrome.d.ts +30 -5
- package/dist/worker/observe/static/operator-chrome.js +354 -101
- package/dist/worker/observe/static/prompt-restart-candidates.d.ts +18 -0
- package/dist/worker/observe/static/prompt-restart-candidates.js +38 -0
- package/dist/worker/observe/static/relations.js +7 -7
- package/dist/worker/observe/static/router.d.ts +57 -0
- package/dist/worker/observe/static/router.js +67 -1
- package/dist/worker/observe/static/run-processing.js +4 -2
- package/dist/worker/observe/static/shell-chrome.js +2 -2
- package/dist/worker/observe/static/state.d.ts +50 -0
- package/dist/worker/observe/static/state.js +191 -1
- package/dist/worker/observe/static/styles.css +1720 -86
- package/dist/worker/observe/static/views/dag-graph.js +5 -3
- package/dist/worker/observe/static/views/dag-inspector.js +2601 -188
- package/dist/worker/observe/static/views/dag.d.ts +13 -0
- package/dist/worker/observe/static/views/dag.js +39 -18
- package/dist/worker/observe/static/views/dags.js +10 -6
- package/dist/worker/observe/static/views/dashboard.js +18 -8
- package/dist/worker/observe/static/views/failures.js +5 -2
- package/dist/worker/observe/static/views/night.js +2 -2
- package/dist/worker/observe/static/views/pool.js +8 -2
- package/dist/worker/observe/static/views/run.js +15 -4
- package/dist/worker/observe/static/views/session-timeline.js +386 -25
- package/dist/worker/observe/static/views/task.js +63 -3
- package/dist/worker/outcomes/adapters.js +19 -0
- package/dist/worker/outcomes/types.js +1 -0
- package/dist/worker/pool/attempt-lease.js +97 -66
- package/dist/worker/pool/begin-attempt-with-lease.js +1 -0
- package/dist/worker/pool/reconcile.js +46 -1
- package/dist/worker/pool/run-store.js +2 -0
- package/dist/worker/pool/state-projection.js +2 -0
- package/dist/worker/task-spec/workflow-routing.js +8 -3
- package/dist/workflows/dag/artifact-bindings.js +149 -0
- package/dist/workflows/dag/artifact-revision-schema-registry.js +31 -0
- package/dist/workflows/dag/backend-test-case-coverage-analysis.js +470 -31
- package/dist/workflows/dag/backend-test-markdown-workflow.js +189 -2
- package/dist/workflows/dag/backend-test-plan-protocol.js +210 -0
- package/dist/workflows/dag/backend-test-pytest-collection.js +168 -16
- package/dist/workflows/dag/backend-test-result-contract.js +5 -1
- package/dist/workflows/dag/backend-test-scenario-param.js +506 -73
- package/dist/workflows/dag/backend-test-scenario-partitions.js +135 -2
- package/dist/workflows/dag/backend-test-writer-completeness.js +131 -28
- package/dist/workflows/dag/budget-enforcement.js +10 -0
- package/dist/workflows/dag/context-receipt.js +305 -0
- package/dist/workflows/dag/context-transfer/context-bundle.js +423 -0
- package/dist/workflows/dag/context-transfer/operator-actions.js +61 -0
- package/dist/workflows/dag/context-transfer/renderers.js +93 -0
- package/dist/workflows/dag/contract-output-registry.js +15 -0
- package/dist/workflows/dag/contract-validator-registrations.js +1 -2
- package/dist/workflows/dag/convergence/controller.js +141 -0
- package/dist/workflows/dag/dag-retry-schema.js +138 -0
- package/dist/workflows/dag/dynamic-runtime/loop-until.js +1 -1
- package/dist/workflows/dag/dynamic-runtime/map.js +17 -3
- package/dist/workflows/dag/failure-category.js +7 -116
- package/dist/workflows/dag/frontend-closeout.js +221 -0
- package/dist/workflows/dag/frontend-design-policy.js +400 -0
- package/dist/workflows/dag/frontend-human-decision.js +182 -0
- package/dist/workflows/dag/frontend-implementation-contract.js +1377 -141
- package/dist/workflows/dag/frontend-plan-render.js +26 -1
- package/dist/workflows/dag/frontend-prewrite-gate.js +376 -318
- package/dist/workflows/dag/frontend-provider-capability-matrix.js +159 -0
- package/dist/workflows/dag/frontend-recovery-capsule.js +455 -0
- package/dist/workflows/dag/frontend-recovery-controller.js +226 -0
- package/dist/workflows/dag/frontend-recovery-lineage.js +178 -0
- package/dist/workflows/dag/frontend-recovery-plan.js +21 -10
- package/dist/workflows/dag/frontend-recovery-run.js +166 -34
- package/dist/workflows/dag/frontend-repair.js +7 -424
- package/dist/workflows/dag/frontend-review-context.js +348 -20
- package/dist/workflows/dag/frontend-review-findings.js +270 -0
- package/dist/workflows/dag/frontend-risk.js +15 -2
- package/dist/workflows/dag/frontend-shadow-dual-write.js +941 -0
- package/dist/workflows/dag/frontend-shape-capsule-store.js +191 -0
- package/dist/workflows/dag/frontend-shape-facts.js +419 -0
- package/dist/workflows/dag/frontend-shape.js +435 -0
- package/dist/workflows/dag/frontend-source-fidelity-ledger.js +108 -0
- package/dist/workflows/dag/frontend-split-application-service.js +203 -0
- package/dist/workflows/dag/frontend-split-orchestrator.js +899 -0
- package/dist/workflows/dag/frontend-test-case-checklist.js +32 -4
- package/dist/workflows/dag/frontend-test-case-generation-assessment.js +69 -0
- package/dist/workflows/dag/frontend-test-case-manifest.js +17 -5
- package/dist/workflows/dag/frontend-test-case-quality.js +11 -16
- package/dist/workflows/dag/frontend-test-environment-probe.js +230 -0
- package/dist/workflows/dag/frontend-test-html-report.js +3 -1
- package/dist/workflows/dag/frontend-test-l5-report.js +3 -1
- package/dist/workflows/dag/frontend-test-layout.js +159 -0
- package/dist/workflows/dag/frontend-test-markdown.js +61 -0
- package/dist/workflows/dag/frontend-test-result-contract.js +202 -42
- package/dist/workflows/dag/frontend-test-standard-scenarios.js +70 -0
- package/dist/workflows/dag/frontend-typed-event-store.js +452 -0
- package/dist/workflows/dag/frontend-typed-event-transaction.js +180 -0
- package/dist/workflows/dag/frontend-verification-trace.js +281 -29
- package/dist/workflows/dag/frontend-worktree-diff.js +250 -17
- package/dist/workflows/dag/frontend-writer-admission.js +319 -0
- package/dist/workflows/dag/frontend-writer-rollback.js +32 -0
- package/dist/workflows/dag/frontend-writer-status.js +256 -0
- package/dist/workflows/dag/init-hybrid.js +1771 -717
- package/dist/workflows/dag/interrupt-request.js +10 -3
- package/dist/workflows/dag/lifecycle.js +3 -3
- package/dist/workflows/dag/node-execution.js +1141 -32
- package/dist/workflows/dag/path-safety.js +1 -0
- package/dist/workflows/dag/prompt.js +158 -7
- package/dist/workflows/dag/recovery-lease.js +170 -0
- package/dist/workflows/dag/report.js +37 -1
- package/dist/workflows/dag/rerun-feedback.js +526 -0
- package/dist/workflows/dag/rerun-plan.js +790 -28
- package/dist/workflows/dag/rerun-run.js +700 -21
- package/dist/workflows/dag/rerun-task.js +311 -14
- package/dist/workflows/dag/retry-policy.js +336 -101
- package/dist/workflows/dag/runner.js +596 -121
- package/dist/workflows/dag/scheduler.js +133 -20
- package/dist/workflows/dag/skill-snapshot.js +17 -0
- package/dist/workflows/dag/structured-output-repair.js +712 -0
- package/dist/workflows/dag/types.js +600 -31
- package/dist/workflows/dag/validate.js +92 -32
- package/docs/README.md +2 -0
- package/docs/architecture/evolution.md +45 -0
- package/docs/architecture/runtime-boundaries.md +8 -7
- package/docs/architecture/worker-and-feature.md +1 -1
- package/docs/examples/README.md +5 -0
- package/docs/init-surface.manifest.json +36 -12
- package/docs/operations/README.md +1 -1
- package/docs/operations/local-development-environment.md +22 -5
- package/docs/skills/vetted-skill-registry.md +16 -0
- package/docs/templates/README.md +4 -2
- package/docs/templates/agent-dag-report.schema.json +8 -2
- package/docs/templates/agent-dag.schema.json +95 -1
- package/docs/templates/backend-test-dag.json +278 -244
- package/docs/templates/frontend-implementation-contract.schema.json +684 -24
- package/docs/templates/frontend-implementation-dag.json +89 -0
- package/docs/templates/frontend-test-case-checklist.md +2 -2
- package/docs/templates/frontend-test-dag.json +10 -12
- package/docs/templates/frontend-test-dag.retrieve-context.prompt.md +1 -1
- package/docs/templates/init-managed-agents.md +13 -3
- package/docs/templates/product-line/task.yaml +1 -1
- package/docs/templates/spec-registry.schema.json +45 -0
- package/harness.json +2 -2
- package/package.json +19 -5
- package/scripts/next-info.mjs +356 -0
- package/scripts/next-publish-gate.mjs +238 -0
- package/scripts/release-source-binding.mjs +251 -0
- package/skills/analyze-product-requirements/SKILL.md +8 -5
- package/skills/analyze-product-requirements/references/acceptance-criteria.md +1 -1
- package/skills/analyze-product-requirements/references/clarification-and-knowledge.md +10 -6
- package/skills/analyze-product-requirements/references/example.md +50 -0
- package/skills/analyze-product-requirements/references/forward-test-cases.md +11 -7
- package/skills/analyze-product-requirements/references/kb-integration.md +5 -5
- package/skills/analyze-product-requirements/references/product-analysis-schema.md +8 -4
- package/skills/analyze-product-requirements/references/product-requirement-schema.md +2 -2
- package/skills/analyze-product-requirements/references/requirement-clarification-schema.md +1 -1
- package/skills/analyze-product-requirements/scripts/test-validators.mjs +11 -1
- package/skills/analyze-product-requirements/scripts/validate-product-analysis.mjs +20 -1
- package/skills/analyze-product-requirements/scripts/validate-requirement-clarification.mjs +9 -0
- package/skills/codebase-scout/SKILL.md +1 -1
- package/skills/fe-test-ui-scout/SKILL.md +65 -0
- package/skills/fe-test-ui-scout/references/ledger-schema.md +62 -0
- package/skills/fe-test-ui-scout/references/recon-protocol.md +54 -0
- package/skills/frontend-bounded-implement/SKILL.md +15 -14
- package/skills/frontend-bounded-implement/references/code-standards.md +19 -0
- package/skills/frontend-contract/SKILL.md +23 -0
- package/skills/frontend-contract/references/contract-protocol.md +34 -0
- package/skills/frontend-design-review/SKILL.md +22 -41
- package/skills/frontend-plan/SKILL.md +26 -0
- package/skills/frontend-plan/references/decision-contract.md +37 -0
- package/skills/frontend-plan/references/design-decisions.md +17 -0
- package/skills/frontend-review/SKILL.md +20 -15
- package/skills/frontend-review/references/review-findings.md +6 -7
- package/skills/frontend-scout/SKILL.md +25 -0
- package/skills/frontend-scout/references/design-evidence.md +16 -0
- package/skills/frontend-scout/references/scout-evidence.md +23 -0
- package/skills/frontend-verification/SKILL.md +1 -1
- package/skills/improve-codebase-architecture/SKILL.md +81 -0
- package/skills/improve-codebase-architecture/deepening.md +37 -0
- package/skills/improve-codebase-architecture/html-report.md +123 -0
- package/skills/improve-codebase-architecture/interface-design.md +44 -0
- package/skills/improve-codebase-architecture/language.md +53 -0
- package/skills/loop-agent/references/command-reference.md +32 -4
- package/skills/loop-agent/references/hybrid-dag.md +9 -2
- package/skills/playwright-cli/SKILL.md +23 -1
- package/skills/playwright-cli-case-generator/SKILL.md +50 -13
- package/dist/worker/console/operation-store.js +0 -169
- package/dist/worker/console/static/assets/channel-Tl-FkUqr.js +0 -1
- package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-BaehtRk4.js +0 -1
- package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-BaehtRk4.js +0 -1
- package/dist/worker/console/static/assets/index-B7Y-0g3J.css +0 -1
- package/dist/worker/console/static/assets/index-DkCrqaYg.js +0 -325
- package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-eEhq2A8Y.js +0 -1
- package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-la8AC7fo.js +0 -8
- package/dist/worker/console/static-src/operator-chat/activity-rail-presentation.js +0 -73
- package/dist/worker/console/static-src/operator-chat/useActivityRailTransition.js +0 -59
- package/skills/frontend-implementation/SKILL.md +0 -52
- package/skills/frontend-implementation/references/code-standards.md +0 -33
- package/skills/frontend-implementation/references/design-spec.md +0 -56
- package/skills/frontend-implementation/references/node-contracts.md +0 -31
- /package/dist/{worker → infrastructure}/console/repo-fingerprint.js +0 -0
|
@@ -1,12 +1,23 @@
|
|
|
1
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
1
2
|
import { existsSync } from "node:fs";
|
|
2
|
-
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { readFile, rm } from "node:fs/promises";
|
|
3
4
|
import path from "node:path";
|
|
4
5
|
import { dispatchOperatorAction } from "./operator-actions.js";
|
|
5
6
|
import { openSseResponse, parseLastEventId, writeSseEvent, } from "./operation-sse.js";
|
|
7
|
+
import { probePiReadiness } from "./pi-readiness.js";
|
|
6
8
|
import { buildOperatorSurfaceHealthV1 } from "./operator-surface-health.js";
|
|
7
9
|
import { ROUTES } from "../observe/routes.js";
|
|
8
|
-
import { evaluateMutationGate, injectConfirmationTokenScript, isMutationMethod, } from "./security.js";
|
|
10
|
+
import { evaluateProtectedDownloadGate, evaluateMutationGate, injectConfirmationTokenScript, isMutationMethod, } from "./security.js";
|
|
9
11
|
import { listDagRunsForRecovery } from "./resolve-dag-run-for-task.js";
|
|
12
|
+
import { writeArtifactRevisionUpload } from "../../infrastructure/console/artifact-revision-store.js";
|
|
13
|
+
import { ensureSecureDir } from "../../infrastructure/console/app-data.js";
|
|
14
|
+
import { acquireContextExportLease, createContextExport, releaseContextExportLease, } from "../../infrastructure/console/context-export-store.js";
|
|
15
|
+
import { acceptOperation } from "./operator-actions.js";
|
|
16
|
+
import { recordContextTransferDiagnostic, recordContextTransferEvent, } from "./context-transfer-diagnostics.js";
|
|
17
|
+
import { isDagRerunPromptOverrideEnabled } from "../../shared/dag-prompt-override.js";
|
|
18
|
+
import { beginWorkerContinuation, resolveWorkerContinuationAuthority, settleWorkerContinuation, } from "../continuation/worker-continuation.js";
|
|
19
|
+
import { installPiPlugin, listPiPluginVersions, listPiPlugins, uninstallPiPlugin, checkPiPluginUpdates, } from "./pi-plugins.js";
|
|
20
|
+
import { pickNativeWorkspaceDirectory } from "./native-directory-picker.js";
|
|
10
21
|
export function sendJson(res, status, body, extraHeaders) {
|
|
11
22
|
const payload = JSON.stringify(body);
|
|
12
23
|
res.writeHead(status, {
|
|
@@ -38,6 +49,10 @@ function contentTypeFor(pathname) {
|
|
|
38
49
|
return "application/octet-stream";
|
|
39
50
|
}
|
|
40
51
|
async function readJsonBody(req, maxBytes = 10 * 1024 * 1024) {
|
|
52
|
+
// Body pre-read by the multi-workspace dispatcher (workspaceId resolution).
|
|
53
|
+
const preRead = req.__preReadBody;
|
|
54
|
+
if (preRead !== undefined)
|
|
55
|
+
return preRead;
|
|
41
56
|
const chunks = [];
|
|
42
57
|
let total = 0;
|
|
43
58
|
for await (const chunk of req) {
|
|
@@ -67,6 +82,7 @@ export async function handleConsoleHealthRequest(_req, res, ctx) {
|
|
|
67
82
|
piReadiness: ctx.operator?.getReadiness().state ?? "setup-required",
|
|
68
83
|
inspectReady: ctx.inspect.ready,
|
|
69
84
|
routes: ROUTES,
|
|
85
|
+
consoleInstanceId: ctx.consoleInstanceId,
|
|
70
86
|
}));
|
|
71
87
|
}
|
|
72
88
|
catch {
|
|
@@ -77,6 +93,7 @@ export async function handleConsoleHealthRequest(_req, res, ctx) {
|
|
|
77
93
|
repoFingerprint: "unavailable",
|
|
78
94
|
packageName: "unknown",
|
|
79
95
|
packageVersion: "0.0.0",
|
|
96
|
+
consoleInstanceId: ctx.consoleInstanceId,
|
|
80
97
|
piReadiness: ctx.operator?.getReadiness().state ?? "setup-required",
|
|
81
98
|
inspect: {
|
|
82
99
|
ready: ctx.inspect.ready,
|
|
@@ -116,6 +133,7 @@ async function handleRecoveryCandidates(_req, res, ctx, url) {
|
|
|
116
133
|
}
|
|
117
134
|
async function handleSessionPing(req, res, ctx) {
|
|
118
135
|
const failure = evaluateMutationGate(req, {
|
|
136
|
+
cookieName: ctx.bootToken.cookieName,
|
|
119
137
|
bootToken: ctx.bootToken.value,
|
|
120
138
|
confirmationToken: ctx.bootToken.confirmationToken,
|
|
121
139
|
consoleOrigin: ctx.getConsoleOrigin(),
|
|
@@ -130,6 +148,525 @@ async function handleSessionPing(req, res, ctx) {
|
|
|
130
148
|
}
|
|
131
149
|
sendJson(res, 200, { ok: true, pong: true });
|
|
132
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* Actions the inspect-scoped mutation token may dispatch. Deliberately
|
|
153
|
+
* minimal: the experimental prompt-override rerun tab needs plan preflight +
|
|
154
|
+
* execution only. Everything else (task creation, runDag, reconcile, chat,
|
|
155
|
+
* worker actions…) requires the general Console token.
|
|
156
|
+
*/
|
|
157
|
+
export const INSPECT_MUTATION_ALLOWED_ACTIONS = new Set([
|
|
158
|
+
"dagRerunPlan",
|
|
159
|
+
"dagRerun",
|
|
160
|
+
"contextExport",
|
|
161
|
+
"artifactRevisionStage",
|
|
162
|
+
"artifactRevisionPlan",
|
|
163
|
+
"artifactRevisionExecute",
|
|
164
|
+
]);
|
|
165
|
+
function evaluateConsoleCapability(req, ctx) {
|
|
166
|
+
const common = {
|
|
167
|
+
consoleOrigin: ctx.getConsoleOrigin(),
|
|
168
|
+
allowNonLoopbackAccess: ctx.allowNonLoopbackAccess === true,
|
|
169
|
+
};
|
|
170
|
+
const general = evaluateMutationGate(req, {
|
|
171
|
+
...common,
|
|
172
|
+
cookieName: ctx.bootToken.cookieName,
|
|
173
|
+
bootToken: ctx.bootToken.value,
|
|
174
|
+
confirmationToken: ctx.bootToken.confirmationToken,
|
|
175
|
+
});
|
|
176
|
+
if (!general || !ctx.inspectBootToken)
|
|
177
|
+
return general;
|
|
178
|
+
return evaluateMutationGate(req, {
|
|
179
|
+
...common,
|
|
180
|
+
cookieName: ctx.inspectBootToken.cookieName,
|
|
181
|
+
bootToken: ctx.inspectBootToken.value,
|
|
182
|
+
confirmationToken: ctx.inspectBootToken.confirmationToken,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
function evaluateConsoleDownloadCapability(req, ctx) {
|
|
186
|
+
const common = {
|
|
187
|
+
consoleOrigin: ctx.getConsoleOrigin(),
|
|
188
|
+
allowNonLoopbackAccess: ctx.allowNonLoopbackAccess === true,
|
|
189
|
+
};
|
|
190
|
+
const general = evaluateProtectedDownloadGate(req, {
|
|
191
|
+
...common,
|
|
192
|
+
cookieName: ctx.bootToken.cookieName,
|
|
193
|
+
bootToken: ctx.bootToken.value,
|
|
194
|
+
confirmationToken: ctx.bootToken.confirmationToken,
|
|
195
|
+
});
|
|
196
|
+
if (!general || !ctx.inspectBootToken)
|
|
197
|
+
return general;
|
|
198
|
+
return evaluateProtectedDownloadGate(req, {
|
|
199
|
+
...common,
|
|
200
|
+
cookieName: ctx.inspectBootToken.cookieName,
|
|
201
|
+
bootToken: ctx.inspectBootToken.value,
|
|
202
|
+
confirmationToken: ctx.inspectBootToken.confirmationToken,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
async function acceptContextExportOperation(input) {
|
|
206
|
+
const operator = input.ctx.operator;
|
|
207
|
+
const clientRequestId = input.clientRequestId?.trim();
|
|
208
|
+
if (!clientRequestId) {
|
|
209
|
+
return {
|
|
210
|
+
status: 400,
|
|
211
|
+
body: { ok: false, error: { code: "INVALID_INPUT", message: "clientRequestId is required" } },
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
const runId = typeof input.actionParams.runId === "string" ? input.actionParams.runId.trim() : "";
|
|
215
|
+
const nodeId = typeof input.actionParams.nodeId === "string" ? input.actionParams.nodeId.trim() : "";
|
|
216
|
+
const attempt = Number(input.actionParams.attempt ?? 1);
|
|
217
|
+
const profile = input.actionParams.profile === "raw" ? "raw" : "redacted";
|
|
218
|
+
const target = ["generic", "pi-session", "pi-handoff", "readable"].includes(String(input.actionParams.target))
|
|
219
|
+
? input.actionParams.target
|
|
220
|
+
: "generic";
|
|
221
|
+
if (!runId || !nodeId || !Number.isInteger(attempt) || attempt < 1) {
|
|
222
|
+
return {
|
|
223
|
+
status: 400,
|
|
224
|
+
body: { ok: false, error: { code: "INVALID_INPUT", message: "runId, nodeId and positive attempt are required" } },
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
if (profile === "raw" && input.actionParams.rawAcknowledged !== true) {
|
|
228
|
+
return {
|
|
229
|
+
status: 400,
|
|
230
|
+
body: { ok: false, error: { code: "RAW_EXPORT_ACKNOWLEDGEMENT_REQUIRED", message: "raw export requires explicit acknowledgement" } },
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
const created = await operator.operations.create({
|
|
234
|
+
clientRequestId,
|
|
235
|
+
action: "contextExport",
|
|
236
|
+
actionParams: { runId, nodeId, attempt, profile, target, rawAcknowledged: profile === "raw" },
|
|
237
|
+
});
|
|
238
|
+
if (created.kind === "conflict") {
|
|
239
|
+
return {
|
|
240
|
+
status: 409,
|
|
241
|
+
body: { ok: false, error: { code: created.code, message: created.message } },
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
if (created.kind === "created") {
|
|
245
|
+
void recordContextTransferEvent({
|
|
246
|
+
appData: operator.actionContext.appData,
|
|
247
|
+
event: "context_export.planned",
|
|
248
|
+
fields: {
|
|
249
|
+
runId,
|
|
250
|
+
nodeId,
|
|
251
|
+
profile,
|
|
252
|
+
target,
|
|
253
|
+
operationId: created.operation.operationId,
|
|
254
|
+
},
|
|
255
|
+
}).catch(() => undefined);
|
|
256
|
+
queueMicrotask(() => {
|
|
257
|
+
void (async () => {
|
|
258
|
+
const startedAt = Date.now();
|
|
259
|
+
await operator.operations.update(created.operation.operationId, {
|
|
260
|
+
state: "running",
|
|
261
|
+
startedAt: new Date().toISOString(),
|
|
262
|
+
});
|
|
263
|
+
try {
|
|
264
|
+
const appData = operator.actionContext.appData;
|
|
265
|
+
if (!appData.contextExports)
|
|
266
|
+
throw new Error("console context export root unavailable");
|
|
267
|
+
ensureSecureDir(appData.contextExports);
|
|
268
|
+
const incomingPath = path.join(appData.contextExports, `${randomBytes(16).toString("hex")}.incoming.zip`);
|
|
269
|
+
await rm(incomingPath, { force: true });
|
|
270
|
+
try {
|
|
271
|
+
const kernel = await runKernelCommand({
|
|
272
|
+
ctx: input.ctx,
|
|
273
|
+
args: [
|
|
274
|
+
"dag", "context", "export",
|
|
275
|
+
"--run-id", runId,
|
|
276
|
+
"--node-id", nodeId,
|
|
277
|
+
"--attempt", String(attempt),
|
|
278
|
+
"--target", target,
|
|
279
|
+
"--redaction", profile,
|
|
280
|
+
...(profile === "raw" ? ["--acknowledge-sensitive-data"] : []),
|
|
281
|
+
"--output", incomingPath,
|
|
282
|
+
"--json",
|
|
283
|
+
],
|
|
284
|
+
});
|
|
285
|
+
const payload = (kernel.json ?? {});
|
|
286
|
+
if (!kernel.ok || !payload.bundleId || !payload.bundleSha256) {
|
|
287
|
+
throw new Error(kernelFailureMessage(kernel));
|
|
288
|
+
}
|
|
289
|
+
const zipBytes = await readFile(incomingPath);
|
|
290
|
+
const exported = await createContextExport({
|
|
291
|
+
appData,
|
|
292
|
+
bundle: {
|
|
293
|
+
zipBytes,
|
|
294
|
+
manifest: {
|
|
295
|
+
bundleId: payload.bundleId,
|
|
296
|
+
bundleSha256: payload.bundleSha256,
|
|
297
|
+
profile,
|
|
298
|
+
target,
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
});
|
|
302
|
+
await recordContextTransferDiagnostic({
|
|
303
|
+
appData: operator.actionContext.appData,
|
|
304
|
+
event: "context-bundle.generate",
|
|
305
|
+
dimensions: {
|
|
306
|
+
outcome: "succeeded",
|
|
307
|
+
target,
|
|
308
|
+
profile,
|
|
309
|
+
bytes: exported.bytes,
|
|
310
|
+
durationMs: Date.now() - startedAt,
|
|
311
|
+
},
|
|
312
|
+
}).catch(() => undefined);
|
|
313
|
+
await recordContextTransferEvent({
|
|
314
|
+
appData: operator.actionContext.appData,
|
|
315
|
+
event: "context_export.ready",
|
|
316
|
+
fields: {
|
|
317
|
+
runId,
|
|
318
|
+
nodeId,
|
|
319
|
+
exportId: exported.exportId,
|
|
320
|
+
profile,
|
|
321
|
+
target,
|
|
322
|
+
bytes: exported.bytes,
|
|
323
|
+
durationMs: Date.now() - startedAt,
|
|
324
|
+
operationId: created.operation.operationId,
|
|
325
|
+
},
|
|
326
|
+
}).catch(() => undefined);
|
|
327
|
+
await operator.operations.update(created.operation.operationId, {
|
|
328
|
+
state: "succeeded",
|
|
329
|
+
finishedAt: new Date().toISOString(),
|
|
330
|
+
result: {
|
|
331
|
+
ok: true,
|
|
332
|
+
exportId: exported.exportId,
|
|
333
|
+
bundleId: exported.bundleId,
|
|
334
|
+
bundleSha256: exported.bundleSha256,
|
|
335
|
+
bytes: exported.bytes,
|
|
336
|
+
expiresAt: exported.expiresAt,
|
|
337
|
+
downloadUrl: `/api/operator/v1/context-exports/${exported.exportId}/download`,
|
|
338
|
+
},
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
finally {
|
|
342
|
+
await rm(incomingPath, { force: true }).catch(() => undefined);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
catch (error) {
|
|
346
|
+
await recordContextTransferDiagnostic({
|
|
347
|
+
appData: operator.actionContext.appData,
|
|
348
|
+
event: "context-bundle.generate",
|
|
349
|
+
dimensions: {
|
|
350
|
+
outcome: "failed",
|
|
351
|
+
target,
|
|
352
|
+
profile,
|
|
353
|
+
reasonCode: "CONTEXT_EXPORT_FAILED",
|
|
354
|
+
durationMs: Date.now() - startedAt,
|
|
355
|
+
},
|
|
356
|
+
}).catch(() => undefined);
|
|
357
|
+
await recordContextTransferEvent({
|
|
358
|
+
appData: operator.actionContext.appData,
|
|
359
|
+
event: "context_export.failed",
|
|
360
|
+
fields: {
|
|
361
|
+
runId,
|
|
362
|
+
nodeId,
|
|
363
|
+
profile,
|
|
364
|
+
target,
|
|
365
|
+
reasonCode: "CONTEXT_EXPORT_FAILED",
|
|
366
|
+
durationMs: Date.now() - startedAt,
|
|
367
|
+
operationId: created.operation.operationId,
|
|
368
|
+
},
|
|
369
|
+
}).catch(() => undefined);
|
|
370
|
+
await operator.operations.update(created.operation.operationId, {
|
|
371
|
+
state: "failed",
|
|
372
|
+
finishedAt: new Date().toISOString(),
|
|
373
|
+
errorCode: "CONTEXT_EXPORT_FAILED",
|
|
374
|
+
errorMessage: error instanceof Error ? error.message : String(error),
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
})();
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
return {
|
|
381
|
+
status: 202,
|
|
382
|
+
body: {
|
|
383
|
+
operationId: created.operation.operationId,
|
|
384
|
+
state: created.operation.state,
|
|
385
|
+
clientRequestId: created.operation.clientRequestId,
|
|
386
|
+
action: created.operation.action,
|
|
387
|
+
},
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
async function runKernelCommand(input) {
|
|
391
|
+
const actionContext = input.ctx.operator.actionContext;
|
|
392
|
+
const run = actionContext.runCommand ??
|
|
393
|
+
((args, options) => actionContext.client.run(args, options));
|
|
394
|
+
return (await run(input.args, {
|
|
395
|
+
cwd: actionContext.repoRoot,
|
|
396
|
+
artifactName: `kernel-${input.args.filter((arg) => !arg.startsWith("--")).slice(0, 3).join("-").replace(/\s+/g, "-")}`,
|
|
397
|
+
expectJson: true,
|
|
398
|
+
env: { ...process.env, LOOP_CONSOLE_APP_DATA: actionContext.appData.root },
|
|
399
|
+
}));
|
|
400
|
+
}
|
|
401
|
+
function kernelFailureMessage(result) {
|
|
402
|
+
const stderr = result.stderr.trim();
|
|
403
|
+
if (stderr) {
|
|
404
|
+
const lastLine = stderr.split("\n").filter(Boolean).pop() ?? stderr;
|
|
405
|
+
return lastLine.slice(0, 300);
|
|
406
|
+
}
|
|
407
|
+
const stdout = result.stdout.trim();
|
|
408
|
+
if (stdout)
|
|
409
|
+
return stdout.slice(0, 300);
|
|
410
|
+
return `kernel command failed with exit code ${result.exitCode}`;
|
|
411
|
+
}
|
|
412
|
+
function decodeBoundedBase64(value) {
|
|
413
|
+
if (typeof value !== "string" || value.length === 0 || value.length > 14_000_000) {
|
|
414
|
+
throw new Error("candidateBase64 is required and exceeds no more than 10 MiB decoded");
|
|
415
|
+
}
|
|
416
|
+
if (!/^[A-Za-z0-9+/]*={0,2}$/.test(value) || value.length % 4 !== 0) {
|
|
417
|
+
throw new Error("candidateBase64 is invalid");
|
|
418
|
+
}
|
|
419
|
+
const bytes = Buffer.from(value, "base64");
|
|
420
|
+
if (bytes.byteLength > 10 * 1024 * 1024)
|
|
421
|
+
throw new Error("candidate exceeds 10 MiB");
|
|
422
|
+
return bytes;
|
|
423
|
+
}
|
|
424
|
+
function revisionProjection(revision) {
|
|
425
|
+
if (!revision)
|
|
426
|
+
return undefined;
|
|
427
|
+
return {
|
|
428
|
+
revisionId: revision.revisionId,
|
|
429
|
+
state: revision.state,
|
|
430
|
+
parent: revision.parent,
|
|
431
|
+
candidate: {
|
|
432
|
+
sha256: revision.candidate.sha256,
|
|
433
|
+
bytes: revision.candidate.bytes,
|
|
434
|
+
mediaType: revision.candidate.mediaType,
|
|
435
|
+
uploadedAt: revision.candidate.uploadedAt,
|
|
436
|
+
},
|
|
437
|
+
validation: revision.validation,
|
|
438
|
+
diff: {
|
|
439
|
+
kind: revision.diff.kind,
|
|
440
|
+
summary: revision.diff.summary,
|
|
441
|
+
truncated: revision.diff.truncated,
|
|
442
|
+
},
|
|
443
|
+
expiresAt: revision.expiresAt,
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
async function acceptArtifactRevisionOperation(input) {
|
|
447
|
+
const operator = input.ctx.operator;
|
|
448
|
+
const clientRequestId = input.clientRequestId?.trim();
|
|
449
|
+
if (!clientRequestId) {
|
|
450
|
+
return { status: 400, body: { ok: false, error: { code: "INVALID_INPUT", message: "clientRequestId is required" } } };
|
|
451
|
+
}
|
|
452
|
+
let candidateBytes;
|
|
453
|
+
try {
|
|
454
|
+
if (input.action === "artifactRevisionStage") {
|
|
455
|
+
candidateBytes = decodeBoundedBase64(input.actionParams.candidateBase64);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
catch (error) {
|
|
459
|
+
return { status: 400, body: { ok: false, error: { code: "INVALID_INPUT", message: error instanceof Error ? error.message : String(error) } } };
|
|
460
|
+
}
|
|
461
|
+
const runId = typeof input.actionParams.runId === "string" ? input.actionParams.runId.trim() : "";
|
|
462
|
+
const nodeId = typeof input.actionParams.nodeId === "string" ? input.actionParams.nodeId.trim() : "";
|
|
463
|
+
const artifactId = typeof input.actionParams.artifactId === "string" ? input.actionParams.artifactId.trim() : "";
|
|
464
|
+
const revisionId = typeof input.actionParams.revisionId === "string" ? input.actionParams.revisionId.trim() : "";
|
|
465
|
+
const planHash = typeof input.actionParams.planHash === "string" ? input.actionParams.planHash.trim() : "";
|
|
466
|
+
const reason = typeof input.actionParams.reason === "string" ? input.actionParams.reason.trim() : "";
|
|
467
|
+
const mediaType = typeof input.actionParams.mediaType === "string" ? input.actionParams.mediaType.trim() : "";
|
|
468
|
+
if (!runId || !artifactId || (input.action === "artifactRevisionStage" && (!nodeId || !mediaType))) {
|
|
469
|
+
return { status: 400, body: { ok: false, error: { code: "INVALID_INPUT", message: "runId, artifactId, nodeId and mediaType are required" } } };
|
|
470
|
+
}
|
|
471
|
+
if (input.action !== "artifactRevisionStage" && !revisionId) {
|
|
472
|
+
return { status: 400, body: { ok: false, error: { code: "INVALID_INPUT", message: "revisionId is required" } } };
|
|
473
|
+
}
|
|
474
|
+
if (input.action === "artifactRevisionExecute" && (!planHash || !reason)) {
|
|
475
|
+
return { status: 400, body: { ok: false, error: { code: "INVALID_INPUT", message: "planHash and reason are required" } } };
|
|
476
|
+
}
|
|
477
|
+
let workerContinuation;
|
|
478
|
+
if (input.action !== "artifactRevisionStage") {
|
|
479
|
+
try {
|
|
480
|
+
workerContinuation = await resolveWorkerContinuationAuthority({
|
|
481
|
+
repoRoot: input.ctx.repoRoot,
|
|
482
|
+
parentDagRunId: runId,
|
|
483
|
+
revisionId,
|
|
484
|
+
allowActiveRevision: input.action === "artifactRevisionExecute",
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
catch (error) {
|
|
488
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
489
|
+
return {
|
|
490
|
+
status: 422,
|
|
491
|
+
body: {
|
|
492
|
+
ok: false,
|
|
493
|
+
error: {
|
|
494
|
+
code: "WORKER_CONTINUATION_AUTHORITY_MISMATCH",
|
|
495
|
+
message,
|
|
496
|
+
},
|
|
497
|
+
},
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
const safeActionParams = {
|
|
502
|
+
runId,
|
|
503
|
+
artifactId,
|
|
504
|
+
...(nodeId ? { nodeId } : {}),
|
|
505
|
+
...(revisionId ? { revisionId } : {}),
|
|
506
|
+
...(planHash ? { planHash } : {}),
|
|
507
|
+
...(reason ? { reason } : {}),
|
|
508
|
+
...(mediaType ? { mediaType } : {}),
|
|
509
|
+
...(candidateBytes
|
|
510
|
+
? { candidateSha256: createHash("sha256").update(candidateBytes).digest("hex"), candidateBytes: candidateBytes.byteLength }
|
|
511
|
+
: {}),
|
|
512
|
+
...(workerContinuation
|
|
513
|
+
? { workerContinuation: workerContinuation.authority }
|
|
514
|
+
: {}),
|
|
515
|
+
};
|
|
516
|
+
const appData = operator.actionContext.appData;
|
|
517
|
+
if (!appData.artifactRevisions) {
|
|
518
|
+
return { status: 503, body: { ok: false, error: { code: "INTERNAL_ERROR", message: "console artifact revision root unavailable" } } };
|
|
519
|
+
}
|
|
520
|
+
let cliArgs;
|
|
521
|
+
if (input.action === "artifactRevisionStage") {
|
|
522
|
+
const candidateSha256 = safeActionParams.candidateSha256;
|
|
523
|
+
cliArgs = [
|
|
524
|
+
"dag", "artifact", "revision", "stage",
|
|
525
|
+
"--run-id", runId,
|
|
526
|
+
"--node-id", nodeId,
|
|
527
|
+
"--artifact-id", artifactId,
|
|
528
|
+
"--candidate-upload", candidateSha256,
|
|
529
|
+
"--request-id", `console-${clientRequestId}`,
|
|
530
|
+
"--json",
|
|
531
|
+
];
|
|
532
|
+
}
|
|
533
|
+
else if (input.action === "artifactRevisionPlan") {
|
|
534
|
+
cliArgs = [
|
|
535
|
+
"dag", "rerun",
|
|
536
|
+
"--run-id", runId,
|
|
537
|
+
"--artifact-revision", revisionId,
|
|
538
|
+
"--plan", "--json",
|
|
539
|
+
];
|
|
540
|
+
}
|
|
541
|
+
else {
|
|
542
|
+
cliArgs = [
|
|
543
|
+
"dag", "rerun",
|
|
544
|
+
"--run-id", runId,
|
|
545
|
+
"--artifact-revision", revisionId,
|
|
546
|
+
"--plan-hash", planHash,
|
|
547
|
+
"--request-id", `console-${clientRequestId}`,
|
|
548
|
+
"--reason", reason,
|
|
549
|
+
"--json",
|
|
550
|
+
];
|
|
551
|
+
}
|
|
552
|
+
if (workerContinuation) {
|
|
553
|
+
cliArgs.push("--worker-continuation", JSON.stringify(workerContinuation.authority));
|
|
554
|
+
}
|
|
555
|
+
let admittedOperationId;
|
|
556
|
+
const accepted = await acceptOperation(operator.actionContext, {
|
|
557
|
+
action: input.action,
|
|
558
|
+
actionParams: safeActionParams,
|
|
559
|
+
clientRequestId,
|
|
560
|
+
cliArgs,
|
|
561
|
+
...(input.action === "artifactRevisionStage" ||
|
|
562
|
+
(input.action === "artifactRevisionExecute" && workerContinuation)
|
|
563
|
+
? {
|
|
564
|
+
prepare: async () => {
|
|
565
|
+
if (input.action === "artifactRevisionStage") {
|
|
566
|
+
await writeArtifactRevisionUpload({
|
|
567
|
+
appData,
|
|
568
|
+
candidateSha256: safeActionParams.candidateSha256,
|
|
569
|
+
candidateBytes: candidateBytes,
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
else if (workerContinuation && admittedOperationId) {
|
|
573
|
+
await operator.actionContext.operations.update(admittedOperationId, { dagRunId: workerContinuation.authority.childWorkerRunId });
|
|
574
|
+
await beginWorkerContinuation({
|
|
575
|
+
repoRoot: input.ctx.repoRoot,
|
|
576
|
+
resolved: workerContinuation,
|
|
577
|
+
operationId: admittedOperationId,
|
|
578
|
+
client: operator.actionContext.client,
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
else {
|
|
582
|
+
throw new Error("Worker continuation operation identity is unavailable");
|
|
583
|
+
}
|
|
584
|
+
},
|
|
585
|
+
prepareFailure: (error) => {
|
|
586
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
587
|
+
if (input.action === "artifactRevisionExecute") {
|
|
588
|
+
const conflict = message.includes("attempt-lease-conflict") || message.includes("state-conflict");
|
|
589
|
+
return {
|
|
590
|
+
status: conflict ? 409 : 422,
|
|
591
|
+
errorCode: conflict
|
|
592
|
+
? "WORKER_CONTINUATION_LEASE_CONFLICT"
|
|
593
|
+
: "WORKER_CONTINUATION_AUTHORITY_MISMATCH",
|
|
594
|
+
body: {
|
|
595
|
+
ok: false,
|
|
596
|
+
error: {
|
|
597
|
+
code: conflict
|
|
598
|
+
? "WORKER_CONTINUATION_LEASE_CONFLICT"
|
|
599
|
+
: "WORKER_CONTINUATION_AUTHORITY_MISMATCH",
|
|
600
|
+
message,
|
|
601
|
+
},
|
|
602
|
+
},
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
const stableCode = [
|
|
606
|
+
"ARTIFACT_REVISION_QUOTA_EXCEEDED",
|
|
607
|
+
"ARTIFACT_REVISION_DRIFT",
|
|
608
|
+
"ARTIFACT_REVISION_PATH_INVALID",
|
|
609
|
+
].find((code) => message.startsWith(code));
|
|
610
|
+
void recordContextTransferEvent({
|
|
611
|
+
appData,
|
|
612
|
+
event: "artifact_revision.rejected",
|
|
613
|
+
fields: {
|
|
614
|
+
runId,
|
|
615
|
+
nodeId,
|
|
616
|
+
reasonCode: stableCode ?? "INVALID_INPUT",
|
|
617
|
+
},
|
|
618
|
+
}).catch(() => undefined);
|
|
619
|
+
return {
|
|
620
|
+
status: stableCode ? 422 : 400,
|
|
621
|
+
errorCode: stableCode ?? "INVALID_INPUT",
|
|
622
|
+
body: { ok: false, error: { code: stableCode ?? "INVALID_INPUT", message } },
|
|
623
|
+
};
|
|
624
|
+
},
|
|
625
|
+
}
|
|
626
|
+
: {}),
|
|
627
|
+
onAdmitted: (operation) => {
|
|
628
|
+
admittedOperationId = operation.operationId;
|
|
629
|
+
if (input.action === "artifactRevisionStage") {
|
|
630
|
+
return recordContextTransferEvent({
|
|
631
|
+
appData,
|
|
632
|
+
event: "artifact_revision.upload_started",
|
|
633
|
+
fields: {
|
|
634
|
+
runId,
|
|
635
|
+
nodeId,
|
|
636
|
+
operationId: operation.operationId,
|
|
637
|
+
},
|
|
638
|
+
}).catch(() => undefined);
|
|
639
|
+
}
|
|
640
|
+
if (input.action === "artifactRevisionExecute") {
|
|
641
|
+
return recordContextTransferEvent({
|
|
642
|
+
appData,
|
|
643
|
+
event: "artifact_rerun.execute_requested",
|
|
644
|
+
fields: {
|
|
645
|
+
runId,
|
|
646
|
+
revisionId,
|
|
647
|
+
operationId: operation.operationId,
|
|
648
|
+
},
|
|
649
|
+
}).catch(() => undefined);
|
|
650
|
+
}
|
|
651
|
+
return undefined;
|
|
652
|
+
},
|
|
653
|
+
...(input.action === "artifactRevisionExecute" && workerContinuation
|
|
654
|
+
? {
|
|
655
|
+
beforeTerminal: (operation, state, info) => settleWorkerContinuation({
|
|
656
|
+
repoRoot: input.ctx.repoRoot,
|
|
657
|
+
resolved: workerContinuation,
|
|
658
|
+
operation,
|
|
659
|
+
state,
|
|
660
|
+
info,
|
|
661
|
+
}),
|
|
662
|
+
}
|
|
663
|
+
: {}),
|
|
664
|
+
});
|
|
665
|
+
if (accepted.kind === "error") {
|
|
666
|
+
return { status: accepted.status, body: accepted.body };
|
|
667
|
+
}
|
|
668
|
+
return { status: accepted.status, body: accepted.body };
|
|
669
|
+
}
|
|
133
670
|
async function handleCreateOperation(req, res, ctx) {
|
|
134
671
|
if (!ctx.operator) {
|
|
135
672
|
sendJson(res, 503, {
|
|
@@ -141,12 +678,31 @@ async function handleCreateOperation(req, res, ctx) {
|
|
|
141
678
|
});
|
|
142
679
|
return;
|
|
143
680
|
}
|
|
144
|
-
const
|
|
681
|
+
const generalGateContext = {
|
|
682
|
+
cookieName: ctx.bootToken.cookieName,
|
|
145
683
|
bootToken: ctx.bootToken.value,
|
|
146
684
|
confirmationToken: ctx.bootToken.confirmationToken,
|
|
147
685
|
consoleOrigin: ctx.getConsoleOrigin(),
|
|
148
686
|
allowNonLoopbackAccess: ctx.allowNonLoopbackAccess === true,
|
|
149
|
-
}
|
|
687
|
+
};
|
|
688
|
+
let failure = evaluateMutationGate(req, generalGateContext);
|
|
689
|
+
let inspectScoped = false;
|
|
690
|
+
if (failure && ctx.inspectBootToken) {
|
|
691
|
+
// Scoped /inspect credentials: try the inspect gate before failing. The
|
|
692
|
+
// general gate already rejected, so passing here only ever yields the
|
|
693
|
+
// allowlisted actions below — never general write capability.
|
|
694
|
+
const scopedFailure = evaluateMutationGate(req, {
|
|
695
|
+
cookieName: ctx.inspectBootToken.cookieName,
|
|
696
|
+
bootToken: ctx.inspectBootToken.value,
|
|
697
|
+
confirmationToken: ctx.inspectBootToken.confirmationToken,
|
|
698
|
+
consoleOrigin: ctx.getConsoleOrigin(),
|
|
699
|
+
allowNonLoopbackAccess: ctx.allowNonLoopbackAccess === true,
|
|
700
|
+
});
|
|
701
|
+
if (!scopedFailure) {
|
|
702
|
+
inspectScoped = true;
|
|
703
|
+
failure = undefined;
|
|
704
|
+
}
|
|
705
|
+
}
|
|
150
706
|
if (failure) {
|
|
151
707
|
sendJson(res, failure.status, {
|
|
152
708
|
ok: false,
|
|
@@ -156,7 +712,7 @@ async function handleCreateOperation(req, res, ctx) {
|
|
|
156
712
|
}
|
|
157
713
|
let body;
|
|
158
714
|
try {
|
|
159
|
-
body = (await readJsonBody(req));
|
|
715
|
+
body = (await readJsonBody(req, 15 * 1024 * 1024));
|
|
160
716
|
}
|
|
161
717
|
catch (error) {
|
|
162
718
|
sendJson(res, 400, {
|
|
@@ -173,10 +729,42 @@ async function handleCreateOperation(req, res, ctx) {
|
|
|
173
729
|
? body.actionParams
|
|
174
730
|
: {};
|
|
175
731
|
const clientRequestId = typeof body.clientRequestId === "string" ? body.clientRequestId : undefined;
|
|
732
|
+
if (inspectScoped && !INSPECT_MUTATION_ALLOWED_ACTIONS.has(action)) {
|
|
733
|
+
sendJson(res, 403, {
|
|
734
|
+
ok: false,
|
|
735
|
+
error: {
|
|
736
|
+
code: "ACTION_NOT_IN_INSPECT_SCOPE",
|
|
737
|
+
message: `inspect-scoped token only allows: ${[...INSPECT_MUTATION_ALLOWED_ACTIONS].join(", ")}`,
|
|
738
|
+
},
|
|
739
|
+
});
|
|
740
|
+
return;
|
|
741
|
+
}
|
|
742
|
+
if (action === "contextExport") {
|
|
743
|
+
const accepted = await acceptContextExportOperation({
|
|
744
|
+
ctx,
|
|
745
|
+
actionParams,
|
|
746
|
+
clientRequestId,
|
|
747
|
+
});
|
|
748
|
+
sendJson(res, accepted.status, accepted.body);
|
|
749
|
+
return;
|
|
750
|
+
}
|
|
751
|
+
if (action === "artifactRevisionStage" ||
|
|
752
|
+
action === "artifactRevisionPlan" ||
|
|
753
|
+
action === "artifactRevisionExecute") {
|
|
754
|
+
const accepted = await acceptArtifactRevisionOperation({
|
|
755
|
+
ctx,
|
|
756
|
+
action,
|
|
757
|
+
actionParams,
|
|
758
|
+
clientRequestId,
|
|
759
|
+
});
|
|
760
|
+
sendJson(res, accepted.status, accepted.body);
|
|
761
|
+
return;
|
|
762
|
+
}
|
|
176
763
|
const result = await dispatchOperatorAction(ctx.operator.actionContext, {
|
|
177
764
|
action,
|
|
178
765
|
actionParams,
|
|
179
766
|
clientRequestId,
|
|
767
|
+
source: "human-ui",
|
|
180
768
|
});
|
|
181
769
|
sendJson(res, result.status, result.body);
|
|
182
770
|
}
|
|
@@ -202,7 +790,35 @@ async function handleGetOperation(_req, res, ctx, operationId) {
|
|
|
202
790
|
});
|
|
203
791
|
return;
|
|
204
792
|
}
|
|
205
|
-
sendJson(res, 200, {
|
|
793
|
+
sendJson(res, 200, {
|
|
794
|
+
ok: true,
|
|
795
|
+
workspaceId: ctx.workspace?.workspaceId,
|
|
796
|
+
operation: { ...op, workspaceId: ctx.workspace?.workspaceId },
|
|
797
|
+
});
|
|
798
|
+
}
|
|
799
|
+
/**
|
|
800
|
+
* GET /api/operator/v1/operations?workspaceId= — NEW per-workspace list route
|
|
801
|
+
* (multi-workspace foundation). Returns only the resolved Context's Operations
|
|
802
|
+
* and injects the owning workspaceId. operation-store.ts is unchanged.
|
|
803
|
+
*/
|
|
804
|
+
async function handleListOperations(_req, res, ctx) {
|
|
805
|
+
if (!ctx.operator) {
|
|
806
|
+
sendJson(res, 503, {
|
|
807
|
+
ok: false,
|
|
808
|
+
error: {
|
|
809
|
+
code: "INTERNAL_ERROR",
|
|
810
|
+
message: "operator runtime unavailable",
|
|
811
|
+
},
|
|
812
|
+
});
|
|
813
|
+
return;
|
|
814
|
+
}
|
|
815
|
+
const operations = await ctx.operator.operations.list();
|
|
816
|
+
sendJson(res, 200, {
|
|
817
|
+
ok: true,
|
|
818
|
+
schemaVersion: 1,
|
|
819
|
+
workspaceId: ctx.workspace?.workspaceId,
|
|
820
|
+
ops: operations.map((op) => ({ ...op, workspaceId: ctx.workspace?.workspaceId })),
|
|
821
|
+
});
|
|
206
822
|
}
|
|
207
823
|
async function handleOperationEvents(req, res, ctx, operationId) {
|
|
208
824
|
if (!ctx.operator) {
|
|
@@ -287,6 +903,34 @@ async function handleOperationEvents(req, res, ctx, operationId) {
|
|
|
287
903
|
* Path-escape-safe static file serve for Console SPA.
|
|
288
904
|
* Sets boot capability cookie on HTML responses.
|
|
289
905
|
*/
|
|
906
|
+
/**
|
|
907
|
+
* Inject the general Console confirmation token into HTML, and additionally
|
|
908
|
+
* the scoped inspect mutation token when the experimental prompt-override
|
|
909
|
+
* switch is enabled and inspect credentials are available. The standalone
|
|
910
|
+
* /inspect/ document canonicalizes into the Console SPA (/#/inspect...), so
|
|
911
|
+
* the SPA must carry the scoped inspect token for the export/rerun tab to be
|
|
912
|
+
* rendered by the mounted inspect workspace.
|
|
913
|
+
*/
|
|
914
|
+
function injectScopedInspectTokens(raw, ctx) {
|
|
915
|
+
let content = injectConfirmationTokenScript(raw, ctx.bootToken.confirmationToken);
|
|
916
|
+
if (isDagRerunPromptOverrideEnabled() && ctx.inspectBootToken) {
|
|
917
|
+
content = injectConfirmationTokenScript(content, ctx.inspectBootToken.confirmationToken, "__INSPECT_MUTATION_TOKEN__");
|
|
918
|
+
}
|
|
919
|
+
return content;
|
|
920
|
+
}
|
|
921
|
+
/**
|
|
922
|
+
* HTML response Set-Cookie headers for the Console SPA. The general boot
|
|
923
|
+
* cookie is always set; when the experimental prompt-override switch is
|
|
924
|
+
* enabled the scoped inspect cookie is set alongside so the hosted inspect
|
|
925
|
+
* workspace (mounted inside the SPA) can authenticate its allowlisted
|
|
926
|
+
* mutation requests.
|
|
927
|
+
*/
|
|
928
|
+
function scopedSetCookieHeaders(ctx) {
|
|
929
|
+
if (isDagRerunPromptOverrideEnabled() && ctx.inspectBootToken) {
|
|
930
|
+
return [ctx.bootToken.setCookieHeader, ctx.inspectBootToken.setCookieHeader];
|
|
931
|
+
}
|
|
932
|
+
return ctx.bootToken.setCookieHeader;
|
|
933
|
+
}
|
|
290
934
|
export async function serveConsoleStatic(req, res, ctx) {
|
|
291
935
|
const url = new URL(req.url ?? "/", "http://localhost");
|
|
292
936
|
let pathname = decodeURIComponent(url.pathname);
|
|
@@ -305,11 +949,14 @@ export async function serveConsoleStatic(req, res, ctx) {
|
|
|
305
949
|
// SPA fallback for non-file routes
|
|
306
950
|
const indexPath = path.join(resolvedStatic, "index.html");
|
|
307
951
|
if (existsSync(indexPath) && !pathname.includes(".")) {
|
|
308
|
-
const html =
|
|
952
|
+
const html = injectScopedInspectTokens(await readFile(indexPath), ctx);
|
|
309
953
|
res.writeHead(200, {
|
|
310
954
|
"Content-Type": "text/html; charset=utf-8",
|
|
311
955
|
"Content-Length": html.byteLength,
|
|
312
|
-
|
|
956
|
+
// Boot capability tokens are baked into the document; a cached
|
|
957
|
+
// page from a previous Console process makes every mutation 403.
|
|
958
|
+
"Cache-Control": "no-store",
|
|
959
|
+
"Set-Cookie": scopedSetCookieHeaders(ctx),
|
|
313
960
|
});
|
|
314
961
|
res.end(html);
|
|
315
962
|
return;
|
|
@@ -320,14 +967,15 @@ export async function serveConsoleStatic(req, res, ctx) {
|
|
|
320
967
|
const raw = await readFile(resolvedFile);
|
|
321
968
|
const contentType = contentTypeFor(pathname);
|
|
322
969
|
const content = contentType.startsWith("text/html")
|
|
323
|
-
?
|
|
970
|
+
? injectScopedInspectTokens(raw, ctx)
|
|
324
971
|
: raw;
|
|
325
972
|
const headers = {
|
|
326
973
|
"Content-Type": contentType,
|
|
327
974
|
"Content-Length": content.byteLength,
|
|
328
975
|
};
|
|
329
976
|
if (contentType.startsWith("text/html")) {
|
|
330
|
-
headers["
|
|
977
|
+
headers["Cache-Control"] = "no-store";
|
|
978
|
+
headers["Set-Cookie"] = scopedSetCookieHeaders(ctx);
|
|
331
979
|
}
|
|
332
980
|
res.writeHead(200, headers);
|
|
333
981
|
res.end(content);
|
|
@@ -385,6 +1033,95 @@ async function handleNightAuxTickerPost(req, res, ctx) {
|
|
|
385
1033
|
const status = ticker.setEnabled(body.enabled);
|
|
386
1034
|
sendJson(res, 200, { ok: true, ticker: status });
|
|
387
1035
|
}
|
|
1036
|
+
async function handlePiPluginInstall(req, res) {
|
|
1037
|
+
let body;
|
|
1038
|
+
try {
|
|
1039
|
+
body = (await readJsonBody(req));
|
|
1040
|
+
}
|
|
1041
|
+
catch (error) {
|
|
1042
|
+
sendJson(res, 400, {
|
|
1043
|
+
ok: false,
|
|
1044
|
+
error: {
|
|
1045
|
+
code: "INVALID_INPUT",
|
|
1046
|
+
message: error instanceof Error ? error.message : String(error),
|
|
1047
|
+
},
|
|
1048
|
+
});
|
|
1049
|
+
return;
|
|
1050
|
+
}
|
|
1051
|
+
const name = typeof body.name === "string" ? body.name.trim() : "";
|
|
1052
|
+
if (!name) {
|
|
1053
|
+
sendJson(res, 400, {
|
|
1054
|
+
ok: false,
|
|
1055
|
+
error: { code: "INVALID_INPUT", message: "missing package name" },
|
|
1056
|
+
});
|
|
1057
|
+
return;
|
|
1058
|
+
}
|
|
1059
|
+
const version = typeof body.version === "string" ? body.version.trim() : undefined;
|
|
1060
|
+
try {
|
|
1061
|
+
const result = await installPiPlugin(name, version);
|
|
1062
|
+
if (!result.ok) {
|
|
1063
|
+
sendJson(res, 400, {
|
|
1064
|
+
ok: false,
|
|
1065
|
+
error: { code: "INSTALL_FAILED", message: result.error },
|
|
1066
|
+
});
|
|
1067
|
+
return;
|
|
1068
|
+
}
|
|
1069
|
+
sendJson(res, 200, { ok: true });
|
|
1070
|
+
}
|
|
1071
|
+
catch (error) {
|
|
1072
|
+
sendJson(res, 500, {
|
|
1073
|
+
ok: false,
|
|
1074
|
+
error: {
|
|
1075
|
+
code: "INTERNAL_ERROR",
|
|
1076
|
+
message: error instanceof Error ? error.message : String(error),
|
|
1077
|
+
},
|
|
1078
|
+
});
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
async function handlePiPluginUninstall(req, res) {
|
|
1082
|
+
let body;
|
|
1083
|
+
try {
|
|
1084
|
+
body = (await readJsonBody(req));
|
|
1085
|
+
}
|
|
1086
|
+
catch (error) {
|
|
1087
|
+
sendJson(res, 400, {
|
|
1088
|
+
ok: false,
|
|
1089
|
+
error: {
|
|
1090
|
+
code: "INVALID_INPUT",
|
|
1091
|
+
message: error instanceof Error ? error.message : String(error),
|
|
1092
|
+
},
|
|
1093
|
+
});
|
|
1094
|
+
return;
|
|
1095
|
+
}
|
|
1096
|
+
const name = typeof body.name === "string" ? body.name.trim() : "";
|
|
1097
|
+
if (!name) {
|
|
1098
|
+
sendJson(res, 400, {
|
|
1099
|
+
ok: false,
|
|
1100
|
+
error: { code: "INVALID_INPUT", message: "missing package name" },
|
|
1101
|
+
});
|
|
1102
|
+
return;
|
|
1103
|
+
}
|
|
1104
|
+
try {
|
|
1105
|
+
const result = await uninstallPiPlugin(name);
|
|
1106
|
+
if (!result.ok) {
|
|
1107
|
+
sendJson(res, 400, {
|
|
1108
|
+
ok: false,
|
|
1109
|
+
error: { code: "UNINSTALL_FAILED", message: result.error },
|
|
1110
|
+
});
|
|
1111
|
+
return;
|
|
1112
|
+
}
|
|
1113
|
+
sendJson(res, 200, { ok: true });
|
|
1114
|
+
}
|
|
1115
|
+
catch (error) {
|
|
1116
|
+
sendJson(res, 500, {
|
|
1117
|
+
ok: false,
|
|
1118
|
+
error: {
|
|
1119
|
+
code: "INTERNAL_ERROR",
|
|
1120
|
+
message: error instanceof Error ? error.message : String(error),
|
|
1121
|
+
},
|
|
1122
|
+
});
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
388
1125
|
export async function handleConsoleOperatorRequest(req, res, ctx) {
|
|
389
1126
|
const method = (req.method ?? "GET").toUpperCase();
|
|
390
1127
|
const url = new URL(req.url ?? "/", "http://localhost");
|
|
@@ -410,10 +1147,101 @@ export async function handleConsoleOperatorRequest(req, res, ctx) {
|
|
|
410
1147
|
await handleCreateOperation(req, res, ctx);
|
|
411
1148
|
return true;
|
|
412
1149
|
}
|
|
1150
|
+
if (method === "GET" && pathname === "/api/operator/v1/operations") {
|
|
1151
|
+
await handleListOperations(req, res, ctx);
|
|
1152
|
+
return true;
|
|
1153
|
+
}
|
|
1154
|
+
const contextDownloadMatch = pathname.match(/^\/api\/operator\/v1\/context-exports\/([a-f0-9]{32})\/download$/);
|
|
1155
|
+
if (method === "GET" && contextDownloadMatch) {
|
|
1156
|
+
if (!ctx.operator) {
|
|
1157
|
+
sendJson(res, 503, { ok: false, error: { code: "INTERNAL_ERROR", message: "operator runtime unavailable" } });
|
|
1158
|
+
return true;
|
|
1159
|
+
}
|
|
1160
|
+
const failure = evaluateConsoleDownloadCapability(req, ctx);
|
|
1161
|
+
if (failure) {
|
|
1162
|
+
sendJson(res, failure.status, { ok: false, error: { code: failure.code, message: failure.message } });
|
|
1163
|
+
return true;
|
|
1164
|
+
}
|
|
1165
|
+
try {
|
|
1166
|
+
const exportId = contextDownloadMatch[1];
|
|
1167
|
+
const leased = await acquireContextExportLease({
|
|
1168
|
+
appData: ctx.operator.actionContext.appData,
|
|
1169
|
+
exportId,
|
|
1170
|
+
});
|
|
1171
|
+
res.writeHead(200, {
|
|
1172
|
+
"Content-Type": "application/zip",
|
|
1173
|
+
"Content-Length": leased.bytes.byteLength,
|
|
1174
|
+
"Content-Disposition": `attachment; filename="context-${leased.record.bundleId}.zip"`,
|
|
1175
|
+
"Cache-Control": "no-store",
|
|
1176
|
+
"X-Content-Type-Options": "nosniff",
|
|
1177
|
+
});
|
|
1178
|
+
res.end(leased.bytes);
|
|
1179
|
+
await releaseContextExportLease({
|
|
1180
|
+
appData: ctx.operator.actionContext.appData,
|
|
1181
|
+
exportId,
|
|
1182
|
+
leaseId: leased.leaseId,
|
|
1183
|
+
}).catch(() => undefined);
|
|
1184
|
+
}
|
|
1185
|
+
catch (error) {
|
|
1186
|
+
if (res.headersSent)
|
|
1187
|
+
return true;
|
|
1188
|
+
sendJson(res, 404, {
|
|
1189
|
+
ok: false,
|
|
1190
|
+
error: { code: "CONTEXT_EXPORT_UNAVAILABLE", message: error instanceof Error ? error.message : String(error) },
|
|
1191
|
+
});
|
|
1192
|
+
}
|
|
1193
|
+
return true;
|
|
1194
|
+
}
|
|
413
1195
|
if (method === "GET" && pathname === "/api/operator/v1/night-aux-ticker") {
|
|
414
1196
|
await handleNightAuxTickerGet(req, res, ctx);
|
|
415
1197
|
return true;
|
|
416
1198
|
}
|
|
1199
|
+
if (method === "GET" && pathname === "/api/operator/v1/pi-plugins") {
|
|
1200
|
+
sendJson(res, 200, { ok: true, data: listPiPlugins() });
|
|
1201
|
+
return true;
|
|
1202
|
+
}
|
|
1203
|
+
if (method === "GET" &&
|
|
1204
|
+
pathname === "/api/operator/v1/pi-plugins/versions") {
|
|
1205
|
+
const name = url.searchParams.get("name")?.trim() ?? "";
|
|
1206
|
+
if (!name) {
|
|
1207
|
+
sendJson(res, 400, {
|
|
1208
|
+
ok: false,
|
|
1209
|
+
error: { code: "INVALID_INPUT", message: "missing name" },
|
|
1210
|
+
});
|
|
1211
|
+
return true;
|
|
1212
|
+
}
|
|
1213
|
+
const result = await listPiPluginVersions(name);
|
|
1214
|
+
if (!result.ok) {
|
|
1215
|
+
sendJson(res, 400, {
|
|
1216
|
+
ok: false,
|
|
1217
|
+
error: { code: "FETCH_FAILED", message: result.error },
|
|
1218
|
+
});
|
|
1219
|
+
return true;
|
|
1220
|
+
}
|
|
1221
|
+
sendJson(res, 200, {
|
|
1222
|
+
ok: true,
|
|
1223
|
+
data: { versions: result.versions, latest: result.latest },
|
|
1224
|
+
});
|
|
1225
|
+
return true;
|
|
1226
|
+
}
|
|
1227
|
+
if (method === "GET" && pathname === "/api/operator/v1/pi-plugins/updates") {
|
|
1228
|
+
try {
|
|
1229
|
+
const view = await checkPiPluginUpdates({
|
|
1230
|
+
force: url.searchParams.get("force") === "1",
|
|
1231
|
+
});
|
|
1232
|
+
sendJson(res, 200, { ok: true, data: view });
|
|
1233
|
+
}
|
|
1234
|
+
catch (error) {
|
|
1235
|
+
sendJson(res, 500, {
|
|
1236
|
+
ok: false,
|
|
1237
|
+
error: {
|
|
1238
|
+
code: "INTERNAL_ERROR",
|
|
1239
|
+
message: error instanceof Error ? error.message : String(error),
|
|
1240
|
+
},
|
|
1241
|
+
});
|
|
1242
|
+
}
|
|
1243
|
+
return true;
|
|
1244
|
+
}
|
|
417
1245
|
const opMatch = pathname.match(/^\/api\/operator\/v1\/operations\/([^/]+)(?:\/(events))?$/);
|
|
418
1246
|
if (opMatch) {
|
|
419
1247
|
const operationId = decodeURIComponent(opMatch[1]);
|
|
@@ -428,6 +1256,7 @@ export async function handleConsoleOperatorRequest(req, res, ctx) {
|
|
|
428
1256
|
}
|
|
429
1257
|
if (isMutationMethod(method)) {
|
|
430
1258
|
const failure = evaluateMutationGate(req, {
|
|
1259
|
+
cookieName: ctx.bootToken.cookieName,
|
|
431
1260
|
bootToken: ctx.bootToken.value,
|
|
432
1261
|
confirmationToken: ctx.bootToken.confirmationToken,
|
|
433
1262
|
consoleOrigin: ctx.getConsoleOrigin(),
|
|
@@ -444,6 +1273,14 @@ export async function handleConsoleOperatorRequest(req, res, ctx) {
|
|
|
444
1273
|
await handleNightAuxTickerPost(req, res, ctx);
|
|
445
1274
|
return true;
|
|
446
1275
|
}
|
|
1276
|
+
if (method === "POST" && pathname === "/api/operator/v1/pi-plugins/install") {
|
|
1277
|
+
await handlePiPluginInstall(req, res);
|
|
1278
|
+
return true;
|
|
1279
|
+
}
|
|
1280
|
+
if (method === "POST" && pathname === "/api/operator/v1/pi-plugins/uninstall") {
|
|
1281
|
+
await handlePiPluginUninstall(req, res);
|
|
1282
|
+
return true;
|
|
1283
|
+
}
|
|
447
1284
|
// Allow other operator POSTs only under known routes; unknown → 404
|
|
448
1285
|
sendJson(res, 404, {
|
|
449
1286
|
ok: false,
|
|
@@ -473,3 +1310,387 @@ export async function handleConsoleRequest(req, res, ctx) {
|
|
|
473
1310
|
}
|
|
474
1311
|
return false;
|
|
475
1312
|
}
|
|
1313
|
+
export function createWorkspaceReadinessCache() {
|
|
1314
|
+
const entries = new Map();
|
|
1315
|
+
return {
|
|
1316
|
+
get: (repoRoot) => entries.get(repoRoot),
|
|
1317
|
+
set: (repoRoot, entry) => {
|
|
1318
|
+
entries.set(repoRoot, entry);
|
|
1319
|
+
},
|
|
1320
|
+
};
|
|
1321
|
+
}
|
|
1322
|
+
const defaultWorkspaceReadinessCache = createWorkspaceReadinessCache();
|
|
1323
|
+
const READY_STATE_TTL_MS = 60_000;
|
|
1324
|
+
const NON_READY_STATE_TTL_MS = 15_000;
|
|
1325
|
+
function isCacheFresh(entry, now) {
|
|
1326
|
+
const ttl = entry.state === "ready" ? READY_STATE_TTL_MS : NON_READY_STATE_TTL_MS;
|
|
1327
|
+
return now - entry.probedAt < ttl;
|
|
1328
|
+
}
|
|
1329
|
+
/** Readiness placeholder for a never-probed workspace (AC-006): the list is
|
|
1330
|
+
* still returned immediately with a pending marker, refreshed by the
|
|
1331
|
+
* background probe. */
|
|
1332
|
+
function pendingReadinessSummary(inspectReady) {
|
|
1333
|
+
return {
|
|
1334
|
+
state: "pending",
|
|
1335
|
+
summary: `pi=pending; inspect=${inspectReady ? "ready" : "unavailable"}`,
|
|
1336
|
+
};
|
|
1337
|
+
}
|
|
1338
|
+
/**
|
|
1339
|
+
* Process-level Workspace Registry HTTP surface (2026-08-22 multi-workspace
|
|
1340
|
+
* foundation):
|
|
1341
|
+
* GET /api/operator/v1/workspaces — visible list
|
|
1342
|
+
* POST /api/operator/v1/workspaces/pick — host native folder chooser
|
|
1343
|
+
* POST /api/operator/v1/workspaces — body { "name": "<label>",
|
|
1344
|
+
* "directoryPath": "<dir>" }
|
|
1345
|
+
* PATCH /api/operator/v1/workspaces/:workspaceId — body { "beforeWorkspaceId":
|
|
1346
|
+
* "<id>" | null }
|
|
1347
|
+
* DELETE /api/operator/v1/workspaces/:workspaceId — soft remove (restore on re-add)
|
|
1348
|
+
*
|
|
1349
|
+
* POST/PATCH/DELETE are mutations and pass the Console mutation gate. GET carries no
|
|
1350
|
+
* workspace selection parameter.
|
|
1351
|
+
*
|
|
1352
|
+
* AC-006 (2026-08-23): GET is NON-BLOCKING — registry + process-level
|
|
1353
|
+
* readiness cache answer immediately (first sight may be a pending
|
|
1354
|
+
* placeholder); probes refresh the cache in the background for subsequent
|
|
1355
|
+
* requests. A hanging probe can never delay the 200 list.
|
|
1356
|
+
*/
|
|
1357
|
+
export async function handleWorkspaceRoutes(req, res, registry, deps, url, pathname, method, readinessDeps) {
|
|
1358
|
+
if (method === "GET" &&
|
|
1359
|
+
pathname === "/api/operator/v1/workspaces/events") {
|
|
1360
|
+
res.writeHead(200, {
|
|
1361
|
+
"Content-Type": "text/event-stream; charset=utf-8",
|
|
1362
|
+
"Cache-Control": "no-cache, no-transform",
|
|
1363
|
+
Connection: "keep-alive",
|
|
1364
|
+
"X-Accel-Buffering": "no",
|
|
1365
|
+
});
|
|
1366
|
+
const sendRevision = (event, revision) => {
|
|
1367
|
+
if (res.destroyed || res.writableEnded)
|
|
1368
|
+
return;
|
|
1369
|
+
res.write(`id: ${revision}\nevent: ${event}\ndata: ${JSON.stringify({ schemaVersion: 1, revision })}\n\n`);
|
|
1370
|
+
};
|
|
1371
|
+
let baselineSent = false;
|
|
1372
|
+
let pendingRevision = 0;
|
|
1373
|
+
const unsubscribe = registry.subscribe((revision) => {
|
|
1374
|
+
if (!baselineSent)
|
|
1375
|
+
pendingRevision = Math.max(pendingRevision, revision);
|
|
1376
|
+
else
|
|
1377
|
+
sendRevision("workspace_registry_changed", revision);
|
|
1378
|
+
});
|
|
1379
|
+
const initial = await registry.snapshotVisible();
|
|
1380
|
+
sendRevision("workspace_registry_ready", initial.revision);
|
|
1381
|
+
baselineSent = true;
|
|
1382
|
+
if (pendingRevision > initial.revision) {
|
|
1383
|
+
sendRevision("workspace_registry_changed", pendingRevision);
|
|
1384
|
+
}
|
|
1385
|
+
const heartbeat = setInterval(() => {
|
|
1386
|
+
if (!res.destroyed && !res.writableEnded)
|
|
1387
|
+
res.write(": keepalive\n\n");
|
|
1388
|
+
}, 15_000);
|
|
1389
|
+
heartbeat.unref();
|
|
1390
|
+
let closed = false;
|
|
1391
|
+
const close = () => {
|
|
1392
|
+
if (closed)
|
|
1393
|
+
return;
|
|
1394
|
+
closed = true;
|
|
1395
|
+
clearInterval(heartbeat);
|
|
1396
|
+
unsubscribe();
|
|
1397
|
+
};
|
|
1398
|
+
req.once("aborted", close);
|
|
1399
|
+
res.once("close", close);
|
|
1400
|
+
return;
|
|
1401
|
+
}
|
|
1402
|
+
if (method === "GET" && pathname === "/api/operator/v1/workspaces") {
|
|
1403
|
+
const snapshot = await registry.snapshotVisible();
|
|
1404
|
+
const records = snapshot.workspaces;
|
|
1405
|
+
const inspectReady = readinessDeps.inspectReady;
|
|
1406
|
+
const readinessCache = readinessDeps.readinessCache ?? defaultWorkspaceReadinessCache;
|
|
1407
|
+
const workspaces = records.map((record) => {
|
|
1408
|
+
const cached = readinessCache.get(record.repoRoot);
|
|
1409
|
+
return {
|
|
1410
|
+
workspaceId: record.workspaceId,
|
|
1411
|
+
name: record.name,
|
|
1412
|
+
displayPath: record.displayPath,
|
|
1413
|
+
repoFingerprint: record.repoFingerprint,
|
|
1414
|
+
createdAt: record.createdAt,
|
|
1415
|
+
lastAccessedAt: record.lastAccessedAt,
|
|
1416
|
+
sessionIds: record.sessionIds,
|
|
1417
|
+
readiness: cached
|
|
1418
|
+
? {
|
|
1419
|
+
state: cached.state,
|
|
1420
|
+
summary: `pi=${cached.state}; inspect=${inspectReady ? "ready" : "unavailable"}`,
|
|
1421
|
+
}
|
|
1422
|
+
: pendingReadinessSummary(inspectReady),
|
|
1423
|
+
};
|
|
1424
|
+
});
|
|
1425
|
+
// Respond FIRST, then refresh readiness in the background (AC-006).
|
|
1426
|
+
sendJson(res, 200, {
|
|
1427
|
+
ok: true,
|
|
1428
|
+
schemaVersion: 2,
|
|
1429
|
+
revision: snapshot.revision,
|
|
1430
|
+
workspaces,
|
|
1431
|
+
});
|
|
1432
|
+
void Promise.all(records.map(async (record) => {
|
|
1433
|
+
const cached = readinessCache.get(record.repoRoot);
|
|
1434
|
+
if (cached && isCacheFresh(cached, Date.now()))
|
|
1435
|
+
return;
|
|
1436
|
+
let state;
|
|
1437
|
+
try {
|
|
1438
|
+
const report = await probePiReadiness({
|
|
1439
|
+
override: deps.piReadinessProbe,
|
|
1440
|
+
repoRoot: record.repoRoot,
|
|
1441
|
+
});
|
|
1442
|
+
state = report.state;
|
|
1443
|
+
}
|
|
1444
|
+
catch {
|
|
1445
|
+
state = "setup-required";
|
|
1446
|
+
}
|
|
1447
|
+
readinessCache.set(record.repoRoot, {
|
|
1448
|
+
state,
|
|
1449
|
+
probedAt: Date.now(),
|
|
1450
|
+
});
|
|
1451
|
+
})).catch(() => undefined);
|
|
1452
|
+
return;
|
|
1453
|
+
}
|
|
1454
|
+
if (method === "POST" && pathname === "/api/operator/v1/workspaces/pick") {
|
|
1455
|
+
const failure = evaluateMutationGate(req, {
|
|
1456
|
+
cookieName: deps.bootToken.cookieName,
|
|
1457
|
+
bootToken: deps.bootToken.value,
|
|
1458
|
+
confirmationToken: deps.bootToken.confirmationToken,
|
|
1459
|
+
consoleOrigin: deps.getConsoleOrigin(),
|
|
1460
|
+
allowNonLoopbackAccess: deps.allowNonLoopbackAccess,
|
|
1461
|
+
});
|
|
1462
|
+
if (failure) {
|
|
1463
|
+
sendJson(res, failure.status, {
|
|
1464
|
+
ok: false,
|
|
1465
|
+
error: { code: failure.code, message: failure.message },
|
|
1466
|
+
});
|
|
1467
|
+
return;
|
|
1468
|
+
}
|
|
1469
|
+
if (deps.allowNonLoopbackAccess) {
|
|
1470
|
+
sendJson(res, 409, {
|
|
1471
|
+
ok: false,
|
|
1472
|
+
error: {
|
|
1473
|
+
code: "NATIVE_PICKER_UNAVAILABLE",
|
|
1474
|
+
message: "原生目录选择仅在本机回环地址启动的 Console 中可用。",
|
|
1475
|
+
},
|
|
1476
|
+
});
|
|
1477
|
+
return;
|
|
1478
|
+
}
|
|
1479
|
+
const abortController = new AbortController();
|
|
1480
|
+
const abort = () => abortController.abort();
|
|
1481
|
+
req.once("aborted", abort);
|
|
1482
|
+
res.once("close", abort);
|
|
1483
|
+
try {
|
|
1484
|
+
const directoryPath = await (deps.pickDirectory ?? pickNativeWorkspaceDirectory)(abortController.signal);
|
|
1485
|
+
if (!res.writableEnded && !abortController.signal.aborted) {
|
|
1486
|
+
sendJson(res, 200, { ok: true, directoryPath });
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
catch (error) {
|
|
1490
|
+
if (!res.writableEnded && !abortController.signal.aborted) {
|
|
1491
|
+
sendJson(res, 500, {
|
|
1492
|
+
ok: false,
|
|
1493
|
+
error: {
|
|
1494
|
+
code: "DIRECTORY_PICKER_FAILED",
|
|
1495
|
+
message: error instanceof Error ? error.message : String(error),
|
|
1496
|
+
},
|
|
1497
|
+
});
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1500
|
+
finally {
|
|
1501
|
+
req.off("aborted", abort);
|
|
1502
|
+
res.off("close", abort);
|
|
1503
|
+
}
|
|
1504
|
+
return;
|
|
1505
|
+
}
|
|
1506
|
+
if (method === "POST" && pathname === "/api/operator/v1/workspaces") {
|
|
1507
|
+
const failure = evaluateMutationGate(req, {
|
|
1508
|
+
cookieName: deps.bootToken.cookieName,
|
|
1509
|
+
bootToken: deps.bootToken.value,
|
|
1510
|
+
confirmationToken: deps.bootToken.confirmationToken,
|
|
1511
|
+
consoleOrigin: deps.getConsoleOrigin(),
|
|
1512
|
+
allowNonLoopbackAccess: deps.allowNonLoopbackAccess,
|
|
1513
|
+
});
|
|
1514
|
+
if (failure) {
|
|
1515
|
+
sendJson(res, failure.status, {
|
|
1516
|
+
ok: false,
|
|
1517
|
+
error: { code: failure.code, message: failure.message },
|
|
1518
|
+
});
|
|
1519
|
+
return;
|
|
1520
|
+
}
|
|
1521
|
+
let body;
|
|
1522
|
+
try {
|
|
1523
|
+
body = (await readJsonBody(req));
|
|
1524
|
+
}
|
|
1525
|
+
catch (error) {
|
|
1526
|
+
sendJson(res, 400, {
|
|
1527
|
+
ok: false,
|
|
1528
|
+
error: {
|
|
1529
|
+
code: "INVALID_INPUT",
|
|
1530
|
+
message: error instanceof Error ? error.message : String(error),
|
|
1531
|
+
},
|
|
1532
|
+
});
|
|
1533
|
+
return;
|
|
1534
|
+
}
|
|
1535
|
+
const directoryPath = typeof body.directoryPath === "string"
|
|
1536
|
+
? body.directoryPath
|
|
1537
|
+
: typeof body.path === "string"
|
|
1538
|
+
? body.path
|
|
1539
|
+
: "";
|
|
1540
|
+
if (!directoryPath.trim()) {
|
|
1541
|
+
sendJson(res, 400, {
|
|
1542
|
+
ok: false,
|
|
1543
|
+
error: {
|
|
1544
|
+
code: "INVALID_INPUT",
|
|
1545
|
+
message: "directoryPath (string) is required",
|
|
1546
|
+
},
|
|
1547
|
+
});
|
|
1548
|
+
return;
|
|
1549
|
+
}
|
|
1550
|
+
if (body.name !== undefined &&
|
|
1551
|
+
(typeof body.name !== "string" || !body.name.trim())) {
|
|
1552
|
+
sendJson(res, 400, {
|
|
1553
|
+
ok: false,
|
|
1554
|
+
error: {
|
|
1555
|
+
code: "INVALID_INPUT",
|
|
1556
|
+
message: "name must be a non-empty string when provided",
|
|
1557
|
+
},
|
|
1558
|
+
});
|
|
1559
|
+
return;
|
|
1560
|
+
}
|
|
1561
|
+
const name = typeof body.name === "string" ? body.name : undefined;
|
|
1562
|
+
const result = await registry.add(directoryPath, name ? { name } : {});
|
|
1563
|
+
if (!result.ok) {
|
|
1564
|
+
const status = result.code === "DUPLICATE"
|
|
1565
|
+
? 409
|
|
1566
|
+
: result.code === "INVALID_PATH"
|
|
1567
|
+
? 400
|
|
1568
|
+
: 400;
|
|
1569
|
+
sendJson(res, status, {
|
|
1570
|
+
ok: false,
|
|
1571
|
+
error: {
|
|
1572
|
+
code: result.code,
|
|
1573
|
+
message: result.message,
|
|
1574
|
+
},
|
|
1575
|
+
});
|
|
1576
|
+
return;
|
|
1577
|
+
}
|
|
1578
|
+
const record = result.record;
|
|
1579
|
+
sendJson(res, 201, {
|
|
1580
|
+
ok: true,
|
|
1581
|
+
workspace: {
|
|
1582
|
+
workspaceId: record.workspaceId,
|
|
1583
|
+
name: record.name,
|
|
1584
|
+
displayPath: record.displayPath,
|
|
1585
|
+
repoFingerprint: record.repoFingerprint,
|
|
1586
|
+
createdAt: record.createdAt,
|
|
1587
|
+
lastAccessedAt: record.lastAccessedAt,
|
|
1588
|
+
readiness: {
|
|
1589
|
+
state: "setup-required",
|
|
1590
|
+
summary: `pi=unknown; inspect=${readinessDeps.inspectReady ? "ready" : "unavailable"}`,
|
|
1591
|
+
},
|
|
1592
|
+
},
|
|
1593
|
+
});
|
|
1594
|
+
return;
|
|
1595
|
+
}
|
|
1596
|
+
const workspaceMatch = pathname.match(/^\/api\/operator\/v1\/workspaces\/([^/]+)$/);
|
|
1597
|
+
if (method === "PATCH" && workspaceMatch) {
|
|
1598
|
+
const failure = evaluateMutationGate(req, {
|
|
1599
|
+
cookieName: deps.bootToken.cookieName,
|
|
1600
|
+
bootToken: deps.bootToken.value,
|
|
1601
|
+
confirmationToken: deps.bootToken.confirmationToken,
|
|
1602
|
+
consoleOrigin: deps.getConsoleOrigin(),
|
|
1603
|
+
allowNonLoopbackAccess: deps.allowNonLoopbackAccess,
|
|
1604
|
+
});
|
|
1605
|
+
if (failure) {
|
|
1606
|
+
sendJson(res, failure.status, {
|
|
1607
|
+
ok: false,
|
|
1608
|
+
error: { code: failure.code, message: failure.message },
|
|
1609
|
+
});
|
|
1610
|
+
return;
|
|
1611
|
+
}
|
|
1612
|
+
let body;
|
|
1613
|
+
try {
|
|
1614
|
+
body = (await readJsonBody(req));
|
|
1615
|
+
}
|
|
1616
|
+
catch (error) {
|
|
1617
|
+
sendJson(res, 400, {
|
|
1618
|
+
ok: false,
|
|
1619
|
+
error: {
|
|
1620
|
+
code: "INVALID_INPUT",
|
|
1621
|
+
message: error instanceof Error ? error.message : String(error),
|
|
1622
|
+
},
|
|
1623
|
+
});
|
|
1624
|
+
return;
|
|
1625
|
+
}
|
|
1626
|
+
if (body.beforeWorkspaceId !== null &&
|
|
1627
|
+
typeof body.beforeWorkspaceId !== "string") {
|
|
1628
|
+
sendJson(res, 400, {
|
|
1629
|
+
ok: false,
|
|
1630
|
+
error: {
|
|
1631
|
+
code: "INVALID_INPUT",
|
|
1632
|
+
message: "beforeWorkspaceId must be a workspace id or null",
|
|
1633
|
+
},
|
|
1634
|
+
});
|
|
1635
|
+
return;
|
|
1636
|
+
}
|
|
1637
|
+
const workspaceId = decodeURIComponent(workspaceMatch[1]);
|
|
1638
|
+
const beforeWorkspaceId = typeof body.beforeWorkspaceId === "string"
|
|
1639
|
+
? body.beforeWorkspaceId
|
|
1640
|
+
: null;
|
|
1641
|
+
const reordered = await registry.insertBefore(workspaceId, beforeWorkspaceId);
|
|
1642
|
+
if (!reordered.ok) {
|
|
1643
|
+
sendJson(res, 404, {
|
|
1644
|
+
ok: false,
|
|
1645
|
+
error: {
|
|
1646
|
+
code: reordered.code,
|
|
1647
|
+
message: reordered.code === "ANCHOR_NOT_FOUND"
|
|
1648
|
+
? `unknown workspace anchor: ${beforeWorkspaceId}`
|
|
1649
|
+
: `unknown workspace: ${workspaceId}`,
|
|
1650
|
+
},
|
|
1651
|
+
});
|
|
1652
|
+
return;
|
|
1653
|
+
}
|
|
1654
|
+
sendJson(res, 200, {
|
|
1655
|
+
ok: true,
|
|
1656
|
+
workspaceId,
|
|
1657
|
+
beforeWorkspaceId,
|
|
1658
|
+
changed: reordered.changed,
|
|
1659
|
+
});
|
|
1660
|
+
return;
|
|
1661
|
+
}
|
|
1662
|
+
if (method === "DELETE" && workspaceMatch) {
|
|
1663
|
+
const failure = evaluateMutationGate(req, {
|
|
1664
|
+
cookieName: deps.bootToken.cookieName,
|
|
1665
|
+
bootToken: deps.bootToken.value,
|
|
1666
|
+
confirmationToken: deps.bootToken.confirmationToken,
|
|
1667
|
+
consoleOrigin: deps.getConsoleOrigin(),
|
|
1668
|
+
allowNonLoopbackAccess: deps.allowNonLoopbackAccess,
|
|
1669
|
+
});
|
|
1670
|
+
if (failure) {
|
|
1671
|
+
sendJson(res, failure.status, {
|
|
1672
|
+
ok: false,
|
|
1673
|
+
error: { code: failure.code, message: failure.message },
|
|
1674
|
+
});
|
|
1675
|
+
return;
|
|
1676
|
+
}
|
|
1677
|
+
const workspaceId = decodeURIComponent(workspaceMatch[1]);
|
|
1678
|
+
const removed = await registry.remove(workspaceId);
|
|
1679
|
+
if (!removed) {
|
|
1680
|
+
sendJson(res, 404, {
|
|
1681
|
+
ok: false,
|
|
1682
|
+
error: {
|
|
1683
|
+
code: "WORKSPACE_NOT_FOUND",
|
|
1684
|
+
message: `unknown workspace: ${workspaceId}`,
|
|
1685
|
+
},
|
|
1686
|
+
});
|
|
1687
|
+
return;
|
|
1688
|
+
}
|
|
1689
|
+
sendJson(res, 200, { ok: true, workspaceId, removed: true });
|
|
1690
|
+
return;
|
|
1691
|
+
}
|
|
1692
|
+
sendJson(res, 404, {
|
|
1693
|
+
ok: false,
|
|
1694
|
+
error: { code: "NOT_FOUND", message: `unknown workspace route: ${pathname}` },
|
|
1695
|
+
});
|
|
1696
|
+
}
|