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
3 changes: 3 additions & 0 deletions dokimi/changelog.d/20261125_160000_copilot-grep-searched.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Fixed

- **A Copilot CLI `grep` tool call over a guidance file counts in `process.guidance_searched`** — the `copilot-json` converter turned a `grep` call into a bare `tool` event, so `grep` with `paths: "AGENTS.md"` and `output_mode: "content"` listed nothing. The event now carries `searched`, the call's `paths` (one string or a list) resolved from the start directory as a `view` path is, in `content` mode only; the default mode, `files_with_matches` and `count` print no line of a file, and a call with no `paths` names no file. A result that failed, is empty or says `No matches found.` drops it. A search adds no `read` event, so `tool_calls` and `guidance_read` do not change.
2 changes: 1 addition & 1 deletion dokimi/docs/events-format.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ depend on the kind:
| `command` | `text`; `rc` (integer, or `null` when no result came back); `rc_from: "success"` when Copilot reported a completion status without an exit code; `output` and `output_truncated` when the harness returned output; `searched` (a list of workspace paths) when a `grep`, `egrep`, `fgrep`, `rg` or `git grep` part of it named files and showed lines of them (see below) |
| `read` | `path` (absent on a refused relative read whose file is not known; a relative path joined to the working directory the CLI started in loses its `.` components and repeated `/`, while an absolute path, or a relative one with no working directory known, is kept as written; a `..` always stays as written, since the name before it may be a link); `rc` 0 or 1 when the harness reported one |
| `edit` | `path`; `rc`; `deleted` when the file was deleted |
| `tool` | `name`; `skill` on a `Skill` call; `searched` (one path) on a Claude Code `Grep` call whose `path` is given and whose `output_mode` is `content` |
| `tool` | `name`; `skill` on a `Skill` call; `searched` (one path) on a Claude Code `Grep` call whose `path` is given and whose `output_mode` is `content`; `searched` (the call's `paths`, one or a list) on a Copilot `grep` call whose `output_mode` is `content` and whose result is not empty, `No matches found.` or a failure |
| `probe` | `target`, `pattern`, `text`, `rc`: written by the runner after the `command` event it matched, never by a converter ([§4.1](repo-evaluation-contract.md#41-eventsjsonl)) |
| `choice` | `candidate`, `act` (install, import, use or remove), `path` (edit path or null). The runner writes these after their source event when the run names candidates. |
| `turn` | `turn` (the model call's index in the trace, from 0; a subagent's calls count too); `input` (uncached input), `output` (`null` on a Claude turn: its assistant records carry the output count from the start of the stream, not the call's billed count), `cache_read`, `cache_write`, `prompt_tokens` (the whole prompt: `input + cache_read + cache_write`); each `null` when the harness reported no such count (a Claude `prompt_tokens` sums the parts it reported, so it is low when a part is `null`) |
Expand Down
2 changes: 1 addition & 1 deletion dokimi/docs/repo-evaluation-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ parent's and subagents' together, so a grader need not:
| `failed_commands` | commands not denied whose `rc` is neither `0` nor `null` |
| `denied_commands` | commands with `denied: true` (a hook or the harness's permissions refused them) |
| `guidance_read` | sorted, distinct workspace paths (normalized: `./a`, `a/../b`; not `~`; a `..` after a link is followed as the system does, by the links the workspace had at the start, not collapsed: `alias/../AGENTS.md` with `alias -> docs/nested` is `docs/AGENTS.md`) of `read` events, neither denied nor failed (`rc` 1: the file does not exist), that `guidance.globs` match. A read event is a read tool's (Claude Code's Read, Copilot's `view`) or a shell read: a Claude Code Bash call, Codex command or Copilot `bash` command that only prints files, as §7 lists (a bare `cat`, `head`, `tail`, `nl` or `sed -n`, timed too: `time cat AGENTS.md`, `X=1 time cat AGENTS.md`, or after `command`: `command cat AGENTS.md`, not after `env`, which runs a program, never a builtin: `env command cat AGENTS.md` and `env builtin cat AGENTS.md` run no `cat`; `cd <dir>; cat AGENTS.md` reads `<dir>/AGENTS.md`; not a call of a shell function of that name the same Bash call defined (Claude Code starts each call in a new shell, which keeps no function of an earlier call): `cat() { echo hi; }; cat AGENTS.md`, `\cat AGENTS.md` and `cat() ( echo hi ); cat AGENTS.md` too, is no read, as bash runs the function, nor one after a function named `command`, `env`, `builtin` or `time`, not the keyword: `command() { echo hi; }; command cat AGENTS.md`). A command that is one such read naming one file, alone, the one command of a brace group (`{ cat AGENTS.md; }`) or after `cd` commands (`cd sub && cat AGENTS.md`; `time cd`, `command cd`, `builtin cd`, `X=1 cd`, a quoted or escaped `"cd"` or `\cd` too, not `env cd`) or a virtualenv's activate (`source .venv/bin/activate && cat AGENTS.md`, `source 'my env/bin/activate'` too), and fails is no read; one naming two keeps its reads, even when only one is known (`cd -; cat missing.md /ws/AGENTS.md`). Because such a call cannot say which of its files failed, a path counts only when the workspace held that guidance file when the agent started, the arm's files included, also when the path leads to it through a link (`alias/AGENTS.md` with `alias -> docs`), by the links the workspace had at the start, so a link the agent removes or retargets later does not unlist a read it made through it: a path that never existed (`cat docs/AGENTS.md 2>/dev/null` in a workspace without it), a link that dangles or loops (also one that returns to a directory through a `..` component: `alias -> alias/../docs`, and one whose target goes `..` out of a name that was no directory at the start: `alias -> missing/../docs`, which the system refuses), a file the arm removed and a file the agent created itself are not listed. Guidance seen through a pipe, `grep` or `rg` is not a read here (a search is `guidance_searched`), nor is a relative read after an earlier Claude Code Bash call ran a `cd` (`time cd` and `command cd` too), `pushd`, `popd`, or an `eval`, `source` or `.` (which may run one; not `source .venv/bin/activate`, a virtualenv's activate script alone, assumed to run none, §7), its name quoted or escaped too (`"source" "$ENV"`, `\cd "$D"`), or called a shell function whose body names one of these (`f() { cd sub; }` defined in that call; `source` and `.` only as a command, not of an activate script: `f() { git add .; }` names none), in its own shell, not in a subshell, pipeline or background job (the shell keeps its directory between calls, so the file is not known; a call a hook or the permissions refused ran nothing, so it moves nothing). That holds across agents: after the parent's `cd`, a subagent's relative reads are dropped too, and the reverse, since a subagent may share the parent's shell (not checked on a real trace; dropping a read is the safe side either way); to count those, add a `process_metrics` counter on the command text (§2), which also counts denied commands, unlike this row |
| `guidance_searched` | sorted, distinct workspace paths, normalized (a `..` after a link followed, as in `guidance_read`) and filtered as `guidance_read` is (`guidance.globs` match, the workspace held the file when the agent started), of the files a search showed lines of: the `searched` list of a `command` event not refused, or of a Claude Code `Grep` `tool` event ([events format](events-format.md)). A search is not a read: it adds no `read` event, so `tool_calls` and `guidance_read` stay as they were, and a file both printed and searched is in both lists. A part of a Claude Code Bash call, Codex command or Copilot `bash` command is a search when it runs `grep`, `egrep`, `fgrep`, `rg` or `git grep` (`/bin/grep` and `command grep` too, `git --no-pager grep`, `git -P grep` and `git -c k=v grep`, not `git -C dir grep`, nor a shell function of that name the same call defined) and names the file as an operand: past the pattern, after `-e` or `--` (`-ewarn` and `-nefoo`, with the expression attached, too), not the value of an option (`-m 1`) nor a pattern file (`-f F`, `-fF`); `git grep` takes the paths after `--` or after the pattern. The `cd` rules are `guidance_read`'s (`cd sub && grep x AGENTS.md` searches `sub/AGENTS.md`; a relative file after an earlier call's `cd` is dropped, and is not added to `unknown_reads`, which counts reads only). A `Grep` call counts when it has a `path` and `output_mode` `content` (a relative `path` starts at the directory the harness started in, as a Bash call does, and is dropped after an earlier Bash call that may have moved the shell, as a relative Bash search is): Claude Code's default mode (`files_with_matches`) and `count` print no line of a file, and nor does a result that is empty or says `No matches found` (also an `offset` past the last line), as an error result does not. Not counted, since no line of the file reached the agent or no file is named: `-q`, `--quiet`, `--silent`, `-l`, `--files-with-matches`, `-L`, `--files-without-match` (not rg's `-L`, which follows links), `-c`, `--count`, `--count-matches`, `-V` and rg's `--files` and `-h` (`grep -h` is `--no-filename` and stays a search; for `grep`, an unambiguous prefix of a long option too, also one that takes a value: `--qui`, `--cou`, `--exclude-d AGENTS.md`, whose `AGENTS.md` is no operand; rg reads none); a directory operand (`grep -r x docs`, `rg x docs` name no guidance file); a glob or a computed operand (`*.md`, `$f`, `$(ls)`); stdout redirected to a file or `/dev/null`; stdin (`cat AGENTS.md \| grep x`, which is not a read either); a negated (`! grep`), subshell or refused command. A search piped only into `head` or `tail` with known options (`grep x AGENTS.md \| head -n 20`, `\| head -n 20 2>/dev/null`, `\|& head`, `\| /usr/bin/head` and `\| LC_ALL=C head` too; also after `if`, `while` or `then`) counts; a pipe into any other stage, a `head` or `tail` that names a file, takes an unknown option or a value the tool refuses (`tail --follow=bad`, `--pid=x`, `-s x`, `-n x`; `--follow=name` too, which tail refuses for its input before it prints a line), `--help` or `--version`, passes no line (`-n 0`, `-c 0`) or is a shell function the same call defined, does not. A search of several files lists every file it named when its command showed a line, without attributing the lines to files (`grep visible AGENTS.md docs/AGENTS.md` whose output is only `AGENTS.md:1:visible` lists both). A search that fails as one search of one file (`rc` 1: no line matched, or 2: an error; for Claude Code any nonzero exit) is no search of it, as a failed one-file read is no read; one naming several files, when every search of the command is in its last part (`grep x AGENTS.md sub/AGENTS.md`, `echo hi; grep x AGENTS.md`, `cd sub && grep x AGENTS.md \| head`), loses them all on `rc` 1 (no line matched in any of them) and, for Claude Code, on any error; on another `rc` (2: an error, perhaps in one file of several) or when an earlier part also searched (`grep a A.md; grep b B.md`, whose exit says nothing of the first), it keeps them, as a multi-file read does; unless the trace gives the command's result as the empty text, which no search showed a line in (`grep x AGENTS.md \| head` exits 0 with nothing matched; a result that is absent from the trace is not taken for empty). A Copilot `grep` tool call and a PowerShell command are not parsed |
| `guidance_searched` | sorted, distinct workspace paths, normalized (a `..` after a link followed, as in `guidance_read`) and filtered as `guidance_read` is (`guidance.globs` match, the workspace held the file when the agent started), of the files a search showed lines of: the `searched` list of a `command` event not refused, or of a Claude Code `Grep` or Copilot `grep` `tool` event ([events format](events-format.md)). A search is not a read: it adds no `read` event, so `tool_calls` and `guidance_read` stay as they were, and a file both printed and searched is in both lists. A part of a Claude Code Bash call, Codex command or Copilot `bash` command is a search when it runs `grep`, `egrep`, `fgrep`, `rg` or `git grep` (`/bin/grep` and `command grep` too, `git --no-pager grep`, `git -P grep` and `git -c k=v grep`, not `git -C dir grep`, nor a shell function of that name the same call defined) and names the file as an operand: past the pattern, after `-e` or `--` (`-ewarn` and `-nefoo`, with the expression attached, too), not the value of an option (`-m 1`) nor a pattern file (`-f F`, `-fF`); `git grep` takes the paths after `--` or after the pattern. The `cd` rules are `guidance_read`'s (`cd sub && grep x AGENTS.md` searches `sub/AGENTS.md`; a relative file after an earlier call's `cd` is dropped, and is not added to `unknown_reads`, which counts reads only). A `Grep` call counts when it has a `path` and `output_mode` `content` (a relative `path` starts at the directory the harness started in, as a Bash call does, and is dropped after an earlier Bash call that may have moved the shell, as a relative Bash search is): Claude Code's default mode (`files_with_matches`) and `count` print no line of a file, and nor does a result that is empty or says `No matches found` (also an `offset` past the last line), as an error result does not. Not counted, since no line of the file reached the agent or no file is named: `-q`, `--quiet`, `--silent`, `-l`, `--files-with-matches`, `-L`, `--files-without-match` (not rg's `-L`, which follows links), `-c`, `--count`, `--count-matches`, `-V` and rg's `--files` and `-h` (`grep -h` is `--no-filename` and stays a search; for `grep`, an unambiguous prefix of a long option too, also one that takes a value: `--qui`, `--cou`, `--exclude-d AGENTS.md`, whose `AGENTS.md` is no operand; rg reads none); a directory operand (`grep -r x docs`, `rg x docs` name no guidance file); a glob or a computed operand (`*.md`, `$f`, `$(ls)`); stdout redirected to a file or `/dev/null`; stdin (`cat AGENTS.md \| grep x`, which is not a read either); a negated (`! grep`), subshell or refused command. A search piped only into `head` or `tail` with known options (`grep x AGENTS.md \| head -n 20`, `\| head -n 20 2>/dev/null`, `\|& head`, `\| /usr/bin/head` and `\| LC_ALL=C head` too; also after `if`, `while` or `then`) counts; a pipe into any other stage, a `head` or `tail` that names a file, takes an unknown option or a value the tool refuses (`tail --follow=bad`, `--pid=x`, `-s x`, `-n x`; `--follow=name` too, which tail refuses for its input before it prints a line), `--help` or `--version`, passes no line (`-n 0`, `-c 0`) or is a shell function the same call defined, does not. A search of several files lists every file it named when its command showed a line, without attributing the lines to files (`grep visible AGENTS.md docs/AGENTS.md` whose output is only `AGENTS.md:1:visible` lists both). A search that fails as one search of one file (`rc` 1: no line matched, or 2: an error; for Claude Code any nonzero exit) is no search of it, as a failed one-file read is no read; one naming several files, when every search of the command is in its last part (`grep x AGENTS.md sub/AGENTS.md`, `echo hi; grep x AGENTS.md`, `cd sub && grep x AGENTS.md \| head`), loses them all on `rc` 1 (no line matched in any of them) and, for Claude Code, on any error; on another `rc` (2: an error, perhaps in one file of several) or when an earlier part also searched (`grep a A.md; grep b B.md`, whose exit says nothing of the first), it keeps them, as a multi-file read does; unless the trace gives the command's result as the empty text, which no search showed a line in (`grep x AGENTS.md \| head` exits 0 with nothing matched; a result that is absent from the trace is not taken for empty). A Copilot `grep` tool call counts under the rules of a `Grep` call: its `paths` (one string or a list, each resolved from the start directory as a `view` path is; an empty or non-string entry names nothing) in `output_mode` `content`, not the default mode, `files_with_matches` or `count`, and not a call with no `paths`; a failed result, an empty one or `No matches found.` drops it, and a relative path is not dropped after an earlier `bash` call's `cd`, as `view`'s is not. A PowerShell command is not parsed |
| `unknown_reads` | the relative shell reads, of calls neither refused nor failed as one read of one file (see `guidance_read`; `cd -; cat missing.md` failing counts none), that the trace made at a directory the converter could not follow (after `source env.sh`, `cd -`, a call of a function that runs a `cd`, or a `cd` in an earlier Claude Code Bash call): they have no `read` event, so `guidance_read` may miss them; `0` when there are none |
| `counters` | each `process_metrics` name (§2) and its count |

