@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,65 @@
|
|
|
1
|
+
import { relativeKey, searchTargets } from '../fs/targets.js';
|
|
2
|
+
import { compileGlob } from '../fs/glob.js';
|
|
3
|
+
import { callDenyRoots, defaultRealpath, isDeniedPath } from '../fs/scope.js';
|
|
4
|
+
import { anchorOf, shownPath, stringArg } from '../fs/tool-path.js';
|
|
5
|
+
import { walkFiles } from '../fs/walk.js';
|
|
6
|
+
import { folderArg, folderPaths } from './list-dir.js';
|
|
7
|
+
const GLOB_MATCHES = 100;
|
|
8
|
+
export function createGlobTool({ realpath = defaultRealpath, deniedRoots } = {}) {
|
|
9
|
+
return {
|
|
10
|
+
name: 'glob',
|
|
11
|
+
toolset: 'files',
|
|
12
|
+
description: 'Find files in the shared folder by name pattern, newest first. "**" crosses folders: ' +
|
|
13
|
+
'"**/*.md" finds every Markdown file, "*report*" matches names anywhere.',
|
|
14
|
+
parameters: {
|
|
15
|
+
type: 'object',
|
|
16
|
+
properties: {
|
|
17
|
+
pattern: { type: 'string', description: 'Name or path pattern, e.g. "**/*.pdf"' },
|
|
18
|
+
dir: {
|
|
19
|
+
type: 'string',
|
|
20
|
+
description: 'Folder to search, relative to the shared folder (optional)'
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
required: ['pattern']
|
|
24
|
+
},
|
|
25
|
+
effect: () => 'read',
|
|
26
|
+
concurrent: true,
|
|
27
|
+
stableRead: true,
|
|
28
|
+
autoApprove: true,
|
|
29
|
+
rootsRequired: true,
|
|
30
|
+
validate: (args) => (stringArg(args, 'pattern') ? null : 'pattern is required'),
|
|
31
|
+
paths: (args, ctx) => folderPaths(args, ctx),
|
|
32
|
+
resource: (args) => ({ kind: 'file', label: `glob ${String(args.pattern ?? '')}` }),
|
|
33
|
+
async execute(args, ctx) {
|
|
34
|
+
const roots = ctx?.fsRoots ?? [];
|
|
35
|
+
const deny = await callDenyRoots(deniedRoots, ctx?.policy, realpath);
|
|
36
|
+
const scoped = await searchTargets(folderArg(args, ctx), roots, { realpath, deny });
|
|
37
|
+
if ('error' in scoped) {
|
|
38
|
+
return scoped;
|
|
39
|
+
}
|
|
40
|
+
const pattern = String(args.pattern);
|
|
41
|
+
const test = compileGlob(pattern);
|
|
42
|
+
const byName = !pattern.includes('/');
|
|
43
|
+
const hits = [];
|
|
44
|
+
let walkTruncated = false;
|
|
45
|
+
for (const target of scoped.targets) {
|
|
46
|
+
const walk = await walkFiles(target.root, target.folder);
|
|
47
|
+
walkTruncated ||= walk.truncated;
|
|
48
|
+
for (const file of walk.files) {
|
|
49
|
+
const rel = relativeKey(file.key, target.folder);
|
|
50
|
+
const name = rel.slice(rel.lastIndexOf('/') + 1);
|
|
51
|
+
if (isDeniedPath(file.path, deny) || !(test(rel) || (byName && test(name)))) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
const entry = await target.root.drive.entry(file.key);
|
|
55
|
+
hits.push({ path: shownPath(file.path, anchorOf(ctx)), mtime: entry?.mtime ?? 0 });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
hits.sort((a, b) => b.mtime - a.mtime);
|
|
59
|
+
return {
|
|
60
|
+
matches: hits.slice(0, GLOB_MATCHES).map((hit) => hit.path),
|
|
61
|
+
truncated: walkTruncated || hits.length > GLOB_MATCHES || undefined
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ToolDefinition } from '../../contract/index.ts';
|
|
2
|
+
import { type FsToolOptions } from '../fs/scope.ts';
|
|
3
|
+
export interface GrepToolOptions extends FsToolOptions {
|
|
4
|
+
readonly maxWalkEntries?: number;
|
|
5
|
+
}
|
|
6
|
+
export declare function createGrepTool({ realpath, deniedRoots, maxWalkEntries }?: GrepToolOptions): ToolDefinition;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { errorMessage } from '../../guards.js';
|
|
2
|
+
import { searchTargets } from '../fs/targets.js';
|
|
3
|
+
import { compileGlob } from '../fs/glob.js';
|
|
4
|
+
import { callDenyRoots, defaultRealpath } from '../fs/scope.js';
|
|
5
|
+
import { DriveSearch } from '../fs/search.js';
|
|
6
|
+
import { anchorOf, shownPath, stringArg } from '../fs/tool-path.js';
|
|
7
|
+
import { MAX_WALK_ENTRIES, MAX_WALK_MS } from '../fs/walk.js';
|
|
8
|
+
import { folderArg, folderPaths } from './list-dir.js';
|
|
9
|
+
const GREP_MATCHES = 100;
|
|
10
|
+
const MAX_LINE_CHARS = 300;
|
|
11
|
+
export function createGrepTool({ realpath = defaultRealpath, deniedRoots, maxWalkEntries = MAX_WALK_ENTRIES } = {}) {
|
|
12
|
+
return {
|
|
13
|
+
name: 'grep',
|
|
14
|
+
toolset: 'files',
|
|
15
|
+
description: 'Search inside the files of the shared folder. The pattern is plain text, case-insensitive; set ' +
|
|
16
|
+
'regex for a regular expression. Returns "path:line: text". Narrow with include (e.g. "*.ts").',
|
|
17
|
+
parameters: {
|
|
18
|
+
type: 'object',
|
|
19
|
+
properties: {
|
|
20
|
+
pattern: { type: 'string', description: 'Text to find' },
|
|
21
|
+
dir: {
|
|
22
|
+
type: 'string',
|
|
23
|
+
description: 'Folder to search, relative to the shared folder (optional)'
|
|
24
|
+
},
|
|
25
|
+
include: {
|
|
26
|
+
type: 'string',
|
|
27
|
+
description: 'Only files whose name matches this pattern (optional)'
|
|
28
|
+
},
|
|
29
|
+
regex: { type: 'boolean', description: 'Treat pattern as a regular expression' }
|
|
30
|
+
},
|
|
31
|
+
required: ['pattern']
|
|
32
|
+
},
|
|
33
|
+
effect: () => 'read',
|
|
34
|
+
concurrent: true,
|
|
35
|
+
stableRead: true,
|
|
36
|
+
autoApprove: true,
|
|
37
|
+
rootsRequired: true,
|
|
38
|
+
validate(args) {
|
|
39
|
+
if (!stringArg(args, 'pattern'))
|
|
40
|
+
return 'pattern is required';
|
|
41
|
+
if (args.regex !== true)
|
|
42
|
+
return null;
|
|
43
|
+
try {
|
|
44
|
+
new RegExp(String(args.pattern), 'i');
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
return `invalid regex: ${errorMessage(err)}`;
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
paths: (args, ctx) => folderPaths(args, ctx),
|
|
52
|
+
resource: (args) => ({ kind: 'file', label: `grep ${String(args.pattern ?? '')}` }),
|
|
53
|
+
async execute(args, ctx) {
|
|
54
|
+
const roots = ctx?.fsRoots ?? [];
|
|
55
|
+
const deny = await callDenyRoots(deniedRoots, ctx?.policy, realpath);
|
|
56
|
+
const scoped = await searchTargets(folderArg(args, ctx), roots, { realpath, deny });
|
|
57
|
+
if ('error' in scoped) {
|
|
58
|
+
return scoped;
|
|
59
|
+
}
|
|
60
|
+
const pattern = String(args.pattern);
|
|
61
|
+
const regex = args.regex === true;
|
|
62
|
+
const query = {
|
|
63
|
+
search: new DriveSearch([pattern], { regex }),
|
|
64
|
+
pattern,
|
|
65
|
+
regex,
|
|
66
|
+
include: stringArg(args, 'include') ? compileGlob(String(args.include)) : null,
|
|
67
|
+
deny,
|
|
68
|
+
maxEntries: maxWalkEntries
|
|
69
|
+
};
|
|
70
|
+
const hits = [];
|
|
71
|
+
let truncated = false;
|
|
72
|
+
for (const target of scoped.targets) {
|
|
73
|
+
let found;
|
|
74
|
+
try {
|
|
75
|
+
found = await searchTarget(target, {
|
|
76
|
+
...query,
|
|
77
|
+
maxMatches: GREP_MATCHES + 1 - hits.length
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
return { error: errorMessage(err) };
|
|
82
|
+
}
|
|
83
|
+
hits.push(...found.hits);
|
|
84
|
+
truncated ||= found.truncated || found.cut;
|
|
85
|
+
if (found.capped) {
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const anchor = anchorOf(ctx);
|
|
90
|
+
const rows = hits
|
|
91
|
+
.slice(0, GREP_MATCHES)
|
|
92
|
+
.map((hit) => `${shownPath(hit.file, anchor)}:${hit.line}: ${hit.text.slice(0, MAX_LINE_CHARS)}`);
|
|
93
|
+
return {
|
|
94
|
+
matches: rows.join('\n') || 'no matches',
|
|
95
|
+
truncated: truncated || hits.length > GREP_MATCHES || undefined
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function searchTarget({ root, folder }, { search, pattern, regex, include, deny, maxEntries, maxMatches }) {
|
|
101
|
+
if (root.kind === 'hyper' && root.search && !include) {
|
|
102
|
+
return root.search({
|
|
103
|
+
folder,
|
|
104
|
+
queries: [pattern],
|
|
105
|
+
regex,
|
|
106
|
+
caseSensitive: false,
|
|
107
|
+
includeIgnored: false,
|
|
108
|
+
maxMatches,
|
|
109
|
+
maxEntries,
|
|
110
|
+
maxMs: MAX_WALK_MS
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return search.searchFolder(root, folder, { maxMatches, maxEntries, include, deny });
|
|
114
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createEditFileTool } from './edit-file.js';
|
|
2
|
+
import { createGlobTool } from './glob.js';
|
|
3
|
+
import { createGrepTool } from './grep.js';
|
|
4
|
+
import { createListDirTool } from './list-dir.js';
|
|
5
|
+
import { createMakeDirTool } from './make-dir.js';
|
|
6
|
+
import { createReadFileTool } from './read-file.js';
|
|
7
|
+
import { createCopyFileTool, createMoveFileTool } from './transfer.js';
|
|
8
|
+
import { createTrashFileTool } from './trash-file.js';
|
|
9
|
+
import { createWriteFileTool } from './write-file.js';
|
|
10
|
+
export function createFileTools(options = {}) {
|
|
11
|
+
return [
|
|
12
|
+
createReadFileTool(options),
|
|
13
|
+
createListDirTool(options),
|
|
14
|
+
createGlobTool(options),
|
|
15
|
+
createGrepTool(options),
|
|
16
|
+
createWriteFileTool(options),
|
|
17
|
+
createEditFileTool(options),
|
|
18
|
+
createMoveFileTool(options),
|
|
19
|
+
createCopyFileTool(options),
|
|
20
|
+
createMakeDirTool(options),
|
|
21
|
+
createTrashFileTool(options)
|
|
22
|
+
];
|
|
23
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ToolDefinition } from '../../contract/index.ts';
|
|
2
|
+
import { type FsToolOptions } from '../fs/scope.ts';
|
|
3
|
+
import { type Grants } from '../fs/tool-path.ts';
|
|
4
|
+
export declare function createListDirTool({ realpath, deniedRoots }?: FsToolOptions): ToolDefinition;
|
|
5
|
+
export declare function folderArg(args: Record<string, unknown>, grants: Grants | undefined): string | undefined;
|
|
6
|
+
export declare function folderPaths(args: Record<string, unknown>, grants: Grants | undefined): string[];
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import { relativeKey, searchTargets } from '../fs/targets.js';
|
|
3
|
+
import { callDenyRoots, defaultRealpath, displayPath, hostPath, isDeniedPath } from '../fs/scope.js';
|
|
4
|
+
import { anchorOf, rootedPath, stringArg } from '../fs/tool-path.js';
|
|
5
|
+
import { WALK_SKIP_DIRS, walkFiles } from '../fs/walk.js';
|
|
6
|
+
const LIST_ENTRIES = 200;
|
|
7
|
+
export function createListDirTool({ realpath = defaultRealpath, deniedRoots } = {}) {
|
|
8
|
+
return {
|
|
9
|
+
name: 'list_dir',
|
|
10
|
+
toolset: 'files',
|
|
11
|
+
description: 'List a folder inside the shared folder: each entry with its type, size and last change. ' +
|
|
12
|
+
'Leave path empty for the shared folder itself. Use this, not exec, to look inside it.',
|
|
13
|
+
parameters: {
|
|
14
|
+
type: 'object',
|
|
15
|
+
properties: {
|
|
16
|
+
path: { type: 'string', description: 'Folder, relative to the shared folder (optional)' }
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
effect: () => 'read',
|
|
20
|
+
concurrent: true,
|
|
21
|
+
stableRead: true,
|
|
22
|
+
autoApprove: true,
|
|
23
|
+
rootsRequired: true,
|
|
24
|
+
paths: (args, ctx) => folderPaths(args, ctx),
|
|
25
|
+
resource: (args, ctx) => ({
|
|
26
|
+
kind: 'file',
|
|
27
|
+
label: `list ${folderArg(args, ctx) ?? 'shared folder'}`
|
|
28
|
+
}),
|
|
29
|
+
async execute(args, ctx) {
|
|
30
|
+
const roots = ctx?.fsRoots ?? [];
|
|
31
|
+
const deny = await callDenyRoots(deniedRoots, ctx?.policy, realpath);
|
|
32
|
+
const scoped = await searchTargets(folderArg(args, ctx), roots, { realpath, deny });
|
|
33
|
+
if ('error' in scoped) {
|
|
34
|
+
return scoped;
|
|
35
|
+
}
|
|
36
|
+
const { entries, truncated } = await collect(scoped.targets, { deny, anchor: anchorOf(ctx) });
|
|
37
|
+
const rows = await describe([...entries].slice(0, LIST_ENTRIES));
|
|
38
|
+
return {
|
|
39
|
+
entries: rows.join('\n') || '(empty)',
|
|
40
|
+
truncated: truncated || entries.size > LIST_ENTRIES || undefined
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export function folderArg(args, grants) {
|
|
46
|
+
const folder = stringArg(args, 'dir') ?? stringArg(args, 'path');
|
|
47
|
+
return folder && folder !== '.' && folder !== '/'
|
|
48
|
+
? rootedPath(folder, anchorOf(grants))
|
|
49
|
+
: undefined;
|
|
50
|
+
}
|
|
51
|
+
export function folderPaths(args, grants) {
|
|
52
|
+
const folder = folderArg(args, grants);
|
|
53
|
+
return folder ? [folder] : (grants?.fsRoots ?? []).map((root) => displayPath(root, '/'));
|
|
54
|
+
}
|
|
55
|
+
async function collect(targets, { deny, anchor }) {
|
|
56
|
+
const entries = new Map();
|
|
57
|
+
let truncated = false;
|
|
58
|
+
for (const target of targets) {
|
|
59
|
+
const own = targets.length === 1 || target.root === anchor;
|
|
60
|
+
const level = target.root.kind === 'local'
|
|
61
|
+
? await localLevel(target.root, target.folder, deny)
|
|
62
|
+
: await walkedLevel(target, deny);
|
|
63
|
+
truncated ||= level.truncated;
|
|
64
|
+
for (const child of level.children) {
|
|
65
|
+
const name = own ? child.name : displayPath(target.root, child.key);
|
|
66
|
+
entries.set(name, { ...child, drive: target.root.drive });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return { entries, truncated };
|
|
70
|
+
}
|
|
71
|
+
async function localLevel(root, folder, deny) {
|
|
72
|
+
const children = [];
|
|
73
|
+
for (const dirent of await readdir(hostPath(root, folder))) {
|
|
74
|
+
const key = childKey(folder, dirent.name);
|
|
75
|
+
if (dirent.isSymbolicLink() || isDeniedPath(hostPath(root, key), deny)) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (dirent.isDirectory() && !WALK_SKIP_DIRS.has(dirent.name)) {
|
|
79
|
+
const items = (await readdir(hostPath(root, key))).length;
|
|
80
|
+
children.push({ name: dirent.name, key, folder: true, items });
|
|
81
|
+
}
|
|
82
|
+
else if (dirent.isFile()) {
|
|
83
|
+
children.push({ name: dirent.name, key, folder: false, items: 0 });
|
|
84
|
+
}
|
|
85
|
+
if (children.length > LIST_ENTRIES) {
|
|
86
|
+
return { children, truncated: true };
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return { children, truncated: false };
|
|
90
|
+
}
|
|
91
|
+
async function walkedLevel(target, deny) {
|
|
92
|
+
const walk = await walkFiles(target.root, target.folder);
|
|
93
|
+
const children = [];
|
|
94
|
+
const folders = new Map();
|
|
95
|
+
for (const file of walk.files) {
|
|
96
|
+
if (isDeniedPath(file.path, deny))
|
|
97
|
+
continue;
|
|
98
|
+
const [name, below] = relativeKey(file.key, target.folder).split('/');
|
|
99
|
+
if (below === undefined) {
|
|
100
|
+
children.push({ name, key: file.key, folder: false, items: 0 });
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
folders.set(name, (folders.get(name) ?? new Set()).add(below));
|
|
104
|
+
}
|
|
105
|
+
for (const [name, items] of folders) {
|
|
106
|
+
children.push({ name, key: childKey(target.folder, name), folder: true, items: items.size });
|
|
107
|
+
}
|
|
108
|
+
return { children, truncated: walk.truncated };
|
|
109
|
+
}
|
|
110
|
+
async function readdir(dir) {
|
|
111
|
+
try {
|
|
112
|
+
return await fs.promises.readdir(dir, { withFileTypes: true });
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
return [];
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function childKey(folder, name) {
|
|
119
|
+
return folder === '/' ? `/${name}` : `${folder}/${name}`;
|
|
120
|
+
}
|
|
121
|
+
async function describe(entries) {
|
|
122
|
+
const rows = [];
|
|
123
|
+
for (const [name, entry] of entries) {
|
|
124
|
+
if (entry.folder) {
|
|
125
|
+
rows.push(`${name}/ (folder, ${entry.items} ${entry.items === 1 ? 'item' : 'items'})`);
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
const stat = await entry.drive.entry(entry.key);
|
|
129
|
+
const size = stat?.value.blob?.byteLength ?? 0;
|
|
130
|
+
const changed = stat?.mtime
|
|
131
|
+
? `, changed ${new Date(stat.mtime).toISOString().slice(0, 16)}`
|
|
132
|
+
: '';
|
|
133
|
+
rows.push(`${name} (${size} bytes${changed})`);
|
|
134
|
+
}
|
|
135
|
+
return rows;
|
|
136
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import { errorMessage } from '../../guards.js';
|
|
3
|
+
import { defaultRealpath } from '../fs/scope.js';
|
|
4
|
+
import { localPathOf, resolveRooted, rootedArgs, rootedLabel, stringArg } from '../fs/tool-path.js';
|
|
5
|
+
export function createMakeDirTool({ realpath = defaultRealpath, deniedRoots } = {}) {
|
|
6
|
+
return {
|
|
7
|
+
name: 'make_dir',
|
|
8
|
+
toolset: 'files',
|
|
9
|
+
description: 'Create a folder (and any missing parents) inside the shared folder.',
|
|
10
|
+
parameters: {
|
|
11
|
+
type: 'object',
|
|
12
|
+
properties: {
|
|
13
|
+
path: { type: 'string', description: 'Folder path, relative to the shared folder' }
|
|
14
|
+
},
|
|
15
|
+
required: ['path']
|
|
16
|
+
},
|
|
17
|
+
effect: () => 'read',
|
|
18
|
+
writeRootsRequired: true,
|
|
19
|
+
validate: (args) => (stringArg(args, 'path') ? null : 'path is required'),
|
|
20
|
+
paths: (args, ctx) => rootedArgs(args, ctx, ['path']),
|
|
21
|
+
resource: (args, ctx) => ({
|
|
22
|
+
kind: 'file',
|
|
23
|
+
label: rootedLabel('mkdir', { grants: ctx, paths: [String(args.path)] })
|
|
24
|
+
}),
|
|
25
|
+
async execute(args, ctx) {
|
|
26
|
+
const resolved = await resolveRooted(String(args.path), {
|
|
27
|
+
grants: ctx,
|
|
28
|
+
write: true,
|
|
29
|
+
realpath,
|
|
30
|
+
deniedRoots
|
|
31
|
+
});
|
|
32
|
+
if ('error' in resolved) {
|
|
33
|
+
return resolved;
|
|
34
|
+
}
|
|
35
|
+
const target = localPathOf(resolved);
|
|
36
|
+
if (!target) {
|
|
37
|
+
return { error: 'folders can only be created in a folder on this device' };
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
await fs.promises.mkdir(target, { recursive: true });
|
|
41
|
+
return { created: String(args.path) };
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
return { error: errorMessage(err) };
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import b4a from 'b4a';
|
|
2
|
+
import { errorMessage } from '../../guards.js';
|
|
3
|
+
import { documentText, isDocument } from '../fs/document-text.js';
|
|
4
|
+
import { createLocalRoots } from '../fs/local.js';
|
|
5
|
+
import { defaultRealpath, resolveKey } from '../fs/scope.js';
|
|
6
|
+
import { anchorOf, positiveInt, resolveRooted, rootedArgs, rootedPath, stringArg } from '../fs/tool-path.js';
|
|
7
|
+
const READ_LINES = 400;
|
|
8
|
+
const READ_CHARS = 20_000;
|
|
9
|
+
const BINARY_PROBE = 1024;
|
|
10
|
+
export function createReadFileTool({ realpath = defaultRealpath, deniedRoots } = {}) {
|
|
11
|
+
return {
|
|
12
|
+
name: 'read_file',
|
|
13
|
+
toolset: 'files',
|
|
14
|
+
description: 'Read one file from the shared folder. Lines come back numbered ("12| text"). For a long file, ' +
|
|
15
|
+
'read a range with startLine/endLine. PDF, Word and PowerPoint files come back as their text. ' +
|
|
16
|
+
'Use this, not exec, for files in the shared folder.',
|
|
17
|
+
parameters: {
|
|
18
|
+
type: 'object',
|
|
19
|
+
properties: {
|
|
20
|
+
path: { type: 'string', description: 'File path, relative to the shared folder' },
|
|
21
|
+
startLine: { type: 'integer', description: 'First line to read (1-based, optional)' },
|
|
22
|
+
endLine: { type: 'integer', description: 'Last line to read (optional)' }
|
|
23
|
+
},
|
|
24
|
+
required: ['path']
|
|
25
|
+
},
|
|
26
|
+
effect: () => 'read',
|
|
27
|
+
concurrent: true,
|
|
28
|
+
stableRead: true,
|
|
29
|
+
autoApprove: true,
|
|
30
|
+
rootsRequired: true,
|
|
31
|
+
validate: (args) => (stringArg(args, 'path') ? null : 'path is required'),
|
|
32
|
+
paths: (args, ctx) => rootedArgs(args, ctx, ['path']),
|
|
33
|
+
resource(args, ctx) {
|
|
34
|
+
const requested = stringArg(args, 'path');
|
|
35
|
+
return requested ? { kind: 'file', label: rootedPath(requested, anchorOf(ctx)) } : null;
|
|
36
|
+
},
|
|
37
|
+
async execute(args, ctx) {
|
|
38
|
+
const requested = String(args.path);
|
|
39
|
+
const spill = ctx?.spill ? await createLocalRoots([ctx.spill.dir], realpath) : [];
|
|
40
|
+
const own = spill.length ? await resolveKey(requested, spill, { realpath }) : null;
|
|
41
|
+
const resolved = own && !('error' in own)
|
|
42
|
+
? own
|
|
43
|
+
: await resolveRooted(requested, { grants: ctx, write: false, realpath, deniedRoots });
|
|
44
|
+
if ('error' in resolved) {
|
|
45
|
+
return resolved;
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
const text = await textOf(resolved, requested);
|
|
49
|
+
if (typeof text !== 'string') {
|
|
50
|
+
return text;
|
|
51
|
+
}
|
|
52
|
+
return numbered(text, {
|
|
53
|
+
start: positiveInt(args.startLine),
|
|
54
|
+
end: positiveInt(args.endLine)
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
return { error: errorMessage(err) };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
async function textOf(resolved, requested) {
|
|
64
|
+
const { drive } = resolved.root;
|
|
65
|
+
const bytes = (await drive.entry(resolved.key)) ? await drive.get(resolved.key) : null;
|
|
66
|
+
if (bytes === null) {
|
|
67
|
+
return { error: `no such file: ${requested}. Use list_dir or glob to find the right path.` };
|
|
68
|
+
}
|
|
69
|
+
if (isDocument(resolved.key)) {
|
|
70
|
+
return documentText(resolved.key, bytes);
|
|
71
|
+
}
|
|
72
|
+
if (bytes.subarray(0, BINARY_PROBE).includes(0)) {
|
|
73
|
+
return { error: `${requested} is a binary file (not text, PDF, Word or PowerPoint)` };
|
|
74
|
+
}
|
|
75
|
+
return b4a.toString(bytes, 'utf8');
|
|
76
|
+
}
|
|
77
|
+
function numbered(text, { start, end }) {
|
|
78
|
+
const lines = text.split('\n');
|
|
79
|
+
if (lines.length > 1 && lines[lines.length - 1] === '') {
|
|
80
|
+
lines.pop();
|
|
81
|
+
}
|
|
82
|
+
const total = lines.length;
|
|
83
|
+
const first = Math.min(start ?? 1, Math.max(total, 1));
|
|
84
|
+
const out = [];
|
|
85
|
+
let chars = 0;
|
|
86
|
+
let cut = false;
|
|
87
|
+
for (let n = first; n <= Math.min(total, end ?? first + READ_LINES - 1); n++) {
|
|
88
|
+
const row = `${n}| ${lines[n - 1]}`;
|
|
89
|
+
if (chars + row.length > READ_CHARS) {
|
|
90
|
+
cut = out.length === 0;
|
|
91
|
+
if (cut) {
|
|
92
|
+
out.push(row.slice(0, READ_CHARS));
|
|
93
|
+
}
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
out.push(row);
|
|
97
|
+
chars += row.length + 1;
|
|
98
|
+
}
|
|
99
|
+
const last = first + out.length - 1;
|
|
100
|
+
const shown = cut
|
|
101
|
+
? `line ${first} of ${total}, cut at ${READ_CHARS} characters`
|
|
102
|
+
: `lines ${first}-${last} of ${total}`;
|
|
103
|
+
const header = last < total ? `${shown}; continue with startLine ${last + 1}` : shown;
|
|
104
|
+
return { content: `${header}\n${out.join('\n')}` };
|
|
105
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ToolDefinition } from '../../contract/index.ts';
|
|
2
|
+
import { type FsToolOptions } from '../fs/scope.ts';
|
|
3
|
+
export declare function createMoveFileTool(options?: FsToolOptions): ToolDefinition;
|
|
4
|
+
export declare function createCopyFileTool(options?: FsToolOptions): ToolDefinition;
|
|
@@ -0,0 +1,83 @@
|
|
|
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
|
+
function fromTo(from) {
|
|
7
|
+
return {
|
|
8
|
+
type: 'object',
|
|
9
|
+
properties: {
|
|
10
|
+
from: { type: 'string', description: from },
|
|
11
|
+
to: { type: 'string', description: 'New path, relative to the shared folder' }
|
|
12
|
+
},
|
|
13
|
+
required: ['from', 'to']
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export function createMoveFileTool(options = {}) {
|
|
17
|
+
return {
|
|
18
|
+
...transferTool({ ...options, copy: false }),
|
|
19
|
+
name: 'move_file',
|
|
20
|
+
parameters: fromTo('Current path, relative to the shared folder'),
|
|
21
|
+
description: 'Move or rename a file or folder inside the shared folder. Fails if the destination exists. ' +
|
|
22
|
+
'Asks the user first.',
|
|
23
|
+
effect: () => 'write',
|
|
24
|
+
autoApprove: false
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export function createCopyFileTool(options = {}) {
|
|
28
|
+
return {
|
|
29
|
+
...transferTool({ ...options, copy: true }),
|
|
30
|
+
name: 'copy_file',
|
|
31
|
+
parameters: fromTo('File to copy, relative to the shared folder'),
|
|
32
|
+
description: 'Copy a file inside the shared folder to a new path. Fails if the destination exists.',
|
|
33
|
+
effect: () => 'read'
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function transferTool({ realpath = defaultRealpath, deniedRoots, copy }) {
|
|
37
|
+
return {
|
|
38
|
+
toolset: 'files',
|
|
39
|
+
writeRootsRequired: true,
|
|
40
|
+
validate: (args) => stringArg(args, 'from') && stringArg(args, 'to') ? null : 'from and to are required',
|
|
41
|
+
paths: (args, ctx) => rootedArgs(args, ctx, ['from', 'to']),
|
|
42
|
+
resource: (args, ctx) => ({
|
|
43
|
+
kind: 'file',
|
|
44
|
+
label: rootedLabel(copy ? 'copy' : 'move', {
|
|
45
|
+
grants: ctx,
|
|
46
|
+
paths: [String(args.from), String(args.to)]
|
|
47
|
+
})
|
|
48
|
+
}),
|
|
49
|
+
execute: (args, ctx) => transfer(args, ctx, { realpath, deniedRoots, copy })
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
async function transfer(args, ctx, { realpath = defaultRealpath, deniedRoots, copy }) {
|
|
53
|
+
const scope = { grants: ctx, write: true, realpath, deniedRoots };
|
|
54
|
+
const from = await resolveRooted(String(args.from), scope);
|
|
55
|
+
if ('error' in from) {
|
|
56
|
+
return from;
|
|
57
|
+
}
|
|
58
|
+
const to = await resolveRooted(String(args.to), scope);
|
|
59
|
+
if ('error' in to) {
|
|
60
|
+
return to;
|
|
61
|
+
}
|
|
62
|
+
const source = localPathOf(from);
|
|
63
|
+
const target = localPathOf(to);
|
|
64
|
+
if (!source || !target) {
|
|
65
|
+
return { error: 'moving and copying work only in a folder on this device' };
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
if (!fs.existsSync(source)) {
|
|
69
|
+
return { error: `no such file: ${String(args.from)}` };
|
|
70
|
+
}
|
|
71
|
+
if (fs.existsSync(target)) {
|
|
72
|
+
return { error: `${String(args.to)} already exists` };
|
|
73
|
+
}
|
|
74
|
+
await fs.promises.mkdir(path.dirname(target), { recursive: true });
|
|
75
|
+
await (copy ? fs.promises.copyFile(source, target) : fs.promises.rename(source, target));
|
|
76
|
+
return copy
|
|
77
|
+
? { copied: String(args.from), to: String(args.to) }
|
|
78
|
+
: { moved: String(args.from), to: String(args.to) };
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
return { error: errorMessage(err) };
|
|
82
|
+
}
|
|
83
|
+
}
|