@tomsun28/pizza 0.0.9 → 0.1.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/README.md +20 -143
- package/README.zh-CN.md +36 -0
- package/dist/bun/cli.d.ts +2 -0
- package/dist/bun/cli.js +6 -0
- package/dist/bun/register-bedrock.d.ts +1 -0
- package/dist/bun/register-bedrock.js +3 -0
- package/dist/cli/args.d.ts +48 -0
- package/dist/cli/args.js +330 -0
- package/dist/cli/config-selector.d.ts +13 -0
- package/dist/cli/config-selector.js +30 -0
- package/dist/cli/file-processor.d.ts +14 -0
- package/dist/cli/file-processor.js +82 -0
- package/dist/cli/initial-message.d.ts +17 -0
- package/dist/cli/initial-message.js +21 -0
- package/dist/cli/list-models.d.ts +8 -0
- package/dist/cli/list-models.js +96 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +68 -0
- package/dist/config.d.ts +79 -0
- package/dist/config.js +223 -0
- package/dist/core/agent/index.d.ts +6 -0
- package/dist/core/agent/index.js +6 -0
- package/dist/core/agent/types.d.ts +202 -0
- package/dist/core/agent/types.js +51 -0
- package/dist/core/auth-storage.d.ts +135 -0
- package/dist/core/auth-storage.js +417 -0
- package/dist/core/bash-executor.d.ts +31 -0
- package/dist/core/bash-executor.js +107 -0
- package/dist/core/compaction/branch-summarization.d.ts +87 -0
- package/dist/core/compaction/branch-summarization.js +242 -0
- package/dist/core/compaction/compaction-engine.d.ts +40 -0
- package/dist/core/compaction/compaction-engine.js +292 -0
- package/dist/core/compaction/compaction.d.ts +106 -0
- package/dist/core/compaction/compaction.js +295 -0
- package/dist/core/compaction/index.d.ts +7 -0
- package/dist/core/compaction/index.js +7 -0
- package/dist/core/compaction/utils.d.ts +37 -0
- package/dist/core/compaction/utils.js +152 -0
- package/dist/core/defaults.d.ts +2 -0
- package/dist/core/defaults.js +1 -0
- package/dist/core/diagnostics.d.ts +14 -0
- package/dist/core/diagnostics.js +1 -0
- package/dist/core/event-bus.d.ts +8 -0
- package/dist/core/event-bus.js +24 -0
- package/dist/core/event-store/events.d.ts +465 -0
- package/dist/core/event-store/events.js +6 -0
- package/dist/core/event-store/index.d.ts +10 -0
- package/dist/core/event-store/index.js +10 -0
- package/dist/core/event-store/sqlite-store.d.ts +27 -0
- package/dist/core/event-store/sqlite-store.js +275 -0
- package/dist/core/event-store/store.d.ts +91 -0
- package/dist/core/event-store/store.js +7 -0
- package/dist/core/event-store/thread-scoped-store.d.ts +29 -0
- package/dist/core/event-store/thread-scoped-store.js +50 -0
- package/dist/core/event-store/types.d.ts +70 -0
- package/dist/core/event-store/types.js +7 -0
- package/dist/core/event-store/workspace.d.ts +37 -0
- package/dist/core/event-store/workspace.js +71 -0
- package/dist/core/exec.d.ts +28 -0
- package/dist/core/exec.js +74 -0
- package/dist/core/export-html/ansi-to-html.d.ts +21 -0
- package/dist/core/export-html/ansi-to-html.js +248 -0
- package/dist/core/export-html/index.d.ts +29 -0
- package/dist/core/export-html/index.js +186 -0
- package/dist/core/export-html/template.css +1017 -0
- package/dist/core/export-html/template.html +55 -0
- package/dist/core/export-html/template.js +1742 -0
- package/dist/core/export-html/tool-renderer.d.ts +39 -0
- package/dist/core/export-html/tool-renderer.js +94 -0
- package/dist/core/export-html/vendor/highlight.min.js +1213 -0
- package/dist/core/export-html/vendor/marked.min.js +6 -0
- package/dist/core/extensions/index.d.ts +12 -0
- package/dist/core/extensions/index.js +9 -0
- package/dist/core/extensions/loader.d.ts +24 -0
- package/dist/core/extensions/loader.js +492 -0
- package/dist/core/extensions/runner.d.ts +167 -0
- package/dist/core/extensions/runner.js +898 -0
- package/dist/core/extensions/session-context.d.ts +67 -0
- package/dist/core/extensions/session-context.js +272 -0
- package/dist/core/extensions/types.d.ts +1147 -0
- package/dist/core/extensions/types.js +44 -0
- package/dist/core/extensions/wrapper.d.ts +19 -0
- package/dist/core/extensions/wrapper.js +21 -0
- package/dist/core/footer-data-provider.d.ts +47 -0
- package/dist/core/footer-data-provider.js +321 -0
- package/dist/core/goal/index.d.ts +3 -0
- package/dist/core/goal/index.js +1 -0
- package/dist/core/goal/scheduler.d.ts +83 -0
- package/dist/core/goal/scheduler.js +154 -0
- package/dist/core/goal/types.d.ts +182 -0
- package/dist/core/goal/types.js +11 -0
- package/dist/core/index.d.ts +8 -0
- package/dist/core/index.js +8 -0
- package/dist/core/intent/classifier.d.ts +53 -0
- package/dist/core/intent/classifier.js +353 -0
- package/dist/core/intent/index.d.ts +8 -0
- package/dist/core/intent/index.js +8 -0
- package/dist/core/intent/tool-adapter.d.ts +31 -0
- package/dist/core/intent/tool-adapter.js +168 -0
- package/dist/core/intent/types.d.ts +71 -0
- package/dist/core/intent/types.js +6 -0
- package/dist/core/keybindings.d.ts +297 -0
- package/dist/core/keybindings.js +250 -0
- package/dist/core/messages.d.ts +30 -0
- package/dist/core/messages.js +134 -0
- package/dist/core/model-registry.d.ts +131 -0
- package/dist/core/model-registry.js +634 -0
- package/dist/core/model-resolver.d.ts +109 -0
- package/dist/core/model-resolver.js +486 -0
- package/dist/core/output-guard.d.ts +5 -0
- package/dist/core/output-guard.js +58 -0
- package/dist/core/package-manager.d.ts +196 -0
- package/dist/core/package-manager.js +1873 -0
- package/dist/core/projection/boundary-inferrer.d.ts +58 -0
- package/dist/core/projection/boundary-inferrer.js +122 -0
- package/dist/core/projection/event-to-message.d.ts +35 -0
- package/dist/core/projection/event-to-message.js +253 -0
- package/dist/core/projection/goal-projection.d.ts +67 -0
- package/dist/core/projection/goal-projection.js +339 -0
- package/dist/core/projection/index.d.ts +13 -0
- package/dist/core/projection/index.js +13 -0
- package/dist/core/projection/session-manager.d.ts +100 -0
- package/dist/core/projection/session-manager.js +331 -0
- package/dist/core/projection/session-projection.d.ts +58 -0
- package/dist/core/projection/session-projection.js +257 -0
- package/dist/core/projection/task-history.d.ts +13 -0
- package/dist/core/projection/task-history.js +61 -0
- package/dist/core/projection/timeline-projection.d.ts +82 -0
- package/dist/core/projection/timeline-projection.js +276 -0
- package/dist/core/projection/types.d.ts +69 -0
- package/dist/core/projection/types.js +6 -0
- package/dist/core/prompt-templates.d.ts +51 -0
- package/dist/core/prompt-templates.js +249 -0
- package/dist/core/resolve-config-value.d.ts +22 -0
- package/dist/core/resolve-config-value.js +125 -0
- package/dist/core/resource-loader.d.ts +193 -0
- package/dist/core/resource-loader.js +685 -0
- package/dist/core/runtime/ai-client.d.ts +12 -0
- package/dist/core/runtime/ai-client.js +153 -0
- package/dist/core/runtime/checkpoint.d.ts +12 -0
- package/dist/core/runtime/checkpoint.js +78 -0
- package/dist/core/runtime/index.d.ts +12 -0
- package/dist/core/runtime/index.js +12 -0
- package/dist/core/runtime/llm-types.d.ts +99 -0
- package/dist/core/runtime/llm-types.js +6 -0
- package/dist/core/runtime/local-runtime.d.ts +23 -0
- package/dist/core/runtime/local-runtime.js +59 -0
- package/dist/core/runtime/policies.d.ts +72 -0
- package/dist/core/runtime/policies.js +37 -0
- package/dist/core/runtime/reactor.d.ts +213 -0
- package/dist/core/runtime/reactor.js +992 -0
- package/dist/core/runtime/runtime.d.ts +191 -0
- package/dist/core/runtime/runtime.js +449 -0
- package/dist/core/runtime/types.d.ts +42 -0
- package/dist/core/runtime/types.js +1 -0
- package/dist/core/sdk.d.ts +12 -0
- package/dist/core/sdk.js +10 -0
- package/dist/core/session-context-builder.d.ts +9 -0
- package/dist/core/session-context-builder.js +87 -0
- package/dist/core/session-cwd.d.ts +18 -0
- package/dist/core/session-cwd.js +36 -0
- package/dist/core/session-facade-factory.d.ts +79 -0
- package/dist/core/session-facade-factory.js +460 -0
- package/dist/core/session-facade.d.ts +57 -0
- package/dist/core/session-facade.js +91 -0
- package/dist/core/session-listing.d.ts +30 -0
- package/dist/core/session-listing.js +168 -0
- package/dist/core/session-reader.d.ts +19 -0
- package/dist/core/session-reader.js +101 -0
- package/dist/core/session-ref.d.ts +7 -0
- package/dist/core/session-ref.js +25 -0
- package/dist/core/session-services.d.ts +51 -0
- package/dist/core/session-services.js +90 -0
- package/dist/core/session-stats.d.ts +43 -0
- package/dist/core/session-stats.js +41 -0
- package/dist/core/settings-manager.d.ts +236 -0
- package/dist/core/settings-manager.js +706 -0
- package/dist/core/skill-block-parser.d.ts +12 -0
- package/dist/core/skill-block-parser.js +15 -0
- package/dist/core/skills.d.ts +59 -0
- package/dist/core/skills.js +408 -0
- package/dist/core/slash-commands.d.ts +13 -0
- package/dist/core/slash-commands.js +17 -0
- package/dist/core/source-info.d.ts +17 -0
- package/dist/core/source-info.js +18 -0
- package/dist/core/system-prompt.d.ts +27 -0
- package/dist/core/system-prompt.js +179 -0
- package/dist/core/timings.d.ts +7 -0
- package/dist/core/timings.js +30 -0
- package/dist/core/tools/bash.d.ts +95 -0
- package/dist/core/tools/bash.js +513 -0
- package/dist/core/tools/builtin-commands.d.ts +75 -0
- package/dist/core/tools/builtin-commands.js +503 -0
- package/dist/core/tools/compat-commands.d.ts +12 -0
- package/dist/core/tools/compat-commands.js +1280 -0
- package/dist/core/tools/edit-diff.d.ts +59 -0
- package/dist/core/tools/edit-diff.js +263 -0
- package/dist/core/tools/edit.d.ts +49 -0
- package/dist/core/tools/edit.js +340 -0
- package/dist/core/tools/file-mutation-queue.d.ts +5 -0
- package/dist/core/tools/file-mutation-queue.js +36 -0
- package/dist/core/tools/find.d.ts +34 -0
- package/dist/core/tools/find.js +459 -0
- package/dist/core/tools/grep.d.ts +36 -0
- package/dist/core/tools/grep.js +422 -0
- package/dist/core/tools/index.d.ts +70 -0
- package/dist/core/tools/index.js +129 -0
- package/dist/core/tools/line-anchors.d.ts +33 -0
- package/dist/core/tools/line-anchors.js +151 -0
- package/dist/core/tools/ls.d.ts +36 -0
- package/dist/core/tools/ls.js +268 -0
- package/dist/core/tools/path-utils.d.ts +7 -0
- package/dist/core/tools/path-utils.js +80 -0
- package/dist/core/tools/read.d.ts +35 -0
- package/dist/core/tools/read.js +244 -0
- package/dist/core/tools/render-utils.d.ts +20 -0
- package/dist/core/tools/render-utils.js +48 -0
- package/dist/core/tools/session-split.d.ts +9 -0
- package/dist/core/tools/session-split.js +77 -0
- package/dist/core/tools/tool-definition-wrapper.d.ts +13 -0
- package/dist/core/tools/tool-definition-wrapper.js +32 -0
- package/dist/core/tools/truncate.d.ts +69 -0
- package/dist/core/tools/truncate.js +204 -0
- package/dist/core/tools/write.d.ts +25 -0
- package/dist/core/tools/write.js +211 -0
- package/dist/core/types/session-types.d.ts +123 -0
- package/dist/core/types/session-types.js +8 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +38 -0
- package/dist/main.d.ts +11 -2
- package/dist/main.js +577 -149
- package/dist/modes/event-mapper.d.ts +115 -0
- package/dist/modes/event-mapper.js +200 -0
- package/dist/modes/gui/server.d.ts +14 -0
- package/dist/modes/gui/server.js +1032 -0
- package/dist/modes/index.d.ts +10 -0
- package/dist/modes/index.js +9 -0
- package/dist/modes/interactive/assets/clankolas.png +0 -0
- package/dist/modes/interactive/components/armin.d.ts +33 -0
- package/dist/modes/interactive/components/armin.js +328 -0
- package/dist/modes/interactive/components/assistant-message.d.ts +19 -0
- package/dist/modes/interactive/components/assistant-message.js +115 -0
- package/dist/modes/interactive/components/bash-execution.d.ts +33 -0
- package/dist/modes/interactive/components/bash-execution.js +169 -0
- package/dist/modes/interactive/components/bordered-loader.d.ts +15 -0
- package/dist/modes/interactive/components/bordered-loader.js +50 -0
- package/dist/modes/interactive/components/branch-summary-message.d.ts +15 -0
- package/dist/modes/interactive/components/branch-summary-message.js +41 -0
- package/dist/modes/interactive/components/brand-header.d.ts +33 -0
- package/dist/modes/interactive/components/brand-header.js +235 -0
- package/dist/modes/interactive/components/compaction-summary-message.d.ts +15 -0
- package/dist/modes/interactive/components/compaction-summary-message.js +42 -0
- package/dist/modes/interactive/components/config-selector.d.ts +70 -0
- package/dist/modes/interactive/components/config-selector.js +469 -0
- package/dist/modes/interactive/components/countdown-timer.d.ts +13 -0
- package/dist/modes/interactive/components/countdown-timer.js +27 -0
- package/dist/modes/interactive/components/custom-editor.d.ts +27 -0
- package/dist/modes/interactive/components/custom-editor.js +94 -0
- package/dist/modes/interactive/components/custom-message.d.ts +19 -0
- package/dist/modes/interactive/components/custom-message.js +73 -0
- package/dist/modes/interactive/components/daxnuts.d.ts +22 -0
- package/dist/modes/interactive/components/daxnuts.js +137 -0
- package/dist/modes/interactive/components/diff.d.ts +11 -0
- package/dist/modes/interactive/components/diff.js +132 -0
- package/dist/modes/interactive/components/dynamic-border.d.ts +14 -0
- package/dist/modes/interactive/components/dynamic-border.js +19 -0
- package/dist/modes/interactive/components/earendil-announcement.d.ts +4 -0
- package/dist/modes/interactive/components/earendil-announcement.js +39 -0
- package/dist/modes/interactive/components/extension-editor.d.ts +19 -0
- package/dist/modes/interactive/components/extension-editor.js +105 -0
- package/dist/modes/interactive/components/extension-input.d.ts +22 -0
- package/dist/modes/interactive/components/extension-input.js +54 -0
- package/dist/modes/interactive/components/extension-selector.d.ts +23 -0
- package/dist/modes/interactive/components/extension-selector.js +70 -0
- package/dist/modes/interactive/components/footer.d.ts +55 -0
- package/dist/modes/interactive/components/footer.js +207 -0
- package/dist/modes/interactive/components/index.d.ts +31 -0
- package/dist/modes/interactive/components/index.js +32 -0
- package/dist/modes/interactive/components/keybinding-hints.d.ts +7 -0
- package/dist/modes/interactive/components/keybinding-hints.js +21 -0
- package/dist/modes/interactive/components/login-dialog.d.ts +41 -0
- package/dist/modes/interactive/components/login-dialog.js +138 -0
- package/dist/modes/interactive/components/model-selector.d.ts +32 -0
- package/dist/modes/interactive/components/model-selector.js +209 -0
- package/dist/modes/interactive/components/oauth-selector.d.ts +18 -0
- package/dist/modes/interactive/components/oauth-selector.js +91 -0
- package/dist/modes/interactive/components/settings-selector.d.ts +57 -0
- package/dist/modes/interactive/components/settings-selector.js +299 -0
- package/dist/modes/interactive/components/show-images-selector.d.ts +9 -0
- package/dist/modes/interactive/components/show-images-selector.js +37 -0
- package/dist/modes/interactive/components/skill-invocation-message.d.ts +16 -0
- package/dist/modes/interactive/components/skill-invocation-message.js +44 -0
- package/dist/modes/interactive/components/theme-selector.d.ts +10 -0
- package/dist/modes/interactive/components/theme-selector.js +47 -0
- package/dist/modes/interactive/components/thinking-selector.d.ts +10 -0
- package/dist/modes/interactive/components/thinking-selector.js +50 -0
- package/dist/modes/interactive/components/timeline-view.d.ts +31 -0
- package/dist/modes/interactive/components/timeline-view.js +81 -0
- package/dist/modes/interactive/components/tool-execution.d.ts +64 -0
- package/dist/modes/interactive/components/tool-execution.js +305 -0
- package/dist/modes/interactive/components/tree-selector.d.ts +88 -0
- package/dist/modes/interactive/components/tree-selector.js +1072 -0
- package/dist/modes/interactive/components/user-message-selector.d.ts +29 -0
- package/dist/modes/interactive/components/user-message-selector.js +110 -0
- package/dist/modes/interactive/components/user-message.d.ts +9 -0
- package/dist/modes/interactive/components/user-message.js +27 -0
- package/dist/modes/interactive/components/visual-truncate.d.ts +23 -0
- package/dist/modes/interactive/components/visual-truncate.js +32 -0
- package/dist/modes/interactive/interactive-mode.d.ts +394 -0
- package/dist/modes/interactive/interactive-mode.js +4116 -0
- package/dist/modes/interactive/theme/dark.json +85 -0
- package/dist/modes/interactive/theme/light.json +84 -0
- package/dist/modes/interactive/theme/theme-schema.json +335 -0
- package/dist/modes/interactive/theme/theme.d.ts +80 -0
- package/dist/modes/interactive/theme/theme.js +973 -0
- package/dist/modes/print-mode.d.ts +27 -0
- package/dist/modes/print-mode.js +102 -0
- package/dist/modes/rpc/jsonl.d.ts +16 -0
- package/dist/modes/rpc/jsonl.js +48 -0
- package/dist/modes/rpc/rpc-client.d.ts +219 -0
- package/dist/modes/rpc/rpc-client.js +405 -0
- package/dist/modes/rpc/rpc-mode.d.ts +19 -0
- package/dist/modes/rpc/rpc-mode.js +381 -0
- package/dist/modes/rpc/rpc-types.d.ts +406 -0
- package/dist/modes/rpc/rpc-types.js +7 -0
- package/dist/package-manager-cli.d.ts +3 -0
- package/dist/package-manager-cli.js +233 -0
- package/dist/utils/changelog.d.ts +20 -0
- package/dist/utils/changelog.js +86 -0
- package/dist/utils/child-process.d.ts +10 -0
- package/dist/utils/child-process.js +77 -0
- package/dist/utils/clipboard-image.d.ts +10 -0
- package/dist/utils/clipboard-image.js +244 -0
- package/dist/utils/clipboard-native.d.ts +7 -0
- package/dist/utils/clipboard-native.js +13 -0
- package/dist/utils/clipboard.d.ts +1 -0
- package/dist/utils/clipboard.js +77 -0
- package/dist/utils/exif-orientation.d.ts +4 -0
- package/dist/utils/exif-orientation.js +157 -0
- package/dist/utils/frontmatter.d.ts +7 -0
- package/dist/utils/frontmatter.js +25 -0
- package/dist/utils/git.d.ts +25 -0
- package/dist/utils/git.js +162 -0
- package/dist/utils/image-convert.d.ts +8 -0
- package/dist/utils/image-convert.js +38 -0
- package/dist/utils/image-resize.d.ts +35 -0
- package/dist/utils/image-resize.js +136 -0
- package/dist/utils/mime.d.ts +1 -0
- package/dist/utils/mime.js +25 -0
- package/dist/utils/path-shims.d.ts +1 -0
- package/dist/utils/path-shims.js +90 -0
- package/dist/utils/paths.d.ts +6 -0
- package/dist/utils/paths.js +18 -0
- package/dist/utils/photon.d.ts +20 -0
- package/dist/utils/photon.js +120 -0
- package/dist/utils/shell.d.ts +29 -0
- package/dist/utils/shell.js +189 -0
- package/dist/utils/sleep.d.ts +4 -0
- package/dist/utils/sleep.js +16 -0
- package/dist/utils/tools-manager.d.ts +3 -0
- package/dist/utils/tools-manager.js +101 -0
- package/dist/vendor/bin/darwin-arm64/fd +0 -0
- package/dist/vendor/bin/darwin-arm64/rg +0 -0
- package/dist/vendor/bin/darwin-x64/fd +0 -0
- package/dist/vendor/bin/darwin-x64/rg +0 -0
- package/dist/vendor/bin/linux-arm64/fd +0 -0
- package/dist/vendor/bin/linux-arm64/rg +0 -0
- package/dist/vendor/bin/linux-x64/fd +0 -0
- package/dist/vendor/bin/linux-x64/rg +0 -0
- package/dist/vendor/bin/win32-arm64/fd.exe +0 -0
- package/dist/vendor/bin/win32-arm64/rg.exe +0 -0
- package/dist/vendor/bin/win32-x64/fd.exe +0 -0
- package/dist/vendor/bin/win32-x64/rg.exe +0 -0
- package/package.json +90 -26
- package/dist/extension/core.d.ts +0 -69
- package/dist/extension/core.js +0 -270
- package/dist/extension/core.js.map +0 -1
- package/dist/extension/index.d.ts +0 -25
- package/dist/extension/index.js +0 -303
- package/dist/extension/index.js.map +0 -1
- package/dist/main.js.map +0 -1
- package/themes/pizza.json +0 -87
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared diff computation utilities for the edit tool.
|
|
3
|
+
* Used by both edit.ts (for execution) and tool-execution.ts (for preview rendering).
|
|
4
|
+
*/
|
|
5
|
+
export declare function detectLineEnding(content: string): "\r\n" | "\n";
|
|
6
|
+
export declare function normalizeToLF(text: string): string;
|
|
7
|
+
export declare function restoreLineEndings(text: string, ending: "\r\n" | "\n"): string;
|
|
8
|
+
export type Edit = {
|
|
9
|
+
op: "replace";
|
|
10
|
+
range: string;
|
|
11
|
+
new: string;
|
|
12
|
+
} | {
|
|
13
|
+
op: "insert_before";
|
|
14
|
+
range: string;
|
|
15
|
+
new: string;
|
|
16
|
+
} | {
|
|
17
|
+
op: "insert_after";
|
|
18
|
+
range: string;
|
|
19
|
+
new: string;
|
|
20
|
+
} | {
|
|
21
|
+
op: "delete";
|
|
22
|
+
range: string;
|
|
23
|
+
};
|
|
24
|
+
export interface AppliedEditsResult {
|
|
25
|
+
baseContent: string;
|
|
26
|
+
newContent: string;
|
|
27
|
+
}
|
|
28
|
+
/** Strip UTF-8 BOM if present, return both the BOM (if any) and the text without it */
|
|
29
|
+
export declare function stripBom(content: string): {
|
|
30
|
+
bom: string;
|
|
31
|
+
text: string;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Apply one or more range edits to LF-normalized content.
|
|
35
|
+
*
|
|
36
|
+
* All edits are resolved against the same original content. Replacements are
|
|
37
|
+
* then applied in reverse order so offsets remain stable.
|
|
38
|
+
*/
|
|
39
|
+
export declare function applyEditsToNormalizedContent(normalizedContent: string, edits: Edit[], path: string): AppliedEditsResult;
|
|
40
|
+
/**
|
|
41
|
+
* Generate a unified diff string with line numbers and context.
|
|
42
|
+
* Returns both the diff string and the first changed line number (in the new file).
|
|
43
|
+
*/
|
|
44
|
+
export declare function generateDiffString(oldContent: string, newContent: string, contextLines?: number): {
|
|
45
|
+
diff: string;
|
|
46
|
+
firstChangedLine: number | undefined;
|
|
47
|
+
};
|
|
48
|
+
export interface EditDiffResult {
|
|
49
|
+
diff: string;
|
|
50
|
+
firstChangedLine: number | undefined;
|
|
51
|
+
}
|
|
52
|
+
export interface EditDiffError {
|
|
53
|
+
error: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Compute the diff for one or more edit operations without applying them.
|
|
57
|
+
* Used for preview rendering in the TUI before the tool executes.
|
|
58
|
+
*/
|
|
59
|
+
export declare function computeEditsDiff(path: string, edits: Edit[], cwd: string): Promise<EditDiffResult | EditDiffError>;
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared diff computation utilities for the edit tool.
|
|
3
|
+
* Used by both edit.ts (for execution) and tool-execution.ts (for preview rendering).
|
|
4
|
+
*/
|
|
5
|
+
import * as Diff from "diff";
|
|
6
|
+
import { constants } from "fs";
|
|
7
|
+
import { access, readFile } from "fs/promises";
|
|
8
|
+
import { resolveRange } from "./line-anchors.js";
|
|
9
|
+
import { resolveToCwd } from "./path-utils.js";
|
|
10
|
+
export function detectLineEnding(content) {
|
|
11
|
+
const crlfIdx = content.indexOf("\r\n");
|
|
12
|
+
const lfIdx = content.indexOf("\n");
|
|
13
|
+
if (lfIdx === -1)
|
|
14
|
+
return "\n";
|
|
15
|
+
if (crlfIdx === -1)
|
|
16
|
+
return "\n";
|
|
17
|
+
return crlfIdx < lfIdx ? "\r\n" : "\n";
|
|
18
|
+
}
|
|
19
|
+
export function normalizeToLF(text) {
|
|
20
|
+
return text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
21
|
+
}
|
|
22
|
+
export function restoreLineEndings(text, ending) {
|
|
23
|
+
return ending === "\r\n" ? text.replace(/\n/g, "\r\n") : text;
|
|
24
|
+
}
|
|
25
|
+
/** Strip UTF-8 BOM if present, return both the BOM (if any) and the text without it */
|
|
26
|
+
export function stripBom(content) {
|
|
27
|
+
return content.startsWith("\uFEFF") ? { bom: "\uFEFF", text: content.slice(1) } : { bom: "", text: content };
|
|
28
|
+
}
|
|
29
|
+
function getNoChangeError(path, totalEdits) {
|
|
30
|
+
if (totalEdits === 1) {
|
|
31
|
+
return new Error(`No changes made to ${path}. The edit produced identical content.`);
|
|
32
|
+
}
|
|
33
|
+
return new Error(`No changes made to ${path}. The edits produced identical content.`);
|
|
34
|
+
}
|
|
35
|
+
function normalizeReplacementText(newValue, existingText) {
|
|
36
|
+
const normalized = normalizeToLF(newValue);
|
|
37
|
+
if (existingText.endsWith("\n") && normalized.length > 0 && !normalized.endsWith("\n")) {
|
|
38
|
+
return `${normalized}\n`;
|
|
39
|
+
}
|
|
40
|
+
return normalized;
|
|
41
|
+
}
|
|
42
|
+
function normalizeInsertionText(newValue, op, range) {
|
|
43
|
+
const normalized = normalizeToLF(newValue);
|
|
44
|
+
if (normalized.length === 0) {
|
|
45
|
+
return "";
|
|
46
|
+
}
|
|
47
|
+
const lineText = normalized.endsWith("\n") ? normalized : `${normalized}\n`;
|
|
48
|
+
if (op === "insert_after" && range.existingText.length > 0 && !range.existingText.endsWith("\n")) {
|
|
49
|
+
return `\n${lineText}`;
|
|
50
|
+
}
|
|
51
|
+
return lineText;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Apply one or more range edits to LF-normalized content.
|
|
55
|
+
*
|
|
56
|
+
* All edits are resolved against the same original content. Replacements are
|
|
57
|
+
* then applied in reverse order so offsets remain stable.
|
|
58
|
+
*/
|
|
59
|
+
export function applyEditsToNormalizedContent(normalizedContent, edits, path) {
|
|
60
|
+
for (let i = 0; i < edits.length; i++) {
|
|
61
|
+
const edit = edits[i];
|
|
62
|
+
if (edit.range.trim().length === 0) {
|
|
63
|
+
throw new Error(`edits[${i}].range must not be empty in ${path}.`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const baseContent = normalizedContent;
|
|
67
|
+
const matchedEdits = [];
|
|
68
|
+
for (let i = 0; i < edits.length; i++) {
|
|
69
|
+
const edit = edits[i];
|
|
70
|
+
const resolved = resolveRange(baseContent, edit.range, path);
|
|
71
|
+
let matchIndex = resolved.startIndex;
|
|
72
|
+
let matchLength = resolved.endIndex - resolved.startIndex;
|
|
73
|
+
let replacement = "";
|
|
74
|
+
switch (edit.op) {
|
|
75
|
+
case "replace":
|
|
76
|
+
replacement = normalizeReplacementText(edit.new, resolved.existingText);
|
|
77
|
+
break;
|
|
78
|
+
case "insert_before":
|
|
79
|
+
matchLength = 0;
|
|
80
|
+
replacement = normalizeInsertionText(edit.new, edit.op, resolved);
|
|
81
|
+
break;
|
|
82
|
+
case "insert_after":
|
|
83
|
+
matchIndex = resolved.endIndex;
|
|
84
|
+
matchLength = 0;
|
|
85
|
+
replacement = normalizeInsertionText(edit.new, edit.op, resolved);
|
|
86
|
+
break;
|
|
87
|
+
case "delete":
|
|
88
|
+
replacement = "";
|
|
89
|
+
break;
|
|
90
|
+
default:
|
|
91
|
+
throw new Error(`edits[${i}].op is invalid in ${path}.`);
|
|
92
|
+
}
|
|
93
|
+
matchedEdits.push({
|
|
94
|
+
editIndex: i,
|
|
95
|
+
matchIndex,
|
|
96
|
+
matchLength,
|
|
97
|
+
replacement,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
matchedEdits.sort((a, b) => a.matchIndex - b.matchIndex);
|
|
101
|
+
for (let i = 1; i < matchedEdits.length; i++) {
|
|
102
|
+
const previous = matchedEdits[i - 1];
|
|
103
|
+
const current = matchedEdits[i];
|
|
104
|
+
if (previous.matchIndex + previous.matchLength > current.matchIndex) {
|
|
105
|
+
throw new Error(`edits[${previous.editIndex}] and edits[${current.editIndex}] overlap in ${path}. Merge them into one edit or target disjoint regions.`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
let newContent = baseContent;
|
|
109
|
+
for (let i = matchedEdits.length - 1; i >= 0; i--) {
|
|
110
|
+
const edit = matchedEdits[i];
|
|
111
|
+
newContent =
|
|
112
|
+
newContent.substring(0, edit.matchIndex) +
|
|
113
|
+
edit.replacement +
|
|
114
|
+
newContent.substring(edit.matchIndex + edit.matchLength);
|
|
115
|
+
}
|
|
116
|
+
if (baseContent === newContent) {
|
|
117
|
+
throw getNoChangeError(path, edits.length);
|
|
118
|
+
}
|
|
119
|
+
return { baseContent, newContent };
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Generate a unified diff string with line numbers and context.
|
|
123
|
+
* Returns both the diff string and the first changed line number (in the new file).
|
|
124
|
+
*/
|
|
125
|
+
export function generateDiffString(oldContent, newContent, contextLines = 4) {
|
|
126
|
+
const parts = Diff.diffLines(oldContent, newContent);
|
|
127
|
+
const output = [];
|
|
128
|
+
const oldLines = oldContent.split("\n");
|
|
129
|
+
const newLines = newContent.split("\n");
|
|
130
|
+
const maxLineNum = Math.max(oldLines.length, newLines.length);
|
|
131
|
+
const lineNumWidth = String(maxLineNum).length;
|
|
132
|
+
let oldLineNum = 1;
|
|
133
|
+
let newLineNum = 1;
|
|
134
|
+
let lastWasChange = false;
|
|
135
|
+
let firstChangedLine;
|
|
136
|
+
for (let i = 0; i < parts.length; i++) {
|
|
137
|
+
const part = parts[i];
|
|
138
|
+
const raw = part.value.split("\n");
|
|
139
|
+
if (raw[raw.length - 1] === "") {
|
|
140
|
+
raw.pop();
|
|
141
|
+
}
|
|
142
|
+
if (part.added || part.removed) {
|
|
143
|
+
// Capture the first changed line (in the new file)
|
|
144
|
+
if (firstChangedLine === undefined) {
|
|
145
|
+
firstChangedLine = newLineNum;
|
|
146
|
+
}
|
|
147
|
+
// Show the change
|
|
148
|
+
for (const line of raw) {
|
|
149
|
+
if (part.added) {
|
|
150
|
+
const lineNum = String(newLineNum).padStart(lineNumWidth, " ");
|
|
151
|
+
output.push(`+${lineNum} ${line}`);
|
|
152
|
+
newLineNum++;
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
// removed
|
|
156
|
+
const lineNum = String(oldLineNum).padStart(lineNumWidth, " ");
|
|
157
|
+
output.push(`-${lineNum} ${line}`);
|
|
158
|
+
oldLineNum++;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
lastWasChange = true;
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
// Context lines - only show a few before/after changes
|
|
165
|
+
const nextPartIsChange = i < parts.length - 1 && (parts[i + 1].added || parts[i + 1].removed);
|
|
166
|
+
const hasLeadingChange = lastWasChange;
|
|
167
|
+
const hasTrailingChange = nextPartIsChange;
|
|
168
|
+
if (hasLeadingChange && hasTrailingChange) {
|
|
169
|
+
if (raw.length <= contextLines * 2) {
|
|
170
|
+
for (const line of raw) {
|
|
171
|
+
const lineNum = String(oldLineNum).padStart(lineNumWidth, " ");
|
|
172
|
+
output.push(` ${lineNum} ${line}`);
|
|
173
|
+
oldLineNum++;
|
|
174
|
+
newLineNum++;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
const leadingLines = raw.slice(0, contextLines);
|
|
179
|
+
const trailingLines = raw.slice(raw.length - contextLines);
|
|
180
|
+
const skippedLines = raw.length - leadingLines.length - trailingLines.length;
|
|
181
|
+
for (const line of leadingLines) {
|
|
182
|
+
const lineNum = String(oldLineNum).padStart(lineNumWidth, " ");
|
|
183
|
+
output.push(` ${lineNum} ${line}`);
|
|
184
|
+
oldLineNum++;
|
|
185
|
+
newLineNum++;
|
|
186
|
+
}
|
|
187
|
+
output.push(` ${"".padStart(lineNumWidth, " ")} ...`);
|
|
188
|
+
oldLineNum += skippedLines;
|
|
189
|
+
newLineNum += skippedLines;
|
|
190
|
+
for (const line of trailingLines) {
|
|
191
|
+
const lineNum = String(oldLineNum).padStart(lineNumWidth, " ");
|
|
192
|
+
output.push(` ${lineNum} ${line}`);
|
|
193
|
+
oldLineNum++;
|
|
194
|
+
newLineNum++;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
else if (hasLeadingChange) {
|
|
199
|
+
const shownLines = raw.slice(0, contextLines);
|
|
200
|
+
const skippedLines = raw.length - shownLines.length;
|
|
201
|
+
for (const line of shownLines) {
|
|
202
|
+
const lineNum = String(oldLineNum).padStart(lineNumWidth, " ");
|
|
203
|
+
output.push(` ${lineNum} ${line}`);
|
|
204
|
+
oldLineNum++;
|
|
205
|
+
newLineNum++;
|
|
206
|
+
}
|
|
207
|
+
if (skippedLines > 0) {
|
|
208
|
+
output.push(` ${"".padStart(lineNumWidth, " ")} ...`);
|
|
209
|
+
oldLineNum += skippedLines;
|
|
210
|
+
newLineNum += skippedLines;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
else if (hasTrailingChange) {
|
|
214
|
+
const skippedLines = Math.max(0, raw.length - contextLines);
|
|
215
|
+
if (skippedLines > 0) {
|
|
216
|
+
output.push(` ${"".padStart(lineNumWidth, " ")} ...`);
|
|
217
|
+
oldLineNum += skippedLines;
|
|
218
|
+
newLineNum += skippedLines;
|
|
219
|
+
}
|
|
220
|
+
for (const line of raw.slice(skippedLines)) {
|
|
221
|
+
const lineNum = String(oldLineNum).padStart(lineNumWidth, " ");
|
|
222
|
+
output.push(` ${lineNum} ${line}`);
|
|
223
|
+
oldLineNum++;
|
|
224
|
+
newLineNum++;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
// Skip these context lines entirely
|
|
229
|
+
oldLineNum += raw.length;
|
|
230
|
+
newLineNum += raw.length;
|
|
231
|
+
}
|
|
232
|
+
lastWasChange = false;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return { diff: output.join("\n"), firstChangedLine };
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Compute the diff for one or more edit operations without applying them.
|
|
239
|
+
* Used for preview rendering in the TUI before the tool executes.
|
|
240
|
+
*/
|
|
241
|
+
export async function computeEditsDiff(path, edits, cwd) {
|
|
242
|
+
const absolutePath = resolveToCwd(path, cwd);
|
|
243
|
+
try {
|
|
244
|
+
// Check if file exists and is readable
|
|
245
|
+
try {
|
|
246
|
+
await access(absolutePath, constants.R_OK);
|
|
247
|
+
}
|
|
248
|
+
catch {
|
|
249
|
+
return { error: `File not found: ${path}` };
|
|
250
|
+
}
|
|
251
|
+
// Read the file
|
|
252
|
+
const rawContent = await readFile(absolutePath, "utf-8");
|
|
253
|
+
// Strip BOM before resolving line anchors.
|
|
254
|
+
const { text: content } = stripBom(rawContent);
|
|
255
|
+
const normalizedContent = normalizeToLF(content);
|
|
256
|
+
const { baseContent, newContent } = applyEditsToNormalizedContent(normalizedContent, edits, path);
|
|
257
|
+
// Generate the diff
|
|
258
|
+
return generateDiffString(baseContent, newContent);
|
|
259
|
+
}
|
|
260
|
+
catch (err) {
|
|
261
|
+
return { error: err instanceof Error ? err.message : String(err) };
|
|
262
|
+
}
|
|
263
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { AgentTool } from "../agent/types.js";
|
|
2
|
+
import { Box } from "@earendil-works/pi-tui";
|
|
3
|
+
import { type Static } from "@sinclair/typebox";
|
|
4
|
+
import type { ToolDefinition } from "../extensions/types.js";
|
|
5
|
+
import { type EditDiffError, type EditDiffResult } from "./edit-diff.js";
|
|
6
|
+
type EditPreview = EditDiffResult | EditDiffError;
|
|
7
|
+
type EditRenderState = {
|
|
8
|
+
callComponent?: EditCallRenderComponent;
|
|
9
|
+
};
|
|
10
|
+
declare const editSchema: import("@sinclair/typebox").TObject<{
|
|
11
|
+
path: import("@sinclair/typebox").TString;
|
|
12
|
+
edits: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
|
|
13
|
+
op: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"replace">, import("@sinclair/typebox").TLiteral<"insert_before">, import("@sinclair/typebox").TLiteral<"insert_after">, import("@sinclair/typebox").TLiteral<"delete">]>;
|
|
14
|
+
range: import("@sinclair/typebox").TString;
|
|
15
|
+
new: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
16
|
+
}>>;
|
|
17
|
+
}>;
|
|
18
|
+
export type EditToolInput = Static<typeof editSchema>;
|
|
19
|
+
export interface EditToolDetails {
|
|
20
|
+
/** Unified diff of the changes made */
|
|
21
|
+
diff: string;
|
|
22
|
+
/** Line number of the first change in the new file (for editor navigation) */
|
|
23
|
+
firstChangedLine?: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Pluggable operations for the edit tool.
|
|
27
|
+
* Override these to delegate file editing to remote systems (for example SSH).
|
|
28
|
+
*/
|
|
29
|
+
export interface EditOperations {
|
|
30
|
+
/** Read file contents as a Buffer */
|
|
31
|
+
readFile: (absolutePath: string) => Promise<Buffer>;
|
|
32
|
+
/** Write content to a file */
|
|
33
|
+
writeFile: (absolutePath: string, content: string) => Promise<void>;
|
|
34
|
+
/** Check if file is readable and writable (throw if not) */
|
|
35
|
+
access: (absolutePath: string) => Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
export interface EditToolOptions {
|
|
38
|
+
/** Custom operations for file editing. Default: local filesystem */
|
|
39
|
+
operations?: EditOperations;
|
|
40
|
+
}
|
|
41
|
+
type EditCallRenderComponent = Box & {
|
|
42
|
+
preview?: EditPreview;
|
|
43
|
+
previewArgsKey?: string;
|
|
44
|
+
previewPending?: boolean;
|
|
45
|
+
settledError?: boolean;
|
|
46
|
+
};
|
|
47
|
+
export declare function createEditToolDefinition(cwd: string, options?: EditToolOptions): ToolDefinition<typeof editSchema, EditToolDetails | undefined, EditRenderState>;
|
|
48
|
+
export declare function createEditTool(cwd: string, options?: EditToolOptions): AgentTool<typeof editSchema>;
|
|
49
|
+
export {};
|