Repository navigation
agent-guards: facts, one state table per place (#1063) - #1065
Merged
Merged
Conversation
A state table holds one row per thing (Thing | What we made / how to use it | State now | Why | Updated). The `facts` command prints the rows that match some words, with their header; `--index` lists the things; `--check` is the gardener's check (stale Updated, too many rows, broken rows, missing tables). The `facts-hook` hook shows the things at session start with "check the state table before diagnosing or redoing something", and before compaction asks to keep names, not rows. Tables are configured in the machine file (agent-guards part "facts": dirs, projects matched by origin remote or folder, staleDays, maxRows, indexLines); FACTS_DIRS overrides. The kit ships only the tool, the format and the hook; tables live with the machine or project. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fixes from the review of #1065: - tests: dates fixed by FACTS_TODAY / a fixed today, so no test depends on the day it runs - --check reads this folder's tables only; every project's only with --check --all (FACTS.md: never post --all output to a public place); --check never reads record repos - agent-guards check: facts-hook runs with the same HOME the wanted answer is computed under (no false FAIL with ~/) - git is asked at most once per hook answer (projects computed once and passed in) - only regular files are read (O_NONBLOCK + fstat): a FIFO STATE.md is a note, never a wait - index: no file line with none of its things; the whole session text is capped (indexChars, default 4000) with "+N more: run facts --index" - parser: short |-|-| separators, a second header row starts a new table, "(cut at N MB)" note - dates: future dates flagged, "11-23 (checked)" read, 02-29 in a non-leap year means the last leap year - places deduped by real path - installer: an unrelated /usr/local/bin/facts is left alone with a warning (OPTIONAL_LINKS in kit_install) New: facts.records ([{path, projectsDir, shared}]): `facts WORDS` searches the record repo's text files after the tables (this project's projects/<name>/ and the shared folders; --all every project), at most 10 hits, skipping .git, links, files over 1 MiB and copies of tables already read. --records WORDS (50 hits), --no-records. The session hook names the repo in one line and never shows its content. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1063. The daily gardener that runs
facts --checkis wired in #1064, not in this PR.What
After a compaction, a handoff or a new session, an agent does not know what was already made or why things are the way they are. It spends usage finding out again, and sometimes gets it wrong. This PR adds a state table per place: one Markdown table with one row per thing (
Thing | What we made / how to use it | State now | Why | Updated). It also adds the tools to read the tables:facts <words>prints the table rows that hold every word, each under its table's header, with Thing-column hits first. If no row holds all the words, it shows the rows that hold some of them and says so. After the tables, it searches the record repo, when one is configured (see below).facts --indexprints every Thing.facts --dirsshows where it looked, record repos included.facts --allalso reads every project's tables and record folders. FACTS.md warns: never post--alloutput to a public place.facts --checkis the gardener's check, report only, and exits 1 when it finds something. It checks this folder's tables only (every project's with--check --all) and never reads the record repo. It reports:Updateddate is stale, in the future, or not readable;maxRows;Updatedcolumn;facts-hook:facts <words>prints the matching rows". Then it adds the project's text and one line,Records: <path> (facts <words> searches it), when a record repo is there; the repo's content is never shown. The whole text is capped atindexChars(default 4000) andindexLines. When it is cut, it ends with+N more: run facts --index.Record repo search
The config is
facts.records: [{path, projectsDir: "projects", shared: ["machines", "orch", "shared"]}]..md .txt .json .yml .yaml .sh) in the shared folders and in the current project'sprojects/<name>/folder.<name>is the project row's new optionalnamekey, or else the last part of its remote or folder. With--all, it searches every project's folder.path:line: textline, at most 160 characters. The default search shows at most 10 hits, then+N more (facts --records <words>).--records <words>searches the repo only and shows up to 50 hits.--no-recordssearches the tables only..git, links, and files that are not regular files;STATE.mdis not shown twice.note:line in the command; the hook says nothing about it.Example (a fixture with a mirrored table, another project's notes, and a shared runbook):
Config
Config lives in the machine file's
agent-guardssection, partfacts:dirslists the tables for every session on the machine.projectsrows are{match, dirs, text, name}.matchis a remote (host/owner/repo) or a folder, never a glob.staleDays,maxRows,indexLines,indexChars,records.FACTS_DIRSreplaces the table lists for one command or session.A broken config part is named, and the defaults are used. A bad
projectsorrecordsrow is dropped and the good rows are kept.Review round 1 fixes
FACTS_TODAYor a fixedtoday, so no test depends on the day it runs. Before, the fixed dates would have started failing on 12-02.--checkreads only the current project, unless--allis given.agent-guards check:facts-hooknow runs under the same HOME that the expected answer is computed with. Before,~/dirs gave a false FAIL.O_NONBLOCKand checked withfstat. A FIFOSTATE.mdgives a note and never hangs.indexChars.|-|-|separators are accepted;(cut at N MB)note.11-23 (checked)is read;02-29in a non-leap year means the last leap year./usr/local/bin/factsis not this kit's link, it is left alone with a warning. The install still succeeds, and uninstall does not remove it. This uses a genericOPTIONAL_LINKSin the sharedkit_install.py.Why Python in agent-guards, not a separate Node script
The agent-guards kit already has what this needs:
agent-guards check.A separate script would mean a second config path and a second way to wire hooks.
General vs project
OPTIONAL_LINKSin the installer), the config keys and the docs (fork-kit/agent-guards/FACTS.md). No project, person, path or machine is named. Examples use made-up names and/srv/example/...paths.facts.dirs,facts.projects,facts.records).Tests
fork-kit/agent-guards/tests/facts.test.py: 42 tests, up from 24. New cases:(checked)suffix,02-29.recordsandnamerows.--check: current project only vs--all; it never reads records.--recordsand--no-records, the mirrored-table skip,.git, big files, links and FIFOs skipped, the current project vs--all, a missing repo, the hook's Records line, and--dirs.wiring.test.py:agent-guards checkwith a~/table dir passes.install.test.py: an unrelated/usr/local/bin/factsis left alone through install, update and uninstall, and our own link is kept.common/tests/kit_install.test.pycoversOPTIONAL_LINKSfor every kit.These pass locally:
fork-ci-testsforfork-kit/agent-guards/andfork-kit/common/;🤖 Generated with Claude Code