agileflow 2.90.7 → 2.92.0

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.
Files changed (144) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +6 -6
  3. package/lib/README.md +178 -0
  4. package/lib/codebase-indexer.js +818 -0
  5. package/lib/colors.js +190 -12
  6. package/lib/consent.js +232 -0
  7. package/lib/correlation.js +277 -0
  8. package/lib/error-codes.js +46 -0
  9. package/lib/errors.js +48 -6
  10. package/lib/file-cache.js +182 -0
  11. package/lib/format-error.js +156 -0
  12. package/lib/path-resolver.js +155 -7
  13. package/lib/paths.js +212 -20
  14. package/lib/placeholder-registry.js +205 -0
  15. package/lib/registry-di.js +358 -0
  16. package/lib/result-schema.js +363 -0
  17. package/lib/result.js +210 -0
  18. package/lib/session-registry.js +13 -0
  19. package/lib/session-state-machine.js +465 -0
  20. package/lib/validate-commands.js +308 -0
  21. package/lib/validate-names.js +3 -3
  22. package/lib/validate.js +116 -52
  23. package/package.json +4 -1
  24. package/scripts/af +34 -0
  25. package/scripts/agent-loop.js +63 -9
  26. package/scripts/agileflow-configure.js +2 -2
  27. package/scripts/agileflow-welcome.js +435 -23
  28. package/scripts/archive-completed-stories.sh +57 -11
  29. package/scripts/claude-tmux.sh +102 -0
  30. package/scripts/damage-control-bash.js +3 -70
  31. package/scripts/damage-control-edit.js +3 -20
  32. package/scripts/damage-control-write.js +3 -20
  33. package/scripts/dependency-check.js +310 -0
  34. package/scripts/get-env.js +11 -4
  35. package/scripts/lib/configure-detect.js +23 -1
  36. package/scripts/lib/configure-features.js +43 -2
  37. package/scripts/lib/context-formatter.js +771 -0
  38. package/scripts/lib/context-loader.js +699 -0
  39. package/scripts/lib/damage-control-utils.js +107 -0
  40. package/scripts/lib/json-utils.sh +162 -0
  41. package/scripts/lib/state-migrator.js +353 -0
  42. package/scripts/lib/story-state-machine.js +437 -0
  43. package/scripts/obtain-context.js +118 -1048
  44. package/scripts/pre-push-check.sh +46 -0
  45. package/scripts/precompact-context.sh +36 -11
  46. package/scripts/query-codebase.js +538 -0
  47. package/scripts/ralph-loop.js +5 -5
  48. package/scripts/session-manager.js +220 -42
  49. package/scripts/spawn-parallel.js +651 -0
  50. package/scripts/tui/blessed/data/watcher.js +180 -0
  51. package/scripts/tui/blessed/index.js +244 -0
  52. package/scripts/tui/blessed/panels/output.js +101 -0
  53. package/scripts/tui/blessed/panels/sessions.js +150 -0
  54. package/scripts/tui/blessed/panels/trace.js +97 -0
  55. package/scripts/tui/blessed/ui/help.js +77 -0
  56. package/scripts/tui/blessed/ui/screen.js +52 -0
  57. package/scripts/tui/blessed/ui/statusbar.js +47 -0
  58. package/scripts/tui/blessed/ui/tabbar.js +99 -0
  59. package/scripts/tui/index.js +38 -30
  60. package/scripts/validators/README.md +143 -0
  61. package/scripts/validators/component-validator.js +239 -0
  62. package/scripts/validators/json-schema-validator.js +186 -0
  63. package/scripts/validators/markdown-validator.js +152 -0
  64. package/scripts/validators/migration-validator.js +129 -0
  65. package/scripts/validators/security-validator.js +380 -0
  66. package/scripts/validators/story-format-validator.js +197 -0
  67. package/scripts/validators/test-result-validator.js +114 -0
  68. package/scripts/validators/workflow-validator.js +247 -0
  69. package/src/core/agents/accessibility.md +6 -0
  70. package/src/core/agents/adr-writer.md +6 -0
  71. package/src/core/agents/analytics.md +6 -0
  72. package/src/core/agents/api.md +6 -0
  73. package/src/core/agents/ci.md +6 -0
  74. package/src/core/agents/codebase-query.md +261 -0
  75. package/src/core/agents/compliance.md +6 -0
  76. package/src/core/agents/configuration-damage-control.md +6 -0
  77. package/src/core/agents/configuration-visual-e2e.md +6 -0
  78. package/src/core/agents/database.md +10 -0
  79. package/src/core/agents/datamigration.md +6 -0
  80. package/src/core/agents/design.md +6 -0
  81. package/src/core/agents/devops.md +6 -0
  82. package/src/core/agents/documentation.md +6 -0
  83. package/src/core/agents/epic-planner.md +6 -0
  84. package/src/core/agents/integrations.md +6 -0
  85. package/src/core/agents/mentor.md +6 -0
  86. package/src/core/agents/mobile.md +6 -0
  87. package/src/core/agents/monitoring.md +6 -0
  88. package/src/core/agents/multi-expert.md +6 -0
  89. package/src/core/agents/performance.md +6 -0
  90. package/src/core/agents/product.md +6 -0
  91. package/src/core/agents/qa.md +6 -0
  92. package/src/core/agents/readme-updater.md +6 -0
  93. package/src/core/agents/refactor.md +6 -0
  94. package/src/core/agents/research.md +6 -0
  95. package/src/core/agents/security.md +6 -0
  96. package/src/core/agents/testing.md +10 -0
  97. package/src/core/agents/ui.md +6 -0
  98. package/src/core/commands/adr.md +114 -0
  99. package/src/core/commands/agent.md +120 -0
  100. package/src/core/commands/assign.md +145 -0
  101. package/src/core/commands/audit.md +401 -0
  102. package/src/core/commands/babysit.md +32 -5
  103. package/src/core/commands/board.md +1 -0
  104. package/src/core/commands/changelog.md +118 -0
  105. package/src/core/commands/configure.md +42 -6
  106. package/src/core/commands/diagnose.md +114 -0
  107. package/src/core/commands/epic.md +205 -1
  108. package/src/core/commands/handoff.md +128 -0
  109. package/src/core/commands/help.md +76 -0
  110. package/src/core/commands/metrics.md +1 -0
  111. package/src/core/commands/pr.md +96 -0
  112. package/src/core/commands/research/analyze.md +1 -0
  113. package/src/core/commands/research/ask.md +2 -0
  114. package/src/core/commands/research/import.md +1 -0
  115. package/src/core/commands/research/list.md +2 -0
  116. package/src/core/commands/research/synthesize.md +584 -0
  117. package/src/core/commands/research/view.md +2 -0
  118. package/src/core/commands/roadmap/analyze.md +400 -0
  119. package/src/core/commands/session/new.md +113 -6
  120. package/src/core/commands/session/spawn.md +197 -0
  121. package/src/core/commands/sprint.md +22 -0
  122. package/src/core/commands/status.md +200 -1
  123. package/src/core/commands/story/list.md +9 -9
  124. package/src/core/commands/story/view.md +1 -0
  125. package/src/core/commands/story.md +143 -4
  126. package/src/core/experts/codebase-query/expertise.yaml +190 -0
  127. package/src/core/experts/codebase-query/question.md +73 -0
  128. package/src/core/experts/codebase-query/self-improve.md +105 -0
  129. package/src/core/templates/agileflow-metadata.json +55 -2
  130. package/src/core/templates/plan-template.md +125 -0
  131. package/src/core/templates/story-lifecycle.md +213 -0
  132. package/src/core/templates/story-template.md +4 -0
  133. package/src/core/templates/tdd-test-template.js +241 -0
  134. package/tools/cli/commands/setup.js +86 -0
  135. package/tools/cli/installers/core/installer.js +94 -0
  136. package/tools/cli/installers/ide/_base-ide.js +20 -11
  137. package/tools/cli/installers/ide/codex.js +29 -47
  138. package/tools/cli/lib/config-manager.js +17 -2
  139. package/tools/cli/lib/content-transformer.js +271 -0
  140. package/tools/cli/lib/error-handler.js +14 -22
  141. package/tools/cli/lib/ide-error-factory.js +421 -0
  142. package/tools/cli/lib/ide-health-monitor.js +364 -0
  143. package/tools/cli/lib/ide-registry.js +114 -1
  144. package/tools/cli/lib/ui.js +14 -25
@@ -0,0 +1,125 @@
1
+ ---
2
+ plan_id: {{PLAN_ID}}
3
+ epic: {{EPIC_ID}}
4
+ title: {{TITLE}}
5
+ created: {{CREATED}}
6
+ ---
7
+
8
+ # {{TITLE}}
9
+
10
+ ## Overview
11
+
12
+ {{GOAL}}
13
+
14
+ ---
15
+
16
+ ## Phase 1: Foundation (Sequential)
17
+
18
+ <!-- Stories that must complete before parallel work can begin -->
19
+ <!-- These have no dependencies or are prerequisites for everything else -->
20
+
21
+ - [ ] {{STORY_ID}}: {{STORY_TITLE}}
22
+ - [ ] {{STORY_ID}}: {{STORY_TITLE}}
23
+
24
+ ---
25
+
26
+ ## Phase 2: Features (Parallel-eligible)
27
+
28
+ <!-- Stories that can run in parallel sessions -->
29
+ <!-- All depend only on Phase 1 completion -->
30
+
31
+ - [ ] {{STORY_ID}}: {{STORY_TITLE}} (Session A)
32
+ - [ ] {{STORY_ID}}: {{STORY_TITLE}} (Session B)
33
+ - [ ] {{STORY_ID}}: {{STORY_TITLE}} (Session C)
34
+
35
+ ---
36
+
37
+ ## Phase 3: Integration (Sequential)
38
+
39
+ <!-- Stories that depend on Phase 2 completion -->
40
+ <!-- Must wait for parallel work to merge -->
41
+
42
+ - [ ] {{STORY_ID}}: {{STORY_TITLE}}
43
+
44
+ ---
45
+
46
+ ## Deviations Log
47
+
48
+ <!-- Track decisions that differ from original plan -->
49
+ <!-- Important: Keep this updated so next sessions have context -->
50
+
51
+ | Date | Phase | Original | Changed To | Reason |
52
+ |------|-------|----------|------------|--------|
53
+ | | | | | |
54
+
55
+ ---
56
+
57
+ ## Session Prompts
58
+
59
+ <!-- Copy-paste prompts for new parallel sessions -->
60
+ <!-- Customize based on specific stories in Phase 2 -->
61
+
62
+ ### Session A prompt:
63
+ ```
64
+ Read plan.md in the project root.
65
+ Execute Phase 2 Task A: [TASK DESCRIPTION].
66
+ Phase 1 is complete - foundation is in place.
67
+ Check off tasks in plan.md when done.
68
+ Log any deviations to the Deviations Log section.
69
+ Run tests before marking complete.
70
+ ```
71
+
72
+ ### Session B prompt:
73
+ ```
74
+ Read plan.md in the project root.
75
+ Execute Phase 2 Task B: [TASK DESCRIPTION].
76
+ Phase 1 is complete - foundation is in place.
77
+ Check off tasks in plan.md when done.
78
+ Log any deviations to the Deviations Log section.
79
+ Run tests before marking complete.
80
+ ```
81
+
82
+ ### Session C prompt:
83
+ ```
84
+ Read plan.md in the project root.
85
+ Execute Phase 2 Task C: [TASK DESCRIPTION].
86
+ Phase 1 is complete - foundation is in place.
87
+ Check off tasks in plan.md when done.
88
+ Log any deviations to the Deviations Log section.
89
+ Run tests before marking complete.
90
+ ```
91
+
92
+ ---
93
+
94
+ ## Verification Session
95
+
96
+ <!-- Keep one terminal dedicated to plan verification -->
97
+ <!-- After each phase, run these checks -->
98
+
99
+ ### Phase completion checks:
100
+ ```
101
+ After Phase 1:
102
+ - [ ] All Phase 1 checkboxes checked
103
+ - [ ] Tests passing
104
+ - [ ] No uncommitted changes
105
+ - [ ] Ready to spawn parallel sessions
106
+
107
+ After Phase 2:
108
+ - [ ] All Phase 2 checkboxes checked
109
+ - [ ] All parallel branches merged
110
+ - [ ] No merge conflicts
111
+ - [ ] Integration tests passing
112
+
113
+ After Phase 3:
114
+ - [ ] All Phase 3 checkboxes checked
115
+ - [ ] Final tests passing
116
+ - [ ] Ready for review/deploy
117
+ ```
118
+
119
+ ---
120
+
121
+ ## Notes
122
+
123
+ <!-- Additional context, risks, or decisions -->
124
+ <!-- Reference ADRs if architectural decisions were made -->
125
+
@@ -0,0 +1,213 @@
1
+ # Story Lifecycle
2
+
3
+ This document describes how stories transition through different states in AgileFlow.
4
+
5
+ ---
6
+
7
+ ## State Diagram
8
+
9
+ ```mermaid
10
+ stateDiagram-v2
11
+ [*] --> draft: create
12
+
13
+ draft --> ready: validate (DoR met)
14
+ draft --> draft: edit
15
+
16
+ ready --> in_progress: start work
17
+ ready --> blocked: dependency issue
18
+
19
+ in_progress --> in_review: submit PR
20
+ in_progress --> blocked: blocker found
21
+ in_progress --> ready: pause work
22
+
23
+ blocked --> ready: unblocked
24
+ blocked --> in_progress: unblocked (continue)
25
+
26
+ in_review --> done: PR merged
27
+ in_review --> in_progress: changes requested
28
+
29
+ done --> [*]
30
+ ```
31
+
32
+ ---
33
+
34
+ ## Story States
35
+
36
+ | State | Description | Next Actions |
37
+ |-------|-------------|--------------|
38
+ | **draft** | Story created but not ready for work | Validate, add AC, set estimate |
39
+ | **ready** | Definition of Ready (DoR) met | Start work, assign owner |
40
+ | **in-progress** | Actively being worked on | Complete, submit PR, or pause |
41
+ | **blocked** | Waiting on external dependency | Resolve blocker, escalate |
42
+ | **in-review** | Pull request submitted | Review, approve, merge |
43
+ | **done** | Work complete and merged | Archive, celebrate |
44
+
45
+ ---
46
+
47
+ ## State Transitions
48
+
49
+ ### draft → ready
50
+
51
+ **Trigger**: Story passes Definition of Ready (DoR)
52
+
53
+ **DoR Checklist**:
54
+ - [ ] Clear acceptance criteria (Given/When/Then)
55
+ - [ ] Estimate provided
56
+ - [ ] Dependencies identified
57
+ - [ ] Owner assigned
58
+ - [ ] Epic linked
59
+
60
+ **Command**: `/agileflow:story-validate STORY=US-XXXX`
61
+
62
+ ---
63
+
64
+ ### ready → in-progress
65
+
66
+ **Trigger**: Developer starts work
67
+
68
+ **Actions**:
69
+ 1. Update status.json: `status: "in-progress"`
70
+ 2. Set phase to `execute`
71
+ 3. Log to bus/log.jsonl
72
+
73
+ **Command**: `/agileflow:status STORY=US-XXXX STATUS=in-progress`
74
+
75
+ ---
76
+
77
+ ### in-progress → in-review
78
+
79
+ **Trigger**: Pull request created
80
+
81
+ **Actions**:
82
+ 1. Update status.json: `status: "in-review"`
83
+ 2. Set phase to `audit`
84
+ 3. Add PR link
85
+ 4. Log to bus/log.jsonl
86
+
87
+ **Command**: `/agileflow:status STORY=US-XXXX STATUS=in-review PR=<url>`
88
+
89
+ ---
90
+
91
+ ### in-review → done
92
+
93
+ **Trigger**: PR merged to main
94
+
95
+ **Actions**:
96
+ 1. Update status.json: `status: "done"`
97
+ 2. Set phase to `complete`
98
+ 3. Log completion to bus/log.jsonl
99
+ 4. Auto-archive after 7 days
100
+
101
+ **Command**: `/agileflow:status STORY=US-XXXX STATUS=done`
102
+
103
+ ---
104
+
105
+ ### → blocked
106
+
107
+ **Trigger**: External dependency or blocker found
108
+
109
+ **Actions**:
110
+ 1. Update status.json: `status: "blocked"`
111
+ 2. Add blocker reason
112
+ 3. Log to bus/log.jsonl
113
+ 4. Notify dependent teams
114
+
115
+ **Command**: `/agileflow:status STORY=US-XXXX STATUS=blocked SUMMARY="Waiting on API keys"`
116
+
117
+ ---
118
+
119
+ ## Phase Mapping
120
+
121
+ Stories have both a **status** and a **phase**. Phases group statuses for high-level tracking:
122
+
123
+ | Status | Phase | Description |
124
+ |--------|-------|-------------|
125
+ | draft | plan | Planning and scoping |
126
+ | ready | plan | Ready for planning/assignment |
127
+ | in-progress | execute | Active development |
128
+ | blocked | execute | Blocked but in execute phase |
129
+ | in-review | audit | Quality review |
130
+ | done | complete | Work finished |
131
+
132
+ ---
133
+
134
+ ## WIP Limits
135
+
136
+ AgileFlow enforces Work-In-Progress (WIP) limits to prevent overload:
137
+
138
+ - **Per Agent**: Max 2 stories in `in-progress` + `in-review`
139
+ - **Per Epic**: Configurable, typically 5-10 concurrent stories
140
+
141
+ **Violation handling**:
142
+ ```
143
+ ⚠️ WIP Limit Exceeded
144
+
145
+ AG-UI has 3 stories in progress (limit: 2):
146
+ - US-0042: Login Form
147
+ - US-0043: Profile Page
148
+ - US-0044: Dashboard
149
+
150
+ Complete or pause a story before starting new work.
151
+ ```
152
+
153
+ ---
154
+
155
+ ## Lifecycle in status.json
156
+
157
+ ```json
158
+ {
159
+ "stories": {
160
+ "US-0042": {
161
+ "id": "US-0042",
162
+ "title": "Login Form with Validation",
163
+ "epic": "EP-0010",
164
+ "owner": "AG-UI",
165
+ "status": "in-progress",
166
+ "phase": "execute",
167
+ "estimate": "2h",
168
+ "deps": ["US-0041"],
169
+ "created": "2026-01-20T10:00:00Z",
170
+ "updated": "2026-01-21T14:30:00Z",
171
+ "history": [
172
+ {"status": "draft", "ts": "2026-01-20T10:00:00Z"},
173
+ {"status": "ready", "ts": "2026-01-20T11:00:00Z"},
174
+ {"status": "in-progress", "ts": "2026-01-21T09:00:00Z"}
175
+ ]
176
+ }
177
+ }
178
+ }
179
+ ```
180
+
181
+ ---
182
+
183
+ ## Bus Messages
184
+
185
+ State transitions are logged to `docs/09-agents/bus/log.jsonl`:
186
+
187
+ ```jsonl
188
+ {"ts":"2026-01-21T09:00:00Z","type":"status","from":"AG-UI","to":"ALL","story":"US-0042","status":"in-progress","text":"Started work on login form"}
189
+ {"ts":"2026-01-21T14:30:00Z","type":"status","from":"AG-UI","to":"ALL","story":"US-0042","status":"in-review","pr":"https://github.com/.../pull/42"}
190
+ {"ts":"2026-01-21T16:00:00Z","type":"status","from":"AG-UI","to":"ALL","story":"US-0042","status":"done","text":"PR merged"}
191
+ ```
192
+
193
+ ---
194
+
195
+ ## Related Commands
196
+
197
+ | Command | Purpose |
198
+ |---------|---------|
199
+ | `/agileflow:story` | Create new story |
200
+ | `/agileflow:status` | Update story status |
201
+ | `/agileflow:board` | View kanban board |
202
+ | `/agileflow:blockers` | View blocked stories |
203
+ | `/agileflow:story-validate` | Validate DoR |
204
+
205
+ ---
206
+
207
+ ## Best Practices
208
+
209
+ 1. **Keep stories small**: 1-3 days of work maximum
210
+ 2. **Update status promptly**: Reflect actual work state
211
+ 3. **Document blockers**: Include reason and expected resolution
212
+ 4. **Respect WIP limits**: Complete before starting new
213
+ 5. **Use phase handoffs**: Capture context at transitions
@@ -8,6 +8,8 @@ estimate: {{ESTIMATE}}
8
8
  created: {{CREATED}}
9
9
  updated: {{UPDATED}}
10
10
  dependencies: {{DEPENDENCIES}}
11
+ tdd_mode: {{TDD_MODE}}
12
+ test_file: {{TEST_FILE}}
11
13
  ---
12
14
 
13
15
  # {{STORY_ID}}: {{TITLE}}
@@ -15,6 +17,7 @@ dependencies: {{DEPENDENCIES}}
15
17
  **Epic**: {{EPIC_ID}}
16
18
  **Owner**: {{OWNER}}
17
19
  **Estimate**: {{ESTIMATE}}
20
+ {{TDD_BADGE}}
18
21
 
19
22
  ## Description
20
23
  {{DESCRIPTION}}
@@ -50,6 +53,7 @@ dependencies: {{DEPENDENCIES}}
50
53
 
51
54
  ## Testing Strategy
52
55
  See: `docs/07-testing/test-cases/{{STORY_ID}}.md`
56
+ {{TDD_TEST_FILE_REF}}
53
57
 
54
58
  ## Dependencies
55
59
  {{DEPENDENCIES}}
@@ -0,0 +1,241 @@
1
+ /**
2
+ * TDD Test Template for AgileFlow Story Creation
3
+ *
4
+ * This template generates framework-specific test stubs from acceptance criteria.
5
+ * Used by /agileflow:story when TDD=true flag is set.
6
+ *
7
+ * Placeholders:
8
+ * - {{STORY_ID}} - Story identifier (e.g., US-0042)
9
+ * - {{TITLE}} - Story title
10
+ * - {{EPIC}} - Epic identifier (e.g., EP-0010)
11
+ * - {{AC_TESTS}} - Generated test cases from acceptance criteria
12
+ * - {{CREATED}} - ISO timestamp
13
+ */
14
+
15
+ // Template for Jest/Vitest (JavaScript/TypeScript)
16
+ const jestTemplate = `/**
17
+ * TDD Tests for {{STORY_ID}}: {{TITLE}}
18
+ *
19
+ * Story: docs/06-stories/{{EPIC}}/{{STORY_ID}}-*.md
20
+ * Created: {{CREATED}}
21
+ *
22
+ * These tests are generated from acceptance criteria.
23
+ * Implementation goal: Make all tests pass.
24
+ *
25
+ * Workflow:
26
+ * 1. Review each test case (currently skipped)
27
+ * 2. Implement the feature code
28
+ * 3. Remove .skip from tests one at a time
29
+ * 4. Run tests until all pass
30
+ */
31
+
32
+ describe('{{STORY_ID}}: {{TITLE}}', () => {
33
+ {{AC_TESTS}}
34
+ });
35
+ `;
36
+
37
+ // Template for individual AC test block (Jest)
38
+ const jestAcTemplate = `
39
+ // {{AC_LABEL}}: {{AC_SUMMARY}}
40
+ describe('{{AC_SUMMARY}}', () => {
41
+ it.skip('should {{THEN_CLAUSE}}', () => {
42
+ // Given: {{GIVEN_CLAUSE}}
43
+ // TODO: Set up test preconditions
44
+
45
+ // When: {{WHEN_CLAUSE}}
46
+ // TODO: Execute the action
47
+
48
+ // Then: {{THEN_CLAUSE}}
49
+ // TODO: Add assertions
50
+ expect(true).toBe(true);
51
+ });
52
+ });
53
+ `;
54
+
55
+ // Template for pytest (Python)
56
+ const pytestTemplate = `"""
57
+ TDD Tests for {{STORY_ID}}: {{TITLE}}
58
+
59
+ Story: docs/06-stories/{{EPIC}}/{{STORY_ID}}-*.md
60
+ Created: {{CREATED}}
61
+
62
+ These tests are generated from acceptance criteria.
63
+ Implementation goal: Make all tests pass.
64
+
65
+ Workflow:
66
+ 1. Review each test case (currently skipped)
67
+ 2. Implement the feature code
68
+ 3. Remove @pytest.mark.skip from tests one at a time
69
+ 4. Run tests until all pass
70
+ """
71
+
72
+ import pytest
73
+
74
+ {{AC_TESTS}}
75
+ `;
76
+
77
+ // Template for individual AC test block (pytest)
78
+ const pytestAcTemplate = `
79
+ # {{AC_LABEL}}: {{AC_SUMMARY}}
80
+ class Test{{AC_CLASS_NAME}}:
81
+ @pytest.mark.skip(reason="TDD: Implement feature first")
82
+ def test_{{TEST_NAME}}(self):
83
+ """
84
+ Given: {{GIVEN_CLAUSE}}
85
+ When: {{WHEN_CLAUSE}}
86
+ Then: {{THEN_CLAUSE}}
87
+ """
88
+ # TODO: Set up test preconditions (Given)
89
+
90
+ # TODO: Execute the action (When)
91
+
92
+ # TODO: Add assertions (Then)
93
+ assert True
94
+ `;
95
+
96
+ // Template for Go tests
97
+ const goTestTemplate = `package {{PACKAGE_NAME}}_test
98
+
99
+ /*
100
+ TDD Tests for {{STORY_ID}}: {{TITLE}}
101
+
102
+ Story: docs/06-stories/{{EPIC}}/{{STORY_ID}}-*.md
103
+ Created: {{CREATED}}
104
+
105
+ These tests are generated from acceptance criteria.
106
+ Implementation goal: Make all tests pass.
107
+ */
108
+
109
+ import (
110
+ "testing"
111
+ )
112
+
113
+ {{AC_TESTS}}
114
+ `;
115
+
116
+ // Template for individual AC test block (Go)
117
+ const goAcTemplate = `
118
+ // {{AC_LABEL}}: {{AC_SUMMARY}}
119
+ func Test{{AC_FUNC_NAME}}(t *testing.T) {
120
+ t.Skip("TDD: Implement feature first")
121
+
122
+ // Given: {{GIVEN_CLAUSE}}
123
+ // TODO: Set up test preconditions
124
+
125
+ // When: {{WHEN_CLAUSE}}
126
+ // TODO: Execute the action
127
+
128
+ // Then: {{THEN_CLAUSE}}
129
+ // TODO: Add assertions
130
+ }
131
+ `;
132
+
133
+ // Export templates for use by story.md command
134
+ module.exports = {
135
+ jest: {
136
+ file: jestTemplate,
137
+ ac: jestAcTemplate,
138
+ extension: '.test.ts',
139
+ directory: '__tests__'
140
+ },
141
+ vitest: {
142
+ file: jestTemplate, // Same format as Jest
143
+ ac: jestAcTemplate,
144
+ extension: '.test.ts',
145
+ directory: '__tests__'
146
+ },
147
+ pytest: {
148
+ file: pytestTemplate,
149
+ ac: pytestAcTemplate,
150
+ extension: '_test.py',
151
+ directory: 'tests'
152
+ },
153
+ go: {
154
+ file: goTestTemplate,
155
+ ac: goAcTemplate,
156
+ extension: '_test.go',
157
+ directory: ''
158
+ },
159
+
160
+ /**
161
+ * Parse acceptance criteria into structured format
162
+ * @param {string} acText - Raw AC text with Given/When/Then
163
+ * @returns {Array} Parsed AC objects
164
+ */
165
+ parseAcceptanceCriteria(acText) {
166
+ const criteria = [];
167
+ const acBlocks = acText.split(/(?=(?:AC\d+|###?\s*AC))/i);
168
+
169
+ for (const block of acBlocks) {
170
+ if (!block.trim()) continue;
171
+
172
+ // Extract label (AC1, AC2, etc.)
173
+ const labelMatch = block.match(/(?:AC\s*)?(\d+)/i);
174
+ const label = labelMatch ? `AC${labelMatch[1]}` : `AC${criteria.length + 1}`;
175
+
176
+ // Extract Given/When/Then
177
+ const givenMatch = block.match(/\*?\*?Given\*?\*?[:\s]+(.+?)(?=\*?\*?When|$)/is);
178
+ const whenMatch = block.match(/\*?\*?When\*?\*?[:\s]+(.+?)(?=\*?\*?Then|$)/is);
179
+ const thenMatch = block.match(/\*?\*?Then\*?\*?[:\s]+(.+?)(?=\*?\*?(?:Given|AC|###)|$)/is);
180
+
181
+ if (givenMatch || whenMatch || thenMatch) {
182
+ criteria.push({
183
+ label,
184
+ given: givenMatch ? givenMatch[1].trim() : 'preconditions are met',
185
+ when: whenMatch ? whenMatch[1].trim() : 'action is performed',
186
+ then: thenMatch ? thenMatch[1].trim() : 'expected result occurs',
187
+ summary: this.generateSummary(givenMatch, whenMatch, thenMatch)
188
+ });
189
+ }
190
+ }
191
+
192
+ // If no structured AC found, create one from the whole text
193
+ if (criteria.length === 0 && acText.trim()) {
194
+ criteria.push({
195
+ label: 'AC1',
196
+ given: 'the feature is implemented',
197
+ when: 'user interacts with it',
198
+ then: 'expected behavior occurs',
199
+ summary: acText.substring(0, 50).trim()
200
+ });
201
+ }
202
+
203
+ return criteria;
204
+ },
205
+
206
+ /**
207
+ * Generate a short summary from Given/When/Then
208
+ */
209
+ generateSummary(givenMatch, whenMatch, thenMatch) {
210
+ if (thenMatch) {
211
+ // Use Then clause, truncated
212
+ return thenMatch[1].trim().substring(0, 50).replace(/[^\w\s]/g, '');
213
+ }
214
+ if (whenMatch) {
215
+ return whenMatch[1].trim().substring(0, 50).replace(/[^\w\s]/g, '');
216
+ }
217
+ return 'acceptance criteria';
218
+ },
219
+
220
+ /**
221
+ * Convert string to valid function/class name
222
+ */
223
+ toIdentifier(str) {
224
+ return str
225
+ .replace(/[^\w\s]/g, '')
226
+ .split(/\s+/)
227
+ .map((word, i) => i === 0 ? word.toLowerCase() : word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
228
+ .join('');
229
+ },
230
+
231
+ /**
232
+ * Convert string to PascalCase for class names
233
+ */
234
+ toPascalCase(str) {
235
+ return str
236
+ .replace(/[^\w\s]/g, '')
237
+ .split(/\s+/)
238
+ .map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
239
+ .join('');
240
+ }
241
+ };