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
4 changes: 4 additions & 0 deletions DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -955,10 +955,12 @@ For the AI agent search-rule template, see [AI Integration](USER_GUIDE.md#ai-int
|---|---|
| Human-readable default | Query commands (`search`, `definition`, `references`, `callers`, `callees`, `symbols`, `files`, `excerpt`, `map`, `inspect`, `suggestions`) default to **human-readable output**. |
| `--json` | Emits JSON lines output, one JSON object per line, designed for easy parsing by AI agents. |
| `--count --json` envelope | Count-only JSON for `search`, `definition`, `references`, `callers`, `callees`, `symbols`, `files`, `find`, and `impact` is a single automation-oriented object. It always includes `count`, applied `query_context`, freshness metadata (`indexed_file_count`, `indexed_at`, `freshness_available`), and trust flags `degraded` / `authoritative_count`; commands with matched-file totals also include `files` and compatibility alias `file_count`. `authoritative_count=false` means a readiness or graph/exact trust signal made the count non-authoritative, while the freshness fields describe the indexed snapshot used for the count. |
| `search --json` sentinel | Appends a final `{"done":true,"count":N,"interrupted":false}` sentinel after result rows, including zero-result responses, so stream consumers can distinguish a clean end from a truncated/interrupted stream. |
| `--json-envelope` commands | Applies to `search`, `definition`, `references`, `callers`, `callees`, `symbols`, `files`, `find`, `excerpt`, `map`, `inspect`, `outline`, `status`, `validate`, `languages`, `impact`, `deps`, `unused`, and `hotspots`. |
| `--json-envelope` shape | Wraps the per-line `--json` stream into a single `{"metadata": {...}, "results": [...]}` document. `metadata` carries `api_version`, `command`, `cdidx_version`, `elapsed_ms`, `db_path`, `result_count`, `exit_code`, and, when applicable, `query_normalized` and `indexed_at_head_sha`. |
| Envelope migration | `--json-envelope` implies `--json`, so callers do not need to pass both. The default output remains the legacy NDJSON / array form for one release; the envelope will become the default in the next major release, when the flat form becomes opt-in via `--json-flat`. |
| `find --all` scan summary | `find` requires either repeatable `--path <glob>` filters or explicit `--all`. `--all` scans indexed files repo-wide with safety caps and cannot be combined with `--path`. JSON count output includes `candidate_files`, `files_scanned`, `lines_scanned`, `scan_truncated`, `scan_cap_reached`, optional `scan_truncation_reason`, and the active `candidate_file_limit` / `line_scan_limit`; human count output writes the same scan summary to stderr. |

#### JSON output API version contract

Expand Down Expand Up @@ -3095,10 +3097,12 @@ AI エージェント向け検索ルールのテンプレートについては
|---|---|
| human-readable default | query command(`search`、`definition`、`references`、`callers`、`callees`、`symbols`、`files`、`excerpt`、`map`、`inspect`、`suggestions`)は既定で**人間向け出力**です。 |
| `--json` | JSON lines output(1 行 1 JSON object)に切り替えます。AI agent が容易に parse できるよう設計されています。 |
| `--count --json` envelope | `search`、`definition`、`references`、`callers`、`callees`、`symbols`、`files`、`find`、`impact` の count-only JSON は単一の自動化向け object です。常に `count`、適用済み `query_context`、freshness metadata(`indexed_file_count`、`indexed_at`、`freshness_available`)、trust flag の `degraded` / `authoritative_count` を含みます。matched-file total を持つ command は `files` と互換 alias の `file_count` も含みます。`authoritative_count=false` は readiness または graph/exact trust signal により count が authoritative ではないことを示し、freshness field は count に使った index snapshot を説明します。 |
| `search --json` sentinel | result row の後に、0 件応答も含めて最後の `{"done":true,"count":N,"interrupted":false}` sentinel を追加します。stream consumer は clean end と truncated / interrupted stream を区別できます。 |
| `--json-envelope` 対象 command | `search`、`definition`、`references`、`callers`、`callees`、`symbols`、`files`、`find`、`excerpt`、`map`、`inspect`、`outline`、`status`、`validate`、`languages`、`impact`、`deps`、`unused`、`hotspots`。 |
| `--json-envelope` shape | per-line `--json` stream を単一の `{"metadata": {...}, "results": [...]}` document に包みます。`metadata` は `api_version`、`command`、`cdidx_version`、`elapsed_ms`、`db_path`、`result_count`、`exit_code`、該当時は `query_normalized` と `indexed_at_head_sha` を持ちます。 |
| envelope migration | `--json-envelope` は `--json` を imply するため、caller は両方を指定する必要がありません。既定 output は 1 release の間 legacy NDJSON / array form のままです。次の major release では envelope が既定になり、flat form は `--json-flat` による opt-in になります。 |
| `find --all` scan summary | `find` は repeatable な `--path <glob>` か明示的な `--all` のどちらかを要求します。`--all` は safety cap 付きで index 済みファイルを repo-wide に走査し、`--path` とは併用できません。JSON count output は `candidate_files`、`files_scanned`、`lines_scanned`、`scan_truncated`、`scan_cap_reached`、任意の `scan_truncation_reason`、有効な `candidate_file_limit` / `line_scan_limit` を含みます。human count output は同じ scan summary を stderr に出します。 |

#### JSON 出力 API バージョン契約

Expand Down
25 changes: 20 additions & 5 deletions USER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,14 @@ source line hits the body byte cap, continuation still advances to the following
source line because body paging is line-based. `inspect --json` also includes
`body_mode` metadata so clients can see whether body content was requested,
whether it is present, and which follow-up flags to use.
Count-only JSON (`--count --json` or `--format count` where supported) is a
single object with `count`, applied `query_context`, freshness metadata
(`indexed_file_count`, `indexed_at`, `freshness_available`), and trust flags
`degraded` / `authoritative_count`. Commands that count matched files also
include `files`; the older `file_count` field remains as a compatibility alias
with the same value and is not scheduled for removal before the next major
release. New consumers should read `files` and treat `authoritative_count=false`
as a signal to inspect the accompanying readiness or graph/exact trust fields.

```bash
cdidx search authenticate --json # ndjson stream, one result per line
Expand All @@ -329,11 +337,6 @@ cdidx inspect Compute --body-only # definitions with body_content only
cdidx inspect Compute --body --body-start 40 --body-lines 40
```

For `cdidx find --count --json`, `files` is the canonical matched-file count.
The older `file_count` field remains as a deprecated compatibility alias with
the same value and is not scheduled for removal before the next major release;
new consumers should read `files`.

## Editor and index portability

Use `cdidx export ctags` when an editor wants the traditional ctags file format
Expand Down Expand Up @@ -1086,9 +1089,11 @@ cdidx excerpt src/CodeIndex/Cli/GitHelper.cs --start 19 --end 28 --before 3 --af
```bash
cdidx find "graph table" --path src/CodeIndex/Cli/QueryCommandRunner.cs
cdidx find "Graph Table" --path src/CodeIndex/Cli/QueryCommandRunner.cs --exact --before 1 --after 1 --json
cdidx find "guard" --all --count --json
```

`find` fills the gap between repo-wide `search` and line-number-based `excerpt`: when you already know the target file, it returns matching line numbers, columns, and short surrounding context from the indexed file without falling back to raw-text tools. The query text is capped at 1,000 characters, matching `search`.
Use `--path <glob>` for a bounded file set, or pass `--all` to opt in to a repo-wide indexed-file scan with safety caps. `--all` and `--path` are mutually exclusive. Count JSON includes scan summary fields such as `candidate_files`, `files_scanned`, `lines_scanned`, `scan_truncated`, `scan_cap_reached`, `candidate_file_limit`, and `line_scan_limit`; human count output writes the scan summary to stderr.

### List files

Expand Down Expand Up @@ -2667,6 +2672,14 @@ shorthand です。definition body が返却 slice より長い場合は
`--body-lines` で page size を指定できます。`inspect --json` には `body_mode`
metadata も含まれるため、body content が要求済みか、存在するか、次に使う flag が何かを
client 側で判断できます。
count-only JSON(対応 command の `--count --json` または `--format count`)は、
`count`、適用済み `query_context`、freshness metadata(`indexed_file_count`、
`indexed_at`、`freshness_available`)、trust flag の `degraded` /
`authoritative_count` を持つ単一 object です。matched file を数える command は
`files` も含みます。古い `file_count` field は同じ値の互換 alias として残っており、
少なくとも次の major release までは削除予定はありません。新しい consumer は
`files` を読み、`authoritative_count=false` の場合は同じ payload の readiness または
graph/exact trust field を確認してください。

```bash
cdidx search authenticate --json # ndjson stream、1 行 1 result
Expand Down Expand Up @@ -3442,9 +3455,11 @@ cdidx excerpt src/CodeIndex/Cli/GitHelper.cs --start 19 --end 28 --before 3 --af
```bash
cdidx find "graph table" --path src/CodeIndex/Cli/QueryCommandRunner.cs
cdidx find "Graph Table" --path src/CodeIndex/Cli/QueryCommandRunner.cs --exact --before 1 --after 1 --json
cdidx find "guard" --all --count --json
```

`find` は、リポジトリ全体を対象にする `search` と、行番号が必要な `excerpt` の間を埋めるコマンドです。対象ファイルが既に分かっているときに、raw text ツールへ戻らずに、インデックス済みファイルから一致行番号・列番号・短い前後文脈を返します。query text は `search` と同じく 1,000 文字までです。
対象を絞る場合は `--path <glob>` を使い、repo-wide の index 済みファイル走査が必要な場合だけ `--all` を明示します。`--all` と `--path` は併用できません。count JSON には `candidate_files`、`files_scanned`、`lines_scanned`、`scan_truncated`、`scan_cap_reached`、`candidate_file_limit`、`line_scan_limit` などの scan summary field が入り、human count output では同じ scan summary が stderr に出ます。

### ファイル一覧

Expand Down
20 changes: 20 additions & 0 deletions changelog.d/unreleased/3446.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
category: fixed
issues:
- 3446
affected:
- src/CodeIndex/Cli/CliFlagSchema.cs
- src/CodeIndex/Cli/ConsoleUi.cs
- src/CodeIndex/Cli/QueryCommandRunner.cs
- tests/CodeIndex.Tests/QueryCommandRunnerMapTests.cs
- tests/CodeIndex.Tests/QueryCommandRunnerSymbolTests.cs
- tests/CodeIndex.Tests/QueryCommandRunnerInspectTests.cs
---

## English

- **Format aliases now work consistently on map, symbols, and inspect (#3446)** — `map` and `inspect` accept `--format json` / `--format compact`, `symbols` accepts `--format json` / `--format count`, and unsupported format combinations now return command-specific hints.

## 日本語

- **map、symbols、inspect の format alias を揃えました (#3446)** — `map` と `inspect` は `--format json` / `--format compact` を受け付け、`symbols` は `--format json` / `--format count` を受け付けます。未対応の format 組み合わせではコマンド別のヒントを返します。
21 changes: 21 additions & 0 deletions changelog.d/unreleased/3560.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
category: added
issues:
- 3560
affected:
- src/CodeIndex/Cli/CliFlagSchema.cs
- src/CodeIndex/Cli/ConsoleUi.cs
- src/CodeIndex/Cli/QueryCommandRunner.cs
- src/CodeIndex/Database/DbReader.FilesStatus.cs
- src/CodeIndex/Mcp/McpToolHandlers.cs
- src/CodeIndex/Models/QueryResults.cs
- tests/CodeIndex.Tests/QueryCommandRunnerSearchTests.cs
---

## English

- **Explicit repository-wide find scans are now bounded and observable (#3560)** — `find --all` searches every indexed file with candidate-file and line-scan caps, and `find --count` now reports scan summaries in JSON and human output.

## 日本語

- **リポジトリ全体の find scan を明示的かつ観測可能にしました (#3560)** — `find --all` は候補ファイル数と走査行数の上限付きで全インデックス済みファイルを検索し、`find --count` は JSON と human 出力で scan summary を返します。
17 changes: 17 additions & 0 deletions changelog.d/unreleased/3566.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
category: fixed
issues:
- 3566
affected:
- src/CodeIndex/Cli/QueryCommandRunner.cs
- tests/CodeIndex.Tests/QueryCommandRunnerTests.cs
- tests/CodeIndex.Tests/QueryCommandRunnerGraphTests.cs
---

## English

- **Count-only JSON responses now include a stable automation envelope (#3566)** — `search`, `symbols`, `definition`, `files`, `references`, `callers`, `callees`, `impact`, and `find` count JSON include applied query context, freshness metadata, file-count aliases where relevant, and `authoritative_count`/`degraded` readiness signals.

## 日本語

- **count-only JSON に自動化向け envelope を追加しました (#3566)** — `search`、`symbols`、`definition`、`files`、`references`、`callers`、`callees`、`impact`、`find` の count JSON が、適用済み query context、freshness メタデータ、必要な file count alias、`authoritative_count` / `degraded` の readiness signal を含むようになりました。
8 changes: 4 additions & 4 deletions src/CodeIndex/Cli/CliFlagSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ internal static class CliFlagSchema
private static readonly string[] RankByCommands = ["callers", "callees"];
private static readonly string[] ByBucketCommands = ["unused"];
private static readonly string[] UnusedFilterCommands = ["unused"];
private static readonly string[] AllResultCommands = ["goto"];
private static readonly string[] AllResultCommands = ["goto", "find"];

private static readonly string[] SinceCommands = ["search", "definition", "symbols", "files", "suggestions"];
private static readonly string[] ByteFormatCommands = ["files", "map"];
Expand Down Expand Up @@ -199,7 +199,7 @@ internal static class CliFlagSchema

private static readonly string[] FormatCommands =
[
"search", "definition", "references", "callers", "callees", "find", "validate", "deps", "suggestions",
"search", "definition", "references", "callers", "callees", "symbols", "find", "map", "inspect", "validate", "deps", "suggestions",
];

private static readonly string[] ProfileCommands =
Expand All @@ -226,7 +226,7 @@ private static IReadOnlyList<CliFlag> BuildAll()
new() { Name = "--json", Description = "JSON output; search/files/validate also accept --json=array for a single JSON array", Commands = Set(JsonCommands) },
new() { Name = "--pretty", Description = "Pretty-print JSON output with indentation", Commands = Set(JsonCommands), TopLevel = true },
new() { Name = "--compact", Description = "AI-oriented compact JSON with capped list sections and truncation metadata", Commands = Set(CompactJsonCommands) },
new() { Name = "--format", ValuePlaceholder = "<text|json|count|compact|csv|tsv|lsp|qf|sarif|markdown|issue-drafts>", Description = "Standard output format for token budgets, editor integrations, and CI; search recipes and suggestions export also accept issue-drafts", Commands = Set(FormatCommands) },
new() { Name = "--format", ValuePlaceholder = "<text|json|count|compact|csv|tsv|lsp|qf|sarif|markdown|issue-drafts>", Description = "Standard output format for token budgets, editor integrations, and CI; supported values vary by command, and search recipes/suggestions export also accept issue-drafts", Commands = Set(FormatCommands) },
new() { Name = "--quiet", ShortName = "-q", Description = "Suppress informational stderr output; errors still print", Commands = Set(AllCommands.ToArray()), TopLevel = true },
new() { Name = "--silent", Description = "Alias for --quiet", Commands = Set(AllCommands.ToArray()), TopLevel = true },
new() { Name = "--color", ValuePlaceholder = "<auto|always|never>", Description = "Color output mode", Commands = Set(), TopLevel = true },
Expand Down Expand Up @@ -261,7 +261,7 @@ private static IReadOnlyList<CliFlag> BuildAll()
new() { Name = "--by-bucket", Description = "Unused: include per-bucket grouped result arrays in JSON output", Commands = Set(ByBucketCommands) },
new() { Name = "--bucket", ValuePlaceholder = "<bucket>", Description = "Unused: return only one confidence bucket", Commands = Set(UnusedFilterCommands) },
new() { Name = "--min-confidence", ValuePlaceholder = "<medium|low>", Description = "Unused: return symbols at or above this confidence", Commands = Set(UnusedFilterCommands) },
new() { Name = "--all", Description = "goto: return all matching LSP locations instead of requiring a single target", Commands = Set(AllResultCommands) },
new() { Name = "--all", Description = "goto: return all matching LSP locations; find: search all indexed files instead of requiring --path", Commands = Set(AllResultCommands) },
new() { Name = "--rank-by", ValuePlaceholder = "<weighted|count|kind>", Description = "Rank callers/callees by weighted structural score, raw count, or kind bucket", Commands = Set(RankByCommands) },
new() { Name = "--raw-kinds", Description = "Show raw reference kinds instead of logical graph kinds", Commands = Set(RawKindsCommands) },
new() { Name = "--count", Description = "Count only", Commands = Set(CountCommands) },
Expand Down
Loading
Loading