@deepseek-harness-tui/dsh-tui 0.17.0 → 0.19.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.
Files changed (318) hide show
  1. package/README.md +43 -16
  2. package/bin/dsh-tui.js +46 -3
  3. package/cli/adapters/dsh/index.mjs +2 -2
  4. package/guide/dsh-tui-guide/cli.en.md +1 -1
  5. package/guide/dsh-tui-guide/cli.md +1 -1
  6. package/guide/dsh-tui-guide/codex-backend.en.md +2 -2
  7. package/guide/dsh-tui-guide/codex-backend.md +2 -2
  8. package/guide/dsh-tui-guide/configuration.en.md +8 -2
  9. package/guide/dsh-tui-guide/configuration.md +8 -2
  10. package/guide/dsh-tui-guide/getting-started.en.md +174 -6
  11. package/guide/dsh-tui-guide/getting-started.md +125 -15
  12. package/guide/dsh-tui-guide/interaction.en.md +30 -8
  13. package/guide/dsh-tui-guide/interaction.md +18 -5
  14. package/guide/dsh-tui-guide/plugins.en.md +28 -7
  15. package/guide/dsh-tui-guide/plugins.md +18 -5
  16. package/guide/dsh-tui-guide/user-guide.en.md +32 -17
  17. package/guide/dsh-tui-guide/user-guide.md +23 -12
  18. package/lib/settings.json +3 -3
  19. package/lib/types/adapter/channel/ui-policy.d.ts +1 -0
  20. package/lib/types/adapter/channel/ui-policy.d.ts.map +1 -1
  21. package/lib/types/adapter/channel/ui-policy.js +1 -0
  22. package/lib/types/adapter/ports/channel-ui.d.ts +10 -2
  23. package/lib/types/adapter/ports/channel-ui.d.ts.map +1 -1
  24. package/lib/types/adapter/ports/channel-view.d.ts +31 -5
  25. package/lib/types/adapter/ports/channel-view.d.ts.map +1 -1
  26. package/lib/types/adapter/standard/grants.d.ts +60 -0
  27. package/lib/types/adapter/standard/grants.d.ts.map +1 -1
  28. package/lib/types/adapter/standard/grants.js +74 -0
  29. package/lib/types/agent/events.d.ts +16 -3
  30. package/lib/types/agent/events.d.ts.map +1 -1
  31. package/lib/types/agent/session.d.ts +5 -0
  32. package/lib/types/agent/session.d.ts.map +1 -1
  33. package/lib/types/backends/claude/translate/core.d.ts +2 -2
  34. package/lib/types/backends/claude/translate/core.d.ts.map +1 -1
  35. package/lib/types/backends/claude/translate/core.js +10 -6
  36. package/lib/types/backends/codex/session/commands.d.ts +2 -0
  37. package/lib/types/backends/codex/session/commands.d.ts.map +1 -1
  38. package/lib/types/backends/codex/session/commands.js +8 -4
  39. package/lib/types/backends/codex/session/input.d.ts +11 -7
  40. package/lib/types/backends/codex/session/input.d.ts.map +1 -1
  41. package/lib/types/backends/codex/session/input.js +68 -15
  42. package/lib/types/backends/codex/session/session.d.ts.map +1 -1
  43. package/lib/types/backends/codex/session/session.js +2 -3
  44. package/lib/types/channel/projection.d.ts.map +1 -1
  45. package/lib/types/channel/projection.js +78 -10
  46. package/lib/types/channel/questions.d.ts +19 -3
  47. package/lib/types/channel/questions.d.ts.map +1 -1
  48. package/lib/types/channel/sanitize.d.ts.map +1 -1
  49. package/lib/types/channel/sanitize.js +8 -4
  50. package/lib/types/channel/subagent-failure.d.ts +49 -0
  51. package/lib/types/channel/subagent-failure.d.ts.map +1 -0
  52. package/lib/types/channel/subagent-failure.js +59 -0
  53. package/lib/types/channel/transcript.d.ts +17 -0
  54. package/lib/types/channel/transcript.d.ts.map +1 -1
  55. package/lib/types/channel/transcript.js +35 -0
  56. package/lib/types/commands.js +2 -2
  57. package/lib/types/components/GoalTodoPanel.d.ts +71 -6
  58. package/lib/types/components/GoalTodoPanel.d.ts.map +1 -1
  59. package/lib/types/components/GoalTodoPanel.js +165 -17
  60. package/lib/types/components/MessageList.d.ts.map +1 -1
  61. package/lib/types/components/MessageList.js +14 -9
  62. package/lib/types/components/PluginGrantList.d.ts +45 -0
  63. package/lib/types/components/PluginGrantList.d.ts.map +1 -0
  64. package/lib/types/components/PluginGrantList.js +126 -0
  65. package/lib/types/components/PluginInstallPane.d.ts.map +1 -1
  66. package/lib/types/components/PluginInstallPane.js +35 -6
  67. package/lib/types/components/PluginManagePane.d.ts.map +1 -1
  68. package/lib/types/components/PluginManagePane.js +65 -8
  69. package/lib/types/components/PromptInput.d.ts.map +1 -1
  70. package/lib/types/components/PromptInput.js +63 -8
  71. package/lib/types/components/SubagentDashboard.d.ts.map +1 -1
  72. package/lib/types/components/SubagentDashboard.js +17 -1
  73. package/lib/types/components/SubagentDetailScene.d.ts.map +1 -1
  74. package/lib/types/components/SubagentDetailScene.js +12 -0
  75. package/lib/types/components/messages/AssistantToolUseMessage.d.ts +2 -1
  76. package/lib/types/components/messages/AssistantToolUseMessage.d.ts.map +1 -1
  77. package/lib/types/components/messages/AssistantToolUseMessage.js +16 -7
  78. package/lib/types/components/onboardingModel.d.ts +2 -2
  79. package/lib/types/components/onboardingModel.js +3 -3
  80. package/lib/types/components/onboardingProviderPlan.d.ts +110 -0
  81. package/lib/types/components/onboardingProviderPlan.d.ts.map +1 -0
  82. package/lib/types/components/onboardingProviderPlan.js +78 -0
  83. package/lib/types/components/questions/AskUserQuestionPanel.d.ts +5 -8
  84. package/lib/types/components/questions/AskUserQuestionPanel.d.ts.map +1 -1
  85. package/lib/types/components/questions/AskUserQuestionPanel.js +7 -4
  86. package/lib/types/components/questions/PlanReviewPanel.d.ts +3 -6
  87. package/lib/types/components/questions/PlanReviewPanel.d.ts.map +1 -1
  88. package/lib/types/components/revealScope.d.ts +15 -0
  89. package/lib/types/components/revealScope.d.ts.map +1 -0
  90. package/lib/types/components/revealScope.js +17 -0
  91. package/lib/types/components/sidePanel/btw/BtwComposer.d.ts +41 -1
  92. package/lib/types/components/sidePanel/btw/BtwComposer.d.ts.map +1 -1
  93. package/lib/types/components/sidePanel/btw/BtwComposer.js +123 -6
  94. package/lib/types/components/sidePanel/btw/BtwPanelAdapter.d.ts.map +1 -1
  95. package/lib/types/components/sidePanel/btw/BtwPanelAdapter.js +9 -2
  96. package/lib/types/components/sidePanel/btw/BtwThreadScene.d.ts +7 -1
  97. package/lib/types/components/sidePanel/btw/BtwThreadScene.d.ts.map +1 -1
  98. package/lib/types/components/sidePanel/btw/BtwThreadScene.js +9 -2
  99. package/lib/types/components/sidePanel/btw/useBtwComposerPaste.d.ts +30 -0
  100. package/lib/types/components/sidePanel/btw/useBtwComposerPaste.d.ts.map +1 -0
  101. package/lib/types/components/sidePanel/btw/useBtwComposerPaste.js +94 -0
  102. package/lib/types/components/sidePanel/builtinPanels.d.ts.map +1 -1
  103. package/lib/types/components/sidePanel/builtinPanels.js +14 -2
  104. package/lib/types/components/sidePanel/types.d.ts +2 -0
  105. package/lib/types/components/sidePanel/types.d.ts.map +1 -1
  106. package/lib/types/components/sidePanel/useSidePanel.d.ts.map +1 -1
  107. package/lib/types/components/sidePanel/useSidePanel.js +15 -1
  108. package/lib/types/components/smoothReveal.d.ts +36 -6
  109. package/lib/types/components/smoothReveal.d.ts.map +1 -1
  110. package/lib/types/components/smoothReveal.js +92 -21
  111. package/lib/types/components/workspaces/HomeWorkspaceRow.d.ts +4 -14
  112. package/lib/types/components/workspaces/HomeWorkspaceRow.d.ts.map +1 -1
  113. package/lib/types/components/workspaces/HomeWorkspaceRow.js +26 -17
  114. package/lib/types/dsh-adapter/backend/session.d.ts +7 -1
  115. package/lib/types/dsh-adapter/backend/session.d.ts.map +1 -1
  116. package/lib/types/dsh-adapter/backend/session.js +74 -6
  117. package/lib/types/dsh-adapter/backend/translate.d.ts.map +1 -1
  118. package/lib/types/dsh-adapter/backend/translate.js +15 -6
  119. package/lib/types/dsh-adapter/channel/agent-view-projection.d.ts +1 -1
  120. package/lib/types/dsh-adapter/channel/agent-view-projection.d.ts.map +1 -1
  121. package/lib/types/dsh-adapter/channel/agent-view-projection.js +3 -1
  122. package/lib/types/dsh-adapter/channel/attached-context.d.ts +15 -2
  123. package/lib/types/dsh-adapter/channel/attached-context.d.ts.map +1 -1
  124. package/lib/types/dsh-adapter/channel/attached-context.js +26 -3
  125. package/lib/types/dsh-adapter/channel/binding-events.d.ts +3 -0
  126. package/lib/types/dsh-adapter/channel/binding-events.d.ts.map +1 -1
  127. package/lib/types/dsh-adapter/channel/binding-events.js +43 -2
  128. package/lib/types/dsh-adapter/channel/composer-images.d.ts +2 -0
  129. package/lib/types/dsh-adapter/channel/composer-images.d.ts.map +1 -1
  130. package/lib/types/dsh-adapter/channel/composer-images.js +10 -2
  131. package/lib/types/dsh-adapter/channel/composer-mentions.d.ts.map +1 -1
  132. package/lib/types/dsh-adapter/channel/composer-mentions.js +22 -7
  133. package/lib/types/dsh-adapter/channel/context-bookkeeping.d.ts +3 -7
  134. package/lib/types/dsh-adapter/channel/context-bookkeeping.d.ts.map +1 -1
  135. package/lib/types/dsh-adapter/channel/context-bookkeeping.js +16 -6
  136. package/lib/types/dsh-adapter/channel/core/binding-feed.d.ts +6 -0
  137. package/lib/types/dsh-adapter/channel/core/binding-feed.d.ts.map +1 -1
  138. package/lib/types/dsh-adapter/channel/core/binding-feed.js +35 -1
  139. package/lib/types/dsh-adapter/channel/core/compose.d.ts +3 -7
  140. package/lib/types/dsh-adapter/channel/core/compose.d.ts.map +1 -1
  141. package/lib/types/dsh-adapter/channel/core/compose.js +6 -1
  142. package/lib/types/dsh-adapter/channel/core/local-actions.d.ts.map +1 -1
  143. package/lib/types/dsh-adapter/channel/core/local-actions.js +3 -26
  144. package/lib/types/dsh-adapter/channel/emitter.js +1 -1
  145. package/lib/types/dsh-adapter/channel/extensions.d.ts.map +1 -1
  146. package/lib/types/dsh-adapter/channel/extensions.js +8 -0
  147. package/lib/types/dsh-adapter/channel/input-actions.d.ts +4 -4
  148. package/lib/types/dsh-adapter/channel/input-actions.d.ts.map +1 -1
  149. package/lib/types/dsh-adapter/channel/input-actions.js +59 -5
  150. package/lib/types/dsh-adapter/channel/input-delivery.d.ts +3 -7
  151. package/lib/types/dsh-adapter/channel/input-delivery.d.ts.map +1 -1
  152. package/lib/types/dsh-adapter/channel/input-delivery.js +21 -8
  153. package/lib/types/dsh-adapter/channel/mentions.d.ts.map +1 -1
  154. package/lib/types/dsh-adapter/channel/mentions.js +21 -7
  155. package/lib/types/dsh-adapter/channel/model-actions.d.ts +4 -1
  156. package/lib/types/dsh-adapter/channel/model-actions.d.ts.map +1 -1
  157. package/lib/types/dsh-adapter/channel/model-actions.js +26 -9
  158. package/lib/types/dsh-adapter/channel/model-selection.d.ts +27 -2
  159. package/lib/types/dsh-adapter/channel/model-selection.d.ts.map +1 -1
  160. package/lib/types/dsh-adapter/channel/model-selection.js +81 -37
  161. package/lib/types/dsh-adapter/channel/model-switch.d.ts +1 -1
  162. package/lib/types/dsh-adapter/channel/model-switch.d.ts.map +1 -1
  163. package/lib/types/dsh-adapter/channel/paths.d.ts.map +1 -1
  164. package/lib/types/dsh-adapter/channel/paths.js +11 -9
  165. package/lib/types/dsh-adapter/channel/session-live-adoption.d.ts +1 -1
  166. package/lib/types/dsh-adapter/channel/session-live-adoption.d.ts.map +1 -1
  167. package/lib/types/dsh-adapter/channel/session-live-adoption.js +6 -1
  168. package/lib/types/dsh-adapter/channel/session-reset.d.ts.map +1 -1
  169. package/lib/types/dsh-adapter/channel/session-reset.js +3 -1
  170. package/lib/types/dsh-adapter/channel/session-resume.d.ts +1 -1
  171. package/lib/types/dsh-adapter/channel/session-resume.d.ts.map +1 -1
  172. package/lib/types/dsh-adapter/channel/session-resume.js +10 -3
  173. package/lib/types/dsh-adapter/channel/session-rewind.d.ts +1 -1
  174. package/lib/types/dsh-adapter/channel/session-rewind.d.ts.map +1 -1
  175. package/lib/types/dsh-adapter/channel/session-rewind.js +9 -3
  176. package/lib/types/dsh-adapter/channel/session-tree-actions.d.ts +1 -1
  177. package/lib/types/dsh-adapter/channel/session-tree-actions.d.ts.map +1 -1
  178. package/lib/types/dsh-adapter/channel/session-tree-actions.js +11 -5
  179. package/lib/types/dsh-adapter/channel/settings-host.d.ts.map +1 -1
  180. package/lib/types/dsh-adapter/channel/settings-host.js +6 -3
  181. package/lib/types/dsh-adapter/channel/transcript.d.ts +3 -2
  182. package/lib/types/dsh-adapter/channel/transcript.d.ts.map +1 -1
  183. package/lib/types/dsh-adapter/channel/transcript.js +13 -4
  184. package/lib/types/dsh-adapter/channel/types.d.ts +11 -2
  185. package/lib/types/dsh-adapter/channel/types.d.ts.map +1 -1
  186. package/lib/types/dsh-adapter/contract.d.ts +27 -3
  187. package/lib/types/dsh-adapter/contract.d.ts.map +1 -1
  188. package/lib/types/dsh-adapter/contract.js +47 -5
  189. package/lib/types/dsh-adapter/entry-slot.d.ts +6 -0
  190. package/lib/types/dsh-adapter/entry-slot.d.ts.map +1 -1
  191. package/lib/types/dsh-adapter/experimental-bundles.d.ts +3 -0
  192. package/lib/types/dsh-adapter/experimental-bundles.d.ts.map +1 -1
  193. package/lib/types/dsh-adapter/experimental-bundles.js +4 -0
  194. package/lib/types/dsh-adapter/fresh-agent.d.ts +1 -1
  195. package/lib/types/dsh-adapter/fresh-agent.d.ts.map +1 -1
  196. package/lib/types/dsh-adapter/fresh-agent.js +60 -11
  197. package/lib/types/dsh-adapter/grant-file.d.ts +70 -0
  198. package/lib/types/dsh-adapter/grant-file.d.ts.map +1 -0
  199. package/lib/types/dsh-adapter/grant-file.js +178 -0
  200. package/lib/types/dsh-adapter/host-access.d.ts +4 -0
  201. package/lib/types/dsh-adapter/host-access.d.ts.map +1 -1
  202. package/lib/types/dsh-adapter/host-access.js +114 -15
  203. package/lib/types/dsh-adapter/host-contract.d.ts +1 -1
  204. package/lib/types/dsh-adapter/host-contract.d.ts.map +1 -1
  205. package/lib/types/dsh-adapter/host-contract.js +5 -3
  206. package/lib/types/dsh-adapter/host-dsh.d.ts +0 -8
  207. package/lib/types/dsh-adapter/host-dsh.d.ts.map +1 -1
  208. package/lib/types/dsh-adapter/host-dsh.js +27 -6
  209. package/lib/types/dsh-adapter/host-entry.js +4 -0
  210. package/lib/types/dsh-adapter/index.d.ts.map +1 -1
  211. package/lib/types/dsh-adapter/index.js +8 -5
  212. package/lib/types/dsh-adapter/oauth/profiles.d.ts.map +1 -1
  213. package/lib/types/dsh-adapter/oauth/profiles.js +14 -1
  214. package/lib/types/dsh-adapter/panels.d.ts +7 -1
  215. package/lib/types/dsh-adapter/panels.d.ts.map +1 -1
  216. package/lib/types/dsh-adapter/plugin-declaration.d.ts +28 -0
  217. package/lib/types/dsh-adapter/plugin-declaration.d.ts.map +1 -1
  218. package/lib/types/dsh-adapter/plugin-declaration.js +43 -1
  219. package/lib/types/dsh-adapter/plugin-install.d.ts +28 -1
  220. package/lib/types/dsh-adapter/plugin-install.d.ts.map +1 -1
  221. package/lib/types/dsh-adapter/plugin-install.js +160 -13
  222. package/lib/types/dsh-adapter/plugin-manage.d.ts +53 -10
  223. package/lib/types/dsh-adapter/plugin-manage.d.ts.map +1 -1
  224. package/lib/types/dsh-adapter/plugin-manage.js +240 -51
  225. package/lib/types/dsh-adapter/plugin.d.ts.map +1 -1
  226. package/lib/types/dsh-adapter/plugin.js +203 -58
  227. package/lib/types/dsh-adapter/plugins-info.d.ts +6 -7
  228. package/lib/types/dsh-adapter/plugins-info.d.ts.map +1 -1
  229. package/lib/types/dsh-adapter/plugins-info.js +34 -21
  230. package/lib/types/dsh-adapter/presets.d.ts +41 -10
  231. package/lib/types/dsh-adapter/presets.d.ts.map +1 -1
  232. package/lib/types/dsh-adapter/presets.js +59 -12
  233. package/lib/types/dsh-adapter/process-exit.d.ts +1 -1
  234. package/lib/types/dsh-adapter/process-exit.js +1 -1
  235. package/lib/types/dsh-adapter/providerWizard.d.ts +2 -0
  236. package/lib/types/dsh-adapter/providerWizard.d.ts.map +1 -1
  237. package/lib/types/dsh-adapter/providerWizard.js +11 -5
  238. package/lib/types/dsh-adapter/questions.d.ts +3 -4
  239. package/lib/types/dsh-adapter/questions.d.ts.map +1 -1
  240. package/lib/types/dsh-adapter/questions.js +1 -1
  241. package/lib/types/dsh-adapter/row-attachment.d.ts +30 -0
  242. package/lib/types/dsh-adapter/row-attachment.d.ts.map +1 -0
  243. package/lib/types/dsh-adapter/row-attachment.js +29 -0
  244. package/lib/types/dsh-adapter/session-list-metadata.js +2 -2
  245. package/lib/types/dsh-adapter/subagents.d.ts +5 -0
  246. package/lib/types/dsh-adapter/subagents.d.ts.map +1 -1
  247. package/lib/types/dsh-adapter/subagents.js +22 -1
  248. package/lib/types/dsh-adapter/team-mode.d.ts +17 -10
  249. package/lib/types/dsh-adapter/team-mode.d.ts.map +1 -1
  250. package/lib/types/dsh-adapter/team-mode.js +19 -12
  251. package/lib/types/dsh-adapter/tool-scope.d.ts +24 -0
  252. package/lib/types/dsh-adapter/tool-scope.d.ts.map +1 -0
  253. package/lib/types/dsh-adapter/tool-scope.js +127 -0
  254. package/lib/types/dsh-adapter/types.d.ts +2 -1
  255. package/lib/types/dsh-adapter/types.d.ts.map +1 -1
  256. package/lib/types/dsh-adapter/worktree-tool.d.ts +27 -0
  257. package/lib/types/dsh-adapter/worktree-tool.d.ts.map +1 -0
  258. package/lib/types/dsh-adapter/worktree-tool.js +87 -0
  259. package/lib/types/heldInputs.d.ts +75 -0
  260. package/lib/types/heldInputs.d.ts.map +1 -0
  261. package/lib/types/heldInputs.js +409 -0
  262. package/lib/types/i18n.d.ts +577 -34
  263. package/lib/types/i18n.d.ts.map +1 -1
  264. package/lib/types/i18n.js +230 -22
  265. package/lib/types/ink/components/App.d.ts +2 -0
  266. package/lib/types/ink/components/App.d.ts.map +1 -1
  267. package/lib/types/ink/components/App.js +8 -0
  268. package/lib/types/ink/events/input-event.d.ts.map +1 -1
  269. package/lib/types/ink/events/input-event.js +7 -6
  270. package/lib/types/ink/hit-test.d.ts +2 -0
  271. package/lib/types/ink/hit-test.d.ts.map +1 -1
  272. package/lib/types/ink/hit-test.js +10 -0
  273. package/lib/types/ink/hooks/use-program-status.d.ts +1 -1
  274. package/lib/types/ink/hooks/use-program-status.d.ts.map +1 -1
  275. package/lib/types/ink/hooks/use-program-status.js +3 -2
  276. package/lib/types/ink/ink.d.ts +1 -0
  277. package/lib/types/ink/ink.d.ts.map +1 -1
  278. package/lib/types/ink/ink.js +5 -2
  279. package/lib/types/ink/parse-keypress.d.ts.map +1 -1
  280. package/lib/types/ink/parse-keypress.js +25 -0
  281. package/lib/types/ink/terminal.d.ts +13 -2
  282. package/lib/types/ink/terminal.d.ts.map +1 -1
  283. package/lib/types/ink/terminal.js +29 -5
  284. package/lib/types/onboardingDraft.d.ts +143 -0
  285. package/lib/types/onboardingDraft.d.ts.map +1 -0
  286. package/lib/types/onboardingDraft.js +71 -0
  287. package/lib/types/screens/Chat.d.ts.map +1 -1
  288. package/lib/types/screens/Chat.js +133 -32
  289. package/lib/types/screens/Onboarding.d.ts +22 -3
  290. package/lib/types/screens/Onboarding.d.ts.map +1 -1
  291. package/lib/types/screens/Onboarding.js +606 -36
  292. package/lib/types/screens/SessionSupervisor.d.ts +3 -6
  293. package/lib/types/screens/SessionSupervisor.d.ts.map +1 -1
  294. package/lib/types/screens/SessionSupervisor.js +5 -8
  295. package/lib/types/screens/sessionSupervisor/ForeignSessionPanes.d.ts +1 -2
  296. package/lib/types/screens/sessionSupervisor/ForeignSessionPanes.d.ts.map +1 -1
  297. package/lib/types/screens/sessionSupervisor/ForeignSessionPanes.js +2 -2
  298. package/lib/types/screens/sessionSupervisor/model.d.ts +1 -1
  299. package/lib/types/screens/sessionSupervisor/model.js +1 -1
  300. package/lib/types/sessionMounts.d.ts +12 -5
  301. package/lib/types/sessionMounts.d.ts.map +1 -1
  302. package/lib/types/sessionMounts.js +33 -6
  303. package/lib/types/settings/definitions.js +2 -2
  304. package/lib/types/update.d.ts +412 -20
  305. package/lib/types/update.d.ts.map +1 -1
  306. package/lib/types/update.js +2094 -193
  307. package/lib/types/updateHost.d.ts +198 -0
  308. package/lib/types/updateHost.d.ts.map +1 -0
  309. package/lib/types/updateHost.js +608 -0
  310. package/lib/types/utils/paths.d.ts +15 -0
  311. package/lib/types/utils/paths.d.ts.map +1 -1
  312. package/lib/types/utils/paths.js +25 -0
  313. package/lib/types/utils/processName.d.ts +16 -0
  314. package/lib/types/utils/processName.d.ts.map +1 -0
  315. package/lib/types/utils/processName.js +27 -0
  316. package/package.json +114 -108
  317. package/tui-profile/feed/README.md +1 -1
  318. package/tui-profile/feed/first-party.json +1 -1
@@ -0,0 +1,409 @@
1
+ /**
2
+ * `/restart` carry-over of the composer queue (#1651): the queued and held
3
+ * texts the old process still showed are written to a per-restart file whose
4
+ * path rides the replacement's env, and the replacement parks them as held
5
+ * dock rows. The backend copies die with the old process (the kernel records
6
+ * them as canceled), so nothing re-sends them until the user sends the dock.
7
+ * Staged images live in the old process's memory: their bytes ride the file
8
+ * and the replacement stages them again.
9
+ */
10
+ import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
11
+ import { randomBytes } from 'node:crypto';
12
+ import { basename, dirname, join, resolve } from 'node:path';
13
+ import { sniffImageMediaType } from './utils/imageResize.js';
14
+ import { DATA_DIR } from './utils/paths.js';
15
+ /** env marker naming the file the replacement takes its held inputs from. */
16
+ export const HELD_INPUTS_ENV = 'DSH_TUI_HELD_INPUTS';
17
+ const HELD_INPUTS_FILE = /^held-inputs-\d+-[0-9a-f]{12}\.json$/u;
18
+ /** A restart that stalled leaves its file for the printed resume command; one
19
+ * nobody resumed within this long is swept at a later launch. */
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;
23
+ /**
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.
77
+ * @returns The env marker to hand the replacement, or undefined when there
78
+ * is nothing to carry or the write failed (best effort: a restart never
79
+ * waits on it).
80
+ */
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() !== '');
83
+ if (kept.length === 0)
84
+ return undefined;
85
+ // Unique per restart: a stalled restart's file stays for its printed
86
+ // resume command, and a later process reusing the pid must not replace it.
87
+ const file = join(dir, `held-inputs-${pid}-${randomBytes(6).toString('hex')}.json`);
88
+ try {
89
+ mkdirSync(dir, { recursive: true });
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' });
101
+ return { [HELD_INPUTS_ENV]: file };
102
+ }
103
+ catch {
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
+ }
114
+ }
115
+ }
116
+ /**
117
+ * The one handoff this process has not settled yet. The DSH launcher's boot
118
+ * recompose applies the entry a second time, after the first pass consumed
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.
122
+ */
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();
132
+ /** Read the marker once per handoff; without a fresh one, hand back the
133
+ * pending handoff (the recompose asking again). */
134
+ function carriedInputs(env, dir) {
135
+ if (env[HELD_INPUTS_ENV] !== undefined)
136
+ waiting = readHeldInputs(env, dir);
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
+ });
152
+ }
153
+ /** Best effort: a file another process still holds open must not decide
154
+ * whether this one starts. */
155
+ function removeHeldFile(file) {
156
+ try {
157
+ rmSync(file, { force: true });
158
+ }
159
+ catch {
160
+ }
161
+ }
162
+ /**
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.
169
+ */
170
+ export function adoptHeldInputs(channel, env = process.env, dir = DATA_DIR) {
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.
176
+ const settle = () => {
177
+ if (file !== undefined)
178
+ removeHeldFile(file);
179
+ waiting = undefined;
180
+ claimWaiters.clear();
181
+ sweepHeldInputs(dir);
182
+ };
183
+ if (inputs.length === 0) {
184
+ settle();
185
+ return undefined;
186
+ }
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
+ }
251
+ settle();
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;
282
+ }
283
+ const unsubscribe = channel.subscribe(() => {
284
+ if (!channel.ready)
285
+ return;
286
+ unsubscribe();
287
+ take();
288
+ });
289
+ return () => {
290
+ stop();
291
+ unsubscribe();
292
+ };
293
+ }
294
+ /**
295
+ * The resume command after a restart that ended before any replacement took
296
+ * the held inputs (a stall, a failed spawn): their file stays, and the command
297
+ * hands it to the next launch. Windows has no shared env-assignment syntax:
298
+ * PowerShell and cmd.exe each get their own copy-pasteable line.
299
+ */
300
+ export function heldInputsResumeCommand(command, env, platform = process.platform) {
301
+ const file = env?.[HELD_INPUTS_ENV];
302
+ if (file === undefined || !existsSync(file))
303
+ return command;
304
+ if (platform === 'win32') {
305
+ // This line is the only way a stalled restart gets its texts back, and the
306
+ // two Windows shells disagree on how to set a variable: print both.
307
+ return `$env:${HELD_INPUTS_ENV}='${file.replaceAll('\'', '\'\'')}'; ${command}\nset "${HELD_INPUTS_ENV}=${file}" && ${command}`;
308
+ }
309
+ return `${HELD_INPUTS_ENV}='${file.replaceAll('\'', '\'\\\'\'')}' ${command}`;
310
+ }
311
+ /**
312
+ * Take (read and delete) the inputs a `/restart` handed this process. One
313
+ * shot: the env marker is consumed too, so no child inherits it.
314
+ */
315
+ export function takeHeldInputs(env = process.env, dir = DATA_DIR) {
316
+ const marked = env[HELD_INPUTS_ENV] !== undefined;
317
+ const { inputs, file } = readHeldInputs(env, dir);
318
+ if (file !== undefined)
319
+ removeHeldFile(file);
320
+ if (marked) {
321
+ waiting = undefined;
322
+ claimWaiters.clear();
323
+ }
324
+ return inputs;
325
+ }
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
348
+ * deletes once it is done with them. */
349
+ function readHeldInputs(env, dir) {
350
+ const file = env[HELD_INPUTS_ENV];
351
+ delete env[HELD_INPUTS_ENV];
352
+ // Only ever a file writeHeldInputs named, in the directory it writes to:
353
+ // the marker is env input, and the caller deletes what it names.
354
+ if (file === undefined || !HELD_INPUTS_FILE.test(basename(file)) || dirname(resolve(file)) !== resolve(dir))
355
+ return { inputs: [] };
356
+ try {
357
+ const parsed = JSON.parse(readFileSync(file, 'utf8'));
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
+ };
384
+ }
385
+ catch {
386
+ return { inputs: [], file };
387
+ }
388
+ }
389
+ /** Remove held-input files older than the resume window (best effort). */
390
+ export function sweepHeldInputs(dir = DATA_DIR, now = Date.now()) {
391
+ let names;
392
+ try {
393
+ names = readdirSync(dir);
394
+ }
395
+ catch {
396
+ return;
397
+ }
398
+ for (const name of names) {
399
+ if (!HELD_INPUTS_FILE.test(name))
400
+ continue;
401
+ const file = join(dir, name);
402
+ try {
403
+ if (now - statSync(file).mtimeMs > HELD_INPUTS_MAX_AGE_MS)
404
+ rmSync(file, { force: true });
405
+ }
406
+ catch {
407
+ }
408
+ }
409
+ }