@fbincon/claude-code-statusline 3.7.0 → 3.9.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/README.md +81 -79
- package/candidate.json +434 -289
- package/node_modules/@fbincon/statusline-cli/dist/src/config/arguments.js +18 -4
- package/node_modules/@fbincon/statusline-cli/dist/src/config/arguments.js.map +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/config/commands.js +26 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/config/commands.js.map +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/config/profile-command.js +7 -2
- package/node_modules/@fbincon/statusline-cli/dist/src/config/profile-command.js.map +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/config/selective-import.d.ts +3 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/config/selective-import.js +40 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/config/selective-import.js.map +1 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/diagnostics/observations.js +5 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/diagnostics/observations.js.map +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/help.js +9 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/help.js.map +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/integration/configure.js +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/integration/configure.js.map +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/integration/doctor.js +20 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/integration/doctor.js.map +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/integration/mods.d.ts +4 -3
- package/node_modules/@fbincon/statusline-cli/dist/src/integration/mods.js +14 -13
- package/node_modules/@fbincon/statusline-cli/dist/src/integration/mods.js.map +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/integration/resources.d.ts +5 -2
- package/node_modules/@fbincon/statusline-cli/dist/src/integration/resources.js +8 -6
- package/node_modules/@fbincon/statusline-cli/dist/src/integration/resources.js.map +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/main.js +14 -2
- package/node_modules/@fbincon/statusline-cli/dist/src/main.js.map +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/management/arguments.d.ts +17 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/arguments.js +56 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/arguments.js.map +1 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/bootstrap.d.ts +7 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/bootstrap.js +69 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/bootstrap.js.map +1 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/configuration.d.ts +10 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/configuration.js +123 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/configuration.js.map +1 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/first-entry.d.ts +20 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/first-entry.js +170 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/first-entry.js.map +1 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/integration-runner.d.ts +1 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/integration-runner.js +51 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/integration-runner.js.map +1 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/integration.d.ts +3 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/integration.js +34 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/integration.js.map +1 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/mod-transition-runner.d.ts +1 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/mod-transition-runner.js +16 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/mod-transition-runner.js.map +1 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/mod-transition.d.ts +3 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/mod-transition.js +96 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/mod-transition.js.map +1 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/restore.d.ts +3 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/restore.js +62 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/restore.js.map +1 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/service.d.ts +18 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/service.js +319 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/service.js.map +1 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/store.d.ts +53 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/store.js +117 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/store.js.map +1 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/worker-entry.d.ts +1 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/worker-entry.js +13 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/worker-entry.js.map +1 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/runtime/git.js +9 -10
- package/node_modules/@fbincon/statusline-cli/dist/src/runtime/git.js.map +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/runtime/usage-index.js +2 -2
- package/node_modules/@fbincon/statusline-cli/dist/src/runtime/usage-index.js.map +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/sources/context.js +4 -2
- package/node_modules/@fbincon/statusline-cli/dist/src/sources/context.js.map +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/sources/providers.js +6 -2
- package/node_modules/@fbincon/statusline-cli/dist/src/sources/providers.js.map +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/ui/protocol.d.ts +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/ui/protocol.js +22 -6
- package/node_modules/@fbincon/statusline-cli/dist/src/ui/protocol.js.map +1 -1
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/.claude-plugin/plugin.json +1 -1
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/hooks/register.ts +1 -1
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/backend.ts +7 -4
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/client/keys.ts +9 -6
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/client/settings.ts +5 -1
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/alignment-manager.ts +59 -0
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/alignments.ts +77 -0
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/appearance.ts +3 -2
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/draft.ts +17 -4
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/forms.ts +18 -4
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/gradients.ts +29 -0
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/group-manager.ts +5 -3
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/groups.ts +2 -0
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/import-differences.ts +72 -0
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/import-review.ts +49 -2
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/import-selection.ts +38 -0
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/profile-manager.ts +14 -5
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/generated-contracts.ts +9 -3
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/i18n/generated-locales.ts +552 -6
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/i18n/presentation.ts +2 -0
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/session.ts +3 -1
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/resource-manifest.json +26 -21
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/ui/client/draw.ts +6 -2
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/ui/client/help.ts +1 -1
- package/node_modules/@fbincon/statusline-cli/resources/statusline-runtime/.claude-plugin/plugin.json +1 -1
- package/node_modules/@fbincon/statusline-cli/resources/statusline-runtime/resource-manifest.json +3 -3
- package/node_modules/@fbincon/statusline-core/dist/src/config/defaults.js +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/config/display.d.ts +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/config/display.js +13 -4
- package/node_modules/@fbincon/statusline-core/dist/src/config/display.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/config/editor-fields.js +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/config/editor-fields.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/config/formatting.js +11 -4
- package/node_modules/@fbincon/statusline-core/dist/src/config/formatting.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/config/import-review.d.ts +2 -4
- package/node_modules/@fbincon/statusline-core/dist/src/config/import-review.js +2 -83
- package/node_modules/@fbincon/statusline-core/dist/src/config/import-review.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/config/instances.js +12 -3
- package/node_modules/@fbincon/statusline-core/dist/src/config/instances.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/contracts/ui.d.ts +15 -3
- package/node_modules/@fbincon/statusline-core/dist/src/contracts/ui.js +2 -2
- package/node_modules/@fbincon/statusline-core/dist/src/contracts/ui.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/editor/alignment-manager.d.ts +18 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/alignment-manager.js +112 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/alignment-manager.js.map +1 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/alignments.d.ts +21 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/alignments.js +117 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/alignments.js.map +1 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/appearance.js +3 -2
- package/node_modules/@fbincon/statusline-core/dist/src/editor/appearance.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/editor/backend.js +8 -4
- package/node_modules/@fbincon/statusline-core/dist/src/editor/backend.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/editor/draft.d.ts +4 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/draft.js +16 -3
- package/node_modules/@fbincon/statusline-core/dist/src/editor/draft.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/editor/forms.js +24 -4
- package/node_modules/@fbincon/statusline-core/dist/src/editor/forms.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/editor/gradients.d.ts +16 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/gradients.js +31 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/gradients.js.map +1 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/group-manager.d.ts +2 -1
- package/node_modules/@fbincon/statusline-core/dist/src/editor/group-manager.js +5 -3
- package/node_modules/@fbincon/statusline-core/dist/src/editor/group-manager.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/editor/groups.js +3 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/groups.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/editor/import-differences.d.ts +4 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/import-differences.js +86 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/import-differences.js.map +1 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/import-review.d.ts +8 -2
- package/node_modules/@fbincon/statusline-core/dist/src/editor/import-review.js +67 -1
- package/node_modules/@fbincon/statusline-core/dist/src/editor/import-review.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/editor/import-selection.d.ts +7 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/import-selection.js +42 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/import-selection.js.map +1 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/profile-manager.d.ts +4 -1
- package/node_modules/@fbincon/statusline-core/dist/src/editor/profile-manager.js +16 -4
- package/node_modules/@fbincon/statusline-core/dist/src/editor/profile-manager.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/i18n/generated-locales.d.ts +546 -0
- package/node_modules/@fbincon/statusline-core/dist/src/i18n/generated-locales.js +552 -6
- package/node_modules/@fbincon/statusline-core/dist/src/i18n/generated-locales.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/management/compatibility.d.ts +27 -0
- package/node_modules/@fbincon/statusline-core/dist/src/management/compatibility.js +78 -0
- package/node_modules/@fbincon/statusline-core/dist/src/management/compatibility.js.map +1 -0
- package/node_modules/@fbincon/statusline-core/dist/src/management/package.d.ts +41 -0
- package/node_modules/@fbincon/statusline-core/dist/src/management/package.js +15 -0
- package/node_modules/@fbincon/statusline-core/dist/src/management/package.js.map +1 -0
- package/node_modules/@fbincon/statusline-core/dist/src/release.d.ts +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/release.js +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/alignment.d.ts +3 -0
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/alignment.js +97 -0
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/alignment.js.map +1 -0
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/components.d.ts +1 -0
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/components.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/diagnose.js +2 -3
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/diagnose.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/explain.js +2 -0
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/explain.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/gradients.d.ts +13 -0
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/gradients.js +68 -0
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/gradients.js.map +1 -0
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/groups.js +5 -4
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/groups.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/items.d.ts +4 -1
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/items.js +41 -15
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/items.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/layout.d.ts +1 -0
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/layout.js +9 -3
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/layout.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/powerline.d.ts +4 -0
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/powerline.js +15 -1
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/powerline.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/subagents.js +7 -5
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/subagents.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/trace.d.ts +3 -0
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/trace.js +3 -0
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/trace.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/runtime/git.d.ts +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/runtime/git.js +1 -1
- package/node_modules/@fbincon/statusline-core/resources/i18n/locales/en.json +92 -1
- package/node_modules/@fbincon/statusline-core/resources/i18n/locales/ja.json +92 -1
- package/node_modules/@fbincon/statusline-core/resources/i18n/locales/ko.json +92 -1
- package/node_modules/@fbincon/statusline-core/resources/i18n/locales/zh-CN.json +92 -1
- package/node_modules/@fbincon/statusline-core/resources/i18n/locales/zh-HK.json +92 -1
- package/node_modules/@fbincon/statusline-core/resources/i18n/locales/zh-TW.json +92 -1
- package/node_modules/@fbincon/statusline-platform/dist/src/command.d.ts +1 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/command.js +1 -1
- package/node_modules/@fbincon/statusline-platform/dist/src/command.js.map +1 -1
- package/node_modules/@fbincon/statusline-platform/dist/src/files.d.ts +1 -1
- package/node_modules/@fbincon/statusline-platform/dist/src/files.js +5 -5
- package/node_modules/@fbincon/statusline-platform/dist/src/files.js.map +1 -1
- package/node_modules/@fbincon/statusline-platform/dist/src/git.d.ts +31 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/git.js +180 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/git.js.map +1 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/npm.d.ts +44 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/npm.js +229 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/npm.js.map +1 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/package-copy.d.ts +4 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/package-copy.js +49 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/package-copy.js.map +1 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/remove-tree.d.ts +2 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/remove-tree.js +51 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/remove-tree.js.map +1 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/source-process.d.ts +4 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/source-process.js +24 -2
- package/node_modules/@fbincon/statusline-platform/dist/src/source-process.js.map +1 -1
- package/node_modules/@fbincon/statusline-platform/dist/src/terminal/capabilities.d.ts +12 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/terminal/capabilities.js +20 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/terminal/capabilities.js.map +1 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/terminal/session.d.ts +3 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/terminal/session.js +5 -2
- package/node_modules/@fbincon/statusline-platform/dist/src/terminal/session.js.map +1 -1
- package/node_modules/@fbincon/statusline-platform/dist/src/terminal/windows-modes.d.ts +3 -1
- package/node_modules/@fbincon/statusline-platform/dist/src/terminal/windows-modes.js +20 -3
- package/node_modules/@fbincon/statusline-platform/dist/src/terminal/windows-modes.js.map +1 -1
- package/node_modules/@fbincon/statusline-platform/dist/src/windows-source-environment.d.ts +3 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/windows-source-environment.js +5 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/windows-source-environment.js.map +1 -1
- package/node_modules/@fbincon/statusline-tui/dist/src/drawing/pages.js +5 -0
- package/node_modules/@fbincon/statusline-tui/dist/src/drawing/pages.js.map +1 -1
- package/node_modules/@fbincon/statusline-tui/dist/src/drawing/presentation.js +5 -0
- package/node_modules/@fbincon/statusline-tui/dist/src/drawing/presentation.js.map +1 -1
- package/node_modules/@fbincon/statusline-tui/dist/src/drawing/shortcuts.js +2 -2
- package/node_modules/@fbincon/statusline-tui/dist/src/drawing/shortcuts.js.map +1 -1
- package/node_modules/@fbincon/statusline-tui/dist/src/drawing.js +1 -1
- package/node_modules/@fbincon/statusline-tui/dist/src/drawing.js.map +1 -1
- package/node_modules/@fbincon/statusline-tui/dist/src/session.js +7 -8
- package/node_modules/@fbincon/statusline-tui/dist/src/session.js.map +1 -1
- package/node_modules/@fbincon/statusline-tui/dist/src/setup.d.ts +1 -1
- package/node_modules/@fbincon/statusline-tui/dist/src/setup.js +6 -4
- package/node_modules/@fbincon/statusline-tui/dist/src/setup.js.map +1 -1
- package/node_modules/@fbincon/statusline-tui/dist/src/state.js +12 -5
- package/node_modules/@fbincon/statusline-tui/dist/src/state.js.map +1 -1
- package/package.json +47 -1
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { isAbsolute, relative, resolve, sep, basename } from 'node:path';
|
|
2
|
+
import { realpathSync, statSync, accessSync, constants, existsSync } from 'node:fs';
|
|
3
|
+
import { runCommand, monotonicMilliseconds, CommandTimeout } from './command.js';
|
|
4
|
+
import { which } from './commands.js';
|
|
5
|
+
/** Per-process policy only: never rewrite repository or user configuration. */
|
|
6
|
+
export const GIT_POLICY_VERSION = 1;
|
|
7
|
+
const BASE = ['core.fsmonitor=', 'safe.bareRepository=explicit'];
|
|
8
|
+
export class GitPolicyError extends Error {
|
|
9
|
+
reason;
|
|
10
|
+
constructor(reason) {
|
|
11
|
+
super(reason);
|
|
12
|
+
this.reason = reason;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export function filterEntries(raw) {
|
|
16
|
+
if (!raw)
|
|
17
|
+
return [];
|
|
18
|
+
const parts = raw.split('\0');
|
|
19
|
+
if (parts.pop() !== '' || parts.length % 3)
|
|
20
|
+
throw new GitPolicyError('policy_unavailable');
|
|
21
|
+
const result = [];
|
|
22
|
+
for (let i = 0; i < parts.length; i += 3) {
|
|
23
|
+
const scope = parts[i], origin = parts[i + 1], pair = parts[i + 2], at = pair.indexOf('\n');
|
|
24
|
+
const key = pair.slice(0, at), match = /^filter\.(.+)\.(clean|smudge|process|required)$/u.exec(key);
|
|
25
|
+
if (at < 0 || !match || !['system', 'global', 'local', 'worktree', 'command'].includes(scope))
|
|
26
|
+
throw new GitPolicyError('policy_unavailable');
|
|
27
|
+
result.push({ scope, origin, key, name: match[1], field: match[2], value: pair.slice(at + 1) });
|
|
28
|
+
}
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
function inside(path, root) {
|
|
32
|
+
const part = relative(root, path);
|
|
33
|
+
return !part || part !== '..' && !part.startsWith('..' + sep) && !isAbsolute(part);
|
|
34
|
+
}
|
|
35
|
+
const quote = (value) => "'" + value.replaceAll("'", "'\\''") + "'";
|
|
36
|
+
function externalExecutable(path, roots, program) {
|
|
37
|
+
try {
|
|
38
|
+
const actual = realpathSync.native(path);
|
|
39
|
+
const name = process.platform === 'win32' ? basename(actual).toLowerCase() : basename(actual);
|
|
40
|
+
if (name !== program && name !== program + '.exe')
|
|
41
|
+
return null;
|
|
42
|
+
if (roots.some(root => inside(actual, root)) || !statSync(actual).isFile() || /[\r\n\0]/u.test(actual))
|
|
43
|
+
return null;
|
|
44
|
+
accessSync(actual, process.platform === 'win32' ? constants.F_OK : constants.X_OK);
|
|
45
|
+
return actual;
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/** Known repository-installed drivers are pinned to a verified external executable. */
|
|
52
|
+
export function filterOverrides(entries, roots, env) {
|
|
53
|
+
try {
|
|
54
|
+
roots = roots.map(root => realpathSync.native(root));
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
throw new GitPolicyError('policy_unavailable');
|
|
58
|
+
}
|
|
59
|
+
const overrides = new Map();
|
|
60
|
+
for (const entry of entries) {
|
|
61
|
+
const origin = entry.origin.startsWith('file:') ? resolve(roots[0], entry.origin.slice(5)) : null;
|
|
62
|
+
let repositoryOwned = ['local', 'worktree'].includes(entry.scope);
|
|
63
|
+
if (origin) {
|
|
64
|
+
try {
|
|
65
|
+
repositoryOwned ||= roots.some(root => inside(realpathSync.native(origin), root));
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
throw new GitPolicyError('policy_unavailable');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (!repositoryOwned || entry.field === 'required')
|
|
72
|
+
continue;
|
|
73
|
+
if (/[=\r\n\0]/u.test(entry.name))
|
|
74
|
+
throw new GitPolicyError('filter_blocked');
|
|
75
|
+
if (!entry.value) {
|
|
76
|
+
overrides.set(entry.key, '');
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const lfs = { clean: 'clean -- %f', smudge: 'smudge -- %f', process: 'filter-process' };
|
|
80
|
+
if (entry.value === 'git-lfs ' + lfs[entry.field]) {
|
|
81
|
+
const found = which('git-lfs', env), executable = found && externalExecutable(found, roots, 'git-lfs');
|
|
82
|
+
if (!executable)
|
|
83
|
+
throw new GitPolicyError('filter_blocked');
|
|
84
|
+
overrides.set(entry.key, quote(executable) + ' ' + lfs[entry.field]);
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const crypt = /^(?:"([\p{L}\p{N}\p{M}_./\\:+@ ()~-]+)"|([\p{L}\p{N}\p{M}_./\\:+@~-]+)) (clean|smudge)( --key-name [\w-]+)?$/u.exec(entry.value);
|
|
88
|
+
const program = crypt?.[1] ?? crypt?.[2];
|
|
89
|
+
if (program && isAbsolute(program) && /(?:^|[/\\])git-crypt(?:\.exe)?$/u.test(program) && crypt[3] === entry.field) {
|
|
90
|
+
const executable = externalExecutable(program, roots, 'git-crypt');
|
|
91
|
+
if (executable) {
|
|
92
|
+
overrides.set(entry.key, quote(executable) + ' ' + crypt[3] + (crypt[4] ?? ''));
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
throw new GitPolicyError('filter_blocked');
|
|
97
|
+
}
|
|
98
|
+
return [...overrides].map(([key, value]) => key + '=' + value);
|
|
99
|
+
}
|
|
100
|
+
/** Preserve existing user runtime pairs, append our policy, and reject malformed environments. */
|
|
101
|
+
export function gitEnvironment(env = process.env, overrides = []) {
|
|
102
|
+
const raw = env.GIT_CONFIG_COUNT ?? '', count = raw === '' ? 0 : Number(raw);
|
|
103
|
+
if (!/^(?:\d+)?$/u.test(raw) || !Number.isSafeInteger(count) || count > 1024)
|
|
104
|
+
throw new GitPolicyError('policy_unavailable');
|
|
105
|
+
const next = { ...env, GIT_OPTIONAL_LOCKS: '0', GIT_TERMINAL_PROMPT: '0', LC_ALL: 'C' };
|
|
106
|
+
for (let i = 0; i < count; i++)
|
|
107
|
+
if (env['GIT_CONFIG_KEY_' + i] === undefined || env['GIT_CONFIG_VALUE_' + i] === undefined)
|
|
108
|
+
throw new GitPolicyError('policy_unavailable');
|
|
109
|
+
[...BASE, ...overrides].forEach((pair, i) => {
|
|
110
|
+
const at = pair.indexOf('=');
|
|
111
|
+
next['GIT_CONFIG_KEY_' + (count + i)] = pair.slice(0, at);
|
|
112
|
+
next['GIT_CONFIG_VALUE_' + (count + i)] = pair.slice(at + 1);
|
|
113
|
+
});
|
|
114
|
+
next.GIT_CONFIG_COUNT = String(count + BASE.length + overrides.length);
|
|
115
|
+
// Git parses command-scope parameters after COUNT. Keep user parameters but
|
|
116
|
+
// append the policy last, including for Git children of provider programs.
|
|
117
|
+
next.GIT_CONFIG_PARAMETERS = [env.GIT_CONFIG_PARAMETERS ?? '', ...[...BASE, ...overrides].map(quote)].filter(Boolean).join(' ');
|
|
118
|
+
return next;
|
|
119
|
+
}
|
|
120
|
+
export class GitInvocation {
|
|
121
|
+
cwd;
|
|
122
|
+
run;
|
|
123
|
+
monotonic;
|
|
124
|
+
deadline;
|
|
125
|
+
environment;
|
|
126
|
+
constructor(cwd, timeoutMs, run = runCommand, monotonic = monotonicMilliseconds, env = process.env) {
|
|
127
|
+
this.cwd = cwd;
|
|
128
|
+
this.run = run;
|
|
129
|
+
this.monotonic = monotonic;
|
|
130
|
+
this.deadline = monotonic() + timeoutMs;
|
|
131
|
+
this.environment = gitEnvironment(env);
|
|
132
|
+
}
|
|
133
|
+
command(args, overrides = []) {
|
|
134
|
+
const timeoutMs = this.deadline - this.monotonic();
|
|
135
|
+
if (timeoutMs <= 0)
|
|
136
|
+
throw new CommandTimeout('Git deadline expired');
|
|
137
|
+
return this.run({ executable: 'git', args: ['-C', this.cwd, '--no-optional-locks', ...[...BASE, ...overrides].flatMap(pair => ['-c', pair]), ...args] }, { timeoutMs, environment: this.environment, maxOutputBytes: 4 * 1024 * 1024 });
|
|
138
|
+
}
|
|
139
|
+
/** Inspection commands do not scan tracked file contents or invoke filter programs. */
|
|
140
|
+
worktreePolicy(seen = new Set()) {
|
|
141
|
+
const config = this.command(['config', '--null', '--includes', '--show-scope', '--show-origin', '--get-regexp', '^filter\\..*\\.(clean|smudge|process|required)$']);
|
|
142
|
+
if (config.code !== 0 && !(config.code === 1 && !config.stdout.length))
|
|
143
|
+
throw new GitPolicyError(config.stderr.toString().includes('not a git repository') ? 'not_repo' : 'policy_unavailable');
|
|
144
|
+
const entries = filterEntries(config.stdout.toString('utf8'));
|
|
145
|
+
const index = this.command(['ls-files', '--stage', '-z', '--full-name', '--', ':/']);
|
|
146
|
+
if (index.code !== 0)
|
|
147
|
+
throw new GitPolicyError(index.stderr.toString().includes('not a git repository') ? 'not_repo' : 'policy_unavailable');
|
|
148
|
+
const submodules = index.stdout.toString('utf8').split('\0').filter(row => row.startsWith('160000 ')).map(row => row.slice(row.indexOf('\t') + 1));
|
|
149
|
+
if (!entries.length && !submodules.length)
|
|
150
|
+
return [];
|
|
151
|
+
const roots = this.command(['rev-parse', '--show-toplevel', '--absolute-git-dir', '--path-format=absolute', '--git-common-dir']);
|
|
152
|
+
if (roots.code !== 0)
|
|
153
|
+
throw new GitPolicyError('policy_unavailable');
|
|
154
|
+
const paths = roots.stdout.toString('utf8').trimEnd().split(/\r?\n/u);
|
|
155
|
+
if (paths.length !== 3 || paths.some(path => !isAbsolute(path)))
|
|
156
|
+
throw new GitPolicyError('policy_unavailable');
|
|
157
|
+
const canonical = paths.map(path => realpathSync.native(path)), top = canonical[0];
|
|
158
|
+
if (seen.has(top) || seen.size >= 64)
|
|
159
|
+
throw new GitPolicyError('policy_unavailable');
|
|
160
|
+
seen.add(top);
|
|
161
|
+
const overrides = filterOverrides(entries, canonical, this.environment);
|
|
162
|
+
for (const submodule of submodules) {
|
|
163
|
+
const child = resolve(top, submodule);
|
|
164
|
+
if (!inside(child, top) || child === top)
|
|
165
|
+
throw new GitPolicyError('policy_unavailable');
|
|
166
|
+
if (!existsSync(resolve(child, '.git')))
|
|
167
|
+
continue; // An uninitialized module cannot scan a worktree.
|
|
168
|
+
const nested = new GitInvocation(child, this.deadline - this.monotonic(), this.run, this.monotonic, this.environment).worktreePolicy(seen);
|
|
169
|
+
for (const value of nested) {
|
|
170
|
+
const key = value.slice(0, value.indexOf('='));
|
|
171
|
+
if (overrides.some(previous => previous.startsWith(key + '=') && previous !== value))
|
|
172
|
+
throw new GitPolicyError('policy_unavailable');
|
|
173
|
+
if (!overrides.includes(value))
|
|
174
|
+
overrides.push(value);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return overrides;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
//# sourceMappingURL=git.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git.js","sourceRoot":"","sources":["../../src/git.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACpF,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAAE,cAAc,EAA0C,MAAM,cAAc,CAAC;AACzH,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,+EAA+E;AAC/E,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC;AACpC,MAAM,IAAI,GAAG,CAAC,iBAAiB,EAAE,8BAA8B,CAAC,CAAC;AACjE,MAAM,OAAO,cAAe,SAAQ,KAAK;IACT;IAA5B,YAA4B,MAA4D;QAAI,KAAK,CAAC,MAAM,CAAC,CAAC;QAA9E,WAAM,GAAN,MAAM,CAAsD;IAAmB,CAAC;CAC/G;AAED,MAAM,UAAU,aAAa,CAAC,GAAW;IACrC,IAAI,CAAC,GAAG;QAAE,OAAO,EAAE,CAAC;IACpB,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC9B,IAAI,KAAK,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,KAAK,CAAC,MAAM,GAAG,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K,CAAC;oBAAE,MAAM,IAAI,cAAc,CAAC,oBAAoB,CAAC,CAAC;gBACrI,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC;oBAAE,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC1D,CAAC;QACL,CAAC;QACD,OAAO,SAAS,CAAC;IACrB,CAAC;CACJ"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type PackageIdentity } from '@fbincon/statusline-core/management/package';
|
|
2
|
+
import { type PackageCompatibility } from '@fbincon/statusline-core/management/compatibility';
|
|
3
|
+
import { type SourceProcessOptions, type SourceProcessResult } from './source-process.js';
|
|
4
|
+
export interface NpmLayout {
|
|
5
|
+
prefix: string;
|
|
6
|
+
root: string;
|
|
7
|
+
bin: string;
|
|
8
|
+
registry: string;
|
|
9
|
+
npmVersion: string;
|
|
10
|
+
cache: string;
|
|
11
|
+
}
|
|
12
|
+
export interface RegistryPackage {
|
|
13
|
+
version: string;
|
|
14
|
+
registry: string;
|
|
15
|
+
integrity: string;
|
|
16
|
+
nodeEngine: string;
|
|
17
|
+
compatibility: PackageCompatibility;
|
|
18
|
+
legacy: boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare const globalPackageRoot: (prefix: string) => string;
|
|
21
|
+
export declare const globalPackageBin: (prefix: string) => string;
|
|
22
|
+
export declare function verifyArchive(path: string, target: RegistryPackage): void;
|
|
23
|
+
export declare function within(path: string, root: string): boolean;
|
|
24
|
+
export declare function productRoot(start: string): string | null;
|
|
25
|
+
export declare function productIdentity(root: string, prefix?: string): PackageIdentity | null;
|
|
26
|
+
export declare function npmEntry(environment?: NodeJS.ProcessEnv): string;
|
|
27
|
+
export declare function writablePrefix(prefix: string): void;
|
|
28
|
+
export declare class Npm {
|
|
29
|
+
readonly environment: NodeJS.ProcessEnv;
|
|
30
|
+
readonly runner: (options: SourceProcessOptions) => Promise<SourceProcessResult>;
|
|
31
|
+
readonly signal?: AbortSignal | undefined;
|
|
32
|
+
readonly entry: string;
|
|
33
|
+
onProcess?: (pid: number | null) => void;
|
|
34
|
+
constructor(environment?: NodeJS.ProcessEnv, runner?: (options: SourceProcessOptions) => Promise<SourceProcessResult>, entry?: string, signal?: AbortSignal | undefined);
|
|
35
|
+
run(args: readonly string[], cwd?: string, timeoutMs?: number): Promise<string>;
|
|
36
|
+
layout(explicit?: string): Promise<NpmLayout>;
|
|
37
|
+
verify(identity: PackageIdentity, bin?: string): Promise<void>;
|
|
38
|
+
install(version: string, layout: NpmLayout): Promise<void>;
|
|
39
|
+
metadata(selector: string, layout: NpmLayout): Promise<RegistryPackage>;
|
|
40
|
+
download(target: RegistryPackage, directory: string): Promise<string>;
|
|
41
|
+
installArchive(archive: string, prefix: string): Promise<void>;
|
|
42
|
+
nodeCompatible(range: string): Promise<boolean>;
|
|
43
|
+
validateStaged(prefix: string, target: RegistryPackage): Promise<PackageIdentity>;
|
|
44
|
+
}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import { dirname, join, isAbsolute } from 'node:path';
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
import { PACKAGE_NAME } from '@fbincon/statusline-core/release';
|
|
5
|
+
import { PackageError, exactVersion } from '@fbincon/statusline-core/management/package';
|
|
6
|
+
import { compatibility, LEGACY_370_SHA256 } from '@fbincon/statusline-core/management/compatibility';
|
|
7
|
+
import { equalSettings } from '@fbincon/statusline-core/json-equality';
|
|
8
|
+
import { which, resolvedPath, sameLaunchEntry } from './commands.js';
|
|
9
|
+
import { runSourceProcess } from './source-process.js';
|
|
10
|
+
export const globalPackageRoot = (prefix) => join(prefix, process.platform === 'win32' ? 'node_modules' : 'lib/node_modules', PACKAGE_NAME);
|
|
11
|
+
export const globalPackageBin = (prefix) => join(prefix, process.platform === 'win32' ? 'claude-statusline.cmd' : 'bin/claude-statusline');
|
|
12
|
+
export function verifyArchive(path, target) {
|
|
13
|
+
const stat = fs.lstatSync(path);
|
|
14
|
+
if (!stat.isFile() || stat.isSymbolicLink() || stat.size > 64 * 1024 * 1024)
|
|
15
|
+
throw new PackageError('integrity');
|
|
16
|
+
const bytes = fs.readFileSync(path);
|
|
17
|
+
if ('sha512-' + createHash('sha512').update(bytes).digest('base64') !== target.integrity || target.legacy && createHash('sha256').update(bytes).digest('hex') !== LEGACY_370_SHA256)
|
|
18
|
+
throw new PackageError('integrity');
|
|
19
|
+
}
|
|
20
|
+
export function within(path, root) { const normalized = resolvedPath(path), base = resolvedPath(root); return normalized === base || normalized.startsWith(base + (process.platform === 'win32' ? '\\' : '/')); }
|
|
21
|
+
export function productRoot(start) {
|
|
22
|
+
for (let root = dirname(start), n = 0; n < 12; n++, root = dirname(root)) {
|
|
23
|
+
try {
|
|
24
|
+
if (JSON.parse(fs.readFileSync(join(root, 'package.json'), 'utf8')).name === PACKAGE_NAME)
|
|
25
|
+
return fs.realpathSync.native(root);
|
|
26
|
+
}
|
|
27
|
+
catch { /* Continue to the enclosing public package. */ }
|
|
28
|
+
if (dirname(root) === root)
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
export function productIdentity(root, prefix = '') {
|
|
34
|
+
if (!fs.existsSync(root))
|
|
35
|
+
return null;
|
|
36
|
+
try {
|
|
37
|
+
if (fs.lstatSync(root).isSymbolicLink())
|
|
38
|
+
throw new Error('linked product');
|
|
39
|
+
const manifest = JSON.parse(fs.readFileSync(join(root, 'package.json'), 'utf8'));
|
|
40
|
+
if (manifest.name !== PACKAGE_NAME || !exactVersion(manifest.version) || manifest.bin?.['claude-statusline'] !== 'bin/claude-statusline.js')
|
|
41
|
+
throw new Error('identity');
|
|
42
|
+
const entry = join(root, 'node_modules/@fbincon/statusline-cli/dist/src/entry.js');
|
|
43
|
+
const inventoryBytes = fs.readFileSync(join(root, 'candidate.json'));
|
|
44
|
+
const inventory = JSON.parse(inventoryBytes.toString('utf8'));
|
|
45
|
+
if (inventory.name !== PACKAGE_NAME || inventory.version !== manifest.version || inventory.application_version !== manifest.version)
|
|
46
|
+
throw new Error('inventory');
|
|
47
|
+
for (const file of ['bin/claude-statusline.js', 'node_modules/@fbincon/statusline-cli/dist/src/entry.js', 'node_modules/@fbincon/statusline-core/dist/src/release.js']) {
|
|
48
|
+
if (fs.lstatSync(join(root, file)).isSymbolicLink() || createHash('sha256').update(fs.readFileSync(join(root, file))).digest('hex') !== inventory.files?.[file])
|
|
49
|
+
throw new Error('bytes');
|
|
50
|
+
}
|
|
51
|
+
return { version: manifest.version, root: fs.realpathSync.native(root), entry: fs.realpathSync.native(entry), prefix, integrity: null, registry: null, inventory_sha256: createHash('sha256').update(inventoryBytes).digest('hex') };
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
throw new PackageError('identity');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export function npmEntry(environment = process.env) {
|
|
58
|
+
const found = which('npm', environment);
|
|
59
|
+
const choices = [environment.npm_execpath, found && resolvedPath(found), found && join(dirname(found), 'node_modules/npm/bin/npm-cli.js'),
|
|
60
|
+
join(dirname(process.execPath), 'node_modules/npm/bin/npm-cli.js'), join(dirname(process.execPath), '../lib/node_modules/npm/bin/npm-cli.js')];
|
|
61
|
+
for (const path of choices)
|
|
62
|
+
if (path) {
|
|
63
|
+
try {
|
|
64
|
+
const actual = fs.realpathSync.native(path);
|
|
65
|
+
if (actual.endsWith('npm-cli.js') && JSON.parse(fs.readFileSync(join(dirname(actual), '../package.json'), 'utf8')).name === 'npm')
|
|
66
|
+
return actual;
|
|
67
|
+
}
|
|
68
|
+
catch { /* Try another standard npm installation. Never execute a batch shim. */ }
|
|
69
|
+
}
|
|
70
|
+
throw new PackageError('npm_missing');
|
|
71
|
+
}
|
|
72
|
+
export function writablePrefix(prefix) {
|
|
73
|
+
let parent = prefix;
|
|
74
|
+
while (!fs.existsSync(parent) && parent !== dirname(parent))
|
|
75
|
+
parent = dirname(parent);
|
|
76
|
+
try {
|
|
77
|
+
if (!fs.statSync(parent).isDirectory())
|
|
78
|
+
throw new Error();
|
|
79
|
+
fs.accessSync(parent, fs.constants.W_OK | (process.platform === 'win32' ? 0 : fs.constants.X_OK));
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
throw new PackageError('permissions');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
export class Npm {
|
|
86
|
+
environment;
|
|
87
|
+
runner;
|
|
88
|
+
signal;
|
|
89
|
+
entry;
|
|
90
|
+
onProcess;
|
|
91
|
+
constructor(environment = process.env, runner = runSourceProcess, entry, signal) {
|
|
92
|
+
this.environment = environment;
|
|
93
|
+
this.runner = runner;
|
|
94
|
+
this.signal = signal;
|
|
95
|
+
this.entry = entry ?? npmEntry(environment);
|
|
96
|
+
}
|
|
97
|
+
async run(args, cwd = process.cwd(), timeoutMs = 30000) {
|
|
98
|
+
const result = await this.runner({ executable: process.execPath, args: [this.entry, ...args], cwd, input: '', timeoutMs, signal: this.signal, onProcess: this.onProcess,
|
|
99
|
+
environment: { ...this.environment, npm_config_update_notifier: 'false', npm_config_audit: 'false', npm_config_fund: 'false' } });
|
|
100
|
+
if (result.reason !== 'completed') {
|
|
101
|
+
// npm's --json failure object has a stable code. Never forward its
|
|
102
|
+
// free-form detail, which can contain private registry information.
|
|
103
|
+
let code;
|
|
104
|
+
try {
|
|
105
|
+
code = JSON.parse(result.stdout)?.error?.code;
|
|
106
|
+
}
|
|
107
|
+
catch { /* Not JSON. */ }
|
|
108
|
+
if (code === 'EINTEGRITY')
|
|
109
|
+
throw new PackageError('integrity');
|
|
110
|
+
throw new PackageError(result.reason === 'cancelled' ? 'interrupted' : result.reason === 'timeout' ? 'timeout' : 'npm_failed');
|
|
111
|
+
}
|
|
112
|
+
return result.stdout.trim();
|
|
113
|
+
}
|
|
114
|
+
async layout(explicit) {
|
|
115
|
+
const reported = explicit ?? await this.run(['prefix', '--global']);
|
|
116
|
+
if (explicit === undefined && !isAbsolute(reported))
|
|
117
|
+
throw new PackageError('prefix');
|
|
118
|
+
const prefix = resolvedPath(reported);
|
|
119
|
+
if (!isAbsolute(prefix) || /[\0\r\n]/u.test(prefix))
|
|
120
|
+
throw new PackageError('prefix');
|
|
121
|
+
// npm invocations share configuration/cache initialization. Serialize
|
|
122
|
+
// preflight, including the native Windows process supervisor startup.
|
|
123
|
+
const moduleRoot = await this.run(['root', '--global', '--prefix', prefix]);
|
|
124
|
+
const npmVersion = await this.run(['--version']);
|
|
125
|
+
const scoped = await this.run(['config', 'get', '@fbincon:registry']);
|
|
126
|
+
const cache = await this.run(['config', 'get', 'cache']);
|
|
127
|
+
const registry = scoped && scoped !== 'undefined' && scoped !== 'null' ? scoped : await this.run(['config', 'get', 'registry']);
|
|
128
|
+
try {
|
|
129
|
+
const url = new URL(registry);
|
|
130
|
+
if (!['https:', 'http:'].includes(url.protocol) || url.username || url.password || url.search || url.hash)
|
|
131
|
+
throw new Error();
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
throw new PackageError('registry');
|
|
135
|
+
}
|
|
136
|
+
if (!isAbsolute(moduleRoot) || /[\0\r\n]/u.test(moduleRoot))
|
|
137
|
+
throw new PackageError('prefix');
|
|
138
|
+
const expected = process.platform === 'win32' ? join(prefix, 'node_modules') : join(prefix, 'lib/node_modules');
|
|
139
|
+
if (resolvedPath(moduleRoot) !== resolvedPath(expected))
|
|
140
|
+
throw new PackageError('prefix');
|
|
141
|
+
if (!isAbsolute(cache) || within(prefix, cache))
|
|
142
|
+
throw new PackageError('prefix');
|
|
143
|
+
return { prefix, root: join(moduleRoot, PACKAGE_NAME), bin: join(prefix, process.platform === 'win32' ? 'claude-statusline.cmd' : 'bin/claude-statusline'), registry, npmVersion, cache: resolvedPath(cache) };
|
|
144
|
+
}
|
|
145
|
+
async verify(identity, bin) {
|
|
146
|
+
if (bin && !sameLaunchEntry(bin, { executable: process.execPath, args: [identity.entry] }))
|
|
147
|
+
throw new PackageError('identity');
|
|
148
|
+
const result = await this.runner({ executable: process.execPath, args: [identity.entry, '--version'], cwd: identity.root, input: '', timeoutMs: 10000, signal: this.signal, environment: this.environment });
|
|
149
|
+
if (result.reason !== 'completed' || result.stdout.trim() !== 'claude-statusline ' + identity.version)
|
|
150
|
+
throw new PackageError('identity');
|
|
151
|
+
}
|
|
152
|
+
async install(version, layout) {
|
|
153
|
+
if (!exactVersion(version))
|
|
154
|
+
throw new PackageError('version');
|
|
155
|
+
await this.run(['install', '--global', '--prefix', layout.prefix, '--registry', layout.registry, '--ignore-scripts', '--bin-links=true', '--no-audit', '--no-fund', PACKAGE_NAME + '@' + version], process.cwd(), 180000);
|
|
156
|
+
}
|
|
157
|
+
async metadata(selector, layout) {
|
|
158
|
+
if (!exactVersion(selector) && !['latest', 'beta'].includes(selector))
|
|
159
|
+
throw new PackageError('version');
|
|
160
|
+
let value;
|
|
161
|
+
try {
|
|
162
|
+
value = JSON.parse(await this.run(['view', PACKAGE_NAME + '@' + selector, '--json', '--registry', layout.registry]));
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
if (error instanceof PackageError)
|
|
166
|
+
throw error;
|
|
167
|
+
throw new PackageError('metadata');
|
|
168
|
+
}
|
|
169
|
+
if (!value || Array.isArray(value) || value.name !== PACKAGE_NAME || !exactVersion(value.version) || exactVersion(selector) && value.version !== selector ||
|
|
170
|
+
typeof value.dist?.integrity !== 'string' || !/^sha512-[A-Za-z0-9+/]{86}==$/u.test(value.dist.integrity) || typeof value.engines?.node !== 'string' || value.engines.node.length > 256 || /[\p{Cc}\p{Cs}]/u.test(value.engines.node))
|
|
171
|
+
throw new PackageError('metadata');
|
|
172
|
+
if (value.version === '3.7.0' && value.statuslineCompatibility !== undefined)
|
|
173
|
+
throw new PackageError('metadata');
|
|
174
|
+
return { version: value.version, registry: layout.registry, integrity: value.dist.integrity, nodeEngine: value.engines.node,
|
|
175
|
+
compatibility: compatibility(value.statuslineCompatibility, value.version), legacy: value.version === '3.7.0' };
|
|
176
|
+
}
|
|
177
|
+
async download(target, directory) {
|
|
178
|
+
fs.mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
179
|
+
let result;
|
|
180
|
+
try {
|
|
181
|
+
result = JSON.parse(await this.run(['pack', PACKAGE_NAME + '@' + target.version, '--json', '--ignore-scripts', '--registry', target.registry, '--pack-destination', directory], directory, 180000));
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
if (error instanceof PackageError)
|
|
185
|
+
throw error;
|
|
186
|
+
throw new PackageError('metadata');
|
|
187
|
+
}
|
|
188
|
+
const filename = PACKAGE_NAME.replace('@', '').replace('/', '-') + '-' + target.version + '.tgz';
|
|
189
|
+
if (!Array.isArray(result) || result.length !== 1 || result[0]?.filename !== filename)
|
|
190
|
+
throw new PackageError('metadata');
|
|
191
|
+
const path = join(directory, filename);
|
|
192
|
+
verifyArchive(path, target);
|
|
193
|
+
return path;
|
|
194
|
+
}
|
|
195
|
+
async installArchive(archive, prefix) {
|
|
196
|
+
await this.run(['install', '--global', '--prefix', prefix, '--offline', '--ignore-scripts', '--bin-links=true', '--engine-strict=true', '--no-audit', '--no-fund', archive], dirname(archive), 180000);
|
|
197
|
+
}
|
|
198
|
+
async nodeCompatible(range) {
|
|
199
|
+
const program = "const {createRequire}=require('node:module');const semver=createRequire(process.argv[1])('semver');process.stdout.write(String(!!semver.validRange(process.argv[2]) && semver.satisfies(process.versions.node,process.argv[2])));";
|
|
200
|
+
const result = await this.runner({ executable: process.execPath, args: ['-e', program, this.entry, range], cwd: dirname(this.entry), input: '', timeoutMs: 10000, environment: this.environment, signal: this.signal });
|
|
201
|
+
if (result.reason !== 'completed' || !['true', 'false'].includes(result.stdout))
|
|
202
|
+
throw new PackageError('compatibility_unknown');
|
|
203
|
+
return result.stdout === 'true';
|
|
204
|
+
}
|
|
205
|
+
async validateStaged(prefix, target) {
|
|
206
|
+
const root = globalPackageRoot(prefix), identity = productIdentity(root, prefix);
|
|
207
|
+
if (!identity || identity.version !== target.version)
|
|
208
|
+
throw new PackageError('identity');
|
|
209
|
+
const manifest = JSON.parse(fs.readFileSync(join(root, 'package.json'), 'utf8'));
|
|
210
|
+
if (manifest.engines?.node !== target.nodeEngine || !equalSettings(compatibility(manifest.statuslineCompatibility, target.version), target.compatibility) || (manifest.statuslineCompatibility === undefined) !== target.legacy)
|
|
211
|
+
throw new PackageError('identity');
|
|
212
|
+
await this.verify(identity, globalPackageBin(prefix));
|
|
213
|
+
for (const [name, protocol] of [['statusline-native', target.compatibility.editor_protocol], ['statusline-runtime', target.compatibility.runtime_protocol]]) {
|
|
214
|
+
const resources = join(root, 'node_modules/@fbincon/statusline-cli/resources', name);
|
|
215
|
+
const descriptor = JSON.parse(fs.readFileSync(join(resources, 'resource-manifest.json'), 'utf8'));
|
|
216
|
+
if (descriptor.backend_version !== target.version || descriptor.mod_version !== target.version || descriptor.protocol_version !== protocol)
|
|
217
|
+
throw new PackageError('identity');
|
|
218
|
+
for (const [file, hash] of Object.entries(descriptor.files ?? {})) {
|
|
219
|
+
if (file.startsWith('/') || file.includes('\\') || file.split('/').some(part => !part || part === '..' || part === '.') || typeof hash !== 'string')
|
|
220
|
+
throw new PackageError('identity');
|
|
221
|
+
const path = join(resources, file);
|
|
222
|
+
if (fs.lstatSync(path).isSymbolicLink() || createHash('sha256').update(fs.readFileSync(path)).digest('hex') !== hash)
|
|
223
|
+
throw new PackageError('identity');
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return { ...identity, integrity: target.integrity, registry: target.registry };
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
//# sourceMappingURL=npm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"npm.js","sourceRoot":"","sources":["../../src/npm.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,IAAI,EAAW,UAAU,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAA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@
|
|
|
1
|
+
/** Copy an installed package before loading any native adapter from it. */
|
|
2
|
+
import * as fs from 'node:fs';
|
|
3
|
+
import { dirname, isAbsolute, join, relative, sep } from 'node:path';
|
|
4
|
+
import { resolvedPath } from './commands.js';
|
|
5
|
+
import { removeTree } from './remove-tree.js';
|
|
6
|
+
export function copyPackage(source, destination, limits = { entries: 16384, bytes: 256 * 1024 * 1024 }) {
|
|
7
|
+
// Resolve existing ancestors on both sides, including Windows short names
|
|
8
|
+
// and junctions, before accepting an absent destination below them.
|
|
9
|
+
const origin = fs.realpathSync.native(source), target = resolvedPath(destination);
|
|
10
|
+
const inside = relative(origin, target);
|
|
11
|
+
if (!inside || !isAbsolute(inside) && inside !== '..' && !inside.startsWith('..' + sep))
|
|
12
|
+
throw new Error('Package copy destination must be outside the source');
|
|
13
|
+
if (!fs.lstatSync(source).isDirectory())
|
|
14
|
+
throw new Error('Package copy source must be a regular directory');
|
|
15
|
+
fs.mkdirSync(dirname(target), { recursive: true, mode: 0o700 });
|
|
16
|
+
fs.mkdirSync(target, { mode: 0o700 });
|
|
17
|
+
let entries = 0, bytes = 0;
|
|
18
|
+
const pending = [{ source: origin, destination: target }];
|
|
19
|
+
try {
|
|
20
|
+
while (pending.length) {
|
|
21
|
+
const directory = pending.pop();
|
|
22
|
+
for (const name of fs.readdirSync(directory.source)) {
|
|
23
|
+
if (++entries > limits.entries)
|
|
24
|
+
throw new Error('Package copy exceeds its entry limit');
|
|
25
|
+
const from = join(directory.source, name), to = join(directory.destination, name), stat = fs.lstatSync(from);
|
|
26
|
+
if (stat.isDirectory()) {
|
|
27
|
+
fs.mkdirSync(to, { mode: 0o700 });
|
|
28
|
+
pending.push({ source: from, destination: to });
|
|
29
|
+
}
|
|
30
|
+
else if (stat.isFile()) {
|
|
31
|
+
bytes += stat.size;
|
|
32
|
+
if (bytes > limits.bytes)
|
|
33
|
+
throw new Error('Package copy exceeds its byte limit');
|
|
34
|
+
// Avoid fs.cpSync: Node 22.23.4 Windows acceptance exited
|
|
35
|
+
// with 0xC0000409 inside that call, before native loading.
|
|
36
|
+
fs.copyFileSync(from, to, fs.constants.COPYFILE_EXCL);
|
|
37
|
+
fs.chmodSync(to, stat.mode & 0o111 ? 0o700 : 0o600);
|
|
38
|
+
}
|
|
39
|
+
else
|
|
40
|
+
throw new Error('Package copy contains a link or special file');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
removeTree(target);
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=package-copy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-copy.js","sourceRoot":"","sources":["../../src/package-copy.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,MAAM,UAAU,WAAW,CAAC,MAAc,EAAE,WAAmB,EAAE,MAAM,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI,GAAG,IAAI,EAAE;IAClH,0EAA0E;IAC1E,oEAAoE;IACpE,MAAM,MAAM,GAAG,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,YAAY,CAAC,WAAW,CAAC,CAAC;IAClF,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,IAAI,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,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AC,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,CAAC;gBACpD,CAAC;qBACI,IAAI,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;oBACrB,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC;oBACnB,IAAI,KAAK,GAAG,MAAM,CAAC,KAAK;wBACpB,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;oBAC3D,0DAA0D;oBAC1D,2DAA2D;oBAC3D,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;oBACtD,EAAE,CAAC,SAAS,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;gBACxD,CAAC;;oBAEG,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;YACxE,CAAC;QACL,CAAC;IACL,CAAC;IACD,OAAO,KAAK,EAAE,CAAC;QACX,UAAU,CAAC,MAAM,CAAC,CAAC;QACnB,MAAM,KAAK,CAAC;IAChB,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** Remove caller-owned files without the old Windows rmSync Unicode bug. */
|
|
2
|
+
import * as fs from 'node:fs';
|
|
3
|
+
import { dirname, join, resolve } from 'node:path';
|
|
4
|
+
function remove(path, directory) {
|
|
5
|
+
for (const delay of [10, 20, 40, 80, 160, null]) {
|
|
6
|
+
try {
|
|
7
|
+
if (directory)
|
|
8
|
+
fs.rmdirSync(path);
|
|
9
|
+
else
|
|
10
|
+
fs.unlinkSync(path);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
const code = error.code;
|
|
15
|
+
if (code === 'ENOENT')
|
|
16
|
+
return;
|
|
17
|
+
if (process.platform !== 'win32' || delay === null || !['EACCES', 'EPERM', 'EBUSY', 'ENOTEMPTY'].includes(code ?? ''))
|
|
18
|
+
throw error;
|
|
19
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, delay);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/** The caller supplies its own private/owned target. Links are removed, never traversed. */
|
|
24
|
+
export function removeTree(path) {
|
|
25
|
+
const root = resolve(path);
|
|
26
|
+
if (dirname(root) === root)
|
|
27
|
+
throw new Error('Cannot remove a filesystem root');
|
|
28
|
+
const pending = [{ path: root, visited: false }];
|
|
29
|
+
while (pending.length) {
|
|
30
|
+
const entry = pending.pop();
|
|
31
|
+
let stat;
|
|
32
|
+
try {
|
|
33
|
+
stat = fs.lstatSync(entry.path);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
if (error.code === 'ENOENT')
|
|
37
|
+
continue;
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
if (!stat.isDirectory())
|
|
41
|
+
remove(entry.path, false);
|
|
42
|
+
else if (entry.visited)
|
|
43
|
+
remove(entry.path, true);
|
|
44
|
+
else {
|
|
45
|
+
pending.push({ ...entry, visited: true });
|
|
46
|
+
for (const name of fs.readdirSync(entry.path))
|
|
47
|
+
pending.push({ path: join(entry.path, name), visited: false });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=remove-tree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove-tree.js","sourceRoot":"","sources":["../../src/remove-tree.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEnD,SAAS,MAAM,CAAC,IAAY,EAAE,SAAkB;IAC5C,KAAK,MAAM,KAAK,IAAI,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,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