Repository navigation
Description
Problem or Motivation
search_code (InvestigationTools.search_code in src/devops_cli/roadmap/refine/refine_investigation.py) runs git grep -n -I -F -i over the whole tree at the staged commit, with no path filter. cut then keeps at most 240 lines and 8,000 characters. git grep gives the lines in path order. So lines from CHANGELOG.md, .agents, .github, docs and openspec/changes/archive fill the answer before any line from src/ or tests/. The answer ends with a cut notice that does not say where the left-out matches are. The stage toolbox (StageTools) and the refine investigation share this tool.
Measured at origin/main 499b42c with the same command and the same cut:
| Text | Matches | In the archive | In src/ or tests/ |
Lines kept | Kept lines in src/ or tests/ |
|---|---|---|---|---|---|
ci test |
5,368 | 4,360 | 765 | 23 | 0 |
ci docs |
791 | 526 | 220 | 27 | 0 |
check_proposal( |
117 | 11 | 98 | 18 | 0 |
read_spec |
138 | 59 | 62 | 15 | 0 |
trace gate |
103 | 55 | 27 | 14 | 0 |
Effects on the stage job:
search_codeanswers of plan and review runs were about 19M characters in 3 days (devops_cli_roadmap_tool_answer_chars), about as large as theread_fileanswers.- In the comment sample of 54 items (8,213 calls), 3,251 searches used only 2,467 distinct texts.
- The planner searched
ci testin 18 items, got no code line, and then read all ofsrc/devops_cli/commands/ci.py(about 23.7k tokens).
Proposed Solution & Architectural Design
- Leave out
openspec/changes/archive/by default with agit greppathspec exclude (:(exclude)openspec/changes/archive). - Put the lines of code files first, then the lines of documents (
.md,.rst,.txt,CHANGELOG.md). Keep the path order inside each class. - Cut each line at about 200 characters.
- End a cut answer with the count of left-out matches for each top directory, such as
left out: src 742, tests 23, docs 31. - Add an optional
pathargument: a directory or a glob pathspec. With it the model can search the archive or one folder. - Change the tool description so that the model knows items 1, 4 and 5.
The rules apply to every target repository: they use the file class and the pathspec, not the layout of devops-cli.
Target Subsystem
SDLC, Git & PR Governance: src/devops_cli/roadmap/refine/refine_investigation.py (search_code, cut), src/devops_cli/roadmap/stage/stage_tools.py, the tool rules of src/devops_cli/ai/tasks/.
Existing Tool Considered
git grep pathspec magic (:(exclude), :(glob)) does the filter, and the tool already uses git grep. ripgrep has file types, but it reads the working tree, not a commit, and it is a new runner dependency. Cost to build: about 0.6M tokens and 2 hours (estimate), about 60 lines and 6 tests. Keep cost: low.
Acceptance Criteria
- Test first: in a fixture repository where an archive file and a long
CHANGELOG.mdline match before asrc/line, the answer holds thesrc/line, holds no archive line, and ends with the left-out count for each top directory. - Test first:
search_code(text, path="openspec/changes/archive")returns the archive lines. - A test: no answer line is longer than the line cut.
- Measure:
devops roadmap eval stage --replaykeeps every known-bad plan refused. From the stage comments, for 7 days: the characters of eachsearch_codeanswer, the searches of each run, and theread_filecalls onsrc/devops_cli/commands/ci.pyandsrc/devops_cli/roadmap/stage/stage_change.py. - Live proof after release: in real Service stage runs, the share of
search_codeanswers that hold at least one code line when the commit has code matches (baseline: 0 of the 5 texts above).
Dependencies
None. It is separate from the command card item, which removes the need to search for the devops ci forms.
Standards Compliance
- I confirm this proposal aligns with AGENTS.md engineering principles (cyclomatic complexity <= 10, nesting <= 4 blocks, zero bare exceptions, tests that cover the changed lines).
Alternatives check of 2026-11-23: in-use.
The repository already uses this tool.
Tool: git/git (https://github.com/git/git), NOASSERTION, last activity 2026-11-22, maintained.
Reason: Searches found no tool that shapes code-search output; git grep pathspec magic covers the default archive exclusion and an optional path filter, but the code-first order, per-line cut and left-out counts stay custom.
Covers:
:(exclude)pathspec leaves out the archive by default- A pathspec argument limits the search to one directory
--countgives exact totals for left-out counts
Lacks:
- No code-before-document ordering of matches
- No per-line length cut
- No left-out counts per top directory
- No tool description for the model
Proposed design
Problem statement
Fix search_code to put code lines first, leave out the archive by default, accept an optional path, cut long lines and report left-out counts. Today git grep returns matches in path order, so CHANGELOG.md, .agents, .github, docs and the archive fill the answer before src/ or tests/. The cut notice does not say where the left-out matches are. Stage and refine runs then spend tokens on large file reads.
Acceptance criteria
Requirement: Default archive exclusion
search_code SHALL leave out openspec/changes/archive from a search that names no path.
Scenario: Archive match is not in the default answer
- WHEN
search_code("needle")runs on a fixture commit where an archive file and asrc/file hold the text - THEN the answer holds the
src/line and holds no archive line.
Requirement: Optional path filter
search_code SHALL accept an optional path argument that limits the search to one repository directory or git pathspec.
Scenario: Archive search uses the path argument
- WHEN
search_code("needle", path="openspec/changes/archive")runs on the fixture commit - THEN the answer holds the archive line.
Requirement: Code lines before document lines
search_code SHALL put matches from code files before matches from .md, .rst and .txt documents.
Scenario: Code match comes before a document match
- WHEN a fixture commit holds a matching
CHANGELOG.mdline and a matchingsrc/line and the answer keeps both - THEN the
src/line comes before theCHANGELOG.mdline.
Requirement: Per-line cut
search_code SHALL cut each formatted match line to at most 200 characters.
Scenario: Long match line is shortened
- WHEN a fixture commit holds a matching line longer than 200 characters
- THEN no line of the answer is longer than 200 characters.
Requirement: Left-out counts by top directory
search_code SHALL end a cut answer with the count of left-out matches for each top directory.
Scenario: Cut answer reports the left-out counts
- WHEN the fixture commit holds more matches than the answer keeps in
src,testsanddocs - THEN the answer ends with a line such as
left out: src <n>, tests <n>, docs <n>with the left-out count for each directory.
Requirement: Tool description states the search rules
The search_code tool description SHALL state the default archive exclusion, the optional path argument and the left-out counts.
Scenario: Tool description tells the model the rules
- WHEN the tool list of
InvestigationToolsandStageToolsis built - THEN each
search_codedescription names the archive exclusion, thepathargument and the left-out counts.
Requirement: Stage toolbox shares the search
StageTools SHALL use the same search_code behavior as InvestigationTools.
Scenario: Stage toolbox applies the archive exclusion
- WHEN
StageTools.search_coderuns on the fixture commit - THEN the answer holds the
src/line and holds no archive line.
Requirement: Stage replay keeps refusals
The stage replay SHALL keep every known-bad plan refused after the search change.
Scenario: Stage replay keeps refusals
- WHEN
uv run devops roadmap eval stage --replayruns - THEN every known-bad plan is refused.
Existing Tool Considered
git/git (https://github.com/git/git) has verdict in-use; see the alternatives check in the issue body for what it covers and lacks. The proposal uses its pathspec magic for the default archive exclusion and the optional path filter. It adds the code-first order, the 200-character line cut, the per-top-directory left-out counts and the tool description in search_code, which the tool lacks. The issue estimates about 60 lines and 6 tests, 0.6M tokens and 2 hours to build, with low keep cost.
Key questions
- How should
search_codeexclude the archive and still let the model search it?: Use a default:(exclude)openspec/changes/archivepathspec. Add an optionalpathargument that replaces the default filter. Validate the path as a repository-relative git pathspec. (best practice) [sources: src/devops_cli/roadmap/refine/refine_investigation.py]- Chosen: Default exclude plus optional path. git grep pathspec magic covers the exclusion and the path filter, and one code path serves both jobs.
- Rejected: Exclude only with a separate flag. The model must know a second argument and can forget it.
- Rejected: No default exclusion. Archive lines still fill the answer.
- How should the tool count left-out matches when
git grep --max-countcaps each file?: When the answer is cut, rungit grep --countfor the same search. Subtract the kept matches for each top directory. Report the difference. Keep the per-file line cap for the line output. (best practice) [sources: src/devops_cli/roadmap/refine/refine_investigation.py]- Chosen: Second
git grep --countcall. It gives exact totals without holding every match line in memory. - Rejected: Count from the capped lines. A file with more matches than the cap undercounts the left-out matches.
- Rejected: Remove the per-file cap. A file with millions of matches can exhaust memory.
- Chosen: Second
- How should
StageToolsandInvestigationToolsshare the new search behavior?: Keep onesearch_codeimplementation inInvestigationTools. HaveStageToolscall it. Do not copy the filter, order, cut and count code. (best practice) [sources: src/devops_cli/roadmap/refine/refine_investigation.py, src/devops_cli/roadmap/stage/stage_tools.py]- Chosen: One shared implementation. Both jobs get the same behavior and one test set.
- Rejected: Separate implementation in each toolbox. The two copies can drift and double the tests.
- How should the tool order code lines before document lines?: Classify
.md,.rstand.txtpaths as documents. Put all other paths first. Keep the git path order inside each class. (best practice) [sources: src/devops_cli/roadmap/refine/refine_investigation.py]- Chosen: Suffix-based document class. It is simple, works for any target repository, and follows the issue.
- Rejected: Repository-specific directory list. It breaks the rule for other target repositories.
- Rejected: No ordering. Documents still fill the answer before code.
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Nov 13, 2026
Both target the cut function in refine_investigation.py, but 4341 fixes the missing character-limit notice while the candidate reorders results, excludes archive, and adds a path argument.devops-cli-service commentedon Nov 17, 2026
Alternatives check: in-use
Reason:
git grepalready searches the tree at a given commit, and its pathspec magic (:(exclude),:(glob)) covers the archive exclusion and the optional directory/glob filter that the issue asks for; it is also the grep the tool already runs. It does not order code before documents, cut long lines, or count left-out matches per top directory, so the rest of the fix stays insearch_code.The repository already uses this tool.
Tool: git/git (https://github.com/git/git)
Covers:
:(exclude)openspec/changes/archivepathspec leaves the archive out by defaultLacks:
CHANGELOG.md,docs/and the archive still precedesrc/andtests/search_codeTools considered:
Searches run:
Sources:
Checked on 2026-11-17. A person decides what this means for the item. The check changes no label and closes no issue.
devops-cli-service commentedon Nov 18, 2026
Status set to Ready at 9be129e (see proposed design in issue body).
Moved to new items: #6239.
chore(main): release 0.247.0 (#7752)
devops-cli-service commentedon Nov 29, 2026
Released in v0.247.0: https://github.com/dan-petty/devops-cli/releases/tag/v0.247.0
devops-cli-service commentedon Nov 29, 2026
Live since 2026-11-29 16:17 UTC