@aiwayds/dsh-opentui 0.23.1 → 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,1442 +52077,1324 @@ 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
- if (seam.hasBridgeCapability?.("subagents.stopChildren") === true && seam.stopChildren) {
52227
- let dispositions = [];
52228
- try {
52229
- dispositions = await seam.stopChildren();
52230
- } catch {}
52231
- return {
52232
- parent,
52233
- children: dispositions.filter((row) => row.disposition === "cancel-issued").length,
52234
- dispositions
52235
- };
52236
- }
52237
- let children = 0;
52238
- for (const view of seam.subagentViews?.() ?? []) {
52239
- if (view.status !== "running" || !seam.interruptChild)
52240
- continue;
52241
- try {
52242
- await seam.interruptChild(view.id);
52243
- children++;
52244
- } 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;
52245
52316
  }
52246
- return { parent, children };
52247
- }
52248
-
52249
- // ../tui-base/src/routes/session/turn-overlay-controller.ts
52250
- function askSignature(questions) {
52251
- return JSON.stringify(questions.map((question) => [
52252
- question.id,
52253
- question.prompt,
52254
- question.header,
52255
- question.description,
52256
- question.detail,
52257
- question.multiSelect === true,
52258
- question.options.map((option) => [option.label, option.description])
52259
- ]));
52317
+ return;
52260
52318
  }
52261
-
52262
- class TurnOverlayController {
52263
- #approvals = [];
52264
- #asks = [];
52265
- #seq = 0;
52266
- #listeners = new Set;
52267
- #idleHandlers = new Set;
52268
- #busy = false;
52269
- #pendingAsks;
52270
- subscribe(fn) {
52271
- this.#listeners.add(fn);
52272
- return () => this.#listeners.delete(fn);
52273
- }
52274
- attachPendingAsks(read) {
52275
- this.#pendingAsks = read;
52276
- }
52277
- invalidateAsk(eventId, reason) {
52278
- if (eventId === "")
52279
- return;
52280
- 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)
52281
52331
  return;
52282
- this.#approvals = this.#approvals.filter((entry) => {
52283
- if (entry.request.eventId !== eventId)
52284
- return true;
52285
- entry.resolve("rejected");
52286
- return false;
52287
- });
52288
- this.#asks = this.#asks.filter((entry) => {
52289
- if (entry.eventId !== eventId)
52290
- return true;
52291
- entry.resolve([]);
52292
- return false;
52293
- });
52294
- this.#approvals.push({
52295
- request: {
52296
- id: ++this.#seq,
52297
- name: "ask",
52298
- args: {},
52299
- eventId,
52300
- escalation: false,
52301
- invalidatedReason: reason
52302
- },
52303
- 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();
52304
52363
  });
52305
- this.#changed();
52306
52364
  }
