Core Responsibilities
- Iterative sprint planning: Produce batches of tasks you can fully specify right now
- Goal tracking: Maintain awareness of the full project scope across all iterations
- Worker feedback processing: Adapt plans based on handoff intelligence
- Scope management: Prevent file conflicts through locked-scope tracking
- Build health monitoring: Respond to reconciler sweep results
Implementation
Location:packages/orchestrator/src/planner.ts
Class Structure
Planning Loop
The root planner operates as a continuous loop that triggers replanning when conditions are met:- First iteration (
iteration === 0): Initial planning - Handoff threshold (
handoffsSinceLastPlan.length >= 3): Workers completed work - No active work (
activeTasks.size === 0): All workers idle but project incomplete
Message Building
The planner constructs different messages for initial vs. follow-up planning:Initial Message
Follow-up Message (with Delta Optimization)
Task Dispatch
Parsed tasks are dispatched with complexity-based routing:shouldDecompose):
- Task scope has ≥4 files (default
scopeThreshold) - Current depth < 3 (max decomposition depth)
Prompt Engineering
Location:prompts/root-planner.md
The root planner system prompt is structured in clear sections:
1. Philosophy and Conversation Model
2. Scratchpad System
3. Sprint Planning Strategy
4. Definition of Done
The prompt enforces staff-engineer-level acceptance criteria:| Bad | Good |
|---|---|
| ”Function works correctly. Tests pass." | "createUser() rejects duplicate emails with DuplicateEmailError. Tests cover: valid creation, duplicate email, missing required fields, invalid email format. tsc —noEmit exits 0.” |
5. Processing Handoffs
6. Concern Triage
7. Finalization Awareness
Output Format
The planner returns JSON with two fields:Examples from Prompt
Sprint 1 — Discovery & Foundation (5 tasks)
- Scratchpad explicitly lists all 18 features and marks them
[NOT STARTED] - Only emits 5 foundational tasks that have zero dependencies
- Explicitly states what CANNOT yet be planned and why
Sprint 3 — Informed Core Build-out (12 tasks)
- Scratchpad updated with [DONE] and [IN PROGRESS] status
- References actual patterns workers established (“Zod-validation-then-repository”)
- Creates task based on worker concern (“error responses inconsistent”)
Anti-Patterns (from Prompt)
The prompt explicitly warns against:- Upfront enumeration — “Trying to plan all 50 tasks in sprint 1. You don’t have enough information yet.”
- Mega-tasks — “‘Build the authentication system’ is not a task. ‘Implement JWT token generation in src/auth/token.ts’ is.”
- Premature fan-out — “Emitting 40 feature tasks when the foundation hasn’t landed yet.”
- Stale scratchpad — “Copy-pasting your previous scratchpad without updating it. Rewrite from scratch each time.”
- Ignoring the spec — “Generating tasks based on general knowledge instead of the project’s SPEC.md.”
- Lost goals — “Failing to track features from FEATURES.json across sprints.”
Configuration
Tracing and Monitoring
The planner emits structured trace spans:~/.longshot/traces/ for detailed execution analysis.
Best Practices
1. Use Read-Only Tools Extensively
2. Track All Goals in Scratchpad
Every SPEC.md feature and FEATURES.json entry must be tracked:3. Process Every Concern
Worker concerns must be triaged and tracked:4. Defer Confidently
Explicitly state what you’re deferring and why:Next Steps
- Subplanner Agent — Learn how complex tasks are recursively decomposed
- Worker Agent — Understand how individual tasks are implemented
- Reconciler Agent — See how build/test health is monitored