agy-bar 0.9.5 → 1.0.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/AGENTS.md CHANGED
@@ -7,7 +7,7 @@ If a user asks you to install **agy-bar** into their Antigravity CLI (`agy`), fo
7
7
  - If Node.js is missing or older than 20, stop and inform the user; do **not** install or upgrade Node.js automatically.
8
8
 
9
9
  2. **Choose installation method**
10
- - **Recommended (via npm, zero clone):** run `npx -y agy-bar install` (or `npx -y agy-bar install --proxy-hook` if the user wants the shell hook below) and verify with `agy-bar doctor`.
10
+ - **Recommended (via npm, zero clone):** run `npx -y agy-bar@latest install --yes` (or `npx -y agy-bar@latest install --proxy-hook` if the user wants the shell hook below) and verify with `agy-bar doctor`.
11
11
  - **Or from GitHub `main`:**
12
12
  - If you are already inside a clean `agy-bar` clone on `main` pointing to `xy-tuoren/agy-bar` with an empty `git status --porcelain`, run `git pull --ff-only origin main`.
13
13
  - Otherwise clone fresh into a clean directory (e.g. `~/agy-bar` on macOS/Linux/WSL or `%USERPROFILE%\agy-bar` on Windows):
@@ -17,15 +17,14 @@ If a user asks you to install **agy-bar** into their Antigravity CLI (`agy`), fo
17
17
 
18
18
  3. **Ask about the optional no-TUN proxy shell hook, then run the installer & self-check**
19
19
  - Before running `install`, briefly ask the user whether they also want `agy-bar` to add a 7-line managed `agy()` function to their shell rc (`~/.zshrc` / `~/.bashrc` / `config.fish`) so typing plain `agy` automatically uses their local proxy (Clash/Surge/v2ray) without TUN mode (removable anytime via `agy-bar proxy unhook` or `uninstall`).
20
- - If the user says **yes**, pass `--proxy-hook`; if **no** (or unsure), omit it so their shell rc stays completely untouched (they can still use `agy-bar run` anytime).
20
+ - If the user says **yes**, pass `--proxy-hook`; if **no** (or unsure), pass `--yes` (omitting `--proxy-hook`) so their shell rc stays completely untouched (they can still use `agy-bar run` anytime).
21
21
  ```sh
22
- cd ~/agy-bar
23
- node bin/agy-bar.mjs install # or: node bin/agy-bar.mjs install --proxy-hook
24
- node bin/agy-bar.mjs doctor
22
+ npx -y agy-bar@latest install --yes # or: npx -y agy-bar@latest install --proxy-hook
23
+ agy-bar doctor
25
24
  ```
26
25
  - Zero third-party dependencies: do **not** run `npm install`.
27
26
  - Non-interactive `install` leaves `~/.zshrc` untouched by default unless `--proxy-hook` is passed (or an existing managed hook is already present).
28
- - Installs the statusline runtime, global `~/.local/bin/agy-bar` command, and companion `/agy-bar` skill by default. Pass `--no-skill` only if the user explicitly opts out or if an unrelated `agy-bar` skill already exists (never overwrite unrelated skills).
27
+ - Installs the statusline runtime, official native AGY `title` hook (preserving any existing custom `settings.json.title`; pass `--no-title` to opt out), global `~/.local/bin/agy-bar` command, and companion `/agy-bar` skill by default. Pass `--no-skill` only if the user explicitly opts out or if an unrelated `agy-bar` skill already exists (never overwrite unrelated skills).
29
28
 
30
29
  4. **Strict safety boundaries**
31
30
  - Never modify `agy-bar` source files, Antigravity binaries, or unrelated fields in `~/.gemini/antigravity-cli/settings.json`.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,29 @@
2
2
 
3
3
  All notable changes to **agy-bar** are documented here.
4
4
 
