@cxmyu/ccglance 1.0.0 → 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.
Files changed (3) hide show
  1. package/README.md +15 -170
  2. package/README.zh-CN.md +13 -142
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -145,90 +145,17 @@ On Windows use a full path, e.g. `node D:\\path\\to\\ccglance\\dist\\cli.js`.
145
145
  > command needs no path at all. `"padding": 0` drops Claude Code's default leading
146
146
  > indent so the row starts at the left edge.
147
147
 
148
- ## Line reference
148
+ ## Status line at a glance
149
149
 
150
- **Line 1 — runtime**
150
+ Three logical rows; any row with no data disappears:
151
151
 
152
- | Label | Segment | Source | Shows |
153
- |---|---|---|---|
154
- | 🤖 | model | `model.display_name`, fallback to `model.id` | stdin display name with minimal compacting (`Opus 4.8 1M`); readable id fallback when missing |
155
- | 🧠 | effort | `effort.level` | reasoning effort |
156
- | ✅/⏸️/💭/⚙️/🔧 | status | transcript tail | icon-only state; tool name while a tool is running |
157
- | 🚀 | fast | `fast_mode` | shown only when fast mode is on |
158
- | ⚡️ | context | `context_window` | usage % · input · output · tokens left |
159
- | 💾 | cache | `context_window.current_usage` | hit % · cache read · cache write |
160
- | 🎯 | style | `output_style.name` | active output style |
152
+ 1. **Runtime** — 🤖 model · 🧠 effort · status · 🚀 fast · ⚡️ context · 💾 cache · 🎯 style
153
+ 2. **Quota** *(subscription sessions only)* — 📊 Hour / Week rate-limit meters
154
+ 3. **Project / session** — 📁 dir · 🌿 git · 🏷️ session name · ⏱️ session · 💰 cost · 💩 version
161
155
 
162
- **Line 2 — quota**
163
-
164
- | Label | Segment | Source | Shows |
165
- |---|---|---|---|
166
- | 📊 | rate limits | `rate_limits.five_hour` / `rate_limits.seven_day` | Compact Hour / Week moon-phase meters with percentage and reset time; Claude Code does not provide a monthly quota window |
167
-
168
- **Line 3 — project / session**
169
-
170
- | Icon | Segment | Source | Shows |
171
- |---|---|---|---|
172
- | 📁 | dir | `workspace.current_dir` | current directory name |
173
- | 🌿 / 🌲 | git + worktree | stdin + local `git` | branch + status glyph: `✓` clean, `●` dirty, `⚠` conflicts; plus `↑ahead` `↓behind`; `worktree.name` is appended after the branch state |
174
- | 🏷️ | session name | `session_name` | set via `--name` or `/rename` |
175
- | ⏱️ | session | `cost` | elapsed time + `+added` `-removed` lines |
176
- | 💰 | cost | `cost.total_cost_usd` | USD cost, shown only when greater than 0 |
177
- | 💩 | version | `version` | Claude Code version; appends `↑latest` when the 4h cache finds a newer release |
178
-
179
- Rate-limit moon phases:
180
-
181
- | Usage | Icon |
182
- |---|---|
183
- | 0% <= usage < 10% | 🌑 |
184
- | 10% <= usage < 30% | 🌒 |
185
- | 30% <= usage < 60% | 🌓 |
186
- | 60% <= usage < 90% | 🌔 |
187
- | 90% <= usage <= 100% | 🌕 |
188
-
189
- ## Icon Reference
190
-
191
- | Icon | Meaning |
192
- |---|---|
193
- | 🤖 | model name; `model.display_name` is the source of truth, with readable `model.id` fallback |
194
- | 🧠 | reasoning effort |
195
- | ✅ | idle; the last assistant turn appears complete |
196
- | ⏸️ | paused; a running action was interrupted or cancelled |
197
- | 💭 | thinking; waiting for or receiving model output |
198
- | ⚙️ | working; a tool result returned and Claude is processing it |
199
- | 🔧 | tool call in progress; the tool name is shown when available |
200
- | 🚀 | fast mode |
201
- | ⚡️ | context-window usage |
202
- | 💾 | prompt cache usage |
203
- | 🎯 | output style |
204
- | 📊 | Hour / Week rate-limit quota |
205
- | 🌑 🌒 🌓 🌔 🌕 | rate-limit usage level |
206
- | ⏳ | time until the quota window resets |
207
- | 📁 | current directory |
208
- | 🌿 | git branch |
209
- | ✓ ● ⚠ | git clean / dirty / conflict |
210
- | 🌲 | worktree name, shown inside the git segment |
211
- | 🏷️ | session name |
212
- | ⏱️ | session duration |
213
- | 💰 | session cost |
214
- | 💩 | Claude Code version |
215
- | ↑latest | newer Claude Code version is available |
216
-
217
- ## Color Semantics
218
-
219
- | Color | Meaning |
220
- |---|---|
221
- | Bright green | idle/healthy state, fast mode, cache, additions, clean git marker, git ahead/outgoing/push count |
222
- | Yellow | attention state: paused status, effort, quota reset time, cost, warning thresholds |
223
- | Bright red | risk or negative state: danger thresholds, conflicts, deletions, update hint |
224
- | Blue | Git modified/dirty status and behind/incoming/pull count |
225
- | Cyan / white | neutral runtime/project identity: model, style, session duration, git branch |
226
- | Magenta | active context/session identity: context window, session name |
227
-
228
- The status icons are inferred from the transcript tail when Claude Code redraws
229
- the status line. They are a redraw-time approximation, not a live event stream.
230
- If a running action is cancelled with Esc, ccglance updates on the next Claude
231
- Code redraw; transcript interrupt markers are shown as paused.
156
+ **Full reference** — every segment's stdin source, all icon meanings, rate-limit
157
+ moon-phase levels, session-status icons and color semantics — lives in
158
+ **[docs/segments.md](./docs/segments.md)**.
232
159
 
233
160
  ## How it works
234
161
 
@@ -247,80 +174,16 @@ bounded transcript-tail reads, and the post-render detached npm registry check.
247
174
 
248
175
  ## Development
249
176
 
250
- ### Source Build
177
+ Source build, tests, benchmark, source layout, contribution practices and git
178
+ cache internals live in **[docs/development.md](./docs/development.md)**. Quick start:
251
179
 
252
180
  ```bash
253
181
  git clone https://github.com/CxMYu/CcGlanceLine.git
254
182
  cd CcGlanceLine
255
- npm install # installs devDeps and runs prepare -> build
256
-
257
- npm run build # compile src/ → dist/
258
- npm run typecheck # tsc --noEmit (strict)
259
- npm test # build + node:test fixtures/snapshots/smoke
260
- npm run benchmark # build + latency benchmark
261
- ccglance preview # preview the linked/global command
262
-
263
- # smoke-test with a sample stdin payload:
264
- printf '%s' '{"model":{"display_name":"Claude Opus 4.8 (1M context)","id":"claude-opus-4-8[1m]"}}' | node dist/cli.js
183
+ npm install # devDeps + prepare build
184
+ npm test # build + node:test
265
185
  ```
266
186
 
267
- For local dogfooding, use `npm link` after building and configure Claude Code
268
- with `"command": "ccglance"`. Without a global link, point Claude Code directly
269
- at `node /absolute/path/to/ccglance/dist/cli.js`.
270
-
271
- ### Validation
272
-
273
- - `test/fixtures/` contains stdin payloads for subscription, API-style,
274
- missing-field, and high-context scenarios.
275
- - `test/snapshots/` locks the ANSI-colored rendered output so icon, spacing,
276
- color, and row changes are intentional.
277
- - `test/*.test.js` uses Node's built-in `node:test`; no test runner dependency
278
- is added to the runtime package.
279
- - `bench/latency.js` measures cold process startup against an empty Node
280
- baseline, plus no-git, subscription+transcript, git warm-cache, and git
281
- cold-fallback paths. On Windows, the empty Node baseline is usually the
282
- dominant part of the number; compare ccglance cases to that baseline.
283
-
284
- ### Agent Build Practices
285
-
286
- - Treat `src/` as the source of truth. Do not hand-edit `dist/`; regenerate it
287
- with `npm run build`.
288
- - Keep the status line fixed-style: no user config loader, no external style
289
- file, and no runtime style discovery.
290
- - Keep runtime dependencies at zero. New dependencies must be development-only
291
- and justified by the build pipeline.
292
- - After code changes, run `npm run typecheck`, `npm run build`, and
293
- `ccglance preview`.
294
- - When changing icon or spacing behavior, test the plain ANSI-stripped preview
295
- and at least one synthetic stdin payload that exercises the edited segment.
296
-
297
- ### Source layout
298
-
299
- ```text
300
- src/
301
- cli.ts # command entry: preview / statusLine stdin
302
- defaults/ # fixed built-in style and segment order
303
- readers/ # stdin, transcript tail reads, terminal width
304
- render/ # colors, icons, layout, final rendering
305
- segments/ # per-segment rendering logic
306
- runtime/ # git and Claude Code version-cache helpers
307
- types/ # Claude Code stdin and renderer types
308
- utils/ # formatting and display-width helpers
309
- test/
310
- fixtures/ # representative Claude Code stdin and transcript data
311
- snapshots/ # fixed rendered-output baselines
312
- bench/
313
- latency.js # startup and cache-path benchmark
314
- ```
315
-
316
- Only the compiled `dist/` is published to npm. `npm run build` cleans `dist`
317
- before compiling so old flat artifacts cannot leak into the package.
318
-
319
- ## Session status and preview
320
-
321
- - Session status: an icon indicator inferred from the transcript tail; `✅` idle, `⏸️` paused/interrupted, `💭` thinking, `⚙️` processing a tool result, `🔧 <tool>` running a tool.
322
- - ccglance preview: render a built-in sample with the fixed renderer.
323
-
324
187
  ## Cache Files
