leaf-coding-agent 1.0.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/dist/cli/args.d.ts +55 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/args.js +356 -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 +82 -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 +98 -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 +18 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +92 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +428 -0
- package/dist/config.js.map +1 -0
- package/dist/core/agent-session-runtime.d.ts +117 -0
- package/dist/core/agent-session-runtime.d.ts.map +1 -0
- package/dist/core/agent-session-runtime.js +300 -0
- package/dist/core/agent-session-runtime.js.map +1 -0
- package/dist/core/agent-session-services.d.ts +87 -0
- package/dist/core/agent-session-services.d.ts.map +1 -0
- package/dist/core/agent-session-services.js +119 -0
- package/dist/core/agent-session-services.js.map +1 -0
- package/dist/core/agent-session.d.ts +602 -0
- package/dist/core/agent-session.d.ts.map +1 -0
- package/dist/core/agent-session.js +2523 -0
- package/dist/core/agent-session.js.map +1 -0
- package/dist/core/auth-guidance.d.ts +5 -0
- package/dist/core/auth-guidance.d.ts.map +1 -0
- package/dist/core/auth-guidance.js +21 -0
- package/dist/core/auth-guidance.js.map +1 -0
- package/dist/core/auth-storage.d.ts +141 -0
- package/dist/core/auth-storage.d.ts.map +1 -0
- package/dist/core/auth-storage.js +442 -0
- package/dist/core/auth-storage.js.map +1 -0
- package/dist/core/bash-executor.d.ts +32 -0
- package/dist/core/bash-executor.d.ts.map +1 -0
- package/dist/core/bash-executor.js +111 -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 +619 -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 +226 -0
- package/dist/core/export-html/index.js.map +1 -0
- package/dist/core/export-html/template.css +1066 -0
- package/dist/core/export-html/template.html +55 -0
- package/dist/core/export-html/template.js +1851 -0
- package/dist/core/export-html/tool-renderer.d.ts +34 -0
- package/dist/core/export-html/tool-renderer.d.ts.map +1 -0
- package/dist/core/export-html/tool-renderer.js +108 -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 +24 -0
- package/dist/core/extensions/loader.d.ts.map +1 -0
- package/dist/core/extensions/loader.js +481 -0
- package/dist/core/extensions/loader.js.map +1 -0
- package/dist/core/extensions/runner.d.ts +159 -0
- package/dist/core/extensions/runner.d.ts.map +1 -0
- package/dist/core/extensions/runner.js +830 -0
- package/dist/core/extensions/runner.js.map +1 -0
- package/dist/core/extensions/types.d.ts +1175 -0
- package/dist/core/extensions/types.d.ts.map +1 -0
- package/dist/core/extensions/types.js +45 -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 +52 -0
- package/dist/core/footer-data-provider.d.ts.map +1 -0
- package/dist/core/footer-data-provider.js +310 -0
- package/dist/core/footer-data-provider.js.map +1 -0
- package/dist/core/http-dispatcher.d.ts +21 -0
- package/dist/core/http-dispatcher.d.ts.map +1 -0
- package/dist/core/http-dispatcher.js +48 -0
- package/dist/core/http-dispatcher.js.map +1 -0
- package/dist/core/index.d.ts +12 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +12 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/keybindings.d.ts +353 -0
- package/dist/core/keybindings.d.ts.map +1 -0
- package/dist/core/keybindings.js +295 -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 +150 -0
- package/dist/core/model-registry.d.ts.map +1 -0
- package/dist/core/model-registry.js +784 -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 +495 -0
- package/dist/core/model-resolver.js.map +1 -0
- package/dist/core/output-guard.d.ts +7 -0
- package/dist/core/output-guard.d.ts.map +1 -0
- package/dist/core/output-guard.js +89 -0
- package/dist/core/output-guard.js.map +1 -0
- package/dist/core/package-manager.d.ts +204 -0
- package/dist/core/package-manager.d.ts.map +1 -0
- package/dist/core/package-manager.js +2040 -0
- package/dist/core/package-manager.js.map +1 -0
- package/dist/core/prompt-templates.d.ts +52 -0
- package/dist/core/prompt-templates.d.ts.map +1 -0
- package/dist/core/prompt-templates.js +238 -0
- package/dist/core/prompt-templates.js.map +1 -0
- package/dist/core/provider-display-names.d.ts +2 -0
- package/dist/core/provider-display-names.d.ts.map +1 -0
- package/dist/core/provider-display-names.js +33 -0
- package/dist/core/provider-display-names.js.map +1 -0
- package/dist/core/resolve-config-value.d.ts +31 -0
- package/dist/core/resolve-config-value.d.ts.map +1 -0
- package/dist/core/resolve-config-value.js +249 -0
- package/dist/core/resolve-config-value.js.map +1 -0
- package/dist/core/resource-loader.d.ts +194 -0
- package/dist/core/resource-loader.d.ts.map +1 -0
- package/dist/core/resource-loader.js +734 -0
- package/dist/core/resource-loader.js.map +1 -0
- package/dist/core/sdk.d.ts +109 -0
- package/dist/core/sdk.d.ts.map +1 -0
- package/dist/core/sdk.js +291 -0
- package/dist/core/sdk.js.map +1 -0
- package/dist/core/session-cwd.d.ts +19 -0
- package/dist/core/session-cwd.d.ts.map +1 -0
- package/dist/core/session-cwd.js +38 -0
- package/dist/core/session-cwd.js.map +1 -0
- package/dist/core/session-manager.d.ts +332 -0
- package/dist/core/session-manager.d.ts.map +1 -0
- package/dist/core/session-manager.js +1194 -0
- package/dist/core/session-manager.js.map +1 -0
- package/dist/core/settings-manager.d.ts +266 -0
- package/dist/core/settings-manager.d.ts.map +1 -0
- package/dist/core/settings-manager.js +800 -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 +387 -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 +25 -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 +30 -0
- package/dist/core/system-prompt.d.ts.map +1 -0
- package/dist/core/system-prompt.js +117 -0
- package/dist/core/system-prompt.js.map +1 -0
- package/dist/core/telemetry.d.ts +3 -0
- package/dist/core/telemetry.d.ts.map +1 -0
- package/dist/core/telemetry.js +9 -0
- package/dist/core/telemetry.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 +68 -0
- package/dist/core/tools/bash.d.ts.map +1 -0
- package/dist/core/tools/bash.js +337 -0
- package/dist/core/tools/bash.js.map +1 -0
- package/dist/core/tools/edit-diff.d.ts +87 -0
- package/dist/core/tools/edit-diff.d.ts.map +1 -0
- package/dist/core/tools/edit-diff.js +345 -0
- package/dist/core/tools/edit-diff.js.map +1 -0
- package/dist/core/tools/edit.d.ts +51 -0
- package/dist/core/tools/edit.d.ts.map +1 -0
- package/dist/core/tools/edit.js +287 -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 +52 -0
- package/dist/core/tools/file-mutation-queue.js.map +1 -0
- package/dist/core/tools/find.d.ts +35 -0
- package/dist/core/tools/find.d.ts.map +1 -0
- package/dist/core/tools/find.js +297 -0
- package/dist/core/tools/find.js.map +1 -0
- package/dist/core/tools/grep.d.ts +37 -0
- package/dist/core/tools/grep.d.ts.map +1 -0
- package/dist/core/tools/grep.js +304 -0
- package/dist/core/tools/grep.js.map +1 -0
- package/dist/core/tools/index.d.ts +40 -0
- package/dist/core/tools/index.d.ts.map +1 -0
- package/dist/core/tools/index.js +112 -0
- package/dist/core/tools/index.js.map +1 -0
- package/dist/core/tools/ls.d.ts +37 -0
- package/dist/core/tools/ls.d.ts.map +1 -0
- package/dist/core/tools/ls.js +169 -0
- package/dist/core/tools/ls.js.map +1 -0
- package/dist/core/tools/output-accumulator.d.ts +52 -0
- package/dist/core/tools/output-accumulator.d.ts.map +1 -0
- package/dist/core/tools/output-accumulator.js +184 -0
- package/dist/core/tools/output-accumulator.js.map +1 -0
- package/dist/core/tools/path-utils.d.ts +10 -0
- package/dist/core/tools/path-utils.d.ts.map +1 -0
- package/dist/core/tools/path-utils.js +99 -0
- package/dist/core/tools/path-utils.js.map +1 -0
- package/dist/core/tools/read.d.ts +35 -0
- package/dist/core/tools/read.d.ts.map +1 -0
- package/dist/core/tools/read.js +290 -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 +34 -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 +215 -0
- package/dist/core/tools/truncate.js.map +1 -0
- package/dist/core/tools/worker.d.ts +23 -0
- package/dist/core/tools/worker.d.ts.map +1 -0
- package/dist/core/tools/worker.js +150 -0
- package/dist/core/tools/worker.js.map +1 -0
- package/dist/core/tools/write.d.ts +26 -0
- package/dist/core/tools/write.d.ts.map +1 -0
- package/dist/core/tools/write.js +198 -0
- package/dist/core/tools/write.js.map +1 -0
- package/dist/core/worker-integration.d.ts +79 -0
- package/dist/core/worker-integration.d.ts.map +1 -0
- package/dist/core/worker-integration.js +108 -0
- package/dist/core/worker-integration.js.map +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +42 -0
- package/dist/index.js.map +1 -0
- package/dist/main.d.ts +12 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +623 -0
- package/dist/main.js.map +1 -0
- package/dist/migrations.d.ts +33 -0
- package/dist/migrations.d.ts.map +1 -0
- package/dist/migrations.js +398 -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/assets/clankolas.png +0 -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 +20 -0
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/assistant-message.js +121 -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 +54 -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 +506 -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/daxnuts.d.ts +23 -0
- package/dist/modes/interactive/components/daxnuts.d.ts.map +1 -0
- package/dist/modes/interactive/components/daxnuts.js +140 -0
- package/dist/modes/interactive/components/daxnuts.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/earendil-announcement.d.ts +5 -0
- package/dist/modes/interactive/components/earendil-announcement.d.ts.map +1 -0
- package/dist/modes/interactive/components/earendil-announcement.js +40 -0
- package/dist/modes/interactive/components/earendil-announcement.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 +119 -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 +26 -0
- package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/extension-selector.js +83 -0
- package/dist/modes/interactive/components/extension-selector.js.map +1 -0
- package/dist/modes/interactive/components/footer.d.ts +28 -0
- package/dist/modes/interactive/components/footer.d.ts.map +1 -0
- package/dist/modes/interactive/components/footer.js +210 -0
- package/dist/modes/interactive/components/footer.js.map +1 -0
- package/dist/modes/interactive/components/index.d.ts +32 -0
- package/dist/modes/interactive/components/index.d.ts.map +1 -0
- package/dist/modes/interactive/components/index.js +33 -0
- package/dist/modes/interactive/components/index.js.map +1 -0
- package/dist/modes/interactive/components/keybinding-hints.d.ts +13 -0
- package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -0
- package/dist/modes/interactive/components/keybinding-hints.js +36 -0
- package/dist/modes/interactive/components/keybinding-hints.js.map +1 -0
- package/dist/modes/interactive/components/login-dialog.d.ts +52 -0
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -0
- package/dist/modes/interactive/components/login-dialog.js +183 -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 +278 -0
- package/dist/modes/interactive/components/model-selector.js.map +1 -0
- package/dist/modes/interactive/components/oauth-selector.d.ts +31 -0
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/oauth-selector.js +165 -0
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -0
- package/dist/modes/interactive/components/scoped-models-selector.d.ts +42 -0
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/scoped-models-selector.js +290 -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 +96 -0
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/session-selector.js +861 -0
- package/dist/modes/interactive/components/session-selector.js.map +1 -0
- package/dist/modes/interactive/components/settings-selector.d.ts +69 -0
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/settings-selector.js +390 -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 +63 -0
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -0
- package/dist/modes/interactive/components/tool-execution.js +295 -0
- package/dist/modes/interactive/components/tool-execution.js.map +1 -0
- package/dist/modes/interactive/components/tree-selector.d.ts +89 -0
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/tree-selector.js +1093 -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 +114 -0
- package/dist/modes/interactive/components/user-message-selector.js.map +1 -0
- package/dist/modes/interactive/components/user-message.d.ts +10 -0
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/user-message.js +29 -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/components/worker-status.d.ts +23 -0
- package/dist/modes/interactive/components/worker-status.d.ts.map +1 -0
- package/dist/modes/interactive/components/worker-status.js +77 -0
- package/dist/modes/interactive/components/worker-status.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts +370 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-mode.js +4674 -0
- package/dist/modes/interactive/interactive-mode.js.map +1 -0
- package/dist/modes/interactive/theme/dark.json +86 -0
- package/dist/modes/interactive/theme/light.json +85 -0
- package/dist/modes/interactive/theme/theme-schema.json +335 -0
- package/dist/modes/interactive/theme/theme.d.ts +100 -0
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -0
- package/dist/modes/interactive/theme/theme.js +1034 -0
- package/dist/modes/interactive/theme/theme.js.map +1 -0
- package/dist/modes/interactive/worker-ui-integration.d.ts +102 -0
- package/dist/modes/interactive/worker-ui-integration.d.ts.map +1 -0
- package/dist/modes/interactive/worker-ui-integration.js +147 -0
- package/dist/modes/interactive/worker-ui-integration.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 +131 -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 +227 -0
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-client.js +467 -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 +615 -0
- package/dist/modes/rpc/rpc-mode.js.map +1 -0
- package/dist/modes/rpc/rpc-types.d.ts +420 -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/package-manager-cli.d.ts +4 -0
- package/dist/package-manager-cli.d.ts.map +1 -0
- package/dist/package-manager-cli.js +515 -0
- package/dist/package-manager-cli.js.map +1 -0
- package/dist/utils/ansi.d.ts +2 -0
- package/dist/utils/ansi.d.ts.map +1 -0
- package/dist/utils/ansi.js +52 -0
- package/dist/utils/ansi.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 +15 -0
- package/dist/utils/child-process.d.ts.map +1 -0
- package/dist/utils/child-process.js +88 -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 +10 -0
- package/dist/utils/clipboard-native.d.ts.map +1 -0
- package/dist/utils/clipboard-native.js +20 -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 +117 -0
- package/dist/utils/clipboard.js.map +1 -0
- package/dist/utils/deprecation.d.ts +4 -0
- package/dist/utils/deprecation.d.ts.map +1 -0
- package/dist/utils/deprecation.js +13 -0
- package/dist/utils/deprecation.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/fs-watch.d.ts +5 -0
- package/dist/utils/fs-watch.d.ts.map +1 -0
- package/dist/utils/fs-watch.js +25 -0
- package/dist/utils/fs-watch.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/html.d.ts +7 -0
- package/dist/utils/html.d.ts.map +1 -0
- package/dist/utils/html.js +40 -0
- package/dist/utils/html.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-core.d.ts +30 -0
- package/dist/utils/image-resize-core.d.ts.map +1 -0
- package/dist/utils/image-resize-core.js +124 -0
- package/dist/utils/image-resize-core.js.map +1 -0
- package/dist/utils/image-resize-worker.d.ts +2 -0
- package/dist/utils/image-resize-worker.d.ts.map +1 -0
- package/dist/utils/image-resize-worker.js +31 -0
- package/dist/utils/image-resize-worker.js.map +1 -0
- package/dist/utils/image-resize.d.ts +16 -0
- package/dist/utils/image-resize.d.ts.map +1 -0
- package/dist/utils/image-resize.js +97 -0
- package/dist/utils/image-resize.js.map +1 -0
- package/dist/utils/json.d.ts +3 -0
- package/dist/utils/json.d.ts.map +1 -0
- package/dist/utils/json.js +7 -0
- package/dist/utils/json.js.map +1 -0
- package/dist/utils/leaf-user-agent.d.ts +2 -0
- package/dist/utils/leaf-user-agent.d.ts.map +1 -0
- package/dist/utils/leaf-user-agent.js +5 -0
- package/dist/utils/leaf-user-agent.js.map +1 -0
- package/dist/utils/mime.d.ts +3 -0
- package/dist/utils/mime.d.ts.map +1 -0
- package/dist/utils/mime.js +69 -0
- package/dist/utils/mime.js.map +1 -0
- package/dist/utils/paths.d.ts +31 -0
- package/dist/utils/paths.d.ts.map +1 -0
- package/dist/utils/paths.js +92 -0
- package/dist/utils/paths.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 +30 -0
- package/dist/utils/shell.d.ts.map +1 -0
- package/dist/utils/shell.js +195 -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/syntax-highlight.d.ts +12 -0
- package/dist/utils/syntax-highlight.d.ts.map +1 -0
- package/dist/utils/syntax-highlight.js +118 -0
- package/dist/utils/syntax-highlight.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 +328 -0
- package/dist/utils/tools-manager.js.map +1 -0
- package/dist/utils/version-check.d.ts +15 -0
- package/dist/utils/version-check.d.ts.map +1 -0
- package/dist/utils/version-check.js +82 -0
- package/dist/utils/version-check.js.map +1 -0
- package/dist/utils/windows-self-update.d.ts +3 -0
- package/dist/utils/windows-self-update.d.ts.map +1 -0
- package/dist/utils/windows-self-update.js +77 -0
- package/dist/utils/windows-self-update.js.map +1 -0
- package/package.json +100 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync, statSync } from "fs";
|
|
2
|
+
import { basename, dirname, join, resolve, sep } from "path";
|
|
3
|
+
import { CONFIG_DIR_NAME } from "../config.js";
|
|
4
|
+
import { parseFrontmatter } from "../utils/frontmatter.js";
|
|
5
|
+
import { resolvePath } from "../utils/paths.js";
|
|
6
|
+
import { createSyntheticSourceInfo } from "./source-info.js";
|
|
7
|
+
/**
|
|
8
|
+
* Parse command arguments respecting quoted strings (bash-style)
|
|
9
|
+
* Returns array of arguments
|
|
10
|
+
*/
|
|
11
|
+
export function parseCommandArgs(argsString) {
|
|
12
|
+
const args = [];
|
|
13
|
+
let current = "";
|
|
14
|
+
let inQuote = null;
|
|
15
|
+
for (let i = 0; i < argsString.length; i++) {
|
|
16
|
+
const char = argsString[i];
|
|
17
|
+
if (inQuote) {
|
|
18
|
+
if (char === inQuote) {
|
|
19
|
+
inQuote = null;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
current += char;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
else if (char === '"' || char === "'") {
|
|
26
|
+
inQuote = char;
|
|
27
|
+
}
|
|
28
|
+
else if (/\s/.test(char)) {
|
|
29
|
+
if (current) {
|
|
30
|
+
args.push(current);
|
|
31
|
+
current = "";
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
current += char;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (current) {
|
|
39
|
+
args.push(current);
|
|
40
|
+
}
|
|
41
|
+
return args;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Substitute argument placeholders in template content
|
|
45
|
+
* Supports:
|
|
46
|
+
* - $1, $2, ... for positional args
|
|
47
|
+
* - $@ and $ARGUMENTS for all args
|
|
48
|
+
* - ${@:N} for args from Nth onwards (bash-style slicing)
|
|
49
|
+
* - ${@:N:L} for L args starting from Nth
|
|
50
|
+
*
|
|
51
|
+
* Note: Replacement happens on the template string only. Argument values
|
|
52
|
+
* containing patterns like $1, $@, or $ARGUMENTS are NOT recursively substituted.
|
|
53
|
+
*/
|
|
54
|
+
export function substituteArgs(content, args) {
|
|
55
|
+
let result = content;
|
|
56
|
+
// Replace $1, $2, etc. with positional args FIRST (before wildcards)
|
|
57
|
+
// This prevents wildcard replacement values containing $<digit> patterns from being re-substituted
|
|
58
|
+
result = result.replace(/\$(\d+)/g, (_, num) => {
|
|
59
|
+
const index = parseInt(num, 10) - 1;
|
|
60
|
+
return args[index] ?? "";
|
|
61
|
+
});
|
|
62
|
+
// Replace ${@:start} or ${@:start:length} with sliced args (bash-style)
|
|
63
|
+
// Process BEFORE simple $@ to avoid conflicts
|
|
64
|
+
result = result.replace(/\$\{@:(\d+)(?::(\d+))?\}/g, (_, startStr, lengthStr) => {
|
|
65
|
+
let start = parseInt(startStr, 10) - 1; // Convert to 0-indexed (user provides 1-indexed)
|
|
66
|
+
// Treat 0 as 1 (bash convention: args start at 1)
|
|
67
|
+
if (start < 0)
|
|
68
|
+
start = 0;
|
|
69
|
+
if (lengthStr) {
|
|
70
|
+
const length = parseInt(lengthStr, 10);
|
|
71
|
+
return args.slice(start, start + length).join(" ");
|
|
72
|
+
}
|
|
73
|
+
return args.slice(start).join(" ");
|
|
74
|
+
});
|
|
75
|
+
// Pre-compute all args joined (optimization)
|
|
76
|
+
const allArgs = args.join(" ");
|
|
77
|
+
// Replace $ARGUMENTS with all args joined (new syntax, aligns with Claude, Codex, OpenCode)
|
|
78
|
+
result = result.replace(/\$ARGUMENTS/g, allArgs);
|
|
79
|
+
// Replace $@ with all args joined (existing syntax)
|
|
80
|
+
result = result.replace(/\$@/g, allArgs);
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
function loadTemplateFromFile(filePath, sourceInfo) {
|
|
84
|
+
try {
|
|
85
|
+
const rawContent = readFileSync(filePath, "utf-8");
|
|
86
|
+
const { frontmatter, body } = parseFrontmatter(rawContent);
|
|
87
|
+
const name = basename(filePath).replace(/\.md$/, "");
|
|
88
|
+
// Get description from frontmatter or first non-empty line
|
|
89
|
+
let description = frontmatter.description || "";
|
|
90
|
+
if (!description) {
|
|
91
|
+
const firstLine = body.split("\n").find((line) => line.trim());
|
|
92
|
+
if (firstLine) {
|
|
93
|
+
// Truncate if too long
|
|
94
|
+
description = firstLine.slice(0, 60);
|
|
95
|
+
if (firstLine.length > 60)
|
|
96
|
+
description += "...";
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
name,
|
|
101
|
+
description,
|
|
102
|
+
...(frontmatter["argument-hint"] && { argumentHint: frontmatter["argument-hint"] }),
|
|
103
|
+
content: body,
|
|
104
|
+
sourceInfo,
|
|
105
|
+
filePath,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Scan a directory for .md files (non-recursive) and load them as prompt templates.
|
|
114
|
+
*/
|
|
115
|
+
function loadTemplatesFromDir(dir, getSourceInfo) {
|
|
116
|
+
const templates = [];
|
|
117
|
+
if (!existsSync(dir)) {
|
|
118
|
+
return templates;
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
const entries = readdirSync(dir, { withFileTypes: true });
|
|
122
|
+
for (const entry of entries) {
|
|
123
|
+
const fullPath = join(dir, entry.name);
|
|
124
|
+
// For symlinks, check if they point to a file
|
|
125
|
+
let isFile = entry.isFile();
|
|
126
|
+
if (entry.isSymbolicLink()) {
|
|
127
|
+
try {
|
|
128
|
+
const stats = statSync(fullPath);
|
|
129
|
+
isFile = stats.isFile();
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
// Broken symlink, skip it
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (isFile && entry.name.endsWith(".md")) {
|
|
137
|
+
const template = loadTemplateFromFile(fullPath, getSourceInfo(fullPath));
|
|
138
|
+
if (template) {
|
|
139
|
+
templates.push(template);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
return templates;
|
|
146
|
+
}
|
|
147
|
+
return templates;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Load all prompt templates from:
|
|
151
|
+
* 1. Global: agentDir/prompts/
|
|
152
|
+
* 2. Project: cwd/{CONFIG_DIR_NAME}/prompts/
|
|
153
|
+
* 3. Explicit prompt paths
|
|
154
|
+
*/
|
|
155
|
+
export function loadPromptTemplates(options) {
|
|
156
|
+
const resolvedCwd = resolvePath(options.cwd);
|
|
157
|
+
const resolvedAgentDir = resolvePath(options.agentDir);
|
|
158
|
+
const promptPaths = options.promptPaths;
|
|
159
|
+
const includeDefaults = options.includeDefaults;
|
|
160
|
+
const templates = [];
|
|
161
|
+
const globalPromptsDir = join(resolvedAgentDir, "prompts");
|
|
162
|
+
const projectPromptsDir = resolve(resolvedCwd, CONFIG_DIR_NAME, "prompts");
|
|
163
|
+
const isUnderPath = (target, root) => {
|
|
164
|
+
const normalizedRoot = resolve(root);
|
|
165
|
+
if (target === normalizedRoot) {
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
const prefix = normalizedRoot.endsWith(sep) ? normalizedRoot : `${normalizedRoot}${sep}`;
|
|
169
|
+
return target.startsWith(prefix);
|
|
170
|
+
};
|
|
171
|
+
const getSourceInfo = (resolvedPath) => {
|
|
172
|
+
if (isUnderPath(resolvedPath, globalPromptsDir)) {
|
|
173
|
+
return createSyntheticSourceInfo(resolvedPath, {
|
|
174
|
+
source: "local",
|
|
175
|
+
scope: "user",
|
|
176
|
+
baseDir: globalPromptsDir,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
if (isUnderPath(resolvedPath, projectPromptsDir)) {
|
|
180
|
+
return createSyntheticSourceInfo(resolvedPath, {
|
|
181
|
+
source: "local",
|
|
182
|
+
scope: "project",
|
|
183
|
+
baseDir: projectPromptsDir,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
return createSyntheticSourceInfo(resolvedPath, {
|
|
187
|
+
source: "local",
|
|
188
|
+
baseDir: statSync(resolvedPath).isDirectory() ? resolvedPath : dirname(resolvedPath),
|
|
189
|
+
});
|
|
190
|
+
};
|
|
191
|
+
if (includeDefaults) {
|
|
192
|
+
templates.push(...loadTemplatesFromDir(globalPromptsDir, getSourceInfo));
|
|
193
|
+
templates.push(...loadTemplatesFromDir(projectPromptsDir, getSourceInfo));
|
|
194
|
+
}
|
|
195
|
+
// 3. Load explicit prompt paths
|
|
196
|
+
for (const rawPath of promptPaths) {
|
|
197
|
+
const resolvedPath = resolvePath(rawPath, resolvedCwd, { trim: true });
|
|
198
|
+
if (!existsSync(resolvedPath)) {
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
try {
|
|
202
|
+
const stats = statSync(resolvedPath);
|
|
203
|
+
if (stats.isDirectory()) {
|
|
204
|
+
templates.push(...loadTemplatesFromDir(resolvedPath, getSourceInfo));
|
|
205
|
+
}
|
|
206
|
+
else if (stats.isFile() && resolvedPath.endsWith(".md")) {
|
|
207
|
+
const template = loadTemplateFromFile(resolvedPath, getSourceInfo(resolvedPath));
|
|
208
|
+
if (template) {
|
|
209
|
+
templates.push(template);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
catch {
|
|
214
|
+
// Ignore read failures
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return templates;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Expand a prompt template if it matches a template name.
|
|
221
|
+
* Returns the expanded content or the original text if not a template.
|
|
222
|
+
*/
|
|
223
|
+
export function expandPromptTemplate(text, templates) {
|
|
224
|
+
if (!text.startsWith("/"))
|
|
225
|
+
return text;
|
|
226
|
+
const match = text.match(/^\/([^\s]+)(?:\s+([\s\S]*))?$/);
|
|
227
|
+
if (!match)
|
|
228
|
+
return text;
|
|
229
|
+
const templateName = match[1];
|
|
230
|
+
const argsString = match[2] ?? "";
|
|
231
|
+
const template = templates.find((t) => t.name === templateName);
|
|
232
|
+
if (template) {
|
|
233
|
+
const args = parseCommandArgs(argsString);
|
|
234
|
+
return substituteArgs(template.content, args);
|
|
235
|
+
}
|
|
236
|
+
return text;
|
|
237
|
+
}
|
|
238
|
+
//# sourceMappingURL=prompt-templates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-templates.js","sourceRoot":"","sources":["../../src/core/prompt-templates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,yBAAyB,EAAmB,MAAM,kBAAkB,CAAC;AAc9E;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,UAAkB,EAAY;IAC9D,MAAM,IAAI,GAAa,EAAE,CAAC;IAC1B,IAAI,OAAO,GAAG,EAAE,CAAC;IACjB,IAAI,OAAO,GAAkB,IAAI,CAAC;IAElC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5C,MAAM,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;QAE3B,IAAI,OAAO,EAAE,CAAC;YACb,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;gBACtB,OAAO,GAAG,IAAI,CAAC;YAChB,CAAC;iBAAM,CAAC;gBACP,OAAO,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AI,CAAC,CAAC;IAC/C,CAAC;IAED,OAAO,IAAI,CAAC;AAAA,CACZ","sourcesContent":["import { existsSync, readdirSync, readFileSync, statSync } from \"fs\";\nimport { basename, dirname, join, resolve, sep } from \"path\";\nimport { CONFIG_DIR_NAME } from \"../config.ts\";\nimport { parseFrontmatter } from \"../utils/frontmatter.ts\";\nimport { resolvePath } from \"../utils/paths.ts\";\nimport { createSyntheticSourceInfo, type SourceInfo } from \"./source-info.ts\";\n\n/**\n * Represents a prompt template loaded from a markdown file\n */\nexport interface PromptTemplate {\n\tname: string;\n\tdescription: string;\n\targumentHint?: string;\n\tcontent: string;\n\tsourceInfo: SourceInfo;\n\tfilePath: string; // Absolute path to the template file\n}\n\n/**\n * Parse command arguments respecting quoted strings (bash-style)\n * Returns array of arguments\n */\nexport function parseCommandArgs(argsString: string): string[] {\n\tconst args: string[] = [];\n\tlet current = \"\";\n\tlet inQuote: string | null = null;\n\n\tfor (let i = 0; i < argsString.length; i++) {\n\t\tconst char = argsString[i];\n\n\t\tif (inQuote) {\n\t\t\tif (char === inQuote) {\n\t\t\t\tinQuote = null;\n\t\t\t} else {\n\t\t\t\tcurrent += char;\n\t\t\t}\n\t\t} else if (char === '\"' || char === \"'\") {\n\t\t\tinQuote = char;\n\t\t} else if (/\\s/.test(char)) {\n\t\t\tif (current) {\n\t\t\t\targs.push(current);\n\t\t\t\tcurrent = \"\";\n\t\t\t}\n\t\t} else {\n\t\t\tcurrent += char;\n\t\t}\n\t}\n\n\tif (current) {\n\t\targs.push(current);\n\t}\n\n\treturn args;\n}\n\n/**\n * Substitute argument placeholders in template content\n * Supports:\n * - $1, $2, ... for positional args\n * - $@ and $ARGUMENTS for all args\n * - ${@:N} for args from Nth onwards (bash-style slicing)\n * - ${@:N:L} for L args starting from Nth\n *\n * Note: Replacement happens on the template string only. Argument values\n * containing patterns like $1, $@, or $ARGUMENTS are NOT recursively substituted.\n */\nexport function substituteArgs(content: string, args: string[]): string {\n\tlet result = content;\n\n\t// Replace $1, $2, etc. with positional args FIRST (before wildcards)\n\t// This prevents wildcard replacement values containing $<digit> patterns from being re-substituted\n\tresult = result.replace(/\\$(\\d+)/g, (_, num) => {\n\t\tconst index = parseInt(num, 10) - 1;\n\t\treturn args[index] ?? \"\";\n\t});\n\n\t// Replace ${@:start} or ${@:start:length} with sliced args (bash-style)\n\t// Process BEFORE simple $@ to avoid conflicts\n\tresult = result.replace(/\\$\\{@:(\\d+)(?::(\\d+))?\\}/g, (_, startStr, lengthStr) => {\n\t\tlet start = parseInt(startStr, 10) - 1; // Convert to 0-indexed (user provides 1-indexed)\n\t\t// Treat 0 as 1 (bash convention: args start at 1)\n\t\tif (start < 0) start = 0;\n\n\t\tif (lengthStr) {\n\t\t\tconst length = parseInt(lengthStr, 10);\n\t\t\treturn args.slice(start, start + length).join(\" \");\n\t\t}\n\t\treturn args.slice(start).join(\" \");\n\t});\n\n\t// Pre-compute all args joined (optimization)\n\tconst allArgs = args.join(\" \");\n\n\t// Replace $ARGUMENTS with all args joined (new syntax, aligns with Claude, Codex, OpenCode)\n\tresult = result.replace(/\\$ARGUMENTS/g, allArgs);\n\n\t// Replace $@ with all args joined (existing syntax)\n\tresult = result.replace(/\\$@/g, allArgs);\n\n\treturn result;\n}\n\nfunction loadTemplateFromFile(filePath: string, sourceInfo: SourceInfo): PromptTemplate | null {\n\ttry {\n\t\tconst rawContent = readFileSync(filePath, \"utf-8\");\n\t\tconst { frontmatter, body } = parseFrontmatter<Record<string, string>>(rawContent);\n\n\t\tconst name = basename(filePath).replace(/\\.md$/, \"\");\n\n\t\t// Get description from frontmatter or first non-empty line\n\t\tlet description = frontmatter.description || \"\";\n\t\tif (!description) {\n\t\t\tconst firstLine = body.split(\"\\n\").find((line) => line.trim());\n\t\t\tif (firstLine) {\n\t\t\t\t// Truncate if too long\n\t\t\t\tdescription = firstLine.slice(0, 60);\n\t\t\t\tif (firstLine.length > 60) description += \"...\";\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tname,\n\t\t\tdescription,\n\t\t\t...(frontmatter[\"argument-hint\"] && { argumentHint: frontmatter[\"argument-hint\"] }),\n\t\t\tcontent: body,\n\t\t\tsourceInfo,\n\t\t\tfilePath,\n\t\t};\n\t} catch {\n\t\treturn null;\n\t}\n}\n\n/**\n * Scan a directory for .md files (non-recursive) and load them as prompt templates.\n */\nfunction loadTemplatesFromDir(dir: string, getSourceInfo: (filePath: string) => SourceInfo): PromptTemplate[] {\n\tconst templates: PromptTemplate[] = [];\n\n\tif (!existsSync(dir)) {\n\t\treturn templates;\n\t}\n\n\ttry {\n\t\tconst entries = readdirSync(dir, { withFileTypes: true });\n\n\t\tfor (const entry of entries) {\n\t\t\tconst fullPath = join(dir, entry.name);\n\n\t\t\t// For symlinks, check if they point to a file\n\t\t\tlet isFile = entry.isFile();\n\t\t\tif (entry.isSymbolicLink()) {\n\t\t\t\ttry {\n\t\t\t\t\tconst stats = statSync(fullPath);\n\t\t\t\t\tisFile = stats.isFile();\n\t\t\t\t} catch {\n\t\t\t\t\t// Broken symlink, skip it\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (isFile && entry.name.endsWith(\".md\")) {\n\t\t\t\tconst template = loadTemplateFromFile(fullPath, getSourceInfo(fullPath));\n\t\t\t\tif (template) {\n\t\t\t\t\ttemplates.push(template);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} catch {\n\t\treturn templates;\n\t}\n\n\treturn templates;\n}\n\nexport interface LoadPromptTemplatesOptions {\n\t/** Working directory for project-local templates. */\n\tcwd: string;\n\t/** Agent config directory for global templates. */\n\tagentDir: string;\n\t/** Explicit prompt template paths (files or directories). */\n\tpromptPaths: string[];\n\t/** Include default prompt directories. */\n\tincludeDefaults: boolean;\n}\n\n/**\n * Load all prompt templates from:\n * 1. Global: agentDir/prompts/\n * 2. Project: cwd/{CONFIG_DIR_NAME}/prompts/\n * 3. Explicit prompt paths\n */\nexport function loadPromptTemplates(options: LoadPromptTemplatesOptions): PromptTemplate[] {\n\tconst resolvedCwd = resolvePath(options.cwd);\n\tconst resolvedAgentDir = resolvePath(options.agentDir);\n\tconst promptPaths = options.promptPaths;\n\tconst includeDefaults = options.includeDefaults;\n\n\tconst templates: PromptTemplate[] = [];\n\n\tconst globalPromptsDir = join(resolvedAgentDir, \"prompts\");\n\tconst projectPromptsDir = resolve(resolvedCwd, CONFIG_DIR_NAME, \"prompts\");\n\n\tconst isUnderPath = (target: string, root: string): boolean => {\n\t\tconst normalizedRoot = resolve(root);\n\t\tif (target === normalizedRoot) {\n\t\t\treturn true;\n\t\t}\n\t\tconst prefix = normalizedRoot.endsWith(sep) ? normalizedRoot : `${normalizedRoot}${sep}`;\n\t\treturn target.startsWith(prefix);\n\t};\n\n\tconst getSourceInfo = (resolvedPath: string): SourceInfo => {\n\t\tif (isUnderPath(resolvedPath, globalPromptsDir)) {\n\t\t\treturn createSyntheticSourceInfo(resolvedPath, {\n\t\t\t\tsource: \"local\",\n\t\t\t\tscope: \"user\",\n\t\t\t\tbaseDir: globalPromptsDir,\n\t\t\t});\n\t\t}\n\t\tif (isUnderPath(resolvedPath, projectPromptsDir)) {\n\t\t\treturn createSyntheticSourceInfo(resolvedPath, {\n\t\t\t\tsource: \"local\",\n\t\t\t\tscope: \"project\",\n\t\t\t\tbaseDir: projectPromptsDir,\n\t\t\t});\n\t\t}\n\t\treturn createSyntheticSourceInfo(resolvedPath, {\n\t\t\tsource: \"local\",\n\t\t\tbaseDir: statSync(resolvedPath).isDirectory() ? resolvedPath : dirname(resolvedPath),\n\t\t});\n\t};\n\n\tif (includeDefaults) {\n\t\ttemplates.push(...loadTemplatesFromDir(globalPromptsDir, getSourceInfo));\n\t\ttemplates.push(...loadTemplatesFromDir(projectPromptsDir, getSourceInfo));\n\t}\n\n\t// 3. Load explicit prompt paths\n\tfor (const rawPath of promptPaths) {\n\t\tconst resolvedPath = resolvePath(rawPath, resolvedCwd, { trim: true });\n\t\tif (!existsSync(resolvedPath)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\ttry {\n\t\t\tconst stats = statSync(resolvedPath);\n\t\t\tif (stats.isDirectory()) {\n\t\t\t\ttemplates.push(...loadTemplatesFromDir(resolvedPath, getSourceInfo));\n\t\t\t} else if (stats.isFile() && resolvedPath.endsWith(\".md\")) {\n\t\t\t\tconst template = loadTemplateFromFile(resolvedPath, getSourceInfo(resolvedPath));\n\t\t\t\tif (template) {\n\t\t\t\t\ttemplates.push(template);\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {\n\t\t\t// Ignore read failures\n\t\t}\n\t}\n\n\treturn templates;\n}\n\n/**\n * Expand a prompt template if it matches a template name.\n * Returns the expanded content or the original text if not a template.\n */\nexport function expandPromptTemplate(text: string, templates: PromptTemplate[]): string {\n\tif (!text.startsWith(\"/\")) return text;\n\n\tconst match = text.match(/^\\/([^\\s]+)(?:\\s+([\\s\\S]*))?$/);\n\tif (!match) return text;\n\n\tconst templateName = match[1];\n\tconst argsString = match[2] ?? \"\";\n\n\tconst template = templates.find((t) => t.name === templateName);\n\tif (template) {\n\t\tconst args = parseCommandArgs(argsString);\n\t\treturn substituteArgs(template.content, args);\n\t}\n\n\treturn text;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-display-names.d.ts","sourceRoot":"","sources":["../../src/core/provider-display-names.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,+BAA+B,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CA+BlE,CAAC","sourcesContent":["export const BUILT_IN_PROVIDER_DISPLAY_NAMES: Record<string, string> = {\n\tanthropic: \"Anthropic\",\n\t\"amazon-bedrock\": \"Amazon Bedrock\",\n\t\"azure-openai-responses\": \"Azure OpenAI Responses\",\n\tcerebras: \"Cerebras\",\n\t\"cloudflare-ai-gateway\": \"Cloudflare AI Gateway\",\n\t\"cloudflare-workers-ai\": \"Cloudflare Workers AI\",\n\tdeepseek: \"DeepSeek\",\n\tfireworks: \"Fireworks\",\n\tgoogle: \"Google Gemini\",\n\t\"google-vertex\": \"Google Vertex AI\",\n\tgroq: \"Groq\",\n\thuggingface: \"Hugging Face\",\n\t\"kimi-coding\": \"Kimi For Coding\",\n\tmistral: \"Mistral\",\n\tminimax: \"MiniMax\",\n\t\"minimax-cn\": \"MiniMax (China)\",\n\tmoonshotai: \"Moonshot AI\",\n\t\"moonshotai-cn\": \"Moonshot AI (China)\",\n\topencode: \"OpenCode Zen\",\n\t\"opencode-go\": \"OpenCode Go\",\n\topenai: \"OpenAI\",\n\topenrouter: \"OpenRouter\",\n\ttogether: \"Together AI\",\n\t\"vercel-ai-gateway\": \"Vercel AI Gateway\",\n\txai: \"xAI\",\n\tzai: \"ZAI\",\n\txiaomi: \"Xiaomi MiMo\",\n\t\"xiaomi-token-plan-cn\": \"Xiaomi MiMo Token Plan (China)\",\n\t\"xiaomi-token-plan-ams\": \"Xiaomi MiMo Token Plan (Amsterdam)\",\n\t\"xiaomi-token-plan-sgp\": \"Xiaomi MiMo Token Plan (Singapore)\",\n};\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export const BUILT_IN_PROVIDER_DISPLAY_NAMES = {
|
|
2
|
+
anthropic: "Anthropic",
|
|
3
|
+
"amazon-bedrock": "Amazon Bedrock",
|
|
4
|
+
"azure-openai-responses": "Azure OpenAI Responses",
|
|
5
|
+
cerebras: "Cerebras",
|
|
6
|
+
"cloudflare-ai-gateway": "Cloudflare AI Gateway",
|
|
7
|
+
"cloudflare-workers-ai": "Cloudflare Workers AI",
|
|
8
|
+
deepseek: "DeepSeek",
|
|
9
|
+
fireworks: "Fireworks",
|
|
10
|
+
google: "Google Gemini",
|
|
11
|
+
"google-vertex": "Google Vertex AI",
|
|
12
|
+
groq: "Groq",
|
|
13
|
+
huggingface: "Hugging Face",
|
|
14
|
+
"kimi-coding": "Kimi For Coding",
|
|
15
|
+
mistral: "Mistral",
|
|
16
|
+
minimax: "MiniMax",
|
|
17
|
+
"minimax-cn": "MiniMax (China)",
|
|
18
|
+
moonshotai: "Moonshot AI",
|
|
19
|
+
"moonshotai-cn": "Moonshot AI (China)",
|
|
20
|
+
opencode: "OpenCode Zen",
|
|
21
|
+
"opencode-go": "OpenCode Go",
|
|
22
|
+
openai: "OpenAI",
|
|
23
|
+
openrouter: "OpenRouter",
|
|
24
|
+
together: "Together AI",
|
|
25
|
+
"vercel-ai-gateway": "Vercel AI Gateway",
|
|
26
|
+
xai: "xAI",
|
|
27
|
+
zai: "ZAI",
|
|
28
|
+
xiaomi: "Xiaomi MiMo",
|
|
29
|
+
"xiaomi-token-plan-cn": "Xiaomi MiMo Token Plan (China)",
|
|
30
|
+
"xiaomi-token-plan-ams": "Xiaomi MiMo Token Plan (Amsterdam)",
|
|
31
|
+
"xiaomi-token-plan-sgp": "Xiaomi MiMo Token Plan (Singapore)",
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=provider-display-names.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-display-names.js","sourceRoot":"","sources":["../../src/core/provider-display-names.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,+BAA+B,GAA2B;IACtE,SAAS,EAAE,WAAW;IACtB,gBAAgB,EAAE,gBAAgB;IAClC,wBAAwB,EAAE,wBAAwB;IAClD,QAAQ,EAAE,UAAU;IACpB,uBAAuB,EAAE,uBAAuB;IAChD,uBAAuB,EAAE,uBAAuB;IAChD,QAAQ,EAAE,UAAU;IACpB,SAAS,EAAE,WAAW;IACtB,MAAM,EAAE,eAAe;IACvB,eAAe,EAAE,kBAAkB;IACnC,IAAI,EAAE,MAAM;IACZ,WAAW,EAAE,cAAc;IAC3B,aAAa,EAAE,iBAAiB;IAChC,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;IAClB,YAAY,EAAE,iBAAiB;IAC/B,UAAU,EAAE,aAAa;IACzB,eAAe,EAAE,qBAAqB;IACtC,QAAQ,EAAE,cAAc;IACxB,aAAa,EAAE,aAAa;IAC5B,MAAM,EAAE,QAAQ;IAChB,UAAU,EAAE,YAAY;IACxB,QAAQ,EAAE,aAAa;IACvB,mBAAmB,EAAE,mBAAmB;IACxC,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,MAAM,EAAE,aAAa;IACrB,sBAAsB,EAAE,gCAAgC;IACxD,uBAAuB,EAAE,oCAAoC;IAC7D,uBAAuB,EAAE,oCAAoC;CAC7D,CAAC","sourcesContent":["export const BUILT_IN_PROVIDER_DISPLAY_NAMES: Record<string, string> = {\n\tanthropic: \"Anthropic\",\n\t\"amazon-bedrock\": \"Amazon Bedrock\",\n\t\"azure-openai-responses\": \"Azure OpenAI Responses\",\n\tcerebras: \"Cerebras\",\n\t\"cloudflare-ai-gateway\": \"Cloudflare AI Gateway\",\n\t\"cloudflare-workers-ai\": \"Cloudflare Workers AI\",\n\tdeepseek: \"DeepSeek\",\n\tfireworks: \"Fireworks\",\n\tgoogle: \"Google Gemini\",\n\t\"google-vertex\": \"Google Vertex AI\",\n\tgroq: \"Groq\",\n\thuggingface: \"Hugging Face\",\n\t\"kimi-coding\": \"Kimi For Coding\",\n\tmistral: \"Mistral\",\n\tminimax: \"MiniMax\",\n\t\"minimax-cn\": \"MiniMax (China)\",\n\tmoonshotai: \"Moonshot AI\",\n\t\"moonshotai-cn\": \"Moonshot AI (China)\",\n\topencode: \"OpenCode Zen\",\n\t\"opencode-go\": \"OpenCode Go\",\n\topenai: \"OpenAI\",\n\topenrouter: \"OpenRouter\",\n\ttogether: \"Together AI\",\n\t\"vercel-ai-gateway\": \"Vercel AI Gateway\",\n\txai: \"xAI\",\n\tzai: \"ZAI\",\n\txiaomi: \"Xiaomi MiMo\",\n\t\"xiaomi-token-plan-cn\": \"Xiaomi MiMo Token Plan (China)\",\n\t\"xiaomi-token-plan-ams\": \"Xiaomi MiMo Token Plan (Amsterdam)\",\n\t\"xiaomi-token-plan-sgp\": \"Xiaomi MiMo Token Plan (Singapore)\",\n};\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve configuration values that may be shell commands, environment variables, or literals.
|
|
3
|
+
* Used by auth-storage.ts and model-registry.ts.
|
|
4
|
+
*/
|
|
5
|
+
export declare function getConfigValueEnvVarName(config: string): string | undefined;
|
|
6
|
+
export declare function getConfigValueEnvVarNames(config: string): string[];
|
|
7
|
+
export declare function getMissingConfigValueEnvVarNames(config: string): string[];
|
|
8
|
+
export declare function isCommandConfigValue(config: string): boolean;
|
|
9
|
+
export declare function isConfigValueConfigured(config: string): boolean;
|
|
10
|
+
export declare function isLegacyEnvVarNameConfigValue(config: string): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Resolve a config value (API key, header value, etc.) to an actual value.
|
|
13
|
+
* - If starts with "!", executes the rest as a shell command and uses stdout (cached)
|
|
14
|
+
* - Interpolates "$ENV_VAR" or "${ENV_VAR}" references with the named environment variable
|
|
15
|
+
* - In non-command values, "$$" escapes a literal "$" and "$!" escapes a literal "!"
|
|
16
|
+
* - Otherwise treats the value as a literal
|
|
17
|
+
*/
|
|
18
|
+
export declare function resolveConfigValue(config: string): string | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Resolve all header values using the same resolution logic as API keys.
|
|
21
|
+
*/
|
|
22
|
+
export declare function resolveConfigValueUncached(config: string): string | undefined;
|
|
23
|
+
export declare function resolveConfigValueOrThrow(config: string, description: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Resolve all header values using the same resolution logic as API keys.
|
|
26
|
+
*/
|
|
27
|
+
export declare function resolveHeaders(headers: Record<string, string> | undefined): Record<string, string> | undefined;
|
|
28
|
+
export declare function resolveHeadersOrThrow(headers: Record<string, string> | undefined, description: string): Record<string, string> | undefined;
|
|
29
|
+
/** Clear the config value command cache. Exported for testing. */
|
|
30
|
+
export declare function clearConfigValueCache(): void;
|
|
31
|
+
//# sourceMappingURL=resolve-config-value.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-config-value.d.ts","sourceRoot":"","sources":["../../src/core/resolve-config-value.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAgHH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAI3E;AAED,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAGlE;AAED,wBAAgB,gCAAgC,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAEzE;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAE5D;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAE/D;AAED,wBAAgB,6BAA6B,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAErE;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAMrE;AAiED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAM7E;AAED,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAsBrF;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAU9G;AAED,wBAAgB,qBAAqB,CACpC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,EAC3C,WAAW,EAAE,MAAM,GACjB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAOpC;AAED,kEAAkE;AAClE,wBAAgB,qBAAqB,IAAI,IAAI,CAE5C","sourcesContent":["/**\n * Resolve configuration values that may be shell commands, environment variables, or literals.\n * Used by auth-storage.ts and model-registry.ts.\n */\n\nimport { execSync, spawnSync } from \"child_process\";\nimport { getShellConfig } from \"../utils/shell.ts\";\n\n// Cache for shell command results (persists for process lifetime)\nconst commandResultCache = new Map<string, string | undefined>();\nconst ENV_VAR_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;\nconst ENV_VAR_NAME_PREFIX_RE = /^[A-Za-z_][A-Za-z0-9_]*/;\nconst LEGACY_ENV_VAR_NAME_RE = /^[A-Z_][A-Z0-9_]*$/;\n\ntype TemplatePart = { type: \"literal\"; value: string } | { type: \"env\"; name: string };\n\ntype ConfigValueReference = { type: \"command\"; config: string } | { type: \"template\"; parts: TemplatePart[] };\n\nfunction appendLiteral(parts: TemplatePart[], value: string): void {\n\tif (!value) return;\n\tconst previousPart = parts[parts.length - 1];\n\tif (previousPart?.type === \"literal\") {\n\t\tpreviousPart.value += value;\n\t\treturn;\n\t}\n\tparts.push({ type: \"literal\", value });\n}\n\nfunction parseConfigValueTemplate(config: string): TemplatePart[] {\n\tconst parts: TemplatePart[] = [];\n\tlet index = 0;\n\n\twhile (index < config.length) {\n\t\tconst dollarIndex = config.indexOf(\"$\", index);\n\t\tif (dollarIndex < 0) {\n\t\t\tappendLiteral(parts, config.slice(index));\n\t\t\tbreak;\n\t\t}\n\n\t\tappendLiteral(parts, config.slice(index, dollarIndex));\n\t\tconst nextChar = config[dollarIndex + 1];\n\n\t\tif (nextChar === \"$\" || nextChar === \"!\") {\n\t\t\tappendLiteral(parts, nextChar);\n\t\t\tindex = dollarIndex + 2;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (nextChar === \"{\") {\n\t\t\tconst endIndex = config.indexOf(\"}\", dollarIndex + 2);\n\t\t\tif (endIndex < 0) {\n\t\t\t\tappendLiteral(parts, \"$\");\n\t\t\t\tindex = dollarIndex + 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst name = config.slice(dollarIndex + 2, endIndex);\n\t\t\tif (ENV_VAR_NAME_RE.test(name)) {\n\t\t\t\tparts.push({ type: \"env\", name });\n\t\t\t} else {\n\t\t\t\tappendLiteral(parts, config.slice(dollarIndex, endIndex + 1));\n\t\t\t}\n\t\t\tindex = endIndex + 1;\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst match = config.slice(dollarIndex + 1).match(ENV_VAR_NAME_PREFIX_RE);\n\t\tif (match) {\n\t\t\tparts.push({ type: \"env\", name: match[0] });\n\t\t\tindex = dollarIndex + 1 + match[0].length;\n\t\t\tcontinue;\n\t\t}\n\n\t\tappendLiteral(parts, \"$\");\n\t\tindex = dollarIndex + 1;\n\t}\n\n\treturn parts;\n}\n\nfunction parseConfigValueReference(config: string): ConfigValueReference {\n\tif (config.startsWith(\"!\")) {\n\t\treturn { type: \"command\", config };\n\t}\n\n\treturn { type: \"template\", parts: parseConfigValueTemplate(config) };\n}\n\nfunction resolveEnvConfigValue(name: string): string | undefined {\n\treturn process.env[name] || undefined;\n}\n\nfunction getTemplateEnvVarNames(parts: TemplatePart[]): string[] {\n\tconst names: string[] = [];\n\tfor (const part of parts) {\n\t\tif (part.type !== \"env\" || names.includes(part.name)) continue;\n\t\tnames.push(part.name);\n\t}\n\treturn names;\n}\n\nfunction resolveTemplate(parts: TemplatePart[]): string | undefined {\n\tlet resolved = \"\";\n\tfor (const part of parts) {\n\t\tif (part.type === \"literal\") {\n\t\t\tresolved += part.value;\n\t\t\tcontinue;\n\t\t}\n\t\tconst envValue = resolveEnvConfigValue(part.name);\n\t\tif (envValue === undefined) return undefined;\n\t\tresolved += envValue;\n\t}\n\treturn resolved;\n}\n\nexport function getConfigValueEnvVarName(config: string): string | undefined {\n\tconst reference = parseConfigValueReference(config);\n\tif (reference.type !== \"template\") return undefined;\n\treturn reference.parts.length === 1 && reference.parts[0]?.type === \"env\" ? reference.parts[0].name : undefined;\n}\n\nexport function getConfigValueEnvVarNames(config: string): string[] {\n\tconst reference = parseConfigValueReference(config);\n\treturn reference.type === \"template\" ? getTemplateEnvVarNames(reference.parts) : [];\n}\n\nexport function getMissingConfigValueEnvVarNames(config: string): string[] {\n\treturn getConfigValueEnvVarNames(config).filter((name) => resolveEnvConfigValue(name) === undefined);\n}\n\nexport function isCommandConfigValue(config: string): boolean {\n\treturn parseConfigValueReference(config).type === \"command\";\n}\n\nexport function isConfigValueConfigured(config: string): boolean {\n\treturn getMissingConfigValueEnvVarNames(config).length === 0;\n}\n\nexport function isLegacyEnvVarNameConfigValue(config: string): boolean {\n\treturn LEGACY_ENV_VAR_NAME_RE.test(config);\n}\n\n/**\n * Resolve a config value (API key, header value, etc.) to an actual value.\n * - If starts with \"!\", executes the rest as a shell command and uses stdout (cached)\n * - Interpolates \"$ENV_VAR\" or \"${ENV_VAR}\" references with the named environment variable\n * - In non-command values, \"$$\" escapes a literal \"$\" and \"$!\" escapes a literal \"!\"\n * - Otherwise treats the value as a literal\n */\nexport function resolveConfigValue(config: string): string | undefined {\n\tconst reference = parseConfigValueReference(config);\n\tif (reference.type === \"command\") {\n\t\treturn executeCommand(reference.config);\n\t}\n\treturn resolveTemplate(reference.parts);\n}\n\nfunction executeWithConfiguredShell(command: string): { executed: boolean; value: string | undefined } {\n\ttry {\n\t\tconst { shell, args } = getShellConfig();\n\t\tconst result = spawnSync(shell, [...args, command], {\n\t\t\tencoding: \"utf-8\",\n\t\t\ttimeout: 10000,\n\t\t\tstdio: [\"ignore\", \"pipe\", \"ignore\"],\n\t\t\tshell: false,\n\t\t\twindowsHide: true,\n\t\t});\n\n\t\tif (result.error) {\n\t\t\tconst error = result.error as NodeJS.ErrnoException;\n\t\t\tif (error.code === \"ENOENT\") {\n\t\t\t\treturn { executed: false, value: undefined };\n\t\t\t}\n\t\t\treturn { executed: true, value: undefined };\n\t\t}\n\n\t\tif (result.status !== 0) {\n\t\t\treturn { executed: true, value: undefined };\n\t\t}\n\n\t\tconst value = (result.stdout ?? \"\").trim();\n\t\treturn { executed: true, value: value || undefined };\n\t} catch {\n\t\treturn { executed: false, value: undefined };\n\t}\n}\n\nfunction executeWithDefaultShell(command: string): string | undefined {\n\ttry {\n\t\tconst output = execSync(command, {\n\t\t\tencoding: \"utf-8\",\n\t\t\ttimeout: 10000,\n\t\t\tstdio: [\"ignore\", \"pipe\", \"ignore\"],\n\t\t});\n\t\treturn output.trim() || undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction executeCommandUncached(commandConfig: string): string | undefined {\n\tconst command = commandConfig.slice(1);\n\treturn process.platform === \"win32\"\n\t\t? (() => {\n\t\t\t\tconst configuredResult = executeWithConfiguredShell(command);\n\t\t\t\treturn configuredResult.executed ? configuredResult.value : executeWithDefaultShell(command);\n\t\t\t})()\n\t\t: executeWithDefaultShell(command);\n}\n\nfunction executeCommand(commandConfig: string): string | undefined {\n\tif (commandResultCache.has(commandConfig)) {\n\t\treturn commandResultCache.get(commandConfig);\n\t}\n\n\tconst result = executeCommandUncached(commandConfig);\n\tcommandResultCache.set(commandConfig, result);\n\treturn result;\n}\n\n/**\n * Resolve all header values using the same resolution logic as API keys.\n */\nexport function resolveConfigValueUncached(config: string): string | undefined {\n\tconst reference = parseConfigValueReference(config);\n\tif (reference.type === \"command\") {\n\t\treturn executeCommandUncached(reference.config);\n\t}\n\treturn resolveTemplate(reference.parts);\n}\n\nexport function resolveConfigValueOrThrow(config: string, description: string): string {\n\tconst resolvedValue = resolveConfigValueUncached(config);\n\tif (resolvedValue !== undefined) {\n\t\treturn resolvedValue;\n\t}\n\n\tconst reference = parseConfigValueReference(config);\n\tif (reference.type === \"command\") {\n\t\tthrow new Error(`Failed to resolve ${description} from shell command: ${reference.config.slice(1)}`);\n\t}\n\n\tif (reference.type === \"template\") {\n\t\tconst missingEnvVars = getMissingConfigValueEnvVarNames(config);\n\t\tif (missingEnvVars.length === 1) {\n\t\t\tthrow new Error(`Failed to resolve ${description} from environment variable: ${missingEnvVars[0]}`);\n\t\t}\n\t\tif (missingEnvVars.length > 1) {\n\t\t\tthrow new Error(`Failed to resolve ${description} from environment variables: ${missingEnvVars.join(\", \")}`);\n\t\t}\n\t}\n\n\tthrow new Error(`Failed to resolve ${description}`);\n}\n\n/**\n * Resolve all header values using the same resolution logic as API keys.\n */\nexport function resolveHeaders(headers: Record<string, string> | undefined): Record<string, string> | undefined {\n\tif (!headers) return undefined;\n\tconst resolved: Record<string, string> = {};\n\tfor (const [key, value] of Object.entries(headers)) {\n\t\tconst resolvedValue = resolveConfigValue(value);\n\t\tif (resolvedValue) {\n\t\t\tresolved[key] = resolvedValue;\n\t\t}\n\t}\n\treturn Object.keys(resolved).length > 0 ? resolved : undefined;\n}\n\nexport function resolveHeadersOrThrow(\n\theaders: Record<string, string> | undefined,\n\tdescription: string,\n): Record<string, string> | undefined {\n\tif (!headers) return undefined;\n\tconst resolved: Record<string, string> = {};\n\tfor (const [key, value] of Object.entries(headers)) {\n\t\tresolved[key] = resolveConfigValueOrThrow(value, `${description} header \"${key}\"`);\n\t}\n\treturn Object.keys(resolved).length > 0 ? resolved : undefined;\n}\n\n/** Clear the config value command cache. Exported for testing. */\nexport function clearConfigValueCache(): void {\n\tcommandResultCache.clear();\n}\n"]}
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve configuration values that may be shell commands, environment variables, or literals.
|
|
3
|
+
* Used by auth-storage.ts and model-registry.ts.
|
|
4
|
+
*/
|
|
5
|
+
import { execSync, spawnSync } from "child_process";
|
|
6
|
+
import { getShellConfig } from "../utils/shell.js";
|
|
7
|
+
// Cache for shell command results (persists for process lifetime)
|
|
8
|
+
const commandResultCache = new Map();
|
|
9
|
+
const ENV_VAR_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
10
|
+
const ENV_VAR_NAME_PREFIX_RE = /^[A-Za-z_][A-Za-z0-9_]*/;
|
|
11
|
+
const LEGACY_ENV_VAR_NAME_RE = /^[A-Z_][A-Z0-9_]*$/;
|
|
12
|
+
function appendLiteral(parts, value) {
|
|
13
|
+
if (!value)
|
|
14
|
+
return;
|
|
15
|
+
const previousPart = parts[parts.length - 1];
|
|
16
|
+
if (previousPart?.type === "literal") {
|
|
17
|
+
previousPart.value += value;
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
parts.push({ type: "literal", value });
|
|
21
|
+
}
|
|
22
|
+
function parseConfigValueTemplate(config) {
|
|
23
|
+
const parts = [];
|
|
24
|
+
let index = 0;
|
|
25
|
+
while (index < config.length) {
|
|
26
|
+
const dollarIndex = config.indexOf("$", index);
|
|
27
|
+
if (dollarIndex < 0) {
|
|
28
|
+
appendLiteral(parts, config.slice(index));
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
appendLiteral(parts, config.slice(index, dollarIndex));
|
|
32
|
+
const nextChar = config[dollarIndex + 1];
|
|
33
|
+
if (nextChar === "$" || nextChar === "!") {
|
|
34
|
+
appendLiteral(parts, nextChar);
|
|
35
|
+
index = dollarIndex + 2;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (nextChar === "{") {
|
|
39
|
+
const endIndex = config.indexOf("}", dollarIndex + 2);
|
|
40
|
+
if (endIndex < 0) {
|
|
41
|
+
appendLiteral(parts, "$");
|
|
42
|
+
index = dollarIndex + 1;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
const name = config.slice(dollarIndex + 2, endIndex);
|
|
46
|
+
if (ENV_VAR_NAME_RE.test(name)) {
|
|
47
|
+
parts.push({ type: "env", name });
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
appendLiteral(parts, config.slice(dollarIndex, endIndex + 1));
|
|
51
|
+
}
|
|
52
|
+
index = endIndex + 1;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const match = config.slice(dollarIndex + 1).match(ENV_VAR_NAME_PREFIX_RE);
|
|
56
|
+
if (match) {
|
|
57
|
+
parts.push({ type: "env", name: match[0] });
|
|
58
|
+
index = dollarIndex + 1 + match[0].length;
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
appendLiteral(parts, "$");
|
|
62
|
+
index = dollarIndex + 1;
|
|
63
|
+
}
|
|
64
|
+
return parts;
|
|
65
|
+
}
|
|
66
|
+
function parseConfigValueReference(config) {
|
|
67
|
+
if (config.startsWith("!")) {
|
|
68
|
+
return { type: "command", config };
|
|
69
|
+
}
|
|
70
|
+
return { type: "template", parts: parseConfigValueTemplate(config) };
|
|
71
|
+
}
|
|
72
|
+
function resolveEnvConfigValue(name) {
|
|
73
|
+
return process.env[name] || undefined;
|
|
74
|
+
}
|
|
75
|
+
function getTemplateEnvVarNames(parts) {
|
|
76
|
+
const names = [];
|
|
77
|
+
for (const part of parts) {
|
|
78
|
+
if (part.type !== "env" || names.includes(part.name))
|
|
79
|
+
continue;
|
|
80
|
+
names.push(part.name);
|
|
81
|
+
}
|
|
82
|
+
return names;
|
|
83
|
+
}
|
|
84
|
+
function resolveTemplate(parts) {
|
|
85
|
+
let resolved = "";
|
|
86
|
+
for (const part of parts) {
|
|
87
|
+
if (part.type === "literal") {
|
|
88
|
+
resolved += part.value;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
const envValue = resolveEnvConfigValue(part.name);
|
|
92
|
+
if (envValue === undefined)
|
|
93
|
+
return undefined;
|
|
94
|
+
resolved += envValue;
|
|
95
|
+
}
|
|
96
|
+
return resolved;
|
|
97
|
+
}
|
|
98
|
+
export function getConfigValueEnvVarName(config) {
|
|
99
|
+
const reference = parseConfigValueReference(config);
|
|
100
|
+
if (reference.type !== "template")
|
|
101
|
+
return undefined;
|
|
102
|
+
return reference.parts.length === 1 && reference.parts[0]?.type === "env" ? reference.parts[0].name : undefined;
|
|
103
|
+
}
|
|
104
|
+
export function getConfigValueEnvVarNames(config) {
|
|
105
|
+
const reference = parseConfigValueReference(config);
|
|
106
|
+
return reference.type === "template" ? getTemplateEnvVarNames(reference.parts) : [];
|
|
107
|
+
}
|
|
108
|
+
export function getMissingConfigValueEnvVarNames(config) {
|
|
109
|
+
return getConfigValueEnvVarNames(config).filter((name) => resolveEnvConfigValue(name) === undefined);
|
|
110
|
+
}
|
|
111
|
+
export function isCommandConfigValue(config) {
|
|
112
|
+
return parseConfigValueReference(config).type === "command";
|
|
113
|
+
}
|
|
114
|
+
export function isConfigValueConfigured(config) {
|
|
115
|
+
return getMissingConfigValueEnvVarNames(config).length === 0;
|
|
116
|
+
}
|
|
117
|
+
export function isLegacyEnvVarNameConfigValue(config) {
|
|
118
|
+
return LEGACY_ENV_VAR_NAME_RE.test(config);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Resolve a config value (API key, header value, etc.) to an actual value.
|
|
122
|
+
* - If starts with "!", executes the rest as a shell command and uses stdout (cached)
|
|
123
|
+
* - Interpolates "$ENV_VAR" or "${ENV_VAR}" references with the named environment variable
|
|
124
|
+
* - In non-command values, "$$" escapes a literal "$" and "$!" escapes a literal "!"
|
|
125
|
+
* - Otherwise treats the value as a literal
|
|
126
|
+
*/
|
|
127
|
+
export function resolveConfigValue(config) {
|
|
128
|
+
const reference = parseConfigValueReference(config);
|
|
129
|
+
if (reference.type === "command") {
|
|
130
|
+
return executeCommand(reference.config);
|
|
131
|
+
}
|
|
132
|
+
return resolveTemplate(reference.parts);
|
|
133
|
+
}
|
|
134
|
+
function executeWithConfiguredShell(command) {
|
|
135
|
+
try {
|
|
136
|
+
const { shell, args } = getShellConfig();
|
|
137
|
+
const result = spawnSync(shell, [...args, command], {
|
|
138
|
+
encoding: "utf-8",
|
|
139
|
+
timeout: 10000,
|
|
140
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
141
|
+
shell: false,
|
|
142
|
+
windowsHide: true,
|
|
143
|
+
});
|
|
144
|
+
if (result.error) {
|
|
145
|
+
const error = result.error;
|
|
146
|
+
if (error.code === "ENOENT") {
|
|
147
|
+
return { executed: false, value: undefined };
|
|
148
|
+
}
|
|
149
|
+
return { executed: true, value: undefined };
|
|
150
|
+
}
|
|
151
|
+
if (result.status !== 0) {
|
|
152
|
+
return { executed: true, value: undefined };
|
|
153
|
+
}
|
|
154
|
+
const value = (result.stdout ?? "").trim();
|
|
155
|
+
return { executed: true, value: value || undefined };
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
return { executed: false, value: undefined };
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function executeWithDefaultShell(command) {
|
|
162
|
+
try {
|
|
163
|
+
const output = execSync(command, {
|
|
164
|
+
encoding: "utf-8",
|
|
165
|
+
timeout: 10000,
|
|
166
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
167
|
+
});
|
|
168
|
+
return output.trim() || undefined;
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
return undefined;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
function executeCommandUncached(commandConfig) {
|
|
175
|
+
const command = commandConfig.slice(1);
|
|
176
|
+
return process.platform === "win32"
|
|
177
|
+
? (() => {
|
|
178
|
+
const configuredResult = executeWithConfiguredShell(command);
|
|
179
|
+
return configuredResult.executed ? configuredResult.value : executeWithDefaultShell(command);
|
|
180
|
+
})()
|
|
181
|
+
: executeWithDefaultShell(command);
|
|
182
|
+
}
|
|
183
|
+
function executeCommand(commandConfig) {
|
|
184
|
+
if (commandResultCache.has(commandConfig)) {
|
|
185
|
+
return commandResultCache.get(commandConfig);
|
|
186
|
+
}
|
|
187
|
+
const result = executeCommandUncached(commandConfig);
|
|
188
|
+
commandResultCache.set(commandConfig, result);
|
|
189
|
+
return result;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Resolve all header values using the same resolution logic as API keys.
|
|
193
|
+
*/
|
|
194
|
+
export function resolveConfigValueUncached(config) {
|
|
195
|
+
const reference = parseConfigValueReference(config);
|
|
196
|
+
if (reference.type === "command") {
|
|
197
|
+
return executeCommandUncached(reference.config);
|
|
198
|
+
}
|
|
199
|
+
return resolveTemplate(reference.parts);
|
|
200
|
+
}
|
|
201
|
+
export function resolveConfigValueOrThrow(config, description) {
|
|
202
|
+
const resolvedValue = resolveConfigValueUncached(config);
|
|
203
|
+
if (resolvedValue !== undefined) {
|
|
204
|
+
return resolvedValue;
|
|
205
|
+
}
|
|
206
|
+
const reference = parseConfigValueReference(config);
|
|
207
|
+
if (reference.type === "command") {
|
|
208
|
+
throw new Error(`Failed to resolve ${description} from shell command: ${reference.config.slice(1)}`);
|
|
209
|
+
}
|
|
210
|
+
if (reference.type === "template") {
|
|
211
|
+
const missingEnvVars = getMissingConfigValueEnvVarNames(config);
|
|
212
|
+
if (missingEnvVars.length === 1) {
|
|
213
|
+
throw new Error(`Failed to resolve ${description} from environment variable: ${missingEnvVars[0]}`);
|
|
214
|
+
}
|
|
215
|
+
if (missingEnvVars.length > 1) {
|
|
216
|
+
throw new Error(`Failed to resolve ${description} from environment variables: ${missingEnvVars.join(", ")}`);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
throw new Error(`Failed to resolve ${description}`);
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Resolve all header values using the same resolution logic as API keys.
|
|
223
|
+
*/
|
|
224
|
+
export function resolveHeaders(headers) {
|
|
225
|
+
if (!headers)
|
|
226
|
+
return undefined;
|
|
227
|
+
const resolved = {};
|
|
228
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
229
|
+
const resolvedValue = resolveConfigValue(value);
|
|
230
|
+
if (resolvedValue) {
|
|
231
|
+
resolved[key] = resolvedValue;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return Object.keys(resolved).length > 0 ? resolved : undefined;
|
|
235
|
+
}
|
|
236
|
+
export function resolveHeadersOrThrow(headers, description) {
|
|
237
|
+
if (!headers)
|
|
238
|
+
return undefined;
|
|
239
|
+
const resolved = {};
|
|
240
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
241
|
+
resolved[key] = resolveConfigValueOrThrow(value, `${description} header "${key}"`);
|
|
242
|
+
}
|
|
243
|
+
return Object.keys(resolved).length > 0 ? resolved : undefined;
|
|
244
|
+
}
|
|
245
|
+
/** Clear the config value command cache. Exported for testing. */
|
|
246
|
+
export function clearConfigValueCache() {
|
|
247
|
+
commandResultCache.clear();
|
|
248
|
+
}
|
|
249
|
+
//# sourceMappingURL=resolve-config-value.js.map
|