@qvac/harness 1.0.0-rc.2 → 1.0.0-rc.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.nvmrc +1 -0
- package/CHANGELOG.md +2280 -1485
- package/README.md +56 -43
- package/dist-lib/index.d.ts +50 -6
- package/dist-lib/index.js +130 -28
- package/dist-lib/lib/agent/delegate.d.ts +3 -2
- package/dist-lib/lib/agent/delegate.js +6 -4
- package/dist-lib/lib/agent/follow.d.ts +5 -0
- package/dist-lib/lib/agent/follow.js +2 -0
- package/dist-lib/lib/agent/resolve.js +22 -17
- package/dist-lib/lib/agent/tool-selection.d.ts +4 -2
- package/dist-lib/lib/agent/tool-selection.js +5 -6
- package/dist-lib/lib/agent/tools.d.ts +1 -0
- package/dist-lib/lib/agent/tools.js +2 -1
- package/dist-lib/lib/capabilities/agent-ports.js +3 -3
- package/dist-lib/lib/capabilities/completion-engine/actors/batching.js +1 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/direct-search.js +2 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/executing.js +60 -9
- package/dist-lib/lib/capabilities/completion-engine/actors/execution-plan.js +4 -4
- package/dist-lib/lib/capabilities/completion-engine/actors/inspect-prepare.js +3 -2
- package/dist-lib/lib/capabilities/completion-engine/actors/inspecting.js +35 -6
- package/dist-lib/lib/capabilities/completion-engine/actors/loading-skill.d.ts +1 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/loading-skill.js +2 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/preparing.js +67 -27
- package/dist-lib/lib/capabilities/completion-engine/actors/rejecting.js +6 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/resolving.js +61 -16
- package/dist-lib/lib/capabilities/completion-engine/actors/retrieving.js +2 -2
- package/dist-lib/lib/capabilities/completion-engine/actors/skill-step.js +23 -13
- package/dist-lib/lib/capabilities/completion-engine/actors/stream.d.ts +8 -3
- package/dist-lib/lib/capabilities/completion-engine/actors/stream.js +61 -3
- package/dist-lib/lib/capabilities/completion-engine/actors/streaming.d.ts +5 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/streaming.js +47 -21
- package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.d.ts +1 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.js +30 -5
- package/dist-lib/lib/capabilities/completion-engine/driver.js +27 -11
- package/dist-lib/lib/capabilities/completion-engine/durable.d.ts +1 -0
- package/dist-lib/lib/capabilities/completion-engine/durable.js +5 -1
- package/dist-lib/lib/capabilities/completion-engine/index.d.ts +2 -1
- package/dist-lib/lib/capabilities/completion-engine/index.js +2 -2
- package/dist-lib/lib/capabilities/completion-engine/loop.d.ts +15 -2
- package/dist-lib/lib/capabilities/completion-engine/loop.js +7 -0
- package/dist-lib/lib/capabilities/completion-engine/metrics.d.ts +9 -2
- package/dist-lib/lib/capabilities/completion-engine/metrics.js +28 -7
- package/dist-lib/lib/capabilities/completion-engine/model-round.d.ts +46 -0
- package/dist-lib/lib/capabilities/completion-engine/model-round.js +45 -0
- package/dist-lib/lib/capabilities/completion-engine/operations.js +1 -1
- package/dist-lib/lib/capabilities/completion-engine/ports.js +3 -7
- package/dist-lib/lib/capabilities/completion-engine/round.d.ts +23 -3
- package/dist-lib/lib/capabilities/completion-engine/round.js +323 -97
- package/dist-lib/lib/capabilities/completion-engine/session.d.ts +10 -3
- package/dist-lib/lib/capabilities/completion-engine/session.js +30 -2
- package/dist-lib/lib/capabilities/completion-engine/tool-caller.js +3 -2
- package/dist-lib/lib/capabilities/completion-engine/tool-execution.d.ts +4 -3
- package/dist-lib/lib/capabilities/completion-engine/tool-execution.js +15 -10
- package/dist-lib/lib/capabilities/completion-engine/turns.d.ts +11 -4
- package/dist-lib/lib/capabilities/completion-engine/turns.js +48 -65
- package/dist-lib/lib/capabilities/download.d.ts +9 -7
- package/dist-lib/lib/capabilities/download.js +1 -1
- package/dist-lib/lib/capabilities/enhance.d.ts +1 -1
- package/dist-lib/lib/capabilities/enhance.js +20 -8
- package/dist-lib/lib/capabilities/preview-model-source.d.ts +7 -0
- package/dist-lib/lib/capabilities/preview-model-source.js +83 -23
- package/dist-lib/lib/capabilities/sdk-tool.d.ts +1 -0
- package/dist-lib/lib/capabilities/sdk-tool.js +18 -1
- package/dist-lib/lib/capabilities/tool-plan.d.ts +1 -1
- package/dist-lib/lib/capabilities/tool-plan.js +5 -5
- package/dist-lib/lib/capabilities/tool-prompt-log.js +3 -3
- package/dist-lib/lib/capabilities/tool-turns.d.ts +7 -9
- package/dist-lib/lib/capabilities/tool-turns.js +25 -20
- package/dist-lib/lib/client/index.d.ts +19 -0
- package/dist-lib/lib/client/index.js +262 -0
- package/dist-lib/lib/connect.d.ts +13 -10
- package/dist-lib/lib/connect.js +62 -24
- package/dist-lib/lib/context-window.d.ts +1 -0
- package/dist-lib/lib/context-window.js +3 -3
- package/dist-lib/lib/contract/agent.d.ts +7 -3
- package/dist-lib/lib/contract/completion.d.ts +44 -29
- package/dist-lib/lib/contract/egress-proxy.d.ts +13 -0
- package/dist-lib/lib/contract/egress-proxy.js +1 -0
- package/dist-lib/lib/contract/exec.d.ts +3 -3
- package/dist-lib/lib/contract/hooks.d.ts +4 -1
- package/dist-lib/lib/contract/index.d.ts +1 -0
- package/dist-lib/lib/contract/models.d.ts +6 -4
- package/dist-lib/lib/contract/policy.d.ts +75 -0
- package/dist-lib/lib/contract/policy.js +1 -0
- package/dist-lib/lib/contract/run.d.ts +9 -3
- package/dist-lib/lib/contract/sandbox.d.ts +3 -1
- package/dist-lib/lib/contract/translation.d.ts +20 -0
- package/dist-lib/lib/contract/translation.js +1 -0
- package/dist-lib/lib/contract-types.d.ts +32 -14
- package/dist-lib/lib/embeddings/index.d.ts +7 -1
- package/dist-lib/lib/embeddings/index.js +26 -5
- package/dist-lib/lib/errors.d.ts +266 -0
- package/dist-lib/lib/errors.js +198 -0
- package/dist-lib/lib/fold/index.d.ts +25 -1
- package/dist-lib/lib/fold/index.js +75 -9
- package/dist-lib/lib/guarded-fetch.js +11 -7
- package/dist-lib/lib/hardware/gpu-probe.js +10 -1
- package/dist-lib/lib/helpers/completion-params.d.ts +6 -2
- package/dist-lib/lib/helpers/completion-params.js +10 -1
- package/dist-lib/lib/helpers/engine-error.d.ts +2 -1
- package/dist-lib/lib/helpers/engine-error.js +12 -12
- package/dist-lib/lib/helpers/goal-check.d.ts +4 -0
- package/dist-lib/lib/helpers/goal-check.js +81 -0
- package/dist-lib/lib/helpers/head-tail.js +1 -1
- package/dist-lib/lib/helpers/load-stall.d.ts +1 -1
- package/dist-lib/lib/helpers/load-stall.js +2 -2
- package/dist-lib/lib/helpers/markup-stream-filter.d.ts +4 -1
- package/dist-lib/lib/helpers/markup-stream-filter.js +20 -6
- package/dist-lib/lib/helpers/repeated-reply.js +24 -16
- package/dist-lib/lib/helpers/thinking.d.ts +3 -2
- package/dist-lib/lib/helpers/thinking.js +19 -0
- package/dist-lib/lib/hooks/built-in/arg-repair.js +6 -2
- package/dist-lib/lib/hooks/built-in/policy-rules.d.ts +8 -0
- package/dist-lib/lib/hooks/built-in/policy-rules.js +192 -0
- package/dist-lib/lib/hooks/built-in/sandbox.js +23 -5
- package/dist-lib/lib/hooks/index.d.ts +4 -1
- package/dist-lib/lib/hooks/index.js +9 -4
- package/dist-lib/lib/hooks/run.js +3 -3
- package/dist-lib/lib/lifecycle/index.js +15 -14
- package/dist-lib/lib/lifecycle/machine.js +2 -2
- package/dist-lib/lib/log.d.ts +26 -5
- package/dist-lib/lib/log.js +86 -23
- package/dist-lib/lib/machine/completion/actions/completion.d.ts +4 -2
- package/dist-lib/lib/machine/completion/actions/completion.js +75 -10
- package/dist-lib/lib/machine/completion/actions/prepare.js +1 -1
- package/dist-lib/lib/machine/completion/actions/tools.js +48 -5
- package/dist-lib/lib/machine/completion/context.js +4 -1
- package/dist-lib/lib/machine/completion/guards/retry.d.ts +1 -0
- package/dist-lib/lib/machine/completion/guards/retry.js +8 -2
- package/dist-lib/lib/machine/completion/implementations.d.ts +10 -4
- package/dist-lib/lib/machine/completion/implementations.js +27 -6
- package/dist-lib/lib/machine/completion/machine.d.ts +21 -3
- package/dist-lib/lib/machine/completion/machine.js +33 -4
- package/dist-lib/lib/machine/completion/rules.d.ts +17 -2
- package/dist-lib/lib/machine/completion/rules.js +49 -3
- package/dist-lib/lib/machine/completion/types.d.ts +36 -0
- package/dist-lib/lib/machine/index.d.ts +27 -4
- package/dist-lib/lib/machine/index.js +6 -1
- package/dist-lib/lib/models/context-choice.d.ts +15 -0
- package/dist-lib/lib/models/context-choice.js +55 -0
- package/dist-lib/lib/models/download-gate.d.ts +20 -0
- package/dist-lib/lib/models/download-gate.js +73 -0
- package/dist-lib/lib/models/gguf-header.d.ts +5 -0
- package/dist-lib/lib/models/gguf-header.js +165 -14
- package/dist-lib/lib/models/llm-presets.d.ts +5 -1
- package/dist-lib/lib/models/llm-presets.js +6 -5
- package/dist-lib/lib/models/memory-cap.d.ts +13 -0
- package/dist-lib/lib/models/memory-cap.js +21 -0
- package/dist-lib/lib/models/model-catalog.d.ts +2 -0
- package/dist-lib/lib/models/model-catalog.js +15 -0
- package/dist-lib/lib/models/model-fit.d.ts +1 -1
- package/dist-lib/lib/models/model-fit.js +5 -6
- package/dist-lib/lib/models/model-handle.d.ts +8 -2
- package/dist-lib/lib/models/model-handle.js +14 -3
- package/dist-lib/lib/models/model-list.d.ts +8 -1
- package/dist-lib/lib/models/model-list.js +23 -0
- package/dist-lib/lib/models/model-pool.d.ts +35 -5
- package/dist-lib/lib/models/model-pool.js +121 -43
- package/dist-lib/lib/models/model-source.d.ts +1 -0
- package/dist-lib/lib/models/model-source.js +23 -5
- package/dist-lib/lib/models/sdk-faults.d.ts +1 -0
- package/dist-lib/lib/models/sdk-faults.js +9 -0
- package/dist-lib/lib/no-redirect-fetch-bare.js +2 -1
- package/dist-lib/lib/no-redirect-fetch-impl.js +2 -1
- package/dist-lib/lib/office/engine/pptx/picture-area.d.ts +23 -0
- package/dist-lib/lib/office/engine/pptx/picture-area.js +84 -0
- package/dist-lib/lib/office/engine/pptx/presentation.d.ts +2 -0
- package/dist-lib/lib/office/engine/pptx/presentation.js +55 -17
- package/dist-lib/lib/office/engine/pptx/types.d.ts +1 -0
- package/dist-lib/lib/office/engine/xlsx/workbook.d.ts +1 -0
- package/dist-lib/lib/office/engine/xlsx/workbook.js +34 -3
- package/dist-lib/lib/office/extract.js +4 -3
- package/dist-lib/lib/office/index.js +2 -1
- package/dist-lib/lib/plugins/registry.d.ts +3 -0
- package/dist-lib/lib/plugins/registry.js +16 -7
- package/dist-lib/lib/policy/index.d.ts +10 -0
- package/dist-lib/lib/policy/index.js +229 -0
- package/dist-lib/lib/prompt.d.ts +1 -0
- package/dist-lib/lib/prompt.js +7 -1
- package/dist-lib/lib/residency/completion-runtime.d.ts +1 -0
- package/dist-lib/lib/residency/completion-runtime.js +11 -4
- package/dist-lib/lib/residency/index.d.ts +44 -4
- package/dist-lib/lib/residency/index.js +399 -35
- package/dist-lib/lib/resolution-detector.js +3 -3
- package/dist-lib/lib/rpc-session.js +2 -1
- package/dist-lib/lib/sdk-loader.js +17 -11
- package/dist-lib/lib/serve.js +76 -36
- package/dist-lib/lib/sidecar/index.d.ts +29 -0
- package/dist-lib/lib/sidecar/index.js +174 -0
- package/dist-lib/lib/sidecar/user-plugins.d.ts +8 -0
- package/dist-lib/lib/sidecar/user-plugins.js +117 -0
- package/dist-lib/lib/skills-host/index.d.ts +1 -0
- package/dist-lib/lib/skills-host/index.js +8 -4
- package/dist-lib/lib/spawn.d.ts +3 -4
- package/dist-lib/lib/spawn.js +17 -17
- package/dist-lib/lib/spill.d.ts +1 -0
- package/dist-lib/lib/spill.js +12 -8
- package/dist-lib/lib/tools/attachments/staging.js +8 -8
- package/dist-lib/lib/tools/exec/runner.js +2 -1
- package/dist-lib/lib/tools/exec/scope.d.ts +0 -1
- package/dist-lib/lib/tools/exec/scope.js +23 -114
- package/dist-lib/lib/tools/exec/shell-guidance.js +4 -4
- package/dist-lib/lib/tools/exec/shell-line.d.ts +26 -0
- package/dist-lib/lib/tools/exec/shell-line.js +334 -0
- package/dist-lib/lib/tools/exec.d.ts +4 -1
- package/dist-lib/lib/tools/exec.js +87 -26
- package/dist-lib/lib/tools/files/edit-file.d.ts +3 -0
- package/dist-lib/lib/tools/files/edit-file.js +74 -0
- package/dist-lib/lib/tools/files/glob.d.ts +3 -0
- package/dist-lib/lib/tools/files/glob.js +65 -0
- package/dist-lib/lib/tools/files/grep.d.ts +6 -0
- package/dist-lib/lib/tools/files/grep.js +114 -0
- package/dist-lib/lib/tools/files/index.d.ts +3 -0
- package/dist-lib/lib/tools/files/index.js +23 -0
- package/dist-lib/lib/tools/files/list-dir.d.ts +6 -0
- package/dist-lib/lib/tools/files/list-dir.js +136 -0
- package/dist-lib/lib/tools/files/make-dir.d.ts +3 -0
- package/dist-lib/lib/tools/files/make-dir.js +48 -0
- package/dist-lib/lib/tools/files/read-file.d.ts +3 -0
- package/dist-lib/lib/tools/files/read-file.js +105 -0
- package/dist-lib/lib/tools/files/transfer.d.ts +4 -0
- package/dist-lib/lib/tools/files/transfer.js +83 -0
- package/dist-lib/lib/tools/files/trash-file.d.ts +4 -0
- package/dist-lib/lib/tools/files/trash-file.js +62 -0
- package/dist-lib/lib/tools/files/write-file.d.ts +3 -0
- package/dist-lib/lib/tools/files/write-file.js +56 -0
- package/dist-lib/lib/tools/fs/document-text.d.ts +2 -0
- package/dist-lib/lib/tools/fs/document-text.js +38 -0
- package/dist-lib/lib/tools/fs/drive.d.ts +14 -3
- package/dist-lib/lib/tools/fs/drive.js +9 -1
- package/dist-lib/lib/tools/fs/edit-match.d.ts +11 -0
- package/dist-lib/lib/tools/fs/edit-match.js +85 -0
- package/dist-lib/lib/tools/fs/ignore.d.ts +13 -0
- package/dist-lib/lib/tools/fs/ignore.js +104 -0
- package/dist-lib/lib/tools/fs/local.js +28 -5
- package/dist-lib/lib/tools/fs/remote-protocol.d.ts +23 -3
- package/dist-lib/lib/tools/fs/remote.d.ts +3 -4
- package/dist-lib/lib/tools/fs/remote.js +23 -13
- package/dist-lib/lib/tools/fs/scope.d.ts +5 -1
- package/dist-lib/lib/tools/fs/scope.js +5 -2
- package/dist-lib/lib/tools/fs/search.d.ts +41 -0
- package/dist-lib/lib/tools/fs/search.js +382 -0
- package/dist-lib/lib/tools/{file-glob.d.ts → fs/targets.d.ts} +1 -5
- package/dist-lib/lib/tools/fs/targets.js +32 -0
- package/dist-lib/lib/tools/fs/tool-path.d.ts +27 -0
- package/dist-lib/lib/tools/fs/tool-path.js +70 -0
- package/dist-lib/lib/tools/fs/walk.d.ts +15 -3
- package/dist-lib/lib/tools/fs/walk.js +118 -24
- package/dist-lib/lib/tools/http-request.js +12 -2
- package/dist-lib/lib/tools/index.js +2 -10
- package/dist-lib/lib/tools/office/ops.js +1 -1
- package/dist-lib/lib/tools/office.js +77 -21
- package/dist-lib/lib/tools/pdf/build.d.ts +5 -1
- package/dist-lib/lib/tools/pdf/build.js +31 -6
- package/dist-lib/lib/tools/pdf.js +17 -2
- package/dist-lib/lib/tools/skill.js +10 -7
- package/dist-lib/lib/tools/skills/bundled-dir.js +4 -4
- package/dist-lib/lib/tools/skills/catalog.d.ts +2 -0
- package/dist-lib/lib/tools/skills/catalog.js +6 -2
- package/dist-lib/lib/tools/skills/cli-argv.js +25 -5
- package/dist-lib/lib/tools/skills/cli-schema-check.d.ts +1 -0
- package/dist-lib/lib/tools/skills/cli-schema-check.js +3 -0
- package/dist-lib/lib/tools/skills/cli-schema-load.js +10 -0
- package/dist-lib/lib/tools/skills/cli-schema-types.d.ts +2 -0
- package/dist-lib/lib/tools/skills/cli-schema.js +6 -3
- package/dist-lib/lib/tools/skills/credential-health.js +3 -3
- package/dist-lib/lib/tools/skills/frontmatter-parser.d.ts +2 -0
- package/dist-lib/lib/tools/skills/frontmatter-parser.js +4 -0
- package/dist-lib/lib/tools/skills/manifest-parse.d.ts +1 -0
- package/dist-lib/lib/tools/skills/manifest-parse.js +12 -0
- package/dist-lib/lib/tools/skills/mention-name.d.ts +6 -0
- package/dist-lib/lib/tools/skills/mention-name.js +6 -0
- package/dist-lib/lib/tools/skills/mention.d.ts +2 -2
- package/dist-lib/lib/tools/skills/mention.js +11 -4
- package/dist-lib/lib/tools/skills/overlay-crud.js +3 -2
- package/dist-lib/lib/tools/url-guard.d.ts +6 -1
- package/dist-lib/lib/tools/url-guard.js +8 -2
- package/dist-lib/lib/tools/web-fetch.js +10 -4
- package/dist-lib/lib/wire.js +3 -5
- package/dist-lib/plugins/coding/index.d.ts +1 -1
- package/dist-lib/plugins/coding/index.js +2 -4
- package/dist-lib/plugins/coding/session.d.ts +3 -3
- package/dist-lib/plugins/coding/session.js +26 -14
- package/dist-lib/plugins/command-hooks/index.js +5 -3
- package/dist-lib/plugins/egress-proxy/index.d.ts +53 -0
- package/dist-lib/plugins/egress-proxy/index.js +182 -0
- package/dist-lib/plugins/image/edit-image.js +4 -3
- package/dist-lib/plugins/image/generate-image.d.ts +4 -3
- package/dist-lib/plugins/image/generate-image.js +10 -9
- package/dist-lib/plugins/image/index.d.ts +1 -1
- package/dist-lib/plugins/image/index.js +13 -10
- package/dist-lib/plugins/language-hint/index.d.ts +15 -0
- package/dist-lib/plugins/language-hint/index.js +51 -0
- package/dist-lib/plugins/lsp/tool.js +2 -2
- package/dist-lib/plugins/mcp/index.js +6 -3
- package/dist-lib/plugins/music/generate-music.d.ts +4 -2
- package/dist-lib/plugins/music/generate-music.js +7 -4
- package/dist-lib/plugins/music/index.js +12 -9
- package/dist-lib/plugins/obsidian/command.js +2 -2
- package/dist-lib/plugins/obsidian/note-name.js +2 -1
- package/dist-lib/plugins/obsidian/safe-path.js +5 -4
- package/dist-lib/plugins/obsidian/vault-create.js +3 -2
- package/dist-lib/plugins/obsidian/vault-fs.js +2 -2
- package/dist-lib/plugins/obsidian/vault-paths.js +3 -2
- package/dist-lib/plugins/obsidian/vault-read.js +6 -5
- package/dist-lib/plugins/obsidian/vault-write.js +13 -12
- package/dist-lib/plugins/python/guarded-fetch.d.ts +2 -1
- package/dist-lib/plugins/python/guarded-fetch.js +5 -1
- package/dist-lib/plugins/python/interrupt-timer.js +2 -2
- package/dist-lib/plugins/python/loader.js +68 -3
- package/dist-lib/plugins/python/memfs.js +2 -2
- package/dist-lib/plugins/python/pyodide.d.ts +1 -0
- package/dist-lib/plugins/python/pyodide.js +9 -8
- package/dist-lib/plugins/python/python-adapter.js +3 -1
- package/dist-lib/plugins/python/run-session.d.ts +1 -0
- package/dist-lib/plugins/python/run-session.js +19 -8
- package/dist-lib/plugins/python/wheels.js +8 -6
- package/dist-lib/plugins/python/worker/active.js +2 -2
- package/dist-lib/plugins/python/worker/client.js +9 -8
- package/dist-lib/plugins/python/worker/protocol.d.ts +2 -0
- package/dist-lib/plugins/python/worker/serve.js +23 -4
- package/dist-lib/plugins/python/worker/spawn.d.ts +2 -1
- package/dist-lib/plugins/python/worker/spawn.js +2 -1
- package/dist-lib/plugins/run-report/chain.d.ts +2 -0
- package/dist-lib/plugins/run-report/chain.js +73 -0
- package/dist-lib/plugins/run-report/flow-view.js +2 -1
- package/dist-lib/plugins/run-report/flow.d.ts +1 -1
- package/dist-lib/plugins/run-report/flow.js +66 -14
- package/dist-lib/plugins/run-report/index.d.ts +23 -2
- package/dist-lib/plugins/run-report/index.js +27 -12
- package/dist-lib/plugins/run-report/model.d.ts +10 -1
- package/dist-lib/plugins/run-report/model.js +12 -6
- package/dist-lib/plugins/run-report/page.d.ts +9 -0
- package/dist-lib/plugins/run-report/page.js +55 -15
- package/dist-lib/plugins/run-report/script.js +317 -43
- package/dist-lib/plugins/run-report/story.d.ts +2 -1
- package/dist-lib/plugins/run-report/story.js +3 -3
- package/dist-lib/plugins/run-report/style.d.ts +1 -1
- package/dist-lib/plugins/run-report/style.js +126 -0
- package/dist-lib/plugins/run-report/why.js +1 -1
- package/dist-lib/plugins/sandbox-linux/index.d.ts +60 -0
- package/dist-lib/plugins/sandbox-linux/index.js +347 -0
- package/dist-lib/plugins/sandbox-linux/seccomp.d.ts +2 -0
- package/dist-lib/plugins/sandbox-linux/seccomp.js +74 -0
- package/dist-lib/plugins/sandbox-macos/index.d.ts +23 -11
- package/dist-lib/plugins/sandbox-macos/index.js +239 -49
- package/dist-lib/plugins/sandbox-vm/vm-shell.d.ts +4 -2
- package/dist-lib/plugins/sandbox-vm/vm-shell.js +9 -4
- package/dist-lib/plugins/sandbox-windows/helper/qvac-sandbox.c +554 -0
- package/dist-lib/plugins/sandbox-windows/index.d.ts +53 -0
- package/dist-lib/plugins/sandbox-windows/index.js +205 -0
- package/dist-lib/plugins/sandbox-windows/prebuilds/win32-arm64/qvac-sandbox.exe +0 -0
- package/dist-lib/plugins/sandbox-windows/prebuilds/win32-x64/qvac-sandbox.exe +0 -0
- package/dist-lib/plugins/speech/audio-resample.d.ts +1 -1
- package/dist-lib/plugins/speech/audio-resample.js +7 -8
- package/dist-lib/plugins/speech/audio-transcode-bare.d.ts +1 -1
- package/dist-lib/plugins/speech/audio-transcode-bare.js +23 -26
- package/dist-lib/plugins/speech/audio-transcode-node.d.ts +1 -1
- package/dist-lib/plugins/speech/audio-transcode-node.js +1 -3
- package/dist-lib/plugins/speech/speech-runtime.js +37 -37
- package/dist-lib/plugins/speech/voice.d.ts +5 -1
- package/dist-lib/plugins/speech/voice.js +100 -31
- package/dist-lib/plugins/translation/index.d.ts +1 -0
- package/dist-lib/plugins/translation/index.js +16 -9
- package/dist-lib/plugins/translation/translate.d.ts +7 -3
- package/dist-lib/plugins/translation/translate.js +64 -58
- package/dist-lib/plugins/weather/geocode.js +2 -1
- package/dist-lib/plugins/weather/lookup.js +5 -4
- package/dist-lib/plugins/web-search/engines/bing.js +2 -1
- package/dist-lib/plugins/web-search/engines/google.js +2 -1
- package/dist-lib/plugins/web-search/fetch-html.d.ts +5 -5
- package/dist-lib/plugins/web-search/fetch-html.js +12 -15
- package/dist-lib/plugins/web-search/tool.js +1 -0
- package/dist-lib/schema/harness.js +48 -7
- package/dist-lib/spec/bind.js +9 -0
- package/dist-lib/spec/calls.js +3 -0
- package/dist-lib/spec/hrpc/hrpc.json +42 -3
- package/dist-lib/spec/hrpc/index.js +44 -8
- package/dist-lib/spec/hrpc/messages.js +297 -202
- package/dist-lib/spec/hyperschema/index.js +297 -202
- package/dist-lib/spec/hyperschema/schema.json +155 -84
- package/dist-lib/spec/hyperschema/types.d.ts +23 -3
- package/package.json +101 -38
- package/patches/@qvac%2Finference@0.22.0.patch +59 -0
- package/patches/pyodide@314.0.2.patch +37 -8
- package/scripts/addon-externals.cjs +10 -5
- package/worker/harness-sidecar.mjs +18 -154
- package/dist-lib/lib/tools/create-documents.d.ts +0 -3
- package/dist-lib/lib/tools/create-documents.js +0 -95
- package/dist-lib/lib/tools/edit-documents.d.ts +0 -3
- package/dist-lib/lib/tools/edit-documents.js +0 -132
- package/dist-lib/lib/tools/exec/shell-argv.d.ts +0 -2
- package/dist-lib/lib/tools/exec/shell-argv.js +0 -61
- package/dist-lib/lib/tools/file-glob.js +0 -118
- package/dist-lib/lib/tools/grep.d.ts +0 -5
- package/dist-lib/lib/tools/grep.js +0 -184
- package/dist-lib/lib/tools/read-files.d.ts +0 -5
- package/dist-lib/lib/tools/read-files.js +0 -160
- package/dist-lib/plugins/coding/write-file.d.ts +0 -3
- package/dist-lib/plugins/coding/write-file.js +0 -52
- package/patches/@qvac%2Finference@0.21.0.patch +0 -67
- package/patches/bare-stow@0.1.5.patch +0 -68
- package/patches/hypercore-blob-server@1.15.0.patch +0 -15
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
|
+
import { Policy } from '../../lib/policy/index.js';
|
|
2
3
|
import { attachOutputs, stageInputs } from '../../lib/tools/attachments/staging.js';
|
|
3
4
|
import { checkFileName, checkOutputName, MAX_INPUTS, MAX_OUTPUTS } from '../../lib/tools/attachments/output-policy.js';
|
|
4
5
|
import { runPython } from './pyodide.js';
|
|
@@ -423,7 +424,7 @@ export function createPythonAdapter(loadPyodide, network = false) {
|
|
|
423
424
|
const fetchAttachment = ctx?.fetchAttachment;
|
|
424
425
|
const turnImages = ctx?.turnImages;
|
|
425
426
|
const runBudget = ctx?.runBudget;
|
|
426
|
-
const sandbox = ctx?.
|
|
427
|
+
const sandbox = ctx?.policy?.network.mode === 'off';
|
|
427
428
|
const toolNames = ctx?.toolNames;
|
|
428
429
|
const approved = ctx?.approval === 'allowed' || ctx?.approval === 'skip-all';
|
|
429
430
|
const reach = network && !sandbox && approved;
|
|
@@ -472,6 +473,7 @@ export function createPythonAdapter(loadPyodide, network = false) {
|
|
|
472
473
|
loadPyodide,
|
|
473
474
|
network: reach,
|
|
474
475
|
hosts: gated ? namedHosts(source) : undefined,
|
|
476
|
+
allowed: Policy.hostsOf(ctx?.policy),
|
|
475
477
|
askConnect: gated ? confirmConnect : undefined
|
|
476
478
|
});
|
|
477
479
|
const hint = packageFetchFailedHint(result.stderr) ??
|
|
@@ -66,6 +66,7 @@ export interface RunSpec {
|
|
|
66
66
|
readonly installTimeoutMs: number;
|
|
67
67
|
readonly network?: boolean | undefined;
|
|
68
68
|
readonly hosts?: readonly string[] | undefined;
|
|
69
|
+
readonly allowed?: readonly string[] | undefined;
|
|
69
70
|
}
|
|
70
71
|
export interface RunOutcome {
|
|
71
72
|
readonly result: PythonRunResult;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { errorMessage } from '../../lib/guards.js';
|
|
2
2
|
import { AbortedError } from '../../lib/helpers/race-abort.js';
|
|
3
|
-
import {
|
|
3
|
+
import { HarnessError } from '../../lib/errors.js';
|
|
4
|
+
import { HarnessLog } from '../../lib/log.js';
|
|
4
5
|
import { capOutput } from '../../lib/tools/exec/runner.js';
|
|
5
6
|
import { collectOutputs, openScratch, stageInputFiles } from './memfs.js';
|
|
6
7
|
import { isGuardedFetch, setConnectPolicy } from './guarded-fetch.js';
|
|
@@ -100,7 +101,10 @@ async function runOnce(py, code, opts) {
|
|
|
100
101
|
}
|
|
101
102
|
return retry;
|
|
102
103
|
}
|
|
103
|
-
class InstallTimeoutError extends
|
|
104
|
+
class InstallTimeoutError extends HarnessError {
|
|
105
|
+
constructor(ms) {
|
|
106
|
+
super('PACKAGE_INSTALL_TIMED_OUT', [ms]);
|
|
107
|
+
}
|
|
104
108
|
}
|
|
105
109
|
function installSource(py, packages) {
|
|
106
110
|
const plan = planVendoredInstall(packages);
|
|
@@ -108,7 +112,7 @@ function installSource(py, packages) {
|
|
|
108
112
|
return `import micropip\nawait micropip.install(${JSON.stringify(packages)})`;
|
|
109
113
|
}
|
|
110
114
|
const specs = [...stageVendoredWheels(py.FS, plan), ...plan.packages];
|
|
111
|
-
|
|
115
|
+
HarnessLog.info('python: installing from vendored wheels', { specs });
|
|
112
116
|
return `import micropip\nawait micropip.install(${JSON.stringify(specs)}, deps=False)`;
|
|
113
117
|
}
|
|
114
118
|
async function installPackages(py, packages, { timeoutMs, isCancelled }) {
|
|
@@ -119,7 +123,7 @@ async function installPackages(py, packages, { timeoutMs, isCancelled }) {
|
|
|
119
123
|
const install = py.runPythonAsync(installSource(py, packages));
|
|
120
124
|
let timer;
|
|
121
125
|
const bound = new Promise((_, reject) => {
|
|
122
|
-
timer = setTimeout(() => reject(new InstallTimeoutError(
|
|
126
|
+
timer = setTimeout(() => reject(new InstallTimeoutError(timeoutMs)), timeoutMs);
|
|
123
127
|
});
|
|
124
128
|
try {
|
|
125
129
|
await Promise.race([install, bound]);
|
|
@@ -145,7 +149,10 @@ function newDeliverables(before, after) {
|
|
|
145
149
|
export async function performRun(py, spec, opts = {}) {
|
|
146
150
|
const isCancelled = opts.isCancelled ?? (() => false);
|
|
147
151
|
const ask = opts.askConnect ?? (async () => false);
|
|
148
|
-
const
|
|
152
|
+
const gated = spec.hosts || spec.allowed;
|
|
153
|
+
const access = spec.network === true
|
|
154
|
+
? { policy: gated ? { named: spec.hosts, ask, allowed: spec.allowed } : null }
|
|
155
|
+
: null;
|
|
149
156
|
const output = { stdout: '', stderr: '' };
|
|
150
157
|
py.setStdout({ batched: (chunk) => (output.stdout += chunk + '\n') });
|
|
151
158
|
py.setStderr({ batched: (chunk) => (output.stderr += chunk + '\n') });
|
|
@@ -153,16 +160,17 @@ export async function performRun(py, spec, opts = {}) {
|
|
|
153
160
|
if (isCancelled()) {
|
|
154
161
|
throw new AbortedError();
|
|
155
162
|
}
|
|
156
|
-
|
|
163
|
+
HarnessLog.info('python: installing packages', {
|
|
157
164
|
packages: [...spec.packages],
|
|
158
165
|
timeoutMs: spec.installTimeoutMs
|
|
159
166
|
});
|
|
167
|
+
setConnectPolicy(spec.allowed ? { ask, allowed: spec.allowed } : null);
|
|
160
168
|
try {
|
|
161
169
|
await installPackages(py, spec.packages, {
|
|
162
170
|
timeoutMs: spec.installTimeoutMs,
|
|
163
171
|
isCancelled
|
|
164
172
|
});
|
|
165
|
-
|
|
173
|
+
HarnessLog.info('python: packages ready', { packages: [...spec.packages] });
|
|
166
174
|
}
|
|
167
175
|
catch (error) {
|
|
168
176
|
if (error instanceof AbortedError) {
|
|
@@ -171,7 +179,7 @@ export async function performRun(py, spec, opts = {}) {
|
|
|
171
179
|
const message = errorMessage(error);
|
|
172
180
|
const timedOut = error instanceof InstallTimeoutError;
|
|
173
181
|
const evict = timedOut || isPyodideFatal(error);
|
|
174
|
-
|
|
182
|
+
HarnessLog.warn(timedOut ? 'python: package install timed out' : 'python: package install failed', {
|
|
175
183
|
packages: [...spec.packages],
|
|
176
184
|
err: message,
|
|
177
185
|
evict
|
|
@@ -181,6 +189,9 @@ export async function performRun(py, spec, opts = {}) {
|
|
|
181
189
|
evict
|
|
182
190
|
};
|
|
183
191
|
}
|
|
192
|
+
finally {
|
|
193
|
+
setConnectPolicy(null);
|
|
194
|
+
}
|
|
184
195
|
output.stdout = '';
|
|
185
196
|
output.stderr = '';
|
|
186
197
|
}
|
|
@@ -4,7 +4,7 @@ import process from 'process';
|
|
|
4
4
|
import { fileURLToPath } from 'url';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { errorMessage } from '../../lib/guards.js';
|
|
7
|
-
import {
|
|
7
|
+
import { HarnessLog } from '../../lib/log.js';
|
|
8
8
|
const ManifestSchema = z.object({
|
|
9
9
|
pyodide: z.string(),
|
|
10
10
|
packages: z.record(z.string(), z.object({
|
|
@@ -18,19 +18,21 @@ const ManifestSchema = z.object({
|
|
|
18
18
|
const STAGE_DIR = '/qvac-wheels';
|
|
19
19
|
export function wheelsDir() {
|
|
20
20
|
return (process.env.QVAC_PYTHON_WHEELS_DIR ||
|
|
21
|
-
path.dirname(fileURLToPath(import.meta.asset
|
|
21
|
+
path.dirname(fileURLToPath(typeof import.meta.asset === 'function'
|
|
22
|
+
? import.meta.asset('#pyodide-wheels')
|
|
23
|
+
: import.meta.resolve('#pyodide-wheels'))));
|
|
22
24
|
}
|
|
23
25
|
export function vendoredManifest(dir = wheelsDir()) {
|
|
24
26
|
const file = `${dir}/manifest.json`;
|
|
25
27
|
if (!fs.existsSync(file)) {
|
|
26
|
-
|
|
28
|
+
HarnessLog.info('python: no vendored wheels', { dir });
|
|
27
29
|
return null;
|
|
28
30
|
}
|
|
29
31
|
try {
|
|
30
32
|
return ManifestSchema.parse(JSON.parse(fs.readFileSync(file, 'utf8')));
|
|
31
33
|
}
|
|
32
34
|
catch (error) {
|
|
33
|
-
|
|
35
|
+
HarnessLog.warn('python: vendored wheel manifest unusable', {
|
|
34
36
|
file,
|
|
35
37
|
err: errorMessage(error)
|
|
36
38
|
});
|
|
@@ -74,7 +76,7 @@ export function planVendoredInstall(specs, opts = {}) {
|
|
|
74
76
|
}
|
|
75
77
|
for (const wheel of entry.pypi) {
|
|
76
78
|
if (!fs.existsSync(`${dir}/${wheel}`)) {
|
|
77
|
-
|
|
79
|
+
HarnessLog.warn('python: vendored wheel missing, installing from PyPI instead', { wheel });
|
|
78
80
|
return null;
|
|
79
81
|
}
|
|
80
82
|
wheels.add(`${dir}/${wheel}`);
|
|
@@ -114,6 +116,6 @@ export function seedPackageCache(cacheDir, dir = wheelsDir()) {
|
|
|
114
116
|
seeded++;
|
|
115
117
|
}
|
|
116
118
|
if (seeded > 0) {
|
|
117
|
-
|
|
119
|
+
HarnessLog.debug('python: seeded package cache', { cacheDir, wheels: seeded });
|
|
118
120
|
}
|
|
119
121
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HarnessLog } from '../../../lib/log.js';
|
|
2
2
|
import { asWorkerMessage } from './protocol.js';
|
|
3
3
|
const SHUTDOWN_GRACE_MS = 3_000;
|
|
4
4
|
let active = null;
|
|
@@ -20,7 +20,7 @@ export async function readMessage(link) {
|
|
|
20
20
|
if (message?.type !== 'log') {
|
|
21
21
|
return message;
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
HarnessLog[message.level](`python worker: ${message.message}`);
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
export async function drainAndReap(worker) {
|
|
@@ -2,7 +2,8 @@ import { AbortController } from 'bare-abort-controller';
|
|
|
2
2
|
import process from 'process';
|
|
3
3
|
import { fileURLToPath } from 'url';
|
|
4
4
|
import { AbortedError, raceAbort } from '../../../lib/helpers/race-abort.js';
|
|
5
|
-
import {
|
|
5
|
+
import { HarnessError } from '../../../lib/errors.js';
|
|
6
|
+
import { HarnessLog } from '../../../lib/log.js';
|
|
6
7
|
import { RESEND_MS, SIGINT } from '../deadline-state.js';
|
|
7
8
|
import { fromWireResult } from './protocol.js';
|
|
8
9
|
import { activeWorker, destroy, drainAndReap, forget, grace, readMessage } from './active.js';
|
|
@@ -24,18 +25,18 @@ async function awaitReady(link) {
|
|
|
24
25
|
return;
|
|
25
26
|
}
|
|
26
27
|
if (message?.type === 'boot-error') {
|
|
27
|
-
throw new
|
|
28
|
+
throw new HarnessError('PYTHON_WORKER_FAILED', [message.message]);
|
|
28
29
|
}
|
|
29
30
|
throw new Error('python worker sent an unexpected first message');
|
|
30
31
|
}
|
|
31
32
|
function boot() {
|
|
32
|
-
|
|
33
|
+
HarnessLog.info('python: booting worker thread');
|
|
33
34
|
const sab = new SharedArrayBuffer(1);
|
|
34
|
-
const link = spawnPythonWorker(workerEntry(), { sab, log:
|
|
35
|
+
const link = spawnPythonWorker(workerEntry(), { sab, log: HarnessLog.level() });
|
|
35
36
|
const worker = {
|
|
36
37
|
link,
|
|
37
38
|
view: new Uint8Array(sab),
|
|
38
|
-
ready: awaitReady(link).then(() =>
|
|
39
|
+
ready: awaitReady(link).then(() => HarnessLog.info('python: worker ready')),
|
|
39
40
|
nextId: 1
|
|
40
41
|
};
|
|
41
42
|
worker.ready.catch(() => {
|
|
@@ -58,7 +59,7 @@ async function resultFor(worker, id, askConnect) {
|
|
|
58
59
|
return { result: fromWireResult(message.result), evict: message.evict };
|
|
59
60
|
}
|
|
60
61
|
if (message?.type === 'boot-error') {
|
|
61
|
-
throw new
|
|
62
|
+
throw new HarnessError('PYTHON_WORKER_FAILED', [message.message]);
|
|
62
63
|
}
|
|
63
64
|
throw new Error('python worker sent an unexpected message');
|
|
64
65
|
}
|
|
@@ -73,7 +74,7 @@ async function interrupt(worker, outcome) {
|
|
|
73
74
|
timer.expired
|
|
74
75
|
]);
|
|
75
76
|
if (settled === 'grace') {
|
|
76
|
-
|
|
77
|
+
HarnessLog.warn('python: worker ignored interrupt; killing', { graceMs });
|
|
77
78
|
destroy(worker);
|
|
78
79
|
}
|
|
79
80
|
else {
|
|
@@ -137,7 +138,7 @@ export async function runPythonInWorker(spec, opts) {
|
|
|
137
138
|
}
|
|
138
139
|
if (first === 'timeout') {
|
|
139
140
|
await cancel();
|
|
140
|
-
throw new
|
|
141
|
+
throw new HarnessError('COMMAND_TIMED_OUT', [opts.timeoutMs]);
|
|
141
142
|
}
|
|
142
143
|
if (first.evict) {
|
|
143
144
|
await drainAndReap(worker);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { LineLevel } from '../../../lib/log.ts';
|
|
1
2
|
import type { PythonRunResult, RunSpec } from '../run-session.ts';
|
|
2
3
|
export type HostMessage = {
|
|
3
4
|
readonly type: 'run';
|
|
@@ -23,6 +24,7 @@ export interface WireResult {
|
|
|
23
24
|
}
|
|
24
25
|
export type WorkerMessage = {
|
|
25
26
|
readonly type: 'log';
|
|
27
|
+
readonly level: LineLevel;
|
|
26
28
|
readonly message: string;
|
|
27
29
|
} | {
|
|
28
30
|
readonly type: 'ready';
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { parentPort, workerData } from 'worker_threads';
|
|
2
2
|
import { errorMessage, isRecord } from '../../../lib/guards.js';
|
|
3
|
-
import {
|
|
3
|
+
import { HarnessLog } from '../../../lib/log.js';
|
|
4
4
|
import { performRun } from '../run-session.js';
|
|
5
5
|
import { asHostMessage, toWireResult } from './protocol.js';
|
|
6
6
|
function narrowThreadData(data) {
|
|
7
7
|
if (isRecord(data) && 'sab' in data) {
|
|
8
8
|
const sab = data.sab;
|
|
9
|
-
const log = 'log' in data && data.log
|
|
9
|
+
const log = 'log' in data && HarnessLog.isLevel(data.log) ? data.log : 'off';
|
|
10
10
|
if (sab instanceof SharedArrayBuffer) {
|
|
11
11
|
return { sab, log };
|
|
12
12
|
}
|
|
@@ -71,12 +71,31 @@ async function serveRuns(port, py) {
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
+
function refuseCodeGeneration() {
|
|
75
|
+
throw new EvalError('code generation is disabled in the python worker');
|
|
76
|
+
}
|
|
77
|
+
function sealCodeGeneration() {
|
|
78
|
+
const prototypes = [
|
|
79
|
+
function () { },
|
|
80
|
+
async function () { },
|
|
81
|
+
function* () { },
|
|
82
|
+
async function* () { }
|
|
83
|
+
].map((fn) => Object.getPrototypeOf(fn));
|
|
84
|
+
for (const prototype of prototypes) {
|
|
85
|
+
Object.defineProperty(prototype, 'constructor', {
|
|
86
|
+
value: refuseCodeGeneration,
|
|
87
|
+
writable: false,
|
|
88
|
+
configurable: false
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
74
92
|
export async function serve(load) {
|
|
75
93
|
const { port, sab, log } = openPort();
|
|
76
|
-
|
|
77
|
-
|
|
94
|
+
HarnessLog.setLevel(log);
|
|
95
|
+
HarnessLog.setSink((message, level) => port.write({ type: 'log', level, message }));
|
|
78
96
|
try {
|
|
79
97
|
const py = await load();
|
|
98
|
+
sealCodeGeneration();
|
|
80
99
|
py.setInterruptBuffer(new Uint8Array(sab));
|
|
81
100
|
port.write({ type: 'ready' });
|
|
82
101
|
await serveRuns(port, py);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { LogLevel } from '../../../lib/log.ts';
|
|
1
2
|
export interface WorkerLink {
|
|
2
3
|
read(): Promise<unknown>;
|
|
3
4
|
write(message: unknown): Promise<void>;
|
|
@@ -8,7 +9,7 @@ export interface WorkerLink {
|
|
|
8
9
|
}
|
|
9
10
|
export interface WorkerData {
|
|
10
11
|
readonly sab: SharedArrayBuffer;
|
|
11
|
-
readonly log:
|
|
12
|
+
readonly log: LogLevel;
|
|
12
13
|
}
|
|
13
14
|
export declare function spawnPythonWorker(entry: string, data: WorkerData): WorkerLink;
|
|
14
15
|
export declare function preloadWorker(entry: string): Promise<void>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Worker } from 'worker_threads';
|
|
2
|
+
import { HarnessError } from '../../../lib/errors.js';
|
|
2
3
|
export function spawnPythonWorker(entry, data) {
|
|
3
4
|
const worker = new Worker(entry, {
|
|
4
5
|
workerData: data,
|
|
@@ -26,7 +27,7 @@ export function spawnPythonWorker(entry, data) {
|
|
|
26
27
|
};
|
|
27
28
|
worker.on('message', push);
|
|
28
29
|
worker.on('error', (error) => fail(error instanceof Error ? error : new Error(String(error))));
|
|
29
|
-
worker.on('exit', (code) => fail(new
|
|
30
|
+
worker.on('exit', (code) => fail(new HarnessError('PYTHON_WORKER_EXITED', [code])));
|
|
30
31
|
worker.unref();
|
|
31
32
|
return {
|
|
32
33
|
read() {
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { isRecord } from '../../lib/guards.js';
|
|
2
|
+
const TRANSFER = 'transfer_to_agent';
|
|
3
|
+
export function chain(models) {
|
|
4
|
+
const first = models[0];
|
|
5
|
+
const last = models[models.length - 1];
|
|
6
|
+
if (models.length === 1) {
|
|
7
|
+
return first;
|
|
8
|
+
}
|
|
9
|
+
const out = {
|
|
10
|
+
...first,
|
|
11
|
+
run: { ...last.run, runId: first.run.runId, startedAt: first.run.startedAt },
|
|
12
|
+
running: last.running,
|
|
13
|
+
definition: models.find((model) => model.definition)?.definition ?? null,
|
|
14
|
+
steps: [],
|
|
15
|
+
visits: {},
|
|
16
|
+
edges: {},
|
|
17
|
+
story: { prompt: first.story.prompt, rounds: [], tools: [] },
|
|
18
|
+
hops: []
|
|
19
|
+
};
|
|
20
|
+
let steps = 0;
|
|
21
|
+
let rounds = 0;
|
|
22
|
+
for (const [index, model] of models.entries()) {
|
|
23
|
+
const reason = index === 0 ? '' : transferReason(models[index - 1]);
|
|
24
|
+
out.hops.push({
|
|
25
|
+
agent: model.run.agent,
|
|
26
|
+
model: model.run.model,
|
|
27
|
+
reason,
|
|
28
|
+
round: rounds,
|
|
29
|
+
step: (model.steps[0]?.index ?? 0) + steps
|
|
30
|
+
});
|
|
31
|
+
out.steps.push(...model.steps.map((step) => ({
|
|
32
|
+
...step,
|
|
33
|
+
index: step.index + steps,
|
|
34
|
+
round: step.round + rounds
|
|
35
|
+
})));
|
|
36
|
+
merge(out.visits, model.visits, steps);
|
|
37
|
+
merge(out.edges, model.edges, steps);
|
|
38
|
+
out.story.rounds.push(...model.story.rounds.map((round) => ({
|
|
39
|
+
...round,
|
|
40
|
+
round: round.round + rounds,
|
|
41
|
+
step: shift(round.step, steps),
|
|
42
|
+
calls: round.calls.map((call) => ({
|
|
43
|
+
...call,
|
|
44
|
+
round: call.round + rounds,
|
|
45
|
+
step: shift(call.step, steps)
|
|
46
|
+
}))
|
|
47
|
+
})));
|
|
48
|
+
out.story.tools.push(...model.story.tools);
|
|
49
|
+
steps += (model.steps.at(-1)?.index ?? -1) + 1;
|
|
50
|
+
rounds += model.story.rounds.length;
|
|
51
|
+
}
|
|
52
|
+
const tokens = models.map((model) => model.run.tokens);
|
|
53
|
+
out.run.tools = [...new Set(models.flatMap((model) => model.run.tools))];
|
|
54
|
+
out.run.rounds = models.reduce((sum, model) => sum + model.run.rounds, 0);
|
|
55
|
+
out.run.tokens = tokens.includes(null)
|
|
56
|
+
? null
|
|
57
|
+
: tokens.reduce((sum, n) => Number(sum) + Number(n), 0);
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
function merge(into, from, by) {
|
|
61
|
+
for (const [key, indexes] of Object.entries(from)) {
|
|
62
|
+
into[key] = [...(into[key] ?? []), ...indexes.map((index) => index + by)];
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function shift(step, by) {
|
|
66
|
+
return step === null ? null : step + by;
|
|
67
|
+
}
|
|
68
|
+
function transferReason(model) {
|
|
69
|
+
const call = model.story.rounds
|
|
70
|
+
.flatMap((round) => round.calls)
|
|
71
|
+
.findLast((call) => call.name === TRANSFER);
|
|
72
|
+
return isRecord(call?.args) ? String(call.args.reason ?? '') : '';
|
|
73
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ReportModel } from './model.ts';
|
|
2
2
|
import type { Outcome } from './story.ts';
|
|
3
|
-
export type FlowKind = 'start' | 'round' | 'call' | 'end';
|
|
3
|
+
export type FlowKind = 'start' | 'handoff' | 'steer' | 'round' | 'call' | 'end';
|
|
4
4
|
export type FlowStatus = Outcome | 'model' | 'start' | 'done' | 'error';
|
|
5
5
|
export interface FlowNode {
|
|
6
6
|
id: string;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
const PER_LINE =
|
|
1
|
+
const PER_LINE = 34;
|
|
2
|
+
const PER_CALL_LINE = 42;
|
|
2
3
|
const ROUND_W = 250;
|
|
3
4
|
const CALL_W = 300;
|
|
4
5
|
const GAP_X = 44;
|
|
5
6
|
const GAP_Y = 30;
|
|
6
7
|
export function flow(model) {
|
|
7
8
|
const nodes = graph(model);
|
|
8
|
-
own(nodes, model
|
|
9
|
+
own(nodes, model);
|
|
9
10
|
const rows = rowsOf(nodes);
|
|
10
11
|
const edges = [];
|
|
11
12
|
let y = 0;
|
|
@@ -68,19 +69,31 @@ function down(from, to) {
|
|
|
68
69
|
};
|
|
69
70
|
}
|
|
70
71
|
function graph(model) {
|
|
71
|
-
const { run, story } = model;
|
|
72
|
+
const { run, story, hops } = model;
|
|
72
73
|
const nodes = [
|
|
73
74
|
node({
|
|
74
75
|
id: 'start',
|
|
75
76
|
kind: 'start',
|
|
76
77
|
status: 'start',
|
|
77
78
|
title: 'Request',
|
|
79
|
+
meta: hops[0]?.agent ?? '',
|
|
78
80
|
lines: wrap(story.prompt)
|
|
79
81
|
})
|
|
80
82
|
];
|
|
83
|
+
const inputs = inputSteps(model.steps);
|
|
81
84
|
for (const round of story.rounds) {
|
|
85
|
+
const hop = hops.findIndex((hop, index) => index > 0 && hop.round === round.round);
|
|
86
|
+
if (hop > 0) {
|
|
87
|
+
nodes.push(handoffNode(hops, hop));
|
|
88
|
+
}
|
|
89
|
+
nodes.push(...takeInputs(inputs, round.round));
|
|
82
90
|
nodes.push(roundNode(round), ...round.calls.map((call, index) => callNode(call, index)));
|
|
83
91
|
}
|
|
92
|
+
nodes.push(...takeInputs(inputs, Infinity));
|
|
93
|
+
if (model.running) {
|
|
94
|
+
nodes.push(node({ id: 'end', kind: 'end', status: 'running', title: 'Running', lines: [] }));
|
|
95
|
+
return nodes;
|
|
96
|
+
}
|
|
84
97
|
const good = run.outcome === 'success' || run.status === 'done';
|
|
85
98
|
nodes.push(node({
|
|
86
99
|
id: 'end',
|
|
@@ -91,6 +104,41 @@ function graph(model) {
|
|
|
91
104
|
}));
|
|
92
105
|
return nodes;
|
|
93
106
|
}
|
|
107
|
+
function inputSteps(steps) {
|
|
108
|
+
return steps.flatMap((step) => step.kind === 'transition'
|
|
109
|
+
? step.events
|
|
110
|
+
.filter((event) => event.type === 'INPUT')
|
|
111
|
+
.map((event) => ({
|
|
112
|
+
step: step.index,
|
|
113
|
+
round: step.round,
|
|
114
|
+
mode: String(event.mode),
|
|
115
|
+
text: String(event.text)
|
|
116
|
+
}))
|
|
117
|
+
: []);
|
|
118
|
+
}
|
|
119
|
+
function takeInputs(inputs, round) {
|
|
120
|
+
const taken = inputs.filter((input) => input.round < round);
|
|
121
|
+
inputs.splice(0, taken.length);
|
|
122
|
+
return taken.map((input) => node({
|
|
123
|
+
id: `input-${input.step}`,
|
|
124
|
+
kind: 'steer',
|
|
125
|
+
status: 'start',
|
|
126
|
+
title: input.mode === 'follow-up' ? 'Follow-up' : 'Steer',
|
|
127
|
+
lines: wrap(input.text),
|
|
128
|
+
from: input.step
|
|
129
|
+
}));
|
|
130
|
+
}
|
|
131
|
+
function handoffNode(hops, index) {
|
|
132
|
+
const { agent, model, reason, step } = hops[index];
|
|
133
|
+
return node({
|
|
134
|
+
id: `hop-${index}`,
|
|
135
|
+
kind: 'handoff',
|
|
136
|
+
status: 'model',
|
|
137
|
+
title: `${hops[index - 1].agent} → ${agent}`,
|
|
138
|
+
lines: [...wrap(`on ${model}`, 1), ...wrap(reason)],
|
|
139
|
+
from: step
|
|
140
|
+
});
|
|
141
|
+
}
|
|
94
142
|
function roundNode(round) {
|
|
95
143
|
const meta = [seconds(round.durationMs), round.tokens === null ? '' : `${round.tokens} tokens`];
|
|
96
144
|
return node({
|
|
@@ -107,7 +155,7 @@ function roundNode(round) {
|
|
|
107
155
|
function callNode(call, index) {
|
|
108
156
|
const asked = call.approved === null ? '' : `${call.approved ? 'approved' : 'declined'} by a person`;
|
|
109
157
|
const said = call.outcome === 'ok' ? gist(call.args) : call.detail;
|
|
110
|
-
const lines = call.outcome === 'denied' && asked ? [] : wrap(said);
|
|
158
|
+
const lines = call.outcome === 'denied' && asked ? [] : wrap(said, 2, PER_CALL_LINE);
|
|
111
159
|
return node({
|
|
112
160
|
id: `call-${call.round}-${index}`,
|
|
113
161
|
kind: 'call',
|
|
@@ -139,30 +187,34 @@ function node(input) {
|
|
|
139
187
|
h: 40 + lines.length * 17 + (badge ? 22 : 0)
|
|
140
188
|
};
|
|
141
189
|
}
|
|
142
|
-
function own(nodes, steps) {
|
|
143
|
-
const
|
|
190
|
+
function own(nodes, { steps, hops }) {
|
|
191
|
+
const inputs = new Map(nodes.filter((node) => node.kind === 'steer').map((node) => [node.from, node]));
|
|
192
|
+
const started = nodes.filter((node) => node.from !== null && node.kind !== 'steer');
|
|
144
193
|
const end = nodes.at(-1);
|
|
194
|
+
const lastRun = hops.at(-1)?.step ?? 0;
|
|
145
195
|
let finishing = false;
|
|
146
196
|
for (const step of steps) {
|
|
147
197
|
finishing ||=
|
|
148
|
-
step.
|
|
198
|
+
step.index >= lastRun &&
|
|
199
|
+
step.kind === 'transition' &&
|
|
149
200
|
step.entered.some((id) => /\.(answering|wrapping|finishing)$/.test(id));
|
|
150
|
-
const owner =
|
|
151
|
-
|
|
152
|
-
|
|
201
|
+
const owner = inputs.get(step.index) ??
|
|
202
|
+
(finishing
|
|
203
|
+
? end
|
|
204
|
+
: (started.filter((node) => Number(node.from) <= step.index).at(-1) ?? nodes[0]));
|
|
153
205
|
owner?.steps.push(step.index);
|
|
154
206
|
}
|
|
155
207
|
}
|
|
156
|
-
function wrap(text, max = 2) {
|
|
208
|
+
function wrap(text, max = 2, per = PER_LINE) {
|
|
157
209
|
const words = text.replace(/\s+/g, ' ').trim().split(' ').filter(Boolean);
|
|
158
210
|
const lines = [];
|
|
159
211
|
let line = '';
|
|
160
212
|
for (const word of words) {
|
|
161
|
-
if (line && line.length + word.length + 1 >
|
|
213
|
+
if (line && line.length + word.length + 1 > per) {
|
|
162
214
|
lines.push(line);
|
|
163
215
|
line = '';
|
|
164
216
|
}
|
|
165
|
-
line = line ? `${line} ${word}` : word.slice(0,
|
|
217
|
+
line = line ? `${line} ${word}` : word.slice(0, per);
|
|
166
218
|
if (lines.length === max) {
|
|
167
219
|
break;
|
|
168
220
|
}
|
|
@@ -171,7 +223,7 @@ function wrap(text, max = 2) {
|
|
|
171
223
|
lines.push(line);
|
|
172
224
|
}
|
|
173
225
|
if (lines.length === max && words.join(' ').length > lines.join(' ').length) {
|
|
174
|
-
lines[max - 1] = `${(lines[max - 1] ?? '').slice(0,
|
|
226
|
+
lines[max - 1] = `${(lines[max - 1] ?? '').slice(0, per - 1)}…`;
|
|
175
227
|
}
|
|
176
228
|
return lines;
|
|
177
229
|
}
|
|
@@ -1,17 +1,38 @@
|
|
|
1
1
|
import { type EngineBoot, type EngineStep, type MachineLog, type RunRecord } from '../../lib/run-log/index.ts';
|
|
2
2
|
export interface RunReportOptions {
|
|
3
3
|
title?: string;
|
|
4
|
+
live?: boolean;
|
|
4
5
|
}
|
|
5
6
|
export interface RunRecordingOptions {
|
|
7
|
+
hopLog: () => RunHopLog;
|
|
8
|
+
}
|
|
9
|
+
export interface RunHopLog {
|
|
6
10
|
boot: EngineBoot;
|
|
7
11
|
onStep: (step: EngineStep) => Promise<void>;
|
|
8
12
|
requestDigestKey: Uint8Array;
|
|
9
13
|
}
|
|
10
14
|
export interface RunRecording {
|
|
11
|
-
|
|
15
|
+
hops: RunRecord[][];
|
|
12
16
|
options: RunRecordingOptions;
|
|
13
17
|
}
|
|
18
|
+
export interface ReportParts {
|
|
19
|
+
title: string;
|
|
20
|
+
hero: string;
|
|
21
|
+
jumps: string;
|
|
22
|
+
canvas: string;
|
|
23
|
+
machine: boolean;
|
|
24
|
+
data: object;
|
|
25
|
+
}
|
|
26
|
+
export interface LiveReportOptions {
|
|
27
|
+
source?: string;
|
|
28
|
+
}
|
|
29
|
+
export type RunSource = MachineLog | RunRecord[];
|
|
30
|
+
export interface RunChain {
|
|
31
|
+
hops: RunSource[];
|
|
32
|
+
}
|
|
14
33
|
export declare class RunReport {
|
|
15
34
|
static record(): RunRecording;
|
|
16
|
-
static render(source:
|
|
35
|
+
static render(source: RunSource | RunChain, options?: RunReportOptions): Promise<string>;
|
|
36
|
+
static parts(source: RunSource | RunChain, { title, live }?: RunReportOptions): Promise<ReportParts>;
|
|
37
|
+
static live({ source }?: LiveReportOptions): string;
|
|
17
38
|
}
|