@songtonyli/dsh-cli 0.1.26 → 0.1.28

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.
@@ -8,7 +8,7 @@ import { canOpenNativePath, openNativeUrl } from "@deepseek-ai/dsh-native-comman
8
8
  import { SessionLogOffset } from "@deepseek-ai/dsh-session";
9
9
  import { homedir } from "node:os";
10
10
  import "@deepseek-ai/cordis";
11
- import { HarnessError, ReasoningEffortId, createUserMessage } from "@deepseek-ai/dsh-llm";
11
+ import { HarnessError, ReasoningEffortId, boundContextSummary, createUserMessage } from "@deepseek-ai/dsh-llm";
12
12
  import { activeAtToken, formatFileMention } from "@deepseek-ai/dsh-file-reference";
13
13
  import { formatSessionReferenceMention } from "@deepseek-ai/dsh-session-reference";
14
14
  import { assertNever } from "@deepseek-ai/dsh-util-values";
@@ -2239,7 +2239,10 @@ const SGR = {
2239
2239
  bold: ["1", "22"],
2240
2240
  italic: ["3", "23"],
2241
2241
  underline: ["4", "24"],
2242
+ strikethrough: ["9", "29"],
2242
2243
  accent: ["36", "39"],
2244
+ heading: ["38;5;117", "39"],
2245
+ link: ["38;5;75", "39"],
2243
2246
  success: ["32", "39"],
2244
2247
  warning: ["33", "39"],
2245
2248
  error: ["31", "39"],
@@ -2260,7 +2263,10 @@ function createPalette(enabled) {
2260
2263
  bold: role("bold"),
2261
2264
  italic: role("italic"),
2262
2265
  underline: role("underline"),
2266
+ strikethrough: role("strikethrough"),
2263
2267
  accent: role("accent"),
2268
+ heading: role("heading"),
2269
+ link: role("link"),
2264
2270
  success: role("success"),
2265
2271
  warning: role("warning"),
2266
2272
  error: role("error"),
@@ -2306,19 +2312,19 @@ function colorEnabled(env, isTty) {
2306
2312
  function markdownTheme(palette, highlight) {
2307
2313
  return {
2308
2314
  highlightCode: (code, lang) => highlight?.lines(code, lang) ?? code.split("\n"),
2309
- heading: (text) => palette.bold(palette.accent(text)),
2310
- link: palette.accent,
2315
+ heading: (text) => palette.bold(palette.heading(text)),
2316
+ link: (text) => palette.underline(palette.link(text)),
2311
2317
  linkUrl: palette.dim,
2312
- code: palette.warning,
2318
+ code: palette.link,
2313
2319
  codeBlock: (text) => text,
2314
2320
  codeBlockBorder: palette.dim,
2315
- quote: palette.italic,
2321
+ quote: (text) => palette.italic(palette.dim(text)),
2316
2322
  quoteBorder: palette.dim,
2317
2323
  hr: palette.dim,
2318
- listBullet: palette.accent,
2324
+ listBullet: palette.heading,
2319
2325
  bold: palette.bold,
2320
2326
  italic: palette.italic,
2321
- strikethrough: palette.dim,
2327
+ strikethrough: palette.strikethrough,
2322
2328
  underline: palette.underline
2323
2329
  };
2324
2330
  }
@@ -3508,6 +3514,79 @@ var BarCursorEditor = class extends Editor {
3508
3514
  });
3509
3515
  }
3510
3516
  };
