@qvac/harness 1.0.0-rc.2 → 1.0.0-rc.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.nvmrc +1 -0
- package/CHANGELOG.md +3050 -1485
- package/README.md +110 -46
- package/dist-lib/index.d.ts +60 -15
- package/dist-lib/index.js +228 -35
- package/dist-lib/lib/agent/delegate.d.ts +3 -2
- package/dist-lib/lib/agent/delegate.js +6 -4
- package/dist-lib/lib/agent/follow.d.ts +5 -0
- package/dist-lib/lib/agent/follow.js +11 -2
- package/dist-lib/lib/agent/resolve.js +29 -17
- package/dist-lib/lib/agent/tool-selection.d.ts +4 -2
- package/dist-lib/lib/agent/tool-selection.js +5 -6
- package/dist-lib/lib/agent/tools.d.ts +2 -0
- package/dist-lib/lib/agent/tools.js +2 -1
- package/dist-lib/lib/capabilities/agent-ports.d.ts +1 -1
- package/dist-lib/lib/capabilities/agent-ports.js +11 -4
- package/dist-lib/lib/capabilities/completion-engine/actors/batching.js +1 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/direct-search.js +2 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/executing.d.ts +2 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/executing.js +129 -12
- package/dist-lib/lib/capabilities/completion-engine/actors/execution-plan.js +10 -4
- package/dist-lib/lib/capabilities/completion-engine/actors/inspect-prepare.js +3 -2
- package/dist-lib/lib/capabilities/completion-engine/actors/inspecting.d.ts +1 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/inspecting.js +54 -10
- package/dist-lib/lib/capabilities/completion-engine/actors/loading-skill.d.ts +1 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/loading-skill.js +10 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/preparing.js +137 -50
- package/dist-lib/lib/capabilities/completion-engine/actors/rejecting.js +10 -4
- package/dist-lib/lib/capabilities/completion-engine/actors/resolving.js +69 -17
- package/dist-lib/lib/capabilities/completion-engine/actors/retrieving.d.ts +2 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/retrieving.js +33 -16
- package/dist-lib/lib/capabilities/completion-engine/actors/run-prepare.js +36 -22
- package/dist-lib/lib/capabilities/completion-engine/actors/skill-step.js +50 -12
- package/dist-lib/lib/capabilities/completion-engine/actors/stream.d.ts +10 -4
- package/dist-lib/lib/capabilities/completion-engine/actors/stream.js +80 -3
- package/dist-lib/lib/capabilities/completion-engine/actors/streaming.d.ts +5 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/streaming.js +95 -35
- package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.d.ts +2 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.js +55 -16
- package/dist-lib/lib/capabilities/completion-engine/driver.js +58 -15
- package/dist-lib/lib/capabilities/completion-engine/durable.d.ts +3 -1
- package/dist-lib/lib/capabilities/completion-engine/durable.js +12 -2
- package/dist-lib/lib/capabilities/completion-engine/engine.d.ts +4 -1
- package/dist-lib/lib/capabilities/completion-engine/engine.js +14 -1
- package/dist-lib/lib/capabilities/completion-engine/index.d.ts +5 -1
- package/dist-lib/lib/capabilities/completion-engine/index.js +5 -2
- package/dist-lib/lib/capabilities/completion-engine/loop.d.ts +25 -3
- package/dist-lib/lib/capabilities/completion-engine/loop.js +13 -2
- package/dist-lib/lib/capabilities/completion-engine/metrics.d.ts +9 -2
- package/dist-lib/lib/capabilities/completion-engine/metrics.js +28 -7
- package/dist-lib/lib/capabilities/completion-engine/model-round.d.ts +63 -0
- package/dist-lib/lib/capabilities/completion-engine/model-round.js +99 -0
- package/dist-lib/lib/capabilities/completion-engine/operations.js +30 -10
- package/dist-lib/lib/capabilities/completion-engine/ports.js +6 -9
- package/dist-lib/lib/capabilities/completion-engine/prepare-step.d.ts +4 -1
- package/dist-lib/lib/capabilities/completion-engine/round.d.ts +38 -6
- package/dist-lib/lib/capabilities/completion-engine/round.js +393 -116
- package/dist-lib/lib/capabilities/completion-engine/session.d.ts +12 -4
- package/dist-lib/lib/capabilities/completion-engine/session.js +31 -2
- package/dist-lib/lib/capabilities/completion-engine/tool-caller.js +3 -2
- package/dist-lib/lib/capabilities/completion-engine/tool-execution.d.ts +5 -4
- package/dist-lib/lib/capabilities/completion-engine/tool-execution.js +32 -12
- package/dist-lib/lib/capabilities/completion-engine/tool-sets.d.ts +24 -0
- package/dist-lib/lib/capabilities/completion-engine/tool-sets.js +15 -0
- package/dist-lib/lib/capabilities/completion-engine/turns.d.ts +17 -9
- package/dist-lib/lib/capabilities/completion-engine/turns.js +96 -87
- package/dist-lib/lib/capabilities/detect-language.d.ts +2 -1
- package/dist-lib/lib/capabilities/detect-language.js +14 -2
- package/dist-lib/lib/capabilities/download.d.ts +10 -8
- package/dist-lib/lib/capabilities/download.js +1 -1
- package/dist-lib/lib/capabilities/enhance.d.ts +1 -1
- package/dist-lib/lib/capabilities/enhance.js +23 -11
- package/dist-lib/lib/capabilities/kv-cache.d.ts +1 -1
- package/dist-lib/lib/capabilities/preview-model-source.d.ts +7 -0
- package/dist-lib/lib/capabilities/preview-model-source.js +83 -23
- package/dist-lib/lib/capabilities/prompt-prefix.d.ts +3 -1
- package/dist-lib/lib/capabilities/prompt-prefix.js +8 -0
- package/dist-lib/lib/capabilities/sdk-tool.d.ts +13 -4
- package/dist-lib/lib/capabilities/sdk-tool.js +59 -7
- package/dist-lib/lib/capabilities/skill-entry.d.ts +13 -1
- package/dist-lib/lib/capabilities/skill-entry.js +33 -2
- package/dist-lib/lib/capabilities/tool-failed-note.d.ts +1 -0
- package/dist-lib/lib/capabilities/tool-failed-note.js +1 -0
- package/dist-lib/lib/capabilities/tool-plan.d.ts +5 -1
- package/dist-lib/lib/capabilities/tool-plan.js +20 -5
- package/dist-lib/lib/capabilities/tool-prompt-log.d.ts +1 -1
- package/dist-lib/lib/capabilities/tool-prompt-log.js +3 -3
- package/dist-lib/lib/capabilities/tool-turns.d.ts +20 -9
- package/dist-lib/lib/capabilities/tool-turns.js +77 -49
- package/dist-lib/lib/capabilities/usage-breakdown.d.ts +1 -0
- package/dist-lib/lib/capabilities/usage-breakdown.js +4 -1
- package/dist-lib/lib/client/index.d.ts +19 -0
- package/dist-lib/lib/client/index.js +263 -0
- package/dist-lib/lib/connect.d.ts +19 -10
- package/dist-lib/lib/connect.js +239 -32
- package/dist-lib/lib/context-window.d.ts +2 -0
- package/dist-lib/lib/context-window.js +9 -3
- package/dist-lib/lib/contract/agent.d.ts +13 -3
- package/dist-lib/lib/contract/completion.d.ts +77 -31
- package/dist-lib/lib/contract/drive.d.ts +4 -0
- package/dist-lib/lib/contract/drive.js +1 -0
- package/dist-lib/lib/contract/egress-proxy.d.ts +13 -0
- package/dist-lib/lib/contract/egress-proxy.js +1 -0
- package/dist-lib/lib/contract/exec.d.ts +4 -3
- package/dist-lib/lib/contract/hooks.d.ts +4 -1
- package/dist-lib/lib/contract/index.d.ts +4 -0
- package/dist-lib/lib/contract/knowledge.d.ts +10 -0
- package/dist-lib/lib/contract/managed-skills.d.ts +1 -0
- package/dist-lib/lib/contract/managed-skills.js +1 -0
- package/dist-lib/lib/contract/media.d.ts +58 -0
- package/dist-lib/lib/contract/media.js +1 -0
- package/dist-lib/lib/contract/models.d.ts +12 -6
- package/dist-lib/lib/contract/ocr.d.ts +13 -0
- package/dist-lib/lib/contract/ocr.js +1 -0
- package/dist-lib/lib/contract/policy.d.ts +75 -0
- package/dist-lib/lib/contract/policy.js +1 -0
- package/dist-lib/lib/contract/run.d.ts +28 -3
- package/dist-lib/lib/contract/sandbox.d.ts +3 -1
- package/dist-lib/lib/contract/speech.d.ts +1 -1
- package/dist-lib/lib/contract/translation.d.ts +20 -0
- package/dist-lib/lib/contract/translation.js +1 -0
- package/dist-lib/lib/contract-types.d.ts +46 -16
- package/dist-lib/lib/embeddings/index.d.ts +7 -1
- package/dist-lib/lib/embeddings/index.js +26 -5
- package/dist-lib/lib/errors.d.ts +278 -0
- package/dist-lib/lib/errors.js +212 -0
- package/dist-lib/lib/fold/index.d.ts +26 -1
- package/dist-lib/lib/fold/index.js +76 -9
- package/dist-lib/lib/guarded-fetch.js +11 -7
- package/dist-lib/lib/guards.d.ts +2 -0
- package/dist-lib/lib/guards.js +7 -0
- package/dist-lib/lib/hardware/capability-probe.js +10 -7
- package/dist-lib/lib/hardware/cpu-placement.d.ts +8 -0
- package/dist-lib/lib/hardware/cpu-placement.js +48 -0
- package/dist-lib/lib/hardware/gpu-probe-addon.js +26 -11
- package/dist-lib/lib/hardware/gpu-probe.js +10 -1
- package/dist-lib/lib/hardware/gpu-stats.native.cjs +17 -1
- package/dist-lib/lib/helpers/completion-params.d.ts +7 -2
- package/dist-lib/lib/helpers/completion-params.js +26 -2
- package/dist-lib/lib/helpers/control-tokens.d.ts +3 -0
- package/dist-lib/lib/helpers/control-tokens.js +25 -0
- package/dist-lib/lib/helpers/engine-error.d.ts +2 -1
- package/dist-lib/lib/helpers/engine-error.js +12 -12
- package/dist-lib/lib/helpers/goal-check.d.ts +44 -0
- package/dist-lib/lib/helpers/goal-check.js +407 -0
- package/dist-lib/lib/helpers/head-tail.js +1 -1
- package/dist-lib/lib/helpers/html-helpers.js +9 -6
- package/dist-lib/lib/helpers/load-stall.d.ts +1 -1
- package/dist-lib/lib/helpers/load-stall.js +2 -2
- package/dist-lib/lib/helpers/markup-stream-filter.d.ts +4 -1
- package/dist-lib/lib/helpers/markup-stream-filter.js +20 -6
- package/dist-lib/lib/helpers/repeated-reply.js +24 -16
- package/dist-lib/lib/helpers/require-peers.d.ts +3 -0
- package/dist-lib/lib/helpers/require-peers.js +23 -0
- package/dist-lib/lib/helpers/run-outcome.d.ts +2 -0
- package/dist-lib/lib/helpers/run-outcome.js +6 -2
- package/dist-lib/lib/helpers/spawn-path.d.ts +1 -0
- package/dist-lib/lib/helpers/spawn-path.js +2 -1
- package/dist-lib/lib/helpers/thinking.d.ts +3 -2
- package/dist-lib/lib/helpers/thinking.js +19 -0
- package/dist-lib/lib/hooks/built-in/arg-repair.js +6 -2
- package/dist-lib/lib/hooks/built-in/policy-rules.d.ts +8 -0
- package/dist-lib/lib/hooks/built-in/policy-rules.js +192 -0
- package/dist-lib/lib/hooks/built-in/sandbox.js +23 -5
- package/dist-lib/lib/hooks/index.d.ts +4 -1
- package/dist-lib/lib/hooks/index.js +9 -4
- package/dist-lib/lib/hooks/run.js +3 -3
- package/dist-lib/lib/lifecycle/index.js +15 -14
- package/dist-lib/lib/lifecycle/machine.js +2 -2
- package/dist-lib/lib/log.d.ts +26 -5
- package/dist-lib/lib/log.js +86 -23
- package/dist-lib/lib/machine/completion/actions/completion.d.ts +11 -6
- package/dist-lib/lib/machine/completion/actions/completion.js +251 -35
- package/dist-lib/lib/machine/completion/actions/prepare.js +1 -1
- package/dist-lib/lib/machine/completion/actions/tools.js +122 -6
- package/dist-lib/lib/machine/completion/context.js +11 -1
- package/dist-lib/lib/machine/completion/guards/retry.d.ts +3 -1
- package/dist-lib/lib/machine/completion/guards/retry.js +9 -2
- package/dist-lib/lib/machine/completion/implementations.d.ts +16 -7
- package/dist-lib/lib/machine/completion/implementations.js +59 -15
- package/dist-lib/lib/machine/completion/machine.d.ts +36 -7
- package/dist-lib/lib/machine/completion/machine.js +58 -9
- package/dist-lib/lib/machine/completion/rules.d.ts +23 -2
- package/dist-lib/lib/machine/completion/rules.js +91 -6
- package/dist-lib/lib/machine/completion/types.d.ts +77 -1
- package/dist-lib/lib/machine/index.d.ts +48 -9
- package/dist-lib/lib/machine/index.js +11 -1
- package/dist-lib/lib/media-host.d.ts +12 -0
- package/dist-lib/lib/media-host.js +52 -0
- package/dist-lib/lib/media-port.d.ts +20 -0
- package/dist-lib/lib/media-port.js +77 -0
- package/dist-lib/lib/media-wire.d.ts +8 -0
- package/dist-lib/lib/media-wire.js +111 -0
- package/dist-lib/lib/models/context-choice.d.ts +15 -0
- package/dist-lib/lib/models/context-choice.js +62 -0
- package/dist-lib/lib/models/context.d.ts +1 -1
- package/dist-lib/lib/models/custom-model-cache.d.ts +1 -0
- package/dist-lib/lib/models/custom-model-cache.js +3 -0
- package/dist-lib/lib/models/download-gate.d.ts +20 -0
- package/dist-lib/lib/models/download-gate.js +73 -0
- package/dist-lib/lib/models/gguf-header.d.ts +11 -0
- package/dist-lib/lib/models/gguf-header.js +203 -15
- package/dist-lib/lib/models/gpu-selection.d.ts +6 -1
- package/dist-lib/lib/models/gpu-selection.js +29 -5
- package/dist-lib/lib/models/kv-cache.d.ts +2 -0
- package/dist-lib/lib/models/kv-cache.js +8 -0
- package/dist-lib/lib/models/llm-presets.d.ts +6 -1
- package/dist-lib/lib/models/llm-presets.js +33 -6
- package/dist-lib/lib/models/load-requests.d.ts +9 -0
- package/dist-lib/lib/models/load-requests.js +42 -0
- package/dist-lib/lib/models/memory-cap.d.ts +13 -0
- package/dist-lib/lib/models/memory-cap.js +21 -0
- package/dist-lib/lib/models/model-catalog-constants.d.ts +2 -2
- package/dist-lib/lib/models/model-catalog-constants.js +3 -4
- package/dist-lib/lib/models/model-catalog.d.ts +7 -3
- package/dist-lib/lib/models/model-catalog.js +44 -11
- package/dist-lib/lib/models/model-delete.d.ts +1 -1
- package/dist-lib/lib/models/model-fit.d.ts +2 -2
- package/dist-lib/lib/models/model-fit.js +5 -6
- package/dist-lib/lib/models/model-handle.d.ts +9 -2
- package/dist-lib/lib/models/model-handle.js +14 -3
- package/dist-lib/lib/models/model-list.d.ts +9 -2
- package/dist-lib/lib/models/model-list.js +23 -0
- package/dist-lib/lib/models/model-pool.d.ts +42 -7
- package/dist-lib/lib/models/model-pool.js +139 -49
- package/dist-lib/lib/models/model-source.d.ts +3 -2
- package/dist-lib/lib/models/model-source.js +23 -5
- package/dist-lib/lib/models/opencl-cache.js +2 -2
- package/dist-lib/lib/models/sdk-faults.d.ts +1 -0
- package/dist-lib/lib/models/sdk-faults.js +9 -0
- package/dist-lib/lib/models/tool-dialect.d.ts +1 -1
- package/dist-lib/lib/models/tts-model-default.d.ts +2 -1
- package/dist-lib/lib/models/tts-model-default.js +8 -6
- package/dist-lib/lib/no-redirect-fetch-bare.js +2 -1
- package/dist-lib/lib/no-redirect-fetch-impl.d.ts +2 -1
- package/dist-lib/lib/no-redirect-fetch-impl.js +46 -8
- package/dist-lib/lib/office/engine/pptx/picture-area.d.ts +23 -0
- package/dist-lib/lib/office/engine/pptx/picture-area.js +84 -0
- package/dist-lib/lib/office/engine/pptx/presentation.d.ts +2 -0
- package/dist-lib/lib/office/engine/pptx/presentation.js +64 -21
- package/dist-lib/lib/office/engine/pptx/types.d.ts +1 -0
- package/dist-lib/lib/office/engine/xlsx/sheet.js +10 -4
- package/dist-lib/lib/office/engine/xlsx/workbook.d.ts +1 -0
- package/dist-lib/lib/office/engine/xlsx/workbook.js +34 -3
- package/dist-lib/lib/office/extract.js +4 -3
- package/dist-lib/lib/office/index.js +2 -1
- package/dist-lib/lib/plugins/registry.d.ts +15 -0
- package/dist-lib/lib/plugins/registry.js +91 -22
- package/dist-lib/lib/plugins/require-bare.d.ts +1 -0
- package/dist-lib/lib/plugins/require-bare.js +13 -0
- package/dist-lib/lib/policy/index.d.ts +11 -0
- package/dist-lib/lib/policy/index.js +235 -0
- package/dist-lib/lib/prompt.d.ts +9 -4
- package/dist-lib/lib/prompt.js +95 -32
- package/dist-lib/lib/residency/completion-runtime.d.ts +15 -5
- package/dist-lib/lib/residency/completion-runtime.js +47 -36
- package/dist-lib/lib/residency/index.d.ts +56 -4
- package/dist-lib/lib/residency/index.js +442 -40
- package/dist-lib/lib/resolution-detector.js +3 -3
- package/dist-lib/lib/round-host.d.ts +12 -0
- package/dist-lib/lib/round-host.js +57 -0
- package/dist-lib/lib/round-port.d.ts +24 -0
- package/dist-lib/lib/round-port.js +81 -0
- package/dist-lib/lib/rpc-session.js +2 -1
- package/dist-lib/lib/run-log/request-codec.js +2 -2
- package/dist-lib/lib/sdk-loader.d.ts +1 -1
- package/dist-lib/lib/sdk-loader.js +47 -17
- package/dist-lib/lib/sdk-storage.d.ts +1 -0
- package/dist-lib/lib/sdk-storage.js +18 -2
- package/dist-lib/lib/serve.js +242 -50
- package/dist-lib/lib/sidecar/index.d.ts +39 -0
- package/dist-lib/lib/sidecar/index.js +205 -0
- package/dist-lib/lib/sidecar/user-plugins.d.ts +9 -0
- package/dist-lib/lib/sidecar/user-plugins.js +119 -0
- package/dist-lib/lib/skills-host/index.d.ts +3 -1
- package/dist-lib/lib/skills-host/index.js +27 -14
- package/dist-lib/lib/spawn.d.ts +6 -4
- package/dist-lib/lib/spawn.js +22 -20
- package/dist-lib/lib/spill.d.ts +1 -0
- package/dist-lib/lib/spill.js +12 -8
- package/dist-lib/lib/tools/ask-user.d.ts +2 -0
- package/dist-lib/lib/tools/ask-user.js +137 -0
- package/dist-lib/lib/tools/attachments/delivered.d.ts +5 -0
- package/dist-lib/lib/tools/attachments/delivered.js +16 -0
- package/dist-lib/lib/tools/attachments/fetched-file.d.ts +32 -0
- package/dist-lib/lib/tools/attachments/fetched-file.js +134 -0
- package/dist-lib/lib/tools/attachments/staging.d.ts +1 -0
- package/dist-lib/lib/tools/attachments/staging.js +19 -8
- package/dist-lib/lib/tools/exec/runner.d.ts +4 -0
- package/dist-lib/lib/tools/exec/runner.js +20 -2
- package/dist-lib/lib/tools/exec/scope.d.ts +0 -1
- package/dist-lib/lib/tools/exec/scope.js +23 -114
- package/dist-lib/lib/tools/exec/shell-guidance.js +4 -4
- package/dist-lib/lib/tools/exec/shell-line.d.ts +26 -0
- package/dist-lib/lib/tools/exec/shell-line.js +334 -0
- package/dist-lib/lib/tools/exec.d.ts +4 -1
- package/dist-lib/lib/tools/exec.js +89 -27
- package/dist-lib/lib/tools/files/edit-file.d.ts +6 -0
- package/dist-lib/lib/tools/files/edit-file.js +266 -0
- package/dist-lib/lib/tools/files/glob.d.ts +3 -0
- package/dist-lib/lib/tools/files/glob.js +65 -0
- package/dist-lib/lib/tools/files/grep.d.ts +6 -0
- package/dist-lib/lib/tools/files/grep.js +212 -0
- package/dist-lib/lib/tools/files/index.d.ts +3 -0
- package/dist-lib/lib/tools/files/index.js +25 -0
- package/dist-lib/lib/tools/files/list-dir.d.ts +6 -0
- package/dist-lib/lib/tools/files/list-dir.js +136 -0
- package/dist-lib/lib/tools/files/make-dir.d.ts +3 -0
- package/dist-lib/lib/tools/files/make-dir.js +48 -0
- package/dist-lib/lib/tools/files/read-file.d.ts +3 -0
- package/dist-lib/lib/tools/files/read-file.js +224 -0
- package/dist-lib/lib/tools/files/transfer.d.ts +4 -0
- package/dist-lib/lib/tools/files/transfer.js +83 -0
- package/dist-lib/lib/tools/files/trash-file.d.ts +4 -0
- package/dist-lib/lib/tools/files/trash-file.js +62 -0
- package/dist-lib/lib/tools/files/write-file.d.ts +3 -0
- package/dist-lib/lib/tools/files/write-file.js +56 -0
- package/dist-lib/lib/tools/fs/document-text.d.ts +8 -0
- package/dist-lib/lib/tools/fs/document-text.js +22 -0
- package/dist-lib/lib/tools/fs/drive.d.ts +10 -14
- package/dist-lib/lib/tools/fs/drive.js +9 -1
- package/dist-lib/lib/tools/fs/edit-match.d.ts +33 -0
- package/dist-lib/lib/tools/fs/edit-match.js +445 -0
- package/dist-lib/lib/tools/fs/ignore.d.ts +13 -0
- package/dist-lib/lib/tools/fs/ignore.js +104 -0
- package/dist-lib/lib/tools/fs/local.js +28 -5
- package/dist-lib/lib/tools/fs/remote-protocol.d.ts +45 -3
- package/dist-lib/lib/tools/fs/remote-protocol.js +1 -1
- package/dist-lib/lib/tools/fs/remote.d.ts +3 -11
- package/dist-lib/lib/tools/fs/remote.js +24 -14
- package/dist-lib/lib/tools/fs/scope.d.ts +5 -1
- package/dist-lib/lib/tools/fs/scope.js +5 -2
- package/dist-lib/lib/tools/fs/search.d.ts +41 -0
- package/dist-lib/lib/tools/fs/search.js +383 -0
- package/dist-lib/lib/tools/{file-glob.d.ts → fs/targets.d.ts} +1 -5
- package/dist-lib/lib/tools/fs/targets.js +32 -0
- package/dist-lib/lib/tools/fs/tool-path.d.ts +27 -0
- package/dist-lib/lib/tools/fs/tool-path.js +70 -0
- package/dist-lib/lib/tools/fs/walk.d.ts +16 -3
- package/dist-lib/lib/tools/fs/walk.js +119 -24
- package/dist-lib/lib/tools/http-request/request.d.ts +4 -2
- package/dist-lib/lib/tools/http-request/request.js +2 -1
- package/dist-lib/lib/tools/http-request/truncate-response.d.ts +16 -1
- package/dist-lib/lib/tools/http-request/truncate-response.js +56 -11
- package/dist-lib/lib/tools/http-request.d.ts +1 -0
- package/dist-lib/lib/tools/http-request.js +101 -16
- package/dist-lib/lib/tools/index.d.ts +4 -1
- package/dist-lib/lib/tools/index.js +8 -12
- package/dist-lib/lib/tools/office/ops.d.ts +1 -0
- package/dist-lib/lib/tools/office/ops.js +5 -1
- package/dist-lib/lib/tools/office.d.ts +2 -1
- package/dist-lib/lib/tools/office.js +273 -56
- package/dist-lib/lib/tools/operations/builders.d.ts +4 -3
- package/dist-lib/lib/tools/operations/builders.js +41 -3
- package/dist-lib/lib/tools/operations/calendar-range.d.ts +16 -0
- package/dist-lib/lib/tools/operations/calendar-range.js +40 -0
- package/dist-lib/lib/tools/operations/compile.js +8 -6
- package/dist-lib/lib/tools/operations/manifest.d.ts +4 -0
- package/dist-lib/lib/tools/pdf/build.d.ts +15 -1
- package/dist-lib/lib/tools/pdf/build.js +77 -16
- package/dist-lib/lib/tools/pdf/pages.d.ts +12 -0
- package/dist-lib/lib/tools/pdf/pages.js +31 -0
- package/dist-lib/lib/tools/pdf/recognize.d.ts +13 -0
- package/dist-lib/lib/tools/pdf/recognize.js +59 -0
- package/dist-lib/lib/tools/pdf.js +56 -12
- package/dist-lib/lib/tools/skill.js +10 -7
- package/dist-lib/lib/tools/skills/bundled-dir.d.ts +5 -1
- package/dist-lib/lib/tools/skills/bundled-dir.js +27 -24
- package/dist-lib/lib/tools/skills/catalog.d.ts +3 -1
- package/dist-lib/lib/tools/skills/catalog.js +7 -3
- package/dist-lib/lib/tools/skills/cli-argv.js +25 -5
- package/dist-lib/lib/tools/skills/cli-schema-check.d.ts +1 -0
- package/dist-lib/lib/tools/skills/cli-schema-check.js +3 -0
- package/dist-lib/lib/tools/skills/cli-schema-load.js +10 -0
- package/dist-lib/lib/tools/skills/cli-schema-types.d.ts +2 -0
- package/dist-lib/lib/tools/skills/cli-schema.js +6 -3
- package/dist-lib/lib/tools/skills/credential-check.d.ts +1 -0
- package/dist-lib/lib/tools/skills/credential-check.js +3 -0
- package/dist-lib/lib/tools/skills/credential-health.js +3 -3
- package/dist-lib/lib/tools/skills/frontmatter-parser.d.ts +3 -0
- package/dist-lib/lib/tools/skills/frontmatter-parser.js +5 -0
- package/dist-lib/lib/tools/skills/manifest-parse.d.ts +1 -0
- package/dist-lib/lib/tools/skills/manifest-parse.js +39 -3
- package/dist-lib/lib/tools/skills/manifest.d.ts +1 -0
- package/dist-lib/lib/tools/skills/mention-name.d.ts +6 -0
- package/dist-lib/lib/tools/skills/mention-name.js +6 -0
- package/dist-lib/lib/tools/skills/mention.d.ts +2 -2
- package/dist-lib/lib/tools/skills/mention.js +11 -4
- package/dist-lib/lib/tools/skills/overlay-crud.d.ts +3 -3
- package/dist-lib/lib/tools/skills/overlay-crud.js +7 -6
- package/dist-lib/lib/tools/skills/overlay-watch.d.ts +2 -2
- package/dist-lib/lib/tools/skills/overlay-watch.js +4 -3
- package/dist-lib/lib/tools/skills/scope-key.d.ts +1 -0
- package/dist-lib/lib/tools/skills/scope-key.js +4 -0
- package/dist-lib/lib/tools/skills/skill-state-constants.d.ts +1 -0
- package/dist-lib/lib/tools/skills/skill-state-constants.js +4 -0
- package/dist-lib/lib/tools/url-guard.d.ts +6 -1
- package/dist-lib/lib/tools/url-guard.js +8 -2
- package/dist-lib/lib/tools/web-fetch.js +50 -133
- package/dist-lib/lib/wire.d.ts +13 -0
- package/dist-lib/lib/wire.js +78 -6
- package/dist-lib/plugins/coding/index.d.ts +1 -1
- package/dist-lib/plugins/coding/index.js +2 -4
- package/dist-lib/plugins/coding/read-only.d.ts +1 -0
- package/dist-lib/plugins/coding/read-only.js +264 -0
- package/dist-lib/plugins/coding/session.d.ts +6 -4
- package/dist-lib/plugins/coding/session.js +45 -16
- package/dist-lib/plugins/coding-guards/index.d.ts +25 -0
- package/dist-lib/plugins/coding-guards/index.js +126 -0
- package/dist-lib/plugins/command-hooks/index.js +5 -3
- package/dist-lib/plugins/egress-proxy/index.d.ts +53 -0
- package/dist-lib/plugins/egress-proxy/index.js +184 -0
- package/dist-lib/plugins/image/edit-image.d.ts +3 -22
- package/dist-lib/plugins/image/edit-image.js +23 -46
- package/dist-lib/plugins/image/fit.d.ts +31 -0
- package/dist-lib/plugins/image/fit.js +28 -0
- package/dist-lib/plugins/image/generate-image.d.ts +27 -6
- package/dist-lib/plugins/image/generate-image.js +201 -74
- package/dist-lib/plugins/image/index.d.ts +2 -1
- package/dist-lib/plugins/image/index.js +29 -12
- package/dist-lib/plugins/knowledge/index.d.ts +3 -0
- package/dist-lib/plugins/knowledge/index.js +5 -0
- package/dist-lib/plugins/knowledge/manifest.d.ts +53 -0
- package/dist-lib/plugins/knowledge/manifest.js +86 -0
- package/dist-lib/plugins/knowledge/search-tool.js +8 -8
- package/dist-lib/plugins/knowledge/store.d.ts +45 -8
- package/dist-lib/plugins/knowledge/store.js +428 -166
- package/dist-lib/plugins/language-hint/index.d.ts +15 -0
- package/dist-lib/plugins/language-hint/index.js +54 -0
- package/dist-lib/plugins/lsp/tool.js +2 -2
- package/dist-lib/plugins/mcp/call.js +15 -4
- package/dist-lib/plugins/mcp/index.js +6 -3
- package/dist-lib/plugins/mcp/protocol.d.ts +10 -2
- package/dist-lib/plugins/mcp/protocol.js +13 -12
- package/dist-lib/plugins/mcp/server.js +1 -1
- package/dist-lib/plugins/mcp/tool-listing.d.ts +6 -0
- package/dist-lib/plugins/mcp/tool-listing.js +97 -0
- package/dist-lib/plugins/music/generate-music.d.ts +24 -5
- package/dist-lib/plugins/music/generate-music.js +170 -64
- package/dist-lib/plugins/music/index.d.ts +2 -1
- package/dist-lib/plugins/music/index.js +23 -11
- package/dist-lib/plugins/obsidian/command.js +2 -2
- package/dist-lib/plugins/obsidian/index.js +14 -4
- package/dist-lib/plugins/obsidian/note-name.js +2 -1
- package/dist-lib/plugins/obsidian/readiness.js +2 -2
- package/dist-lib/plugins/obsidian/safe-path.js +5 -4
- package/dist-lib/plugins/obsidian/vault-create.js +3 -2
- package/dist-lib/plugins/obsidian/vault-fs.js +2 -2
- package/dist-lib/plugins/obsidian/vault-paths.js +3 -2
- package/dist-lib/plugins/obsidian/vault-read.js +20 -18
- package/dist-lib/plugins/obsidian/vault-write.js +13 -12
- package/dist-lib/plugins/ocr/bmp.d.ts +2 -0
- package/dist-lib/plugins/ocr/bmp.js +27 -0
- package/dist-lib/plugins/ocr/index.d.ts +12 -0
- package/dist-lib/plugins/ocr/index.js +20 -0
- package/dist-lib/plugins/ocr/ocr-runtime.d.ts +23 -0
- package/dist-lib/plugins/ocr/ocr-runtime.js +82 -0
- package/dist-lib/plugins/ocr/reading-order.d.ts +5 -0
- package/dist-lib/plugins/ocr/reading-order.js +218 -0
- package/dist-lib/plugins/python/bare-floor.d.ts +1 -0
- package/dist-lib/plugins/python/bare-floor.js +2 -0
- package/dist-lib/plugins/python/guarded-fetch.d.ts +2 -1
- package/dist-lib/plugins/python/guarded-fetch.js +5 -1
- package/dist-lib/plugins/python/index.d.ts +4 -1
- package/dist-lib/plugins/python/index.js +6 -1
- package/dist-lib/plugins/python/interrupt-timer.js +2 -2
- package/dist-lib/plugins/python/language.js +11 -10
- package/dist-lib/plugins/python/loader.d.ts +1 -0
- package/dist-lib/plugins/python/loader.js +76 -3
- package/dist-lib/plugins/python/memfs.js +2 -2
- package/dist-lib/plugins/python/pyodide.d.ts +1 -0
- package/dist-lib/plugins/python/pyodide.js +9 -8
- package/dist-lib/plugins/python/python-adapter.d.ts +6 -1
- package/dist-lib/plugins/python/python-adapter.js +37 -2
- package/dist-lib/plugins/python/run-session.d.ts +1 -0
- package/dist-lib/plugins/python/run-session.js +19 -8
- package/dist-lib/plugins/python/wheels.js +8 -6
- package/dist-lib/plugins/python/worker/active.js +2 -2
- package/dist-lib/plugins/python/worker/client.js +10 -9
- package/dist-lib/plugins/python/worker/entry.js +2 -8
- package/dist-lib/plugins/python/worker/preload.d.ts +1 -0
- package/dist-lib/plugins/python/worker/preload.js +2 -0
- package/dist-lib/plugins/python/worker/protocol.d.ts +2 -0
- package/dist-lib/plugins/python/worker/serve.js +23 -4
- package/dist-lib/plugins/python/worker/spawn.d.ts +2 -1
- package/dist-lib/plugins/python/worker/spawn.js +3 -2
- package/dist-lib/plugins/quickjs/index.js +4 -0
- package/dist-lib/plugins/quickjs/runtime.js +8 -3
- package/dist-lib/plugins/run-report/chain.d.ts +2 -0
- package/dist-lib/plugins/run-report/chain.js +73 -0
- package/dist-lib/plugins/run-report/flow-view.js +2 -1
- package/dist-lib/plugins/run-report/flow.d.ts +1 -1
- package/dist-lib/plugins/run-report/flow.js +66 -14
- package/dist-lib/plugins/run-report/index.d.ts +23 -2
- package/dist-lib/plugins/run-report/index.js +32 -13
- package/dist-lib/plugins/run-report/layout.js +1 -1
- package/dist-lib/plugins/run-report/model.d.ts +10 -1
- package/dist-lib/plugins/run-report/model.js +12 -6
- package/dist-lib/plugins/run-report/page.d.ts +9 -0
- package/dist-lib/plugins/run-report/page.js +55 -15
- package/dist-lib/plugins/run-report/script.js +317 -43
- package/dist-lib/plugins/run-report/story.d.ts +2 -1
- package/dist-lib/plugins/run-report/story.js +7 -4
- package/dist-lib/plugins/run-report/style.d.ts +1 -1
- package/dist-lib/plugins/run-report/style.js +126 -0
- package/dist-lib/plugins/run-report/why.js +1 -1
- package/dist-lib/plugins/sandbox-linux/index.d.ts +62 -0
- package/dist-lib/plugins/sandbox-linux/index.js +354 -0
- package/dist-lib/plugins/sandbox-linux/seccomp.d.ts +2 -0
- package/dist-lib/plugins/sandbox-linux/seccomp.js +74 -0
- package/dist-lib/plugins/sandbox-macos/index.d.ts +25 -11
- package/dist-lib/plugins/sandbox-macos/index.js +244 -49
- package/dist-lib/plugins/sandbox-vm/index.d.ts +2 -1
- package/dist-lib/plugins/sandbox-vm/index.js +5 -2
- package/dist-lib/plugins/sandbox-vm/vm-shell.d.ts +7 -3
- package/dist-lib/plugins/sandbox-vm/vm-shell.js +54 -20
- package/dist-lib/plugins/sandbox-windows/helper/qvac-sandbox.c +554 -0
- package/dist-lib/plugins/sandbox-windows/index.d.ts +53 -0
- package/dist-lib/plugins/sandbox-windows/index.js +205 -0
- package/dist-lib/plugins/sandbox-windows/prebuilds/win32-arm64/qvac-sandbox.exe +0 -0
- package/dist-lib/plugins/sandbox-windows/prebuilds/win32-x64/qvac-sandbox.exe +0 -0
- package/dist-lib/plugins/speech/audio-resample.d.ts +1 -1
- package/dist-lib/plugins/speech/audio-resample.js +8 -8
- package/dist-lib/plugins/speech/audio-transcode-bare.d.ts +1 -1
- package/dist-lib/plugins/speech/audio-transcode-bare.js +23 -26
- package/dist-lib/plugins/speech/audio-transcode-node.d.ts +1 -1
- package/dist-lib/plugins/speech/audio-transcode-node.js +1 -3
- package/dist-lib/plugins/speech/index.d.ts +1 -0
- package/dist-lib/plugins/speech/index.js +8 -1
- package/dist-lib/plugins/speech/speech-engine.d.ts +1 -1
- package/dist-lib/plugins/speech/speech-engine.js +10 -5
- package/dist-lib/plugins/speech/speech-runtime.js +37 -37
- package/dist-lib/plugins/speech/speech-text.d.ts +1 -0
- package/dist-lib/plugins/speech/speech-text.js +9 -4
- package/dist-lib/plugins/speech/voice.d.ts +5 -1
- package/dist-lib/plugins/speech/voice.js +107 -33
- package/dist-lib/plugins/translation/index.d.ts +2 -1
- package/dist-lib/plugins/translation/index.js +21 -10
- package/dist-lib/plugins/translation/translate.d.ts +9 -5
- package/dist-lib/plugins/translation/translate.js +69 -64
- package/dist-lib/plugins/walkie-talkie/index.d.ts +4 -2
- package/dist-lib/plugins/walkie-talkie/index.js +19 -6
- package/dist-lib/plugins/walkie-talkie/wire.d.ts +5 -0
- package/dist-lib/plugins/walkie-talkie/wire.js +6 -5
- package/dist-lib/plugins/weather/geocode.js +2 -1
- package/dist-lib/plugins/weather/lookup.js +6 -4
- package/dist-lib/plugins/web-search/engines/bing.js +2 -1
- package/dist-lib/plugins/web-search/engines/google.js +2 -1
- package/dist-lib/plugins/web-search/fetch-html.d.ts +5 -5
- package/dist-lib/plugins/web-search/fetch-html.js +12 -15
- package/dist-lib/plugins/web-search/tool.js +1 -0
- package/dist-lib/schema/generate.js +8 -1
- package/dist-lib/schema/harness.js +91 -12
- package/dist-lib/spec/bind.js +12 -0
- package/dist-lib/spec/calls.js +4 -0
- package/dist-lib/spec/hrpc/hrpc.json +55 -3
- package/dist-lib/spec/hrpc/index.js +58 -10
- package/dist-lib/spec/hrpc/messages.js +461 -209
- package/dist-lib/spec/hyperschema/index.js +461 -209
- package/dist-lib/spec/hyperschema/schema.json +285 -85
- package/dist-lib/spec/hyperschema/types.d.ts +41 -5
- package/package.json +264 -64
- package/patches/pyodide@314.0.2.patch +37 -8
- package/scripts/addon-externals.cjs +16 -5
- package/worker/harness-sidecar.mjs +23 -154
- package/dist-lib/lib/tools/create-documents.d.ts +0 -3
- package/dist-lib/lib/tools/create-documents.js +0 -95
- package/dist-lib/lib/tools/edit-documents.d.ts +0 -3
- package/dist-lib/lib/tools/edit-documents.js +0 -132
- package/dist-lib/lib/tools/exec/shell-argv.d.ts +0 -2
- package/dist-lib/lib/tools/exec/shell-argv.js +0 -61
- package/dist-lib/lib/tools/file-glob.js +0 -118
- package/dist-lib/lib/tools/grep.d.ts +0 -5
- package/dist-lib/lib/tools/grep.js +0 -184
- package/dist-lib/lib/tools/read-files.d.ts +0 -5
- package/dist-lib/lib/tools/read-files.js +0 -160
- package/dist-lib/plugins/coding/write-file.d.ts +0 -3
- package/dist-lib/plugins/coding/write-file.js +0 -52
- package/patches/@qvac%2Finference@0.21.0.patch +0 -67
- package/patches/bare-stow@0.1.5.patch +0 -68
- package/patches/hypercore-blob-server@1.15.0.patch +0 -15
- package/patches/localwatch@1.4.3.patch +0 -13
|
@@ -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,224 @@
|
|
|
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 MAX_DOCUMENT_BYTES = 8 * 1024 * 1024;
|
|
8
|
+
const READ_LINES = 400;
|
|
9
|
+
const READ_CHARS = 20_000;
|
|
10
|
+
const BINARY_PROBE = 1024;
|
|
11
|
+
const LINE_BYTES = 3 * READ_CHARS + 4;
|
|
12
|
+
export function createReadFileTool({ realpath = defaultRealpath, deniedRoots } = {}) {
|
|
13
|
+
return {
|
|
14
|
+
name: 'read_file',
|
|
15
|
+
toolset: 'files',
|
|
16
|
+
description: 'Read one file from the shared folder. Lines come back numbered ("12| text"). For a long file, ' +
|
|
17
|
+
'read a range with startLine/endLine; partial reads may show an unknown total. PDF, Word and PowerPoint files come back as their text. ' +
|
|
18
|
+
'Use this, not exec, for files in the shared folder.',
|
|
19
|
+
parameters: {
|
|
20
|
+
type: 'object',
|
|
21
|
+
properties: {
|
|
22
|
+
path: { type: 'string', description: 'File path, relative to the shared folder' },
|
|
23
|
+
startLine: { type: 'integer', description: 'First line to read (1-based, optional)' },
|
|
24
|
+
endLine: { type: 'integer', description: 'Last line to read (optional)' }
|
|
25
|
+
},
|
|
26
|
+
required: ['path']
|
|
27
|
+
},
|
|
28
|
+
effect: () => 'read',
|
|
29
|
+
concurrent: true,
|
|
30
|
+
stableRead: true,
|
|
31
|
+
autoApprove: true,
|
|
32
|
+
rootsRequired: true,
|
|
33
|
+
validate: (args) => (stringArg(args, 'path') ? null : 'path is required'),
|
|
34
|
+
paths: (args, ctx) => rootedArgs(args, ctx, ['path']),
|
|
35
|
+
resource(args, ctx) {
|
|
36
|
+
const requested = stringArg(args, 'path');
|
|
37
|
+
return requested ? { kind: 'file', label: rootedPath(requested, anchorOf(ctx)) } : null;
|
|
38
|
+
},
|
|
39
|
+
async execute(args, ctx) {
|
|
40
|
+
const requested = String(args.path);
|
|
41
|
+
const spill = ctx?.spill ? await createLocalRoots([ctx.spill.dir], realpath) : [];
|
|
42
|
+
const own = spill.length ? await resolveKey(requested, spill, { realpath }) : null;
|
|
43
|
+
const resolved = own && !('error' in own)
|
|
44
|
+
? own
|
|
45
|
+
: await resolveRooted(requested, { grants: ctx, write: false, realpath, deniedRoots });
|
|
46
|
+
if ('error' in resolved) {
|
|
47
|
+
return resolved;
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
const range = {
|
|
51
|
+
start: positiveInt(args.startLine),
|
|
52
|
+
end: positiveInt(args.endLine)
|
|
53
|
+
};
|
|
54
|
+
if (isDocument(resolved.key)) {
|
|
55
|
+
const text = await documentOf(resolved, requested, ctx);
|
|
56
|
+
return typeof text === 'string' ? numbered(text, range) : text;
|
|
57
|
+
}
|
|
58
|
+
return await textRange(resolved, requested, range);
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
return { error: errorMessage(err) };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
async function documentOf(resolved, requested, ctx) {
|
|
67
|
+
const { drive } = resolved.root;
|
|
68
|
+
const entry = await drive.entry(resolved.key);
|
|
69
|
+
if (entry?.value.blob && entry.value.blob.byteLength > MAX_DOCUMENT_BYTES) {
|
|
70
|
+
return {
|
|
71
|
+
error: `${requested} is larger than the ${MAX_DOCUMENT_BYTES}-byte document extraction limit`
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
const bytes = entry ? await drive.get(resolved.key) : null;
|
|
75
|
+
if (bytes === null) {
|
|
76
|
+
return { error: `no such file: ${requested}. Use list_dir or glob to find the right path.` };
|
|
77
|
+
}
|
|
78
|
+
if (bytes.byteLength > MAX_DOCUMENT_BYTES) {
|
|
79
|
+
return {
|
|
80
|
+
error: `${requested} is larger than the ${MAX_DOCUMENT_BYTES}-byte document extraction limit`
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
return documentText(resolved.key, bytes, { ocr: ctx?.ocr, signal: ctx?.signal });
|
|
84
|
+
}
|
|
85
|
+
function numbered(text, { start, end }) {
|
|
86
|
+
const lines = text.split('\n');
|
|
87
|
+
if (lines.length > 1 && lines[lines.length - 1] === '') {
|
|
88
|
+
lines.pop();
|
|
89
|
+
}
|
|
90
|
+
const total = lines.length;
|
|
91
|
+
const first = Math.min(start ?? 1, Math.max(total, 1));
|
|
92
|
+
const out = [];
|
|
93
|
+
let chars = 0;
|
|
94
|
+
let cut = false;
|
|
95
|
+
for (let n = first; n <= Math.min(total, end ?? first + READ_LINES - 1); n++) {
|
|
96
|
+
const row = `${n}| ${lines[n - 1]}`;
|
|
97
|
+
if (chars + row.length > READ_CHARS) {
|
|
98
|
+
cut = out.length === 0;
|
|
99
|
+
if (cut) {
|
|
100
|
+
out.push(row.slice(0, READ_CHARS));
|
|
101
|
+
}
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
out.push(row);
|
|
105
|
+
chars += row.length + 1;
|
|
106
|
+
}
|
|
107
|
+
const last = first + out.length - 1;
|
|
108
|
+
const shown = cut
|
|
109
|
+
? `line ${first} of ${total}, cut at ${READ_CHARS} characters`
|
|
110
|
+
: `lines ${first}-${last} of ${total}`;
|
|
111
|
+
const header = last < total ? `${shown}; continue with startLine ${last + 1}` : shown;
|
|
112
|
+
return { content: `${header}\n${out.join('\n')}` };
|
|
113
|
+
}
|
|
114
|
+
async function textRange(resolved, requested, range) {
|
|
115
|
+
const { drive } = resolved.root;
|
|
116
|
+
if (!(await drive.entry(resolved.key))) {
|
|
117
|
+
return { error: `no such file: ${requested}. Use list_dir or glob to find the right path.` };
|
|
118
|
+
}
|
|
119
|
+
const reader = new TextRange(range);
|
|
120
|
+
let probed = 0;
|
|
121
|
+
for await (const chunk of drive.createReadStream(resolved.key)) {
|
|
122
|
+
if (chunk.subarray(0, Math.max(0, BINARY_PROBE - probed)).includes(0)) {
|
|
123
|
+
return { error: `${requested} is a binary file (not text, PDF, Word or PowerPoint)` };
|
|
124
|
+
}
|
|
125
|
+
probed += chunk.length;
|
|
126
|
+
reader.feed(chunk);
|
|
127
|
+
if (reader.stopped) {
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return { content: reader.finish() };
|
|
132
|
+
}
|
|
133
|
+
class TextRange {
|
|
134
|
+
stopped = false;
|
|
135
|
+
#first;
|
|
136
|
+
#last;
|
|
137
|
+
#out = [];
|
|
138
|
+
#shownFirst;
|
|
139
|
+
#chars = 0;
|
|
140
|
+
#cut = false;
|
|
141
|
+
#full = false;
|
|
142
|
+
#lines = 0;
|
|
143
|
+
#line = emptyLine();
|
|
144
|
+
#previous = emptyLine();
|
|
145
|
+
constructor({ start, end }) {
|
|
146
|
+
this.#first = start ?? 1;
|
|
147
|
+
this.#last = end ?? this.#first + READ_LINES - 1;
|
|
148
|
+
this.#shownFirst = this.#first;
|
|
149
|
+
}
|
|
150
|
+
feed(chunk) {
|
|
151
|
+
let at = 0;
|
|
152
|
+
while (!this.stopped) {
|
|
153
|
+
if (this.#full) {
|
|
154
|
+
this.stopped = at < chunk.length;
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const newline = chunk.indexOf(0x0a, at);
|
|
158
|
+
this.#append(chunk.subarray(at, newline === -1 ? chunk.length : newline));
|
|
159
|
+
if (newline !== -1 || (this.#line.cut && this.#lines + 1 >= this.#first)) {
|
|
160
|
+
this.#close();
|
|
161
|
+
}
|
|
162
|
+
if (newline === -1) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
at = newline + 1;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
finish() {
|
|
169
|
+
const eof = !this.stopped;
|
|
170
|
+
if (eof && this.#line.bytes > 0) {
|
|
171
|
+
this.#close();
|
|
172
|
+
}
|
|
173
|
+
if (eof && this.#out.length === 0 && this.#last >= this.#first) {
|
|
174
|
+
this.#shownFirst = Math.max(this.#lines, 1);
|
|
175
|
+
const row = `${this.#shownFirst}| ${lineText(this.#previous)}`;
|
|
176
|
+
this.#out.push(row.slice(0, READ_CHARS));
|
|
177
|
+
this.#cut = this.#previous.cut || row.length > READ_CHARS;
|
|
178
|
+
}
|
|
179
|
+
const total = eof ? String(Math.max(this.#lines, 1)) : 'unknown';
|
|
180
|
+
const lastShown = this.#shownFirst + this.#out.length - 1;
|
|
181
|
+
const shown = this.#cut
|
|
182
|
+
? `line ${this.#shownFirst} of ${total}, cut at ${READ_CHARS} characters`
|
|
183
|
+
: `lines ${this.#shownFirst}-${lastShown} of ${total}`;
|
|
184
|
+
const header = !eof || lastShown < this.#lines ? `${shown}; continue with startLine ${lastShown + 1}` : shown;
|
|
185
|
+
return `${header}\n${this.#out.join('\n')}`;
|
|
186
|
+
}
|
|
187
|
+
#append(bytes) {
|
|
188
|
+
const kept = bytes.subarray(0, LINE_BYTES - this.#line.bytes);
|
|
189
|
+
if (kept.length) {
|
|
190
|
+
this.#line.parts.push(kept);
|
|
191
|
+
}
|
|
192
|
+
this.#line.bytes += kept.length;
|
|
193
|
+
this.#line.cut ||= kept.length < bytes.length;
|
|
194
|
+
}
|
|
195
|
+
#close() {
|
|
196
|
+
this.#lines++;
|
|
197
|
+
this.#previous = this.#line;
|
|
198
|
+
this.#line = emptyLine();
|
|
199
|
+
if (this.#lines < this.#first) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const row = `${this.#lines}| ${lineText(this.#previous)}`;
|
|
203
|
+
if (this.#out.length === 0) {
|
|
204
|
+
this.#shownFirst = this.#lines;
|
|
205
|
+
}
|
|
206
|
+
if (this.#chars + row.length > READ_CHARS) {
|
|
207
|
+
this.#cut = this.#out.length === 0;
|
|
208
|
+
if (this.#cut) {
|
|
209
|
+
this.#out.push(row.slice(0, READ_CHARS));
|
|
210
|
+
}
|
|
211
|
+
this.stopped = true;
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
this.#out.push(row);
|
|
215
|
+
this.#chars += row.length + 1;
|
|
216
|
+
this.#full = this.#lines === this.#last;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
function emptyLine() {
|
|
220
|
+
return { parts: [], bytes: 0, cut: false };
|
|
221
|
+
}
|
|
222
|
+
function lineText(line) {
|
|
223
|
+
return b4a.toString(b4a.concat(line.parts), 'utf8');
|
|
224
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -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,8 @@
|
|
|
1
|
+
import type { AbortSignal as BareAbortSignal } from 'bare-abort-controller';
|
|
2
|
+
import type { OcrService } from '../../contract/ocr.ts';
|
|
3
|
+
export declare function isDocument(key: string): boolean;
|
|
4
|
+
export interface DocumentTextOptions {
|
|
5
|
+
readonly ocr?: OcrService | undefined;
|
|
6
|
+
readonly signal?: BareAbortSignal | undefined;
|
|
7
|
+
}
|
|
8
|
+
export declare function documentText(key: string, bytes: Uint8Array, { ocr, signal }?: DocumentTextOptions): Promise<string>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { docx, pptx } from '../../office/engine/index.js';
|
|
2
|
+
import { pdfPages } from '../pdf/pages.js';
|
|
3
|
+
export function isDocument(key) {
|
|
4
|
+
return /\.(pdf|docx|pptx)$/i.test(key);
|
|
5
|
+
}
|
|
6
|
+
export async function documentText(key, bytes, { ocr, signal } = {}) {
|
|
7
|
+
if (!/\.pdf$/i.test(key)) {
|
|
8
|
+
const read = /\.docx$/i.test(key) ? docx.open(bytes).read() : pptx.open(bytes).read();
|
|
9
|
+
return collectText(read).join('\n');
|
|
10
|
+
}
|
|
11
|
+
const pages = await pdfPages(bytes, { ocr, signal });
|
|
12
|
+
return pages.map(({ page, text }) => `--- page ${page} ---\n${text}`).join('\n');
|
|
13
|
+
}
|
|
14
|
+
function collectText(value) {
|
|
15
|
+
if (Array.isArray(value)) {
|
|
16
|
+
return value.flatMap(collectText);
|
|
17
|
+
}
|
|
18
|
+
if (typeof value !== 'object' || value === null) {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
return Object.entries(value).flatMap(([key, inner]) => key === 'text' && typeof inner === 'string' ? [inner] : collectText(inner));
|
|
22
|
+
}
|