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

fix(claude): restore workspace paths from project metadata - #150

Merged
makoMakoGo merged 2 commits into
personal/local-clientsfrom
agent/fix-claude-project-paths
Jul 16, 2026
Merged

fix(claude): restore workspace paths from project metadata#150
makoMakoGo merged 2 commits into
personal/local-clientsfrom
agent/fix-claude-project-paths

Conversation

@makoMakoGo

@makoMakoGo makoMakoGo commented Jul 15, 2026

Copy link
Copy Markdown
Owner

Summary

  • restore Claude workspace paths by forward-matching projectPath, cwd ancestors, parent sessions, history, and project configuration against Claude's project-directory encoding
  • resolve every transcript from its own authoritative candidates so lossy project keys and parallel parse order cannot cross-group workspaces
  • retain the original Claude project slug, with a non-fatal diagnostic, when path verification is unresolved or ambiguous
  • keep parent/external-dependent results out of the message cache unless the parent already participates in the source fingerprint

Root cause

Claude stores transcripts under a lossy encoded project directory name such as -home-travis-01-workspace-tokscale. The parser treated that directory name as workspace metadata whenever an individual record did not provide a directly usable cwd, so TUI and JSON reports exposed the encoded name instead of the real project path. The first resolver revision also cached a verified path by lossy project key, making colliding paths and parallel parse order capable of reusing the wrong workspace.

User impact

Workspace grouping now uses the full verified path as workspaceKey and its final directory as workspaceLabel. Recovery records can carry an authoritative projectPath. If verification fails, reports retain the original Claude slug instead of returning Unknown workspace, so the source remains identifiable without presenting the slug as a verified filesystem path.

Validation

  • cargo test — 2218 passed, 5 ignored
  • cargo clippy -p tokscale-core --tests -- -D warnings
  • cargo build -p tokscale-cli
  • local Claude scan over 4,006 JSONL files (~620 MB): tokscale-recovery resolved to /home/travis/tokscale-recovery, with zero Unknown workspace and zero Linux -home-... workspace labels

Summary by CodeRabbit

  • 改进
    • 优化 Claude Code 会话的项目工作区识别,支持使用 projectPath 及相关路径信息进行更准确匹配。
    • 改善多会话、父子会话及历史记录场景下的工作区归类,并缓存解析结果以保持一致性。
    • 无法明确判断工作区时保留用量数据,避免错误归类。
    • 更新相关测试,提升不同会话来源之间的工作区分组准确性。

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Claude 会话现在收集 projectPathcwd 项目候选,通过按 home_dir 缓存的解析器确定工作区,并将结果应用到消息。适配器注入共享解析器,相关解析、缓存和分组测试同步更新。

Changes

Claude 工作区解析

Layer / File(s) Summary
项目候选与解析器
crates/tokscale-core/src/sessions/claudecode.rs
新增 projectPath 字段、项目候选收集、项目键转换、外部候选读取及缓存解析逻辑。
会话解析应用工作区
crates/tokscale-core/src/sessions/claudecode.rs
解析入口支持注入 ClaudeProjectResolver,并依据解析结果更新或清空消息的工作区元数据。
适配器解析器注册
crates/tokscale-core/src/adapters/claude.rs
home_dir 管理解析器实例,在发现阶段重置并在解析阶段注入,同时递增记录健康版本。
工作区解析与分组测试
crates/tokscale-core/src/sessions/claudecode.rs, crates/tokscale-cli/tests/cli_tests.rs
新增和调整项目路径、祖先 cwd、外部候选、歧义、缓存、长路径键及跨工具分组测试。

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ClaudeAdapter
  participant ClaudeProjectResolver
  participant ClaudeSessionParser
  participant WorkspaceMessages
  ClaudeAdapter->>ClaudeProjectResolver: 按 home_dir 获取解析器
  ClaudeAdapter->>ClaudeSessionParser: 注入解析器并解析 JSONL
  ClaudeSessionParser->>ClaudeProjectResolver: 提交 projectPath、cwd 和父会话候选
  ClaudeProjectResolver-->>ClaudeSessionParser: 返回工作区解析结果
  ClaudeSessionParser->>WorkspaceMessages: 写入 workspace_key 和 workspace_label
Loading

Possibly related issues

