@tomsun28/pizza 0.1.0 → 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 -14
- package/dist/extension/index.js +0 -374
- package/dist/extension/index.js.map +0 -1
- package/dist/main.js.map +0 -1
- package/themes/pizza.json +0 -87
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared truncation utilities for tool outputs.
|
|
3
|
+
*
|
|
4
|
+
* Truncation is based on two independent limits - whichever is hit first wins:
|
|
5
|
+
* - Line limit (default: 2000 lines)
|
|
6
|
+
* - Byte limit (default: 50KB)
|
|
7
|
+
*
|
|
8
|
+
* Never returns partial lines (except bash tail truncation edge case).
|
|
9
|
+
*/
|
|
10
|
+
export const DEFAULT_MAX_LINES = 2000;
|
|
11
|
+
export const DEFAULT_MAX_BYTES = 50 * 1024; // 50KB
|
|
12
|
+
export const GREP_MAX_LINE_LENGTH = 500; // Max chars per grep match line
|
|
13
|
+
/**
|
|
14
|
+
* Format bytes as human-readable size.
|
|
15
|
+
*/
|
|
16
|
+
export function formatSize(bytes) {
|
|
17
|
+
if (bytes < 1024) {
|
|
18
|
+
return `${bytes}B`;
|
|
19
|
+
}
|
|
20
|
+
else if (bytes < 1024 * 1024) {
|
|
21
|
+
return `${(bytes / 1024).toFixed(1)}KB`;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)}MB`;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Truncate content from the head (keep first N lines/bytes).
|
|
29
|
+
* Suitable for file reads where you want to see the beginning.
|
|
30
|
+
*
|
|
31
|
+
* Never returns partial lines. If first line exceeds byte limit,
|
|
32
|
+
* returns empty content with firstLineExceedsLimit=true.
|
|
33
|
+
*/
|
|
34
|
+
export function truncateHead(content, options = {}) {
|
|
35
|
+
const maxLines = options.maxLines ?? DEFAULT_MAX_LINES;
|
|
36
|
+
const maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;
|
|
37
|
+
const totalBytes = Buffer.byteLength(content, "utf-8");
|
|
38
|
+
const lines = content.split("\n");
|
|
39
|
+
const totalLines = lines.length;
|
|
40
|
+
// Check if no truncation needed
|
|
41
|
+
if (totalLines <= maxLines && totalBytes <= maxBytes) {
|
|
42
|
+
return {
|
|
43
|
+
content,
|
|
44
|
+
truncated: false,
|
|
45
|
+
truncatedBy: null,
|
|
46
|
+
totalLines,
|
|
47
|
+
totalBytes,
|
|
48
|
+
outputLines: totalLines,
|
|
49
|
+
outputBytes: totalBytes,
|
|
50
|
+
lastLinePartial: false,
|
|
51
|
+
firstLineExceedsLimit: false,
|
|
52
|
+
maxLines,
|
|
53
|
+
maxBytes,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
// Check if first line alone exceeds byte limit
|
|
57
|
+
const firstLineBytes = Buffer.byteLength(lines[0], "utf-8");
|
|
58
|
+
if (firstLineBytes > maxBytes) {
|
|
59
|
+
return {
|
|
60
|
+
content: "",
|
|
61
|
+
truncated: true,
|
|
62
|
+
truncatedBy: "bytes",
|
|
63
|
+
totalLines,
|
|
64
|
+
totalBytes,
|
|
65
|
+
outputLines: 0,
|
|
66
|
+
outputBytes: 0,
|
|
67
|
+
lastLinePartial: false,
|
|
68
|
+
firstLineExceedsLimit: true,
|
|
69
|
+
maxLines,
|
|
70
|
+
maxBytes,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
// Collect complete lines that fit
|
|
74
|
+
const outputLinesArr = [];
|
|
75
|
+
let outputBytesCount = 0;
|
|
76
|
+
let truncatedBy = "lines";
|
|
77
|
+
for (let i = 0; i < lines.length && i < maxLines; i++) {
|
|
78
|
+
const line = lines[i];
|
|
79
|
+
const lineBytes = Buffer.byteLength(line, "utf-8") + (i > 0 ? 1 : 0); // +1 for newline
|
|
80
|
+
if (outputBytesCount + lineBytes > maxBytes) {
|
|
81
|
+
truncatedBy = "bytes";
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
outputLinesArr.push(line);
|
|
85
|
+
outputBytesCount += lineBytes;
|
|
86
|
+
}
|
|
87
|
+
// If we exited due to line limit
|
|
88
|
+
if (outputLinesArr.length >= maxLines && outputBytesCount <= maxBytes) {
|
|
89
|
+
truncatedBy = "lines";
|
|
90
|
+
}
|
|
91
|
+
const outputContent = outputLinesArr.join("\n");
|
|
92
|
+
const finalOutputBytes = Buffer.byteLength(outputContent, "utf-8");
|
|
93
|
+
return {
|
|
94
|
+
content: outputContent,
|
|
95
|
+
truncated: true,
|
|
96
|
+
truncatedBy,
|
|
97
|
+
totalLines,
|
|
98
|
+
totalBytes,
|
|
99
|
+
outputLines: outputLinesArr.length,
|
|
100
|
+
outputBytes: finalOutputBytes,
|
|
101
|
+
lastLinePartial: false,
|
|
102
|
+
firstLineExceedsLimit: false,
|
|
103
|
+
maxLines,
|
|
104
|
+
maxBytes,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Truncate content from the tail (keep last N lines/bytes).
|
|
109
|
+
* Suitable for bash output where you want to see the end (errors, final results).
|
|
110
|
+
*
|
|
111
|
+
* May return partial first line if the last line of original content exceeds byte limit.
|
|
112
|
+
*/
|
|
113
|
+
export function truncateTail(content, options = {}) {
|
|
114
|
+
const maxLines = options.maxLines ?? DEFAULT_MAX_LINES;
|
|
115
|
+
const maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;
|
|
116
|
+
const totalBytes = Buffer.byteLength(content, "utf-8");
|
|
117
|
+
const lines = content.split("\n");
|
|
118
|
+
const totalLines = lines.length;
|
|
119
|
+
// Check if no truncation needed
|
|
120
|
+
if (totalLines <= maxLines && totalBytes <= maxBytes) {
|
|
121
|
+
return {
|
|
122
|
+
content,
|
|
123
|
+
truncated: false,
|
|
124
|
+
truncatedBy: null,
|
|
125
|
+
totalLines,
|
|
126
|
+
totalBytes,
|
|
127
|
+
outputLines: totalLines,
|
|
128
|
+
outputBytes: totalBytes,
|
|
129
|
+
lastLinePartial: false,
|
|
130
|
+
firstLineExceedsLimit: false,
|
|
131
|
+
maxLines,
|
|
132
|
+
maxBytes,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
// Work backwards from the end
|
|
136
|
+
const outputLinesArr = [];
|
|
137
|
+
let outputBytesCount = 0;
|
|
138
|
+
let truncatedBy = "lines";
|
|
139
|
+
let lastLinePartial = false;
|
|
140
|
+
for (let i = lines.length - 1; i >= 0 && outputLinesArr.length < maxLines; i--) {
|
|
141
|
+
const line = lines[i];
|
|
142
|
+
const lineBytes = Buffer.byteLength(line, "utf-8") + (outputLinesArr.length > 0 ? 1 : 0); // +1 for newline
|
|
143
|
+
if (outputBytesCount + lineBytes > maxBytes) {
|
|
144
|
+
truncatedBy = "bytes";
|
|
145
|
+
// Edge case: if we haven't added ANY lines yet and this line exceeds maxBytes,
|
|
146
|
+
// take the end of the line (partial)
|
|
147
|
+
if (outputLinesArr.length === 0) {
|
|
148
|
+
const truncatedLine = truncateStringToBytesFromEnd(line, maxBytes);
|
|
149
|
+
outputLinesArr.unshift(truncatedLine);
|
|
150
|
+
outputBytesCount = Buffer.byteLength(truncatedLine, "utf-8");
|
|
151
|
+
lastLinePartial = true;
|
|
152
|
+
}
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
outputLinesArr.unshift(line);
|
|
156
|
+
outputBytesCount += lineBytes;
|
|
157
|
+
}
|
|
158
|
+
// If we exited due to line limit
|
|
159
|
+
if (outputLinesArr.length >= maxLines && outputBytesCount <= maxBytes) {
|
|
160
|
+
truncatedBy = "lines";
|
|
161
|
+
}
|
|
162
|
+
const outputContent = outputLinesArr.join("\n");
|
|
163
|
+
const finalOutputBytes = Buffer.byteLength(outputContent, "utf-8");
|
|
164
|
+
return {
|
|
165
|
+
content: outputContent,
|
|
166
|
+
truncated: true,
|
|
167
|
+
truncatedBy,
|
|
168
|
+
totalLines,
|
|
169
|
+
totalBytes,
|
|
170
|
+
outputLines: outputLinesArr.length,
|
|
171
|
+
outputBytes: finalOutputBytes,
|
|
172
|
+
lastLinePartial,
|
|
173
|
+
firstLineExceedsLimit: false,
|
|
174
|
+
maxLines,
|
|
175
|
+
maxBytes,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Truncate a string to fit within a byte limit (from the end).
|
|
180
|
+
* Handles multi-byte UTF-8 characters correctly.
|
|
181
|
+
*/
|
|
182
|
+
function truncateStringToBytesFromEnd(str, maxBytes) {
|
|
183
|
+
const buf = Buffer.from(str, "utf-8");
|
|
184
|
+
if (buf.length <= maxBytes) {
|
|
185
|
+
return str;
|
|
186
|
+
}
|
|
187
|
+
// Start from the end, skip maxBytes back
|
|
188
|
+
let start = buf.length - maxBytes;
|
|
189
|
+
// Find a valid UTF-8 boundary (start of a character)
|
|
190
|
+
while (start < buf.length && (buf[start] & 0xc0) === 0x80) {
|
|
191
|
+
start++;
|
|
192
|
+
}
|
|
193
|
+
return buf.slice(start).toString("utf-8");
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Truncate a single line to max characters, adding [truncated] suffix.
|
|
197
|
+
* Used for grep match lines.
|
|
198
|
+
*/
|
|
199
|
+
export function truncateLine(line, maxChars = GREP_MAX_LINE_LENGTH) {
|
|
200
|
+
if (line.length <= maxChars) {
|
|
201
|
+
return { text: line, wasTruncated: false };
|
|
202
|
+
}
|
|
203
|
+
return { text: `${line.slice(0, maxChars)}... [truncated]`, wasTruncated: true };
|
|
204
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { AgentTool } from "../agent/types.js";
|
|
2
|
+
import { type Static } from "@sinclair/typebox";
|
|
3
|
+
import type { ToolDefinition } from "../extensions/types.js";
|
|
4
|
+
declare const writeSchema: import("@sinclair/typebox").TObject<{
|
|
5
|
+
path: import("@sinclair/typebox").TString;
|
|
6
|
+
content: import("@sinclair/typebox").TString;
|
|
7
|
+
}>;
|
|
8
|
+
export type WriteToolInput = Static<typeof writeSchema>;
|
|
9
|
+
/**
|
|
10
|
+
* Pluggable operations for the write tool.
|
|
11
|
+
* Override these to delegate file writing to remote systems (for example SSH).
|
|
12
|
+
*/
|
|
13
|
+
export interface WriteOperations {
|
|
14
|
+
/** Write content to a file */
|
|
15
|
+
writeFile: (absolutePath: string, content: string) => Promise<void>;
|
|
16
|
+
/** Create directory recursively */
|
|
17
|
+
mkdir: (dir: string) => Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
export interface WriteToolOptions {
|
|
20
|
+
/** Custom operations for file writing. Default: local filesystem */
|
|
21
|
+
operations?: WriteOperations;
|
|
22
|
+
}
|
|
23
|
+
export declare function createWriteToolDefinition(cwd: string, options?: WriteToolOptions): ToolDefinition<typeof writeSchema, undefined>;
|
|
24
|
+
export declare function createWriteTool(cwd: string, options?: WriteToolOptions): AgentTool<typeof writeSchema>;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { Container, Text } from "@earendil-works/pi-tui";
|
|
2
|
+
import { Type } from "@sinclair/typebox";
|
|
3
|
+
import { mkdir as fsMkdir, writeFile as fsWriteFile } from "fs/promises";
|
|
4
|
+
import { dirname } from "path";
|
|
5
|
+
import { keyHint } from "../../modes/interactive/components/keybinding-hints.js";
|
|
6
|
+
import { getLanguageFromPath, highlightCode } from "../../modes/interactive/theme/theme.js";
|
|
7
|
+
import { withFileMutationQueue } from "./file-mutation-queue.js";
|
|
8
|
+
import { resolveToCwd } from "./path-utils.js";
|
|
9
|
+
import { invalidArgText, normalizeDisplayText, replaceTabs, shortenPath, str } from "./render-utils.js";
|
|
10
|
+
import { wrapToolDefinition } from "./tool-definition-wrapper.js";
|
|
11
|
+
const writeSchema = Type.Object({
|
|
12
|
+
path: Type.String({ description: "Path to the file to write (relative or absolute)" }),
|
|
13
|
+
content: Type.String({ description: "Content to write to the file" }),
|
|
14
|
+
});
|
|
15
|
+
const defaultWriteOperations = {
|
|
16
|
+
writeFile: (path, content) => fsWriteFile(path, content, "utf-8"),
|
|
17
|
+
mkdir: (dir) => fsMkdir(dir, { recursive: true }).then(() => { }),
|
|
18
|
+
};
|
|
19
|
+
class WriteCallRenderComponent extends Text {
|
|
20
|
+
constructor() {
|
|
21
|
+
super("", 0, 0);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const WRITE_PARTIAL_FULL_HIGHLIGHT_LINES = 50;
|
|
25
|
+
function highlightSingleLine(line, lang) {
|
|
26
|
+
const highlighted = highlightCode(line, lang);
|
|
27
|
+
return highlighted[0] ?? "";
|
|
28
|
+
}
|
|
29
|
+
function refreshWriteHighlightPrefix(cache) {
|
|
30
|
+
const prefixCount = Math.min(WRITE_PARTIAL_FULL_HIGHLIGHT_LINES, cache.normalizedLines.length);
|
|
31
|
+
if (prefixCount === 0)
|
|
32
|
+
return;
|
|
33
|
+
const prefixSource = cache.normalizedLines.slice(0, prefixCount).join("\n");
|
|
34
|
+
const prefixHighlighted = highlightCode(prefixSource, cache.lang);
|
|
35
|
+
for (let i = 0; i < prefixCount; i++) {
|
|
36
|
+
cache.highlightedLines[i] =
|
|
37
|
+
prefixHighlighted[i] ?? highlightSingleLine(cache.normalizedLines[i] ?? "", cache.lang);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function rebuildWriteHighlightCacheFull(rawPath, fileContent) {
|
|
41
|
+
const lang = rawPath ? getLanguageFromPath(rawPath) : undefined;
|
|
42
|
+
if (!lang)
|
|
43
|
+
return undefined;
|
|
44
|
+
const displayContent = normalizeDisplayText(fileContent);
|
|
45
|
+
const normalized = replaceTabs(displayContent);
|
|
46
|
+
return {
|
|
47
|
+
rawPath,
|
|
48
|
+
lang,
|
|
49
|
+
rawContent: fileContent,
|
|
50
|
+
normalizedLines: normalized.split("\n"),
|
|
51
|
+
highlightedLines: highlightCode(normalized, lang),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function updateWriteHighlightCacheIncremental(cache, rawPath, fileContent) {
|
|
55
|
+
const lang = rawPath ? getLanguageFromPath(rawPath) : undefined;
|
|
56
|
+
if (!lang)
|
|
57
|
+
return undefined;
|
|
58
|
+
if (!cache)
|
|
59
|
+
return rebuildWriteHighlightCacheFull(rawPath, fileContent);
|
|
60
|
+
if (cache.lang !== lang || cache.rawPath !== rawPath)
|
|
61
|
+
return rebuildWriteHighlightCacheFull(rawPath, fileContent);
|
|
62
|
+
if (!fileContent.startsWith(cache.rawContent))
|
|
63
|
+
return rebuildWriteHighlightCacheFull(rawPath, fileContent);
|
|
64
|
+
if (fileContent.length === cache.rawContent.length)
|
|
65
|
+
return cache;
|
|
66
|
+
const deltaRaw = fileContent.slice(cache.rawContent.length);
|
|
67
|
+
const deltaDisplay = normalizeDisplayText(deltaRaw);
|
|
68
|
+
const deltaNormalized = replaceTabs(deltaDisplay);
|
|
69
|
+
cache.rawContent = fileContent;
|
|
70
|
+
if (cache.normalizedLines.length === 0) {
|
|
71
|
+
cache.normalizedLines.push("");
|
|
72
|
+
cache.highlightedLines.push("");
|
|
73
|
+
}
|
|
74
|
+
const segments = deltaNormalized.split("\n");
|
|
75
|
+
const lastIndex = cache.normalizedLines.length - 1;
|
|
76
|
+
cache.normalizedLines[lastIndex] += segments[0];
|
|
77
|
+
cache.highlightedLines[lastIndex] = highlightSingleLine(cache.normalizedLines[lastIndex], cache.lang);
|
|
78
|
+
for (let i = 1; i < segments.length; i++) {
|
|
79
|
+
cache.normalizedLines.push(segments[i]);
|
|
80
|
+
cache.highlightedLines.push(highlightSingleLine(segments[i], cache.lang));
|
|
81
|
+
}
|
|
82
|
+
refreshWriteHighlightPrefix(cache);
|
|
83
|
+
return cache;
|
|
84
|
+
}
|
|
85
|
+
function trimTrailingEmptyLines(lines) {
|
|
86
|
+
let end = lines.length;
|
|
87
|
+
while (end > 0 && lines[end - 1] === "") {
|
|
88
|
+
end--;
|
|
89
|
+
}
|
|
90
|
+
return lines.slice(0, end);
|
|
91
|
+
}
|
|
92
|
+
function formatWriteCall(args, options, theme, cache) {
|
|
93
|
+
const rawPath = str(args?.file_path ?? args?.path);
|
|
94
|
+
const fileContent = str(args?.content);
|
|
95
|
+
const path = rawPath !== null ? shortenPath(rawPath) : null;
|
|
96
|
+
const invalidArg = invalidArgText(theme);
|
|
97
|
+
let text = `${theme.fg("toolTitle", theme.bold("write"))} ${path === null ? invalidArg : path ? theme.fg("accent", path) : theme.fg("toolOutput", "...")}`;
|
|
98
|
+
if (fileContent === null) {
|
|
99
|
+
text += `\n\n${theme.fg("error", "[invalid content arg - expected string]")}`;
|
|
100
|
+
}
|
|
101
|
+
else if (fileContent) {
|
|
102
|
+
const lang = rawPath ? getLanguageFromPath(rawPath) : undefined;
|
|
103
|
+
const renderedLines = lang
|
|
104
|
+
? (cache?.highlightedLines ?? highlightCode(replaceTabs(normalizeDisplayText(fileContent)), lang))
|
|
105
|
+
: normalizeDisplayText(fileContent).split("\n");
|
|
106
|
+
const lines = trimTrailingEmptyLines(renderedLines);
|
|
107
|
+
const totalLines = lines.length;
|
|
108
|
+
const maxLines = options.expanded ? lines.length : 10;
|
|
109
|
+
const displayLines = lines.slice(0, maxLines);
|
|
110
|
+
const remaining = lines.length - maxLines;
|
|
111
|
+
text += `\n\n${displayLines.map((line) => (lang ? line : theme.fg("toolOutput", replaceTabs(line)))).join("\n")}`;
|
|
112
|
+
if (remaining > 0) {
|
|
113
|
+
text += `${theme.fg("muted", `\n... (${remaining} more lines, ${totalLines} total,`)} ${keyHint("app.tools.expand", "to expand")})`;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return text;
|
|
117
|
+
}
|
|
118
|
+
function formatWriteResult(result, theme) {
|
|
119
|
+
if (!result.isError) {
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
const output = result.content
|
|
123
|
+
.filter((c) => c.type === "text")
|
|
124
|
+
.map((c) => c.text || "")
|
|
125
|
+
.join("\n");
|
|
126
|
+
if (!output) {
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
return `\n${theme.fg("error", output)}`;
|
|
130
|
+
}
|
|
131
|
+
export function createWriteToolDefinition(cwd, options) {
|
|
132
|
+
const ops = options?.operations ?? defaultWriteOperations;
|
|
133
|
+
return {
|
|
134
|
+
name: "write",
|
|
135
|
+
label: "write",
|
|
136
|
+
description: "Write content to a file. Creates the file if it doesn't exist, overwrites if it does. Automatically creates parent directories.",
|
|
137
|
+
promptSnippet: "Create or overwrite files",
|
|
138
|
+
promptGuidelines: ["Use write only for new files or complete rewrites."],
|
|
139
|
+
parameters: writeSchema,
|
|
140
|
+
async execute(_toolCallId, { path, content }, signal, _onUpdate, _ctx) {
|
|
141
|
+
const absolutePath = resolveToCwd(path, cwd);
|
|
142
|
+
const dir = dirname(absolutePath);
|
|
143
|
+
return withFileMutationQueue(absolutePath, () => new Promise((resolve, reject) => {
|
|
144
|
+
if (signal?.aborted) {
|
|
145
|
+
reject(new Error("Operation aborted"));
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
let aborted = false;
|
|
149
|
+
const onAbort = () => {
|
|
150
|
+
aborted = true;
|
|
151
|
+
reject(new Error("Operation aborted"));
|
|
152
|
+
};
|
|
153
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
154
|
+
(async () => {
|
|
155
|
+
try {
|
|
156
|
+
// Create parent directories if needed.
|
|
157
|
+
await ops.mkdir(dir);
|
|
158
|
+
if (aborted)
|
|
159
|
+
return;
|
|
160
|
+
// Write the file contents.
|
|
161
|
+
await ops.writeFile(absolutePath, content);
|
|
162
|
+
if (aborted)
|
|
163
|
+
return;
|
|
164
|
+
signal?.removeEventListener("abort", onAbort);
|
|
165
|
+
resolve({
|
|
166
|
+
content: [
|
|
167
|
+
{ type: "text", text: `Successfully wrote ${content.length} bytes to ${path}` },
|
|
168
|
+
],
|
|
169
|
+
details: undefined,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
signal?.removeEventListener("abort", onAbort);
|
|
174
|
+
if (!aborted)
|
|
175
|
+
reject(error);
|
|
176
|
+
}
|
|
177
|
+
})();
|
|
178
|
+
}));
|
|
179
|
+
},
|
|
180
|
+
renderCall(args, theme, context) {
|
|
181
|
+
const renderArgs = args;
|
|
182
|
+
const rawPath = str(renderArgs?.file_path ?? renderArgs?.path);
|
|
183
|
+
const fileContent = str(renderArgs?.content);
|
|
184
|
+
const component = context.lastComponent ?? new WriteCallRenderComponent();
|
|
185
|
+
if (fileContent !== null) {
|
|
186
|
+
component.cache = context.argsComplete
|
|
187
|
+
? rebuildWriteHighlightCacheFull(rawPath, fileContent)
|
|
188
|
+
: updateWriteHighlightCacheIncremental(component.cache, rawPath, fileContent);
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
component.cache = undefined;
|
|
192
|
+
}
|
|
193
|
+
component.setText(formatWriteCall(renderArgs, { expanded: context.expanded, isPartial: context.isPartial }, theme, component.cache));
|
|
194
|
+
return component;
|
|
195
|
+
},
|
|
196
|
+
renderResult(result, _options, theme, context) {
|
|
197
|
+
const output = formatWriteResult({ ...result, isError: context.isError }, theme);
|
|
198
|
+
if (!output) {
|
|
199
|
+
const component = context.lastComponent ?? new Container();
|
|
200
|
+
component.clear();
|
|
201
|
+
return component;
|
|
202
|
+
}
|
|
203
|
+
const text = context.lastComponent ?? new Text("", 0, 0);
|
|
204
|
+
text.setText(output);
|
|
205
|
+
return text;
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
export function createWriteTool(cwd, options) {
|
|
210
|
+
return wrapToolDefinition(createWriteToolDefinition(cwd, options));
|
|
211
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session Domain Types
|
|
3
|
+
*
|
|
4
|
+
* Shared type definitions for the session entry model.
|
|
5
|
+
* Extracted from the legacy SessionManager to allow its removal
|
|
6
|
+
* while preserving the type contracts used by extensions, compaction, and export.
|
|
7
|
+
*/
|
|
8
|
+
import type { AgentMessage } from "../agent/types.js";
|
|
9
|
+
import type { ImageContent, TextContent } from "@earendil-works/pi-ai/compat";
|
|
10
|
+
export interface SessionHeader {
|
|
11
|
+
type: "session";
|
|
12
|
+
version?: number;
|
|
13
|
+
id: string;
|
|
14
|
+
timestamp: string;
|
|
15
|
+
cwd: string;
|
|
16
|
+
parentSession?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface SessionEntryBase {
|
|
19
|
+
type: string;
|
|
20
|
+
id: string;
|
|
21
|
+
parentId: string | null;
|
|
22
|
+
timestamp: string;
|
|
23
|
+
}
|
|
24
|
+
export interface SessionMessageEntry extends SessionEntryBase {
|
|
25
|
+
type: "message";
|
|
26
|
+
message: AgentMessage;
|
|
27
|
+
}
|
|
28
|
+
export interface ThinkingLevelChangeEntry extends SessionEntryBase {
|
|
29
|
+
type: "thinking_level_change";
|
|
30
|
+
thinkingLevel: string;
|
|
31
|
+
}
|
|
32
|
+
export interface ModelChangeEntry extends SessionEntryBase {
|
|
33
|
+
type: "model_change";
|
|
34
|
+
provider: string;
|
|
35
|
+
modelId: string;
|
|
36
|
+
}
|
|
37
|
+
export interface CompactionEntry<T = unknown> extends SessionEntryBase {
|
|
38
|
+
type: "compaction";
|
|
39
|
+
summary: string;
|
|
40
|
+
firstKeptEntryId: string;
|
|
41
|
+
tokensBefore: number;
|
|
42
|
+
details?: T;
|
|
43
|
+
fromHook?: boolean;
|
|
44
|
+
}
|
|
45
|
+
export interface BranchSummaryEntry<T = unknown> extends SessionEntryBase {
|
|
46
|
+
type: "branch_summary";
|
|
47
|
+
fromId: string;
|
|
48
|
+
summary: string;
|
|
49
|
+
details?: T;
|
|
50
|
+
fromHook?: boolean;
|
|
51
|
+
}
|
|
52
|
+
export interface CustomEntry<T = unknown> extends SessionEntryBase {
|
|
53
|
+
type: "custom";
|
|
54
|
+
customType: string;
|
|
55
|
+
data?: T;
|
|
56
|
+
}
|
|
57
|
+
export interface LabelEntry extends SessionEntryBase {
|
|
58
|
+
type: "label";
|
|
59
|
+
targetId: string;
|
|
60
|
+
label: string | undefined;
|
|
61
|
+
}
|
|
62
|
+
export interface SessionInfoEntry extends SessionEntryBase {
|
|
63
|
+
type: "session_info";
|
|
64
|
+
name?: string;
|
|
65
|
+
}
|
|
66
|
+
export interface CustomMessageEntry<T = unknown> extends SessionEntryBase {
|
|
67
|
+
type: "custom_message";
|
|
68
|
+
customType: string;
|
|
69
|
+
content: string | (TextContent | ImageContent)[];
|
|
70
|
+
details?: T;
|
|
71
|
+
display: boolean;
|
|
72
|
+
}
|
|
73
|
+
export type SessionEntry = SessionMessageEntry | ThinkingLevelChangeEntry | ModelChangeEntry | CompactionEntry | BranchSummaryEntry | CustomEntry | CustomMessageEntry | LabelEntry | SessionInfoEntry;
|
|
74
|
+
export interface SessionTreeNode {
|
|
75
|
+
entry: SessionEntry;
|
|
76
|
+
children: SessionTreeNode[];
|
|
77
|
+
label?: string;
|
|
78
|
+
labelTimestamp?: string;
|
|
79
|
+
}
|
|
80
|
+
export interface SessionContext {
|
|
81
|
+
messages: AgentMessage[];
|
|
82
|
+
thinkingLevel: string;
|
|
83
|
+
model: {
|
|
84
|
+
provider: string;
|
|
85
|
+
modelId: string;
|
|
86
|
+
} | null;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Read-only interface for session data access.
|
|
90
|
+
* Implemented by EventStoreExtensionSessionManager and legacy SessionManager.
|
|
91
|
+
*/
|
|
92
|
+
export interface ReadonlySessionManager {
|
|
93
|
+
getCwd(): string;
|
|
94
|
+
getSessionDir(): string;
|
|
95
|
+
getSessionId(): string;
|
|
96
|
+
getSessionFile(): string | undefined;
|
|
97
|
+
getLeafId(): string | null;
|
|
98
|
+
getLeafEntry(): SessionEntry | undefined;
|
|
99
|
+
getEntry(entryId: string): SessionEntry | undefined;
|
|
100
|
+
getLabel(entryId: string): string | undefined;
|
|
101
|
+
getBranch(fromId?: string): SessionEntry[];
|
|
102
|
+
getHeader(): SessionHeader;
|
|
103
|
+
getEntries(): SessionEntry[];
|
|
104
|
+
getTree(): SessionTreeNode[];
|
|
105
|
+
getSessionName(): string | undefined;
|
|
106
|
+
}
|
|
107
|
+
export interface SessionInfo {
|
|
108
|
+
path: string;
|
|
109
|
+
id: string;
|
|
110
|
+
cwd: string;
|
|
111
|
+
name?: string;
|
|
112
|
+
parentSessionPath?: string;
|
|
113
|
+
created: Date;
|
|
114
|
+
modified: Date;
|
|
115
|
+
messageCount: number;
|
|
116
|
+
firstMessage: string;
|
|
117
|
+
allMessagesText: string;
|
|
118
|
+
}
|
|
119
|
+
export type SessionListProgress = (loaded: number, total: number) => void;
|
|
120
|
+
export interface NewSessionOptions {
|
|
121
|
+
id?: string;
|
|
122
|
+
parentSession?: string;
|
|
123
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export { getAgentDir, VERSION } from "./config.js";
|
|
2
|
+
export { SessionFacade, type SessionFacadeConfig, type SessionFacadeEventListener } from "./core/session-facade.js";
|
|
3
|
+
export { createSessionFacade, type CreateSessionFacadeOptions, type CreateSessionFacadeResult, } from "./core/session-facade-factory.js";
|
|
4
|
+
export { type ApiKeyCredential, type AuthCredential, AuthStorage, type AuthStorageBackend, FileAuthStorageBackend, InMemoryAuthStorageBackend, type OAuthCredential, } from "./core/auth-storage.js";
|
|
5
|
+
export { type BranchPreparation, type BranchSummaryResult, type CollectEntriesResult, type CompactionResult, type CutPointResult, type FileOperations, findCutPoint, findTurnStartIndex, type GenerateBranchSummaryOptions, generateBranchSummary, getLastAssistantUsage, prepareBranchEntries, serializeConversation, shouldCompact, } from "./core/compaction/index.js";
|
|
6
|
+
export { createEventBus, type EventBus, type EventBusController } from "./core/event-bus.js";
|
|
7
|
+
export type { AgentEndEvent, AgentStartEvent, AgentToolResult, AgentToolUpdateCallback, AppKeybinding, BashToolCallEvent, BeforeAgentStartEvent, BeforeAgentStartEventResult, BeforeProviderRequestEvent, BeforeProviderRequestEventResult, BuildSystemPromptOptions, CompactOptions, ContextEvent, ContextUsage, CustomToolCallEvent, EditToolCallEvent, ExecOptions, ExecResult, Extension, ExtensionActions, ExtensionAPI, ExtensionCommandContext, ExtensionCommandContextActions, ExtensionContext, ExtensionContextActions, ExtensionError, ExtensionEvent, ExtensionFactory, ExtensionFlag, ExtensionHandler, ExtensionRuntime, ExtensionShortcut, ExtensionUIContext, ExtensionUIDialogOptions, ExtensionWidgetOptions, FindToolCallEvent, GrepToolCallEvent, InputEvent, InputEventResult, InputSource, KeybindingsManager, LoadExtensionsResult, LsToolCallEvent, MessageRenderer, MessageRenderOptions, ProviderConfig, ProviderModelConfig, ReadToolCallEvent, RegisteredCommand, RegisteredTool, ResolvedCommand, SessionBeforeCompactEvent, SessionBeforeForkEvent, SessionBeforeSwitchEvent, SessionBeforeTreeEvent, SessionCompactEvent, SessionShutdownEvent, SessionStartEvent, SessionTreeEvent, SlashCommandInfo, SlashCommandSource, SourceInfo, TerminalInputHandler, ToolCallEvent, ToolCallEventResult, ToolDefinition, ToolExecutionMode, ToolInfo, ToolRenderResultOptions, ToolResultEvent, TurnEndEvent, TurnStartEvent, UserBashEvent, UserBashEventResult, WidgetPlacement, WorkingIndicatorOptions, WriteToolCallEvent, } from "./core/extensions/index.js";
|
|
8
|
+
export { createExtensionRuntime, defineTool, discoverAndLoadExtensions, EventStoreExtensionSessionManager, ExtensionRunner, isBashToolResult, isEditToolResult, isFindToolResult, isGrepToolResult, isLsToolResult, isReadToolResult, isToolCallEventType, isWriteToolResult, wrapRegisteredTool, wrapRegisteredTools, type EventStoreExtensionSessionManagerOptions, type ExtensionSessionManager, } from "./core/extensions/index.js";
|
|
9
|
+
export type { ReadonlyFooterDataProvider } from "./core/footer-data-provider.js";
|
|
10
|
+
export { convertToLlm } from "./core/messages.js";
|
|
11
|
+
export { ModelRegistry } from "./core/model-registry.js";
|
|
12
|
+
export type { PackageManager, PathMetadata, ProgressCallback, ProgressEvent, ResolvedPaths, ResolvedResource, } from "./core/package-manager.js";
|
|
13
|
+
export { DefaultPackageManager } from "./core/package-manager.js";
|
|
14
|
+
export type { ResourceCollision, ResourceDiagnostic, ResourceLoader } from "./core/resource-loader.js";
|
|
15
|
+
export { DefaultResourceLoader, loadProjectContextFiles } from "./core/resource-loader.js";
|
|
16
|
+
export { createBashTool, createCodingTools, createEditTool, createFindTool, createGrepTool, createLsTool, createReadOnlyTools, createReadTool, createWriteTool, type PromptTemplate, } from "./core/sdk.js";
|
|
17
|
+
export { type CompactionSettings, type ImageSettings, type PackageSource, type RetrySettings, SettingsManager, } from "./core/settings-manager.js";
|
|
18
|
+
export { formatSkillsForPrompt, type LoadSkillsFromDirOptions, type LoadSkillsResult, loadSkills, loadSkillsFromDir, type Skill, type SkillFrontmatter, } from "./core/skills.js";
|
|
19
|
+
export { createSyntheticSourceInfo } from "./core/source-info.js";
|
|
20
|
+
export { type BashOperations, type BashSpawnContext, type BashSpawnHook, type BashToolDetails, type BashToolInput, type BashToolOptions, createBashToolDefinition, createEditToolDefinition, createFindToolDefinition, createGrepToolDefinition, createLocalBashOperations, createLsToolDefinition, createReadToolDefinition, createWriteToolDefinition, DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, type EditOperations, type EditToolDetails, type EditToolInput, type EditToolOptions, type FindOperations, type FindToolDetails, type FindToolInput, type FindToolOptions, formatSize, type GrepOperations, type GrepToolDetails, type GrepToolInput, type GrepToolOptions, type LsOperations, type LsToolDetails, type LsToolInput, type LsToolOptions, type ReadOperations, type ReadToolDetails, type ReadToolInput, type ReadToolOptions, type ToolsOptions, type TruncationOptions, type TruncationResult, truncateHead, truncateLine, truncateTail, type WriteOperations, type WriteToolInput, type WriteToolOptions, withFileMutationQueue, } from "./core/tools/index.js";
|
|
21
|
+
export { type MainOptions, main } from "./main.js";
|
|
22
|
+
export { InteractiveMode, mapTypedEventToModeEvents, type InteractiveModeOptions, type ModeEvent, type ModelInfo, type PrintModeOptions, RpcClient, type RpcClientOptions, type RpcCommand, type RpcEventListener, type RpcResponse, type RpcSessionState, runPrintModeWithFacade, runRpcModeWithFacade, } from "./modes/index.js";
|
|
23
|
+
export { ArminComponent, AssistantMessageComponent, BashExecutionComponent, BorderedLoader, BranchSummaryMessageComponent, CompactionSummaryMessageComponent, CustomEditor, CustomMessageComponent, DynamicBorder, ExtensionEditorComponent, ExtensionInputComponent, ExtensionSelectorComponent, FooterComponent, keyHint, keyText, LoginDialogComponent, ModelSelectorComponent, OAuthSelectorComponent, type RenderDiffOptions, rawKeyHint, renderDiff, type SettingsCallbacks, type SettingsConfig, SettingsSelectorComponent, ShowImagesSelectorComponent, SkillInvocationMessageComponent, ThemeSelectorComponent, ThinkingSelectorComponent, ToolExecutionComponent, type ToolExecutionOptions, TreeSelectorComponent, truncateToVisualLines, UserMessageComponent, UserMessageSelectorComponent, type VisualTruncateResult, } from "./modes/interactive/components/index.js";
|
|
24
|
+
export { getLanguageFromPath, getMarkdownTheme, getSelectListTheme, getSettingsListTheme, highlightCode, initTheme, Theme, type ThemeColor, } from "./modes/interactive/theme/theme.js";
|
|
25
|
+
export { copyToClipboard } from "./utils/clipboard.js";
|
|
26
|
+
export { parseFrontmatter, stripFrontmatter } from "./utils/frontmatter.js";
|
|
27
|
+
export { getShellConfig } from "./utils/shell.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Core session management
|
|
2
|
+
// Config paths
|
|
3
|
+
export { getAgentDir, VERSION } from "./config.js";
|
|
4
|
+
export { SessionFacade } from "./core/session-facade.js";
|
|
5
|
+
export { createSessionFacade, } from "./core/session-facade-factory.js";
|
|
6
|
+
// Auth and model registry
|
|
7
|
+
export { AuthStorage, FileAuthStorageBackend, InMemoryAuthStorageBackend, } from "./core/auth-storage.js";
|
|
8
|
+
// Compaction
|
|
9
|
+
export { findCutPoint, findTurnStartIndex, generateBranchSummary, getLastAssistantUsage, prepareBranchEntries, serializeConversation, shouldCompact, } from "./core/compaction/index.js";
|
|
10
|
+
export { createEventBus } from "./core/event-bus.js";
|
|
11
|
+
export { createExtensionRuntime, defineTool, discoverAndLoadExtensions, EventStoreExtensionSessionManager, ExtensionRunner, isBashToolResult, isEditToolResult, isFindToolResult, isGrepToolResult, isLsToolResult, isReadToolResult, isToolCallEventType, isWriteToolResult, wrapRegisteredTool, wrapRegisteredTools, } from "./core/extensions/index.js";
|
|
12
|
+
export { convertToLlm } from "./core/messages.js";
|
|
13
|
+
export { ModelRegistry } from "./core/model-registry.js";
|
|
14
|
+
export { DefaultPackageManager } from "./core/package-manager.js";
|
|
15
|
+
export { DefaultResourceLoader, loadProjectContextFiles } from "./core/resource-loader.js";
|
|
16
|
+
// SDK for programmatic usage
|
|
17
|
+
export { createBashTool,
|
|
18
|
+
// Tool factories (for custom cwd)
|
|
19
|
+
createCodingTools, createEditTool, createFindTool, createGrepTool, createLsTool, createReadOnlyTools, createReadTool, createWriteTool, } from "./core/sdk.js";
|
|
20
|
+
export { SettingsManager, } from "./core/settings-manager.js";
|
|
21
|
+
// Skills
|
|
22
|
+
export { formatSkillsForPrompt, loadSkills, loadSkillsFromDir, } from "./core/skills.js";
|
|
23
|
+
export { createSyntheticSourceInfo } from "./core/source-info.js";
|
|
24
|
+
// Tools
|
|
25
|
+
export { createBashToolDefinition, createEditToolDefinition, createFindToolDefinition, createGrepToolDefinition, createLocalBashOperations, createLsToolDefinition, createReadToolDefinition, createWriteToolDefinition, DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, truncateHead, truncateLine, truncateTail, withFileMutationQueue, } from "./core/tools/index.js";
|
|
26
|
+
// Main entry point
|
|
27
|
+
export { main } from "./main.js";
|
|
28
|
+
// Run modes for programmatic SDK usage
|
|
29
|
+
export { InteractiveMode, mapTypedEventToModeEvents, RpcClient, runPrintModeWithFacade, runRpcModeWithFacade, } from "./modes/index.js";
|
|
30
|
+
// UI components for extensions
|
|
31
|
+
export { ArminComponent, AssistantMessageComponent, BashExecutionComponent, BorderedLoader, BranchSummaryMessageComponent, CompactionSummaryMessageComponent, CustomEditor, CustomMessageComponent, DynamicBorder, ExtensionEditorComponent, ExtensionInputComponent, ExtensionSelectorComponent, FooterComponent, keyHint, keyText, LoginDialogComponent, ModelSelectorComponent, OAuthSelectorComponent, rawKeyHint, renderDiff, SettingsSelectorComponent, ShowImagesSelectorComponent, SkillInvocationMessageComponent, ThemeSelectorComponent, ThinkingSelectorComponent, ToolExecutionComponent, TreeSelectorComponent, truncateToVisualLines, UserMessageComponent, UserMessageSelectorComponent, } from "./modes/interactive/components/index.js";
|
|
32
|
+
// Theme utilities for custom tools and extensions
|
|
33
|
+
export { getLanguageFromPath, getMarkdownTheme, getSelectListTheme, getSettingsListTheme, highlightCode, initTheme, Theme, } from "./modes/interactive/theme/theme.js";
|
|
34
|
+
// Clipboard utilities
|
|
35
|
+
export { copyToClipboard } from "./utils/clipboard.js";
|
|
36
|
+
export { parseFrontmatter, stripFrontmatter } from "./utils/frontmatter.js";
|
|
37
|
+
// Shell utilities
|
|
38
|
+
export { getShellConfig } from "./utils/shell.js";
|
package/dist/main.d.ts
CHANGED
|
@@ -1,2 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Main entry point for the coding agent CLI.
|
|
3
|
+
*
|
|
4
|
+
* This file handles CLI argument parsing and translates them into
|
|
5
|
+
* createSessionFacade() options. The SDK does the heavy lifting.
|
|
6
|
+
*/
|
|
7
|
+
import type { ExtensionFactory } from "./core/extensions/types.js";
|
|
8
|
+
export interface MainOptions {
|
|
9
|
+
extensionFactories?: ExtensionFactory[];
|
|
10
|
+
}
|
|
11
|
+
export declare function main(args: string[], options?: MainOptions): Promise<void>;
|