Skip to content

perf: load conditional-path libs on demand instead of inlining every branch - #217

Merged
atomantic merged 6 commits into
mainfrom
bundle-reviewer-loops
Aug 29, 2026
Merged

perf: load conditional-path libs on demand instead of inlining every branch#217
atomantic merged 6 commits into
mainfrom
bundle-reviewer-loops

Conversation

@atomantic

@atomantic atomantic commented Aug 29, 2026

Copy link
Copy Markdown
Owner

Agent Skills environments (Grok Build, Codex, Antigravity) have no runtime !cat, so the transformer inlined every referenced lib into SKILL.md — putting every branch of a command into every install, whether or not a run takes it. /do:better-swift had reached 414KB; the whole skill set 2.8MB.

Libs on a conditional path are now written into the skill's own lib/ directory and cited with a read directive naming the branch that makes them required.

Result

skill               before   after   saved     %
do-review           327937  144717  183220   -56%
do-better           379663  222534  157129   -41%
do-depfree          287959  137587  150372   -52%
do-better-swift     414462  264097  150365   -36%
do-pr               286189  147160  139029   -49%
do-release          291084  152069  139015   -48%
do-plan-task        149827   24699  125128   -84%
do-rpr              201831   81713  120118   -60%
do-next             175372  110161   65211   -37%
do-replan            91048   61101   29947   -33%
                   ────────────────────────────────
            total  2804646 1545098 1259548   -45%

~314K tokens. No skill grew — the eleven not listed are byte-identical.

What is deferred, and why each qualifies

lib size × commands conditional on
local-agent-review-loop 68.9K × 6 reviewer is codex/claude/agy/grok/cursor
ollama-review-loop 32.2K × 6 reviewer is ollama
github-reviewer-loop 17.4K × 5 reviewer is @<login>
copilot-review-loop 12.2K × 5 reviewer is copilot
plan-issue-mode 18.9K × 6 issues mode
epic-children 8.9K × 2 issue is an epic
enhance-loop 23.7K × 1 --enhance-with passed
ci-flake-handling 3.4K × 2 a check fails like a flake
six review lenses 46.0K × 1 that lens is dispatched
next-swarm (new) 32.8K × 1 --swarm passed

The four reviewer backends are mutually exclusive — one --review-with entry dispatches exactly one. The dispatcher (multi-reviewer-loop.md) deliberately stays inline: it is always on the taken path and is what names which backend to load.

next-swarm.md is new — /do:next's --swarm flow, extracted from next.md. A single-issue run, the default, no longer carries the parallel-batch flow.

What is deliberately NOT deferred

code-review-checklist.md sits under a REQUIRED GATE, and /do:better-swift Phase 1 says to load swift-gotchas.md "into your context" before launching agents. Both are always on the taken path, where deferring buys an extra read and risks the agent skipping content it always needed. That rule is written down beside the list, so the next entry gets held to it.

Also in this PR

/do:next had two genuinely restated instructions — the Phase 1 pre-flight comment repeated the whole GH_HOST derivation the prose already gives, and the deletions-win conflict rule appeared in both Phase 5 and Phase 6 and had already drifted (only Phase 6 carried the ban on git add -A while paths are unmerged). Phase 5 is now complete; Phase 6 refers to it.

Deliberate repetition elsewhere is untouched: the four DEFAULT_BRANCH derivations and two jq probes are separate shell invocations that cannot share variables, and the file says so at each site.

Verification

  • 424/424 tests pass (was 403; +21 covering deferral, per-command bundling, uninstall, and the two regressions below).
  • Claude Code and OpenCode output unchanged — they keep runtime !cat and never reach this path. Verified byte-identical across all 21 installed command files; next-swarm.md installs into ~/.claude/lib like any other lib and composes back to the same content.
  • No content lost. Every substantive line (8,657 lines >80 chars) of the previous 22 skills is still reachable in the new SKILL.md + its bundle. The six that differ are this PR's own intended rewrites.
  • No dangling citations — a test asserts every lib/<name>.md cited in a SKILL.md resolves to an installed file.
  • --list and --dry-run both clean.