Possibly related PRs

  • makoMakoGo/tokscale#30:同样修改 Claude 工作区身份推断及分组前的工作区字段应用逻辑。

Suggested reviewers: junhoyeo

Poem

小兔捧着路径跳,
projectPathcwd 相邀。
Resolver 缓存轻轻转,
工作区标签落满草。
分组测试月光照。

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Title check ✅ Passed 标题准确概括了此次修复:从 Claude 项目元数据恢复工作区路径。
✨ 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 agent/fix-claude-project-paths

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.

@codspeed-hq

codspeed-hq Bot commented Jul 15, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 27 untouched benchmarks


Comparing agent/fix-claude-project-paths (be5f3d0) with personal/local-clients (c284102)

Open in CodSpeed

@makoMakoGo
makoMakoGo force-pushed the agent/fix-claude-project-paths branch from e7db9d0 to 1ea5fb8 Compare July 15, 2026 18:38
@makoMakoGo
makoMakoGo marked this pull request as ready for review July 15, 2026 18:42
@makoMakoGo

Copy link
Copy Markdown
Owner Author

/juya review

@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-core/src/adapters/claude.rs
Comment thread crates/tokscale-core/src/adapters/claude.rs
Comment thread crates/tokscale-core/src/sessions/claudecode.rs

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

Caution

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

⚠️ Outside diff range comments (1)
crates/tokscale-core/src/sessions/claudecode.rs (1)

883-903: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

仅从通过校验的记录收集项目候选。

Line 883 在空 entry_type 校验前写入候选,因此明确被拒绝的记录仍可注入 projectPath/cwd,进而错误设置或清空所有有效消息的工作区。请将候选收集移到该校验之后。

🤖 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/sessions/claudecode.rs` around lines 883 - 903, Move
the project candidate collection in the Claude session parsing flow to after the
blank entry_type validation and rejection branch. Ensure
project_candidates.record and the entry_workspace calculation only run for
records that pass validation, while preserving the existing rejection handling
for malformed records.
🤖 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/sessions/claudecode.rs`:
- Around line 155-163: 调整 resolved 缓存命中逻辑,使其先评估当前 projectPath/cwd
的权威本地候选,再使用缓存结果,避免旧缓存覆盖后续匹配;在发生冲突时将缓存标记为 Ambiguous,或将候选身份纳入缓存键。为同一 resolver 解析
/home/travis/a-b 与 /home/travis/a/b 补充回归测试,确保两个路径不会因有损 project_key 被错误归组。

---

Outside diff comments:
In `@crates/tokscale-core/src/sessions/claudecode.rs`:
- Around line 883-903: Move the project candidate collection in the Claude
session parsing flow to after the blank entry_type validation and rejection
branch. Ensure project_candidates.record and the entry_workspace calculation
only run for records that pass validation, while preserving the existing
rejection handling for malformed records.
🪄 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: e287d593-f8e4-43da-abe7-9deefb358387

📥 Commits

Reviewing files that changed from the base of the PR and between c284102 and 1ea5fb8.

📒 Files selected for processing (3)
  • crates/tokscale-cli/tests/cli_tests.rs
  • crates/tokscale-core/src/adapters/claude.rs
  • crates/tokscale-core/src/sessions/claudecode.rs

Comment thread crates/tokscale-core/src/sessions/claudecode.rs Outdated

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1ea5fb851a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/tokscale-core/src/sessions/claudecode.rs
Comment thread crates/tokscale-core/src/sessions/claudecode.rs Outdated
Comment thread crates/tokscale-core/src/adapters/claude.rs
Comment thread crates/tokscale-core/src/sessions/claudecode.rs Outdated
Comment thread crates/tokscale-core/src/sessions/claudecode.rs Outdated
@makoMakoGo

Copy link
Copy Markdown
Owner Author

The outside-diff CodeRabbit finding is addressed in be5f3d0: projectPath/cwd candidates are now collected only after the record passes blank-type validation, in both transcript parsing and parent-candidate reads. Covered by test_blank_entry_type_cannot_supply_project_path.

@makoMakoGo
makoMakoGo merged commit d00d049 into personal/local-clients Jul 16, 2026
9 checks passed
@makoMakoGo
makoMakoGo deleted the agent/fix-claude-project-paths branch July 16, 2026 03:36
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