@bastani/atomic 0.9.2-alpha.1 → 0.9.3-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +70 -0
- package/README.md +2 -2
- package/dist/builtin/cursor/CHANGELOG.md +6 -0
- package/dist/builtin/cursor/package.json +2 -2
- package/dist/builtin/intercom/CHANGELOG.md +6 -0
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/CHANGELOG.md +12 -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 +17 -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/schemas.ts +2 -2
- package/dist/builtin/subagents/src/intercom/result-intercom.ts +4 -3
- 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/shared/types-depth.ts +5 -5
- package/dist/builtin/subagents/src/shared/types-runtime.ts +2 -1
- package/dist/builtin/subagents/src/tui/render-event-formatting.ts +2 -2
- package/dist/builtin/web-access/CHANGELOG.md +6 -0
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/CHANGELOG.md +21 -0
- package/dist/builtin/workflows/README.md +2 -2
- 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/extension/config-loader.ts +35 -15
- package/dist/builtin/workflows/src/extension/discovery.ts +20 -8
- package/dist/builtin/workflows/src/extension/extension-runtime-state.ts +1 -2
- package/dist/builtin/workflows/src/extension/wiring.ts +1 -1
- package/dist/builtin/workflows/src/tui/dispatch-confirm.ts +11 -10
- 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 +11 -3
- 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/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/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/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/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 +16 -1
- package/docs/containerization.md +1 -1
- package/docs/docs.json +1 -0
- package/docs/extensions.md +25 -36
- package/docs/quickstart.md +11 -6
- package/docs/sdk.md +5 -5
- 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 +7 -5
- 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 +3 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conflict-registry.d.ts","sourceRoot":"","sources":["../../../src/core/tools/conflict-registry.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,IAAI,EAAE,MAAM,EAAE,CAAC;CACf;AAID,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,aAAa,EAAE,CAwB/E;AAED,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,IAAI,CAEjF;AAED,6FAA6F;AAC7F,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,EAAE,CAExE;AAED,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAE7F","sourcesContent":["export interface ConflictBlock {\n\tfile: string;\n\tstart: number;\n\tsep: number;\n\tend: number;\n\tbaseSep?: number;\n\tours: string[];\n\ttheirs: string[];\n\tbase: string[];\n}\n\nconst conflictRegistry = new Map<string, ConflictBlock[]>();\n\nexport function parseConflictBlocks(file: string, text: string): ConflictBlock[] {\n\tconst lines = text.split(\"\\n\"), blocks: ConflictBlock[] = [];\n\tfor (let index = 0; index < lines.length; index++) {\n\t\tif (!lines[index]?.startsWith(\"<<<<<<<\")) continue;\n\t\tlet baseSep: number | undefined, sep = -1, end = -1;\n\t\tfor (let cursor = index + 1; cursor < lines.length; cursor++) {\n\t\t\tif (lines[cursor]?.startsWith(\"|||||||\")) baseSep = cursor;\n\t\t\telse if (lines[cursor]?.startsWith(\"=======\")) sep = cursor;\n\t\t\telse if (lines[cursor]?.startsWith(\">>>>>>>\")) { end = cursor; break; }\n\t\t}\n\t\tif (sep < 0 || end < 0) continue;\n\t\tblocks.push({\n\t\t\tfile,\n\t\t\tstart: index,\n\t\t\tsep,\n\t\t\tend,\n\t\t\tbaseSep,\n\t\t\tours: lines.slice(index + 1, baseSep ?? sep),\n\t\t\tbase: baseSep === undefined ? [] : lines.slice(baseSep + 1, sep),\n\t\t\ttheirs: lines.slice(sep + 1, end),\n\t\t});\n\t\tindex = end;\n\t}\n\treturn blocks;\n}\n\nexport function registerConflictBlocks(cwd: string, blocks: ConflictBlock[]): void {\n\tconflictRegistry.set(cwd, blocks);\n}\n\n/** All conflict blocks a prior `read …:conflicts` registered for this cwd, in read order. */\nexport function getRegisteredConflictBlocks(cwd: string): ConflictBlock[] {\n\treturn conflictRegistry.get(cwd) ?? [];\n}\n\nexport function getRegisteredConflictBlock(cwd: string, id: number): ConflictBlock | undefined {\n\treturn conflictRegistry.get(cwd)?.[id - 1];\n}\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const conflictRegistry = new Map();
|
|
2
|
+
export function parseConflictBlocks(file, text) {
|
|
3
|
+
const lines = text.split("\n"), blocks = [];
|
|
4
|
+
for (let index = 0; index < lines.length; index++) {
|
|
5
|
+
if (!lines[index]?.startsWith("<<<<<<<"))
|
|
6
|
+
continue;
|
|
7
|
+
let baseSep, sep = -1, end = -1;
|
|
8
|
+
for (let cursor = index + 1; cursor < lines.length; cursor++) {
|
|
9
|
+
if (lines[cursor]?.startsWith("|||||||"))
|
|
10
|
+
baseSep = cursor;
|
|
11
|
+
else if (lines[cursor]?.startsWith("======="))
|
|
12
|
+
sep = cursor;
|
|
13
|
+
else if (lines[cursor]?.startsWith(">>>>>>>")) {
|
|
14
|
+
end = cursor;
|
|
15
|
+
break;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
if (sep < 0 || end < 0)
|
|
19
|
+
continue;
|
|
20
|
+
blocks.push({
|
|
21
|
+
file,
|
|
22
|
+
start: index,
|
|
23
|
+
sep,
|
|
24
|
+
end,
|
|
25
|
+
baseSep,
|
|
26
|
+
ours: lines.slice(index + 1, baseSep ?? sep),
|
|
27
|
+
base: baseSep === undefined ? [] : lines.slice(baseSep + 1, sep),
|
|
28
|
+
theirs: lines.slice(sep + 1, end),
|
|
29
|
+
});
|
|
30
|
+
index = end;
|
|
31
|
+
}
|
|
32
|
+
return blocks;
|
|
33
|
+
}
|
|
34
|
+
export function registerConflictBlocks(cwd, blocks) {
|
|
35
|
+
conflictRegistry.set(cwd, blocks);
|
|
36
|
+
}
|
|
37
|
+
/** All conflict blocks a prior `read …:conflicts` registered for this cwd, in read order. */
|
|
38
|
+
export function getRegisteredConflictBlocks(cwd) {
|
|
39
|
+
return conflictRegistry.get(cwd) ?? [];
|
|
40
|
+
}
|
|
41
|
+
export function getRegisteredConflictBlock(cwd, id) {
|
|
42
|
+
return conflictRegistry.get(cwd)?.[id - 1];
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=conflict-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conflict-registry.js","sourceRoot":"","sources":["../../../src/core/tools/conflict-registry.ts"],"names":[],"mappings":"AAWA,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAA2B,CAAC;AAE5D,MAAM,UAAU,mBAAmB,CAAC,IAAY,EAAE,IAAY;IAC7D,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,GAAoB,EAAE,CAAC;IAC7D,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QACnD,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC,SAAS,CAAC;YAAE,SAAS;QACnD,IAAI,OAA2B,EAAE,GAAG,GAAG,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC;QACpD,KAAK,IAAI,MAAM,GAAG,KAAK,GAAG,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC;YAC9D,IAAI,KAAK,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC,SAAS,CAAC;gBAAE,OAAO,GAAG,MAAM,CAAC;iBACtD,IAAI,KAAK,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC,SAAS,CAAC;gBAAE,GAAG,GAAG,MAAM,CAAC;iBACvD,IAAI,KAAK,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;gBAAC,GAAG,GAAG,MAAM,CAAC;gBAAC,MAAM;YAAC,CAAC;QACxE,CAAC;QACD,IAAI,GAAG,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC;YAAE,SAAS;QACjC,MAAM,CAAC,IAAI,CAAC;YACX,IAAI;YACJ,KAAK,EAAE,KAAK;YACZ,GAAG;YACH,GAAG;YACH,OAAO;YACP,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,EAAE,OAAO,IAAI,GAAG,CAAC;YAC5C,IAAI,EAAE,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC,EAAE,GAAG,CAAC;YAChE,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,EAAE,GAAG,CAAC;SACjC,CAAC,CAAC;QACH,KAAK,GAAG,GAAG,CAAC;IACb,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,GAAW,EAAE,MAAuB;IAC1E,gBAAgB,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;AACnC,CAAC;AAED,6FAA6F;AAC7F,MAAM,UAAU,2BAA2B,CAAC,GAAW;IACtD,OAAO,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,GAAW,EAAE,EAAU;IACjE,OAAO,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;AAC5C,CAAC","sourcesContent":["export interface ConflictBlock {\n\tfile: string;\n\tstart: number;\n\tsep: number;\n\tend: number;\n\tbaseSep?: number;\n\tours: string[];\n\ttheirs: string[];\n\tbase: string[];\n}\n\nconst conflictRegistry = new Map<string, ConflictBlock[]>();\n\nexport function parseConflictBlocks(file: string, text: string): ConflictBlock[] {\n\tconst lines = text.split(\"\\n\"), blocks: ConflictBlock[] = [];\n\tfor (let index = 0; index < lines.length; index++) {\n\t\tif (!lines[index]?.startsWith(\"<<<<<<<\")) continue;\n\t\tlet baseSep: number | undefined, sep = -1, end = -1;\n\t\tfor (let cursor = index + 1; cursor < lines.length; cursor++) {\n\t\t\tif (lines[cursor]?.startsWith(\"|||||||\")) baseSep = cursor;\n\t\t\telse if (lines[cursor]?.startsWith(\"=======\")) sep = cursor;\n\t\t\telse if (lines[cursor]?.startsWith(\">>>>>>>\")) { end = cursor; break; }\n\t\t}\n\t\tif (sep < 0 || end < 0) continue;\n\t\tblocks.push({\n\t\t\tfile,\n\t\t\tstart: index,\n\t\t\tsep,\n\t\t\tend,\n\t\t\tbaseSep,\n\t\t\tours: lines.slice(index + 1, baseSep ?? sep),\n\t\t\tbase: baseSep === undefined ? [] : lines.slice(baseSep + 1, sep),\n\t\t\ttheirs: lines.slice(sep + 1, end),\n\t\t});\n\t\tindex = end;\n\t}\n\treturn blocks;\n}\n\nexport function registerConflictBlocks(cwd: string, blocks: ConflictBlock[]): void {\n\tconflictRegistry.set(cwd, blocks);\n}\n\n/** All conflict blocks a prior `read …:conflicts` registered for this cwd, in read order. */\nexport function getRegisteredConflictBlocks(cwd: string): ConflictBlock[] {\n\treturn conflictRegistry.get(cwd) ?? [];\n}\n\nexport function getRegisteredConflictBlock(cwd: string, id: number): ConflictBlock | undefined {\n\treturn conflictRegistry.get(cwd)?.[id - 1];\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface DirectoryTreeResult {
|
|
2
|
+
rendered: string;
|
|
3
|
+
truncated: boolean;
|
|
4
|
+
totalLines: number;
|
|
5
|
+
}
|
|
6
|
+
interface DirectoryTreeOptions {
|
|
7
|
+
maxDepth?: number;
|
|
8
|
+
perDirLimit?: number | null;
|
|
9
|
+
rootLimit?: number | null;
|
|
10
|
+
}
|
|
11
|
+
export declare function buildDirectoryTree(rootPath: string, options?: DirectoryTreeOptions): Promise<DirectoryTreeResult>;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=directory-tree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directory-tree.d.ts","sourceRoot":"","sources":["../../../src/core/tools/directory-tree.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,mBAAmB;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACnB;AAaD,UAAU,oBAAoB;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AA+DD,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAE,oBAAyB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAO3H","sourcesContent":["import { readdir, stat } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\nimport { formatSize } from \"./truncate.ts\";\n\nexport interface DirectoryTreeResult {\n\trendered: string;\n\ttruncated: boolean;\n\ttotalLines: number;\n}\n\ninterface TreeNode {\n\tname: string;\n\tpath: string;\n\tisDir: boolean;\n\tmtimeMs: number;\n\tsize: number;\n\tdepth: number;\n\tchildren: TreeNode[];\n\tdroppedCount: number;\n}\n\ninterface DirectoryTreeOptions {\n\tmaxDepth?: number;\n\tperDirLimit?: number | null;\n\trootLimit?: number | null;\n}\n\nfunction formatAge(ageSeconds: number): string {\n\tif (ageSeconds < 60) return `${ageSeconds}s`;\n\tconst minutes = Math.floor(ageSeconds / 60);\n\tif (minutes < 60) return `${minutes}m`;\n\tconst hours = Math.floor(minutes / 60);\n\tif (hours < 24) return `${hours}h`;\n\tconst days = Math.floor(hours / 24);\n\tif (days < 30) return `${days}d`;\n\tconst months = Math.floor(days / 30);\n\tif (months < 12) return `${months}mo`;\n\treturn `${Math.floor(months / 12)}y`;\n}\n\nfunction shouldSkipDirectory(name: string): boolean { return name === \".git\" || name === \"node_modules\"; }\n\nfunction byRecency(a: TreeNode, b: TreeNode): number {\n\treturn b.mtimeMs - a.mtimeMs || a.name.localeCompare(b.name);\n}\n\nasync function buildNode(fullPath: string, name: string, depth: number, maxDepth: number): Promise<TreeNode | undefined> {\n\tconst info = await stat(fullPath).catch(() => undefined);\n\tif (!info) return undefined;\n\tconst node: TreeNode = { name, path: fullPath, isDir: info.isDirectory(), mtimeMs: info.mtimeMs, size: info.size, depth, children: [], droppedCount: 0 };\n\tif (!node.isDir || depth >= maxDepth) return node;\n\tconst entries = (await readdir(fullPath, { withFileTypes: true }).catch(() => [])).filter((entry) => !entry.isDirectory() || !shouldSkipDirectory(entry.name));\n\tconst children = await Promise.all(entries.map((entry) => buildNode(resolve(fullPath, entry.name), entry.name, depth + 1, maxDepth)));\n\tnode.children = children.filter((child): child is TreeNode => child !== undefined).sort(byRecency);\n\treturn node;\n}\n\nfunction applyChildLimit(node: TreeNode, perDirLimit: number | null, rootLimit: number | null): boolean {\n\tlet truncated = false;\n\tconst limit = node.depth === 0 ? rootLimit : perDirLimit;\n\tif (limit !== null && node.children.length > limit) {\n\t\tconst originalCount = node.children.length;\n\t\tnode.children = limit <= 1 ? node.children.slice(0, Math.max(0, limit)) : [...node.children.slice(0, limit - 1), node.children.at(-1)!];\n\t\tnode.droppedCount = originalCount - node.children.length;\n\t\ttruncated = true;\n\t}\n\tfor (const child of node.children) if (child.isDir) truncated = applyChildLimit(child, perDirLimit, rootLimit) || truncated;\n\treturn truncated;\n}\n\nfunction renderNode(node: TreeNode, now: number, out: string[]): void {\n\tif (node.depth === 0) out.push(\".\");\n\telse {\n\t\tconst indent = \" \".repeat(node.depth);\n\t\tconst suffix = node.isDir ? \"/\" : \"\";\n\t\tconst meta = node.isDir ? \"\" : ` ${formatSize(node.size).padEnd(8)} ${formatAge(Math.max(0, Math.floor((now - node.mtimeMs) / 1000)))}`;\n\t\tout.push(`${indent}- ${node.name}${suffix}${meta}`.trimEnd());\n\t}\n\tif (node.droppedCount === 0) {\n\t\tfor (const child of node.children) renderNode(child, now, out);\n\t\treturn;\n\t}\n\tconst recent = node.children.slice(0, -1), oldest = node.children.at(-1);\n\tfor (const child of recent) renderNode(child, now, out);\n\tout.push(`${\" \".repeat(node.depth + 1)}- … ${node.droppedCount} more`);\n\tif (oldest) renderNode(oldest, now, out);\n}\n\nexport async function buildDirectoryTree(rootPath: string, options: DirectoryTreeOptions = {}): Promise<DirectoryTreeResult> {\n\tconst root = await buildNode(rootPath, \".\", 0, options.maxDepth ?? 2);\n\tif (!root || root.children.length === 0) return { rendered: \"(empty directory)\", truncated: false, totalLines: 1 };\n\tconst truncated = applyChildLimit(root, options.perDirLimit ?? 12, options.rootLimit === undefined ? null : options.rootLimit);\n\tconst lines: string[] = [];\n\trenderNode(root, Date.now(), lines);\n\treturn { rendered: lines.join(\"\\n\"), truncated, totalLines: lines.length };\n}\n"]}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { readdir, stat } from "node:fs/promises";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { formatSize } from "./truncate.js";
|
|
4
|
+
function formatAge(ageSeconds) {
|
|
5
|
+
if (ageSeconds < 60)
|
|
6
|
+
return `${ageSeconds}s`;
|
|
7
|
+
const minutes = Math.floor(ageSeconds / 60);
|
|
8
|
+
if (minutes < 60)
|
|
9
|
+
return `${minutes}m`;
|
|
10
|
+
const hours = Math.floor(minutes / 60);
|
|
11
|
+
if (hours < 24)
|
|
12
|
+
return `${hours}h`;
|
|
13
|
+
const days = Math.floor(hours / 24);
|
|
14
|
+
if (days < 30)
|
|
15
|
+
return `${days}d`;
|
|
16
|
+
const months = Math.floor(days / 30);
|
|
17
|
+
if (months < 12)
|
|
18
|
+
return `${months}mo`;
|
|
19
|
+
return `${Math.floor(months / 12)}y`;
|
|
20
|
+
}
|
|
21
|
+
function shouldSkipDirectory(name) { return name === ".git" || name === "node_modules"; }
|
|
22
|
+
function byRecency(a, b) {
|
|
23
|
+
return b.mtimeMs - a.mtimeMs || a.name.localeCompare(b.name);
|
|
24
|
+
}
|
|
25
|
+
async function buildNode(fullPath, name, depth, maxDepth) {
|
|
26
|
+
const info = await stat(fullPath).catch(() => undefined);
|
|
27
|
+
if (!info)
|
|
28
|
+
return undefined;
|
|
29
|
+
const node = { name, path: fullPath, isDir: info.isDirectory(), mtimeMs: info.mtimeMs, size: info.size, depth, children: [], droppedCount: 0 };
|
|
30
|
+
if (!node.isDir || depth >= maxDepth)
|
|
31
|
+
return node;
|
|
32
|
+
const entries = (await readdir(fullPath, { withFileTypes: true }).catch(() => [])).filter((entry) => !entry.isDirectory() || !shouldSkipDirectory(entry.name));
|
|
33
|
+
const children = await Promise.all(entries.map((entry) => buildNode(resolve(fullPath, entry.name), entry.name, depth + 1, maxDepth)));
|
|
34
|
+
node.children = children.filter((child) => child !== undefined).sort(byRecency);
|
|
35
|
+
return node;
|
|
36
|
+
}
|
|
37
|
+
function applyChildLimit(node, perDirLimit, rootLimit) {
|
|
38
|
+
let truncated = false;
|
|
39
|
+
const limit = node.depth === 0 ? rootLimit : perDirLimit;
|
|
40
|
+
if (limit !== null && node.children.length > limit) {
|
|
41
|
+
const originalCount = node.children.length;
|
|
42
|
+
node.children = limit <= 1 ? node.children.slice(0, Math.max(0, limit)) : [...node.children.slice(0, limit - 1), node.children.at(-1)];
|
|
43
|
+
node.droppedCount = originalCount - node.children.length;
|
|
44
|
+
truncated = true;
|
|
45
|
+
}
|
|
46
|
+
for (const child of node.children)
|
|
47
|
+
if (child.isDir)
|
|
48
|
+
truncated = applyChildLimit(child, perDirLimit, rootLimit) || truncated;
|
|
49
|
+
return truncated;
|
|
50
|
+
}
|
|
51
|
+
function renderNode(node, now, out) {
|
|
52
|
+
if (node.depth === 0)
|
|
53
|
+
out.push(".");
|
|
54
|
+
else {
|
|
55
|
+
const indent = " ".repeat(node.depth);
|
|
56
|
+
const suffix = node.isDir ? "/" : "";
|
|
57
|
+
const meta = node.isDir ? "" : ` ${formatSize(node.size).padEnd(8)} ${formatAge(Math.max(0, Math.floor((now - node.mtimeMs) / 1000)))}`;
|
|
58
|
+
out.push(`${indent}- ${node.name}${suffix}${meta}`.trimEnd());
|
|
59
|
+
}
|
|
60
|
+
if (node.droppedCount === 0) {
|
|
61
|
+
for (const child of node.children)
|
|
62
|
+
renderNode(child, now, out);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const recent = node.children.slice(0, -1), oldest = node.children.at(-1);
|
|
66
|
+
for (const child of recent)
|
|
67
|
+
renderNode(child, now, out);
|
|
68
|
+
out.push(`${" ".repeat(node.depth + 1)}- … ${node.droppedCount} more`);
|
|
69
|
+
if (oldest)
|
|
70
|
+
renderNode(oldest, now, out);
|
|
71
|
+
}
|
|
72
|
+
export async function buildDirectoryTree(rootPath, options = {}) {
|
|
73
|
+
const root = await buildNode(rootPath, ".", 0, options.maxDepth ?? 2);
|
|
74
|
+
if (!root || root.children.length === 0)
|
|
75
|
+
return { rendered: "(empty directory)", truncated: false, totalLines: 1 };
|
|
76
|
+
const truncated = applyChildLimit(root, options.perDirLimit ?? 12, options.rootLimit === undefined ? null : options.rootLimit);
|
|
77
|
+
const lines = [];
|
|
78
|
+
renderNode(root, Date.now(), lines);
|
|
79
|
+
return { rendered: lines.join("\n"), truncated, totalLines: lines.length };
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=directory-tree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directory-tree.js","sourceRoot":"","sources":["../../../src/core/tools/directory-tree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAyB3C,SAAS,SAAS,CAAC,UAAkB;IACpC,IAAI,UAAU,GAAG,EAAE;QAAE,OAAO,GAAG,UAAU,GAAG,CAAC;IAC7C,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,GAAG,EAAE,CAAC,CAAC;IAC5C,IAAI,OAAO,GAAG,EAAE;QAAE,OAAO,GAAG,OAA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mBAAmB,EAAE,SAAS,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC;IACnH,MAAM,SAAS,GAAG,eAAe,CAAC,IAAI,EAAE,OAAO,CAAC,WAAW,IAAI,EAAE,EAAE,OAAO,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAC/H,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,KAAK,CAAC,CAAC;IACpC,OAAO,EAAE,QAAQ,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC;AAC5E,CAAC","sourcesContent":["import { readdir, stat } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\nimport { formatSize } from \"./truncate.ts\";\n\nexport interface DirectoryTreeResult {\n\trendered: string;\n\ttruncated: boolean;\n\ttotalLines: number;\n}\n\ninterface TreeNode {\n\tname: string;\n\tpath: string;\n\tisDir: boolean;\n\tmtimeMs: number;\n\tsize: number;\n\tdepth: number;\n\tchildren: TreeNode[];\n\tdroppedCount: number;\n}\n\ninterface DirectoryTreeOptions {\n\tmaxDepth?: number;\n\tperDirLimit?: number | null;\n\trootLimit?: number | null;\n}\n\nfunction formatAge(ageSeconds: number): string {\n\tif (ageSeconds < 60) return `${ageSeconds}s`;\n\tconst minutes = Math.floor(ageSeconds / 60);\n\tif (minutes < 60) return `${minutes}m`;\n\tconst hours = Math.floor(minutes / 60);\n\tif (hours < 24) return `${hours}h`;\n\tconst days = Math.floor(hours / 24);\n\tif (days < 30) return `${days}d`;\n\tconst months = Math.floor(days / 30);\n\tif (months < 12) return `${months}mo`;\n\treturn `${Math.floor(months / 12)}y`;\n}\n\nfunction shouldSkipDirectory(name: string): boolean { return name === \".git\" || name === \"node_modules\"; }\n\nfunction byRecency(a: TreeNode, b: TreeNode): number {\n\treturn b.mtimeMs - a.mtimeMs || a.name.localeCompare(b.name);\n}\n\nasync function buildNode(fullPath: string, name: string, depth: number, maxDepth: number): Promise<TreeNode | undefined> {\n\tconst info = await stat(fullPath).catch(() => undefined);\n\tif (!info) return undefined;\n\tconst node: TreeNode = { name, path: fullPath, isDir: info.isDirectory(), mtimeMs: info.mtimeMs, size: info.size, depth, children: [], droppedCount: 0 };\n\tif (!node.isDir || depth >= maxDepth) return node;\n\tconst entries = (await readdir(fullPath, { withFileTypes: true }).catch(() => [])).filter((entry) => !entry.isDirectory() || !shouldSkipDirectory(entry.name));\n\tconst children = await Promise.all(entries.map((entry) => buildNode(resolve(fullPath, entry.name), entry.name, depth + 1, maxDepth)));\n\tnode.children = children.filter((child): child is TreeNode => child !== undefined).sort(byRecency);\n\treturn node;\n}\n\nfunction applyChildLimit(node: TreeNode, perDirLimit: number | null, rootLimit: number | null): boolean {\n\tlet truncated = false;\n\tconst limit = node.depth === 0 ? rootLimit : perDirLimit;\n\tif (limit !== null && node.children.length > limit) {\n\t\tconst originalCount = node.children.length;\n\t\tnode.children = limit <= 1 ? node.children.slice(0, Math.max(0, limit)) : [...node.children.slice(0, limit - 1), node.children.at(-1)!];\n\t\tnode.droppedCount = originalCount - node.children.length;\n\t\ttruncated = true;\n\t}\n\tfor (const child of node.children) if (child.isDir) truncated = applyChildLimit(child, perDirLimit, rootLimit) || truncated;\n\treturn truncated;\n}\n\nfunction renderNode(node: TreeNode, now: number, out: string[]): void {\n\tif (node.depth === 0) out.push(\".\");\n\telse {\n\t\tconst indent = \" \".repeat(node.depth);\n\t\tconst suffix = node.isDir ? \"/\" : \"\";\n\t\tconst meta = node.isDir ? \"\" : ` ${formatSize(node.size).padEnd(8)} ${formatAge(Math.max(0, Math.floor((now - node.mtimeMs) / 1000)))}`;\n\t\tout.push(`${indent}- ${node.name}${suffix}${meta}`.trimEnd());\n\t}\n\tif (node.droppedCount === 0) {\n\t\tfor (const child of node.children) renderNode(child, now, out);\n\t\treturn;\n\t}\n\tconst recent = node.children.slice(0, -1), oldest = node.children.at(-1);\n\tfor (const child of recent) renderNode(child, now, out);\n\tout.push(`${\" \".repeat(node.depth + 1)}- … ${node.droppedCount} more`);\n\tif (oldest) renderNode(oldest, now, out);\n}\n\nexport async function buildDirectoryTree(rootPath: string, options: DirectoryTreeOptions = {}): Promise<DirectoryTreeResult> {\n\tconst root = await buildNode(rootPath, \".\", 0, options.maxDepth ?? 2);\n\tif (!root || root.children.length === 0) return { rendered: \"(empty directory)\", truncated: false, totalLines: 1 };\n\tconst truncated = applyChildLimit(root, options.perDirLimit ?? 12, options.rootLimit === undefined ? null : options.rootLimit);\n\tconst lines: string[] = [];\n\trenderNode(root, Date.now(), lines);\n\treturn { rendered: lines.join(\"\\n\"), truncated, totalLines: lines.length };\n}\n"]}
|
|
@@ -1,51 +1,26 @@
|
|
|
1
1
|
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
|
-
import { Box } from "@earendil-works/pi-tui";
|
|
3
2
|
import { type Static, Type } from "typebox";
|
|
4
3
|
import type { ToolDefinition } from "../extensions/types.ts";
|
|
5
|
-
import { type
|
|
6
|
-
type EditPreview = EditDiffResult | EditDiffError;
|
|
7
|
-
type EditRenderState = {
|
|
8
|
-
callComponent?: EditCallRenderComponent;
|
|
9
|
-
};
|
|
4
|
+
import { type HashlineSnapshotStore } from "./hashline.ts";
|
|
10
5
|
declare const editSchema: Type.TObject<{
|
|
11
|
-
|
|
12
|
-
edits: Type.TArray<Type.TObject<{
|
|
13
|
-
oldText: Type.TString;
|
|
14
|
-
newText: Type.TString;
|
|
15
|
-
}>>;
|
|
6
|
+
input: Type.TString;
|
|
16
7
|
}>;
|
|
17
8
|
export type EditToolInput = Static<typeof editSchema>;
|
|
18
9
|
export interface EditToolDetails {
|
|
19
|
-
/** Display-oriented diff of the changes made */
|
|
20
10
|
diff: string;
|
|
21
|
-
/** Standard unified patch of the changes made */
|
|
22
11
|
patch: string;
|
|
23
|
-
/** Line number of the first change in the new file (for editor navigation) */
|
|
24
12
|
firstChangedLine?: number;
|
|
25
13
|
}
|
|
26
|
-
/**
|
|
27
|
-
* Pluggable operations for the edit tool.
|
|
28
|
-
* Override these to delegate file editing to remote systems (for example SSH).
|
|
29
|
-
*/
|
|
30
14
|
export interface EditOperations {
|
|
31
|
-
/** Read file contents as a Buffer */
|
|
32
15
|
readFile: (absolutePath: string) => Promise<Buffer>;
|
|
33
|
-
/** Write content to a file */
|
|
34
16
|
writeFile: (absolutePath: string, content: string) => Promise<void>;
|
|
35
|
-
/** Check if file is readable and writable (throw if not) */
|
|
36
17
|
access: (absolutePath: string) => Promise<void>;
|
|
37
18
|
}
|
|
38
19
|
export interface EditToolOptions {
|
|
39
|
-
/** Custom operations for file editing. Default: local filesystem */
|
|
40
20
|
operations?: EditOperations;
|
|
21
|
+
hashlineStore?: HashlineSnapshotStore;
|
|
41
22
|
}
|
|
42
|
-
|
|
43
|
-
preview?: EditPreview;
|
|
44
|
-
previewArgsKey?: string;
|
|
45
|
-
previewPending?: boolean;
|
|
46
|
-
settledError?: boolean;
|
|
47
|
-
};
|
|
48
|
-
export declare function createEditToolDefinition(cwd: string, options?: EditToolOptions): ToolDefinition<typeof editSchema, EditToolDetails | undefined, EditRenderState>;
|
|
23
|
+
export declare function createEditToolDefinition(cwd: string, options?: EditToolOptions): ToolDefinition<typeof editSchema, EditToolDetails | undefined>;
|
|
49
24
|
export declare function createEditTool(cwd: string, options?: EditToolOptions): AgentTool<typeof editSchema>;
|
|
50
25
|
export {};
|
|
51
26
|
//# sourceMappingURL=edit.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../../../src/core/tools/edit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,GAAG,EAA2B,MAAM,wBAAwB,CAAC;AAGtE,OAA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wBAAgB,wBAAwB,CACvC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,eAAe,GACvB,cAAc,CAAC,OAAO,UAAU,EAAE,eAAe,GAAG,SAAS,EAAE,eAAe,CAAC,CA+IjF;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC,OAAO,UAAU,CAAC,CAEnG","sourcesContent":["import type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport { Box, Container, Spacer, Text } from \"@earendil-works/pi-tui\";\nimport { constants } from \"fs\";\nimport { access as fsAccess, readFile as fsReadFile, writeFile as fsWriteFile } from \"fs/promises\";\nimport { type Static, Type } from \"typebox\";\nimport { renderDiff } from \"../../modes/interactive/components/diff.ts\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport {\n\tapplyEditsToNormalizedContent,\n\tcomputeEditsDiff,\n\tdetectLineEnding,\n\ttype Edit,\n\ttype EditDiffError,\n\ttype EditDiffResult,\n\tgenerateDiffString,\n\tgenerateUnifiedPatch,\n\tnormalizeToLF,\n\trestoreLineEndings,\n\tstripBom,\n} from \"./edit-diff.ts\";\nimport { withFileMutationQueue } from \"./file-mutation-queue.ts\";\nimport { resolveToCwd } from \"./path-utils.ts\";\nimport { renderToolPath, str } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\ntype EditPreview = EditDiffResult | EditDiffError;\n\ntype EditRenderState = {\n\tcallComponent?: EditCallRenderComponent;\n};\n\nconst replaceEditSchema = Type.Object(\n\t{\n\t\toldText: Type.String({\n\t\t\tdescription:\n\t\t\t\t\"Exact text for one targeted replacement. It must be unique in the original file and must not overlap with any other edits[].oldText in the same call.\",\n\t\t}),\n\t\tnewText: Type.String({ description: \"Replacement text for this targeted edit.\" }),\n\t},\n\t{ additionalProperties: false },\n);\n\nconst editSchema = Type.Object(\n\t{\n\t\tpath: Type.String({ description: \"Path to the file to edit (relative or absolute)\" }),\n\t\tedits: Type.Array(replaceEditSchema, {\n\t\t\tdescription:\n\t\t\t\t\"One or more targeted replacements. Each edit is matched against the original file, not incrementally. Do not include overlapping or nested edits. If two changes touch the same block or nearby lines, merge them into one edit instead.\",\n\t\t}),\n\t},\n\t{ additionalProperties: false },\n);\n\nexport type EditToolInput = Static<typeof editSchema>;\ntype LegacyEditToolInput = EditToolInput & {\n\toldText?: unknown;\n\tnewText?: unknown;\n};\n\nexport interface EditToolDetails {\n\t/** Display-oriented diff of the changes made */\n\tdiff: string;\n\t/** Standard unified patch of the changes made */\n\tpatch: string;\n\t/** Line number of the first change in the new file (for editor navigation) */\n\tfirstChangedLine?: number;\n}\n\n/**\n * Pluggable operations for the edit tool.\n * Override these to delegate file editing to remote systems (for example SSH).\n */\nexport interface EditOperations {\n\t/** Read file contents as a Buffer */\n\treadFile: (absolutePath: string) => Promise<Buffer>;\n\t/** Write content to a file */\n\twriteFile: (absolutePath: string, content: string) => Promise<void>;\n\t/** Check if file is readable and writable (throw if not) */\n\taccess: (absolutePath: string) => Promise<void>;\n}\n\nconst defaultEditOperations: EditOperations = {\n\treadFile: (path) => fsReadFile(path),\n\twriteFile: (path, content) => fsWriteFile(path, content, \"utf-8\"),\n\taccess: (path) => fsAccess(path, constants.R_OK | constants.W_OK),\n};\n\nexport interface EditToolOptions {\n\t/** Custom operations for file editing. Default: local filesystem */\n\toperations?: EditOperations;\n}\n\nfunction prepareEditArguments(input: unknown): EditToolInput {\n\tif (!input || typeof input !== \"object\") {\n\t\treturn input as EditToolInput;\n\t}\n\n\tconst args = input as Record<string, unknown>;\n\n\t// Some models (Opus 4.6, GLM-5.1) send edits as a JSON string instead of an array\n\tif (typeof args.edits === \"string\") {\n\t\ttry {\n\t\t\tconst parsed = JSON.parse(args.edits);\n\t\t\tif (Array.isArray(parsed)) args.edits = parsed;\n\t\t} catch {}\n\t}\n\n\tconst legacy = args as LegacyEditToolInput;\n\tif (typeof legacy.oldText !== \"string\" || typeof legacy.newText !== \"string\") {\n\t\treturn args as EditToolInput;\n\t}\n\n\tconst edits = Array.isArray(legacy.edits) ? [...legacy.edits] : [];\n\tedits.push({ oldText: legacy.oldText, newText: legacy.newText });\n\tconst { oldText: _oldText, newText: _newText, ...rest } = legacy;\n\treturn { ...rest, edits } as EditToolInput;\n}\n\nfunction validateEditInput(input: EditToolInput): { path: string; edits: Edit[] } {\n\tif (!Array.isArray(input.edits) || input.edits.length === 0) {\n\t\tthrow new Error(\"Edit tool input is invalid. edits must contain at least one replacement.\");\n\t}\n\treturn { path: input.path, edits: input.edits };\n}\n\ntype RenderableEditArgs = {\n\tpath?: string;\n\tfile_path?: string;\n\tedits?: Edit[];\n\toldText?: string;\n\tnewText?: string;\n};\n\ntype EditToolResultLike = {\n\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\tdetails?: EditToolDetails;\n};\n\ntype EditCallRenderComponent = Box & {\n\tpreview?: EditPreview;\n\tpreviewArgsKey?: string;\n\tpreviewPending?: boolean;\n\tsettledError?: boolean;\n};\n\nfunction createEditCallRenderComponent(): EditCallRenderComponent {\n\treturn Object.assign(new Box(1, 1, (text: string) => text), {\n\t\tpreview: undefined as EditPreview | undefined,\n\t\tpreviewArgsKey: undefined as string | undefined,\n\t\tpreviewPending: false,\n\t\tsettledError: false,\n\t});\n}\n\nfunction getEditCallRenderComponent(state: EditRenderState, lastComponent: unknown): EditCallRenderComponent {\n\tif (lastComponent instanceof Box) {\n\t\tconst component = lastComponent as EditCallRenderComponent;\n\t\tstate.callComponent = component;\n\t\treturn component;\n\t}\n\tif (state.callComponent) {\n\t\treturn state.callComponent;\n\t}\n\tconst component = createEditCallRenderComponent();\n\tstate.callComponent = component;\n\treturn component;\n}\n\nfunction getRenderablePreviewInput(args: RenderableEditArgs | undefined): { path: string; edits: Edit[] } | null {\n\tif (!args) {\n\t\treturn null;\n\t}\n\n\tconst path = typeof args.path === \"string\" ? args.path : typeof args.file_path === \"string\" ? args.file_path : null;\n\tif (!path) {\n\t\treturn null;\n\t}\n\n\tif (\n\t\tArray.isArray(args.edits) &&\n\t\targs.edits.length > 0 &&\n\t\targs.edits.every((edit) => typeof edit?.oldText === \"string\" && typeof edit?.newText === \"string\")\n\t) {\n\t\treturn { path, edits: args.edits };\n\t}\n\n\tif (typeof args.oldText === \"string\" && typeof args.newText === \"string\") {\n\t\treturn { path, edits: [{ oldText: args.oldText, newText: args.newText }] };\n\t}\n\n\treturn null;\n}\n\nfunction formatEditCall(args: RenderableEditArgs | undefined, theme: Theme, cwd: string): string {\n\tconst pathDisplay = renderToolPath(str(args?.file_path ?? args?.path), theme, cwd);\n\treturn `${theme.fg(\"toolTitle\", theme.bold(\"edit\"))} ${pathDisplay}`;\n}\n\nfunction formatEditResult(\n\targs: RenderableEditArgs | undefined,\n\tpreview: EditPreview | undefined,\n\tresult: EditToolResultLike,\n\ttheme: Theme,\n\tisError: boolean,\n): string | undefined {\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tconst previewDiff = preview && !(\"error\" in preview) ? preview.diff : undefined;\n\tconst previewError = preview && \"error\" in preview ? preview.error : undefined;\n\tif (isError) {\n\t\tconst errorText = result.content\n\t\t\t.filter((c) => c.type === \"text\")\n\t\t\t.map((c) => c.text || \"\")\n\t\t\t.join(\"\\n\");\n\t\tif (!errorText || errorText === previewError) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn theme.fg(\"error\", errorText);\n\t}\n\n\tconst resultDiff = result.details?.diff;\n\tif (resultDiff && resultDiff !== previewDiff) {\n\t\treturn renderDiff(resultDiff, { filePath: rawPath ?? undefined });\n\t}\n\n\treturn undefined;\n}\n\nfunction getEditHeaderBg(\n\tpreview: EditPreview | undefined,\n\tsettledError: boolean | undefined,\n\ttheme: Theme,\n): (text: string) => string {\n\tif (preview) {\n\t\tif (\"error\" in preview) {\n\t\t\treturn (text: string) => theme.bg(\"toolErrorBg\", text);\n\t\t}\n\t\treturn (text: string) => theme.bg(\"toolSuccessBg\", text);\n\t}\n\tif (settledError) {\n\t\treturn (text: string) => theme.bg(\"toolErrorBg\", text);\n\t}\n\treturn (text: string) => theme.bg(\"toolPendingBg\", text);\n}\n\nfunction buildEditCallComponent(\n\tcomponent: EditCallRenderComponent,\n\targs: RenderableEditArgs | undefined,\n\ttheme: Theme,\n\tcwd: string,\n): EditCallRenderComponent {\n\tcomponent.setBgFn(getEditHeaderBg(component.preview, component.settledError, theme));\n\tcomponent.clear();\n\tcomponent.addChild(new Text(formatEditCall(args, theme, cwd), 0, 0));\n\n\tif (!component.preview) {\n\t\treturn component;\n\t}\n\n\tconst body =\n\t\t\"error\" in component.preview ? theme.fg(\"error\", component.preview.error) : renderDiff(component.preview.diff);\n\tcomponent.addChild(new Spacer(1));\n\tcomponent.addChild(new Text(body, 0, 0));\n\treturn component;\n}\n\nfunction setEditPreview(\n\tcomponent: EditCallRenderComponent,\n\tpreview: EditPreview,\n\targsKey: string | undefined,\n): boolean {\n\tconst current = component.preview;\n\tconst changed =\n\t\tcurrent === undefined ||\n\t\t(\"error\" in current && \"error\" in preview\n\t\t\t? current.error !== preview.error\n\t\t\t: \"error\" in current !== \"error\" in preview) ||\n\t\t(!(\"error\" in current) &&\n\t\t\t!(\"error\" in preview) &&\n\t\t\t(current.diff !== preview.diff || current.firstChangedLine !== preview.firstChangedLine));\n\tcomponent.preview = preview;\n\tcomponent.previewArgsKey = argsKey;\n\tcomponent.previewPending = false;\n\treturn changed;\n}\n\nexport function createEditToolDefinition(\n\tcwd: string,\n\toptions?: EditToolOptions,\n): ToolDefinition<typeof editSchema, EditToolDetails | undefined, EditRenderState> {\n\tconst ops = options?.operations ?? defaultEditOperations;\n\treturn {\n\t\tname: \"edit\",\n\t\tlabel: \"edit\",\n\t\tdescription:\n\t\t\t\"Edit a single file using exact text replacement. Every edits[].oldText must match a unique, non-overlapping region of the original file. If two changes affect the same block or nearby lines, merge them into one edit instead of emitting overlapping edits. Do not include large unchanged regions just to connect distant changes.\",\n\t\tpromptSnippet:\n\t\t\t\"Make precise file edits with exact text replacement, including multiple disjoint edits in one call\",\n\t\tpromptGuidelines: [\n\t\t\t\"Use edit for precise changes (edits[].oldText must match exactly)\",\n\t\t\t\"When changing multiple separate locations in one file, use one edit call with multiple entries in edits[] instead of multiple edit calls\",\n\t\t\t\"Each edits[].oldText is matched against the original file, not after earlier edits are applied. Do not emit overlapping or nested edits. Merge nearby changes into one edit.\",\n\t\t\t\"Keep edits[].oldText as small as possible while still being unique in the file. Do not pad with large unchanged regions.\",\n\t\t],\n\t\tparameters: editSchema,\n\t\trenderShell: \"self\",\n\t\tprepareArguments: prepareEditArguments,\n\t\tasync execute(_toolCallId, input: EditToolInput, signal?: AbortSignal, _onUpdate?, _ctx?) {\n\t\t\tconst { path, edits } = validateEditInput(input);\n\t\t\tconst absolutePath = resolveToCwd(path, cwd);\n\n\t\t\treturn withFileMutationQueue(absolutePath, async () => {\n\t\t\t\t// Do not reject from an abort event listener here: that would release the\n\t\t\t\t// mutation queue while an in-flight filesystem operation may still finish.\n\t\t\t\t// Checking signal.aborted after each await observes the same aborts while\n\t\t\t\t// keeping the queue locked until the current operation has settled.\n\t\t\t\tconst throwIfAborted = (): void => {\n\t\t\t\t\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n\t\t\t\t};\n\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Check if file exists.\n\t\t\t\ttry {\n\t\t\t\t\tawait ops.access(absolutePath);\n\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\tthrowIfAborted();\n\t\t\t\t\tconst errorMessage =\n\t\t\t\t\t\terror instanceof Error && \"code\" in error ? `Error code: ${error.code}` : String(error);\n\t\t\t\t\tthrow new Error(`Could not edit file: ${path}. ${errorMessage}.`);\n\t\t\t\t}\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Read the file.\n\t\t\t\tconst buffer = await ops.readFile(absolutePath);\n\t\t\t\tconst rawContent = buffer.toString(\"utf-8\");\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Strip BOM before matching. The model will not include an invisible BOM in oldText.\n\t\t\t\tconst { bom, text: content } = stripBom(rawContent);\n\t\t\t\tconst originalEnding = detectLineEnding(content);\n\t\t\t\tconst normalizedContent = normalizeToLF(content);\n\t\t\t\tconst { baseContent, newContent } = applyEditsToNormalizedContent(normalizedContent, edits, path);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\tconst finalContent = bom + restoreLineEndings(newContent, originalEnding);\n\t\t\t\tawait ops.writeFile(absolutePath, finalContent);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\tconst diffResult = generateDiffString(baseContent, newContent);\n\t\t\t\tconst patch = generateUnifiedPatch(path, baseContent, newContent);\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\ttext: `Successfully replaced ${edits.length} block(s) in ${path}.`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: { diff: diffResult.diff, patch, firstChangedLine: diffResult.firstChangedLine },\n\t\t\t\t};\n\t\t\t});\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst component = getEditCallRenderComponent(context.state, context.lastComponent);\n\t\t\tconst previewInput = getRenderablePreviewInput(args as RenderableEditArgs | undefined);\n\t\t\tconst argsKey = previewInput\n\t\t\t\t? JSON.stringify({ path: previewInput.path, edits: previewInput.edits })\n\t\t\t\t: undefined;\n\n\t\t\tif (component.previewArgsKey !== argsKey) {\n\t\t\t\tcomponent.preview = undefined;\n\t\t\t\tcomponent.previewArgsKey = argsKey;\n\t\t\t\tcomponent.previewPending = false;\n\t\t\t\tcomponent.settledError = false;\n\t\t\t}\n\n\t\t\tif (context.argsComplete && previewInput && !component.preview && !component.previewPending) {\n\t\t\t\tcomponent.previewPending = true;\n\t\t\t\tconst requestKey = argsKey;\n\t\t\t\tvoid computeEditsDiff(previewInput.path, previewInput.edits, context.cwd).then((preview) => {\n\t\t\t\t\tif (component.previewArgsKey === requestKey) {\n\t\t\t\t\t\tsetEditPreview(component, preview, requestKey);\n\t\t\t\t\t\tcontext.invalidate();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn buildEditCallComponent(component, args, theme, context.cwd);\n\t\t},\n\t\trenderResult(result, _options, theme, context) {\n\t\t\tconst callComponent = context.state.callComponent;\n\t\t\tconst previewInput = getRenderablePreviewInput(context.args as RenderableEditArgs | undefined);\n\t\t\tconst argsKey = previewInput\n\t\t\t\t? JSON.stringify({ path: previewInput.path, edits: previewInput.edits })\n\t\t\t\t: undefined;\n\t\t\tconst typedResult = result as EditToolResultLike;\n\t\t\tconst resultDiff = !context.isError ? typedResult.details?.diff : undefined;\n\t\t\tlet changed = false;\n\t\t\tif (callComponent) {\n\t\t\t\tif (typeof resultDiff === \"string\") {\n\t\t\t\t\tchanged =\n\t\t\t\t\t\tsetEditPreview(\n\t\t\t\t\t\t\tcallComponent,\n\t\t\t\t\t\t\t{ diff: resultDiff, firstChangedLine: typedResult.details?.firstChangedLine },\n\t\t\t\t\t\t\targsKey,\n\t\t\t\t\t\t) || changed;\n\t\t\t\t}\n\t\t\t\tif (callComponent.settledError !== context.isError) {\n\t\t\t\t\tcallComponent.settledError = context.isError;\n\t\t\t\t\tchanged = true;\n\t\t\t\t}\n\t\t\t\tif (changed) {\n\t\t\t\t\tbuildEditCallComponent(\n\t\t\t\t\t\tcallComponent,\n\t\t\t\t\t\tcontext.args as RenderableEditArgs | undefined,\n\t\t\t\t\t\ttheme,\n\t\t\t\t\t\tcontext.cwd,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst output = formatEditResult(context.args, callComponent?.preview, typedResult, theme, context.isError);\n\t\t\tconst component = (context.lastComponent as Container | undefined) ?? new Container();\n\t\t\tcomponent.clear();\n\t\t\tif (!output) {\n\t\t\t\treturn component;\n\t\t\t}\n\t\t\tcomponent.addChild(new Spacer(1));\n\t\t\tcomponent.addChild(new Text(output, 1, 0));\n\t\t\treturn component;\n\t\t},\n\t};\n}\n\nexport function createEditTool(cwd: string, options?: EditToolOptions): AgentTool<typeof editSchema> {\n\treturn wrapToolDefinition(createEditToolDefinition(cwd, options));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../../../src/core/tools/edit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAK/D,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAG5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAG7D,OAAO,EAAwF,KAAK,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAQjJ,QAAA,MAAM,UAAU;;EAGf,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AAEtD,MAAM,WAAW,eAAe;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,cAAc;IAC9B,QAAQ,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACpD,SAAS,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACpE,MAAM,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAChD;AAQD,MAAM,WAAW,eAAe;IAC/B,UAAU,CAAC,EAAE,cAAc,CAAC;IAC5B,aAAa,CAAC,EAAE,qBAAqB,CAAC;CACtC;AAwGD,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,cAAc,CAAC,OAAO,UAAU,EAAE,eAAe,GAAG,SAAS,CAAC,CAoE/I;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC,OAAO,UAAU,CAAC,CAEnG","sourcesContent":["import type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport { Container, Spacer, Text } from \"@earendil-works/pi-tui\";\nimport { Filesystem, Patch, Patcher, type PatchSectionResult, type PreparedSection, type WriteResult } from \"./hashline-engine/index.ts\";\nimport { constants } from \"fs\";\nimport { access as fsAccess, readFile as fsReadFile, writeFile as fsWriteFile } from \"fs/promises\";\nimport { type Static, Type } from \"typebox\";\nimport { renderDiff } from \"../../modes/interactive/components/diff.ts\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport { generateDiffString, generateUnifiedPatch, normalizeToLF, stripBom } from \"./edit-diff.ts\";\nimport { withFileMutationQueue } from \"./file-mutation-queue.ts\";\nimport { createHashlineSnapshotStore, formatCompactHashlineEditResult, recordHashlineSnapshot, type HashlineSnapshotStore } from \"./hashline.ts\";\nimport { invalidateNativeSearchCache } from \"./search-native.ts\";\nimport { isNotebookPath, readEditableNotebookText, serializeEditedNotebookText } from \"./notebook.ts\";\nimport { nativeBlockResolver } from \"./block-resolver.ts\";\nimport { resolveReadPath } from \"./path-utils.ts\";\nimport { renderToolPath } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst editSchema = Type.Object(\n\t{ input: Type.String({ description: \"One or more hashline file sections. Must start with [PATH#TAG]; tag comes from the latest read, search, write, or successful edit output.\" }) },\n\t{ additionalProperties: false },\n);\n\nexport type EditToolInput = Static<typeof editSchema>;\n\nexport interface EditToolDetails {\n\tdiff: string;\n\tpatch: string;\n\tfirstChangedLine?: number;\n}\n\nexport interface EditOperations {\n\treadFile: (absolutePath: string) => Promise<Buffer>;\n\twriteFile: (absolutePath: string, content: string) => Promise<void>;\n\taccess: (absolutePath: string) => Promise<void>;\n}\n\nconst defaultEditOperations: EditOperations = {\n\treadFile: (path) => fsReadFile(path),\n\twriteFile: (path, content) => fsWriteFile(path, content, \"utf-8\"),\n\taccess: (path) => fsAccess(path, constants.R_OK | constants.W_OK),\n};\n\nexport interface EditToolOptions {\n\toperations?: EditOperations;\n\thashlineStore?: HashlineSnapshotStore;\n}\n\ntype EditToolResultLike = {\n\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\tdetails?: EditToolDetails;\n};\n\nclass EditFilesystem extends Filesystem {\n\tprivate readonly cwd: string;\n\tprivate readonly operations: EditOperations;\n\tconstructor(cwd: string, operations: EditOperations) { super(); this.cwd = cwd; this.operations = operations; }\n\n\tcanonicalPath(path: string): string { return resolveReadPath(path, this.cwd); }\n\n\tasync preflightWrite(path: string): Promise<void> {\n\t\tconst absolutePath = this.canonicalPath(path);\n\t\ttry { await this.operations.access(absolutePath); }\n\t\tcatch (error: unknown) {\n\t\t\tconst message = error instanceof Error && \"code\" in error ? `Error code: ${error.code}` : String(error);\n\t\t\tthrow new Error(`Could not edit file: ${path}. ${message}.`);\n\t\t}\n\t}\n\n\tasync readText(path: string): Promise<string> {\n\t\tconst absolutePath = this.canonicalPath(path);\n\t\treturn isNotebookPath(absolutePath) ? readEditableNotebookText(absolutePath, path) : (await this.operations.readFile(absolutePath)).toString(\"utf-8\");\n\t}\n\n\tasync writeText(path: string, content: string): Promise<WriteResult> {\n\t\tconst absolutePath = this.canonicalPath(path);\n\t\tconst persisted = isNotebookPath(absolutePath) ? serializeEditedNotebookText(absolutePath, path, normalizeToLF(stripBom(content).text)) : content;\n\t\tawait this.operations.writeFile(absolutePath, persisted);\n\t\treturn { text: persisted };\n\t}\n}\n\nfunction isFourDigitHexTag(value: string): boolean {\n\treturn value.length === 4 && [...value].every((char) => (char >= \"0\" && char <= \"9\") || (char >= \"a\" && char <= \"f\") || (char >= \"A\" && char <= \"F\"));\n}\n\nfunction extractFirstHeaderPath(input: string | undefined): string | undefined {\n\tif (!input) return undefined;\n\tfor (const line of input.split(\"\\n\")) {\n\t\tconst trimmed = line.trimStart();\n\t\tif (!trimmed.startsWith(\"[\")) continue;\n\t\tconst hashIndex = trimmed.indexOf(\"#\", 1);\n\t\tconst closeIndex = hashIndex >= 0 ? trimmed.indexOf(\"]\", hashIndex + 1) : -1;\n\t\tif (hashIndex <= 1 || closeIndex !== hashIndex + 5) continue;\n\t\tconst tag = trimmed.slice(hashIndex + 1, closeIndex);\n\t\tif (isFourDigitHexTag(tag)) return trimmed.slice(1, hashIndex);\n\t}\n\treturn undefined;\n}\n\nfunction formatEditCall(args: unknown, theme: Theme, cwd: string): string {\n\tconst input = args && typeof args === \"object\" && \"input\" in args ? (args as { input?: unknown }).input : undefined;\n\tconst pathDisplay = renderToolPath(extractFirstHeaderPath(typeof input === \"string\" ? input : undefined) ?? null, theme, cwd);\n\treturn `${theme.fg(\"toolTitle\", theme.bold(\"edit\"))} ${pathDisplay}`;\n}\n\nfunction formatEditResult(result: EditToolResultLike, theme: Theme, isError: boolean): string | undefined {\n\tif (isError) {\n\t\tconst errorText = result.content.filter((c) => c.type === \"text\").map((c) => c.text || \"\").join(\"\\n\");\n\t\treturn errorText ? theme.fg(\"error\", errorText) : undefined;\n\t}\n\treturn result.details?.diff ? renderDiff(result.details.diff) : undefined;\n}\n\nasync function withFileMutationQueues<T>(filePaths: readonly string[], fn: () => Promise<T>): Promise<T> {\n\tconst sorted = [...new Set(filePaths)].sort();\n\tconst run = (index: number): Promise<T> => {\n\t\tconst filePath = sorted[index];\n\t\treturn filePath ? withFileMutationQueue(filePath, () => run(index + 1)) : fn();\n\t};\n\treturn run(0);\n}\n\nfunction throwIfAborted(signal?: AbortSignal): void {\n\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n}\n\nfunction formatNoopMessage(path: string, count: number): string {\n\treturn `Edits to ${path} parsed and applied cleanly, but produced no change: your body row(s) are byte-identical to the file at the targeted lines. The bug is somewhere else — re-read the file before issuing another edit. Do NOT widen the payload or add lines; verify the anchor first.${count > 1 ? `\\nNo-op count for this identical payload: ${count}.` : \"\"}`;\n}\n\nfunction blockMessages(item: PreparedSection | PatchSectionResult): string[] {\n\tconst warnings = \"parseWarnings\" in item ? [...item.parseWarnings, ...(item.applyResult.warnings ?? [])] : item.warnings;\n\tconst resolutions = (\"applyResult\" in item ? item.applyResult.blockResolutions : item.blockResolutions)?.map((resolution) => {\n\t\tconst verb = resolution.op === \"insert_after\" ? \"insert after block\" : `${resolution.op} block`;\n\t\tconst lands = resolution.op === \"insert_after\" ? `; body lands after line ${resolution.end}` : \"\";\n\t\treturn `${verb} ${resolution.anchorLine} → resolved lines ${resolution.start}-${resolution.end} (${resolution.end - resolution.start + 1} lines)${lands}`;\n\t}) ?? [];\n\treturn [...warnings, ...resolutions];\n}\n\nfunction assertUniquePreparedPaths(prepared: readonly PreparedSection[]): void {\n\tconst seen = new Map<string, string>();\n\tfor (const entry of prepared) {\n\t\tconst previous = seen.get(entry.canonicalPath);\n\t\tif (previous) throw new Error(`Multiple hashline sections resolve to the same file (${previous} and ${entry.section.path}). Merge their ops under one header before applying.`);\n\t\tseen.set(entry.canonicalPath, entry.section.path);\n\t}\n}\n\nexport function createEditToolDefinition(cwd: string, options?: EditToolOptions): ToolDefinition<typeof editSchema, EditToolDetails | undefined> {\n\tconst ops = options?.operations ?? defaultEditOperations;\n\tconst hashlineStore = options?.hashlineStore ?? createHashlineSnapshotStore();\n\tconst fs = new EditFilesystem(cwd, ops);\n\tconst patcher = new Patcher({ fs, snapshots: hashlineStore.snapshots, blockResolver: nativeBlockResolver });\n\tconst noopCounts = new Map<string, number>();\n\treturn {\n\t\tname: \"edit\",\n\t\tlabel: \"edit\",\n\t\tdescription: \"Edit existing files with the hashline patch language: each section starts with [PATH#TAG] (TAG is the 4-hex snapshot tag from your latest read/search), then hunk headers (replace N..M:, replace block N:, delete N..M, delete block N, insert before|after N:, insert after block N:, insert head:, insert tail:) followed by +TEXT body rows. Numbers refer to the original file. Use the write tool to create new files.\",\n\t\tpromptSnippet: \"Apply source edits with hashline patch input\",\n\t\tpromptGuidelines: [\n\t\t\t\"hashline edit format: a header ending in ':' is followed by '+'TEXT body rows; 'delete' has no body. Every section starts with [PATH#TAG]; TAG is REQUIRED (the 4-hex snapshot tag from your latest read/search) — there is no hashless form. Use the write tool to create new files.\",\n\t\t\t\"Ops: 'replace N..M:' replaces original lines N..M (INCLUSIVE — line M is consumed); 'replace block N:' replaces the whole syntactic block that BEGINS on line N (Atomic resolves the closing line with a brace/indent heuristic; point N at the opener); 'delete N..M' / 'delete block N' delete (no body); 'insert before N:' / 'insert after N:' insert relative to a line; 'insert after block N:' inserts after the END of the block beginning on N; 'insert head:' / 'insert tail:' insert at file start/end. Single line: 'replace N..N:' / 'delete N'. The range is the ORIGINAL lines you touch; body length is irrelevant.\",\n\t\t\t\"Body rows appear only under a ':' header. Every row is '+TEXT' (adds a literal line, leading whitespace kept; '+' alone adds a blank line). There is NO other body row kind — never write '-old' or a bare/context line. To keep a line, leave it out of every range. For a literal line starting with '-' or '+', prefix it: '+-x', '++x'.\",\n\t\t\t\"Numbers refer to the ORIGINAL file and do not shift as hunks apply; they die with the call — every applied edit mints a fresh #TAG and renumbers, so anchor the next edit on the edit response or a fresh read. Ranges are TIGHT: cover ONLY lines whose content changes; a stale wide range shreds everything it spans. Pure additions use 'insert', never a widened 'replace'. Whole construct → 'replace block N'; lines inside it → 'replace N..M'.\",\n\t\t\t\"On a stale-tag rejection or any surprising result: STOP and re-read before further edits. Never start or end a range mid-expression/mid-block, and never span a hunk across an elided ('…') region — read it first. Never use edit to reformat/restyle code; run the project formatter instead.\",\n\t\t],\n\t\tparameters: editSchema,\n\t\tasync execute(_toolCallId, input: EditToolInput, signal?: AbortSignal) {\n\t\t\tif (typeof input.input !== \"string\" || input.input.trim() === \"\") throw new Error(\"edit input must be a non-empty hashline script with [PATH#TAG] sections.\");\n\t\t\tconst patch = Patch.parse(input.input, { cwd });\n\t\t\tconst prepared: PreparedSection[] = [];\n\t\t\tfor (const section of patch.sections) { throwIfAborted(signal); prepared.push(await patcher.prepare(section)); }\n\t\t\tassertUniquePreparedPaths(prepared);\n\t\t\tconst noops = prepared.filter((item) => item.isNoop);\n\t\t\tif (noops.length > 0) {\n\t\t\t\tif (noops.length !== prepared.length) throw new Error(`Hashline edit for ${noops[0]!.section.path} did not change the file.`);\n\t\t\t\tconst key = prepared.map((item) => `${item.canonicalPath}\\0${item.applyResult.text}`).join(\"\\0\\0\");\n\t\t\t\tconst count = (noopCounts.get(key) ?? 0) + 1;\n\t\t\t\tnoopCounts.set(key, count);\n\t\t\t\tif (count >= 3) throw new Error(`STOP. ${formatNoopMessage(prepared[0]!.section.path, count)}`);\n\t\t\t\treturn { content: [{ type: \"text\", text: formatNoopMessage(prepared[0]!.section.path, count) }], details: { diff: \"\", patch: \"\" } };\n\t\t\t}\n\t\t\treturn withFileMutationQueues(prepared.map((item) => item.canonicalPath), async () => {\n\t\t\t\tfor (const item of prepared) if (normalizeToLF(stripBom(await fs.readText(item.section.path)).text) !== item.normalized) throw new Error(`Stale hashline tag for ${item.section.path}: file content changed before write. Re-read before editing.`);\n\t\t\t\tconst applyResult = await patcher.apply(patch);\n\t\t\t\tconst outputs: string[] = [];\n\t\t\t\tlet combinedDiff = \"\", combinedPatch = \"\";\n\t\t\t\tlet firstChangedLine: number | undefined;\n\t\t\t\tfor (const result of applyResult.sections) {\n\t\t\t\t\tthrowIfAborted(signal);\n\t\t\t\t\tinvalidateNativeSearchCache(result.canonicalPath);\n\t\t\t\t\tconst snapshot = recordHashlineSnapshot(result.canonicalPath, cwd, result.after, hashlineStore);\n\t\t\t\t\tconst diffResult = generateDiffString(result.before, result.after);\n\t\t\t\t\tcombinedDiff += `${combinedDiff ? \"\\n\" : \"\"}${diffResult.diff}`;\n\t\t\t\t\tcombinedPatch += `${combinedPatch ? \"\\n\" : \"\"}${generateUnifiedPatch(result.path, result.before, result.after)}`;\n\t\t\t\t\tfirstChangedLine ??= diffResult.firstChangedLine;\n\t\t\t\t\toutputs.push(formatCompactHashlineEditResult(snapshot, diffResult, blockMessages(result)));\n\t\t\t\t}\n\t\t\t\treturn { content: [{ type: \"text\", text: outputs.join(\"\\n\\n\") }], details: { diff: combinedDiff, patch: combinedPatch, firstChangedLine } };\n\t\t\t});\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(formatEditCall(args, theme, context.cwd));\n\t\t\treturn text;\n\t\t},\n\t\trenderResult(result, _options, theme, context) {\n\t\t\tconst output = formatEditResult(result as EditToolResultLike, theme, context.isError);\n\t\t\tconst component = (context.lastComponent as Container | undefined) ?? new Container();\n\t\t\tcomponent.clear();\n\t\t\tif (!output) return component;\n\t\t\tcomponent.addChild(new Spacer(1));\n\t\t\tcomponent.addChild(new Text(output, 1, 0));\n\t\t\treturn component;\n\t\t},\n\t};\n}\n\nexport function createEditTool(cwd: string, options?: EditToolOptions): AgentTool<typeof editSchema> {\n\treturn wrapToolDefinition(createEditToolDefinition(cwd, options));\n}\n"]}
|