fix(claude): restore workspace paths from project metadata - #150
Conversation
WalkthroughClaude 会话现在收集 ChangesClaude 工作区解析
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
Possibly related issues
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
e7db9d0 to
1ea5fb8
Compare
|
/juya review |
There was a problem hiding this comment.
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
📒 Files selected for processing (3)
crates/tokscale-cli/tests/cli_tests.rscrates/tokscale-core/src/adapters/claude.rscrates/tokscale-core/src/sessions/claudecode.rs
There was a problem hiding this comment.
💡 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".
|
The outside-diff CodeRabbit finding is addressed in |
Summary
projectPath,cwdancestors, parent sessions, history, and project configuration against Claude's project-directory encodingRoot 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 usablecwd, 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
workspaceKeyand its final directory asworkspaceLabel. Recovery records can carry an authoritativeprojectPath. If verification fails, reports retain the original Claude slug instead of returningUnknown workspace, so the source remains identifiable without presenting the slug as a verified filesystem path.Validation
cargo test— 2218 passed, 5 ignoredcargo clippy -p tokscale-core --tests -- -D warningscargo build -p tokscale-clitokscale-recoveryresolved to/home/travis/tokscale-recovery, with zeroUnknown workspaceand zero Linux-home-...workspace labelsSummary by CodeRabbit
projectPath及相关路径信息进行更准确匹配。