@lenylvt/pi-coding-agent 0.64.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3331 -0
- package/README.md +48 -0
- package/dist/bun/cli.d.ts +3 -0
- package/dist/bun/cli.d.ts.map +1 -0
- package/dist/bun/cli.js +5 -0
- package/dist/bun/cli.js.map +1 -0
- package/dist/cli/args.d.ts +49 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/args.js +292 -0
- package/dist/cli/args.js.map +1 -0
- package/dist/cli/config-selector.d.ts +14 -0
- package/dist/cli/config-selector.d.ts.map +1 -0
- package/dist/cli/config-selector.js +31 -0
- package/dist/cli/config-selector.js.map +1 -0
- package/dist/cli/file-processor.d.ts +15 -0
- package/dist/cli/file-processor.d.ts.map +1 -0
- package/dist/cli/file-processor.js +83 -0
- package/dist/cli/file-processor.js.map +1 -0
- package/dist/cli/initial-message.d.ts +18 -0
- package/dist/cli/initial-message.d.ts.map +1 -0
- package/dist/cli/initial-message.js +22 -0
- package/dist/cli/initial-message.js.map +1 -0
- package/dist/cli/list-models.d.ts +9 -0
- package/dist/cli/list-models.d.ts.map +1 -0
- package/dist/cli/list-models.js +92 -0
- package/dist/cli/list-models.js.map +1 -0
- package/dist/cli/session-picker.d.ts +9 -0
- package/dist/cli/session-picker.d.ts.map +1 -0
- package/dist/cli/session-picker.js +35 -0
- package/dist/cli/session-picker.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +14 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +69 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +178 -0
- package/dist/config.js.map +1 -0
- package/dist/core/agent-session.d.ts +622 -0
- package/dist/core/agent-session.d.ts.map +1 -0
- package/dist/core/agent-session.js +2688 -0
- package/dist/core/agent-session.js.map +1 -0
- package/dist/core/auth-storage.d.ts +132 -0
- package/dist/core/auth-storage.d.ts.map +1 -0
- package/dist/core/auth-storage.js +422 -0
- package/dist/core/auth-storage.js.map +1 -0
- package/dist/core/bash-executor.d.ts +46 -0
- package/dist/core/bash-executor.d.ts.map +1 -0
- package/dist/core/bash-executor.js +113 -0
- package/dist/core/bash-executor.js.map +1 -0
- package/dist/core/compaction/branch-summarization.d.ts +88 -0
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -0
- package/dist/core/compaction/branch-summarization.js +243 -0
- package/dist/core/compaction/branch-summarization.js.map +1 -0
- package/dist/core/compaction/compaction.d.ts +121 -0
- package/dist/core/compaction/compaction.d.ts.map +1 -0
- package/dist/core/compaction/compaction.js +613 -0
- package/dist/core/compaction/compaction.js.map +1 -0
- package/dist/core/compaction/index.d.ts +7 -0
- package/dist/core/compaction/index.d.ts.map +1 -0
- package/dist/core/compaction/index.js +7 -0
- package/dist/core/compaction/index.js.map +1 -0
- package/dist/core/compaction/utils.d.ts +38 -0
- package/dist/core/compaction/utils.d.ts.map +1 -0
- package/dist/core/compaction/utils.js +153 -0
- package/dist/core/compaction/utils.js.map +1 -0
- package/dist/core/defaults.d.ts +3 -0
- package/dist/core/defaults.d.ts.map +1 -0
- package/dist/core/defaults.js +2 -0
- package/dist/core/defaults.js.map +1 -0
- package/dist/core/diagnostics.d.ts +15 -0
- package/dist/core/diagnostics.d.ts.map +1 -0
- package/dist/core/diagnostics.js +2 -0
- package/dist/core/diagnostics.js.map +1 -0
- package/dist/core/event-bus.d.ts +9 -0
- package/dist/core/event-bus.d.ts.map +1 -0
- package/dist/core/event-bus.js +25 -0
- package/dist/core/event-bus.js.map +1 -0
- package/dist/core/exec.d.ts +29 -0
- package/dist/core/exec.d.ts.map +1 -0
- package/dist/core/exec.js +75 -0
- package/dist/core/exec.js.map +1 -0
- package/dist/core/export-html/ansi-to-html.d.ts +22 -0
- package/dist/core/export-html/ansi-to-html.d.ts.map +1 -0
- package/dist/core/export-html/ansi-to-html.js +249 -0
- package/dist/core/export-html/ansi-to-html.js.map +1 -0
- package/dist/core/export-html/index.d.ts +37 -0
- package/dist/core/export-html/index.d.ts.map +1 -0
- package/dist/core/export-html/index.js +224 -0
- package/dist/core/export-html/index.js.map +1 -0
- package/dist/core/export-html/template.css +1001 -0
- package/dist/core/export-html/template.html +55 -0
- package/dist/core/export-html/template.js +1690 -0
- package/dist/core/export-html/tool-renderer.d.ts +38 -0
- package/dist/core/export-html/tool-renderer.d.ts.map +1 -0
- package/dist/core/export-html/tool-renderer.js +95 -0
- package/dist/core/export-html/tool-renderer.js.map +1 -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.d.ts.map +1 -0
- package/dist/core/extensions/index.js +9 -0
- package/dist/core/extensions/index.js.map +1 -0
- package/dist/core/extensions/loader.d.ts +25 -0
- package/dist/core/extensions/loader.d.ts.map +1 -0
- package/dist/core/extensions/loader.js +436 -0
- package/dist/core/extensions/loader.js.map +1 -0
- package/dist/core/extensions/runner.d.ts +148 -0
- package/dist/core/extensions/runner.d.ts.map +1 -0
- package/dist/core/extensions/runner.js +700 -0
- package/dist/core/extensions/runner.js.map +1 -0
- package/dist/core/extensions/types.d.ts +1085 -0
- package/dist/core/extensions/types.d.ts.map +1 -0
- package/dist/core/extensions/types.js +35 -0
- package/dist/core/extensions/types.js.map +1 -0
- package/dist/core/extensions/wrapper.d.ts +20 -0
- package/dist/core/extensions/wrapper.d.ts.map +1 -0
- package/dist/core/extensions/wrapper.js +22 -0
- package/dist/core/extensions/wrapper.js.map +1 -0
- package/dist/core/footer-data-provider.d.ts +44 -0
- package/dist/core/footer-data-provider.d.ts.map +1 -0
- package/dist/core/footer-data-provider.js +252 -0
- package/dist/core/footer-data-provider.js.map +1 -0
- package/dist/core/index.d.ts +10 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +10 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/keybindings.d.ts +275 -0
- package/dist/core/keybindings.d.ts.map +1 -0
- package/dist/core/keybindings.js +241 -0
- package/dist/core/keybindings.js.map +1 -0
- package/dist/core/messages.d.ts +77 -0
- package/dist/core/messages.d.ts.map +1 -0
- package/dist/core/messages.js +123 -0
- package/dist/core/messages.js.map +1 -0
- package/dist/core/model-registry.d.ts +132 -0
- package/dist/core/model-registry.d.ts.map +1 -0
- package/dist/core/model-registry.js +565 -0
- package/dist/core/model-registry.js.map +1 -0
- package/dist/core/model-resolver.d.ts +110 -0
- package/dist/core/model-resolver.d.ts.map +1 -0
- package/dist/core/model-resolver.js +464 -0
- package/dist/core/model-resolver.js.map +1 -0
- package/dist/core/output-guard.d.ts +6 -0
- package/dist/core/output-guard.d.ts.map +1 -0
- package/dist/core/output-guard.js +59 -0
- package/dist/core/output-guard.js.map +1 -0
- package/dist/core/package-manager.d.ts +172 -0
- package/dist/core/package-manager.d.ts.map +1 -0
- package/dist/core/package-manager.js +1801 -0
- package/dist/core/package-manager.js.map +1 -0
- package/dist/core/prompt-templates.d.ts +51 -0
- package/dist/core/prompt-templates.d.ts.map +1 -0
- package/dist/core/prompt-templates.js +249 -0
- package/dist/core/prompt-templates.js.map +1 -0
- package/dist/core/resolve-config-value.d.ts +23 -0
- package/dist/core/resolve-config-value.d.ts.map +1 -0
- package/dist/core/resolve-config-value.js +126 -0
- package/dist/core/resolve-config-value.js.map +1 -0
- package/dist/core/resource-loader.d.ts +185 -0
- package/dist/core/resource-loader.d.ts.map +1 -0
- package/dist/core/resource-loader.js +698 -0
- package/dist/core/resource-loader.js.map +1 -0
- package/dist/core/sdk.d.ts +90 -0
- package/dist/core/sdk.d.ts.map +1 -0
- package/dist/core/sdk.js +233 -0
- package/dist/core/sdk.js.map +1 -0
- package/dist/core/self-update.d.ts +3 -0
- package/dist/core/self-update.d.ts.map +1 -0
- package/dist/core/self-update.js +46 -0
- package/dist/core/self-update.js.map +1 -0
- package/dist/core/session-manager.d.ts +329 -0
- package/dist/core/session-manager.d.ts.map +1 -0
- package/dist/core/session-manager.js +1097 -0
- package/dist/core/session-manager.js.map +1 -0
- package/dist/core/settings-manager.d.ts +237 -0
- package/dist/core/settings-manager.d.ts.map +1 -0
- package/dist/core/settings-manager.js +708 -0
- package/dist/core/settings-manager.js.map +1 -0
- package/dist/core/skills.d.ts +60 -0
- package/dist/core/skills.d.ts.map +1 -0
- package/dist/core/skills.js +409 -0
- package/dist/core/skills.js.map +1 -0
- package/dist/core/slash-commands.d.ts +14 -0
- package/dist/core/slash-commands.d.ts.map +1 -0
- package/dist/core/slash-commands.js +22 -0
- package/dist/core/slash-commands.js.map +1 -0
- package/dist/core/source-info.d.ts +18 -0
- package/dist/core/source-info.d.ts.map +1 -0
- package/dist/core/source-info.js +19 -0
- package/dist/core/source-info.js.map +1 -0
- package/dist/core/system-prompt.d.ts +28 -0
- package/dist/core/system-prompt.d.ts.map +1 -0
- package/dist/core/system-prompt.js +116 -0
- package/dist/core/system-prompt.js.map +1 -0
- package/dist/core/timings.d.ts +8 -0
- package/dist/core/timings.d.ts.map +1 -0
- package/dist/core/timings.js +31 -0
- package/dist/core/timings.js.map +1 -0
- package/dist/core/tools/bash.d.ts +73 -0
- package/dist/core/tools/bash.d.ts.map +1 -0
- package/dist/core/tools/bash.js +342 -0
- package/dist/core/tools/bash.js.map +1 -0
- package/dist/core/tools/edit-diff.d.ts +85 -0
- package/dist/core/tools/edit-diff.d.ts.map +1 -0
- package/dist/core/tools/edit-diff.js +337 -0
- package/dist/core/tools/edit-diff.js.map +1 -0
- package/dist/core/tools/edit.d.ts +53 -0
- package/dist/core/tools/edit.d.ts.map +1 -0
- package/dist/core/tools/edit.js +196 -0
- package/dist/core/tools/edit.js.map +1 -0
- package/dist/core/tools/file-mutation-queue.d.ts +6 -0
- package/dist/core/tools/file-mutation-queue.d.ts.map +1 -0
- package/dist/core/tools/file-mutation-queue.js +37 -0
- package/dist/core/tools/file-mutation-queue.js.map +1 -0
- package/dist/core/tools/find.d.ts +46 -0
- package/dist/core/tools/find.d.ts.map +1 -0
- package/dist/core/tools/find.js +258 -0
- package/dist/core/tools/find.js.map +1 -0
- package/dist/core/tools/grep.d.ts +56 -0
- package/dist/core/tools/grep.d.ts.map +1 -0
- package/dist/core/tools/grep.js +293 -0
- package/dist/core/tools/grep.js.map +1 -0
- package/dist/core/tools/index.d.ts +115 -0
- package/dist/core/tools/index.d.ts.map +1 -0
- package/dist/core/tools/index.js +86 -0
- package/dist/core/tools/index.js.map +1 -0
- package/dist/core/tools/ls.d.ts +46 -0
- package/dist/core/tools/ls.d.ts.map +1 -0
- package/dist/core/tools/ls.js +172 -0
- package/dist/core/tools/ls.js.map +1 -0
- package/dist/core/tools/path-utils.d.ts +8 -0
- package/dist/core/tools/path-utils.d.ts.map +1 -0
- package/dist/core/tools/path-utils.js +81 -0
- package/dist/core/tools/path-utils.js.map +1 -0
- package/dist/core/tools/read.d.ts +46 -0
- package/dist/core/tools/read.d.ts.map +1 -0
- package/dist/core/tools/read.js +225 -0
- package/dist/core/tools/read.js.map +1 -0
- package/dist/core/tools/render-utils.d.ts +21 -0
- package/dist/core/tools/render-utils.d.ts.map +1 -0
- package/dist/core/tools/render-utils.js +49 -0
- package/dist/core/tools/render-utils.js.map +1 -0
- package/dist/core/tools/tool-definition-wrapper.d.ts +14 -0
- package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -0
- package/dist/core/tools/tool-definition-wrapper.js +32 -0
- package/dist/core/tools/tool-definition-wrapper.js.map +1 -0
- package/dist/core/tools/truncate.d.ts +70 -0
- package/dist/core/tools/truncate.d.ts.map +1 -0
- package/dist/core/tools/truncate.js +205 -0
- package/dist/core/tools/truncate.js.map +1 -0
- package/dist/core/tools/write.d.ts +35 -0
- package/dist/core/tools/write.d.ts.map +1 -0
- package/dist/core/tools/write.js +216 -0
- package/dist/core/tools/write.js.map +1 -0
- package/dist/core/version-check.d.ts +2 -0
- package/dist/core/version-check.d.ts.map +1 -0
- package/dist/core/version-check.js +73 -0
- package/dist/core/version-check.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/dist/main.d.ts +8 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +811 -0
- package/dist/main.js.map +1 -0
- package/dist/migrations.d.ts +32 -0
- package/dist/migrations.d.ts.map +1 -0
- package/dist/migrations.js +258 -0
- package/dist/migrations.js.map +1 -0
- package/dist/modes/index.d.ts +9 -0
- package/dist/modes/index.d.ts.map +1 -0
- package/dist/modes/index.js +8 -0
- package/dist/modes/index.js.map +1 -0
- package/dist/modes/interactive/components/armin.d.ts +34 -0
- package/dist/modes/interactive/components/armin.d.ts.map +1 -0
- package/dist/modes/interactive/components/armin.js +333 -0
- package/dist/modes/interactive/components/armin.js.map +1 -0
- package/dist/modes/interactive/components/assistant-message.d.ts +18 -0
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/assistant-message.js +107 -0
- package/dist/modes/interactive/components/assistant-message.js.map +1 -0
- package/dist/modes/interactive/components/bash-execution.d.ts +34 -0
- package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -0
- package/dist/modes/interactive/components/bash-execution.js +175 -0
- package/dist/modes/interactive/components/bash-execution.js.map +1 -0
- package/dist/modes/interactive/components/bordered-loader.d.ts +16 -0
- package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -0
- package/dist/modes/interactive/components/bordered-loader.js +51 -0
- package/dist/modes/interactive/components/bordered-loader.js.map +1 -0
- package/dist/modes/interactive/components/branch-summary-message.d.ts +16 -0
- package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/branch-summary-message.js +44 -0
- package/dist/modes/interactive/components/branch-summary-message.js.map +1 -0
- package/dist/modes/interactive/components/compaction-summary-message.d.ts +16 -0
- package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/compaction-summary-message.js +45 -0
- package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -0
- package/dist/modes/interactive/components/config-selector.d.ts +71 -0
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/config-selector.js +479 -0
- package/dist/modes/interactive/components/config-selector.js.map +1 -0
- package/dist/modes/interactive/components/countdown-timer.d.ts +14 -0
- package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -0
- package/dist/modes/interactive/components/countdown-timer.js +33 -0
- package/dist/modes/interactive/components/countdown-timer.js.map +1 -0
- package/dist/modes/interactive/components/custom-editor.d.ts +21 -0
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -0
- package/dist/modes/interactive/components/custom-editor.js +70 -0
- package/dist/modes/interactive/components/custom-editor.js.map +1 -0
- package/dist/modes/interactive/components/custom-message.d.ts +20 -0
- package/dist/modes/interactive/components/custom-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/custom-message.js +79 -0
- package/dist/modes/interactive/components/custom-message.js.map +1 -0
- package/dist/modes/interactive/components/diff.d.ts +12 -0
- package/dist/modes/interactive/components/diff.d.ts.map +1 -0
- package/dist/modes/interactive/components/diff.js +133 -0
- package/dist/modes/interactive/components/diff.js.map +1 -0
- package/dist/modes/interactive/components/dynamic-border.d.ts +15 -0
- package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -0
- package/dist/modes/interactive/components/dynamic-border.js +21 -0
- package/dist/modes/interactive/components/dynamic-border.js.map +1 -0
- package/dist/modes/interactive/components/extension-editor.d.ts +20 -0
- package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -0
- package/dist/modes/interactive/components/extension-editor.js +111 -0
- package/dist/modes/interactive/components/extension-editor.js.map +1 -0
- package/dist/modes/interactive/components/extension-input.d.ts +23 -0
- package/dist/modes/interactive/components/extension-input.d.ts.map +1 -0
- package/dist/modes/interactive/components/extension-input.js +61 -0
- package/dist/modes/interactive/components/extension-input.js.map +1 -0
- package/dist/modes/interactive/components/extension-selector.d.ts +24 -0
- package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/extension-selector.js +78 -0
- package/dist/modes/interactive/components/extension-selector.js.map +1 -0
- package/dist/modes/interactive/components/footer.d.ts +26 -0
- package/dist/modes/interactive/components/footer.d.ts.map +1 -0
- package/dist/modes/interactive/components/footer.js +198 -0
- package/dist/modes/interactive/components/footer.js.map +1 -0
- package/dist/modes/interactive/components/index.d.ts +31 -0
- package/dist/modes/interactive/components/index.d.ts.map +1 -0
- package/dist/modes/interactive/components/index.js +32 -0
- package/dist/modes/interactive/components/index.js.map +1 -0
- package/dist/modes/interactive/components/keybinding-hints.d.ts +8 -0
- package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -0
- package/dist/modes/interactive/components/keybinding-hints.js +22 -0
- package/dist/modes/interactive/components/keybinding-hints.js.map +1 -0
- package/dist/modes/interactive/components/login-dialog.d.ts +42 -0
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -0
- package/dist/modes/interactive/components/login-dialog.js +145 -0
- package/dist/modes/interactive/components/login-dialog.js.map +1 -0
- package/dist/modes/interactive/components/model-selector.d.ts +47 -0
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/model-selector.js +275 -0
- package/dist/modes/interactive/components/model-selector.js.map +1 -0
- package/dist/modes/interactive/components/oauth-selector.d.ts +19 -0
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/oauth-selector.js +97 -0
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -0
- package/dist/modes/interactive/components/scoped-models-selector.d.ts +49 -0
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/scoped-models-selector.js +275 -0
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -0
- package/dist/modes/interactive/components/session-selector-search.d.ts +23 -0
- package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -0
- package/dist/modes/interactive/components/session-selector-search.js +155 -0
- package/dist/modes/interactive/components/session-selector-search.js.map +1 -0
- package/dist/modes/interactive/components/session-selector.d.ts +95 -0
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/session-selector.js +848 -0
- package/dist/modes/interactive/components/session-selector.js.map +1 -0
- package/dist/modes/interactive/components/settings-selector.d.ts +58 -0
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/settings-selector.js +301 -0
- package/dist/modes/interactive/components/settings-selector.js.map +1 -0
- package/dist/modes/interactive/components/show-images-selector.d.ts +10 -0
- package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/show-images-selector.js +39 -0
- package/dist/modes/interactive/components/show-images-selector.js.map +1 -0
- package/dist/modes/interactive/components/skill-invocation-message.d.ts +17 -0
- package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/skill-invocation-message.js +47 -0
- package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -0
- package/dist/modes/interactive/components/theme-selector.d.ts +11 -0
- package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/theme-selector.js +50 -0
- package/dist/modes/interactive/components/theme-selector.js.map +1 -0
- package/dist/modes/interactive/components/thinking-selector.d.ts +11 -0
- package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/thinking-selector.js +51 -0
- package/dist/modes/interactive/components/thinking-selector.js.map +1 -0
- package/dist/modes/interactive/components/tool-execution.d.ts +58 -0
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -0
- package/dist/modes/interactive/components/tool-execution.js +274 -0
- package/dist/modes/interactive/components/tool-execution.js.map +1 -0
- package/dist/modes/interactive/components/tree-selector.d.ts +87 -0
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/tree-selector.js +1051 -0
- package/dist/modes/interactive/components/tree-selector.js.map +1 -0
- package/dist/modes/interactive/components/user-message-selector.d.ts +30 -0
- package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/user-message-selector.js +113 -0
- package/dist/modes/interactive/components/user-message-selector.js.map +1 -0
- package/dist/modes/interactive/components/user-message.d.ts +9 -0
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/user-message.js +28 -0
- package/dist/modes/interactive/components/user-message.js.map +1 -0
- package/dist/modes/interactive/components/visual-truncate.d.ts +24 -0
- package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -0
- package/dist/modes/interactive/components/visual-truncate.js +33 -0
- package/dist/modes/interactive/components/visual-truncate.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts +311 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-mode.js +3798 -0
- package/dist/modes/interactive/interactive-mode.js.map +1 -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 +81 -0
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -0
- package/dist/modes/interactive/theme/theme.js +975 -0
- package/dist/modes/interactive/theme/theme.js.map +1 -0
- package/dist/modes/print-mode.d.ts +28 -0
- package/dist/modes/print-mode.d.ts.map +1 -0
- package/dist/modes/print-mode.js +107 -0
- package/dist/modes/print-mode.js.map +1 -0
- package/dist/modes/rpc/jsonl.d.ts +17 -0
- package/dist/modes/rpc/jsonl.d.ts.map +1 -0
- package/dist/modes/rpc/jsonl.js +49 -0
- package/dist/modes/rpc/jsonl.js.map +1 -0
- package/dist/modes/rpc/rpc-client.d.ts +217 -0
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-client.js +401 -0
- package/dist/modes/rpc/rpc-client.js.map +1 -0
- package/dist/modes/rpc/rpc-mode.d.ts +20 -0
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-mode.js +522 -0
- package/dist/modes/rpc/rpc-mode.js.map +1 -0
- package/dist/modes/rpc/rpc-types.d.ts +408 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-types.js +8 -0
- package/dist/modes/rpc/rpc-types.js.map +1 -0
- package/dist/utils/changelog.d.ts +21 -0
- package/dist/utils/changelog.d.ts.map +1 -0
- package/dist/utils/changelog.js +87 -0
- package/dist/utils/changelog.js.map +1 -0
- package/dist/utils/child-process.d.ts +11 -0
- package/dist/utils/child-process.d.ts.map +1 -0
- package/dist/utils/child-process.js +78 -0
- package/dist/utils/child-process.js.map +1 -0
- package/dist/utils/clipboard-image.d.ts +11 -0
- package/dist/utils/clipboard-image.d.ts.map +1 -0
- package/dist/utils/clipboard-image.js +245 -0
- package/dist/utils/clipboard-image.js.map +1 -0
- package/dist/utils/clipboard-native.d.ts +8 -0
- package/dist/utils/clipboard-native.d.ts.map +1 -0
- package/dist/utils/clipboard-native.js +14 -0
- package/dist/utils/clipboard-native.js.map +1 -0
- package/dist/utils/clipboard.d.ts +2 -0
- package/dist/utils/clipboard.d.ts.map +1 -0
- package/dist/utils/clipboard.js +78 -0
- package/dist/utils/clipboard.js.map +1 -0
- package/dist/utils/exif-orientation.d.ts +5 -0
- package/dist/utils/exif-orientation.d.ts.map +1 -0
- package/dist/utils/exif-orientation.js +158 -0
- package/dist/utils/exif-orientation.js.map +1 -0
- package/dist/utils/frontmatter.d.ts +8 -0
- package/dist/utils/frontmatter.d.ts.map +1 -0
- package/dist/utils/frontmatter.js +26 -0
- package/dist/utils/frontmatter.js.map +1 -0
- package/dist/utils/git.d.ts +26 -0
- package/dist/utils/git.d.ts.map +1 -0
- package/dist/utils/git.js +163 -0
- package/dist/utils/git.js.map +1 -0
- package/dist/utils/image-convert.d.ts +9 -0
- package/dist/utils/image-convert.d.ts.map +1 -0
- package/dist/utils/image-convert.js +39 -0
- package/dist/utils/image-convert.js.map +1 -0
- package/dist/utils/image-resize.d.ts +36 -0
- package/dist/utils/image-resize.d.ts.map +1 -0
- package/dist/utils/image-resize.js +137 -0
- package/dist/utils/image-resize.js.map +1 -0
- package/dist/utils/mime.d.ts +2 -0
- package/dist/utils/mime.d.ts.map +1 -0
- package/dist/utils/mime.js +26 -0
- package/dist/utils/mime.js.map +1 -0
- package/dist/utils/photon.d.ts +21 -0
- package/dist/utils/photon.d.ts.map +1 -0
- package/dist/utils/photon.js +121 -0
- package/dist/utils/photon.js.map +1 -0
- package/dist/utils/shell.d.ts +26 -0
- package/dist/utils/shell.d.ts.map +1 -0
- package/dist/utils/shell.js +186 -0
- package/dist/utils/shell.js.map +1 -0
- package/dist/utils/sleep.d.ts +5 -0
- package/dist/utils/sleep.d.ts.map +1 -0
- package/dist/utils/sleep.js +17 -0
- package/dist/utils/sleep.js.map +1 -0
- package/dist/utils/tools-manager.d.ts +3 -0
- package/dist/utils/tools-manager.d.ts.map +1 -0
- package/dist/utils/tools-manager.js +252 -0
- package/dist/utils/tools-manager.js.map +1 -0
- package/docs/compaction.md +394 -0
- package/docs/custom-provider.md +327 -0
- package/docs/extensions.md +2229 -0
- package/docs/images/doom-extension.png +0 -0
- package/docs/images/exy.png +0 -0
- package/docs/images/interactive-mode.png +0 -0
- package/docs/images/tree-view.png +0 -0
- package/docs/json.md +82 -0
- package/docs/keybindings.md +173 -0
- package/docs/models.md +197 -0
- package/docs/packages.md +218 -0
- package/docs/prompt-templates.md +67 -0
- package/docs/providers.md +98 -0
- package/docs/release.md +40 -0
- package/docs/rpc.md +1377 -0
- package/docs/sdk.md +971 -0
- package/docs/session.md +412 -0
- package/docs/settings.md +149 -0
- package/docs/shell-aliases.md +13 -0
- package/docs/skills.md +232 -0
- package/docs/terminal-setup.md +106 -0
- package/docs/termux.md +127 -0
- package/docs/themes.md +295 -0
- package/docs/tmux.md +61 -0
- package/docs/tree.md +228 -0
- package/docs/tui.md +887 -0
- package/docs/windows.md +17 -0
- package/examples/README.md +25 -0
- package/examples/extensions/README.md +204 -0
- package/examples/extensions/auto-commit-on-exit.ts +49 -0
- package/examples/extensions/bash-spawn-hook.ts +30 -0
- package/examples/extensions/bookmark.ts +50 -0
- package/examples/extensions/built-in-tool-renderer.ts +246 -0
- package/examples/extensions/claude-rules.ts +86 -0
- package/examples/extensions/commands.ts +72 -0
- package/examples/extensions/confirm-destructive.ts +59 -0
- package/examples/extensions/custom-compaction.ts +127 -0
- package/examples/extensions/custom-footer.ts +64 -0
- package/examples/extensions/custom-header.ts +73 -0
- package/examples/extensions/custom-provider-anthropic/index.ts +604 -0
- package/examples/extensions/custom-provider-anthropic/package.json +19 -0
- package/examples/extensions/custom-provider-gitlab-duo/index.ts +349 -0
- package/examples/extensions/custom-provider-gitlab-duo/package.json +16 -0
- package/examples/extensions/custom-provider-gitlab-duo/test.ts +82 -0
- package/examples/extensions/dirty-repo-guard.ts +56 -0
- package/examples/extensions/doom-overlay/README.md +46 -0
- package/examples/extensions/doom-overlay/doom/build/doom.js +21 -0
- package/examples/extensions/doom-overlay/doom/build/doom.wasm +0 -0
- package/examples/extensions/doom-overlay/doom/build.sh +152 -0
- package/examples/extensions/doom-overlay/doom/doomgeneric_pi.c +72 -0
- package/examples/extensions/doom-overlay/doom-component.ts +132 -0
- package/examples/extensions/doom-overlay/doom-engine.ts +173 -0
- package/examples/extensions/doom-overlay/doom-keys.ts +104 -0
- package/examples/extensions/doom-overlay/index.ts +74 -0
- package/examples/extensions/doom-overlay/wad-finder.ts +51 -0
- package/examples/extensions/dynamic-resources/SKILL.md +8 -0
- package/examples/extensions/dynamic-resources/dynamic.json +79 -0
- package/examples/extensions/dynamic-resources/dynamic.md +5 -0
- package/examples/extensions/dynamic-resources/index.ts +15 -0
- package/examples/extensions/dynamic-tools.ts +74 -0
- package/examples/extensions/event-bus.ts +43 -0
- package/examples/extensions/file-trigger.ts +41 -0
- package/examples/extensions/git-checkpoint.ts +53 -0
- package/examples/extensions/handoff.ts +153 -0
- package/examples/extensions/hello.ts +25 -0
- package/examples/extensions/hidden-thinking-label.ts +57 -0
- package/examples/extensions/inline-bash.ts +94 -0
- package/examples/extensions/input-transform.ts +43 -0
- package/examples/extensions/interactive-shell.ts +196 -0
- package/examples/extensions/mac-system-theme.ts +47 -0
- package/examples/extensions/message-renderer.ts +59 -0
- package/examples/extensions/minimal-mode.ts +426 -0
- package/examples/extensions/modal-editor.ts +85 -0
- package/examples/extensions/model-status.ts +31 -0
- package/examples/extensions/notify.ts +55 -0
- package/examples/extensions/overlay-qa-tests.ts +1348 -0
- package/examples/extensions/overlay-test.ts +150 -0
- package/examples/extensions/permission-gate.ts +34 -0
- package/examples/extensions/pirate.ts +47 -0
- package/examples/extensions/plan-mode/README.md +65 -0
- package/examples/extensions/plan-mode/index.ts +340 -0
- package/examples/extensions/plan-mode/utils.ts +166 -0
- package/examples/extensions/preset.ts +397 -0
- package/examples/extensions/protected-paths.ts +30 -0
- package/examples/extensions/provider-payload.ts +14 -0
- package/examples/extensions/qna.ts +122 -0
- package/examples/extensions/question.ts +264 -0
- package/examples/extensions/questionnaire.ts +427 -0
- package/examples/extensions/rainbow-editor.ts +88 -0
- package/examples/extensions/reload-runtime.ts +37 -0
- package/examples/extensions/rpc-demo.ts +124 -0
- package/examples/extensions/sandbox/index.ts +321 -0
- package/examples/extensions/sandbox/package.json +19 -0
- package/examples/extensions/send-user-message.ts +97 -0
- package/examples/extensions/session-name.ts +27 -0
- package/examples/extensions/shutdown-command.ts +63 -0
- package/examples/extensions/snake.ts +343 -0
- package/examples/extensions/space-invaders.ts +560 -0
- package/examples/extensions/ssh.ts +220 -0
- package/examples/extensions/status-line.ts +40 -0
- package/examples/extensions/subagent/README.md +172 -0
- package/examples/extensions/subagent/agents/planner.md +37 -0
- package/examples/extensions/subagent/agents/reviewer.md +35 -0
- package/examples/extensions/subagent/agents/scout.md +50 -0
- package/examples/extensions/subagent/agents/worker.md +24 -0
- package/examples/extensions/subagent/agents.ts +126 -0
- package/examples/extensions/subagent/index.ts +986 -0
- package/examples/extensions/subagent/prompts/implement-and-review.md +10 -0
- package/examples/extensions/subagent/prompts/implement.md +10 -0
- package/examples/extensions/subagent/prompts/scout-and-plan.md +9 -0
- package/examples/extensions/summarize.ts +206 -0
- package/examples/extensions/system-prompt-header.ts +17 -0
- package/examples/extensions/timed-confirm.ts +70 -0
- package/examples/extensions/titlebar-spinner.ts +58 -0
- package/examples/extensions/todo.ts +299 -0
- package/examples/extensions/tool-override.ts +144 -0
- package/examples/extensions/tools.ts +146 -0
- package/examples/extensions/trigger-compact.ts +50 -0
- package/examples/extensions/truncated-tool.ts +195 -0
- package/examples/extensions/widget-placement.ts +17 -0
- package/examples/extensions/with-deps/index.ts +32 -0
- package/examples/extensions/with-deps/package.json +22 -0
- package/examples/rpc-extension-ui.ts +632 -0
- package/examples/sdk/01-minimal.ts +22 -0
- package/examples/sdk/02-custom-model.ts +49 -0
- package/examples/sdk/03-custom-prompt.ts +55 -0
- package/examples/sdk/04-skills.ts +52 -0
- package/examples/sdk/05-tools.ts +56 -0
- package/examples/sdk/06-extensions.ts +88 -0
- package/examples/sdk/07-context-files.ts +40 -0
- package/examples/sdk/08-prompt-templates.ts +48 -0
- package/examples/sdk/09-api-keys-and-oauth.ts +48 -0
- package/examples/sdk/10-settings.ts +51 -0
- package/examples/sdk/11-sessions.ts +48 -0
- package/examples/sdk/12-full-control.ts +81 -0
- package/examples/sdk/README.md +144 -0
- package/package.json +95 -0
- package/src/bun/cli.ts +5 -0
- package/src/cli/args.ts +309 -0
- package/src/cli/config-selector.ts +52 -0
- package/src/cli/file-processor.ts +100 -0
- package/src/cli/initial-message.ts +43 -0
- package/src/cli/list-models.ts +104 -0
- package/src/cli/session-picker.ts +52 -0
- package/src/cli.ts +16 -0
- package/src/config.ts +214 -0
- package/src/core/agent-session.ts +3279 -0
- package/src/core/auth-storage.ts +488 -0
- package/src/core/bash-executor.ts +158 -0
- package/src/core/compaction/branch-summarization.ts +355 -0
- package/src/core/compaction/compaction.ts +823 -0
- package/src/core/compaction/index.ts +7 -0
- package/src/core/compaction/utils.ts +170 -0
- package/src/core/defaults.ts +3 -0
- package/src/core/diagnostics.ts +15 -0
- package/src/core/event-bus.ts +33 -0
- package/src/core/exec.ts +107 -0
- package/src/core/export-html/ansi-to-html.ts +258 -0
- package/src/core/export-html/index.ts +314 -0
- package/src/core/export-html/template.css +1001 -0
- package/src/core/export-html/template.html +55 -0
- package/src/core/export-html/template.js +1690 -0
- package/src/core/export-html/tool-renderer.ts +156 -0
- package/src/core/export-html/vendor/highlight.min.js +1213 -0
- package/src/core/export-html/vendor/marked.min.js +6 -0
- package/src/core/extensions/index.ts +168 -0
- package/src/core/extensions/loader.ts +557 -0
- package/src/core/extensions/runner.ts +915 -0
- package/src/core/extensions/types.ts +1461 -0
- package/src/core/extensions/wrapper.ts +27 -0
- package/src/core/footer-data-provider.ts +273 -0
- package/src/core/index.ts +61 -0
- package/src/core/keybindings.ts +302 -0
- package/src/core/messages.ts +195 -0
- package/src/core/model-registry.ts +766 -0
- package/src/core/model-resolver.ts +606 -0
- package/src/core/output-guard.ts +74 -0
- package/src/core/package-manager.ts +2222 -0
- package/src/core/prompt-templates.ts +294 -0
- package/src/core/resolve-config-value.ts +142 -0
- package/src/core/resource-loader.ts +886 -0
- package/src/core/sdk.ts +360 -0
- package/src/core/self-update.ts +57 -0
- package/src/core/session-manager.ts +1410 -0
- package/src/core/settings-manager.ts +973 -0
- package/src/core/skills.ts +508 -0
- package/src/core/slash-commands.ts +37 -0
- package/src/core/source-info.ts +40 -0
- package/src/core/system-prompt.ts +168 -0
- package/src/core/timings.ts +31 -0
- package/src/core/tools/bash.ts +431 -0
- package/src/core/tools/edit-diff.ts +445 -0
- package/src/core/tools/edit.ts +307 -0
- package/src/core/tools/file-mutation-queue.ts +39 -0
- package/src/core/tools/find.ts +314 -0
- package/src/core/tools/grep.ts +375 -0
- package/src/core/tools/index.ts +193 -0
- package/src/core/tools/ls.ts +233 -0
- package/src/core/tools/path-utils.ts +94 -0
- package/src/core/tools/read.ts +269 -0
- package/src/core/tools/render-utils.ts +64 -0
- package/src/core/tools/tool-definition-wrapper.ts +43 -0
- package/src/core/tools/truncate.ts +265 -0
- package/src/core/tools/write.ts +285 -0
- package/src/core/version-check.ts +85 -0
- package/src/index.ts +348 -0
- package/src/main.ts +958 -0
- package/src/migrations.ts +290 -0
- package/src/modes/index.ts +9 -0
- package/src/modes/interactive/components/armin.ts +382 -0
- package/src/modes/interactive/components/assistant-message.ts +130 -0
- package/src/modes/interactive/components/bash-execution.ts +218 -0
- package/src/modes/interactive/components/bordered-loader.ts +66 -0
- package/src/modes/interactive/components/branch-summary-message.ts +58 -0
- package/src/modes/interactive/components/compaction-summary-message.ts +59 -0
- package/src/modes/interactive/components/config-selector.ts +592 -0
- package/src/modes/interactive/components/countdown-timer.ts +38 -0
- package/src/modes/interactive/components/custom-editor.ts +80 -0
- package/src/modes/interactive/components/custom-message.ts +99 -0
- package/src/modes/interactive/components/diff.ts +147 -0
- package/src/modes/interactive/components/dynamic-border.ts +25 -0
- package/src/modes/interactive/components/extension-editor.ts +147 -0
- package/src/modes/interactive/components/extension-input.ts +87 -0
- package/src/modes/interactive/components/extension-selector.ts +107 -0
- package/src/modes/interactive/components/footer.ts +216 -0
- package/src/modes/interactive/components/index.ts +31 -0
- package/src/modes/interactive/components/keybinding-hints.ts +24 -0
- package/src/modes/interactive/components/login-dialog.ts +178 -0
- package/src/modes/interactive/components/model-selector.ts +328 -0
- package/src/modes/interactive/components/oauth-selector.ts +121 -0
- package/src/modes/interactive/components/scoped-models-selector.ts +346 -0
- package/src/modes/interactive/components/session-selector-search.ts +194 -0
- package/src/modes/interactive/components/session-selector.ts +1010 -0
- package/src/modes/interactive/components/settings-selector.ts +432 -0
- package/src/modes/interactive/components/show-images-selector.ts +50 -0
- package/src/modes/interactive/components/skill-invocation-message.ts +55 -0
- package/src/modes/interactive/components/theme-selector.ts +67 -0
- package/src/modes/interactive/components/thinking-selector.ts +74 -0
- package/src/modes/interactive/components/tool-execution.ts +328 -0
- package/src/modes/interactive/components/tree-selector.ts +1197 -0
- package/src/modes/interactive/components/user-message-selector.ts +143 -0
- package/src/modes/interactive/components/user-message.ts +33 -0
- package/src/modes/interactive/components/visual-truncate.ts +50 -0
- package/src/modes/interactive/interactive-mode.ts +4501 -0
- package/src/modes/interactive/theme/dark.json +85 -0
- package/src/modes/interactive/theme/light.json +84 -0
- package/src/modes/interactive/theme/theme-schema.json +335 -0
- package/src/modes/interactive/theme/theme.ts +1137 -0
- package/src/modes/print-mode.ts +131 -0
- package/src/modes/rpc/jsonl.ts +58 -0
- package/src/modes/rpc/rpc-client.ts +505 -0
- package/src/modes/rpc/rpc-mode.ts +654 -0
- package/src/modes/rpc/rpc-types.ts +262 -0
- package/src/utils/changelog.ts +99 -0
- package/src/utils/child-process.ts +86 -0
- package/src/utils/clipboard-image.ts +300 -0
- package/src/utils/clipboard-native.ts +22 -0
- package/src/utils/clipboard.ts +81 -0
- package/src/utils/exif-orientation.ts +183 -0
- package/src/utils/frontmatter.ts +39 -0
- package/src/utils/git.ts +192 -0
- package/src/utils/image-convert.ts +41 -0
- package/src/utils/image-resize.ts +176 -0
- package/src/utils/mime.ts +30 -0
- package/src/utils/photon.ts +139 -0
- package/src/utils/shell.ts +202 -0
- package/src/utils/sleep.ts +18 -0
- package/src/utils/tools-manager.ts +287 -0
package/src/utils/git.ts
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import hostedGitInfo from "hosted-git-info";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Parsed git URL information.
|
|
5
|
+
*/
|
|
6
|
+
export type GitSource = {
|
|
7
|
+
/** Always "git" for git sources */
|
|
8
|
+
type: "git";
|
|
9
|
+
/** Clone URL (always valid for git clone, without ref suffix) */
|
|
10
|
+
repo: string;
|
|
11
|
+
/** Git host domain (e.g., "github.com") */
|
|
12
|
+
host: string;
|
|
13
|
+
/** Repository path (e.g., "user/repo") */
|
|
14
|
+
path: string;
|
|
15
|
+
/** Git ref (branch, tag, commit) if specified */
|
|
16
|
+
ref?: string;
|
|
17
|
+
/** True if ref was specified (package won't be auto-updated) */
|
|
18
|
+
pinned: boolean;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
function splitRef(url: string): { repo: string; ref?: string } {
|
|
22
|
+
const scpLikeMatch = url.match(/^git@([^:]+):(.+)$/);
|
|
23
|
+
if (scpLikeMatch) {
|
|
24
|
+
const pathWithMaybeRef = scpLikeMatch[2] ?? "";
|
|
25
|
+
const refSeparator = pathWithMaybeRef.indexOf("@");
|
|
26
|
+
if (refSeparator < 0) return { repo: url };
|
|
27
|
+
const repoPath = pathWithMaybeRef.slice(0, refSeparator);
|
|
28
|
+
const ref = pathWithMaybeRef.slice(refSeparator + 1);
|
|
29
|
+
if (!repoPath || !ref) return { repo: url };
|
|
30
|
+
return {
|
|
31
|
+
repo: `git@${scpLikeMatch[1] ?? ""}:${repoPath}`,
|
|
32
|
+
ref,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (url.includes("://")) {
|
|
37
|
+
try {
|
|
38
|
+
const parsed = new URL(url);
|
|
39
|
+
const pathWithMaybeRef = parsed.pathname.replace(/^\/+/, "");
|
|
40
|
+
const refSeparator = pathWithMaybeRef.indexOf("@");
|
|
41
|
+
if (refSeparator < 0) return { repo: url };
|
|
42
|
+
const repoPath = pathWithMaybeRef.slice(0, refSeparator);
|
|
43
|
+
const ref = pathWithMaybeRef.slice(refSeparator + 1);
|
|
44
|
+
if (!repoPath || !ref) return { repo: url };
|
|
45
|
+
parsed.pathname = `/${repoPath}`;
|
|
46
|
+
return {
|
|
47
|
+
repo: parsed.toString().replace(/\/$/, ""),
|
|
48
|
+
ref,
|
|
49
|
+
};
|
|
50
|
+
} catch {
|
|
51
|
+
return { repo: url };
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const slashIndex = url.indexOf("/");
|
|
56
|
+
if (slashIndex < 0) {
|
|
57
|
+
return { repo: url };
|
|
58
|
+
}
|
|
59
|
+
const host = url.slice(0, slashIndex);
|
|
60
|
+
const pathWithMaybeRef = url.slice(slashIndex + 1);
|
|
61
|
+
const refSeparator = pathWithMaybeRef.indexOf("@");
|
|
62
|
+
if (refSeparator < 0) {
|
|
63
|
+
return { repo: url };
|
|
64
|
+
}
|
|
65
|
+
const repoPath = pathWithMaybeRef.slice(0, refSeparator);
|
|
66
|
+
const ref = pathWithMaybeRef.slice(refSeparator + 1);
|
|
67
|
+
if (!repoPath || !ref) {
|
|
68
|
+
return { repo: url };
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
repo: `${host}/${repoPath}`,
|
|
72
|
+
ref,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function parseGenericGitUrl(url: string): GitSource | null {
|
|
77
|
+
const { repo: repoWithoutRef, ref } = splitRef(url);
|
|
78
|
+
let repo = repoWithoutRef;
|
|
79
|
+
let host = "";
|
|
80
|
+
let path = "";
|
|
81
|
+
|
|
82
|
+
const scpLikeMatch = repoWithoutRef.match(/^git@([^:]+):(.+)$/);
|
|
83
|
+
if (scpLikeMatch) {
|
|
84
|
+
host = scpLikeMatch[1] ?? "";
|
|
85
|
+
path = scpLikeMatch[2] ?? "";
|
|
86
|
+
} else if (
|
|
87
|
+
repoWithoutRef.startsWith("https://") ||
|
|
88
|
+
repoWithoutRef.startsWith("http://") ||
|
|
89
|
+
repoWithoutRef.startsWith("ssh://") ||
|
|
90
|
+
repoWithoutRef.startsWith("git://")
|
|
91
|
+
) {
|
|
92
|
+
try {
|
|
93
|
+
const parsed = new URL(repoWithoutRef);
|
|
94
|
+
host = parsed.hostname;
|
|
95
|
+
path = parsed.pathname.replace(/^\/+/, "");
|
|
96
|
+
} catch {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
} else {
|
|
100
|
+
const slashIndex = repoWithoutRef.indexOf("/");
|
|
101
|
+
if (slashIndex < 0) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
host = repoWithoutRef.slice(0, slashIndex);
|
|
105
|
+
path = repoWithoutRef.slice(slashIndex + 1);
|
|
106
|
+
if (!host.includes(".") && host !== "localhost") {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
repo = `https://${repoWithoutRef}`;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const normalizedPath = path.replace(/\.git$/, "").replace(/^\/+/, "");
|
|
113
|
+
if (!host || !normalizedPath || normalizedPath.split("/").length < 2) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
type: "git",
|
|
119
|
+
repo,
|
|
120
|
+
host,
|
|
121
|
+
path: normalizedPath,
|
|
122
|
+
ref,
|
|
123
|
+
pinned: Boolean(ref),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Parse git source into a GitSource.
|
|
129
|
+
*
|
|
130
|
+
* Rules:
|
|
131
|
+
* - With git: prefix, accept all historical shorthand forms.
|
|
132
|
+
* - Without git: prefix, only accept explicit protocol URLs.
|
|
133
|
+
*/
|
|
134
|
+
export function parseGitUrl(source: string): GitSource | null {
|
|
135
|
+
const trimmed = source.trim();
|
|
136
|
+
const hasGitPrefix = trimmed.startsWith("git:");
|
|
137
|
+
const url = hasGitPrefix ? trimmed.slice(4).trim() : trimmed;
|
|
138
|
+
|
|
139
|
+
if (!hasGitPrefix && !/^(https?|ssh|git):\/\//i.test(url)) {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const split = splitRef(url);
|
|
144
|
+
|
|
145
|
+
const hostedCandidates = [split.ref ? `${split.repo}#${split.ref}` : undefined, url].filter(
|
|
146
|
+
(value): value is string => Boolean(value),
|
|
147
|
+
);
|
|
148
|
+
for (const candidate of hostedCandidates) {
|
|
149
|
+
const info = hostedGitInfo.fromUrl(candidate);
|
|
150
|
+
if (info) {
|
|
151
|
+
if (split.ref && info.project?.includes("@")) {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
const useHttpsPrefix =
|
|
155
|
+
!split.repo.startsWith("http://") &&
|
|
156
|
+
!split.repo.startsWith("https://") &&
|
|
157
|
+
!split.repo.startsWith("ssh://") &&
|
|
158
|
+
!split.repo.startsWith("git://") &&
|
|
159
|
+
!split.repo.startsWith("git@");
|
|
160
|
+
return {
|
|
161
|
+
type: "git",
|
|
162
|
+
repo: useHttpsPrefix ? `https://${split.repo}` : split.repo,
|
|
163
|
+
host: info.domain || "",
|
|
164
|
+
path: `${info.user}/${info.project}`.replace(/\.git$/, ""),
|
|
165
|
+
ref: info.committish || split.ref || undefined,
|
|
166
|
+
pinned: Boolean(info.committish || split.ref),
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const httpsCandidates = [split.ref ? `https://${split.repo}#${split.ref}` : undefined, `https://${url}`].filter(
|
|
172
|
+
(value): value is string => Boolean(value),
|
|
173
|
+
);
|
|
174
|
+
for (const candidate of httpsCandidates) {
|
|
175
|
+
const info = hostedGitInfo.fromUrl(candidate);
|
|
176
|
+
if (info) {
|
|
177
|
+
if (split.ref && info.project?.includes("@")) {
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
return {
|
|
181
|
+
type: "git",
|
|
182
|
+
repo: `https://${split.repo}`,
|
|
183
|
+
host: info.domain || "",
|
|
184
|
+
path: `${info.user}/${info.project}`.replace(/\.git$/, ""),
|
|
185
|
+
ref: info.committish || split.ref || undefined,
|
|
186
|
+
pinned: Boolean(info.committish || split.ref),
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return parseGenericGitUrl(url);
|
|
192
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { applyExifOrientation } from "./exif-orientation.js";
|
|
2
|
+
import { loadPhoton } from "./photon.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Convert image to PNG format for terminal display.
|
|
6
|
+
* Kitty graphics protocol requires PNG format (f=100).
|
|
7
|
+
*/
|
|
8
|
+
export async function convertToPng(
|
|
9
|
+
base64Data: string,
|
|
10
|
+
mimeType: string,
|
|
11
|
+
): Promise<{ data: string; mimeType: string } | null> {
|
|
12
|
+
// Already PNG, no conversion needed
|
|
13
|
+
if (mimeType === "image/png") {
|
|
14
|
+
return { data: base64Data, mimeType };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const photon = await loadPhoton();
|
|
18
|
+
if (!photon) {
|
|
19
|
+
// Photon not available, can't convert
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
const bytes = new Uint8Array(Buffer.from(base64Data, "base64"));
|
|
25
|
+
const rawImage = photon.PhotonImage.new_from_byteslice(bytes);
|
|
26
|
+
const image = applyExifOrientation(photon, rawImage, bytes);
|
|
27
|
+
if (image !== rawImage) rawImage.free();
|
|
28
|
+
try {
|
|
29
|
+
const pngBuffer = image.get_bytes();
|
|
30
|
+
return {
|
|
31
|
+
data: Buffer.from(pngBuffer).toString("base64"),
|
|
32
|
+
mimeType: "image/png",
|
|
33
|
+
};
|
|
34
|
+
} finally {
|
|
35
|
+
image.free();
|
|
36
|
+
}
|
|
37
|
+
} catch {
|
|
38
|
+
// Conversion failed
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import type { ImageContent } from "@lenylvt/pi-ai";
|
|
2
|
+
import { applyExifOrientation } from "./exif-orientation.js";
|
|
3
|
+
import { loadPhoton } from "./photon.js";
|
|
4
|
+
|
|
5
|
+
export interface ImageResizeOptions {
|
|
6
|
+
maxWidth?: number; // Default: 2000
|
|
7
|
+
maxHeight?: number; // Default: 2000
|
|
8
|
+
maxBytes?: number; // Default: 4.5MB of base64 payload (below Anthropic's 5MB limit)
|
|
9
|
+
jpegQuality?: number; // Default: 80
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ResizedImage {
|
|
13
|
+
data: string; // base64
|
|
14
|
+
mimeType: string;
|
|
15
|
+
originalWidth: number;
|
|
16
|
+
originalHeight: number;
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
wasResized: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// 4.5MB of base64 payload. Provides headroom below Anthropic's 5MB limit.
|
|
23
|
+
const DEFAULT_MAX_BYTES = 4.5 * 1024 * 1024;
|
|
24
|
+
|
|
25
|
+
const DEFAULT_OPTIONS: Required<ImageResizeOptions> = {
|
|
26
|
+
maxWidth: 2000,
|
|
27
|
+
maxHeight: 2000,
|
|
28
|
+
maxBytes: DEFAULT_MAX_BYTES,
|
|
29
|
+
jpegQuality: 80,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
interface EncodedCandidate {
|
|
33
|
+
data: string;
|
|
34
|
+
encodedSize: number;
|
|
35
|
+
mimeType: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function encodeCandidate(buffer: Uint8Array, mimeType: string): EncodedCandidate {
|
|
39
|
+
const data = Buffer.from(buffer).toString("base64");
|
|
40
|
+
return {
|
|
41
|
+
data,
|
|
42
|
+
encodedSize: Buffer.byteLength(data, "utf-8"),
|
|
43
|
+
mimeType,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Resize an image to fit within the specified max dimensions and encoded file size.
|
|
49
|
+
* Returns null if the image cannot be resized below maxBytes.
|
|
50
|
+
*
|
|
51
|
+
* Uses Photon (Rust/WASM) for image processing. If Photon is not available,
|
|
52
|
+
* returns null.
|
|
53
|
+
*
|
|
54
|
+
* Strategy for staying under maxBytes:
|
|
55
|
+
* 1. First resize to maxWidth/maxHeight
|
|
56
|
+
* 2. Try both PNG and JPEG formats, pick the smaller one
|
|
57
|
+
* 3. If still too large, try JPEG with decreasing quality
|
|
58
|
+
* 4. If still too large, progressively reduce dimensions until 1x1
|
|
59
|
+
*/
|
|
60
|
+
export async function resizeImage(img: ImageContent, options?: ImageResizeOptions): Promise<ResizedImage | null> {
|
|
61
|
+
const opts = { ...DEFAULT_OPTIONS, ...options };
|
|
62
|
+
const inputBuffer = Buffer.from(img.data, "base64");
|
|
63
|
+
const inputBase64Size = Buffer.byteLength(img.data, "utf-8");
|
|
64
|
+
|
|
65
|
+
const photon = await loadPhoton();
|
|
66
|
+
if (!photon) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
let image: ReturnType<typeof photon.PhotonImage.new_from_byteslice> | undefined;
|
|
71
|
+
try {
|
|
72
|
+
const inputBytes = new Uint8Array(inputBuffer);
|
|
73
|
+
const rawImage = photon.PhotonImage.new_from_byteslice(inputBytes);
|
|
74
|
+
image = applyExifOrientation(photon, rawImage, inputBytes);
|
|
75
|
+
if (image !== rawImage) rawImage.free();
|
|
76
|
+
|
|
77
|
+
const originalWidth = image.get_width();
|
|
78
|
+
const originalHeight = image.get_height();
|
|
79
|
+
const format = img.mimeType?.split("/")[1] ?? "png";
|
|
80
|
+
|
|
81
|
+
// Check if already within all limits (dimensions AND encoded size)
|
|
82
|
+
if (originalWidth <= opts.maxWidth && originalHeight <= opts.maxHeight && inputBase64Size < opts.maxBytes) {
|
|
83
|
+
return {
|
|
84
|
+
data: img.data,
|
|
85
|
+
mimeType: img.mimeType ?? `image/${format}`,
|
|
86
|
+
originalWidth,
|
|
87
|
+
originalHeight,
|
|
88
|
+
width: originalWidth,
|
|
89
|
+
height: originalHeight,
|
|
90
|
+
wasResized: false,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Calculate initial dimensions respecting max limits
|
|
95
|
+
let targetWidth = originalWidth;
|
|
96
|
+
let targetHeight = originalHeight;
|
|
97
|
+
|
|
98
|
+
if (targetWidth > opts.maxWidth) {
|
|
99
|
+
targetHeight = Math.round((targetHeight * opts.maxWidth) / targetWidth);
|
|
100
|
+
targetWidth = opts.maxWidth;
|
|
101
|
+
}
|
|
102
|
+
if (targetHeight > opts.maxHeight) {
|
|
103
|
+
targetWidth = Math.round((targetWidth * opts.maxHeight) / targetHeight);
|
|
104
|
+
targetHeight = opts.maxHeight;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function tryEncodings(width: number, height: number, jpegQualities: number[]): EncodedCandidate[] {
|
|
108
|
+
const resized = photon!.resize(image!, width, height, photon!.SamplingFilter.Lanczos3);
|
|
109
|
+
|
|
110
|
+
try {
|
|
111
|
+
const candidates: EncodedCandidate[] = [encodeCandidate(resized.get_bytes(), "image/png")];
|
|
112
|
+
for (const quality of jpegQualities) {
|
|
113
|
+
candidates.push(encodeCandidate(resized.get_bytes_jpeg(quality), "image/jpeg"));
|
|
114
|
+
}
|
|
115
|
+
return candidates;
|
|
116
|
+
} finally {
|
|
117
|
+
resized.free();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const qualitySteps = Array.from(new Set([opts.jpegQuality, 85, 70, 55, 40]));
|
|
122
|
+
let currentWidth = targetWidth;
|
|
123
|
+
let currentHeight = targetHeight;
|
|
124
|
+
|
|
125
|
+
while (true) {
|
|
126
|
+
const candidates = tryEncodings(currentWidth, currentHeight, qualitySteps);
|
|
127
|
+
for (const candidate of candidates) {
|
|
128
|
+
if (candidate.encodedSize < opts.maxBytes) {
|
|
129
|
+
return {
|
|
130
|
+
data: candidate.data,
|
|
131
|
+
mimeType: candidate.mimeType,
|
|
132
|
+
originalWidth,
|
|
133
|
+
originalHeight,
|
|
134
|
+
width: currentWidth,
|
|
135
|
+
height: currentHeight,
|
|
136
|
+
wasResized: true,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (currentWidth === 1 && currentHeight === 1) {
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const nextWidth = currentWidth === 1 ? 1 : Math.max(1, Math.floor(currentWidth * 0.75));
|
|
146
|
+
const nextHeight = currentHeight === 1 ? 1 : Math.max(1, Math.floor(currentHeight * 0.75));
|
|
147
|
+
if (nextWidth === currentWidth && nextHeight === currentHeight) {
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
currentWidth = nextWidth;
|
|
152
|
+
currentHeight = nextHeight;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return null;
|
|
156
|
+
} catch {
|
|
157
|
+
return null;
|
|
158
|
+
} finally {
|
|
159
|
+
if (image) {
|
|
160
|
+
image.free();
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Format a dimension note for resized images.
|
|
167
|
+
* This helps the model understand the coordinate mapping.
|
|
168
|
+
*/
|
|
169
|
+
export function formatDimensionNote(result: ResizedImage): string | undefined {
|
|
170
|
+
if (!result.wasResized) {
|
|
171
|
+
return undefined;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const scale = result.originalWidth / result.width;
|
|
175
|
+
return `[Image: original ${result.originalWidth}x${result.originalHeight}, displayed at ${result.width}x${result.height}. Multiply coordinates by ${scale.toFixed(2)} to map to original image.]`;
|
|
176
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { open } from "node:fs/promises";
|
|
2
|
+
import { fileTypeFromBuffer } from "file-type";
|
|
3
|
+
|
|
4
|
+
const IMAGE_MIME_TYPES = new Set(["image/jpeg", "image/png", "image/gif", "image/webp"]);
|
|
5
|
+
|
|
6
|
+
const FILE_TYPE_SNIFF_BYTES = 4100;
|
|
7
|
+
|
|
8
|
+
export async function detectSupportedImageMimeTypeFromFile(filePath: string): Promise<string | null> {
|
|
9
|
+
const fileHandle = await open(filePath, "r");
|
|
10
|
+
try {
|
|
11
|
+
const buffer = Buffer.alloc(FILE_TYPE_SNIFF_BYTES);
|
|
12
|
+
const { bytesRead } = await fileHandle.read(buffer, 0, FILE_TYPE_SNIFF_BYTES, 0);
|
|
13
|
+
if (bytesRead === 0) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const fileType = await fileTypeFromBuffer(buffer.subarray(0, bytesRead));
|
|
18
|
+
if (!fileType) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (!IMAGE_MIME_TYPES.has(fileType.mime)) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return fileType.mime;
|
|
27
|
+
} finally {
|
|
28
|
+
await fileHandle.close();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Photon image processing wrapper.
|
|
3
|
+
*
|
|
4
|
+
* This module provides a unified interface to @silvia-odwyer/photon-node that works in:
|
|
5
|
+
* 1. Node.js (development, bun run build)
|
|
6
|
+
* 2. Bun compiled binaries (standalone distribution)
|
|
7
|
+
*
|
|
8
|
+
* The challenge: photon-node's CJS entry uses fs.readFileSync(__dirname + '/photon_rs_bg.wasm')
|
|
9
|
+
* which bakes the build machine's absolute path into Bun compiled binaries.
|
|
10
|
+
*
|
|
11
|
+
* Solution:
|
|
12
|
+
* 1. Patch fs.readFileSync to redirect missing photon_rs_bg.wasm reads
|
|
13
|
+
* 2. Copy photon_rs_bg.wasm next to the executable in build:binary
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import type { PathOrFileDescriptor } from "fs";
|
|
17
|
+
import { createRequire } from "module";
|
|
18
|
+
import * as path from "path";
|
|
19
|
+
import { fileURLToPath } from "url";
|
|
20
|
+
|
|
21
|
+
const require = createRequire(import.meta.url);
|
|
22
|
+
const fs = require("fs") as typeof import("fs");
|
|
23
|
+
|
|
24
|
+
// Re-export types from the main package
|
|
25
|
+
export type { PhotonImage as PhotonImageType } from "@silvia-odwyer/photon-node";
|
|
26
|
+
|
|
27
|
+
type ReadFileSync = typeof fs.readFileSync;
|
|
28
|
+
|
|
29
|
+
const WASM_FILENAME = "photon_rs_bg.wasm";
|
|
30
|
+
|
|
31
|
+
// Lazy-loaded photon module
|
|
32
|
+
let photonModule: typeof import("@silvia-odwyer/photon-node") | null = null;
|
|
33
|
+
let loadPromise: Promise<typeof import("@silvia-odwyer/photon-node") | null> | null = null;
|
|
34
|
+
|
|
35
|
+
function pathOrNull(file: PathOrFileDescriptor): string | null {
|
|
36
|
+
if (typeof file === "string") {
|
|
37
|
+
return file;
|
|
38
|
+
}
|
|
39
|
+
if (file instanceof URL) {
|
|
40
|
+
return fileURLToPath(file);
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function getFallbackWasmPaths(): string[] {
|
|
46
|
+
const execDir = path.dirname(process.execPath);
|
|
47
|
+
return [
|
|
48
|
+
path.join(execDir, WASM_FILENAME),
|
|
49
|
+
path.join(execDir, "photon", WASM_FILENAME),
|
|
50
|
+
path.join(process.cwd(), WASM_FILENAME),
|
|
51
|
+
];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function patchPhotonWasmRead(): () => void {
|
|
55
|
+
const originalReadFileSync: ReadFileSync = fs.readFileSync.bind(fs);
|
|
56
|
+
const fallbackPaths = getFallbackWasmPaths();
|
|
57
|
+
const mutableFs = fs as { readFileSync: ReadFileSync };
|
|
58
|
+
|
|
59
|
+
const patchedReadFileSync: ReadFileSync = ((...args: Parameters<ReadFileSync>) => {
|
|
60
|
+
const [file, options] = args;
|
|
61
|
+
const resolvedPath = pathOrNull(file);
|
|
62
|
+
|
|
63
|
+
if (resolvedPath?.endsWith(WASM_FILENAME)) {
|
|
64
|
+
try {
|
|
65
|
+
return originalReadFileSync(...args);
|
|
66
|
+
} catch (error) {
|
|
67
|
+
const err = error as NodeJS.ErrnoException;
|
|
68
|
+
if (err?.code && err.code !== "ENOENT") {
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
for (const fallbackPath of fallbackPaths) {
|
|
73
|
+
if (!fs.existsSync(fallbackPath)) {
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (options === undefined) {
|
|
77
|
+
return originalReadFileSync(fallbackPath);
|
|
78
|
+
}
|
|
79
|
+
return originalReadFileSync(fallbackPath, options);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return originalReadFileSync(...args);
|
|
87
|
+
}) as ReadFileSync;
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
mutableFs.readFileSync = patchedReadFileSync;
|
|
91
|
+
} catch {
|
|
92
|
+
Object.defineProperty(fs, "readFileSync", {
|
|
93
|
+
value: patchedReadFileSync,
|
|
94
|
+
writable: true,
|
|
95
|
+
configurable: true,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return () => {
|
|
100
|
+
try {
|
|
101
|
+
mutableFs.readFileSync = originalReadFileSync;
|
|
102
|
+
} catch {
|
|
103
|
+
Object.defineProperty(fs, "readFileSync", {
|
|
104
|
+
value: originalReadFileSync,
|
|
105
|
+
writable: true,
|
|
106
|
+
configurable: true,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Load the photon module asynchronously.
|
|
114
|
+
* Returns cached module on subsequent calls.
|
|
115
|
+
*/
|
|
116
|
+
export async function loadPhoton(): Promise<typeof import("@silvia-odwyer/photon-node") | null> {
|
|
117
|
+
if (photonModule) {
|
|
118
|
+
return photonModule;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (loadPromise) {
|
|
122
|
+
return loadPromise;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
loadPromise = (async () => {
|
|
126
|
+
const restoreReadFileSync = patchPhotonWasmRead();
|
|
127
|
+
try {
|
|
128
|
+
photonModule = await import("@silvia-odwyer/photon-node");
|
|
129
|
+
return photonModule;
|
|
130
|
+
} catch {
|
|
131
|
+
photonModule = null;
|
|
132
|
+
return photonModule;
|
|
133
|
+
} finally {
|
|
134
|
+
restoreReadFileSync();
|
|
135
|
+
}
|
|
136
|
+
})();
|
|
137
|
+
|
|
138
|
+
return loadPromise;
|
|
139
|
+
}
|