52307
- invalidateAll(reason) {
52308
- if (reason === "")
52365
+ function remove(entry) {
52366
+ const before = queue();
52367
+ if (!before.includes(entry))
52309
52368
  return;
52310
- const open = this.#approvals.length + this.#asks.length;
52311
- 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();
52312
52374
  return;
52313
- const terminals = [];
52314
- for (const entry of this.#approvals) {
52315
- terminals.push({
52316
- request: {
52317
- id: ++this.#seq,
52318
- name: "ask",
52319
- args: {},
52320
- ...entry.request.eventId !== undefined ? { eventId: entry.request.eventId } : {},
52321
- escalation: false,
52322
- invalidatedReason: reason
52323
- },
52324
- resolve: () => {}
52325
- });
52326
- }
52327
- for (const entry of this.#asks) {
52328
- terminals.push({
52329
- request: {
52330
- id: ++this.#seq,
52331
- name: "ask",
52332
- args: {},
52333
- ...entry.eventId !== undefined ? { eventId: entry.eventId } : {},
52334
- escalation: false,
52335
- invalidatedReason: reason
52336
- },
52337
- resolve: () => {}
52338
- });
52339
52375
  }
52340
- for (const entry of this.#approvals)
52341
- entry.resolve("rejected");
52342
- for (const entry of this.#asks)
52343
- entry.resolve([]);
52344
- this.#approvals = terminals;
52345
- this.#asks = [];
52346
- this.#changed();
52347
- }
52348
- pendingInvalidated() {
52349
- const out = new Map;
52350
- for (const entry of this.#approvals) {
52351
- if (entry.request.invalidatedReason !== undefined && entry.request.eventId !== undefined) {
52352
- out.set(entry.request.eventId, entry.request.invalidatedReason);
52353
- }
52376
+ if (frame !== undefined) {
52377
+ ownership?.pop(frame);
52378
+ frame = undefined;
52354
52379
  }
52355
- return out;
52356
- }
52357
- onIdle(fn) {
52358
- this.#idleHandlers.add(fn);
52359
- return () => this.#idleHandlers.delete(fn);
52380
+ afterLayout(() => {
52381
+ if (hasRequests())
52382
+ return;
52383
+ composerFocus?.();
52384
+ });
52360
52385
  }
52361
- #changed() {
52362
- for (const listener of this.#listeners)
52363
- listener();
52364
- const busy = this.#approvals.length > 0 || this.#asks.length > 0;
52365
- if (this.#busy && !busy)
52366
- for (const handler of this.#idleHandlers)
52367
- handler();
52368
- this.#busy = busy;
52369
- }
52370
- get pendingApproval() {
52371
- return this.#approvals[0]?.request;
52372
- }
52373
- get pendingApprovalCount() {
52374
- return this.#approvals.length;
52375
- }
52376
- get pendingAskCount() {
52377
- return this.#asks.length;
52378
- }
52379
- requestApproval(name, args) {
52380
- const ask = this.#matchApproval(name, args);
52381
- const promise = new Promise((resolve) => {
52382
- this.#approvals.push({
52383
- request: {
52384
- id: ++this.#seq,
52385
- name,
52386
- args,
52387
- escalation: ask?.escalation === true,
52388
- ...ask !== undefined ? { eventId: ask.eventId } : {}
52389
- },
52390
- resolve
52391
- });
52392
- this.#changed();
52393
- });
52394
- return promise;
52395
- }
52396
- #matchApproval(name, args) {
52397
- const asks = (this.#pendingAsks?.() ?? []).filter((ask) => ask.kind === "approval");
52398
- if (asks.length === 0)
52399
- return;
52400
- const callId = typeof args.callId === "string" ? args.callId : undefined;
52401
- if (callId !== undefined) {
52402
- const byCall = asks.filter((ask) => ask.callId === callId);
52403
- return byCall.length > 0 ? byCall[byCall.length - 1] : undefined;
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();
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;
52404
52416
  }
52405
- const reason = typeof args.reason === "string" ? args.reason : undefined;
52406
- const byName = asks.filter((ask) => (ask.toolName ?? "tool") === name && (reason === undefined || ask.reason === reason));
52407
- if (byName.length > 0)
52408
- return byName[byName.length - 1];
52409
- return asks.length === 1 ? asks[0] : undefined;
52410
- }
52411
- confirmApproval() {
52412
- this.#settleApproval("allowed-once");
52413
- }
52414
- rejectApproval() {
52415
- this.#settleApproval("rejected");
52416
- }
52417
- approveAlways() {
52418
- this.#settleEscalated("always");
52419
- }
52420
- approveSession() {
52421
- this.#settleEscalated("session");
52422
- }
52423
- #settleEscalated(verdict) {
52424
- if (this.#approvals[0]?.request.escalation !== true)
52425
- return;
52426
- this.#settleApproval(verdict);
52427
- }
52428
- #settleApproval(verdict) {
52429
- const head = this.#approvals.shift();
52430
- if (!head)
52431
- return;
52432
- head.resolve(verdict);
52433
- this.#changed();
52434
- }
52435
- syncPendingAsks() {
52436
- if (this.#pendingAsks === undefined)
52437
- return;
52438
- const asks = this.#pendingAsks();
52439
- let changed = false;
52440
- const approvalsBefore = this.#approvals.length;
52441
- this.#approvals = this.#approvals.filter((entry) => {
52442
- if (this.#approvalStillPending(entry.request, asks))
52443
- return true;
52444
- entry.resolve("rejected");
52445
- return false;
52446
- });
52447
- if (this.#approvals.length !== approvalsBefore)
52448
- changed = true;
52449
- const questionsBefore = this.#asks.length;
52450
- this.#asks = this.#asks.filter((entry) => {
52451
- if (this.#questionStillPending(entry, asks))
52452
- return true;
52453
- entry.resolve([]);
52454
- return false;
52455
- });
52456
- if (this.#asks.length !== questionsBefore)
52457
- changed = true;
52458
- if (changed)
52459
- this.#changed();
52460
- }
52461
- #approvalStillPending(request, asks) {
52462
- if (request.eventId !== undefined)
52463
- return asks.some((ask) => ask.eventId === request.eventId);
52464
- return asks.some((ask) => ask.kind === "approval");
52465
- }
52466
- #questionStillPending(entry, asks) {
52467
- if (entry.eventId !== undefined)
52468
- return asks.some((ask) => ask.eventId === entry.eventId);
52469
- return asks.some((ask) => ask.kind === "questions");
52470
- }
52471
- cancelAllApprovals() {
52472
- if (this.#approvals.length === 0)
52473
- return;
52474
- const entries = this.#approvals.splice(0);
52475
- for (const entry of entries)
52476
- entry.resolve("rejected");
52477
- this.#changed();
52478
- }
52479
- cancelAllAsks() {
52480
- if (this.#asks.length === 0)
52481
- return;
52482
- const entries = this.#asks.splice(0);
52483
- for (const entry of entries)
52484
- entry.resolve([]);
52485
- this.#changed();
52486
- }
52487
- get pendingAsk() {
52488
- const head = this.#asks[0];
52489
- if (!head)
52490
- return;
52491
- return {
52492
- id: head.id,
52493
- ...head.eventId !== undefined ? { eventId: head.eventId } : {},
52494
- questions: head.questions,
52495
- index: head.index,
52496
- picks: head.picks,
52497
- phase: head.phase,
52498
- customs: [...head.customs],
52499
- customDraft: head.customDrafts[head.index] ?? null,
52500
- cursors: [...head.cursors],
52501
- listCursors: [...head.listCursors],
52502
- reviewCursor: head.reviewCursor
52503
- };
52504
- }
52505
- get currentQuestion() {
52506
- const head = this.#asks[0];
52507
- return head?.questions[head.index];
52508
- }
52509
- #matchAsk(questions) {
52510
- const asks = (this.#pendingAsks?.() ?? []).filter((ask) => ask.kind === "questions");
52511
- if (asks.length === 0)
52512
- return;
52513
- const claimed = new Set(this.#asks.map((entry) => entry.eventId));
52514
- const available = asks.filter((ask) => !claimed.has(ask.eventId));
52515
- if (available.length === 0)
52516
- return;
52517
- const signature = askSignature(questions);
52518
- const exact = available.filter((ask) => askSignature(ask.questions ?? []) === signature);
52519
- if (exact.length > 0)
52520
- return exact[0];
52521
- return available.length === 1 ? available[0] : undefined;
52522
- }
52523
- answer(questions) {
52524
- if (questions.length === 0)
52525
- return Promise.resolve([]);
52526
- const ask = this.#matchAsk(questions);
52527
- return new Promise((resolve) => {
52528
- this.#asks.push({
52529
- id: ++this.#seq,
52530
- ...ask !== undefined ? { eventId: ask.eventId } : {},
52531
- questions,
52532
- index: 0,
52533
- picks: questions.map((question) => recommendedPicks(question)),
52534
- phase: questions[0]?.options.length === 0 ? "input" : "questions",
52535
- customs: questions.map(() => {
52536
- return;
52537
- }),
52538
- customDrafts: questions.map(() => null),
52539
- cursors: questions.map(() => 0),
52540
- listCursors: questions.map(() => 0),
52541
- reviewCursor: 0,
52542
- resolve
52543
- });
52544
- this.#changed();
52545
- });
52546
- }
52547
- toggle(option) {
52548
- const head = this.#asks[0];
52549
- const question = head?.questions[head.index];
52550
- if (!head || !question || head.phase === "review")
52551
- return;
52552
- if (head.phase === "input")
52553
- return;
52554
- head.customs[head.index] = undefined;
52555
- head.customDrafts[head.index] = null;
52556
- if (question.multiSelect === true) {
52557
- const current = head.picks[head.index] ?? [];
52558
- head.picks[head.index] = current.includes(option) ? current.filter((label) => label !== option) : [...current, option];
52559
- this.#changed();
52560
- return;
52417
+ };
52418
+ onCleanup(() => {
52419
+ cancelAfterLayout?.();
52420
+ if (frame !== undefined) {
52421
+ ownership?.pop(frame);
52422
+ frame = undefined;
52561
52423
  }
52562
- head.picks[head.index] = [option];
52563
- if (head.questions.length === 1) {
52564
- this.#asks.shift();
52565
- head.resolve(this.#envelope(head));
52566
- this.#changed();
52567
- return;
52424
+ setQueue([]);
52425
+ });
52426
+ return createComponent2(Context7.Provider, {
52427
+ value: api,
52428
+ get children() {
52429
+ return props.children;
52568
52430
  }
52569
- if (this.#allAnswered(head)) {
52570
- head.phase = "review";
52571
- head.reviewCursor = 0;
52572
- } else {
52573
- const next = head.questions.findIndex((_, qi) => qi > head.index && (head.picks[qi]?.length ?? 0) === 0 && !head.customs[qi]);
52574
- if (next >= 0)
52575
- head.index = next;
52576
- head.phase = head.questions[head.index]?.options.length === 0 ? "input" : "questions";
52577
- if (head.phase === "input") {
52578
- const question = head.questions[head.index];
52579
- if (question !== undefined) {
52580
- head.cursors[head.index] = inlineRowIndex(question, askNeedsReview(head.questions));
52581
- }
52582
- }
52583
- }
52584
- this.#changed();
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)
52475
+ return;
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;
52585
52598
  }
52586
- switchFocus(direction) {
52587
- const head = this.#asks[0];
52588
- if (!head || head.phase === "review" || head.questions.length < 2)
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;
52609
+ }
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")
52589
52650
  return;
52590
- if (head.phase === "input" && (head.questions[head.index]?.options.length ?? 0) > 0)
52651
+ const current = question();
52652
+ if (current?.header === undefined || current.header === current.prompt)
52591
52653
  return;
52592
- const next = Math.max(0, Math.min(head.questions.length - 1, head.index + direction));
52593
- if (next === head.index)
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 {
52594
52667
  return;
52595
- head.index = next;
52596
- const question = head.questions[next];
52597
- head.phase = question?.options.length === 0 ? "input" : "questions";
52598
- if (head.phase === "input" && question !== undefined) {
52599
- head.cursors[next] = inlineRowIndex(question, askNeedsReview(head.questions));
52600
52668
  }
52601
- this.#changed();
52602
- }
52603
- confirmQuestion() {
52604
- const head = this.#asks[0];
52605
- if (!head || head.phase === "review" || head.phase === "input")
52606
- return false;
52607
- const question = head.questions[head.index];
52608
- if (question === undefined || !askNeedsReview(head.questions))
52609
- return false;
52610
- const next = head.questions.findIndex((_, qi) => qi > head.index && (head.picks[qi]?.length ?? 0) === 0 && !head.customs[qi]);
52611
- if (next >= 0) {
52612
- head.index = next;
52613
- const target = head.questions[next];
52614
- head.phase = target?.options.length === 0 ? "input" : "questions";
52615
- if (head.phase === "input" && target !== undefined) {
52616
- head.cursors[next] = inlineRowIndex(target, askNeedsReview(head.questions));
52617
- }
52618
- } else {
52619
- head.phase = "review";
52620
- head.reviewCursor = 0;
52621
- }
52622
- this.#changed();
52623
- return true;
52624
- }
52625
- beginCustom() {
52626
- const head = this.#asks[0];
52627
- if (!head || head.phase === "review")
52628
- return false;
52629
- const question = head.questions[head.index];
52630
- head.customDrafts[head.index] = head.customs[head.index] ?? "";
52631
- head.phase = "input";
52632
- if (question !== undefined) {
52633
- head.cursors[head.index] = inlineRowIndex(question, askNeedsReview(head.questions));
52634
- }
52635
- this.#changed();
52636
- return true;
52637
- }
52638
- patchCustom(text) {
52639
- const head = this.#asks[0];
52640
- if (!head || head.customDrafts[head.index] === null)
52641
- return;
52642
- head.customDrafts[head.index] = text;
52643
- this.#changed();
52644
- }
52645
- commitCustom() {
52646
- const head = this.#asks[0];
52647
- const question = head?.questions[head.index];
52648
- if (!head || !question)
52649
- return;
52650
- const draft = head.customDrafts[head.index] ?? null;
52651
- if (draft === null)
52652
- return;
52653
- const text = draft.trim();
52654
- head.customDrafts[head.index] = null;
52655
- if (text === "") {
52656
- this.#backToList(head);
52657
- this.#changed();
52658
- return;
52659
- }
52660
- head.customs[head.index] = text;
52661
- head.picks[head.index] = [];
52662
- if (question.multiSelect !== true && head.questions.length === 1) {
52663
- this.#asks.shift();
52664
- head.resolve(this.#envelope(head));
52665
- this.#changed();
52666
- return;
52667
- }
52668
- if (this.#allAnswered(head)) {
52669
- head.phase = "review";
52670
- head.reviewCursor = 0;
52671
- } else {
52672
- const next = head.questions.findIndex((_, qi) => qi > head.index && (head.picks[qi]?.length ?? 0) === 0 && !head.customs[qi]);
52673
- if (next >= 0)
52674
- head.index = next;
52675
- head.phase = head.questions[head.index]?.options.length === 0 ? "input" : "questions";
52676
- }
52677
- this.#changed();
52678
- }
52679
- cancelCustomEdit() {
52680
- const head = this.#asks[0];
52681
- if (!head || head.customDrafts[head.index] === null)
52682
- return;
52683
- head.customDrafts[head.index] = null;
52684
- this.#backToList(head);
52685
- this.#changed();
52686
- }
52687
- get inlineText() {
52688
- const head = this.#asks[0];
52689
- if (!head)
52690
- return "";
52691
- const draft = head.customDrafts[head.index];
52692
- if (draft !== null && draft !== undefined)
52693
- return draft;
52694
- return head.customs[head.index] ?? "";
52695
- }
52696
- setInlineText(text) {
52697
- const head = this.#asks[0];
52698
- const question = head?.questions[head.index];
52699
- if (!head || !question || head.phase === "review")
52700
- return;
52701
- if ((head.customDrafts[head.index] ?? null) === null && text === "")
52702
- return;
52703
- head.customDrafts[head.index] = text;
52704
- head.phase = "input";
52705
- head.cursors[head.index] = inlineRowIndex(question, askNeedsReview(head.questions));
52706
- this.#changed();
52707
- }
52708
- focusInput() {
52709
- const head = this.#asks[0];
52710
- const question = head?.questions[head.index];
52711
- if (!head || !question || head.phase === "review")
52712
- return;
52713
- head.phase = "input";
52714
- head.cursors[head.index] = inlineRowIndex(question, askNeedsReview(head.questions));
52715
- this.#changed();
52716
- }
52717
- focusOptions() {
52718
- const head = this.#asks[0];
52719
- if (!head || head.phase !== "input")
52720
- return;
52721
- this.#backToList(head);
52722
- this.#changed();
52723
- }
52724
- setCursor(row) {
52725
- const head = this.#asks[0];
52726
- const question = head?.questions[head.index];
52727
- if (!head || !question || head.phase === "review")
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)
52728
52684
  return;
52729
- const needsReview = askNeedsReview(head.questions);
52730
- const inline = inlineRowIndex(question, needsReview);
52731
- const next = Math.max(0, Math.min(inline, Math.floor(row)));
52732
- head.cursors[head.index] = next;
52733
- head.phase = next === inline ? "input" : "questions";
52734
- if (next !== inline)
52735
- head.listCursors[head.index] = next;
52736
- this.#changed();
52737
- }
52738
- moveCursor(delta) {
52739
- const head = this.#asks[0];
52740
- const question = head?.questions[head.index];
52741
- if (!head || !question || head.phase === "review")
52685
+ const scroller = nearestScroller(row);
52686
+ if (scroller === undefined)
52742
52687
  return;
52743
- const needsReview = askNeedsReview(head.questions);
52744
- const last = questionRowCount(question, needsReview) - 1;
52745
- const next = Math.max(0, Math.min(last, (head.cursors[head.index] ?? 0) + delta));
52746
- const inline = inlineRowIndex(question, needsReview);
52747
- head.cursors[head.index] = next;
52748
- head.phase = next === inline ? "input" : "questions";
52749
- if (next !== inline)
52750
- head.listCursors[head.index] = next;
52751
- this.#changed();
52688
+ scroller.scrollChildIntoView(row, {
52689
+ align: "nearest"
52690
+ });
52752
52691
  }
52753
- setReviewCursor(row) {
52754
- const head = this.#asks[0];
52755
- if (!head || head.phase !== "review")
52756
- return;
52757
- const next = Math.max(0, Math.min(head.questions.length, Math.floor(row)));
52758
- if (next === head.reviewCursor)
52692
+ function focusInputRow() {
52693
+ const input = inputEl;
52694
+ if (input === undefined || input.isDestroyed)
52759
52695
  return;
52760
- head.reviewCursor = next;
52761
- this.#changed();
52762
- }
52763
- moveReviewCursor(delta) {
52764
- this.setReviewCursor((this.#asks[0]?.reviewCursor ?? 0) + delta);
52696
+ input.focus();
52697
+ revealRow(inlineRowEl);
52765
52698
  }
52766
- #backToList(head) {
52767
- const question = head.questions[head.index];
52768
- if (question === undefined)
52769
- return;
52770
- if (question.options.length === 0) {
52771
- head.phase = "input";
52699
+ createEffect(on(() => phase(), (next) => {
52700
+ if (next === "input") {
52701
+ focusInputRow();
52772
52702
  return;
52773
52703
  }
52774
- head.phase = "questions";
52775
- const inline = inlineRowIndex(question, askNeedsReview(head.questions));
52776
- const row = Math.max(0, Math.min(inline - 1, head.listCursors[head.index] ?? 0));
52777
- head.cursors[head.index] = row;
52778
- head.listCursors[head.index] = row;
52779
- }
52780
- enterReview() {
52781
- const head = this.#asks[0];
52782
- if (!head || head.phase === "review")
52783
- return false;
52784
- if (!askNeedsReview(head.questions))
52785
- return false;
52786
- head.phase = "review";
52787
- head.reviewCursor = 0;
52788
- this.#changed();
52789
- return true;
52790
- }
52791
- backToQuestions(focus) {
52792
- const head = this.#asks[0];
52793
- if (!head || head.phase !== "review")
52794
- return;
52795
- head.phase = "questions";
52796
- if (focus !== undefined && focus >= 0 && focus < head.questions.length)
52797
- head.index = focus;
52798
- const question = head.questions[head.index];
52799
- if (question !== undefined && question.options.length === 0)
52800
- head.phase = "input";
52801
- this.#changed();
52802
- }
52803
- submit() {
52804
- const head = this.#asks[0];
52805
- if (!head)
52704
+ if (next !== "questions")
52806
52705
  return;
52807
- this.#asks.shift();
52808
- head.resolve(this.#envelope(head));
52809
- this.#changed();
52810
- }
52811
- #allAnswered(head) {
52812
- return head.questions.every((_, qi) => (head.picks[qi]?.length ?? 0) > 0 || head.customs[qi] !== undefined && head.customs[qi] !== "");
52813
- }
52814
- #envelope(head) {
52815
- return head.questions.map((question, qi) => {
52816
- const custom = head.customs[qi];
52817
- if (custom !== undefined && custom !== "") {
52818
- return { questionId: question.id, selected: "", custom };
52819
- }
52820
- const picks = head.picks[qi] ?? [];
52821
- return {
52822
- questionId: question.id,
52823
- selected: picks[0] ?? "",
52824
- ...picks.length > 1 ? { selections: [...picks] } : {}
52825
- };
52826
- });
52827
- }
52828
- decline() {
52829
- const head = this.#asks.shift();
52830
- 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")
52831
52720
  return;
52832
- head.resolve([]);
52833
- this.#changed();
52834
- }
52835
- }
52836
- var init_turn_overlay_controller = __esm(() => {
52837
- init_ask_options();
52838
- });
52839
-
52840
- // ../tui-base/src/ui/dialog-confirm.tsx
52841
- import { TextAttributes as TextAttributes7 } from "@opentui/core";
52842
- function DialogConfirm(props) {
52843
- const dialog = useDialog();
52844
- const theme = useTheme().surface("dialog");
52845
- const newDesigns = useNewDesigns();
52846
- const row = () => currentRowColors(theme);
52847
- const [store, setStore] = createStore({
52848
- active: "confirm"
52849
- });
52850
- const choose = (key) => {
52851
- if (key === "confirm")
52852
- props.onConfirm?.();
52853
- if (key === "cancel")
52854
- props.onCancel?.();
52855
- dialog.clear();
52856
- };
52857
- const chooseExtra = (action) => {
52858
- action.onTrigger();
52859
- dialog.clear();
52860
- };
52861
- Keymap2.createLayer(() => ({
52862
- mode: "modal",
52863
- commands: [...newDesigns() ? [{
52864
- bind: "return",
52865
- title: "Confirm",
52866
- group: "Dialog",
52867
- run: () => choose("confirm")
52868
- }, {
52869
- bind: "escape",
52870
- title: "Cancel",
52871
- group: "Dialog",
52872
- run: () => choose("cancel")
52873
- }] : [{
52874
- bind: "return",
52875
- title: "Confirm dialog selection",
52876
- group: "Dialog",
52877
- run: () => choose(store.active)
52878
- }, {
52879
- bind: "left",
52880
- title: "Previous dialog option",
52881
- group: "Dialog",
52882
- run: () => {
52883
- setStore("active", store.active === "confirm" ? "cancel" : "confirm");
52884
- }
52885
- }, {
52886
- bind: "right",
52887
- title: "Next dialog option",
52888
- group: "Dialog",
52889
- run: () => {
52890
- setStore("active", store.active === "confirm" ? "cancel" : "confirm");
52891
- }
52892
- }], ...(props.extraActions ?? []).map((action) => ({
52893
- bind: action.bind,
52894
- title: action.title ?? action.label,
52895
- group: "Dialog",
52896
- run: () => chooseExtra(action)
52897
- }))]
52721
+ revealRow(listEl?.getChildren()[cursor()]);
52898
52722
  }));
52899
- return createComponent2(DialogLayout, {
52900
- get header() {
52901
- return createComponent2(DialogHeader, {
52902
- get title() {
52903
- return props.title;
52904
- },
52905
- get titleView() {
52906
- return (() => {
52907
- var _el$2 = createElement("box"), _el$3 = createElement("text");
52908
- insertNode(_el$2, _el$3);
52909
- setProp(_el$2, "flexDirection", "row");
52910
- insert(_el$2, createComponent2(ReminderBadge, {}), _el$3);
52911
- setProp(_el$3, "wrapMode", "none");
52912
- insert(_el$3, () => props.title.replace(/^\u26A0\s*/, ""));
52913
- effect((_p$) => {
52914
- var _v$ = newDesigns() ? undefined : TextAttributes7.BOLD, _v$2 = theme.text.base;
52915
- _v$ !== _p$.e && (_p$.e = setProp(_el$3, "attributes", _v$, _p$.e));
52916
- _v$2 !== _p$.t && (_p$.t = setProp(_el$3, "fg", _v$2, _p$.t));
52917
- return _p$;
52918
- }, {
52919
- e: undefined,
52920
- t: undefined
52921
- });
52922
- return _el$2;
52923
- })();
52924
- }
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)
52925
52738
  });
52926
- },
52927
- get footer() {
52928
- return {
52929
- actions: {
52930
- secondary: (props.extraActions ?? []).map((action) => ({
52931
- title: action.label.toLowerCase(),
52932
- key: action.bind,
52933
- onTrigger: () => chooseExtra(action)
52934
- })),
52935
- primary: [
52936
- {
52937
- title: (props.label?.cancel ?? "cancel").toLowerCase(),
52938
- key: "esc",
52939
- onTrigger: () => choose("cancel")
52940
- },
52941
- {
52942
- title: (props.label?.confirm ?? "confirm").toLowerCase(),
52943
- key: "enter",
52944
- onTrigger: () => choose("confirm")
52945
- }
52946
- ]
52947
- }
52948
- };
52949
- },
52950
- get legacyFooter() {
52951
- return (() => {
52952
- var _el$4 = createElement("box"), _el$5 = createElement("box"), _el$6 = createElement("box");
52953
- insertNode(_el$4, _el$5);
52954
- insertNode(_el$4, _el$6);
52955
- setProp(_el$4, "flexDirection", "row");
52956
- setProp(_el$4, "justifyContent", "space-between");
52957
- setProp(_el$4, "gap", 1);
52958
- setProp(_el$5, "flexDirection", "row");
52959
- insert(_el$5, createComponent2(For, {
52960
- get each() {
52961
- return props.extraActions ?? [];
52962
- },
52963
- children: (action) => (() => {
52964
- var _el$7 = createElement("box"), _el$8 = createElement("text");
52965
- insertNode(_el$7, _el$8);
52966
- setProp(_el$7, "paddingLeft", 1);
52967
- setProp(_el$7, "paddingRight", 1);
52968
- setProp(_el$7, "onMouseUp", () => chooseExtra(action));
52969
- insert(_el$8, () => `${action.label} [${action.bind}]`);
52970
- effect((_$p) => setProp(_el$8, "fg", theme.text.muted, _$p));
52971
- return _el$7;
52972
- })()
52973
- }));
52974
- setProp(_el$6, "flexDirection", "row");
52975
- insert(_el$6, createComponent2(For, {
52976
- each: ["cancel", "confirm"],
52977
- children: (key) => (() => {
52978
- var _el$9 = createElement("box"), _el$0 = createElement("text");
52979
- insertNode(_el$9, _el$0);
52980
- setProp(_el$9, "paddingLeft", 1);
52981
- setProp(_el$9, "paddingRight", 1);
52982
- setProp(_el$9, "onMouseUp", () => choose(key));
52983
- insert(_el$0, () => titlecase(props.label?.[key] ?? key));
52984
- effect((_p$) => {
52985
- var _v$3 = key === store.active ? row().backgroundColor : undefined, _v$4 = key === store.active ? row().textColor : theme.text.muted;
52986
- _v$3 !== _p$.e && (_p$.e = setProp(_el$9, "backgroundColor", _v$3, _p$.e));
52987
- _v$4 !== _p$.t && (_p$.t = setProp(_el$0, "fg", _v$4, _p$.t));
52988
- return _p$;
52989
- }, {
52990
- e: undefined,
52991
- t: undefined
52992
- });
52993
- return _el$9;
52994
- })()
52995
- }));
52996
- return _el$4;
52997
- })();
52998
- },
52999
- get children() {
53000
- var _el$ = createElement("text");
53001
- insert(_el$, () => props.message);
53002
- effect((_$p) => setProp(_el$, "fg", theme.text.muted, _$p));
53003
- return _el$;
53004
52739
  }
53005
- });
53006
- }
53007
- var init_dialog_confirm = __esm(() => {
53008
- init_index_bun();
53009
- init_index_bun();
53010
- init_index_bun();
53011
- init_index_bun();
53012
- init_index_bun();
53013
- init_index_bun();
53014
- init_index_bun();
53015
- init_keymap();
53016
- init_theme3();
53017
- init_config();
53018
- init_dialog();
53019
- init_server2();
53020
- init_server();
53021
- init_locale();
53022
- init_semantic();
53023
- init_turn_overlays();
53024
- });
53025
-
53026
- // ../tui-base/src/routes/session/ask-keys.ts
53027
- function printableText(event) {
53028
- const text = event.sequence;
53029
- if (text.length !== 1)
53030
- return;
53031
- if (event.ctrl || event.meta || event.super === true || event.hyper === true)
53032
- return;
53033
- if (text === " ")
53034
- return;
53035
- if (text >= "0" && text <= "9")
53036
- return;
53037
- const code = text.codePointAt(0) ?? 0;
53038
- if (code < 32 || code === 127)
53039
- return;
53040
- return text;
53041
- }
53042
- function useAskKeys(options) {
53043
- const keymap = Keymap2.useOptional();
53044
- if (keymap === undefined)
53045
- return;
53046
- const renderer = useRenderer();
53047
- const ownership = useInputOwnershipOptional();
53048
- const ownsDock = () => ownership === undefined || ownership.top().kind === "dock";
53049
- const ask = () => options.controller.pendingAsk;
53050
- const question = () => {
53051
- const batch = ask();
53052
- return batch?.questions[batch.index];
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)
52743
+ });
53053
52744
  };
53054
- const needsReview = () => askNeedsReview(ask()?.questions ?? []);
53055
- const currentRow = () => {
52745
+ const answerText = (qi) => {
53056
52746
  const batch = ask();
53057
- return batch === undefined ? 0 : batch.cursors[batch.index] ?? 0;
53058
- };
53059
- const inputFocused = () => {
53060
- const input = options.input();
53061
- return input !== undefined && renderer.currentFocusedRenderable === input;
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(", ");
53062
52753
  };
53063
- onCleanup(keymap.intercept("key", ({ event }) => {
53064
- if (!ownsDock())
53065
- return;
53066
- const batch = ask();
53067
- if (batch === undefined || batch.phase !== "questions")
53068
- return;
53069
- if (printableText(event) === undefined)
53070
- return;
53071
- options.controller.focusInput();
53072
- options.input()?.focus();
53073
- }));
53074
- function move(delta) {
53075
- const batch = ask();
53076
- if (batch === undefined)
53077
- return false;
53078
- if (batch.phase === "review") {
53079
- options.controller.moveReviewCursor(delta);
53080
- return true;
53081
- }
53082
- if (batch.phase === "input")
53083
- return false;
53084
- options.controller.moveCursor(delta);
53085
- return true;
53086
- }
53087
- function page(direction) {
53088
- return move(direction * ASK_PAGE_ROWS);
53089
- }
53090
- function boundary(toEnd) {
53091
- const batch = ask();
53092
- if (batch === undefined)
53093
- return false;
53094
- if (batch.phase === "review") {
53095
- options.controller.setReviewCursor(toEnd ? batch.questions.length : 0);
53096
- return true;
53097
- }
53098
- if (batch.phase === "input")
53099
- return false;
53100
- const current = question();
53101
- if (current === undefined)
53102
- return false;
53103
- options.controller.setCursor(toEnd ? questionRowCount(current, needsReview()) - 1 : 0);
53104
- return true;
53105
- }
53106
- function switchQuestion(direction) {
53107
- const batch = ask();
53108
- if (batch === undefined)
53109
- return false;
53110
- if (batch.phase === "input")
53111
- return false;
53112
- if (batch.phase === "review") {
53113
- if (direction === -1) {
53114
- options.controller.backToQuestions(batch.questions.length - 1);
53115
- return true;
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;
53116
52805
  }
53117
- return false;
53118
- }
53119
- if (batch.questions.length < 2)
53120
- return false;
53121
- options.controller.switchFocus(direction);
53122
- return true;
53123
- }
53124
- function enter() {
53125
- const batch = ask();
53126
- if (batch === undefined)
53127
- return false;
53128
- if (batch.phase === "input")
53129
- return false;
53130
- if (batch.phase === "review") {
53131
- const intent = reviewRowIntent(batch.reviewCursor, batch.questions.length);
53132
- if (intent.kind === "submit") {
53133
- options.controller.submit();
53134
- return true;
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();
52839
+ },
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;
52877
+ }
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")}`);
52956
+ effect((_p$) => {
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));
52963
+ return _p$;
52964
+ }, {
52965
+ e: undefined,
52966
+ t: undefined,
52967
+ a: undefined,
52968
+ o: undefined,
52969
+ i: undefined
52970
+ });
52971
+ return _el$25;
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;
53135
52995
  }
53136
- options.controller.backToQuestions(intent.question);
53137
- return true;
53138
- }
53139
- const current = question();
53140
- if (current === undefined)
53141
- return false;
53142
- const row = currentRow();
53143
- if (hasReviewRow(current, needsReview()) && row === current.options.length) {
53144
- return options.controller.enterReview();
53145
- }
53146
- const option = current.options[row];
53147
- if (option === undefined)
53148
- return false;
53149
- if (current.multiSelect === true)
53150
- return options.controller.confirmQuestion();
53151
- options.controller.toggle(option.label);
53152
- return true;
53153
- }
53154
- function space() {
53155
- const batch = ask();
53156
- if (batch === undefined || batch.phase !== "questions")
53157
- return false;
53158
- const current = question();
53159
- if (current === undefined || current.multiSelect !== true)
53160
- return false;
53161
- if (inputFocused())
53162
- return false;
53163
- const option = current.options[currentRow()];
53164
- if (option === undefined)
53165
- return false;
53166
- options.controller.toggle(option.label);
53167
- return true;
53168
- }
53169
- function digit(index) {
53170
- const batch = ask();
53171
- if (batch === undefined || batch.phase !== "questions")
53172
- return false;
53173
- if (inputFocused())
53174
- return false;
53175
- const option = question()?.options[index];
53176
- if (option === undefined)
53177
- return false;
53178
- options.controller.toggle(option.label);
53179
- return true;
53180
- }
53181
- function atOutermost(batch) {
53182
- if (batch.phase === "review" || batch.index > 0)
53183
- return false;
53184
- if (batch.phase === "input")
53185
- return (batch.questions[batch.index]?.options.length ?? 0) === 0;
53186
- return true;
53187
- }
53188
- function backOut() {
53189
- const batch = ask();
53190
- if (batch === undefined)
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()
53014
+ }));
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
+ })();
53038
+ }
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 ";
53055
+ };
53056
+ const stateColor = () => {
53057
+ if (props.cursor())
53058
+ return currentFg();
53059
+ return props.row().selected ? success() : faint();
53060
+ };
53061
+ const badgeInline = () => {
53062
+ if (!label().recommended || props.compact())
53191
53063
  return false;
53192
- if (batch.phase === "review") {
53193
- options.controller.backToQuestions(batch.questions.length - 1);
53194
- return true;
53195
- }
53196
- if (batch.phase === "input") {
53197
- const current = batch.questions[batch.index];
53198
- if (current !== undefined && current.options.length > 0) {
53199
- options.controller.focusOptions();
53200
- 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;
53201
53096
  }
53202
- }
53203
- if (batch.index > 0) {
53204
- options.controller.switchFocus(-1);
53205
- return true;
53206
- }
53207
- options.controller.decline();
53208
- return true;
53209
- }
53210
- function interrupt() {
53211
- const batch = ask();
53212
- if (batch === undefined)
53213
- return false;
53214
- if (atOutermost(batch))
53215
- armNonArmingInterrupt();
53216
- return backOut();
53217
- }
53218
- Keymap2.createLayer(() => ({
53219
- mode: "global",
53220
- enabled: ownsDock,
53221
- commands: [
53222
- { bind: "up,ctrl+p", run: () => move(-1) },
53223
- { bind: "down,ctrl+n", run: () => move(1) },
53224
- { bind: "pageup", run: () => page(-1) },
53225
- { bind: "pagedown", run: () => page(1) },
53226
- { bind: "home", run: () => boundary(false) },
53227
- { bind: "end", run: () => boundary(true) },
53228
- { bind: "return", run: enter },
53229
- { bind: "space", run: space },
53230
- ...Array.from({ length: 9 }, (_, index) => ({
53231
- bind: `${index + 1}`,
53232
- enabled: () => !inputFocused(),
53233
- run: () => digit(index)
53234
- })),
53235
- { bind: "left", run: () => switchQuestion(-1) },
53236
- { bind: "right", run: () => switchQuestion(1) },
53237
- { bind: "escape", run: backOut },
53238
- { bind: "ctrl+c", run: interrupt }
53239
- ]
53240
- }));
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;
53117
+ }
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
+ })();
53241
53159
  }
