Skip to content

Commit 7b96abd

Browse files
feat(config-watch): AGENTS.md change detector (#86)
- config_watch.py: take_snapshot, diff_snapshots, find_affected_sessions, cmd_config_watch - Subcommands: snapshot, check, history, affected - SHA-256 hashing of watched config files; snapshots stored in .agent-traces/config-snapshots.json - Default watch list: AGENTS.md, CLAUDE.md, system_prompt.md/txt, .cursorrules, .github/copilot-instructions.md - check exits 1 when config has changed (CI gate) - 42 tests in tests/test_config_watch.py - README: new config-watch section and command reference entries - Version bump 0.49.0 → 0.50.0 Closes #86 Co-authored-by: Ona <no-reply@ona.com>
1 parent c9a8fa5 commit 7b96abd

4 files changed

Lines changed: 570 additions & 1 deletion

File tree

README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ print(f"Replay with: agent-strace replay {meta.session_id}")
186186
| `curve` | Personal cost-efficiency curve |
187187
| `a2a-tree` | Cross-agent trace correlation (A2A protocol) |
188188
| `mcp` | MCP server: expose traces as queryable tools for a debugging agent |
189+
| `config-watch` | Snapshot and diff AGENTS.md and other config files; find affected sessions |
189190

190191
```
191192
agent-strace setup [--redact] [--global] Generate Claude Code hooks config
@@ -237,6 +238,14 @@ agent-strace oncall --rotation-start DATE On-call readiness for agent-modi
237238
agent-strace curve [--export csv] Personal agent cost-efficiency curve
238239
agent-strace inflation [--compare m1,m2] Token inflation calculator across model versions
239240
agent-strace a2a-tree [session-id] Visualise A2A agent call graph
241+
agent-strace config-watch snapshot [--label TEXT] [--watch PATH]
242+
Snapshot current config file state
243+
agent-strace config-watch check [--format text|json] [--watch PATH]
244+
Diff current state vs last snapshot (exit 1 if changed)
245+
agent-strace config-watch history [--format text|json]
246+
List all snapshots
247+
agent-strace config-watch affected [--since DURATION] [--format text|json]
248+
Sessions that ran after a config change
240249
```
241250

242251
### Import existing Claude Code sessions
@@ -437,6 +446,58 @@ Rules are configurable via `.agent-strace-lint.json`:
437446
| `error-retry-loop` | WARN | Same tool errored and was retried 3+ times |
438447
| `no-output` | WARN | Session completed with no write or file-modifying tool calls |
439448

449+
### Config change detector
450+
451+
Track changes to AGENTS.md and other agent configuration files. Snapshot the current state before a change, then check what drifted and which sessions ran after it.
452+
453+
```bash
454+
# Record a snapshot of all watched config files
455+
agent-strace config-watch snapshot
456+
457+
# Add a label to identify the snapshot
458+
agent-strace config-watch snapshot --label "before-prompt-refactor"
459+
460+
# Check whether anything changed since the last snapshot (exit 1 if yes)
461+
agent-strace config-watch check
462+
463+
# Machine-readable diff
464+
agent-strace config-watch check --format json
465+
466+
# List all snapshots
467+
agent-strace config-watch history
468+
469+
# Find sessions that ran after a config change
470+
agent-strace config-watch affected
471+
472+
# Limit to sessions from the last 7 days
473+
agent-strace config-watch affected --since 7d
474+
```
475+
476+
Example output:
477+
478+
```
479+
$ agent-strace config-watch check
480+
CHANGED AGENTS.md (sha256: a1b2c3d4 → e5f6a7b8)
481+
ADDED .claude/settings.json
482+
No changes to: CLAUDE.md, system_prompt.md
483+
484+
$ agent-strace config-watch affected
485+
2 session(s) ran after a config change:
486+
487+
abc123def456 2026-05-20T14:32:01 (after change to: AGENTS.md)
488+
789xyz012abc 2026-05-20T15:10:44 (after change to: AGENTS.md)
489+
490+
Run `agent-strace drift` to compare behaviour before and after the change.
491+
```
492+
493+
Watched files by default: `AGENTS.md`, `CLAUDE.md`, `system_prompt.md`, `system_prompt.txt`, `.cursorrules`, `.github/copilot-instructions.md`. Add extra paths with `--watch`:
494+
495+
```bash
496+
agent-strace config-watch snapshot --watch .claude/settings.json --watch custom_prompt.txt
497+
```
498+
499+
Snapshots are stored in `.agent-traces/config-snapshots.json`. Use `check` as a CI gate — it exits 1 when config has changed since the last snapshot.
500+
440501
### Data retention
441502

442503
Enforce configurable retention policies to automatically delete old session data — required for GDPR, SOC 2, and internal data policies.

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.49.0"
3+
__version__ = "0.50.0"

src/agent_trace/cli.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
from .integrations import detect_and_instrument, _INTEGRATIONS
5050
from .budget_report import cmd_budget_report
5151
from .compare import cmd_compare
52+
from .config_watch import cmd_config_watch
5253
from .lint import cmd_lint
5354
from .retention import cmd_retention
5455
from .sample import cmd_sample
@@ -883,6 +884,32 @@ def build_parser() -> argparse.ArgumentParser:
883884
p_sample.add_argument("--seed", type=int, default=None,
884885
help="random seed for reproducible random sampling")
885886

887+
# config-watch
888+
p_cw = sub.add_parser("config-watch",
889+
help="detect AGENTS.md and config file changes between sessions")
890+
cw_sub = p_cw.add_subparsers(dest="config_watch_command")
891+
892+
cw_snap = cw_sub.add_parser("snapshot", help="record a snapshot of current config files")
893+
cw_snap.add_argument("--label", metavar="TEXT",
894+
help="human-readable label for this snapshot")
895+
cw_snap.add_argument("--watch", metavar="PATH", action="append",
896+
help="additional file to watch (repeatable)")
897+
898+
cw_check = cw_sub.add_parser("check",
899+
help="check whether config has changed since last snapshot")
900+
cw_check.add_argument("--watch", metavar="PATH", action="append",
901+
help="additional file to watch (repeatable)")
902+
cw_check.add_argument("--format", choices=["text", "json"], default="text")
903+
904+
cw_hist = cw_sub.add_parser("history", help="show full snapshot history")
905+
cw_hist.add_argument("--format", choices=["text", "json"], default="text")
906+
907+
cw_aff = cw_sub.add_parser("affected",
908+
help="list sessions that ran after a config change")
909+
cw_aff.add_argument("--since", metavar="DURATION",
910+
help="only sessions newer than this (e.g. 7d, 24h)")
911+
cw_aff.add_argument("--format", choices=["text", "json"], default="text")
912+
886913
# compare
887914
p_compare = sub.add_parser("compare", help="session-to-session regression report")
888915
p_compare.add_argument("session_id_a", nargs="?",
@@ -1053,6 +1080,7 @@ def main() -> None:
10531080
"auto": cmd_auto,
10541081
"budget-report": cmd_budget_report,
10551082
"compare": cmd_compare,
1083+
"config-watch": cmd_config_watch,
10561084
"lint": cmd_lint,
10571085
"retention": cmd_retention,
10581086
"sample": cmd_sample,

0 commit comments

Comments
 (0)