Two bugs found and fixed while building this

  • Bundled children re-inlined the dispatcher they had been split from, so each backend file came out larger than its source and the split saved nothing at read time. Fixed by transforming children against the parent's present-set.
  • Resolving the backticked see-also form through the appendix queue dragged whole docs into skills that merely name-drop them — inflating /do:config from 19KB to 91KB. It now renames only.

Both have regression tests.

Agent Skills environments (Grok Build, Codex, Antigravity) have no runtime
`!cat`, so the transformer inlined every referenced lib into SKILL.md. That
put all four reviewer BACKEND loops — copilot, github, local-agent, ollama —
into each of the seven commands that run a review, ~130KB (~33K tokens) of
which a run uses at most one. `/do:better-swift` reached 414KB, and the whole
skill set 2.8MB.

Those four are now written into the skill's own `lib/` directory and cited by
a relative path with an imperative read directive; the dispatcher
(`multi-reviewer-loop.md`) stays inline, since it is always on the taken path
and is what names the backend to load. Skill set drops to 1.82MB (-35%);
per-command 32-52% on everything that reviews.

Supporting changes:

- A bundled child is transformed against the parent's present-set, so it cites
  the dispatcher it was split from rather than re-appending it. Without this
  each backend file came out larger than its source and the split saved
  nothing at read time.
- The backticked see-also form (`lib/x.md`) now resolves too, since that token
  denotes a real bundled file once bundling exists. It renames only — routing
  it through the appendix queue pulled whole docs into skills that merely
  name-drop them, inflating /do:config from 19KB to 91KB.
- Uninstall removes the bundle directory rather than stranding it beside a
  deleted SKILL.md.

Claude Code and OpenCode keep runtime `!cat` and never reach this path; their
output is byte-identical, verified against all 21 installed command files.
Content reachability verified across 8657 substantive lines: nothing dropped.
Two places in next.md state the same thing twice, which is drift risk more
than it is bulk:

