@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
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { errorMessage } from '../../guards.js';
|
|
4
|
+
import { defaultRealpath } from '../fs/scope.js';
|
|
5
|
+
import { localPathOf, resolveRooted, rootedArgs, rootedLabel, stringArg } from '../fs/tool-path.js';
|
|
6
|
+
export const TRASH_DIR = '.trash';
|
|
7
|
+
export function createTrashFileTool({ realpath = defaultRealpath, deniedRoots } = {}) {
|
|
8
|
+
return {
|
|
9
|
+
name: 'trash_file',
|
|
10
|
+
toolset: 'files',
|
|
11
|
+
description: `Move a file or folder to the shared folder's ${TRASH_DIR} folder, where the user can restore it. ` +
|
|
12
|
+
'Nothing is deleted permanently. Asks the user first.',
|
|
13
|
+
parameters: {
|
|
14
|
+
type: 'object',
|
|
15
|
+
properties: {
|
|
16
|
+
path: { type: 'string', description: 'Path to trash, relative to the shared folder' }
|
|
17
|
+
},
|
|
18
|
+
required: ['path']
|
|
19
|
+
},
|
|
20
|
+
effect: () => 'write',
|
|
21
|
+
autoApprove: false,
|
|
22
|
+
writeRootsRequired: true,
|
|
23
|
+
validate: (args) => (stringArg(args, 'path') ? null : 'path is required'),
|
|
24
|
+
paths: (args, ctx) => rootedArgs(args, ctx, ['path']),
|
|
25
|
+
resource: (args, ctx) => ({
|
|
26
|
+
kind: 'file',
|
|
27
|
+
label: rootedLabel('trash', { grants: ctx, paths: [String(args.path)] })
|
|
28
|
+
}),
|
|
29
|
+
async execute(args, ctx) {
|
|
30
|
+
const requested = String(args.path);
|
|
31
|
+
const resolved = await resolveRooted(requested, {
|
|
32
|
+
grants: ctx,
|
|
33
|
+
write: true,
|
|
34
|
+
realpath,
|
|
35
|
+
deniedRoots
|
|
36
|
+
});
|
|
37
|
+
if ('error' in resolved) {
|
|
38
|
+
return resolved;
|
|
39
|
+
}
|
|
40
|
+
const source = localPathOf(resolved);
|
|
41
|
+
if (!source || resolved.root.kind !== 'local') {
|
|
42
|
+
return { error: 'trash works only in a folder on this device' };
|
|
43
|
+
}
|
|
44
|
+
if (resolved.key === '/') {
|
|
45
|
+
return { error: 'the shared folder itself cannot be trashed' };
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
if (!fs.existsSync(source)) {
|
|
49
|
+
return { error: `no such file: ${requested}` };
|
|
50
|
+
}
|
|
51
|
+
const bin = path.join(resolved.root.root, TRASH_DIR);
|
|
52
|
+
const name = `${Date.now().toString(36)}-${path.basename(source)}`;
|
|
53
|
+
await fs.promises.mkdir(bin, { recursive: true });
|
|
54
|
+
await fs.promises.rename(source, path.join(bin, name));
|
|
55
|
+
return { trashed: requested, restorableAt: `${TRASH_DIR}/${name}` };
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
return { error: errorMessage(err) };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { errorMessage } from '../../guards.js';
|
|
2
|
+
import { defaultRealpath } from '../fs/scope.js';
|
|
3
|
+
import { existsNow, resolveRooted, rootedArgs, rootedLabel, stringArg } from '../fs/tool-path.js';
|
|
4
|
+
import { writeText } from '../fs/write.js';
|
|
5
|
+
export function createWriteFileTool({ realpath = defaultRealpath, deniedRoots } = {}) {
|
|
6
|
+
return {
|
|
7
|
+
name: 'write_file',
|
|
8
|
+
toolset: 'files',
|
|
9
|
+
description: 'Write a whole file in the shared folder: creates it (and its folders) or replaces it completely. ' +
|
|
10
|
+
'Replacing an existing file asks the user first. For a small change, use edit_file. ' +
|
|
11
|
+
'Use this, not exec, to write files in the shared folder.',
|
|
12
|
+
parameters: {
|
|
13
|
+
type: 'object',
|
|
14
|
+
properties: {
|
|
15
|
+
path: { type: 'string', description: 'File path, relative to the shared folder' },
|
|
16
|
+
content: { type: 'string', description: 'The complete new content' }
|
|
17
|
+
},
|
|
18
|
+
required: ['path', 'content']
|
|
19
|
+
},
|
|
20
|
+
effect: (args, ctx) => (existsNow(stringArg(args, 'path'), ctx) ? 'write' : 'read'),
|
|
21
|
+
writeRootsRequired: true,
|
|
22
|
+
paths: (args, ctx) => rootedArgs(args, ctx, ['path']),
|
|
23
|
+
validate: (args) => stringArg(args, 'path') && typeof args.content === 'string'
|
|
24
|
+
? null
|
|
25
|
+
: 'path and content are required',
|
|
26
|
+
resource: (args, ctx) => ({
|
|
27
|
+
kind: 'file',
|
|
28
|
+
label: `${rootedLabel('write', { grants: ctx, paths: [String(args.path)] })}, ${String(args.content ?? '').length} chars`
|
|
29
|
+
}),
|
|
30
|
+
async execute(args, ctx) {
|
|
31
|
+
const requested = String(args.path);
|
|
32
|
+
const resolved = await resolveRooted(requested, {
|
|
33
|
+
grants: ctx,
|
|
34
|
+
write: true,
|
|
35
|
+
realpath,
|
|
36
|
+
deniedRoots
|
|
37
|
+
});
|
|
38
|
+
if ('error' in resolved) {
|
|
39
|
+
return resolved;
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const existing = await resolved.root.drive.entry(resolved.key);
|
|
43
|
+
if (existing !== null && ctx?.approval === 'auto') {
|
|
44
|
+
return { error: `${requested} already exists; call write_file again to replace it` };
|
|
45
|
+
}
|
|
46
|
+
await writeText(resolved.root.drive, resolved.key, String(args.content), {
|
|
47
|
+
executable: existing?.value.executable
|
|
48
|
+
});
|
|
49
|
+
return { written: requested, replaced: existing !== null };
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
return { error: errorMessage(err) };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { HarnessError } from '../../errors.js';
|
|
2
|
+
import { docx, pptx } from '../../office/engine/index.js';
|
|
3
|
+
let pdfium = null;
|
|
4
|
+
function loadPdfium() {
|
|
5
|
+
pdfium ??= import('bare-pdfium').then((loaded) => loaded, () => null);
|
|
6
|
+
return pdfium;
|
|
7
|
+
}
|
|
8
|
+
export function isDocument(key) {
|
|
9
|
+
return /\.(pdf|docx|pptx)$/i.test(key);
|
|
10
|
+
}
|
|
11
|
+
export async function documentText(key, bytes) {
|
|
12
|
+
if (!/\.pdf$/i.test(key)) {
|
|
13
|
+
const read = /\.docx$/i.test(key) ? docx.open(bytes).read() : pptx.open(bytes).read();
|
|
14
|
+
return collectText(read).join('\n');
|
|
15
|
+
}
|
|
16
|
+
const lib = await loadPdfium();
|
|
17
|
+
if (!lib) {
|
|
18
|
+
throw new HarnessError('PDF_TEXT_UNAVAILABLE');
|
|
19
|
+
}
|
|
20
|
+
const doc = lib.open(bytes);
|
|
21
|
+
try {
|
|
22
|
+
return [...doc.textPages()]
|
|
23
|
+
.map(({ page, text }) => `--- page ${page + 1} ---\n${text.replace(/\r\n?/g, '\n').trim()}`)
|
|
24
|
+
.join('\n');
|
|
25
|
+
}
|
|
26
|
+
finally {
|
|
27
|
+
doc.close();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function collectText(value) {
|
|
31
|
+
if (Array.isArray(value)) {
|
|
32
|
+
return value.flatMap(collectText);
|
|
33
|
+
}
|
|
34
|
+
if (typeof value !== 'object' || value === null) {
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
return Object.entries(value).flatMap(([key, inner]) => key === 'text' && typeof inner === 'string' ? [inner] : collectText(inner));
|
|
38
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Writable } from 'streamx';
|
|
2
|
+
import { HarnessError } from '../../errors.ts';
|
|
2
3
|
export interface DriveEntry {
|
|
3
4
|
key: string;
|
|
4
5
|
value: {
|
|
@@ -11,16 +12,26 @@ export interface DriveEntry {
|
|
|
11
12
|
};
|
|
12
13
|
mtime?: number;
|
|
13
14
|
}
|
|
15
|
+
export interface DriveDir {
|
|
16
|
+
key: string;
|
|
17
|
+
dir: true;
|
|
18
|
+
}
|
|
19
|
+
export interface DriveListOptions {
|
|
20
|
+
skip?: ReadonlySet<string>;
|
|
21
|
+
recursive?: boolean;
|
|
22
|
+
}
|
|
14
23
|
export interface Drive {
|
|
15
24
|
entry(key: string, opts?: {
|
|
16
25
|
follow?: boolean;
|
|
17
26
|
}): Promise<DriveEntry | null>;
|
|
18
27
|
get(key: string): Promise<Uint8Array | null>;
|
|
19
|
-
list(folder?: string, opts?:
|
|
20
|
-
skip?: ReadonlySet<string>;
|
|
21
|
-
}): AsyncIterable<DriveEntry>;
|
|
28
|
+
list(folder?: string, opts?: DriveListOptions): AsyncIterable<DriveEntry | DriveDir>;
|
|
22
29
|
createReadStream(key: string): AsyncIterable<Uint8Array>;
|
|
23
30
|
createWriteStream(key: string, opts?: {
|
|
24
31
|
executable?: boolean;
|
|
25
32
|
}): Writable;
|
|
26
33
|
}
|
|
34
|
+
export declare class DriveReadTruncatedError extends HarnessError<'DRIVE_READ_TRUNCATED'> {
|
|
35
|
+
constructor(key: string, bytes: number);
|
|
36
|
+
}
|
|
37
|
+
export declare function isDriveReadTruncated(err: unknown): err is DriveReadTruncatedError;
|
|
@@ -1 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { HarnessError } from '../../errors.js';
|
|
2
|
+
export class DriveReadTruncatedError extends HarnessError {
|
|
3
|
+
constructor(key, bytes) {
|
|
4
|
+
super('DRIVE_READ_TRUNCATED', [bytes, key]);
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export function isDriveReadTruncated(err) {
|
|
8
|
+
return err instanceof DriveReadTruncatedError;
|
|
9
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface EditRequest {
|
|
2
|
+
readonly old: string;
|
|
3
|
+
readonly replacement: string;
|
|
4
|
+
readonly replaceAll: boolean;
|
|
5
|
+
}
|
|
6
|
+
export interface EditMatch {
|
|
7
|
+
content: string;
|
|
8
|
+
count: number;
|
|
9
|
+
error: string | null;
|
|
10
|
+
}
|
|
11
|
+
export declare function editMatch(content: string, request: EditRequest): EditMatch;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
const TYPOGRAPHIC = {
|
|
2
|
+
'“': '"',
|
|
3
|
+
'”': '"',
|
|
4
|
+
'‘': "'",
|
|
5
|
+
'’': "'",
|
|
6
|
+
'–': '-',
|
|
7
|
+
'—': '-',
|
|
8
|
+
' ': ' '
|
|
9
|
+
};
|
|
10
|
+
function plain(text) {
|
|
11
|
+
return text.replace(/[“”‘’–— ]/g, (c) => TYPOGRAPHIC[c] ?? c);
|
|
12
|
+
}
|
|
13
|
+
function occurrences(haystack, needle) {
|
|
14
|
+
const found = [];
|
|
15
|
+
let at = haystack.indexOf(needle);
|
|
16
|
+
while (at !== -1) {
|
|
17
|
+
found.push({ from: at, to: at + needle.length });
|
|
18
|
+
at = haystack.indexOf(needle, at + needle.length);
|
|
19
|
+
}
|
|
20
|
+
return found;
|
|
21
|
+
}
|
|
22
|
+
function lineStarts(lines) {
|
|
23
|
+
const starts = [];
|
|
24
|
+
let offset = 0;
|
|
25
|
+
for (const line of lines) {
|
|
26
|
+
starts.push(offset);
|
|
27
|
+
offset += line.length + 1;
|
|
28
|
+
}
|
|
29
|
+
return starts;
|
|
30
|
+
}
|
|
31
|
+
function trimmedLineSpans(content, old) {
|
|
32
|
+
const lines = content.split('\n');
|
|
33
|
+
const wanted = old.split('\n').map((line) => line.trimEnd());
|
|
34
|
+
const ownsNewline = wanted.length > 1 && wanted[wanted.length - 1] === '';
|
|
35
|
+
if (ownsNewline) {
|
|
36
|
+
wanted.pop();
|
|
37
|
+
}
|
|
38
|
+
const starts = lineStarts(lines);
|
|
39
|
+
const spans = [];
|
|
40
|
+
for (let i = 0; i + wanted.length <= lines.length; i++) {
|
|
41
|
+
const block = lines.slice(i, i + wanted.length);
|
|
42
|
+
if (block.every((line, k) => line.trimEnd() === wanted[k])) {
|
|
43
|
+
const last = i + wanted.length - 1;
|
|
44
|
+
const end = starts[last] + lines[last].length;
|
|
45
|
+
spans.push({ from: starts[i], to: ownsNewline && last < lines.length - 1 ? end + 1 : end });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return spans;
|
|
49
|
+
}
|
|
50
|
+
function spansFor(content, old) {
|
|
51
|
+
const exact = occurrences(content, old);
|
|
52
|
+
if (exact.length) {
|
|
53
|
+
return exact;
|
|
54
|
+
}
|
|
55
|
+
const typographic = occurrences(plain(content), plain(old));
|
|
56
|
+
if (typographic.length) {
|
|
57
|
+
return typographic;
|
|
58
|
+
}
|
|
59
|
+
return trimmedLineSpans(plain(content), plain(old));
|
|
60
|
+
}
|
|
61
|
+
function ambiguity(text, spans) {
|
|
62
|
+
const lines = spans.map((span) => text.slice(0, span.from).split('\n').length).join(', ');
|
|
63
|
+
return `old text matches ${spans.length} places (lines ${lines}). Include a neighbouring line so it matches once, or set replaceAll to change every one.`;
|
|
64
|
+
}
|
|
65
|
+
export function editMatch(content, request) {
|
|
66
|
+
const crlf = content.includes('\r\n');
|
|
67
|
+
const text = crlf ? content.replace(/\r\n/g, '\n') : content;
|
|
68
|
+
const spans = spansFor(text, request.old.replace(/\r\n/g, '\n'));
|
|
69
|
+
if (!spans.length) {
|
|
70
|
+
return {
|
|
71
|
+
content,
|
|
72
|
+
count: 0,
|
|
73
|
+
error: 'old text not found. Read the file with read_file and copy the exact lines you want to change, including their indentation.'
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
if (spans.length > 1 && !request.replaceAll) {
|
|
77
|
+
return { content, count: 0, error: ambiguity(text, spans) };
|
|
78
|
+
}
|
|
79
|
+
const replacement = request.replacement.replace(/\r\n/g, '\n');
|
|
80
|
+
let next = text;
|
|
81
|
+
for (const span of [...spans].sort((a, b) => b.from - a.from)) {
|
|
82
|
+
next = next.slice(0, span.from) + replacement + next.slice(span.to);
|
|
83
|
+
}
|
|
84
|
+
return { content: crlf ? next.replace(/\n/g, '\r\n') : next, count: spans.length, error: null };
|
|
85
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
interface Rule {
|
|
2
|
+
base: string;
|
|
3
|
+
regex: RegExp;
|
|
4
|
+
negate: boolean;
|
|
5
|
+
dirOnly: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare class IgnoreRules {
|
|
8
|
+
#private;
|
|
9
|
+
constructor(rules?: readonly Rule[]);
|
|
10
|
+
add(base: string, text: string): IgnoreRules;
|
|
11
|
+
ignored(relPath: string, isDir: boolean): boolean;
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
function escapeRegex(c) {
|
|
2
|
+
return /[.+^${}()|[\]\\*?/-]/.test(c) ? `\\${c}` : c;
|
|
3
|
+
}
|
|
4
|
+
function classAt(glob, start) {
|
|
5
|
+
const negate = glob[start + 1] === '!' || glob[start + 1] === '^';
|
|
6
|
+
const first = negate ? start + 2 : start + 1;
|
|
7
|
+
let body = '';
|
|
8
|
+
for (let i = first; i < glob.length; i++) {
|
|
9
|
+
const c = glob.charAt(i);
|
|
10
|
+
if (c === ']' && i > first) {
|
|
11
|
+
return { source: negate ? `[^/${body}]` : `[${body}]`, end: i };
|
|
12
|
+
}
|
|
13
|
+
const escaped = c === '\\' && i + 1 < glob.length;
|
|
14
|
+
const literal = escaped ? glob.charAt(++i) : c;
|
|
15
|
+
body += literal === '-' && !escaped ? '-' : escapeRegex(literal);
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
function starsAt(glob, i) {
|
|
20
|
+
if (glob[i + 1] !== '*') {
|
|
21
|
+
return { source: '[^/]*', end: i };
|
|
22
|
+
}
|
|
23
|
+
const wholeSegment = (i === 0 || glob[i - 1] === '/') && (i + 2 === glob.length || glob[i + 2] === '/');
|
|
24
|
+
if (!wholeSegment) {
|
|
25
|
+
let end = i + 1;
|
|
26
|
+
while (glob[end + 1] === '*') {
|
|
27
|
+
end++;
|
|
28
|
+
}
|
|
29
|
+
return { source: '[^/]*', end };
|
|
30
|
+
}
|
|
31
|
+
return i + 2 === glob.length
|
|
32
|
+
? { source: '.*', end: i + 1 }
|
|
33
|
+
: { source: '(?:[^/]*/)*', end: i + 2 };
|
|
34
|
+
}
|
|
35
|
+
function pieceAt(glob, i) {
|
|
36
|
+
const c = glob.charAt(i);
|
|
37
|
+
if (c === '\\' && i + 1 < glob.length) {
|
|
38
|
+
return { source: escapeRegex(glob.charAt(i + 1)), end: i + 1 };
|
|
39
|
+
}
|
|
40
|
+
if (c === '*') {
|
|
41
|
+
return starsAt(glob, i);
|
|
42
|
+
}
|
|
43
|
+
if (c === '?') {
|
|
44
|
+
return { source: '[^/]', end: i };
|
|
45
|
+
}
|
|
46
|
+
return (c === '[' && classAt(glob, i)) || { source: escapeRegex(c), end: i };
|
|
47
|
+
}
|
|
48
|
+
function globSource(glob) {
|
|
49
|
+
let source = '';
|
|
50
|
+
for (let i = 0; i < glob.length; i++) {
|
|
51
|
+
const piece = pieceAt(glob, i);
|
|
52
|
+
source += piece.source;
|
|
53
|
+
i = piece.end;
|
|
54
|
+
}
|
|
55
|
+
return source;
|
|
56
|
+
}
|
|
57
|
+
function parseLine(base, raw) {
|
|
58
|
+
const trimmed = raw.replace(/(?<!\\) +$/, '');
|
|
59
|
+
if (trimmed === '' || trimmed.startsWith('#')) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
const negate = trimmed.startsWith('!');
|
|
63
|
+
const body = negate ? trimmed.slice(1) : trimmed;
|
|
64
|
+
const dirOnly = body.endsWith('/');
|
|
65
|
+
const pattern = dirOnly ? body.slice(0, -1) : body;
|
|
66
|
+
if (pattern === '') {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
const anchored = pattern.includes('/');
|
|
70
|
+
const source = globSource(pattern.startsWith('/') ? pattern.slice(1) : pattern);
|
|
71
|
+
try {
|
|
72
|
+
const regex = new RegExp(anchored ? `^${source}$` : `^(?:.*/)?${source}$`);
|
|
73
|
+
return { base, regex, negate, dirOnly };
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function matches(rule, relPath, isDir) {
|
|
80
|
+
if (rule.dirOnly && !isDir) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
if (rule.base === '') {
|
|
84
|
+
return rule.regex.test(relPath);
|
|
85
|
+
}
|
|
86
|
+
return relPath.startsWith(`${rule.base}/`) && rule.regex.test(relPath.slice(rule.base.length + 1));
|
|
87
|
+
}
|
|
88
|
+
export class IgnoreRules {
|
|
89
|
+
#rules;
|
|
90
|
+
constructor(rules = []) {
|
|
91
|
+
this.#rules = rules;
|
|
92
|
+
}
|
|
93
|
+
add(base, text) {
|
|
94
|
+
const added = text
|
|
95
|
+
.split(/\r?\n/)
|
|
96
|
+
.map((line) => parseLine(base, line))
|
|
97
|
+
.filter((rule) => rule !== null);
|
|
98
|
+
return added.length === 0 ? this : new IgnoreRules([...this.#rules, ...added]);
|
|
99
|
+
}
|
|
100
|
+
ignored(relPath, isDir) {
|
|
101
|
+
const rule = this.#rules.findLast((candidate) => matches(candidate, relPath, isDir));
|
|
102
|
+
return rule !== undefined && !rule.negate;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -1,13 +1,36 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
1
2
|
import path from 'path';
|
|
2
3
|
import Localdrive from 'localdrive';
|
|
3
4
|
import { defaultRealpath } from './scope.js';
|
|
4
|
-
function withSkipList(localdrive) {
|
|
5
|
+
function withSkipList(localdrive, root) {
|
|
6
|
+
async function* listShallow(folder, skip) {
|
|
7
|
+
const base = folder === '/' ? '' : folder.replace(/\/+$/, '');
|
|
8
|
+
const dir = await fs.promises.opendir(path.join(root, base)).catch(() => null);
|
|
9
|
+
if (dir === null) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
for await (const dirent of dir) {
|
|
13
|
+
if (skip?.has(dirent.name))
|
|
14
|
+
continue;
|
|
15
|
+
const key = `${base}/${dirent.name}`;
|
|
16
|
+
if (dirent.isDirectory()) {
|
|
17
|
+
yield { key, dir: true };
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
const entry = await localdrive.entry(key);
|
|
21
|
+
if (entry) {
|
|
22
|
+
yield entry;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
5
26
|
return {
|
|
6
27
|
entry: localdrive.entry.bind(localdrive),
|
|
7
28
|
get: localdrive.get.bind(localdrive),
|
|
8
|
-
list: (folder, opts) =>
|
|
9
|
-
|
|
10
|
-
|
|
29
|
+
list: (folder = '/', opts) => opts?.recursive === false
|
|
30
|
+
? listShallow(folder, opts.skip)
|
|
31
|
+
: localdrive.list(folder, {
|
|
32
|
+
ignore: (key) => key.split('/').some((segment) => opts?.skip?.has(segment))
|
|
33
|
+
}),
|
|
11
34
|
createReadStream: localdrive.createReadStream.bind(localdrive),
|
|
12
35
|
createWriteStream: localdrive.createWriteStream.bind(localdrive)
|
|
13
36
|
};
|
|
@@ -23,7 +46,7 @@ export async function createLocalRoots(dirs, realpath = defaultRealpath) {
|
|
|
23
46
|
continue;
|
|
24
47
|
}
|
|
25
48
|
const localdrive = new Localdrive(canonical, { atomic: true });
|
|
26
|
-
roots.push({ kind: 'local', root: canonical, drive: withSkipList(localdrive) });
|
|
49
|
+
roots.push({ kind: 'local', root: canonical, drive: withSkipList(localdrive, canonical) });
|
|
27
50
|
}
|
|
28
51
|
return roots;
|
|
29
52
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { DriveEntry } from './drive.ts';
|
|
1
|
+
import type { DriveDir, DriveEntry } from './drive.ts';
|
|
2
|
+
import type { SearchHit } from './search.ts';
|
|
2
3
|
export interface DriveEntryRequest {
|
|
3
4
|
op: 'entry';
|
|
4
5
|
driveKey: string;
|
|
@@ -19,6 +20,7 @@ export interface DriveListRequest {
|
|
|
19
20
|
driveKey: string;
|
|
20
21
|
folder: string;
|
|
21
22
|
skip: string[];
|
|
23
|
+
recursive: boolean;
|
|
22
24
|
limit: number;
|
|
23
25
|
cursor: string | null;
|
|
24
26
|
}
|
|
@@ -29,12 +31,30 @@ export interface DriveWriteRequest {
|
|
|
29
31
|
path: string;
|
|
30
32
|
executable?: boolean;
|
|
31
33
|
}
|
|
32
|
-
export
|
|
34
|
+
export interface DriveSearchQuery {
|
|
35
|
+
folder: string;
|
|
36
|
+
queries: string[];
|
|
37
|
+
regex: boolean;
|
|
38
|
+
caseSensitive: boolean;
|
|
39
|
+
includeIgnored: boolean;
|
|
40
|
+
maxMatches: number;
|
|
41
|
+
maxEntries: number;
|
|
42
|
+
maxMs: number;
|
|
43
|
+
}
|
|
44
|
+
export interface DriveSearchRequest extends DriveSearchQuery {
|
|
45
|
+
op: 'search';
|
|
46
|
+
driveKey: string;
|
|
47
|
+
}
|
|
48
|
+
export type DriveRequest = DriveEntryRequest | DriveGetRequest | DriveReadRequest | DriveListRequest | DriveWriteRequest | DriveSearchRequest;
|
|
33
49
|
export interface DriveResponse {
|
|
34
50
|
error?: string;
|
|
35
51
|
entry?: DriveEntry | null;
|
|
36
52
|
path?: string | null;
|
|
37
53
|
truncated?: boolean;
|
|
38
|
-
entries?: DriveEntry
|
|
54
|
+
entries?: Array<DriveEntry | DriveDir>;
|
|
39
55
|
cursor?: string | null;
|
|
56
|
+
hits?: SearchHit[];
|
|
57
|
+
capped?: boolean;
|
|
58
|
+
cut?: boolean;
|
|
59
|
+
skippedLinks?: number;
|
|
40
60
|
}
|
|
@@ -3,16 +3,15 @@ import type { HyperRoot } from './scope.ts';
|
|
|
3
3
|
export interface GrantedDrive {
|
|
4
4
|
readonly key: string;
|
|
5
5
|
readonly writable: boolean;
|
|
6
|
+
readonly search?: boolean;
|
|
6
7
|
}
|
|
7
8
|
export type DriveOpFn = (request: DriveRequest) => Promise<DriveResponse>;
|
|
8
9
|
export declare const DRIVE_CALL_TIMEOUT_MS = 20000;
|
|
10
|
+
export declare const DRIVE_SEARCH_TIMEOUT_MS: number;
|
|
9
11
|
export declare const MAX_DRIVE_BYTES: number;
|
|
10
12
|
export declare const DRIVE_LIST_PAGE = 256;
|
|
11
|
-
export declare class DriveReadTruncatedError extends Error {
|
|
12
|
-
constructor(key: string);
|
|
13
|
-
}
|
|
14
|
-
export declare function isDriveReadTruncated(err: unknown): err is DriveReadTruncatedError;
|
|
15
13
|
export interface RemoteRootsOptions {
|
|
16
14
|
readonly timeoutMs?: number;
|
|
15
|
+
readonly searchTimeoutMs?: number;
|
|
17
16
|
}
|
|
18
17
|
export declare function createRemoteRoots(drives: readonly GrantedDrive[], driveOp: DriveOpFn, opts?: RemoteRootsOptions): HyperRoot[];
|
|
@@ -1,23 +1,18 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { Writable } from 'streamx';
|
|
4
|
+
import { HarnessError } from '../../errors.js';
|
|
5
|
+
import { DriveReadTruncatedError } from './drive.js';
|
|
6
|
+
import { MAX_WALK_MS } from './walk.js';
|
|
4
7
|
import { STAGING_DIR } from '../../staging.js';
|
|
5
8
|
export const DRIVE_CALL_TIMEOUT_MS = 20_000;
|
|
9
|
+
export const DRIVE_SEARCH_TIMEOUT_MS = MAX_WALK_MS + DRIVE_CALL_TIMEOUT_MS;
|
|
6
10
|
export const MAX_DRIVE_BYTES = 8 * 1024 * 1024;
|
|
7
11
|
export const DRIVE_LIST_PAGE = 256;
|
|
8
12
|
const noop = () => { };
|
|
9
|
-
export class DriveReadTruncatedError extends Error {
|
|
10
|
-
constructor(key) {
|
|
11
|
-
super(`read stopped at ${MAX_DRIVE_BYTES} bytes: ${key}`);
|
|
12
|
-
this.name = 'DriveReadTruncatedError';
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
export function isDriveReadTruncated(err) {
|
|
16
|
-
return err instanceof DriveReadTruncatedError;
|
|
17
|
-
}
|
|
18
13
|
function withTimeout(promise, ms, op) {
|
|
19
14
|
return new Promise((resolve, reject) => {
|
|
20
|
-
const timer = setTimeout(() => reject(new
|
|
15
|
+
const timer = setTimeout(() => reject(new HarnessError('DRIVE_TIMED_OUT', [op])), ms);
|
|
21
16
|
promise.then((value) => {
|
|
22
17
|
clearTimeout(timer);
|
|
23
18
|
resolve(value);
|
|
@@ -62,9 +57,10 @@ function remoteDrive(driveKey, driveOp, timeoutMs) {
|
|
|
62
57
|
},
|
|
63
58
|
async *list(folder = '/', opts) {
|
|
64
59
|
const skip = [...(opts?.skip ?? [])];
|
|
60
|
+
const recursive = opts?.recursive ?? true;
|
|
65
61
|
let cursor = null;
|
|
66
62
|
while (true) {
|
|
67
|
-
const response = await call(driveOp, { op: 'list', driveKey, folder, skip, limit: DRIVE_LIST_PAGE, cursor }, timeoutMs);
|
|
63
|
+
const response = await call(driveOp, { op: 'list', driveKey, folder, skip, recursive, limit: DRIVE_LIST_PAGE, cursor }, timeoutMs);
|
|
68
64
|
const entries = response.entries ?? [];
|
|
69
65
|
for (const entry of entries) {
|
|
70
66
|
yield entry;
|
|
@@ -87,7 +83,7 @@ function remoteDrive(driveKey, driveOp, timeoutMs) {
|
|
|
87
83
|
await fs.promises.unlink(response.path).catch(noop);
|
|
88
84
|
}
|
|
89
85
|
if (response.truncated) {
|
|
90
|
-
throw new DriveReadTruncatedError(readKey);
|
|
86
|
+
throw new DriveReadTruncatedError(readKey, MAX_DRIVE_BYTES);
|
|
91
87
|
}
|
|
92
88
|
},
|
|
93
89
|
createWriteStream(writeKey, writeOpts) {
|
|
@@ -125,13 +121,27 @@ function remoteDrive(driveKey, driveOp, timeoutMs) {
|
|
|
125
121
|
}
|
|
126
122
|
};
|
|
127
123
|
}
|
|
124
|
+
function remoteSearch(driveKey, driveOp, timeoutMs) {
|
|
125
|
+
return async (query) => {
|
|
126
|
+
const response = await call(driveOp, { op: 'search', driveKey, ...query }, timeoutMs);
|
|
127
|
+
return {
|
|
128
|
+
hits: response.hits ?? [],
|
|
129
|
+
capped: response.capped === true,
|
|
130
|
+
cut: response.cut === true,
|
|
131
|
+
truncated: response.truncated === true,
|
|
132
|
+
skippedLinks: response.skippedLinks ?? 0
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
}
|
|
128
136
|
export function createRemoteRoots(drives, driveOp, opts = {}) {
|
|
129
137
|
const timeoutMs = opts.timeoutMs ?? DRIVE_CALL_TIMEOUT_MS;
|
|
138
|
+
const searchTimeoutMs = opts.searchTimeoutMs ?? DRIVE_SEARCH_TIMEOUT_MS;
|
|
130
139
|
return drives.map((drive) => ({
|
|
131
140
|
kind: 'hyper',
|
|
132
141
|
key: drive.key,
|
|
133
142
|
writable: drive.writable,
|
|
134
143
|
prefix: '/',
|
|
135
|
-
drive: remoteDrive(drive.key, driveOp, timeoutMs)
|
|
144
|
+
drive: remoteDrive(drive.key, driveOp, timeoutMs),
|
|
145
|
+
search: drive.search ? remoteSearch(drive.key, driveOp, searchTimeoutMs) : undefined
|
|
136
146
|
}));
|
|
137
147
|
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import type { CompiledPolicy } from '../../contract/policy.ts';
|
|
1
2
|
import type { Drive } from './drive.ts';
|
|
3
|
+
import type { DriveSearchQuery } from './remote-protocol.ts';
|
|
4
|
+
import type { FolderSearchResult } from './search.ts';
|
|
2
5
|
export type Realpath = (p: string) => Promise<string>;
|
|
3
6
|
export declare const defaultRealpath: Realpath;
|
|
4
7
|
export interface LocalRoot {
|
|
@@ -12,6 +15,7 @@ export interface HyperRoot {
|
|
|
12
15
|
readonly writable: boolean;
|
|
13
16
|
readonly prefix: string;
|
|
14
17
|
readonly drive: Drive;
|
|
18
|
+
readonly search?: (query: DriveSearchQuery) => Promise<FolderSearchResult>;
|
|
15
19
|
}
|
|
16
20
|
export type DriveRoot = LocalRoot | HyperRoot;
|
|
17
21
|
export interface FsToolOptions {
|
|
@@ -22,10 +26,10 @@ export declare const NO_DIRS_GRANTED = "no directories are granted";
|
|
|
22
26
|
export interface FsToolError {
|
|
23
27
|
error: string;
|
|
24
28
|
}
|
|
25
|
-
export declare const NO_STORAGE_ROOT = "cannot fence the app storage root: the SDK home is unknown";
|
|
26
29
|
export declare function deniedRootsFor(sdkHome: string | undefined): readonly string[];
|
|
27
30
|
export declare const PROTECTED_PATH_ERROR = "path is inside a protected app directory";
|
|
28
31
|
export declare function canonicalDenyRoots(deniedRoots: readonly string[] | undefined, realpath: Realpath): Promise<readonly string[]>;
|
|
32
|
+
export declare function callDenyRoots(deniedRoots: readonly string[] | undefined, policy: CompiledPolicy | undefined, realpath: Realpath): Promise<readonly string[]>;
|
|
29
33
|
export declare function isDeniedPath(hostPath: string, canonicalDenyRoots: readonly string[]): boolean;
|
|
30
34
|
export declare function overlaps(a: string, b: string): boolean;
|
|
31
35
|
export declare function hostPath(root: LocalRoot, key: string): string;
|