Skip to content

fix(mimocode): scan ~/.local/share/mimocode, not /micode - #784

Merged
junhoyeo merged 2 commits into
junhoyeo:mainfrom
Javis603:fix/micode-data-dir
Jun 28, 2026
Merged

fix(mimocode): scan ~/.local/share/mimocode, not /micode#784
junhoyeo merged 2 commits into
junhoyeo:mainfrom
Javis603:fix/micode-data-dir

Conversation

@Javis603

@Javis603 Javis603 commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Summary

MiMo Code usage is never detected: the scanner looks in ~/.local/share/micode/, but MiMo Code stores its SQLite session db under ~/.local/share/mimocode/. Pointing the scanner at mimocode fixes detection. The client id stays micode — only the data directory changes.

Root cause

MiMo Code (XiaomiMiMo/MiMo-Code) resolves all of its XDG base dirs from a single app name:

// packages/shared/src/global.ts
const APP = "mimocode"
// ...
data: path.join(xdgData!, APP),   // -> ~/.local/share/mimocode

So sessions live at ~/.local/share/mimocode/mimocode.db (and config/state/cache under ~/.config/mimocode, ~/.local/state/mimocode). On Windows the same layout appears under %USERPROFILE%\.local\share\mimocode\.

The MiMo Code scanner added in #710 assumed ~/.local/share/micode/mimocode.db. Note this is internally inconsistent: the directory is micode but the filename matcher is mimocode.db. The string micode never appears anywhere in MiMo-Code's history (git log -S '"micode"' --all is empty) — it has been mimocode since the V0.1.0 open-source release on 2026-06-10. So no backward-compat fallback to micode is needed.

Evidence

The shipped tokscale 4.0.4 scans ~/.local/share/micode/ — which does not exist — so it finds nothing:

$ tokscale --json --client micode --group-by client,model --no-spinner
{"groupBy":"client,model","entries":[],"totalMessages":0,"totalCost":0.0, ...}

Built from this branch, it scans the real ~/.local/share/mimocode/ directory (no symlink, no env override) and finds the sessions. Filtered to the genuine native MiMo provider (mimo):

$ ./target/release/tokscale --json --client micode --group-by client,provider,model --no-spinner
{"client":"micode","provider":"mimo","model":"mimo-auto","input":116588,"output":5893,"messageCount":21,"cost":0.11}

Note: MiMo Code imports Claude Code sessions into its db

MiMo Code automatically imports Claude Code sessions (~/.claude/projects) into mimocode.db on first run — its claude-import service (CLI mimocode session import-claude; README: "Import from Claude Code"). The observed log shows service=claude-import scanned=113 imported=113 ... resynced=4.

So mimocode.db can hold sessions whose tokens are already attributed to the claude client, and scanning it will double-count them under micode. This PR only corrects the scan path; whether to exclude or dedup imported sessions is a separate decision, out of scope here.

Changes

  • clients.rsMiMoCode.relative: "micode""mimocode"
  • scanner.rs — scan dir {xdg_data}/micode{xdg_data}/mimocode (+ comment)
  • sessions/micode.rs — doc-comment path
  • lib.rs — the one test that seeds a fixture at .local/share/micode moves to .local/share/mimocode so it matches the scan path
  • README.md / README.ja.md / README.ko.md / README.zh-cn.md — the MiMo Code data-dir paths (clients table, platform-paths table, MiMo Code section)

Unchanged: the client id micode, the mimocode.db / mimocode-<channel>.db filename matcher, the parser, and every CLI/TUI/frontend id.

Verification

  • cargo fmt --all -- --check — clean
  • cargo clippy --locked --workspace --all-features -- -D warnings — clean
  • cargo test --workspace --all-features — 1950 passed, 0 failed (includes the updated micode path-fixture test)

Follow-up (intentionally not in this PR)

MiMo Code also honors MIMOCODE_HOME to relocate all four base dirs ($MIMOCODE_HOME/data). Honoring it could be a separate enhancement; this PR keeps the change minimal and focused on the default XDG path.

@vercel

vercel Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
tokscale Ignored Ignored Preview Jun 27, 2026 11:59pm

Request Review

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1 issue found across 8 files

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

Re-trigger cubic

Comment thread crates/tokscale-core/src/scanner.rs
@junhoyeo junhoyeo changed the title fix(micode): scan ~/.local/share/mimocode, not micode fix(mimocode): scan ~/.local/share/mimocode, not micode Jun 27, 2026
@junhoyeo junhoyeo changed the title fix(mimocode): scan ~/.local/share/mimocode, not micode fix(mimocode): scan ~/.local/share/mimocode, not /micode Jun 27, 2026
The scanner hardcoded the MiMo Code data root (XDG_DATA_HOME + "mimocode"),
duplicating the path that lives in `ClientId::MiMoCode` metadata and risking
drift the next time the directory changes. Resolve it via
`ClientId::MiMoCode.data().resolve_path_with_env_strategy(...)` like OpenCode,
Kimi, and the other XDG clients already do.

Behavior-preserving: for an XdgData root the helper yields the identical
`{XDG_DATA_HOME|~/.local/share}/mimocode` path. Verified by the existing
test_micode_authoritative_cost_is_not_repriced_on_first_parse_or_cache_hit.

Constraint: scan path must match clients.rs metadata to avoid silent non-detection
Confidence: high
Scope-risk: narrow

@junhoyeo junhoyeo left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks @Javis603 — excellent fix and an exemplary writeup. The root-cause evidence (the git log -S "micode" history check, before/after CLI output, and the honest scoped-out note about MiMo Code importing Claude Code sessions into mimocode.db) made this easy to verify. MiMo Code usage was silently undetected before this, so it is a real correctness fix.

I pushed one maintainer commit (26c5749b) addressing cubic's P2: the scanner now derives the data dir from ClientId::MiMoCode metadata instead of duplicating the path, so it stays in sync with clients.rs. fmt + clippy clean, mimocode detection test passing. 🚀

@junhoyeo
junhoyeo merged commit bc06d4e into junhoyeo:main Jun 28, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants