did-it-search 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. did_it_search-0.4.0/.github/run-action.py +91 -0
  2. did_it_search-0.4.0/LICENSE +21 -0
  3. did_it_search-0.4.0/MANIFEST.in +4 -0
  4. did_it_search-0.4.0/PKG-INFO +179 -0
  5. did_it_search-0.4.0/README.md +168 -0
  6. did_it_search-0.4.0/action.yml +28 -0
  7. did_it_search-0.4.0/examples/plain_rg.py +21 -0
  8. did_it_search-0.4.0/examples/reference_adapter.py +9 -0
  9. did_it_search-0.4.0/pyproject.toml +25 -0
  10. did_it_search-0.4.0/setup.cfg +4 -0
  11. did_it_search-0.4.0/src/did_it_search.egg-info/PKG-INFO +179 -0
  12. did_it_search-0.4.0/src/did_it_search.egg-info/SOURCES.txt +42 -0
  13. did_it_search-0.4.0/src/did_it_search.egg-info/dependency_links.txt +1 -0
  14. did_it_search-0.4.0/src/did_it_search.egg-info/entry_points.txt +2 -0
  15. did_it_search-0.4.0/src/did_it_search.egg-info/top_level.txt +1 -0
  16. did_it_search-0.4.0/src/diditsearch/__init__.py +1 -0
  17. did_it_search-0.4.0/src/diditsearch/__main__.py +4 -0
  18. did_it_search-0.4.0/src/diditsearch/baseline.py +205 -0
  19. did_it_search-0.4.0/src/diditsearch/cli.py +250 -0
  20. did_it_search-0.4.0/src/diditsearch/explain.py +319 -0
  21. did_it_search-0.4.0/src/diditsearch/explain_cli.py +67 -0
  22. did_it_search-0.4.0/src/diditsearch/fixtures.py +74 -0
  23. did_it_search-0.4.0/src/diditsearch/pi_adapter.mjs +139 -0
  24. did_it_search-0.4.0/src/diditsearch/pi_replay.py +156 -0
  25. did_it_search-0.4.0/src/diditsearch/reference.py +129 -0
  26. did_it_search-0.4.0/src/diditsearch/runner.py +177 -0
  27. did_it_search-0.4.0/src/diditsearch/summary.py +40 -0
  28. did_it_search-0.4.0/study/README.md +23 -0
  29. did_it_search-0.4.0/study/pi-11895.json +100 -0
  30. did_it_search-0.4.0/study/prepare.py +27 -0
  31. did_it_search-0.4.0/study/responses/astra.md +11 -0
  32. did_it_search-0.4.0/study/responses/opus.md +40 -0
  33. did_it_search-0.4.0/study/responses/sol.md +20 -0
  34. did_it_search-0.4.0/tests/test_action.py +114 -0
  35. did_it_search-0.4.0/tests/test_baseline.py +148 -0
  36. did_it_search-0.4.0/tests/test_change_cli.py +76 -0
  37. did_it_search-0.4.0/tests/test_cli.py +117 -0
  38. did_it_search-0.4.0/tests/test_explain.py +209 -0
  39. did_it_search-0.4.0/tests/test_explain_cli.py +150 -0
  40. did_it_search-0.4.0/tests/test_fixtures.py +84 -0
  41. did_it_search-0.4.0/tests/test_pi_adapter.py +218 -0
  42. did_it_search-0.4.0/tests/test_pi_replay.py +94 -0
  43. did_it_search-0.4.0/tests/test_reference.py +138 -0
  44. did_it_search-0.4.0/tests/test_runner.py +136 -0
