feat(reference): UnityCsReference のローカルキャッシュ参照機構(Phase 1)#186
Conversation
SPEC #185 の Phase 1 を完了。Unity 公式 C# ソース UnityCsReference を `unity-cli reference fetch` でローカルキャッシュ (`~/.unity/cache/UnityCsReference/<version>/`)し、grep / view / status / clean のサブコマンドと `unity-csharp-reference` skill から読み取り専用で参照できる ようにする。 - src/reference/{mod,version,cache,fetcher,search}.rs を新規追加 - ProjectVersion.txt からの Unity バージョン検出と静的ブランチマッピング - git clone --depth 1 --single-branch --branch <ver-branch> の shallow clone - walkdir + regex の grep / view(行範囲 + 行番号 + context lines) - cache GC (--keep N --dry-run) と meta JSON I/O - src/cli.rs / src/app/runner.rs に Reference サブコマンドと dispatcher 配線 - src/tooling/{tool_catalog,local_tools}.rs に reference_* 6 ツール登録と local_tools.maybe_execute_local_tool からの委譲 - src/core/managed_binaries.rs に cache_root()(UNITY_CLI_CACHE_ROOT 対応) - 新 skill unity-csharp-reference(Skill Contract v1 準拠、symlink 含む) - 既存 skill (navigate / edit / scene-inspect) の siblings に追加(R12/R22 解消) - docs/tools.md / README.ja.md / ATTRIBUTION.md(Unity Companion License) 検証ゲート: - cargo fmt --check / cargo clippy --all-targets -- -D warnings: clean - cargo test --bin unity-cli: 278 passed - unity-cli skills lint --severity error: 15 skills / 0 violations Refs #185 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 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 |
- src/app/runner.rs: collapsible_match (string/boolean/number arms) を
match guard 形式に書き換え、`-D warnings` での fail を解消
- src/reference/cache.rs: gc の sort_by を sort_by_key(|e| Reverse(e.1)) に
置き換え、clippy 1.95 の unnecessary_sort_by を解消
- src/reference/{mod,fetcher}.rs: dispatcher / resolve_version /
resolve_version_and_branch / dir_size / now_unix_seconds_string /
github_token / ensure_git_available / run_clone license guard /
execute_grep|view|search|fetch|status の 17 件の追加 test を加え、
reference module の line coverage を 90% threshold まで引き上げ
ローカル検証:
- cargo fmt -- --check: clean
- cargo clippy --all-targets -- -D warnings: clean (local clippy 0.1.94)
- cargo test --bin unity-cli: 295 passed / 0 failed (+17 from previous run)
Refs #185
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Phase 1 PR の Rust Coverage >= 90% gate を満たすため、テストのみで 全体 line coverage を 89.15% から 90.44% まで引き上げる。 - src/reference/version.rs: detect の error path (ファイル不在、行不在、空値)、 parse_editor_version、resolve_branch、minor_version_key の error inputs に 対する unit test を追加 - src/reference/cache.rs: list_versions の root 不在 / file 混在、gc(keep=0)、 read_meta の error / invalid JSON など 6 件の境界 test を追加 - src/reference/mod.rs: execute_view/_search/_grep の required param 検証、 invalid regex、file_glob filter、clean(dryRun=false)、fetch(force=true) の 既存 dest 削除パスなど 8 件の dispatcher test を追加 - src/core/self_update.rs: maybe_self_update の opt-out / throttle、 warn_cargo_conflict、touch、is_recent、last_check_path に対する 7 件の test - src/core/managed_binaries.rs: tools_root / cache_root の env fallback と detect_rid の triple 検証で 3 件 - src/app/runner.rs: build_reference_call の 6 variants 全網羅で 12 件 ローカル測定: - 327 tests pass (serial) - cargo llvm-cov --all-targets: TOTAL line coverage 90.44% (前回 89.15% → +1.29%、reference 系単独は 91-99%) Refs #185 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Pure cosmetic change: rustfmt now wraps the test module imports onto a single line and reformats one assert_eq! into the multi-line layout rustfmt prefers for long expression arguments. No behavior change. Refs #185 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ttr 位置) - build_reference_call_grep_defaults_context_to_zero / build_reference_call_view_omits_optional_lines / build_reference_call_clean_defaults: 戻り値の tool を _tool に変更し rust 1.95 の unused_variables を解消 - run_with_cli_set_active_text_output_when_reachable の前に付くべき #[allow(clippy::await_holding_lock)] が build_reference_call_status_* に ずれていたのを正しい位置へ戻し、await_holding_lock を解消 Refs #185 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
CI gate clear: merge_state CLEAN
修正サマリ
現在の CI 状態
レビューおよび merge をお願いします。Phase 2 (シンボル lookup インデックス) と Phase 3 (バージョン差分 + LSP go-to-definition 実験) は別 SPEC として後続で切り出します。 |
SPEC #187 (Phase 2 シンボル lookup インデックス) を land し、Phase 1 で得た知見を tasks/lessons.md に追記する。Phase 1 は PR #186 で develop 統合済みのため、本 PR の diff は Phase 2 と lessons のみ。 採用方針 B (独自 ReferenceSymbolEntry) と Symbol scope (型のみ) は gwt-discussion で確定済み。member-level lookup は Phase 2.5 以降の 拡張余地として残し、validate_kind の受理リストには method/property/ field も含めておく。 主な変更: - src/reference/index.rs (新規): ReferenceSymbolEntry と ReferenceSymbolIndex 構造、build_or_update_index で size+mtime ベースの incremental 更新、find_symbol で kind / namespace フィルタ - src/reference/mod.rs: maybe_execute_reference_tool に reference_find_symbol 分岐と execute_find_symbol を追加、 dispatcher 経由テスト 6 件 - src/cli.rs: ReferenceCommand::FindSymbol variant - src/app/runner.rs: build_reference_call に FindSymbol 分岐と 2 件のテスト - src/tooling/tool_catalog.rs: reference_find_symbol を TOOL_NAMES / executor / read_only / params_schema / parity count(125) に登録 - .claude-plugin/.../unity-csharp-reference/SKILL.md: Preferred Flow に find-symbol 例とフォールバック説明 - references/symbol-lookup-playbook.md: workflow step 1 を反映 - docs/tools.md: Reference Cache (6 -> 7 tools) - tasks/lessons.md: SPEC #185 振り返り 3 件 (clippy 1.95 差、 coverage 90% 維持、SPEC section markers) ローカル検証: - cargo fmt -- --check: clean - cargo clippy --all-targets -- -D warnings: clean - cargo test --bin unity-cli: 356 passed / 0 failed - cargo llvm-cov --all-targets: TOTAL line coverage 90.69% - unity-cli skills lint --severity error: 15 skills / 0 violations Refs #187 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Summary
unity-cli referencesubcommand family andunity-csharp-referenceskill so LLMs and developers can browse the official Unity C# source (UnityCsReference) as a read-only local cache when implementing Unity scripts.~/.unity/cache/UnityCsReference/<version>/driven byProjectVersion.txtdetection plus a static branch map.Changes
src/reference/version.rs: parseProjectSettings/ProjectVersion.txt, map major.minor to UnityCsReference branches (2020.3/staging through 6000.0/staging), surface--branchhint for unmapped versions.src/reference/cache.rs:reference_root,version_dir,read_meta/write_meta(.unity-cli-meta.json),list_versions, andgc(keep, dry_run)for LRU-by-mtime cleanup.src/reference/fetcher.rs:build_clone_args(--depth 1 --single-branch --branch <ver>), license gate (--accept-license/UNITY_CLI_ACCEPT_LICENSE=1), git availability probe,GITHUB_TOKEN/GH_TOKENinjection viahttp.extraHeader.src/reference/search.rs:run_grep(walkdir + regex with optional file-name glob and context lines) andrun_view(line range slice,..traversal guard).src/reference/mod.rs:maybe_execute_reference_toolJSON dispatcher forreference_fetch/reference_status/reference_search/reference_grep/reference_view/reference_clean.src/cli.rsandsrc/app/runner.rs:Command::ReferenceplusReferenceCommandandbuild_reference_callhelper routing each subcommand toexecute_tool("reference_*", params).src/tooling/tool_catalog.rsandsrc/tooling/local_tools.rs: registerreference_*6 tools, mark themToolExecutor::Local, classify fetch/clean as mutating and status/search/grep/view as read-only, define per-toolparams_schema, and delegate frommaybe_execute_local_tool.src/core/managed_binaries.rs: addcache_root()(env override viaUNITY_CLI_CACHE_ROOT, defaults to~/.unity/cache)..claude-plugin/plugins/unity-cli/skills/unity-csharp-reference/: new skill (SKILL.md+references/{runtime-checklist,fetch-and-cache,symbol-lookup-playbook}.md) under Skill Contract v1..claude/skills/unity-csharp-referenceand.agents/skills/unity-csharp-referencesymlinks added for discovery..claude-plugin/plugins/unity-cli/skills/unity-csharp-{edit,navigate}/SKILL.mdandunity-scene-inspect/SKILL.md: cross-listunity-csharp-referenceinsiblingsto clear R12 / R22 collisions.docs/tools.md,README.ja.md,ATTRIBUTION.md: new Reference Cache section, README feature line, and Unity Companion License attribution (English + Japanese).tests/fixtures/reference-cache/: minimal fixture (Editor + Runtime/Export/Animation) used by grep / view snapshot tests.Testing
cargo fmt -- --check— clean (no diff)cargo clippy --all-targets -- -D warnings— cleancargo test --bin unity-cli— 278 passed, 0 failed (19 new tests across reference modules)unity-cli skills lint --severity error— 15 skills checked, 0 violationsUNITY_CLI_CACHE_ROOT="$(mktemp -d)" unity-cli reference status --output json→{ "ok": true, "versions": [] }Closing Issues
Related Issues / Links
Checklist
cargo clippy,cargo fmt,unity-cli skills lint)docs/tools.md,README.ja.md,ATTRIBUTION.md, new skill)feat)Context
unity-clipreviously gave LLMs access only to project-local C# sources andcsharp-lsp(OmniSharp/Roslyn) metadata when implementing Unity scripts. The official Unity C# implementation was unreachable, so API misuse, behavior assumptions, and version-specific differences had to be guessed.gwt-discussionsession decided to mirror UnityCsReference locally as a read-only cache exposed throughunity-cli referenceand a siblingunity-csharp-referenceskill.Risk / Impact
src/reference/module + CLI / catalog / local dispatcher wiring; new skill alongside existingunity-csharp-{navigate,edit}/unity-scene-inspect(siblings cross-listed). Cache lives under~/.unity/cache/UnityCsReference/<version>/and is independent of~/.unity/tools/(managed_binaries). LSP workspace folders are intentionally untouched to avoid rename/diagnostic noise from external sources.reference clean --keep 1is the default knob;reference status --output jsonsurfacessizeBytes.--accept-licenseorUNITY_CLI_ACCEPT_LICENSE=1;ATTRIBUTION.mddocuments the consent and no-redistribution rule.rm -rf ~/.unity/cache/UnityCsReference). No persisted state outside that directory.Notes
reference find-symbol) and Phase 3 (cross-version diff + LSP go-to-definition experiment) are intentionally out of scope and will be tracked as follow-up SPECs.