@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,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process @file CLI arguments into text content and image attachments
|
|
3
|
+
*/
|
|
4
|
+
import { access, readFile, stat } from "node:fs/promises";
|
|
5
|
+
import chalk from "chalk";
|
|
6
|
+
import { resolve } from "path";
|
|
7
|
+
import { resolveReadPath } from "../core/tools/path-utils.js";
|
|
8
|
+
import { formatDimensionNote, resizeImage } from "../utils/image-resize.js";
|
|
9
|
+
import { detectSupportedImageMimeTypeFromFile } from "../utils/mime.js";
|
|
10
|
+
/** Process @file arguments into text content and image attachments */
|
|
11
|
+
export async function processFileArguments(fileArgs, options) {
|
|
12
|
+
const autoResizeImages = options?.autoResizeImages ?? true;
|
|
13
|
+
let text = "";
|
|
14
|
+
const images = [];
|
|
15
|
+
for (const fileArg of fileArgs) {
|
|
16
|
+
// Expand and resolve path (handles ~ expansion and macOS screenshot Unicode spaces)
|
|
17
|
+
const absolutePath = resolve(resolveReadPath(fileArg, process.cwd()));
|
|
18
|
+
// Check if file exists
|
|
19
|
+
try {
|
|
20
|
+
await access(absolutePath);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
console.error(chalk.red(`Error: File not found: ${absolutePath}`));
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
// Check if file is empty
|
|
27
|
+
const stats = await stat(absolutePath);
|
|
28
|
+
if (stats.size === 0) {
|
|
29
|
+
// Skip empty files
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const mimeType = await detectSupportedImageMimeTypeFromFile(absolutePath);
|
|
33
|
+
if (mimeType) {
|
|
34
|
+
// Handle image file
|
|
35
|
+
const content = await readFile(absolutePath);
|
|
36
|
+
const base64Content = content.toString("base64");
|
|
37
|
+
let attachment;
|
|
38
|
+
let dimensionNote;
|
|
39
|
+
if (autoResizeImages) {
|
|
40
|
+
const resized = await resizeImage({ type: "image", data: base64Content, mimeType });
|
|
41
|
+
if (!resized) {
|
|
42
|
+
text += `<file name="${absolutePath}">[Image omitted: could not be resized below the inline image size limit.]</file>\n`;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
dimensionNote = formatDimensionNote(resized);
|
|
46
|
+
attachment = {
|
|
47
|
+
type: "image",
|
|
48
|
+
mimeType: resized.mimeType,
|
|
49
|
+
data: resized.data,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
attachment = {
|
|
54
|
+
type: "image",
|
|
55
|
+
mimeType,
|
|
56
|
+
data: base64Content,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
images.push(attachment);
|
|
60
|
+
// Add text reference to image with optional dimension note
|
|
61
|
+
if (dimensionNote) {
|
|
62
|
+
text += `<file name="${absolutePath}">${dimensionNote}</file>\n`;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
text += `<file name="${absolutePath}"></file>\n`;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
// Handle text file
|
|
70
|
+
try {
|
|
71
|
+
const content = await readFile(absolutePath, "utf-8");
|
|
72
|
+
text += `<file name="${absolutePath}">\n${content}\n</file>\n`;
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
76
|
+
console.error(chalk.red(`Error: Could not read file ${absolutePath}: ${message}`));
|
|
77
|
+
process.exit(1);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return { text, images };
|
|
82
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ImageContent } from "@earendil-works/pi-ai/compat";
|
|
2
|
+
import type { Args } from "./args.js";
|
|
3
|
+
export interface InitialMessageInput {
|
|
4
|
+
parsed: Args;
|
|
5
|
+
fileText?: string;
|
|
6
|
+
fileImages?: ImageContent[];
|
|
7
|
+
stdinContent?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface InitialMessageResult {
|
|
10
|
+
initialMessage?: string;
|
|
11
|
+
initialImages?: ImageContent[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Combine stdin content, @file text, and the first CLI message into a single
|
|
15
|
+
* initial prompt for non-interactive mode.
|
|
16
|
+
*/
|
|
17
|
+
export declare function buildInitialMessage({ parsed, fileText, fileImages, stdinContent, }: InitialMessageInput): InitialMessageResult;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Combine stdin content, @file text, and the first CLI message into a single
|
|
3
|
+
* initial prompt for non-interactive mode.
|
|
4
|
+
*/
|
|
5
|
+
export function buildInitialMessage({ parsed, fileText, fileImages, stdinContent, }) {
|
|
6
|
+
const parts = [];
|
|
7
|
+
if (stdinContent !== undefined) {
|
|
8
|
+
parts.push(stdinContent);
|
|
9
|
+
}
|
|
10
|
+
if (fileText) {
|
|
11
|
+
parts.push(fileText);
|
|
12
|
+
}
|
|
13
|
+
if (parsed.messages.length > 0) {
|
|
14
|
+
parts.push(parsed.messages[0]);
|
|
15
|
+
parsed.messages.shift();
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
initialMessage: parts.length > 0 ? parts.join("") : undefined,
|
|
19
|
+
initialImages: fileImages && fileImages.length > 0 ? fileImages : undefined,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* List available models with optional fuzzy search
|
|
3
|
+
*/
|
|
4
|
+
import type { ModelRegistry } from "../core/model-registry.js";
|
|
5
|
+
/**
|
|
6
|
+
* List available models, optionally filtered by search pattern
|
|
7
|
+
*/
|
|
8
|
+
export declare function listModels(modelRegistry: ModelRegistry, searchPattern?: string): Promise<void>;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* List available models with optional fuzzy search
|
|
3
|
+
*/
|
|
4
|
+
import { fuzzyFilter } from "@earendil-works/pi-tui";
|
|
5
|
+
import chalk from "chalk";
|
|
6
|
+
/**
|
|
7
|
+
* Format a number as human-readable (e.g., 200000 -> "200K", 1000000 -> "1M")
|
|
8
|
+
*/
|
|
9
|
+
function formatTokenCount(count) {
|
|
10
|
+
if (count >= 1_000_000) {
|
|
11
|
+
const millions = count / 1_000_000;
|
|
12
|
+
return millions % 1 === 0 ? `${millions}M` : `${millions.toFixed(1)}M`;
|
|
13
|
+
}
|
|
14
|
+
if (count >= 1_000) {
|
|
15
|
+
const thousands = count / 1_000;
|
|
16
|
+
return thousands % 1 === 0 ? `${thousands}K` : `${thousands.toFixed(1)}K`;
|
|
17
|
+
}
|
|
18
|
+
return count.toString();
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* List available models, optionally filtered by search pattern
|
|
22
|
+
*/
|
|
23
|
+
export async function listModels(modelRegistry, searchPattern) {
|
|
24
|
+
const loadError = modelRegistry.getError();
|
|
25
|
+
if (loadError) {
|
|
26
|
+
console.error(chalk.yellow(`Warning: errors loading models.json:\n${loadError}`));
|
|
27
|
+
}
|
|
28
|
+
const models = modelRegistry.getAvailable();
|
|
29
|
+
if (models.length === 0) {
|
|
30
|
+
console.log("No models available. Set API keys in environment variables.");
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
// Apply fuzzy filter if search pattern provided
|
|
34
|
+
let filteredModels = models;
|
|
35
|
+
if (searchPattern) {
|
|
36
|
+
filteredModels = fuzzyFilter(models, searchPattern, (m) => `${m.provider} ${m.id}`);
|
|
37
|
+
}
|
|
38
|
+
if (filteredModels.length === 0) {
|
|
39
|
+
console.log(`No models matching "${searchPattern}"`);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
// Sort by provider, then by model id
|
|
43
|
+
filteredModels.sort((a, b) => {
|
|
44
|
+
const providerCmp = a.provider.localeCompare(b.provider);
|
|
45
|
+
if (providerCmp !== 0)
|
|
46
|
+
return providerCmp;
|
|
47
|
+
return a.id.localeCompare(b.id);
|
|
48
|
+
});
|
|
49
|
+
// Calculate column widths
|
|
50
|
+
const rows = filteredModels.map((m) => ({
|
|
51
|
+
provider: m.provider,
|
|
52
|
+
model: m.id,
|
|
53
|
+
context: formatTokenCount(m.contextWindow),
|
|
54
|
+
maxOut: formatTokenCount(m.maxTokens),
|
|
55
|
+
thinking: m.reasoning ? "yes" : "no",
|
|
56
|
+
images: m.input.includes("image") ? "yes" : "no",
|
|
57
|
+
}));
|
|
58
|
+
const headers = {
|
|
59
|
+
provider: "provider",
|
|
60
|
+
model: "model",
|
|
61
|
+
context: "context",
|
|
62
|
+
maxOut: "max-out",
|
|
63
|
+
thinking: "thinking",
|
|
64
|
+
images: "images",
|
|
65
|
+
};
|
|
66
|
+
const widths = {
|
|
67
|
+
provider: Math.max(headers.provider.length, ...rows.map((r) => r.provider.length)),
|
|
68
|
+
model: Math.max(headers.model.length, ...rows.map((r) => r.model.length)),
|
|
69
|
+
context: Math.max(headers.context.length, ...rows.map((r) => r.context.length)),
|
|
70
|
+
maxOut: Math.max(headers.maxOut.length, ...rows.map((r) => r.maxOut.length)),
|
|
71
|
+
thinking: Math.max(headers.thinking.length, ...rows.map((r) => r.thinking.length)),
|
|
72
|
+
images: Math.max(headers.images.length, ...rows.map((r) => r.images.length)),
|
|
73
|
+
};
|
|
74
|
+
// Print header
|
|
75
|
+
const headerLine = [
|
|
76
|
+
headers.provider.padEnd(widths.provider),
|
|
77
|
+
headers.model.padEnd(widths.model),
|
|
78
|
+
headers.context.padEnd(widths.context),
|
|
79
|
+
headers.maxOut.padEnd(widths.maxOut),
|
|
80
|
+
headers.thinking.padEnd(widths.thinking),
|
|
81
|
+
headers.images.padEnd(widths.images),
|
|
82
|
+
].join(" ");
|
|
83
|
+
console.log(headerLine);
|
|
84
|
+
// Print rows
|
|
85
|
+
for (const row of rows) {
|
|
86
|
+
const line = [
|
|
87
|
+
row.provider.padEnd(widths.provider),
|
|
88
|
+
row.model.padEnd(widths.model),
|
|
89
|
+
row.context.padEnd(widths.context),
|
|
90
|
+
row.maxOut.padEnd(widths.maxOut),
|
|
91
|
+
row.thinking.padEnd(widths.thinking),
|
|
92
|
+
row.images.padEnd(widths.images),
|
|
93
|
+
].join(" ");
|
|
94
|
+
console.log(line);
|
|
95
|
+
}
|
|
96
|
+
}
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* CLI entry point for the coding agent.
|
|
4
|
+
* Routes read/write/edit built-in commands to builtin-commands.ts.
|
|
5
|
+
* grep, find, ls are not built-in commands — they are passed to the system shell.
|
|
6
|
+
* and passes other commands to main.ts
|
|
7
|
+
*/
|
|
8
|
+
process.title = "pizza";
|
|
9
|
+
process.env.PIZZA_CODING_AGENT = "true";
|
|
10
|
+
process.emitWarning = (() => { });
|
|
11
|
+
import { writeFileSync } from "node:fs";
|
|
12
|
+
import { EnvHttpProxyAgent, setGlobalDispatcher } from "undici";
|
|
13
|
+
import { executeCompatCommand, COMPAT_COMMANDS } from "./core/tools/compat-commands.js";
|
|
14
|
+
import { executeBuiltinCommand, BUILTIN_COMMANDS } from "./core/tools/builtin-commands.js";
|
|
15
|
+
import { main } from "./main.js";
|
|
16
|
+
setGlobalDispatcher(new EnvHttpProxyAgent());
|
|
17
|
+
function writeCompatOutput(fd, text) {
|
|
18
|
+
if (!text)
|
|
19
|
+
return;
|
|
20
|
+
try {
|
|
21
|
+
writeFileSync(fd, text);
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
if (error.code !== "EPIPE")
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
// Check if this is a built-in command call
|
|
29
|
+
const args = process.argv.slice(2);
|
|
30
|
+
if (args[0] === "__compat" && args.length >= 2) {
|
|
31
|
+
const command = args[1];
|
|
32
|
+
if (!COMPAT_COMMANDS.includes(command)) {
|
|
33
|
+
console.error(`Unknown compat command: ${command}`);
|
|
34
|
+
console.error(`Available compat commands: ${COMPAT_COMMANDS.join(", ")}`);
|
|
35
|
+
process.exit(2);
|
|
36
|
+
}
|
|
37
|
+
const result = await executeCompatCommand(command, args.slice(2), { cwd: process.cwd() });
|
|
38
|
+
writeCompatOutput(1, result.stdout);
|
|
39
|
+
writeCompatOutput(2, result.stderr);
|
|
40
|
+
process.exitCode = result.exitCode;
|
|
41
|
+
}
|
|
42
|
+
else if (args[0] === "builtin" && args.length >= 2) {
|
|
43
|
+
const command = args[1];
|
|
44
|
+
if (!BUILTIN_COMMANDS.includes(command)) {
|
|
45
|
+
console.error(`Unknown builtin command: ${command}`);
|
|
46
|
+
console.error(`Available commands: ${BUILTIN_COMMANDS.join(", ")}`);
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
const commandArgs = args.slice(2);
|
|
50
|
+
const cwd = process.cwd();
|
|
51
|
+
executeBuiltinCommand(command, commandArgs, { cwd })
|
|
52
|
+
.then((result) => {
|
|
53
|
+
if (result.stdout) {
|
|
54
|
+
console.log(result.stdout);
|
|
55
|
+
}
|
|
56
|
+
if (result.stderr) {
|
|
57
|
+
console.error(result.stderr);
|
|
58
|
+
}
|
|
59
|
+
process.exit(result.exitCode);
|
|
60
|
+
})
|
|
61
|
+
.catch((error) => {
|
|
62
|
+
console.error(`Error executing builtin command: ${error.message}`);
|
|
63
|
+
process.exit(1);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
main(args);
|
|
68
|
+
}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detect if we're running as a Bun compiled binary.
|
|
3
|
+
* Bun binaries have import.meta.url containing "$bunfs", "~BUN", or "%7EBUN" (Bun's virtual filesystem path)
|
|
4
|
+
*/
|
|
5
|
+
export declare const isBunBinary: boolean;
|
|
6
|
+
/** Detect if Bun is the runtime (compiled binary or bun run) */
|
|
7
|
+
export declare const isBunRuntime: boolean;
|
|
8
|
+
export type InstallMethod = "bun-binary" | "npm" | "pnpm" | "yarn" | "bun" | "unknown";
|
|
9
|
+
export declare function detectInstallMethod(): InstallMethod;
|
|
10
|
+
export declare function getUpdateInstruction(packageName: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Get the base directory for resolving package-level assets (package.json, README.md, CHANGELOG.md).
|
|
13
|
+
* - For Bun binary: returns the directory containing the executable
|
|
14
|
+
* - For Node.js: walks up from __dirname to find the package root (directory with package.json)
|
|
15
|
+
* - For tsx (src/): returns the package root
|
|
16
|
+
*/
|
|
17
|
+
export declare function getPackageDir(): string;
|
|
18
|
+
/**
|
|
19
|
+
* Get path to built-in themes directory (shipped with package)
|
|
20
|
+
* - For Bun binary: theme/ next to executable
|
|
21
|
+
* - For Node.js (dist/): dist/modes/interactive/theme/
|
|
22
|
+
* - For tsx (src/): src/modes/interactive/theme/
|
|
23
|
+
*/
|
|
24
|
+
export declare function getThemesDir(): string;
|
|
25
|
+
/**
|
|
26
|
+
* Get path to HTML export template directory (shipped with package)
|
|
27
|
+
* - For Bun binary: export-html/ next to executable
|
|
28
|
+
* - For Node.js (dist/): dist/core/export-html/
|
|
29
|
+
* - For tsx (src/): src/core/export-html/
|
|
30
|
+
*/
|
|
31
|
+
export declare function getExportTemplateDir(): string;
|
|
32
|
+
/** Get path to package.json */
|
|
33
|
+
export declare function getPackageJsonPath(): string;
|
|
34
|
+
/** Get path to docs directory */
|
|
35
|
+
export declare function getDocsPath(): string;
|
|
36
|
+
/** Get path to CHANGELOG.md */
|
|
37
|
+
export declare function getChangelogPath(): string;
|
|
38
|
+
/**
|
|
39
|
+
* Get path to built-in interactive assets directory.
|
|
40
|
+
* - For Bun binary: assets/ next to executable
|
|
41
|
+
* - For Node.js (dist/): dist/modes/interactive/assets/
|
|
42
|
+
* - For tsx (src/): src/modes/interactive/assets/
|
|
43
|
+
*/
|
|
44
|
+
export declare function getInteractiveAssetsDir(): string;
|
|
45
|
+
/** Get path to a bundled interactive asset */
|
|
46
|
+
export declare function getBundledInteractiveAssetPath(name: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* Get path to managed binaries shipped with the package.
|
|
49
|
+
* - For Bun binary: vendor/bin/ next to executable
|
|
50
|
+
* - For Node.js (dist/): dist/vendor/bin/
|
|
51
|
+
* - For tsx (src/): dist/vendor/bin/ when release assets have been built
|
|
52
|
+
*/
|
|
53
|
+
export declare function getBundledBinDir(): string;
|
|
54
|
+
export declare const APP_NAME: string;
|
|
55
|
+
export declare const CONFIG_DIR_NAME: string;
|
|
56
|
+
export declare const VERSION: string;
|
|
57
|
+
export declare const ENV_AGENT_DIR: string;
|
|
58
|
+
/** Get the share viewer URL for a gist ID */
|
|
59
|
+
export declare function getShareViewerUrl(gistId: string): string;
|
|
60
|
+
/** Get the agent config directory (e.g., ~/.pizza/agent/) */
|
|
61
|
+
export declare function getAgentDir(): string;
|
|
62
|
+
/** Get path to user's custom themes directory */
|
|
63
|
+
export declare function getCustomThemesDir(): string;
|
|
64
|
+
/** Get path to models.json */
|
|
65
|
+
export declare function getModelsPath(): string;
|
|
66
|
+
/** Get path to auth.json */
|
|
67
|
+
export declare function getAuthPath(): string;
|
|
68
|
+
/** Get path to settings.json */
|
|
69
|
+
export declare function getSettingsPath(): string;
|
|
70
|
+
/** Get path to tools directory */
|
|
71
|
+
export declare function getToolsDir(): string;
|
|
72
|
+
/** Get path to managed binaries directory (fd, rg) */
|
|
73
|
+
export declare function getBinDir(): string;
|
|
74
|
+
/** Get path to prompt templates directory */
|
|
75
|
+
export declare function getPromptsDir(): string;
|
|
76
|
+
/** Get path to sessions directory */
|
|
77
|
+
export declare function getSessionsDir(): string;
|
|
78
|
+
/** Get path to debug log file */
|
|
79
|
+
export declare function getDebugLogPath(): string;
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "fs";
|
|
2
|
+
import { homedir } from "os";
|
|
3
|
+
import { dirname, join, resolve } from "path";
|
|
4
|
+
import { fileURLToPath } from "url";
|
|
5
|
+
// =============================================================================
|
|
6
|
+
// Package Detection
|
|
7
|
+
// =============================================================================
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
+
const __dirname = dirname(__filename);
|
|
10
|
+
/**
|
|
11
|
+
* Detect if we're running as a Bun compiled binary.
|
|
12
|
+
* Bun binaries have import.meta.url containing "$bunfs", "~BUN", or "%7EBUN" (Bun's virtual filesystem path)
|
|
13
|
+
*/
|
|
14
|
+
export const isBunBinary = import.meta.url.includes("$bunfs") || import.meta.url.includes("~BUN") || import.meta.url.includes("%7EBUN");
|
|
15
|
+
/** Detect if Bun is the runtime (compiled binary or bun run) */
|
|
16
|
+
export const isBunRuntime = !!process.versions.bun;
|
|
17
|
+
export function detectInstallMethod() {
|
|
18
|
+
if (isBunBinary) {
|
|
19
|
+
return "bun-binary";
|
|
20
|
+
}
|
|
21
|
+
const resolvedPath = `${__dirname}\0${process.execPath || ""}`.toLowerCase().replace(/\\/g, "/");
|
|
22
|
+
if (resolvedPath.includes("/pnpm/") || resolvedPath.includes("/.pnpm/")) {
|
|
23
|
+
return "pnpm";
|
|
24
|
+
}
|
|
25
|
+
if (resolvedPath.includes("/yarn/") || resolvedPath.includes("/.yarn/")) {
|
|
26
|
+
return "yarn";
|
|
27
|
+
}
|
|
28
|
+
if (isBunRuntime) {
|
|
29
|
+
return "bun";
|
|
30
|
+
}
|
|
31
|
+
if (resolvedPath.includes("/npm/") || resolvedPath.includes("/node_modules/")) {
|
|
32
|
+
return "npm";
|
|
33
|
+
}
|
|
34
|
+
return "unknown";
|
|
35
|
+
}
|
|
36
|
+
export function getUpdateInstruction(packageName) {
|
|
37
|
+
const method = detectInstallMethod();
|
|
38
|
+
switch (method) {
|
|
39
|
+
case "bun-binary":
|
|
40
|
+
return "Download the latest Pizza binary from the project releases page";
|
|
41
|
+
case "pnpm":
|
|
42
|
+
return `Run: pnpm install -g ${packageName}`;
|
|
43
|
+
case "yarn":
|
|
44
|
+
return `Run: yarn global add ${packageName}`;
|
|
45
|
+
case "bun":
|
|
46
|
+
return `Run: bun install -g ${packageName}`;
|
|
47
|
+
case "npm":
|
|
48
|
+
return `Run: npm install -g ${packageName}`;
|
|
49
|
+
default:
|
|
50
|
+
return `Run: npm install -g ${packageName}`;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// =============================================================================
|
|
54
|
+
// Package Asset Paths (shipped with executable)
|
|
55
|
+
// =============================================================================
|
|
56
|
+
/**
|
|
57
|
+
* Get the base directory for resolving package-level assets (package.json, README.md, CHANGELOG.md).
|
|
58
|
+
* - For Bun binary: returns the directory containing the executable
|
|
59
|
+
* - For Node.js: walks up from __dirname to find the package root (directory with package.json)
|
|
60
|
+
* - For tsx (src/): returns the package root
|
|
61
|
+
*/
|
|
62
|
+
export function getPackageDir() {
|
|
63
|
+
// Allow override via environment variable (useful for Nix/Guix where store paths tokenize poorly)
|
|
64
|
+
const envDir = process.env.PIZZA_PACKAGE_DIR;
|
|
65
|
+
if (envDir) {
|
|
66
|
+
if (envDir === "~")
|
|
67
|
+
return homedir();
|
|
68
|
+
if (envDir.startsWith("~/"))
|
|
69
|
+
return homedir() + envDir.slice(1);
|
|
70
|
+
return envDir;
|
|
71
|
+
}
|
|
72
|
+
if (isBunBinary) {
|
|
73
|
+
// Bun binary: process.execPath points to the compiled executable
|
|
74
|
+
return dirname(process.execPath);
|
|
75
|
+
}
|
|
76
|
+
// Node.js: walk up from __dirname until we find package.json
|
|
77
|
+
let dir = __dirname;
|
|
78
|
+
if (dir.endsWith("/dist") || dir.endsWith("\\dist")) {
|
|
79
|
+
dir = dirname(dir);
|
|
80
|
+
}
|
|
81
|
+
while (dir !== dirname(dir)) {
|
|
82
|
+
if (existsSync(join(dir, "package.json"))) {
|
|
83
|
+
return dir;
|
|
84
|
+
}
|
|
85
|
+
dir = dirname(dir);
|
|
86
|
+
}
|
|
87
|
+
// Fallback (shouldn't happen)
|
|
88
|
+
return __dirname;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Get path to built-in themes directory (shipped with package)
|
|
92
|
+
* - For Bun binary: theme/ next to executable
|
|
93
|
+
* - For Node.js (dist/): dist/modes/interactive/theme/
|
|
94
|
+
* - For tsx (src/): src/modes/interactive/theme/
|
|
95
|
+
*/
|
|
96
|
+
export function getThemesDir() {
|
|
97
|
+
if (isBunBinary) {
|
|
98
|
+
return join(getPackageDir(), "theme");
|
|
99
|
+
}
|
|
100
|
+
// __dirname is always dist/ or src/ — assets live at the same relative path from either
|
|
101
|
+
return join(__dirname, "modes", "interactive", "theme");
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Get path to HTML export template directory (shipped with package)
|
|
105
|
+
* - For Bun binary: export-html/ next to executable
|
|
106
|
+
* - For Node.js (dist/): dist/core/export-html/
|
|
107
|
+
* - For tsx (src/): src/core/export-html/
|
|
108
|
+
*/
|
|
109
|
+
export function getExportTemplateDir() {
|
|
110
|
+
if (isBunBinary) {
|
|
111
|
+
return join(getPackageDir(), "export-html");
|
|
112
|
+
}
|
|
113
|
+
// __dirname is always dist/ or src/ — assets live at the same relative path from either
|
|
114
|
+
return join(__dirname, "core", "export-html");
|
|
115
|
+
}
|
|
116
|
+
/** Get path to package.json */
|
|
117
|
+
export function getPackageJsonPath() {
|
|
118
|
+
return join(getPackageDir(), "package.json");
|
|
119
|
+
}
|
|
120
|
+
/** Get path to docs directory */
|
|
121
|
+
export function getDocsPath() {
|
|
122
|
+
return resolve(join(getPackageDir(), "docs"));
|
|
123
|
+
}
|
|
124
|
+
/** Get path to CHANGELOG.md */
|
|
125
|
+
export function getChangelogPath() {
|
|
126
|
+
return resolve(join(getPackageDir(), "CHANGELOG.md"));
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Get path to built-in interactive assets directory.
|
|
130
|
+
* - For Bun binary: assets/ next to executable
|
|
131
|
+
* - For Node.js (dist/): dist/modes/interactive/assets/
|
|
132
|
+
* - For tsx (src/): src/modes/interactive/assets/
|
|
133
|
+
*/
|
|
134
|
+
export function getInteractiveAssetsDir() {
|
|
135
|
+
if (isBunBinary) {
|
|
136
|
+
return join(getPackageDir(), "assets");
|
|
137
|
+
}
|
|
138
|
+
// __dirname is always dist/ or src/ — assets live at the same relative path from either
|
|
139
|
+
return join(__dirname, "modes", "interactive", "assets");
|
|
140
|
+
}
|
|
141
|
+
/** Get path to a bundled interactive asset */
|
|
142
|
+
export function getBundledInteractiveAssetPath(name) {
|
|
143
|
+
return join(getInteractiveAssetsDir(), name);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Get path to managed binaries shipped with the package.
|
|
147
|
+
* - For Bun binary: vendor/bin/ next to executable
|
|
148
|
+
* - For Node.js (dist/): dist/vendor/bin/
|
|
149
|
+
* - For tsx (src/): dist/vendor/bin/ when release assets have been built
|
|
150
|
+
*/
|
|
151
|
+
export function getBundledBinDir() {
|
|
152
|
+
if (isBunBinary) {
|
|
153
|
+
return join(getPackageDir(), "vendor", "bin");
|
|
154
|
+
}
|
|
155
|
+
return join(getPackageDir(), "dist", "vendor", "bin");
|
|
156
|
+
}
|
|
157
|
+
// =============================================================================
|
|
158
|
+
// App Config (from package.json pizzaConfig)
|
|
159
|
+
// =============================================================================
|
|
160
|
+
const pkg = JSON.parse(readFileSync(getPackageJsonPath(), "utf-8"));
|
|
161
|
+
const appConfig = pkg.pizzaConfig ?? {};
|
|
162
|
+
export const APP_NAME = appConfig.name || "pizza";
|
|
163
|
+
export const CONFIG_DIR_NAME = appConfig.configDir || ".pizza";
|
|
164
|
+
export const VERSION = pkg.version;
|
|
165
|
+
export const ENV_AGENT_DIR = `${APP_NAME.toUpperCase()}_CODING_AGENT_DIR`;
|
|
166
|
+
const DEFAULT_SHARE_VIEWER_URL = "https://pizza.dev/session/";
|
|
167
|
+
/** Get the share viewer URL for a gist ID */
|
|
168
|
+
export function getShareViewerUrl(gistId) {
|
|
169
|
+
const baseUrl = process.env.PIZZA_SHARE_VIEWER_URL || DEFAULT_SHARE_VIEWER_URL;
|
|
170
|
+
return `${baseUrl}#${gistId}`;
|
|
171
|
+
}
|
|
172
|
+
// =============================================================================
|
|
173
|
+
// User Config Paths (~/.pizza/agent/*)
|
|
174
|
+
// =============================================================================
|
|
175
|
+
/** Get the agent config directory (e.g., ~/.pizza/agent/) */
|
|
176
|
+
export function getAgentDir() {
|
|
177
|
+
const envDir = process.env[ENV_AGENT_DIR];
|
|
178
|
+
if (envDir) {
|
|
179
|
+
// Expand tilde to home directory
|
|
180
|
+
if (envDir === "~")
|
|
181
|
+
return homedir();
|
|
182
|
+
if (envDir.startsWith("~/"))
|
|
183
|
+
return homedir() + envDir.slice(1);
|
|
184
|
+
return envDir;
|
|
185
|
+
}
|
|
186
|
+
return join(homedir(), CONFIG_DIR_NAME, "agent");
|
|
187
|
+
}
|
|
188
|
+
/** Get path to user's custom themes directory */
|
|
189
|
+
export function getCustomThemesDir() {
|
|
190
|
+
return join(getAgentDir(), "themes");
|
|
191
|
+
}
|
|
192
|
+
/** Get path to models.json */
|
|
193
|
+
export function getModelsPath() {
|
|
194
|
+
return join(getAgentDir(), "models.json");
|
|
195
|
+
}
|
|
196
|
+
/** Get path to auth.json */
|
|
197
|
+
export function getAuthPath() {
|
|
198
|
+
return join(getAgentDir(), "auth.json");
|
|
199
|
+
}
|
|
200
|
+
/** Get path to settings.json */
|
|
201
|
+
export function getSettingsPath() {
|
|
202
|
+
return join(getAgentDir(), "settings.json");
|
|
203
|
+
}
|
|
204
|
+
/** Get path to tools directory */
|
|
205
|
+
export function getToolsDir() {
|
|
206
|
+
return join(getAgentDir(), "tools");
|
|
207
|
+
}
|
|
208
|
+
/** Get path to managed binaries directory (fd, rg) */
|
|
209
|
+
export function getBinDir() {
|
|
210
|
+
return join(getAgentDir(), "bin");
|
|
211
|
+
}
|
|
212
|
+
/** Get path to prompt templates directory */
|
|
213
|
+
export function getPromptsDir() {
|
|
214
|
+
return join(getAgentDir(), "prompts");
|
|
215
|
+
}
|
|
216
|
+
/** Get path to sessions directory */
|
|
217
|
+
export function getSessionsDir() {
|
|
218
|
+
return join(getAgentDir(), "sessions");
|
|
219
|
+
}
|
|
220
|
+
/** Get path to debug log file */
|
|
221
|
+
export function getDebugLogPath() {
|
|
222
|
+
return join(getAgentDir(), `${APP_NAME}-debug.log`);
|
|
223
|
+
}
|