@bastani/atomic 0.9.2 → 0.9.3-alpha.2
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 +66 -0
- package/README.md +2 -2
- package/dist/builtin/cursor/CHANGELOG.md +15 -0
- package/dist/builtin/cursor/README.md +2 -1
- package/dist/builtin/cursor/package.json +2 -2
- package/dist/builtin/cursor/src/cursor-models-raw.json +2 -9
- package/dist/builtin/cursor/src/model-mapper.ts +14 -3
- package/dist/builtin/cursor/src/proto/protobuf-codec-base64.ts +22 -0
- package/dist/builtin/cursor/src/proto/protobuf-codec-request.ts +53 -13
- package/dist/builtin/cursor/src/proto/protobuf-codec-wire.ts +24 -7
- package/dist/builtin/cursor/src/proto/protobuf-codec.ts +3 -2
- package/dist/builtin/cursor/src/stream.ts +5 -11
- package/dist/builtin/cursor/src/transport-types.ts +3 -0
- package/dist/builtin/cursor/src/transport.ts +1 -0
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/CHANGELOG.md +6 -0
- package/dist/builtin/mcp/direct-tools.ts +4 -2
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/mcp/proxy-call.ts +3 -1
- package/dist/builtin/mcp/utils.ts +18 -7
- package/dist/builtin/subagents/CHANGELOG.md +20 -0
- package/dist/builtin/subagents/README.md +6 -6
- package/dist/builtin/subagents/agents/code-simplifier.md +7 -6
- package/dist/builtin/subagents/agents/codebase-analyzer.md +5 -4
- package/dist/builtin/subagents/agents/codebase-locator.md +3 -3
- package/dist/builtin/subagents/agents/codebase-online-researcher.md +10 -10
- package/dist/builtin/subagents/agents/codebase-pattern-finder.md +4 -4
- package/dist/builtin/subagents/agents/codebase-research-analyzer.md +3 -3
- package/dist/builtin/subagents/agents/codebase-research-locator.md +4 -4
- package/dist/builtin/subagents/agents/debugger.md +5 -5
- package/dist/builtin/subagents/agents/worker.md +56 -0
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/skills/subagent/SKILL.md +11 -11
- package/dist/builtin/subagents/src/agents/agent-loaders.ts +3 -5
- package/dist/builtin/subagents/src/agents/agent-management-helpers.ts +3 -3
- package/dist/builtin/subagents/src/extension/fanout-child.ts +1 -0
- package/dist/builtin/subagents/src/extension/index.ts +6 -3
- package/dist/builtin/subagents/src/extension/schemas.ts +2 -7
- package/dist/builtin/subagents/src/intercom/result-intercom.ts +4 -3
- package/dist/builtin/subagents/src/runs/background/async-job-tracker.ts +1 -4
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-single.ts +15 -1
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor.ts +35 -1
- package/dist/builtin/subagents/src/runs/shared/mcp-direct-tool-allowlist.ts +1 -1
- package/dist/builtin/subagents/src/runs/shared/nested-render.ts +2 -2
- package/dist/builtin/subagents/src/runs/shared/pi-args.ts +2 -1
- package/dist/builtin/subagents/src/runs/shared/subagent-prompt-runtime.ts +4 -2
- package/dist/builtin/subagents/src/shared/types-async.ts +1 -0
- package/dist/builtin/subagents/src/shared/types-depth.ts +5 -5
- package/dist/builtin/subagents/src/shared/types-runtime.ts +2 -1
- package/dist/builtin/subagents/src/slash/prompt-template-bridge.ts +27 -5
- package/dist/builtin/subagents/src/tui/render-event-formatting.ts +2 -2
- package/dist/builtin/subagents/src/tui/render-layout.ts +27 -4
- package/dist/builtin/subagents/src/tui/render-result-animation.ts +22 -31
- package/dist/builtin/subagents/src/tui/render-result-compact.ts +6 -6
- package/dist/builtin/subagents/src/tui/render-result.ts +20 -19
- package/dist/builtin/subagents/src/tui/render-status-progress.ts +3 -3
- package/dist/builtin/subagents/src/tui/render-widget.ts +46 -7
- package/dist/builtin/subagents/src/tui/render.ts +2 -2
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/CHANGELOG.md +56 -0
- package/dist/builtin/workflows/README.md +3 -3
- package/dist/builtin/workflows/builtin/goal-artifacts.ts +11 -6
- package/dist/builtin/workflows/builtin/goal-ledger.ts +33 -1
- package/dist/builtin/workflows/builtin/goal-prompts.ts +23 -28
- package/dist/builtin/workflows/builtin/goal-reducer.ts +2 -2
- package/dist/builtin/workflows/builtin/goal-reports.ts +2 -5
- package/dist/builtin/workflows/builtin/goal-review.ts +1 -1
- package/dist/builtin/workflows/builtin/goal-runner.ts +10 -17
- package/dist/builtin/workflows/builtin/open-claude-design-feedback.ts +3 -3
- package/dist/builtin/workflows/builtin/open-claude-design-phases.ts +1 -3
- package/dist/builtin/workflows/builtin/open-claude-design-setup.ts +1 -1
- package/dist/builtin/workflows/builtin/ralph-core.ts +7 -17
- package/dist/builtin/workflows/builtin/ralph-runner.ts +11 -18
- package/dist/builtin/workflows/builtin/shared-prompts.ts +1 -1
- package/dist/builtin/workflows/package.json +1 -1
- package/dist/builtin/workflows/src/authoring.d.ts +1 -1
- package/dist/builtin/workflows/src/durable/backend.ts +343 -0
- package/dist/builtin/workflows/src/durable/child-primitive.ts +79 -0
- package/dist/builtin/workflows/src/durable/dbos-backend.ts +421 -0
- package/dist/builtin/workflows/src/durable/dbos-envelope.ts +171 -0
- package/dist/builtin/workflows/src/durable/factory.ts +96 -0
- package/dist/builtin/workflows/src/durable/file-backend.ts +433 -0
- package/dist/builtin/workflows/src/durable/index.ts +73 -0
- package/dist/builtin/workflows/src/durable/resume-catalog.ts +217 -0
- package/dist/builtin/workflows/src/durable/resume-runtime.ts +299 -0
- package/dist/builtin/workflows/src/durable/scoped-backend.ts +171 -0
- package/dist/builtin/workflows/src/durable/stage-primitive.ts +284 -0
- package/dist/builtin/workflows/src/durable/tool-primitive.ts +180 -0
- package/dist/builtin/workflows/src/durable/types.ts +168 -0
- package/dist/builtin/workflows/src/durable/ui-primitive.ts +96 -0
- package/dist/builtin/workflows/src/engine/options.ts +3 -0
- package/dist/builtin/workflows/src/engine/primitives/parallel.ts +2 -2
- package/dist/builtin/workflows/src/engine/primitives/task.ts +4 -4
- package/dist/builtin/workflows/src/engine/primitives/ui.ts +22 -8
- package/dist/builtin/workflows/src/engine/primitives/workflow.ts +8 -0
- package/dist/builtin/workflows/src/engine/run-durable-finalize.ts +69 -0
- package/dist/builtin/workflows/src/engine/run-durable-stage-session.ts +31 -0
- package/dist/builtin/workflows/src/engine/run.ts +148 -6
- package/dist/builtin/workflows/src/engine/runtime.ts +8 -2
- package/dist/builtin/workflows/src/extension/config-loader.ts +35 -15
- package/dist/builtin/workflows/src/extension/discovery.ts +20 -8
- package/dist/builtin/workflows/src/extension/extension-factory.ts +6 -12
- package/dist/builtin/workflows/src/extension/extension-lifecycle.ts +5 -1
- package/dist/builtin/workflows/src/extension/extension-runtime-state.ts +4 -2
- package/dist/builtin/workflows/src/extension/runtime.ts +48 -9
- package/dist/builtin/workflows/src/extension/wiring.ts +1 -1
- package/dist/builtin/workflows/src/extension/workflow-run-control-command.ts +143 -4
- package/dist/builtin/workflows/src/runs/background/quit.ts +61 -0
- package/dist/builtin/workflows/src/runs/background/status.ts +1 -0
- package/dist/builtin/workflows/src/runs/foreground/executor-direct-helpers.ts +5 -5
- package/dist/builtin/workflows/src/runs/foreground/executor-stage-call.ts +74 -33
- package/dist/builtin/workflows/src/runs/foreground/executor-stage-context.ts +20 -1
- package/dist/builtin/workflows/src/runs/foreground/executor-stage-factory.ts +8 -7
- package/dist/builtin/workflows/src/runs/foreground/executor-stage-replay.ts +1 -0
- package/dist/builtin/workflows/src/runs/foreground/executor-stage-types.ts +1 -1
- package/dist/builtin/workflows/src/runs/foreground/executor-types.ts +19 -2
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-context.ts +4 -0
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-controller.ts +10 -10
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-options.ts +5 -1
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-send-user-message.ts +25 -0
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-types.ts +3 -0
- package/dist/builtin/workflows/src/shared/authoring-contract-stage.d.ts +16 -0
- package/dist/builtin/workflows/src/shared/authoring-contract-stage.ts +20 -0
- package/dist/builtin/workflows/src/shared/authoring-contract-ui.d.ts +23 -1
- package/dist/builtin/workflows/src/shared/authoring-contract-ui.ts +30 -1
- package/dist/builtin/workflows/src/shared/store-public-types.ts +6 -2
- package/dist/builtin/workflows/src/shared/store-run-methods.ts +12 -6
- package/dist/builtin/workflows/src/shared/types.ts +55 -0
- package/dist/builtin/workflows/src/tui/dispatch-confirm.ts +11 -10
- package/dist/builtin/workflows/src/tui/graph-view-constants.ts +1 -1
- package/dist/builtin/workflows/src/tui/graph-view-graph-render.ts +41 -0
- package/dist/builtin/workflows/src/tui/graph-view-input.ts +82 -24
- package/dist/builtin/workflows/src/tui/graph-view-render.ts +7 -0
- package/dist/builtin/workflows/src/tui/graph-view-state.ts +22 -2
- package/dist/builtin/workflows/src/tui/graph-view-types.ts +4 -5
- package/dist/builtin/workflows/src/tui/overlay-adapter.ts +9 -11
- package/dist/builtin/workflows/src/tui/stage-chat-view-footer-status.ts +9 -3
- package/dist/builtin/workflows/src/tui/stage-chat-view-input.ts +11 -2
- package/dist/builtin/workflows/src/tui/stage-chat-view-live-events.ts +35 -0
- package/dist/builtin/workflows/src/tui/stage-chat-view-state.ts +51 -17
- package/dist/builtin/workflows/src/tui/stage-chat-view-status.ts +36 -0
- package/dist/builtin/workflows/src/tui/stage-chat-view-types.ts +5 -1
- package/dist/builtin/workflows/src/tui/stage-chat-view.ts +3 -1
- package/dist/builtin/workflows/src/tui/status-list.ts +14 -2
- package/dist/builtin/workflows/src/tui/widget.ts +23 -8
- package/dist/builtin/workflows/src/tui/workflow-attach-pane-types.ts +5 -4
- package/dist/builtin/workflows/src/tui/workflow-attach-pane.ts +8 -8
- package/dist/builtin/workflows/src/tui/workflow-resume-selector.ts +151 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +9 -9
- package/dist/cli/args.js.map +1 -1
- package/dist/config-self-update.d.ts.map +1 -1
- package/dist/config-self-update.js +3 -4
- package/dist/config-self-update.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +4 -5
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-bash.d.ts +1 -0
- package/dist/core/agent-session-bash.d.ts.map +1 -1
- package/dist/core/agent-session-bash.js +1 -0
- package/dist/core/agent-session-bash.js.map +1 -1
- package/dist/core/agent-session-tool-registry.d.ts.map +1 -1
- package/dist/core/agent-session-tool-registry.js +23 -0
- package/dist/core/agent-session-tool-registry.js.map +1 -1
- package/dist/core/bash-executor.d.ts +2 -0
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js +1 -0
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +29 -0
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +36 -1
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/compaction/context-compaction-metrics.d.ts +14 -2
- package/dist/core/compaction/context-compaction-metrics.d.ts.map +1 -1
- package/dist/core/compaction/context-compaction-metrics.js +50 -1
- package/dist/core/compaction/context-compaction-metrics.js.map +1 -1
- package/dist/core/compaction/context-compaction-prompt.d.ts.map +1 -1
- package/dist/core/compaction/context-compaction-prompt.js +2 -0
- package/dist/core/compaction/context-compaction-prompt.js.map +1 -1
- package/dist/core/compaction/context-compaction-runner.d.ts.map +1 -1
- package/dist/core/compaction/context-compaction-runner.js +1 -1
- package/dist/core/compaction/context-compaction-runner.js.map +1 -1
- package/dist/core/compaction/context-deletion-application.d.ts.map +1 -1
- package/dist/core/compaction/context-deletion-application.js +5 -5
- package/dist/core/compaction/context-deletion-application.js.map +1 -1
- package/dist/core/compaction/context-deletion-targets.d.ts +2 -0
- package/dist/core/compaction/context-deletion-targets.d.ts.map +1 -1
- package/dist/core/compaction/context-deletion-targets.js +23 -3
- package/dist/core/compaction/context-deletion-targets.js.map +1 -1
- package/dist/core/compaction/context-deletion-tool-definitions.d.ts +6 -0
- package/dist/core/compaction/context-deletion-tool-definitions.d.ts.map +1 -1
- package/dist/core/compaction/context-deletion-tool-definitions.js.map +1 -1
- package/dist/core/compaction/context-deletion-tools.d.ts.map +1 -1
- package/dist/core/compaction/context-deletion-tools.js +18 -10
- package/dist/core/compaction/context-deletion-tools.js.map +1 -1
- package/dist/core/compaction/context-transcript-analysis.d.ts.map +1 -1
- package/dist/core/compaction/context-transcript-analysis.js +2 -4
- package/dist/core/compaction/context-transcript-analysis.js.map +1 -1
- package/dist/core/copilot-gemini-tool-arguments.d.ts.map +1 -1
- package/dist/core/copilot-gemini-tool-arguments.js +2 -60
- package/dist/core/copilot-gemini-tool-arguments.js.map +1 -1
- package/dist/core/extensions/context-types.d.ts +2 -0
- package/dist/core/extensions/context-types.d.ts.map +1 -1
- package/dist/core/extensions/context-types.js.map +1 -1
- package/dist/core/extensions/index.d.ts +2 -2
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader-virtual-modules.d.ts.map +1 -1
- package/dist/core/extensions/loader-virtual-modules.js +57 -32
- package/dist/core/extensions/loader-virtual-modules.js.map +1 -1
- package/dist/core/extensions/runner-context.d.ts.map +1 -1
- package/dist/core/extensions/runner-context.js +11 -0
- package/dist/core/extensions/runner-context.js.map +1 -1
- package/dist/core/extensions/tool-events.d.ts +13 -13
- package/dist/core/extensions/tool-events.d.ts.map +1 -1
- package/dist/core/extensions/tool-events.js +3 -3
- package/dist/core/extensions/tool-events.js.map +1 -1
- package/dist/core/extensions/types.d.ts +1 -1
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/flattened-tool-arguments.d.ts +18 -0
- package/dist/core/flattened-tool-arguments.d.ts.map +1 -1
- package/dist/core/flattened-tool-arguments.js +104 -0
- package/dist/core/flattened-tool-arguments.js.map +1 -1
- package/dist/core/messages.d.ts +1 -0
- package/dist/core/messages.d.ts.map +1 -1
- package/dist/core/messages.js +46 -1
- package/dist/core/messages.js.map +1 -1
- package/dist/core/sdk-exports.d.ts +1 -1
- package/dist/core/sdk-exports.d.ts.map +1 -1
- package/dist/core/sdk-exports.js +1 -1
- package/dist/core/sdk-exports.js.map +1 -1
- package/dist/core/sdk-types.d.ts +2 -2
- package/dist/core/sdk-types.d.ts.map +1 -1
- package/dist/core/sdk-types.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +12 -0
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager-core.d.ts +15 -7
- package/dist/core/session-manager-core.d.ts.map +1 -1
- package/dist/core/session-manager-core.js +20 -9
- package/dist/core/session-manager-core.js.map +1 -1
- package/dist/core/session-manager-entries.d.ts +2 -2
- package/dist/core/session-manager-entries.d.ts.map +1 -1
- package/dist/core/session-manager-entries.js +9 -3
- package/dist/core/session-manager-entries.js.map +1 -1
- package/dist/core/session-manager-history.d.ts.map +1 -1
- package/dist/core/session-manager-history.js +2 -1
- package/dist/core/session-manager-history.js.map +1 -1
- package/dist/core/session-manager-list.d.ts +3 -3
- package/dist/core/session-manager-list.d.ts.map +1 -1
- package/dist/core/session-manager-list.js +27 -8
- package/dist/core/session-manager-list.js.map +1 -1
- package/dist/core/session-manager-storage.d.ts +3 -1
- package/dist/core/session-manager-storage.d.ts.map +1 -1
- package/dist/core/session-manager-storage.js +55 -12
- package/dist/core/session-manager-storage.js.map +1 -1
- package/dist/core/session-manager-tool-dependencies.d.ts +10 -0
- package/dist/core/session-manager-tool-dependencies.d.ts.map +1 -0
- package/dist/core/session-manager-tool-dependencies.js +133 -0
- package/dist/core/session-manager-tool-dependencies.js.map +1 -0
- package/dist/core/session-manager-types.d.ts +22 -0
- package/dist/core/session-manager-types.d.ts.map +1 -1
- package/dist/core/session-manager-types.js.map +1 -1
- package/dist/core/session-manager.d.ts +2 -2
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +1 -1
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager-basic-accessors.d.ts +4 -0
- package/dist/core/settings-manager-basic-accessors.d.ts.map +1 -1
- package/dist/core/settings-manager-basic-accessors.js +18 -0
- package/dist/core/settings-manager-basic-accessors.js.map +1 -1
- package/dist/core/settings-manager-resource-accessors.d.ts +4 -0
- package/dist/core/settings-manager-resource-accessors.d.ts.map +1 -1
- package/dist/core/settings-manager-resource-accessors.js +15 -0
- package/dist/core/settings-manager-resource-accessors.js.map +1 -1
- package/dist/core/settings-types.d.ts +11 -0
- package/dist/core/settings-types.d.ts.map +1 -1
- package/dist/core/settings-types.js.map +1 -1
- package/dist/core/system-prompt.d.ts +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +3 -2
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/artifact-protocol.d.ts +11 -0
- package/dist/core/tools/artifact-protocol.d.ts.map +1 -0
- package/dist/core/tools/artifact-protocol.js +76 -0
- package/dist/core/tools/artifact-protocol.js.map +1 -0
- package/dist/core/tools/artifacts.d.ts +18 -0
- package/dist/core/tools/artifacts.d.ts.map +1 -0
- package/dist/core/tools/artifacts.js +90 -0
- package/dist/core/tools/artifacts.js.map +1 -0
- package/dist/core/tools/bash-async-jobs.d.ts +20 -0
- package/dist/core/tools/bash-async-jobs.d.ts.map +1 -0
- package/dist/core/tools/bash-async-jobs.js +59 -0
- package/dist/core/tools/bash-async-jobs.js.map +1 -0
- package/dist/core/tools/bash-async-output.d.ts +10 -0
- package/dist/core/tools/bash-async-output.d.ts.map +1 -0
- package/dist/core/tools/bash-async-output.js +80 -0
- package/dist/core/tools/bash-async-output.js.map +1 -0
- package/dist/core/tools/bash-interceptor.d.ts +10 -0
- package/dist/core/tools/bash-interceptor.d.ts.map +1 -0
- package/dist/core/tools/bash-interceptor.js +39 -0
- package/dist/core/tools/bash-interceptor.js.map +1 -0
- package/dist/core/tools/bash-leading-cd.d.ts +7 -0
- package/dist/core/tools/bash-leading-cd.d.ts.map +1 -0
- package/dist/core/tools/bash-leading-cd.js +59 -0
- package/dist/core/tools/bash-leading-cd.js.map +1 -0
- package/dist/core/tools/bash-pty-native.d.ts +14 -0
- package/dist/core/tools/bash-pty-native.d.ts.map +1 -0
- package/dist/core/tools/bash-pty-native.js +71 -0
- package/dist/core/tools/bash-pty-native.js.map +1 -0
- package/dist/core/tools/bash.d.ts +28 -17
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +152 -35
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/block-resolver.d.ts +16 -0
- package/dist/core/tools/block-resolver.d.ts.map +1 -0
- package/dist/core/tools/block-resolver.js +74 -0
- package/dist/core/tools/block-resolver.js.map +1 -0
- package/dist/core/tools/conflict-registry.d.ts +16 -0
- package/dist/core/tools/conflict-registry.d.ts.map +1 -0
- package/dist/core/tools/conflict-registry.js +44 -0
- package/dist/core/tools/conflict-registry.js.map +1 -0
- package/dist/core/tools/directory-tree.d.ts +13 -0
- package/dist/core/tools/directory-tree.d.ts.map +1 -0
- package/dist/core/tools/directory-tree.js +81 -0
- package/dist/core/tools/directory-tree.js.map +1 -0
- package/dist/core/tools/edit.d.ts +4 -29
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +136 -228
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/fetch-url.d.ts +74 -0
- package/dist/core/tools/fetch-url.d.ts.map +1 -0
- package/dist/core/tools/fetch-url.js +518 -0
- package/dist/core/tools/fetch-url.js.map +1 -0
- package/dist/core/tools/find.d.ts +27 -9
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +400 -176
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/glob-path-utils.d.ts +8 -0
- package/dist/core/tools/glob-path-utils.d.ts.map +1 -0
- package/dist/core/tools/glob-path-utils.js +26 -0
- package/dist/core/tools/glob-path-utils.js.map +1 -0
- package/dist/core/tools/grep.d.ts +12 -0
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +141 -17
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/hashline-engine/apply.d.ts +11 -0
- package/dist/core/tools/hashline-engine/apply.d.ts.map +1 -0
- package/dist/core/tools/hashline-engine/apply.js +752 -0
- package/dist/core/tools/hashline-engine/apply.js.map +1 -0
- package/dist/core/tools/hashline-engine/block.d.ts +40 -0
- package/dist/core/tools/hashline-engine/block.d.ts.map +1 -0
- package/dist/core/tools/hashline-engine/block.js +117 -0
- package/dist/core/tools/hashline-engine/block.js.map +1 -0
- package/dist/core/tools/hashline-engine/diff-preview.d.ts +15 -0
- package/dist/core/tools/hashline-engine/diff-preview.d.ts.map +1 -0
- package/dist/core/tools/hashline-engine/diff-preview.js +98 -0
- package/dist/core/tools/hashline-engine/diff-preview.js.map +1 -0
- package/dist/core/tools/hashline-engine/format.d.ts +71 -0
- package/dist/core/tools/hashline-engine/format.d.ts.map +1 -0
- package/dist/core/tools/hashline-engine/format.js +178 -0
- package/dist/core/tools/hashline-engine/format.js.map +1 -0
- package/dist/core/tools/hashline-engine/fs.d.ts +81 -0
- package/dist/core/tools/hashline-engine/fs.d.ts.map +1 -0
- package/dist/core/tools/hashline-engine/fs.js +143 -0
- package/dist/core/tools/hashline-engine/fs.js.map +1 -0
- package/dist/core/tools/hashline-engine/index.d.ts +18 -0
- package/dist/core/tools/hashline-engine/index.d.ts.map +1 -0
- package/dist/core/tools/hashline-engine/index.js +20 -0
- package/dist/core/tools/hashline-engine/index.js.map +1 -0
- package/dist/core/tools/hashline-engine/input.d.ts +101 -0
- package/dist/core/tools/hashline-engine/input.d.ts.map +1 -0
- package/dist/core/tools/hashline-engine/input.js +398 -0
- package/dist/core/tools/hashline-engine/input.js.map +1 -0
- package/dist/core/tools/hashline-engine/messages.d.ts +99 -0
- package/dist/core/tools/hashline-engine/messages.d.ts.map +1 -0
- package/dist/core/tools/hashline-engine/messages.js +144 -0
- package/dist/core/tools/hashline-engine/messages.js.map +1 -0
- package/dist/core/tools/hashline-engine/mismatch.d.ts +45 -0
- package/dist/core/tools/hashline-engine/mismatch.d.ts.map +1 -0
- package/dist/core/tools/hashline-engine/mismatch.js +90 -0
- package/dist/core/tools/hashline-engine/mismatch.js.map +1 -0
- package/dist/core/tools/hashline-engine/normalize.d.ts +21 -0
- package/dist/core/tools/hashline-engine/normalize.d.ts.map +1 -0
- package/dist/core/tools/hashline-engine/normalize.js +33 -0
- package/dist/core/tools/hashline-engine/normalize.js.map +1 -0
- package/dist/core/tools/hashline-engine/parser.d.ts +24 -0
- package/dist/core/tools/hashline-engine/parser.d.ts.map +1 -0
- package/dist/core/tools/hashline-engine/parser.js +381 -0
- package/dist/core/tools/hashline-engine/parser.js.map +1 -0
- package/dist/core/tools/hashline-engine/patcher.d.ts +118 -0
- package/dist/core/tools/hashline-engine/patcher.d.ts.map +1 -0
- package/dist/core/tools/hashline-engine/patcher.js +341 -0
- package/dist/core/tools/hashline-engine/patcher.js.map +1 -0
- package/dist/core/tools/hashline-engine/prefixes.d.ts +43 -0
- package/dist/core/tools/hashline-engine/prefixes.d.ts.map +1 -0
- package/dist/core/tools/hashline-engine/prefixes.js +135 -0
- package/dist/core/tools/hashline-engine/prefixes.js.map +1 -0
- package/dist/core/tools/hashline-engine/recovery.d.ts +41 -0
- package/dist/core/tools/hashline-engine/recovery.d.ts.map +1 -0
- package/dist/core/tools/hashline-engine/recovery.js +168 -0
- package/dist/core/tools/hashline-engine/recovery.js.map +1 -0
- package/dist/core/tools/hashline-engine/snapshots.d.ts +65 -0
- package/dist/core/tools/hashline-engine/snapshots.d.ts.map +1 -0
- package/dist/core/tools/hashline-engine/snapshots.js +108 -0
- package/dist/core/tools/hashline-engine/snapshots.js.map +1 -0
- package/dist/core/tools/hashline-engine/stream.d.ts +3 -0
- package/dist/core/tools/hashline-engine/stream.d.ts.map +1 -0
- package/dist/core/tools/hashline-engine/stream.js +111 -0
- package/dist/core/tools/hashline-engine/stream.js.map +1 -0
- package/dist/core/tools/hashline-engine/tokenizer.d.ts +69 -0
- package/dist/core/tools/hashline-engine/tokenizer.d.ts.map +1 -0
- package/dist/core/tools/hashline-engine/tokenizer.js +430 -0
- package/dist/core/tools/hashline-engine/tokenizer.js.map +1 -0
- package/dist/core/tools/hashline-engine/types.d.ts +166 -0
- package/dist/core/tools/hashline-engine/types.d.ts.map +1 -0
- package/dist/core/tools/hashline-engine/types.js +9 -0
- package/dist/core/tools/hashline-engine/types.js.map +1 -0
- package/dist/core/tools/hashline.d.ts +29 -0
- package/dist/core/tools/hashline.d.ts.map +1 -0
- package/dist/core/tools/hashline.js +110 -0
- package/dist/core/tools/hashline.js.map +1 -0
- package/dist/core/tools/index.d.ts +6 -4
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +52 -35
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/notebook.d.ts +38 -0
- package/dist/core/tools/notebook.d.ts.map +1 -0
- package/dist/core/tools/notebook.js +125 -0
- package/dist/core/tools/notebook.js.map +1 -0
- package/dist/core/tools/read-document-extract.d.ts +9 -0
- package/dist/core/tools/read-document-extract.d.ts.map +1 -0
- package/dist/core/tools/read-document-extract.js +212 -0
- package/dist/core/tools/read-document-extract.js.map +1 -0
- package/dist/core/tools/read-selectors.d.ts +24 -0
- package/dist/core/tools/read-selectors.d.ts.map +1 -0
- package/dist/core/tools/read-selectors.js +277 -0
- package/dist/core/tools/read-selectors.js.map +1 -0
- package/dist/core/tools/read-url.d.ts +37 -0
- package/dist/core/tools/read-url.d.ts.map +1 -0
- package/dist/core/tools/read-url.js +39 -0
- package/dist/core/tools/read-url.js.map +1 -0
- package/dist/core/tools/read.d.ts +11 -11
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +224 -94
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/resource-selectors.d.ts +44 -0
- package/dist/core/tools/resource-selectors.d.ts.map +1 -0
- package/dist/core/tools/resource-selectors.js +808 -0
- package/dist/core/tools/resource-selectors.js.map +1 -0
- package/dist/core/tools/search-details.d.ts +26 -0
- package/dist/core/tools/search-details.d.ts.map +1 -0
- package/dist/core/tools/search-details.js +24 -0
- package/dist/core/tools/search-details.js.map +1 -0
- package/dist/core/tools/search-line-ranges.d.ts +11 -0
- package/dist/core/tools/search-line-ranges.d.ts.map +1 -0
- package/dist/core/tools/search-line-ranges.js +65 -0
- package/dist/core/tools/search-line-ranges.js.map +1 -0
- package/dist/core/tools/search-native.d.ts +97 -0
- package/dist/core/tools/search-native.d.ts.map +1 -0
- package/dist/core/tools/search-native.js +27 -0
- package/dist/core/tools/search-native.js.map +1 -0
- package/dist/core/tools/search.d.ts +24 -0
- package/dist/core/tools/search.d.ts.map +1 -0
- package/dist/core/tools/search.js +573 -0
- package/dist/core/tools/search.js.map +1 -0
- package/dist/core/tools/truncate.d.ts +4 -4
- package/dist/core/tools/truncate.d.ts.map +1 -1
- package/dist/core/tools/truncate.js +3 -3
- package/dist/core/tools/truncate.js.map +1 -1
- package/dist/core/tools/url-ip-guards.d.ts +4 -0
- package/dist/core/tools/url-ip-guards.d.ts.map +1 -0
- package/dist/core/tools/url-ip-guards.js +126 -0
- package/dist/core/tools/url-ip-guards.js.map +1 -0
- package/dist/core/tools/write.d.ts +12 -2
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +166 -14
- package/dist/core/tools/write.js.map +1 -1
- package/dist/core/trust-manager.d.ts.map +1 -1
- package/dist/core/trust-manager.js +2 -3
- package/dist/core/trust-manager.js.map +1 -1
- package/dist/index-extensions.d.ts +2 -2
- package/dist/index-extensions.d.ts.map +1 -1
- package/dist/index-extensions.js +1 -1
- package/dist/index-extensions.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-runtime.d.ts +1 -0
- package/dist/modes/interactive/components/chat-session-host-runtime.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-runtime.js +12 -0
- package/dist/modes/interactive/components/chat-session-host-runtime.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-terminal-cleanup.d.ts +4 -0
- package/dist/modes/interactive/components/chat-session-host-terminal-cleanup.d.ts.map +1 -0
- package/dist/modes/interactive/components/chat-session-host-terminal-cleanup.js +131 -0
- package/dist/modes/interactive/components/chat-session-host-terminal-cleanup.js.map +1 -0
- package/dist/modes/interactive/components/chat-session-host.d.ts +2 -0
- package/dist/modes/interactive/components/chat-session-host.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host.js +7 -1
- package/dist/modes/interactive/components/chat-session-host.js.map +1 -1
- package/dist/modes/interactive/components/chat-transcript.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-transcript.js +15 -4
- package/dist/modes/interactive/components/chat-transcript.js.map +1 -1
- package/dist/modes/interactive/components/custom-editor.d.ts +1 -0
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-editor.js +9 -2
- package/dist/modes/interactive/components/custom-editor.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector-handlers.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector-handlers.js +3 -0
- package/dist/modes/interactive/components/settings-selector-handlers.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector-items.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector-items.js +7 -0
- package/dist/modes/interactive/components/settings-selector-items.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector-types.d.ts +2 -0
- package/dist/modes/interactive/components/settings-selector-types.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector-types.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +3 -0
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +26 -0
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector-content.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector-content.js +0 -5
- package/dist/modes/interactive/components/tree-selector-content.js.map +1 -1
- package/dist/modes/interactive/interactive-auth-login.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-auth-login.js +1 -0
- package/dist/modes/interactive/interactive-auth-login.js.map +1 -1
- package/dist/modes/interactive/interactive-autocomplete.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-autocomplete.js +80 -2
- package/dist/modes/interactive/interactive-autocomplete.js.map +1 -1
- package/dist/modes/interactive/interactive-hotkeys-debug.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-hotkeys-debug.js +3 -0
- package/dist/modes/interactive/interactive-hotkeys-debug.js.map +1 -1
- package/dist/modes/interactive/interactive-input-handling.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-input-handling.js +51 -0
- package/dist/modes/interactive/interactive-input-handling.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-base.d.ts +5 -0
- package/dist/modes/interactive/interactive-mode-base.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-base.js +5 -0
- package/dist/modes/interactive/interactive-mode-base.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-deps.d.ts +1 -1
- package/dist/modes/interactive/interactive-mode-deps.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-deps.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-surface.d.ts +12 -0
- package/dist/modes/interactive/interactive-mode-surface.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-surface.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +1 -0
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/interactive-model-routing.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-model-routing.js +4 -1
- package/dist/modes/interactive/interactive-model-routing.js.map +1 -1
- package/dist/modes/interactive/interactive-onboarding.d.ts +11 -0
- package/dist/modes/interactive/interactive-onboarding.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-onboarding.js +220 -0
- package/dist/modes/interactive/interactive-onboarding.js.map +1 -0
- package/dist/modes/interactive/interactive-selectors.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-selectors.js +4 -0
- package/dist/modes/interactive/interactive-selectors.js.map +1 -1
- package/dist/modes/interactive/interactive-session-routing.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-session-routing.js +6 -0
- package/dist/modes/interactive/interactive-session-routing.js.map +1 -1
- package/dist/modes/interactive/interactive-slash-commands.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-slash-commands.js +9 -4
- package/dist/modes/interactive/interactive-slash-commands.js.map +1 -1
- package/dist/modes/interactive/interactive-startup.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-startup.js +28 -0
- package/dist/modes/interactive/interactive-startup.js.map +1 -1
- package/dist/utils/child-process.d.ts.map +1 -1
- package/dist/utils/child-process.js +21 -1
- package/dist/utils/child-process.js.map +1 -1
- package/dist/utils/markit.d.ts +8 -0
- package/dist/utils/markit.d.ts.map +1 -0
- package/dist/utils/markit.js +53 -0
- package/dist/utils/markit.js.map +1 -0
- package/dist/utils/paths.d.ts +2 -1
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +14 -1
- package/dist/utils/paths.js.map +1 -1
- package/docs/compaction.md +18 -1
- package/docs/containerization.md +1 -1
- package/docs/docs.json +1 -0
- package/docs/extensions.md +25 -36
- package/docs/models.md +1 -1
- package/docs/providers.md +2 -1
- package/docs/quickstart.md +11 -6
- package/docs/sdk.md +5 -5
- package/docs/session-format.md +6 -0
- package/docs/sessions.md +6 -0
- package/docs/settings.md +7 -0
- package/docs/subagents.md +3 -2
- package/docs/tools.md +49 -0
- package/docs/usage.md +3 -3
- package/docs/workflows.md +112 -8
- package/examples/extensions/subagent/README.md +5 -5
- package/examples/extensions/subagent/agents/planner.md +1 -1
- package/examples/extensions/subagent/agents/reviewer.md +1 -1
- package/examples/extensions/subagent/agents/scout.md +2 -2
- package/examples/extensions/subagent/display.ts +3 -3
- package/examples/sdk/05-tools.ts +3 -3
- package/examples/sdk/README.md +1 -1
- package/package.json +5 -3
|
@@ -0,0 +1,808 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { dirname, isAbsolute, relative, resolve } from "node:path";
|
|
4
|
+
import { deflateRawSync, gunzipSync, gzipSync, inflateRawSync } from "node:zlib";
|
|
5
|
+
import { loadNativeSearchBinding } from "./search-native.js";
|
|
6
|
+
function sqliteDatabase() {
|
|
7
|
+
try {
|
|
8
|
+
return createRequire(import.meta.url)("bun:sqlite").Database;
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
throw new Error("SQLite selectors require Atomic's Bun runtime with bun:sqlite support.");
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function existingSqliteFile(path) { if (!existsSync(path))
|
|
15
|
+
return undefined; return readFileSync(path).subarray(0, 16).toString("binary") === "SQLite format 3\0"; }
|
|
16
|
+
export function sqliteSelectorForPath(value, cwd) { const selector = parseSqliteSelector(value); if (!selector)
|
|
17
|
+
return undefined; const absolute = resolveContainedLocalPath(cwd, selector.databasePath, "SQLite selector"); if (existingSqliteFile(absolute) !== true)
|
|
18
|
+
return undefined; return { ...selector, databasePath: absolute }; }
|
|
19
|
+
const MAX_TAR_ARCHIVE_BYTES = 256 * 1024 * 1024;
|
|
20
|
+
const MAX_ARCHIVE_MEMBER_BYTES = 64 * 1024 * 1024;
|
|
21
|
+
const MAX_ARCHIVE_DIRECTORY_ENTRIES = 500;
|
|
22
|
+
export function parseArchiveSelector(value) {
|
|
23
|
+
const match = value.match(/^(.+\.(?:zip|jar|tar|tgz|tar\.gz|gz)):(.*)$/i);
|
|
24
|
+
return match ? { archivePath: match[1] ?? "", memberPath: match[2] ?? "" } : undefined;
|
|
25
|
+
}
|
|
26
|
+
export function resolveArchiveSelector(selector, cwd) {
|
|
27
|
+
return { ...selector, archivePath: resolveContainedLocalPath(cwd, selector.archivePath, "Archive selector") };
|
|
28
|
+
}
|
|
29
|
+
export function parseSqliteSelector(value) {
|
|
30
|
+
const match = value.match(/^(.+\.(?:sqlite3?|db3?))(?:\?q=(.+)|:([^:?]+)(?:\?(.+))?(?::([^:?]+))?)?$/i);
|
|
31
|
+
if (!match)
|
|
32
|
+
return undefined;
|
|
33
|
+
const params = new URLSearchParams(match[4] ?? "");
|
|
34
|
+
const limit = Number.parseInt(params.get("limit") ?? "", 10);
|
|
35
|
+
const offset = Number.parseInt(params.get("offset") ?? "", 10);
|
|
36
|
+
const sampleRows = Number.parseInt(params.get("sampleRows") ?? params.get("sample_rows") ?? "", 10);
|
|
37
|
+
return { databasePath: match[1] ?? "", query: match[2] ? decodeURIComponent(match[2]) : undefined, table: match[3], rowId: match[5] ?? params.get("id") ?? undefined, limit: Number.isFinite(limit) ? Math.max(0, Math.min(500, limit)) : undefined, offset: Number.isFinite(offset) ? Math.max(0, offset) : undefined, where: params.get("where") ?? undefined, order: params.get("order") ?? undefined, schema: params.get("schema") === "true" || params.get("schema") === "1", sampleRows: Number.isFinite(sampleRows) ? Math.max(0, Math.min(100, sampleRows)) : undefined };
|
|
38
|
+
}
|
|
39
|
+
function isZipArchive(path) { return /\.(?:zip|jar)$/i.test(path); }
|
|
40
|
+
function isGzipTar(path) { return /\.(?:tgz|tar\.gz|gz)$/i.test(path); }
|
|
41
|
+
function crc32(data) {
|
|
42
|
+
let crc = ~0;
|
|
43
|
+
for (const byte of data) {
|
|
44
|
+
crc ^= byte;
|
|
45
|
+
for (let i = 0; i < 8; i++)
|
|
46
|
+
crc = (crc >>> 1) ^ (0xedb88320 & -(crc & 1));
|
|
47
|
+
}
|
|
48
|
+
return ~crc >>> 0;
|
|
49
|
+
}
|
|
50
|
+
function assertZipRange(buf, offset, length, label) {
|
|
51
|
+
if (!Number.isSafeInteger(offset) || !Number.isSafeInteger(length) || offset < 0 || length < 0 || offset > buf.length - length)
|
|
52
|
+
throw new Error(`Invalid zip entry bounds: ${label}`);
|
|
53
|
+
}
|
|
54
|
+
function zipEntryPayload(buf, label, name, localOffset, compressedSize) {
|
|
55
|
+
if (compressedSize > MAX_ARCHIVE_MEMBER_BYTES)
|
|
56
|
+
throw new Error(`Archive member compressed data too large: ${name}`);
|
|
57
|
+
assertZipRange(buf, localOffset, 30, label);
|
|
58
|
+
if (buf.readUInt32LE(localOffset) !== 0x04034b50)
|
|
59
|
+
throw new Error(`Invalid zip local header: ${label}`);
|
|
60
|
+
const localNameLen = buf.readUInt16LE(localOffset + 26), localExtraLen = buf.readUInt16LE(localOffset + 28), start = localOffset + 30 + localNameLen + localExtraLen;
|
|
61
|
+
assertZipRange(buf, start, compressedSize, label);
|
|
62
|
+
return buf.subarray(start, start + compressedSize);
|
|
63
|
+
}
|
|
64
|
+
export function readZipEntriesFromBuffer(buf, label) {
|
|
65
|
+
const entries = new Map();
|
|
66
|
+
let eocd = -1;
|
|
67
|
+
for (let i = buf.length - 22; i >= 0; i--)
|
|
68
|
+
if (buf.readUInt32LE(i) === 0x06054b50) {
|
|
69
|
+
eocd = i;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
if (eocd < 0)
|
|
73
|
+
throw new Error(`Invalid zip archive: ${label}`);
|
|
74
|
+
let ptr = buf.readUInt32LE(eocd + 16);
|
|
75
|
+
const total = buf.readUInt16LE(eocd + 10);
|
|
76
|
+
for (let n = 0; n < total; n++) {
|
|
77
|
+
assertZipRange(buf, ptr, 46, label);
|
|
78
|
+
if (buf.readUInt32LE(ptr) !== 0x02014b50)
|
|
79
|
+
throw new Error(`Invalid zip central directory: ${label}`);
|
|
80
|
+
const method = buf.readUInt16LE(ptr + 10), compressedSize = buf.readUInt32LE(ptr + 20), size = buf.readUInt32LE(ptr + 24), nameLen = buf.readUInt16LE(ptr + 28), extraLen = buf.readUInt16LE(ptr + 30), commentLen = buf.readUInt16LE(ptr + 32), localOffset = buf.readUInt32LE(ptr + 42);
|
|
81
|
+
assertZipRange(buf, ptr + 46, nameLen + extraLen + commentLen, label);
|
|
82
|
+
const name = buf.subarray(ptr + 46, ptr + 46 + nameLen).toString();
|
|
83
|
+
ptr += 46 + nameLen + extraLen + commentLen;
|
|
84
|
+
if (name.endsWith("/"))
|
|
85
|
+
continue;
|
|
86
|
+
if (size > MAX_ARCHIVE_MEMBER_BYTES)
|
|
87
|
+
throw new Error(`Archive member too large: ${name}`);
|
|
88
|
+
const data = zipEntryPayload(buf, label, name, localOffset, compressedSize);
|
|
89
|
+
entries.set(name, method === 0 ? Buffer.from(data) : method === 8 ? inflateRawSync(data, { maxOutputLength: MAX_ARCHIVE_MEMBER_BYTES }) : (() => { throw new Error(`Unsupported zip compression method ${method} for ${name}`); })());
|
|
90
|
+
}
|
|
91
|
+
return entries;
|
|
92
|
+
}
|
|
93
|
+
export function readZipEntries(path) { return readZipEntriesFromBuffer(readFileSync(path), path); }
|
|
94
|
+
function writeZipEntries(path, entries) {
|
|
95
|
+
const locals = [], centrals = [];
|
|
96
|
+
let offset = 0;
|
|
97
|
+
for (const [name, data] of entries) {
|
|
98
|
+
const nameBuf = Buffer.from(name), compressed = deflateRawSync(data), crc = crc32(data);
|
|
99
|
+
const local = Buffer.alloc(30);
|
|
100
|
+
local.writeUInt32LE(0x04034b50, 0);
|
|
101
|
+
local.writeUInt16LE(20, 4);
|
|
102
|
+
local.writeUInt16LE(8, 8);
|
|
103
|
+
local.writeUInt32LE(crc, 14);
|
|
104
|
+
local.writeUInt32LE(compressed.length, 18);
|
|
105
|
+
local.writeUInt32LE(data.length, 22);
|
|
106
|
+
local.writeUInt16LE(nameBuf.length, 26);
|
|
107
|
+
locals.push(local, nameBuf, compressed);
|
|
108
|
+
const central = Buffer.alloc(46);
|
|
109
|
+
central.writeUInt32LE(0x02014b50, 0);
|
|
110
|
+
central.writeUInt16LE(20, 4);
|
|
111
|
+
central.writeUInt16LE(20, 6);
|
|
112
|
+
central.writeUInt16LE(8, 10);
|
|
113
|
+
central.writeUInt32LE(crc, 16);
|
|
114
|
+
central.writeUInt32LE(compressed.length, 20);
|
|
115
|
+
central.writeUInt32LE(data.length, 24);
|
|
116
|
+
central.writeUInt16LE(nameBuf.length, 28);
|
|
117
|
+
central.writeUInt32LE(offset, 42);
|
|
118
|
+
centrals.push(central, nameBuf);
|
|
119
|
+
offset += local.length + nameBuf.length + compressed.length;
|
|
120
|
+
}
|
|
121
|
+
const centralSize = centrals.reduce((sum, part) => sum + part.length, 0);
|
|
122
|
+
const eocd = Buffer.alloc(22);
|
|
123
|
+
eocd.writeUInt32LE(0x06054b50, 0);
|
|
124
|
+
eocd.writeUInt16LE(entries.size, 8);
|
|
125
|
+
eocd.writeUInt16LE(entries.size, 10);
|
|
126
|
+
eocd.writeUInt32LE(centralSize, 12);
|
|
127
|
+
eocd.writeUInt32LE(offset, 16);
|
|
128
|
+
writeFileSync(path, Buffer.concat([...locals, ...centrals, eocd]));
|
|
129
|
+
}
|
|
130
|
+
function parseTar(path) {
|
|
131
|
+
const raw = readFileSync(path);
|
|
132
|
+
if (raw.length > MAX_TAR_ARCHIVE_BYTES)
|
|
133
|
+
throw new Error(`Archive too large: ${path}`);
|
|
134
|
+
const buf = isGzipTar(path) ? gunzipSync(raw, { maxOutputLength: MAX_TAR_ARCHIVE_BYTES }) : raw;
|
|
135
|
+
if (buf.length > MAX_TAR_ARCHIVE_BYTES)
|
|
136
|
+
throw new Error(`Archive too large: ${path}`);
|
|
137
|
+
const entries = new Map();
|
|
138
|
+
for (let offset = 0; offset + 512 <= buf.length;) {
|
|
139
|
+
const header = buf.subarray(offset, offset + 512);
|
|
140
|
+
if (header.every((byte) => byte === 0))
|
|
141
|
+
break;
|
|
142
|
+
const name = header.subarray(0, 100).toString().replace(/\0.*$/, "");
|
|
143
|
+
const prefix = header.subarray(345, 500).toString().replace(/\0.*$/, "");
|
|
144
|
+
const fullName = prefix ? `${prefix}/${name}` : name;
|
|
145
|
+
const size = Number.parseInt(header.subarray(124, 136).toString().replace(/\0.*$/, "").trim() || "0", 8);
|
|
146
|
+
const type = String.fromCharCode(header[156] ?? 48);
|
|
147
|
+
const dataStart = offset + 512;
|
|
148
|
+
if (type !== "5" && fullName) {
|
|
149
|
+
if (size > MAX_ARCHIVE_MEMBER_BYTES)
|
|
150
|
+
throw new Error(`Archive member too large: ${fullName}`);
|
|
151
|
+
entries.set(fullName, Buffer.from(buf.subarray(dataStart, dataStart + size)));
|
|
152
|
+
}
|
|
153
|
+
offset = dataStart + Math.ceil(size / 512) * 512;
|
|
154
|
+
}
|
|
155
|
+
return entries;
|
|
156
|
+
}
|
|
157
|
+
function tarHeader(name, size) {
|
|
158
|
+
const header = Buffer.alloc(512);
|
|
159
|
+
const nameBytes = Buffer.from(name);
|
|
160
|
+
nameBytes.copy(header, 0, 0, Math.min(100, nameBytes.length));
|
|
161
|
+
header.write("0000644\0", 100);
|
|
162
|
+
header.write("0000000\0", 108);
|
|
163
|
+
header.write("0000000\0", 116);
|
|
164
|
+
header.write(size.toString(8).padStart(11, "0") + "\0", 124);
|
|
165
|
+
header.write("00000000000\0", 136);
|
|
166
|
+
header.fill(0x20, 148, 156);
|
|
167
|
+
header[156] = 48;
|
|
168
|
+
header.write("ustar\0", 257);
|
|
169
|
+
header.write("00", 263);
|
|
170
|
+
let sum = 0;
|
|
171
|
+
for (const byte of header)
|
|
172
|
+
sum += byte;
|
|
173
|
+
header.write(sum.toString(8).padStart(6, "0") + "\0 ", 148);
|
|
174
|
+
return header;
|
|
175
|
+
}
|
|
176
|
+
function writeTar(path, entries) {
|
|
177
|
+
const parts = [];
|
|
178
|
+
for (const [name, data] of entries) {
|
|
179
|
+
parts.push(tarHeader(name, data.length), data);
|
|
180
|
+
const pad = (512 - (data.length % 512)) % 512;
|
|
181
|
+
if (pad)
|
|
182
|
+
parts.push(Buffer.alloc(pad));
|
|
183
|
+
}
|
|
184
|
+
parts.push(Buffer.alloc(1024));
|
|
185
|
+
const out = Buffer.concat(parts);
|
|
186
|
+
writeFileSync(path, isGzipTar(path) ? gzipSync(out) : out);
|
|
187
|
+
}
|
|
188
|
+
function listArchiveDirectory(names, memberPath) {
|
|
189
|
+
const prefix = memberPath ? `${memberPath.replace(/\/+$/g, "")}/` : "";
|
|
190
|
+
const children = new Set();
|
|
191
|
+
for (const name of names) {
|
|
192
|
+
if (!name.startsWith(prefix) || name === prefix)
|
|
193
|
+
continue;
|
|
194
|
+
const rest = name.slice(prefix.length);
|
|
195
|
+
const [first, ...more] = rest.split("/");
|
|
196
|
+
if (first)
|
|
197
|
+
children.add(more.length > 0 ? `${first}/` : first);
|
|
198
|
+
}
|
|
199
|
+
return [...children].sort().slice(0, MAX_ARCHIVE_DIRECTORY_ENTRIES).join("\n");
|
|
200
|
+
}
|
|
201
|
+
function readZipSelector(path, memberPath) {
|
|
202
|
+
const buf = readFileSync(path);
|
|
203
|
+
let eocd = -1;
|
|
204
|
+
for (let i = buf.length - 22; i >= 0; i--)
|
|
205
|
+
if (buf.readUInt32LE(i) === 0x06054b50) {
|
|
206
|
+
eocd = i;
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
if (eocd < 0)
|
|
210
|
+
throw new Error(`Invalid zip archive: ${path}`);
|
|
211
|
+
let ptr = buf.readUInt32LE(eocd + 16);
|
|
212
|
+
const total = buf.readUInt16LE(eocd + 10), names = [];
|
|
213
|
+
for (let n = 0; n < total; n++) {
|
|
214
|
+
assertZipRange(buf, ptr, 46, path);
|
|
215
|
+
if (buf.readUInt32LE(ptr) !== 0x02014b50)
|
|
216
|
+
throw new Error(`Invalid zip central directory: ${path}`);
|
|
217
|
+
const method = buf.readUInt16LE(ptr + 10), compressedSize = buf.readUInt32LE(ptr + 20), size = buf.readUInt32LE(ptr + 24), nameLen = buf.readUInt16LE(ptr + 28), extraLen = buf.readUInt16LE(ptr + 30), commentLen = buf.readUInt16LE(ptr + 32), localOffset = buf.readUInt32LE(ptr + 42);
|
|
218
|
+
assertZipRange(buf, ptr + 46, nameLen + extraLen + commentLen, path);
|
|
219
|
+
const name = buf.subarray(ptr + 46, ptr + 46 + nameLen).toString();
|
|
220
|
+
ptr += 46 + nameLen + extraLen + commentLen;
|
|
221
|
+
if (name.endsWith("/"))
|
|
222
|
+
continue;
|
|
223
|
+
names.push(name);
|
|
224
|
+
if (memberPath && name !== memberPath)
|
|
225
|
+
continue;
|
|
226
|
+
if (!memberPath)
|
|
227
|
+
continue;
|
|
228
|
+
if (size > MAX_ARCHIVE_MEMBER_BYTES)
|
|
229
|
+
throw new Error(`Archive member too large: ${memberPath}`);
|
|
230
|
+
const data = zipEntryPayload(buf, path, name, localOffset, compressedSize);
|
|
231
|
+
return (method === 0 ? Buffer.from(data) : method === 8 ? inflateRawSync(data, { maxOutputLength: MAX_ARCHIVE_MEMBER_BYTES }) : (() => { throw new Error(`Unsupported zip compression method ${method} for ${name}`); })()).toString("utf8");
|
|
232
|
+
}
|
|
233
|
+
const listing = listArchiveDirectory(names, memberPath);
|
|
234
|
+
if (listing)
|
|
235
|
+
return listing;
|
|
236
|
+
if (!memberPath)
|
|
237
|
+
return "";
|
|
238
|
+
throw new Error(`Archive member not found: ${memberPath}`);
|
|
239
|
+
}
|
|
240
|
+
export function readArchiveSelector(selector) {
|
|
241
|
+
if (isZipArchive(selector.archivePath))
|
|
242
|
+
return readZipSelector(selector.archivePath, selector.memberPath);
|
|
243
|
+
const entries = parseTar(selector.archivePath);
|
|
244
|
+
if (!selector.memberPath)
|
|
245
|
+
return listArchiveDirectory(entries.keys(), "");
|
|
246
|
+
const data = entries.get(selector.memberPath);
|
|
247
|
+
if (data) {
|
|
248
|
+
if (data.length > MAX_ARCHIVE_MEMBER_BYTES)
|
|
249
|
+
throw new Error(`Archive member too large: ${selector.memberPath}`);
|
|
250
|
+
return data.toString("utf8");
|
|
251
|
+
}
|
|
252
|
+
const listing = listArchiveDirectory(entries.keys(), selector.memberPath);
|
|
253
|
+
if (listing)
|
|
254
|
+
return listing;
|
|
255
|
+
throw new Error(`Archive member not found: ${selector.memberPath}`);
|
|
256
|
+
}
|
|
257
|
+
function validateArchiveMemberPath(memberPath) { if (!memberPath || memberPath.startsWith("/") || memberPath.endsWith("/") || memberPath.split("/").includes(".."))
|
|
258
|
+
throw new Error(`Invalid archive member path: ${memberPath}`); }
|
|
259
|
+
function writeZipEntrySelective(path, memberPath, data) {
|
|
260
|
+
const source = existsSync(path) ? readFileSync(path) : Buffer.alloc(0);
|
|
261
|
+
const locals = [], centrals = [];
|
|
262
|
+
let offset = 0;
|
|
263
|
+
if (source.length > 0) {
|
|
264
|
+
let eocd = -1;
|
|
265
|
+
for (let i = source.length - 22; i >= 0; i--)
|
|
266
|
+
if (source.readUInt32LE(i) === 0x06054b50) {
|
|
267
|
+
eocd = i;
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
if (eocd < 0)
|
|
271
|
+
throw new Error(`Invalid zip archive: ${path}`);
|
|
272
|
+
let ptr = source.readUInt32LE(eocd + 16);
|
|
273
|
+
const total = source.readUInt16LE(eocd + 10);
|
|
274
|
+
for (let n = 0; n < total; n++) {
|
|
275
|
+
assertZipRange(source, ptr, 46, path);
|
|
276
|
+
const start = ptr, flags = source.readUInt16LE(ptr + 8), nameLen = source.readUInt16LE(ptr + 28), extraLen = source.readUInt16LE(ptr + 30), commentLen = source.readUInt16LE(ptr + 32), localOffset = source.readUInt32LE(ptr + 42), compressedSize = source.readUInt32LE(ptr + 20);
|
|
277
|
+
assertZipRange(source, ptr + 46, nameLen + extraLen + commentLen, path);
|
|
278
|
+
const name = source.subarray(ptr + 46, ptr + 46 + nameLen).toString();
|
|
279
|
+
ptr += 46 + nameLen + extraLen + commentLen;
|
|
280
|
+
if (name === memberPath)
|
|
281
|
+
continue;
|
|
282
|
+
if ((flags & 0x0008) !== 0)
|
|
283
|
+
throw new Error(`Unsupported zip data descriptor during selective write: ${name}`);
|
|
284
|
+
assertZipRange(source, localOffset, 30, path);
|
|
285
|
+
const localNameLen = source.readUInt16LE(localOffset + 26), localExtraLen = source.readUInt16LE(localOffset + 28), localEnd = localOffset + 30 + localNameLen + localExtraLen + compressedSize;
|
|
286
|
+
assertZipRange(source, localOffset, localEnd - localOffset, path);
|
|
287
|
+
const local = source.subarray(localOffset, localEnd), central = Buffer.from(source.subarray(start, ptr));
|
|
288
|
+
central.writeUInt32LE(offset, 42);
|
|
289
|
+
locals.push(local);
|
|
290
|
+
centrals.push(central);
|
|
291
|
+
offset += local.length;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
const tmp = `${path}.atomic-entry-${Date.now()}`;
|
|
295
|
+
writeZipEntries(tmp, new Map([[memberPath, data]]));
|
|
296
|
+
const built = readFileSync(tmp);
|
|
297
|
+
rmSync(tmp, { force: true });
|
|
298
|
+
const eocdStart = built.length - 22, localLen = built.readUInt32LE(eocdStart + 16), centralSizeOne = built.readUInt32LE(eocdStart + 12);
|
|
299
|
+
const central = Buffer.from(built.subarray(localLen, localLen + centralSizeOne));
|
|
300
|
+
central.writeUInt32LE(offset, 42);
|
|
301
|
+
locals.push(built.subarray(0, localLen));
|
|
302
|
+
centrals.push(central);
|
|
303
|
+
offset += localLen;
|
|
304
|
+
const centralSize = centrals.reduce((sum, part) => sum + part.length, 0), eocd = Buffer.alloc(22);
|
|
305
|
+
eocd.writeUInt32LE(0x06054b50, 0);
|
|
306
|
+
eocd.writeUInt16LE(centrals.length, 8);
|
|
307
|
+
eocd.writeUInt16LE(centrals.length, 10);
|
|
308
|
+
eocd.writeUInt32LE(centralSize, 12);
|
|
309
|
+
eocd.writeUInt32LE(offset, 16);
|
|
310
|
+
writeFileSync(path, Buffer.concat([...locals, ...centrals, eocd]));
|
|
311
|
+
}
|
|
312
|
+
export function writeArchiveSelector(selector, content) {
|
|
313
|
+
validateArchiveMemberPath(selector.memberPath);
|
|
314
|
+
mkdirSync(dirname(selector.archivePath), { recursive: true });
|
|
315
|
+
if (isZipArchive(selector.archivePath)) {
|
|
316
|
+
writeZipEntrySelective(selector.archivePath, selector.memberPath, Buffer.from(content));
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
const entries = existsSync(selector.archivePath) ? parseTar(selector.archivePath) : new Map();
|
|
320
|
+
entries.set(selector.memberPath, Buffer.from(content));
|
|
321
|
+
writeTar(selector.archivePath, entries);
|
|
322
|
+
}
|
|
323
|
+
const SEARCH_LINE_LIMIT = 512;
|
|
324
|
+
function truncateSearchLine(line) {
|
|
325
|
+
return line.length > SEARCH_LINE_LIMIT ? `${line.slice(0, SEARCH_LINE_LIMIT)}… [truncated]` : line;
|
|
326
|
+
}
|
|
327
|
+
function stripExtendedRegexWhitespace(pattern) {
|
|
328
|
+
let out = "", escaped = false, inClass = false, inComment = false;
|
|
329
|
+
for (const ch of pattern) {
|
|
330
|
+
if (inComment) {
|
|
331
|
+
if (ch === "\n" || ch === "\r")
|
|
332
|
+
inComment = false;
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
if (escaped) {
|
|
336
|
+
out += ch;
|
|
337
|
+
escaped = false;
|
|
338
|
+
continue;
|
|
339
|
+
}
|
|
340
|
+
if (ch === "\\") {
|
|
341
|
+
out += ch;
|
|
342
|
+
escaped = true;
|
|
343
|
+
continue;
|
|
344
|
+
}
|
|
345
|
+
if (ch === "[")
|
|
346
|
+
inClass = true;
|
|
347
|
+
else if (ch === "]")
|
|
348
|
+
inClass = false;
|
|
349
|
+
if (!inClass && ch === "#") {
|
|
350
|
+
inComment = true;
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
if (!inClass && /\s/.test(ch))
|
|
354
|
+
continue;
|
|
355
|
+
out += ch;
|
|
356
|
+
}
|
|
357
|
+
return out;
|
|
358
|
+
}
|
|
359
|
+
function normalizeSearchPattern(pattern, ignoreCase) {
|
|
360
|
+
const match = pattern.match(/^\(\?([imsUx-]+)\)([\s\S]*)$/);
|
|
361
|
+
const flags = new Set();
|
|
362
|
+
if (ignoreCase)
|
|
363
|
+
flags.add("i");
|
|
364
|
+
if (match) {
|
|
365
|
+
const inline = match[1] ?? "";
|
|
366
|
+
for (const flag of inline) {
|
|
367
|
+
if (flag === "i" || flag === "m" || flag === "s")
|
|
368
|
+
flags.add(flag);
|
|
369
|
+
}
|
|
370
|
+
return { pattern: inline.includes("x") ? stripExtendedRegexWhitespace(match[2] ?? "") : match[2] ?? "", flags: [...flags].join("") };
|
|
371
|
+
}
|
|
372
|
+
return { pattern, flags: [...flags].join("") };
|
|
373
|
+
}
|
|
374
|
+
function searchTextSelectorLines(label, text, pattern, ignoreCase, literal, contextBefore = 1, contextAfter = 3) {
|
|
375
|
+
const normalized = normalizeSearchPattern(pattern, ignoreCase);
|
|
376
|
+
if (!literal && !normalized.pattern.includes("\n") && !pattern.includes("\\n"))
|
|
377
|
+
try {
|
|
378
|
+
const native = loadNativeSearchBinding()?.search?.(text, { pattern: normalized.pattern, ignoreCase: normalized.flags.includes("i"), multiline: normalized.flags.includes("m") || normalized.flags.includes("s"), contextBefore, contextAfter });
|
|
379
|
+
if (native && !native.error)
|
|
380
|
+
return native.matches.flatMap((match) => [...(match.contextBefore ?? []).map((line) => `${label}-${line.lineNumber}- ${truncateSearchLine(line.line)}`), `${label}:${match.lineNumber}: ${truncateSearchLine(match.line)}`, ...(match.contextAfter ?? []).map((line) => `${label}-${line.lineNumber}- ${truncateSearchLine(line.line)}`)]);
|
|
381
|
+
}
|
|
382
|
+
catch { }
|
|
383
|
+
const matcher = literal ? undefined : new RegExp(normalized.pattern, normalized.flags);
|
|
384
|
+
const needle = normalized.flags.includes("i") ? normalized.pattern.toLowerCase() : normalized.pattern;
|
|
385
|
+
const lines = text.split("\n");
|
|
386
|
+
const matchLines = new Set();
|
|
387
|
+
lines.forEach((line, index) => { const haystack = normalized.flags.includes("i") ? line.toLowerCase() : line; if (matcher ? matcher.test(line) : haystack.includes(needle))
|
|
388
|
+
matchLines.add(index + 1); });
|
|
389
|
+
if (matchLines.size === 0 && matcher) {
|
|
390
|
+
const match = new RegExp(normalized.pattern, normalized.flags).exec(text);
|
|
391
|
+
if (match?.[0]) {
|
|
392
|
+
const start = text.slice(0, match.index).split("\n").length;
|
|
393
|
+
for (let line = start; line < start + match[0].split("\n").length; line++)
|
|
394
|
+
matchLines.add(line);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
const outputLines = new Set();
|
|
398
|
+
for (const line of matchLines)
|
|
399
|
+
for (let n = Math.max(1, line - contextBefore); n <= Math.min(lines.length, line + contextAfter); n++)
|
|
400
|
+
outputLines.add(n);
|
|
401
|
+
return [...outputLines].sort((a, b) => a - b).map((line) => `${label}${matchLines.has(line) ? ":" : "-"}${line}${matchLines.has(line) ? ":" : "-"} ${truncateSearchLine(lines[line - 1] ?? "")}`);
|
|
402
|
+
}
|
|
403
|
+
export function searchArchiveSelector(selector, pattern, ignoreCase = false, literal = false, contextBefore = 1, contextAfter = 3) {
|
|
404
|
+
if (isZipArchive(selector.archivePath) && selector.memberPath)
|
|
405
|
+
return searchTextSelectorLines(`${selector.archivePath}:${selector.memberPath}`, readArchiveSelector(selector), pattern, ignoreCase, literal, contextBefore, contextAfter).join("\n");
|
|
406
|
+
const entries = isZipArchive(selector.archivePath) ? readZipEntries(selector.archivePath) : parseTar(selector.archivePath);
|
|
407
|
+
const out = [];
|
|
408
|
+
for (const [name, data] of entries) {
|
|
409
|
+
if (selector.memberPath && name !== selector.memberPath)
|
|
410
|
+
continue;
|
|
411
|
+
out.push(...searchTextSelectorLines(`${selector.archivePath}:${name}`, data.toString("utf8"), pattern, ignoreCase, literal, contextBefore, contextAfter));
|
|
412
|
+
}
|
|
413
|
+
return out.join("\n");
|
|
414
|
+
}
|
|
415
|
+
function routerFromContext(context) { return context?.internalRouter ?? context?.internalResourceRouter; }
|
|
416
|
+
async function resolveViaRouter(value, cwd, context) {
|
|
417
|
+
const router = routerFromContext(context);
|
|
418
|
+
const routed = await router?.resolve?.(value);
|
|
419
|
+
if (routed)
|
|
420
|
+
return routed;
|
|
421
|
+
const resolved = await context?.resolveInternalUrl?.(value);
|
|
422
|
+
if (resolved)
|
|
423
|
+
return resolved;
|
|
424
|
+
return resolveInternalSelector(value, cwd);
|
|
425
|
+
}
|
|
426
|
+
function isContained(root, candidate) {
|
|
427
|
+
const rel = relative(root, candidate);
|
|
428
|
+
return rel === "" || (!rel.startsWith("..") && !isAbsolute(rel));
|
|
429
|
+
}
|
|
430
|
+
function nearestExistingAncestor(pathValue) {
|
|
431
|
+
let current = pathValue;
|
|
432
|
+
while (!existsSync(current)) {
|
|
433
|
+
const parent = dirname(current);
|
|
434
|
+
if (parent === current)
|
|
435
|
+
return current;
|
|
436
|
+
current = parent;
|
|
437
|
+
}
|
|
438
|
+
return current;
|
|
439
|
+
}
|
|
440
|
+
function realpathExisting(pathValue) { return realpathSync.native(nearestExistingAncestor(pathValue)); }
|
|
441
|
+
function resolveContainedPath(root, pathValue, label) {
|
|
442
|
+
const lexicalRoot = resolve(root), resolved = resolve(root, pathValue);
|
|
443
|
+
if (!isContained(lexicalRoot, resolved))
|
|
444
|
+
throw new Error(`${label} escapes the workspace: ${pathValue}`);
|
|
445
|
+
if (!isContained(realpathExisting(lexicalRoot), realpathExisting(resolved)))
|
|
446
|
+
throw new Error(`${label} escapes the workspace: ${pathValue}`);
|
|
447
|
+
return resolved;
|
|
448
|
+
}
|
|
449
|
+
function resolveContainedLocalPath(cwd, pathValue, label = "local:// resource") { return resolveContainedPath(cwd, pathValue, label); }
|
|
450
|
+
function fallbackInternalPath(value, cwd) {
|
|
451
|
+
const skill = value.match(/^skill:\/\/([^/]+)\/?(.*)$/);
|
|
452
|
+
if (skill) {
|
|
453
|
+
const name = skill[1] ?? "", rest = skill[2] || "SKILL.md";
|
|
454
|
+
return [".agents/skills", "packages/subagents/skills", "packages/workflows/skills"].map((base) => resolveContainedPath(resolveContainedLocalPath(cwd, base, "skill:// resource"), `${name}/${rest}`, "skill:// resource")).find((candidate) => existsSync(candidate));
|
|
455
|
+
}
|
|
456
|
+
const local = value.match(/^local:\/\/(.+)$/);
|
|
457
|
+
if (local)
|
|
458
|
+
return resolveContainedLocalPath(cwd, local[1] ?? "");
|
|
459
|
+
return undefined;
|
|
460
|
+
}
|
|
461
|
+
export function resolveInternalSelector(value, cwd) { return fallbackInternalPath(value, cwd); }
|
|
462
|
+
export async function readInternalSelector(value, cwd, context) {
|
|
463
|
+
const router = routerFromContext(context);
|
|
464
|
+
const routed = await router?.read?.(value);
|
|
465
|
+
if (typeof routed === "string")
|
|
466
|
+
return routed;
|
|
467
|
+
if (Buffer.isBuffer(routed))
|
|
468
|
+
return routed.toString("utf8");
|
|
469
|
+
const resolved = await resolveViaRouter(value, cwd, context);
|
|
470
|
+
if (!resolved || !existsSync(resolved))
|
|
471
|
+
throw new Error(`Internal resource not found or no session router supports it: ${value}`);
|
|
472
|
+
return readFileSync(resolved, "utf8");
|
|
473
|
+
}
|
|
474
|
+
export async function writeInternalSelector(value, cwd, content, context) {
|
|
475
|
+
const router = routerFromContext(context);
|
|
476
|
+
if (router?.write) {
|
|
477
|
+
await router.write(value, content);
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
const resolved = await resolveViaRouter(value, cwd, context);
|
|
481
|
+
if (!resolved)
|
|
482
|
+
throw new Error(`Unsupported writable internal resource without a session router: ${value}`);
|
|
483
|
+
mkdirSync(dirname(resolved), { recursive: true });
|
|
484
|
+
writeFileSync(resolved, content);
|
|
485
|
+
}
|
|
486
|
+
export async function searchInternalSelector(value, cwd, pattern, ignoreCase = false, literal = false, context, contextBefore = 1, contextAfter = 3) {
|
|
487
|
+
return searchTextSelectorLines(value, await readInternalSelector(value, cwd, context), pattern, ignoreCase, literal, contextBefore, contextAfter).join("\n");
|
|
488
|
+
}
|
|
489
|
+
function shellQuote(value) { return `'${value.replace(/'/g, `'\\''`)}'`; }
|
|
490
|
+
export async function expandShellInternalUrls(text, cwd, context, quote = false) {
|
|
491
|
+
let output = text;
|
|
492
|
+
const matches = [...new Set(text.match(/[a-z][a-z0-9+.-]*:\/\/[^\s'"`$)]+/gi) ?? [])];
|
|
493
|
+
for (const match of matches) {
|
|
494
|
+
const resolved = await resolveViaRouter(match, cwd, context);
|
|
495
|
+
if (resolved)
|
|
496
|
+
output = output.split(match).join(quote ? shellQuote(resolved) : resolved);
|
|
497
|
+
}
|
|
498
|
+
return output;
|
|
499
|
+
}
|
|
500
|
+
const ROW_COUNT_PROBE_CAP = 50_000;
|
|
501
|
+
const MAX_RAW_QUERY_ROWS = 1000;
|
|
502
|
+
function quoteSqliteIdent(value) { return `"${value.replace(/"/g, '""')}"`; }
|
|
503
|
+
function formatSqliteOrder(order) {
|
|
504
|
+
if (!order)
|
|
505
|
+
return "";
|
|
506
|
+
return order.split(",").map((part) => {
|
|
507
|
+
const [column, direction] = part.split(":");
|
|
508
|
+
if (!column || !/^[A-Za-z_][\w$]*$/.test(column))
|
|
509
|
+
throw new Error(`Invalid SQLite order column: ${part}`);
|
|
510
|
+
const dir = direction?.toLowerCase() === "desc" ? "desc" : "asc";
|
|
511
|
+
return `${quoteSqliteIdent(column)} ${dir}`;
|
|
512
|
+
}).join(", ");
|
|
513
|
+
}
|
|
514
|
+
const FORBIDDEN_WHERE_KEYWORDS = new Set(["limit", "offset", "union", "intersect", "except", "attach", "detach", "pragma", "select", "load_extension"]);
|
|
515
|
+
function validateSqliteWhere(where) {
|
|
516
|
+
const trimmed = where?.trim();
|
|
517
|
+
if (!trimmed)
|
|
518
|
+
return undefined;
|
|
519
|
+
let quote = "", token = "";
|
|
520
|
+
const flush = () => { const lower = token.toLowerCase(); if (token && (FORBIDDEN_WHERE_KEYWORDS.has(lower) || lower.startsWith("pragma_") || lower.startsWith("sqlite_")))
|
|
521
|
+
throw new Error("Invalid SQLite where filter"); token = ""; };
|
|
522
|
+
for (let i = 0; i < trimmed.length; i++) {
|
|
523
|
+
const ch = trimmed[i], next = trimmed[i + 1];
|
|
524
|
+
if (quote === "'") {
|
|
525
|
+
if (ch === "'" && next === "'") {
|
|
526
|
+
i++;
|
|
527
|
+
continue;
|
|
528
|
+
}
|
|
529
|
+
if (ch === "'")
|
|
530
|
+
quote = "";
|
|
531
|
+
continue;
|
|
532
|
+
}
|
|
533
|
+
if (quote === "\"") {
|
|
534
|
+
if (ch === "\"" && next === "\"") {
|
|
535
|
+
i++;
|
|
536
|
+
continue;
|
|
537
|
+
}
|
|
538
|
+
if (ch === "\"") {
|
|
539
|
+
quote = "";
|
|
540
|
+
flush();
|
|
541
|
+
continue;
|
|
542
|
+
}
|
|
543
|
+
if (ch && /[A-Za-z0-9_]/.test(ch)) {
|
|
544
|
+
token += ch;
|
|
545
|
+
continue;
|
|
546
|
+
}
|
|
547
|
+
flush();
|
|
548
|
+
token = ch;
|
|
549
|
+
continue;
|
|
550
|
+
}
|
|
551
|
+
if (ch === "'" || ch === "\"") {
|
|
552
|
+
flush();
|
|
553
|
+
quote = ch;
|
|
554
|
+
continue;
|
|
555
|
+
}
|
|
556
|
+
if (ch === ";" || ch === "-" && next === "-" || ch === "/" && next === "*" || ch === "*" && next === "/")
|
|
557
|
+
throw new Error("Invalid SQLite where filter");
|
|
558
|
+
if (ch && /[A-Za-z0-9_]/.test(ch)) {
|
|
559
|
+
token += ch;
|
|
560
|
+
continue;
|
|
561
|
+
}
|
|
562
|
+
flush();
|
|
563
|
+
}
|
|
564
|
+
flush();
|
|
565
|
+
return trimmed;
|
|
566
|
+
}
|
|
567
|
+
function rowsToJsonLines(rows) { return rows.map((row) => JSON.stringify(row)).join("\n"); }
|
|
568
|
+
const FORBIDDEN_RAW_QUERY_KEYWORDS = new Set(["attach", "detach", "pragma", "insert", "update", "delete", "drop", "alter", "create", "replace", "vacuum", "reindex", "load_extension", "union", "intersect", "except"]);
|
|
569
|
+
function validateRawSqliteQuery(query) {
|
|
570
|
+
const trimmed = query.trim();
|
|
571
|
+
if (!trimmed)
|
|
572
|
+
throw new Error("SQLite raw query must not be empty");
|
|
573
|
+
if (!/^select\b/i.test(trimmed))
|
|
574
|
+
throw new Error("Invalid raw SQLite query");
|
|
575
|
+
let quote = "", token = "";
|
|
576
|
+
const flush = () => { const lower = token.toLowerCase(); if (lower && (FORBIDDEN_RAW_QUERY_KEYWORDS.has(lower) || lower.startsWith("sqlite_") || lower.startsWith("pragma_")))
|
|
577
|
+
throw new Error("Invalid raw SQLite query"); token = ""; };
|
|
578
|
+
for (let i = 0; i < trimmed.length; i++) {
|
|
579
|
+
const ch = trimmed[i], next = trimmed[i + 1];
|
|
580
|
+
if (quote === "'") {
|
|
581
|
+
if (ch === "'" && next === "'") {
|
|
582
|
+
i++;
|
|
583
|
+
continue;
|
|
584
|
+
}
|
|
585
|
+
if (ch === "'")
|
|
586
|
+
quote = "";
|
|
587
|
+
continue;
|
|
588
|
+
}
|
|
589
|
+
if (quote === "\"") {
|
|
590
|
+
if (ch === "\"" && next === "\"") {
|
|
591
|
+
i++;
|
|
592
|
+
continue;
|
|
593
|
+
}
|
|
594
|
+
if (ch === "\"") {
|
|
595
|
+
quote = "";
|
|
596
|
+
flush();
|
|
597
|
+
continue;
|
|
598
|
+
}
|
|
599
|
+
if (ch && /[A-Za-z0-9_]/.test(ch)) {
|
|
600
|
+
token += ch;
|
|
601
|
+
continue;
|
|
602
|
+
}
|
|
603
|
+
flush();
|
|
604
|
+
token = ch;
|
|
605
|
+
continue;
|
|
606
|
+
}
|
|
607
|
+
if (ch === "'" || ch === "\"") {
|
|
608
|
+
flush();
|
|
609
|
+
quote = ch;
|
|
610
|
+
continue;
|
|
611
|
+
}
|
|
612
|
+
if (ch === ";" || ch === "-" && next === "-" || ch === "/" && next === "*" || ch === "*" && next === "/")
|
|
613
|
+
throw new Error("Invalid raw SQLite query");
|
|
614
|
+
if (ch && /[A-Za-z0-9_]/.test(ch)) {
|
|
615
|
+
token += ch;
|
|
616
|
+
continue;
|
|
617
|
+
}
|
|
618
|
+
flush();
|
|
619
|
+
}
|
|
620
|
+
flush();
|
|
621
|
+
if (quote)
|
|
622
|
+
throw new Error("Invalid raw SQLite query");
|
|
623
|
+
return trimmed;
|
|
624
|
+
}
|
|
625
|
+
function readRawSqliteRows(query) { const rows = []; const iterable = query.iterate?.(); if (!iterable)
|
|
626
|
+
return query.all().slice(0, MAX_RAW_QUERY_ROWS); for (const row of iterable) {
|
|
627
|
+
if (rows.length >= MAX_RAW_QUERY_ROWS)
|
|
628
|
+
break;
|
|
629
|
+
rows.push(row);
|
|
630
|
+
} return rows; }
|
|
631
|
+
function sqliteTableColumns(db, table) { return db.query(`pragma table_info(${quoteSqliteIdent(table)})`).all().map((row) => String(row.name ?? "")).filter(Boolean); }
|
|
632
|
+
function boundedSqliteRowCount(db, table) { const row = db.query(`select count(*) as count from (select 1 from ${quoteSqliteIdent(table)} limit ${ROW_COUNT_PROBE_CAP + 1})`).all()[0]; const count = Number(row?.count ?? 0); return count > ROW_COUNT_PROBE_CAP ? `${ROW_COUNT_PROBE_CAP}+` : count; }
|
|
633
|
+
function normalizeSqliteWriteValue(value, column) {
|
|
634
|
+
if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean")
|
|
635
|
+
return value;
|
|
636
|
+
throw new Error(`SQLite column '${column}' only accepts JSON scalar values or null`);
|
|
637
|
+
}
|
|
638
|
+
function sqlitePrimaryKey(db, table) { return db.query(`pragma table_info(${quoteSqliteIdent(table)})`).all().find((row) => row.pk === 1)?.name ?? "rowid"; }
|
|
639
|
+
export function readSqliteSelector(selector) {
|
|
640
|
+
const Database = sqliteDatabase();
|
|
641
|
+
const db = new Database(selector.databasePath, { readonly: true });
|
|
642
|
+
try {
|
|
643
|
+
if (selector.query)
|
|
644
|
+
return rowsToJsonLines(readRawSqliteRows(db.query(validateRawSqliteQuery(selector.query))));
|
|
645
|
+
if (!selector.table) {
|
|
646
|
+
const tables = db.query("select name from sqlite_master where type='table' and name not like 'sqlite_%' order by name").all().slice(0, 500);
|
|
647
|
+
return tables.map((row) => { const name = String(row.name ?? ""); return JSON.stringify({ table: name, rows: boundedSqliteRowCount(db, name) }); }).join("\n");
|
|
648
|
+
}
|
|
649
|
+
const schemaRows = db.query(`pragma table_info(${quoteSqliteIdent(selector.table)})`).all();
|
|
650
|
+
if (selector.schema)
|
|
651
|
+
return rowsToJsonLines(schemaRows);
|
|
652
|
+
const key = sqlitePrimaryKey(db, selector.table);
|
|
653
|
+
const where = selector.rowId ? `${quoteSqliteIdent(key)} = ?` : validateSqliteWhere(selector.where);
|
|
654
|
+
const order = formatSqliteOrder(selector.order);
|
|
655
|
+
const isQuery = selector.limit !== undefined || selector.offset !== undefined || selector.where || selector.order;
|
|
656
|
+
const limit = selector.sampleRows ?? selector.limit ?? (isQuery ? 20 : 5);
|
|
657
|
+
const offset = selector.offset ?? 0;
|
|
658
|
+
const sql = [`select * from ${quoteSqliteIdent(selector.table)}`, where ? `where ${where}` : "", order ? `order by ${order}` : "", "limit ? offset ?"].filter(Boolean).join(" ");
|
|
659
|
+
const rows = selector.rowId ? db.query(sql).all(selector.rowId, limit, offset) : db.query(sql).all(limit, offset);
|
|
660
|
+
if (selector.rowId || isQuery || selector.sampleRows !== undefined)
|
|
661
|
+
return rowsToJsonLines(rows);
|
|
662
|
+
return [`# ${selector.table}`, "Schema:", rowsToJsonLines(schemaRows), "Rows:", rowsToJsonLines(rows)].join("\n");
|
|
663
|
+
}
|
|
664
|
+
finally {
|
|
665
|
+
db.close();
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
function stripJson5Comments(input) {
|
|
669
|
+
let out = "", quote = "", escaped = false;
|
|
670
|
+
for (let i = 0; i < input.length; i++) {
|
|
671
|
+
const ch = input[i], next = input[i + 1];
|
|
672
|
+
if (escaped) {
|
|
673
|
+
out += ch;
|
|
674
|
+
escaped = false;
|
|
675
|
+
continue;
|
|
676
|
+
}
|
|
677
|
+
if (quote) {
|
|
678
|
+
out += ch;
|
|
679
|
+
if (ch === "\\")
|
|
680
|
+
escaped = true;
|
|
681
|
+
else if (ch === quote)
|
|
682
|
+
quote = "";
|
|
683
|
+
continue;
|
|
684
|
+
}
|
|
685
|
+
if (ch === '"' || ch === "'") {
|
|
686
|
+
quote = ch;
|
|
687
|
+
out += ch;
|
|
688
|
+
continue;
|
|
689
|
+
}
|
|
690
|
+
if (ch === "/" && next === "/") {
|
|
691
|
+
while (i < input.length && input[i] !== "\n")
|
|
692
|
+
i++;
|
|
693
|
+
out += "\n";
|
|
694
|
+
continue;
|
|
695
|
+
}
|
|
696
|
+
if (ch === "/" && next === "*") {
|
|
697
|
+
i += 2;
|
|
698
|
+
while (i < input.length && !(input[i] === "*" && input[i + 1] === "/"))
|
|
699
|
+
i++;
|
|
700
|
+
i++;
|
|
701
|
+
continue;
|
|
702
|
+
}
|
|
703
|
+
out += ch;
|
|
704
|
+
}
|
|
705
|
+
return out;
|
|
706
|
+
}
|
|
707
|
+
function parseLooseJsonObject(content) {
|
|
708
|
+
const trimmed = stripJson5Comments(content.trim());
|
|
709
|
+
if (!trimmed)
|
|
710
|
+
throw new Error("SQLite write content must be a JSON object; empty content only deletes a row when a row id is present.");
|
|
711
|
+
let parsed;
|
|
712
|
+
try {
|
|
713
|
+
parsed = JSON.parse(trimmed);
|
|
714
|
+
}
|
|
715
|
+
catch {
|
|
716
|
+
const normalized = trimmed.replace(/([{,]\s*)([A-Za-z_$][\w$]*)\s*:/g, '$1"$2":').replace(/:\s*\+(-?\d+(?:\.\d+)?)/g, ":$1").replace(/(:\s*)0x[0-9a-fA-F]+/g, (match, prefix) => `${prefix}${Number.parseInt(match.slice(prefix.length + 2), 16)}`).replace(/'([^'\\]*(?:\\.[^'\\]*)*)'/g, (_match, body) => JSON.stringify(body.replace(/\\'/g, "'"))).replace(/,\s*([}\]])/g, "$1");
|
|
717
|
+
parsed = JSON.parse(normalized);
|
|
718
|
+
}
|
|
719
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
720
|
+
throw new Error("SQLite write content must be a JSON object.");
|
|
721
|
+
return Object.fromEntries(Object.entries(parsed).map(([column, value]) => [column, normalizeSqliteWriteValue(value, column)]));
|
|
722
|
+
}
|
|
723
|
+
export function writeSqliteSelector(selector, content) {
|
|
724
|
+
if (!selector.table)
|
|
725
|
+
throw new Error("SQLite write target must include a table name");
|
|
726
|
+
if (!existsSync(selector.databasePath))
|
|
727
|
+
throw new Error(`SQLite database does not exist: ${selector.databasePath}`);
|
|
728
|
+
if (content.trim() === "") {
|
|
729
|
+
if (!selector.rowId)
|
|
730
|
+
throw new Error("SQLite empty content deletes a row only when a row id is present.");
|
|
731
|
+
const Database = sqliteDatabase();
|
|
732
|
+
const db = new Database(selector.databasePath);
|
|
733
|
+
try {
|
|
734
|
+
const table = selector.table;
|
|
735
|
+
const result = db.query(`delete from ${quoteSqliteIdent(table)} where ${quoteSqliteIdent(sqlitePrimaryKey(db, table))} = ?`).run(selector.rowId);
|
|
736
|
+
return (result.changes ?? 0) > 0 ? `Deleted row '${selector.rowId}' in ${table}` : `No row deleted for '${selector.rowId}' in ${table}`;
|
|
737
|
+
}
|
|
738
|
+
finally {
|
|
739
|
+
db.close();
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
const data = parseLooseJsonObject(content);
|
|
743
|
+
const Database = sqliteDatabase();
|
|
744
|
+
const db = new Database(selector.databasePath);
|
|
745
|
+
try {
|
|
746
|
+
const table = selector.table;
|
|
747
|
+
const quotedTable = quoteSqliteIdent(table);
|
|
748
|
+
const key = sqlitePrimaryKey(db, table);
|
|
749
|
+
const quotedKey = quoteSqliteIdent(key);
|
|
750
|
+
const validColumns = new Set(sqliteTableColumns(db, table));
|
|
751
|
+
if (!selector.rowId && key !== "id" && Object.hasOwn(data, "id") && !Object.hasOwn(data, key)) {
|
|
752
|
+
data[key] = data.id;
|
|
753
|
+
delete data.id;
|
|
754
|
+
}
|
|
755
|
+
const columns = Object.keys(data);
|
|
756
|
+
for (const column of columns)
|
|
757
|
+
if (!validColumns.has(column))
|
|
758
|
+
throw new Error(`SQLite table '${table}' has no column named '${column}'`);
|
|
759
|
+
if (columns.length === 0) {
|
|
760
|
+
if (!selector.rowId) {
|
|
761
|
+
db.query(`insert into ${quotedTable} default values`).run();
|
|
762
|
+
return `Inserted row into ${table}`;
|
|
763
|
+
}
|
|
764
|
+
throw new Error("SQLite update content must include at least one column.");
|
|
765
|
+
}
|
|
766
|
+
if (!selector.rowId) {
|
|
767
|
+
const quoted = columns.map(quoteSqliteIdent).join(", ");
|
|
768
|
+
db.query(`insert into ${quotedTable} (${quoted}) values (${columns.map(() => "?").join(", ")})`).run(...columns.map((column) => data[column]));
|
|
769
|
+
return `Inserted row into ${table}`;
|
|
770
|
+
}
|
|
771
|
+
const assignments = columns.map((column) => `${quoteSqliteIdent(column)} = ?`).join(", ");
|
|
772
|
+
const result = db.query(`update ${quotedTable} set ${assignments} where ${quotedKey} = ?`).run(...columns.map((column) => data[column]), selector.rowId);
|
|
773
|
+
return (result.changes ?? 0) > 0 ? `Updated row '${selector.rowId}' in ${table}` : `No row updated for '${selector.rowId}' in ${table}`;
|
|
774
|
+
}
|
|
775
|
+
finally {
|
|
776
|
+
db.close();
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
export function searchSqliteSelector(selector, pattern, ignoreCase = false, contextBefore = 1, contextAfter = 3) {
|
|
780
|
+
const normalized = normalizeSearchPattern(pattern, ignoreCase);
|
|
781
|
+
const matcher = new RegExp(normalized.pattern, normalized.flags);
|
|
782
|
+
if (!selector.table || selector.query)
|
|
783
|
+
return searchTextSelectorLines(`${selector.databasePath}:${selector.table ?? "tables"}`, readSqliteSelector(selector), pattern, ignoreCase, false, contextBefore, contextAfter).join("\n");
|
|
784
|
+
const Database = sqliteDatabase();
|
|
785
|
+
const db = new Database(selector.databasePath, { readonly: true });
|
|
786
|
+
try {
|
|
787
|
+
const key = sqlitePrimaryKey(db, selector.table);
|
|
788
|
+
const where = selector.rowId ? `${quoteSqliteIdent(key)} = ?` : validateSqliteWhere(selector.where);
|
|
789
|
+
const order = formatSqliteOrder(selector.order);
|
|
790
|
+
const limit = selector.sampleRows ?? selector.limit ?? 1000;
|
|
791
|
+
const offset = selector.offset ?? 0;
|
|
792
|
+
const rowIdAlias = "__atomic_rowid__";
|
|
793
|
+
const selectList = key === "rowid" ? `rowid as ${quoteSqliteIdent(rowIdAlias)}, *` : "*";
|
|
794
|
+
const sql = [`select ${selectList} from ${quoteSqliteIdent(selector.table)}`, where ? `where ${where}` : "", order ? `order by ${order}` : "", "limit ? offset ?"].filter(Boolean).join(" ");
|
|
795
|
+
const rows = selector.rowId ? db.query(sql).all(selector.rowId, limit, offset) : db.query(sql).all(limit, offset);
|
|
796
|
+
return rows.map((rawRow, index) => {
|
|
797
|
+
const row = rawRow;
|
|
798
|
+
const rowKey = key === "rowid" ? row[rowIdAlias] : row[key];
|
|
799
|
+
if (key === "rowid")
|
|
800
|
+
delete row[rowIdAlias];
|
|
801
|
+
return { row, key: String(rowKey ?? offset + index + 1) };
|
|
802
|
+
}).filter(({ row }) => matcher.test(JSON.stringify(row))).map(({ row, key }) => `${selector.databasePath}:${selector.table}:${key}: ${truncateSearchLine(JSON.stringify(row))}`).join("\n");
|
|
803
|
+
}
|
|
804
|
+
finally {
|
|
805
|
+
db.close();
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
//# sourceMappingURL=resource-selectors.js.map
|