diff --git a/AGENT.md b/AGENT.md index 0a777bd..8f75f95 100644 --- a/AGENT.md +++ b/AGENT.md @@ -5,7 +5,7 @@ **Lean. Rules, not essays.** - **A rule is one or two lines.** If it needs a paragraph to justify it, the rule stays here and - the justification goes in `logs/audit_log.md`. + the justification goes in the audit log (`dev-skills/logging`) or the pull request. - **Write only what the code cannot say.** Invariants, traps, decisions and costs. If reading the code would tell you, cut it. - **No history, no dates, no "decided on".** This is the current state only; history goes in the @@ -19,10 +19,15 @@ |---|---|---| | `AGENT.md` | rules for working on this repo, and its state now | every session, first | | `skills/*/SKILL.md` | instructions for agents working **on a wiki**, not on this repo | when changing a skill, or the code a skill calls | -| `dev-skills/*/SKILL.md` | skills for working **on this repo**: `update-docs` | when doing that job | +| `dev-skills/*/SKILL.md` | skills for working **on this repo**: `update-docs`, `logging` | when doing that job | | `docs/*.md` | how-to guides, usage and configuration, for people and agents: explanations, not rules | when changing what they describe | | `patterns/README.md` | the trace and pattern formats | before writing code that records runs | -| `logs/audit_log.md` | when and why each decision was taken: appended, never rewritten | **never by default** | +| `logs/decisions/` | when and why each decision from an agent session was taken: one file per decision; `sh dev-skills/logging/log.sh` prints them as the audit log | **never by default** | +| `logs/audit_log.md` | the audit log from before `logs/decisions/`: frozen, never edited | **never by default** | + +> **Decisions are logged only through `dev-skills/logging`:** one new file per decision in +> `logs/decisions/`, in the same commit as its work, with no hash in it. A decision a person takes +> without an agent goes in the pull request, not the log. --- @@ -165,6 +170,8 @@ and silently carried into projects where it doesn't apply. would resolve against LabBrain. From a wiki, use `pixi run --manifest-path /pixi.toml labbrain`. - **Environments:** `pixi run -e dev test` and `pixi run -e dev lint`, plus `-e py311`, the oldest Python that `requires-python` promises. +- **Nothing is committed on `main`.** Work goes on a `feat/` branch and reaches `main` by + pull request. Agents never push. - **CI** (`.github/workflows/ci.yml`) runs on pushes to `main` and on pull requests: pixi (`dev`, `py311`, the pre-push checks) and uv (3.11, 3.13), each with its lock enforced. - **Actions are pinned to a commit hash,** with the release in a comment. The token is read-only, diff --git a/README.md b/README.md index 8e6f7a1..110a64f 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,8 @@ dev-skills/ skills for agents working on this repo patterns/ trace and pattern formats, with dummy examples docs/ how-to guides, usage and configuration env/ .env.example; your own .env, which git ignores -logs/audit_log.md when and why each decision was taken +logs/decisions/ when and why each agent decision was taken: one file each +logs/audit_log.md the same, from before logs/decisions/; frozen tests/ pytest; reference/ holds okf_vault.sh, which the parity tests compare against ``` @@ -109,6 +110,10 @@ Read [AGENT.md](AGENT.md) first: it holds the rules for this repo, for people an they exist. See [docs/writing-a-skill.md](docs/writing-a-skill.md). - **A change to a command, option or setting** updates the docs in the same commit; `tests/test_docs.py` fails on a missing one. +- **Audit log:** decisions taken with a coding agent are logged by the agent with + [dev-skills/logging](dev-skills/logging/SKILL.md), one file per decision in `logs/decisions/`. + Decisions you take yourself go in the pull request description. Read the log with + `sh dev-skills/logging/log.sh`. Don't edit `logs/audit_log.md`, and don't rename or delete a record. - **Before pushing:** ```sh pixi run -e dev test diff --git a/dev-skills/logging/SKILL.md b/dev-skills/logging/SKILL.md new file mode 100644 index 0000000..641cac2 --- /dev/null +++ b/dev-skills/logging/SKILL.md @@ -0,0 +1,93 @@ +--- +name: logging +description: Record a decision taken in an agent session as a new file of its own in LabBrain's logs/decisions/, committed together with the work it describes and holding no hash, and print the audit log with each record's hash looked up from git. Use when asked to log a decision, and when a major decision or discovery has been made in a session. A decision a person takes without an agent goes in the pull request instead. Commits locally; never pushes. +--- + +# logging: one file per decision, committed with its work + +This skill is for working on the LabBrain repo. Each decision is a file of its own in `logs/decisions/`. +`logs/audit_log.md` is the log from before records, frozen. `sh dev-skills/logging/log.sh` prints the whole log. + +## Why +Several people and agents log decisions, each on their own branch. Entries appended to one file +conflict on every merge, because every branch writes at its end, and a hash written into an entry +needs a second commit and a later edit. So each decision is a new file, which no other branch +writes, and it holds no hash: git knows which commit added it, and `log.sh` looks that up each time +the log is read. The record goes in the same commit as its work, so that commit holds both. Nothing +stored depends on a hash, so a rebase or a squash merge leaves the log right. + +## What goes in it +- **Decisions and discoveries from an agent session** that shape the code: taken by the agent, or + agreed between the agent and the person it works with. +- **Not a decision a person takes on their own.** That goes in the pull request description. +- **Not routine work:** docs catching up with the code, a fixed typo, a test for what already works. + +## Rules +- **Never push.** Not after a commit, not to finish the job, not when asked to log. Pushing is the + user's. +- **Never commit on `main`.** Work reaches `main` only by pull request from a `feat/` branch. If + `git branch --show-current` says `main`, stop and ask which `feat/` branch to use, then + `git switch -c feat/`; uncommitted work comes with it. +- **Never edit `logs/audit_log.md`.** It is the history from before records, kept as it was. +- **One decision, one record,** at `logs/decisions/YYYY-MM-DD-.md`: the date, then a few lowercase + words joined by hyphens that name the decision. Never a running number: two branches would both + take the next one. The name must be new on every branch: `git log --all --oneline -- ` + prints nothing. +- **No hash in a record.** `log.sh` looks it up. +- **The record goes in the same commit as its work.** A decision that changed no file is a commit + holding only its record. Never commit a record without its work. +- **Commit only what the decision touched.** Stage named paths, `git add -- …`; never + `git add -A`, `git add .` or `git commit -a`. Unrelated changes stay unstaged. If one file holds + both, ask before staging it. +- **Never `--no-verify`.** A failing hook stops the commit; report it, and the record stays + uncommitted. +- **A committed record is not rewritten.** A typo or a wrong fact is fixed in place. A decision + that changes, or is reversed, is a new record whose `supersedes` names the old record's file. +- **Never rename, move or delete a record.** Its hash is the commit that added it at that path; a + renamed record would take the hash of the rename. +- **Never commit the printed log.** It is made each time it is read, so it never conflicts. +- AGENT.md's rules on commits still hold: read `git status` first; no data, secrets or generated + files. + +## Record format +``` +--- +date: YYYY-MM-DD +title: +decided_by: [human:<handle>, <tool>/<model>] +supersedes: <YYYY-MM-DD-topic>.md +--- + +**Discovered / Decided:** what. +**Why:** the reasoning, including what was rejected. +**Cost:** what it broke, changed or left open. +``` +- **`decided_by`** names who took the decision, as actors: the person as `human:<handle>` (their `LABBRAIN_CONTRIBUTOR`, if set; otherwise ask), + and you as `<tool>/<model>`, e.g. `claude-code/claude-opus-5-5`. A decision you took alone names + only you. **Never an email address.** +- **`supersedes`** only when the record replaces an earlier one; otherwise leave the line out. +- **Put the title in double quotes** if it holds a colon. + +## Logging a decision +When asked to log a decision, being asked is the go-ahead to commit it. +1. `git status` and `git diff`: list the paths that belong to the decision. +2. Name the record, and check the name is new: `git log --all --oneline -- logs/decisions/<name>.md` + prints nothing. +3. Write the record. +4. Commit work and record together: `git add -- <paths> logs/decisions/<name>.md`, then + `git commit -m "<title>"`. +5. Run `sh dev-skills/logging/log.sh --uncommitted`: the record is not listed. +6. Report the hash (`git log -1 --format=%h`) and anything left unstaged. Do not push. + +If the work can't be committed yet (the user says not yet, the tests fail, a hook refuses), write +the record and stop. It stays uncommitted, `git status` shows it, and it goes in with the work when +that is committed. If the work was committed before it was logged, commit the record on its own and +name the work's commit in its body; that hash is plain text, and nothing checks it. + +## Reading the log +`sh dev-skills/logging/log.sh` prints `logs/audit_log.md`, then every record oldest first under a `## YYYY-MM-DD — <hash> — <title>` +header. The hash is the commit that added the record, or `uncommitted`. It needs the full history: +a shallow clone shows older records with the wrong hash. + +`sh dev-skills/logging/log.sh --uncommitted` lists the records not yet committed, or edited since: exit 0 none, 1 some, 2 +it could not check. diff --git a/dev-skills/logging/log.sh b/dev-skills/logging/log.sh new file mode 100644 index 0000000..71e021c --- /dev/null +++ b/dev-skills/logging/log.sh @@ -0,0 +1,79 @@ +#!/bin/sh +# The audit log, read from the decision records: one file per decision in $dir, holding no hash. +# Each record's hash is looked up in git every time this runs: the commit that added the file. +# sh dev-skills/logging/log.sh prints $old (frozen), then every record oldest +# first, under `## YYYY-MM-DD — <hash> — <title>` +# sh dev-skills/logging/log.sh --uncommitted lists records not committed, or edited since; +# exit 0 none, 1 some, 2 cannot check +# Needs the full history: in a shallow clone, older records show the wrong hash. +dir=logs/decisions +old=logs/audit_log.md + +git rev-parse --git-dir >/dev/null 2>&1 || { echo "log.sh: not in a git repo" >&2; exit 2; } +cd "$(git rev-parse --show-toplevel)" || exit 2 + +if [ "$1" = --uncommitted ]; then + [ -d "$dir" ] || exit 0 + status=$(git -c core.quotePath=false status --porcelain --untracked-files=all -- "$dir") || exit 2 + [ -n "$status" ] || exit 0 + printf '%s\n' "$status" | awk '{ + x = substr($0, 1, 1); y = substr($0, 2, 1); what = "edited since its commit" + if (x == "?" || x == "A") what = "not committed" + else if (x == "D" || y == "D") what = "deleted" + else if (x == "R") what = "renamed" + print what ": " substr($0, 4) }' + exit 1 +fi +[ $# -eq 0 ] || { echo "usage: sh dev-skills/logging/log.sh [--uncommitted]" >&2; exit 2; } + +[ ! -f "$old" ] || { cat "$old"; printf '\n<!-- end of %s; from here, one record per decision in %s/ -->\n' "$old" "$dir"; } +set -- "$dir"/*.md +[ -f "$1" ] || exit 0 + +# Which commit added each record, oldest first. --no-renames: a renamed record is added anew. +added=${TMPDIR:-/tmp}/log.$$ +trap 'rm -f "$added"' EXIT +git -c core.quotePath=false log --reverse --no-renames --diff-filter=A --format=@%h --name-only \ + -- "$dir" > "$added" || exit 2 + +# Order: the date the name starts with, then the order the records were committed in. +tab=$(printf '\t') +order=$(printf '%s\n' "$@" | awk -v tab="$tab" ' + FILENAME == ARGV[1] { if (substr($0, 1, 1) == "@") n++; else if ($0 != "") at[$0] = n; next } + { name = $0; sub(/.*\//, "", name) + print substr(name, 1, 10) tab (($0 in at) ? at[$0] : 999999999) tab $0 }' "$added" - | + sort -t "$tab" -k1,1 -k2,2n | cut -f3) + +set -f +IFS=' +' +# shellcheck disable=SC2086 # one record per line; names hold no spaces +awk ' + function header() { + if (title == "") title = name + if (date == "") date = substr(name, 1, 10) + printf "\n---\n\n## %s — %s — %s\n\n", date, ((file in hash) ? hash[file] : "uncommitted"), title + if (by != "") print "**Decided by:** " by + if (sup != "") print "**Supersedes:** " sup + if (by != "" || sup != "") print "" + state = 2; lead = 1 + } + FILENAME == ARGV[1] { if (substr($0, 1, 1) == "@") h = substr($0, 2); else if ($0 != "") hash[$0] = h; next } + FNR == 1 { + if (state == 1) header() + file = FILENAME; name = file; sub(/.*\//, "", name); date = title = by = sup = "" + if ($0 == "---") { state = 1; next } + header() + } + state == 1 { + if ($0 == "---") { header(); next } + k = $0; sub(/:.*/, "", k); v = $0; sub(/^[^:]*:[ \t]*/, "", v); sub(/[ \t]+$/, "", v) + if (v ~ /^".*"$/) v = substr(v, 2, length(v) - 2) + if (k == "date") date = v + else if (k == "title") title = v + else if (k == "decided_by") { gsub(/^\[|\]$/, "", v); by = v } + else if (k == "supersedes") sup = v + next + } + state == 2 { if (lead && $0 ~ /^[ \t]*$/) next; lead = 0; print } + END { if (state == 1) header() }' "$added" $order diff --git a/docs/writing-a-function.md b/docs/writing-a-function.md index 3740499..03cccb6 100644 --- a/docs/writing-a-function.md +++ b/docs/writing-a-function.md @@ -61,8 +61,8 @@ and prints their results. Nothing else prints. super().__init__("not inside the vault %s: %s" % (vault, path)) ``` - **A one-line docstring,** and comments only where the code isn't obvious. -- **No new dependency without a reason,** written in the audit log. The runtime today is the - standard library plus `python-dotenv`. +- **No new dependency without a reason,** given in the pull request, or by an agent through + `dev-skills/logging`. The runtime today is the standard library plus `python-dotenv`. ## An example Say `check` should flag a folder summary that has no `description`, since `index.md` shows the @@ -118,7 +118,7 @@ package on copies of the same wiki, and expects the same output and the same fil alters what a command prints or writes on the dummy wiki: - change `test_parity.py` in the same commit; - add the difference to AGENT.md's list of known differences; -- add an entry to `logs/audit_log.md` that says why. +- say why in the pull request, or, as an agent, through `dev-skills/logging`. ## Before you push ```sh diff --git a/docs/writing-a-skill.md b/docs/writing-a-skill.md index 84af6c9..1f06a5d 100644 --- a/docs/writing-a-skill.md +++ b/docs/writing-a-skill.md @@ -86,5 +86,5 @@ like code. ## Skills for working on this repo The skills in `skills/` are for agents working on a wiki. Skills for developing LabBrain itself -(today only `update-docs`) live in `dev-skills/`, so that a wiki copying `skills/` doesn't pick them +(`update-docs` and `logging`) live in `dev-skills/`, so that a wiki copying `skills/` doesn't pick them up. They use the same format and the same tests. diff --git a/logs/audit_log.md b/logs/audit_log.md index 3457d76..82e9f61 100644 --- a/logs/audit_log.md +++ b/logs/audit_log.md @@ -312,3 +312,17 @@ never deleted a file that had a drift record. **Cost:** a key left empty before the fix stays until the next `drift-stamp` refills it, because `links` rewrites a summary only when its records change. The personal vault's one case was removed by hand. + +--- + +## 2026-11-12 — uncommitted — decisions are logged by `dev-skills/logging`, with their commit's hash + +**Decided:** `dev-skills/logging` (tracked) writes audit-log entries and fills in their hashes. +The work is committed first, locally, staging only the paths the decision touched; the entry +follows in a commit of its own, on a `feat/` branch, never on `main`. `dev-skills/logging/pending.sh` lists entries whose hash is +`uncommitted`, missing, or no commit in this repo. AGENT.md runs it at the start of every session, +and the agent raises what it lists with the user before resolving anything. Nothing is pushed. + +**Why:** a decision is taken before its commit exists, so the hash was left for later and depended on remembering. Asked for. + +**Cost:** a logged decision is two commits, the work and then the entry. `logging` joins `update-docs` in `dev-skills/`, under the same tests.