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
14 changes: 14 additions & 0 deletions DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,13 @@ previews are sanitized and bounded. JSON failures write the envelope to stdout
and leave stderr empty. Human failures write the matching coded `Error`,
`Hint`, and `Usage` lines to stderr and leave stdout empty.

Unsupported `search --regex` / `search --all` diagnostics add a command-specific,
display-only `find` recovery contract. Preserve exact normalized argument
semantics in typed `alternative_command.argv`, render both POSIX-shell and
PowerShell forms from that argv, mark the command as not executed, and report
non-equivalent options or blockers instead of emitting a lossy alternative.
Do not include implicit workspace defaults such as an undisclosed data directory.

Resolve project-config dependency before calling `CdidxConfigFile.Load`.
Process-static commands (`license`, `--version`, help forms, completions, and
subcommand help) must not discover or parse project config. `validate-config`
Expand Down Expand Up @@ -3798,6 +3805,13 @@ sanitization し、上限を適用してから merge します。JSON の失敗
出し、stderr を空に保ちます。human の失敗は対応する code 付き `Error`、`Hint`、
`Usage` を stderr に出し、stdout を空に保ちます。

未対応の `search --regex` / `search --all` diagnostic は、command 固有で表示専用の
`find` recovery 契約を追加します。正規化した引数の semantics を型付き
`alternative_command.argv` に正確に保持し、その argv から POSIX shell と PowerShell
の両形式を生成し、未実行であることを明示してください。不正確な代替 command を出さず、
対応不能な option または blocker を報告し、未指定の data directory など暗黙の
workspace default を含めてはいけません。

`CdidxConfigFile.Load` を呼ぶ前に project-config 依存性を解決します。process-static な
command(`license`、`--version`、help 形式、completion、subcommand help)は project
config を探索・parse しません。`validate-config` と `config show` は有効な設定を
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ Bounded `map --compact` keeps the established top-level section arrays and compa

`find --all --json` also makes bounded scans explicit. Repository-wide case-insensitive ASCII literals of at least three characters use the trigram index to select candidate files before the existing line matcher verifies every result; regex, `--exact`, short, non-ASCII, legacy, unsynchronized, and actively rebuilding trigram-index queries use an explicit line-scan fallback. `search_strategy` and optional `search_fallback_reason` report which path ran. Default streaming JSON rows end with a terminal record containing `scan_complete`, `authoritative_rows`, verified file/line counts, active caps, truncation reason, and recovery guidance; count JSON carries the same scan state in its single result object through `authoritative_count`. Row formats that cannot carry this metadata, including JSON array and location-only formats, are rejected with `--all`; use text, NDJSON, or count output. A candidate-file or line-scan cap returns partial-result exit code `11` unless `--allow-partial` is set. Ordinary result-limit early stops remain exit `0` but report `scan_complete=false` and `result_limit_reached=true`.

`search --regex` and `search --all` remain unsupported because `search` keeps its indexed-query semantics. When every argument has an exact `find` mapping, the usage error now includes a shell-safe, display-only `cdidx find` alternative and never executes it. JSON errors expose typed `alternative_command` (`argv`, `posix_sh`, `powershell`, `display_only`, and `executed`), `alternative_reason`, `non_equivalent_options`, `alternative_blockers`, and `automatic_execution` fields. When a search-only option, conflicting `--path` / `--all` scope, or unsafe one-line value prevents an exact mapping, `alternative_command` is `null` and the diagnostic explains the difference instead of suggesting a lossy command.

Use it with AI tools or editors:

