@oh-my-pi/pi-tui 18.9.2 → 18.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/CHANGELOG.md +53 -105
  2. package/dist/types/app-keybindings.d.ts +5 -0
  3. package/dist/types/chat/assistant-message.d.ts +1 -1
  4. package/dist/types/chat/user-message.d.ts +3 -2
  5. package/dist/types/chrome/countdown-timer.d.ts +3 -2
  6. package/dist/types/debug-server.d.ts +2 -0
  7. package/dist/types/overlays/annotation-overlay.d.ts +19 -0
  8. package/dist/types/overlays/ask-dialog.d.ts +11 -6
  9. package/dist/types/overlays/btw-history-panel.d.ts +2 -6
  10. package/dist/types/overlays/hook-editor.d.ts +7 -2
  11. package/dist/types/overlays/hook-input.d.ts +12 -4
  12. package/dist/types/overlays/jobs-panel.d.ts +8 -7
  13. package/dist/types/overlays/login-dialog.d.ts +8 -3
  14. package/dist/types/overlays/mcp-add-wizard.d.ts +9 -1
  15. package/dist/types/overlays/pause-screen.d.ts +5 -0
  16. package/dist/types/overlays/report-panel.d.ts +5 -1
  17. package/dist/types/overlays/reset-usage-selector.d.ts +7 -5
  18. package/dist/types/overlays/session-account-selector.d.ts +4 -0
  19. package/dist/types/overlays/session-info-overlay.d.ts +7 -3
  20. package/dist/types/overlays/usage-dashboard.d.ts +6 -6
  21. package/dist/types/prompt/composer.d.ts +1 -20
  22. package/dist/types/status-line/context-usage.d.ts +1 -1
  23. package/dist/types/tools/grouped-file-output.d.ts +4 -1
  24. package/dist/types/tui.d.ts +10 -3
  25. package/package.json +9 -9
  26. package/src/app-keybindings.ts +5 -0
  27. package/src/apps/autoresearch-dashboard.ts +440 -27
  28. package/src/chat/assistant-message.ts +41 -13
  29. package/src/chat/user-message.ts +32 -19
  30. package/src/chrome/countdown-timer.ts +3 -3
  31. package/src/chrome/transcript-container.ts +202 -28
  32. package/src/debug-server.ts +51 -69
  33. package/src/hotkeys-markdown.ts +1 -0
  34. package/src/native/reconcile.ts +24 -6
  35. package/src/overlays/advisor-config.ts +259 -8
  36. package/src/overlays/annotation-overlay.ts +420 -168
  37. package/src/overlays/ask-dialog.ts +249 -105
  38. package/src/overlays/btw-history-panel.ts +178 -124
  39. package/src/overlays/hook-editor.ts +90 -32
  40. package/src/overlays/hook-input.ts +105 -19
  41. package/src/overlays/jobs-panel.ts +154 -132
  42. package/src/overlays/login-dialog.ts +201 -91
  43. package/src/overlays/mcp-add-wizard.ts +559 -279
  44. package/src/overlays/pause-screen.ts +81 -23
  45. package/src/overlays/plugin-selector.ts +17 -1
  46. package/src/overlays/queue-mode-selector.ts +10 -0
  47. package/src/overlays/report-panel.ts +6 -2
  48. package/src/overlays/reset-usage-selector.ts +130 -21
  49. package/src/overlays/session-account-selector.ts +36 -0
  50. package/src/overlays/session-info-overlay.ts +197 -76
  51. package/src/overlays/show-images-selector.ts +1 -0
  52. package/src/overlays/theme-selector.ts +6 -1
  53. package/src/overlays/thinking-selector.ts +8 -4
  54. package/src/overlays/usage-dashboard.ts +495 -143
  55. package/src/prompt/composer.ts +35 -72
  56. package/src/status-line/context-usage.ts +154 -57
  57. package/src/tools/grep.ts +1 -0
  58. package/src/tools/grouped-file-output.ts +11 -2
  59. package/src/tui.ts +27 -4
@@ -1,24 +1,52 @@
1
1
  /**
2
- * Simple text input component for hooks.
2
+ * One-line text prompt an extension (hook) asks the user.
3
3
  */
4
- import { Spacer, type TUI } from "../index";
4
+ import { type Component, Spacer, Text, type TUI } from "../index";
5
5
  import { matchesAppInterrupt } from "../keybinding-matchers";
