Skip to content
This repository was archived by the owner on Jul 30, 2026. It is now read-only.

feat(zcode): port ZCode support and sync version - #79

Merged
makoMakoGo merged 9 commits into
personal/local-clientsfrom
port/upstream-2026-06-25
Jun 25, 2026
Merged

feat(zcode): port ZCode support and sync version#79
makoMakoGo merged 9 commits into
personal/local-clientsfrom
port/upstream-2026-06-25

Conversation

@makoMakoGo

@makoMakoGo makoMakoGo commented Jun 25, 2026

Copy link
Copy Markdown
Owner

Summary

  • Port ZCode local session support as a branch-native parser, adapter, catalog entry, CLI/TUI client option, generated frontend registry entry, and minimal README documentation.
  • Preserve Usage tab status messages during auto-refresh so background usage fetches do not overwrite current user-facing status text.
  • Sync release manifests directly to 4.0.3, collapsing upstream 4.0.0 through 4.0.3 version bump commits into one local bump.
  • Record the porting decision in docs/upstream/2026-06-25.md; Codex login changes are intentionally skipped.

Upstream References

  • ZCode support: 640e97b4731e740d9f79580eb9c0e74349f07062
  • ZCode empty-string usage subset: f7a124df69d877cdfb1620a2c82805ac2ad2aeb1
  • Usage auto-refresh status subset: 38202b3399698d080ea4c56eac3560c494ebf8bb
  • Version bumps collapsed to 4.0.3: 4efba615177e7d22c750265d344113d5d2ede9a8, 4236758661417a00e550e30f36b4385a979421a3, 7c1c7ba36a136c0311e7d39c6828c2b1c9a7f5c1, 4062d4d721d6ce13dcb7540f7c145903f66c3d73

Verification

  • cargo fmt --all
  • bun scripts/generate-client-registry.ts --check
  • cargo test -p tokscale-core
  • cargo test -p tokscale-cli
  • bun run --cwd packages/frontend test
  • bun run build:cli

Local Build and RSS Smoke

  • Built current head 36ea09f2 with cargo build --release -p tokscale-cli; release binary reports tokscale 4.0.3.
  • Replaced local ~/.local/bin/tokscale with the current-head release binary and verified tokscale --version plus tokscale --no-spinner --json --light.
  • RSS baseline is the previously installed local tokscale 3.1.3; each value below is the median of 3 runs.
Scenario Local 3.1.3 Current head 4.0.3 Delta
Full report CLI (--no-spinner --json --light) 50,472 KB / 49.3 MB 51,492 KB / 50.3 MB +1,020 KB / +2.02%
clients CLI 365,412 KB / 356.8 MB 369,516 KB / 360.9 MB +4,104 KB / +1.12%
TUI idle 8s (tokscale tui in a pseudo-tty) 12,640 KB / 12.3 MB 10,080 KB / 9.8 MB -2,560 KB / -20.25%

No RSS regression was observed in the local smoke measurements. TUI exits with timeout status 124 in this measurement because it is a persistent interactive view.


Summary by cubic

Adds ZCode local session support and improves Usage tab refresh with independent clocks and status preservation. Also fixes ZCode token accounting and syncs the workspace and @tokscale/cli to 4.0.3.

  • New Features

    • ZCode local client: parses ~/.zcode/projects/**/*.jsonl via a native parser; added to the catalog, frontend registry, and CLI/TUI (zcode, hotkey q). Preserves raw model IDs, uses an unknown-model fallback, carries forward a requested model until the assistant reports one, and estimates fallback tokens from text content.
  • Bug Fixes

    • Usage tab auto-refresh: separate clocks for subscription usage vs local reports; background fetch runs in preserve-status mode and only polls on the Usage tab, with overdue checks when switching tabs. Manual refreshes take precedence and show their result even if an auto-refresh is in flight.
    • ZCode token accounting: boolean and numeric content now contributes to estimated tokens; prompt_tokens_details.cached_tokens is treated as cache_read and subtracted from prompt_tokens, and flat cache-read fields are merged and clamped to prompt_tokens to avoid double-counting.

Written for commit 36ea09f. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • 新功能

    • 新增对 ZCode 的支持,包含本地会话识别、导入解析、前端筛选与文档说明。
    • 前端与命令行客户端列表已更新,可识别并展示 ZCode。
  • 优化

    • 改进 TUI 自动刷新与用量获取行为,减少切换页面时的状态覆盖与重复刷新问题。
  • 版本更新

    • 发布版本统一升级到 4.0.3

Ported from upstream 640e97b4731e740d9f79580eb9c0e74349f07062.

Includes the ZCode usage parsing subset from upstream f7a124df69d877cdfb1620a2c82805ac2ad2aeb1 without the Codex login workflow.
Ported from upstream 38202b3399698d080ea4c56eac3560c494ebf8bb.
Collapses upstream release bump commits 4efba615177e7d22c750265d344113d5d2ede9a8, 4236758661417a00e550e30f36b4385a979421a3, 7c1c7ba36a136c0311e7d39c6828c2b1c9a7f5c1, and 4062d4d721d6ce13dcb7540f7c145903f66c3d73.
@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

PR 新增 ZCode 的会话解析、本地客户端/适配器注册、客户端目录/前端/CLI 暴露、README 与上游文档同步,以及各包版本升级到 4.0.3;同时调整 TUI 使用页的自动刷新和状态保留逻辑。

Changes

ZCode 支持与版本同步

Layer / File(s) Summary
解析器契约和 JSONL 解析
crates/tokscale-core/src/message_cache.rs, crates/tokscale-core/src/sessions/mod.rs, crates/tokscale-core/src/sessions/zcode.rs
ParserId 增加 Zcodesessions::zcode 导出解析器,并新增 ZCode JSONL 结构、解析流程、辅助函数和单测。
本地发现和适配器接入
crates/tokscale-core/src/local_clients.rs, crates/tokscale-core/src/adapters/mod.rs, crates/tokscale-core/src/adapters/file.rs
LOCAL_CLIENTSLOCAL_SOURCE_ADAPTERSZCODE_ADAPTER 接入 ZCode,本地扫描与 discover/fold 测试同步增加。
客户端目录和 CLI/TUI 暴露
crates/tokscale-core/client-catalog.json, packages/frontend/src/lib/clientRegistry.generated.ts, crates/tokscale-cli/src/main.rs, crates/tokscale-cli/src/tui/data/mod.rs
客户端目录、前端注册表和 CLI/TUI 断言都加入了 ZCode 条目、显示名、热键与解析映射。
版本同步
Cargo.toml, packages/cli/package.json, packages/cli-*/package.json, packages/tokscale/package.json
workspace、CLI 包和各平台二进制包的版本号都更新为 4.0.3
README 和上游说明
README*.md, docs/upstream/2026-06-25.md
四份 README 和上游归档补充了 ZCode 支持、来源筛选、Windows 路径与端口记录。

Usage 自动刷新

Layer / File(s) Summary
自动刷新时钟
crates/tokscale-cli/src/tui/app.rs
App 新增 usage 页刷新时钟和保留状态标记,切换 tab、开启自动刷新、手动刷新与 usage 手动抓取都会重置对应时钟,并按当前页分流自动刷新判断。
用量抓取状态保留
crates/tokscale-cli/src/tui/app.rs
订阅用量抓取增加保留状态的调用路径,on_tick() 轮询结果时按保留标记决定是否覆盖状态提示,并补充相关测试。

Sequence Diagram(s)

sequenceDiagram
  participant App
  participant fetch_subscription_usage_with_status
  participant begin_subscription_usage_fetch
  participant usage_rx
  App->>fetch_subscription_usage_with_status: fetch_subscription_usage_with_status(preserve_status)
  fetch_subscription_usage_with_status->>begin_subscription_usage_fetch: start usage fetch
  begin_subscription_usage_fetch-->>App: usage_rx
  App->>usage_rx: poll result on tick
  usage_rx-->>App: success / failure / disconnect
  App->>App: update cache and status_message
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Possibly related PRs

  • makoMakoGo/tokscale#78: 同样修改了 ParserId / parser-version 缓存相关代码,和本次新增 ParserId::Zcode 共享同一持久化标识路径。

Poem

