@deepseek-harness-tui/dsh-tui 0.18.0 → 0.20.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 +90 -59
- package/bin/dsh-tui.js +46 -3
- package/cordis.patch.yml +5 -3
- package/cordis.yml +3 -2
- package/guide/dsh-tui-guide/codex-backend.en.md +2 -2
- package/guide/dsh-tui-guide/codex-backend.md +2 -2
- package/guide/dsh-tui-guide/configuration.en.md +7 -2
- package/guide/dsh-tui-guide/configuration.md +7 -2
- package/guide/dsh-tui-guide/getting-started.en.md +168 -4
- package/guide/dsh-tui-guide/getting-started.md +121 -14
- package/guide/dsh-tui-guide/interaction.en.md +11 -10
- package/guide/dsh-tui-guide/interaction.md +5 -4
- package/guide/dsh-tui-guide/user-guide.en.md +12 -6
- package/guide/dsh-tui-guide/user-guide.md +12 -6
- package/lib/settings.json +24 -8
- package/lib/types/adapter/ports/channel-ui.d.ts +10 -7
- package/lib/types/adapter/ports/channel-ui.d.ts.map +1 -1
- package/lib/types/adapter/ports/channel-view.d.ts +67 -8
- package/lib/types/adapter/ports/channel-view.d.ts.map +1 -1
- package/lib/types/agent/events.d.ts +14 -5
- package/lib/types/agent/events.d.ts.map +1 -1
- package/lib/types/agent/session.d.ts +5 -0
- package/lib/types/agent/session.d.ts.map +1 -1
- package/lib/types/backends/claude/tools.d.ts.map +1 -1
- package/lib/types/backends/claude/tools.js +8 -3
- package/lib/types/backends/claude/translate/core.d.ts +2 -2
- package/lib/types/backends/claude/translate/core.d.ts.map +1 -1
- package/lib/types/backends/claude/translate/core.js +10 -6
- package/lib/types/backends/codex/session/commands.d.ts +2 -0
- package/lib/types/backends/codex/session/commands.d.ts.map +1 -1
- package/lib/types/backends/codex/session/commands.js +8 -4
- package/lib/types/backends/codex/session/input.d.ts +11 -7
- package/lib/types/backends/codex/session/input.d.ts.map +1 -1
- package/lib/types/backends/codex/session/input.js +68 -15
- package/lib/types/backends/codex/session/session.d.ts.map +1 -1
- package/lib/types/backends/codex/session/session.js +2 -3
- package/lib/types/backends/codex/translate/presentation.d.ts.map +1 -1
- package/lib/types/backends/codex/translate/presentation.js +5 -2
- package/lib/types/channel/interaction.d.ts.map +1 -1
- package/lib/types/channel/interaction.js +1 -0
- package/lib/types/channel/permissions.d.ts +15 -0
- package/lib/types/channel/permissions.d.ts.map +1 -1
- package/lib/types/channel/permissions.js +28 -0
- package/lib/types/channel/projection.d.ts.map +1 -1
- package/lib/types/channel/projection.js +89 -11
- package/lib/types/channel/questions.d.ts +45 -3
- package/lib/types/channel/questions.d.ts.map +1 -1
- package/lib/types/channel/questions.js +43 -0
- package/lib/types/channel/sanitize.d.ts.map +1 -1
- package/lib/types/channel/sanitize.js +8 -4
- package/lib/types/channel/subagent-failure.d.ts +49 -0
- package/lib/types/channel/subagent-failure.d.ts.map +1 -0
- package/lib/types/channel/subagent-failure.js +59 -0
- package/lib/types/channel/transcript.d.ts +17 -0
- package/lib/types/channel/transcript.d.ts.map +1 -1
- package/lib/types/channel/transcript.js +35 -0
- package/lib/types/commands.js +2 -2
- package/lib/types/components/MessageList.d.ts.map +1 -1
- package/lib/types/components/MessageList.js +14 -10
- package/lib/types/components/PromptInput.d.ts.map +1 -1
- package/lib/types/components/PromptInput.js +61 -6
- package/lib/types/components/SplitDiffView.d.ts.map +1 -1
- package/lib/types/components/SplitDiffView.js +3 -2
- package/lib/types/components/StarPrompt.d.ts +5 -3
- package/lib/types/components/StarPrompt.d.ts.map +1 -1
- package/lib/types/components/StarPrompt.js +56 -6
- package/lib/types/components/SubagentCard.d.ts.map +1 -1
- package/lib/types/components/SubagentCard.js +1 -1
- package/lib/types/components/SubagentDashboard.d.ts.map +1 -1
- package/lib/types/components/SubagentDashboard.js +9 -2
- package/lib/types/components/SubagentDetailScene.d.ts.map +1 -1
- package/lib/types/components/SubagentDetailScene.js +1 -1
- package/lib/types/components/messages/AssistantToolUseMessage.d.ts.map +1 -1
- package/lib/types/components/messages/AssistantToolUseMessage.js +126 -25
- package/lib/types/components/questions/AskUserQuestionPanel.d.ts +5 -8
- package/lib/types/components/questions/AskUserQuestionPanel.d.ts.map +1 -1
- package/lib/types/components/questions/AskUserQuestionPanel.js +7 -4
- package/lib/types/components/questions/PlanReviewPanel.d.ts +3 -6
- package/lib/types/components/questions/PlanReviewPanel.d.ts.map +1 -1
- package/lib/types/components/revealScope.d.ts +15 -0
- package/lib/types/components/revealScope.d.ts.map +1 -0
- package/lib/types/components/revealScope.js +17 -0
- package/lib/types/components/sidePanel/btw/BtwComposer.d.ts +34 -1
- package/lib/types/components/sidePanel/btw/BtwComposer.d.ts.map +1 -1
- package/lib/types/components/sidePanel/btw/BtwComposer.js +108 -7
- package/lib/types/components/sidePanel/btw/BtwPanelAdapter.d.ts.map +1 -1
- package/lib/types/components/sidePanel/btw/BtwPanelAdapter.js +1 -1
- package/lib/types/components/sidePanel/btw/BtwThreadScene.d.ts.map +1 -1
- package/lib/types/components/sidePanel/btw/BtwThreadScene.js +1 -1
- package/lib/types/components/smoothReveal.d.ts +36 -6
- package/lib/types/components/smoothReveal.d.ts.map +1 -1
- package/lib/types/components/smoothReveal.js +92 -21
- package/lib/types/components/teamRoster.d.ts +6 -3
- package/lib/types/components/teamRoster.d.ts.map +1 -1
- package/lib/types/components/workspaces/HomeWorkspaceRow.d.ts +4 -14
- package/lib/types/components/workspaces/HomeWorkspaceRow.d.ts.map +1 -1
- package/lib/types/components/workspaces/HomeWorkspaceRow.js +26 -17
- package/lib/types/dsh-adapter/approvals.d.ts +19 -0
- package/lib/types/dsh-adapter/approvals.d.ts.map +1 -1
- package/lib/types/dsh-adapter/approvals.js +17 -1
- package/lib/types/dsh-adapter/backend/session.d.ts.map +1 -1
- package/lib/types/dsh-adapter/backend/session.js +12 -0
- package/lib/types/dsh-adapter/backend/translate.d.ts.map +1 -1
- package/lib/types/dsh-adapter/backend/translate.js +21 -4
- package/lib/types/dsh-adapter/channel/attached-context.d.ts +15 -2
- package/lib/types/dsh-adapter/channel/attached-context.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/attached-context.js +26 -3
- package/lib/types/dsh-adapter/channel/binding-events.d.ts +3 -0
- package/lib/types/dsh-adapter/channel/binding-events.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/binding-events.js +43 -2
- package/lib/types/dsh-adapter/channel/context-bookkeeping.d.ts +2 -6
- package/lib/types/dsh-adapter/channel/context-bookkeeping.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/context-bookkeeping.js +7 -1
- package/lib/types/dsh-adapter/channel/core/compose.d.ts +2 -6
- package/lib/types/dsh-adapter/channel/core/compose.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/core/compose.js +1 -1
- package/lib/types/dsh-adapter/channel/core/local-actions.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/core/local-actions.js +3 -26
- package/lib/types/dsh-adapter/channel/emitter.js +1 -1
- package/lib/types/dsh-adapter/channel/extensions.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/extensions.js +15 -4
- package/lib/types/dsh-adapter/channel/input-actions.d.ts +2 -2
- package/lib/types/dsh-adapter/channel/input-actions.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/input-actions.js +34 -10
- package/lib/types/dsh-adapter/channel/input-delivery.d.ts +3 -7
- package/lib/types/dsh-adapter/channel/input-delivery.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/input-delivery.js +14 -5
- package/lib/types/dsh-adapter/channel/local-actions.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/local-actions.js +7 -3
- package/lib/types/dsh-adapter/channel/model-actions.d.ts +4 -1
- package/lib/types/dsh-adapter/channel/model-actions.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/model-actions.js +26 -9
- package/lib/types/dsh-adapter/channel/model-selection.d.ts +27 -2
- package/lib/types/dsh-adapter/channel/model-selection.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/model-selection.js +81 -37
- package/lib/types/dsh-adapter/channel/model-switch.d.ts +1 -1
- package/lib/types/dsh-adapter/channel/model-switch.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/projection-helpers.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/projection-helpers.js +4 -2
- package/lib/types/dsh-adapter/channel/session-rewind.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/session-rewind.js +6 -2
- package/lib/types/dsh-adapter/channel/session-tree-actions.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/session-tree-actions.js +8 -4
- package/lib/types/dsh-adapter/channel/settings-host.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/settings-host.js +185 -36
- package/lib/types/dsh-adapter/channel/subagent-projection.d.ts +55 -4
- package/lib/types/dsh-adapter/channel/subagent-projection.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/subagent-projection.js +80 -16
- package/lib/types/dsh-adapter/channel/subagent-transcript.d.ts +1 -1
- package/lib/types/dsh-adapter/channel/subagent-transcript.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/subagent-transcript.js +6 -5
- package/lib/types/dsh-adapter/channel/task-completion.js +2 -10
- package/lib/types/dsh-adapter/channel/transcript.d.ts +3 -2
- package/lib/types/dsh-adapter/channel/transcript.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/transcript.js +13 -4
- package/lib/types/dsh-adapter/channel/types.d.ts +11 -2
- package/lib/types/dsh-adapter/channel/types.d.ts.map +1 -1
- package/lib/types/dsh-adapter/compat/compaction-previews.d.ts +11 -0
- package/lib/types/dsh-adapter/compat/compaction-previews.d.ts.map +1 -0
- package/lib/types/dsh-adapter/compat/compaction-previews.js +38 -0
- package/lib/types/dsh-adapter/compat/messages.d.ts +1 -1
- package/lib/types/dsh-adapter/compat/messages.d.ts.map +1 -1
- package/lib/types/dsh-adapter/compat/messages.js +2 -2
- package/lib/types/dsh-adapter/contract.d.ts +29 -3
- package/lib/types/dsh-adapter/contract.d.ts.map +1 -1
- package/lib/types/dsh-adapter/contract.js +48 -5
- package/lib/types/dsh-adapter/experimental-bundles.d.ts +5 -0
- package/lib/types/dsh-adapter/experimental-bundles.d.ts.map +1 -1
- package/lib/types/dsh-adapter/experimental-bundles.js +0 -2
- package/lib/types/dsh-adapter/fresh-agent.d.ts +1 -1
- package/lib/types/dsh-adapter/fresh-agent.d.ts.map +1 -1
- package/lib/types/dsh-adapter/fresh-agent.js +60 -11
- package/lib/types/dsh-adapter/host-access.d.ts.map +1 -1
- package/lib/types/dsh-adapter/host-access.js +60 -11
- package/lib/types/dsh-adapter/host-contract.d.ts +1 -1
- package/lib/types/dsh-adapter/host-contract.d.ts.map +1 -1
- package/lib/types/dsh-adapter/host-contract.js +5 -3
- package/lib/types/dsh-adapter/host-dsh.d.ts +2 -8
- package/lib/types/dsh-adapter/host-dsh.d.ts.map +1 -1
- package/lib/types/dsh-adapter/host-dsh.js +30 -6
- package/lib/types/dsh-adapter/host-entry.js +4 -0
- package/lib/types/dsh-adapter/index.d.ts +9 -1
- package/lib/types/dsh-adapter/index.d.ts.map +1 -1
- package/lib/types/dsh-adapter/index.js +5 -0
- package/lib/types/dsh-adapter/oauth/account-notifications.d.ts +73 -0
- package/lib/types/dsh-adapter/oauth/account-notifications.d.ts.map +1 -0
- package/lib/types/dsh-adapter/oauth/account-notifications.js +250 -0
- package/lib/types/dsh-adapter/oauth/bonus.d.ts +34 -9
- package/lib/types/dsh-adapter/oauth/bonus.d.ts.map +1 -1
- package/lib/types/dsh-adapter/oauth/bonus.js +47 -5
- package/lib/types/dsh-adapter/oauth/deepseek.d.ts +7 -2
- package/lib/types/dsh-adapter/oauth/deepseek.d.ts.map +1 -1
- package/lib/types/dsh-adapter/oauth/deepseek.js +6 -1
- package/lib/types/dsh-adapter/oauth/index.d.ts.map +1 -1
- package/lib/types/dsh-adapter/oauth/index.js +44 -0
- package/lib/types/dsh-adapter/oauth/profiles.d.ts.map +1 -1
- package/lib/types/dsh-adapter/oauth/profiles.js +14 -1
- package/lib/types/dsh-adapter/oauth/service.d.ts.map +1 -1
- package/lib/types/dsh-adapter/oauth/service.js +5 -6
- package/lib/types/dsh-adapter/plugin-manage.d.ts +6 -4
- package/lib/types/dsh-adapter/plugin-manage.d.ts.map +1 -1
- package/lib/types/dsh-adapter/plugin-manage.js +3 -2
- package/lib/types/dsh-adapter/plugin.d.ts +237 -6
- package/lib/types/dsh-adapter/plugin.d.ts.map +1 -1
- package/lib/types/dsh-adapter/plugin.js +751 -67
- package/lib/types/dsh-adapter/presets.d.ts +38 -11
- package/lib/types/dsh-adapter/presets.d.ts.map +1 -1
- package/lib/types/dsh-adapter/presets.js +46 -17
- package/lib/types/dsh-adapter/process-exit.d.ts +1 -1
- package/lib/types/dsh-adapter/process-exit.js +1 -1
- package/lib/types/dsh-adapter/questions.d.ts +3 -4
- package/lib/types/dsh-adapter/questions.d.ts.map +1 -1
- package/lib/types/dsh-adapter/questions.js +1 -1
- package/lib/types/dsh-adapter/session-list-metadata.js +2 -2
- package/lib/types/dsh-adapter/session-projection-store.d.ts +1 -1
- package/lib/types/dsh-adapter/session-projection-store.d.ts.map +1 -1
- package/lib/types/dsh-adapter/session-projection-store.js +30 -23
- package/lib/types/dsh-adapter/sessionTree.d.ts.map +1 -1
- package/lib/types/dsh-adapter/sessionTree.js +4 -1
- package/lib/types/dsh-adapter/subagents.d.ts +6 -0
- package/lib/types/dsh-adapter/subagents.d.ts.map +1 -1
- package/lib/types/dsh-adapter/subagents.js +32 -3
- package/lib/types/dsh-adapter/team-mode.d.ts +46 -27
- package/lib/types/dsh-adapter/team-mode.d.ts.map +1 -1
- package/lib/types/dsh-adapter/team-mode.js +157 -29
- package/lib/types/dsh-adapter/team-roster.d.ts +53 -18
- package/lib/types/dsh-adapter/team-roster.d.ts.map +1 -1
- package/lib/types/dsh-adapter/team-roster.js +206 -39
- package/lib/types/dsh-adapter/team-tools.d.ts +25 -12
- package/lib/types/dsh-adapter/team-tools.d.ts.map +1 -1
- package/lib/types/dsh-adapter/team-tools.js +81 -26
- package/lib/types/dsh-adapter/tool-scope.d.ts +24 -0
- package/lib/types/dsh-adapter/tool-scope.d.ts.map +1 -0
- package/lib/types/dsh-adapter/tool-scope.js +127 -0
- package/lib/types/dsh-adapter/types.d.ts +2 -1
- package/lib/types/dsh-adapter/types.d.ts.map +1 -1
- package/lib/types/heldInputs.d.ts +55 -16
- package/lib/types/heldInputs.d.ts.map +1 -1
- package/lib/types/heldInputs.js +277 -41
- package/lib/types/i18n.d.ts +292 -20
- package/lib/types/i18n.d.ts.map +1 -1
- package/lib/types/i18n.js +89 -13
- package/lib/types/ink/components/App.d.ts +2 -0
- package/lib/types/ink/components/App.d.ts.map +1 -1
- package/lib/types/ink/components/App.js +8 -0
- package/lib/types/ink/dom.d.ts.map +1 -1
- package/lib/types/ink/dom.js +13 -3
- package/lib/types/ink/events/input-event.d.ts.map +1 -1
- package/lib/types/ink/events/input-event.js +7 -6
- package/lib/types/ink/flush-tick.d.ts +6 -0
- package/lib/types/ink/flush-tick.d.ts.map +1 -1
- package/lib/types/ink/flush-tick.js +31 -0
- package/lib/types/ink/hit-test.d.ts +2 -0
- package/lib/types/ink/hit-test.d.ts.map +1 -1
- package/lib/types/ink/hit-test.js +10 -0
- package/lib/types/ink/hooks/use-program-status.d.ts +1 -1
- package/lib/types/ink/hooks/use-program-status.d.ts.map +1 -1
- package/lib/types/ink/hooks/use-program-status.js +3 -2
- package/lib/types/ink/hooks/use-terminal-title.d.ts +15 -0
- package/lib/types/ink/hooks/use-terminal-title.d.ts.map +1 -1
- package/lib/types/ink/hooks/use-terminal-title.js +23 -3
- package/lib/types/ink/ink.d.ts +1 -0
- package/lib/types/ink/ink.d.ts.map +1 -1
- package/lib/types/ink/ink.js +7 -4
- package/lib/types/ink/jumpback-state.d.ts +33 -0
- package/lib/types/ink/jumpback-state.d.ts.map +1 -0
- package/lib/types/ink/jumpback-state.js +51 -0
- package/lib/types/ink/jumpback.d.ts +78 -0
- package/lib/types/ink/jumpback.d.ts.map +1 -0
- package/lib/types/ink/jumpback.js +515 -0
- package/lib/types/ink/log-update.js +37 -14
- package/lib/types/ink/notify-helper/activate.cs +836 -0
- package/lib/types/ink/notify-helper/compile.d.ts +30 -0
- package/lib/types/ink/notify-helper/compile.d.ts.map +1 -0
- package/lib/types/ink/notify-helper/compile.js +235 -0
- package/lib/types/ink/parse-keypress.d.ts.map +1 -1
- package/lib/types/ink/parse-keypress.js +25 -0
- package/lib/types/ink/terminal-notification-windows.d.ts +8 -4
- package/lib/types/ink/terminal-notification-windows.d.ts.map +1 -1
- package/lib/types/ink/terminal-notification-windows.js +14 -21
- package/lib/types/ink/terminal-notification.d.ts +31 -2
- package/lib/types/ink/terminal-notification.d.ts.map +1 -1
- package/lib/types/ink/terminal-notification.js +51 -0
- package/lib/types/ink/terminal.d.ts +15 -3
- package/lib/types/ink/terminal.d.ts.map +1 -1
- package/lib/types/ink/terminal.js +38 -9
- package/lib/types/screens/AgentTranscriptScene.d.ts.map +1 -1
- package/lib/types/screens/AgentTranscriptScene.js +1 -1
- package/lib/types/screens/Chat.d.ts +4 -3
- package/lib/types/screens/Chat.d.ts.map +1 -1
- package/lib/types/screens/Chat.js +81 -11
- package/lib/types/screens/SessionSupervisor.d.ts +3 -6
- package/lib/types/screens/SessionSupervisor.d.ts.map +1 -1
- package/lib/types/screens/SessionSupervisor.js +5 -8
- package/lib/types/screens/sessionSupervisor/ForeignSessionPanes.d.ts +1 -2
- package/lib/types/screens/sessionSupervisor/ForeignSessionPanes.d.ts.map +1 -1
- package/lib/types/screens/sessionSupervisor/ForeignSessionPanes.js +2 -2
- package/lib/types/screens/sessionSupervisor/model.d.ts +1 -1
- package/lib/types/screens/sessionSupervisor/model.js +1 -1
- package/lib/types/sessionMounts.d.ts +12 -5
- package/lib/types/sessionMounts.d.ts.map +1 -1
- package/lib/types/sessionMounts.js +33 -6
- package/lib/types/settings/definitions.d.ts +12 -0
- package/lib/types/settings/definitions.d.ts.map +1 -1
- package/lib/types/settings/definitions.js +15 -7
- package/lib/types/update.d.ts +412 -20
- package/lib/types/update.d.ts.map +1 -1
- package/lib/types/update.js +2094 -193
- package/lib/types/updateHost.d.ts +198 -0
- package/lib/types/updateHost.d.ts.map +1 -0
- package/lib/types/updateHost.js +608 -0
- package/lib/types/utils/processName.d.ts +16 -0
- package/lib/types/utils/processName.d.ts.map +1 -0
- package/lib/types/utils/processName.js +27 -0
- package/package.json +114 -111
- package/presets/liangshen/agent.cordis.yml +4 -0
- package/tui-profile/feed/README.md +1 -1
- package/tui-profile/feed/first-party.json +1 -1
|
@@ -0,0 +1,608 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host-engine (`dsh`) update planning: peer-range parsing, target selection
|
|
3
|
+
* and global-install classification.
|
|
4
|
+
*
|
|
5
|
+
* Backend-neutral on purpose: this module carries no `@deepseek-ai/*` import or
|
|
6
|
+
* literal. The caller (`src/update.ts`) supplies the package names and the
|
|
7
|
+
* registry data, so the same rules can be exercised without a network.
|
|
8
|
+
*
|
|
9
|
+
* The single source of truth for the engine line is the TARGET TUI's
|
|
10
|
+
* `@deepseek-ai/dsh-app-boot` peer range. Published ranges are version
|
|
11
|
+
* enumerations (`0.2.0-rc.2 || 0.2.1-rc.2 || …`), so parsing is exact: a range
|
|
12
|
+
* with operators is refused instead of guessed at. `scripts/verify-manifest-deps.ts`
|
|
13
|
+
* fails the release when the enumeration leaves the validated line, so the
|
|
14
|
+
* runtime never has to trust a range it cannot enumerate.
|
|
15
|
+
*/
|
|
16
|
+
import { accessSync, constants, existsSync, readFileSync, readdirSync, realpathSync } from 'node:fs';
|
|
17
|
+
import { basename, delimiter, dirname, join, resolve, sep } from 'node:path';
|
|
18
|
+
import gt from 'semver/functions/gt.js';
|
|
19
|
+
import prerelease from 'semver/functions/prerelease.js';
|
|
20
|
+
import valid from 'semver/functions/valid.js';
|
|
21
|
+
/** `DSH_TUI_DSH_PM=npm|pnpm` forces the package-manager classification. */
|
|
22
|
+
export const DSH_PM_ENV = 'DSH_TUI_DSH_PM';
|
|
23
|
+
function isRecord(value) {
|
|
24
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Parse an enumerated peer range into exact versions.
|
|
28
|
+
*
|
|
29
|
+
* @param raw - e.g. `'0.2.1-rc.5 || 0.2.2-rc.1'`.
|
|
30
|
+
* @returns Deduplicated versions, or `[]` for an absent/operator range.
|
|
31
|
+
*/
|
|
32
|
+
export function parseHostLineRange(raw) {
|
|
33
|
+
if (raw === undefined || raw.trim() === '')
|
|
34
|
+
return [];
|
|
35
|
+
const versions = [];
|
|
36
|
+
for (const part of raw.split('||')) {
|
|
37
|
+
const version = valid(part.trim());
|
|
38
|
+
if (version === null)
|
|
39
|
+
return [];
|
|
40
|
+
if (!versions.includes(version))
|
|
41
|
+
versions.push(version);
|
|
42
|
+
}
|
|
43
|
+
return versions;
|
|
44
|
+
}
|
|
45
|
+
function newestVersion(versions) {
|
|
46
|
+
let newest;
|
|
47
|
+
for (const version of versions) {
|
|
48
|
+
const parsed = valid(version);
|
|
49
|
+
if (parsed === null)
|
|
50
|
+
continue;
|
|
51
|
+
if (newest === undefined || gt(parsed, newest))
|
|
52
|
+
newest = parsed;
|
|
53
|
+
}
|
|
54
|
+
return newest;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The newest published engine release outside the target TUI's enumerated
|
|
58
|
+
* line. This only feeds the "waiting for a TUI release" notice: the line
|
|
59
|
+
* itself stays the selection rule, and an unvalidated alpha is not named
|
|
60
|
+
* (policy never selects it, so reporting it would be noise rather than an
|
|
61
|
+
* actionable wait).
|
|
62
|
+
*
|
|
63
|
+
* @param available - Published registry versions, or undefined when the
|
|
64
|
+
* lookup failed.
|
|
65
|
+
* @param newestAllowed - Highest version in the target TUI's peer range.
|
|
66
|
+
* @returns The newer release, or undefined when the line already covers the
|
|
67
|
+
* registry's newest.
|
|
68
|
+
*/
|
|
69
|
+
function newerReleaseOutsideLine(available, newestAllowed) {
|
|
70
|
+
if (available === undefined || newestAllowed === undefined)
|
|
71
|
+
return undefined;
|
|
72
|
+
let newest;
|
|
73
|
+
for (const version of available) {
|
|
74
|
+
const parsed = valid(version);
|
|
75
|
+
if (parsed === null || !gt(parsed, newestAllowed))
|
|
76
|
+
continue;
|
|
77
|
+
// Skip only the alpha line, not the whole answer: a newer alpha must not
|
|
78
|
+
// hide an rc/beta release outside the range that IS worth waiting for.
|
|
79
|
+
if (prerelease(parsed)?.includes('alpha') === true)
|
|
80
|
+
continue;
|
|
81
|
+
if (newest === undefined || gt(parsed, newest))
|
|
82
|
+
newest = parsed;
|
|
83
|
+
}
|
|
84
|
+
return newest;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Pick the engine version for a target TUI line.
|
|
88
|
+
*
|
|
89
|
+
* `newest` is the highest PUBLISHED version inside `allowed`; anything newer
|
|
90
|
+
* on the registry (an alpha line, say) is never selected. A current engine
|
|
91
|
+
* ahead of the window is kept — this project never downgrades — and reported
|
|
92
|
+
* as drift by the caller.
|
|
93
|
+
*
|
|
94
|
+
* @param input - Current engine, the target TUI's enumerated line, and the
|
|
95
|
+
* registry's published versions.
|
|
96
|
+
*/
|
|
97
|
+
export function selectHostTarget(input) {
|
|
98
|
+
const current = input.current === undefined ? null : valid(input.current);
|
|
99
|
+
if (current === null)
|
|
100
|
+
return { kind: 'none', reason: 'unknown-current' };
|
|
101
|
+
const published = new Set();
|
|
102
|
+
for (const version of input.available) {
|
|
103
|
+
const parsed = valid(version);
|
|
104
|
+
if (parsed !== null)
|
|
105
|
+
published.add(parsed);
|
|
106
|
+
}
|
|
107
|
+
const candidates = input.allowed.filter(version => published.has(version));
|
|
108
|
+
const newest = newestVersion(candidates);
|
|
109
|
+
if (newest === undefined)
|
|
110
|
+
return { kind: 'unavailable', reason: 'no-version' };
|
|
111
|
+
if (current === newest)
|
|
112
|
+
return { kind: 'none', reason: 'newest' };
|
|
113
|
+
if (gt(current, newest))
|
|
114
|
+
return { kind: 'none', reason: 'newer-than-validated' };
|
|
115
|
+
return { kind: 'install', to: newest };
|
|
116
|
+
}
|
|
117
|
+
/** The npm global prefix of a package dir, or undefined for other layouts. */
|
|
118
|
+
function npmPrefix(dir, platform) {
|
|
119
|
+
// POSIX npm puts globals under `<prefix>/lib/node_modules`, every platform's
|
|
120
|
+
// project installs under `<project>/node_modules`. Only the global shape is
|
|
121
|
+
// an install this module may drive.
|
|
122
|
+
const posixMarker = `${sep}lib${sep}node_modules${sep}`;
|
|
123
|
+
const posixIndex = dir.lastIndexOf(posixMarker);
|
|
124
|
+
if (posixIndex > 0)
|
|
125
|
+
return dir.slice(0, posixIndex);
|
|
126
|
+
if (platform !== 'win32')
|
|
127
|
+
return undefined;
|
|
128
|
+
// npm's Windows shim tree is `<prefix>\node_modules`; accept it only when the
|
|
129
|
+
// prefix is npm's own directory, so a project or a yarn/asdf tree stays
|
|
130
|
+
// unclassified instead of being installed into by guesswork.
|
|
131
|
+
const windowsMarker = `${sep}node_modules${sep}`;
|
|
132
|
+
const windowsIndex = dir.lastIndexOf(windowsMarker);
|
|
133
|
+
if (windowsIndex <= 0)
|
|
134
|
+
return undefined;
|
|
135
|
+
const prefix = dir.slice(0, windowsIndex);
|
|
136
|
+
return basename(prefix).toLowerCase() === 'npm' ? prefix : undefined;
|
|
137
|
+
}
|
|
138
|
+
function isWritable(path) {
|
|
139
|
+
try {
|
|
140
|
+
accessSync(path, constants.W_OK);
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/** pnpm's legacy global slot and modern isolated entity/hash group directories. */
|
|
148
|
+
const GROUP_SLOT = /^v?\d+$/u;
|
|
149
|
+
/** The `dsh` executable names a PATH entry can carry. */
|
|
150
|
+
function dshShimNames(platform) {
|
|
151
|
+
return platform === 'win32' ? ['dsh.cmd', 'dsh.ps1', 'dsh'] : ['dsh'];
|
|
152
|
+
}
|
|
153
|
+
/** Read one group manifest's direct dependencies (the installed set). */
|
|
154
|
+
function pnpmGroupMembers(groupRoot) {
|
|
155
|
+
try {
|
|
156
|
+
const parsed = JSON.parse(readFileSync(join(groupRoot, 'package.json'), 'utf8'));
|
|
157
|
+
if (!isRecord(parsed) || !isRecord(parsed.dependencies))
|
|
158
|
+
return undefined;
|
|
159
|
+
return Object.keys(parsed.dependencies);
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
return undefined;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/** Every candidate group root under a pnpm home, bounded like pnpm itself. */
|
|
166
|
+
function pnpmGroupRoots(pnpmHome) {
|
|
167
|
+
let slots;
|
|
168
|
+
try {
|
|
169
|
+
slots = readdirSync(join(pnpmHome, 'global')).filter(name => GROUP_SLOT.test(name)).slice(0, 8);
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
return [];
|
|
173
|
+
}
|
|
174
|
+
const roots = [];
|
|
175
|
+
for (const slot of slots) {
|
|
176
|
+
const slotDir = join(pnpmHome, 'global', slot);
|
|
177
|
+
roots.push(slotDir);
|
|
178
|
+
try {
|
|
179
|
+
for (const name of readdirSync(slotDir)) {
|
|
180
|
+
if (roots.length >= 64)
|
|
181
|
+
break;
|
|
182
|
+
if (name !== 'node_modules')
|
|
183
|
+
roots.push(join(slotDir, name));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
// An unreadable slot proves nothing; the remaining slots still count.
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return roots;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Prove which pnpm home/group owns `packageDir` from the `dsh` shim on PATH.
|
|
194
|
+
*
|
|
195
|
+
* A pnpm 12 global install resolves through the shared virtual store, so the
|
|
196
|
+
* package realpath no longer names its `global/` group — and the ambient
|
|
197
|
+
* `PNPM_HOME` may belong to a completely different install. The shim that
|
|
198
|
+
* launched this process is the ownership evidence: derive candidate homes from
|
|
199
|
+
* PATH entries carrying `dsh`, then accept exactly one group whose declared
|
|
200
|
+
* dependency really resolves to `packageDir`. No evidence or an ambiguous
|
|
201
|
+
* result returns undefined (the caller refuses to write).
|
|
202
|
+
*
|
|
203
|
+
* pnpm >= 11.21 keeps BOTH the real install directory and a hash symlink that
|
|
204
|
+
* points at it in the same slot. They are one group, not two owners: compare
|
|
205
|
+
* canonical (realpath) group roots so the alias is not counted twice. Two
|
|
206
|
+
* genuinely distinct groups that both claim the package stay ambiguous.
|
|
207
|
+
*/
|
|
208
|
+
function pnpmOwnedGroup(packageDir, env, platform) {
|
|
209
|
+
const names = dshShimNames(platform);
|
|
210
|
+
const homes = new Set();
|
|
211
|
+
for (const dir of (env.PATH ?? env.Path ?? '').split(delimiter)) {
|
|
212
|
+
if (dir === '')
|
|
213
|
+
continue;
|
|
214
|
+
if (!names.some(name => existsSync(join(dir, name))))
|
|
215
|
+
continue;
|
|
216
|
+
homes.add(resolve(dir));
|
|
217
|
+
homes.add(dirname(resolve(dir)));
|
|
218
|
+
}
|
|
219
|
+
const owned = [];
|
|
220
|
+
const groupRootKey = (groupRoot) => {
|
|
221
|
+
try {
|
|
222
|
+
return realpathSync(groupRoot);
|
|
223
|
+
}
|
|
224
|
+
catch {
|
|
225
|
+
return resolve(groupRoot);
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
for (const home of homes) {
|
|
229
|
+
for (const groupRoot of pnpmGroupRoots(home)) {
|
|
230
|
+
const members = pnpmGroupMembers(groupRoot);
|
|
231
|
+
if (members === undefined)
|
|
232
|
+
continue;
|
|
233
|
+
const owns = members.some((name) => {
|
|
234
|
+
try {
|
|
235
|
+
return realpathSync(join(groupRoot, 'node_modules', name)) === packageDir;
|
|
236
|
+
}
|
|
237
|
+
catch {
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
// Canonicalize the entity, not the alias: `pnpm add -g` needs the real
|
|
242
|
+
// group directory, and both spellings must collapse to one owner.
|
|
243
|
+
const key = groupRootKey(groupRoot);
|
|
244
|
+
if (owns && !owned.some(candidate => candidate.groupRoot === key))
|
|
245
|
+
owned.push({ home, groupRoot: key });
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return owned.length === 1 ? owned[0] : undefined;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Whether a pnpm step may be automated: the owning group must be proven and
|
|
252
|
+
* must contain this package alone. `pnpm add -g <pkg>` replaces every group
|
|
253
|
+
* containing `<pkg>`, so a multi-member group would lose its other CLIs.
|
|
254
|
+
*/
|
|
255
|
+
function pnpmGroupProven(install, packageName) {
|
|
256
|
+
if (install.installer !== 'pnpm' || install.groupRoot === undefined)
|
|
257
|
+
return false;
|
|
258
|
+
const members = pnpmGroupMembers(install.groupRoot);
|
|
259
|
+
return members !== undefined && members.length === 1 && members[0] === packageName;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Whether `dir` lives in a volta package image. The default `~/.volta` is not
|
|
263
|
+
* the only valid home: `VOLTA_HOME` (honoured by `host-dsh.ts` when it follows
|
|
264
|
+
* a volta shim) moves the image anywhere, and a custom image that is missed
|
|
265
|
+
* here would be rewritten by `npm install -g --prefix` instead of left to
|
|
266
|
+
* volta. The literal `/.volta/` fallback keeps the old classification for an
|
|
267
|
+
* unexported home.
|
|
268
|
+
*/
|
|
269
|
+
function isVoltaImage(dir, env) {
|
|
270
|
+
const homes = [];
|
|
271
|
+
if (env.VOLTA_HOME !== undefined && env.VOLTA_HOME !== '')
|
|
272
|
+
homes.push(env.VOLTA_HOME);
|
|
273
|
+
const home = env.HOME ?? env.USERPROFILE;
|
|
274
|
+
if (home !== undefined && home !== '')
|
|
275
|
+
homes.push(join(home, '.volta'));
|
|
276
|
+
const roots = new Set();
|
|
277
|
+
for (const voltaHome of homes) {
|
|
278
|
+
const image = resolve(join(voltaHome, 'tools', 'image'));
|
|
279
|
+
roots.add(image);
|
|
280
|
+
try {
|
|
281
|
+
roots.add(realpathSync(image));
|
|
282
|
+
}
|
|
283
|
+
catch {
|
|
284
|
+
// A missing image cannot be the one we are classifying; keep the path.
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
for (const root of roots) {
|
|
288
|
+
if (dir === root || dir.startsWith(root + sep))
|
|
289
|
+
return true;
|
|
290
|
+
}
|
|
291
|
+
return /[\\/]\.volta[\\/]tools[\\/]image[\\/]/u.test(dir);
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Classify a host package directory by layout. Only recognized global npm /
|
|
295
|
+
* pnpm layouts are auto-installable; volta and anything else are reported as
|
|
296
|
+
* such so the caller prints a manual command instead of guessing.
|
|
297
|
+
*
|
|
298
|
+
* @param packageDir - The installed `@deepseek-ai/dsh` package directory.
|
|
299
|
+
* @param env - Process environment (`PNPM_HOME`, `VOLTA_HOME`, `DSH_TUI_DSH_PM`).
|
|
300
|
+
* @param platform - Test seam for the Windows npm layout.
|
|
301
|
+
*/
|
|
302
|
+
export function detectHostInstall(packageDir, env = process.env, platform = process.platform) {
|
|
303
|
+
let dir = resolve(packageDir);
|
|
304
|
+
try {
|
|
305
|
+
dir = realpathSync(dir);
|
|
306
|
+
}
|
|
307
|
+
catch {
|
|
308
|
+
// Keep the logical path; the manifest read and classification still work.
|
|
309
|
+
}
|
|
310
|
+
let version;
|
|
311
|
+
try {
|
|
312
|
+
const parsed = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8'));
|
|
313
|
+
if (isRecord(parsed) && typeof parsed.version === 'string')
|
|
314
|
+
version = valid(parsed.version) ?? undefined;
|
|
315
|
+
}
|
|
316
|
+
catch {
|
|
317
|
+
// An unreadable manifest leaves the version unknown; the caller then
|
|
318
|
+
// declines to touch the engine.
|
|
319
|
+
}
|
|
320
|
+
const forced = env[DSH_PM_ENV] === 'npm' || env[DSH_PM_ENV] === 'pnpm' ? env[DSH_PM_ENV] : undefined;
|
|
321
|
+
// volta's image tree is owned by volta itself (default or custom home).
|
|
322
|
+
if (isVoltaImage(dir, env)) {
|
|
323
|
+
return { packageDir: dir, version, installer: 'volta', writable: false };
|
|
324
|
+
}
|
|
325
|
+
// Legacy globals put node_modules directly under the numbered slot; pnpm
|
|
326
|
+
// 11/12 isolated groups insert an entity/hash directory before node_modules.
|
|
327
|
+
// Capture that whole group, not its slot: its manifest proves membership.
|
|
328
|
+
// An ambient PNPM_HOME must never send the install to a different home.
|
|
329
|
+
const globalGroup = /^(.*?)[\\/]global[\\/](v?\d+)(?:[\\/]([^\\/]+))?[\\/]node_modules[\\/]/u.exec(dir);
|
|
330
|
+
if (globalGroup !== null && globalGroup[1] !== '') {
|
|
331
|
+
const home = globalGroup[1];
|
|
332
|
+
const slot = join(home, 'global', globalGroup[2]);
|
|
333
|
+
return {
|
|
334
|
+
packageDir: dir,
|
|
335
|
+
version,
|
|
336
|
+
installer: forced ?? 'pnpm',
|
|
337
|
+
pnpmHome: home,
|
|
338
|
+
groupRoot: globalGroup[3] === undefined ? slot : join(slot, globalGroup[3]),
|
|
339
|
+
writable: isWritable(home),
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
// pnpm 12's global store links: the realpath has no `global/` segment, and
|
|
343
|
+
// the store root is often NOT the PNPM_HOME. Ownership must come from the
|
|
344
|
+
// `dsh` shim on PATH; an inherited PNPM_HOME is never adopted by guesswork,
|
|
345
|
+
// or the install would land in an unrelated home.
|
|
346
|
+
if (/[\\/]store[\\/]v\d+[\\/]links[\\/]/u.test(dir)) {
|
|
347
|
+
const owned = pnpmOwnedGroup(dir, env, platform);
|
|
348
|
+
if (owned === undefined) {
|
|
349
|
+
return { packageDir: dir, version, installer: forced ?? 'pnpm', writable: false };
|
|
350
|
+
}
|
|
351
|
+
return {
|
|
352
|
+
packageDir: dir,
|
|
353
|
+
version,
|
|
354
|
+
installer: forced ?? 'pnpm',
|
|
355
|
+
pnpmHome: owned.home,
|
|
356
|
+
groupRoot: owned.groupRoot,
|
|
357
|
+
writable: isWritable(owned.home),
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
// A project-local pnpm store: `pnpm add -g` would install elsewhere.
|
|
361
|
+
if (/[\\/]\.pnpm[\\/]/u.test(dir)) {
|
|
362
|
+
return { packageDir: dir, version, installer: 'unknown', writable: false };
|
|
363
|
+
}
|
|
364
|
+
const prefix = npmPrefix(dir, platform);
|
|
365
|
+
if (prefix !== undefined) {
|
|
366
|
+
if (forced === 'pnpm') {
|
|
367
|
+
const owned = pnpmOwnedGroup(dir, env, platform);
|
|
368
|
+
if (owned === undefined) {
|
|
369
|
+
return { packageDir: dir, version, installer: 'pnpm', writable: false };
|
|
370
|
+
}
|
|
371
|
+
return {
|
|
372
|
+
packageDir: dir,
|
|
373
|
+
version,
|
|
374
|
+
installer: 'pnpm',
|
|
375
|
+
pnpmHome: owned.home,
|
|
376
|
+
groupRoot: owned.groupRoot,
|
|
377
|
+
writable: isWritable(owned.home),
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
return { packageDir: dir, version, installer: 'npm', prefix, writable: isWritable(prefix) };
|
|
381
|
+
}
|
|
382
|
+
return { packageDir: dir, version, installer: 'unknown', writable: false };
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* pnpm >= 11 refuses versions younger than `minimumReleaseAge` (24h by
|
|
386
|
+
* default) unless that exact version is exempted. The profile install writes
|
|
387
|
+
* the exemption into the profile's workspace file; the one-shot global
|
|
388
|
+
* installs here have no such file, and `/update` runs right after a release —
|
|
389
|
+
* i.e. always inside the window. The pinned version is one the target TUI
|
|
390
|
+
* validates, so the window is waived for that single invocation only. Both
|
|
391
|
+
* spellings are set: pnpm 12's CLI reads PNPM_CONFIG_ (verified on 12.16.1;
|
|
392
|
+
* its own error text advertises that form), while npm-style config readers
|
|
393
|
+
* only understand npm_config_ - the repo pins pnpm 11 for releases, which
|
|
394
|
+
* cannot be probed here, so the second spelling is kept rather than guessed
|
|
395
|
+
* away. Each reader ignores the other's variable. The waiver covers the whole
|
|
396
|
+
* dependency closure of this one install, not just the package: the engine's
|
|
397
|
+
* closure is published in lockstep at the same version, so an exact-version
|
|
398
|
+
* exclusion would not unblock it anyway.
|
|
399
|
+
*/
|
|
400
|
+
export const PNPM_RELEASE_AGE_ENV = {
|
|
401
|
+
PNPM_CONFIG_MINIMUM_RELEASE_AGE: '0',
|
|
402
|
+
npm_config_minimum_release_age: '0',
|
|
403
|
+
};
|
|
404
|
+
/** Render `NAME=value` prefixes so a printed command can be pasted as-is. */
|
|
405
|
+
export function shellEnvPrefix(vars, platform = process.platform) {
|
|
406
|
+
const entries = Object.entries(vars);
|
|
407
|
+
return platform === 'win32'
|
|
408
|
+
// `set "NAME=value"` is the cmd form that keeps spaces, `&`, `|`, `<`, `>`
|
|
409
|
+
// and `^` literal; the outer quotes belong to cmd, not to the value.
|
|
410
|
+
? entries.map(([name, value]) => `set "${name}=${value}" && `).join('')
|
|
411
|
+
: entries.map(([name, value]) => `${name}=${shellPath(value, platform)} `).join('');
|
|
412
|
+
}
|
|
413
|
+
/** Quote a path for a printed command; it may contain spaces or shell metacharacters. */
|
|
414
|
+
function shellPath(value, platform) {
|
|
415
|
+
if (platform === 'win32') {
|
|
416
|
+
// cmd.exe: double quotes keep spaces and & | < > ^ ( ) literal. A literal
|
|
417
|
+
// quote cannot appear in a Windows path, so it needs no escaping.
|
|
418
|
+
return /[\s&|<>^()]/u.test(value) ? `"${value}"` : value;
|
|
419
|
+
}
|
|
420
|
+
// POSIX: a conservative safe set stays bare; everything else becomes a
|
|
421
|
+
// single-quoted literal, where $, backticks, \, ;, & and globbing are inert.
|
|
422
|
+
if (/^[A-Za-z0-9_./:@%+,-]+$/u.test(value))
|
|
423
|
+
return value;
|
|
424
|
+
return `'${value.replaceAll("'", "'\\''")}'`;
|
|
425
|
+
}
|
|
426
|
+
/** The installer command for a detected layout, or undefined when unknown. */
|
|
427
|
+
export function hostInstallCommand(install, packageName, version) {
|
|
428
|
+
const spec = `${packageName}@${version}`;
|
|
429
|
+
if (install.installer === 'pnpm') {
|
|
430
|
+
return {
|
|
431
|
+
file: 'pnpm',
|
|
432
|
+
args: ['add', '-g', spec],
|
|
433
|
+
env: {
|
|
434
|
+
...PNPM_RELEASE_AGE_ENV,
|
|
435
|
+
...(install.pnpmHome === undefined ? {} : { PNPM_HOME: install.pnpmHome }),
|
|
436
|
+
},
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
if (install.installer === 'npm') {
|
|
440
|
+
return {
|
|
441
|
+
file: 'npm',
|
|
442
|
+
args: install.prefix === undefined
|
|
443
|
+
? ['install', '-g', spec]
|
|
444
|
+
: ['install', '-g', '--prefix', install.prefix, spec],
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
return undefined;
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Manual repair commands for a layout. More than one entry when the platform
|
|
451
|
+
* has an alternative (e.g. the sudo form for an unwritable npm prefix).
|
|
452
|
+
*
|
|
453
|
+
* @param install - Detected install; undefined when detection failed.
|
|
454
|
+
*/
|
|
455
|
+
export function hostManualCommands(packageName, version, install, platform = process.platform) {
|
|
456
|
+
const spec = `${packageName}@${version}`;
|
|
457
|
+
switch (install?.installer) {
|
|
458
|
+
case 'pnpm': {
|
|
459
|
+
// `pnpm add -g <one package>` replaces every group containing it. Only a
|
|
460
|
+
// proven singleton group may print that command; anything else gets an
|
|
461
|
+
// inspection step instead of a command that would delete sibling CLIs.
|
|
462
|
+
if (install.groupRoot === undefined || !pnpmGroupProven(install, packageName)) {
|
|
463
|
+
return [
|
|
464
|
+
`pnpm list -g --depth 0\n Inspect the install group before aligning ${spec}; preserve every member and its peers. ` +
|
|
465
|
+
'A single-package `pnpm add -g` replaces the whole group, so align it with the command that created that group.',
|
|
466
|
+
];
|
|
467
|
+
}
|
|
468
|
+
// The owner home is part of the command. Detection proves the group from
|
|
469
|
+
// the owning shim even when the ambient PNPM_HOME names a DIFFERENT
|
|
470
|
+
// install; dropping it from the printed form would repair the wrong
|
|
471
|
+
// global install (the automated command pins it too).
|
|
472
|
+
const env = install.pnpmHome === undefined
|
|
473
|
+
? PNPM_RELEASE_AGE_ENV
|
|
474
|
+
: { ...PNPM_RELEASE_AGE_ENV, PNPM_HOME: install.pnpmHome };
|
|
475
|
+
return [`${shellEnvPrefix(env, platform)}pnpm add -g ${spec}`];
|
|
476
|
+
}
|
|
477
|
+
case 'volta': return [`volta install ${spec}`];
|
|
478
|
+
case 'npm': {
|
|
479
|
+
// A prefix with spaces must survive copy-paste as one argument.
|
|
480
|
+
const prefix = install.prefix === undefined ? '' : ` --prefix ${shellPath(install.prefix, platform)}`;
|
|
481
|
+
// Never elevate from inside the TUI: the user runs this themselves.
|
|
482
|
+
const sudo = platform !== 'win32' && !install.writable ? 'sudo ' : '';
|
|
483
|
+
return [`${sudo}npm install -g${prefix} ${spec}`];
|
|
484
|
+
}
|
|
485
|
+
default: return [`npm install -g ${spec}`];
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Whether the engine is usable after the planned step. `undefined` = cannot
|
|
490
|
+
* tell (unknown current version or unparseable range) and the caller must not
|
|
491
|
+
* claim compatibility either way.
|
|
492
|
+
*
|
|
493
|
+
* An engine AHEAD of the window counts as usable for the boot/restart
|
|
494
|
+
* decision: this project never downgrades, and the boot drift notice reports
|
|
495
|
+
* the newer line. This is NOT the official plugin manager's install check: the
|
|
496
|
+
* manager validates a new TUI against the running engine with exact semver
|
|
497
|
+
* membership, where an ahead engine is outside the line. Use
|
|
498
|
+
* {@link hostSatisfiesLine} for that decision.
|
|
499
|
+
*/
|
|
500
|
+
export function hostCompatibility(input) {
|
|
501
|
+
if (input.step?.kind === 'install')
|
|
502
|
+
return true;
|
|
503
|
+
const current = input.current === undefined ? null : valid(input.current);
|
|
504
|
+
if (current === null)
|
|
505
|
+
return undefined;
|
|
506
|
+
const allowed = input.allowed.map(version => valid(version)).filter((version) => version !== null);
|
|
507
|
+
if (allowed.length === 0)
|
|
508
|
+
return undefined;
|
|
509
|
+
if (allowed.includes(current))
|
|
510
|
+
return true;
|
|
511
|
+
const newest = newestVersion(allowed);
|
|
512
|
+
return newest !== undefined && gt(current, newest) ? true : false;
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Strict line membership for the official plugin manager's install check.
|
|
516
|
+
*
|
|
517
|
+
* The manager evaluates the target TUI's peer ranges against the RUNNING
|
|
518
|
+
* engine with semver `satisfies()`; an engine ABOVE the enumerated line is
|
|
519
|
+
* outside it exactly like an older one, so it cannot install that TUI.
|
|
520
|
+
* `hostCompatibility` deliberately keeps an ahead engine usable for the
|
|
521
|
+
* boot/restart decision and must not be used here.
|
|
522
|
+
*
|
|
523
|
+
* @param input - The current engine and the target TUI's enumerated line.
|
|
524
|
+
* @returns true when the current version is one of the enumerated versions;
|
|
525
|
+
* false when it is outside; undefined when either side cannot be read.
|
|
526
|
+
*/
|
|
527
|
+
export function hostSatisfiesLine(input) {
|
|
528
|
+
if (input.current === undefined)
|
|
529
|
+
return undefined;
|
|
530
|
+
const current = valid(input.current);
|
|
531
|
+
if (current === null)
|
|
532
|
+
return undefined;
|
|
533
|
+
const allowed = input.allowed.map(version => valid(version)).filter((version) => version !== null);
|
|
534
|
+
if (allowed.length === 0)
|
|
535
|
+
return undefined;
|
|
536
|
+
return allowed.includes(current);
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Build the engine step of a plan.
|
|
540
|
+
*
|
|
541
|
+
* @param input - Current version, the target TUI's enumerated peer range, the
|
|
542
|
+
* registry's available versions (undefined = lookup failed), the detected
|
|
543
|
+
* install, the package name and the `DSH_TUI_UPDATE_ENGINE=0` switch.
|
|
544
|
+
*/
|
|
545
|
+
export function planHostStep(input) {
|
|
546
|
+
if (input.current === undefined || valid(input.current) === null)
|
|
547
|
+
return { kind: 'none', reason: 'unknown-current' };
|
|
548
|
+
if (input.range === undefined)
|
|
549
|
+
return { kind: 'none', reason: 'unknown-range' };
|
|
550
|
+
const allowed = parseHostLineRange(input.range);
|
|
551
|
+
if (allowed.length === 0)
|
|
552
|
+
return { kind: 'none', reason: 'unknown-range' };
|
|
553
|
+
// A failed lookup still knows the range's highest target: the manual repair
|
|
554
|
+
// command names it, so a refusal is always actionable (§10 of the plan).
|
|
555
|
+
const manualVersion = newestVersion(allowed) ?? 'latest';
|
|
556
|
+
if (input.available === undefined) {
|
|
557
|
+
return {
|
|
558
|
+
kind: 'unavailable',
|
|
559
|
+
reason: 'offline',
|
|
560
|
+
from: input.current,
|
|
561
|
+
manual: hostManualCommands(input.packageName, manualVersion, input.install),
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
const selection = selectHostTarget({ current: input.current, allowed, available: input.available });
|
|
565
|
+
if (selection.kind === 'none') {
|
|
566
|
+
// A settled line can still have a newer release outside it. Remember it
|
|
567
|
+
// so the idle notice explains the wait instead of reading as "nothing to
|
|
568
|
+
// see" (the "TUI has not declared support yet" case from #1849 review).
|
|
569
|
+
const newerPublished = selection.reason === 'newest'
|
|
570
|
+
? newerReleaseOutsideLine(input.available, manualVersion)
|
|
571
|
+
: undefined;
|
|
572
|
+
return {
|
|
573
|
+
kind: 'none',
|
|
574
|
+
reason: selection.reason,
|
|
575
|
+
from: input.current,
|
|
576
|
+
...(selection.reason === 'newer-than-validated' ? { to: manualVersion } : {}),
|
|
577
|
+
...(newerPublished === undefined ? {} : { newerPublished }),
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
if (selection.kind === 'unavailable') {
|
|
581
|
+
return {
|
|
582
|
+
kind: 'unavailable',
|
|
583
|
+
reason: 'no-version',
|
|
584
|
+
from: input.current,
|
|
585
|
+
to: manualVersion === 'latest' ? undefined : manualVersion,
|
|
586
|
+
manual: hostManualCommands(input.packageName, manualVersion, input.install),
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
const manual = hostManualCommands(input.packageName, selection.to, input.install);
|
|
590
|
+
if (input.disabled === true) {
|
|
591
|
+
// Keep the target/command in the refusal path: skipping the automatic
|
|
592
|
+
// install must not hide an incompatible pair.
|
|
593
|
+
return { kind: 'none', reason: 'disabled', from: input.current, to: selection.to, manual };
|
|
594
|
+
}
|
|
595
|
+
// A pnpm step is only safe in a proven singleton group: `pnpm add -g` removes
|
|
596
|
+
// every co-installed package from the group. Refuse to guess.
|
|
597
|
+
if (input.install !== undefined && input.install.installer === 'pnpm' && !pnpmGroupProven(input.install, input.packageName)) {
|
|
598
|
+
return { kind: 'unavailable', reason: 'group-unproven', from: input.current, to: selection.to, manual };
|
|
599
|
+
}
|
|
600
|
+
const command = input.install === undefined ? undefined : hostInstallCommand(input.install, input.packageName, selection.to);
|
|
601
|
+
if (input.install === undefined || command === undefined) {
|
|
602
|
+
return { kind: 'unavailable', reason: 'no-installer', from: input.current, to: selection.to, manual };
|
|
603
|
+
}
|
|
604
|
+
if (!input.install.writable) {
|
|
605
|
+
return { kind: 'unavailable', reason: 'not-writable', from: input.current, to: selection.to, manual };
|
|
606
|
+
}
|
|
607
|
+
return { kind: 'install', from: input.current, to: selection.to, packageDir: input.install.packageDir, command, manual };
|
|
608
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Name the OS process, so process listings show `dsh-tui` (#1831).
|
|
3
|
+
*
|
|
4
|
+
* Linux reports a process by its thread group leader's name — field 2 of
|
|
5
|
+
* `/proc/<pid>/stat` — which is what `ps -o comm`, `top` and desktop process
|
|
6
|
+
* monitors display, and Node starts that thread as "MainThread". Writing
|
|
7
|
+
* /proc/self/comm renames the leader and leaves argv alone, where
|
|
8
|
+
* `process.title` would rewrite cmdline as well; tools and regressions
|
|
9
|
+
* recognise the entry by its cmdline.
|
|
10
|
+
*
|
|
11
|
+
* Only Linux has this file and only Linux needs the rename (elsewhere `ps`
|
|
12
|
+
* shows the executable). A read-only /proc rejects the write and the name then
|
|
13
|
+
* stays as Node set it, exactly as before this ran.
|
|
14
|
+
*/
|
|
15
|
+
export declare function setProcessName(name: string): void;
|
|
16
|
+
//# sourceMappingURL=processName.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processName.d.ts","sourceRoot":"","sources":["../../../src/utils/processName.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CASjD"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { writeFileSync } from 'node:fs';
|
|
2
|
+
/**
|
|
3
|
+
* Name the OS process, so process listings show `dsh-tui` (#1831).
|
|
4
|
+
*
|
|
5
|
+
* Linux reports a process by its thread group leader's name — field 2 of
|
|
6
|
+
* `/proc/<pid>/stat` — which is what `ps -o comm`, `top` and desktop process
|
|
7
|
+
* monitors display, and Node starts that thread as "MainThread". Writing
|
|
8
|
+
* /proc/self/comm renames the leader and leaves argv alone, where
|
|
9
|
+
* `process.title` would rewrite cmdline as well; tools and regressions
|
|
10
|
+
* recognise the entry by its cmdline.
|
|
11
|
+
*
|
|
12
|
+
* Only Linux has this file and only Linux needs the rename (elsewhere `ps`
|
|
13
|
+
* shows the executable). A read-only /proc rejects the write and the name then
|
|
14
|
+
* stays as Node set it, exactly as before this ran.
|
|
15
|
+
*/
|
|
16
|
+
export function setProcessName(name) {
|
|
17
|
+
if (process.platform !== 'linux')
|
|
18
|
+
return;
|
|
19
|
+
try {
|
|
20
|
+
// No trailing newline: the kernel stores the bytes verbatim, and a newline
|
|
21
|
+
// in comm makes `ps` print "dsh-tui?" and misparses /proc/<pid>/stat.
|
|
22
|
+
writeFileSync('/proc/self/comm', name);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
// Read-only /proc (some containers): keep the inherited name.
|
|
26
|
+
}
|
|
27
|
+
}
|