From 2693512c7aa6571fffd8bb0b50d12544e8888750 Mon Sep 17 00:00:00 2001 From: Patrick CN Martin Date: Thu, 12 Nov 2026 16:13:19 +0100 Subject: [PATCH 1/2] logging skill - adds a skill for logging so that decisions are always linked to a hash - done on request --- AGENT.md | 8 +++- dev-skills/logging/SKILL.md | 77 +++++++++++++++++++++++++++++++++++ dev-skills/logging/pending.sh | 28 +++++++++++++ docs/writing-a-skill.md | 2 +- logs/audit_log.md | 14 +++++++ 5 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 dev-skills/logging/SKILL.md create mode 100755 dev-skills/logging/pending.sh diff --git a/AGENT.md b/AGENT.md index 0a777bd..aa2ccf6 100644 --- a/AGENT.md +++ b/AGENT.md @@ -19,11 +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** | +> **Every session, before anything else:** `sh dev-skills/logging/pending.sh`. If it lists entries, +> tell the user there are uncommitted decisions in the audit log and stop; on their go-ahead, follow +> `dev-skills/logging`. Decisions are logged only through that skill. + --- ## What LabBrain is — *work in progress, nothing deployed* @@ -165,6 +169,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/dev-skills/logging/SKILL.md b/dev-skills/logging/SKILL.md new file mode 100644 index 0000000..341b39e --- /dev/null +++ b/dev-skills/logging/SKILL.md @@ -0,0 +1,77 @@ +--- +name: logging +description: Write a decision to LabBrain's audit log with the hash of the commit that holds its work, and fill in the hash of entries still marked uncommitted. Use when asked to log a decision, when a major decision or discovery has been made, and when the session-start check in AGENT.md lists pending entries. Commits locally; never pushes. +--- + +# logging: every audit-log entry names its commit + +This skill is for working on the LabBrain repo. The log is `logs/audit_log.md`; the check is +`sh dev-skills/logging/pending.sh`. + +## Why +The hash is what makes an entry checkable: the commit exists and holds what the entry says. A +hash exists only once its commit does, and decisions are usually taken before the commit. An +entry written first says `uncommitted`, and an `uncommitted` entry is a decision whose work may +not be in git at all. The check brings it back each session until it names its commit. + +## 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. +- **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 amend, rebase, squash or reset.** A rewritten commit orphans every hash already logged. +- **Never `--no-verify`.** A failing hook stops the commit; report it, and the entry stays + `uncommitted`. +- **The hash is the work's commit,** read with `git rev-parse --short HEAD` straight after it. The + entry then goes in a commit of its own, so the log is always one commit behind the work it + names. +- **A decision that changed no tracked file** takes the hash of `HEAD` and says so: + `## YYYY-MM-DD — (no tracked file changed) — `. +- **Filling in a hash is the one edit allowed to an existing entry.** Nothing else in it changes. +- AGENT.md's rules on commits still hold: read `git status` first; no data, secrets or generated + files. + +## Entry format +The header is `## YYYY-MM-DD — <hash> — <title>`, with `uncommitted` in place of the hash until +the commit exists. The body follows the template at the top of the log. Entries go at the end, +newest last. + +## At session start +AGENT.md has you run `sh dev-skills/logging/pending.sh` before anything else. +- **Exit 0:** nothing pending; say nothing. +- **Exit 1:** tell the user *"There are uncommitted decisions in the audit log"*, list the lines + it printed, and stop. Do not resolve them unasked. +- **Exit 2:** it could not check (no log, not a repo); say so. + +On the user's go-ahead, resolve them (below). + +## 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. Commit them: `git add -- <paths>`, then `git commit -m "<title>"`. +3. `git rev-parse --short HEAD` is the hash. +4. Append the entry to `logs/audit_log.md` with that hash. +5. Commit the log alone: `git add -- logs/audit_log.md`, `git commit -m "audit log: <title>"`. +6. Run the check; it exits 0. +7. Report both hashes 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), +append the entry as `uncommitted` and stop; the next session's check brings it back. + +## Resolving `uncommitted` entries +For each line the check printed: +1. Read the entry and work out which files it describes. +2. **Already committed?** `git log --oneline -- <paths>`, then `git show --stat <hash>` on each + candidate. One commit that holds the work is the hash. +3. **Still in the working tree?** Commit it as in *Logging a decision*, steps 1–3. +4. **Neither, or several commits and no clear one?** Don't guess a hash. Tell the user what you + found and leave the entry as it is. +5. Replace `uncommitted` in the header with the hash. A `no commit <hash> here` line (a typo, or + history that was rewritten) is fixed the same way, once the right commit is known. + +Then commit the log once for all of them, `audit log: hashes for <n> entries`, run the check, +and report each entry with its hash, plus any left unresolved. Do not push. diff --git a/dev-skills/logging/pending.sh b/dev-skills/logging/pending.sh new file mode 100755 index 0000000..42227bf --- /dev/null +++ b/dev-skills/logging/pending.sh @@ -0,0 +1,28 @@ +#!/bin/sh +# Audit-log entries that do not name their commit: the hash is `uncommitted`, missing, +# or not a commit in this repo. Prints one line per entry; exit 0 none, 1 some, 2 cannot check. +# Reads entry headers only (`## YYYY-MM-DD — <hash> — <title>`), and only those below a +# `<!-- hashes from here -->` line when the log has one: entries above it predate hashes. +# Run from the repo root: sh dev-skills/logging/pending.sh [log] +log=${1:-logs/audit_log.md} +[ -f "$log" ] || { echo "pending.sh: no audit log at $log" >&2; exit 2; } +git rev-parse --git-dir >/dev/null 2>&1 || { echo "pending.sh: not in a git repo" >&2; exit 2; } + +start=$(grep -n '^<!-- hashes from here -->' "$log" | tail -n 1 | cut -d: -f1) +found=0 +tail -n +"$((${start:-0} + 1))" "$log" | grep -E '^## [0-9]{4}-[0-9]{2}-[0-9]{2} — ' > "${TMPDIR:-/tmp}/pending.$$" +while IFS= read -r header; do + rest=${header#* — } + hash=${rest%%[ ,]*} + case $hash in + uncommitted) why=uncommitted ;; + *[!0-9a-f]* | '') why='no hash' ;; + *) if [ ${#hash} -lt 7 ] || ! git cat-file -e "$hash^{commit}" 2>/dev/null; then + why="no commit $hash here" + else continue; fi ;; + esac + echo "$why: $header" + found=1 +done < "${TMPDIR:-/tmp}/pending.$$" +rm -f "${TMPDIR:-/tmp}/pending.$$" +exit $found 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. From d674d3e684b92af0d031a8fbc83c92d5205ea1a0 Mon Sep 17 00:00:00 2001 From: Patrick CN Martin <pcnmartin@gmail.com> Date: Fri, 13 Nov 2026 09:47:56 +0100 Subject: [PATCH 2/2] feat(Dev skills): adding a new approach to logging to avoid conflicts between devs and still keep history --- AGENT.md | 11 ++-- README.md | 7 ++- dev-skills/logging/SKILL.md | 114 +++++++++++++++++++--------------- dev-skills/logging/log.sh | 79 +++++++++++++++++++++++ dev-skills/logging/pending.sh | 28 --------- docs/writing-a-function.md | 6 +- 6 files changed, 159 insertions(+), 86 deletions(-) create mode 100644 dev-skills/logging/log.sh delete mode 100755 dev-skills/logging/pending.sh diff --git a/AGENT.md b/AGENT.md index aa2ccf6..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 @@ -22,11 +22,12 @@ | `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** | -> **Every session, before anything else:** `sh dev-skills/logging/pending.sh`. If it lists entries, -> tell the user there are uncommitted decisions in the audit log and stop; on their go-ahead, follow -> `dev-skills/logging`. Decisions are logged only through that skill. +> **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. --- 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 index 341b39e..641cac2 100644 --- a/dev-skills/logging/SKILL.md +++ b/dev-skills/logging/SKILL.md @@ -1,18 +1,26 @@ --- name: logging -description: Write a decision to LabBrain's audit log with the hash of the commit that holds its work, and fill in the hash of entries still marked uncommitted. Use when asked to log a decision, when a major decision or discovery has been made, and when the session-start check in AGENT.md lists pending entries. Commits locally; never pushes. +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: every audit-log entry names its commit +# logging: one file per decision, committed with its work -This skill is for working on the LabBrain repo. The log is `logs/audit_log.md`; the check is -`sh dev-skills/logging/pending.sh`. +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 -The hash is what makes an entry checkable: the commit exists and holds what the entry says. A -hash exists only once its commit does, and decisions are usually taken before the commit. An -entry written first says `uncommitted`, and an `uncommitted` entry is a decision whose work may -not be in git at all. The check brings it back each session until it names its commit. +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 @@ -20,58 +28,66 @@ not be in git at all. The check brings it back each session until it names its c - **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/<topic>` branch to use, then `git switch -c feat/<topic>`; 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-<topic>.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 -- <path>` + 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 -- <path>…`; never `git add -A`, `git add .` or `git commit -a`. Unrelated changes stay unstaged. If one file holds both, ask before staging it. -- **Never amend, rebase, squash or reset.** A rewritten commit orphans every hash already logged. -- **Never `--no-verify`.** A failing hook stops the commit; report it, and the entry stays - `uncommitted`. -- **The hash is the work's commit,** read with `git rev-parse --short HEAD` straight after it. The - entry then goes in a commit of its own, so the log is always one commit behind the work it - names. -- **A decision that changed no tracked file** takes the hash of `HEAD` and says so: - `## YYYY-MM-DD — <hash> (no tracked file changed) — <title>`. -- **Filling in a hash is the one edit allowed to an existing entry.** Nothing else in it changes. +- **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. -## Entry format -The header is `## YYYY-MM-DD — <hash> — <title>`, with `uncommitted` in place of the hash until -the commit exists. The body follows the template at the top of the log. Entries go at the end, -newest last. - -## At session start -AGENT.md has you run `sh dev-skills/logging/pending.sh` before anything else. -- **Exit 0:** nothing pending; say nothing. -- **Exit 1:** tell the user *"There are uncommitted decisions in the audit log"*, list the lines - it printed, and stop. Do not resolve them unasked. -- **Exit 2:** it could not check (no log, not a repo); say so. +## Record format +``` +--- +date: YYYY-MM-DD +title: <title> +decided_by: [human:<handle>, <tool>/<model>] +supersedes: <YYYY-MM-DD-topic>.md +--- -On the user's go-ahead, resolve them (below). +**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. Commit them: `git add -- <paths>`, then `git commit -m "<title>"`. -3. `git rev-parse --short HEAD` is the hash. -4. Append the entry to `logs/audit_log.md` with that hash. -5. Commit the log alone: `git add -- logs/audit_log.md`, `git commit -m "audit log: <title>"`. -6. Run the check; it exits 0. -7. Report both hashes and anything left unstaged. Do not push. +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), -append the entry as `uncommitted` and stop; the next session's check brings it back. +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. -## Resolving `uncommitted` entries -For each line the check printed: -1. Read the entry and work out which files it describes. -2. **Already committed?** `git log --oneline -- <paths>`, then `git show --stat <hash>` on each - candidate. One commit that holds the work is the hash. -3. **Still in the working tree?** Commit it as in *Logging a decision*, steps 1–3. -4. **Neither, or several commits and no clear one?** Don't guess a hash. Tell the user what you - found and leave the entry as it is. -5. Replace `uncommitted` in the header with the hash. A `no commit <hash> here` line (a typo, or - history that was rewritten) is fixed the same way, once the right commit is known. +## 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. -Then commit the log once for all of them, `audit log: hashes for <n> entries`, run the check, -and report each entry with its hash, plus any left unresolved. Do not push. +`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/dev-skills/logging/pending.sh b/dev-skills/logging/pending.sh deleted file mode 100755 index 42227bf..0000000 --- a/dev-skills/logging/pending.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh -# Audit-log entries that do not name their commit: the hash is `uncommitted`, missing, -# or not a commit in this repo. Prints one line per entry; exit 0 none, 1 some, 2 cannot check. -# Reads entry headers only (`## YYYY-MM-DD — <hash> — <title>`), and only those below a -# `<!-- hashes from here -->` line when the log has one: entries above it predate hashes. -# Run from the repo root: sh dev-skills/logging/pending.sh [log] -log=${1:-logs/audit_log.md} -[ -f "$log" ] || { echo "pending.sh: no audit log at $log" >&2; exit 2; } -git rev-parse --git-dir >/dev/null 2>&1 || { echo "pending.sh: not in a git repo" >&2; exit 2; } - -start=$(grep -n '^<!-- hashes from here -->' "$log" | tail -n 1 | cut -d: -f1) -found=0 -tail -n +"$((${start:-0} + 1))" "$log" | grep -E '^## [0-9]{4}-[0-9]{2}-[0-9]{2} — ' > "${TMPDIR:-/tmp}/pending.$$" -while IFS= read -r header; do - rest=${header#* — } - hash=${rest%%[ ,]*} - case $hash in - uncommitted) why=uncommitted ;; - *[!0-9a-f]* | '') why='no hash' ;; - *) if [ ${#hash} -lt 7 ] || ! git cat-file -e "$hash^{commit}" 2>/dev/null; then - why="no commit $hash here" - else continue; fi ;; - esac - echo "$why: $header" - found=1 -done < "${TMPDIR:-/tmp}/pending.$$" -rm -f "${TMPDIR:-/tmp}/pending.$$" -exit $found 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