@qvac/harness 1.0.0-rc.2 → 1.0.0-rc.20
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 +3050 -1485
- package/README.md +110 -46
- package/dist-lib/index.d.ts +60 -15
- package/dist-lib/index.js +228 -35
- 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 +11 -2
- package/dist-lib/lib/agent/resolve.js +29 -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 +2 -0
- package/dist-lib/lib/agent/tools.js +2 -1
- package/dist-lib/lib/capabilities/agent-ports.d.ts +1 -1
- package/dist-lib/lib/capabilities/agent-ports.js +11 -4
- 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.d.ts +2 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/executing.js +129 -12
- package/dist-lib/lib/capabilities/completion-engine/actors/execution-plan.js +10 -4
- package/dist-lib/lib/capabilities/completion-engine/actors/inspect-prepare.js +3 -2
- package/dist-lib/lib/capabilities/completion-engine/actors/inspecting.d.ts +1 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/inspecting.js +54 -10
- 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 +10 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/preparing.js +137 -50
- package/dist-lib/lib/capabilities/completion-engine/actors/rejecting.js +10 -4
- package/dist-lib/lib/capabilities/completion-engine/actors/resolving.js +69 -17
- package/dist-lib/lib/capabilities/completion-engine/actors/retrieving.d.ts +2 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/retrieving.js +33 -16
- package/dist-lib/lib/capabilities/completion-engine/actors/run-prepare.js +36 -22
- package/dist-lib/lib/capabilities/completion-engine/actors/skill-step.js +50 -12
- package/dist-lib/lib/capabilities/completion-engine/actors/stream.d.ts +10 -4
- package/dist-lib/lib/capabilities/completion-engine/actors/stream.js +80 -3
- package/dist-lib/lib/capabilities/completion-engine/actors/streaming.d.ts +5 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/streaming.js +95 -35
- package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.d.ts +2 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.js +55 -16
- package/dist-lib/lib/capabilities/completion-engine/driver.js +58 -15
- package/dist-lib/lib/capabilities/completion-engine/durable.d.ts +3 -1
- package/dist-lib/lib/capabilities/completion-engine/durable.js +12 -2
- package/dist-lib/lib/capabilities/completion-engine/engine.d.ts +4 -1
- package/dist-lib/lib/capabilities/completion-engine/engine.js +14 -1
- package/dist-lib/lib/capabilities/completion-engine/index.d.ts +5 -1
- package/dist-lib/lib/capabilities/completion-engine/index.js +5 -2
- package/dist-lib/lib/capabilities/completion-engine/loop.d.ts +25 -3
- package/dist-lib/lib/capabilities/completion-engine/loop.js +13 -2
- 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 +63 -0
- package/dist-lib/lib/capabilities/completion-engine/model-round.js +99 -0
- package/dist-lib/lib/capabilities/completion-engine/operations.js +30 -10
- package/dist-lib/lib/capabilities/completion-engine/ports.js +6 -9
- package/dist-lib/lib/capabilities/completion-engine/prepare-step.d.ts +4 -1
- package/dist-lib/lib/capabilities/completion-engine/round.d.ts +38 -6
- package/dist-lib/lib/capabilities/completion-engine/round.js +393 -116
- package/dist-lib/lib/capabilities/completion-engine/session.d.ts +12 -4
- package/dist-lib/lib/capabilities/completion-engine/session.js +31 -2
- package/dist-lib/lib/capabilities/completion-engine/tool-caller.js +3 -2
- package/dist-lib/lib/capabilities/completion-engine/tool-execution.d.ts +5 -4
- package/dist-lib/lib/capabilities/completion-engine/tool-execution.js +32 -12
- package/dist-lib/lib/capabilities/completion-engine/tool-sets.d.ts +24 -0
- package/dist-lib/lib/capabilities/completion-engine/tool-sets.js +15 -0
- package/dist-lib/lib/capabilities/completion-engine/turns.d.ts +17 -9
- package/dist-lib/lib/capabilities/completion-engine/turns.js +96 -87
- package/dist-lib/lib/capabilities/detect-language.d.ts +2 -1
- package/dist-lib/lib/capabilities/detect-language.js +14 -2
- package/dist-lib/lib/capabilities/download.d.ts +10 -8
- 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 +23 -11
- package/dist-lib/lib/capabilities/kv-cache.d.ts +1 -1
- 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/prompt-prefix.d.ts +3 -1
- package/dist-lib/lib/capabilities/prompt-prefix.js +8 -0
- package/dist-lib/lib/capabilities/sdk-tool.d.ts +13 -4
- package/dist-lib/lib/capabilities/sdk-tool.js +59 -7
- package/dist-lib/lib/capabilities/skill-entry.d.ts +13 -1
- package/dist-lib/lib/capabilities/skill-entry.js +33 -2
- package/dist-lib/lib/capabilities/tool-failed-note.d.ts +1 -0
- package/dist-lib/lib/capabilities/tool-failed-note.js +1 -0
- package/dist-lib/lib/capabilities/tool-plan.d.ts +5 -1
- package/dist-lib/lib/capabilities/tool-plan.js +20 -5
- package/dist-lib/lib/capabilities/tool-prompt-log.d.ts +1 -1
- package/dist-lib/lib/capabilities/tool-prompt-log.js +3 -3
- package/dist-lib/lib/capabilities/tool-turns.d.ts +20 -9
- package/dist-lib/lib/capabilities/tool-turns.js +77 -49
- package/dist-lib/lib/capabilities/usage-breakdown.d.ts +1 -0
- package/dist-lib/lib/capabilities/usage-breakdown.js +4 -1
- package/dist-lib/lib/client/index.d.ts +19 -0
- package/dist-lib/lib/client/index.js +263 -0
- package/dist-lib/lib/connect.d.ts +19 -10
- package/dist-lib/lib/connect.js +239 -32
- package/dist-lib/lib/context-window.d.ts +2 -0
- package/dist-lib/lib/context-window.js +9 -3
- package/dist-lib/lib/contract/agent.d.ts +13 -3
- package/dist-lib/lib/contract/completion.d.ts +77 -31
- package/dist-lib/lib/contract/drive.d.ts +4 -0
- package/dist-lib/lib/contract/drive.js +1 -0
- 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 +4 -3
- package/dist-lib/lib/contract/hooks.d.ts +4 -1
- package/dist-lib/lib/contract/index.d.ts +4 -0
- package/dist-lib/lib/contract/knowledge.d.ts +10 -0
- package/dist-lib/lib/contract/managed-skills.d.ts +1 -0
- package/dist-lib/lib/contract/managed-skills.js +1 -0
- package/dist-lib/lib/contract/media.d.ts +58 -0
- package/dist-lib/lib/contract/media.js +1 -0
- package/dist-lib/lib/contract/models.d.ts +12 -6
- package/dist-lib/lib/contract/ocr.d.ts +13 -0
- package/dist-lib/lib/contract/ocr.js +1 -0
- 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 +28 -3
- package/dist-lib/lib/contract/sandbox.d.ts +3 -1
- package/dist-lib/lib/contract/speech.d.ts +1 -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 +46 -16
- 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 +278 -0
- package/dist-lib/lib/errors.js +212 -0
- package/dist-lib/lib/fold/index.d.ts +26 -1
- package/dist-lib/lib/fold/index.js +76 -9
- package/dist-lib/lib/guarded-fetch.js +11 -7
- package/dist-lib/lib/guards.d.ts +2 -0
- package/dist-lib/lib/guards.js +7 -0
- package/dist-lib/lib/hardware/capability-probe.js +10 -7
- package/dist-lib/lib/hardware/cpu-placement.d.ts +8 -0
- package/dist-lib/lib/hardware/cpu-placement.js +48 -0
- package/dist-lib/lib/hardware/gpu-probe-addon.js +26 -11
- package/dist-lib/lib/hardware/gpu-probe.js +10 -1
- package/dist-lib/lib/hardware/gpu-stats.native.cjs +17 -1
- package/dist-lib/lib/helpers/completion-params.d.ts +7 -2
- package/dist-lib/lib/helpers/completion-params.js +26 -2
- package/dist-lib/lib/helpers/control-tokens.d.ts +3 -0
- package/dist-lib/lib/helpers/control-tokens.js +25 -0
- 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 +44 -0
- package/dist-lib/lib/helpers/goal-check.js +407 -0
- package/dist-lib/lib/helpers/head-tail.js +1 -1
- package/dist-lib/lib/helpers/html-helpers.js +9 -6
- 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/require-peers.d.ts +3 -0
- package/dist-lib/lib/helpers/require-peers.js +23 -0
- package/dist-lib/lib/helpers/run-outcome.d.ts +2 -0
- package/dist-lib/lib/helpers/run-outcome.js +6 -2
- package/dist-lib/lib/helpers/spawn-path.d.ts +1 -0
- package/dist-lib/lib/helpers/spawn-path.js +2 -1
- 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 +11 -6
- package/dist-lib/lib/machine/completion/actions/completion.js +251 -35
- package/dist-lib/lib/machine/completion/actions/prepare.js +1 -1
- package/dist-lib/lib/machine/completion/actions/tools.js +122 -6
- package/dist-lib/lib/machine/completion/context.js +11 -1
- package/dist-lib/lib/machine/completion/guards/retry.d.ts +3 -1
- package/dist-lib/lib/machine/completion/guards/retry.js +9 -2
- package/dist-lib/lib/machine/completion/implementations.d.ts +16 -7
- package/dist-lib/lib/machine/completion/implementations.js +59 -15
- package/dist-lib/lib/machine/completion/machine.d.ts +36 -7
- package/dist-lib/lib/machine/completion/machine.js +58 -9
- package/dist-lib/lib/machine/completion/rules.d.ts +23 -2
- package/dist-lib/lib/machine/completion/rules.js +91 -6
- package/dist-lib/lib/machine/completion/types.d.ts +77 -1
- package/dist-lib/lib/machine/index.d.ts +48 -9
- package/dist-lib/lib/machine/index.js +11 -1
- package/dist-lib/lib/media-host.d.ts +12 -0
- package/dist-lib/lib/media-host.js +52 -0
- package/dist-lib/lib/media-port.d.ts +20 -0
- package/dist-lib/lib/media-port.js +77 -0
- package/dist-lib/lib/media-wire.d.ts +8 -0
- package/dist-lib/lib/media-wire.js +111 -0
- package/dist-lib/lib/models/context-choice.d.ts +15 -0
- package/dist-lib/lib/models/context-choice.js +62 -0
- package/dist-lib/lib/models/context.d.ts +1 -1
- package/dist-lib/lib/models/custom-model-cache.d.ts +1 -0
- package/dist-lib/lib/models/custom-model-cache.js +3 -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 +11 -0
- package/dist-lib/lib/models/gguf-header.js +203 -15
- package/dist-lib/lib/models/gpu-selection.d.ts +6 -1
- package/dist-lib/lib/models/gpu-selection.js +29 -5
- package/dist-lib/lib/models/kv-cache.d.ts +2 -0
- package/dist-lib/lib/models/kv-cache.js +8 -0
- package/dist-lib/lib/models/llm-presets.d.ts +6 -1
- package/dist-lib/lib/models/llm-presets.js +33 -6
- package/dist-lib/lib/models/load-requests.d.ts +9 -0
- package/dist-lib/lib/models/load-requests.js +42 -0
- 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-constants.d.ts +2 -2
- package/dist-lib/lib/models/model-catalog-constants.js +3 -4
- package/dist-lib/lib/models/model-catalog.d.ts +7 -3
- package/dist-lib/lib/models/model-catalog.js +44 -11
- package/dist-lib/lib/models/model-delete.d.ts +1 -1
- package/dist-lib/lib/models/model-fit.d.ts +2 -2
- package/dist-lib/lib/models/model-fit.js +5 -6
- package/dist-lib/lib/models/model-handle.d.ts +9 -2
- package/dist-lib/lib/models/model-handle.js +14 -3
- package/dist-lib/lib/models/model-list.d.ts +9 -2
- package/dist-lib/lib/models/model-list.js +23 -0
- package/dist-lib/lib/models/model-pool.d.ts +42 -7
- package/dist-lib/lib/models/model-pool.js +139 -49
- package/dist-lib/lib/models/model-source.d.ts +3 -2
- package/dist-lib/lib/models/model-source.js +23 -5
- package/dist-lib/lib/models/opencl-cache.js +2 -2
- 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/models/tool-dialect.d.ts +1 -1
- package/dist-lib/lib/models/tts-model-default.d.ts +2 -1
- package/dist-lib/lib/models/tts-model-default.js +8 -6
- package/dist-lib/lib/no-redirect-fetch-bare.js +2 -1
- package/dist-lib/lib/no-redirect-fetch-impl.d.ts +2 -1
- package/dist-lib/lib/no-redirect-fetch-impl.js +46 -8
- 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 +64 -21
- package/dist-lib/lib/office/engine/pptx/types.d.ts +1 -0
- package/dist-lib/lib/office/engine/xlsx/sheet.js +10 -4
- 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 +15 -0
- package/dist-lib/lib/plugins/registry.js +91 -22
- package/dist-lib/lib/plugins/require-bare.d.ts +1 -0
- package/dist-lib/lib/plugins/require-bare.js +13 -0
- package/dist-lib/lib/policy/index.d.ts +11 -0
- package/dist-lib/lib/policy/index.js +235 -0
- package/dist-lib/lib/prompt.d.ts +9 -4
- package/dist-lib/lib/prompt.js +95 -32
- package/dist-lib/lib/residency/completion-runtime.d.ts +15 -5
- package/dist-lib/lib/residency/completion-runtime.js +47 -36
- package/dist-lib/lib/residency/index.d.ts +56 -4
- package/dist-lib/lib/residency/index.js +442 -40
- package/dist-lib/lib/resolution-detector.js +3 -3
- package/dist-lib/lib/round-host.d.ts +12 -0
- package/dist-lib/lib/round-host.js +57 -0
- package/dist-lib/lib/round-port.d.ts +24 -0
- package/dist-lib/lib/round-port.js +81 -0
- package/dist-lib/lib/rpc-session.js +2 -1
- package/dist-lib/lib/run-log/request-codec.js +2 -2
- package/dist-lib/lib/sdk-loader.d.ts +1 -1
- package/dist-lib/lib/sdk-loader.js +47 -17
- package/dist-lib/lib/sdk-storage.d.ts +1 -0
- package/dist-lib/lib/sdk-storage.js +18 -2
- package/dist-lib/lib/serve.js +242 -50
- package/dist-lib/lib/sidecar/index.d.ts +39 -0
- package/dist-lib/lib/sidecar/index.js +205 -0
- package/dist-lib/lib/sidecar/user-plugins.d.ts +9 -0
- package/dist-lib/lib/sidecar/user-plugins.js +119 -0
- package/dist-lib/lib/skills-host/index.d.ts +3 -1
- package/dist-lib/lib/skills-host/index.js +27 -14
- package/dist-lib/lib/spawn.d.ts +6 -4
- package/dist-lib/lib/spawn.js +22 -20
- package/dist-lib/lib/spill.d.ts +1 -0
- package/dist-lib/lib/spill.js +12 -8
- package/dist-lib/lib/tools/ask-user.d.ts +2 -0
- package/dist-lib/lib/tools/ask-user.js +137 -0
- package/dist-lib/lib/tools/attachments/delivered.d.ts +5 -0
- package/dist-lib/lib/tools/attachments/delivered.js +16 -0
- package/dist-lib/lib/tools/attachments/fetched-file.d.ts +32 -0
- package/dist-lib/lib/tools/attachments/fetched-file.js +134 -0
- package/dist-lib/lib/tools/attachments/staging.d.ts +1 -0
- package/dist-lib/lib/tools/attachments/staging.js +19 -8
- package/dist-lib/lib/tools/exec/runner.d.ts +4 -0
- package/dist-lib/lib/tools/exec/runner.js +20 -2
- 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 +89 -27
- package/dist-lib/lib/tools/files/edit-file.d.ts +6 -0
- package/dist-lib/lib/tools/files/edit-file.js +266 -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 +212 -0
- package/dist-lib/lib/tools/files/index.d.ts +3 -0
- package/dist-lib/lib/tools/files/index.js +25 -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 +224 -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 +8 -0
- package/dist-lib/lib/tools/fs/document-text.js +22 -0
- package/dist-lib/lib/tools/fs/drive.d.ts +10 -14
- package/dist-lib/lib/tools/fs/drive.js +9 -1
- package/dist-lib/lib/tools/fs/edit-match.d.ts +33 -0
- package/dist-lib/lib/tools/fs/edit-match.js +445 -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 +45 -3
- package/dist-lib/lib/tools/fs/remote-protocol.js +1 -1
- package/dist-lib/lib/tools/fs/remote.d.ts +3 -11
- package/dist-lib/lib/tools/fs/remote.js +24 -14
- 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 +383 -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 +16 -3
- package/dist-lib/lib/tools/fs/walk.js +119 -24
- package/dist-lib/lib/tools/http-request/request.d.ts +4 -2
- package/dist-lib/lib/tools/http-request/request.js +2 -1
- package/dist-lib/lib/tools/http-request/truncate-response.d.ts +16 -1
- package/dist-lib/lib/tools/http-request/truncate-response.js +56 -11
- package/dist-lib/lib/tools/http-request.d.ts +1 -0
- package/dist-lib/lib/tools/http-request.js +101 -16
- package/dist-lib/lib/tools/index.d.ts +4 -1
- package/dist-lib/lib/tools/index.js +8 -12
- package/dist-lib/lib/tools/office/ops.d.ts +1 -0
- package/dist-lib/lib/tools/office/ops.js +5 -1
- package/dist-lib/lib/tools/office.d.ts +2 -1
- package/dist-lib/lib/tools/office.js +273 -56
- package/dist-lib/lib/tools/operations/builders.d.ts +4 -3
- package/dist-lib/lib/tools/operations/builders.js +41 -3
- package/dist-lib/lib/tools/operations/calendar-range.d.ts +16 -0
- package/dist-lib/lib/tools/operations/calendar-range.js +40 -0
- package/dist-lib/lib/tools/operations/compile.js +8 -6
- package/dist-lib/lib/tools/operations/manifest.d.ts +4 -0
- package/dist-lib/lib/tools/pdf/build.d.ts +15 -1
- package/dist-lib/lib/tools/pdf/build.js +77 -16
- package/dist-lib/lib/tools/pdf/pages.d.ts +12 -0
- package/dist-lib/lib/tools/pdf/pages.js +31 -0
- package/dist-lib/lib/tools/pdf/recognize.d.ts +13 -0
- package/dist-lib/lib/tools/pdf/recognize.js +59 -0
- package/dist-lib/lib/tools/pdf.js +56 -12
- package/dist-lib/lib/tools/skill.js +10 -7
- package/dist-lib/lib/tools/skills/bundled-dir.d.ts +5 -1
- package/dist-lib/lib/tools/skills/bundled-dir.js +27 -24
- package/dist-lib/lib/tools/skills/catalog.d.ts +3 -1
- package/dist-lib/lib/tools/skills/catalog.js +7 -3
- 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-check.d.ts +1 -0
- package/dist-lib/lib/tools/skills/credential-check.js +3 -0
- package/dist-lib/lib/tools/skills/credential-health.js +3 -3
- package/dist-lib/lib/tools/skills/frontmatter-parser.d.ts +3 -0
- package/dist-lib/lib/tools/skills/frontmatter-parser.js +5 -0
- package/dist-lib/lib/tools/skills/manifest-parse.d.ts +1 -0
- package/dist-lib/lib/tools/skills/manifest-parse.js +39 -3
- package/dist-lib/lib/tools/skills/manifest.d.ts +1 -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.d.ts +3 -3
- package/dist-lib/lib/tools/skills/overlay-crud.js +7 -6
- package/dist-lib/lib/tools/skills/overlay-watch.d.ts +2 -2
- package/dist-lib/lib/tools/skills/overlay-watch.js +4 -3
- package/dist-lib/lib/tools/skills/scope-key.d.ts +1 -0
- package/dist-lib/lib/tools/skills/scope-key.js +4 -0
- package/dist-lib/lib/tools/skills/skill-state-constants.d.ts +1 -0
- package/dist-lib/lib/tools/skills/skill-state-constants.js +4 -0
- 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 +50 -133
- package/dist-lib/lib/wire.d.ts +13 -0
- package/dist-lib/lib/wire.js +78 -6
- package/dist-lib/plugins/coding/index.d.ts +1 -1
- package/dist-lib/plugins/coding/index.js +2 -4
- package/dist-lib/plugins/coding/read-only.d.ts +1 -0
- package/dist-lib/plugins/coding/read-only.js +264 -0
- package/dist-lib/plugins/coding/session.d.ts +6 -4
- package/dist-lib/plugins/coding/session.js +45 -16
- package/dist-lib/plugins/coding-guards/index.d.ts +25 -0
- package/dist-lib/plugins/coding-guards/index.js +126 -0
- 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 +184 -0
- package/dist-lib/plugins/image/edit-image.d.ts +3 -22
- package/dist-lib/plugins/image/edit-image.js +23 -46
- package/dist-lib/plugins/image/fit.d.ts +31 -0
- package/dist-lib/plugins/image/fit.js +28 -0
- package/dist-lib/plugins/image/generate-image.d.ts +27 -6
- package/dist-lib/plugins/image/generate-image.js +201 -74
- package/dist-lib/plugins/image/index.d.ts +2 -1
- package/dist-lib/plugins/image/index.js +29 -12
- package/dist-lib/plugins/knowledge/index.d.ts +3 -0
- package/dist-lib/plugins/knowledge/index.js +5 -0
- package/dist-lib/plugins/knowledge/manifest.d.ts +53 -0
- package/dist-lib/plugins/knowledge/manifest.js +86 -0
- package/dist-lib/plugins/knowledge/search-tool.js +8 -8
- package/dist-lib/plugins/knowledge/store.d.ts +45 -8
- package/dist-lib/plugins/knowledge/store.js +428 -166
- package/dist-lib/plugins/language-hint/index.d.ts +15 -0
- package/dist-lib/plugins/language-hint/index.js +54 -0
- package/dist-lib/plugins/lsp/tool.js +2 -2
- package/dist-lib/plugins/mcp/call.js +15 -4
- package/dist-lib/plugins/mcp/index.js +6 -3
- package/dist-lib/plugins/mcp/protocol.d.ts +10 -2
- package/dist-lib/plugins/mcp/protocol.js +13 -12
- package/dist-lib/plugins/mcp/server.js +1 -1
- package/dist-lib/plugins/mcp/tool-listing.d.ts +6 -0
- package/dist-lib/plugins/mcp/tool-listing.js +97 -0
- package/dist-lib/plugins/music/generate-music.d.ts +24 -5
- package/dist-lib/plugins/music/generate-music.js +170 -64
- package/dist-lib/plugins/music/index.d.ts +2 -1
- package/dist-lib/plugins/music/index.js +23 -11
- package/dist-lib/plugins/obsidian/command.js +2 -2
- package/dist-lib/plugins/obsidian/index.js +14 -4
- package/dist-lib/plugins/obsidian/note-name.js +2 -1
- package/dist-lib/plugins/obsidian/readiness.js +2 -2
- 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 +20 -18
- package/dist-lib/plugins/obsidian/vault-write.js +13 -12
- package/dist-lib/plugins/ocr/bmp.d.ts +2 -0
- package/dist-lib/plugins/ocr/bmp.js +27 -0
- package/dist-lib/plugins/ocr/index.d.ts +12 -0
- package/dist-lib/plugins/ocr/index.js +20 -0
- package/dist-lib/plugins/ocr/ocr-runtime.d.ts +23 -0
- package/dist-lib/plugins/ocr/ocr-runtime.js +82 -0
- package/dist-lib/plugins/ocr/reading-order.d.ts +5 -0
- package/dist-lib/plugins/ocr/reading-order.js +218 -0
- package/dist-lib/plugins/python/bare-floor.d.ts +1 -0
- package/dist-lib/plugins/python/bare-floor.js +2 -0
- 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/index.d.ts +4 -1
- package/dist-lib/plugins/python/index.js +6 -1
- package/dist-lib/plugins/python/interrupt-timer.js +2 -2
- package/dist-lib/plugins/python/language.js +11 -10
- package/dist-lib/plugins/python/loader.d.ts +1 -0
- package/dist-lib/plugins/python/loader.js +76 -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.d.ts +6 -1
- package/dist-lib/plugins/python/python-adapter.js +37 -2
- 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 +10 -9
- package/dist-lib/plugins/python/worker/entry.js +2 -8
- package/dist-lib/plugins/python/worker/preload.d.ts +1 -0
- package/dist-lib/plugins/python/worker/preload.js +2 -0
- 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 +3 -2
- package/dist-lib/plugins/quickjs/index.js +4 -0
- package/dist-lib/plugins/quickjs/runtime.js +8 -3
- 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 +32 -13
- package/dist-lib/plugins/run-report/layout.js +1 -1
- 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 +7 -4
- 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 +62 -0
- package/dist-lib/plugins/sandbox-linux/index.js +354 -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 +25 -11
- package/dist-lib/plugins/sandbox-macos/index.js +244 -49
- package/dist-lib/plugins/sandbox-vm/index.d.ts +2 -1
- package/dist-lib/plugins/sandbox-vm/index.js +5 -2
- package/dist-lib/plugins/sandbox-vm/vm-shell.d.ts +7 -3
- package/dist-lib/plugins/sandbox-vm/vm-shell.js +54 -20
- 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 +8 -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/index.d.ts +1 -0
- package/dist-lib/plugins/speech/index.js +8 -1
- package/dist-lib/plugins/speech/speech-engine.d.ts +1 -1
- package/dist-lib/plugins/speech/speech-engine.js +10 -5
- package/dist-lib/plugins/speech/speech-runtime.js +37 -37
- package/dist-lib/plugins/speech/speech-text.d.ts +1 -0
- package/dist-lib/plugins/speech/speech-text.js +9 -4
- package/dist-lib/plugins/speech/voice.d.ts +5 -1
- package/dist-lib/plugins/speech/voice.js +107 -33
- package/dist-lib/plugins/translation/index.d.ts +2 -1
- package/dist-lib/plugins/translation/index.js +21 -10
- package/dist-lib/plugins/translation/translate.d.ts +9 -5
- package/dist-lib/plugins/translation/translate.js +69 -64
- package/dist-lib/plugins/walkie-talkie/index.d.ts +4 -2
- package/dist-lib/plugins/walkie-talkie/index.js +19 -6
- package/dist-lib/plugins/walkie-talkie/wire.d.ts +5 -0
- package/dist-lib/plugins/walkie-talkie/wire.js +6 -5
- package/dist-lib/plugins/weather/geocode.js +2 -1
- package/dist-lib/plugins/weather/lookup.js +6 -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/generate.js +8 -1
- package/dist-lib/schema/harness.js +91 -12
- package/dist-lib/spec/bind.js +12 -0
- package/dist-lib/spec/calls.js +4 -0
- package/dist-lib/spec/hrpc/hrpc.json +55 -3
- package/dist-lib/spec/hrpc/index.js +58 -10
- package/dist-lib/spec/hrpc/messages.js +461 -209
- package/dist-lib/spec/hyperschema/index.js +461 -209
- package/dist-lib/spec/hyperschema/schema.json +285 -85
- package/dist-lib/spec/hyperschema/types.d.ts +41 -5
- package/package.json +264 -64
- package/patches/pyodide@314.0.2.patch +37 -8
- package/scripts/addon-externals.cjs +16 -5
- package/worker/harness-sidecar.mjs +23 -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
- package/patches/localwatch@1.4.3.patch +0 -13
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isRecord } from '../guards.js';
|
|
2
2
|
export const DEGENERATE_ANSWER_FALLBACK = "I couldn't complete that step and don't have a useful result to share.";
|
|
3
3
|
export const ROUND_CAP_ANSWER = "I ran out of steps before I could finish that. Ask me to continue and I'll pick up where I left off.";
|
|
4
|
+
export const REPEATED_CALL_ANSWER = "I stopped because I kept repeating the same step without getting anywhere. Tell me more about what you want, or put it another way, and I'll try something else.";
|
|
4
5
|
export const SEARCH_CAPPED_ANSWER = "I searched the web but couldn't find the answer in the results I got.";
|
|
5
6
|
export const DELIVERED_ANSWER = 'Your file is attached to the chat.';
|
|
6
7
|
export const WRITE_RESULT_LEAD = "Here's what came back:";
|
|
@@ -66,7 +67,7 @@ export function failureFromToolExecution(result, outcome) {
|
|
|
66
67
|
return resultFailure(result);
|
|
67
68
|
}
|
|
68
69
|
export function degenerateAnswer(outcome, history, facts) {
|
|
69
|
-
const rest = facts.latestFailure ?? cappedAnswer(outcome, history);
|
|
70
|
+
const rest = facts.latestFailure ?? cappedAnswer(outcome, history, facts.repeated === true);
|
|
70
71
|
const lines = [
|
|
71
72
|
writeReport(facts.confirmedWrites),
|
|
72
73
|
facts.delivered ? DELIVERED_ANSWER : null,
|
|
@@ -74,7 +75,10 @@ export function degenerateAnswer(outcome, history, facts) {
|
|
|
74
75
|
].filter((line) => line !== null);
|
|
75
76
|
return lines.length ? lines.join('\n\n') : DEGENERATE_ANSWER_FALLBACK;
|
|
76
77
|
}
|
|
77
|
-
function cappedAnswer(outcome, history) {
|
|
78
|
+
function cappedAnswer(outcome, history, repeated) {
|
|
79
|
+
if (outcome === 'exhausted' && repeated) {
|
|
80
|
+
return REPEATED_CALL_ANSWER;
|
|
81
|
+
}
|
|
78
82
|
if (outcome === 'search-capped') {
|
|
79
83
|
return searchCappedAnswer(history);
|
|
80
84
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare const HOMEBREW_BIN_DIRS: readonly string[];
|
|
2
2
|
export declare function withHomebrewPath(path: string | undefined, platformName: string): string | undefined;
|
|
3
3
|
export declare const EXEC_ENV_ALLOWLIST: readonly ['PATH', 'HOME', 'TMPDIR', 'TMP', 'TEMP', 'LANG', 'LC_ALL', 'LC_CTYPE', 'TZ', 'USER', 'LOGNAME', 'HTTP_PROXY', 'http_proxy', 'HTTPS_PROXY', 'https_proxy', 'ALL_PROXY', 'all_proxy', 'NO_PROXY', 'no_proxy', 'SSL_CERT_FILE', 'SSL_CERT_DIR', 'CURL_CA_BUNDLE', 'REQUESTS_CA_BUNDLE', 'NODE_EXTRA_CA_CERTS'];
|
|
4
|
+
export declare const EXEC_ENV_DEFAULTS: Readonly<Record<string, string>>;
|
|
4
5
|
export declare function execEnv(env: Readonly<Record<string, string | undefined>>, platformName: string): Record<string, string>;
|
|
5
6
|
export declare function spawnEnv(env: Readonly<Record<string, string | undefined>>, platformName: string, overrides?: Readonly<Record<string, string>>): Record<string, string>;
|
|
@@ -40,8 +40,9 @@ const PLATFORM_EXEC_ENV_ALLOWLIST = {
|
|
|
40
40
|
win32: ['SystemRoot', 'COMSPEC', 'PATHEXT', 'USERPROFILE'],
|
|
41
41
|
linux: ['DISPLAY', 'WAYLAND_DISPLAY', 'XDG_RUNTIME_DIR']
|
|
42
42
|
};
|
|
43
|
+
export const EXEC_ENV_DEFAULTS = { PYTHONUNBUFFERED: '1' };
|
|
43
44
|
export function execEnv(env, platformName) {
|
|
44
|
-
const out = {};
|
|
45
|
+
const out = { ...EXEC_ENV_DEFAULTS };
|
|
45
46
|
const keys = [...EXEC_ENV_ALLOWLIST, ...(PLATFORM_EXEC_ENV_ALLOWLIST[platformName] ?? [])];
|
|
46
47
|
for (const key of keys) {
|
|
47
48
|
const value = env[key];
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type TextEvent = {
|
|
2
2
|
type: 'thinking' | 'content';
|
|
3
3
|
text: string;
|
|
4
|
-
}
|
|
4
|
+
};
|
|
5
5
|
export interface SplitThinkingOptions {
|
|
6
6
|
startInThink?: boolean;
|
|
7
7
|
}
|
|
8
|
+
export declare function tapThinking(tokens: AsyncIterable<string>, opts: SplitThinkingOptions, onThinking: () => void): AsyncGenerator<string>;
|
|
8
9
|
export declare function splitThinking(tokens: AsyncIterable<string>, opts?: SplitThinkingOptions): AsyncGenerator<TextEvent, string | null>;
|
|
@@ -24,6 +24,25 @@ function nextTag(buffer, inThink) {
|
|
|
24
24
|
}
|
|
25
25
|
return open && { ...open, inThink: true };
|
|
26
26
|
}
|
|
27
|
+
export async function* tapThinking(tokens, opts, onThinking) {
|
|
28
|
+
let inThink = opts.startInThink === true;
|
|
29
|
+
let tail = '';
|
|
30
|
+
for await (const token of tokens) {
|
|
31
|
+
const wasThinking = inThink;
|
|
32
|
+
tail += token;
|
|
33
|
+
let tag = firstMarker(tail, inThink ? CLOSE_TAGS : OPEN_TAGS);
|
|
34
|
+
while (tag) {
|
|
35
|
+
tail = tail.slice(tag.index + tag.marker.length);
|
|
36
|
+
inThink = !inThink;
|
|
37
|
+
tag = firstMarker(tail, inThink ? CLOSE_TAGS : OPEN_TAGS);
|
|
38
|
+
}
|
|
39
|
+
tail = tail.slice(tail.length - holdback(tail, inThink ? CLOSE_TAGS : OPEN_TAGS));
|
|
40
|
+
if (wasThinking && inThink) {
|
|
41
|
+
onThinking();
|
|
42
|
+
}
|
|
43
|
+
yield token;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
27
46
|
export async function* splitThinking(tokens, opts) {
|
|
28
47
|
let buffer = '';
|
|
29
48
|
let inThink = opts?.startInThink === true;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsonrepair } from 'jsonrepair';
|
|
2
2
|
import { isRecord } from '../../guards.js';
|
|
3
|
-
import {
|
|
3
|
+
import { HarnessLog } from '../../log.js';
|
|
4
4
|
import { escapeLiteralDollars } from '../../tools/exec/scope.js';
|
|
5
5
|
const JSON_NUMBER = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/;
|
|
6
6
|
export class ArgRepairHook {
|
|
@@ -57,7 +57,11 @@ function coerceString(value, schema, site) {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
if (structured || scalarOnly) {
|
|
60
|
-
|
|
60
|
+
HarnessLog.debug('arg repair declined', {
|
|
61
|
+
tool: site.tool,
|
|
62
|
+
param: site.path,
|
|
63
|
+
length: value.length
|
|
64
|
+
});
|
|
61
65
|
}
|
|
62
66
|
return value;
|
|
63
67
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { HarnessHook, HookContext, HookResult, PolicyRule } from '../../contract/index.ts';
|
|
2
|
+
export declare class PolicyRulesHook implements HarnessHook {
|
|
3
|
+
readonly name = "policy-rules";
|
|
4
|
+
readonly phase: 'preToolCall';
|
|
5
|
+
readonly rules: readonly PolicyRule[];
|
|
6
|
+
constructor(rules: readonly PolicyRule[]);
|
|
7
|
+
run(ctx: HookContext): HookResult;
|
|
8
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { Policy } from '../../policy/index.js';
|
|
3
|
+
import { detachJson } from '../../helpers/detach-json.js';
|
|
4
|
+
import { compileGlob } from '../../tools/fs/glob.js';
|
|
5
|
+
import { ShellLine } from '../../tools/exec/shell-line.js';
|
|
6
|
+
const FD_DUP = /^(\d+|-)$/;
|
|
7
|
+
export class PolicyRulesHook {
|
|
8
|
+
name = 'policy-rules';
|
|
9
|
+
phase = 'preToolCall';
|
|
10
|
+
rules;
|
|
11
|
+
constructor(rules) {
|
|
12
|
+
this.rules = detachJson(rules);
|
|
13
|
+
}
|
|
14
|
+
run(ctx) {
|
|
15
|
+
if (ctx.phase !== 'preToolCall')
|
|
16
|
+
return;
|
|
17
|
+
const rules = this.rules.filter((rule) => applies(rule, ctx));
|
|
18
|
+
if (rules.length === 0) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const fold = new Fold();
|
|
22
|
+
for (const rule of rules.filter((each) => !each.command)) {
|
|
23
|
+
fold.add(rule, callVerdict(rule, ctx));
|
|
24
|
+
}
|
|
25
|
+
const commandRules = rules.filter((each) => each.command);
|
|
26
|
+
const text = commandRules.length ? (ctx.command?.(ctx.args) ?? null) : null;
|
|
27
|
+
if (text !== null) {
|
|
28
|
+
fold.line(ShellLine.parse(text), commandRules);
|
|
29
|
+
}
|
|
30
|
+
return fold.result();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
class Fold {
|
|
34
|
+
denied = null;
|
|
35
|
+
asked = false;
|
|
36
|
+
unknown = false;
|
|
37
|
+
allowed = false;
|
|
38
|
+
add(rule, verdict) {
|
|
39
|
+
if (verdict === 'unknown') {
|
|
40
|
+
this.unknown = true;
|
|
41
|
+
}
|
|
42
|
+
else if (verdict === 'match') {
|
|
43
|
+
this.#matched(rule);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
line(line, rules) {
|
|
47
|
+
this.unknown ||= line.unjudgeable !== null;
|
|
48
|
+
let every = line.commands.length > 0;
|
|
49
|
+
for (const part of line.commands) {
|
|
50
|
+
let allowed = false;
|
|
51
|
+
for (const rule of rules) {
|
|
52
|
+
const verdict = commandVerdict(rule, part);
|
|
53
|
+
if (rule.decision === 'allow' && verdict === 'match') {
|
|
54
|
+
allowed = true;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
this.add(rule, verdict);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
every &&= allowed;
|
|
61
|
+
}
|
|
62
|
+
this.allowed ||= every;
|
|
63
|
+
}
|
|
64
|
+
result() {
|
|
65
|
+
if (this.denied) {
|
|
66
|
+
return { permission: 'deny', reason: `a policy rule denies this call: ${label(this.denied)}` };
|
|
67
|
+
}
|
|
68
|
+
if (this.unknown || this.asked) {
|
|
69
|
+
return { permission: 'ask' };
|
|
70
|
+
}
|
|
71
|
+
return this.allowed ? { permission: 'allow' } : undefined;
|
|
72
|
+
}
|
|
73
|
+
#matched(rule) {
|
|
74
|
+
if (rule.decision === 'deny') {
|
|
75
|
+
this.denied ??= rule;
|
|
76
|
+
}
|
|
77
|
+
else if (rule.decision === 'ask') {
|
|
78
|
+
this.asked = true;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
this.allowed = true;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function applies(rule, ctx) {
|
|
86
|
+
const named = rule.tool === undefined || rule.tool === ctx.toolName;
|
|
87
|
+
const read = rule.command ? ctx.command : !rule.paths || ctx.paths;
|
|
88
|
+
return named && Boolean(read) && (!rule.hosts || ctx.egress !== undefined);
|
|
89
|
+
}
|
|
90
|
+
function callVerdict(rule, ctx) {
|
|
91
|
+
const verdicts = [];
|
|
92
|
+
if (rule.paths) {
|
|
93
|
+
const globs = rule.paths.map(pathGlob);
|
|
94
|
+
const paths = ctx.paths?.(ctx.args) ?? [];
|
|
95
|
+
verdicts.push(over(rule, paths.map((each) => pathVerdict(each, globs))));
|
|
96
|
+
}
|
|
97
|
+
if (rule.hosts) {
|
|
98
|
+
const { hosts } = rule;
|
|
99
|
+
const targets = ctx.egress?.(ctx.args) ?? [];
|
|
100
|
+
const urls = typeof targets === 'string' ? [targets] : targets;
|
|
101
|
+
verdicts.push(over(rule, urls.map((url) => hostVerdict(url, hosts))));
|
|
102
|
+
}
|
|
103
|
+
return every(verdicts);
|
|
104
|
+
}
|
|
105
|
+
function commandVerdict(rule, part) {
|
|
106
|
+
const prefix = rule.command ?? [];
|
|
107
|
+
const { argv, expands } = part;
|
|
108
|
+
if (expands[0]) {
|
|
109
|
+
return 'unknown';
|
|
110
|
+
}
|
|
111
|
+
const named = rule.decision === 'allow'
|
|
112
|
+
? argv[0] === prefix[0]
|
|
113
|
+
: program(argv[0] ?? '') === program(prefix[0] ?? '');
|
|
114
|
+
if (!named) {
|
|
115
|
+
return 'no';
|
|
116
|
+
}
|
|
117
|
+
const expanding = prefix.findIndex((_word, i) => expands[i]);
|
|
118
|
+
const differs = prefix.findIndex((word, i) => i > 0 && argv[i] !== word);
|
|
119
|
+
if (expanding !== -1 && (differs === -1 || expanding <= differs)) {
|
|
120
|
+
return 'unknown';
|
|
121
|
+
}
|
|
122
|
+
if (differs !== -1) {
|
|
123
|
+
return 'no';
|
|
124
|
+
}
|
|
125
|
+
if (rule.decision === 'allow' && (part.assignments.length || part.redirects.some(writesFile))) {
|
|
126
|
+
return 'no';
|
|
127
|
+
}
|
|
128
|
+
return rule.paths ? over(rule, wordVerdicts(part, prefix.length, rule.paths)) : 'match';
|
|
129
|
+
}
|
|
130
|
+
function wordVerdicts({ argv, expands }, from, patterns) {
|
|
131
|
+
const globs = patterns.map(pathGlob);
|
|
132
|
+
return argv.slice(from).flatMap((word, i) => {
|
|
133
|
+
const option = word.startsWith('--') && word.includes('=');
|
|
134
|
+
if (word.startsWith('-') && !option) {
|
|
135
|
+
return [];
|
|
136
|
+
}
|
|
137
|
+
const value = option ? word.slice(word.indexOf('=') + 1) : word;
|
|
138
|
+
return [expands[from + i] ? 'unknown' : pathVerdict(value, globs)];
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
function pathGlob(pattern) {
|
|
142
|
+
return compileGlob(path.posix.normalize(pattern));
|
|
143
|
+
}
|
|
144
|
+
function pathVerdict(word, globs) {
|
|
145
|
+
if (word.split(/[/\\]/).includes('..')) {
|
|
146
|
+
return 'unknown';
|
|
147
|
+
}
|
|
148
|
+
const normal = path.posix.normalize(word);
|
|
149
|
+
return globs.some((glob) => glob(normal)) ? 'match' : 'no';
|
|
150
|
+
}
|
|
151
|
+
function hostVerdict(target, hosts) {
|
|
152
|
+
let host;
|
|
153
|
+
try {
|
|
154
|
+
host = new URL(target).hostname;
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
return 'unknown';
|
|
158
|
+
}
|
|
159
|
+
return Policy.allowsHost(hosts, host) ? 'match' : 'no';
|
|
160
|
+
}
|
|
161
|
+
function over(rule, verdicts) {
|
|
162
|
+
if (rule.decision !== 'allow') {
|
|
163
|
+
return some(verdicts);
|
|
164
|
+
}
|
|
165
|
+
return verdicts.length ? every(verdicts) : 'no';
|
|
166
|
+
}
|
|
167
|
+
function every(verdicts) {
|
|
168
|
+
if (verdicts.includes('no')) {
|
|
169
|
+
return 'no';
|
|
170
|
+
}
|
|
171
|
+
return verdicts.includes('unknown') ? 'unknown' : 'match';
|
|
172
|
+
}
|
|
173
|
+
function some(verdicts) {
|
|
174
|
+
if (verdicts.includes('match')) {
|
|
175
|
+
return 'match';
|
|
176
|
+
}
|
|
177
|
+
return verdicts.includes('unknown') ? 'unknown' : 'no';
|
|
178
|
+
}
|
|
179
|
+
function program(word) {
|
|
180
|
+
return word
|
|
181
|
+
.replace(/^.*[/\\]/, '')
|
|
182
|
+
.replace(/\.exe$/i, '')
|
|
183
|
+
.toLowerCase();
|
|
184
|
+
}
|
|
185
|
+
function writesFile({ op, target }) {
|
|
186
|
+
return !((op === '>&' || op === '<&') && FD_DUP.test(target));
|
|
187
|
+
}
|
|
188
|
+
function label(rule) {
|
|
189
|
+
return [rule.tool, rule.command?.join(' '), rule.paths?.join(', '), rule.hosts?.join(', ')]
|
|
190
|
+
.filter(Boolean)
|
|
191
|
+
.join(' ');
|
|
192
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { bareBin
|
|
1
|
+
import { bareBin } from '../../tools/exec/scope.js';
|
|
2
|
+
import { ShellLine } from '../../tools/exec/shell-line.js';
|
|
2
3
|
const NETWORK_BINS = new Set([
|
|
3
4
|
'curl',
|
|
4
5
|
'wget',
|
|
@@ -31,15 +32,32 @@ export class SandboxHook {
|
|
|
31
32
|
run(ctx) {
|
|
32
33
|
if (ctx.phase !== 'preToolCall')
|
|
33
34
|
return;
|
|
34
|
-
if (
|
|
35
|
+
if (ctx.network !== 'off' || ctx.toolName !== 'exec')
|
|
35
36
|
return;
|
|
36
|
-
const
|
|
37
|
-
if (
|
|
37
|
+
const line = ShellLine.parse(String(ctx.args.command ?? ''));
|
|
38
|
+
if (line.constructs.some((each) => each.kind === 'eval')) {
|
|
38
39
|
return {
|
|
39
40
|
kind: 'hook-rejection',
|
|
40
|
-
error:
|
|
41
|
+
error: 'the network is off: eval, ., source, trap or a builtin given $ or ` runs code that may reach it',
|
|
41
42
|
guidance: true
|
|
42
43
|
};
|
|
43
44
|
}
|
|
45
|
+
for (const { argv, expands } of line.commands) {
|
|
46
|
+
if (expands[0]) {
|
|
47
|
+
return {
|
|
48
|
+
kind: 'hook-rejection',
|
|
49
|
+
error: `the network is off: ${argv[0]} names a program only once the shell expands it`,
|
|
50
|
+
guidance: true
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
const bin = bareBin((argv[0] ?? '').replace(/^.*[/\\]/, ''));
|
|
54
|
+
if (bin && NETWORK_BINS.has(bin)) {
|
|
55
|
+
return {
|
|
56
|
+
kind: 'hook-rejection',
|
|
57
|
+
error: `the network is off: ${bin} reaches the network`,
|
|
58
|
+
guidance: true
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
44
62
|
}
|
|
45
63
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { ToolExecutionOutcome } from '../contract/index.ts';
|
|
2
|
-
import type { HarnessHook, HookRejection, HookPhase, PostToolCallPayload, PreFoldPayload, PreToolCallPayload, PromptSubmitPayload, RunEndPayload, RunLifecyclePayload, RunStartPayload, StopPayload, ToolFailurePayload } from '../contract/index.ts';
|
|
2
|
+
import type { HarnessHook, HookRejection, HookPhase, PolicyRule, PostToolCallPayload, PreFoldPayload, PreToolCallPayload, PromptSubmitPayload, RunEndPayload, RunLifecyclePayload, RunStartPayload, StopPayload, ToolFailurePayload } from '../contract/index.ts';
|
|
3
3
|
import { ArgRepairHook } from './built-in/arg-repair.ts';
|
|
4
4
|
import { EgressGuardHook } from './built-in/egress.ts';
|
|
5
|
+
import { PolicyRulesHook } from './built-in/policy-rules.ts';
|
|
5
6
|
import { SandboxHook } from './built-in/sandbox.ts';
|
|
6
7
|
import { SkillCatalogGuardHook } from './built-in/skill-catalog.ts';
|
|
7
8
|
export type PreToolFold = {
|
|
@@ -28,12 +29,14 @@ declare function snapshotHooks(hooks: readonly HarnessHook[]): readonly HarnessH
|
|
|
28
29
|
export declare class HookPipeline {
|
|
29
30
|
static ArgRepairHook: typeof ArgRepairHook;
|
|
30
31
|
static EgressGuardHook: typeof EgressGuardHook;
|
|
32
|
+
static PolicyRulesHook: typeof PolicyRulesHook;
|
|
31
33
|
static SandboxHook: typeof SandboxHook;
|
|
32
34
|
static SkillCatalogGuardHook: typeof SkillCatalogGuardHook;
|
|
33
35
|
static snapshot: typeof snapshotHooks;
|
|
34
36
|
static defaults(): HarnessHook[];
|
|
35
37
|
readonly hooks: readonly HarnessHook[];
|
|
36
38
|
constructor(hooks?: readonly HarnessHook[]);
|
|
39
|
+
withRules(rules: readonly PolicyRule[]): HookPipeline;
|
|
37
40
|
hasPhase(phase: HookPhase): boolean;
|
|
38
41
|
onRunLifecycle(payload: RunLifecyclePayload): Promise<void>;
|
|
39
42
|
onRunStart(payload: Omit<RunStartPayload, 'phase'>): Promise<void>;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HarnessLog } from '../log.js';
|
|
2
2
|
import { normalizeToolExecutionOutcome } from '../helpers/run-outcome.js';
|
|
3
3
|
import { runHooks } from './run.js';
|
|
4
4
|
import { ArgRepairHook } from './built-in/arg-repair.js';
|
|
5
5
|
import { EgressGuardHook } from './built-in/egress.js';
|
|
6
|
+
import { PolicyRulesHook } from './built-in/policy-rules.js';
|
|
6
7
|
import { SandboxHook } from './built-in/sandbox.js';
|
|
7
8
|
import { SkillCatalogGuardHook } from './built-in/skill-catalog.js';
|
|
8
9
|
const TOOL_PHASES = ['preToolCall', 'postToolCall', 'toolFailure'];
|
|
@@ -37,7 +38,7 @@ function snapshotHooks(hooks) {
|
|
|
37
38
|
async function advise(hooks, payload) {
|
|
38
39
|
const folded = await runHooks(hooks, payload, matches);
|
|
39
40
|
if ('guidance' in folded) {
|
|
40
|
-
|
|
41
|
+
HarnessLog.warn('run hook failed', { stage: payload.phase, error: folded.error });
|
|
41
42
|
return undefined;
|
|
42
43
|
}
|
|
43
44
|
return folded;
|
|
@@ -45,6 +46,7 @@ async function advise(hooks, payload) {
|
|
|
45
46
|
export class HookPipeline {
|
|
46
47
|
static ArgRepairHook = ArgRepairHook;
|
|
47
48
|
static EgressGuardHook = EgressGuardHook;
|
|
49
|
+
static PolicyRulesHook = PolicyRulesHook;
|
|
48
50
|
static SandboxHook = SandboxHook;
|
|
49
51
|
static SkillCatalogGuardHook = SkillCatalogGuardHook;
|
|
50
52
|
static snapshot = snapshotHooks;
|
|
@@ -60,6 +62,9 @@ export class HookPipeline {
|
|
|
60
62
|
constructor(hooks = []) {
|
|
61
63
|
this.hooks = snapshotHooks(hooks);
|
|
62
64
|
}
|
|
65
|
+
withRules(rules) {
|
|
66
|
+
return new HookPipeline([...this.hooks, new PolicyRulesHook(rules)]);
|
|
67
|
+
}
|
|
63
68
|
hasPhase(phase) {
|
|
64
69
|
return this.hooks.some((hook) => hook.phase === phase);
|
|
65
70
|
}
|
|
@@ -75,7 +80,7 @@ export class HookPipeline {
|
|
|
75
80
|
async promptSubmit(payload) {
|
|
76
81
|
const folded = await runHooks(this.hooks, { phase: 'promptSubmit', ...payload }, matches);
|
|
77
82
|
if ('guidance' in folded) {
|
|
78
|
-
|
|
83
|
+
HarnessLog.info('prompt rejected by hook', { mode: payload.mode, hook: folded.hook });
|
|
79
84
|
return { ok: false, rejection: folded };
|
|
80
85
|
}
|
|
81
86
|
return folded.context === undefined ? { ok: true } : { ok: true, context: folded.context };
|
|
@@ -95,7 +100,7 @@ export class HookPipeline {
|
|
|
95
100
|
async runPreToolFold(payload) {
|
|
96
101
|
const folded = await runHooks(this.hooks, { phase: 'preToolCall', ...payload }, matches);
|
|
97
102
|
if ('guidance' in folded) {
|
|
98
|
-
|
|
103
|
+
HarnessLog.info('tool rejected: pre-hook refused the call', {
|
|
99
104
|
tool: payload.toolName,
|
|
100
105
|
hook: folded.hook,
|
|
101
106
|
phase: folded.phase
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AbortController } from 'bare-abort-controller';
|
|
2
2
|
import { errorMessage, isRecord } from '../guards.js';
|
|
3
3
|
import { HookHalt } from '../helpers/engine-error.js';
|
|
4
|
-
import {
|
|
4
|
+
import { HarnessLog } from '../log.js';
|
|
5
5
|
function cloneJson(value) {
|
|
6
6
|
try {
|
|
7
7
|
const text = JSON.stringify(value);
|
|
@@ -83,7 +83,7 @@ function merge(fold, returned) {
|
|
|
83
83
|
}
|
|
84
84
|
function rejectionOf(current, err, hook) {
|
|
85
85
|
const message = errorMessage(err);
|
|
86
|
-
|
|
86
|
+
HarnessLog.warn('hook failed', { stage: current.phase, hook, error: message });
|
|
87
87
|
if (current.phase === 'postToolCall') {
|
|
88
88
|
return rejection(`tool executed; output withheld: post-hook failed: ${message}. Do not retry this call.`, hook, current.phase);
|
|
89
89
|
}
|
|
@@ -148,7 +148,7 @@ export async function runHooks(hooks, ctx, match) {
|
|
|
148
148
|
}
|
|
149
149
|
const halt = HALTS.includes(ctx.phase) ? text(returned, 'halt') : undefined;
|
|
150
150
|
if (halt !== undefined) {
|
|
151
|
-
|
|
151
|
+
HarnessLog.info('hook halted the run', { stage: ctx.phase, hook: hookId });
|
|
152
152
|
throw new HookHalt(halt, hookId);
|
|
153
153
|
}
|
|
154
154
|
if (isRejection(returned)) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { HarnessError } from '../errors.js';
|
|
1
2
|
import { errorMessage } from '../guards.js';
|
|
2
|
-
import {
|
|
3
|
+
import { HarnessLog } from '../log.js';
|
|
3
4
|
import { ModelUnloadError } from '../models/model-pool.js';
|
|
4
5
|
import { trackCompletion } from './completion-run.js';
|
|
5
6
|
import { createHarnessLifecycle } from './machine.js';
|
|
@@ -82,13 +83,13 @@ export class Lifecycle {
|
|
|
82
83
|
}
|
|
83
84
|
assertNotClosing() {
|
|
84
85
|
if (this._closeRequested || this._resource.closing || this._resource.closed) {
|
|
85
|
-
throw new
|
|
86
|
+
throw new HarnessError('HARNESS_CLOSING');
|
|
86
87
|
}
|
|
87
88
|
}
|
|
88
89
|
enterWork() {
|
|
89
90
|
this.assertNotClosing();
|
|
90
91
|
if (this._runtimeDraining) {
|
|
91
|
-
throw new
|
|
92
|
+
throw new HarnessError('HARNESS_SUSPENDED');
|
|
92
93
|
}
|
|
93
94
|
if (this._runtimeUnloadFailed) {
|
|
94
95
|
throw new Error('Runtime unload failed; close the harness before loading models again');
|
|
@@ -119,7 +120,7 @@ export class Lifecycle {
|
|
|
119
120
|
}
|
|
120
121
|
trackDetachedRun(pending, runId) {
|
|
121
122
|
const tracked = pending.catch((error) => {
|
|
122
|
-
|
|
123
|
+
HarnessLog.info('detached completion effect failed', { runId, err: errorMessage(error) });
|
|
123
124
|
});
|
|
124
125
|
this._detachedRuns.add(tracked);
|
|
125
126
|
void tracked
|
|
@@ -133,7 +134,7 @@ export class Lifecycle {
|
|
|
133
134
|
this._failedModelUnloads.add(modelId);
|
|
134
135
|
this._poolUnloadFailed = true;
|
|
135
136
|
this._runtimeUnloadFailed = true;
|
|
136
|
-
|
|
137
|
+
HarnessLog.info('model unload failed', { modelId, err: errorMessage(error) });
|
|
137
138
|
}
|
|
138
139
|
recordPoolCleanupFailure() {
|
|
139
140
|
this._poolCleanupFailed = true;
|
|
@@ -179,7 +180,7 @@ export class Lifecycle {
|
|
|
179
180
|
catch (error) {
|
|
180
181
|
sdkCloseFailed = true;
|
|
181
182
|
sdkCloseError = error;
|
|
182
|
-
|
|
183
|
+
HarnessLog.info('sdk close failed', { err: errorMessage(error) });
|
|
183
184
|
}
|
|
184
185
|
}
|
|
185
186
|
if (sdkCloseFailed) {
|
|
@@ -223,7 +224,7 @@ export class Lifecycle {
|
|
|
223
224
|
const closed = await Promise.allSettled([...runs].map((run) => run.close()));
|
|
224
225
|
for (const outcome of closed) {
|
|
225
226
|
if (outcome.status === 'rejected') {
|
|
226
|
-
|
|
227
|
+
HarnessLog.info('completion close failed', {
|
|
227
228
|
err: errorMessage(outcome.reason)
|
|
228
229
|
});
|
|
229
230
|
}
|
|
@@ -231,7 +232,7 @@ export class Lifecycle {
|
|
|
231
232
|
}
|
|
232
233
|
async _suspendRuntimes() {
|
|
233
234
|
this._runtimeDraining = true;
|
|
234
|
-
|
|
235
|
+
HarnessLog.info('suspending', { models: this._models() });
|
|
235
236
|
this.abortCompletions();
|
|
236
237
|
this._loads.drain();
|
|
237
238
|
await this._closeCompletions([...this._completionRuns].filter((run) => run.started));
|
|
@@ -249,7 +250,7 @@ export class Lifecycle {
|
|
|
249
250
|
}
|
|
250
251
|
this._statusChanged();
|
|
251
252
|
await this._sdkLifecycle('suspend');
|
|
252
|
-
|
|
253
|
+
HarnessLog.info('suspended');
|
|
253
254
|
}
|
|
254
255
|
async _sdkLifecycle(op) {
|
|
255
256
|
const sdk = await this._sdk.peek()?.catch(noop);
|
|
@@ -260,12 +261,12 @@ export class Lifecycle {
|
|
|
260
261
|
await sdk[op]();
|
|
261
262
|
}
|
|
262
263
|
catch (err) {
|
|
263
|
-
|
|
264
|
+
HarnessLog.error(`sdk ${op} failed`, { err: errorMessage(err) });
|
|
264
265
|
if (op === 'suspend') {
|
|
265
266
|
throw err;
|
|
266
267
|
}
|
|
267
268
|
await sdk.resume().catch((retryErr) => {
|
|
268
|
-
|
|
269
|
+
HarnessLog.error('sdk resume retry failed', {
|
|
269
270
|
err: errorMessage(retryErr)
|
|
270
271
|
});
|
|
271
272
|
throw retryErr;
|
|
@@ -287,7 +288,7 @@ export class Lifecycle {
|
|
|
287
288
|
for (const outcome of [...pools, ...others]) {
|
|
288
289
|
if (outcome.status !== 'rejected')
|
|
289
290
|
continue;
|
|
290
|
-
|
|
291
|
+
HarnessLog.warn('unload failed', { err: errorMessage(outcome.reason) });
|
|
291
292
|
}
|
|
292
293
|
const sdk = await this._sdk.peek()?.catch(noop);
|
|
293
294
|
if (sdk) {
|
|
@@ -298,7 +299,7 @@ export class Lifecycle {
|
|
|
298
299
|
this._statusChanged();
|
|
299
300
|
}
|
|
300
301
|
catch (error) {
|
|
301
|
-
|
|
302
|
+
HarnessLog.info('model unload retry failed', {
|
|
302
303
|
modelId,
|
|
303
304
|
err: errorMessage(error)
|
|
304
305
|
});
|
|
@@ -315,7 +316,7 @@ export class Lifecycle {
|
|
|
315
316
|
if (this._runtimeUnloadFailed) {
|
|
316
317
|
throw new Error('Runtime unload failed; close the harness before loading models again');
|
|
317
318
|
}
|
|
318
|
-
|
|
319
|
+
HarnessLog.info('resuming', { pools: 'recreated' });
|
|
319
320
|
this._loads.undrain();
|
|
320
321
|
this._recreate();
|
|
321
322
|
try {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { assign, createActor, fromPromise, setup, waitFor } from 'xstate';
|
|
2
2
|
import { errorMessage, isRecord } from '../guards.js';
|
|
3
|
-
import {
|
|
3
|
+
import { HarnessLog } from '../log.js';
|
|
4
4
|
function errorFromEvent(event) {
|
|
5
5
|
return isRecord(event) ? event.error : undefined;
|
|
6
6
|
}
|
|
@@ -19,7 +19,7 @@ export const harnessLifecycle = setup({
|
|
|
19
19
|
hold: assign(({ event }) => ({ pending: requestFromEvent(event) })),
|
|
20
20
|
clear: assign({ pending: null }),
|
|
21
21
|
report: ({ event }) => {
|
|
22
|
-
|
|
22
|
+
HarnessLog.info('lifecycle step failed', { err: errorMessage(errorFromEvent(event)) });
|
|
23
23
|
},
|
|
24
24
|
recordError: assign(({ context, event }) => {
|
|
25
25
|
const message = errorMessage(errorFromEvent(event));
|
package/dist-lib/lib/log.d.ts
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
1
|
+
import { type LogLevel } from '@qvac/logging';
|
|
2
|
+
export type { LogLevel };
|
|
3
|
+
export type LineLevel = Exclude<LogLevel, 'off'>;
|
|
4
|
+
export type Sink = (line: string, level: LineLevel) => void;
|
|
5
|
+
export interface HostLogger {
|
|
6
|
+
info(...args: unknown[]): void;
|
|
7
|
+
warn(...args: unknown[]): void;
|
|
8
|
+
error?(...args: unknown[]): void;
|
|
9
|
+
debug?(...args: unknown[]): void;
|
|
10
|
+
getLevel?(): string;
|
|
11
|
+
}
|
|
12
|
+
export declare class HarnessLog {
|
|
13
|
+
static error(message: string, data?: Record<string, unknown>): void;
|
|
14
|
+
static warn(message: string, data?: Record<string, unknown>): void;
|
|
15
|
+
static info(message: string, data?: Record<string, unknown>): void;
|
|
16
|
+
static debug(message: string, data?: Record<string, unknown>): void;
|
|
17
|
+
static diag(message: string, data?: Record<string, unknown>): void;
|
|
18
|
+
static enable(on: boolean): void;
|
|
19
|
+
static setLevel(level: LogLevel): void;
|
|
20
|
+
static level(): LogLevel;
|
|
21
|
+
static followHost(level: unknown): void;
|
|
22
|
+
static toHost(next: HostLogger | null): void;
|
|
23
|
+
static isLevel(value: unknown): value is LogLevel;
|
|
24
|
+
static enabled(level: LineLevel): boolean;
|
|
25
|
+
static setSink(next: Sink | null): void;
|
|
26
|
+
}
|