openvibe 0.57.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3041 -0
- package/README.md +569 -0
- package/dist/cli/args.d.ts +44 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/args.js +272 -0
- package/dist/cli/args.js.map +1 -0
- package/dist/cli/config-selector.d.ts +10 -0
- package/dist/cli/config-selector.d.ts.map +1 -0
- package/dist/cli/config-selector.js +26 -0
- package/dist/cli/config-selector.js.map +1 -0
- package/dist/cli/file-processor.d.ts +10 -0
- package/dist/cli/file-processor.d.ts.map +1 -0
- package/dist/cli/file-processor.js +68 -0
- package/dist/cli/file-processor.js.map +1 -0
- package/dist/cli/list-models.d.ts +3 -0
- package/dist/cli/list-models.d.ts.map +1 -0
- package/dist/cli/list-models.js +30 -0
- package/dist/cli/list-models.js.map +1 -0
- package/dist/cli/session-picker.d.ts +5 -0
- package/dist/cli/session-picker.d.ts.map +1 -0
- package/dist/cli/session-picker.js +30 -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 +31 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +29 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +145 -0
- package/dist/config.js.map +1 -0
- package/dist/core/accelerated-client.d.ts +42 -0
- package/dist/core/accelerated-client.d.ts.map +1 -0
- package/dist/core/accelerated-client.js +97 -0
- package/dist/core/accelerated-client.js.map +1 -0
- package/dist/core/accelerated-stream.d.ts +41 -0
- package/dist/core/accelerated-stream.d.ts.map +1 -0
- package/dist/core/accelerated-stream.js +133 -0
- package/dist/core/accelerated-stream.js.map +1 -0
- package/dist/core/agent-session.d.ts +566 -0
- package/dist/core/agent-session.d.ts.map +1 -0
- package/dist/core/agent-session.js +2361 -0
- package/dist/core/agent-session.js.map +1 -0
- package/dist/core/api-concurrency.d.ts +37 -0
- package/dist/core/api-concurrency.d.ts.map +1 -0
- package/dist/core/api-concurrency.js +179 -0
- package/dist/core/api-concurrency.js.map +1 -0
- package/dist/core/auth-storage.d.ts +66 -0
- package/dist/core/auth-storage.d.ts.map +1 -0
- package/dist/core/auth-storage.js +336 -0
- package/dist/core/auth-storage.js.map +1 -0
- package/dist/core/bash-executor.d.ts +15 -0
- package/dist/core/bash-executor.d.ts.map +1 -0
- package/dist/core/bash-executor.js +166 -0
- package/dist/core/bash-executor.js.map +1 -0
- package/dist/core/branded-ai.d.ts +17 -0
- package/dist/core/branded-ai.d.ts.map +1 -0
- package/dist/core/branded-ai.js +123 -0
- package/dist/core/branded-ai.js.map +1 -0
- package/dist/core/compaction/branch-summarization.d.ts +37 -0
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -0
- package/dist/core/compaction/branch-summarization.js +158 -0
- package/dist/core/compaction/branch-summarization.js.map +1 -0
- package/dist/core/compaction/compaction.d.ts +56 -0
- package/dist/core/compaction/compaction.d.ts.map +1 -0
- package/dist/core/compaction/compaction.js +501 -0
- package/dist/core/compaction/compaction.js.map +1 -0
- package/dist/core/compaction/index.d.ts +4 -0
- package/dist/core/compaction/index.d.ts.map +1 -0
- package/dist/core/compaction/index.js +4 -0
- package/dist/core/compaction/index.js.map +1 -0
- package/dist/core/compaction/utils.d.ts +17 -0
- package/dist/core/compaction/utils.d.ts.map +1 -0
- package/dist/core/compaction/utils.js +120 -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 +13 -0
- package/dist/core/exec.d.ts.map +1 -0
- package/dist/core/exec.js +61 -0
- package/dist/core/exec.js.map +1 -0
- package/dist/core/export-html/ansi-to-html.d.ts +3 -0
- package/dist/core/export-html/ansi-to-html.d.ts.map +1 -0
- package/dist/core/export-html/ansi-to-html.js +193 -0
- package/dist/core/export-html/ansi-to-html.js.map +1 -0
- package/dist/core/export-html/index.d.ts +22 -0
- package/dist/core/export-html/index.d.ts.map +1 -0
- package/dist/core/export-html/index.js +193 -0
- package/dist/core/export-html/index.js.map +1 -0
- package/dist/core/export-html/template.css +971 -0
- package/dist/core/export-html/template.html +54 -0
- package/dist/core/export-html/template.js +1583 -0
- package/dist/core/export-html/tool-renderer.d.ts +21 -0
- package/dist/core/export-html/tool-renderer.d.ts.map +1 -0
- package/dist/core/export-html/tool-renderer.js +51 -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 +8 -0
- package/dist/core/extensions/index.d.ts.map +1 -0
- package/dist/core/extensions/index.js +5 -0
- package/dist/core/extensions/index.js.map +1 -0
- package/dist/core/extensions/loader.d.ts +7 -0
- package/dist/core/extensions/loader.d.ts.map +1 -0
- package/dist/core/extensions/loader.js +349 -0
- package/dist/core/extensions/loader.js.map +1 -0
- package/dist/core/extensions/runner.d.ts +124 -0
- package/dist/core/extensions/runner.d.ts.map +1 -0
- package/dist/core/extensions/runner.js +657 -0
- package/dist/core/extensions/runner.js.map +1 -0
- package/dist/core/extensions/types.d.ts +1032 -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 +8 -0
- package/dist/core/extensions/wrapper.d.ts.map +1 -0
- package/dist/core/extensions/wrapper.js +79 -0
- package/dist/core/extensions/wrapper.js.map +1 -0
- package/dist/core/footer-data-provider.d.ts +19 -0
- package/dist/core/footer-data-provider.d.ts.map +1 -0
- package/dist/core/footer-data-provider.js +113 -0
- package/dist/core/footer-data-provider.js.map +1 -0
- package/dist/core/index.d.ts +13 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +11 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/keybindings.d.ts +22 -0
- package/dist/core/keybindings.d.ts.map +1 -0
- package/dist/core/keybindings.js +124 -0
- package/dist/core/keybindings.js.map +1 -0
- package/dist/core/messages.d.ts +51 -0
- package/dist/core/messages.d.ts.map +1 -0
- package/dist/core/messages.js +102 -0
- package/dist/core/messages.js.map +1 -0
- package/dist/core/model-registry.d.ts +26 -0
- package/dist/core/model-registry.d.ts.map +1 -0
- package/dist/core/model-registry.js +61 -0
- package/dist/core/model-registry.js.map +1 -0
- package/dist/core/model-resolver.d.ts +20 -0
- package/dist/core/model-resolver.d.ts.map +1 -0
- package/dist/core/model-resolver.js +47 -0
- package/dist/core/model-resolver.js.map +1 -0
- package/dist/core/multi-gpu-executor.d.ts +50 -0
- package/dist/core/multi-gpu-executor.d.ts.map +1 -0
- package/dist/core/multi-gpu-executor.js +201 -0
- package/dist/core/multi-gpu-executor.js.map +1 -0
- package/dist/core/onboarding.d.ts +3 -0
- package/dist/core/onboarding.d.ts.map +1 -0
- package/dist/core/onboarding.js +109 -0
- package/dist/core/onboarding.js.map +1 -0
- package/dist/core/package-manager.d.ts +136 -0
- package/dist/core/package-manager.d.ts.map +1 -0
- package/dist/core/package-manager.js +1375 -0
- package/dist/core/package-manager.js.map +1 -0
- package/dist/core/prompt-templates.d.ts +18 -0
- package/dist/core/prompt-templates.d.ts.map +1 -0
- package/dist/core/prompt-templates.js +204 -0
- package/dist/core/prompt-templates.js.map +1 -0
- package/dist/core/resolve-config-value.d.ts +4 -0
- package/dist/core/resolve-config-value.d.ts.map +1 -0
- package/dist/core/resolve-config-value.js +45 -0
- package/dist/core/resolve-config-value.js.map +1 -0
- package/dist/core/resource-loader.d.ts +184 -0
- package/dist/core/resource-loader.d.ts.map +1 -0
- package/dist/core/resource-loader.js +661 -0
- package/dist/core/resource-loader.js.map +1 -0
- package/dist/core/response-accelerator.d.ts +51 -0
- package/dist/core/response-accelerator.d.ts.map +1 -0
- package/dist/core/response-accelerator.js +149 -0
- package/dist/core/response-accelerator.js.map +1 -0
- package/dist/core/sdk.d.ts +39 -0
- package/dist/core/sdk.d.ts.map +1 -0
- package/dist/core/sdk.js +151 -0
- package/dist/core/sdk.js.map +1 -0
- package/dist/core/session-manager.d.ts +160 -0
- package/dist/core/session-manager.d.ts.map +1 -0
- package/dist/core/session-manager.js +899 -0
- package/dist/core/session-manager.js.map +1 -0
- package/dist/core/settings-manager.d.ts +220 -0
- package/dist/core/settings-manager.d.ts.map +1 -0
- package/dist/core/settings-manager.js +673 -0
- package/dist/core/settings-manager.js.map +1 -0
- package/dist/core/skills.d.ts +33 -0
- package/dist/core/skills.d.ts.map +1 -0
- package/dist/core/skills.js +326 -0
- package/dist/core/skills.js.map +1 -0
- package/dist/core/slash-commands.d.ts +15 -0
- package/dist/core/slash-commands.d.ts.map +1 -0
- package/dist/core/slash-commands.js +19 -0
- package/dist/core/slash-commands.js.map +1 -0
- package/dist/core/system-prompt.d.ts +23 -0
- package/dist/core/system-prompt.d.ts.map +1 -0
- package/dist/core/system-prompt.js +154 -0
- package/dist/core/system-prompt.js.map +1 -0
- package/dist/core/timings.d.ts +3 -0
- package/dist/core/timings.d.ts.map +1 -0
- package/dist/core/timings.js +21 -0
- package/dist/core/timings.js.map +1 -0
- package/dist/core/tools/bash.d.ts +40 -0
- package/dist/core/tools/bash.d.ts.map +1 -0
- package/dist/core/tools/bash.js +212 -0
- package/dist/core/tools/bash.js.map +1 -0
- package/dist/core/tools/edit-diff.d.ts +29 -0
- package/dist/core/tools/edit-diff.d.ts.map +1 -0
- package/dist/core/tools/edit-diff.js +182 -0
- package/dist/core/tools/edit-diff.js.map +1 -0
- package/dist/core/tools/edit.d.ts +28 -0
- package/dist/core/tools/edit.d.ts.map +1 -0
- package/dist/core/tools/edit.js +129 -0
- package/dist/core/tools/edit.js.map +1 -0
- package/dist/core/tools/fast-executor.d.ts +33 -0
- package/dist/core/tools/fast-executor.d.ts.map +1 -0
- package/dist/core/tools/fast-executor.js +83 -0
- package/dist/core/tools/fast-executor.js.map +1 -0
- package/dist/core/tools/find.d.ts +28 -0
- package/dist/core/tools/find.d.ts.map +1 -0
- package/dist/core/tools/find.js +50 -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 +233 -0
- package/dist/core/tools/grep.js.map +1 -0
- package/dist/core/tools/index.d.ts +63 -0
- package/dist/core/tools/index.d.ts.map +1 -0
- package/dist/core/tools/index.js +52 -0
- package/dist/core/tools/index.js.map +1 -0
- package/dist/core/tools/local-accelerator.d.ts +65 -0
- package/dist/core/tools/local-accelerator.d.ts.map +1 -0
- package/dist/core/tools/local-accelerator.js +198 -0
- package/dist/core/tools/local-accelerator.js.map +1 -0
- package/dist/core/tools/ls.d.ts +31 -0
- package/dist/core/tools/ls.d.ts.map +1 -0
- package/dist/core/tools/ls.js +109 -0
- package/dist/core/tools/ls.js.map +1 -0
- package/dist/core/tools/parallel-executor.d.ts +60 -0
- package/dist/core/tools/parallel-executor.d.ts.map +1 -0
- package/dist/core/tools/parallel-executor.js +257 -0
- package/dist/core/tools/parallel-executor.js.map +1 -0
- package/dist/core/tools/path-utils.d.ts +4 -0
- package/dist/core/tools/path-utils.d.ts.map +1 -0
- package/dist/core/tools/path-utils.js +70 -0
- package/dist/core/tools/path-utils.js.map +1 -0
- package/dist/core/tools/read.d.ts +29 -0
- package/dist/core/tools/read.d.ts.map +1 -0
- package/dist/core/tools/read.js +146 -0
- package/dist/core/tools/read.js.map +1 -0
- package/dist/core/tools/truncate.d.ts +28 -0
- package/dist/core/tools/truncate.d.ts.map +1 -0
- package/dist/core/tools/truncate.js +161 -0
- package/dist/core/tools/truncate.js.map +1 -0
- package/dist/core/tools/write.d.ts +21 -0
- package/dist/core/tools/write.d.ts.map +1 -0
- package/dist/core/tools/write.js +69 -0
- package/dist/core/tools/write.js.map +1 -0
- package/dist/core/user-config.d.ts +26 -0
- package/dist/core/user-config.d.ts.map +1 -0
- package/dist/core/user-config.js +75 -0
- package/dist/core/user-config.js.map +1 -0
- package/dist/index.d.ts +27 -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 +2 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +609 -0
- package/dist/main.js.map +1 -0
- package/dist/migrations.d.ts +8 -0
- package/dist/migrations.d.ts.map +1 -0
- package/dist/migrations.js +197 -0
- package/dist/migrations.js.map +1 -0
- package/dist/modes/index.d.ts +6 -0
- package/dist/modes/index.d.ts.map +1 -0
- package/dist/modes/index.js +5 -0
- package/dist/modes/index.js.map +1 -0
- package/dist/modes/interactive/components/armin.d.ts +31 -0
- package/dist/modes/interactive/components/armin.d.ts.map +1 -0
- package/dist/modes/interactive/components/armin.js +306 -0
- package/dist/modes/interactive/components/armin.js.map +1 -0
- package/dist/modes/interactive/components/assistant-message.d.ts +13 -0
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/assistant-message.js +82 -0
- package/dist/modes/interactive/components/assistant-message.js.map +1 -0
- package/dist/modes/interactive/components/bash-execution.d.ts +23 -0
- package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -0
- package/dist/modes/interactive/components/bash-execution.js +126 -0
- package/dist/modes/interactive/components/bash-execution.js.map +1 -0
- package/dist/modes/interactive/components/bordered-loader.d.ts +15 -0
- package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -0
- package/dist/modes/interactive/components/bordered-loader.js +50 -0
- package/dist/modes/interactive/components/bordered-loader.js.map +1 -0
- package/dist/modes/interactive/components/branch-summary-message.d.ts +12 -0
- package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/branch-summary-message.js +40 -0
- package/dist/modes/interactive/components/branch-summary-message.js.map +1 -0
- package/dist/modes/interactive/components/compaction-summary-message.d.ts +12 -0
- package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/compaction-summary-message.js +41 -0
- package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -0
- package/dist/modes/interactive/components/config-selector.d.ts +68 -0
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/config-selector.js +451 -0
- package/dist/modes/interactive/components/config-selector.js.map +1 -0
- package/dist/modes/interactive/components/countdown-timer.d.ts +11 -0
- package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -0
- package/dist/modes/interactive/components/countdown-timer.js +30 -0
- package/dist/modes/interactive/components/countdown-timer.js.map +1 -0
- package/dist/modes/interactive/components/custom-editor.d.ts +14 -0
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -0
- package/dist/modes/interactive/components/custom-editor.js +52 -0
- package/dist/modes/interactive/components/custom-editor.js.map +1 -0
- package/dist/modes/interactive/components/custom-message.d.ts +16 -0
- package/dist/modes/interactive/components/custom-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/custom-message.js +66 -0
- package/dist/modes/interactive/components/custom-message.js.map +1 -0
- package/dist/modes/interactive/components/daxnuts.d.ts +18 -0
- package/dist/modes/interactive/components/daxnuts.d.ts.map +1 -0
- package/dist/modes/interactive/components/daxnuts.js +130 -0
- package/dist/modes/interactive/components/daxnuts.js.map +1 -0
- package/dist/modes/interactive/components/diff.d.ts +5 -0
- package/dist/modes/interactive/components/diff.d.ts.map +1 -0
- package/dist/modes/interactive/components/diff.js +106 -0
- package/dist/modes/interactive/components/diff.js.map +1 -0
- package/dist/modes/interactive/components/dynamic-border.d.ts +8 -0
- package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -0
- package/dist/modes/interactive/components/dynamic-border.js +12 -0
- package/dist/modes/interactive/components/dynamic-border.js.map +1 -0
- package/dist/modes/interactive/components/extension-editor.d.ts +16 -0
- package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -0
- package/dist/modes/interactive/components/extension-editor.js +95 -0
- package/dist/modes/interactive/components/extension-editor.js.map +1 -0
- package/dist/modes/interactive/components/extension-input.d.ts +20 -0
- package/dist/modes/interactive/components/extension-input.d.ts.map +1 -0
- package/dist/modes/interactive/components/extension-input.js +57 -0
- package/dist/modes/interactive/components/extension-input.js.map +1 -0
- package/dist/modes/interactive/components/extension-selector.d.ts +20 -0
- package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/extension-selector.js +74 -0
- package/dist/modes/interactive/components/extension-selector.js.map +1 -0
- package/dist/modes/interactive/components/footer.d.ts +14 -0
- package/dist/modes/interactive/components/footer.d.ts.map +1 -0
- package/dist/modes/interactive/components/footer.js +78 -0
- package/dist/modes/interactive/components/footer.js.map +1 -0
- package/dist/modes/interactive/components/index.d.ts +28 -0
- package/dist/modes/interactive/components/index.d.ts.map +1 -0
- package/dist/modes/interactive/components/index.js +28 -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 +25 -0
- package/dist/modes/interactive/components/keybinding-hints.js.map +1 -0
- package/dist/modes/interactive/components/onboarding-wizard.d.ts +23 -0
- package/dist/modes/interactive/components/onboarding-wizard.d.ts.map +1 -0
- package/dist/modes/interactive/components/onboarding-wizard.js +250 -0
- package/dist/modes/interactive/components/onboarding-wizard.js.map +1 -0
- package/dist/modes/interactive/components/session-selector-search.d.ts +21 -0
- package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -0
- package/dist/modes/interactive/components/session-selector-search.js +149 -0
- package/dist/modes/interactive/components/session-selector-search.js.map +1 -0
- package/dist/modes/interactive/components/session-selector.d.ts +89 -0
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/session-selector.js +786 -0
- package/dist/modes/interactive/components/session-selector.js.map +1 -0
- package/dist/modes/interactive/components/settings-selector.d.ts +55 -0
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/settings-selector.js +273 -0
- package/dist/modes/interactive/components/settings-selector.js.map +1 -0
- package/dist/modes/interactive/components/show-images-selector.d.ts +7 -0
- package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/show-images-selector.js +28 -0
- package/dist/modes/interactive/components/show-images-selector.js.map +1 -0
- package/dist/modes/interactive/components/skill-invocation-message.d.ts +12 -0
- package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/skill-invocation-message.js +40 -0
- package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -0
- package/dist/modes/interactive/components/theme-selector.d.ts +8 -0
- package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/theme-selector.js +38 -0
- package/dist/modes/interactive/components/theme-selector.js.map +1 -0
- package/dist/modes/interactive/components/thinking-selector.d.ts +8 -0
- package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/thinking-selector.js +40 -0
- package/dist/modes/interactive/components/thinking-selector.js.map +1 -0
- package/dist/modes/interactive/components/tool-execution.d.ts +54 -0
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -0
- package/dist/modes/interactive/components/tool-execution.js +704 -0
- package/dist/modes/interactive/components/tool-execution.js.map +1 -0
- package/dist/modes/interactive/components/tree-selector.d.ts +59 -0
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/tree-selector.js +929 -0
- package/dist/modes/interactive/components/tree-selector.js.map +1 -0
- package/dist/modes/interactive/components/user-message-selector.d.ts +24 -0
- package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/user-message-selector.js +89 -0
- package/dist/modes/interactive/components/user-message-selector.js.map +1 -0
- package/dist/modes/interactive/components/user-message.d.ts +6 -0
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/user-message.js +24 -0
- package/dist/modes/interactive/components/user-message.js.map +1 -0
- package/dist/modes/interactive/components/visual-truncate.d.ts +6 -0
- package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -0
- package/dist/modes/interactive/components/visual-truncate.js +15 -0
- package/dist/modes/interactive/components/visual-truncate.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts +177 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-mode.js +3037 -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 +60 -0
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -0
- package/dist/modes/interactive/theme/theme.js +852 -0
- package/dist/modes/interactive/theme/theme.js.map +1 -0
- package/dist/modes/print-mode.d.ts +10 -0
- package/dist/modes/print-mode.d.ts.map +1 -0
- package/dist/modes/print-mode.js +80 -0
- package/dist/modes/print-mode.js.map +1 -0
- package/dist/modes/rpc/jsonl.d.ts +4 -0
- package/dist/modes/rpc/jsonl.d.ts.map +1 -0
- package/dist/modes/rpc/jsonl.js +36 -0
- package/dist/modes/rpc/jsonl.js.map +1 -0
- package/dist/modes/rpc/rpc-client.d.ts +94 -0
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-client.js +262 -0
- package/dist/modes/rpc/rpc-client.js.map +1 -0
- package/dist/modes/rpc/rpc-mode.d.ts +3 -0
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-mode.js +227 -0
- package/dist/modes/rpc/rpc-mode.js.map +1 -0
- package/dist/modes/rpc/rpc-types.d.ts +395 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-types.js +2 -0
- package/dist/modes/rpc/rpc-types.js.map +1 -0
- package/dist/utils/changelog.d.ts +11 -0
- package/dist/utils/changelog.d.ts.map +1 -0
- package/dist/utils/changelog.js +69 -0
- package/dist/utils/changelog.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 +157 -0
- package/dist/utils/clipboard-image.js.map +1 -0
- package/dist/utils/clipboard-native.d.ts +7 -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 +55 -0
- package/dist/utils/clipboard.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 +10 -0
- package/dist/utils/git.d.ts.map +1 -0
- package/dist/utils/git.js +156 -0
- package/dist/utils/git.js.map +1 -0
- package/dist/utils/image-convert.d.ts +5 -0
- package/dist/utils/image-convert.d.ts.map +1 -0
- package/dist/utils/image-convert.js +28 -0
- package/dist/utils/image-convert.js.map +1 -0
- package/dist/utils/image-resize.d.ts +19 -0
- package/dist/utils/image-resize.d.ts.map +1 -0
- package/dist/utils/image-resize.js +152 -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 +3 -0
- package/dist/utils/photon.d.ts.map +1 -0
- package/dist/utils/photon.js +102 -0
- package/dist/utils/photon.js.map +1 -0
- package/dist/utils/shell.d.ts +8 -0
- package/dist/utils/shell.d.ts.map +1 -0
- package/dist/utils/shell.js +135 -0
- package/dist/utils/shell.js.map +1 -0
- package/dist/utils/sleep.d.ts +2 -0
- package/dist/utils/sleep.d.ts.map +1 -0
- package/dist/utils/sleep.js +14 -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 +227 -0
- package/dist/utils/tools-manager.js.map +1 -0
- package/docs/compaction.md +392 -0
- package/docs/custom-provider.md +592 -0
- package/docs/development.md +69 -0
- package/docs/extensions.md +2023 -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 +79 -0
- package/docs/keybindings.md +182 -0
- package/docs/models.md +297 -0
- package/docs/packages.md +209 -0
- package/docs/prompt-templates.md +67 -0
- package/docs/providers.md +188 -0
- package/docs/rpc.md +1354 -0
- package/docs/sdk.md +968 -0
- package/docs/session.md +412 -0
- package/docs/settings.md +225 -0
- package/docs/shell-aliases.md +13 -0
- package/docs/skills.md +231 -0
- package/docs/terminal-setup.md +87 -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 +205 -0
- package/examples/extensions/antigravity-image-gen.ts +415 -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 +114 -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-lock.json +24 -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/custom-provider-qwen-cli/index.ts +345 -0
- package/examples/extensions/custom-provider-qwen-cli/package.json +16 -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 +150 -0
- package/examples/extensions/hello.ts +25 -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 +168 -0
- package/examples/extensions/preset.ts +398 -0
- package/examples/extensions/protected-paths.ts +30 -0
- package/examples/extensions/provider-payload.ts +14 -0
- package/examples/extensions/qna.ts +119 -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 +318 -0
- package/examples/extensions/sandbox/package-lock.json +92 -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 +964 -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 +195 -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 +143 -0
- package/examples/extensions/tools.ts +146 -0
- package/examples/extensions/trigger-compact.ts +40 -0
- package/examples/extensions/truncated-tool.ts +192 -0
- package/examples/extensions/widget-placement.ts +17 -0
- package/examples/extensions/with-deps/index.ts +32 -0
- package/examples/extensions/with-deps/package-lock.json +31 -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 +46 -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 +47 -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 +82 -0
- package/examples/sdk/README.md +144 -0
- package/package.json +100 -0
|
@@ -0,0 +1,1375 @@
|
|
|
1
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { homedir, tmpdir } from "node:os";
|
|
5
|
+
import { basename, dirname, join, relative, resolve, sep } from "node:path";
|
|
6
|
+
import ignore from "ignore";
|
|
7
|
+
import { minimatch } from "minimatch";
|
|
8
|
+
import { CONFIG_DIR_NAME } from "../config.js";
|
|
9
|
+
import { parseGitUrl } from "../utils/git.js";
|
|
10
|
+
const NETWORK_TIMEOUT_MS = 10000;
|
|
11
|
+
function isOfflineModeEnabled() {
|
|
12
|
+
const value = process.env.PI_OFFLINE;
|
|
13
|
+
if (!value)
|
|
14
|
+
return false;
|
|
15
|
+
return value === "1" || value.toLowerCase() === "true" || value.toLowerCase() === "yes";
|
|
16
|
+
}
|
|
17
|
+
const RESOURCE_TYPES = ["extensions", "skills", "prompts", "themes"];
|
|
18
|
+
const FILE_PATTERNS = {
|
|
19
|
+
extensions: /\.(ts|js)$/,
|
|
20
|
+
skills: /\.md$/,
|
|
21
|
+
prompts: /\.md$/,
|
|
22
|
+
themes: /\.json$/,
|
|
23
|
+
};
|
|
24
|
+
const IGNORE_FILE_NAMES = [".gitignore", ".ignore", ".fdignore"];
|
|
25
|
+
function toPosixPath(p) {
|
|
26
|
+
return p.split(sep).join("/");
|
|
27
|
+
}
|
|
28
|
+
function prefixIgnorePattern(line, prefix) {
|
|
29
|
+
const trimmed = line.trim();
|
|
30
|
+
if (!trimmed)
|
|
31
|
+
return null;
|
|
32
|
+
if (trimmed.startsWith("#") && !trimmed.startsWith("\\#"))
|
|
33
|
+
return null;
|
|
34
|
+
let pattern = line;
|
|
35
|
+
let negated = false;
|
|
36
|
+
if (pattern.startsWith("!")) {
|
|
37
|
+
negated = true;
|
|
38
|
+
pattern = pattern.slice(1);
|
|
39
|
+
}
|
|
40
|
+
else if (pattern.startsWith("\\!")) {
|
|
41
|
+
pattern = pattern.slice(1);
|
|
42
|
+
}
|
|
43
|
+
if (pattern.startsWith("/")) {
|
|
44
|
+
pattern = pattern.slice(1);
|
|
45
|
+
}
|
|
46
|
+
const prefixed = prefix ? `${prefix}${pattern}` : pattern;
|
|
47
|
+
return negated ? `!${prefixed}` : prefixed;
|
|
48
|
+
}
|
|
49
|
+
function addIgnoreRules(ig, dir, rootDir) {
|
|
50
|
+
const relativeDir = relative(rootDir, dir);
|
|
51
|
+
const prefix = relativeDir ? `${toPosixPath(relativeDir)}/` : "";
|
|
52
|
+
for (const filename of IGNORE_FILE_NAMES) {
|
|
53
|
+
const ignorePath = join(dir, filename);
|
|
54
|
+
if (!existsSync(ignorePath))
|
|
55
|
+
continue;
|
|
56
|
+
try {
|
|
57
|
+
const content = readFileSync(ignorePath, "utf-8");
|
|
58
|
+
const patterns = content
|
|
59
|
+
.split(/\r?\n/)
|
|
60
|
+
.map((line) => prefixIgnorePattern(line, prefix))
|
|
61
|
+
.filter((line) => Boolean(line));
|
|
62
|
+
if (patterns.length > 0) {
|
|
63
|
+
ig.add(patterns);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch { }
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function isPattern(s) {
|
|
70
|
+
return s.startsWith("!") || s.startsWith("+") || s.startsWith("-") || s.includes("*") || s.includes("?");
|
|
71
|
+
}
|
|
72
|
+
function splitPatterns(entries) {
|
|
73
|
+
const plain = [];
|
|
74
|
+
const patterns = [];
|
|
75
|
+
for (const entry of entries) {
|
|
76
|
+
if (isPattern(entry)) {
|
|
77
|
+
patterns.push(entry);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
plain.push(entry);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return { plain, patterns };
|
|
84
|
+
}
|
|
85
|
+
function collectFiles(dir, filePattern, skipNodeModules = true, ignoreMatcher, rootDir) {
|
|
86
|
+
const files = [];
|
|
87
|
+
if (!existsSync(dir))
|
|
88
|
+
return files;
|
|
89
|
+
const root = rootDir ?? dir;
|
|
90
|
+
const ig = ignoreMatcher ?? ignore();
|
|
91
|
+
addIgnoreRules(ig, dir, root);
|
|
92
|
+
try {
|
|
93
|
+
const entries = readdirSync(dir, { withFileTypes: true });
|
|
94
|
+
for (const entry of entries) {
|
|
95
|
+
if (entry.name.startsWith("."))
|
|
96
|
+
continue;
|
|
97
|
+
if (skipNodeModules && entry.name === "node_modules")
|
|
98
|
+
continue;
|
|
99
|
+
const fullPath = join(dir, entry.name);
|
|
100
|
+
let isDir = entry.isDirectory();
|
|
101
|
+
let isFile = entry.isFile();
|
|
102
|
+
if (entry.isSymbolicLink()) {
|
|
103
|
+
try {
|
|
104
|
+
const stats = statSync(fullPath);
|
|
105
|
+
isDir = stats.isDirectory();
|
|
106
|
+
isFile = stats.isFile();
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const relPath = toPosixPath(relative(root, fullPath));
|
|
113
|
+
const ignorePath = isDir ? `${relPath}/` : relPath;
|
|
114
|
+
if (ig.ignores(ignorePath))
|
|
115
|
+
continue;
|
|
116
|
+
if (isDir) {
|
|
117
|
+
files.push(...collectFiles(fullPath, filePattern, skipNodeModules, ig, root));
|
|
118
|
+
}
|
|
119
|
+
else if (isFile && filePattern.test(entry.name)) {
|
|
120
|
+
files.push(fullPath);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
catch { }
|
|
125
|
+
return files;
|
|
126
|
+
}
|
|
127
|
+
function collectSkillEntries(dir, includeRootFiles = true, ignoreMatcher, rootDir) {
|
|
128
|
+
const entries = [];
|
|
129
|
+
if (!existsSync(dir))
|
|
130
|
+
return entries;
|
|
131
|
+
const root = rootDir ?? dir;
|
|
132
|
+
const ig = ignoreMatcher ?? ignore();
|
|
133
|
+
addIgnoreRules(ig, dir, root);
|
|
134
|
+
try {
|
|
135
|
+
const dirEntries = readdirSync(dir, { withFileTypes: true });
|
|
136
|
+
for (const entry of dirEntries) {
|
|
137
|
+
if (entry.name.startsWith("."))
|
|
138
|
+
continue;
|
|
139
|
+
if (entry.name === "node_modules")
|
|
140
|
+
continue;
|
|
141
|
+
const fullPath = join(dir, entry.name);
|
|
142
|
+
let isDir = entry.isDirectory();
|
|
143
|
+
let isFile = entry.isFile();
|
|
144
|
+
if (entry.isSymbolicLink()) {
|
|
145
|
+
try {
|
|
146
|
+
const stats = statSync(fullPath);
|
|
147
|
+
isDir = stats.isDirectory();
|
|
148
|
+
isFile = stats.isFile();
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const relPath = toPosixPath(relative(root, fullPath));
|
|
155
|
+
const ignorePath = isDir ? `${relPath}/` : relPath;
|
|
156
|
+
if (ig.ignores(ignorePath))
|
|
157
|
+
continue;
|
|
158
|
+
if (isDir) {
|
|
159
|
+
entries.push(...collectSkillEntries(fullPath, false, ig, root));
|
|
160
|
+
}
|
|
161
|
+
else if (isFile) {
|
|
162
|
+
const isRootMd = includeRootFiles && entry.name.endsWith(".md");
|
|
163
|
+
const isSkillMd = !includeRootFiles && entry.name === "SKILL.md";
|
|
164
|
+
if (isRootMd || isSkillMd) {
|
|
165
|
+
entries.push(fullPath);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
catch { }
|
|
171
|
+
return entries;
|
|
172
|
+
}
|
|
173
|
+
function collectAutoSkillEntries(dir, includeRootFiles = true) {
|
|
174
|
+
return collectSkillEntries(dir, includeRootFiles);
|
|
175
|
+
}
|
|
176
|
+
function findGitRepoRoot(startDir) {
|
|
177
|
+
let dir = resolve(startDir);
|
|
178
|
+
while (true) {
|
|
179
|
+
if (existsSync(join(dir, ".git"))) {
|
|
180
|
+
return dir;
|
|
181
|
+
}
|
|
182
|
+
const parent = dirname(dir);
|
|
183
|
+
if (parent === dir) {
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
dir = parent;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
function collectAncestorAgentsSkillDirs(startDir) {
|
|
190
|
+
const skillDirs = [];
|
|
191
|
+
const resolvedStartDir = resolve(startDir);
|
|
192
|
+
const gitRepoRoot = findGitRepoRoot(resolvedStartDir);
|
|
193
|
+
let dir = resolvedStartDir;
|
|
194
|
+
while (true) {
|
|
195
|
+
skillDirs.push(join(dir, ".agents", "skills"));
|
|
196
|
+
if (gitRepoRoot && dir === gitRepoRoot) {
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
const parent = dirname(dir);
|
|
200
|
+
if (parent === dir) {
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
dir = parent;
|
|
204
|
+
}
|
|
205
|
+
return skillDirs;
|
|
206
|
+
}
|
|
207
|
+
function collectAutoPromptEntries(dir) {
|
|
208
|
+
const entries = [];
|
|
209
|
+
if (!existsSync(dir))
|
|
210
|
+
return entries;
|
|
211
|
+
const ig = ignore();
|
|
212
|
+
addIgnoreRules(ig, dir, dir);
|
|
213
|
+
try {
|
|
214
|
+
const dirEntries = readdirSync(dir, { withFileTypes: true });
|
|
215
|
+
for (const entry of dirEntries) {
|
|
216
|
+
if (entry.name.startsWith("."))
|
|
217
|
+
continue;
|
|
218
|
+
if (entry.name === "node_modules")
|
|
219
|
+
continue;
|
|
220
|
+
const fullPath = join(dir, entry.name);
|
|
221
|
+
let isFile = entry.isFile();
|
|
222
|
+
if (entry.isSymbolicLink()) {
|
|
223
|
+
try {
|
|
224
|
+
isFile = statSync(fullPath).isFile();
|
|
225
|
+
}
|
|
226
|
+
catch {
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
const relPath = toPosixPath(relative(dir, fullPath));
|
|
231
|
+
if (ig.ignores(relPath))
|
|
232
|
+
continue;
|
|
233
|
+
if (isFile && entry.name.endsWith(".md")) {
|
|
234
|
+
entries.push(fullPath);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
catch { }
|
|
239
|
+
return entries;
|
|
240
|
+
}
|
|
241
|
+
function collectAutoThemeEntries(dir) {
|
|
242
|
+
const entries = [];
|
|
243
|
+
if (!existsSync(dir))
|
|
244
|
+
return entries;
|
|
245
|
+
const ig = ignore();
|
|
246
|
+
addIgnoreRules(ig, dir, dir);
|
|
247
|
+
try {
|
|
248
|
+
const dirEntries = readdirSync(dir, { withFileTypes: true });
|
|
249
|
+
for (const entry of dirEntries) {
|
|
250
|
+
if (entry.name.startsWith("."))
|
|
251
|
+
continue;
|
|
252
|
+
if (entry.name === "node_modules")
|
|
253
|
+
continue;
|
|
254
|
+
const fullPath = join(dir, entry.name);
|
|
255
|
+
let isFile = entry.isFile();
|
|
256
|
+
if (entry.isSymbolicLink()) {
|
|
257
|
+
try {
|
|
258
|
+
isFile = statSync(fullPath).isFile();
|
|
259
|
+
}
|
|
260
|
+
catch {
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
const relPath = toPosixPath(relative(dir, fullPath));
|
|
265
|
+
if (ig.ignores(relPath))
|
|
266
|
+
continue;
|
|
267
|
+
if (isFile && entry.name.endsWith(".json")) {
|
|
268
|
+
entries.push(fullPath);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
catch { }
|
|
273
|
+
return entries;
|
|
274
|
+
}
|
|
275
|
+
function readPiManifestFile(packageJsonPath) {
|
|
276
|
+
try {
|
|
277
|
+
const content = readFileSync(packageJsonPath, "utf-8");
|
|
278
|
+
const pkg = JSON.parse(content);
|
|
279
|
+
return pkg.pi ?? null;
|
|
280
|
+
}
|
|
281
|
+
catch {
|
|
282
|
+
return null;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
function resolveExtensionEntries(dir) {
|
|
286
|
+
const packageJsonPath = join(dir, "package.json");
|
|
287
|
+
if (existsSync(packageJsonPath)) {
|
|
288
|
+
const manifest = readPiManifestFile(packageJsonPath);
|
|
289
|
+
if (manifest?.extensions?.length) {
|
|
290
|
+
const entries = [];
|
|
291
|
+
for (const extPath of manifest.extensions) {
|
|
292
|
+
const resolvedExtPath = resolve(dir, extPath);
|
|
293
|
+
if (existsSync(resolvedExtPath)) {
|
|
294
|
+
entries.push(resolvedExtPath);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
if (entries.length > 0) {
|
|
298
|
+
return entries;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
const indexTs = join(dir, "index.ts");
|
|
303
|
+
const indexJs = join(dir, "index.js");
|
|
304
|
+
if (existsSync(indexTs)) {
|
|
305
|
+
return [indexTs];
|
|
306
|
+
}
|
|
307
|
+
if (existsSync(indexJs)) {
|
|
308
|
+
return [indexJs];
|
|
309
|
+
}
|
|
310
|
+
return null;
|
|
311
|
+
}
|
|
312
|
+
function collectAutoExtensionEntries(dir) {
|
|
313
|
+
const entries = [];
|
|
314
|
+
if (!existsSync(dir))
|
|
315
|
+
return entries;
|
|
316
|
+
const rootEntries = resolveExtensionEntries(dir);
|
|
317
|
+
if (rootEntries) {
|
|
318
|
+
return rootEntries;
|
|
319
|
+
}
|
|
320
|
+
const ig = ignore();
|
|
321
|
+
addIgnoreRules(ig, dir, dir);
|
|
322
|
+
try {
|
|
323
|
+
const dirEntries = readdirSync(dir, { withFileTypes: true });
|
|
324
|
+
for (const entry of dirEntries) {
|
|
325
|
+
if (entry.name.startsWith("."))
|
|
326
|
+
continue;
|
|
327
|
+
if (entry.name === "node_modules")
|
|
328
|
+
continue;
|
|
329
|
+
const fullPath = join(dir, entry.name);
|
|
330
|
+
let isDir = entry.isDirectory();
|
|
331
|
+
let isFile = entry.isFile();
|
|
332
|
+
if (entry.isSymbolicLink()) {
|
|
333
|
+
try {
|
|
334
|
+
const stats = statSync(fullPath);
|
|
335
|
+
isDir = stats.isDirectory();
|
|
336
|
+
isFile = stats.isFile();
|
|
337
|
+
}
|
|
338
|
+
catch {
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
const relPath = toPosixPath(relative(dir, fullPath));
|
|
343
|
+
const ignorePath = isDir ? `${relPath}/` : relPath;
|
|
344
|
+
if (ig.ignores(ignorePath))
|
|
345
|
+
continue;
|
|
346
|
+
if (isFile && (entry.name.endsWith(".ts") || entry.name.endsWith(".js"))) {
|
|
347
|
+
entries.push(fullPath);
|
|
348
|
+
}
|
|
349
|
+
else if (isDir) {
|
|
350
|
+
const resolvedEntries = resolveExtensionEntries(fullPath);
|
|
351
|
+
if (resolvedEntries) {
|
|
352
|
+
entries.push(...resolvedEntries);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
catch { }
|
|
358
|
+
return entries;
|
|
359
|
+
}
|
|
360
|
+
function collectResourceFiles(dir, resourceType) {
|
|
361
|
+
if (resourceType === "skills") {
|
|
362
|
+
return collectSkillEntries(dir);
|
|
363
|
+
}
|
|
364
|
+
if (resourceType === "extensions") {
|
|
365
|
+
return collectAutoExtensionEntries(dir);
|
|
366
|
+
}
|
|
367
|
+
return collectFiles(dir, FILE_PATTERNS[resourceType]);
|
|
368
|
+
}
|
|
369
|
+
function matchesAnyPattern(filePath, patterns, baseDir) {
|
|
370
|
+
const rel = relative(baseDir, filePath);
|
|
371
|
+
const name = basename(filePath);
|
|
372
|
+
const isSkillFile = name === "SKILL.md";
|
|
373
|
+
const parentDir = isSkillFile ? dirname(filePath) : undefined;
|
|
374
|
+
const parentRel = isSkillFile ? relative(baseDir, parentDir) : undefined;
|
|
375
|
+
const parentName = isSkillFile ? basename(parentDir) : undefined;
|
|
376
|
+
return patterns.some((pattern) => {
|
|
377
|
+
if (minimatch(rel, pattern) || minimatch(name, pattern) || minimatch(filePath, pattern)) {
|
|
378
|
+
return true;
|
|
379
|
+
}
|
|
380
|
+
if (!isSkillFile)
|
|
381
|
+
return false;
|
|
382
|
+
return minimatch(parentRel, pattern) || minimatch(parentName, pattern) || minimatch(parentDir, pattern);
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
function normalizeExactPattern(pattern) {
|
|
386
|
+
if (pattern.startsWith("./") || pattern.startsWith(".\\")) {
|
|
387
|
+
return pattern.slice(2);
|
|
388
|
+
}
|
|
389
|
+
return pattern;
|
|
390
|
+
}
|
|
391
|
+
function matchesAnyExactPattern(filePath, patterns, baseDir) {
|
|
392
|
+
if (patterns.length === 0)
|
|
393
|
+
return false;
|
|
394
|
+
const rel = relative(baseDir, filePath);
|
|
395
|
+
const name = basename(filePath);
|
|
396
|
+
const isSkillFile = name === "SKILL.md";
|
|
397
|
+
const parentDir = isSkillFile ? dirname(filePath) : undefined;
|
|
398
|
+
const parentRel = isSkillFile ? relative(baseDir, parentDir) : undefined;
|
|
399
|
+
return patterns.some((pattern) => {
|
|
400
|
+
const normalized = normalizeExactPattern(pattern);
|
|
401
|
+
if (normalized === rel || normalized === filePath) {
|
|
402
|
+
return true;
|
|
403
|
+
}
|
|
404
|
+
if (!isSkillFile)
|
|
405
|
+
return false;
|
|
406
|
+
return normalized === parentRel || normalized === parentDir;
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
function getOverridePatterns(entries) {
|
|
410
|
+
return entries.filter((pattern) => pattern.startsWith("!") || pattern.startsWith("+") || pattern.startsWith("-"));
|
|
411
|
+
}
|
|
412
|
+
function isEnabledByOverrides(filePath, patterns, baseDir) {
|
|
413
|
+
const overrides = getOverridePatterns(patterns);
|
|
414
|
+
const excludes = overrides.filter((pattern) => pattern.startsWith("!")).map((pattern) => pattern.slice(1));
|
|
415
|
+
const forceIncludes = overrides.filter((pattern) => pattern.startsWith("+")).map((pattern) => pattern.slice(1));
|
|
416
|
+
const forceExcludes = overrides.filter((pattern) => pattern.startsWith("-")).map((pattern) => pattern.slice(1));
|
|
417
|
+
let enabled = true;
|
|
418
|
+
if (excludes.length > 0 && matchesAnyPattern(filePath, excludes, baseDir)) {
|
|
419
|
+
enabled = false;
|
|
420
|
+
}
|
|
421
|
+
if (forceIncludes.length > 0 && matchesAnyExactPattern(filePath, forceIncludes, baseDir)) {
|
|
422
|
+
enabled = true;
|
|
423
|
+
}
|
|
424
|
+
if (forceExcludes.length > 0 && matchesAnyExactPattern(filePath, forceExcludes, baseDir)) {
|
|
425
|
+
enabled = false;
|
|
426
|
+
}
|
|
427
|
+
return enabled;
|
|
428
|
+
}
|
|
429
|
+
function applyPatterns(allPaths, patterns, baseDir) {
|
|
430
|
+
const includes = [];
|
|
431
|
+
const excludes = [];
|
|
432
|
+
const forceIncludes = [];
|
|
433
|
+
const forceExcludes = [];
|
|
434
|
+
for (const p of patterns) {
|
|
435
|
+
if (p.startsWith("+")) {
|
|
436
|
+
forceIncludes.push(p.slice(1));
|
|
437
|
+
}
|
|
438
|
+
else if (p.startsWith("-")) {
|
|
439
|
+
forceExcludes.push(p.slice(1));
|
|
440
|
+
}
|
|
441
|
+
else if (p.startsWith("!")) {
|
|
442
|
+
excludes.push(p.slice(1));
|
|
443
|
+
}
|
|
444
|
+
else {
|
|
445
|
+
includes.push(p);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
let result;
|
|
449
|
+
if (includes.length === 0) {
|
|
450
|
+
result = [...allPaths];
|
|
451
|
+
}
|
|
452
|
+
else {
|
|
453
|
+
result = allPaths.filter((filePath) => matchesAnyPattern(filePath, includes, baseDir));
|
|
454
|
+
}
|
|
455
|
+
if (excludes.length > 0) {
|
|
456
|
+
result = result.filter((filePath) => !matchesAnyPattern(filePath, excludes, baseDir));
|
|
457
|
+
}
|
|
458
|
+
if (forceIncludes.length > 0) {
|
|
459
|
+
for (const filePath of allPaths) {
|
|
460
|
+
if (!result.includes(filePath) && matchesAnyExactPattern(filePath, forceIncludes, baseDir)) {
|
|
461
|
+
result.push(filePath);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
if (forceExcludes.length > 0) {
|
|
466
|
+
result = result.filter((filePath) => !matchesAnyExactPattern(filePath, forceExcludes, baseDir));
|
|
467
|
+
}
|
|
468
|
+
return new Set(result);
|
|
469
|
+
}
|
|
470
|
+
export class DefaultPackageManager {
|
|
471
|
+
cwd;
|
|
472
|
+
agentDir;
|
|
473
|
+
settingsManager;
|
|
474
|
+
globalNpmRoot;
|
|
475
|
+
progressCallback;
|
|
476
|
+
constructor(options) {
|
|
477
|
+
this.cwd = options.cwd;
|
|
478
|
+
this.agentDir = options.agentDir;
|
|
479
|
+
this.settingsManager = options.settingsManager;
|
|
480
|
+
}
|
|
481
|
+
setProgressCallback(callback) {
|
|
482
|
+
this.progressCallback = callback;
|
|
483
|
+
}
|
|
484
|
+
addSourceToSettings(source, options) {
|
|
485
|
+
const scope = options?.local ? "project" : "user";
|
|
486
|
+
const currentSettings = scope === "project" ? this.settingsManager.getProjectSettings() : this.settingsManager.getGlobalSettings();
|
|
487
|
+
const currentPackages = currentSettings.packages ?? [];
|
|
488
|
+
const normalizedSource = this.normalizePackageSourceForSettings(source, scope);
|
|
489
|
+
const exists = currentPackages.some((existing) => this.packageSourcesMatch(existing, source, scope));
|
|
490
|
+
if (exists) {
|
|
491
|
+
return false;
|
|
492
|
+
}
|
|
493
|
+
const nextPackages = [...currentPackages, normalizedSource];
|
|
494
|
+
if (scope === "project") {
|
|
495
|
+
this.settingsManager.setProjectPackages(nextPackages);
|
|
496
|
+
}
|
|
497
|
+
else {
|
|
498
|
+
this.settingsManager.setPackages(nextPackages);
|
|
499
|
+
}
|
|
500
|
+
return true;
|
|
501
|
+
}
|
|
502
|
+
removeSourceFromSettings(source, options) {
|
|
503
|
+
const scope = options?.local ? "project" : "user";
|
|
504
|
+
const currentSettings = scope === "project" ? this.settingsManager.getProjectSettings() : this.settingsManager.getGlobalSettings();
|
|
505
|
+
const currentPackages = currentSettings.packages ?? [];
|
|
506
|
+
const nextPackages = currentPackages.filter((existing) => !this.packageSourcesMatch(existing, source, scope));
|
|
507
|
+
const changed = nextPackages.length !== currentPackages.length;
|
|
508
|
+
if (!changed) {
|
|
509
|
+
return false;
|
|
510
|
+
}
|
|
511
|
+
if (scope === "project") {
|
|
512
|
+
this.settingsManager.setProjectPackages(nextPackages);
|
|
513
|
+
}
|
|
514
|
+
else {
|
|
515
|
+
this.settingsManager.setPackages(nextPackages);
|
|
516
|
+
}
|
|
517
|
+
return true;
|
|
518
|
+
}
|
|
519
|
+
getInstalledPath(source, scope) {
|
|
520
|
+
const parsed = this.parseSource(source);
|
|
521
|
+
if (parsed.type === "npm") {
|
|
522
|
+
const path = this.getNpmInstallPath(parsed, scope);
|
|
523
|
+
return existsSync(path) ? path : undefined;
|
|
524
|
+
}
|
|
525
|
+
if (parsed.type === "git") {
|
|
526
|
+
const path = this.getGitInstallPath(parsed, scope);
|
|
527
|
+
return existsSync(path) ? path : undefined;
|
|
528
|
+
}
|
|
529
|
+
if (parsed.type === "local") {
|
|
530
|
+
const baseDir = this.getBaseDirForScope(scope);
|
|
531
|
+
const path = this.resolvePathFromBase(parsed.path, baseDir);
|
|
532
|
+
return existsSync(path) ? path : undefined;
|
|
533
|
+
}
|
|
534
|
+
return undefined;
|
|
535
|
+
}
|
|
536
|
+
emitProgress(event) {
|
|
537
|
+
this.progressCallback?.(event);
|
|
538
|
+
}
|
|
539
|
+
async withProgress(action, source, message, operation) {
|
|
540
|
+
this.emitProgress({ type: "start", action, source, message });
|
|
541
|
+
try {
|
|
542
|
+
await operation();
|
|
543
|
+
this.emitProgress({ type: "complete", action, source });
|
|
544
|
+
}
|
|
545
|
+
catch (error) {
|
|
546
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
547
|
+
this.emitProgress({ type: "error", action, source, message: errorMessage });
|
|
548
|
+
throw error;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
async resolve(onMissing) {
|
|
552
|
+
const accumulator = this.createAccumulator();
|
|
553
|
+
const globalSettings = this.settingsManager.getGlobalSettings();
|
|
554
|
+
const projectSettings = this.settingsManager.getProjectSettings();
|
|
555
|
+
const allPackages = [];
|
|
556
|
+
for (const pkg of projectSettings.packages ?? []) {
|
|
557
|
+
allPackages.push({ pkg, scope: "project" });
|
|
558
|
+
}
|
|
559
|
+
for (const pkg of globalSettings.packages ?? []) {
|
|
560
|
+
allPackages.push({ pkg, scope: "user" });
|
|
561
|
+
}
|
|
562
|
+
const packageSources = this.dedupePackages(allPackages);
|
|
563
|
+
await this.resolvePackageSources(packageSources, accumulator, onMissing);
|
|
564
|
+
const globalBaseDir = this.agentDir;
|
|
565
|
+
const projectBaseDir = join(this.cwd, CONFIG_DIR_NAME);
|
|
566
|
+
for (const resourceType of RESOURCE_TYPES) {
|
|
567
|
+
const target = this.getTargetMap(accumulator, resourceType);
|
|
568
|
+
const globalEntries = (globalSettings[resourceType] ?? []);
|
|
569
|
+
const projectEntries = (projectSettings[resourceType] ?? []);
|
|
570
|
+
this.resolveLocalEntries(projectEntries, resourceType, target, {
|
|
571
|
+
source: "local",
|
|
572
|
+
scope: "project",
|
|
573
|
+
origin: "top-level",
|
|
574
|
+
}, projectBaseDir);
|
|
575
|
+
this.resolveLocalEntries(globalEntries, resourceType, target, {
|
|
576
|
+
source: "local",
|
|
577
|
+
scope: "user",
|
|
578
|
+
origin: "top-level",
|
|
579
|
+
}, globalBaseDir);
|
|
580
|
+
}
|
|
581
|
+
this.addAutoDiscoveredResources(accumulator, globalSettings, projectSettings, globalBaseDir, projectBaseDir);
|
|
582
|
+
return this.toResolvedPaths(accumulator);
|
|
583
|
+
}
|
|
584
|
+
async resolveExtensionSources(sources, options) {
|
|
585
|
+
const accumulator = this.createAccumulator();
|
|
586
|
+
const scope = options?.temporary ? "temporary" : options?.local ? "project" : "user";
|
|
587
|
+
const packageSources = sources.map((source) => ({ pkg: source, scope }));
|
|
588
|
+
await this.resolvePackageSources(packageSources, accumulator);
|
|
589
|
+
return this.toResolvedPaths(accumulator);
|
|
590
|
+
}
|
|
591
|
+
async install(source, options) {
|
|
592
|
+
const parsed = this.parseSource(source);
|
|
593
|
+
const scope = options?.local ? "project" : "user";
|
|
594
|
+
await this.withProgress("install", source, `Installing ${source}...`, async () => {
|
|
595
|
+
if (parsed.type === "npm") {
|
|
596
|
+
await this.installNpm(parsed, scope, false);
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
599
|
+
if (parsed.type === "git") {
|
|
600
|
+
await this.installGit(parsed, scope);
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
if (parsed.type === "local") {
|
|
604
|
+
const resolved = this.resolvePath(parsed.path);
|
|
605
|
+
if (!existsSync(resolved)) {
|
|
606
|
+
throw new Error(`Path does not exist: ${resolved}`);
|
|
607
|
+
}
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
throw new Error(`Unsupported install source: ${source}`);
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
async remove(source, options) {
|
|
614
|
+
const parsed = this.parseSource(source);
|
|
615
|
+
const scope = options?.local ? "project" : "user";
|
|
616
|
+
await this.withProgress("remove", source, `Removing ${source}...`, async () => {
|
|
617
|
+
if (parsed.type === "npm") {
|
|
618
|
+
await this.uninstallNpm(parsed, scope);
|
|
619
|
+
return;
|
|
620
|
+
}
|
|
621
|
+
if (parsed.type === "git") {
|
|
622
|
+
await this.removeGit(parsed, scope);
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
if (parsed.type === "local") {
|
|
626
|
+
return;
|
|
627
|
+
}
|
|
628
|
+
throw new Error(`Unsupported remove source: ${source}`);
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
async update(source) {
|
|
632
|
+
const globalSettings = this.settingsManager.getGlobalSettings();
|
|
633
|
+
const projectSettings = this.settingsManager.getProjectSettings();
|
|
634
|
+
const identity = source ? this.getPackageIdentity(source) : undefined;
|
|
635
|
+
for (const pkg of globalSettings.packages ?? []) {
|
|
636
|
+
const sourceStr = typeof pkg === "string" ? pkg : pkg.source;
|
|
637
|
+
if (identity && this.getPackageIdentity(sourceStr, "user") !== identity)
|
|
638
|
+
continue;
|
|
639
|
+
await this.updateSourceForScope(sourceStr, "user");
|
|
640
|
+
}
|
|
641
|
+
for (const pkg of projectSettings.packages ?? []) {
|
|
642
|
+
const sourceStr = typeof pkg === "string" ? pkg : pkg.source;
|
|
643
|
+
if (identity && this.getPackageIdentity(sourceStr, "project") !== identity)
|
|
644
|
+
continue;
|
|
645
|
+
await this.updateSourceForScope(sourceStr, "project");
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
async updateSourceForScope(source, scope) {
|
|
649
|
+
if (isOfflineModeEnabled()) {
|
|
650
|
+
return;
|
|
651
|
+
}
|
|
652
|
+
const parsed = this.parseSource(source);
|
|
653
|
+
if (parsed.type === "npm") {
|
|
654
|
+
if (parsed.pinned)
|
|
655
|
+
return;
|
|
656
|
+
await this.withProgress("update", source, `Updating ${source}...`, async () => {
|
|
657
|
+
await this.installNpm(parsed, scope, false);
|
|
658
|
+
});
|
|
659
|
+
return;
|
|
660
|
+
}
|
|
661
|
+
if (parsed.type === "git") {
|
|
662
|
+
if (parsed.pinned)
|
|
663
|
+
return;
|
|
664
|
+
await this.withProgress("update", source, `Updating ${source}...`, async () => {
|
|
665
|
+
await this.updateGit(parsed, scope);
|
|
666
|
+
});
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
async resolvePackageSources(sources, accumulator, onMissing) {
|
|
671
|
+
for (const { pkg, scope } of sources) {
|
|
672
|
+
const sourceStr = typeof pkg === "string" ? pkg : pkg.source;
|
|
673
|
+
const filter = typeof pkg === "object" ? pkg : undefined;
|
|
674
|
+
const parsed = this.parseSource(sourceStr);
|
|
675
|
+
const metadata = { source: sourceStr, scope, origin: "package" };
|
|
676
|
+
if (parsed.type === "local") {
|
|
677
|
+
const baseDir = this.getBaseDirForScope(scope);
|
|
678
|
+
this.resolveLocalExtensionSource(parsed, accumulator, filter, metadata, baseDir);
|
|
679
|
+
continue;
|
|
680
|
+
}
|
|
681
|
+
const installMissing = async () => {
|
|
682
|
+
if (isOfflineModeEnabled()) {
|
|
683
|
+
return false;
|
|
684
|
+
}
|
|
685
|
+
if (!onMissing) {
|
|
686
|
+
await this.installParsedSource(parsed, scope);
|
|
687
|
+
return true;
|
|
688
|
+
}
|
|
689
|
+
const action = await onMissing(sourceStr);
|
|
690
|
+
if (action === "skip")
|
|
691
|
+
return false;
|
|
692
|
+
if (action === "error")
|
|
693
|
+
throw new Error(`Missing source: ${sourceStr}`);
|
|
694
|
+
await this.installParsedSource(parsed, scope);
|
|
695
|
+
return true;
|
|
696
|
+
};
|
|
697
|
+
if (parsed.type === "npm") {
|
|
698
|
+
const installedPath = this.getNpmInstallPath(parsed, scope);
|
|
699
|
+
const needsInstall = !existsSync(installedPath) || (await this.npmNeedsUpdate(parsed, installedPath));
|
|
700
|
+
if (needsInstall) {
|
|
701
|
+
const installed = await installMissing();
|
|
702
|
+
if (!installed)
|
|
703
|
+
continue;
|
|
704
|
+
}
|
|
705
|
+
metadata.baseDir = installedPath;
|
|
706
|
+
this.collectPackageResources(installedPath, accumulator, filter, metadata);
|
|
707
|
+
continue;
|
|
708
|
+
}
|
|
709
|
+
if (parsed.type === "git") {
|
|
710
|
+
const installedPath = this.getGitInstallPath(parsed, scope);
|
|
711
|
+
if (!existsSync(installedPath)) {
|
|
712
|
+
const installed = await installMissing();
|
|
713
|
+
if (!installed)
|
|
714
|
+
continue;
|
|
715
|
+
}
|
|
716
|
+
else if (scope === "temporary" && !parsed.pinned && !isOfflineModeEnabled()) {
|
|
717
|
+
await this.refreshTemporaryGitSource(parsed, sourceStr);
|
|
718
|
+
}
|
|
719
|
+
metadata.baseDir = installedPath;
|
|
720
|
+
this.collectPackageResources(installedPath, accumulator, filter, metadata);
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
resolveLocalExtensionSource(source, accumulator, filter, metadata, baseDir) {
|
|
725
|
+
const resolved = this.resolvePathFromBase(source.path, baseDir);
|
|
726
|
+
if (!existsSync(resolved)) {
|
|
727
|
+
return;
|
|
728
|
+
}
|
|
729
|
+
try {
|
|
730
|
+
const stats = statSync(resolved);
|
|
731
|
+
if (stats.isFile()) {
|
|
732
|
+
metadata.baseDir = dirname(resolved);
|
|
733
|
+
this.addResource(accumulator.extensions, resolved, metadata, true);
|
|
734
|
+
return;
|
|
735
|
+
}
|
|
736
|
+
if (stats.isDirectory()) {
|
|
737
|
+
metadata.baseDir = resolved;
|
|
738
|
+
const resources = this.collectPackageResources(resolved, accumulator, filter, metadata);
|
|
739
|
+
if (!resources) {
|
|
740
|
+
this.addResource(accumulator.extensions, resolved, metadata, true);
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
catch {
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
async installParsedSource(parsed, scope) {
|
|
749
|
+
if (parsed.type === "npm") {
|
|
750
|
+
await this.installNpm(parsed, scope, scope === "temporary");
|
|
751
|
+
return;
|
|
752
|
+
}
|
|
753
|
+
if (parsed.type === "git") {
|
|
754
|
+
await this.installGit(parsed, scope);
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
getPackageSourceString(pkg) {
|
|
759
|
+
return typeof pkg === "string" ? pkg : pkg.source;
|
|
760
|
+
}
|
|
761
|
+
getSourceMatchKeyForInput(source) {
|
|
762
|
+
const parsed = this.parseSource(source);
|
|
763
|
+
if (parsed.type === "npm") {
|
|
764
|
+
return `npm:${parsed.name}`;
|
|
765
|
+
}
|
|
766
|
+
if (parsed.type === "git") {
|
|
767
|
+
return `git:${parsed.host}/${parsed.path}`;
|
|
768
|
+
}
|
|
769
|
+
return `local:${this.resolvePath(parsed.path)}`;
|
|
770
|
+
}
|
|
771
|
+
getSourceMatchKeyForSettings(source, scope) {
|
|
772
|
+
const parsed = this.parseSource(source);
|
|
773
|
+
if (parsed.type === "npm") {
|
|
774
|
+
return `npm:${parsed.name}`;
|
|
775
|
+
}
|
|
776
|
+
if (parsed.type === "git") {
|
|
777
|
+
return `git:${parsed.host}/${parsed.path}`;
|
|
778
|
+
}
|
|
779
|
+
const baseDir = this.getBaseDirForScope(scope);
|
|
780
|
+
return `local:${this.resolvePathFromBase(parsed.path, baseDir)}`;
|
|
781
|
+
}
|
|
782
|
+
packageSourcesMatch(existing, inputSource, scope) {
|
|
783
|
+
const left = this.getSourceMatchKeyForSettings(this.getPackageSourceString(existing), scope);
|
|
784
|
+
const right = this.getSourceMatchKeyForInput(inputSource);
|
|
785
|
+
return left === right;
|
|
786
|
+
}
|
|
787
|
+
normalizePackageSourceForSettings(source, scope) {
|
|
788
|
+
const parsed = this.parseSource(source);
|
|
789
|
+
if (parsed.type !== "local") {
|
|
790
|
+
return source;
|
|
791
|
+
}
|
|
792
|
+
const baseDir = this.getBaseDirForScope(scope);
|
|
793
|
+
const resolved = this.resolvePath(parsed.path);
|
|
794
|
+
const rel = relative(baseDir, resolved);
|
|
795
|
+
return rel || ".";
|
|
796
|
+
}
|
|
797
|
+
parseSource(source) {
|
|
798
|
+
if (source.startsWith("npm:")) {
|
|
799
|
+
const spec = source.slice("npm:".length).trim();
|
|
800
|
+
const { name, version } = this.parseNpmSpec(spec);
|
|
801
|
+
return {
|
|
802
|
+
type: "npm",
|
|
803
|
+
spec,
|
|
804
|
+
name,
|
|
805
|
+
pinned: Boolean(version),
|
|
806
|
+
};
|
|
807
|
+
}
|
|
808
|
+
const trimmed = source.trim();
|
|
809
|
+
const isWindowsAbsolutePath = /^[A-Za-z]:[\\/]|^\\\\/.test(trimmed);
|
|
810
|
+
const isLocalPathLike = trimmed.startsWith(".") ||
|
|
811
|
+
trimmed.startsWith("/") ||
|
|
812
|
+
trimmed === "~" ||
|
|
813
|
+
trimmed.startsWith("~/") ||
|
|
814
|
+
isWindowsAbsolutePath;
|
|
815
|
+
if (isLocalPathLike) {
|
|
816
|
+
return { type: "local", path: source };
|
|
817
|
+
}
|
|
818
|
+
const gitParsed = parseGitUrl(source);
|
|
819
|
+
if (gitParsed) {
|
|
820
|
+
return gitParsed;
|
|
821
|
+
}
|
|
822
|
+
return { type: "local", path: source };
|
|
823
|
+
}
|
|
824
|
+
async npmNeedsUpdate(source, installedPath) {
|
|
825
|
+
if (isOfflineModeEnabled()) {
|
|
826
|
+
return false;
|
|
827
|
+
}
|
|
828
|
+
const installedVersion = this.getInstalledNpmVersion(installedPath);
|
|
829
|
+
if (!installedVersion)
|
|
830
|
+
return true;
|
|
831
|
+
const { version: pinnedVersion } = this.parseNpmSpec(source.spec);
|
|
832
|
+
if (pinnedVersion) {
|
|
833
|
+
return installedVersion !== pinnedVersion;
|
|
834
|
+
}
|
|
835
|
+
try {
|
|
836
|
+
const latestVersion = await this.getLatestNpmVersion(source.name);
|
|
837
|
+
return latestVersion !== installedVersion;
|
|
838
|
+
}
|
|
839
|
+
catch {
|
|
840
|
+
return false;
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
getInstalledNpmVersion(installedPath) {
|
|
844
|
+
const packageJsonPath = join(installedPath, "package.json");
|
|
845
|
+
if (!existsSync(packageJsonPath))
|
|
846
|
+
return undefined;
|
|
847
|
+
try {
|
|
848
|
+
const content = readFileSync(packageJsonPath, "utf-8");
|
|
849
|
+
const pkg = JSON.parse(content);
|
|
850
|
+
return pkg.version;
|
|
851
|
+
}
|
|
852
|
+
catch {
|
|
853
|
+
return undefined;
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
async getLatestNpmVersion(packageName) {
|
|
857
|
+
const response = await fetch(`https://registry.npmjs.org/${encodeURIComponent(packageName)}/latest`, {
|
|
858
|
+
signal: AbortSignal.timeout(NETWORK_TIMEOUT_MS),
|
|
859
|
+
});
|
|
860
|
+
if (!response.ok)
|
|
861
|
+
throw new Error(`Failed to fetch npm registry: ${response.status}`);
|
|
862
|
+
const data = (await response.json());
|
|
863
|
+
return data.version;
|
|
864
|
+
}
|
|
865
|
+
getPackageIdentity(source, scope) {
|
|
866
|
+
const parsed = this.parseSource(source);
|
|
867
|
+
if (parsed.type === "npm") {
|
|
868
|
+
return `npm:${parsed.name}`;
|
|
869
|
+
}
|
|
870
|
+
if (parsed.type === "git") {
|
|
871
|
+
return `git:${parsed.host}/${parsed.path}`;
|
|
872
|
+
}
|
|
873
|
+
if (scope) {
|
|
874
|
+
const baseDir = this.getBaseDirForScope(scope);
|
|
875
|
+
return `local:${this.resolvePathFromBase(parsed.path, baseDir)}`;
|
|
876
|
+
}
|
|
877
|
+
return `local:${this.resolvePath(parsed.path)}`;
|
|
878
|
+
}
|
|
879
|
+
dedupePackages(packages) {
|
|
880
|
+
const seen = new Map();
|
|
881
|
+
for (const entry of packages) {
|
|
882
|
+
const sourceStr = typeof entry.pkg === "string" ? entry.pkg : entry.pkg.source;
|
|
883
|
+
const identity = this.getPackageIdentity(sourceStr, entry.scope);
|
|
884
|
+
const existing = seen.get(identity);
|
|
885
|
+
if (!existing) {
|
|
886
|
+
seen.set(identity, entry);
|
|
887
|
+
}
|
|
888
|
+
else if (entry.scope === "project" && existing.scope === "user") {
|
|
889
|
+
seen.set(identity, entry);
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
return Array.from(seen.values());
|
|
893
|
+
}
|
|
894
|
+
parseNpmSpec(spec) {
|
|
895
|
+
const match = spec.match(/^(@?[^@]+(?:\/[^@]+)?)(?:@(.+))?$/);
|
|
896
|
+
if (!match) {
|
|
897
|
+
return { name: spec };
|
|
898
|
+
}
|
|
899
|
+
const name = match[1] ?? spec;
|
|
900
|
+
const version = match[2];
|
|
901
|
+
return { name, version };
|
|
902
|
+
}
|
|
903
|
+
async installNpm(source, scope, temporary) {
|
|
904
|
+
if (scope === "user" && !temporary) {
|
|
905
|
+
await this.runCommand("npm", ["install", "-g", source.spec]);
|
|
906
|
+
return;
|
|
907
|
+
}
|
|
908
|
+
const installRoot = this.getNpmInstallRoot(scope, temporary);
|
|
909
|
+
this.ensureNpmProject(installRoot);
|
|
910
|
+
await this.runCommand("npm", ["install", source.spec, "--prefix", installRoot]);
|
|
911
|
+
}
|
|
912
|
+
async uninstallNpm(source, scope) {
|
|
913
|
+
if (scope === "user") {
|
|
914
|
+
await this.runCommand("npm", ["uninstall", "-g", source.name]);
|
|
915
|
+
return;
|
|
916
|
+
}
|
|
917
|
+
const installRoot = this.getNpmInstallRoot(scope, false);
|
|
918
|
+
if (!existsSync(installRoot)) {
|
|
919
|
+
return;
|
|
920
|
+
}
|
|
921
|
+
await this.runCommand("npm", ["uninstall", source.name, "--prefix", installRoot]);
|
|
922
|
+
}
|
|
923
|
+
async installGit(source, scope) {
|
|
924
|
+
const targetDir = this.getGitInstallPath(source, scope);
|
|
925
|
+
if (existsSync(targetDir)) {
|
|
926
|
+
return;
|
|
927
|
+
}
|
|
928
|
+
const gitRoot = this.getGitInstallRoot(scope);
|
|
929
|
+
if (gitRoot) {
|
|
930
|
+
this.ensureGitIgnore(gitRoot);
|
|
931
|
+
}
|
|
932
|
+
mkdirSync(dirname(targetDir), { recursive: true });
|
|
933
|
+
await this.runCommand("git", ["clone", source.repo, targetDir]);
|
|
934
|
+
if (source.ref) {
|
|
935
|
+
await this.runCommand("git", ["checkout", source.ref], { cwd: targetDir });
|
|
936
|
+
}
|
|
937
|
+
const packageJsonPath = join(targetDir, "package.json");
|
|
938
|
+
if (existsSync(packageJsonPath)) {
|
|
939
|
+
await this.runCommand("npm", ["install"], { cwd: targetDir });
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
async updateGit(source, scope) {
|
|
943
|
+
const targetDir = this.getGitInstallPath(source, scope);
|
|
944
|
+
if (!existsSync(targetDir)) {
|
|
945
|
+
await this.installGit(source, scope);
|
|
946
|
+
return;
|
|
947
|
+
}
|
|
948
|
+
await this.runCommand("git", ["fetch", "--prune", "origin"], { cwd: targetDir });
|
|
949
|
+
try {
|
|
950
|
+
await this.runCommand("git", ["reset", "--hard", "@{upstream}"], { cwd: targetDir });
|
|
951
|
+
}
|
|
952
|
+
catch {
|
|
953
|
+
await this.runCommand("git", ["remote", "set-head", "origin", "-a"], { cwd: targetDir }).catch(() => { });
|
|
954
|
+
await this.runCommand("git", ["reset", "--hard", "origin/HEAD"], { cwd: targetDir });
|
|
955
|
+
}
|
|
956
|
+
await this.runCommand("git", ["clean", "-fdx"], { cwd: targetDir });
|
|
957
|
+
const packageJsonPath = join(targetDir, "package.json");
|
|
958
|
+
if (existsSync(packageJsonPath)) {
|
|
959
|
+
await this.runCommand("npm", ["install"], { cwd: targetDir });
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
async refreshTemporaryGitSource(source, sourceStr) {
|
|
963
|
+
if (isOfflineModeEnabled()) {
|
|
964
|
+
return;
|
|
965
|
+
}
|
|
966
|
+
try {
|
|
967
|
+
await this.withProgress("pull", sourceStr, `Refreshing ${sourceStr}...`, async () => {
|
|
968
|
+
await this.updateGit(source, "temporary");
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
catch { }
|
|
972
|
+
}
|
|
973
|
+
async removeGit(source, scope) {
|
|
974
|
+
const targetDir = this.getGitInstallPath(source, scope);
|
|
975
|
+
if (!existsSync(targetDir))
|
|
976
|
+
return;
|
|
977
|
+
rmSync(targetDir, { recursive: true, force: true });
|
|
978
|
+
this.pruneEmptyGitParents(targetDir, this.getGitInstallRoot(scope));
|
|
979
|
+
}
|
|
980
|
+
pruneEmptyGitParents(targetDir, installRoot) {
|
|
981
|
+
if (!installRoot)
|
|
982
|
+
return;
|
|
983
|
+
const resolvedRoot = resolve(installRoot);
|
|
984
|
+
let current = dirname(targetDir);
|
|
985
|
+
while (current.startsWith(resolvedRoot) && current !== resolvedRoot) {
|
|
986
|
+
if (!existsSync(current)) {
|
|
987
|
+
current = dirname(current);
|
|
988
|
+
continue;
|
|
989
|
+
}
|
|
990
|
+
const entries = readdirSync(current);
|
|
991
|
+
if (entries.length > 0) {
|
|
992
|
+
break;
|
|
993
|
+
}
|
|
994
|
+
try {
|
|
995
|
+
rmSync(current, { recursive: true, force: true });
|
|
996
|
+
}
|
|
997
|
+
catch {
|
|
998
|
+
break;
|
|
999
|
+
}
|
|
1000
|
+
current = dirname(current);
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
ensureNpmProject(installRoot) {
|
|
1004
|
+
if (!existsSync(installRoot)) {
|
|
1005
|
+
mkdirSync(installRoot, { recursive: true });
|
|
1006
|
+
}
|
|
1007
|
+
this.ensureGitIgnore(installRoot);
|
|
1008
|
+
const packageJsonPath = join(installRoot, "package.json");
|
|
1009
|
+
if (!existsSync(packageJsonPath)) {
|
|
1010
|
+
const pkgJson = { name: "pi-extensions", private: true };
|
|
1011
|
+
writeFileSync(packageJsonPath, JSON.stringify(pkgJson, null, 2), "utf-8");
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
ensureGitIgnore(dir) {
|
|
1015
|
+
if (!existsSync(dir)) {
|
|
1016
|
+
mkdirSync(dir, { recursive: true });
|
|
1017
|
+
}
|
|
1018
|
+
const ignorePath = join(dir, ".gitignore");
|
|
1019
|
+
if (!existsSync(ignorePath)) {
|
|
1020
|
+
writeFileSync(ignorePath, "*\n!.gitignore\n", "utf-8");
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
getNpmInstallRoot(scope, temporary) {
|
|
1024
|
+
if (temporary) {
|
|
1025
|
+
return this.getTemporaryDir("npm");
|
|
1026
|
+
}
|
|
1027
|
+
if (scope === "project") {
|
|
1028
|
+
return join(this.cwd, CONFIG_DIR_NAME, "npm");
|
|
1029
|
+
}
|
|
1030
|
+
return join(this.getGlobalNpmRoot(), "..");
|
|
1031
|
+
}
|
|
1032
|
+
getGlobalNpmRoot() {
|
|
1033
|
+
if (this.globalNpmRoot) {
|
|
1034
|
+
return this.globalNpmRoot;
|
|
1035
|
+
}
|
|
1036
|
+
const result = this.runCommandSync("npm", ["root", "-g"]);
|
|
1037
|
+
this.globalNpmRoot = result.trim();
|
|
1038
|
+
return this.globalNpmRoot;
|
|
1039
|
+
}
|
|
1040
|
+
getNpmInstallPath(source, scope) {
|
|
1041
|
+
if (scope === "temporary") {
|
|
1042
|
+
return join(this.getTemporaryDir("npm"), "node_modules", source.name);
|
|
1043
|
+
}
|
|
1044
|
+
if (scope === "project") {
|
|
1045
|
+
return join(this.cwd, CONFIG_DIR_NAME, "npm", "node_modules", source.name);
|
|
1046
|
+
}
|
|
1047
|
+
return join(this.getGlobalNpmRoot(), source.name);
|
|
1048
|
+
}
|
|
1049
|
+
getGitInstallPath(source, scope) {
|
|
1050
|
+
if (scope === "temporary") {
|
|
1051
|
+
return this.getTemporaryDir(`git-${source.host}`, source.path);
|
|
1052
|
+
}
|
|
1053
|
+
if (scope === "project") {
|
|
1054
|
+
return join(this.cwd, CONFIG_DIR_NAME, "git", source.host, source.path);
|
|
1055
|
+
}
|
|
1056
|
+
return join(this.agentDir, "git", source.host, source.path);
|
|
1057
|
+
}
|
|
1058
|
+
getGitInstallRoot(scope) {
|
|
1059
|
+
if (scope === "temporary") {
|
|
1060
|
+
return undefined;
|
|
1061
|
+
}
|
|
1062
|
+
if (scope === "project") {
|
|
1063
|
+
return join(this.cwd, CONFIG_DIR_NAME, "git");
|
|
1064
|
+
}
|
|
1065
|
+
return join(this.agentDir, "git");
|
|
1066
|
+
}
|
|
1067
|
+
getTemporaryDir(prefix, suffix) {
|
|
1068
|
+
const hash = createHash("sha256")
|
|
1069
|
+
.update(`${prefix}-${suffix ?? ""}`)
|
|
1070
|
+
.digest("hex")
|
|
1071
|
+
.slice(0, 8);
|
|
1072
|
+
return join(tmpdir(), "pi-extensions", prefix, hash, suffix ?? "");
|
|
1073
|
+
}
|
|
1074
|
+
getBaseDirForScope(scope) {
|
|
1075
|
+
if (scope === "project") {
|
|
1076
|
+
return join(this.cwd, CONFIG_DIR_NAME);
|
|
1077
|
+
}
|
|
1078
|
+
if (scope === "user") {
|
|
1079
|
+
return this.agentDir;
|
|
1080
|
+
}
|
|
1081
|
+
return this.cwd;
|
|
1082
|
+
}
|
|
1083
|
+
resolvePath(input) {
|
|
1084
|
+
const trimmed = input.trim();
|
|
1085
|
+
if (trimmed === "~")
|
|
1086
|
+
return homedir();
|
|
1087
|
+
if (trimmed.startsWith("~/"))
|
|
1088
|
+
return join(homedir(), trimmed.slice(2));
|
|
1089
|
+
if (trimmed.startsWith("~"))
|
|
1090
|
+
return join(homedir(), trimmed.slice(1));
|
|
1091
|
+
return resolve(this.cwd, trimmed);
|
|
1092
|
+
}
|
|
1093
|
+
resolvePathFromBase(input, baseDir) {
|
|
1094
|
+
const trimmed = input.trim();
|
|
1095
|
+
if (trimmed === "~")
|
|
1096
|
+
return homedir();
|
|
1097
|
+
if (trimmed.startsWith("~/"))
|
|
1098
|
+
return join(homedir(), trimmed.slice(2));
|
|
1099
|
+
if (trimmed.startsWith("~"))
|
|
1100
|
+
return join(homedir(), trimmed.slice(1));
|
|
1101
|
+
return resolve(baseDir, trimmed);
|
|
1102
|
+
}
|
|
1103
|
+
collectPackageResources(packageRoot, accumulator, filter, metadata) {
|
|
1104
|
+
if (filter) {
|
|
1105
|
+
for (const resourceType of RESOURCE_TYPES) {
|
|
1106
|
+
const patterns = filter[resourceType];
|
|
1107
|
+
const target = this.getTargetMap(accumulator, resourceType);
|
|
1108
|
+
if (patterns !== undefined) {
|
|
1109
|
+
this.applyPackageFilter(packageRoot, patterns, resourceType, target, metadata);
|
|
1110
|
+
}
|
|
1111
|
+
else {
|
|
1112
|
+
this.collectDefaultResources(packageRoot, resourceType, target, metadata);
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
return true;
|
|
1116
|
+
}
|
|
1117
|
+
const manifest = this.readPiManifest(packageRoot);
|
|
1118
|
+
if (manifest) {
|
|
1119
|
+
for (const resourceType of RESOURCE_TYPES) {
|
|
1120
|
+
const entries = manifest[resourceType];
|
|
1121
|
+
this.addManifestEntries(entries, packageRoot, resourceType, this.getTargetMap(accumulator, resourceType), metadata);
|
|
1122
|
+
}
|
|
1123
|
+
return true;
|
|
1124
|
+
}
|
|
1125
|
+
let hasAnyDir = false;
|
|
1126
|
+
for (const resourceType of RESOURCE_TYPES) {
|
|
1127
|
+
const dir = join(packageRoot, resourceType);
|
|
1128
|
+
if (existsSync(dir)) {
|
|
1129
|
+
const files = collectResourceFiles(dir, resourceType);
|
|
1130
|
+
for (const f of files) {
|
|
1131
|
+
this.addResource(this.getTargetMap(accumulator, resourceType), f, metadata, true);
|
|
1132
|
+
}
|
|
1133
|
+
hasAnyDir = true;
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
return hasAnyDir;
|
|
1137
|
+
}
|
|
1138
|
+
collectDefaultResources(packageRoot, resourceType, target, metadata) {
|
|
1139
|
+
const manifest = this.readPiManifest(packageRoot);
|
|
1140
|
+
const entries = manifest?.[resourceType];
|
|
1141
|
+
if (entries) {
|
|
1142
|
+
this.addManifestEntries(entries, packageRoot, resourceType, target, metadata);
|
|
1143
|
+
return;
|
|
1144
|
+
}
|
|
1145
|
+
const dir = join(packageRoot, resourceType);
|
|
1146
|
+
if (existsSync(dir)) {
|
|
1147
|
+
const files = collectResourceFiles(dir, resourceType);
|
|
1148
|
+
for (const f of files) {
|
|
1149
|
+
this.addResource(target, f, metadata, true);
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
applyPackageFilter(packageRoot, userPatterns, resourceType, target, metadata) {
|
|
1154
|
+
const { allFiles } = this.collectManifestFiles(packageRoot, resourceType);
|
|
1155
|
+
if (userPatterns.length === 0) {
|
|
1156
|
+
for (const f of allFiles) {
|
|
1157
|
+
this.addResource(target, f, metadata, false);
|
|
1158
|
+
}
|
|
1159
|
+
return;
|
|
1160
|
+
}
|
|
1161
|
+
const enabledByUser = applyPatterns(allFiles, userPatterns, packageRoot);
|
|
1162
|
+
for (const f of allFiles) {
|
|
1163
|
+
const enabled = enabledByUser.has(f);
|
|
1164
|
+
this.addResource(target, f, metadata, enabled);
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
collectManifestFiles(packageRoot, resourceType) {
|
|
1168
|
+
const manifest = this.readPiManifest(packageRoot);
|
|
1169
|
+
const entries = manifest?.[resourceType];
|
|
1170
|
+
if (entries && entries.length > 0) {
|
|
1171
|
+
const allFiles = this.collectFilesFromManifestEntries(entries, packageRoot, resourceType);
|
|
1172
|
+
const manifestPatterns = entries.filter(isPattern);
|
|
1173
|
+
const enabledByManifest = manifestPatterns.length > 0 ? applyPatterns(allFiles, manifestPatterns, packageRoot) : new Set(allFiles);
|
|
1174
|
+
return { allFiles: Array.from(enabledByManifest), enabledByManifest };
|
|
1175
|
+
}
|
|
1176
|
+
const conventionDir = join(packageRoot, resourceType);
|
|
1177
|
+
if (!existsSync(conventionDir)) {
|
|
1178
|
+
return { allFiles: [], enabledByManifest: new Set() };
|
|
1179
|
+
}
|
|
1180
|
+
const allFiles = collectResourceFiles(conventionDir, resourceType);
|
|
1181
|
+
return { allFiles, enabledByManifest: new Set(allFiles) };
|
|
1182
|
+
}
|
|
1183
|
+
readPiManifest(packageRoot) {
|
|
1184
|
+
const packageJsonPath = join(packageRoot, "package.json");
|
|
1185
|
+
if (!existsSync(packageJsonPath)) {
|
|
1186
|
+
return null;
|
|
1187
|
+
}
|
|
1188
|
+
try {
|
|
1189
|
+
const content = readFileSync(packageJsonPath, "utf-8");
|
|
1190
|
+
const pkg = JSON.parse(content);
|
|
1191
|
+
return pkg.pi ?? null;
|
|
1192
|
+
}
|
|
1193
|
+
catch {
|
|
1194
|
+
return null;
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
addManifestEntries(entries, root, resourceType, target, metadata) {
|
|
1198
|
+
if (!entries)
|
|
1199
|
+
return;
|
|
1200
|
+
const allFiles = this.collectFilesFromManifestEntries(entries, root, resourceType);
|
|
1201
|
+
const patterns = entries.filter(isPattern);
|
|
1202
|
+
const enabledPaths = applyPatterns(allFiles, patterns, root);
|
|
1203
|
+
for (const f of allFiles) {
|
|
1204
|
+
if (enabledPaths.has(f)) {
|
|
1205
|
+
this.addResource(target, f, metadata, true);
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
collectFilesFromManifestEntries(entries, root, resourceType) {
|
|
1210
|
+
const plain = entries.filter((entry) => !isPattern(entry));
|
|
1211
|
+
const resolved = plain.map((entry) => resolve(root, entry));
|
|
1212
|
+
return this.collectFilesFromPaths(resolved, resourceType);
|
|
1213
|
+
}
|
|
1214
|
+
resolveLocalEntries(entries, resourceType, target, metadata, baseDir) {
|
|
1215
|
+
if (entries.length === 0)
|
|
1216
|
+
return;
|
|
1217
|
+
const { plain, patterns } = splitPatterns(entries);
|
|
1218
|
+
const resolvedPlain = plain.map((p) => this.resolvePathFromBase(p, baseDir));
|
|
1219
|
+
const allFiles = this.collectFilesFromPaths(resolvedPlain, resourceType);
|
|
1220
|
+
const enabledPaths = applyPatterns(allFiles, patterns, baseDir);
|
|
1221
|
+
for (const f of allFiles) {
|
|
1222
|
+
this.addResource(target, f, metadata, enabledPaths.has(f));
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
addAutoDiscoveredResources(accumulator, globalSettings, projectSettings, globalBaseDir, projectBaseDir) {
|
|
1226
|
+
const userMetadata = {
|
|
1227
|
+
source: "auto",
|
|
1228
|
+
scope: "user",
|
|
1229
|
+
origin: "top-level",
|
|
1230
|
+
baseDir: globalBaseDir,
|
|
1231
|
+
};
|
|
1232
|
+
const projectMetadata = {
|
|
1233
|
+
source: "auto",
|
|
1234
|
+
scope: "project",
|
|
1235
|
+
origin: "top-level",
|
|
1236
|
+
baseDir: projectBaseDir,
|
|
1237
|
+
};
|
|
1238
|
+
const userOverrides = {
|
|
1239
|
+
extensions: (globalSettings.extensions ?? []),
|
|
1240
|
+
skills: (globalSettings.skills ?? []),
|
|
1241
|
+
prompts: (globalSettings.prompts ?? []),
|
|
1242
|
+
themes: (globalSettings.themes ?? []),
|
|
1243
|
+
};
|
|
1244
|
+
const projectOverrides = {
|
|
1245
|
+
extensions: (projectSettings.extensions ?? []),
|
|
1246
|
+
skills: (projectSettings.skills ?? []),
|
|
1247
|
+
prompts: (projectSettings.prompts ?? []),
|
|
1248
|
+
themes: (projectSettings.themes ?? []),
|
|
1249
|
+
};
|
|
1250
|
+
const userDirs = {
|
|
1251
|
+
extensions: join(globalBaseDir, "extensions"),
|
|
1252
|
+
skills: join(globalBaseDir, "skills"),
|
|
1253
|
+
prompts: join(globalBaseDir, "prompts"),
|
|
1254
|
+
themes: join(globalBaseDir, "themes"),
|
|
1255
|
+
};
|
|
1256
|
+
const projectDirs = {
|
|
1257
|
+
extensions: join(projectBaseDir, "extensions"),
|
|
1258
|
+
skills: join(projectBaseDir, "skills"),
|
|
1259
|
+
prompts: join(projectBaseDir, "prompts"),
|
|
1260
|
+
themes: join(projectBaseDir, "themes"),
|
|
1261
|
+
};
|
|
1262
|
+
const userAgentsSkillsDir = join(homedir(), ".agents", "skills");
|
|
1263
|
+
const projectAgentsSkillDirs = collectAncestorAgentsSkillDirs(this.cwd).filter((dir) => resolve(dir) !== resolve(userAgentsSkillsDir));
|
|
1264
|
+
const addResources = (resourceType, paths, metadata, overrides, baseDir) => {
|
|
1265
|
+
const target = this.getTargetMap(accumulator, resourceType);
|
|
1266
|
+
for (const path of paths) {
|
|
1267
|
+
const enabled = isEnabledByOverrides(path, overrides, baseDir);
|
|
1268
|
+
this.addResource(target, path, metadata, enabled);
|
|
1269
|
+
}
|
|
1270
|
+
};
|
|
1271
|
+
addResources("extensions", collectAutoExtensionEntries(projectDirs.extensions), projectMetadata, projectOverrides.extensions, projectBaseDir);
|
|
1272
|
+
addResources("skills", [
|
|
1273
|
+
...collectAutoSkillEntries(projectDirs.skills),
|
|
1274
|
+
...projectAgentsSkillDirs.flatMap((dir) => collectAutoSkillEntries(dir)),
|
|
1275
|
+
], projectMetadata, projectOverrides.skills, projectBaseDir);
|
|
1276
|
+
addResources("prompts", collectAutoPromptEntries(projectDirs.prompts), projectMetadata, projectOverrides.prompts, projectBaseDir);
|
|
1277
|
+
addResources("themes", collectAutoThemeEntries(projectDirs.themes), projectMetadata, projectOverrides.themes, projectBaseDir);
|
|
1278
|
+
addResources("extensions", collectAutoExtensionEntries(userDirs.extensions), userMetadata, userOverrides.extensions, globalBaseDir);
|
|
1279
|
+
addResources("skills", [...collectAutoSkillEntries(userDirs.skills), ...collectAutoSkillEntries(userAgentsSkillsDir)], userMetadata, userOverrides.skills, globalBaseDir);
|
|
1280
|
+
addResources("prompts", collectAutoPromptEntries(userDirs.prompts), userMetadata, userOverrides.prompts, globalBaseDir);
|
|
1281
|
+
addResources("themes", collectAutoThemeEntries(userDirs.themes), userMetadata, userOverrides.themes, globalBaseDir);
|
|
1282
|
+
}
|
|
1283
|
+
collectFilesFromPaths(paths, resourceType) {
|
|
1284
|
+
const files = [];
|
|
1285
|
+
for (const p of paths) {
|
|
1286
|
+
if (!existsSync(p))
|
|
1287
|
+
continue;
|
|
1288
|
+
try {
|
|
1289
|
+
const stats = statSync(p);
|
|
1290
|
+
if (stats.isFile()) {
|
|
1291
|
+
files.push(p);
|
|
1292
|
+
}
|
|
1293
|
+
else if (stats.isDirectory()) {
|
|
1294
|
+
files.push(...collectResourceFiles(p, resourceType));
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
catch { }
|
|
1298
|
+
}
|
|
1299
|
+
return files;
|
|
1300
|
+
}
|
|
1301
|
+
getTargetMap(accumulator, resourceType) {
|
|
1302
|
+
switch (resourceType) {
|
|
1303
|
+
case "extensions":
|
|
1304
|
+
return accumulator.extensions;
|
|
1305
|
+
case "skills":
|
|
1306
|
+
return accumulator.skills;
|
|
1307
|
+
case "prompts":
|
|
1308
|
+
return accumulator.prompts;
|
|
1309
|
+
case "themes":
|
|
1310
|
+
return accumulator.themes;
|
|
1311
|
+
default:
|
|
1312
|
+
throw new Error(`Unknown resource type: ${resourceType}`);
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
addResource(map, path, metadata, enabled) {
|
|
1316
|
+
if (!path)
|
|
1317
|
+
return;
|
|
1318
|
+
if (!map.has(path)) {
|
|
1319
|
+
map.set(path, { metadata, enabled });
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
createAccumulator() {
|
|
1323
|
+
return {
|
|
1324
|
+
extensions: new Map(),
|
|
1325
|
+
skills: new Map(),
|
|
1326
|
+
prompts: new Map(),
|
|
1327
|
+
themes: new Map(),
|
|
1328
|
+
};
|
|
1329
|
+
}
|
|
1330
|
+
toResolvedPaths(accumulator) {
|
|
1331
|
+
const toResolved = (entries) => {
|
|
1332
|
+
return Array.from(entries.entries()).map(([path, { metadata, enabled }]) => ({
|
|
1333
|
+
path,
|
|
1334
|
+
enabled,
|
|
1335
|
+
metadata,
|
|
1336
|
+
}));
|
|
1337
|
+
};
|
|
1338
|
+
return {
|
|
1339
|
+
extensions: toResolved(accumulator.extensions),
|
|
1340
|
+
skills: toResolved(accumulator.skills),
|
|
1341
|
+
prompts: toResolved(accumulator.prompts),
|
|
1342
|
+
themes: toResolved(accumulator.themes),
|
|
1343
|
+
};
|
|
1344
|
+
}
|
|
1345
|
+
runCommand(command, args, options) {
|
|
1346
|
+
return new Promise((resolvePromise, reject) => {
|
|
1347
|
+
const child = spawn(command, args, {
|
|
1348
|
+
cwd: options?.cwd,
|
|
1349
|
+
stdio: "inherit",
|
|
1350
|
+
shell: process.platform === "win32",
|
|
1351
|
+
});
|
|
1352
|
+
child.on("error", reject);
|
|
1353
|
+
child.on("exit", (code) => {
|
|
1354
|
+
if (code === 0) {
|
|
1355
|
+
resolvePromise();
|
|
1356
|
+
}
|
|
1357
|
+
else {
|
|
1358
|
+
reject(new Error(`${command} ${args.join(" ")} failed with code ${code}`));
|
|
1359
|
+
}
|
|
1360
|
+
});
|
|
1361
|
+
});
|
|
1362
|
+
}
|
|
1363
|
+
runCommandSync(command, args) {
|
|
1364
|
+
const result = spawnSync(command, args, {
|
|
1365
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
1366
|
+
encoding: "utf-8",
|
|
1367
|
+
shell: process.platform === "win32",
|
|
1368
|
+
});
|
|
1369
|
+
if (result.status !== 0) {
|
|
1370
|
+
throw new Error(`Failed to run ${command} ${args.join(" ")}: ${result.stderr || result.stdout}`);
|
|
1371
|
+
}
|
|
1372
|
+
return (result.stdout || result.stderr || "").trim();
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
//# sourceMappingURL=package-manager.js.map
|