diff --git a/.codex/README.md b/.codex/README.md index ae55e100d1..6c8fcd7272 100644 --- a/.codex/README.md +++ b/.codex/README.md @@ -15,9 +15,9 @@ paths to committed config files. For CodeIndex work, dogfood the repo-built binary for code search: ```bash -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll search SymbolExtractor -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll symbols --lang csharp -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll inspect src/CodeIndex/Indexer/SymbolExtractor.cs +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll search SymbolExtractor --db .cdidx/codeindex.db +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll symbols --lang csharp --db .cdidx/codeindex.db +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll inspect src/CodeIndex/Indexer/SymbolExtractor.cs --db .cdidx/codeindex.db ``` The guard hooks block grep-like search escape hatches, global `cdidx`, and diff --git a/.codex/workflows/issue-fix.md b/.codex/workflows/issue-fix.md index 7d9e78fc01..2cb26aec76 100644 --- a/.codex/workflows/issue-fix.md +++ b/.codex/workflows/issue-fix.md @@ -21,7 +21,7 @@ Use this workflow for GitHub issue implementation tasks. 6. Comment in English on each in-scope issue that work has started on that branch. 7. Read required project guidance, including `SELF_IMPROVEMENT.md` and any files referenced by `AGENT_GUIDE.md`. -8. Check the local CodeIndex index first with `dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll status --check --json`. If it exits `0` with `index_matches_workspace: true`, keep the existing DB; otherwise refresh it using the documented project procedure. +8. Check the local CodeIndex index first with `dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll status --check --db .cdidx/codeindex.db --json`. The checked-in workspace manifest uses the root `.cdidx/codeindex.db` through `index_strategy: single`; do not create per-member databases. Always pass that explicit `--db` to dogfood index, query, MCP, LSP, and maintenance commands because data-directory and active-workspace overrides take precedence over CWD discovery. If the command exits `0` with `index_matches_workspace: true`, keep the existing DB; otherwise refresh it using the documented project procedure. Then run `dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll workspace status --check --json` and require the manifest view to be healthy too. 9. For code search, use only the locally built binary: ```bash diff --git a/AGENT_GUIDE.md b/AGENT_GUIDE.md index 5b9492d99b..e88608e7fa 100644 --- a/AGENT_GUIDE.md +++ b/AGENT_GUIDE.md @@ -40,17 +40,25 @@ dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll Examples: -- `dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll search SymbolExtractor` -- `dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll symbols --lang csharp` -- `dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll inspect src/CodeIndex/Indexer/SymbolExtractor.cs` +- `dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll search SymbolExtractor --db .cdidx/codeindex.db` +- `dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll symbols --lang csharp --db .cdidx/codeindex.db` +- `dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll inspect src/CodeIndex/Indexer/SymbolExtractor.cs --db .cdidx/codeindex.db` Before implementation, first check whether the local index already matches the current workspace: ```bash -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll status --check --json +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll status --check --db .cdidx/codeindex.db --json ``` -If the command exits `0` and reports `index_matches_workspace: true`, you may trust the existing `.cdidx/codeindex.db` without rebuilding it. If it exits with stale-index status or reports mismatched `workspace_check` counts, refresh the local index as documented by the project guidance. If the exact index-refresh command is documented elsewhere, use that documented command instead of inventing a new one. +The checked-in `cdidx.workspace.json` intentionally uses `index_strategy: single`. The canonical repository-wide database is the root `.cdidx/codeindex.db`; do not create or select `src/CodeIndex/.cdidx/codeindex.db` or `tests/CodeIndex.Tests/.cdidx/codeindex.db` for repository work. Always pass `--db .cdidx/codeindex.db` to repository dogfood CLI queries, MCP, LSP, and maintenance commands such as `optimize`, `vacuum`, and `db integrity`. Running from the repository root alone is insufficient because `CDIDX_DATA_DIR` and active-workspace settings take precedence over CWD discovery. + +If the root status command exits `0` and reports `index_matches_workspace: true`, you may trust the existing `.cdidx/codeindex.db` without rebuilding it. If it exits with stale-index status or reports mismatched `workspace_check` counts, refresh the local index as documented by the project guidance. If the exact index-refresh command is documented elsewhere, use that documented command instead of inventing a new one. After the root status is healthy, also verify the manifest view: + +```bash +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll workspace status --check --json +``` + +Both checks must be healthy. Under the `single` strategy, `workspace status` evaluates each declared member through the shared root database, while repository-root docs, scripts, workflows, and policy remain searchable because indexing always targets `.`. This rule applies to code search and repository understanding. It does not forbid Git commands, build tools, test runners, package managers, or small shell checks that are not being used to search implementation code. Enforcement of forbidden tools is provided separately by the Claude and Codex guard hooks. diff --git a/DEVELOPER_GUIDE.md b/DEVELOPER_GUIDE.md index 513b15246a..bec1384324 100644 --- a/DEVELOPER_GUIDE.md +++ b/DEVELOPER_GUIDE.md @@ -89,10 +89,10 @@ POSIX-only enforcement. Production `File.Delete`, `Directory.Delete`, and `File.Move` call sites are allowed only for owned CodeIndex state or caller-approved outputs. Re-run the audit with the local binary when changing these areas: ```bash -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll search File.Delete --path src/ --exclude-tests --exact-substring --count-by file --limit 80 -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll search Directory.Delete --path src/ --exclude-tests --exact-substring --count-by file --limit 80 -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll search File.Move --path src/ --exclude-tests --exact-substring --count-by file --limit 80 -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll search --recipe filesystem-mutation-boundaries --format count --limit 80 +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll search File.Delete --path src/ --exclude-tests --exact-substring --count-by file --limit 80 --db .cdidx/codeindex.db +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll search Directory.Delete --path src/ --exclude-tests --exact-substring --count-by file --limit 80 --db .cdidx/codeindex.db +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll search File.Move --path src/ --exclude-tests --exact-substring --count-by file --limit 80 --db .cdidx/codeindex.db +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll search --recipe filesystem-mutation-boundaries --format count --limit 80 --db .cdidx/codeindex.db ``` | Surface | Ownership and boundary policy | Cleanup or rollback policy | @@ -233,6 +233,13 @@ ownership boundaries so behavior changes remain reviewable and testable. `cdidx.workspace.json` and `.cdidx-workspace.json` declare monorepo members without adding a YAML dependency. Workspace manifests are capped at 64 KiB, 16 JSON nesting levels, 1024 members, 4096 characters per member path, and 255 characters for `default_db_name`. The supported schema is additive: `members` is an array of member paths that must be relative to and resolve under the manifest directory, `index_strategy` is `per_member` or `single` with unknown values rejected, `default_db_name` is a plain file name that overrides `codeindex.db`, and `shared_ignores` is reserved for shared ignore policy. Invalid `members` entries are rejected with bounded diagnostics, and valid entries are normalized and deduplicated with the workspace path casing policy before DB paths are materialized. `cdidx workspace list` and `cdidx workspace status` report member DB paths. `workspace status` also reports each member's project-directory and database existence as the unambiguous sibling fields `project_exists` and `db_exists`; the older `exists` field remains a compatibility alias for `project_exists`. Per-member `index_health` reports probe status and stable reason, a structured `repair_action`, schema compatibility, exact workspace freshness, timestamps, index completeness, and graph readiness. It probes at most 64 distinct existing member databases per invocation, reuses a probe when members share a database under the `single` strategy, and marks later members as `not_checked` with a top-level truncation summary. +This repository's checked-in manifest deliberately selects `index_strategy: single`. The canonical dogfood topology indexes the repository root into `.cdidx/codeindex.db`, which keeps source, tests, root documentation, scripts, workflows, and agent policy in one searchable database while `workspace status` reuses that database for every declared member. Repository dogfood CLI queries, MCP, LSP, and maintenance commands (`optimize`, `vacuum`, `db integrity`, and related previews) always pass `--db .cdidx/codeindex.db`; running from the root alone does not pin the database because `CDIDX_DATA_DIR` and active-workspace settings take precedence over CWD discovery. Repository validation runs the explicitly pinned `status --check --json` plus manifest-driven `workspace status --check --json`; neither workflow creates per-member databases. + +```bash +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll status --check --db .cdidx/codeindex.db --json +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll workspace status --check --json +``` + `member_health_summary` aggregates healthy, degraded, and missing members, reports the exit code that enforcement would use, and deduplicates recommended action codes. `cdidx workspace status --check` returns success `0` only when every required member is `ready`; it returns not-found `2` when the manifest is missing, the manifest has no members, or any required project/database is missing, and stale-index `5` for every other degraded aggregate (including stale, incomplete, incompatible, invalid, unavailable, or probe-limit-skipped members). Missing takes precedence over degraded in a mixed workspace. Without `--check`, `workspace status` remains informational and returns `0` after a successful report. Invalid manifest schema or safety failures remain usage exit `1` and, in JSON mode, are returned as a structured `workspace_manifest_invalid` error instead of falling through to the top-level crash handler. Repair commands are emitted as `name` plus `args[]`, not shell-quoted strings, so paths remain portable across Windows and POSIX shells. `cdidx workspace use ` writes an existing manifest member or `default` workspace to the per-user config directory and rejects missing manifest members. A directory name remains a shorthand when it identifies exactly one member; repeated directory names remain ambiguous. A manifest-relative path selects the exact normalized member, accepts either slash spelling, and stores the canonical forward-slash relative path in active workspace state. Manifest-member selections also persist `manifest_member: true`, so members named `default` or `env` remain distinguishable from the reserved non-manifest states. Active workspace names share the manifest member path's 4096-character bound. `cdidx workspace clear` (also available as `workspace deactivate`) removes that persisted selection instead of rebinding `default` to the current directory. When `CDIDX_ACTIVE_WORKSPACE` is set, clear reports that the environment override must be unset because it takes precedence over persisted state. Query DB resolution keeps existing precedence: explicit `--db`, then explicit `--data-dir` / `CDIDX_DATA_DIR`, then active workspace state, then ancestor/CWD discovery. @@ -3761,9 +3768,9 @@ Windows と明示的な SQLite file URI では、この POSIX 限定 enforcement 本番コードの `File.Delete`、`Directory.Delete`、`File.Move` 呼び出しは、CodeIndex が所有する状態、または caller が承認した出力に限って許可します。これらの領域を変更する場合は、ローカル binary で次の監査を再実行してください: ```bash -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll search File.Delete --path src/ --exclude-tests --exact-substring --count-by file --limit 80 -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll search Directory.Delete --path src/ --exclude-tests --exact-substring --count-by file --limit 80 -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll search File.Move --path src/ --exclude-tests --exact-substring --count-by file --limit 80 +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll search File.Delete --path src/ --exclude-tests --exact-substring --count-by file --limit 80 --db .cdidx/codeindex.db +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll search Directory.Delete --path src/ --exclude-tests --exact-substring --count-by file --limit 80 --db .cdidx/codeindex.db +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll search File.Move --path src/ --exclude-tests --exact-substring --count-by file --limit 80 --db .cdidx/codeindex.db ``` | surface | ownership / boundary policy | cleanup / rollback policy | @@ -3918,6 +3925,14 @@ graph readiness を報告します。project directory と database の存在有 1 回の実行で probe する既存の異なる member database は最大 64 個で、 `single` strategy で database が共有される場合は probe 結果を再利用し、それ以降の member は `not_checked` として top-level の truncation summary に反映します。 + +このリポジトリで追跡している manifest は、意図的に `index_strategy: single` を選択します。正規の dogfood topology はリポジトリルートを `.cdidx/codeindex.db` に index し、source、tests、ルートの documentation、scripts、workflows、agent policy を1つの検索可能な database に保ちながら、`workspace status` がすべての宣言済み member に同じ database を再利用します。リポジトリの dogfood では、CLI query、MCP / LSP、maintenance command(`optimize`、`vacuum`、`db integrity` と関連 preview)のすべてに `--db .cdidx/codeindex.db` を明示します。`CDIDX_DATA_DIR` と active workspace の設定は CWD discovery より優先されるため、リポジトリルートで実行するだけでは database を固定できません。リポジトリ検証では明示的に固定した `status --check --json` と manifest 駆動の `workspace status --check --json` の両方を実行し、per-member database は作成しません。 + +```bash +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll status --check --db .cdidx/codeindex.db --json +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll workspace status --check --json +``` + `member_health_summary` は healthy / degraded / missing member を集約し、enforcement 時の exit code と 重複排除した recommended action code を返します。`cdidx workspace status --check` はすべての required member が `ready` の場合だけ success `0`、manifest 不在、member 0件、required project / diff --git a/SELF_IMPROVEMENT.md b/SELF_IMPROVEMENT.md index 1f8f5c4245..50b236fb65 100644 --- a/SELF_IMPROVEMENT.md +++ b/SELF_IMPROVEMENT.md @@ -38,12 +38,13 @@ The loop is not just "suggest ideas". It is: - Keep **one task per commit**. - Before every commit, explicitly work through `.codex/workflows/precommit.md`. - Before every commit, review the authoritative [Search and Indexing Rules](AGENT_GUIDE.md#search-and-indexing-rules); strengthen `AGENT_GUIDE.md` or the relevant workflow if AI search behavior should change. -- After every commit, rebuild `cdidx` from the latest local source, run `dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll status --check --json`, and refresh `.cdidx/codeindex.db` with that freshly built binary only when the check does not report `index_matches_workspace: true`. -- Prefer the lightest truthful refresh mode: use `--files` only for known in-place edits or new files, use `--commits HEAD` after a normal commit because it tracks renames/deletes from git history, use `--changed-between ` after branch switches when both refs are known, and reserve `cdidx . --json` for full-workspace scans after history-moving operations or cases where repo-wide stale files must be purged. `cdidx . --json` is not a forced rebuild and may report `mode:"incremental"` while skipping unchanged files; if `status --check --json` still reports stale after that scan, escalate to `dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll index . --rebuild --yes --json`. +- After every commit, rebuild `cdidx` from the latest local source, run `dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll status --check --db .cdidx/codeindex.db --json`, and refresh `.cdidx/codeindex.db` with that freshly built binary only when the check does not report `index_matches_workspace: true`. +- The checked-in `cdidx.workspace.json` uses `index_strategy: single`, so the root `.cdidx/codeindex.db` is the only canonical dogfood database. Index `.` so source, tests, docs, scripts, workflows, and policy stay searchable; do not maintain redundant member databases. Always pass `--db .cdidx/codeindex.db` to dogfood CLI queries, MCP/LSP, and maintenance commands; starting from the repository root alone does not pin the DB because data-directory and active-workspace overrides take precedence. After the pinned root status is healthy, require `dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll workspace status --check --json` to be healthy too. +- Prefer the lightest truthful refresh mode: use `--files` only for known in-place edits or new files, use `--commits HEAD` after a normal commit because it tracks renames/deletes from git history, use `--changed-between ` after branch switches when both refs are known, and reserve `cdidx . --db .cdidx/codeindex.db --json` for full-workspace scans after history-moving operations or cases where repo-wide stale files must be purged. That full scan is not a forced rebuild and may report `mode:"incremental"` while skipping unchanged files; if the explicitly pinned `status --check --json` still reports stale after that scan, escalate to `dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll index . --rebuild --yes --db .cdidx/codeindex.db --json`. - Prefer the **locally built latest binary** (`dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll`) over an older globally installed `cdidx` whenever the repository code has changed. **Never fall back to a global `cdidx`** — the global version may have an older DB schema, missing query features, or stale extraction logic that silently produces wrong results. This is enforced at the Claude Code harness level via the repo-tracked `.claude/settings.json`, which denies the full set of shell code-search and file-discovery commands: `rg`, `grep`, `egrep`, `fgrep`, `zgrep`, `rgrep`, `ripgrep`, `ag`, `ack`, `ack-grep`, `git grep`, `find`, `locate`, `mlocate`, `mdfind`, and `cdidx`. Use the built-in Grep / Glob tools or the locally built binary instead. - Treat repo-tracked `.claude/settings.json`, `.claude/hooks/bash-guard.py`, `.codex/hooks.json`, and `.codex/hooks/bash_guard.py` as tool-specific guard adapters. Do not edit them during ordinary self-improvement work unless the task is explicitly about agent guard behavior. Shared Bash command policy lives in `.agent_harness/command_guard_core.py`; update that shared core for common policy and review both adapters only when tool-specific behavior changes. The current guard is deny-oriented: it is intentionally permissive for routine `dotnet`, `git`, `gh`, `codex exec`, `/tmp` work, and read-only shell inspection, while still blocking dangerous shell patterns and sensitive local read paths. - Respect the current local-privacy boundary in Claude Code: home-directory personal areas and credential-like files are intentionally read-denied by policy. Do not weaken those restrictions as a convenience workaround for self-improvement tasks; if the task genuinely requires changing the guard, treat that as the task itself and update docs accordingly. -- After `git switch`, re-index with the **locally built binary** using `dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll index . --changed-between --json` when the workflow has both the previous and current refs; this updates only the files changed between branches while still purging rename/delete old paths included by git. If the refs are not available, or after `git reset`, `git rebase`, `git commit --amend`, or `git merge`, use `dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll . --json` so stale files are purged against the current checkout. If the follow-up status check remains stale, run `dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll index . --rebuild --yes --json` instead of repeating `cdidx . --json`. +- After `git switch`, re-index with the **locally built binary** using `dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll index . --changed-between --db .cdidx/codeindex.db --json` when the workflow has both the previous and current refs; this updates only the files changed between branches while still purging rename/delete old paths included by git. If the refs are not available, or after `git reset`, `git rebase`, `git commit --amend`, or `git merge`, use `dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll . --db .cdidx/codeindex.db --json` so stale files are purged against the current checkout. If the follow-up status check remains stale, run `dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll index . --rebuild --yes --db .cdidx/codeindex.db --json` instead of repeating the full scan. - When searching and navigating code to investigate bugs, plan fixes, or verify changes, always use the **locally built binary** — not the globally installed version. This ensures query results reflect the latest extraction rules and DB schema from this branch. - If the **locally built binary** crashes, aborts unexpectedly, or exposes a new defect during this loop, do not silently work around it or fall back to an older/global binary. Notify the user with the concrete failure, explain that the self-improvement loop is now blocked or tainted by that defect, and propose fixing it as a separate task or as the next approved priority. - Treat the loop itself as ongoing regression coverage and light monkey testing. Do not limit yourself to only the safest or most standard workflows; actively exercise recent features, edge features, and less-traveled commands/options so the loop can indirectly surface crashes, bad assumptions, stale help text, and integration defects. @@ -100,7 +101,7 @@ Use the binary produced from the current commit, not an older global tool, so th Start with the exact workspace match check: ```bash -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll status --check --json +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll status --check --db .cdidx/codeindex.db --json ``` If it exits `0` and reports `index_matches_workspace: true`, keep the existing `.cdidx/codeindex.db`. Otherwise, refresh the index. @@ -112,18 +113,18 @@ Choose the one refresh mode that matches your situation: ```bash # During local in-place edits or new-file additions, refresh only the files you touched # Old paths from renames/deletes are NOT purged unless you also pass them explicitly -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll index . --files src/CodeIndex/Cli/QueryCommandRunner.cs tests/CodeIndex.Tests/QueryCommandRunnerTests.cs --json +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll index . --files src/CodeIndex/Cli/QueryCommandRunner.cs tests/CodeIndex.Tests/QueryCommandRunnerTests.cs --db .cdidx/codeindex.db --json # After a normal commit, prefer git-aware diff refresh because it sees renames/deletes commit_id=$(git rev-parse HEAD) -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll index . --commits "$commit_id" --json +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll index . --commits "$commit_id" --db .cdidx/codeindex.db --json # After a branch switch, prefer the before/after refs when your workflow has both -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll index . --changed-between --json +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll index . --changed-between --db .cdidx/codeindex.db --json # First sync on a checkout, after history-moving git operations, # or when branch-switch refs are unavailable -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll . --json +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll . --db .cdidx/codeindex.db --json ``` `--changed-between` reconciles the requested range with the persisted whole-workspace verification baseline. If that baseline is older or divergent, the local binary adds the missing baseline-to-current paths; if Git can no longer resolve it, follow the emitted fetch/full-scan guidance instead of substituting `--files`. @@ -131,7 +132,7 @@ dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll . --json If you prefer `dotnet run`, that is also acceptable: ```bash -dotnet run --project src/CodeIndex -- . --json +dotnet run --project src/CodeIndex -- . --db .cdidx/codeindex.db --json ``` ### 4. Explore the repo with cdidx itself @@ -143,18 +144,18 @@ Do not only exercise the obvious happy-path commands. Regularly touch newer feat If `status --json` reports `fold_ready: false` and you only need Unicode-aware `--exact` semantics on an older DB, prefer upgrading in place with: ```bash -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll backfill-fold --json +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll backfill-fold --db .cdidx/codeindex.db --json ``` -Use `cdidx . --json` as a full-workspace scan only when you need a fresh source scan, when history-moving git operations just happened, when branch-switch refs are unavailable, or when repo-wide stale-file purge matters more than speed. This path is not a forced rebuild: it may report `mode:"incremental"` and skip unchanged files. If `status --check --json` remains stale after that scan, run `dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll index . --rebuild --yes --json`. In the ordinary commit-to-commit loop, prefer `--commits` first; after branch switches with known refs, prefer `--changed-between`; and use `--files` only for in-place edits/new files where no old path needs purging. +Use `cdidx . --db .cdidx/codeindex.db --json` as a full-workspace scan only when you need a fresh source scan, when history-moving git operations just happened, when branch-switch refs are unavailable, or when repo-wide stale-file purge matters more than speed. This path is not a forced rebuild: it may report `mode:"incremental"` and skip unchanged files. If `status --check --db .cdidx/codeindex.db --json` remains stale after that scan, run `dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll index . --rebuild --yes --db .cdidx/codeindex.db --json`. In the ordinary commit-to-commit loop, prefer `--commits` first; after branch switches with known refs, prefer `--changed-between`; and use `--files` only for in-place edits/new files where no old path needs purging. Typical sequence: ```bash -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll status --json -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll map --json --limit 10 --path src/ --exclude-tests -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll inspect QueryCommandRunner --exclude-tests --limit 5 -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll search "AI" --path src/ --exclude-tests --snippet-lines 6 --json +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll status --db .cdidx/codeindex.db --json +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll map --db .cdidx/codeindex.db --json --limit 10 --path src/ --exclude-tests +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll inspect QueryCommandRunner --db .cdidx/codeindex.db --exclude-tests --limit 5 +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll search "AI" --db .cdidx/codeindex.db --path src/ --exclude-tests --snippet-lines 6 --json ``` Use `inspect` when you already have a likely symbol name. Use `search` for raw text or unsupported languages. Use `map` first when you need orientation. @@ -200,9 +201,9 @@ Examples: ```bash dotnet test -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll status --json -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll map --json --path src/ --exclude-tests -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll inspect ResolveGitCommonDir --json --exclude-tests --limit 5 +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll status --db .cdidx/codeindex.db --json +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll map --db .cdidx/codeindex.db --json --path src/ --exclude-tests +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll inspect ResolveGitCommonDir --db .cdidx/codeindex.db --json --exclude-tests --limit 5 ``` ### 8. Commit exactly one task @@ -232,14 +233,14 @@ dotnet build # Default post-commit path: refresh from the last commit's diff # This is safer than --files because git diff sees renames/deletes commit_id=$(git rev-parse HEAD) -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll index . --commits "$commit_id" --json +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll index . --commits "$commit_id" --db .cdidx/codeindex.db --json # Branch switch path when the before/after refs are known -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll index . --changed-between --json +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll index . --changed-between --db .cdidx/codeindex.db --json # Escalate to a full scan after git reset/rebase/amend/merge, # when branch-switch refs are unavailable, or whenever repo-wide stale purge is required -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll . --json +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll . --db .cdidx/codeindex.db --json ``` ### 10. Use the refreshed index to choose the next task @@ -370,12 +371,13 @@ Read `SELF_IMPROVEMENT.md`, inspect the current repo with cdidx itself, identify - **1案件1コミット** を守る。 - 毎コミット前に、`.codex/workflows/precommit.md` を明示的に確認する。 - 毎コミット前に、正本である [Search and Indexing Rules](AGENT_GUIDE.md#search-and-indexing-rules) を見直し、AIの検索行動を変えるべきなら `AGENT_GUIDE.md` または関連 workflow を強化する。 -- 毎コミット後に、ローカルソースの最新状態から `cdidx` を再ビルドし、`dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll status --check --json` を実行する。`index_matches_workspace: true` でなければ、その新しいバイナリで `.cdidx/codeindex.db` を更新する。 -- 更新モードは「正しさを保てる範囲で最も軽いもの」を優先する。`--files` は把握している in-place 編集や新規追加だけに使い、通常のコミット後は rename/delete も拾える `--commits HEAD` を使う。ブランチ切り替え後は前後の ref が分かるなら `--changed-between ` を使い、履歴を動かす操作や repo 全体で stale file を掃除したい場合だけ `cdidx . --json` の全 workspace scan へ上げる。`cdidx . --json` は強制 rebuild ではなく、`mode:"incremental"` と表示して unchanged file を skip する場合があるため、その後の `status --check --json` がまだ stale なら `dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll index . --rebuild --yes --json` に上げる。 +- 毎コミット後に、ローカルソースの最新状態から `cdidx` を再ビルドし、`dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll status --check --db .cdidx/codeindex.db --json` を実行する。`index_matches_workspace: true` でなければ、その新しいバイナリで `.cdidx/codeindex.db` を更新する。 +- リポジトリ追跡の `cdidx.workspace.json` は `index_strategy: single` を使うため、ルートの `.cdidx/codeindex.db` だけを正規のドッグフード用データベースとする。source、tests、docs、scripts、workflows、policy をすべて検索可能にするため `.` を index し、重複する member database は維持しない。dogfood の CLI query、MCP/LSP、maintenance command には常に `--db .cdidx/codeindex.db` を渡す。data-directory と active-workspace の override は CWD discovery より優先されるため、リポジトリルートから実行するだけでは DB を固定できない。明示的に固定した root status が healthy になった後、`dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll workspace status --check --json` も healthy であることを必須とする。 +- 更新モードは「正しさを保てる範囲で最も軽いもの」を優先する。`--files` は把握している in-place 編集や新規追加だけに使い、通常のコミット後は rename/delete も拾える `--commits HEAD` を使う。ブランチ切り替え後は前後の ref が分かるなら `--changed-between ` を使い、履歴を動かす操作や repo 全体で stale file を掃除したい場合だけ `cdidx . --db .cdidx/codeindex.db --json` の全 workspace scan へ上げる。この full scan は強制 rebuild ではなく、`mode:"incremental"` と表示して unchanged file を skip する場合があるため、明示的に DB を固定した `status --check --json` がまだ stale なら `dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll index . --rebuild --yes --db .cdidx/codeindex.db --json` に上げる。 - リポジトリのコードを変更した後は、古いグローバルインストール版ではなく **ローカルでビルドした最新版バイナリ** (`dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll`) を使う。**グローバル版には絶対に戻らないこと** — グローバル版は DB スキーマが古い、クエリ機能が欠けている、抽出ロジックが古くて誤った結果を返す、といった問題が起こりうる。このルールはリポジトリ追跡の `.claude/settings.json` で harness レベルでも強制されており、shell のコード検索・ファイル探索系コマンドを網羅的に deny している(`rg`、`grep`、`egrep`、`fgrep`、`zgrep`、`rgrep`、`ripgrep`、`ag`、`ack`、`ack-grep`、`git grep`、`find`、`locate`、`mlocate`、`mdfind`、`cdidx`)。代わりに組み込みの Grep / Glob ツールかローカルビルド版を使うこと。 - リポジトリ追跡の `.claude/settings.json`、`.claude/hooks/bash-guard.py`、`.codex/hooks.json`、`.codex/hooks/bash_guard.py` は tool-specific guard adapter として扱う。通常の自己改善作業では編集せず、agent guard 挙動自体を変えるタスクのときだけ触る。共通の Bash command policy は `.agent_harness/command_guard_core.py` に置かれているため、共通ポリシーを変える場合は shared core を更新し、tool 固有挙動が変わる場合だけ両 adapter を見直す。現在のガードは deny ベースで、日常的な `dotnet`、`git`、`gh`、`codex exec`、`/tmp` 作業、読み取り中心の shell 確認は止めにくくしつつ、危険な shell パターンと機微なローカル read path は止める設計になっている。 - Claude Code のローカルプライバシー境界を尊重すること。ホーム配下の私物領域や資格情報系ファイルはポリシーで read deny されているため、自己改善タスクを進めやすくする目的でそれを緩めない。もし guard の変更自体が本当に必要なら、それを独立したタスクとして扱い、関連ドキュメントも同じコミットで更新する。 -- `git switch` の後は、切り替え前後の ref が分かる場合、**ローカルビルド版** で `dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll index . --changed-between --json` を実行する。これにより、ブランチ間で変わったファイルだけを更新しつつ、git が返す rename/delete の旧 path も purge できる。ref が分からない場合や、`git reset`、`git rebase`、`git commit --amend`、`git merge` の後は、`dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll . --json` の full-workspace scan で現在の checkout に対する stale file を掃除する。その後も status check が stale なら、`cdidx . --json` を繰り返さず `dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll index . --rebuild --yes --json` を実行する。 +- `git switch` の後は、切り替え前後の ref が分かる場合、**ローカルビルド版** で `dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll index . --changed-between --db .cdidx/codeindex.db --json` を実行する。これにより、ブランチ間で変わったファイルだけを更新しつつ、git が返す rename/delete の旧 path も purge できる。ref が分からない場合や、`git reset`、`git rebase`、`git commit --amend`、`git merge` の後は、`dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll . --db .cdidx/codeindex.db --json` の full-workspace scan で現在の checkout に対する stale file を掃除する。その後も status check が stale なら、full scan を繰り返さず `dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll index . --rebuild --yes --db .cdidx/codeindex.db --json` を実行する。 - バグ調査、修正計画、変更検証のためにコード検索・ナビゲーションを行うときも、常に **ローカルビルド版** を使う。グローバルインストール版は使わない。これにより、このブランチの最新の抽出ルールと DB スキーマを反映した検索結果が得られる。 - このループ中に **ローカルビルド版** がクラッシュしたり、異常終了したり、新しい不具合を露呈した場合は、黙って回避したり古い版・グローバル版へ逃げたりしないこと。具体的な失敗内容をユーザーに通知し、その不具合によって自己改善ループがブロックされている、または結果の信頼性が損なわれていることを説明したうえで、別タスクまたは次の承認済み優先事項として修正提案を出すこと。 - このループ自体を、継続的なリグレッション確認と軽いモンキーテストとして扱うこと。最も安全で標準的なワークフローだけに偏らず、新しい機能、利用頻度の低い機能、枝葉末節のオプションも積極的に触り、間接的にクラッシュ、古いヘルプ文、想定漏れ、統合不具合をあぶり出すこと。 @@ -432,7 +434,7 @@ dotnet build まず現在の workspace と DB が一致しているか確認します: ```bash -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll status --check --json +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll status --check --db .cdidx/codeindex.db --json ``` 終了コード `0` かつ `index_matches_workspace: true` なら、既存の `.cdidx/codeindex.db` をそのまま使って構いません。それ以外ならインデックスを更新してください。 @@ -443,20 +445,20 @@ dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll status --check --json ```bash # ブランチ切り替え後、前後の ref が分かる場合 -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll index . --changed-between --json +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll index . --changed-between --db .cdidx/codeindex.db --json # checkout 直後の初回同期、履歴を動かす git 操作の直後、 # またはブランチ切り替え前後の ref が分からない場合 -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll . --json +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll . --db .cdidx/codeindex.db --json # 手元の in-place 編集や新規追加だけを反映 # rename/delete の旧 path は、明示しない限り purge されない -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll index . --files src/CodeIndex/Cli/QueryCommandRunner.cs tests/CodeIndex.Tests/QueryCommandRunnerTests.cs --json +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll index . --files src/CodeIndex/Cli/QueryCommandRunner.cs tests/CodeIndex.Tests/QueryCommandRunnerTests.cs --db .cdidx/codeindex.db --json # 通常のコミット直後は、そのコミット差分だけを反映 # git diff が rename/delete も見られるので、こちらを既定にする commit_id=$(git rev-parse HEAD) -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll index . --commits "$commit_id" --json +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll index . --commits "$commit_id" --db .cdidx/codeindex.db --json ``` `--changed-between` は要求範囲を永続化済みの workspace 全体検証基準と照合します。基準が古い、または分岐している場合は不足する基準→現在 HEAD の path をローカル binary が補完します。Git が基準を解決できない場合は `--files` へ置き換えず、出力された fetch / full scan の案内に従ってください。 @@ -464,7 +466,7 @@ dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll index . --commits "$commit_id" `dotnet run` でも構いません: ```bash -dotnet run --project src/CodeIndex -- . --json +dotnet run --project src/CodeIndex -- . --db .cdidx/codeindex.db --json ``` ### 4. cdidx 自身でリポジトリを観察する @@ -476,18 +478,18 @@ dotnet run --project src/CodeIndex -- . --json `status --json` が `fold_ready: false` を返し、古い DB に対して Unicode-aware な `--exact` だけを有効化したい場合は、まず次で in-place upgrade することを優先してください: ```bash -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll backfill-fold --json +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll backfill-fold --db .cdidx/codeindex.db --json ``` -ソース再走査も必要なとき、履歴を動かす git 操作の直後、ブランチ切り替え前後の ref が分からないとき、または repo 全体で stale file を掃除したいときだけ、`cdidx . --json` の full-workspace scan を使います。この経路は強制 rebuild ではなく、`mode:"incremental"` と表示して unchanged file を skip する場合があります。その後の `status --check --json` がまだ stale なら、`dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll index . --rebuild --yes --json` を実行してください。通常のコミット間ループでは rename/delete も追える `--commits`、ブランチ切り替えでは前後 ref を渡す `--changed-between` を先に考え、`--files` は in-place 編集や新規追加に限定してください。 +ソース再走査も必要なとき、履歴を動かす git 操作の直後、ブランチ切り替え前後の ref が分からないとき、または repo 全体で stale file を掃除したいときだけ、`cdidx . --db .cdidx/codeindex.db --json` の full-workspace scan を使います。この経路は強制 rebuild ではなく、`mode:"incremental"` と表示して unchanged file を skip する場合があります。その後の `status --check --db .cdidx/codeindex.db --json` がまだ stale なら、`dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll index . --rebuild --yes --db .cdidx/codeindex.db --json` を実行してください。通常のコミット間ループでは rename/delete も追える `--commits`、ブランチ切り替えでは前後 ref を渡す `--changed-between` を先に考え、`--files` は in-place 編集や新規追加に限定してください。 典型例: ```bash -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll status --json -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll map --json --limit 10 --path src/ --exclude-tests -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll inspect QueryCommandRunner --exclude-tests --limit 5 -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll search "AI" --path src/ --exclude-tests --snippet-lines 6 --json +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll status --db .cdidx/codeindex.db --json +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll map --db .cdidx/codeindex.db --json --limit 10 --path src/ --exclude-tests +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll inspect QueryCommandRunner --db .cdidx/codeindex.db --exclude-tests --limit 5 +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll search "AI" --db .cdidx/codeindex.db --path src/ --exclude-tests --snippet-lines 6 --json ``` 候補シンボル名が分かっているなら `inspect`、生テキストや未対応言語なら `search`、全体像が欲しいなら `map` を優先します。 @@ -533,9 +535,9 @@ dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll search "AI" --path src/ --excl ```bash dotnet test -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll status --json -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll map --json --path src/ --exclude-tests -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll inspect ResolveGitCommonDir --json --exclude-tests --limit 5 +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll status --db .cdidx/codeindex.db --json +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll map --db .cdidx/codeindex.db --json --path src/ --exclude-tests +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll inspect ResolveGitCommonDir --db .cdidx/codeindex.db --json --exclude-tests --limit 5 ``` ### 8. 1案件だけコミットする @@ -565,15 +567,15 @@ dotnet build # 通常の post-commit 経路: 直前コミットの差分を反映 # git diff が rename/delete も拾えるため、--files より安全 commit_id=$(git rev-parse HEAD) -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll index . --commits "$commit_id" --json +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll index . --commits "$commit_id" --db .cdidx/codeindex.db --json # ブランチ切り替え後、前後の ref が分かる場合 -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll index . --changed-between --json +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll index . --changed-between --db .cdidx/codeindex.db --json # git reset/rebase/amend/merge の後、 # ブランチ切り替え前後の ref が分からない場合、 # または repo 全体の stale file purge が必要な場合はフル更新 -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll . --json +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll . --db .cdidx/codeindex.db --json ``` ### 10. 更新済みインデックスから次の案件を選ぶ diff --git a/TESTING_GUIDE.md b/TESTING_GUIDE.md index d2def12152..61648e2f82 100644 --- a/TESTING_GUIDE.md +++ b/TESTING_GUIDE.md @@ -383,6 +383,7 @@ Use `docs/test-doc-maintenance-plan.md` before moving oversized suites or adding Shared extractor-regex safety coverage. Demand-driven enumeration tests must take only the requested prefix and keep a catastrophic suffix unvisited, while timeout tests continue to verify best-effort empty results and captured diagnostics. - `DocumentationStatusContractTests.cs`, `DocumentationDriftTests.cs` Checked-in documentation contract tests. They use `RepositoryTestPaths` to keep status fields, workflow references, documented `cdidx` command examples, release/changelog workflow snippets, and representative English/Japanese guide sections synchronized. + Repository dogfood coverage keeps `cdidx.workspace.json` on the shared root database topology and requires the agent, self-improvement, developer, and issue-fix guidance to name the same `.cdidx/codeindex.db` and both root/workspace status checks. `DocumentationStatusContractTests.cs` includes readiness, maintenance, and MCP status fields so status JSON support contracts stay visible in the user and agent guides. Workflow tests that compare multiline YAML snippets should use `RepositoryTestPaths.ReadNormalizedWorkflow(...)` so line-ending normalization stays centralized across CI, release, package-lock, and mutation workflow contracts. Reuse that normalized value for all assertions in a test instead of reading or retaining both raw and normalized copies of the same workflow. @@ -1387,6 +1388,7 @@ dotnet test --filter "FullyQualifiedName~GitHelperTests" 共有 extractor-regex safety のカバレッジです。demand-driven enumeration test は要求された prefix だけを取得して catastrophic suffix を未走査のまま保ち、timeout test は引き続き best-effort の empty result と captured diagnostic を検証してください。 - `DocumentationStatusContractTests.cs`、`DocumentationDriftTests.cs` checked-in documentation の契約テスト。`RepositoryTestPaths` を使って、status field、workflow 参照、文書化された `cdidx` コマンド例、release/changelog workflow の snippet、代表的な英日 guide セクションの同期を維持します。 + repository dogfood coverage は `cdidx.workspace.json` を共有 root database topology に固定し、agent、self-improvement、developer、issue-fix guidance が同じ `.cdidx/codeindex.db` と root/workspace 両方の status check を記載することを要求します。 `DocumentationStatusContractTests.cs` は readiness、maintenance、MCP status field も含め、status JSON support contract が user guide と agent guide に残るようにします。 複数行の YAML snippet を比較する workflow test は `RepositoryTestPaths.ReadNormalizedWorkflow(...)` を使い、CI、release、package-lock、mutation workflow contract 間の line-ending normalization を一か所に集約します。 同じ test 内の全 assertion でその normalized value を再利用し、同じ workflow の raw copy と normalized copy を重複して読み込んだり保持したりしません。 diff --git a/cdidx.workspace.json b/cdidx.workspace.json index 83043f1ba0..0f476aea32 100644 --- a/cdidx.workspace.json +++ b/cdidx.workspace.json @@ -3,7 +3,7 @@ "src/CodeIndex", "tests/CodeIndex.Tests" ], - "index_strategy": "per_member", + "index_strategy": "single", "default_db_name": "codeindex.db", "shared_ignores": [ "bin/", diff --git a/changelog.d/unreleased/5062.fixed.md b/changelog.d/unreleased/5062.fixed.md new file mode 100644 index 0000000000..9aba577672 --- /dev/null +++ b/changelog.d/unreleased/5062.fixed.md @@ -0,0 +1,19 @@ +--- +category: fixed +issues: + - 5062 +affected: + - cdidx.workspace.json + - AGENT_GUIDE.md + - SELF_IMPROVEMENT.md + - DEVELOPER_GUIDE.md + - .codex/workflows/issue-fix.md +--- + +## English + +- **Repository dogfooding now uses one canonical root database (#5062)** — the checked-in workspace manifest uses the supported `single` strategy, and agent/developer guidance consistently targets `.cdidx/codeindex.db` for CLI, MCP, LSP, maintenance, and both root/workspace health checks. + +## 日本語 + +- **リポジトリのドッグフーディングで正規の root database を1つだけ使うようになりました (#5062)** — 追跡済み workspace manifest は対応済みの `single` strategy を使い、agent / developer guidance は CLI、MCP、LSP、maintenance、root/workspace 両方の health check で一貫して `.cdidx/codeindex.db` を対象にします。 diff --git a/docs/large-file-decomposition-plan.md b/docs/large-file-decomposition-plan.md index 289681dc20..9f70754901 100644 --- a/docs/large-file-decomposition-plan.md +++ b/docs/large-file-decomposition-plan.md @@ -25,9 +25,9 @@ Issue #4061 refreshes the baseline with a fresh local index and tracks every split with the same dogfood queries before and after each move: ```bash -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll files --bytes --path src/ --exclude-tests --limit 40 --json -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll hotspots --group-by file --path src/ --exclude-tests --limit 40 --json -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll symbols --sort size --lang csharp --exclude-tests --limit 120 --json +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll files --bytes --path src/ --exclude-tests --limit 40 --db .cdidx/codeindex.db --json +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll hotspots --group-by file --path src/ --exclude-tests --limit 40 --db .cdidx/codeindex.db --json +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll symbols --sort size --lang csharp --exclude-tests --limit 120 --db .cdidx/codeindex.db --json ``` The pre-split snapshot on `origin/main` at @@ -192,9 +192,9 @@ issue #4061 では、fresh なローカル index でベースラインを更新 の前後を同じ dogfood query で追跡します。 ```bash -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll files --bytes --path src/ --exclude-tests --limit 40 --json -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll hotspots --group-by file --path src/ --exclude-tests --limit 40 --json -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll symbols --sort size --lang csharp --exclude-tests --limit 120 --json +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll files --bytes --path src/ --exclude-tests --limit 40 --db .cdidx/codeindex.db --json +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll hotspots --group-by file --path src/ --exclude-tests --limit 40 --db .cdidx/codeindex.db --json +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll symbols --sort size --lang csharp --exclude-tests --limit 120 --db .cdidx/codeindex.db --json ``` `origin/main` の `eaf0e9114c945598e44b11d8ac6010f2087ea046` で取得した diff --git a/docs/sqlite-command-policy-audit.md b/docs/sqlite-command-policy-audit.md index 477ab1ffbf..313a8b5eee 100644 --- a/docs/sqlite-command-policy-audit.md +++ b/docs/sqlite-command-policy-audit.md @@ -3,8 +3,8 @@ Issue #4070 audited `CommandText` and `PRAGMA` construction in production code. The current dogfood commands are: ```bash -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll search --recipe dogfood-risk-patterns/raw-sql-command-text --path src/ --exclude-tests --count --group-by file --limit 80 -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll search --recipe dogfood-risk-patterns/pragma-command --path src/ --exclude-tests --count --group-by file --limit 80 +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll search --recipe dogfood-risk-patterns/raw-sql-command-text --path src/ --exclude-tests --count --group-by file --limit 80 --db .cdidx/codeindex.db +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll search --recipe dogfood-risk-patterns/pragma-command --path src/ --exclude-tests --count --group-by file --limit 80 --db .cdidx/codeindex.db ``` | Category | Files / examples | Policy | diff --git a/docs/test-doc-maintenance-plan.md b/docs/test-doc-maintenance-plan.md index 3a2b8cf408..4ab96f796d 100644 --- a/docs/test-doc-maintenance-plan.md +++ b/docs/test-doc-maintenance-plan.md @@ -77,7 +77,7 @@ candidate before changing a skip. Before adding or retaining a skip, run: ```bash -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll search --exact-substring --query "Skip =" --path tests/CodeIndex.Tests --limit 80 --json +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll search --exact-substring --query "Skip =" --path tests/CodeIndex.Tests --limit 80 --db .cdidx/codeindex.db --json ``` ## Split Sequence @@ -211,7 +211,7 @@ exact-substring query を使い、変更前に候補を 1 件ずつ確認して skip を追加または維持する前に次を実行してください。 ```bash -dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll search --exact-substring --query "Skip =" --path tests/CodeIndex.Tests --limit 80 --json +dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll search --exact-substring --query "Skip =" --path tests/CodeIndex.Tests --limit 80 --db .cdidx/codeindex.db --json ``` ## 分割順序 diff --git a/tests/CodeIndex.Tests/DocumentationDriftTests.cs b/tests/CodeIndex.Tests/DocumentationDriftTests.cs index 56a80a617b..2cb3743bc2 100644 --- a/tests/CodeIndex.Tests/DocumentationDriftTests.cs +++ b/tests/CodeIndex.Tests/DocumentationDriftTests.cs @@ -1,4 +1,5 @@ using System.Reflection; +using System.Text.Json; using System.Text.RegularExpressions; using CodeIndex.Cli; using CodeIndex.Database; @@ -23,6 +24,10 @@ public sealed class DocumentationDriftTests @"`(?:[A-Z_][A-Z0-9_]*=\S+\s+)*(?cdidx|dotnet\s+\./src/CodeIndex/bin/Debug/net8\.0/cdidx\.dll|dotnet\s+run\s+--project\s+src/CodeIndex\s+--)\s+(?[^\s`|;&]+)[^`]*`", RegexOptions.Compiled); + private static readonly Regex LocalRepositoryCdidxInvocationRegex = new( + @"dotnet\s+\./src/CodeIndex/bin/Debug/net8\.0/cdidx\.dll(?:\s+(?[^\s`|;&]+))?", + RegexOptions.Compiled); + private static readonly Regex ErrorCodeTableRowRegex = new( @"^\| `(?E[0-9]{3}_[A-Z0-9_]+)` \|", RegexOptions.Compiled | RegexOptions.Multiline); @@ -149,6 +154,63 @@ public void DocumentedCdidxExamples_UseKnownEntrypointTokens_Issue4160() Assert.Empty(failures); } + [Fact] + public void RepositoryDogfoodManifestAndGuidance_StaySynchronized_Issue5062() + { + using var manifest = JsonDocument.Parse(RepositoryTestPaths.ReadText("cdidx.workspace.json")); + var root = manifest.RootElement; + + Assert.Equal("single", root.GetProperty("index_strategy").GetString()); + Assert.Equal("codeindex.db", root.GetProperty("default_db_name").GetString()); + Assert.Equal( + ["src/CodeIndex", "tests/CodeIndex.Tests"], + root.GetProperty("members").EnumerateArray().Select(member => member.GetString()).ToArray()); + + const string canonicalDb = ".cdidx/codeindex.db"; + const string rootStatus = "dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll status --check --db .cdidx/codeindex.db --json"; + const string workspaceStatus = "dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll workspace status --check --json"; + var guidancePaths = new[] + { + "AGENT_GUIDE.md", + "SELF_IMPROVEMENT.md", + "DEVELOPER_GUIDE.md", + ".codex/workflows/issue-fix.md", + }; + + foreach (var relativePath in guidancePaths) + { + var content = RepositoryTestPaths.ReadText(relativePath.Split('/')); + Assert.Contains(canonicalDb, content, StringComparison.Ordinal); + Assert.Contains(rootStatus, content, StringComparison.Ordinal); + Assert.Contains(workspaceStatus, content, StringComparison.Ordinal); + } + + var unpinnedInvocations = new List(); + foreach (var relativePath in EnumerateDocumentationCommandReferenceFiles()) + { + var lines = RepositoryTestPaths.ReadNormalizedLines(relativePath.Split('/')); + for (var lineNumber = 0; lineNumber < lines.Length; lineNumber++) + { + var line = lines[lineNumber]; + foreach (Match match in LocalRepositoryCdidxInvocationRegex.Matches(line)) + { + var token = NormalizeCdidxToken(match.Groups["token"].Value); + if (string.IsNullOrWhiteSpace(token) || RepositoryDogfoodCommandDoesNotSelectDatabase(token)) + continue; + + if (!line.Contains("--db .cdidx/codeindex.db", StringComparison.Ordinal) + && !line.Contains("--db=.cdidx/codeindex.db", StringComparison.Ordinal)) + { + unpinnedInvocations.Add( + $"{relativePath}:{lineNumber + 1}: repository dogfood command does not select {canonicalDb}: {line.Trim()}"); + } + } + } + } + + Assert.Empty(unpinnedInvocations); + } + [Fact] public void PreparedCommandCacheDefault_DocumentationMatchesRuntime() { @@ -259,6 +321,7 @@ private static IEnumerable EnumerateDocumentationCommandReferenceFiles() { var rootFiles = new[] { + ".codex/README.md", "AGENT_GUIDE.md", "README.md", "USER_GUIDE.md", @@ -309,6 +372,27 @@ private static bool ShouldSkipCdidxEntrypointToken(string token) return token[0] is '.' or '/' or '\\' or '~' or '$' or '%' or '<' or '[' or '{' or '"'; } + private static bool RepositoryDogfoodCommandDoesNotSelectDatabase(string token) + { + return token is + "--check-updates" or + "--completions" or + "--help" or + "--help-all" or + "--help-flags" or + "--sushi" or + "--version" or + "completions" or + "config" or + "help" or + "languages" or + "license" or + "test-extractor" or + "upgrade" or + "validate-config" or + "workspace"; + } + private static string ToRepositoryRelativePath(string absolutePath) { return Path.GetRelativePath(RepositoryTestPaths.Root, absolutePath)