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

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