Deep analysis

From sequenzia/agent-alchemy · View interactive version

Deep analysis is an AI agent skill from the GitHub repository sequenzia/agent-alchemy. Deep exploration and synthesis workflow using agent teams with dynamic planning and hub-and-spoke coordination. Use when asked for "deep analysis", "deep understanding", "analyze codebase", "explore and analyze", or "investigate codebase".

How to use this skill

Skill file

Deep Analysis Workflow

Execute a structured exploration + synthesis workflow using agent teams with 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.

  1. Read settings file:
  1. Determine invocation mode:
  1. Resolve settings:
  1. Set behavioral flags:

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:

  1. Check if .agents/sessions/exploration-cache/manifest.md exists
  2. If found, read the manifest and verify:
  1. If cache is valid:
  1. If cache is invalid or absent: Set CACHE_HIT = false

Step 2: Interrupted Session Check

If ENABLE_CHECKPOINTING = true:

  1. Check if .agents/sessions/__da_live__/checkpoint.md exists
  2. If found, read the checkpoint to determine last_completed_phase
  3. Prompt the user to choose:
  1. If not found: proceed normally

Step 3: Initialize Session Directory

If ENABLE_CHECKPOINTING = true AND CACHE_HIT = false:

  1. Create .agents/sessions/__da_live__/ directory
  2. Write checkpoint.md:

```markdown

## Deep Analysis Session

```

  1. Write progress.md:

```markdown

## Deep Analysis Progress

### Phase Log

```


Phase 1: Reconnaissance & Planning

Goal: Perform codebase reconnaissance, generate dynamic focus areas, and compose a team plan.

  1. Determine analysis context:
  1. Rapid codebase reconnaissance:

Quickly map the codebase structure. This should take 1-2 minutes, not deep investigation.

Fallback: If reconnaissance fails (empty project, unusual structure, errors), use the static focus area templates from Step 3b.

  1. 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:

For feature-focused analysis, focus areas should track the feature's actual footprint:

```

Example:

Focus 1: "API routes and middleware in src/api/ and src/middleware/" (auth-related endpoints, request handling)

Focus 2: "React components in src/pages/profile/ and src/components/user/" (UI layer for user profiles)

Focus 3: "Data models and services in src/db/ and src/services/" (persistence and business logic)

```

For general analysis, focus areas should map to the codebase's actual structure:

```

Example:

Focus 1: "Next.js app layer in apps/web/src/" (pages, components, app router)

Focus 2: "Shared library in packages/core/src/" (utilities, types, shared logic)

Focus 3: "CLI and tooling in packages/cli/" (commands, configuration, build)

```

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

```

  1. Compose the team plan:

Assemble a structured plan document from the reconnaissance and focus area findings:

```markdown

## Team Plan: Deep Analysis

### Analysis Context

[context from Step 1]

### Reconnaissance Summary

### Focus Areas

#### Focus Area 1: [Label]

#### Focus Area 2: [Label]

[... repeated for each focus area]

### Agent Composition

| Role | Count | Purpose |

|------|-------|---------|

| Explorer | [N] | Independent focus area exploration |

| Synthesizer | 1 | Merge findings, deep investigation |

### Task Dependencies

```

  1. Checkpoint (if ENABLE_CHECKPOINTING = true):

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`

  1. Present the team plan to the user (output the plan from Phase 1 Step 4), then prompt the user to choose:
  1. If "Modify" (up to 3 cycles):
  1. If "Regenerate" (up to 2 cycles):
  1. Checkpoint (if ENABLE_CHECKPOINTING = true):

Phase 3: Team Assembly

Goal: Create the team, spawn agents, create tasks, and assign work using the approved plan.

  1. Create the team:
  1. Spawn teammates:

Spawn agents based on the approved plan:

  1. Create tasks:

Create a task for each item based on the approved plan's focus areas:

  1. Assign exploration tasks (with status guard):

For each exploration task, apply the following status-guarded assignment:

1. Check the task's current status and owner

2. Only assign if status is pending AND owner is empty

3. If already assigned or completed: log "Task [ID] already [status], skipping" and move on

4. Set the owner to the corresponding explorer

5. Send the explorer a message with the task details:

