Skip to content

docs: one file per CAPABILITIES.md row; generated pages refresh after merge - #2518

Merged
abrichr merged 7 commits into
mainfrom
claude/capabilities-row-files
Nov 23, 2026
Merged

abrichr merged 7 commits into
mainfrom
claude/capabilities-row-files

Conversation

@abrichr

@abrichr abrichr commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Problem

Almost every pull request adds a row to a CAPABILITIES.md table (most at the end of "The core") and regenerates llms-full.txt, which quotes the whole page. So each merge to main makes the other open pull requests conflict. On 2026-11-22, git merge-tree against main showed 9 of 10 conflicting pull requests conflict in llms-full.txt, and 3 of them in CAPABILITIES.md.

Change

  • One file per row. capabilities/<NN>-<section>/section.md holds a section's prose and table header; each table row is capabilities/<NN>-<section>/<NNNN>-<slug>.md, one line, exactly as it prints. scripts/build_capabilities.py assembles CAPABILITIES.md (rows by number, then name; the command list from build_command_map.render()). The split reproduces the current page byte for byte.
  • Pull requests no longer regenerate the pages. .github/workflows/refresh-generated.yml runs on pushes to main that change a source, daily, and on dispatch. It regenerates CAPABILITIES.md and llms-full.txt and opens a draft pull request from bot/refresh-generated-<sha>, closing the one it replaces. It never pushes to main. It is a draft because GitHub starts no workflows for a pull request the workflow token opens; marking it ready runs CI. The body lists every line the refresh removes from CAPABILITIES.md.
  • A guard on the refresh. capabilities/CAPABILITIES.md.sha256 holds the hash of the page as the script last wrote it. When main's page no longer matches the hash or its sources (for example, an open pull request whose green CI predates --check-pr lands a hand-added row), the refresh stops, prints the lines no source produces, and opens a "CAPABILITIES.md refresh blocked" issue. It doesn't drop them.
  • A tolerant check in CI. The smoke job runs build_capabilities.py --check-pr HEAD^1. It passes when a page is current or untouched by the change, and fails a hand edit, which the next refresh would drop. Nothing strict runs on main or nightly, so a pending refresh never turns main red.
  • Tests read sources, not the committed pages: test_shipped_only_copy scans capabilities/, test_quickstart_command and the review-brief test use the generator's output, and the command-map test checks the assembled page. New: tests/test_build_capabilities.py.
  • Older branches. scripts/migrate_branch_to_split_files.py gains a step: during a merge of main, it moves the rows a branch added, edited or removed in CAPABILITIES.md into row files, and resets both pages to main's copy. Prose edits are listed for a person to move into section.md.
  • CLAUDE.md, CONTRIBUTING.md, capabilities/README.md, the commands README and the CI README now say: add or update your row file in the same pull request, and don't touch the generated pages.

Proof

rm CAPABILITIES.md && python scripts/build_capabilities.py
git diff --exit-code origin/main -- CAPABILITIES.md   # exit 0
sha256 ae64c9ece85b9ced00bb2e1078e750bfd2b3ec12d958fa19d6b6bb4b92dd3220 (both)

This pull request leaves CAPABILITIES.md and llms-full.txt unchanged, so it conflicts with no open pull request on them. A dry run of the migration on #2512 (a stack that adds 5 rows) kept all 5 and every row main had, and passed --check-pr. Link check now checks row links on the assembled page, where they print.

What changed from the brief: the brief asked for a per-PR test that CAPABILITIES.md is byte-identical to the script output. A strict per-PR test would make every pull request regenerate the page, and the page would conflict exactly as before. So the per-PR check is tolerant: it fails only a hand edit. Byte identity holds for this pull request, and the refresh pull request enforces it with --check.

Not covered: packages/flow/CHANGELOG.md conflicted in 6 of the 10 sampled pull requests, and .gitleaksignore in 2. Both are hand-edited lists, so this change doesn't touch them. Changelog fragments would be the matching fix.

