@deepseek-harness-tui/dsh-tui 0.19.0 → 0.20.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (224) hide show
  1. package/README.md +67 -57
  2. package/bin/dsh-tui.js +26 -8
  3. package/cordis.patch.yml +5 -3
  4. package/cordis.yml +3 -2
  5. package/guide/dsh-tui-guide/claude-backend.en.md +6 -5
  6. package/guide/dsh-tui-guide/claude-backend.md +5 -5
  7. package/guide/dsh-tui-guide/configuration.en.md +1 -1
  8. package/guide/dsh-tui-guide/configuration.md +1 -1
  9. package/guide/dsh-tui-guide/getting-started.en.md +2 -2
  10. package/guide/dsh-tui-guide/getting-started.md +2 -2
  11. package/guide/dsh-tui-guide/migrate.en.md +5 -0
  12. package/guide/dsh-tui-guide/migrate.md +4 -0
  13. package/guide/dsh-tui-guide/plugins.en.md +17 -1
  14. package/guide/dsh-tui-guide/plugins.md +12 -1
  15. package/guide/dsh-tui-guide/user-guide.en.md +7 -2
  16. package/guide/dsh-tui-guide/user-guide.md +7 -2
  17. package/lib/settings.json +24 -8
  18. package/lib/types/adapter/kernel/host-facade.d.ts +3 -1
  19. package/lib/types/adapter/kernel/host-facade.d.ts.map +1 -1
  20. package/lib/types/adapter/kernel/host-facade.js +6 -0
  21. package/lib/types/adapter/kernel/runtime.d.ts.map +1 -1
  22. package/lib/types/adapter/kernel/runtime.js +5 -0
  23. package/lib/types/adapter/kernel/slices/extensions.d.ts +1 -0
  24. package/lib/types/adapter/kernel/slices/extensions.d.ts.map +1 -1
  25. package/lib/types/adapter/kernel/slices/extensions.js +6 -1
  26. package/lib/types/adapter/kernel/slices/index.d.ts +1 -1
  27. package/lib/types/adapter/kernel/slices/index.d.ts.map +1 -1
  28. package/lib/types/adapter/kernel/slices/index.js +3 -2
  29. package/lib/types/adapter/ports/channel-catalog.d.ts +19 -0
  30. package/lib/types/adapter/ports/channel-catalog.d.ts.map +1 -1
  31. package/lib/types/adapter/ports/channel-view.d.ts +39 -3
  32. package/lib/types/adapter/ports/channel-view.d.ts.map +1 -1
  33. package/lib/types/adapter/ports/extensions.d.ts +9 -0
  34. package/lib/types/adapter/ports/extensions.d.ts.map +1 -1
  35. package/lib/types/adapter/ports/index.d.ts +1 -1
  36. package/lib/types/adapter/ports/index.d.ts.map +1 -1
  37. package/lib/types/adapter/upstream/extensions-driver.d.ts +4 -1
  38. package/lib/types/adapter/upstream/extensions-driver.d.ts.map +1 -1
  39. package/lib/types/adapter/upstream/extensions-driver.js +111 -1
  40. package/lib/types/adapter/upstream/index.d.ts +1 -1
  41. package/lib/types/adapter/upstream/index.d.ts.map +1 -1
  42. package/lib/types/adapter/upstream/index.js +1 -1
  43. package/lib/types/agent/events.d.ts +3 -1
  44. package/lib/types/agent/events.d.ts.map +1 -1
  45. package/lib/types/api.d.ts +1 -1
  46. package/lib/types/api.d.ts.map +1 -1
  47. package/lib/types/backends/claude/backend.d.ts.map +1 -1
  48. package/lib/types/backends/claude/backend.js +7 -2
  49. package/lib/types/backends/claude/tools.d.ts.map +1 -1
  50. package/lib/types/backends/claude/tools.js +8 -3
  51. package/lib/types/backends/codex/translate/presentation.d.ts.map +1 -1
  52. package/lib/types/backends/codex/translate/presentation.js +5 -2
  53. package/lib/types/channel/interaction.d.ts.map +1 -1
  54. package/lib/types/channel/interaction.js +1 -0
  55. package/lib/types/channel/permissions.d.ts +15 -0
  56. package/lib/types/channel/permissions.d.ts.map +1 -1
  57. package/lib/types/channel/permissions.js +28 -0
  58. package/lib/types/channel/projection.d.ts.map +1 -1
  59. package/lib/types/channel/projection.js +11 -1
  60. package/lib/types/channel/questions.d.ts +26 -0
  61. package/lib/types/channel/questions.d.ts.map +1 -1
  62. package/lib/types/channel/questions.js +43 -0
  63. package/lib/types/commands.js +1 -1
  64. package/lib/types/components/FileSuggestions.d.ts +2 -2
  65. package/lib/types/components/FileSuggestions.d.ts.map +1 -1
  66. package/lib/types/components/FileSuggestions.js +25 -5
  67. package/lib/types/components/MessageList.d.ts.map +1 -1
  68. package/lib/types/components/MessageList.js +3 -3
  69. package/lib/types/components/PromptInput.d.ts +7 -1
  70. package/lib/types/components/PromptInput.d.ts.map +1 -1
  71. package/lib/types/components/PromptInput.js +81 -23
  72. package/lib/types/components/SplitDiffView.d.ts.map +1 -1
  73. package/lib/types/components/SplitDiffView.js +3 -2
  74. package/lib/types/components/StarPrompt.d.ts +5 -3
  75. package/lib/types/components/StarPrompt.d.ts.map +1 -1
  76. package/lib/types/components/StarPrompt.js +56 -6
  77. package/lib/types/components/SubagentCard.d.ts.map +1 -1
  78. package/lib/types/components/SubagentCard.js +1 -1
  79. package/lib/types/components/SubagentDashboard.d.ts.map +1 -1
  80. package/lib/types/components/SubagentDashboard.js +3 -2
  81. package/lib/types/components/SubagentDetailScene.d.ts.map +1 -1
  82. package/lib/types/components/SubagentDetailScene.js +1 -1
  83. package/lib/types/components/messages/AssistantToolUseMessage.d.ts.map +1 -1
  84. package/lib/types/components/messages/AssistantToolUseMessage.js +121 -23
  85. package/lib/types/components/teamRoster.d.ts +6 -3
  86. package/lib/types/components/teamRoster.d.ts.map +1 -1
  87. package/lib/types/dsh-adapter/approvals.d.ts +19 -0
  88. package/lib/types/dsh-adapter/approvals.d.ts.map +1 -1
  89. package/lib/types/dsh-adapter/approvals.js +17 -1
  90. package/lib/types/dsh-adapter/backend/translate.d.ts.map +1 -1
  91. package/lib/types/dsh-adapter/backend/translate.js +15 -3
  92. package/lib/types/dsh-adapter/channel/extensions.d.ts.map +1 -1
  93. package/lib/types/dsh-adapter/channel/extensions.js +7 -4
  94. package/lib/types/dsh-adapter/channel/local-actions.d.ts.map +1 -1
  95. package/lib/types/dsh-adapter/channel/local-actions.js +7 -3
  96. package/lib/types/dsh-adapter/channel/projection-helpers.d.ts.map +1 -1
  97. package/lib/types/dsh-adapter/channel/projection-helpers.js +4 -2
  98. package/lib/types/dsh-adapter/channel/settings-host.d.ts.map +1 -1
  99. package/lib/types/dsh-adapter/channel/settings-host.js +179 -33
  100. package/lib/types/dsh-adapter/channel/subagent-projection.d.ts +55 -4
  101. package/lib/types/dsh-adapter/channel/subagent-projection.d.ts.map +1 -1
  102. package/lib/types/dsh-adapter/channel/subagent-projection.js +80 -16
  103. package/lib/types/dsh-adapter/channel/subagent-transcript.d.ts +1 -1
  104. package/lib/types/dsh-adapter/channel/subagent-transcript.d.ts.map +1 -1
  105. package/lib/types/dsh-adapter/channel/subagent-transcript.js +6 -5
  106. package/lib/types/dsh-adapter/channel/task-completion.js +2 -10
  107. package/lib/types/dsh-adapter/childStderr.d.ts +1 -1
  108. package/lib/types/dsh-adapter/childStderr.d.ts.map +1 -1
  109. package/lib/types/dsh-adapter/childStderr.js +5 -0
  110. package/lib/types/dsh-adapter/compat/compaction-previews.d.ts +11 -0
  111. package/lib/types/dsh-adapter/compat/compaction-previews.d.ts.map +1 -0
  112. package/lib/types/dsh-adapter/compat/compaction-previews.js +38 -0
  113. package/lib/types/dsh-adapter/compat/messages.d.ts +1 -1
  114. package/lib/types/dsh-adapter/compat/messages.d.ts.map +1 -1
  115. package/lib/types/dsh-adapter/compat/messages.js +2 -2
  116. package/lib/types/dsh-adapter/contract.d.ts +12 -5
  117. package/lib/types/dsh-adapter/contract.d.ts.map +1 -1
  118. package/lib/types/dsh-adapter/contract.js +15 -4
  119. package/lib/types/dsh-adapter/experimental-bundles.d.ts +5 -0
  120. package/lib/types/dsh-adapter/experimental-bundles.d.ts.map +1 -1
  121. package/lib/types/dsh-adapter/experimental-bundles.js +0 -2
  122. package/lib/types/dsh-adapter/extensions.d.ts +3 -2
  123. package/lib/types/dsh-adapter/extensions.d.ts.map +1 -1
  124. package/lib/types/dsh-adapter/extensions.js +5 -2
  125. package/lib/types/dsh-adapter/host-contract.d.ts +1 -1
  126. package/lib/types/dsh-adapter/host-contract.js +2 -2
  127. package/lib/types/dsh-adapter/host-dsh.d.ts +6 -0
  128. package/lib/types/dsh-adapter/host-dsh.d.ts.map +1 -1
  129. package/lib/types/dsh-adapter/host-dsh.js +29 -0
  130. package/lib/types/dsh-adapter/index.d.ts +9 -1
  131. package/lib/types/dsh-adapter/index.d.ts.map +1 -1
  132. package/lib/types/dsh-adapter/index.js +5 -0
  133. package/lib/types/dsh-adapter/mention-providers.d.ts +91 -0
  134. package/lib/types/dsh-adapter/mention-providers.d.ts.map +1 -0
  135. package/lib/types/dsh-adapter/mention-providers.js +214 -0
  136. package/lib/types/dsh-adapter/migrate/entry.d.ts +2 -0
  137. package/lib/types/dsh-adapter/migrate/entry.d.ts.map +1 -0
  138. package/lib/types/dsh-adapter/migrate/entry.js +46 -0
  139. package/lib/types/dsh-adapter/oauth/account-notifications.d.ts +73 -0
  140. package/lib/types/dsh-adapter/oauth/account-notifications.d.ts.map +1 -0
  141. package/lib/types/dsh-adapter/oauth/account-notifications.js +250 -0
  142. package/lib/types/dsh-adapter/oauth/bonus.d.ts +34 -9
  143. package/lib/types/dsh-adapter/oauth/bonus.d.ts.map +1 -1
  144. package/lib/types/dsh-adapter/oauth/bonus.js +47 -5
  145. package/lib/types/dsh-adapter/oauth/deepseek.d.ts +7 -2
  146. package/lib/types/dsh-adapter/oauth/deepseek.d.ts.map +1 -1
  147. package/lib/types/dsh-adapter/oauth/deepseek.js +6 -1
  148. package/lib/types/dsh-adapter/oauth/index.d.ts.map +1 -1
  149. package/lib/types/dsh-adapter/oauth/index.js +44 -0
  150. package/lib/types/dsh-adapter/oauth/service.d.ts.map +1 -1
  151. package/lib/types/dsh-adapter/oauth/service.js +5 -6
  152. package/lib/types/dsh-adapter/plugin-manage.d.ts +6 -4
  153. package/lib/types/dsh-adapter/plugin-manage.d.ts.map +1 -1
  154. package/lib/types/dsh-adapter/plugin-manage.js +3 -2
  155. package/lib/types/dsh-adapter/plugin.d.ts +237 -6
  156. package/lib/types/dsh-adapter/plugin.d.ts.map +1 -1
  157. package/lib/types/dsh-adapter/plugin.js +611 -23
  158. package/lib/types/dsh-adapter/session-projection-store.d.ts +1 -1
  159. package/lib/types/dsh-adapter/session-projection-store.d.ts.map +1 -1
  160. package/lib/types/dsh-adapter/session-projection-store.js +30 -23
  161. package/lib/types/dsh-adapter/sessionTree.d.ts.map +1 -1
  162. package/lib/types/dsh-adapter/sessionTree.js +4 -1
  163. package/lib/types/dsh-adapter/subagents.d.ts +1 -0
  164. package/lib/types/dsh-adapter/subagents.d.ts.map +1 -1
  165. package/lib/types/dsh-adapter/subagents.js +10 -2
  166. package/lib/types/dsh-adapter/team-mode.d.ts +29 -17
  167. package/lib/types/dsh-adapter/team-mode.d.ts.map +1 -1
  168. package/lib/types/dsh-adapter/team-mode.js +138 -17
  169. package/lib/types/dsh-adapter/team-roster.d.ts +53 -18
  170. package/lib/types/dsh-adapter/team-roster.d.ts.map +1 -1
  171. package/lib/types/dsh-adapter/team-roster.js +206 -39
  172. package/lib/types/dsh-adapter/team-tools.d.ts +25 -12
  173. package/lib/types/dsh-adapter/team-tools.d.ts.map +1 -1
  174. package/lib/types/dsh-adapter/team-tools.js +81 -26
  175. package/lib/types/extensions.d.ts +2 -0
  176. package/lib/types/extensions.d.ts.map +1 -1
  177. package/lib/types/extensions.js +4 -1
  178. package/lib/types/i18n.d.ts +71 -11
  179. package/lib/types/i18n.d.ts.map +1 -1
  180. package/lib/types/i18n.js +32 -9
  181. package/lib/types/ink/dom.d.ts.map +1 -1
  182. package/lib/types/ink/dom.js +13 -3
  183. package/lib/types/ink/flush-tick.d.ts +6 -0
  184. package/lib/types/ink/flush-tick.d.ts.map +1 -1
  185. package/lib/types/ink/flush-tick.js +31 -0
  186. package/lib/types/ink/hooks/use-terminal-title.d.ts +15 -0
  187. package/lib/types/ink/hooks/use-terminal-title.d.ts.map +1 -1
  188. package/lib/types/ink/hooks/use-terminal-title.js +23 -3
  189. package/lib/types/ink/ink.js +2 -2
  190. package/lib/types/ink/jumpback-state.d.ts +33 -0
  191. package/lib/types/ink/jumpback-state.d.ts.map +1 -0
  192. package/lib/types/ink/jumpback-state.js +51 -0
  193. package/lib/types/ink/jumpback.d.ts +78 -0
  194. package/lib/types/ink/jumpback.d.ts.map +1 -0
  195. package/lib/types/ink/jumpback.js +515 -0
  196. package/lib/types/ink/log-update.js +37 -14
  197. package/lib/types/ink/notify-helper/activate.cs +836 -0
  198. package/lib/types/ink/notify-helper/compile.d.ts +30 -0
  199. package/lib/types/ink/notify-helper/compile.d.ts.map +1 -0
  200. package/lib/types/ink/notify-helper/compile.js +235 -0
  201. package/lib/types/ink/terminal-notification-windows.d.ts +8 -4
  202. package/lib/types/ink/terminal-notification-windows.d.ts.map +1 -1
  203. package/lib/types/ink/terminal-notification-windows.js +14 -21
  204. package/lib/types/ink/terminal-notification.d.ts +31 -2
  205. package/lib/types/ink/terminal-notification.d.ts.map +1 -1
  206. package/lib/types/ink/terminal-notification.js +51 -0
  207. package/lib/types/ink/terminal.d.ts +2 -1
  208. package/lib/types/ink/terminal.d.ts.map +1 -1
  209. package/lib/types/ink/terminal.js +9 -4
  210. package/lib/types/screens/AgentTranscriptScene.d.ts.map +1 -1
  211. package/lib/types/screens/AgentTranscriptScene.js +1 -1
  212. package/lib/types/screens/Chat.d.ts +8 -4
  213. package/lib/types/screens/Chat.d.ts.map +1 -1
  214. package/lib/types/screens/Chat.js +40 -11
  215. package/lib/types/settings/definitions.d.ts +12 -0
  216. package/lib/types/settings/definitions.d.ts.map +1 -1
  217. package/lib/types/settings/definitions.js +15 -7
  218. package/lib/types/utils/fileSuggestions.d.ts +14 -3
  219. package/lib/types/utils/fileSuggestions.d.ts.map +1 -1
  220. package/lib/types/utils/fileSuggestions.js +33 -0
  221. package/package.json +117 -112
  222. package/presets/liangshen/agent.cordis.yml +4 -0
  223. package/tui-profile/feed/README.md +1 -1
  224. package/tui-profile/feed/first-party.json +1 -1
@@ -28,14 +28,16 @@ import { removeClipboardImageDir } from '../utils/clipboard.js';
28
28
  import { appendCrashLog, serializeCrashDetail, unserializableCrashDetail } from '../utils/crashDetail.js';
29
29
  import { pluginManagerOf } from './plugin-manager.js';
30
30
  import { logForDebugging } from '../utils/debug.js';
31
- import { createTerminalNotifier } from '../ink/terminal-notification.js';
31
+ import { clipToWidthGraphemes, createTerminalNotifier, notificationText } from '../ink/terminal-notification.js';
32
32
  import { getTerminalFocused } from '../ink/terminal-focus-state.js';
33
+ import { createJumpBack, isMarkerFileSession } from '../ink/jumpback.js';
34
+ import { getJumpBackState, setJumpBackEnabled } from '../ink/jumpback-state.js';
33
35
  import { resolveNotificationMethod } from '../ink/terminal.js';
34
36
  import { isEnvTruthy } from '../utils/envUtils.js';
35
37
  import { QuestionStore, bindQuestionStore } from './questions.js';
36
38
  import { prepareQuestionAnswerer } from './questions-answerer.js';
37
39
  import { adapterRuntimeFor } from '../adapter/kernel/runtime-context.js';
38
- import { ApprovalStore, bindApprovalStore } from './approvals.js';
40
+ import { ApprovalStore, bindApprovalStore, reasonOf } from './approvals.js';
39
41
  import { PermissionStore } from '../channel/permissions.js';
40
42
  import { registerPromptDebug } from './promptDebug.js';
41
43
  import { readActivityFrames } from '../activityPrefs.js';
@@ -77,6 +79,7 @@ import { createTeamRosterStore } from './team-roster.js';
77
79
  import { createTeamCommandEntry, filterTeamReplacedTools } from './team-mode.js';
78
80
  import { getHostToastStore } from './toast.js';
79
81
  import { getHostShortcuts } from './shortcuts.js';
82
+ import { getHostMentions } from './mention-providers.js';
80
83
  import { getHostThemes } from './themes.js';
81
84
  import { attachSessionToWorkspace } from './workspace.js';
82
85
  import { createLocalWorkspaceRuntime, getHostWorkspaceRuntime } from './workspaces.js';
@@ -183,7 +186,22 @@ export function createTaskNotificationSettings(notifier, initial) {
183
186
  };
184
187
  }
185
188
  /**
186
- * Ring the terminal for a completion the host's gate already approved.
189
+ * Whether a notification is announced at all: the one gate shared by task
190
+ * completions and waiting interruptions, asked before the Windows transport so
191
+ * a suppressed notification never costs a PowerShell process, and so a
192
+ * delivered toast never also rings the bell. The Windows fallback re-enters
193
+ * through `ringTaskCompletion`, which carries this answer instead of asking the
194
+ * focus question again after the awaits.
195
+ * @param settings - The live notification settings.
196
+ * @param stdoutTty - Whether stdout is a TTY right now.
197
+ * @param focused - Whether the terminal reports focus right now.
198
+ * @returns True when the switch and the focus policy say this notification is due.
199
+ */
200
+ export function notificationAlertsEnabled(settings, stdoutTty, focused) {
201
+ return stdoutTty && settings.condition !== 'off' && !(settings.condition === 'unfocused' && focused);
202
+ }
203
+ /**
204
+ * Ring the terminal for a notification the host's gate already approved.
187
205
  *
188
206
  * The gate asks whether the terminal is focused; this port runs after the toast's
189
207
  * await, which is up to 30 s of PowerShell. Asking the focus question a second
@@ -207,7 +225,7 @@ export function ringTaskCompletion(notifier, settings, title, message) {
207
225
  }
208
226
  }
209
227
  /**
210
- * Show one task-completion toast and answer for what it did.
228
+ * Show one notification toast and answer for what it did.
211
229
  *
212
230
  * Exactly one answer reaches the terminal path: `unavailable` rings the bell
213
231
  * (AC-5), because the alternative is a notification the user never learns
@@ -218,12 +236,15 @@ export function ringTaskCompletion(notifier, settings, title, message) {
218
236
  * without a toast, a registry write or a child process.
219
237
  * @param title - The localized title.
220
238
  * @param message - The single-line summary; empty shows the title alone.
221
- * @param backendId - The session that completed; a DSH plugin only covers DSH events.
239
+ * @param backendId - The session the notification speaks for; a DSH plugin only covers DSH events.
222
240
  * @param delivery - The toast port, and the terminal path to fall back to.
223
241
  */
224
242
  export async function deliverTaskCompletionOnWindows(title, message, backendId, delivery) {
243
+ let target = refreshJumpBackMarker(delivery);
225
244
  let externalNotifierActive = false;
226
- if (backendId === 'dsh' && delivery.pluginManager !== undefined) {
245
+ // A delivery that opts out keeps `false` without paying for the inventory read:
246
+ // the caller already knows the external plugin does not cover this notice.
247
+ if (backendId === 'dsh' && delivery.pluginManager !== undefined && delivery.yieldToExternal !== false) {
227
248
  try {
228
249
  const plugins = await delivery.pluginManager.listPlugins();
229
250
  externalNotifierActive = plugins.some(plugin => plugin.enabled && plugin.fiberPhase === 'active'
@@ -233,23 +254,261 @@ export async function deliverTaskCompletionOnWindows(title, message, backendId,
233
254
  logForDebugging('external notifier inventory unavailable; using the built-in Windows notification');
234
255
  }
235
256
  }
257
+ // The inventory await is a toggle boundary too: a switch turned off while it
258
+ // ran already cleaned up, so the target taken before it must not register or
259
+ // promise anything now.
260
+ if (target !== undefined) {
261
+ const state = getJumpBackState();
262
+ if (!state.enabled || state.generation !== target.generation || !ownerAllows(delivery)) {
263
+ target = undefined;
264
+ }
265
+ }
266
+ // An external notifier ships this notification: only a toast this process sends
267
+ // can come back here, so no probe and no registration - the URI would never
268
+ // be clicked.
269
+ const launch = target === undefined || externalNotifierActive ? undefined : await jumpBackLaunch(target, delivery);
236
270
  const result = await delivery.toast({
237
271
  title,
238
272
  message,
239
273
  externalNotifierActive,
240
274
  canDispatch: delivery.canDispatch,
275
+ launch,
241
276
  });
242
277
  if (result.status !== 'unavailable' || delivery.canDispatch?.() === false)
243
278
  return;
244
279
  // AC-5 wants the bell, not a silent loss - and the reason is what makes the
245
280
  // pair "toast missing + bell rang" explainable afterwards. Ring first, then
246
- // report: the port rings for a completion the gate already approved, and a line
281
+ // report: the port rings for a notification the gate already approved, and a line
247
282
  // written ahead of the action is how the fallback came to log a bell that a
248
283
  // second look at the focus had eaten.
249
284
  const cause = result.detail === undefined ? result.reason : `${result.reason}: ${result.detail}`;
250
285
  delivery.terminal(title, message);
251
286
  logForDebugging(`windows toast unavailable (${cause}); using the terminal fallback`);
252
287
  }
288
+ /** Where the documented activation URI starts; the helper parses it (D6). */
289
+ const JUMP_BACK_LAUNCH_PREFIX = 'dsh-tui:activate?m=';
290
+ let sharedJumpBack;
291
+ /**
292
+ * The jump-back orchestration for this process: one instance, so the protocol
293
+ * key it registered and the marker files it wrote are exactly what `cleanup()`
294
+ * removes. A per-notification instance would lose that bookkeeping and
295
+ * leak both.
296
+ */
297
+ function jumpBackForProcess() {
298
+ sharedJumpBack ??= createJumpBack();
299
+ return sharedJumpBack;
300
+ }
301
+ /**
302
+ * The marker file's name for one notification (D8): the backend's session id when
303
+ * it is a safe file name, else a name for this process. A missing id is no
304
+ * reason to skip the documented file - the toast still names this pane.
305
+ * @returns A file name that cannot leave the marker directory.
306
+ */
307
+ function markerFileName(sessionId) {
308
+ return sessionId !== undefined && isMarkerFileSession(sessionId)
309
+ ? sessionId
310
+ : `process-${process.pid}`;
311
+ }
312
+ /**
313
+ * Refresh the documented marker file for this notification (D8).
314
+ *
315
+ * The file is written before the toast's ownership is known: an external
316
+ * notifier may deliver this notification, but an external plugin reading the
317
+ * documented seam still has to find this session's marker (AC-9). Only the
318
+ * probe that decides whether a click can be promised comes later.
319
+ * @param delivery - The ports for this notification; `jumpback` defaults to this
320
+ * process's orchestration.
321
+ * @returns The marker and its orchestration, or undefined when jump-back is
322
+ * off, off Windows, has no marker yet, or the port refuses to write.
323
+ */
324
+ function refreshJumpBackMarker(delivery) {
325
+ // The title writer tags a pane only on Windows; promising a jump anywhere
326
+ // else is a dead click. A disabled switch costs nothing and comes first.
327
+ const { enabled, marker, generation } = getJumpBackState();
328
+ if (!enabled || marker === null || (delivery.platform ?? process.platform) !== 'win32')
329
+ return undefined;
330
+ const jumpback = delivery.jumpback ?? jumpBackForProcess();
331
+ try {
332
+ // `writeMarker` answers undefined, not a throw, when the directory is not
333
+ // writable. A target without its documented file would still allow a probe
334
+ // and a registration, so a click would promise a jump other instances
335
+ // cannot see (and cannot use to judge this one alive).
336
+ if (jumpback.writeMarker(markerFileName(delivery.sessionId), marker) === undefined) {
337
+ logForDebugging('jumpback: the launch could not be prepared; sending the plain toast', {
338
+ step: 'marker',
339
+ detail: 'the marker file was not written',
340
+ });
341
+ return undefined;
342
+ }
343
+ return { marker, jumpback, generation };
344
+ }
345
+ catch (error) {
346
+ // The delivery path is fire-and-forget: a port that throws must cost the
347
+ // jump-back promise, never the notification itself (AC-3/AC-10). One
348
+ // message covers both preparation steps; `step` says which one failed.
349
+ logForDebugging('jumpback: the launch could not be prepared; sending the plain toast', {
350
+ step: 'marker',
351
+ detail: error instanceof Error ? error.message : String(error),
352
+ });
353
+ return undefined;
354
+ }
355
+ }
356
+ /**
357
+ * Whether the host still owns this notification. A throwing callback is a released
358
+ * owner, not a reason to break the delivery path: the promise is the only thing
359
+ * it may cost.
360
+ */
361
+ function ownerAllows(delivery) {
362
+ try {
363
+ return delivery.canDispatch?.() !== false;
364
+ }
365
+ catch (error) {
366
+ logForDebugging('jumpback: the owner check threw; treating the owner as released', {
367
+ detail: error instanceof Error ? error.message : String(error),
368
+ });
369
+ return false;
370
+ }
371
+ }
372
+ /**
373
+ * Ask whether this notification may carry a jump-back URI (D4/D7).
374
+ *
375
+ * The marker file was already refreshed by {@link refreshJumpBackMarker}; this
376
+ * step only spends the half second a probe costs. It must prove exactly one
377
+ * target (AC-3), and a refused protocol registration also answers no URI - a
378
+ * click whose handler is missing is a dead click (D7). Every skip leaves its
379
+ * stage and reason in the debug log.
380
+ * @param target - The marker and the orchestration that must prove it reachable.
381
+ * @returns The activation URI, or undefined for the plain toast.
382
+ */
383
+ async function jumpBackLaunch(target, delivery) {
384
+ // The setting can be turned off while this notification waits for its probe or
385
+ // for the registry. A stale preparation must not write the key back: the
386
+ // disable already ran its cleanup, and the click would outlive the switch.
387
+ const stillWanted = () => {
388
+ const state = getJumpBackState();
389
+ return state.enabled && state.generation === target.generation && ownerAllows(delivery);
390
+ };
391
+ if (!stillWanted())
392
+ return undefined;
393
+ try {
394
+ const probe = await target.jumpback.probe(target.marker);
395
+ if (!probe.capable || !stillWanted())
396
+ return undefined;
397
+ if (!await target.jumpback.ensureProtocol(probe.helperPath))
398
+ return undefined;
399
+ if (!stillWanted())
400
+ return undefined;
401
+ return `${JUMP_BACK_LAUNCH_PREFIX}${target.marker}`;
402
+ }
403
+ catch (error) {
404
+ // Same rule as the marker refresh: the jump-back promise is all a throwing
405
+ // port may cost (AC-3/AC-10).
406
+ logForDebugging('jumpback: the launch could not be prepared; sending the plain toast', {
407
+ step: 'probe',
408
+ detail: error instanceof Error ? error.message : String(error),
409
+ });
410
+ return undefined;
411
+ }
412
+ }
413
+ /**
414
+ * Publish the documented marker file as soon as the setting is turned on (D8).
415
+ *
416
+ * The notification path refreshes it per notification, but between the flip and
417
+ * the first notification an external reader already sees the switch on and would
418
+ * find no file for the current session (AC-9). Only a session whose id can name
419
+ * the documented `<session>.json` is published: the per-notification fallback
420
+ * (`process-<pid>.json`) exists for a toast that still needs a name, while here
421
+ * a reader looking the session up would find nothing either way.
422
+ *
423
+ * Best-effort by the same rule as the delivery path: the switch was already
424
+ * published, and a throwing port may cost the seam, never the settings edit.
425
+ * @param sessionId - The current session's id, when the host has one yet.
426
+ * @param platform - The host platform; only Windows tags panes (D2).
427
+ */
428
+ function refreshEnabledMarker(jumpback, sessionId, platform) {
429
+ const { enabled, marker } = getJumpBackState();
430
+ if (!enabled || platform !== 'win32' || marker === null)
431
+ return;
432
+ if (sessionId === undefined || !isMarkerFileSession(sessionId))
433
+ return;
434
+ try {
435
+ if (jumpback.writeMarker(sessionId, marker) === undefined) {
436
+ logForDebugging('jumpback: the enabled marker file was not written', { sessionId });
437
+ }
438
+ }
439
+ catch (error) {
440
+ logForDebugging('jumpback: the enabled marker file could not be refreshed', {
441
+ detail: error instanceof Error ? error.message : String(error),
442
+ });
443
+ }
444
+ }
445
+ /**
446
+ * Every cleanup a disable started, chained so a later enable orders its marker
447
+ * write after the delete that owns the same documented path. The chain is
448
+ * append-only on purpose: a stale enable that awaited an older link must never
449
+ * replace the tail and drop a newer cleanup (review 2026-11-01).
450
+ */
451
+ let cleanupChain = Promise.resolve();
452
+ /**
453
+ * Publish one jump-back settings resolution and act on the transition
454
+ * (D1/D4/D8). Enabling sweeps stale marker files once and refreshes the
455
+ * documented seam for the current session; disabling is a cleanup point of its
456
+ * own (AC-1/AC-9), not merely a title rewrite.
457
+ *
458
+ * `cleanup()` removes only what THIS process registered or wrote - another
459
+ * instance's protocol key survives - and is a no-op for a process that
460
+ * never did either, so a disabled boot path is unchanged. The sweep is
461
+ * win32-gated inside the orchestration, so no second platform judgment is made
462
+ * for it; the marker refresh needs the platform here because it happens before
463
+ * any port proves the host. Exported for the regression, which drives the same
464
+ * transition the settings watch calls.
465
+ * @param platform - The host platform; defaults to this process's, injectable
466
+ * for the regression, which runs on POSIX CI.
467
+ */
468
+ /**
469
+ * Compile the helper once the user enables jump-back, off the notification path:
470
+ * the first notification then pays the probe's half second, not the csc run.
471
+ */
472
+ function warmJumpBackHelper() {
473
+ void import('../ink/notify-helper/compile.js')
474
+ .then(module => module.ensureHelper())
475
+ .catch((error) => {
476
+ logForDebugging('jumpback: helper warm-up failed', {
477
+ detail: error instanceof Error ? error.message : String(error),
478
+ });
479
+ });
480
+ }
481
+ export async function applyJumpBackSetting(jumpback, enabled, sessionId, platform = process.platform) {
482
+ const wasEnabled = getJumpBackState().enabled;
483
+ setJumpBackEnabled(enabled);
484
+ if (enabled && !wasEnabled) {
485
+ // The generation this enable published: a later toggle changes it, and a
486
+ // stale enable must never publish a marker under the replacement's nose.
487
+ const generation = getJumpBackState().generation;
488
+ // Every cleanup that started before this enable owns the documented path
489
+ // for a while. The chain is append-only, so the tail captured here covers
490
+ // all of them; a stale enable must not reset it, or a newer cleanup goes
491
+ // untracked and deletes the marker this generation is about to write.
492
+ await cleanupChain;
493
+ if (getJumpBackState().generation !== generation || !getJumpBackState().enabled)
494
+ return;
495
+ jumpback.sweepStale();
496
+ refreshEnabledMarker(jumpback, sessionId, platform);
497
+ }
498
+ else if (!enabled && wasEnabled) {
499
+ // Append instead of starting a parallel delete: a quick re-enable then
500
+ // orders its marker write after every cleanup that started before it, and
501
+ // a stale enable that awaited an older link cannot drop this one. The
502
+ // settings watch does not wait for the transition itself.
503
+ cleanupChain = cleanupChain
504
+ .then(() => jumpback.cleanup())
505
+ .catch((error) => {
506
+ logForDebugging('jumpback: the cleanup after disabling failed', {
507
+ detail: error instanceof Error ? error.message : String(error),
508
+ });
509
+ });
510
+ }
511
+ }
253
512
  /**
254
513
  * The production toast port. The Windows module is imported on first use and
255
514
  * never at load time, so this path does not pull it in on a host that never
@@ -268,6 +527,223 @@ async function showWindowsToast(input) {
268
527
  return { status: 'unavailable', reason: 'unexpected', detail };
269
528
  }
270
529
  }
530
+ /** Cells a notification body may spend on the session name. */
531
+ const NOTIFICATION_SESSION_NAME_MAX_WIDTH = 20;
532
+ /**
533
+ * The session name as a notification shows it: a localized placeholder while
534
+ * the session is unnamed, and a grapheme-safe clip when a long name would crowd
535
+ * out the tool and reason after it. A Windows toast keeps 80 cells of the body,
536
+ * and the tool and reason are what tell the reader which prompt is waiting, so
537
+ * the name is the only part that gives way.
538
+ * @param sessionTitle - The attached session's title.
539
+ * @returns One plain line fitting the name's share of the body budget.
540
+ */
541
+ function notificationSessionName(sessionTitle) {
542
+ const name = notificationText(sessionTitle);
543
+ if (name === '')
544
+ return t('untitled-session');
545
+ return clipToWidthGraphemes(name, NOTIFICATION_SESSION_NAME_MAX_WIDTH);
546
+ }
547
+ /**
548
+ * The approval notification body: the session, the tool and the asker's
549
+ * reason, in that order, with empty parts dropped. A session that is not named
550
+ * yet contributes a localized placeholder name rather than vanishing from the
551
+ * body altogether.
552
+ *
553
+ * The reason is host-provided text: DSH's sandbox escalation passes the model's
554
+ * own `justification` through verbatim, so it can carry arbitrary prose. It is
555
+ * normalized to one plain line and capped like the completion preview, but the
556
+ * body makes no redaction promise - the panel keeps the full reason and the
557
+ * gated command, and the tool call's arguments are never read for the body.
558
+ *
559
+ * The session name is the only part that may be shortened: a Windows toast
560
+ * keeps 80 cells of the body, and the tool and reason are what tells the
561
+ * reader which prompt is waiting, so the name is clipped first.
562
+ *
563
+ * Exported like the completion seams above so the regression can assert the
564
+ * exact body without a toast or a live approval request.
565
+ * @param sessionTitle - The attached session's title; empty before it is
566
+ * named, which falls back to a localized placeholder.
567
+ * @param toolName - The tool the prompt gates.
568
+ * @param reason - The asker's reason as the host provides it, when it gave one.
569
+ */
570
+ export function approvalNotificationMessage(sessionTitle, toolName, reason) {
571
+ const reasonText = reason === undefined ? '' : notificationText(reason);
572
+ return [notificationSessionName(sessionTitle), notificationText(toolName), reasonText]
573
+ .filter(part => part !== '')
574
+ .join(':');
575
+ }
576
+ /**
577
+ * Build the notice for a parked non-DSH prompt, or undefined when the prompt
578
+ * belongs to a subagent: that prompt still parks for the panel and its
579
+ * session-list badge, but it is not this window's waiting prompt and must not
580
+ * raise a notification here.
581
+ * @param request - The parked backend prompt.
582
+ * @param session - The attached session's title and backend.
583
+ * @returns The notice to announce, or undefined when the prompt is not this window's.
584
+ */
585
+ export function backendApprovalNotice(request, session) {
586
+ if (request.agentId !== undefined)
587
+ return undefined;
588
+ return {
589
+ sessionTitle: session.title,
590
+ toolName: request.toolName,
591
+ ...(request.reason === undefined ? {} : { reason: request.reason }),
592
+ backendId: session.backendId,
593
+ };
594
+ }
595
+ /**
596
+ * Build the notice for a DSH approval request, or undefined when the request
597
+ * belongs to another agent - a background session or a subagent. Those still
598
+ * park for the panel and its needs-input badge, but only the attached session's
599
+ * ask belongs in this window's notification.
600
+ * @param request - The agent id, tool and resolved reason of the approval request.
601
+ * @param session - The attached agent id, session title and backend.
602
+ * @returns The notice to announce, or undefined for another agent's request.
603
+ */
604
+ export function dshApprovalNotice(request, session) {
605
+ if (request.agentId !== session.attachedAgentId)
606
+ return undefined;
607
+ return {
608
+ sessionTitle: session.title,
609
+ toolName: request.toolName,
610
+ ...(request.reason === undefined ? {} : { reason: request.reason }),
611
+ backendId: session.backendId,
612
+ };
613
+ }
614
+ /**
615
+ * Whether a notification queued before the Windows transport may still be
616
+ * dispatched: the window must still own the channel, the switch must not have
617
+ * been turned off, the notice must speak for the session that is attached now,
618
+ * and the interruption it announces must still be waiting. A check that throws
619
+ * counts as released: a state the seam cannot read must not produce a toast
620
+ * about a prompt that may already be gone.
621
+ * @param input - The live facts read at dispatch time.
622
+ * @returns True when the notification is still true enough to show.
623
+ */
624
+ export function notificationDispatchAllowed(input) {
625
+ if (!input.ownerCurrent || input.condition === 'off')
626
+ return false;
627
+ if (input.announcedSessionId !== undefined && input.announcedSessionId !== input.currentSessionId)
628
+ return false;
629
+ if (input.stillWaiting === undefined)
630
+ return true;
631
+ try {
632
+ return input.stillWaiting();
633
+ }
634
+ catch {
635
+ return false;
636
+ }
637
+ }
638
+ /**
639
+ * Build the entry point that announces one waiting interruption - an approval,
640
+ * a waiting question or a plan review. The body is already
641
+ * decided by the caller; this seam owns the shared focus/off gate, the platform
642
+ * split, the jump-back ports and the dispatch rechecks. The gate runs before
643
+ * the Windows transport so a suppressed notification never costs a PowerShell
644
+ * process, and a delivered toast never also rings the bell.
645
+ * @param facts - The live ports and settings the announcement reads.
646
+ * @returns The function that announces one interruption; `options.yieldToExternal`
647
+ * is handed to the delivery, `options.stillWaiting` to its dispatch recheck.
648
+ */
649
+ export function createInterruptionAnnouncer(facts) {
650
+ return (title, message, backendId, options) => {
651
+ if (!facts.alertsEnabled())
652
+ return;
653
+ const settings = facts.settings();
654
+ if (resolveNotificationMethod(settings.method, facts.platform) !== 'windows') {
655
+ facts.notifier.notify(title, message);
656
+ return;
657
+ }
658
+ const announcedSessionId = facts.sessionId();
659
+ void deliverTaskCompletionOnWindows(title, message, backendId, {
660
+ pluginManager: facts.pluginManager(),
661
+ yieldToExternal: options?.yieldToExternal,
662
+ canDispatch: () => notificationDispatchAllowed({
663
+ ownerCurrent: facts.ownerCurrent(),
664
+ condition: facts.settings().condition,
665
+ announcedSessionId,
666
+ currentSessionId: facts.sessionId(),
667
+ stillWaiting: options?.stillWaiting,
668
+ }),
669
+ toast: facts.toast,
670
+ terminal: (fallbackTitle, fallbackMessage) => ringTaskCompletion(facts.notifier, facts.settings(), fallbackTitle, fallbackMessage),
671
+ jumpback: facts.jumpback,
672
+ sessionId: announcedSessionId,
673
+ // One platform judgment for the method and the toast gate, so an injected
674
+ // regression sees the same host the delivery pretends to run on.
675
+ platform: facts.platform,
676
+ });
677
+ };
678
+ }
679
+ /**
680
+ * The waiting-question notification body: the first question's header and
681
+ * question, trimmed and joined, with empty parts dropped. The body only has to
682
+ * say that the session is waiting for an answer - options, detail and link
683
+ * stay in the panel, because a lock screen is the wrong place to choose one.
684
+ * Both parts are host- or model-authored, so they get the same normalization as
685
+ * every other notification body (ANSI/C0 stripped, whitespace collapsed,
686
+ * 200-grapheme cap); a long question therefore cannot push the panel-only
687
+ * context into the notification, and a control sequence cannot reach either
688
+ * transport. Formatting only: {@link questionNotice} decides whether the ask is
689
+ * announced, and under which title.
690
+ * @param questions - The ask's questions, in display order.
691
+ */
692
+ export function questionNotificationMessage(questions) {
693
+ const first = questions[0];
694
+ if (first === undefined)
695
+ return '';
696
+ return [notificationText(first.header ?? ''), notificationText(first.question)]
697
+ .filter(part => part !== '')
698
+ .join(':');
699
+ }
700
+ /**
701
+ * The waiting-question notice: whether the ask is announced at all, under which
702
+ * title, and whether an external notifier owns it - decided once here so no
703
+ * caller has to infer it back from the title. A plan review is announced under
704
+ * its own title because what is waiting is a decision on a plan, not an answer
705
+ * to a generic prompt; naming it up front says so before the body is read.
706
+ *
707
+ * The plan review also stays in-house: cc-dsh-notifier announces approvals and
708
+ * `ask_user_question` calls (it listens to `approval/asked` and `tool/call`),
709
+ * and a plan review is neither. Yielding would leave only its generic idle
710
+ * notice, which does not say that a plan review is waiting. An ordinary ask
711
+ * keeps the default and yields to an active external notifier.
712
+ *
713
+ * A batch with nothing to say yields no notice: a title with an empty body is
714
+ * pure noise away from the terminal.
715
+ * @param questions - The ask's questions, in display order.
716
+ */
717
+ export function questionNotice(questions) {
718
+ const message = questionNotificationMessage(questions);
719
+ if (message === '')
720
+ return undefined;
721
+ const planReview = questions.some(question => question.intent?.kind === 'plan-review');
722
+ return { titleKey: planReview ? 'plan-review-notification' : 'question-notification', message, yieldToExternal: !planReview };
723
+ }
724
+ /**
725
+ * The waiting-question notice for one ask, or undefined when the ask is not this
726
+ * window's. Two shapes name the asker: a backend bridge stamps the asking
727
+ * subagent in `agentId` (that ask still parks in the panel), while a DSH ask
728
+ * carries the protocol's `agent` object and, on the legacy `registerProvider`
729
+ * hosts, reaches this store for every in-process session. Only the attached
730
+ * session's asks become a system notification; an ask with no owner (a local
731
+ * wizard or `/auth`) has nothing to compare and is announced as before.
732
+ * Exported so the regression drives the production guard and title mapping
733
+ * instead of installing its own copy of them.
734
+ * @param request - The ask the store hands the observer, including the DSH
735
+ * protocol's structural `agent` when present.
736
+ * @param attachedAgentId - The session/agent this window is attached to now.
737
+ * @returns The notice to announce, or undefined when the ask stays in the panel.
738
+ */
739
+ export function waitingQuestionNotice(request, attachedAgentId) {
740
+ if (request.agentId !== undefined)
741
+ return undefined;
742
+ const asking = request.agent;
743
+ if (asking !== undefined && (attachedAgentId === undefined || String(asking.id) !== attachedAgentId))
744
+ return undefined;
745
+ return questionNotice(request.questions);
746
+ }
271
747
  export async function apply(ctx, runtimeConfig, configOwner = ctx, runtimeOptions = {}) {
272
748
  const config = configValues(runtimeConfig);
273
749
  const taskNotifier = createTerminalNotifier(process.stdout);
@@ -276,23 +752,19 @@ export async function apply(ctx, runtimeConfig, configOwner = ctx, runtimeOption
276
752
  method: config.notificationMethod ?? 'auto',
277
753
  });
278
754
  configureTaskNotifications(config.taskNotifications, config.notificationMethod);
279
- /**
280
- * Whether a task completion is announced at all: the one gate, asked before
281
- * the Windows transport so a suppressed notification never costs a PowerShell
282
- * process, and so a delivered toast never also rings the bell. The Windows
283
- * fallback re-enters through `ringTaskCompletion`, which carries this answer
284
- * instead of asking the focus question again after the awaits. Explicit off or
285
- * owner release revokes pending dispatch; an already started host is not recalled.
286
- */
287
- const taskCompletionAlertsEnabled = () => process.stdout.isTTY === true
288
- && notificationSettings.condition !== 'off'
289
- && !(notificationSettings.condition === 'unfocused' && getTerminalFocused());
755
+ // Jump-back (D4/D7/D8): one orchestration per process, cleaned up on
756
+ // this fiber's teardown. Creating it touches nothing - the registry and the
757
+ // marker directory are only reached after the user turns the setting on and a
758
+ // notification is delivered (AC-1). `cleanup()` is a no-op for a process that
759
+ // never registered or wrote, so an off launch exits exactly as before.
760
+ const jumpBack = jumpBackForProcess();
761
+ ctx.effect(() => () => jumpBack.cleanup());
290
762
  /**
291
763
  * Announce a finished task: the channel's `onTaskComplete` payload and gate,
292
764
  * with the Windows method resolved first (`auto` picks the toast there, D2).
293
765
  */
294
766
  const announceTaskCompletion = (preview, backendId) => {
295
- if (!taskCompletionAlertsEnabled())
767
+ if (!notificationAlertsEnabled(notificationSettings, process.stdout.isTTY === true, getTerminalFocused()))
296
768
  return;
297
769
  const title = t('task-complete-notification');
298
770
  const message = preview ?? '';
@@ -305,8 +777,43 @@ export async function apply(ctx, runtimeConfig, configOwner = ctx, runtimeOption
305
777
  canDispatch: () => channelOwnerCurrent(rawChannel) && notificationSettings.condition !== 'off',
306
778
  toast: showWindowsToast,
307
779
  terminal: (fallbackTitle, fallbackMessage) => ringTaskCompletion(taskNotifier, notificationSettings, fallbackTitle, fallbackMessage),
780
+ jumpback: jumpBack,
781
+ // Read at announce time: the marker file names the session that just
782
+ // completed, not whichever session this process mounted at boot (D8).
783
+ sessionId: rawChannel.sessionRef.sessionId,
308
784
  });
309
785
  };
786
+ /**
787
+ * The shared interruption seam: focus/off gate, platform split, jump-back
788
+ * ports and dispatch rechecks for a waiting approval, question or plan
789
+ * review. A queued notice is dropped at
790
+ * dispatch time when the switch turned off, the session is no longer the
791
+ * attached one, or the interruption was answered in the meantime.
792
+ */
793
+ const announceInterruption = createInterruptionAnnouncer({
794
+ notifier: taskNotifier,
795
+ settings: () => notificationSettings,
796
+ alertsEnabled: () => notificationAlertsEnabled(notificationSettings, process.stdout.isTTY === true, getTerminalFocused()),
797
+ platform: process.platform,
798
+ sessionId: () => rawChannel.sessionRef.sessionId,
799
+ ownerCurrent: () => channelOwnerCurrent(rawChannel),
800
+ pluginManager: () => pluginManagerOf(ctx),
801
+ toast: showWindowsToast,
802
+ jumpback: jumpBack,
803
+ });
804
+ /**
805
+ * Announce a pending approval: the shared interruption seam with the
806
+ * session/tool/reason body (`approvalNotificationMessage`). Called once per
807
+ * parked request - a queued prompt still needs its decision, so nothing is
808
+ * deduplicated.
809
+ * @param notice - The attached session's title, the gated tool, the asker's
810
+ * reason and the backend that owns the session.
811
+ * @param stillWaiting - Whether that approval is still parked, read again
812
+ * before the native transport dispatches.
813
+ */
814
+ const announceApproval = (notice, stillWaiting) => {
815
+ announceInterruption(t('approval-notification'), approvalNotificationMessage(notice.sessionTitle, notice.toolName, notice.reason), notice.backendId, { stillWaiting });
816
+ };
310
817
  // /restart handoff diagnosis: the replacement process is marked by env and
311
818
  // logs its boot progress to ~/.dsh-tui/restart.log (ordinary launches stay
312
819
  // silent). First line lands before anything in this function can throw.
@@ -498,6 +1005,32 @@ export async function apply(ctx, runtimeConfig, configOwner = ctx, runtimeOption
498
1005
  // adapter binds either registration to this Cordis fiber; this separate
499
1006
  // effect rejects asks still parked in the UI during teardown.
500
1007
  ctx.effect(() => () => questionStore.rejectAll());
1008
+ // A waiting question is an interruption like a parked approval: announce it
1009
+ // through the same notifier so a user who stepped away sees that the
1010
+ // session needs an answer. The store calls this once per ask batch (a queued
1011
+ // one included) and already swallows callback throws; the catch here only
1012
+ // keeps a composition mistake visible in the debug log.
1013
+ questionStore.setOnAsk(request => {
1014
+ // The guard and the title mapping are one production decision: the notice
1015
+ // drops a subagent's ask and another in-process session's ask (the legacy
1016
+ // provider path receives every agent's question), while plan reviews stay
1017
+ // for the later change.
1018
+ const notice = waitingQuestionNotice(request, channel.agentId);
1019
+ if (notice === undefined)
1020
+ return;
1021
+ try {
1022
+ // Pure passthrough: the notice decides the plan-review opt-out, so this
1023
+ // callback must not infer it back from the title.
1024
+ announceInterruption(t(notice.titleKey), notice.message, rawChannel.sessionRef.backendId, {
1025
+ yieldToExternal: notice.yieldToExternal,
1026
+ stillWaiting: () => questionStore.hasPendingRequest(request),
1027
+ });
1028
+ }
1029
+ catch (error) {
1030
+ const detail = error instanceof Error ? error.message : String(error);
1031
+ logForDebugging(`question notification failed (${detail})`);
1032
+ }
1033
+ });
501
1034
  // DSH user-interaction seam: the model's ask_user_question tool parks on
502
1035
  // the userQuestions service until a UI answerer responds. Mount the
503
1036
  // service when the composition doesn't (the official dsh-base
@@ -902,8 +1435,23 @@ export async function apply(ctx, runtimeConfig, configOwner = ctx, runtimeOption
902
1435
  // approval panel renders; its questions share the DSH questionnaire store.
903
1436
  // Teardown withdraws whatever is still parked.
904
1437
  const backendPermissions = backendStart === undefined ? undefined : new PermissionStore();
905
- if (backendPermissions !== undefined)
1438
+ if (backendPermissions !== undefined) {
1439
+ // A non-DSH session's prompts park in this channel-owned store: there is no
1440
+ // background session to filter out, and the session name is read from the
1441
+ // channel, not the view (`PermissionRequestView` carries no session id).
1442
+ // A subagent's prompt parks for the panel and its session-list badge, but
1443
+ // only the attached session's asks belong in a system notification.
1444
+ backendPermissions.setOnPark(request => {
1445
+ const notice = backendApprovalNotice(request, {
1446
+ title: rawChannel.sessionTitle,
1447
+ backendId: rawChannel.sessionRef.backendId,
1448
+ });
1449
+ if (notice === undefined)
1450
+ return;
1451
+ announceApproval(notice, () => backendPermissions.pending().some(view => view.requestId === request.requestId));
1452
+ });
906
1453
  ctx.effect(() => () => backendPermissions.settleAll());
1454
+ }
907
1455
  const resolved = backendStart !== undefined || dshInEntry
908
1456
  ? { agent: undefined, handle: undefined, agentPreset: undefined, route: undefined }
909
1457
  : await resolveAgent(ctx, bootSessionId, configuredRoute, startupRoute, deploymentRoute, meta, config.preset);
@@ -1279,6 +1827,10 @@ export async function apply(ctx, runtimeConfig, configOwner = ctx, runtimeOption
1279
1827
  // Must mirror Config's union (`src/dsh-adapter/index.ts`): a method
1280
1828
  // missing here is rejected by /settings and never reaches the runtime.
1281
1829
  notificationMethod: Schema.union(['auto', 'osc9', 'bel', 'windows']),
1830
+ // Must mirror Config's `jumpBack` (D1). No default on purpose
1831
+ // (D1a): applyDisplay resolves `?? config.jumpBack ?? false`, so an
1832
+ // explicit cordis.yml value stays decisive while the user layer is unset.
1833
+ jumpBack: Schema.boolean(),
1282
1834
  // Same no-default rule: applyDisplay resolves `?? config.mermaidDiagrams ?? true`.
1283
1835
  mermaidDiagrams: Schema.boolean(),
1284
1836
  // Code-frame shape; unset keeps the light rail frame.
@@ -1469,6 +2021,11 @@ export async function apply(ctx, runtimeConfig, configOwner = ctx, runtimeOption
1469
2021
  channel.setExpandEditor(value.expandEditor ?? config.expandEditor ?? true);
1470
2022
  channel.setSmoothStreaming(value.smoothStreaming ?? config.smoothStreaming ?? true);
1471
2023
  configureTaskNotifications(value.taskNotifications ?? config.taskNotifications, value.notificationMethod ?? config.notificationMethod);
2024
+ void applyJumpBackSetting(jumpBack, value.jumpBack ?? config.jumpBack ?? false, rawChannel.sessionRef.sessionId)
2025
+ .then(() => {
2026
+ if (process.platform === 'win32' && getJumpBackState().enabled)
2027
+ warmJumpBackHelper();
2028
+ });
1472
2029
  applyMermaidDiagrams(value.mermaidDiagrams ?? config.mermaidDiagrams);
1473
2030
  applyCodeFrameStyle(value.codeFrameStyle ?? config.codeFrameStyle);
1474
2031
  applyMathRendering(resolveMathRendering(value, config));
@@ -1780,6 +2337,13 @@ export async function apply(ctx, runtimeConfig, configOwner = ctx, runtimeOption
1780
2337
  ...settingField('notificationMethod'),
1781
2338
  format: value => String(value ?? config.notificationMethod ?? 'auto'),
1782
2339
  },
2340
+ {
2341
+ ...settingField('jumpBack'),
2342
+ format(value) {
2343
+ // Unset in settings.yaml: the effective default is off (D1a).
2344
+ return String(typeof value === 'boolean' ? value : config.jumpBack === true);
2345
+ },
2346
+ },
1783
2347
  {
1784
2348
  ...settingField('codeFrameStyle'),
1785
2349
  },
@@ -2047,7 +2611,25 @@ export async function apply(ctx, runtimeConfig, configOwner = ctx, runtimeOption
2047
2611
  // The in-process DSH kernel installs it in `attachDsh`.
2048
2612
  const mountDshApprovals = (dshCtx) => {
2049
2613
  if (dshCtx.get('approval') !== undefined && backendStart === undefined) {
2050
- dshCtx.on('approval/request', (req, next) => approvalStore.park(req).catch(() => next()));
2614
+ dshCtx.on('approval/request', (req, next) => {
2615
+ // Park first: the ask must reach the panel even if announcing it fails.
2616
+ const parked = approvalStore.park(req).catch(() => next());
2617
+ // Only the attached session's ask belongs to this window: a background
2618
+ // session or a subagent carries its own agent id, so it still parks for
2619
+ // the panel and its needs-input badge but must not raise a toast here.
2620
+ const agentId = String(req.agent.id);
2621
+ const notice = dshApprovalNotice({ agentId, toolName: req.toolName, reason: reasonOf(req) }, { attachedAgentId: channel.agentId, title: rawChannel.sessionTitle, backendId: rawChannel.sessionRef.backendId });
2622
+ if (notice !== undefined) {
2623
+ try {
2624
+ announceApproval(notice, () => approvalStore.hasParkedRequest(req));
2625
+ }
2626
+ catch (error) {
2627
+ const detail = error instanceof Error ? error.message : String(error);
2628
+ logForDebugging(`approval notification failed (${detail})`);
2629
+ }
2630
+ }
2631
+ return parked;
2632
+ });
2051
2633
  // Badge-flip push (P-4): React does not know the session log appended —
2052
2634
  // a source-badge verdict that only flips inside getSnapshot() surfaces
2053
2635
  // solely when something else re-renders. Feed the session firehose to
@@ -2532,6 +3114,8 @@ export async function apply(ctx, runtimeConfig, configOwner = ctx, runtimeOption
2532
3114
  // no longer runs a second activity tracker of its own.
2533
3115
  activityStore,
2534
3116
  extensionShortcuts: getHostShortcuts(ctx.get('tuiShortcuts')),
3117
+ // Plugin `@` completion rows (same row); absent ⇒ files only.
3118
+ extensionMentions: getHostMentions(ctx.get('tuiMentions')),
2535
3119
  themeHost: liveThemeHost(),
2536
3120
  // Full-screen surfaces inside Chat — the trajectory scene and the session
2537
3121
  // browser — enter the alt screen themselves in inline mode; in fullscreen
@@ -2579,10 +3163,14 @@ export async function apply(ctx, runtimeConfig, configOwner = ctx, runtimeOption
2579
3163
  onPluginManage: createPluginManageEntry(ctx, {
2580
3164
  profileName: profile ?? resolveDshProfileName(),
2581
3165
  }),
2582
- // `/team [status]`: the live team report (team-mode.ts). The bundle switch
2583
- // is `/plugin enable|disable`, which shares the lifecycle flow.
3166
+ // `/team [status|on|off]`: the live team report and, on hosts with a
3167
+ // per-session selection, its switch (team-mode.ts). A bundle host keeps
3168
+ // `/plugin enable|disable`, which shares the lifecycle flow.
2584
3169
  onTeamCommand: createTeamCommandEntry(ctx, {
2585
3170
  profileName: profile ?? resolveDshProfileName(),
3171
+ // The bound session's live Agent; team-mode walks to the tree root whose
3172
+ // saved selection owns the switch (a descendant is rejected upstream).
3173
+ rootAgent: () => liveDshAgent(),
2586
3174
  }),
2587
3175
  kernelPinned: backendPinned,
2588
3176
  // Only a `dsh --profile <name>` launch has a profile installation for