"Your exploration task [ID] is assigned. Focus area: [label]. Directories: [list]. Starting files: [list]. Search patterns: [list]. Begin exploration now."

Never re-assign a completed or in-progress task.

  1. Checkpoint (if ENABLE_CHECKPOINTING = true):

Phase 4: Focused Exploration

Goal: Workers explore their assigned areas independently.

Monitoring Loop

After assigning exploration tasks, monitor progress with status-aware tracking:

  1. When an explorer goes idle or sends a message, check their task status
  2. If task is completed: Record the explorer's findings. If ENABLE_CHECKPOINTING = true, write explorer-{N}-findings.md to .agents/sessions/__da_live__/ and update checkpoint.
  3. If task is in_progress: The explorer is still working — do not re-send the assignment
  4. If task is pending and owner is set: The explorer received the assignment but has not started yet — wait, do not re-send
  5. If task is pending and owner is empty: Assignment may have been lost — re-assign using the status guard from Phase 3 step 4

Never re-assign a completed or in-progress task. This is the primary duplicate prevention mechanism.

Update the progress display as explorers complete.


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:

  1. Verify all exploration tasks are completed
  2. Check that each worker produced a report with content (review the messages/reports received)
  3. If a worker failed completely (empty or error output):
  1. If all produced content: proceed immediately to Step 2

Step 2: Launch Synthesis

  1. Assign the synthesis task to the synthesizer
  2. Send the synthesizer a message with exploration context and recon findings:

"All exploration tasks are complete. Your synthesis task is now assigned.

Analysis context: [analysis context]

Codebase path: [PATH]

Recon findings from planning phase:

The workers are: [list of explorer names from the approved plan]. You can message them with follow-up questions if you find conflicts or gaps in their findings.

You have shell access for deep investigation — use it for git history analysis, dependency trees, static analysis, or any investigation that file reading and searching cannot handle.

Read the completed exploration tasks to access their reports, then synthesize into a unified analysis. Evaluate completeness before finalizing."

  1. Wait for the synthesizer to mark the synthesis task as completed
  1. Checkpoint (if ENABLE_CHECKPOINTING = true):

Phase 6: Completion + Cleanup

Goal: Collect results, present to user, and tear down the team.

  1. Collect synthesis output:
  1. Write exploration cache (if CACHE_TTL > 0):

```markdown

## Exploration Cache Manifest

```

  1. Present or return results:
  1. Shutdown teammates:

Send shutdown requests to all spawned teammates (iterate over the actual agents from the approved plan).

  1. Archive session and cleanup team:

Error Handling

Settings Check Failure

Planning Phase Failure

Approval Phase Failure

Partial Worker Failure

Synthesizer Failure

General Failures

If any phase fails:

  1. Explain what went wrong
  2. Ask the user how to proceed:

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 spawn and assign explorers whose findings files are missing. Add existing findings to synthesizer context. |

| Phase 5 | Load all explorer findings from session dir. Spawn a fresh synthesizer and launch synthesis with the persisted findings. |

| Phase 6 | Load synthesis.md from session dir. Proceed directly to present/return results and cleanup. |

Recovery procedure:

  1. Read checkpoint.md to determine last_completed_phase and session state (team_name, explorer_names, task_ids)
  2. Load any persisted artifacts from the session directory (team_plan, explorer findings, synthesis)
  3. Resume from Phase last_completed_phase + 1 using the loaded state
  4. For Phase 4 recovery: compare persisted explorer-{N}-findings.md files against expected explorer list to determine which explorers still need to run

Agent Coordination


Nested Agents

This skill uses the following nested agents:


Integration Notes

Sub-agent Capabilities

Code Explorer agents need:

Code Synthesizer agent needs:

Configurable Parameters

| Parameter | Default | Description |

|-----------|---------|-------------|

| direct-invocation-approval | true | Require plan approval when invoked directly |

| invocation-by-skill-approval | false | Require approval when loaded by another skill |

| cache-ttl-hours | 24 | Hours before exploration cache expires; 0 disables |

| enable-checkpointing | true | Write session checkpoints at phase boundaries |

| enable-progress-indicators | true | Display phase progress messages |

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.