Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions USER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@ can use `jq -s '.'` or pass `--json=array` to `search` to emit the result set as
one JSON array. Add `--pretty` with `--json` to indent single-document JSON
responses; for `search`, use `--json=array --pretty` when the result set itself
should be indented because default `search --json` stays newline-delimited.
`search --named-query <name>=<query>` can be repeated to run an ad hoc grouped
batch with the same filters and snippet bounds. Named batches emit one grouped
JSON document, and `--format compact` keeps the per-result
`CompactSearchResult` snippet/highlight context instead of reducing rows to
file/line pairs.
For AI-oriented bounded payloads, `map`, `inspect`, and `outline` accept
`--compact`. It implies JSON output, caps list sections to 5 items by default
(or the explicit `--limit` / `--top` value), and adds `compact`,
Expand Down Expand Up @@ -922,6 +927,9 @@ cdidx search "File.ReadAllText" --exact-substring --reject-before "Length" --gua
cdidx search "FileMode.Create" --exact-substring --require-after "File.Move" --guard-window 12 # require a nearby follow-up action
cdidx search --list-recipes # show reusable audit recipes
cdidx search --recipe risky-code --json # run a curated audit query set and return grouped JSON
cdidx search --named-query pack="dotnet pack" --named-query push="nuget push" --format compact # named ad hoc batch with compact snippets
cdidx search "catch (Exception" --group-by file --count --json # rank broad audit hits by file
cdidx search "JsonDocument.Parse" --group-by symbol --count --json # rank broad audit hits by enclosing symbol
cdidx search --recipe risky-code --format issue-drafts --open-issues open-issues.json # issue draft JSON with duplicate preflight
cdidx search "--open-reports" --path README.md --count # quoted literal that starts with --
cdidx search --query "--path" --path README.md # search for an option-looking literal
Expand Down Expand Up @@ -1077,7 +1085,7 @@ When `definition --body` is combined with `--json`, `body_content` is capped to

