@deepseek-harness-tui/dsh-tui 0.17.0 → 0.18.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 (186) hide show
  1. package/README.md +10 -8
  2. package/cli/adapters/dsh/index.mjs +2 -2
  3. package/guide/dsh-tui-guide/cli.en.md +1 -1
  4. package/guide/dsh-tui-guide/cli.md +1 -1
  5. package/guide/dsh-tui-guide/configuration.en.md +3 -2
  6. package/guide/dsh-tui-guide/configuration.md +3 -2
  7. package/guide/dsh-tui-guide/getting-started.en.md +6 -2
  8. package/guide/dsh-tui-guide/getting-started.md +4 -1
  9. package/guide/dsh-tui-guide/interaction.en.md +28 -7
  10. package/guide/dsh-tui-guide/interaction.md +17 -5
  11. package/guide/dsh-tui-guide/plugins.en.md +28 -7
  12. package/guide/dsh-tui-guide/plugins.md +18 -5
  13. package/guide/dsh-tui-guide/user-guide.en.md +29 -15
  14. package/guide/dsh-tui-guide/user-guide.md +20 -10
  15. package/lib/settings.json +3 -3
  16. package/lib/types/adapter/channel/ui-policy.d.ts +1 -0
  17. package/lib/types/adapter/channel/ui-policy.d.ts.map +1 -1
  18. package/lib/types/adapter/channel/ui-policy.js +1 -0
  19. package/lib/types/adapter/ports/channel-ui.d.ts +5 -0
  20. package/lib/types/adapter/ports/channel-ui.d.ts.map +1 -1
  21. package/lib/types/adapter/ports/channel-view.d.ts +3 -0
  22. package/lib/types/adapter/ports/channel-view.d.ts.map +1 -1
  23. package/lib/types/adapter/standard/grants.d.ts +60 -0
  24. package/lib/types/adapter/standard/grants.d.ts.map +1 -1
  25. package/lib/types/adapter/standard/grants.js +74 -0
  26. package/lib/types/agent/events.d.ts +7 -1
  27. package/lib/types/agent/events.d.ts.map +1 -1
  28. package/lib/types/commands.js +1 -1
  29. package/lib/types/components/GoalTodoPanel.d.ts +71 -6
  30. package/lib/types/components/GoalTodoPanel.d.ts.map +1 -1
  31. package/lib/types/components/GoalTodoPanel.js +165 -17
  32. package/lib/types/components/MessageList.d.ts.map +1 -1
  33. package/lib/types/components/MessageList.js +3 -2
  34. package/lib/types/components/PluginGrantList.d.ts +45 -0
  35. package/lib/types/components/PluginGrantList.d.ts.map +1 -0
  36. package/lib/types/components/PluginGrantList.js +126 -0
  37. package/lib/types/components/PluginInstallPane.d.ts.map +1 -1
  38. package/lib/types/components/PluginInstallPane.js +35 -6
  39. package/lib/types/components/PluginManagePane.d.ts.map +1 -1
  40. package/lib/types/components/PluginManagePane.js +65 -8
  41. package/lib/types/components/PromptInput.js +2 -2
  42. package/lib/types/components/SubagentDashboard.d.ts.map +1 -1
  43. package/lib/types/components/SubagentDashboard.js +10 -0
  44. package/lib/types/components/SubagentDetailScene.d.ts.map +1 -1
  45. package/lib/types/components/SubagentDetailScene.js +12 -0
  46. package/lib/types/components/messages/AssistantToolUseMessage.d.ts +2 -1
  47. package/lib/types/components/messages/AssistantToolUseMessage.d.ts.map +1 -1
  48. package/lib/types/components/messages/AssistantToolUseMessage.js +11 -5
  49. package/lib/types/components/onboardingModel.d.ts +2 -2
  50. package/lib/types/components/onboardingModel.js +3 -3
  51. package/lib/types/components/onboardingProviderPlan.d.ts +110 -0
  52. package/lib/types/components/onboardingProviderPlan.d.ts.map +1 -0
  53. package/lib/types/components/onboardingProviderPlan.js +78 -0
  54. package/lib/types/components/sidePanel/btw/BtwComposer.d.ts +7 -0
  55. package/lib/types/components/sidePanel/btw/BtwComposer.d.ts.map +1 -1
  56. package/lib/types/components/sidePanel/btw/BtwComposer.js +16 -0
  57. package/lib/types/components/sidePanel/btw/BtwPanelAdapter.d.ts.map +1 -1
  58. package/lib/types/components/sidePanel/btw/BtwPanelAdapter.js +8 -1
  59. package/lib/types/components/sidePanel/btw/BtwThreadScene.d.ts +7 -1
  60. package/lib/types/components/sidePanel/btw/BtwThreadScene.d.ts.map +1 -1
  61. package/lib/types/components/sidePanel/btw/BtwThreadScene.js +8 -1
  62. package/lib/types/components/sidePanel/btw/useBtwComposerPaste.d.ts +30 -0
  63. package/lib/types/components/sidePanel/btw/useBtwComposerPaste.d.ts.map +1 -0
  64. package/lib/types/components/sidePanel/btw/useBtwComposerPaste.js +94 -0
  65. package/lib/types/components/sidePanel/builtinPanels.d.ts.map +1 -1
  66. package/lib/types/components/sidePanel/builtinPanels.js +14 -2
  67. package/lib/types/components/sidePanel/types.d.ts +2 -0
  68. package/lib/types/components/sidePanel/types.d.ts.map +1 -1
  69. package/lib/types/components/sidePanel/useSidePanel.d.ts.map +1 -1
  70. package/lib/types/components/sidePanel/useSidePanel.js +15 -1
  71. package/lib/types/dsh-adapter/backend/session.d.ts +7 -1
  72. package/lib/types/dsh-adapter/backend/session.d.ts.map +1 -1
  73. package/lib/types/dsh-adapter/backend/session.js +62 -6
  74. package/lib/types/dsh-adapter/backend/translate.d.ts.map +1 -1
  75. package/lib/types/dsh-adapter/backend/translate.js +9 -5
  76. package/lib/types/dsh-adapter/channel/agent-view-projection.d.ts +1 -1
  77. package/lib/types/dsh-adapter/channel/agent-view-projection.d.ts.map +1 -1
  78. package/lib/types/dsh-adapter/channel/agent-view-projection.js +3 -1
  79. package/lib/types/dsh-adapter/channel/composer-images.d.ts +2 -0
  80. package/lib/types/dsh-adapter/channel/composer-images.d.ts.map +1 -1
  81. package/lib/types/dsh-adapter/channel/composer-images.js +10 -2
  82. package/lib/types/dsh-adapter/channel/composer-mentions.d.ts.map +1 -1
  83. package/lib/types/dsh-adapter/channel/composer-mentions.js +22 -7
  84. package/lib/types/dsh-adapter/channel/context-bookkeeping.d.ts +1 -1
  85. package/lib/types/dsh-adapter/channel/context-bookkeeping.d.ts.map +1 -1
  86. package/lib/types/dsh-adapter/channel/context-bookkeeping.js +9 -5
  87. package/lib/types/dsh-adapter/channel/core/binding-feed.d.ts +6 -0
  88. package/lib/types/dsh-adapter/channel/core/binding-feed.d.ts.map +1 -1
  89. package/lib/types/dsh-adapter/channel/core/binding-feed.js +35 -1
  90. package/lib/types/dsh-adapter/channel/core/compose.d.ts +1 -1
  91. package/lib/types/dsh-adapter/channel/core/compose.d.ts.map +1 -1
  92. package/lib/types/dsh-adapter/channel/core/compose.js +5 -0
  93. package/lib/types/dsh-adapter/channel/input-actions.d.ts +2 -2
  94. package/lib/types/dsh-adapter/channel/input-actions.d.ts.map +1 -1
  95. package/lib/types/dsh-adapter/channel/input-actions.js +30 -0
  96. package/lib/types/dsh-adapter/channel/input-delivery.d.ts +1 -1
  97. package/lib/types/dsh-adapter/channel/input-delivery.d.ts.map +1 -1
  98. package/lib/types/dsh-adapter/channel/input-delivery.js +8 -4
  99. package/lib/types/dsh-adapter/channel/mentions.d.ts.map +1 -1
  100. package/lib/types/dsh-adapter/channel/mentions.js +21 -7
  101. package/lib/types/dsh-adapter/channel/paths.d.ts.map +1 -1
  102. package/lib/types/dsh-adapter/channel/paths.js +11 -9
  103. package/lib/types/dsh-adapter/channel/session-live-adoption.d.ts +1 -1
  104. package/lib/types/dsh-adapter/channel/session-live-adoption.d.ts.map +1 -1
  105. package/lib/types/dsh-adapter/channel/session-live-adoption.js +6 -1
  106. package/lib/types/dsh-adapter/channel/session-reset.d.ts.map +1 -1
  107. package/lib/types/dsh-adapter/channel/session-reset.js +3 -1
  108. package/lib/types/dsh-adapter/channel/session-resume.d.ts +1 -1
  109. package/lib/types/dsh-adapter/channel/session-resume.d.ts.map +1 -1
  110. package/lib/types/dsh-adapter/channel/session-resume.js +10 -3
  111. package/lib/types/dsh-adapter/channel/session-rewind.d.ts +1 -1
  112. package/lib/types/dsh-adapter/channel/session-rewind.d.ts.map +1 -1
  113. package/lib/types/dsh-adapter/channel/session-rewind.js +3 -1
  114. package/lib/types/dsh-adapter/channel/session-tree-actions.d.ts +1 -1
  115. package/lib/types/dsh-adapter/channel/session-tree-actions.d.ts.map +1 -1
  116. package/lib/types/dsh-adapter/channel/session-tree-actions.js +3 -1
  117. package/lib/types/dsh-adapter/contract.d.ts +4 -3
  118. package/lib/types/dsh-adapter/contract.d.ts.map +1 -1
  119. package/lib/types/dsh-adapter/contract.js +6 -3
  120. package/lib/types/dsh-adapter/entry-slot.d.ts +6 -0
  121. package/lib/types/dsh-adapter/entry-slot.d.ts.map +1 -1
  122. package/lib/types/dsh-adapter/experimental-bundles.d.ts +3 -0
  123. package/lib/types/dsh-adapter/experimental-bundles.d.ts.map +1 -1
  124. package/lib/types/dsh-adapter/experimental-bundles.js +4 -0
  125. package/lib/types/dsh-adapter/grant-file.d.ts +70 -0
  126. package/lib/types/dsh-adapter/grant-file.d.ts.map +1 -0
  127. package/lib/types/dsh-adapter/grant-file.js +178 -0
  128. package/lib/types/dsh-adapter/host-access.d.ts +4 -0
  129. package/lib/types/dsh-adapter/host-access.d.ts.map +1 -1
  130. package/lib/types/dsh-adapter/host-access.js +54 -4
  131. package/lib/types/dsh-adapter/host-contract.d.ts +1 -1
  132. package/lib/types/dsh-adapter/host-contract.js +2 -2
  133. package/lib/types/dsh-adapter/host-dsh.js +3 -3
  134. package/lib/types/dsh-adapter/index.d.ts.map +1 -1
  135. package/lib/types/dsh-adapter/index.js +8 -5
  136. package/lib/types/dsh-adapter/panels.d.ts +7 -1
  137. package/lib/types/dsh-adapter/panels.d.ts.map +1 -1
  138. package/lib/types/dsh-adapter/plugin-declaration.d.ts +28 -0
  139. package/lib/types/dsh-adapter/plugin-declaration.d.ts.map +1 -1
  140. package/lib/types/dsh-adapter/plugin-declaration.js +43 -1
  141. package/lib/types/dsh-adapter/plugin-install.d.ts +28 -1
  142. package/lib/types/dsh-adapter/plugin-install.d.ts.map +1 -1
  143. package/lib/types/dsh-adapter/plugin-install.js +160 -13
  144. package/lib/types/dsh-adapter/plugin-manage.d.ts +53 -10
  145. package/lib/types/dsh-adapter/plugin-manage.d.ts.map +1 -1
  146. package/lib/types/dsh-adapter/plugin-manage.js +240 -51
  147. package/lib/types/dsh-adapter/plugin.d.ts.map +1 -1
  148. package/lib/types/dsh-adapter/plugin.js +64 -18
  149. package/lib/types/dsh-adapter/plugins-info.d.ts +6 -7
  150. package/lib/types/dsh-adapter/plugins-info.d.ts.map +1 -1
  151. package/lib/types/dsh-adapter/plugins-info.js +34 -21
  152. package/lib/types/dsh-adapter/presets.d.ts +6 -2
  153. package/lib/types/dsh-adapter/presets.d.ts.map +1 -1
  154. package/lib/types/dsh-adapter/presets.js +23 -5
  155. package/lib/types/dsh-adapter/process-exit.d.ts +1 -1
  156. package/lib/types/dsh-adapter/process-exit.js +1 -1
  157. package/lib/types/dsh-adapter/providerWizard.d.ts +2 -0
  158. package/lib/types/dsh-adapter/providerWizard.d.ts.map +1 -1
  159. package/lib/types/dsh-adapter/providerWizard.js +11 -5
  160. package/lib/types/dsh-adapter/row-attachment.d.ts +30 -0
  161. package/lib/types/dsh-adapter/row-attachment.d.ts.map +1 -0
  162. package/lib/types/dsh-adapter/row-attachment.js +29 -0
  163. package/lib/types/dsh-adapter/worktree-tool.d.ts +27 -0
  164. package/lib/types/dsh-adapter/worktree-tool.d.ts.map +1 -0
  165. package/lib/types/dsh-adapter/worktree-tool.js +87 -0
  166. package/lib/types/heldInputs.d.ts +36 -0
  167. package/lib/types/heldInputs.d.ts.map +1 -0
  168. package/lib/types/heldInputs.js +173 -0
  169. package/lib/types/i18n.d.ts +352 -25
  170. package/lib/types/i18n.d.ts.map +1 -1
  171. package/lib/types/i18n.js +171 -18
  172. package/lib/types/onboardingDraft.d.ts +143 -0
  173. package/lib/types/onboardingDraft.d.ts.map +1 -0
  174. package/lib/types/onboardingDraft.js +71 -0
  175. package/lib/types/screens/Chat.d.ts.map +1 -1
  176. package/lib/types/screens/Chat.js +90 -30
  177. package/lib/types/screens/Onboarding.d.ts +22 -3
  178. package/lib/types/screens/Onboarding.d.ts.map +1 -1
  179. package/lib/types/screens/Onboarding.js +606 -36
  180. package/lib/types/settings/definitions.js +2 -2
  181. package/lib/types/utils/paths.d.ts +15 -0
  182. package/lib/types/utils/paths.d.ts.map +1 -1
  183. package/lib/types/utils/paths.js +25 -0
  184. package/package.json +111 -108
  185. package/tui-profile/feed/README.md +1 -1
  186. package/tui-profile/feed/first-party.json +1 -1
