@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,9 +1,11 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
2
|
import { randomBytes } from 'crypto';
|
|
3
3
|
import path from 'path';
|
|
4
|
+
import { Policy } from '../../lib/policy/index.js';
|
|
5
|
+
import { HarnessError } from '../../lib/errors.js';
|
|
4
6
|
import { isRecord } from '../../lib/guards.js';
|
|
5
7
|
import { appendOutput, createCapturedOutput, formatOutput, MAX_OUTPUT_CHARS } from '../../lib/tools/exec/runner.js';
|
|
6
|
-
import {
|
|
8
|
+
import { callDenyRoots, defaultRealpath, overlaps, resolveKey } from '../../lib/tools/fs/scope.js';
|
|
7
9
|
const STATE_DIR = '"$__qvac_dir"';
|
|
8
10
|
const SHELL_TIMEOUT_MS = 300_000;
|
|
9
11
|
const MAX_TIMEOUT_MS = 1_800_000;
|
|
@@ -11,7 +13,7 @@ const NO_WORKSPACE = 'the coding tools need one writable directory granted to th
|
|
|
11
13
|
const DRIVE_WORKSPACE = 'the coding tools work in a local project folder, not a drive or a filesystem root';
|
|
12
14
|
const DENIED_WORKSPACE = 'the coding tools need a project folder that neither holds nor sits in a protected app folder';
|
|
13
15
|
const DRIVE_PATH = 'the coding tools take a local path inside the project, not a drive path';
|
|
14
|
-
const NOT_ISOLATED = '
|
|
16
|
+
const NOT_ISOLATED = 'the network is off and this sandbox is not isolated, so the coding tools are off';
|
|
15
17
|
const BUDGET_SPENT = 'run wall-clock budget exhausted; no time remains for this call';
|
|
16
18
|
export function guidance(error) {
|
|
17
19
|
return { error, guidance: true };
|
|
@@ -24,7 +26,7 @@ export function shellQuote(text) {
|
|
|
24
26
|
}
|
|
25
27
|
export function errorText(error) {
|
|
26
28
|
if (error instanceof Error) {
|
|
27
|
-
return error.name === 'AbortError' || error
|
|
29
|
+
return error.name === 'AbortError' || HarnessError.is(error, 'ABORTED')
|
|
28
30
|
? 'command aborted'
|
|
29
31
|
: error.message;
|
|
30
32
|
}
|
|
@@ -44,7 +46,7 @@ function workspaceRoot(ctx) {
|
|
|
44
46
|
}
|
|
45
47
|
return root;
|
|
46
48
|
}
|
|
47
|
-
|
|
49
|
+
async function workspaceKey(root, input) {
|
|
48
50
|
if (input.includes('://')) {
|
|
49
51
|
return { error: DRIVE_PATH };
|
|
50
52
|
}
|
|
@@ -89,25 +91,29 @@ export class CodingSession {
|
|
|
89
91
|
_bind;
|
|
90
92
|
_workspaces;
|
|
91
93
|
_runs;
|
|
94
|
+
_keys;
|
|
92
95
|
constructor(sandbox, deniedRoots = []) {
|
|
93
96
|
this.sandbox = sandbox;
|
|
94
97
|
this.deniedRoots = deniedRoots;
|
|
95
98
|
this._bind = `__qvac_dir="\${TMPDIR:-/tmp}"/qvac-coding-${b4a.toHex(randomBytes(8))}`;
|
|
96
99
|
this._workspaces = new Map();
|
|
97
100
|
this._runs = new Map();
|
|
101
|
+
this._keys = new Map();
|
|
98
102
|
}
|
|
99
103
|
effect(ctx) {
|
|
100
104
|
return ctx?.planMode || !this.sandbox.isolated ? 'write' : 'read';
|
|
101
105
|
}
|
|
102
106
|
refusal(ctx) {
|
|
103
|
-
return ctx?.
|
|
107
|
+
return ctx?.policy?.network.mode === 'off' && !this.sandbox.isolated
|
|
108
|
+
? guidance(NOT_ISOLATED)
|
|
109
|
+
: null;
|
|
104
110
|
}
|
|
105
111
|
async workspace(ctx) {
|
|
106
112
|
const root = this.refusal(ctx) ?? workspaceRoot(ctx);
|
|
107
113
|
if (isError(root)) {
|
|
108
114
|
return root;
|
|
109
115
|
}
|
|
110
|
-
const deny = await
|
|
116
|
+
const deny = await callDenyRoots(this.deniedRoots, ctx?.policy, defaultRealpath);
|
|
111
117
|
return deny.some((each) => overlaps(root.root, each)) ? guidance(DENIED_WORKSPACE) : root;
|
|
112
118
|
}
|
|
113
119
|
policyVersion() {
|
|
@@ -120,19 +126,21 @@ export class CodingSession {
|
|
|
120
126
|
statePath(runId) {
|
|
121
127
|
return `${STATE_DIR}/${b4a.toHex(b4a.from(runId))}`;
|
|
122
128
|
}
|
|
123
|
-
open(root, runId) {
|
|
129
|
+
open(root, runId, policy) {
|
|
130
|
+
const key = `${root.root}\0${JSON.stringify(policy)}`;
|
|
124
131
|
this._runs.set(runId, root.root);
|
|
125
|
-
|
|
132
|
+
this._keys.set(runId, key);
|
|
133
|
+
let workspace = this._workspaces.get(key);
|
|
126
134
|
if (!workspace) {
|
|
127
|
-
workspace = this.sandbox.open(root.root);
|
|
128
|
-
workspace.catch(() => this._workspaces.delete(
|
|
129
|
-
this._workspaces.set(
|
|
135
|
+
workspace = this.sandbox.open(root.root, policy);
|
|
136
|
+
workspace.catch(() => this._workspaces.delete(key));
|
|
137
|
+
this._workspaces.set(key, workspace);
|
|
130
138
|
}
|
|
131
139
|
return workspace;
|
|
132
140
|
}
|
|
133
141
|
workspaceOf(runId) {
|
|
134
|
-
const
|
|
135
|
-
return
|
|
142
|
+
const key = this._keys.get(runId);
|
|
143
|
+
return key === undefined ? null : (this._workspaces.get(key) ?? null);
|
|
136
144
|
}
|
|
137
145
|
_prelude(runId) {
|
|
138
146
|
return [
|
|
@@ -171,6 +179,7 @@ export class CodingSession {
|
|
|
171
179
|
async endRun(runId) {
|
|
172
180
|
const workspace = this.workspaceOf(runId);
|
|
173
181
|
this._runs.delete(runId);
|
|
182
|
+
this._keys.delete(runId);
|
|
174
183
|
if (workspace) {
|
|
175
184
|
const state = this.statePath(runId);
|
|
176
185
|
await this.execState(await workspace, `rm -f ${state}.env ${state}.cwd ${state}.tmp`);
|
|
@@ -180,6 +189,7 @@ export class CodingSession {
|
|
|
180
189
|
const workspaces = await Promise.allSettled(this._workspaces.values());
|
|
181
190
|
this._workspaces.clear();
|
|
182
191
|
this._runs.clear();
|
|
192
|
+
this._keys.clear();
|
|
183
193
|
await Promise.allSettled(workspaces.map(async (each) => {
|
|
184
194
|
if (each.status !== 'fulfilled')
|
|
185
195
|
return;
|
|
@@ -233,7 +243,8 @@ async function runShell({ session, start }, args, ctx) {
|
|
|
233
243
|
}
|
|
234
244
|
const runId = ctx?.runId ?? '';
|
|
235
245
|
try {
|
|
236
|
-
const
|
|
246
|
+
const policy = ctx?.policy ?? Policy.compile(undefined, { write: [root.root] });
|
|
247
|
+
const call = { workspace: await session.open(root, runId, policy), runId, line };
|
|
237
248
|
if (args.background === true) {
|
|
238
249
|
return await start(call);
|
|
239
250
|
}
|
|
@@ -253,6 +264,7 @@ export function shellTool(options) {
|
|
|
253
264
|
parameters: SHELL_PARAMETERS,
|
|
254
265
|
effect: (_args, ctx) => session.effect(ctx),
|
|
255
266
|
quote: (args) => (typeof args.command === 'string' ? args.command : null),
|
|
267
|
+
command: (args) => (typeof args.command === 'string' ? args.command : null),
|
|
256
268
|
validate(args) {
|
|
257
269
|
return typeof args.command === 'string' && args.command.trim()
|
|
258
270
|
? null
|
|
@@ -3,7 +3,7 @@ import { spawn } from 'child_process';
|
|
|
3
3
|
import process from 'process';
|
|
4
4
|
import { errorMessage, isRecord } from '../../lib/guards.js';
|
|
5
5
|
import { execEnv } from '../../lib/helpers/spawn-path.js';
|
|
6
|
-
import {
|
|
6
|
+
import { HarnessLog } from '../../lib/log.js';
|
|
7
7
|
import { PluginRegistry } from '../../lib/plugins/index.js';
|
|
8
8
|
const DEFAULT_TIMEOUT_S = 60;
|
|
9
9
|
const STDERR_TAIL = 2_000;
|
|
@@ -120,7 +120,7 @@ function blocked(event, reason) {
|
|
|
120
120
|
case 'Stop':
|
|
121
121
|
return { continue: said };
|
|
122
122
|
case 'PreCompact':
|
|
123
|
-
|
|
123
|
+
HarnessLog.info('PreCompact hook exited 2; a fold cannot be blocked', { reason: said });
|
|
124
124
|
return undefined;
|
|
125
125
|
}
|
|
126
126
|
}
|
|
@@ -291,7 +291,9 @@ export class CommandHooks {
|
|
|
291
291
|
const config = this._hooks;
|
|
292
292
|
const skipped = Object.keys(config).filter(isSkipped);
|
|
293
293
|
if (skipped.length) {
|
|
294
|
-
|
|
294
|
+
HarnessLog.info('command-hooks: these events have no harness phase and never run', {
|
|
295
|
+
events: skipped
|
|
296
|
+
});
|
|
295
297
|
}
|
|
296
298
|
const commands = Object.entries(config).flatMap(([event, entries = []]) => isEvent(event) ? commandsOf(event, entries) : []);
|
|
297
299
|
const hooks = commands.map((spec) => ({
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import net from 'net';
|
|
2
|
+
import type { HarnessPlugin, PluginSetup } from '../../lib/plugins/index.ts';
|
|
3
|
+
import { type HostResolver } from '../../lib/tools/url-guard.ts';
|
|
4
|
+
import type { EgressProxyOptions, EgressProxyService, EgressProxySession } from '../../lib/contract/egress-proxy.ts';
|
|
5
|
+
export type Dial = (address: string, port: number) => net.Socket;
|
|
6
|
+
export interface EgressProxyPluginOptions {
|
|
7
|
+
readonly resolveHost?: HostResolver;
|
|
8
|
+
readonly dial?: Dial;
|
|
9
|
+
}
|
|
10
|
+
export declare class EgressProxy implements HarnessPlugin, EgressProxyService {
|
|
11
|
+
readonly name = "egress-proxy";
|
|
12
|
+
readonly api = 1;
|
|
13
|
+
readonly provides: string[];
|
|
14
|
+
readonly addons: {
|
|
15
|
+
'bare-net': () => Promise<{
|
|
16
|
+
constants: {
|
|
17
|
+
type: {
|
|
18
|
+
TCP: 1;
|
|
19
|
+
IPC: 2;
|
|
20
|
+
};
|
|
21
|
+
state: {
|
|
22
|
+
UNREFED: number;
|
|
23
|
+
BINDING: number;
|
|
24
|
+
BOUND: number;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
errors: typeof import("bare-net").errors;
|
|
28
|
+
isIP: typeof import("bare-tcp").isIP;
|
|
29
|
+
isIPv4: typeof import("bare-tcp").isIPv4;
|
|
30
|
+
isIPv6: typeof import("bare-tcp").isIPv6;
|
|
31
|
+
Socket: typeof import("bare-net").NetSocket;
|
|
32
|
+
Server: typeof import("bare-net").NetServer;
|
|
33
|
+
createConnection(path: string, opts?: import("bare-net").NetOptions & import("bare-pipe").PipeConnectOptions, onconnect?: () => void): import("bare-net").NetSocket;
|
|
34
|
+
createConnection(path: string, onconnect: () => void): import("bare-net").NetSocket;
|
|
35
|
+
createConnection(port: number, host?: string, opts?: import("bare-net").NetOptions & import("bare-tcp").TCPSocketConnectOptions, onconnect?: () => void): import("bare-net").NetSocket;
|
|
36
|
+
createConnection(port: number, host: string, onconnect: () => void): import("bare-net").NetSocket;
|
|
37
|
+
createConnection(port: number, onconnect: () => void): import("bare-net").NetSocket;
|
|
38
|
+
createConnection(opts: import("bare-net").NetOptions & import("bare-net").NetSocketConnectOptions, onconnect?: () => void): import("bare-net").NetSocket;
|
|
39
|
+
connect: typeof import("bare-net").createConnection;
|
|
40
|
+
createServer(opts?: import("bare-net").NetOptions, onconnection?: (socket: import("bare-net").NetSocket) => void): import("bare-net").NetServer;
|
|
41
|
+
createServer(onconnection: (socket: import("bare-net").NetSocket) => void): import("bare-net").NetServer;
|
|
42
|
+
default: typeof import("bare-net");
|
|
43
|
+
}>;
|
|
44
|
+
};
|
|
45
|
+
private readonly _resolveHost;
|
|
46
|
+
private readonly _dial;
|
|
47
|
+
private readonly _sessions;
|
|
48
|
+
constructor({ resolveHost, dial }?: EgressProxyPluginOptions);
|
|
49
|
+
setup(): PluginSetup;
|
|
50
|
+
open({ hosts, signal }: EgressProxyOptions): Promise<EgressProxySession>;
|
|
51
|
+
private _serve;
|
|
52
|
+
private _forward;
|
|
53
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import b4a from 'b4a';
|
|
2
|
+
import net from 'net';
|
|
3
|
+
import { lookupHost } from '../../lib/dns-lookup.js';
|
|
4
|
+
import { PluginRegistry } from '../../lib/plugins/index.js';
|
|
5
|
+
import { resolveOutboundUrl } from '../../lib/tools/url-guard.js';
|
|
6
|
+
const MAX_HEAD = 64 * 1024;
|
|
7
|
+
const HEAD_END = '\r\n\r\n';
|
|
8
|
+
const REASONS = {
|
|
9
|
+
400: 'Bad Request',
|
|
10
|
+
403: 'Forbidden',
|
|
11
|
+
431: 'Request Header Fields Too Large',
|
|
12
|
+
502: 'Bad Gateway'
|
|
13
|
+
};
|
|
14
|
+
const DROPPED = /^(host|connection|keep-alive|proxy-connection|proxy-authorization)\s*:/i;
|
|
15
|
+
export class EgressProxy {
|
|
16
|
+
name = 'egress-proxy';
|
|
17
|
+
api = PluginRegistry.API_VERSION;
|
|
18
|
+
provides = ['egress-proxy'];
|
|
19
|
+
addons = { 'bare-net': () => import('bare-net') };
|
|
20
|
+
_resolveHost;
|
|
21
|
+
_dial;
|
|
22
|
+
_sessions = new Set();
|
|
23
|
+
constructor({ resolveHost = lookupHost, dial = (address, port) => net.connect(port, address) } = {}) {
|
|
24
|
+
this._resolveHost = resolveHost;
|
|
25
|
+
this._dial = dial;
|
|
26
|
+
}
|
|
27
|
+
setup() {
|
|
28
|
+
return {
|
|
29
|
+
services: { 'egress-proxy': { open: (options) => this.open(options) } },
|
|
30
|
+
teardown: async () => {
|
|
31
|
+
await Promise.all([...this._sessions].map((session) => session.close()));
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
async open({ hosts, signal }) {
|
|
36
|
+
const sockets = new Set();
|
|
37
|
+
const served = {
|
|
38
|
+
hosts,
|
|
39
|
+
denied: new Set(),
|
|
40
|
+
track: (socket) => {
|
|
41
|
+
sockets.add(socket);
|
|
42
|
+
socket.on('close', () => sockets.delete(socket));
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const server = net.createServer((client) => {
|
|
46
|
+
served.track(client);
|
|
47
|
+
this._serve(client, served);
|
|
48
|
+
});
|
|
49
|
+
const port = await listen(server);
|
|
50
|
+
let closing = null;
|
|
51
|
+
const session = {
|
|
52
|
+
port,
|
|
53
|
+
denied: () => [...served.denied],
|
|
54
|
+
close: () => {
|
|
55
|
+
closing ??= new Promise((resolve) => {
|
|
56
|
+
for (const socket of sockets) {
|
|
57
|
+
socket.destroy();
|
|
58
|
+
}
|
|
59
|
+
server.close(() => resolve());
|
|
60
|
+
}).then(() => {
|
|
61
|
+
this._sessions.delete(session);
|
|
62
|
+
});
|
|
63
|
+
return closing;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
this._sessions.add(session);
|
|
67
|
+
signal?.addEventListener('abort', () => void session.close());
|
|
68
|
+
return session;
|
|
69
|
+
}
|
|
70
|
+
_serve(client, served) {
|
|
71
|
+
const chunks = [];
|
|
72
|
+
client.on('error', () => client.destroy());
|
|
73
|
+
const onData = (chunk) => {
|
|
74
|
+
chunks.push(chunk);
|
|
75
|
+
const buffered = b4a.concat(chunks);
|
|
76
|
+
const end = b4a.indexOf(buffered, HEAD_END);
|
|
77
|
+
if (end === -1) {
|
|
78
|
+
if (buffered.byteLength > MAX_HEAD) {
|
|
79
|
+
client.removeListener('data', onData);
|
|
80
|
+
reply(client, 431, 'the request head is too large');
|
|
81
|
+
}
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
client.pause();
|
|
85
|
+
client.removeListener('data', onData);
|
|
86
|
+
void this._forward(client, parseHead(buffered, end), served);
|
|
87
|
+
};
|
|
88
|
+
client.on('data', onData);
|
|
89
|
+
}
|
|
90
|
+
async _forward(client, request, served) {
|
|
91
|
+
const tunnel = request.method.toUpperCase() === 'CONNECT';
|
|
92
|
+
const url = parseTarget(tunnel ? `http://${request.target}` : request.target);
|
|
93
|
+
if (!url || url.protocol !== 'http:' || (tunnel && url.pathname !== '/')) {
|
|
94
|
+
reply(client, 400, 'the proxy takes CONNECT host:port or an absolute http:// URL');
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const check = await resolveOutboundUrl(url, {
|
|
98
|
+
resolveHost: this._resolveHost,
|
|
99
|
+
hosts: served.hosts
|
|
100
|
+
});
|
|
101
|
+
if (check.blocked) {
|
|
102
|
+
served.denied.add(url.hostname);
|
|
103
|
+
reply(client, 403, `egress-proxy refused ${url.hostname}: ${check.blocked}`);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const address = check.addresses?.[0] ?? url.hostname.replace(/^\[(.*)\]$/, '$1');
|
|
107
|
+
const upstream = this._dial(address, Number(url.port) || 80);
|
|
108
|
+
served.track(upstream);
|
|
109
|
+
const opening = tunnel ? null : originHead(request, url);
|
|
110
|
+
splice(client, upstream, { opening, rest: request.rest, host: url.hostname });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function parseHead(buffered, end) {
|
|
114
|
+
const [line, ...fields] = b4a.toString(buffered.subarray(0, end), 'latin1').split('\r\n');
|
|
115
|
+
const [method = '', target = '', version = 'HTTP/1.1'] = line.split(' ');
|
|
116
|
+
return { method, target, version, fields, rest: buffered.subarray(end + HEAD_END.length) };
|
|
117
|
+
}
|
|
118
|
+
function splice(client, upstream, { opening, rest, host }) {
|
|
119
|
+
let connected = false;
|
|
120
|
+
upstream.on('error', () => {
|
|
121
|
+
if (connected) {
|
|
122
|
+
client.destroy();
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
reply(client, 502, `egress-proxy could not reach ${host}`);
|
|
126
|
+
}
|
|
127
|
+
upstream.destroy();
|
|
128
|
+
});
|
|
129
|
+
client.on('error', () => upstream.destroy());
|
|
130
|
+
upstream.once('connect', () => {
|
|
131
|
+
connected = true;
|
|
132
|
+
if (opening === null) {
|
|
133
|
+
client.write('HTTP/1.1 200 Connection Established\r\n\r\n');
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
upstream.write(opening);
|
|
137
|
+
}
|
|
138
|
+
if (rest.byteLength > 0) {
|
|
139
|
+
upstream.write(rest);
|
|
140
|
+
}
|
|
141
|
+
client.pipe(upstream);
|
|
142
|
+
upstream.pipe(client);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
async function listen(server) {
|
|
146
|
+
await new Promise((resolve, reject) => {
|
|
147
|
+
server.once('error', reject);
|
|
148
|
+
server.listen(0, '127.0.0.1', () => resolve());
|
|
149
|
+
});
|
|
150
|
+
const address = server.address();
|
|
151
|
+
return typeof address === 'object' && address ? address.port : 0;
|
|
152
|
+
}
|
|
153
|
+
function parseTarget(target) {
|
|
154
|
+
try {
|
|
155
|
+
return new URL(target);
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function originHead({ method, version, fields }, url) {
|
|
162
|
+
const kept = fields.filter((field) => field !== '' && !DROPPED.test(field));
|
|
163
|
+
return [
|
|
164
|
+
`${method} ${url.pathname}${url.search} ${version}`,
|
|
165
|
+
`Host: ${url.host}`,
|
|
166
|
+
...kept,
|
|
167
|
+
'Connection: close',
|
|
168
|
+
'',
|
|
169
|
+
''
|
|
170
|
+
].join('\r\n');
|
|
171
|
+
}
|
|
172
|
+
function reply(socket, status, reason) {
|
|
173
|
+
const body = `${reason}\n`;
|
|
174
|
+
socket.end([
|
|
175
|
+
`HTTP/1.1 ${status} ${REASONS[status]}`,
|
|
176
|
+
'Content-Type: text/plain',
|
|
177
|
+
`Content-Length: ${b4a.byteLength(body)}`,
|
|
178
|
+
'Connection: close',
|
|
179
|
+
'',
|
|
180
|
+
body
|
|
181
|
+
].join('\r\n'));
|
|
182
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import path from 'path';
|
|
4
|
+
import { HarnessError } from '../../lib/errors.js';
|
|
4
5
|
import { AbortedError } from '../../lib/helpers/race-abort.js';
|
|
5
|
-
import { BUSY_ERROR, DIM_STEP, effectiveSteps, generationPercentTick,
|
|
6
|
+
import { BUSY_ERROR, DIM_STEP, effectiveSteps, generationPercentTick, normalizeClamps, parseCommonArgs, runDiffusion } from './generate-image.js';
|
|
6
7
|
const DEFAULT_STRENGTH = 0.7;
|
|
7
8
|
const FLUX2_GUIDANCE = 3.5;
|
|
8
9
|
const FLUX2_CFG_SCALE = 1;
|
|
@@ -283,8 +284,8 @@ export function createEditImageTool(runtime, { loadMedia = defaultLoadMedia, res
|
|
|
283
284
|
if (err instanceof AbortedError) {
|
|
284
285
|
return { error: 'image generation canceled' };
|
|
285
286
|
}
|
|
286
|
-
if (err
|
|
287
|
-
return { error: IMAGE_LOAD_STALL_ERROR };
|
|
287
|
+
if (HarnessError.is(err, 'IMAGE_LOAD_STALLED')) {
|
|
288
|
+
return { error: HarnessError.IMAGE_LOAD_STALL_ERROR };
|
|
288
289
|
}
|
|
289
290
|
throw err;
|
|
290
291
|
}
|
|
@@ -3,6 +3,7 @@ import type { ToolDefinition } from '../../lib/contract/index.ts';
|
|
|
3
3
|
import type { ModelSrc } from '../../lib/models/context.ts';
|
|
4
4
|
import { type ImageClamps, type ImageModelSet } from '../../lib/models/model-catalog.ts';
|
|
5
5
|
import type { ModelHost, TrackedLoad } from '../../lib/contract/models.ts';
|
|
6
|
+
import type { HoldFn } from '../../lib/contract/models.ts';
|
|
6
7
|
import { type ModelRegistrySdk } from '../../lib/models/model-source.ts';
|
|
7
8
|
export declare const MAX_DIM = 1024;
|
|
8
9
|
export declare const DIM_STEP = 64;
|
|
@@ -62,7 +63,8 @@ export interface DiffusionRuntimeOptions extends ImageModelSet {
|
|
|
62
63
|
loadSdk: () => Promise<DiffusionSdk>;
|
|
63
64
|
onProgress?: (model: string, progress: Record<string, unknown>) => void;
|
|
64
65
|
onLoaded?: (model: string) => void;
|
|
65
|
-
onBeforeLoad?: (signal
|
|
66
|
+
onBeforeLoad?: (signal: BareAbortSignal | undefined, srcs: ReadonlyArray<string>) => Promise<void>;
|
|
67
|
+
hold?: HoldFn;
|
|
66
68
|
loads?: Pick<ModelHost, 'track'>;
|
|
67
69
|
stallMs?: number;
|
|
68
70
|
}
|
|
@@ -80,8 +82,7 @@ export interface DiffusionRuntime {
|
|
|
80
82
|
release(): void;
|
|
81
83
|
}
|
|
82
84
|
export declare function generationPercentTick(onPercent: (percentage: number) => void, encodePhases?: number): (tick: DiffusionTick) => void;
|
|
83
|
-
export declare
|
|
84
|
-
export declare function createDiffusionRuntime({ loadSdk, onProgress, onLoaded, onBeforeLoad, loads, stallMs, ...base }: DiffusionRuntimeOptions): DiffusionRuntime;
|
|
85
|
+
export declare function createDiffusionRuntime({ loadSdk, onProgress, onLoaded, onBeforeLoad, hold, loads, stallMs, ...base }: DiffusionRuntimeOptions): DiffusionRuntime;
|
|
85
86
|
export declare const BUSY_ERROR = "an image generation is already running; try again when it finishes";
|
|
86
87
|
export interface ImageToolError {
|
|
87
88
|
error: string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import ScopeLock from 'scope-lock';
|
|
2
|
+
import { HarnessError } from '../../lib/errors.js';
|
|
2
3
|
import { AbortedError, raceAbort } from '../../lib/helpers/race-abort.js';
|
|
3
4
|
import { DIFFUSION_CATALOG, imageModelFor } from '../../lib/models/model-catalog.js';
|
|
4
5
|
import { createLoadStall } from '../../lib/helpers/load-stall.js';
|
|
@@ -37,8 +38,7 @@ function diffusionProgressName(set) {
|
|
|
37
38
|
const entry = DIFFUSION_CATALOG.find((candidate) => candidate.model.src === set.model);
|
|
38
39
|
return entry?.name ?? set.model;
|
|
39
40
|
}
|
|
40
|
-
export
|
|
41
|
-
export function createDiffusionRuntime({ loadSdk, onProgress, onLoaded, onBeforeLoad, loads = { track: (pending) => pending }, stallMs = IMAGE_LOAD_STALL_MS, ...base }) {
|
|
41
|
+
export function createDiffusionRuntime({ loadSdk, onProgress, onLoaded, onBeforeLoad, hold, loads = { track: (pending) => pending }, stallMs = IMAGE_LOAD_STALL_MS, ...base }) {
|
|
42
42
|
let loading = null;
|
|
43
43
|
let residentFingerprint = null;
|
|
44
44
|
let busy = false;
|
|
@@ -75,13 +75,16 @@ export function createDiffusionRuntime({ loadSdk, onProgress, onLoaded, onBefore
|
|
|
75
75
|
ensureLoaded: async (sdk, signal, modelChoice) => {
|
|
76
76
|
const set = (modelChoice && imageModelFor(modelChoice)) || base;
|
|
77
77
|
const fingerprint = fingerprintOf(set);
|
|
78
|
+
if (hold && !(loading && residentFingerprint === fingerprint)) {
|
|
79
|
+
await hold(diffusionProgressName(set), 'diffusion', signal);
|
|
80
|
+
}
|
|
78
81
|
await lock.lock();
|
|
79
82
|
try {
|
|
80
83
|
if (loading && residentFingerprint !== fingerprint) {
|
|
81
84
|
await doUnload();
|
|
82
85
|
}
|
|
83
86
|
if (!loading && onBeforeLoad) {
|
|
84
|
-
await onBeforeLoad(signal);
|
|
87
|
+
await onBeforeLoad(signal, [set.model, set.llmModel, set.vaeModel].filter((src) => src !== undefined));
|
|
85
88
|
}
|
|
86
89
|
residentFingerprint = fingerprint;
|
|
87
90
|
loading ??= (async () => {
|
|
@@ -98,7 +101,7 @@ export function createDiffusionRuntime({ loadSdk, onProgress, onLoaded, onBefore
|
|
|
98
101
|
config.vaeModelSrc = await resolveModelSrc(sdk, set.vaeModel, 'diffusion');
|
|
99
102
|
}
|
|
100
103
|
const modelConfig = Object.keys(config).length ? config : undefined;
|
|
101
|
-
const stall = createLoadStall(stallMs,
|
|
104
|
+
const stall = createLoadStall(stallMs, () => new HarnessError('IMAGE_LOAD_STALLED'));
|
|
102
105
|
const pending = sdk.loadModel({
|
|
103
106
|
modelSrc,
|
|
104
107
|
modelType: 'diffusion',
|
|
@@ -114,9 +117,7 @@ export function createDiffusionRuntime({ loadSdk, onProgress, onLoaded, onBefore
|
|
|
114
117
|
return { modelId, prediction: set.prediction };
|
|
115
118
|
}
|
|
116
119
|
catch (err) {
|
|
117
|
-
if (err
|
|
118
|
-
err.message === IMAGE_LOAD_STALL_ERROR &&
|
|
119
|
-
pending.requestId) {
|
|
120
|
+
if (HarnessError.is(err, 'IMAGE_LOAD_STALLED') && pending.requestId) {
|
|
120
121
|
void sdk.cancel?.({ requestId: pending.requestId }).catch(noop);
|
|
121
122
|
}
|
|
122
123
|
throw err;
|
|
@@ -367,8 +368,8 @@ export function createGenerateImageTool(runtime, clamps) {
|
|
|
367
368
|
if (err instanceof AbortedError) {
|
|
368
369
|
return { error: 'image generation canceled' };
|
|
369
370
|
}
|
|
370
|
-
if (err
|
|
371
|
-
return { error: IMAGE_LOAD_STALL_ERROR };
|
|
371
|
+
if (HarnessError.is(err, 'IMAGE_LOAD_STALLED')) {
|
|
372
|
+
return { error: HarnessError.IMAGE_LOAD_STALL_ERROR };
|
|
372
373
|
}
|
|
373
374
|
throw err;
|
|
374
375
|
}
|
|
@@ -2,7 +2,7 @@ import type { ImageClamps, ImageModelSet } from '../../lib/models/model-catalog.
|
|
|
2
2
|
import type { HarnessPlugin, PluginContext, PluginSetup } from '../../lib/plugins/index.ts';
|
|
3
3
|
import { loadMediaCodecs } from './edit-image.ts';
|
|
4
4
|
export { createEditImageTool } from './edit-image.ts';
|
|
5
|
-
export { createDiffusionRuntime, createGenerateImageTool, generationPercentTick,
|
|
5
|
+
export { createDiffusionRuntime, createGenerateImageTool, generationPercentTick, settingsDimension, settingsSteps, type DiffusionRuntime, type DiffusionRuntimeOptions, type DiffusionSdk, type DiffusionTick } from './generate-image.ts';
|
|
6
6
|
export interface ImageOptions {
|
|
7
7
|
model: string | ImageModelSet;
|
|
8
8
|
clamps?: ImageClamps;
|
|
@@ -1,21 +1,23 @@
|
|
|
1
|
+
import { HarnessError } from '../../lib/errors.js';
|
|
1
2
|
import { retryMemo } from '../../lib/helpers/retry-memo.js';
|
|
2
3
|
import { PluginRegistry } from '../../lib/plugins/index.js';
|
|
3
4
|
import { createEditImageTool, loadMediaCodecs } from './edit-image.js';
|
|
4
5
|
import { createDiffusionRuntime, createGenerateImageTool } from './generate-image.js';
|
|
5
6
|
export { createEditImageTool } from './edit-image.js';
|
|
6
|
-
export { createDiffusionRuntime, createGenerateImageTool, generationPercentTick,
|
|
7
|
-
const BUSY_MESSAGE = 'the chat model is busy; try the image again once the current reply finishes';
|
|
7
|
+
export { createDiffusionRuntime, createGenerateImageTool, generationPercentTick, settingsDimension, settingsSteps } from './generate-image.js';
|
|
8
8
|
function diffusionRuntime(models, model) {
|
|
9
9
|
const loadSdk = retryMemo(async () => {
|
|
10
10
|
const sdk = await models.sdk();
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
if (typeof globalThis.Bare !== 'undefined') {
|
|
12
|
+
const [{ diffusionPlugin }, { registerPlugin }] = await Promise.all([
|
|
13
|
+
import('@qvac/sdk/sdcpp-generation/plugin'),
|
|
14
|
+
import('@qvac/sdk/plugins')
|
|
15
|
+
]);
|
|
16
|
+
try {
|
|
17
|
+
registerPlugin(diffusionPlugin);
|
|
18
|
+
}
|
|
19
|
+
catch { }
|
|
17
20
|
}
|
|
18
|
-
catch { }
|
|
19
21
|
return sdk;
|
|
20
22
|
});
|
|
21
23
|
const transfers = new Map();
|
|
@@ -23,6 +25,7 @@ function diffusionRuntime(models, model) {
|
|
|
23
25
|
...(typeof model === 'string' ? { model } : model),
|
|
24
26
|
loads: models,
|
|
25
27
|
loadSdk,
|
|
28
|
+
hold: models.hold,
|
|
26
29
|
onProgress: (name, progress) => {
|
|
27
30
|
const state = models.progressState(name, progress);
|
|
28
31
|
if (state.status === 'downloading' &&
|
|
@@ -43,7 +46,7 @@ function diffusionRuntime(models, model) {
|
|
|
43
46
|
models.statusChanged();
|
|
44
47
|
models.emit({ ...transfer, status: 'downloaded' });
|
|
45
48
|
},
|
|
46
|
-
onBeforeLoad: (signal) => models.makeRoom(signal,
|
|
49
|
+
onBeforeLoad: (signal, srcs) => models.makeRoom(signal, new HarnessError('CHAT_MODEL_BUSY', ['image']), srcs)
|
|
47
50
|
});
|
|
48
51
|
}
|
|
49
52
|
export class Image {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { HarnessPlugin, PluginContext, PluginSetup } from '../../lib/plugins/index.ts';
|
|
2
|
+
export interface LanguageHintOptions {
|
|
3
|
+
minWords?: number;
|
|
4
|
+
minProbability?: number;
|
|
5
|
+
}
|
|
6
|
+
export declare class LanguageHint implements HarnessPlugin {
|
|
7
|
+
readonly name = "language-hint";
|
|
8
|
+
readonly api = 1;
|
|
9
|
+
readonly needs: string[];
|
|
10
|
+
private readonly _minWords;
|
|
11
|
+
private readonly _minProbability;
|
|
12
|
+
constructor(options?: LanguageHintOptions);
|
|
13
|
+
setup(ctx: PluginContext): PluginSetup;
|
|
14
|
+
private _hint;
|
|
15
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { detectLanguage, UNDETERMINED } from '../../lib/capabilities/detect-language.js';
|
|
2
|
+
import { PluginRegistry } from '../../lib/plugins/index.js';
|
|
3
|
+
const TIMEOUT_MS = 120_000;
|
|
4
|
+
export class LanguageHint {
|
|
5
|
+
name = 'language-hint';
|
|
6
|
+
api = PluginRegistry.API_VERSION;
|
|
7
|
+
needs = ['translation'];
|
|
8
|
+
_minWords;
|
|
9
|
+
_minProbability;
|
|
10
|
+
constructor(options = {}) {
|
|
11
|
+
this._minWords = options.minWords ?? 3;
|
|
12
|
+
this._minProbability = options.minProbability ?? 0.5;
|
|
13
|
+
}
|
|
14
|
+
setup(ctx) {
|
|
15
|
+
const translation = ctx.service('translation');
|
|
16
|
+
const hook = {
|
|
17
|
+
name: 'language-hint',
|
|
18
|
+
phase: 'promptSubmit',
|
|
19
|
+
timeoutMs: TIMEOUT_MS,
|
|
20
|
+
run: (payload, options) => payload.phase === 'promptSubmit'
|
|
21
|
+
? this._hint(translation, payload.text, options)
|
|
22
|
+
: undefined
|
|
23
|
+
};
|
|
24
|
+
return { hooks: [hook] };
|
|
25
|
+
}
|
|
26
|
+
async _hint(translation, text, options) {
|
|
27
|
+
if (text.trim().split(/\s+/).length < this._minWords)
|
|
28
|
+
return;
|
|
29
|
+
const [top] = detectLanguage({ text, topK: 2 });
|
|
30
|
+
if (!top || top.code === UNDETERMINED || top.code === 'en') {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if ((top.probability ?? 0) < this._minProbability) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const said = `The user wrote in ${top.language}.`;
|
|
37
|
+
const answer = `Answer in ${top.language}.`;
|
|
38
|
+
let english;
|
|
39
|
+
try {
|
|
40
|
+
english = await translation.translate({ text, from: top.code, to: 'en' }, options?.signal);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return { context: `${said} ${answer}` };
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
context: 'error' in english
|
|
47
|
+
? `${said} ${answer}`
|
|
48
|
+
: `${said} In English: "${english.text}". Work from the English. ${answer}`
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -2,7 +2,7 @@ import fs from 'fs';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { fileURLToPath, pathToFileURL } from 'url';
|
|
4
4
|
import { errorMessage, isRecord } from '../../lib/guards.js';
|
|
5
|
-
import {
|
|
5
|
+
import { callDenyRoots, defaultRealpath, hostPath, isDeniedPath, PROTECTED_PATH_ERROR, resolveKey } from '../../lib/tools/fs/scope.js';
|
|
6
6
|
const OPERATIONS = ['definition', 'references', 'hover', 'symbols', 'diagnostics'];
|
|
7
7
|
const MAX_LOCATIONS = 30;
|
|
8
8
|
const MAX_OUTLINE = 100;
|
|
@@ -320,7 +320,7 @@ const PARAMETERS = {
|
|
|
320
320
|
};
|
|
321
321
|
async function run(args, ctx, options) {
|
|
322
322
|
const { pool, servers, requestTimeoutMs, deniedRoots, realpath = defaultRealpath } = options;
|
|
323
|
-
const deny = await
|
|
323
|
+
const deny = await callDenyRoots(deniedRoots, ctx?.policy, realpath);
|
|
324
324
|
const view = { roots: ctx?.fsRoots ?? [], deny, realpath, lines: new Map() };
|
|
325
325
|
const found = await target(args, view, servers);
|
|
326
326
|
if ('error' in found) {
|