@qvac/harness 1.0.0-rc.2 → 1.0.0-rc.21
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 +3073 -1485
- package/README.md +110 -46
- package/dist-lib/index.d.ts +63 -16
- package/dist-lib/index.js +232 -38
- 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 +30 -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/answering.js +2 -2
- 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/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 +132 -13
- package/dist-lib/lib/capabilities/completion-engine/actors/execution-plan.js +11 -5
- 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 +12 -2
- package/dist-lib/lib/capabilities/completion-engine/actors/preparing.js +142 -50
- package/dist-lib/lib/capabilities/completion-engine/actors/rejecting.js +10 -4
- package/dist-lib/lib/capabilities/completion-engine/actors/resolving.js +78 -20
- 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 +38 -23
- 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 +101 -41
- 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 +56 -17
- 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 +26 -3
- package/dist-lib/lib/capabilities/completion-engine/loop.js +14 -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 +395 -118
- 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 +5 -2
- package/dist-lib/lib/capabilities/completion-engine/tool-execution.d.ts +8 -43
- package/dist-lib/lib/capabilities/completion-engine/tool-execution.js +32 -141
- package/dist-lib/lib/capabilities/completion-engine/tool-outcome.d.ts +4 -0
- package/dist-lib/lib/capabilities/completion-engine/tool-outcome.js +42 -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/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 +98 -86
- 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/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 +8 -43
- package/dist-lib/lib/capabilities/tool-turns.js +6 -253
- 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/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 +16 -0
- package/dist-lib/lib/connect/host-run-log.js +74 -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 +20 -11
- package/dist-lib/lib/connect.js +178 -415
- package/dist-lib/lib/context-window.d.ts +13 -5
- package/dist-lib/lib/context-window.js +19 -6
- package/dist-lib/lib/contract/agent.d.ts +25 -4
- package/dist-lib/lib/contract/completion.d.ts +82 -32
- package/dist-lib/lib/contract/drive.d.ts +130 -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 +17 -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 +48 -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/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 -0
- package/dist-lib/lib/helpers/goal-check.js +35 -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/recent-map.d.ts +7 -0
- package/dist-lib/lib/helpers/recent-map.js +23 -0
- 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/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 +149 -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/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 +15 -16
- package/dist-lib/lib/machine/completion/actions/completion.js +164 -107
- 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 +3 -2
- 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 +111 -140
- 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 +18 -9
- package/dist-lib/lib/machine/completion/implementations.js +64 -16
- package/dist-lib/lib/machine/completion/machine.d.ts +38 -9
- package/dist-lib/lib/machine/completion/machine.js +58 -9
- package/dist-lib/lib/machine/completion/metrics.d.ts +25 -0
- package/dist-lib/lib/machine/completion/metrics.js +68 -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 +19 -27
- package/dist-lib/lib/machine/completion/rules.js +48 -79
- 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 +81 -14
- package/dist-lib/lib/machine/index.d.ts +50 -11
- package/dist-lib/lib/machine/index.js +12 -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.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 +17 -6
- package/dist-lib/lib/residency/completion-runtime.js +91 -37
- package/dist-lib/lib/residency/index.d.ts +59 -6
- package/dist-lib/lib/residency/index.js +444 -42
- 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/redact.js +7 -7
- 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/completion.d.ts +7 -0
- package/dist-lib/lib/serve/completion.js +553 -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 +147 -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 +38 -0
- package/dist-lib/lib/serve/run-log-start.js +254 -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 +51 -916
- 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 +7 -3
- package/dist-lib/lib/skills-host/index.js +47 -22
- 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 +5 -25
- 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 +2 -40
- 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 +4 -15
- package/dist-lib/lib/tools/fs/scope.js +5 -2
- package/dist-lib/lib/tools/fs/search.d.ts +25 -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 +14 -5
- 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 +17 -3
- 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 +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 +56 -13
- package/dist-lib/lib/tools/skill.js +23 -11
- package/dist-lib/lib/tools/skills/bundled-dir.d.ts +8 -1
- package/dist-lib/lib/tools/skills/bundled-dir.js +42 -36
- 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 +7 -8
- package/dist-lib/lib/tools/skills/catalog.js +1 -158
- 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/index.d.ts +1 -0
- package/dist-lib/lib/tools/skills/index.js +1 -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/skills/skill-tree.d.ts +5 -0
- package/dist-lib/lib/tools/skills/skill-tree.js +54 -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/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 -64
- package/dist-lib/lib/wire.js +24 -417
- 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/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/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 +94 -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 +485 -209
- package/dist-lib/spec/hyperschema/index.js +485 -209
- package/dist-lib/spec/hyperschema/schema.json +290 -85
- package/dist-lib/spec/hyperschema/types.d.ts +42 -5
- package/package.json +265 -65
- package/patches/pyodide@314.0.2.patch +37 -8
- package/scripts/addon-externals.cjs +16 -5
- package/worker/harness-sidecar.mjs +23 -154
- package/dist-lib/lib/tools/create-documents.d.ts +0 -3
- package/dist-lib/lib/tools/create-documents.js +0 -95
- package/dist-lib/lib/tools/edit-documents.d.ts +0 -3
- package/dist-lib/lib/tools/edit-documents.js +0 -132
- package/dist-lib/lib/tools/exec/shell-argv.d.ts +0 -2
- package/dist-lib/lib/tools/exec/shell-argv.js +0 -61
- package/dist-lib/lib/tools/file-glob.js +0 -118
- package/dist-lib/lib/tools/grep.d.ts +0 -5
- package/dist-lib/lib/tools/grep.js +0 -184
- package/dist-lib/lib/tools/read-files.d.ts +0 -5
- package/dist-lib/lib/tools/read-files.js +0 -160
- package/dist-lib/plugins/coding/write-file.d.ts +0 -3
- package/dist-lib/plugins/coding/write-file.js +0 -52
- package/patches/@qvac%2Finference@0.21.0.patch +0 -67
- package/patches/bare-stow@0.1.5.patch +0 -68
- package/patches/hypercore-blob-server@1.15.0.patch +0 -15
- package/patches/localwatch@1.4.3.patch +0 -13
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
|
+
import { HarnessError } from '../../lib/errors.js';
|
|
3
4
|
import { dailyCandidates, ensureWithinRoot, FRONTMATTER_RE, getArg, listFolders, listMarkdownFiles, parseFrontmatter, readFileText, resolveNotePath, todayStamp } from './vault-paths.js';
|
|
5
|
+
function statOrNull(p) {
|
|
6
|
+
try {
|
|
7
|
+
return fs.statSync(p);
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
4
13
|
export function handleVault(vaultPath) {
|
|
5
14
|
return JSON.stringify({ name: path.basename(vaultPath), path: vaultPath });
|
|
6
15
|
}
|
|
@@ -16,8 +25,13 @@ export function handleVaults(vaultPath) {
|
|
|
16
25
|
}
|
|
17
26
|
export function handleRead(vaultPath, args) {
|
|
18
27
|
const notePath = resolveNotePath(vaultPath, args);
|
|
19
|
-
|
|
20
|
-
|
|
28
|
+
const stat = notePath ? statOrNull(notePath) : null;
|
|
29
|
+
if (!notePath || !stat) {
|
|
30
|
+
throw new HarnessError('OBSIDIAN_NOTE_NOT_FOUND', [args]);
|
|
31
|
+
}
|
|
32
|
+
if (stat.isDirectory()) {
|
|
33
|
+
const folder = path.relative(path.resolve(vaultPath), notePath).split(path.sep).join('/');
|
|
34
|
+
throw new HarnessError('OBSIDIAN_PATH_IS_FOLDER', [folder]);
|
|
21
35
|
}
|
|
22
36
|
return readFileText(notePath);
|
|
23
37
|
}
|
|
@@ -43,7 +57,7 @@ function parseLimit(args) {
|
|
|
43
57
|
export function handleSearch(vaultPath, args) {
|
|
44
58
|
const query = getArg(args, 'query');
|
|
45
59
|
if (!query) {
|
|
46
|
-
throw new
|
|
60
|
+
throw new HarnessError('OBSIDIAN_MISSING_ARGUMENT', ['query=']);
|
|
47
61
|
}
|
|
48
62
|
const limit = parseLimit(args);
|
|
49
63
|
const lowerQuery = query.toLowerCase();
|
|
@@ -68,11 +82,7 @@ export function handleSearch(vaultPath, args) {
|
|
|
68
82
|
return matches.join('\n') + truncated;
|
|
69
83
|
}
|
|
70
84
|
export function handleProperties(vaultPath, args) {
|
|
71
|
-
|
|
72
|
-
if (!notePath || !fs.existsSync(notePath)) {
|
|
73
|
-
throw new Error(`Note not found. Args: ${args.join(', ')}`);
|
|
74
|
-
}
|
|
75
|
-
return JSON.stringify(parseFrontmatter(readFileText(notePath)), null, 2);
|
|
85
|
+
return JSON.stringify(parseFrontmatter(handleRead(vaultPath, args)), null, 2);
|
|
76
86
|
}
|
|
77
87
|
function countTags(tagCounts, content) {
|
|
78
88
|
for (const match of content.matchAll(/#([a-zA-Z0-9_/-]+)/g)) {
|
|
@@ -97,20 +107,12 @@ export function handleTags(vaultPath) {
|
|
|
97
107
|
return sorted.map(([tag, count]) => `#${tag} (${count})`).join('\n') || '(no tags)';
|
|
98
108
|
}
|
|
99
109
|
export function handleWordcount(vaultPath, args) {
|
|
100
|
-
const
|
|
101
|
-
if (!notePath || !fs.existsSync(notePath)) {
|
|
102
|
-
throw new Error(`Note not found. Args: ${args.join(', ')}`);
|
|
103
|
-
}
|
|
104
|
-
const body = readFileText(notePath).replace(FRONTMATTER_RE, '').trim();
|
|
110
|
+
const body = handleRead(vaultPath, args).replace(FRONTMATTER_RE, '').trim();
|
|
105
111
|
const words = body.split(/\s+/).filter(Boolean).length;
|
|
106
112
|
return `${words} words`;
|
|
107
113
|
}
|
|
108
114
|
export function handleOutline(vaultPath, args) {
|
|
109
|
-
const
|
|
110
|
-
if (!notePath || !fs.existsSync(notePath)) {
|
|
111
|
-
throw new Error(`Note not found. Args: ${args.join(', ')}`);
|
|
112
|
-
}
|
|
113
|
-
const headings = readFileText(notePath)
|
|
115
|
+
const headings = handleRead(vaultPath, args)
|
|
114
116
|
.split('\n')
|
|
115
117
|
.filter((line) => /^#{1,6}\s/.test(line));
|
|
116
118
|
return headings.join('\n') || '(no headings)';
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
|
+
import { HarnessError } from '../../lib/errors.js';
|
|
3
4
|
import { markdownFileName } from './note-name.js';
|
|
4
5
|
import { appendToFile, dailyCandidates, ensureWithinRoot, FRONTMATTER_RE, getArg, getContentArg, moveFile, readFileSnapshot, resolveNotePath, todayStamp, updateFileText, writeIfUnchanged } from './vault-paths.js';
|
|
5
6
|
export function handleAppend(vaultPath, args) {
|
|
6
7
|
const notePath = resolveNotePath(vaultPath, args);
|
|
7
8
|
if (!notePath || !fs.existsSync(notePath)) {
|
|
8
|
-
throw new
|
|
9
|
+
throw new HarnessError('OBSIDIAN_NOTE_NOT_FOUND', [args]);
|
|
9
10
|
}
|
|
10
11
|
const content = getContentArg(args);
|
|
11
12
|
if (!content) {
|
|
12
|
-
throw new
|
|
13
|
+
throw new HarnessError('OBSIDIAN_MISSING_ARGUMENT', ['content=']);
|
|
13
14
|
}
|
|
14
15
|
appendToFile(notePath, content);
|
|
15
16
|
return `Appended to: ${path.relative(vaultPath, notePath)}`;
|
|
@@ -17,11 +18,11 @@ export function handleAppend(vaultPath, args) {
|
|
|
17
18
|
export function handlePrepend(vaultPath, args) {
|
|
18
19
|
const notePath = resolveNotePath(vaultPath, args);
|
|
19
20
|
if (!notePath || !fs.existsSync(notePath)) {
|
|
20
|
-
throw new
|
|
21
|
+
throw new HarnessError('OBSIDIAN_NOTE_NOT_FOUND', [args]);
|
|
21
22
|
}
|
|
22
23
|
const content = getContentArg(args);
|
|
23
24
|
if (!content) {
|
|
24
|
-
throw new
|
|
25
|
+
throw new HarnessError('OBSIDIAN_MISSING_ARGUMENT', ['content=']);
|
|
25
26
|
}
|
|
26
27
|
updateFileText(notePath, (existing) => content + existing);
|
|
27
28
|
return `Prepended to: ${path.relative(vaultPath, notePath)}`;
|
|
@@ -40,7 +41,7 @@ function uniqueTrashPath(base) {
|
|
|
40
41
|
export function handleDelete(vaultPath, args) {
|
|
41
42
|
const notePath = resolveNotePath(vaultPath, args);
|
|
42
43
|
if (!notePath || !fs.existsSync(notePath)) {
|
|
43
|
-
throw new
|
|
44
|
+
throw new HarnessError('OBSIDIAN_NOTE_NOT_FOUND', [args]);
|
|
44
45
|
}
|
|
45
46
|
const root = path.resolve(vaultPath);
|
|
46
47
|
const trashPath = uniqueTrashPath(ensureWithinRoot(vaultPath, path.join('.trash', path.relative(root, notePath))));
|
|
@@ -51,11 +52,11 @@ export function handleDelete(vaultPath, args) {
|
|
|
51
52
|
export function handleMove(vaultPath, args) {
|
|
52
53
|
const notePath = resolveNotePath(vaultPath, args);
|
|
53
54
|
if (!notePath || !fs.existsSync(notePath)) {
|
|
54
|
-
throw new
|
|
55
|
+
throw new HarnessError('OBSIDIAN_NOTE_NOT_FOUND', [args]);
|
|
55
56
|
}
|
|
56
57
|
const to = getArg(args, 'to');
|
|
57
58
|
if (!to) {
|
|
58
|
-
throw new
|
|
59
|
+
throw new HarnessError('OBSIDIAN_MISSING_ARGUMENT', ['to=']);
|
|
59
60
|
}
|
|
60
61
|
const destDir = ensureWithinRoot(vaultPath, to);
|
|
61
62
|
if (!fs.existsSync(destDir)) {
|
|
@@ -68,11 +69,11 @@ export function handleMove(vaultPath, args) {
|
|
|
68
69
|
export function handleRename(vaultPath, args) {
|
|
69
70
|
const notePath = resolveNotePath(vaultPath, args);
|
|
70
71
|
if (!notePath || !fs.existsSync(notePath)) {
|
|
71
|
-
throw new
|
|
72
|
+
throw new HarnessError('OBSIDIAN_NOTE_NOT_FOUND', [args]);
|
|
72
73
|
}
|
|
73
74
|
const newName = getArg(args, 'name');
|
|
74
75
|
if (!newName) {
|
|
75
|
-
throw new
|
|
76
|
+
throw new HarnessError('OBSIDIAN_MISSING_ARGUMENT', ['name=']);
|
|
76
77
|
}
|
|
77
78
|
const fileName = markdownFileName(newName);
|
|
78
79
|
const relativeDir = path.relative(path.resolve(vaultPath), path.dirname(notePath));
|
|
@@ -96,11 +97,11 @@ function mergeIntoFrontmatter(fmBlock, newProps) {
|
|
|
96
97
|
export function handlePropertySet(vaultPath, args) {
|
|
97
98
|
const notePath = resolveNotePath(vaultPath, args);
|
|
98
99
|
if (!notePath || !fs.existsSync(notePath)) {
|
|
99
|
-
throw new
|
|
100
|
+
throw new HarnessError('OBSIDIAN_NOTE_NOT_FOUND', [args]);
|
|
100
101
|
}
|
|
101
102
|
const propArgs = args.filter((a) => !a.startsWith('file=') && !a.startsWith('path=') && a.includes('='));
|
|
102
103
|
if (propArgs.length === 0) {
|
|
103
|
-
throw new
|
|
104
|
+
throw new HarnessError('OBSIDIAN_NO_PROPERTIES');
|
|
104
105
|
}
|
|
105
106
|
const newProps = propArgs.map((a) => {
|
|
106
107
|
const eqIdx = a.indexOf('=');
|
|
@@ -120,7 +121,7 @@ export function handlePropertySet(vaultPath, args) {
|
|
|
120
121
|
export function handleDailyAppend(vaultPath, args) {
|
|
121
122
|
const content = getContentArg(args);
|
|
122
123
|
if (!content) {
|
|
123
|
-
throw new
|
|
124
|
+
throw new HarnessError('OBSIDIAN_MISSING_ARGUMENT', ['content=']);
|
|
124
125
|
}
|
|
125
126
|
const dateStr = todayStamp();
|
|
126
127
|
let target = null;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import b4a from 'b4a';
|
|
2
|
+
const HEADER_BYTES = 54;
|
|
3
|
+
export function bmp({ width, height, data }) {
|
|
4
|
+
const row = (width * 3 + 3) & ~3;
|
|
5
|
+
const bytes = b4a.alloc(HEADER_BYTES + row * height);
|
|
6
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
7
|
+
bytes[0] = 0x42;
|
|
8
|
+
bytes[1] = 0x4d;
|
|
9
|
+
view.setUint32(2, bytes.byteLength, true);
|
|
10
|
+
view.setUint32(10, HEADER_BYTES, true);
|
|
11
|
+
view.setUint32(14, 40, true);
|
|
12
|
+
view.setInt32(18, width, true);
|
|
13
|
+
view.setInt32(22, height, true);
|
|
14
|
+
view.setUint16(26, 1, true);
|
|
15
|
+
view.setUint16(28, 24, true);
|
|
16
|
+
view.setUint32(34, row * height, true);
|
|
17
|
+
for (let y = 0; y < height; y++) {
|
|
18
|
+
const from = (height - 1 - y) * width * 4;
|
|
19
|
+
const to = HEADER_BYTES + y * row;
|
|
20
|
+
for (let x = 0; x < width; x++) {
|
|
21
|
+
bytes[to + x * 3] = data[from + x * 4 + 2] ?? 0;
|
|
22
|
+
bytes[to + x * 3 + 1] = data[from + x * 4 + 1] ?? 0;
|
|
23
|
+
bytes[to + x * 3 + 2] = data[from + x * 4] ?? 0;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return bytes;
|
|
27
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const BOX_PAD = 2;
|
|
2
|
+
export function inkCoverage(image, blocks) {
|
|
3
|
+
const lum = luminance(image);
|
|
4
|
+
const level = otsu(lum);
|
|
5
|
+
const words = wordMask(image, blocks);
|
|
6
|
+
let ink = 0;
|
|
7
|
+
let covered = 0;
|
|
8
|
+
for (let i = 0; i < lum.length; i++) {
|
|
9
|
+
if ((lum[i] ?? 0) > level)
|
|
10
|
+
continue;
|
|
11
|
+
ink++;
|
|
12
|
+
covered += words[i] ?? 0;
|
|
13
|
+
}
|
|
14
|
+
return ink === 0 ? 1 : covered / ink;
|
|
15
|
+
}
|
|
16
|
+
function luminance({ width, height, data }) {
|
|
17
|
+
const lum = new Uint8Array(width * height);
|
|
18
|
+
for (let i = 0; i < lum.length; i++) {
|
|
19
|
+
const at = i * 4;
|
|
20
|
+
lum[i] = ((data[at] ?? 0) * 299 + (data[at + 1] ?? 0) * 587 + (data[at + 2] ?? 0) * 114) / 1000;
|
|
21
|
+
}
|
|
22
|
+
return lum;
|
|
23
|
+
}
|
|
24
|
+
function otsu(lum) {
|
|
25
|
+
const counts = new Float64Array(256);
|
|
26
|
+
for (const value of lum) {
|
|
27
|
+
counts[value] = (counts[value] ?? 0) + 1;
|
|
28
|
+
}
|
|
29
|
+
let total = 0;
|
|
30
|
+
counts.forEach((count, value) => {
|
|
31
|
+
total += value * count;
|
|
32
|
+
});
|
|
33
|
+
let dark = 0;
|
|
34
|
+
let darkSum = 0;
|
|
35
|
+
let best = -1;
|
|
36
|
+
let level = 0;
|
|
37
|
+
counts.forEach((count, value) => {
|
|
38
|
+
dark += count;
|
|
39
|
+
darkSum += value * count;
|
|
40
|
+
const light = lum.length - dark;
|
|
41
|
+
if (dark === 0 || light === 0) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const between = dark * light * (darkSum / dark - (total - darkSum) / light) ** 2;
|
|
45
|
+
if (between > best) {
|
|
46
|
+
best = between;
|
|
47
|
+
level = value;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
return level;
|
|
51
|
+
}
|
|
52
|
+
function wordMask({ width, height }, blocks) {
|
|
53
|
+
const mask = new Uint8Array(width * height);
|
|
54
|
+
for (const { bbox } of blocks) {
|
|
55
|
+
if (!bbox)
|
|
56
|
+
continue;
|
|
57
|
+
const [x0, y0, x1, y1] = bbox;
|
|
58
|
+
const left = Math.max(0, Math.floor(x0) - BOX_PAD);
|
|
59
|
+
const right = Math.min(width, Math.ceil(x1) + BOX_PAD);
|
|
60
|
+
const top = Math.max(0, Math.floor(y0) - BOX_PAD);
|
|
61
|
+
const bottom = Math.min(height, Math.ceil(y1) + BOX_PAD);
|
|
62
|
+
for (let y = top; y < bottom; y++) {
|
|
63
|
+
mask.fill(1, y * width + left, y * width + right);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return mask;
|
|
67
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { HarnessPlugin, PluginContext, PluginSetup } from '../../lib/plugins/index.ts';
|
|
2
|
+
export declare class Ocr implements HarnessPlugin {
|
|
3
|
+
readonly name = "ocr";
|
|
4
|
+
readonly api = 1;
|
|
5
|
+
readonly provides: string[];
|
|
6
|
+
readonly needs: string[];
|
|
7
|
+
readonly addons: {
|
|
8
|
+
'ocr-ggml': () => Promise<(callback: (priority: number, message: string) => void) => void>;
|
|
9
|
+
};
|
|
10
|
+
constructor();
|
|
11
|
+
setup(ctx: PluginContext): PluginSetup;
|
|
12
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { PluginRegistry } from '../../lib/plugins/index.js';
|
|
2
|
+
import { OcrRuntime } from './ocr-runtime.js';
|
|
3
|
+
export class Ocr {
|
|
4
|
+
name = 'ocr';
|
|
5
|
+
api = PluginRegistry.API_VERSION;
|
|
6
|
+
provides = ['ocr'];
|
|
7
|
+
needs = ['models'];
|
|
8
|
+
addons = {
|
|
9
|
+
'ocr-ggml': async () => (await import('@qvac/ocr-ggml/addonLogging')).default.setLogger
|
|
10
|
+
};
|
|
11
|
+
constructor() {
|
|
12
|
+
PluginRegistry.requirePeers('ocr', {
|
|
13
|
+
'@qvac/ocr-ggml': () => import.meta.resolve('@qvac/ocr-ggml/addonLogging')
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
setup(ctx) {
|
|
17
|
+
const runtime = new OcrRuntime(ctx.service('models'));
|
|
18
|
+
return { services: { ocr: runtime }, unloadIdle: () => runtime.unloadIdle() };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { AbortSignal as BareAbortSignal } from 'bare-abort-controller';
|
|
2
|
+
import type { ModelHost } from '../../lib/contract/models.ts';
|
|
3
|
+
import type { OcrImage, OcrPage, OcrService } from '../../lib/contract/ocr.ts';
|
|
4
|
+
import { type OcrBlock } from './reading-order.ts';
|
|
5
|
+
export interface OcrSdk {
|
|
6
|
+
ocr(params: {
|
|
7
|
+
modelId: string;
|
|
8
|
+
image: Uint8Array;
|
|
9
|
+
}): {
|
|
10
|
+
blocks: Promise<OcrBlock[]>;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export declare class OcrRuntime implements OcrService {
|
|
14
|
+
private readonly _models;
|
|
15
|
+
private readonly _loadSdk;
|
|
16
|
+
private readonly _pool;
|
|
17
|
+
private _tail;
|
|
18
|
+
private readonly _kept;
|
|
19
|
+
constructor(models: ModelHost);
|
|
20
|
+
read(image: OcrImage, signal?: BareAbortSignal): Promise<OcrPage>;
|
|
21
|
+
unloadIdle(): Promise<void>;
|
|
22
|
+
private _recognize;
|
|
23
|
+
private _open;
|
|
24
|
+
private _serial;
|
|
25
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { createHash } from 'crypto';
|
|
2
|
+
import { OCR_DOCTR, OCR_DOCTR_1 } from '@qvac/inference/models';
|
|
3
|
+
import { errorMessage } from '../../lib/guards.js';
|
|
4
|
+
import { raceAbort } from '../../lib/helpers/race-abort.js';
|
|
5
|
+
import { RecentMap } from '../../lib/helpers/recent-map.js';
|
|
6
|
+
import { retryMemo } from '../../lib/helpers/retry-memo.js';
|
|
7
|
+
import { HarnessLog } from '../../lib/log.js';
|
|
8
|
+
import { bmp } from './bmp.js';
|
|
9
|
+
import { inkCoverage } from './coverage.js';
|
|
10
|
+
import { readingOrder } from './reading-order.js';
|
|
11
|
+
const OCR_MODEL_LABEL = 'OCR model';
|
|
12
|
+
const KEPT_PAGES = 1024;
|
|
13
|
+
function ocrSdk(models) {
|
|
14
|
+
return retryMemo(async () => {
|
|
15
|
+
const sdk = await models.sdk();
|
|
16
|
+
if (typeof globalThis.Bare !== 'undefined') {
|
|
17
|
+
const [{ ocrPlugin }, { registerPlugin }] = await Promise.all([
|
|
18
|
+
import('@qvac/inference/ggml-ocr/plugin'),
|
|
19
|
+
import('@qvac/inference/plugin-registry')
|
|
20
|
+
]);
|
|
21
|
+
try {
|
|
22
|
+
registerPlugin(ocrPlugin);
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
HarnessLog.warn('plugin registration skipped', { plugin: 'ocr', err: errorMessage(err) });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return sdk;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
export class OcrRuntime {
|
|
32
|
+
_models;
|
|
33
|
+
_loadSdk;
|
|
34
|
+
_pool;
|
|
35
|
+
_tail = Promise.resolve();
|
|
36
|
+
_kept = new RecentMap(KEPT_PAGES);
|
|
37
|
+
constructor(models) {
|
|
38
|
+
this._models = models;
|
|
39
|
+
this._loadSdk = ocrSdk(models);
|
|
40
|
+
this._pool = models.registerPool({
|
|
41
|
+
addon: 'ocr',
|
|
42
|
+
modelType: 'ggml-ocr',
|
|
43
|
+
modelConfig: { pipelineType: 'doctr', detectorModelSrc: OCR_DOCTR_1 },
|
|
44
|
+
label: OCR_MODEL_LABEL,
|
|
45
|
+
sdk: this._loadSdk
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
async read(image, signal) {
|
|
49
|
+
const key = pageKey(image);
|
|
50
|
+
const kept = this._kept.get(key);
|
|
51
|
+
if (kept) {
|
|
52
|
+
return kept;
|
|
53
|
+
}
|
|
54
|
+
const page = await this._recognize(image, signal);
|
|
55
|
+
this._kept.set(key, page);
|
|
56
|
+
return page;
|
|
57
|
+
}
|
|
58
|
+
unloadIdle() {
|
|
59
|
+
return this._pool.evictIdle(() => true);
|
|
60
|
+
}
|
|
61
|
+
async _recognize(image, signal) {
|
|
62
|
+
const { held, releaseWork } = this._open();
|
|
63
|
+
let job = null;
|
|
64
|
+
try {
|
|
65
|
+
const { modelId } = await raceAbort(held.load(), signal);
|
|
66
|
+
const sdk = await this._loadSdk();
|
|
67
|
+
job = this._serial(async () => {
|
|
68
|
+
const blocks = await sdk.ocr({ modelId, image: bmp(image) }).blocks;
|
|
69
|
+
return { text: readingOrder(blocks), coverage: inkCoverage(image, blocks) };
|
|
70
|
+
});
|
|
71
|
+
return await raceAbort(job, signal);
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
void Promise.allSettled([job ?? held.peek()]).then(() => {
|
|
75
|
+
try {
|
|
76
|
+
held.release();
|
|
77
|
+
}
|
|
78
|
+
finally {
|
|
79
|
+
releaseWork();
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
_open() {
|
|
85
|
+
const releaseWork = this._models.enterWork();
|
|
86
|
+
try {
|
|
87
|
+
return { held: this._pool.open(OCR_DOCTR.src), releaseWork };
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
releaseWork();
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
_serial(job) {
|
|
95
|
+
const run = this._tail.then(job);
|
|
96
|
+
this._tail = run.catch(noop);
|
|
97
|
+
return run;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function noop() { }
|
|
101
|
+
function pageKey({ width, height, data }) {
|
|
102
|
+
return createHash('sha256').update(`${width}x${height}:`).update(data).digest('hex');
|
|
103
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
const COLUMNS = { start: 'left', end: 'right' };
|
|
2
|
+
const ROWS = { start: 'top', end: 'bottom' };
|
|
3
|
+
const COLUMN_GAP = 1.5;
|
|
4
|
+
const BLOCK_GAP = 1;
|
|
5
|
+
const COLUMN_WORDS = 4;
|
|
6
|
+
const MARGIN_LINES = 0.6;
|
|
7
|
+
const MARGIN_MIN_LINES = 10;
|
|
8
|
+
const SPANNED_LINES = 0.2;
|
|
9
|
+
const MARGIN_SLACK = 0.25;
|
|
10
|
+
const SPANS = 0.5;
|
|
11
|
+
const HEADING_INSET = 0.25;
|
|
12
|
+
export function readingOrder(blocks) {
|
|
13
|
+
const words = blocks.flatMap(({ text, bbox }) => bbox ? [{ text, left: bbox[0], top: bbox[1], right: bbox[2], bottom: bbox[3] }] : []);
|
|
14
|
+
if (words.length < blocks.length) {
|
|
15
|
+
return blocks.map((block) => block.text).join('\n');
|
|
16
|
+
}
|
|
17
|
+
const level = deskewed(words);
|
|
18
|
+
return regionLines(level, medianHeight(level)).join('\n');
|
|
19
|
+
}
|
|
20
|
+
function deskewed(words) {
|
|
21
|
+
const gutter = medianHeight(words) * COLUMN_GAP;
|
|
22
|
+
const slants = chainLines(words).flatMap(({ words: line }) => segments(line, gutter).flatMap((run) => (run.length >= 3 ? [slope(run)] : [])));
|
|
23
|
+
const tilt = slants.sort((a, b) => a - b)[Math.floor(slants.length / 2)] ?? 0;
|
|
24
|
+
if (tilt === 0 || slants.length < MARGIN_MIN_LINES) {
|
|
25
|
+
return [...words];
|
|
26
|
+
}
|
|
27
|
+
return words.map((word) => {
|
|
28
|
+
const across = tilt * middle(word);
|
|
29
|
+
const down = tilt * centre(word);
|
|
30
|
+
const { text, left, top, right, bottom } = word;
|
|
31
|
+
return {
|
|
32
|
+
text,
|
|
33
|
+
left: left + across,
|
|
34
|
+
right: right + across,
|
|
35
|
+
top: top - down,
|
|
36
|
+
bottom: bottom - down
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function slope(run) {
|
|
41
|
+
const first = run[0];
|
|
42
|
+
const last = run.at(-1);
|
|
43
|
+
if (!first || !last || centre(last) === centre(first)) {
|
|
44
|
+
return 0;
|
|
45
|
+
}
|
|
46
|
+
return (middle(last) - middle(first)) / (centre(last) - centre(first));
|
|
47
|
+
}
|
|
48
|
+
function segments(line, gutter) {
|
|
49
|
+
const runs = [];
|
|
50
|
+
let reach = -Infinity;
|
|
51
|
+
for (const word of line) {
|
|
52
|
+
if (word.left - reach >= gutter) {
|
|
53
|
+
runs.push([]);
|
|
54
|
+
}
|
|
55
|
+
runs.at(-1)?.push(word);
|
|
56
|
+
reach = Math.max(reach, word.right);
|
|
57
|
+
}
|
|
58
|
+
return runs;
|
|
59
|
+
}
|
|
60
|
+
function regionLines(words, lineHeight) {
|
|
61
|
+
const columns = dense(split(words, COLUMNS, lineHeight * COLUMN_GAP)) ?? dense(marginColumns(words, lineHeight));
|
|
62
|
+
if (columns) {
|
|
63
|
+
return columns.flatMap((column) => regionLines(column, lineHeight));
|
|
64
|
+
}
|
|
65
|
+
const blocks = split(words, ROWS, lineHeight * BLOCK_GAP) ?? spannedBands(words, lineHeight);
|
|
66
|
+
if (blocks) {
|
|
67
|
+
return blocks.flatMap((block) => regionLines(block, lineHeight));
|
|
68
|
+
}
|
|
69
|
+
return chainLines(words).map((line) => line.words.map((word) => word.text).join(' '));
|
|
70
|
+
}
|
|
71
|
+
function split(words, { start, end }, gap) {
|
|
72
|
+
const parts = [];
|
|
73
|
+
let reach = -Infinity;
|
|
74
|
+
for (const word of [...words].sort((a, b) => a[start] - b[start])) {
|
|
75
|
+
if (word[start] - reach >= gap) {
|
|
76
|
+
parts.push([]);
|
|
77
|
+
}
|
|
78
|
+
parts.at(-1)?.push(word);
|
|
79
|
+
reach = Math.max(reach, word[end]);
|
|
80
|
+
}
|
|
81
|
+
return parts.length > 1 ? parts : null;
|
|
82
|
+
}
|
|
83
|
+
function dense(columns) {
|
|
84
|
+
const text = columns?.every((column) => column.length / chainLines(column).length >= COLUMN_WORDS);
|
|
85
|
+
return text ? columns : null;
|
|
86
|
+
}
|
|
87
|
+
function marginColumns(words, lineHeight) {
|
|
88
|
+
const region = regionOf(words, lineHeight);
|
|
89
|
+
const { edges } = region;
|
|
90
|
+
if (edges.length === 0 || chainLines(words).some((line) => spanning(line, region))) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
const slack = lineHeight * MARGIN_SLACK;
|
|
94
|
+
const columns = edges.map(() => []);
|
|
95
|
+
columns.push([]);
|
|
96
|
+
for (const word of words) {
|
|
97
|
+
columns[edges.filter((edge) => word.left >= edge - slack).length]?.push(word);
|
|
98
|
+
}
|
|
99
|
+
return columns;
|
|
100
|
+
}
|
|
101
|
+
function spannedBands(words, lineHeight) {
|
|
102
|
+
const region = regionOf(words, lineHeight);
|
|
103
|
+
const { edges } = region;
|
|
104
|
+
const bands = [];
|
|
105
|
+
let across = true;
|
|
106
|
+
for (const line of chainLines(words)) {
|
|
107
|
+
const parts = spanning(line, region);
|
|
108
|
+
if (parts || across) {
|
|
109
|
+
bands.push([]);
|
|
110
|
+
}
|
|
111
|
+
bands.at(-1)?.push(...line.words);
|
|
112
|
+
across = parts;
|
|
113
|
+
}
|
|
114
|
+
return edges.length > 0 && bands.length > 1 ? bands : null;
|
|
115
|
+
}
|
|
116
|
+
function columnEdges(words, lineHeight) {
|
|
117
|
+
const lines = chainLines(words);
|
|
118
|
+
if (lines.length < MARGIN_MIN_LINES) {
|
|
119
|
+
return [];
|
|
120
|
+
}
|
|
121
|
+
const edges = sharedEdges(words, lineHeight * MARGIN_SLACK, lines.length * MARGIN_LINES);
|
|
122
|
+
return edges.filter((edge) => {
|
|
123
|
+
const before = words.filter((word) => word.right <= edge);
|
|
124
|
+
const across = lines.filter((line) => line.words.some((word) => spans(word, [edge], lineHeight)));
|
|
125
|
+
return dense([before]) !== null && across.length <= lines.length * SPANNED_LINES;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
function regionOf(words, lineHeight) {
|
|
129
|
+
const firsts = chainLines(words)
|
|
130
|
+
.map((line) => line.first.left)
|
|
131
|
+
.sort((a, b) => a - b);
|
|
132
|
+
const start = firsts[Math.floor(firsts.length / 2)] ?? 0;
|
|
133
|
+
const end = Math.max(...words.map((word) => word.right));
|
|
134
|
+
return { edges: columnEdges(words, lineHeight), start, end, lineHeight };
|
|
135
|
+
}
|
|
136
|
+
function spanning(line, region) {
|
|
137
|
+
const { edges, lineHeight } = region;
|
|
138
|
+
return line.words.some((word) => spans(word, edges, lineHeight)) || heading(line, region);
|
|
139
|
+
}
|
|
140
|
+
function heading({ words }, { edges, start, end, lineHeight }) {
|
|
141
|
+
const ordered = [...words].sort((a, b) => a.left - b.left);
|
|
142
|
+
const first = ordered[0];
|
|
143
|
+
const last = ordered.at(-1);
|
|
144
|
+
const inset = ((end - start) / (edges.length + 1)) * HEADING_INSET;
|
|
145
|
+
if (!first || !last || first.left < start + inset || last.right > end - inset) {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
const slack = lineHeight * MARGIN_SLACK;
|
|
149
|
+
return ordered.slice(1).some((word, at) => {
|
|
150
|
+
const before = ordered[at];
|
|
151
|
+
return (before !== undefined &&
|
|
152
|
+
word.left - before.right < lineHeight * COLUMN_GAP &&
|
|
153
|
+
edges.some((edge) => before.left < edge - slack && word.left >= edge - slack));
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
function spans({ left, right }, edges, lineHeight) {
|
|
157
|
+
const reach = lineHeight * SPANS;
|
|
158
|
+
return edges.some((edge) => left < edge - reach && right > edge + reach);
|
|
159
|
+
}
|
|
160
|
+
function sharedEdges(words, slack, least) {
|
|
161
|
+
const lefts = words.map((word) => word.left).sort((a, b) => a - b);
|
|
162
|
+
const windows = [];
|
|
163
|
+
let to = 0;
|
|
164
|
+
for (const [from, edge] of lefts.entries()) {
|
|
165
|
+
while (to < lefts.length && (lefts[to] ?? 0) <= edge + slack) {
|
|
166
|
+
to++;
|
|
167
|
+
}
|
|
168
|
+
if (to - from >= least) {
|
|
169
|
+
windows.push({ edge, count: to - from });
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
const edges = [];
|
|
173
|
+
for (const { edge } of windows.sort((a, b) => b.count - a.count)) {
|
|
174
|
+
if (edges.every((kept) => Math.abs(kept - edge) > slack)) {
|
|
175
|
+
edges.push(edge);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return edges.sort((a, b) => a - b);
|
|
179
|
+
}
|
|
180
|
+
function chainLines(words) {
|
|
181
|
+
const lines = [];
|
|
182
|
+
for (const word of [...words].sort((a, b) => a.left - b.left)) {
|
|
183
|
+
const line = levelWith(lines, word);
|
|
184
|
+
if (line) {
|
|
185
|
+
line.words.push(word);
|
|
186
|
+
line.last = word;
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
lines.push({ first: word, last: word, words: [word] });
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return lines.sort((a, b) => middle(a.first) - middle(b.first));
|
|
193
|
+
}
|
|
194
|
+
function levelWith(lines, word) {
|
|
195
|
+
let closest;
|
|
196
|
+
let offset = Infinity;
|
|
197
|
+
for (const line of lines) {
|
|
198
|
+
const apart = Math.abs(middle(line.last) - middle(word));
|
|
199
|
+
if (apart < height(line.last) / 2 && apart < offset) {
|
|
200
|
+
closest = line;
|
|
201
|
+
offset = apart;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return closest;
|
|
205
|
+
}
|
|
206
|
+
function middle(word) {
|
|
207
|
+
return (word.top + word.bottom) / 2;
|
|
208
|
+
}
|
|
209
|
+
function centre(word) {
|
|
210
|
+
return (word.left + word.right) / 2;
|
|
211
|
+
}
|
|
212
|
+
function height(word) {
|
|
213
|
+
return word.bottom - word.top;
|
|
214
|
+
}
|
|
215
|
+
function medianHeight(words) {
|
|
216
|
+
const heights = words.map(height).sort((a, b) => a - b);
|
|
217
|
+
return heights[Math.floor(heights.length / 2)] ?? 0;
|
|
218
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|