Skip to content

Commit b050bce

Browse files
committed
Merge remote-tracking branch 'origin/main' into codex/fix-issue1827-1954
2 parents 85764d8 + 8606923 commit b050bce

33 files changed

Lines changed: 1213 additions & 103 deletions

DEVELOPER_GUIDE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ Scoped `--files` / `--commits` refreshes reuse the same path filter as full scan
148148

149149
Incremental refreshes that mutate `fts_chunks` increment `codeindex_meta.fts_incremental_writes_since_optimize`. When the counter reaches `DbWriter.DefaultFtsOptimizeIncrementalWriteThreshold`, the update path runs `INSERT INTO fts_chunks(fts_chunks) VALUES('optimize')`, resets the counter, and stamps `fts_last_optimized_at`. Users can run the same maintenance directly with `cdidx optimize --db <path>` or `cdidx index <projectPath> --optimize`; this may briefly hold the writer lock on large indexes.
150150

151+
Successful writer sessions attempt `PRAGMA wal_checkpoint(TRUNCATE)` before closing a writable `DbContext`, so large WAL files are reclaimed after index, backfill, optimize, prune, and other DB-writing commands. `cdidx db schema [--json]` dumps `sqlite_master` entries plus `PRAGMA user_version` for schema inspection, and `cdidx db prune --dry-run|--apply [--json]` counts or deletes orphaned `symbol_references`, `reference_lines`, and `symbols` rows before running `PRAGMA optimize` on apply.
152+
151153
### Extending the indexer
152154

153155
Out-of-tree post-extraction hooks can implement `CodeIndex.Indexer.Hooks.IPostExtractionHook` in a `.dll` placed under `~/.config/cdidx/hooks/` (or the directory named by `CDIDX_HOOKS_DIR`). Hook assemblies are discovered in path order. Each concrete hook type is instantiated with a public parameterless constructor, then called after built-in symbol extraction and again after built-in reference extraction, before rows are persisted. Hooks receive a `FileContext` plus mutable `IList<SymbolRecord>` / `IList<ReferenceRecord>` values, so they can annotate extracted records, add synthetic symbols, or add domain-specific references.

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Output controls:
8484
| ASCII-only terminal output | Use `--ascii`, `CDIDX_ASCII=1`, `NO_UNICODE`, `TERM=dumb`, accessibility env hints, or a non-UTF-8 locale. Spinners use pipe, slash, dash, and backslash frames; progress bars use `#` / `-`; very narrow terminals fall back to percentage-only progress. |
8585
| Color and terminal capability | `--color auto` emits ANSI only for capable interactive terminals; `TERM=dumb`, `CI=true`, missing Unix terminal hints, `NO_COLOR`, or `CLICOLOR=0` disable ANSI/progress control sequences. `--palette basic|256|truecolor` can override the `COLORTERM` / `TERM` color-depth detection. |
8686
| UTF-8 JSON pipelines | CLI `--json` output is written as UTF-8 without a BOM and never includes ANSI escape sequences, even when color is forced for human output. |
87-
| Script-friendly query pipelines | Use `--quiet`, `-q`, `--silent`, or `CDIDX_QUIET=1` to suppress informational stderr text while preserving errors. `--quiet` takes precedence over `--verbose`. |
87+
| Script-friendly query pipelines | Use `--quiet`, `-q`, `--silent`, or `CDIDX_QUIET=1` to suppress informational stderr text while preserving errors. `--quiet` takes precedence over `--verbose`. Read commands that support `--format` can emit `count`, `compact`, `csv`, or `tsv` output when callers need smaller or table-shaped payloads instead of full excerpts. |
8888

8989
Use `cdidx` when a repository will be searched repeatedly from terminals,
9090
scripts, CI, or AI tools. Use `rg` when you only need a one-off text scan.
@@ -112,7 +112,7 @@ See [DISTRIBUTION.md](DISTRIBUTION.md) for the full channel matrix and
112112

113113
### Validate
114114

115-
Run `cdidx validate [--db <path>] [--json] [--verbose] [--kind <kind>] [--path <glob>]`
115+
Run `cdidx validate [--db <path>] [--json] [--format <text|json|count|compact|csv|tsv|lsp|qf|sarif>] [--verbose] [--kind <kind>] [--path <glob>]`
116116
to report indexed file issues such as replacement characters (`U+FFFD`), BOMs,
117117
NUL bytes, mixed line endings, UTF-16 BOMs, and likely non-UTF8 content.
118118
Validation findings are reported in the output and do not by themselves make
@@ -133,7 +133,7 @@ downgrading `cdidx`.
133133