Before merge

Rows that land on main after this branch's last sync have no row file. The guard stops the first refresh on them instead of dropping them. To avoid that, right before merging:

git merge origin/main
python scripts/build_capabilities.py --split      # re-split the newest page
rm CAPABILITIES.md && python scripts/build_capabilities.py
git diff --exit-code origin/main -- CAPABILITIES.md llms-full.txt

Commit the result. Never run --split after the split has landed: it rebuilds the row files from the committed page, so it would delete rows that exist only as row files.

Open pull requests that hand-edit CAPABILITIES.md fail --check-pr on their next CI run. python scripts/migrate_branch_to_split_files.py, run during their merge of main, moves their rows.

The refresh workflow is not exercised end to end; its first run is on main after merge.

… merge

CAPABILITIES.md is assembled from capabilities/<section>/<row>.md by
scripts/build_capabilities.py; the split reproduces the current page byte for
byte. Pull requests edit only sources. refresh-generated.yml opens a draft
pull request that regenerates CAPABILITIES.md and llms-full.txt from main,
and CI's --check-pr fails only a hand edit of either page. The migrate
script moves an older branch's rows into row files.
… the page

A pull request whose CI passed before --check-pr existed can still land a
hand-added row. The refresh now stops when CAPABILITIES.md no longer matches
capabilities/CAPABILITIES.md.sha256 (written with every regeneration), lists
the lines no source produces, and opens an issue. Link check reads row links
on the assembled page, where they print. --split keeps capabilities/README.md.
The refresh guard passes a page that already matches its sources, so a
regeneration that skipped the stamp can't block the refresh. Editor and OS
leftovers (.DS_Store, foo.md~) under capabilities/ are ignored. The refresh
finds its own pull requests by author, not among the first 50 open ones.
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

From: Gemini
Reviewed-Head: 1e0ac1e
Model: gemini-3.1-pro-preview (round 1; the 201 verbatim row files were left out of the diff)

Here is the review of the pull request, ranked by severity. The architecture cleanly solves the merge conflict problem, but there is a logic gap in the PR check that can permanently block the bot, and a local build crasher on macOS.

1. High: Accurate hand-edits pass CI but permanently block the refresh bot (Logic Error)

File: scripts/build_capabilities.py
Line: ~280 (Inside if "--check-pr" in argv:)

Problem:
The --check-pr logic is intended to be tolerant, but it creates a trap if a user hand-edits CAPABILITIES.md perfectly but forgets to manually update the hash in STAMP.

  1. If the user edits both capabilities/01-... and CAPABILITIES.md so they match, current != text is False.
  2. Because they didn't edit the STAMP file, _changed_since(base, STAMP) is False.
  3. The PR passes CI and merges.
  4. On main, the refresh bot runs --guard. It sees the STAMP hash doesn't match the new CAPABILITIES.md page. It checks if there are extra lines, finds none (because the page perfectly matches the sources), and returns 1, blocking the bot workflow permanently until a human fixes the STAMP.

Fix:
Enforce that if CAPABILITIES.md was changed, the STAMP must also be correct (meaning the user must have used the script, not hand-edited it). Add this at the end of the --check-pr block:

        for path, text in generated().items():
            current = path.read_text("utf-8") if path.exists() else ""
            if current != text and _changed_since(base, path):
                bad.append(_rel(path))
        
        # Ensure STAMP was updated if CAPABILITIES.md was hand-edited successfully
        if OUT not in bad and _changed_since(base, OUT):
            if STAMP.read_text("utf-8") != _stamp(OUT.read_text("utf-8")):
                bad.append(_rel(STAMP))

2. Medium: Stray/Hidden files crash the local build (Developer Experience)

File: scripts/build_capabilities.py
Lines: 96 (sections), 102 (rows)

Problem:
_numbered enforces a strict regex and raises a hard SystemExit if a file or folder doesn't match. macOS automatically generates .DS_Store files, and editors frequently generate hidden .swp or ~ backup files. If a developer opens the capabilities/ directory on a Mac, or their editor drops a backup file in a section folder, running python scripts/build_capabilities.py locally will crash immediately, disrupting local development.

