@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
|
@@ -10,6 +10,7 @@ export class Fold {
|
|
|
10
10
|
static TIERS = TIERS;
|
|
11
11
|
static RATIO = 0.95;
|
|
12
12
|
static KEEP_TURNS = 1;
|
|
13
|
+
static KEEP_ROUNDS = 2;
|
|
13
14
|
static PREFIX = '[Summary of the earlier conversation in this chat, written by another model. Treat it as established context, not as a new request.]';
|
|
14
15
|
summarize;
|
|
15
16
|
constructor(summarize) {
|
|
@@ -21,13 +22,25 @@ export class Fold {
|
|
|
21
22
|
static isSummary(message) {
|
|
22
23
|
return message.role === 'user' && message.content.startsWith(Fold.PREFIX);
|
|
23
24
|
}
|
|
25
|
+
static isTurn(message, nudges) {
|
|
26
|
+
return (message.role === 'user' &&
|
|
27
|
+
!Fold.isSummary(message) &&
|
|
28
|
+
!nudges.includes(message.content) &&
|
|
29
|
+
!Fold.carriesPlan(message, nudges));
|
|
30
|
+
}
|
|
31
|
+
static carriesPlan(message, nudges) {
|
|
32
|
+
return (message.role === 'user' &&
|
|
33
|
+
nudges.some((nudge) => message.content.startsWith(`${nudge}\nPlan:\n`)));
|
|
34
|
+
}
|
|
24
35
|
static ratio(ctxSize) {
|
|
25
36
|
return TIERS.find(([below]) => ctxSize < below)?.[1] ?? Fold.RATIO;
|
|
26
37
|
}
|
|
27
38
|
static fits(ctxSize) {
|
|
28
39
|
return ctxSize === undefined || ctxSize >= Fold.FLOOR;
|
|
29
40
|
}
|
|
30
|
-
static due({ cacheTokens, ctxSize }) {
|
|
41
|
+
static due({ cacheTokens, ctxSize, cutOff }) {
|
|
42
|
+
if (cutOff)
|
|
43
|
+
return true;
|
|
31
44
|
if (!cacheTokens || !ctxSize)
|
|
32
45
|
return false;
|
|
33
46
|
return cacheTokens >= ctxSize * Fold.ratio(ctxSize);
|
|
@@ -49,18 +62,30 @@ export class Fold {
|
|
|
49
62
|
const end = users[users.length - keepTurns];
|
|
50
63
|
return end > 0 ? { end, foldedTurns: users.length - keepTurns } : null;
|
|
51
64
|
}
|
|
65
|
+
static roundBoundary(messages, { nudges, keeps }, most = Infinity) {
|
|
66
|
+
const task = messages.findLastIndex((message) => Fold.isTurn(message, nudges));
|
|
67
|
+
if (task === -1) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
const starts = messages.flatMap((message, at) => at > task && message.role === 'assistant' ? [at] : []);
|
|
71
|
+
const plan = messages.findLastIndex((message, at) => at > task && Fold.carriesPlan(message, nudges));
|
|
72
|
+
const kept = (from, to) => (plan >= from && plan < to) || messages.slice(from, to).some(keeps);
|
|
73
|
+
const rounds = starts
|
|
74
|
+
.map((from, index) => [from, starts[index + 1] ?? messages.length])
|
|
75
|
+
.slice(0, Math.max(0, starts.length - Fold.KEEP_ROUNDS))
|
|
76
|
+
.filter(([from, to]) => !kept(from, to))
|
|
77
|
+
.slice(0, most);
|
|
78
|
+
const summaries = messages.flatMap((message, at) => at > task && Fold.isSummary(message) ? [at] : []);
|
|
79
|
+
const folded = rounds.flatMap(([from, to]) => Array.from({ length: to - from }, (_, offset) => from + offset));
|
|
80
|
+
return { task, folded: [...summaries, ...folded], foldedRounds: rounds.length };
|
|
81
|
+
}
|
|
52
82
|
static prompt(messages, instructions) {
|
|
53
|
-
const prior = messages
|
|
54
|
-
const transcript = messages
|
|
55
|
-
.map((message) => {
|
|
56
|
-
const sender = message.role === 'user' && message.name ? `${message.name}: ` : '';
|
|
57
|
-
return `${message.role === 'user' ? 'User' : 'Assistant'}: ${sender}${message.content}`;
|
|
58
|
-
})
|
|
59
|
-
.join('\n\n');
|
|
83
|
+
const prior = messages.some(Fold.isSummary);
|
|
84
|
+
const transcript = messages.map(transcribed).join('\n\n');
|
|
60
85
|
return [
|
|
61
86
|
'Summarize the conversation below so another model can continue it without seeing it.',
|
|
62
87
|
prior
|
|
63
|
-
? 'The conversation
|
|
88
|
+
? 'The conversation carries an earlier summary. Carry everything from it that is still true into your new summary — it is discarded after this, so whatever you leave out is lost — and correct it where the later turns disagree.'
|
|
64
89
|
: null,
|
|
65
90
|
'Output exactly these four sections, in this order, keeping every heading even when it has nothing under it:',
|
|
66
91
|
'## Objective\n## Facts and decisions\n## State\n## Next steps',
|
|
@@ -120,4 +145,45 @@ export class Fold {
|
|
|
120
145
|
};
|
|
121
146
|
}
|
|
122
147
|
}
|
|
148
|
+
async rounds(messages, options) {
|
|
149
|
+
if (!Fold.fits(options.ctxSize)) {
|
|
150
|
+
return { folded: false, reason: 'below-floor' };
|
|
151
|
+
}
|
|
152
|
+
let most = Infinity;
|
|
153
|
+
for (;;) {
|
|
154
|
+
const boundary = Fold.roundBoundary(messages, options, most);
|
|
155
|
+
if (!boundary?.foldedRounds) {
|
|
156
|
+
const summarized = boundary !== null && boundary.folded.length > 0;
|
|
157
|
+
return { folded: false, reason: summarized ? 'already-compacted' : 'nothing-to-fold' };
|
|
158
|
+
}
|
|
159
|
+
const folded = boundary.folded.map((at) => messages[at]);
|
|
160
|
+
const attempt = await this.summarize(Fold.prompt([messages[boundary.task], ...folded], options.instructions));
|
|
161
|
+
const summary = attempt.text?.trim() || null;
|
|
162
|
+
if (!summary) {
|
|
163
|
+
if (attempt.overflowed && boundary.foldedRounds > 1) {
|
|
164
|
+
most = Math.floor(boundary.foldedRounds / 2);
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
return { folded: false, reason: 'no-summary' };
|
|
168
|
+
}
|
|
169
|
+
if (!Fold.shrinks(folded, summary)) {
|
|
170
|
+
return { folded: false, reason: 'summary-not-smaller' };
|
|
171
|
+
}
|
|
172
|
+
const history = spliced(messages, boundary, summary);
|
|
173
|
+
return { folded: true, history, summary, foldedRounds: boundary.foldedRounds };
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
function spliced(messages, boundary, summary) {
|
|
178
|
+
const gone = new Set(boundary.folded);
|
|
179
|
+
return [
|
|
180
|
+
...messages.slice(0, boundary.task + 1),
|
|
181
|
+
{ role: 'user', content: Fold.turn(summary) },
|
|
182
|
+
...messages.filter((_, at) => at > boundary.task && !gone.has(at))
|
|
183
|
+
];
|
|
184
|
+
}
|
|
185
|
+
const SENDERS = { user: 'User', tool: 'Tool result' };
|
|
186
|
+
function transcribed(message) {
|
|
187
|
+
const sender = message.role === 'user' && message.name ? `${message.name}: ` : '';
|
|
188
|
+
return `${SENDERS[message.role] ?? 'Assistant'}: ${sender}${message.content}`;
|
|
123
189
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AbortController } from 'bare-abort-controller';
|
|
2
2
|
import b4a from 'b4a';
|
|
3
3
|
import { noRedirectFetch } from '#no-redirect-fetch';
|
|
4
|
+
import { HarnessError } from './errors.js';
|
|
4
5
|
import { lookupHost } from './dns-lookup.js';
|
|
5
6
|
import { checkOutboundHost, resolveOutboundUrl } from './tools/url-guard.js';
|
|
6
7
|
export const MAX_RESPONSE_BYTES = 100 * 1024 * 1024;
|
|
@@ -164,18 +165,21 @@ export function createGuardedFetch(options = {}) {
|
|
|
164
165
|
try {
|
|
165
166
|
for (let hops = 0;; hops++) {
|
|
166
167
|
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
|
|
167
|
-
throw new
|
|
168
|
+
throw new HarnessError('FETCH_REFUSED', [`unsupported protocol ${url.protocol}`]);
|
|
168
169
|
}
|
|
169
170
|
const literal = checkOutboundHost(url);
|
|
170
171
|
if (literal) {
|
|
171
|
-
throw new
|
|
172
|
+
throw new HarnessError('FETCH_REFUSED', [`${literal}`]);
|
|
172
173
|
}
|
|
173
174
|
if (!(await mayConnect(url.hostname))) {
|
|
174
|
-
throw new
|
|
175
|
+
throw new HarnessError('FETCH_REFUSED', [`${url.hostname} was not approved for this run`]);
|
|
175
176
|
}
|
|
176
|
-
const check = await resolveOutboundUrl(url,
|
|
177
|
+
const check = await resolveOutboundUrl(url, {
|
|
178
|
+
resolveHost,
|
|
179
|
+
signal: controller.signal
|
|
180
|
+
});
|
|
177
181
|
if (check.blocked) {
|
|
178
|
-
throw new
|
|
182
|
+
throw new HarnessError('FETCH_REFUSED', [`${check.blocked}`]);
|
|
179
183
|
}
|
|
180
184
|
const response = await send(url, {
|
|
181
185
|
method,
|
|
@@ -195,10 +199,10 @@ export function createGuardedFetch(options = {}) {
|
|
|
195
199
|
});
|
|
196
200
|
}
|
|
197
201
|
if (init.redirect === 'error') {
|
|
198
|
-
throw new
|
|
202
|
+
throw new HarnessError('FETCH_REFUSED', ['redirect not allowed']);
|
|
199
203
|
}
|
|
200
204
|
if (hops >= MAX_REDIRECTS) {
|
|
201
|
-
throw new
|
|
205
|
+
throw new HarnessError('FETCH_REFUSED', ['too many redirects']);
|
|
202
206
|
}
|
|
203
207
|
const next = new URL(location, url);
|
|
204
208
|
if (next.protocol !== url.protocol || next.host !== url.host) {
|
|
@@ -4,9 +4,12 @@ import os from 'os';
|
|
|
4
4
|
import { readSystemStats } from '#hw-gpu-stats';
|
|
5
5
|
const FLAG = '--gpu-probe';
|
|
6
6
|
const TIMEOUT_MS = 5000;
|
|
7
|
+
let relaunchable = false;
|
|
7
8
|
export function runGpuProbeIfRequested() {
|
|
8
|
-
|
|
9
|
+
relaunchable = true;
|
|
10
|
+
if (!Bare.argv.includes(FLAG)) {
|
|
9
11
|
return;
|
|
12
|
+
}
|
|
10
13
|
console.log(JSON.stringify(readSystemStats()));
|
|
11
14
|
queueMicrotask(() => Bare.exit(0));
|
|
12
15
|
}
|
|
@@ -48,9 +51,15 @@ export function spawnGpuProbe(entry = Bare.argv[1]) {
|
|
|
48
51
|
});
|
|
49
52
|
}
|
|
50
53
|
export async function probeGpuStats() {
|
|
54
|
+
if (typeof Bare !== 'undefined' && Bare.argv.includes(FLAG)) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
51
57
|
const platform = os.platform();
|
|
52
58
|
if (typeof Bare === 'undefined' || (platform !== 'linux' && platform !== 'win32')) {
|
|
53
59
|
return readSystemStats();
|
|
54
60
|
}
|
|
61
|
+
if (!relaunchable) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
55
64
|
return (await spawnGpuProbe()).stats;
|
|
56
65
|
}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
import type { CompletionSdk } from '../contract/index.ts';
|
|
1
|
+
import type { CompletionSdk, Message } from '../contract/index.ts';
|
|
2
2
|
export type CompletionParams = Parameters<CompletionSdk['completion']>[0];
|
|
3
|
-
|
|
3
|
+
interface CompletionParamsInput extends Omit<CompletionParams, 'stream' | 'history'> {
|
|
4
|
+
history: Message[];
|
|
5
|
+
}
|
|
6
|
+
export declare function completionParams({ modelId, history, tools, generationParams, responseFormat, toolDialect, kvCache }: CompletionParamsInput): CompletionParams;
|
|
7
|
+
export {};
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
+
function isSdkMessage(turn) {
|
|
2
|
+
return turn.toolCalls !== null && turn.toolCallId !== null;
|
|
3
|
+
}
|
|
1
4
|
export function completionParams({ modelId, history, tools, generationParams, responseFormat, toolDialect, kvCache }) {
|
|
2
5
|
return {
|
|
3
6
|
modelId,
|
|
4
|
-
history
|
|
7
|
+
history: history.map((turn) => isSdkMessage(turn)
|
|
8
|
+
? turn
|
|
9
|
+
: {
|
|
10
|
+
...turn,
|
|
11
|
+
toolCalls: turn.toolCalls ?? undefined,
|
|
12
|
+
toolCallId: turn.toolCallId ?? undefined
|
|
13
|
+
}),
|
|
5
14
|
stream: true,
|
|
6
15
|
tools,
|
|
7
16
|
generationParams,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { HarnessError } from '../errors.ts';
|
|
1
2
|
import type { Operation } from '../contract/run.ts';
|
|
2
3
|
export declare class RecoveryRequired extends Error {
|
|
3
4
|
readonly operation: Operation;
|
|
@@ -8,7 +9,7 @@ export declare class HookHalt extends Error {
|
|
|
8
9
|
readonly hook: string;
|
|
9
10
|
constructor(reason: string, hook: string);
|
|
10
11
|
}
|
|
11
|
-
export declare class AbortedError extends
|
|
12
|
+
export declare class AbortedError extends HarnessError<'ABORTED'> {
|
|
12
13
|
constructor();
|
|
13
14
|
}
|
|
14
15
|
export interface ErrorCause {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { HarnessError } from '../errors.js';
|
|
1
2
|
export class RecoveryRequired extends Error {
|
|
2
3
|
operation;
|
|
3
4
|
constructor(operation) {
|
|
@@ -14,11 +15,9 @@ export class HookHalt extends Error {
|
|
|
14
15
|
this.hook = hook;
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
|
-
export class AbortedError extends
|
|
18
|
+
export class AbortedError extends HarnessError {
|
|
18
19
|
constructor() {
|
|
19
|
-
super('
|
|
20
|
-
this.name = 'AbortedError';
|
|
21
|
-
Error.captureStackTrace?.(this, AbortedError);
|
|
20
|
+
super('ABORTED');
|
|
22
21
|
}
|
|
23
22
|
}
|
|
24
23
|
const CAUSE_DEPTH = 3;
|
|
@@ -44,10 +43,7 @@ function tagCause(error, depth) {
|
|
|
44
43
|
else if (object && typeof ownData(object, 'name') === 'string') {
|
|
45
44
|
name = ownData(object, 'name');
|
|
46
45
|
}
|
|
47
|
-
const code = object
|
|
48
|
-
?
|
|
49
|
-
ownData(object, 'code')
|
|
50
|
-
: undefined;
|
|
46
|
+
const code = object ? ownCode(object) : undefined;
|
|
51
47
|
const stack = error instanceof Error ? error.stack : undefined;
|
|
52
48
|
const cause = object ? tagCause(ownData(object, 'cause'), depth - 1) : undefined;
|
|
53
49
|
const taggedCause = { message, name };
|
|
@@ -260,10 +256,7 @@ export function tagError(error) {
|
|
|
260
256
|
}
|
|
261
257
|
return aborted;
|
|
262
258
|
}
|
|
263
|
-
|
|
264
|
-
if (object && typeof ownData(object, 'code') === 'string') {
|
|
265
|
-
code = ownData(object, 'code');
|
|
266
|
-
}
|
|
259
|
+
const code = object ? ownCode(object) : undefined;
|
|
267
260
|
const cause = object ? tagCause(ownData(object, 'cause'), CAUSE_DEPTH) : undefined;
|
|
268
261
|
const failed = {
|
|
269
262
|
tag: 'failed',
|
|
@@ -330,6 +323,13 @@ function rehydrateCause(value, depth = CAUSE_DEPTH) {
|
|
|
330
323
|
}
|
|
331
324
|
return error;
|
|
332
325
|
}
|
|
326
|
+
function ownCode(object) {
|
|
327
|
+
const code = ownData(object, 'code');
|
|
328
|
+
if (typeof code === 'string') {
|
|
329
|
+
return code;
|
|
330
|
+
}
|
|
331
|
+
return typeof code === 'number' && Number.isFinite(code) ? String(code) : undefined;
|
|
332
|
+
}
|
|
333
333
|
function errorMessage(value) {
|
|
334
334
|
if (typeof value === 'string')
|
|
335
335
|
return value;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
const SHELL_OPERATOR = /(&&|\|\||;|\||\n)/;
|
|
2
|
+
const RUNNER = /^(python[\d.]*|bash|sh|node|bun|pytest)$/;
|
|
3
|
+
const CHECKS_HEADING = /^[\s*#_]*checks:?[\s*_]*$/i;
|
|
4
|
+
const CHECK_LINE = /^\s*(?:[-*]|\d+[.)])?\s*`([^`]+)`\s*$/;
|
|
5
|
+
export const MAX_GOAL_CHECKS = 8;
|
|
6
|
+
export const GOAL_CHECKS_ASK = '[This goal has no checks yet. Name the commands that will prove the task is done: write a ' +
|
|
7
|
+
'line `Checks:`, then one command per line in backticks, such as `test -s /app/result.json` ' +
|
|
8
|
+
'or `python3 check.py`. Each must exit 0 only once the task is done, with no pipe, ; or && ' +
|
|
9
|
+
'in it. The goal is met only once each of them ran on its own and exited 0.]';
|
|
10
|
+
export function namedChecks(text) {
|
|
11
|
+
const lines = text.split('\n');
|
|
12
|
+
const heading = lines.findIndex((line) => CHECKS_HEADING.test(line));
|
|
13
|
+
if (heading < 0) {
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
const named = [];
|
|
17
|
+
for (const line of lines.slice(heading + 1)) {
|
|
18
|
+
const command = CHECK_LINE.exec(line)?.[1].trim();
|
|
19
|
+
if (!command) {
|
|
20
|
+
if (line.trim() || named.length) {
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (runsCheck(command, command) && !named.includes(command)) {
|
|
26
|
+
named.push(command);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return named.slice(0, MAX_GOAL_CHECKS);
|
|
30
|
+
}
|
|
31
|
+
export function runsCheck(command, check) {
|
|
32
|
+
const wanted = words(check);
|
|
33
|
+
const parts = command.split(SHELL_OPERATOR);
|
|
34
|
+
for (let at = parts.length - 1; at >= 0; at -= 2) {
|
|
35
|
+
if (!parts[at].trim()) {
|
|
36
|
+
parts.splice(at === parts.length - 1 ? Math.max(at - 1, 0) : at, 2);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
for (let at = 0; at < parts.length; at += 2) {
|
|
40
|
+
const after = parts.slice(at + 1).filter((_, n) => n % 2 === 0);
|
|
41
|
+
if (parts[at - 1] !== '||' &&
|
|
42
|
+
after.every((operator) => operator === '&&') &&
|
|
43
|
+
invokes(words(parts[at]), wanted)) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
function words(text) {
|
|
50
|
+
return text
|
|
51
|
+
.trim()
|
|
52
|
+
.split(/\s+/)
|
|
53
|
+
.filter(Boolean)
|
|
54
|
+
.map((word) => word.replace(/^['"]|['"]$/g, ''));
|
|
55
|
+
}
|
|
56
|
+
function invokes(tokens, wanted) {
|
|
57
|
+
let start = tokens.findIndex((token) => !/^\w+=/.test(token));
|
|
58
|
+
if (start < 0) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
if (leads(tokens.slice(start), wanted)) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
if (!RUNNER.test(tokens[start].split('/').at(-1) ?? '')) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
start++;
|
|
68
|
+
while (tokens[start]?.startsWith('-')) {
|
|
69
|
+
start++;
|
|
70
|
+
}
|
|
71
|
+
return leads(tokens.slice(start), wanted);
|
|
72
|
+
}
|
|
73
|
+
function leads(tokens, wanted) {
|
|
74
|
+
return (wanted.length > 0 &&
|
|
75
|
+
wanted.every((word, at) => tokens[at] !== undefined && samePath(tokens[at], word)));
|
|
76
|
+
}
|
|
77
|
+
function samePath(a, b) {
|
|
78
|
+
const left = a.replace(/^\.\//, '');
|
|
79
|
+
const right = b.replace(/^\.\//, '');
|
|
80
|
+
return left === right || left.endsWith(`/${right}`) || right.endsWith(`/${left}`);
|
|
81
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
function omitted(count, locator, startLine) {
|
|
2
|
-
const where = locator ? `;
|
|
2
|
+
const where = locator ? `; read_file path=${locator} startLine=${startLine}` : '';
|
|
3
3
|
return `\n…[${count} chars omitted${where}]…\n`;
|
|
4
4
|
}
|
|
5
5
|
export function headTail(text, limit) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export function createLoadStall(ms,
|
|
1
|
+
export function createLoadStall(ms, stalled) {
|
|
2
2
|
let timer = null;
|
|
3
3
|
let rejectStall = null;
|
|
4
4
|
const promise = new Promise((_, reject) => {
|
|
@@ -9,7 +9,7 @@ export function createLoadStall(ms, message) {
|
|
|
9
9
|
clearTimeout(timer);
|
|
10
10
|
}
|
|
11
11
|
timer = setTimeout(() => {
|
|
12
|
-
rejectStall?.(
|
|
12
|
+
rejectStall?.(stalled());
|
|
13
13
|
}, ms);
|
|
14
14
|
};
|
|
15
15
|
arm();
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
export interface MarkupStreamFilterOptions {
|
|
2
|
+
readonly onToolCall?: (body: string) => void;
|
|
3
|
+
}
|
|
1
4
|
export interface MarkupStreamFilter {
|
|
2
5
|
readonly push: (token: string) => string;
|
|
3
6
|
readonly flush: () => string;
|
|
4
7
|
}
|
|
5
|
-
export declare function createMarkupStreamFilter(): MarkupStreamFilter;
|
|
8
|
+
export declare function createMarkupStreamFilter(options?: MarkupStreamFilterOptions): MarkupStreamFilter;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { holdback } from 'asenion/scan';
|
|
2
2
|
import { createJoinGuard } from './join-guard.js';
|
|
3
3
|
import { scanNamedMarkup } from './markup-scanner.js';
|
|
4
|
-
const
|
|
4
|
+
const TOOL_CALL_OPEN = '<tool_call>';
|
|
5
|
+
const MARKUP_OPENERS = [TOOL_CALL_OPEN, '<tool_response>'];
|
|
5
6
|
const MARKUP_CLOSERS = {
|
|
6
7
|
'<tool_call>': '</tool_call>',
|
|
7
8
|
'<tool_response>': '</tool_response>'
|
|
@@ -9,13 +10,15 @@ const MARKUP_CLOSERS = {
|
|
|
9
10
|
const MARKUP_MARKERS = [...MARKUP_OPENERS, ...Object.values(MARKUP_CLOSERS)];
|
|
10
11
|
const FUNCTION_CLOSE = '</function>';
|
|
11
12
|
const JOIN_MARKERS = [...MARKUP_MARKERS, '<function', '</function>', '<FUNCTION', '</FUNCTION>'];
|
|
12
|
-
function initialState() {
|
|
13
|
+
function initialState({ onToolCall = noop }) {
|
|
13
14
|
return {
|
|
14
15
|
buffer: '',
|
|
15
16
|
lower: '',
|
|
16
17
|
markerAt: MARKUP_MARKERS.map(() => -1),
|
|
17
18
|
namedFrom: 0,
|
|
18
19
|
closer: null,
|
|
20
|
+
held: null,
|
|
21
|
+
onToolCall,
|
|
19
22
|
candidate: null,
|
|
20
23
|
candidateTail: '',
|
|
21
24
|
stripNewline: false,
|
|
@@ -67,8 +70,8 @@ function nextStep(state) {
|
|
|
67
70
|
}
|
|
68
71
|
return state.closer ? consumeSuppressed(state) : emitUntilOpener(state);
|
|
69
72
|
}
|
|
70
|
-
export function createMarkupStreamFilter() {
|
|
71
|
-
const state = initialState();
|
|
73
|
+
export function createMarkupStreamFilter(options = {}) {
|
|
74
|
+
const state = initialState(options);
|
|
72
75
|
return {
|
|
73
76
|
push(token) {
|
|
74
77
|
appendBuffer(state, token);
|
|
@@ -87,6 +90,7 @@ export function createMarkupStreamFilter() {
|
|
|
87
90
|
function resetPending(state) {
|
|
88
91
|
setBuffer(state, '');
|
|
89
92
|
state.closer = null;
|
|
93
|
+
state.held = null;
|
|
90
94
|
state.candidate = null;
|
|
91
95
|
state.candidateTail = '';
|
|
92
96
|
state.stripNewline = false;
|
|
@@ -112,10 +116,18 @@ function consumeSuppressed(state) {
|
|
|
112
116
|
const closer = state.closer ?? '';
|
|
113
117
|
const end = state.buffer.indexOf(closer);
|
|
114
118
|
if (end === -1) {
|
|
115
|
-
const
|
|
116
|
-
|
|
119
|
+
const kept = state.buffer.length - holdback(state.buffer, [closer]);
|
|
120
|
+
if (state.held !== null) {
|
|
121
|
+
state.held += state.buffer.slice(0, kept);
|
|
122
|
+
}
|
|
123
|
+
setBuffer(state, state.buffer.slice(kept));
|
|
117
124
|
return { out: '', done: true };
|
|
118
125
|
}
|
|
126
|
+
if (state.held !== null) {
|
|
127
|
+
const body = state.held + state.buffer.slice(0, end);
|
|
128
|
+
state.held = null;
|
|
129
|
+
state.onToolCall(body);
|
|
130
|
+
}
|
|
119
131
|
setBuffer(state, state.buffer.slice(end + closer.length));
|
|
120
132
|
state.stripNewline = true;
|
|
121
133
|
state.closer = null;
|
|
@@ -143,6 +155,7 @@ function consumeFixedMarker(state, index, marker) {
|
|
|
143
155
|
const closer = MARKUP_CLOSERS[marker];
|
|
144
156
|
state.stripNewline = closer === undefined;
|
|
145
157
|
state.closer = closer ?? null;
|
|
158
|
+
state.held = marker === TOOL_CALL_OPEN ? '' : null;
|
|
146
159
|
return { out, done: false };
|
|
147
160
|
}
|
|
148
161
|
function scanNamedOpen(buffer, haystack, start) {
|
|
@@ -179,3 +192,4 @@ function emitUntilOpener(state) {
|
|
|
179
192
|
setBuffer(state, state.buffer.slice(state.buffer.length - hold));
|
|
180
193
|
return { out, done: true };
|
|
181
194
|
}
|
|
195
|
+
function noop() { }
|
|
@@ -17,28 +17,36 @@ function firstHalf(items, key) {
|
|
|
17
17
|
const repeats = items.slice(half).every((item, at) => key(item) === key(items[at]));
|
|
18
18
|
return repeats ? items.slice(0, half) : items;
|
|
19
19
|
}
|
|
20
|
-
async function* withoutRepeatedTail(
|
|
20
|
+
async function* withoutRepeatedTail(events) {
|
|
21
21
|
let streamed = '';
|
|
22
|
-
let held =
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
let held = [];
|
|
23
|
+
let heldText = '';
|
|
24
|
+
for await (const event of events) {
|
|
25
|
+
if (event.type !== 'contentDelta') {
|
|
26
|
+
yield event;
|
|
26
27
|
continue;
|
|
27
28
|
}
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
if (heldText && streamed.startsWith(heldText + event.text)) {
|
|
30
|
+
held.push(event);
|
|
31
|
+
heldText += event.text;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (heldText) {
|
|
35
|
+
yield* held;
|
|
36
|
+
streamed += heldText;
|
|
37
|
+
held = [];
|
|
38
|
+
heldText = '';
|
|
32
39
|
}
|
|
33
|
-
if (streamed.length >= MIN_REPEAT_CHARS &&
|
|
34
|
-
held =
|
|
40
|
+
if (streamed.length >= MIN_REPEAT_CHARS && event.text && streamed.startsWith(event.text)) {
|
|
41
|
+
held = [event];
|
|
42
|
+
heldText = event.text;
|
|
35
43
|
continue;
|
|
36
44
|
}
|
|
37
|
-
streamed +=
|
|
38
|
-
yield
|
|
45
|
+
streamed += event.text;
|
|
46
|
+
yield event;
|
|
39
47
|
}
|
|
40
|
-
if (
|
|
41
|
-
yield held;
|
|
48
|
+
if (heldText && heldText !== streamed) {
|
|
49
|
+
yield* held;
|
|
42
50
|
}
|
|
43
51
|
}
|
|
44
52
|
function once(reply) {
|
|
@@ -58,6 +66,6 @@ function once(reply) {
|
|
|
58
66
|
export function withoutRepeatedReply(result) {
|
|
59
67
|
const final = result.final.then(once);
|
|
60
68
|
final.catch(noop);
|
|
61
|
-
return { ...result,
|
|
69
|
+
return { ...result, events: withoutRepeatedTail(result.events), final };
|
|
62
70
|
}
|
|
63
71
|
function noop() { }
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type TextEvent = {
|
|
2
2
|
type: 'thinking' | 'content';
|
|
3
3
|
text: string;
|
|
4
|
-
}
|
|
4
|
+
};
|
|
5
5
|
export interface SplitThinkingOptions {
|
|
6
6
|
startInThink?: boolean;
|
|
7
7
|
}
|
|
8
|
+
export declare function tapThinking(tokens: AsyncIterable<string>, opts: SplitThinkingOptions, onThinking: () => void): AsyncGenerator<string>;
|
|
8
9
|
export declare function splitThinking(tokens: AsyncIterable<string>, opts?: SplitThinkingOptions): AsyncGenerator<TextEvent, string | null>;
|
|
@@ -24,6 +24,25 @@ function nextTag(buffer, inThink) {
|
|
|
24
24
|
}
|
|
25
25
|
return open && { ...open, inThink: true };
|
|
26
26
|
}
|
|
27
|
+
export async function* tapThinking(tokens, opts, onThinking) {
|
|
28
|
+
let inThink = opts.startInThink === true;
|
|
29
|
+
let tail = '';
|
|
30
|
+
for await (const token of tokens) {
|
|
31
|
+
const wasThinking = inThink;
|
|
32
|
+
tail += token;
|
|
33
|
+
let tag = firstMarker(tail, inThink ? CLOSE_TAGS : OPEN_TAGS);
|
|
34
|
+
while (tag) {
|
|
35
|
+
tail = tail.slice(tag.index + tag.marker.length);
|
|
36
|
+
inThink = !inThink;
|
|
37
|
+
tag = firstMarker(tail, inThink ? CLOSE_TAGS : OPEN_TAGS);
|
|
38
|
+
}
|
|
39
|
+
tail = tail.slice(tail.length - holdback(tail, inThink ? CLOSE_TAGS : OPEN_TAGS));
|
|
40
|
+
if (wasThinking && inThink) {
|
|
41
|
+
onThinking();
|
|
42
|
+
}
|
|
43
|
+
yield token;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
27
46
|
export async function* splitThinking(tokens, opts) {
|
|
28
47
|
let buffer = '';
|
|
29
48
|
let inThink = opts?.startInThink === true;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsonrepair } from 'jsonrepair';
|
|
2
2
|
import { isRecord } from '../../guards.js';
|
|
3
|
-
import {
|
|
3
|
+
import { HarnessLog } from '../../log.js';
|
|
4
4
|
import { escapeLiteralDollars } from '../../tools/exec/scope.js';
|
|
5
5
|
const JSON_NUMBER = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/;
|
|
6
6
|
export class ArgRepairHook {
|
|
@@ -57,7 +57,11 @@ function coerceString(value, schema, site) {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
if (structured || scalarOnly) {
|
|
60
|
-
|
|
60
|
+
HarnessLog.debug('arg repair declined', {
|
|
61
|
+
tool: site.tool,
|
|
62
|
+
param: site.path,
|
|
63
|
+
length: value.length
|
|
64
|
+
});
|
|
61
65
|
}
|
|
62
66
|
return value;
|
|
63
67
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { HarnessHook, HookContext, HookResult, PolicyRule } from '../../contract/index.ts';
|
|
2
|
+
export declare class PolicyRulesHook implements HarnessHook {
|
|
3
|
+
readonly name = "policy-rules";
|
|
4
|
+
readonly phase: 'preToolCall';
|
|
5
|
+
readonly rules: readonly PolicyRule[];
|
|
6
|
+
constructor(rules: readonly PolicyRule[]);
|
|
7
|
+
run(ctx: HookContext): HookResult;
|
|
8
|
+
}
|