When running in Codex or ChatGPT Work, first read
Codex integration.
In Claude Code or Cowork, read
${CLAUDE_PLUGIN_ROOT}/docs/claude.md
first.
This skill automates the creation, correction, formatting, and correctness
verification of Elephant-and-Goldfish Model (EGM) compliant
files
across a directory tree. It establishes clear architectural contracts
(interfaces, invariants, and side effects) for both human developers and AI
assistants.
A Goldfish runs in a fresh context with no conversation history. Spawn each
subagent with your harness's subagent tool (Antigravity:
; Claude Code:
; Codex:
). Each subagent is defined in
, and its
frontmatter
(for example
) is the subagent type to request
where your harness registers named subagents. Otherwise spawn a general-purpose
subagent and tell it to read that persona file first. Pass the prompt verbatim
and wait for the report. If your harness cannot nest subagents,
use direct dispatch instead of the synthesizer. See
.
If your harness has no subagent tool, run the scout steps inline.
-
Incremental BFS Discovery: Map the target
tree level-by-level
(BFS) using a directory queue, listing one directory level at a time. (CRITICAL: never run a recursive search such as
or
.)
- Preserve intermediate folder nodes.
- Ignore symbolic links to prevent infinite recursion.
- Ignore hidden/system directories (, , ,
, , , ).
- Read and (if present) and ignore matching glob patterns.
- Preserve package and build manifests (, ,
, , , ) in the discovery map
to extract verification targets later.
-
Safety Gate & Unbounded Spawning Approval (CRITICAL): During the BFS
loop, if the total running count of discovered directories exceeds 15,
immediately pause discovery and request user approval (using a structured question tool, if your harness has one, or plain chat) to warn the user and request approval
for full-tree execution:
- : "The target directory tree contains more than 15
subdirectories. This is a large execution scope. Do you want to proceed
with full-tree bootstrapping?"
- :
["Yes, proceed with full tree bootstrapping", "No, abort execution"]
- (CRITICAL: After requesting approval, you MUST wait for the user's
response before continuing or spawning any workers).
- If the user selects abort, terminate execution immediately.
-
Bottom-up Post-Pruning Pass: Once mapping is complete (and approved),
walk the mapped tree bottom-up (leaves to root). Filter out non-code and
test-only directories:
- Source Code Files: Files matching recognized source code, schema, and
contract extensions:
- Systems & Compiled: , , , , , , ,
, , ,
- Managed & Enterprise: , , , ,
- Scripting & Dynamic: , , , , ,
- Web & Mobile: , , , , , , ,
,
- Data & Schemas / IDLs: , , , ,
,
- Infrastructure / Declarative Code: , ,
(Excludes build manifests, lockfiles, test fixtures, documentation, and
generic data dumps like , , ).
- Test Directory Exclusion: Exclude directories containing exclusively
test code (e.g. named , , , or containing only
files matching , , , or ).
- Non-Code Filtering: Exclude any directory that contains no source code
files AND contains no subdirectories with code. Retain empty
intermediate folders only if they have child directories that contain
code.
-
Calculate the total count of pruned directories and maximum depth. Proceed
to Step 3: Execution Strategy Selection.
-
Direct Execution Strategy (Directory Count <= 5):
- If the total count of pruned directories is 5 or fewer, execute the bottom-up
documentation directly in the current thread.
- Jump to Step 4: Sub-Orchestrator Worker Flow (treating the Root
Orchestrator as the worker for the entire ), and then proceed to
Step 5: Root Compilation & Termination.
-
Unbounded Parallel Subagent Swarm Strategy (Directory Count > 5):
- (CRITICAL: If Directory Count > 15, you MUST verify that you have
received explicit user approval before proceeding. If not yet approved,
request approval immediately and wait for the user's response before
spawning workers).
- Partition the discovery map into independent subtree branches using the
Adaptive Depth Partitioning Algorithm:
- Set .
- Extract directory nodes from the discovery map located at the
current .
- If the count of nodes at is between 3 and 5: select these
nodes as subtree partition roots.
- If the count of nodes at < 3: increment (up to a max
of 3) and repeat step 2.
- If the count of nodes at > 5: group the largest branches (by
total nested folder count) into 3-4 separate partitions, combine the
remaining small branches into a single fallback partition subtree,
and select these as partition roots.
- Fallback: If reaches 3 and count is still < 3, select the
immediate children of the root (or fall back to sequential
execution).
- Spawn Unbounded Sub-Orchestrators: For each partition subtree root,
use your harness's subagent tool to spawn a parallel worker:
- Subagent:
egm-bootstrap-orchestrator
(agents/bootstrap_orchestrator.md
) (or a general-purpose subagent)
- : "Run egm-bootstrap with path=,
is_worker=true, sub_tree_root=,
target_filename=."
- Unbounded Execution: Spawn all Sub-Orchestrators in parallel without
artificial concurrency limits (as authorized by the user during the
safety gate).
- Go idle and wait for all worker subagents to return their JSON subtree
index payloads. Jump to Step 5: Root Compilation & Termination.
-
Receive Worker Payloads: Collect the JSON
payloads
returned by all parallel Sub-Orchestrators.
- Root Fault Tolerance: If a parallel worker fails or times out, log a
warning, insert a placeholder warning link (
[Subtree Root] (Documentation failed / Subagent execution timeout)
) in the root
Blueprint's subdirectory index, and complete the remaining compilation.
(Worker failures leaving partial files are handled as an incremental
progress feature; the Correction Policy allows resuming on subsequent
runs).
-
Intermediate Directory Documentation: Identify any intermediate
directories sitting between the root
and the partitioned subtree
roots.
- Process these intermediate directories sequentially bottom-up.
- Generate Intermediate Blueprint contract files using the compiled summaries
returned by the workers.
- Ensure clean formatting and valid relative links for each Intermediate
Blueprint contract file.
-
Root Directory Documentation: The target root
of the execution is
always classified as the
Repository Root (Blueprint / Hay).
- Check if already exists in . If present, apply the
Correction & Modification Policy to read and retain the existing
title, metadata, and architectural overview at the top of the root
contract file.
- Check if itself contains any direct source files. If present,
spawn a scout for to extract local symbols
and invariants, appending them under the optional
## Local Interface & Invariants
section.
- Compile the final root using the Repository Root Blueprint
Template, rolling up all top-level subdirectory boundaries. Ensure any
root architecture or sequence diagrams strictly match the synchronous /
asynchronous boundaries, operation names, and storage backends in the
child payloads without inventing unverified nodes.
- Write the root using your file-writing tool.
-
Final Correctness Verification (CRITICAL): You MUST perform a final
verification pass across ALL created and modified contract files in the
(including all child package contracts like
and
) as a correctness check before concluding work. You
MUST explicitly read every single created or modified contract file
to verify its content. Do not skip any child contract files. Verify:
- EGM Compliance & Code Grounding: Ensure , ,
and sections exist, cite real code symbols/flags/tables
from the scout extraction, and contain zero speculative or unverified
claims.
- Markdown Syntax: Ensure clean headers, valid tables, and proper code block fences.
- Valid & Resolvable Links (CRITICAL): Ensure all subdirectory and
sibling links use valid relative paths (
./subdir/${target_filename}
or
), and explicitly verify that every referenced target
file actually exists on the filesystem. Remove or correct any broken
relative references.
- Valid Targets: Verify verification targets match project test
configuration and use valid target syntax (for Bazel, or
, never ).
-
Optional Drift Review (CRITICAL): After verification, ask the user (using
a structured question tool, if your harness has one, or plain chat) to offer running a drift report
on the generated documentation updates:
- : "Do you want to run the EGM Drift Report on the generated
contract updates to check for consistency with the codebase?"
- :
["(Recommended) Yes, run drift report on modified contracts", "No, skip drift review"]
- If the user selects "Yes", run the skill targeting
the modified contracts to verify 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). (Note:
While is often used for design documents, it can be
applied to EGM-compliant contracts as a variant).
-
Terminate execution successfully.