@tea-agent/loop-agent 0.1.0-fe-test.4 → 0.1.0-fe-test.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +1 -1
- package/CHANGELOG.md +442 -2524
- package/README.md +19 -12
- package/dist/adapters/loop-agent.js +34 -0
- package/dist/application/dag/args.js +8 -0
- package/dist/application/dag/run-dag.js +5 -0
- package/dist/application/evaluation/budget.js +40 -1
- package/dist/application/evaluation/corpus-hash.js +10 -15
- package/dist/application/evaluation/corpus.js +2 -1
- package/dist/application/evaluation/frontend-browser-acceptance.js +77 -0
- package/dist/application/evaluation/frontend-corpus-browser-acceptance.js +175 -0
- package/dist/application/evaluation/frontend-gateway-evidence.js +226 -0
- package/dist/application/evaluation/frontend-pair-registration.js +143 -0
- package/dist/application/evaluation/frontend-paired-summary.js +150 -0
- package/dist/application/evaluation/frontend-run-observation.js +144 -0
- package/dist/application/evaluation/frontend-shared-evidence.js +105 -0
- package/dist/application/evaluation/types.js +45 -12
- package/dist/application/task-lifecycle/advance.js +64 -15
- package/dist/application/task-lifecycle/observe.js +69 -30
- package/dist/application/task-lifecycle/plan-transitions.js +5 -4
- package/dist/build-stamp.json +3 -3
- package/dist/cli/command-definitions.js +18 -5
- package/dist/cli/program.js +8 -5
- package/dist/cli/update/init-surface-notifier.js +2 -0
- package/dist/cli/update/policy.js +2 -0
- package/dist/commands/client-recovery.js +20 -55
- package/dist/commands/cursor-prompt.js +2 -0
- package/dist/commands/dag-approve.js +2 -0
- package/dist/commands/dag-final-verification.js +2 -0
- package/dist/commands/dag-init-hybrid.js +2 -0
- package/dist/commands/dag-reconcile-tasks.js +2 -0
- package/dist/commands/dag-reject.js +2 -0
- package/dist/commands/dag-report.js +2 -0
- package/dist/commands/dag-rerun.js +2 -0
- package/dist/commands/dag-resume.js +2 -0
- package/dist/commands/dag-workflow-compile.js +2 -0
- package/dist/commands/dag-workflow-plan.js +2 -0
- package/dist/commands/dag-workflow-validate.js +2 -0
- package/dist/commands/delegate.js +2 -0
- package/dist/commands/examples.js +2 -0
- package/dist/commands/import-prd.js +2 -0
- package/dist/commands/init-legacy-audit.js +330 -0
- package/dist/commands/init-model-catalog.js +2 -0
- package/dist/commands/init-upgrade.js +644 -104
- package/dist/commands/init.js +700 -338
- package/dist/commands/instructions.js +2 -0
- package/dist/commands/knowledge.js +2 -0
- package/dist/commands/loop-benchmark.js +2 -0
- package/dist/commands/operator-guide.js +99 -0
- package/dist/commands/operator.js +16 -3
- package/dist/commands/pi-prompt.js +2 -0
- package/dist/commands/pi-reuse-benchmark.js +2 -0
- package/dist/commands/promote-run.js +2 -0
- package/dist/commands/stats.js +1 -1
- package/dist/commands/study-init.js +2 -0
- package/dist/commands/task-advance.js +32 -0
- package/dist/commands/task-source-prepare.js +18 -2
- package/dist/commands/worktree-create.js +2 -0
- package/dist/commands/worktree-remove.js +2 -0
- package/dist/executors/dag-pi/guards.js +4 -0
- package/dist/executors/dag-pi/model-config.js +30 -0
- package/dist/executors/dag-pi/plan/fact-adoption.js +55 -0
- package/dist/executors/dag-pi/plan/facts.js +180 -0
- package/dist/executors/dag-pi/plan/finalize-tools.js +259 -0
- package/dist/executors/dag-pi/plan/ledger-contract.js +55 -0
- package/dist/executors/dag-pi/plan/record-tools.js +861 -0
- package/dist/executors/dag-pi/plan/schema.js +129 -0
- package/dist/executors/dag-pi/plan/tool-helpers.js +16 -0
- package/dist/executors/dag-pi/sessions/index.js +6 -0
- package/dist/executors/dag-pi/sessions/plan-batches.js +280 -0
- package/dist/executors/dag-pi/sessions/plan-prompts.js +367 -0
- package/dist/executors/dag-pi/sessions/scout-parallel.js +197 -0
- package/dist/executors/dag-pi/sessions/segmented-plan.js +1184 -0
- package/dist/executors/dag-pi/sessions/writer-evidence.js +60 -0
- package/dist/executors/dag-pi/tools/contract-tools.js +515 -0
- package/dist/executors/dag-pi/tools/design-terminal-tools.js +159 -0
- package/dist/executors/dag-pi/tools/plan-decision-tools.js +529 -0
- package/dist/executors/dag-pi/tools/review-terminal-tools.js +159 -0
- package/dist/executors/dag-pi/tools/scout-evidence-tools.js +270 -0
- package/dist/executors/dag-pi-executor.js +1517 -3180
- package/dist/executors/pi-executor.js +112 -4
- package/dist/executors/pi-sdk-executor.js +258 -44
- package/dist/executors/pi-writer-tool-policy.js +60 -4
- package/dist/executors/playwright-cli-launcher.js +31 -45
- package/dist/executors/shell-executor.js +358 -48
- package/dist/executors/shell-presets.js +1 -1
- package/dist/executors/shell-verification.js +3 -0
- package/dist/executors/shell-write-guard.js +77 -102
- package/dist/governance/exec-plans.js +16 -4
- package/dist/governance/harness.js +2 -7
- package/dist/governance/manifest-types.js +28 -9
- package/dist/governance/project-capability-scanner.js +263 -0
- package/dist/governance/project-config.js +96 -0
- package/dist/governance/resource-catalog.js +151 -0
- package/dist/infrastructure/console/app-data.js +12 -2
- package/dist/infrastructure/console/operation-store.js +48 -14
- package/dist/infrastructure/evaluation/corpus-store.js +37 -12
- package/dist/shared/artifacts-core.js +2 -0
- package/dist/shared/backend-dogfood-preflight.js +47 -0
- package/dist/shared/dag-failure-category.js +9 -0
- package/dist/shared/file-identity.js +23 -0
- package/dist/shared/frontend-execution-policy.js +23 -0
- package/dist/shared/git-progress.js +2 -0
- package/dist/shared/git-workspace-status.js +482 -0
- package/dist/shared/one-shot-prompt-args.js +2 -0
- package/dist/shared/operator/capabilities.js +185 -0
- package/dist/shared/package-metadata.js +29 -11
- package/dist/shared/path-safety.js +2 -2
- package/dist/shared/pi-context-pressure/extension.js +49 -16
- package/dist/shared/pi-context-pressure/index.js +1 -0
- package/dist/shared/pi-context-pressure/sift-bridge.js +1 -1
- package/dist/shared/pi-context-pressure/telemetry.js +4 -0
- package/dist/shared/pi-context-pressure/tool-result-pruner.js +98 -0
- package/dist/shared/pi-provider-recovery.js +182 -0
- package/dist/shared/pi-retry-settings.js +40 -0
- package/dist/shared/reference-context.js +2 -0
- package/dist/shared/update/npm-client.js +49 -1
- package/dist/shared/wizard-local-telemetry.js +51 -0
- package/dist/task/config-types.js +51 -2
- package/dist/task/contract/apply.js +36 -2
- package/dist/task/contract/project.js +22 -0
- package/dist/task/contract/recover.js +6 -0
- package/dist/task/contract/schema.js +12 -0
- package/dist/task/frontend-preflight.js +1 -1
- package/dist/task/source-prepare/artifact-meta.js +9 -2
- package/dist/task/source-prepare/build-draft.js +61 -0
- package/dist/task/source-prepare/fragment-inventory.js +4 -1
- package/dist/task/source-prepare/ledger-reconciliation.js +2 -2
- package/dist/task/source-prepare/ledger-review.js +6 -9
- package/dist/task/source-prepare/parse-intent.js +165 -14
- package/dist/task/source-prepare/path-policy.js +17 -7
- package/dist/task/source-prepare/prepare.js +6 -1
- package/dist/task/source-prepare/semantic-intake.js +33 -28
- package/dist/task/source-prepare/source-execution.js +65 -0
- package/dist/task/source-prepare/source-fidelity-pi.js +49 -17
- package/dist/task/source-prepare/source-provider-budget.js +290 -0
- package/dist/task/source-references.js +48 -23
- package/dist/task/task-demand-routing.js +5 -2
- package/dist/worker/cli.js +3 -5
- package/dist/worker/console/chat/assistant-content.js +5 -13
- package/dist/worker/console/chat/browser-automation.js +937 -0
- package/dist/worker/console/chat/browser-content.js +74 -0
- package/dist/worker/console/chat/browser-diagnostics.js +250 -0
- package/dist/worker/console/chat/browser-evaluation.js +58 -0
- package/dist/worker/console/chat/browser-operation-queue.js +19 -0
- package/dist/worker/console/chat/browser-pick.js +113 -0
- package/dist/worker/console/chat/browser-policy.js +113 -0
- package/dist/worker/console/chat/browser-routes.js +329 -0
- package/dist/worker/console/chat/browser-screenshot-result.js +47 -0
- package/dist/worker/console/chat/browser-storage.js +89 -0
- package/dist/worker/console/chat/chat-event-store.js +73 -18
- package/dist/worker/console/chat/context-insights.js +788 -0
- package/dist/worker/console/chat/conversation-nodes.js +383 -0
- package/dist/worker/console/chat/db-connections.js +854 -0
- package/dist/worker/console/chat/explore-tools.js +18 -2
- package/dist/worker/console/chat/pet/pet-affinity.js +169 -0
- package/dist/worker/console/chat/pet/pet-persist.js +109 -0
- package/dist/worker/console/chat/pet/pet-registry.js +142 -0
- package/dist/worker/console/chat/pet/pet-remarks.js +48 -0
- package/dist/worker/console/chat/pet/pet-routes.js +125 -0
- package/dist/worker/console/chat/pet/pet-service.js +262 -0
- package/dist/worker/console/chat/pet/pet-state.js +99 -0
- package/dist/worker/console/chat/pi-mode-loop-isolation.js +170 -0
- package/dist/worker/console/chat/pi-runtime/custom-tools/ask-user-question.js +44 -0
- package/dist/worker/console/chat/pi-runtime/custom-tools/browser-tools.js +135 -0
- package/dist/worker/console/chat/pi-runtime/custom-tools/explore-tools.js +202 -0
- package/dist/worker/console/chat/pi-runtime/custom-tools/goal-tools.js +79 -0
- package/dist/worker/console/chat/pi-runtime/custom-tools/operator-tools.js +94 -0
- package/dist/worker/console/chat/pi-runtime/custom-tools/scheduled-goal-tools.js +22 -0
- package/dist/worker/console/chat/pi-runtime/custom-tools/sql-tools.js +670 -0
- package/dist/worker/console/chat/pi-runtime/custom-tools/todo-write.js +38 -0
- package/dist/worker/console/chat/pi-runtime/inspection-types.js +28 -0
- package/dist/worker/console/chat/pi-runtime/inspection.js +439 -0
- package/dist/worker/console/chat/pi-runtime/progressive-tools.js +195 -0
- package/dist/worker/console/chat/pi-runtime/sdk-bindings.js +153 -0
- package/dist/worker/console/chat/pi-runtime/sdk-session.js +5 -0
- package/dist/worker/console/chat/pi-runtime.js +793 -1230
- package/dist/worker/console/chat/provider-error.js +0 -12
- package/dist/worker/console/chat/repo-browser.js +132 -6
- package/dist/worker/console/chat/repo-preview-kind.js +155 -0
- package/dist/worker/console/chat/resource-loader.js +4 -1
- package/dist/worker/console/chat/routes.js +861 -148
- package/dist/worker/console/chat/scheduled-goal-booking.js +59 -0
- package/dist/worker/console/chat/scheduled-goal-delivery.js +27 -0
- package/dist/worker/console/chat/scheduled-goal-request.js +198 -0
- package/dist/worker/console/chat/scm-routes.js +217 -0
- package/dist/worker/console/chat/scm-service.js +283 -0
- package/dist/worker/console/chat/scm-tools.js +111 -0
- package/dist/worker/console/chat/sdd-data-alignment.js +85 -41
- package/dist/worker/console/chat/session-catalog.js +32 -0
- package/dist/worker/console/chat/session-mode-view.js +49 -0
- package/dist/worker/console/chat/session-mode.js +224 -0
- package/dist/worker/console/chat/session-store.js +232 -32
- package/dist/worker/console/chat/shortcuts.js +13 -0
- package/dist/worker/console/chat/subagents/agent-tool.js +62 -0
- package/dist/worker/console/chat/subagents/explore-agent.js +169 -0
- package/dist/worker/console/chat/subagents/index.js +5 -0
- package/dist/worker/console/chat/subagents/orchestrator.js +273 -0
- package/dist/worker/console/chat/subagents/tool-policy.js +53 -0
- package/dist/worker/console/chat/subagents/types.js +13 -0
- package/dist/worker/console/chat/terminal-routes.js +216 -0
- package/dist/worker/console/chat/terminal-sessions.js +348 -0
- package/dist/worker/console/chat/terminal-tools.js +211 -0
- package/dist/worker/console/chat/timeline-message-order.js +22 -0
- package/dist/worker/console/chat/tool-preview.js +136 -0
- package/dist/worker/console/chat/tools.js +69 -1
- package/dist/worker/console/chat/turn-order.js +13 -0
- package/dist/worker/console/chat/turn-process.js +210 -36
- package/dist/worker/console/chat/user-turn-outline.js +19 -0
- package/dist/worker/console/console-shutdown.js +34 -0
- package/dist/worker/console/console-update-and-init.js +1 -19
- package/dist/worker/console/console-update-runtime.js +7 -22
- package/dist/worker/console/dag-confirmation.js +3 -0
- package/dist/worker/console/dag-execution-receipt.js +3 -0
- package/dist/worker/console/interview/tools.js +1 -0
- package/dist/worker/console/operator-actions.js +95 -4
- package/dist/worker/console/operator-user-error.js +28 -1
- package/dist/worker/console/pi-readiness.js +4 -4
- package/dist/worker/console/prd-intake-bridge.js +47 -1
- package/dist/worker/console/recovery-cta.js +14 -14
- package/dist/worker/console/routes.js +13 -0
- package/dist/worker/console/scheduled-goal-host.js +98 -0
- package/dist/worker/console/scheduled-goal-operation-adapter.js +127 -0
- package/dist/worker/console/server.js +33 -31
- package/dist/worker/console/static/app-icon.svg +39 -0
- package/dist/worker/console/static/assets/{abnfDiagram-N423BO3Z-BZogYNl1.js → abnfDiagram-N423BO3Z-DASc69AM.js} +1 -1
- package/dist/worker/console/static/assets/{arc-DcJTLe2v.js → arc-h09p-LAc.js} +1 -1
- package/dist/worker/console/static/assets/{architectureDiagram-T3A2C74G-B39EQQ9n.js → architectureDiagram-T3A2C74G-CZ3dtLkh.js} +1 -1
- package/dist/worker/console/static/assets/{blockDiagram-VBNYF7ZC-CitCGV56.js → blockDiagram-VBNYF7ZC-DMrRhMXG.js} +1 -1
- package/dist/worker/console/static/assets/{c4Diagram-5PPSVZJV-rvWuOHLG.js → c4Diagram-5PPSVZJV-DQxisHV6.js} +1 -1
- package/dist/worker/console/static/assets/channel-D1zgKZfg.js +1 -0
- package/dist/worker/console/static/assets/{chunk-2GRJ4B5K-DGXplIJs.js → chunk-2GRJ4B5K-CefVN9zh.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-2Q5K7J3B-ur9OqjPn.js → chunk-2Q5K7J3B-DmR1Koq2.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-5RXB4S5H-D1KqU_Vi.js → chunk-5RXB4S5H-NlzrSW7L.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-5VM5RSS4-BlVZrbtM.js → chunk-5VM5RSS4-DfelJv-0.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-6Q2QTUOP-BAzz3nQy.js → chunk-6Q2QTUOP-BK6RFy58.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-GF5L2VYU-CP_nYuCV.js → chunk-GF5L2VYU-BAeh9lz4.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-JWPE2WC7-CWvKQ80X.js → chunk-JWPE2WC7-ChPS5WzG.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-KBJHAD2P-CyUki8wp.js → chunk-KBJHAD2P-BoVe5IM6.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-RYQCIY6F-5NYzNKfY.js → chunk-RYQCIY6F-C4q_0Lw9.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-XXDRQBXY-DHdUgjS-.js → chunk-XXDRQBXY-Bb9TvjeY.js} +1 -1
- package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-CXNNsY2M.js +1 -0
- package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-CXNNsY2M.js +1 -0
- package/dist/worker/console/static/assets/{cose-bilkent-JH36ORCC-ANQ5g_t6.js → cose-bilkent-JH36ORCC-DmNnL8Ff.js} +1 -1
- package/dist/worker/console/static/assets/{cynefin-VYW2F7L2-CruT_4-0.js → cynefin-VYW2F7L2-Contvx58.js} +1 -1
- package/dist/worker/console/static/assets/{cynefinDiagram-MW4NZA55-rbFo77ID.js → cynefinDiagram-MW4NZA55-Cigq7cjk.js} +1 -1
- package/dist/worker/console/static/assets/{dagre-VZM6K2ZE-asstxBQs.js → dagre-VZM6K2ZE-dEbC0nxb.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-7IWD3JNH-DzTyBZwI.js → diagram-7IWD3JNH-CzIztESV.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-B4RE2ZJO-gw8ccH3B.js → diagram-B4RE2ZJO-Bo14zbaY.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-LBJQPF4R-B8RpZzOf.js → diagram-LBJQPF4R-C4xUyil6.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-Q27KOJAE-B1zJkCS9.js → diagram-Q27KOJAE-CaBY_uYa.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-UB23O5K3-B6JLWZmO.js → diagram-UB23O5K3-ClUXUeiu.js} +1 -1
- package/dist/worker/console/static/assets/{ebnfDiagram-BXEA7PRR-q2iZP-Ps.js → ebnfDiagram-BXEA7PRR-BbGCgjC6.js} +1 -1
- package/dist/worker/console/static/assets/{erDiagram-JOGREHBK-B3dbbktQ.js → erDiagram-JOGREHBK-Dr-AcwSl.js} +1 -1
- package/dist/worker/console/static/assets/{flowDiagram-UKHOOZJN-C-zc6-kB.js → flowDiagram-UKHOOZJN-BG8Gcfyc.js} +1 -1
- package/dist/worker/console/static/assets/{ganttDiagram-PKOTCBZU-BSolnot9.js → ganttDiagram-PKOTCBZU-CFVaPs5r.js} +1 -1
- package/dist/worker/console/static/assets/{gitGraphDiagram-DS77QQ5N-Bo8jGxTk.js → gitGraphDiagram-DS77QQ5N-ChJ8pm-O.js} +1 -1
- package/dist/worker/console/static/assets/index-B_5GhVIO.js +488 -0
- package/dist/worker/console/static/assets/index-C7YMBluX.css +1 -0
- package/dist/worker/console/static/assets/{infoDiagram-6WML65LV-DQaZqJOH.js → infoDiagram-6WML65LV-C5J9-uCZ.js} +1 -1
- package/dist/worker/console/static/assets/{ishikawaDiagram-WSZJBQD7-DsdX1WnE.js → ishikawaDiagram-WSZJBQD7-BcfjqzDv.js} +1 -1
- package/dist/worker/console/static/assets/{journeyDiagram-NVQOT4AX-CP5EYDZL.js → journeyDiagram-NVQOT4AX-BzzCO-rD.js} +1 -1
- package/dist/worker/console/static/assets/{kanban-definition-27J2QSJJ-DAm14Dr8.js → kanban-definition-27J2QSJJ-NCHUZ46h.js} +1 -1
- package/dist/worker/console/static/assets/{linear-gZECoLc5.js → linear-BKZlWCUU.js} +1 -1
- package/dist/worker/console/static/assets/{mermaid.core-BRJNIM6p.js → mermaid.core-DbTaQjFE.js} +5 -5
- package/dist/worker/console/static/assets/{mindmap-definition-FAOFIHXS-Cja3kLkR.js → mindmap-definition-FAOFIHXS-CroYl5xQ.js} +1 -1
- package/dist/worker/console/static/assets/{pegDiagram-VL7TDLO6-22ZGFisL.js → pegDiagram-VL7TDLO6-DgMBx-9k.js} +1 -1
- package/dist/worker/console/static/assets/{pieDiagram-7S7Q4E2Y-BXin0Y1o.js → pieDiagram-7S7Q4E2Y-CyWDmbq1.js} +1 -1
- package/dist/worker/console/static/assets/{quadrantDiagram-CIZ2JOQS-Cw6T69Yt.js → quadrantDiagram-CIZ2JOQS-BgGEOqSP.js} +1 -1
- package/dist/worker/console/static/assets/{railroadDiagram-AXF67PYL-C1-gTieN.js → railroadDiagram-AXF67PYL-BMZ7oeeV.js} +1 -1
- package/dist/worker/console/static/assets/{requirementDiagram-LRYGKXZP--H5N2iI1.js → requirementDiagram-LRYGKXZP-DxqyGhcc.js} +1 -1
- package/dist/worker/console/static/assets/{sankeyDiagram-W5VNT64P-CgWAPeRz.js → sankeyDiagram-W5VNT64P-DnSvNCG8.js} +1 -1
- package/dist/worker/console/static/assets/{sequenceDiagram-SI44F4Z6-CrKqzGvt.js → sequenceDiagram-SI44F4Z6-BiZh6f-R.js} +1 -1
- package/dist/worker/console/static/assets/{sizeCapture-X5ZJPWSS-BB3wG06K.js → sizeCapture-X5ZJPWSS-BKXSI8WB.js} +1 -1
- package/dist/worker/console/static/assets/{stateDiagram-OKZ733FA-DjsGgdgY.js → stateDiagram-OKZ733FA-CfSgoYFm.js} +1 -1
- package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-DgHi3vjb.js +1 -0
- package/dist/worker/console/static/assets/{swimlanes-SLNWSIFB-DYKEbvAR.js → swimlanes-SLNWSIFB-CyGADcHe.js} +2 -2
- package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-Bgvdt1Y0.js +8 -0
- package/dist/worker/console/static/assets/{timeline-definition-Z64GVDOM-eQOb5k9Y.js → timeline-definition-Z64GVDOM-HmPaSPOK.js} +1 -1
- package/dist/worker/console/static/assets/{vennDiagram-T6HMQDX7-B2-l9FIu.js → vennDiagram-T6HMQDX7-VA2VBbez.js} +1 -1
- package/dist/worker/console/static/assets/{wardleyDiagram-T6FBY63Y-BX2Cda3l.js → wardleyDiagram-T6FBY63Y-BxjiBPZa.js} +1 -1
- package/dist/worker/console/static/assets/{xychartDiagram-ELKLHX3M-D9S892ph.js → xychartDiagram-ELKLHX3M--hUY-qFj.js} +1 -1
- package/dist/worker/console/static/index.html +5 -2
- package/dist/worker/console/static/manifest.webmanifest +19 -0
- package/dist/worker/console/static/pets/ember/pet.json +167 -0
- package/dist/worker/console/static/pets/ember/spritesheet.png +0 -0
- package/dist/worker/console/static-src/app/console-types.js +9 -1
- package/dist/worker/console/static-src/chat-view-types.js +1 -1
- package/dist/worker/console/static-src/operator-chat/active-turn-tail.js +10 -0
- package/dist/worker/console/static-src/operator-chat/animation-frame-batcher.js +38 -0
- package/dist/worker/console/static-src/operator-chat/chat-link.js +114 -0
- package/dist/worker/console/static-src/operator-chat/chat-scroll-position.js +24 -0
- package/dist/worker/console/static-src/operator-chat/chat-sse-events.js +360 -14
- package/dist/worker/console/static-src/operator-chat/chat-stream-continuity.js +101 -0
- package/dist/worker/console/static-src/operator-chat/compaction-message.js +10 -2
- package/dist/worker/console/static-src/operator-chat/composer-session-ledger.js +192 -0
- package/dist/worker/console/static-src/operator-chat/context-insights-store.js +64 -0
- package/dist/worker/console/static-src/operator-chat/details-rail-surfaces.js +99 -0
- package/dist/worker/console/static-src/operator-chat/file-palette-nav.js +81 -0
- package/dist/worker/console/static-src/operator-chat/open-preview-in-browser.js +57 -9
- package/dist/worker/console/static-src/operator-chat/pending-user-message.js +66 -0
- package/dist/worker/console/static-src/operator-chat/process-label.js +63 -0
- package/dist/worker/console/static-src/operator-chat/slash-palette-nav.js +15 -5
- package/dist/worker/console/static-src/operator-chat/timeline-merge.js +29 -0
- package/dist/worker/console/static-src/operator-chat/tools-catalog.js +36 -8
- package/dist/worker/console/static-src/operator-chat/transcript-mode.js +21 -0
- package/dist/worker/console/static-src/operator-chat/turn-group-equality.js +16 -0
- package/dist/worker/console/static-src/operator-chat/turn-process-disclosure.js +18 -0
- package/dist/worker/console/static-src/operator-chat/turn-state-projection.js +166 -0
- package/dist/worker/console/static-src/operator-chat/turn-stream-controller.js +58 -2
- package/dist/worker/console/static-src/operator-chat/use-searchable-hidden.js +51 -0
- package/dist/worker/console/static-src/operator-chat/use-stat-dialog.js +95 -0
- package/dist/worker/console/static-src/operator-chat/useChatSessions.js +338 -93
- package/dist/worker/console/static-src/operator-chat/useChatStream.js +310 -106
- package/dist/worker/console/static-src/operator-chat/useChatThread.js +179 -75
- package/dist/worker/console/static-src/operator-chat/useComposer.js +281 -79
- package/dist/worker/console/static-src/operator-chat/useRepoBrowser.js +21 -3
- package/dist/worker/console/static-src/operator-chat/useRuntimeControls.js +36 -17
- package/dist/worker/console/static-src/operator-chat/useRuntimeSnapshot.js +18 -0
- package/dist/worker/console/static-src/operator-chat/useWorkspaceBrowserGate.js +4 -0
- package/dist/worker/console/static-src/operator-chat/user-turn-anchor-equality.js +21 -0
- package/dist/worker/console/static-src/prd-file-import.js +3 -1
- package/dist/worker/console/static-src/shell/console-update-reload.js +1 -1
- package/dist/worker/console/workspace-context.js +54 -1
- package/dist/worker/console/workspace-initialization.js +218 -0
- package/dist/worker/delivery/git-transaction.js +2 -0
- package/dist/worker/delivery/package.js +4 -1
- package/dist/worker/feature/fullstack-validate.js +2 -0
- package/dist/worker/loop-agent/loop-agent-client.js +8 -2
- package/dist/worker/materialize/harness-task-lineage.js +4 -2
- package/dist/worker/materialize/harness-task-materializer.js +4 -1
- package/dist/worker/metrics/projector.js +1 -1
- package/dist/worker/observability/event-store.js +4 -1
- package/dist/worker/observability/read-model.js +27 -3
- package/dist/worker/observe/node-context-insights.js +479 -0
- package/dist/worker/observe/node-transparency.js +103 -72
- package/dist/worker/observe/routes.js +24 -1
- package/dist/worker/observe/static/console-theme.css +178 -0
- package/dist/worker/observe/static/console-theme.js +74 -0
- package/dist/worker/observe/static/dag-inspector-humanize.js +3 -0
- package/dist/worker/observe/static/dom.js +20 -1
- package/dist/worker/observe/static/format-pool.d.ts +2 -0
- package/dist/worker/observe/static/format-pool.js +6 -0
- package/dist/worker/observe/static/format.js +7 -0
- package/dist/worker/observe/static/inspect-workspace.js +34 -7
- package/dist/worker/observe/static/inspector-submission.js +32 -0
- package/dist/worker/observe/static/kpi.js +1 -0
- package/dist/worker/observe/static/operator-chrome.css +85 -0
- package/dist/worker/observe/static/operator-chrome.js +13 -1
- package/dist/worker/observe/static/relations.js +2 -0
- package/dist/worker/observe/static/router.js +13 -0
- package/dist/worker/observe/static/run-processing.js +2 -0
- package/dist/worker/observe/static/shell-chrome.js +36 -3
- package/dist/worker/observe/static/state.js +35 -2
- package/dist/worker/observe/static/styles.css +263 -39
- package/dist/worker/observe/static/task-failure-labels.d.ts +4 -0
- package/dist/worker/observe/static/task-failure-labels.js +67 -0
- package/dist/worker/observe/static/task-history.js +12 -0
- package/dist/worker/observe/static/views/batch.js +6 -13
- package/dist/worker/observe/static/views/dag-graph.js +50 -3
- package/dist/worker/observe/static/views/dag-inspector.js +742 -268
- package/dist/worker/observe/static/views/dag-trajectory.js +3 -0
- package/dist/worker/observe/static/views/dag.d.ts +6 -0
- package/dist/worker/observe/static/views/dag.js +49 -11
- package/dist/worker/observe/static/views/dags.js +2 -0
- package/dist/worker/observe/static/views/dashboard.js +21 -12
- package/dist/worker/observe/static/views/failures.js +21 -11
- package/dist/worker/observe/static/views/feature.js +11 -29
- package/dist/worker/observe/static/views/pool.js +37 -28
- package/dist/worker/observe/static/views/run.js +48 -5
- package/dist/worker/observe/static/views/session-timeline.js +189 -240
- package/dist/worker/observe/static/views/task.js +81 -62
- package/dist/worker/outcomes/declared-artifacts.js +2 -0
- package/dist/worker/preflight.js +3 -0
- package/dist/worker/scheduler/scheduled-goal-dispatch.js +118 -0
- package/dist/worker/scheduler/scheduled-goal-evidence.js +230 -0
- package/dist/worker/scheduler/scheduled-goal-recovery.js +62 -0
- package/dist/worker/scheduler/scheduled-goal-store.js +709 -0
- package/dist/worker/scheduler/scheduled-goal-supervisor.js +132 -0
- package/dist/worker/scheduler/scheduled-goal-time.js +102 -0
- package/dist/worker/scheduler/scheduled-goal-types.js +95 -0
- package/dist/worker/task-spec/validate.js +4 -1
- package/dist/workflows/dag/backend-test-case-coverage-analysis.js +3 -1
- package/dist/workflows/dag/backend-test-layout.js +27 -7
- package/dist/workflows/dag/backend-test-markdown-workflow.js +9 -25
- package/dist/workflows/dag/backend-test-plan-protocol.js +82 -5
- package/dist/workflows/dag/backend-test-pytest-collection.js +4 -1
- package/dist/workflows/dag/budget-enforcement.js +82 -3
- package/dist/workflows/dag/checkpoint.js +686 -0
- package/dist/workflows/dag/dag-retry-schema.js +14 -0
- package/dist/workflows/dag/decision-envelope.js +2 -0
- package/dist/workflows/dag/dynamic-runtime/map.js +15 -2
- package/dist/workflows/dag/dynamic-runtime/shared.js +2 -2
- package/dist/workflows/dag/final-verification.js +45 -10
- package/dist/workflows/dag/frontend-capacity.js +9 -0
- package/dist/workflows/dag/frontend-closeout.js +5 -1
- package/dist/workflows/dag/frontend-committed-facts.js +461 -0
- package/dist/workflows/dag/frontend-contract-facts.js +133 -0
- package/dist/workflows/dag/frontend-design-policy.js +107 -21
- package/dist/workflows/dag/frontend-durable-tools.js +225 -0
- package/dist/workflows/dag/frontend-execution-groups.js +24 -0
- package/dist/workflows/dag/frontend-implementation-contract.js +554 -26
- package/dist/workflows/dag/frontend-input-projection.js +76 -0
- package/dist/workflows/dag/frontend-plan-canary.js +103 -0
- package/dist/workflows/dag/frontend-plan-decision-contract.js +795 -0
- package/dist/workflows/dag/frontend-plan-progress.js +92 -0
- package/dist/workflows/dag/frontend-plan-recovery-policy.js +18 -0
- package/dist/workflows/dag/frontend-plan-render.js +21 -5
- package/dist/workflows/dag/frontend-provider-capability-matrix.js +8 -61
- package/dist/workflows/dag/frontend-recovery-controller.js +7 -7
- package/dist/workflows/dag/frontend-recovery-lineage.js +13 -0
- package/dist/workflows/dag/frontend-recovery-plan.js +10 -5
- package/dist/workflows/dag/frontend-recovery-run.js +148 -47
- package/dist/workflows/dag/frontend-repair-assertions.js +36 -0
- package/dist/workflows/dag/frontend-repair.js +79 -76
- package/dist/workflows/dag/frontend-review-context.js +71 -69
- package/dist/workflows/dag/frontend-review-scopes.js +237 -0
- package/dist/workflows/dag/frontend-risk.js +101 -12
- package/dist/workflows/dag/frontend-root-observation.js +261 -0
- package/dist/workflows/dag/frontend-session-budget.js +376 -0
- package/dist/workflows/dag/frontend-session-context.js +10 -0
- package/dist/workflows/dag/frontend-shape-facts.js +12 -2
- package/dist/workflows/dag/frontend-shape.js +27 -32
- package/dist/workflows/dag/frontend-test-case-checklist.js +14 -3
- package/dist/workflows/dag/frontend-test-case-generation-assessment.js +88 -0
- package/dist/workflows/dag/frontend-test-case-manifest.js +6 -1
- package/dist/workflows/dag/frontend-test-case-quality.js +3 -3
- package/dist/workflows/dag/frontend-test-environment-probe.js +0 -2
- package/dist/workflows/dag/frontend-test-execution-evidence.js +328 -0
- package/dist/workflows/dag/frontend-test-framework-adapters.js +309 -0
- package/dist/workflows/dag/frontend-test-layout.js +41 -12
- package/dist/workflows/dag/frontend-test-result-contract.js +15 -1
- package/dist/workflows/dag/frontend-typed-event-store.js +57 -26
- package/dist/workflows/dag/frontend-verification-trace.js +65 -48
- package/dist/workflows/dag/frontend-writer-admission.js +6 -48
- package/dist/workflows/dag/frontend-writer-status.js +0 -23
- package/dist/workflows/dag/hybrid/sources.js +1831 -0
- package/dist/workflows/dag/hybrid/templates/backend-test.js +1822 -0
- package/dist/workflows/dag/hybrid/templates/frontend-test.js +807 -0
- package/dist/workflows/dag/hybrid/templates/frontend.js +1529 -0
- package/dist/workflows/dag/hybrid/templates/index.js +8 -0
- package/dist/workflows/dag/hybrid/templates/kg-bootstrap.js +449 -0
- package/dist/workflows/dag/hybrid/templates/knowledge-sync.js +495 -0
- package/dist/workflows/dag/hybrid/templates/shared.js +101 -0
- package/dist/workflows/dag/hybrid/templates/standard.js +265 -0
- package/dist/workflows/dag/hybrid/types.js +32 -0
- package/dist/workflows/dag/init-hybrid.js +57 -7077
- package/dist/workflows/dag/interrupt-request.js +2 -0
- package/dist/workflows/dag/lifecycle.js +11 -2
- package/dist/workflows/dag/node-execution.js +257 -247
- package/dist/workflows/dag/output-protocol.js +1 -0
- package/dist/workflows/dag/prompt.js +4 -0
- package/dist/workflows/dag/reconcile-run.js +2 -0
- package/dist/workflows/dag/repair-artifact.js +3 -1
- package/dist/workflows/dag/report.js +2 -0
- package/dist/workflows/dag/rerun-feedback.js +36 -4
- package/dist/workflows/dag/rerun-plan.js +106 -4
- package/dist/workflows/dag/rerun-run.js +7 -0
- package/dist/workflows/dag/rerun-task.js +75 -1
- package/dist/workflows/dag/retry-policy.js +34 -10
- package/dist/workflows/dag/runner-exit-diagnostics.js +125 -0
- package/dist/workflows/dag/runner.js +38 -1074
- package/dist/workflows/dag/scheduler.js +2 -4
- package/dist/workflows/dag/skill-instructions.js +102 -32
- package/dist/workflows/dag/skill-snapshot.js +3 -0
- package/dist/workflows/dag/skills.js +7 -7
- package/dist/workflows/dag/structured-output-repair.js +4 -1
- package/dist/workflows/dag/terminal-status.js +502 -0
- package/dist/workflows/dag/test-artifact-namespace.js +73 -0
- package/dist/workflows/dag/types.js +79 -7
- package/dist/workflows/dag/validate.js +38 -13
- package/dist/workflows/dag/workspace-checkpoint.js +79 -1
- package/dist/workflows/loop/benchmark.js +11 -8
- package/docs/README.md +2 -1
- package/docs/architecture/dag-execution.md +4 -4
- package/docs/architecture/runtime-boundaries.md +29 -23
- package/docs/governance/README.md +1 -0
- package/docs/governance/harness-methodology-verification.md +11 -0
- package/docs/init-surface.manifest.json +44 -295
- package/docs/operations/README.md +4 -0
- package/docs/templates/README.md +5 -5
- package/docs/templates/agent-dag.base.json +9 -9
- package/docs/templates/agent-dag.final-verification.json +6 -6
- package/docs/templates/agent-dag.schema.json +2 -2
- package/docs/templates/agent-dag.supervised-implementation.json +12 -12
- package/docs/templates/backend-test-dag.generate-pytest.prompt.md +3 -3
- package/docs/templates/backend-test-dag.json +708 -703
- package/docs/templates/backend-test-dag.review-cases.prompt.md +3 -3
- package/docs/templates/frontend-design-contract.md +4 -4
- package/docs/templates/frontend-implementation-contract.schema.json +99 -22
- package/docs/templates/frontend-implementation-dag.json +7 -7
- package/docs/templates/frontend-test-case-checklist.md +2 -2
- package/docs/templates/frontend-test-case.example.md +2 -0
- package/docs/templates/frontend-test-dag.generate-cases.prompt.md +1 -1
- package/docs/templates/frontend-test-dag.json +48 -39
- package/docs/templates/frontend-test-dag.retrieve-context.prompt.md +2 -2
- package/docs/templates/frontend-test-dag.retrospect.prompt.md +1 -1
- package/docs/templates/frontend-test-dag.review-cases.prompt.md +1 -1
- package/docs/templates/hybrid-dag.json +9 -9
- package/docs/templates/knowledge-sync-dag.json +8 -8
- package/harness.json +1 -1
- package/package.json +27 -8
- package/resource-catalog.v1.json +1981 -0
- package/resources/agent-bridge/loop-agent/SKILL.md +40 -0
- package/resources/init-history/legacy-surface.v1.json +33 -0
- package/skills/fe-test-ui-scout/SKILL.md +4 -4
- package/skills/fe-test-ui-scout/references/ledger-schema.md +1 -1
- package/skills/frontend-bounded-implement/references/code-standards.md +3 -3
- package/skills/frontend-contract/SKILL.md +2 -1
- package/skills/frontend-contract/references/contract-protocol.md +22 -4
- package/skills/frontend-design-review/SKILL.md +16 -18
- package/skills/frontend-design-review/references/review-checklist.md +3 -4
- package/skills/frontend-plan/SKILL.md +25 -3
- package/skills/frontend-plan/references/decision-contract.md +117 -8
- package/skills/frontend-plan/references/design-decisions.md +32 -0
- package/skills/frontend-review/SKILL.md +29 -36
- package/skills/frontend-review/references/review-findings.md +8 -3
- package/skills/frontend-scout/references/scout-evidence.md +4 -0
- package/skills/init-update/SKILL.md +34 -0
- package/skills/init-update/agents/openai.yaml +6 -0
- package/skills/loop-agent/references/command-reference.md +8 -0
- package/skills/loop-agent/references/hybrid-dag.md +1 -1
- package/skills/playwright-cli/SKILL.md +1 -1
- package/skills/playwright-cli-case-generator/SKILL.md +7 -5
- package/dist/commands/new-task.js +0 -5
- package/dist/commands/status.js +0 -57
- package/dist/commands/task-contract.js +0 -269
- package/dist/shared/prompts.js +0 -26
- package/dist/task/config.js +0 -2
- package/dist/task/contract/validate-draft.js +0 -106
- package/dist/task/goal.js +0 -3
- package/dist/task/index.js +0 -12
- package/dist/task/lifecycle.js +0 -1
- package/dist/task/operator/capabilities.js +0 -6
- package/dist/task/operator/envelope.js +0 -2
- package/dist/task/operator/index.js +0 -5
- package/dist/task/operator/registry.js +0 -2
- package/dist/task/paths.js +0 -1
- package/dist/task/source-state.js +0 -1
- package/dist/task/subagent-guidance.js +0 -1
- package/dist/worker/console/chat/sift-bridge.js +0 -1
- package/dist/worker/console/index.js +0 -20
- package/dist/worker/console/static/assets/channel-CXqdP5pW.js +0 -1
- package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-D9C3agF7.js +0 -1
- package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-D9C3agF7.js +0 -1
- package/dist/worker/console/static/assets/index-CAZ2fC_X.css +0 -1
- package/dist/worker/console/static/assets/index-DhfjOafu.js +0 -449
- package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-Tp7V0U4q.js +0 -1
- package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-DUZWZWi8.js +0 -8
- package/dist/worker/scheduler/index.js +0 -25
- package/dist/workflows/dag/facts.js +0 -4
- package/dist/workflows/dag/frontend-shadow-dual-write.js +0 -941
- package/dist/workflows/dag/index.js +0 -6
- package/dist/workflows/dynamic/index.js +0 -7
- /package/dist/{task/operator/types.js → executors/dag-pi/plan/session.js} +0 -0
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP API for the workspace-controlled external browser. The sidebar iframe
|
|
3
|
+
* is an independent preview; these endpoints operate the Playwright page.
|
|
4
|
+
* `GET panel/frame` additionally serves passive screencast frames so the
|
|
5
|
+
* panel can mirror the shared window (same context, login state included).
|
|
6
|
+
*/
|
|
7
|
+
import { embeddabilityOf, extractFrameAncestors, normalizeBrowserUrl, } from "./browser-policy.js";
|
|
8
|
+
function workspaceIdOf(req) {
|
|
9
|
+
try {
|
|
10
|
+
return new URL(req.url ?? "/", "http://localhost").searchParams.get("workspaceId") ?? undefined;
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function sendJson(res, status, body) {
|
|
17
|
+
res.writeHead(status, {
|
|
18
|
+
"content-type": "application/json; charset=utf-8",
|
|
19
|
+
"cache-control": "no-store",
|
|
20
|
+
});
|
|
21
|
+
res.end(JSON.stringify(body));
|
|
22
|
+
}
|
|
23
|
+
function errorPayload(error) {
|
|
24
|
+
return {
|
|
25
|
+
code: error instanceof Error && "code" in error
|
|
26
|
+
? String(error.code)
|
|
27
|
+
: "BROWSER_OPERATION_FAILED",
|
|
28
|
+
message: error instanceof Error ? error.message : String(error),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function requireScope(req, deps) {
|
|
32
|
+
const ws = workspaceIdOf(req);
|
|
33
|
+
if (!ws) {
|
|
34
|
+
return { ok: false, status: 400, code: "WORKSPACE_REQUIRED", message: "workspaceId is required" };
|
|
35
|
+
}
|
|
36
|
+
if (deps.requireWorkspace && !deps.requireWorkspace(req).ok) {
|
|
37
|
+
return { ok: false, status: 403, code: "WORKSPACE_DENIED", message: "workspace scope mismatch" };
|
|
38
|
+
}
|
|
39
|
+
return { ok: true };
|
|
40
|
+
}
|
|
41
|
+
async function readJson(req) {
|
|
42
|
+
const chunks = [];
|
|
43
|
+
let size = 0;
|
|
44
|
+
for await (const chunk of req) {
|
|
45
|
+
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
46
|
+
size += buffer.byteLength;
|
|
47
|
+
if (size > 1024 * 1024)
|
|
48
|
+
throw new Error("request body exceeds 1MB");
|
|
49
|
+
chunks.push(buffer);
|
|
50
|
+
}
|
|
51
|
+
if (chunks.length === 0)
|
|
52
|
+
return {};
|
|
53
|
+
try {
|
|
54
|
+
const value = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
55
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
56
|
+
throw new Error("expected JSON object");
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
catch (cause) {
|
|
60
|
+
throw new Error("invalid browser request JSON object", { cause });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export async function handleBrowserRequest(req, res, deps, pathname) {
|
|
64
|
+
if (!pathname.startsWith("/api/operator/v1/chat/browser"))
|
|
65
|
+
return false;
|
|
66
|
+
const method = (req.method ?? "GET").toUpperCase();
|
|
67
|
+
const rest = pathname.slice("/api/operator/v1/chat/browser".length);
|
|
68
|
+
const parts = rest.split("/").filter(Boolean);
|
|
69
|
+
const sub = parts[0] ?? "";
|
|
70
|
+
try {
|
|
71
|
+
if (method === "GET" && sub === "screenshots" && parts.length === 2) {
|
|
72
|
+
const scope = requireScope(req, deps);
|
|
73
|
+
if (!scope.ok) {
|
|
74
|
+
sendJson(res, scope.status, { ok: false, error: { code: scope.code, message: scope.message } });
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
if (!deps.automation) {
|
|
78
|
+
sendJson(res, 503, { ok: false });
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
const bytes = await deps.automation.readScreenshot(parts[1] ?? "");
|
|
83
|
+
res.writeHead(200, { "content-type": "image/png", "cache-control": "no-store", "x-content-type-options": "nosniff" });
|
|
84
|
+
res.end(bytes);
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
sendJson(res, 404, { ok: false, error: { code: "SCREENSHOT_UNAVAILABLE", message: "screenshot unavailable" } });
|
|
88
|
+
}
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
if (method === "GET" && sub === "state" && parts.length === 1) {
|
|
92
|
+
const scope = requireScope(req, deps);
|
|
93
|
+
if (!scope.ok) {
|
|
94
|
+
sendJson(res, scope.status, {
|
|
95
|
+
ok: false,
|
|
96
|
+
error: { code: scope.code, message: scope.message },
|
|
97
|
+
});
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
if (!deps.automation) {
|
|
101
|
+
sendJson(res, 200, { ok: true, data: { page: null } });
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
const page = await deps.automation.state();
|
|
105
|
+
sendJson(res, 200, { ok: true, data: { page } });
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
if (method === "GET" && sub === "probe" && parts.length === 1) {
|
|
109
|
+
const scope = requireScope(req, deps);
|
|
110
|
+
if (!scope.ok) {
|
|
111
|
+
sendJson(res, scope.status, {
|
|
112
|
+
ok: false,
|
|
113
|
+
error: { code: scope.code, message: scope.message },
|
|
114
|
+
});
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
const raw = new URL(req.url ?? "/", "http://localhost").searchParams.get("url") ?? "";
|
|
118
|
+
const normalized = normalizeBrowserUrl(raw);
|
|
119
|
+
if (normalized.kind !== "ok") {
|
|
120
|
+
sendJson(res, 400, {
|
|
121
|
+
ok: false,
|
|
122
|
+
error: {
|
|
123
|
+
code: normalized.kind === "blocked" ? "BAD_SCHEME" : "INVALID_URL",
|
|
124
|
+
message: normalized.kind === "blocked"
|
|
125
|
+
? "only http/https urls can be probed"
|
|
126
|
+
: "invalid url",
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
const controller = new AbortController();
|
|
132
|
+
const timer = setTimeout(() => controller.abort(), 8000);
|
|
133
|
+
try {
|
|
134
|
+
let response = await fetch(normalized.url, {
|
|
135
|
+
method: "HEAD",
|
|
136
|
+
redirect: "follow",
|
|
137
|
+
signal: controller.signal,
|
|
138
|
+
});
|
|
139
|
+
if (response.status === 405 || response.status === 501) {
|
|
140
|
+
response = await fetch(normalized.url, {
|
|
141
|
+
method: "GET",
|
|
142
|
+
redirect: "follow",
|
|
143
|
+
signal: controller.signal,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
const frameAncestors = extractFrameAncestors(response.headers.get("content-security-policy"));
|
|
147
|
+
const xFrameOptions = response.headers.get("x-frame-options");
|
|
148
|
+
const probe = {
|
|
149
|
+
reachable: true,
|
|
150
|
+
url: response.url,
|
|
151
|
+
status: response.status,
|
|
152
|
+
...(xFrameOptions !== null ? { xFrameOptions } : {}),
|
|
153
|
+
...(frameAncestors !== undefined ? { frameAncestors } : {}),
|
|
154
|
+
};
|
|
155
|
+
sendJson(res, 200, {
|
|
156
|
+
ok: true,
|
|
157
|
+
data: { probe, verdict: embeddabilityOf(probe) },
|
|
158
|
+
});
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
sendJson(res, 200, {
|
|
163
|
+
ok: true,
|
|
164
|
+
data: {
|
|
165
|
+
probe: { reachable: false },
|
|
166
|
+
verdict: "unknown",
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
finally {
|
|
172
|
+
clearTimeout(timer);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (method === "GET" && sub === "panel" && parts[1] === "frame") {
|
|
176
|
+
const scope = requireScope(req, deps);
|
|
177
|
+
if (!scope.ok) {
|
|
178
|
+
sendJson(res, scope.status, {
|
|
179
|
+
ok: false,
|
|
180
|
+
error: { code: scope.code, message: scope.message },
|
|
181
|
+
});
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
if (!deps.automation) {
|
|
185
|
+
sendJson(res, 200, { ok: true, data: { running: false, changed: false, seq: 0 } });
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
const sinceRaw = new URL(req.url ?? "/", "http://localhost").searchParams.get("since");
|
|
189
|
+
const parsed = sinceRaw === null ? 0 : Number(sinceRaw);
|
|
190
|
+
const frame = await deps.automation.panelFrame(Number.isFinite(parsed) ? parsed : 0);
|
|
191
|
+
sendJson(res, 200, { ok: true, data: frame });
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
if (method === "POST" && parts.length >= 1) {
|
|
195
|
+
const scope = requireScope(req, deps);
|
|
196
|
+
if (!scope.ok) {
|
|
197
|
+
sendJson(res, scope.status, {
|
|
198
|
+
ok: false,
|
|
199
|
+
error: { code: scope.code, message: scope.message },
|
|
200
|
+
});
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
if (!deps.automation) {
|
|
204
|
+
sendJson(res, 503, {
|
|
205
|
+
ok: false,
|
|
206
|
+
error: { code: "BROWSER_UNAVAILABLE", message: "browser service unavailable" },
|
|
207
|
+
});
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
const body = await readJson(req);
|
|
211
|
+
const automation = deps.automation;
|
|
212
|
+
const result = await automation.run({ tabId: numberOrUndefined(body.tabId) }, () => dispatchBrowserPost(automation, sub, body));
|
|
213
|
+
sendJson(res, 200, { ok: true, data: result });
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
216
|
+
sendJson(res, 404, {
|
|
217
|
+
ok: false,
|
|
218
|
+
error: { code: "NOT_FOUND", message: `unknown browser route: ${method} ${pathname}` },
|
|
219
|
+
});
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
catch (error) {
|
|
223
|
+
if (!res.headersSent) {
|
|
224
|
+
sendJson(res, 500, { ok: false, error: errorPayload(error) });
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
res.end();
|
|
228
|
+
}
|
|
229
|
+
return true;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
async function dispatchBrowserPost(automation, action, body) {
|
|
233
|
+
switch (action) {
|
|
234
|
+
case "navigate": {
|
|
235
|
+
const result = await automation.navigate(string(body.url));
|
|
236
|
+
if (!result.ok)
|
|
237
|
+
throw new BrowserRouteError(result.code, result.error);
|
|
238
|
+
return result.page;
|
|
239
|
+
}
|
|
240
|
+
case "focus":
|
|
241
|
+
return automation.focus();
|
|
242
|
+
case "reload":
|
|
243
|
+
return automation.reload();
|
|
244
|
+
case "back":
|
|
245
|
+
return automation.goBack();
|
|
246
|
+
case "forward":
|
|
247
|
+
return automation.goForward();
|
|
248
|
+
case "scroll":
|
|
249
|
+
return automation.scroll({
|
|
250
|
+
direction: body.direction === "up" ? "up" : "down",
|
|
251
|
+
amount: numberOrUndefined(body.amount),
|
|
252
|
+
});
|
|
253
|
+
case "tab":
|
|
254
|
+
if (body.mode === "new")
|
|
255
|
+
return automation.newTab(optionalString(body.url));
|
|
256
|
+
if (body.mode === "close")
|
|
257
|
+
return automation.closeTab(numberOrUndefined(body.tabId));
|
|
258
|
+
return automation.selectTab(number(body.tabId));
|
|
259
|
+
case "dialog":
|
|
260
|
+
return automation.handleDialog(body.action === "dismiss" ? "dismiss" : "accept", optionalString(body.promptText));
|
|
261
|
+
case "pointer": {
|
|
262
|
+
const type = string(body.type);
|
|
263
|
+
if (!["mousemove", "mousedown", "mouseup", "wheel"].includes(type)) {
|
|
264
|
+
throw new Error("invalid pointer event type");
|
|
265
|
+
}
|
|
266
|
+
const event = type === "wheel"
|
|
267
|
+
? {
|
|
268
|
+
type,
|
|
269
|
+
x: number(body.x),
|
|
270
|
+
y: number(body.y),
|
|
271
|
+
deltaX: number(body.deltaX ?? 0),
|
|
272
|
+
deltaY: number(body.deltaY ?? 0),
|
|
273
|
+
}
|
|
274
|
+
: {
|
|
275
|
+
type,
|
|
276
|
+
x: number(body.x),
|
|
277
|
+
y: number(body.y),
|
|
278
|
+
...(body.button === "middle" || body.button === "right"
|
|
279
|
+
? { button: body.button }
|
|
280
|
+
: {}),
|
|
281
|
+
};
|
|
282
|
+
return automation.dispatchPointer(event);
|
|
283
|
+
}
|
|
284
|
+
case "keyboard": {
|
|
285
|
+
const type = string(body.type);
|
|
286
|
+
if (type !== "keydown" && type !== "keyup")
|
|
287
|
+
throw new Error("invalid keyboard event type");
|
|
288
|
+
const key = string(body.key);
|
|
289
|
+
if (!isPanelKeyboardKey(key)) {
|
|
290
|
+
throw new Error("invalid keyboard key; use the text action for printable characters");
|
|
291
|
+
}
|
|
292
|
+
return automation.dispatchKeyboard({ type, key });
|
|
293
|
+
}
|
|
294
|
+
case "text":
|
|
295
|
+
return automation.inputText(string(body.text));
|
|
296
|
+
case "wait":
|
|
297
|
+
return automation.waitFor(number(body.ms ?? 500));
|
|
298
|
+
default:
|
|
299
|
+
throw new Error(`unknown browser action: ${action}`);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
class BrowserRouteError extends Error {
|
|
303
|
+
code;
|
|
304
|
+
constructor(code, message) {
|
|
305
|
+
super(message);
|
|
306
|
+
this.code = code;
|
|
307
|
+
this.name = "BrowserRouteError";
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
function string(value) {
|
|
311
|
+
if (typeof value !== "string")
|
|
312
|
+
throw new Error("expected string");
|
|
313
|
+
return value;
|
|
314
|
+
}
|
|
315
|
+
function optionalString(value) {
|
|
316
|
+
return typeof value === "string" ? value : undefined;
|
|
317
|
+
}
|
|
318
|
+
function number(value) {
|
|
319
|
+
if (typeof value !== "number" || !Number.isFinite(value))
|
|
320
|
+
throw new Error("expected finite number");
|
|
321
|
+
return value;
|
|
322
|
+
}
|
|
323
|
+
function numberOrUndefined(value) {
|
|
324
|
+
return value === undefined || value === null ? undefined : number(value);
|
|
325
|
+
}
|
|
326
|
+
function isPanelKeyboardKey(key) {
|
|
327
|
+
return /^(Control|Meta|Alt|Shift)(\+[A-Za-z0-9][A-Za-z0-9]*)?$/.test(key)
|
|
328
|
+
|| (key.length > 1 && /^[A-Za-z][A-Za-z0-9]*$/.test(key));
|
|
329
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** Small text envelope survives live SSE and restored tool-result previews. */
|
|
2
|
+
const SCREENSHOT_METADATA_BUDGET = 2500;
|
|
3
|
+
const ESSENTIAL_KEYS = ["tabId", "snapshotId", "screenshotUrl", "screenshotPath", "screenshotError", "imageWarning"];
|
|
4
|
+
const OPTIONAL_KEYS = ["title", "url"];
|
|
5
|
+
const OPTIONAL_KEY_SET = new Set(OPTIONAL_KEYS);
|
|
6
|
+
/** Control characters balloon the serialized JSON and can break history restore. */
|
|
7
|
+
function cleanString(value, max) {
|
|
8
|
+
if (typeof value !== "string")
|
|
9
|
+
return value;
|
|
10
|
+
return value.replace(/[\u0000-\u001f\u007f-\u009f]/g, "").slice(0, max);
|
|
11
|
+
}
|
|
12
|
+
export function screenshotMetadata(result) {
|
|
13
|
+
const output = {};
|
|
14
|
+
for (const key of [...ESSENTIAL_KEYS, ...OPTIONAL_KEYS]) {
|
|
15
|
+
if (result[key] !== undefined)
|
|
16
|
+
output[key] = cleanString(result[key], OPTIONAL_KEY_SET.has(key) ? 200 : 500);
|
|
17
|
+
}
|
|
18
|
+
// Never truncate the serialized JSON itself: shed optional fields, then shorten the rest.
|
|
19
|
+
if (JSON.stringify(output).length > SCREENSHOT_METADATA_BUDGET)
|
|
20
|
+
for (const key of OPTIONAL_KEYS)
|
|
21
|
+
delete output[key];
|
|
22
|
+
if (JSON.stringify(output).length > SCREENSHOT_METADATA_BUDGET) {
|
|
23
|
+
for (const key of ESSENTIAL_KEYS)
|
|
24
|
+
if (typeof output[key] === "string")
|
|
25
|
+
output[key] = output[key].slice(0, 120);
|
|
26
|
+
}
|
|
27
|
+
return output;
|
|
28
|
+
}
|
|
29
|
+
/** Only renderer-local, workspace-scoped screenshot routes may become an <img>. */
|
|
30
|
+
export function screenshotUrlFromText(text) {
|
|
31
|
+
try {
|
|
32
|
+
const data = JSON.parse(text);
|
|
33
|
+
if (!data || typeof data !== "object" || !("screenshotUrl" in data) || typeof data.screenshotUrl !== "string")
|
|
34
|
+
return undefined;
|
|
35
|
+
return /^\/api\/operator\/v1\/chat\/browser\/screenshots\/[0-9a-f-]{36}\.png\?workspaceId=[A-Za-z0-9_%.-]+$/.test(data.screenshotUrl) ? data.screenshotUrl : undefined;
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** Console's text history omits binary payloads; this never mutates Pi model messages. */
|
|
42
|
+
export function omitBrowserImageData(_key, value) {
|
|
43
|
+
if (value && typeof value === "object" && "type" in value && value.type === "image") {
|
|
44
|
+
return { type: "image", dataOmitted: true };
|
|
45
|
+
}
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { constants } from "node:fs";
|
|
3
|
+
import { mkdir, open, realpath, rename, rm, writeFile } from "node:fs/promises";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
const stateSchema = z.object({
|
|
7
|
+
cookies: z.array(z.object({
|
|
8
|
+
name: z.string().min(1), value: z.string(), domain: z.string().min(1),
|
|
9
|
+
path: z.string().startsWith("/"), expires: z.number().finite(),
|
|
10
|
+
httpOnly: z.boolean(), secure: z.boolean(), sameSite: z.enum(["Strict", "Lax", "None"]),
|
|
11
|
+
partitionKey: z.string().optional(),
|
|
12
|
+
}).strict()).max(3000),
|
|
13
|
+
origins: z.array(z.object({
|
|
14
|
+
origin: z.string().refine((value) => {
|
|
15
|
+
try {
|
|
16
|
+
const url = new URL(value);
|
|
17
|
+
return ["http:", "https:"].includes(url.protocol) && url.origin === value;
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
}),
|
|
23
|
+
localStorage: z.array(z.object({ name: z.string(), value: z.string() }).strict()).max(10000),
|
|
24
|
+
}).strict()).max(100),
|
|
25
|
+
}).strict();
|
|
26
|
+
export async function exportBrowserStorage(context, directory) {
|
|
27
|
+
await mkdir(directory, { recursive: true, mode: 0o700 });
|
|
28
|
+
const state = await context.storageState();
|
|
29
|
+
const target = path.join(directory, `${randomUUID()}.json`);
|
|
30
|
+
const temporary = `${target}.tmp`;
|
|
31
|
+
try {
|
|
32
|
+
await writeFile(temporary, JSON.stringify(state), { mode: 0o600, flag: "wx" });
|
|
33
|
+
await rename(temporary, target);
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
await rm(temporary, { force: true });
|
|
37
|
+
}
|
|
38
|
+
return { path: target, cookieCount: state.cookies.length, origins: state.origins.map((entry) => entry.origin), scope: "cookies+localStorage", excluded: ["sessionStorage", "IndexedDB", "OPFS", "credentials"] };
|
|
39
|
+
}
|
|
40
|
+
/** Parse and validate fully before obtaining or mutating a browser context. */
|
|
41
|
+
export async function readBrowserStorage(filename, directory) {
|
|
42
|
+
const root = await realpath(directory);
|
|
43
|
+
const parent = await realpath(path.dirname(path.resolve(filename)));
|
|
44
|
+
const target = path.join(parent, path.basename(filename));
|
|
45
|
+
if (parent !== root || path.extname(target) !== ".json")
|
|
46
|
+
throw new Error("storage import requires a JSON file directly in the browser storage directory");
|
|
47
|
+
const handle = await open(target, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
48
|
+
try {
|
|
49
|
+
const stat = await handle.stat();
|
|
50
|
+
if (!stat.isFile() || stat.size > 5 * 1024 * 1024)
|
|
51
|
+
throw new Error("storage file must be regular and at most 5 MiB");
|
|
52
|
+
const raw = await handle.readFile("utf8");
|
|
53
|
+
try {
|
|
54
|
+
return stateSchema.parse(JSON.parse(raw));
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
throw new Error("invalid storage state: only cookies and http(s) origin localStorage are supported");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
await handle.close();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export async function mergeBrowserStorage(context, state) {
|
|
65
|
+
// A temporary routed document writes only listed keys, without running the site's application.
|
|
66
|
+
const page = await context.newPage();
|
|
67
|
+
let cdp;
|
|
68
|
+
try {
|
|
69
|
+
cdp = await context.newCDPSession(page);
|
|
70
|
+
// page.route alone does not intercept a response supplied by an installed service worker.
|
|
71
|
+
await cdp.send("Network.enable");
|
|
72
|
+
await cdp.send("Network.setBypassServiceWorker", { bypass: true });
|
|
73
|
+
await page.route("**/*", (route) => route.fulfill({ status: 200, contentType: "text/html", body: "<!doctype html><title>Import login state</title>" }));
|
|
74
|
+
await context.addCookies(state.cookies);
|
|
75
|
+
for (const entry of state.origins) {
|
|
76
|
+
await page.goto(entry.origin, { waitUntil: "domcontentloaded", timeout: 10_000 });
|
|
77
|
+
await page.evaluate((items) => { for (const item of items)
|
|
78
|
+
localStorage.setItem(item.name, item.value); }, entry.localStorage);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch (cause) {
|
|
82
|
+
throw new Error("storage merge failed; some entries may have been applied, inspect state before retrying", { cause });
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
await cdp?.detach().catch(() => undefined);
|
|
86
|
+
await page.close();
|
|
87
|
+
}
|
|
88
|
+
return { mode: "merge", cookieCount: state.cookies.length, origins: state.origins.map((entry) => entry.origin), reloadRequired: true };
|
|
89
|
+
}
|
|
@@ -22,14 +22,16 @@ import path from "node:path";
|
|
|
22
22
|
import { ensureSecureDir, writeSecureJsonSync, } from "../../../infrastructure/console/app-data.js";
|
|
23
23
|
import { isTerminalOperationState, } from "../../../infrastructure/console/operation-store.js";
|
|
24
24
|
import { scrubSecrets } from "./explore-tools.js";
|
|
25
|
-
|
|
25
|
+
/** Bounded preview stored on the event ring / SSE (not the live tool payload). */
|
|
26
|
+
export const OPERATION_PREVIEW_MAX_CHARS = 4000;
|
|
27
|
+
const OPERATION_PREVIEW_TRUNCATION_SUFFIX = "…[truncated]";
|
|
26
28
|
function boundedRedactedText(value, maxChars = OPERATION_PREVIEW_MAX_CHARS) {
|
|
27
29
|
if (typeof value !== "string" || !value.trim())
|
|
28
30
|
return undefined;
|
|
29
31
|
const { scrubbed } = scrubSecrets(value);
|
|
30
32
|
return scrubbed.length <= maxChars
|
|
31
33
|
? scrubbed
|
|
32
|
-
: `${scrubbed.slice(0, maxChars)}
|
|
34
|
+
: `${scrubbed.slice(0, maxChars)}${OPERATION_PREVIEW_TRUNCATION_SUFFIX}`;
|
|
33
35
|
}
|
|
34
36
|
function safeIdentity(value) {
|
|
35
37
|
return boundedRedactedText(value, 240);
|
|
@@ -325,18 +327,62 @@ export function projectChatToolEventPayload(input) {
|
|
|
325
327
|
toolName: input.toolName,
|
|
326
328
|
argsPreview: preview,
|
|
327
329
|
previewHash,
|
|
330
|
+
...(input.step === undefined ? {} : { step: input.step }),
|
|
331
|
+
...(input.parentToolCallId
|
|
332
|
+
? { parentToolCallId: input.parentToolCallId }
|
|
333
|
+
: {}),
|
|
328
334
|
};
|
|
329
335
|
}
|
|
330
336
|
const { preview, previewHash } = projectToolResultPreview(input.value);
|
|
337
|
+
if (input.kind === "tool_update") {
|
|
338
|
+
return {
|
|
339
|
+
toolCallId: input.toolCallId,
|
|
340
|
+
toolName: input.toolName,
|
|
341
|
+
resultPreview: preview,
|
|
342
|
+
previewHash,
|
|
343
|
+
...(input.step === undefined ? {} : { step: input.step }),
|
|
344
|
+
...(input.parentToolCallId
|
|
345
|
+
? { parentToolCallId: input.parentToolCallId }
|
|
346
|
+
: {}),
|
|
347
|
+
};
|
|
348
|
+
}
|
|
331
349
|
return {
|
|
332
350
|
toolCallId: input.toolCallId,
|
|
333
351
|
toolName: input.toolName,
|
|
334
352
|
resultPreview: preview,
|
|
335
353
|
previewHash,
|
|
336
354
|
isError: Boolean(input.isError),
|
|
355
|
+
...(input.step === undefined ? {} : { step: input.step }),
|
|
356
|
+
...(input.parentToolCallId
|
|
357
|
+
? { parentToolCallId: input.parentToolCallId }
|
|
358
|
+
: {}),
|
|
337
359
|
...(input.operationId ? { operationId: input.operationId } : {}),
|
|
338
360
|
};
|
|
339
361
|
}
|
|
362
|
+
export function projectUnknownChatEventPayload(input) {
|
|
363
|
+
const redact = (value, depth) => {
|
|
364
|
+
if (depth >= 6)
|
|
365
|
+
return "[DEPTH_LIMIT]";
|
|
366
|
+
if (Array.isArray(value)) {
|
|
367
|
+
return value.slice(0, 50).map((item) => redact(item, depth + 1));
|
|
368
|
+
}
|
|
369
|
+
if (!value || typeof value !== "object")
|
|
370
|
+
return value;
|
|
371
|
+
const result = {};
|
|
372
|
+
for (const [key, child] of Object.entries(value).slice(0, 100)) {
|
|
373
|
+
result[key] = /authorization|cookie|password|secret|token|api[-_]?key/i.test(key)
|
|
374
|
+
? "[REDACTED]"
|
|
375
|
+
: redact(child, depth + 1);
|
|
376
|
+
}
|
|
377
|
+
return result;
|
|
378
|
+
};
|
|
379
|
+
const { preview, previewHash } = boundedRedactedJson(redact(input.value, 0));
|
|
380
|
+
return {
|
|
381
|
+
eventType: input.eventType.slice(0, 120),
|
|
382
|
+
preview,
|
|
383
|
+
previewHash,
|
|
384
|
+
};
|
|
385
|
+
}
|
|
340
386
|
export function projectOperationEventSummary(event) {
|
|
341
387
|
const messagePreview = boundedRedactedText(event.message, 600);
|
|
342
388
|
const dataPreview = event.data === undefined
|
|
@@ -404,22 +450,27 @@ function dropOneByPriority(ring) {
|
|
|
404
450
|
return events.shift();
|
|
405
451
|
}
|
|
406
452
|
/**
|
|
407
|
-
* D2 coalescing decision: merge
|
|
408
|
-
*
|
|
409
|
-
*
|
|
410
|
-
* (their presence makes the tail check fail), so an
|
|
411
|
-
* update → tool_call → update sequence never merges across the tool boundary.
|
|
453
|
+
* D2 coalescing decision: merge high-frequency cumulative text/tool updates
|
|
454
|
+
* into a matching ring tail inside the coalescing window. Structural events
|
|
455
|
+
* close the window implicitly (their presence makes the tail check fail).
|
|
412
456
|
* `partial.at` (when present) drives the clock so tests can inject window
|
|
413
457
|
* boundaries deterministically without fake timers.
|
|
414
458
|
*/
|
|
415
459
|
function shouldCoalesce(ring, turnId, partial) {
|
|
416
|
-
if (partial.kind !== "message_update")
|
|
417
|
-
return false;
|
|
418
460
|
const tail = ring.events.at(-1);
|
|
419
|
-
if (!tail || tail.kind !==
|
|
461
|
+
if (!tail || tail.kind !== partial.kind)
|
|
420
462
|
return false;
|
|
421
463
|
if (tail.turnId !== turnId)
|
|
422
464
|
return false;
|
|
465
|
+
if (partial.kind === "tool_update") {
|
|
466
|
+
const currentId = partial.data.toolCallId;
|
|
467
|
+
const tailId = tail.data.toolCallId;
|
|
468
|
+
if (!currentId || currentId !== tailId)
|
|
469
|
+
return false;
|
|
470
|
+
}
|
|
471
|
+
else if (partial.kind !== "message_update") {
|
|
472
|
+
return false;
|
|
473
|
+
}
|
|
423
474
|
const nowMs = partial.at ? Date.parse(partial.at) : Date.now();
|
|
424
475
|
if (Number.isNaN(nowMs))
|
|
425
476
|
return false;
|
|
@@ -451,8 +502,8 @@ const DEFAULT_PERSIST_DEBOUNCE_MS = 250;
|
|
|
451
502
|
* interim flush is forced, so a fast stream never widens the loss window
|
|
452
503
|
* unboundedly even if the `at` clock stalls. */
|
|
453
504
|
const DEFAULT_PERSIST_MAX_PENDING_UPDATES = 250;
|
|
454
|
-
/** Conservative per-event scale for the byte pre-check gate (UTF-8 multibyte ≤ 4 bytes/char
|
|
455
|
-
const BYTE_GATE_SCALE =
|
|
505
|
+
/** Conservative per-event scale for the byte pre-check gate (UTF-8 multibyte ≤ 4 bytes/char). Persist is compact JSON, so this is no longer multiplied by pretty-print expansion. */
|
|
506
|
+
const BYTE_GATE_SCALE = 4;
|
|
456
507
|
/** Fixed envelope slack (schema keys, turnCount, nextSeq, minSeq, turns) for the byte pre-check gate. */
|
|
457
508
|
const BYTE_GATE_SLACK = 8192;
|
|
458
509
|
/** Legacy epoch for event files written before M5.1 (no epoch field). */
|
|
@@ -653,7 +704,8 @@ export function createChatEventStore(options) {
|
|
|
653
704
|
const maxBytes = options?.maxBytesPerSession ?? DEFAULT_MAX_BYTES;
|
|
654
705
|
const coalesceWindowMs = options?.coalesceWindowMs ?? DEFAULT_COALESCE_WINDOW_MS;
|
|
655
706
|
const eventEpoch = options?.epoch?.trim() || LEGACY_EPOCH;
|
|
656
|
-
const persistWriter = options?.persistWriter ??
|
|
707
|
+
const persistWriter = options?.persistWriter ??
|
|
708
|
+
((file, payload) => writeSecureJsonSync(file, payload, { pretty: false }));
|
|
657
709
|
const persistDebounceMs = options?.persistDebounceMs ?? DEFAULT_PERSIST_DEBOUNCE_MS;
|
|
658
710
|
const persistMaxPendingUpdates = options?.persistMaxPendingUpdates ?? DEFAULT_PERSIST_MAX_PENDING_UPDATES;
|
|
659
711
|
const persistenceDir = options?.appData?.chatEvents
|
|
@@ -756,10 +808,10 @@ export function createChatEventStore(options) {
|
|
|
756
808
|
epoch: ring.epoch,
|
|
757
809
|
};
|
|
758
810
|
}
|
|
759
|
-
/** Serialized exactly as `writeSecureJsonSync` writes it, so byte
|
|
760
|
-
* (D4) and the on-disk bytes use the same formatting. */
|
|
811
|
+
/** Serialized exactly as compact `writeSecureJsonSync` writes it, so byte
|
|
812
|
+
* accounting (D4) and the on-disk bytes use the same formatting. */
|
|
761
813
|
function serializeRingForPersist(sessionId, ring) {
|
|
762
|
-
return `${JSON.stringify(ringPayload(sessionId, ring)
|
|
814
|
+
return `${JSON.stringify(ringPayload(sessionId, ring))}\n`;
|
|
763
815
|
}
|
|
764
816
|
function bytesOfRing(sessionId, ring) {
|
|
765
817
|
return Buffer.byteLength(serializeRingForPersist(sessionId, ring), "utf8");
|
|
@@ -1014,12 +1066,12 @@ export function createChatEventStore(options) {
|
|
|
1014
1066
|
ring.approxBytes += byteHint(live);
|
|
1015
1067
|
}
|
|
1016
1068
|
enforceBounds(sessionId, ring);
|
|
1017
|
-
// B5-1:
|
|
1069
|
+
// B5-1: high-frequency cumulative updates defer the persist;
|
|
1018
1070
|
// every other kind (message_end / tool_call / error / turn signals …)
|
|
1019
1071
|
// still persists synchronously. Because persistNow writes the FULL
|
|
1020
1072
|
// in-memory ring, one flush also lands any earlier pending updates in
|
|
1021
1073
|
// order — no two-phase flush is needed.
|
|
1022
|
-
if (partial.kind === "message_update") {
|
|
1074
|
+
if (partial.kind === "message_update" || partial.kind === "tool_update") {
|
|
1023
1075
|
const atMs = partial.at ? Date.parse(partial.at) : Date.now();
|
|
1024
1076
|
if (!Number.isNaN(atMs)) {
|
|
1025
1077
|
persistDebounced(sessionId, ring, atMs);
|
|
@@ -1072,6 +1124,9 @@ export function createChatEventStore(options) {
|
|
|
1072
1124
|
epoch(sessionId) {
|
|
1073
1125
|
return ringFor(sessionId).epoch;
|
|
1074
1126
|
},
|
|
1127
|
+
latestSeq(sessionId) {
|
|
1128
|
+
return ringFor(sessionId).nextSeq - 1;
|
|
1129
|
+
},
|
|
1075
1130
|
snapshot(sessionId) {
|
|
1076
1131
|
const ring = rings.get(sessionId) ?? loadRing(sessionId);
|
|
1077
1132
|
if (ring)
|