Fix:
Filter out hidden files and enforce the .md extension before passing paths into _numbered:

# Line ~96
def sections(root: Path = SOURCES) -> list[Path]:
    return _numbered((p for p in root.iterdir() if p.is_dir() and not p.name.startswith((".", "__"))), _SECTION_DIR)

# Line ~102
def rows(section: Path) -> list[str]:
    """Return a section's table rows, in order, each checked to be one row."""
    files = (p for p in section.iterdir() if p.is_file() and p.name != SECTION and not p.name.startswith(".") and p.name.endswith(".md"))

3. Low: Bot PRs may duplicate in high-traffic repositories (Scale)

File: .github/workflows/refresh-generated.yml
Line: 73

Problem:
You are using gh pr list --state open --limit 50 to find the existing bot PRs to close them. In an active monorepo, if 50 non-bot PRs are opened while the bot PR sits open (or is left as a draft for a few days), the command will fail to fetch the bot's PR. The workflow will then erroneously open a duplicate refresh PR instead of updating/closing the old one.

Fix:
Filter the GitHub CLI search by the bot's author label or drastically raise the limit.

          open_prs="$(gh pr list --repo "$GITHUB_REPOSITORY" --state open --author "app/github-actions" --limit 100 \

(Note: If you use the standard bot token, the author string is app/github-actions).

A row file put directly under capabilities/ would never print, so the build
now fails on one instead of dropping it. Each refresh branch carries its run
id, so a rerun on the same main commit never meets a leftover branch.
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

From: Gemini
Reviewed-Head: cf14f54
Model: gemini-3.1-pro-preview (round 2)

Here is a review of the pull request, focusing on correctness, data-loss paths, and workflow logic errors, ranked by severity.

1. High: Silent data loss if a row file is placed in the wrong directory

File: scripts/build_capabilities.py
Line: ~127 (inside assemble())
Problem: If a contributor misreads the instructions and places their row file directly under capabilities/ instead of capabilities/<section>/ (e.g., capabilities/0100-my-row.md), the sections() function will silently ignore it because it only looks for directories. The --check-pr guard will pass because the user edited a source file without touching CAPABILITIES.md. Once merged, the refresh workflow will regenerate the page entirely ignoring the file, permanently dropping the row without raising any errors.
Fix: Explicitly guard against stray markdown files at the root of capabilities/. Update assemble() to fail the build if one is found:

def assemble(root: Path = SOURCES) -> str:
    """Return CAPABILITIES.md as the files under capabilities/ describe it."""
    for p in root.iterdir():
        if p.is_file() and p.name not in ("README.md", "CAPABILITIES.md.sha256") and _visible(p):
            raise SystemExit(f"{_rel(p)}: row files must be inside a section directory, not here")
    # ... rest of assemble()

2. Moderate: Branch collision blocks the refresh workflow

File: .github/workflows/refresh-generated.yml
Line: 104
Problem: The workflow names the refresh branch using the SHA of main (bot/refresh-generated-<sha>). If a workflow run manages to push the branch but fails before calling gh pr create (e.g., due to an API timeout), or if a maintainer manually closes the PR without deleting the branch, the branch remains remote. The next time the bot runs on the same main commit (e.g., via schedule or dispatch), it will attempt to push to the exact same branch name. Because the new commit has a different timestamp (generating a different commit hash), a standard git push will be rejected as non-fast-forward, permanently breaking the run.
Fix: Append --force (-f) to the git push command to ensure the bot can always update its own temporary branch:

          git push -q -f origin "HEAD:refs/heads/$branch"

3. Low: Row ordering bug in migration script edge-case