6
6
  import { CountdownTimer } from "../chrome/countdown-timer";
7
7
  import { formTheme } from "../chrome/form-theme";
8
8
  import { OverlayPanel } from "../chrome/overlay-box";
9
9
  import { Form, TextFormField } from "../components/form";
10
- import { editorKey, interruptKey } from "../chrome/keybinding-hints";
11
- import { node } from "../native/describe";
12
- import type { DescribeContext, NativeNode } from "../native/node";
13
- import { overlayCard } from "../native/overlay";
10
+ import { boundKeys, editorKey, interruptKey } from "../chrome/keybinding-hints";
11
+ import { getKeybindings } from "../keybindings";
12
+ import { col, node, span } from "../native/describe";
13
+ import type { DescribeContext, NativeChild, NativeNode, NativeUiEvent } from "../native/node";
14
+ import { actionBar, actionButton } from "../native/overlay";
14
15
  import { plainText } from "../native/spans";
15
16
 
17
+ /** Role prefix of the sheet's parts (`omp.hook-input.head`, `.title`, `.timer`, `.detail`, `.field`). */
18
+ const PART = "omp.hook-input";
19
+
16
20
  export interface HookInputOptions {
17
21
  tui?: TUI;
18
22
  timeout?: number;
19
23
  onTimeout?: () => void;
20
24
  }
21
25
 
