@aiwayds/dsh-opentui 0.23.0 → 0.23.2

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.
@@ -50401,6 +50401,8 @@ function Transcript(props) {
50401
50401
  const color = {
50402
50402
  text: () => theme?.text.base ?? "#e6e6e6",
50403
50403
  user: () => theme?.text.action.primary.base ?? "#7aa2f7",
50404
+ userBorder: () => theme?.hue.interactive[400] ?? unfocusedBorderColor(theme),
50405
+ codeBorder: () => theme ? theme.increase(theme.markdown.code, 2) : undefined,
50404
50406
  reasoningBorder: () => theme?.border.base ?? "#565f89",
50405
50407
  done: () => theme?.text.feedback.success.base ?? "#9ece6a",
50406
50408
  running: () => theme?.text.feedback.warning.base ?? "#e0af68",
@@ -50428,7 +50430,7 @@ function Transcript(props) {
50428
50430
  cellPaddingX: 1
50429
50431
  });
50430
50432
  effect((_p$) => {
50431
- var _v$ = skinRenderNode(row.key, row.final, props.renderNode, renderer, theme?.border.base), _v$2 = row.text, _v$3 = !row.final, _v$4 = syntaxStyle(), _v$5 = color.text();
50433
+ var _v$ = skinRenderNode(row.key, row.final, props.renderNode, renderer, color.codeBorder()), _v$2 = row.text, _v$3 = !row.final, _v$4 = syntaxStyle(), _v$5 = color.text();
50432
50434
  _v$ !== _p$.e && (_p$.e = setProp(_el$2, "renderNode", _v$, _p$.e));
50433
50435
  _v$2 !== _p$.t && (_p$.t = setProp(_el$2, "content", _v$2, _p$.t));
50434
50436
  _v$3 !== _p$.a && (_p$.a = setProp(_el$2, "streaming", _v$3, _p$.a));
@@ -50479,7 +50481,7 @@ function Transcript(props) {
50479
50481
  return row.text;
50480
50482
  }
50481
50483
  }), null);
50482
- effect((_$p) => setProp(_el$3, "borderColor", unfocusedBorderColor(theme), _$p));
50484
+ effect((_$p) => setProp(_el$3, "borderColor", color.userBorder(), _$p));
50483
50485
  return _el$3;
50484
50486
  })();
50485
50487
  case "interrupted":