3517
+ //#endregion
3518
+ //#region lib/types/shell-line.js
3519
+ /**
3520
+ * Parse and present a user-typed `!` / `!!` shell line. The terminal runs the
3521
+ * command itself; `!` becomes next-step context and `!!` stays local.
3522
+ * @module @deepseek-ai/dsh-tui-app/shell-line
3523
+ */
3524
+ /**
3525
+ * Read a submitted editor line as a user shell command.
3526
+ * @param text - the trimmed editor text.
3527
+ * @returns the command and whether it is excluded, or undefined when the line
3528
+ * is not a nonempty `!` / `!!` prefix.
3529
+ */
3530
+ function parseUserShellLine(text) {
3531
+ const trimmed = text.trim();
3532
+ if (!trimmed.startsWith("!")) return void 0;
3533
+ const excluded = trimmed.startsWith("!!");
3534
+ const command = (excluded ? trimmed.slice(2) : trimmed.slice(1)).trim();
3535
+ return command === "" ? void 0 : {
3536
+ command,
3537
+ excluded
3538
+ };
3539
+ }
3540
+ /**
3541
+ * Shape one finished run as the text the next model request reads.
3542
+ * @param command - the command the user typed after `!`.
3543
+ * @param result - the completed foreground run.
3544
+ * @returns the model-facing notice body.
3545
+ */
3546
+ function userShellContextText(command, result) {
3547
+ const output = combinedOutput(result);
3548
+ let text = `The user ran \`${command}\` in the terminal.\n`;
3549
+ text += output === "" ? "(no output)" : `\`\`\`\n${output}\n\`\`\``;
3550
+ if (result.aborted) text += "\n\n(command cancelled)";
3551
+ else if (result.timedOut) text += `\n\n[timed out after ${String(result.timeoutMs)}ms]`;
3552
+ else if (result.signal !== null) text += `\n\n[killed by signal: ${result.signal}]`;
3553
+ else if (result.exitCode !== null && result.exitCode !== 0) text += `\n\nCommand exited with code ${String(result.exitCode)}`;
3554
+ return text;
3555
+ }
3556
+ /**
3557
+ * Shape one finished run as the rows the transcript draws immediately.
3558
+ * @param command - the command the user typed after `!`.
3559
+ * @param result - the completed foreground run.
3560
+ * @returns `$ command`, any output, and a cancel or nonzero-exit marker.
3561
+ */
3562
+ function userShellTranscriptRows(command, result) {
3563
+ const output = combinedOutput(result);
3564
+ const rows = [`$ ${command}`];
3565
+ if (output !== "") rows.push(output);
3566
+ if (result.aborted) rows.push("(command cancelled)");
3567
+ else if (result.exitCode !== null && result.exitCode !== 0) rows.push(`(exit ${String(result.exitCode)})`);
3568
+ return rows;
3569
+ }
3570
+ /**
3571
+ * Join stdout and a marked stderr section, dropping a single trailing newline
3572
+ * so a fenced body does not carry a blank last line.
3573
+ * @param result - the completed foreground run.
3574
+ * @returns the combined body, or the empty string when both streams are empty.
3575
+ */
3576
+ function combinedOutput(result) {
3577
+ const out = streamText(result.stdout);
3578
+ const err = streamText(result.stderr);
3579
+ if (err === "") return out;
3580
+ return out === "" ? `[stderr]\n${err}` : `${out}\n[stderr]\n${err}`;
3581
+ }
3582
+ /**
3583
+ * Take one collected stream, appending its truncation marker when present.
3584
+ * @param output - one captured stream.
3585
+ * @returns the text without a single trailing newline.
3586
+ */
3587
+ function streamText(output) {
3588
+ return (output.truncated ? `${output.text}\n[output truncated; full output: ${output.spillPath ?? "(unavailable)"}]` : output.text).replace(/\n$/u, "");
3589
+ }
3511
3590
  /** What the provider-default row is called. */
3512
3591
  const PROVIDER_DEFAULT_LABEL = "Provider default";
3513
3592
  /** The `/effort` argument that restores the provider default. */
@@ -3562,6 +3641,54 @@ function matchEffort(reasoning, typed) {
3562
3641
  return wanted === DEFAULT_ARGUMENT ? void 0 : null;
3563
3642
  }
3564
3643
  //#endregion
3644
+ //#region lib/types/permission.js
3645
+ /**
3646
+ * Permission-preset rows and labels shared by `/permission` and the
3647
+ * permission status-bar hint.
3648
+ * @module @deepseek-ai/dsh-tui-app/permission
3649
+ */
3650
+ /**
3651
+ * The display name of one preset.
3652
+ * @param options - the process catalog.
3653
+ * @param preset - the selected preset, including a derived `custom` value.
3654
+ * @returns the catalog label, or the raw id when the catalog no longer lists it.
3655
+ */
3656
+ function permissionName(options, preset) {
3657
+ return options.find((option) => option.value === preset)?.name ?? preset;
3658
+ }
3659
+ /**
3660
+ * Picker rows for the process catalog, in contribution order.
3661
+ * @param options - the selectable presets.
3662
+ * @returns the rows.
3663
+ */
3664
+ function permissionItems(options) {
3665
+ return options.map((option) => ({
3666
+ value: option.value,
3667
+ label: option.name,
3668
+ ...option.description === void 0 ? {} : { description: option.description }
3669
+ }));
3670
+ }
3671
+ /**
3672
+ * The dim row under the picker heading.
3673
+ * @param options - the process catalog.
3674
+ * @param preset - the preset in force.
3675
+ * @returns one row naming the preset in force and how to dismiss the picker.
3676
+ */
3677
+ function permissionHint(options, preset) {
3678
+ return `current: ${permissionName(options, preset)} · Esc keeps it`;
3679
+ }
3680
+ /**
3681
+ * The preset a typed `/permission` argument names. Matching is without case
3682
+ * so a typed id can follow the catalog's own casing.
3683
+ * @param options - the process catalog.
3684
+ * @param typed - the argument, matched against catalog values.
3685
+ * @returns the catalog value, or null when nothing matches.
3686
+ */
3687
+ function matchPermission(options, typed) {
3688
+ const wanted = typed.toLowerCase();
3689
+ return options.find((option) => option.value.toLowerCase() === wanted)?.value ?? null;
3690
+ }
3691
+ //#endregion
3565
3692
  //#region lib/types/export.js
3566
3693
  /**
3567
3694
  * `/export`: the same session-log ZIP the browser downloads, written to a
@@ -3756,9 +3883,9 @@ const HINTS = {
3756
3883
  "Esc input"
3757
3884
  ],
3758
3885
  queue: [
3759
- "↑↓ prompts · S steer · I inject · E edit · Esc input",
3760
- "S steer · I inject · E edit · Esc input",
3761
- "Esc input"
3886
+ "enter steer · ↑ select/edit · esc cancel",
3887
+ "enter steer · esc cancel",
3888
+ "esc cancel"
3762
3889
  ],
3763
3890
  panel: [
3764
3891
  "↑↓ children · Enter details · Tab regions · Esc input",
@@ -3788,7 +3915,7 @@ const FOCUS_REGIONS = [
3788
3915
  const REGION_LABELS = {
3789
3916
  editor: "input",
3790
3917
  transcript: "conversation",
3791
- queue: "queued prompts",
3918
+ queue: "follow-ups",
3792
3919
  panel: "subagent panel",
3793
3920
  bar: "status bar"
3794
3921
  };
@@ -3823,6 +3950,7 @@ const KEY_LINES = {
3823
3950
  "Enter sends · Shift+Enter newline · ↑↓ history · Ctrl+S steers",
3824
3951
  "Shift+Tab effort list · Shift+←→ words",
3825
3952
  "@ completes paths and sessions · / completes commands · Tab takes one",
3953
+ "!cmd runs here · the next prompt can read it · !!cmd stays local",
3826
3954
  `${ENTRY_KEYS} · Ctrl+G reader`,
3827
3955
  "Ctrl+O folds every tool card and context row",
3828
3956
  "Esc arms the stop · Esc again stops the turn",
@@ -4107,13 +4235,17 @@ function transcriptKey(data) {
4107
4235
  return cycleKey(data) ?? typeKey(data);
4108
4236
  }
4109
4237
  /**
4110
- * What one key means while the pending-prompt panel holds the keyboard.
4238
+ * What one key means while the follow-ups panel holds the keyboard.
4111
4239
  * @param data - the raw key bytes.
4112
4240
  * @returns the action, or undefined for a key the panel consumes without effect.
4113
4241
  */
