@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
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure projection from a DAG run detail payload (GET /api/dag-runs/:id) into
|
|
3
|
+
* the structured run progress shown on the wizard RunPanel: node counts,
|
|
4
|
+
* current node + elapsed time, failure pointer, and stall signal. The panel
|
|
5
|
+
* used to show only a raw SSE log tail — node/phase information drowned in
|
|
6
|
+
* log noise during 20-40 minute runs.
|
|
7
|
+
*/
|
|
8
|
+
export function classifyRunProgressNodeStatus(raw) {
|
|
9
|
+
const status = (raw ?? "").trim().toLowerCase();
|
|
10
|
+
if (!status)
|
|
11
|
+
return "pending";
|
|
12
|
+
if (status.includes("running") || status === "in_progress" || status === "active") {
|
|
13
|
+
return "running";
|
|
14
|
+
}
|
|
15
|
+
if (status.includes("fail") || status.includes("error") || status === "blocked") {
|
|
16
|
+
return "failed";
|
|
17
|
+
}
|
|
18
|
+
if (status.includes("finish") ||
|
|
19
|
+
status.includes("success") ||
|
|
20
|
+
status === "done" ||
|
|
21
|
+
status === "ok") {
|
|
22
|
+
return "finished";
|
|
23
|
+
}
|
|
24
|
+
if (status.includes("skip"))
|
|
25
|
+
return "skipped";
|
|
26
|
+
return "pending";
|
|
27
|
+
}
|
|
28
|
+
function toProgressNode(node) {
|
|
29
|
+
const nodeId = String(node.nodeId ?? node.id ?? "").trim();
|
|
30
|
+
return {
|
|
31
|
+
nodeId,
|
|
32
|
+
label: String((node.label ?? node.name ?? nodeId) || "未命名节点"),
|
|
33
|
+
status: String(node.status ?? ""),
|
|
34
|
+
rank: typeof node.rank === "string" ? node.rank : undefined,
|
|
35
|
+
startedAt: typeof node.startedAt === "string" ? node.startedAt : undefined,
|
|
36
|
+
durationMs: typeof node.durationMs === "number" ? node.durationMs : undefined,
|
|
37
|
+
errorPreview: typeof node.errorPreview === "string" ? node.errorPreview : undefined,
|
|
38
|
+
lastMeaningfulProgressAt: typeof node.lastMeaningfulProgressAt === "string"
|
|
39
|
+
? node.lastMeaningfulProgressAt
|
|
40
|
+
: undefined,
|
|
41
|
+
livenessStatus: typeof node.livenessStatus === "string" ? node.livenessStatus : undefined,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function latestIso(values) {
|
|
45
|
+
let latest = null;
|
|
46
|
+
for (const iso of values) {
|
|
47
|
+
if (!iso)
|
|
48
|
+
continue;
|
|
49
|
+
const time = Date.parse(iso);
|
|
50
|
+
if (!Number.isFinite(time))
|
|
51
|
+
continue;
|
|
52
|
+
if (!latest || time > latest.time)
|
|
53
|
+
latest = { iso, time };
|
|
54
|
+
}
|
|
55
|
+
return latest?.iso ?? null;
|
|
56
|
+
}
|
|
57
|
+
function elapsedSince(iso, now) {
|
|
58
|
+
if (!iso)
|
|
59
|
+
return null;
|
|
60
|
+
const started = Date.parse(iso);
|
|
61
|
+
if (Number.isNaN(started))
|
|
62
|
+
return null;
|
|
63
|
+
const elapsed = now - started;
|
|
64
|
+
return elapsed >= 0 ? elapsed : null;
|
|
65
|
+
}
|
|
66
|
+
export function summarizeRunProgress(dag, now = Date.now()) {
|
|
67
|
+
if (!dag) {
|
|
68
|
+
return {
|
|
69
|
+
total: 0,
|
|
70
|
+
finished: 0,
|
|
71
|
+
running: null,
|
|
72
|
+
failed: null,
|
|
73
|
+
terminal: false,
|
|
74
|
+
effectiveStatus: null,
|
|
75
|
+
stalled: false,
|
|
76
|
+
currentNodeElapsedMs: null,
|
|
77
|
+
runElapsedMs: null,
|
|
78
|
+
lastMeaningfulProgressAt: null,
|
|
79
|
+
observedAtMs: now,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
const rawNodes = Array.isArray(dag.nodes) ? dag.nodes : [];
|
|
83
|
+
const nodes = rawNodes.map(toProgressNode);
|
|
84
|
+
const classes = nodes.map((node) => classifyRunProgressNodeStatus(node.status));
|
|
85
|
+
const finished = classes.filter((cls) => cls === "finished" || cls === "skipped").length;
|
|
86
|
+
const runningIndex = classes.indexOf("running");
|
|
87
|
+
const running = runningIndex >= 0 ? nodes[runningIndex] : null;
|
|
88
|
+
const failedIndex = classes.indexOf("failed");
|
|
89
|
+
const failed = failedIndex >= 0 ? nodes[failedIndex] : null;
|
|
90
|
+
const effectiveStatus = String(dag.effectiveStatus ??
|
|
91
|
+
dag.status ??
|
|
92
|
+
"").toLowerCase();
|
|
93
|
+
const terminal = TERMINAL_RUN_PROGRESS_STATUSES.has(effectiveStatus);
|
|
94
|
+
const runStartedAt = typeof dag.startedAt === "string" ? dag.startedAt : undefined;
|
|
95
|
+
const runDurationMs = typeof dag.durationMs === "number" ? dag.durationMs : undefined;
|
|
96
|
+
return {
|
|
97
|
+
total: nodes.length,
|
|
98
|
+
finished,
|
|
99
|
+
running,
|
|
100
|
+
failed,
|
|
101
|
+
terminal,
|
|
102
|
+
effectiveStatus: effectiveStatus || null,
|
|
103
|
+
stalled: effectiveStatus === "running-suspected-stall",
|
|
104
|
+
currentNodeElapsedMs: running?.durationMs ?? elapsedSince(running?.startedAt, now),
|
|
105
|
+
runElapsedMs: terminal
|
|
106
|
+
? (runDurationMs ?? elapsedSince(runStartedAt, now))
|
|
107
|
+
: elapsedSince(runStartedAt, now),
|
|
108
|
+
lastMeaningfulProgressAt: latestIso(nodes.map((node) => node.lastMeaningfulProgressAt)),
|
|
109
|
+
observedAtMs: now,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
const TERMINAL_RUN_PROGRESS_STATUSES = new Set([
|
|
113
|
+
"finished",
|
|
114
|
+
"failed",
|
|
115
|
+
"partial_failed",
|
|
116
|
+
"superseded",
|
|
117
|
+
"abandoned",
|
|
118
|
+
]);
|
|
119
|
+
export function formatDurationMs(ms) {
|
|
120
|
+
if (ms == null || !Number.isFinite(ms) || ms < 0)
|
|
121
|
+
return "—";
|
|
122
|
+
const totalSeconds = Math.floor(ms / 1000);
|
|
123
|
+
const hours = Math.floor(totalSeconds / 3600);
|
|
124
|
+
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
|
125
|
+
const seconds = totalSeconds % 60;
|
|
126
|
+
if (hours > 0)
|
|
127
|
+
return `${hours} 时 ${minutes} 分`;
|
|
128
|
+
if (minutes > 0)
|
|
129
|
+
return `${minutes} 分 ${seconds} 秒`;
|
|
130
|
+
return `${seconds} 秒`;
|
|
131
|
+
}
|
|
132
|
+
function friendlyRunPhase(node) {
|
|
133
|
+
if (!node)
|
|
134
|
+
return "正在等待下一阶段";
|
|
135
|
+
const searchable = `${node.nodeId} ${node.label}`.toLowerCase();
|
|
136
|
+
if (/contract|boundary|intake/.test(searchable))
|
|
137
|
+
return "正在确认执行边界";
|
|
138
|
+
if (/scout|explore|research/.test(searchable))
|
|
139
|
+
return "正在梳理影响范围";
|
|
140
|
+
if (/plan|design/.test(searchable))
|
|
141
|
+
return "正在规划实施步骤";
|
|
142
|
+
if (/implement|repair|fix|write/.test(searchable))
|
|
143
|
+
return "正在实现本次修改";
|
|
144
|
+
if (/verify|test|lint|review|check/.test(searchable))
|
|
145
|
+
return "正在验证本次修改";
|
|
146
|
+
if (/closeout|handoff|report/.test(searchable))
|
|
147
|
+
return "正在整理执行结果";
|
|
148
|
+
if (node.label && node.label !== node.nodeId)
|
|
149
|
+
return `正在进行${node.label}`;
|
|
150
|
+
return "正在推进当前阶段";
|
|
151
|
+
}
|
|
152
|
+
function formatMeaningfulAge(iso, now) {
|
|
153
|
+
if (!iso)
|
|
154
|
+
return "等待首个执行进展";
|
|
155
|
+
const time = Date.parse(iso);
|
|
156
|
+
if (!Number.isFinite(time))
|
|
157
|
+
return "等待首个执行进展";
|
|
158
|
+
const seconds = Math.max(0, Math.floor((now - time) / 1000));
|
|
159
|
+
if (seconds < 60)
|
|
160
|
+
return `最近进展 ${seconds} 秒前`;
|
|
161
|
+
const minutes = Math.floor(seconds / 60);
|
|
162
|
+
if (minutes < 60)
|
|
163
|
+
return `最近进展 ${minutes} 分钟前`;
|
|
164
|
+
return `最近进展 ${Math.floor(minutes / 60)} 小时前`;
|
|
165
|
+
}
|
|
166
|
+
/** Human-facing copy shared by the task panel and Operator Chat progress row. */
|
|
167
|
+
export function presentRunProgress(summary, now = Date.now()) {
|
|
168
|
+
if (!summary || !summary.effectiveStatus) {
|
|
169
|
+
return {
|
|
170
|
+
kind: "pending",
|
|
171
|
+
title: "DAG 正在启动",
|
|
172
|
+
detail: "正在等待首个执行进展",
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
const status = summary.effectiveStatus;
|
|
176
|
+
const liveElapsed = summary.runElapsedMs == null
|
|
177
|
+
? null
|
|
178
|
+
: summary.runElapsedMs +
|
|
179
|
+
(summary.terminal ? 0 : Math.max(0, now - summary.observedAtMs));
|
|
180
|
+
const elapsed = formatDurationMs(liveElapsed);
|
|
181
|
+
const progressDetail = `${friendlyRunPhase(summary.running)} · 已完成 ${summary.finished}/${summary.total} 步 · ${formatMeaningfulAge(summary.lastMeaningfulProgressAt, now)}`;
|
|
182
|
+
if (status === "running") {
|
|
183
|
+
return { kind: "progress", title: `DAG 执行中 · 已运行 ${elapsed}`, detail: progressDetail };
|
|
184
|
+
}
|
|
185
|
+
if (status === "running-quiet") {
|
|
186
|
+
return { kind: "quiet", title: `DAG 仍在执行 · 已运行 ${elapsed}`, detail: progressDetail };
|
|
187
|
+
}
|
|
188
|
+
if (status === "running-suspected-stall") {
|
|
189
|
+
return { kind: "warning", title: `执行可能停滞 · 已运行 ${elapsed}`, detail: progressDetail };
|
|
190
|
+
}
|
|
191
|
+
if (["needs-attention", "paused", "interrupted"].includes(status)) {
|
|
192
|
+
return { kind: "warning", title: "DAG 需要处理", detail: progressDetail };
|
|
193
|
+
}
|
|
194
|
+
if (status === "finished") {
|
|
195
|
+
return {
|
|
196
|
+
kind: "success",
|
|
197
|
+
title: `DAG 已完成 · 总用时 ${elapsed}`,
|
|
198
|
+
detail: `已完成 ${summary.finished}/${summary.total} 步 · ${formatMeaningfulAge(summary.lastMeaningfulProgressAt, now)}`,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
if (status === "partial_failed" || status === "failed") {
|
|
202
|
+
return {
|
|
203
|
+
kind: "error",
|
|
204
|
+
title: `DAG 未完成 · 总用时 ${elapsed}`,
|
|
205
|
+
detail: `已完成 ${summary.finished}/${summary.total} 步 · ${formatMeaningfulAge(summary.lastMeaningfulProgressAt, now)}`,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
if (status === "pending") {
|
|
209
|
+
return { kind: "pending", title: "DAG 正在启动", detail: progressDetail };
|
|
210
|
+
}
|
|
211
|
+
return {
|
|
212
|
+
kind: "warning",
|
|
213
|
+
title: `DAG 已结束 · 总用时 ${elapsed}`,
|
|
214
|
+
detail: `已完成 ${summary.finished}/${summary.total} 步`,
|
|
215
|
+
};
|
|
216
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export function isReplacementConsoleHealth(health, expectedConsoleInstanceId, previousConsoleInstanceId) {
|
|
2
|
+
if (!health || typeof health !== "object")
|
|
3
|
+
return false;
|
|
4
|
+
const instanceId = typeof health.consoleInstanceId ===
|
|
5
|
+
"string"
|
|
6
|
+
? health.consoleInstanceId.trim()
|
|
7
|
+
: "";
|
|
8
|
+
if (!instanceId)
|
|
9
|
+
return false;
|
|
10
|
+
const expected = expectedConsoleInstanceId?.trim();
|
|
11
|
+
if (expected)
|
|
12
|
+
return instanceId === expected;
|
|
13
|
+
return previousConsoleInstanceId !== null && instanceId !== previousConsoleInstanceId;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Poll /api/health until the replacement Console answers, then reload. A
|
|
17
|
+
* handoff deliberately leaves the old process alive briefly, so HTTP 200 alone
|
|
18
|
+
* is insufficient: the response must carry the new instance identity.
|
|
19
|
+
*/
|
|
20
|
+
export async function reloadWhenConsoleReady(options = {}) {
|
|
21
|
+
const timeoutMs = options.timeoutMs ?? 30_000;
|
|
22
|
+
const fetchImpl = options.fetchImpl ?? fetch;
|
|
23
|
+
const reload = options.reload ?? (() => window.location.reload());
|
|
24
|
+
const started = Date.now();
|
|
25
|
+
let previousConsoleInstanceId = null;
|
|
26
|
+
while (Date.now() - started < timeoutMs) {
|
|
27
|
+
try {
|
|
28
|
+
const res = await fetchImpl(`/api/health?ts=${Date.now()}`, {
|
|
29
|
+
cache: "no-store",
|
|
30
|
+
});
|
|
31
|
+
if (res.ok) {
|
|
32
|
+
const health = await res.json().catch(() => null);
|
|
33
|
+
if (isReplacementConsoleHealth(health, options.expectedConsoleInstanceId, previousConsoleInstanceId)) {
|
|
34
|
+
reload();
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
const healthRecord = health;
|
|
38
|
+
const instanceId = typeof healthRecord?.consoleInstanceId === "string"
|
|
39
|
+
? healthRecord.consoleInstanceId.trim()
|
|
40
|
+
: "";
|
|
41
|
+
if (instanceId && previousConsoleInstanceId === null) {
|
|
42
|
+
previousConsoleInstanceId = instanceId;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
// old process gone, new one not listening yet — keep polling
|
|
48
|
+
}
|
|
49
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
50
|
+
}
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
+
import { confirmationToken } from "../operator-chat/format.js";
|
|
3
|
+
import { describeMutationGateFailure, isMutationGateFailureCode, } from "../operator-chat/mutation-gate.js";
|
|
4
|
+
/**
|
|
5
|
+
* Multi-workspace registry state (2026-08-23, AC-001/AC-003).
|
|
6
|
+
*
|
|
7
|
+
* Consumes the process-level GET/POST/PATCH/DELETE /api/operator/v1/workspaces
|
|
8
|
+
* surface. POST/DELETE pass the Console mutation-gate confirmation token.
|
|
9
|
+
* The selected workspaceId is remembered in localStorage and validated
|
|
10
|
+
* against the visible list. A stale local preference falls back to the first
|
|
11
|
+
* visible workspace; an explicit unknown URL id remains fail-closed in the
|
|
12
|
+
* route layer.
|
|
13
|
+
*
|
|
14
|
+
* The network/state machine lives in createWorkspacesController (headless,
|
|
15
|
+
* node-testable); useWorkspaces is a thin React subscription wrapper.
|
|
16
|
+
*/
|
|
17
|
+
export const ACTIVE_WORKSPACE_STORAGE_KEY = "loop-console.operator-shell.active-workspace.v1";
|
|
18
|
+
export function readStoredWorkspaceId(storage) {
|
|
19
|
+
try {
|
|
20
|
+
const raw = storage?.getItem(ACTIVE_WORKSPACE_STORAGE_KEY)?.trim();
|
|
21
|
+
return raw || null;
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export function rememberWorkspaceId(workspaceId, storage) {
|
|
28
|
+
try {
|
|
29
|
+
if (workspaceId)
|
|
30
|
+
storage?.setItem(ACTIVE_WORKSPACE_STORAGE_KEY, workspaceId);
|
|
31
|
+
else
|
|
32
|
+
storage?.removeItem(ACTIVE_WORKSPACE_STORAGE_KEY);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
/* localStorage unavailable: in-memory selection still works. */
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export function pickDefaultWorkspaceId(workspaces, storedId) {
|
|
39
|
+
if (storedId) {
|
|
40
|
+
if (workspaces.some((w) => w.workspaceId === storedId))
|
|
41
|
+
return { status: "ok", workspaceId: storedId };
|
|
42
|
+
return { status: "ok", workspaceId: workspaces[0]?.workspaceId ?? null };
|
|
43
|
+
}
|
|
44
|
+
return { status: "ok", workspaceId: workspaces[0]?.workspaceId ?? null };
|
|
45
|
+
}
|
|
46
|
+
export function describeWorkspaceAddError(status, code, message) {
|
|
47
|
+
if (status === 409 || code === "DUPLICATE") {
|
|
48
|
+
return (message ||
|
|
49
|
+
"该目录(或等价路径)已存在为 Workspace:请直接选择既有条目,或更换其他真实目录。");
|
|
50
|
+
}
|
|
51
|
+
if (status === 400 || code === "INVALID_PATH") {
|
|
52
|
+
return message || "目录不可用:请确认输入的是存在的真实目录绝对路径。";
|
|
53
|
+
}
|
|
54
|
+
if (isMutationGateFailureCode(code)) {
|
|
55
|
+
return describeMutationGateFailure(code);
|
|
56
|
+
}
|
|
57
|
+
return message || `添加 Workspace 失败(HTTP ${status})`;
|
|
58
|
+
}
|
|
59
|
+
// The headless object also exposes subscribe(); declared via intersection below.
|
|
60
|
+
/** Headless multi-workspace state machine (real request path, no React). */
|
|
61
|
+
export function createWorkspacesController(params = {}) {
|
|
62
|
+
const origin = params.origin ?? "";
|
|
63
|
+
const fetchImpl = params.fetchFn ?? fetch;
|
|
64
|
+
const storage = params.storage;
|
|
65
|
+
const token = params.confirmationTokenFn ?? confirmationToken;
|
|
66
|
+
const listeners = new Set();
|
|
67
|
+
let appliedRevision = 0;
|
|
68
|
+
let refreshQueued = false;
|
|
69
|
+
let refreshPromise = null;
|
|
70
|
+
let eventStream;
|
|
71
|
+
let disposed = false;
|
|
72
|
+
let state = {
|
|
73
|
+
workspaces: [],
|
|
74
|
+
loading: true,
|
|
75
|
+
error: null,
|
|
76
|
+
workspaceId: readStoredWorkspaceId(storage),
|
|
77
|
+
unknownWorkspaceId: null,
|
|
78
|
+
};
|
|
79
|
+
const emit = () => {
|
|
80
|
+
for (const listener of listeners)
|
|
81
|
+
listener();
|
|
82
|
+
};
|
|
83
|
+
const setState = (patch) => {
|
|
84
|
+
state = { ...state, ...patch };
|
|
85
|
+
emit();
|
|
86
|
+
};
|
|
87
|
+
const refresh = () => {
|
|
88
|
+
refreshQueued = true;
|
|
89
|
+
if (refreshPromise)
|
|
90
|
+
return refreshPromise;
|
|
91
|
+
refreshPromise = (async () => {
|
|
92
|
+
while (refreshQueued && !disposed) {
|
|
93
|
+
refreshQueued = false;
|
|
94
|
+
try {
|
|
95
|
+
const res = await fetchImpl(`${origin}/api/operator/v1/workspaces`, {
|
|
96
|
+
credentials: "include",
|
|
97
|
+
});
|
|
98
|
+
if (!res.ok)
|
|
99
|
+
continue;
|
|
100
|
+
const body = (await res.json());
|
|
101
|
+
const revision = Number.isSafeInteger(body.revision)
|
|
102
|
+
? Math.max(0, body.revision ?? 0)
|
|
103
|
+
: undefined;
|
|
104
|
+
// Legacy/injected responses without revision remain usable. A
|
|
105
|
+
// revisioned response can never roll the projection backwards.
|
|
106
|
+
if (revision !== undefined && revision < appliedRevision)
|
|
107
|
+
continue;
|
|
108
|
+
if (revision !== undefined)
|
|
109
|
+
appliedRevision = revision;
|
|
110
|
+
const list = body.workspaces ?? [];
|
|
111
|
+
const pick = pickDefaultWorkspaceId(list, state.workspaceId);
|
|
112
|
+
if (pick.status === "unknown-workspace") {
|
|
113
|
+
setState({
|
|
114
|
+
workspaces: list,
|
|
115
|
+
unknownWorkspaceId: pick.workspaceId,
|
|
116
|
+
});
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
const nextId = pick.workspaceId;
|
|
120
|
+
const previousId = state.workspaceId;
|
|
121
|
+
setState({
|
|
122
|
+
workspaces: list,
|
|
123
|
+
unknownWorkspaceId: null,
|
|
124
|
+
...(nextId !== previousId ? { workspaceId: nextId } : {}),
|
|
125
|
+
});
|
|
126
|
+
if (nextId !== previousId)
|
|
127
|
+
rememberWorkspaceId(nextId, storage);
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
/* Registry unreachable: keep last known list. */
|
|
131
|
+
}
|
|
132
|
+
finally {
|
|
133
|
+
if (state.loading)
|
|
134
|
+
setState({ loading: false });
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
})().finally(() => {
|
|
138
|
+
refreshPromise = null;
|
|
139
|
+
// An event can arrive between the loop condition and finally.
|
|
140
|
+
if (refreshQueued && !disposed)
|
|
141
|
+
void refresh();
|
|
142
|
+
});
|
|
143
|
+
return refreshPromise;
|
|
144
|
+
};
|
|
145
|
+
const consumeRegistryEvent = (event) => {
|
|
146
|
+
try {
|
|
147
|
+
const revision = Number(JSON.parse(event.data).revision);
|
|
148
|
+
if (Number.isSafeInteger(revision) && revision > appliedRevision) {
|
|
149
|
+
void refresh();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
/* Malformed frames are ignored; reconnect baseline remains authoritative. */
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
const startEventStream = () => {
|
|
157
|
+
if (eventStream || disposed)
|
|
158
|
+
return;
|
|
159
|
+
const factory = params.eventSourceFactory ??
|
|
160
|
+
(typeof EventSource !== "undefined"
|
|
161
|
+
? (url) => new EventSource(url, {
|
|
162
|
+
withCredentials: true,
|
|
163
|
+
})
|
|
164
|
+
: undefined);
|
|
165
|
+
if (!factory)
|
|
166
|
+
return;
|
|
167
|
+
eventStream = factory(`${origin}/api/operator/v1/workspaces/events`);
|
|
168
|
+
eventStream.addEventListener("workspace_registry_ready", consumeRegistryEvent);
|
|
169
|
+
eventStream.addEventListener("workspace_registry_changed", consumeRegistryEvent);
|
|
170
|
+
};
|
|
171
|
+
const addWorkspace = async (directoryPath, name) => {
|
|
172
|
+
setState({ error: null });
|
|
173
|
+
try {
|
|
174
|
+
const res = await fetchImpl(`${origin}/api/operator/v1/workspaces`, {
|
|
175
|
+
method: "POST",
|
|
176
|
+
credentials: "include",
|
|
177
|
+
headers: {
|
|
178
|
+
"Content-Type": "application/json",
|
|
179
|
+
"x-loop-console-confirmation": token(),
|
|
180
|
+
},
|
|
181
|
+
body: JSON.stringify({ directoryPath, ...(name ? { name } : {}) }),
|
|
182
|
+
});
|
|
183
|
+
const body = (await res.json().catch(() => ({})));
|
|
184
|
+
if (!res.ok || !body.workspace) {
|
|
185
|
+
const message = describeWorkspaceAddError(res.status, body.error?.code, body.error?.message);
|
|
186
|
+
setState({ error: message });
|
|
187
|
+
return { ok: false, error: message };
|
|
188
|
+
}
|
|
189
|
+
await refresh();
|
|
190
|
+
setState({ workspaceId: body.workspace.workspaceId });
|
|
191
|
+
rememberWorkspaceId(body.workspace.workspaceId, storage);
|
|
192
|
+
return { ok: true, workspaceId: body.workspace.workspaceId };
|
|
193
|
+
}
|
|
194
|
+
catch (err) {
|
|
195
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
196
|
+
const display = `添加 Workspace 失败:${message}`;
|
|
197
|
+
setState({ error: display });
|
|
198
|
+
return { ok: false, error: display };
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
const pickWorkspaceDirectory = async () => {
|
|
202
|
+
setState({ error: null });
|
|
203
|
+
try {
|
|
204
|
+
const res = await fetchImpl(`${origin}/api/operator/v1/workspaces/pick`, {
|
|
205
|
+
method: "POST",
|
|
206
|
+
credentials: "include",
|
|
207
|
+
headers: {
|
|
208
|
+
"x-loop-console-confirmation": token(),
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
const body = (await res.json().catch(() => ({})));
|
|
212
|
+
if (!res.ok) {
|
|
213
|
+
const message = isMutationGateFailureCode(body.error?.code)
|
|
214
|
+
? describeMutationGateFailure(body.error?.code ?? "")
|
|
215
|
+
: (body.error?.message ?? `打开目录选择窗口失败(HTTP ${res.status})`);
|
|
216
|
+
setState({ error: message });
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
return typeof body.directoryPath === "string" && body.directoryPath.trim()
|
|
220
|
+
? body.directoryPath
|
|
221
|
+
: null;
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
225
|
+
setState({ error: `打开目录选择窗口失败:${message}` });
|
|
226
|
+
return null;
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
const removeWorkspace = async (targetId) => {
|
|
230
|
+
setState({ error: null });
|
|
231
|
+
try {
|
|
232
|
+
const res = await fetchImpl(`${origin}/api/operator/v1/workspaces/${encodeURIComponent(targetId)}`, {
|
|
233
|
+
method: "DELETE",
|
|
234
|
+
credentials: "include",
|
|
235
|
+
headers: {
|
|
236
|
+
"x-loop-console-confirmation": token(),
|
|
237
|
+
},
|
|
238
|
+
});
|
|
239
|
+
const body = (await res.json().catch(() => ({})));
|
|
240
|
+
if (!res.ok) {
|
|
241
|
+
const message = res.status === 404
|
|
242
|
+
? "Workspace 已不存在(可能已被移除),列表将刷新。"
|
|
243
|
+
: isMutationGateFailureCode(body.error?.code)
|
|
244
|
+
? describeMutationGateFailure(body.error?.code ?? "")
|
|
245
|
+
: (body.error?.message ?? `移除 Workspace 失败(HTTP ${res.status})`);
|
|
246
|
+
setState({ error: message });
|
|
247
|
+
await refresh();
|
|
248
|
+
return { ok: false, error: message };
|
|
249
|
+
}
|
|
250
|
+
await refresh();
|
|
251
|
+
// Soft remove keeps historical sessions; if the removed workspace was
|
|
252
|
+
// selected, switch to a remaining one (never a startup-workspace id —
|
|
253
|
+
// only visible registry entries are ever selected).
|
|
254
|
+
if (state.workspaceId === targetId) {
|
|
255
|
+
const nextId = state.workspaces[0]?.workspaceId ?? null;
|
|
256
|
+
setState({ workspaceId: nextId });
|
|
257
|
+
rememberWorkspaceId(nextId, storage);
|
|
258
|
+
}
|
|
259
|
+
return { ok: true };
|
|
260
|
+
}
|
|
261
|
+
catch (err) {
|
|
262
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
263
|
+
const display = `移除 Workspace 失败:${message}`;
|
|
264
|
+
setState({ error: display });
|
|
265
|
+
return { ok: false, error: display };
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
const reorderWorkspace = async (workspaceId, beforeWorkspaceId) => {
|
|
269
|
+
const previous = state.workspaces;
|
|
270
|
+
const source = previous.find((workspace) => workspace.workspaceId === workspaceId);
|
|
271
|
+
const anchor = beforeWorkspaceId
|
|
272
|
+
? previous.find((workspace) => workspace.workspaceId === beforeWorkspaceId)
|
|
273
|
+
: undefined;
|
|
274
|
+
if (!source || (beforeWorkspaceId && !anchor)) {
|
|
275
|
+
return { ok: false, error: "工作区顺序已变化,请稍后重试。" };
|
|
276
|
+
}
|
|
277
|
+
const optimistic = previous.filter((workspace) => workspace.workspaceId !== workspaceId);
|
|
278
|
+
const insertAt = beforeWorkspaceId
|
|
279
|
+
? optimistic.findIndex((workspace) => workspace.workspaceId === beforeWorkspaceId)
|
|
280
|
+
: optimistic.length;
|
|
281
|
+
optimistic.splice(insertAt, 0, source);
|
|
282
|
+
if (optimistic.every((workspace, index) => workspace.workspaceId === previous[index]?.workspaceId)) {
|
|
283
|
+
return { ok: true };
|
|
284
|
+
}
|
|
285
|
+
setState({ workspaces: optimistic, error: null });
|
|
286
|
+
try {
|
|
287
|
+
const res = await fetchImpl(`${origin}/api/operator/v1/workspaces/${encodeURIComponent(workspaceId)}`, {
|
|
288
|
+
method: "PATCH",
|
|
289
|
+
credentials: "include",
|
|
290
|
+
headers: {
|
|
291
|
+
"Content-Type": "application/json",
|
|
292
|
+
"x-loop-console-confirmation": token(),
|
|
293
|
+
},
|
|
294
|
+
body: JSON.stringify({ beforeWorkspaceId }),
|
|
295
|
+
});
|
|
296
|
+
const body = (await res.json().catch(() => ({})));
|
|
297
|
+
if (!res.ok) {
|
|
298
|
+
const message = isMutationGateFailureCode(body.error?.code)
|
|
299
|
+
? describeMutationGateFailure(body.error?.code ?? "")
|
|
300
|
+
: (body.error?.message ?? `调整 Workspace 顺序失败(HTTP ${res.status})`);
|
|
301
|
+
setState({ workspaces: previous, error: message });
|
|
302
|
+
void refresh();
|
|
303
|
+
return { ok: false, error: message };
|
|
304
|
+
}
|
|
305
|
+
return { ok: true };
|
|
306
|
+
}
|
|
307
|
+
catch (error) {
|
|
308
|
+
const message = `调整 Workspace 顺序失败:${error instanceof Error ? error.message : String(error)}`;
|
|
309
|
+
setState({ workspaces: previous, error: message });
|
|
310
|
+
void refresh();
|
|
311
|
+
return { ok: false, error: message };
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
const selectWorkspace = (next) => {
|
|
315
|
+
if (next === state.workspaceId && !state.unknownWorkspaceId)
|
|
316
|
+
return;
|
|
317
|
+
setState({ workspaceId: next, unknownWorkspaceId: null });
|
|
318
|
+
rememberWorkspaceId(next, storage);
|
|
319
|
+
};
|
|
320
|
+
const dispose = () => {
|
|
321
|
+
if (disposed)
|
|
322
|
+
return;
|
|
323
|
+
disposed = true;
|
|
324
|
+
eventStream?.close();
|
|
325
|
+
eventStream = undefined;
|
|
326
|
+
listeners.clear();
|
|
327
|
+
};
|
|
328
|
+
void refresh();
|
|
329
|
+
return {
|
|
330
|
+
get workspaces() {
|
|
331
|
+
return state.workspaces;
|
|
332
|
+
},
|
|
333
|
+
get loading() {
|
|
334
|
+
return state.loading;
|
|
335
|
+
},
|
|
336
|
+
get error() {
|
|
337
|
+
return state.error;
|
|
338
|
+
},
|
|
339
|
+
get workspaceId() {
|
|
340
|
+
return state.workspaceId;
|
|
341
|
+
},
|
|
342
|
+
get unknownWorkspaceId() {
|
|
343
|
+
return state.unknownWorkspaceId;
|
|
344
|
+
},
|
|
345
|
+
refresh,
|
|
346
|
+
pickWorkspaceDirectory,
|
|
347
|
+
addWorkspace,
|
|
348
|
+
removeWorkspace,
|
|
349
|
+
reorderWorkspace,
|
|
350
|
+
selectWorkspace,
|
|
351
|
+
dispose,
|
|
352
|
+
subscribe(listener) {
|
|
353
|
+
listeners.add(listener);
|
|
354
|
+
startEventStream();
|
|
355
|
+
return () => {
|
|
356
|
+
listeners.delete(listener);
|
|
357
|
+
if (listeners.size === 0) {
|
|
358
|
+
eventStream?.close();
|
|
359
|
+
eventStream = undefined;
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
},
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
/** React binding: one controller per mount, state mirrored into useState. */
|
|
366
|
+
export function useWorkspaces(params) {
|
|
367
|
+
const controllerRef = useRef(null);
|
|
368
|
+
if (!controllerRef.current) {
|
|
369
|
+
controllerRef.current = createWorkspacesController(params);
|
|
370
|
+
}
|
|
371
|
+
const controller = controllerRef.current;
|
|
372
|
+
const [state, setState] = useState(() => ({
|
|
373
|
+
workspaces: controller.workspaces,
|
|
374
|
+
loading: controller.loading,
|
|
375
|
+
error: controller.error,
|
|
376
|
+
workspaceId: controller.workspaceId,
|
|
377
|
+
unknownWorkspaceId: controller.unknownWorkspaceId,
|
|
378
|
+
}));
|
|
379
|
+
useEffect(() => {
|
|
380
|
+
const unsubscribe = controller.subscribe(() => {
|
|
381
|
+
setState({
|
|
382
|
+
workspaces: controller.workspaces,
|
|
383
|
+
loading: controller.loading,
|
|
384
|
+
error: controller.error,
|
|
385
|
+
workspaceId: controller.workspaceId,
|
|
386
|
+
unknownWorkspaceId: controller.unknownWorkspaceId,
|
|
387
|
+
});
|
|
388
|
+
});
|
|
389
|
+
return unsubscribe;
|
|
390
|
+
}, [controller]);
|
|
391
|
+
return useMemo(() => ({
|
|
392
|
+
get workspaces() {
|
|
393
|
+
return state.workspaces;
|
|
394
|
+
},
|
|
395
|
+
get loading() {
|
|
396
|
+
return state.loading;
|
|
397
|
+
},
|
|
398
|
+
get error() {
|
|
399
|
+
return state.error;
|
|
400
|
+
},
|
|
401
|
+
get workspaceId() {
|
|
402
|
+
return state.workspaceId;
|
|
403
|
+
},
|
|
404
|
+
get unknownWorkspaceId() {
|
|
405
|
+
return state.unknownWorkspaceId;
|
|
406
|
+
},
|
|
407
|
+
refresh: controller.refresh,
|
|
408
|
+
pickWorkspaceDirectory: controller.pickWorkspaceDirectory,
|
|
409
|
+
addWorkspace: controller.addWorkspace,
|
|
410
|
+
removeWorkspace: controller.removeWorkspace,
|
|
411
|
+
reorderWorkspace: controller.reorderWorkspace,
|
|
412
|
+
selectWorkspace: controller.selectWorkspace,
|
|
413
|
+
dispose: controller.dispose,
|
|
414
|
+
}), [state, controller]);
|
|
415
|
+
}
|