happier-tui 0.1.0 → 0.2.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/app.js CHANGED
@@ -1,13 +1,16 @@
1
1
  import { appendFileSync } from "node:fs";
2
- import { CombinedAutocompleteProvider, Editor, isKeyRelease, isKeyRepeat, Key, matchesKey, ProcessTerminal, ScrollView, truncateToWidth, TuiAltScreen, VStack, wrapTextWithAnsi, } from "@earendil-works/pi-tui";
2
+ import { isKeyRelease, isKeyRepeat, Key, matchesKey, ProcessTerminal, ScrollView, truncateToWidth, TuiAltScreen, VStack, wrapTextWithAnsi, } from "@earendil-works/pi-tui";
3
3
  import { HappierError, isBusy, pendingRequests, sessionModels, sessionTitle, } from "./happier/client.js";
4
+ import { CLAUDE_EFFORT_LEVELS, effortOverride, isWaitingForLimit, sessionGoal, sessionModes, sessionOptions, usageLimit } from "./happier/controls.js";
4
5
  import { Transcript } from "./happier/transcript.js";
5
6
  import { attentionChange, FOCUS_IN, FOCUS_OUT, notificationSequence, } from "./ui/notify.js";
6
7
  import { NewSessionFlow } from "./new-session.js";
7
- import { errorText, justify, machineName, questionsOf, requestSummary, shortHost } from "./ui/format.js";
8
+ import { errorText, justify, machineName, questionsOf, requestSummary, shortHost, untilText } from "./ui/format.js";
9
+ import { SessionAutocomplete } from "./ui/autocomplete.js";
10
+ import { PromptEditor } from "./ui/prompt-editor.js";
8
11
  import { Picker } from "./ui/picker.js";
9
12
  import { Home, sortSessions, statusGlyph } from "./ui/home.js";
10
- import { c, clean, editorTheme, shortPath, SPINNER } from "./ui/theme.js";
13
+ import { agoText, c, clean, editorTheme, shortPath, SPINNER } from "./ui/theme.js";
11
14
  import { TranscriptView } from "./ui/transcript-view.js";
12
15
  const PERMISSION_MODES = ["default", "read-only", "safe-yolo", "yolo", "plan"];
13
16
  /** Without input for this long the user counts as away, even if the terminal still has focus. */
@@ -15,8 +18,14 @@ const PRESENCE_IDLE_MS = 3 * 60_000;
15
18
  const LOCAL_COMMANDS = [
16
19
  { name: "sessions", description: "Back to the session list (ctrl+s)" },
17
20
  { name: "new-session", description: "Start a new agent session on a machine (ctrl+n)" },
18
- { name: "mode", description: "Change the permission mode" },
21
+ { name: "mode", description: "Change the agent mode or the permission mode" },
19
22
  { name: "model", description: "Change the model" },
23
+ { name: "effort", description: "Change the thinking level (reasoning effort)" },
24
+ { name: "rename", description: "Rename this session" },
25
+ { name: "queue", description: "Edit or cancel messages waiting to be sent" },
26
+ { name: "tree", description: "Branch into a new session from an earlier message" },
27
+ { name: "goal", description: "Show, set or clear the session's goal" },
28
+ { name: "limit", description: "After a usage limit: resume automatically, check now" },
20
29
  { name: "abort", description: "Interrupt the current turn (esc)" },
21
30
  { name: "stop-session", description: "Stop the session's agent process" },
22
31
  { name: "archive", description: "Archive this session" },
@@ -56,6 +65,7 @@ export class App {
56
65
  client;
57
66
  initialSession;
58
67
  notify;
68
+ launch;
59
69
  tui;
60
70
  view = new TranscriptView();
61
71
  scroll;
@@ -90,14 +100,26 @@ export class App {
90
100
  connection = "connecting";
91
101
  timer = null;
92
102
  commandsKey = "";
103
+ files = new Map();
104
+ /** Prompts waiting in each session's pending queue, as last fetched. */
105
+ queued = new Map();
106
+ /** The session's pending count when its queue was last fetched. */
107
+ queuedCount = new Map();
108
+ /** A queued prompt being edited in the editor; enter saves it back to the queue. */
109
+ editingQueued = null;
110
+ /** Transcript version last seen at the bottom, to tell about output arriving while scrolled up. */
111
+ seen = { id: null, version: 0 };
93
112
  resolveDone = () => { };
94
113
  done = new Promise((r) => {
95
114
  this.resolveDone = r;
96
115
  });
97
- constructor(client, initialSession, notify = { osc: true, bell: true }) {
116
+ constructor(client, initialSession, notify = { osc: true, bell: true },
117
+ /** Start a session on this computer right away instead of showing the start screen. */
118
+ launch) {
98
119
  this.client = client;
99
120
  this.initialSession = initialSession;
100
121
  this.notify = notify;
122
+ this.launch = launch;
101
123
  // The alt-screen renderer enables terminal focus reporting and consumes the focus events in
102
124
  // its own input listener, which runs before ours. Observe them at the terminal instead.
103
125
  const terminal = new ProcessTerminal();
@@ -111,7 +133,7 @@ export class App {
111
133
  scrollToEndIndicator: () => c.accent(" ↓ jump to latest "),
112
134
  });
113
135
  this.scroll = new ScrollView(this.view, { follow: "end", primary: true, scrollbar: "auto" });
114
- this.editor = new Editor(this.tui, editorTheme, { paddingX: 1 });
136
+ this.editor = new PromptEditor(this.tui, editorTheme, { paddingX: 1 });
115
137
  this.editor.onSubmit = (text) => void this.submit(text);
116
138
  this.home = new Home(() => {
117
139
  const machines = [...this.client.machines.values()];
@@ -155,6 +177,17 @@ export class App {
155
177
  { component: new Lines((w) => this.renderRequests(w)), basis: "auto", shrink: 0 },
156
178
  ]);
157
179
  this.showHome();
180
+ this.view.isBusy = () => {
181
+ const s = this.current();
182
+ return !!s && this.busy(s);
183
+ };
184
+ // Keep the clicked line where it is while what is below it unfolds.
185
+ this.view.onToggle = () => this.scroll.scrollTo(this.scroll.scrollTop, { disableFollow: true });
186
+ this.view.onSubagent = (callId) => {
187
+ const s = this.current();
188
+ if (s)
189
+ void this.loadSubagent(s, callId);
190
+ };
158
191
  this.newSessionFlow = new NewSessionFlow({
159
192
  client: this.client,
160
193
  pick: (opts) => this.pick(opts),
@@ -192,6 +225,10 @@ export class App {
192
225
  else
193
226
  this.flash(`No session matches "${wanted}"`, "warn");
194
227
  }
228
+ else if (this.launch) {
229
+ const launch = this.launch;
230
+ this.run(() => this.newSession(launch));
231
+ }
195
232
  this.tui.requestRender();
196
233
  }
197
234
  /** Shows the start screen, which doubles as the session switcher. */
@@ -256,6 +293,8 @@ export class App {
256
293
  if (s.id === this.currentId) {
257
294
  if (isBusy(s))
258
295
  this.awaiting.delete(s.id);
296
+ if (s.pendingCount !== (this.queuedCount.get(s.id) ?? 0))
297
+ void this.refreshQueue(s);
259
298
  this.refreshCommands(s);
260
299
  this.promptForRequests(s);
261
300
  }
@@ -406,9 +445,37 @@ export class App {
406
445
  this.view.hasEarlier = entry.hasEarlier;
407
446
  this.scroll.scrollToEnd();
408
447
  }
448
+ if (s.pendingCount > 0)
449
+ void this.refreshQueue(s);
409
450
  this.promptForRequests(s);
410
451
  this.tui.requestRender();
411
452
  }
453
+ async refreshQueue(s) {
454
+ this.queuedCount.set(s.id, s.pendingCount);
455
+ const list = await this.client.listQueue(s).catch(() => this.queued.get(s.id) ?? []);
456
+ this.queued.set(s.id, list);
457
+ this.tui.requestRender();
458
+ return list;
459
+ }
460
+ /** Loads a subagent's transcript the first time its tool call is shown. */
461
+ async loadSubagent(s, callId) {
462
+ const entry = this.entries.get(s.id);
463
+ if (!entry)
464
+ return;
465
+ entry.transcript.sidechain(callId); // marks it as requested
466
+ let before;
467
+ for (let page = 0; page < 10; page++) {
468
+ const res = await this.client.fetchMessages(s, { sidechainId: callId, beforeSeq: before, limit: 500 }).catch(() => null);
469
+ if (!res)
470
+ break;
471
+ for (const m of res.messages)
472
+ entry.transcript.upsert({ ...m, sidechainId: callId }, m.record);
473
+ if (!res.hasMore || res.nextBeforeSeq === null)
474
+ break;
475
+ before = res.nextBeforeSeq;
476
+ }
477
+ this.tui.requestRender();
478
+ }
412
479
  maybeLoadEarlier() {
413
480
  const s = this.current();
414
481
  const entry = s && this.entries.get(s.id);
@@ -469,7 +536,21 @@ export class App {
469
536
  if (key === this.commandsKey)
470
537
  return;
471
538
  this.commandsKey = key;
472
- this.editor.setAutocompleteProvider(new CombinedAutocompleteProvider([...LOCAL_COMMANDS, ...remote], process.cwd()));
539
+ void this.sessionFiles(s); // warm the `@` index; a large tree takes seconds to list
540
+ this.editor.placeholder = `Message ${s.metadata.flavor ?? "the agent"} · @ files · / commands`;
541
+ this.editor.setAutocompleteProvider(new SessionAutocomplete([...LOCAL_COMMANDS, ...remote], () => this.sessionFiles(s)));
542
+ }
543
+ /** The session's file list for `@` completion, fetched once per session and kept for a minute. */
544
+ sessionFiles(s) {
545
+ const cached = this.files.get(s.id);
546
+ if (cached && Date.now() - cached.at < 60_000)
547
+ return cached.list;
548
+ const list = this.client.listFiles(s).catch((e) => {
549
+ debug(`file list for ${s.id}: ${errorText(e)}`);
550
+ return [];
551
+ });
552
+ this.files.set(s.id, { at: Date.now(), list });
553
+ return list;
473
554
  }
474
555
  // --- input ---
475
556
  /** Global keys. Returns true when the key was handled and must not reach the focused component. */
@@ -507,7 +588,15 @@ export class App {
507
588
  }
508
589
  if (matchesKey(data, Key.escape)) {
509
590
  const s = this.current();
510
- if (this.editor.isShowingAutocomplete() || !s || !this.busy(s))
591
+ if (this.editor.isShowingAutocomplete())
592
+ return false;
593
+ if (this.editingQueued) {
594
+ this.editingQueued = null;
595
+ this.editor.setText("");
596
+ this.flash("Stopped editing; the queued message is unchanged.", "info");
597
+ return true;
598
+ }
599
+ if (!s || !this.busy(s))
511
600
  return false;
512
601
  void this.abort();
513
602
  return true;
@@ -575,6 +664,20 @@ export class App {
575
664
  }
576
665
  const s = this.current();
577
666
  const entry = s && this.entries.get(s.id);
667
+ const editing = this.editingQueued;
668
+ if (s && editing?.sessionId === s.id) {
669
+ this.editingQueued = null;
670
+ try {
671
+ await this.client.editQueued(s, editing.localId, text);
672
+ this.flash("Queued message updated.", "info");
673
+ }
674
+ catch (e) {
675
+ this.editor.setText(raw);
676
+ this.flash(`Not updated: ${errorText(e)}`, "error", 8000);
677
+ }
678
+ void this.refreshQueue(s);
679
+ return;
680
+ }
578
681
  if (!s || !entry) {
579
682
  this.flash("No session open — ctrl+s for the session list.", "warn");
580
683
  this.editor.setText(raw);
@@ -619,24 +722,30 @@ export class App {
619
722
  this.flash("Reloaded.", "info");
620
723
  return;
621
724
  }
622
- case "mode": {
725
+ case "mode":
726
+ return s && this.chooseMode(s, arg);
727
+ case "effort":
728
+ return s && this.chooseEffort(s, arg);
729
+ case "rename": {
623
730
  if (!s)
624
731
  return;
625
- const current = typeof s.metadata.permissionMode === "string" ? s.metadata.permissionMode : "default";
626
- const mode = PERMISSION_MODES.includes(arg)
627
- ? arg
628
- : await this.pick({
629
- title: "Permission mode",
630
- noFilter: true,
631
- selected: current,
632
- items: PERMISSION_MODES.map((m) => ({ value: m, label: m, description: m === current ? "current" : "" })),
633
- });
634
- if (!mode)
732
+ if (!arg.trim()) {
733
+ this.editor.setText(`/rename ${sessionTitle(s)}`);
734
+ this.flash("Edit the title and press enter.", "info");
635
735
  return;
636
- await this.client.setPermissionMode(s, mode);
637
- this.flash(`Permission mode: ${mode} (applies from your next message)`, "info");
736
+ }
737
+ await this.client.rename(s, arg.trim());
738
+ this.flash(`Renamed to "${arg.trim()}".`, "info");
638
739
  return;
639
740
  }
741
+ case "queue":
742
+ return s && this.manageQueue(s);
743
+ case "tree":
744
+ return s && this.branch(s);
745
+ case "goal":
746
+ return s && this.goal(s, arg.trim());
747
+ case "limit":
748
+ return s && this.limit(s);
640
749
  case "model": {
641
750
  if (!s)
642
751
  return;
@@ -712,6 +821,202 @@ export class App {
712
821
  const ok = await this.client.abort(s);
713
822
  this.flash(ok ? "Interrupt sent." : "Nothing to interrupt (no agent attached).", ok ? "info" : "warn");
714
823
  }
824
+ // --- session controls ---
825
+ /** Agent modes (when the agent reports its own) and permission modes, in one list. */
826
+ async chooseMode(s, arg) {
827
+ const agent = sessionModes(s.metadata);
828
+ const permission = typeof s.metadata.permissionMode === "string" ? s.metadata.permissionMode : "default";
829
+ const items = [
830
+ ...agent.available.map((m) => ({
831
+ value: `agent:${m.value}`,
832
+ label: m.name,
833
+ description: ["agent mode", m.value === agent.current ? "current" : "", m.description].filter(Boolean).join(" · "),
834
+ })),
835
+ ...PERMISSION_MODES.map((m) => ({ value: `perm:${m}`, label: m, description: `permissions${m === permission ? " · current" : ""}` })),
836
+ ];
837
+ const byArg = arg && items.find((i) => i.value.endsWith(`:${arg}`) || i.label === arg)?.value;
838
+ const choice = byArg ||
839
+ (await this.pick({
840
+ title: "Mode",
841
+ noFilter: items.length < 10,
842
+ selected: agent.current ? `agent:${agent.current}` : `perm:${permission}`,
843
+ items,
844
+ }));
845
+ if (!choice)
846
+ return;
847
+ const value = choice.slice(choice.indexOf(":") + 1);
848
+ if (choice.startsWith("agent:"))
849
+ await this.client.setMode(s, value);
850
+ else
851
+ await this.client.setPermissionMode(s, value);
852
+ this.flash(`Mode: ${value} (applies from your next message)`, "info");
853
+ }
854
+ async chooseEffort(s, arg) {
855
+ const model = sessionModels(s).current;
856
+ const reported = sessionOptions(s.metadata, model).find((o) => o.id === "reasoning_effort");
857
+ // Claude takes an effort even when the session did not publish the model's levels.
858
+ const effort = reported ??
859
+ (s.metadata.flavor === "claude"
860
+ ? { current: effortOverride(s.metadata) ?? "", choices: CLAUDE_EFFORT_LEVELS.map((l) => ({ value: l, name: l })) }
861
+ : undefined);
862
+ if (!effort) {
863
+ this.flash(`${model || "This model"} does not report thinking levels.`, "warn");
864
+ return;
865
+ }
866
+ const value = effort.choices.find((ch) => ch.value === arg || ch.name.toLowerCase() === arg.toLowerCase())?.value ??
867
+ (await this.pick({
868
+ title: `Thinking level · ${model}`,
869
+ hint: reported ? undefined : "this session did not report its levels; the model may not take them all",
870
+ noFilter: true,
871
+ selected: effort.current,
872
+ items: effort.choices.map((ch) => ({ value: ch.value, label: ch.name, description: ch.value === effort.current ? "current" : "" })),
873
+ }));
874
+ if (!value || value === effort.current)
875
+ return;
876
+ await this.client.setOption(s, "reasoning_effort", value);
877
+ this.flash(`Thinking level: ${value} (applies from your next message)`, "info");
878
+ }
879
+ async manageQueue(s) {
880
+ const queued = await this.refreshQueue(s);
881
+ if (queued.length === 0) {
882
+ this.flash("No message is waiting to be sent.", "info");
883
+ return;
884
+ }
885
+ const id = await this.pick({
886
+ title: `Waiting to be sent (${queued.length})`,
887
+ items: queued.map((q) => ({
888
+ value: q.localId,
889
+ label: oneLine(q.text),
890
+ description: q.delivering ? "being delivered" : agoText(q.createdAt),
891
+ })),
892
+ });
893
+ const q = queued.find((x) => x.localId === id);
894
+ if (!q)
895
+ return;
896
+ if (q.delivering) {
897
+ this.flash("That message is already being handed to the agent; it can no longer be changed.", "info");
898
+ return;
899
+ }
900
+ const action = await this.pick({
901
+ title: oneLine(q.text),
902
+ noFilter: true,
903
+ items: [
904
+ { value: "edit", label: "Edit", description: "load it in the editor; enter saves, esc leaves it as is" },
905
+ { value: "cancel", label: "Cancel", description: "remove it from the queue" },
906
+ ],
907
+ });
908
+ if (action === "cancel") {
909
+ await this.client.cancelQueued(s, q.localId);
910
+ await this.refreshQueue(s);
911
+ this.flash("Cancelled.", "info");
912
+ }
913
+ else if (action === "edit") {
914
+ this.editingQueued = { sessionId: s.id, localId: q.localId };
915
+ this.editor.setText(q.text);
916
+ this.flash("Editing a queued message: enter saves it, esc leaves it unchanged.", "info", 10_000);
917
+ }
918
+ }
919
+ /**
920
+ * Branches the conversation into a new session, like Pi's /tree: the new session holds what
921
+ * came before the chosen message, which is put back in the editor to rewrite. Codex sessions
922
+ * can instead be rolled back in place.
923
+ */
924
+ async branch(s) {
925
+ const prompts = (this.entries.get(s.id)?.transcript.list() ?? [])
926
+ .filter((r) => r.seq !== undefined && r.items[0]?.kind === "user")
927
+ .reverse();
928
+ const textOf = (r) => (r.items[0]?.kind === "user" ? r.items[0].text : "");
929
+ const choice = await this.pick({
930
+ title: "Branch from",
931
+ hint: "a new session continues from just before the message you pick (scroll up first to reach older ones)",
932
+ maxVisible: 14,
933
+ items: [
934
+ { value: "latest", label: "The whole conversation", description: "copy everything so far" },
935
+ ...prompts.map((r) => ({ value: String(r.seq), label: oneLine(textOf(r)), description: agoText(r.createdAt) })),
936
+ ],
937
+ });
938
+ if (!choice)
939
+ return;
940
+ const row = prompts.find((r) => String(r.seq) === choice);
941
+ if (row && s.metadata.flavor === "codex" && s.active) {
942
+ const how = await this.pick({
943
+ title: oneLine(textOf(row)),
944
+ noFilter: true,
945
+ items: [
946
+ { value: "fork", label: "Branch into a new session", description: "this session stays as it is" },
947
+ { value: "rollback", label: "Roll back this session", description: "undo this message and everything after it" },
948
+ ],
949
+ });
950
+ if (!how)
951
+ return;
952
+ if (how === "rollback") {
953
+ if (!(await this.confirm("Undo this message and everything after it in this session?")))
954
+ return;
955
+ await this.client.rollback(s, row.seq);
956
+ this.entries.delete(s.id);
957
+ await this.openSession(s.id);
958
+ this.editor.setText(textOf(row));
959
+ this.flash("Rolled back; the message is back in the editor.", "info");
960
+ return;
961
+ }
962
+ }
963
+ this.flash("Creating the branch…", "info", 180_000);
964
+ const childId = await this.client.fork(s, row ? row.seq : null);
965
+ await this.client.waitForSession(childId);
966
+ this.notice = null;
967
+ await this.openSession(childId);
968
+ if (row)
969
+ this.editor.setText(textOf(row));
970
+ this.flash(row ? "New branch; rewrite the message and press enter." : "New branch with the whole conversation.", "info", 8000);
971
+ }
972
+ async goal(s, arg) {
973
+ if (arg === "clear") {
974
+ await this.client.setGoal(s, null);
975
+ this.flash("Goal cleared.", "info");
976
+ return;
977
+ }
978
+ if (arg) {
979
+ await this.client.setGoal(s, arg);
980
+ this.flash("Goal set.", "info");
981
+ return;
982
+ }
983
+ const goal = sessionGoal(s.metadata);
984
+ if (!goal) {
985
+ this.editor.setText("/goal ");
986
+ this.flash("Type the goal after /goal and press enter (Claude and Codex sessions).", "info", 8000);
987
+ return;
988
+ }
989
+ const action = await this.pick({
990
+ title: `Goal · ${goal.status}: ${oneLine(goal.title)}`,
991
+ noFilter: true,
992
+ items: [
993
+ { value: "edit", label: "Change it" },
994
+ { value: "clear", label: "Clear it" },
995
+ ],
996
+ });
997
+ if (action === "edit")
998
+ this.editor.setText(`/goal ${goal.title}`);
999
+ else if (action === "clear")
1000
+ return this.goal(s, "clear");
1001
+ }
1002
+ async limit(s) {
1003
+ const u = usageLimit(s.metadata);
1004
+ const waiting = isWaitingForLimit(u);
1005
+ const action = await this.pick({
1006
+ title: waiting ? `Waiting for the usage limit${u?.resetAt ? ` to reset at ${untilText(u.resetAt)}` : ""}` : "Usage limit",
1007
+ noFilter: true,
1008
+ items: [
1009
+ ...(waiting
1010
+ ? [{ value: "waitResume.cancel", label: "Stop waiting", description: "do not resume this session by itself" }]
1011
+ : [{ value: "waitResume.enable", label: "Resume automatically", description: "continue this session when the limit resets" }]),
1012
+ { value: "checkNow", label: "Check now", description: "resume right away if the limit has reset" },
1013
+ ],
1014
+ });
1015
+ if (!action)
1016
+ return;
1017
+ const res = await this.client.usageLimitAction(s, action);
1018
+ this.flash(`Usage limit: ${String(res.status ?? "done").replace(/_/g, " ")}`, "info");
1019
+ }
715
1020
  // --- overlays ---
716
1021
  pick(opts) {
717
1022
  return new Promise((resolve) => {
@@ -790,8 +1095,8 @@ export class App {
790
1095
  return;
791
1096
  await this.client.respondPermission(s, req, choice);
792
1097
  }
793
- async newSession() {
794
- const sessionId = await this.newSessionFlow.run();
1098
+ async newSession(local) {
1099
+ const sessionId = await this.newSessionFlow.run(local);
795
1100
  if (sessionId)
796
1101
  await this.openSession(sessionId);
797
1102
  }
@@ -867,8 +1172,8 @@ export class App {
867
1172
  : c.err("○ offline — retrying");
868
1173
  let left = ` ${c.accent.bold("happier")}`;
869
1174
  if (s) {
870
- left += ` ${statusGlyph(s, this.frame)} ${c.bold(clean(sessionTitle(s)).replace(/\s+/g, " "))}`;
871
- left += c.dim(` ${s.metadata.flavor ?? "?"} · ${this.hostOf(s)} · ${shortPath(s.metadata.path, s.metadata.homeDir)}`);
1175
+ left += ` ${statusGlyph(s, this.frame)} ${c.bold.whiteBright(clean(sessionTitle(s)).replace(/\s+/g, " "))}`;
1176
+ left += c.faint(` ${s.metadata.flavor ?? "?"} · ${this.hostOf(s)} · ${shortPath(s.metadata.path, s.metadata.homeDir)}`);
872
1177
  }
873
1178
  else {
874
1179
  left += c.dim(` ${this.client.config.serverName}`);
@@ -878,7 +1183,34 @@ export class App {
878
1183
  renderRequests(width) {
879
1184
  const lines = [];
880
1185
  const s = this.current();
1186
+ const version = (s && this.entries.get(s.id)?.transcript.version) ?? 0;
1187
+ if (this.scroll.isFollowingEnd || s?.id !== this.seen.id)
1188
+ this.seen = { id: s?.id ?? null, version };
1189
+ else if (version > this.seen.version)
1190
+ lines.push(` ${c.accent("↓ new messages below")} ${c.faint("· pgdn to read")}`);
881
1191
  if (s) {
1192
+ const goal = sessionGoal(s.metadata);
1193
+ if (goal && !["complete", "cancelled"].includes(goal.status)) {
1194
+ const status = goal.reason ? `${goal.status}, ${goal.reason}` : goal.status;
1195
+ lines.push(truncateToWidth(` ${c.accent("◎")} ${c.dim(`goal (${status}):`)} ${clean(oneLine(goal.title))}`, width));
1196
+ }
1197
+ const limit = usageLimit(s.metadata);
1198
+ if (limit) {
1199
+ const when = limit.resetAt ? ` at ${untilText(limit.resetAt)}` : "";
1200
+ const text = isWaitingForLimit(limit)
1201
+ ? `Usage limit: resumes by itself${when}`
1202
+ : `Usage limit: ${limit.status}${when} · /limit`;
1203
+ lines.push(` ${c.warn("⏸")} ${c.warn(text)}`);
1204
+ }
1205
+ const queued = this.queued.get(s.id) ?? [];
1206
+ for (const q of queued.slice(0, 3)) {
1207
+ const label = q.delivering ? "⧗ sending:" : "⧗ queued:";
1208
+ lines.push(truncateToWidth(` ${c.dim(label)} ${clean(oneLine(q.text))}`, width));
1209
+ }
1210
+ if (queued.length > 0) {
1211
+ const more = queued.length > 3 ? `+${queued.length - 3} more · ` : "";
1212
+ lines.push(c.faint(` ${more}/queue to edit or cancel`));
1213
+ }
882
1214
  const reqs = pendingRequests(s);
883
1215
  const first = reqs[0];
884
1216
  if (first) {
@@ -907,13 +1239,19 @@ export class App {
907
1239
  const model = sessionModels(s).current;
908
1240
  if (model)
909
1241
  parts.push(c.dim(model));
1242
+ const effort = sessionOptions(s.metadata, model).find((o) => o.id === "reasoning_effort")?.current ?? effortOverride(s.metadata);
1243
+ if (effort)
1244
+ parts.push(c.dim(`thinking ${effort}`));
910
1245
  const usage = this.entries.get(s.id)?.transcript.usage;
911
1246
  if (usage?.contextUsed && usage.contextWindow) {
912
1247
  const pct = Math.round((usage.contextUsed / usage.contextWindow) * 100);
913
- parts.push((pct >= 85 ? c.warn : c.dim)(`ctx ${pct}%`));
1248
+ const of = `${tokens(usage.contextUsed)}/${tokens(usage.contextWindow)}`;
1249
+ parts.push((pct >= 85 ? c.warn : c.dim)(`context ${pct}% (${of})`));
914
1250
  }
915
- if (s.pendingCount > 0)
916
- parts.push(c.dim(`${s.pendingCount} queued`));
1251
+ else if (usage?.contextUsed)
1252
+ parts.push(c.dim(`context ${tokens(usage.contextUsed)}`));
1253
+ if (usage?.cost)
1254
+ parts.push(c.dim(`$${usage.cost.toFixed(2)}`));
917
1255
  let state;
918
1256
  if (this.busy(s))
919
1257
  state = c.warn(`${SPINNER[this.frame % SPINNER.length]} working`) + c.dim(" · esc to interrupt");
@@ -921,10 +1259,20 @@ export class App {
921
1259
  state = c.dim("inactive · sending resumes it");
922
1260
  else
923
1261
  state = c.ok("ready");
924
- return [justify(` ${state}${c.dim(" · ")}${parts.join(c.dim(" · "))}`, c.dim("ctrl+s sessions · /keys "), width)];
1262
+ const right = `${this.busy(s) ? "" : `last activity ${agoText(s.activityAt)} · `}ctrl+s sessions · /keys `;
1263
+ return [justify(` ${state}${c.dim(" · ")}${parts.join(c.dim(" · "))}`, c.faint(right), width)];
925
1264
  }
926
1265
  }
927
1266
  const isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v);
1267
+ const oneLine = (text) => text.replace(/\s+/g, " ").trim();
1268
+ /** 126443 → "126k", 1000000 → "1M". */
1269
+ function tokens(n) {
1270
+ if (n >= 1_000_000)
1271
+ return `${Number((n / 1_000_000).toFixed(1))}M`;
1272
+ if (n >= 1000)
1273
+ return `${Math.round(n / 1000)}k`;
1274
+ return String(n);
1275
+ }
928
1276
  function isDirect(s) {
929
1277
  return isObj(s.metadata.directSessionV1) && s.seq === 0;
930
1278
  }