325
188
 
326
189
  ccglance stores only disposable runtime caches: git status, transcript-derived
@@ -341,27 +204,9 @@ If you set `CLAUDE_CONFIG_DIR` to relocate Claude Code's config, ccglance places
341
204
  its caches under that directory instead. Deleting the whole `ccglance/` folder is
342
205
  safe — every file is regenerated on the next render.
343
206
 
344
- Git cache behavior:
345
-
346
- - Cache key is the Git worktree root, so multiple Claude Code terminals in the
347
- same repo share one git cache.
348
- - The branch name prefers Claude Code stdin when `worktree.branch` is present;
349
- otherwise ccglance checks `.git/HEAD` on every render, so normal branch
350
- switches still show up immediately.
351
- - Dirty/conflict and ahead/behind details use a cache. A cache newer than 20
352
- minutes is returned when it still belongs to the current branch.
353
- - Local state (`✓` / `●` / `⚠`) and upstream state (`↑ahead` / `↓behind`) come
354
- from the same cached `git status --porcelain=v2 --branch` snapshot, so they
355
- share the same TTL. If both local and upstream changes exist, ccglance shows
356
- them together, for example `main ● ↑1 ↓1`.
357
- - A stale cache, missing cache, or branch change still renders immediately;
358
- ccglance shows a fast branch-only `HEAD` fallback, then refreshes `git status`
359
- in a detached process.
360
- - Refresh uses an exclusive `.refresh` marker and atomic temp-file rename, so
361
- concurrent terminals do not corrupt the cache.
362
- - There is no heartbeat or resident watcher. Refresh is lazy: Claude Code
363
- redraws the status line, ccglance checks the cache age, and only then starts
364
- the detached refresh process if the cache is stale.
207
+ Git cache behavior (cache key, `HEAD` fallback, 20-minute TTL, detached refresh,
208
+ atomic writes) is documented in
209
+ [docs/development.md](./docs/development.md#git-cache-internals).
365
210
 
366
211
  ## Related Projects
367
212
 
package/README.zh-CN.md CHANGED
@@ -129,88 +129,16 @@ Windows 用完整路径,例如 `node D:\\path\\to\\ccglance\\dist\\cli.js`。
129
129
  > 全局的 `ccglance` 命令则完全不需要写路径。`"padding": 0` 去掉 Claude Code 默认的左侧缩进,
130
130
  > 让状态栏从最左开始。
131
131
 
132
- ## 字段说明
132
+ ## 状态栏速览
133
133
 
134
- **第一行 —— 运行时**
134
+ 三个逻辑行,任意一行无数据时自动消失:
135
135
 
136
- | 标识 | 段 | 来源 | 展示 |
137
- |---|---|---|---|
138
- | 🤖 | 模型 | `model.display_name`,缺失时回退 `model.id` | stdin display name 只做轻量压缩(`Opus 4.8 1M`);缺失时用可读 id 兜底 |
139
- | 🧠 | effort | `effort.level` | 推理强度 |
140
- | ✅/⏸️/💭/⚙️/🔧 | 状态 | transcript 尾部 | 仅图标显示状态;工具运行时显示工具名 |
141
- | 🚀 | fast | `fast_mode` | 仅 fast 模式开启时显示 |
142
- | ⚡️ | 上下文 | `context_window` | 占比 · 输入 · 输出 · 剩余 |
143
- | 💾 | 缓存 | `context_window.current_usage` | 命中率 · 缓存读取 · 缓存写入 |
144
- | 🎯 | 输出风格 | `output_style.name` | 当前 output style |
136
+ 1. **运行时** —— 🤖 模型 · 🧠 effort · 状态 · 🚀 fast · ⚡️ 上下文 · 💾 缓存 · 🎯 风格
137
+ 2. **配额**(仅订阅会话)—— 📊 Hour / Week 配额仪表
138
+ 3. **项目 / 会话** —— 📁 目录 · 🌿 git · 🏷️ 会话名 · ⏱️ 会话 · 💰 成本 · 💩 版本
145
139
 
146
- **第二行 —— 订阅 / 配额**
147
-
148
- | 标识 | 段 | 来源 | 展示 |
149
- |---|---|---|---|
150
- | 📊 | 配额 | `rate_limits.five_hour` / `rate_limits.seven_day` | Hour / Week 紧凑月相仪表,各自带百分比和重置时间;Claude Code 当前没有月配额窗口 |
151
-
152
- **第三行 —— 项目 / 会话**
153
-
154
- | 图标 | 段 | 来源 | 展示 |
155
- |---|---|---|---|
156
- | 📁 | 目录 | `workspace.current_dir` | 当前目录名 |
157
- | 🌿 / 🌲 | git + worktree | stdin + 本地 `git` | 分支 + 状态标记:`✓` 干净、`●` 有未提交变更、`⚠` 有冲突;另含 `↑领先` `↓落后`;`worktree.name` 追加在分支状态右侧 |
158
- | 🏷️ | 会话名 | `session_name` | 由 `--name` 或 `/rename` 设置 |
159
- | ⏱️ | 会话 | `cost` | 耗时 + `+新增` `-删除` 行数 |
160
- | 💰 | cost | `cost.total_cost_usd` | 美元成本,大于 0 时显示 |
161
- | 💩 | 版本 | `version` | Claude Code 版本;4 小时缓存发现新版时追加 `↑latest` |
162
-
163
- 配额月相映射:
164
-
165
- | 占用 | 图标 |
166
- |---|---|
167
- | 0% <= 占用 < 10% | 🌑 |
168
- | 10% <= 占用 < 30% | 🌒 |
169
- | 30% <= 占用 < 60% | 🌓 |
170
- | 60% <= 占用 < 90% | 🌔 |
171
- | 90% <= 占用 <= 100% | 🌕 |
172
-
173
- ## 图标说明
174
-
175
- | 图标 | 含义 |
176
- |---|---|
177
- | 🤖 | 模型名;以 `model.display_name` 为准,缺失时用可读 `model.id` 兜底 |
178
- | 🧠 | 推理强度 |
179
- | ✅ | 空闲;最近一轮 assistant 输出已完成 |
180
- | ⏸️ | 暂停;正在执行的动作被用户中断或取消 |
181
- | 💭 | 思考中;等待或正在接收模型输出 |
182
- | ⚙️ | 处理中;工具结果已返回,Claude 正在继续处理 |
183
- | 🔧 | 工具调用中;可用时会显示工具名 |
184
- | 🚀 | fast mode |
185
- | ⚡️ | 上下文窗口占用 |
186
- | 💾 | prompt cache 使用情况 |
187
- | 🎯 | output style |
188
- | 📊 | Hour / Week 订阅配额 |
189
- | 🌑 🌒 🌓 🌔 🌕 | 配额占用档位 |
190
- | ⏳ | 距离当前配额窗口重置的时间 |
191
- | 📁 | 当前目录 |
192
- | 🌿 | git 分支 |
193
- | ✓ ● ⚠ | git 干净 / 有未提交变更 / 有冲突 |
194
- | 🌲 | worktree 名,显示在 git 段内 |
195
- | 🏷️ | 会话名 |
196
- | ⏱️ | 会话耗时 |
197
- | 💰 | 会话成本 |
198
- | 💩 | Claude Code 版本 |
199
- | ↑latest | 检测到更新的 Claude Code 版本 |
200
-
201
- ## 颜色语义
202
-
203
- | 颜色 | 含义 |
204
- |---|---|
205
- | 亮绿 | 空闲/健康状态、fast、缓存、新增、git 干净标记、git 领先/outgoing/push 计数 |
206
- | 黄色 | 需要注意:暂停状态、effort、配额重置时间、成本、警戒阈值 |
207
- | 亮红 | 风险或负向:危险阈值、冲突、删除、版本更新提示 |
208
- | 蓝色 | Git modified/dirty 状态、落后/incoming/pull 计数 |
209
- | 青色 / 白色 | 中性运行与项目信息:模型、输出风格、会话耗时、git 分支 |
210
- | 品红 | 当前上下文与会话身份:上下文窗口、会话名 |
211
-
212
- status 图标来自 transcript 尾部推断,只代表 Claude Code 触发 statusline 刷新时的近似状态,不是实时事件流。
213
- 如果正在执行时按 Esc 取消,ccglance 会在 Claude Code 下一次重绘 statusline 时更新;transcript 里的中断标记会显示为暂停。
140
+ **完整参考** —— 每个段的 stdin 来源、所有图标含义、配额月相档位、会话状态图标与颜色语义 ——
141
+ 见 **[docs/segments.zh-CN.md](./docs/segments.zh-CN.md)**。
214
142
 
215
143
  ## 原理
216
144
 
@@ -225,62 +153,16 @@ transcript 尾部读取,以及渲染后的后台版本检查。
225
153
 
226
154
  ## 开发
227
155
 
228
- ### 源码构建
156
+ 源码构建、测试、基准、代码结构、贡献范式与 git 缓存内部细节见
157
+ **[docs/development.zh-CN.md](./docs/development.zh-CN.md)**。快速开始:
229
158
 
230
159
  ```bash
231
160
  git clone https://github.com/CxMYu/CcGlanceLine.git
232
161
  cd CcGlanceLine
233
- npm install # 安装 devDeps,并执行 prepare -> build
234
-
235
- npm run build # 编译 src/ → dist/
236
- npm run typecheck # tsc --noEmit(strict)
237
- npm test # 构建 + node:test fixtures/snapshots/smoke
238
- npm run benchmark # 构建 + 启动耗时基准
239
- ccglance preview # 预览全局/软链命令
240
-
241
- # 用样例 stdin 冒烟测试:
242
- printf '%s' '{"model":{"display_name":"Claude Opus 4.8 (1M context)","id":"claude-opus-4-8[1m]"}}' | node dist/cli.js
162
+ npm install # devDeps + prepare 构建
163
+ npm test # 构建 + node:test
243
164
  ```
244
165
 
245
- 本地试用建议构建后执行 `npm link`,然后在 Claude Code 里配置 `"command": "ccglance"`。不做全局链接时,直接配置 `node /绝对路径/ccglance/dist/cli.js`。
246
-
247
- ### 验证
248
-
249
- - `test/fixtures/` 放订阅、API 风格、字段缺失、高上下文占用等 stdin 样例。
250
- - `test/snapshots/` 固定 ANSI 彩色渲染结果,图标、间距、颜色、换行变化都必须是有意修改。
251
- - `test/*.test.js` 使用 Node 内置 `node:test`,不额外引入运行时测试框架。
252
- - `bench/latency.js` 会同时测空 Node 基线、无 git、订阅+transcript、git warm cache、
253
- git cold fallback。Windows 上空 Node 冷启动通常占大头,判断 ccglance 成本时应看相对基线的增量。
254
-
255
- ### Agent 构建范式
256
-
257
- - `src/` 是唯一源码;不要手改 `dist/`,用 `npm run build` 重新生成。
258
- - 保持固定内置风格:不要加用户配置读取、外部样式文件、运行时样式发现。
259
- - 保持运行时零依赖;新增依赖只能是构建期依赖,并说明必要性。
260
- - 改代码后执行 `npm run typecheck`、`npm run build`、`ccglance preview`。
261
- - 修改图标或间距时,检查去掉 ANSI 后的 preview,并用至少一个合成 stdin 覆盖被改的 segment。
262
-
263
- ### 代码结构
264
-
265
- ```text
266
- src/
267
- cli.ts # 命令入口:preview / statusLine stdin
268
- defaults/ # 固定内置风格与显示顺序
269
- readers/ # stdin、transcript 尾读、终端宽度
270
- render/ # 颜色、图标、布局、最终渲染
271
- segments/ # 每个显示项的渲染逻辑
272
- runtime/ # git、Claude Code 版本缓存等运行时能力
273
- types/ # Claude Code stdin 与渲染类型
274
- utils/ # 格式化、显示宽度计算
275
- test/
276
- fixtures/ # 代表性的 Claude Code stdin 和 transcript 数据
277
- snapshots/ # 固定渲染输出基准
278
- bench/
279
- latency.js # 启动耗时与缓存路径基准
280
- ```
281
-
282
- 发布到 npm 的只有编译后的 `dist/`;`npm run build` 会先清空 `dist` 再编译,避免旧平铺产物混入包里。
283
-
284
166
  ## 缓存文件
285
167
 
286
168
  `ccglance` 只落盘可丢弃的运行缓存:git 状态、transcript 派生状态、Claude Code 最新版本缓存。
@@ -298,19 +180,8 @@ bench/
298
180
  若设置了 `CLAUDE_CONFIG_DIR` 改变 Claude Code 配置目录,ccglance 的缓存会跟着落到该目录下。
299
181
  整个 `ccglance/` 目录随时可安全删除 —— 下次渲染会自动重建。
300
182
 
301
- git 缓存逻辑:
302
-
303
- - 缓存 key 使用 Git worktree 根目录,同一仓库里的多个 Claude Code 终端共享一份 git 缓存。
304
- - 分支名优先使用 Claude Code stdin 里的 `worktree.branch`;没有该字段时,每次渲染都会从
305
- `.git/HEAD` 快速读取,所以普通切换分支也会立即显示。
306
- - dirty/冲突和 ahead/behind 细节使用缓存;20 分钟内且仍属于当前分支的缓存会直接返回。
307
- - 本地状态(`✓` / `●` / `⚠`)和上游状态(`↑领先` / `↓落后`)来自同一次
308
- `git status --porcelain=v2 --branch` 缓存快照,所以 TTL 相同。如果本地和远程状态同时存在,
309
- 会一起显示,例如 `main ● ↑1 ↓1`。
310
- - 缓存过期、无缓存或分支变化时仍立即渲染:用 `.git/HEAD` 快速只显示分支,再后台刷新 `git status`。
311
- - 刷新使用独占 `.refresh` 标记,写入使用临时文件 rename,多个终端并发不会写坏缓存。
312
- - 没有心跳,也没有常驻 watcher。刷新是懒触发:Claude Code 重绘 statusline 时启动 ccglance,
313
- ccglance 检查缓存年龄,只有过期时才启动 detached 后台刷新进程。
183
+ git 缓存逻辑(缓存 key、`HEAD` 兜底、20 分钟 TTL、detached 刷新、原子写)见
184
+ [docs/development.zh-CN.md](./docs/development.zh-CN.md#git-缓存内部细节)。
314
185
 
315
186
  ## 相关项目
316
187
 
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@cxmyu/ccglance",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "A fast, zero-dependency, multi-line status line for Claude Code — model, effort, context, cache, git and session, all at a glance.",
5
5
  "bin": {
6
- "ccglance": "./dist/cli.js"
6
+ "ccglance": "dist/cli.js"
7
7
  },
8
8
  "main": "./dist/cli.js",
9
9
  "exports": {