@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,127 @@
|
|
|
1
|
+
import * as scope from '@deepseek-ai/dsh-scope';
|
|
2
|
+
import { presetToolDeny, runningPresetOf } from './presets.js';
|
|
3
|
+
import { teamReplacedToolDeny } from './team-mode.js';
|
|
4
|
+
// Scope ancestry and definitions arrived after the oldest supported hosts.
|
|
5
|
+
// Probe the public export by shape; the legacy assembly path needs neither.
|
|
6
|
+
const scopeParentOf = scope.scopeParentOf;
|
|
7
|
+
/**
|
|
8
|
+
* Keep one exact restriction per live agent, including background/child agents
|
|
9
|
+
* that never bind to the screen. Agent publication awaits agent/created, so its
|
|
10
|
+
* restriction is installed before the factory releases any queued work.
|
|
11
|
+
*
|
|
12
|
+
* @param ctx - Composition context supplying the registry and lifecycle events.
|
|
13
|
+
* @param own - Channel lifetime funnel; releases listeners and every owned mask.
|
|
14
|
+
* @param currentAgent - Initial/borrowed foreground not necessarily in the registry.
|
|
15
|
+
*/
|
|
16
|
+
export function createToolScope(ctx, own, currentAgent) {
|
|
17
|
+
const tools = ctx.get?.('tools');
|
|
18
|
+
// No registry-side work is needed on legacy hosts (or a rosterless fixture).
|
|
19
|
+
// Their assembly filter is still authoritative, with its original lifecycle.
|
|
20
|
+
if (typeof tools?.restrict !== 'function' || typeof tools.definitions !== 'function' || scopeParentOf === undefined)
|
|
21
|
+
return { apply: () => undefined };
|
|
22
|
+
const tracked = new Set();
|
|
23
|
+
const retired = new WeakSet();
|
|
24
|
+
const applied = new Map();
|
|
25
|
+
const listeners = [];
|
|
26
|
+
let closed = false;
|
|
27
|
+
let refreshing = false;
|
|
28
|
+
let refreshQueued = false;
|
|
29
|
+
const release = (agent) => {
|
|
30
|
+
const previous = applied.get(agent);
|
|
31
|
+
applied.delete(agent);
|
|
32
|
+
previous?.dispose();
|
|
33
|
+
};
|
|
34
|
+
own(() => {
|
|
35
|
+
closed = true;
|
|
36
|
+
const failures = [];
|
|
37
|
+
for (const dispose of [...listeners.splice(0), ...[...applied.values()].map(entry => entry.dispose)]) {
|
|
38
|
+
try {
|
|
39
|
+
dispose();
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
failures.push(error);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
applied.clear();
|
|
46
|
+
tracked.clear();
|
|
47
|
+
if (failures.length > 0)
|
|
48
|
+
throw new AggregateError(failures, 'dsh-tui: tool scope cleanup failed');
|
|
49
|
+
});
|
|
50
|
+
const applyOne = (agent) => {
|
|
51
|
+
const scoped = agent.ctx;
|
|
52
|
+
const service = scoped?.get?.('tools');
|
|
53
|
+
if (typeof service?.restrict !== 'function' || typeof service.definitions !== 'function' || scopeParentOf === undefined)
|
|
54
|
+
return;
|
|
55
|
+
try {
|
|
56
|
+
// The parent view contains inherited/restrictable names before OUR mask.
|
|
57
|
+
// The exact-agent view also contains own-scope Team tools. Using the
|
|
58
|
+
// latter alone would forget already-hidden spawners on the next refresh;
|
|
59
|
+
// using the global view would never see preset or Team registrations.
|
|
60
|
+
const inherited = new Set(service.definitions(scopeParentOf(agent)).map(tool => tool.name));
|
|
61
|
+
const visible = new Set(service.definitions(agent).map(tool => tool.name));
|
|
62
|
+
const deny = [...new Set([
|
|
63
|
+
...presetToolDeny(runningPresetOf(agent.session)),
|
|
64
|
+
...teamReplacedToolDeny(new Set([...inherited, ...visible])),
|
|
65
|
+
])].filter(name => inherited.has(name)).sort();
|
|
66
|
+
const signature = deny.join('\n');
|
|
67
|
+
if (applied.get(agent)?.signature === signature)
|
|
68
|
+
return;
|
|
69
|
+
release(agent);
|
|
70
|
+
// Empty filters are rejected upstream and carry no opinion here.
|
|
71
|
+
if (deny.length > 0)
|
|
72
|
+
applied.set(agent, { signature, dispose: service.restrict({ deny }) });
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
ctx.logger?.warn?.('dsh-tui: could not restrict tools for the agent', error);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const refresh = () => {
|
|
79
|
+
if (closed)
|
|
80
|
+
return;
|
|
81
|
+
// Both install AND disposal synchronously emit tools/change. Finish the
|
|
82
|
+
// atomic refresh first, then coalesce those events into one stable pass.
|
|
83
|
+
refreshQueued = true;
|
|
84
|
+
if (refreshing)
|
|
85
|
+
return;
|
|
86
|
+
refreshing = true;
|
|
87
|
+
try {
|
|
88
|
+
do {
|
|
89
|
+
refreshQueued = false;
|
|
90
|
+
const registry = ctx.get?.('agents');
|
|
91
|
+
const foreground = currentAgent();
|
|
92
|
+
for (const agent of registry?.list?.() ?? [])
|
|
93
|
+
if (!retired.has(agent))
|
|
94
|
+
tracked.add(agent);
|
|
95
|
+
if (foreground !== undefined && !retired.has(foreground))
|
|
96
|
+
tracked.add(foreground);
|
|
97
|
+
for (const agent of tracked)
|
|
98
|
+
applyOne(agent);
|
|
99
|
+
} while (refreshQueued && !closed);
|
|
100
|
+
}
|
|
101
|
+
finally {
|
|
102
|
+
refreshing = false;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const apply = (agent) => {
|
|
106
|
+
if (closed || retired.has(agent))
|
|
107
|
+
return;
|
|
108
|
+
tracked.add(agent);
|
|
109
|
+
refresh();
|
|
110
|
+
};
|
|
111
|
+
listeners.push(ctx.on('tools/change', refresh));
|
|
112
|
+
listeners.push(ctx.on('agent/created', ({ agent }) => {
|
|
113
|
+
apply(agent);
|
|
114
|
+
return undefined;
|
|
115
|
+
}));
|
|
116
|
+
listeners.push(ctx.on('agent/disposed', ({ agent }) => {
|
|
117
|
+
retired.add(agent);
|
|
118
|
+
tracked.delete(agent);
|
|
119
|
+
release(agent);
|
|
120
|
+
}));
|
|
121
|
+
listeners.push(ctx.on('session/event', (_session, event) => {
|
|
122
|
+
if (event.type === 'agent-preset/selected')
|
|
123
|
+
refresh();
|
|
124
|
+
}));
|
|
125
|
+
refresh();
|
|
126
|
+
return { apply };
|
|
127
|
+
}
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
* breaks exactly one module, never the whole UI.
|
|
8
8
|
*/
|
|
9
9
|
export type { LlmModelInfo, LlmProviderInfo } from '@deepseek-ai/dsh-llm';
|
|
10
|
-
export type { Agent, AgentHandle, AgentStatus, CreateAgentOptions
|
|
10
|
+
export type { Agent, AgentHandle, AgentStatus, CreateAgentOptions } from '@deepseek-ai/dsh-agent';
|
|
11
|
+
export type { ModelSelectionRef } from './channel/model-selection.js';
|
|
11
12
|
export type { SessionId, SessionEvent, SessionHeader } from '@deepseek-ai/dsh-session';
|
|
12
13
|
export type { CommandRuntime } from '@deepseek-ai/dsh-commands';
|
|
13
14
|
export type { ApprovalOutcome, ApprovalRequest } from '@deepseek-ai/dsh-user-approval';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/dsh-adapter/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACzE,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/dsh-adapter/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACzE,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AACjG,YAAY,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AACrE,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AACtF,YAAY,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC/D,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AACtF,YAAY,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACxD,YAAY,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,YAAY,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAExD;;;;GAIG;AACH,YAAY,EACV,UAAU,EACV,WAAW,EACX,aAAa,EACb,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,UAAU,EACV,UAAU,EACV,QAAQ,EACR,UAAU,EACV,WAAW,EACX,cAAc,GACf,MAAM,uBAAuB,CAAA"}
|
|
@@ -1,36 +1,75 @@
|
|
|
1
|
-
|
|
1
|
+
import type { AttachedContext, ChannelImageMediaType, ComposerImageRef, ComposerSubmission, StagedImageHandle, StagedImageInput, TranscriptImage } from './adapter/ports/channel-view.js';
|
|
2
|
+
/** env marker naming the file the replacement takes its held inputs from. */
|
|
2
3
|
export declare const HELD_INPUTS_ENV = "DSH_TUI_HELD_INPUTS";
|
|
4
|
+
/** One staged image of a carried input: its visible token and its bytes. */
|
|
5
|
+
export interface HeldImage {
|
|
6
|
+
readonly token: string;
|
|
7
|
+
readonly data: Uint8Array;
|
|
8
|
+
readonly mediaType: ChannelImageMediaType;
|
|
9
|
+
readonly name?: string;
|
|
10
|
+
}
|
|
11
|
+
/** One carried "send to Chat" context: the fields a later delivery needs.
|
|
12
|
+
* The composer's chip id is minted per screen and means nothing to the
|
|
13
|
+
* replacement, so it is not carried. */
|
|
14
|
+
export interface HeldContext {
|
|
15
|
+
readonly source: 'panel';
|
|
16
|
+
readonly sourceId: string;
|
|
17
|
+
readonly title: string;
|
|
18
|
+
readonly content: string;
|
|
19
|
+
readonly truncated: boolean;
|
|
20
|
+
}
|
|
21
|
+
/** One carried input. */
|
|
22
|
+
export interface HeldInput {
|
|
23
|
+
readonly text: string;
|
|
24
|
+
readonly images?: readonly HeldImage[];
|
|
25
|
+
readonly contexts?: readonly HeldContext[];
|
|
26
|
+
}
|
|
3
27
|
/**
|
|
4
|
-
*
|
|
28
|
+
* The old process's side: the pending rows with their staged images' bytes.
|
|
29
|
+
* Never rejects; an image that cannot be read in time stays behind (its token
|
|
30
|
+
* then sends as text, which the composer warns about).
|
|
31
|
+
*/
|
|
32
|
+
export declare function collectHeldInputs(pending: readonly {
|
|
33
|
+
readonly text: string;
|
|
34
|
+
readonly images: readonly ComposerImageRef[];
|
|
35
|
+
readonly contexts?: readonly AttachedContext[];
|
|
36
|
+
}[], stagedImage: (stageId: string) => TranscriptImage | undefined): Promise<HeldInput[]>;
|
|
37
|
+
/**
|
|
38
|
+
* Write the inputs for a replacement process to take.
|
|
5
39
|
* @returns The env marker to hand the replacement, or undefined when there
|
|
6
40
|
* is nothing to carry or the write failed (best effort: a restart never
|
|
7
41
|
* waits on it).
|
|
8
42
|
*/
|
|
9
|
-
export declare function writeHeldInputs(
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
* held rows once the screen's channel is ready (never sent by themselves).
|
|
13
|
-
* A pass that cannot reach a ready channel leaves the handoff pending for the
|
|
14
|
-
* next `apply()` instead of dropping it.
|
|
15
|
-
* @returns What stops waiting for a channel that is not ready yet.
|
|
16
|
-
*/
|
|
17
|
-
export declare function adoptHeldInputs(channel: {
|
|
43
|
+
export declare function writeHeldInputs(inputs: readonly (string | HeldInput)[], dir?: string, pid?: number): Record<string, string> | undefined;
|
|
44
|
+
/** What `adoptHeldInputs` needs from the screen's channel. */
|
|
45
|
+
export interface HeldInputsChannel {
|
|
18
46
|
readonly ready: boolean;
|
|
19
47
|
subscribe(listener: () => void): () => void;
|
|
20
|
-
holdInputs(
|
|
21
|
-
|
|
48
|
+
holdInputs(inputs: readonly (string | ComposerSubmission)[]): number;
|
|
49
|
+
stagedImageGeneration(): number;
|
|
50
|
+
stageComposerImage(input: StagedImageInput, generation: number): Promise<StagedImageHandle>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The replacement's side: park the inputs a `/restart` handed this process as
|
|
54
|
+
* held rows once the screen's channel is ready (never sent by themselves),
|
|
55
|
+
* their images staged again first. An image the new session refuses is left
|
|
56
|
+
* out; its token stays in the text. A pass that cannot reach a ready channel
|
|
57
|
+
* leaves the handoff pending for the next `apply()` instead of dropping it.
|
|
58
|
+
* @returns What stops the adoption, or undefined when nothing was carried.
|
|
59
|
+
*/
|
|
60
|
+
export declare function adoptHeldInputs(channel: HeldInputsChannel, env?: NodeJS.ProcessEnv, dir?: string): (() => void) | undefined;
|
|
22
61
|
/**
|
|
23
62
|
* The resume command after a restart that ended before any replacement took
|
|
24
|
-
* the held
|
|
63
|
+
* the held inputs (a stall, a failed spawn): their file stays, and the command
|
|
25
64
|
* hands it to the next launch. Windows has no shared env-assignment syntax:
|
|
26
65
|
* PowerShell and cmd.exe each get their own copy-pasteable line.
|
|
27
66
|
*/
|
|
28
67
|
export declare function heldInputsResumeCommand(command: string, env: Readonly<Record<string, string>> | undefined, platform?: NodeJS.Platform): string;
|
|
29
68
|
/**
|
|
30
|
-
* Take (read and delete) the
|
|
69
|
+
* Take (read and delete) the inputs a `/restart` handed this process. One
|
|
31
70
|
* shot: the env marker is consumed too, so no child inherits it.
|
|
32
71
|
*/
|
|
33
|
-
export declare function takeHeldInputs(env?: NodeJS.ProcessEnv, dir?: string):
|
|
72
|
+
export declare function takeHeldInputs(env?: NodeJS.ProcessEnv, dir?: string): HeldInput[];
|
|
34
73
|
/** Remove held-input files older than the resume window (best effort). */
|
|
35
74
|
export declare function sweepHeldInputs(dir?: string, now?: number): void;
|
|
36
75
|
//# sourceMappingURL=heldInputs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"heldInputs.d.ts","sourceRoot":"","sources":["../../src/heldInputs.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"heldInputs.d.ts","sourceRoot":"","sources":["../../src/heldInputs.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAA;AAIzL,6EAA6E;AAC7E,eAAO,MAAM,eAAe,wBAAwB,CAAA;AAOpD,4EAA4E;AAC5E,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAA;IACzB,QAAQ,CAAC,SAAS,EAAE,qBAAqB,CAAA;IACzC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CACvB;AAED;;yCAEyC;AACzC,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAA;CAC5B;AAED,yBAAyB;AACzB,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,SAAS,EAAE,CAAA;IACtC,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,WAAW,EAAE,CAAA;CAC3C;AAKD;;;;GAIG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,SAAS;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,gBAAgB,EAAE,CAAC;IAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,eAAe,EAAE,CAAA;CAAE,EAAE,EAC3I,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,eAAe,GAAG,SAAS,GAC5D,OAAO,CAAC,SAAS,EAAE,CAAC,CA0CtB;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,EAAE,GAAG,GAAE,MAAiB,EAAE,GAAG,GAAE,MAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CA+B9J;AAED,8DAA8D;AAC9D,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;IACvB,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAA;IAC3C,UAAU,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,kBAAkB,CAAC,EAAE,GAAG,MAAM,CAAA;IACpE,qBAAqB,IAAI,MAAM,CAAA;IAC/B,kBAAkB,CAAC,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAA;CAC5F;AAkDD;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,iBAAiB,EAAE,GAAG,GAAE,MAAM,CAAC,UAAwB,EAAE,GAAG,GAAE,MAAiB,GAAG,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAkHlJ;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,SAAS,EAAE,QAAQ,GAAE,MAAM,CAAC,QAA2B,GAAG,MAAM,CAShK;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,EAAE,GAAG,GAAE,MAAiB,GAAG,SAAS,EAAE,CASxG;AAyDD,0EAA0E;AAC1E,wBAAgB,eAAe,CAAC,GAAG,GAAE,MAAiB,EAAE,GAAG,GAAE,MAAmB,GAAG,IAAI,CAetF"}
|
package/lib/types/heldInputs.js
CHANGED
|
@@ -4,26 +4,82 @@
|
|
|
4
4
|
* path rides the replacement's env, and the replacement parks them as held
|
|
5
5
|
* dock rows. The backend copies die with the old process (the kernel records
|
|
6
6
|
* them as canceled), so nothing re-sends them until the user sends the dock.
|
|
7
|
-
*
|
|
7
|
+
* Staged images live in the old process's memory: their bytes ride the file
|
|
8
|
+
* and the replacement stages them again.
|
|
8
9
|
*/
|
|
9
10
|
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
10
11
|
import { randomBytes } from 'node:crypto';
|
|
11
12
|
import { basename, dirname, join, resolve } from 'node:path';
|
|
13
|
+
import { sniffImageMediaType } from './utils/imageResize.js';
|
|
12
14
|
import { DATA_DIR } from './utils/paths.js';
|
|
13
|
-
/** env marker naming the file the replacement takes its held
|
|
15
|
+
/** env marker naming the file the replacement takes its held inputs from. */
|
|
14
16
|
export const HELD_INPUTS_ENV = 'DSH_TUI_HELD_INPUTS';
|
|
15
17
|
const HELD_INPUTS_FILE = /^held-inputs-\d+-[0-9a-f]{12}\.json$/u;
|
|
16
18
|
/** A restart that stalled leaves its file for the printed resume command; one
|
|
17
19
|
* nobody resumed within this long is swept at a later launch. */
|
|
18
20
|
const HELD_INPUTS_MAX_AGE_MS = 7 * 24 * 60 * 60 * 1000;
|
|
21
|
+
/** How long one image read may take before the restart goes on without it. */
|
|
22
|
+
const IMAGE_READ_MS = 2000;
|
|
19
23
|
/**
|
|
20
|
-
*
|
|
24
|
+
* The old process's side: the pending rows with their staged images' bytes.
|
|
25
|
+
* Never rejects; an image that cannot be read in time stays behind (its token
|
|
26
|
+
* then sends as text, which the composer warns about).
|
|
27
|
+
*/
|
|
28
|
+
export async function collectHeldInputs(pending, stagedImage) {
|
|
29
|
+
const readImage = async (ref) => {
|
|
30
|
+
const image = stagedImage(ref.stageId);
|
|
31
|
+
if (image === undefined)
|
|
32
|
+
return undefined;
|
|
33
|
+
// A ref'd timer, unlike AbortSignal.timeout: while the exit waits on this
|
|
34
|
+
// read the process must stay up until the replacement is spawned.
|
|
35
|
+
const abort = new AbortController();
|
|
36
|
+
let timer;
|
|
37
|
+
try {
|
|
38
|
+
const data = await Promise.race([
|
|
39
|
+
image.read(abort.signal),
|
|
40
|
+
new Promise((_, reject) => {
|
|
41
|
+
timer = setTimeout(() => {
|
|
42
|
+
abort.abort();
|
|
43
|
+
reject(new Error('image read timed out'));
|
|
44
|
+
}, IMAGE_READ_MS);
|
|
45
|
+
}),
|
|
46
|
+
]);
|
|
47
|
+
const mediaType = sniffImageMediaType(data);
|
|
48
|
+
if (mediaType === undefined)
|
|
49
|
+
return undefined;
|
|
50
|
+
return { token: ref.token, data, mediaType, ...(image.name === undefined ? {} : { name: image.name }) };
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
finally {
|
|
56
|
+
clearTimeout(timer);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
return Promise.all(pending.map(async (item) => {
|
|
60
|
+
const images = (await Promise.all(item.images.map(readImage))).filter((image) => image !== undefined);
|
|
61
|
+
const contexts = (item.contexts ?? []).map((context) => ({
|
|
62
|
+
source: context.source,
|
|
63
|
+
sourceId: context.sourceId,
|
|
64
|
+
title: context.title,
|
|
65
|
+
content: context.content,
|
|
66
|
+
truncated: context.truncated,
|
|
67
|
+
}));
|
|
68
|
+
return {
|
|
69
|
+
text: item.text,
|
|
70
|
+
...(images.length === 0 ? {} : { images }),
|
|
71
|
+
...(contexts.length === 0 ? {} : { contexts }),
|
|
72
|
+
};
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Write the inputs for a replacement process to take.
|
|
21
77
|
* @returns The env marker to hand the replacement, or undefined when there
|
|
22
78
|
* is nothing to carry or the write failed (best effort: a restart never
|
|
23
79
|
* waits on it).
|
|
24
80
|
*/
|
|
25
|
-
export function writeHeldInputs(
|
|
26
|
-
const kept =
|
|
81
|
+
export function writeHeldInputs(inputs, dir = DATA_DIR, pid = process.pid) {
|
|
82
|
+
const kept = inputs.map(input => typeof input === 'string' ? { text: input } : input).filter(input => input.text.trim() !== '');
|
|
27
83
|
if (kept.length === 0)
|
|
28
84
|
return undefined;
|
|
29
85
|
// Unique per restart: a stalled restart's file stays for its printed
|
|
@@ -31,26 +87,68 @@ export function writeHeldInputs(texts, dir = DATA_DIR, pid = process.pid) {
|
|
|
31
87
|
const file = join(dir, `held-inputs-${pid}-${randomBytes(6).toString('hex')}.json`);
|
|
32
88
|
try {
|
|
33
89
|
mkdirSync(dir, { recursive: true });
|
|
34
|
-
|
|
35
|
-
|
|
90
|
+
const records = kept.map(input => ({
|
|
91
|
+
text: input.text,
|
|
92
|
+
...(input.images === undefined || input.images.length === 0 ? {} : {
|
|
93
|
+
images: input.images.map(image => ({ ...image, data: Buffer.from(image.data).toString('base64') })),
|
|
94
|
+
}),
|
|
95
|
+
...(input.contexts === undefined || input.contexts.length === 0 ? {} : { contexts: input.contexts.map(context => ({ ...context })) }),
|
|
96
|
+
}));
|
|
97
|
+
// The user's own prompt text and images: readable by them alone.
|
|
98
|
+
// Both shapes in one file: a replacement that is an older build reads
|
|
99
|
+
// `texts` (it knows nothing of images), this build prefers `inputs`.
|
|
100
|
+
writeFileSync(file, JSON.stringify({ inputs: records, texts: kept.map(input => input.text) }), { mode: 0o600, flag: 'wx' });
|
|
36
101
|
return { [HELD_INPUTS_ENV]: file };
|
|
37
102
|
}
|
|
38
103
|
catch {
|
|
39
|
-
|
|
104
|
+
// Images are the luxury here: a plain-text file still hands the words
|
|
105
|
+
// over, and the resume command it prints stays honest about the rest.
|
|
106
|
+
try {
|
|
107
|
+
rmSync(file, { force: true });
|
|
108
|
+
writeFileSync(file, JSON.stringify({ texts: kept.map(input => input.text) }), { mode: 0o600, flag: 'wx' });
|
|
109
|
+
return { [HELD_INPUTS_ENV]: file };
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
40
114
|
}
|
|
41
115
|
}
|
|
42
116
|
/**
|
|
43
117
|
* The one handoff this process has not settled yet. The DSH launcher's boot
|
|
44
118
|
* recompose applies the entry a second time, after the first pass consumed
|
|
45
|
-
* the env marker; that pass must still find the
|
|
119
|
+
* the env marker; that pass must still find the inputs. A pass claims it
|
|
120
|
+
* before holding: staging images is async, and a stale listener must not park
|
|
121
|
+
* the same inputs again while the first pass is still staging.
|
|
46
122
|
*/
|
|
47
123
|
let waiting;
|
|
124
|
+
/**
|
|
125
|
+
* Passes that asked for the handoff while another one was staging its images.
|
|
126
|
+
* Staging is async, so the holder can stop (a replaced screen, a failed
|
|
127
|
+
* boot pass) before it parks anything: it releases the claim, and without a
|
|
128
|
+
* wake-up here the ready sibling that already lost the race would never look
|
|
129
|
+
* again — its inputs would stay on disk with nobody holding them.
|
|
130
|
+
*/
|
|
131
|
+
const claimWaiters = new Set();
|
|
48
132
|
/** Read the marker once per handoff; without a fresh one, hand back the
|
|
49
133
|
* pending handoff (the recompose asking again). */
|
|
50
134
|
function carriedInputs(env, dir) {
|
|
51
135
|
if (env[HELD_INPUTS_ENV] !== undefined)
|
|
52
136
|
waiting = readHeldInputs(env, dir);
|
|
53
|
-
return waiting ?? {
|
|
137
|
+
return waiting ?? { inputs: [] };
|
|
138
|
+
}
|
|
139
|
+
/** The write side of a carried image, bounded like the read side: a channel
|
|
140
|
+
* that never answers must not keep the handoff claim forever. */
|
|
141
|
+
function stageWithin(work) {
|
|
142
|
+
let timer;
|
|
143
|
+
const timeout = new Promise((_, reject) => {
|
|
144
|
+
timer = setTimeout(() => reject(new Error('image staging timed out')), IMAGE_READ_MS);
|
|
145
|
+
// A guard for an exit path musn't keep the process up by itself.
|
|
146
|
+
timer.unref?.();
|
|
147
|
+
});
|
|
148
|
+
return Promise.race([work, timeout]).finally(() => {
|
|
149
|
+
if (timer !== undefined)
|
|
150
|
+
clearTimeout(timer);
|
|
151
|
+
});
|
|
54
152
|
}
|
|
55
153
|
/** Best effort: a file another process still holds open must not decide
|
|
56
154
|
* whether this one starts. */
|
|
@@ -62,49 +160,140 @@ function removeHeldFile(file) {
|
|
|
62
160
|
}
|
|
63
161
|
}
|
|
64
162
|
/**
|
|
65
|
-
* The replacement's side: park the
|
|
66
|
-
* held rows once the screen's channel is ready (never sent by themselves)
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
163
|
+
* The replacement's side: park the inputs a `/restart` handed this process as
|
|
164
|
+
* held rows once the screen's channel is ready (never sent by themselves),
|
|
165
|
+
* their images staged again first. An image the new session refuses is left
|
|
166
|
+
* out; its token stays in the text. A pass that cannot reach a ready channel
|
|
167
|
+
* leaves the handoff pending for the next `apply()` instead of dropping it.
|
|
168
|
+
* @returns What stops the adoption, or undefined when nothing was carried.
|
|
70
169
|
*/
|
|
71
170
|
export function adoptHeldInputs(channel, env = process.env, dir = DATA_DIR) {
|
|
72
|
-
const
|
|
73
|
-
const {
|
|
74
|
-
// The file goes only once its
|
|
75
|
-
// dies before
|
|
76
|
-
// parent prints. Then files nobody resumed are swept.
|
|
171
|
+
const handoff = carriedInputs(env, dir);
|
|
172
|
+
const { inputs, file } = handoff;
|
|
173
|
+
// The file goes only once its inputs are on screen: a replacement that
|
|
174
|
+
// dies (or stops) before then, staging images included, leaves it for the
|
|
175
|
+
// resume command its parent prints. Then files nobody resumed are swept.
|
|
77
176
|
const settle = () => {
|
|
78
177
|
if (file !== undefined)
|
|
79
178
|
removeHeldFile(file);
|
|
80
179
|
waiting = undefined;
|
|
180
|
+
claimWaiters.clear();
|
|
81
181
|
sweepHeldInputs(dir);
|
|
82
182
|
};
|
|
83
|
-
if (
|
|
183
|
+
if (inputs.length === 0) {
|
|
84
184
|
settle();
|
|
85
185
|
return undefined;
|
|
86
186
|
}
|
|
87
|
-
|
|
88
|
-
|
|
187
|
+
let stopped = false;
|
|
188
|
+
/** Hand the claim back and wake the pass that lost it. The file is still on
|
|
189
|
+
* disk: only a pass that actually parks the inputs may settle the handoff. */
|
|
190
|
+
const release = () => {
|
|
191
|
+
if (waiting !== handoff)
|
|
192
|
+
return;
|
|
193
|
+
handoff.claimed = false;
|
|
194
|
+
for (const wake of [...claimWaiters]) {
|
|
195
|
+
claimWaiters.delete(wake);
|
|
196
|
+
wake();
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
const hold = async () => {
|
|
200
|
+
let generation;
|
|
201
|
+
try {
|
|
202
|
+
generation = channel.stagedImageGeneration();
|
|
203
|
+
}
|
|
204
|
+
catch {
|
|
205
|
+
// The screen is gone before staging even started: nobody here can park
|
|
206
|
+
// the rows. Keep the file and let the next pass (or the resume command)
|
|
207
|
+
// take the handoff instead of leaving the claim held.
|
|
208
|
+
release();
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
const submissions = await Promise.all(inputs.map(async (input) => {
|
|
212
|
+
const contexts = (input.contexts ?? []).map((context) => ({
|
|
213
|
+
id: `ctx-held-${randomBytes(4).toString('hex')}`,
|
|
214
|
+
source: context.source,
|
|
215
|
+
sourceId: context.sourceId,
|
|
216
|
+
title: context.title,
|
|
217
|
+
content: context.content,
|
|
218
|
+
chars: context.content.length,
|
|
219
|
+
truncated: context.truncated,
|
|
220
|
+
}));
|
|
221
|
+
const withContexts = contexts.length === 0 ? {} : { contexts };
|
|
222
|
+
if (input.images === undefined)
|
|
223
|
+
return { text: input.text, ...withContexts };
|
|
224
|
+
const refs = await Promise.all(input.images.map(async (image) => {
|
|
225
|
+
try {
|
|
226
|
+
const { stageId } = await stageWithin(channel.stageComposerImage({ data: image.data, mediaType: image.mediaType, ...(image.name === undefined ? {} : { name: image.name }) }, generation));
|
|
227
|
+
return { token: image.token, stageId };
|
|
228
|
+
}
|
|
229
|
+
catch {
|
|
230
|
+
return undefined;
|
|
231
|
+
}
|
|
232
|
+
}));
|
|
233
|
+
const images = refs.filter((ref) => ref !== undefined);
|
|
234
|
+
return { text: input.text, ...(images.length === 0 ? {} : { images }), ...withContexts };
|
|
235
|
+
}));
|
|
236
|
+
if (stopped) {
|
|
237
|
+
// Nothing was parked: hand the claim back so a later apply (the entry's
|
|
238
|
+
// next boot pass) can still take these inputs. The file is still there.
|
|
239
|
+
release();
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
try {
|
|
243
|
+
channel.holdInputs(submissions);
|
|
244
|
+
}
|
|
245
|
+
catch {
|
|
246
|
+
// The screen refused the rows (disposed mid-staging): keep the file for
|
|
247
|
+
// the resume command and let a later pass take the handoff.
|
|
248
|
+
release();
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
89
251
|
settle();
|
|
90
|
-
|
|
252
|
+
};
|
|
253
|
+
// Whoever holds first owns the handoff, and owns it from before the async
|
|
254
|
+
// staging starts: a stale listener whose channel turns ready mid-staging
|
|
255
|
+
// must not park the same inputs a second time.
|
|
256
|
+
const claim = () => {
|
|
257
|
+
if (handoff.claimed === true || waiting !== handoff)
|
|
258
|
+
return false;
|
|
259
|
+
handoff.claimed = true;
|
|
260
|
+
return true;
|
|
261
|
+
};
|
|
262
|
+
const take = () => {
|
|
263
|
+
if (stopped || waiting !== handoff)
|
|
264
|
+
return;
|
|
265
|
+
if (!claim()) {
|
|
266
|
+
// A sibling pass owns the handoff and is staging images; it may stop
|
|
267
|
+
// before it parks anything, so wait to be woken instead of returning.
|
|
268
|
+
claimWaiters.add(take);
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
claimWaiters.delete(take);
|
|
272
|
+
// A throw outside the per-image catch must not leave the claim held.
|
|
273
|
+
void hold().catch(() => { release(); });
|
|
274
|
+
};
|
|
275
|
+
const stop = () => {
|
|
276
|
+
stopped = true;
|
|
277
|
+
claimWaiters.delete(take);
|
|
278
|
+
};
|
|
279
|
+
if (channel.ready) {
|
|
280
|
+
take();
|
|
281
|
+
return stop;
|
|
91
282
|
}
|
|
92
283
|
const unsubscribe = channel.subscribe(() => {
|
|
93
284
|
if (!channel.ready)
|
|
94
285
|
return;
|
|
95
286
|
unsubscribe();
|
|
96
|
-
|
|
97
|
-
// same texts must never be parked twice.
|
|
98
|
-
if (waiting !== inputs)
|
|
99
|
-
return;
|
|
100
|
-
channel.holdInputs(texts);
|
|
101
|
-
settle();
|
|
287
|
+
take();
|
|
102
288
|
});
|
|
103
|
-
return
|
|
289
|
+
return () => {
|
|
290
|
+
stop();
|
|
291
|
+
unsubscribe();
|
|
292
|
+
};
|
|
104
293
|
}
|
|
105
294
|
/**
|
|
106
295
|
* The resume command after a restart that ended before any replacement took
|
|
107
|
-
* the held
|
|
296
|
+
* the held inputs (a stall, a failed spawn): their file stays, and the command
|
|
108
297
|
* hands it to the next launch. Windows has no shared env-assignment syntax:
|
|
109
298
|
* PowerShell and cmd.exe each get their own copy-pasteable line.
|
|
110
299
|
*/
|
|
@@ -120,19 +309,42 @@ export function heldInputsResumeCommand(command, env, platform = process.platfor
|
|
|
120
309
|
return `${HELD_INPUTS_ENV}='${file.replaceAll('\'', '\'\\\'\'')}' ${command}`;
|
|
121
310
|
}
|
|
122
311
|
/**
|
|
123
|
-
* Take (read and delete) the
|
|
312
|
+
* Take (read and delete) the inputs a `/restart` handed this process. One
|
|
124
313
|
* shot: the env marker is consumed too, so no child inherits it.
|
|
125
314
|
*/
|
|
126
315
|
export function takeHeldInputs(env = process.env, dir = DATA_DIR) {
|
|
127
316
|
const marked = env[HELD_INPUTS_ENV] !== undefined;
|
|
128
|
-
const {
|
|
317
|
+
const { inputs, file } = readHeldInputs(env, dir);
|
|
129
318
|
if (file !== undefined)
|
|
130
319
|
removeHeldFile(file);
|
|
131
|
-
if (marked)
|
|
320
|
+
if (marked) {
|
|
132
321
|
waiting = undefined;
|
|
133
|
-
|
|
322
|
+
claimWaiters.clear();
|
|
323
|
+
}
|
|
324
|
+
return inputs;
|
|
134
325
|
}
|
|
135
|
-
|
|
326
|
+
const heldContextOf = (value) => {
|
|
327
|
+
if (value === null || typeof value !== 'object')
|
|
328
|
+
return undefined;
|
|
329
|
+
const { source, sourceId, title, content, truncated } = value;
|
|
330
|
+
if (source !== 'panel' || typeof sourceId !== 'string' || typeof title !== 'string' || typeof content !== 'string')
|
|
331
|
+
return undefined;
|
|
332
|
+
return { source, sourceId, title, content, truncated: truncated === true };
|
|
333
|
+
};
|
|
334
|
+
const heldImageOf = (value) => {
|
|
335
|
+
if (value === null || typeof value !== 'object')
|
|
336
|
+
return undefined;
|
|
337
|
+
const { token, data, name } = value;
|
|
338
|
+
if (typeof token !== 'string' || typeof data !== 'string')
|
|
339
|
+
return undefined;
|
|
340
|
+
const bytes = new Uint8Array(Buffer.from(data, 'base64'));
|
|
341
|
+
// The bytes decide the type, not the file's word for it.
|
|
342
|
+
const mediaType = sniffImageMediaType(bytes);
|
|
343
|
+
if (mediaType === undefined)
|
|
344
|
+
return undefined;
|
|
345
|
+
return { token, data: bytes, mediaType, ...(typeof name === 'string' ? { name } : {}) };
|
|
346
|
+
};
|
|
347
|
+
/** Read the inputs and consume the env marker; `file` is what the caller
|
|
136
348
|
* deletes once it is done with them. */
|
|
137
349
|
function readHeldInputs(env, dir) {
|
|
138
350
|
const file = env[HELD_INPUTS_ENV];
|
|
@@ -140,14 +352,38 @@ function readHeldInputs(env, dir) {
|
|
|
140
352
|
// Only ever a file writeHeldInputs named, in the directory it writes to:
|
|
141
353
|
// the marker is env input, and the caller deletes what it names.
|
|
142
354
|
if (file === undefined || !HELD_INPUTS_FILE.test(basename(file)) || dirname(resolve(file)) !== resolve(dir))
|
|
143
|
-
return {
|
|
355
|
+
return { inputs: [] };
|
|
144
356
|
try {
|
|
145
357
|
const parsed = JSON.parse(readFileSync(file, 'utf8'));
|
|
146
|
-
const
|
|
147
|
-
|
|
358
|
+
const record = parsed !== null && typeof parsed === 'object' ? parsed : undefined;
|
|
359
|
+
// A file an older build wrote holds `{texts: [...]}` (and no images). The
|
|
360
|
+
// resume command that build printed still names it: read it instead of
|
|
361
|
+
// deleting the queued texts as an empty handoff.
|
|
362
|
+
const inputs = record?.inputs ?? record?.texts;
|
|
363
|
+
if (!Array.isArray(inputs))
|
|
364
|
+
return { inputs: [], file };
|
|
365
|
+
return {
|
|
366
|
+
inputs: inputs.flatMap((input) => {
|
|
367
|
+
if (typeof input === 'string')
|
|
368
|
+
return input.trim() === '' ? [] : [{ text: input }];
|
|
369
|
+
if (input === null || typeof input !== 'object')
|
|
370
|
+
return [];
|
|
371
|
+
const { text, images, contexts } = input;
|
|
372
|
+
if (typeof text !== 'string' || text.trim() === '')
|
|
373
|
+
return [];
|
|
374
|
+
const held = Array.isArray(images) ? images.map(heldImageOf).filter((image) => image !== undefined) : [];
|
|
375
|
+
const carried = Array.isArray(contexts) ? contexts.map(heldContextOf).filter((context) => context !== undefined) : [];
|
|
376
|
+
return [{
|
|
377
|
+
text,
|
|
378
|
+
...(held.length === 0 ? {} : { images: held }),
|
|
379
|
+
...(carried.length === 0 ? {} : { contexts: carried }),
|
|
380
|
+
}];
|
|
381
|
+
}),
|
|
382
|
+
file,
|
|
383
|
+
};
|
|
148
384
|
}
|
|
149
385
|
catch {
|
|
150
|
-
return {
|
|
386
|
+
return { inputs: [], file };
|
|
151
387
|
}
|
|
152
388
|
}
|
|
153
389
|
/** Remove held-input files older than the resume window (best effort). */
|