agy-bar 0.9.0 → 0.9.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  All notable changes to **agy-bar** are documented here.
4
4
 
5
+ ## [0.9.1] - 2026-11-26
6
+
7
+ ### Added
8
+ - **Full 6-State Agent Activity Machine (`src/agent-state.mjs`)**:
9
+ - Unified session activity classification across terminal tab titles, statusline Line 1 badges, telemetry turn timers, and `agy-bar monitor`, aligned with Antigravity CLI's official `statusLine` payload schema (`agent_state`, `tool_confirmation_pending`, `subagents`, `task_count`, and native `cost.total_usd`).
10
+ - **Subagents / Background Tasks Active (`SUB N` / `TASK N` / `● [N]`)**: Replaced emoji `⚡N` with cohesive ASCII `SUB N` and `TASK N` badges on Line 1 (zero cross-terminal glyph-width drift). When the parent agent pauses (`agent_state: "idle"`) while subagents (`subagents[].status === "running"`) or background tasks (`task_count > 0`) are still executing, tab titles stay active (`● [N] <topic>` / `● <topic>`) instead of falsely showing `✓` complete.
11
+ - **Waiting for User Input / Approval (`?` / `CONFIRM` / `INPUT`)**: Displays `? <topic>` on the tab, bold amber `CONFIRM` (`tool_confirmation_pending: true`) or `INPUT` (`agent_state: "reviewing"`) on statusline Line 1, and `? confirm` / `? input` + `N waiting` summary in `agy-bar monitor`.
12
+ - **Error & Startup States (`✗ ERR` / `…`)**: Distinctly marks `error` (`✗` + bold red `ERR`) and `authenticating` / `initializing` (`…`) instead of falling back to `✓`.
13
+ - **Native `cost.total_usd` Compatibility**: Automatically incorporates AGY's native `cost.total_usd` field when reported alongside local DB/telemetry cost tracking.
14
+
5
15
  ## [0.9.0] - 2026-11-26
6
16
 
7
17
  ### Added
package/README.md CHANGED
@@ -14,6 +14,10 @@
14
14
 
15
15
  </div>
16
16
 
