Deep Analysis Workflow
Execute a structured exploration + synthesis workflow using hub-and-spoke coordination. The lead performs rapid reconnaissance to generate dynamic focus areas, composes a team plan for review, workers explore independently, and a synthesizer merges findings with deep investigation.
This skill can be invoked standalone or loaded by other skills as a reusable building block. Approval behavior is configurable.
Settings Check
Goal: Determine whether the team plan requires user approval before execution.
Read settings:
- Check configuration for deep-analysis settings
- Look for a
deep-analysis section with nested settings:
direct-invocation-approval: Whether to require plan approval when invoked directly (default: true)
invocation-by-skill-approval: Whether to require approval when loaded by another skill (default: false)
Determine invocation mode:
- Direct invocation: The user invoked this skill directly, or it is running standalone
- Skill-invoked: Another skill (e.g., codebase-analysis, feature-dev, docs-manager) loaded and is executing this workflow
Resolve settings:
- If settings were found, use them as-is
- If the settings are missing, use defaults
- If the settings are malformed (unparseable), warn the user and use defaults
Set REQUIRE_APPROVAL:
- If direct invocation: use
direct-invocation-approval value (default: true)
- If skill-invoked: use
invocation-by-skill-approval value (default: false)
Parse session settings (also under the deep-analysis section):
cache-ttl-hours: Number of hours before exploration cache expires. Default: 24. Set to 0 to disable caching entirely.
enable-checkpointing: Whether to write session checkpoints at phase boundaries. Default: true.
enable-progress-indicators: Whether to display phase progress messages. Default: true.
Set behavioral flags:
CACHE_TTL = value of cache-ttl-hours (default: 24)
ENABLE_CHECKPOINTING = value of enable-checkpointing (default: true)
ENABLE_PROGRESS = value of enable-progress-indicators (default: true)
Phase 0: Session Setup
Goal: Check for cached exploration results, detect interrupted sessions, and initialize the session directory.
Skip this phase entirely if CACHE_TTL = 0 AND ENABLE_CHECKPOINTING = false.
Step 1: Exploration Cache Check
If CACHE_TTL > 0:
- Check if
.agents/sessions/exploration-cache/manifest.md exists
- If found, read the manifest and verify:
analysis_context matches the current analysis context (or is a superset)
codebase_path matches the current working directory
timestamp is within CACHE_TTL hours of now
- Config files referenced in
config_checksum haven't been modified since the cache was written (check mod-times of package.json, tsconfig.json, pyproject.toml, etc.)
- If cache is valid:
- Skill-invoked mode: Auto-accept the cache. Set
CACHE_HIT = true. Read cached synthesis.md and recon_summary.md. Skip to Phase 6 step 2 (present/return results).
- Direct invocation: Prompt the user to choose:
- Use cached results -- Set
CACHE_HIT = true, skip to Phase 6 step 2
- Refresh analysis -- Set
CACHE_HIT = false, proceed normally
- If cache is invalid or absent: Set
CACHE_HIT = false
Step 2: Interrupted Session Check
If ENABLE_CHECKPOINTING = true:
- Check if
.agents/sessions/__da_live__/checkpoint.md exists
- If found, read the checkpoint to determine
last_completed_phase
- Prompt the user to choose:
- Resume from Phase [N+1] -- Load checkpoint state, proceed from the interrupted phase (see Session Recovery in Error Handling)
- Start fresh -- Archive the interrupted session to
.agents/sessions/da-interrupted-{timestamp}/ and proceed normally
- If not found: proceed normally
Step 3: Initialize Session Directory
If ENABLE_CHECKPOINTING = true AND CACHE_HIT = false:
- Create
.agents/sessions/__da_live__/ directory
- Write
checkpoint.md:## Deep Analysis Session
- **analysis_context**: [context from arguments or caller]
- **codebase_path**: [current working directory]
- **started**: [ISO timestamp]
- **current_phase**: 0
- **status**: initialized
- Write
progress.md:## Deep Analysis Progress
- **Phase**: 0 of 6
- **Status**: Session initialized
### Phase Log
- [timestamp] Phase 0: Session initialized
Phase 1: Reconnaissance & Planning
Goal: Perform codebase reconnaissance, generate dynamic focus areas, and compose a team plan.
Determine analysis context:
- Accept the following inputs: an analysis context or focus area
- If no inputs and this skill was loaded by another skill, use the calling skill's context
- If no inputs and standalone invocation, set context to "general codebase understanding"
- Set
PATH = current working directory
- Inform the user: "Exploring codebase at:
PATH" with the analysis context
Rapid codebase reconnaissance:
Quickly map the codebase structure. This should take 1-2 minutes, not deep investigation.
- Directory structure: Search for top-level directories to understand the project layout
- Language and framework detection: Read config files (
package.json, tsconfig.json, pyproject.toml, Cargo.toml, go.mod, etc.) to identify primary language(s) and framework(s)
- File distribution: Search with patterns like
src/**/*.ts, **/*.py to gauge the size and shape of different areas
- Key documentation: Read
README.md, CLAUDE.md, or similar docs if they exist for project context
- For feature-focused analysis: Search file contents for feature-related terms (function names, component names, route paths) to find hotspot directories
- For general analysis: Identify the 3-5 largest or most architecturally significant directories
Fallback: If reconnaissance fails (empty project, unusual structure, errors), use the static focus area templates from Step 3b.
Generate dynamic focus areas:
Based on reconnaissance findings, create focus areas tailored to the actual codebase. Default to 3 focus areas, but adjust based on codebase size and complexity (2 for small projects, up to 4 for large ones).
a) Dynamic focus areas (default):
Each focus area should include:
- Label: Short description (e.g., "API layer in src/api/")
- Directories: Specific directories to explore
- Starting files: 2-3 key files to read first
- Search terms: Patterns to find related code
- Complexity estimate: Low/Medium/High based on file count and apparent structure
b) Static fallback focus areas (only if recon failed):
For feature-focused analysis:
Focus 1: Explore entry points and user-facing code related to the context
Focus 2: Explore data models, schemas, and storage related to the context
Focus 3: Explore utilities, helpers, and shared infrastructure
For general codebase understanding:
Focus 1: Explore application structure, entry points, and core logic
Focus 2: Explore configuration, infrastructure, and shared utilities
Focus 3: Explore shared utilities, patterns, and cross-cutting concerns
Compose the team plan:
Assemble a structured plan document from the reconnaissance and focus area findings:
## Team Plan: Deep Analysis
### Analysis Context
[context from Step 1]
### Reconnaissance Summary
- **Project:** [name/type]
- **Primary language/framework:** [detected]
- **Codebase size:** [file counts, key directories]
- **Key observations:** [2-3 bullets]
### Focus Areas
#### Focus Area 1: [Label]
- **Directories:** [list]
- **Starting files:** [2-3 files]
- **Search patterns:** [patterns]
- **Complexity:** [Low/Medium/High]
- **Assigned to:** explorer-1
#### Focus Area 2: [Label]
- **Directories:** [list]
- **Starting files:** [2-3 files]
- **Search patterns:** [patterns]
- **Complexity:** [Low/Medium/High]
- **Assigned to:** explorer-2
[... repeated for each focus area]
### Worker Composition
| Role | Count | Purpose |
|------|-------|---------|
| Explorer | [N] | Independent focus area exploration |
| Synthesizer | 1 | Merge findings, deep investigation |
### Task Dependencies
- Exploration Tasks 1-[N]: parallel (no dependencies)
- Synthesis Task: blocked by all exploration tasks
Checkpoint (if ENABLE_CHECKPOINTING = true):
- Update
.agents/sessions/__da_live__/checkpoint.md: set current_phase: 1
- Write
.agents/sessions/__da_live__/team_plan.md with the full team plan from Step 4
- Write
.agents/sessions/__da_live__/recon_summary.md with reconnaissance findings from Step 2
- Append to
progress.md: [timestamp] Phase 1: Reconnaissance complete -- [N] focus areas identified
Phase 2: Review & Approval
Goal: Present the team plan for user review and approval before allocating resources.
If REQUIRE_APPROVAL = false
Skip to Phase 3 with a brief note: "Auto-approving team plan (skill-invoked mode). Proceeding with [N] explorers and 1 synthesizer."
If REQUIRE_APPROVAL = true
Present the team plan to the user (output the plan from Phase 1 Step 4), then prompt the user to choose:
- Approve -- Proceed to Phase 3 as-is
- Modify -- User describes changes (adjust focus areas, add/remove explorers, change scope)
- Regenerate -- Re-run reconnaissance with user feedback
If "Modify" (up to 3 cycles):
- Ask what to change
- Apply modifications to the team plan (adjust focus areas, worker count, scope)
- Re-present the updated plan for approval
- If 3 modification cycles are exhausted, offer "Approve current plan" or "Abort analysis"
If "Regenerate" (up to 2 cycles):
- Ask for feedback/new direction
- Return to Phase 1 Step 2 with the user's feedback incorporated
- Re-compose and re-present the team plan
- If 2 regeneration cycles are exhausted, offer "Approve current plan" or "Abort analysis"
Checkpoint (if ENABLE_CHECKPOINTING = true):
- Update
.agents/sessions/__da_live__/checkpoint.md: set current_phase: 2, record approval_mode (approved/auto-approved)
- Append to
progress.md: [timestamp] Phase 2: Plan approved (mode: [approval_mode])
Phase 3: Team Assembly
Goal: Set up workers, create tasks, and assign work using the approved plan.
Prepare workers:
Based on the approved plan, prepare the following workers:
- N explorers (one per focus area): Refer to the code-explorer skill for exploration behavior. Each explorer investigates their assigned focus area independently.
- 1 synthesizer: Refer to the code-synthesizer skill for synthesis behavior. The synthesizer has shell access for git history, dependency analysis, and static analysis.
Create tasks:
For each focus area, create an exploration task with: subject ("Explore: [Focus area label]"), detailed exploration instructions including directories, starting files, search terms, and complexity estimate.
Create a synthesis task: "Synthesize and evaluate exploration findings" -- blocked by all exploration tasks.
Assign exploration tasks:
For each exploration task, delegate to the corresponding explorer worker with the task details: focus area label, directories, starting files, and search patterns.
Checkpoint (if ENABLE_CHECKPOINTING = true):
- Update
.agents/sessions/__da_live__/checkpoint.md: set current_phase: 3, record worker names, task assignments
- Append to
progress.md: [timestamp] Phase 3: Team assembled -- [N] explorers, 1 synthesizer
Phase 4: Focused Exploration
Goal: Workers explore their assigned areas independently.
Monitoring
After assigning exploration tasks, monitor progress:
- When an explorer completes, record their findings. If
ENABLE_CHECKPOINTING = true, write explorer-{N}-findings.md to .agents/sessions/__da_live__/ and update checkpoint.
- Workers explore independently -- no cross-worker communication (hub-and-spoke topology)
- Workers can respond to follow-up questions from the synthesizer
- Each worker marks its task as completed when done
- Wait for all exploration tasks to complete before proceeding to Phase 5
Phase 5: Evaluation and Synthesis
Goal: Verify exploration completeness, launch synthesis with deep investigation.
Step 1: Structural Completeness Check
This is a structural check, not a quality assessment:
- Verify all exploration tasks are completed
- Check that each worker produced a report with content
- If a worker failed completely (empty or error output):
- Create a follow-up exploration task targeting the gap
- Assign it to an idle worker
- Wait for the follow-up to complete
- If all produced content: proceed immediately to Step 2
Step 2: Launch Synthesis
Assign the synthesis task to the synthesizer worker
Provide the synthesizer with:
- Analysis context and codebase path
- Reconnaissance findings from Phase 1
- The list of explorer workers (for follow-up questions if needed)
- Instructions to read exploration task results, synthesize into a unified analysis, and evaluate completeness before finalizing
The synthesizer has shell access for deep investigation -- git history analysis, dependency trees, static analysis, or any investigation that basic file reading cannot handle
Wait for the synthesizer to complete
Checkpoint (if ENABLE_CHECKPOINTING = true):
- Update
.agents/sessions/__da_live__/checkpoint.md: set current_phase: 5
- Write
.agents/sessions/__da_live__/synthesis.md with the synthesis results
- Append to
progress.md: [timestamp] Phase 5: Synthesis complete
Phase 6: Completion + Cleanup
Goal: Collect results, present to user, and clean up.
Collect synthesis output:
- Read the synthesis results from the synthesizer
Write exploration cache (if CACHE_TTL > 0):
Present or return results:
- Standalone invocation: Present the synthesized analysis to the user. The results remain in conversation memory for follow-up questions.
- Loaded by another skill: The synthesis is complete. Control returns to the calling workflow -- do not present a standalone summary.
Shut down workers:
Signal all workers that analysis is complete and they can stop.
Archive session and cleanup:
- If
ENABLE_CHECKPOINTING = true: Move .agents/sessions/__da_live__/ to .agents/sessions/da-{timestamp}/
- Clean up any temporary team/task resources
Error Handling
Settings Check Failure
- If settings exist but are malformed or unparseable: warn the user ("Settings found but could not parse deep-analysis settings -- using defaults") and proceed with default approval values.
Planning Phase Failure
- If reconnaissance fails (errors, empty results, unusual structure): fall back to static focus area templates (Step 3b)
- If the codebase appears empty: inform the user and ask how to proceed
Approval Phase Failure
- If maximum modification cycles (3) or regeneration cycles (2) are reached without approval, prompt the user to choose:
- Approve current plan -- Proceed with the latest version of the plan
- Abort analysis -- Cancel the analysis entirely
Partial Worker Failure
- If one worker fails: create a follow-up task targeting the missed focus area, assign to an idle worker
- If two workers fail: attempt follow-ups, but if they also fail, instruct the synthesizer to work with partial results
- If all workers fail: inform the user and offer to retry or abort
Synthesizer Failure
- If the synthesizer fails: present the raw exploration results to the user directly
- Offer to retry synthesis or let the user work with partial results
General Failures
If any phase fails:
- Explain what went wrong
- Ask the user how to proceed:
- Retry the phase
- Continue with partial results
- Abort the analysis
Session Recovery
When resuming from an interrupted session (detected in Phase 0 Step 2), use the following per-phase strategy:
| Interrupted At |
Recovery Strategy |
| Phase 1 |
Restart from Phase 1 (reconnaissance is fast, ~1-2 min) |
| Phase 2 |
Load saved team_plan.md from session dir, re-present for approval |
| Phase 3 |
Load approved plan from checkpoint, restart team assembly |
| Phase 4 |
Read completed explorer-{N}-findings.md files from session dir. Only assign explorers whose findings files are missing. Add existing findings to synthesizer context. |
| Phase 5 |
Load all explorer findings from session dir. Launch a fresh synthesizer with the persisted findings. |
| Phase 6 |
Load synthesis.md from session dir. Proceed directly to present/return results and cleanup. |
Recovery procedure:
- Read
checkpoint.md to determine last_completed_phase and session state (worker names, task assignments)
- Load any persisted artifacts from the session directory (team_plan, explorer findings, synthesis)
- Resume from Phase
last_completed_phase + 1 using the loaded state
- For Phase 4 recovery: compare persisted
explorer-{N}-findings.md files against expected explorer list to determine which explorers still need to run
Coordination
- The lead (you) acts as the planner: performs recon, composes the team plan, handles approval, assigns work
- Workers explore independently -- no cross-worker communication (hub-and-spoke topology)
- The synthesizer can ask workers follow-up questions to resolve conflicts and fill gaps
- The synthesizer has shell access for deep investigation (git history, dependency trees, static analysis)
- Wait for task dependencies to resolve before proceeding
- Handle worker failures gracefully -- continue with partial results
- Worker count and focus area details come from the approved plan, not hardcoded values
Integration Notes
What this component does: Orchestrates a multi-phase deep analysis workflow: reconnaissance, dynamic planning, user approval, parallel exploration via independent workers, synthesis with deep investigation, caching, and session checkpointing/recovery.
Origin: Skill (orchestrator, keystone)
Capabilities needed:
- File reading, writing, and search (for reconnaissance, caching, checkpointing)
- Shell command execution (for the synthesizer's deep investigation: git history, dependency trees, static analysis)
- User interaction/prompting (for approval flow, cache decisions, session recovery)
- Task/worker delegation (for spawning explorer and synthesizer workers)
- Background task monitoring (for tracking explorer completion)
Adaptation guidance:
- The hub-and-spoke coordination pattern originally used platform-specific TeamCreate/TaskCreate/SendMessage/TaskUpdate APIs. Adapt to whatever task delegation and messaging mechanism the target harness provides.
- Explorer workers were originally spawned as Sonnet-tier agents; the synthesizer as Opus-tier. If the target harness supports model selection, preserve this tiering for cost efficiency.
- Session checkpointing writes to
.agents/sessions/__da_live__/. If the target harness has its own session/state management, adapt accordingly.
- The approval flow uses interactive prompts. If the target harness is non-interactive, default to auto-approval.
1---2name: deep-analysis-113description: Deep exploration and synthesis workflow with dynamic planning and hub-and-spoke coordination. Use for deep analysis, deep understanding, or codebase investigation.4---5
6# Deep Analysis Workflow
7
8Execute a structured exploration + synthesis workflow using hub-and-spoke coordination. The lead performs rapid reconnaissance to generate dynamic focus areas, composes a team plan for review, workers explore independently, and a synthesizer merges findings with deep investigation.
9
10This skill can be invoked standalone or loaded by other skills as a reusable building block. Approval behavior is configurable.
11
12## Settings Check
13
14**Goal:** Determine whether the team plan requires user approval before execution.
15
161. **Read settings:**
17 - Check configuration for deep-analysis settings
18 - Look for a `deep-analysis` section with nested settings:
19 - `direct-invocation-approval`: Whether to require plan approval when invoked directly (default: true)
20 - `invocation-by-skill-approval`: Whether to require approval when loaded by another skill (default: false)
21
222. **Determine invocation mode:**
23 - **Direct invocation:** The user invoked this skill directly, or it is running standalone
24 - **Skill-invoked:** Another skill (e.g., codebase-analysis, feature-dev, docs-manager) loaded and is executing this workflow
25
263. **Resolve settings:**
27 - If settings were found, use them as-is
28 - If the settings are missing, use defaults
29 - If the settings are malformed (unparseable), warn the user and use defaults
30
314. **Set `REQUIRE_APPROVAL`:**
32 - If direct invocation: use `direct-invocation-approval` value (default: `true`)
33 - If skill-invoked: use `invocation-by-skill-approval` value (default: `false`)
34
355. **Parse session settings** (also under the `deep-analysis` section):
36 - `cache-ttl-hours`: Number of hours before exploration cache expires. Default: `24`. Set to `0` to disable caching entirely.
37 - `enable-checkpointing`: Whether to write session checkpoints at phase boundaries. Default: `true`.
38 - `enable-progress-indicators`: Whether to display phase progress messages. Default: `true`.
39
406. **Set behavioral flags:**
41 - `CACHE_TTL` = value of `cache-ttl-hours` (default: `24`)
42 - `ENABLE_CHECKPOINTING` = value of `enable-checkpointing` (default: `true`)
43 - `ENABLE_PROGRESS` = value of `enable-progress-indicators` (default: `true`)
44
45---
46
47## Phase 0: Session Setup
48
49**Goal:** Check for cached exploration results, detect interrupted sessions, and initialize the session directory.
50
51> Skip this phase entirely if `CACHE_TTL = 0` AND `ENABLE_CHECKPOINTING = false`.
52
53### Step 1: Exploration Cache Check
54
55If `CACHE_TTL > 0`:
56
571. Check if `.agents/sessions/exploration-cache/manifest.md` exists
582. If found, read the manifest and verify:
59 - `analysis_context` matches the current analysis context (or is a superset)
60 - `codebase_path` matches the current working directory
61 - `timestamp` is within `CACHE_TTL` hours of now
62 - Config files referenced in `config_checksum` haven't been modified since the cache was written (check mod-times of `package.json`, `tsconfig.json`, `pyproject.toml`, etc.)
633. **If cache is valid:**
64 - **Skill-invoked mode:** Auto-accept the cache. Set `CACHE_HIT = true`. Read cached `synthesis.md` and `recon_summary.md`. Skip to Phase 6 step 2 (present/return results).
65 - **Direct invocation:** Prompt the user to choose:
66 - **Use cached results** -- Set `CACHE_HIT = true`, skip to Phase 6 step 2
67 - **Refresh analysis** -- Set `CACHE_HIT = false`, proceed normally
684. **If cache is invalid or absent:** Set `CACHE_HIT = false`
69
70### Step 2: Interrupted Session Check
71
72If `ENABLE_CHECKPOINTING = true`:
73
741. Check if `.agents/sessions/__da_live__/checkpoint.md` exists
752. If found, read the checkpoint to determine `last_completed_phase`
763. Prompt the user to choose:
77 - **Resume from Phase [N+1]** -- Load checkpoint state, proceed from the interrupted phase (see Session Recovery in Error Handling)
78 - **Start fresh** -- Archive the interrupted session to `.agents/sessions/da-interrupted-{timestamp}/` and proceed normally
794. If not found: proceed normally
80
81### Step 3: Initialize Session Directory
82
83If `ENABLE_CHECKPOINTING = true` AND `CACHE_HIT = false`:
84
851. Create `.agents/sessions/__da_live__/` directory
862. Write `checkpoint.md`:
87 ```markdown
88 ## Deep Analysis Session
89 - **analysis_context**: [context from arguments or caller]
90 - **codebase_path**: [current working directory]
91 - **started**: [ISO timestamp]
92 - **current_phase**: 0
93 - **status**: initialized
94 ```
953. Write `progress.md`:
96 ```markdown
97 ## Deep Analysis Progress
98 - **Phase**: 0 of 6
99 - **Status**: Session initialized
100
101 ### Phase Log
102 - [timestamp] Phase 0: Session initialized
103 ```
104
105---
106
107## Phase 1: Reconnaissance & Planning
108
109**Goal:** Perform codebase reconnaissance, generate dynamic focus areas, and compose a team plan.
110
1111. **Determine analysis context:**
112 - Accept the following inputs: an analysis context or focus area
113 - If no inputs and this skill was loaded by another skill, use the calling skill's context
114 - If no inputs and standalone invocation, set context to "general codebase understanding"
115 - Set `PATH = current working directory`
116 - Inform the user: "Exploring codebase at: `PATH`" with the analysis context
117
1182. **Rapid codebase reconnaissance:**
119 Quickly map the codebase structure. This should take 1-2 minutes, not deep investigation.
120
121 - **Directory structure:** Search for top-level directories to understand the project layout
122 - **Language and framework detection:** Read config files (`package.json`, `tsconfig.json`, `pyproject.toml`, `Cargo.toml`, `go.mod`, etc.) to identify primary language(s) and framework(s)
123 - **File distribution:** Search with patterns like `src/**/*.ts`, `**/*.py` to gauge the size and shape of different areas
124 - **Key documentation:** Read `README.md`, `CLAUDE.md`, or similar docs if they exist for project context
125 - **For feature-focused analysis:** Search file contents for feature-related terms (function names, component names, route paths) to find hotspot directories
126 - **For general analysis:** Identify the 3-5 largest or most architecturally significant directories
127
128 **Fallback:** If reconnaissance fails (empty project, unusual structure, errors), use the static focus area templates from Step 3b.
129
1303. **Generate dynamic focus areas:**
131
132 Based on reconnaissance findings, create focus areas tailored to the actual codebase. Default to 3 focus areas, but adjust based on codebase size and complexity (2 for small projects, up to 4 for large ones).
133
134 **a) Dynamic focus areas (default):**
135
136 Each focus area should include:
137 - **Label:** Short description (e.g., "API layer in src/api/")
138 - **Directories:** Specific directories to explore
139 - **Starting files:** 2-3 key files to read first
140 - **Search terms:** Patterns to find related code
141 - **Complexity estimate:** Low/Medium/High based on file count and apparent structure
142
143 **b) Static fallback focus areas** (only if recon failed):
144
145 For feature-focused analysis:
146 ```
147 Focus 1: Explore entry points and user-facing code related to the context
148 Focus 2: Explore data models, schemas, and storage related to the context
149 Focus 3: Explore utilities, helpers, and shared infrastructure
150 ```
151
152 For general codebase understanding:
153 ```
154 Focus 1: Explore application structure, entry points, and core logic
155 Focus 2: Explore configuration, infrastructure, and shared utilities
156 Focus 3: Explore shared utilities, patterns, and cross-cutting concerns
157 ```
158
1594. **Compose the team plan:**
160
161 Assemble a structured plan document from the reconnaissance and focus area findings:
162
163 ```markdown
164 ## Team Plan: Deep Analysis
165
166 ### Analysis Context
167 [context from Step 1]
168
169 ### Reconnaissance Summary
170 - **Project:** [name/type]
171 - **Primary language/framework:** [detected]
172 - **Codebase size:** [file counts, key directories]
173 - **Key observations:** [2-3 bullets]
174
175 ### Focus Areas
176
177 #### Focus Area 1: [Label]
178 - **Directories:** [list]
179 - **Starting files:** [2-3 files]
180 - **Search patterns:** [patterns]
181 - **Complexity:** [Low/Medium/High]
182 - **Assigned to:** explorer-1
183
184 #### Focus Area 2: [Label]
185 - **Directories:** [list]
186 - **Starting files:** [2-3 files]
187 - **Search patterns:** [patterns]
188 - **Complexity:** [Low/Medium/High]
189 - **Assigned to:** explorer-2
190
191 [... repeated for each focus area]
192
193 ### Worker Composition
194 | Role | Count | Purpose |
195 |------|-------|---------|
196 | Explorer | [N] | Independent focus area exploration |
197 | Synthesizer | 1 | Merge findings, deep investigation |
198
199 ### Task Dependencies
200 - Exploration Tasks 1-[N]: parallel (no dependencies)
201 - Synthesis Task: blocked by all exploration tasks
202 ```
203
2045. **Checkpoint** (if `ENABLE_CHECKPOINTING = true`):
205 - Update `.agents/sessions/__da_live__/checkpoint.md`: set `current_phase: 1`
206 - Write `.agents/sessions/__da_live__/team_plan.md` with the full team plan from Step 4
207 - Write `.agents/sessions/__da_live__/recon_summary.md` with reconnaissance findings from Step 2
208 - Append to `progress.md`: `[timestamp] Phase 1: Reconnaissance complete -- [N] focus areas identified`
209
210---
211
212## Phase 2: Review & Approval
213
214**Goal:** Present the team plan for user review and approval before allocating resources.
215
216### If `REQUIRE_APPROVAL = false`
217
218Skip to Phase 3 with a brief note: "Auto-approving team plan (skill-invoked mode). Proceeding with [N] explorers and 1 synthesizer."
219
220### If `REQUIRE_APPROVAL = true`
221
2221. **Present the team plan** to the user (output the plan from Phase 1 Step 4), then prompt the user to choose:
223 - **Approve** -- Proceed to Phase 3 as-is
224 - **Modify** -- User describes changes (adjust focus areas, add/remove explorers, change scope)
225 - **Regenerate** -- Re-run reconnaissance with user feedback
226
2272. **If "Modify"** (up to 3 cycles):
228 - Ask what to change
229 - Apply modifications to the team plan (adjust focus areas, worker count, scope)
230 - Re-present the updated plan for approval
231 - If 3 modification cycles are exhausted, offer "Approve current plan" or "Abort analysis"
232
2333. **If "Regenerate"** (up to 2 cycles):
234 - Ask for feedback/new direction
235 - Return to Phase 1 Step 2 with the user's feedback incorporated
236 - Re-compose and re-present the team plan
237 - If 2 regeneration cycles are exhausted, offer "Approve current plan" or "Abort analysis"
238
2394. **Checkpoint** (if `ENABLE_CHECKPOINTING = true`):
240 - Update `.agents/sessions/__da_live__/checkpoint.md`: set `current_phase: 2`, record `approval_mode` (approved/auto-approved)
241 - Append to `progress.md`: `[timestamp] Phase 2: Plan approved (mode: [approval_mode])`
242
243---
244
245## Phase 3: Team Assembly
246
247**Goal:** Set up workers, create tasks, and assign work using the approved plan.
248
2491. **Prepare workers:**
250 Based on the approved plan, prepare the following workers:
251
252 - **N explorers** (one per focus area): Refer to the **code-explorer** skill for exploration behavior. Each explorer investigates their assigned focus area independently.
253 - **1 synthesizer**: Refer to the **code-synthesizer** skill for synthesis behavior. The synthesizer has shell access for git history, dependency analysis, and static analysis.
254
2552. **Create tasks:**
256 For each focus area, create an exploration task with: subject ("Explore: [Focus area label]"), detailed exploration instructions including directories, starting files, search terms, and complexity estimate.
257
258 Create a synthesis task: "Synthesize and evaluate exploration findings" -- blocked by all exploration tasks.
259
2603. **Assign exploration tasks:**
261 For each exploration task, delegate to the corresponding explorer worker with the task details: focus area label, directories, starting files, and search patterns.
262
2634. **Checkpoint** (if `ENABLE_CHECKPOINTING = true`):
264 - Update `.agents/sessions/__da_live__/checkpoint.md`: set `current_phase: 3`, record worker names, task assignments
265 - Append to `progress.md`: `[timestamp] Phase 3: Team assembled -- [N] explorers, 1 synthesizer`
266
267---
268
269## Phase 4: Focused Exploration
270
271**Goal:** Workers explore their assigned areas independently.
272
273### Monitoring
274
275After assigning exploration tasks, monitor progress:
276
2771. When an explorer completes, record their findings. If `ENABLE_CHECKPOINTING = true`, write `explorer-{N}-findings.md` to `.agents/sessions/__da_live__/` and update checkpoint.
2782. Workers explore independently -- no cross-worker communication (hub-and-spoke topology)
2793. Workers can respond to follow-up questions from the synthesizer
2804. Each worker marks its task as completed when done
2815. **Wait for all exploration tasks to complete** before proceeding to Phase 5
282
283---
284
285## Phase 5: Evaluation and Synthesis
286
287**Goal:** Verify exploration completeness, launch synthesis with deep investigation.
288
289### Step 1: Structural Completeness Check
290
291This is a structural check, not a quality assessment:
292
2931. Verify all exploration tasks are completed
2942. Check that each worker produced a report with content
2953. **If a worker failed completely** (empty or error output):
296 - Create a follow-up exploration task targeting the gap
297 - Assign it to an idle worker
298 - Wait for the follow-up to complete
2994. **If all produced content**: proceed immediately to Step 2
300
301### Step 2: Launch Synthesis
302
3031. Assign the synthesis task to the synthesizer worker
3042. Provide the synthesizer with:
305 - Analysis context and codebase path
306 - Reconnaissance findings from Phase 1
307 - The list of explorer workers (for follow-up questions if needed)
308 - Instructions to read exploration task results, synthesize into a unified analysis, and evaluate completeness before finalizing
3093. The synthesizer has shell access for deep investigation -- git history analysis, dependency trees, static analysis, or any investigation that basic file reading cannot handle
3104. Wait for the synthesizer to complete
311
3125. **Checkpoint** (if `ENABLE_CHECKPOINTING = true`):
313 - Update `.agents/sessions/__da_live__/checkpoint.md`: set `current_phase: 5`
314 - Write `.agents/sessions/__da_live__/synthesis.md` with the synthesis results
315 - Append to `progress.md`: `[timestamp] Phase 5: Synthesis complete`
316
317---
318
319## Phase 6: Completion + Cleanup
320
321**Goal:** Collect results, present to user, and clean up.
322
3231. **Collect synthesis output:**
324 - Read the synthesis results from the synthesizer
325
3262. **Write exploration cache** (if `CACHE_TTL > 0`):
327 - Create `.agents/sessions/exploration-cache/` directory (overwrite if exists)
328 - Write `manifest.md`:
329 ```markdown
330 ## Exploration Cache Manifest
331 - **analysis_context**: [the analysis context used]
332 - **codebase_path**: [current working directory]
333 - **timestamp**: [ISO timestamp]
334 - **config_checksum**: [comma-separated list of config files and their mod-times]
335 - **ttl_hours**: [CACHE_TTL value]
336 - **explorer_count**: [N]
337 ```
338 - Write `synthesis.md` with the full synthesis output
339 - Write `recon_summary.md` with the Phase 1 reconnaissance findings
340 - Write `explorer-{N}-findings.md` for each explorer's findings (if not already persisted from Phase 4 checkpoints)
341
3423. **Present or return results:**
343 - **Standalone invocation:** Present the synthesized analysis to the user. The results remain in conversation memory for follow-up questions.
344 - **Loaded by another skill:** The synthesis is complete. Control returns to the calling workflow -- do not present a standalone summary.
345
3464. **Shut down workers:**
347 Signal all workers that analysis is complete and they can stop.
348
3495. **Archive session and cleanup:**
350 - If `ENABLE_CHECKPOINTING = true`: Move `.agents/sessions/__da_live__/` to `.agents/sessions/da-{timestamp}/`
351 - Clean up any temporary team/task resources
352
353---
354
355## Error Handling
356
357### Settings Check Failure
358- If settings exist but are malformed or unparseable: warn the user ("Settings found but could not parse deep-analysis settings -- using defaults") and proceed with default approval values.
359
360### Planning Phase Failure
361- If reconnaissance fails (errors, empty results, unusual structure): fall back to static focus area templates (Step 3b)
362- If the codebase appears empty: inform the user and ask how to proceed
363
364### Approval Phase Failure
365- If maximum modification cycles (3) or regeneration cycles (2) are reached without approval, prompt the user to choose:
366 - **Approve current plan** -- Proceed with the latest version of the plan
367 - **Abort analysis** -- Cancel the analysis entirely
368
369### Partial Worker Failure
370- If one worker fails: create a follow-up task targeting the missed focus area, assign to an idle worker
371- If two workers fail: attempt follow-ups, but if they also fail, instruct the synthesizer to work with partial results
372- If all workers fail: inform the user and offer to retry or abort
373
374### Synthesizer Failure
375- If the synthesizer fails: present the raw exploration results to the user directly
376- Offer to retry synthesis or let the user work with partial results
377
378### General Failures
379If any phase fails:
3801. Explain what went wrong
3812. Ask the user how to proceed:
382 - Retry the phase
383 - Continue with partial results
384 - Abort the analysis
385
386### Session Recovery
387
388When resuming from an interrupted session (detected in Phase 0 Step 2), use the following per-phase strategy:
389
390| Interrupted At | Recovery Strategy |
391|----------------|-------------------|
392| **Phase 1** | Restart from Phase 1 (reconnaissance is fast, ~1-2 min) |
393| **Phase 2** | Load saved `team_plan.md` from session dir, re-present for approval |
394| **Phase 3** | Load approved plan from checkpoint, restart team assembly |
395| **Phase 4** | Read completed `explorer-{N}-findings.md` files from session dir. Only assign explorers whose findings files are missing. Add existing findings to synthesizer context. |
396| **Phase 5** | Load all explorer findings from session dir. Launch a fresh synthesizer with the persisted findings. |
397| **Phase 6** | Load `synthesis.md` from session dir. Proceed directly to present/return results and cleanup. |
398
399**Recovery procedure:**
4001. Read `checkpoint.md` to determine `last_completed_phase` and session state (worker names, task assignments)
4012. Load any persisted artifacts from the session directory (team_plan, explorer findings, synthesis)
4023. Resume from Phase `last_completed_phase + 1` using the loaded state
4034. For Phase 4 recovery: compare persisted `explorer-{N}-findings.md` files against expected explorer list to determine which explorers still need to run
404
405---
406
407## Coordination
408
409- The lead (you) acts as the planner: performs recon, composes the team plan, handles approval, assigns work
410- Workers explore independently -- no cross-worker communication (hub-and-spoke topology)
411- The synthesizer can ask workers follow-up questions to resolve conflicts and fill gaps
412- The synthesizer has shell access for deep investigation (git history, dependency trees, static analysis)
413- Wait for task dependencies to resolve before proceeding
414- Handle worker failures gracefully -- continue with partial results
415- Worker count and focus area details come from the approved plan, not hardcoded values
416
417## Integration Notes
418
419**What this component does:** Orchestrates a multi-phase deep analysis workflow: reconnaissance, dynamic planning, user approval, parallel exploration via independent workers, synthesis with deep investigation, caching, and session checkpointing/recovery.
420
421**Origin:** Skill (orchestrator, keystone)
422
423**Capabilities needed:**
424- File reading, writing, and search (for reconnaissance, caching, checkpointing)
425- Shell command execution (for the synthesizer's deep investigation: git history, dependency trees, static analysis)
426- User interaction/prompting (for approval flow, cache decisions, session recovery)
427- Task/worker delegation (for spawning explorer and synthesizer workers)
428- Background task monitoring (for tracking explorer completion)
429
430**Adaptation guidance:**
431- The hub-and-spoke coordination pattern originally used platform-specific TeamCreate/TaskCreate/SendMessage/TaskUpdate APIs. Adapt to whatever task delegation and messaging mechanism the target harness provides.
432- Explorer workers were originally spawned as Sonnet-tier agents; the synthesizer as Opus-tier. If the target harness supports model selection, preserve this tiering for cost efficiency.
433- Session checkpointing writes to `.agents/sessions/__da_live__/`. If the target harness has its own session/state management, adapt accordingly.
434- The approval flow uses interactive prompts. If the target harness is non-interactive, default to auto-approval.