Expand Down
20 changes: 19 additions & 1 deletion dokimi/dokimi/repos/cli_traces.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,23 @@
return [{"t": t, "kind": "edit", "path": relative_path(_from_cwd(p.strip(), cwd), workdir),
**({"deleted": True} if verb == "Delete" else {})}
for verb, p in _PATCH_FILE.findall(text)]
return [{"t": t, "kind": "tool", "name": name}]
event: dict[str, Any] = {"t": t, "kind": "tool", "name": name}
if name == "grep" and obj.get("output_mode") == "content": # the other modes list file names or counts

Check warning on line 373 in dokimi/dokimi/repos/cli_traces.py

View workflow job for this annotation

GitHub Actions / Mutation of changed lines

mutant survived: flip-compare `obj.get("output_mode") == "content"` -> `obj.get('output_mode') != 'content'`

Check warning on line 373 in dokimi/dokimi/repos/cli_traces.py

View workflow job for this annotation

GitHub Actions / Mutation of changed lines

mutant survived: swap-boolop `name == "grep" and obj.get("output_mode") == "content"` -> `name == 'grep' or obj.get('output_mode') == 'content'`

Check warning on line 373 in dokimi/dokimi/repos/cli_traces.py

View workflow job for this annotation

GitHub Actions / Mutation of changed lines