File: scripts/migrate_branch_to_split_files.py
Line: ~396 (inside _place_row())
Problem: If a row is dynamically inserted between two existing rows whose integer prefixes differ by exactly 1 (e.g., 0040-apple.md and 0041-banana.md), the formula low + (high - low) // 2 assigns the new row the number 40. The script resolves the filename collision by appending a suffix, resulting in 0040-<slug>-2.md. Because build_capabilities.py sorts these by (number, filename), the ordering between 0040-apple.md and 0040-aardvark-2.md will fall back to alphabetical string sorting. As a result, the new row could print before apple, violating the intended table insertion order.
Fix: Because this script is purely for one-time legacy branch migrations (and normal row increments step by 10), this is a minor edge case. No hard fix is strictly required, but you can avoid it by ensuring numbers are scaled wider during migration, or appending a 9 digit suffix to the name to guarantee it falls correctly in string-sort ordering.


Summary: The core architecture (especially how guard() leverages the STAMP to gracefully permit lagging pages while aggressively failing manual bypasses) is extremely robust. Merge conflicts will definitely be resolved by this design once the stray-file data-loss path is plugged.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

From: Claude
Reviewed-Head: 61c9140

Author declaration: Claude wrote the changes on this branch up to and including 61c9140. The two Gemini reviews above are the cross-vendor review for this head.

  • CAPABILITIES.md is unchanged. rm CAPABILITIES.md && python scripts/build_capabilities.py rebuilds it byte for byte from capabilities/. git diff --exit-code origin/main -- CAPABILITIES.md llms-full.txt exits 0, and both copies hash to sha256 ae64c9ec…dd3220.
  • Fixes from Gemini round 1.
    • The refresh guard now passes a page that already matches its sources, so a hand-regenerated page with a stale stamp can't block the refresh.
    • Editor and OS leftovers (.DS_Store, foo.md~) are ignored.
    • The workflow finds its own pull requests by author.
  • Fixes from Gemini round 2.
    • A row file put directly under capabilities/ now fails the build instead of being dropped.
    • Each refresh branch carries its run id, so the workflow never needs a force-push.
    • Left as is: round 2 noted that a migrated row inserted between rows whose numbers differ by 1 sorts by name. It affects only the one-time migration, which spaces rows by 10.
  • Tests.
    • tests/: 2311 passed, 9 skipped, one process. test_receipt_verify.py was left out because the local env has the PyPI openadapt-types.
    • packages/flow/tests/test_capabilities_map.py: 2 passed.
    • New: tests/test_build_capabilities.py and a git-level migration test in tests/test_migrate_split_files.py.
  • Migration dry run on feat(flow): repeating structures learned from the demo, added to match the intake and checked per instance #2512. feat(flow): repeating structures learned from the demo, added to match the intake and checked per instance #2512 is a stack that adds 5 rows. The dry run kept all 5 and every row on main, and --check-pr passed.
  • Not exercised end to end: refresh-generated.yml. Its first run happens on main after merge.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Gemini
Reviewed-Head: 61c9140

Independent cross-vendor adversarial review of 61c91401a72b5432302e1981909a7b3d8d2cc4d4 (Claude-authored; I authored none of this PR).

Findings & fail-closed verification

  • Round-2 blockers resolved:
    • scripts/build_capabilities.py:assemble() now fails closed (SystemExit) if any visible file other than README.md or CAPABILITIES.md.sha256 is placed directly under capabilities/, preventing silent row drops, covered by test_a_row_file_outside_a_section_fails_the_build.
    • .github/workflows/refresh-generated.yml appends -${GITHUB_RUN_ID} to bot/refresh-generated-${sha}-${GITHUB_RUN_ID}, preventing branch push collisions on reruns without force-pushing.
  • Data-loss & workflow safety: --guard checks CAPABILITIES.md.sha256 (and source equality) before regenerating, halting and opening/updating a "CAPABILITIES.md refresh blocked" issue instead of silently dropping hand-edited rows. The workflow never pushes to main (opens draft PRs and closes superseded ones). ci.yml runs --check-pr HEAD^1 to catch hand-edits to generated files while tolerating lagging pages, and link-check.yml validates assembled CAPABILITIES.md when capabilities/ changes.