134134
| Area | What cdidx provides |
135135
|---|---|
136-
| Search surfaces | CLI-first output for humans and machines; full-text, symbol, reference, caller/callee, dependency, map, inspect, and excerpt commands. |
136+
| Search surfaces | CLI-first output for humans and machines; full-text, symbol, reference, caller/callee, dependency, map, inspect, and excerpt commands. `search`, `definition`, `references`, `callers`, `callees`, `find`, and `validate` support `--format count|compact|csv|tsv|lsp|qf|sarif` for token-budgeted agents, scripts, editors, and CI reports. |
137137
| Ranking and filters | Public/exported symbol matches rank ahead of protected, internal, and private matches. Use `--no-visibility-rank` for legacy order, and `--visibility` / `--exclude-visibility` with `symbols`, `definition`, `unused`, and `hotspots`. Query defaults can be adjusted with `CDIDX_DEFAULT_LIMIT`, `CDIDX_DEFAULT_SNIPPET_LINES`, and `CDIDX_DEFAULT_MAX_LINE_WIDTH`; explicit CLI flags still win. |
138138
| Project scoping | `.sln` / `.csproj`-aware <code>--project &lt;name&#124;path&gt;</code> filters for indexing and queries, plus `--solution <path>` when a workspace has multiple solution files. |
139139
| MCP integration | MCP server support for AI clients such as Claude Code, Cursor, and Windsurf, including tools, indexed-file resources, starter prompts, schema constraints for local argument validation, `mimeType` on text content blocks, logging, a structured `ping` health result, HTTP `GET /healthz`, opt-in HTTP `/events` keep-alive notifications, a compatibility server-side `notifications/initialized` ready signal on stdio or HTTP `/events` streams, and `Language support:` descriptions sourced from the same registries as `cdidx languages`. Tool schemas reject unknown arguments with `-32602`, advertise `x-stability`, and use snake_case structured JSON keys to match the CLI JSON contract. |
@@ -376,7 +376,7 @@ upgrade / downgrade 後はインストール済み補完 script を再生成し
376376
| MCP 連携 | Claude Code、Cursor、Windsurf などの AI クライアント向け MCP server。tools、インデックス済みファイル resources、starter prompts、ローカル引数検証用の schema constraints、text content block の `mimeType`、logging、構造化された `ping` health result、HTTP `GET /healthz`、opt-in の HTTP `/events` keep-alive notification、stdio または HTTP `/events` stream 上の互換性用 server-side `notifications/initialized` ready signal、`cdidx languages` と同じ言語レジストリ由来の `Language support:` 説明を提供します。Tool schema は未知の引数を `-32602` で拒否し、`x-stability` を公開し、CLI JSON contract と一致する snake_case の structured JSON key を使います。 |
377377
| freshness | `--parallelism` による parallel full-scan、`--files` / `--commits` による差分更新、`--watch` による継続更新、`status --check` による完全一致確認、`--stale-after` / `CDIDX_STALE_AFTER` による age threshold 上書きに対応します。 |
378378
| storage | `.cdidx/codeindex.db` に保存する local-first 設計。ネストしたディレクトリからの query コマンドは、current directory にフォールバックする前に最上位祖先の `.cdidx/codeindex.db` を優先します。既定の SQLite 保存先は `--data-dir <dir>``CDIDX_DATA_DIR``XDG_DATA_HOME` で workspace 外へ移せます。明示的な `--db <path>` は引き続き最優先です。 |
379-
| DB maintenance | 新規 index DB は SQLite incremental auto-vacuum を使います。既存 DB は `cdidx vacuum` で free page を回収でき、legacy no-autovacuum DB は初回だけ full `VACUUM` で変換します。`status --json``db_pragma_settings` 配下に metrics を出力します。 |
379+
| DB maintenance | 新規 index DB は SQLite incremental auto-vacuum を使います。成功した writer 実行は WAL を `TRUNCATE` checkpoint します。既存 DB は `cdidx vacuum` で free page を回収でき、legacy no-autovacuum DB は初回だけ full `VACUUM` で変換します`cdidx db schema` は on-disk schema を出力し、`cdidx db prune --dry-run|--apply` は orphaned DB rows を検査・削除します`status --json``db_pragma_settings` 配下に metrics を出力します。 |
380380
| security defaults | POSIX では `.cdidx``0700` 権限で作成します。`status --json` は利用可能な場合に実効 POSIX mode を `data_dir_mode` として報告します。 |
381381
| diagnostics | `status --config` は source attribution 付きの effective configuration を出力し、`status --explain <field>` は readiness field の意味と対処を説明します。read 系コマンドは `--profile``--slow-query-ms <n>`、<code>--trace=stderr&#124;file&#124;none</code> に対応し、file trace は lifecycle log と同じ場所に日次 `query-trace-YYYYMMDD.jsonl` を書きます。 |
382382
| drift checks | `cdidx diff <db1> <db2>` は schema、file、symbol、reference の差分を比較します。exit code は `0` identical、`1` drift、`2` schema mismatch、`3` unreadable DB です。 |
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
category: fixed
3+
issues:
4+
- 1617
5+
affected:
6+
- src/CodeIndex/Cli/GlobalToolLog.cs
7+
- src/CodeIndex/Cli/ProgramRunner.cs
8+
- src/CodeIndex/Cli/QueryCommandRunner.cs
9+
- src/CodeIndex/Mcp/McpServer.cs
10+
- src/CodeIndex/Mcp/McpToolHandlers.cs
11+
- tests/CodeIndex.Tests/McpServerTests.cs
12+
---
13+
14+
## English
15+
16+
- **Time-sensitive CLI and MCP paths now use injectable clocks (#1617)** — status age calculations, query trace/log naming, MCP ping timestamps, and MCP suggestion persistence can now be driven by `TimeProvider` for deterministic tests.
17+
18+
## 日本語
19+
20+
- **時刻に依存する CLI / MCP 経路が注入可能な clock を使うようになりました (#1617)** — status の経過時間計算、query trace / log のファイル名、MCP ping の timestamp、MCP suggestion の永続化を `TimeProvider` で決定論的にテストできるようになりました。
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
category: fixed
3+
issues:
4+
- 1618
5+
affected:
6+
- src/CodeIndex/Cli/SuggestionStore.cs
7+
- tests/CodeIndex.Tests/SuggestionStoreTests.cs
8+
---
9+
10+
## English
11+
12+
- **Suggestion `CreatedAt` is now stamped at persistence time (#1618)** — new suggestions receive their creation timestamp inside the store's locked write path, aligning the recorded time with when the suggestion enters the local store.
13+
14+
## 日本語
15+
16+
- **suggestion の `CreatedAt` を永続化時に記録するようになりました (#1618)** — 新規 suggestion の作成時刻は store のロックされた書き込み経路内で付与され、ローカル store に入った時刻と一致するようになりました。
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
category: fixed
3+
issues:
4+
- 1642
5+
affected:
6+
- src/CodeIndex/Cli/QueryCommandRunner.cs
7+
- src/CodeIndex/Cli/CliFlagSchema.cs
8+
- src/CodeIndex/Cli/ConsoleUi.cs
9+
- src/CodeIndex/Mcp/McpToolDefinitions.cs
10+
- src/CodeIndex/Mcp/McpToolHandlers.cs
11+
- tests/CodeIndex.Tests/McpServerTests.cs
12+
- tests/CodeIndex.Tests/QueryCommandRunnerTests.cs
13+
---
14+
15+
## English
16+
17+
- **Read commands now support lightweight `count` and `compact` output formats (#1642)** — CLI `search`, `definition`, `references`, `callers`, `callees`, `find`, and `validate` can return count-only or file/line-only payloads through `--format`, while MCP search/definition/reference/caller/callee tools accept `format: "count"` or `format: "compact"` without emitting excerpts or full result metadata.
18+
19+
## 日本語
20+
21+
- **read 系コマンドで軽量な `count` / `compact` 出力形式を使えるようになりました (#1642)** — CLI の `search``definition``references``callers``callees``find``validate``--format` により、MCP の search / definition / reference / caller / callee 系ツールは `format: "count"` または `format: "compact"` により、excerpt や完全な結果メタデータを出さずに count-only または file/line-only の payload を返せます。
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
category: fixed
3+
issues:
4+
- 1644
5+
affected:
6+
- src/CodeIndex/Database/DbContext.cs
7+
- tests/CodeIndex.Tests/DatabaseTests.cs
8+
---
9+
10+
## English
11+
12+
- **Successful writer sessions now truncate-checkpoint the SQLite WAL (#1644)** — writable DB contexts attempt `PRAGMA wal_checkpoint(TRUNCATE)` after write work so large `codeindex.db-wal` sidecars are reclaimed after successful maintenance and index runs.
13+
14+
## 日本語
15+
16+
- **成功した writer session が SQLite WAL を truncate checkpoint するようになりました (#1644)** — 書き込みを行った DB context は `PRAGMA wal_checkpoint(TRUNCATE)` を試行し、成功した maintenance / index 実行後に肥大化した `codeindex.db-wal` sidecar を回収します。
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
category: added
3+
issues:
4+
- 1646
5+
affected:
6+
- src/CodeIndex/Cli/DbCommandRunner.cs
7+
- src/CodeIndex/Cli/JsonOutputContracts.cs
8+
- tests/CodeIndex.Tests/DbCommandRunnerTests.cs
9+
---
10+
11+
## English
12+
13+
- **Added `cdidx db schema` for on-disk schema inspection (#1646)** — the new command prints SQLite schema entries and `PRAGMA user_version`, with `--json` for automation.
14+
15+
## 日本語
16+
17+
- **on-disk schema を確認する `cdidx db schema` を追加しました (#1646)** — 新しいコマンドは SQLite schema entries と `PRAGMA user_version` を出力し、自動化向けに `--json` も提供します。
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
category: added
3+
issues:
4+
- 1728
5+
affected:
6+
- src/CodeIndex/Cli/DbCommandRunner.cs
7+
- src/CodeIndex/Cli/JsonOutputContracts.cs
8+
- tests/CodeIndex.Tests/DbCommandRunnerTests.cs
9+
---
10+
11+
## English
12+
13+
- **Added `cdidx db prune --dry-run|--apply` for stale DB rows (#1728)** — the command counts or deletes orphaned `symbol_references`, `reference_lines`, and `symbols` rows, then runs `PRAGMA optimize` after apply.
14+
15+
## 日本語
16+
17+
- **stale DB rows を処理する `cdidx db prune --dry-run|--apply` を追加しました (#1728)** — このコマンドは orphaned `symbol_references``reference_lines``symbols` rows を集計または削除し、apply 後に `PRAGMA optimize` を実行します。
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
category: added
3+
issues:
4+
- 1941
5+
affected:
6+
- src/CodeIndex/Cli/QueryCommandRunner.cs
7+
- src/CodeIndex/Cli/CliFlagSchema.cs
8+
- src/CodeIndex/Cli/ConsoleUi.cs
9+
- tests/CodeIndex.Tests/QueryCommandRunnerTests.cs
10+
---
11+
12+
## English
13+
14+
- **Built-in CSV and TSV query formatters are now available (#1941)** — formatter-aware read commands accept `--format csv` and `--format tsv`, giving scripts and CI jobs table-shaped output without reserializing JSON.
15+
16+
## 日本語
17+
18+
- **組み込みの CSV / TSV query formatter を追加しました (#1941)** — formatter 対応の read 系コマンドで `--format csv``--format tsv` を指定でき、スクリプトや CI が JSON を再シリアライズせずに表形式の出力を扱えます。
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
category: fixed
3+
issues:
4+
- 2034
5+
affected:
6+
- tests/CodeIndex.Tests/ManualTimeProvider.cs
7+
- tests/CodeIndex.Tests/McpServerTests.cs
8+
- tests/CodeIndex.Tests/SuggestionStoreTests.cs
9+
---
10+
11+
## English
12+
13+
- **Time-dependent tests now use an explicit test clock (#2034)** — MCP timestamp and suggestion lifecycle coverage use `ManualTimeProvider` instead of depending on wall-clock time or hardcoded fixture dates.
14+
15+
## 日本語
16+
17+
- **時刻依存テストが明示的な test clock を使うようになりました (#2034)** — MCP timestamp と suggestion lifecycle のカバレッジは wall-clock や固定 fixture 日付に依存せず `ManualTimeProvider` を使うようになりました。

0 commit comments

Comments
 (0)