mutant survived: negate-condition `name == "grep" and obj.get("output_mode") == "content"` -> `not (name == "grep" and obj.get("output_mode") == "content")`

Check warning on line 373 in dokimi/dokimi/repos/cli_traces.py

View workflow job for this annotation

GitHub Actions / Mutation of changed lines

mutant survived: flip-compare `name == "grep"` -> `name != 'grep'`
event.update(searched_field([_from_cwd(p, cwd) for p in _grep_paths(obj.get("paths"))], workdir))
return [event]


def _grep_paths(paths: Any) -> list[str]:
"""The ``paths`` of a Copilot ``grep`` call: one string or a list; an empty or non-string entry names nothing."""
entries = [paths] if isinstance(paths, str) else paths if isinstance(paths, list) else []
return [p for p in entries if isinstance(p, str) and p]


def _grep_found_nothing(data: dict[str, Any]) -> bool:
"""A ``grep`` completion that failed, or whose content is empty or the CLI's ``No matches found.``."""
result = data.get("result")
content = result.get("content") if isinstance(result, dict) else None

Check warning on line 387 in dokimi/dokimi/repos/cli_traces.py

View workflow job for this annotation

GitHub Actions / Mutation of changed lines

mutant survived: negate-condition `isinstance(result, dict)` -> `not (isinstance(result, dict))`
return data.get("success") is False or (isinstance(content, str) and content.strip() in ("", "No matches found."))