Generality gate

  1. No per-app code in engine: Verified; pure documentation, CI workflow, and generator/migration tooling.
  2. Fix the class, not the instance: Verified; eliminates recurring CAPABILITIES.md / llms-full.txt merge conflicts across all PRs with one assembler, hash guard, PR check, and branch-migration helper.
  3. Held-out evidence: Honestly disclosed — byte-identical reassembly verified on CAPABILITIES.md, migration dry-run tested on feat(flow): repeating structures learned from the demo, added to match the intake and checked per instance #2512, and refresh-generated.yml noted as not yet exercised end-to-end until first run on main.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Grok
Reviewed-Head: b2fdb88

Delta versus Gemini APPROVE at 61c91401a72b5432302e1981909a7b3d8d2cc4d4 (request 7082881287). The only unique-file change at this head is the one-line Lychee exclude in .github/workflows/link-check.yml. No prior Grok verdict at this head. I did not merge.

P1 — The committed page and row files are out of sync; CI guard() fails

tests/test_build_capabilities.py::test_the_committed_stamp_matches_the_page_the_sources_build failed on CI (assert guard() == 0, got 1). guard() reported many lines on CAPABILITIES.md that no row file produces, including later main rows for effect locations, handoffs, flight, proxy, plan, ledger, wrap, and readiness.

The stamp file hashes the committed page, but the page is not what assemble() builds from capabilities/. This branch's merge-base is a23cf5a6, well behind current main. A GitHub merge into current main, or a stale post-split page, leaves rows on the assembled document that the split sources do not own. The smoke job also failed python3 scripts/build_capabilities.py --check-pr HEAD^1: it treats capabilities/CAPABILITIES.md.sha256 as a hand-edit of a generated file.

Please merge current main, regenerate the row files, the page, and the stamp together from the same sources, and show that guard() and --check-pr pass on the resulting merge.

P2 — The link-check fix is correct but not enough to land

Changing --exclude-path '^\./capabilities/' to --exclude-path '(^|/)capabilities/' is the right fix for path-prefix variation, and the assembled CAPABILITIES.md is still checked. The only other capabilities/ paths in the tree are Tauri JSON files, which this markdown glob does not include. That change does not fix the P1.

Note: launcher also failed test_help_text_is_byte_identical for openadapt. That is the known main-branch snapshot issue from #2421 (fix in #2546); it is not unique to this PR.

I will not approve this head until the split, the page, and the stamp match on a current-main merge.

Re-ran build_capabilities.py --split on main's page: 216 row files (was 201).
The assembled page is byte-identical to origin/main.
@abrichr

abrichr commented Nov 22, 2026 •

Copy link
Copy Markdown
Member Author

From: Claude
Reviewed-Head: 81397a8

Author declaration: Claude wrote the merge of origin/main at 24034b5 into this branch at 81397a8. It's an ordinary merge with no force-push and no conflicts.

  • Re-split. python scripts/build_capabilities.py --split was run on main's CAPABILITIES.md. That left 216 row files, up from 201. The 15 new rows are the ones main gained since the last sync, and main edited 3 existing rows. Section prefixes are renumbered by 10, so most row files show as renames.
  • Byte identity. rm CAPABILITIES.md && python scripts/build_capabilities.py and then git diff --exit-code origin/main -- CAPABILITIES.md llms-full.txt exits 0. Both pages hash to sha256 9427a5c0…ca65, which matches capabilities/CAPABILITIES.md.sha256.
  • No row lost or duplicated. Main has 234 table lines. Those are 216 rows plus 18 header and separator lines, which live in section.md. The multiset of main's table lines equals the row files plus the headers.
  • Derived files. build_command_map.py and build_llms_full.py were rerun and produced no change against main.
  • Tests. I ran the capabilities, migration, shipped-only-copy, documented-tasks, quickstart, capabilities-map and compatibility-matrix tests in one process: 102 passed, 1 skipped. --check, --check-pr origin/main and --guard all exit 0. The 1-minute load average was 14.2 at the start.
  • Protected paths. None are touched, according to .github/agent-safety-manifest.json.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Claude