53242
- var ASK_PAGE_ROWS = 5;
53243
- var init_ask_keys = __esm(() => {
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();
53244
53170
  init_index_bun();
53245
53171
  init_server();
53246
- init_keymap();
53247
- init_input_ownership();
53172
+ init_i18n();
53173
+ init_theme3();
53174
+ init_config();
53175
+ init_semantic();
53248
53176
  init_ask_options();
53249
- init_turn_cancel();
53177
+ init_ask_keys();
53178
+ init_dock_host();
53179
+ init_string_width();
53250
53180
  });
53251
53181
 
53252
- // ../tui-base/src/routes/session/dock-host.tsx
53253
- function firstFocusable(node) {
53254
- if (node === undefined)
53255
- return;
53256
- for (const child of node.getChildren()) {
53257
- if (child.focusable)
53258
- return child;
53259
- const nested = firstFocusable(child);
53260
- if (nested !== undefined)
53261
- return nested;
53262
- }
53263
- return;
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();
53264
53191
  }
53265
- function DockProvider(props) {
53266
- const renderer = useRenderer();
53267
- const ownership = useInputOwnershipOptional();
53268
- const [queue, setQueue] = createSignal([]);
53269
- let frame;
53270
- let composerFocus;
53271
- let focusTarget;
53272
- let cancelAfterLayout;
53273
- const hasRequests = () => queue().length > 0;
53274
- function afterLayout(callback) {
53275
- cancelAfterLayout?.();
53276
- if (renderer.isDestroyed)
53277
- return;
53278
- let done = false;
53279
- const handler = () => {
53280
- if (done)
53281
- return;
53282
- done = true;
53283
- renderer.off("frame", handler);
53284
- if (cancelAfterLayout === cancel)
53285
- cancelAfterLayout = undefined;
53286
- callback();
53287
- };
53288
- const cancel = () => {
53289
- if (done)
53290
- return;
53291
- done = true;
53292
- renderer.off("frame", handler);
53293
- if (cancelAfterLayout === cancel)
53294
- cancelAfterLayout = undefined;
53295
- };
53296
- cancelAfterLayout = cancel;
53297
- renderer.on("frame", handler);
53298
- }
53299
- function focusDock() {
53300
- afterLayout(() => {
53301
- if (!hasRequests())
53302
- return;
53303
- const target = focusTarget?.();
53304
- if (target !== undefined) {
53305
- target.focus();
53306
- return;
53307
- }
53308
- renderer.currentFocusedRenderable?.blur();
53309
- });
53310
- }
53311
- function remove(entry) {
53312
- const before = queue();
53313
- if (!before.includes(entry))
53314
- return;
53315
- const next = before.filter((item) => item !== entry);
53316
- setQueue(next);
53317
- if (next.length > 0) {
53318
- if (before[0] !== next[0])
53319
- focusDock();
53320
- return;
53321
- }
53322
- if (frame !== undefined) {
53323
- ownership?.pop(frame);
53324
- frame = undefined;
53325
- }
53326
- afterLayout(() => {
53327
- if (hasRequests())
53328
- return;
53329
- composerFocus?.();
53330
- });
53331
- }
53332
- const api = {
53333
- open(render, options = {}) {
53334
- const id = ++ordinal2;
53335
- const entry = {
53336
- id,
53337
- kind: options.kind,
53338
- options,
53339
- close: () => remove(entry),
53340
- render
53341
- };
53342
- const before = queue();
53343
- setQueue([...before, entry]);
53344
- if (before.length === 0) {
53345
- frame = ownership?.push("dock");
53346
- focusDock();
53347
- }
53348
- return {
53349
- id,
53350
- close: entry.close
53351
- };
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);
53352
53204
  },
53353
- queueDepth: () => Math.max(0, queue().length - 1),
53354
- isOpen: () => hasRequests(),
53355
- currentKind: () => queue()[0]?.kind,
53356
- current: () => queue()[0],
53357
- bindComposerFocus(refocus) {
53358
- composerFocus = refocus;
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
+ };
53359
53213
  },
53360
- bindFocusTarget(resolve) {
53361
- focusTarget = resolve;
53362
- }
53363
- };
53364
- onCleanup(() => {
53365
- cancelAfterLayout?.();
53366
- if (frame !== undefined) {
53367
- ownership?.pop(frame);
53368
- frame = undefined;
53369
- }
53370
- setQueue([]);
53371
- });
53372
- return createComponent2(Context7.Provider, {
53373
- value: api,
53374
- get children() {
53375
- return props.children;
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;
53376
53226
  }
53377
53227
  });
53378
53228
  }
53379
- function useDock() {
53380
- const value = useContext(Context7);
53381
- if (!value)
53382
- throw new Error("Dock.Provider is missing");
53383
- return value;
53384
- }
53385
- function DockSeat(props) {
53386
- const dock = useDock();
53387
- const dimensions = useTerminalSize();
53229
+ function ReminderBadge() {
53388
53230
  const theme = useThemeOptional();
53389
- let scroll;
53390
- let body;
53391
- let disposed = false;
53392
- const [measured, setMeasured] = createSignal(undefined);
53393
- const resolveFocus = () => {
53394
- const designated = dock.current()?.options.focusRef?.();
53395
- return designated ?? firstFocusable(body);
53396
- };
53397
- dock.bindFocusTarget(resolveFocus);
53398
- onCleanup(() => {
53399
- disposed = true;
53400
- dock.bindFocusTarget(undefined);
53401
- });
53402
- const capRows = () => Math.max(1, Math.floor(dimensions().height * DOCK_MAX_ROWS_RATIO));
53403
- const contentRows = () => measured() ?? dock.current()?.options.contentRows ?? capRows();
53404
- const overflows = () => contentRows() > capRows() && capRows() > 1;
53405
- const viewportRows = () => Math.max(1, Math.min(contentRows(), capRows() - (overflows() ? 1 : 0)));
53406
- const hiddenRows = () => Math.max(0, contentRows() - viewportRows());
53407
- const indicatorText = () => {
53408
- const label = dock.current()?.options.overflowLabel;
53409
- return label ? label(hiddenRows()) : `\u2191\u2193 ${hiddenRows()}`;
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);
53410
53242
  };
53411
- const muted = () => theme?.text.muted ?? "#9aa5ce";
53412
- const background = () => theme?.background.base ?? "black";
53413
- createEffect(on(() => dock.current()?.id, () => {
53414
- if (scroll !== undefined && !scroll.isDestroyed)
53415
- scroll.scrollTo(0);
53416
- }, {
53417
- defer: true
53418
- }));
53419
- createEffect(on(capRows, () => {
53420
- if (scroll === undefined || scroll.isDestroyed)
53421
- return;
53422
- scroll.afterLayout(() => {
53423
- if (scroll === undefined || scroll.isDestroyed)
53424
- return;
53425
- const max = Math.max(0, scroll.scrollHeight - scroll.viewport.height);
53426
- if (scroll.scrollTop > max)
53427
- scroll.scrollTo(max);
53428
- });
53429
- }, {
53430
- defer: true
53431
- }));
53432
53243
  return (() => {
53433
- var _el$ = createElement("box"), _el$2 = createElement("box");
53434
- insertNode(_el$, _el$2);
53435
- setProp(_el$, "width", "100%");
53244
+ var _el$ = createElement("text");
53245
+ insertNode(_el$, createTextNode(`\u26A0 `));
53436
53246
  setProp(_el$, "flexShrink", 0);
53437
- setProp(_el$, "flexDirection", "column");
53438
- setProp(_el$2, "width", "100%");
53439
- setProp(_el$2, "flexShrink", 0);
53440
- insert(_el$2, () => props.composer());
53441
- insert(_el$, createComponent2(Show, {
53442
- get when() {
53443
- return dock.current();
53444
- },
53445
- children: (request) => (() => {
53446
- var _el$3 = createElement("box"), _el$4 = createElement("scrollbox"), _el$5 = createElement("box");
53447
- insertNode(_el$3, _el$4);
53448
- setProp(_el$3, "width", "100%");
53449
- setProp(_el$3, "flexShrink", 0);
53450
- setProp(_el$3, "flexDirection", "column");
53451
- insertNode(_el$4, _el$5);
53452
- use((value) => {
53453
- scroll = value;
53454
- }, _el$4);
53455
- setProp(_el$4, "width", "100%");
53456
- setProp(_el$4, "flexShrink", 0);
53457
- setProp(_el$4, "focusable", false);
53458
- setProp(_el$4, "scrollY", true);
53459
- setProp(_el$4, "scrollX", false);
53460
- setProp(_el$4, "overflow", "hidden");
53461
- setProp(_el$4, "verticalScrollbarOptions", {
53462
- visible: false
53463
- });
53464
- use((value) => {
53465
- body = value;
53466
- }, _el$5);
53467
- setProp(_el$5, "width", "100%");
53468
- setProp(_el$5, "flexDirection", "column");
53469
- setProp(_el$5, "onSizeChange", function() {
53470
- if (disposed)
53471
- return;
53472
- const next = Math.max(0, Math.floor(this.height));
53473
- if (next !== measured())
53474
- setMeasured(next);
53475
- });
53476
- insert(_el$5, () => request().render({
53477
- id: request().id,
53478
- close: request().close,
53479
- width: () => dimensions().width,
53480
- maxHeight: capRows
53481
- }));
53482
- insert(_el$3, createComponent2(Show, {
53483
- get when() {
53484
- return memo2(() => !!overflows())() && hiddenRows() > 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;
53273
+ }
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();
53289
+ }
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;
53485
53298
  },
53486
- get children() {
53487
- var _el$6 = createElement("text");
53488
- setProp(_el$6, "wrapMode", "none");
53489
- setProp(_el$6, "paddingLeft", 1);
53490
- insert(_el$6, indicatorText);
53491
- effect((_$p) => setProp(_el$6, "fg", muted(), _$p));
53492
- return _el$6;
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();
53493
53326
  }
53494
- }), null);
53495
- effect((_p$) => {
53496
- var _v$ = background(), _v$2 = viewportRows();
53497
- _v$ !== _p$.e && (_p$.e = setProp(_el$3, "backgroundColor", _v$, _p$.e));
53498
- _v$2 !== _p$.t && (_p$.t = setProp(_el$4, "height", _v$2, _p$.t));
53499
- return _p$;
53500
53327
  }, {
53501
- e: undefined,
53502
- t: undefined
53328
+ key,
53329
+ tone: "warning"
53503
53330
  });
53504
- return _el$3;
53505
- })()
53506
- }), null);
53507
- effect((_$p) => setProp(_el$2, "visible", !dock.isOpen(), _$p));
53508
- return _el$;
53509
- })();
53331
+ } catch {
53332
+ props.controller.rejectApproval();
53333
+ }
53334
+ return;
53335
+ }
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;
53362
+ }
53363
+ closeAsk();
53364
+ });
53365
+ onCleanup(closeAsk);
53366
+ return createComponent2(Show, {
53367
+ when: false,
53368
+ children: null
53369
+ });
53510
53370
  }
53511
- var DOCK_MAX_ROWS_RATIO = 0.6, Context7, ordinal2 = 0;
53512
- var init_dock_host = __esm(() => {
53513
- init_index_bun();
53371
+ function registerTurnOverlays(seam, controller, options) {
53372
+ if (typeof seam.pendingAsks === "function") {
53373
+ const read = seam.pendingAsks.bind(seam);
53374
+ controller.attachPendingAsks(() => read() ?? []);
53375
+ }
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
+ });
53394
+ }
53395
+ seam.registerAskProvider((questions) => controller.answer(questions));
53396
+ }
53397
+ var init_turn_overlays = __esm(() => {
53514
53398
  init_index_bun();
53515
53399
  init_index_bun();
53516
53400
  init_index_bun();
@@ -53520,847 +53404,995 @@ var init_dock_host = __esm(() => {
53520
53404
  init_index_bun();
53521
53405
  init_server();
53522
53406
  init_index_bun();
53407
+ init_dialog_confirm();
53408
+ init_dialog();
53523
53409
  init_input_ownership();
53524
53410
  init_theme3();
53525
- init_terminal_size();
53526
- Context7 = createContext(undefined);
53411
+ init_i18n();
53412
+ init_motion();
53413
+ init_semantic();
53414
+ init_widgets_dock();
53415
+ init_ask_panel();
53416
+ init_ask_options();
53417
+ init_dock_host();
53527
53418
  });
53528
53419
 
53529
- // ../tui-base/src/routes/session/ask-panel.tsx
53530
- function resolveFocus(ask, list, input) {
53531
- if (ask === undefined)
53532
- return;
53533
- if (ask.phase === "input")
53534
- return input;
53535
- return list ?? input;
53536
- }
53537
- function nearestScroller(node) {
53538
- let current = node;
53539
- while (current !== null && current !== undefined) {
53540
- const candidate = current;
53541
- if (typeof candidate.scrollChildIntoView === "function")
53542
- return current;
53543
- current = current.parent;
53544
- }
53545
- return;
53546
- }
53547
- function AskPanel(props) {
53548
- const theme = useThemeOptional();
53549
- const dock = useDock();
53550
- let configCursorStyle;
53551
- try {
53552
- configCursorStyle = useCursorStyle();
53553
- } catch {
53554
- configCursorStyle = undefined;
53555
- }
53556
- const [version, setVersion] = createSignal(0);
53557
- onMount(() => {
53558
- const unsubscribe = props.controller.subscribe(() => setVersion((value) => value + 1));
53559
- onCleanup(unsubscribe);
53560
- });
53561
- const ask = () => {
53562
- version();
53563
- return props.controller.pendingAsk;
53564
- };
53565
- const questions = () => ask()?.questions ?? [];
53566
- const question = () => {
53567
- const batch = ask();
53568
- return batch?.questions[batch.index];
53569
- };
53570
- const index = () => ask()?.index ?? 0;
53571
- const phase = () => ask()?.phase ?? "questions";
53572
- const phaseOf = () => {
53573
- if (phase() === "review")
53574
- return "review";
53575
- return phase() === "input" ? "input" : "options";
53576
- };
53577
- const picks = () => {
53578
- const batch = ask();
53579
- return batch ? batch.picks[batch.index] ?? [] : [];
53580
- };
53581
- const cursor = () => {
53582
- const batch = ask();
53583
- return batch ? batch.cursors[batch.index] ?? 0 : 0;
53584
- };
53585
- const listCursor = () => {
53586
- const batch = ask();
53587
- return batch ? batch.listCursors[batch.index] ?? 0 : 0;
53588
- };
53589
- const markedRow = () => phaseOf() === "input" ? listCursor() : cursor();
53590
- const reviewCursor = () => ask()?.reviewCursor ?? 0;
53591
- const multi = () => question()?.multiSelect === true;
53592
- const compact = () => props.width() < ASK_COMPACT_COLUMNS;
53593
- const needsReview = () => askNeedsReview(questions());
53594
- const eyebrow = () => {
53595
- if (phaseOf() === "review")
53596
- return;
53597
- const current = question();
53598
- if (current?.header === undefined || current.header === current.prompt)
53599
- return;
53600
- return current.header;
53601
- };
53602
- const muted = () => theme?.text.muted ?? "#9aa5ce";
53603
- const faint = () => theme?.text.faint ?? "#565f89";
53604
- const base = () => theme?.text.base ?? "#e6e6e6";
53605
- const accent = () => theme?.hue.interactive[500] ?? "#7aa2f7";
53606
- const currentBg = () => theme?.background.action.primary.focused;
53607
- const currentFg = () => theme?.text.action.primary.focused ?? accent();
53608
- const rule = () => theme?.border.base ?? "#565f89";
53609
- const cursorShape = () => {
53610
- try {
53611
- return configCursorStyle?.()?.style;
53612
- } catch {
53613
- return;
53614
- }
53615
- };
53616
- let listEl;
53617
- let inputEl;
53618
- let inlineRowEl;
53619
- useAskKeys({
53620
- controller: props.controller,
53621
- input: () => inputEl
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"
53622
53429
  });
53623
- const queuedCount = () => {
53624
- version();
53625
- return props.queued?.() ?? dock.queueDepth();
53626
- };
53627
- props.onFocusTarget?.(() => resolveFocus(ask(), listEl, inputEl));
53628
- function revealRow(row) {
53629
- if (row === undefined || row.isDestroyed)
53630
- return;
53631
- const scroller = nearestScroller(row);
53632
- if (scroller === undefined)
53633
- return;
53634
- scroller.scrollChildIntoView(row, {
53635
- align: "nearest"
53636
- });
53637
- }
53638
- function focusInputRow() {
53639
- const input = inputEl;
53640
- if (input === undefined || input.isDestroyed)
53641
- return;
53642
- input.focus();
53643
- revealRow(inlineRowEl);
53644
- }
53645
- createEffect(on(() => phase(), (next) => {
53646
- if (next === "input") {
53647
- focusInputRow();
53648
- return;
53649
- }
53650
- if (next !== "questions")
53651
- return;
53652
- const focusList = () => {
53653
- if (listEl !== undefined && !listEl.isDestroyed)
53654
- listEl.focus();
53655
- };
53656
- if (listEl !== undefined && !listEl.isDestroyed)
53657
- focusList();
53658
- else
53659
- queueMicrotask(focusList);
53660
- }));
53661
- createEffect(on(() => index(), () => phase() === "input" ? focusInputRow() : undefined, {
53662
- defer: true
53663
- }));
53664
- createEffect(on([() => index(), cursor], () => {
53665
- if (phaseOf() !== "options")
53666
- return;
53667
- revealRow(listEl?.getChildren()[cursor()]);
53668
- }));
53669
- const optionRows = () => (question()?.options ?? []).map((option, position) => ({
53670
- option,
53671
- number: position + 1,
53672
- selected: picks().includes(option.label)
53673
- }));
53674
- const labelColumn = (row) => GUTTER + CURSOR_CELLS + STATE_CELLS + `${row.number}. `.length;
53675
- const footerHint = () => {
53676
- if (phaseOf() === "review")
53677
- return t("overlay.ask.footer.review", {
53678
- esc: t("overlay.ask.esc.review")
53679
- });
53680
- if (phaseOf() === "input") {
53681
- const escKey = question()?.options.length === 0 ? index() > 0 ? "overlay.ask.esc.prevQuestion" : "overlay.ask.esc.decline" : "overlay.ask.esc.back";
53682
- return t("overlay.ask.footer.input", {
53683
- esc: t(escKey)
53684
- });
53685
- }
53686
- const escKey = questions().length > 1 && index() > 0 ? "overlay.ask.esc.prevQuestion" : "overlay.ask.esc.decline";
53687
- return t(multi() ? "overlay.ask.footer.multi" : "overlay.ask.footer.options", {
53688
- esc: t(escKey)
53689
- });
53430
+ const choose = (key) => {
53431
+ if (key === "confirm")
53432
+ props.onConfirm?.();
53433
+ if (key === "cancel")
53434
+ props.onCancel?.();
53435
+ dialog.clear();
53690
53436
  };
53691
- const answerText = (qi) => {
53692
- const batch = ask();
53693
- if (!batch)
53694
- return "";
53695
- const custom = batch.customs[qi];
53696
- if (custom !== undefined && custom !== "")
53697
- return custom;
53698
- return (batch.picks[qi] ?? []).map((label) => splitRecommended(label).label).join(", ");
53437
+ const chooseExtra = (action) => {
53438
+ action.onTrigger();
53439
+ dialog.clear();
53699
53440
  };
53700
- const reviewRowActive = (qi) => reviewCursor() === qi;
53701
- const reviewSubmitActive = () => reviewRowIntent(reviewCursor(), questions().length).kind === "submit";
53702
- return (() => {
53703
- 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");
53704
- insertNode(_el$, _el$2);
53705
- insertNode(_el$, _el$3);
53706
- insertNode(_el$, _el$1);
53707
- insertNode(_el$, _el$12);
53708
- setProp(_el$, "flexDirection", "column");
53709
- setProp(_el$, "width", "100%");
53710
- setProp(_el$, "flexShrink", 0);
53711
- setProp(_el$2, "width", "100%");
53712
- setProp(_el$2, "flexShrink", 0);
53713
- setProp(_el$2, "border", ["top"]);
53714
- setProp(_el$2, "borderStyle", "single");
53715
- insert(_el$, createComponent2(Show, {
53716
- get when() {
53717
- return eyebrow();
53718
- },
53719
- children: (header) => (() => {
53720
- var _el$13 = createElement("box"), _el$14 = createElement("text");
53721
- insertNode(_el$13, _el$14);
53722
- setProp(_el$13, "paddingLeft", 2);
53723
- setProp(_el$13, "paddingRight", 2);
53724
- setProp(_el$14, "wrapMode", "none");
53725
- insert(_el$14, header);
53726
- effect((_$p) => setProp(_el$14, "fg", muted(), _$p));
53727
- return _el$13;
53728
- })()
53729
- }), _el$3);
53730
- insertNode(_el$3, _el$4);
53731
- setProp(_el$3, "paddingLeft", 2);
53732
- setProp(_el$3, "paddingRight", 2);
53733
- setProp(_el$4, "wrapMode", "word");
53734
- insert(_el$4, (() => {
53735
- var _c$ = memo2(() => phaseOf() === "review");
53736
- return () => _c$() ? t("overlay.ask.reviewTitle") : question()?.prompt ?? "";
53737
- })());
53738
- insert(_el$, createComponent2(Show, {
53739
- get when() {
53740
- return questions().length >= 2;
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)
53741
53459
  },
53742
- get children() {
53743
- var _el$5 = createElement("box"), _el$6 = createElement("text");
53744
- insertNode(_el$5, _el$6);
53745
- setProp(_el$5, "paddingLeft", 2);
53746
- setProp(_el$5, "paddingRight", 2);
53747
- setProp(_el$6, "wrapMode", "none");
53748
- insert(_el$6, () => askTabStrip(questions(), ask()?.picks ?? [], index(), ask()?.customs));
53749
- effect((_$p) => setProp(_el$6, "fg", muted(), _$p));
53750
- return _el$5;
53751
- }
53752
- }), _el$1);
53753
- insert(_el$, createComponent2(Show, {
53754
- get when() {
53755
- return memo2(() => phaseOf() !== "review")() ? question()?.detail : undefined;
53460
+ {
53461
+ bind: "left",
53462
+ title: "Previous dialog option",
53463
+ group: "Dialog",
53464
+ run: () => {
53465
+ setStore("active", store.active === "confirm" ? "cancel" : "confirm");
53466
+ }
53756
53467
  },
53757
- children: (detail) => (() => {
53758
- var _el$15 = createElement("box"), _el$16 = createElement("text");
53759
- insertNode(_el$15, _el$16);
53760
- setProp(_el$15, "paddingLeft", 2);
53761
- setProp(_el$15, "paddingRight", 2);
53762
- setProp(_el$16, "wrapMode", "word");
53763
- insert(_el$16, detail);
53764
- effect((_$p) => setProp(_el$16, "fg", muted(), _$p));
53765
- return _el$15;
53766
- })()
53767
- }), _el$1);
53768
- insert(_el$, createComponent2(Show, {
53769
- get when() {
53770
- return phaseOf() === "review";
53468
+ {
53469
+ bind: "right",
53470
+ title: "Next dialog option",
53471
+ group: "Dialog",
53472
+ run: () => {
53473
+ setStore("active", store.active === "confirm" ? "cancel" : "confirm");
53474
+ }
53771
53475
  },
53772
- get fallback() {
53773
- return [(() => {
53774
- var _el$17 = createElement("box");
53775
- use((value) => {
53776
- listEl = value;
53777
- }, _el$17);
53778
- setProp(_el$17, "flexDirection", "column");
53779
- setProp(_el$17, "width", "100%");
53780
- setProp(_el$17, "flexShrink", 0);
53781
- setProp(_el$17, "focusable", true);
53782
- insert(_el$17, createComponent2(Index, {
53783
- get each() {
53784
- return optionRows();
53785
- },
53786
- children: (row, position) => createComponent2(OptionRow, {
53787
- row,
53788
- cursor: () => phaseOf() !== "input" && position === cursor(),
53789
- marked: () => position === markedRow(),
53790
- multi: () => multi(),
53791
- compact: () => compact(),
53792
- width: () => props.width(),
53793
- labelColumn: () => labelColumn(row())
53794
- })
53795
- }), null);
53796
- insert(_el$17, createComponent2(Show, {
53797
- get when() {
53798
- return memo2(() => question() !== undefined)() && hasReviewRow(question(), needsReview());
53799
- },
53800
- get children() {
53801
- var _el$18 = createElement("box"), _el$19 = createElement("text"), _el$20 = createElement("text");
53802
- insertNode(_el$18, _el$19);
53803
- insertNode(_el$18, _el$20);
53804
- setProp(_el$18, "flexDirection", "row");
53805
- setProp(_el$18, "width", "100%");
53806
- setProp(_el$18, "flexShrink", 0);
53807
- setProp(_el$18, "paddingLeft", 2);
53808
- insert(_el$19, () => markedRow() === (question()?.options.length ?? 0) ? "\u203A " : " ");
53809
- setProp(_el$20, "wrapMode", "word");
53810
- insert(_el$20, () => t("overlay.ask.reviewRow"));
53811
- effect((_p$) => {
53812
- 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();
53813
- _v$8 !== _p$.e && (_p$.e = setProp(_el$18, "backgroundColor", _v$8, _p$.e));
53814
- _v$9 !== _p$.t && (_p$.t = setProp(_el$19, "fg", _v$9, _p$.t));
53815
- _v$0 !== _p$.a && (_p$.a = setProp(_el$20, "fg", _v$0, _p$.a));
53816
- return _p$;
53817
- }, {
53818
- e: undefined,
53819
- t: undefined,
53820
- a: undefined
53821
- });
53822
- return _el$18;
53823
- }
53824
- }), null);
53825
- return _el$17;
53826
- })(), (() => {
53827
- var _el$21 = createElement("box"), _el$22 = createElement("text"), _el$24 = createElement("input");
53828
- insertNode(_el$21, _el$22);
53829
- insertNode(_el$21, _el$24);
53830
- use((value) => {
53831
- inlineRowEl = value;
53832
- }, _el$21);
53833
- setProp(_el$21, "flexDirection", "row");
53834
- setProp(_el$21, "width", "100%");
53835
- setProp(_el$21, "flexShrink", 0);
53836
- setProp(_el$21, "paddingLeft", 2);
53837
- insertNode(_el$22, createTextNode(`\u270E `));
53838
- use((value) => {
53839
- inputEl = value;
53840
- }, _el$24);
53841
- setProp(_el$24, "flexGrow", 1);
53842
- setProp(_el$24, "onInput", (value) => props.controller.setInlineText(value));
53843
- setProp(_el$24, "onSubmit", () => props.controller.commitCustom());
53844
- effect((_p$) => {
53845
- 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();
53846
- _v$1 !== _p$.e && (_p$.e = setProp(_el$21, "backgroundColor", _v$1, _p$.e));
53847
- _v$10 !== _p$.t && (_p$.t = setProp(_el$22, "fg", _v$10, _p$.t));
53848
- _v$11 !== _p$.a && (_p$.a = setProp(_el$24, "value", _v$11, _p$.a));
53849
- _v$12 !== _p$.o && (_p$.o = setProp(_el$24, "placeholder", _v$12, _p$.o));
53850
- _v$13 !== _p$.i && (_p$.i = setProp(_el$24, "placeholderColor", _v$13, _p$.i));
53851
- _v$14 !== _p$.n && (_p$.n = setProp(_el$24, "textColor", _v$14, _p$.n));
53852
- _v$15 !== _p$.s && (_p$.s = setProp(_el$24, "focusedTextColor", _v$15, _p$.s));
53853
- _v$16 !== _p$.h && (_p$.h = setProp(_el$24, "cursorColor", _v$16, _p$.h));
53854
- _v$17 !== _p$.r && (_p$.r = setProp(_el$24, "cursorStyle", _v$17, _p$.r));
53855
- return _p$;
53856
- }, {
53857
- e: undefined,
53858
- t: undefined,
53859
- a: undefined,
53860
- o: undefined,
53861
- i: undefined,
53862
- n: undefined,
53863
- s: undefined,
53864
- h: undefined,
53865
- r: undefined
53866
- });
53867
- return _el$21;
53868
- })()];
53476
+ {
53477
+ bind: "tab",
53478
+ title: "Next dialog option",
53479
+ group: "Dialog",
53480
+ run: () => {
53481
+ setStore("active", store.active === "confirm" ? "cancel" : "confirm");
53482
+ }
53869
53483
  },
53870
- get children() {
53871
- var _el$7 = createElement("box"), _el$8 = createElement("box"), _el$9 = createElement("text"), _el$0 = createElement("text");
53872
- insertNode(_el$7, _el$8);
53873
- setProp(_el$7, "flexDirection", "column");
53874
- setProp(_el$7, "width", "100%");
53875
- setProp(_el$7, "flexShrink", 0);
53876
- insert(_el$7, createComponent2(Index, {
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, {
53877
53560
  get each() {
53878
- return questions();
53561
+ return props.extraActions ?? [];
53879
53562
  },
53880
- children: (item, qi) => (() => {
53881
- 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");
53882
- insertNode(_el$25, _el$26);
53883
- insertNode(_el$25, _el$31);
53884
- setProp(_el$25, "flexDirection", "column");
53885
- setProp(_el$25, "width", "100%");
53886
- setProp(_el$25, "flexShrink", 0);
53887
- insertNode(_el$26, _el$27);
53888
- insertNode(_el$26, _el$28);
53889
- insertNode(_el$26, _el$30);
53890
- setProp(_el$26, "flexDirection", "row");
53891
- setProp(_el$26, "width", "100%");
53892
- setProp(_el$26, "flexShrink", 0);
53893
- setProp(_el$26, "paddingLeft", 2);
53894
- insert(_el$27, () => reviewRowActive(qi) ? "\u203A " : " ");
53895
- insertNode(_el$28, createTextNode(`\u2713 `));
53896
- setProp(_el$30, "wrapMode", "word");
53897
- insert(_el$30, () => item().prompt);
53898
- insertNode(_el$31, _el$32);
53899
- setProp(_el$31, "paddingLeft", 6);
53900
- setProp(_el$32, "wrapMode", "word");
53901
- insert(_el$32, () => `\u2192 ${answerText(qi) !== "" ? answerText(qi) : t("overlay.ask.unanswered")}`);
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));
53902
53584
  effect((_p$) => {
53903
- 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();
53904
- _v$18 !== _p$.e && (_p$.e = setProp(_el$26, "backgroundColor", _v$18, _p$.e));
53905
- _v$19 !== _p$.t && (_p$.t = setProp(_el$27, "fg", _v$19, _p$.t));
53906
- _v$20 !== _p$.a && (_p$.a = setProp(_el$28, "fg", _v$20, _p$.a));
53907
- _v$21 !== _p$.o && (_p$.o = setProp(_el$30, "fg", _v$21, _p$.o));
53908
- _v$22 !== _p$.i && (_p$.i = setProp(_el$32, "fg", _v$22, _p$.i));
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));
53909
53588
  return _p$;
53910
53589
  }, {
53911
53590
  e: undefined,
53912
- t: undefined,
53913
- a: undefined,
53914
- o: undefined,
53915
- i: undefined
53591
+ t: undefined
53916
53592
  });
53917
- return _el$25;
53593
+ return _el$9;
53918
53594
  })()
53919
- }), _el$8);
53920
- insertNode(_el$8, _el$9);
53921
- insertNode(_el$8, _el$0);
53922
- setProp(_el$8, "flexDirection", "row");
53923
- setProp(_el$8, "width", "100%");
53924
- setProp(_el$8, "flexShrink", 0);
53925
- setProp(_el$8, "paddingLeft", 2);
53926
- insert(_el$9, () => reviewSubmitActive() ? "\u203A " : " ");
53927
- setProp(_el$0, "wrapMode", "none");
53928
- insert(_el$0, () => t("overlay.ask.submitRow"));
53929
- effect((_p$) => {
53930
- var _v$ = reviewSubmitActive() ? currentBg() : undefined, _v$2 = reviewSubmitActive() ? currentFg() : accent(), _v$3 = reviewSubmitActive() ? currentFg() : base();
53931
- _v$ !== _p$.e && (_p$.e = setProp(_el$8, "backgroundColor", _v$, _p$.e));
53932
- _v$2 !== _p$.t && (_p$.t = setProp(_el$9, "fg", _v$2, _p$.t));
53933
- _v$3 !== _p$.a && (_p$.a = setProp(_el$0, "fg", _v$3, _p$.a));
53934
- return _p$;
53935
- }, {
53936
- e: undefined,
53937
- t: undefined,
53938
- a: undefined
53939
- });
53940
- return _el$7;
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
+ });
53606
+ }
53607
+ var init_dialog_confirm = __esm(() => {
53608
+ init_index_bun();
53609
+ init_index_bun();
53610
+ init_index_bun();
53611
+ init_index_bun();
53612
+ init_index_bun();
53613
+ init_index_bun();
53614
+ init_index_bun();
53615
+ init_keymap();
53616
+ init_theme3();
53617
+ init_config();
53618
+ init_dialog();
53619
+ init_server2();
53620
+ init_server();
53621
+ init_locale();
53622
+ init_semantic();
53623
+ init_turn_overlays();
53624
+ });
53625
+
53626
+ // ../tui-base/src/routes/session/turn-cancel.tsx
53627
+ function armNonArmingInterrupt() {
53628
+ nonArmingInterrupt = true;
53629
+ }
53630
+ function consumeNonArmingInterrupt() {
53631
+ const armed = nonArmingInterrupt;
53632
+ nonArmingInterrupt = false;
53633
+ return armed;
53634
+ }
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);
53649
+ };
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);
53660
+ };
53661
+ return {
53662
+ escape() {
53663
+ if (!props.busy() || props.escapeYields?.())
53664
+ return false;
53665
+ if (!props.confirmStop) {
53666
+ props.interrupt();
53667
+ return true;
53941
53668
  }
53942
- }), _el$1);
53943
- insertNode(_el$1, _el$10);
53944
- setProp(_el$1, "flexDirection", "row");
53945
- setProp(_el$1, "width", "100%");
53946
- setProp(_el$1, "justifyContent", "space-between");
53947
- setProp(_el$1, "paddingLeft", 2);
53948
- setProp(_el$1, "paddingRight", 2);
53949
- setProp(_el$10, "wrapMode", "none");
53950
- insert(_el$10, footerHint);
53951
- insert(_el$1, createComponent2(Show, {
53952
- get when() {
53953
- return queuedCount() > 0;
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
53701
+ };
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
+ });
53727
+ };
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$;
53759
+ }
53760
+ });
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 === "")
53837
+ return;
53838
+ if (this.#approvals.some((entry) => entry.request.invalidatedReason !== undefined && entry.request.eventId === eventId))
53839
+ return;
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
53954
53860
  },
