Artifact 02379b815536df7731de60621f0d5634cd2447df90b65e3dc44f2147a93588f6:
- Executable file
tools/rule_redundancy.sh
— part of check-in
[f3ab690bb4]
at
2026-11-19 19:07:12
on branch agent-instructions
— Rules for every coding agent, not only Claude Code: global and project instruction files from one agent table
ctx assumed Claude Code was the only agent. A table of agents (claude, codex, gemini, pi, opencode) now gives each one's global instruction file, with its env override, and the project file names it reads.
- Every existing global instruction file is a * rule with an agent: line; project CLAUDE.md, AGENTS.md and GEMINI.md are imported, and whole instruction files are excluded everywhere by name from the table. - The covered check judges a project rule only against the global instructions of the agents it reaches (rule_reach: Claude Code memory and ctx remember rules reach claude), and retires it only when the quote is in a global file of every one of them. Reasons name the files, kept in ctx_rule_covered_file; old CLAUDE.md-worded retirements still revive. - An import retires a global instruction-file rule only when its file is gone from disk, so scans run with different CODEX_HOME, XDG_CONFIG_HOME or CLAUDE_CONFIG_DIR no longer retire and re-import each other's globals; other rules retire as before when an import no longer sees them. - Messages and docs say global instructions and name the file. Each instruction-file rule gets one new version on the first scan after upgrading. (user: dmestas, size: 1387) [annotate] [blame] [check-ins using] [more...]
#!/bin/sh # Reports how much of an archive's rules the automatic clean-up would touch, changing nothing: # rules in force, identical copies a rules import would collapse, rules the covered check would # send to the judge, and groups of the same rule saved in several projects. # # cp ~/.ctx/ctx.sqlite /tmp/copy.sqlite # with ctx not running # CTX_DB=/tmp/copy.sqlite tools/rule_redundancy.sh # # Each agent's global instructions are the rules keyed by the paths ctx reads them from, with # the same environment (CLAUDE_CONFIG_DIR, CODEX_HOME and the rest, else HOME) as for ctx. set -eu CTX=${CTX:-ctx} [ -n "${CTX_DB:-}" ] || { echo "rule_redundancy: set CTX_DB to a scratch copy of the archive" >&2; exit 2; } [ -n "${HOME:-}" ] && [ "$CTX_DB" -ef "$HOME/.ctx/ctx.sqlite" ] && { echo "rule_redundancy: CTX_DB is the live archive; use a copy" >&2; exit 2; } export CTX_DB echo "active rules: $("$CTX" sql "SELECT count(*) FROM ctx_doc WHERE kind = 'rule' AND status IS NULL")" echo "identical copies to collapse: $("$CTX" rules collapse --dry-run | sed -n 's/^\([0-9]*\) identical cop.* would collapse$/\1/p')" echo "rules to send to the covered check: $("$CTX" rules covered --dry-run | sed -n 's/^\([0-9]*\) rules would be sent.*/\1/p')" echo "groups of the same rule in several projects: $("$CTX" rules same | sed -n 's/^\([0-9]*\) groups\{0,1\} of the same rule.*/\1/p')"