File size: 21,040 Bytes
9e64e71 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 | <!-- handbook:ref cli opencode-ctx ralph run -->
<!-- handbook:ref cli opencode-ctx ralph start -->
<!-- handbook:ref cli opencode-ctx ralph spec -->
<!-- handbook:ref cli opencode-ctx ralph review -->
# OpenCode Workflow Handbook
Short, terminal-friendly map of the agentic workflow.
Assets discovered from: /Users/hjerp/.config/opencode
## Pipeline (What Comes Next)
## Delegation Brief (Required)
For any non-trivial work (anything you would normally put in a ticket/PRD), start with a short **Delegation Brief**.
This is the invariant "front page" that gets carried through discovery, delivery, and implementation so agents do not drift.
Minimum fields:
```text
Objective (what + why):
Deliverables (artifacts/capabilities):
In scope / Out of scope (non-goals):
Boundaries (authority + constraints):
Checkpoints (when to show work / ask):
Acceptance checks (how we know it's done):
```
How it glues into the existing workflow:
- `strategy` strengthens Objective/why (when the why is unclear or long-horizon).
- `discovery` turns Objective into validated scope + taste, and sharpens Acceptance checks.
- `delivery-spec` turns Deliverables/Boundaries into an engineering handoff.
- `design-doc` records decision rationale when the "how" has meaningful options.
- `autocode-implementation-planner` encodes the brief as **Core Intent (Immutable)** in the implementation spec, then uses the information barrier to generate independent verification.
**Note:** `strategy` is optional β use it when the "why" matters as much as the "what" (methodologies, frameworks, platforms). Most projects start at `discovery`.
```
[delegation brief] -> [strategy] -> discovery -> delivery-spec -> design-doc
| | | |
v v v v
vision validate scope+handoff decisions
(optional) +taste
architecture -> autocode-implementation-planner -> verification-planner -> execution loop
| | | |
v v v v
system map IMPLEMENTATION_SPEC.md VERIFICATION_SPEC.md build/review/verify
```
## When to Create Which Doc
| Complexity | Product Spec? | Design Doc? | Start With |
|------------|---------------|-------------|------------|
| **Simple** (CRUD, config) | Skip | Skip | `autocode-implementation-planner` |
| **Standard** (new feature) | Recommended | Optional | `discovery` skill β implementation planner |
| **Complex** (multi-system) | Required | Required | `discovery` β `delivery-spec` β design doc β implementation planner |
| **Exploratory** (unknown) | Skip | Skip | `prototype` skill first |
**Decision criteria:**
- Create **discovery** doc when stakeholders need to agree on scope
- Create **design-doc** when architecture decisions need to be recorded
- Skip both for tactical work that doesn't need alignment
## Where Artifacts Live
- vision/ = project philosophy (optional, for methodologies/frameworks) [explanation]
- docs/ = durable knowledge, organized by Diataxis type:
- docs/guides/ = how-to procedures [how-to]
- docs/design-docs/ = decision rationale [explanation]
- docs/discovery/ = problem validation + taste [explanation]
- docs/delivery-specs/ = engineering handoff [reference]
- docs/references/ = external docs for agents [reference]
- docs/exploration/ = ideas, scratchpad [exploration]
- docs/learnings/ = durable patterns [reference]
- docs/DOCS_TAXONOMY.md = where to put new docs
- specs/ = per-slice execution artifacts (FEATURES.json, impl specs, verification specs, CLARIFICATION_QUESTIONS.md (optional))
**Architecture lives in `docs/ARCHITECTURE.md`** β it's durable system knowledge, not a per-feature artifact.
## Architecture: One File, Multiple Tools
**Canonical location:** `docs/ARCHITECTURE.md`
All architecture tools output to the same file:
| Tool | Purpose |
|------|---------|
| `architecture` skill | Create NEW architecture (greenfield, redesign) |
| `codebase-onboarding` skill | Understand EXISTING architecture |
| `opencode-ctx docs architecture apply` | Refresh auto-managed snapshot |
| `/update-architecture-diagram` | Quick diagram refresh |
**Workflow:**
- Joining existing project β `codebase-onboarding` first
- Building new system β `architecture` skill
- Regular maintenance β `opencode-ctx docs architecture apply`
**Keep it fresh:**
- Human-curated sections: coarse (5-10 boxes, 2-4 key flows)
- Auto-managed snapshot: refresh with `opencode-ctx docs architecture apply`
- CI gate: `opencode-ctx docs architecture check`
## What To Run (Typical Flow)
- Start by writing (or asking the agent to draft) a Delegation Brief (required for significant work).
- To draft a Delegation Brief as a reusable artifact: use `delegation-brief`.
- If you are unsure what doc to write: use `triage`.
- To generate "what to build next" ideas from a codebase or product: use `ideation`.
- To capture project philosophy (rare): use `strategy` or create `vision/VISION.md` manually.
- To set direction for a longer horizon: use `strategy`.
- To validate and capture taste for a feature: use `discovery`.
- To hand off a concrete solution: use `delivery-spec`.
- To record architectural decisions: use `design-doc`.
- To map shared components across features: use `architecture`.
- To plan implementation with verification barrier: use `autocode-implementation-planner`.
- To inject baseline guardrails into `AGENTS.md`: `opencode-ctx guidelines apply --packs <lang>,testing,delivery-safety --file AGENTS.md`
**Vision vs Discovery:**
- Vision = enduring project philosophy (rare, for methodologies/frameworks)
- Discovery = feature-specific validation and taste capture (common)
| Use Vision When... | Use Discovery When... |
|--------------------|----------------------|
| The project IS a methodology or framework | You're validating a specific feature idea |
| Philosophy needs to persist across many features | The "why" is feature-specific |
| Multiple contributors need philosophical alignment | Taste capture is per-feature |
| The project will evolve over years | The project is < 6 months |
**Lightweight vision alternative:** Add a "Vision" section to README.md (2-3 paragraphs) instead of a full `vision/` directory.
Then build + ship with commands:
- /autocode-next-step (implement next spec step)
- /feature-demo F### (generate executable demo proving the feature works β auto-runs at loop end)
- /review-changes (auto-review)
- /commit-push-pr (commit, push, PR)
- /techdebt (tech debt scan)
For hands-free loops (optional):
- `opencode-ctx ralph start <spec>` (start server + browser + autonomous loop + cleanup)
- `opencode-ctx ralph run <spec>` (autonomous implement loop)
- `opencode-ctx ralph spec <spec>` (iterative spec refinement)
- `opencode-ctx ralph review` (review/fix bounded loop)
Common options: `-m MODEL` (alias: sonnet, opus, gpt-builder), `--max-iter N`
## Full Workflow (Complex Features)
```
0. Delegation Brief (required for significant work)
βββ docs/delegation-briefs/<feature>.md # delegation-brief skill
1. Discovery (taste capture + problem validation)
βββ docs/discovery/<feature>.md # discovery skill
βββ docs/discovery/<feature>.json # Machine-readable taste data
1b. Delivery spec (engineering handoff - optional for simple features)
βββ docs/delivery-specs/<feature>.md # delivery-spec skill
2. Design doc (architectural decisions)
βββ docs/design-docs/<feature>.md # design-doc skill (ADR-style)
3. Feature planning (multi-feature projects)
βββ specs/FEATURES.json # autocode-plan-features skill
4. Implementation planning (reads taste from step 1)
βββ specs/F001-IMPLEMENTATION_SPEC.md # autocode-implementation-planner skill
βββ specs/F001-VERIFICATION_SPEC.md # Auto-generated
5. Execution
βββ /autocode-next-step # Or: opencode-ctx ralph start <spec>
6. Knowledge extraction (automatic)
βββ docs/learnings/*.md # compound-engineer at finalization
```
**Taste flows through the pipeline:**
- `discovery` captures delights, frustrations, feeling
- `delivery-spec` (optional) translates to functional requirements
- `autocode-implementation-planner` reads taste JSON and uses as success criteria
- Verification checks implementation against captured taste
## Quick Workflow (Simple Features)
```bash
# Plan directly
skill({ name: "autocode-implementation-planner" })
# Execute
/autocode-next-step
# Or autonomous: opencode-ctx ralph start <spec>
# Review and ship
/review-changes
/commit-push-pr
```
## Linking Docs to Features (FEATURES.json)
When using `FEATURES.json`, link to related documentation:
```json
{
"id": "F001",
"name": "User Authentication",
"docs": {
"discovery_json": "docs/discovery/auth.json",
"discovery_md": "docs/discovery/auth.md",
"delivery_spec": "docs/delivery-specs/auth.md",
"design_doc": "docs/design-docs/auth-system.md"
},
"specs": {
"implementation": "specs/F001-IMPLEMENTATION_SPEC.md",
"verification": "specs/F001-VERIFICATION_SPEC.md"
}
}
```
The `autocode-implementation-planner` skill automatically checks each linked doc and uses it as context.
## AGENTS.md Convention
AGENTS.md is a **navigation map**, not an encyclopedia:
- ~60-80 lines
- Links to docs/ for details
- No inline learnings (those go in `docs/learnings/`)
- Injectable guidelines via `<!-- GUIDELINES-BEGIN/END -->`
```bash
# Apply or update language guidelines (idempotent)
opencode-ctx guidelines apply --packs python,testing,delivery-safety --file AGENTS.md
# Frontend projects
opencode-ctx guidelines apply --packs frontend,testing,delivery-safety --file AGENTS.md
# Preview without writing
opencode-ctx guidelines apply --packs python,testing,delivery-safety --file AGENTS.md --dry-run
```
Available packs: `python`, `testing`, `frontend`, `delivery-safety`
## Parallel Feature Development (Fan-Out / Fan-In)
When a project has multiple independent features to implement, use the
parallel workflow to create isolated clones for each, then merge back safely.
```bash
# Plan: AI-assisted analysis of which features can run in parallel
opencode-ctx parallel plan # analyze FEATURES.json + specs
opencode-ctx parallel plan --status ready # filter by status
opencode-ctx parallel plan --format json # machine-readable output
# Fan-out: create parallel clones for features
opencode-ctx parallel fan-out # reads FEATURES.json (planned/ready)
opencode-ctx parallel fan-out --features F001,F002 # explicit feature list
opencode-ctx parallel fan-out --from-local # clone from local (faster)
# Status: check all parallel clones
opencode-ctx parallel status
opencode-ctx parallel status --format json
# Work in each clone independently
cd ../repo-F001-auth-system
opencode-ctx ralph start specs/F001-IMPLEMENTATION_SPEC.md
# Fan-in: pre-merge conflict analysis
opencode-ctx parallel fan-in # trial merge against main
opencode-ctx parallel fan-in --format json
# Cleanup: remove clones after merging
opencode-ctx parallel cleanup F001
opencode-ctx parallel cleanup --all --force
```
**AI-Orchestrated Workflow (recommended):**
1. Use `/parallel-plan` command β analyzes implementation specs for file overlaps
and dependencies, recommends parallelizable batches, asks for confirmation
2. On confirmation, automatically calls `fan-out` for the batch
3. User runs `opencode-ctx ralph start <spec>` (or manual implementation) in each clone
4. Use `parallel-orchestrator` agent to monitor progress and coordinate merges
5. `fan-in` runs trial merges; orchestrator generates a merge playbook
6. User merges per-feature PRs in the suggested order
7. `cleanup` removes clones after merge
**Manual Workflow:**
1. `fan-out` creates sibling clones, each on a `feat/F###-slug` branch
2. User runs `opencode-ctx ralph start <spec>` (or manual implementation) in each clone
3. `fan-in` runs trial merges to detect conflicts and suggests merge order
4. User merges per-feature PRs in the suggested order
5. `cleanup` removes clones after merge
The `plan` command reads Section 2 (Change Manifest) from implementation specs to
extract file lists, computes pairwise file overlaps, and partitions features into
conflict-free batches. Fan-in respects feature dependencies from FEATURES.json
and orders clean merges before conflicting ones.
## Maintenance Commands
```bash
# Keep the architecture snapshot current
opencode-ctx docs architecture apply # refresh auto-managed snapshot
opencode-ctx docs architecture check # CI gate
# Keep the FEATURES.json schema current (multi-feature projects)
opencode-ctx features schema apply # creates specs/schemas/autocode-features-v1.schema.json
opencode-ctx features schema check # CI gate
opencode-ctx features schema apply --dry-run
# Validate docs structure
opencode-ctx docs validate
```
## Global Configuration
Additional commands, agents, and skills are in `/Users/hjerp/.config/opencode`:
| Path | Contents |
|------|----------|
| `AGENTS.md` | Global workflow policies |
| `commands/` | Slash commands (`/autocode-*`, `/review-*`, etc.) |
| `agents/` | Specialized agents (planner, reviewer, executor, etc.) |
| `skills/` | Product planning skills (strategy, discovery, delivery-spec, etc.) |
| `scripts/` | Automation scripts (legacy, deprecated β use `opencode-ctx ralph`) |
## Skills (Discovered)
| Skill | Description |
|---|---|
| `ai-adoption-engagement` | Run an end-to-end AI adoption consulting engagement: scoping, current-state maturity di... |
| `ai-strategy` | Plan, evaluate, and iteratively update AI implementation strategy for an organization o... |
| `architecture` | Create lightweight system architecture establishing shared understanding across feature... |
| `autocode-implementation-planner` | Research and plan software changes with structured verification handoff. Orchestrates s... |
| `autocode-plan-features` | Create machine-parseable feature lists for multi-feature projects. Generates FEATURES.j... |
| `causal-driver` | Build causal driver trees for any metric β separate accounting identities from causal h... |
| `checkpoint-protocol` | Structured human checkpoint protocol that minimizes evaluation overhead. Transforms 're... |
| `codebase-onboarding` | Rapidly understand an unfamiliar codebase by generating a structured overview with ASCI... |
| `communication` | Craft compelling communication for stakeholders. Covers storytelling frameworks, persua... |
| `core-web-vitals` | Optimize Core Web Vitals (LCP, INP, CLS) for better page experience and search ranking.... |
| `delegation-brief` | Create a short delegation contract (objective, deliverables, boundaries, checkpoints, a... |
| `delivery-spec` | Create delivery specs that define solutions for engineers and AI agents (Phase 3). Use... |
| `design-doc` | Record architectural decisions with rationale (ADR-style). Captures WHY decisions were... |
| `discovery` | Validate and prioritize product ideas using PR/FAQ, Opportunity Solution Trees, Taste C... |
| `execution` | Translate PRDs into user stories with acceptance criteria (Phase 4). Use when: (1) Engi... |
| `frameworks` | Reusable frameworks, checklists, and templates (a lightweight reference library). Use w... |
| `frontend-builder` | LLM-optimized frontend implementation guidance. Use when: (1) Starting new frontend pro... |
| `ideation` | Generate structured 'what to build next' candidates from a codebase or product using th... |
| `landscape-scan` | Competitive intelligence for company building and investment diligence. Maps the full c... |
| `ml-concept-eval` | Evaluate an ML/statistical technique against a specific business context: is it viable,... |
| `peer-collaboration` | Coordinate volunteer or peer teams without formal authority. Use when: (1) Working with... |
| `principal-ml-engineer` | Principal ML engineer playbook: design ML/LLM systems that are reliable, observable, ex... |
| `project-leadership` | Adaptive project leadership for competitions, research, coursework, ventures, and deliv... |
| `prototype` | Rapid exploratory prototyping to resolve ambiguity and validate ideas before committing... |
| `sector-primer` | Rapid industry understanding for consultants and investors. Produces a structured Indus... |
| `seo` | Optimize for search engine visibility and ranking. Use when asked to "improve SEO", "op... |
| `spec-staff-review` | Deliberate quality review of implementation specs by a staff engineer persona. Use for... |
| `strategic-thinker` | Guide users through strategic thinking using the Strategy Kernel framework. Facilitates... |
| `strategy` | Create product vision boards and outcome-based roadmaps (Phase 0-1). Use when: (1) Annu... |
| `team-lead` | Reference skill for team leadership principles: coaching, feedback, delegation. Use whe... |
| `triage` | Guide users through product planning workflow and select the right documentation (Triag... |
| `visual-artifacts` | Create professional visual artifacts: diagrams (Mermaid, Excalidraw) and presentations... |
| `web-performance` | Optimize web performance for faster loading and better user experience. Use when asked... |
| `web-security` | Apply modern web security best practices including CSP, HTTPS, XSS prevention, and depe... |
| `what-how-alignment` | System-level alignment between intent (what) and implementation (how). Analyzes complet... |
## Commands (Discovered)
| Command | Agent | Description |
|---|---|---|
| `/autocode-fix-from-review` | `executor` | Apply fixes from review report and run verification |
| `/autocode-fix-verification` | `verifier` | Fix features marked complete without proper verification evidence |
| `/autocode-next-step` | `executor` | Execute the next implementation step with verification |
| `/autocode-refine-spec` | `reviewer` | Iteratively refine an implementation spec before verification planning |
| `/autocode-verification-planner` | `verification-planner` | Generate verification criteria from sanitized spec |
| `/commit-push-pr` | `executor` | Commit, Push, and Create Pull Request |
| `/feature-demo` | `feature-demo` | Generate an executable demo document for a completed feature |
| `/full-web-audit` | `executor` | Comprehensive web quality audit (performance, accessibility, SEO, security) |
| `/parallel-plan` | `parallel-orchestrator` | Analyze FEATURES.json and plan parallelizable feature batches |
| `/review-changes` | `reviewer` | Review changes before commit or PR |
| `/review-frontend` | `frontend-reviewer` | Visual review of running frontend via Playwright MCP |
| `/techdebt` | `reviewer` | Analyze code for technical debt, duplications, and AI slop patterns |
| `/update-architecture-diagram` | `executor` | Refresh the System Diagram in ARCHITECTURE.md to match current codebase |
| `/update-model-routing` | `executor` | Refresh model routing recommendations with current pricing from models.dev |
| `/validate-spec` | `verifier` | Check if implementation matches spec; report discrepancies |
## Ralph CLI (Autonomous Loops)
| Command | Purpose |
|---------|---------|
| `opencode-ctx ralph start <spec>` | Start server + browser + run loop + cleanup (all-in-one) |
| `opencode-ctx ralph run <spec>` | Run implementation loop (attach to existing server with `-s`) |
| `opencode-ctx ralph spec <spec>` | Iterative spec refinement (default: 3 iterations) |
| `opencode-ctx ralph review` | Review + fix loop on current changes |
Common options: `-m MODEL` (aliases: sonnet, opus, gpt-builder), `--max-iter N`
## Scripts (Discovered β legacy, prefer `opencode-ctx ralph`)
| Script | Description |
|---|---|
| `cleanup-feature.sh` | Remove a parallel feature clone |
| `learnings.sh` | Query learnings (AGENTS.md or docs/LEARNINGS) |
| `parallel-feature.sh` | Create isolated clone for parallel feature development |
| `ralph-loop.sh` | βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ |
| `ralph-review-loop.sh` | βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ |
| `ralph-spec-loop.sh` | βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ |
| `update-model-routing.sh` | Fetch model pricing from models.dev and generate routing tables |
|