17
+ ![agy-bar live Ghostty terminal screenshot](https://raw.githubusercontent.com/xy-tuoren/agy-bar/main/assets/live-statusline.png)
18
+
19
+ <sub>Real Ghostty capture: 10 running subagents (`⚡10`), live Git diff (`+14.3K -803`), no-TUN proxy (`PX 7897`), 1.01B cumulative tokens, 99% prompt cache TTL, TTFT & speed, live conversation spend, and 5h/7d quotas.</sub>
20
+
17
21
  ![agy-bar true-color statusline preview](https://raw.githubusercontent.com/xy-tuoren/agy-bar/main/assets/preview.svg)
18
22
 
19
23
  ```sh
@@ -34,7 +38,7 @@ CTX ▮▮▮▯▯▯▯▯ 42.6% (1.0M) │ CACHE 88%·3m42s │ TTFT 1.9s·15
34
38
 
35
39
  | Zone | What It Shows | Smart Behavior |
36
40
  | --- | --- | --- |
37
- | **Line 1 · Left** | `~/code/agy-bar (main* +142 -38) · PX 7897` | Compact `~` path (`dirStyle`), live Git diff lines (tracked + untracked text, 3s cache), active proxy port badge, plus on-demand busy badges (`● 34s · esc`, `⚡2` subagents, `PLAN` / `SANDBOX`, Vim `[NORMAL]`) |
41
+ | **Line 1 · Left** | `~/code/agy-bar (main* +142 -38) · PX 7897` | Compact `~` path (`dirStyle`), live Git diff lines (tracked + untracked text, 3s cache), active proxy port badge, plus on-demand state badges (`CONFIRM` / `INPUT` when waiting on you, `ERR`, `● 34s · esc`, `SUB N` subagents, `TASK N` background tasks, `PLAN` / `SANDBOX`, Vim `[NORMAL]`) |
38
42
  | **Line 1 · Right** | `DAY 136M/$13.2 · WK 810M · MO 875M · ALL 906M │ Model` | Calm neutral cumulative token/spend strip + active model & reasoning effort; sheds gracefully on narrow split panes |
39
43
  | **Line 2 · Left** | `CTX ▮▮▮▯▯▯▯▯ 42.6% (1.0M) │ CACHE 88%·3m42s │ TTFT 1.9s·158t/s │ ~$0.18` | Unified health context gauge (`→/compact` at danger), 5-min prompt cache TTL countdown, exact first-token latency + streaming decode speed, and live conversation spend (rolls up nested subagent costs automatically, refreshing every 20s while subagents run) |
40
44
  | **Line 2 · Right** | `5h ▮▮▮▮▮▯ 85% (2h30m) │ 7d ▮▮▮▮▯▯ 64% (3d)` | Active model pool quotas (**Gemini 4 Neon / Carbon / Hydrogen / Argon** & **Claude 3p**) with reset countdowns |
@@ -76,14 +80,13 @@ Running 3–5 `agy` sessions across different repos? Open `agy-bar monitor` in a
76
80
 
77
81
  ---
78
82
 
79
- ### 5. Automatic Terminal Tab Titles (`●` / `✓`) & Agent Summarization (`agy-bar title`)
83
+ ### 5. Automatic Terminal Tab Titles (`●` / `● [N]` / `?` / `✓`) & Agent Summarization (`agy-bar title`)
80
84
 
81
- Replaces identical `agy --dangerously-skip-permissions` tabs across Ghostty, iTerm2, Kitty, WezTerm, macOS Terminal, and VS Code with live state + conversation title via standard OSC 0/2 (zero extra tokens; safely skipped on native Windows):
85
+ Replaces identical `agy --dangerously-skip-permissions` tabs across Ghostty, iTerm2, Kitty, WezTerm, macOS Terminal, and VS Code with live activity state (`●` working, `● [N]` running subagents, `?` waiting for user input/confirmation, `✗` error, `✓` truly idle) + concise topic title via standard OSC 0/2 (zero extra tokens; safely skipped on native Windows):
82
86
 
83
- ```text
84
- Before: agy --dangerously-skip-permissions │ agy --dangerously-skip-permissions │ agy --dangerously-skip-permissions
85
- After: ● Fix Windows doctor check │ ✓ agy-bar (main*) │ ● Add 52-week stats heatmap
86
- ```
87
+ ![agy-bar live Ghostty tab titles comparison](https://raw.githubusercontent.com/xy-tuoren/agy-bar/main/assets/live-tab-titles.png)
88
+
89
+ <sub>Real Ghostty tab bar: auto-synced tabs (`● agy-bar 开源状态栏`, `📊 agy-bar Token 热力图`) right next to an unmodified default `agy --dangerously-skip-per...` tab.</sub>
87
90
 
88
91
  > **Pro Tip — Auto-summarize tab titles on topic shifts (~10 tokens, zero extra API calls)**
89
92
  > Add this one line to your global `~/.gemini/antigravity-cli/AGENTS.md`:
package/README.zh-CN.md CHANGED
@@ -14,6 +14,10 @@
14
14
 
15
15
  </div>
16
16
 
17
+ ![agy-bar Ghostty 终端真机实拍](https://raw.githubusercontent.com/xy-tuoren/agy-bar/main/assets/live-statusline.png)
18
+
19
+ <sub>Ghostty 真机实拍:10 并发子代理(`⚡10`)、实时代码增删(`+14.3K -803`)、免 TUN 本地代理(`PX 7897`)、1.01B 累计 Token、99% 缓存倒计时、TTFT/速率、本对话预估费用与 5h/7d 额度条。</sub>
20
+
17
21
  ![agy-bar 真彩渲染预览](https://raw.githubusercontent.com/xy-tuoren/agy-bar/main/assets/preview.svg)
18
22
 
19
23
  ```sh
@@ -34,7 +38,7 @@ CTX ▮▮▮▯▯▯▯▯ 42.6% (1.0M) │ CACHE 88%·3m42s │ TTFT 1.9s·15
34
38
 
35
39
  | 区域 | 显示内容 | 贴心细节 |
36
40
  | --- | --- | --- |
37
- | **第一行 · 左侧** | `~/code/agy-bar (main* +142 -38) · PX 7897` | 精简 `~` 路径(`dirStyle`)、当前改动实时增删行数(含已追踪修改与新建文本文件,3s 缓存)、本地代理端口徽章;仅在工作态按需亮起 `● 34s · esc`、并行子代理 `⚡2`、`PLAN`/`SANDBOX`、Vim `[NORMAL]` |
41
+ | **第一行 · 左侧** | `~/code/agy-bar (main* +142 -38) · PX 7897` | 精简 `~` 路径(`dirStyle`)、当前改动实时增删行数(含已追踪修改与新建文本文件,3s 缓存)、本地代理端口徽章;按需亮起状态徽章(等待确认/输入 `CONFIRM`/`INPUT`、报错 `ERR`、工作态 `● 34s · esc`、并行子代理 `SUB N`、后台任务 `TASK N`、`PLAN`/`SANDBOX`、Vim `[NORMAL]`) |
38
42
  | **第一行 · 右侧** | `DAY 136M/$13.2 · WK 810M · MO 875M · ALL 906M │ 模型` | 低饱和中性配色汇总今日/本周/本月/累计用量与今日费用 + 当前模型与思考强度;窄分屏自动分级退让 |
39
43
  | **第二行 · 左侧** | `CTX ▮▮▮▯▯▯▯▯ 42.6% (1.0M) │ CACHE 88%·3m42s │ TTFT 1.9s·158t/s │ ~$0.18` | 统一健康色上下文条(危急提示 `→/compact`)、5 分钟缓存保活倒计时、首字时间 + 纯解码速率、本对话预估费用(自动归集所有子代理与嵌套孙代理开销,子代理运行中每 20 秒准实时刷新) |
40
44
  | **第二行 · 右侧** | `5h ▮▮▮▮▮▯ 85% (2h30m) │ 7d ▮▮▮▮▯▯ 64% (3d)` | 自动匹配当前模型额度池(**Gemini 4 Neon / Carbon / Hydrogen / Argon** 与 **Claude 3p**)及重置倒计时 |
@@ -76,14 +80,13 @@ CTX ▮▮▮▯▯▯▯▯ 42.6% (1.0M) │ CACHE 88%·3m42s │ TTFT 1.9s·15
76
80
 
77
81
  ---
78
82
 
79
- ### 5. 终端标签页标题自动同步 (`●` / `✓`) 与 Agent 摘要 (`agy-bar title`)
83
+ ### 5. 终端标签页标题自动同步 (`●` / `● [N]` / `?` / `✓`) 与 Agent 摘要 (`agy-bar title`)
80
84
 
81
- 彻底告别多开时所有标签页都叫 `agy --dangerously-skip-permissions` 的烦恼:在 macOS / Linux / WSL 下的 Ghostty、iTerm2、Kitty、WezTerm、Terminal.app、VS Code 中通过标准 OSC 0/2 自动同步工作状态与会话标题(零额外 Token;原生 Windows 自动安全跳过):
85
+ 彻底告别多开时所有标签页都叫 `agy --dangerously-skip-permissions` 的烦恼:在 macOS / Linux / WSL 下的 Ghostty、iTerm2、Kitty、WezTerm、Terminal.app、VS Code 中通过标准 OSC 0/2 自动同步精确状态(`●` 工作中、`● [N]` 子代理运行中、`?` 等待你确认/输入、`✗` 报错、`✓` 全部完成)与精简主题(零额外 Token;原生 Windows 自动安全跳过):
82
86
 
83
- ```text
84
- 之前: agy --dangerously-skip-permissions │ agy --dangerously-skip-permissions │ agy --dangerously-skip-permissions
85
- 之后: ● 修复 Windows 兼容性 │ ✓ agy-bar (main*) │ ● 新增 52 周热力图统计
86
- ```
87
+ ![agy-bar Ghostty 标签页标题真机对比](https://raw.githubusercontent.com/xy-tuoren/agy-bar/main/assets/live-tab-titles.png)
88
+
89
+ <sub>Ghostty 标签栏真机对比:左侧已自动同步为 `● agy-bar 开源状态栏`、`📊 agy-bar Token 热力图`,右侧为未启用前的默认 `agy --dangerously-skip-per...`。</sub>
87
90
 
88
91
  > **进阶技巧 — 让 Agent 换话题时自动缩写标签名(仅耗 ~10 tokens,零额外 API 调用)**
89
92
  > 在你的全局 `~/.gemini/antigravity-cli/AGENTS.md` 里加上这一句即可:
package/bin/agy-bar.mjs CHANGED
@@ -455,6 +455,9 @@ export async function main(argv = process.argv.slice(2)) {
455
455
  const renderedTitle = buildTabTitle(
456
456
  {
457
457
  agent_state: updated.agentState,
458
+ subagents: updated.runningSubagents || 0,
459
+ task_count: updated.runningTasks || 0,
460
+ tool_confirmation_pending: Boolean(updated.toolConfirmationPending),
458
461
  conversation_title: updated.conversationTitle,
459
462
  cwd: updated.cwd,
460
463
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agy-bar",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "description": "Zero-dependency terminal statusline, no-TUN proxy launcher, exact TTFT & tok/s speed, 5-min cache TTL countdown, live pricing cache, automatic tab titles, 52-week token heatmap, and multi-CLI monitor for Antigravity CLI (agy).",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -8,7 +8,7 @@
8
8
  "homepage": "https://github.com/xy-tuoren/agy-bar",
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "https://github.com/xy-tuoren/agy-bar.git"
11
+ "url": "git+https://github.com/xy-tuoren/agy-bar.git"
12
12
  },
13
13
  "bugs": {
14
14
  "url": "https://github.com/xy-tuoren/agy-bar/issues"
@@ -34,7 +34,7 @@
34
34
  "node": ">=20.0.0"
35
35
  },
36
36
  "bin": {
37
- "agy-bar": "./bin/agy-bar.mjs"
37
+ "agy-bar": "bin/agy-bar.mjs"
38
38
  },
39
39
  "files": [
40
40
  "AGENTS.md",
@@ -0,0 +1,186 @@
1
+ const MAIN_BUSY_STATES = Object.freeze(new Set(['working', 'tool_use', 'thinking']));
2
+ const STARTUP_STATES = Object.freeze(new Set(['authenticating', 'initializing']));
3
+ const RUNNING_SUBAGENT_STATUSES = Object.freeze(new Set(['running', 'working', 'active', 'in_progress']));
4
+
5
+ function nonNegNumber(value) {
6
+ return typeof value === 'number' && Number.isFinite(value) && value >= 0 ? value : null;
7
+ }
8
+
9
+ export function countRunningSubagents(payload) {
10
+ const raw = payload?.subagents;
11
+ if (!raw) return 0;
12
+ if (typeof raw === 'number' && Number.isFinite(raw) && raw > 0) return Math.floor(raw);
13
+ if (Array.isArray(raw)) {
14
+ let count = 0;
15
+ for (const item of raw) {
16
+ if (!item || typeof item !== 'object') continue;
17
+ const st = String(item.status || item.state || '').trim().toLowerCase();
18
+ if (item.running === true || RUNNING_SUBAGENT_STATUSES.has(st)) {
19
+ count += 1;
20
+ }
21
+ }
22
+ return count;
23
+ }
24
+ if (typeof raw === 'object') {
25
+ const n = nonNegNumber(raw.running ?? raw.active);
26
+ return n !== null ? Math.floor(n) : 0;
27
+ }
28
+ return 0;
29
+ }
30
+
31
+ export function countRunningTasks(payload) {
32
+ const n = nonNegNumber(payload?.task_count);
33
+ return n !== null ? Math.floor(n) : 0;
34
+ }
35
+
36
+ export function isToolConfirmationPending(payload) {
37
+ return payload?.tool_confirmation_pending === true;
38
+ }
39
+
40
+ export function extractNativeCostUsd(payload) {
41
+ const n = nonNegNumber(payload?.cost?.total_usd);
42
+ return n !== null && n > 0 ? n : null;
43
+ }
44
+
45
+ /**
46
+ * Single source of truth for classifying Antigravity CLI session activity across
47
+ * tab titles, statusline badges, telemetry timers, and multi-CLI monitor.
48
+ *
49
+ * Official AGY agent_state values:
50
+ * idle | working | tool_use | reviewing | authenticating | initializing | error
51
+ * Plus auxiliary live signals:
52
+ * tool_confirmation_pending, subagents[].status === 'running', task_count > 0
53
+ */
54
+ export function classifyAgentActivity(payload = {}) {
55
+ const raw = typeof payload?.agent_state === 'string' ? payload.agent_state.trim().toLowerCase() : '';
56
+ const rawState = raw || 'idle';
57
+ const runningSubagents = countRunningSubagents(payload);
58
+ const runningTasks = countRunningTasks(payload);
59
+ const confirmPending = isToolConfirmationPending(payload);
60
+
61
+ if (confirmPending) {
62
+ return Object.freeze({
63
+ kind: 'confirm',
64
+ rawState,
65
+ needsAttention: true,
66
+ isMainBusy: false,
67
+ isActive: true,
68
+ runningSubagents,
69
+ runningTasks,
70
+ confirmPending: true,
71
+ tabPrefix: '? ',
72
+ statusBadge: 'CONFIRM',
73
+ monitorLabel: 'confirm',
74
+ });
75
+ }
76
+
77
+ if (rawState === 'reviewing') {
78
+ return Object.freeze({
79
+ kind: 'input',
80
+ rawState,
81
+ needsAttention: true,
82
+ isMainBusy: false,
83
+ isActive: true,
84
+ runningSubagents,
85
+ runningTasks,
86
+ confirmPending: false,
87
+ tabPrefix: '? ',
88
+ statusBadge: 'INPUT',
89
+ monitorLabel: 'input',
90
+ });
91
+ }
92
+
93
+ if (rawState === 'error') {
94
+ return Object.freeze({
95
+ kind: 'error',
96
+ rawState,
97
+ needsAttention: true,
98
+ isMainBusy: false,
99
+ isActive: false,
100
+ runningSubagents,
101
+ runningTasks,
102
+ confirmPending: false,
103
+ tabPrefix: '✗ ',
104
+ statusBadge: 'ERR',
105
+ monitorLabel: 'error',
106
+ });
107
+ }
108
+
109
+ if (MAIN_BUSY_STATES.has(rawState)) {
110
+ return Object.freeze({
111
+ kind: 'working',
112
+ rawState,
113
+ needsAttention: false,
114
+ isMainBusy: true,
115
+ isActive: true,
116
+ runningSubagents,
117
+ runningTasks,
118
+ confirmPending: false,
119
+ tabPrefix: '● ',
120
+ statusBadge: null,
121
+ monitorLabel: rawState,
122
+ });
123
+ }
124
+
125
+ if (runningSubagents > 0) {
126
+ return Object.freeze({
127
+ kind: 'subagents',
128
+ rawState,
129
+ needsAttention: false,
130
+ isMainBusy: false,
131
+ isActive: true,
132
+ runningSubagents,
133
+ runningTasks,
134
+ confirmPending: false,
135
+ tabPrefix: `● [${runningSubagents}] `,
136
+ statusBadge: null,
137
+ monitorLabel: `sub:${runningSubagents}`,
138
+ });
139
+ }
140
+
141
+ if (runningTasks > 0) {
142
+ return Object.freeze({
143
+ kind: 'tasks',
144
+ rawState,
145
+ needsAttention: false,
146
+ isMainBusy: false,
147
+ isActive: true,
148
+ runningSubagents,
149
+ runningTasks,
150
+ confirmPending: false,
151
+ tabPrefix: '● ',
152
+ statusBadge: null,
153
+ monitorLabel: `task:${runningTasks}`,
154
+ });
155
+ }
156
+
157
+ if (STARTUP_STATES.has(rawState)) {
158
+ return Object.freeze({
159
+ kind: 'startup',
160
+ rawState,
161
+ needsAttention: false,
162
+ isMainBusy: false,
163
+ isActive: true,
164
+ runningSubagents,
165
+ runningTasks,
166
+ confirmPending: false,
167
+ tabPrefix: '… ',
168
+ statusBadge: null,
169
+ monitorLabel: rawState === 'authenticating' ? 'auth' : 'init',
170
+ });
171
+ }
172
+
173
+ return Object.freeze({
174
+ kind: 'idle',
175
+ rawState,
176
+ needsAttention: false,
177
+ isMainBusy: false,
178
+ isActive: false,
179
+ runningSubagents,
180
+ runningTasks,
181
+ confirmPending: false,
182
+ tabPrefix: '✓ ',
183
+ statusBadge: null,
184
+ monitorLabel: 'idle',
185
+ });
186
+ }
package/src/monitor.mjs CHANGED
@@ -48,6 +48,64 @@ function padLeft(text, len) {
48
48
  return w >= len ? s : ' '.repeat(len - w) + s;
49
49
  }
50
50
 
51
+ function describeMonitorState(session, p, useColor) {
52
+ const kind = session.activityKind || (session.isBusy ? 'working' : 'idle');
53
+ if (kind === 'confirm' || kind === 'input') {
54
+ return {
55
+ dot: bold(fg('?', p.warn, useColor), useColor),
56
+ label: kind,
57
+ tone: p.warn,
58
+ strong: true,
59
+ };
60
+ }
61
+ if (kind === 'error') {
62
+ return {
63
+ dot: bold(fg('✗', p.danger, useColor), useColor),
64
+ label: 'error',
65
+ tone: p.danger,
66
+ strong: true,
67
+ };
68
+ }
69
+ if (kind === 'subagents') {
70
+ return {
71
+ dot: fg('●', p.accent, useColor),
72
+ label: `sub:${session.runningSubagents || 1}`,
73
+ tone: p.accent,
74
+ strong: false,
75
+ };
76
+ }
77
+ if (kind === 'tasks') {
78
+ return {
79
+ dot: fg('●', p.accent, useColor),
80
+ label: `task:${session.runningTasks || 1}`,
81
+ tone: p.accent,
82
+ strong: false,
83
+ };
84
+ }
85
+ if (kind === 'startup') {
86
+ return {
87
+ dot: fg('…', p.muted, useColor),
88
+ label: session.agentState === 'authenticating' ? 'auth' : 'init',
89
+ tone: p.muted,
90
+ strong: false,
91
+ };
92
+ }
93
+ if (kind === 'working') {
94
+ return {
95
+ dot: fg('●', p.warn, useColor),
96
+ label: session.agentState || 'working',
97
+ tone: p.warn,
98
+ strong: false,
99
+ };
100
+ }
101
+ return {
102
+ dot: session.ageMs <= 5 * 60 * 1000 ? fg('●', p.good, useColor) : fg('○', p.muted, useColor),
103
+ label: session.agentState || 'idle',
104
+ tone: p.text,
105
+ strong: false,
106
+ };
107
+ }
108
+
51
109
  export function renderMonitorFrame(
52
110
  sessions,
53
111
  { now = Date.now(), config = loadConfig(), color = true, env = process.env, columns = process.stdout.columns || 98 } = {},
@@ -60,9 +118,11 @@ export function renderMonitorFrame(
60
118
  const ruleWidth = Math.min(104, Math.max(76, columns || 98));
61
119
 
62
120
  const activeCount = sessions.filter((s) => s.ageMs <= 5 * 60 * 1000).length;
121
+ const waitingCount = sessions.filter((s) => s.activityKind === 'confirm' || s.activityKind === 'input').length;
122
+ const waitSuffix = waitingCount > 0 ? ` · ${waitingCount} waiting` : '';
63
123
  lines.push(
64
124
  bold(fg('agy-bar monitor', p.accent, useColor), useColor) +
65
- fg(` · ${sessions.length} recent CLI session${sessions.length === 1 ? '' : 's'} (${activeCount} active) · Ctrl+C to quit`, p.muted, useColor),
125
+ fg(` · ${sessions.length} recent CLI session${sessions.length === 1 ? '' : 's'} (${activeCount} active${waitSuffix}) · Ctrl+C to quit`, p.muted, useColor),
66
126
  );
67
127
  lines.push(fg('─'.repeat(ruleWidth), p.sep, useColor));
68
128
 
@@ -101,8 +161,9 @@ export function renderMonitorFrame(
101
161
  const healthyCtxColor = config.colorMode === 'distinct' ? p.accent : p.good;
102
162
 
103
163
  for (const s of sessions) {
104
- const dot = s.isBusy ? fg('●', p.warn, useColor) : s.ageMs <= 5 * 60 * 1000 ? fg('●', p.good, useColor) : fg('○', p.muted, useColor);
105
- const stateLabel = padRight(s.agentState || 'idle', 8);
164
+ const state = describeMonitorState(s, p, useColor);
165
+ const stateLabel = padRight(state.label, 8);
166
+ const styledState = state.strong ? bold(fg(stateLabel, state.tone, useColor), useColor) : fg(stateLabel, state.tone, useColor);
106
167
  const ws = s.workspaceName || s.sessionId.slice(0, 10);
107
168
  const branchPart = s.branch ? `:${s.branch}${s.dirty ? '*' : ''}` : '';
108
169
  const wsCell = padRight(`${ws}${branchPart}`, 22);
@@ -128,7 +189,7 @@ export function renderMonitorFrame(
128
189
  const costCell = padLeft(typeof s.sessionCostUsd === 'number' && s.sessionCostUsd > 0 ? formatUsd(s.sessionCostUsd) : '--', 7);
129
190
 
130
191
  lines.push(
131
- `${dot} ${fg(stateLabel, s.isBusy ? p.warn : p.text, useColor)} ` +
192
+ `${state.dot} ${styledState} ` +
132
193
  `${fg(wsCell, p.branch, useColor)} ` +
133
194
  `${fg(modelCell, p.text, useColor)} ` +
134
195
  `${ctxBar} ${fg(ctxText, ctxTone, useColor)} ` +
package/src/render.mjs CHANGED
@@ -1,9 +1,12 @@
1
1
  import { homedir } from 'node:os';
2
+ import { classifyAgentActivity, countRunningSubagents } from './agent-state.mjs';
2
3
  import { bold, clipAnsi, detectColorDepth, fg, sanitizeText, visibleWidth } from './ansi.mjs';
3
4
  import { BAR_STYLES, DEFAULT_CONFIG, normalizeConfig } from './config.mjs';
4
5
  import { formatUsd } from './pricing.mjs';
5
6
  import { resolvePalette } from './themes.mjs';
6
7
 
8
+ export { countRunningSubagents };
9
+
7
10
  const KNOWN_BUCKETS = Object.freeze({
8
11
  'gemini-5h': Object.freeze({ group: 'Gemini', kind: '5h', label: '5h' }),
9
12
  'gemini-weekly': Object.freeze({ group: 'Gemini', kind: 'weekly', label: '7d' }),
@@ -233,28 +236,6 @@ export function extractActiveProxyLabel(env = {}) {
233
236
  }
234
237
  }
235
238
 
236
- export function countRunningSubagents(payload) {
237
- const raw = payload?.subagents;
238
- if (!raw) return 0;
239
- if (typeof raw === 'number' && Number.isFinite(raw) && raw > 0) return Math.floor(raw);
240
- if (Array.isArray(raw)) {
241
- let count = 0;
242
- for (const item of raw) {
243
- if (!item || typeof item !== 'object') continue;
244
- const st = String(item.status || item.state || '').toLowerCase();
245
- if (item.running === true || st === 'running' || st === 'working' || st === 'active' || st === 'in_progress') {
246
- count += 1;
247
- }
248
- }
249
- return count;
250
- }
251
- if (typeof raw === 'object') {
252
- const n = nonNegNumber(raw.running ?? raw.active);
253
- return n !== null ? Math.floor(n) : 0;
254
- }
255
- return 0;
256
- }
257
-
258
239
  export function formatTurnElapsed(seconds) {
259
240
  const sec = nonNegNumber(seconds);
260
241
  if (sec === null || sec < 1) return '';
@@ -282,11 +263,20 @@ function formatModeBadges(payload, show, palette, color) {
282
263
  return joinWithSep(badges, ' · ', palette, color);
283
264
  }
284
265
 
285
- function formatSubagentsBadge(payload, show, palette, color) {
286
- if (!show.subagents) return '';
287
- const running = countRunningSubagents(payload);
288
- if (running <= 0) return '';
289
- return bold(fg(`⚡${running}`, palette.accent, color), color);
266
+ function formatAttentionBadge(activity, show, palette, color) {
267
+ if (!activity.statusBadge || (!show.mode && !show.hint)) return '';
268
+ const tone = activity.kind === 'error' ? palette.danger : palette.warn;
269
+ return bold(fg(activity.statusBadge, tone, color), color);
270
+ }
271
+
272
+ function formatSubagentsBadge(activity, show, palette, color) {
273
+ if (!show.subagents || activity.runningSubagents <= 0) return '';
274
+ return `${fg('SUB', palette.muted, color)} ${bold(fg(String(activity.runningSubagents), palette.accent, color), color)}`;
275
+ }
276
+
277
+ function formatTasksBadge(activity, show, palette, color) {
278
+ if (!show.subagents || activity.runningTasks <= 0) return '';
279
+ return `${fg('TASK', palette.muted, color)} ${fg(String(activity.runningTasks), palette.accent, color)}`;
290
280
  }
291
281
 
292
282
  function formatBusySegment(isBusy, telemetry, show, palette, color) {
@@ -460,11 +450,13 @@ function formatUsageSummarySegment(
460
450
 
461
451
  function renderMetaLine(payload, width, config, palette, color, git, usageSummary = null, telemetry = null, env = {}, home = homedir()) {
462
452
  const { show, dirStyle } = config;
463
- const isBusy = ['working', 'tool_use', 'thinking'].includes(payload?.agent_state);
453
+ const activity = classifyAgentActivity(payload);
464
454
  const vimBadge = formatVimBadge(payload, show, palette, color);
455
+ const attentionBadge = formatAttentionBadge(activity, show, palette, color);
465
456
  const modeBadge = formatModeBadges(payload, show, palette, color);
466
- const subagentsBadge = formatSubagentsBadge(payload, show, palette, color);
467
- const busySeg = formatBusySegment(isBusy, telemetry, show, palette, color);
457
+ const subagentsBadge = formatSubagentsBadge(activity, show, palette, color);
458
+ const tasksBadge = formatTasksBadge(activity, show, palette, color);
459
+ const busySeg = formatBusySegment(activity.isMainBusy, telemetry, show, palette, color);
468
460
  const proxyBadge = formatProxyBadge(env, show, palette, color);
469
461
  const modelText = show.model ? formatModelName(payload?.model, show.effort) : '';
470
462
  const modelSeg = modelText ? fg(modelText, palette.muted, color) : '';
@@ -513,12 +505,12 @@ function renderMetaLine(payload, width, config, palette, color, git, usageSummar
513
505
  home,
514
506
  });
515
507
 
516
- const leftFull = joinWithSep([vimBadge, modeBadge, subagentsBadge, busySeg, wsFull, proxyBadge], ' · ', palette, color);
517
- const leftNoDiff = joinWithSep([vimBadge, modeBadge, subagentsBadge, busySeg, wsNoDiff, proxyBadge], ' · ', palette, color);
518
- const leftShort = joinWithSep([vimBadge, modeBadge, subagentsBadge, busySeg, wsShort, proxyBadge], ' · ', palette, color);
519
- const leftNoProxy = joinWithSep([vimBadge, modeBadge, subagentsBadge, busySeg, wsShort], ' · ', palette, color);
520
- const leftCompact = joinWithSep([vimBadge, modeBadge, subagentsBadge, busySeg, wsShort || gitOnly], ' · ', palette, color);
521
- const leftMinimal = vimBadge || modeBadge || subagentsBadge || busySeg || gitOnly;
508
+ const leftFull = joinWithSep([vimBadge, attentionBadge, modeBadge, subagentsBadge, tasksBadge, busySeg, wsFull, proxyBadge], ' · ', palette, color);
509
+ const leftNoDiff = joinWithSep([vimBadge, attentionBadge, modeBadge, subagentsBadge, tasksBadge, busySeg, wsNoDiff, proxyBadge], ' · ', palette, color);
510
+ const leftShort = joinWithSep([vimBadge, attentionBadge, modeBadge, subagentsBadge, tasksBadge, busySeg, wsShort, proxyBadge], ' · ', palette, color);
511
+ const leftNoProxy = joinWithSep([vimBadge, attentionBadge, modeBadge, subagentsBadge, tasksBadge, busySeg, wsShort], ' · ', palette, color);
512
+ const leftCompact = joinWithSep([vimBadge, attentionBadge, modeBadge, subagentsBadge, busySeg, wsShort || gitOnly], ' · ', palette, color);
513
+ const leftMinimal = attentionBadge || vimBadge || modeBadge || subagentsBadge || busySeg || gitOnly;
522
514
 
523
515
  const pairs = [
524
516
  [leftFull, rightFull],
@@ -1,11 +1,12 @@
1
1
  import { realpathSync } from 'node:fs';
2
2
  import { resolve } from 'node:path';
3
3
  import { fileURLToPath } from 'node:url';
4
+ import { classifyAgentActivity, extractNativeCostUsd } from './agent-state.mjs';
4
5
  import { loadConfig } from './config.mjs';
5
6
  import { readGitInfo } from './git.mjs';
6
7
  import { getOrRefreshUsageSummary } from './history-scan.mjs';
7
8
  import { maybeTriggerBackgroundPricingSync } from './pricing-sync.mjs';
8
- import { countRunningSubagents, renderFallback, renderStatusline } from './render.mjs';
9
+ import { renderFallback, renderStatusline } from './render.mjs';
9
10
  import { readLatestStepTiming } from './step-timing.mjs';
10
11
  import { syncTabTitle } from './tab-title.mjs';
11
12
  import { maybeCaptureRedactedPayload, peekSessionState, recordTelemetry, updateSessionTabTitle } from './telemetry.mjs';
@@ -61,6 +62,7 @@ export async function runStatusline({ stdin = process.stdin, stdout = process.st
61
62
  enableLedger: config.ledger,
62
63
  });
63
64
 
65
+ const activity = classifyAgentActivity(payload);
64
66
  let usageSummary = null;
65
67
  if (
66
68
  config.show.todayTokens ||
@@ -75,12 +77,13 @@ export async function runStatusline({ stdin = process.stdin, stdout = process.st
75
77
  sessionId: telemetry.sessionId,
76
78
  deltaTokens: telemetry.turnTokensDelta || 0,
77
79
  deltaCostUsd: telemetry.turnCostDeltaUsd || 0,
78
- hasRunningSubagents: countRunningSubagents(payload) > 0,
80
+ hasRunningSubagents: activity.runningSubagents > 0,
79
81
  allowScan: config.dbTiming,
80
82
  });
81
83
  }
82
84
 
83
- const effectiveSessionCostUsd = Math.max(telemetry.sessionCostUsd || 0, usageSummary?.sessionCostUsd || 0);
85
+ const nativeCostUsd = extractNativeCostUsd(payload);
86
+ const effectiveSessionCostUsd = Math.max(telemetry.sessionCostUsd || 0, usageSummary?.sessionCostUsd || 0, nativeCostUsd || 0);
84
87
  const effectiveTelemetry =
85
88
  effectiveSessionCostUsd !== telemetry.sessionCostUsd
86
89
  ? { ...telemetry, sessionCostUsd: effectiveSessionCostUsd }
package/src/tab-title.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import { execFileSync } from 'node:child_process';
2
2
  import { accessSync, closeSync, constants, openSync, writeSync } from 'node:fs';
3
3
  import { basename } from 'node:path';
4
+ import { classifyAgentActivity } from './agent-state.mjs';
4
5
  import { clipPlain, sanitizeText, visibleWidth } from './ansi.mjs';
5
6
 
6
7
  const VALID_TTY_RE = /^(?:tty[a-z0-9]+|pts\/\d+)$/i;
@@ -41,8 +42,8 @@ export function buildTabTitle(
41
42
  ) {
42
43
  const source = config.tabTitleSource || 'auto';
43
44
  const maxCols = config.tabTitleMaxLen || 26;
44
- const isBusy = ['working', 'tool_use', 'thinking'].includes(payload?.agent_state);
45
- const prefix = isBusy ? '● ' : '✓ ';
45
+ const activity = classifyAgentActivity(payload);
46
+ const prefix = activity.tabPrefix;
46
47
 
47
48
  const rawCwd = payload?.workspace?.current_dir || payload?.cwd || '';
48
49
  const dirName = rawCwd ? sanitizeText(basename(rawCwd)) : '';
package/src/telemetry.mjs CHANGED
@@ -2,13 +2,12 @@ import { createHash } from 'node:crypto';
2
2
  import { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
3
3
  import { homedir } from 'node:os';
4
4
  import { basename, join } from 'node:path';
5
+ import { classifyAgentActivity } from './agent-state.mjs';
5
6
  import { sanitizeText } from './ansi.mjs';
6
7
  import { configDir } from './config.mjs';
7
8
  import { writeFileAtomic } from './fs-atomic.mjs';
8
9
  import { estimateCost } from './pricing.mjs';
9
10
 
10
- const BUSY_STATES = new Set(['working', 'tool_use', 'thinking']);
11
-
12
11
  function nonNeg(value) {
13
12
  return typeof value === 'number' && Number.isFinite(value) && value >= 0 ? value : null;
14
13
  }
@@ -188,12 +187,13 @@ export function recordTelemetry(
188
187
  const curCacheRead = nonNeg(usage?.cache_read_input_tokens) ?? 0;
189
188
  const curCacheWrite = nonNeg(usage?.cache_creation_input_tokens) ?? 0;
190
189
 
191
- const isBusy = BUSY_STATES.has(p.agent_state);
192
- const wasBusy = Boolean(prev?.isBusy);
190
+ const activity = classifyAgentActivity(p);
191
+ const isMainBusy = activity.isMainBusy;
192
+ const wasMainBusy = Boolean(prev?.isMainBusy ?? (prev?.activityKind ? prev.activityKind === 'working' : prev?.isBusy));
193
193
 
194
194
  let turnStartedAt = prev?.turnStartedAt ?? null;
195
195
  let turnFirstTokenAt = prev?.turnFirstTokenAt ?? null;
196
- if (isBusy && (!wasBusy || turnStartedAt === null)) {
196
+ if (isMainBusy && (!wasMainBusy || turnStartedAt === null)) {
197
197
  turnStartedAt = now;
198
198
  turnFirstTokenAt = null;
199
199
  }
@@ -363,13 +363,13 @@ export function recordTelemetry(
363
363
  }
364
364
  }
365
365
 
366
- if (!isBusy) {
366
+ if (!isMainBusy) {
367
367
  turnStartedAt = null;
368
368
  turnFirstTokenAt = null;
369
369
  }
370
370
 
371
371
  const turnElapsedSec =
372
- isBusy && turnStartedAt !== null && now >= turnStartedAt ? Math.floor((now - turnStartedAt) / 1000) : null;
372
+ isMainBusy && turnStartedAt !== null && now >= turnStartedAt ? Math.floor((now - turnStartedAt) / 1000) : null;
373
373
 
374
374
  const cwd = p.workspace?.current_dir || p.cwd || prev?.cwd || null;
375
375
  const cacheTtlMs = Math.max(30, cacheTtlSec) * 1000;
@@ -399,7 +399,13 @@ export function recordTelemetry(
399
399
  gitCheckedAt: git?.dirtyChecked ? now : prev?.gitCheckedAt ?? null,
400
400
  dbStamp: stepTiming?.dbStamp ?? prev?.dbStamp ?? null,
401
401
  agentState: sanitizeText(p.agent_state || '') || 'idle',
402
- isBusy,
402
+ activityKind: activity.kind,
403
+ needsAttention: activity.needsAttention,
404
+ runningSubagents: activity.runningSubagents,
405
+ runningTasks: activity.runningTasks,
406
+ toolConfirmationPending: activity.confirmPending,
407
+ isMainBusy,
408
+ isBusy: activity.isActive,
403
409
  conversationTitle,
404
410
  customTitle,
405
411
  customTitleBase,