我蹦过草堆看 ZCode,
JSONL 亮晶晶像露珠。
4.0.3 的铃铛叮当响,
用量不乱,状态也稳住。
兔尾一甩,春天开跑啦 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 62.30% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed 标题准确概括了本次变更的两项核心内容:引入 ZCode 支持并同步版本号。
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch port/upstream-2026-06-25

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@makoMakoGo
makoMakoGo marked this pull request as ready for review June 25, 2026 12:41
@makoMakoGo

Copy link
Copy Markdown
Owner Author

/juya review

@codspeed-hq

codspeed-hq Bot commented Jun 25, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 18 untouched benchmarks


Comparing port/upstream-2026-06-25 (36ea09f) with personal/local-clients (5e5bf54)1

Open in CodSpeed

Footnotes

  1. No successful run was found on personal/local-clients (53a89b6) during the generation of this report, so 5e5bf54 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@juya-review-bot juya-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OpenCodeReview found 3 issue(s).

Comment thread crates/tokscale-cli/src/tui/app.rs
Comment thread crates/tokscale-core/src/sessions/zcode.rs Outdated
Comment thread crates/tokscale-core/src/sessions/zcode.rs Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/tokscale-cli/src/tui/app.rs`:
- Around line 888-894: The in-flight usage fetch handling in
fetch_subscription_usage_with_status currently only sets
usage_fetch_preserve_status when preserve_status is true, so a manual fetch
cannot override an earlier preserved-status fetch. Update this early-return path
to let a non-preserve request clear usage_fetch_preserve_status when
usage_rx.is_some(), so manual u/r fetches can replace auto-refresh behavior and
allow the completion status to display normally.

In `@crates/tokscale-core/src/sessions/zcode.rs`:
- Around line 190-198: The content_chars helper is currently measuring JSON
serialization length instead of the actual message text length, which inflates
token estimates for strings, arrays, and objects. Update content_chars in
zcode.rs to recursively walk serde_json::Value and sum only real text content
(ignoring quotes, keys, and structural characters), and then tighten the related
tests around the fallback estimation to assert the exact expected value rather
than only checking for a positive result.
- Around line 106-107: The parsing logic in `zcode.rs` is normalizing
`entry.model` too early by passing it through `canonicalize_model`, which causes
`UnifiedMessage.model_id` to lose the original transcript value. Update the
`model_id` assignment in the transcript parsing path to preserve the raw model
string, and restrict normalization to display/grouping code only; then adjust
the related assertions in the affected parsing/test sections so they expect the
original `model_id` rather than a lowercased one.

In `@docs/upstream/2026-06-25.md`:
- Line 9: Three fenced code blocks in the markdown document are missing language
identifiers, which will keep triggering markdownlint MD040. Update each affected
fenced block in the document to include a consistent language tag such as text,
and apply the same fix to the other referenced fenced blocks so the markdown
style check passes without noise.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8a09d2c4-e6a3-4085-990b-2a0f29c41237

📥 Commits

Reviewing files that changed from the base of the PR and between 53a89b6 and fb9d57c.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (27)
  • Cargo.toml
  • README.ja.md
  • README.ko.md
  • README.md
  • README.zh-cn.md
  • crates/tokscale-cli/src/main.rs
  • crates/tokscale-cli/src/tui/app.rs
  • crates/tokscale-cli/src/tui/data/mod.rs
  • crates/tokscale-core/client-catalog.json
  • crates/tokscale-core/src/adapters/file.rs
  • crates/tokscale-core/src/adapters/mod.rs
  • crates/tokscale-core/src/local_clients.rs
  • crates/tokscale-core/src/message_cache.rs
  • crates/tokscale-core/src/sessions/mod.rs
  • crates/tokscale-core/src/sessions/zcode.rs
  • docs/upstream/2026-06-25.md
  • packages/cli-darwin-arm64/package.json
  • packages/cli-darwin-x64/package.json
  • packages/cli-linux-arm64-gnu/package.json
  • packages/cli-linux-arm64-musl/package.json
  • packages/cli-linux-x64-gnu/package.json
  • packages/cli-linux-x64-musl/package.json
  • packages/cli-win32-arm64-msvc/package.json
  • packages/cli-win32-x64-msvc/package.json
  • packages/cli/package.json
  • packages/frontend/src/lib/clientRegistry.generated.ts
  • packages/tokscale/package.json

Comment thread crates/tokscale-cli/src/tui/app.rs
Comment thread crates/tokscale-core/src/sessions/zcode.rs Outdated
Comment thread crates/tokscale-core/src/sessions/zcode.rs Outdated
Comment thread docs/upstream/2026-06-25.md Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 issues found across 28 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread crates/tokscale-cli/src/tui/app.rs Outdated
Comment thread crates/tokscale-core/src/sessions/zcode.rs Outdated
Comment thread crates/tokscale-core/src/sessions/zcode.rs Outdated
Comment thread crates/tokscale-core/src/sessions/zcode.rs Outdated
Keep the preserve-status mode attached to the in-flight usage fetch so auto-refresh cannot hide a manual fetch result.

Use an explicit unknown ZCode model fallback, and cover the requested-model carry-forward behavior with a parser test.
Let manual usage refreshes request visible completion status for an in-flight auto-refresh fetch.

Preserve raw ZCode model IDs and estimate fallback tokens from text content instead of JSON encoding length.

Add language tags to the upstream port manifest code fences.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 3 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread crates/tokscale-core/src/sessions/zcode.rs Outdated
Treat boolean and numeric ZCode content as fallback text instead of empty content, so non-string assistant messages still emit estimated usage.
Parse Z.AI prompt_tokens_details.cached_tokens as cache_read and subtract it from prompt_tokens for ordinary input accounting.

Track subscription usage and local report auto-refresh clocks independently, including overdue checks when switching tabs.
Compute an effective cache_read value before splitting Z.AI prompt_tokens, then subtract and report that same value so flat cache fields do not double-count prompt tokens.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
crates/tokscale-cli/src/tui/app.rs (1)

713-725: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

断连时也要清空旧的 Usage 数据和缓存。

Line 713 的 worker 断连分支只记录错误,但保留了旧的 subscription_usage 和磁盘缓存;下一帧/下次启动可能继续展示过期用量。这里应与空结果/错误结果分支一致清空数据与缓存。

建议修复
                 Err(std::sync::mpsc::TryRecvError::Disconnected) => {
                     let preserve_status = self.usage_fetch_preserve_status;
                     self.usage_fetch_preserve_status = false;
                     self.usage_rx = None;
+                    self.subscription_usage.clear();
+                    crate::commands::usage::clear_cache();
                     self.subscription_usage_errors =
                         vec![crate::commands::usage::UsageProviderError {
                             provider: "unknown".to_string(),
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/tokscale-cli/src/tui/app.rs` around lines 713 - 725, The
disconnected-worker branch in app.rs only sets an error and status but leaves
stale usage state behind. Update the TryRecvError::Disconnected handling in the
app state update path to match the empty/error-result branches by clearing the
current subscription_usage data and any persisted usage cache, in addition to
resetting usage_rx and recording the UsageProviderError. Use the existing
usage_fetch_preserve_status flow in app::App to keep the status behavior
unchanged while ensuring no outdated usage is shown on the next frame or after
restart.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@crates/tokscale-cli/src/tui/app.rs`:
- Around line 713-725: The disconnected-worker branch in app.rs only sets an
error and status but leaves stale usage state behind. Update the
TryRecvError::Disconnected handling in the app state update path to match the
empty/error-result branches by clearing the current subscription_usage data and
any persisted usage cache, in addition to resetting usage_rx and recording the
UsageProviderError. Use the existing usage_fetch_preserve_status flow in
app::App to keep the status behavior unchanged while ensuring no outdated usage
is shown on the next frame or after restart.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 591c72e8-a062-49b8-9cae-918065909989

📥 Commits

Reviewing files that changed from the base of the PR and between fb9d57c and 36ea09f.

📒 Files selected for processing (3)
  • crates/tokscale-cli/src/tui/app.rs
  • crates/tokscale-core/src/sessions/zcode.rs
  • docs/upstream/2026-06-25.md
✅ Files skipped from review due to trivial changes (1)
  • docs/upstream/2026-06-25.md

@makoMakoGo
makoMakoGo merged commit 366d21b into personal/local-clients Jun 25, 2026
12 checks passed
@makoMakoGo
makoMakoGo deleted the port/upstream-2026-06-25 branch June 25, 2026 14:33
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant