Polywave Architecture
May 11, 2026 · View on GitHub
System Overview
Polywave is a protocol for parallel agent coordination in software development. It decomposes feature work into independent units with disjoint file ownership, enabling concurrent implementation by multiple AI agents.
┌─────────────────────────────────────────────────────────────────┐
│ Orchestrator (synchronous, /polywave skill in Claude Code) │
│ • Launches Scout/Scaffold/Wave/Integration/Critic agents │
│ • Enforces invariants (I1-I6) │
│ • Manages wave lifecycle │
│ • Does NOT perform analysis or implementation itself │
└─────────────────────────────────────────────────────────────────┘
│
┌──────────────────┼──────────────────┐
▼ ▼ ▼
┌────────────────┐ ┌────────────────┐ ┌────────────────┐
│ Scout Agent │ │ Scaffold Agent │ │ Wave Agents │
│ (async) │ │ (async) │ │ (async) │
│ • Analyzes │ │ • Creates type │ │ • Implement │
│ codebase │ │ scaffolds │ │ features │
│ • Writes IMPL │ │ • Commits to │ │ • Run tests │
│ manifest │ │ main branch │ │ • Write to │
└────────────────┘ └────────────────┘ │ worktrees │
│ └────────────────┘
│ (after E16 validation) │ (parallel)
▼ ┌────┴────┐
┌────────────────┐ ▼ ▼
│ Critic Agent │ Agent A Agent B
│ (async, E37) │ (wave1) (wave1)
│ • Reviews IMPL │ │
│ briefs vs │ ▼ (after merge)
│ codebase │ ┌──────────────────┐
│ • Writes │ │ Integration Agent │
│ CriticResult │ │ (async, serial) │
│ • Never edits │ │ • Wires exports │
│ source files │ │ into callers │
└────────────────┘ │ • Runs on main │
└──────────────────┘
Agent Types
Polywave coordinates seven asynchronous agent roles plus the synchronous Orchestrator. Each type has mechanically enforced boundaries; a model prompted to violate its role is blocked before the tool executes.
| Agent Type | Subagent Tag | Role | Tool Access |
|---|---|---|---|
| Scout | scout | Analyzes codebase, produces IMPL manifest with file ownership and interface contracts | Read, Glob, Grep, Bash (no Write/Edit on source files) |
| Scaffold Agent | scaffold-agent | Materializes shared type stubs as committed source files before Wave 1 | Read, Write, Edit, Bash |
| Wave Agent | wave-agent | Implements assigned files in an isolated git worktree | Read, Write, Edit, Bash, Glob, Grep |
| Critic Agent | critic-agent | Reviews IMPL doc agent briefs against the actual codebase (E37); never modifies source files | Read, Glob, Grep, Bash |
| Integration Agent | integration-agent | Wires new exports into caller code post-merge; restricted to integration_connectors files. Also serves as hotfix agent for between-wave caller cascade fixes (E47). | Read, Write, Edit, Bash |
| Planner | planner | Decomposes a program into features, assigns tiers, produces PROGRAM manifest | Read, Glob, Grep, Bash |
Critic Agent (E37)
The Critic Agent is a pre-wave quality gate that runs after E16 IMPL validation and before the REVIEWED state. It is auto-triggered when wave 1 has 3 or more agents, or when file_ownership contains entries from 2 or more repos. It can be suppressed with --no-critic.
What it does:
- Reads the full IMPL manifest (all agent briefs, interface contracts, file ownership table)
- For each agent brief, reads every source file in that agent's ownership list
- Runs 10 verification checks against the actual codebase:
- Check 1 (
file_existence):action=modifyfiles must exist;action=newfiles must not - Check 2 (
symbol_accuracy): Function/type/method names in briefs must exist as stated - Check 3 (
pattern_accuracy): Implementation patterns described must match actual source patterns - Check 4 (
interface_consistency): Interface contracts must be syntactically valid and consistent with source types - Check 5 (
import_chains): All packages referenced in interface contracts must be importable - Check 6 (
side_effect_completeness): New exported symbols that require registration (CLI commands, HTTP routes, React components) must have their registration file infile_ownership - Check 7 (
complexity_balance): Warning if any agent owns >8 files or >40% of total IMPL files - Check 8 (
caller_exhaustiveness): All callers of changed symbols must be infile_ownership; usespolywave-tools check-callersto enumerate call sites - Check 9 (
i1_disjoint_ownership): Validatesfile_ownershiptable for I1 violations before worktrees are created - Check 10 (
result_code_semantics): Verifies correctresult.Result[T]usage in agent briefs
- Check 1 (
- Writes a structured
CriticResultto the IMPL doc'scritic_reportfield viapolywave-tools set-critic-review - Emits overall verdict:
PASS(all agents pass, or only warnings present) orISSUES(one or more agents have errors)
Enforcement: prepare-wave checks the critic verdict before creating worktrees. Verdict ISSUES blocks worktree creation with exit code 1. Verdict PASS (including warning-only) proceeds.
What it does NOT do: The Critic Agent never modifies source files or fixes briefs. It verifies accuracy only. Brief corrections are applied by the Orchestrator or human after reviewing the CriticResult summary; the critic is then re-run until verdict is PASS.
CLI note (Claude Code sessions): In CLI orchestration mode, the Orchestrator uses Agent(subagent_type=critic-agent, ...) rather than polywave-tools run-critic. The polywave-tools run-critic command is only valid for programmatic/API orchestration outside of a Claude Code session.
See E37 in protocol/execution-rules.md for full specification.
Core Components
1. IMPL Manifest
The single source of truth for feature decomposition. Written by Scout, consumed by all agents.
Location: docs/IMPL/IMPL-<feature-slug>.yaml
Key sections:
- File ownership table (I1: disjoint file ownership)
- Interface contracts (I2: contracts precede implementation)
- Wave structure (I3: sequential wave execution)
- Scaffolds (type/interface definitions)
- Quality gates (build, test, lint requirements)
Format: YAML manifest with typed structured sections (fenced blocks with type=impl-* attributes).
2. Git Worktree Isolation
Each Wave agent operates in an isolated git worktree with its own branch. No shared state, no merge conflicts during implementation.
Structure:
repo/
├── .git/ # Main git directory
├── main branch files...
└── .claude/
└── worktrees/
└── saw/
└── {slug}/
├── wave1-agent-A/ # Isolated worktree
│ ├── .git -> ... # Links to main .git
│ └── [files] # Agent A's workspace
└── wave1-agent-B/ # Isolated worktree
├── .git -> ...
└── [files] # Agent B's workspace
Benefits:
- Agents cannot interfere with each other's work
- Each agent has full git history and can commit independently
- Merge happens after all agents complete (I3: wave sequencing)
E43 Hook-Based Enforcement (v0.65.0+):
In Claude Code implementations, worktree isolation is enforced mechanically via six lifecycle hooks rather than relying on agent cooperation:
- SubagentStart: Environment injection — Sets
POLYWAVE_AGENT_WORKTREE,POLYWAVE_AGENT_ID,POLYWAVE_WAVE_NUMBER,POLYWAVE_IMPL_PATH,POLYWAVE_BRANCHwhen wave agents launch - SubagentStart: Worktree isolation validation (
validate_worktree_isolation) — Two-phase check: Phase 1 validates pwd+branch pattern; Phase 2 verifies exact branch via.polywave-agent-brief.mdfrontmatter - PreToolUse:Bash: CD auto-injection — Prepends
cd $POLYWAVE_AGENT_WORKTREE &&to every bash command, ensuring commands run in the correct working directory automatically - PreToolUse:Write/Edit: Path validation — Blocks relative paths and paths outside worktree boundaries at the tool boundary (exit 2), preventing the "Agent B leak" scenario where files are created in the main repo instead of the worktree
- SubagentStop: Compliance verification — Checks completion report exists and commits exist on branch, creating an audit trail for post-hoc violation analysis
- Stop: Orchestrator stop warning (
polywave_orchestrator_stop) — Warns when the session ends with an active IMPL in WAVE_PENDING or WAVE_EXECUTING state, or with active worktrees present. Non-blocking (exit 0 always); usesstop_hook_activeto prevent re-trigger loops.
This defense-in-depth approach makes isolation violations impossible at the tool boundary rather than merely detected after merge. Other implementations must provide equivalent enforcement at their tool invocation boundary or fall back to instruction-based isolation (Field 0 self-verification).
See E43 in protocol/execution-rules.md for full specification.
3. Protocol SDK (polywave-tools CLI)
The polywave-tools binary provides 75+ commands covering all protocol operations. Key commands include:
Batching commands (atomic multi-step workflows):
run-scout— Launch Scout, validate IMPL, auto-correct IDs, finalize gatesprepare-wave— Check deps, create worktrees, extract briefs, init journals, verify hooksfinalize-wave— Verify commits, scan stubs, run gates, merge, verify build, apply cascade hotfix (E47), cleanup; supports--dry-runflagfinalize-impl— Validate, populate gates, re-validaterun-wave— Fully automated wave execution
Worktree operations:
create-worktrees— Create isolated worktrees for a wavecleanup/cleanup-stale— Remove worktrees after mergeverify-isolation— Check agent is in correct worktree
IMPL management:
list-impls— Discover IMPL docsvalidate— E16 manifest validationextract-context— E23 per-agent context extractionupdate-status/set-impl-state— Agent and IMPL status trackingmark-complete/set-completion— E15 completion markeramend-impl/check-impl-conflicts— IMPL modification and conflict detection
Quality assurance:
scan-stubs/detect-scaffolds/validate-scaffolds— E20 stub and scaffold detectionrun-gates/tier-gate— E21 quality gate verificationcheck-conflicts/check-type-collisions— I1 ownership and type collision detectionrun-critic/set-critic-review/set-critic-verdict/run-review— Code review system
Program layer (multi-IMPL coordination):
create-program/list-programs/program-status— Program lifecycleprogram-execute/program-replan— Program execution and replanningfinalize-tier/mark-program-complete— Program completionfreeze-contracts/freeze-check— Contract managementcheck-program-conflicts/validate-program— Program validationimport-impls— Import existing IMPLs into a program
Agent and execution:
prepare-agent/update-agent-prompt— Agent setupinterview— E39 requirements gathering moderetry/build-retry-context/diagnose-build-failure— Failure recoveryresume-detect— Session resumption detectiondaemon— Continuous queue-processing daemon
Analysis and utilities:
analyze-deps/check-deps/detect-cascades— Dependency analysis (analyze-depsis a thin CLI wrapper overBuildGraph+ToOutput; theAnalyzeDepsGo function was deleted and replaced byBuildGraph(ctx, repoRoot, files)+ToOutput(graph))analyze-suitability— Codebase suitability assessmentassign-agent-ids/extract-commands— IMPL utilitiesjournal-init/journal-context— Journal managementmetrics/query/solve— Metrics, queries, and dependency solvingverify-hook-installed/verify-install— Installation verificationupdate-context— E18 project memory update
Run polywave-tools --help for the complete command list.
See protocol/execution-rules.md for detailed command specifications.
4. Interface Contracts
All cross-agent dependencies are defined as interface contracts in the IMPL manifest before parallel work begins.
Scaffold Agent creates:
- Type definitions (structs, interfaces, enums)
- Function signatures (no implementation, just signatures)
- Package documentation
Committed to main branch before Wave 1 launches. This enforces I2: interface contracts precede parallel implementation.
Interface freeze: When create-worktrees runs, contracts become immutable. Any interface change after this point requires recreating all worktrees.
5. Tool Journaling Subsystem
External observer pattern that preserves agent execution context across Claude Code's context window compaction events.
┌──────────────────────────────────────────────────────────────┐
│ Claude Code Session (wave1-agent-A) │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ Agent executes tools: │ │
│ │ • Read, Write, Edit, Bash │ │
│ │ • Context compaction erases history after ~45 min │ │
│ └──────────────────────────────────────────────────────────┘ │
│ │ │
│ │ logs to │
│ ▼ │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ .claude/sessions/1a2b3c4d.jsonl │ │
│ │ (Claude Code's internal session log) │ │
│ └──────────────────────────────────────────────────────────┘ │
└──────────────────────────────────────────────────────────────┘
│
│ tailed by (external observer)
▼
┌──────────────────────────────────────────────────────────────┐
│ JournalObserver (pkg/journal/) │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ .polywave-state/wave1/agent-A/ │ │
│ │ ├── cursor.json (read position) │ │
│ │ ├── index.jsonl (tool execution history) │ │
│ │ ├── context.md (generated on-demand summary) │ │
│ │ ├── recent.json (last 30 entries) │ │
│ │ └── tool-results/ (full tool outputs) │ │
│ └──────────────────────────────────────────────────────────┘ │
│ │
│ Methods: │
│ • Sync() - Update index from session log │
│ • GenerateContext() - Create markdown summary │
│ • Checkpoint(name) - Create named snapshot │
│ • Archive() - Compress after merge │
└──────────────────────────────────────────────────────────────┘
│
│ generates
▼
┌──────────────────────────────────────────────────────────────┐
│ Agent Prompt (before launch) │
│ │
│ ## Prior Work │
│ You have already modified: │
│ - pkg/journal/observer.go (created) │
│ │
│ Test results: │
│ - TestSync: PASS │
│ │
│ [Agent's full brief follows...] │
└──────────────────────────────────────────────────────────────┘
Why it exists: Long-running agents (45+ minutes) hit context compaction, losing memory of prior work. The journal system preserves execution history externally and injects it as context before agent launch.
Key properties:
- External observer (no Claude Code modifications)
- Automatic recovery (orchestrator loads journal before agent launch)
- Checkpoint system (named snapshots at milestones)
- Archive policy (compressed after merge, 30-day retention)
Components:
pkg/journal/observer.go— Core observer (tail session log, extract tools)pkg/journal/context.go— Context generator (analyze history, produce markdown)pkg/journal/checkpoint.go— Checkpoint manager (create/restore snapshots)pkg/journal/archive.go— Archive policy (compress, retain, cleanup)cmd/polywave-tools/debug_journal.go— CLI for debugging failed agents
Integration points:
prepare-wave/prepare-agent: JSON output includesjournal_context_availableandjournal_context_fileper agent, enabling the orchestrator to prepend journal context to agent promptslaunchAgent: Prepends journal context to the agent's launch prompt when available (restores working memory after compaction or interruption)- Periodic sync: 30-second goroutine runs during agent execution to keep journals current
- Wave agents: Receive prepended context in prompt (transparent, no agent changes needed)
See tool-journaling.md for full documentation.
Execution Flow
Phase 1: Scout
- User invokes
/polywave scout <feature-description>(optionally with--repo <path>to target a different repo than the session cwd) - Orchestrator launches Scout agent (async,
subagent_type: scout) - Scout analyzes codebase, identifies interfaces, writes IMPL manifest
- Orchestrator validates IMPL manifest (E16:
polywave-tools validate) - Orchestrator checks E37 trigger conditions: if wave 1 has 3+ agents or
file_ownershipspans 2+ repos, launches Critic Agent (async,subagent_type: critic-agent) - Critic reads every brief and owned file, runs 10 verification checks, writes
CriticResultto IMPL doc; execution blocks ifverdict: ISSUES - User reviews and approves decomposition; IMPL transitions to
REVIEWEDstate
Phase 2: Scaffold (if needed)
- If IMPL manifest has scaffolds with
Status: pending: - Orchestrator launches Scaffold Agent (async,
subagent_type: scaffold-agent) - Scaffold Agent creates type definitions and commits to main branch
- User reviews scaffold files
- Orchestrator verifies all scaffolds show
Status: committedbefore proceeding
Phase 3: Wave Execution Loop
For each wave (1..N):
-
Worktree creation:
polywave-tools create-worktreescreates isolated worktrees for each agent- Enforces interface freeze (I2: no contract changes after this point)
-
Journal initialization:
- Orchestrator creates
JournalObserverfor each agent - Syncs from existing session log (if resuming)
- Generates context summary
- Orchestrator creates
-
Agent launch:
- Orchestrator prepends journal context to agent prompt
- Launches all wave agents in parallel (
run_in_background: true) - Each agent works in its own worktree branch
-
Journal sync (periodic):
- Observer syncs every 30 seconds during execution
- No re-injection (context is static after launch)
-
Agent completion:
- Agents commit to worktree branches (I5: commit before reporting)
- Agents write completion reports to IMPL manifest
- Orchestrator reads completion reports (I4: IMPL doc is source of truth)
-
Quality gates:
polywave-tools scan-stubs(E20: detect unimplemented stubs)polywave-tools run-gates(E21: verify build/test/lint)
-
Merge verification:
polywave-tools verify-commits(all agents committed)polywave-tools merge-agents(merge to main with --no-ff)polywave-tools verify-build(post-merge build check)
-
Journal archiving:
observer.Archive()compresses journals- Removes worktrees via
polywave-tools cleanup
-
Next wave:
- If more waves remain: repeat from step 1
- If final wave:
polywave-tools mark-complete(E15)
Phase 4: Completion
- Orchestrator runs
polywave-tools mark-completeon IMPL manifest - Orchestrator runs
polywave-tools update-context(E18: update project memory) - IMPL doc is marked
state: COMPLETE - Feature is done
Invariants
The protocol enforces six core invariants:
I1: Disjoint File Ownership
- No two agents in the same wave own the same file
- Checked by
polywave-tools check-conflictsbefore worktree creation - Violated IMPL docs are rejected at validation time
I2: Interface Contracts Precede Implementation
- All cross-agent dependencies defined in IMPL manifest before Wave 1
- Scaffold Agent commits contracts to main branch
- Contracts freeze when worktrees are created (no changes allowed)
I3: Wave Sequencing
- Wave N+1 does not launch until Wave N merges successfully
- Post-merge verification must pass before proceeding
- Enforced by orchestrator (not bypassed even in
--automode)
I4: IMPL Doc is Single Source of Truth
- Completion reports written to IMPL doc, not chat
- Status updates via
polywave-tools update-status - Orchestrator reads IMPL doc to determine wave state
I5: Agents Commit Before Reporting
- Each agent commits to worktree branch before writing completion report
- Orchestrator verifies commits exist via
polywave-tools verify-commits - Missing commits flag protocol deviation
I6: Role Separation
- Orchestrator does not perform Scout/Scaffold/Wave work
- All analysis and implementation delegated to async agents
- Orchestrator only manages protocol state transitions
See protocol/invariants.md for full specification.
Error Handling
Engine Error Pattern (result.Result[T])
All engine functions that can partially succeed use the result.Result[T] generic wrapper from pkg/result. A Result[T] carries a Status (SUCCESS, PARTIAL, or FATAL), a typed Value, and an Errors slice of SAWError structs. Each SAWError has a structured Code (domain-prefixed constant from pkg/result/codes.go), a human-readable Message, and an optional Cause.
The .Code field on a Result holds the top-level status code (SUCCESS/PARTIAL/FATAL). Domain-specific error codes live in result.Errors[0].Code. Agent briefs that compare .Code against domain error constants (e.g., result.Code == V001) are flagged by Critic Check 10 (result_code_semantics).
Agent Failure Types (E19)
Agents report failure via failure_type field in completion report:
transient— Retry automatically (up to 2 times)fixable— Read agent notes, apply fix, relaunchneeds_replan— Re-engage Scout with agent findingsescalate— Surface to human immediatelytimeout— Agent approaching turn limit, stopped cleanly
Orchestrator response:
transient/fixable→ automatic retry in--automodeneeds_replan/escalate→ stop and surface to usertimeout→ read partial work, decide on manual completion or retry
Journal Recovery on Failure
When an agent fails mid-wave:
- Journal preserves full execution history (not lost to compaction)
- User inspects via
polywave-tools debug-journal wave<N>/agent-<ID> - User identifies root cause from tool history
- User reverts worktree to last good commit (if needed)
- Orchestrator re-launches agent with updated prompt
- Journal context includes prior attempt (agent learns from failure)
See tool-journaling.md for debugging workflow.
Directory Structure
repo/
├── .git/ # Main git directory
├── .claude/
│ ├── worktrees/ # Isolated worktrees (I3)
│ │ └── saw/
│ │ └── {slug}/
│ │ ├── wave1-agent-A/
│ │ └── wave1-agent-B/
│ └── sessions/ # Claude Code session logs (read by journal)
│ └── 1a2b3c4d.jsonl
├── .polywave-state/
│ ├── wave1/ # Tool execution history
│ │ ├── agent-A/
│ │ │ ├── cursor.json
│ │ │ ├── index.jsonl
│ │ │ ├── recent.json
│ │ │ └── tool-results/
│ │ └── agent-B/
│ └── archives/ # Compressed journals after merge
│ └── wave1-agent-A.tar.gz
├── docs/
│ ├── IMPL/ # IMPL manifests (I4)
│ │ └── IMPL-<feature>.yaml
│ └── CONTEXT.md # Project memory (E18)
├── polywave.config.json # Project config (model defaults, quality settings)
└── [source code]
Configuration
Project-local config at <repo>/polywave.config.json or global default at ~/.claude/polywave.config.json:
{
"repos": [],
"repo": {
"path": ""
},
"agent": {
"scout_model": "claude-sonnet-4-6",
"wave_model": "claude-sonnet-4-6",
"chat_model": "claude-sonnet-4-6",
"critic_model": "claude-sonnet-4-6",
"integration_model": "claude-sonnet-4-6",
"scaffold_model": "claude-sonnet-4-6",
"planner_model": "claude-sonnet-4-6"
},
"quality": {
"require_tests": false,
"require_lint": false,
"block_on_failure": false
},
"appearance": {
"theme": "dark"
}
}
Program Layer (Multi-IMPL Coordination)
The Program manifest system coordinates multiple related IMPLs that together deliver a larger initiative. A Program defines tiers of IMPLs with dependency relationships, enabling ordered execution across features.
Key concepts:
- Program manifest — YAML file defining tiers, IMPL references, and dependency graph
- Tiers — Ordered groups of IMPLs; Tier N+1 waits for Tier N completion
- Contract freezing — Cross-IMPL interfaces are frozen before dependent tiers execute
- Cascade detection — Identifies when changes in one IMPL affect others
Tier-gated execution (T-series rules): The PROGRAM manifest defines tiers with ordered execution. program-execute drives the tier loop: for each tier it runs Scouts in parallel (E31), tracks cross-IMPL progress (E32), runs the tier gate (E29), freezes cross-IMPL contracts (E30), and auto-advances in --auto mode (E33). Tier N+1 does not launch until tier N's gate verification passes (P3).
Tier batching commands:
prepare-tier— Cross-IMPL conflict check (P1+), create IMPL branches (E28B/P5), coordinate worktree creation, return tier readinessfinalize-tier— Tier gate verification (E29), contract freezing (E30), cross-IMPL merge coordination, return tier completion
Protocol spec: protocol/program-invariants.md, protocol/program-manifest.md
Commands: create-program, program-execute, program-replan, program-status, list-programs, prepare-tier, finalize-tier, tier-gate, freeze-contracts, freeze-check, check-program-conflicts, import-impls, mark-program-complete, validate-program
Protocol State Machine
IMPL manifests track lifecycle state via 12 states (including SCOUT_VALIDATING) with enforced transition guards. Invalid transitions are rejected by protocol.SetImplState().
INTERVIEWING ──> SCOUT_PENDING ──> REVIEWED ──> SCAFFOLD_PENDING ──> WAVE_PENDING
│ │
v v
NOT_SUITABLE WAVE_EXECUTING
│
v
WAVE_MERGING
│
v
WAVE_VERIFIED ──> COMPLETE
│
v
(next wave: WAVE_EXECUTING)
Any active state ──> BLOCKED (recoverable)
State descriptions:
| State | Meaning |
|---|---|
INTERVIEWING | Requirements-gathering session in progress (E39); transitions to SCOUT_PENDING when REQUIREMENTS.md is written |
SCOUT_PENDING | Scout agent is running or IMPL manifest is being written |
REVIEWED | IMPL manifest has passed E16 validation and E37 critic gate; awaiting wave execution approval |
SCAFFOLD_PENDING | Scaffold Agent is materializing shared types; transitions to WAVE_PENDING when all scaffolds are committed |
WAVE_PENDING | Ready to execute the current wave; worktrees not yet created |
WAVE_EXECUTING | Wave agents are running in their worktrees |
WAVE_MERGING | Agent branches are being merged to main |
WAVE_VERIFIED | Post-merge verification (build, tests, stubs) passed; either advances to next wave or to COMPLETE |
BLOCKED | Recoverable error state; requires human intervention before execution can resume |
COMPLETE | All waves merged and verified; IMPL archived |
NOT_SUITABLE | Scout determined the feature is not suitable for parallel execution |
The Program state machine wraps these with 9 program-level states: PROGRAM_PLANNING, PROGRAM_REVIEWED, PROGRAM_EXECUTING, PROGRAM_TIER_GATE, PROGRAM_BLOCKED, PROGRAM_REPLANNING, PROGRAM_COMPLETE, PROGRAM_NOT_SUITABLE, and PROGRAM_CONTRACTED.
Daemon, Queue, and Autonomy
The system supports continuous automated execution through a daemon loop:
- Daemon (
polywave-tools daemon) — Long-running process that pulls work from a queue and executes Scout/Wave workflows continuously - Queue — Ordered list of pending work items (features to scout, waves to execute)
- Autonomy settings — Controls how much the daemon can do without human approval (e.g., auto-approve scouts, auto-merge waves)
Interview Mode (E39)
A requirements-gathering pathway that launches an interactive interview session before Scout. The interview agent asks clarifying questions to refine a vague feature request into a well-specified Scout input.
Command: polywave-tools interview
Go Engine Package Structure
The Go engine (polywave-go) contains 40 packages under pkg/. Key packages beyond the core:
| Package | Purpose |
|---|---|
pkg/engine | High-level Scout, Wave, Scaffold, Chat operations |
pkg/protocol | YAML manifest parsing, validation, extraction |
pkg/agent | Agent execution runtime with tool system and 4 backends (Anthropic API, AWS Bedrock, OpenAI-compatible, Claude CLI) |
pkg/journal | External observer for tool execution history |
pkg/orchestrator | State machine, event publishing, wave management |
pkg/types | Shared type definitions used across all packages |
pkg/worktree | Git worktree creation and management |
pkg/suitability | Codebase suitability analysis and pre-implementation scanning |
pkg/analyzer | Multi-language dependency graph construction; key API: BuildGraph(ctx, repoRoot, files) → *DepGraph; CascadeCandidate is the unified cascade type (CascadeFile removed); DetectCascades, DetectWiring |
pkg/solver | Dependency solver for wave agent assignment (topological sort, Kahn's algorithm) |
pkg/observability | Event emission system (E40) |
pkg/queue | Work queue for daemon mode |
pkg/autonomy | Autonomy level settings and enforcement |
pkg/interview | E39 interview mode implementation |
pkg/resume | Session resumption detection and context recovery |
pkg/retry / pkg/retryctx | Failure retry logic and context building |
pkg/scaffold / pkg/scaffoldval | Scaffold creation and validation |
pkg/result | Unified result.Result[T] generic for consistent error handling; SUCCESS/PARTIAL/FATAL status codes; 280+ named error constants across 20 domains (V/W/B/G/A/N/O/P/T/S/C/K/I/D/E/X/Q/R/J/Z) |
pkg/collision | Type collision detection across agents (AST-based, E41) |
pkg/deps | Dependency conflict detection (lock files: go.mod, Cargo.lock, package-lock.json) |
pkg/builddiag | Build failure diagnosis |
pkg/codereview | LLM-powered diff review (run-review); scores diffs across quality dimensions; separate from the E37 critic agent (which is a prompt-based subagent, not an SDK package) |
pkg/hooks | Git hook installation and verification |
pkg/pipeline | Execution pipeline management |
pkg/format | Output formatting |
pkg/gatecache | Quality gate result caching |
internal/git | Low-level git command execution |
Web Application Architecture
The web application (polywave-web) provides an HTTP/SSE interface for the protocol engine.
Dependency: Imports polywave-go via a replace directive pointing to the local filesystem in go.mod.
Structure:
pkg/api/— HTTP route handlers (88 route registrations)pkg/service/— Service layer between API handlers and engine (config_service.go,impl_service.go,wave_service.go,scout_service.go,program_service.go,merge_service.go)web/— React frontend (TypeScript)cmd/saw/— Server binary entry pointweb/embed.go—//go:embeddirective embeds built frontend assets into the Go binary
Binaries produced:
polywave-goproducespolywave-tools(CLI toolkit, ~21MB)polywave-webproducespolywave(web server with embedded assets, ~24MB)
Build requirement: Web assets are embedded at compile time. Any frontend change requires cd web && npm run build followed by go build -o saw ./cmd/saw to produce an updated binary.
Key UI components: ProgramBoard, ProgramDependencyGraph, DaemonControl, QueuePanel, AutonomySettings, InterviewLauncher
API surface: REST endpoints under /api/ covering IMPLs, waves, programs, daemon control, queue management, autonomy settings, and interviews. Server-Sent Events (SSE) provide real-time progress updates during Polywave execution.
See Also
- Protocol Invariants — I1-I6 formal specification
- Protocol Execution Rules — E1-E47 orchestrator rules
- Tool Journaling — Compaction safety system
- Orchestrator Skill — /polywave command implementation