@tea-agent/loop-agent 0.1.0-fe-test.2 → 0.1.0-fe-test.4
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 +4321 -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 +1443 -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 +2 -1
- 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 +53 -5
- package/dist/workflows/dag/frontend-test-case-manifest.js +11 -4
- 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-rerun-candidates.js +103 -0
- package/dist/workflows/dag/frontend-test-result-contract.js +188 -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 +1675 -721
- 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 +585 -31
- package/dist/workflows/dag/validate.js +93 -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 +8 -10
- 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,31 +1,26 @@
|
|
|
1
1
|
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
2
3
|
import { existsSync } from "node:fs";
|
|
3
4
|
import { createServer } from "node:http";
|
|
4
5
|
import path from "node:path";
|
|
5
6
|
import { fileURLToPath } from "node:url";
|
|
6
|
-
import {
|
|
7
|
+
import { readPackageVersion } from "../../shared/package-metadata.js";
|
|
7
8
|
import { DAG_ABSOLUTE_MAX_WALL_CLOCK_MS } from "../../shared/timeout-policy.js";
|
|
8
|
-
import { openConsoleAppData } from "
|
|
9
|
-
import { DagConfirmationStore } from "./dag-confirmation.js";
|
|
10
|
-
import { DagExecutionReceiptStore } from "./dag-execution-receipt.js";
|
|
11
|
-
import { DraftStore } from "./draft-store.js";
|
|
12
|
-
import { AssessmentStore } from "./interview/assessment.js";
|
|
13
|
-
import { InterviewSessionStore } from "./interview/session.js";
|
|
9
|
+
import { openConsoleAppData } from "../../infrastructure/console/app-data.js";
|
|
14
10
|
import { isLoopbackHost } from "./loopback.js";
|
|
15
11
|
import { ChatSessionStore } from "./chat/session-store.js";
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import { handleConsoleHealthRequest, handleConsoleOperatorRequest, sendJson, serveConsoleStatic, } from "./routes.js";
|
|
24
|
-
import { issueBootCapabilityToken } from "./security.js";
|
|
25
|
-
import { resolveSiblingLoopAgentBin } from "./sibling-controller.js";
|
|
26
|
-
import { NightAuxTicker } from "./night-aux-ticker.js";
|
|
12
|
+
import { ChatSessionCatalog } from "./chat/session-catalog.js";
|
|
13
|
+
import { matchRepoHtmlPreviewRoute } from "./chat/repo-browser.js";
|
|
14
|
+
import { handleConsoleHealthRequest, handleWorkspaceRoutes, sendJson, serveConsoleStatic, } from "./routes.js";
|
|
15
|
+
import { issueBootCapabilityToken, injectConfirmationTokenScript, } from "./security.js";
|
|
16
|
+
import { resolvePackageRootFromConsole } from "./sibling-controller.js";
|
|
17
|
+
import { isDagRerunPromptOverrideEnabled } from "../../shared/dag-prompt-override.js";
|
|
18
|
+
import { defaultObserveStaticDir, handleMatchedObserveRoute, matchObserveGetRoute, ROUTES, serveObserveStatic, } from "../observe/routes.js";
|
|
27
19
|
import { deriveObserveRouteCapabilities } from "../observe/health.js";
|
|
28
|
-
import {
|
|
20
|
+
import { WorkspaceRegistry, } from "./workspace-registry.js";
|
|
21
|
+
import { createWorkspaceContext, } from "./workspace-context.js";
|
|
22
|
+
import { createConsoleUpdateExecutor } from "./console-update-runtime.js";
|
|
23
|
+
import { createConsoleHandoff } from "./console-handoff.js";
|
|
29
24
|
/**
|
|
30
25
|
* Default hard timeout for the Console-owned LoopAgentClient.
|
|
31
26
|
*
|
|
@@ -66,138 +61,195 @@ export async function createConsoleServer(options) {
|
|
|
66
61
|
process.stderr.write(`console: binding non-loopback host ${host} (Operator mutations enabled; no network auth — expose only on trusted networks)\n`);
|
|
67
62
|
}
|
|
68
63
|
const repoRoot = path.resolve(options.repoRoot);
|
|
69
|
-
const
|
|
64
|
+
const configuredPort = options.port ?? 8790;
|
|
70
65
|
const debug = options.debug === true;
|
|
71
66
|
const keepAliveTimeoutMs = options.keepAliveTimeoutMs ?? 65_000;
|
|
72
67
|
const staticDir = options.staticDir ?? defaultConsoleStaticDir();
|
|
73
68
|
const inspectStaticDir = options.inspectStaticDir ?? defaultObserveStaticDir();
|
|
74
|
-
const observeRouteContext = createObserveRouteContext(repoRoot, {
|
|
75
|
-
staticDir: inspectStaticDir,
|
|
76
|
-
});
|
|
77
|
-
const bootToken = issueBootCapabilityToken();
|
|
78
69
|
const operatorSessionId = `sess_${randomBytes(16).toString("hex")}`;
|
|
79
|
-
const
|
|
70
|
+
const consoleInstanceId = options.consoleInstanceId ?? `console_${randomBytes(16).toString("hex")}`;
|
|
71
|
+
// User-level registry root shares the user app-data root directory layout
|
|
72
|
+
// (workspaces.json lives at <root>/workspaces.json, per-workspace records
|
|
73
|
+
// carry fingerprint-isolated namespaces under <root>/repos/<fingerprint>/).
|
|
74
|
+
const bootstrapAppData = openConsoleAppData({
|
|
80
75
|
repoRoot,
|
|
81
76
|
appDataRoot: options.appDataRoot,
|
|
82
77
|
});
|
|
83
|
-
const
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
78
|
+
const registry = new WorkspaceRegistry(bootstrapAppData);
|
|
79
|
+
const startupRecord = await registry.ensureStartupWorkspace(repoRoot);
|
|
80
|
+
const chatSessionCatalog = new ChatSessionCatalog();
|
|
81
|
+
// DSH-style dual baseline: Workspace records own grouping/order, while the
|
|
82
|
+
// Session catalog is rebuilt once at Host startup from durable Session
|
|
83
|
+
// persistence. Requests never rediscover every Workspace store.
|
|
84
|
+
for (const record of await registry.listAll()) {
|
|
85
|
+
try {
|
|
86
|
+
const store = new ChatSessionStore(openConsoleAppData({
|
|
87
|
+
repoRoot: record.repoRoot,
|
|
88
|
+
...(options.appDataRoot
|
|
89
|
+
? { appDataRoot: options.appDataRoot }
|
|
90
|
+
: {}),
|
|
91
|
+
}));
|
|
92
|
+
const sessions = await store.list({ includeArchived: true });
|
|
93
|
+
for (const session of sessions) {
|
|
94
|
+
if (session.repoFingerprint !== record.repoFingerprint)
|
|
95
|
+
continue;
|
|
96
|
+
chatSessionCatalog.upsert(session, record.workspaceId);
|
|
97
|
+
}
|
|
98
|
+
if (!record.hidden) {
|
|
99
|
+
await registry.reconcileSessions(record.workspaceId, sessions
|
|
100
|
+
.filter((session) => session.repoFingerprint === record.repoFingerprint)
|
|
101
|
+
.map((session) => session.sessionId));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
// A removed or externally unavailable Workspace is not an empty Session
|
|
106
|
+
// baseline. Its prior durable membership remains untouched.
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const instanceNonce = configuredPort === 0 ? randomBytes(16).toString("hex") : undefined;
|
|
110
|
+
const bootToken = issueBootCapabilityToken({
|
|
111
|
+
repoFingerprint: startupRecord.repoFingerprint,
|
|
112
|
+
bindHost: host,
|
|
113
|
+
configuredPort,
|
|
114
|
+
...(instanceNonce ? { instanceNonce } : {}),
|
|
95
115
|
});
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
116
|
+
// Scoped credentials for the experimental /inspect prompt-override rerun:
|
|
117
|
+
// separate cookie name + confirmation token so the read-only inspect page
|
|
118
|
+
// can never replay them against the general Console mutation surface.
|
|
119
|
+
const inspectBootToken = issueBootCapabilityToken({
|
|
120
|
+
repoFingerprint: startupRecord.repoFingerprint,
|
|
121
|
+
bindHost: host,
|
|
122
|
+
configuredPort,
|
|
123
|
+
...(instanceNonce ? { instanceNonce } : {}),
|
|
124
|
+
}, { variant: "inspect" });
|
|
125
|
+
let boundHost = host;
|
|
126
|
+
let boundPort = configuredPort;
|
|
127
|
+
const getConsoleOrigin = () => `http://${boundHost}:${boundPort}`;
|
|
128
|
+
// ---- Per-workspace lazily-created contexts -------------------------------
|
|
129
|
+
const workspaceContexts = new Map();
|
|
130
|
+
let sharedConsoleUpdateExecutor = options.consoleUpdateExecutor;
|
|
131
|
+
const materializeContext = async (record) => {
|
|
132
|
+
const existing = workspaceContexts.get(record.workspaceId);
|
|
133
|
+
if (existing)
|
|
134
|
+
return existing;
|
|
135
|
+
const context = await createWorkspaceContext(record, {
|
|
136
|
+
appDataRoot: options.appDataRoot,
|
|
137
|
+
staticDir,
|
|
138
|
+
inspectStaticDir,
|
|
139
|
+
bootToken,
|
|
140
|
+
operatorSessionId,
|
|
141
|
+
getConsoleOrigin,
|
|
142
|
+
allowNonLoopbackAccess: !loopbackBind,
|
|
143
|
+
observeBaseUrl: options.observeBaseUrl,
|
|
144
|
+
fetchImpl: options.fetchImpl,
|
|
145
|
+
piReadinessProbe: options.piReadinessProbe,
|
|
146
|
+
createClient: options.createClient,
|
|
147
|
+
defaultTimeoutMs: options.defaultTimeoutMs,
|
|
148
|
+
skipReconcile: options.skipReconcile,
|
|
149
|
+
chatSessionCatalog,
|
|
106
150
|
});
|
|
107
|
-
|
|
108
|
-
|
|
151
|
+
if (sharedConsoleUpdateExecutor) {
|
|
152
|
+
context.actionContext.consoleUpdateExecutor = sharedConsoleUpdateExecutor;
|
|
153
|
+
}
|
|
154
|
+
workspaceContexts.set(record.workspaceId, context);
|
|
155
|
+
void context.recoverDeferredTurns().catch(() => undefined);
|
|
156
|
+
return context;
|
|
157
|
+
};
|
|
158
|
+
const resolveContext = async (workspaceId) => {
|
|
159
|
+
const id = workspaceId?.trim();
|
|
160
|
+
if (!id) {
|
|
161
|
+
return {
|
|
162
|
+
ok: false,
|
|
163
|
+
status: 400,
|
|
164
|
+
code: "WORKSPACE_REQUIRED",
|
|
165
|
+
message: "workspaceId is required",
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
const record = await registry.getVisible(id);
|
|
169
|
+
if (!record) {
|
|
170
|
+
return {
|
|
171
|
+
ok: false,
|
|
172
|
+
status: 404,
|
|
173
|
+
code: "WORKSPACE_NOT_FOUND",
|
|
174
|
+
message: `unknown workspace: ${id}`,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
const context = await materializeContext(record);
|
|
178
|
+
return { ok: true, context };
|
|
179
|
+
};
|
|
180
|
+
const startupResolution = await resolveContext(startupRecord.workspaceId);
|
|
181
|
+
if (!startupResolution.ok) {
|
|
182
|
+
throw new Error(`console serve: failed to create startup workspace context: ${startupResolution.message}`);
|
|
109
183
|
}
|
|
110
|
-
const
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
184
|
+
const startup = startupResolution.context;
|
|
185
|
+
const requestConsoleHandoff = async (targetVersion) => {
|
|
186
|
+
const packageRoot = resolvePackageRootFromConsole();
|
|
187
|
+
const agentWorkerBin = path.join(packageRoot, "bin", "agent-worker.js");
|
|
188
|
+
if (readPackageVersion(packageRoot) !== targetVersion ||
|
|
189
|
+
!existsSync(agentWorkerBin)) {
|
|
190
|
+
return {
|
|
191
|
+
ok: false,
|
|
192
|
+
message: "verified global package no longer contains the target Console worker",
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
const { handoff, env } = createConsoleHandoff({
|
|
196
|
+
oldPid: process.pid,
|
|
114
197
|
repoRoot,
|
|
198
|
+
host: boundHost,
|
|
199
|
+
port: boundPort,
|
|
200
|
+
...(options.appDataRoot ? { appDataRoot: options.appDataRoot } : {}),
|
|
201
|
+
targetVersion,
|
|
115
202
|
});
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const chatStore = new ChatSessionStore(appData);
|
|
146
|
-
// M5.1: every Console boot owns a fresh event-log generation. A browser
|
|
147
|
-
// reconnecting with an old SSE cursor must reconcile from snapshot rather
|
|
148
|
-
// than silently consume a different process' event namespace.
|
|
149
|
-
const chatEventEpoch = randomBytes(12).toString("hex");
|
|
150
|
-
const chatEvents = createChatEventStore({ appData, epoch: chatEventEpoch });
|
|
151
|
-
const chatTurnExecutions = createChatTurnExecutionRegistry();
|
|
152
|
-
const chatOperationLinker = createChatOperationLinker({
|
|
153
|
-
chatEvents,
|
|
154
|
-
operations,
|
|
155
|
-
operationEvents: events,
|
|
156
|
-
});
|
|
157
|
-
const chatRuntime = new ConsolePiRuntime({
|
|
158
|
-
cwd: repoRoot,
|
|
159
|
-
sessionDir: appData.chatSessions,
|
|
160
|
-
resourcePreferencesPath: appData.resourcePreferences,
|
|
161
|
-
actionContext,
|
|
162
|
-
});
|
|
163
|
-
// chatRouteDeps is a plain object literal — it cannot throw. The previous
|
|
164
|
-
// try/catch was dead code that created a false "handled failure" impression.
|
|
165
|
-
// If a future field can throw, scope it explicitly instead of wrapping the
|
|
166
|
-
// literal.
|
|
167
|
-
const chatRouteDeps = {
|
|
168
|
-
runtime: chatRuntime,
|
|
169
|
-
store: chatStore,
|
|
170
|
-
events: chatEvents,
|
|
171
|
-
turnExecutions: chatTurnExecutions,
|
|
172
|
-
operationLinker: chatOperationLinker,
|
|
173
|
-
appData,
|
|
174
|
-
bootToken,
|
|
175
|
-
getConsoleOrigin,
|
|
176
|
-
allowNonLoopbackAccess: !loopbackBind,
|
|
203
|
+
try {
|
|
204
|
+
const child = spawn(process.execPath, [
|
|
205
|
+
agentWorkerBin,
|
|
206
|
+
"console",
|
|
207
|
+
"--repo",
|
|
208
|
+
repoRoot,
|
|
209
|
+
"--host",
|
|
210
|
+
boundHost,
|
|
211
|
+
"--port",
|
|
212
|
+
String(boundPort),
|
|
213
|
+
...(options.appDataRoot
|
|
214
|
+
? ["--app-data", options.appDataRoot]
|
|
215
|
+
: []),
|
|
216
|
+
"--no-open",
|
|
217
|
+
], { detached: true, stdio: "ignore", env: { ...process.env, ...env } });
|
|
218
|
+
await new Promise((resolve, reject) => {
|
|
219
|
+
child.once("spawn", resolve);
|
|
220
|
+
child.once("error", reject);
|
|
221
|
+
});
|
|
222
|
+
child.unref();
|
|
223
|
+
setTimeout(() => process.kill(process.pid, "SIGTERM"), 100).unref();
|
|
224
|
+
return { ok: true, consoleInstanceId: handoff.consoleInstanceId };
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
return {
|
|
228
|
+
ok: false,
|
|
229
|
+
message: error instanceof Error ? error.message : String(error),
|
|
230
|
+
};
|
|
231
|
+
}
|
|
177
232
|
};
|
|
178
|
-
|
|
233
|
+
sharedConsoleUpdateExecutor ??= createConsoleUpdateExecutor({
|
|
179
234
|
repoRoot,
|
|
180
|
-
|
|
235
|
+
packageRoot: resolvePackageRootFromConsole(),
|
|
236
|
+
client: startup.client,
|
|
237
|
+
operations: startup.operations,
|
|
238
|
+
activeChatTurnCount: () => [...workspaceContexts.values()].reduce((total, context) => total + (context.chatRouteDeps.turnExecutions?.size() ?? 0), 0),
|
|
239
|
+
requestHandoff: requestConsoleHandoff,
|
|
181
240
|
});
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
operations,
|
|
195
|
-
events,
|
|
196
|
-
getReadiness,
|
|
197
|
-
chat: chatRouteDeps,
|
|
198
|
-
nightAuxTicker,
|
|
199
|
-
},
|
|
200
|
-
};
|
|
241
|
+
for (const context of workspaceContexts.values()) {
|
|
242
|
+
context.actionContext.consoleUpdateExecutor = sharedConsoleUpdateExecutor;
|
|
243
|
+
}
|
|
244
|
+
// Legacy surface readiness: the boot readiness report of the startup
|
|
245
|
+
// workspace. Kept as a process-level report for /api/health projections.
|
|
246
|
+
const bootReadiness = startup.getReadiness();
|
|
247
|
+
// Durable follow-up recovery is per-context and runs at context creation
|
|
248
|
+
// (see resolveContext); the startup context is created eagerly below, so its
|
|
249
|
+
// recovery has already been scheduled.
|
|
250
|
+
// Readiness is shared per-context; the legacy getReadiness() helper keeps
|
|
251
|
+
// pointing at the startup context report.
|
|
252
|
+
const getReadiness = () => bootReadiness;
|
|
201
253
|
return new Promise((resolve, reject) => {
|
|
202
254
|
const server = createServer((req, res) => {
|
|
203
255
|
const startedAt = Date.now();
|
|
@@ -245,35 +297,92 @@ export async function createConsoleServer(options) {
|
|
|
245
297
|
}
|
|
246
298
|
});
|
|
247
299
|
async function dispatch(req, res) {
|
|
248
|
-
// Refresh readiness pointer on each request surface
|
|
249
|
-
actionContext.readiness = getReadiness();
|
|
250
300
|
const method = (req.method ?? "GET").toUpperCase();
|
|
251
|
-
const
|
|
301
|
+
const url = new URL(req.url ?? "/", "http://localhost");
|
|
302
|
+
const pathname = decodeURIComponent(url.pathname);
|
|
252
303
|
if (method === "GET" && pathname === "/api/health") {
|
|
253
|
-
await handleConsoleHealthRequest(req, res,
|
|
304
|
+
await handleConsoleHealthRequest(req, res, {
|
|
305
|
+
repoRoot,
|
|
306
|
+
staticDir,
|
|
307
|
+
bootToken,
|
|
308
|
+
getConsoleOrigin,
|
|
309
|
+
allowNonLoopbackAccess: !loopbackBind,
|
|
310
|
+
inspect: {
|
|
311
|
+
ready: existsSync(path.join(inspectStaticDir, "index.html")),
|
|
312
|
+
routeCapabilities: deriveObserveRouteCapabilities(ROUTES),
|
|
313
|
+
},
|
|
314
|
+
consoleInstanceId,
|
|
315
|
+
registry,
|
|
316
|
+
getStartupReadiness: getReadiness,
|
|
317
|
+
});
|
|
254
318
|
return;
|
|
255
319
|
}
|
|
256
320
|
if (pathname.startsWith("/api/operator/v1/") ||
|
|
257
321
|
pathname.startsWith("/api/session/")) {
|
|
258
|
-
//
|
|
322
|
+
// Workspace Registry routes are process-level (no workspaceId).
|
|
323
|
+
if (pathname === "/api/operator/v1/workspaces" ||
|
|
324
|
+
pathname.startsWith("/api/operator/v1/workspaces/")) {
|
|
325
|
+
await handleWorkspaceRoutes(req, res, registry, {
|
|
326
|
+
bootToken,
|
|
327
|
+
getConsoleOrigin,
|
|
328
|
+
allowNonLoopbackAccess: !loopbackBind,
|
|
329
|
+
...(options.piReadinessProbe
|
|
330
|
+
? { piReadinessProbe: options.piReadinessProbe }
|
|
331
|
+
: {}),
|
|
332
|
+
...(options.pickDirectory
|
|
333
|
+
? { pickDirectory: options.pickDirectory }
|
|
334
|
+
: {}),
|
|
335
|
+
}, url, pathname, method, {
|
|
336
|
+
inspectReady: existsSync(path.join(inspectStaticDir, "index.html")),
|
|
337
|
+
});
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
259
340
|
if (pathname.startsWith("/api/operator/v1/chat/") ||
|
|
260
341
|
pathname.startsWith("/api/operator/v1/pi/")) {
|
|
261
|
-
await
|
|
342
|
+
await handleChatDispatch(req, res, pathname, url, method);
|
|
262
343
|
return;
|
|
263
344
|
}
|
|
264
|
-
await
|
|
345
|
+
await handleOperatorDispatch(req, res, pathname, url, method);
|
|
265
346
|
return;
|
|
266
347
|
}
|
|
267
348
|
if (method === "GET" && pathname.startsWith("/api/")) {
|
|
268
349
|
const match = matchObserveGetRoute(pathname);
|
|
269
350
|
if (match) {
|
|
270
|
-
|
|
351
|
+
const requestedWorkspaceId = url.searchParams.get("workspaceId")?.trim() || undefined;
|
|
352
|
+
// Every Observe GET is workspace data. Missing, blank, and unknown
|
|
353
|
+
// workspace ids fail closed; only /api/health remains process-level.
|
|
354
|
+
const resolution = await resolveContext(requestedWorkspaceId);
|
|
355
|
+
if (!resolution.ok) {
|
|
356
|
+
sendJson(res, resolution.status, {
|
|
357
|
+
ok: false,
|
|
358
|
+
error: {
|
|
359
|
+
code: resolution.code,
|
|
360
|
+
message: resolution.message,
|
|
361
|
+
},
|
|
362
|
+
});
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
// Refresh readiness pointer per request surface.
|
|
366
|
+
resolution.context.actionContext.readiness =
|
|
367
|
+
resolution.context.getReadiness();
|
|
368
|
+
await handleMatchedObserveRoute(req, res, match, resolution.context.observeRouteContext);
|
|
271
369
|
return;
|
|
272
370
|
}
|
|
273
371
|
}
|
|
274
372
|
if (pathname.startsWith("/inspect")) {
|
|
373
|
+
// Prompt-override rerun is enabled by default. Unless the emergency
|
|
374
|
+
// kill switch disables it, hand the inspect page SCOPED mutation
|
|
375
|
+
// credentials (separate cookie + token, only strong enough for
|
|
376
|
+
// INSPECT_MUTATION_ALLOWED_ACTIONS — see routes.ts).
|
|
377
|
+
const htmlEnhancer = isDagRerunPromptOverrideEnabled()
|
|
378
|
+
? (html) => ({
|
|
379
|
+
content: injectConfirmationTokenScript(html, inspectBootToken.confirmationToken, "__INSPECT_MUTATION_TOKEN__"),
|
|
380
|
+
setCookie: inspectBootToken.setCookieHeader,
|
|
381
|
+
})
|
|
382
|
+
: undefined;
|
|
275
383
|
await serveObserveStatic(req, res, inspectStaticDir, {
|
|
276
384
|
urlPrefix: "/inspect",
|
|
385
|
+
...(htmlEnhancer ? { htmlEnhancer } : {}),
|
|
277
386
|
});
|
|
278
387
|
return;
|
|
279
388
|
}
|
|
@@ -281,10 +390,395 @@ export async function createConsoleServer(options) {
|
|
|
281
390
|
sendJson(res, 404, { error: "Not found" });
|
|
282
391
|
return;
|
|
283
392
|
}
|
|
284
|
-
|
|
393
|
+
if (options.serveStatic) {
|
|
394
|
+
await options.serveStatic(req, res, {
|
|
395
|
+
confirmationToken: bootToken.confirmationToken,
|
|
396
|
+
setCookieHeader: bootToken.setCookieHeader,
|
|
397
|
+
consoleOrigin: getConsoleOrigin(),
|
|
398
|
+
});
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
await serveConsoleStatic(req, res, {
|
|
402
|
+
repoRoot,
|
|
403
|
+
staticDir,
|
|
404
|
+
bootToken,
|
|
405
|
+
inspectBootToken,
|
|
406
|
+
getConsoleOrigin,
|
|
407
|
+
allowNonLoopbackAccess: !loopbackBind,
|
|
408
|
+
inspect: {
|
|
409
|
+
ready: existsSync(path.join(inspectStaticDir, "index.html")),
|
|
410
|
+
routeCapabilities: deriveObserveRouteCapabilities(ROUTES),
|
|
411
|
+
},
|
|
412
|
+
consoleInstanceId,
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
async function handleChatDispatch(req, res, pathname, url, method,
|
|
416
|
+
/** Explicit owning workspaceId for POST /chat/sessions create
|
|
417
|
+
* (AC-R7-002); undefined for every other chat route. */
|
|
418
|
+
workspaceScope) {
|
|
419
|
+
// POST /api/operator/v1/chat/sessions — creation carries workspaceId in
|
|
420
|
+
// the JSON body; all other chat routes resolve via Session ownership
|
|
421
|
+
// (durable) with optional query workspaceId conflict check.
|
|
422
|
+
const { handleChatRequest: dispatchChat } = await import("./chat/routes.js");
|
|
423
|
+
const htmlPreviewRoute = matchRepoHtmlPreviewRoute(pathname);
|
|
424
|
+
if (method === "GET" &&
|
|
425
|
+
pathname === "/api/operator/v1/chat/sessions" &&
|
|
426
|
+
!url.searchParams.has("workspaceId")) {
|
|
427
|
+
const sessions = chatSessionCatalog.list().map((entry) => {
|
|
428
|
+
const active = entry.workspaceId
|
|
429
|
+
? workspaceContexts
|
|
430
|
+
.get(entry.workspaceId)
|
|
431
|
+
?.chatRouteDeps.events.getActiveTurn(entry.sessionId)
|
|
432
|
+
: undefined;
|
|
433
|
+
return {
|
|
434
|
+
sessionId: entry.sessionId,
|
|
435
|
+
...(entry.workspaceId ? { workspaceId: entry.workspaceId } : {}),
|
|
436
|
+
state: entry.state,
|
|
437
|
+
createdAt: entry.createdAt,
|
|
438
|
+
updatedAt: entry.updatedAt,
|
|
439
|
+
...(entry.title !== undefined ? { title: entry.title } : {}),
|
|
440
|
+
...(entry.displayTitle !== undefined
|
|
441
|
+
? { displayTitle: entry.displayTitle }
|
|
442
|
+
: {}),
|
|
443
|
+
...(entry.modelProvider !== undefined
|
|
444
|
+
? { modelProvider: entry.modelProvider }
|
|
445
|
+
: {}),
|
|
446
|
+
...(entry.modelId !== undefined ? { modelId: entry.modelId } : {}),
|
|
447
|
+
...(entry.thinkingLevel !== undefined
|
|
448
|
+
? { thinkingLevel: entry.thinkingLevel }
|
|
449
|
+
: {}),
|
|
450
|
+
activeTurnId: active?.turnId,
|
|
451
|
+
turnPhase: active?.abortRequestedAt
|
|
452
|
+
? "stopping"
|
|
453
|
+
: active
|
|
454
|
+
? "running"
|
|
455
|
+
: "idle",
|
|
456
|
+
deferredTurn: entry.deferredTurn,
|
|
457
|
+
deferredTurns: entry.deferredTurns,
|
|
458
|
+
isBlank: entry.isBlank && !active,
|
|
459
|
+
};
|
|
460
|
+
});
|
|
461
|
+
sendJson(res, 200, {
|
|
462
|
+
ok: true,
|
|
463
|
+
schemaVersion: 2,
|
|
464
|
+
sessions,
|
|
465
|
+
hasBash: true,
|
|
466
|
+
workspaceErrors: [],
|
|
467
|
+
});
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
if (method === "POST" && pathname === "/api/operator/v1/chat/sessions") {
|
|
471
|
+
// AC-R5-006: the mutation gate fires BEFORE body pre-read/workspace
|
|
472
|
+
// resolution — an unauthenticated mutation gets exactly 403, never a
|
|
473
|
+
// masked 400 (WORKSPACE_REQUIRED/INVALID_INPUT) that would hide the
|
|
474
|
+
// gate-order regression.
|
|
475
|
+
{
|
|
476
|
+
const { evaluateMutationGate } = await import("./security.js");
|
|
477
|
+
const failure = evaluateMutationGate(req, {
|
|
478
|
+
cookieName: bootToken.cookieName,
|
|
479
|
+
bootToken: bootToken.value,
|
|
480
|
+
confirmationToken: bootToken.confirmationToken,
|
|
481
|
+
consoleOrigin: getConsoleOrigin(),
|
|
482
|
+
allowNonLoopbackAccess: !loopbackBind,
|
|
483
|
+
});
|
|
484
|
+
if (failure) {
|
|
485
|
+
sendJson(res, failure.status, {
|
|
486
|
+
ok: false,
|
|
487
|
+
error: {
|
|
488
|
+
code: failure.code,
|
|
489
|
+
message: failure.message,
|
|
490
|
+
},
|
|
491
|
+
});
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
const resolution = await resolveContextFromSessionCreateBody(req, res, resolveContext);
|
|
496
|
+
if (!resolution)
|
|
497
|
+
return; // response already sent
|
|
498
|
+
// AC-R7-002: workspaceId travels as an EXPLICIT parameter through
|
|
499
|
+
// dispatchChat → handleCreateChatSession → store.create. No runtime
|
|
500
|
+
// store.create replacement exists anymore.
|
|
501
|
+
await dispatchChat(req, res, resolution.context.chatRouteDeps, pathname, resolution.context.workspaceId);
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
const sessionMatch = pathname.match(/^\/api\/operator\/v1\/chat\/sessions\/([^/]+)(?:\/|$)/);
|
|
505
|
+
if (sessionMatch) {
|
|
506
|
+
const sessionId = decodeURIComponent(sessionMatch[1]);
|
|
507
|
+
// r4 AC-R2-001: the mutation gate fires BEFORE session ownership
|
|
508
|
+
// resolution — an unauthenticated mutation on ANY session id
|
|
509
|
+
// (existing or not) gets exactly 403, never a masked 404 that
|
|
510
|
+
// would hide a gate-order regression.
|
|
511
|
+
if (method !== "GET" && method !== "HEAD") {
|
|
512
|
+
const { evaluateMutationGate } = await import("./security.js");
|
|
513
|
+
const failure = evaluateMutationGate(req, {
|
|
514
|
+
cookieName: bootToken.cookieName,
|
|
515
|
+
bootToken: bootToken.value,
|
|
516
|
+
confirmationToken: bootToken.confirmationToken,
|
|
517
|
+
consoleOrigin: getConsoleOrigin(),
|
|
518
|
+
allowNonLoopbackAccess: !loopbackBind,
|
|
519
|
+
});
|
|
520
|
+
if (failure) {
|
|
521
|
+
sendJson(res, failure.status, {
|
|
522
|
+
ok: false,
|
|
523
|
+
error: {
|
|
524
|
+
code: failure.code,
|
|
525
|
+
message: failure.message,
|
|
526
|
+
},
|
|
527
|
+
});
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
const requestedId = url.searchParams.get("workspaceId")?.trim();
|
|
532
|
+
const catalogEntry = chatSessionCatalog.get(sessionId);
|
|
533
|
+
let owner;
|
|
534
|
+
if (requestedId) {
|
|
535
|
+
if (catalogEntry?.workspaceId &&
|
|
536
|
+
catalogEntry.workspaceId !== requestedId) {
|
|
537
|
+
sendJson(res, 403, {
|
|
538
|
+
ok: false,
|
|
539
|
+
error: {
|
|
540
|
+
code: "WORKSPACE_CONFLICT",
|
|
541
|
+
message: "workspaceId does not match the session's owning workspace",
|
|
542
|
+
},
|
|
543
|
+
});
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
// The current UI always sends its selected workspace. Resolve that one
|
|
547
|
+
// context directly: scanning every historical registry entry first can
|
|
548
|
+
// fail on an old, deleted temp directory before reaching the real owner.
|
|
549
|
+
const ownerRecord = catalogEntry
|
|
550
|
+
? await registry.get(requestedId)
|
|
551
|
+
: await registry.getVisible(requestedId);
|
|
552
|
+
if (!ownerRecord ||
|
|
553
|
+
(catalogEntry &&
|
|
554
|
+
ownerRecord.repoFingerprint !== catalogEntry.repoFingerprint)) {
|
|
555
|
+
// A session-scoped workspace hint is a conflict boundary. Unknown
|
|
556
|
+
// workspace ids must not reveal whether the session exists elsewhere.
|
|
557
|
+
sendJson(res, 403, {
|
|
558
|
+
ok: false,
|
|
559
|
+
error: {
|
|
560
|
+
code: "WORKSPACE_CONFLICT",
|
|
561
|
+
message: "workspaceId does not match the session's owning workspace",
|
|
562
|
+
},
|
|
563
|
+
});
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
const context = await materializeContext(ownerRecord);
|
|
567
|
+
const stored = await context.chatRouteDeps.store.get(sessionId);
|
|
568
|
+
if (stored)
|
|
569
|
+
owner = context;
|
|
570
|
+
else if (!catalogEntry) {
|
|
571
|
+
// Catalog and store both miss: the session was deleted, not
|
|
572
|
+
// retargeted. Do not scan other workspaces or leak existence.
|
|
573
|
+
sendJson(res, 404, {
|
|
574
|
+
ok: false,
|
|
575
|
+
error: {
|
|
576
|
+
code: "PI_SESSION_NOT_FOUND",
|
|
577
|
+
message: `chat session not found: ${sessionId}`,
|
|
578
|
+
},
|
|
579
|
+
});
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
else {
|
|
583
|
+
chatSessionCatalog.remove(sessionId);
|
|
584
|
+
await registry
|
|
585
|
+
.detachSession(ownerRecord.workspaceId, sessionId)
|
|
586
|
+
.catch(() => undefined);
|
|
587
|
+
// Catalog had the id, but this workspace store does not.
|
|
588
|
+
// Keep the conflict code so a mismatched selection cannot
|
|
589
|
+
// discover whether the session lives elsewhere.
|
|
590
|
+
sendJson(res, 403, {
|
|
591
|
+
ok: false,
|
|
592
|
+
error: {
|
|
593
|
+
code: "WORKSPACE_CONFLICT",
|
|
594
|
+
message: "workspaceId does not match the session's owning workspace",
|
|
595
|
+
},
|
|
596
|
+
});
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
else if (catalogEntry?.workspaceId) {
|
|
601
|
+
const ownerRecord = await registry.get(catalogEntry.workspaceId);
|
|
602
|
+
if (ownerRecord &&
|
|
603
|
+
ownerRecord.repoFingerprint === catalogEntry.repoFingerprint) {
|
|
604
|
+
owner = await materializeContext(ownerRecord);
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
else {
|
|
608
|
+
// Catalog misses are limited to out-of-process/legacy writes after Host
|
|
609
|
+
// startup. Recover once, then publish the discovered Session into the
|
|
610
|
+
// independent baseline for subsequent requests.
|
|
611
|
+
for (const record of await registry.listVisible()) {
|
|
612
|
+
try {
|
|
613
|
+
const resolution = await resolveContext(record.workspaceId);
|
|
614
|
+
if (!resolution.ok)
|
|
615
|
+
continue;
|
|
616
|
+
const stored = await resolution.context.chatRouteDeps.store.get(sessionId);
|
|
617
|
+
if (stored) {
|
|
618
|
+
owner = resolution.context;
|
|
619
|
+
chatSessionCatalog.upsert(stored, record.workspaceId);
|
|
620
|
+
break;
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
catch {
|
|
624
|
+
// An unavailable historical Workspace is not evidence that the
|
|
625
|
+
// requested session is missing from every other visible Workspace.
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
if (!owner) {
|
|
630
|
+
sendJson(res, 404, {
|
|
631
|
+
ok: false,
|
|
632
|
+
error: {
|
|
633
|
+
code: "NOT_FOUND",
|
|
634
|
+
message: `chat session not found: ${sessionId}`,
|
|
635
|
+
},
|
|
636
|
+
});
|
|
637
|
+
return;
|
|
638
|
+
}
|
|
639
|
+
owner.actionContext.readiness = owner.getReadiness();
|
|
640
|
+
// Session-scoped routes: ownership is durable on the record; no explicit
|
|
641
|
+
// workspace scope is needed (it lives in store record + query conflict check).
|
|
642
|
+
await dispatchChat(req, res, owner.chatRouteDeps, pathname, undefined);
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
// Non-session chat surfaces normally resolve from ?workspaceId=. The
|
|
646
|
+
// HTML preview route carries it in the URL path so browser-relative
|
|
647
|
+
// CSS/image requests retain the same workspace scope after dropping a
|
|
648
|
+
// document query string.
|
|
649
|
+
const queryWorkspaceId = url.searchParams.get("workspaceId")?.trim() || undefined;
|
|
650
|
+
if (htmlPreviewRoute &&
|
|
651
|
+
queryWorkspaceId &&
|
|
652
|
+
queryWorkspaceId !== htmlPreviewRoute.workspaceId) {
|
|
653
|
+
sendJson(res, 403, {
|
|
654
|
+
ok: false,
|
|
655
|
+
error: {
|
|
656
|
+
code: "WORKSPACE_CONFLICT",
|
|
657
|
+
message: "workspaceId does not match the HTML preview route",
|
|
658
|
+
},
|
|
659
|
+
});
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
const workspaceId = htmlPreviewRoute?.workspaceId || queryWorkspaceId;
|
|
663
|
+
const resolution = await resolveContext(workspaceId);
|
|
664
|
+
if (!resolution.ok) {
|
|
665
|
+
sendJson(res, resolution.status, {
|
|
666
|
+
ok: false,
|
|
667
|
+
error: { code: resolution.code, message: resolution.message },
|
|
668
|
+
});
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
resolution.context.actionContext.readiness =
|
|
672
|
+
resolution.context.getReadiness();
|
|
673
|
+
await dispatchChat(req, res, resolution.context.chatRouteDeps, pathname, undefined);
|
|
674
|
+
}
|
|
675
|
+
async function handleOperatorDispatch(req, res, pathname, url, method) {
|
|
676
|
+
const { handleConsoleOperatorRequest } = await import("./routes.js");
|
|
677
|
+
// POST /api/operator/v1/operations creation carries workspaceId in the
|
|
678
|
+
// JSON body. Operation reads carry ?workspaceId=. Non-workspace routes
|
|
679
|
+
// (readiness, recovery, session ping, night-aux-ticker) use the startup
|
|
680
|
+
// context for backward compatibility.
|
|
681
|
+
if (method === "POST" && pathname === "/api/operator/v1/operations") {
|
|
682
|
+
const resolution = await resolveContextFromOperationCreateBody(req, res, resolveContext);
|
|
683
|
+
if (!resolution)
|
|
684
|
+
return; // response already sent
|
|
685
|
+
await handleConsoleOperatorRequest(req, res, operatorRouteContext(resolution.context));
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
const opMatch = pathname.match(/^\/api\/operator\/v1\/operations\/([^/]+)(?:\/(events))?$/);
|
|
689
|
+
const contextDownloadMatch = pathname.match(/^\/api\/operator\/v1\/context-exports\/[a-f0-9]{32}\/download$/);
|
|
690
|
+
if ((method === "GET" && pathname === "/api/operator/v1/operations") ||
|
|
691
|
+
opMatch ||
|
|
692
|
+
(method === "GET" && contextDownloadMatch)) {
|
|
693
|
+
const workspaceId = url.searchParams.get("workspaceId") ?? undefined;
|
|
694
|
+
const resolution = await resolveContext(workspaceId);
|
|
695
|
+
if (!resolution.ok) {
|
|
696
|
+
sendJson(res, resolution.status, {
|
|
697
|
+
ok: false,
|
|
698
|
+
error: { code: resolution.code, message: resolution.message },
|
|
699
|
+
});
|
|
700
|
+
return;
|
|
701
|
+
}
|
|
702
|
+
resolution.context.actionContext.readiness =
|
|
703
|
+
resolution.context.getReadiness();
|
|
704
|
+
await handleConsoleOperatorRequest(req, res, operatorRouteContext(resolution.context));
|
|
705
|
+
return;
|
|
706
|
+
}
|
|
707
|
+
// Multi-workspace read-scope (2026-08-26, AC-005): every remaining
|
|
708
|
+
// operator read route (readiness, recovery candidates, night-aux-ticker
|
|
709
|
+
// GET and the ticker POST mutation) requires an EXPLICIT workspaceId;
|
|
710
|
+
// missing/unknown ids fail closed with the shared error contract. No
|
|
711
|
+
// route silently falls back to the startup workspace anymore. Only
|
|
712
|
+
// /api/session/ping stays process-level (mutation-gate probe stub).
|
|
713
|
+
if ((method === "GET" &&
|
|
714
|
+
(pathname === "/api/operator/v1/readiness" ||
|
|
715
|
+
pathname === "/api/operator/v1/recovery/candidates" ||
|
|
716
|
+
pathname === "/api/operator/v1/night-aux-ticker")) ||
|
|
717
|
+
(method === "POST" &&
|
|
718
|
+
pathname === "/api/operator/v1/night-aux-ticker")) {
|
|
719
|
+
const workspaceId = url.searchParams.get("workspaceId") ?? undefined;
|
|
720
|
+
const resolution = await resolveContext(workspaceId);
|
|
721
|
+
if (!resolution.ok) {
|
|
722
|
+
sendJson(res, resolution.status, {
|
|
723
|
+
ok: false,
|
|
724
|
+
error: { code: resolution.code, message: resolution.message },
|
|
725
|
+
});
|
|
726
|
+
return;
|
|
727
|
+
}
|
|
728
|
+
resolution.context.actionContext.readiness =
|
|
729
|
+
resolution.context.getReadiness();
|
|
730
|
+
await handleConsoleOperatorRequest(req, res, operatorRouteContext(resolution.context));
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
// /api/session/ping stays process-level (mutation-gate probe stub).
|
|
734
|
+
if (pathname === "/api/session/ping") {
|
|
735
|
+
await handleConsoleOperatorRequest(req, res, operatorRouteContext(startup));
|
|
736
|
+
return;
|
|
737
|
+
}
|
|
738
|
+
// Pi 插件目录 / 版本 / 更新检查 / 安装 / 卸载:全局用户级(~/.pi/agent),非工作区作用域,用 startup context。
|
|
739
|
+
if (pathname === "/api/operator/v1/pi-plugins" ||
|
|
740
|
+
pathname === "/api/operator/v1/pi-plugins/versions" ||
|
|
741
|
+
pathname === "/api/operator/v1/pi-plugins/updates" ||
|
|
742
|
+
pathname === "/api/operator/v1/pi-plugins/install" ||
|
|
743
|
+
pathname === "/api/operator/v1/pi-plugins/uninstall") {
|
|
744
|
+
await handleConsoleOperatorRequest(req, res, operatorRouteContext(startup));
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
// Unknown operator route: fail closed (never a startup-workspace proxy).
|
|
748
|
+
sendJson(res, 404, {
|
|
749
|
+
ok: false,
|
|
750
|
+
error: {
|
|
751
|
+
code: "NOT_FOUND",
|
|
752
|
+
message: `unknown operator route: ${pathname}`,
|
|
753
|
+
},
|
|
754
|
+
});
|
|
755
|
+
}
|
|
756
|
+
function operatorRouteContext(context) {
|
|
757
|
+
return {
|
|
758
|
+
repoRoot: context.repoRoot,
|
|
759
|
+
staticDir,
|
|
760
|
+
bootToken,
|
|
761
|
+
inspectBootToken,
|
|
762
|
+
getConsoleOrigin,
|
|
763
|
+
allowNonLoopbackAccess: !loopbackBind,
|
|
764
|
+
inspect: {
|
|
765
|
+
ready: existsSync(path.join(inspectStaticDir, "index.html")),
|
|
766
|
+
routeCapabilities: deriveObserveRouteCapabilities(ROUTES),
|
|
767
|
+
},
|
|
768
|
+
consoleInstanceId,
|
|
769
|
+
operator: {
|
|
770
|
+
actionContext: context.actionContext,
|
|
771
|
+
operations: context.operations,
|
|
772
|
+
events: context.events,
|
|
773
|
+
getReadiness: context.getReadiness,
|
|
774
|
+
chat: context.chatRouteDeps,
|
|
775
|
+
nightAuxTicker: context.nightAuxTicker,
|
|
776
|
+
},
|
|
777
|
+
workspace: context,
|
|
778
|
+
};
|
|
285
779
|
}
|
|
286
780
|
server.on("error", reject);
|
|
287
|
-
server.listen(
|
|
781
|
+
server.listen(configuredPort, host, () => {
|
|
288
782
|
const addr = server.address();
|
|
289
783
|
if (!addr || typeof addr === "string") {
|
|
290
784
|
reject(new Error("Failed to get console server address"));
|
|
@@ -303,31 +797,140 @@ export async function createConsoleServer(options) {
|
|
|
303
797
|
url,
|
|
304
798
|
host,
|
|
305
799
|
port: addr.port,
|
|
306
|
-
appData,
|
|
307
|
-
operations,
|
|
308
|
-
events,
|
|
800
|
+
appData: startup.appData,
|
|
801
|
+
operations: startup.operations,
|
|
802
|
+
events: startup.events,
|
|
803
|
+
splitOrchestrator: startup.splitOrchestrator,
|
|
804
|
+
humanDecisionAdapter: startup.humanDecisionAdapter,
|
|
805
|
+
materializer: startup.materializer,
|
|
309
806
|
getReadiness,
|
|
310
807
|
operatorSessionId,
|
|
808
|
+
registry,
|
|
809
|
+
getWorkspaceContext: (workspaceId) => workspaceContexts.get(workspaceId),
|
|
810
|
+
listWorkspaceContexts: () => [...workspaceContexts.values()],
|
|
311
811
|
close: () => new Promise((closeResolve, closeReject) => {
|
|
312
|
-
// Dispose
|
|
812
|
+
// Dispose ALL workspace contexts BEFORE closing the HTTP server so
|
|
313
813
|
// no prompt is left executing and no session/SDK state/file handle
|
|
314
|
-
// leaks across Console restarts
|
|
315
|
-
//
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
process.stderr.write(`[console] chatRuntime.disposeAll() failed during close: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
814
|
+
// leaks across Console restarts. Each context is disposed exactly
|
|
815
|
+
// once (dispose() is idempotent).
|
|
816
|
+
for (const context of workspaceContexts.values()) {
|
|
817
|
+
try {
|
|
818
|
+
context.dispose();
|
|
819
|
+
}
|
|
820
|
+
catch (error) {
|
|
821
|
+
process.stderr.write(`[console] workspace context dispose failed during close: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
822
|
+
}
|
|
324
823
|
}
|
|
824
|
+
workspaceContexts.clear();
|
|
825
|
+
registry.close();
|
|
325
826
|
server.close((err) => (err ? closeReject(err) : closeResolve()));
|
|
827
|
+
// Workspace/event SSE responses are intentionally long-lived. Force them
|
|
828
|
+
// closed after initiating shutdown so Console close never hangs on a tab.
|
|
829
|
+
server.closeAllConnections();
|
|
326
830
|
}),
|
|
327
831
|
});
|
|
328
832
|
});
|
|
329
833
|
});
|
|
330
834
|
}
|
|
835
|
+
/**
|
|
836
|
+
* Resolve a workspace context for POST /chat/sessions. The workspaceId comes
|
|
837
|
+
* from the JSON body; the body is pre-read and handed to the route handler so
|
|
838
|
+
* it is not consumed twice.
|
|
839
|
+
*/
|
|
840
|
+
async function resolveContextFromSessionCreateBody(req, res, resolveContext) {
|
|
841
|
+
const body = await readBodyOnce(req);
|
|
842
|
+
if (!body.ok) {
|
|
843
|
+
sendJson(res, body.status, {
|
|
844
|
+
ok: false,
|
|
845
|
+
error: { code: body.code, message: body.message },
|
|
846
|
+
});
|
|
847
|
+
return undefined;
|
|
848
|
+
}
|
|
849
|
+
const record = body.value;
|
|
850
|
+
const workspaceId = typeof record.workspaceId === "string" ? record.workspaceId : undefined;
|
|
851
|
+
const resolution = await resolveContext(workspaceId);
|
|
852
|
+
if (!resolution.ok) {
|
|
853
|
+
sendJson(res, resolution.status, {
|
|
854
|
+
ok: false,
|
|
855
|
+
error: { code: resolution.code, message: resolution.message },
|
|
856
|
+
});
|
|
857
|
+
return undefined;
|
|
858
|
+
}
|
|
859
|
+
// AC-R7-002 (2026-08-23): the runtime store.create wrapper
|
|
860
|
+
// (the former per-store patch + WeakMap cache) was fully removed;
|
|
861
|
+
// workspaceId now flows as an explicit parameter from this
|
|
862
|
+
// dispatcher through handleCreateChatSession into store.create.
|
|
863
|
+
return { context: resolution.context };
|
|
864
|
+
}
|
|
865
|
+
/** Resolve a workspace context for POST /operations (workspaceId in body). */
|
|
866
|
+
async function resolveContextFromOperationCreateBody(req, res, resolveContext) {
|
|
867
|
+
const body = await readBodyOnce(req);
|
|
868
|
+
if (!body.ok) {
|
|
869
|
+
sendJson(res, body.status, {
|
|
870
|
+
ok: false,
|
|
871
|
+
error: { code: body.code, message: body.message },
|
|
872
|
+
});
|
|
873
|
+
return undefined;
|
|
874
|
+
}
|
|
875
|
+
const record = body.value;
|
|
876
|
+
const workspaceId = typeof record.workspaceId === "string" ? record.workspaceId.trim() : "";
|
|
877
|
+
if (!workspaceId) {
|
|
878
|
+
sendJson(res, 400, {
|
|
879
|
+
ok: false,
|
|
880
|
+
error: {
|
|
881
|
+
code: "WORKSPACE_REQUIRED",
|
|
882
|
+
message: "workspaceId is required",
|
|
883
|
+
},
|
|
884
|
+
});
|
|
885
|
+
return undefined;
|
|
886
|
+
}
|
|
887
|
+
const resolution = await resolveContext(workspaceId);
|
|
888
|
+
if (!resolution.ok) {
|
|
889
|
+
sendJson(res, resolution.status, {
|
|
890
|
+
ok: false,
|
|
891
|
+
error: { code: resolution.code, message: resolution.message },
|
|
892
|
+
});
|
|
893
|
+
return undefined;
|
|
894
|
+
}
|
|
895
|
+
return { context: resolution.context, preReadBody: record };
|
|
896
|
+
}
|
|
897
|
+
/** Read and buffer a JSON request body once (restored onto req for handlers). */
|
|
898
|
+
async function readBodyOnce(req) {
|
|
899
|
+
const chunks = [];
|
|
900
|
+
let total = 0;
|
|
901
|
+
for await (const chunk of req) {
|
|
902
|
+
const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
903
|
+
total += buf.length;
|
|
904
|
+
if (total > 10 * 1024 * 1024) {
|
|
905
|
+
return {
|
|
906
|
+
ok: false,
|
|
907
|
+
status: 400,
|
|
908
|
+
code: "INVALID_INPUT",
|
|
909
|
+
message: "request body exceeds 10485760 bytes",
|
|
910
|
+
};
|
|
911
|
+
}
|
|
912
|
+
chunks.push(buf);
|
|
913
|
+
}
|
|
914
|
+
const raw = Buffer.concat(chunks).toString("utf8");
|
|
915
|
+
if (!raw.trim()) {
|
|
916
|
+
return { ok: true, value: {} };
|
|
917
|
+
}
|
|
918
|
+
try {
|
|
919
|
+
const value = JSON.parse(raw);
|
|
920
|
+
// Re-inject the body so downstream route handlers can read it again.
|
|
921
|
+
req.__preReadBody =
|
|
922
|
+
value;
|
|
923
|
+
return { ok: true, value };
|
|
924
|
+
}
|
|
925
|
+
catch (error) {
|
|
926
|
+
return {
|
|
927
|
+
ok: false,
|
|
928
|
+
status: 400,
|
|
929
|
+
code: "INVALID_INPUT",
|
|
930
|
+
message: `invalid JSON body: ${error instanceof Error ? error.message : String(error)}`,
|
|
931
|
+
};
|
|
932
|
+
}
|
|
933
|
+
}
|
|
331
934
|
function requestSource(req) {
|
|
332
935
|
const forwarded = req.headers["x-forwarded-for"];
|
|
333
936
|
if (typeof forwarded === "string" && forwarded.trim()) {
|