@qvac/harness 1.0.0-rc.9 → 1.0.1
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/CHANGELOG.md +701 -7
- package/NOTICE.md +0 -16
- package/README.md +46 -5
- package/dist-lib/index.d.ts +23 -16
- package/dist-lib/index.js +127 -23
- package/dist-lib/lib/agent/delegate.d.ts +1 -0
- package/dist-lib/lib/agent/delegate.js +10 -9
- package/dist-lib/lib/agent/follow.d.ts +1 -0
- package/dist-lib/lib/agent/follow.js +12 -2
- package/dist-lib/lib/agent/resolve.js +11 -3
- package/dist-lib/lib/agent/tools.d.ts +1 -0
- package/dist-lib/lib/agent/tools.js +1 -1
- package/dist-lib/lib/capabilities/agent-ports.d.ts +1 -1
- package/dist-lib/lib/capabilities/agent-ports.js +8 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/answering.js +2 -2
- package/dist-lib/lib/capabilities/completion-engine/actors/direct-search.js +1 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/execute.d.ts +1 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/executing.d.ts +2 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/executing.js +79 -9
- package/dist-lib/lib/capabilities/completion-engine/actors/execution-plan.js +12 -4
- package/dist-lib/lib/capabilities/completion-engine/actors/inspect-prepare.js +1 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/inspecting.d.ts +1 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/inspecting.js +13 -8
- package/dist-lib/lib/capabilities/completion-engine/actors/loading-skill.js +3 -2
- package/dist-lib/lib/capabilities/completion-engine/actors/preparing.js +47 -22
- package/dist-lib/lib/capabilities/completion-engine/actors/rejecting.js +5 -4
- package/dist-lib/lib/capabilities/completion-engine/actors/resolving.js +10 -4
- package/dist-lib/lib/capabilities/completion-engine/actors/retrieving.d.ts +2 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/retrieving.js +19 -11
- package/dist-lib/lib/capabilities/completion-engine/actors/run-prepare.js +38 -23
- package/dist-lib/lib/capabilities/completion-engine/actors/skill-step.js +31 -10
- package/dist-lib/lib/capabilities/completion-engine/actors/stream.d.ts +5 -3
- package/dist-lib/lib/capabilities/completion-engine/actors/stream.js +61 -7
- package/dist-lib/lib/capabilities/completion-engine/actors/streaming.js +41 -16
- package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.js +26 -10
- package/dist-lib/lib/capabilities/completion-engine/actors.d.ts +1 -0
- package/dist-lib/lib/capabilities/completion-engine/actors.js +8 -8
- package/dist-lib/lib/capabilities/completion-engine/driver.d.ts +0 -1
- package/dist-lib/lib/capabilities/completion-engine/driver.js +30 -6
- package/dist-lib/lib/capabilities/completion-engine/durable.d.ts +2 -1
- package/dist-lib/lib/capabilities/completion-engine/durable.js +7 -1
- package/dist-lib/lib/capabilities/completion-engine/engine.d.ts +2 -0
- package/dist-lib/lib/capabilities/completion-engine/engine.js +35 -15
- package/dist-lib/lib/capabilities/completion-engine/index.d.ts +0 -1
- package/dist-lib/lib/capabilities/completion-engine/loop.d.ts +13 -3
- package/dist-lib/lib/capabilities/completion-engine/loop.js +7 -2
- package/dist-lib/lib/capabilities/completion-engine/model-round.d.ts +4 -1
- package/dist-lib/lib/capabilities/completion-engine/model-round.js +2 -0
- package/dist-lib/lib/capabilities/completion-engine/operations.js +29 -9
- package/dist-lib/lib/capabilities/completion-engine/ports.d.ts +1 -0
- package/dist-lib/lib/capabilities/completion-engine/ports.js +6 -4
- package/dist-lib/lib/capabilities/completion-engine/prepare-step.d.ts +4 -1
- package/dist-lib/lib/capabilities/completion-engine/round.d.ts +14 -0
- package/dist-lib/lib/capabilities/completion-engine/round.js +102 -47
- package/dist-lib/lib/capabilities/completion-engine/session.d.ts +5 -3
- package/dist-lib/lib/capabilities/completion-engine/session.js +1 -0
- package/dist-lib/lib/capabilities/completion-engine/tool-caller.js +3 -1
- package/dist-lib/lib/capabilities/completion-engine/tool-execution.d.ts +5 -41
- package/dist-lib/lib/capabilities/completion-engine/tool-execution.js +21 -135
- package/dist-lib/lib/capabilities/completion-engine/tool-outcome.d.ts +4 -0
- package/dist-lib/lib/capabilities/completion-engine/tool-outcome.js +40 -0
- package/dist-lib/lib/capabilities/completion-engine/tool-preflight.d.ts +43 -0
- package/dist-lib/lib/capabilities/completion-engine/tool-preflight.js +91 -0
- package/dist-lib/lib/capabilities/completion-engine/transition-log.d.ts +14 -0
- package/dist-lib/lib/capabilities/completion-engine/transition-log.js +44 -0
- package/dist-lib/lib/capabilities/completion-engine/turns.d.ts +4 -0
- package/dist-lib/lib/capabilities/completion-engine/turns.js +36 -8
- package/dist-lib/lib/capabilities/enhance.js +3 -3
- package/dist-lib/lib/capabilities/kv-cache.js +11 -3
- package/dist-lib/lib/capabilities/prefix-template.d.ts +34 -0
- package/dist-lib/lib/capabilities/prefix-template.js +175 -0
- package/dist-lib/lib/capabilities/prompt-prefix.d.ts +2 -0
- package/dist-lib/lib/capabilities/prompt-prefix.js +8 -0
- package/dist-lib/lib/capabilities/sdk-tool.d.ts +4 -4
- package/dist-lib/lib/capabilities/sdk-tool.js +22 -6
- 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-turns/answered.d.ts +15 -0
- package/dist-lib/lib/capabilities/tool-turns/answered.js +16 -0
- package/dist-lib/lib/capabilities/tool-turns/attachments.d.ts +7 -0
- package/dist-lib/lib/capabilities/tool-turns/attachments.js +39 -0
- package/dist-lib/lib/capabilities/tool-turns/copy.d.ts +13 -0
- package/dist-lib/lib/capabilities/tool-turns/copy.js +29 -0
- package/dist-lib/lib/capabilities/tool-turns/result-turn.d.ts +22 -0
- package/dist-lib/lib/capabilities/tool-turns/result-turn.js +120 -0
- package/dist-lib/lib/capabilities/tool-turns/run-limits.d.ts +6 -0
- package/dist-lib/lib/capabilities/tool-turns/run-limits.js +32 -0
- package/dist-lib/lib/capabilities/tool-turns/skill-loads.d.ts +9 -0
- package/dist-lib/lib/capabilities/tool-turns/skill-loads.js +71 -0
- package/dist-lib/lib/capabilities/tool-turns.d.ts +10 -43
- package/dist-lib/lib/capabilities/tool-turns.js +7 -262
- 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.js +6 -5
- package/dist-lib/lib/connect/abort.d.ts +6 -0
- package/dist-lib/lib/connect/abort.js +52 -0
- package/dist-lib/lib/connect/bridges.d.ts +21 -0
- package/dist-lib/lib/connect/bridges.js +185 -0
- package/dist-lib/lib/connect/decode.d.ts +31 -0
- package/dist-lib/lib/connect/decode.js +114 -0
- package/dist-lib/lib/connect/host-run-log.d.ts +20 -0
- package/dist-lib/lib/connect/host-run-log.js +89 -0
- package/dist-lib/lib/connect/round-log.d.ts +8 -0
- package/dist-lib/lib/connect/round-log.js +33 -0
- package/dist-lib/lib/connect/served.d.ts +7 -0
- package/dist-lib/lib/connect/served.js +45 -0
- package/dist-lib/lib/connect.d.ts +5 -1
- package/dist-lib/lib/connect.js +102 -444
- package/dist-lib/lib/context-window.d.ts +13 -6
- package/dist-lib/lib/context-window.js +18 -5
- package/dist-lib/lib/contract/agent.d.ts +18 -1
- package/dist-lib/lib/contract/completion.d.ts +35 -3
- package/dist-lib/lib/contract/drive.d.ts +154 -4
- package/dist-lib/lib/contract/exec.d.ts +1 -0
- package/dist-lib/lib/contract/index.d.ts +1 -0
- package/dist-lib/lib/contract/knowledge.d.ts +10 -0
- package/dist-lib/lib/contract/media.d.ts +58 -0
- package/dist-lib/lib/contract/models.d.ts +6 -2
- package/dist-lib/lib/contract/ocr.d.ts +17 -0
- package/dist-lib/lib/contract/ocr.js +1 -0
- package/dist-lib/lib/contract/root-search.d.ts +34 -0
- package/dist-lib/lib/contract/root-search.js +1 -0
- package/dist-lib/lib/contract/run.d.ts +13 -0
- package/dist-lib/lib/contract-types.d.ts +10 -2
- package/dist-lib/lib/docx/index.js +1 -1
- package/dist-lib/lib/errors.d.ts +8 -4
- package/dist-lib/lib/errors.js +12 -8
- package/dist-lib/lib/fold/index.d.ts +4 -2
- package/dist-lib/lib/fold/index.js +15 -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/gpu-probe-addon.js +26 -11
- package/dist-lib/lib/hardware/gpu-stats.native.cjs +17 -1
- package/dist-lib/lib/helpers/completion-params.d.ts +2 -1
- package/dist-lib/lib/helpers/completion-params.js +18 -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/drain.d.ts +1 -1
- package/dist-lib/lib/helpers/drain.js +1 -1
- package/dist-lib/lib/helpers/goal-check/asks.d.ts +25 -0
- package/dist-lib/lib/helpers/goal-check/asks.js +52 -0
- package/dist-lib/lib/helpers/goal-check/checks.d.ts +8 -0
- package/dist-lib/lib/helpers/goal-check/checks.js +92 -0
- package/dist-lib/lib/helpers/goal-check/commands.d.ts +7 -0
- package/dist-lib/lib/helpers/goal-check/commands.js +130 -0
- package/dist-lib/lib/helpers/goal-check/paths.d.ts +5 -0
- package/dist-lib/lib/helpers/goal-check/paths.js +44 -0
- package/dist-lib/lib/helpers/goal-check/shell.d.ts +9 -0
- package/dist-lib/lib/helpers/goal-check/shell.js +96 -0
- package/dist-lib/lib/helpers/goal-check.d.ts +36 -6
- package/dist-lib/lib/helpers/goal-check.js +34 -98
- package/dist-lib/lib/helpers/html-helpers.js +9 -6
- package/dist-lib/lib/helpers/recent-map.d.ts +7 -0
- package/dist-lib/lib/helpers/recent-map.js +23 -0
- package/dist-lib/lib/helpers/repeated-reply.js +9 -2
- package/dist-lib/lib/helpers/root-search.d.ts +3 -0
- package/dist-lib/lib/helpers/root-search.js +74 -0
- package/dist-lib/lib/helpers/run-latency.d.ts +14 -0
- package/dist-lib/lib/helpers/run-latency.js +63 -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/stable-stringify.js +10 -2
- package/dist-lib/lib/helpers/text-coalescer.d.ts +6 -0
- package/dist-lib/lib/helpers/text-coalescer.js +44 -4
- package/dist-lib/lib/helpers/tool-call-markup/emit.d.ts +6 -0
- package/dist-lib/lib/helpers/tool-call-markup/emit.js +15 -0
- package/dist-lib/lib/helpers/tool-call-markup/recover.d.ts +22 -0
- package/dist-lib/lib/helpers/tool-call-markup/recover.js +130 -0
- package/dist-lib/lib/helpers/tool-call-markup/skill-recovery.d.ts +3 -0
- package/dist-lib/lib/helpers/tool-call-markup/skill-recovery.js +56 -0
- package/dist-lib/lib/helpers/tool-call-markup/strip.d.ts +4 -0
- package/dist-lib/lib/helpers/tool-call-markup/strip.js +157 -0
- package/dist-lib/lib/helpers/tool-call-markup.d.ts +19 -24
- package/dist-lib/lib/helpers/tool-call-markup.js +17 -343
- package/dist-lib/lib/lifecycle/completion-run.js +2 -2
- package/dist-lib/lib/log.d.ts +3 -0
- package/dist-lib/lib/log.js +17 -1
- package/dist-lib/lib/machine/completion/actions/completion.d.ts +13 -16
- package/dist-lib/lib/machine/completion/actions/completion.js +110 -138
- package/dist-lib/lib/machine/completion/actions/goal.d.ts +10 -0
- package/dist-lib/lib/machine/completion/actions/goal.js +93 -0
- package/dist-lib/lib/machine/completion/actions/prepare.js +2 -1
- package/dist-lib/lib/machine/completion/actions/reject-tool.d.ts +16 -0
- package/dist-lib/lib/machine/completion/actions/reject-tool.js +147 -0
- package/dist-lib/lib/machine/completion/actions/retry-round.d.ts +6 -0
- package/dist-lib/lib/machine/completion/actions/retry-round.js +50 -0
- package/dist-lib/lib/machine/completion/actions/rounds.d.ts +5 -0
- package/dist-lib/lib/machine/completion/actions/rounds.js +31 -0
- package/dist-lib/lib/machine/completion/actions/tools.d.ts +1 -16
- package/dist-lib/lib/machine/completion/actions/tools.js +73 -151
- package/dist-lib/lib/machine/completion/context.js +6 -1
- package/dist-lib/lib/machine/completion/guards/retry.d.ts +2 -1
- package/dist-lib/lib/machine/completion/guards/retry.js +4 -3
- package/dist-lib/lib/machine/completion/implementations.d.ts +8 -5
- package/dist-lib/lib/machine/completion/implementations.js +22 -7
- package/dist-lib/lib/machine/completion/machine.d.ts +15 -6
- package/dist-lib/lib/machine/completion/machine.js +25 -5
- package/dist-lib/lib/machine/completion/metrics.d.ts +25 -0
- package/dist-lib/lib/machine/completion/metrics.js +70 -0
- package/dist-lib/lib/machine/completion/nudges.d.ts +5 -0
- package/dist-lib/lib/machine/completion/nudges.js +33 -0
- package/dist-lib/lib/machine/completion/rules.d.ts +10 -33
- package/dist-lib/lib/machine/completion/rules.js +27 -103
- package/dist-lib/lib/machine/completion/splice.d.ts +9 -0
- package/dist-lib/lib/machine/completion/splice.js +19 -0
- package/dist-lib/lib/machine/completion/types.d.ts +37 -13
- package/dist-lib/lib/machine/index.d.ts +21 -7
- package/dist-lib/lib/machine/index.js +7 -2
- 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.js +8 -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/gguf-header.d.ts +6 -0
- package/dist-lib/lib/models/gguf-header.js +38 -1
- 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.js +27 -1
- 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/model-catalog-constants.d.ts +3 -2
- package/dist-lib/lib/models/model-catalog-constants.js +8 -5
- package/dist-lib/lib/models/model-catalog.d.ts +12 -3
- package/dist-lib/lib/models/model-catalog.js +40 -16
- package/dist-lib/lib/models/model-delete.js +3 -0
- package/dist-lib/lib/models/model-handle.d.ts +1 -0
- package/dist-lib/lib/models/model-list.d.ts +2 -1
- package/dist-lib/lib/models/model-list.js +5 -1
- package/dist-lib/lib/models/model-pool.d.ts +7 -1
- package/dist-lib/lib/models/model-pool.js +34 -13
- 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-impl.d.ts +2 -1
- package/dist-lib/lib/no-redirect-fetch-impl.js +45 -8
- package/dist-lib/lib/office/index.js +1 -1
- package/dist-lib/lib/plugins/registry.d.ts +12 -0
- package/dist-lib/lib/plugins/registry.js +71 -15
- 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/prompt.d.ts +7 -4
- package/dist-lib/lib/prompt.js +81 -24
- package/dist-lib/lib/residency/completion-runtime.d.ts +8 -6
- package/dist-lib/lib/residency/completion-runtime.js +53 -9
- package/dist-lib/lib/residency/index.d.ts +12 -3
- package/dist-lib/lib/residency/index.js +52 -16
- package/dist-lib/lib/round-host.js +3 -3
- package/dist-lib/lib/round-port.js +3 -3
- package/dist-lib/lib/run-log/boundary.d.ts +1 -4
- package/dist-lib/lib/run-log/boundary.js +4 -21
- package/dist-lib/lib/run-log/history-codec.d.ts +1 -1
- package/dist-lib/lib/run-log/history-codec.js +3 -3
- package/dist-lib/lib/run-log/protocol.js +17 -16
- package/dist-lib/lib/run-log/redact.d.ts +10 -1
- package/dist-lib/lib/run-log/redact.js +99 -9
- package/dist-lib/lib/run-log/request-codec.d.ts +3 -0
- package/dist-lib/lib/run-log/request-codec.js +19 -4
- package/dist-lib/lib/run-log/run-journal.js +1 -1
- package/dist-lib/lib/sdk-loader.d.ts +1 -0
- package/dist-lib/lib/sdk-loader.js +14 -0
- package/dist-lib/lib/serve/completion.d.ts +7 -0
- package/dist-lib/lib/serve/completion.js +571 -0
- package/dist-lib/lib/serve/downloads.d.ts +4 -0
- package/dist-lib/lib/serve/downloads.js +79 -0
- package/dist-lib/lib/serve/models.d.ts +5 -0
- package/dist-lib/lib/serve/models.js +120 -0
- package/dist-lib/lib/serve/noop.d.ts +1 -0
- package/dist-lib/lib/serve/noop.js +1 -0
- package/dist-lib/lib/serve/requests.d.ts +148 -0
- package/dist-lib/lib/serve/requests.js +1 -0
- package/dist-lib/lib/serve/rounds.d.ts +11 -0
- package/dist-lib/lib/serve/rounds.js +67 -0
- package/dist-lib/lib/serve/run-log-start.d.ts +37 -0
- package/dist-lib/lib/serve/run-log-start.js +253 -0
- package/dist-lib/lib/serve/skills.d.ts +32 -0
- package/dist-lib/lib/serve/skills.js +46 -0
- package/dist-lib/lib/serve.d.ts +5 -1
- package/dist-lib/lib/serve.js +23 -995
- package/dist-lib/lib/sidecar/index.d.ts +1 -1
- package/dist-lib/lib/sidecar/index.js +11 -19
- package/dist-lib/lib/sidecar/user-plugins.js +6 -4
- package/dist-lib/lib/skills-host/index.d.ts +6 -3
- package/dist-lib/lib/skills-host/index.js +39 -18
- package/dist-lib/lib/spawn.d.ts +14 -0
- package/dist-lib/lib/spawn.js +9 -5
- 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 +18 -22
- package/dist-lib/lib/tools/exec/runner.d.ts +4 -0
- package/dist-lib/lib/tools/exec/runner.js +20 -3
- package/dist-lib/lib/tools/exec/shell-guidance.d.ts +2 -0
- package/dist-lib/lib/tools/exec/shell-guidance.js +29 -0
- package/dist-lib/lib/tools/exec.js +4 -2
- package/dist-lib/lib/tools/files/edit-file.d.ts +4 -1
- package/dist-lib/lib/tools/files/edit-file.js +220 -28
- package/dist-lib/lib/tools/files/glob.js +72 -11
- package/dist-lib/lib/tools/files/grep.js +65 -22
- package/dist-lib/lib/tools/files/index.js +3 -1
- package/dist-lib/lib/tools/files/read-file.js +199 -36
- package/dist-lib/lib/tools/fs/document-text.d.ts +7 -1
- package/dist-lib/lib/tools/fs/document-text.js +5 -21
- package/dist-lib/lib/tools/fs/drive.d.ts +1 -17
- package/dist-lib/lib/tools/fs/edit-match.d.ts +22 -0
- package/dist-lib/lib/tools/fs/edit-match.js +337 -45
- package/dist-lib/lib/tools/fs/engine.d.ts +9 -0
- package/dist-lib/lib/tools/fs/engine.js +28 -0
- package/dist-lib/lib/tools/fs/remote-protocol.d.ts +1 -81
- package/dist-lib/lib/tools/fs/scope.d.ts +2 -17
- package/dist-lib/lib/tools/fs/search.d.ts +2 -18
- package/dist-lib/lib/tools/fs/suggest.d.ts +8 -0
- package/dist-lib/lib/tools/fs/suggest.js +110 -0
- package/dist-lib/lib/tools/fs/tool-path.d.ts +3 -0
- package/dist-lib/lib/tools/fs/tool-path.js +13 -0
- package/dist-lib/lib/tools/fs/walk.d.ts +5 -5
- package/dist-lib/lib/tools/fs/walk.js +22 -21
- 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 +93 -14
- package/dist-lib/lib/tools/index.d.ts +3 -1
- package/dist-lib/lib/tools/index.js +6 -2
- 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 +3 -2
- package/dist-lib/lib/tools/office.js +200 -39
- 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 +13 -3
- package/dist-lib/lib/tools/pdf/build.js +52 -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 +55 -0
- package/dist-lib/lib/tools/pdf/request.d.ts +3 -8
- package/dist-lib/lib/tools/pdf/request.js +4 -4
- package/dist-lib/lib/tools/pdf.d.ts +0 -1
- package/dist-lib/lib/tools/pdf.js +42 -14
- package/dist-lib/lib/tools/skill.js +13 -4
- package/dist-lib/lib/tools/skills/bundled-dir.d.ts +8 -1
- package/dist-lib/lib/tools/skills/bundled-dir.js +38 -32
- package/dist-lib/lib/tools/skills/bundled-hash.d.ts +1 -0
- package/dist-lib/lib/tools/skills/bundled-hash.js +4 -1
- package/dist-lib/lib/tools/skills/catalog-loader.d.ts +12 -0
- package/dist-lib/lib/tools/skills/catalog-loader.js +173 -0
- package/dist-lib/lib/tools/skills/catalog.d.ts +5 -8
- package/dist-lib/lib/tools/skills/catalog.js +1 -162
- 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/index.d.ts +1 -0
- package/dist-lib/lib/tools/skills/index.js +1 -0
- package/dist-lib/lib/tools/skills/manifest-parse.js +27 -3
- package/dist-lib/lib/tools/skills/manifest.d.ts +1 -0
- package/dist-lib/lib/tools/skills/overlay-crud.d.ts +3 -3
- package/dist-lib/lib/tools/skills/overlay-crud.js +4 -4
- 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-tree.d.ts +5 -0
- package/dist-lib/lib/tools/skills/skill-tree.js +54 -0
- package/dist-lib/lib/tools/tls-failure.d.ts +1 -0
- package/dist-lib/lib/tools/tls-failure.js +8 -0
- package/dist-lib/lib/tools/toolsets.d.ts +1 -1
- package/dist-lib/lib/tools/toolsets.js +2 -0
- package/dist-lib/lib/tools/web-fetch.js +46 -130
- package/dist-lib/lib/wire/download.d.ts +10 -0
- package/dist-lib/lib/wire/download.js +35 -0
- package/dist-lib/lib/wire/event.d.ts +41 -0
- package/dist-lib/lib/wire/event.js +306 -0
- package/dist-lib/lib/wire/fields.d.ts +3 -0
- package/dist-lib/lib/wire/fields.js +12 -0
- package/dist-lib/lib/wire/knowledge.d.ts +9 -0
- package/dist-lib/lib/wire/knowledge.js +68 -0
- package/dist-lib/lib/wire/round.d.ts +14 -0
- package/dist-lib/lib/wire/round.js +45 -0
- package/dist-lib/lib/wire/vectors.d.ts +6 -0
- package/dist-lib/lib/wire/vectors.js +33 -0
- package/dist-lib/lib/wire.d.ts +28 -77
- package/dist-lib/lib/wire.js +24 -463
- package/dist-lib/plugins/charts/chart-tool.d.ts +8 -0
- package/dist-lib/plugins/charts/chart-tool.js +175 -0
- package/dist-lib/plugins/charts/index.d.ts +16 -0
- package/dist-lib/plugins/charts/index.js +21 -0
- 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/diagrams/draw.d.ts +10 -0
- package/dist-lib/plugins/diagrams/draw.js +90 -0
- package/dist-lib/plugins/diagrams/index.d.ts +13 -0
- package/dist-lib/plugins/diagrams/index.js +15 -0
- package/dist-lib/plugins/diagrams/render.d.ts +16 -0
- package/dist-lib/plugins/diagrams/render.js +285 -0
- package/dist-lib/plugins/image/edit-image.d.ts +3 -22
- package/dist-lib/plugins/image/edit-image.js +20 -44
- 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 +24 -4
- package/dist-lib/plugins/image/generate-image.js +198 -72
- package/dist-lib/plugins/image/index.d.ts +2 -1
- package/dist-lib/plugins/image/index.js +17 -8
- 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/mcp/call.js +15 -4
- package/dist-lib/plugins/mcp/protocol.d.ts +10 -2
- package/dist-lib/plugins/mcp/protocol.js +13 -12
- 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 +21 -4
- package/dist-lib/plugins/music/generate-music.js +168 -65
- package/dist-lib/plugins/music/index.d.ts +2 -1
- package/dist-lib/plugins/music/index.js +11 -6
- package/dist-lib/plugins/obsidian/index.js +14 -4
- package/dist-lib/plugins/ocr/bmp.d.ts +2 -0
- package/dist-lib/plugins/ocr/bmp.js +27 -0
- package/dist-lib/plugins/ocr/coverage.d.ts +3 -0
- package/dist-lib/plugins/ocr/coverage.js +67 -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 +25 -0
- package/dist-lib/plugins/ocr/ocr-runtime.js +103 -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/index.d.ts +4 -1
- package/dist-lib/plugins/python/index.js +5 -1
- package/dist-lib/plugins/python/language.js +11 -10
- package/dist-lib/plugins/python/python-adapter.d.ts +6 -1
- package/dist-lib/plugins/python/python-adapter.js +34 -1
- package/dist-lib/plugins/python/worker/client.js +1 -1
- 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/spawn.js +1 -1
- package/dist-lib/plugins/ripgrep/index.d.ts +15 -0
- package/dist-lib/plugins/ripgrep/index.js +28 -0
- package/dist-lib/plugins/run-report/story.js +4 -1
- package/dist-lib/plugins/sandbox-linux/index.js +2 -2
- package/dist-lib/plugins/sandbox-macos/index.js +2 -2
- package/dist-lib/plugins/sandbox-vm/index.d.ts +2 -1
- package/dist-lib/plugins/sandbox-vm/index.js +2 -2
- package/dist-lib/plugins/sandbox-vm/vm-shell.d.ts +3 -1
- package/dist-lib/plugins/sandbox-vm/vm-shell.js +45 -16
- package/dist-lib/plugins/sandbox-windows/index.js +2 -2
- 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/speech-engine.d.ts +1 -1
- package/dist-lib/plugins/speech/speech-engine.js +10 -5
- 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.js +7 -2
- package/dist-lib/plugins/walkie-talkie/index.d.ts +2 -0
- package/dist-lib/plugins/walkie-talkie/index.js +6 -1
- package/dist-lib/plugins/weather/lookup.js +1 -0
- package/dist-lib/schema/baseline.d.ts +2 -1
- package/dist-lib/schema/baseline.js +2 -2
- package/dist-lib/schema/generate.js +8 -1
- package/dist-lib/schema/harness.js +34 -5
- package/dist-lib/schema/release-tags.d.ts +2 -1
- package/dist-lib/schema/release-tags.js +9 -10
- package/dist-lib/spec/bind.js +3 -0
- package/dist-lib/spec/calls.js +1 -0
- package/dist-lib/spec/hrpc/hrpc.json +13 -0
- package/dist-lib/spec/hrpc/index.js +15 -3
- package/dist-lib/spec/hrpc/messages.js +126 -13
- package/dist-lib/spec/hyperschema/index.js +126 -13
- package/dist-lib/spec/hyperschema/schema.json +86 -2
- package/dist-lib/spec/hyperschema/types.d.ts +18 -3
- package/package.json +96 -36
- package/scripts/addon-externals.cjs +7 -1
- package/worker/harness-sidecar.mjs +10 -0
- package/dist-lib/lib/helpers/buffer-burst.d.ts +0 -1
- package/dist-lib/lib/helpers/buffer-burst.js +0 -22
- package/dist-lib/lib/office/engine/codes.d.ts +0 -62
- package/dist-lib/lib/office/engine/codes.js +0 -61
- package/dist-lib/lib/office/engine/docx/document.d.ts +0 -216
- package/dist-lib/lib/office/engine/docx/document.js +0 -1152
- package/dist-lib/lib/office/engine/docx/index.d.ts +0 -7
- package/dist-lib/lib/office/engine/docx/index.js +0 -8
- package/dist-lib/lib/office/engine/docx/styles.d.ts +0 -31
- package/dist-lib/lib/office/engine/docx/styles.js +0 -173
- package/dist-lib/lib/office/engine/docx/template.d.ts +0 -18
- package/dist-lib/lib/office/engine/docx/template.js +0 -133
- package/dist-lib/lib/office/engine/docx/text.d.ts +0 -55
- package/dist-lib/lib/office/engine/docx/text.js +0 -538
- package/dist-lib/lib/office/engine/drawingml/chart.d.ts +0 -63
- package/dist-lib/lib/office/engine/drawingml/chart.js +0 -539
- package/dist-lib/lib/office/engine/drawingml/text.d.ts +0 -35
- package/dist-lib/lib/office/engine/drawingml/text.js +0 -352
- package/dist-lib/lib/office/engine/errors.d.ts +0 -6
- package/dist-lib/lib/office/engine/errors.js +0 -12
- package/dist-lib/lib/office/engine/image.d.ts +0 -8
- package/dist-lib/lib/office/engine/image.js +0 -48
- package/dist-lib/lib/office/engine/index.d.ts +0 -12
- package/dist-lib/lib/office/engine/index.js +0 -7
- package/dist-lib/lib/office/engine/opc/content-types.d.ts +0 -17
- package/dist-lib/lib/office/engine/opc/content-types.js +0 -74
- package/dist-lib/lib/office/engine/opc/media.d.ts +0 -13
- package/dist-lib/lib/office/engine/opc/media.js +0 -11
- package/dist-lib/lib/office/engine/opc/package.d.ts +0 -51
- package/dist-lib/lib/office/engine/opc/package.js +0 -324
- package/dist-lib/lib/office/engine/opc/paths.d.ts +0 -7
- package/dist-lib/lib/office/engine/opc/paths.js +0 -46
- package/dist-lib/lib/office/engine/opc/properties.d.ts +0 -7
- package/dist-lib/lib/office/engine/opc/properties.js +0 -75
- package/dist-lib/lib/office/engine/opc/relationships.d.ts +0 -23
- package/dist-lib/lib/office/engine/opc/relationships.js +0 -65
- package/dist-lib/lib/office/engine/opc/zip.d.ts +0 -15
- package/dist-lib/lib/office/engine/opc/zip.js +0 -264
- package/dist-lib/lib/office/engine/pptx/fit.d.ts +0 -12
- package/dist-lib/lib/office/engine/pptx/fit.js +0 -37
- package/dist-lib/lib/office/engine/pptx/index.d.ts +0 -8
- package/dist-lib/lib/office/engine/pptx/index.js +0 -8
- package/dist-lib/lib/office/engine/pptx/inherit.d.ts +0 -29
- package/dist-lib/lib/office/engine/pptx/inherit.js +0 -155
- package/dist-lib/lib/office/engine/pptx/notes.d.ts +0 -5
- package/dist-lib/lib/office/engine/pptx/notes.js +0 -85
- package/dist-lib/lib/office/engine/pptx/picture-area.d.ts +0 -23
- package/dist-lib/lib/office/engine/pptx/picture-area.js +0 -84
- package/dist-lib/lib/office/engine/pptx/presentation.d.ts +0 -56
- package/dist-lib/lib/office/engine/pptx/presentation.js +0 -787
- package/dist-lib/lib/office/engine/pptx/read.d.ts +0 -9
- package/dist-lib/lib/office/engine/pptx/read.js +0 -66
- package/dist-lib/lib/office/engine/pptx/shapes.d.ts +0 -52
- package/dist-lib/lib/office/engine/pptx/shapes.js +0 -276
- package/dist-lib/lib/office/engine/pptx/slides.d.ts +0 -27
- package/dist-lib/lib/office/engine/pptx/slides.js +0 -123
- package/dist-lib/lib/office/engine/pptx/template.d.ts +0 -20
- package/dist-lib/lib/office/engine/pptx/template.js +0 -391
- package/dist-lib/lib/office/engine/pptx/types.d.ts +0 -121
- package/dist-lib/lib/office/engine/units.d.ts +0 -3
- package/dist-lib/lib/office/engine/units.js +0 -12
- package/dist-lib/lib/office/engine/utf8.d.ts +0 -2
- package/dist-lib/lib/office/engine/utf8.js +0 -103
- package/dist-lib/lib/office/engine/xlsx/formula.d.ts +0 -49
- package/dist-lib/lib/office/engine/xlsx/formula.js +0 -381
- package/dist-lib/lib/office/engine/xlsx/index.d.ts +0 -8
- package/dist-lib/lib/office/engine/xlsx/index.js +0 -8
- package/dist-lib/lib/office/engine/xlsx/refs.d.ts +0 -22
- package/dist-lib/lib/office/engine/xlsx/refs.js +0 -82
- package/dist-lib/lib/office/engine/xlsx/reshape.d.ts +0 -21
- package/dist-lib/lib/office/engine/xlsx/reshape.js +0 -424
- package/dist-lib/lib/office/engine/xlsx/sheet.d.ts +0 -108
- package/dist-lib/lib/office/engine/xlsx/sheet.js +0 -662
- package/dist-lib/lib/office/engine/xlsx/strings.d.ts +0 -15
- package/dist-lib/lib/office/engine/xlsx/strings.js +0 -93
- package/dist-lib/lib/office/engine/xlsx/styles.d.ts +0 -38
- package/dist-lib/lib/office/engine/xlsx/styles.js +0 -369
- package/dist-lib/lib/office/engine/xlsx/template.d.ts +0 -7
- package/dist-lib/lib/office/engine/xlsx/template.js +0 -54
- package/dist-lib/lib/office/engine/xlsx/workbook.d.ts +0 -162
- package/dist-lib/lib/office/engine/xlsx/workbook.js +0 -881
- package/dist-lib/lib/office/engine/xlsx/write.d.ts +0 -2
- package/dist-lib/lib/office/engine/xlsx/write.js +0 -42
- package/dist-lib/lib/office/engine/xml.d.ts +0 -45
- package/dist-lib/lib/office/engine/xml.js +0 -258
- package/patches/localwatch@1.4.3.patch +0 -13
- /package/dist-lib/lib/{office/engine/pptx/types.js → contract/media.js} +0 -0
|
@@ -1,16 +1,36 @@
|
|
|
1
1
|
import { relativeKey, searchTargets } from '../fs/targets.js';
|
|
2
2
|
import { compileGlob } from '../fs/glob.js';
|
|
3
3
|
import { callDenyRoots, defaultRealpath, isDeniedPath } from '../fs/scope.js';
|
|
4
|
-
import { anchorOf, shownPath, stringArg } from '../fs/tool-path.js';
|
|
5
|
-
import {
|
|
4
|
+
import { anchorOf, MAX_LIMIT, pagingError, shownPath, stringArg } from '../fs/tool-path.js';
|
|
5
|
+
import { engineAnswer } from '../fs/engine.js';
|
|
6
|
+
import { MAX_WALK_MS, walkFiles } from '../fs/walk.js';
|
|
6
7
|
import { folderArg, folderPaths } from './list-dir.js';
|
|
7
8
|
const GLOB_MATCHES = 100;
|
|
9
|
+
function interleaveTopLevel(hits) {
|
|
10
|
+
const groups = new Map();
|
|
11
|
+
for (const hit of hits) {
|
|
12
|
+
const list = groups.get(hit.group) ?? [];
|
|
13
|
+
list.push(hit);
|
|
14
|
+
groups.set(hit.group, list);
|
|
15
|
+
}
|
|
16
|
+
const order = [];
|
|
17
|
+
for (let round = 0; order.length < hits.length; round++) {
|
|
18
|
+
for (const list of groups.values()) {
|
|
19
|
+
if (round < list.length) {
|
|
20
|
+
order.push(list[round]);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return order;
|
|
25
|
+
}
|
|
8
26
|
export function createGlobTool({ realpath = defaultRealpath, deniedRoots } = {}) {
|
|
9
27
|
return {
|
|
10
28
|
name: 'glob',
|
|
11
29
|
toolset: 'files',
|
|
12
30
|
description: 'Find files in the shared folder by name pattern, newest first. "**" crosses folders: ' +
|
|
13
|
-
'"**/*.md" finds every Markdown file, "*report*" matches names anywhere.'
|
|
31
|
+
'"**/*.md" finds every Markdown file, "*report*" matches names anywhere. ' +
|
|
32
|
+
'Ignored files and cache folders are skipped (set includeIgnored to find them; .git and node_modules stay out). A long answer samples every ' +
|
|
33
|
+
'top-level folder and offset pages that sample.',
|
|
14
34
|
parameters: {
|
|
15
35
|
type: 'object',
|
|
16
36
|
properties: {
|
|
@@ -18,7 +38,13 @@ export function createGlobTool({ realpath = defaultRealpath, deniedRoots } = {})
|
|
|
18
38
|
dir: {
|
|
19
39
|
type: 'string',
|
|
20
40
|
description: 'Folder to search, relative to the shared folder (optional)'
|
|
21
|
-
}
|
|
41
|
+
},
|
|
42
|
+
includeIgnored: {
|
|
43
|
+
type: 'boolean',
|
|
44
|
+
description: 'Also find files .gitignore and cache folders leave out'
|
|
45
|
+
},
|
|
46
|
+
limit: { type: 'number', description: `Most paths to return (default ${GLOB_MATCHES})` },
|
|
47
|
+
offset: { type: 'number', description: 'Paths to skip, to page past a cut-off answer' }
|
|
22
48
|
},
|
|
23
49
|
required: ['pattern']
|
|
24
50
|
},
|
|
@@ -27,7 +53,7 @@ export function createGlobTool({ realpath = defaultRealpath, deniedRoots } = {})
|
|
|
27
53
|
stableRead: true,
|
|
28
54
|
autoApprove: true,
|
|
29
55
|
rootsRequired: true,
|
|
30
|
-
validate: (args) => (stringArg(args, 'pattern') ?
|
|
56
|
+
validate: (args) => (stringArg(args, 'pattern') ? pagingError(args) : 'pattern is required'),
|
|
31
57
|
paths: (args, ctx) => folderPaths(args, ctx),
|
|
32
58
|
resource: (args) => ({ kind: 'file', label: `glob ${String(args.pattern ?? '')}` }),
|
|
33
59
|
async execute(args, ctx) {
|
|
@@ -40,10 +66,19 @@ export function createGlobTool({ realpath = defaultRealpath, deniedRoots } = {})
|
|
|
40
66
|
const pattern = String(args.pattern);
|
|
41
67
|
const test = compileGlob(pattern);
|
|
42
68
|
const byName = !pattern.includes('/');
|
|
69
|
+
const limit = Math.min(Number(args.limit ?? GLOB_MATCHES), MAX_LIMIT);
|
|
70
|
+
const offset = Number(args.offset ?? 0);
|
|
71
|
+
const includeIgnored = args.includeIgnored === true;
|
|
43
72
|
const hits = [];
|
|
44
73
|
let walkTruncated = false;
|
|
45
|
-
for (const target of scoped.targets) {
|
|
46
|
-
const
|
|
74
|
+
for (const [index, target] of scoped.targets.entries()) {
|
|
75
|
+
const base = target.folder.replace(/^\/+|\/+$/g, '');
|
|
76
|
+
const walk = await walkTarget(target, {
|
|
77
|
+
include: byName || !base ? pattern : `${base}/${pattern}`,
|
|
78
|
+
includeIgnored,
|
|
79
|
+
deny,
|
|
80
|
+
signal: ctx?.signal
|
|
81
|
+
});
|
|
47
82
|
walkTruncated ||= walk.truncated;
|
|
48
83
|
for (const file of walk.files) {
|
|
49
84
|
const rel = relativeKey(file.key, target.folder);
|
|
@@ -51,15 +86,41 @@ export function createGlobTool({ realpath = defaultRealpath, deniedRoots } = {})
|
|
|
51
86
|
if (isDeniedPath(file.path, deny) || !(test(rel) || (byName && test(name)))) {
|
|
52
87
|
continue;
|
|
53
88
|
}
|
|
54
|
-
const
|
|
55
|
-
|
|
89
|
+
const mtime = file.mtime ?? (await target.root.drive.entry(file.key))?.mtime ?? 0;
|
|
90
|
+
const group = `${index}/${rel.includes('/') ? rel.slice(0, rel.indexOf('/')) : ''}`;
|
|
91
|
+
hits.push({ path: shownPath(file.path, anchorOf(ctx)), mtime, group });
|
|
56
92
|
}
|
|
57
93
|
}
|
|
58
94
|
hits.sort((a, b) => b.mtime - a.mtime);
|
|
95
|
+
const sampled = hits.length > GLOB_MATCHES;
|
|
96
|
+
const order = sampled ? interleaveTopLevel(hits) : hits;
|
|
97
|
+
const page = order.slice(offset, offset + limit);
|
|
98
|
+
const truncated = walkTruncated || hits.length > offset + limit || undefined;
|
|
99
|
+
if (!sampled) {
|
|
100
|
+
return { matches: page.map((hit) => hit.path), truncated };
|
|
101
|
+
}
|
|
102
|
+
const groups = new Set(hits.map((hit) => hit.group)).size;
|
|
103
|
+
const shown = new Set(page.map((hit) => hit.group)).size;
|
|
59
104
|
return {
|
|
60
|
-
matches:
|
|
61
|
-
truncated
|
|
105
|
+
matches: page.map((hit) => hit.path),
|
|
106
|
+
truncated,
|
|
107
|
+
note: `showing ${page.length} of ${hits.length} paths, sampled across ${shown} of ${groups} top-level folders; page with offset`
|
|
62
108
|
};
|
|
63
109
|
}
|
|
64
110
|
};
|
|
65
111
|
}
|
|
112
|
+
async function walkTarget({ root, folder }, { include, includeIgnored, deny, signal }) {
|
|
113
|
+
const native = root.kind === 'local' ? root.walk : undefined;
|
|
114
|
+
if (native) {
|
|
115
|
+
const walked = await engineAnswer(root, folder, {
|
|
116
|
+
run: () => native({ folder, include, includeIgnored, deny, maxMs: MAX_WALK_MS, signal }),
|
|
117
|
+
found: (answer) => answer.files.length > 0 || answer.truncated,
|
|
118
|
+
includeIgnored,
|
|
119
|
+
signal
|
|
120
|
+
});
|
|
121
|
+
if (walked) {
|
|
122
|
+
return walked;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return walkFiles(root, folder, { includeIgnored });
|
|
126
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { errorMessage } from '../../guards.js';
|
|
2
2
|
import { searchTargets } from '../fs/targets.js';
|
|
3
3
|
import { compileGlob } from '../fs/glob.js';
|
|
4
|
-
import { callDenyRoots, defaultRealpath } from '../fs/scope.js';
|
|
4
|
+
import { callDenyRoots, defaultRealpath, isDeniedPath } from '../fs/scope.js';
|
|
5
5
|
import { DriveSearch } from '../fs/search.js';
|
|
6
|
-
import { anchorOf, shownPath, stringArg } from '../fs/tool-path.js';
|
|
6
|
+
import { anchorOf, MAX_LIMIT, pagingError, shownPath, stringArg } from '../fs/tool-path.js';
|
|
7
|
+
import { engineAnswer } from '../fs/engine.js';
|
|
7
8
|
import { MAX_WALK_ENTRIES, MAX_WALK_MS } from '../fs/walk.js';
|
|
8
9
|
import { folderArg, folderPaths } from './list-dir.js';
|
|
9
10
|
const GREP_MATCHES = 100;
|
|
10
|
-
const MAX_LIMIT = 500;
|
|
11
11
|
const MAX_LINE_CHARS = 300;
|
|
12
12
|
const TALLY_MATCHES = 5000;
|
|
13
13
|
const SPREAD_MATCHES = 1000;
|
|
@@ -21,8 +21,10 @@ export function createGrepTool({ realpath = defaultRealpath, deniedRoots, maxWal
|
|
|
21
21
|
return {
|
|
22
22
|
name: 'grep',
|
|
23
23
|
toolset: 'files',
|
|
24
|
-
description: 'Search inside the files of the shared folder. The pattern is plain text, case-insensitive
|
|
25
|
-
'"a|b" finds either; set regex for a regular expression.
|
|
24
|
+
description: 'Search inside the files of the shared folder. The pattern is plain text, case-insensitive ' +
|
|
25
|
+
'(set caseSensitive to match case); "a|b" finds either; set regex for a regular expression. ' +
|
|
26
|
+
'Ignored files and cache folders are skipped (set includeIgnored to search them; .git and node_modules stay out). ' +
|
|
27
|
+
'Returns "path:line: text"; output ' +
|
|
26
28
|
'"files" lists matching files with the first line and count, "count" counts per file. Narrow with include (e.g. "*.ts").',
|
|
27
29
|
parameters: {
|
|
28
30
|
type: 'object',
|
|
@@ -37,6 +39,11 @@ export function createGrepTool({ realpath = defaultRealpath, deniedRoots, maxWal
|
|
|
37
39
|
description: 'Only files whose name matches this pattern (optional)'
|
|
38
40
|
},
|
|
39
41
|
regex: { type: 'boolean', description: 'Treat pattern as a regular expression' },
|
|
42
|
+
caseSensitive: { type: 'boolean', description: "Match the pattern's exact case" },
|
|
43
|
+
includeIgnored: {
|
|
44
|
+
type: 'boolean',
|
|
45
|
+
description: 'Also search files .gitignore and cache folders leave out'
|
|
46
|
+
},
|
|
40
47
|
output: {
|
|
41
48
|
type: 'string',
|
|
42
49
|
enum: [...OUTPUTS],
|
|
@@ -58,10 +65,9 @@ export function createGrepTool({ realpath = defaultRealpath, deniedRoots, maxWal
|
|
|
58
65
|
if (args.output !== undefined && !isOutput(args.output)) {
|
|
59
66
|
return `output is one of ${OUTPUTS.join(', ')}`;
|
|
60
67
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
68
|
+
const paging = pagingError(args);
|
|
69
|
+
if (paging) {
|
|
70
|
+
return paging;
|
|
65
71
|
}
|
|
66
72
|
if (args.regex !== true) {
|
|
67
73
|
return null;
|
|
@@ -86,16 +92,21 @@ export function createGrepTool({ realpath = defaultRealpath, deniedRoots, maxWal
|
|
|
86
92
|
const pattern = String(args.pattern);
|
|
87
93
|
const regex = args.regex === true;
|
|
88
94
|
const queries = regex ? [pattern] : alternatives(pattern);
|
|
95
|
+
const caseSensitive = args.caseSensitive === true;
|
|
89
96
|
const output = isOutput(args.output) ? args.output : 'content';
|
|
90
97
|
const limit = Math.min(Number(args.limit ?? GREP_MATCHES), MAX_LIMIT);
|
|
91
98
|
const offset = Number(args.offset ?? 0);
|
|
92
99
|
const spread = args.output === undefined && args.limit === undefined && offset === 0;
|
|
93
100
|
const wanted = spread ? SPREAD_MATCHES : reach(output, offset + limit);
|
|
94
101
|
const query = {
|
|
95
|
-
search: new DriveSearch(queries, { regex }),
|
|
102
|
+
search: new DriveSearch(queries, { regex, caseSensitive }),
|
|
96
103
|
queries,
|
|
97
104
|
regex,
|
|
98
|
-
|
|
105
|
+
caseSensitive,
|
|
106
|
+
includeIgnored: args.includeIgnored === true,
|
|
107
|
+
include: stringArg(args, 'include') ? String(args.include).replace(/^\.\//, '') : undefined,
|
|
108
|
+
anchor: anchorOf(ctx),
|
|
109
|
+
signal: ctx?.signal,
|
|
99
110
|
deny,
|
|
100
111
|
maxEntries: maxWalkEntries
|
|
101
112
|
};
|
|
@@ -136,7 +147,7 @@ export function createGrepTool({ realpath = defaultRealpath, deniedRoots, maxWal
|
|
|
136
147
|
};
|
|
137
148
|
}
|
|
138
149
|
function includes(pattern, anchor) {
|
|
139
|
-
const glob = compileGlob(pattern
|
|
150
|
+
const glob = compileGlob(pattern);
|
|
140
151
|
return pattern.includes('/') ? (_name, full) => glob(shownPath(full, anchor)) : glob;
|
|
141
152
|
}
|
|
142
153
|
const reach = (output, lines) => output === 'content' ? lines : TALLY_MATCHES;
|
|
@@ -195,18 +206,50 @@ function noMatches(pattern, { regex, offset, found }) {
|
|
|
195
206
|
}
|
|
196
207
|
return 'no matches';
|
|
197
208
|
}
|
|
198
|
-
function searchTarget({ root, folder }, { search, queries, regex, include, deny, maxEntries, maxMatches }) {
|
|
209
|
+
async function searchTarget({ root, folder }, { search, queries, regex, caseSensitive, includeIgnored, include, anchor, signal, deny, maxEntries, maxMatches }) {
|
|
210
|
+
const query = {
|
|
211
|
+
folder,
|
|
212
|
+
queries: [...queries],
|
|
213
|
+
regex,
|
|
214
|
+
caseSensitive,
|
|
215
|
+
includeIgnored,
|
|
216
|
+
maxMatches,
|
|
217
|
+
maxEntries,
|
|
218
|
+
maxMs: MAX_WALK_MS
|
|
219
|
+
};
|
|
199
220
|
if (root.kind === 'hyper' && root.search && !include) {
|
|
200
|
-
return root.search(
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
includeIgnored: false,
|
|
221
|
+
return root.search(query);
|
|
222
|
+
}
|
|
223
|
+
const native = root.kind === 'local' ? await nativeSearch(root, { ...query, include, deny, signal }) : null;
|
|
224
|
+
return (native ??
|
|
225
|
+
search.searchFolder(root, folder, {
|
|
206
226
|
maxMatches,
|
|
207
227
|
maxEntries,
|
|
208
|
-
|
|
209
|
-
|
|
228
|
+
include: include ? includes(include, anchor) : null,
|
|
229
|
+
deny,
|
|
230
|
+
includeIgnored
|
|
231
|
+
}));
|
|
232
|
+
}
|
|
233
|
+
async function nativeSearch(root, query) {
|
|
234
|
+
const native = root.search;
|
|
235
|
+
if (!native) {
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
const found = await engineAnswer(root, query.folder, {
|
|
239
|
+
run: () => native(query),
|
|
240
|
+
found: (answer) => answer.hits.length > 0 || answer.truncated,
|
|
241
|
+
includeIgnored: query.includeIgnored,
|
|
242
|
+
signal: query.signal
|
|
243
|
+
});
|
|
244
|
+
if (!found) {
|
|
245
|
+
return null;
|
|
210
246
|
}
|
|
211
|
-
|
|
247
|
+
const hits = found.hits.filter((hit) => !isDeniedPath(hit.file, query.deny));
|
|
248
|
+
const cutShort = found.capped && hits.length < found.hits.length;
|
|
249
|
+
return {
|
|
250
|
+
...found,
|
|
251
|
+
hits,
|
|
252
|
+
capped: hits.length >= query.maxMatches,
|
|
253
|
+
truncated: found.truncated || cutShort
|
|
254
|
+
};
|
|
212
255
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createEditFileTool } from './edit-file.js';
|
|
1
|
+
import { createEditFileTool, createEditManyTool, createInsertTextTool } from './edit-file.js';
|
|
2
2
|
import { createGlobTool } from './glob.js';
|
|
3
3
|
import { createGrepTool } from './grep.js';
|
|
4
4
|
import { createListDirTool } from './list-dir.js';
|
|
@@ -15,6 +15,8 @@ export function createFileTools(options = {}) {
|
|
|
15
15
|
createGrepTool(options),
|
|
16
16
|
createWriteFileTool(options),
|
|
17
17
|
createEditFileTool(options),
|
|
18
|
+
createInsertTextTool(options),
|
|
19
|
+
createEditManyTool(options),
|
|
18
20
|
createMoveFileTool(options),
|
|
19
21
|
createCopyFileTool(options),
|
|
20
22
|
createMakeDirTool(options),
|
|
@@ -2,23 +2,35 @@ import b4a from 'b4a';
|
|
|
2
2
|
import { errorMessage } from '../../guards.js';
|
|
3
3
|
import { documentText, isDocument } from '../fs/document-text.js';
|
|
4
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';
|
|
5
|
+
import { callDenyRoots, defaultRealpath, resolveKey } from '../fs/scope.js';
|
|
6
|
+
import { anchorOf, positiveInt, resolveRooted, rootedArgs, rootedPath, signedLine, stringArg } from '../fs/tool-path.js';
|
|
7
|
+
import { missingFile } from '../fs/suggest.js';
|
|
8
|
+
const MAX_DOCUMENT_BYTES = 8 * 1024 * 1024;
|
|
7
9
|
const READ_LINES = 400;
|
|
8
10
|
const READ_CHARS = 20_000;
|
|
11
|
+
const LINE_CHARS = 2000;
|
|
12
|
+
const TAIL_LINES = 50;
|
|
13
|
+
const COUNT_BYTES = 8 * 1024 * 1024;
|
|
14
|
+
const COUNT_MIB = COUNT_BYTES / 1024 / 1024;
|
|
9
15
|
const BINARY_PROBE = 1024;
|
|
16
|
+
const LINE_BYTES = 3 * LINE_CHARS + 4;
|
|
10
17
|
export function createReadFileTool({ realpath = defaultRealpath, deniedRoots } = {}) {
|
|
11
18
|
return {
|
|
12
19
|
name: 'read_file',
|
|
13
20
|
toolset: 'files',
|
|
14
21
|
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.
|
|
22
|
+
'read a range with startLine/endLine. A line over 2000 chars is cut; the cut names its full ' +
|
|
23
|
+
'length (bytes for a text file, chars for a document). PDF, Word and PowerPoint files come ' +
|
|
24
|
+
'back as their text. ' +
|
|
16
25
|
'Use this, not exec, for files in the shared folder.',
|
|
17
26
|
parameters: {
|
|
18
27
|
type: 'object',
|
|
19
28
|
properties: {
|
|
20
29
|
path: { type: 'string', description: 'File path, relative to the shared folder' },
|
|
21
|
-
startLine: {
|
|
30
|
+
startLine: {
|
|
31
|
+
type: 'integer',
|
|
32
|
+
description: 'First line to read (1-based, optional); negative counts from the end, -50 is the last 50 lines'
|
|
33
|
+
},
|
|
22
34
|
endLine: { type: 'integer', description: 'Last line to read (optional)' }
|
|
23
35
|
},
|
|
24
36
|
required: ['path']
|
|
@@ -44,15 +56,23 @@ export function createReadFileTool({ realpath = defaultRealpath, deniedRoots } =
|
|
|
44
56
|
if ('error' in resolved) {
|
|
45
57
|
return resolved;
|
|
46
58
|
}
|
|
59
|
+
const missing = async () => missingFile({
|
|
60
|
+
requested,
|
|
61
|
+
resolved,
|
|
62
|
+
anchor: anchorOf(ctx),
|
|
63
|
+
deny: await callDenyRoots(deniedRoots, ctx?.policy, realpath)
|
|
64
|
+
});
|
|
47
65
|
try {
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
return text;
|
|
51
|
-
}
|
|
52
|
-
return numbered(text, {
|
|
53
|
-
start: positiveInt(args.startLine),
|
|
66
|
+
const range = {
|
|
67
|
+
start: signedLine(args.startLine),
|
|
54
68
|
end: positiveInt(args.endLine)
|
|
55
|
-
}
|
|
69
|
+
};
|
|
70
|
+
const target = { resolved, requested, missing };
|
|
71
|
+
if (isDocument(resolved.key)) {
|
|
72
|
+
const text = await documentOf(target, ctx);
|
|
73
|
+
return typeof text === 'string' ? numbered(text, range) : text;
|
|
74
|
+
}
|
|
75
|
+
return await textRange(target, range);
|
|
56
76
|
}
|
|
57
77
|
catch (err) {
|
|
58
78
|
return { error: errorMessage(err) };
|
|
@@ -60,46 +80,189 @@ export function createReadFileTool({ realpath = defaultRealpath, deniedRoots } =
|
|
|
60
80
|
}
|
|
61
81
|
};
|
|
62
82
|
}
|
|
63
|
-
async function
|
|
83
|
+
async function documentOf({ resolved, requested, missing }, ctx) {
|
|
64
84
|
const { drive } = resolved.root;
|
|
65
|
-
const
|
|
66
|
-
if (
|
|
67
|
-
return {
|
|
85
|
+
const entry = await drive.entry(resolved.key);
|
|
86
|
+
if (entry?.value.blob && entry.value.blob.byteLength > MAX_DOCUMENT_BYTES) {
|
|
87
|
+
return {
|
|
88
|
+
error: `${requested} is larger than the ${MAX_DOCUMENT_BYTES}-byte document extraction limit`
|
|
89
|
+
};
|
|
68
90
|
}
|
|
69
|
-
|
|
70
|
-
|
|
91
|
+
const bytes = entry ? await drive.get(resolved.key) : null;
|
|
92
|
+
if (bytes === null) {
|
|
93
|
+
return missing();
|
|
71
94
|
}
|
|
72
|
-
if (bytes.
|
|
73
|
-
return {
|
|
95
|
+
if (bytes.byteLength > MAX_DOCUMENT_BYTES) {
|
|
96
|
+
return {
|
|
97
|
+
error: `${requested} is larger than the ${MAX_DOCUMENT_BYTES}-byte document extraction limit`
|
|
98
|
+
};
|
|
74
99
|
}
|
|
75
|
-
return
|
|
100
|
+
return documentText(resolved.key, bytes, { ocr: ctx?.ocr, signal: ctx?.signal });
|
|
76
101
|
}
|
|
77
|
-
function numbered(text, { start, end }) {
|
|
102
|
+
function numbered(text, { start = 1, end }) {
|
|
78
103
|
const lines = text.split('\n');
|
|
79
104
|
if (lines.length > 1 && lines[lines.length - 1] === '') {
|
|
80
105
|
lines.pop();
|
|
81
106
|
}
|
|
82
107
|
const total = lines.length;
|
|
83
|
-
const first =
|
|
84
|
-
const
|
|
108
|
+
const first = tailStart(start, total);
|
|
109
|
+
const rows = [];
|
|
85
110
|
let chars = 0;
|
|
86
|
-
let cut = false;
|
|
87
111
|
for (let n = first; n <= Math.min(total, end ?? first + READ_LINES - 1); n++) {
|
|
88
|
-
const row = `${n}| ${lines[n - 1]}`;
|
|
112
|
+
const row = `${n}| ${clip(lines[n - 1] ?? '')}`;
|
|
89
113
|
if (chars + row.length > READ_CHARS) {
|
|
90
|
-
cut = out.length === 0;
|
|
91
|
-
if (cut) {
|
|
92
|
-
out.push(row.slice(0, READ_CHARS));
|
|
93
|
-
}
|
|
94
114
|
break;
|
|
95
115
|
}
|
|
96
|
-
|
|
116
|
+
rows.push(row);
|
|
97
117
|
chars += row.length + 1;
|
|
98
118
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
119
|
+
return { content: present({ first, rows, total, pastEnd: start > total ? start : undefined }) };
|
|
120
|
+
}
|
|
121
|
+
function tailStart(start, total) {
|
|
122
|
+
if (start < 0) {
|
|
123
|
+
return Math.max(1, total + start + 1);
|
|
124
|
+
}
|
|
125
|
+
return start > total ? Math.max(1, total - TAIL_LINES + 1) : start;
|
|
126
|
+
}
|
|
127
|
+
function present({ first, rows, total, pastEnd }) {
|
|
128
|
+
const last = first + rows.length - 1;
|
|
129
|
+
const shown = pastEnd === undefined
|
|
130
|
+
? `lines ${first}-${last} of ${total ?? 'unknown'}`
|
|
131
|
+
: `startLine ${pastEnd} is past the end; the file has ${total} lines`;
|
|
132
|
+
const header = total === undefined || last < total ? `${shown}; continue with startLine ${last + 1}` : shown;
|
|
133
|
+
return `${header}\n${rows.join('\n')}`;
|
|
134
|
+
}
|
|
135
|
+
function clip(text, bytes) {
|
|
136
|
+
const line = text.endsWith('\r') ? text.slice(0, -1) : text;
|
|
137
|
+
if (line.length <= LINE_CHARS) {
|
|
138
|
+
return line;
|
|
139
|
+
}
|
|
140
|
+
const all = bytes === undefined ? `${line.length} chars` : `${bytes} bytes`;
|
|
141
|
+
return `${line.slice(0, LINE_CHARS)}… (line cut at ${LINE_CHARS} chars; ${all} in all)`;
|
|
142
|
+
}
|
|
143
|
+
async function textRange({ resolved, requested, missing }, range) {
|
|
144
|
+
const { drive } = resolved.root;
|
|
145
|
+
if (!(await drive.entry(resolved.key))) {
|
|
146
|
+
return missing();
|
|
147
|
+
}
|
|
148
|
+
const reader = new TextRange(range);
|
|
149
|
+
let probed = 0;
|
|
150
|
+
for await (const chunk of drive.createReadStream(resolved.key)) {
|
|
151
|
+
if (chunk.subarray(0, Math.max(0, BINARY_PROBE - probed)).includes(0)) {
|
|
152
|
+
return { error: `${requested} is a binary file (not text, PDF, Word or PowerPoint)` };
|
|
153
|
+
}
|
|
154
|
+
probed += chunk.length;
|
|
155
|
+
reader.feed(chunk);
|
|
156
|
+
if (probed > COUNT_BYTES && reader.counting) {
|
|
157
|
+
return reader.done
|
|
158
|
+
? { content: present({ ...reader.finish(), total: undefined }) }
|
|
159
|
+
: {
|
|
160
|
+
error: `${requested} has more than ${reader.lines} lines; its end is past the ${COUNT_MIB} MiB read_file counts, read a startLine range instead`
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return { content: present(reader.finish()) };
|
|
165
|
+
}
|
|
166
|
+
class TextRange {
|
|
167
|
+
#start;
|
|
168
|
+
#end;
|
|
169
|
+
#keep;
|
|
170
|
+
#ring = [];
|
|
171
|
+
#rows = [];
|
|
172
|
+
#first;
|
|
173
|
+
#last;
|
|
174
|
+
#chars = 0;
|
|
175
|
+
done = false;
|
|
176
|
+
#open = false;
|
|
177
|
+
#lines = 0;
|
|
178
|
+
#line = emptyLine();
|
|
179
|
+
constructor({ start = 1, end }) {
|
|
180
|
+
this.#start = start;
|
|
181
|
+
this.#end = end;
|
|
182
|
+
this.#keep = start < 0 ? -start : TAIL_LINES;
|
|
183
|
+
this.#first = start < 0 ? Infinity : start;
|
|
184
|
+
this.#last = end ?? this.#first + READ_LINES - 1;
|
|
185
|
+
}
|
|
186
|
+
get lines() {
|
|
187
|
+
return this.#lines;
|
|
188
|
+
}
|
|
189
|
+
get counting() {
|
|
190
|
+
return this.done || this.#lines + 1 < this.#first;
|
|
191
|
+
}
|
|
192
|
+
feed(chunk) {
|
|
193
|
+
let at = 0;
|
|
194
|
+
while (at < chunk.length) {
|
|
195
|
+
if (this.done) {
|
|
196
|
+
this.#count(chunk, at);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
const newline = chunk.indexOf(0x0a, at);
|
|
200
|
+
this.#append(chunk.subarray(at, newline === -1 ? chunk.length : newline));
|
|
201
|
+
if (newline === -1) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
this.#close();
|
|
205
|
+
at = newline + 1;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
finish() {
|
|
209
|
+
if (this.#line.size > 0 || this.#lines === 0) {
|
|
210
|
+
this.#close();
|
|
211
|
+
}
|
|
212
|
+
const total = this.#lines + (this.#open ? 1 : 0);
|
|
213
|
+
if (this.#start > 0 && this.#start <= total) {
|
|
214
|
+
return { first: this.#first, rows: this.#rows, total };
|
|
215
|
+
}
|
|
216
|
+
this.#first = tailStart(this.#start, total);
|
|
217
|
+
this.#last = (this.#start < 0 ? this.#end : undefined) ?? this.#first + READ_LINES - 1;
|
|
218
|
+
for (let n = this.#first; n <= total && !this.done; n++) {
|
|
219
|
+
this.#take(n, this.#ring[(n - 1) % this.#keep]);
|
|
220
|
+
}
|
|
221
|
+
return {
|
|
222
|
+
first: this.#first,
|
|
223
|
+
rows: this.#rows,
|
|
224
|
+
total,
|
|
225
|
+
pastEnd: this.#start > total ? this.#start : undefined
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
#count(chunk, from) {
|
|
229
|
+
for (let n = b4a.indexOf(chunk, 0x0a, from); n !== -1; n = b4a.indexOf(chunk, 0x0a, n + 1)) {
|
|
230
|
+
this.#lines++;
|
|
231
|
+
}
|
|
232
|
+
this.#open = chunk[chunk.length - 1] !== 0x0a;
|
|
233
|
+
}
|
|
234
|
+
#append(bytes) {
|
|
235
|
+
const kept = bytes.subarray(0, LINE_BYTES - this.#line.bytes);
|
|
236
|
+
if (kept.length) {
|
|
237
|
+
this.#line.parts.push(kept);
|
|
238
|
+
}
|
|
239
|
+
this.#line.bytes += kept.length;
|
|
240
|
+
this.#line.size += bytes.length;
|
|
241
|
+
}
|
|
242
|
+
#close() {
|
|
243
|
+
this.#lines++;
|
|
244
|
+
const line = this.#line;
|
|
245
|
+
this.#line = emptyLine();
|
|
246
|
+
if (this.#lines < this.#first) {
|
|
247
|
+
this.#ring[(this.#lines - 1) % this.#keep] = line;
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
this.#take(this.#lines, line);
|
|
251
|
+
}
|
|
252
|
+
#take(n, line) {
|
|
253
|
+
const row = n > this.#last ? null : `${n}| ${lineText(line)}`;
|
|
254
|
+
if (row === null || this.#chars + row.length > READ_CHARS) {
|
|
255
|
+
this.done = true;
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
this.#rows.push(row);
|
|
259
|
+
this.#chars += row.length + 1;
|
|
260
|
+
this.done = n >= this.#last;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
function emptyLine() {
|
|
264
|
+
return { parts: [], bytes: 0, size: 0 };
|
|
265
|
+
}
|
|
266
|
+
function lineText(line) {
|
|
267
|
+
return clip(b4a.toString(b4a.concat(line.parts), 'utf8'), line.size);
|
|
105
268
|
}
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
+
import type { AbortSignal as BareAbortSignal } from 'bare-abort-controller';
|
|
2
|
+
import type { OcrService } from '../../contract/ocr.ts';
|
|
1
3
|
export declare function isDocument(key: string): boolean;
|
|
2
|
-
export
|
|
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>;
|
|
@@ -1,31 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
let pdfium = null;
|
|
4
|
-
function loadPdfium() {
|
|
5
|
-
pdfium ??= import('bare-pdfium').then((loaded) => loaded, () => null);
|
|
6
|
-
return pdfium;
|
|
7
|
-
}
|
|
1
|
+
import { docx, pptx } from 'qvac-office';
|
|
2
|
+
import { pdfPages } from '../pdf/pages.js';
|
|
8
3
|
export function isDocument(key) {
|
|
9
4
|
return /\.(pdf|docx|pptx)$/i.test(key);
|
|
10
5
|
}
|
|
11
|
-
export async function documentText(key, bytes) {
|
|
6
|
+
export async function documentText(key, bytes, { ocr, signal } = {}) {
|
|
12
7
|
if (!/\.pdf$/i.test(key)) {
|
|
13
8
|
const read = /\.docx$/i.test(key) ? docx.open(bytes).read() : pptx.open(bytes).read();
|
|
14
9
|
return collectText(read).join('\n');
|
|
15
10
|
}
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
throw new HarnessError('PDF_TEXT_UNAVAILABLE');
|
|
19
|
-
}
|
|
20
|
-
const doc = lib.open(bytes);
|
|
21
|
-
try {
|
|
22
|
-
return [...doc.textPages()]
|
|
23
|
-
.map(({ page, text }) => `--- page ${page + 1} ---\n${text.replace(/\r\n?/g, '\n').trim()}`)
|
|
24
|
-
.join('\n');
|
|
25
|
-
}
|
|
26
|
-
finally {
|
|
27
|
-
doc.close();
|
|
28
|
-
}
|
|
11
|
+
const pages = await pdfPages(bytes, { ocr, signal });
|
|
12
|
+
return pages.map(({ page, text }) => `--- page ${page} ---\n${text}`).join('\n');
|
|
29
13
|
}
|
|
30
14
|
function collectText(value) {
|
|
31
15
|
if (Array.isArray(value)) {
|
|
@@ -1,21 +1,5 @@
|
|
|
1
|
-
import type { Writable } from 'streamx';
|
|
2
1
|
import { HarnessError } from '../../errors.ts';
|
|
3
|
-
|
|
4
|
-
export interface DriveListOptions {
|
|
5
|
-
skip?: ReadonlySet<string>;
|
|
6
|
-
recursive?: boolean;
|
|
7
|
-
}
|
|
8
|
-
export interface Drive {
|
|
9
|
-
entry(key: string, opts?: {
|
|
10
|
-
follow?: boolean;
|
|
11
|
-
}): Promise<DriveEntry | null>;
|
|
12
|
-
get(key: string): Promise<Uint8Array | null>;
|
|
13
|
-
list(folder?: string, opts?: DriveListOptions): AsyncIterable<DriveEntry | DriveDir>;
|
|
14
|
-
createReadStream(key: string): AsyncIterable<Uint8Array>;
|
|
15
|
-
createWriteStream(key: string, opts?: {
|
|
16
|
-
executable?: boolean;
|
|
17
|
-
}): Writable;
|
|
18
|
-
}
|
|
2
|
+
export type { Drive, DriveListOptions } from '../../contract/drive.ts';
|
|
19
3
|
export declare class DriveReadTruncatedError extends HarnessError<'DRIVE_READ_TRUNCATED'> {
|
|
20
4
|
constructor(key: string, bytes: number);
|
|
21
5
|
}
|