|
| 1 | +--- |
| 2 | +name: agent-exploration |
| 3 | +description: >- |
| 4 | + Dispatches scoped-write explorer subagents in parallel for general research |
| 5 | + and exploration of any codebase, topic, or domain. The operator passes |
| 6 | + --path (output directory), --agents (parallel count), and --prompt (research |
| 7 | + question). The parent scouts the territory first to divide work, dispatches |
| 8 | + N explorer subagents that each write one analysis file at |
| 9 | + <path>/analysis/NN_analysis_<slug>.md following a seven-section schema, then |
| 10 | + synthesizes <path>/analysis/summary.md. The skill self-contains the explorer |
| 11 | + subagent definition and prompts the operator to install it at |
| 12 | + .claude/agents/explorer.md when absent. Use when running parallel multi-area |
| 13 | + research that must produce written artifacts. Do not use for competitor-only research |
| 14 | + already covered by cy-research-competitors, single-file lookups answerable |
| 15 | + by Explore, or edits to existing code. |
| 16 | +trigger: explicit |
| 17 | +argument-hint: "[--path <dir>] [--agents <num>] [--prompt <text>]" |
| 18 | +metadata: |
| 19 | + author: Pedro Nauck |
| 20 | + github: https://github.com/pedronauck |
| 21 | + repository: https://github.com/pedronauck/skills |
| 22 | +--- |
| 23 | +# Agent Exploration |
| 24 | + |
| 25 | +Generic parallel-research workflow. Use when a question requires deep reads across multiple distinct areas and the operator needs written artifacts (not chat output). The skill dispatches `explorer` subagents in parallel; each writes one analysis file. The parent then synthesizes a final summary. |
| 26 | + |
| 27 | +The skill is self-contained. It ships two explorer subagent definitions side by side so the same skill works on both major harnesses: |
| 28 | + |
| 29 | +- **Claude Code**: `assets/explorer-agent.md` → installed to `.claude/agents/explorer.md` (Markdown with YAML frontmatter). |
| 30 | +- **OpenAI Codex CLI**: `assets/explorer-agent.toml` → installed to `.codex/agents/explorer.toml` (single TOML document with `sandbox_mode = "workspace-write"` and the scoped-write contract carried in `developer_instructions`). |
| 31 | + |
| 32 | +The parent verifies installation for the active harness before every dispatch. |
| 33 | + |
| 34 | +## Required Reading Router |
| 35 | + |
| 36 | +Match your step to the row. Read the listed files **in full before** producing output. They are not appendices — they are load-bearing. Inline content in this SKILL.md is a pointer, not a substitute. |
| 37 | + |
| 38 | +| Step | MUST read | |
| 39 | +| ------------------------------------------------------- | ---------------------------------------------------------------------- | |
| 40 | +| Step 4 — composing every subagent prompt | `references/dispatch-rules.md` + `assets/analysis-template.md` | |
| 41 | +| Step 5 — verifying outputs | `references/checklist.md` + `assets/analysis-template.md` | |
| 42 | +| Step 6 — synthesizing `summary.md` | every `<path>/analysis/NN_analysis_<slug>.md` from this round | |
| 43 | +| Any contract violation, fabricated evidence, or retry | `references/dispatch-rules.md` (re-read; do not paraphrase from memory)| |
| 44 | + |
| 45 | +## Reference Index |
| 46 | + |
| 47 | +- `references/dispatch-rules.md` — the scoped-write contract: what the subagent may write, may read, may run; tool allow/forbid lists; parent responsibilities; parallelism cap; failure handling. **Must be embedded verbatim in every subagent prompt.** |
| 48 | +- `references/checklist.md` — seven-section output validation checklist (installation, inputs, scout, dispatch, files, schema, summary). Run before authoring `summary.md`. |
| 49 | +- `assets/analysis-template.md` — the canonical seven-section schema every subagent fills (Overview, Mechanisms/Patterns, Relevant Sources, Transferable Patterns, Risks/Mismatches, Open Questions, Evidence) plus a Scope header. |
| 50 | +- `assets/explorer-agent.md` / `assets/explorer-agent.toml` — the bundled subagent definitions for Claude Code and Codex CLI. Installed by `scripts/install-explorer.sh`. |
| 51 | +- `scripts/install-explorer.sh` — bootstrap helper. Writes the explorer definition to the active harness's expected path. Refuses to overwrite. |
| 52 | + |
| 53 | +## Bundled Path Rule |
| 54 | + |
| 55 | +Resolve every bundled helper relative to the directory that holds this `SKILL.md`. When a command appears below as `scripts/<name>`, treat the actual invocation as `<agent-exploration-dir>/scripts/<name>` — expand `<agent-exploration-dir>` to the absolute skill directory before running. |
| 56 | + |
| 57 | +## Required Inputs |
| 58 | + |
| 59 | +- `--path <dir>` (required): Output directory. Analysis files are written under `<path>/analysis/`. Any project-relative or absolute directory works (for example `docs/research/<topic>/`, `tasks/<slug>/`, or a path outside the repo). The skill is not tied to any specific project layout. |
| 60 | +- `--agents <num>` (optional, default 3, hard cap 8): Number of explorer subagents to dispatch in parallel. Caps prevent runaway dispatch when the prompt is vague. |
| 61 | +- `--prompt <text>` (required): The research question. Quoted multi-line strings are supported. If omitted, the parent asks the operator before continuing. |
| 62 | + |
| 63 | +If `--path` or `--prompt` is missing, the parent asks the operator a single clarification before continuing. Never invent defaults for either. |
| 64 | + |
| 65 | +## Output Layout |
| 66 | + |
| 67 | +``` |
| 68 | +<path>/analysis/ |
| 69 | +├── 01_analysis_<slug-a>.md |
| 70 | +├── 02_analysis_<slug-b>.md |
| 71 | +├── 03_analysis_<slug-c>.md |
| 72 | +└── summary.md |
| 73 | +``` |
| 74 | + |
| 75 | +- File numbering is zero-padded to two digits (`01`, `02`, …, `08`). |
| 76 | +- Each slug is a short kebab-case identifier the parent assigns during the scout (Step 3), reflecting that slice's focus. |
| 77 | +- `summary.md` is parent-authored synthesis, not a subagent output. |
| 78 | + |
| 79 | +## Procedures |
| 80 | + |
| 81 | +**Step 1: Verify the explorer subagent is installed** |
| 82 | + |
| 83 | +1. Detect the active harness: |
| 84 | + - If the runtime is Claude Code (project contains `.claude/` or `CLAUDE.md`), the expected install path is `.claude/agents/explorer.md`. |
| 85 | + - If the runtime is Codex CLI (project contains `.codex/` or `AGENTS.md`), the expected install path is `.codex/agents/explorer.toml`. |
| 86 | + - If both are present, both targets must be installed (or the operator must opt out per-target). |
| 87 | +2. For each expected target, check whether the file exists. |
| 88 | +3. If every expected target is present, proceed to Step 2. |
| 89 | +4. If any expected target is missing, ask the operator a single question naming the missing targets: e.g. "The `explorer` subagent is not installed for Claude Code (.claude/agents/explorer.md) and Codex CLI (.codex/agents/explorer.toml). Install both now? [yes/no/claude-only/codex-only]". Do not proceed silently. |
| 90 | +5. On any "yes" answer, run the bundled bootstrap helper (`scripts/install-explorer.sh` — **bootstrap helper, writes one or two files**) with the matching `--target`: |
| 91 | + - `<agent-exploration-dir>/scripts/install-explorer.sh --target both` (default) |
| 92 | + - `<agent-exploration-dir>/scripts/install-explorer.sh --target claude` |
| 93 | + - `<agent-exploration-dir>/scripts/install-explorer.sh --target codex` |
| 94 | + Add `--user` to install into `$HOME` instead of the nearest project root. The helper refuses to overwrite existing files and prints `OK` / `SKIP` per target. |
| 95 | +6. On "no", abort the dispatch with a one-line message. Do not dispatch the `explorer` subagent before installation completes — the dispatch will fail with "agent not found". |
| 96 | +7. After installation, re-check that the expected target file(s) exist before continuing. |
| 97 | + |
| 98 | +**Step 2: Resolve inputs** |
| 99 | + |
| 100 | +1. Parse `--path`, `--agents`, `--prompt` from the invocation. If `--path` or `--prompt` is missing, ask the operator and stop. |
| 101 | +2. Default `--agents` to `3` when omitted. Reject values below 1 or above 8 — ask the operator to choose a value in range. |
| 102 | +3. Resolve `--path` to an absolute path. If the directory does not exist, ask the operator whether to create it before continuing. |
| 103 | +4. Create `<path>/analysis/` if absent. The subagents refuse to write into a missing directory. |
| 104 | + |
| 105 | +**Step 3: Parent-led initial scout (MANDATORY — do not skip)** |
| 106 | + |
| 107 | +The scout is the load-bearing step that prevents wasted parallel dispatch. The parent must do this work itself before any subagent is launched. |
| 108 | + |
| 109 | +1. Perform a brief read-only exploration of the problem space using `Glob`, `Grep`, and targeted `Read` calls. The scout's job is to learn enough about the territory to divide it well — not to produce analysis content. Cap the scout at 8–15 tool calls; deep reading belongs to the subagents. |
| 110 | +2. From the scout, identify exactly `--agents` distinct slices that are: |
| 111 | + - **Non-overlapping** — two slices should not require reading the same primary files for the same purpose. |
| 112 | + - **Independently answerable** — a slice's analysis must not depend on another slice's output. |
| 113 | + - **Aligned with the operator's `--prompt`** — every slice serves the original research question. |
| 114 | +3. For each slice, assign: |
| 115 | + - A two-digit ordinal (`01`..`08`). |
| 116 | + - A short kebab-case slug (≤ 4 words) reflecting that slice's focus (e.g. `state-machine`, `event-bus`, `auth-boundaries`). |
| 117 | + - A focused per-slice prompt that names the slice question, the primary source paths/URLs to read, and any cross-references the subagent should use. |
| 118 | +4. Briefly tell the operator the slice list (one line per slice: `NN – slug – focus`) before dispatching. Do not ask for approval unless the slices look thin or overlap; just announce and proceed. |
| 119 | + |
| 120 | +If the scout reveals that fewer than `--agents` non-overlapping slices exist, reduce the dispatch count and tell the operator. Do not pad slices to hit the requested count. |
| 121 | + |
| 122 | +**Step 4: Dispatch explorer subagents in parallel** |
| 123 | + |
| 124 | +Gist tripwires — the contract items the parent must enforce in every prompt: |
| 125 | + |
| 126 | +- The prompt names three things: slice scope, slug+ordinal, exact target file path. If any is missing, the subagent must refuse and ask back. |
| 127 | +- The subagent gets exactly one `Write` — at the named target path — and nothing else. No `Edit`, no `git`/`make`/package managers, no writes outside `<path>/analysis/`. |
| 128 | +- All subagents dispatch in the same parallel batch with `subagent_type: explorer`. Wait for the full set before continuing. |
| 129 | + |
| 130 | +**STOP. Read `references/dispatch-rules.md` in full before composing any subagent prompt.** That file contains the complete scoped-write contract, tool allow/forbid lists, parent responsibilities, and failure handling. The bullets above are tripwires, not the contract — the contract must be embedded verbatim in every subagent prompt. |
| 131 | + |
| 132 | +**STOP. Read `assets/analysis-template.md` in full before composing any subagent prompt.** That file is the canonical seven-section schema every subagent fills. The schema must be embedded in the prompt; do not paraphrase it. |
| 133 | + |
| 134 | +Compose one `explorer` subagent prompt per slice. Every prompt MUST include: |
| 135 | +- The operator's original `--prompt` verbatim, prefixed by a short orientation line. |
| 136 | +- The slice's focused question and the primary sources to read. |
| 137 | +- The exact target path: `<path>/analysis/NN_analysis_<slug>.md` (absolute path). |
| 138 | +- `references/dispatch-rules.md` content embedded verbatim (copy-paste, do not paraphrase). |
| 139 | +- The seven-section schema from `assets/analysis-template.md`. |
| 140 | + |
| 141 | +Dispatch all subagents in the same `Agent` batch with `subagent_type: explorer` on every call. Wait for every subagent to return before continuing — a partial set is unacceptable. |
| 142 | + |
| 143 | +**Step 5: Verify outputs** |
| 144 | + |
| 145 | +Gist tripwires — the floor items that catch most failures: |
| 146 | + |
| 147 | +- Exactly `N` files at the expected `NN_analysis_<slug>.md` paths under `<path>/analysis/`. |
| 148 | +- All seven schema sections present in each file; no empty sections without a gap-note + Open Question. |
| 149 | +- At least one cited source per file sample-checked (Read for local paths, well-formedness for URLs). |
| 150 | + |
| 151 | +**STOP. Read `references/checklist.md` in full before declaring outputs verified.** That file is the seven-section output validation checklist (installation, inputs, scout, dispatch, files, schema, summary). Every item must pass; failing items trigger a re-dispatch of the offending slice. The three bullets above are tripwires, not the contract. |
| 152 | + |
| 153 | +If a section is empty, a file is missing, a cited path is fake, or the schema is incomplete, re-dispatch the offending subagent with the schema embedded and a request to fill the gap. The parent never authors the missing analysis content — the subagent owns the write. |
| 154 | + |
| 155 | +**Step 6: Synthesize `summary.md`** |
| 156 | + |
| 157 | +1. Read every `<path>/analysis/NN_analysis_<slug>.md` in full. |
| 158 | +2. Author `<path>/analysis/summary.md` with these sections: |
| 159 | + - **Research Question** — the operator's `--prompt`, verbatim. |
| 160 | + - **Slice Map** — table mapping each `NN – slug` to its slice question and one-line finding. |
| 161 | + - **Convergences** — patterns or risks that appear in two or more analyses, with cross-citations to the slice files. |
| 162 | + - **Divergences** — places where slices disagree or where one slice surfaces a finding the others miss. |
| 163 | + - **Risks & Open Questions** — consolidated, deduplicated list pulled from each analysis's Open Questions and Risks/Mismatches sections. |
| 164 | + - **Recommended Next Steps** — short, actionable list. Each step cites the slice file(s) that support it. |
| 165 | + - **Index** — bullet list of `<path>/analysis/NN_analysis_<slug>.md` paths so a future reader can drill in. |
| 166 | +3. `summary.md` is parent-authored. Do not dispatch a subagent for this step. |
| 167 | + |
| 168 | +## When Not To Use |
| 169 | + |
| 170 | +- **Single-file lookups** ("where is X defined?", "what does function Y return?"): use `Explore` or direct `Grep`/`Read`. This skill is overkill. |
| 171 | +- **Edits to existing code**: explorer is scoped-write — it can only create new analysis files, not modify anything else. |
| 172 | +- **Tightly scoped competitor / reference-repo research** in projects that already ship a more specialized variant (for example a project-local skill that mirrors a fixed competitor catalog). Use that variant when it exists; use this skill as the generic fallback. |
| 173 | + |
| 174 | +## Error Handling |
| 175 | + |
| 176 | +Operational tripwires only — the full failure taxonomy lives in `references/dispatch-rules.md` (Failure Handling) and `references/checklist.md`. |
| 177 | + |
| 178 | +- **Active-harness target missing and operator declines install:** abort the dispatch with a one-line message. Do not attempt to inline-define the subagent in the dispatch prompt. |
| 179 | +- **`--path` directory cannot be created:** stop and report the filesystem error. Do not fall back to the current working directory silently. |
| 180 | +- **`--agents` out of range:** ask the operator for an in-range value. Do not auto-clamp. |
| 181 | +- **Scout cannot find `--agents` non-overlapping slices:** reduce the dispatch count, inform the operator, and proceed with the smaller set. |
| 182 | +- **Contract violation, schema-incomplete analysis, fabricated evidence, or ambiguous-prompt refusal:** **STOP. Re-read `references/dispatch-rules.md` in full** before re-dispatching. The parent never authors the missing content; the subagent owns the write. |
| 183 | +- **Network/disk error during dispatch:** fail the round entirely. Do not produce a half-set of analyses. Re-dispatch after the error is resolved. |
0 commit comments