@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,14 +1,17 @@
|
|
|
1
|
-
import { compactedFrom, contextCandidates } from '../../context-window.js';
|
|
1
|
+
import { compactedFrom, contextCandidates, TOOL_SEARCH_RESULT } from '../../context-window.js';
|
|
2
|
+
import { Agent } from '../../agent/index.js';
|
|
3
|
+
import { HarnessError } from '../../errors.js';
|
|
2
4
|
import { bufferBurst } from '../../helpers/buffer-burst.js';
|
|
3
5
|
import { endsTurn, stopAtControlToken } from '../../helpers/control-tokens.js';
|
|
4
6
|
import { createMarkupStreamFilter } from '../../helpers/markup-stream-filter.js';
|
|
5
7
|
import { AbortedError, raceAbort } from '../../helpers/race-abort.js';
|
|
6
8
|
import { raceTimeout } from '../../helpers/race-timeout.js';
|
|
7
9
|
import { withoutRepeatedReply } from '../../helpers/repeated-reply.js';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
10
|
+
import { recoverMarkupToolCalls } from '../../helpers/tool-call-markup.js';
|
|
11
|
+
import { splitThinking, tapThinking } from '../../helpers/thinking.js';
|
|
12
|
+
import { errorMessage } from '../../guards.js';
|
|
13
|
+
import { HarnessLog } from '../../log.js';
|
|
14
|
+
import { isContextOverflowError, isForcedCallFault, isKvCacheSaveFault, isSdkModelWedgedError, isToolGrammarFault } from '../../models/sdk-faults.js';
|
|
12
15
|
import { copy } from '../../helpers/copy.js';
|
|
13
16
|
import { stableStringify } from '../../helpers/stable-stringify.js';
|
|
14
17
|
import { detachJson } from '../../helpers/detach-json.js';
|
|
@@ -16,9 +19,9 @@ import { materializeCompletionHistory } from '../tool-turns.js';
|
|
|
16
19
|
import { completionParams } from '../../helpers/completion-params.js';
|
|
17
20
|
import { isFailureResultReference } from '../../helpers/failure-result.js';
|
|
18
21
|
import { Fold } from '../../fold/index.js';
|
|
22
|
+
import { CompletionMachine } from '../../machine/index.js';
|
|
19
23
|
import { modelTurns } from './turns.js';
|
|
20
24
|
const BURST_WINDOW_MS = 100;
|
|
21
|
-
export const CONTEXT_OVERFLOW_MESSAGE = 'This message is too large for the model context window.';
|
|
22
25
|
const noop = () => { };
|
|
23
26
|
function unprovenReplay(state, final) {
|
|
24
27
|
if (!state.unproven)
|
|
@@ -26,7 +29,10 @@ function unprovenReplay(state, final) {
|
|
|
26
29
|
if (state.stopToken) {
|
|
27
30
|
return endsTurn(state.stopToken) ? state.unproven : null;
|
|
28
31
|
}
|
|
29
|
-
if (
|
|
32
|
+
if (state.runaway ||
|
|
33
|
+
state.cut !== null ||
|
|
34
|
+
final.stopReason === 'length' ||
|
|
35
|
+
final.stopReason === 'cancelled') {
|
|
30
36
|
return null;
|
|
31
37
|
}
|
|
32
38
|
return state.unproven;
|
|
@@ -42,15 +48,37 @@ function cancelOnce(sdk, requestId) {
|
|
|
42
48
|
};
|
|
43
49
|
return Object.assign(cancel, { flush: () => pending });
|
|
44
50
|
}
|
|
45
|
-
async function*
|
|
51
|
+
async function* contentDeltas(events) {
|
|
52
|
+
for await (const event of events) {
|
|
53
|
+
if (event.type === 'contentDelta') {
|
|
54
|
+
yield event.text;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async function* countGenerated(tokens, state) {
|
|
59
|
+
for await (const token of tokens) {
|
|
60
|
+
state.live.rawChars += token.length;
|
|
61
|
+
yield token;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
async function* runRoundTokens({ result, state, cancelThisRound, unsettled, signal, startInThink, knownTools }) {
|
|
46
65
|
signal?.addEventListener('abort', cancelThisRound, { once: true });
|
|
47
|
-
|
|
66
|
+
armCut(state, cancelThisRound);
|
|
67
|
+
const closeCalls = watchToolCalls(result.toolCallStream, state, cancelThisRound);
|
|
68
|
+
const tokens = stopAtControlToken(contentDeltas(result.events), (token) => {
|
|
48
69
|
state.stopToken = token;
|
|
49
70
|
});
|
|
71
|
+
const counted = tapThinking(tokens, { startInThink }, () => {
|
|
72
|
+
state.live.reasoningDeltas = ++state.reasoningDeltas;
|
|
73
|
+
});
|
|
50
74
|
let tokenEvents = 0;
|
|
51
|
-
const events = splitThinking(bufferBurst(
|
|
75
|
+
const events = splitThinking(bufferBurst(countGenerated(counted, state), BURST_WINDOW_MS), {
|
|
76
|
+
startInThink
|
|
77
|
+
});
|
|
52
78
|
const thinkingFilter = createMarkupStreamFilter();
|
|
53
|
-
const contentFilter = createMarkupStreamFilter(
|
|
79
|
+
const contentFilter = createMarkupStreamFilter({
|
|
80
|
+
onToolCall: watchMarkupCalls(state, knownTools, cancelThisRound)
|
|
81
|
+
});
|
|
54
82
|
try {
|
|
55
83
|
tokenEvents = yield* processRoundTokenEvents({
|
|
56
84
|
events,
|
|
@@ -60,7 +88,7 @@ async function* runRoundTokens({ result, state, cancelThisRound, signal, startIn
|
|
|
60
88
|
thinkingFilter,
|
|
61
89
|
contentFilter
|
|
62
90
|
});
|
|
63
|
-
|
|
91
|
+
HarnessLog.info('stream ended', { events: tokenEvents, stopToken: state.stopToken });
|
|
64
92
|
if (state.stopToken) {
|
|
65
93
|
cancelThisRound();
|
|
66
94
|
}
|
|
@@ -70,22 +98,97 @@ async function* runRoundTokens({ result, state, cancelThisRound, signal, startIn
|
|
|
70
98
|
cancelThisRound();
|
|
71
99
|
}
|
|
72
100
|
signal?.removeEventListener('abort', cancelThisRound);
|
|
73
|
-
|
|
101
|
+
state.live.cut = undefined;
|
|
102
|
+
closeCalls();
|
|
103
|
+
const closed = events.return(null);
|
|
104
|
+
if (signal?.aborted) {
|
|
105
|
+
unsettled.push(closed.catch(noop));
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
await closed;
|
|
109
|
+
}
|
|
74
110
|
}
|
|
75
111
|
}
|
|
112
|
+
function armCut(state, cancelThisRound) {
|
|
113
|
+
if (state.live.kind !== 'streaming')
|
|
114
|
+
return;
|
|
115
|
+
state.live.cut = (note) => {
|
|
116
|
+
if (state.cut !== null)
|
|
117
|
+
return;
|
|
118
|
+
state.cut = note;
|
|
119
|
+
HarnessLog.info('round cut by the host', { round: state.live.round });
|
|
120
|
+
cancelThisRound();
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function tripsCap(state, seen, call) {
|
|
124
|
+
state.calls.push(call);
|
|
125
|
+
return tripsCount(seen, stableStringify([call.name, call.arguments]), state.calls.length);
|
|
126
|
+
}
|
|
127
|
+
function tripsCount(seen, key, total) {
|
|
128
|
+
const count = (seen.get(key) ?? 0) + 1;
|
|
129
|
+
seen.set(key, count);
|
|
130
|
+
return count >= CompletionMachine.MAX_ROUND_REPEATS || total >= CompletionMachine.MAX_ROUND_CALLS;
|
|
131
|
+
}
|
|
132
|
+
function watchMarkupCalls(state, knownTools, cancelThisRound) {
|
|
133
|
+
const seen = new Map();
|
|
134
|
+
let blocks = 0;
|
|
135
|
+
return (body) => {
|
|
136
|
+
if (state.runaway)
|
|
137
|
+
return;
|
|
138
|
+
blocks++;
|
|
139
|
+
const parsed = recoverMarkupToolCalls(body, knownTools).map((call) => [
|
|
140
|
+
call.name,
|
|
141
|
+
call.arguments
|
|
142
|
+
]);
|
|
143
|
+
const key = parsed.length ? stableStringify(parsed) : body.trim();
|
|
144
|
+
if (tripsCount(seen, key, blocks)) {
|
|
145
|
+
state.runaway = true;
|
|
146
|
+
HarnessLog.info('round stopped on its tool markup', { blocks });
|
|
147
|
+
cancelThisRound();
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
function watchToolCalls(stream, state, cancelThisRound) {
|
|
152
|
+
if (!stream)
|
|
153
|
+
return noop;
|
|
154
|
+
const calls = stream[Symbol.asyncIterator]();
|
|
155
|
+
const seen = new Map();
|
|
156
|
+
let closed = false;
|
|
157
|
+
const close = () => {
|
|
158
|
+
if (closed)
|
|
159
|
+
return;
|
|
160
|
+
closed = true;
|
|
161
|
+
Promise.resolve(calls.return?.()).catch(noop);
|
|
162
|
+
};
|
|
163
|
+
const drain = async () => {
|
|
164
|
+
let next = await calls.next();
|
|
165
|
+
while (!next.done && !closed) {
|
|
166
|
+
if (tripsCap(state, seen, next.value.call)) {
|
|
167
|
+
state.runaway = true;
|
|
168
|
+
HarnessLog.info('round stopped on its tool calls', { calls: state.calls.length });
|
|
169
|
+
cancelThisRound();
|
|
170
|
+
close();
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
next = await calls.next();
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
drain().catch(noop);
|
|
177
|
+
return close;
|
|
178
|
+
}
|
|
76
179
|
async function* processRoundTokenEvents({ events, state, cancelThisRound, signal, thinkingFilter, contentFilter }) {
|
|
77
180
|
let tokenEvents = 0;
|
|
78
181
|
while (true) {
|
|
79
|
-
|
|
182
|
+
if (signal?.aborted) {
|
|
183
|
+
cancelThisRound();
|
|
184
|
+
throw new AbortedError();
|
|
185
|
+
}
|
|
186
|
+
const next = await raceAbort(events.next(), signal);
|
|
80
187
|
if (next.done) {
|
|
81
188
|
state.unproven = next.value;
|
|
82
189
|
yield* flushFilterTails(thinkingFilter, contentFilter);
|
|
83
190
|
break;
|
|
84
191
|
}
|
|
85
|
-
if (signal?.aborted) {
|
|
86
|
-
cancelThisRound();
|
|
87
|
-
throw new AbortedError();
|
|
88
|
-
}
|
|
89
192
|
tokenEvents++;
|
|
90
193
|
if (next.value.type === 'content') {
|
|
91
194
|
state.rawContentText += next.value.text;
|
|
@@ -108,16 +211,18 @@ async function* flushFilterTails(thinkingFilter, contentFilter) {
|
|
|
108
211
|
yield { type: 'content', text: contentTail };
|
|
109
212
|
}
|
|
110
213
|
}
|
|
111
|
-
function
|
|
112
|
-
if (
|
|
214
|
+
export function foldTokens(stats, cacheable) {
|
|
215
|
+
if (cacheable !== false)
|
|
216
|
+
return stats?.cacheTokens;
|
|
217
|
+
if (stats?.promptTokens === undefined)
|
|
113
218
|
return undefined;
|
|
114
|
-
|
|
115
|
-
if (!stats.sentMessages.every(isMessage))
|
|
116
|
-
return undefined;
|
|
117
|
-
return detachJson(stats.sentMessages);
|
|
219
|
+
return stats.promptTokens + (stats.generatedTokens ?? 0);
|
|
118
220
|
}
|
|
119
|
-
function
|
|
120
|
-
|
|
221
|
+
function withoutCacheTokens(stats) {
|
|
222
|
+
if (!stats)
|
|
223
|
+
return undefined;
|
|
224
|
+
const { cacheTokens: _summed, ...rest } = stats;
|
|
225
|
+
return rest;
|
|
121
226
|
}
|
|
122
227
|
function roundTokens(stats) {
|
|
123
228
|
if (!stats)
|
|
@@ -143,49 +248,78 @@ function truncatedFinal(final, contentText) {
|
|
|
143
248
|
}
|
|
144
249
|
export async function* runRecoveredRound(sdk, args) {
|
|
145
250
|
const lease = args.acquireRound ? await args.acquireRound(args.signal) : null;
|
|
251
|
+
const unsettled = [];
|
|
146
252
|
try {
|
|
147
253
|
const roundSdk = lease?.sdk ?? sdk;
|
|
148
254
|
if (!roundSdk) {
|
|
149
255
|
throw new Error('A completion round requires an SDK');
|
|
150
256
|
}
|
|
151
257
|
const ctxSize = lease?.ctxSize ?? args.fold?.ctxSize;
|
|
258
|
+
const slotted = (lease?.slots ?? 1) > 1;
|
|
259
|
+
const attempts = { sent: 0, uncached: slotted, overflows: 0, unsettled };
|
|
152
260
|
const round = yield* runRecoveredRoundWith({
|
|
153
261
|
sdk: roundSdk,
|
|
154
262
|
args,
|
|
155
263
|
modelId: lease?.modelId ?? args.modelId,
|
|
156
264
|
ctxSize,
|
|
157
|
-
attempts
|
|
265
|
+
attempts
|
|
158
266
|
});
|
|
159
|
-
if (args.fold
|
|
160
|
-
Fold.observe(args.cacheKey, {
|
|
267
|
+
if (args.fold?.cacheKey) {
|
|
268
|
+
Fold.observe(args.fold.cacheKey, {
|
|
269
|
+
cacheTokens: foldTokens(round.final.stats, round.cacheable),
|
|
270
|
+
ctxSize
|
|
271
|
+
});
|
|
161
272
|
}
|
|
162
|
-
|
|
273
|
+
const overflows = attempts.overflows ? { overflows: attempts.overflows } : {};
|
|
274
|
+
const final = slotted
|
|
275
|
+
? { ...round.final, stats: withoutCacheTokens(round.final.stats) }
|
|
276
|
+
: round.final;
|
|
277
|
+
return { ...round, final, ctxSize: lease?.ctxSize, ...overflows };
|
|
163
278
|
}
|
|
164
279
|
finally {
|
|
165
|
-
|
|
166
|
-
|
|
280
|
+
if (lease && unsettled.length) {
|
|
281
|
+
void Promise.all(unsettled).then(() => releaseLease(lease));
|
|
167
282
|
}
|
|
168
|
-
|
|
169
|
-
|
|
283
|
+
else if (lease) {
|
|
284
|
+
releaseLease(lease);
|
|
170
285
|
}
|
|
171
286
|
}
|
|
172
287
|
}
|
|
288
|
+
function releaseLease(lease) {
|
|
289
|
+
try {
|
|
290
|
+
lease.release();
|
|
291
|
+
}
|
|
292
|
+
catch (error) {
|
|
293
|
+
HarnessLog.info('completion round lease release failed', { error: errorMessage(error) });
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
export async function recordWholeRound(args) {
|
|
297
|
+
const history = materializeCompletionHistory(args.history, args.failureResults);
|
|
298
|
+
const origins = historyOrigins(args.history, history);
|
|
299
|
+
const params = inferenceParams({ args, modelId: args.modelId, history, cacheable: true });
|
|
300
|
+
await args.recordRequest?.({ round: args.round, attempt: 0, droppedTurns: 0, params }, failureTurns(args, origins, history));
|
|
301
|
+
if (args.signal?.aborted) {
|
|
302
|
+
throw new AbortedError();
|
|
303
|
+
}
|
|
304
|
+
return params;
|
|
305
|
+
}
|
|
173
306
|
async function* runRecoveredRoundWith(send) {
|
|
174
307
|
const { args } = send;
|
|
175
308
|
let history = materializeCompletionHistory(args.history, args.failureResults);
|
|
176
309
|
const origins = historyOrigins(args.history, history);
|
|
177
|
-
const reading = args.
|
|
178
|
-
|
|
179
|
-
|
|
310
|
+
const reading = args.fold?.reading ??
|
|
311
|
+
(args.round === 0 && args.fold?.cacheKey ? Fold.reading(args.fold.cacheKey) : undefined);
|
|
312
|
+
const fold = { chat: false, rounds: false };
|
|
313
|
+
if (reading && Fold.due({ ...reading, ctxSize: reading.ctxSize ?? send.ctxSize })) {
|
|
314
|
+
history = (yield* foldHistory(send, history, fold)) ?? history;
|
|
180
315
|
}
|
|
181
|
-
const fold = { tried: false };
|
|
182
316
|
while (true) {
|
|
183
317
|
const outcome = yield* runLadder({ send, history, origins, fold });
|
|
184
318
|
if ('round' in outcome) {
|
|
185
319
|
return outcome.round;
|
|
186
320
|
}
|
|
187
321
|
if (!('folded' in outcome)) {
|
|
188
|
-
throw
|
|
322
|
+
throw new HarnessError('CONTEXT_WINDOW_EXCEEDED', [], { cause: outcome.overflow });
|
|
189
323
|
}
|
|
190
324
|
history = outcome.folded;
|
|
191
325
|
}
|
|
@@ -198,9 +332,9 @@ async function* runLadder({ send, history, origins, fold }) {
|
|
|
198
332
|
return { round: recoveredRound({ candidate, attempt: outcome.round, origins }) };
|
|
199
333
|
}
|
|
200
334
|
lastOverflow = outcome.overflow;
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
const folded = yield* foldHistory(send, history);
|
|
335
|
+
send.attempts.overflows++;
|
|
336
|
+
if (candidate.history === history) {
|
|
337
|
+
const folded = yield* foldHistory(send, history, fold);
|
|
204
338
|
if (folded) {
|
|
205
339
|
return { folded };
|
|
206
340
|
}
|
|
@@ -211,7 +345,53 @@ async function* runLadder({ send, history, origins, fold }) {
|
|
|
211
345
|
}
|
|
212
346
|
return { overflow: lastOverflow };
|
|
213
347
|
}
|
|
214
|
-
async function* foldHistory(send, history) {
|
|
348
|
+
async function* foldHistory(send, history, tries) {
|
|
349
|
+
if (!tries.chat) {
|
|
350
|
+
tries.chat = true;
|
|
351
|
+
const folded = yield* foldChat(send, history);
|
|
352
|
+
if (folded) {
|
|
353
|
+
return folded;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
if (tries.rounds) {
|
|
357
|
+
return null;
|
|
358
|
+
}
|
|
359
|
+
tries.rounds = true;
|
|
360
|
+
return foldRounds(send, history);
|
|
361
|
+
}
|
|
362
|
+
async function foldRounds(send, history) {
|
|
363
|
+
const { sdk, args, ctxSize } = send;
|
|
364
|
+
const spec = args.fold;
|
|
365
|
+
const nudges = [args.continuationNudge, args.deliveredNudge];
|
|
366
|
+
if (!spec || !Fold.roundBoundary(history, { nudges, keeps: keepsLoad })?.foldedRounds) {
|
|
367
|
+
return null;
|
|
368
|
+
}
|
|
369
|
+
const instructions = await spec.instructions?.(history);
|
|
370
|
+
const result = await new Fold(summarizer(send)).rounds(history, {
|
|
371
|
+
ctxSize,
|
|
372
|
+
instructions,
|
|
373
|
+
nudges,
|
|
374
|
+
keeps: keepsLoad
|
|
375
|
+
});
|
|
376
|
+
if (args.signal?.aborted) {
|
|
377
|
+
throw new AbortedError();
|
|
378
|
+
}
|
|
379
|
+
if (!result.folded) {
|
|
380
|
+
HarnessLog.info('rounds fold refused', { round: args.round, reason: result.reason });
|
|
381
|
+
return null;
|
|
382
|
+
}
|
|
383
|
+
if (args.cacheKey) {
|
|
384
|
+
await dropFoldedKey(sdk, args.cacheKey);
|
|
385
|
+
}
|
|
386
|
+
HarnessLog.info('folded rounds', { round: args.round, foldedRounds: result.foldedRounds });
|
|
387
|
+
return result.history;
|
|
388
|
+
}
|
|
389
|
+
function keepsLoad(message) {
|
|
390
|
+
return (message.role === 'tool' &&
|
|
391
|
+
(message.content.startsWith(TOOL_SEARCH_RESULT) ||
|
|
392
|
+
message.content.startsWith(`[Tool: ${Agent.SKILL_TOOL_NAME} (`)));
|
|
393
|
+
}
|
|
394
|
+
async function* foldChat(send, history) {
|
|
215
395
|
const { sdk, args, ctxSize } = send;
|
|
216
396
|
const spec = args.fold;
|
|
217
397
|
const widest = spec && Fold.boundary(spec.messages);
|
|
@@ -231,7 +411,7 @@ async function* foldHistory(send, history) {
|
|
|
231
411
|
}
|
|
232
412
|
const result = step.value;
|
|
233
413
|
if (!result.folded) {
|
|
234
|
-
|
|
414
|
+
HarnessLog.info('fold refused', { round: args.round, reason: result.reason });
|
|
235
415
|
return null;
|
|
236
416
|
}
|
|
237
417
|
const replaced = modelTurns(spec.messages.slice(0, result.end), spec.nudge).length;
|
|
@@ -243,7 +423,7 @@ async function* foldHistory(send, history) {
|
|
|
243
423
|
if (args.cacheKey) {
|
|
244
424
|
await dropFoldedKey(sdk, args.cacheKey);
|
|
245
425
|
}
|
|
246
|
-
|
|
426
|
+
HarnessLog.info('folded', { round: args.round, foldedTurns: result.foldedTurns });
|
|
247
427
|
yield {
|
|
248
428
|
type: 'fold',
|
|
249
429
|
phase: 'done',
|
|
@@ -258,11 +438,11 @@ async function dropFoldedKey(sdk, cacheKey) {
|
|
|
258
438
|
try {
|
|
259
439
|
const deleted = await sdk.deleteCache?.({ kvCacheKey: cacheKey });
|
|
260
440
|
if (deleted && !deleted.success) {
|
|
261
|
-
|
|
441
|
+
HarnessLog.info('fold key delete did not succeed');
|
|
262
442
|
}
|
|
263
443
|
}
|
|
264
444
|
catch (error) {
|
|
265
|
-
|
|
445
|
+
HarnessLog.info('fold key delete failed', { error: errorMessage(error) });
|
|
266
446
|
}
|
|
267
447
|
}
|
|
268
448
|
function renderedAt(history, spec, end) {
|
|
@@ -270,51 +450,71 @@ function renderedAt(history, spec, end) {
|
|
|
270
450
|
const matches = (at) => rendered.every((turn, index) => history[at + index]?.role === turn.role && history[at + index]?.content === turn.content);
|
|
271
451
|
return [0, 1].find(matches) ?? null;
|
|
272
452
|
}
|
|
273
|
-
function summarizer(
|
|
453
|
+
function summarizer(send) {
|
|
274
454
|
return async (prompt) => {
|
|
275
|
-
const params = completionParams({
|
|
276
|
-
modelId,
|
|
277
|
-
history: [{ role: 'user', content: prompt }],
|
|
278
|
-
generationParams: { reasoning_budget: 0 }
|
|
279
|
-
});
|
|
280
|
-
await args.recordRequest?.({ round: args.round, attempt: attempts.sent++, droppedTurns: 0, params }, []);
|
|
281
|
-
if (args.signal?.aborted) {
|
|
282
|
-
return { text: null, overflowed: false };
|
|
283
|
-
}
|
|
284
|
-
const result = withoutRepeatedReply(sdk.completion(params));
|
|
285
|
-
result.final.catch(noop);
|
|
286
|
-
const cancel = cancelOnce(sdk, result.requestId);
|
|
287
|
-
args.signal?.addEventListener('abort', cancel, { once: true });
|
|
288
|
-
let text = '';
|
|
289
455
|
try {
|
|
290
|
-
|
|
291
|
-
if (event.type === 'content') {
|
|
292
|
-
text += event.text;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
await raceAbort(result.final, args.signal);
|
|
296
|
-
return { text: args.signal?.aborted ? null : text, overflowed: false };
|
|
456
|
+
return await summarizeOnce(send, prompt);
|
|
297
457
|
}
|
|
298
458
|
catch (error) {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
459
|
+
if (!isKvCacheSaveFault(error)) {
|
|
460
|
+
return refusedSummary(error);
|
|
461
|
+
}
|
|
462
|
+
HarnessLog.info('kv cache save failed, retrying the fold summary', {
|
|
463
|
+
round: send.args.round,
|
|
464
|
+
error: errorMessage(error)
|
|
465
|
+
});
|
|
466
|
+
return summarizeOnce(send, prompt).catch(refusedSummary);
|
|
305
467
|
}
|
|
306
468
|
};
|
|
307
469
|
}
|
|
470
|
+
async function summarizeOnce(send, prompt) {
|
|
471
|
+
const { sdk, args, modelId, attempts } = send;
|
|
472
|
+
const params = completionParams({
|
|
473
|
+
modelId,
|
|
474
|
+
history: [{ role: 'user', content: prompt }],
|
|
475
|
+
generationParams: { reasoning_budget: 0 }
|
|
476
|
+
});
|
|
477
|
+
await args.recordRequest?.({ round: args.round, attempt: attempts.sent++, droppedTurns: 0, params }, []);
|
|
478
|
+
if (args.signal?.aborted) {
|
|
479
|
+
return { text: null, overflowed: false };
|
|
480
|
+
}
|
|
481
|
+
const result = withoutRepeatedReply(sdk.completion(params));
|
|
482
|
+
result.final.catch(noop);
|
|
483
|
+
const cancel = cancelOnce(sdk, result.requestId);
|
|
484
|
+
args.signal?.addEventListener('abort', cancel, { once: true });
|
|
485
|
+
let text = '';
|
|
486
|
+
try {
|
|
487
|
+
for await (const event of splitThinking(stopAtControlToken(contentDeltas(result.events), cancel))) {
|
|
488
|
+
if (event.type === 'content') {
|
|
489
|
+
text += event.text;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
await raceAbort(result.final, args.signal);
|
|
493
|
+
return { text: args.signal?.aborted ? null : text, overflowed: false };
|
|
494
|
+
}
|
|
495
|
+
catch (error) {
|
|
496
|
+
cancel();
|
|
497
|
+
throw error;
|
|
498
|
+
}
|
|
499
|
+
finally {
|
|
500
|
+
args.signal?.removeEventListener('abort', cancel);
|
|
501
|
+
await raceTimeout(cancel.flush(), { ms: TRUNCATED_FINAL_MS, fallback: undefined });
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
function refusedSummary(error) {
|
|
505
|
+
return { text: null, overflowed: isContextOverflowError(error) };
|
|
506
|
+
}
|
|
308
507
|
async function* runCandidateAttempts(input) {
|
|
309
508
|
const { sdk, args, modelId, candidate, history, origins, attempts } = input;
|
|
310
|
-
let attemptArgs = args;
|
|
509
|
+
let attemptArgs = attempts.uncached ? { ...args, cacheKey: undefined } : args;
|
|
311
510
|
while (true) {
|
|
312
511
|
if (args.signal?.aborted)
|
|
313
512
|
throw new AbortedError();
|
|
314
513
|
const progress = {
|
|
315
514
|
cancel: cancelOnce(sdk, undefined),
|
|
316
515
|
emitted: false,
|
|
317
|
-
attempt: attempts.sent
|
|
516
|
+
attempt: attempts.sent++,
|
|
517
|
+
unsettled: attempts.unsettled
|
|
318
518
|
};
|
|
319
519
|
try {
|
|
320
520
|
const round = yield* runCandidate({
|
|
@@ -326,7 +526,7 @@ async function* runCandidateAttempts(input) {
|
|
|
326
526
|
baseHistory: history,
|
|
327
527
|
origins
|
|
328
528
|
});
|
|
329
|
-
return { round };
|
|
529
|
+
return { round: attempts.uncached ? { ...round, cacheable: false } : round };
|
|
330
530
|
}
|
|
331
531
|
catch (err) {
|
|
332
532
|
if (err instanceof AbortedError || args.signal?.aborted) {
|
|
@@ -337,24 +537,36 @@ async function* runCandidateAttempts(input) {
|
|
|
337
537
|
}
|
|
338
538
|
const grammarOff = withoutToolGrammar(attemptArgs, err);
|
|
339
539
|
if (grammarOff) {
|
|
340
|
-
|
|
540
|
+
HarnessLog.info('tool grammar fault, retrying the round without it', { round: args.round });
|
|
341
541
|
yield* resetShownRound(args, progress);
|
|
342
542
|
attemptArgs = grammarOff;
|
|
343
543
|
continue;
|
|
344
544
|
}
|
|
345
545
|
const unforced = withoutForcedCall(attemptArgs, err);
|
|
346
546
|
if (unforced) {
|
|
347
|
-
|
|
547
|
+
HarnessLog.info('forced tool call refused, retrying the round without it', {
|
|
548
|
+
round: args.round
|
|
549
|
+
});
|
|
348
550
|
yield* resetShownRound(args, progress);
|
|
349
551
|
attemptArgs = unforced;
|
|
350
552
|
continue;
|
|
351
553
|
}
|
|
554
|
+
if (!attempts.uncached && isKvCacheSaveFault(err)) {
|
|
555
|
+
HarnessLog.info('kv cache save failed, retrying the round uncached', {
|
|
556
|
+
round: args.round,
|
|
557
|
+
error: errorMessage(err)
|
|
558
|
+
});
|
|
559
|
+
yield* resetShownRound(args, progress);
|
|
560
|
+
attempts.uncached = true;
|
|
561
|
+
attemptArgs = { ...attemptArgs, cacheKey: undefined };
|
|
562
|
+
continue;
|
|
563
|
+
}
|
|
352
564
|
if (!isContextOverflowError(err)) {
|
|
353
565
|
throw err;
|
|
354
566
|
}
|
|
355
567
|
if (progress.emitted) {
|
|
356
|
-
yield*
|
|
357
|
-
throw
|
|
568
|
+
yield* foldChat(input, history);
|
|
569
|
+
throw new HarnessError('CONTEXT_WINDOW_EXCEEDED', [], { cause: err });
|
|
358
570
|
}
|
|
359
571
|
return { overflow: err };
|
|
360
572
|
}
|
|
@@ -405,7 +617,9 @@ function recoveredRound({ candidate, attempt, origins }) {
|
|
|
405
617
|
history: restoreHistory(candidate.history, origins),
|
|
406
618
|
cacheable: attempt.cacheable,
|
|
407
619
|
unproven: attempt.state.unproven,
|
|
408
|
-
replay
|
|
620
|
+
replay,
|
|
621
|
+
reasoningDeltas: attempt.state.reasoningDeltas || undefined,
|
|
622
|
+
cut: attempt.state.cut ?? undefined
|
|
409
623
|
};
|
|
410
624
|
}
|
|
411
625
|
function historyOrigins(entries, messages) {
|
|
@@ -445,14 +659,25 @@ async function* runCandidate({ sdk, args, modelId, candidate, progress, baseHist
|
|
|
445
659
|
const result = withoutRepeatedReply(sdk.completion(params));
|
|
446
660
|
result.final.catch(noop);
|
|
447
661
|
progress.cancel = cancelOnce(sdk, result.requestId);
|
|
448
|
-
|
|
662
|
+
args.live.rawChars = 0;
|
|
663
|
+
args.live.reasoningDeltas = 0;
|
|
664
|
+
const state = {
|
|
665
|
+
live: args.live,
|
|
666
|
+
stopToken: null,
|
|
667
|
+
calls: [],
|
|
668
|
+
runaway: false,
|
|
669
|
+
cut: null,
|
|
670
|
+
unproven: null,
|
|
671
|
+
rawContentText: '',
|
|
672
|
+
reasoningDeltas: 0
|
|
673
|
+
};
|
|
449
674
|
const contentText = yield* streamCandidateTokens({ result, state, args, progress });
|
|
450
|
-
const final = state.stopToken
|
|
675
|
+
const final = state.stopToken || state.runaway || state.cut !== null
|
|
451
676
|
? await truncatedFinal(result.final, state.rawContentText)
|
|
452
677
|
: await raceAbort(result.final, args.signal);
|
|
453
678
|
const detachedFinal = {
|
|
454
679
|
...final,
|
|
455
|
-
toolCalls: copy(final.toolCalls ?? []),
|
|
680
|
+
toolCalls: copy(state.runaway || state.cut !== null ? state.calls : (final.toolCalls ?? [])),
|
|
456
681
|
toolErrors: copy(final.toolErrors ?? []),
|
|
457
682
|
stats: copy(final.stats)
|
|
458
683
|
};
|
|
@@ -466,12 +691,16 @@ function inferenceParams({ args, modelId, history, cacheable }) {
|
|
|
466
691
|
modelId,
|
|
467
692
|
history: detachJson(history),
|
|
468
693
|
tools: args.tools ? detachJson(args.tools) : undefined,
|
|
469
|
-
generationParams:
|
|
694
|
+
generationParams: generationParams(args),
|
|
470
695
|
responseFormat: args.responseFormat ? detachJson(args.responseFormat) : undefined,
|
|
471
696
|
toolDialect: args.toolDialect,
|
|
472
697
|
kvCache: cacheable ? args.cacheKey : undefined
|
|
473
698
|
});
|
|
474
699
|
}
|
|
700
|
+
function generationParams(args) {
|
|
701
|
+
const host = args.generationParams ? detachJson(args.generationParams) : undefined;
|
|
702
|
+
return args.tools?.length ? { parallel_tool_calls: true, ...host } : host;
|
|
703
|
+
}
|
|
475
704
|
function inferenceCall({ args, candidate, modelId, params, cacheKey }) {
|
|
476
705
|
return {
|
|
477
706
|
type: 'inference-call',
|
|
@@ -494,7 +723,6 @@ function inferenceSent({ args, candidate, final }) {
|
|
|
494
723
|
type: 'inference-sent',
|
|
495
724
|
round: args.round,
|
|
496
725
|
droppedTurns: candidate.droppedTurns,
|
|
497
|
-
messages: sentMessages(final.stats),
|
|
498
726
|
tokens: roundTokens(final.stats),
|
|
499
727
|
outcome: 'completed',
|
|
500
728
|
reason: undefined
|
|
@@ -502,13 +730,15 @@ function inferenceSent({ args, candidate, final }) {
|
|
|
502
730
|
}
|
|
503
731
|
async function* streamCandidateTokens({ result, state, args, progress }) {
|
|
504
732
|
let contentText = '';
|
|
505
|
-
const startInThink = args.generationParams?.reasoning_budget
|
|
733
|
+
const startInThink = (args.generationParams?.reasoning_budget ?? 0) !== 0;
|
|
506
734
|
for await (const event of runRoundTokens({
|
|
507
735
|
result,
|
|
508
736
|
state,
|
|
509
737
|
cancelThisRound: progress.cancel,
|
|
738
|
+
unsettled: progress.unsettled,
|
|
510
739
|
signal: args.signal,
|
|
511
|
-
startInThink
|
|
740
|
+
startInThink,
|
|
741
|
+
knownTools: args.knownTools ?? []
|
|
512
742
|
})) {
|
|
513
743
|
if (event.type === 'content') {
|
|
514
744
|
contentText += event.text;
|
|
@@ -523,19 +753,20 @@ function candidateFailureEvent({ args, candidate, error }) {
|
|
|
523
753
|
type: 'inference-sent',
|
|
524
754
|
round: args.round,
|
|
525
755
|
droppedTurns: candidate.droppedTurns,
|
|
526
|
-
messages: undefined,
|
|
527
756
|
tokens: undefined,
|
|
528
757
|
outcome: isContextOverflowError(error) ? 'overflowed' : 'failed',
|
|
529
758
|
reason: errorMessage(error)
|
|
530
759
|
};
|
|
531
760
|
}
|
|
532
761
|
function logCandidateFinal({ state, final, contentText }, replay) {
|
|
533
|
-
|
|
762
|
+
HarnessLog.debug('final', {
|
|
534
763
|
stopReason: final.stopReason,
|
|
535
764
|
toolCalls: final.toolCalls.length,
|
|
536
765
|
toolErrors: final.toolErrors?.length ?? 0,
|
|
537
766
|
contentChars: contentText.length,
|
|
538
767
|
stopToken: state.stopToken,
|
|
768
|
+
runaway: state.runaway,
|
|
769
|
+
cut: state.cut !== null,
|
|
539
770
|
replay: replay !== null
|
|
540
771
|
});
|
|
541
772
|
}
|
|
@@ -561,8 +792,3 @@ function restoreHistory(messages, origins) {
|
|
|
561
792
|
return source ? { ...origin.entry, compactedTo: message.content.length } : origin.entry;
|
|
562
793
|
});
|
|
563
794
|
}
|
|
564
|
-
function errorWithCause(message, cause) {
|
|
565
|
-
const error = new Error(message);
|
|
566
|
-
Object.defineProperty(error, 'cause', { value: cause, configurable: true });
|
|
567
|
-
return error;
|
|
568
|
-
}
|