Check warning on line 388 in dokimi/dokimi/repos/cli_traces.py

View workflow job for this annotation

GitHub Actions / Mutation of changed lines

mutant survived: swap-boolop `isinstance(content, str) and content.strip() in ("", "No matches found.")` -> `isinstance(content, str) or content.strip() in ('', 'No matches found.')`

Check warning on line 388 in dokimi/dokimi/repos/cli_traces.py

View workflow job for this annotation

GitHub Actions / Mutation of changed lines

mutant survived: flip-bool `False` -> `True`

Check warning on line 388 in dokimi/dokimi/repos/cli_traces.py

View workflow job for this annotation

GitHub Actions / Mutation of changed lines

mutant survived: swap-boolop `data.get("success") is False or (isinstance(content, str) and content.strip() in ("", "No matches found."))` -> `data.get('success') is False and (isinstance(content, str) and content.strip() in ('', 'No matches found.'))`

Check warning on line 388 in dokimi/dokimi/repos/cli_traces.py

View workflow job for this annotation

GitHub Actions / Mutation of changed lines

mutant survived: return-none `data.get("success") is False or (isinstance(content, str) and content.strip() in ("", "No matches found."))` -> `None`

Check warning on line 388 in dokimi/dokimi/repos/cli_traces.py

View workflow job for this annotation

