egm-bootstrap
Bootstrap directory README.md files across a repository subtree.
SKILL.mdskills/egm-bootstrap/SKILL.md
GitHubEGM Peanuts and Hay Bootstrap (egm-bootstrap)
When running in Codex or ChatGPT Work, first read Codex integration.
In Claude Code or Cowork, read ${CLAUDE_PLUGIN_ROOT}/docs/claude.md first.
Automates creating, updating, and verifying Elephant-and-Goldfish Model (EGM) README.md contracts (Interface, Invariants, Side Effects) across a directory tree: Peanuts (leaf package contracts) and Hay (parent blueprint indexes).
Inputs
path: Target root directory to bootstrap (Required).is_worker: Internal;truewhen running as a Sub-Orchestrator (default:false).sub_tree_root: Internal; subtree partition root path.target_filename: Contract filename to generate or update (default:"README.md", or e.g."EGM.md"when preserving human-written READMEs).
Execution Constraints (CRITICAL)
- Delegation & Plugin-Root Paths: Read the Plugin-Root Resource Paths and Subagent Delegation (Goldfish Isolation) sections of execution instructions (Claude Code:
${CLAUDE_PLUGIN_ROOT}/resources/execution_instructions.md; pathless<SKILL>:~/.gemini/config/plugins/egm/resources/execution_instructions.md). Do not apply theegm-brainstorm/egm-draft/egm-reviewor drafting-only sections here. If file tools cannot read it, apply inline delegation: spawn fresh-context subagents (invoke_subagent/Agent/spawn_agent), use direct dispatch if nesting is unsupported (see harnesses.md), or run scout steps inline if no subagent tool exists. - No Code Generation & VCS Isolation: Strictly limited to documentation (
README.md/target_filename). Do not write or refactor functional source code, and do not perform version control commits (git add,git commit). Write all changes locally using standard file-writing tools; tracking and submitting stay with the human user. - Temporary File Isolation: Each worker keeps its status, checkpoint, and log files in its own directory outside the workspace (host scratch or
mktemp -d), never a fixed, shared path. If neither exists, skip them. - Tool Usage & Formatting: Use shell and file tools for discovery and contract generation following README templates with clean Markdown (headers, tables, fenced blocks; optionally invoke a configured repo formatter like
npx prettier --write). - Subagent Delegation: Spawn sub-orchestrator workers in parallel (capped at 5).
- Mandatory Safety Gate (> 15 Subdirectories): If BFS discovery finds more than 15 subdirectories, pause immediately and request user approval (via structured single-select question tool if available, or plain chat) before proceeding with full-tree execution or spawning workers.
Workflow
Step 0: Ecosystem & Verification Discovery
Inspect the repo root manifest to record VerificationCommand:
- Node/TS (
package.json):npm test(orpnpm test/yarn test) - Rust (
Cargo.toml):cargo test| Go (go.mod):go test ./...| Python (pyproject.toml/pytest.ini/setup.py):pytest - .NET / C# (
*.sln/*.slnx/*.csproj):dotnet test - Make (
Makefile):make test| Bazel (BUILD/BUILD.bazel):bazel test //...| None:<test-command>
Step 1: Startup Branching
If is_worker is true, jump to Step 4 for sub_tree_root. Otherwise run Step 2.
Step 2: Incremental Scoping & Safety Gate (Root Orchestrator)
- BFS Discovery: Map
pathlevel-by-level via a queue (never recursivefindorls -R). Keep intermediate folders and build manifests (package.json,Cargo.toml,go.mod,pyproject.toml,*.sln,*.csproj,Makefile,BUILD). Ignore symlinks, hidden/system directories (e.g.,.git,.antigravity,node_modules,venv,dist,build,third_party), and patterns in.gitignore/.egmignore. - Safety Gate & Spawning Approval (> 15): When running directory count exceeds 15, pause and ask via single-select gate (
is_multi_select: false):question:"The target directory tree contains more than 15 subdirectories. This is a large execution scope: up to 5 parallel workers, and at least one scout per code directory (one per ~1,500 lines of source). Do you want to proceed with full-tree bootstrapping?"options:["Yes, proceed with full tree bootstrapping", "No, abort execution"]Wait for the user; abort immediately if declined.
- Bottom-Up Post-Pruning:
- Recognized Source / Schema Extensions: Systems (
.c,.cc,.cpp,.cxx,.h,.hh,.hpp,.rs,.go,.zig,.lean,.f,.f90,.f95,.f03,.f08,.hs), Managed (.java,.kt,.scala,.cs,.razor,.cshtml,.fs,.vb), Scripting (.py,.rb,.php,.lua,.sh,.bash,.ps1,.psm1,.psd1,.r,.R,.ex,.exs), Web/Mobile (.ts,.tsx,.js,.jsx,.mjs,.cjs,.swift,.m,.dart), Schemas/IDLs (.sql,.proto,.graphql,.gql,.thrift,.prisma), Infra (.tf,.hcl,.cue). Exclude manifests, lockfiles, fixtures, docs, and.csv/.tsv/.parquet. - Exclude Test-Only Dirs: Skip
tests,testing,testdata, or dirs holding only*_test.*,*Test.*,test_*.*,*.spec.*. - Non-Code Filtering: Drop directories with neither direct code nor code-containing subdirectories; keep empty intermediate folders only when descendants hold code.
- Recognized Source / Schema Extensions: Systems (
- Compute pruned directory count and max depth, then run Step 3.
Step 3: Execution Strategy Selection (Root Orchestrator)
- Direct (
<= 5pruned dirs): Run Step 4 inline onpath, then Step 5. - Parallel Subagent Swarm Strategy (
> 5pruned dirs): Verify> 15approval first if applicable. Partition via Adaptive Depth Partitioning:- Start at
depth = 1. Collect nodes atdepth. If 3-5 nodes, use them as partition roots. - If
< 3, incrementdepth(max 3) and re-check. If> 5, take the 3-4 largest branches separately and combine smaller ones into one fallback subtree. - If
depth == 3and still< 3, pick immediate children of root (or run sequentially). - Worker Cap: For each partition subtree root, spawn their Sub-Orchestrators in parallel, never more than 5. Use
egm-bootstrap-orchestrator(agents/bootstrap_orchestrator.md, passing its absolute path if resolved from<plugin-root>, or a general-purpose subagent):Prompt:"Run egm-bootstrap with path=[path], is_worker=true, sub_tree_root=[partition_root], target_filename=[target_filename]." - Wait for all worker JSON
subtree_indexpayloads, then proceed to Step 5.
- Start at
Step 4: Sub-Orchestrator Worker Flow
- Scout Setup (
goldfish-explorer): Register (where runtime subagent definition is supported) or prompt a read-only scout (enable_write_tools: false,enable_subagent_tools: false) with:You are a read-only codebase explorer. Analyze source files in the target directory and return a JSON object matching
{"interface": string[], "invariants": string[], "side_effects": string[]}. Do not write files. Never infer RPC methods, routes, status enums, or invariants from file or directory names alone; cite exact[file:symbol_or_flag]for every entry, and output["None"]if no explicit invariants or side effects exist in code. - Post-Order Traversal (Deepest Leaves First) across
D:- Correction Policy: If
target_filenamealready exists inD, read it (never blindly overwrite), scan code viagoldfish-explorer, extract legacy public symbols, invariants, and side effects as JSON ({"interface": string[], "invariants": string[], "side_effects": string[]}), merge with code-verified scout output, and edittarget_filenamepreserving valid developer notes. - Scout Reading & Chunking: No per-directory or per-file byte cap. List top-level definitions with your search tool first, then read every non-test file in full in chunks of ~1,500 lines cut at top-level definitions (never mid-body; small files share a chunk). Spawn one
goldfish-explorerper chunk in parallel, at most 5 at a time (queue the rest), give each chunk the file's imports and top-level definitions to judge visibility, and merge their JSON. Verify build-manifest deps andimport/#includebefore attributing RPCs, schemas, or message types locally. Read order: (1) contracts, schemas, build manifests (.h,.hh,.hpp,.proto,.graphql,.gql,.thrift,.prisma,.sqlDDL, interfaces; extract exact DDL tables and exported targets); (2) entry points (main.*,index.*,lib.*,mod.*,__init__.py, dir-named files) then source/query files alphabetically; (3) templates/configs <= 200 lines each (800 in config-only dirs), excluding.css/.scss; (4) ignore test files (*_test.*,*Test.*,test_*.*,*.spec.*) everywhere. On scout timeout/failure, log a warning and use["(Details pending/documentation failed)"]. - Parent Propagation: Pass merged child
interfacesummaries into parentP's scout prompt. - Verification Commands: Use
VerificationCommandor the manifest inDor nearest ancestor (.NET:dotnet teston the nearest*.csproj). For Bazel, always emitbazel testorbazel buildwith valid targets (//[package_path]/...or//[package_path]:all; NEVER//[package_path]...,//[package_path]:..., or bare...); usebazel runfor runners. - Template & Link Policy: Read README templates before writing. Use Component Package (Peanuts) when
Dhas direct code (plus child contract links if any) and Intermediate Blueprint whenDhas only child contracts. Use relative links (./child/${target_filename},../sibling/${target_filename}) only for dirs existing in prunedsubtree_indexwith real files (link./child/SKILL.mdfor skill dirs or omit uncreated links), and repo/URL links for external cross-package refs. Format cleanly.
- Correction Policy: If
- Report or Continue: Compile
subtree_index(path,summary,interface,invariants,side_effects). Ifis_workeristrue, read Worker Return Interface Schema, return the matching JSON payload, and stop. Otherwise proceed to Step 5.
Step 5: Root Compilation & Termination (Root Orchestrator)
- Collect Worker Payloads: Merge
subtree_indexJSON results. On worker timeout/failure, insert[Subtree Root] (Documentation failed / Subagent execution timeout)in the root index and continue. - Intermediate Directories: Read README templates if not already loaded, and document intermediate folders between
pathand partition roots bottom-up using the Intermediate Blueprint template and valid relative links. - Root Contract (
path): Always classifypathas Repository Root (Blueprint / Hay) using the Repository Root Blueprint Template, rolling up all top-level subdirectory boundaries. Preserve existing top title/metadata/overview via Correction Policy iftarget_filenameexists. Ifpathhas direct source files, scout them viagoldfish-explorerinto## Local Interface & Invariants. Ensure root diagrams reflect only verified sync/async boundaries, operations, and stores fromsubtree_index, then writetarget_filename. - Final Correctness Verification (CRITICAL): Re-read every created or modified contract file in
subtree_index(including all child packages) and verify:Interface,Invariants, andSide Effectssections cite verified[file:symbol_or_flag]entries (orNone) without unverified claims.- Valid Markdown headers, tables, fences, and Bazel/test targets (
/...or:all, never:...). - Every relative link (
./subdir/${target_filename},./subdir/SKILL.md) points to an existing file on disk (remove or fix broken links).
- Optional Drift Review: Present a single-select gate (
is_multi_select: false):question:"Do you want to run the EGM Drift Report on the generated contract updates to check for consistency with the codebase?"options:["(Recommended) Yes, run drift report on modified contracts", "No, skip drift review"]If selected, run egm-drift-report over modified contracts to check both missing code coverage and doc-to-code hallucinations (verifying every documented method, route, enum, database table, and invariant against local source files and recording discrepancies in the drift report for human triage).
- Terminate cleanly.