@@ -34,14 +34,20 @@
34
34
  * either way, so closing the pane does not stop it.
35
35
  */
36
36
  import { existsSync } from 'node:fs';
37
+ import { join } from 'node:path';
38
+ import { readGrantStore } from '../adapter/standard/grants.js';
39
+ import { adapterRuntimeFor } from '../adapter/kernel/runtime-context.js';
37
40
  import { t } from '../i18n.js';
38
41
  import { resolveDshProfileName } from '../update.js';
39
42
  import { backendDataDir, DATA_DIR } from '../utils/paths.js';
40
- import { COMPOSITION_PACKAGE, declaredBackendsOf, pluginDeclarationOf } from './plugin-declaration.js';
43
+ import { applyGrantMutation, grantFailureText, grantsFilePath, planGrants } from './grant-file.js';
44
+ import { COMPOSITION_PACKAGE, declaredBackendsOf, declaredGrantsOf, pluginDeclarationOf } from './plugin-declaration.js';
45
+ import { getHostGrantStore } from './host-grants.js';
41
46
  import { failureReasonOf } from './plugin-install.js';
42
47
  import { HOST_BUNDLE, pluginGuardVerdict, } from './plugin-guard.js';
43
48
  import { pluginManagerOf } from './plugin-manager.js';
44
- import { cell, parsePluginArgs, pluginFootprintContains } from './plugins-info.js';
49
+ import { cell, parsePluginArgs, pluginFootprintPaths, pluginFootprintSourcesOf } from './plugins-info.js';
50
+ import { storageFileName } from './plugin-storage.js';
45
51
  import { TEAM_BUNDLE } from './team-roster.js';