```bash
Expand Down Expand Up @@ -621,6 +623,8 @@ bounded な `map --compact` は、共通 metadata を追加しながら既存の

`find --all --json` も上限付き scan を明示します。3 文字以上の大文字小文字を区別しない ASCII literal は、trigram index で候補 file を選んだ後、既存の行 matcher ですべての結果を検証します。regex、`--exact`、短い query、非 ASCII query、旧 trigram index、同期 trigger が欠けた index、再構築中の index は明示的な line-scan fallback を使います。実行経路は `search_strategy` と任意の `search_fallback_reason` で確認できます。既定の streaming JSON row は `scan_complete`、`authoritative_rows`、検証済み file / line 数、有効な cap、切り詰め理由、復旧案内を含む終端レコードで終了します。count JSON は単一 result object の `authoritative_count` と同じ scan 状態を返します。この metadata を表現できない JSON array や location-only 形式は `--all` との組み合わせを拒否するため、text、NDJSON、count 出力を使ってください。candidate-file cap または line-scan cap に達した場合は、`--allow-partial` を指定しない限り partial-result 終了コード `11` を返します。通常の result limit による早期停止は終了コード `0` のままですが、`scan_complete=false` と `result_limit_reached=true` を報告します。

`search` は indexed query の semantics を維持するため、`search --regex` と `search --all` は引き続き未対応です。すべての引数を `find` へ正確に対応付けられる場合、usage error は shell-safe で表示専用の `cdidx find` 代替 command を示し、実行はしません。JSON error は型付きの `alternative_command`(`argv`、`posix_sh`、`powershell`、`display_only`、`executed`)、`alternative_reason`、`non_equivalent_options`、`alternative_blockers`、`automatic_execution` field を返します。search 固有 option、競合する `--path` / `--all` scope、安全な1行表示にできない値などで正確な対応付けができない場合、`alternative_command` は `null` となり、不正確な command を提案せず相違点を説明します。

AI tool や editor から使います。

```bash
Expand Down
2 changes: 2 additions & 0 deletions TESTING_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ Use `docs/test-doc-maintenance-plan.md` before moving oversized suites or adding
CLI parsing, command execution, and installer behavior. Index command coverage is split by run mode or feature area, and query command coverage is split by command family with partial test classes so shared console and fixture helpers stay centralized. Keep repeated query-result fixtures, such as overlapping chunk content used by multiple search deduplication tests, in narrow class-level helpers instead of duplicating local builders. `ProgramCliTests.cs` covers top-level entrypoint behavior that must be exercised through a subprocess, while `InstallScriptTests.cs` runs focused bash snippets against `install.sh` in library mode to lock in release-installer regressions without performing real network installs. Installer bundle-generation tests must also verify that `install.sh` is marked generated while every canonical `install_modules/` source remains unmarked.
Status-explain coverage must enumerate the source-generated `StatusResult` serializer properties and require every serialized top-level key to succeed without opening a database. Keep major readiness/trust/extension/maintenance/cap-hit metadata assertions, dotted-member resolution, bounded valid unknown candidates, and redaction of hostile field input in the same focused fixture so serialization and explainability cannot drift independently. Keep every structured explain response key registered for status `--fields` projection, and exercise the response through a bounded JSON projection that proves the outer envelope also omits runtime and path metadata.
Graph snippet-length validation uses one command/format matrix across `references`, `callers`, and `callees`. Keep explicit `--snippet-lines` fail-fast without `--body`, reject location-only and count output even when `--body` is present, preserve the zero/range errors, and retain successful text/JSON body excerpts through the accepted maximum. Also cover option-like literals supplied through `--query` and `--`, plus two-page bounded body projection with clean stderr, correct total counts, and cursor continuation. Top-level compact aliases must validate the original arguments before database access, and bounded count replay must preserve snippet-like query literals.
Search-to-find recovery coverage must exercise `--regex` and `--all` in human and JSON modes, option-shaped and shell-sensitive query values, normalized path/language/exclusion/limit arguments, and explicit non-equivalent or unsafe cases. Assert typed argv plus POSIX-shell and PowerShell displays, absence of implicit workspace defaults, and the no-execution markers; an unmappable request must return no alternative command.
C# `unused` partial-family coverage must reuse one multi-file fixture across regular JSON, compact, `--by-bucket`, and `--actionable`; include top-level and nested partial types, genuinely unused private members, an unrelated same-named family, a containing-type generic-arity collision, and a family-external occurrence in a matched peer file so semantic membership cannot regress into name-only, flattened-qualified-name, or whole-file evidence sharing.
`CliFlagSchemaTests.cs` and `ConsoleUiTests.cs` keep command help, runtime value validation, and each generated shell's option/value catalog aligned with `CliFlagSchema`, and check every Fish command scope against the shared per-command completion projection. When an accepted value or alias changes, assert its registry normalization plus command usage, runtime validation, and Bash / Zsh / Fish / PowerShell completion visibility; add the value to the schema instead of weakening this parity contract.
`ProgramRunnerTests.cs` enumerates `CliCommandCatalog.CommandSubcommands` and requires every valid nested verb to resolve to verb-specific usage with an example. It also pins destructive index confirmation and aggregate dependency-filter help, plus the read-only GitHub duplicate-preflight boundary for suggestion exports. Installer cancellation coverage must wait until the PID file contains a complete positive integer before cancelling, using a bounded dedicated waiter instead of a fixed-delay timer so parallel load cannot expose a redirection-created empty file.
Expand Down Expand Up @@ -1146,6 +1147,7 @@ dotnet test --filter "FullyQualifiedName~GitHelperTests"
CLI の引数解析、コマンド実行、installer 挙動のテスト。Index command coverage は run mode または機能領域ごとの partial suite に分割し、Query command coverage は command family ごとの partial test class に分割して、共有 console / fixture helper は一箇所に保ちます。`ProgramCliTests.cs` はグローバル引数の解釈や完全な CLI 起動フローのように subprocess 経由で確認すべき Program エントリポイント挙動を扱い、`InstallScriptTests.cs` は `install.sh` を library mode で source した bash snippet を実行して、実ネットワーク install を行わずに release installer の回帰を固定する。installer bundle 生成テストでは、`install.sh` が generated と判定される一方、canonical な `install_modules/` source はすべて unmarked のままであることも検証してください。
status explain の coverage は source-generated `StatusResult` serializer property を列挙し、database を開かずに serialized top-level key がすべて成功することを必須にします。主要な readiness / trust / extension / maintenance / cap-hit metadata、dot 区切り member resolution、unknown key に対する上限付きの有効な candidate、悪意ある field input の redaction を同じ focused fixture に置き、serialization と explainability が独立して drift しないようにしてください。structured explain response の全 key を status の `--fields` projection に登録し、outer envelope からも runtime / path metadata が省略されることを上限付き JSON projection で固定してください。
graph の snippet 長 validation は、`references`、`callers`、`callees` を横断する1つの command / format matrix で検証します。明示した `--snippet-lines` は `--body` なしで fail-fast し、`--body` があっても location-only / count 出力では拒否すること、zero / range error を維持すること、受理上限まで text / JSON の body excerpt が成功することを固定してください。さらに、`--query` と `--` で渡した option 風 literal、および stderr が空で total count と cursor continuation が正しい2ページの bounded body projection も検証してください。top-level compact alias は database access より前に原引数を検証し、bounded count replay は snippet 風の query literal を維持しなければなりません。
search から find への recovery coverage では、human / JSON mode の `--regex` と `--all`、option 風および shell-sensitive な query 値、正規化した path / language / exclude / limit 引数、明示的に非等価または unsafe な case を検証してください。型付き argv と POSIX shell / PowerShell 表示、暗黙の workspace default が含まれないこと、未実行 marker を固定し、対応不能な request が代替 command を返さないことを必須にします。
C# `unused` の partial-family coverage では、通常の JSON、compact、`--by-bucket`、`--actionable` で1つの multi-file fixture を共有してください。top-level / nested partial type、本当に未使用の private member、無関係な同名 family、containing type の generic-arity collision、matched peer file 内の family 外 occurrence を含め、semantic membership が name-only、平坦化された qualified name、または file 全体の evidence 共有へ戻らないことを固定します。
`CliFlagSchemaTests.cs` と `ConsoleUiTests.cs` は command help、runtime value validation、各生成 shell の option / value 全カタログを `CliFlagSchema` と同期させ、Fish の全 command scope を共有の command 別 completion 射影と照合します。受理値または alias を変更するときは、registry normalization に加えて command usage、runtime validation、Bash / Zsh / Fish / PowerShell completion への露出を検証し、この parity 契約を弱めず schema に値を追加してください。
`ProgramRunnerTests.cs` は `CliCommandCatalog.CommandSubcommands` を列挙し、すべての有効な nested verb が例を含む verb 固有 usage に解決されることを必須とします。さらに destructive な index confirmation、aggregate dependency filter help、suggestion export の read-only GitHub duplicate-preflight 境界を固定します。installer cancellation coverage は固定時間タイマーではなく上限付きの専用 waiter を使い、PID ファイルが完全な正の整数を含むまで待ってから cancel してください。これにより並列負荷下でも redirection によって作成された空ファイルを読みません。
Expand Down
20 changes: 20 additions & 0 deletions changelog.d/unreleased/4906.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
category: fixed
issues:
- 4906
affected:
- src/CodeIndex/Cli/QueryCommandRunner.Search.cs
- src/CodeIndex/Cli/QueryCommandRunner.SearchFindAlternative.cs
- tests/CodeIndex.Tests/QueryCommandRunnerSearchIssue4906Tests.cs
- README.md
- DEVELOPER_GUIDE.md
- TESTING_GUIDE.md
---