`search`, `definition`, `references`, `callers`, `callees`, `symbols`, `files`, and `find` also share repeatable `--path <glob>` glob-style path filters (multiple values are OR'd together), repeatable `--exclude-path <glob>`, and `--exclude-tests`. Use `*` and `?` to match path segments, and plain text still behaves like a substring filter when you do not include wildcards. Search results prefer source files over tests and docs, and `search` boosts files whose symbol names or paths match the query exactly.

`search --json` and MCP `search` return compact match-centered snippets instead of whole chunks. Each result includes `chunk_start_line`, `chunk_end_line`, `snippet_start_line`, `snippet_end_line`, `snippet`, `match_lines`, `highlights`, `context_before`, `context_after`, `truncated_line_count`, `dropped_match_line_count`, and `truncation_context`, plus optional `enclosing_symbol_name`, `enclosing_symbol_kind`, `enclosing_symbol_start_line`, `enclosing_symbol_end_line`, and `enclosing_container_name` when the match line is inside an indexed symbol. Use `--snippet-lines <n>` to shrink or widen the excerpt window (default: 8, max: 20), and `--max-line-width <n>` to clamp each line around the strongest match when a minified / transpiled file would otherwise return a single huge line (default: 512, max: 4096; `0` disables clamping). `--snippet-focus <leftmost|quality|proximity>` controls that long-line focus; `quality` is the default, `leftmost` keeps the legacy earliest-match behavior, and `proximity` favors dense multi-token clusters. Clamped lines are marked with `...(+N)...` in the snippet and expose `highlights[].truncated` / `highlights[].original_line_length` in JSON / MCP output.
`search --json`, `search --format compact`, named search batches, and MCP `search` return compact match-centered snippets instead of whole chunks. Each result includes `chunk_start_line`, `chunk_end_line`, `snippet_start_line`, `snippet_end_line`, `snippet`, `match_lines`, `highlights`, `context_before`, `context_after`, `truncated_line_count`, `dropped_match_line_count`, and `truncation_context`, plus optional `enclosing_symbol_name`, `enclosing_symbol_kind`, `enclosing_symbol_start_line`, `enclosing_symbol_end_line`, and `enclosing_container_name` when the match line is inside an indexed symbol. Use `--snippet-lines <n>` to shrink or widen the excerpt window (default: 8, max: 20), and `--max-line-width <n>` to clamp each line around the strongest match when a minified / transpiled file would otherwise return a single huge line (default: 512, max: 4096; `0` disables clamping). `--snippet-focus <leftmost|quality|proximity>` controls that long-line focus; `quality` is the default, `leftmost` keeps the legacy earliest-match behavior, and `proximity` favors dense multi-token clusters. Clamped lines are marked with `...(+N)...` in the snippet and expose `highlights[].truncated` / `highlights[].original_line_length` in JSON / MCP output.
Search JSON also exposes `match_origins` and `match_facets` so tools can distinguish matches in code, comments, string literals, regex literals, and CLI help text. Each highlight includes its own `match_origins`; `--exclude-comments` and `--exclude-strings` use those facets to hide comment-only or string-like matches.
The same facets expose `test_file`, `test_symbol`, and `test_fixture` booleans at result, highlight, and match-facet levels. `test_fixture` marks string-like matches inside likely test files or indexed test methods, and `--exclude-fixtures` hides fixture-only matches while keeping real code matches.

Expand Down Expand Up @@ -2712,6 +2720,10 @@ newline-delimited JSON (ndjson) として出力し、最後に `{"done":true,...
単一 document の JSON 応答をインデント付きで出力します。`search` の result set を
整形したい場合は、既定の `search --json` が newline-delimited のまま保たれるため
`--json=array --pretty` を使います。
`search --named-query <name>=<query>` は繰り返し指定でき、同じ filter と snippet 上限で
ad hoc な grouped batch を実行します。名前付き batch は 1 つの grouped JSON document を
出力し、`--format compact` でも各 result の `CompactSearchResult` snippet / highlight
context を維持し、file/line だけの行には縮約しません。
AI 向けに上限付き payload が必要な場合、`map`、`inspect`、`outline` は
`--compact` に対応しています。これは JSON 出力を暗黙に有効化し、list section を
既定 5 件(明示した `--limit` / `--top` があればその値)に cap し、
Expand Down Expand Up @@ -3349,6 +3361,9 @@ cdidx search "File.ReadAllText" --exact-substring --reject-before "Length" --gua
cdidx search "FileMode.Create" --exact-substring --require-after "File.Move" --guard-window 12 # 近傍の後続処理を要求
cdidx search --list-recipes # 再利用可能な audit recipe を表示
cdidx search --recipe risky-code --json # curated audit query set を実行し、grouped JSON を返す
cdidx search --named-query pack="dotnet pack" --named-query push="nuget push" --format compact # 名前付き ad hoc batch と compact snippet
cdidx search "catch (Exception" --group-by file --count --json # 広い audit hit を file 別にランク付け
cdidx search "JsonDocument.Parse" --group-by symbol --count --json # 広い audit hit を enclosing symbol 別にランク付け
cdidx search --recipe risky-code --format issue-drafts --open-issues open-issues.json # duplicate preflight 付き issue draft JSON
cdidx search "--open-reports" --path README.md --count # `--` で始まる引用済みリテラル
cdidx search --query "--path" --path README.md # オプションに見えるリテラルを検索
Expand Down Expand Up @@ -3495,7 +3510,7 @@ function CreateUser src/Services/UserService.cs:

`search`、`definition`、`references`、`callers`、`callees`、`symbols`、`files` は共通で繰り返し指定できる `--path <glob>` の glob 形式パスフィルタ(複数値は OR で結合)、繰り返し指定できる `--exclude-path <glob>`、`--exclude-tests` に対応しています。`*` と `?` でパスパターンを指定でき、ワイルドカードを含めない場合は従来どおり部分文字列として扱われます。検索結果は tests や docs より source を優先し、`search` はシンボル名やパスがクエリと正確に一致するファイルを上に出します。

`search --json`MCP の `search` は、チャンク全文ではなく一致中心の軽量スニペットを返します。各結果には `chunk_start_line`、`chunk_end_line`、`snippet_start_line`、`snippet_end_line`、`snippet`、`match_lines`、`highlights`、`context_before`、`context_after`、`truncated_line_count`、`dropped_match_line_count`、`truncation_context` が含まれ、マッチ行がインデックス済みシンボル範囲内にある場合は `enclosing_symbol_name`、`enclosing_symbol_kind`、`enclosing_symbol_start_line`、`enclosing_symbol_end_line`、`enclosing_container_name` も含まれます。抜粋の長さは `--snippet-lines <n>` で調整でき(デフォルト: 8、最大: 20)、minified / transpiled で 1 行が極端に長いファイルでは `--max-line-width <n>` を使って各行を最も強い一致周辺へクランプできます(`0` でクランプ解除、デフォルト: 512、最大: 4096)。長い行の焦点は `--snippet-focus <leftmost|quality|proximity>` で制御でき、`quality` がデフォルト、`leftmost` は従来の最左一致、`proximity` は近接した複数トークンを優先します。クランプされた行はスニペット内に `...(+N)...` マーカーが入り、JSON / MCP 出力では `highlights[].truncated` / `highlights[].original_line_length` でも検出できます。
`search --json`、`search --format compact`、名前付き search batch、MCP の `search` は、チャンク全文ではなく一致中心の軽量スニペットを返します。各結果には `chunk_start_line`、`chunk_end_line`、`snippet_start_line`、`snippet_end_line`、`snippet`、`match_lines`、`highlights`、`context_before`、`context_after`、`truncated_line_count`、`dropped_match_line_count`、`truncation_context` が含まれ、マッチ行がインデックス済みシンボル範囲内にある場合は `enclosing_symbol_name`、`enclosing_symbol_kind`、`enclosing_symbol_start_line`、`enclosing_symbol_end_line`、`enclosing_container_name` も含まれます。抜粋の長さは `--snippet-lines <n>` で調整でき(デフォルト: 8、最大: 20)、minified / transpiled で 1 行が極端に長いファイルでは `--max-line-width <n>` を使って各行を最も強い一致周辺へクランプできます(`0` でクランプ解除、デフォルト: 512、最大: 4096)。長い行の焦点は `--snippet-focus <leftmost|quality|proximity>` で制御でき、`quality` がデフォルト、`leftmost` は従来の最左一致、`proximity` は近接した複数トークンを優先します。クランプされた行はスニペット内に `...(+N)...` マーカーが入り、JSON / MCP 出力では `highlights[].truncated` / `highlights[].original_line_length` でも検出できます。
検索 JSON には `match_origins` と `match_facets` も含まれ、コード、コメント、文字列リテラル、正規表現リテラル、CLI ヘルプ文言のどこで一致したかをツール側で区別できます。各 highlight にも個別の `match_origins` が付き、`--exclude-comments` と `--exclude-strings` はこの facet を使ってコメントのみ、または文字列系のみの一致を隠します。
同じ facet は result、highlight、match-facet の各レベルで `test_file`、`test_symbol`、`test_fixture` boolean も返します。`test_fixture` はテストらしいファイルまたはインデックス済み test method 内の文字列系一致を示し、`--exclude-fixtures` は実コードの一致を残したまま fixture だけの一致を隠します。

Expand Down
21 changes: 21 additions & 0 deletions changelog.d/unreleased/3388.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
category: added
issues:
- 3388
affected:
- src/CodeIndex/Cli/QueryCommandRunner.cs
- src/CodeIndex/Cli/JsonOutputContracts.cs
- src/CodeIndex/Cli/ConsoleUi.cs
- src/CodeIndex/Cli/CliFlagSchema.cs
- tests/CodeIndex.Tests/ConsoleUiTests.cs
- tests/CodeIndex.Tests/QueryCommandRunnerSearchTests.cs
- USER_GUIDE.md
---

## English

- **Search supports grouped count ranking (#3388)** — `cdidx search --group-by file|symbol --count` now ranks broad search results by file or enclosing symbol, with JSON output for audit triage.

## 日本語

- **search が grouped count ranking に対応しました (#3388)** — `cdidx search --group-by file|symbol --count` で、広い検索結果を file または enclosing symbol 別にランク付けできるようにしました。audit triage 用の JSON 出力にも対応しています。
20 changes: 20 additions & 0 deletions changelog.d/unreleased/3481.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
category: added
issues:
- 3481
affected:
- src/CodeIndex/Cli/QueryCommandRunner.cs
- src/CodeIndex/Cli/SearchAuditRecipes.cs
- src/CodeIndex/Cli/ConsoleUi.cs
- src/CodeIndex/Cli/CliFlagSchema.cs
- tests/CodeIndex.Tests/QueryCommandRunnerSearchTests.cs
- USER_GUIDE.md
---

## English

- **Search supports named ad hoc batches with compact snippets (#3481)** — `cdidx search --named-query <name>=<query>` can now be repeated to run related searches with grouped results, and `search --format compact` preserves bounded snippet, match line, highlight, and truncation context.

## 日本語

- **search が compact snippet 付きの名前付き ad hoc batch に対応しました (#3481)** — `cdidx search --named-query <name>=<query>` を繰り返して関連検索を grouped result として実行できるようになり、`search --format compact` は bounded snippet、match line、highlight、truncation context を保持します。
3 changes: 2 additions & 1 deletion src/CodeIndex/Cli/CliFlagSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ private static IReadOnlyList<CliFlag> BuildAll()
new() { Name = "--query", ValuePlaceholder = "<query>", Description = "Literal query", Commands = Set(QueryCommands) },
new() { Name = "--recipe", ValuePlaceholder = "<name>", Description = "Search: run a built-in audit recipe query set", Commands = Set("search") },
new() { Name = "--list-recipes", Description = "Search: list built-in audit recipes", Commands = Set("search") },
new() { Name = "--named-query", ValuePlaceholder = "<name>=<query>", Description = "Search: add one named ad hoc batch query", Commands = Set("search") },
new() { Name = "--open-issues", ValuePlaceholder = "<path>", Description = "Preflight issue drafts against open issue JSON", Commands = Set("search", "suggestions") },
new() { Name = "--status", ValuePlaceholder = "<status>", Description = "Suggestions: filter by suggestion status", Commands = Set("suggestions") },
new() { Name = "--category", ValuePlaceholder = "<category>", Description = "Suggestions: filter by category", Commands = Set("suggestions") },
Expand Down Expand Up @@ -320,7 +321,7 @@ private static IReadOnlyList<CliFlag> BuildAll()
new() { Name = "--depth", ValuePlaceholder = "<n>", Description = "Map: cap module depth; impact: deprecated alias for --max-hops", Commands = Set("impact", "map") },
new() { Name = "--with-paths", Description = "Impact: include shortest call chains per caller", Commands = Set("impact") },
new() { Name = "--reverse", Description = "Reverse direction (show dependents)", Commands = Set("deps") },
new() { Name = "--group-by", ValuePlaceholder = "<symbol|file|statement>", Description = "Hotspots: choose grouping unit", Commands = Set("hotspots") },
new() { Name = "--group-by", ValuePlaceholder = "<file|symbol|statement>", Description = "Search: group --count rows by file or symbol; hotspots: choose grouping unit", Commands = Set("hotspots", "search") },
new() { Name = "--group-by-name", Description = "Hotspots: collapse same-name rows; JSON paths capped per group", Commands = Set("hotspots") },
new() { Name = "--check", Description = "Verify status freshness/readiness", Commands = Set("status") },
new() { Name = "--config", Description = "Print effective configuration with source attribution", Commands = Set("status") },
Expand Down
Loading
Loading