53955
- get children() {
53956
- var _el$11 = createElement("text");
53957
- setProp(_el$11, "wrapMode", "none");
53958
- insert(_el$11, () => t("overlay.ask.queued", {
53959
- count: queuedCount()
53960
- }));
53961
- effect((_$p) => setProp(_el$11, "fg", muted(), _$p));
53962
- return _el$11;
53861
+ resolve: () => {}
53862
+ });
53863
+ this.#changed();
53864
+ }
53865
+ invalidateAll(reason) {
53866
+ if (reason === "")
53867
+ return;
53868
+ const open = this.#approvals.length + this.#asks.length;
53869
+ if (open === 0)
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
+ });
53884
+ }
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: () => {}
53896
+ });
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);
53963
53911
  }
53964
- }), null);
53965
- setProp(_el$12, "width", "100%");
53966
- setProp(_el$12, "flexShrink", 0);
53967
- setProp(_el$12, "border", ["bottom"]);
53968
- setProp(_el$12, "borderStyle", "single");
53969
- effect((_p$) => {
53970
- var _v$4 = rule(), _v$5 = warningColor(theme), _v$6 = muted(), _v$7 = rule();
53971
- _v$4 !== _p$.e && (_p$.e = setProp(_el$2, "borderColor", _v$4, _p$.e));
53972
- _v$5 !== _p$.t && (_p$.t = setProp(_el$4, "fg", _v$5, _p$.t));
53973
- _v$6 !== _p$.a && (_p$.a = setProp(_el$10, "fg", _v$6, _p$.a));
53974
- _v$7 !== _p$.o && (_p$.o = setProp(_el$12, "borderColor", _v$7, _p$.o));
53975
- return _p$;
53976
- }, {
53977
- e: undefined,
53978
- t: undefined,
53979
- a: undefined,
53980
- o: undefined
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
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;
53962
+ }
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;
53981
54004
  });
