@erichll/pi-statusline 0.4.1 → 0.6.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.
@@ -1,6 +1,6 @@
1
1
  import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
2
2
  import type { RenderTheme } from "./render.ts";
3
- import { cleanText } from "./text.ts";
3
+ import type { RuntimeSnapshot } from "./runtime.ts";
4
4
  import type { StatuslineConfig, StatuslineSnapshot } from "./types.ts";
5
5
 
6
6
  export function seconds(ms: number): string { return `${Math.floor(ms / 1000)}s`; }
@@ -13,50 +13,123 @@ export function elapsed(ms: number): string {
13
13
  }
14
14
  return parts.join(" ");
15
15
  }
16
- interface Part { id: string; text: string; color?: "text" | "muted" | "warning" | "error" | "success"; styled?: string }
16
+ /** Tool timers stay narrow: `12s`, `1m5s`. */
17
+ function short(ms: number): string {
18
+ const total = Math.floor(ms / 1000);
19
+ return total < 60 ? `${total}s` : `${Math.floor(total / 60)}m${total % 60}s`;
20
+ }
21
+ function plural(count: number, word: string): string { return `${word}${count === 1 ? "" : "s"}`; }
22
+
23
+ type Color = "text" | "muted" | "dim" | "accent" | "success" | "warning" | "error";
24
+ type Span = [text: string, color: Color];
25
+ interface Part { id: string; spans: Span[]; styled?: string }
26
+
27
+ function draw(parts: Part[], separator: string, theme: RenderTheme): string {
28
+ return parts.map((part) => part.styled ?? part.spans.map(([text, color]) => theme.style(text, { fg: theme.colors[color] })).join(""))
29
+ .join(theme.style(separator, { fg: theme.colors.dim }));
30
+ }
31
+ function fit(parts: Part[], dropOrder: string[], width: number, separator: string, theme: RenderTheme, ellipsis: string): string | undefined {
32
+ let line = draw(parts, separator, theme);
33
+ for (const id of dropOrder) {
34
+ if (visibleWidth(line) <= width) break;
35
+ const index = parts.findIndex((part) => part.id === id);
36
+ if (index !== -1) { parts.splice(index, 1); line = draw(parts, separator, theme); }
37
+ }
38
+ return parts.length ? truncateToWidth(line, width, ellipsis) : undefined;
39
+ }
40
+
41
+ const STATUS: Partial<Record<RuntimeSnapshot["status"], { icon: string; ascii: string; color: Color }>> = {
42
+ Running: { icon: "●", ascii: "*", color: "accent" },
43
+ Done: { icon: "✓", ascii: "ok", color: "success" },
44
+ Failed: { icon: "✗", ascii: "x", color: "error" },
45
+ Cancelled: { icon: "⊘", ascii: "-", color: "muted" },
46
+ };
17
47
 
