Skip to content

feat: ownership table in CONVENTIONS.md (gen-index, validate, init, upgrade, skill) - #115

Merged
pasrom merged 6 commits into
mainfrom
feat/ownership-table
Nov 27, 2026
Merged

pasrom merged 6 commits into
mainfrom
feat/ownership-table

Conversation

@pasrom

@pasrom pasrom commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

What

An ownership table in a brain's CONVENTIONS.md: where each kind of fact lives, so a review can name the home of a figure instead of guessing it from search hits.

  • CONVENTIONS.md gets a ## Ownership section with two tables: a hand-written one (Topic | Home | Notes) and, under ### Mounted repositories, a generated one (Mount | Repository | Branch | Holds) between two marker lines.
  • km gen-index fills the generated table from .gitmodules alone (new src/km/ownership.py): one row per submodule whose path the git index holds as a gitlink, sorted by path. Nothing is read from inside a mount and no pin is listed, so a pin bump leaves the table fresh. Holds comes from the optional key submodule.<name>.km-owns; without it the cell says _not stated_.
  • km gen-index --check fails on a stale table. Broken markers: nothing is written (no _index.md either), exit 1 with a fix line. Without markers the file is left alone (opt-in by marker presence).
  • km validate (whole-repo runs only) warns ownership-stale, ownership-markers, ownership-topic, ownership-home, ownership-duplicate. A dead row link stays the existing dead-link.
  • Both km init templates carry the section with an empty generated block.
  • km upgrade appends the section, its table filled, once, when the brain crosses from a km at or below 1.26.0 (OWNERSHIP_AFTER).
  • Skill references: the review rule looks the home up in the table first (hand rows, then mounts) and names the row; brain add/brain remove regenerate the table and stage CONVENTIONS.md, and brain add offers to set km-owns; the validate and setup references list the warnings and the upgrade step. SKILL.md is untouched (11992 bytes).

No release and no version bump in this PR.

Format example

## Ownership

| Topic | Home | Notes |
|-------|------|-------|
| Pump controller ratings | [docs/pump-controller-ratings.md](docs/pump-controller-ratings.md) | from the datasheet |

### Mounted repositories

<!-- km:ownership:begin: generated by km gen-index from .gitmodules -->

| Mount | Repository | Branch | Holds |
|---|---|---|---|
| `brains/alpha` | `https://example.com/acme/alpha` | this brain's branch | Pump timing |
| `tools/res` | `https://example.com/acme/res` | default | _not stated_ |

<!-- km:ownership:end -->

Cells: bytes that do not decode become U+FFFD; format characters (zero-width, bidi) are dropped; whitespace and newlines collapse; control characters and backticks become ?; | is escaped; a cell stops at 200 characters with an ellipsis. Mount, Repository and Branch are code spans (so IPv6 brackets survive); in Holds, plain text, [ ] become spaces and < is &lt;. A url loses its user info (user:token@, and the user of scp-style user@host:path), its query and fragment, and a trailing .git. Branch . reads "this brain's branch", none reads "default". Two submodule names for one path give one row.

Marker lines inside fenced code are examples, not markers, and each marker line must close its comment on that line. CONVENTIONS.md is compared with LF and written back in the line ending it has (CRLF where it has any). A CONVENTIONS.md or .gitmodules that is a symbolic link is neither read nor written through; gen-index prints a note.

Warnings

Warning When
ownership-stale the generated block differs from what km gen-index writes
ownership-markers begin or end line missing, doubled or out of order (no ownership-stale then)
ownership-topic a mount has no km-owns
ownership-home a row of the hand table (headed Topic) has no link and no URL
ownership-duplicate the same topic, case-folded, in two hand rows

All warnings, exit code unchanged. Rows in HTML comments or fenced code are ignored.

Upgrade behaviour

  • Crossing 1.26.0, no ## Ownership heading and no markers: the section is appended at the end of CONVENTIONS.md, table filled.
  • Crossing, a hand-written ## Ownership without markers: a note, no diff.
  • Markers present, or not a crossing (already past 1.26.0, or the target is 1.26.0 itself): nothing. A second run is byte-identical.