@@ -0,0 +1,91 @@
1
+ """Run the installed CLI against a consumer checkout and write its step summary."""
2
+
3
+ import os
4
+ import re
5
+ import subprocess
6
+ import sys
7
+ import venv
8
+ from html import escape
9
+ from pathlib import Path
10
+ from tempfile import TemporaryDirectory
11
+
12
+
13
+ def relative_path(value, name):
14
+ path = Path(value)
15
+ if path.anchor or ".." in path.parts:
16
+ raise ValueError(f"{name} must be relative to the checkout: {value!r}")
17
+ return path
18
+
19
+
20
+ def checkout_path(root, path):
21
+ resolved = (root / path).resolve()
22
+ if not resolved.is_relative_to(root):
23
+ raise ValueError(f"Path points outside the checkout: {path}")
24
+ return resolved
25
+
26
+
27
+ def baseline_path(root, path, tmp):
28
+ if os.environ["GITHUB_EVENT_NAME"] != "pull_request":
29
+ return checkout_path(root, path)
30
+ sha = os.environ.get("DIDITSEARCH_PR_BASE_SHA", "")
31
+ if not re.fullmatch(r"[0-9a-fA-F]{40}", sha):
32
+ raise ValueError("The pull request base SHA must be a full Git commit ID.")
33
+
34
+ git = ["git", "--no-replace-objects", "-C", str(root), "cat-file"]
35
+ if subprocess.run([*git, "-e", f"{sha}^{{commit}}"], capture_output=True).returncode:
36
+ raise ValueError(f"Pull request base commit {sha} is unavailable. Set checkout fetch-depth to 0.")
37
+ result = subprocess.run([*git, "blob", f"{sha}:{path.as_posix()}"], capture_output=True)
38
+ if result.returncode:
39
+ if subprocess.run([*git, "-e", f"{sha}:{path.as_posix()}"], capture_output=True).returncode:
40
+ raise ValueError(f"Baseline {path} is missing from the PR base commit {sha}. "
41
+ "Merge the reviewed baseline into the base branch before enabling this check.")
42
+ raise ValueError(f"Could not read baseline {path} from pull request base commit {sha}.")
43
+ baseline = tmp / "baseline.json"
44
+ baseline.write_bytes(result.stdout)
45
+ return baseline
46
+
47
+
48
+ def install_cli(action, env_dir):
49
+ python = env_dir / ("Scripts/python.exe" if os.name == "nt" else "bin/python")
50
+ try:
51
+ venv.create(env_dir, with_pip=True)
52
+ subprocess.run([str(python), "-I", "-m", "pip", "--disable-pip-version-check", "install",
53
+ "--no-deps", str(action)], cwd=action, check=True)
54
+ except subprocess.CalledProcessError as exc:
55
+ raise ValueError(f"Could not install did-it-search in the action's Python environment (exit {exc.returncode}).") from exc
56
+ return python
57
+
58
+
59
+ def main():
60
+ summary = Path(os.environ["GITHUB_STEP_SUMMARY"])
61
+ try:
62
+ root = Path(os.environ["GITHUB_WORKSPACE"]).resolve()
63
+ project = checkout_path(root, relative_path(os.environ["DIDITSEARCH_PROJECT_DIR"], "project-dir"))
64
+ if not project.is_dir():
65
+ raise ValueError(f"Project directory does not exist: {project.relative_to(root)}")
66
+ path = relative_path(os.environ["DIDITSEARCH_BASELINE"], "baseline")
67
+ with TemporaryDirectory(prefix="didit-action-", dir=os.environ.get("RUNNER_TEMP"),
68
+ ignore_cleanup_errors=True) as name:
69
+ tmp = Path(name)
70
+ baseline = baseline_path(root, path, tmp)
71
+ python = install_cli(Path(os.environ["GITHUB_ACTION_PATH"]).resolve(), tmp / "venv")
72
+ result = subprocess.run(
73
+ [str(python), "-I", "-X", "utf8", "-m", "diditsearch", "compare", "--baseline",
74
+ str(baseline), "--tool", "pi", "--markdown"],
75
+ cwd=project, env={**os.environ, "PI_OFFLINE": "1"}, stdout=subprocess.PIPE,
76
+ )
77
+ if result.returncode not in (0, 1, 2) or not result.stdout.strip():
78
+ raise ValueError(f"Compare failed to produce a Markdown report (exit {result.returncode}).")
79
+ with summary.open("ab") as out:
80
+ out.write(result.stdout)
81
+ return result.returncode
82
+ except (OSError, ValueError) as exc:
83
+ message = " ".join(str(exc).splitlines())
84
+ print(f"did-it-search: {message}", file=sys.stderr)
85
+ with summary.open("a", encoding="utf-8") as out:
86
+ out.write(f"## Search regression check — ERROR\n\n<pre>{escape(message)}</pre>\n")
87
+ return 2
88
+
89
+
90
+ if __name__ == "__main__":
91
+ sys.exit(main())
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Anson Huang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,4 @@
1
+ recursive-include examples *.py
2
+ recursive-include tests *.py
3
+ recursive-include study *.py *.md *.json
4
+ include action.yml .github/run-action.py
@@ -0,0 +1,179 @@
1
+ Metadata-Version: 2.4
2
+ Name: did-it-search
3
+ Version: 0.4.0
4
+ Summary: Explain repository search failures and check for regressions in the answers search tools give coding agents.
5
+ License-Expression: MIT
6
+ Project-URL: Repository, https://github.com/yyzquwu/did-it-search
7
+ Requires-Python: >=3.11
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Dynamic: license-file
11
+
12
+ # Did It Search?
13
+
14
+ Explain an empty repository search. Run it where you work to see whether a literal was missing, the file glob selected nothing, or the search could only cover part of the requested path.
15
+
16
+ ## Try it on this repository
17
+
18
+ Install [ripgrep](https://github.com/BurntSushi/ripgrep#installation). With `uvx`, try the release on any local directory:
19
+
20
+ ```sh
21
+ uvx did-it-search explain load_settings . --glob '*.py'
22
+ ```
23
+
24
+ For a persistent CLI installation, use Python 3.11+:
25
+
26
+ ```sh
27
+ python -m pip install did-it-search==0.4.0
28
+ ```
29
+
30
+ From the root of this checkout, try the same search twice:
31
+
32
+ ```sh
33
+ did-it-search explain createGrepTool src/diditsearch --glob '*.rs'
34
+ rg -n -F -- createGrepTool src/diditsearch
35
+ ```
36
+
37
+ The first command exits 1 because the glob selects zero files. The second finds `createGrepTool` in `pi_adapter.mjs`. To try your own search, replace the literal and directory. Add `--json` for a machine-readable result.
38
+
39
+ ![Terminal recording of an empty Rust glob and the follow-up that finds createGrepTool in pi_adapter.mjs](https://raw.githubusercontent.com/yyzquwu/did-it-search/v0.4.0/docs/explain.gif)
40
+
41
+ `explain` needs only Python and ripgrep after installation. It runs locally with a five-second budget by default. Use `--timeout 15` to allow more time. Exit 0 means a confirmed match. Exit 1 means the search completed with no match or selected zero files. Exit 2 means coverage was partial, the path was missing, or the command encountered an error. In JSON, `files_searched` is null when the count is unknown. A suggested follow-up runs only if you choose to execute it.
42
+
43
+ Directory globs are relative to the directory you pass. The command checks ignore rules even for an explicitly named file or a positive glob. It can count excluded paths by name and leaves their contents unread. Counts include eligible empty files. Binary files are identified by NUL bytes after ripgrep decodes the input. A confirmed text match can coexist with exclusions.
44
+
45
+ Ripgrep normally skips hidden entries during a directory search. To inspect a hidden directory such as `.github/workflows`, name it directly. Printed follow-ups use PowerShell on Windows and shell quoting on Unix. Use the JSON argument list for programmatic execution.
46
+
47
+ Large generated trees can exhaust the 4 MiB ripgrep output budget while the command counts excluded filenames. A confirmed match is still reported if exclusion counting stops early. For an output or process limit, narrow the path to the source directory you want to check. `--timeout` changes the time budget only.
48
+
49
+ ## Catch search regressions in CI
50
+
51
+ The GitHub Action checks the Pi SDK installed in your project against a reviewed baseline. In the example PR, downgrading Pi from 1.5.1 to 1.5.0 lost the match in `migrations/main/a.js`. The Action reported that regression and kept three previously accepted differences quiet. [Example pull request](https://github.com/yyzquwu/did-it-search/pull/1)
52
+
53
+ From a project with a local installation of `@earendil-works/pi-coding-agent`, install the kit and record today's behavior. Use Python 3.11+, Git, ripgrep on PATH, and Node 22.19+ (Node 24 recommended).
54
+
55
+ ```sh
56
+ python -m pip install "git+https://github.com/yyzquwu/did-it-search.git@v0.4.0"
57
+ did-it-search baseline --tool pi
58
+ did-it-search compare --tool pi
59
+ ```
60
+
61
+ **First adoption takes two PRs.** In the first, review and merge `.did-it-search.json` into the target branch. It records the installed package version, a fingerprint of the eight fixtures, and the outcomes you accept. In the next PR, add the workflow step. If the base branch has no baseline yet, the check exits 2 even when the PR itself adds one.
62
+
63
+ In a pull-request workflow with `contents: read`, set up Node and ripgrep and include these steps:
64
+
65
+ ```yaml
66
+ - uses: actions/checkout@v7
67
+ with:
68
+ fetch-depth: 0
69
+ persist-credentials: false
70
+ - run: npm ci
71
+ - uses: yyzquwu/did-it-search@v0.4.0
72
+ ```
73
+
74
+ On a PR the Action compares the candidate's installed SDK with the baseline from the PR's base commit. A contributor can inspect the package versions, request, expected result and native tool response in the job summary. New regressions and changed failures exit 1. Improvements and known failures pass. An incompatible baseline or a tool that couldn't run exits 2. Use `compare --json` to consume the comparison outside GitHub. The existing `check` command still grades absolute conformance.
75
+
76
+ **Updating the baseline.** To accept a deliberate change, run `baseline --replace` with the proposed SDK installed and review the JSON diff. Merge just the approved baseline first, then run the dependency PR against it. Replacing the baseline in the dependency PR itself leaves that check comparing against the old expectations. If you use a required check, the two-PR sequence lets reviewers approve the new expectation without disabling it.
77
+
78
+ Baseline and comparison evidence displays temporary fixture roots as `<fixture>`. When the package lives in a subdirectory, set both `project-dir: web` and `baseline: web/.did-it-search.json` (substitute your directory). Use checkout at the workspace root. Events other than `pull_request`, including `merge_group`, use the checked-out baseline.
79
+
80
+ ## Replay the Pi fix
81
+
82
+
83
+ Install Git, ripgrep (`rg`), and Node.js 22.19+ (tested with Node 24). With `uvx` available, run:
84
+
85
+ ```sh
86
+ uvx --from git+https://github.com/yyzquwu/did-it-search.git@v0.4.0 did-it-search replay pi
87
+ ```
88
+
89
+ The replay runs Pi's grep implementation from both sides of [the merged fix](https://github.com/earendil-works/pi/pull/11895) on two fixtures. Both requests ask for the literal `hello` under `repo` with the glob `migrations/main/*.js`. One fixture has the match at `repo/migrations/main/a.js`. The other puts the only match under `repo/nested/migrations/main/b.js`, outside the requested glob. That second case catches a fix that simply widens the search. Add `--json` to inspect the results.
90
+
91
+ ### Observed result
92
+
93
+ The pinned replay needs network access to GitHub and the npm registry. It checks the two commit IDs and the downloaded package hashes, loads the upstream code in a temporary directory, and runs without a model or API key. Exit 0 means the historical regression was reproduced, 1 means the behavior differed from the expected transition, and 2 means the replay could not be evaluated.
94
+
95
+ | Pinned Pi revision | Target in `migrations/main` | Only the deeper decoy contains `hello` |
96
+ | --- | --- | --- |
97
+ | Before · `1f7c685` | `No matches found` | `No matches found` |
98
+ | After · `6bf2ab9` | `migrations/main/a.js:1: console.log("hello");` | `No matches found` |
99
+
100
+ The [recorded replay](study/pi-11895.json) contains the grades and native responses. Did It Search? v0.1 also missed the target. The reference adapter now evaluates directory globs relative to the requested search directory.
101
+
102
+ ### Grade your local Pi installation
103
+
104
+ The local check loads `@earendil-works/pi-coding-agent` from the calling project's Node dependencies. On the target-file case, published versions 1.4.0 and 1.5.0 missed the match; 1.5.1 and 1.6.0 found it. From the project containing Pi, run:
105
+
106
+ ```sh
107
+ did-it-search check --tool pi --case glob-root-hit --case glob-root-decoy --json
108
+ ```
109
+
110
+ Remove the two `--case` options to grade all eight cases. The JSON report retains Pi's native response when it fits alongside the diagnostic in the adapter's 64 KiB output limit. A generic empty result can pass the decoy and still fail a case that requires a specific exclusion reason.
111
+
112
+ ## See the ignored caller
113
+
114
+ From this checkout, with Python 3.11+, Git and ripgrep (`rg`) on your PATH:
115
+
116
+ ```sh
117
+ python -m pip install .
118
+ did-it-search demo
119
+ ```
120
+
121
+ The demo runs a real search for `legacy_export`. Ripgrep exits 1 with empty stdout. The reference adapter reports incomplete coverage and one ignored file. The fixture's answer key locates the caller at `generated/client.ts`. The adapter learns the exclusion by comparing file lists and leaves the ignored file's contents unread.
122
+
123
+ ```sh
124
+ did-it-search check
125
+ did-it-search check --json --adapter examples/plain_rg.py
126
+ did-it-search fixtures search-fixtures
127
+ ```
128
+
129
+ The reference passes all eight cases. The example wraps ordinary ripgrep output and handles a missing path. It passes four cases and exits 1. Try `did-it-search check --adapter examples/reference_adapter.py` for a passing external adapter. The last command above writes eight repositories and `cases.json` to a new directory so you can open a case in your own agent. Run the installed CLI as `python -m diditsearch` when preferred.
130
+
131
+ | Fixture | Search truth | Expected status | Exclusions |
132
+ | --- | --- | --- | --- |
133
+ | hit | A text file contains the literal | `matched` | none |
134
+ | miss | A text file was searched and the literal is absent | `no_match` | none |
135
+ | missing-path | The requested path does not exist | `missing_path` | none |
136
+ | empty-glob | The project contains Python and the request selects Rust files | `no_files` | none |
137
+ | ignored-caller | The only call is in a generated file excluded by Git ignore rules | `partial` | `ignored` |
138
+ | binary | The only occurrence is in a file containing NUL bytes | `partial` | `binary` |
139
+ | glob-root-hit | The match lies inside the requested directory and matches its folder glob | `matched` | none |
140
+ | glob-root-decoy | Only a lookalike folder outside the glob contains the literal | `no_match` | none |
141
+
142
+ ## Check your search adapter in CI
143
+
144
+ Implement the [adapter protocol](#adapter-protocol) around your tool's actual search output. Run this step after installing the kit in your CI environment:
145
+
146
+ ```yaml
147
+ - name: Check search diagnostics
148
+ run: did-it-search check --json --adapter ci/search_adapter.py
149
+ ```
150
+
151
+ Exit 0 means every case agreed with its answer key. Exit 1 means at least one answer disagreed. Exit 2 means the kit or adapter could not run a check, including malformed responses and timeouts. The runner continues after an adapter error and includes the other results. The fixture names and answer key are public, so this is a regression suite for maintainers.
152
+
153
+ ### Adapter protocol
154
+
155
+ The runner starts a new process in each fixture's root and sends one UTF-8 JSON object followed by a newline on stdin.
156
+
157
+ ```json
158
+ {"pattern":"legacy_export","path":".","glob":null}
159
+ ```
160
+
161
+ Return one UTF-8 JSON object without a byte-order mark on stdout (up to 64 KiB) and exit 0 when your tool can describe the outcome. Diagnostic logs may go to stderr. If your adapter keeps a fixture open and cleanup fails, the runner preserves the report and its exit status. Stderr identifies the temporary directory for later removal.
162
+
163
+ ```json
164
+ {"status":"partial","detail":"An ignored file was outside the text search.","skipped":["ignored"]}
165
+ ```
166
+
167
+ `pattern` is a case-sensitive literal. `path` is relative to the fixture root. `glob` is an optional ripgrep-style file glob. The kit grades the status and the set of exclusion reasons. Omit `skipped` for an empty set. The human-readable `detail` string is included in the report. An adapter that cannot determine a cause should report its own result honestly so a mismatch remains visible.
168
+
169
+ Put `--adapter` last: everything after it is the adapter command. A first argument ending in `.py` is resolved relative to the calling directory and run with the kit's Python. Other executables may be given by path or name on PATH. Additional arguments are passed unchanged, so use absolute paths for any other files your command needs. Use `--timeout 5` before `--adapter` to set a per-process timeout in seconds.
170
+
171
+ ## What happened with real agents?
172
+
173
+ In a three-project pilot, each of three agents got the same initial result for three different situations. All three investigated and answered correctly. The [pilot](study/README.md) includes the prompts, first search outputs, follow-ups and final answers. You can recreate its project directories locally.
174
+
175
+ ## Reference scope
176
+
177
+ The reference searches small, stable fixtures. It includes dotfiles and skips Git metadata and links. It applies the glob and in-tree ignore rules even to explicitly named files. Native ripgrep can search a named file that these rules exclude. The reference enumerates filenames under ignored directories to account for exclusions. It reads up to 1 MiB plus one byte per eligible file to identify binary or oversized inputs. A UTF-16 file containing NUL bytes is classified as binary, even though native ripgrep can decode a UTF-16 BOM. A confirmed hit takes precedence and still reports exclusions.
178
+
179
+ Run the tests from an installed checkout with `python -m unittest discover -s tests`.
@@ -0,0 +1,168 @@
1
+ # Did It Search?
2
+
3
+ Explain an empty repository search. Run it where you work to see whether a literal was missing, the file glob selected nothing, or the search could only cover part of the requested path.
4
+
5
+ ## Try it on this repository
6
+
7
+ Install [ripgrep](https://github.com/BurntSushi/ripgrep#installation). With `uvx`, try the release on any local directory:
8
+
9
+ ```sh
10
+ uvx did-it-search explain load_settings . --glob '*.py'
11
+ ```
12
+
13
+ For a persistent CLI installation, use Python 3.11+:
14
+
15
+ ```sh
16
+ python -m pip install did-it-search==0.4.0
17
+ ```
18
+
19
+ From the root of this checkout, try the same search twice:
20
+
21
+ ```sh
22
+ did-it-search explain createGrepTool src/diditsearch --glob '*.rs'
23
+ rg -n -F -- createGrepTool src/diditsearch
24
+ ```
25
+
26
+ The first command exits 1 because the glob selects zero files. The second finds `createGrepTool` in `pi_adapter.mjs`. To try your own search, replace the literal and directory. Add `--json` for a machine-readable result.
27
+
28
+ ![Terminal recording of an empty Rust glob and the follow-up that finds createGrepTool in pi_adapter.mjs](https://raw.githubusercontent.com/yyzquwu/did-it-search/v0.4.0/docs/explain.gif)
29
+
30
+ `explain` needs only Python and ripgrep after installation. It runs locally with a five-second budget by default. Use `--timeout 15` to allow more time. Exit 0 means a confirmed match. Exit 1 means the search completed with no match or selected zero files. Exit 2 means coverage was partial, the path was missing, or the command encountered an error. In JSON, `files_searched` is null when the count is unknown. A suggested follow-up runs only if you choose to execute it.
31
+
32
+ Directory globs are relative to the directory you pass. The command checks ignore rules even for an explicitly named file or a positive glob. It can count excluded paths by name and leaves their contents unread. Counts include eligible empty files. Binary files are identified by NUL bytes after ripgrep decodes the input. A confirmed text match can coexist with exclusions.
33
+
34
+ Ripgrep normally skips hidden entries during a directory search. To inspect a hidden directory such as `.github/workflows`, name it directly. Printed follow-ups use PowerShell on Windows and shell quoting on Unix. Use the JSON argument list for programmatic execution.
35
+
36
+ Large generated trees can exhaust the 4 MiB ripgrep output budget while the command counts excluded filenames. A confirmed match is still reported if exclusion counting stops early. For an output or process limit, narrow the path to the source directory you want to check. `--timeout` changes the time budget only.
37
+
38
+ ## Catch search regressions in CI
39
+
40
+ The GitHub Action checks the Pi SDK installed in your project against a reviewed baseline. In the example PR, downgrading Pi from 1.5.1 to 1.5.0 lost the match in `migrations/main/a.js`. The Action reported that regression and kept three previously accepted differences quiet. [Example pull request](https://github.com/yyzquwu/did-it-search/pull/1)
41
+
42
+ From a project with a local installation of `@earendil-works/pi-coding-agent`, install the kit and record today's behavior. Use Python 3.11+, Git, ripgrep on PATH, and Node 22.19+ (Node 24 recommended).
43
+
44
+ ```sh
45
+ python -m pip install "git+https://github.com/yyzquwu/did-it-search.git@v0.4.0"
46
+ did-it-search baseline --tool pi
47
+ did-it-search compare --tool pi
48
+ ```
49
+
50
+ **First adoption takes two PRs.** In the first, review and merge `.did-it-search.json` into the target branch. It records the installed package version, a fingerprint of the eight fixtures, and the outcomes you accept. In the next PR, add the workflow step. If the base branch has no baseline yet, the check exits 2 even when the PR itself adds one.
51
+
52
+ In a pull-request workflow with `contents: read`, set up Node and ripgrep and include these steps:
53
+
54
+ ```yaml
55
+ - uses: actions/checkout@v7
56
+ with:
57
+ fetch-depth: 0
58
+ persist-credentials: false
59
+ - run: npm ci
60
+ - uses: yyzquwu/did-it-search@v0.4.0
61
+ ```
62
+
63
+ On a PR the Action compares the candidate's installed SDK with the baseline from the PR's base commit. A contributor can inspect the package versions, request, expected result and native tool response in the job summary. New regressions and changed failures exit 1. Improvements and known failures pass. An incompatible baseline or a tool that couldn't run exits 2. Use `compare --json` to consume the comparison outside GitHub. The existing `check` command still grades absolute conformance.
64
+
65
+ **Updating the baseline.** To accept a deliberate change, run `baseline --replace` with the proposed SDK installed and review the JSON diff. Merge just the approved baseline first, then run the dependency PR against it. Replacing the baseline in the dependency PR itself leaves that check comparing against the old expectations. If you use a required check, the two-PR sequence lets reviewers approve the new expectation without disabling it.
66
+
67
+ Baseline and comparison evidence displays temporary fixture roots as `<fixture>`. When the package lives in a subdirectory, set both `project-dir: web` and `baseline: web/.did-it-search.json` (substitute your directory). Use checkout at the workspace root. Events other than `pull_request`, including `merge_group`, use the checked-out baseline.
68
+
69
+ ## Replay the Pi fix
70
+
71
+
72
+ Install Git, ripgrep (`rg`), and Node.js 22.19+ (tested with Node 24). With `uvx` available, run:
73
+
74
+ ```sh
75
+ uvx --from git+https://github.com/yyzquwu/did-it-search.git@v0.4.0 did-it-search replay pi
76
+ ```
77
+
78
+ The replay runs Pi's grep implementation from both sides of [the merged fix](https://github.com/earendil-works/pi/pull/11895) on two fixtures. Both requests ask for the literal `hello` under `repo` with the glob `migrations/main/*.js`. One fixture has the match at `repo/migrations/main/a.js`. The other puts the only match under `repo/nested/migrations/main/b.js`, outside the requested glob. That second case catches a fix that simply widens the search. Add `--json` to inspect the results.
79
+
80
+ ### Observed result
81
+
82
+ The pinned replay needs network access to GitHub and the npm registry. It checks the two commit IDs and the downloaded package hashes, loads the upstream code in a temporary directory, and runs without a model or API key. Exit 0 means the historical regression was reproduced, 1 means the behavior differed from the expected transition, and 2 means the replay could not be evaluated.
83
+
84
+ | Pinned Pi revision | Target in `migrations/main` | Only the deeper decoy contains `hello` |
85
+ | --- | --- | --- |
86
+ | Before · `1f7c685` | `No matches found` | `No matches found` |
87
+ | After · `6bf2ab9` | `migrations/main/a.js:1: console.log("hello");` | `No matches found` |
88
+
89
+ The [recorded replay](study/pi-11895.json) contains the grades and native responses. Did It Search? v0.1 also missed the target. The reference adapter now evaluates directory globs relative to the requested search directory.
90
+
91
+ ### Grade your local Pi installation
92
+
93
+ The local check loads `@earendil-works/pi-coding-agent` from the calling project's Node dependencies. On the target-file case, published versions 1.4.0 and 1.5.0 missed the match; 1.5.1 and 1.6.0 found it. From the project containing Pi, run:
94
+
95
+ ```sh
96
+ did-it-search check --tool pi --case glob-root-hit --case glob-root-decoy --json
97
+ ```
98
+
99
+ Remove the two `--case` options to grade all eight cases. The JSON report retains Pi's native response when it fits alongside the diagnostic in the adapter's 64 KiB output limit. A generic empty result can pass the decoy and still fail a case that requires a specific exclusion reason.
100
+
101
+ ## See the ignored caller
102
+
103
+ From this checkout, with Python 3.11+, Git and ripgrep (`rg`) on your PATH:
104
+
105
+ ```sh
106
+ python -m pip install .
107
+ did-it-search demo
108
+ ```
109
+
110
+ The demo runs a real search for `legacy_export`. Ripgrep exits 1 with empty stdout. The reference adapter reports incomplete coverage and one ignored file. The fixture's answer key locates the caller at `generated/client.ts`. The adapter learns the exclusion by comparing file lists and leaves the ignored file's contents unread.
111
+
112
+ ```sh
113
+ did-it-search check
114
+ did-it-search check --json --adapter examples/plain_rg.py
115
+ did-it-search fixtures search-fixtures
116
+ ```
117
+
118
+ The reference passes all eight cases. The example wraps ordinary ripgrep output and handles a missing path. It passes four cases and exits 1. Try `did-it-search check --adapter examples/reference_adapter.py` for a passing external adapter. The last command above writes eight repositories and `cases.json` to a new directory so you can open a case in your own agent. Run the installed CLI as `python -m diditsearch` when preferred.
119
+
120
+ | Fixture | Search truth | Expected status | Exclusions |
121
+ | --- | --- | --- | --- |
122
+ | hit | A text file contains the literal | `matched` | none |
123
+ | miss | A text file was searched and the literal is absent | `no_match` | none |
124
+ | missing-path | The requested path does not exist | `missing_path` | none |
125
+ | empty-glob | The project contains Python and the request selects Rust files | `no_files` | none |
126
+ | ignored-caller | The only call is in a generated file excluded by Git ignore rules | `partial` | `ignored` |
127
+ | binary | The only occurrence is in a file containing NUL bytes | `partial` | `binary` |
128
+ | glob-root-hit | The match lies inside the requested directory and matches its folder glob | `matched` | none |
129
+ | glob-root-decoy | Only a lookalike folder outside the glob contains the literal | `no_match` | none |
130
+
131
+ ## Check your search adapter in CI
132
+
133
+ Implement the [adapter protocol](#adapter-protocol) around your tool's actual search output. Run this step after installing the kit in your CI environment:
134
+
135
+ ```yaml
136
+ - name: Check search diagnostics
137
+ run: did-it-search check --json --adapter ci/search_adapter.py
138
+ ```
139
+
140
+ Exit 0 means every case agreed with its answer key. Exit 1 means at least one answer disagreed. Exit 2 means the kit or adapter could not run a check, including malformed responses and timeouts. The runner continues after an adapter error and includes the other results. The fixture names and answer key are public, so this is a regression suite for maintainers.
141
+
142
+ ### Adapter protocol
143
+
144
+ The runner starts a new process in each fixture's root and sends one UTF-8 JSON object followed by a newline on stdin.
145
+
146
+ ```json
147
+ {"pattern":"legacy_export","path":".","glob":null}
148
+ ```
149
+
150
+ Return one UTF-8 JSON object without a byte-order mark on stdout (up to 64 KiB) and exit 0 when your tool can describe the outcome. Diagnostic logs may go to stderr. If your adapter keeps a fixture open and cleanup fails, the runner preserves the report and its exit status. Stderr identifies the temporary directory for later removal.
151
+
152
+ ```json
153
+ {"status":"partial","detail":"An ignored file was outside the text search.","skipped":["ignored"]}
154
+ ```
155
+
156
+ `pattern` is a case-sensitive literal. `path` is relative to the fixture root. `glob` is an optional ripgrep-style file glob. The kit grades the status and the set of exclusion reasons. Omit `skipped` for an empty set. The human-readable `detail` string is included in the report. An adapter that cannot determine a cause should report its own result honestly so a mismatch remains visible.
157
+
158
+ Put `--adapter` last: everything after it is the adapter command. A first argument ending in `.py` is resolved relative to the calling directory and run with the kit's Python. Other executables may be given by path or name on PATH. Additional arguments are passed unchanged, so use absolute paths for any other files your command needs. Use `--timeout 5` before `--adapter` to set a per-process timeout in seconds.
159
+
160
+ ## What happened with real agents?
161
+
162
+ In a three-project pilot, each of three agents got the same initial result for three different situations. All three investigated and answered correctly. The [pilot](study/README.md) includes the prompts, first search outputs, follow-ups and final answers. You can recreate its project directories locally.
163
+
164
+ ## Reference scope
165
+
166
+ The reference searches small, stable fixtures. It includes dotfiles and skips Git metadata and links. It applies the glob and in-tree ignore rules even to explicitly named files. Native ripgrep can search a named file that these rules exclude. The reference enumerates filenames under ignored directories to account for exclusions. It reads up to 1 MiB plus one byte per eligible file to identify binary or oversized inputs. A UTF-16 file containing NUL bytes is classified as binary, even though native ripgrep can decode a UTF-16 BOM. A confirmed hit takes precedence and still reports exclusions.
167
+
168
+ Run the tests from an installed checkout with `python -m unittest discover -s tests`.
@@ -0,0 +1,28 @@
1
+ name: Did It Search?
2
+ description: Compare the consumer project's installed Pi grep against a reviewed search baseline.
3
+ inputs:
4
+ project-dir:
5
+ description: Checkout-relative directory with the installed Pi npm package. Install the project's dependencies and put Node.js 22.19+ and ripgrep on PATH before this action.
6
+ required: false
7
+ default: '.'
8
+ baseline:
9
+ description: Checkout-relative baseline path. On pull_request, read this path from the base SHA in Git history (use checkout with fetch-depth 0). On other events, read it from the current checkout.
10
+ required: false
11
+ default: .did-it-search.json
12
+ runs:
13
+ using: composite
14
+ steps:
15
+ - id: runtime
16
+ uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0
17
+ with:
18
+ python-version: '3.11'
19
+ update-environment: 'false'
20
+ - name: Compare installed Pi search
21
+ shell: bash
22
+ working-directory: ${{ github.action_path }}
23
+ env:
24
+ DIDITSEARCH_PYTHON: ${{ steps.runtime.outputs.python-path }}
25
+ DIDITSEARCH_PROJECT_DIR: ${{ inputs.project-dir }}
26
+ DIDITSEARCH_BASELINE: ${{ inputs.baseline }}
27
+ DIDITSEARCH_PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
28
+ run: '"$DIDITSEARCH_PYTHON" -I -X utf8 "$GITHUB_ACTION_PATH/.github/run-action.py"'
@@ -0,0 +1,21 @@
1
+ """Example adapter that exposes the limitations of a conventional empty result."""
2
+ import json
3
+ import subprocess
4
+ import sys
5
+ from pathlib import Path
6
+
7
+ req = json.loads(sys.stdin.buffer.read())
8
+ args = ["rg", "--no-config", "--fixed-strings", "--color=never"]
9
+ if req["glob"] is not None:
10
+ args += ["-g", req["glob"]]
11
+ run = subprocess.run([*args, "--", req["pattern"], req["path"]], capture_output=True)
12
+ if run.returncode == 2 and not Path(req["path"]).exists():
13
+ status, detail = "missing_path", "The requested path does not exist."
14
+ elif run.returncode == 0:
15
+ status, detail = "matched", "ripgrep reported a hit."
16
+ elif run.returncode == 1:
17
+ status, detail = "no_match", "ripgrep returned exit 1."
18
+ else:
19
+ print(run.stderr.decode("utf-8", "replace").strip(), file=sys.stderr)
20
+ sys.exit(2)
21
+ print(json.dumps({"status": status, "detail": detail}))
@@ -0,0 +1,9 @@
1
+ """Expose the reference implementation through the same protocol as a user adapter."""
2
+ import json
3
+ import sys
4
+ from pathlib import Path
5
+
6
+ from diditsearch.reference import inspect_search
7
+
8
+ request = json.loads(sys.stdin.buffer.read().decode("utf-8"))
9
+ print(json.dumps(inspect_search(Path.cwd(), request)))
@@ -0,0 +1,25 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "did-it-search"
7
+ version = "0.4.0"
8
+ description = "Explain repository search failures and check for regressions in the answers search tools give coding agents."
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ dependencies = []
12
+ license = "MIT"
13
+ license-files = ["LICENSE"]
14
+
15
+ [project.urls]
16
+ Repository = "https://github.com/yyzquwu/did-it-search"
17
+
18
+ [project.scripts]
19
+ did-it-search = "diditsearch.cli:main"
20
+
21
+ [tool.setuptools.packages.find]
22
+ where = ["src"]
23
+
24
+ [tool.setuptools.package-data]
25
+ diditsearch = ["*.mjs"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+