4114
4242
  function queueKey(data) {
4115
4243
  const move = moveKey(data, QUEUE_MOVES);
4116
4244
  if (move !== void 0) return move;
4245
+ if (matchesKey(data, "enter")) return {
4246
+ kind: "queue",
4247
+ action: "steer"
4248
+ };
4117
4249
  if (data === "s" || data === "S") return {
4118
4250
  kind: "queue",
4119
4251
  action: "steer"
@@ -4772,9 +4904,10 @@ function partLabels(cursor, blocks) {
4772
4904
  /**
4773
4905
  * The agent's todo list as terminal rows: the status glyphs every todo surface
4774
4906
  * of this terminal draws, the picker choices the list offers, and the detail
4775
- * rows one entered item prints. Everything here is pure text work over plain
4776
- * values; the single service touch is one optional read of the `todos` session
4777
- * projection.
4907
+ * rows one entered item prints. Completed picker content can take a paint
4908
+ * function so the list scratches it out. Everything here is pure text work
4909
+ * over plain values; the single service touch is one optional read of the
4910
+ * `todos` session projection.
4778
4911
  * @module @deepseek-ai/dsh-tui-app/todos
4779
4912
  */
4780
4913
  /**
@@ -4817,22 +4950,34 @@ const TODO_STATUSES = [
4817
4950
  "pending"
4818
4951
  ];
4819
4952
  /**
4953
+ * The content a todo row shows: completed items take `paint` so the list can
4954
+ * scratch them out; every other status is the content unchanged.
4955
+ * @param content - the text after any row-length cut.
4956
+ * @param status - the item's status.
4957
+ * @param paint - how completed content is marked.
4958
+ * @returns the painted content, or `content` when the item is not completed or no paint was given.
4959
+ */
4960
+ function paintTodoContent(content, status, paint) {
4961
+ return status === "completed" && paint !== void 0 ? paint(content) : content;
4962
+ }
4963
+ /**
4820
4964
  * The agent's current todo list as picker rows, in write order.
4821
4965
  * @param ctx - plugin context carrying the optional session-projection registry.
4822
4966
  * @param session - the session whose todo list is read.
4967
+ * @param paint - how completed content is marked; omitted leaves it unmarked.
4823
4968
  * @returns one choice per item. Empty in three cases: no projection registry
4824
4969
  * is composed in this profile, the registry has no `todos` unit registered, or
4825
4970
  * the value is `null` — which it is before the first `todo_write` of the
4826
4971
  * current turn, since every `turn/start` clears the list.
4827
4972
  */
4828
- function listTodoChoices(ctx, session) {
4973
+ function listTodoChoices(ctx, session, paint) {
4829
4974
  const projections = ctx.get("sessionProjections");
4830
4975
  if (projections === void 0) return [];
4831
4976
  const items = projections.snapshot(session, ["todos"]).values.todos;
4832
4977
  if (items === void 0 || items === null) return [];
4833
4978
  return items.map((item, index) => ({
4834
4979
  index,
4835
- label: `${TODO_GLYPH[item.status]} ${labelContent(item.content)}`,
4980
+ label: `${TODO_GLYPH[item.status]} ${paintTodoContent(labelContent(item.content), item.status, paint)}`,
4836
4981
  description: describeStatus(item.status),
4837
4982
  status: item.status
4838
4983
  }));
@@ -5317,7 +5462,7 @@ function buildFooterSegments(inputs) {
5317
5462
  segments.push({
5318
5463
  id: "permission",
5319
5464
  label: `permission ${inputs.permission}`,
5320
- detail: printed([...projected.length === 0 ? [`permission: ${inputs.permission}`] : projected, "/permission <preset> changes the sandbox mode and the approval policy"])
5465
+ detail: printed([...projected.length === 0 ? [`permission: ${inputs.permission}`] : projected, "/permission opens the permission list"])
5321
5466
  });
5322
5467
  }
5323
5468
  if (turn !== void 0) segments.push({
@@ -6174,12 +6319,29 @@ var ModalQueue = class {
6174
6319
  //#endregion
6175
6320
  //#region lib/types/queue-panel.js
6176
6321
  /**
6177
- * The pending-prompt panel above the editor. It presents the Agent inbox as a
6178
- * framed, selectable list without mutating the messages it displays.
6322
+ * The follow-up panel above the editor. It presents the Agent inbox as a
6323
+ * boxed pending-prompt list without mutating the messages it displays.
6179
6324
  * @module @deepseek-ai/dsh-tui-app/queue-panel
6180
6325
  */
6181
6326
  /**
6327
+ * The first content line a row shows.
6328
+ * @param content - the message's full text.
6329
+ * @returns the text before the first newline, or all of `content` when it is one line.
6330
+ */
6331
+ function firstLine(content) {
6332
+ const breakAt = content.indexOf("\n");
6333
+ return breakAt === -1 ? content : content.slice(0, breakAt);
6334
+ }
6335
+ /** Pending-row marker; the same glyph the todo list uses for an unstarted item. */
6336
+ const FOLLOW_UP_GLYPH = "○";
6337
+ /** Columns the glyph and its trailing space occupy on the first wrapped line. */
6338
+ const FOLLOW_UP_PREFIX = `${FOLLOW_UP_GLYPH} `;
6339
+ /** Indent that lines up wrapped follow-up text under the first line's content. */
6340
+ const FOLLOW_UP_INDENT = " ";
6341
+ /**
6182
6342
  * Build the panel rows in claim order: next-step input before ordinary turns.
6343
+ * Messages whose source is not `user` are omitted: a `!` notice waiting for
6344
+ * the next prompt is context, not a prompt the keyboard can steer or edit.
6183
6345
  * @param nextStep - messages waiting for the nearest step boundary.
6184
6346
  * @param nextTurn - messages waiting for separate turns.
6185
6347
  * @returns selectable pending-prompt rows.
@@ -6188,13 +6350,26 @@ function queuePanelRows(nextStep, nextTurn) {
6188
6350
  const row = (target, message) => ({
6189
6351
  message,
6190
6352
  target,
6191
- text: contentText(message.content).split("\n", 1)[0] ?? ""
6353
+ text: firstLine(contentText(message.content))
6192
6354
  });
6193
- return [...nextStep.map((message) => row("next-step", message)), ...nextTurn.map((message) => row("next-turn", message))];
6355
+ const pending = (target, messages) => messages.filter((message) => message.source.kind === "user").map((message) => row(target, message));
6356
+ return [...pending("next-step", nextStep), ...pending("next-turn", nextTurn)];
6194
6357
  }
6195
6358
  /**
6196
- * Render the pending prompts inside a frame. A focused panel accents its held
6197
- * row and names its actions; an unfocused panel names the key that enters it.
6359
+ * One follow-up's text wrapped under the pending glyph, hanging the
6360
+ * continuation so it lines up with the first line's content.
6361
+ * @param text - the row's first content line.
6362
+ * @param room - columns inside the frame.
6363
+ * @param glyph - the pending marker, already styled.
6364
+ * @returns one or more body contents, never wider than `room`.
6365
+ */
6366
+ function followUpLines(text, room, glyph) {
6367
+ return wrapTextWithAnsi(text, Math.max(1, room - visibleWidth(FOLLOW_UP_PREFIX))).map((line, index) => index === 0 ? `${glyph} ${line}` : `${FOLLOW_UP_INDENT}${line}`);
6368
+ }
6369
+ /**
6370
+ * Render the pending prompts as a boxed follow-ups list. A focused panel
6371
+ * accents its held row and names enter, select/edit, and cancel; an unfocused
6372
+ * panel names the key that enters it.
6198
6373
  * @param rows - pending prompts in claim order.
6199
6374
  * @param render - palette, terminal width, and optional selection.
6200
6375
  * @returns panel text, or the empty string when no prompt waits.
@@ -6204,23 +6379,19 @@ function renderQueuePanel(rows, render) {
6204
6379
  const { palette, selected } = render;
6205
6380
  const width = Math.max(1, render.width);
6206
6381
  const tone = selected === void 0 ? "muted" : "focus";
6207
- const title = `${String(rows.length)} pending`;
6208
- const lines = [topRule({
6209
- chip: chip(palette, "QUEUE"),
6210
- title: palette.bold(title),
6382
+ const lines = [tone === "focus" ? palette.accent("follow-ups") : palette.dim("follow-ups"), topRule({
6211
6383
  width,
6212
6384
  palette,
6213
6385
  tone
6214
6386
  })];
6215
6387
  const room = Math.max(1, width - 2);
6216
6388
  for (const [index, row] of rows.entries()) {
6217
- const label = row.target === "next-step" ? "next step" : "next turn";
6218
- const text = `${selected === index ? palette.accent("▸ ") : " "}${palette.dim(`${label} ·`)} ${row.text}`;
6219
- for (const wrapped of wrapTextWithAnsi(text, room)) lines.push(bodyLine(wrapped, width, palette, tone));
6389
+ const glyph = selected === index ? palette.accent(FOLLOW_UP_GLYPH) : FOLLOW_UP_GLYPH;
6390
+ for (const content of followUpLines(row.text, room, glyph)) lines.push(bodyLine(content, width, palette, tone));
6220
6391
  }
6221
- const hints = selected === void 0 ? ["Shift+↓ manages"] : HINTS.queue;
6392
+ const hints = selected === void 0 ? ["shift+↓ select"] : HINTS.queue;
6393
+ lines.push(bodyLine(palette.dim(fitLegend(hints, room)), width, palette, tone));
6222
6394
  lines.push(bottomRule({
6223
- left: palette.dim(fitLegend(hints, ruleRoom(width))),
6224
6395
  width,
6225
6396
  palette,
6226
6397
  tone
@@ -7183,8 +7354,8 @@ function paneIntent(data) {
7183
7354
  * have, correct it when it lands" the rest of this surface uses.
7184
7355
  *
7185
7356
  * Colours come from a shiki theme rather than the palette: a theme
7186
- * distinguishes a keyword from a type from a number, which the nine palette
7187
- * roles cannot, and the transcript is where the model's code is read. The
7357
+ * distinguishes a keyword from a type from a number, which the palette's
7358
+ * structural roles cannot, and the transcript is where the model's code is read. The
7188
7359
  * theme is chosen from the terminal's own background, so a light terminal is
7189
7360
  * not given dark-theme colours, and a terminal that answers neither a colour
7190
7361
  * depth nor a background gets no colour at all.
@@ -8141,6 +8312,11 @@ const LOCAL_COMMANDS = [
8141
8312
  name: "effort",
8142
8313
  description: "Pick the current model's reasoning effort for the next request (/effort <id>, /effort default)"
8143
8314
  },
8315
+ {
8316
+ name: "permission",
8317
+ description: "Pick the permission preset (/permission <preset>)",
8318
+ hint: "<preset>"
8319
+ },
8144
8320
  {
8145
8321
  name: "sessions",
8146
8322
  description: "Switch to another session"
@@ -8238,6 +8414,8 @@ const LOCAL_COMMANDS = [
8238
8414
  description: "Same as /quit"
8239
8415
  }
8240
8416
  ];
8417
+ /** Names the terminal handles before the shared registry, used to hide the matching catalog row. */
8418
+ const LOCAL_COMMAND_NAMES = new Set(LOCAL_COMMANDS.map((command) => command.name));
8241
8419
  /**
8242
8420
  * Whether a sign-in method is a provider subscription rather than a key field.
8243
8421
  * `api-key` is the id a key-collecting login registers under; every other id
@@ -8246,6 +8424,10 @@ const LOCAL_COMMANDS = [
8246
8424
  function isSubscriptionMethod(method) {
8247
8425
  return method.id !== "api-key";
8248
8426
  }
8427
+ /** Shown when `!` is submitted and this composition has no `ctx.shell`. */
8428
+ const SHELL_MISSING = "! needs a shell executor in this composition";
8429
+ /** Shown when a second `!` is submitted while one is still running. */
8430
+ const SHELL_BUSY = "A shell command is already running. Press Esc to cancel it first.";
8249
8431
  /** The interactive terminal application; one instance per process. */
8250
8432
  var TuiApp = class {
8251
8433
  deps;
@@ -8355,6 +8537,8 @@ var TuiApp = class {
8355
8537
  escapeQuietUntil = 0;
8356
8538
  /** Until when a second editor `Escape` stops the running turn. */
8357
8539
  stopArmedUntil = 0;
8540
+ /** Abort of the in-flight user `!` command, when one is running. */
8541
+ shellAbort;
8358
8542
  /**
8359
8543
  * How many of the viewport's own first lines the renderer can no longer
8360
8544
  * repaint, from the last frame the guard settled. The transient line
@@ -8423,6 +8607,9 @@ var TuiApp = class {
8423
8607
  this.editor.onSubmit = (text) => {
8424
8608
  this.onSubmit(text);
8425
8609
  };
8610
+ this.editor.onChange = () => {
8611
+ this.syncEditorBorder();
8612
+ };
8426
8613
  this.queue = new Text("", 0, 0);
8427
8614
  this.panel = new Text("", 0, 0);
8428
8615
  this.footer = new FooterBar(() => ({
@@ -8544,6 +8731,7 @@ var TuiApp = class {
8544
8731
  /** Release the terminal and tell the host to exit; later calls are no-ops. */
8545
8732
  stop() {
8546
8733
  if (this.stopped) return;
8734
+ this.dropUserShell();
8547
8735
  this.restoreQueueDraft();
8548
8736
  this.stopped = true;
8549
8737
  this.updateTicker();
@@ -8561,6 +8749,7 @@ var TuiApp = class {
8561
8749
  }
8562
8750
  /** Draw `next` as the terminal's session: clear the transcript and replay its history. */
8563
8751
  bind(next) {
8752
+ this.dropUserShell();
8564
8753
  if (this.queueDraft !== void 0) {
8565
8754
  this.restoreQueueDraft();
8566
8755
  this.editor.setText("");
@@ -8637,7 +8826,7 @@ var TuiApp = class {
8637
8826
  }
8638
8827
  }
8639
8828
  completableCommands() {
8640
- const shared = this.deps.ctx.get("commands")?.list(this.agent) ?? [];
8829
+ const shared = (this.deps.ctx.get("commands")?.list(this.agent) ?? []).filter((command) => !LOCAL_COMMAND_NAMES.has(command.name));
8641
8830
  return [...LOCAL_COMMANDS, ...shared.map((command) => ({
8642
8831
  name: command.name,
8643
8832
  description: command.description,
@@ -8727,7 +8916,7 @@ var TuiApp = class {
8727
8916
  this.tui.requestRender();
8728
8917
  }
8729
8918
  /**
8730
- * Redraw the queued prompts above the editor from the bound Agent's inbox.
8919
+ * Redraw the follow-ups list above the editor from the bound Agent's inbox.
8731
8920
  * The slot is mounted exactly while a prompt waits, so the editor sits
8732
8921
  * directly under the conversation the rest of the time.
8733
8922
  */
@@ -9033,7 +9222,8 @@ var TuiApp = class {
9033
9222
  */
9034
9223
  async browseTodos() {
9035
9224
  const items = this.statusFacts().todos?.items ?? [];
9036
- const choices = listTodoChoices(this.deps.ctx, this.agent.session);
9225
+ const { palette } = this.deps;
9226
+ const choices = listTodoChoices(this.deps.ctx, this.agent.session, (content) => palette.dim(palette.strikethrough(content)));
9037
9227
  if (choices.length === 0) {
9038
9228
  this.notice("no todos yet");
9039
9229
  return;
@@ -9321,7 +9511,17 @@ var TuiApp = class {
9321
9511
  const now = this.deps.now();
9322
9512
  if (now < this.escapeQuietUntil) return { consume: true };
9323
9513
  if (this.editor.isShowingAutocomplete()) return void 0;
9324
- if (this.agent.status !== "running") return { consume: true };
9514
+ if (this.shellAbort !== void 0) {
9515
+ this.shellAbort.abort();
9516
+ return { consume: true };
9517
+ }
9518
+ if (this.agent.status !== "running") {
9519
+ if (this.editor.getText().trimStart().startsWith("!")) {
9520
+ this.editor.setText("");
9521
+ this.syncEditorBorder();
9522
+ }
9523
+ return { consume: true };
9524
+ }
9325
9525
  if (now >= this.stopArmedUntil) {
9326
9526
  this.stopArmedUntil = now + this.showToast(stopTurnToast(this.turn));
9327
9527
  return { consume: true };
@@ -9900,8 +10100,8 @@ var TuiApp = class {
9900
10100
  this.tui.requestRender();
9901
10101
  }
9902
10102
  /**
9903
- * Handle a submitted editor line: a `/` line runs a command, anything else
9904
- * becomes a user message.
10103
+ * Handle a submitted editor line: a `/` line runs a command, a nonempty `!`
10104
+ * / `!!` line runs in the terminal, and anything else becomes a user message.
9905
10105
  * @param raw - the editor text.
9906
10106
  * @param mode - how a message reaches a running Agent: `queue` waits for the next turn, `steer` enters the current one.
9907
10107
  */
@@ -9920,6 +10120,11 @@ var TuiApp = class {
9920
10120
  this.dispatchCommand(text);
9921
10121
  return;
9922
10122
  }
10123
+ const shell = draft === void 0 ? parseUserShellLine(text) : void 0;
10124
+ if (shell !== void 0) {
10125
+ this.runUserShell(shell.command, shell.excluded);
10126
+ return;
10127
+ }
9923
10128
  this.submit(text, mode, draft);
9924
10129
  }
9925
10130
  /**
@@ -9933,6 +10138,100 @@ var TuiApp = class {
9933
10138
  this.notice(`${name} failed: ${describeFailure(error)}`, "error");
9934
10139
  });
9935
10140
  }
10141
+ /**
10142
+ * Run one user-typed shell command in this process and, unless it was `!!`,
10143
+ * inject the result as next-step context for the next admitted request.
10144
+ * @param command - the text after `!` / `!!`.
10145
+ * @param excluded - true when the line used `!!`.
10146
+ */
10147
+ async runUserShell(command, excluded) {
10148
+ if (this.shellAbort !== void 0) {
10149
+ this.notice(SHELL_BUSY, "error");
10150
+ this.editor.setText(excluded ? `!!${command}` : `!${command}`);
10151
+ this.syncEditorBorder();
10152
+ return;
10153
+ }
10154
+ const shell = this.deps.ctx.get("shell");
10155
+ if (shell === void 0) {
10156
+ this.notice(SHELL_MISSING, "error");
10157
+ return;
10158
+ }
10159
+ /* v8 ignore next -- TUI sessions record cwd on create; process cwd is the fallback when a header omitted it */
10160
+ const workdir = this.agent.session.header.cwd ?? this.deps.cwd;
10161
+ const controller = new AbortController();
10162
+ this.shellAbort = controller;
10163
+ try {
10164
+ const result = await shell.run(shell.resolve({
10165
+ command,
10166
+ workdir,
10167
+ signal: controller.signal,
10168
+ sandboxPolicy: {
10169
+ mode: "danger-full-access",
10170
+ workspaceRoot: workdir,
10171
+ sessionId: this.agent.session.id
10172
+ }
10173
+ }));
10174
+ if (!this.userShellCurrent(controller)) return;
10175
+ this.showUserShell(command, result, excluded);
10176
+ } catch (error) {
10177
+ if (!this.userShellCurrent(controller)) return;
10178
+ this.notice(`! failed: ${describeFailure(error)}`, "error");
10179
+ } finally {
10180
+ if (this.shellAbort === controller) this.shellAbort = void 0;
10181
+ }
10182
+ }
10183
+ /**
10184
+ * Whether `controller` is still the in-flight user-shell run on this bound
10185
+ * session. Bind and quit drop the controller so a late settle cannot draw or
10186
+ * inject into the next session.
10187
+ * @param controller - the AbortController created for this run.
10188
+ * @returns true while this run still owns `shellAbort` and the app is up.
10189
+ */
10190
+ userShellCurrent(controller) {
10191
+ return !this.stopped && this.shellAbort === controller;
10192
+ }
10193
+ /**
10194
+ * Detach and abort the in-flight user-shell run, if any. A late settle then
10195
+ * sees a different controller (or a stopped app) and stays silent.
10196
+ */
10197
+ dropUserShell() {
10198
+ const running = this.shellAbort;
10199
+ this.shellAbort = void 0;
10200
+ running?.abort();
10201
+ }
10202
+ /**
10203
+ * Draw one finished user shell run and inject the model-facing notice.
10204
+ * @param command - the text after `!` / `!!`.
10205
+ * @param result - the completed foreground run.
10206
+ * @param excluded - true when the line used `!!`.
10207
+ */
10208
+ showUserShell(command, result, excluded) {
10209
+ this.showBlock(userShellTranscriptRows(command, result));
10210
+ if (excluded) return;
10211
+ const message = createUserMessage({
10212
+ content: [{
10213
+ type: "text",
10214
+ text: userShellContextText(command, result)
10215
+ }],
10216
+ source: {
10217
+ kind: "plugin",
10218
+ plugin: "tui-app",
10219
+ form: "notice",
10220
+ summary: boundContextSummary(`! ${command}`)
10221
+ }
10222
+ });
10223
+ this.submittedIds.add(message.id);
10224
+ this.agent.inject(message);
10225
+ this.refreshQueue();
10226
+ }
10227
+ /**
10228
+ * Recolor the editor border while the draft starts with `!`.
10229
+ */
10230
+ syncEditorBorder() {
10231
+ const palette = this.deps.palette;
10232
+ this.editor.borderColor = this.editor.getText().trimStart().startsWith("!") ? palette.warning : palette.dim;
10233
+ this.tui.requestRender();
10234
+ }
9936
10235
  /** Return an abandoned edit to the ordinary-turn inbox without waking the Agent. */
9937
10236
  restoreQueueDraft() {
9938
10237
  const draft = this.queueDraft;
@@ -9996,6 +10295,9 @@ var TuiApp = class {
9996
10295
  case "effort":
9997
10296
  await this.runCurrentEffort(argument);
9998
10297
  return;
10298
+ case "permission":
10299
+ await this.choosePermission(argument);
10300
+ return;
9999
10301
  case "sessions":
10000
10302
  case "resume":
10001
10303
  await this.openSessionPicker();
@@ -10332,6 +10634,57 @@ var TuiApp = class {
10332
10634
  this.notice(effort === void 0 ? "effort: provider default from the next request" : `effort ${effort} from the next request`, "success");
10333
10635
  this.refreshFooter();
10334
10636
  }
10637
+ /**
10638
+ * Choose the bound session's permission preset: an empty argument opens
10639
+ * the picker on the preset in force, and anything else names a catalog
10640
+ * value. A pick submits `/permission <preset>` when the shared command
10641
+ * exists, the same write path the browser uses.
10642
+ * @param argument - a catalog value, or empty for the picker.
10643
+ */
10644
+ async choosePermission(argument) {
10645
+ const presets = this.deps.ctx.get("permissionPresets");
10646
+ if (presets === void 0) {
10647
+ this.notice("no permission service is composed", "error");
10648
+ return;
10649
+ }
10650
+ const options = presets.catalog().options;
10651
+ if (argument !== "") {
10652
+ const matched = matchPermission(options, argument);
10653
+ if (matched === null) {
10654
+ const available = options.map((option) => option.value).join(", ");
10655
+ this.notice(available === "" ? `unknown preset "${argument}"` : `unknown preset "${argument}" (available: ${available})`, "error");
10656
+ return;
10657
+ }
10658
+ await this.applyPermission(presets, matched);
10659
+ return;
10660
+ }
10661
+ if (options.length === 0) {
10662
+ this.notice("no selectable permission presets");
10663
+ return;
10664
+ }
10665
+ const current = presets.current(this.agent.session);
10666
+ const picked = await this.showModal(new PickPrompt(this.deps.palette, "Permission preset", permissionItems(options), {
10667
+ body: [permissionHint(options, current)],
10668
+ current
10669
+ }));
10670
+ if (picked === void 0) return;
10671
+ await this.applyPermission(presets, picked.value);
10672
+ }
10673
+ /**
10674
+ * Switch to `name` through the shared `/permission` command when a
10675
+ * registry is composed, otherwise through the permission service.
10676
+ * @param presets - the composed permission service.
10677
+ * @param name - a catalog value.
10678
+ */
10679
+ async applyPermission(presets, name) {
10680
+ if (this.deps.ctx.get("commands") !== void 0) {
10681
+ await this.runSharedCommand(`/permission ${name}`, "permission");
10682
+ return;
10683
+ }
10684
+ presets.set(this.agent.session, name);
10685
+ this.notice(`preset ${name}`, "success");
10686
+ this.refreshFooter();
10687
+ }
10335
10688
  async modelItems() {
10336
10689
  const llm = this.deps.ctx.get("llm");
10337
10690
  if (llm === void 0) return [];
@@ -10462,7 +10815,8 @@ var TuiApp = class {
10462
10815
  this.notice("queue cleared", "success");
10463
10816
  return;
10464
10817
  }
10465
- const rows = [...inbox.nextTurn.map((message) => `next turn: ${contentText(message.content)}`), ...inbox.nextStep.map((message) => `next step: ${contentText(message.content)}`)];
10818
+ const queued = (messages) => messages.filter((message) => message.source.kind === "user");
10819
+ const rows = [...queued(inbox.nextTurn).map((message) => `next turn: ${contentText(message.content)}`), ...queued(inbox.nextStep).map((message) => `next step: ${contentText(message.content)}`)];
10466
10820
  this.notice(rows.length === 0 ? "nothing is queued" : rows.join("\n"));
10467
10821
  }
10468
10822
  async showSkills() {
@@ -11008,9 +11362,9 @@ var TuiApp = class {
11008
11362
  this.todoTurns = tracked;
11009
11363
  }
11010
11364
  onUserMessage(message) {
11365
+ if (this.submittedIds.has(message.id)) return;
11011
11366
  const source = message.source;
11012
11367
  if (source.kind === "user") {
11013
- if (this.submittedIds.has(message.id)) return;
11014
11368
  const attachments = message.content.filter((block) => block.type !== "text").map((block) => `[${block.type}]`);
11015
11369
  this.chat.addChild(new UserBlock(this.theme, [contentText(message.content), ...attachments].filter((part) => part !== "").join("\n"), this.turn));
11016
11370
  return;