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

feat(core): add local source adapters for tracer clients - #60

Merged
makoMakoGo merged 4 commits into
personal/local-clientsfrom
feat/c2-local-source-adapters
Jun 16, 2026
Merged

feat(core): add local source adapters for tracer clients#60
makoMakoGo merged 4 commits into
personal/local-clientsfrom
feat/c2-local-source-adapters

Conversation

@makoMakoGo

@makoMakoGo makoMakoGo commented Jun 16, 2026

Copy link
Copy Markdown
Owner

Refs #36

Summary

  • Add a local source adapter seam for local parse producers.
  • Move the C2 tracer clients behind adapters: Zed, Pi, and OMP.
  • Keep Pi and OMP as separate adapter modules even though they share the sessions::pi parser family.
  • Partition adapter clients from legacy scanner clients so adapter-only requests do not accidentally trigger an all-client legacy scan.
  • Include adapter-discovered source units in source digest computation, including Zed SQLite WAL sidecars.

Scope Boundary

  • This is the C2 tracer-client slice for Move local parse policy behind client adapters #36, not the full C3 migration of remaining local clients.
  • No fallback parser path, sharded cache, streaming aggregation, Codex adapter, or Claude adapter is added here.

Validation

  • rtk cargo fmt --check
  • rtk cargo check -p tokscale-core
  • rtk cargo clippy -p tokscale-core --all-targets
  • rtk cargo test -p tokscale-core adapters:: -- --nocapture
  • rtk cargo test -p tokscale-core pi -- --nocapture
  • rtk cargo test -p tokscale-core omp -- --nocapture
  • rtk cargo test -p tokscale-core --lib
  • rtk cargo test -p tokscale-cli tui::data
  • rtk cargo test

Summary by CodeRabbit

发布说明

  • 新功能

    • 建立本地源适配器框架,统一管理多个本地数据源的发现、解析和消息处理流程。
    • 新增缓存机制优化消息读写流程,提升数据发现效率。
  • 改进

    • 完善多个本地数据源(Zed、Pi、OMP)的支持,增强系统扩展性。

@sourcery-ai sourcery-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.

Sorry @makoMakoGo, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3b470b38-d6a4-4bba-9e61-b7249e1f9b9c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/c2-local-source-adapters

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 and usage tips.

@makoMakoGo
makoMakoGo marked this pull request as ready for review June 16, 2026 14:03

@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: 3

🧹 Nitpick comments (2)
crates/tokscale-core/src/adapters/zed.rs (1)

32-41: ⚖️ Poor tradeoff

macOS 回退路径硬编码可能导致维护负担。

第 36 行将 macOS Zed 数据库路径硬编码为 Library/Application Support/Zed/threads/threads.db。如果 Zed 未来更改目录结构,此处需要手动更新。

虽然 PR 目标中提到"保留 Zed 默认数据库回退顺序"表明这是有意为之,但建议考虑:

  • 添加注释说明此路径与 Zed 的哪个版本/配置相对应
  • 或将回退路径提取为可配置常量便于未来维护