18
- /** Layout consumes snapshots only; width decisions use terminal cells, including ANSI. */
19
- export function renderRuntime(width: number, data: StatuslineSnapshot, config: StatuslineConfig, theme: RenderTheme, extensionStatus?: string, elapsedStatus?: string): string | undefined {
48
+ export interface RuntimeExtras {
49
+ /** Other extensions' statuses, already styled. */
50
+ statuses?: string;
51
+ /** Session age, already styled. */
52
+ session?: string;
53
+ /** Session token total, already styled. */
54
+ tokens?: string;
55
+ /** A `tps` extension status of the form `Elapsed 5m 42s`. */
56
+ elapsedStatus?: string;
57
+ }
58
+
59
+ /** The bottom row: run status and duration, run metrics, then session age, tokens and extension statuses. */
60
+ export function renderRuntime(width: number, data: StatuslineSnapshot, config: StatuslineConfig, theme: RenderTheme, extras: RuntimeExtras = {}): string | undefined {
20
61
  const parts: Part[] = [];
21
62
  const runtime = data.runtime, compact = data.compaction;
22
- const enabled = config.runtime.enabled;
23
- const add = (id: string, text: string, color?: Part["color"]) => parts.push({ id, text, color });
24
- if (elapsedStatus) add("elapsed", elapsedStatus);
25
- else if (enabled && config.runtime.status && runtime?.runId) add("elapsed", `Elapsed ${elapsed(runtime.elapsedMs)}`);
26
- if (enabled && compact?.active) {
27
- add("status", `${config.icons === "ascii" ? "Compacting..." : "Compacting…"} ${seconds(compact.elapsedMs)}`, "warning");
28
- if (config.runtime.counts && compact.count > 0) add("compactions", `Compactions ${compact.count}`);
29
- } else {
30
- if (enabled && runtime) {
31
- if (config.runtime.status) {
32
- const failure = compact?.showFailure && runtime.status !== "Running" ? `Compaction ${compact.last?.status}` : undefined;
33
- if (failure) add("status", failure, "error");
34
- }
35
- let busy = false;
36
- if (runtime.awaitingInput) { add("activity", "Awaiting input", "warning"); busy = true; }
37
- else if (config.runtime.tools && runtime.tools.length) {
38
- add("activity", runtime.tools.length > 1 ? `Tools ${runtime.tools.length} active` : `Tool ${cleanText(runtime.tools[0]!.name).slice(0, 40)} ${seconds(runtime.tools[0]!.elapsedMs)}`);
39
- busy = true;
40
- } else if (config.runtime.noContent && runtime.noContentMs !== null && runtime.noContentMs >= config.runtime.noContentSeconds * 1000) {
41
- add("activity", `No content ${seconds(runtime.noContentMs)}`); busy = true;
42
- }
43
- if (!busy) {
44
- if (config.runtime.avg && runtime.avg !== null) add("avg", `Avg ${Math.round(runtime.avg)} tok/s`);
45
- if (config.runtime.cache && runtime.cache !== null) add("cache", `Cache ${Math.round(runtime.cache * 100)}%`);
46
- }
47
- if (config.runtime.counts && runtime.runId) add("turns", `Turns ${runtime.turns}`);
63
+ const enabled = config.runtime.enabled, ascii = config.icons === "ascii";
64
+ const add = (id: string, ...spans: Span[]) => parts.push({ id, spans });
65
+ const count = (id: string, value: number, word: string) => add(id, [String(value), "text"], [` ${plural(value, word)}`, "dim"]);
66
+ const duration = extras.elapsedStatus?.replace(/^Elapsed /, "") ?? (runtime?.runId ? elapsed(runtime.elapsedMs) : undefined);
67
+ const state = enabled && config.runtime.status && runtime?.runId ? STATUS[runtime.status] : undefined;
68
+ if (state && duration) add("elapsed", [ascii ? state.ascii : state.icon, state.color], [` ${duration}`, "text"]);
69
+ else if (extras.elapsedStatus) add("elapsed", ["elapsed ", "dim"], [duration!, "text"]);
70
+ const compacting = enabled && !!compact?.active;
71
+ if (compacting) {
72
+ add("activity", [`${ascii ? "compacting..." : "compacting…"} ${seconds(compact!.elapsedMs)}`, "warning"]);
73
+ } else if (enabled && runtime) {
74
+ if (config.runtime.status && compact?.showFailure && runtime.status !== "Running") add("failure", [`compaction ${compact.last?.status}`, "error"]);
75
+ if (runtime.awaitingInput) add("activity", ["awaiting input", "warning"]);
76
+ else if (config.runtime.noContent && runtime.noContentMs !== null && runtime.noContentMs >= config.runtime.noContentSeconds * 1000) {
77
+ add("activity", [`no content ${seconds(runtime.noContentMs)}`, "warning"]);
48
78
  }
49
- if (enabled && config.runtime.counts && compact && compact.count > 0) add("compactions", `Compactions ${compact.count}`);
50
- if (extensionStatus) parts.push({ id: "statuses", text: extensionStatus, styled: extensionStatus });
79
+ if (config.runtime.avg && runtime.avg !== null) add("avg", ["avg ", "dim"], [`${Math.round(runtime.avg)} tok/s`, "text"]);
80
+ if (config.runtime.cache && runtime.cache !== null) {
81
+ const percent = Math.round(runtime.cache * 100);
82
+ add("cache", ["cache ", "dim"], [`${percent}%`, percent >= 80 ? "success" : percent >= 50 ? "text" : "warning"]);
83
+ }
84
+ if (config.runtime.counts && runtime.runId) count("turns", runtime.turns, "turn");
51
85
  }
52
- const separator = config.icons === "ascii" ? " | " : " · ";
53
- const draw = () => parts.map((part) => part.styled ?? theme.style(part.text, { fg: theme.colors[part.color ?? "muted"] })).join(theme.style(separator, { fg: theme.colors.dim }));
54
- let line = draw();
55
- for (const id of ["statuses", "cache", "avg", "compactions", "turns", "activity"]) {
56
- if (visibleWidth(line) <= width) break;
57
- const index = parts.findIndex((part) => part.id === id);
58
- if (index !== -1) parts.splice(index, 1);
59
- line = draw();
86
+ if (enabled && config.runtime.counts && compact && compact.count > 0) count("compactions", compact.count, "compaction");
87
+ if (extras.session) parts.push({ id: "session", spans: [], styled: extras.session });
88
+ if (extras.tokens) parts.push({ id: "tokens", spans: [], styled: extras.tokens });
89
+ if (extras.statuses && !compacting) parts.push({ id: "statuses", spans: [], styled: extras.statuses });
90
+ return fit(parts, ["statuses", "cache", "avg", "compactions", "session", "tokens", "turns", "activity", "failure"], width, ascii ? " | " : " · ", theme, ascii ? "..." : "…");
91
+ }
92
+
93
+ /** `◐ bash npm test 12s · ✓ read ×5 · ✗ bash ×1 · +2`: present while the run has used tools. */
94
+ export function renderTools(width: number, data: StatuslineSnapshot, config: StatuslineConfig, theme: RenderTheme): string | undefined {
95
+ const runtime = data.runtime;
96
+ if (!config.runtime.enabled || !config.runtime.tools || !runtime || (!runtime.tools.length && !runtime.completed.length)) return undefined;
97
+ const ascii = config.icons === "ascii";
98
+ const sym = ascii ? { run: ">", ok: "ok", fail: "x", times: "x" } : { run: "◐", ok: "✓", fail: "✗", times: "×" };
99
+ const running: { name: string; count: number; target?: string; elapsedMs: number }[] = [];
100
+ for (const tool of runtime.tools) {
101
+ const group = running.find((item) => item.name === tool.name);
102
+ if (!group) running.push({ name: tool.name, count: 1, target: tool.target, elapsedMs: tool.elapsedMs });
103
+ else { group.count++; group.target = undefined; group.elapsedMs = Math.max(group.elapsedMs, tool.elapsedMs); }
104
+ }
105
+ const ok = runtime.completed.filter((tool) => tool.ok).sort((a, b) => b.ok - a.ok);
106
+ const failed = runtime.completed.filter((tool) => tool.failed).sort((a, b) => b.failed - a.failed);
107
+ const build = (visible: number, targets: boolean, timers: boolean): Part[] => {
108
+ const parts: Part[] = running.slice(0, 2).map((group) => {
109
+ const spans: Span[] = [[sym.run, "warning"], [` ${group.name}`, "accent"]];
110
+ if (group.count > 1) spans.push([` ${sym.times}${group.count}`, "dim"]);
111
+ else if (targets && group.target) spans.push([` ${group.target}`, "muted"]);
112
+ if (timers && group.elapsedMs >= 1000) spans.push([` ${short(group.elapsedMs)}`, group.elapsedMs >= 30000 ? "warning" : "muted"]);
113
+ return { id: "running", spans };
114
+ });
115
+ const moreRunning = running.slice(2).reduce((total, group) => total + group.count, 0);
116
+ if (moreRunning) parts.push({ id: "running", spans: [[sym.run, "warning"], [` +${moreRunning}`, "dim"]] });
117
+ for (const tool of ok.slice(0, visible)) parts.push({ id: "ok", spans: [[sym.ok, "success"], [` ${tool.name}`, "muted"], [` ${sym.times}${tool.ok}`, "dim"]] });
118
+ for (const tool of failed) parts.push({ id: "failed", spans: [[sym.fail, "error"], [` ${tool.name}`, "muted"], [` ${sym.times}${tool.failed}`, "error"]] });
119
+ const hidden = ok.length - Math.min(visible, ok.length);
120
+ if (hidden) parts.push({ id: "more", spans: [[`+${hidden}`, "dim"]] });
121
+ return parts;
122
+ };
123
+ // Narrowing order: fold completed kinds, then drop targets, then timers; running names go last.
124
+ const max = config.runtime.toolsMaxVisible;
125
+ const attempts: [number, boolean, boolean][] = [];
126
+ for (let visible = max; visible >= 1; visible--) attempts.push([visible, true, true]);
127
+ attempts.push([1, false, true], [0, false, true], [0, false, false]);
128
+ const separator = ascii ? " | " : " · ";
129
+ let parts: Part[] = [];
130
+ for (const [visible, targets, timers] of attempts) {
131
+ parts = build(visible, targets, timers);
132
+ if (visibleWidth(draw(parts, separator, theme)) <= width) break;
60
133
  }
61
- return parts.length ? truncateToWidth(line, width, config.icons === "ascii" ? "..." : "…") : undefined;
134
+ return fit(parts, [], width, separator, theme, ascii ? "..." : "…");
62
135
  }
package/src/runtime.ts CHANGED
@@ -2,6 +2,7 @@ import { randomUUID } from "node:crypto";
2
2
  import type { AssistantMessage, AssistantMessageEvent } from "@earendil-works/pi-ai";
3
3
  import type { AgentActivityOutcome } from "@earendil-works/pi-coding-agent";
4
4
  import { cleanText } from "./text.ts";
5
+ import { toolTarget } from "./tools.ts";
5
6
  import { emptyUsage, readUsage } from "./usage.ts";
6
7
  import type { UsageTotals } from "./types.ts";
7
8
 
@@ -12,7 +13,10 @@ export interface RuntimeSnapshot {
12
13
  elapsedMs: number;
13
14
  turns: number;
14
15
  toolCalls: number;
15
- tools: { name: string; elapsedMs: number }[];
16
+ /** Running top-level tools in start order; nested calls are represented by their parent. */
17
+ tools: { name: string; target?: string; elapsedMs: number }[];
18
+ /** Finished calls this run, by tool name in first-seen order. */
19
+ completed: { name: string; ok: number; failed: number }[];
16
20
  awaitingInput: boolean;
17
21
  noContentMs: number | null;
18
22
  usage: UsageTotals | null;
@@ -30,7 +34,8 @@ export class RuntimeState {
30
34
  private outcome: AgentActivityOutcome = "completed";
31
35
  private aborted = false;
32
36
  private turns = 0;
33
- private tools = new Map<string, { name: string; start: number }>();
37
+ private tools = new Map<string, { name: string; target?: string; nested: boolean; start: number }>();
38
+ private completed = new Map<string, { ok: number; failed: number }>();
34
39
  private seenTools = new Set<string>();
35
40
  private prompts = 0;
36
41
  private modelActive = false;
@@ -45,7 +50,7 @@ export class RuntimeState {
45
50
  get id(): string | null { return this.runId; }
46
51
  reset(): void {
47
52
  this.runId = null; this.state = "Idle"; this.startMs = 0; this.endMs = 0;
48
- this.outcome = "completed"; this.aborted = false; this.turns = 0; this.tools.clear(); this.seenTools.clear();
53
+ this.outcome = "completed"; this.aborted = false; this.turns = 0; this.tools.clear(); this.completed.clear(); this.seenTools.clear();
49
54
  this.prompts = 0; this.modelActive = false; this.compacting = false;
50
55
  this.messages.clear(); this.messageAliases.clear(); this.activeMessage = undefined; this.sequence = 0;
51
56
  }
@@ -102,11 +107,22 @@ export class RuntimeState {
102
107
  if (!this.aborted) this.outcome = message.stopReason === "aborted" ? "aborted" : message.stopReason === "error" ? "error" : "completed";
103
108
  }
104
109
  }
105
- toolStart(id: string, name: string): void {
110
+ toolStart(id: string, name: string, args?: unknown, parentId?: string): void {
106
111
  if (!this.running || this.seenTools.has(id)) return;
107
- this.seenTools.add(id); this.tools.set(id, { name: cleanText(name).slice(0, 40) || "unknown", start: this.clock() });
112
+ const target = toolTarget(name, args);
113
+ this.seenTools.add(id);
114
+ this.tools.set(id, { name: cleanText(name).slice(0, 40) || "unknown", ...(target ? { target } : {}), nested: !!parentId, start: this.clock() });
115
+ }
116
+ toolEnd(id: string, isError = false): void {
117
+ const tool = this.tools.get(id);
118
+ if (!tool) return;
119
+ this.tools.delete(id);
120
+ // Calls interrupted by a user cancellation are not tool failures; the run status says so.
121
+ if (isError && this.aborted) return;
122
+ const count = this.completed.get(tool.name) ?? { ok: 0, failed: 0 };
123
+ if (isError) count.failed++; else count.ok++;
124
+ this.completed.set(tool.name, count);
108
125
  }
109
- toolEnd(id: string): void { this.tools.delete(id); }
110
126
  uiStart(): void { this.prompts++; }
111
127
  uiEnd(): void { this.prompts = Math.max(0, this.prompts - 1); this.lastContent = this.clock(); }
112
128
  compaction(active: boolean): void { this.compacting = active; this.lastContent = this.clock(); }
@@ -120,7 +136,9 @@ export class RuntimeState {
120
136
  return {
121
137
  runId: hidden ? null : this.runId, status: hidden ? "Idle" : this.state, elapsedMs,
122
138
  turns: hidden ? 0 : this.turns, toolCalls: hidden ? 0 : this.seenTools.size,
123
- tools: [...this.tools.values()].map((tool) => ({ name: tool.name, elapsedMs: Math.max(0, now - tool.start) })),
139
+ tools: [...this.tools.values()].filter((tool) => !tool.nested)
140
+ .map((tool) => ({ name: tool.name, ...(tool.target ? { target: tool.target } : {}), elapsedMs: Math.max(0, now - tool.start) })),
141
+ completed: hidden ? [] : [...this.completed].map(([name, count]) => ({ name, ...count })),
124
142
  awaitingInput: this.prompts > 0,
125
143
  noContentMs: this.running && this.modelActive && !this.tools.size && !this.prompts && !this.compacting ? Math.max(0, now - this.lastContent) : null,
126
144
  usage, avg: usage && elapsedMs > 0 ? usage.output / (elapsedMs / 1000) : null,
package/src/session.ts CHANGED
@@ -8,10 +8,18 @@ import type { StatuslineConfig, StatuslineSnapshot } from "./types.ts";
8
8
  import { UsageCache } from "./usage.ts";
9
9
  import { RuntimeState } from "./runtime.ts";
10
10
  import { CompactionState } from "./compaction.ts";
11
+ import { QuotaState } from "./quota.ts";
12
+
13
+ /** The header's creation time; hidden rather than guessed when missing, malformed or in the future. */
14
+ export function sessionStart(timestamp: string | undefined, now = Date.now()): number | null {
15
+ const ms = timestamp ? Date.parse(timestamp) : NaN;
16
+ return Number.isFinite(ms) && ms <= now + 60000 ? ms : null;
17
+ }
11
18
 
12
19
  export class FooterSession {
13
20
  readonly runtime = new RuntimeState();
14
21
  readonly compaction = new CompactionState();
22
+ readonly quota = new QuotaState();
15
23
  private ctx: ExtensionContext;
16
24
  private config: StatuslineConfig;
17
25
  private usage = new UsageCache();
@@ -27,6 +35,7 @@ export class FooterSession {
27
35
  private statsKey = "";
28
36
  private displayKey = "";
29
37
  private context: StatuslineSnapshot["context"] = { tokens: null, contextWindow: 0, percent: null };
38
+ private sessionStartMs: number | null = null;
30
39
  private readonly gitReader: GitReader | undefined;
31
40
  private signal: AbortSignal | undefined;
32
41
  private readonly onAbort = () => { this.runtime.observeAbort(); this.schedule(true); };
@@ -35,7 +44,12 @@ export class FooterSession {
35
44
  this.ctx = ctx; this.config = config; this.gitReader = gitReader;
36
45
  }
37
46
  get active(): boolean { return this.ownsFooter && !this.closed; }
38
- setContext(ctx: ExtensionContext): void { this.ctx = ctx; this.watchSignal(); }
47
+ setContext(ctx: ExtensionContext): void { this.ctx = ctx; this.quota.select(ctx.model); this.watchSignal(); }
48
+ beginProviderRequest(): void { if (this.active) this.quota.beginRequest(this.ctx.model); }
49
+ observeProviderResponse(headers: Record<string, string>): void {
50
+ if (!this.active) return;
51
+ this.quota.response(headers, this.ctx.model); this.schedule(true);
52
+ }
39
53
  private watchSignal(): void {
40
54
  if (this.closed || !this.ownsFooter || !this.runtime.running) return;
41
55
  const signal = this.ctx.signal;
@@ -81,15 +95,19 @@ export class FooterSession {
81
95
  this.unsubscribe?.(); this.unsubscribe = undefined;
82
96
  this.ownsFooter = false; this.tui = undefined; this.provider = undefined;
83
97
  }
84
- disable(): void {
98
+ private uninstall(): void {
85
99
  const restore = this.ownsFooter;
86
100
  this.stopResources();
87
101
  if (restore && !this.closed) this.ctx.ui.setFooter(undefined);
88
102
  }
89
- dispose(): void { this.stopResources(); this.clearSignal(); this.closed = true; }
103
+ disable(): void { this.uninstall(); this.quota.clear(); }
104
+ dispose(): void { this.stopResources(); this.clearSignal(); this.quota.clear(); this.closed = true; }
90
105
  apply(config: StatuslineConfig): void {
91
106
  if (this.closed) return;
92
- this.disable(); this.config = config;
107
+ const keepQuota = this.active && config.enabled;
108
+ this.uninstall();
109
+ if (!keepQuota) this.quota.clear();
110
+ this.config = config;
93
111
  if (config.enabled) this.install();
94
112
  }
95
113
  setLive(message: AssistantMessage | undefined): void { this.usage.setLive(message); }
@@ -112,6 +130,7 @@ export class FooterSession {
112
130
  const entries = manager.getEntries();
113
131
  this.usage.update(entries);
114
132
  this.compaction.update(entries);
133
+ this.sessionStartMs = sessionStart(manager.getHeader()?.timestamp);
115
134
  const context = this.ctx.getContextUsage();
116
135
  this.context = context ?? { tokens: null, contextWindow: this.ctx.model?.contextWindow ?? 0, percent: null };
117
136
  }
@@ -129,8 +148,10 @@ export class FooterSession {
129
148
  return {
130
149
  model: this.ctx.model?.name || this.ctx.model?.id || "No model", modelId: this.ctx.model?.id ?? "", reasoning: this.ctx.model?.reasoning ?? false,
131
150
  thinking: this.ctx.thinkingLevel ?? "off", cwd: this.ctx.cwd, home: homedir(),
132
- context: this.context, usage: this.usage.snapshot(), git: this.git,
151
+ context: this.context, usage: this.usage.snapshot(), quota: this.quota.snapshot(this.ctx.model), git: this.git,
133
152
  statuses: this.provider?.getExtensionStatuses() ?? new Map(),
153
+ // Minute resolution keeps an idle footer from repainting every second.
154
+ sessionMinutes: this.sessionStartMs === null ? null : Math.floor(Math.max(0, Date.now() - this.sessionStartMs) / 60000),
134
155
  runtime: this.runtime.snapshot(this.config.runtime.retainSummary), compaction: this.compaction.snapshot(),
135
156
  };
136
157
  }
package/src/tools.ts ADDED
@@ -0,0 +1,43 @@
1
+ import { basename } from "node:path";
2
+ import { visibleWidth } from "@earendil-works/pi-tui";
3
+ import { cleanText } from "./text.ts";
4
+
5
+ function arg(args: unknown, key: string): string | undefined {
6
+ if (typeof args !== "object" || args === null) return undefined;
7
+ const value = (args as Record<string, unknown>)[key];
8
+ return typeof value === "string" ? value : undefined;
9
+ }
10
+ /** Plain-text truncation: targets are styled later, so no escape codes here. */
11
+ function fit(text: string | undefined, width: number): string | undefined {
12
+ if (!text || visibleWidth(text) <= width) return text || undefined;
13
+ let result = "";
14
+ for (const character of text) {
15
+ if (visibleWidth(result + character) > width - 1) break;
16
+ result += character;
17
+ }
18
+ return `${result}…`;
19
+ }
20
+ function fileName(path: string | undefined): string | undefined {
21
+ const name = path ? basename(cleanText(path).replace(/[\\/]+$/, "")) : "";
22
+ return name && name !== "." ? name : undefined;
23
+ }
24
+ /** `cd dir && FOO=1 npm test` → `npm test`: the part that says what is running. */
25
+ function commandSummary(command: string): string | undefined {
26
+ let text = cleanText(command.split(/\r?\n/).find((line) => line.trim()) ?? "");
27
+ for (let previous = ""; previous !== text;) {
28
+ previous = text;
29
+ text = text.replace(/^cd\s+(?:"[^"]*"|'[^']*'|\S+)\s*(?:&&|;)\s*/, "").replace(/^[A-Za-z_][A-Za-z0-9_]*=(?:"[^"]*"|'[^']*'|\S*)\s+/, "");
30
+ }
31
+ return text || undefined;
32
+ }
33
+
34
+ /** A short, sanitized description of what a built-in tool call is working on. */
35
+ export function toolTarget(name: string, args: unknown): string | undefined {
36
+ switch (name) {
37
+ case "bash": case "powershell": { const command = arg(args, "command"); return fit(command && commandSummary(command), 24); }
38
+ case "read": case "edit": case "write": return fit(fileName(arg(args, "path")), 24);
39
+ case "grep": case "find": { const pattern = arg(args, "pattern"); const text = pattern && cleanText(pattern); return text ? `"${fit(text, 16)}"` : undefined; }
40
+ case "ls": { const dir = fileName(arg(args, "path")); return dir ? `${fit(dir, 23)}/` : undefined; }
41
+ default: return undefined;
42
+ }
43
+ }
package/src/types.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { ThemeColor } from "@earendil-works/pi-coding-agent";
2
2
 
3
- export const SEGMENT_IDS = ["model", "thinking", "context", "directory", "git", "cost", "input", "output", "tokens", "cacheRead", "cacheWrite", "statuses"] as const;
3
+ export const SEGMENT_IDS = ["model", "thinking", "context", "quota", "directory", "git", "cost", "input", "output", "session", "tokens", "cacheRead", "cacheWrite", "statuses"] as const;
4
4
  export type SegmentId = typeof SEGMENT_IDS[number];
5
5
  export type ColorValue = ThemeColor | `#${string}`;
6
6
  export type Preset = "powerline";
@@ -15,6 +15,8 @@ export interface RuntimeConfig {
15
15
  cache: boolean;
16
16
  counts: boolean;
17
17
  retainSummary: boolean;
18
+ /** Completed tool kinds shown before folding into `+N` (1–8). */
19
+ toolsMaxVisible: number;
18
20
  }
19
21
  export interface SegmentConfig {
20
22
  id: SegmentId;
@@ -65,8 +67,11 @@ export interface StatuslineSnapshot {
65
67
  home: string;
66
68
  context: { tokens: number | null; contextWindow: number; percent: number | null };
67
69
  usage: UsageTotals;
70
+ quota?: import("./quota.ts").QuotaSnapshot;
68
71
  git: GitState;
69
72
  statuses: ReadonlyMap<string, string>;
73
+ /** Whole minutes since the session file was created; null when unknown. */
74
+ sessionMinutes: number | null;
70
75
  runtime?: import("./runtime.ts").RuntimeSnapshot;
71
76
  compaction?: import("./compaction.ts").CompactionSnapshot;
72
77
  }