5
+ ## [1.0.1] - 2026-11-27
6
+
7
+ ### Fixed & Improved
8
+ - **Automatic Summary Tab Titles on Brand-New Conversations (`src/step-timing.mjs`, `src/title.mjs`, `src/statusline.mjs`, `src/telemetry.mjs`, `bin/agy-bar.mjs`)**:
9
+ - When Antigravity CLI omits `conversation_title` from live `statusLine`/`title` JSON payloads on newly started sessions (even after AGY's background summarizer has already generated a title), `agy-bar` now falls back to reading only the current session's `title` column from local `~/.gemini/antigravity-cli/conversation_summaries.db` in `readOnly: true` mode (Node `>= 22.13`, zero chat text read, respects `dbTiming: false`).
10
+ - Uses `.db`/`.db-wal` `mtime` stamp caching plus a 15s recheck throttle once populated so idle and active hot paths remain near-zero overhead, emits a one-shot tab update if the initial summary lands after turn 1 goes idle, and anchors `customTitleBase` so early `agy-bar title` overrides are preserved while later `/rename` actions still supersede them cleanly.
11
+ - **Documentation (`README.md`, `README.zh-CN.md`)**:
12
+ - Updated the global rules path in the automatic topic-summarization tip to Antigravity's official global file `~/.gemini/AGENTS.md`.
13
+
14
+ ## [1.0.0] - 2026-11-27
15
+
16
+ First stable release of **agy-bar** — zero-dependency statusline HUD, native AGY window/tab title hook, no-TUN local proxy launcher, 52-week token heatmap, live 3-tier pricing cache, and multi-CLI monitor for Antigravity CLI (`agy`).
17
+
18
+ ### Added & Improved
19
+ - **Multi-Tab Custom Title Targeting (`bin/agy-bar.mjs`, `src/telemetry.mjs`, `src/title.mjs`)**:
20
+ - `agy-bar title` now matches the invoking terminal's host `agy` PID (across both `lastTabHostPid` and native `.title` markers) before falling back to most-recent session, preventing accidental cross-tab renames when multiple `agy` sessions run concurrently.
21
+ - `agy-bar title` inspection output now reports `nativeTitleActive` and always displays the live computed `activeTabTitle`.
22
+ - **CI Native Title Smoke Verification (`.github/workflows/ci.yml`)**:
23
+ - Added cross-platform `src/title.mjs` smoke verification to the 9-job macOS / Linux / Windows × Node 20 / 22 / 24 CI matrix.
24
+ - **v1.0.0 Documentation & Showcase Polish (`README.md`, `README.zh-CN.md`, `AGENTS.md`, `skills/agy-bar/SKILL.md`, `assets/monitor-preview.svg`)**:
25
+ - Updated `monitor-preview.svg` to showcase live multi-state tracking (`working`, `sub:3`, `? confirm`, `idle`).
26
+ - Aligned Windows native title documentation, test counts (`87` tests), `npx -y agy-bar@latest install` guidance, Ghostty title tips, and npm Provenance badge across English & Chinese READMEs.
27
+
5
28
  ## [0.9.5] - 2026-11-26
6
29
 
7
30
  ### Added
package/README.md CHANGED
@@ -8,6 +8,7 @@
8
8
 
9
9
  [![CI](https://github.com/xy-tuoren/agy-bar/actions/workflows/ci.yml/badge.svg)](https://github.com/xy-tuoren/agy-bar/actions/workflows/ci.yml)
10
10
  [![npm](https://img.shields.io/npm/v/agy-bar.svg)](https://www.npmjs.com/package/agy-bar)
11
+ [![Provenance](https://img.shields.io/badge/npm-provenance-brightgreen.svg)](https://www.npmjs.com/package/agy-bar)
11
12
  [![Node >= 20](https://img.shields.io/badge/node-%3E%3D20.0.0-brightgreen.svg)](https://nodejs.org/)
12
13
  [![Zero Dependencies](https://img.shields.io/badge/dependencies-0-blue.svg)](#)
13
14
  [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](./LICENSE)
@@ -16,13 +17,13 @@
16
17
 
17
18
  ![agy-bar live Ghostty terminal screenshot](https://raw.githubusercontent.com/xy-tuoren/agy-bar/main/assets/live-statusline.png)
18
19
 
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
+ <sub>Real Ghostty capture: 10 running subagents (displayed as `SUB 10` in v1.0+), 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
21
 
21
22
  ![agy-bar true-color statusline preview](https://raw.githubusercontent.com/xy-tuoren/agy-bar/main/assets/preview.svg)
22
23
 
23
24
  ```sh
24
25
  # Install in one command (Node.js >= 20, zero dependencies)
25
- npx agy-bar install
26
+ npx -y agy-bar@latest install
26
27
  ```
27
28
 
28
29
  ---
@@ -82,17 +83,18 @@ Running 3–5 `agy` sessions across different repos? Open `agy-bar monitor` in a
82
83
 
83
84
  ### 5. Automatic Terminal Tab Titles (`●` / `● [N]` / `?` / `✓`) & Agent Summarization (`agy-bar title`)
84
85
 
85
- Replaces identical `agy --dangerously-skip-permissions` tabs across Ghostty, iTerm2, Kitty, WezTerm, macOS Terminal, Windows Terminal, and VS Code using **Antigravity CLI's official `title` hook** (`settings.json` → `title`, with automatic OSC 0/2 fallback for older sessions) to show live activity state (`●` working, `● [N]` running subagents, `?` waiting for user input/confirmation, `✗` error, `✓` truly idle) + concise topic title (zero extra tokens, full macOS / Linux / Windows support):
86
+ Replaces identical `agy --dangerously-skip-permissions` tabs across Ghostty, iTerm2, Kitty, WezTerm, macOS Terminal, Windows Terminal, and VS Code using **Antigravity CLI's official `title` hook** (`settings.json` → `title`, with automatic OSC 0/2 fallback for older sessions) to show live activity state (`●` working, `● [N]` running subagents, `?` waiting for user input/confirmation, `✗` error, `✓` truly idle) + concise topic title (automatically picking up AGY's generated summary title even on brand-new conversations, zero extra tokens, full macOS / Linux / Windows support):
86
87
 
87
88
  ![agy-bar live Ghostty tab titles comparison](https://raw.githubusercontent.com/xy-tuoren/agy-bar/main/assets/live-tab-titles.png)
88
89
 
89
90
  <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>
90
91
 
91
92
  > **Pro Tip — Auto-summarize tab titles on topic shifts (~10 tokens, zero extra API calls)**
92
- > Add this one line to your global `~/.gemini/antigravity-cli/AGENTS.md`:
93
+ > Add this one line to your global `~/.gemini/AGENTS.md`:
93
94
  > ```text
94
- > When the user starts a clearly new task/topic in a long session, silently run `agy-bar title "<4-8 word concise topic>"` once to keep the terminal tab title up to date.
95
+ > In Antigravity CLI (`agy`) sessions, when starting a clear task or switching to a new topic in a long session, silently run `agy-bar title "<4-8 word concise topic>"` once to keep the terminal tab title up to date.
95
96
  > ```
97
+ > *Ghostty tip*: prefer `agy-bar title "..."` over right-clicking **Change Title…** in Ghostty, which sets a manual `tabOverride` and blocks dynamic `●` / `✓` updates until cleared.
96
98
 
97
99
  ---
98
100
 
@@ -101,7 +103,7 @@ Replaces identical `agy --dangerously-skip-permissions` tabs across Ghostty, iTe
101
103
  | Guarantee | How It Works |
102
104
  | --- | --- |
103
105
  | **100% Official `statusLine` + `title` Hooks** | Zero binary patching, zero Electron injection, zero Google/AGY private API calls, zero account credential access. Survives every AGY update cleanly. |
104
- | **Read-Only Local Telemetry** | SQLite conversation scans (`Node >= 22.13`) open DBs in `readOnly: true` mode and extract **only numeric timestamps & token counts** — never prompts or replies. |
106
+ | **Read-Only Local Telemetry** | SQLite scans (`Node >= 22.13`) open local AGY DBs in `readOnly: true` mode and extract **only numeric timestamps, token counts, subagent parent IDs, and the session's own `title` metadata** — never prompts or replies. |
105
107
  | **Transparent Network Policy** | Statusline rendering itself **never touches the network**. Only an optional 24-hour background sync fetches public unauthenticated pricing JSON (`models.dev` / `LiteLLM`); run `agy-bar config set pricingAutoSync off` for strict offline mode. |
106
108
  | **Zero-Dep Fast Hot Path** | `0` runtime dependencies, zero-subprocess idle refreshes (PID fast-path + 3s Git cache + SQLite `mtime` skip + 5-min Windows theme cache), and atomic file writes across concurrent terminals. |
107
109
 
@@ -114,7 +116,7 @@ Requires **Node.js >= 20.0.0** and **Antigravity CLI (`agy`)**.
114
116
  ### Option 1: Via `npx` (Fastest)
115
117
 
116
118
  ```sh
117
- npx agy-bar install
119
+ npx -y agy-bar@latest install
118
120
  ```
119
121
 
120
122
  ### Option 2: Let `agy` install it for you
@@ -133,7 +135,7 @@ cd ~/agy-bar
133
135
  node bin/agy-bar.mjs install
134
136
  ```
135
137
 
136
- Then **restart `agy`** to activate the statusline (in an existing session, run `/skills reload` to load `/agy-bar`). `install` also places the global `agy-bar` command at `~/.local/bin/agy-bar` and safely backs up your previous `statusLine`. Pass `--no-skill` to skip installing the companion `/agy-bar` skill.
138
+ Then **restart `agy`** to activate the statusline and native `title` hook (in an existing session, run `/skills reload` to load `/agy-bar`). `install` places the global `agy-bar` command at `~/.local/bin/agy-bar`, safely backs up your previous `statusLine` / `title` settings (never overwriting unrelated custom `title` scripts), and leaves `~/.zshrc` untouched unless you opt into the proxy hook. Pass `--no-skill` or `--no-title` to opt out of either component.
137
139
 
138
140
  ---
139
141
 
@@ -202,18 +204,18 @@ agy-bar config reset
202
204
 
203
205
  - **Truecolor & 256-Color Auto-Adaptation**: Emits 24-bit Truecolor in Ghostty, iTerm2, Kitty, WezTerm, Alacritty, Warp, VS Code, and Windows Terminal; automatically downscales to nearest xterm-256 colors in macOS `Terminal.app` (`Apple_Terminal`) and `tmux` / `screen` / SSH without `COLORTERM=truecolor`; honors `NO_COLOR` and `TERM=dumb`.
204
206
  - **Light & Dark Themes**: Automatically adapts both statusline palettes and `agy-bar stats` heatmap ramps for light and dark backgrounds.
205
- - **Windows Notes**: Supported on Windows Terminal, PowerShell 7 (`pwsh`), Windows PowerShell 5.1, and `cmd.exe` (including `.cmd` shims, Windows system proxy detection, and 5-min cached dark/light theme detection). Automatic OSC tab title sync is macOS/Linux/WSL only and is safely skipped on native Windows. On older ConHost fonts missing `▮`, switch with `agy-bar config bar-style squares` or `blocks`.
207
+ - **Windows Notes**: Supported on Windows Terminal, PowerShell 7 (`pwsh`), Windows PowerShell 5.1, and `cmd.exe` (including `.cmd` shims, native AGY `title` hook for Windows Terminal tabs, Windows system proxy detection, and 5-min cached dark/light theme detection; only the legacy OSC `/dev/tty` fallback is POSIX-only). On older ConHost fonts missing `▮`, switch with `agy-bar config bar-style squares` or `blocks`.
206
208
 
207
209
  ---
208
210
 
209
211
  ## Update & Uninstall
210
212
 
211
213
  ```sh
212
- # Update (preserves config, ledger, pricing cache & original statusLine backup)
213
- npx agy-bar@latest install
214
+ # Update (preserves config, ledger, pricing cache & original statusLine/title backup)
215
+ npx -y agy-bar@latest install
214
216
 
215
- # Uninstall & restore previous statusLine + remove managed shell hook cleanly
216
- npx agy-bar uninstall # or: agy-bar uninstall
217
+ # Uninstall & restore previous statusLine/title + remove managed shell hook cleanly
218
+ npx -y agy-bar@latest uninstall # or: agy-bar uninstall
217
219
 
218
220
  # Complete cleanup including current terminal's proxy env vars & agy() function (zsh/bash):
219
221
  eval "$(agy-bar uninstall --remove-skill --purge --print-cleanup)"
@@ -224,7 +226,7 @@ eval "$(agy-bar uninstall --remove-skill --purge --print-cleanup)"
224
226
  ## Development
225
227
 
226
228
  ```sh
227
- npm test # Cross-platform Node.js built-in test suite (75 tests)
229
+ npm test # Cross-platform Node.js built-in test suite (88 tests)
228
230
  npm run preview # Render live terminal preview
229
231
  npm run preview:svg # Regenerate all 5 showcase SVGs in assets/
230
232
  npm run stats # Show local usage stats
package/README.zh-CN.md CHANGED
@@ -8,6 +8,7 @@
8
8
 
9
9
  [![CI](https://github.com/xy-tuoren/agy-bar/actions/workflows/ci.yml/badge.svg)](https://github.com/xy-tuoren/agy-bar/actions/workflows/ci.yml)
10
10
  [![npm](https://img.shields.io/npm/v/agy-bar.svg)](https://www.npmjs.com/package/agy-bar)
11
+ [![Provenance](https://img.shields.io/badge/npm-provenance-brightgreen.svg)](https://www.npmjs.com/package/agy-bar)
11
12
  [![Node >= 20](https://img.shields.io/badge/node-%3E%3D20.0.0-brightgreen.svg)](https://nodejs.org/)
12
13
  [![Zero Dependencies](https://img.shields.io/badge/dependencies-0-blue.svg)](#)
13
14
  [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](./LICENSE)
@@ -16,13 +17,13 @@
16
17
 
17
18
  ![agy-bar Ghostty 终端真机实拍](https://raw.githubusercontent.com/xy-tuoren/agy-bar/main/assets/live-statusline.png)
18
19
 
19
- <sub>Ghostty 真机实拍:10 并发子代理(`⚡10`)、实时代码增删(`+14.3K -803`)、免 TUN 本地代理(`PX 7897`)、1.01B 累计 Token、99% 缓存倒计时、TTFT/速率、本对话预估费用与 5h/7d 额度条。</sub>
20
+ <sub>Ghostty 真机实拍:10 并发子代理(`v1.0+` 已统一显示为 `SUB 10`)、实时代码增删(`+14.3K -803`)、免 TUN 本地代理(`PX 7897`)、1.01B 累计 Token、99% 缓存倒计时、TTFT/速率、本对话预估费用与 5h/7d 额度条。</sub>
20
21
 
21
22
  ![agy-bar 真彩渲染预览](https://raw.githubusercontent.com/xy-tuoren/agy-bar/main/assets/preview.svg)
22
23
 
23
24
  ```sh
24
25
  # 一行命令安装(需 Node.js >= 20,零第三方依赖)
25
- npx agy-bar install
26
+ npx -y agy-bar@latest install
26
27
  ```
27
28
 
28
29
  ---
@@ -82,17 +83,18 @@ CTX ▮▮▮▯▯▯▯▯ 42.6% (1.0M) │ CACHE 88%·3m42s │ TTFT 1.9s·15
82
83
 
83
84
  ### 5. 终端标签页标题自动同步 (`●` / `● [N]` / `?` / `✓`) 与 Agent 摘要 (`agy-bar title`)
84
85
 
85
- 彻底告别多开时所有标签页都叫 `agy --dangerously-skip-permissions` 的烦恼:接入 **Antigravity CLI 官方原生 `title` 接口**(`settings.json` → `title`,旧会话自动回退 OSC 0/2),在 macOS / Linux / 原生 Windows Terminal 下的 Ghostty、iTerm2、Kitty、WezTerm、Terminal.app、VS Code 中稳定同步精确状态(`●` 工作中、`● [N]` 子代理运行中、`?` 等待你确认/输入、`✗` 报错、`✓` 全部完成)与精简主题(零额外 Token、无字节交错):
86
+ 彻底告别多开时所有标签页都叫 `agy --dangerously-skip-permissions` 的烦恼:接入 **Antigravity CLI 官方原生 `title` 接口**(`settings.json` → `title`,旧会话自动回退 OSC 0/2),在 macOS / Linux / 原生 Windows Terminal 下的 Ghostty、iTerm2、Kitty、WezTerm、Terminal.app、VS Code 中稳定同步精确状态(`●` 工作中、`● [N]` 子代理运行中、`?` 等待你确认/输入、`✗` 报错、`✓` 全部完成)与精简主题(新开对话亦会自动同步 AGY 首轮概括标题,零额外 Token、无字节交错):
86
87
 
87
88
  ![agy-bar Ghostty 标签页标题真机对比](https://raw.githubusercontent.com/xy-tuoren/agy-bar/main/assets/live-tab-titles.png)
88
89
 
89
90
  <sub>Ghostty 标签栏真机对比:左侧已自动同步为 `● agy-bar 开源状态栏`、`📊 agy-bar Token 热力图`,右侧为未启用前的默认 `agy --dangerously-skip-per...`。</sub>
90
91
 
91
92
  > **进阶技巧 — 让 Agent 换话题时自动缩写标签名(仅耗 ~10 tokens,零额外 API 调用)**
92
- > 在你的全局 `~/.gemini/antigravity-cli/AGENTS.md` 里加上这一句即可:
93
+ > 在你的全局 `~/.gemini/AGENTS.md` 里加上这一句即可:
93
94
  > ```text
94
- > 当用户在长对话中明显切换到新任务或新话题时,静默执行一次 `agy-bar title "<4~8字中文简短主题>"` 更新终端标签页标题。
95
+ > 在 Antigravity CLI (`agy`) 终端会话中,当用户发起明确的新任务或在长对话中切换到新话题时,静默执行一次 `agy-bar title "<4~8字中文简短主题>"` 更新终端标签页标题。
95
96
  > ```
97
+ > *Ghostty 小贴士*:自定义标签名请优先使用 `agy-bar title "..."`,不要用 Ghostty 右键 **Change Title…**(会写入 `tabOverride` 锁死标签并屏蔽后续 `●` / `✓` 自动更新,清空留空回车即可解锁)。
96
98
 
97
99
  ---
98
100
 
@@ -101,7 +103,7 @@ CTX ▮▮▮▯▯▯▯▯ 42.6% (1.0M) │ CACHE 88%·3m42s │ TTFT 1.9s·15
101
103
  | 承诺 | 实现机制 |
102
104
  | --- | --- |
103
105
  | **100% 官方原生 `statusLine` + `title` 接口** | 不修改/不注入任何客户端二进制,不调用任何 Google/AGY 私有接口,不接触账号凭据;官方任意升级不失效、零封号风险。 |
104
- | **只读本地数值遥测** | SQLite 历史扫描(`Node >= 22.13`)全程 `readOnly: true`,**仅提取数值时间戳与 Token 计数**,绝不读取聊天正文。 |
106
+ | **只读本地元数据遥测** | SQLite 扫描(`Node >= 22.13`)全程 `readOnly: true`,**仅提取数值时间戳、Token 计数、子代理父子 ID 与当前会话 `title` 元数据**,绝不读取聊天正文。 |
105
107
  | **透明联网策略** | 底栏渲染热路径**完全不联网**;仅默认每 24 小时后台异步拉取一次公开免鉴权的 `models.dev` / `LiteLLM` 参考单价,随时可 `agy-bar config set pricingAutoSync off` 严格离线。 |
106
108
  | **零依赖极致流畅** | `0` 第三方依赖,空闲刷新零子进程(PID 快速路径 + 3s Git 缓存 + SQLite `mtime` 跳过 + 5 分钟 Windows 主题缓存),多终端并发采用原子写防文件损坏。 |
107
109
 
@@ -114,7 +116,7 @@ CTX ▮▮▮▯▯▯▯▯ 42.6% (1.0M) │ CACHE 88%·3m42s │ TTFT 1.9s·15
114
116
  ### 方式一:通过 `npx` 一键安装(推荐)
115
117
 
116
118
  ```sh
117
- npx agy-bar install
119
+ npx -y agy-bar@latest install
118
120
  ```
119
121
 
120
122
  ### 方式二:让 `agy` 自动帮你装
@@ -133,7 +135,7 @@ cd ~/agy-bar
133
135
  node bin/agy-bar.mjs install
134
136
  ```
135
137
 
136
- 安装完成后**重启 `agy`** 即可生效(已有会话可先运行 `/skills reload` 加载 `/agy-bar`)。`install` 会自动安装全局命令 `~/.local/bin/agy-bar` 并备份原有 `statusLine` 配置;若不需要配套 `/agy-bar` Skill,可加 `--no-skill`。
138
+ 安装完成后**重启 `agy`** 即可激活状态栏与官方原生 `title` 接口(已有会话可先运行 `/skills reload` 加载 `/agy-bar`)。`install` 会自动安装全局命令 `~/.local/bin/agy-bar`、安全备份原有 `statusLine` / `title` 配置(不会覆盖用户已有的自定义 `title` 脚本),且默认不改动 `~/.zshrc`(按需启用代理 Hook)。如不需要配套 `/agy-bar` Skill 或原生 `title`,可加 `--no-skill` / `--no-title`。
137
139
 
138
140
  ---
139
141
 
@@ -202,18 +204,18 @@ agy-bar config reset
202
204
 
203
205
  - **真彩与 256 色终端自动适配**:在 Ghostty、iTerm2、Kitty、WezTerm、Alacritty、Warp、VS Code、Windows Terminal 中输出 24-bit 真彩;在 macOS 自带 `Terminal.app`(`Apple_Terminal`)及未开真彩的 `tmux` / `screen` / SSH 下自动降级为最接近的 xterm-256 色;完整遵守 `NO_COLOR` 与 `TERM=dumb`。
204
206
  - **深浅主题自适应**:状态栏配色与 `agy-bar stats` 52 周热力图均自动适配深色与浅色背景。
205
- - **Windows 说明**:支持 Windows Terminal、PowerShell 7(`pwsh`)、Windows PowerShell 5.1 与 `cmd.exe`(兼容 `.cmd` 入口、Windows 系统代理检测、主题注册表 5 分钟缓存)。OSC 标签页标题同步仅适用于 macOS / Linux / WSL,原生 Windows 会自动安全跳过;如老版 ConHost 字体缺少 `▮`,可执行 `agy-bar config bar-style squares` 或 `blocks`。
207
+ - **Windows 说明**:支持 Windows Terminal、PowerShell 7(`pwsh`)、Windows PowerShell 5.1 与 `cmd.exe`(兼容 `.cmd` 入口、原生 AGY `title` 标签页标题同步、Windows 系统代理检测、主题注册表 5 分钟缓存;仅旧会话的 OSC `/dev/tty` 旁路回退为 POSIX 专属)。如老版 ConHost 字体缺少 `▮`,可执行 `agy-bar config bar-style squares` 或 `blocks`。
206
208
 
207
209
  ---
208
210
 
209
211
  ## 更新与卸载
210
212
 
211
213
  ```sh
212
- # 更新(保留个人配置、历史账本、定价缓存与原始 statusLine 备份)
213
- npx agy-bar@latest install
214
+ # 更新(保留个人配置、历史账本、定价缓存与原始 statusLine/title 备份)
215
+ npx -y agy-bar@latest install
214
216
 
215
- # 卸载并无损恢复原有 statusLine、移除托管 Shell Hook
216
- npx agy-bar uninstall # 或:agy-bar uninstall
217
+ # 卸载并无损恢复原有 statusLine/title、移除托管 Shell Hook
218
+ npx -y agy-bar@latest uninstall # 或:agy-bar uninstall
217
219
 
218
220
  # 彻底清理(含 Skill、配置目录,并立即清掉当前终端内存中的 agy() 函数与代理环境变量)
219
221
  eval "$(agy-bar uninstall --remove-skill --purge --print-cleanup)"
@@ -224,7 +226,7 @@ eval "$(agy-bar uninstall --remove-skill --purge --print-cleanup)"
224
226
  ## 本地开发
225
227
 
226
228
  ```sh
227
- npm test # 运行内置单元测试(75 项,macOS / Linux / Windows 三端 CI 验证)
229
+ npm test # 运行内置单元测试(88 项,macOS / Linux / Windows 三端 CI 验证)
228
230
  npm run preview # 终端实时预览
229
231
  npm run preview:svg # 重新生成 assets/ 下全部 5 张展示 SVG
230
232
  npm run stats # 查看本机统计
package/bin/agy-bar.mjs CHANGED
@@ -64,9 +64,18 @@ import {
64
64
  } from '../src/shell-hook.mjs';
65
65
  import { aggregateStats, formatStatsReport, HEATMAP_PALETTE_NAMES, PERIOD_NAMES, readLedger, SOURCE_NAMES } from '../src/stats.mjs';
66
66
  import { runStatusline } from '../src/statusline.mjs';
67
- import { buildTabTitle, writeOscTitle } from '../src/tab-title.mjs';
68
- import { armPayloadCapture, listSessions, readCapturedPayload, setSessionCustomTitle, updateSessionTabTitle } from '../src/telemetry.mjs';
67
+ import { readConversationSummaryTitle } from '../src/step-timing.mjs';
68
+ import { buildTabTitle, resolveTerminalTarget, writeOscTitle } from '../src/tab-title.mjs';
69
+ import {
70
+ armPayloadCapture,
71
+ findSessionForHost,
72
+ listSessions,
73
+ readCapturedPayload,
74
+ setSessionCustomTitle,
75
+ updateSessionTabTitle,
76
+ } from '../src/telemetry.mjs';
69
77
  import { THEME_NAMES } from '../src/themes.mjs';
78
+ import { isNativeTitleActive } from '../src/title.mjs';
70
79
 
71
80
  const pkg = JSON.parse(readFileSync(fileURLToPath(new URL('../package.json', import.meta.url)), 'utf8'));
72
81
 
@@ -432,22 +441,52 @@ export async function main(argv = process.argv.slice(2)) {
432
441
  if (command === 'title') {
433
442
  const { flags, positional } = parseFlags(rest);
434
443
  const cfg = loadConfig();
444
+ const hostTarget = flags.session ? null : resolveTerminalTarget();
445
+ const hostPid = hostTarget?.hostPid ?? null;
435
446
  if (!flags.clear && positional.length === 0) {
436
447
  const recent = listSessions();
437
- const target = flags.session ? recent.find((s) => s.sessionId === flags.session) : recent[0];
448
+ const target = flags.session
449
+ ? recent.find((s) => s.sessionId === flags.session)
450
+ : findSessionForHost(recent, hostPid);
438
451
  if (!target) {
439
452
  console.log('No active agy-bar session found yet.');
440
453
  return;
441
454
  }
455
+ const nativeTitleActive = isNativeTitleActive(target.sessionId, { hostPid: hostPid ?? process.ppid });
456
+ const resolvedConvTitle =
457
+ target.conversationTitle ||
458
+ (cfg.dbTiming !== false
459
+ ? readConversationSummaryTitle(target.sessionId, {
460
+ prevDbStamp: target.summaryDbStamp ?? null,
461
+ prevTitle: target.conversationTitle ?? null,
462
+ recheckIntervalMs: 0,
463
+ })?.title || null
464
+ : null);
465
+ const computedTitle = buildTabTitle(
466
+ {
467
+ agent_state: target.agentState,
468
+ subagents: target.runningSubagents || 0,
469
+ task_count: target.runningTasks || 0,
470
+ tool_confirmation_pending: Boolean(target.toolConfirmationPending),
471
+ conversation_title: resolvedConvTitle,
472
+ cwd: target.cwd,
473
+ },
474
+ {
475
+ config: cfg,
476
+ git: target.branch ? { branch: target.branch, dirty: target.dirty } : null,
477
+ customTitle: target.customTitle,
478
+ },
479
+ );
442
480
  console.log(
443
481
  JSON.stringify(
444
482
  {
445
483
  sessionId: target.sessionId,
446
484
  tabTitleEnabled: cfg.tabTitle,
485
+ nativeTitleActive,
447
486
  source: cfg.tabTitleSource,
448
487
  customTitle: target.customTitle || null,
449
- conversationTitle: target.conversationTitle || null,
450
- activeTabTitle: target.lastTabTitle || null,
488
+ conversationTitle: resolvedConvTitle,
489
+ activeTabTitle: (nativeTitleActive ? computedTitle : target.lastTabTitle || computedTitle) || null,
451
490
  },
452
491
  null,
453
492
  2,
@@ -459,15 +498,25 @@ export async function main(argv = process.argv.slice(2)) {
459
498
  const rawText = positional.join(' ').trim();
460
499
  const updated = setSessionCustomTitle(rawText, {
461
500
  sessionId: flags.session || null,
501
+ hostPid,
462
502
  clear: Boolean(flags.clear),
463
503
  });
504
+ const resolvedConvTitle =
505
+ updated.conversationTitle ||
506
+ (cfg.dbTiming !== false
507
+ ? readConversationSummaryTitle(updated.sessionId, {
508
+ prevDbStamp: updated.summaryDbStamp ?? null,
509
+ prevTitle: updated.conversationTitle ?? null,
510
+ recheckIntervalMs: 0,
511
+ })?.title || null
512
+ : null);
464
513
  const renderedTitle = buildTabTitle(
465
514
  {
466
515
  agent_state: updated.agentState,
467
516
  subagents: updated.runningSubagents || 0,
468
517
  task_count: updated.runningTasks || 0,
469
518
  tool_confirmation_pending: Boolean(updated.toolConfirmationPending),
470
- conversation_title: updated.conversationTitle,
519
+ conversation_title: resolvedConvTitle,
471
520
  cwd: updated.cwd,
472
521
  },
473
522
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agy-bar",
3
- "version": "0.9.5",
3
+ "version": "1.0.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",
@@ -34,6 +34,7 @@ agy-bar <command> # installed at ~/.local/bin/agy-bar (or: node ~/.gemini/conf
34
34
  | Multi-CLI live monitor | `agy-bar monitor [--once]` |
35
35
  | Redacted payload debug | `agy-bar debug --capture` then `agy-bar debug` |
36
36
  | Preview / Diagnostics | `agy-bar preview --scenario all` / `agy-bar doctor` |
37
+ | Full uninstall + live shell cleanup | `eval "$(agy-bar uninstall --remove-skill --purge --print-cleanup)"` |
37
38
 
38
39
  ## Toggleable Items
39
40
 
@@ -2,13 +2,14 @@ import { realpathSync } from 'node:fs';
2
2
  import { resolve } from 'node:path';
3
3
  import { fileURLToPath } from 'node:url';
4
4
  import { classifyAgentActivity, extractNativeCostUsd } from './agent-state.mjs';
5
+ import { sanitizeText } from './ansi.mjs';
5
6
  import { loadConfig } from './config.mjs';
6
7
  import { readGitInfo } from './git.mjs';
7
8
  import { getOrRefreshUsageSummary } from './history-scan.mjs';
8
9
  import { maybeTriggerBackgroundPricingSync } from './pricing-sync.mjs';
9
10
  import { extractAccountKey, syncSharedQuota } from './quota-sync.mjs';
10
11
  import { renderFallback, renderStatusline } from './render.mjs';
11
- import { readLatestStepTiming } from './step-timing.mjs';
12
+ import { readConversationSummaryTitle, readLatestStepTiming } from './step-timing.mjs';
12
13
  import { syncTabTitle } from './tab-title.mjs';
13
14
  import { deriveSessionId, maybeCaptureRedactedPayload, peekSessionState, recordTelemetry, resolveSessionTitles } from './telemetry.mjs';
14
15
  import { isNativeTitleActive } from './title.mjs';
@@ -57,14 +58,35 @@ export async function runStatusline({ stdin = process.stdin, stdout = process.st
57
58
  })
58
59
  : null;
59
60
 
61
+ const hasPayloadTitle = Boolean(sanitizeText(effectivePayload?.conversation_title || ''));
62
+ const summaryTitle =
63
+ config.tabTitle && !hasPayloadTitle && config.tabTitleSource !== 'dir' && config.dbTiming !== false
64
+ ? readConversationSummaryTitle(effectivePayload, {
65
+ prevDbStamp: prevSession?.summaryDbStamp ?? null,
66
+ prevTitle: prevSession?.conversationTitle ?? null,
67
+ prevCheckedAt: prevSession?.summaryTitleCheckedAt ?? null,
68
+ now,
69
+ recheckIntervalMs: 15_000,
70
+ })
71
+ : null;
72
+ const { conversationTitle, customTitle } = resolveSessionTitles(effectivePayload, prevSession, {
73
+ dbTitle: summaryTitle?.title ?? null,
74
+ });
75
+ const payloadForTitle =
76
+ conversationTitle && !hasPayloadTitle
77
+ ? { ...effectivePayload, conversation_title: conversationTitle }
78
+ : effectivePayload;
79
+
60
80
  // Sync terminal tab title synchronously before async DB scans when AGY's native
61
- // `settings.json.title` hook is not already driving this session's title.
81
+ // `settings.json.title` hook is not already driving this session's title, OR as a
82
+ // one-shot push the moment a brand-new conversation's initial summary title lands.
62
83
  let tabSync = null;
63
84
  if (!plain && config.tabTitle) {
64
85
  const sessionIdForTitle = deriveSessionId(effectivePayload);
65
- if (!isNativeTitleActive(sessionIdForTitle, { now, hostPid: process.ppid })) {
66
- const { customTitle } = resolveSessionTitles(effectivePayload, prevSession);
67
- tabSync = syncTabTitle(effectivePayload, {
86
+ const nativeActive = isNativeTitleActive(sessionIdForTitle, { now, hostPid: process.ppid });
87
+ const newlyDiscoveredDbTitle = Boolean(!hasPayloadTitle && !prevSession?.conversationTitle && conversationTitle && !customTitle);
88
+ if (!nativeActive || newlyDiscoveredDbTitle) {
89
+ tabSync = syncTabTitle(payloadForTitle, {
68
90
  config,
69
91
  git,
70
92
  customTitle,
@@ -72,6 +94,7 @@ export async function runStatusline({ stdin = process.stdin, stdout = process.st
72
94
  prevTabHostPid: prevSession?.lastTabHostPid ?? null,
73
95
  prevTabTty: prevSession?.lastTabTty || null,
74
96
  hostPidHint: process.ppid,
97
+ force: nativeActive && newlyDiscoveredDbTitle,
75
98
  resolveOpts: { env },
76
99
  });
77
100
  }
@@ -84,6 +107,7 @@ export async function runStatusline({ stdin = process.stdin, stdout = process.st
84
107
  now,
85
108
  git,
86
109
  stepTiming,
110
+ summaryTitle,
87
111
  prevSession,
88
112
  tabSync,
89
113
  cacheTtlSec: config.cacheTtlSec,
@@ -1,9 +1,22 @@
1
1
  import { existsSync, statSync } from 'node:fs';
2
+ import { createRequire } from 'node:module';
2
3
  import { homedir } from 'node:os';
3
4
  import { join } from 'node:path';
4
5
 
5
6
  const UUID_RE = /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i;
6
7
 
8
+ let cachedDatabaseSync;
9
+ function loadDatabaseSync() {
10
+ if (cachedDatabaseSync !== undefined) return cachedDatabaseSync;
11
+ try {
12
+ const req = createRequire(import.meta.url);
13
+ cachedDatabaseSync = req('node:sqlite').DatabaseSync || null;
14
+ } catch {
15
+ cachedDatabaseSync = null;
16
+ }
17
+ return cachedDatabaseSync;
18
+ }
19
+
7
20
  export function decodePbFields(buf) {
8
21
  const b = Buffer.isBuffer(buf) ? buf : Buffer.from(buf || []);
9
22
  let offset = 0;
@@ -162,3 +175,67 @@ export async function readLatestStepTiming(payload, { home = homedir(), prevDbSt
162
175
  }
163
176
  }
164
177
  }
178
+
179
+ export function summaryDbPath(home = homedir()) {
180
+ return join(home, '.gemini', 'antigravity-cli', 'conversation_summaries.db');
181
+ }
182
+
183
+ // Reads ONLY the generated title column for the active conversation from AGY's local
184
+ // conversation_summaries.db (never reads previews, prompts, or replies) when AGY CLI
185
+ // omits conversation_title from live payloads on brand-new conversations.
186
+ export function readConversationSummaryTitle(
187
+ payload,
188
+ {
189
+ home = homedir(),
190
+ dbPath = null,
191
+ prevDbStamp = null,
192
+ prevTitle = null,
193
+ prevCheckedAt = null,
194
+ now = Date.now(),
195
+ recheckIntervalMs = 15_000,
196
+ } = {},
197
+ ) {
198
+ const id = typeof payload === 'string' ? payload : payload?.conversation_id || payload?.session_id;
199
+ if (typeof id !== 'string' || !UUID_RE.test(id)) return null;
200
+
201
+ const targetDb = dbPath || summaryDbPath(home);
202
+ if (!existsSync(targetDb)) return null;
203
+
204
+ const dbStamp = getDbVersionStamp(targetDb);
205
+ if (prevDbStamp && dbStamp && dbStamp === prevDbStamp) {
206
+ return { title: prevTitle || null, unchanged: true, dbStamp, checkedAt: prevCheckedAt ?? now };
207
+ }
208
+
209
+ // Once we already have a title for this session, throttle re-checks while other chats write to the shared WAL.
210
+ if (
211
+ prevTitle &&
212
+ recheckIntervalMs > 0 &&
213
+ typeof prevCheckedAt === 'number' &&
214
+ now >= prevCheckedAt &&
215
+ now - prevCheckedAt < recheckIntervalMs
216
+ ) {
217
+ return { title: prevTitle, unchanged: true, dbStamp: prevDbStamp || dbStamp, checkedAt: prevCheckedAt };
218
+ }
219
+
220
+ const DatabaseSync = loadDatabaseSync();
221
+ if (!DatabaseSync) return null;
222
+
223
+ let db;
224
+ try {
225
+ db = new DatabaseSync(targetDb, { readOnly: true });
226
+ const row = db
227
+ .prepare('SELECT title FROM conversation_summaries WHERE conversation_id = ? LIMIT 1')
228
+ .get(id);
229
+ const raw = typeof row?.title === 'string' ? row.title.trim() : '';
230
+ return { title: raw || null, unchanged: false, dbStamp, checkedAt: now };
231
+ } catch {
232
+ // Gracefully fall back on Node < 22.13, locked DBs, or schema changes.
233
+ return null;
234
+ } finally {
235
+ try {
236
+ db?.close();
237
+ } catch {
238
+ // Ignore close errors.
239
+ }
240
+ }
241
+ }
package/src/telemetry.mjs CHANGED
@@ -158,8 +158,10 @@ function pickQuotaSnapshot(quota) {
158
158
  return Object.keys(out).length > 0 ? out : null;
159
159
  }
160
160
 
161
- export function resolveSessionTitles(payload = {}, prev = null) {
162
- const conversationTitle = sanitizeText(payload?.conversation_title || '') || prev?.conversationTitle || null;
161
+ export function resolveSessionTitles(payload = {}, prev = null, { dbTitle = null } = {}) {
162
+ const payloadTitle = sanitizeText(payload?.conversation_title || '') || null;
163
+ const fallbackDbTitle = sanitizeText(dbTitle || '') || null;
164
+ const conversationTitle = payloadTitle || fallbackDbTitle || prev?.conversationTitle || null;
163
165
  // If user explicitly renamed the conversation via /rename (conversation_title changed),
164
166
  // clear any older custom tab override automatically.
165
167
  let customTitle = prev?.customTitle || null;
@@ -167,6 +169,9 @@ export function resolveSessionTitles(payload = {}, prev = null) {
167
169
  if (customTitle && conversationTitle && customTitleBase && conversationTitle !== customTitleBase) {
168
170
  customTitle = null;
169
171
  customTitleBase = null;
172
+ } else if (customTitle && !customTitleBase && !payloadTitle && fallbackDbTitle) {
173
+ // Anchor customTitleBase once AGY's initial background summary lands so a later /rename still supersedes it.
174
+ customTitleBase = fallbackDbTitle;
170
175
  }
171
176
  return { conversationTitle, customTitle, customTitleBase };
172
177
  }
@@ -177,6 +182,7 @@ export function recordTelemetry(
177
182
  now = Date.now(),
178
183
  git = null,
179
184
  stepTiming = null,
185
+ summaryTitle = null,
180
186
  prevSession = undefined,
181
187
  tabSync = null,
182
188
  baseDir = configDir(homedir()),
@@ -390,7 +396,9 @@ export function recordTelemetry(
390
396
  const cacheRemainingSec =
391
397
  lastActivityAt !== null ? Math.max(0, Math.round((cacheTtlMs - (now - lastActivityAt)) / 1000)) : null;
392
398
 
393
- const { conversationTitle, customTitle, customTitleBase } = resolveSessionTitles(p, prev);
399
+ const { conversationTitle, customTitle, customTitleBase } = resolveSessionTitles(p, prev, {
400
+ dbTitle: summaryTitle?.title ?? null,
401
+ });
394
402
  const tabWritten = Boolean(tabSync?.written && tabSync.title);
395
403
  const nextTabTitle = tabWritten ? tabSync.title : prev?.lastTabTitle || null;
396
404
  const nextTabHostPid = tabWritten
@@ -418,6 +426,8 @@ export function recordTelemetry(
418
426
  gitRemoved: typeof git?.removed === 'number' ? git.removed : prev?.gitRemoved ?? null,
419
427
  gitCheckedAt: git?.dirtyChecked ? now : prev?.gitCheckedAt ?? null,
420
428
  dbStamp: stepTiming?.dbStamp ?? prev?.dbStamp ?? null,
429
+ summaryDbStamp: summaryTitle?.dbStamp ?? prev?.summaryDbStamp ?? null,
430
+ summaryTitleCheckedAt: summaryTitle?.checkedAt ?? prev?.summaryTitleCheckedAt ?? null,
421
431
  agentState: sanitizeText(p.agent_state || '') || 'idle',
422
432
  activityKind: activity.kind,
423
433
  needsAttention: activity.needsAttention,
@@ -512,16 +522,39 @@ export function updateSessionTabTitle(
512
522
  }
513
523
  }
514
524
 
525
+ function readNativeTitlePid(sessionId, baseDir) {
526
+ const markerPath = join(sessionsDir(baseDir), `${sessionId}.title`);
527
+ if (!existsSync(markerPath)) return null;
528
+ try {
529
+ const [, rawPid] = readFileSync(markerPath, 'utf8').trim().split(':');
530
+ const pid = Number(rawPid);
531
+ return Number.isFinite(pid) && pid > 1 ? pid : null;
532
+ } catch {
533
+ return null;
534
+ }
535
+ }
536
+
537
+ export function findSessionForHost(sessions, hostPid, { baseDir = configDir(homedir()) } = {}) {
538
+ if (!Array.isArray(sessions) || sessions.length === 0) return null;
539
+ if (typeof hostPid === 'number' && hostPid > 1) {
540
+ const byTabPid = sessions.find((s) => s.lastTabHostPid === hostPid);
541
+ if (byTabPid) return byTabPid;
542
+ const byNativeMarker = sessions.find((s) => readNativeTitlePid(s.sessionId, baseDir) === hostPid);
543
+ if (byNativeMarker) return byNativeMarker;
544
+ }
545
+ return sessions[0];
546
+ }
547
+
515
548
  export function setSessionCustomTitle(
516
549
  title,
517
- { sessionId = null, baseDir = configDir(homedir()), now = Date.now(), clear = false } = {},
550
+ { sessionId = null, hostPid = null, baseDir = configDir(homedir()), now = Date.now(), clear = false } = {},
518
551
  ) {
519
552
  const sDir = sessionsDir(baseDir);
520
553
  let targetId = sessionId ? String(sessionId).trim().replace(/[^a-zA-Z0-9_-]/g, '') : null;
521
554
 
522
555
  if (!targetId) {
523
556
  const recent = listSessions({ baseDir, now });
524
- targetId = recent[0]?.sessionId || 'default';
557
+ targetId = findSessionForHost(recent, hostPid, { baseDir })?.sessionId || 'default';
525
558
  }
526
559
 
527
560
  const sFile = join(sDir, `${targetId}.json`);
package/src/title.mjs CHANGED
@@ -5,6 +5,7 @@ import { fileURLToPath } from 'node:url';
5
5
  import { sanitizeText } from './ansi.mjs';
6
6
  import { configDir, loadConfig } from './config.mjs';
7
7
  import { readGitInfo } from './git.mjs';
8
+ import { readConversationSummaryTitle } from './step-timing.mjs';
8
9
  import { buildTabTitle } from './tab-title.mjs';
9
10
  import { deriveSessionId, peekSessionState, resolveSessionTitles, sessionsDir } from './telemetry.mjs';
10
11
 
@@ -15,6 +16,21 @@ export function nativeTitleMarkerPath(sessionId, baseDir = configDir(homedir()))
15
16
  return join(sessionsDir(baseDir), `${sessionId}.title`);
16
17
  }
17
18
 
19
+ export function readNativeTitleMarker(sessionId, baseDir = configDir(homedir())) {
20
+ if (!sessionId) return null;
21
+ const markerPath = nativeTitleMarkerPath(sessionId, baseDir);
22
+ if (!existsSync(markerPath)) return null;
23
+ try {
24
+ const [rawTs, rawPid] = readFileSync(markerPath, 'utf8').trim().split(':');
25
+ const ts = Number(rawTs);
26
+ const pid = Number(rawPid);
27
+ if (!Number.isFinite(ts) || ts <= 0) return null;
28
+ return { ts, pid: Number.isFinite(pid) && pid > 1 ? pid : null };
29
+ } catch {
30
+ return null;
31
+ }
32
+ }
33
+
18
34
  export function touchNativeTitleMarker(
19
35
  sessionId,
20
36
  { now = Date.now(), hostPid = process.ppid, baseDir = configDir(homedir()) } = {},
@@ -22,18 +38,9 @@ export function touchNativeTitleMarker(
22
38
  if (!sessionId) return false;
23
39
  const markerPath = nativeTitleMarkerPath(sessionId, baseDir);
24
40
  try {
25
- if (existsSync(markerPath)) {
26
- const [rawTs, rawPid] = readFileSync(markerPath, 'utf8').trim().split(':');
27
- const prevTs = Number(rawTs);
28
- const prevPid = Number(rawPid);
29
- if (
30
- Number.isFinite(prevTs) &&
31
- now - prevTs < NATIVE_TITLE_TOUCH_INTERVAL_MS &&
32
- Number.isFinite(prevPid) &&
33
- prevPid === hostPid
34
- ) {
35
- return true;
36
- }
41
+ const prev = readNativeTitleMarker(sessionId, baseDir);
42
+ if (prev && now - prev.ts < NATIVE_TITLE_TOUCH_INTERVAL_MS && prev.pid === hostPid) {
43
+ return true;
37
44
  }
38
45
  mkdirSync(dirname(markerPath), { recursive: true });
39
46
  writeFileSync(markerPath, `${now}:${Number.isFinite(hostPid) ? hostPid : 0}\n`, 'utf8');
@@ -47,41 +54,53 @@ export function isNativeTitleActive(
47
54
  sessionId,
48
55
  { now = Date.now(), hostPid = process.ppid, baseDir = configDir(homedir()) } = {},
49
56
  ) {
50
- if (!sessionId) return false;
51
- const markerPath = nativeTitleMarkerPath(sessionId, baseDir);
52
- if (!existsSync(markerPath)) return false;
53
- try {
54
- const [rawTs, rawPid] = readFileSync(markerPath, 'utf8').trim().split(':');
55
- const ts = Number(rawTs);
56
- const pid = Number(rawPid);
57
- if (!Number.isFinite(ts) || ts <= 0) return false;
58
- const ageMs = now - ts;
59
- if (ageMs < 0) return true;
60
- if (ageMs < NATIVE_TITLE_FRESH_MS) return true;
61
- if (ageMs < 24 * 60 * 60 * 1000 && Number.isFinite(pid) && pid > 1 && typeof hostPid === 'number' && pid === hostPid) {
62
- return true;
63
- }
64
- return false;
65
- } catch {
66
- return false;
57
+ const marker = readNativeTitleMarker(sessionId, baseDir);
58
+ if (!marker) return false;
59
+ const ageMs = now - marker.ts;
60
+ if (ageMs < 0 || ageMs < NATIVE_TITLE_FRESH_MS) return true;
61
+ if (ageMs < 24 * 60 * 60 * 1000 && marker.pid !== null && typeof hostPid === 'number' && marker.pid === hostPid) {
62
+ return true;
67
63
  }
64
+ return false;
68
65
  }
69
66
 
70
67
  export function renderNativeTitle(
71
68
  payload = {},
72
- { config = loadConfig(), prevSession = undefined, baseDir = configDir(homedir()), now = Date.now(), hostPid = process.ppid, touchMarker = true } = {},
69
+ {
70
+ config = loadConfig(),
71
+ prevSession = undefined,
72
+ home = homedir(),
73
+ baseDir = configDir(home),
74
+ summaryDbPath = null,
75
+ now = Date.now(),
76
+ hostPid = process.ppid,
77
+ touchMarker = true,
78
+ } = {},
73
79
  ) {
74
80
  if (config.tabTitle === false) return '';
75
81
 
76
82
  const p = payload && typeof payload === 'object' ? payload : {};
77
83
  const sessionId = deriveSessionId(p);
78
84
  const prev = prevSession !== undefined ? prevSession : peekSessionState(p, { baseDir });
79
- const { customTitle } = resolveSessionTitles(p, prev);
85
+ const hasPayloadTitle = Boolean(sanitizeText(p?.conversation_title || ''));
86
+ const summaryLookup =
87
+ !hasPayloadTitle && config.tabTitleSource !== 'dir' && config.dbTiming !== false
88
+ ? readConversationSummaryTitle(p, {
89
+ home,
90
+ dbPath: summaryDbPath,
91
+ prevDbStamp: prev?.summaryDbStamp ?? null,
92
+ prevTitle: prev?.conversationTitle ?? null,
93
+ prevCheckedAt: prev?.summaryTitleCheckedAt ?? null,
94
+ now,
95
+ recheckIntervalMs: 5_000,
96
+ })
97
+ : null;
98
+ const { conversationTitle, customTitle } = resolveSessionTitles(p, prev, {
99
+ dbTitle: summaryLookup?.title ?? null,
100
+ });
80
101
 
81
102
  const cwd = p?.workspace?.current_dir || p?.cwd || prev?.cwd || null;
82
- const needsGit =
83
- config.tabTitleSource === 'dir' ||
84
- (!customTitle && !sanitizeText(p?.conversation_title || ''));
103
+ const needsGit = config.tabTitleSource === 'dir' || (!customTitle && !conversationTitle);
85
104
  let git = null;
86
105
  if (needsGit && cwd) {
87
106
  if (prev && prev.cwd === cwd && prev.branch) {
@@ -92,7 +111,9 @@ export function renderNativeTitle(
92
111
  }
93
112
  }
94
113
 
95
- const title = buildTabTitle(p, { config, git, customTitle });
114
+ const effectivePayload =
115
+ conversationTitle && !hasPayloadTitle ? { ...p, conversation_title: conversationTitle } : p;
116
+ const title = buildTabTitle(effectivePayload, { config, git, customTitle });
96
117
  if (touchMarker) {
97
118
  touchNativeTitleMarker(sessionId, { now, hostPid, baseDir });
98
119
  }
@@ -102,8 +123,12 @@ export function renderNativeTitle(
102
123
  export async function runTitleCommand({
103
124
  stdin = process.stdin,
104
125
  stdout = process.stdout,
105
- baseDir = configDir(homedir()),
126
+ home = homedir(),
127
+ baseDir = configDir(home),
128
+ summaryDbPath = null,
106
129
  config = undefined,
130
+ now = Date.now(),
131
+ hostPid = process.ppid,
107
132
  } = {}) {
108
133
  let raw = '';
109
134
  for await (const chunk of stdin) {
@@ -113,7 +138,7 @@ export async function runTitleCommand({
113
138
  try {
114
139
  const payload = raw.trim() ? JSON.parse(raw) : {};
115
140
  const cfg = config ?? loadConfig();
116
- const title = renderNativeTitle(payload, { config: cfg, baseDir });
141
+ const title = renderNativeTitle(payload, { config: cfg, home, baseDir, summaryDbPath, now, hostPid });
117
142
  if (title) {
118
143
  stdout.write(`${title}\n`);
119
144
  }