--- name: egm-bootstrap license: Apache-2.0 disable-model-invocation: true description: Bootstrap EGM directory contracts bottom-up with read-only Copilot scouts and principal-only documentation writes. --- # EGM Peanuts and Hay Bootstrap Before any work, read [Copilot integration](../../docs/copilot.md), including when this skill is invoked directly. Its host adaptation applies throughout. Generate or correct directory contracts from source code, bottom-up, without changing production source. The main session owns discovery, synthesis and all documentation writes. Read-only scouts extract factual source contracts. ## Inputs and constraints - `path`: target root directory; ask if missing. - `target_filename`: default `README.md`. Offer `EGM.md` when human-maintained READMEs should remain untouched. Require a simple Markdown filename, not an absolute path, separator, `.` or `..`; ask for correction before writing. - `is_worker` and `sub_tree_root` are upstream internal parameters. If supplied, explain that this flat adapter has no writing workers and ask the user to select the intended `path`; never silently process a different root. Do not generate implementation files, install dependencies, run builds or tests, stage changes or commit. Record the project's verification command as guidance, not as a claim that it was executed. Use session-private scratch storage if needed, never a shared fixed location. Do not spawn a workflow or unbounded worker swarm. ## Step 0: Discover verification conventions Inspect root manifests and existing project instructions to identify the actual test runner and targets. Examples include `package.json`, `Cargo.toml`, `go.mod`, `pyproject.toml`, `Makefile` and Bazel BUILD files. Do not invent a test command; omit it or label it undetermined if unavailable. For Bazel use valid package patterns such as `//pkg/...` or `//pkg:all`, never `//pkg:...`. ## Step 1: Incremental scope and mandatory approval Discover the tree breadth-first, listing only one level per operation. Do not use a recursive directory search to bypass the incremental gate. Ignore symlinks/junctions, hidden/system directories, dependencies and generated output, including `.git`, `node_modules`, `.venv`, `vendor`, `dist` and `build`. Track the running number of discovered subdirectories, excluding the root. As soon as more than 15 subdirectories are discovered, pause further discovery and ask one structured approval question before any scouts or full-tree work: "The target tree contains more than 15 subdirectories. Continue bootstrapping the full tree?" Wait for an explicit answer. Abort on refusal or cancellation. Do not interpret the initial skill invocation as permission for this gate. After approved discovery, prune bottom-up: - Keep directories with actual production source, schema, query or infrastructure code, and their intermediate ancestors. - Exclude test-only directories and test files (`test_*`, `*_test.*`, `*Test.*`, `*.spec.*`); do not infer production behavior from fixtures. - Exclude documentation-only, asset-only, lockfile-only and generic-data trees. - Use recognized source types, including compiled languages, C#, Java, Swift, scripts, TypeScript, SQL, protobuf, GraphQL and Terraform. - Preserve intermediate nodes needed to connect code-bearing descendants. If no code remains, report that no contracts were generated and stop. Show the retained scope and ask about any unclear boundary or resource limits before extensive parallel execution. Do not impose an arbitrary new cap. ## Step 2: Read-only source extraction Read [the scout contract](../../resources/bootstrap-scout.md) and [the payload schema](references/scout-return.schema.json). For every directory in post-order (deepest leaves first): 1. Read an existing `target_filename`, if present. Preserve its title, metadata, developer notes and architecture narrative. Correct code claims against source; old documentation is not evidence that a symbol exists. 2. Discover source symbols and divide large inputs at definition boundaries, approximately 1,500 lines per scout, without truncating function bodies. Include imports and top-level definitions for visibility and dependencies. 3. Spawn a fresh `elephant-gun:egm-codebase-details` child for each assigned source chunk, Mode BOOTSTRAP, with absolute package root, directory, source paths/ranges, scout contract and explicit child-contract summaries. Parallelize independent chunks when the approved scope and host allow. The scout cannot delegate, execute commands or write files. 4. Read contracts, schemas and manifests first; entry points second; production sources alphabetically next; relevant config last. Ignore tests. Read production source in full across chunks, not just symbol listings. Check imports and manifest dependencies before attributing remote services, tables or generated schemas to a local file. 5. Wait for actual completion. Check status, required fields and citations against the assigned reading list before using the payload. A malformed payload, missing child, denied read or timeout is incomplete. Record the failure and its directory explicitly; never use `["None"]` or invented interfaces to conceal a failure. Scouts always remain read-only, even for small trees. If native delegation is unavailable, stop; do not turn the principal into an allegedly fresh scout. No `egm-bootstrap-orchestrator`, nested workers or dynamic registration. ## Step 3: Main-session compilation Read [the README templates](references/templates.md) before writing. Merge verified scout evidence and already compiled child summaries. - A component with direct source uses the Component Package (Peanuts) template. - An intermediate code-bearing ancestor uses the Intermediate Blueprint. - The target root always uses the Repository Root Blueprint (Hay), with local interface/invariants when it also contains direct code. - Use source-grounded Interface, Invariants and Side Effects sections. Use `None` only when complete extraction found no explicit entries. - Preserve unrelated existing prose; edit the contract, do not replace the entire human-maintained document blindly. - Write only inside the approved tree, using `target_filename`. - Link to child contracts only after those files exist. Never invent a link to a failed contract or a similarly named non-contract asset. - For an incomplete directory, keep existing content, label unverified sections explicitly if updating them, and list the failure in the parent's unlinked incomplete-status section. Continue independent branches only as partial work. Use ordinary relative links for child/sibling contracts. Do not create links whose text is a warning rather than a real filesystem target. Keep an index of all created/modified paths and completion states. ## Step 4: Verification and human handoff Explicitly reread every created or modified contract, including all descendants. Check Markdown, symbols, citations, Interface/Invariants/Side Effects for components, root/intermediate template sections, and every relative link. Verify that all links resolve and that commands match actual project manifests. Correct ungrounded claims before marking a contract complete. Report the actual modified paths and all incomplete branches. Any unresolved scout or verification failure makes the overall run partial, not successful. Do not claim tests were run merely because a Verification section exists. Ask one structured question whether to run `egm-drift-report` on the generated contracts. Wait; do not start drift checking on an unanswered or declined gate. If accepted, supply the exact created/modified paths as the explicit document scope, preserving the incomplete-status information.