Reviewed-Head: 81397a8

A fresh Claude reviewer agent checked the head read-only. It had no part in authoring the change. Its scope was whether any capability row from main was lost, changed, duplicated or reordered.

  • Byte identity. The page that assemble() builds from capabilities/ is byte-identical to origin/main:CAPABILITIES.md. So are the committed CAPABILITIES.md and llms-full.txt. The stamp capabilities/CAPABILITIES.md.sha256 equals the sha256 of main's page. --check and --guard exit 0.

  • Counts. Main has 234 table lines: 216 rows plus 18 header and separator lines, which sit in section.md. The sorted multiset of main's table lines equals the row files plus the section headers.

  • Rows per section. Each matches main:

    Section Rows
    often-missed 19
    the core 61
    approvals 8
    branching 11
    surfaces 16
    fastest layer 27
    when the app changes 18
    computer-use agents 32
    recording, privacy and proof 24
  • Rows main added since the merge base a23cf5a65. Main added 20 lines and removed 5, and 3 of the removals were edits to existing rows. All 20 current lines are present as row files.

  • File hygiene. The reviewer found no stray, empty, multi-line or misnamed files under capabilities/. Each section with rows has exactly one <!-- capability rows --> marker.

  • Files outside capabilities/. Against main, the only files changed outside capabilities/ are the PR's own. Main has moved on since by fix: canonicalize default durable-authority home root and uvx doctor hints #2550, which doesn't touch CAPABILITIES.md or llms-full.txt.

Nit, not blocking: --check-pr HEAD^1 in ci.yml assumes CI checks out a merge commit, which the pull_request event does.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: 81397a8

Delta versus my leftover-lane REQUEST CHANGES at b2fdb883ae0d7e6f3c3c46e5bddc187308ba45c7 (7083733679). This is a round-2 re-review at the new head (merge of origin/main at 24034b59d plus re-split). I did not author this change. I am not merging.

P1 from 7083733679 is fixed

On this tree I reproduced:

  • assemble() is byte-identical to the committed CAPABILITIES.md (155913 bytes) and to origin/main:CAPABILITIES.md. llms-full.txt also matches current main.
  • capabilities/CAPABILITIES.md.sha256 is the sha256 of that page (9427a5c0…).
  • python scripts/build_capabilities.py --guard exits 0.
  • python scripts/build_capabilities.py --check-pr HEAD^1 and --check-pr origin/main both exit 0. Generated files that match generated() are no longer treated as hand-edits.
  • There are 216 row files (was 201 at the previous head), plus 14 section files. tests/test_build_capabilities.py and tests/test_migrate_split_files.py: 15 passed, 1 skipped.

The earlier failure mode — a stamp that hashed a page assemble() could not rebuild, so guard() and the smoke --check-pr failed — is gone.

Notes, not blocking

I will not merge, tag, publish, dispatch, or rerun.

@abrichr
abrichr merged commit 93c4cba into main Nov 23, 2026
53 of 54 checks passed
@abrichr
abrichr deleted the claude/capabilities-row-files branch November 23, 2026 00:33
abrichr added a commit that referenced this pull request Nov 23, 2026
#2518 split the page into capabilities/ row files from main as of 17:13 EST.
Six later first-parent commits updated the stamped page and were kept on
merge, but not the row files, so the stamp test and refresh workflow went
red (#2562). Fold those edits into the sources and regenerate the stamp.
CAPABILITIES.md is unchanged.

- #2471: VERIFIED-run prose; fault-test and openIMIS measured-results notes
- #2477: grade file/PDF/email checks by artifact provenance
- #2472: api_recheck row
- #2397: GraphQL / probe_read_routes text on the transaction-lens row
- #2363 / #2368: second-factor row, including terminal/Windows console

Fixes #2562
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