Since this PR does not bump the version, the crossing only happens with --pin to a later km (the tests use the fake remote's v1.99.0); after the 1.27.0 release it happens on a plain km upgrade.

Operational effect: adding, removing or renaming a mount, or changing its url, branch or km-owns, now needs CONVENTIONS.md restaged; the km-gen-index hook and CI fail until it is. CONVENTIONS.md and .gitmodules are control files for km ready, so such a PR needs a person's label, as before.

Tests

All suites CI runs, locally on macOS:

Suite Before (main) After
gate_smoke 393/0 393/0
index_smoke 82/0 82/0 (its ownership cases moved to ownership_smoke)
ownership_smoke (new) 44/0
pins_smoke 38/0 38/0
cites_smoke 90/0 90/0
doctor_smoke 103/0 103/0
sync_smoke (default) 78/0 78/0
sync_smoke KM_TEST_UV=require 79/0
list_smoke 45/0 45/0
ready_smoke 28/0 28/0
search_smoke 51/0 51/0
automerge_smoke 139/0 139/0
signoff_smoke 136/0 136/0
skill_smoke 5/0 5/0
hook_smoke 31/0 31/0
mounted_pins_smoke 2/0 2/0
runner_smoke 31/0 31/0
action_smoke 13/0 13/0
e2e_smoke 40/0 40/0
e2e_agent_smoke 121/0 121/0
team_smoke 278/0 285/0 (+7)
encoding_smoke 4/0

sync_smoke with KM_TEST_UV=forbid cannot run on this machine (uv is on the PATH, which that mode rejects: 78/1 on that guard alone); CI runs it. The Latin-1 locale step of team_smoke and the Windows job run in CI only. e2e_smoke caught the seed's mount commit leaving the new table stale; the seed now regenerates it in that commit (folded into the init commit).

Mutation checks

Each new case group fails without its change (edit, run, restore). The first ten rows ran when these cases still lived in index_smoke; they moved to ownership_smoke unchanged but for the url cell now being a code span.

Mutation Fails
drop the gitlink intersection in rows() ownership_smoke "a .gitmodules entry without a gitlink is no row"
drop the userinfo strip ownership_smoke "a url change makes it stale; the user info and .git are dropped"
render ignores the branch ownership_smoke "branch . reads as this brain's branch"
validate does not call ownership.problems ownership_smoke warnings + markers cases
no home / duplicate / topic / stale check (each alone) ownership_smoke "home, duplicate, stale and topic warn on their condition"
HTML comments not stripped from the hand table ownership_smoke "a row in a comment warns nothing"
ownership checks also on per-file runs ownership_smoke "per-file runs skip the table"
read() follows a symlinked CONVENTIONS.md ownership_smoke "gen-index writes nothing through a symlinked CONVENTIONS.md"
remove the upgrade's crossing gate team_smoke "upgrade to this km adds no ownership section" and the crossing case
a hand row without a home in the personal template team_smoke "personal brain in git ... warns nothing" and the SECTION check
no U+FFFD for undecodable bytes (_clean dropped) ownership_smoke undecodable byte (gen-index, rerun, PRE_COMMIT) and the upgrade case
the same, with write_text opening the file before encoding ownership_smoke undecodable byte cases (the file must stay whole)
markers counted inside fences ownership_smoke "fenced example" and "only markers are in a fence"
a begin line may leave its comment open ownership_smoke "begin comment wrapped onto two lines"
no CRLF on write / no LF on read ownership_smoke CRLF cases (gen-index and upgrade)
no scp-style strip / no query strip / url not a code span ownership_smoke url cases (IPv6 brackets among them)
no path dedupe ownership_smoke "two names for one path give one row"
no format-character strip / no length cap ownership_smoke "format characters are dropped and a cell is cut at 200 characters"
a symlinked .gitmodules is read ownership_smoke ".gitmodules symlink"
upgrade: a fenced ## Ownership counts / no note on a mounts heading ownership_smoke "an '## Ownership' heading in a fence is none; a mounts heading ... gets a note"

Evals

Run with claude plugin eval . --scaffold --no-publish --allow-tools Bash Write Edit --case <name>, 3 runs each.

Case Ablation Score
review-ownership-table (new) none 1.00 (3/3), first round; 1.00 (3/3) again after the review fixes, with the new names-the-ownership-row grader. No baseline run, so it guards the rule rather than measuring a lift
review-restated-value none 1.00 (3/3), and 1.00 (3/3) after the review-rule change
review-doc none 1.00 (3/3)
brains-list-remove with-without, final grader with 1.00, without 0.42, delta +0.58
brains-list-remove none, after the brains.md fix below 1.00 (3/3)
lookup-all-brains none, after brain_with_two_peers generates its table 1.00 (3/3)

Not rerun: km-queue, pr, pr-review-comments, fix-in-mounted-brain (its fixture shares brain_with_peer, which now also generates the table row).

The first version of stages-conventions required the removal to be committed. In two runs (1 of 3 with --ablation none, 3 of 3 in the first with-without run) the eval sandbox refused writes to .gitmodules and .git/config, so the model ran km gen-index, staged CONVENTIONS.md with the removal and stopped without committing, saying why. The grader now also passes that state (both staged, the reason given); it still fails a run that never regenerates the table or commits the removal without it. The baseline without the plugin never runs km gen-index (0/3 on that grader in both with-without runs).

Deviations from the design and what the checks showed

  • Mount-root link resolves in dead-link: confirmed by test, both for a checked-out mount and for one not checked out (deinit). No change needed.
  • Mounts stay outside the dead-link scan: confirmed; a mount with its own dead link adds no dead-link to the brain (git lists no file inside a gitlink). No change needed.
  • git ignores km-owns: confirmed (git submodule update --init and status print nothing about it). bump-mounted-pins reads only path, url and branch: confirmed by importing the shipped script and checking each entry's keys; the template is unchanged, so no SHIPPED hash change.
  • Symlinked CONVENTIONS.md: not in the original design. km gen-index, km validate and km upgrade neither read nor write through a symlinked CONVENTIONS.md (it may point outside the repository); gen-index prints a note. Tested and mutation-checked.
  • PRE_COMMIT: the design relied on pre-commit noticing the modified file. A rewrite of CONVENTIONS.md under PRE_COMMIT now also exits 1, so the failure does not depend on that; _index.md rewrites keep their behaviour.
  • render(text, root) takes the brain root as a second argument (the design had render(text)).
  • Hand-table checks apply to tables headed Topic in the ## Ownership section only, also where the section has no markers; the generated-table checks need the markers.
  • Upgrade fixture: the team-1.22 fixture holds only workflows, so the upgrade cases build a team brain pinned to v1.11.0 and strip the section the current template writes, which is what a brain from before this change has.
  • Review pass: /simplify and /code-review were not run, since both fan out to sub-agents; instead a manual pass over the whole diff (code, templates, skill references, tests, evals, e2e seed, hook yaml) for reuse, simplification and correctness. It led to three changes: the stale check reuses the rows it already read instead of reading .gitmodules twice; brain add now stages .gitmodules with CONVENTIONS.md (the km-owns edit comes after submodule add staged .gitmodules, so staging CONVENTIONS.md alone would commit a table ahead of .gitmodules); the section text no longer says CI checks the table, since a personal brain has no CI (it says km validate reports it).

Second review round

Folded into the commits that introduced each problem:

  • Undecodable bytes could empty CONVENTIONS.md (gen-index and upgrade): a byte in .gitmodules that does not decode raised while writing, after the file was opened. Now km.paths.write_text encodes before it opens any file, and values from .gitmodules turn such bytes into U+FFFD.
  • Fenced examples of the markers no longer count as markers, and a begin line that does not close its comment is a broken marker.
  • CRLF: compared as LF, written back in the file's own line ending (gen-index and upgrade).
  • Windows: the ownership cases moved to tests/ownership_smoke.sh, which the smoke and windows jobs both run; the symlink cases skip where ln -s makes no symlink.
  • Review rule: a kind of fact with no row gives at most one note per review, listing those topics, and only where the home was found another way. The new grader names-the-ownership-row checks that the reply names the row (CONVENTIONS.md with a line, or the ownership table/row/section).
  • Eval fixtures: brain_with_two_peers also generates its table in the mount commit.
  • Smaller fixes: scp-style user, query and fragment stripped from urls, IPv6 brackets kept; one row per path; format characters dropped and cells capped at 200 characters; a symlinked .gitmodules is not read; upgrade finds the heading and markers with the parser (outside fences) and notes a Mounted repositories heading of the brain's own while still adding the section.

@pasrom
pasrom force-pushed the feat/ownership-table branch from 223f1f7 to 94999f4 Compare November 27, 2026 18:49
…NS.md

CONVENTIONS.md may carry an ownership section whose mounted-repositories
table sits between two marker lines. km gen-index fills it from
.gitmodules alone: one row per submodule whose path the index holds as a
gitlink, sorted by path, with its url (user info and .git dropped), its
branch and what it holds (the optional submodule.<name>.km-owns key).
No pin is listed, so a pin bump leaves the table fresh. Without markers
the file is left alone; with broken ones nothing is written and the run
exits 1. --check fails on a stale table, and under pre-commit a rewrite
fails the commit. A CONVENTIONS.md or .gitmodules that is a symbolic
link is neither read nor written through, with a note.

Marker lines in fenced code are examples, and a marker line must close
its comment. The file is compared with LF and written back in its own
line ending. Bytes that do not decode become U+FFFD, and write_text
encodes before it opens a file, so nothing can empty it halfway.
Cells drop format characters and stop at 200 characters; mount, url and
branch are code spans. A url loses user info (scp-style too), query and
fragment; two names for one path give one row.

The cases live in tests/ownership_smoke.sh, which CI runs on Linux
and Windows.
Whole-repo runs read the ownership section of CONVENTIONS.md and warn:
ownership-stale (the generated table differs from .gitmodules),
ownership-markers (a begin or end line missing, doubled or out of
order), ownership-topic (a mount without km-owns), ownership-home (a
hand row with no link and no URL) and ownership-duplicate (a topic in
two rows). All are warnings; a dead link in a row stays dead-link.
Both templates, personal and team, carry the ownership section: a
header-only Topic | Home | Notes table to fill by hand, and the
mounted-repositories table with its generated block empty, as
km gen-index renders it with no mount. A fresh brain stays at zero
warnings and gen-index --check passes.
km upgrade appends the ownership section to CONVENTIONS.md, its
mounted-repositories table filled from .gitmodules, once: when the
brain moves from a km at or below 1.26.0 to a later one, and only where
the file has neither an Ownership heading nor the table's markers. A
section of the brain's own gets a note and no change; a brain already
past 1.26.0 is left alone. Headings and markers are found outside
fenced code; the section is written in the file's line ending, and a
'Mounted repositories' heading of the brain's own gets a note.
…n brain add and remove

The review rule looks a fact's home up in the ownership table first
(hand rows, then the mounted repositories), names the row in the
finding, lists the topics with no row in at most one note and reports an unreadable home as not
compared. brain add and brain remove regenerate the table and stage
CONVENTIONS.md, and brain add offers to set km-owns. The validate
reference lists the five warnings; the setup reference says what the
upgrade adds.
review-ownership-table reviews the wiring note in a brain whose
ownership table names a second page as the home of the pump
controller's ratings: the finding must name that page and line, after
reading CONVENTIONS.md. brains-list-remove gets a grader that the
regenerated CONVENTIONS.md is staged with the removal, for one commit
(committed, or staged where the sandbox refused the commit); its fixture now
generates the mount's row in the mount commit, so the table starts
fresh, and so does brain_with_two_peers. The new case also checks
that the reply names the Ownership row it used.
@pasrom
pasrom force-pushed the feat/ownership-table branch from 94999f4 to f6df992 Compare November 27, 2026 19:29
@pasrom
pasrom merged commit 338e31f into main Nov 27, 2026
5 checks passed
@pasrom pasrom mentioned this pull request Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant