@comfanion/workflow 4.36.64 → 4.36.66

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comfanion/workflow",
3
- "version": "4.36.64",
3
+ "version": "4.36.66",
4
4
  "description": "Initialize OpenCode Workflow system for AI-assisted development with semantic code search",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,6 +1,6 @@
1
1
  {
2
- "version": "4.36.64",
3
- "buildDate": "2026-01-26T02:48:11.947Z",
2
+ "version": "4.36.66",
3
+ "buildDate": "2026-01-26T20:05:21.512Z",
4
4
  "files": [
5
5
  "config.yaml",
6
6
  "FLOW.yaml",
@@ -2,7 +2,7 @@
2
2
  # This file defines the complete workflow pipeline for AI-assisted development
3
3
 
4
4
  name: documentation-workflow
5
- version: "3.0"
5
+ version: "3.1"
6
6
  description: |
7
7
  End-to-end workflow from research to implementation and review.
8
8
 
@@ -12,6 +12,11 @@ description: |
12
12
  - Skills: Knowledge (HOW to do things)
13
13
 
14
14
  Config: .opencode/config.yaml
15
+
16
+ Project Size Classification:
17
+ - Defined in PRD (first section, mandatory)
18
+ - Agents read PRD to understand project size
19
+ - Size determines depth of all artifacts (PRD, Architecture, Epics, Stories)
15
20
 
16
21
  # =============================================================================
17
22
  # CONFIGURATION
@@ -28,7 +28,7 @@ tools:
28
28
  permission:
29
29
  edit: allow # Can write documentation
30
30
  bash:
31
- "*": ask
31
+ "*": allow
32
32
  "ls *": allow
33
33
  "cat *": allow
34
34
  "tree *": allow
@@ -4,9 +4,8 @@ mode: all # Can be primary agent or invoked via @dev
4
4
  temperature: 0.2
5
5
 
6
6
  model: anthropic/claude-opus-4-5 # Strong
7
- #model: z.ai/glm-4.7 # Better for orchestration as for me but slow (can broke)
8
- #model: openai/gpt-5.2-codex
9
- #model: anthropic/claude-opus-4-5
7
+ #model: z.ai/glm-4.7 # Can break
8
+ #model: openai/gpt-5.2-codex
10
9
 
11
10
  # Tools - FULL ACCESS for implementation
12
11
  tools:
@@ -232,7 +231,7 @@ permission:
232
231
  **What I Don't Do:**
233
232
  - Define product scope (→ @pm)
234
233
  - Make architecture decisions (→ @architect)
235
- - Implement without a story
234
+ - Implement without a story-зж
236
235
  - Skip tests or lie about test status
237
236
 
238
237
  **Red-Green-Refactor:** 🔴 Write failing test → 🟢 Minimal code to pass → 🔵 Refactor
@@ -129,11 +129,21 @@ permission:
129
129
  </principles>
130
130
  </persona>
131
131
 
132
- <sizing-guidelines>
133
- <epic>1-2 weeks of work, 3-8 stories</epic>
134
- <story>1-3 days of work, clear AC</story>
135
- <rule>If too big: Split it. If too small: Merge it.</rule>
136
- </sizing-guidelines>
132
+ <project-size-awareness critical="MANDATORY">
133
+ <instruction>BEFORE starting ANY work (PRD, epics, stories):</instruction>
134
+
135
+ <step n="1">If PRD exists: Read "Project Classification" section (first section)</step>
136
+ <step n="2">If no PRD: Load skill `prd-writing` to understand size classification</step>
137
+ <step n="3">Adapt your approach based on size</step>
138
+
139
+ <key-principle>
140
+ TOY/SMALL → Flat structure, no modules
141
+ MEDIUM+ → Break into Modules/Domains, create Unit docs
142
+
143
+ Don't over-engineer small projects!
144
+ Don't under-structure large projects!
145
+ </key-principle>
146
+ </project-size-awareness>
137
147
 
138
148
  <methodologies>
139
149
  <method name="Problem Framing">What's the REAL problem? Who experiences it? Why does it matter?</method>
@@ -88,13 +88,7 @@ permission:
88
88
  <action>search() in docs for architecture requirements</action>
89
89
  </phase>
90
90
 
91
- <phase name="2. Run Tests & Lint">
92
- <action>Run test suite: go test / npm test / pytest / cargo test</action>
93
- <action>Run linter: golangci-lint / eslint / ruff / cargo clippy</action>
94
- <action>If failures → include in review report as HIGH priority</action>
95
- </phase>
96
-
97
- <phase name="3. Security First">
91
+ <phase name="2. Security Analysis">
98
92
  <action>Check for hardcoded secrets</action>
99
93
  <action>Verify input validation on all user inputs</action>
100
94
  <action>Check SQL injection, XSS vulnerabilities</action>
@@ -102,20 +96,26 @@ permission:
102
96
  <action>Check if sensitive data is logged</action>
103
97
  </phase>
104
98
 
105
- <phase name="4. Correctness">
99
+ <phase name="3. Correctness Analysis">
106
100
  <action>Verify all acceptance criteria are met</action>
107
101
  <action>Check edge cases and error handling</action>
108
102
  <action>Look for logic errors and race conditions</action>
109
103
  <action>Verify tests cover critical paths</action>
110
104
  </phase>
111
105
 
112
- <phase name="5. Code Quality">
106
+ <phase name="4. Code Quality Analysis">
113
107
  <action>Check architecture compliance</action>
114
108
  <action>Look for code duplication</action>
115
109
  <action>Verify naming conventions</action>
116
110
  <action>Check for N+1 queries, performance issues</action>
117
111
  </phase>
118
112
 
113
+ <phase name="5. Run Tests & Lint">
114
+ <action>Run test suite: go test / npm test / pytest / cargo test</action>
115
+ <action>Run linter: golangci-lint / eslint / ruff / cargo clippy</action>
116
+ <action>If failures → include in review report as HIGH priority</action>
117
+ </phase>
118
+
119
119
  <phase name="6. Report">
120
120
  <action>Categorize issues: High/Medium/Low</action>
121
121
  <action>Provide specific fixes for each issue</action>
@@ -4,6 +4,7 @@
4
4
  "instructions": [
5
5
  "AGENTS.md",
6
6
  ".opencode/FLOW.yaml",
7
+ ".opencode/config.yaml",
7
8
  "docs/prd.md",
8
9
  "docs/architecture.md"
9
10
  ],
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "dependencies": {
3
- "@opencode-ai/plugin": "1.1.35"
3
+ "@opencode-ai/plugin": "1.1.36"
4
4
  }
5
5
  }
@@ -1,7 +1,26 @@
1
1
  import type { Plugin } from "@opencode-ai/plugin"
2
- import { readFile, access, readdir } from "fs/promises"
2
+ import { readFile, access, readdir, appendFile } from "fs/promises"
3
3
  import { join } from "path"
4
4
 
5
+ // Debug logging to file
6
+ async function log(directory: string, message: string): Promise<void> {
7
+ const logPath = join(directory, ".opencode", "compaction.log")
8
+ const timestamp = new Date().toISOString()
9
+ try {
10
+ await appendFile(logPath, `[${timestamp}] ${message}\n`)
11
+ } catch {
12
+ // ignore logging errors
13
+ }
14
+ }
15
+
16
+ // Service agents that should be ignored
17
+ const SERVICE_AGENTS = ["title", "compaction", "summary", "system"]
18
+
19
+ function isRealAgent(agent: string | null): boolean {
20
+ if (!agent) return false
21
+ return !SERVICE_AGENTS.includes(agent.toLowerCase())
22
+ }
23
+
5
24
  interface TaskStatus {
6
25
  id: string
7
26
  content: string
@@ -486,30 +505,55 @@ Previous task was completed successfully.
486
505
  return {
487
506
  // Track active agent from chat messages
488
507
  "chat.message": async (input, output) => {
508
+ await log(directory, `chat.message: agent=${input.agent}, sessionID=${input.sessionID}`)
489
509
  if (input.agent) {
490
510
  // Handle both string and object agent (e.g., { name: "dev" })
491
- lastActiveAgent = typeof input.agent === 'string'
511
+ const agent = typeof input.agent === 'string'
492
512
  ? input.agent
493
513
  : (input.agent as any)?.name || null
494
- lastSessionId = input.sessionID
514
+
515
+ // Only track real agents, not service agents
516
+ if (isRealAgent(agent)) {
517
+ lastActiveAgent = agent
518
+ lastSessionId = input.sessionID
519
+ await log(directory, ` -> tracked agent: ${lastActiveAgent}`)
520
+ } else {
521
+ await log(directory, ` -> ignored service agent: ${agent}`)
522
+ }
495
523
  }
496
524
  },
497
525
 
498
526
  // Also track from chat params (backup)
499
527
  "chat.params": async (input, output) => {
528
+ await log(directory, `chat.params: agent=${input.agent}`)
500
529
  if (input.agent) {
501
- lastActiveAgent = typeof input.agent === 'string'
530
+ const agent = typeof input.agent === 'string'
502
531
  ? input.agent
503
532
  : (input.agent as any)?.name || null
533
+
534
+ // Only track real agents, not service agents
535
+ if (isRealAgent(agent)) {
536
+ lastActiveAgent = agent
537
+ await log(directory, ` -> tracked agent: ${lastActiveAgent}`)
538
+ } else {
539
+ await log(directory, ` -> ignored service agent: ${agent}`)
540
+ }
504
541
  }
505
542
  },
506
543
 
507
544
  "experimental.session.compacting": async (input, output) => {
545
+ await log(directory, `=== COMPACTION STARTED ===`)
546
+ await log(directory, ` lastActiveAgent: ${lastActiveAgent}`)
547
+
508
548
  // Use tracked agent or try to detect from session
509
549
  const agent = lastActiveAgent
510
550
  const ctx = await buildContext(agent)
511
551
  ctx.activeAgent = agent
512
552
 
553
+ await log(directory, ` story: ${ctx.story?.path || 'none'}`)
554
+ await log(directory, ` todos: ${ctx.todos.length}`)
555
+ await log(directory, ` relevantFiles: ${ctx.relevantFiles.length}`)
556
+
513
557
  const context = formatContext(ctx)
514
558
  const instructions = formatInstructions(ctx)
515
559
  const readCommands = generateReadCommands(agent, ctx.story)
@@ -532,12 +576,17 @@ ${context}
532
576
  ---
533
577
 
534
578
  ${instructions}`)
579
+
580
+ await log(directory, ` -> output.context pushed (${output.context.length} items)`)
581
+ await log(directory, `=== COMPACTION DONE ===`)
535
582
  },
536
583
 
537
584
  event: async ({ event }) => {
585
+ await log(directory, `event: ${event.type}`)
538
586
  if (event.type === "session.idle") {
539
587
  const story = await getActiveStory()
540
588
  if (story && story.pendingTasks.length === 0) {
589
+ await log(directory, ` -> Story complete: ${story.title}`)
541
590
  console.log(`[compaction] Story complete: ${story.title}`)
542
591
  }
543
592
  }
@@ -30,6 +30,132 @@ Always check project standards: `@CLAUDE.md`
30
30
 
31
31
  Use template at: `@.opencode/skills/architecture-design/template.md`
32
32
 
33
+ ## CRITICAL: Adapt Depth to Project Size
34
+
35
+ **BEFORE writing architecture, read PRD's Project Classification section!**
36
+
37
+ Your architecture document size should match project size:
38
+
39
+ | Project Size | Target Lines | Diagrams | ADRs | Focus |
40
+ |--------------|--------------|----------|------|-------|
41
+ | **TOY** | 200-500 | C4 Context + Container | None | Core components only |
42
+ | **SMALL** | 500-1000 | + C4 Component | 2-3 major decisions | Clear module boundaries |
43
+ | **MEDIUM** | 1000-2000 | + Sequences + ER | 5-10 significant | Complete system design |
44
+ | **LARGE** | 2000-4000 | + Deployment + State | 10-20 all decisions | Multiple files OK |
45
+ | **ENTERPRISE** | 4000+ | All diagrams | 20+ per domain | Per-domain files |
46
+
47
+ **Examples:**
48
+
49
+ **TOY (Tetris - 350 lines):**
50
+ ```
51
+ Executive Summary (50 lines)
52
+ System Context diagram (ASCII)
53
+ 3 Modules: GameEngine, Renderer, ScoreManager
54
+ Data Model: GameState object (no DB)
55
+ Tech Stack: HTML5 Canvas, Vanilla JS
56
+ ```
57
+
58
+ **SMALL (Blog - 800 lines):**
59
+ ```
60
+ Executive Summary
61
+ Decision Summary (pattern choice)
62
+ C4 Context + Container + Component
63
+ 5 Modules: Auth, Posts, Comments, Media, Admin
64
+ ER Diagram (users, posts, comments)
65
+ 2-3 ADRs (why SQLite, why server-side rendering)
66
+ ```
67
+
68
+ **MEDIUM (E-commerce - 1500 lines):**
69
+ ```
70
+ Full C4 model
71
+ 8 Modules across 3 domains
72
+ Complete ER diagram
73
+ Sequence diagrams for checkout flow
74
+ 5-10 ADRs
75
+ Integration points documented
76
+ ```
77
+
78
+ **Don't over-engineer small projects!** If PRD says "toy", keep it under 500 lines.
79
+
80
+ ---
81
+
82
+ ## Module/Unit Breakdown by Size
83
+
84
+ **CRITICAL:** Read PRD's Project Classification to determine module strategy.
85
+
86
+ | Project Size | Module Strategy | Structure |
87
+ |--------------|-----------------|-----------|
88
+ | **TOY** | No modules | Flat components (GameEngine, Renderer, ScoreManager) |
89
+ | **SMALL** | No modules | Flat components (AuthService, PostService, CommentService) |
90
+ | **MEDIUM** | **YES - Modules** | 3-5 modules (OrderModule, InventoryModule, PaymentModule) |
91
+ | **LARGE** | **YES - Domains** | 5-10 domains (OrderDomain, PaymentDomain, UserDomain) |
92
+ | **ENTERPRISE** | **YES - Bounded Contexts** | 10+ contexts with subdomains |
93
+
94
+ **For MEDIUM+ projects:**
95
+
96
+ 1. **Identify Modules from PRD:**
97
+ - Read PRD's Executive Summary → "Key Domains"
98
+ - Each domain = Module in architecture
99
+ - Example: PRD lists "Order Management, Inventory, Payment" → 3 modules
100
+
101
+ 2. **Document Each Module:**
102
+ - Create section per module in architecture.md
103
+ - Define module boundaries (what's in, what's out)
104
+ - Define module's internal services
105
+ - Define module's data ownership
106
+ - Define module's API (what other modules can call)
107
+
108
+ 3. **Create Unit Documentation:**
109
+ - For each module, create `docs/units/module-name/index.md`
110
+ - Use `unit-writing` skill
111
+ - Include: data model, API spec, events (if event-driven)
112
+
113
+ 4. **Module Communication:**
114
+ - Document how modules interact
115
+ - Synchronous (REST/GraphQL) or Asynchronous (events)
116
+ - Integration diagram showing module dependencies
117
+
118
+ **Example - MEDIUM E-commerce (3 modules):**
119
+
120
+ ```markdown
121
+ ## Modules Overview
122
+
123
+ ### Order Management Module
124
+
125
+ **Purpose:** Handles order lifecycle from creation to fulfillment
126
+
127
+ **Internal Services:**
128
+ - OrderService: CRUD operations
129
+ - OrderWorkflowService: Status transitions
130
+ - OrderValidationService: Business rules
131
+
132
+ **Data Ownership:**
133
+ - orders table
134
+ - order_items table
135
+ - order_history table
136
+
137
+ **API (exposed to other modules):**
138
+ - `POST /orders` - Create order
139
+ - `GET /orders/{id}` - Get order details
140
+ - `PUT /orders/{id}/status` - Update status
141
+
142
+ **Events Published:**
143
+ - OrderCreated
144
+ - OrderPaid
145
+ - OrderShipped
146
+
147
+ → Unit: `docs/units/order-management/`
148
+
149
+ ### Payment Module
150
+ ...
151
+
152
+ ### Inventory Module
153
+ ...
154
+ ```
155
+
156
+ **TOY/SMALL projects - NO modules:**
157
+ Just list components/services in flat structure.
158
+
33
159
  ## Architecture Document Structure (v2)
34
160
 
35
161
  ### 1. Executive Summary
@@ -15,30 +15,44 @@ How to transform story tasks into executable instructions for @coder.
15
15
 
16
16
  ## Task Transformation
17
17
 
18
- Story task is a specification. @coder needs executable instruction with full context.
18
+ Story task is specification with Approach steps. Transform it into executable instruction with full context.
19
19
 
20
- ### Add Context
20
+ ### Step 1: Read Required Reading
21
21
 
22
- @coder doesn't see the full story. Include:
23
- - **Existing files** - actual paths to domain entities, interfaces, services that exist
24
- - **Patterns to follow** - link to existing similar code ("follow pattern from X")
25
- - **What was done** - results of previous tasks that this task depends on
22
+ Story has "Required Reading" and task has "Read First":
23
+ 1. Open each linked document
24
+ 2. Find the specific sections mentioned
25
+ 3. Extract patterns, signatures, constraints
26
+
27
+ ### Step 2: Find Existing Code
28
+
29
+ From "Read First" paths:
30
+ 1. Read existing similar code (e.g., "existing service example")
31
+ 2. Note the structure, imports, error handling
32
+ 3. This becomes "Pattern Reference" for @coder
33
+
34
+ ### Step 3: Build Context
35
+
36
+ @coder doesn't see story. Provide:
37
+ - **Existing files** - actual paths with what they contain
38
+ - **Patterns to follow** - link to existing similar code
39
+ - **What was done** - results of previous tasks this depends on
26
40
  - **Imports** - what packages to use
27
41
 
28
- ### Add Implementation Direction
42
+ ### Step 4: Add Direction
29
43
 
30
- Provide guidance, not code:
31
- - Interface signatures (what methods to implement)
44
+ Story has "Approach" with high-level steps. Expand with:
45
+ - Interface signatures (method names, params, return types)
32
46
  - Error handling approach (what errors to return)
33
- - Logging requirements (what to log)
34
47
  - Validation rules (what to validate)
48
+ - Constraints from documentation
35
49
 
36
- ### Add Verification
50
+ ### Step 5: Make Verification Concrete
37
51
 
38
- Story has "Done when". Make it concrete:
52
+ Story has "Done when". Add:
39
53
  - Specific test commands to run
40
- - Expected output format
41
54
  - Files that must compile
55
+ - Test coverage expectations
42
56
 
43
57
  ## Formulating Task for @coder
44
58
 
@@ -22,6 +22,93 @@ Use this skill when you need to:
22
22
 
23
23
  Use template at: `@.opencode/skills/epic-writing/template.md`
24
24
 
25
+ ## CRITICAL: What is an Epic?
26
+
27
+ **Epic scope changes with project size!** Read PRD's Project Classification first.
28
+
29
+ | Project Size | Epic = | Example | Stories |
30
+ |--------------|--------|---------|---------|
31
+ | **TOY** | Major feature | "Game Logic", "UI Rendering", "Scoring" | 3-8 tasks |
32
+ | **SMALL** | Feature area | "User Authentication", "Post Management" | 5-12 tasks |
33
+ | **MEDIUM** | **Module/Unit** | "Order Management Module", "Payment Module" | 8-15 features |
34
+ | **LARGE** | **Domain** | "Order Domain", "Payment Domain" | 10-20 features |
35
+ | **ENTERPRISE** | **Bounded Context** | "Core Banking Context" | 15-30 features |
36
+
37
+ **For MEDIUM+ projects:**
38
+ - Each Epic = One Module from PRD
39
+ - Epic should reference Unit documentation: `→ Unit: docs/units/order-management/`
40
+ - Stories within epic are features of that module
41
+ - Epic owns a set of FRs (e.g., FR-ORD-001 through FR-ORD-015)
42
+
43
+ **Example - MEDIUM E-commerce:**
44
+ ```
45
+ Epic: Order Management Module
46
+ → Unit: docs/units/order-management/
47
+ → FRs: FR-ORD-001 to FR-ORD-012
48
+ → Stories:
49
+ - Customer can create order
50
+ - System validates inventory
51
+ - Order status workflow
52
+ - Order history view
53
+ ...
54
+ ```
55
+
56
+ **Example - TOY Tetris:**
57
+ ```
58
+ Epic: Game Logic
59
+ → Stories:
60
+ - Implement block rotation
61
+ - Add collision detection
62
+ - Clear full lines
63
+ - Increase fall speed
64
+ → No Unit docs needed
65
+ → Simple AC: "Game logic works correctly"
66
+ ```
67
+
68
+ **Example - SMALL Blog:**
69
+ ```
70
+ Epic: Post Management
71
+ → Stories:
72
+ - User can create post
73
+ - User can edit post
74
+ - User can delete post
75
+ - User can publish/unpublish
76
+ - Posts show in list
77
+ → No Unit docs (flat structure)
78
+ → AC: "Users can manage posts through full lifecycle"
79
+ ```
80
+
81
+ ---
82
+
83
+ ## Epic Depth by Project Size
84
+
85
+ **CRITICAL:** Epic structure changes with project size!
86
+
87
+ **TOY/SMALL:**
88
+ - Simple overview (1-2 paragraphs)
89
+ - No Units Affected section (no modules)
90
+ - Simple AC checklist
91
+ - Stories listed as bullet points
92
+ - No Technical Decisions section
93
+ - No Risks section
94
+
95
+ **MEDIUM:**
96
+ - Detailed overview with business value
97
+ - **Units Affected section** (references Unit docs)
98
+ - Comprehensive AC
99
+ - Stories in table with dependencies
100
+ - Technical Decisions with ADR links
101
+ - Risks identified
102
+
103
+ **LARGE/ENTERPRISE:**
104
+ - Complete overview with strategic context
105
+ - **Multiple Units Affected** (cross-domain)
106
+ - Exhaustive AC with compliance
107
+ - Stories with estimates and confidence levels
108
+ - All Technical Decisions documented
109
+ - Risks with mitigation plans
110
+ - Security considerations
111
+
25
112
  ## Epic Structure (v2)
26
113
 
27
114
  ### 1. Header
@@ -21,7 +21,194 @@ Use this skill when you need to:
21
21
 
22
22
  Use the template at: `@.opencode/skills/prd-writing/template.md`
23
23
 
24
- ## PRD Structure (v2)
24
+ ## PRD Structure (v3 - with Project Classification)
25
+
26
+ ### 0. Project Classification (MANDATORY FIRST SECTION)
27
+
28
+ **Purpose:** This section determines how deep and detailed ALL subsequent artifacts will be.
29
+
30
+ **CRITICAL - Fill this FIRST:**
31
+ 1. Ask user about project (or infer from requirements)
32
+ 2. Classify size based on timeline and complexity
33
+ 3. Fill the classification table
34
+ 4. Adapt your writing style for the rest of PRD
35
+
36
+ **Classification Table:**
37
+
38
+ | Attribute | Value | Notes |
39
+ |-----------|-------|-------|
40
+ | **Size** | toy / small / medium / large / enterprise | See guide below |
41
+ | **Complexity** | simple / moderate / complex / very_complex | Business logic depth |
42
+ | **Team Size** | 1-100+ | Number of developers |
43
+ | **Timeline** | Days/weeks/months | Expected duration |
44
+ | **Domain** | game / web_app / api / library / cli / mobile_app / embedded | Project type |
45
+
46
+ **Size Impact Table:**
47
+
48
+ | Attribute | Value |
49
+ |-----------|-------|
50
+ | **PRD Depth** | X-Y pages |
51
+ | **Architecture** | X-Y lines |
52
+ | **Epics** | X-Y (scope: feature/module/domain) |
53
+ | **Stories per Epic** | X-Y |
54
+ | **Sprints** | X |
55
+
56
+ ---
57
+
58
+ ### How to Classify Project Size
59
+
60
+ **Ask yourself:**
61
+ - What's the scope? (single feature vs full system)
62
+ - How complex is the business logic? (simple CRUD vs complex workflows)
63
+ - How many integrations? (none vs many external systems)
64
+ - What's the data model? (few entities vs complex relationships)
65
+ - Who's the team? (solo vs multiple teams)
66
+
67
+ ---
68
+
69
+ **TOY** - Learning/Prototype
70
+ - **Examples:** Tetris, Calculator, Tic-tac-toe, Todo list
71
+ - **Scope:** Single feature or concept exploration
72
+ - **Complexity:** Minimal business logic, no integrations
73
+ - **Data:** No database or simple localStorage
74
+ - **Team:** Solo developer
75
+ - **What to write:**
76
+ - PRD: 2-3 pages, bullet points OK
77
+ - Architecture: 200-500 lines, simple component diagram
78
+ - Structure: Flat components (GameEngine, Renderer, ScoreManager)
79
+ - Epics: 3-5 major features ("Game Logic", "UI", "Scoring")
80
+ - No modules, no Unit docs
81
+
82
+ ---
83
+
84
+ **SMALL** - Simple Application
85
+ - **Examples:** Blog, Portfolio site, Simple REST API, Chrome extension, CLI tool
86
+ - **Scope:** Single application with basic CRUD
87
+ - **Complexity:** Simple business logic, 1-2 integrations max
88
+ - **Data:** Basic database (5-10 tables), simple relationships
89
+ - **Team:** 1-2 developers
90
+ - **What to write:**
91
+ - PRD: 3-5 pages, structured tables
92
+ - Architecture: 500-1000 lines, C4 Context + Container + Component
93
+ - Structure: Flat services (AuthService, PostService, CommentService)
94
+ - Epics: 5-10 feature areas ("User Auth", "Post Management")
95
+ - No modules yet, no Unit docs
96
+
97
+ ---
98
+
99
+ **MEDIUM** - Multi-Module System
100
+ - **Examples:** E-commerce site, CRM, Mobile app, Booking system
101
+ - **Scope:** Multiple interconnected features
102
+ - **Complexity:** Moderate business logic, 3-5 integrations, workflows
103
+ - **Data:** 15-30 tables, complex relationships, transactions
104
+ - **Team:** 2-5 developers (small team)
105
+ - **What to write:**
106
+ - PRD: 5-10 pages, break into **MODULES**
107
+ - Architecture: 1000-2000 lines, full C4 model + sequences
108
+ - Structure: **Modules** (OrderModule, InventoryModule, PaymentModule)
109
+ - Epics: 8-15, **each Epic = one Module**
110
+ - **Create Unit docs** for each module: `docs/units/module-name/`
111
+ - Module boundaries matter - define what's in/out
112
+
113
+ ---
114
+
115
+ **LARGE** - Multi-Domain Platform
116
+ - **Examples:** Multi-tenant SaaS, Payment platform, Social network, Marketplace
117
+ - **Scope:** Multiple domains with complex interactions
118
+ - **Complexity:** Complex business logic, 10+ integrations, event-driven
119
+ - **Data:** 50-100+ tables, multiple databases, caching layers
120
+ - **Team:** 5-20 developers (multiple teams)
121
+ - **What to write:**
122
+ - PRD: 10-20 pages, think in **DOMAINS**
123
+ - Architecture: 2000-4000 lines, likely multiple files per domain
124
+ - Structure: **Domains/Bounded Contexts** (OrderDomain, PaymentDomain)
125
+ - Epics: 15-30, **each Epic = one Domain**
126
+ - **Complete Unit docs** with API specs, events, data models
127
+ - ADRs for all major decisions (affects multiple teams)
128
+ - Security review required
129
+
130
+ ---
131
+
132
+ **ENTERPRISE** - Mission-Critical System
133
+ - **Examples:** Banking system, Healthcare platform, ERP, Trading platform
134
+ - **Scope:** Enterprise-wide system with governance
135
+ - **Complexity:** Very complex, regulatory compliance, high availability
136
+ - **Data:** 100+ tables, distributed databases, audit trails
137
+ - **Team:** 20+ developers (large organization)
138
+ - **What to write:**
139
+ - PRD: 20-50 pages, strategic document
140
+ - Architecture: 4000+ lines, per-domain files
141
+ - Structure: **Bounded Contexts** with subdomains
142
+ - Compliance requirements in every section
143
+ - Multiple review stages (security, compliance, legal)
144
+ - Audit-ready documentation
145
+
146
+ ---
147
+
148
+ ### How Size Affects Your Writing
149
+
150
+ **TOY/SMALL - Keep it lean:**
151
+ ```markdown
152
+ ## Functional Requirements
153
+
154
+ ### Game Logic
155
+ | ID | Requirement | Priority |
156
+ |----|-------------|----------|
157
+ | FR-001 | User can rotate block | P0 |
158
+ | FR-002 | Blocks fall automatically | P0 |
159
+ | FR-003 | Full lines disappear | P0 |
160
+
161
+ **Notes:**
162
+ - Rotation uses standard Tetris rules
163
+ - Fall speed increases with score
164
+ ```
165
+
166
+ **MEDIUM - Structured by modules:**
167
+ ```markdown
168
+ ## Functional Requirements
169
+
170
+ ### Order Management Module
171
+ | ID | Requirement | Priority |
172
+ |----|-------------|----------|
173
+ | FR-ORD-001 | Customer can create order with items | P0 |
174
+ | FR-ORD-002 | System validates inventory before order | P0 |
175
+ | FR-ORD-003 | Order status follows workflow (pending → paid → shipped) | P0 |
176
+
177
+ **Notes:**
178
+ - Order cannot be modified after payment
179
+ - Inventory reserved on order creation, committed on payment
180
+
181
+ → Unit: `docs/units/order-management/`
182
+
183
+ ### Payment Module
184
+ | ID | Requirement | Priority |
185
+ |----|-------------|----------|
186
+ | FR-PAY-001 | System integrates with Stripe | P0 |
187
+ | FR-PAY-002 | Payment failures trigger order cancellation | P0 |
188
+
189
+ → Unit: `docs/units/payment/`
190
+ ```
191
+
192
+ **LARGE/ENTERPRISE - Domain-driven:**
193
+ ```markdown
194
+ ## Functional Requirements
195
+
196
+ ### Order Domain
197
+ → Unit: `docs/units/order-domain/`
198
+
199
+ #### Order Lifecycle
200
+ | ID | Requirement | Priority | Compliance |
201
+ |----|-------------|----------|------------|
202
+ | FR-ORD-001 | Customer can create order | P0 | GDPR: consent required |
203
+ | FR-ORD-002 | Order audit trail maintained | P0 | SOX: 7 year retention |
204
+
205
+ #### Order Validation
206
+ ...
207
+
208
+ ### Payment Domain
209
+ → Unit: `docs/units/payment-domain/`
210
+ ...
211
+ ```
25
212
 
26
213
  ### 1. Executive Summary
27
214
 
@@ -47,9 +234,28 @@ Brief prose section with:
47
234
  | Growth Features | Post-MVP enhancements |
48
235
  | Out of Scope | Explicit exclusions |
49
236
 
237
+ **IMPORTANT - Module Breakdown by Size:**
238
+
239
+ - **TOY/SMALL:** No modules needed, flat feature list
240
+ - **MEDIUM+:** Break into modules/domains (Units)
241
+ - Each module = separate section in scope
242
+ - Each module will become Epic later
243
+ - Example: "Order Management Module", "Payment Module"
244
+
50
245
  ### 4. Functional Requirements
51
246
 
52
- **Grouped by domain in tables:**
247
+ **Grouping by Project Size:**
248
+
249
+ **TOY/SMALL projects:**
250
+ - Group by feature area (flat structure)
251
+ - Example: "Game Logic", "UI", "Scoring"
252
+
253
+ **MEDIUM+ projects:**
254
+ - Group by Module/Unit (hierarchical)
255
+ - Each module gets its own FR table
256
+ - Example: "Order Management Module" → FR-ORD-001, FR-ORD-002
257
+
258
+ **Table format:**
53
259
 
54
260
  | ID | Requirement | Priority |
55
261
  |----|-------------|----------|
@@ -57,6 +263,13 @@ Brief prose section with:
57
263
 
58
264
  With **Notes:** for business rules after each domain table.
59
265
 
266
+ **Module-based FR IDs (MEDIUM+):**
267
+ ```
268
+ FR-ORD-001 # Order Management module
269
+ FR-PAY-001 # Payment module
270
+ FR-INV-001 # Inventory module
271
+ ```
272
+
60
273
  ### 5. Non-Functional Requirements
61
274
 
62
275
  Tables for:
@@ -81,13 +294,40 @@ Using `→` format:
81
294
  → Requirements: `docs/requirements.md`
82
295
  ```
83
296
 
297
+ ## Units (Modules/Domains)
298
+
299
+ **What is a Unit?**
300
+ A Unit is a module, domain, or bounded context - a cohesive piece of the system.
301
+
302
+ **When to create Units?**
303
+
304
+ | Project Size | Units? | Scope | Examples |
305
+ |--------------|--------|-------|----------|
306
+ | **TOY** | No | Flat features | "Game Logic", "UI", "Scoring" |
307
+ | **SMALL** | No | Flat features | "Auth", "Posts", "Comments" |
308
+ | **MEDIUM** | Yes | Modules | "Order Management", "Inventory", "Payment" |
309
+ | **LARGE** | Yes | Domains | "Order Domain", "Payment Domain" |
310
+ | **ENTERPRISE** | Yes | Bounded Contexts | "Core Banking", "Risk Management" |
311
+
312
+ **For MEDIUM+ projects:**
313
+ 1. Identify modules/domains in Executive Summary
314
+ 2. Create separate scope section per module
315
+ 3. Group FRs by module (FR-ORD-001, FR-PAY-001)
316
+ 4. Each module → separate Epic later
317
+ 5. Each module → separate Unit documentation (docs/units/module-name/)
318
+
319
+ **Unit Documentation:**
320
+ - For MEDIUM+ projects, create `docs/units/module-name/index.md` for each module
321
+ - Use `unit-writing` skill to document each unit
322
+ - Link from PRD: `→ Unit: Order Management - docs/units/order-management/`
323
+
84
324
  ## Writing Guidelines
85
325
 
86
326
  ### Reference Format
87
327
 
88
328
  Always use `→` prefix for links:
89
329
  ```
90
- → Unit: `Task`
330
+ → Unit: `Order Management` - docs/units/order-management/
91
331
  → FR: `FR-001`
92
332
  → ADR: `ADR-001`
93
333
  → `path/to/file.md`
@@ -10,6 +10,42 @@ author: {{author}}
10
10
 
11
11
  ---
12
12
 
13
+ ## Project Classification
14
+
15
+ > **Purpose:** Determines workflow depth and artifact sizes. Agents use this to adapt their approach.
16
+ > See `.opencode/project-size-guide.yaml` for detailed guidelines.
17
+
18
+ | Attribute | Value | Notes |
19
+ |-----------|-------|-------|
20
+ | **Size** | {{size}} | toy / small / medium / large / enterprise |
21
+ | **Complexity** | {{complexity}} | simple / moderate / complex / very_complex |
22
+ | **Team Size** | {{team_size}} | Number of developers |
23
+ | **Timeline** | {{timeline}} | Expected duration |
24
+ | **Domain** | {{domain}} | web_app / mobile_app / api / library / cli / game / embedded |
25
+
26
+ **Size Impact:**
27
+ - **PRD Depth:** {{prd_pages}} pages
28
+ - **Architecture:** {{arch_lines}} lines
29
+ - **Epics:** {{epic_count}} ({{epic_scope}})
30
+ - **Stories per Epic:** {{stories_per_epic}}
31
+ - **Sprints:** {{sprint_count}}
32
+
33
+ <!-- Examples:
34
+ TOY (Tetris):
35
+ Size: toy | Complexity: simple | Team: 1 | Timeline: < 1 week | Domain: game
36
+ PRD: 2-3 pages | Arch: 200-500 lines | Epics: 3-5 (major features) | Stories: 3-8 | Sprints: 1
37
+
38
+ SMALL (Blog):
39
+ Size: small | Complexity: simple | Team: 1-2 | Timeline: 1-4 weeks | Domain: web_app
40
+ PRD: 3-5 pages | Arch: 500-1000 lines | Epics: 5-10 (features) | Stories: 5-12 | Sprints: 1-2
41
+
42
+ MEDIUM (E-commerce):
43
+ Size: medium | Complexity: moderate | Team: 2-5 | Timeline: 1-3 months | Domain: web_app
44
+ PRD: 5-10 pages | Arch: 1000-2000 lines | Epics: 8-15 (modules) | Stories: 8-15 | Sprints: 2-4
45
+ -->
46
+
47
+ ---
48
+
13
49
  ## Executive Summary
14
50
 
15
51
  {{project}} is a {{type}} platform for {{target_users}}. The system handles {{core_capabilities}}.
@@ -22,6 +22,35 @@ Use this skill when you need to:
22
22
 
23
23
  Use template at: `@.opencode/skills/story-writing/template.md`
24
24
 
25
+ ## CRITICAL: Story Depth by Project Size
26
+
27
+ **Read PRD's Project Classification to understand appropriate depth!**
28
+
29
+ | Project Size | Story Depth | AC Detail | Tasks | Example |
30
+ |--------------|-------------|-----------|-------|---------|
31
+ | **TOY** | Simple | Basic Given/When/Then | 1-3 tasks, no subtasks | "Implement block rotation" |
32
+ | **SMALL** | Moderate | Given/When/Then + edge cases | 2-5 tasks, optional subtasks | "User can create post" |
33
+ | **MEDIUM** | Detailed | Comprehensive Given/When/Then | 3-8 tasks, subtasks recommended | "Customer can place order" |
34
+ | **LARGE** | Comprehensive | All scenarios + edge cases | 5-10 tasks, subtasks required | "Process payment with retry logic" |
35
+ | **ENTERPRISE** | Exhaustive | All scenarios + compliance | 8-15 tasks, subtasks + estimates | "Execute trade with audit trail" |
36
+
37
+ **Key differences:**
38
+
39
+ **TOY/SMALL:**
40
+ - Simple AC: "Given block at top, When user presses rotate, Then block rotates 90°"
41
+ - Tasks are straightforward: "Add rotation logic", "Add tests"
42
+ - No Required Reading section needed (no coding standards yet)
43
+
44
+ **MEDIUM:**
45
+ - Detailed AC with edge cases: "Given order with out-of-stock item, When customer submits, Then show error"
46
+ - Tasks reference coding standards and Unit docs
47
+ - Required Reading section mandatory
48
+
49
+ **LARGE/ENTERPRISE:**
50
+ - Exhaustive AC with compliance: "Given payment failure, When retry limit reached, Then log to audit, notify customer, update order status"
51
+ - Tasks include security considerations
52
+ - Multiple review stages
53
+
25
54
  ## MANDATORY: Read Before Writing
26
55
 
27
56
  **Before writing ANY story, read these documents:**