26
+ /** Terminal-only key legend under the field; a native terminal puts the keys in the buttons' tooltips. */
27
+ class KeyLegend implements Component {
28
+ readonly #text = new Text("", 0, 0);
29
+
30
+ constructor(private readonly legend: string) {
31
+ this.invalidate();
32
+ }
33
+
34
+ render(width: number): readonly string[] {
35
+ return this.#text.render(width);
36
+ }
37
+
38
+ invalidate(): void {
39
+ this.#text.setText(formTheme.hint(this.legend));
40
+ this.#text.invalidate();
41
+ }
42
+ }
43
+
44
+ interface HookInputNativeMemo {
45
+ countdown: NativeNode | undefined;
46
+ error: boolean;
47
+ node: NativeNode;
48
+ }
49
+
22
50
  export class HookInputComponent extends OverlayPanel {
23
51
  #field: TextFormField;
24
52
  #form: Form;
@@ -26,11 +54,12 @@ export class HookInputComponent extends OverlayPanel {
26
54
  #onCancelCallback: () => void;
27
55
  #baseTitle: string;
28
56
  #countdown: CountdownTimer | undefined;
29
- #nativeMemo: { countdown: NativeNode | undefined; node: NativeNode } | undefined;
57
+ #nativeMemo: HookInputNativeMemo | undefined;
58
+ #nativeActions: NativeNode | undefined;
30
59
 
31
60
  constructor(
32
61
  title: string,
33
- _placeholder: string | undefined,
62
+ placeholder: string | undefined,
34
63
  onSubmit: (value: string) => void,
35
64
  onCancel: () => void,
36
65
  opts?: HookInputOptions,
@@ -55,17 +84,19 @@ export class HookInputComponent extends OverlayPanel {
55
84
 
56
85
  this.#field = new TextFormField({
57
86
  theme: formTheme,
58
- hint: `${editorKey("tui.input.submit")} submit ${interruptKey()} cancel`,
59
87
  empty: "submit",
60
88
  onSubmit: value => this.#onSubmitCallback(value),
61
89
  onCancel: () => this.#onCancelCallback(),
62
90
  });
91
+ // Native terminals draw it while the value is empty; the terminal row stays bare.
92
+ this.#field.input.placeholder = placeholder?.trim() || undefined;
63
93
  this.#form = new Form({
64
94
  fields: [this.#field],
65
95
  onCancel: () => this.#onCancelCallback(),
66
96
  isCancel: matchesAppInterrupt,
67
97
  });
68
98
  this.addChild(this.#form);
99
+ this.addChild(new KeyLegend(`${editorKey("tui.input.submit")} submit ${interruptKey()} cancel`));
69
100
  this.addChild(new Spacer(1));
70
101
  }
71
102
 
@@ -83,24 +114,79 @@ export class HookInputComponent extends OverlayPanel {
83
114
  this.#form.pasteText(text);
84
115
  }
85
116
 
117
+ /** Submit and Cancel run what Enter and the interrupt key run. */
118
+ handleNativeEvent(event: NativeUiEvent): void {
119
+ if (event.type !== "action") return;
120
+ if (event.act === "submit") {
121
+ this.#countdown?.reset();
122
+ this.#field.submit();
123
+ } else if (event.act === "cancel") {
124
+ this.#onCancelCallback();
125
+ }
126
+ }
127
+
86
128
  override dispose(): void {
87
129
  this.#countdown?.dispose();
88
130
  super.dispose();
89
131
  }
90
132
 
91
- /** A card over the form, headed by the title plus the countdown `elapsed` while a timeout runs. */
133
+ /**
134
+ * A sheet in the composer's place, built like the extension editor's: the
135
+ * title's first line (the countdown at its end while a timeout runs) over
136
+ * any further lines as detail, the field written on the sheet (tinted, the
137
+ * reason under it, while a submit was refused), and Cancel · Submit, whose
138
+ * keys live in their tooltips.
139
+ */
92
140
  override describe(_cx: DescribeContext): NativeNode {
93
141
  const countdown = this.#countdown?.describe();
142
+ const error = this.#field.hasError;
94
143
  const memo = this.#nativeMemo;
95
- if (memo && memo.countdown === countdown) return memo.node;
96
- const title = plainText(this.#baseTitle);
97
- const root = countdown
98
- ? overlayCard(this.nativeRole, undefined, [
99
- node("row", { gap: "sm", align: "baseline" }, [node("text", { text: title }), countdown], "head"),
100
- this.#form,
101
- ])
102
- : overlayCard(this.nativeRole, title, [this.#form]);
103
- this.#nativeMemo = { countdown, node: root };
144
+ if (memo && memo.countdown === countdown && memo.error === error) return memo.node;
145
+ const [titleLine = "", ...detailLines] = plainText(this.#baseTitle).trim().split(/\r?\n/);
146
+ const titleRow: NativeChild[] = [
147
+ node(
148
+ "text",
149
+ { spans: [span(titleLine.trim())], role: `${PART}.title`, wrap: "word", grow: 1 },
150
+ undefined,
151
+ "title",
152
+ ),
153
+ ];
154
+ if (countdown) {
155
+ titleRow.push(
156
+ node(
157
+ "row",
158
+ { role: `${PART}.timer`, title: "Cancels when the time runs out; typing restarts it" },
159
+ [countdown],
160
+ "timer",
161
+ ),
162
+ );
163
+ }
164
+ const head: NativeChild[] = [node("row", { gap: "md", align: "baseline" }, titleRow, "line")];
165
+ const detail = detailLines.join("\n").trim();
166
+ if (detail) {
167
+ head.push(node("text", { spans: [span(detail)], role: `${PART}.detail`, wrap: "word" }, undefined, "detail"));
168
+ }
169
+ const root = col(
170
+ [
171
+ node("col", { role: `${PART}.head`, gap: "xs" }, head, "head"),
172
+ node("col", { role: `${PART}.field`, ...(error ? { tone: "error" as const } : {}) }, [this.#form], "field"),
173
+ this.#describeActions(),
174
+ ],
175
+ { role: this.nativeRole },
176
+ );
177
+ this.#nativeMemo = { countdown, error, node: root };
104
178
  return root;
105
179
  }
180
+
181
+ #describeActions(): NativeNode {
182
+ if (this.#nativeActions) return this.#nativeActions;
183
+ const submitKey = getKeybindings().getKeys("tui.input.submit")[0];
184
+ const cancelKey = boundKeys("app.interrupt", ["escape"])[0];
185
+ this.#nativeActions = actionBar([
186
+ null,
187
+ actionButton("Cancel", "cancel", cancelKey ? { keys: cancelKey } : {}),
188
+ actionButton("Submit", "submit", { tone: "accent", ...(submitKey ? { keys: submitKey } : {}) }),
189
+ ]);
190
+ return this.#nativeActions;
191
+ }
106
192
  }
@@ -1,32 +1,17 @@
1
1
  /**
2
2
  * The async background jobs of a session as {@link JobsSheet}: the dismissable
3
- * sheet the native jobs pill and `/jobs` open. It draws task jobs as `agent`
4
- * nodes and the others as a status dot, the one-line label and a live
5
- * `elapsed`, lists every job and inspects the selected one (command, cwd, live
6
- * pids, exit code, output tail).
3
+ * sheet the native jobs pill and `/jobs` open. A master–detail split lists
4
+ * every job (running first) beside the selected one's status, command, facts
5
+ * (cwd, live pids, exit code, artifact) and live output.
7
6
  */
8
- import type { TspAgentProps, TspSpan } from "@oh-my-pi/pi-wire";
7
+ import type { TspSpan, TspTone } from "@oh-my-pi/pi-wire";
9
8
  import { formatDuration } from "@oh-my-pi/pi-utils";
10
9
  import type { Component } from "../tui";
11
10
  import { matchesSelectCancel, matchesSelectDown, matchesSelectUp } from "../keybinding-matchers";
12
11
  import { matchesKey } from "../keys";
13
12
  import { truncateToWidth } from "../utils";
14
13
  import { collapseCommand } from "../apps/ps-data";
15
- import {
16
- ansi,
17
- card,
18
- code,
19
- col,
20
- compact,
21
- elapsed,
22
- item,
23
- kv,
24
- node,
25
- row,
26
- span,
27
- stableKey,
28
- text,
29
- } from "../native/describe";
14
+ import { ansi, code, col, compact, item, node, row, span, stableKey, text } from "../native/describe";
30
15
  import type { DescribeContext, NativeChild, NativeNode, NativeUiEvent } from "../native/node";
31
16
  import { actionBar, actionButton, selectList } from "../native/overlay";
32
17
 
@@ -74,31 +59,45 @@ export interface JobsSheetSource {
74
59
  close(): void;
75
60
  }
76
61
 
77
- const AGENT_STATUS: Record<JobsPanelJob["status"], TspAgentProps["status"]> = {
78
- running: "running",
79
- completed: "done",
80
- failed: "failed",
81
- cancelled: "aborted",
62
+ /** A job's status as the sheet names it. */
63
+ const STATUS_LABEL: Record<JobsPanelJob["status"], string> = {
64
+ running: "Running",
65
+ completed: "Done",
66
+ failed: "Failed",
67
+ cancelled: "Cancelled",
82
68
  };
83
69
 
84
- const DOT: Record<JobsPanelJob["status"], TspSpan> = {
85
- running: { t: "●", s: "accent", fx: "pulse" },
86
- completed: { t: "●", s: "success" },
87
- failed: { t: "●", s: "error" },
88
- cancelled: { t: "●", s: "dim" },
70
+ /** A job's status color: the list row's icon and the detail's status pill. */
71
+ const STATUS_TONE: Record<JobsPanelJob["status"], TspTone> = {
72
+ running: "pending",
73
+ completed: "success",
74
+ failed: "error",
75
+ cancelled: "muted",
89
76
  };
90
77
 
78
+ /** The status pill's lead glyph; a running job's pulses. */
79
+ const STATUS_GLYPH: Record<JobsPanelJob["status"], TspSpan> = {
80
+ running: { t: "●", fx: "pulse" },
81
+ completed: { t: "✓" },
82
+ failed: { t: "✕" },
83
+ cancelled: { t: "⊘" },
84
+ };
85
+
86
+ /** The list row's icon per job type (Tern icon names); other types read as a generic job. */
87
+ const TYPE_ICON: Record<string, string> = { bash: "bash", task: "agent" };
88
+
91
89
  /** Output tail rows the terminal fallback shows under the selected job. */
92
90
  const FALLBACK_TAIL_LINES = 8;
93
91
 
94
92
  /**
95
93
  * The jobs pill's sheet: a centred `lg` glass sheet titled Background jobs.
96
- * A selectable list of every job (running first) sits over the selected
97
- * job's detail: status and live elapsed (a task job's `agent` node), cwd,
98
- * live pids, exit code, the full command and a tail-following output pane.
99
- * It re-reads the session every frame, so the caller re-renders it on a
100
- * timer while it is open. ↑/↓ select, X cancels the selected running job,
101
- * Esc or Close dismisses; nothing enters the transcript.
94
+ * A master–detail split (it stacks in a narrow pane): the selectable job list,
95
+ * grouped Running / Recent, beside the selected job's detail — a status pill
96
+ * with live elapsed and Cancel job, its command or task, facts (agent, cwd,
97
+ * live pids, exit code, artifact) and a tail-following output pane. With no
98
+ * jobs it shows an empty state. It re-reads the session every frame, so the
99
+ * caller re-renders it on a timer while it is open. ↑/↓ select, X cancels the
100
+ * selected running job, Esc or Close dismisses; nothing enters the transcript.
102
101
  */
103
102
  export class JobsSheet implements Component {
104
103
  readonly nativeOverlay = {
@@ -117,8 +116,7 @@ export class JobsSheet implements Component {
117
116
  this.#source = source;
118
117
  }
119
118
 
120
- describe(cx: DescribeContext): NativeNode {
121
- const agent = cx.supports("agent");
119
+ describe(_cx: DescribeContext): NativeNode {
122
120
  const { jobs, selected } = this.#current();
123
121
  const detail = selected && this.#source.inspect(selected.id);
124
122
  const now = Date.now();
@@ -126,7 +124,6 @@ export class JobsSheet implements Component {
126
124
  // when a job starts, settles or leaves, its process changes, its output
127
125
  // grows, or (while one runs) once a second.
128
126
  const key = [
129
- agent,
130
127
  jobs.map(job => `${job.id}:${job.status}`).join(","),
131
128
  selected?.id,
132
129
  detail?.pids.join(" "),
@@ -136,22 +133,21 @@ export class JobsSheet implements Component {
136
133
  ].join("|");
137
134
  const output = detail?.output;
138
135
  if (this.#native?.key === key && this.#native.output === output) return this.#native.node;
139
- const actions = [null, actionButton("Close", "close", { keys: "escape" })];
140
- if (selected?.status === "running") {
141
- actions.unshift(actionButton("Cancel job", "cancel", { keys: "x", tone: "error" }));
142
- }
143
- const described = col(
144
- compact([
145
- selectList(
146
- "jobs",
147
- jobs.map(job => describeJobItem(job, now)),
148
- { selected: selected?.id ?? null, empty: "No background jobs", max: { lines: 6 } },
149
- ),
150
- selected && describeDetail(selected, detail, now, agent),
151
- actionBar(actions),
152
- ]),
153
- { gap: "md" },
154
- );
136
+ const close = actionButton("Close", "close", { keys: "escape" });
137
+ const described = selected
138
+ ? col([
139
+ node(
140
+ "row",
141
+ { role: "omp.jobs.split" },
142
+ [
143
+ node("col", { role: "omp.jobs.master" }, [describeJobList(jobs, selected, now)], "master"),
144
+ describeDetail(selected, detail, now),
145
+ ],
146
+ "split",
147
+ ),
148
+ actionBar([describeSummary(jobs), null, close]),
149
+ ])
150
+ : col([describeEmpty(), actionBar([null, close])]);
155
151
  this.#native = { key, output, node: described };
156
152
  return described;
157
153
  }
@@ -256,94 +252,120 @@ function tailLines(text: string, count: number): string[] {
256
252
  return lines.reverse();
257
253
  }
258
254
 
259
- /** A task job as an `agent` node when the terminal draws them, else a one-line dot row. */
260
- function describeJob(job: JobsPanelJob, nowMs: number, agent: boolean): NativeNode {
261
- const settled = job.status !== "running";
262
- const age = jobAge(job, nowMs);
263
- if (agent && job.type === "task") {
264
- return node(
265
- "agent",
266
- {
267
- name: job.agentId ?? job.id,
268
- agent: "task",
269
- task: job.label,
270
- status: AGENT_STATUS[job.status],
271
- stats: settled ? { took: age } : { age },
272
- },
273
- undefined,
274
- job.id,
275
- );
255
+ /**
256
+ * The master list: Running, then Recent, each under a quiet group label (a
257
+ * plain text child: no row behavior, so ↑/↓ and clicks pass it by).
258
+ */
259
+ function describeJobList(jobs: readonly JobsPanelJob[], selected: JobsPanelJob, nowMs: number): NativeNode {
260
+ const rows: NativeChild[] = [];
261
+ for (const [label, group] of [
262
+ ["Running", jobs.filter(job => job.status === "running")],
263
+ ["Recent", jobs.filter(job => job.status !== "running")],
264
+ ] as const) {
265
+ if (group.length === 0) continue;
266
+ rows.push(node("text", { role: "omp.jobs.group", text: label, wrap: "none" }, undefined, `group-${label}`));
267
+ for (const job of group) rows.push(describeJobItem(job, nowMs));
276
268
  }
277
- return node(
278
- "row",
279
- { role: "omp.jobs.row", gap: "sm", align: "center", title: `${job.id} · ${job.type} · ${job.status}` },
280
- [
281
- text([DOT[job.status]], { aria: job.status, shrink: 0 }),
282
- text([span(collapseCommand(job.label))], { wrap: "none", truncate: "end", grow: 1 }),
283
- text([span(job.type, "dim")], { wrap: "none", shrink: 0 }),
284
- elapsed(age, settled),
285
- ],
286
- job.id,
287
- );
269
+ return selectList("jobs", rows, { selected: selected.id, max: { lines: 12 } });
288
270
  }
289
271
 
290
- /** One sheet list row: status dot and one-line label, then type and age. */
272
+ /**
273
+ * One list row: the type icon tinted by status, the one-line label (a process
274
+ * job's command in mono, a task's work in prose) and how long it ran.
275
+ */
291
276
  function describeJobItem(job: JobsPanelJob, nowMs: number): NativeNode {
277
+ const status = STATUS_LABEL[job.status];
278
+ const age = formatDuration(jobAge(job, nowMs));
292
279
  return item(job.id, {
293
- label: [DOT[job.status], span(" "), span(collapseCommand(job.label))],
294
- value: [span(job.type, "dim"), span(` · ${formatDuration(jobAge(job, nowMs))}`, "muted")],
295
- title: `${job.id} · ${job.type} · ${job.status}`,
280
+ label: [job.type === "task" ? span(job.label) : span(collapseCommand(job.label), "mono")],
281
+ value: [span(age, "mono")],
282
+ icon: TYPE_ICON[job.type] ?? "job",
283
+ tone: STATUS_TONE[job.status],
284
+ title: `${job.label}\n${status} · ${job.type} · ${job.id}`,
285
+ aria: `${job.label}, ${status.toLowerCase()}, ${age}`,
296
286
  });
297
287
  }
298
288
 
299
- /** The selected job: status line (or `agent` node), facts, command and output tail. */
300
- function describeDetail(
301
- job: JobsPanelJob,
302
- detail: JobsPanelDetail | undefined,
303
- nowMs: number,
304
- agent: boolean,
305
- ): NativeNode {
289
+ /** The footer's at-a-glance count. */
290
+ function describeSummary(jobs: readonly JobsPanelJob[]): NativeNode {
291
+ const running = jobs.filter(job => job.status === "running").length;
292
+ const parts = compact([
293
+ running > 0 && `${running} running`,
294
+ jobs.length > running && `${jobs.length - running} recent`,
295
+ ]);
296
+ return node("text", { role: "omp.jobs.summary", text: parts.join(" · "), wrap: "none" }, undefined, "summary");
297
+ }
298
+
299
+ /** No jobs: what the sheet is for, in place of the split. */
300
+ function describeEmpty(): NativeNode {
301
+ return node(
302
+ "col",
303
+ { role: "omp.jobs.empty", align: "center" },
304
+ [
305
+ node("icon", { name: "jobs" }),
306
+ text("No background jobs", { role: "omp.jobs.empty.title" }),
307
+ text("Commands and subagent tasks started in the background show up here while they run.", {
308
+ role: "omp.jobs.empty.note",
309
+ wrap: "word",
310
+ }),
311
+ ],
312
+ "empty",
313
+ );
314
+ }
315
+
316
+ /**
317
+ * The selected job: a status line (pill, live elapsed, type · id, Cancel job),
318
+ * its task or full command, facts and the output pane (or its empty state).
319
+ */
320
+ function describeDetail(job: JobsPanelJob, detail: JobsPanelDetail | undefined, nowMs: number): NativeNode {
306
321
  const settled = job.status !== "running";
307
322
  const exit = detail?.exitCode;
323
+ const age = Math.round(jobAge(job, nowMs));
324
+ const command = detail?.command ?? (job.type === "task" ? undefined : job.label);
325
+ const pids = detail?.pids ?? [];
326
+ const facts = compact([
327
+ job.agentId ? { k: "Agent", v: [span(job.agentId, "mono")] } : undefined,
328
+ detail?.cwd ? { k: "Directory", v: [span(detail.cwd, "path")] } : undefined,
329
+ pids.length > 0 && { k: pids.length > 1 ? "PIDs" : "PID", v: [span(pids.join(", "), "num")] },
330
+ exit !== undefined && { k: "Exit code", v: [span(String(exit), exit === 0 ? "success" : "error")] },
331
+ detail?.artifactId ? { k: "Full output", v: [span(`artifact://${detail.artifactId}`, "mono")] } : undefined,
332
+ ]);
308
333
  const children = compact<NativeChild>([
309
- agent && job.type === "task"
310
- ? describeJob(job, nowMs, agent)
311
- : row(
312
- [
313
- text(
314
- [DOT[job.status], span(` ${job.status}`, "strong"), span(` · ${job.type} · ${job.id}`, "muted")],
315
- {
316
- wrap: "none",
317
- truncate: "end",
318
- },
319
- ),
320
- elapsed(jobAge(job, nowMs), settled),
321
- ],
322
- { gap: "sm", align: "center" },
323
- ),
324
- detail &&
325
- kv([
326
- ["Directory", detail.cwd && [span(detail.cwd, "path")]],
327
- ["PID", detail.pids.length > 0 ? [span(detail.pids.join(", "), "num")] : undefined],
328
- ["Exit", exit === undefined ? undefined : [span(String(exit), exit === 0 ? "success" : "error")]],
329
- ["Full output", detail.artifactId && [span(`artifact://${detail.artifactId}`, "mono")]],
334
+ row(
335
+ compact<NativeChild>([
336
+ text([STATUS_GLYPH[job.status], span(` ${STATUS_LABEL[job.status]}`)], {
337
+ role: "omp.jobs.state",
338
+ tone: STATUS_TONE[job.status],
339
+ wrap: "none",
340
+ }),
341
+ node("elapsed", {
342
+ age,
343
+ ...(settled ? { stopped: age } : {}),
344
+ format: "short",
345
+ role: "omp.jobs.age",
346
+ title: settled ? "Ran for" : "Running for",
347
+ }),
348
+ text([span(`${job.type} · ${job.id}`, "mono")], { role: "omp.jobs.id", wrap: "none", truncate: "end" }),
349
+ node("spacer", { grow: 1 }),
350
+ !settled && actionButton("Cancel job", "cancel", { keys: "x", tone: "error" }),
330
351
  ]),
331
- // The row shows the command on one line; show it whole when that cut or collapsed it.
332
- detail?.command && detail.command !== collapseCommand(job.label)
333
- ? card(
334
- {
335
- head: [span("Command", "muted")],
336
- variant: "bare",
337
- collapsible: true,
338
- collapsed: true,
339
- preview: { lines: 3 },
340
- },
341
- [code(detail.command, { lang: "bash", wrap: true })],
342
- )
343
- : undefined,
344
- detail?.output
345
- ? ansi(detail.output, { follow: !settled, role: "omp.jobs.output", max: { h: "16lines" } })
346
- : text([span(settled ? "No output" : "No output yet", "dim")]),
352
+ { role: "omp.jobs.status", gap: "sm", align: "center" },
353
+ ),
354
+ command
355
+ ? code(command, { lang: "bash", wrap: true, preview: { lines: 4 }, role: "omp.jobs.command" })
356
+ : text(job.label, { role: "omp.jobs.title", wrap: "word" }),
357
+ facts.length > 0 && node("kv", { items: facts, role: "omp.jobs.facts" }),
358
+ node(
359
+ "col",
360
+ { role: "omp.jobs.out", gap: "sm" },
361
+ [
362
+ text("Output", { role: "omp.jobs.label" }),
363
+ detail?.output
364
+ ? ansi(detail.output, { follow: !settled, role: "omp.jobs.output", max: { h: "16lines" } })
365
+ : text(settled ? "No output" : "No output yet", { role: "omp.jobs.nooutput" }),
366
+ ],
367
+ "out",
368
+ ),
347
369
  ]);
348
- return node("col", { gap: "sm", role: "omp.jobs.detail" }, children, stableKey(job.id));
370
+ return node("col", { role: "omp.jobs.detail" }, children, stableKey(job.id));
349
371
  }