Cognitive debt and review coverage¶
agent-strace cognitive-debt reports review coverage for observed
agent-written code. It is a repository and workflow metric. It does not measure
code quality, claim causation, or rank individuals.
Generate a report and badge¶
agent-strace cognitive-debt --since 30d --by repository
agent-strace cognitive-debt --since 30d --by branch --format json --output cognitive-debt.json
agent-strace cognitive-debt --since 30d --by repository --format badge --output cognitive-debt-badge.json
--format json writes the versioned schema v1 report. --format badge writes
Shields-compatible static JSON. --output writes the complete result
atomically. The command writes no partial report when validation or output
handling fails.
The PR Evidence Action can generate both files for the linked review session,
upload them with the minimized Evidence Packet, and treat unknown as
unavailable rather than passing. Its cognitive-debt input defaults to
auto, which is off on pull request events: open pull requests are not read,
so before merge the report cannot see the review. Run it on the default branch
after merge, or use the team view on a
schedule. See PR reviewability.
Reviewed, unreviewed, and unknown¶
The report keeps three coverage states separate:
reviewed: observed agent-written lines with estimated review evidence.unreviewed: observed lines remaining after estimated review coverage when review state is known.unknown: authorship or review state could not be established.
Unknown is not zero review and is not a passing result. If git history is unavailable, affected lines remain unknown instead of becoming unreviewed. A missing path on a recorded write also produces unknown authorship and review coverage.
Schema v1 reports schema_version: 1, agent_written_lines, reviewed,
unreviewed, and unknown line counts and percentages, plus authorship and review
states. The unreviewed ratio is null when review state is unknown.
Agent-written lines¶
A write is a file_write event or a tool call that watch treats as an edit
(see Paths and edits). An MCP tool whose name ends in
apply_patch, edit_file, file_edit, search_replace,
str_replace_editor, str_replace_based_edit_tool, write_file or
write_to_file, such as mcp__filesystem__write_file, is also a write. These
are not counted:
- a todo tool such as Claude Code
TodoWriteor Gemini CLIwrite_todos; - a
str_replace_editororstr_replace_based_edit_toolcall withcommandview; - a call with
dryRun: true; - a call whose linked result is an
errorevent, or hasis_error: trueorsuccess: false; - a shell command, so a file written by
echo x > forsed -iis missed.
Each write counts the lines it adds:
| Recorded change | Lines counted | Used by |
|---|---|---|
Whole new text in content, file_text, new_source, code_edit or text |
Every line | Claude Code Write and NotebookEdit, Copilot CLI create, Gemini CLI write_file |
Old and new text in old_string/new_string, old_str/new_str, old_text/new_text or oldText/newText |
Lines a line diff adds or changes; every new line when the old text is empty | Claude Code Edit, Copilot CLI edit, Gemini CLI replace, str_replace_editor |
An edits list of old and new pairs |
The sum over the pairs | Claude Code MultiEdit, Cursor afterFileEdit |
expected_replacements above 1 |
The pair's lines times that number | Gemini CLI replace |
replacement with no old and new pair |
Every line | |
apply_patch text, as the arguments or in command, input or patch |
+ lines per file; a *** Delete File: section counts nothing; *** Move to: counts under the new name |
Codex, Copilot CLI apply_patch |
A unified diff in diff or patch |
+ lines, without +++ headers |
|
delete_file, or NotebookEdit with edit_mode: delete |
Nothing | |
| No content recorded | 1 line | Imported Codex apply_patch, older Cursor traces |
Every write that changes a file counts at least one line, so a deletion-only
edit counts 1. Writes to the same file are added together. A write that names
no file counts as unknown authorship, which makes the report unknown.
A write outside the session's repository is not that repository's code. A file
in no git repository, such as an agent's plan file in its own state directory
or a scratch file in /tmp, is not counted. A file inside another git
repository is counted with review state unknown (outside_repository). Both
checks need the recorded directory. From another checkout, every file outside
the recorded directory reads not_in_checkout, so a session that wrote a plan
file there reads unknown. Local file:// URIs are URL-decoded and converted
to platform paths before these checks and before git runs. Other URI schemes,
file URIs with a non-local host, query or fragment, and paths that cannot be
converted are not_in_checkout and remain unknown.
Lines from git-ai notes and Agent Trace records¶
cognitive-debt --commits RANGE also counts the ai and mixed lines in the
git-ai notes of those commits, and
--agent-trace-records FILE counts them from Agent Trace records. Each source
is one workflow. The text report shows AI and mixed lines on separate lines,
so a failing check shows how much of its count is mixed. A line that a
reported session already captured is counted once, under that session. These
lines come from the tool that wrote them, not from a recorded write, and their
line numbers are per commit or record. See
How lines are counted.
Review evidence¶
Each file gets the weight of its strongest signal. Its reviewed lines are its agent-written lines times that weight, rounded. When both local git and GitHub have evidence, the larger count is used.
Local git reads commits after that file's latest recorded agent write on the
session's branch: refs/heads/<branch>, then
refs/remotes/origin/<branch>. Commits on other branches are not read. When
the recorded branch is known but neither ref exists, review state is unknown;
git does not fall back to an unrelated HEAD. HEAD is used only when the
session has no known branch.
| Local signal | Weight | Meaning |
|---|---|---|
not_committed |
0 | No commit on the branch touched the file after its latest agent write |
committed_after_session |
0 | A later commit touched the file. Committing is not review |
reviewed_by_trailer |
0.75 | A commit body has a Reviewed-by: line naming another person |
git_unavailable |
unknown | The directory is not a git work tree |
git_revision_unavailable |
unknown | The known recorded branch has no local or origin ref |
outside_repository |
unknown | The file is inside another git repository |
not_in_checkout |
unknown | The file is not in the checkout read instead of the recorded directory, or its URI cannot name a local path |
A Reviewed-by: value does not count when it has the commit author's email,
with or without angle brackets, or, without an email, the author's name. It also does not count when it
contains [bot], copilot, claude, anthropic, openai, codex,
cursor, gemini or devin. Words such as "review", "comment" or "line",
Co-authored-by: trailers, several commit authors, "pull request" and (#N)
in a message are not review evidence.
With --github-token, the command searches merged pull requests whose head is
the session's branch. A pull request is usable only when both its base and head
repository match the recorded repository, its head branch matches, it merged
after the file's latest agent write, and that file is present in its
changed-file list. Exactly one candidate must match. No GitHub evidence is
applied when branch reuse leaves several candidates, when no candidate
contains the file, or when search or changed-file pagination prevents a
complete decision.
| GitHub signal | Weight | Meaning |
|---|---|---|
github_merged_pr |
0 | A merged pull request exists. Merging is not review |
github_reviews |
0.75 | Another person submitted a review |
github_review_comments |
0.85 | Another person left a review comment on the pull request |
github_line_comments |
1.0 | Another person left a review comment on this file |
Reviews and comments by the pull request author, by bots (type: Bot or a
login ending in [bot]) and pending reviews do not count. Open pull requests
are not read. Reviews and comments must also be later than the file's latest
agent write. Malformed or incomplete GitHub responses fail closed with unknown
review state and zero GitHub evidence. A valid GitHub signal makes the file's
review state known, so a matching merged pull request with no later review by
another person counts as unreviewed. GitHub is not queried for files outside
the repository or absent from the checkout.
Reading a trace from another checkout¶
Git runs in the session's recorded working_dir. When that directory no
longer exists, as in CI or another clone, the command uses the git work tree
of the current directory if one of its remotes names the same repository as
the session's recorded git_repo. Remotes match on host, owner and name,
ignoring case, the protocol and .git. Recorded paths under the old directory
are read at the same place under the work tree's top level, so the recorded
directory must have been the repository root. The trace does not record that,
so the command checks it: when any trailing part of the recorded directory
(for /home/dev/widgets/pkg, that is pkg, widgets/pkg and so on) is a
directory in the work tree, or in the session's recorded git_commit, the
session may have started in a subdirectory, and review state stays unknown. A
repository that holds a directory with the same name as its own checkout
directory therefore also reads unknown. A file outside the recorded directory,
or missing from the checkout, is not_in_checkout and unknown. If no remote
matches, or the session has no git_repo, review state stays unknown. Either
way, JSON path keeps the recorded path, and the text report and JSON
relative_path show it relative to the recorded working_dir; see
File paths.
In GitHub Actions, check out with fetch-depth: 0 so git log can see the
branch history.
Status and grouping¶
| Status | Meaning |
|---|---|
clean |
All observed agent-written lines have review evidence |
partial |
Review is known and unreviewed coverage is within the configured threshold |
above_threshold |
Review is known and unreviewed coverage exceeds --threshold |
unknown |
No agent-written lines were observed, or authorship or review coverage is incomplete |
Use --by repository or --by branch. JSON groups contain those aggregates,
and workflows contain per-session details. The legacy --by author value is
only an alias for repository grouping and never emits an individual ranking.
Interpretation limits¶
- Written-line counts are estimates derived from recorded payloads, not a git
patch attribution model. They are exact only when the payload holds the new
text. Claude Code
replace_alledits count once, aNotebookEditreplace counts the whole new cell, and lines that a later write removes still count. - Lines from git-ai notes and Agent Trace records are self-reported by the tool that wrote them. agent-strace checks their shape, not their truth. A line rewritten by a later commit in the range counts again.
- A write the user denied still counts when the provider records no result for it.
- From another checkout, a session that started in a subdirectory, or that
wrote outside its recorded directory (for example an agent's plan file),
reads
unknown. The trace does not record where the working directory sat in the repository. - Review coverage is estimated from local git and optional GitHub pull request, review, and comment signals.
- A review signal does not prove that every changed line was examined.
- No review signal does not prove that no review happened.
- Provider capture gaps can omit file activity before the report runs.
- The badge is presentation output. Use the schema v1 JSON report for automation.
Use this report to choose repositories, branches, and workflows for review. Do not use it as an individual performance score, security certification, or compliance result.