Skip to content

Commit 3955abc

Browse files
Add cognitive debt report (#202)
Adds a local-git cognitive debt report, optional GitHub review enrichment, and live watch threshold support. Closes #170
1 parent 2fb3a99 commit 3955abc

8 files changed

Lines changed: 833 additions & 3 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ Full setup guide: [docs/setup.md](docs/setup.md)
109109
| [`agent-strace dashboard`](docs/commands.md#dashboard) | Multi-session overview |
110110
| [`agent-strace budget-report`](docs/commands.md#budget-report) | Weekly spend digest |
111111
| [`agent-strace team-report`](docs/commands.md#team-report) | Team spend by author, branch, or PR |
112+
| [`agent-strace cognitive-debt`](docs/commands.md#cognitive-debt) | Unreviewed agent-written code by session |
112113
| [`agent-strace lint <id>`](docs/commands.md#lint) | Flag bad behaviour patterns (loops, spirals, waste) |
113114
| [`agent-strace drift`](docs/commands.md#drift) | Detect behavioural drift over time |
114115
| [`agent-strace fingerprint`](docs/commands.md#fingerprint) | Baseline an agent's behavioural profile |

‎docs/commands.md‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ Live session monitor with kill-switch rules.
169169
| `--on-violation terminal\|file\|kill` | Action when a rule fires |
170170
| `--on-death CMD` | Command to run after kill (receives `{post_mortem_path}`) |
171171
| `--policy FILE` | Scope policy file to enforce (default: `.agent-scope.json`) |
172-
| `--rules FILE_OR_BUILTINS` | JSON/YAML rules file, or comma-separated built-ins such as `mcp-poisoning,loop:3/10,budget:$5,timeout:30m` |
172+
| `--rules FILE_OR_BUILTINS` | JSON/YAML rules file, or comma-separated built-ins such as `mcp-poisoning,loop:3/10,budget:$5,timeout:30m,cognitive-debt:0.8` |
173173
| `--stream-to URL` | Stream events to HTTP endpoint in real-time |
174174
| `--dry-run` | Evaluate rules without acting |
175175

@@ -447,6 +447,26 @@ Team cost attribution across recorded sessions. By default it groups spend by gi
447447
| `--export text|csv|json` | Output format. `csv` is intended for spreadsheets and finance workflows |
448448
| `--outlier-threshold N` | Flag sessions whose cost is above `N` times the report average; default is `2.0` |
449449
450+
### `cognitive-debt`
451+
```
452+
agent-strace cognitive-debt [--session ID] [--since DATE] [--until DATE]
453+
[--by author|branch] [--threshold N]
454+
[--format text|json] [--github-token TOKEN]
455+
```
456+
Measure unreviewed agent-written code from trace file-write events and local git history. The report works without a GitHub token; when git history is unavailable it still reports agent-written lines and treats review evidence as unknown.
457+
458+
| Flag | Description |
459+
|---|---|
460+
| `--session ID` | Score one session by ID or prefix |
461+
| `--since DATE` | Start of reporting window. Accepts ISO dates or durations like `30d`; default is `30d` |
462+
| `--until DATE` | End of reporting window. Accepts ISO dates or durations like `7d`; default is now |
463+
| `--by author|branch` | Group summary rows by git author or branch |
464+
| `--threshold N` | Flag sessions above this debt score; default is `0.7` |
465+
| `--format text|json` | Output format |
466+
| `--github-token TOKEN` | Optional GitHub token for merged PR review/comment enrichment; local git works without it |
467+
468+
`agent-strace watch --rules cognitive-debt:0.8` enables a live rule that alerts when a session has modified files that have not yet had human review.
469+
450470
### `standup`
451471
```
452472
agent-strace standup [--session SESSION_ID]

‎src/agent_trace/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""agent-trace: strace for AI agents."""
22

3-
__version__ = "0.76.0"
3+
__version__ = "0.77.0"

‎src/agent_trace/cli.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
from .standup import cmd_standup
4444
from .audit import cmd_audit, verify_chain
4545
from .cost import cmd_cost
46+
from .cognitive_debt import cmd_cognitive_debt
4647
from .curve import cmd_curve
4748
from .dashboard import cmd_dashboard
4849
from .shadow_ai import cmd_audit_tools
@@ -1056,6 +1057,23 @@ def build_parser() -> argparse.ArgumentParser:
10561057
default=2.0, metavar="SECONDS",
10571058
help="max seconds between flushes when streaming (default: 2.0)")
10581059

1060+
# cognitive-debt
1061+
p_debt = sub.add_parser("cognitive-debt", help="measure unreviewed agent-written code")
1062+
p_debt.add_argument("--session", metavar="ID", default="",
1063+
help="session ID or prefix to score (default: recent sessions)")
1064+
p_debt.add_argument("--since", default="30d", metavar="DATE",
1065+
help="start of reporting window, ISO date or duration (default: 30d)")
1066+
p_debt.add_argument("--until", default="", metavar="DATE",
1067+
help="end of reporting window, ISO date or duration (default: now)")
1068+
p_debt.add_argument("--by", choices=["author", "branch"], default="author",
1069+
help="group summary rows by author or branch (default: author)")
1070+
p_debt.add_argument("--threshold", type=float, default=0.7,
1071+
help="flag sessions above this debt score (default: 0.7)")
1072+
p_debt.add_argument("--format", choices=["text", "json"], default="text",
1073+
help="output format (default: text)")
1074+
p_debt.add_argument("--github-token", default="",
1075+
help="GitHub token for optional PR review/comment enrichment")
1076+
10591077
# mcp-scan
10601078
p_mcp_scan = sub.add_parser("mcp-scan", help="scan runtime MCP tool poisoning indicators")
10611079
p_mcp_scan.add_argument("--session", metavar="ID",
@@ -1670,6 +1688,7 @@ def main() -> None:
16701688
"explain": cmd_explain,
16711689
"timeline": cmd_timeline,
16721690
"cost": cmd_cost,
1691+
"cognitive-debt": cmd_cognitive_debt,
16731692
"diff": cmd_diff,
16741693
"why": cmd_why,
16751694
"audit": cmd_audit,

0 commit comments

Comments
 (0)