GitHub Actions / Mutation of changed lines

mutant survived: flip-compare `data.get("success") is False` -> `data.get('success') is not False`


def _copilot_result(out: Transcript, call: _Derived, data: dict[str, Any]) -> None:
Expand All @@ -379,6 +395,8 @@
reads = [e for e in events if e["kind"] == "read"]
failed = data.get("success") is False
for event in events:
if event["kind"] == "tool" and _grep_found_nothing(data):
event.pop("searched", None) # a failed grep, or one with no match, showed no line
if event["kind"] == "edit" and data.get("success") is not None:
event["rc"] = 0 if data.get("success") else 1
if event["kind"] != "command":
Expand Down
2 changes: 1 addition & 1 deletion dokimi/dokimi/repos/process_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
tells them): a multi-file read (``cat a missing``) keeps its reads, as its exit does not say which file failed;
- ``guidance_searched``: the sorted workspace paths, under the same rules as ``guidance_read``, in the ``searched`` list of
a ``command`` event not denied (a ``grep``, ``egrep``, ``fgrep``, ``rg`` or ``git grep`` that showed lines of the file) or of
a Claude Code ``Grep`` ``tool`` event (``output_mode`` ``content``). The files are not in ``guidance_read``, and the
a Claude Code ``Grep`` or Copilot ``grep`` ``tool`` event (``output_mode`` ``content``). The files are not in ``guidance_read``, and the
search is no ``read`` event, so ``tool_calls`` does not count it;
- ``unknown_reads``: the relative shell reads the trace made at a directory the converter could not follow
(after ``source env.sh``, say), which have no ``read`` event: ``guidance_read`` may miss them. It comes from
Expand Down
Loading
Loading