@loomwright/cli 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/tui.js CHANGED
@@ -37541,7 +37541,7 @@ function toolEnv(name) {
37541
37541
  }
37542
37542
 
37543
37543
  // packages/core/src/version.ts
37544
- var FACTORY_VERSION = "1.2.0";
37544
+ var FACTORY_VERSION = "1.3.0";
37545
37545
 
37546
37546
  // packages/core/src/lock/lock.ts
37547
37547
  var LOCK_FILE = "factory.lock.json";
@@ -43948,7 +43948,10 @@ function realPathOf(abs, depth = 0) {
43948
43948
 
43949
43949
  // packages/core/src/policy/sandbox.ts
43950
43950
  var SANDBOX_EXEC = "/usr/bin/sandbox-exec";
43951
- function sandboxEnabled(setting, platform = process.platform, exists = existsSync23) {
43951
+ function sandboxEnabled(setting, platform = process.platform, exists = existsSync23, env = process.env) {
43952
+ const marker = env.AI_FACTORY_SANDBOX;
43953
+ if (marker === "wrapped" || marker === "off")
43954
+ return false;
43952
43955
  return setting !== "off" && platform === "darwin" && exists(SANDBOX_EXEC);
43953
43956
  }
43954
43957
  var regexPath = (p) => realPathOf(p).replace(/[.*+?^${}()|[\]\\/]/g, "\\$&");
@@ -44100,11 +44103,13 @@ function staleLockfileNote(paths) {
44100
44103
  async function runOne(input, gate) {
44101
44104
  const before = await snapshot2(input.worktree);
44102
44105
  const bins = gate.binDirs.map((b) => join29(input.worktree, b));
44106
+ const sandboxed = sandboxEnabled(input.config.security.sandbox);
44103
44107
  const env = {
44104
44108
  ...agentProcessEnv(),
44105
44109
  ...cacheEnv(input.root, input.repo.name),
44106
44110
  ...QUIET_ENV,
44107
44111
  ...gate.env ?? {},
44112
+ AI_FACTORY_SANDBOX: sandboxed ? "wrapped" : "off",
44108
44113
  PATH: [...bins, process.env.PATH ?? ""].join(delimiter)
44109
44114
  };
44110
44115
  const argv = [
@@ -44114,7 +44119,7 @@ async function runOne(input, gate) {
44114
44119
  ${gate.setup}
44115
44120
  ${gate.command}`
44116
44121
  ];
44117
- const res = await exec(sandboxEnabled(input.config.security.sandbox) ? sandboxArgv(seatbeltProfile(checkoutPolicy(input.root, input.worktree, [join29(input.root, ".factory", "cache")])), argv) : argv, {
44122
+ const res = await exec(sandboxed ? sandboxArgv(seatbeltProfile(checkoutPolicy(input.root, input.worktree, [join29(input.root, ".factory", "cache")])), argv) : argv, {
44118
44123
  cwd: join29(input.worktree, gate.cwd),
44119
44124
  env,
44120
44125
  replaceEnv: true,
@@ -53284,6 +53289,18 @@ var LABELS = {
53284
53289
  var answerRecorded = "recorded — applies at the next step";
53285
53290
  var emptyWorkspace = "No changes exist yet. Press n to start one.";
53286
53291
  var replayNotice = "Replay — read-only; the workspace is not touched.";
53292
+ var landConfirmNote = "the change branches are merged into their base branches locally";
53293
+ function landedNotice(id) {
53294
+ return `landed ${id} — the run is gone`;
53295
+ }
53296
+ function findingsCount(count) {
53297
+ return count === 1 ? "1 finding" : `${count} findings`;
53298
+ }
53299
+ function pausedFindings(dash, count) {
53300
+ if (count === 1)
53301
+ return `paused ${dash} 1 spec finding needs reword`;
53302
+ return `paused ${dash} ${count} spec findings need reword`;
53303
+ }
53287
53304
  function keyHint(key, label) {
53288
53305
  return { key, label, enabled: true };
53289
53306
  }
@@ -53301,6 +53318,138 @@ var TOKENS = {
53301
53318
  skipped: { hex: "#8A8A8A", ansi256: 245, ansi16: 8 }
53302
53319
  };
53303
53320
 
53321
+ // packages/tui/src/model/format.ts
53322
+ function formatElapsed(ms) {
53323
+ const seconds = Math.floor(Math.max(0, ms) / 1000);
53324
+ const s = seconds % 60;
53325
+ const m = Math.floor(seconds / 60) % 60;
53326
+ const h = Math.floor(seconds / 3600);
53327
+ if (h > 0)
53328
+ return `${h}h${String(m).padStart(2, "0")}m`;
53329
+ if (m > 0)
53330
+ return `${m}m${String(s).padStart(2, "0")}s`;
53331
+ return `${s}s`;
53332
+ }
53333
+ function formatTokensShort(n) {
53334
+ const value = Math.max(0, n);
53335
+ if (value >= 1e6)
53336
+ return `${(value / 1e6).toFixed(1)}M`;
53337
+ if (value >= 1000)
53338
+ return `${(value / 1000).toFixed(1)}k`;
53339
+ return String(Math.round(value));
53340
+ }
53341
+ function stripControls(text) {
53342
+ return text.replace(/[^\P{Cc}\t\n]/gu, "");
53343
+ }
53344
+ function flat(text) {
53345
+ return stripControls(text).replace(/\s*[\r\n]+\s*/g, " ").trim();
53346
+ }
53347
+ function truncate2(text, width, glyphs) {
53348
+ if (width <= 0)
53349
+ return "";
53350
+ if (text.length <= width)
53351
+ return text;
53352
+ const mark = glyphs.bullet === "-" ? "..." : "…";
53353
+ if (width <= mark.length)
53354
+ return mark.slice(0, width);
53355
+ return `${text.slice(0, width - mark.length)}${mark}`;
53356
+ }
53357
+
53358
+ // packages/tui/src/views/style.ts
53359
+ function inkColor(token, depth) {
53360
+ return depth === "none" ? undefined : TOKENS[token].hex;
53361
+ }
53362
+ function colorProps(token, depth) {
53363
+ const color = inkColor(token, depth);
53364
+ return color === undefined ? {} : { color };
53365
+ }
53366
+ function joinFields(glyphs, fields) {
53367
+ return fields.join(` ${glyphs.bullet} `);
53368
+ }
53369
+ function dash(glyphs) {
53370
+ return glyphs.bullet === "-" ? "-" : "—";
53371
+ }
53372
+ function gateLine(name, status, duration, widths) {
53373
+ return `${name.padEnd(widths.name)} ${status.padEnd(widths.status)} ${duration}`;
53374
+ }
53375
+ function clip(text, room, glyphs) {
53376
+ return truncate2(text, room, glyphs);
53377
+ }
53378
+ function statusGlyph(status, glyphs) {
53379
+ switch (status) {
53380
+ case "merged":
53381
+ case "pass":
53382
+ case "passed":
53383
+ return glyphs.passed;
53384
+ case "failed":
53385
+ case "fail":
53386
+ case "timeout":
53387
+ return glyphs.failed;
53388
+ case "blocked":
53389
+ case "cancelled":
53390
+ case "missing":
53391
+ case "not-check-only":
53392
+ return glyphs.blocked;
53393
+ case "skipped":
53394
+ return glyphs.skipped;
53395
+ case "running":
53396
+ case "merging":
53397
+ return glyphs.running;
53398
+ default:
53399
+ return glyphs.pending;
53400
+ }
53401
+ }
53402
+ function statusToken(status) {
53403
+ switch (status) {
53404
+ case "merged":
53405
+ case "pass":
53406
+ case "passed":
53407
+ return "passed";
53408
+ case "failed":
53409
+ case "fail":
53410
+ case "timeout":
53411
+ return "failed";
53412
+ case "blocked":
53413
+ case "cancelled":
53414
+ case "missing":
53415
+ case "not-check-only":
53416
+ return "blocked";
53417
+ case "skipped":
53418
+ return "skipped";
53419
+ case "running":
53420
+ case "merging":
53421
+ return "running";
53422
+ default:
53423
+ return "muted";
53424
+ }
53425
+ }
53426
+ function phaseGlyph(phase, glyphs) {
53427
+ switch (phase) {
53428
+ case "done":
53429
+ return glyphs.passed;
53430
+ case "aborted":
53431
+ return glyphs.failed;
53432
+ case "paused":
53433
+ case "awaiting-approval":
53434
+ return glyphs.blocked;
53435
+ default:
53436
+ return glyphs.running;
53437
+ }
53438
+ }
53439
+ function phaseToken(phase) {
53440
+ switch (phase) {
53441
+ case "done":
53442
+ return "passed";
53443
+ case "aborted":
53444
+ return "failed";
53445
+ case "paused":
53446
+ case "awaiting-approval":
53447
+ return "muted";
53448
+ default:
53449
+ return "running";
53450
+ }
53451
+ }
53452
+
53304
53453
  // packages/tui/src/approval/overlay.ts
53305
53454
  var MISSING_IDENTITY = "git user.email is not set; it records who approved";
53306
53455
  function approvalAvailable(evidence) {
@@ -53308,26 +53457,22 @@ function approvalAvailable(evidence) {
53308
53457
  return {
53309
53458
  approve: identity,
53310
53459
  "approve-only": identity,
53311
- reword: evidence.findings > 0,
53312
53460
  reapprove: identity && evidence.specCommit !== null
53313
53461
  };
53314
53462
  }
53315
53463
  var WAITING_FOR = {
53316
53464
  approve: ["queued", "implementing"],
53317
53465
  "approve-only": ["queued"],
53318
- reword: ["design", "awaiting-approval"],
53319
53466
  reapprove: ["awaiting-approval", "queued"]
53320
53467
  };
53321
53468
  var GRANTED_NEEDED = {
53322
53469
  approve: true,
53323
53470
  "approve-only": true,
53324
- reword: false,
53325
53471
  reapprove: true
53326
53472
  };
53327
53473
  var ALL_AVAILABLE = {
53328
53474
  approve: true,
53329
53475
  "approve-only": true,
53330
- reword: true,
53331
53476
  reapprove: true
53332
53477
  };
53333
53478
  function grantedCommit(commit, approver) {
@@ -53380,8 +53525,6 @@ function actionForKey(input) {
53380
53525
  return "approve";
53381
53526
  case "A":
53382
53527
  return "approve-only";
53383
- case "w":
53384
- return "reword";
53385
53528
  case "R":
53386
53529
  return "reapprove";
53387
53530
  default:
@@ -53402,7 +53545,7 @@ function approvalKeys(state, input, key, available = ALL_AVAILABLE) {
53402
53545
  if (key.return || !key.ctrl && input === "y") {
53403
53546
  return { state: { kind: "launching", action: state.action }, launch: state.action };
53404
53547
  }
53405
- if (key.escape || !key.ctrl && input === "n")
53548
+ if (!key.ctrl && input === "n")
53406
53549
  return { state: { kind: "idle" } };
53407
53550
  return { state };
53408
53551
  }
@@ -53411,17 +53554,12 @@ function approvalKeys(state, input, key, available = ALL_AVAILABLE) {
53411
53554
  return { state };
53412
53555
  return { state: { kind: "confirming", action } };
53413
53556
  }
53414
- function dash(glyphs) {
53415
- return glyphs.bullet === "-" ? "-" : "—";
53416
- }
53417
53557
  function actionLabel(action) {
53418
53558
  switch (action) {
53419
53559
  case "approve":
53420
53560
  return "approve and run";
53421
53561
  case "approve-only":
53422
53562
  return "approve only";
53423
- case "reword":
53424
- return "reword";
53425
53563
  case "reapprove":
53426
53564
  return "reapprove";
53427
53565
  default: {
@@ -53446,8 +53584,6 @@ function confirmation(input) {
53446
53584
  "confirm approve only: nothing is implemented",
53447
53585
  `press r (resume) later or run \`loomwright approve ${run.id}\``
53448
53586
  ];
53449
- case "reword":
53450
- return ["confirm reword: this starts the architect session", "and may take long"];
53451
53587
  case "reapprove": {
53452
53588
  const commit = input.evidence.specCommit;
53453
53589
  return [
@@ -53498,24 +53634,28 @@ function stateLines(input, glyphs) {
53498
53634
  }
53499
53635
  }
53500
53636
  }
53637
+ function inertEsc(reason) {
53638
+ return { key: "Esc", label: "waits for the action", enabled: false, reason };
53639
+ }
53501
53640
  function panelKeys(input) {
53502
53641
  const { state, evidence } = input;
53503
53642
  const keys = [];
53504
53643
  if (state.kind === "confirming") {
53505
- keys.push(keyHint("Enter", "confirm"), keyHint("Esc", "cancel"));
53506
- } else if (state.kind === "waiting") {
53507
- if (state.action === "approve-only")
53644
+ keys.push(keyHint("Enter", "confirm"), keyHint("n", "cancel"), inertEsc("press Enter or n"));
53645
+ } else if (state.kind === "launching" || state.kind === "waiting") {
53646
+ if (state.kind === "waiting" && state.action === "approve-only") {
53508
53647
  keys.push(keyHint("r", "resume"));
53648
+ }
53649
+ keys.push(inertEsc("the child is still running"));
53509
53650
  } else if (state.kind === "idle" || state.kind === "failed") {
53510
53651
  const available = approvalAvailable(evidence);
53511
53652
  if (available.approve)
53512
53653
  keys.push(keyHint("a", "approve and run"));
53513
53654
  if (available["approve-only"])
53514
53655
  keys.push(keyHint("A", "approve only"));
53515
- if (available.reword)
53516
- keys.push(keyHint("w", "reword"));
53517
53656
  if (available.reapprove)
53518
53657
  keys.push(keyHint("R", "reapprove"));
53658
+ keys.push(keyHint("Esc", "collapse"));
53519
53659
  }
53520
53660
  keys.push(keyHint("q", "quit"));
53521
53661
  return keys;
@@ -53543,6 +53683,109 @@ function approvalPanel(input) {
53543
53683
  };
53544
53684
  }
53545
53685
 
53686
+ // packages/tui/src/model/activity-scope.ts
53687
+ var REVIEW_PREFIX = "review:";
53688
+ var EXPLORE_PREFIX = "explore:";
53689
+ function scopeKey(scope) {
53690
+ switch (scope.kind) {
53691
+ case "run":
53692
+ return "run";
53693
+ case "task":
53694
+ return `task:${scope.taskId}`;
53695
+ case "repo":
53696
+ return `repo:${scope.repo}`;
53697
+ default: {
53698
+ const unhandled = scope;
53699
+ throw new Error(`unknown activity scope: ${String(unhandled)}`);
53700
+ }
53701
+ }
53702
+ }
53703
+ function scopesOfLine(tasks, line) {
53704
+ const step = line.step;
53705
+ const task = tasks.find((candidate) => candidate.id === step);
53706
+ if (task !== undefined)
53707
+ return taskScopeFor(task);
53708
+ for (const prefix of [REVIEW_PREFIX, EXPLORE_PREFIX]) {
53709
+ if (!step.startsWith(prefix))
53710
+ continue;
53711
+ const repo = step.slice(prefix.length);
53712
+ if (repo !== "")
53713
+ return [{ kind: "repo", repo }];
53714
+ }
53715
+ if (step !== "" && tasks.some((candidate) => candidate.repo === step))
53716
+ return [{ kind: "repo", repo: step }];
53717
+ return [{ kind: "run" }];
53718
+ }
53719
+ function taskScopeFor(task) {
53720
+ const scopes = [{ kind: "task", taskId: task.id }];
53721
+ if (task.repo !== "")
53722
+ scopes.push({ kind: "repo", repo: task.repo });
53723
+ return scopes;
53724
+ }
53725
+ function linesInScope(tasks, lines, scope) {
53726
+ switch (scope.kind) {
53727
+ case "run":
53728
+ return lines;
53729
+ case "task": {
53730
+ const task = tasks.find((candidate) => candidate.id === scope.taskId);
53731
+ const wanted = task === undefined ? [{ kind: "task", taskId: scope.taskId }] : taskScopeFor(task);
53732
+ const keys = new Set(wanted.map(scopeKey));
53733
+ return lines.filter((line) => scopesOfLine(tasks, line).some((lineScope) => keys.has(scopeKey(lineScope))));
53734
+ }
53735
+ case "repo":
53736
+ return lines.filter((line) => scopesOfLine(tasks, line).some((lineScope) => lineScope.kind === "repo" && lineScope.repo === scope.repo));
53737
+ default: {
53738
+ const unhandled = scope;
53739
+ throw new Error(`unknown activity scope: ${String(unhandled)}`);
53740
+ }
53741
+ }
53742
+ }
53743
+
53744
+ // packages/tui/src/model/viewport.ts
53745
+ function clampOffset(offset, length, size) {
53746
+ if (size <= 0 || length <= 0)
53747
+ return 0;
53748
+ return Math.min(Math.max(0, length - size), Math.max(0, offset));
53749
+ }
53750
+ function window2(offset, length, size) {
53751
+ return { offset, size, total: length };
53752
+ }
53753
+ function sliceWindow(items, w) {
53754
+ return items.slice(w.offset, Math.min(w.total, w.offset + w.size));
53755
+ }
53756
+ function pageSize(size) {
53757
+ return Math.max(1, size);
53758
+ }
53759
+ function moveBy(offset, delta, length, size) {
53760
+ return clampOffset(offset + delta, length, size);
53761
+ }
53762
+ function firstOffset(length) {
53763
+ return clampOffset(0, length, length);
53764
+ }
53765
+ function lastOffset(length, size) {
53766
+ return clampOffset(length - size, length, size);
53767
+ }
53768
+ function nextOffset(offset, index, length, size) {
53769
+ if (size <= 0 || length <= 0)
53770
+ return 0;
53771
+ const current = clampOffset(offset, length, size);
53772
+ if (index < current)
53773
+ return clampOffset(index, length, size);
53774
+ if (index >= current + size)
53775
+ return clampOffset(index - size + 1, length, size);
53776
+ return current;
53777
+ }
53778
+ function followOffset(offset, length, size, follow = true) {
53779
+ return follow ? lastOffset(length, size) : clampOffset(offset, length, size);
53780
+ }
53781
+ function windowTitle(label, w) {
53782
+ if (w.total <= w.size)
53783
+ return null;
53784
+ const start = w.offset + 1;
53785
+ const end = Math.min(w.total, w.offset + w.size);
53786
+ return `${label} ${start}-${end}/${w.total}`;
53787
+ }
53788
+
53546
53789
  // packages/tui/src/model/view-model.ts
53547
53790
  function elapsedSince(createdAt, now) {
53548
53791
  const created = Date.parse(createdAt);
@@ -53581,25 +53824,27 @@ function runEntries(input) {
53581
53824
  }
53582
53825
  function taskRow(task, snapshot, selectedTaskId) {
53583
53826
  const seen = snapshot?.tasks[task.id];
53827
+ const id = flat(task.id);
53584
53828
  return {
53585
- id: task.id,
53586
- title: task.title,
53587
- repo: task.repo,
53829
+ id,
53830
+ title: flat(task.title),
53831
+ repo: flat(task.repo),
53588
53832
  status: seen?.status ?? task.status,
53589
53833
  attempt: seen?.attempt ?? 0,
53590
53834
  failures: task.failures,
53591
53835
  deps: task.deps,
53592
- selected: task.id === selectedTaskId
53836
+ selected: id === selectedTaskId
53593
53837
  };
53594
53838
  }
53595
53839
  function questionRows(run, snapshot) {
53596
53840
  const questionsFile = run.draft === undefined ? `openspec/changes/${run.id}/questions.md` : `${run.draft}/openspec/changes/${run.id}/questions.md`;
53597
53841
  const records = snapshot?.questions ?? run.clarifications;
53598
53842
  return records.map((question) => ({
53599
- step: question.step,
53600
- question: question.question,
53843
+ step: flat(question.step),
53844
+ question: flat(question.question),
53845
+ rawQuestion: question.question,
53601
53846
  status: question.status,
53602
- ...question.answer === undefined ? {} : { answer: question.answer },
53847
+ ...question.answer === undefined ? {} : { answer: flat(question.answer) },
53603
53848
  questionsFile
53604
53849
  }));
53605
53850
  }
@@ -53608,31 +53853,73 @@ function approvalView(run, snapshot) {
53608
53853
  const granted = snapshot?.approval ?? null;
53609
53854
  if (pending === null && granted === null && run.phase !== "awaiting-approval")
53610
53855
  return null;
53856
+ const specHash = pending?.specHash ?? granted?.specHash ?? null;
53857
+ const specCommit = granted !== null && granted.approver !== "" ? granted.specCommit : null;
53858
+ const approver = granted !== null && granted.approver !== "" ? granted.approver : null;
53611
53859
  return {
53612
53860
  changeId: run.id,
53613
- summary: run.summary,
53614
- changeDir: pending?.changeDir ?? null,
53615
- specHash: pending?.specHash ?? granted?.specHash ?? null,
53616
- specCommit: granted !== null && granted.approver !== "" ? granted.specCommit : null,
53617
- approver: granted !== null && granted.approver !== "" ? granted.approver : null
53618
- };
53861
+ summary: flat(run.summary),
53862
+ changeDir: pending === null ? null : flat(pending.changeDir),
53863
+ specHash: specHash === null ? null : flat(specHash),
53864
+ specCommit: specCommit === null ? null : flat(specCommit),
53865
+ approver: approver === null ? null : flat(approver)
53866
+ };
53867
+ }
53868
+ function findingRows(run) {
53869
+ return run.specFindings.map((finding) => ({
53870
+ severity: finding.severity,
53871
+ file: finding.file === undefined ? null : flat(finding.file),
53872
+ line: finding.line === undefined ? null : finding.line,
53873
+ what: flat(finding.what),
53874
+ problem: flat(finding.problem),
53875
+ fix: flat(finding.fix),
53876
+ impact: flat(finding.impact)
53877
+ }));
53619
53878
  }
53620
- function taskDetail(row, facts) {
53879
+ function taskDetail(row, facts, tasks) {
53621
53880
  return {
53622
53881
  task: row,
53623
53882
  agent: facts.agents[row.id] ?? null,
53624
53883
  retries: facts.retries[row.id] ?? 0,
53625
53884
  gates: facts.gates[row.id] ?? [],
53626
- activity: facts.activity.filter((line) => line.step === row.id)
53885
+ activity: linesInScope(tasks, facts.activity, { kind: "task", taskId: row.id })
53627
53886
  };
53628
53887
  }
53888
+ var REWORD_PHASES = new Set([
53889
+ "queued",
53890
+ "implementing",
53891
+ "reviewing",
53892
+ "contracts",
53893
+ "full-suite",
53894
+ "closing",
53895
+ "paused",
53896
+ "aborted"
53897
+ ]);
53898
+ function rewordAvailability(run, input) {
53899
+ if (input.source === "replay" || !REWORD_PHASES.has(run.phase))
53900
+ return { state: "absent", reason: null };
53901
+ const role = roleOf(run.id, input.status);
53902
+ if (role.kind === "active")
53903
+ return {
53904
+ state: "inert",
53905
+ reason: `${run.id} is being driven by pid ${role.pid}; stop it first`
53906
+ };
53907
+ const active = input.status.active;
53908
+ if (input.status.driverAlive && active !== null && active.changeId !== run.id)
53909
+ return {
53910
+ state: "inert",
53911
+ reason: `${active.changeId} is the active change; finish or abort it before rewording ${run.id}`
53912
+ };
53913
+ return { state: "available", reason: null };
53914
+ }
53629
53915
  function runDetail(entry, input) {
53630
53916
  const { run } = entry;
53631
53917
  const tasks = run.tasks.map((task) => taskRow(task, input.snapshot, input.selectedTaskId));
53918
+ const scopeTasks = tasks.map(({ id, repo }) => ({ id, repo }));
53632
53919
  const selected = tasks.find((task) => task.id === input.selectedTaskId) ?? null;
53633
53920
  return {
53634
53921
  id: run.id,
53635
- summary: run.summary,
53922
+ summary: flat(run.summary),
53636
53923
  phase: run.phase,
53637
53924
  elapsedMs: elapsedSince(run.createdAt, input.now),
53638
53925
  tokens: entry.tokens,
@@ -53640,16 +53927,22 @@ function runDetail(entry, input) {
53640
53927
  lock: roleOf(run.id, input.status),
53641
53928
  tasks,
53642
53929
  selectedTaskId: input.selectedTaskId,
53643
- detail: selected === null ? null : taskDetail(selected, input.facts),
53930
+ detail: selected === null ? null : taskDetail(selected, input.facts, scopeTasks),
53644
53931
  activity: input.facts.activity,
53645
53932
  questions: questionRows(run, input.snapshot),
53646
53933
  approval: approvalView(run, input.snapshot),
53647
- replayed: input.source === "replay"
53934
+ specFindings: findingRows(run),
53935
+ pausedReason: run.pausedReason === undefined ? null : flat(run.pausedReason),
53936
+ replayed: input.source === "replay",
53937
+ reword: rewordAvailability(run, input)
53648
53938
  };
53649
53939
  }
53650
53940
  function canResume(phase) {
53651
53941
  return phase === "paused" || phase === "aborted" || phase === "queued";
53652
53942
  }
53943
+ function canLand(phase) {
53944
+ return phase === "done";
53945
+ }
53653
53946
  function listFooter(input) {
53654
53947
  return [
53655
53948
  keyHint("n", "new change"),
@@ -53658,41 +53951,146 @@ function listFooter(input) {
53658
53951
  ...input.selectedRunId === null ? [] : [keyHint("Enter", "open run")]
53659
53952
  ];
53660
53953
  }
53661
- function runFooter(run) {
53954
+ function runFooter(input, run) {
53662
53955
  if (run === null)
53663
53956
  return [keyHint("q", "quit"), keyHint("?", "help")];
53957
+ if (input.source === "replay")
53958
+ return [keyHint("L", "log"), keyHint("?", "help"), keyHint("q", "quit")];
53664
53959
  const hints = [];
53665
53960
  if (canResume(run.phase))
53666
53961
  hints.push(keyHint("r", "resume"));
53962
+ if (canLand(run.phase))
53963
+ hints.push(keyHint("l", "land"));
53964
+ hints.push(...rewordHints(run.reword));
53667
53965
  if (run.phase !== "done" && run.phase !== "aborted")
53668
53966
  hints.push(keyHint("x", "abort"));
53669
53967
  if (run.detail?.task.status === "failed")
53670
53968
  hints.push(keyHint("t", "retry task"));
53671
53969
  if (run.questions.length > 0)
53672
53970
  hints.push(keyHint("Q", "questions"));
53673
- hints.push(keyHint("?", "help"), keyHint("q", "quit"));
53971
+ hints.push(keyHint("L", "log"), keyHint("?", "help"), keyHint("q", "quit"));
53674
53972
  return hints;
53675
53973
  }
53974
+ function rewordHints(reword) {
53975
+ switch (reword.state) {
53976
+ case "available":
53977
+ return [keyHint("w", "reword")];
53978
+ case "inert":
53979
+ return [
53980
+ {
53981
+ key: "w",
53982
+ label: "reword",
53983
+ enabled: false,
53984
+ ...reword.reason === null ? {} : { reason: reword.reason }
53985
+ }
53986
+ ];
53987
+ case "absent":
53988
+ return [];
53989
+ default: {
53990
+ const unhandled = reword.state;
53991
+ throw new Error(`unknown reword state: ${String(unhandled)}`);
53992
+ }
53993
+ }
53994
+ }
53676
53995
  function footerFor(input, run) {
53677
53996
  if (input.panel !== undefined && input.panel !== null)
53678
53997
  return input.panel.keys;
53679
- return input.screen === "list" ? listFooter(input) : runFooter(run);
53998
+ return input.screen === "list" ? listFooter(input) : runFooter(input, run);
53999
+ }
54000
+ var TAIL_FLOOR = 4;
54001
+ function headerRows(run) {
54002
+ if (run === null)
54003
+ return 1;
54004
+ if (run.phase === "awaiting-approval")
54005
+ return 2;
54006
+ if (run.phase === "paused" && run.specFindings.length > 0)
54007
+ return 2;
54008
+ return 1;
54009
+ }
54010
+ function capNotice(notice, maxRows) {
54011
+ const lines = notice.split(`
54012
+ `);
54013
+ if (lines.length <= maxRows)
54014
+ return notice;
54015
+ if (maxRows <= 0)
54016
+ return null;
54017
+ const head = lines.slice(0, Math.min(2, maxRows));
54018
+ const tailRows = maxRows - head.length;
54019
+ return [...head, ...tailRows === 0 ? [] : lines.slice(-tailRows)].join(`
54020
+ `);
54021
+ }
54022
+ function detailNoticeRows(rows, header) {
54023
+ return Math.max(0, rows - header - 1 - DETAIL_MIN_ROWS);
54024
+ }
54025
+ function singlePaneTailRows(viewModel) {
54026
+ const run = viewModel.run;
54027
+ if (run === null)
54028
+ return 0;
54029
+ const noticeRows = viewModel.notice === null ? 0 : viewModel.notice.split(`
54030
+ `).length;
54031
+ const graphRows = 1 + Math.min(run.tasks.length, viewModel.taskWindow.size);
54032
+ return Math.max(0, viewModel.rows - headerRows(run) - noticeRows - graphRows - 1);
54033
+ }
54034
+ function twoPaneTailRows(viewModel) {
54035
+ const run = viewModel.run;
54036
+ if (run === null)
54037
+ return 0;
54038
+ const noticeRows = viewModel.notice === null ? 0 : viewModel.notice.split(`
54039
+ `).length;
54040
+ return Math.max(0, viewModel.rows - headerRows(run) - noticeRows - 1);
54041
+ }
54042
+ var DETAIL_FIXED_ROWS = 10;
54043
+ var DETAIL_MIN_ROWS = DETAIL_FIXED_ROWS + 1;
54044
+ var DETAIL_TAIL_FLOOR = 4;
54045
+ function detailBodyRows(viewModel, run) {
54046
+ const noticeRows = viewModel.notice === null ? 0 : viewModel.notice.split(`
54047
+ `).length;
54048
+ return Math.max(0, viewModel.rows - headerRows(run) - noticeRows - 1);
54049
+ }
54050
+ function detailFixedRows(detail) {
54051
+ return DETAIL_FIXED_ROWS + (detail.gates.length === 0 ? 1 : 0) + (detail.activity.length === 0 ? 1 : 0);
54052
+ }
54053
+ function taskDetailGateRows(viewModel) {
54054
+ const run = viewModel.run;
54055
+ if (run === null || run.detail === null)
54056
+ return 0;
54057
+ return Math.max(0, detailBodyRows(viewModel, run) - detailFixedRows(run.detail) - DETAIL_TAIL_FLOOR);
54058
+ }
54059
+ function taskDetailTailRows(viewModel) {
54060
+ const run = viewModel.run;
54061
+ if (run === null || run.detail === null)
54062
+ return 0;
54063
+ const gates = run.detail.gates.length;
54064
+ const gateRows = gates === 0 ? 1 : Math.min(gates, taskDetailGateRows(viewModel));
54065
+ return Math.max(0, detailBodyRows(viewModel, run) - detailFixedRows(run.detail) - gateRows);
53680
54066
  }
53681
54067
  function buildViewModel(input) {
53682
54068
  const ordered = runEntries(input).sort((a, b) => Date.parse(b.run.createdAt) - Date.parse(a.run.createdAt));
53683
54069
  const list = ordered.map(({ run, tokens, cost }) => ({
53684
54070
  id: run.id,
53685
- summary: run.summary,
54071
+ summary: flat(run.summary),
53686
54072
  phase: run.phase,
53687
54073
  role: roleOf(run.id, input.status),
53688
54074
  tokens,
53689
54075
  cost,
53690
54076
  elapsedMs: elapsedSince(run.createdAt, input.now),
54077
+ findings: run.specFindings.length,
53691
54078
  selected: run.id === input.selectedRunId
53692
54079
  }));
53693
54080
  const entry = ordered.find((candidate) => candidate.run.id === input.selectedRunId);
53694
54081
  const run = entry === undefined ? null : runDetail(entry, input);
53695
- const notice = input.notice ?? (input.source === "replay" ? replayNotice : null) ?? (list.length === 0 ? emptyWorkspace : null);
54082
+ const header = headerRows(run);
54083
+ const rawNotice = input.notice ?? (input.source === "replay" ? replayNotice : null) ?? (list.length === 0 ? emptyWorkspace : null);
54084
+ const notice = rawNotice === null || run === null || run.detail === null ? rawNotice : capNotice(rawNotice, detailNoticeRows(input.rows, header));
54085
+ const noticeRows = notice === null ? 0 : notice.split(`
54086
+ `).length;
54087
+ const footerRows = 1;
54088
+ const listSize = Math.max(0, input.rows - 1 - footerRows - noticeRows);
54089
+ const graphSize = Math.min(run?.tasks.length ?? 0, Math.max(0, input.rows - header - noticeRows - 2 - TAIL_FLOOR));
54090
+ const listIndex = list.findIndex((item) => item.id === input.selectedRunId);
54091
+ const taskIndex = run?.tasks.findIndex((task) => task.id === input.selectedTaskId) ?? -1;
54092
+ const listOffset = nextOffset(input.listOffset ?? 0, listIndex, list.length, listSize);
54093
+ const taskOffset = nextOffset(input.taskOffset ?? 0, taskIndex, run?.tasks.length ?? 0, graphSize);
53696
54094
  return {
53697
54095
  source: input.source,
53698
54096
  screen: input.screen,
@@ -53704,7 +54102,9 @@ function buildViewModel(input) {
53704
54102
  run,
53705
54103
  panel: input.panel ?? null,
53706
54104
  footer: footerFor(input, run),
53707
- notice
54105
+ notice,
54106
+ listWindow: window2(listOffset, list.length, listSize),
54107
+ taskWindow: window2(taskOffset, run?.tasks.length ?? 0, graphSize)
53708
54108
  };
53709
54109
  }
53710
54110
 
@@ -53732,6 +54132,12 @@ function resumeFor(viewModel) {
53732
54132
  return null;
53733
54133
  return canResume(run.phase) ? { kind: "resume", id: run.id } : null;
53734
54134
  }
54135
+ function landFor(viewModel) {
54136
+ const run = viewModel.run;
54137
+ if (run === null)
54138
+ return null;
54139
+ return canLand(run.phase) ? { kind: "land", id: run.id } : null;
54140
+ }
53735
54141
  function dash2(glyphs) {
53736
54142
  return glyphs.bullet === "-" ? "-" : "—";
53737
54143
  }
@@ -53772,6 +54178,19 @@ function confirmPanel(action, glyphs) {
53772
54178
  keys: [keyHint("Enter", "confirm"), keyHint("Esc", "cancel")],
53773
54179
  notice: null
53774
54180
  };
54181
+ case "land":
54182
+ return {
54183
+ kind: "confirm",
54184
+ title: `Land ${action.id}?`,
54185
+ lines: [
54186
+ `change: ${action.id}`,
54187
+ landConfirmNote,
54188
+ `merged change branches are deleted ${dash2(glyphs)} its worktrees and run state removed`,
54189
+ "nothing is pushed"
54190
+ ],
54191
+ keys: [keyHint("Enter", "confirm"), keyHint("Esc", "cancel")],
54192
+ notice: null
54193
+ };
53775
54194
  default: {
53776
54195
  const unhandled = action;
53777
54196
  throw new Error(`unknown control action: ${String(unhandled)}`);
@@ -53786,86 +54205,360 @@ function confirmKeys(input, key) {
53786
54205
  return "none";
53787
54206
  }
53788
54207
 
53789
- // packages/tui/src/controls/questions.tsx
53790
- var initialQuestions = {
53791
- selected: 0,
53792
- draft: null,
53793
- notice: null
53794
- };
53795
- function recordAt(run, index) {
53796
- return run.questions[index];
53797
- }
53798
- function draftFor(record) {
53799
- if (record.status !== "unanswered")
53800
- return null;
53801
- return { step: record.step, question: record.question, text: "", recorded: false };
54208
+ // packages/tui/src/controls/activity-pane.ts
54209
+ var PANE_CHROME_ROWS = 5;
54210
+ function activityPaneBodyRows(rows) {
54211
+ return Math.max(1, rows - PANE_CHROME_ROWS);
53802
54212
  }
53803
- function withSelection(run, state, index) {
53804
- const record = recordAt(run, index);
53805
- if (record === undefined)
53806
- return state;
53807
- const draft = draftFor(record);
53808
- return { selected: index, draft, notice: null };
54213
+ function paneState(scope, taskId) {
54214
+ return { scope, taskId, offset: 0, follow: true };
53809
54215
  }
53810
- function openQuestions(run) {
53811
- if (run.questions.length === 0)
53812
- return null;
53813
- const index = run.questions.findIndex((record) => record.status === "unanswered");
53814
- return withSelection(run, initialQuestions, index === -1 ? 0 : index);
54216
+ function taskFor(run, taskId) {
54217
+ return taskId === null ? undefined : run.tasks.find((task) => task.id === taskId);
53815
54218
  }
53816
- function append(state, text) {
53817
- if (state.draft === null)
53818
- return state;
53819
- return { ...state, draft: { ...state.draft, text: state.draft.text + text }, notice: null };
54219
+ function scopeTasks(run) {
54220
+ return run.tasks.map(({ id, repo }) => ({ id, repo }));
53820
54221
  }
53821
- function removeLast(state) {
53822
- if (state.draft === null)
53823
- return state;
53824
- return {
53825
- ...state,
53826
- draft: { ...state.draft, text: state.draft.text.slice(0, -1) },
53827
- notice: null
53828
- };
54222
+ function openActivityPane(run) {
54223
+ const task = taskFor(run, run.selectedTaskId);
54224
+ return task === undefined ? paneState("run", null) : paneState("task", task.id);
53829
54225
  }
53830
- function questionsKeys(run, state, input, key) {
53831
- const record = recordAt(run, state.selected);
53832
- if (key.escape) {
53833
- return state.draft === null ? { state } : { state: { ...state, draft: null, notice: null } };
54226
+ function cycleScope(run, state) {
54227
+ switch (state.scope) {
54228
+ case "run": {
54229
+ const task = taskFor(run, run.selectedTaskId ?? run.tasks[0]?.id ?? null);
54230
+ return task === undefined ? state : { ...state, scope: "task", taskId: task.id };
54231
+ }
54232
+ case "task": {
54233
+ const task = taskFor(run, state.taskId);
54234
+ if (task === undefined || task.repo === "") {
54235
+ return { ...state, scope: "run", taskId: null };
54236
+ }
54237
+ return { ...state, scope: "repo", taskId: task.id };
54238
+ }
54239
+ case "repo":
54240
+ return { ...state, scope: "run", taskId: null };
54241
+ default: {
54242
+ const unhandled = state.scope;
54243
+ throw new Error(`unknown pane scope: ${String(unhandled)}`);
54244
+ }
53834
54245
  }
53835
- if (state.draft === null && (key.upArrow || !key.ctrl && input === "k")) {
53836
- return { state: withSelection(run, state, Math.max(0, state.selected - 1)) };
54246
+ }
54247
+ function scopeLines(run, state) {
54248
+ const tasks = scopeTasks(run);
54249
+ switch (state.scope) {
54250
+ case "run":
54251
+ return linesInScope(tasks, run.activity, { kind: "run" });
54252
+ case "task":
54253
+ return state.taskId === null ? [] : linesInScope(tasks, run.activity, { kind: "task", taskId: state.taskId });
54254
+ case "repo": {
54255
+ const task = taskFor(run, state.taskId);
54256
+ if (task === undefined || task.repo === "")
54257
+ return [];
54258
+ return linesInScope(tasks, run.activity, { kind: "repo", repo: task.repo });
54259
+ }
54260
+ default: {
54261
+ const unhandled = state.scope;
54262
+ throw new Error(`unknown pane scope: ${String(unhandled)}`);
54263
+ }
53837
54264
  }
53838
- if (state.draft === null && (key.downArrow || !key.ctrl && input === "j")) {
53839
- return {
53840
- state: withSelection(run, state, Math.min(run.questions.length - 1, state.selected + 1))
54265
+ }
54266
+ function scopeName(run, state) {
54267
+ switch (state.scope) {
54268
+ case "run":
54269
+ return "run";
54270
+ case "task":
54271
+ return state.taskId ?? "run";
54272
+ case "repo": {
54273
+ const task = taskFor(run, state.taskId);
54274
+ return task === undefined || task.repo === "" ? "repo" : task.repo;
54275
+ }
54276
+ default: {
54277
+ const unhandled = state.scope;
54278
+ throw new Error(`unknown pane scope: ${String(unhandled)}`);
54279
+ }
54280
+ }
54281
+ }
54282
+ function paneWindow(state, length, size) {
54283
+ return window2(followOffset(state.offset, length, size, state.follow), length, size);
54284
+ }
54285
+ function activityPaneKeys(run, state, input, key, size) {
54286
+ if (key.escape)
54287
+ return { state, close: true };
54288
+ if (key.tab)
54289
+ return { state: cycleScope(run, state) };
54290
+ const length = scopeLines(run, state).length;
54291
+ const height = Math.max(1, size);
54292
+ const current = followOffset(state.offset, length, height, state.follow);
54293
+ if (!key.ctrl && input === "f") {
54294
+ const follow = !state.follow;
54295
+ return {
54296
+ state: {
54297
+ ...state,
54298
+ follow,
54299
+ offset: follow ? lastOffset(length, height) : current
54300
+ }
54301
+ };
54302
+ }
54303
+ if (key.downArrow || !key.ctrl && input === "j") {
54304
+ return {
54305
+ state: { ...state, follow: false, offset: clampOffset(current + 1, length, height) }
54306
+ };
54307
+ }
54308
+ if (key.upArrow || !key.ctrl && input === "k") {
54309
+ return {
54310
+ state: { ...state, follow: false, offset: clampOffset(current - 1, length, height) }
54311
+ };
54312
+ }
54313
+ if (key.pageDown) {
54314
+ return {
54315
+ state: {
54316
+ ...state,
54317
+ follow: false,
54318
+ offset: clampOffset(current + pageSize(height), length, height)
54319
+ }
54320
+ };
54321
+ }
54322
+ if (key.pageUp) {
54323
+ return {
54324
+ state: {
54325
+ ...state,
54326
+ follow: false,
54327
+ offset: clampOffset(current - pageSize(height), length, height)
54328
+ }
53841
54329
  };
53842
54330
  }
54331
+ if (!key.ctrl && input === "g") {
54332
+ return { state: { ...state, follow: false, offset: firstOffset(length) } };
54333
+ }
54334
+ if (!key.ctrl && input === "G") {
54335
+ return { state: { ...state, follow: false, offset: lastOffset(length, height) } };
54336
+ }
54337
+ return { state };
54338
+ }
54339
+ function activityLineText(line, glyphs) {
54340
+ const ref = line.logRef === undefined ? "" : `${glyphs.arrow} ${line.logRef} `;
54341
+ return `${line.step} ${glyphs.bullet} ${line.kind} ${glyphs.bullet} ${ref}${line.text}`;
54342
+ }
54343
+ function dash3(glyphs) {
54344
+ return glyphs.bullet === "-" ? "-" : "—";
54345
+ }
54346
+ function activityPanePanel(input) {
54347
+ const { run, state, glyphs, rows } = input;
54348
+ const lines = scopeLines(run, state);
54349
+ const bodyRows = activityPaneBodyRows(rows);
54350
+ const shown = sliceWindow(lines, paneWindow(state, lines.length, bodyRows)).map((line) => activityLineText(line, glyphs));
54351
+ const body = [...shown, ...Array(bodyRows - shown.length).fill(" ")];
54352
+ return {
54353
+ kind: "activity",
54354
+ title: `Activity ${dash3(glyphs)} ${scopeName(run, state)}`,
54355
+ lines: body,
54356
+ keys: [
54357
+ keyHint("j/k", "scroll"),
54358
+ keyHint("PgUp/PgDn", "page"),
54359
+ keyHint("g/G", "ends"),
54360
+ keyHint("f", state.follow ? "follow on" : "follow off"),
54361
+ keyHint("Tab", "scope"),
54362
+ keyHint("Esc", "back")
54363
+ ],
54364
+ notice: null
54365
+ };
54366
+ }
54367
+
54368
+ // packages/tui/src/model/keys.ts
54369
+ function deletesLast(key) {
54370
+ return key.backspace || key.delete;
54371
+ }
54372
+ function listIntent(viewModel, key) {
54373
+ switch (key) {
54374
+ case "Enter":
54375
+ case "\r":
54376
+ return viewModel.selectedRunId === null ? { kind: "none" } : { kind: "open-run", runId: viewModel.selectedRunId };
54377
+ case "Down":
54378
+ case "j":
54379
+ return { kind: "next-run" };
54380
+ case "Up":
54381
+ case "k":
54382
+ return { kind: "prev-run" };
54383
+ case "PgUp":
54384
+ return { kind: "page-up" };
54385
+ case "PgDn":
54386
+ return { kind: "page-down" };
54387
+ case "g":
54388
+ return { kind: "first" };
54389
+ case "G":
54390
+ return { kind: "last" };
54391
+ default:
54392
+ return { kind: "none" };
54393
+ }
54394
+ }
54395
+ function runIntent(viewModel, key) {
54396
+ switch (key) {
54397
+ case "Esc":
54398
+ case "\x1B":
54399
+ return viewModel.run?.selectedTaskId == null ? { kind: "back" } : { kind: "clear-task" };
54400
+ case "Down":
54401
+ case "j":
54402
+ return { kind: "next-task" };
54403
+ case "Up":
54404
+ case "k":
54405
+ return { kind: "prev-task" };
54406
+ case "PgUp":
54407
+ return { kind: "page-up" };
54408
+ case "PgDn":
54409
+ return { kind: "page-down" };
54410
+ case "g":
54411
+ return { kind: "first" };
54412
+ case "G":
54413
+ return { kind: "last" };
54414
+ case "r":
54415
+ return { kind: "resume" };
54416
+ case "x":
54417
+ return { kind: "abort" };
54418
+ case "t":
54419
+ return { kind: "retry" };
54420
+ case "l":
54421
+ return { kind: "land" };
54422
+ case "Q":
54423
+ return { kind: "open-questions" };
54424
+ case "L":
54425
+ return { kind: "open-activity" };
54426
+ default:
54427
+ return { kind: "none" };
54428
+ }
54429
+ }
54430
+ function applyKey(viewModel, key) {
54431
+ if (viewModel.panel !== null)
54432
+ return { kind: "none" };
54433
+ if (key === "q")
54434
+ return { kind: "quit" };
54435
+ if (key === "?")
54436
+ return { kind: "help" };
54437
+ return viewModel.screen === "list" ? listIntent(viewModel, key) : runIntent(viewModel, key);
54438
+ }
54439
+
54440
+ // packages/tui/src/controls/questions.tsx
54441
+ var initialQuestions = {
54442
+ selected: 0,
54443
+ focus: "record",
54444
+ text: "",
54445
+ offset: 0,
54446
+ recorded: new Set,
54447
+ notice: null
54448
+ };
54449
+ function recordKey(step, question) {
54450
+ return `${step}\x00${question}`;
54451
+ }
54452
+ var RECORD_BLOCK_ROWS = 3;
54453
+ var PANE_CHROME_ROWS2 = 6;
54454
+ function questionsBodyRows(rows, noticeRows = 0) {
54455
+ return Math.max(1, rows - PANE_CHROME_ROWS2 - Math.max(0, noticeRows));
54456
+ }
54457
+ function recordAt(run, index) {
54458
+ return run.questions[index];
54459
+ }
54460
+ function openQuestions(run, recorded = initialQuestions.recorded) {
54461
+ if (run.questions.length === 0)
54462
+ return null;
54463
+ const index = run.questions.findIndex((record) => record.status === "unanswered");
54464
+ return { ...initialQuestions, selected: index === -1 ? 0 : index, recorded };
54465
+ }
54466
+ function withRecordedAnswer(recorded, step, question) {
54467
+ const next = new Set(recorded);
54468
+ next.add(recordKey(step, question));
54469
+ return next;
54470
+ }
54471
+ function questionsSelectionOffset(run, selected, offset, rows, composerRows = 0) {
54472
+ const total = run.questions.length * RECORD_BLOCK_ROWS;
54473
+ const size = Math.max(1, questionsBodyRows(rows) - composerRows);
54474
+ return selectedWindowOffset(offset, selected, total, size);
54475
+ }
54476
+ function selectedWindowOffset(offset, selected, total, size) {
54477
+ const start = selected * RECORD_BLOCK_ROWS;
54478
+ const end = start + RECORD_BLOCK_ROWS;
54479
+ const next = nextOffset(offset, start, total, size);
54480
+ return end > next + size ? clampOffset(end - size, total, size) : next;
54481
+ }
54482
+ function selectRecord(run, state, index, rows) {
54483
+ if (index === state.selected)
54484
+ return state;
54485
+ const offset = rows === undefined ? state.offset : questionsSelectionOffset(run, index, state.offset, rows);
54486
+ return { ...state, selected: index, offset, notice: null };
54487
+ }
54488
+ function append(state, text) {
54489
+ return { ...state, text: state.text + text, notice: null };
54490
+ }
54491
+ function removeLast(state) {
54492
+ return { ...state, text: Array.from(state.text).slice(0, -1).join(""), notice: null };
54493
+ }
54494
+ function questionsKeys(run, state, input, key, rows) {
54495
+ const record = recordAt(run, state.selected);
54496
+ if (key.escape) {
54497
+ if (state.focus === "composer") {
54498
+ return { state: { ...state, focus: "record", text: "", notice: null } };
54499
+ }
54500
+ return { state, close: true };
54501
+ }
54502
+ if (state.focus === "record") {
54503
+ if (key.upArrow || !key.ctrl && input === "k") {
54504
+ return { state: selectRecord(run, state, Math.max(0, state.selected - 1), rows) };
54505
+ }
54506
+ if (key.downArrow || !key.ctrl && input === "j") {
54507
+ return {
54508
+ state: selectRecord(run, state, Math.min(run.questions.length - 1, state.selected + 1), rows)
54509
+ };
54510
+ }
54511
+ if (key.return) {
54512
+ if (record === undefined || record.status !== "unanswered")
54513
+ return { state };
54514
+ if (state.recorded.has(recordKey(record.step, record.question)))
54515
+ return { state };
54516
+ const offset = rows === undefined ? state.offset : questionsSelectionOffset(run, state.selected, state.offset, rows, 1);
54517
+ return { state: { ...state, focus: "composer", text: "", offset, notice: null } };
54518
+ }
54519
+ return { state };
54520
+ }
54521
+ if (key.ctrl && (input === "j" || input === `
54522
+ ` || input === "\r")) {
54523
+ return { state: append(state, `
54524
+ `) };
54525
+ }
53843
54526
  if (key.return) {
53844
- if (record === undefined)
54527
+ if (record === undefined || record.status !== "unanswered")
53845
54528
  return { state };
53846
- if (state.draft === null) {
53847
- const draft = draftFor(record);
53848
- return draft === null ? { state } : { state: { ...state, draft, notice: null } };
53849
- }
53850
- if (state.draft.recorded)
54529
+ if (state.recorded.has(recordKey(record.step, record.question)))
53851
54530
  return { state };
53852
- const text = state.draft.text.trim();
53853
- if (text === "")
54531
+ const answer = state.text.trim();
54532
+ if (answer === "")
53854
54533
  return { state: { ...state, notice: "the answer is empty" } };
53855
- if (record.status !== "unanswered")
53856
- return { state };
53857
- return { state, answer: { answer: text, question: record.question } };
54534
+ return {
54535
+ state,
54536
+ answer: { answer, question: record.question, rawQuestion: record.rawQuestion }
54537
+ };
53858
54538
  }
53859
- if (state.draft === null)
53860
- return { state };
53861
- if (key.backspace)
54539
+ if (deletesLast(key))
53862
54540
  return { state: removeLast(state) };
53863
- if (key.tab || key.ctrl || key.meta || input.length === 0)
54541
+ if (key.upArrow || key.downArrow || key.pageUp || key.pageDown)
54542
+ return { state };
54543
+ const typed = stripControls(input);
54544
+ if (key.tab || key.ctrl || key.meta || typed.length === 0)
53864
54545
  return { state };
53865
- return { state: append(state, input) };
54546
+ return { state: append(state, typed) };
53866
54547
  }
53867
- function dash3(glyphs) {
53868
- return glyphs.bullet === "-" ? "-" : "—";
54548
+ function recordAnswerInState(run, state, step, question, rows) {
54549
+ const recorded = withRecordedAnswer(state.recorded, step, question);
54550
+ const next = run.questions.findIndex((record, index) => index > state.selected && record.status === "unanswered");
54551
+ const selected = next === -1 ? state.selected : next;
54552
+ const offset = rows === undefined ? state.offset : questionsSelectionOffset(run, selected, state.offset, rows);
54553
+ return {
54554
+ ...state,
54555
+ selected,
54556
+ focus: "record",
54557
+ text: "",
54558
+ offset,
54559
+ recorded,
54560
+ notice: null
54561
+ };
53869
54562
  }
53870
54563
  function recordedLabel(glyphs) {
53871
54564
  return glyphs.bullet === "-" ? answerRecorded.replace("—", "-") : answerRecorded;
@@ -53873,7 +54566,7 @@ function recordedLabel(glyphs) {
53873
54566
  function marker(selected, glyphs) {
53874
54567
  return selected ? glyphs.focus : " ";
53875
54568
  }
53876
- function statusGlyph(record, glyphs) {
54569
+ function statusGlyph2(record, glyphs) {
53877
54570
  switch (record.status) {
53878
54571
  case "answered":
53879
54572
  return glyphs.passed;
@@ -53890,27 +54583,19 @@ function statusGlyph(record, glyphs) {
53890
54583
  function recordLines(record, index, state, glyphs) {
53891
54584
  const selected = index === state.selected;
53892
54585
  const lines = [
53893
- `${marker(selected, glyphs)} ${statusGlyph(record, glyphs)} ${record.step}`,
54586
+ `${marker(selected, glyphs)} ${statusGlyph2(record, glyphs)} ${record.step}`,
53894
54587
  ` ${record.question}`
53895
54588
  ];
53896
54589
  switch (record.status) {
53897
54590
  case "answered":
53898
- lines.push(record.answer === undefined ? " answered" : ` answered ${dash3(glyphs)} ${record.answer}`);
54591
+ lines.push(record.answer === undefined ? " answered" : ` answered ${dash(glyphs)} ${record.answer}`);
53899
54592
  break;
53900
54593
  case "skipped":
53901
54594
  lines.push(" skipped");
53902
54595
  break;
53903
- case "unanswered": {
53904
- const draft = selected ? state.draft : null;
53905
- if (draft?.recorded === true) {
53906
- lines.push(` ${recordedLabel(glyphs)}`);
53907
- } else {
53908
- lines.push(` unanswered ${dash3(glyphs)} Enter answers`);
53909
- if (draft !== null)
53910
- lines.push(` answer> ${draft.text}`);
53911
- }
54596
+ case "unanswered":
54597
+ lines.push(state.recorded.has(recordKey(record.step, record.question)) ? ` ${recordedLabel(glyphs)}` : ` unanswered ${dash(glyphs)} Enter answers`);
53912
54598
  break;
53913
- }
53914
54599
  default: {
53915
54600
  const unhandled = record.status;
53916
54601
  throw new Error(`unknown question status: ${String(unhandled)}`);
@@ -53918,113 +54603,390 @@ function recordLines(record, index, state, glyphs) {
53918
54603
  }
53919
54604
  return lines;
53920
54605
  }
54606
+ function composerLines(text) {
54607
+ return text.split(`
54608
+ `).map((line, index) => index === 0 ? `answer> ${line}` : ` ${line}`);
54609
+ }
54610
+ function footerKeys(run, state) {
54611
+ if (state.focus === "composer") {
54612
+ return [
54613
+ keyHint("Ctrl-J", "newline"),
54614
+ keyHint("Enter", "record"),
54615
+ keyHint("Esc", "leaves the composer to navigate")
54616
+ ];
54617
+ }
54618
+ const keys = [keyHint("j/k", "navigate")];
54619
+ const record = run.questions[state.selected];
54620
+ if (record?.status === "unanswered" && !state.recorded.has(recordKey(record.step, record.question))) {
54621
+ keys.push(keyHint("Enter", "answer"));
54622
+ }
54623
+ keys.push(keyHint("Esc", "close"));
54624
+ return keys;
54625
+ }
53921
54626
  function questionsPanel(input) {
53922
- const { run, state, glyphs } = input;
54627
+ const { run, state, glyphs, rows } = input;
53923
54628
  const questionsFile = run.questions[0]?.questionsFile ?? `openspec/changes/${run.id}/questions.md`;
53924
- const lines = [questionsFile];
53925
- run.questions.forEach((record, index) => {
53926
- lines.push(...recordLines(record, index, state, glyphs));
53927
- });
53928
- const selected = run.questions[state.selected];
53929
- const canAnswer = selected?.status === "unanswered";
53930
- const keys = canAnswer ? [keyHint("Enter", "answer"), keyHint("Esc", "close")] : [keyHint("Esc", "close")];
54629
+ const composer = state.focus === "composer" ? composerLines(state.text) : [];
54630
+ const blocks = run.questions.map((record, index) => recordLines(record, index, state, glyphs));
54631
+ let lines;
54632
+ if (rows === undefined) {
54633
+ lines = [questionsFile, ...blocks.flat(), ...composer];
54634
+ } else {
54635
+ const flat = blocks.flat();
54636
+ const bodyRows = questionsBodyRows(rows, state.notice === null ? 0 : 1);
54637
+ const composerRows = Math.min(composer.length, Math.max(0, bodyRows - 1));
54638
+ const shownComposer = composerRows === 0 ? [] : composer.slice(composer.length - composerRows);
54639
+ const recordRows = Math.max(1, bodyRows - shownComposer.length);
54640
+ const offset = selectedWindowOffset(state.offset, state.selected, flat.length, recordRows);
54641
+ lines = [
54642
+ questionsFile,
54643
+ ...sliceWindow(flat, window2(offset, flat.length, recordRows)),
54644
+ ...shownComposer
54645
+ ];
54646
+ }
53931
54647
  return {
53932
54648
  kind: "questions",
53933
- title: `Questions ${dash3(glyphs)} ${run.id}`,
54649
+ title: `Questions ${dash(glyphs)} ${run.id}`,
53934
54650
  lines,
53935
- keys,
54651
+ keys: footerKeys(run, state),
53936
54652
  notice: state.notice
53937
54653
  };
53938
54654
  }
53939
54655
 
53940
- // packages/tui/src/help.ts
53941
- var HELP_LINES = [
53942
- "n start a new change",
53943
- "Tab intake text/file mode",
53944
- "Enter open the selected run or task; confirm",
53945
- "Esc back out of a panel; cancel",
53946
- "j / k move the selection",
53947
- "a approve and run",
53948
- "A approve only",
53949
- "w reword",
53950
- "R reapprove",
53951
- "r resume",
53952
- "x abort",
53953
- "t retry the selected failed task",
53954
- "Q questions",
53955
- "? help",
53956
- "q quit"
53957
- ];
53958
- function helpPanel() {
54656
+ // packages/tui/src/theme/env.ts
54657
+ function terminalEnv(source) {
54658
+ if (source === undefined)
54659
+ return {};
53959
54660
  return {
53960
- kind: "help",
53961
- title: "Help",
53962
- lines: HELP_LINES,
53963
- keys: [keyHint("Esc", "close"), keyHint("q", "quit")],
53964
- notice: null
54661
+ ...source.TERM === undefined ? {} : { TERM: source.TERM },
54662
+ ...source.COLORTERM === undefined ? {} : { COLORTERM: source.COLORTERM },
54663
+ ...source.NO_COLOR === undefined ? {} : { NO_COLOR: source.NO_COLOR },
54664
+ ...source.LANG === undefined ? {} : { LANG: source.LANG },
54665
+ ...source.LC_ALL === undefined ? {} : { LC_ALL: source.LC_ALL },
54666
+ ...source.LC_CTYPE === undefined ? {} : { LC_CTYPE: source.LC_CTYPE }
53965
54667
  };
53966
54668
  }
53967
- function helpKeys(input, key) {
53968
- if (key.escape)
53969
- return "close";
53970
- if (!key.ctrl && input === "q")
53971
- return "quit";
53972
- return "none";
53973
- }
53974
-
53975
- // packages/tui/src/intake/paths.ts
53976
- import {
53977
- accessSync,
53978
- closeSync as closeSync3,
53979
- constants as constants2,
53980
- openSync as openSync3,
53981
- readdirSync as readdirSync13,
53982
- readSync as readSync2,
53983
- statSync as statSync9
53984
- } from "node:fs";
53985
- import { homedir } from "node:os";
53986
- import { basename as basename2, dirname as dirname10, isAbsolute as isAbsolute3, join as join38, resolve as resolve5, sep as sep2 } from "node:path";
53987
- function expandTilde(input) {
53988
- if (input === "~")
53989
- return homedir();
53990
- if (input.startsWith("~/"))
53991
- return join38(homedir(), input.slice(2));
53992
- return input;
53993
- }
53994
- function isDirectory(path) {
53995
- try {
53996
- return statSync9(path).isDirectory();
53997
- } catch {
53998
- return false;
54669
+ function localeOf(env) {
54670
+ for (const value of [env.LC_ALL, env.LC_CTYPE, env.LANG]) {
54671
+ if (value !== undefined && value !== "")
54672
+ return value;
53999
54673
  }
54674
+ return;
54000
54675
  }
54001
- function joinDisplay(dir, name) {
54002
- if (dir === "")
54003
- return name;
54004
- return dir.endsWith("/") ? `${dir}${name}` : `${dir}/${name}`;
54005
- }
54006
- function allowedUnderFactory(absolute, cwd) {
54007
- const requests = join38(cwd, ".factory", "requests");
54008
- if (absolute === requests)
54676
+ function isUtf8Locale(env) {
54677
+ const locale = localeOf(env);
54678
+ if (locale === undefined)
54009
54679
  return true;
54010
- return absolute.startsWith(`${requests}${sep2}`) && absolute.endsWith(".md");
54011
- }
54012
- function blockedByFactory(absolute, cwd) {
54013
- const factory = join38(cwd, ".factory");
54014
- const inside = absolute === factory || absolute.startsWith(`${factory}${sep2}`);
54015
- return inside && !allowedUnderFactory(absolute, cwd);
54016
- }
54017
- function rankOf(candidate, cwd) {
54018
- const requests = join38(cwd, ".factory", "requests");
54019
- return candidate.absolute.startsWith(`${requests}${sep2}`) && candidate.absolute.endsWith(".md") ? 0 : 1;
54020
- }
54021
- function byRequestThenPath(cwd) {
54022
- return (a, b) => {
54023
- const rank = rankOf(a, cwd) - rankOf(b, cwd);
54024
- if (rank !== 0)
54025
- return rank;
54026
- return a.path < b.path ? -1 : a.path > b.path ? 1 : 0;
54027
- };
54680
+ return /utf-?8/i.test(locale);
54681
+ }
54682
+ function detectColorDepth(env, isTTY) {
54683
+ if (!isTTY)
54684
+ return "none";
54685
+ if (env.NO_COLOR !== undefined)
54686
+ return "none";
54687
+ if (env.TERM === "dumb")
54688
+ return "none";
54689
+ const colorterm = env.COLORTERM;
54690
+ if (colorterm !== undefined && /truecolor|24bit/i.test(colorterm))
54691
+ return "truecolor";
54692
+ const term = env.TERM;
54693
+ if (term !== undefined && /256color/i.test(term))
54694
+ return "256";
54695
+ return "16";
54696
+ }
54697
+
54698
+ // packages/tui/src/theme/glyphs.ts
54699
+ var UNICODE_GLYPHS = {
54700
+ passed: "✔",
54701
+ failed: "✖",
54702
+ blocked: "▲",
54703
+ running: "▶",
54704
+ pending: "○",
54705
+ merged: "●",
54706
+ skipped: "–",
54707
+ focus: "›",
54708
+ arrow: "→",
54709
+ bullet: "•",
54710
+ approval: "!"
54711
+ };
54712
+ var ASCII_GLYPHS = {
54713
+ passed: "+",
54714
+ failed: "x",
54715
+ blocked: "!",
54716
+ running: ">",
54717
+ pending: "o",
54718
+ merged: "*",
54719
+ skipped: "-",
54720
+ focus: ">",
54721
+ arrow: ">",
54722
+ bullet: "-",
54723
+ approval: "!"
54724
+ };
54725
+ function glyphsFor(options) {
54726
+ if (typeof options === "boolean")
54727
+ return options ? ASCII_GLYPHS : UNICODE_GLYPHS;
54728
+ if (options.ascii || options.env.TERM === "dumb" || !isUtf8Locale(options.env)) {
54729
+ return ASCII_GLYPHS;
54730
+ }
54731
+ return UNICODE_GLYPHS;
54732
+ }
54733
+
54734
+ // packages/tui/src/controls/reword.ts
54735
+ var REWORD_PROMPT_REQUIRED = "the prompt is required";
54736
+ var initialReword = {
54737
+ text: "",
54738
+ offset: 0,
54739
+ notice: null,
54740
+ failure: null
54741
+ };
54742
+ function openReword(run) {
54743
+ return run.reword.state === "available" ? { ...initialReword } : null;
54744
+ }
54745
+ function findingLocation(finding) {
54746
+ if (finding.file === null)
54747
+ return "";
54748
+ return finding.line === null ? finding.file : `${finding.file}:${finding.line}`;
54749
+ }
54750
+ function chunks(text, width) {
54751
+ const points = Array.from(text);
54752
+ if (points.length === 0)
54753
+ return [""];
54754
+ const out = [];
54755
+ for (let at = 0;at < points.length; at += width) {
54756
+ out.push(points.slice(at, at + width).join(""));
54757
+ }
54758
+ return out;
54759
+ }
54760
+ function wrapped(prefix, text, columns) {
54761
+ const width = Math.max(1, Math.max(20, columns - 6) - prefix.length);
54762
+ return chunks(text, width).map((chunk, index) => `${index === 0 ? prefix : " ".repeat(prefix.length)}${chunk}`);
54763
+ }
54764
+ function promptLines(text, columns) {
54765
+ return text.split(`
54766
+ `).flatMap((line, index) => wrapped(index === 0 ? "prompt> " : " ", line, columns));
54767
+ }
54768
+ function rewordArgvLine(run, text, glyphs = UNICODE_GLYPHS) {
54769
+ const trimmed = text.trim();
54770
+ if (trimmed === "")
54771
+ return `reword ${run.id} --prompt <text>`;
54772
+ const [first = "", ...rest] = trimmed.split(`
54773
+ `);
54774
+ const mark = glyphs.bullet === "-" ? "..." : "…";
54775
+ return `reword ${run.id} --prompt ${rest.length === 0 ? first : `${first}${mark}`}`;
54776
+ }
54777
+ function findingLines(finding, index, columns) {
54778
+ const location = findingLocation(finding);
54779
+ const header = `${index + 1}. ${finding.severity}${location === "" ? "" : ` ${location}`}`;
54780
+ return [
54781
+ header,
54782
+ ...wrapped(" problem: ", finding.problem, columns),
54783
+ ...wrapped(" fix: ", finding.fix, columns)
54784
+ ];
54785
+ }
54786
+ function bodyLines(run, state, columns, glyphs = UNICODE_GLYPHS) {
54787
+ return [
54788
+ ...run.specFindings.flatMap((finding, index) => findingLines(finding, index, columns)),
54789
+ ...promptLines(state.text, columns),
54790
+ rewordArgvLine(run, state.text, glyphs)
54791
+ ];
54792
+ }
54793
+ function failureLines(failure) {
54794
+ if (failure === null)
54795
+ return [];
54796
+ return [
54797
+ `exited with code ${failure.code}`,
54798
+ ...failure.logPath === null ? [] : [`spawn log: ${failure.logPath}`],
54799
+ ...failure.lines
54800
+ ];
54801
+ }
54802
+ var PANEL_CHROME_ROWS = 5;
54803
+ function bodyRows(rows, state) {
54804
+ const noticeRows = state.notice === null ? 0 : state.notice.split(`
54805
+ `).length;
54806
+ return Math.max(1, rows - PANEL_CHROME_ROWS - noticeRows - failureLines(state.failure).length);
54807
+ }
54808
+ function move(run, state, delta, rows, columns) {
54809
+ const length = bodyLines(run, state, columns).length;
54810
+ const offset = clampOffset(state.offset + delta, length, bodyRows(rows, state));
54811
+ return offset === state.offset ? state : { ...state, offset };
54812
+ }
54813
+ function removeLast2(state) {
54814
+ return {
54815
+ ...state,
54816
+ text: Array.from(state.text).slice(0, -1).join(""),
54817
+ notice: null
54818
+ };
54819
+ }
54820
+ function followPrompt(run, state, rows, columns) {
54821
+ const length = bodyLines(run, state, columns).length;
54822
+ const offset = lastOffset(length, bodyRows(rows, state));
54823
+ return offset === state.offset ? state : { ...state, offset };
54824
+ }
54825
+ function rewordKeys(run, state, input, key, rows, columns = 80) {
54826
+ if (key.escape)
54827
+ return { state, close: true };
54828
+ if (key.return) {
54829
+ const prompt = state.text.trim();
54830
+ if (run.specFindings.length === 0 && prompt === "") {
54831
+ return { state: { ...state, notice: REWORD_PROMPT_REQUIRED } };
54832
+ }
54833
+ return { state, launch: prompt === "" ? {} : { prompt } };
54834
+ }
54835
+ if (key.upArrow)
54836
+ return { state: move(run, state, -1, rows, columns) };
54837
+ if (key.downArrow)
54838
+ return { state: move(run, state, 1, rows, columns) };
54839
+ if (key.pageUp) {
54840
+ return { state: move(run, state, -pageSize(bodyRows(rows, state)), rows, columns) };
54841
+ }
54842
+ if (key.pageDown) {
54843
+ return { state: move(run, state, pageSize(bodyRows(rows, state)), rows, columns) };
54844
+ }
54845
+ if (key.ctrl && (input === "j" || input === `
54846
+ `)) {
54847
+ return {
54848
+ state: followPrompt(run, { ...state, text: `${state.text}
54849
+ `, notice: null }, rows, columns)
54850
+ };
54851
+ }
54852
+ if (deletesLast(key))
54853
+ return { state: followPrompt(run, removeLast2(state), rows, columns) };
54854
+ if (key.ctrl || key.meta || key.tab)
54855
+ return { state };
54856
+ const typed = stripControls(input);
54857
+ if (typed.length === 0)
54858
+ return { state };
54859
+ return {
54860
+ state: followPrompt(run, { ...state, text: state.text + typed, notice: null }, rows, columns)
54861
+ };
54862
+ }
54863
+ function dash4(glyphs) {
54864
+ return glyphs.bullet === "-" ? "-" : "—";
54865
+ }
54866
+ function scrollKey(glyphs) {
54867
+ return glyphs.bullet === "-" ? "Up/Down PgUp/PgDn" : "↑/↓ PgUp/PgDn";
54868
+ }
54869
+ function keysFor(run, state, glyphs) {
54870
+ const missingPrompt = run.specFindings.length === 0 && state.text.trim() === "";
54871
+ const confirm = missingPrompt ? {
54872
+ key: "Enter",
54873
+ label: "confirm",
54874
+ enabled: false,
54875
+ reason: REWORD_PROMPT_REQUIRED
54876
+ } : keyHint("Enter", "confirm");
54877
+ return [
54878
+ keyHint("Ctrl-J", "newline"),
54879
+ confirm,
54880
+ keyHint("Esc", "back"),
54881
+ keyHint(scrollKey(glyphs), "scroll")
54882
+ ];
54883
+ }
54884
+ function rewordPanel(input) {
54885
+ const { run, state, glyphs, rows, columns } = input;
54886
+ const body = bodyLines(run, state, columns, glyphs);
54887
+ const size = bodyRows(rows, state);
54888
+ const shown = sliceWindow(body, window2(clampOffset(state.offset, body.length, size), body.length, size));
54889
+ return {
54890
+ kind: "reword",
54891
+ title: `Reword ${dash4(glyphs)} ${run.id}`,
54892
+ lines: [...shown, ...failureLines(state.failure)],
54893
+ keys: keysFor(run, state, glyphs),
54894
+ notice: state.notice
54895
+ };
54896
+ }
54897
+
54898
+ // packages/tui/src/help.ts
54899
+ var HELP_LINES = [
54900
+ "n start a new change",
54901
+ "Tab intake text/file mode",
54902
+ "Tab cycle the log scope",
54903
+ "Enter open the selected run or task; confirm",
54904
+ "Esc back out of a panel; cancel",
54905
+ "j / k move the selection",
54906
+ "PgUp / PgDn page; g / G first or last",
54907
+ "L open the activity log; f toggle log follow",
54908
+ "a approve and run",
54909
+ "A approve only",
54910
+ "w reword",
54911
+ "R reapprove",
54912
+ "r resume",
54913
+ "x abort",
54914
+ "t retry the selected failed task",
54915
+ "l land a done run",
54916
+ "Q questions",
54917
+ "? help",
54918
+ "q quit"
54919
+ ];
54920
+ function helpPanel() {
54921
+ return {
54922
+ kind: "help",
54923
+ title: "Help",
54924
+ lines: HELP_LINES,
54925
+ keys: [keyHint("Esc", "close"), keyHint("q", "quit")],
54926
+ notice: null
54927
+ };
54928
+ }
54929
+ function helpKeys(input, key) {
54930
+ if (key.escape)
54931
+ return "close";
54932
+ if (!key.ctrl && input === "q")
54933
+ return "quit";
54934
+ return "none";
54935
+ }
54936
+
54937
+ // packages/tui/src/intake/paths.ts
54938
+ import {
54939
+ accessSync,
54940
+ closeSync as closeSync3,
54941
+ constants as constants2,
54942
+ openSync as openSync3,
54943
+ readdirSync as readdirSync13,
54944
+ readSync as readSync2,
54945
+ statSync as statSync9
54946
+ } from "node:fs";
54947
+ import { homedir } from "node:os";
54948
+ import { basename as basename2, dirname as dirname10, isAbsolute as isAbsolute3, join as join38, resolve as resolve5, sep as sep2 } from "node:path";
54949
+ function expandTilde(input) {
54950
+ if (input === "~")
54951
+ return homedir();
54952
+ if (input.startsWith("~/"))
54953
+ return join38(homedir(), input.slice(2));
54954
+ return input;
54955
+ }
54956
+ function isDirectory(path) {
54957
+ try {
54958
+ return statSync9(path).isDirectory();
54959
+ } catch {
54960
+ return false;
54961
+ }
54962
+ }
54963
+ function joinDisplay(dir, name) {
54964
+ if (dir === "")
54965
+ return name;
54966
+ return dir.endsWith("/") ? `${dir}${name}` : `${dir}/${name}`;
54967
+ }
54968
+ function allowedUnderFactory(absolute, cwd) {
54969
+ const requests = join38(cwd, ".factory", "requests");
54970
+ if (absolute === requests)
54971
+ return true;
54972
+ return absolute.startsWith(`${requests}${sep2}`) && absolute.endsWith(".md");
54973
+ }
54974
+ function blockedByFactory(absolute, cwd) {
54975
+ const factory = join38(cwd, ".factory");
54976
+ const inside = absolute === factory || absolute.startsWith(`${factory}${sep2}`);
54977
+ return inside && !allowedUnderFactory(absolute, cwd);
54978
+ }
54979
+ function rankOf(candidate, cwd) {
54980
+ const requests = join38(cwd, ".factory", "requests");
54981
+ return candidate.absolute.startsWith(`${requests}${sep2}`) && candidate.absolute.endsWith(".md") ? 0 : 1;
54982
+ }
54983
+ function byRequestThenPath(cwd) {
54984
+ return (a, b) => {
54985
+ const rank = rankOf(a, cwd) - rankOf(b, cwd);
54986
+ if (rank !== 0)
54987
+ return rank;
54988
+ return a.path < b.path ? -1 : a.path > b.path ? 1 : 0;
54989
+ };
54028
54990
  }
54029
54991
  function completePath(input, cwd) {
54030
54992
  const expanded = expandTilde(input);
@@ -54170,7 +55132,7 @@ function editFile(state, chunk, ctx) {
54170
55132
  error: null
54171
55133
  };
54172
55134
  }
54173
- function removeLast2(state, ctx) {
55135
+ function removeLast3(state, ctx) {
54174
55136
  if (state.mode === "text") {
54175
55137
  return { ...state, text: state.text.slice(0, -1), error: null };
54176
55138
  }
@@ -54216,18 +55178,36 @@ function intakeKeys(state, input, key, ctx) {
54216
55178
  return state.mode === "text" ? { state: { ...state, text: `${state.text}
54217
55179
  `, error: null } } : { state };
54218
55180
  }
54219
- if (key.backspace)
54220
- return { state: removeLast2(state, ctx) };
54221
- if (key.escape || input.length === 0)
55181
+ if (deletesLast(key))
55182
+ return { state: removeLast3(state, ctx) };
55183
+ if (key.escape)
54222
55184
  return { state };
54223
- return state.mode === "text" ? { state: { ...state, text: state.text + input, error: null } } : { state: editFile(state, input, ctx) };
55185
+ const typed = stripControls(input);
55186
+ if (typed.length === 0)
55187
+ return { state };
55188
+ return state.mode === "text" ? { state: { ...state, text: state.text + typed, error: null } } : { state: editFile(state, typed, ctx) };
54224
55189
  }
54225
55190
  function title(state, glyphs) {
54226
55191
  const dash = glyphs.bullet === "-" ? "-" : "—";
54227
55192
  return `New change ${dash} ${state.mode}`;
54228
55193
  }
54229
- var PANEL_CHROME_ROWS = 5;
55194
+ var PANEL_CHROME_ROWS2 = 5;
54230
55195
  var PREVIEW_HEADER_ROWS = 3;
55196
+ function requestLines(state, rows, trailing) {
55197
+ if (state.text === "")
55198
+ return ["request: (empty)"];
55199
+ if (!state.text.includes(`
55200
+ `))
55201
+ return [`request: ${state.text}`];
55202
+ const all = state.text.split(`
55203
+ `);
55204
+ const room = Math.max(0, rows - PANEL_CHROME_ROWS2 - trailing);
55205
+ if (room === 0)
55206
+ return [];
55207
+ const shown = all.slice(0, room - 1);
55208
+ const label = shown.length < all.length ? `request (${shown.length} of ${all.length} lines):` : `request (${all.length} lines):`;
55209
+ return [label, ...shown.map((line) => ` | ${line}`)];
55210
+ }
54231
55211
  function fileLines(state, glyphs, rows, trailing) {
54232
55212
  if (state.file === null) {
54233
55213
  const lines = [`path: ${state.path === "" ? "(type a path)" : state.path}`];
@@ -54237,7 +55217,7 @@ function fileLines(state, glyphs, rows, trailing) {
54237
55217
  }
54238
55218
  return lines;
54239
55219
  }
54240
- const limit = Math.max(0, rows - PANEL_CHROME_ROWS - PREVIEW_HEADER_ROWS - trailing);
55220
+ const limit = Math.max(0, rows - PANEL_CHROME_ROWS2 - PREVIEW_HEADER_ROWS - trailing);
54241
55221
  const shown = state.file.preview.slice(0, limit);
54242
55222
  const label = shown.length < state.file.preview.length ? `preview (${shown.length} of ${state.file.preview.length} lines):` : `preview (${state.file.preview.length} lines):`;
54243
55223
  return [
@@ -54249,8 +55229,10 @@ function fileLines(state, glyphs, rows, trailing) {
54249
55229
  }
54250
55230
  function intakePanel(state, glyphs, rows = 40) {
54251
55231
  const spawnedRows = state.spawned === null ? 0 : 1 + state.spawned.tail.length;
54252
- const trailing = (state.submitting && state.spawned === null ? 1 : 0) + spawnedRows + (state.queuedNote === null ? 0 : 1);
54253
- const lines = state.mode === "text" ? [state.text === "" ? "request: (empty)" : `request: ${state.text}`] : fileLines(state, glyphs, rows, trailing);
55232
+ const noticeRows = state.error === null ? 0 : state.error.split(`
55233
+ `).length;
55234
+ const trailing = (state.submitting && state.spawned === null ? 1 : 0) + spawnedRows + (state.queuedNote === null ? 0 : 1) + noticeRows;
55235
+ const lines = state.mode === "text" ? requestLines(state, rows, trailing) : fileLines(state, glyphs, rows, trailing);
54254
55236
  if (state.submitting && state.spawned === null)
54255
55237
  lines.push("starting...");
54256
55238
  if (state.spawned !== null) {
@@ -54296,12 +55278,16 @@ function actionArgs(action) {
54296
55278
  return ["approve", action.id];
54297
55279
  case "approve-only":
54298
55280
  return ["approve", action.id, "--no-continue"];
54299
- case "reword":
54300
- return ["reword", action.id];
55281
+ case "reword": {
55282
+ const prompt = action.prompt?.trim() ?? "";
55283
+ return prompt === "" ? ["reword", action.id] : ["reword", action.id, "--prompt", prompt];
55284
+ }
54301
55285
  case "reapprove":
54302
55286
  return ["reapprove", action.id];
54303
55287
  case "resume":
54304
55288
  return ["resume", action.id];
55289
+ case "land":
55290
+ return ["land", action.id];
54305
55291
  default: {
54306
55292
  const unhandled = action;
54307
55293
  throw new Error(`unknown launch action: ${String(unhandled)}`);
@@ -54385,7 +55371,7 @@ function tailLog(logPath, lines = 10) {
54385
55371
  } catch {
54386
55372
  return [];
54387
55373
  }
54388
- const rows = text.split(/\r?\n/u);
55374
+ const rows = text.split(/\r?\n/u).map(stripControls);
54389
55375
  if (rows.at(-1) === "")
54390
55376
  rows.pop();
54391
55377
  return rows.slice(-lines);
@@ -54408,99 +55394,566 @@ class ActivityRing {
54408
55394
  this.count += 1;
54409
55395
  return;
54410
55396
  }
54411
- this.slots[this.start] = line;
54412
- this.start = (this.start + 1) % ACTIVITY_LIMIT;
54413
- }
54414
- toArray() {
54415
- const lines = [];
54416
- for (let index = 0;index < this.count; index += 1) {
54417
- const line = this.slots[(this.start + index) % ACTIVITY_LIMIT];
54418
- if (line !== undefined)
54419
- lines.push(line);
55397
+ this.slots[this.start] = line;
55398
+ this.start = (this.start + 1) % ACTIVITY_LIMIT;
55399
+ }
55400
+ lastIs(kind) {
55401
+ if (this.count === 0)
55402
+ return false;
55403
+ return this.slots[(this.start + this.count - 1) % ACTIVITY_LIMIT]?.kind === kind;
55404
+ }
55405
+ replaceLast(line) {
55406
+ if (this.count === 0) {
55407
+ this.push(line);
55408
+ return;
55409
+ }
55410
+ this.slots[(this.start + this.count - 1) % ACTIVITY_LIMIT] = line;
55411
+ }
55412
+ toArray() {
55413
+ const lines = [];
55414
+ for (let index = 0;index < this.count; index += 1) {
55415
+ const line = this.slots[(this.start + index) % ACTIVITY_LIMIT];
55416
+ if (line !== undefined)
55417
+ lines.push(line);
55418
+ }
55419
+ return lines;
55420
+ }
55421
+ get length() {
55422
+ return this.count;
55423
+ }
55424
+ }
55425
+
55426
+ // packages/tui/src/model/facts.ts
55427
+ function collectFacts(events) {
55428
+ return appendFacts({ gates: {}, agents: {}, retries: {}, activity: [] }, events);
55429
+ }
55430
+ function sourceOf(step) {
55431
+ return step === undefined || step === "" ? "run" : step;
55432
+ }
55433
+ function attemptText(attempt) {
55434
+ return attempt === undefined ? "" : ` (attempt ${attempt})`;
55435
+ }
55436
+ function isRef2(value) {
55437
+ return typeof value === "object" && value !== null && "path" in value && typeof value.path === "string";
55438
+ }
55439
+ function refOf(data) {
55440
+ if (typeof data !== "object" || data === null)
55441
+ return;
55442
+ if ("ref" in data && isRef2(data.ref))
55443
+ return data.ref.path;
55444
+ if ("outputRef" in data && isRef2(data.outputRef))
55445
+ return data.outputRef.path;
55446
+ return;
55447
+ }
55448
+ function duration3(ms) {
55449
+ return ms >= 1000 ? `${(ms / 1000).toFixed(1)}s` : `${Math.round(ms)}ms`;
55450
+ }
55451
+ function line(event, step, kind, text) {
55452
+ const logRef = refOf(event.data);
55453
+ return {
55454
+ seq: event.seq,
55455
+ step: flat(step),
55456
+ kind,
55457
+ text: flat(text),
55458
+ ...logRef === undefined ? {} : { logRef: flat(logRef) }
55459
+ };
55460
+ }
55461
+ function appendFacts(prior, events) {
55462
+ const gates = {};
55463
+ for (const [step, rows] of Object.entries(prior.gates))
55464
+ gates[step] = [...rows];
55465
+ const agents = { ...prior.agents };
55466
+ const retries = { ...prior.retries };
55467
+ const activity = new ActivityRing(prior.activity);
55468
+ const bump = (key) => {
55469
+ retries[key] = (retries[key] ?? 0) + 1;
55470
+ };
55471
+ for (const event of events) {
55472
+ switch (event.type) {
55473
+ case "gate.finished": {
55474
+ const step = flat(event.data.step ?? "");
55475
+ const row = {
55476
+ step,
55477
+ name: flat(event.data.name),
55478
+ type: event.data.type,
55479
+ status: event.data.status,
55480
+ durationMs: event.data.durationMs
55481
+ };
55482
+ const rows = gates[step];
55483
+ if (rows === undefined) {
55484
+ gates[step] = [row];
55485
+ } else {
55486
+ const index = rows.findIndex((existing) => existing.name === row.name);
55487
+ if (index === -1)
55488
+ rows.push(row);
55489
+ else
55490
+ rows[index] = row;
55491
+ }
55492
+ activity.push(line(event, sourceOf(event.data.step), "gate", `${event.data.name} ${event.data.status} in ${duration3(event.data.durationMs)}`));
55493
+ break;
55494
+ }
55495
+ case "agent.started":
55496
+ agents[flat(event.data.step)] = {
55497
+ role: flat(event.data.agent),
55498
+ model: flat(event.data.model),
55499
+ durationMs: null
55500
+ };
55501
+ activity.push(line(event, sourceOf(event.data.step), "agent", `${event.data.agent} started on ${event.data.model}${event.data.label === undefined ? "" : ` (${event.data.label})`}`));
55502
+ break;
55503
+ case "agent.finished": {
55504
+ const step = flat(event.data.step);
55505
+ const priorAgent = agents[step];
55506
+ agents[step] = {
55507
+ role: flat(event.data.role),
55508
+ model: priorAgent?.model ?? "",
55509
+ durationMs: event.data.durationMs
55510
+ };
55511
+ activity.push(line(event, sourceOf(event.data.step), "agent", `${event.data.role} ${event.data.outcome} in ${duration3(event.data.durationMs)}${event.data.problem === undefined ? "" : `: ${event.data.problem}`}`));
55512
+ break;
55513
+ }
55514
+ case "agent.retry":
55515
+ bump(flat(event.data.step));
55516
+ activity.push(line(event, sourceOf(event.data.step), "agent", `retry${event.data.reason === undefined ? "" : `: ${event.data.reason}`}`));
55517
+ break;
55518
+ case "task.retried":
55519
+ bump(flat(event.data.task.id));
55520
+ activity.push(line(event, sourceOf(event.data.task.id), "task", `retried${attemptText(event.data.attempt)}${event.data.reason === undefined ? "" : `: ${event.data.reason}`}`));
55521
+ break;
55522
+ case "agent.activity": {
55523
+ const ref = event.data.ref?.path;
55524
+ activity.push({
55525
+ seq: event.seq,
55526
+ step: flat(event.data.step),
55527
+ kind: event.data.kind,
55528
+ text: flat(event.data.detail),
55529
+ ...ref === undefined ? {} : { logRef: flat(ref) }
55530
+ });
55531
+ break;
55532
+ }
55533
+ case "run.started":
55534
+ activity.push(line(event, "run", "run", `started in ${event.data.phase}`));
55535
+ break;
55536
+ case "run.finished":
55537
+ activity.push(line(event, "run", "run", `finished: ${event.data.outcome}`));
55538
+ break;
55539
+ case "run.paused":
55540
+ activity.push(line(event, "run", "run", `paused: ${event.data.reason}`));
55541
+ break;
55542
+ case "run.resumed":
55543
+ activity.push(line(event, "run", "run", "resumed"));
55544
+ break;
55545
+ case "run.aborted":
55546
+ activity.push(line(event, "run", "run", "aborted"));
55547
+ break;
55548
+ case "run.branches": {
55549
+ const branches = Object.entries(event.data.branches).map(([name, info]) => `${name} (base ${info.base})`);
55550
+ activity.push(line(event, "run", "run", branches.length === 0 ? "branches: none" : `branches: ${branches.join(", ")}`));
55551
+ break;
55552
+ }
55553
+ case "run.pause-requested":
55554
+ activity.push(line(event, "run", "run", event.data.reason === undefined ? "pause requested" : `pause requested: ${event.data.reason}`));
55555
+ break;
55556
+ case "phase.changed":
55557
+ activity.push(line(event, "run", "phase", `${event.data.from ?? "start"} -> ${event.data.to}${event.data.reason === undefined ? "" : `: ${event.data.reason}`}`));
55558
+ break;
55559
+ case "task.queued":
55560
+ activity.push(line(event, sourceOf(event.data.task.id), "task", `queued${attemptText(event.data.attempt)}`));
55561
+ break;
55562
+ case "task.started":
55563
+ activity.push(line(event, sourceOf(event.data.task.id), "task", `started${attemptText(event.data.attempt)}`));
55564
+ break;
55565
+ case "task.passed":
55566
+ activity.push(line(event, sourceOf(event.data.task.id), "task", `passed${attemptText(event.data.attempt)}`));
55567
+ break;
55568
+ case "task.failed":
55569
+ activity.push(line(event, sourceOf(event.data.task.id), "task", `failed: ${event.data.reason}${attemptText(event.data.attempt)}`));
55570
+ break;
55571
+ case "task.blocked":
55572
+ activity.push(line(event, sourceOf(event.data.task.id), "task", `blocked: ${event.data.reason}`));
55573
+ break;
55574
+ case "task.skipped":
55575
+ activity.push(line(event, sourceOf(event.data.task.id), "task", `skipped${event.data.reason === undefined ? "" : `: ${event.data.reason}`}`));
55576
+ break;
55577
+ case "task.merging":
55578
+ activity.push(line(event, sourceOf(event.data.task.id), "task", "merging"));
55579
+ break;
55580
+ case "task.merged":
55581
+ activity.push(line(event, sourceOf(event.data.task.id), "task", `merged ${event.data.commit}`));
55582
+ break;
55583
+ case "task.conflict":
55584
+ activity.push(line(event, sourceOf(event.data.task.id), "task", `conflict: ${event.data.files.join(", ")}`));
55585
+ break;
55586
+ case "task.requeued":
55587
+ activity.push(line(event, sourceOf(event.data.task.id), "task", `requeued: ${event.data.reason}`));
55588
+ break;
55589
+ case "task.transient":
55590
+ activity.push(line(event, sourceOf(event.data.task.id), "task", `transient: ${event.data.reason}`));
55591
+ break;
55592
+ case "task.interrupted":
55593
+ activity.push(line(event, sourceOf(event.data.task.id), "task", "interrupted"));
55594
+ break;
55595
+ case "task.waiting": {
55596
+ const waiting = event.data.tasks.map((task) => `${task.id} (${task.reason})`);
55597
+ activity.push(line(event, "run", "task", waiting.length === 0 ? "waiting" : `waiting on ${waiting.join(", ")}`));
55598
+ break;
55599
+ }
55600
+ case "task.removed":
55601
+ activity.push(line(event, sourceOf(event.data.task.id), "task", `removed${event.data.reason === undefined ? "" : `: ${event.data.reason}`}`));
55602
+ break;
55603
+ case "gate.planned": {
55604
+ const planned = event.data.gates.map((gate) => gate.name);
55605
+ const stage = event.data.stage === undefined ? "" : `${event.data.stage}: `;
55606
+ activity.push(line(event, sourceOf(event.data.step), "gate", `${stage}planned ${planned.length === 0 ? "no gates" : planned.join(", ")}`));
55607
+ break;
55608
+ }
55609
+ case "gate.started":
55610
+ activity.push(line(event, sourceOf(event.data.step), "gate", `${event.data.name} started${event.data.command === undefined ? "" : `: ${event.data.command}`}`));
55611
+ break;
55612
+ case "gate.report":
55613
+ activity.push(line(event, sourceOf(event.data.step), "gate", `${event.data.passed ? "passed" : "failed"}: ${event.data.results.length} gates`));
55614
+ break;
55615
+ case "install.started":
55616
+ activity.push(line(event, sourceOf(event.data.repo), "install", `${event.data.step} started${event.data.detail === undefined ? "" : `: ${event.data.detail}`}`));
55617
+ break;
55618
+ case "install.finished":
55619
+ activity.push(line(event, sourceOf(event.data.repo), "install", `${event.data.step} finished${event.data.durationMs === undefined ? "" : ` in ${duration3(event.data.durationMs)}`}${event.data.detail === undefined ? "" : `: ${event.data.detail}`}`));
55620
+ break;
55621
+ case "install.failed":
55622
+ activity.push(line(event, sourceOf(event.data.repo), "install", `${event.data.step} failed${event.data.detail === undefined ? "" : `: ${event.data.detail}`}`));
55623
+ break;
55624
+ case "question.raised":
55625
+ activity.push(line(event, sourceOf(event.data.step), "question", `${event.data.question} (${event.data.status})`));
55626
+ break;
55627
+ case "question.answered":
55628
+ activity.push(line(event, sourceOf(event.data.step), "question", `${event.data.question}: ${event.data.answer ?? event.data.status}`));
55629
+ break;
55630
+ case "approval.pending":
55631
+ activity.push(line(event, "run", "approval", `pending ${event.data.specHash} in ${event.data.changeDir}`));
55632
+ break;
55633
+ case "approval.requested":
55634
+ activity.push(line(event, "run", "approval", `requested ${event.data.specHash} at ${event.data.specCommit}`));
55635
+ break;
55636
+ case "approval.granted":
55637
+ activity.push(line(event, "run", "approval", `granted by ${event.data.approver} at ${event.data.specCommit}`));
55638
+ break;
55639
+ case "usage.delta": {
55640
+ const who = event.data.agent ?? event.data.model;
55641
+ activity.push(line(event, sourceOf(event.data.step), "usage", `${who === undefined ? "" : `${who}: `}in ${event.data.usage.input} out ${event.data.usage.output}`));
55642
+ break;
55643
+ }
55644
+ case "progress.line":
55645
+ activity.push(line(event, "run", "log", event.data.text));
55646
+ break;
55647
+ case "heartbeat": {
55648
+ const heartbeat = line(event, "run", "heartbeat", event.data.text);
55649
+ if (activity.lastIs("heartbeat"))
55650
+ activity.replaceLast(heartbeat);
55651
+ else
55652
+ activity.push(heartbeat);
55653
+ break;
55654
+ }
55655
+ default: {
55656
+ const unhandled = event;
55657
+ throw new Error(`unhandled run event: ${String(unhandled)}`);
55658
+ }
55659
+ }
55660
+ }
55661
+ return { gates, agents, retries, activity: activity.toArray() };
55662
+ }
55663
+
55664
+ // packages/tui/src/model/controls.ts
55665
+ async function performControl(deps, action) {
55666
+ switch (action.kind) {
55667
+ case "abort":
55668
+ await deps.factory.abort(action.id);
55669
+ return null;
55670
+ case "retry":
55671
+ await deps.factory.retry(action.id, action.taskId);
55672
+ return null;
55673
+ case "resume":
55674
+ return deps.launcher.launch({ kind: "resume", id: action.id });
55675
+ case "land":
55676
+ return deps.launcher.launch({ kind: "land", id: action.id });
55677
+ default: {
55678
+ const unhandled = action;
55679
+ throw new Error(`unknown control action: ${String(unhandled)}`);
55680
+ }
55681
+ }
55682
+ }
55683
+ function createResumeGuard() {
55684
+ const inFlight = new Set;
55685
+ return {
55686
+ begin(id) {
55687
+ if (inFlight.has(id))
55688
+ return false;
55689
+ inFlight.add(id);
55690
+ return true;
55691
+ },
55692
+ has(id) {
55693
+ return inFlight.has(id);
55694
+ },
55695
+ end(id) {
55696
+ inFlight.delete(id);
55697
+ }
55698
+ };
55699
+ }
55700
+ function createLandGuard() {
55701
+ let inFlight = false;
55702
+ return {
55703
+ begin() {
55704
+ if (inFlight)
55705
+ return false;
55706
+ inFlight = true;
55707
+ return true;
55708
+ },
55709
+ has() {
55710
+ return inFlight;
55711
+ },
55712
+ end() {
55713
+ inFlight = false;
55714
+ }
55715
+ };
55716
+ }
55717
+ function spawnLogLine(displayPath) {
55718
+ return `spawn log: ${displayPath}`;
55719
+ }
55720
+ function resumeStarted(data, id, displayPath) {
55721
+ const notice = `resume ${id} — ${spawnLogLine(displayPath)}`;
55722
+ const approval = data.approval;
55723
+ if (approval?.kind === "waiting") {
55724
+ return { ...data, notice, approval: { ...approval, logPath: displayPath } };
55725
+ }
55726
+ return { ...data, notice };
55727
+ }
55728
+ function resumeFailed(data, id, spawn, code) {
55729
+ const tail = tailLog(spawn.logPath, 10);
55730
+ const failed = data.approval === null ? null : approvalExited(data.approval, code, tail);
55731
+ if (failed !== null && failed !== data.approval)
55732
+ return { ...data, approval: failed };
55733
+ return {
55734
+ ...data,
55735
+ notice: [
55736
+ `resume ${id} exited with code ${code}`,
55737
+ spawnLogLine(spawn.displayPath),
55738
+ ...tail
55739
+ ].join(`
55740
+ `)
55741
+ };
55742
+ }
55743
+ function landStarted(data, id, displayPath) {
55744
+ return { ...data, notice: `land ${id} — ${spawnLogLine(displayPath)}`, pendingLand: null };
55745
+ }
55746
+ function rewordStarted(data, id, displayPath) {
55747
+ const log = spawnLogLine(displayPath);
55748
+ const reword = data.reword ?? null;
55749
+ return reword === null ? { ...data, notice: `reword ${id} — ${log}` } : { ...data, reword: { ...reword, notice: log, failure: null } };
55750
+ }
55751
+ function rewordFailed(data, id, spawn, code) {
55752
+ const tail = tailLog(spawn.logPath, 10);
55753
+ const reword = data.reword ?? null;
55754
+ if (reword !== null) {
55755
+ return {
55756
+ ...data,
55757
+ reword: {
55758
+ ...reword,
55759
+ notice: null,
55760
+ failure: { code, lines: tail, logPath: spawn.displayPath }
55761
+ }
55762
+ };
55763
+ }
55764
+ return {
55765
+ ...data,
55766
+ notice: [
55767
+ `reword ${id} exited with code ${code}`,
55768
+ spawnLogLine(spawn.displayPath),
55769
+ ...tail
55770
+ ].join(`
55771
+ `)
55772
+ };
55773
+ }
55774
+ function rewordSucceeded(data, id, displayPath) {
55775
+ return {
55776
+ ...data,
55777
+ reword: null,
55778
+ notice: `reword ${id} — ${spawnLogLine(displayPath)}`
55779
+ };
55780
+ }
55781
+ function startReword(deps, id, prompt) {
55782
+ if (!deps.guard.begin(id))
55783
+ return;
55784
+ const text = prompt?.trim() ?? "";
55785
+ (async () => {
55786
+ let result;
55787
+ try {
55788
+ result = await deps.launcher.launch({
55789
+ kind: "reword",
55790
+ id,
55791
+ ...text === "" ? {} : { prompt: text }
55792
+ });
55793
+ } catch (err) {
55794
+ deps.guard.end(id);
55795
+ const message = err instanceof Error ? err.message : String(err);
55796
+ deps.update((current) => {
55797
+ const reword = current.reword ?? null;
55798
+ return reword === null ? { ...current, notice: message } : { ...current, reword: { ...reword, notice: message } };
55799
+ });
55800
+ return;
55801
+ }
55802
+ deps.update((current) => rewordStarted(current, id, result.displayPath));
55803
+ result.exited.then(({ code }) => {
55804
+ deps.guard.end(id);
55805
+ if (code === 0) {
55806
+ deps.update((current) => rewordSucceeded(current, id, result.displayPath));
55807
+ return;
55808
+ }
55809
+ if (code === null)
55810
+ return;
55811
+ deps.update((current) => rewordFailed(current, id, result, code));
55812
+ });
55813
+ })();
55814
+ }
55815
+ function startResume(deps, id) {
55816
+ if (!deps.guard.begin(id))
55817
+ return;
55818
+ (async () => {
55819
+ let result;
55820
+ try {
55821
+ result = await performControl(deps, { kind: "resume", id });
55822
+ } catch (err) {
55823
+ deps.guard.end(id);
55824
+ const message = err instanceof Error ? err.message : String(err);
55825
+ deps.update((current) => ({ ...current, notice: message }));
55826
+ return;
55827
+ }
55828
+ deps.update((current) => resumeStarted(current, id, result.displayPath));
55829
+ result.exited.then(({ code }) => {
55830
+ deps.guard.end(id);
55831
+ if (code === null || code === 0)
55832
+ return;
55833
+ deps.update((current) => resumeFailed(current, id, result, code));
55834
+ });
55835
+ try {
55836
+ await deps.refresh();
55837
+ } catch (err) {
55838
+ const message = err instanceof Error ? err.message : String(err);
55839
+ deps.update((current) => ({ ...current, notice: message }));
54420
55840
  }
54421
- return lines;
54422
- }
54423
- get length() {
54424
- return this.count;
54425
- }
55841
+ })();
54426
55842
  }
54427
-
54428
- // packages/tui/src/model/facts.ts
54429
- function collectFacts(events) {
54430
- return appendFacts({ gates: {}, agents: {}, retries: {}, activity: [] }, events);
55843
+ function landFailed(data, id, spawn, code) {
55844
+ const tail = tailLog(spawn.logPath, 10);
55845
+ return {
55846
+ ...data,
55847
+ notice: [`land ${id} exited with code ${code}`, spawnLogLine(spawn.displayPath), ...tail].join(`
55848
+ `),
55849
+ pendingLand: null
55850
+ };
54431
55851
  }
54432
- function appendFacts(prior, events) {
54433
- const gates = {};
54434
- for (const [step, rows] of Object.entries(prior.gates))
54435
- gates[step] = [...rows];
54436
- const agents = { ...prior.agents };
54437
- const retries = { ...prior.retries };
54438
- const activity = new ActivityRing(prior.activity);
54439
- const bump = (key) => {
54440
- retries[key] = (retries[key] ?? 0) + 1;
55852
+ function landSettled(data, id, refreshed) {
55853
+ const next = {
55854
+ ...data,
55855
+ status: refreshed.status,
55856
+ runs: refreshed.runs,
55857
+ pendingLand: null,
55858
+ activity: null,
55859
+ approvalCollapsed: false
54441
55860
  };
54442
- for (const event of events) {
54443
- switch (event.type) {
54444
- case "gate.finished": {
54445
- const step = event.data.step ?? "";
54446
- const row = {
54447
- step,
54448
- name: event.data.name,
54449
- type: event.data.type,
54450
- status: event.data.status,
54451
- durationMs: event.data.durationMs
54452
- };
54453
- const rows = gates[step];
54454
- if (rows === undefined) {
54455
- gates[step] = [row];
54456
- break;
54457
- }
54458
- const index = rows.findIndex((existing) => existing.name === row.name);
54459
- if (index === -1)
54460
- rows.push(row);
54461
- else
54462
- rows[index] = row;
54463
- break;
55861
+ if (refreshed.status.runs.some((run) => run.id === id))
55862
+ return next;
55863
+ return {
55864
+ ...next,
55865
+ screen: "list",
55866
+ selectedRunId: null,
55867
+ selectedTaskId: null,
55868
+ snapshot: null,
55869
+ facts: collectFacts([]),
55870
+ notice: landedNotice(id),
55871
+ intake: null,
55872
+ approval: null,
55873
+ approvalCollapsed: false,
55874
+ questions: null,
55875
+ activity: null,
55876
+ reword: null,
55877
+ confirmation: null,
55878
+ help: false,
55879
+ identity: null
55880
+ };
55881
+ }
55882
+ function settleLanding(data) {
55883
+ const id = data.pendingLand;
55884
+ if (id === null)
55885
+ return data;
55886
+ if (data.selectedRunId !== id)
55887
+ return { ...data, pendingLand: null };
55888
+ return landSettled(data, id, { status: data.status, runs: data.runs });
55889
+ }
55890
+ function startLand(deps, id) {
55891
+ if (!deps.guard.begin())
55892
+ return;
55893
+ (async () => {
55894
+ let result;
55895
+ try {
55896
+ result = await performControl(deps, { kind: "land", id });
55897
+ } catch (err) {
55898
+ deps.guard.end();
55899
+ const message = err instanceof Error ? err.message : String(err);
55900
+ deps.update((current) => ({ ...current, notice: message }));
55901
+ return;
55902
+ }
55903
+ deps.update((current) => landStarted(current, id, result.displayPath));
55904
+ result.exited.then(({ code }) => {
55905
+ deps.guard.end();
55906
+ if (code === null) {
55907
+ const tail = tailLog(result.logPath, 10);
55908
+ deps.update((current) => ({
55909
+ ...current,
55910
+ notice: [
55911
+ `land ${id} ended without an exit code`,
55912
+ spawnLogLine(result.displayPath),
55913
+ ...tail
55914
+ ].join(`
55915
+ `),
55916
+ pendingLand: null
55917
+ }));
55918
+ return;
54464
55919
  }
54465
- case "agent.started":
54466
- agents[event.data.step] = {
54467
- role: event.data.agent,
54468
- model: event.data.model,
54469
- durationMs: null
54470
- };
54471
- break;
54472
- case "agent.finished": {
54473
- const step = event.data.step;
54474
- const priorAgent = agents[step];
54475
- agents[step] = {
54476
- role: event.data.role,
54477
- model: priorAgent?.model ?? "",
54478
- durationMs: event.data.durationMs
54479
- };
54480
- break;
55920
+ if (code !== 0) {
55921
+ deps.update((current) => landFailed(current, id, result, code));
55922
+ return;
54481
55923
  }
54482
- case "agent.retry":
54483
- bump(event.data.step);
54484
- break;
54485
- case "task.retried":
54486
- bump(event.data.task.id);
54487
- break;
54488
- case "agent.activity": {
54489
- const ref = event.data.ref?.path;
54490
- activity.push({
54491
- seq: event.seq,
54492
- step: event.data.step,
54493
- kind: event.data.kind,
54494
- text: event.data.detail,
54495
- ...ref === undefined ? {} : { logRef: ref }
55924
+ deps.update((current) => ({ ...current, pendingLand: id }));
55925
+ const settle = (refreshed) => {
55926
+ deps.update((current) => landSettled(current, id, refreshed));
55927
+ if (!refreshed.status.runs.some((run) => run.id === id))
55928
+ deps.stopTail();
55929
+ };
55930
+ deps.refresh().then((refreshed) => {
55931
+ if (refreshed !== null) {
55932
+ settle(refreshed);
55933
+ return;
55934
+ }
55935
+ deps.refresh().then((retry) => {
55936
+ if (retry !== null)
55937
+ settle(retry);
54496
55938
  });
54497
- break;
54498
- }
54499
- default:
54500
- break;
55939
+ });
55940
+ });
55941
+ try {
55942
+ await deps.refresh();
55943
+ } catch (err) {
55944
+ const message = err instanceof Error ? err.message : String(err);
55945
+ deps.update((current) => ({ ...current, notice: message }));
54501
55946
  }
54502
- }
54503
- return { gates, agents, retries, activity: activity.toArray() };
55947
+ })();
55948
+ }
55949
+ function landConfirmation(viewModel, guard) {
55950
+ const action = landFor(viewModel);
55951
+ if (action === null || guard.has())
55952
+ return null;
55953
+ return action;
55954
+ }
55955
+ async function recordAnswer(factory, changeId, answer, question) {
55956
+ await factory.answer(changeId, answer, question);
54504
55957
  }
54505
55958
 
54506
55959
  // packages/tui/src/model/fold.ts
@@ -54511,55 +55964,6 @@ function foldRun(prior, events) {
54511
55964
  };
54512
55965
  }
54513
55966
 
54514
- // packages/tui/src/model/keys.ts
54515
- function listIntent(viewModel, key) {
54516
- switch (key) {
54517
- case "Enter":
54518
- case "\r":
54519
- return viewModel.selectedRunId === null ? { kind: "none" } : { kind: "open-run", runId: viewModel.selectedRunId };
54520
- case "Down":
54521
- case "j":
54522
- return { kind: "next-run" };
54523
- case "Up":
54524
- case "k":
54525
- return { kind: "prev-run" };
54526
- default:
54527
- return { kind: "none" };
54528
- }
54529
- }
54530
- function runIntent(viewModel, key) {
54531
- switch (key) {
54532
- case "Esc":
54533
- case "\x1B":
54534
- return viewModel.run?.selectedTaskId == null ? { kind: "back" } : { kind: "clear-task" };
54535
- case "Down":
54536
- case "j":
54537
- return { kind: "next-task" };
54538
- case "Up":
54539
- case "k":
54540
- return { kind: "prev-task" };
54541
- case "r":
54542
- return { kind: "resume" };
54543
- case "x":
54544
- return { kind: "abort" };
54545
- case "t":
54546
- return { kind: "retry" };
54547
- case "Q":
54548
- return { kind: "open-questions" };
54549
- default:
54550
- return { kind: "none" };
54551
- }
54552
- }
54553
- function applyKey(viewModel, key) {
54554
- if (viewModel.panel !== null)
54555
- return { kind: "none" };
54556
- if (key === "q")
54557
- return { kind: "quit" };
54558
- if (key === "?")
54559
- return { kind: "help" };
54560
- return viewModel.screen === "list" ? listIntent(viewModel, key) : runIntent(viewModel, key);
54561
- }
54562
-
54563
55967
  // packages/tui/src/model/poll.ts
54564
55968
  function createStatusPoller(options) {
54565
55969
  const intervalMs = options.intervalMs ?? 1000;
@@ -54645,18 +56049,96 @@ function createFrameScheduler(options) {
54645
56049
  cancelPending = () => clearTimeout(handle);
54646
56050
  };
54647
56051
  return {
54648
- request() {
54649
- if (stopped || cancelPending !== null)
56052
+ request() {
56053
+ if (stopped || cancelPending !== null)
56054
+ return;
56055
+ arm();
56056
+ },
56057
+ get frames() {
56058
+ return frames;
56059
+ },
56060
+ stop() {
56061
+ stopped = true;
56062
+ cancelPending?.();
56063
+ cancelPending = null;
56064
+ }
56065
+ };
56066
+ }
56067
+
56068
+ // packages/tui/src/model/ui-data.ts
56069
+ function selectedRunState(data) {
56070
+ const id = data.selectedRunId;
56071
+ if (id === null)
56072
+ return;
56073
+ return data.status.runs.find((run) => run.id === id) ?? data.runs.find((run) => run.id === id);
56074
+ }
56075
+ function grantedCommit2(snapshot) {
56076
+ const approval = snapshot?.approval ?? null;
56077
+ return approval === null || approval.approver === "" ? null : approval.specCommit;
56078
+ }
56079
+ function evidenceOf(data) {
56080
+ return {
56081
+ ...data.identity === null ? {} : { identity: data.identity },
56082
+ findings: selectedRunState(data)?.specFindings.length ?? 0,
56083
+ specCommit: grantedCommit2(data.snapshot)
56084
+ };
56085
+ }
56086
+ function panelOpen(data) {
56087
+ return data.intake !== null || data.questions !== null || (data.reword ?? null) !== null || data.confirmation !== null || data.help || (data.activity ?? null) !== null;
56088
+ }
56089
+ function syncApproval(data) {
56090
+ if (data.screen !== "run" || data.selectedRunId === null)
56091
+ return data;
56092
+ const run = selectedRunState(data);
56093
+ const phase = run?.phase ?? data.snapshot?.phase ?? null;
56094
+ if (data.approval === null) {
56095
+ if (panelOpen(data))
56096
+ return data;
56097
+ if (phase === null)
56098
+ return data;
56099
+ const opened = approvalForPhase(phase, null);
56100
+ return opened === null ? data : { ...data, approval: opened, approvalCollapsed: false, identity: null };
56101
+ }
56102
+ if ((data.approval.kind === "idle" || data.approval.kind === "failed") && phase !== null && phase !== "awaiting-approval") {
56103
+ return { ...data, approval: null, approvalCollapsed: false };
56104
+ }
56105
+ if (data.approval.kind !== "waiting")
56106
+ return data;
56107
+ const next = approvalProgress(data.approval, {
56108
+ phase,
56109
+ granted: grantedCommit2(data.snapshot) !== null
56110
+ });
56111
+ if (next === data.approval)
56112
+ return data;
56113
+ return { ...data, approval: next.kind === "done" ? null : next, approvalCollapsed: false };
56114
+ }
56115
+
56116
+ // packages/tui/src/model/status.ts
56117
+ function mergeRun(current, id, partial) {
56118
+ const previous = current.status;
56119
+ const fresh = partial.runs.find((run) => run.id === id);
56120
+ if (fresh === undefined)
56121
+ return current;
56122
+ const runs = previous.runs.some((run) => run.id === id) ? previous.runs.map((run) => run.id === id ? fresh : run) : [...previous.runs, fresh];
56123
+ return settleLanding(syncApproval({ ...current, status: { ...previous, ...partial, runs } }));
56124
+ }
56125
+ function createStatusSource(options) {
56126
+ return {
56127
+ refresh: options.refresh,
56128
+ async poll() {
56129
+ const id = options.pendingSpawn?.() === true ? null : options.selectedRunId();
56130
+ if (id === null) {
56131
+ await options.refresh();
54650
56132
  return;
54651
- arm();
54652
- },
54653
- get frames() {
54654
- return frames;
54655
- },
54656
- stop() {
54657
- stopped = true;
54658
- cancelPending?.();
54659
- cancelPending = null;
56133
+ }
56134
+ let partial;
56135
+ try {
56136
+ partial = await options.factory.status(id);
56137
+ } catch {
56138
+ await options.refresh();
56139
+ return;
56140
+ }
56141
+ options.update((current) => mergeRun(current, id, partial));
54660
56142
  }
54661
56143
  };
54662
56144
  }
@@ -54832,329 +56314,240 @@ function parseKey(data) {
54832
56314
  return { input: "Esc", key };
54833
56315
  case "\t":
54834
56316
  key.tab = true;
54835
- return { input: "Tab", key };
54836
- case "":
54837
- case "\b":
54838
- key.backspace = true;
54839
- return { input: "", key };
54840
- default:
54841
- break;
54842
- }
54843
- const code = data.codePointAt(0) ?? 0;
54844
- if (data.length === 1 && code >= 1 && code <= 26) {
54845
- key.ctrl = true;
54846
- return { input: String.fromCharCode(code + 96), key };
54847
- }
54848
- if (data.length === 1 && /[A-Z]/.test(data))
54849
- key.shift = true;
54850
- return { input: data, key };
54851
- }
54852
- function setRaw(input, enabled) {
54853
- if (typeof input.setRawMode !== "function")
54854
- return;
54855
- input.setRawMode(enabled);
54856
- }
54857
- function createTerminalSession(input, output) {
54858
- const wasRaw = input.isRaw === true;
54859
- let entered = false;
54860
- let left = false;
54861
- return {
54862
- enter() {
54863
- if (entered)
54864
- return;
54865
- entered = true;
54866
- left = false;
54867
- output.write(ENTER_ALTERNATE);
54868
- if (!wasRaw)
54869
- setRaw(input, true);
54870
- },
54871
- leave() {
54872
- if (left)
54873
- return;
54874
- left = true;
54875
- entered = false;
54876
- output.write(LEAVE_ALTERNATE);
54877
- if (!wasRaw)
54878
- setRaw(input, false);
54879
- },
54880
- get columns() {
54881
- return output.columns ?? 80;
54882
- },
54883
- get rows() {
54884
- return output.rows ?? 24;
54885
- },
54886
- onKey(handler) {
54887
- const listener = (data) => {
54888
- const text = typeof data === "string" ? data : data.toString("utf8");
54889
- const parsed = parseKey(text);
54890
- handler(parsed.input, parsed.key);
54891
- };
54892
- input.on("data", listener);
54893
- input.resume();
54894
- return () => {
54895
- input.off("data", listener);
54896
- input.pause();
54897
- };
54898
- },
54899
- onResize(handler) {
54900
- output.on("resize", handler);
54901
- return () => output.off("resize", handler);
54902
- },
54903
- onSignal(handler) {
54904
- process.on("SIGINT", handler);
54905
- process.on("SIGTERM", handler);
54906
- return () => {
54907
- process.off("SIGINT", handler);
54908
- process.off("SIGTERM", handler);
54909
- };
54910
- }
54911
- };
54912
- }
54913
-
54914
- // packages/tui/src/theme/env.ts
54915
- function terminalEnv(source) {
54916
- if (source === undefined)
54917
- return {};
54918
- return {
54919
- ...source.TERM === undefined ? {} : { TERM: source.TERM },
54920
- ...source.COLORTERM === undefined ? {} : { COLORTERM: source.COLORTERM },
54921
- ...source.NO_COLOR === undefined ? {} : { NO_COLOR: source.NO_COLOR },
54922
- ...source.LANG === undefined ? {} : { LANG: source.LANG },
54923
- ...source.LC_ALL === undefined ? {} : { LC_ALL: source.LC_ALL },
54924
- ...source.LC_CTYPE === undefined ? {} : { LC_CTYPE: source.LC_CTYPE }
54925
- };
54926
- }
54927
- function localeOf(env) {
54928
- for (const value of [env.LC_ALL, env.LC_CTYPE, env.LANG]) {
54929
- if (value !== undefined && value !== "")
54930
- return value;
54931
- }
54932
- return;
54933
- }
54934
- function isUtf8Locale(env) {
54935
- const locale = localeOf(env);
54936
- if (locale === undefined)
54937
- return true;
54938
- return /utf-?8/i.test(locale);
54939
- }
54940
- function detectColorDepth(env, isTTY) {
54941
- if (!isTTY)
54942
- return "none";
54943
- if (env.NO_COLOR !== undefined)
54944
- return "none";
54945
- if (env.TERM === "dumb")
54946
- return "none";
54947
- const colorterm = env.COLORTERM;
54948
- if (colorterm !== undefined && /truecolor|24bit/i.test(colorterm))
54949
- return "truecolor";
54950
- const term = env.TERM;
54951
- if (term !== undefined && /256color/i.test(term))
54952
- return "256";
54953
- return "16";
54954
- }
54955
-
54956
- // packages/tui/src/theme/glyphs.ts
54957
- var UNICODE_GLYPHS = {
54958
- passed: "✔",
54959
- failed: "✖",
54960
- blocked: "▲",
54961
- running: "▶",
54962
- pending: "○",
54963
- merged: "●",
54964
- skipped: "–",
54965
- focus: "›",
54966
- arrow: "→",
54967
- bullet: "•",
54968
- approval: "!"
54969
- };
54970
- var ASCII_GLYPHS = {
54971
- passed: "+",
54972
- failed: "x",
54973
- blocked: "!",
54974
- running: ">",
54975
- pending: "o",
54976
- merged: "*",
54977
- skipped: "-",
54978
- focus: ">",
54979
- arrow: ">",
54980
- bullet: "-",
54981
- approval: "!"
54982
- };
54983
- function glyphsFor(options) {
54984
- if (typeof options === "boolean")
54985
- return options ? ASCII_GLYPHS : UNICODE_GLYPHS;
54986
- if (options.ascii || options.env.TERM === "dumb" || !isUtf8Locale(options.env)) {
54987
- return ASCII_GLYPHS;
54988
- }
54989
- return UNICODE_GLYPHS;
54990
- }
54991
-
54992
- // packages/tui/src/views/style.ts
54993
- function inkColor(token, depth) {
54994
- return depth === "none" ? undefined : TOKENS[token].hex;
54995
- }
54996
- function colorProps(token, depth) {
54997
- const color = inkColor(token, depth);
54998
- return color === undefined ? {} : { color };
54999
- }
55000
- function joinFields(glyphs, fields) {
55001
- return fields.join(` ${glyphs.bullet} `);
55002
- }
55003
- function statusGlyph2(status, glyphs) {
55004
- switch (status) {
55005
- case "merged":
55006
- case "pass":
55007
- case "passed":
55008
- return glyphs.passed;
55009
- case "failed":
55010
- case "fail":
55011
- case "timeout":
55012
- return glyphs.failed;
55013
- case "blocked":
55014
- case "cancelled":
55015
- case "missing":
55016
- case "not-check-only":
55017
- return glyphs.blocked;
55018
- case "skipped":
55019
- return glyphs.skipped;
55020
- case "running":
55021
- case "merging":
55022
- return glyphs.running;
55023
- default:
55024
- return glyphs.pending;
55025
- }
55026
- }
55027
- function statusToken(status) {
55028
- switch (status) {
55029
- case "merged":
55030
- case "pass":
55031
- case "passed":
55032
- return "passed";
55033
- case "failed":
55034
- case "fail":
55035
- case "timeout":
55036
- return "failed";
55037
- case "blocked":
55038
- case "cancelled":
55039
- case "missing":
55040
- case "not-check-only":
55041
- return "blocked";
55042
- case "skipped":
55043
- return "skipped";
55044
- case "running":
55045
- case "merging":
55046
- return "running";
55047
- default:
55048
- return "muted";
55049
- }
55050
- }
55051
- function phaseGlyph(phase, glyphs) {
55052
- switch (phase) {
55053
- case "done":
55054
- return glyphs.passed;
55055
- case "aborted":
55056
- return glyphs.failed;
55057
- case "paused":
55058
- case "awaiting-approval":
55059
- return glyphs.blocked;
55060
- default:
55061
- return glyphs.running;
55062
- }
55063
- }
55064
- function phaseToken(phase) {
55065
- switch (phase) {
55066
- case "done":
55067
- return "passed";
55068
- case "aborted":
55069
- return "failed";
55070
- case "paused":
55071
- case "awaiting-approval":
55072
- return "muted";
56317
+ return { input: "Tab", key };
56318
+ case "":
56319
+ case "\b":
56320
+ key.backspace = true;
56321
+ return { input: "", key };
55073
56322
  default:
55074
- return "running";
56323
+ break;
56324
+ }
56325
+ const code = data.codePointAt(0) ?? 0;
56326
+ if (data.length === 1 && code >= 1 && code <= 26) {
56327
+ key.ctrl = true;
56328
+ return { input: String.fromCharCode(code + 96), key };
55075
56329
  }
56330
+ if (data.length === 1 && /[A-Z]/.test(data))
56331
+ key.shift = true;
56332
+ return { input: data, key };
56333
+ }
56334
+ function setRaw(input, enabled) {
56335
+ if (typeof input.setRawMode !== "function")
56336
+ return;
56337
+ input.setRawMode(enabled);
56338
+ }
56339
+ function createTerminalSession(input, output) {
56340
+ const wasRaw = input.isRaw === true;
56341
+ let entered = false;
56342
+ let left = false;
56343
+ return {
56344
+ enter() {
56345
+ if (entered)
56346
+ return;
56347
+ entered = true;
56348
+ left = false;
56349
+ output.write(ENTER_ALTERNATE);
56350
+ if (!wasRaw)
56351
+ setRaw(input, true);
56352
+ },
56353
+ leave() {
56354
+ if (left)
56355
+ return;
56356
+ left = true;
56357
+ entered = false;
56358
+ output.write(LEAVE_ALTERNATE);
56359
+ if (!wasRaw)
56360
+ setRaw(input, false);
56361
+ },
56362
+ get columns() {
56363
+ return output.columns ?? 80;
56364
+ },
56365
+ get rows() {
56366
+ return output.rows ?? 24;
56367
+ },
56368
+ onKey(handler) {
56369
+ const listener = (data) => {
56370
+ const text = typeof data === "string" ? data : data.toString("utf8");
56371
+ const parsed = parseKey(text);
56372
+ handler(parsed.input, parsed.key);
56373
+ };
56374
+ input.on("data", listener);
56375
+ input.resume();
56376
+ return () => {
56377
+ input.off("data", listener);
56378
+ input.pause();
56379
+ };
56380
+ },
56381
+ onResize(handler) {
56382
+ output.on("resize", handler);
56383
+ return () => output.off("resize", handler);
56384
+ },
56385
+ onSignal(handler) {
56386
+ process.on("SIGINT", handler);
56387
+ process.on("SIGTERM", handler);
56388
+ return () => {
56389
+ process.off("SIGINT", handler);
56390
+ process.off("SIGTERM", handler);
56391
+ };
56392
+ }
56393
+ };
55076
56394
  }
55077
56395
 
55078
56396
  // packages/tui/src/views/activity.tsx
55079
56397
  var jsx_dev_runtime = __toESM(require_jsx_dev_runtime(), 1);
56398
+ function ActivityLines({
56399
+ lines,
56400
+ glyphs,
56401
+ depth,
56402
+ columns
56403
+ }) {
56404
+ if (lines.length === 0)
56405
+ return null;
56406
+ return /* @__PURE__ */ jsx_dev_runtime.jsxDEV(Box_default, {
56407
+ flexDirection: "column",
56408
+ children: lines.map((line) => {
56409
+ const sep = ` ${glyphs.bullet} `;
56410
+ const refText = line.logRef === undefined ? "" : `${glyphs.arrow} ${line.logRef}`;
56411
+ const reserved = 2 * sep.length + (line.logRef === undefined ? 0 : 1);
56412
+ if (columns <= reserved) {
56413
+ const plain = `${line.step}${sep}${line.kind}${sep}${refText === "" ? "" : `${refText} `}${line.text}`;
56414
+ return /* @__PURE__ */ jsx_dev_runtime.jsxDEV(Text, {
56415
+ wrap: "truncate",
56416
+ children: clip(plain, columns, glyphs)
56417
+ }, line.seq, false, undefined, this);
56418
+ }
56419
+ let room = columns - reserved;
56420
+ const step = clip(line.step, room, glyphs);
56421
+ room -= step.length;
56422
+ const kind = clip(line.kind, room, glyphs);
56423
+ room -= kind.length;
56424
+ const ref = clip(refText, room, glyphs);
56425
+ room -= ref.length;
56426
+ const text = clip(line.text, room, glyphs);
56427
+ return /* @__PURE__ */ jsx_dev_runtime.jsxDEV(Text, {
56428
+ wrap: "truncate",
56429
+ children: [
56430
+ /* @__PURE__ */ jsx_dev_runtime.jsxDEV(Text, {
56431
+ ...colorProps("muted", depth),
56432
+ children: step
56433
+ }, undefined, false, undefined, this),
56434
+ sep,
56435
+ /* @__PURE__ */ jsx_dev_runtime.jsxDEV(Text, {
56436
+ ...colorProps("muted", depth),
56437
+ children: kind
56438
+ }, undefined, false, undefined, this),
56439
+ sep,
56440
+ line.logRef === undefined ? null : /* @__PURE__ */ jsx_dev_runtime.jsxDEV(jsx_dev_runtime.Fragment, {
56441
+ children: [
56442
+ /* @__PURE__ */ jsx_dev_runtime.jsxDEV(Text, {
56443
+ ...colorProps("muted", depth),
56444
+ children: ref
56445
+ }, undefined, false, undefined, this),
56446
+ " "
56447
+ ]
56448
+ }, undefined, true, undefined, this),
56449
+ text
56450
+ ]
56451
+ }, line.seq, true, undefined, this);
56452
+ })
56453
+ }, undefined, false, undefined, this);
56454
+ }
55080
56455
  function ActivityTail({
55081
56456
  lines,
55082
56457
  glyphs,
55083
56458
  depth,
55084
- maxLines = 20
56459
+ maxLines = 20,
56460
+ columns
55085
56461
  }) {
55086
- const count = Math.max(0, maxLines);
55087
- const shown = count === 0 ? [] : lines.slice(Math.max(0, lines.length - count));
55088
- if (shown.length === 0) {
56462
+ if (maxLines <= 0)
56463
+ return null;
56464
+ if (lines.length === 0) {
55089
56465
  return /* @__PURE__ */ jsx_dev_runtime.jsxDEV(Text, {
55090
56466
  ...colorProps("muted", depth),
55091
56467
  children: "no activity yet"
55092
56468
  }, undefined, false, undefined, this);
55093
56469
  }
55094
- return /* @__PURE__ */ jsx_dev_runtime.jsxDEV(Box_default, {
55095
- flexDirection: "column",
55096
- children: shown.map((line) => /* @__PURE__ */ jsx_dev_runtime.jsxDEV(Text, {
55097
- wrap: "truncate",
55098
- children: [
55099
- line.step,
55100
- " ",
55101
- glyphs.bullet,
55102
- " ",
55103
- line.kind,
55104
- " ",
55105
- glyphs.bullet,
55106
- " ",
55107
- line.text,
55108
- line.logRef === undefined ? "" : ` ${glyphs.arrow} ${line.logRef}`
55109
- ]
55110
- }, line.seq, true, undefined, this))
56470
+ const shown = lines.slice(Math.max(0, lines.length - maxLines));
56471
+ return /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ActivityLines, {
56472
+ lines: shown,
56473
+ glyphs,
56474
+ depth,
56475
+ columns
55111
56476
  }, undefined, false, undefined, this);
55112
56477
  }
55113
56478
 
55114
56479
  // packages/tui/src/views/footer.tsx
55115
56480
  var jsx_dev_runtime2 = __toESM(require_jsx_dev_runtime(), 1);
55116
- function KeyFooter({ hints, glyphs, depth }) {
55117
- const text = hints.filter((hint) => hint.enabled).map((hint) => `${hint.key} ${hint.label}`).join(` ${glyphs.bullet} `);
56481
+ function isKept(key) {
56482
+ return key === "q" || key === "?";
56483
+ }
56484
+ function fitEnabled(hints, separator, columns) {
56485
+ const shown = [...hints];
56486
+ let text = shown.map((hint) => hint.text).join(separator);
56487
+ while (text.length > columns) {
56488
+ const drop = shown.findLastIndex((hint) => !isKept(hint.key));
56489
+ if (drop < 0)
56490
+ break;
56491
+ shown.splice(drop, 1);
56492
+ text = shown.map((hint) => hint.text).join(separator);
56493
+ }
56494
+ return text;
56495
+ }
56496
+ function footerText(hints, glyphs, columns) {
56497
+ const separator = ` ${glyphs.bullet} `;
56498
+ const inert = [];
56499
+ const enabled = [];
56500
+ for (const hint of hints) {
56501
+ if (hint.enabled) {
56502
+ enabled.push({ key: hint.key, text: `${hint.key} ${hint.label}` });
56503
+ } else if (hint.reason !== undefined) {
56504
+ inert.push(`${hint.key} ${hint.label} ${dash(glyphs)} ${hint.reason}`);
56505
+ }
56506
+ }
56507
+ const enabledText = fitEnabled(enabled, separator, columns);
56508
+ if (inert.length === 0)
56509
+ return enabledText;
56510
+ if (enabledText === "")
56511
+ return clip(inert.join(separator), columns, glyphs);
56512
+ const room = columns - enabledText.length - separator.length;
56513
+ if (room <= 0)
56514
+ return enabledText;
56515
+ const inertText = clip(inert.join(separator), room, glyphs);
56516
+ return inertText === "" ? enabledText : `${inertText}${separator}${enabledText}`;
56517
+ }
56518
+ function KeyFooter({ hints, glyphs, depth, columns }) {
56519
+ const text = footerText(hints, glyphs, columns);
55118
56520
  return /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(Text, {
55119
56521
  ...colorProps("muted", depth),
55120
56522
  wrap: "truncate",
55121
- children: text
56523
+ children: clip(text, columns, glyphs)
55122
56524
  }, undefined, false, undefined, this);
55123
56525
  }
55124
56526
 
55125
- // packages/tui/src/model/format.ts
55126
- function formatElapsed(ms) {
55127
- const seconds = Math.floor(Math.max(0, ms) / 1000);
55128
- const s = seconds % 60;
55129
- const m = Math.floor(seconds / 60) % 60;
55130
- const h = Math.floor(seconds / 3600);
55131
- if (h > 0)
55132
- return `${h}h${String(m).padStart(2, "0")}m`;
55133
- if (m > 0)
55134
- return `${m}m${String(s).padStart(2, "0")}s`;
55135
- return `${s}s`;
55136
- }
55137
- function formatTokensShort(n) {
55138
- const value = Math.max(0, n);
55139
- if (value >= 1e6)
55140
- return `${(value / 1e6).toFixed(1)}M`;
55141
- if (value >= 1000)
55142
- return `${(value / 1000).toFixed(1)}k`;
55143
- return String(Math.round(value));
55144
- }
55145
- function truncate2(text, width) {
55146
- if (width <= 0)
55147
- return "";
55148
- if (text.length <= width)
55149
- return text;
55150
- if (width === 1)
55151
- return "…";
55152
- return `${text.slice(0, width - 1)}…`;
55153
- }
55154
-
55155
56527
  // packages/tui/src/views/header.tsx
55156
56528
  var jsx_dev_runtime3 = __toESM(require_jsx_dev_runtime(), 1);
55157
- function RunHeader({ run, glyphs, depth }) {
56529
+ function clipTail(text, room, glyphs) {
56530
+ if (room <= 0)
56531
+ return "";
56532
+ if (text.length <= room)
56533
+ return text;
56534
+ const mark = glyphs.bullet === "-" ? "..." : "…";
56535
+ if (room <= mark.length)
56536
+ return text.slice(-room);
56537
+ return `${mark}${text.slice(-(room - mark.length))}`;
56538
+ }
56539
+ function RunHeader({ run, glyphs, depth, columns }) {
56540
+ const showReapprove = run.approval !== null && run.approval.specCommit !== null;
56541
+ const phase = phaseGlyph(run.phase, glyphs);
56542
+ const meta = joinFields(glyphs, [
56543
+ formatElapsed(run.elapsedMs),
56544
+ `${formatTokensShort(run.tokens)} tokens`,
56545
+ `$${run.cost.toFixed(2)}`,
56546
+ roleLabel(run.lock)
56547
+ ]);
56548
+ const room = Math.max(0, columns - phase.length - 2);
56549
+ const head = clip(`${run.id} ${LABELS[run.phase]}`, Math.max(0, room - meta.length - 1), glyphs);
56550
+ const clippedMeta = clipTail(meta, Math.max(0, room - head.length - 1), glyphs);
55158
56551
  return /* @__PURE__ */ jsx_dev_runtime3.jsxDEV(Box_default, {
55159
56552
  flexDirection: "column",
55160
56553
  children: [
@@ -55163,17 +56556,18 @@ function RunHeader({ run, glyphs, depth }) {
55163
56556
  children: [
55164
56557
  /* @__PURE__ */ jsx_dev_runtime3.jsxDEV(Text, {
55165
56558
  ...colorProps(phaseToken(run.phase), depth),
55166
- children: phaseGlyph(run.phase, glyphs)
56559
+ children: phase
55167
56560
  }, undefined, false, undefined, this),
55168
56561
  " ",
55169
- joinFields(glyphs, [
55170
- run.id,
55171
- LABELS[run.phase],
55172
- formatElapsed(run.elapsedMs),
55173
- `${formatTokensShort(run.tokens)} tokens`,
55174
- `$${run.cost.toFixed(2)}`,
55175
- roleLabel(run.lock)
55176
- ])
56562
+ /* @__PURE__ */ jsx_dev_runtime3.jsxDEV(Text, {
56563
+ bold: true,
56564
+ children: head
56565
+ }, undefined, false, undefined, this),
56566
+ " ",
56567
+ /* @__PURE__ */ jsx_dev_runtime3.jsxDEV(Text, {
56568
+ ...colorProps("muted", depth),
56569
+ children: clippedMeta
56570
+ }, undefined, false, undefined, this)
55177
56571
  ]
55178
56572
  }, undefined, true, undefined, this),
55179
56573
  run.phase === "awaiting-approval" ? /* @__PURE__ */ jsx_dev_runtime3.jsxDEV(Text, {
@@ -55181,9 +56575,15 @@ function RunHeader({ run, glyphs, depth }) {
55181
56575
  wrap: "truncate",
55182
56576
  children: joinFields(glyphs, [
55183
56577
  `${glyphs.approval} awaiting approval`,
55184
- "a approve",
55185
- "A approve only"
56578
+ "a approve and run",
56579
+ "A approve only",
56580
+ ...showReapprove ? ["R reapprove"] : []
55186
56581
  ])
56582
+ }, undefined, false, undefined, this) : null,
56583
+ run.phase === "paused" && run.specFindings.length > 0 ? /* @__PURE__ */ jsx_dev_runtime3.jsxDEV(Text, {
56584
+ ...colorProps(phaseToken(run.phase), depth),
56585
+ wrap: "truncate",
56586
+ children: `${phaseGlyph(run.phase, glyphs)} ${pausedFindings(dash(glyphs), run.specFindings.length)}`
55187
56587
  }, undefined, false, undefined, this) : null
55188
56588
  ]
55189
56589
  }, undefined, true, undefined, this);
@@ -55191,10 +56591,45 @@ function RunHeader({ run, glyphs, depth }) {
55191
56591
 
55192
56592
  // packages/tui/src/views/panel.tsx
55193
56593
  var jsx_dev_runtime4 = __toESM(require_jsx_dev_runtime(), 1);
55194
- function PanelBox({ panel, glyphs, depth }) {
56594
+ var STATUS_LINE = /^ {2}(?:answered|skipped|unanswered|recorded)(?:\s|$)/u;
56595
+ function questionLine(line, isFile, key, glyphs, depth) {
56596
+ if (isFile || STATUS_LINE.test(line)) {
56597
+ return /* @__PURE__ */ jsx_dev_runtime4.jsxDEV(Text, {
56598
+ wrap: "truncate",
56599
+ ...colorProps("muted", depth),
56600
+ children: line
56601
+ }, key, false, undefined, this);
56602
+ }
56603
+ if (line.startsWith(`${glyphs.focus} `)) {
56604
+ return /* @__PURE__ */ jsx_dev_runtime4.jsxDEV(Text, {
56605
+ wrap: "truncate",
56606
+ bold: true,
56607
+ children: [
56608
+ /* @__PURE__ */ jsx_dev_runtime4.jsxDEV(Text, {
56609
+ ...colorProps("focus", depth),
56610
+ children: line.slice(0, glyphs.focus.length)
56611
+ }, undefined, false, undefined, this),
56612
+ line.slice(glyphs.focus.length)
56613
+ ]
56614
+ }, key, true, undefined, this);
56615
+ }
56616
+ return /* @__PURE__ */ jsx_dev_runtime4.jsxDEV(Text, {
56617
+ wrap: "truncate",
56618
+ children: line
56619
+ }, key, false, undefined, this);
56620
+ }
56621
+ function clipLines(text, room, glyphs) {
56622
+ return text.split(`
56623
+ `).map((line) => clip(line, room, glyphs)).join(`
56624
+ `);
56625
+ }
56626
+ function PanelBox({ panel, glyphs, depth, rows, columns }) {
55195
56627
  const token = panel.kind === "approval" ? "approval" : "focus";
55196
56628
  const borderColor = inkColor(token, depth);
56629
+ const innerWidth = Math.max(0, columns - 4);
55197
56630
  const occurrences = new Map;
56631
+ const bodyRows = panel.lines.length + (panel.notice === null ? 0 : 1);
56632
+ const spaced = bodyRows + 6 <= rows;
55198
56633
  return /* @__PURE__ */ jsx_dev_runtime4.jsxDEV(Box_default, {
55199
56634
  flexDirection: "column",
55200
56635
  borderStyle: "classic",
@@ -55204,25 +56639,30 @@ function PanelBox({ panel, glyphs, depth }) {
55204
56639
  /* @__PURE__ */ jsx_dev_runtime4.jsxDEV(Text, {
55205
56640
  bold: true,
55206
56641
  ...colorProps(token, depth),
55207
- children: panel.title
56642
+ wrap: "truncate",
56643
+ children: clip(panel.title, innerWidth, glyphs)
55208
56644
  }, undefined, false, undefined, this),
55209
- panel.lines.map((line) => {
56645
+ panel.lines.map((line, index) => {
55210
56646
  const count = (occurrences.get(line) ?? 0) + 1;
55211
56647
  occurrences.set(line, count);
55212
- return /* @__PURE__ */ jsx_dev_runtime4.jsxDEV(Text, {
56648
+ const key = `${line}#${count}`;
56649
+ return panel.kind === "questions" ? questionLine(clipLines(line, innerWidth, glyphs), index === 0, key, glyphs, depth) : /* @__PURE__ */ jsx_dev_runtime4.jsxDEV(Text, {
55213
56650
  wrap: "truncate",
55214
- children: line
55215
- }, `${line}#${count}`, false, undefined, this);
56651
+ children: clipLines(line, innerWidth, glyphs)
56652
+ }, key, false, undefined, this);
55216
56653
  }),
55217
56654
  panel.notice === null ? null : /* @__PURE__ */ jsx_dev_runtime4.jsxDEV(Text, {
55218
56655
  ...colorProps("muted", depth),
55219
56656
  wrap: "truncate",
55220
- children: panel.notice
56657
+ children: clipLines(panel.notice, innerWidth, glyphs)
55221
56658
  }, undefined, false, undefined, this),
56659
+ spaced ? /* @__PURE__ */ jsx_dev_runtime4.jsxDEV(Text, {
56660
+ children: " "
56661
+ }, undefined, false, undefined, this) : null,
55222
56662
  /* @__PURE__ */ jsx_dev_runtime4.jsxDEV(Text, {
55223
56663
  ...colorProps("muted", depth),
55224
56664
  wrap: "truncate",
55225
- children: panel.keys.map((hint) => `${hint.key} ${hint.label}`).join(` ${glyphs.bullet} `)
56665
+ children: clip(panel.keys.map((hint) => `${hint.key} ${hint.label}`).join(` ${glyphs.bullet} `), innerWidth, glyphs)
55226
56666
  }, undefined, false, undefined, this)
55227
56667
  ]
55228
56668
  }, undefined, true, undefined, this);
@@ -55230,37 +56670,108 @@ function PanelBox({ panel, glyphs, depth }) {
55230
56670
 
55231
56671
  // packages/tui/src/views/run-list.tsx
55232
56672
  var jsx_dev_runtime5 = __toESM(require_jsx_dev_runtime(), 1);
56673
+ var SUMMARY_RESERVE = 12;
56674
+ function clipHead(item, room, glyphs) {
56675
+ if (room <= 0)
56676
+ return "";
56677
+ if (room <= item.id.length)
56678
+ return clip(item.id, room, glyphs);
56679
+ const summaryRoom = room - item.id.length - 2;
56680
+ if (summaryRoom <= 0)
56681
+ return item.id;
56682
+ return `${item.id} ${clip(item.summary, summaryRoom, glyphs)}`;
56683
+ }
56684
+ function markerOf(item, glyphs) {
56685
+ return item.findings > 0 ? ` ${glyphs.blocked} ${findingsCount(item.findings)}` : "";
56686
+ }
56687
+ function metaOf(item) {
56688
+ return [
56689
+ LABELS[item.phase],
56690
+ roleLabel(item.role),
56691
+ `${formatTokensShort(item.tokens)} tokens`,
56692
+ `$${item.cost.toFixed(2)}`,
56693
+ formatElapsed(item.elapsedMs)
56694
+ ];
56695
+ }
56696
+ function paneWidth(viewModel) {
56697
+ return viewModel.twoPane ? Math.floor(viewModel.columns / 2) : viewModel.columns;
56698
+ }
55233
56699
  function RunList({ viewModel, glyphs, depth }) {
56700
+ const cells = paneWidth(viewModel) - 8;
56701
+ const title = windowTitle("runs", viewModel.listWindow);
55234
56702
  return /* @__PURE__ */ jsx_dev_runtime5.jsxDEV(Box_default, {
55235
56703
  flexDirection: "column",
55236
56704
  children: [
55237
56705
  /* @__PURE__ */ jsx_dev_runtime5.jsxDEV(Text, {
55238
- bold: true,
55239
- children: "Runs"
55240
- }, undefined, false, undefined, this),
55241
- viewModel.list.map((item) => /* @__PURE__ */ jsx_dev_runtime5.jsxDEV(Text, {
55242
- wrap: "truncate",
55243
56706
  children: [
55244
56707
  /* @__PURE__ */ jsx_dev_runtime5.jsxDEV(Text, {
55245
- ...item.selected ? colorProps("focus", depth) : {},
55246
- children: item.selected ? glyphs.focus : " "
55247
- }, undefined, false, undefined, this),
55248
- " ",
55249
- /* @__PURE__ */ jsx_dev_runtime5.jsxDEV(Text, {
55250
- ...colorProps(phaseToken(item.phase), depth),
55251
- children: phaseGlyph(item.phase, glyphs)
56708
+ bold: true,
56709
+ children: "Runs"
55252
56710
  }, undefined, false, undefined, this),
55253
- " ",
55254
- joinFields(glyphs, [
55255
- item.id,
55256
- LABELS[item.phase],
55257
- roleLabel(item.role),
55258
- `${formatTokensShort(item.tokens)} tokens`,
55259
- `$${item.cost.toFixed(2)}`,
55260
- formatElapsed(item.elapsedMs)
55261
- ])
56711
+ title === null ? null : /* @__PURE__ */ jsx_dev_runtime5.jsxDEV(Text, {
56712
+ ...colorProps("muted", depth),
56713
+ children: ` ${glyphs.bullet} ${title}`
56714
+ }, undefined, false, undefined, this)
55262
56715
  ]
55263
- }, item.id, true, undefined, this)),
56716
+ }, undefined, true, undefined, this),
56717
+ sliceWindow(viewModel.list, viewModel.listWindow).map((item) => {
56718
+ const meta = metaOf(item);
56719
+ const metaFull = meta.join(` ${glyphs.bullet} `);
56720
+ const marker = clip(markerOf(item, glyphs), cells, glyphs);
56721
+ const markerRoom = Math.max(0, cells - marker.length);
56722
+ const headReserve = Math.min(markerRoom, item.id.length + 2 + SUMMARY_RESERVE);
56723
+ const headRoom = viewModel.twoPane ? markerRoom : Math.max(markerRoom - metaFull.length, headReserve);
56724
+ const head = clipHead(item, headRoom, glyphs);
56725
+ const clippedMeta = clip(metaFull, Math.max(0, markerRoom - head.length), glyphs);
56726
+ const selected = item.selected;
56727
+ return /* @__PURE__ */ jsx_dev_runtime5.jsxDEV(Text, {
56728
+ wrap: "truncate",
56729
+ ...selected ? { bold: true } : {},
56730
+ children: [
56731
+ /* @__PURE__ */ jsx_dev_runtime5.jsxDEV(Text, {
56732
+ ...selected ? colorProps("focus", depth) : {},
56733
+ children: selected ? glyphs.focus : " "
56734
+ }, undefined, false, undefined, this),
56735
+ " ",
56736
+ /* @__PURE__ */ jsx_dev_runtime5.jsxDEV(Text, {
56737
+ ...colorProps(phaseToken(item.phase), depth),
56738
+ children: phaseGlyph(item.phase, glyphs)
56739
+ }, undefined, false, undefined, this),
56740
+ " ",
56741
+ head,
56742
+ marker === "" ? null : /* @__PURE__ */ jsx_dev_runtime5.jsxDEV(Text, {
56743
+ bold: true,
56744
+ children: marker
56745
+ }, undefined, false, undefined, this),
56746
+ clippedMeta === "" ? null : /* @__PURE__ */ jsx_dev_runtime5.jsxDEV(jsx_dev_runtime5.Fragment, {
56747
+ children: [
56748
+ " ",
56749
+ glyphs.bullet,
56750
+ " "
56751
+ ]
56752
+ }, undefined, true, undefined, this),
56753
+ clippedMeta === metaFull ? /* @__PURE__ */ jsx_dev_runtime5.jsxDEV(jsx_dev_runtime5.Fragment, {
56754
+ children: [
56755
+ /* @__PURE__ */ jsx_dev_runtime5.jsxDEV(Text, {
56756
+ children: meta[0] ?? ""
56757
+ }, undefined, false, undefined, this),
56758
+ ` ${glyphs.bullet} `,
56759
+ /* @__PURE__ */ jsx_dev_runtime5.jsxDEV(Text, {
56760
+ children: meta[1] ?? ""
56761
+ }, undefined, false, undefined, this),
56762
+ ` ${glyphs.bullet} `,
56763
+ /* @__PURE__ */ jsx_dev_runtime5.jsxDEV(Text, {
56764
+ ...colorProps("muted", depth),
56765
+ children: `${meta[2] ?? ""} ${glyphs.bullet} ${meta[3] ?? ""} ${glyphs.bullet} ${meta[4] ?? ""}`
56766
+ }, undefined, false, undefined, this)
56767
+ ]
56768
+ }, undefined, true, undefined, this) : /* @__PURE__ */ jsx_dev_runtime5.jsxDEV(Text, {
56769
+ ...colorProps("muted", depth),
56770
+ children: clippedMeta
56771
+ }, undefined, false, undefined, this)
56772
+ ]
56773
+ }, item.id, true, undefined, this);
56774
+ }),
55264
56775
  viewModel.notice === null ? null : /* @__PURE__ */ jsx_dev_runtime5.jsxDEV(Text, {
55265
56776
  ...colorProps("muted", depth),
55266
56777
  wrap: "truncate",
@@ -55272,64 +56783,112 @@ function RunList({ viewModel, glyphs, depth }) {
55272
56783
 
55273
56784
  // packages/tui/src/views/task-detail.tsx
55274
56785
  var jsx_dev_runtime6 = __toESM(require_jsx_dev_runtime(), 1);
55275
- function TaskDetail({ detail, glyphs, depth }) {
55276
- const { task, agent, retries, gates, activity } = detail;
55277
- const agentLine = agent === null ? "agent (none)" : joinFields(glyphs, [
55278
- `agent ${agent.role}`,
55279
- `model ${agent.model === "" ? "unknown" : agent.model}`,
55280
- `duration ${agent.durationMs === null ? "-" : formatElapsed(agent.durationMs)}`
55281
- ]);
56786
+ var FACT_LABELS = [
56787
+ "task",
56788
+ "status",
56789
+ "repo",
56790
+ "attempt",
56791
+ "retries",
56792
+ "agent",
56793
+ "model",
56794
+ "duration"
56795
+ ];
56796
+ function windowGates(gates, rows) {
56797
+ if (rows <= 0)
56798
+ return { shown: [], more: gates.length };
56799
+ if (gates.length <= rows)
56800
+ return { shown: gates, more: 0 };
56801
+ const shown = gates.slice(0, rows - 1);
56802
+ return { shown, more: gates.length - shown.length };
56803
+ }
56804
+ function factsOf(detail, glyphs) {
56805
+ const { task, agent, retries } = detail;
56806
+ return [
56807
+ {
56808
+ label: "task",
56809
+ value: `${task.id} ${glyphs.bullet} ${task.title}`,
56810
+ bold: true
56811
+ },
56812
+ { label: "status", value: task.status, bold: false },
56813
+ { label: "repo", value: task.repo, bold: false },
56814
+ { label: "attempt", value: String(task.attempt), bold: false },
56815
+ { label: "retries", value: String(retries), bold: false },
56816
+ { label: "agent", value: agent === null ? "(none)" : agent.role, bold: false },
56817
+ {
56818
+ label: "model",
56819
+ value: agent === null || agent.model === "" ? "unknown" : agent.model,
56820
+ bold: false
56821
+ },
56822
+ {
56823
+ label: "duration",
56824
+ value: agent === null || agent.durationMs === null ? "-" : formatElapsed(agent.durationMs),
56825
+ bold: false
56826
+ }
56827
+ ];
56828
+ }
56829
+ function TaskDetail({
56830
+ detail,
56831
+ glyphs,
56832
+ depth,
56833
+ maxLines,
56834
+ gateRows,
56835
+ columns
56836
+ }) {
56837
+ const { gates, activity } = detail;
56838
+ const facts = factsOf(detail, glyphs);
56839
+ const labelWidth = Math.max(...FACT_LABELS.map((label) => label.length));
56840
+ const nameWidth = gates.reduce((width, gate) => Math.max(width, gate.name.length), 0);
56841
+ const statusWidth = gates.reduce((width, gate) => Math.max(width, gate.status.length), 0);
56842
+ const widths = { name: nameWidth, status: statusWidth };
56843
+ const gateWindow = windowGates(gates, gateRows);
56844
+ const foldedGates = gateRows <= 0 && gates.length > 0;
56845
+ const valueRoom = Math.max(0, columns - labelWidth - 1);
55282
56846
  return /* @__PURE__ */ jsx_dev_runtime6.jsxDEV(Box_default, {
55283
56847
  flexDirection: "column",
55284
56848
  children: [
55285
- /* @__PURE__ */ jsx_dev_runtime6.jsxDEV(Text, {
55286
- bold: true,
56849
+ facts.map((fact) => /* @__PURE__ */ jsx_dev_runtime6.jsxDEV(Text, {
55287
56850
  wrap: "truncate",
55288
56851
  children: [
55289
- task.id,
55290
- " ",
55291
- glyphs.bullet,
56852
+ /* @__PURE__ */ jsx_dev_runtime6.jsxDEV(Text, {
56853
+ ...colorProps("muted", depth),
56854
+ children: fact.label.padEnd(labelWidth)
56855
+ }, undefined, false, undefined, this),
55292
56856
  " ",
55293
- truncate2(task.title, 56)
56857
+ /* @__PURE__ */ jsx_dev_runtime6.jsxDEV(Text, {
56858
+ ...fact.bold ? { bold: true } : {},
56859
+ children: clip(fact.value, valueRoom, glyphs)
56860
+ }, undefined, false, undefined, this)
55294
56861
  ]
55295
- }, undefined, true, undefined, this),
55296
- /* @__PURE__ */ jsx_dev_runtime6.jsxDEV(Text, {
55297
- wrap: "truncate",
55298
- children: joinFields(glyphs, [
55299
- `status ${task.status}`,
55300
- `repo ${task.repo}`,
55301
- `attempt ${task.attempt}`
55302
- ])
55303
- }, undefined, false, undefined, this),
55304
- /* @__PURE__ */ jsx_dev_runtime6.jsxDEV(Text, {
55305
- wrap: "truncate",
55306
- children: agentLine
55307
- }, undefined, false, undefined, this),
55308
- /* @__PURE__ */ jsx_dev_runtime6.jsxDEV(Text, {
55309
- children: `retries ${retries}`
55310
- }, undefined, false, undefined, this),
56862
+ }, fact.label, true, undefined, this)),
55311
56863
  /* @__PURE__ */ jsx_dev_runtime6.jsxDEV(Text, {
55312
56864
  bold: true,
55313
- children: "Gates"
56865
+ children: foldedGates ? `Gates ${glyphs.bullet} ${gateWindow.more} hidden` : "Gates"
55314
56866
  }, undefined, false, undefined, this),
55315
56867
  gates.length === 0 ? /* @__PURE__ */ jsx_dev_runtime6.jsxDEV(Text, {
55316
56868
  ...colorProps("muted", depth),
55317
56869
  children: "no gate results"
55318
- }, undefined, false, undefined, this) : gates.map((gate) => /* @__PURE__ */ jsx_dev_runtime6.jsxDEV(Text, {
55319
- wrap: "truncate",
56870
+ }, undefined, false, undefined, this) : /* @__PURE__ */ jsx_dev_runtime6.jsxDEV(jsx_dev_runtime6.Fragment, {
55320
56871
  children: [
55321
- /* @__PURE__ */ jsx_dev_runtime6.jsxDEV(Text, {
55322
- ...colorProps(statusToken(gate.status), depth),
55323
- children: statusGlyph2(gate.status, glyphs)
55324
- }, undefined, false, undefined, this),
55325
- " ",
55326
- gate.name,
55327
- " ",
55328
- gate.status,
55329
- " ",
55330
- formatElapsed(gate.durationMs)
56872
+ gateWindow.shown.map((gate) => {
56873
+ const glyph = statusGlyph(gate.status, glyphs);
56874
+ return /* @__PURE__ */ jsx_dev_runtime6.jsxDEV(Text, {
56875
+ wrap: "truncate",
56876
+ children: [
56877
+ /* @__PURE__ */ jsx_dev_runtime6.jsxDEV(Text, {
56878
+ ...colorProps(statusToken(gate.status), depth),
56879
+ children: glyph
56880
+ }, undefined, false, undefined, this),
56881
+ " ",
56882
+ clip(gateLine(gate.name, gate.status, formatElapsed(gate.durationMs), widths), Math.max(0, columns - glyph.length - 1), glyphs)
56883
+ ]
56884
+ }, `${gate.step}-${gate.name}`, true, undefined, this);
56885
+ }),
56886
+ gateWindow.more === 0 || foldedGates ? null : /* @__PURE__ */ jsx_dev_runtime6.jsxDEV(Text, {
56887
+ ...colorProps("muted", depth),
56888
+ children: `${gateWindow.more} more gates`
56889
+ }, undefined, false, undefined, this)
55331
56890
  ]
55332
- }, `${gate.step}-${gate.name}`, true, undefined, this)),
56891
+ }, undefined, true, undefined, this),
55333
56892
  /* @__PURE__ */ jsx_dev_runtime6.jsxDEV(Text, {
55334
56893
  bold: true,
55335
56894
  children: "Activity"
@@ -55337,7 +56896,9 @@ function TaskDetail({ detail, glyphs, depth }) {
55337
56896
  /* @__PURE__ */ jsx_dev_runtime6.jsxDEV(ActivityTail, {
55338
56897
  lines: activity,
55339
56898
  glyphs,
55340
- depth
56899
+ depth,
56900
+ maxLines,
56901
+ columns
55341
56902
  }, undefined, false, undefined, this)
55342
56903
  ]
55343
56904
  }, undefined, true, undefined, this);
@@ -55345,45 +56906,109 @@ function TaskDetail({ detail, glyphs, depth }) {
55345
56906
 
55346
56907
  // packages/tui/src/views/task-graph.tsx
55347
56908
  var jsx_dev_runtime7 = __toESM(require_jsx_dev_runtime(), 1);
55348
- function TaskGraph({ tasks, glyphs, depth }) {
56909
+ function TaskGraph({ tasks, window: window2, glyphs, depth, columns }) {
56910
+ const title = windowTitle("tasks", window2);
55349
56911
  return /* @__PURE__ */ jsx_dev_runtime7.jsxDEV(Box_default, {
55350
56912
  flexDirection: "column",
55351
56913
  children: [
55352
56914
  /* @__PURE__ */ jsx_dev_runtime7.jsxDEV(Text, {
55353
- bold: true,
55354
- children: "Tasks"
55355
- }, undefined, false, undefined, this),
55356
- tasks.map((task) => /* @__PURE__ */ jsx_dev_runtime7.jsxDEV(Text, {
55357
- wrap: "truncate",
55358
56915
  children: [
55359
56916
  /* @__PURE__ */ jsx_dev_runtime7.jsxDEV(Text, {
55360
- ...task.selected ? colorProps("focus", depth) : {},
55361
- children: task.selected ? glyphs.focus : " "
55362
- }, undefined, false, undefined, this),
55363
- " ",
55364
- "[",
55365
- /* @__PURE__ */ jsx_dev_runtime7.jsxDEV(Text, {
55366
- ...colorProps(statusToken(task.status), depth),
55367
- children: statusGlyph2(task.status, glyphs)
56917
+ bold: true,
56918
+ children: "Tasks"
55368
56919
  }, undefined, false, undefined, this),
55369
- "] ",
55370
- task.id,
55371
- " ",
55372
- task.status,
55373
- " ",
55374
- task.repo,
55375
- " attempt ",
55376
- task.attempt,
55377
- " ",
55378
- truncate2(task.title, 40)
56920
+ title === null ? null : /* @__PURE__ */ jsx_dev_runtime7.jsxDEV(Text, {
56921
+ ...colorProps("muted", depth),
56922
+ children: ` ${glyphs.bullet} ${title}`
56923
+ }, undefined, false, undefined, this)
55379
56924
  ]
55380
- }, task.id, true, undefined, this))
56925
+ }, undefined, true, undefined, this),
56926
+ sliceWindow(tasks, window2).map((task) => {
56927
+ const marker = task.selected ? glyphs.focus : " ";
56928
+ const glyph = statusGlyph(task.status, glyphs);
56929
+ const head = `${marker} [${glyph}] `;
56930
+ const rest = `${task.id} ${task.status} ${task.repo} attempt ${task.attempt} ${task.title}`;
56931
+ if (columns <= head.length) {
56932
+ return /* @__PURE__ */ jsx_dev_runtime7.jsxDEV(Text, {
56933
+ wrap: "truncate",
56934
+ ...task.selected ? { bold: true } : {},
56935
+ children: clip(`${head}${rest}`, columns, glyphs)
56936
+ }, task.id, false, undefined, this);
56937
+ }
56938
+ return /* @__PURE__ */ jsx_dev_runtime7.jsxDEV(Text, {
56939
+ wrap: "truncate",
56940
+ ...task.selected ? { bold: true } : {},
56941
+ children: [
56942
+ /* @__PURE__ */ jsx_dev_runtime7.jsxDEV(Text, {
56943
+ ...task.selected ? colorProps("focus", depth) : {},
56944
+ children: marker
56945
+ }, undefined, false, undefined, this),
56946
+ " [",
56947
+ /* @__PURE__ */ jsx_dev_runtime7.jsxDEV(Text, {
56948
+ ...colorProps(statusToken(task.status), depth),
56949
+ children: glyph
56950
+ }, undefined, false, undefined, this),
56951
+ "]",
56952
+ " ",
56953
+ clip(rest, columns - head.length, glyphs)
56954
+ ]
56955
+ }, task.id, true, undefined, this);
56956
+ })
56957
+ ]
56958
+ }, undefined, true, undefined, this);
56959
+ }
56960
+
56961
+ // packages/tui/src/views/run-view.tsx
56962
+ var jsx_dev_runtime8 = __toESM(require_jsx_dev_runtime(), 1);
56963
+ function singlePaneBudget(viewModel) {
56964
+ const window2 = viewModel.taskWindow;
56965
+ const run = viewModel.run;
56966
+ const budget = singlePaneTailRows(viewModel);
56967
+ if (run === null)
56968
+ return { window: window2, tailRows: budget };
56969
+ const chrome = 2;
56970
+ const shownTasks = Math.min(run.tasks.length, window2.size);
56971
+ const overflow = Math.max(0, run.activity.length - Math.max(0, budget - chrome));
56972
+ const shortfall = Math.max(0, chrome + TAIL_FLOOR - budget);
56973
+ const removed = Math.min(chrome, shownTasks, overflow, shortfall);
56974
+ const size = Math.max(0, window2.size - removed);
56975
+ const index = run.tasks.findIndex((task) => task.selected);
56976
+ return {
56977
+ window: {
56978
+ offset: nextOffset(window2.offset, index, window2.total, size),
56979
+ size,
56980
+ total: window2.total
56981
+ },
56982
+ tailRows: Math.max(0, budget - chrome + removed)
56983
+ };
56984
+ }
56985
+ function ActivitySection({
56986
+ lines,
56987
+ glyphs,
56988
+ depth,
56989
+ maxLines,
56990
+ spaced,
56991
+ columns
56992
+ }) {
56993
+ return /* @__PURE__ */ jsx_dev_runtime8.jsxDEV(jsx_dev_runtime8.Fragment, {
56994
+ children: [
56995
+ spaced ? /* @__PURE__ */ jsx_dev_runtime8.jsxDEV(Text, {
56996
+ children: " "
56997
+ }, undefined, false, undefined, this) : null,
56998
+ /* @__PURE__ */ jsx_dev_runtime8.jsxDEV(Text, {
56999
+ bold: true,
57000
+ children: "Activity"
57001
+ }, undefined, false, undefined, this),
57002
+ /* @__PURE__ */ jsx_dev_runtime8.jsxDEV(ActivityTail, {
57003
+ lines,
57004
+ glyphs,
57005
+ depth,
57006
+ maxLines,
57007
+ columns
57008
+ }, undefined, false, undefined, this)
55381
57009
  ]
55382
57010
  }, undefined, true, undefined, this);
55383
57011
  }
55384
-
55385
- // packages/tui/src/views/run-view.tsx
55386
- var jsx_dev_runtime8 = __toESM(require_jsx_dev_runtime(), 1);
55387
57012
  function RunView({ viewModel, glyphs, depth, twoPane }) {
55388
57013
  const run = viewModel.run;
55389
57014
  if (run === null) {
@@ -55391,13 +57016,19 @@ function RunView({ viewModel, glyphs, depth, twoPane }) {
55391
57016
  children: "No run selected."
55392
57017
  }, undefined, false, undefined, this);
55393
57018
  }
57019
+ const single = singlePaneBudget(viewModel);
57020
+ const inner = Math.max(0, viewModel.columns - 2);
57021
+ const leftWidth = Math.max(0, Math.floor(inner / 2) - 1);
57022
+ const rightWidth = Math.max(0, inner - leftWidth - 1);
55394
57023
  return /* @__PURE__ */ jsx_dev_runtime8.jsxDEV(Box_default, {
55395
57024
  flexDirection: "column",
57025
+ paddingX: 1,
55396
57026
  children: [
55397
57027
  /* @__PURE__ */ jsx_dev_runtime8.jsxDEV(RunHeader, {
55398
57028
  run,
55399
57029
  glyphs,
55400
- depth
57030
+ depth,
57031
+ columns: inner
55401
57032
  }, undefined, false, undefined, this),
55402
57033
  viewModel.notice === null ? null : /* @__PURE__ */ jsx_dev_runtime8.jsxDEV(Text, {
55403
57034
  ...colorProps("muted", depth),
@@ -55409,37 +57040,62 @@ function RunView({ viewModel, glyphs, depth, twoPane }) {
55409
57040
  children: [
55410
57041
  /* @__PURE__ */ jsx_dev_runtime8.jsxDEV(Box_default, {
55411
57042
  flexDirection: "column",
55412
- width: Math.floor(viewModel.columns / 2),
57043
+ width: leftWidth,
55413
57044
  children: /* @__PURE__ */ jsx_dev_runtime8.jsxDEV(TaskGraph, {
55414
57045
  tasks: run.tasks,
57046
+ window: viewModel.taskWindow,
55415
57047
  glyphs,
55416
- depth
57048
+ depth,
57049
+ columns: leftWidth
55417
57050
  }, undefined, false, undefined, this)
55418
57051
  }, undefined, false, undefined, this),
55419
57052
  /* @__PURE__ */ jsx_dev_runtime8.jsxDEV(Box_default, {
55420
57053
  flexDirection: "column",
55421
57054
  flexGrow: 1,
55422
57055
  paddingLeft: 1,
55423
- children: run.detail === null ? /* @__PURE__ */ jsx_dev_runtime8.jsxDEV(ActivityTail, {
57056
+ children: run.detail === null ? /* @__PURE__ */ jsx_dev_runtime8.jsxDEV(ActivitySection, {
55424
57057
  lines: run.activity,
55425
57058
  glyphs,
55426
57059
  depth,
55427
- maxLines: Math.max(0, viewModel.rows - 6)
57060
+ maxLines: Math.max(0, twoPaneTailRows(viewModel) - 2),
57061
+ spaced: true,
57062
+ columns: rightWidth
55428
57063
  }, undefined, false, undefined, this) : /* @__PURE__ */ jsx_dev_runtime8.jsxDEV(TaskDetail, {
55429
57064
  detail: run.detail,
55430
57065
  glyphs,
55431
- depth
57066
+ depth,
57067
+ maxLines: taskDetailTailRows(viewModel),
57068
+ gateRows: taskDetailGateRows(viewModel),
57069
+ columns: rightWidth
55432
57070
  }, undefined, false, undefined, this)
55433
57071
  }, undefined, false, undefined, this)
55434
57072
  ]
55435
- }, undefined, true, undefined, this) : run.detail === null ? /* @__PURE__ */ jsx_dev_runtime8.jsxDEV(TaskGraph, {
55436
- tasks: run.tasks,
55437
- glyphs,
55438
- depth
55439
- }, undefined, false, undefined, this) : /* @__PURE__ */ jsx_dev_runtime8.jsxDEV(TaskDetail, {
57073
+ }, undefined, true, undefined, this) : run.detail === null ? /* @__PURE__ */ jsx_dev_runtime8.jsxDEV(Box_default, {
57074
+ flexDirection: "column",
57075
+ children: [
57076
+ /* @__PURE__ */ jsx_dev_runtime8.jsxDEV(TaskGraph, {
57077
+ tasks: run.tasks,
57078
+ window: single.window,
57079
+ glyphs,
57080
+ depth,
57081
+ columns: inner
57082
+ }, undefined, false, undefined, this),
57083
+ /* @__PURE__ */ jsx_dev_runtime8.jsxDEV(ActivitySection, {
57084
+ lines: run.activity,
57085
+ glyphs,
57086
+ depth,
57087
+ maxLines: single.tailRows,
57088
+ spaced: true,
57089
+ columns: inner
57090
+ }, undefined, false, undefined, this)
57091
+ ]
57092
+ }, undefined, true, undefined, this) : /* @__PURE__ */ jsx_dev_runtime8.jsxDEV(TaskDetail, {
55440
57093
  detail: run.detail,
55441
57094
  glyphs,
55442
- depth
57095
+ depth,
57096
+ maxLines: taskDetailTailRows(viewModel),
57097
+ gateRows: taskDetailGateRows(viewModel),
57098
+ columns: inner
55443
57099
  }, undefined, false, undefined, this)
55444
57100
  ]
55445
57101
  }, undefined, true, undefined, this);
@@ -55449,6 +57105,7 @@ function RunView({ viewModel, glyphs, depth, twoPane }) {
55449
57105
  var jsx_dev_runtime9 = __toESM(require_jsx_dev_runtime(), 1);
55450
57106
  function Frame({ viewModel, glyphs, depth }) {
55451
57107
  const run = viewModel.run;
57108
+ const previewColumns = Math.max(0, viewModel.columns - Math.floor(viewModel.columns / 2) - 1);
55452
57109
  return /* @__PURE__ */ jsx_dev_runtime9.jsxDEV(Box_default, {
55453
57110
  flexDirection: "column",
55454
57111
  width: viewModel.columns,
@@ -55457,11 +57114,12 @@ function Frame({ viewModel, glyphs, depth }) {
55457
57114
  /* @__PURE__ */ jsx_dev_runtime9.jsxDEV(Box_default, {
55458
57115
  flexDirection: "column",
55459
57116
  flexGrow: 1,
55460
- overflowY: "hidden",
55461
57117
  children: viewModel.panel !== null ? /* @__PURE__ */ jsx_dev_runtime9.jsxDEV(PanelBox, {
55462
57118
  panel: viewModel.panel,
55463
57119
  glyphs,
55464
- depth
57120
+ depth,
57121
+ rows: viewModel.rows,
57122
+ columns: viewModel.columns
55465
57123
  }, undefined, false, undefined, this) : viewModel.screen === "list" ? viewModel.twoPane && run !== null ? /* @__PURE__ */ jsx_dev_runtime9.jsxDEV(Box_default, {
55466
57124
  flexDirection: "row",
55467
57125
  children: [
@@ -55482,13 +57140,15 @@ function Frame({ viewModel, glyphs, depth }) {
55482
57140
  /* @__PURE__ */ jsx_dev_runtime9.jsxDEV(RunHeader, {
55483
57141
  run,
55484
57142
  glyphs,
55485
- depth
57143
+ depth,
57144
+ columns: previewColumns
55486
57145
  }, undefined, false, undefined, this),
55487
57146
  /* @__PURE__ */ jsx_dev_runtime9.jsxDEV(ActivityTail, {
55488
57147
  lines: run.activity,
55489
57148
  glyphs,
55490
57149
  depth,
55491
- maxLines: Math.max(0, viewModel.rows - 6)
57150
+ maxLines: twoPaneTailRows(viewModel),
57151
+ columns: previewColumns
55492
57152
  }, undefined, false, undefined, this)
55493
57153
  ]
55494
57154
  }, undefined, true, undefined, this)
@@ -55507,7 +57167,8 @@ function Frame({ viewModel, glyphs, depth }) {
55507
57167
  /* @__PURE__ */ jsx_dev_runtime9.jsxDEV(KeyFooter, {
55508
57168
  hints: viewModel.footer,
55509
57169
  glyphs,
55510
- depth
57170
+ depth,
57171
+ columns: viewModel.columns
55511
57172
  }, undefined, false, undefined, this)
55512
57173
  ]
55513
57174
  }, undefined, true, undefined, this);
@@ -55585,6 +57246,10 @@ function keyName2(input, key) {
55585
57246
  return "Up";
55586
57247
  if (key.downArrow)
55587
57248
  return "Down";
57249
+ if (key.pageUp)
57250
+ return "PgUp";
57251
+ if (key.pageDown)
57252
+ return "PgDn";
55588
57253
  return input;
55589
57254
  }
55590
57255
  function isReadOnly(view) {
@@ -55600,63 +57265,61 @@ var REPLAY_WRITE_KEYS = new Set([
55600
57265
  "r",
55601
57266
  "x",
55602
57267
  "t",
57268
+ "l",
55603
57269
  "Q"
55604
57270
  ]);
55605
57271
  function replayKey(view, input, key) {
55606
57272
  if (key.ctrl && input === "c")
55607
- return { quit: true, notice: null };
55608
- if (!key.ctrl && input === "q")
55609
- return { quit: true, notice: null };
55610
- if (isReadOnly(view) && REPLAY_WRITE_KEYS.has(input)) {
55611
- return { quit: false, notice: REPLAY_READ_ONLY };
55612
- }
55613
- return { quit: false, notice: null };
55614
- }
55615
- function selectedRunState(data) {
55616
- const id = data.selectedRunId;
55617
- if (id === null)
55618
- return;
55619
- return data.status.runs.find((run) => run.id === id) ?? data.runs.find((run) => run.id === id);
55620
- }
55621
- function grantedCommit2(snapshot) {
55622
- const approval = snapshot?.approval ?? null;
55623
- return approval === null || approval.approver === "" ? null : approval.specCommit;
55624
- }
55625
- function evidenceOf(data) {
55626
- return {
55627
- identity: data.identity ?? "",
55628
- findings: selectedRunState(data)?.specFindings.length ?? 0,
55629
- specCommit: grantedCommit2(data.snapshot)
55630
- };
55631
- }
55632
- function panelOpen(data) {
55633
- return data.intake !== null || data.questions !== null || data.confirmation !== null || data.help;
55634
- }
55635
- function syncApproval(data) {
55636
- if (data.screen !== "run" || data.selectedRunId === null)
55637
- return data;
55638
- const run = selectedRunState(data);
55639
- const phase = run?.phase ?? data.snapshot?.phase ?? null;
55640
- if (data.approval === null) {
55641
- if (panelOpen(data))
55642
- return data;
55643
- if (phase === null)
55644
- return data;
55645
- const opened = approvalForPhase(phase, null);
55646
- return opened === null ? data : { ...data, approval: opened, identity: null };
57273
+ return { quit: true, notice: null, help: null };
57274
+ if (view.panel?.kind === "help") {
57275
+ const outcome = helpKeys(input, key);
57276
+ if (outcome === "quit")
57277
+ return { quit: true, notice: null, help: null };
57278
+ return { quit: false, notice: null, help: outcome === "close" ? false : null };
55647
57279
  }
55648
- if ((data.approval.kind === "idle" || data.approval.kind === "failed") && phase !== null && phase !== "awaiting-approval") {
55649
- return { ...data, approval: null };
57280
+ if (!key.ctrl && input === "q")
57281
+ return { quit: true, notice: null, help: null };
57282
+ if (!key.ctrl && input === "?" && view.footer.some((hint) => hint.key === "?")) {
57283
+ return { quit: false, notice: null, help: true };
55650
57284
  }
55651
- if (data.approval.kind !== "waiting")
55652
- return data;
55653
- const next = approvalProgress(data.approval, {
55654
- phase,
55655
- granted: grantedCommit2(data.snapshot) !== null
55656
- });
55657
- if (next === data.approval)
55658
- return data;
55659
- return { ...data, approval: next.kind === "done" ? null : next };
57285
+ if (isReadOnly(view) && REPLAY_WRITE_KEYS.has(input)) {
57286
+ return { quit: false, notice: REPLAY_READ_ONLY, help: null };
57287
+ }
57288
+ return { quit: false, notice: null, help: null };
57289
+ }
57290
+ function replayHelpView(view) {
57291
+ const panel = helpPanel();
57292
+ return { ...view, panel, footer: panel.keys };
57293
+ }
57294
+ function replayActivityView(view, state, glyphs) {
57295
+ if (view.run === null)
57296
+ return view;
57297
+ const panel = activityPanePanel({ run: view.run, state, glyphs, rows: view.rows });
57298
+ return { ...view, panel, footer: panel.keys };
57299
+ }
57300
+ function approvalKeyRoute(data, key, input) {
57301
+ if (data.approval === null)
57302
+ return "run";
57303
+ if (data.screen !== "run")
57304
+ return "overlay";
57305
+ if (data.approvalCollapsed === true) {
57306
+ if (key.escape)
57307
+ return "overlay";
57308
+ if (!key.ctrl && (input === "a" || input === "A" || input === "R"))
57309
+ return "reopen";
57310
+ return "run";
57311
+ }
57312
+ if (key.escape && (data.approval.kind === "idle" || data.approval.kind === "failed")) {
57313
+ return "collapse";
57314
+ }
57315
+ return "overlay";
57316
+ }
57317
+ function quitsOnKey(data, input, key) {
57318
+ if (key.ctrl && input === "c")
57319
+ return true;
57320
+ if (key.ctrl || input !== "q")
57321
+ return false;
57322
+ return !(data.intake !== null || data.questions?.focus === "composer" || (data.reword ?? null) !== null);
55660
57323
  }
55661
57324
  function viewOf(data, glyphs) {
55662
57325
  const baseInput = {
@@ -55672,13 +57335,27 @@ function viewOf(data, glyphs) {
55672
57335
  selectedRunId: data.selectedRunId,
55673
57336
  selectedTaskId: data.selectedTaskId,
55674
57337
  panel: null,
55675
- notice: data.notice
57338
+ notice: data.notice,
57339
+ listOffset: data.listOffset ?? 0,
57340
+ taskOffset: data.taskOffset ?? 0
55676
57341
  };
55677
57342
  const base = buildViewModel(baseInput);
57343
+ const activity = data.activity ?? null;
55678
57344
  if (data.help) {
55679
57345
  return buildViewModel({ ...baseInput, panel: helpPanel() });
55680
57346
  }
55681
- if (data.approval !== null && data.screen === "run") {
57347
+ if (activity !== null && base.run !== null) {
57348
+ return buildViewModel({
57349
+ ...baseInput,
57350
+ panel: activityPanePanel({
57351
+ run: base.run,
57352
+ state: activity,
57353
+ glyphs,
57354
+ rows: data.rows
57355
+ })
57356
+ });
57357
+ }
57358
+ if (data.approval !== null && data.screen === "run" && data.approvalCollapsed !== true) {
55682
57359
  if (base.run === null)
55683
57360
  return base;
55684
57361
  const run = selectedRunState(data);
@@ -55691,13 +57368,24 @@ function viewOf(data, glyphs) {
55691
57368
  });
55692
57369
  return buildViewModel({ ...baseInput, panel });
55693
57370
  }
57371
+ const reword = data.reword ?? null;
57372
+ if (reword !== null && base.run !== null) {
57373
+ const panel = rewordPanel({
57374
+ run: base.run,
57375
+ state: reword,
57376
+ glyphs,
57377
+ rows: data.rows,
57378
+ columns: data.columns
57379
+ });
57380
+ return buildViewModel({ ...baseInput, panel });
57381
+ }
55694
57382
  if (data.intake !== null) {
55695
57383
  return buildViewModel({ ...baseInput, panel: intakePanel(data.intake, glyphs, data.rows) });
55696
57384
  }
55697
57385
  if (data.questions !== null && base.run !== null) {
55698
57386
  return buildViewModel({
55699
57387
  ...baseInput,
55700
- panel: questionsPanel({ run: base.run, state: data.questions, glyphs })
57388
+ panel: questionsPanel({ run: base.run, state: data.questions, glyphs, rows: data.rows })
55701
57389
  });
55702
57390
  }
55703
57391
  if (data.confirmation !== null) {
@@ -55717,12 +57405,18 @@ function initialData(options, status, runs, glyphs) {
55717
57405
  snapshot: null,
55718
57406
  facts: collectFacts([]),
55719
57407
  notice: null,
57408
+ listOffset: 0,
57409
+ taskOffset: 0,
55720
57410
  intake: null,
55721
57411
  approval: null,
57412
+ approvalCollapsed: false,
55722
57413
  questions: null,
57414
+ activity: null,
57415
+ reword: null,
55723
57416
  confirmation: null,
55724
57417
  help: false,
55725
- identity: null
57418
+ identity: null,
57419
+ pendingLand: null
55726
57420
  };
55727
57421
  const view = viewOf(base, glyphs);
55728
57422
  return { ...base, selectedRunId: view.list[0]?.id ?? null };
@@ -55738,77 +57432,6 @@ function gitExec(args, cwd) {
55738
57432
  });
55739
57433
  });
55740
57434
  }
55741
- async function performControl(deps, action) {
55742
- switch (action.kind) {
55743
- case "abort":
55744
- await deps.factory.abort(action.id);
55745
- return null;
55746
- case "retry":
55747
- await deps.factory.retry(action.id, action.taskId);
55748
- return null;
55749
- case "resume":
55750
- return deps.launcher.launch({ kind: "resume", id: action.id });
55751
- default: {
55752
- const unhandled = action;
55753
- throw new Error(`unknown control action: ${String(unhandled)}`);
55754
- }
55755
- }
55756
- }
55757
- function createResumeGuard() {
55758
- const inFlight = new Set;
55759
- return {
55760
- begin(id) {
55761
- if (inFlight.has(id))
55762
- return false;
55763
- inFlight.add(id);
55764
- return true;
55765
- },
55766
- end(id) {
55767
- inFlight.delete(id);
55768
- }
55769
- };
55770
- }
55771
- function resumeFailed(data, id, logPath, code) {
55772
- const tail = tailLog(logPath, 10);
55773
- const failed = data.approval === null ? null : approvalExited(data.approval, code, tail);
55774
- if (failed !== null && failed !== data.approval)
55775
- return { ...data, approval: failed };
55776
- return {
55777
- ...data,
55778
- notice: [`resume ${id} exited with code ${code}`, ...tail].join(`
55779
- `)
55780
- };
55781
- }
55782
- function startResume(deps, id) {
55783
- if (!deps.guard.begin(id))
55784
- return;
55785
- (async () => {
55786
- let result;
55787
- try {
55788
- result = await performControl(deps, { kind: "resume", id });
55789
- } catch (err) {
55790
- deps.guard.end(id);
55791
- const message = err instanceof Error ? err.message : String(err);
55792
- deps.update((current) => ({ ...current, notice: message }));
55793
- return;
55794
- }
55795
- result.exited.then(({ code }) => {
55796
- deps.guard.end(id);
55797
- if (code === null || code === 0)
55798
- return;
55799
- deps.update((current) => resumeFailed(current, id, result.logPath, code));
55800
- });
55801
- try {
55802
- await deps.refresh();
55803
- } catch (err) {
55804
- const message = err instanceof Error ? err.message : String(err);
55805
- deps.update((current) => ({ ...current, notice: message }));
55806
- }
55807
- })();
55808
- }
55809
- async function recordAnswer(factory, changeId, answer, question) {
55810
- await factory.answer(changeId, answer, question);
55811
- }
55812
57435
  async function runInSession(input) {
55813
57436
  input.session.enter();
55814
57437
  try {
@@ -55888,7 +57511,10 @@ function Interactive({
55888
57511
  notice: null,
55889
57512
  intake: null,
55890
57513
  approval: null,
57514
+ approvalCollapsed: false,
55891
57515
  questions: null,
57516
+ activity: null,
57517
+ reword: null,
55892
57518
  confirmation: null,
55893
57519
  help: false,
55894
57520
  identity: null
@@ -55995,9 +57621,6 @@ function Interactive({
55995
57621
  case "approve-only":
55996
57622
  action = { kind, id };
55997
57623
  break;
55998
- case "reword":
55999
- action = { kind, id };
56000
- break;
56001
57624
  case "reapprove":
56002
57625
  action = { kind, id };
56003
57626
  break;
@@ -56031,48 +57654,59 @@ function Interactive({
56031
57654
  const refreshStatus = import_react27.useCallback(async () => {
56032
57655
  try {
56033
57656
  const [status, runs] = await Promise.all([factory.status(), factory.listRuns()]);
57657
+ const selected = dataRef.current.selectedRunId;
57658
+ if (selected !== null && !status.runs.some((run) => run.id === selected))
57659
+ stopTail();
56034
57660
  const pending = spawnBaseline.current;
56035
57661
  if (pending === null) {
56036
- setData((current) => syncApproval({ ...current, status, runs }));
56037
- return;
57662
+ setData((current) => settleLanding(syncApproval({ ...current, status, runs })));
57663
+ return { status, runs };
56038
57664
  }
56039
57665
  const watch = watchSpawn(pending.ids, status, pending.logPath, tailLog);
56040
57666
  if (watch.started !== null) {
56041
57667
  spawnBaseline.current = null;
56042
- setData((current) => syncApproval({ ...current, status, runs }));
57668
+ setData((current) => settleLanding(syncApproval({ ...current, status, runs })));
56043
57669
  openRun(watch.started);
56044
- return;
57670
+ return { status, runs };
56045
57671
  }
56046
57672
  setData((current) => {
56047
57673
  const intake = current.intake;
56048
- return syncApproval({
57674
+ return settleLanding(syncApproval({
56049
57675
  ...current,
56050
57676
  status,
56051
57677
  runs,
56052
57678
  intake: intake === null || intake.spawned === null ? intake : { ...intake, spawned: { ...intake.spawned, tail: watch.tail } }
56053
- });
57679
+ }));
56054
57680
  });
56055
- } catch {}
56056
- }, [factory, openRun]);
57681
+ return { status, runs };
57682
+ } catch {
57683
+ return null;
57684
+ }
57685
+ }, [factory, openRun, stopTail]);
57686
+ const statusSource = import_react27.useMemo(() => createStatusSource({
57687
+ factory,
57688
+ selectedRunId: () => dataRef.current.screen === "run" ? dataRef.current.selectedRunId : null,
57689
+ pendingSpawn: () => spawnBaseline.current !== null,
57690
+ update: setData,
57691
+ refresh: refreshStatus
57692
+ }), [factory, refreshStatus]);
56057
57693
  const answering = import_react27.useRef(false);
56058
- const submitAnswer = import_react27.useCallback((id, question, answer) => {
57694
+ const recordedAnswers = import_react27.useRef(new Map);
57695
+ const submitAnswer = import_react27.useCallback((id, rawQuestion, question, step, answer) => {
56059
57696
  if (isReadOnly(viewRef.current) || answering.current)
56060
57697
  return;
56061
57698
  answering.current = true;
56062
57699
  (async () => {
56063
57700
  try {
56064
- await recordAnswer(factory, id, answer, question);
57701
+ await recordAnswer(factory, id, answer, rawQuestion);
57702
+ recordedAnswers.current.set(id, withRecordedAnswer(recordedAnswers.current.get(id) ?? new Set, step, question));
57703
+ const run = viewRef.current.run;
56065
57704
  setData((current) => {
56066
- const questions = current.questions;
56067
- if (questions === null || questions.draft === null)
57705
+ if (current.questions === null || run === null)
56068
57706
  return current;
56069
57707
  return {
56070
57708
  ...current,
56071
- questions: {
56072
- ...questions,
56073
- draft: { ...questions.draft, recorded: true },
56074
- notice: null
56075
- }
57709
+ questions: recordAnswerInState(run, current.questions, step, question, current.rows)
56076
57710
  };
56077
57711
  });
56078
57712
  await refreshStatus();
@@ -56085,6 +57719,8 @@ function Interactive({
56085
57719
  })();
56086
57720
  }, [factory, refreshStatus]);
56087
57721
  const resumeGuard = import_react27.useRef(createResumeGuard());
57722
+ const rewordGuard = import_react27.useRef(createResumeGuard());
57723
+ const landGuard = import_react27.useRef(createLandGuard());
56088
57724
  const applyControl = import_react27.useCallback((action) => {
56089
57725
  if (isReadOnly(viewRef.current))
56090
57726
  return;
@@ -56094,7 +57730,20 @@ function Interactive({
56094
57730
  launcher,
56095
57731
  guard: resumeGuard.current,
56096
57732
  update: setData,
56097
- refresh: refreshStatus
57733
+ refresh: async () => {
57734
+ await refreshStatus();
57735
+ }
57736
+ }, action.id);
57737
+ return;
57738
+ }
57739
+ if (action.kind === "land") {
57740
+ startLand({
57741
+ factory,
57742
+ launcher,
57743
+ guard: landGuard.current,
57744
+ update: setData,
57745
+ refresh: refreshStatus,
57746
+ stopTail
56098
57747
  }, action.id);
56099
57748
  return;
56100
57749
  }
@@ -56107,18 +57756,22 @@ function Interactive({
56107
57756
  setData((current) => ({ ...current, notice: message }));
56108
57757
  }
56109
57758
  })();
56110
- }, [factory, launcher, refreshStatus]);
57759
+ }, [factory, launcher, refreshStatus, stopTail]);
56111
57760
  import_react27.useEffect(() => {
56112
57761
  if (isReadOnly(viewRef.current))
56113
57762
  return;
56114
- const poller = createStatusPoller({ poll: refreshStatus });
57763
+ const poller = createStatusPoller({
57764
+ poll: async () => {
57765
+ await statusSource.poll();
57766
+ }
57767
+ });
56115
57768
  pollerRef.current = poller;
56116
57769
  poller.start();
56117
57770
  return () => {
56118
57771
  poller.stop();
56119
57772
  pollerRef.current = null;
56120
57773
  };
56121
- }, [refreshStatus]);
57774
+ }, [statusSource]);
56122
57775
  import_react27.useEffect(() => {
56123
57776
  const onResize = () => {
56124
57777
  setData((current) => ({
@@ -56150,23 +57803,34 @@ function Interactive({
56150
57803
  const keyHandler = import_react27.useRef(() => {});
56151
57804
  keyHandler.current = (input, key) => {
56152
57805
  const state = dataRef.current;
56153
- if (key.ctrl && input === "c" || state.approval !== null && !key.ctrl && input === "q") {
57806
+ if (quitsOnKey(state, input, key)) {
56154
57807
  exit();
56155
57808
  return;
56156
57809
  }
56157
57810
  if (state.approval !== null) {
56158
- const run = selectedRunState(state);
56159
- if (run !== undefined) {
56160
- const outcome = approvalKeys(state.approval, input, key, approvalAvailable(evidenceOf(state)));
56161
- if (outcome.state !== state.approval) {
56162
- setData((current) => ({ ...current, approval: outcome.state }));
57811
+ const route = state.approvalCollapsed === true && panelOpen(state) ? "run" : approvalKeyRoute(state, key, input);
57812
+ if (route === "collapse") {
57813
+ setData((current) => ({ ...current, approvalCollapsed: true }));
57814
+ return;
57815
+ }
57816
+ if (route === "reopen") {
57817
+ setData((current) => ({ ...current, approvalCollapsed: false }));
57818
+ return;
57819
+ }
57820
+ if (route === "overlay") {
57821
+ const run = selectedRunState(state);
57822
+ if (run !== undefined) {
57823
+ const outcome = approvalKeys(state.approval, input, key, approvalAvailable(evidenceOf(state)));
57824
+ if (outcome.state !== state.approval) {
57825
+ setData((current) => ({ ...current, approval: outcome.state }));
57826
+ }
57827
+ if (outcome.launch !== undefined)
57828
+ launchApproval(run.id, outcome.launch);
57829
+ if (outcome.resume === true)
57830
+ applyControl({ kind: "resume", id: run.id });
56163
57831
  }
56164
- if (outcome.launch !== undefined)
56165
- launchApproval(run.id, outcome.launch);
56166
- if (outcome.resume === true)
56167
- applyControl({ kind: "resume", id: run.id });
57832
+ return;
56168
57833
  }
56169
- return;
56170
57834
  }
56171
57835
  if (state.intake !== null) {
56172
57836
  if (key.escape) {
@@ -56187,16 +57851,17 @@ function Interactive({
56187
57851
  if (state.questions !== null) {
56188
57852
  const run = viewRef.current.run;
56189
57853
  if (run !== null) {
56190
- if (key.escape && state.questions.draft === null) {
57854
+ const outcome = questionsKeys(run, state.questions, input, key, state.rows);
57855
+ if (outcome.close === true) {
56191
57856
  setData((current) => ({ ...current, questions: null }));
56192
57857
  return;
56193
57858
  }
56194
- const outcome = questionsKeys(run, state.questions, input, key);
56195
57859
  if (outcome.state !== state.questions) {
56196
57860
  setData((current) => ({ ...current, questions: outcome.state }));
56197
57861
  }
56198
57862
  if (outcome.answer !== undefined) {
56199
- submitAnswer(run.id, outcome.answer.question, outcome.answer.answer);
57863
+ const record = run.questions[state.questions.selected];
57864
+ submitAnswer(run.id, outcome.answer.rawQuestion, outcome.answer.question, record?.step ?? "", outcome.answer.answer);
56200
57865
  }
56201
57866
  }
56202
57867
  return;
@@ -56224,6 +57889,65 @@ function Interactive({
56224
57889
  exit();
56225
57890
  return;
56226
57891
  }
57892
+ const activity = state.activity ?? null;
57893
+ if (activity !== null) {
57894
+ const run = viewRef.current.run;
57895
+ if (run === null) {
57896
+ setData((current) => ({ ...current, activity: null }));
57897
+ return;
57898
+ }
57899
+ const outcome = activityPaneKeys(run, activity, input, key, activityPaneBodyRows(state.rows));
57900
+ if (outcome.close === true) {
57901
+ setData((current) => ({ ...current, activity: null }));
57902
+ return;
57903
+ }
57904
+ if (outcome.state !== activity) {
57905
+ setData((current) => ({ ...current, activity: outcome.state }));
57906
+ }
57907
+ return;
57908
+ }
57909
+ const reword = state.reword ?? null;
57910
+ if (reword !== null) {
57911
+ const run = viewRef.current.run;
57912
+ if (run === null) {
57913
+ setData((current) => ({ ...current, reword: null }));
57914
+ return;
57915
+ }
57916
+ const outcome = rewordKeys(run, reword, input, key, state.rows, state.columns);
57917
+ if (outcome.close === true) {
57918
+ setData((current) => ({ ...current, reword: null }));
57919
+ return;
57920
+ }
57921
+ if (outcome.state !== reword) {
57922
+ setData((current) => ({ ...current, reword: outcome.state }));
57923
+ }
57924
+ if (outcome.launch !== undefined) {
57925
+ startReword({ launcher, guard: rewordGuard.current, update: setData }, run.id, outcome.launch.prompt);
57926
+ }
57927
+ return;
57928
+ }
57929
+ if (!key.ctrl && input === "w" && !panelOpen(state) && state.screen === "run") {
57930
+ const run = viewRef.current.run;
57931
+ if (run !== null) {
57932
+ switch (run.reword.state) {
57933
+ case "available": {
57934
+ const opened = openReword(run);
57935
+ if (opened !== null)
57936
+ setData((current) => ({ ...current, reword: opened }));
57937
+ return;
57938
+ }
57939
+ case "inert":
57940
+ setData((current) => ({ ...current, notice: run.reword.reason }));
57941
+ return;
57942
+ case "absent":
57943
+ return;
57944
+ default: {
57945
+ const unhandled = run.reword.state;
57946
+ throw new Error(`unknown reword state: ${String(unhandled)}`);
57947
+ }
57948
+ }
57949
+ }
57950
+ }
56227
57951
  if (!key.ctrl && input === "n") {
56228
57952
  submitting.current = false;
56229
57953
  setData((current) => ({ ...current, intake: initialIntake }));
@@ -56250,12 +57974,19 @@ function Interactive({
56250
57974
  return;
56251
57975
  case "open-questions": {
56252
57976
  const run = current.run;
56253
- const questions = run === null ? null : openQuestions(run);
57977
+ const questions = run === null ? null : openQuestions(run, recordedAnswers.current.get(run.id) ?? new Set);
56254
57978
  if (questions !== null) {
56255
57979
  setData((state) => ({ ...state, questions, confirmation: null }));
56256
57980
  }
56257
57981
  return;
56258
57982
  }
57983
+ case "open-activity": {
57984
+ const run = current.run;
57985
+ if (run !== null) {
57986
+ setData((state) => ({ ...state, activity: openActivityPane(run) }));
57987
+ }
57988
+ return;
57989
+ }
56259
57990
  case "abort": {
56260
57991
  const action = confirmFor(current);
56261
57992
  if (action !== null) {
@@ -56279,6 +58010,13 @@ function Interactive({
56279
58010
  }
56280
58011
  return;
56281
58012
  }
58013
+ case "land": {
58014
+ const action = landConfirmation(current, landGuard.current);
58015
+ if (action !== null) {
58016
+ setData((state) => ({ ...state, confirmation: action, questions: null }));
58017
+ }
58018
+ return;
58019
+ }
56282
58020
  case "clear-task":
56283
58021
  setData((state) => ({ ...state, selectedTaskId: null }));
56284
58022
  return;
@@ -56288,13 +58026,16 @@ function Interactive({
56288
58026
  foldRef.current = null;
56289
58027
  setData((state) => ({
56290
58028
  ...state,
58029
+ activity: null,
56291
58030
  screen: "list",
56292
58031
  selectedTaskId: null,
56293
58032
  snapshot: null,
56294
58033
  facts: collectFacts([]),
56295
58034
  notice: null,
56296
58035
  approval: null,
58036
+ approvalCollapsed: false,
56297
58037
  questions: null,
58038
+ reword: null,
56298
58039
  confirmation: null,
56299
58040
  help: false,
56300
58041
  identity: null
@@ -56306,9 +58047,16 @@ function Interactive({
56306
58047
  const index = items.findIndex((item) => item.id === current.selectedRunId);
56307
58048
  const step = intent.kind === "next-run" ? 1 : -1;
56308
58049
  const probe = index === -1 ? 0 : index + step;
56309
- const next = items[Math.min(items.length - 1, Math.max(0, probe))];
58050
+ const clamped = Math.min(items.length - 1, Math.max(0, probe));
58051
+ const next = items[clamped];
56310
58052
  if (next !== undefined) {
56311
- setData((state) => ({ ...state, selectedRunId: next.id, selectedTaskId: null }));
58053
+ const offset = nextOffset(current.listWindow.offset, clamped, items.length, current.listWindow.size);
58054
+ setData((state) => ({
58055
+ ...state,
58056
+ selectedRunId: next.id,
58057
+ selectedTaskId: null,
58058
+ listOffset: offset
58059
+ }));
56312
58060
  }
56313
58061
  return;
56314
58062
  }
@@ -56320,12 +58068,82 @@ function Interactive({
56320
58068
  const index = tasks.findIndex((task) => task.selected);
56321
58069
  const step = intent.kind === "next-task" ? 1 : -1;
56322
58070
  const probe = index === -1 ? 0 : index + step;
56323
- const next = tasks[Math.min(tasks.length - 1, Math.max(0, probe))];
58071
+ const clamped = Math.min(tasks.length - 1, Math.max(0, probe));
58072
+ const next = tasks[clamped];
56324
58073
  if (next !== undefined) {
56325
- setData((state) => ({ ...state, selectedTaskId: next.id }));
58074
+ const offset = nextOffset(current.taskWindow.offset, clamped, tasks.length, current.taskWindow.size);
58075
+ setData((state) => ({ ...state, selectedTaskId: next.id, taskOffset: offset }));
56326
58076
  }
56327
58077
  return;
56328
58078
  }
58079
+ case "page-up":
58080
+ case "page-down":
58081
+ if (current.screen === "list") {
58082
+ const items = current.list;
58083
+ if (items.length === 0)
58084
+ return;
58085
+ const size = current.listWindow.size;
58086
+ const step = pageSize(size) * (intent.kind === "page-down" ? 1 : -1);
58087
+ const index = items.findIndex((item) => item.id === current.selectedRunId);
58088
+ const clamped = Math.min(items.length - 1, Math.max(0, (index === -1 ? 0 : index) + step));
58089
+ const next = items[clamped];
58090
+ if (next !== undefined) {
58091
+ const offset = moveBy(current.listWindow.offset, step, items.length, size);
58092
+ setData((state) => ({
58093
+ ...state,
58094
+ selectedRunId: next.id,
58095
+ selectedTaskId: null,
58096
+ listOffset: offset
58097
+ }));
58098
+ }
58099
+ return;
58100
+ }
58101
+ {
58102
+ const tasks = current.run?.tasks ?? [];
58103
+ if (tasks.length === 0)
58104
+ return;
58105
+ const size = current.taskWindow.size;
58106
+ const step = pageSize(size) * (intent.kind === "page-down" ? 1 : -1);
58107
+ const index = tasks.findIndex((task) => task.selected);
58108
+ const clamped = Math.min(tasks.length - 1, Math.max(0, (index === -1 ? 0 : index) + step));
58109
+ const next = tasks[clamped];
58110
+ if (next !== undefined) {
58111
+ const offset = moveBy(current.taskWindow.offset, step, tasks.length, size);
58112
+ setData((state) => ({ ...state, selectedTaskId: next.id, taskOffset: offset }));
58113
+ }
58114
+ return;
58115
+ }
58116
+ case "first":
58117
+ case "last":
58118
+ if (current.screen === "list") {
58119
+ const items = current.list;
58120
+ if (items.length === 0)
58121
+ return;
58122
+ const index = intent.kind === "first" ? 0 : items.length - 1;
58123
+ const next = items[index];
58124
+ if (next !== undefined) {
58125
+ const offset = intent.kind === "first" ? firstOffset(items.length) : lastOffset(items.length, current.listWindow.size);
58126
+ setData((state) => ({
58127
+ ...state,
58128
+ selectedRunId: next.id,
58129
+ selectedTaskId: null,
58130
+ listOffset: offset
58131
+ }));
58132
+ }
58133
+ return;
58134
+ }
58135
+ {
58136
+ const tasks = current.run?.tasks ?? [];
58137
+ if (tasks.length === 0)
58138
+ return;
58139
+ const index = intent.kind === "first" ? 0 : tasks.length - 1;
58140
+ const next = tasks[index];
58141
+ if (next !== undefined) {
58142
+ const offset = intent.kind === "first" ? firstOffset(tasks.length) : lastOffset(tasks.length, current.taskWindow.size);
58143
+ setData((state) => ({ ...state, selectedTaskId: next.id, taskOffset: offset }));
58144
+ }
58145
+ return;
58146
+ }
56329
58147
  default:
56330
58148
  return;
56331
58149
  }
@@ -56337,6 +58155,9 @@ function Interactive({
56337
58155
  depth
56338
58156
  }, undefined, false, undefined, this);
56339
58157
  }
58158
+ function nextReplaySize(current, columns, rows) {
58159
+ return { columns: columns ?? current.columns, rows: rows ?? current.rows };
58160
+ }
56340
58161
  function replayView(load, options) {
56341
58162
  const model = replayModel(load, options.now);
56342
58163
  const glyphs = glyphsFor({ ascii: options.ascii, env: options.env ?? {} });
@@ -56366,20 +58187,53 @@ function replayView(load, options) {
56366
58187
  });
56367
58188
  return buildViewModel({ ...input, panel: { ...panel, notice: "replay: read-only" } });
56368
58189
  }
56369
- function Replay({ view, glyphs, depth }) {
58190
+ function Replay({ load, options, glyphs, depth }) {
56370
58191
  const { exit } = use_app_default();
58192
+ const [size, setSize] = import_react27.useState({ columns: options.columns, rows: options.rows });
56371
58193
  const [notice, setNotice] = import_react27.useState(null);
56372
- const current = import_react27.useMemo(() => notice === null ? view : { ...view, notice }, [view, notice]);
58194
+ const [help, setHelp] = import_react27.useState(false);
58195
+ const [activity, setActivity] = import_react27.useState(null);
58196
+ const view = import_react27.useMemo(() => replayView(load, { ...options, columns: size.columns, rows: size.rows }), [load, options, size]);
58197
+ const base = import_react27.useMemo(() => notice === null ? view : { ...view, notice }, [view, notice]);
58198
+ const withActivity = activity === null ? base : replayActivityView(base, activity, glyphs);
58199
+ const current = help ? replayHelpView(withActivity) : withActivity;
56373
58200
  const currentRef = import_react27.useRef(current);
56374
58201
  currentRef.current = current;
58202
+ import_react27.useEffect(() => {
58203
+ const onResize = () => {
58204
+ setSize((last) => nextReplaySize(last, process14.stdout.columns, process14.stdout.rows));
58205
+ };
58206
+ process14.stdout.on("resize", onResize);
58207
+ return () => {
58208
+ process14.stdout.off("resize", onResize);
58209
+ };
58210
+ }, []);
56375
58211
  use_input_default((input, key) => {
56376
- const outcome = replayKey(currentRef.current, input, key);
58212
+ const running = currentRef.current;
58213
+ if (activity === null && !help && !key.ctrl && input === "L" && running.run !== null) {
58214
+ setActivity(openActivityPane(running.run));
58215
+ return;
58216
+ }
58217
+ if (activity !== null && running.run !== null) {
58218
+ const outcome = activityPaneKeys(running.run, activity, input, key, activityPaneBodyRows(running.rows));
58219
+ if (outcome.close === true) {
58220
+ setActivity(null);
58221
+ return;
58222
+ }
58223
+ if (outcome.state !== activity) {
58224
+ setActivity(outcome.state);
58225
+ return;
58226
+ }
58227
+ }
58228
+ const outcome = replayKey(running, input, key);
56377
58229
  if (outcome.quit) {
56378
58230
  exit();
56379
58231
  return;
56380
58232
  }
56381
58233
  if (outcome.notice !== null)
56382
58234
  setNotice(outcome.notice);
58235
+ if (outcome.help !== null)
58236
+ setHelp(outcome.help);
56383
58237
  });
56384
58238
  return /* @__PURE__ */ jsx_dev_runtime10.jsxDEV(Frame, {
56385
58239
  viewModel: current,
@@ -56391,15 +58245,15 @@ async function runReplay(options, replay) {
56391
58245
  const { glyphs, depth } = themeFor(options);
56392
58246
  const env = terminalEnv(options.env);
56393
58247
  const load = await readReplayFile(replay);
56394
- const view = replayView(load, {
58248
+ const viewOptions = {
56395
58249
  now: Date.now(),
56396
58250
  ascii: options.ascii,
56397
58251
  columns: options.columns,
56398
58252
  rows: options.rows,
56399
58253
  env
56400
- });
58254
+ };
56401
58255
  if (options.once) {
56402
- options.out(await renderFrame(view, { columns: options.columns, rows: options.rows }, { ascii: options.ascii, env }));
58256
+ options.out(await renderFrame(replayView(load, viewOptions), { columns: viewOptions.columns, rows: viewOptions.rows }, { ascii: options.ascii, env }));
56403
58257
  return 0;
56404
58258
  }
56405
58259
  const session = options.session ?? createTerminalSession(process14.stdin, process14.stdout);
@@ -56412,14 +58266,16 @@ async function runReplay(options, replay) {
56412
58266
  session,
56413
58267
  render: async () => {
56414
58268
  const instance = render_default(/* @__PURE__ */ jsx_dev_runtime10.jsxDEV(Replay, {
56415
- view,
58269
+ load,
58270
+ options: viewOptions,
56416
58271
  glyphs,
56417
58272
  depth
56418
58273
  }, undefined, false, undefined, this), {
56419
58274
  stdout: process14.stdout,
56420
58275
  stdin: process14.stdin,
56421
58276
  patchConsole: false,
56422
- exitOnCtrlC: false
58277
+ exitOnCtrlC: false,
58278
+ debug: options.frames === true
56423
58279
  });
56424
58280
  await instance.waitUntilExit();
56425
58281
  }
@@ -56487,15 +58343,37 @@ async function runTui(options) {
56487
58343
  }
56488
58344
  export {
56489
58345
  REPLAY_READ_ONLY,
58346
+ approvalKeyRoute,
58347
+ createLandGuard,
56490
58348
  createResumeGuard,
58349
+ evidenceOf,
58350
+ grantedCommit2 as grantedCommit,
56491
58351
  isReadOnly,
58352
+ landConfirmation,
58353
+ landFailed,
58354
+ landSettled,
58355
+ landStarted,
58356
+ nextReplaySize,
58357
+ panelOpen,
56492
58358
  performControl,
58359
+ quitsOnKey,
56493
58360
  recordAnswer,
58361
+ replayActivityView,
58362
+ replayHelpView,
56494
58363
  replayKey,
56495
58364
  replayView,
56496
58365
  resumeFailed,
58366
+ resumeStarted,
58367
+ rewordFailed,
58368
+ rewordStarted,
58369
+ rewordSucceeded,
56497
58370
  runInSession,
56498
58371
  runTui,
58372
+ selectedRunState,
58373
+ settleLanding,
58374
+ startLand,
56499
58375
  startResume,
56500
- syncApproval
58376
+ startReword,
58377
+ syncApproval,
58378
+ viewOf
56501
58379
  };