@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,12 +1,17 @@
|
|
|
1
|
-
import
|
|
1
|
+
import ScopeLock from 'scope-lock';
|
|
2
|
+
import { HarnessError } from '../errors.js';
|
|
3
|
+
import { errorMessage, isRecord } from '../guards.js';
|
|
2
4
|
import { AbortedError, raceAbort } from '../helpers/race-abort.js';
|
|
3
|
-
import {
|
|
5
|
+
import { HarnessLog } from '../log.js';
|
|
6
|
+
import { ContextChoice as ContextClimb } from '../models/context-choice.js';
|
|
7
|
+
import { parseGgufHeader, readGgufHeaderBytes } from '../models/gguf-header.js';
|
|
4
8
|
import { resolveMainGpu } from '../models/gpu-selection.js';
|
|
5
9
|
import { createIdleReaper } from '../models/idle-unload.js';
|
|
6
|
-
import {
|
|
10
|
+
import { memoryCapBytes, nextVictim, VictimRank } from '../models/memory-cap.js';
|
|
11
|
+
import { assetBytes, curatedListables, curatedModelAsset, customContextLength, customModelSrc, modelAddonOf } from '../models/model-catalog.js';
|
|
7
12
|
import { ModelFit } from '../models/model-fit.js';
|
|
8
13
|
import { createModelStatusCache, invalidateModelStatusCache } from '../models/model-list.js';
|
|
9
|
-
import { awaitModelCapacity, contextSize, slotCount, createModelPool, evictIdle, evictIdleWhere, evictModel, evictModelWithin, isResident, leaseCount, loadedModels, loadingModels, modelKey, modelOf, releaseModel, resolveLoadOptions, settledModels } from '../models/model-pool.js';
|
|
14
|
+
import { awaitModelCapacity, contextSize, slotCount, createModelPool, evictIdle, evictIdleWhere, evictIdleWithin, evictModel, evictModelWithin, isResident, leaseCount, loadedModels, loadingModels, modelKey, modelOf, releaseModel, resolveLoadOptions, settledEntries, settledModels } from '../models/model-pool.js';
|
|
10
15
|
import { openclCacheDir } from '../models/opencl-cache.js';
|
|
11
16
|
import { prepareCompletionRuntime } from './completion-runtime.js';
|
|
12
17
|
const PLUGIN_EVICT_WAIT_MS = 15_000;
|
|
@@ -17,6 +22,23 @@ const LOAD_BUSY_MESSAGE = 'the chat model is busy; load this model once the curr
|
|
|
17
22
|
const UNLOAD_LEASE_WAIT_MS = 10_000;
|
|
18
23
|
const DEFAULT_COMPLETION_MODEL_CAP = 1;
|
|
19
24
|
const WEDGED_EVICT_LEASED_MS = 120_000;
|
|
25
|
+
function fitSrc(modelSrc) {
|
|
26
|
+
if (typeof modelSrc === 'string')
|
|
27
|
+
return modelSrc;
|
|
28
|
+
const { src, name, sha256Checksum } = modelSrc;
|
|
29
|
+
return { src, name, sha256Checksum };
|
|
30
|
+
}
|
|
31
|
+
function downloadBytes(modelSrc) {
|
|
32
|
+
if (typeof modelSrc === 'string') {
|
|
33
|
+
return assetBytes(modelSrc);
|
|
34
|
+
}
|
|
35
|
+
return isRecord(modelSrc) && typeof modelSrc.expectedSize === 'number'
|
|
36
|
+
? modelSrc.expectedSize
|
|
37
|
+
: undefined;
|
|
38
|
+
}
|
|
39
|
+
function stagesBytes(srcs) {
|
|
40
|
+
return srcs.reduce((sum, src) => sum + (assetBytes(src) ?? 0), 0);
|
|
41
|
+
}
|
|
20
42
|
export class Residency {
|
|
21
43
|
gate;
|
|
22
44
|
sdk;
|
|
@@ -45,10 +67,20 @@ export class Residency {
|
|
|
45
67
|
_completionModelCap;
|
|
46
68
|
_modelFaults = new Map();
|
|
47
69
|
_idle;
|
|
70
|
+
_hold;
|
|
71
|
+
_capability;
|
|
72
|
+
_sizeLoads = false;
|
|
73
|
+
_capBytes = null;
|
|
74
|
+
_reserved = new Map();
|
|
75
|
+
_contexts = new ContextClimb(() => this._contextProfile());
|
|
76
|
+
_admission = new ScopeLock();
|
|
77
|
+
_byHand = new Map();
|
|
48
78
|
_models;
|
|
49
79
|
constructor(opts) {
|
|
50
80
|
this.gate = opts.gate;
|
|
51
81
|
this.sdk = opts.sdk;
|
|
82
|
+
this._hold = opts.hold;
|
|
83
|
+
this._capability = opts.capability;
|
|
52
84
|
this._loads = opts.loads;
|
|
53
85
|
this._emit = opts.emit;
|
|
54
86
|
this._projectionFor = opts.projectionFor;
|
|
@@ -71,7 +103,7 @@ export class Residency {
|
|
|
71
103
|
this._idle = createIdleReaper({
|
|
72
104
|
sweep: () => this._unloadIdleModels(),
|
|
73
105
|
waitMs: WEDGED_EVICT_WAIT_MS,
|
|
74
|
-
onError: (err) =>
|
|
106
|
+
onError: (err) => HarnessLog.warn('idle unload failed', { err: errorMessage(err) })
|
|
75
107
|
});
|
|
76
108
|
}
|
|
77
109
|
get pool() {
|
|
@@ -88,6 +120,8 @@ export class Residency {
|
|
|
88
120
|
}
|
|
89
121
|
recreate() {
|
|
90
122
|
this.fit.clearRows();
|
|
123
|
+
this._reserved.clear();
|
|
124
|
+
this._byHand.clear();
|
|
91
125
|
this._models = this._createPool();
|
|
92
126
|
}
|
|
93
127
|
destroy() {
|
|
@@ -106,9 +140,49 @@ export class Residency {
|
|
|
106
140
|
invalidateModelStatusCache(this._modelStatus);
|
|
107
141
|
this.fit.clearRows();
|
|
108
142
|
}
|
|
109
|
-
async
|
|
143
|
+
async setMemoryCap(percent) {
|
|
144
|
+
this._sizeLoads = true;
|
|
145
|
+
const { mobile, memoryBudget } = await this._capability();
|
|
146
|
+
this._capBytes =
|
|
147
|
+
percent > 0 && !mobile && memoryBudget
|
|
148
|
+
? memoryCapBytes(percent, memoryBudget.availableBytes)
|
|
149
|
+
: null;
|
|
150
|
+
HarnessLog.info('memory cap', { percent, capBytes: this._capBytes });
|
|
151
|
+
if (this._capBytes !== null) {
|
|
152
|
+
await this.busy(() => this._admit(() => this._makeRoom(0, { generators: true })));
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
settledBytes() {
|
|
156
|
+
return this._pools()
|
|
157
|
+
.flatMap((pool) => settledEntries(pool))
|
|
158
|
+
.reduce((sum, { bytes }) => sum + (bytes ?? 0), 0);
|
|
159
|
+
}
|
|
160
|
+
memoryByModel() {
|
|
161
|
+
const memory = new Map();
|
|
162
|
+
for (const { key, bytes } of this._pools().flatMap((pool) => settledEntries(pool))) {
|
|
163
|
+
if (bytes === undefined)
|
|
164
|
+
continue;
|
|
165
|
+
const model = modelOf(key);
|
|
166
|
+
memory.set(model, (memory.get(model) ?? 0) + bytes);
|
|
167
|
+
}
|
|
168
|
+
return memory;
|
|
169
|
+
}
|
|
170
|
+
async makeRoomForPlugin(signal, busy, srcs = []) {
|
|
171
|
+
if (this._capBytes !== null && !this._models.destroyed) {
|
|
172
|
+
await this._makeRoomForGenerator(srcs, signal);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
110
175
|
if (!(await this._roomForPlugin(signal, PLUGIN_EVICT_WAIT_MS))) {
|
|
111
|
-
throw new Error(
|
|
176
|
+
throw typeof busy === 'string' ? new Error(busy) : busy;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
async _makeRoomForGenerator(srcs, signal) {
|
|
180
|
+
if (signal?.aborted) {
|
|
181
|
+
throw new AbortedError();
|
|
182
|
+
}
|
|
183
|
+
await this._makeRoom(stagesBytes(srcs), { replying: true });
|
|
184
|
+
if (signal?.aborted) {
|
|
185
|
+
throw new AbortedError();
|
|
112
186
|
}
|
|
113
187
|
}
|
|
114
188
|
async _roomForPlugin(signal, deadlineMs) {
|
|
@@ -175,7 +249,7 @@ export class Residency {
|
|
|
175
249
|
slots: this._slots,
|
|
176
250
|
mainGpu: resolveMainGpu,
|
|
177
251
|
openclCacheDir,
|
|
178
|
-
contextFor: (key) => this.fit.chosen(key),
|
|
252
|
+
contextFor: (key) => this._contexts.chosen(key) ?? this.fit.chosen(key),
|
|
179
253
|
slotsFor: (key) => this.fit.chosenSlots(key)
|
|
180
254
|
};
|
|
181
255
|
}
|
|
@@ -184,7 +258,10 @@ export class Residency {
|
|
|
184
258
|
return createModelPool(loadSdk, (state) => this.notify(state), {
|
|
185
259
|
deviceConfig: this.deviceConfig(),
|
|
186
260
|
loads: this._loads,
|
|
187
|
-
onUnloadFailure: (modelId, error) => this.gate.recordModelUnloadFailure(modelId, error)
|
|
261
|
+
onUnloadFailure: (modelId, error) => this.gate.recordModelUnloadFailure(modelId, error),
|
|
262
|
+
beforeLoad: (load) => this.beforeLoad(load),
|
|
263
|
+
chooseContext: (load, tier) => this._chooseContext(load, tier),
|
|
264
|
+
hold: this._hold
|
|
188
265
|
});
|
|
189
266
|
}
|
|
190
267
|
loadLifecycleSdk() {
|
|
@@ -212,7 +289,7 @@ export class Residency {
|
|
|
212
289
|
if (!this.gate.opened || this.gate.closing || this.gate.suspended || this.gate.draining) {
|
|
213
290
|
return;
|
|
214
291
|
}
|
|
215
|
-
|
|
292
|
+
HarnessLog.info('idle unload', { models: this.loaded().map((entry) => entry.model) });
|
|
216
293
|
const [pools, plugins] = await Promise.all([
|
|
217
294
|
Promise.allSettled([evictIdle(this._models), ...this._evictIdle()]),
|
|
218
295
|
this._unloadIdlePlugins()
|
|
@@ -220,7 +297,7 @@ export class Residency {
|
|
|
220
297
|
for (const outcome of [...pools, ...plugins]) {
|
|
221
298
|
if (outcome.status !== 'rejected')
|
|
222
299
|
continue;
|
|
223
|
-
|
|
300
|
+
HarnessLog.warn('idle unload failed', { err: errorMessage(outcome.reason) });
|
|
224
301
|
}
|
|
225
302
|
invalidateModelStatusCache(this._modelStatus);
|
|
226
303
|
this.fit.clearRows();
|
|
@@ -232,7 +309,7 @@ export class Residency {
|
|
|
232
309
|
return this.fit
|
|
233
310
|
.rows(() => this._rowQueries())
|
|
234
311
|
.catch((err) => {
|
|
235
|
-
|
|
312
|
+
HarnessLog.warn('fit estimate failed', { rows: rows.length, err: errorMessage(err) });
|
|
236
313
|
return new Map();
|
|
237
314
|
});
|
|
238
315
|
}
|
|
@@ -259,14 +336,14 @@ export class Residency {
|
|
|
259
336
|
return;
|
|
260
337
|
}
|
|
261
338
|
const target = this._target(model, agent);
|
|
262
|
-
|
|
339
|
+
HarnessLog.info('warm model', { model, resident: isResident(target.pool, target.key) });
|
|
263
340
|
await this._loadAndRelease(target, signal, async () => {
|
|
264
341
|
await this._embedRoom(model, target);
|
|
265
342
|
if (isResident(target.pool, target.key)) {
|
|
266
343
|
return true;
|
|
267
344
|
}
|
|
268
345
|
if (target.needsRoom) {
|
|
269
|
-
return this._roomForPlugin(signal, WARM_ROOM_WAIT_MS);
|
|
346
|
+
return this._capBytes !== null || this._roomForPlugin(signal, WARM_ROOM_WAIT_MS);
|
|
270
347
|
}
|
|
271
348
|
if (!target.loadOpts) {
|
|
272
349
|
return true;
|
|
@@ -283,13 +360,16 @@ export class Residency {
|
|
|
283
360
|
await this.gate.ready();
|
|
284
361
|
}
|
|
285
362
|
if (this.gate.suspended) {
|
|
286
|
-
throw new
|
|
363
|
+
throw new HarnessError('HARNESS_SUSPENDED');
|
|
287
364
|
}
|
|
288
365
|
const target = this._target(model, agent);
|
|
289
366
|
const resident = isResident(target.pool, target.key);
|
|
290
|
-
|
|
367
|
+
HarnessLog.info('load model', { model, resident });
|
|
368
|
+
if (!resident && !(await this._admitByHand(model, target, signal))) {
|
|
369
|
+
return { loaded: false, reason: 'memory' };
|
|
370
|
+
}
|
|
291
371
|
if (!target.loadOpts) {
|
|
292
|
-
await this.
|
|
372
|
+
await this._loadByHand(target, signal, async () => {
|
|
293
373
|
await this._embedRoom(model, target);
|
|
294
374
|
if (target.needsRoom && !isResident(target.pool, target.key)) {
|
|
295
375
|
await this.makeRoomForPlugin(signal, LOAD_BUSY_MESSAGE);
|
|
@@ -299,19 +379,12 @@ export class Residency {
|
|
|
299
379
|
return { loaded: true };
|
|
300
380
|
}
|
|
301
381
|
if (!resident) {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
return { loaded: false, reason: 'memory' };
|
|
305
|
-
}
|
|
306
|
-
if (choice && !target.loadOpts.ctxSize && !signal?.aborted) {
|
|
307
|
-
this.fit.keep(target.key, choice);
|
|
308
|
-
}
|
|
309
|
-
await evictIdleWhere(this._models, (key) => modelOf(key) === model && !this._replying.includes(key));
|
|
310
|
-
await this.unloadIdleGenerators();
|
|
382
|
+
await evictIdleWhere(this._models, this._replacedBy(model));
|
|
383
|
+
await this._yieldGenerators();
|
|
311
384
|
}
|
|
312
385
|
this._pinned.add(target.key);
|
|
313
386
|
try {
|
|
314
|
-
await this.
|
|
387
|
+
await this._loadByHand(target, signal);
|
|
315
388
|
}
|
|
316
389
|
catch (err) {
|
|
317
390
|
this._pinned.delete(target.key);
|
|
@@ -326,7 +399,7 @@ export class Residency {
|
|
|
326
399
|
const target = this._target(model);
|
|
327
400
|
const name = modelOf(target.key);
|
|
328
401
|
const unloaded = await evictModel(target.pool, name, { deadlineMs: UNLOAD_LEASE_WAIT_MS });
|
|
329
|
-
|
|
402
|
+
HarnessLog.info('unload model', { model, unloaded });
|
|
330
403
|
if (unloaded) {
|
|
331
404
|
for (const key of this._pinned) {
|
|
332
405
|
if (modelOf(key) === name) {
|
|
@@ -340,9 +413,294 @@ export class Residency {
|
|
|
340
413
|
const lease = await this.acquireLease({ pool, key, open, signal, prepare });
|
|
341
414
|
lease?.release();
|
|
342
415
|
}
|
|
416
|
+
async _loadByHand(target, signal, prepare = async () => true) {
|
|
417
|
+
let started = false;
|
|
418
|
+
const settle = () => {
|
|
419
|
+
if (this._byHand.delete(target.key)) {
|
|
420
|
+
this._reserved.delete(target.key);
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
try {
|
|
424
|
+
const lease = await this.acquireLease({
|
|
425
|
+
pool: target.pool,
|
|
426
|
+
key: target.key,
|
|
427
|
+
open: target.open,
|
|
428
|
+
signal,
|
|
429
|
+
prepare,
|
|
430
|
+
onLoad: (loading) => {
|
|
431
|
+
started = true;
|
|
432
|
+
void loading.then(noop, noop).then(settle);
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
lease?.release();
|
|
436
|
+
}
|
|
437
|
+
finally {
|
|
438
|
+
if (!started) {
|
|
439
|
+
settle();
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}
|
|
343
443
|
async unloadIdleGenerators() {
|
|
344
444
|
await this._unloadIdlePlugins();
|
|
345
445
|
}
|
|
446
|
+
async _yieldGenerators() {
|
|
447
|
+
if (this._capBytes === null) {
|
|
448
|
+
await this.unloadIdleGenerators();
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
async _admitByHand(model, target, signal) {
|
|
452
|
+
if (this._capBytes === null) {
|
|
453
|
+
return this._chooseByHand(model, target, signal);
|
|
454
|
+
}
|
|
455
|
+
return this._admit(async () => {
|
|
456
|
+
if (isResident(target.pool, target.key) || this._byHand.has(target.key)) {
|
|
457
|
+
return true;
|
|
458
|
+
}
|
|
459
|
+
const sized = await this._sizeByHand(model, target);
|
|
460
|
+
const capBytes = this._capBytes;
|
|
461
|
+
const replaced = this._replacedEntries(model, target);
|
|
462
|
+
const used = this._usedBytes() - replaced.reduce((sum, { bytes }) => sum + (bytes ?? 0), 0);
|
|
463
|
+
const alone = this._alone(model, target);
|
|
464
|
+
const fits = capBytes === null || alone || sized.bytes === undefined || used + sized.bytes <= capBytes;
|
|
465
|
+
if ((sized.tooLarge && !alone) || !fits) {
|
|
466
|
+
return false;
|
|
467
|
+
}
|
|
468
|
+
this._byHand.set(target.key, sized.ctxSize);
|
|
469
|
+
if (sized.bytes !== undefined) {
|
|
470
|
+
this._reserved.set(target.key, sized.bytes);
|
|
471
|
+
}
|
|
472
|
+
return true;
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
async _chooseByHand(model, target, signal) {
|
|
476
|
+
if (!target.loadOpts) {
|
|
477
|
+
return true;
|
|
478
|
+
}
|
|
479
|
+
const choice = await this._loadDecision(model, target.loadOpts);
|
|
480
|
+
if (choice?.fits === false) {
|
|
481
|
+
return this._alone(model, target);
|
|
482
|
+
}
|
|
483
|
+
if (choice && !target.loadOpts.ctxSize && !signal?.aborted) {
|
|
484
|
+
this.fit.keep(target.key, choice);
|
|
485
|
+
}
|
|
486
|
+
return true;
|
|
487
|
+
}
|
|
488
|
+
_replacedBy(model) {
|
|
489
|
+
return (key) => modelOf(key) === model && !this._replying.includes(key);
|
|
490
|
+
}
|
|
491
|
+
_replacedEntries(model, target) {
|
|
492
|
+
const replacedBy = this._replacedBy(model);
|
|
493
|
+
return target.pool === this._models
|
|
494
|
+
? settledEntries(this._models).filter(({ key, refs }) => refs === 0 && replacedBy(key))
|
|
495
|
+
: [];
|
|
496
|
+
}
|
|
497
|
+
_alone(model, target) {
|
|
498
|
+
const settled = this._pools().flatMap((pool) => settledEntries(pool));
|
|
499
|
+
const loading = this._pools().some((pool) => loadingModels(pool).length > 0);
|
|
500
|
+
return (!loading &&
|
|
501
|
+
this._reserved.size === 0 &&
|
|
502
|
+
settled.length === this._replacedEntries(model, target).length);
|
|
503
|
+
}
|
|
504
|
+
async _sizeByHand(model, target) {
|
|
505
|
+
const addon = modelAddonOf(model);
|
|
506
|
+
const modelSrc = curatedModelAsset(model, addon) ?? customModelSrc(model, addon) ?? model;
|
|
507
|
+
let ctxSize;
|
|
508
|
+
let modelConfig;
|
|
509
|
+
if (target.loadOpts) {
|
|
510
|
+
const load = { opts: target.loadOpts, deviceConfig: this.deviceConfig() };
|
|
511
|
+
const slots = slotCount(model, load);
|
|
512
|
+
ctxSize = contextSize(model, modelSrc, load) * slots;
|
|
513
|
+
modelConfig = {
|
|
514
|
+
ctx_size: ctxSize,
|
|
515
|
+
parallel: slots > 1 ? slots : undefined,
|
|
516
|
+
projectionModelSrc: this._projectionFor(model)
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
const sized = await this._sizeLoad({
|
|
520
|
+
key: target.key,
|
|
521
|
+
model,
|
|
522
|
+
modelSrc,
|
|
523
|
+
modelType: target.modelType,
|
|
524
|
+
modelConfig
|
|
525
|
+
});
|
|
526
|
+
return { ...sized, ctxSize };
|
|
527
|
+
}
|
|
528
|
+
async _admit(run) {
|
|
529
|
+
await this._admission.lock();
|
|
530
|
+
try {
|
|
531
|
+
return await run();
|
|
532
|
+
}
|
|
533
|
+
finally {
|
|
534
|
+
this._admission.unlock();
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
async beforeLoad(load) {
|
|
538
|
+
if (!this._sizeLoads)
|
|
539
|
+
return undefined;
|
|
540
|
+
const bytes = this._byHand.has(load.key)
|
|
541
|
+
? await this._admit(() => this._reserveByHand(load))
|
|
542
|
+
: await this._admit(() => this._reserve(load));
|
|
543
|
+
return { bytes, release: () => this._reserved.delete(load.key) };
|
|
544
|
+
}
|
|
545
|
+
async _reserveByHand(load) {
|
|
546
|
+
const admittedAt = this._byHand.get(load.key);
|
|
547
|
+
this._byHand.delete(load.key);
|
|
548
|
+
if (load.modelConfig?.['ctx_size'] !== admittedAt) {
|
|
549
|
+
const { bytes } = await this._sizeLoad(load);
|
|
550
|
+
if (bytes !== undefined) {
|
|
551
|
+
this._reserved.set(load.key, bytes);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
return this._reserved.get(load.key);
|
|
555
|
+
}
|
|
556
|
+
async _reserve(load) {
|
|
557
|
+
const sized = await this._sizeLoad(load);
|
|
558
|
+
if (this._capBytes !== null) {
|
|
559
|
+
await this._makeRoom(sized.bytes ?? 0, {
|
|
560
|
+
generators: true,
|
|
561
|
+
tooLarge: sized.tooLarge,
|
|
562
|
+
recheck: async () => (await this._sizeLoad(load)).tooLarge
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
if (sized.bytes !== undefined) {
|
|
566
|
+
this._reserved.set(load.key, sized.bytes);
|
|
567
|
+
}
|
|
568
|
+
return sized.bytes;
|
|
569
|
+
}
|
|
570
|
+
async _sizeLoad({ model, modelSrc, modelType, modelConfig }) {
|
|
571
|
+
const downloaded = downloadBytes(modelSrc);
|
|
572
|
+
const { projectionModelSrc, ...config } = modelConfig ?? {};
|
|
573
|
+
const projection = downloadBytes(projectionModelSrc) ?? 0;
|
|
574
|
+
try {
|
|
575
|
+
const sdk = await this.sdk.load();
|
|
576
|
+
const { models } = await sdk.assessModelFit({
|
|
577
|
+
models: [{ modelSrc: fitSrc(modelSrc), modelType, modelConfig: config }]
|
|
578
|
+
});
|
|
579
|
+
const [fit] = models;
|
|
580
|
+
const bytes = fit?.floorBytes ?? downloaded;
|
|
581
|
+
return {
|
|
582
|
+
bytes: bytes === undefined ? undefined : bytes + projection,
|
|
583
|
+
tooLarge: fit?.verdict === 'likely-too-large',
|
|
584
|
+
confirmed: fit?.verdict === 'likely-fits' && fit.evidence === 'native-fit'
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
catch (err) {
|
|
588
|
+
HarnessLog.warn('fit estimate failed', { model, err: errorMessage(err) });
|
|
589
|
+
return {
|
|
590
|
+
bytes: downloaded === undefined ? undefined : downloaded + projection,
|
|
591
|
+
tooLarge: false,
|
|
592
|
+
confirmed: false
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
async _chooseContext(load, tier) {
|
|
597
|
+
if (this._borrowed.has(load.model)) {
|
|
598
|
+
return tier;
|
|
599
|
+
}
|
|
600
|
+
const parallel = load.modelConfig?.['parallel'];
|
|
601
|
+
const slots = typeof parallel === 'number' ? parallel : 1;
|
|
602
|
+
const ctxSize = await this._contexts.choose(load.key, tier, {
|
|
603
|
+
trained: () => this._trainedContext(load),
|
|
604
|
+
fits: async (rung) => {
|
|
605
|
+
const sized = await this._sizeLoad({
|
|
606
|
+
...load,
|
|
607
|
+
modelConfig: { ...load.modelConfig, ctx_size: rung * slots }
|
|
608
|
+
});
|
|
609
|
+
const room = this._capRoom(load.key);
|
|
610
|
+
return sized.confirmed && (room === null || (sized.bytes ?? Infinity) <= room);
|
|
611
|
+
}
|
|
612
|
+
});
|
|
613
|
+
HarnessLog.info('context chosen', { model: load.model, tier, ctxSize });
|
|
614
|
+
return ctxSize;
|
|
615
|
+
}
|
|
616
|
+
_capRoom(key) {
|
|
617
|
+
const cap = this._capBytes;
|
|
618
|
+
return cap === null ? null : cap - (this._usedBytes() - (this._reserved.get(key) ?? 0));
|
|
619
|
+
}
|
|
620
|
+
async _contextProfile() {
|
|
621
|
+
const { capabilityProfile, memoryBudget } = await this._capability();
|
|
622
|
+
return memoryBudget ? capabilityProfile : undefined;
|
|
623
|
+
}
|
|
624
|
+
async _trainedContext({ model, modelSrc }) {
|
|
625
|
+
const custom = customContextLength(model);
|
|
626
|
+
if (custom || typeof modelSrc === 'string') {
|
|
627
|
+
return custom;
|
|
628
|
+
}
|
|
629
|
+
const info = await this._modelInfo(modelSrc.name);
|
|
630
|
+
const file = info?.cacheFiles[0]?.path;
|
|
631
|
+
const bytes = file ? await readGgufHeaderBytes(file) : null;
|
|
632
|
+
return (bytes && parseGgufHeader(bytes)?.contextLength) || undefined;
|
|
633
|
+
}
|
|
634
|
+
async _modelInfo(name) {
|
|
635
|
+
try {
|
|
636
|
+
const sdk = await this.sdk.load();
|
|
637
|
+
return await sdk.getModelInfo({ name });
|
|
638
|
+
}
|
|
639
|
+
catch {
|
|
640
|
+
return null;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
async _makeRoom(need, room) {
|
|
644
|
+
const capBytes = this._capBytes;
|
|
645
|
+
if (capBytes === null) {
|
|
646
|
+
return;
|
|
647
|
+
}
|
|
648
|
+
const tried = new Set();
|
|
649
|
+
let tooLarge = room.tooLarge ?? false;
|
|
650
|
+
while (this._usedBytes() + need > capBytes || tooLarge) {
|
|
651
|
+
const victim = nextVictim(this._capVictims(room).filter(({ id }) => !tried.has(id)));
|
|
652
|
+
if (!victim) {
|
|
653
|
+
HarnessLog.warn('model over memory cap', {
|
|
654
|
+
need,
|
|
655
|
+
used: this._usedBytes(),
|
|
656
|
+
capBytes,
|
|
657
|
+
tooLarge
|
|
658
|
+
});
|
|
659
|
+
return;
|
|
660
|
+
}
|
|
661
|
+
tried.add(victim.id);
|
|
662
|
+
await victim.evict();
|
|
663
|
+
if (tooLarge && room.recheck) {
|
|
664
|
+
tooLarge = await room.recheck();
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
_capVictims({ replying = false, generators = false }) {
|
|
669
|
+
const victims = [];
|
|
670
|
+
if (generators) {
|
|
671
|
+
victims.push({
|
|
672
|
+
id: 'generators',
|
|
673
|
+
rank: VictimRank.generator,
|
|
674
|
+
lastUsed: 0,
|
|
675
|
+
evict: () => this.unloadIdleGenerators()
|
|
676
|
+
});
|
|
677
|
+
}
|
|
678
|
+
for (const [index, pool] of this._pools().entries()) {
|
|
679
|
+
for (const { key, refs, lastUsed } of settledEntries(pool)) {
|
|
680
|
+
const inReply = this._replying.includes(key);
|
|
681
|
+
if (refs > 0 || (inReply && !replying)) {
|
|
682
|
+
continue;
|
|
683
|
+
}
|
|
684
|
+
victims.push({
|
|
685
|
+
id: `${index}:${key}`,
|
|
686
|
+
rank: this._victimRank(pool, key, inReply),
|
|
687
|
+
lastUsed,
|
|
688
|
+
evict: () => evictIdleWithin(pool, key, { deadlineMs: WEDGED_EVICT_WAIT_MS })
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
return victims;
|
|
693
|
+
}
|
|
694
|
+
_victimRank(pool, key, inReply) {
|
|
695
|
+
if (pool !== this._models)
|
|
696
|
+
return VictimRank.companion;
|
|
697
|
+
if (inReply)
|
|
698
|
+
return VictimRank.replying;
|
|
699
|
+
return this._pinned.has(key) ? VictimRank.pinned : VictimRank.requested;
|
|
700
|
+
}
|
|
701
|
+
_usedBytes() {
|
|
702
|
+
return this.settledBytes() + [...this._reserved.values()].reduce((sum, bytes) => sum + bytes, 0);
|
|
703
|
+
}
|
|
346
704
|
async _fits(model, loadOpts, { native = false } = {}) {
|
|
347
705
|
const asset = curatedModelAsset(model, 'llm');
|
|
348
706
|
if (!asset) {
|
|
@@ -385,6 +743,7 @@ export class Residency {
|
|
|
385
743
|
return {
|
|
386
744
|
pool: this._models,
|
|
387
745
|
key,
|
|
746
|
+
modelType: 'llamacpp-completion',
|
|
388
747
|
loadOpts,
|
|
389
748
|
open: () => this._models.open(key, model, loadOpts)
|
|
390
749
|
};
|
|
@@ -392,7 +751,7 @@ export class Residency {
|
|
|
392
751
|
if (addon === 'embeddings' || addon === 'tts' || addon === 'parakeet') {
|
|
393
752
|
return this._poolFor(addon, model);
|
|
394
753
|
}
|
|
395
|
-
throw new
|
|
754
|
+
throw new HarnessError('MODEL_NOT_RESIDENT', [model]);
|
|
396
755
|
}
|
|
397
756
|
loadOptions(model, agent) {
|
|
398
757
|
return resolveLoadOptions({
|
|
@@ -402,7 +761,7 @@ export class Residency {
|
|
|
402
761
|
projectionModel: this._projectionFor(model)
|
|
403
762
|
}, this.deviceConfig());
|
|
404
763
|
}
|
|
405
|
-
async acquireLease({ pool, key, open, signal, prepare }) {
|
|
764
|
+
async acquireLease({ pool, key, open, signal, prepare, onLoad }) {
|
|
406
765
|
const releaseWork = this.gate.enterWork();
|
|
407
766
|
let pendingLoad = null;
|
|
408
767
|
let opened = false;
|
|
@@ -430,7 +789,7 @@ export class Residency {
|
|
|
430
789
|
throw new AbortedError();
|
|
431
790
|
}
|
|
432
791
|
if (this.gate.suspended || this.gate.draining) {
|
|
433
|
-
throw new
|
|
792
|
+
throw new HarnessError('HARNESS_SUSPENDED');
|
|
434
793
|
}
|
|
435
794
|
this.gate.assertNotClosing();
|
|
436
795
|
if (this.gate.unloadFailed) {
|
|
@@ -440,8 +799,9 @@ export class Residency {
|
|
|
440
799
|
opened = true;
|
|
441
800
|
const loading = handle.load();
|
|
442
801
|
pendingLoad = loading;
|
|
802
|
+
onLoad?.(loading);
|
|
443
803
|
const loaded = await raceAbort(loading, signal);
|
|
444
|
-
return { modelId: loaded.modelId, ctxSize: loaded.ctxSize, release };
|
|
804
|
+
return { modelId: loaded.modelId, ctxSize: loaded.ctxSize, slots: loaded.slots, release };
|
|
445
805
|
}
|
|
446
806
|
catch (error) {
|
|
447
807
|
if (pendingLoad) {
|
|
@@ -463,6 +823,10 @@ export class Residency {
|
|
|
463
823
|
}
|
|
464
824
|
}
|
|
465
825
|
async makeRoomForCompletion(model, { loadOpts, signal, deadlineMs = MODEL_ROOM_WAIT_MS }) {
|
|
826
|
+
if (this._capBytes !== null) {
|
|
827
|
+
await evictIdleWhere(this._models, this._replacedBy(model));
|
|
828
|
+
return true;
|
|
829
|
+
}
|
|
466
830
|
const roomed = await awaitModelCapacity(this._models, {
|
|
467
831
|
cap: this._completionModelCap,
|
|
468
832
|
deadlineMs,
|
|
@@ -473,7 +837,7 @@ export class Residency {
|
|
|
473
837
|
await this.unloadIdleGenerators();
|
|
474
838
|
}
|
|
475
839
|
else {
|
|
476
|
-
|
|
840
|
+
HarnessLog.warn('model room wait gave up', {
|
|
477
841
|
cap: this._completionModelCap,
|
|
478
842
|
loaded: loadedModels(this._models).length
|
|
479
843
|
});
|
|
@@ -495,7 +859,7 @@ export class Residency {
|
|
|
495
859
|
const evicted = leased
|
|
496
860
|
? false
|
|
497
861
|
: await evictModelWithin(this._models, key, { deadlineMs: WEDGED_EVICT_WAIT_MS });
|
|
498
|
-
|
|
862
|
+
HarnessLog.warn('wedged model evicted', { model, faults, evicted, leased });
|
|
499
863
|
if (leased) {
|
|
500
864
|
this._evictAfterLeases(model, key);
|
|
501
865
|
}
|
|
@@ -514,7 +878,7 @@ export class Residency {
|
|
|
514
878
|
}
|
|
515
879
|
_evictAfterLeases(model, key) {
|
|
516
880
|
void evictModelWithin(this._models, key, { deadlineMs: WEDGED_EVICT_LEASED_MS })
|
|
517
|
-
.then((evicted) =>
|
|
881
|
+
.then((evicted) => HarnessLog.warn('wedged model evicted after leases', { model, evicted }))
|
|
518
882
|
.catch(noop);
|
|
519
883
|
}
|
|
520
884
|
async busy(run) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { errorMessage, isRecord } from './guards.js';
|
|
2
|
-
import {
|
|
2
|
+
import { HarnessLog } from './log.js';
|
|
3
3
|
function readValue(value, key) {
|
|
4
4
|
if (value === null)
|
|
5
5
|
return undefined;
|
|
@@ -80,7 +80,7 @@ export function installResolutionDetector(meta) {
|
|
|
80
80
|
const wrapped = (specifier, parentURL, opts = {}) => {
|
|
81
81
|
const parent = String(parentURL);
|
|
82
82
|
if (isReferrerLost(opts.referrer, parent, cacheRecord)) {
|
|
83
|
-
|
|
83
|
+
HarnessLog.warn('diag referrer LOST', {
|
|
84
84
|
specifier,
|
|
85
85
|
parent,
|
|
86
86
|
modules: Object.keys(cacheRecord).length,
|
|
@@ -92,7 +92,7 @@ export function installResolutionDetector(meta) {
|
|
|
92
92
|
}
|
|
93
93
|
catch (err) {
|
|
94
94
|
if (isReferrerLost(opts.referrer, parent, cacheRecord)) {
|
|
95
|
-
|
|
95
|
+
HarnessLog.error('diag resolve FAILED after a lost referrer', resolutionFailure(specifier, parent, err));
|
|
96
96
|
}
|
|
97
97
|
throw err;
|
|
98
98
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { HarnessError } from './errors.js';
|
|
1
2
|
export function settleOnClose(hrpc) {
|
|
2
3
|
const session = hrpc;
|
|
3
4
|
let reason = null;
|
|
4
5
|
const dead = (err) => {
|
|
5
|
-
reason ??= err ?? new
|
|
6
|
+
reason ??= err ?? new HarnessError('RPC_STREAM_DESTROYED');
|
|
6
7
|
};
|
|
7
8
|
const call = session._call.bind(session);
|
|
8
9
|
const callSync = session._callSync.bind(session);
|