## English

- **Unsupported search scan flags now point safely to find (#4906)** — `search --regex` and `search --all` usage errors now provide a shell-safe, display-only `cdidx find` alternative when every argument maps exactly, expose typed recovery fields in JSON, and explain non-equivalent or unsafe requests without executing or suggesting a lossy command.

## 日本語

- **search の未対応 scan flag が find を安全に案内するようになりました (#4906)** — `search --regex` と `search --all` の usage error は、すべての引数を正確に対応付けられる場合に shell-safe で表示専用の `cdidx find` 代替 command を示し、JSON では型付き recovery field を返します。非等価または unsafe な request は、不正確な command の提案や実行をせず理由を説明します。
3 changes: 3 additions & 0 deletions src/CodeIndex/Cli/QueryCommandRunner.Search.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ private static int RunSearchCore(
options.InvocationMachineErrorOutputRequested = ProgramRunner.ContainsJsonOutputFlag(validationArgs);
using var exactLanguageScope = DbReader.BeginExactQueryLanguageScope(
options.Lang);
if (ReferenceEquals(invocationContext, QueryCommandInvocationContext.Search)
&& TryWriteSearchFindAlternativeError(validationArgs, options, jsonOptions))
return CommandExitCodes.UsageError;
if (TryWriteUnsupportedOptionError(
invocationContext,
validationArgs,
Expand Down
Loading
Loading