🤖 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-core/src/adapters/zed.rs` around lines 32 - 41, The hardcoded
macOS Zed database path in the format string within the
adapter_discover::push_existing_file call lacks context about which Zed version
or configuration it corresponds to, which may cause maintenance issues if the
path structure changes. Add a comment above the hardcoded path string explaining
which Zed version or configuration this fallback path corresponds to, or
consider extracting the path pattern into a named constant at the module level
to make it easier to maintain and update in the future if Zed's directory
structure changes.
crates/tokscale-core/src/lib.rs (1)

1758-1769: ⚡ Quick win

给报表主解析路径补一个 adapter-only 回归测试。

新增 driver 测试覆盖了 parse_local_clients,但 graph/model/monthly/hourly 报表走的是这里的 parse_all_messages_with_pricing_with_env_strategy。建议加一个小测试:创建 Zed fixture 和 OpenCode decoy,调用 parse_all_messages_with_pricing(..., &["zed".to_string()], ...),断言只返回 Zed 消息,避免未来这里回退成 legacy full scan 或漏合并 adapter 产物。

🤖 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-core/src/lib.rs` around lines 1758 - 1769, Add a regression
test for the adapter-only filtering behavior used by the
`parse_all_messages_with_pricing_with_env_strategy` function (which is used by
graph/model/monthly/hourly reports). Create a test that sets up a fixture with
multiple adapters (Zed as the selected adapter and OpenCode as a decoy), then
call `parse_all_messages_with_pricing` with only the Zed adapter specified in
the adapter list, and assert that the returned messages contain only Zed-related
messages and no OpenCode messages. This test ensures the function correctly
filters by the specified adapters and prevents future regressions where the code
might fall back to legacy full scan behavior or fail to merge adapter products
correctly.
🤖 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-core/src/adapters/cache.rs`:
- Around line 69-87: When parsing results in empty messages, the current logic
does not invalidate stale cache entries because the invalidate_cache field only
checks the cacheable condition. When messages.is_empty() is true, set
invalidate_cache to true to ensure old cache entries are removed and not left as
stale entries causing repeated fingerprint misses. Update the invalidate_cache
field in the ParsedUnit struct to use a condition that includes
messages.is_empty() alongside the !cacheable check so that empty parse results
trigger cache invalidation just like non-cacheable results do. This issue also
applies at line range 101-105 where similar logic handles invalidate_cache
assignment and requires the same fix.

In `@crates/tokscale-core/src/lib.rs`:
- Around line 4472-4478: The test fixture setup hardcodes a Linux-specific Zed
default directory path ($HOME/.local/share/zed/threads) in the threads_dir,
threads_db, and wal_path setup without platform conditions, but the Zed adapter
branches by OS for the default path discovery, causing test failures on
macOS/Windows. Fix this at all three affected sites (lines 4472-4478, 7208-7213,
and 7289-7294) by either injecting threads_dir through
scanner_settings.extra_scan_paths, generating the directory conditionally based
on target_os, or adding #[cfg(target_os = "linux")] to gate the tests to Linux
only. Choose one approach and apply it consistently across all occurrences.

In `@docs/plans/2026-06-16-c2-adapter-seam.md`:
- Around line 3-4: Fix the Markdown syntax error where `PR` and `#59` are split
across lines at the start of the document. The current line break causes `#59`
to appear at the beginning of a line, which Markdown may interpret as incomplete
heading syntax. Reformat the Status line so that `PR `#59`` stays together on the
same line, preventing rendering issues and maintaining proper Markdown syntax.

---

Nitpick comments:
In `@crates/tokscale-core/src/adapters/zed.rs`:
- Around line 32-41: The hardcoded macOS Zed database path in the format string
within the adapter_discover::push_existing_file call lacks context about which
Zed version or configuration it corresponds to, which may cause maintenance
issues if the path structure changes. Add a comment above the hardcoded path
string explaining which Zed version or configuration this fallback path
corresponds to, or consider extracting the path pattern into a named constant at
the module level to make it easier to maintain and update in the future if Zed's
directory structure changes.

In `@crates/tokscale-core/src/lib.rs`:
- Around line 1758-1769: Add a regression test for the adapter-only filtering
behavior used by the `parse_all_messages_with_pricing_with_env_strategy`
function (which is used by graph/model/monthly/hourly reports). Create a test
that sets up a fixture with multiple adapters (Zed as the selected adapter and
OpenCode as a decoy), then call `parse_all_messages_with_pricing` with only the
Zed adapter specified in the adapter list, and assert that the returned messages
contain only Zed-related messages and no OpenCode messages. This test ensures
the function correctly filters by the specified adapters and prevents future
regressions where the code might fall back to legacy full scan behavior or fail
to merge adapter products correctly.
🪄 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: b82b1441-5be5-447e-97bc-692330dac9a2

📥 Commits

Reviewing files that changed from the base of the PR and between 494d95b and 93611db.

📒 Files selected for processing (8)
  • crates/tokscale-core/src/adapters/cache.rs
  • crates/tokscale-core/src/adapters/discover.rs
  • crates/tokscale-core/src/adapters/mod.rs
  • crates/tokscale-core/src/adapters/omp.rs
  • crates/tokscale-core/src/adapters/pi.rs
  • crates/tokscale-core/src/adapters/zed.rs
  • crates/tokscale-core/src/lib.rs
  • docs/plans/2026-06-16-c2-adapter-seam.md

Comment thread crates/tokscale-core/src/adapters/cache.rs
Comment thread crates/tokscale-core/src/lib.rs
Comment thread docs/plans/2026-06-16-c2-adapter-seam.md Outdated
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