53982
- return _el$;
53983
- })();
53984
- }
53985
- function OptionRow(props) {
53986
- const theme = useThemeOptional();
53987
- const muted = () => theme?.text.muted ?? "#9aa5ce";
53988
- const faint = () => theme?.text.faint ?? "#565f89";
53989
- const base = () => theme?.text.base ?? "#e6e6e6";
53990
- const accent = () => theme?.hue.interactive[500] ?? "#7aa2f7";
53991
- const success = () => theme?.text.feedback.success.base ?? "#9ece6a";
53992
- const currentBg = () => theme?.background.action.primary.focused;
53993
- const currentFg = () => theme?.text.action.primary.focused ?? accent();
53994
- const label = () => splitRecommended(props.row().option.label);
53995
- const number = () => `${props.row().number}. `;
53996
- const badge = () => `[${t("overlay.ask.recommended")}]`;
53997
- const stateGlyph = () => {
53998
- if (props.multi())
53999
- return props.row().selected ? "\u25A0 " : "\u25A1 ";
54000
- return props.row().selected ? "\u25CF " : "\u25CB ";
54001
- };
54002
- const stateColor = () => {
54003
- if (props.cursor())
54004
- return currentFg();
54005
- return props.row().selected ? success() : faint();
54006
- };
54007
- const badgeInline = () => {
54008
- 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([]);
54009
54012
  return false;
54010
- const used = props.labelColumn() + stringWidth(label().label) + BADGE_GAP + stringWidth(badge());
54011
- return used <= props.width();
54012
- };
54013
- const labelColor = () => props.cursor() ? currentFg() : base();
54014
- return (() => {
54015
- 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");
54016
- insertNode(_el$33, _el$34);
54017
- setProp(_el$33, "flexDirection", "column");
54018
- setProp(_el$33, "width", "100%");
54019
- setProp(_el$33, "flexShrink", 0);
54020
- insertNode(_el$34, _el$35);
54021
- insertNode(_el$34, _el$36);
54022
- insertNode(_el$34, _el$37);
54023
- insertNode(_el$34, _el$38);
54024
- setProp(_el$34, "flexDirection", "row");
54025
- setProp(_el$34, "width", "100%");
54026
- setProp(_el$34, "flexShrink", 0);
54027
- setProp(_el$34, "paddingLeft", 2);
54028
- insert(_el$35, () => props.marked() ? "\u203A " : " ");
54029
- insert(_el$36, stateGlyph);
54030
- insert(_el$37, number);
54031
- setProp(_el$38, "wrapMode", "word");
54032
- insert(_el$38, () => label().label);
54033
- insert(_el$34, createComponent2(Show, {
54034
- get when() {
54035
- return badgeInline();
54036
- },
54037
- get children() {
54038
- var _el$39 = createElement("text");
54039
- insert(_el$39, () => ` ${badge()}`);
54040
- effect((_$p) => setProp(_el$39, "fg", props.cursor() ? currentFg() : success(), _$p));
54041
- return _el$39;
54042
- }
54043
- }), null);
54044
- insert(_el$33, createComponent2(Show, {
54045
- get when() {
54046
- return memo2(() => !!label().recommended)() && !badgeInline();
54047
- },
54048
- get children() {
54049
- var _el$40 = createElement("box"), _el$41 = createElement("text");
54050
- insertNode(_el$40, _el$41);
54051
- setProp(_el$41, "wrapMode", "none");
54052
- insert(_el$41, badge);
54053
- effect((_p$) => {
54054
- var _v$23 = props.labelColumn(), _v$24 = success();
54055
- _v$23 !== _p$.e && (_p$.e = setProp(_el$40, "paddingLeft", _v$23, _p$.e));
54056
- _v$24 !== _p$.t && (_p$.t = setProp(_el$41, "fg", _v$24, _p$.t));
54057
- return _p$;
54058
- }, {
54059
- e: undefined,
54060
- t: undefined
54061
- });
54062
- return _el$40;
54063
- }
54064
- }), null);
54065
- insert(_el$33, createComponent2(Show, {
54066
- get when() {
54067
- return props.row().option.description;
54068
- },
54069
- children: (description) => (() => {
54070
- var _el$42 = createElement("box"), _el$43 = createElement("text");
54071
- insertNode(_el$42, _el$43);
54072
- setProp(_el$43, "wrapMode", "word");
54073
- insert(_el$43, description);
54074
- effect((_p$) => {
54075
- var _v$31 = props.labelColumn(), _v$32 = muted();
54076
- _v$31 !== _p$.e && (_p$.e = setProp(_el$42, "paddingLeft", _v$31, _p$.e));
54077
- _v$32 !== _p$.t && (_p$.t = setProp(_el$43, "fg", _v$32, _p$.t));
54078
- return _p$;
54079
- }, {
54080
- e: undefined,
54081
- t: undefined
54082
- });
54083
- return _el$42;
54084
- })()
54085
- }), null);
54086
- effect((_p$) => {
54087
- 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;
54088
- _v$25 !== _p$.e && (_p$.e = setProp(_el$34, "backgroundColor", _v$25, _p$.e));
54089
- _v$26 !== _p$.t && (_p$.t = setProp(_el$35, "fg", _v$26, _p$.t));
54090
- _v$27 !== _p$.a && (_p$.a = setProp(_el$36, "fg", _v$27, _p$.a));
54091
- _v$28 !== _p$.o && (_p$.o = setProp(_el$37, "fg", _v$28, _p$.o));
54092
- _v$29 !== _p$.i && (_p$.i = setProp(_el$38, "fg", _v$29, _p$.i));
54093
- _v$30 !== _p$.n && (_p$.n = setProp(_el$38, "flexGrow", _v$30, _p$.n));
54094
- return _p$;
54095
- }, {
54096
- e: undefined,
54097
- t: undefined,
54098
- a: undefined,
54099
- o: undefined,
54100
- i: undefined,
54101
- n: undefined
54102
54013
  });
54103
- return _el$33;
54104
- })();
54105
- }
54106
- var ASK_COMPACT_COLUMNS = 64, GUTTER = 2, CURSOR_CELLS = 2, STATE_CELLS = 2, BADGE_GAP = 2;
54107
- var init_ask_panel = __esm(() => {
54108
- init_index_bun();
54109
- init_index_bun();
54110
- init_index_bun();
54111
- init_index_bun();
54112
- init_index_bun();
54113
- init_index_bun();
54114
- init_index_bun();
54115
- init_index_bun();
54116
- init_index_bun();
54117
- init_server();
54118
- init_i18n();
54119
- init_theme3();
54120
- init_config();
54121
- init_semantic();
54122
- init_ask_options();
54123
- init_ask_keys();
54124
- init_dock_host();
54125
- init_string_width();
54126
- });
54127
-
54128
- // ../tui-base/src/routes/session/turn-overlays.tsx
54129
- function summarizeArgs(name, args, limit = 160) {
54130
- let body = JSON.stringify(args);
54131
- if (body === undefined)
54132
- body = "";
54133
- body = body.trim();
54134
- if (body.length > limit)
54135
- body = body.slice(0, limit - 1) + "\u2026";
54136
- return `${name} ${body}`.trim();
54137
- }
54138
- function ApprovalCard(props) {
54139
- const invalidated = () => props.invalidatedReason !== undefined;
54140
- return createComponent2(DialogConfirm, {
54141
- get title() {
54142
- return memo2(() => !!invalidated())() ? t("overlay.ask.invalidatedTitle") : t("overlay.ask.approvalTitle", {
54143
- 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
54144
54101
  });
54145
- },
54146
- get message() {
54147
- return memo2(() => !!invalidated())() ? t("overlay.ask.invalidated", {
54148
- reason: props.invalidatedReason ?? ""
54149
- }) : summarizeArgs(props.name, props.args);
54150
- },
54151
- get label() {
54152
- return memo2(() => !!invalidated())() ? {
54153
- confirm: t("overlay.ask.invalidatedAck"),
54154
- cancel: t("overlay.ask.invalidatedAck")
54155
- } : {
54156
- confirm: t("overlay.ask.allow"),
54157
- cancel: t("overlay.ask.reject")
54158
- };
54159
- },
54160
- onConfirm: () => props.onVerdict("allowed-once"),
54161
- onCancel: () => props.onVerdict("rejected"),
54162
- get extraActions() {
54163
- return memo2(() => !!(!invalidated() && props.escalation === true))() ? [{
54164
- label: t("overlay.ask.allowAlways"),
54165
- bind: "a",
54166
- onTrigger: () => props.onVerdict("always")
54167
- }, {
54168
- label: t("overlay.ask.allowSession"),
54169
- bind: "s",
54170
- onTrigger: () => props.onVerdict("session")
54171
- }] : 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;
54172
54119
  }
54173
- });
54174
- }
54175
- function ReminderBadge() {
54176
- const theme = useThemeOptional();
54177
- const [tick, setTick] = createSignal(0);
54178
- const startedAt = Date.now();
54179
- const pulsing = () => motionDecorationsEnabled() && Date.now() - startedAt < SKIN_PULSE_MS;
54180
- onAnimationTick(() => pulsing() && motionAnimationRunning() ? motionFrameRate() : undefined, () => setTick((t) => t + 1));
54181
- const fg = () => {
54182
- tick();
54183
- const target = warningColor(theme);
54184
- if (!motionDecorationsEnabled())
54185
- return target;
54186
- const bright = skinPulseBrightness(Date.now() - startedAt);
54187
- return bright >= 1 ? target : mixSkinColor(target, theme?.background.base ?? "#000000", 1 - bright);
54188
- };
54189
- return (() => {
54190
- var _el$ = createElement("text");
54191
- insertNode(_el$, createTextNode(`\u26A0 `));
54192
- setProp(_el$, "flexShrink", 0);
54193
- effect((_$p) => setProp(_el$, "fg", fg(), _$p));
54194
- return _el$;
54195
- })();
54196
- }
54197
- function TurnOverlayHost(props) {
54198
- const dialog = useDialog();
54199
- const dock = useDock();
54200
- const pageOwns = useIsPageOwner();
54201
- const [version, setVersion] = createSignal(0);
54202
- onMount(() => {
54203
- const unsubscribe = props.controller.subscribe(() => setVersion((value) => value + 1));
54204
- onCleanup(unsubscribe);
54205
- const timer = setInterval(() => props.controller.syncPendingAsks(), 200);
54206
- onCleanup(() => clearInterval(timer));
54207
- });
54208
- props.controller.onIdle(() => {
54209
- setTimeout(() => props.reclaimFocus?.(), 3);
54210
- });
54211
- let panelFocus;
54212
- let askHandle;
54213
- let askId;
54214
- let shown;
54215
- function closeAsk() {
54216
- askHandle?.close();
54217
- askHandle = undefined;
54218
- askId = undefined;
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;
54126
+ }
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();
54143
+ }
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();
54219
54274
  }
54220
- createEffect(() => {
54221
- version();
54222
- const approval = props.controller.pendingApproval;
54223
- const ask = props.controller.pendingAsk;
54224
- const askShowing = askHandle !== undefined && ask !== undefined && askId === ask.id;
54225
- const pageOwned = pageOwns();
54226
- const approvalWins = approval !== undefined && !askShowing;
54227
- const askAdmitted = ask !== undefined && (askShowing || pageOwned);
54228
- const key = approvalWins ? `approval:${approval.id}` : askAdmitted ? `ask:${ask.id}` : "";
54229
- if (key === shown)
54275
+ focusOptions() {
54276
+ const head = this.#asks[0];
54277
+ if (!head || head.phase !== "input")
54230
54278
  return;
54231
- const previousKey = shown;
54232
- shown = key;
54233
- if (previousKey?.startsWith("approval:") === true && dialog.stack.at(-1)?.key === previousKey) {
54234
- dialog.clear();
54235
- }
54236
- if (approvalWins) {
54237
- closeAsk();
54238
- const atOpen = key;
54239
- const approvalId = approval.id;
54240
- try {
54241
- dialog.replace(() => createComponent2(ApprovalCard, {
54242
- get name() {
54243
- return approval.name;
54244
- },
54245
- get args() {
54246
- return approval.args;
54247
- },
54248
- get escalation() {
54249
- return approval.escalation;
54250
- },
54251
- get invalidatedReason() {
54252
- return approval.invalidatedReason;
54253
- },
54254
- onVerdict: (verdict) => {
54255
- switch (verdict) {
54256
- case "allowed-once":
54257
- props.controller.confirmApproval();
54258
- break;
54259
- case "always":
54260
- props.controller.approveAlways();
54261
- break;
54262
- case "session":
54263
- props.controller.approveSession();
54264
- break;
54265
- default:
54266
- props.controller.rejectApproval();
54267
- }
54268
- }
54269
- }), () => {
54270
- if (shown === atOpen && props.controller.pendingApproval?.id === approvalId) {
54271
- props.controller.rejectApproval();
54272
- }
54273
- }, {
54274
- key,
54275
- tone: "warning"
54276
- });
54277
- } catch {
54278
- props.controller.rejectApproval();
54279
- }
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")
54280
54286
  return;
54281
- }
54282
- if (ask !== undefined && askAdmitted) {
54283
- if (askHandle !== undefined && askId === ask.id)
54284
- return;
54285
- const previous = askHandle;
54286
- askId = ask.id;
54287
- askHandle = dock.open((ctx) => createComponent2(AskPanel, {
54288
- get controller() {
54289
- return props.controller;
54290
- },
54291
- get width() {
54292
- return ctx.width;
54293
- },
54294
- queued: () => Math.max(0, props.controller.pendingAskCount + props.controller.pendingApprovalCount - 1),
54295
- onFocusTarget: (resolve) => {
54296
- panelFocus = resolve;
54297
- }
54298
- }), {
54299
- kind: "ask",
54300
- contentRows: estimateAskRows(ask),
54301
- focusRef: () => panelFocus?.(),
54302
- overflowLabel: (hidden) => t("overlay.ask.overflow", {
54303
- count: hidden
54304
- })
54305
- });
54306
- previous?.close();
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";
54307
54330
  return;
54308
54331
  }
54309
- closeAsk();
54310
- });
54311
- onCleanup(closeAsk);
54312
- return createComponent2(Show, {
54313
- when: false,
54314
- children: null
54315
- });
54316
- }
54317
- function registerTurnOverlays(seam, controller, options) {
54318
- if (typeof seam.pendingAsks === "function") {
54319
- const read = seam.pendingAsks.bind(seam);
54320
- controller.attachPendingAsks(() => read() ?? []);
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;
54321
54337
  }
54322
- if (typeof seam.onSessionEvent === "function") {
54323
- seam.onSessionEvent((event) => {
54324
- if (event.type === "bridge.dead") {
54325
- const configured = options?.deadReason;
54326
- if (configured === undefined)
54327
- return;
54328
- const reason = typeof configured === "function" ? configured(event.details) : configured;
54329
- if (reason !== "")
54330
- controller.invalidateAll(reason);
54331
- return;
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")
54352
+ return;
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)
54364
+ return;
54365
+ this.#asks.shift();
54366
+ head.resolve(this.#envelope(head));
54367
+ this.#changed();
54368
+ }
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 };
54332
54377
  }
54333
- if (event.type !== "bridge.ask.invalidated")
54334
- return;
54335
- const details = event.details;
54336
- if (typeof details?.eventId !== "string")
54337
- return;
54338
- 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
+ };
54339
54384
  });
54340
54385
  }
54341
- 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
+ }
54342
54393
  }
54343
- var init_turn_overlays = __esm(() => {
54344
- init_index_bun();
54345
- init_index_bun();
54346
- init_index_bun();
54347
- init_index_bun();
54348
- init_index_bun();
54349
- init_index_bun();
54350
- init_index_bun();
54351
- init_server();
54352
- init_index_bun();
54353
- init_dialog_confirm();
54354
- init_dialog();
54355
- init_input_ownership();
54356
- init_theme3();
54357
- init_i18n();
54358
- init_motion();
54359
- init_semantic();
54360
- init_widgets_dock();
54361
- init_ask_panel();
54394
+ var init_turn_overlay_controller = __esm(() => {
54362
54395
  init_ask_options();
54363
- init_dock_host();
54364
54396
  });
54365
54397
 
54366
54398
  // ../tui-base/src/routes/session/hotkeys.ts
@@ -54758,12 +54790,19 @@ function coreCommands() {
54758
54790
  ctx.refreshFooter?.();
54759
54791
  return;
54760
54792
  }
54761
- 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
+ }
54762
54802
  if (catalog.length === 0) {
54763
54803
  ctx.say(t("command.model.emptyCatalog"));
54764
54804
  return;
54765
54805
  }
54766
- const current = await ctx.seam.currentModelSelection();
54767
54806
  const prefs = readModelPrefsFromConfig(ctx.seam.configLoad?.());
54768
54807
  let favorites = prefs.favoriteModels;
54769
54808
  let hidden = prefs.hiddenModels;
@@ -63665,7 +63704,7 @@ var init_subagents_viewer = __esm(() => {
63665
63704
  import { TextAttributes as TextAttributes12 } from "@opentui/core";
63666
63705
  function resolveVersion() {
63667
63706
  try {
63668
- return "0.23.1";
63707
+ return "0.23.2";
63669
63708
  } catch {
63670
63709
  return "dev";
63671
63710
  }
@@ -68550,7 +68589,6 @@ function V2SessionPageBody(props) {
68550
68589
  };
68551
68590
  const reloadSession = (sessionId) => {
68552
68591
  setLastRequest(undefined);
68553
- setSessionIdFromRecovery(undefined);
68554
68592
  composerRef?.resetDeliveries();
68555
68593
  setComposerPending([]);
68556
68594
  setTools(0);
@@ -69653,5 +69691,5 @@ export {
69653
69691
  themeNameFromConfig
69654
69692
  };
69655
69693
 
69656
- //# debugId=E9FE1903EEBDE04F64756E2164756E21
69694
+ //# debugId=A551D22BBC95CF9464756E2164756E21
69657
69695
  //# sourceMappingURL=index.js.map