@@ -50757,7 +50759,7 @@ function requestEchoLine(text) {
50757
50759
  `)[0] ?? text;
50758
50760
  if (first.trim() === "")
50759
50761
  return;
50760
- return `\u25CF ${first}`;
50762
+ return `\uD83D\uDC64 ${first}`;
50761
50763
  }
50762
50764
  function childLineText(child, isLast, spin, width) {
50763
50765
  const track = isLast ? "\u2514\u2500 " : "\u251C\u2500 ";
@@ -50825,7 +50827,7 @@ function lastRequestLines(rows, request, width) {
50825
50827
  function LastRequestDock(props) {
50826
50828
  const dimensions = useTerminalSize();
50827
50829
  const theme = useThemeOptional();
50828
- const fgFor = (tone) => tone === "running" ? theme?.text.feedback.warning.base ?? "#e0af68" : theme?.text.muted ?? "#9aa5ce";
50830
+ const fgFor = (tone) => tone === "running" ? theme?.text.feedback.warning.base ?? "#e0af68" : theme?.text.base ?? "#e6e6e6";
50829
50831
  const contentWidth = () => Math.max(16, dimensions().width - 1);
50830
50832
  const lineWidth = (line) => Math.max(1, contentWidth() - (line.indent ?? 0));
50831
50833
  const lines = () => lastRequestLines(props.rows, props.lastRequest, contentWidth()).filter((line) => line.id === "lr:echo");
@@ -52075,2281 +52077,2322 @@ var init_pane_focus = __esm(() => {
52075
52077
  init_keymap();
52076
52078
  });
52077
52079
 
52078
- // ../tui-base/src/routes/session/turn-cancel.tsx
52079
- function armNonArmingInterrupt() {
52080
- nonArmingInterrupt = true;
52081
- }
52082
- function consumeNonArmingInterrupt() {
52083
- const armed = nonArmingInterrupt;
52084
- nonArmingInterrupt = false;
52085
- return armed;
52080
+ // ../tui-base/src/routes/session/ask-keys.ts
52081
+ function printableText(event) {
52082
+ const text = event.sequence;
52083
+ if (text.length !== 1)
52084
+ return;
52085
+ if (event.ctrl || event.meta || event.super === true || event.hyper === true)
52086
+ return;
52087
+ if (text === " ")
52088
+ return;
52089
+ if (text >= "0" && text <= "9")
52090
+ return;
52091
+ const code = text.codePointAt(0) ?? 0;
52092
+ if (code < 32 || code === 127)
52093
+ return;
52094
+ return text;
52086
52095
  }
52087
- function createCtrlCGate(windowMs = CTRL_C_QUIT_WINDOW_MS, now = Date.now) {
52088
- let armedAt;
52089
- return {
52090
- press() {
52091
- const t = now();
52092
- if (armedAt !== undefined && t - armedAt <= windowMs) {
52093
- armedAt = undefined;
52094
- return "quit";
52095
- }
52096
- armedAt = t;
52097
- return "arm";
52098
- },
52099
- reset() {
52100
- armedAt = undefined;
52101
- }
52096
+ function useAskKeys(options) {
52097
+ const keymap = Keymap2.useOptional();
52098
+ if (keymap === undefined)
52099
+ return;
52100
+ const renderer = useRenderer();
52101
+ const ownership = useInputOwnershipOptional();
52102
+ const ownsDock = () => ownership === undefined || ownership.top().kind === "dock";
52103
+ const ask = () => options.controller.pendingAsk;
52104
+ const question = () => {
52105
+ const batch = ask();
52106
+ return batch?.questions[batch.index];
52102
52107
  };
52103
- }
52104
- function createTurnCancel(props, onArm) {
52105
- const windowMs = props.windowMs ?? CTRL_C_QUIT_WINDOW_MS;
52106
- const gate = createCtrlCGate(windowMs);
52107
- let timer;
52108
- let armedKey;
52109
- const disarm = () => {
52110
- if (timer)
52111
- clearTimeout(timer);
52112
- timer = undefined;
52113
- const key = armedKey;
52114
- armedKey = undefined;
52115
- if (key)
52116
- onArm(false, key);
52108
+ const needsReview = () => askNeedsReview(ask()?.questions ?? []);
52109
+ const currentRow = () => {
52110
+ const batch = ask();
52111
+ return batch === undefined ? 0 : batch.cursors[batch.index] ?? 0;
52117
52112
  };
52118
- const arm = (key, beforeExpire) => {
52119
- if (timer)
52120
- clearTimeout(timer);
52121
- armedKey = key;
52122
- onArm(true, key);
52123
- timer = setTimeout(() => {
52124
- timer = undefined;
52125
- beforeExpire?.();
52126
- disarm();
52127
- }, windowMs);
52113
+ const inputFocused = () => {
52114
+ const input = options.input();
52115
+ return input !== undefined && renderer.currentFocusedRenderable === input;
52128
52116
  };
52129
- return {
52130
- escape() {
52131
- if (!props.busy() || props.escapeYields?.())
52132
- return false;
52133
- if (!props.confirmStop) {
52134
- props.interrupt();
52117
+ onCleanup(keymap.intercept("key", ({ event }) => {
52118
+ if (!ownsDock())
52119
+ return;
52120
+ const batch = ask();
52121
+ if (batch === undefined || batch.phase !== "questions")
52122
+ return;
52123
+ if (printableText(event) === undefined)
52124
+ return;
52125
+ options.controller.focusInput();
52126
+ options.input()?.focus();
52127
+ }));
52128
+ function move(delta) {
52129
+ const batch = ask();
52130
+ if (batch === undefined)
52131
+ return false;
52132
+ if (batch.phase === "review") {
52133
+ options.controller.moveReviewCursor(delta);
52134
+ return true;
52135
+ }
52136
+ if (batch.phase === "input")
52137
+ return false;
52138
+ options.controller.moveCursor(delta);
52139
+ return true;
52140
+ }
52141
+ function page(direction) {
52142
+ return move(direction * ASK_PAGE_ROWS);
52143
+ }
52144
+ function boundary(toEnd) {
52145
+ const batch = ask();
52146
+ if (batch === undefined)
52147
+ return false;
52148
+ if (batch.phase === "review") {
52149
+ options.controller.setReviewCursor(toEnd ? batch.questions.length : 0);
52150
+ return true;
52151
+ }
52152
+ if (batch.phase === "input")
52153
+ return false;
52154
+ const current = question();
52155
+ if (current === undefined)
52156
+ return false;
52157
+ options.controller.setCursor(toEnd ? questionRowCount(current, needsReview()) - 1 : 0);
52158
+ return true;
52159
+ }
52160
+ function switchQuestion(direction) {
52161
+ const batch = ask();
52162
+ if (batch === undefined)
52163
+ return false;
52164
+ if (batch.phase === "input")
52165
+ return false;
52166
+ if (batch.phase === "review") {
52167
+ if (direction === -1) {
52168
+ options.controller.backToQuestions(batch.questions.length - 1);
52135
52169
  return true;
52136
52170
  }
52137
- if (armedKey === "escape") {
52138
- disarm();
52139
- props.confirmStop();
52171
+ return false;
52172
+ }
52173
+ if (batch.questions.length < 2)
52174
+ return false;
52175
+ options.controller.switchFocus(direction);
52176
+ return true;
52177
+ }
52178
+ function enter() {
52179
+ const batch = ask();
52180
+ if (batch === undefined)
52181
+ return false;
52182
+ if (batch.phase === "input")
52183
+ return false;
52184
+ if (batch.phase === "review") {
52185
+ const intent = reviewRowIntent(batch.reviewCursor, batch.questions.length);
52186
+ if (intent.kind === "submit") {
52187
+ options.controller.submit();
52140
52188
  return true;
52141
52189
  }
52142
- arm("escape");
52190
+ options.controller.backToQuestions(intent.question);
52143
52191
  return true;
52144
- },
52145
- ctrlC() {
52146
- if (armedKey === "escape")
52147
- disarm();
52148
- if (consumeNonArmingInterrupt() && props.busy()) {
52149
- props.interrupt();
52150
- return true;
52151
- }
52152
- if (gate.press() === "quit") {
52153
- disarm();
52154
- props.quit();
52192
+ }
52193
+ const current = question();
52194
+ if (current === undefined)
52195
+ return false;
52196
+ const row = currentRow();
52197
+ if (hasReviewRow(current, needsReview()) && row === current.options.length) {
52198
+ return options.controller.enterReview();
52199
+ }
52200
+ const option = current.options[row];
52201
+ if (option === undefined)
52202
+ return false;
52203
+ if (current.multiSelect === true)
52204
+ return options.controller.confirmQuestion();
52205
+ options.controller.toggle(option.label);
52206
+ return true;
52207
+ }
52208
+ function space() {
52209
+ const batch = ask();
52210
+ if (batch === undefined || batch.phase !== "questions")
52211
+ return false;
52212
+ const current = question();
52213
+ if (current === undefined || current.multiSelect !== true)
52214
+ return false;
52215
+ if (inputFocused())
52216
+ return false;
52217
+ const option = current.options[currentRow()];
52218
+ if (option === undefined)
52219
+ return false;
52220
+ options.controller.toggle(option.label);
52221
+ return true;
52222
+ }
52223
+ function digit(index) {
52224
+ const batch = ask();
52225
+ if (batch === undefined || batch.phase !== "questions")
52226
+ return false;
52227
+ if (inputFocused())
52228
+ return false;
52229
+ const option = question()?.options[index];
52230
+ if (option === undefined)
52231
+ return false;
52232
+ options.controller.toggle(option.label);
52233
+ return true;
52234
+ }
52235
+ function atOutermost(batch) {
52236
+ if (batch.phase === "review" || batch.index > 0)
52237
+ return false;
52238
+ if (batch.phase === "input")
52239
+ return (batch.questions[batch.index]?.options.length ?? 0) === 0;
52240
+ return true;
52241
+ }
52242
+ function backOut() {
52243
+ const batch = ask();
52244
+ if (batch === undefined)
52245
+ return false;
52246
+ if (batch.phase === "review") {
52247
+ options.controller.backToQuestions(batch.questions.length - 1);
52248
+ return true;
52249
+ }
52250
+ if (batch.phase === "input") {
52251
+ const current = batch.questions[batch.index];
52252
+ if (current !== undefined && current.options.length > 0) {
52253
+ options.controller.focusOptions();
52155
52254
  return true;
52156
52255
  }
52157
- if (props.busy())
52158
- props.interrupt();
52159
- arm("ctrl-c", () => gate.reset());
52256
+ }
52257
+ if (batch.index > 0) {
52258
+ options.controller.switchFocus(-1);
52160
52259
  return true;
52161
- },
52162
- dispose: disarm
52163
- };
52164
- }
52165
- function TurnCancelKeys(props) {
52166
- const theme = useThemeOptional();
52167
- const [armed, setArmed] = createSignal(undefined);
52168
- const cancel = createTurnCancel(props, (value, key) => setArmed(value ? key : undefined));
52169
- onCleanup(() => cancel.dispose());
52260
+ }
52261
+ options.controller.decline();
52262
+ return true;
52263
+ }
52264
+ function interrupt() {
52265
+ const batch = ask();
52266
+ if (batch === undefined)
52267
+ return false;
52268
+ if (atOutermost(batch))
52269
+ armNonArmingInterrupt();
52270
+ return backOut();
52271
+ }
52170
52272
  Keymap2.createLayer(() => ({
52171
52273
  mode: "global",
52172
- enabled: props.enabled(),
52173
- commands: [{
52174
- bind: "escape",
52175
- title: props.confirmStop ? "Stop current turn (press Esc twice)" : "Interrupt current turn",
52176
- group: "Session",
52177
- run: () => cancel.escape()
52178
- }, {
52179
- bind: "ctrl+c",
52180
- title: "Interrupt / quit (press twice)",
52181
- group: "Session",
52182
- run: () => cancel.ctrlC()
52183
- }]
52184
- }));
52185
- return createComponent2(Show, {
52186
- get when() {
52187
- return armed();
52188
- },
52189
- get children() {
52190
- var _el$ = createElement("box"), _el$2 = createElement("text");
52191
- insertNode(_el$, _el$2);
52192
- setProp(_el$, "height", 1);
52193
- setProp(_el$, "flexShrink", 0);
52194
- setProp(_el$, "paddingLeft", 1);
52195
- setProp(_el$2, "wrapMode", "none");
52196
- insert(_el$2, (() => {
52197
- var _c$ = memo2(() => armed() === "escape");
52198
- return () => _c$() ? t("turn.stop.escHint") : "Press Ctrl+C again to quit";
52199
- })());
52200
- effect((_$p) => setProp(_el$2, "fg", theme?.text.feedback.warning.base ?? "#e0af68", _$p));
52201
- return _el$;
52202
- }
52203
- });
52274
+ enabled: ownsDock,
52275
+ commands: [
52276
+ { bind: "up,ctrl+p", run: () => move(-1) },
52277
+ { bind: "down,ctrl+n", run: () => move(1) },
52278
+ { bind: "pageup", run: () => page(-1) },
52279
+ { bind: "pagedown", run: () => page(1) },
52280
+ { bind: "home", run: () => boundary(false) },
52281
+ { bind: "end", run: () => boundary(true) },
52282
+ { bind: "return", run: enter },
52283
+ { bind: "space", run: space },
52284
+ ...Array.from({ length: 9 }, (_, index) => ({
52285
+ bind: `${index + 1}`,
52286
+ enabled: () => !inputFocused(),
52287
+ run: () => digit(index)
52288
+ })),
52289
+ { bind: "left", run: () => switchQuestion(-1) },
52290
+ { bind: "right", run: () => switchQuestion(1) },
52291
+ { bind: "escape", run: backOut },
52292
+ { bind: "ctrl+c", run: interrupt }
52293
+ ]
52294
+ }));
52204
52295
  }
52205
- var CTRL_C_QUIT_WINDOW_MS = 500, nonArmingInterrupt = false;
52206
- var init_turn_cancel = __esm(() => {
52207
- init_index_bun();
52208
- init_index_bun();
52209
- init_index_bun();
52210
- init_index_bun();
52211
- init_index_bun();
52212
- init_index_bun();
52296
+ var ASK_PAGE_ROWS = 5;
52297
+ var init_ask_keys = __esm(() => {
52213
52298
  init_index_bun();
52214
52299
  init_server();
52215
52300
  init_keymap();
52216
- init_theme3();
52217
- init_i18n();
52301
+ init_input_ownership();
52302
+ init_ask_options();
52303
+ init_turn_cancel();
52218
52304
  });
52219
52305
 
52220
- // ../tui-base/src/routes/session/stop-all.ts
52221
- async function stopEverything(seam) {
52222
- const turn = seam.status?.().turn;
52223
- const parent = turn !== undefined && turn !== "idle";
52224
- if (parent)
52225
- seam.interrupt();
52226
- let children = 0;
52227
- for (const view of seam.subagentViews?.() ?? []) {
52228
- if (view.status !== "running" || !seam.interruptChild)
52229
- continue;
52230
- try {
52231
- await seam.interruptChild(view.id);
52232
- children++;
52233
- } catch {}
52306
+ // ../tui-base/src/routes/session/dock-host.tsx
52307
+ function firstFocusable(node) {
52308
+ if (node === undefined)
52309
+ return;
52310
+ for (const child of node.getChildren()) {
52311
+ if (child.focusable)
52312
+ return child;
52313
+ const nested = firstFocusable(child);
52314
+ if (nested !== undefined)
52315
+ return nested;
52234
52316
  }
52235
- return { parent, children };
52236
- }
52237
-
52238
- // ../tui-base/src/routes/session/turn-overlay-controller.ts
52239
- function askSignature(questions) {
52240
- return JSON.stringify(questions.map((question) => [
52241
- question.id,
52242
- question.prompt,
52243
- question.header,
52244
- question.description,
52245
- question.detail,
52246
- question.multiSelect === true,
52247
- question.options.map((option) => [option.label, option.description])
52248
- ]));
52317
+ return;
52249
52318
  }
52250
-
52251
- class TurnOverlayController {
52252
- #approvals = [];
52253
- #asks = [];
52254
- #seq = 0;
52255
- #listeners = new Set;
52256
- #idleHandlers = new Set;
52257
- #busy = false;
52258
- #pendingAsks;
52259
- subscribe(fn) {
52260
- this.#listeners.add(fn);
52261
- return () => this.#listeners.delete(fn);
52262
- }
52263
- attachPendingAsks(read) {
52264
- this.#pendingAsks = read;
52265
- }
52266
- invalidateAsk(eventId, reason) {
52267
- if (eventId === "")
52268
- return;
52269
- if (this.#approvals.some((entry) => entry.request.invalidatedReason !== undefined && entry.request.eventId === eventId))
52319
+ function DockProvider(props) {
52320
+ const renderer = useRenderer();
52321
+ const ownership = useInputOwnershipOptional();
52322
+ const [queue, setQueue] = createSignal([]);
52323
+ let frame;
52324
+ let composerFocus;
52325
+ let focusTarget;
52326
+ let cancelAfterLayout;
52327
+ const hasRequests = () => queue().length > 0;
52328
+ function afterLayout(callback) {
52329
+ cancelAfterLayout?.();
52330
+ if (renderer.isDestroyed)
52270
52331
  return;
52271
- this.#approvals = this.#approvals.filter((entry) => {
52272
- if (entry.request.eventId !== eventId)
52273
- return true;
52274
- entry.resolve("rejected");
52275
- return false;
52276
- });
52277
- this.#asks = this.#asks.filter((entry) => {
52278
- if (entry.eventId !== eventId)
52279
- return true;
52280
- entry.resolve([]);
52281
- return false;
52282
- });
52283
- this.#approvals.push({
52284
- request: {
52285
- id: ++this.#seq,
52286
- name: "ask",
52287
- args: {},
52288
- eventId,
52289
- escalation: false,
52290
- invalidatedReason: reason
52291
- },
52292
- resolve: () => {}
52332
+ let done = false;
52333
+ const handler = () => {
52334
+ if (done)
52335
+ return;
52336
+ done = true;
52337
+ renderer.off("frame", handler);
52338
+ if (cancelAfterLayout === cancel)
52339
+ cancelAfterLayout = undefined;
52340
+ callback();
52341
+ };
52342
+ const cancel = () => {
52343
+ if (done)
52344
+ return;
52345
+ done = true;
52346
+ renderer.off("frame", handler);
52347
+ if (cancelAfterLayout === cancel)
52348
+ cancelAfterLayout = undefined;
52349
+ };
52350
+ cancelAfterLayout = cancel;
52351
+ renderer.on("frame", handler);
52352
+ }
52353
+ function focusDock() {
52354
+ afterLayout(() => {
52355
+ if (!hasRequests())
52356
+ return;
52357
+ const target = focusTarget?.();
52358
+ if (target !== undefined) {
52359
+ target.focus();
52360
+ return;
52361
+ }
52362
+ renderer.currentFocusedRenderable?.blur();
52293
52363
  });
52294
- this.#changed();
52295
52364
  }
52296
- invalidateAll(reason) {
52297
- if (reason === "")
52365
+ function remove(entry) {
52366
+ const before = queue();
52367
+ if (!before.includes(entry))
52298
52368
  return;
52299
- const open = this.#approvals.length + this.#asks.length;
52300
- if (open === 0)
52369
+ const next = before.filter((item) => item !== entry);
52370
+ setQueue(next);
52371
+ if (next.length > 0) {
52372
+ if (before[0] !== next[0])
52373
+ focusDock();
52301
52374
  return;
52302
- const terminals = [];
52303
- for (const entry of this.#approvals) {
52304
- terminals.push({
52305
- request: {
52306
- id: ++this.#seq,
52307
- name: "ask",
52308
- args: {},
52309
- ...entry.request.eventId !== undefined ? { eventId: entry.request.eventId } : {},
52310
- escalation: false,
52311
- invalidatedReason: reason
52312
- },
52313
- resolve: () => {}
52314
- });
52315
52375
  }
52316
- for (const entry of this.#asks) {
52317
- terminals.push({
52318
- request: {
52319
- id: ++this.#seq,
52320
- name: "ask",
52321
- args: {},
52322
- ...entry.eventId !== undefined ? { eventId: entry.eventId } : {},
52323
- escalation: false,
52324
- invalidatedReason: reason
52325
- },
52326
- resolve: () => {}
52327
- });
52376
+ if (frame !== undefined) {
52377
+ ownership?.pop(frame);
52378
+ frame = undefined;
52328
52379
  }
52329
- for (const entry of this.#approvals)
52330
- entry.resolve("rejected");
52331
- for (const entry of this.#asks)
52332
- entry.resolve([]);
52333
- this.#approvals = terminals;
52334
- this.#asks = [];
52335
- this.#changed();
52380
+ afterLayout(() => {
52381
+ if (hasRequests())
52382
+ return;
52383
+ composerFocus?.();
52384
+ });
52336
52385
  }
52337
- pendingInvalidated() {
52338
- const out = new Map;
52339
- for (const entry of this.#approvals) {
52340
- if (entry.request.invalidatedReason !== undefined && entry.request.eventId !== undefined) {
52341
- out.set(entry.request.eventId, entry.request.invalidatedReason);
52386
+ const api = {
52387
+ open(render, options = {}) {
52388
+ const id = ++ordinal2;
52389
+ const entry = {
52390
+ id,
52391
+ kind: options.kind,
52392
+ options,
52393
+ close: () => remove(entry),
52394
+ render
52395
+ };
52396
+ const before = queue();
52397
+ setQueue([...before, entry]);
52398
+ if (before.length === 0) {
52399
+ frame = ownership?.push("dock");
52400
+ focusDock();
52342
52401
  }
52402
+ return {
52403
+ id,
52404
+ close: entry.close
52405
+ };
52406
+ },
52407
+ queueDepth: () => Math.max(0, queue().length - 1),
52408
+ isOpen: () => hasRequests(),
52409
+ currentKind: () => queue()[0]?.kind,
52410
+ current: () => queue()[0],
52411
+ bindComposerFocus(refocus) {
52412
+ composerFocus = refocus;
52413
+ },
52414
+ bindFocusTarget(resolve) {
52415
+ focusTarget = resolve;
52343
52416
  }
52344
- return out;
52345
- }
52346
- onIdle(fn) {
52347
- this.#idleHandlers.add(fn);
52348
- return () => this.#idleHandlers.delete(fn);
52349
- }
52350
- #changed() {
52351
- for (const listener of this.#listeners)
52352
- listener();
52353
- const busy = this.#approvals.length > 0 || this.#asks.length > 0;
52354
- if (this.#busy && !busy)
52355
- for (const handler of this.#idleHandlers)
52356
- handler();
52357
- this.#busy = busy;
52358
- }
52359
- get pendingApproval() {
52360
- return this.#approvals[0]?.request;
52361
- }
52362
- get pendingApprovalCount() {
52363
- return this.#approvals.length;
52364
- }
52365
- get pendingAskCount() {
52366
- return this.#asks.length;
52367
- }
52368
- requestApproval(name, args) {
52369
- const ask = this.#matchApproval(name, args);
52370
- const promise = new Promise((resolve) => {
52371
- this.#approvals.push({
52372
- request: {
52373
- id: ++this.#seq,
52374
- name,
52375
- args,
52376
- escalation: ask?.escalation === true,
52377
- ...ask !== undefined ? { eventId: ask.eventId } : {}
52378
- },
52379
- resolve
52380
- });
52381
- this.#changed();
52382
- });
52383
- return promise;
52384
- }
52385
- #matchApproval(name, args) {
52386
- const asks = (this.#pendingAsks?.() ?? []).filter((ask) => ask.kind === "approval");
52387
- if (asks.length === 0)
52388
- return;
52389
- const callId = typeof args.callId === "string" ? args.callId : undefined;
52390
- if (callId !== undefined) {
52391
- const byCall = asks.filter((ask) => ask.callId === callId);
52392
- return byCall.length > 0 ? byCall[byCall.length - 1] : undefined;
52393
- }
52394
- const reason = typeof args.reason === "string" ? args.reason : undefined;
52395
- const byName = asks.filter((ask) => (ask.toolName ?? "tool") === name && (reason === undefined || ask.reason === reason));
52396
- if (byName.length > 0)
52397
- return byName[byName.length - 1];
52398
- return asks.length === 1 ? asks[0] : undefined;
52399
- }
52400
- confirmApproval() {
52401
- this.#settleApproval("allowed-once");
52402
- }
52403
- rejectApproval() {
52404
- this.#settleApproval("rejected");
52405
- }
52406
- approveAlways() {
52407
- this.#settleEscalated("always");
52408
- }
52409
- approveSession() {
52410
- this.#settleEscalated("session");
52411
- }
52412
- #settleEscalated(verdict) {
52413
- if (this.#approvals[0]?.request.escalation !== true)
52414
- return;
52415
- this.#settleApproval(verdict);
52416
- }
52417
- #settleApproval(verdict) {
52418
- const head = this.#approvals.shift();
52419
- if (!head)
52420
- return;
52421
- head.resolve(verdict);
52422
- this.#changed();
52423
- }
52424
- syncPendingAsks() {
52425
- if (this.#pendingAsks === undefined)
52426
- return;
52427
- const asks = this.#pendingAsks();
52428
- let changed = false;
52429
- const approvalsBefore = this.#approvals.length;
52430
- this.#approvals = this.#approvals.filter((entry) => {
52431
- if (this.#approvalStillPending(entry.request, asks))
52432
- return true;
52433
- entry.resolve("rejected");
52434
- return false;
52435
- });
52436
- if (this.#approvals.length !== approvalsBefore)
52437
- changed = true;
52438
- const questionsBefore = this.#asks.length;
52439
- this.#asks = this.#asks.filter((entry) => {
52440
- if (this.#questionStillPending(entry, asks))
52441
- return true;
52442
- entry.resolve([]);
52443
- return false;
52444
- });
52445
- if (this.#asks.length !== questionsBefore)
52446
- changed = true;
52447
- if (changed)
52448
- this.#changed();
52449
- }
52450
- #approvalStillPending(request, asks) {
52451
- if (request.eventId !== undefined)
52452
- return asks.some((ask) => ask.eventId === request.eventId);
52453
- return asks.some((ask) => ask.kind === "approval");
52454
- }
52455
- #questionStillPending(entry, asks) {
52456
- if (entry.eventId !== undefined)
52457
- return asks.some((ask) => ask.eventId === entry.eventId);
52458
- return asks.some((ask) => ask.kind === "questions");
52459
- }
52460
- cancelAllApprovals() {
52461
- if (this.#approvals.length === 0)
52462
- return;
52463
- const entries = this.#approvals.splice(0);
52464
- for (const entry of entries)
52465
- entry.resolve("rejected");
52466
- this.#changed();
52467
- }
52468
- cancelAllAsks() {
52469
- if (this.#asks.length === 0)
52470
- return;
52471
- const entries = this.#asks.splice(0);
52472
- for (const entry of entries)
52473
- entry.resolve([]);
52474
- this.#changed();
52475
- }
52476
- get pendingAsk() {
52477
- const head = this.#asks[0];
52478
- if (!head)
52479
- return;
52480
- return {
52481
- id: head.id,
52482
- ...head.eventId !== undefined ? { eventId: head.eventId } : {},
52483
- questions: head.questions,
52484
- index: head.index,
52485
- picks: head.picks,
52486
- phase: head.phase,
52487
- customs: [...head.customs],
52488
- customDraft: head.customDrafts[head.index] ?? null,
52489
- cursors: [...head.cursors],
52490
- listCursors: [...head.listCursors],
52491
- reviewCursor: head.reviewCursor
52492
- };
52493
- }
52494
- get currentQuestion() {
52495
- const head = this.#asks[0];
52496
- return head?.questions[head.index];
52497
- }
52498
- #matchAsk(questions) {
52499
- const asks = (this.#pendingAsks?.() ?? []).filter((ask) => ask.kind === "questions");
52500
- if (asks.length === 0)
52501
- return;
52502
- const claimed = new Set(this.#asks.map((entry) => entry.eventId));
52503
- const available = asks.filter((ask) => !claimed.has(ask.eventId));
52504
- if (available.length === 0)
52505
- return;
52506
- const signature = askSignature(questions);
52507
- const exact = available.filter((ask) => askSignature(ask.questions ?? []) === signature);
52508
- if (exact.length > 0)
52509
- return exact[0];
52510
- return available.length === 1 ? available[0] : undefined;
52511
- }
52512
- answer(questions) {
52513
- if (questions.length === 0)
52514
- return Promise.resolve([]);
52515
- const ask = this.#matchAsk(questions);
52516
- return new Promise((resolve) => {
52517
- this.#asks.push({
52518
- id: ++this.#seq,
52519
- ...ask !== undefined ? { eventId: ask.eventId } : {},
52520
- questions,
52521
- index: 0,
52522
- picks: questions.map((question) => recommendedPicks(question)),
52523
- phase: questions[0]?.options.length === 0 ? "input" : "questions",
52524
- customs: questions.map(() => {
52525
- return;
52526
- }),
52527
- customDrafts: questions.map(() => null),
52528
- cursors: questions.map(() => 0),
52529
- listCursors: questions.map(() => 0),
52530
- reviewCursor: 0,
52531
- resolve
52532
- });
52533
- this.#changed();
52534
- });
52535
- }
52536
- toggle(option) {
52537
- const head = this.#asks[0];
52538
- const question = head?.questions[head.index];
52539
- if (!head || !question || head.phase === "review")
52540
- return;
52541
- if (head.phase === "input")
52542
- return;
52543
- head.customs[head.index] = undefined;
52544
- head.customDrafts[head.index] = null;
52545
- if (question.multiSelect === true) {
52546
- const current = head.picks[head.index] ?? [];
52547
- head.picks[head.index] = current.includes(option) ? current.filter((label) => label !== option) : [...current, option];
52548
- this.#changed();
52549
- return;
52550
- }
52551
- head.picks[head.index] = [option];
52552
- if (head.questions.length === 1) {
52553
- this.#asks.shift();
52554
- head.resolve(this.#envelope(head));
52555
- this.#changed();
52556
- return;
52417
+ };
52418
+ onCleanup(() => {
52419
+ cancelAfterLayout?.();
52420
+ if (frame !== undefined) {
52421
+ ownership?.pop(frame);
52422
+ frame = undefined;
52557
52423
  }
52558
- if (this.#allAnswered(head)) {
52559
- head.phase = "review";
52560
- head.reviewCursor = 0;
52561
- } else {
52562
- const next = head.questions.findIndex((_, qi) => qi > head.index && (head.picks[qi]?.length ?? 0) === 0 && !head.customs[qi]);
52563
- if (next >= 0)
52564
- head.index = next;
52565
- head.phase = head.questions[head.index]?.options.length === 0 ? "input" : "questions";
52566
- if (head.phase === "input") {
52567
- const question = head.questions[head.index];
52568
- if (question !== undefined) {
52569
- head.cursors[head.index] = inlineRowIndex(question, askNeedsReview(head.questions));
52570
- }
52571
- }
52424
+ setQueue([]);
52425
+ });
52426
+ return createComponent2(Context7.Provider, {
52427
+ value: api,
52428
+ get children() {
52429
+ return props.children;
52572
52430
  }
52573
- this.#changed();
52574
- }
52575
- switchFocus(direction) {
52576
- const head = this.#asks[0];
52577
- if (!head || head.phase === "review" || head.questions.length < 2)
52578
- return;
52579
- if (head.phase === "input" && (head.questions[head.index]?.options.length ?? 0) > 0)
52580
- return;
52581
- const next = Math.max(0, Math.min(head.questions.length - 1, head.index + direction));
52582
- if (next === head.index)
52583
- return;
52584
- head.index = next;
52585
- const question = head.questions[next];
52586
- head.phase = question?.options.length === 0 ? "input" : "questions";
52587
- if (head.phase === "input" && question !== undefined) {
52588
- head.cursors[next] = inlineRowIndex(question, askNeedsReview(head.questions));
52589
- }
52590
- this.#changed();
52591
- }
52592
- confirmQuestion() {
52593
- const head = this.#asks[0];
52594
- if (!head || head.phase === "review" || head.phase === "input")
52595
- return false;
52596
- const question = head.questions[head.index];
52597
- if (question === undefined || !askNeedsReview(head.questions))
52598
- return false;
52599
- const next = head.questions.findIndex((_, qi) => qi > head.index && (head.picks[qi]?.length ?? 0) === 0 && !head.customs[qi]);
52600
- if (next >= 0) {
52601
- head.index = next;
52602
- const target = head.questions[next];
52603
- head.phase = target?.options.length === 0 ? "input" : "questions";
52604
- if (head.phase === "input" && target !== undefined) {
52605
- head.cursors[next] = inlineRowIndex(target, askNeedsReview(head.questions));
52606
- }
52607
- } else {
52608
- head.phase = "review";
52609
- head.reviewCursor = 0;
52610
- }
52611
- this.#changed();
52612
- return true;
52613
- }
52614
- beginCustom() {
52615
- const head = this.#asks[0];
52616
- if (!head || head.phase === "review")
52617
- return false;
52618
- const question = head.questions[head.index];
52619
- head.customDrafts[head.index] = head.customs[head.index] ?? "";
52620
- head.phase = "input";
52621
- if (question !== undefined) {
52622
- head.cursors[head.index] = inlineRowIndex(question, askNeedsReview(head.questions));
52623
- }
52624
- this.#changed();
52625
- return true;
52626
- }
52627
- patchCustom(text) {
52628
- const head = this.#asks[0];
52629
- if (!head || head.customDrafts[head.index] === null)
52431
+ });
52432
+ }
52433
+ function useDock() {
52434
+ const value = useContext(Context7);
52435
+ if (!value)
52436
+ throw new Error("Dock.Provider is missing");
52437
+ return value;
52438
+ }
52439
+ function DockSeat(props) {
52440
+ const dock = useDock();
52441
+ const dimensions = useTerminalSize();
52442
+ const theme = useThemeOptional();
52443
+ let scroll;
52444
+ let body;
52445
+ let disposed = false;
52446
+ const [measured, setMeasured] = createSignal(undefined);
52447
+ const resolveFocus = () => {
52448
+ const designated = dock.current()?.options.focusRef?.();
52449
+ return designated ?? firstFocusable(body);
52450
+ };
52451
+ dock.bindFocusTarget(resolveFocus);
52452
+ onCleanup(() => {
52453
+ disposed = true;
52454
+ dock.bindFocusTarget(undefined);
52455
+ });
52456
+ const capRows = () => Math.max(1, Math.floor(dimensions().height * DOCK_MAX_ROWS_RATIO));
52457
+ const contentRows = () => measured() ?? dock.current()?.options.contentRows ?? capRows();
52458
+ const overflows = () => contentRows() > capRows() && capRows() > 1;
52459
+ const viewportRows = () => Math.max(1, Math.min(contentRows(), capRows() - (overflows() ? 1 : 0)));
52460
+ const hiddenRows = () => Math.max(0, contentRows() - viewportRows());
52461
+ const indicatorText = () => {
52462
+ const label = dock.current()?.options.overflowLabel;
52463
+ return label ? label(hiddenRows()) : `\u2191\u2193 ${hiddenRows()}`;
52464
+ };
52465
+ const muted = () => theme?.text.muted ?? "#9aa5ce";
52466
+ const background = () => theme?.background.base ?? "black";
52467
+ createEffect(on(() => dock.current()?.id, () => {
52468
+ if (scroll !== undefined && !scroll.isDestroyed)
52469
+ scroll.scrollTo(0);
52470
+ }, {
52471
+ defer: true
52472
+ }));
52473
+ createEffect(on(capRows, () => {
52474
+ if (scroll === undefined || scroll.isDestroyed)
52630
52475
  return;
52631
- head.customDrafts[head.index] = text;
52632
- this.#changed();
52476
+ scroll.afterLayout(() => {
52477
+ if (scroll === undefined || scroll.isDestroyed)
52478
+ return;
52479
+ const max = Math.max(0, scroll.scrollHeight - scroll.viewport.height);
52480
+ if (scroll.scrollTop > max)
52481
+ scroll.scrollTo(max);
52482
+ });
52483
+ }, {
52484
+ defer: true
52485
+ }));
52486
+ return (() => {
52487
+ var _el$ = createElement("box"), _el$2 = createElement("box");
52488
+ insertNode(_el$, _el$2);
52489
+ setProp(_el$, "width", "100%");
52490
+ setProp(_el$, "flexShrink", 0);
52491
+ setProp(_el$, "flexDirection", "column");
52492
+ setProp(_el$2, "width", "100%");
52493
+ setProp(_el$2, "flexShrink", 0);
52494
+ insert(_el$2, () => props.composer());
52495
+ insert(_el$, createComponent2(Show, {
52496
+ get when() {
52497
+ return dock.current();
52498
+ },
52499
+ children: (request) => (() => {
52500
+ var _el$3 = createElement("box"), _el$4 = createElement("scrollbox"), _el$5 = createElement("box");
52501
+ insertNode(_el$3, _el$4);
52502
+ setProp(_el$3, "width", "100%");
52503
+ setProp(_el$3, "flexShrink", 0);
52504
+ setProp(_el$3, "flexDirection", "column");
52505
+ insertNode(_el$4, _el$5);
52506
+ use((value) => {
52507
+ scroll = value;
52508
+ }, _el$4);
52509
+ setProp(_el$4, "width", "100%");
52510
+ setProp(_el$4, "flexShrink", 0);
52511
+ setProp(_el$4, "focusable", false);
52512
+ setProp(_el$4, "scrollY", true);
52513
+ setProp(_el$4, "scrollX", false);
52514
+ setProp(_el$4, "overflow", "hidden");
52515
+ setProp(_el$4, "verticalScrollbarOptions", {
52516
+ visible: false
52517
+ });
52518
+ use((value) => {
52519
+ body = value;
52520
+ }, _el$5);
52521
+ setProp(_el$5, "width", "100%");
52522
+ setProp(_el$5, "flexDirection", "column");
52523
+ setProp(_el$5, "onSizeChange", function() {
52524
+ if (disposed)
52525
+ return;
52526
+ const next = Math.max(0, Math.floor(this.height));
52527
+ if (next !== measured())
52528
+ setMeasured(next);
52529
+ });
52530
+ insert(_el$5, () => request().render({
52531
+ id: request().id,
52532
+ close: request().close,
52533
+ width: () => dimensions().width,
52534
+ maxHeight: capRows
52535
+ }));
52536
+ insert(_el$3, createComponent2(Show, {
52537
+ get when() {
52538
+ return memo2(() => !!overflows())() && hiddenRows() > 0;
52539
+ },
52540
+ get children() {
52541
+ var _el$6 = createElement("text");
52542
+ setProp(_el$6, "wrapMode", "none");
52543
+ setProp(_el$6, "paddingLeft", 1);
52544
+ insert(_el$6, indicatorText);
52545
+ effect((_$p) => setProp(_el$6, "fg", muted(), _$p));
52546
+ return _el$6;
52547
+ }
52548
+ }), null);
52549
+ effect((_p$) => {
52550
+ var _v$ = background(), _v$2 = viewportRows();
52551
+ _v$ !== _p$.e && (_p$.e = setProp(_el$3, "backgroundColor", _v$, _p$.e));
52552
+ _v$2 !== _p$.t && (_p$.t = setProp(_el$4, "height", _v$2, _p$.t));
52553
+ return _p$;
52554
+ }, {
52555
+ e: undefined,
52556
+ t: undefined
52557
+ });
52558
+ return _el$3;
52559
+ })()
52560
+ }), null);
52561
+ effect((_$p) => setProp(_el$2, "visible", !dock.isOpen(), _$p));
52562
+ return _el$;
52563
+ })();
52564
+ }
52565
+ var DOCK_MAX_ROWS_RATIO = 0.6, Context7, ordinal2 = 0;
52566
+ var init_dock_host = __esm(() => {
52567
+ init_index_bun();
52568
+ init_index_bun();
52569
+ init_index_bun();
52570
+ init_index_bun();
52571
+ init_index_bun();
52572
+ init_index_bun();
52573
+ init_index_bun();
52574
+ init_index_bun();
52575
+ init_server();
52576
+ init_index_bun();
52577
+ init_input_ownership();
52578
+ init_theme3();
52579
+ init_terminal_size();
52580
+ Context7 = createContext(undefined);
52581
+ });
52582
+
52583
+ // ../tui-base/src/routes/session/ask-panel.tsx
52584
+ function resolveFocus(ask, list, input) {
52585
+ if (ask === undefined)
52586
+ return;
52587
+ if (ask.phase === "input")
52588
+ return input;
52589
+ return list ?? input;
52590
+ }
52591
+ function nearestScroller(node) {
52592
+ let current = node;
52593
+ while (current !== null && current !== undefined) {
52594
+ const candidate = current;
52595
+ if (typeof candidate.scrollChildIntoView === "function")
52596
+ return current;
52597
+ current = current.parent;
52633
52598
  }
52634
- commitCustom() {
52635
- const head = this.#asks[0];
52636
- const question = head?.questions[head.index];
52637
- if (!head || !question)
52638
- return;
52639
- const draft = head.customDrafts[head.index] ?? null;
52640
- if (draft === null)
52641
- return;
52642
- const text = draft.trim();
52643
- head.customDrafts[head.index] = null;
52644
- if (text === "") {
52645
- this.#backToList(head);
52646
- this.#changed();
52647
- return;
52648
- }
52649
- head.customs[head.index] = text;
52650
- head.picks[head.index] = [];
52651
- if (question.multiSelect !== true && head.questions.length === 1) {
52652
- this.#asks.shift();
52653
- head.resolve(this.#envelope(head));
52654
- this.#changed();
52655
- return;
52656
- }
52657
- if (this.#allAnswered(head)) {
52658
- head.phase = "review";
52659
- head.reviewCursor = 0;
52660
- } else {
52661
- const next = head.questions.findIndex((_, qi) => qi > head.index && (head.picks[qi]?.length ?? 0) === 0 && !head.customs[qi]);
52662
- if (next >= 0)
52663
- head.index = next;
52664
- head.phase = head.questions[head.index]?.options.length === 0 ? "input" : "questions";
52665
- }
52666
- this.#changed();
52599
+ return;
52600
+ }
52601
+ function AskPanel(props) {
52602
+ const theme = useThemeOptional();
52603
+ const dock = useDock();
52604
+ let configCursorStyle;
52605
+ try {
52606
+ configCursorStyle = useCursorStyle();
52607
+ } catch {
52608
+ configCursorStyle = undefined;
52667
52609
  }
52668
- cancelCustomEdit() {
52669
- const head = this.#asks[0];
52670
- if (!head || head.customDrafts[head.index] === null)
52671
- return;
52672
- head.customDrafts[head.index] = null;
52673
- this.#backToList(head);
52674
- this.#changed();
52675
- }
52676
- get inlineText() {
52677
- const head = this.#asks[0];
52678
- if (!head)
52679
- return "";
52680
- const draft = head.customDrafts[head.index];
52681
- if (draft !== null && draft !== undefined)
52682
- return draft;
52683
- return head.customs[head.index] ?? "";
52684
- }
52685
- setInlineText(text) {
52686
- const head = this.#asks[0];
52687
- const question = head?.questions[head.index];
52688
- if (!head || !question || head.phase === "review")
52689
- return;
52690
- if ((head.customDrafts[head.index] ?? null) === null && text === "")
52610
+ const [version, setVersion] = createSignal(0);
52611
+ onMount(() => {
52612
+ const unsubscribe = props.controller.subscribe(() => setVersion((value) => value + 1));
52613
+ onCleanup(unsubscribe);
52614
+ });
52615
+ const ask = () => {
52616
+ version();
52617
+ return props.controller.pendingAsk;
52618
+ };
52619
+ const questions = () => ask()?.questions ?? [];
52620
+ const question = () => {
52621
+ const batch = ask();
52622
+ return batch?.questions[batch.index];
52623
+ };
52624
+ const index = () => ask()?.index ?? 0;
52625
+ const phase = () => ask()?.phase ?? "questions";
52626
+ const phaseOf = () => {
52627
+ if (phase() === "review")
52628
+ return "review";
52629
+ return phase() === "input" ? "input" : "options";
52630
+ };
52631
+ const picks = () => {
52632
+ const batch = ask();
52633
+ return batch ? batch.picks[batch.index] ?? [] : [];
52634
+ };
52635
+ const cursor = () => {
52636
+ const batch = ask();
52637
+ return batch ? batch.cursors[batch.index] ?? 0 : 0;
52638
+ };
52639
+ const listCursor = () => {
52640
+ const batch = ask();
52641
+ return batch ? batch.listCursors[batch.index] ?? 0 : 0;
52642
+ };
52643
+ const markedRow = () => phaseOf() === "input" ? listCursor() : cursor();
52644
+ const reviewCursor = () => ask()?.reviewCursor ?? 0;
52645
+ const multi = () => question()?.multiSelect === true;
52646
+ const compact = () => props.width() < ASK_COMPACT_COLUMNS;
52647
+ const needsReview = () => askNeedsReview(questions());
52648
+ const eyebrow = () => {
52649
+ if (phaseOf() === "review")
52691
52650
  return;
52692
- head.customDrafts[head.index] = text;
52693
- head.phase = "input";
52694
- head.cursors[head.index] = inlineRowIndex(question, askNeedsReview(head.questions));
52695
- this.#changed();
52696
- }
52697
- focusInput() {
52698
- const head = this.#asks[0];
52699
- const question = head?.questions[head.index];
52700
- if (!head || !question || head.phase === "review")
52651
+ const current = question();
52652
+ if (current?.header === undefined || current.header === current.prompt)
52701
52653
  return;
52702
- head.phase = "input";
52703
- head.cursors[head.index] = inlineRowIndex(question, askNeedsReview(head.questions));
52704
- this.#changed();
52705
- }
52706
- focusOptions() {
52707
- const head = this.#asks[0];
52708
- if (!head || head.phase !== "input")
52654
+ return current.header;
52655
+ };
52656
+ const muted = () => theme?.text.muted ?? "#9aa5ce";
52657
+ const faint = () => theme?.text.faint ?? "#565f89";
52658
+ const base = () => theme?.text.base ?? "#e6e6e6";
52659
+ const accent = () => theme?.hue.interactive[500] ?? "#7aa2f7";
52660
+ const currentBg = () => theme?.background.action.primary.focused;
52661
+ const currentFg = () => theme?.text.action.primary.focused ?? accent();
52662
+ const rule = () => theme?.border.base ?? "#565f89";
52663
+ const cursorShape = () => {
52664
+ try {
52665
+ return configCursorStyle?.()?.style;
52666
+ } catch {
52709
52667
  return;
52710
- this.#backToList(head);
52711
- this.#changed();
52712
- }
52713
- setCursor(row) {
52714
- const head = this.#asks[0];
52715
- const question = head?.questions[head.index];
52716
- if (!head || !question || head.phase === "review")
52668
+ }
52669
+ };
52670
+ let listEl;
52671
+ let inputEl;
52672
+ let inlineRowEl;
52673
+ useAskKeys({
52674
+ controller: props.controller,
52675
+ input: () => inputEl
52676
+ });
52677
+ const queuedCount = () => {
52678
+ version();
52679
+ return props.queued?.() ?? dock.queueDepth();
52680
+ };
52681
+ props.onFocusTarget?.(() => resolveFocus(ask(), listEl, inputEl));
52682
+ function revealRow(row) {
52683
+ if (row === undefined || row.isDestroyed)
52717
52684
  return;
52718
- const needsReview = askNeedsReview(head.questions);
52719
- const inline = inlineRowIndex(question, needsReview);
52720
- const next = Math.max(0, Math.min(inline, Math.floor(row)));
52721
- head.cursors[head.index] = next;
52722
- head.phase = next === inline ? "input" : "questions";
52723
- if (next !== inline)
52724
- head.listCursors[head.index] = next;
52725
- this.#changed();
52726
- }
52727
- moveCursor(delta) {
52728
- const head = this.#asks[0];
52729
- const question = head?.questions[head.index];
52730
- if (!head || !question || head.phase === "review")
52685
+ const scroller = nearestScroller(row);
52686
+ if (scroller === undefined)
52731
52687
  return;
52732
- const needsReview = askNeedsReview(head.questions);
52733
- const last = questionRowCount(question, needsReview) - 1;
52734
- const next = Math.max(0, Math.min(last, (head.cursors[head.index] ?? 0) + delta));
52735
- const inline = inlineRowIndex(question, needsReview);
52736
- head.cursors[head.index] = next;
52737
- head.phase = next === inline ? "input" : "questions";
52738
- if (next !== inline)
52739
- head.listCursors[head.index] = next;
52740
- this.#changed();
52688
+ scroller.scrollChildIntoView(row, {
52689
+ align: "nearest"
52690
+ });
52741
52691
  }
52742
- setReviewCursor(row) {
52743
- const head = this.#asks[0];
52744
- if (!head || head.phase !== "review")
52745
- return;
52746
- const next = Math.max(0, Math.min(head.questions.length, Math.floor(row)));
52747
- if (next === head.reviewCursor)
52692
+ function focusInputRow() {
52693
+ const input = inputEl;
52694
+ if (input === undefined || input.isDestroyed)
52748
52695
  return;
52749
- head.reviewCursor = next;
52750
- this.#changed();
52751
- }
52752
- moveReviewCursor(delta) {
52753
- this.setReviewCursor((this.#asks[0]?.reviewCursor ?? 0) + delta);
52696
+ input.focus();
52697
+ revealRow(inlineRowEl);
52754
52698
  }
52755
- #backToList(head) {
52756
- const question = head.questions[head.index];
52757
- if (question === undefined)
52758
- return;
52759
- if (question.options.length === 0) {
52760
- head.phase = "input";
52699
+ createEffect(on(() => phase(), (next) => {
52700
+ if (next === "input") {
52701
+ focusInputRow();
52761
52702
  return;
52762
52703
  }
52763
- head.phase = "questions";
52764
- const inline = inlineRowIndex(question, askNeedsReview(head.questions));
52765
- const row = Math.max(0, Math.min(inline - 1, head.listCursors[head.index] ?? 0));
52766
- head.cursors[head.index] = row;
52767
- head.listCursors[head.index] = row;
52768
- }
52769
- enterReview() {
52770
- const head = this.#asks[0];
52771
- if (!head || head.phase === "review")
52772
- return false;
52773
- if (!askNeedsReview(head.questions))
52774
- return false;
52775
- head.phase = "review";
52776
- head.reviewCursor = 0;
52777
- this.#changed();
52778
- return true;
52779
- }
52780
- backToQuestions(focus) {
52781
- const head = this.#asks[0];
52782
- if (!head || head.phase !== "review")
52704
+ if (next !== "questions")
52783
52705
  return;
52784
- head.phase = "questions";
52785
- if (focus !== undefined && focus >= 0 && focus < head.questions.length)
52786
- head.index = focus;
52787
- const question = head.questions[head.index];
52788
- if (question !== undefined && question.options.length === 0)
52789
- head.phase = "input";
52790
- this.#changed();
52791
- }
52792
- submit() {
52793
- const head = this.#asks[0];
52794
- if (!head)
52706
+ const focusList = () => {
52707
+ if (listEl !== undefined && !listEl.isDestroyed)
52708
+ listEl.focus();
52709
+ };
52710
+ if (listEl !== undefined && !listEl.isDestroyed)
52711
+ focusList();
52712
+ else
52713
+ queueMicrotask(focusList);
52714
+ }));
52715
+ createEffect(on(() => index(), () => phase() === "input" ? focusInputRow() : undefined, {
52716
+ defer: true
52717
+ }));
52718
+ createEffect(on([() => index(), cursor], () => {
52719
+ if (phaseOf() !== "options")
52795
52720
  return;
52796
- this.#asks.shift();
52797
- head.resolve(this.#envelope(head));
52798
- this.#changed();
52799
- }
52800
- #allAnswered(head) {
52801
- return head.questions.every((_, qi) => (head.picks[qi]?.length ?? 0) > 0 || head.customs[qi] !== undefined && head.customs[qi] !== "");
52802
- }
52803
- #envelope(head) {
52804
- return head.questions.map((question, qi) => {
52805
- const custom = head.customs[qi];
52806
- if (custom !== undefined && custom !== "") {
52807
- return { questionId: question.id, selected: "", custom };
52808
- }
52809
- const picks = head.picks[qi] ?? [];
52810
- return {
52811
- questionId: question.id,
52812
- selected: picks[0] ?? "",
52813
- ...picks.length > 1 ? { selections: [...picks] } : {}
52814
- };
52721
+ revealRow(listEl?.getChildren()[cursor()]);
52722
+ }));
52723
+ const optionRows = () => (question()?.options ?? []).map((option, position) => ({
52724
+ option,
52725
+ number: position + 1,
52726
+ selected: picks().includes(option.label)
52727
+ }));
52728
+ const labelColumn = (row) => GUTTER + CURSOR_CELLS + STATE_CELLS + `${row.number}. `.length;
52729
+ const footerHint = () => {
52730
+ if (phaseOf() === "review")
52731
+ return t("overlay.ask.footer.review", {
52732
+ esc: t("overlay.ask.esc.review")
52733
+ });
52734
+ if (phaseOf() === "input") {
52735
+ const escKey = question()?.options.length === 0 ? index() > 0 ? "overlay.ask.esc.prevQuestion" : "overlay.ask.esc.decline" : "overlay.ask.esc.back";
52736
+ return t("overlay.ask.footer.input", {
52737
+ esc: t(escKey)
52738
+ });
52739
+ }
52740
+ const escKey = questions().length > 1 && index() > 0 ? "overlay.ask.esc.prevQuestion" : "overlay.ask.esc.decline";
52741
+ return t(multi() ? "overlay.ask.footer.multi" : "overlay.ask.footer.options", {
52742
+ esc: t(escKey)
52815
52743
  });
52816
- }
52817
- decline() {
52818
- const head = this.#asks.shift();
52819
- if (!head)
52820
- return;
52821
- head.resolve([]);
52822
- this.#changed();
52823
- }
52824
- }
52825
- var init_turn_overlay_controller = __esm(() => {
52826
- init_ask_options();
52827
- });
52828
-
52829
- // ../tui-base/src/ui/dialog-confirm.tsx
52830
- import { TextAttributes as TextAttributes7 } from "@opentui/core";
52831
- function DialogConfirm(props) {
52832
- const dialog = useDialog();
52833
- const theme = useTheme().surface("dialog");
52834
- const newDesigns = useNewDesigns();
52835
- const row = () => currentRowColors(theme);
52836
- const [store, setStore] = createStore({
52837
- active: "confirm"
52838
- });
52839
- const choose = (key) => {
52840
- if (key === "confirm")
52841
- props.onConfirm?.();
52842
- if (key === "cancel")
52843
- props.onCancel?.();
52844
- dialog.clear();
52845
52744
  };
52846
- const chooseExtra = (action) => {
52847
- action.onTrigger();
52848
- dialog.clear();
52745
+ const answerText = (qi) => {
52746
+ const batch = ask();
52747
+ if (!batch)
52748
+ return "";
52749
+ const custom = batch.customs[qi];
52750
+ if (custom !== undefined && custom !== "")
52751
+ return custom;
52752
+ return (batch.picks[qi] ?? []).map((label) => splitRecommended(label).label).join(", ");
52849
52753
  };
52850
- Keymap2.createLayer(() => ({
52851
- mode: "modal",
52852
- commands: [...newDesigns() ? [{
52853
- bind: "return",
52854
- title: "Confirm",
52855
- group: "Dialog",
52856
- run: () => choose("confirm")
52857
- }, {
52858
- bind: "escape",
52859
- title: "Cancel",
52860
- group: "Dialog",
52861
- run: () => choose("cancel")
52862
- }] : [{
52863
- bind: "return",
52864
- title: "Confirm dialog selection",
52865
- group: "Dialog",
52866
- run: () => choose(store.active)
52867
- }, {
52868
- bind: "left",
52869
- title: "Previous dialog option",
52870
- group: "Dialog",
52871
- run: () => {
52872
- setStore("active", store.active === "confirm" ? "cancel" : "confirm");
52873
- }
52874
- }, {
52875
- bind: "right",
52876
- title: "Next dialog option",
52877
- group: "Dialog",
52878
- run: () => {
52879
- setStore("active", store.active === "confirm" ? "cancel" : "confirm");
52754
+ const reviewRowActive = (qi) => reviewCursor() === qi;
52755
+ const reviewSubmitActive = () => reviewRowIntent(reviewCursor(), questions().length).kind === "submit";
52756
+ return (() => {
52757
+ var _el$ = createElement("box"), _el$2 = createElement("box"), _el$3 = createElement("box"), _el$4 = createElement("text"), _el$1 = createElement("box"), _el$10 = createElement("text"), _el$12 = createElement("box");
52758
+ insertNode(_el$, _el$2);
52759
+ insertNode(_el$, _el$3);
52760
+ insertNode(_el$, _el$1);
52761
+ insertNode(_el$, _el$12);
52762
+ setProp(_el$, "flexDirection", "column");
52763
+ setProp(_el$, "width", "100%");
52764
+ setProp(_el$, "flexShrink", 0);
52765
+ setProp(_el$2, "width", "100%");
52766
+ setProp(_el$2, "flexShrink", 0);
52767
+ setProp(_el$2, "border", ["top"]);
52768
+ setProp(_el$2, "borderStyle", "single");
52769
+ insert(_el$, createComponent2(Show, {
52770
+ get when() {
52771
+ return eyebrow();
52772
+ },
52773
+ children: (header) => (() => {
52774
+ var _el$13 = createElement("box"), _el$14 = createElement("text");
52775
+ insertNode(_el$13, _el$14);
52776
+ setProp(_el$13, "paddingLeft", 2);
52777
+ setProp(_el$13, "paddingRight", 2);
52778
+ setProp(_el$14, "wrapMode", "none");
52779
+ insert(_el$14, header);
52780
+ effect((_$p) => setProp(_el$14, "fg", muted(), _$p));
52781
+ return _el$13;
52782
+ })()
52783
+ }), _el$3);
52784
+ insertNode(_el$3, _el$4);
52785
+ setProp(_el$3, "paddingLeft", 2);
52786
+ setProp(_el$3, "paddingRight", 2);
52787
+ setProp(_el$4, "wrapMode", "word");
52788
+ insert(_el$4, (() => {
52789
+ var _c$ = memo2(() => phaseOf() === "review");
52790
+ return () => _c$() ? t("overlay.ask.reviewTitle") : question()?.prompt ?? "";
52791
+ })());
52792
+ insert(_el$, createComponent2(Show, {
52793
+ get when() {
52794
+ return questions().length >= 2;
52795
+ },
52796
+ get children() {
52797
+ var _el$5 = createElement("box"), _el$6 = createElement("text");
52798
+ insertNode(_el$5, _el$6);
52799
+ setProp(_el$5, "paddingLeft", 2);
52800
+ setProp(_el$5, "paddingRight", 2);
52801
+ setProp(_el$6, "wrapMode", "none");
52802
+ insert(_el$6, () => askTabStrip(questions(), ask()?.picks ?? [], index(), ask()?.customs));
52803
+ effect((_$p) => setProp(_el$6, "fg", muted(), _$p));
52804
+ return _el$5;
52880
52805
  }
52881
- }], ...(props.extraActions ?? []).map((action) => ({
52882
- bind: action.bind,
52883
- title: action.title ?? action.label,
52884
- group: "Dialog",
52885
- run: () => chooseExtra(action)
52886
- }))]
52887
- }));
52888
- return createComponent2(DialogLayout, {
52889
- get header() {
52890
- return createComponent2(DialogHeader, {
52891
- get title() {
52892
- return props.title;
52893
- },
52894
- get titleView() {
52895
- return (() => {
52896
- var _el$2 = createElement("box"), _el$3 = createElement("text");
52897
- insertNode(_el$2, _el$3);
52898
- setProp(_el$2, "flexDirection", "row");
52899
- insert(_el$2, createComponent2(ReminderBadge, {}), _el$3);
52900
- setProp(_el$3, "wrapMode", "none");
52901
- insert(_el$3, () => props.title.replace(/^\u26A0\s*/, ""));
52902
- effect((_p$) => {
52903
- var _v$ = newDesigns() ? undefined : TextAttributes7.BOLD, _v$2 = theme.text.base;
52904
- _v$ !== _p$.e && (_p$.e = setProp(_el$3, "attributes", _v$, _p$.e));
52905
- _v$2 !== _p$.t && (_p$.t = setProp(_el$3, "fg", _v$2, _p$.t));
52906
- return _p$;
52907
- }, {
52908
- e: undefined,
52909
- t: undefined
52910
- });
52911
- return _el$2;
52912
- })();
52913
- }
52914
- });
52915
- },
52916
- get footer() {
52917
- return {
52918
- actions: {
52919
- secondary: (props.extraActions ?? []).map((action) => ({
52920
- title: action.label.toLowerCase(),
52921
- key: action.bind,
52922
- onTrigger: () => chooseExtra(action)
52923
- })),
52924
- primary: [
52925
- {
52926
- title: (props.label?.cancel ?? "cancel").toLowerCase(),
52927
- key: "esc",
52928
- onTrigger: () => choose("cancel")
52806
+ }), _el$1);
52807
+ insert(_el$, createComponent2(Show, {
52808
+ get when() {
52809
+ return memo2(() => phaseOf() !== "review")() ? question()?.detail : undefined;
52810
+ },
52811
+ children: (detail) => (() => {
52812
+ var _el$15 = createElement("box"), _el$16 = createElement("text");
52813
+ insertNode(_el$15, _el$16);
52814
+ setProp(_el$15, "paddingLeft", 2);
52815
+ setProp(_el$15, "paddingRight", 2);
52816
+ setProp(_el$16, "wrapMode", "word");
52817
+ insert(_el$16, detail);
52818
+ effect((_$p) => setProp(_el$16, "fg", muted(), _$p));
52819
+ return _el$15;
52820
+ })()
52821
+ }), _el$1);
52822
+ insert(_el$, createComponent2(Show, {
52823
+ get when() {
52824
+ return phaseOf() === "review";
52825
+ },
52826
+ get fallback() {
52827
+ return [(() => {
52828
+ var _el$17 = createElement("box");
52829
+ use((value) => {
52830
+ listEl = value;
52831
+ }, _el$17);
52832
+ setProp(_el$17, "flexDirection", "column");
52833
+ setProp(_el$17, "width", "100%");
52834
+ setProp(_el$17, "flexShrink", 0);
52835
+ setProp(_el$17, "focusable", true);
52836
+ insert(_el$17, createComponent2(Index, {
52837
+ get each() {
52838
+ return optionRows();
52929
52839
  },
52930
- {
52931
- title: (props.label?.confirm ?? "confirm").toLowerCase(),
52932
- key: "enter",
52933
- onTrigger: () => choose("confirm")
52840
+ children: (row, position) => createComponent2(OptionRow, {
52841
+ row,
52842
+ cursor: () => phaseOf() !== "input" && position === cursor(),
52843
+ marked: () => position === markedRow(),
52844
+ multi: () => multi(),
52845
+ compact: () => compact(),
52846
+ width: () => props.width(),
52847
+ labelColumn: () => labelColumn(row())
52848
+ })
52849
+ }), null);
52850
+ insert(_el$17, createComponent2(Show, {
52851
+ get when() {
52852
+ return memo2(() => question() !== undefined)() && hasReviewRow(question(), needsReview());
52853
+ },
52854
+ get children() {
52855
+ var _el$18 = createElement("box"), _el$19 = createElement("text"), _el$20 = createElement("text");
52856
+ insertNode(_el$18, _el$19);
52857
+ insertNode(_el$18, _el$20);
52858
+ setProp(_el$18, "flexDirection", "row");
52859
+ setProp(_el$18, "width", "100%");
52860
+ setProp(_el$18, "flexShrink", 0);
52861
+ setProp(_el$18, "paddingLeft", 2);
52862
+ insert(_el$19, () => markedRow() === (question()?.options.length ?? 0) ? "\u203A " : " ");
52863
+ setProp(_el$20, "wrapMode", "word");
52864
+ insert(_el$20, () => t("overlay.ask.reviewRow"));
52865
+ effect((_p$) => {
52866
+ var _v$8 = phaseOf() !== "input" && markedRow() === (question()?.options.length ?? 0) ? currentBg() : undefined, _v$9 = phaseOf() !== "input" && markedRow() === (question()?.options.length ?? 0) ? accent() : faint(), _v$0 = phaseOf() !== "input" && markedRow() === (question()?.options.length ?? 0) ? currentFg() : muted();
52867
+ _v$8 !== _p$.e && (_p$.e = setProp(_el$18, "backgroundColor", _v$8, _p$.e));
52868
+ _v$9 !== _p$.t && (_p$.t = setProp(_el$19, "fg", _v$9, _p$.t));
52869
+ _v$0 !== _p$.a && (_p$.a = setProp(_el$20, "fg", _v$0, _p$.a));
52870
+ return _p$;
52871
+ }, {
52872
+ e: undefined,
52873
+ t: undefined,
52874
+ a: undefined
52875
+ });
52876
+ return _el$18;
52934
52877
  }
52935
- ]
52936
- }
52937
- };
52938
- },
52939
- get legacyFooter() {
52940
- return (() => {
52941
- var _el$4 = createElement("box"), _el$5 = createElement("box"), _el$6 = createElement("box");
52942
- insertNode(_el$4, _el$5);
52943
- insertNode(_el$4, _el$6);
52944
- setProp(_el$4, "flexDirection", "row");
52945
- setProp(_el$4, "justifyContent", "space-between");
52946
- setProp(_el$4, "gap", 1);
52947
- setProp(_el$5, "flexDirection", "row");
52948
- insert(_el$5, createComponent2(For, {
52949
- get each() {
52950
- return props.extraActions ?? [];
52951
- },
52952
- children: (action) => (() => {
52953
- var _el$7 = createElement("box"), _el$8 = createElement("text");
52954
- insertNode(_el$7, _el$8);
52955
- setProp(_el$7, "paddingLeft", 1);
52956
- setProp(_el$7, "paddingRight", 1);
52957
- setProp(_el$7, "onMouseUp", () => chooseExtra(action));
52958
- insert(_el$8, () => `${action.label} [${action.bind}]`);
52959
- effect((_$p) => setProp(_el$8, "fg", theme.text.muted, _$p));
52960
- return _el$7;
52961
- })()
52962
- }));
52963
- setProp(_el$6, "flexDirection", "row");
52964
- insert(_el$6, createComponent2(For, {
52965
- each: ["cancel", "confirm"],
52966
- children: (key) => (() => {
52967
- var _el$9 = createElement("box"), _el$0 = createElement("text");
52968
- insertNode(_el$9, _el$0);
52969
- setProp(_el$9, "paddingLeft", 1);
52970
- setProp(_el$9, "paddingRight", 1);
52971
- setProp(_el$9, "onMouseUp", () => choose(key));
52972
- insert(_el$0, () => titlecase(props.label?.[key] ?? key));
52878
+ }), null);
52879
+ return _el$17;
52880
+ })(), (() => {
52881
+ var _el$21 = createElement("box"), _el$22 = createElement("text"), _el$24 = createElement("input");
52882
+ insertNode(_el$21, _el$22);
52883
+ insertNode(_el$21, _el$24);
52884
+ use((value) => {
52885
+ inlineRowEl = value;
52886
+ }, _el$21);
52887
+ setProp(_el$21, "flexDirection", "row");
52888
+ setProp(_el$21, "width", "100%");
52889
+ setProp(_el$21, "flexShrink", 0);
52890
+ setProp(_el$21, "paddingLeft", 2);
52891
+ insertNode(_el$22, createTextNode(`\u270E `));
52892
+ use((value) => {
52893
+ inputEl = value;
52894
+ }, _el$24);
52895
+ setProp(_el$24, "flexGrow", 1);
52896
+ setProp(_el$24, "onInput", (value) => props.controller.setInlineText(value));
52897
+ setProp(_el$24, "onSubmit", () => props.controller.commitCustom());
52898
+ effect((_p$) => {
52899
+ var _v$1 = phaseOf() === "input" ? currentBg() : undefined, _v$10 = phaseOf() === "input" ? currentFg() : muted(), _v$11 = props.controller.inlineText, _v$12 = t("overlay.ask.inputPlaceholder"), _v$13 = muted(), _v$14 = base(), _v$15 = currentFg(), _v$16 = phaseOf() === "input" ? currentFg() : accent(), _v$17 = cursorShape();
52900
+ _v$1 !== _p$.e && (_p$.e = setProp(_el$21, "backgroundColor", _v$1, _p$.e));
52901
+ _v$10 !== _p$.t && (_p$.t = setProp(_el$22, "fg", _v$10, _p$.t));
52902
+ _v$11 !== _p$.a && (_p$.a = setProp(_el$24, "value", _v$11, _p$.a));
52903
+ _v$12 !== _p$.o && (_p$.o = setProp(_el$24, "placeholder", _v$12, _p$.o));
52904
+ _v$13 !== _p$.i && (_p$.i = setProp(_el$24, "placeholderColor", _v$13, _p$.i));
52905
+ _v$14 !== _p$.n && (_p$.n = setProp(_el$24, "textColor", _v$14, _p$.n));
52906
+ _v$15 !== _p$.s && (_p$.s = setProp(_el$24, "focusedTextColor", _v$15, _p$.s));
52907
+ _v$16 !== _p$.h && (_p$.h = setProp(_el$24, "cursorColor", _v$16, _p$.h));
52908
+ _v$17 !== _p$.r && (_p$.r = setProp(_el$24, "cursorStyle", _v$17, _p$.r));
52909
+ return _p$;
52910
+ }, {
52911
+ e: undefined,
52912
+ t: undefined,
52913
+ a: undefined,
52914
+ o: undefined,
52915
+ i: undefined,
52916
+ n: undefined,
52917
+ s: undefined,
52918
+ h: undefined,
52919
+ r: undefined
52920
+ });
52921
+ return _el$21;
52922
+ })()];
52923
+ },
52924
+ get children() {
52925
+ var _el$7 = createElement("box"), _el$8 = createElement("box"), _el$9 = createElement("text"), _el$0 = createElement("text");
52926
+ insertNode(_el$7, _el$8);
52927
+ setProp(_el$7, "flexDirection", "column");
52928
+ setProp(_el$7, "width", "100%");
52929
+ setProp(_el$7, "flexShrink", 0);
52930
+ insert(_el$7, createComponent2(Index, {
52931
+ get each() {
52932
+ return questions();
52933
+ },
52934
+ children: (item, qi) => (() => {
52935
+ var _el$25 = createElement("box"), _el$26 = createElement("box"), _el$27 = createElement("text"), _el$28 = createElement("text"), _el$30 = createElement("text"), _el$31 = createElement("box"), _el$32 = createElement("text");
52936
+ insertNode(_el$25, _el$26);
52937
+ insertNode(_el$25, _el$31);
52938
+ setProp(_el$25, "flexDirection", "column");
52939
+ setProp(_el$25, "width", "100%");
52940
+ setProp(_el$25, "flexShrink", 0);
52941
+ insertNode(_el$26, _el$27);
52942
+ insertNode(_el$26, _el$28);
52943
+ insertNode(_el$26, _el$30);
52944
+ setProp(_el$26, "flexDirection", "row");
52945
+ setProp(_el$26, "width", "100%");
52946
+ setProp(_el$26, "flexShrink", 0);
52947
+ setProp(_el$26, "paddingLeft", 2);
52948
+ insert(_el$27, () => reviewRowActive(qi) ? "\u203A " : " ");
52949
+ insertNode(_el$28, createTextNode(`\u2713 `));
52950
+ setProp(_el$30, "wrapMode", "word");
52951
+ insert(_el$30, () => item().prompt);
52952
+ insertNode(_el$31, _el$32);
52953
+ setProp(_el$31, "paddingLeft", 6);
52954
+ setProp(_el$32, "wrapMode", "word");
52955
+ insert(_el$32, () => `\u2192 ${answerText(qi) !== "" ? answerText(qi) : t("overlay.ask.unanswered")}`);
52973
52956
  effect((_p$) => {
52974
- var _v$3 = key === store.active ? row().backgroundColor : undefined, _v$4 = key === store.active ? row().textColor : theme.text.muted;
52975
- _v$3 !== _p$.e && (_p$.e = setProp(_el$9, "backgroundColor", _v$3, _p$.e));
52976
- _v$4 !== _p$.t && (_p$.t = setProp(_el$0, "fg", _v$4, _p$.t));
52957
+ var _v$18 = reviewRowActive(qi) ? currentBg() : undefined, _v$19 = reviewRowActive(qi) ? currentFg() : accent(), _v$20 = reviewRowActive(qi) ? currentFg() : muted(), _v$21 = reviewRowActive(qi) ? currentFg() : base(), _v$22 = answerText(qi) !== "" ? accent() : faint();
52958
+ _v$18 !== _p$.e && (_p$.e = setProp(_el$26, "backgroundColor", _v$18, _p$.e));
52959
+ _v$19 !== _p$.t && (_p$.t = setProp(_el$27, "fg", _v$19, _p$.t));
52960
+ _v$20 !== _p$.a && (_p$.a = setProp(_el$28, "fg", _v$20, _p$.a));
52961
+ _v$21 !== _p$.o && (_p$.o = setProp(_el$30, "fg", _v$21, _p$.o));
52962
+ _v$22 !== _p$.i && (_p$.i = setProp(_el$32, "fg", _v$22, _p$.i));
52977
52963
  return _p$;
52978
52964
  }, {
52979
52965
  e: undefined,
52980
- t: undefined
52966
+ t: undefined,
52967
+ a: undefined,
52968
+ o: undefined,
52969
+ i: undefined
52981
52970
  });
52982
- return _el$9;
52971
+ return _el$25;
52983
52972
  })()
52973
+ }), _el$8);
52974
+ insertNode(_el$8, _el$9);
52975
+ insertNode(_el$8, _el$0);
52976
+ setProp(_el$8, "flexDirection", "row");
52977
+ setProp(_el$8, "width", "100%");
52978
+ setProp(_el$8, "flexShrink", 0);
52979
+ setProp(_el$8, "paddingLeft", 2);
52980
+ insert(_el$9, () => reviewSubmitActive() ? "\u203A " : " ");
52981
+ setProp(_el$0, "wrapMode", "none");
52982
+ insert(_el$0, () => t("overlay.ask.submitRow"));
52983
+ effect((_p$) => {
52984
+ var _v$ = reviewSubmitActive() ? currentBg() : undefined, _v$2 = reviewSubmitActive() ? currentFg() : accent(), _v$3 = reviewSubmitActive() ? currentFg() : base();
52985
+ _v$ !== _p$.e && (_p$.e = setProp(_el$8, "backgroundColor", _v$, _p$.e));
52986
+ _v$2 !== _p$.t && (_p$.t = setProp(_el$9, "fg", _v$2, _p$.t));
52987
+ _v$3 !== _p$.a && (_p$.a = setProp(_el$0, "fg", _v$3, _p$.a));
52988
+ return _p$;
52989
+ }, {
52990
+ e: undefined,
52991
+ t: undefined,
52992
+ a: undefined
52993
+ });
52994
+ return _el$7;
52995
+ }
52996
+ }), _el$1);
52997
+ insertNode(_el$1, _el$10);
52998
+ setProp(_el$1, "flexDirection", "row");
52999
+ setProp(_el$1, "width", "100%");
53000
+ setProp(_el$1, "justifyContent", "space-between");
53001
+ setProp(_el$1, "paddingLeft", 2);
53002
+ setProp(_el$1, "paddingRight", 2);
53003
+ setProp(_el$10, "wrapMode", "none");
53004
+ insert(_el$10, footerHint);
53005
+ insert(_el$1, createComponent2(Show, {
53006
+ get when() {
53007
+ return queuedCount() > 0;
53008
+ },
53009
+ get children() {
53010
+ var _el$11 = createElement("text");
53011
+ setProp(_el$11, "wrapMode", "none");
53012
+ insert(_el$11, () => t("overlay.ask.queued", {
53013
+ count: queuedCount()
52984
53014
  }));
52985
- return _el$4;
52986
- })();
52987
- },
52988
- get children() {
52989
- var _el$ = createElement("text");
52990
- insert(_el$, () => props.message);
52991
- effect((_$p) => setProp(_el$, "fg", theme.text.muted, _$p));
52992
- return _el$;
52993
- }
52994
- });
52995
- }
52996
- var init_dialog_confirm = __esm(() => {
52997
- init_index_bun();
52998
- init_index_bun();
52999
- init_index_bun();
53000
- init_index_bun();
53001
- init_index_bun();
53002
- init_index_bun();
53003
- init_index_bun();
53004
- init_keymap();
53005
- init_theme3();
53006
- init_config();
53007
- init_dialog();
53008
- init_server2();
53009
- init_server();
53010
- init_locale();
53011
- init_semantic();
53012
- init_turn_overlays();
53013
- });
53014
-
53015
- // ../tui-base/src/routes/session/ask-keys.ts
53016
- function printableText(event) {
53017
- const text = event.sequence;
53018
- if (text.length !== 1)
53019
- return;
53020
- if (event.ctrl || event.meta || event.super === true || event.hyper === true)
53021
- return;
53022
- if (text === " ")
53023
- return;
53024
- if (text >= "0" && text <= "9")
53025
- return;
53026
- const code = text.codePointAt(0) ?? 0;
53027
- if (code < 32 || code === 127)
53028
- return;
53029
- return text;
53015
+ effect((_$p) => setProp(_el$11, "fg", muted(), _$p));
53016
+ return _el$11;
53017
+ }
53018
+ }), null);
53019
+ setProp(_el$12, "width", "100%");
53020
+ setProp(_el$12, "flexShrink", 0);
53021
+ setProp(_el$12, "border", ["bottom"]);
53022
+ setProp(_el$12, "borderStyle", "single");
53023
+ effect((_p$) => {
53024
+ var _v$4 = rule(), _v$5 = warningColor(theme), _v$6 = muted(), _v$7 = rule();
53025
+ _v$4 !== _p$.e && (_p$.e = setProp(_el$2, "borderColor", _v$4, _p$.e));
53026
+ _v$5 !== _p$.t && (_p$.t = setProp(_el$4, "fg", _v$5, _p$.t));
53027
+ _v$6 !== _p$.a && (_p$.a = setProp(_el$10, "fg", _v$6, _p$.a));
53028
+ _v$7 !== _p$.o && (_p$.o = setProp(_el$12, "borderColor", _v$7, _p$.o));
53029
+ return _p$;
53030
+ }, {
53031
+ e: undefined,
53032
+ t: undefined,
53033
+ a: undefined,
53034
+ o: undefined
53035
+ });
53036
+ return _el$;
53037
+ })();
53030
53038
  }
53031
- function useAskKeys(options) {
53032
- const keymap = Keymap2.useOptional();
53033
- if (keymap === undefined)
53034
- return;
53035
- const renderer = useRenderer();
53036
- const ownership = useInputOwnershipOptional();
53037
- const ownsDock = () => ownership === undefined || ownership.top().kind === "dock";
53038
- const ask = () => options.controller.pendingAsk;
53039
- const question = () => {
53040
- const batch = ask();
53041
- return batch?.questions[batch.index];
53039
+ function OptionRow(props) {
53040
+ const theme = useThemeOptional();
53041
+ const muted = () => theme?.text.muted ?? "#9aa5ce";
53042
+ const faint = () => theme?.text.faint ?? "#565f89";
53043
+ const base = () => theme?.text.base ?? "#e6e6e6";
53044
+ const accent = () => theme?.hue.interactive[500] ?? "#7aa2f7";
53045
+ const success = () => theme?.text.feedback.success.base ?? "#9ece6a";
53046
+ const currentBg = () => theme?.background.action.primary.focused;
53047
+ const currentFg = () => theme?.text.action.primary.focused ?? accent();
53048
+ const label = () => splitRecommended(props.row().option.label);
53049
+ const number = () => `${props.row().number}. `;
53050
+ const badge = () => `[${t("overlay.ask.recommended")}]`;
53051
+ const stateGlyph = () => {
53052
+ if (props.multi())
53053
+ return props.row().selected ? "\u25A0 " : "\u25A1 ";
53054
+ return props.row().selected ? "\u25CF " : "\u25CB ";
53042
53055
  };
53043
- const needsReview = () => askNeedsReview(ask()?.questions ?? []);
53044
- const currentRow = () => {
53045
- const batch = ask();
53046
- return batch === undefined ? 0 : batch.cursors[batch.index] ?? 0;
53056
+ const stateColor = () => {
53057
+ if (props.cursor())
53058
+ return currentFg();
53059
+ return props.row().selected ? success() : faint();
53047
53060
  };
53048
- const inputFocused = () => {
53049
- const input = options.input();
53050
- return input !== undefined && renderer.currentFocusedRenderable === input;
53051
- };
53052
- onCleanup(keymap.intercept("key", ({ event }) => {
53053
- if (!ownsDock())
53054
- return;
53055
- const batch = ask();
53056
- if (batch === undefined || batch.phase !== "questions")
53057
- return;
53058
- if (printableText(event) === undefined)
53059
- return;
53060
- options.controller.focusInput();
53061
- options.input()?.focus();
53062
- }));
53063
- function move(delta) {
53064
- const batch = ask();
53065
- if (batch === undefined)
53066
- return false;
53067
- if (batch.phase === "review") {
53068
- options.controller.moveReviewCursor(delta);
53069
- return true;
53070
- }
53071
- if (batch.phase === "input")
53072
- return false;
53073
- options.controller.moveCursor(delta);
53074
- return true;
53075
- }
53076
- function page(direction) {
53077
- return move(direction * ASK_PAGE_ROWS);
53078
- }
53079
- function boundary(toEnd) {
53080
- const batch = ask();
53081
- if (batch === undefined)
53082
- return false;
53083
- if (batch.phase === "review") {
53084
- options.controller.setReviewCursor(toEnd ? batch.questions.length : 0);
53085
- return true;
53086
- }
53087
- if (batch.phase === "input")
53088
- return false;
53089
- const current = question();
53090
- if (current === undefined)
53091
- return false;
53092
- options.controller.setCursor(toEnd ? questionRowCount(current, needsReview()) - 1 : 0);
53093
- return true;
53094
- }
53095
- function switchQuestion(direction) {
53096
- const batch = ask();
53097
- if (batch === undefined)
53098
- return false;
53099
- if (batch.phase === "input")
53061
+ const badgeInline = () => {
53062
+ if (!label().recommended || props.compact())
53100
53063
  return false;
53101
- if (batch.phase === "review") {
53102
- if (direction === -1) {
53103
- options.controller.backToQuestions(batch.questions.length - 1);
53104
- return true;
53064
+ const used = props.labelColumn() + stringWidth(label().label) + BADGE_GAP + stringWidth(badge());
53065
+ return used <= props.width();
53066
+ };
53067
+ const labelColor = () => props.cursor() ? currentFg() : base();
53068
+ return (() => {
53069
+ var _el$33 = createElement("box"), _el$34 = createElement("box"), _el$35 = createElement("text"), _el$36 = createElement("text"), _el$37 = createElement("text"), _el$38 = createElement("text");
53070
+ insertNode(_el$33, _el$34);
53071
+ setProp(_el$33, "flexDirection", "column");
53072
+ setProp(_el$33, "width", "100%");
53073
+ setProp(_el$33, "flexShrink", 0);
53074
+ insertNode(_el$34, _el$35);
53075
+ insertNode(_el$34, _el$36);
53076
+ insertNode(_el$34, _el$37);
53077
+ insertNode(_el$34, _el$38);
53078
+ setProp(_el$34, "flexDirection", "row");
53079
+ setProp(_el$34, "width", "100%");
53080
+ setProp(_el$34, "flexShrink", 0);
53081
+ setProp(_el$34, "paddingLeft", 2);
53082
+ insert(_el$35, () => props.marked() ? "\u203A " : " ");
53083
+ insert(_el$36, stateGlyph);
53084
+ insert(_el$37, number);
53085
+ setProp(_el$38, "wrapMode", "word");
53086
+ insert(_el$38, () => label().label);
53087
+ insert(_el$34, createComponent2(Show, {
53088
+ get when() {
53089
+ return badgeInline();
53090
+ },
53091
+ get children() {
53092
+ var _el$39 = createElement("text");
53093
+ insert(_el$39, () => ` ${badge()}`);
53094
+ effect((_$p) => setProp(_el$39, "fg", props.cursor() ? currentFg() : success(), _$p));
53095
+ return _el$39;
53105
53096
  }
53106
- return false;
53107
- }
53108
- if (batch.questions.length < 2)
53109
- return false;
53110
- options.controller.switchFocus(direction);
53111
- return true;
53112
- }
53113
- function enter() {
53114
- const batch = ask();
53115
- if (batch === undefined)
53116
- return false;
53117
- if (batch.phase === "input")
53118
- return false;
53119
- if (batch.phase === "review") {
53120
- const intent = reviewRowIntent(batch.reviewCursor, batch.questions.length);
53121
- if (intent.kind === "submit") {
53122
- options.controller.submit();
53123
- return true;
53097
+ }), null);
53098
+ insert(_el$33, createComponent2(Show, {
53099
+ get when() {
53100
+ return memo2(() => !!label().recommended)() && !badgeInline();
53101
+ },
53102
+ get children() {
53103
+ var _el$40 = createElement("box"), _el$41 = createElement("text");
53104
+ insertNode(_el$40, _el$41);
53105
+ setProp(_el$41, "wrapMode", "none");
53106
+ insert(_el$41, badge);
53107
+ effect((_p$) => {
53108
+ var _v$23 = props.labelColumn(), _v$24 = success();
53109
+ _v$23 !== _p$.e && (_p$.e = setProp(_el$40, "paddingLeft", _v$23, _p$.e));
53110
+ _v$24 !== _p$.t && (_p$.t = setProp(_el$41, "fg", _v$24, _p$.t));
53111
+ return _p$;
53112
+ }, {
53113
+ e: undefined,
53114
+ t: undefined
53115
+ });
53116
+ return _el$40;
53124
53117
  }
53125
- options.controller.backToQuestions(intent.question);
53126
- return true;
53127
- }
53128
- const current = question();
53129
- if (current === undefined)
53130
- return false;
53131
- const row = currentRow();
53132
- if (hasReviewRow(current, needsReview()) && row === current.options.length) {
53133
- return options.controller.enterReview();
53118
+ }), null);
53119
+ insert(_el$33, createComponent2(Show, {
53120
+ get when() {
53121
+ return props.row().option.description;
53122
+ },
53123
+ children: (description) => (() => {
53124
+ var _el$42 = createElement("box"), _el$43 = createElement("text");
53125
+ insertNode(_el$42, _el$43);
53126
+ setProp(_el$43, "wrapMode", "word");
53127
+ insert(_el$43, description);
53128
+ effect((_p$) => {
53129
+ var _v$31 = props.labelColumn(), _v$32 = muted();
53130
+ _v$31 !== _p$.e && (_p$.e = setProp(_el$42, "paddingLeft", _v$31, _p$.e));
53131
+ _v$32 !== _p$.t && (_p$.t = setProp(_el$43, "fg", _v$32, _p$.t));
53132
+ return _p$;
53133
+ }, {
53134
+ e: undefined,
53135
+ t: undefined
53136
+ });
53137
+ return _el$42;
53138
+ })()
53139
+ }), null);
53140
+ effect((_p$) => {
53141
+ var _v$25 = props.cursor() ? currentBg() : undefined, _v$26 = props.cursor() ? currentFg() : faint(), _v$27 = stateColor(), _v$28 = props.cursor() ? currentFg() : faint(), _v$29 = labelColor(), _v$30 = badgeInline() ? 0 : 1;
53142
+ _v$25 !== _p$.e && (_p$.e = setProp(_el$34, "backgroundColor", _v$25, _p$.e));
53143
+ _v$26 !== _p$.t && (_p$.t = setProp(_el$35, "fg", _v$26, _p$.t));
53144
+ _v$27 !== _p$.a && (_p$.a = setProp(_el$36, "fg", _v$27, _p$.a));
53145
+ _v$28 !== _p$.o && (_p$.o = setProp(_el$37, "fg", _v$28, _p$.o));
53146
+ _v$29 !== _p$.i && (_p$.i = setProp(_el$38, "fg", _v$29, _p$.i));
53147
+ _v$30 !== _p$.n && (_p$.n = setProp(_el$38, "flexGrow", _v$30, _p$.n));
53148
+ return _p$;
53149
+ }, {
53150
+ e: undefined,
53151
+ t: undefined,
53152
+ a: undefined,
53153
+ o: undefined,
53154
+ i: undefined,
53155
+ n: undefined
53156
+ });
53157
+ return _el$33;
53158
+ })();
53159
+ }
53160
+ var ASK_COMPACT_COLUMNS = 64, GUTTER = 2, CURSOR_CELLS = 2, STATE_CELLS = 2, BADGE_GAP = 2;
53161
+ var init_ask_panel = __esm(() => {
53162
+ init_index_bun();
53163
+ init_index_bun();
53164
+ init_index_bun();
53165
+ init_index_bun();
53166
+ init_index_bun();
53167
+ init_index_bun();
53168
+ init_index_bun();
53169
+ init_index_bun();
53170
+ init_index_bun();
53171
+ init_server();
53172
+ init_i18n();
53173
+ init_theme3();
53174
+ init_config();
53175
+ init_semantic();
53176
+ init_ask_options();
53177
+ init_ask_keys();
53178
+ init_dock_host();
53179
+ init_string_width();
53180
+ });
53181
+
53182
+ // ../tui-base/src/routes/session/turn-overlays.tsx
53183
+ function summarizeArgs(name, args, limit = 160) {
53184
+ let body = JSON.stringify(args);
53185
+ if (body === undefined)
53186
+ body = "";
53187
+ body = body.trim();
53188
+ if (body.length > limit)
53189
+ body = body.slice(0, limit - 1) + "\u2026";
53190
+ return `${name} ${body}`.trim();
53191
+ }
53192
+ function ApprovalCard(props) {
53193
+ const invalidated = () => props.invalidatedReason !== undefined;
53194
+ return createComponent2(DialogConfirm, {
53195
+ get title() {
53196
+ return memo2(() => !!invalidated())() ? t("overlay.ask.invalidatedTitle") : t("overlay.ask.approvalTitle", {
53197
+ name: props.name
53198
+ });
53199
+ },
53200
+ get message() {
53201
+ return memo2(() => !!invalidated())() ? t("overlay.ask.invalidated", {
53202
+ reason: props.invalidatedReason ?? ""
53203
+ }) : summarizeArgs(props.name, props.args);
53204
+ },
53205
+ get label() {
53206
+ return memo2(() => !!invalidated())() ? {
53207
+ confirm: t("overlay.ask.invalidatedAck"),
53208
+ cancel: t("overlay.ask.invalidatedAck")
53209
+ } : {
53210
+ confirm: t("overlay.ask.allow"),
53211
+ cancel: t("overlay.ask.reject")
53212
+ };
53213
+ },
53214
+ onConfirm: () => props.onVerdict("allowed-once"),
53215
+ onCancel: () => props.onVerdict("rejected"),
53216
+ get extraActions() {
53217
+ return memo2(() => !!(!invalidated() && props.escalation === true))() ? [{
53218
+ label: t("overlay.ask.allowAlways"),
53219
+ bind: "a",
53220
+ onTrigger: () => props.onVerdict("always")
53221
+ }, {
53222
+ label: t("overlay.ask.allowSession"),
53223
+ bind: "s",
53224
+ onTrigger: () => props.onVerdict("session")
53225
+ }] : undefined;
53134
53226
  }
53135
- const option = current.options[row];
53136
- if (option === undefined)
53137
- return false;
53138
- if (current.multiSelect === true)
53139
- return options.controller.confirmQuestion();
53140
- options.controller.toggle(option.label);
53141
- return true;
53142
- }
53143
- function space() {
53144
- const batch = ask();
53145
- if (batch === undefined || batch.phase !== "questions")
53146
- return false;
53147
- const current = question();
53148
- if (current === undefined || current.multiSelect !== true)
53149
- return false;
53150
- if (inputFocused())
53151
- return false;
53152
- const option = current.options[currentRow()];
53153
- if (option === undefined)
53154
- return false;
53155
- options.controller.toggle(option.label);
53156
- return true;
53157
- }
53158
- function digit(index) {
53159
- const batch = ask();
53160
- if (batch === undefined || batch.phase !== "questions")
53161
- return false;
53162
- if (inputFocused())
53163
- return false;
53164
- const option = question()?.options[index];
53165
- if (option === undefined)
53166
- return false;
53167
- options.controller.toggle(option.label);
53168
- return true;
53169
- }
53170
- function atOutermost(batch) {
53171
- if (batch.phase === "review" || batch.index > 0)
53172
- return false;
53173
- if (batch.phase === "input")
53174
- return (batch.questions[batch.index]?.options.length ?? 0) === 0;
53175
- return true;
53227
+ });
53228
+ }
53229
+ function ReminderBadge() {
53230
+ const theme = useThemeOptional();
53231
+ const [tick, setTick] = createSignal(0);
53232
+ const startedAt = Date.now();
53233
+ const pulsing = () => motionDecorationsEnabled() && Date.now() - startedAt < SKIN_PULSE_MS;
53234
+ onAnimationTick(() => pulsing() && motionAnimationRunning() ? motionFrameRate() : undefined, () => setTick((t) => t + 1));
53235
+ const fg = () => {
53236
+ tick();
53237
+ const target = warningColor(theme);
53238
+ if (!motionDecorationsEnabled())
53239
+ return target;
53240
+ const bright = skinPulseBrightness(Date.now() - startedAt);
53241
+ return bright >= 1 ? target : mixSkinColor(target, theme?.background.base ?? "#000000", 1 - bright);
53242
+ };
53243
+ return (() => {
53244
+ var _el$ = createElement("text");
53245
+ insertNode(_el$, createTextNode(`\u26A0 `));
53246
+ setProp(_el$, "flexShrink", 0);
53247
+ effect((_$p) => setProp(_el$, "fg", fg(), _$p));
53248
+ return _el$;
53249
+ })();
53250
+ }
53251
+ function TurnOverlayHost(props) {
53252
+ const dialog = useDialog();
53253
+ const dock = useDock();
53254
+ const pageOwns = useIsPageOwner();
53255
+ const [version, setVersion] = createSignal(0);
53256
+ onMount(() => {
53257
+ const unsubscribe = props.controller.subscribe(() => setVersion((value) => value + 1));
53258
+ onCleanup(unsubscribe);
53259
+ const timer = setInterval(() => props.controller.syncPendingAsks(), 200);
53260
+ onCleanup(() => clearInterval(timer));
53261
+ });
53262
+ props.controller.onIdle(() => {
53263
+ setTimeout(() => props.reclaimFocus?.(), 3);
53264
+ });
53265
+ let panelFocus;
53266
+ let askHandle;
53267
+ let askId;
53268
+ let shown;
53269
+ function closeAsk() {
53270
+ askHandle?.close();
53271
+ askHandle = undefined;
53272
+ askId = undefined;
53176
53273
  }
53177
- function backOut() {
53178
- const batch = ask();
53179
- if (batch === undefined)
53180
- return false;
53181
- if (batch.phase === "review") {
53182
- options.controller.backToQuestions(batch.questions.length - 1);
53183
- return true;
53274
+ createEffect(() => {
53275
+ version();
53276
+ const approval = props.controller.pendingApproval;
53277
+ const ask = props.controller.pendingAsk;
53278
+ const askShowing = askHandle !== undefined && ask !== undefined && askId === ask.id;
53279
+ const pageOwned = pageOwns();
53280
+ const approvalWins = approval !== undefined && !askShowing;
53281
+ const askAdmitted = ask !== undefined && (askShowing || pageOwned);
53282
+ const key = approvalWins ? `approval:${approval.id}` : askAdmitted ? `ask:${ask.id}` : "";
53283
+ if (key === shown)
53284
+ return;
53285
+ const previousKey = shown;
53286
+ shown = key;
53287
+ if (previousKey?.startsWith("approval:") === true && dialog.stack.at(-1)?.key === previousKey) {
53288
+ dialog.clear();
53184
53289
  }
53185
- if (batch.phase === "input") {
53186
- const current = batch.questions[batch.index];
53187
- if (current !== undefined && current.options.length > 0) {
53188
- options.controller.focusOptions();
53189
- return true;
53290
+ if (approvalWins) {
53291
+ closeAsk();
53292
+ const atOpen = key;
53293
+ const approvalId = approval.id;
53294
+ try {
53295
+ dialog.replace(() => createComponent2(ApprovalCard, {
53296
+ get name() {
53297
+ return approval.name;
53298
+ },
53299
+ get args() {
53300
+ return approval.args;
53301
+ },
53302
+ get escalation() {
53303
+ return approval.escalation;
53304
+ },
53305
+ get invalidatedReason() {
53306
+ return approval.invalidatedReason;
53307
+ },
53308
+ onVerdict: (verdict) => {
53309
+ switch (verdict) {
53310
+ case "allowed-once":
53311
+ props.controller.confirmApproval();
53312
+ break;
53313
+ case "always":
53314
+ props.controller.approveAlways();
53315
+ break;
53316
+ case "session":
53317
+ props.controller.approveSession();
53318
+ break;
53319
+ default:
53320
+ props.controller.rejectApproval();
53321
+ }
53322
+ }
53323
+ }), () => {
53324
+ if (shown === atOpen && props.controller.pendingApproval?.id === approvalId) {
53325
+ props.controller.rejectApproval();
53326
+ }
53327
+ }, {
53328
+ key,
53329
+ tone: "warning"
53330
+ });
53331
+ } catch {
53332
+ props.controller.rejectApproval();
53190
53333
  }
53334
+ return;
53191
53335
  }
53192
- if (batch.index > 0) {
53193
- options.controller.switchFocus(-1);
53194
- return true;
53336
+ if (ask !== undefined && askAdmitted) {
53337
+ if (askHandle !== undefined && askId === ask.id)
53338
+ return;
53339
+ const previous = askHandle;
53340
+ askId = ask.id;
53341
+ askHandle = dock.open((ctx) => createComponent2(AskPanel, {
53342
+ get controller() {
53343
+ return props.controller;
53344
+ },
53345
+ get width() {
53346
+ return ctx.width;
53347
+ },
53348
+ queued: () => Math.max(0, props.controller.pendingAskCount + props.controller.pendingApprovalCount - 1),
53349
+ onFocusTarget: (resolve) => {
53350
+ panelFocus = resolve;
53351
+ }
53352
+ }), {
53353
+ kind: "ask",
53354
+ contentRows: estimateAskRows(ask),
53355
+ focusRef: () => panelFocus?.(),
53356
+ overflowLabel: (hidden) => t("overlay.ask.overflow", {
53357
+ count: hidden
53358
+ })
53359
+ });
53360
+ previous?.close();
53361
+ return;
53195
53362
  }
53196
- options.controller.decline();
53197
- return true;
53363
+ closeAsk();
53364
+ });
53365
+ onCleanup(closeAsk);
53366
+ return createComponent2(Show, {
53367
+ when: false,
53368
+ children: null
53369
+ });
53370
+ }
53371
+ function registerTurnOverlays(seam, controller, options) {
53372
+ if (typeof seam.pendingAsks === "function") {
53373
+ const read = seam.pendingAsks.bind(seam);
53374
+ controller.attachPendingAsks(() => read() ?? []);
53198
53375
  }
53199
- function interrupt() {
53200
- const batch = ask();
53201
- if (batch === undefined)
53202
- return false;
53203
- if (atOutermost(batch))
53204
- armNonArmingInterrupt();
53205
- return backOut();
53376
+ if (typeof seam.onSessionEvent === "function") {
53377
+ seam.onSessionEvent((event) => {
53378
+ if (event.type === "bridge.dead") {
53379
+ const configured = options?.deadReason;
53380
+ if (configured === undefined)
53381
+ return;
53382
+ const reason = typeof configured === "function" ? configured(event.details) : configured;
53383
+ if (reason !== "")
53384
+ controller.invalidateAll(reason);
53385
+ return;
53386
+ }
53387
+ if (event.type !== "bridge.ask.invalidated")
53388
+ return;
53389
+ const details = event.details;
53390
+ if (typeof details?.eventId !== "string")
53391
+ return;
53392
+ controller.invalidateAsk(details.eventId, typeof details.reason === "string" ? details.reason : "");
53393
+ });
53206
53394
  }
53207
- Keymap2.createLayer(() => ({
53208
- mode: "global",
53209
- enabled: ownsDock,
53210
- commands: [
53211
- { bind: "up,ctrl+p", run: () => move(-1) },
53212
- { bind: "down,ctrl+n", run: () => move(1) },
53213
- { bind: "pageup", run: () => page(-1) },
53214
- { bind: "pagedown", run: () => page(1) },
53215
- { bind: "home", run: () => boundary(false) },
53216
- { bind: "end", run: () => boundary(true) },
53217
- { bind: "return", run: enter },
53218
- { bind: "space", run: space },
53219
- ...Array.from({ length: 9 }, (_, index) => ({
53220
- bind: `${index + 1}`,
53221
- enabled: () => !inputFocused(),
53222
- run: () => digit(index)
53223
- })),
53224
- { bind: "left", run: () => switchQuestion(-1) },
53225
- { bind: "right", run: () => switchQuestion(1) },
53226
- { bind: "escape", run: backOut },
53227
- { bind: "ctrl+c", run: interrupt }
53228
- ]
53229
- }));
53395
+ seam.registerAskProvider((questions) => controller.answer(questions));
53230
53396
  }
53231
- var ASK_PAGE_ROWS = 5;
53232
- var init_ask_keys = __esm(() => {
53397
+ var init_turn_overlays = __esm(() => {
53398
+ init_index_bun();
53399
+ init_index_bun();
53400
+ init_index_bun();
53401
+ init_index_bun();
53402
+ init_index_bun();
53403
+ init_index_bun();
53233
53404
  init_index_bun();
53234
53405
  init_server();
53235
- init_keymap();
53406
+ init_index_bun();
53407
+ init_dialog_confirm();
53408
+ init_dialog();
53236
53409
  init_input_ownership();
53410
+ init_theme3();
53411
+ init_i18n();
53412
+ init_motion();
53413
+ init_semantic();
53414
+ init_widgets_dock();
53415
+ init_ask_panel();
53237
53416
  init_ask_options();
53238
- init_turn_cancel();
53417
+ init_dock_host();
53239
53418
  });
53240
53419
 
53241
- // ../tui-base/src/routes/session/dock-host.tsx
53242
- function firstFocusable(node) {
53243
- if (node === undefined)
53244
- return;
53245
- for (const child of node.getChildren()) {
53246
- if (child.focusable)
53247
- return child;
53248
- const nested = firstFocusable(child);
53249
- if (nested !== undefined)
53250
- return nested;
53251
- }
53252
- return;
53253
- }
53254
- function DockProvider(props) {
53255
- const renderer = useRenderer();
53256
- const ownership = useInputOwnershipOptional();
53257
- const [queue, setQueue] = createSignal([]);
53258
- let frame;
53259
- let composerFocus;
53260
- let focusTarget;
53261
- let cancelAfterLayout;
53262
- const hasRequests = () => queue().length > 0;
53263
- function afterLayout(callback) {
53264
- cancelAfterLayout?.();
53265
- if (renderer.isDestroyed)
53266
- return;
53267
- let done = false;
53268
- const handler = () => {
53269
- if (done)
53270
- return;
53271
- done = true;
53272
- renderer.off("frame", handler);
53273
- if (cancelAfterLayout === cancel)
53274
- cancelAfterLayout = undefined;
53275
- callback();
53276
- };
53277
- const cancel = () => {
53278
- if (done)
53279
- return;
53280
- done = true;
53281
- renderer.off("frame", handler);
53282
- if (cancelAfterLayout === cancel)
53283
- cancelAfterLayout = undefined;
53284
- };
53285
- cancelAfterLayout = cancel;
53286
- renderer.on("frame", handler);
53287
- }
53288
- function focusDock() {
53289
- afterLayout(() => {
53290
- if (!hasRequests())
53291
- return;
53292
- const target = focusTarget?.();
53293
- if (target !== undefined) {
53294
- target.focus();
53295
- return;
53296
- }
53297
- renderer.currentFocusedRenderable?.blur();
53298
- });
53299
- }
53300
- function remove(entry) {
53301
- const before = queue();
53302
- if (!before.includes(entry))
53303
- return;
53304
- const next = before.filter((item) => item !== entry);
53305
- setQueue(next);
53306
- if (next.length > 0) {
53307
- if (before[0] !== next[0])
53308
- focusDock();
53309
- return;
53310
- }
53311
- if (frame !== undefined) {
53312
- ownership?.pop(frame);
53313
- frame = undefined;
53314
- }
53315
- afterLayout(() => {
53316
- if (hasRequests())
53317
- return;
53318
- composerFocus?.();
53319
- });
53320
- }
53321
- const api = {
53322
- open(render, options = {}) {
53323
- const id = ++ordinal2;
53324
- const entry = {
53325
- id,
53326
- kind: options.kind,
53327
- options,
53328
- close: () => remove(entry),
53329
- render
53330
- };
53331
- const before = queue();
53332
- setQueue([...before, entry]);
53333
- if (before.length === 0) {
53334
- frame = ownership?.push("dock");
53335
- focusDock();
53336
- }
53337
- return {
53338
- id,
53339
- close: entry.close
53340
- };
53341
- },
53342
- queueDepth: () => Math.max(0, queue().length - 1),
53343
- isOpen: () => hasRequests(),
53344
- currentKind: () => queue()[0]?.kind,
53345
- current: () => queue()[0],
53346
- bindComposerFocus(refocus) {
53347
- composerFocus = refocus;
53348
- },
53349
- bindFocusTarget(resolve) {
53350
- focusTarget = resolve;
53351
- }
53352
- };
53353
- onCleanup(() => {
53354
- cancelAfterLayout?.();
53355
- if (frame !== undefined) {
53356
- ownership?.pop(frame);
53357
- frame = undefined;
53358
- }
53359
- setQueue([]);
53360
- });
53361
- return createComponent2(Context7.Provider, {
53362
- value: api,
53363
- get children() {
53364
- return props.children;
53365
- }
53420
+ // ../tui-base/src/ui/dialog-confirm.tsx
53421
+ import { TextAttributes as TextAttributes7 } from "@opentui/core";
53422
+ function DialogConfirm(props) {
53423
+ const dialog = useDialog();
53424
+ const theme = useTheme().surface("dialog");
53425
+ const newDesigns = useNewDesigns();
53426
+ const row = () => currentRowColors(theme);
53427
+ const [store, setStore] = createStore({
53428
+ active: "confirm"
53366
53429
  });
53367
- }
53368
- function useDock() {
53369
- const value = useContext(Context7);
53370
- if (!value)
53371
- throw new Error("Dock.Provider is missing");
53372
- return value;
53373
- }
53374
- function DockSeat(props) {
53375
- const dock = useDock();
53376
- const dimensions = useTerminalSize();
53377
- const theme = useThemeOptional();
53378
- let scroll;
53379
- let body;
53380
- let disposed = false;
53381
- const [measured, setMeasured] = createSignal(undefined);
53382
- const resolveFocus = () => {
53383
- const designated = dock.current()?.options.focusRef?.();
53384
- return designated ?? firstFocusable(body);
53430
+ const choose = (key) => {
53431
+ if (key === "confirm")
53432
+ props.onConfirm?.();
53433
+ if (key === "cancel")
53434
+ props.onCancel?.();
53435
+ dialog.clear();
53385
53436
  };
53386
- dock.bindFocusTarget(resolveFocus);
53387
- onCleanup(() => {
53388
- disposed = true;
53389
- dock.bindFocusTarget(undefined);
53390
- });
53391
- const capRows = () => Math.max(1, Math.floor(dimensions().height * DOCK_MAX_ROWS_RATIO));
53392
- const contentRows = () => measured() ?? dock.current()?.options.contentRows ?? capRows();
53393
- const overflows = () => contentRows() > capRows() && capRows() > 1;
53394
- const viewportRows = () => Math.max(1, Math.min(contentRows(), capRows() - (overflows() ? 1 : 0)));
53395
- const hiddenRows = () => Math.max(0, contentRows() - viewportRows());
53396
- const indicatorText = () => {
53397
- const label = dock.current()?.options.overflowLabel;
53398
- return label ? label(hiddenRows()) : `\u2191\u2193 ${hiddenRows()}`;
53437
+ const chooseExtra = (action) => {
53438
+ action.onTrigger();
53439
+ dialog.clear();
53399
53440
  };
53400
- const muted = () => theme?.text.muted ?? "#9aa5ce";
53401
- const background = () => theme?.background.base ?? "black";
53402
- createEffect(on(() => dock.current()?.id, () => {
53403
- if (scroll !== undefined && !scroll.isDestroyed)
53404
- scroll.scrollTo(0);
53405
- }, {
53406
- defer: true
53407
- }));
53408
- createEffect(on(capRows, () => {
53409
- if (scroll === undefined || scroll.isDestroyed)
53410
- return;
53411
- scroll.afterLayout(() => {
53412
- if (scroll === undefined || scroll.isDestroyed)
53413
- return;
53414
- const max = Math.max(0, scroll.scrollHeight - scroll.viewport.height);
53415
- if (scroll.scrollTop > max)
53416
- scroll.scrollTo(max);
53417
- });
53418
- }, {
53419
- defer: true
53420
- }));
53421
- return (() => {
53422
- var _el$ = createElement("box"), _el$2 = createElement("box");
53423
- insertNode(_el$, _el$2);
53424
- setProp(_el$, "width", "100%");
53425
- setProp(_el$, "flexShrink", 0);
53426
- setProp(_el$, "flexDirection", "column");
53427
- setProp(_el$2, "width", "100%");
53428
- setProp(_el$2, "flexShrink", 0);
53429
- insert(_el$2, () => props.composer());
53430
- insert(_el$, createComponent2(Show, {
53431
- get when() {
53432
- return dock.current();
53441
+ Keymap2.createLayer(() => ({
53442
+ mode: "modal",
53443
+ commands: [...newDesigns() ? [{
53444
+ bind: "return",
53445
+ title: "Confirm",
53446
+ group: "Dialog",
53447
+ run: () => choose("confirm")
53448
+ }, {
53449
+ bind: "escape",
53450
+ title: "Cancel",
53451
+ group: "Dialog",
53452
+ run: () => choose("cancel")
53453
+ }] : [
53454
+ {
53455
+ bind: "return",
53456
+ title: "Confirm dialog selection",
53457
+ group: "Dialog",
53458
+ run: () => choose(store.active)
53433
53459
  },
53434
- children: (request) => (() => {
53435
- var _el$3 = createElement("box"), _el$4 = createElement("scrollbox"), _el$5 = createElement("box");
53436
- insertNode(_el$3, _el$4);
53437
- setProp(_el$3, "width", "100%");
53438
- setProp(_el$3, "flexShrink", 0);
53439
- setProp(_el$3, "flexDirection", "column");
53440
- insertNode(_el$4, _el$5);
53441
- use((value) => {
53442
- scroll = value;
53443
- }, _el$4);
53444
- setProp(_el$4, "width", "100%");
53445
- setProp(_el$4, "flexShrink", 0);
53446
- setProp(_el$4, "focusable", false);
53447
- setProp(_el$4, "scrollY", true);
53448
- setProp(_el$4, "scrollX", false);
53449
- setProp(_el$4, "overflow", "hidden");
53450
- setProp(_el$4, "verticalScrollbarOptions", {
53451
- visible: false
53452
- });
53453
- use((value) => {
53454
- body = value;
53455
- }, _el$5);
53456
- setProp(_el$5, "width", "100%");
53457
- setProp(_el$5, "flexDirection", "column");
53458
- setProp(_el$5, "onSizeChange", function() {
53459
- if (disposed)
53460
- return;
53461
- const next = Math.max(0, Math.floor(this.height));
53462
- if (next !== measured())
53463
- setMeasured(next);
53464
- });
53465
- insert(_el$5, () => request().render({
53466
- id: request().id,
53467
- close: request().close,
53468
- width: () => dimensions().width,
53469
- maxHeight: capRows
53470
- }));
53471
- insert(_el$3, createComponent2(Show, {
53472
- get when() {
53473
- return memo2(() => !!overflows())() && hiddenRows() > 0;
53460
+ {
53461
+ bind: "left",
53462
+ title: "Previous dialog option",
53463
+ group: "Dialog",
53464
+ run: () => {
53465
+ setStore("active", store.active === "confirm" ? "cancel" : "confirm");
53466
+ }
53467
+ },
53468
+ {
53469
+ bind: "right",
53470
+ title: "Next dialog option",
53471
+ group: "Dialog",
53472
+ run: () => {
53473
+ setStore("active", store.active === "confirm" ? "cancel" : "confirm");
53474
+ }
53475
+ },
53476
+ {
53477
+ bind: "tab",
53478
+ title: "Next dialog option",
53479
+ group: "Dialog",
53480
+ run: () => {
53481
+ setStore("active", store.active === "confirm" ? "cancel" : "confirm");
53482
+ }
53483
+ },
53484
+ {
53485
+ bind: "shift+tab",
53486
+ title: "Previous dialog option",
53487
+ group: "Dialog",
53488
+ run: () => {
53489
+ setStore("active", store.active === "confirm" ? "cancel" : "confirm");
53490
+ }
53491
+ }
53492
+ ], ...(props.extraActions ?? []).map((action) => ({
53493
+ bind: action.bind,
53494
+ title: action.title ?? action.label,
53495
+ group: "Dialog",
53496
+ run: () => chooseExtra(action)
53497
+ }))]
53498
+ }));
53499
+ return createComponent2(DialogLayout, {
53500
+ get header() {
53501
+ return createComponent2(DialogHeader, {
53502
+ get title() {
53503
+ return props.title;
53504
+ },
53505
+ get titleView() {
53506
+ return (() => {
53507
+ var _el$2 = createElement("box"), _el$3 = createElement("text");
53508
+ insertNode(_el$2, _el$3);
53509
+ setProp(_el$2, "flexDirection", "row");
53510
+ insert(_el$2, createComponent2(ReminderBadge, {}), _el$3);
53511
+ setProp(_el$3, "wrapMode", "none");
53512
+ insert(_el$3, () => props.title.replace(/^\u26A0\s*/, ""));
53513
+ effect((_p$) => {
53514
+ var _v$ = newDesigns() ? undefined : TextAttributes7.BOLD, _v$2 = theme.text.base;
53515
+ _v$ !== _p$.e && (_p$.e = setProp(_el$3, "attributes", _v$, _p$.e));
53516
+ _v$2 !== _p$.t && (_p$.t = setProp(_el$3, "fg", _v$2, _p$.t));
53517
+ return _p$;
53518
+ }, {
53519
+ e: undefined,
53520
+ t: undefined
53521
+ });
53522
+ return _el$2;
53523
+ })();
53524
+ }
53525
+ });
53526
+ },
53527
+ get footer() {
53528
+ return {
53529
+ actions: {
53530
+ secondary: (props.extraActions ?? []).map((action) => ({
53531
+ title: action.label.toLowerCase(),
53532
+ key: action.bind,
53533
+ onTrigger: () => chooseExtra(action)
53534
+ })),
53535
+ primary: [
53536
+ {
53537
+ title: (props.label?.cancel ?? "cancel").toLowerCase(),
53538
+ key: "esc",
53539
+ onTrigger: () => choose("cancel")
53540
+ },
53541
+ {
53542
+ title: (props.label?.confirm ?? "confirm").toLowerCase(),
53543
+ key: "enter",
53544
+ onTrigger: () => choose("confirm")
53545
+ }
53546
+ ]
53547
+ }
53548
+ };
53549
+ },
53550
+ get legacyFooter() {
53551
+ return (() => {
53552
+ var _el$4 = createElement("box"), _el$5 = createElement("box"), _el$6 = createElement("box");
53553
+ insertNode(_el$4, _el$5);
53554
+ insertNode(_el$4, _el$6);
53555
+ setProp(_el$4, "flexDirection", "row");
53556
+ setProp(_el$4, "justifyContent", "space-between");
53557
+ setProp(_el$4, "gap", 1);
53558
+ setProp(_el$5, "flexDirection", "row");
53559
+ insert(_el$5, createComponent2(For, {
53560
+ get each() {
53561
+ return props.extraActions ?? [];
53474
53562
  },
53475
- get children() {
53476
- var _el$6 = createElement("text");
53477
- setProp(_el$6, "wrapMode", "none");
53478
- setProp(_el$6, "paddingLeft", 1);
53479
- insert(_el$6, indicatorText);
53480
- effect((_$p) => setProp(_el$6, "fg", muted(), _$p));
53481
- return _el$6;
53482
- }
53483
- }), null);
53484
- effect((_p$) => {
53485
- var _v$ = background(), _v$2 = viewportRows();
53486
- _v$ !== _p$.e && (_p$.e = setProp(_el$3, "backgroundColor", _v$, _p$.e));
53487
- _v$2 !== _p$.t && (_p$.t = setProp(_el$4, "height", _v$2, _p$.t));
53488
- return _p$;
53489
- }, {
53490
- e: undefined,
53491
- t: undefined
53492
- });
53493
- return _el$3;
53494
- })()
53495
- }), null);
53496
- effect((_$p) => setProp(_el$2, "visible", !dock.isOpen(), _$p));
53497
- return _el$;
53498
- })();
53563
+ children: (action) => (() => {
53564
+ var _el$7 = createElement("box"), _el$8 = createElement("text");
53565
+ insertNode(_el$7, _el$8);
53566
+ setProp(_el$7, "paddingLeft", 1);
53567
+ setProp(_el$7, "paddingRight", 1);
53568
+ setProp(_el$7, "onMouseUp", () => chooseExtra(action));
53569
+ insert(_el$8, () => `${action.label} [${action.bind}]`);
53570
+ effect((_$p) => setProp(_el$8, "fg", theme.text.muted, _$p));
53571
+ return _el$7;
53572
+ })()
53573
+ }));
53574
+ setProp(_el$6, "flexDirection", "row");
53575
+ insert(_el$6, createComponent2(For, {
53576
+ each: ["cancel", "confirm"],
53577
+ children: (key) => (() => {
53578
+ var _el$9 = createElement("box"), _el$0 = createElement("text");
53579
+ insertNode(_el$9, _el$0);
53580
+ setProp(_el$9, "paddingLeft", 1);
53581
+ setProp(_el$9, "paddingRight", 1);
53582
+ setProp(_el$9, "onMouseUp", () => choose(key));
53583
+ insert(_el$0, () => titlecase(props.label?.[key] ?? key));
53584
+ effect((_p$) => {
53585
+ var _v$3 = key === store.active ? row().backgroundColor : undefined, _v$4 = key === store.active ? row().textColor : theme.text.muted;
53586
+ _v$3 !== _p$.e && (_p$.e = setProp(_el$9, "backgroundColor", _v$3, _p$.e));
53587
+ _v$4 !== _p$.t && (_p$.t = setProp(_el$0, "fg", _v$4, _p$.t));
53588
+ return _p$;
53589
+ }, {
53590
+ e: undefined,
53591
+ t: undefined
53592
+ });
53593
+ return _el$9;
53594
+ })()
53595
+ }));
53596
+ return _el$4;
53597
+ })();
53598
+ },
53599
+ get children() {
53600
+ var _el$ = createElement("text");
53601
+ insert(_el$, () => props.message);
53602
+ effect((_$p) => setProp(_el$, "fg", theme.text.muted, _$p));
53603
+ return _el$;
53604
+ }
53605
+ });
53499
53606
  }
53500
- var DOCK_MAX_ROWS_RATIO = 0.6, Context7, ordinal2 = 0;
53501
- var init_dock_host = __esm(() => {
53502
- init_index_bun();
53503
- init_index_bun();
53607
+ var init_dialog_confirm = __esm(() => {
53504
53608
  init_index_bun();
53505
53609
  init_index_bun();
53506
53610
  init_index_bun();
53507
53611
  init_index_bun();
53508
53612
  init_index_bun();
53509
53613
  init_index_bun();
53510
- init_server();
53511
53614
  init_index_bun();
53512
- init_input_ownership();
53615
+ init_keymap();
53513
53616
  init_theme3();
53514
- init_terminal_size();
53515
- Context7 = createContext(undefined);
53617
+ init_config();
53618
+ init_dialog();
53619
+ init_server2();
53620
+ init_server();
53621
+ init_locale();
53622
+ init_semantic();
53623
+ init_turn_overlays();
53516
53624
  });
53517
53625
 
53518
- // ../tui-base/src/routes/session/ask-panel.tsx
53519
- function resolveFocus(ask, list, input) {
53520
- if (ask === undefined)
53521
- return;
53522
- if (ask.phase === "input")
53523
- return input;
53524
- return list ?? input;
53626
+ // ../tui-base/src/routes/session/turn-cancel.tsx
53627
+ function armNonArmingInterrupt() {
53628
+ nonArmingInterrupt = true;
53525
53629
  }
53526
- function nearestScroller(node) {
53527
- let current = node;
53528
- while (current !== null && current !== undefined) {
53529
- const candidate = current;
53530
- if (typeof candidate.scrollChildIntoView === "function")
53531
- return current;
53532
- current = current.parent;
53533
- }
53534
- return;
53630
+ function consumeNonArmingInterrupt() {
53631
+ const armed = nonArmingInterrupt;
53632
+ nonArmingInterrupt = false;
53633
+ return armed;
53535
53634
  }
53536
- function AskPanel(props) {
53537
- const theme = useThemeOptional();
53538
- const dock = useDock();
53539
- let configCursorStyle;
53540
- try {
53541
- configCursorStyle = useCursorStyle();
53542
- } catch {
53543
- configCursorStyle = undefined;
53544
- }
53545
- const [version, setVersion] = createSignal(0);
53546
- onMount(() => {
53547
- const unsubscribe = props.controller.subscribe(() => setVersion((value) => value + 1));
53548
- onCleanup(unsubscribe);
53549
- });
53550
- const ask = () => {
53551
- version();
53552
- return props.controller.pendingAsk;
53553
- };
53554
- const questions = () => ask()?.questions ?? [];
53555
- const question = () => {
53556
- const batch = ask();
53557
- return batch?.questions[batch.index];
53635
+ function createTurnCancel(props, onArm, confirmQuit) {
53636
+ const windowMs = props.windowMs ?? CTRL_C_QUIT_WINDOW_MS;
53637
+ let timer;
53638
+ let armedKey;
53639
+ let busyInterrupted = false;
53640
+ let lastBusy = false;
53641
+ const disarm = () => {
53642
+ if (timer)
53643
+ clearTimeout(timer);
53644
+ timer = undefined;
53645
+ const key = armedKey;
53646
+ armedKey = undefined;
53647
+ if (key)
53648
+ onArm(false, key);
53558
53649
  };
53559
- const index = () => ask()?.index ?? 0;
53560
- const phase = () => ask()?.phase ?? "questions";
53561
- const phaseOf = () => {
53562
- if (phase() === "review")
53563
- return "review";
53564
- return phase() === "input" ? "input" : "options";
53650
+ const arm = (key, beforeExpire) => {
53651
+ if (timer)
53652
+ clearTimeout(timer);
53653
+ armedKey = key;
53654
+ onArm(true, key);
53655
+ timer = setTimeout(() => {
53656
+ timer = undefined;
53657
+ beforeExpire?.();
53658
+ disarm();
53659
+ }, windowMs);
53565
53660
  };
53566
- const picks = () => {
53567
- const batch = ask();
53568
- return batch ? batch.picks[batch.index] ?? [] : [];
53569
- };
53570
- const cursor = () => {
53571
- const batch = ask();
53572
- return batch ? batch.cursors[batch.index] ?? 0 : 0;
53573
- };
53574
- const listCursor = () => {
53575
- const batch = ask();
53576
- return batch ? batch.listCursors[batch.index] ?? 0 : 0;
53661
+ return {
53662
+ escape() {
53663
+ if (!props.busy() || props.escapeYields?.())
53664
+ return false;
53665
+ if (!props.confirmStop) {
53666
+ props.interrupt();
53667
+ return true;
53668
+ }
53669
+ if (armedKey === "escape") {
53670
+ disarm();
53671
+ props.confirmStop();
53672
+ return true;
53673
+ }
53674
+ arm("escape");
53675
+ return true;
53676
+ },
53677
+ ctrlC() {
53678
+ if (armedKey === "escape")
53679
+ disarm();
53680
+ const busy = props.busy();
53681
+ if (busy && !lastBusy)
53682
+ busyInterrupted = false;
53683
+ if (consumeNonArmingInterrupt() && busy) {
53684
+ props.interrupt();
53685
+ busyInterrupted = true;
53686
+ lastBusy = props.busy();
53687
+ return true;
53688
+ }
53689
+ if (busy && !busyInterrupted) {
53690
+ props.interrupt();
53691
+ busyInterrupted = true;
53692
+ lastBusy = props.busy();
53693
+ return true;
53694
+ }
53695
+ busyInterrupted = false;
53696
+ lastBusy = props.busy();
53697
+ confirmQuit();
53698
+ return true;
53699
+ },
53700
+ dispose: disarm
53577
53701
  };
53578
- const markedRow = () => phaseOf() === "input" ? listCursor() : cursor();
53579
- const reviewCursor = () => ask()?.reviewCursor ?? 0;
53580
- const multi = () => question()?.multiSelect === true;
53581
- const compact = () => props.width() < ASK_COMPACT_COLUMNS;
53582
- const needsReview = () => askNeedsReview(questions());
53583
- const eyebrow = () => {
53584
- if (phaseOf() === "review")
53585
- return;
53586
- const current = question();
53587
- if (current?.header === undefined || current.header === current.prompt)
53588
- return;
53589
- return current.header;
53702
+ }
53703
+ function TurnCancelKeys(props) {
53704
+ const theme = useThemeOptional();
53705
+ const dialog = useDialog();
53706
+ const [armed, setArmed] = createSignal(undefined);
53707
+ const openQuitDialog = () => {
53708
+ dialog.replace(() => createComponent2(DialogConfirm, {
53709
+ get title() {
53710
+ return t("turn.quit.confirmTitle");
53711
+ },
53712
+ get message() {
53713
+ return t("turn.quit.confirmMessage");
53714
+ },
53715
+ get label() {
53716
+ return {
53717
+ confirm: t("turn.quit.confirmLabel"),
53718
+ cancel: t("turn.quit.cancelLabel")
53719
+ };
53720
+ },
53721
+ get onConfirm() {
53722
+ return props.quit;
53723
+ }
53724
+ }), undefined, {
53725
+ tone: "warning"
53726
+ });
53590
53727
  };
53591
- const muted = () => theme?.text.muted ?? "#9aa5ce";
53592
- const faint = () => theme?.text.faint ?? "#565f89";
53593
- const base = () => theme?.text.base ?? "#e6e6e6";
53594
- const accent = () => theme?.hue.interactive[500] ?? "#7aa2f7";
53595
- const currentBg = () => theme?.background.action.primary.focused;
53596
- const currentFg = () => theme?.text.action.primary.focused ?? accent();
53597
- const rule = () => theme?.border.base ?? "#565f89";
53598
- const cursorShape = () => {
53599
- try {
53600
- return configCursorStyle?.()?.style;
53601
- } catch {
53602
- return;
53728
+ const cancel = createTurnCancel(props, (value, key) => setArmed(value ? key : undefined), openQuitDialog);
53729
+ onCleanup(() => cancel.dispose());
53730
+ Keymap2.createLayer(() => ({
53731
+ mode: "global",
53732
+ enabled: props.enabled(),
53733
+ commands: [{
53734
+ bind: "escape",
53735
+ title: props.confirmStop ? "Stop current turn (press Esc twice)" : "Interrupt current turn",
53736
+ group: "Session",
53737
+ run: () => cancel.escape()
53738
+ }, {
53739
+ bind: "ctrl+c",
53740
+ title: "Quit / interrupt turn",
53741
+ group: "Session",
53742
+ run: () => cancel.ctrlC()
53743
+ }]
53744
+ }));
53745
+ return createComponent2(Show, {
53746
+ get when() {
53747
+ return armed();
53748
+ },
53749
+ get children() {
53750
+ var _el$ = createElement("box"), _el$2 = createElement("text");
53751
+ insertNode(_el$, _el$2);
53752
+ setProp(_el$, "height", 1);
53753
+ setProp(_el$, "flexShrink", 0);
53754
+ setProp(_el$, "paddingLeft", 1);
53755
+ setProp(_el$2, "wrapMode", "none");
53756
+ insert(_el$2, () => t("turn.stop.escHint"));
53757
+ effect((_$p) => setProp(_el$2, "fg", theme?.text.feedback.warning.base ?? "#e0af68", _$p));
53758
+ return _el$;
53603
53759
  }
53604
- };
53605
- let listEl;
53606
- let inputEl;
53607
- let inlineRowEl;
53608
- useAskKeys({
53609
- controller: props.controller,
53610
- input: () => inputEl
53611
53760
  });
53612
- const queuedCount = () => {
53613
- version();
53614
- return props.queued?.() ?? dock.queueDepth();
53615
- };
53616
- props.onFocusTarget?.(() => resolveFocus(ask(), listEl, inputEl));
53617
- function revealRow(row) {
53618
- if (row === undefined || row.isDestroyed)
53761
+ }
53762
+ var CTRL_C_QUIT_WINDOW_MS = 500, nonArmingInterrupt = false;
53763
+ var init_turn_cancel = __esm(() => {
53764
+ init_index_bun();
53765
+ init_index_bun();
53766
+ init_index_bun();
53767
+ init_index_bun();
53768
+ init_index_bun();
53769
+ init_index_bun();
53770
+ init_server();
53771
+ init_keymap();
53772
+ init_theme3();
53773
+ init_i18n();
53774
+ init_dialog();
53775
+ init_dialog_confirm();
53776
+ });
53777
+
53778
+ // ../tui-base/src/routes/session/stop-all.ts
53779
+ async function stopEverything(seam) {
53780
+ const turn = seam.status?.().turn;
53781
+ const parent = turn !== undefined && turn !== "idle";
53782
+ if (parent)
53783
+ seam.interrupt();
53784
+ if (seam.hasBridgeCapability?.("subagents.stopChildren") === true && seam.stopChildren) {
53785
+ let dispositions = [];
53786
+ try {
53787
+ dispositions = await seam.stopChildren();
53788
+ } catch {}
53789
+ return {
53790
+ parent,
53791
+ children: dispositions.filter((row) => row.disposition === "cancel-issued").length,
53792
+ dispositions
53793
+ };
53794
+ }
53795
+ let children = 0;
53796
+ for (const view of seam.subagentViews?.() ?? []) {
53797
+ if (view.status !== "running" || !seam.interruptChild)
53798
+ continue;
53799
+ try {
53800
+ await seam.interruptChild(view.id);
53801
+ children++;
53802
+ } catch {}
53803
+ }
53804
+ return { parent, children };
53805
+ }
53806
+
53807
+ // ../tui-base/src/routes/session/turn-overlay-controller.ts
53808
+ function askSignature(questions) {
53809
+ return JSON.stringify(questions.map((question) => [
53810
+ question.id,
53811
+ question.prompt,
53812
+ question.header,
53813
+ question.description,
53814
+ question.detail,
53815
+ question.multiSelect === true,
53816
+ question.options.map((option) => [option.label, option.description])
53817
+ ]));
53818
+ }
53819
+
53820
+ class TurnOverlayController {
53821
+ #approvals = [];
53822
+ #asks = [];
53823
+ #seq = 0;
53824
+ #listeners = new Set;
53825
+ #idleHandlers = new Set;
53826
+ #busy = false;
53827
+ #pendingAsks;
53828
+ subscribe(fn) {
53829
+ this.#listeners.add(fn);
53830
+ return () => this.#listeners.delete(fn);
53831
+ }
53832
+ attachPendingAsks(read) {
53833
+ this.#pendingAsks = read;
53834
+ }
53835
+ invalidateAsk(eventId, reason) {
53836
+ if (eventId === "")
53619
53837
  return;
53620
- const scroller = nearestScroller(row);
53621
- if (scroller === undefined)
53838
+ if (this.#approvals.some((entry) => entry.request.invalidatedReason !== undefined && entry.request.eventId === eventId))
53622
53839
  return;
53623
- scroller.scrollChildIntoView(row, {
53624
- align: "nearest"
53840
+ this.#approvals = this.#approvals.filter((entry) => {
53841
+ if (entry.request.eventId !== eventId)
53842
+ return true;
53843
+ entry.resolve("rejected");
53844
+ return false;
53845
+ });
53846
+ this.#asks = this.#asks.filter((entry) => {
53847
+ if (entry.eventId !== eventId)
53848
+ return true;
53849
+ entry.resolve([]);
53850
+ return false;
53851
+ });
53852
+ this.#approvals.push({
53853
+ request: {
53854
+ id: ++this.#seq,
53855
+ name: "ask",
53856
+ args: {},
53857
+ eventId,
53858
+ escalation: false,
53859
+ invalidatedReason: reason
53860
+ },
53861
+ resolve: () => {}
53625
53862
  });
53863
+ this.#changed();
53626
53864
  }
53627
- function focusInputRow() {
53628
- const input = inputEl;
53629
- if (input === undefined || input.isDestroyed)
53865
+ invalidateAll(reason) {
53866
+ if (reason === "")
53630
53867
  return;
53631
- input.focus();
53632
- revealRow(inlineRowEl);
53633
- }
53634
- createEffect(on(() => phase(), (next) => {
53635
- if (next === "input") {
53636
- focusInputRow();
53868
+ const open = this.#approvals.length + this.#asks.length;
53869
+ if (open === 0)
53637
53870
  return;
53871
+ const terminals = [];
53872
+ for (const entry of this.#approvals) {
53873
+ terminals.push({
53874
+ request: {
53875
+ id: ++this.#seq,
53876
+ name: "ask",
53877
+ args: {},
53878
+ ...entry.request.eventId !== undefined ? { eventId: entry.request.eventId } : {},
53879
+ escalation: false,
53880
+ invalidatedReason: reason
53881
+ },
53882
+ resolve: () => {}
53883
+ });
53638
53884
  }
53639
- if (next !== "questions")
53640
- return;
53641
- const focusList = () => {
53642
- if (listEl !== undefined && !listEl.isDestroyed)
53643
- listEl.focus();
53644
- };
53645
- if (listEl !== undefined && !listEl.isDestroyed)
53646
- focusList();
53647
- else
53648
- queueMicrotask(focusList);
53649
- }));
53650
- createEffect(on(() => index(), () => phase() === "input" ? focusInputRow() : undefined, {
53651
- defer: true
53652
- }));
53653
- createEffect(on([() => index(), cursor], () => {
53654
- if (phaseOf() !== "options")
53655
- return;
53656
- revealRow(listEl?.getChildren()[cursor()]);
53657
- }));
53658
- const optionRows = () => (question()?.options ?? []).map((option, position) => ({
53659
- option,
53660
- number: position + 1,
53661
- selected: picks().includes(option.label)
53662
- }));
53663
- const labelColumn = (row) => GUTTER + CURSOR_CELLS + STATE_CELLS + `${row.number}. `.length;
53664
- const footerHint = () => {
53665
- if (phaseOf() === "review")
53666
- return t("overlay.ask.footer.review", {
53667
- esc: t("overlay.ask.esc.review")
53885
+ for (const entry of this.#asks) {
53886
+ terminals.push({
53887
+ request: {
53888
+ id: ++this.#seq,
53889
+ name: "ask",
53890
+ args: {},
53891
+ ...entry.eventId !== undefined ? { eventId: entry.eventId } : {},
53892
+ escalation: false,
53893
+ invalidatedReason: reason
53894
+ },
53895
+ resolve: () => {}
53668
53896
  });
53669
- if (phaseOf() === "input") {
53670
- const escKey = question()?.options.length === 0 ? index() > 0 ? "overlay.ask.esc.prevQuestion" : "overlay.ask.esc.decline" : "overlay.ask.esc.back";
53671
- return t("overlay.ask.footer.input", {
53672
- esc: t(escKey)
53897
+ }
53898
+ for (const entry of this.#approvals)
53899
+ entry.resolve("rejected");
53900
+ for (const entry of this.#asks)
53901
+ entry.resolve([]);
53902
+ this.#approvals = terminals;
53903
+ this.#asks = [];
53904
+ this.#changed();
53905
+ }
53906
+ pendingInvalidated() {
53907
+ const out = new Map;
53908
+ for (const entry of this.#approvals) {
53909
+ if (entry.request.invalidatedReason !== undefined && entry.request.eventId !== undefined) {
53910
+ out.set(entry.request.eventId, entry.request.invalidatedReason);
53911
+ }
53912
+ }
53913
+ return out;
53914
+ }
53915
+ onIdle(fn) {
53916
+ this.#idleHandlers.add(fn);
53917
+ return () => this.#idleHandlers.delete(fn);
53918
+ }
53919
+ #changed() {
53920
+ for (const listener of this.#listeners)
53921
+ listener();
53922
+ const busy = this.#approvals.length > 0 || this.#asks.length > 0;
53923
+ if (this.#busy && !busy)
53924
+ for (const handler of this.#idleHandlers)
53925
+ handler();
53926
+ this.#busy = busy;
53927
+ }
53928
+ get pendingApproval() {
53929
+ return this.#approvals[0]?.request;
53930
+ }
53931
+ get pendingApprovalCount() {
53932
+ return this.#approvals.length;
53933
+ }
53934
+ get pendingAskCount() {
53935
+ return this.#asks.length;
53936
+ }
53937
+ requestApproval(name, args) {
53938
+ const ask = this.#matchApproval(name, args);
53939
+ const promise = new Promise((resolve) => {
53940
+ this.#approvals.push({
53941
+ request: {
53942
+ id: ++this.#seq,
53943
+ name,
53944
+ args,
53945
+ escalation: ask?.escalation === true,
53946
+ ...ask !== undefined ? { eventId: ask.eventId } : {}
53947
+ },
53948
+ resolve
53673
53949
  });
53950
+ this.#changed();
53951
+ });
53952
+ return promise;
53953
+ }
53954
+ #matchApproval(name, args) {
53955
+ const asks = (this.#pendingAsks?.() ?? []).filter((ask) => ask.kind === "approval");
53956
+ if (asks.length === 0)
53957
+ return;
53958
+ const callId = typeof args.callId === "string" ? args.callId : undefined;
53959
+ if (callId !== undefined) {
53960
+ const byCall = asks.filter((ask) => ask.callId === callId);
53961
+ return byCall.length > 0 ? byCall[byCall.length - 1] : undefined;
53674
53962
  }
53675
- const escKey = questions().length > 1 && index() > 0 ? "overlay.ask.esc.prevQuestion" : "overlay.ask.esc.decline";
53676
- return t(multi() ? "overlay.ask.footer.multi" : "overlay.ask.footer.options", {
53677
- esc: t(escKey)
53963
+ const reason = typeof args.reason === "string" ? args.reason : undefined;
53964
+ const byName = asks.filter((ask) => (ask.toolName ?? "tool") === name && (reason === undefined || ask.reason === reason));
53965
+ if (byName.length > 0)
53966
+ return byName[byName.length - 1];
53967
+ return asks.length === 1 ? asks[0] : undefined;
53968
+ }
53969
+ confirmApproval() {
53970
+ this.#settleApproval("allowed-once");
53971
+ }
53972
+ rejectApproval() {
53973
+ this.#settleApproval("rejected");
53974
+ }
53975
+ approveAlways() {
53976
+ this.#settleEscalated("always");
53977
+ }
53978
+ approveSession() {
53979
+ this.#settleEscalated("session");
53980
+ }
53981
+ #settleEscalated(verdict) {
53982
+ if (this.#approvals[0]?.request.escalation !== true)
53983
+ return;
53984
+ this.#settleApproval(verdict);
53985
+ }
53986
+ #settleApproval(verdict) {
53987
+ const head = this.#approvals.shift();
53988
+ if (!head)
53989
+ return;
53990
+ head.resolve(verdict);
53991
+ this.#changed();
53992
+ }
53993
+ syncPendingAsks() {
53994
+ if (this.#pendingAsks === undefined)
53995
+ return;
53996
+ const asks = this.#pendingAsks();
53997
+ let changed = false;
53998
+ const approvalsBefore = this.#approvals.length;
53999
+ this.#approvals = this.#approvals.filter((entry) => {
54000
+ if (this.#approvalStillPending(entry.request, asks))
54001
+ return true;
54002
+ entry.resolve("rejected");
54003
+ return false;
53678
54004
  });
53679
- };
53680
- const answerText = (qi) => {
53681
- const batch = ask();
53682
- if (!batch)
53683
- return "";
53684
- const custom = batch.customs[qi];
53685
- if (custom !== undefined && custom !== "")
53686
- return custom;
53687
- return (batch.picks[qi] ?? []).map((label) => splitRecommended(label).label).join(", ");
53688
- };
53689
- const reviewRowActive = (qi) => reviewCursor() === qi;
53690
- const reviewSubmitActive = () => reviewRowIntent(reviewCursor(), questions().length).kind === "submit";
53691
- return (() => {
53692
- var _el$ = createElement("box"), _el$2 = createElement("box"), _el$3 = createElement("box"), _el$4 = createElement("text"), _el$1 = createElement("box"), _el$10 = createElement("text"), _el$12 = createElement("box");
53693
- insertNode(_el$, _el$2);
53694
- insertNode(_el$, _el$3);
53695
- insertNode(_el$, _el$1);
53696
- insertNode(_el$, _el$12);
53697
- setProp(_el$, "flexDirection", "column");
53698
- setProp(_el$, "width", "100%");
53699
- setProp(_el$, "flexShrink", 0);
53700
- setProp(_el$2, "width", "100%");
53701
- setProp(_el$2, "flexShrink", 0);
53702
- setProp(_el$2, "border", ["top"]);
53703
- setProp(_el$2, "borderStyle", "single");
53704
- insert(_el$, createComponent2(Show, {
53705
- get when() {
53706
- return eyebrow();
53707
- },
53708
- children: (header) => (() => {
53709
- var _el$13 = createElement("box"), _el$14 = createElement("text");
53710
- insertNode(_el$13, _el$14);
53711
- setProp(_el$13, "paddingLeft", 2);
53712
- setProp(_el$13, "paddingRight", 2);
53713
- setProp(_el$14, "wrapMode", "none");
53714
- insert(_el$14, header);
53715
- effect((_$p) => setProp(_el$14, "fg", muted(), _$p));
53716
- return _el$13;
53717
- })()
53718
- }), _el$3);
53719
- insertNode(_el$3, _el$4);
53720
- setProp(_el$3, "paddingLeft", 2);
53721
- setProp(_el$3, "paddingRight", 2);
53722
- setProp(_el$4, "wrapMode", "word");
53723
- insert(_el$4, (() => {
53724
- var _c$ = memo2(() => phaseOf() === "review");
53725
- return () => _c$() ? t("overlay.ask.reviewTitle") : question()?.prompt ?? "";
53726
- })());
53727
- insert(_el$, createComponent2(Show, {
53728
- get when() {
53729
- return questions().length >= 2;
53730
- },
53731
- get children() {
53732
- var _el$5 = createElement("box"), _el$6 = createElement("text");
53733
- insertNode(_el$5, _el$6);
53734
- setProp(_el$5, "paddingLeft", 2);
53735
- setProp(_el$5, "paddingRight", 2);
53736
- setProp(_el$6, "wrapMode", "none");
53737
- insert(_el$6, () => askTabStrip(questions(), ask()?.picks ?? [], index(), ask()?.customs));
53738
- effect((_$p) => setProp(_el$6, "fg", muted(), _$p));
53739
- return _el$5;
53740
- }
53741
- }), _el$1);
53742
- insert(_el$, createComponent2(Show, {
53743
- get when() {
53744
- return memo2(() => phaseOf() !== "review")() ? question()?.detail : undefined;
53745
- },
53746
- children: (detail) => (() => {
53747
- var _el$15 = createElement("box"), _el$16 = createElement("text");
53748
- insertNode(_el$15, _el$16);
53749
- setProp(_el$15, "paddingLeft", 2);
53750
- setProp(_el$15, "paddingRight", 2);
53751
- setProp(_el$16, "wrapMode", "word");
53752
- insert(_el$16, detail);
53753
- effect((_$p) => setProp(_el$16, "fg", muted(), _$p));
53754
- return _el$15;
53755
- })()
53756
- }), _el$1);
53757
- insert(_el$, createComponent2(Show, {
53758
- get when() {
53759
- return phaseOf() === "review";
53760
- },
53761
- get fallback() {
53762
- return [(() => {
53763
- var _el$17 = createElement("box");
53764
- use((value) => {
53765
- listEl = value;
53766
- }, _el$17);
53767
- setProp(_el$17, "flexDirection", "column");
53768
- setProp(_el$17, "width", "100%");
53769
- setProp(_el$17, "flexShrink", 0);
53770
- setProp(_el$17, "focusable", true);
53771
- insert(_el$17, createComponent2(Index, {
53772
- get each() {
53773
- return optionRows();
53774
- },
53775
- children: (row, position) => createComponent2(OptionRow, {
53776
- row,
53777
- cursor: () => phaseOf() !== "input" && position === cursor(),
53778
- marked: () => position === markedRow(),
53779
- multi: () => multi(),
53780
- compact: () => compact(),
53781
- width: () => props.width(),
53782
- labelColumn: () => labelColumn(row())
53783
- })
53784
- }), null);
53785
- insert(_el$17, createComponent2(Show, {
53786
- get when() {
53787
- return memo2(() => question() !== undefined)() && hasReviewRow(question(), needsReview());
53788
- },
53789
- get children() {
53790
- var _el$18 = createElement("box"), _el$19 = createElement("text"), _el$20 = createElement("text");
53791
- insertNode(_el$18, _el$19);
53792
- insertNode(_el$18, _el$20);
53793
- setProp(_el$18, "flexDirection", "row");
53794
- setProp(_el$18, "width", "100%");
53795
- setProp(_el$18, "flexShrink", 0);
53796
- setProp(_el$18, "paddingLeft", 2);
53797
- insert(_el$19, () => markedRow() === (question()?.options.length ?? 0) ? "\u203A " : " ");
53798
- setProp(_el$20, "wrapMode", "word");
53799
- insert(_el$20, () => t("overlay.ask.reviewRow"));
53800
- effect((_p$) => {
53801
- var _v$8 = phaseOf() !== "input" && markedRow() === (question()?.options.length ?? 0) ? currentBg() : undefined, _v$9 = phaseOf() !== "input" && markedRow() === (question()?.options.length ?? 0) ? accent() : faint(), _v$0 = phaseOf() !== "input" && markedRow() === (question()?.options.length ?? 0) ? currentFg() : muted();
53802
- _v$8 !== _p$.e && (_p$.e = setProp(_el$18, "backgroundColor", _v$8, _p$.e));
53803
- _v$9 !== _p$.t && (_p$.t = setProp(_el$19, "fg", _v$9, _p$.t));
53804
- _v$0 !== _p$.a && (_p$.a = setProp(_el$20, "fg", _v$0, _p$.a));
53805
- return _p$;
53806
- }, {
53807
- e: undefined,
53808
- t: undefined,
53809
- a: undefined
53810
- });
53811
- return _el$18;
53812
- }
53813
- }), null);
53814
- return _el$17;
53815
- })(), (() => {
53816
- var _el$21 = createElement("box"), _el$22 = createElement("text"), _el$24 = createElement("input");
53817
- insertNode(_el$21, _el$22);
53818
- insertNode(_el$21, _el$24);
53819
- use((value) => {
53820
- inlineRowEl = value;
53821
- }, _el$21);
53822
- setProp(_el$21, "flexDirection", "row");
53823
- setProp(_el$21, "width", "100%");
53824
- setProp(_el$21, "flexShrink", 0);
53825
- setProp(_el$21, "paddingLeft", 2);
53826
- insertNode(_el$22, createTextNode(`\u270E `));
53827
- use((value) => {
53828
- inputEl = value;
53829
- }, _el$24);
53830
- setProp(_el$24, "flexGrow", 1);
53831
- setProp(_el$24, "onInput", (value) => props.controller.setInlineText(value));
53832
- setProp(_el$24, "onSubmit", () => props.controller.commitCustom());
53833
- effect((_p$) => {
53834
- var _v$1 = phaseOf() === "input" ? currentBg() : undefined, _v$10 = phaseOf() === "input" ? currentFg() : muted(), _v$11 = props.controller.inlineText, _v$12 = t("overlay.ask.inputPlaceholder"), _v$13 = muted(), _v$14 = base(), _v$15 = currentFg(), _v$16 = phaseOf() === "input" ? currentFg() : accent(), _v$17 = cursorShape();
53835
- _v$1 !== _p$.e && (_p$.e = setProp(_el$21, "backgroundColor", _v$1, _p$.e));
53836
- _v$10 !== _p$.t && (_p$.t = setProp(_el$22, "fg", _v$10, _p$.t));
53837
- _v$11 !== _p$.a && (_p$.a = setProp(_el$24, "value", _v$11, _p$.a));
53838
- _v$12 !== _p$.o && (_p$.o = setProp(_el$24, "placeholder", _v$12, _p$.o));
53839
- _v$13 !== _p$.i && (_p$.i = setProp(_el$24, "placeholderColor", _v$13, _p$.i));
53840
- _v$14 !== _p$.n && (_p$.n = setProp(_el$24, "textColor", _v$14, _p$.n));
53841
- _v$15 !== _p$.s && (_p$.s = setProp(_el$24, "focusedTextColor", _v$15, _p$.s));
53842
- _v$16 !== _p$.h && (_p$.h = setProp(_el$24, "cursorColor", _v$16, _p$.h));
53843
- _v$17 !== _p$.r && (_p$.r = setProp(_el$24, "cursorStyle", _v$17, _p$.r));
53844
- return _p$;
53845
- }, {
53846
- e: undefined,
53847
- t: undefined,
53848
- a: undefined,
53849
- o: undefined,
53850
- i: undefined,
53851
- n: undefined,
53852
- s: undefined,
53853
- h: undefined,
53854
- r: undefined
53855
- });
53856
- return _el$21;
53857
- })()];
53858
- },
53859
- get children() {
53860
- var _el$7 = createElement("box"), _el$8 = createElement("box"), _el$9 = createElement("text"), _el$0 = createElement("text");
53861
- insertNode(_el$7, _el$8);
53862
- setProp(_el$7, "flexDirection", "column");
53863
- setProp(_el$7, "width", "100%");
53864
- setProp(_el$7, "flexShrink", 0);
53865
- insert(_el$7, createComponent2(Index, {
53866
- get each() {
53867
- return questions();
53868
- },
53869
- children: (item, qi) => (() => {
53870
- var _el$25 = createElement("box"), _el$26 = createElement("box"), _el$27 = createElement("text"), _el$28 = createElement("text"), _el$30 = createElement("text"), _el$31 = createElement("box"), _el$32 = createElement("text");
53871
- insertNode(_el$25, _el$26);
53872
- insertNode(_el$25, _el$31);
53873
- setProp(_el$25, "flexDirection", "column");
53874
- setProp(_el$25, "width", "100%");
53875
- setProp(_el$25, "flexShrink", 0);
53876
- insertNode(_el$26, _el$27);
53877
- insertNode(_el$26, _el$28);
53878
- insertNode(_el$26, _el$30);
53879
- setProp(_el$26, "flexDirection", "row");
53880
- setProp(_el$26, "width", "100%");
53881
- setProp(_el$26, "flexShrink", 0);
53882
- setProp(_el$26, "paddingLeft", 2);
53883
- insert(_el$27, () => reviewRowActive(qi) ? "\u203A " : " ");
53884
- insertNode(_el$28, createTextNode(`\u2713 `));
53885
- setProp(_el$30, "wrapMode", "word");
53886
- insert(_el$30, () => item().prompt);
53887
- insertNode(_el$31, _el$32);
53888
- setProp(_el$31, "paddingLeft", 6);
53889
- setProp(_el$32, "wrapMode", "word");
53890
- insert(_el$32, () => `\u2192 ${answerText(qi) !== "" ? answerText(qi) : t("overlay.ask.unanswered")}`);
53891
- effect((_p$) => {
53892
- var _v$18 = reviewRowActive(qi) ? currentBg() : undefined, _v$19 = reviewRowActive(qi) ? currentFg() : accent(), _v$20 = reviewRowActive(qi) ? currentFg() : muted(), _v$21 = reviewRowActive(qi) ? currentFg() : base(), _v$22 = answerText(qi) !== "" ? accent() : faint();
53893
- _v$18 !== _p$.e && (_p$.e = setProp(_el$26, "backgroundColor", _v$18, _p$.e));
53894
- _v$19 !== _p$.t && (_p$.t = setProp(_el$27, "fg", _v$19, _p$.t));
53895
- _v$20 !== _p$.a && (_p$.a = setProp(_el$28, "fg", _v$20, _p$.a));
53896
- _v$21 !== _p$.o && (_p$.o = setProp(_el$30, "fg", _v$21, _p$.o));
53897
- _v$22 !== _p$.i && (_p$.i = setProp(_el$32, "fg", _v$22, _p$.i));
53898
- return _p$;
53899
- }, {
53900
- e: undefined,
53901
- t: undefined,
53902
- a: undefined,
53903
- o: undefined,
53904
- i: undefined
53905
- });
53906
- return _el$25;
53907
- })()
53908
- }), _el$8);
53909
- insertNode(_el$8, _el$9);
53910
- insertNode(_el$8, _el$0);
53911
- setProp(_el$8, "flexDirection", "row");
53912
- setProp(_el$8, "width", "100%");
53913
- setProp(_el$8, "flexShrink", 0);
53914
- setProp(_el$8, "paddingLeft", 2);
53915
- insert(_el$9, () => reviewSubmitActive() ? "\u203A " : " ");
53916
- setProp(_el$0, "wrapMode", "none");
53917
- insert(_el$0, () => t("overlay.ask.submitRow"));
53918
- effect((_p$) => {
53919
- var _v$ = reviewSubmitActive() ? currentBg() : undefined, _v$2 = reviewSubmitActive() ? currentFg() : accent(), _v$3 = reviewSubmitActive() ? currentFg() : base();
53920
- _v$ !== _p$.e && (_p$.e = setProp(_el$8, "backgroundColor", _v$, _p$.e));
53921
- _v$2 !== _p$.t && (_p$.t = setProp(_el$9, "fg", _v$2, _p$.t));
53922
- _v$3 !== _p$.a && (_p$.a = setProp(_el$0, "fg", _v$3, _p$.a));
53923
- return _p$;
53924
- }, {
53925
- e: undefined,
53926
- t: undefined,
53927
- a: undefined
53928
- });
53929
- return _el$7;
53930
- }
53931
- }), _el$1);
53932
- insertNode(_el$1, _el$10);
53933
- setProp(_el$1, "flexDirection", "row");
53934
- setProp(_el$1, "width", "100%");
53935
- setProp(_el$1, "justifyContent", "space-between");
53936
- setProp(_el$1, "paddingLeft", 2);
53937
- setProp(_el$1, "paddingRight", 2);
53938
- setProp(_el$10, "wrapMode", "none");
53939
- insert(_el$10, footerHint);
53940
- insert(_el$1, createComponent2(Show, {
53941
- get when() {
53942
- return queuedCount() > 0;
53943
- },
53944
- get children() {
53945
- var _el$11 = createElement("text");
53946
- setProp(_el$11, "wrapMode", "none");
53947
- insert(_el$11, () => t("overlay.ask.queued", {
53948
- count: queuedCount()
53949
- }));
53950
- effect((_$p) => setProp(_el$11, "fg", muted(), _$p));
53951
- return _el$11;
53952
- }
53953
- }), null);
53954
- setProp(_el$12, "width", "100%");
53955
- setProp(_el$12, "flexShrink", 0);
53956
- setProp(_el$12, "border", ["bottom"]);
53957
- setProp(_el$12, "borderStyle", "single");
53958
- effect((_p$) => {
53959
- var _v$4 = rule(), _v$5 = warningColor(theme), _v$6 = muted(), _v$7 = rule();
53960
- _v$4 !== _p$.e && (_p$.e = setProp(_el$2, "borderColor", _v$4, _p$.e));
53961
- _v$5 !== _p$.t && (_p$.t = setProp(_el$4, "fg", _v$5, _p$.t));
53962
- _v$6 !== _p$.a && (_p$.a = setProp(_el$10, "fg", _v$6, _p$.a));
53963
- _v$7 !== _p$.o && (_p$.o = setProp(_el$12, "borderColor", _v$7, _p$.o));
53964
- return _p$;
53965
- }, {
53966
- e: undefined,
53967
- t: undefined,
53968
- a: undefined,
53969
- o: undefined
53970
- });
53971
- return _el$;
53972
- })();
53973
- }
53974
- function OptionRow(props) {
53975
- const theme = useThemeOptional();
53976
- const muted = () => theme?.text.muted ?? "#9aa5ce";
53977
- const faint = () => theme?.text.faint ?? "#565f89";
53978
- const base = () => theme?.text.base ?? "#e6e6e6";
53979
- const accent = () => theme?.hue.interactive[500] ?? "#7aa2f7";
53980
- const success = () => theme?.text.feedback.success.base ?? "#9ece6a";
53981
- const currentBg = () => theme?.background.action.primary.focused;
53982
- const currentFg = () => theme?.text.action.primary.focused ?? accent();
53983
- const label = () => splitRecommended(props.row().option.label);
53984
- const number = () => `${props.row().number}. `;
53985
- const badge = () => `[${t("overlay.ask.recommended")}]`;
53986
- const stateGlyph = () => {
53987
- if (props.multi())
53988
- return props.row().selected ? "\u25A0 " : "\u25A1 ";
53989
- return props.row().selected ? "\u25CF " : "\u25CB ";
53990
- };
53991
- const stateColor = () => {
53992
- if (props.cursor())
53993
- return currentFg();
53994
- return props.row().selected ? success() : faint();
53995
- };
53996
- const badgeInline = () => {
53997
- if (!label().recommended || props.compact())
54005
+ if (this.#approvals.length !== approvalsBefore)
54006
+ changed = true;
54007
+ const questionsBefore = this.#asks.length;
54008
+ this.#asks = this.#asks.filter((entry) => {
54009
+ if (this.#questionStillPending(entry, asks))
54010
+ return true;
54011
+ entry.resolve([]);
53998
54012
  return false;
53999
- const used = props.labelColumn() + stringWidth(label().label) + BADGE_GAP + stringWidth(badge());
54000
- return used <= props.width();
54001
- };
54002
- const labelColor = () => props.cursor() ? currentFg() : base();
54003
- return (() => {
54004
- var _el$33 = createElement("box"), _el$34 = createElement("box"), _el$35 = createElement("text"), _el$36 = createElement("text"), _el$37 = createElement("text"), _el$38 = createElement("text");
54005
- insertNode(_el$33, _el$34);
54006
- setProp(_el$33, "flexDirection", "column");
54007
- setProp(_el$33, "width", "100%");
54008
- setProp(_el$33, "flexShrink", 0);
54009
- insertNode(_el$34, _el$35);
54010
- insertNode(_el$34, _el$36);
54011
- insertNode(_el$34, _el$37);
54012
- insertNode(_el$34, _el$38);
54013
- setProp(_el$34, "flexDirection", "row");
54014
- setProp(_el$34, "width", "100%");
54015
- setProp(_el$34, "flexShrink", 0);
54016
- setProp(_el$34, "paddingLeft", 2);
54017
- insert(_el$35, () => props.marked() ? "\u203A " : " ");
54018
- insert(_el$36, stateGlyph);
54019
- insert(_el$37, number);
54020
- setProp(_el$38, "wrapMode", "word");
54021
- insert(_el$38, () => label().label);
54022
- insert(_el$34, createComponent2(Show, {
54023
- get when() {
54024
- return badgeInline();
54025
- },
54026
- get children() {
54027
- var _el$39 = createElement("text");
54028
- insert(_el$39, () => ` ${badge()}`);
54029
- effect((_$p) => setProp(_el$39, "fg", props.cursor() ? currentFg() : success(), _$p));
54030
- return _el$39;
54031
- }
54032
- }), null);
54033
- insert(_el$33, createComponent2(Show, {
54034
- get when() {
54035
- return memo2(() => !!label().recommended)() && !badgeInline();
54036
- },
54037
- get children() {
54038
- var _el$40 = createElement("box"), _el$41 = createElement("text");
54039
- insertNode(_el$40, _el$41);
54040
- setProp(_el$41, "wrapMode", "none");
54041
- insert(_el$41, badge);
54042
- effect((_p$) => {
54043
- var _v$23 = props.labelColumn(), _v$24 = success();
54044
- _v$23 !== _p$.e && (_p$.e = setProp(_el$40, "paddingLeft", _v$23, _p$.e));
54045
- _v$24 !== _p$.t && (_p$.t = setProp(_el$41, "fg", _v$24, _p$.t));
54046
- return _p$;
54047
- }, {
54048
- e: undefined,
54049
- t: undefined
54050
- });
54051
- return _el$40;
54052
- }
54053
- }), null);
54054
- insert(_el$33, createComponent2(Show, {
54055
- get when() {
54056
- return props.row().option.description;
54057
- },
54058
- children: (description) => (() => {
54059
- var _el$42 = createElement("box"), _el$43 = createElement("text");
54060
- insertNode(_el$42, _el$43);
54061
- setProp(_el$43, "wrapMode", "word");
54062
- insert(_el$43, description);
54063
- effect((_p$) => {
54064
- var _v$31 = props.labelColumn(), _v$32 = muted();
54065
- _v$31 !== _p$.e && (_p$.e = setProp(_el$42, "paddingLeft", _v$31, _p$.e));
54066
- _v$32 !== _p$.t && (_p$.t = setProp(_el$43, "fg", _v$32, _p$.t));
54067
- return _p$;
54068
- }, {
54069
- e: undefined,
54070
- t: undefined
54071
- });
54072
- return _el$42;
54073
- })()
54074
- }), null);
54075
- effect((_p$) => {
54076
- var _v$25 = props.cursor() ? currentBg() : undefined, _v$26 = props.cursor() ? currentFg() : faint(), _v$27 = stateColor(), _v$28 = props.cursor() ? currentFg() : faint(), _v$29 = labelColor(), _v$30 = badgeInline() ? 0 : 1;
54077
- _v$25 !== _p$.e && (_p$.e = setProp(_el$34, "backgroundColor", _v$25, _p$.e));
54078
- _v$26 !== _p$.t && (_p$.t = setProp(_el$35, "fg", _v$26, _p$.t));
54079
- _v$27 !== _p$.a && (_p$.a = setProp(_el$36, "fg", _v$27, _p$.a));
54080
- _v$28 !== _p$.o && (_p$.o = setProp(_el$37, "fg", _v$28, _p$.o));
54081
- _v$29 !== _p$.i && (_p$.i = setProp(_el$38, "fg", _v$29, _p$.i));
54082
- _v$30 !== _p$.n && (_p$.n = setProp(_el$38, "flexGrow", _v$30, _p$.n));
54083
- return _p$;
54084
- }, {
54085
- e: undefined,
54086
- t: undefined,
54087
- a: undefined,
54088
- o: undefined,
54089
- i: undefined,
54090
- n: undefined
54091
54013
  });
54092
- return _el$33;
54093
- })();
54094
- }
54095
- var ASK_COMPACT_COLUMNS = 64, GUTTER = 2, CURSOR_CELLS = 2, STATE_CELLS = 2, BADGE_GAP = 2;
54096
- var init_ask_panel = __esm(() => {
54097
- init_index_bun();
54098
- init_index_bun();
54099
- init_index_bun();
54100
- init_index_bun();
54101
- init_index_bun();
54102
- init_index_bun();
54103
- init_index_bun();
54104
- init_index_bun();
54105
- init_index_bun();
54106
- init_server();
54107
- init_i18n();
54108
- init_theme3();
54109
- init_config();
54110
- init_semantic();
54111
- init_ask_options();
54112
- init_ask_keys();
54113
- init_dock_host();
54114
- init_string_width();
54115
- });
54116
-
54117
- // ../tui-base/src/routes/session/turn-overlays.tsx
54118
- function summarizeArgs(name, args, limit = 160) {
54119
- let body = JSON.stringify(args);
54120
- if (body === undefined)
54121
- body = "";
54122
- body = body.trim();
54123
- if (body.length > limit)
54124
- body = body.slice(0, limit - 1) + "\u2026";
54125
- return `${name} ${body}`.trim();
54126
- }
54127
- function ApprovalCard(props) {
54128
- const invalidated = () => props.invalidatedReason !== undefined;
54129
- return createComponent2(DialogConfirm, {
54130
- get title() {
54131
- return memo2(() => !!invalidated())() ? t("overlay.ask.invalidatedTitle") : t("overlay.ask.approvalTitle", {
54132
- name: props.name
54014
+ if (this.#asks.length !== questionsBefore)
54015
+ changed = true;
54016
+ if (changed)
54017
+ this.#changed();
54018
+ }
54019
+ #approvalStillPending(request, asks) {
54020
+ if (request.eventId !== undefined)
54021
+ return asks.some((ask) => ask.eventId === request.eventId);
54022
+ return asks.some((ask) => ask.kind === "approval");
54023
+ }
54024
+ #questionStillPending(entry, asks) {
54025
+ if (entry.eventId !== undefined)
54026
+ return asks.some((ask) => ask.eventId === entry.eventId);
54027
+ return asks.some((ask) => ask.kind === "questions");
54028
+ }
54029
+ cancelAllApprovals() {
54030
+ if (this.#approvals.length === 0)
54031
+ return;
54032
+ const entries = this.#approvals.splice(0);
54033
+ for (const entry of entries)
54034
+ entry.resolve("rejected");
54035
+ this.#changed();
54036
+ }
54037
+ cancelAllAsks() {
54038
+ if (this.#asks.length === 0)
54039
+ return;
54040
+ const entries = this.#asks.splice(0);
54041
+ for (const entry of entries)
54042
+ entry.resolve([]);
54043
+ this.#changed();
54044
+ }
54045
+ get pendingAsk() {
54046
+ const head = this.#asks[0];
54047
+ if (!head)
54048
+ return;
54049
+ return {
54050
+ id: head.id,
54051
+ ...head.eventId !== undefined ? { eventId: head.eventId } : {},
54052
+ questions: head.questions,
54053
+ index: head.index,
54054
+ picks: head.picks,
54055
+ phase: head.phase,
54056
+ customs: [...head.customs],
54057
+ customDraft: head.customDrafts[head.index] ?? null,
54058
+ cursors: [...head.cursors],
54059
+ listCursors: [...head.listCursors],
54060
+ reviewCursor: head.reviewCursor
54061
+ };
54062
+ }
54063
+ get currentQuestion() {
54064
+ const head = this.#asks[0];
54065
+ return head?.questions[head.index];
54066
+ }
54067
+ #matchAsk(questions) {
54068
+ const asks = (this.#pendingAsks?.() ?? []).filter((ask) => ask.kind === "questions");
54069
+ if (asks.length === 0)
54070
+ return;
54071
+ const claimed = new Set(this.#asks.map((entry) => entry.eventId));
54072
+ const available = asks.filter((ask) => !claimed.has(ask.eventId));
54073
+ if (available.length === 0)
54074
+ return;
54075
+ const signature = askSignature(questions);
54076
+ const exact = available.filter((ask) => askSignature(ask.questions ?? []) === signature);
54077
+ if (exact.length > 0)
54078
+ return exact[0];
54079
+ return available.length === 1 ? available[0] : undefined;
54080
+ }
54081
+ answer(questions) {
54082
+ if (questions.length === 0)
54083
+ return Promise.resolve([]);
54084
+ const ask = this.#matchAsk(questions);
54085
+ return new Promise((resolve) => {
54086
+ this.#asks.push({
54087
+ id: ++this.#seq,
54088
+ ...ask !== undefined ? { eventId: ask.eventId } : {},
54089
+ questions,
54090
+ index: 0,
54091
+ picks: questions.map((question) => recommendedPicks(question)),
54092
+ phase: questions[0]?.options.length === 0 ? "input" : "questions",
54093
+ customs: questions.map(() => {
54094
+ return;
54095
+ }),
54096
+ customDrafts: questions.map(() => null),
54097
+ cursors: questions.map(() => 0),
54098
+ listCursors: questions.map(() => 0),
54099
+ reviewCursor: 0,
54100
+ resolve
54133
54101
  });
54134
- },
54135
- get message() {
54136
- return memo2(() => !!invalidated())() ? t("overlay.ask.invalidated", {
54137
- reason: props.invalidatedReason ?? ""
54138
- }) : summarizeArgs(props.name, props.args);
54139
- },
54140
- get label() {
54141
- return memo2(() => !!invalidated())() ? {
54142
- confirm: t("overlay.ask.invalidatedAck"),
54143
- cancel: t("overlay.ask.invalidatedAck")
54144
- } : {
54145
- confirm: t("overlay.ask.allow"),
54146
- cancel: t("overlay.ask.reject")
54147
- };
54148
- },
54149
- onConfirm: () => props.onVerdict("allowed-once"),
54150
- onCancel: () => props.onVerdict("rejected"),
54151
- get extraActions() {
54152
- return memo2(() => !!(!invalidated() && props.escalation === true))() ? [{
54153
- label: t("overlay.ask.allowAlways"),
54154
- bind: "a",
54155
- onTrigger: () => props.onVerdict("always")
54156
- }, {
54157
- label: t("overlay.ask.allowSession"),
54158
- bind: "s",
54159
- onTrigger: () => props.onVerdict("session")
54160
- }] : undefined;
54102
+ this.#changed();
54103
+ });
54104
+ }
54105
+ toggle(option) {
54106
+ const head = this.#asks[0];
54107
+ const question = head?.questions[head.index];
54108
+ if (!head || !question || head.phase === "review")
54109
+ return;
54110
+ if (head.phase === "input")
54111
+ return;
54112
+ head.customs[head.index] = undefined;
54113
+ head.customDrafts[head.index] = null;
54114
+ if (question.multiSelect === true) {
54115
+ const current = head.picks[head.index] ?? [];
54116
+ head.picks[head.index] = current.includes(option) ? current.filter((label) => label !== option) : [...current, option];
54117
+ this.#changed();
54118
+ return;
54119
+ }
54120
+ head.picks[head.index] = [option];
54121
+ if (head.questions.length === 1) {
54122
+ this.#asks.shift();
54123
+ head.resolve(this.#envelope(head));
54124
+ this.#changed();
54125
+ return;
54161
54126
  }
54162
- });
54163
- }
54164
- function ReminderBadge() {
54165
- const theme = useThemeOptional();
54166
- const [tick, setTick] = createSignal(0);
54167
- const startedAt = Date.now();
54168
- const pulsing = () => motionDecorationsEnabled() && Date.now() - startedAt < SKIN_PULSE_MS;
54169
- onAnimationTick(() => pulsing() && motionAnimationRunning() ? motionFrameRate() : undefined, () => setTick((t) => t + 1));
54170
- const fg = () => {
54171
- tick();
54172
- const target = warningColor(theme);
54173
- if (!motionDecorationsEnabled())
54174
- return target;
54175
- const bright = skinPulseBrightness(Date.now() - startedAt);
54176
- return bright >= 1 ? target : mixSkinColor(target, theme?.background.base ?? "#000000", 1 - bright);
54177
- };
54178
- return (() => {
54179
- var _el$ = createElement("text");
54180
- insertNode(_el$, createTextNode(`\u26A0 `));
54181
- setProp(_el$, "flexShrink", 0);
54182
- effect((_$p) => setProp(_el$, "fg", fg(), _$p));
54183
- return _el$;
54184
- })();
54185
- }
54186
- function TurnOverlayHost(props) {
54187
- const dialog = useDialog();
54188
- const dock = useDock();
54189
- const pageOwns = useIsPageOwner();
54190
- const [version, setVersion] = createSignal(0);
54191
- onMount(() => {
54192
- const unsubscribe = props.controller.subscribe(() => setVersion((value) => value + 1));
54193
- onCleanup(unsubscribe);
54194
- const timer = setInterval(() => props.controller.syncPendingAsks(), 200);
54195
- onCleanup(() => clearInterval(timer));
54196
- });
54197
- props.controller.onIdle(() => {
54198
- setTimeout(() => props.reclaimFocus?.(), 3);
54199
- });
54200
- let panelFocus;
54201
- let askHandle;
54202
- let askId;
54203
- let shown;
54204
- function closeAsk() {
54205
- askHandle?.close();
54206
- askHandle = undefined;
54207
- askId = undefined;
54127
+ if (this.#allAnswered(head)) {
54128
+ head.phase = "review";
54129
+ head.reviewCursor = 0;
54130
+ } else {
54131
+ const next = head.questions.findIndex((_, qi) => qi > head.index && (head.picks[qi]?.length ?? 0) === 0 && !head.customs[qi]);
54132
+ if (next >= 0)
54133
+ head.index = next;
54134
+ head.phase = head.questions[head.index]?.options.length === 0 ? "input" : "questions";
54135
+ if (head.phase === "input") {
54136
+ const question = head.questions[head.index];
54137
+ if (question !== undefined) {
54138
+ head.cursors[head.index] = inlineRowIndex(question, askNeedsReview(head.questions));
54139
+ }
54140
+ }
54141
+ }
54142
+ this.#changed();
54208
54143
  }
54209
- createEffect(() => {
54210
- version();
54211
- const approval = props.controller.pendingApproval;
54212
- const ask = props.controller.pendingAsk;
54213
- const askShowing = askHandle !== undefined && ask !== undefined && askId === ask.id;
54214
- const pageOwned = pageOwns();
54215
- const approvalWins = approval !== undefined && !askShowing;
54216
- const askAdmitted = ask !== undefined && (askShowing || pageOwned);
54217
- const key = approvalWins ? `approval:${approval.id}` : askAdmitted ? `ask:${ask.id}` : "";
54218
- if (key === shown)
54144
+ switchFocus(direction) {
54145
+ const head = this.#asks[0];
54146
+ if (!head || head.phase === "review" || head.questions.length < 2)
54147
+ return;
54148
+ if (head.phase === "input" && (head.questions[head.index]?.options.length ?? 0) > 0)
54149
+ return;
54150
+ const next = Math.max(0, Math.min(head.questions.length - 1, head.index + direction));
54151
+ if (next === head.index)
54152
+ return;
54153
+ head.index = next;
54154
+ const question = head.questions[next];
54155
+ head.phase = question?.options.length === 0 ? "input" : "questions";
54156
+ if (head.phase === "input" && question !== undefined) {
54157
+ head.cursors[next] = inlineRowIndex(question, askNeedsReview(head.questions));
54158
+ }
54159
+ this.#changed();
54160
+ }
54161
+ confirmQuestion() {
54162
+ const head = this.#asks[0];
54163
+ if (!head || head.phase === "review" || head.phase === "input")
54164
+ return false;
54165
+ const question = head.questions[head.index];
54166
+ if (question === undefined || !askNeedsReview(head.questions))
54167
+ return false;
54168
+ const next = head.questions.findIndex((_, qi) => qi > head.index && (head.picks[qi]?.length ?? 0) === 0 && !head.customs[qi]);
54169
+ if (next >= 0) {
54170
+ head.index = next;
54171
+ const target = head.questions[next];
54172
+ head.phase = target?.options.length === 0 ? "input" : "questions";
54173
+ if (head.phase === "input" && target !== undefined) {
54174
+ head.cursors[next] = inlineRowIndex(target, askNeedsReview(head.questions));
54175
+ }
54176
+ } else {
54177
+ head.phase = "review";
54178
+ head.reviewCursor = 0;
54179
+ }
54180
+ this.#changed();
54181
+ return true;
54182
+ }
54183
+ beginCustom() {
54184
+ const head = this.#asks[0];
54185
+ if (!head || head.phase === "review")
54186
+ return false;
54187
+ const question = head.questions[head.index];
54188
+ head.customDrafts[head.index] = head.customs[head.index] ?? "";
54189
+ head.phase = "input";
54190
+ if (question !== undefined) {
54191
+ head.cursors[head.index] = inlineRowIndex(question, askNeedsReview(head.questions));
54192
+ }
54193
+ this.#changed();
54194
+ return true;
54195
+ }
54196
+ patchCustom(text) {
54197
+ const head = this.#asks[0];
54198
+ if (!head || head.customDrafts[head.index] === null)
54199
+ return;
54200
+ head.customDrafts[head.index] = text;
54201
+ this.#changed();
54202
+ }
54203
+ commitCustom() {
54204
+ const head = this.#asks[0];
54205
+ const question = head?.questions[head.index];
54206
+ if (!head || !question)
54207
+ return;
54208
+ const draft = head.customDrafts[head.index] ?? null;
54209
+ if (draft === null)
54210
+ return;
54211
+ const text = draft.trim();
54212
+ head.customDrafts[head.index] = null;
54213
+ if (text === "") {
54214
+ this.#backToList(head);
54215
+ this.#changed();
54216
+ return;
54217
+ }
54218
+ head.customs[head.index] = text;
54219
+ head.picks[head.index] = [];
54220
+ if (question.multiSelect !== true && head.questions.length === 1) {
54221
+ this.#asks.shift();
54222
+ head.resolve(this.#envelope(head));
54223
+ this.#changed();
54224
+ return;
54225
+ }
54226
+ if (this.#allAnswered(head)) {
54227
+ head.phase = "review";
54228
+ head.reviewCursor = 0;
54229
+ } else {
54230
+ const next = head.questions.findIndex((_, qi) => qi > head.index && (head.picks[qi]?.length ?? 0) === 0 && !head.customs[qi]);
54231
+ if (next >= 0)
54232
+ head.index = next;
54233
+ head.phase = head.questions[head.index]?.options.length === 0 ? "input" : "questions";
54234
+ }
54235
+ this.#changed();
54236
+ }
54237
+ cancelCustomEdit() {
54238
+ const head = this.#asks[0];
54239
+ if (!head || head.customDrafts[head.index] === null)
54240
+ return;
54241
+ head.customDrafts[head.index] = null;
54242
+ this.#backToList(head);
54243
+ this.#changed();
54244
+ }
54245
+ get inlineText() {
54246
+ const head = this.#asks[0];
54247
+ if (!head)
54248
+ return "";
54249
+ const draft = head.customDrafts[head.index];
54250
+ if (draft !== null && draft !== undefined)
54251
+ return draft;
54252
+ return head.customs[head.index] ?? "";
54253
+ }
54254
+ setInlineText(text) {
54255
+ const head = this.#asks[0];
54256
+ const question = head?.questions[head.index];
54257
+ if (!head || !question || head.phase === "review")
54258
+ return;
54259
+ if ((head.customDrafts[head.index] ?? null) === null && text === "")
54260
+ return;
54261
+ head.customDrafts[head.index] = text;
54262
+ head.phase = "input";
54263
+ head.cursors[head.index] = inlineRowIndex(question, askNeedsReview(head.questions));
54264
+ this.#changed();
54265
+ }
54266
+ focusInput() {
54267
+ const head = this.#asks[0];
54268
+ const question = head?.questions[head.index];
54269
+ if (!head || !question || head.phase === "review")
54270
+ return;
54271
+ head.phase = "input";
54272
+ head.cursors[head.index] = inlineRowIndex(question, askNeedsReview(head.questions));
54273
+ this.#changed();
54274
+ }
54275
+ focusOptions() {
54276
+ const head = this.#asks[0];
54277
+ if (!head || head.phase !== "input")
54278
+ return;
54279
+ this.#backToList(head);
54280
+ this.#changed();
54281
+ }
54282
+ setCursor(row) {
54283
+ const head = this.#asks[0];
54284
+ const question = head?.questions[head.index];
54285
+ if (!head || !question || head.phase === "review")
54286
+ return;
54287
+ const needsReview = askNeedsReview(head.questions);
54288
+ const inline = inlineRowIndex(question, needsReview);
54289
+ const next = Math.max(0, Math.min(inline, Math.floor(row)));
54290
+ head.cursors[head.index] = next;
54291
+ head.phase = next === inline ? "input" : "questions";
54292
+ if (next !== inline)
54293
+ head.listCursors[head.index] = next;
54294
+ this.#changed();
54295
+ }
54296
+ moveCursor(delta) {
54297
+ const head = this.#asks[0];
54298
+ const question = head?.questions[head.index];
54299
+ if (!head || !question || head.phase === "review")
54300
+ return;
54301
+ const needsReview = askNeedsReview(head.questions);
54302
+ const last = questionRowCount(question, needsReview) - 1;
54303
+ const next = Math.max(0, Math.min(last, (head.cursors[head.index] ?? 0) + delta));
54304
+ const inline = inlineRowIndex(question, needsReview);
54305
+ head.cursors[head.index] = next;
54306
+ head.phase = next === inline ? "input" : "questions";
54307
+ if (next !== inline)
54308
+ head.listCursors[head.index] = next;
54309
+ this.#changed();
54310
+ }
54311
+ setReviewCursor(row) {
54312
+ const head = this.#asks[0];
54313
+ if (!head || head.phase !== "review")
54314
+ return;
54315
+ const next = Math.max(0, Math.min(head.questions.length, Math.floor(row)));
54316
+ if (next === head.reviewCursor)
54317
+ return;
54318
+ head.reviewCursor = next;
54319
+ this.#changed();
54320
+ }
54321
+ moveReviewCursor(delta) {
54322
+ this.setReviewCursor((this.#asks[0]?.reviewCursor ?? 0) + delta);
54323
+ }
54324
+ #backToList(head) {
54325
+ const question = head.questions[head.index];
54326
+ if (question === undefined)
54327
+ return;
54328
+ if (question.options.length === 0) {
54329
+ head.phase = "input";
54219
54330
  return;
54220
- const previousKey = shown;
54221
- shown = key;
54222
- if (previousKey?.startsWith("approval:") === true && dialog.stack.at(-1)?.key === previousKey) {
54223
- dialog.clear();
54224
54331
  }
54225
- if (approvalWins) {
54226
- closeAsk();
54227
- const atOpen = key;
54228
- const approvalId = approval.id;
54229
- try {
54230
- dialog.replace(() => createComponent2(ApprovalCard, {
54231
- get name() {
54232
- return approval.name;
54233
- },
54234
- get args() {
54235
- return approval.args;
54236
- },
54237
- get escalation() {
54238
- return approval.escalation;
54239
- },
54240
- get invalidatedReason() {
54241
- return approval.invalidatedReason;
54242
- },
54243
- onVerdict: (verdict) => {
54244
- switch (verdict) {
54245
- case "allowed-once":
54246
- props.controller.confirmApproval();
54247
- break;
54248
- case "always":
54249
- props.controller.approveAlways();
54250
- break;
54251
- case "session":
54252
- props.controller.approveSession();
54253
- break;
54254
- default:
54255
- props.controller.rejectApproval();
54256
- }
54257
- }
54258
- }), () => {
54259
- if (shown === atOpen && props.controller.pendingApproval?.id === approvalId) {
54260
- props.controller.rejectApproval();
54261
- }
54262
- }, {
54263
- key,
54264
- tone: "warning"
54265
- });
54266
- } catch {
54267
- props.controller.rejectApproval();
54268
- }
54332
+ head.phase = "questions";
54333
+ const inline = inlineRowIndex(question, askNeedsReview(head.questions));
54334
+ const row = Math.max(0, Math.min(inline - 1, head.listCursors[head.index] ?? 0));
54335
+ head.cursors[head.index] = row;
54336
+ head.listCursors[head.index] = row;
54337
+ }
54338
+ enterReview() {
54339
+ const head = this.#asks[0];
54340
+ if (!head || head.phase === "review")
54341
+ return false;
54342
+ if (!askNeedsReview(head.questions))
54343
+ return false;
54344
+ head.phase = "review";
54345
+ head.reviewCursor = 0;
54346
+ this.#changed();
54347
+ return true;
54348
+ }
54349
+ backToQuestions(focus) {
54350
+ const head = this.#asks[0];
54351
+ if (!head || head.phase !== "review")
54269
54352
  return;
54270
- }
54271
- if (ask !== undefined && askAdmitted) {
54272
- if (askHandle !== undefined && askId === ask.id)
54273
- return;
54274
- const previous = askHandle;
54275
- askId = ask.id;
54276
- askHandle = dock.open((ctx) => createComponent2(AskPanel, {
54277
- get controller() {
54278
- return props.controller;
54279
- },
54280
- get width() {
54281
- return ctx.width;
54282
- },
54283
- queued: () => Math.max(0, props.controller.pendingAskCount + props.controller.pendingApprovalCount - 1),
54284
- onFocusTarget: (resolve) => {
54285
- panelFocus = resolve;
54286
- }
54287
- }), {
54288
- kind: "ask",
54289
- contentRows: estimateAskRows(ask),
54290
- focusRef: () => panelFocus?.(),
54291
- overflowLabel: (hidden) => t("overlay.ask.overflow", {
54292
- count: hidden
54293
- })
54294
- });
54295
- previous?.close();
54353
+ head.phase = "questions";
54354
+ if (focus !== undefined && focus >= 0 && focus < head.questions.length)
54355
+ head.index = focus;
54356
+ const question = head.questions[head.index];
54357
+ if (question !== undefined && question.options.length === 0)
54358
+ head.phase = "input";
54359
+ this.#changed();
54360
+ }
54361
+ submit() {
54362
+ const head = this.#asks[0];
54363
+ if (!head)
54296
54364
  return;
54297
- }
54298
- closeAsk();
54299
- });
54300
- onCleanup(closeAsk);
54301
- return createComponent2(Show, {
54302
- when: false,
54303
- children: null
54304
- });
54305
- }
54306
- function registerTurnOverlays(seam, controller, options) {
54307
- if (typeof seam.pendingAsks === "function") {
54308
- const read = seam.pendingAsks.bind(seam);
54309
- controller.attachPendingAsks(() => read() ?? []);
54365
+ this.#asks.shift();
54366
+ head.resolve(this.#envelope(head));
54367
+ this.#changed();
54310
54368
  }
54311
- if (typeof seam.onSessionEvent === "function") {
54312
- seam.onSessionEvent((event) => {
54313
- if (event.type === "bridge.dead") {
54314
- const configured = options?.deadReason;
54315
- if (configured === undefined)
54316
- return;
54317
- const reason = typeof configured === "function" ? configured(event.details) : configured;
54318
- if (reason !== "")
54319
- controller.invalidateAll(reason);
54320
- return;
54369
+ #allAnswered(head) {
54370
+ return head.questions.every((_, qi) => (head.picks[qi]?.length ?? 0) > 0 || head.customs[qi] !== undefined && head.customs[qi] !== "");
54371
+ }
54372
+ #envelope(head) {
54373
+ return head.questions.map((question, qi) => {
54374
+ const custom = head.customs[qi];
54375
+ if (custom !== undefined && custom !== "") {
54376
+ return { questionId: question.id, selected: "", custom };
54321
54377
  }
54322
- if (event.type !== "bridge.ask.invalidated")
54323
- return;
54324
- const details = event.details;
54325
- if (typeof details?.eventId !== "string")
54326
- return;
54327
- controller.invalidateAsk(details.eventId, typeof details.reason === "string" ? details.reason : "");
54378
+ const picks = head.picks[qi] ?? [];
54379
+ return {
54380
+ questionId: question.id,
54381
+ selected: picks[0] ?? "",
54382
+ ...picks.length > 1 ? { selections: [...picks] } : {}
54383
+ };
54328
54384
  });
54329
54385
  }
54330
- seam.registerAskProvider((questions) => controller.answer(questions));
54386
+ decline() {
54387
+ const head = this.#asks.shift();
54388
+ if (!head)
54389
+ return;
54390
+ head.resolve([]);
54391
+ this.#changed();
54392
+ }
54331
54393
  }
54332
- var init_turn_overlays = __esm(() => {
54333
- init_index_bun();
54334
- init_index_bun();
54335
- init_index_bun();
54336
- init_index_bun();
54337
- init_index_bun();
54338
- init_index_bun();
54339
- init_index_bun();
54340
- init_server();
54341
- init_index_bun();
54342
- init_dialog_confirm();
54343
- init_dialog();
54344
- init_input_ownership();
54345
- init_theme3();
54346
- init_i18n();
54347
- init_motion();
54348
- init_semantic();
54349
- init_widgets_dock();
54350
- init_ask_panel();
54394
+ var init_turn_overlay_controller = __esm(() => {
54351
54395
  init_ask_options();
54352
- init_dock_host();
54353
54396
  });
54354
54397
 
54355
54398
  // ../tui-base/src/routes/session/hotkeys.ts
@@ -54747,12 +54790,19 @@ function coreCommands() {
54747
54790
  ctx.refreshFooter?.();
54748
54791
  return;
54749
54792
  }
54750
- const catalog = await ctx.seam.modelCatalog();
54793
+ let catalog;
54794
+ let current;
54795
+ try {
54796
+ catalog = await ctx.seam.modelCatalog();
54797
+ current = await ctx.seam.currentModelSelection();
54798
+ } catch (error) {
54799
+ ctx.say(t("command.model.unavailable", { reason: seamFailureReason(error) }));
54800
+ return;
54801
+ }
54751
54802
  if (catalog.length === 0) {
54752
54803
  ctx.say(t("command.model.emptyCatalog"));
54753
54804
  return;
54754
54805
  }
54755
- const current = await ctx.seam.currentModelSelection();
54756
54806
  const prefs = readModelPrefsFromConfig(ctx.seam.configLoad?.());
54757
54807
  let favorites = prefs.favoriteModels;
54758
54808
  let hidden = prefs.hiddenModels;
@@ -63101,7 +63151,7 @@ function viewerRows(views) {
63101
63151
  return [...running, ...settled];
63102
63152
  }
63103
63153
  function viewerRowText(view, roundCap, elapsedText) {
63104
- const glyph = view.status === "running" ? "\u280B" : view.status === "completed" ? "\u2713" : view.status === "failed" ? "\u2717" : "\u2014";
63154
+ const glyph = view.status === "running" ? "\u280B" : view.status === "completed" ? "\u2713" : view.status === "failed" ? "\u2717" : view.status === "interrupted" ? "\u2298" : "\u2014";
63105
63155
  const stop = subagentHardStopGlyph(view);
63106
63156
  const label = `${stop ? `${stop} ` : ""}${titlecase(view.label)}`;
63107
63157
  const suffix = subagentMarkerSuffix(view);
@@ -63443,7 +63493,7 @@ function SubagentsViewer(props) {
63443
63493
  function headerText(view, now) {
63444
63494
  if (view === undefined)
63445
63495
  return t("panel.subagents.header.fallback");
63446
- const status = view.status === "running" ? t("panel.subagents.status.running") : view.status === "completed" ? t("panel.subagents.status.completed") : view.status === "failed" ? t("panel.subagents.status.failed") : t("panel.subagents.status.cancelled");
63496
+ const status = view.status === "running" ? t("panel.subagents.status.running") : view.status === "completed" ? t("panel.subagents.status.completed") : view.status === "failed" ? t("panel.subagents.status.failed") : view.status === "interrupted" ? t("panel.subagents.status.interrupted") : t("panel.subagents.status.cancelled");
63447
63497
  const elapsed = rowElapsedText(view, now);
63448
63498
  const rounds = t("panel.subagents.row.rounds", {
63449
63499
  count: String(view.rounds)
@@ -63654,7 +63704,7 @@ var init_subagents_viewer = __esm(() => {
63654
63704
  import { TextAttributes as TextAttributes12 } from "@opentui/core";
63655
63705
  function resolveVersion() {
63656
63706
  try {
63657
- return "0.23.0";
63707
+ return "0.23.2";
63658
63708
  } catch {
63659
63709
  return "dev";
63660
63710
  }
@@ -66169,7 +66219,11 @@ function bridgeAgentRunKey(runId, seq) {
66169
66219
  return `${runId}:${seq}`;
66170
66220
  }
66171
66221
  function bridgeSettledStatus(outcome) {
66172
- return outcome === "failed" || outcome === "cancelled" ? outcome : "completed";
66222
+ if (outcome === "failed" || outcome === "cancelled")
66223
+ return outcome;
66224
+ if (outcome === "aborted")
66225
+ return "interrupted";
66226
+ return "completed";
66173
66227
  }
66174
66228
  function bridgeSettleChild(existing, outcome, startedAt, now) {
66175
66229
  return {
@@ -66364,6 +66418,29 @@ function bridgeChildJournalMeta(rows) {
66364
66418
  ...model !== undefined ? { model } : {}
66365
66419
  };
66366
66420
  }
66421
+ function bridgeChildStopReason(rows) {
66422
+ for (let i = rows.length - 1;i >= 0; i -= 1) {
66423
+ const row = rows[i];
66424
+ if (row.type !== "user/message")
66425
+ continue;
66426
+ const source = asRecord5(asRecord5(row.payload).source);
66427
+ if (source.kind !== BRIDGE_SUBAGENT_SETTLED)
66428
+ continue;
66429
+ const reason = source.stopReason;
66430
+ if (typeof reason === "string" && reason !== "")
66431
+ return reason;
66432
+ }
66433
+ for (let i = rows.length - 1;i >= 0; i -= 1) {
66434
+ const row = rows[i];
66435
+ if (row.type !== "turn/end")
66436
+ continue;
66437
+ const reason = asRecord5(asRecord5(row.payload).reason);
66438
+ const kind = reason.kind;
66439
+ if (typeof kind === "string" && kind !== "")
66440
+ return kind;
66441
+ }
66442
+ return;
66443
+ }
66367
66444
  function bridgeChildJournalKey(view) {
66368
66445
  return `${view.id}@${view.startedAt ?? ""}`;
66369
66446
  }
@@ -66512,11 +66589,15 @@ class BridgeSessionSeam {
66512
66589
  #subagentJournalMeta = new Map;
66513
66590
  #sweepSettledRuns = new Map;
66514
66591
  #subagentSettleSnapshots = new Map;
66592
+ #interruptInFlight = new Map;
66593
+ #interruptGeneration = 0;
66594
+ #confirmClock;
66515
66595
  #connection = "disconnected";
66516
66596
  #turn = "idle";
66517
66597
  #bridgeLink = "ready";
66518
66598
  #sessionAttached = false;
66519
66599
  #currentSessionId;
66600
+ #bridgeCapabilities = new Set;
66520
66601
  #lastAppliedSeq;
66521
66602
  #lastAppliedSessionId;
66522
66603
  #appliedReplayKeys = new Set;
@@ -66550,17 +66631,37 @@ class BridgeSessionSeam {
66550
66631
  this.#ctx = options.ctx;
66551
66632
  this.#onDead = options.onDead;
66552
66633
  this.#onPermissionUnavailable = options.onPermissionUnavailable;
66634
+ this.#confirmClock = options.confirmClock ?? {
66635
+ sleep: (ms) => new Promise((resolve) => {
66636
+ const timer = setTimeout(resolve, ms);
66637
+ timer.unref?.();
66638
+ }),
66639
+ now: () => Date.now()
66640
+ };
66553
66641
  this.#unsubEvent = this.#transport.onEvent((frame) => this.#onBridgeEvent(frame));
66554
66642
  }
66555
66643
  async connect() {
66556
66644
  try {
66557
- await this.#transport.request("bridge.ping");
66645
+ const reply = asRecord5(await this.#transport.request("bridge.ping"));
66646
+ this.#recordBridgeCapabilities(reply.capabilities);
66558
66647
  this.#connection = "connected";
66559
66648
  } catch (err) {
66560
66649
  this.#connection = "disconnected";
66561
66650
  this.#ctx.logger.warn("[bridge-seam] bridge.ping failed, status connection=disconnected: %s", err);
66562
66651
  }
66563
66652
  }
66653
+ #recordBridgeCapabilities(value) {
66654
+ this.#bridgeCapabilities.clear();
66655
+ if (!Array.isArray(value))
66656
+ return;
66657
+ for (const entry of value) {
66658
+ if (typeof entry === "string" && entry !== "")
66659
+ this.#bridgeCapabilities.add(entry);
66660
+ }
66661
+ }
66662
+ hasBridgeCapability(name) {
66663
+ return this.#bridgeCapabilities.has(name);
66664
+ }
66564
66665
  status() {
66565
66666
  if (this.#connection === "disconnected") {
66566
66667
  this.#degradeOnce("status", "no handshake/status frame; returning disconnected/idle");
@@ -67027,6 +67128,108 @@ class BridgeSessionSeam {
67027
67128
  subagentViews() {
67028
67129
  return [...this.#subagentViews.values()].map((view) => ({ ...view }));
67029
67130
  }
67131
+ async interruptChild(childId) {
67132
+ const parentSessionId = this.#currentSessionId;
67133
+ if (parentSessionId === undefined || parentSessionId === "") {
67134
+ throw new BridgeProtocolError("NO_SESSION", "cannot interrupt a subagent: no session is bound to this bridge connection", { childId });
67135
+ }
67136
+ const generation = ++this.#interruptGeneration;
67137
+ const sessionAtStart = this.#subagentSessionId;
67138
+ this.#interruptInFlight.set(childId, generation);
67139
+ let value;
67140
+ try {
67141
+ value = asRecord5(await this.#transport.request("subagents.interrupt", { parentSessionId, childId }));
67142
+ } catch (err) {
67143
+ if (this.#interruptInFlight.get(childId) === generation)
67144
+ this.#interruptInFlight.delete(childId);
67145
+ throw err;
67146
+ }
67147
+ const disposition = value.disposition;
67148
+ if (disposition === "cancel-issued") {
67149
+ this.#confirmChildStop(childId, generation, sessionAtStart);
67150
+ return;
67151
+ }
67152
+ if (disposition === "already-settled") {
67153
+ if (this.#interruptInFlight.get(childId) === generation)
67154
+ this.#interruptInFlight.delete(childId);
67155
+ return;
67156
+ }
67157
+ if (this.#interruptInFlight.get(childId) === generation)
67158
+ this.#interruptInFlight.delete(childId);
67159
+ const detail = value.detail;
67160
+ throw new BridgeProtocolError("INTERRUPT_FAILED", `bridge failed to interrupt subagent ${childId}${typeof disposition === "string" ? ` (${disposition})` : ""}`, { childId, disposition, ...detail !== undefined ? { detail } : {} });
67161
+ }
67162
+ async stopChildren() {
67163
+ const parentSessionId = this.#currentSessionId;
67164
+ if (parentSessionId === undefined || parentSessionId === "") {
67165
+ throw new BridgeProtocolError("NO_SESSION", "cannot stop children: no session is bound to this bridge connection");
67166
+ }
67167
+ const value = asRecord5(await this.#transport.request("subagents.stopChildren", { parentSessionId }));
67168
+ const children = value.children;
67169
+ if (!Array.isArray(children))
67170
+ return [];
67171
+ const sessionAtStart = this.#subagentSessionId;
67172
+ const rows = children.map((row) => {
67173
+ const r = asRecord5(row);
67174
+ return {
67175
+ childId: typeof r.childId === "string" ? r.childId : "",
67176
+ disposition: typeof r.disposition === "string" ? r.disposition : "failed"
67177
+ };
67178
+ });
67179
+ for (const row of rows) {
67180
+ if (row.disposition !== "cancel-issued" || row.childId === "")
67181
+ continue;
67182
+ const generation = ++this.#interruptGeneration;
67183
+ this.#interruptInFlight.set(row.childId, generation);
67184
+ this.#confirmChildStop(row.childId, generation, sessionAtStart);
67185
+ }
67186
+ return rows;
67187
+ }
67188
+ async#confirmChildStop(childId, generation, sessionAtStart) {
67189
+ const clock = this.#confirmClock;
67190
+ const deadlineAt = clock.now() + CONFIRM_TIMEOUT_MS;
67191
+ let delayMs = CONFIRM_POLL_INITIAL_MS;
67192
+ try {
67193
+ for (;; ) {
67194
+ await clock.sleep(delayMs);
67195
+ if (this.#disposed || this.#subagentSessionId !== sessionAtStart || this.#interruptInFlight.get(childId) !== generation)
67196
+ return;
67197
+ let stopped = false;
67198
+ try {
67199
+ const items = asRecord5(await this.#transport.request("session.list", { _request: {} })).items;
67200
+ if (Array.isArray(items)) {
67201
+ stopped = items.some((row) => {
67202
+ const item = asRecord5(row);
67203
+ return item.sessionId === childId && item.running === false;
67204
+ });
67205
+ }
67206
+ } catch {}
67207
+ if (this.#disposed || this.#subagentSessionId !== sessionAtStart || this.#interruptInFlight.get(childId) !== generation)
67208
+ return;
67209
+ if (stopped) {
67210
+ let reason = "aborted";
67211
+ try {
67212
+ const rows = asRecord5(await this.#transport.request("journal.replay", { sessionId: childId })).rows;
67213
+ if (Array.isArray(rows)) {
67214
+ const clean = rows.filter((row) => row !== null && typeof row === "object" && !Array.isArray(row));
67215
+ reason = bridgeChildStopReason(clean) ?? "aborted";
67216
+ }
67217
+ } catch {}
67218
+ if (this.#disposed || this.#subagentSessionId !== sessionAtStart || this.#interruptInFlight.get(childId) !== generation)
67219
+ return;
67220
+ this.#settleChildFromHost(childId, reason, clock.now());
67221
+ return;
67222
+ }
67223
+ if (clock.now() >= deadlineAt) {
67224
+ if (this.#interruptInFlight.get(childId) === generation)
67225
+ this.#interruptInFlight.delete(childId);
67226
+ this.#ctx.logger.debug?.("[bridge-seam] subagent stop confirm timed out (child=%s, generation=%d, after=%dms); " + "clearing in-flight marker for turn sweep", childId, generation, CONFIRM_TIMEOUT_MS);
67227
+ return;
67228
+ }
67229
+ delayMs = Math.min(CONFIRM_POLL_MAX_MS, delayMs * 2);
67230
+ }
67231
+ } catch {}
67232
+ }
67030
67233
  #freezeSettles(before) {
67031
67234
  for (const [childId, startedAt] of before) {
67032
67235
  const view = this.#subagentViews.get(childId);
@@ -67079,19 +67282,30 @@ class BridgeSessionSeam {
67079
67282
  const now = Date.now();
67080
67283
  let changed = false;
67081
67284
  for (const childId of toSettle) {
67082
- const existing = this.#subagentViews.get(childId);
67083
- if (existing !== undefined)
67084
- this.#sweepSettledRuns.set(childId, bridgeChildJournalKey(existing));
67085
- if (this.#foldWithFrozenSettle("user/message", {
67086
- source: { kind: BRIDGE_SUBAGENT_SETTLED, stopReason: "completed", senderSessionId: childId }
67087
- }, now, false))
67285
+ if (this.#interruptInFlight.has(childId))
67286
+ continue;
67287
+ if (this.#settleChildFromHost(childId, "completed", now, false))
67088
67288
  changed = true;
67089
67289
  }
67090
67290
  if (changed) {
67091
- this.#syncSubagentMeta(false);
67092
67291
  this.#emitSubagentViews();
67093
67292
  }
67094
67293
  }
67294
+ #settleChildFromHost(childId, stopReason, now = Date.now(), emit = true) {
67295
+ const existing = this.#subagentViews.get(childId);
67296
+ if (existing !== undefined)
67297
+ this.#sweepSettledRuns.set(childId, bridgeChildJournalKey(existing));
67298
+ const changed = this.#foldWithFrozenSettle("user/message", {
67299
+ source: { kind: BRIDGE_SUBAGENT_SETTLED, stopReason, senderSessionId: childId }
67300
+ }, now, false);
67301
+ if (changed) {
67302
+ this.#syncSubagentMeta(false);
67303
+ if (emit)
67304
+ this.#emitSubagentViews();
67305
+ }
67306
+ this.#interruptInFlight.delete(childId);
67307
+ return changed;
67308
+ }
67095
67309
  async#ensureChildJournal(childId, startedAt) {
67096
67310
  const key = `${childId}@${startedAt ?? ""}`;
67097
67311
  if (this.#subagentJournalLoaded.has(key))
@@ -67212,7 +67426,9 @@ class BridgeSessionSeam {
67212
67426
  const now = Date.now();
67213
67427
  let changed = false;
67214
67428
  if (frame.type === "agent.spawn") {
67215
- changed = this.#foldWithFrozenSettle(BRIDGE_AGENT_START, payload, now, true);
67429
+ const runId = typeof payload.runId === "string" ? payload.runId : "";
67430
+ const childId = typeof payload.childId === "string" ? payload.childId : "";
67431
+ changed = runId === `${BRIDGE_CATALOG_RUN_PREFIX}${childId}` ? this.#foldWithFrozenSettle(BRIDGE_SUBAGENT_CATALOG, payload, now, true) : this.#foldWithFrozenSettle(BRIDGE_AGENT_START, payload, now, true);
67216
67432
  } else if (frame.type === "agent.settle") {
67217
67433
  changed = this.#foldWithFrozenSettle(BRIDGE_AGENT_END, payload, now, true);
67218
67434
  }
@@ -67231,6 +67447,8 @@ class BridgeSessionSeam {
67231
67447
  this.#subagentJournalMeta.clear();
67232
67448
  this.#sweepSettledRuns.clear();
67233
67449
  this.#subagentSettleSnapshots.clear();
67450
+ this.#interruptInFlight.clear();
67451
+ this.#interruptGeneration += 1;
67234
67452
  this.#subagentSessionId = sessionId;
67235
67453
  rosterReset = true;
67236
67454
  }
@@ -67378,6 +67596,9 @@ class BridgeSessionSeam {
67378
67596
  this.#subagentJournalMeta.clear();
67379
67597
  this.#sweepSettledRuns.clear();
67380
67598
  this.#subagentSettleSnapshots.clear();
67599
+ this.#interruptInFlight.clear();
67600
+ this.#interruptGeneration = 0;
67601
+ this.#bridgeCapabilities.clear();
67381
67602
  this.#activeCallbacks = undefined;
67382
67603
  this.#cancelAllAsks();
67383
67604
  this.#bufferedPendingSnapshot = undefined;
@@ -67712,7 +67933,7 @@ class BridgeSessionSeam {
67712
67933
  }
67713
67934
  }
67714
67935
  }
67715
- var BridgeProtocolError, BRIDGE_AGENT_START = "tool-workflow/agent-start", BRIDGE_AGENT_END = "tool-workflow/agent-end", BRIDGE_SUBAGENT_CATALOG = "subagent/catalog", BRIDGE_SUBAGENT_SETTLED = "subagent-settled", BRIDGE_CATALOG_RUN_PREFIX = "catalog:", fmtTokens = (n) => n >= 1000 ? `${(n / 1000).toFixed(1)}k` : `${n}`;
67936
+ var BridgeProtocolError, BRIDGE_AGENT_START = "tool-workflow/agent-start", BRIDGE_AGENT_END = "tool-workflow/agent-end", BRIDGE_SUBAGENT_CATALOG = "subagent/catalog", BRIDGE_SUBAGENT_SETTLED = "subagent-settled", BRIDGE_CATALOG_RUN_PREFIX = "catalog:", CONFIRM_POLL_INITIAL_MS = 250, CONFIRM_POLL_MAX_MS = 1000, CONFIRM_TIMEOUT_MS = 45000, fmtTokens = (n) => n >= 1000 ? `${(n / 1000).toFixed(1)}k` : `${n}`;
67716
67937
  var init_bridge_session_seam = __esm(() => {
67717
67938
  init_remote_session_ops();
67718
67939
  init_session_seam_adapter();
@@ -68368,7 +68589,6 @@ function V2SessionPageBody(props) {
68368
68589
  };
68369
68590
  const reloadSession = (sessionId) => {
68370
68591
  setLastRequest(undefined);
68371
- setSessionIdFromRecovery(undefined);
68372
68592
  composerRef?.resetDeliveries();
68373
68593
  setComposerPending([]);
68374
68594
  setTools(0);
@@ -69471,5 +69691,5 @@ export {
69471
69691
  themeNameFromConfig
69472
69692
  };
69473
69693
 
69474
- //# debugId=CF96FD408007020364756E2164756E21
69694
+ //# debugId=A551D22BBC95CF9464756E2164756E21
69475
69695
  //# sourceMappingURL=index.js.map