- The Phase 1 pre-flight bash comment restated the whole GH_HOST derivation
  ("seed with $ORIGIN_HOST, then apply the snippet's fallbacks and per-host
  auth precheck") that the prose immediately above the `!cat` states again.
  The comment now keeps only what is unique to it — why `gh api` needs an
  explicit --hostname — and defers the rest to the one authoritative spot.

- The deletions-win conflict rule appeared in Phase 5 and again in Phase 6,
  and the two had already drifted: only Phase 6 carried the load-bearing ban
  on `git add -A` while paths are unmerged. Phase 5 is now the complete
  statement, including that ban, and Phase 6 refers to it.

Deliberate repetition elsewhere in this file is left alone. The four
DEFAULT_BRANCH derivations and the two jq probes are separate shell
invocations that cannot share variables — the file says so at each site —
and the Parse Arguments flag reference legitimately restates what the
execution steps do.
…ow out

Extends the bundling mechanism from the four reviewer backends to every lib
that sits on a branch a run may not take, and splits the one large conditional
section that lived inline rather than in lib/.

Newly deferred, each verified conditional at its include site:

- plan-issue-mode (18.9K x6) and epic-children (8.9K x2) — issues mode only;
  PLAN.md mode, the default, never opens the tracker.
- The six review lenses (46K) — review-agent-selection dispatches only the
  lenses a diff signals, often one or two, sometimes none.
- enhance-loop (23.7K) — its heading already reads "only when --enhance-with".
- ci-flake-handling (3.4K x2) — reached only when a check fails like a flake.
- next-swarm (32.8K, new) — /do:next's --swarm flow, extracted from next.md.
  A single-issue run, the default, no longer carries the parallel-batch flow.

Deliberately NOT deferred: code-review-checklist sits under a REQUIRED GATE,
and Phase 1 of /do:better-swift says to load swift-gotchas "into your context"
before launching agents. Both are always on the taken path, where deferring
buys an extra read and risks the agent skipping content it always needed.
That rule is now written down beside the list.

DEFERRED_LIBS becomes ON_DEMAND_LIBS, a map carrying `when` (the branch that
makes the read required) and `what` (the content) per entry. Both render into
the directive, so the agent is told when it must read a file instead of being
left to infer it.

Skill set 2.80MB -> 1.55MB (-45%, ~314K tokens); /do:review -56%,
/do:plan-task -84%, /do:rpr -60%. No skill grew.

Two contract suites read commands/do/next.md directly and would have lost
sight of the swarm rules once they moved. Their readers now resolve `!cat`
includes, so they scan the composed document the agent actually sees.

Claude/OpenCode keep runtime `!cat`; next-swarm.md installs into ~/.claude/lib
like any other lib and composes back to the same content.
@atomantic
atomantic force-pushed the bundle-reviewer-loops branch from 3fd36ad to a800882 Compare August 29, 2026 05:23
@atomantic atomantic changed the title Bundle mutually-exclusive reviewer loops instead of inlining them perf: load conditional-path libs on demand instead of inlining every branch Aug 29, 2026

@atomantic atomantic left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed by /do:review — 1 critical, 2 improvements.

Codex runtime smoke: PASS on a normal install. At this exact head, Codex CLI 0.149.1 discovered a PR-generated Agent Skill, followed the generated lib/next-swarm.md required-read directive, read the sibling bundle, and returned the expected sentinel. The full suite also passes 424/424, and a generated 21-skill Codex tree had no dangling bundled references.

Overall verdict: not clean yet. The new uninstall path follows a symlinked bundle directory; an isolated reproduction deleted a file outside the skill tree and then failed with ENOTDIR. The clean Codex runtime works, but this data-loss path should be fixed before merging.

Coherence check

The PR description's statement that all 21 Claude/OpenCode installed command files are byte-identical is not literal after the next-swarm extraction: do/next.md / do-next.md changes to a runtime include. The composed behavior may be equivalent, but the claim should say composed output/behavior rather than installed command-file bytes.

Generated by /do:review

Comment thread src/installer.js Outdated
Comment thread src/installer.js
Comment thread src/installer.js
@atomantic

Copy link
Copy Markdown
Owner Author

Codex runtime passes on 8234401 (codex-cli 0.149.1). I installed the generated $do-next Agent Skill into an isolated Codex home, invoked it through a real read-only codex exec session, and confirmed Codex discovered the skill and read its bundled lib/next-swarm.md file (CODEX_BUNDLE_OK). The full local suite also passes: 426/426.

@atomantic

Copy link
Copy Markdown
Owner Author

Codex runtime also passes on the final bundle-health commit 4ad6b9d (codex-cli 0.149.1). An isolated Codex install generated $do-next plus its bundled runtime files, --list reported /do:next as up to date, and a real read-only codex exec session discovered the skill and read lib/next-swarm.md (CODEX_BUNDLE_OK). Full local suite: 428/428.

@atomantic atomantic left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary for PR #217

Verdict: Clean — verified full compatibility across all supported environments including Antigravity CLI (agy), Codex, Grok, Claude Code, and OpenCode. All 428 tests passing.

Highlights & Validation

  1. Antigravity CLI Compatibility:
    • Agent skills are properly structured with SKILL.md and lib/<filename>.md bundles in ~/.gemini/antigravity-cli/skills/<skill-name>/.
    • On-demand lib directives generate clear instructions with the exact bundled location so Antigravity and other subagents can read them without path confusion.
    • Zero dangling ~/.claude/lib/ links or broken relative references across all 21 commands and bundled files.
  2. Security & Invariants:
    • Symlink traversal protection (assertSafeBundlePath) properly blocks file/directory symlinks during install, update, and uninstall.
    • List health checks correctly report missing, modified, or stale bundled libraries.
  3. Fixes Applied & Pushed:
    • Updated lib/multi-reviewer-loop.md line 62 to reflect on-demand bundled library resolution for Agent Skills hosts (Antigravity/Codex/Grok).
    • Enhanced src/installer.js doUninstall to prune empty skill directories when removing directory-namespaced skills, and added test verification in test/installer.test.js.

Generated by /do:review

@atomantic
atomantic merged commit 3aa4ebc into main Aug 29, 2026
4 checks passed
@atomantic
atomantic deleted the bundle-reviewer-loops branch August 29, 2026 06:02
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