46
52
  const NO_TEAM_MEMBERS = { active: 0, unseen: 0 };
47
53
  /**
@@ -144,6 +150,10 @@ export function createPluginManageFlow(options) {
144
150
  let target;
145
151
  /** What the report calls it: its own name, never the argument text. */
146
152
  let label = '';
153
+ /** The bundle's declaration, captured while the package is still installed. */
154
+ let declaration;
155
+ /** The plan for that declaration's permissions; `undefined` when unreadable. */
156
+ let grantPlan;
147
157
  /** Whether the session that asked is still bound; false drops every write. */
148
158
  const live = () => options.binding() === bindingAtStart;
149
159
  const emit = (lines) => {
@@ -187,6 +197,13 @@ export function createPluginManageFlow(options) {
187
197
  if (bundle !== undefined) {
188
198
  target = bundleTarget(options.action, bundle);
189
199
  label = cell(bundle.name);
200
+ // Read once, before the write, for every bundle action: a removal can no
201
+ // longer read the declaration afterwards, and enable/disable need the
202
+ // same id and permissions.
203
+ declaration = captureDeclaration(bundle.name);
204
+ grantPlan = declaration?.kind === 'declared' && declaration.grants !== undefined && options.grants !== undefined
205
+ ? planGrants(options.grants, declaration.grants)
206
+ : undefined;
190
207
  return await guardThenDecide(bundleGuardTarget(bundle), () => ask(hostRowIdsOf(bundles)));
191
208
  }
192
209
  let plugin = plugins.find(candidate => candidate.entryId === wanted)
@@ -242,16 +259,120 @@ export function createPluginManageFlow(options) {
242
259
  const resolved = target;
243
260
  if (resolved === undefined)
244
261
  return { kind: 'done' };
262
+ const grants = resolved.kind === 'bundle' ? grantPlan : undefined;
245
263
  if (options.action === 'remove')
246
- return { kind: 'confirm', target: resolved, question: { kind: 'remove' } };
264
+ return { kind: 'confirm', target: resolved, question: { kind: 'remove' }, grants };
247
265
  if (options.action === 'disable') {
248
266
  const hostRow = resolved.kind === 'row' && resolved.patchId !== undefined && hostRowIds.has(resolved.patchId);
249
267
  if (hostRow)
250
- return { kind: 'confirm', target: resolved, question: { kind: 'host-row' } };
268
+ return { kind: 'confirm', target: resolved, question: { kind: 'host-row' }, grants };
251
269
  const { active, unseen } = resolved.kind === 'bundle' && resolved.name === TEAM_BUNDLE ? options.teamActiveMembers?.() ?? NO_TEAM_MEMBERS : NO_TEAM_MEMBERS;
252
- return active + unseen > 0 ? { kind: 'confirm', target: resolved, question: { kind: 'team-active', members: active, unseen } } : run();
270
+ return active + unseen > 0 ? { kind: 'confirm', target: resolved, question: { kind: 'team-active', members: active, unseen }, grants } : run();
253
271
  }
254
- return { kind: 'confirm', target: resolved, question: { kind: 'trust' } };
272
+ return { kind: 'confirm', target: resolved, question: { kind: 'trust' }, grants };
273
+ }
274
+ /**
275
+ * Read one bundle's declaration before the write. A resolver that throws is
276
+ * treated exactly like an unreadable declaration: the action goes on, and
277
+ * this flow reports that it cannot name the component rather than guessing
278
+ * an id.
279
+ */
280
+ function captureDeclaration(name) {
281
+ try {
282
+ return options.declarationOf?.(name);
283
+ }
284
+ catch {
285
+ return { kind: 'unreadable' };
286
+ }
287
+ }
288
+ /** The declared permission names a revoke acts on, de-duplicated, in order. */
289
+ function declaredNames(declared) {
290
+ return [...new Set(declared.permissions.map(permission => permission.name))];
291
+ }
292
+ /** What every grant write here hands the file layer. */
293
+ function grantWriteOptions() {
294
+ return {
295
+ dataDir: options.grantsDataDir,
296
+ knownPermissions: options.grants?.knownPermissions(),
297
+ };
298
+ }
299
+ /** Grant a bundle's declared permissions before its code is loaded (enable). */
300
+ async function ensureDeclared(plan) {
301
+ if (options.grants === undefined)
302
+ return undefined;
303
+ const write = await applyGrantMutation({ kind: 'ensure', id: plan.id, permissions: plan.entries }, grantWriteOptions());
304
+ if (!write.ok) {
305
+ emit([t('plugins-grant-write-refused', {
306
+ file: cell(grantsFilePath(options.grantsDataDir)),
307
+ reason: grantFailureText(write),
308
+ })]);
309
+ return undefined;
310
+ }
311
+ if (plan.unknown.length > 0) {
312
+ emit([t('plugins-grant-unknown-skipped', { names: cell(plan.unknown.join(', ')) })]);
313
+ }
314
+ if (write.changed) {
315
+ emit([t('plugins-manage-grant-granted', {
316
+ count: String(plan.entries.length),
317
+ id: cell(plan.id),
318
+ })]);
319
+ }
320
+ const store = options.grants;
321
+ if (store !== undefined) {
322
+ const unapplied = plan.entries.filter(entry => !store.allows({ componentId: plan.id }, entry.name, entry.scope));
323
+ if (unapplied.length > 0) {
324
+ emit([t('plugins-grant-unapplied', {
325
+ scopes: cell(unapplied.map(entry => `${entry.name}@${entry.scope}`).join(', ')),
326
+ })]);
327
+ }
328
+ }
329
+ return write;
330
+ }
331
+ /** Revoke the declared permission names after the code is unloaded (disable). */
332
+ async function revokeDeclared(declared) {
333
+ if (options.grants === undefined)
334
+ return;
335
+ const names = declaredNames(declared);
336
+ if (names.length === 0)
337
+ return;
338
+ const write = await applyGrantMutation({ kind: 'revoke', id: declared.id, names }, grantWriteOptions());
339
+ if (!write.ok) {
340
+ emit([t('plugins-manage-grant-revoke-failed', {
341
+ reason: grantFailureText(write),
342
+ id: cell(declared.id),
343
+ file: cell(grantsFilePath(options.grantsDataDir)),
344
+ })]);
345
+ return;
346
+ }
347
+ if (write.changed) {
348
+ emit([t('plugins-manage-grant-revoked', { count: String(names.length), id: cell(declared.id) })]);
349
+ }
350
+ }
351
+ /** Delete the component's grant entries after its package left (remove). */
352
+ async function forgetDeclared(declared) {
353
+ if (options.grants === undefined)
354
+ return;
355
+ const write = await applyGrantMutation({ kind: 'forget', id: declared.id }, grantWriteOptions());
356
+ if (!write.ok) {
357
+ // The one path that leaves an inheritance risk behind: a package reusing
358
+ // this component id would inherit these rules. Say so, with the id and
359
+ // the file, instead of a quiet warning.
360
+ emit([t('plugins-manage-grant-forget-failed', {
361
+ reason: grantFailureText(write),
362
+ id: cell(declared.id),
363
+ file: cell(grantsFilePath(options.grantsDataDir)),
364
+ })]);
365
+ return;
366
+ }
367
+ if (write.changed)
368
+ emit([t('plugins-manage-grant-forgotten', { id: cell(declared.id) })]);
369
+ }
370
+ /** An enable whose write failed: put the grant back, or say why not. */
371
+ async function rollbackGrant(write) {
372
+ if (write === undefined || !write.changed)
373
+ return;
374
+ const restored = await write.undo();
375
+ emit([t(restored ? 'plugins-grant-rolled-back' : 'plugins-grant-rollback-failed')]);
255
376
  }
256
377
  /** Write through the service, then turn its result into the next step. */
257
378
  async function run() {
@@ -263,16 +384,19 @@ export function createPluginManageFlow(options) {
263
384
  const refused = refuseWhileBusy();
264
385
  if (refused !== undefined)
265
386
  return refused;
266
- let residue;
267
- if (current.kind === 'bundle' && current.action === 'remove') {
268
- try {
269
- // The declaration is inside the package that the write removes.
270
- residue = options.residueOf?.(current.name);
271
- }
272
- catch {
273
- // An unreadable declaration leaves the removal's residue unjudged.
274
- }
387
+ // The declaration was captured in `decide()`, before the write: a removal
388
+ // can no longer read the package afterwards. A declaration that exists but
389
+ // cannot be read is reported here, with no id guessed.
390
+ if (current.kind === 'bundle' && declaration !== undefined
391
+ && (declaration.kind === 'unreadable' || declaration.grants === undefined)) {
392
+ emit([t('plugins-manage-grant-unhandled', { target: label })]);
275
393
  }
394
+ const declared = current.kind === 'bundle' && declaration?.kind === 'declared' ? declaration.grants : undefined;
395
+ const plan = current.kind === 'bundle' ? grantPlan : undefined;
396
+ // Grant before the write that loads the code; revoke and forget after the
397
+ // write that unloads it (grant lifecycle plan §6.2). A failed enable puts
398
+ // the grant back; the other two act only on a successful write.
399
+ const grantWrite = current.action === 'enable' && plan !== undefined ? await ensureDeclared(plan) : undefined;
276
400
  let result;
277
401
  try {
278
402
  result = await write(current);
@@ -281,13 +405,24 @@ export function createPluginManageFlow(options) {
281
405
  // The service folds its failures in-band; only a lock or a disposal error
282
406
  // rejects, and that still has to leave a readable line behind.
283
407
  emit([t('plugins-manage-failed', { reason: cell(error instanceof Error ? error.message : String(error)) })]);
408
+ if (current.action === 'enable')
409
+ await rollbackGrant(grantWrite);
284
410
  return { kind: 'done' };
285
411
  }
286
412
  // None of these three offers a cancellation; a service that reports one
287
413
  // anyway has already been reported by whatever stopped it.
288
- if (result.application === 'cancelled')
414
+ if (result.application === 'cancelled') {
415
+ if (current.action === 'enable')
416
+ await rollbackGrant(grantWrite);
289
417
  return { kind: 'done' };
418
+ }
290
419
  if (result.application === 'failed') {
420
+ // The profile's own files decide whether the enable landed: a reload
421
+ // failure after the selection was saved keeps the grant (the next start
422
+ // enables the bundle with its declaration), while a failed save puts it
423
+ // back. `application` alone cannot tell the two apart.
424
+ if (current.action === 'enable' && !result.changed)
425
+ await rollbackGrant(grantWrite);
291
426
  const incompatible = result.error?.code === 'incompatible-version' ? result.error.incompatible ?? [] : [];
292
427
  emit([
293
428
  t('plugins-manage-failed', { reason: failureReasonOf(result) }),
@@ -301,12 +436,26 @@ export function createPluginManageFlow(options) {
301
436
  }),
302
437
  t('plugins-install-rescue'),
303
438
  ]);
439
+ if (current.action === 'enable' && result.changed)
440
+ emit([t('plugins-manage-enable-persisted')]);
304
441
  return { kind: 'done' };
305
442
  }
443
+ // The write landed (or the profile was already in that state): a disable is
444
+ // still "off and revoked", and a removal still forgets the component. The
445
+ // declaration was read before the write, which is the only moment it could
446
+ // be read.
447
+ if (declared !== undefined) {
448
+ if (current.action === 'remove')
449
+ await forgetDeclared(declared);
450
+ else if (current.action === 'disable')
451
+ await revokeDeclared(declared);
452
+ }
306
453
  // A disk no-op says nothing about higher-priority overrides or a pending
307
454
  // restart. Only an applied no-op is already in the requested state.
308
455
  if (!result.changed && result.application === 'applied') {
309
456
  emit([t('plugins-manage-unchanged', { target: label })]);
457
+ if (current.kind === 'bundle' && current.action === 'remove')
458
+ reportResidue(current.name, declaration);
310
459
  return { kind: 'done' };
311
460
  }
312
461
  const stateKey = result.application === 'restart-required'
@@ -317,7 +466,7 @@ export function createPluginManageFlow(options) {
317
466
  ...result.application === 'restart-required' ? [t('plugins-install-restart-hint')] : [],
318
467
  ]);
319
468
  if (current.kind === 'bundle' && current.action === 'remove')
320
- reportResidue(current.name, residue);
469
+ reportResidue(current.name, declaration);
321
470
  return { kind: 'done' };
322
471
  }
323
472
  /** The service call one action makes, with the id shape the service takes. */
@@ -332,15 +481,22 @@ export function createPluginManageFlow(options) {
332
481
  }
333
482
  /**
334
483
  * What one removal left in this profile. The service rolls the profile's own
335
- * files back; everything under `~/.dsh-tui` — a backend's data directory, its
336
- * grants, its storage namespaces — is the person's own data and stays.
337
- * Reported once, deleted by nobody but them (decision D). Silent when the
338
- * watch judged the removal and found nothing: an "all clean" line on every
339
- * removal would be noise, and for a bundle that never had a backend it would
340
- * also answer a question nobody asked.
484
+ * files back; everything under `~/.dsh-tui` — a backend's data directory, the
485
+ * effect ledger, storage namespaces — is the person's own data and stays.
486
+ * The component's **grant entries** are the one exception: they are deleted
487
+ * with the component, because a later package reusing its id would inherit
488
+ * them (grant lifecycle plan D-3). Reported by source (D-5), once. Silent
489
+ * when the declaration was read and nothing is left.
341
490
  */
342
- function reportResidue(name, watch) {
491
+ function reportResidue(name, declaration) {
492
+ if (declaration === undefined || declaration.kind === 'unreadable') {
493
+ emit([t('plugins-manage-residue-unjudged', { target: cell(name) })]);
494
+ return;
495
+ }
496
+ const watch = declaration.residue;
343
497
  if (watch === undefined) {
498
+ // The declaration named no identity this check could look for. The old
499
+ // residue watch answered the same way: not judged, never "clean".
344
500
  emit([t('plugins-manage-residue-unjudged', { target: cell(name) })]);
345
501
  return;
346
502
  }
@@ -380,11 +536,11 @@ export function createPluginManageFlow(options) {
380
536
  * through (the screen then runs the read-only report, which is where the CLI
381
537
  * route is printed).
382
538
  *
383
- * This is the one place that knows how a removal is wired to the running
384
- * composition, and the only place that touches the person's own data. The
385
- * residue watch is built here, **while the bundle is still installed**: the
386
- * declaration that names its data directory and its plugin identity is a file
387
- * inside the package, so it is unreadable once the bundle has left.
539
+ * This is the one place that knows how a lifecycle action is wired to the
540
+ * running composition, and the only place that touches the person's own data.
541
+ * The bundle's declaration is read here, **while it is still installed**: its
542
+ * grants and the residue watch both come from a file inside the package, so
543
+ * both are unreadable once the bundle has left.
388
544
  */
389
545
  export function createPluginManageEntry(ctx, options = {}) {
390
546
  return (args, sink) => {
@@ -396,6 +552,9 @@ export function createPluginManageEntry(ctx, options = {}) {
396
552
  const manager = pluginManagerOf(ctx);
397
553
  if (manager === undefined)
398
554
  return undefined;
555
+ // The same live store the /plugin report and the plugin-host row use.
556
+ const grants = getHostGrantStore(ctx.get('tuiPluginHost'))
557
+ ?? readGrantStore(undefined, undefined, adapterRuntimeFor(ctx));
399
558
  return createPluginManageFlow({
400
559
  manager,
401
560
  action: parsed.kind,
@@ -405,9 +564,8 @@ export function createPluginManageEntry(ctx, options = {}) {
405
564
  onLines: sink.onLines,
406
565
  teamActiveMembers: sink.teamActiveMembers,
407
566
  profileName: options.profileName ?? resolveDshProfileName(),
408
- // Only a removal has anything to leave behind, and only a removal has a
409
- // package to read the declaration from.
410
- residueOf: parsed.kind === 'remove' ? name => residueWatchOf(ctx, name) : undefined,
567
+ grants,
568
+ declarationOf: name => bundleDeclarationOf(ctx, name),
411
569
  });
412
570
  };
413
571
  }
@@ -426,6 +584,22 @@ export function createPluginManageEntry(ctx, options = {}) {
426
584
  * is not evidence of a clean removal, only of an unanswerable question.
427
585
  */
428
586
  export function residueWatchOf(ctx, name, dataRoot = DATA_DIR) {
587
+ const declaration = bundleDeclarationOf(ctx, name, dataRoot);
588
+ return declaration?.kind === 'declared' ? declaration.residue : undefined;
589
+ }
590
+ /**
591
+ * Read one installed bundle's declaration once, before any lifecycle write.
592
+ *
593
+ * The declaration is the package's own file, so it has to be read while the
594
+ * package is still there: after a removal it is gone, and after an enable or
595
+ * disable the grants half still has to name the component id. The raw parse
596
+ * feeds both answers — the residue watch (which trusts the declaration's own
597
+ * `id`/Backend ids, as before) and the grants reader (which applies the same
598
+ * parse/projection gates every other consumer does). A file that exists but
599
+ * cannot be read is `unreadable`, never "no declaration": the two lead to
600
+ * different reports.
601
+ */
602
+ export function bundleDeclarationOf(ctx, name, dataRoot = DATA_DIR) {
429
603
  const declaration = pluginDeclarationOf(ctx, name);
430
604
  if (declaration === undefined)
431
605
  return undefined;
@@ -434,27 +608,42 @@ export function residueWatchOf(ctx, name, dataRoot = DATA_DIR) {
434
608
  parsed = JSON.parse(declaration.source);
435
609
  }
436
610
  catch {
437
- return undefined;
611
+ return { kind: 'unreadable' };
438
612
  }
439
- const record = parsed !== null && typeof parsed === 'object' ? parsed : undefined;
440
- const componentId = typeof record?.id === 'string' && record.id !== '' ? record.id : undefined;
613
+ if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed))
614
+ return { kind: 'unreadable' };
615
+ const record = parsed;
616
+ const componentId = typeof record.id === 'string' && record.id !== '' ? record.id : undefined;
441
617
  const backendIds = backendIdsIn(record);
442
- if (componentId === undefined && backendIds.length === 0)
443
- return undefined;
444
- return () => {
445
- const left = [];
446
- for (const backendId of backendIds) {
447
- const dir = backendDataDir(backendId, dataRoot);
448
- if (existsSync(dir))
449
- left.push(dir);
450
- }
451
- // The three footprint sources the grant matrix unions, asked through the
452
- // same reader that drew it — never by a second one that could disagree.
453
- if (componentId !== undefined && pluginFootprintContains(componentId, { dataDir: dataRoot })) {
454
- left.push(t('plugins-manage-residue-footprint', { id: cell(componentId) }));
455
- }
456
- return left;
457
- };
618
+ const grants = declaredGrantsOf(record);
619
+ const residue = componentId === undefined && backendIds.length === 0
620
+ ? undefined
621
+ : () => {
622
+ const left = [];
623
+ for (const backendId of backendIds) {
624
+ const dir = backendDataDir(backendId, dataRoot);
625
+ if (existsSync(dir))
626
+ left.push(dir);
627
+ }
628
+ if (componentId !== undefined) {
629
+ // One source per line (D-5): the grants entry was deleted with the
630
+ // component, so what remains here is the audit ledger and the person's
631
+ // storage namespace, each named by its own path.
632
+ const sources = pluginFootprintSourcesOf(componentId, { dataDir: dataRoot });
633
+ const paths = pluginFootprintPaths({ dataDir: dataRoot });
634
+ const id = cell(componentId);
635
+ if (sources.ledger)
636
+ left.push(t('plugins-manage-residue-ledger', { id, file: cell(paths.ledgerFile) }));
637
+ if (sources.storage) {
638
+ left.push(t('plugins-manage-residue-storage', {
639
+ id,
640
+ file: cell(join(paths.storageDir, `${storageFileName(componentId)}.json`)),
641
+ }));
642
+ }
643
+ }
644
+ return left;
645
+ };
646
+ return { kind: 'declared', grants, residue };
458
647
  }
459
648
  /**
460
649
  * The backend ids a declaration contributes. Only a `Backend` entry names one,
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/dsh-adapter/plugin.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAe,MAAM,wBAAwB,CAAA;AAGhE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAGlD,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,EAA+D,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAsBtH,OAAO,EAAmE,KAAK,WAAW,EAAE,M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AU,CAC9B,GAAG,EAAE,OAAO,EACZ,QAAQ,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO,MAAM,CAAC,CAAC,GAAG,SAAS,EACxD,UAAU,EAAE,OAAO,EACnB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,YAAY,EAAE,MAAM,GAAG,SAAS,EAChC,IAAI,EAAE,MAAM,IAAI,EAChB,OAAO,GAAE;IACP,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,0EAA0E;IAC1E,aAAa,CAAC,EAAE,aAAa,CAAA;CACzB,GACL,OAAO,CAAC,IAAI,CAAC,CAuGf;AA4MD,gFAAgF;AAChF,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAIrE"}
@@ -52,6 +52,7 @@ import { clearResumeTarget, resumeTargetFromArgv, stripResumeArgs, writeResumeTa
52
52
  import { cmdlineArgsOf, initialPromptFromCmdlineArgs } from './startup-args.js';
53
53
  import { readHomePrefs } from '../homePrefs.js';
54
54
  import { handoffEventTag, formatHandoffNotice } from '../handoffEvents.js';
55
+ import { adoptHeldInputs, heldInputsResumeCommand, takeHeldInputs, writeHeldInputs } from '../heldInputs.js';
55
56
  import { armFirstFrameAck, beginHandoffAck, handoffAttemptId, ownsAltScreenExit } from '../handoffAck.js';
56
57
  import { DSH_BACKEND_ID, HOST_NOTICE_ENV, KERNEL_SWITCH_HANDOFF_ENV, RESUME_BACKEND_ENV, RESUME_RETRY_ENV, parseBackendId, readKernelPrefs, resolveRememberedBackend, resolveResumeTarget, writeKernelPrefs } from '../kernelPrefs.js';
57
58
  import { shouldOfferOnboarding } from '../onboardingPrefs.js';
@@ -79,7 +80,8 @@ import { getHostThemes } from './themes.js';
79
80
  import { attachSessionToWorkspace } from './workspace.js';
80
81
  import { createLocalWorkspaceRuntime, getHostWorkspaceRuntime } from './workspaces.js';
81
82
  import { trackHostSettingsSection } from './settings-sections.js';
82
- import { compositionRoot, withHostRootCapability } from './host-access.js';
83
+ import { compositionRoot, outsideActivation, withHostRootCapability } from './host-access.js';
84
+ import { createRowAttachment } from './row-attachment.js';
83
85
  import { armAdmissionLoader } from './admission-loader.js';
84
86
  import { assembleBackendsFromProfile } from './backend-assembly.js';
85
87
  import { disposeRootSettled } from './root-dispose.js';
@@ -482,7 +484,8 @@ export async function apply(ctx, runtimeConfig, configOwner = ctx, runtimeOption
482
484
  // The host-level tool mount above is intentional for the TUI and for user
483
485
  // presets, but the official Minimal preset is a single-tool trajectory (one
484
486
  // persistent shell: bash on POSIX, pwsh on Windows). Filter only that preset
485
- // at the final assembly boundary. Reading the session on every assembly also
487
+ // (plus create_worktree for liangshen, presets.ts) at the final assembly
488
+ // boundary. Reading the session on every assembly also
486
489
  // makes blank-session /preset switches and resumed sessions behave correctly.
487
490
  // Agent Teams is decided at the same boundary: presets keep their legacy
488
491
  // delegation rows, and a request that carries `spawn_teammate` drops
@@ -2046,6 +2049,10 @@ export async function apply(ctx, runtimeConfig, configOwner = ctx, runtimeOption
2046
2049
  // The standalone entry has no `ctx.cmdlineArgs` (its argv is the app's); a
2047
2050
  // replacement keeps the arguments but the first process sent their prompt.
2048
2051
  const initialPrompt = launchPromptSent ? '' : initialPromptFromCmdlineArgs(cmdlineArgs ?? process.argv.slice(2));
2052
+ // The queue a /restart carried over: held, never auto-sent (heldInputs.ts).
2053
+ const stopHeldInputs = adoptHeldInputs(channel);
2054
+ if (stopHeldInputs !== undefined)
2055
+ ctx.effect(() => stopHeldInputs, 'dsh-tui held inputs after startup');
2049
2056
  if (initialPrompt) {
2050
2057
  // A placeholder session refuses sends and nothing replays them after
2051
2058
  // adoption: hold the prompt until the channel is ready.
@@ -2225,12 +2232,15 @@ export async function apply(ctx, runtimeConfig, configOwner = ctx, runtimeOption
2225
2232
  });
2226
2233
  }
2227
2234
  refreshLastRunRecord();
2235
+ // The queue dies with this process (the kernel records it canceled);
2236
+ // the replacement parks the same texts as held dock rows (#1651).
2237
+ const heldEnv = writeHeldInputs(channel.pending.map(item => item.text));
2228
2238
  void finishExit(ctx, instance, bootedFullscreen,
2229
2239
  // This line is the one the user actually sees before the terminal is
2230
2240
  // handed over (the composer's toast dies with the unmount): a
2231
- // mid-turn restart must say that the running turn and its queued
2232
- // input are dropped, not promise a clean resume.
2233
- t(channel.working ? 'restart-during-turn' : 'restart-starting'), undefined, () => runRestart(ctx, profile, handoffSessionId(), handoffHint, { kernel: backendChoice }, exitSeam));
2241
+ // mid-turn restart must say that the running turn is interrupted,
2242
+ // not promise a clean resume.
2243
+ t(channel.working ? 'restart-during-turn' : 'restart-starting'), undefined, () => runRestart(ctx, profile, handoffSessionId(), handoffHint, { kernel: backendChoice, env: heldEnv }, exitSeam));
2234
2244
  return;
2235
2245
  }
2236
2246
  // Judge against the live session behind the channel (channel.agentId),
@@ -2741,6 +2751,36 @@ export async function apply(ctx, runtimeConfig, configOwner = ctx, runtimeOption
2741
2751
  catch {
2742
2752
  }
2743
2753
  };
2754
+ // The row's seams (presets, ask_user, approvals, the assembly filters)
2755
+ // live on the row and unload with it: a row that comes back mounts them again.
2756
+ const rowAttachment = createRowAttachment({
2757
+ closed: () => compositionFailed || exited,
2758
+ ready: () => channel.ready,
2759
+ mountSeams: async (dshCtx) => {
2760
+ await installPresets(dshCtx);
2761
+ const seams = mountDshQuestionSeams(dshCtx);
2762
+ if (seams.notice !== undefined)
2763
+ notifyChannel(seams.notice, { color: 'error' });
2764
+ if (seams.registration.kind === 'waterfall')
2765
+ seams.registration.register(channel);
2766
+ mountDshApprovals(dshCtx);
2767
+ refreshHostServices();
2768
+ },
2769
+ readConfig: (rowRuntimeConfig) => { rowFacts.config = configValues(rowRuntimeConfig); },
2770
+ ended: () => channel.status === 'disposed',
2771
+ // The resume path reopens the session on the entry's own context, so
2772
+ // a later unload of the row can no longer take the agent along. It
2773
+ // runs as the entry's action: the row's activation only triggered it.
2774
+ reopen: async () => {
2775
+ const result = await outsideActivation(() => channel.resumeTo(channel.sessionId));
2776
+ if (result.ok)
2777
+ notifyChannel(t('session-reattached'));
2778
+ },
2779
+ failed: (error) => {
2780
+ logForDebugging(`dsh-tui: reopening the session after its row came back failed (${error instanceof Error ? error.message : String(error)})`);
2781
+ },
2782
+ });
2783
+ entrySlot.reattachDsh = rowAttachment.reattach;
2744
2784
  entrySlot.attachDsh = async (rowCtx, rowRuntimeConfig) => {
2745
2785
  const dshCtx = rowCtx;
2746
2786
  // The composition failed (its row is on screen), or the process is
@@ -2750,14 +2790,7 @@ export async function apply(ctx, runtimeConfig, configOwner = ctx, runtimeOption
2750
2790
  try {
2751
2791
  const rowConfig = configValues(rowRuntimeConfig);
2752
2792
  rowFacts.config = rowConfig;
2753
- await installPresets(dshCtx);
2754
- const seams = mountDshQuestionSeams(dshCtx);
2755
- if (seams.notice !== undefined)
2756
- notifyChannel(seams.notice, { color: 'error' });
2757
- if (seams.registration.kind === 'waterfall')
2758
- seams.registration.register(channel);
2759
- mountDshApprovals(dshCtx);
2760
- refreshHostServices();
2793
+ await rowAttachment.mount(dshCtx);
2761
2794
  const rowRoute = { provider: rowConfig.provider, model: rowConfig.model };
2762
2795
  // The same startup/deployment split the plugin's own boot makes (issue #67).
2763
2796
  const { startupRoute: rowStartupRoute, deploymentRoute: rowDeploymentRoute } = startupRoutes(dshCtx, rowRoute);
@@ -2774,7 +2807,7 @@ export async function apply(ctx, runtimeConfig, configOwner = ctx, runtimeOption
2774
2807
  const created = await openOnRow(undefined, { cwd });
2775
2808
  await takeOpened(created);
2776
2809
  refreshLastRunRecord();
2777
- return createDshSession(dshCtx, { agent: created.agent, handle: created.handle });
2810
+ return createDshSession(dshCtx, { agent: created.agent, handle: created.handle }, { screenOutlivesContext: true });
2778
2811
  };
2779
2812
  // The entry mounted on rebuilt defaults: the row's own `workspace` /
2780
2813
  // `cwd` decide the session directory, with `apply`'s precedence. A
@@ -2798,7 +2831,7 @@ export async function apply(ctx, runtimeConfig, configOwner = ctx, runtimeOption
2798
2831
  ? undefined
2799
2832
  : rowConfig.sessionId ?? resumeTargetFromArgv(cmdlineArgsOf(dshCtx) ?? process.argv.slice(2));
2800
2833
  const opened = await openOnRow(rowSessionId, startupMeta);
2801
- const session = createDshSession(dshCtx, { agent: opened.agent, handle: opened.handle });
2834
+ const session = createDshSession(dshCtx, { agent: opened.agent, handle: opened.handle }, { screenOutlivesContext: true });
2802
2835
  // The composition failed while this opened: close the unadoptable session.
2803
2836
  if (compositionFailed) {
2804
2837
  await session.dispose().catch(() => undefined);
@@ -3357,8 +3390,18 @@ function runRestart(ctx, profile, sessionId, hint = id => resumeCommand(profile,
3357
3390
  // abort). Spawning the replacement then would race this process for the
3358
3391
  // session mount, so the only honest answer is the resume hint the user can
3359
3392
  // run after this process is gone.
3393
+ // Held texts no replacement took (a stall, a failed spawn) stay on disk for
3394
+ // the resume command, which names their file; without a session to resume
3395
+ // they go. A replacement that ran took them already.
3396
+ const dropHeldInputs = () => { takeHeldInputs({ ...options.env }); };
3397
+ const resumeLine = (id) => heldInputsResumeCommand(hint(id), options.env);
3398
+ const ended = () => {
3399
+ if (sessionId === '')
3400
+ dropHeldInputs();
3401
+ return preservedSessionTail(sessionId, resumeLine);
3402
+ };
3360
3403
  const stalled = () => {
3361
- writeHandoffNotice(`\ndsh-tui restart timed out while stopping the current turn.${preservedSessionTail(sessionId, hint)}`);
3404
+ writeHandoffNotice(`\ndsh-tui restart timed out while stopping the current turn.${ended()}`);
3362
3405
  process.exit(1);
3363
3406
  };
3364
3407
  disposeRootAndThen(ctx, () => {
@@ -3375,13 +3418,16 @@ function runRestart(ctx, profile, sessionId, hint = id => resumeCommand(profile,
3375
3418
  void restartTui(sessionId, supervision).then(restartCode => {
3376
3419
  logRestartEvent('runRestart: restartTui resolved', { restartCode });
3377
3420
  if (restartCode !== 0) {
3378
- writeHandoffNotice(`\ndsh-tui restart failed to spawn (exit ${restartCode}).${preservedSessionTail(sessionId, hint)}`);
3421
+ writeHandoffNotice(`\ndsh-tui restart failed to spawn (exit ${restartCode}).${ended()}`);
3422
+ }
3423
+ else {
3424
+ dropHeldInputs();
3379
3425
  }
3380
3426
  process.exit(restartCode);
3381
3427
  }, restartError => {
3382
3428
  const message = restartError instanceof Error ? restartError.message : String(restartError);
3383
3429
  logRestartEvent('runRestart: restartTui rejected', { message });
3384
- writeHandoffNotice(`\ndsh-tui restart failed: ${message}.${preservedSessionTail(sessionId, hint)}`);
3430
+ writeHandoffNotice(`\ndsh-tui restart failed: ${message}.${ended()}`);
3385
3431
  process.exit(1);
3386
3432
  });
3387
3433
  }, stalled);
@@ -76,18 +76,17 @@ export interface PluginFootprintOverrides {
76
76
  * storage namespaces ('host'/'undeclared' ledger identities are not
77
77
  * plugins and are excluded). */
78
78
  export declare function pluginFootprints(paths: PluginFootprintPaths): string[];
79
+ /** Which of the three sources still names one plugin id. */
80
+ export declare function pluginFootprintSourcesOf(pluginId: string, overrides?: PluginFootprintOverrides): {
81
+ readonly grants: boolean;
82
+ readonly ledger: boolean;
83
+ readonly storage: boolean;
84
+ };
79
85
  /**
80
86
  * The three footprint sources, resolved the way the diagnostics resolve them
81
87
  * (test overrides first, else the packaged locations under `~/.dsh-tui`).
82
88
  */
83
89
  export declare function pluginFootprintPaths(overrides?: PluginFootprintOverrides): PluginFootprintPaths;
84
- /**
85
- * Whether one plugin id still has a footprint in this profile: a grants-file
86
- * key, an effect-ledger record, or a storage namespace. The same three sources
87
- * the matrix unions — a removal that left something behind is read here rather
88
- * than by a second reader that could disagree with the report (C-5).
89
- */
90
- export declare function pluginFootprintContains(pluginId: string, overrides?: PluginFootprintOverrides): boolean;
91
90
  /** Which form of the command the raw argument text asks for. */
92
91
  export type PluginArgs = {
93
92
  readonly kind: 'overview';