Skip to content

Commit c623d14

Browse files
Perloverclaude
andcommitted
feat(spec-writing): add impact analysis to prevent missing affected code
Problem: When writing specs for refactoring tasks that modify shared constants or types, the current workflow only searches for "reusable" code, not ALL affected code. This caused specs to miss critical areas like duplicate definitions in different packages (e.g., crawler having its own SUPPORTED_LANGUAGES while shared package has another). Solution: Add three layers of impact analysis: 1. write-spec.md - New Step 2.5 "Impact Analysis": - Search for ALL usages of constants/types being modified - Detect duplicate definitions across packages (RED FLAG) - Find hardcoded values that should use constants - Document all affected packages/modules 2. research-spec.md - New impact analysis question: - Ask users about OTHER packages that might be affected - Specifically mention crawler, scripts, config files, tests - Record affected areas for spec-writer to investigate 3. create-tasks-list.md - New Step 1.5 "Verify Spec Completeness": - Independent grep search before creating tasks - Compare grep results with files mentioned in spec - Flag and document any gaps found - Create additional task groups for missing areas This ensures refactoring specs capture ALL code that needs updates, preventing production issues from partially applied changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent a386cf3 commit c623d14

File tree

3 files changed

+139
-8
lines changed

3 files changed

+139
-8
lines changed

profiles/default/workflows/implementation/create-tasks-list.md

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
## Core Responsibilities
44

55
1. **Analyze spec and requirements**: Read and analyze the spec.md and/or requirements.md to inform the tasks list you will create.
6-
2. **Plan task execution order**: Break the requirements into a list of tasks in an order that takes their dependencies into account.
7-
3. **Group tasks by specialization**: Group tasks that require the same skill or stack specialization together (backend, api, ui design, etc.)
8-
4. **Create Tasks list**: Create the markdown tasks list broken into groups with sub-tasks.
6+
2. **Verify spec completeness**: For refactoring tasks, independently verify all affected code is covered in the spec.
7+
3. **Plan task execution order**: Break the requirements into a list of tasks in an order that takes their dependencies into account.
8+
4. **Group tasks by specialization**: Group tasks that require the same skill or stack specialization together (backend, api, ui design, etc.)
9+
5. **Create Tasks list**: Create the markdown tasks list broken into groups with sub-tasks.
910

1011
## Workflow
1112

@@ -17,6 +18,56 @@ Read each of these files (whichever are available) and analyze them to understan
1718

1819
Use your learnings to inform the tasks list and groupings you will create in the next step.
1920

21+
### Step 1.5: Verify Spec Completeness (for refactoring tasks)
22+
23+
**CRITICAL:** Before creating tasks, verify the spec has identified ALL affected code. This prevents missing critical updates that could break the application.
24+
25+
**When to perform verification:**
26+
- The spec involves modifying shared constants, types, or patterns
27+
- The spec involves renaming or changing values used across files
28+
- The spec mentions any kind of refactoring
29+
30+
**How to verify:**
31+
32+
1. **Identify key constants/types from the spec:**
33+
Extract the main constants, types, or patterns being modified from the spec.
34+
35+
2. **Run independent impact verification:**
36+
```bash
37+
# For each constant/type being modified, search entire codebase
38+
grep -r "CONSTANT_NAME" --include="*.ts" --include="*.tsx" --include="*.vue" . | wc -l
39+
40+
# List unique directories with matches
41+
grep -r "CONSTANT_NAME" --include="*.ts" | cut -d':' -f1 | xargs -I{} dirname {} | sort -u
42+
```
43+
44+
3. **Compare against spec:**
45+
- Count files/packages mentioned in spec
46+
- Compare with grep results
47+
- If grep finds MORE files/packages than spec mentions, the spec may be INCOMPLETE
48+
49+
4. **Check for duplicate definitions:**
50+
```bash
51+
# Detect if same constant is defined in multiple places
52+
grep -rn "export const CONSTANT_NAME" --include="*.ts" .
53+
```
54+
If duplicates exist but aren't mentioned in spec, flag this.
55+
56+
5. **If gaps found:**
57+
- Document the missing files/packages discovered
58+
- Create additional task groups to address them
59+
- Include a note in tasks.md about the gaps found
60+
61+
**Example gap documentation in tasks.md:**
62+
```markdown
63+
### Note: Additional Files Discovered
64+
65+
During task creation, impact analysis found the following files not mentioned in spec:
66+
- `packages/server/src/crawler/config.ts` - contains duplicate CONSTANT_NAME definition
67+
- `packages/server/src/scripts/utils.ts` - hardcoded value 'xyz'
68+
69+
These have been added as Task Group X.
70+
```
2071

2172
### Step 2: Create Tasks Breakdown
2273

@@ -188,6 +239,8 @@ Recommended implementation sequence:
188239
## Important Constraints
189240

190241
- **Create tasks that are specific and verifiable**
242+
- **Verify spec completeness for refactoring tasks:** Run independent grep searches to find all affected files, not just those mentioned in spec
243+
- **Flag gaps discovered:** If your impact analysis finds files not in the spec, document them and create task groups to address them
191244
- **Group related tasks:** For example, group back-end engineering tasks together and front-end UI tasks together.
192245
- **Limit test writing during development**:
193246
- Each task group (1-3) should write 2-8 focused tests maximum

profiles/default/workflows/specification/research-spec.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,20 @@ Are there existing features in your codebase with similar patterns we should ref
7474
7575
Please provide file/folder paths or names of these features if they exist.
7676
77+
**Impact Analysis (for refactoring/modification tasks):**
78+
If this feature involves changing existing constants, types, or shared code, I need to identify ALL affected areas to avoid missing critical updates:
79+
80+
- Are there any OTHER packages or modules that define or use the same constants/types?
81+
- Are there any hardcoded values in the codebase that should be updated?
82+
- Which areas beyond the obvious ones might be affected?
83+
- Backend services?
84+
- Crawler/background jobs?
85+
- Scripts and utilities?
86+
- Configuration files?
87+
- Tests?
88+
89+
Please list any areas you know use the affected constants/types that I should investigate.
90+
7791
**Visual Assets Request:**
7892
Do you have any design mockups, wireframes, or screenshots that could help guide the development?
7993
@@ -182,6 +196,17 @@ Use the following structure and do not deviate from this structure when writing
182196
[If user provided no similar features]
183197
No similar existing features identified for reference.
184198

199+
### Impact Analysis
200+
[Based on user's response about affected areas - CRITICAL for refactoring tasks]
201+
202+
**Affected Areas Identified by User:**
203+
- Package/Module: [Name] - Reason: [why it's affected]
204+
- Hardcoded values: [locations mentioned by user]
205+
- Additional areas: [crawler, scripts, config files, etc.]
206+
207+
[If user provided no impact information OR this is a new feature (not refactoring)]
208+
No additional impact areas identified. Note: spec-writer should still perform independent impact analysis.
209+
185210
### Follow-up Questions
186211
[If any were asked]
187212

@@ -251,12 +276,15 @@ Ready for specification creation.
251276
## Important Constraints
252277

253278
- **MANDATORY**: Always run bash command to check visuals folder after receiving user answers
279+
- **MANDATORY**: Always ask about impact analysis for refactoring tasks - which other areas use the same constants/types
254280
- DO NOT write technical specifications for development. Just record your findings from information gathering to this single file: `[spec-path]/planning/requirements.md`.
255281
- Visual check is based on actual file(s) found via bash, NOT user statements
256282
- Check filenames for low-fidelity indicators and clarify design intent if found
257283
- Ask about existing similar features to promote code reuse
284+
- Ask about affected areas beyond obvious ones (crawler, scripts, config files, tests)
258285
- Keep follow-ups minimal (1-3 questions max)
259286
- Save user's exact answers, not interpretations
260287
- Document all visual findings including fidelity level
261288
- Document paths to similar features for spec-writer to reference
289+
- Document all affected areas mentioned by user for spec-writer's impact analysis
262290
- OUTPUT questions and STOP to wait for orchestrator to relay responses

profiles/default/workflows/specification/write-spec.md

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
1. **Analyze Requirements**: Load and analyze requirements and visual assets thoroughly
66
2. **Search for Reusable Code**: Find reusable components and patterns in existing codebase
7-
3. **Create Specification**: Write comprehensive specification document
7+
3. **Impact Analysis**: Find ALL code affected by this change (critical for refactoring)
8+
4. **Create Specification**: Write comprehensive specification document
89

910
## Workflow
1011

@@ -44,6 +45,53 @@ Use appropriate search tools and commands for the project's technology stack to
4445

4546
Document your findings for use in the specification.
4647

48+
### Step 2.5: Impact Analysis - Find All Affected Code
49+
50+
**CRITICAL:** Before creating the specification, perform comprehensive impact analysis to find ALL code that will be affected by this change. This is especially important for refactoring tasks that modify shared constants, types, or patterns.
51+
52+
**When to perform impact analysis:**
53+
- Modifying shared constants or type definitions
54+
- Renaming or changing values used across multiple files
55+
- Refactoring code that may have duplicates in different packages
56+
- Changing APIs, database schemas, or configuration formats
57+
58+
**How to perform impact analysis:**
59+
60+
1. **Search for constant/type usages:**
61+
```bash
62+
# Find all files using the constants/types being modified
63+
grep -r "CONSTANT_NAME" --include="*.ts" --include="*.tsx" --include="*.vue" .
64+
grep -r "TypeName" --include="*.ts" --include="*.tsx" .
65+
```
66+
67+
2. **Check for duplicate definitions:**
68+
```bash
69+
# Detect if the same constant is defined in multiple places (this is a RED FLAG)
70+
grep -rn "export const CONSTANT_NAME" --include="*.ts" .
71+
grep -rn "export type TypeName" --include="*.ts" .
72+
```
73+
If duplicates are found, they MUST be consolidated in the spec.
74+
75+
3. **Find hardcoded values:**
76+
```bash
77+
# Search for hardcoded values that should use the constant
78+
grep -rn "'literal_value'" --include="*.ts" --include="*.tsx" --include="*.vue" .
79+
```
80+
81+
4. **Identify all packages/modules affected:**
82+
```bash
83+
# List unique directories with matches
84+
grep -r "CONSTANT_NAME" --include="*.ts" | cut -d':' -f1 | xargs -I{} dirname {} | sort -u
85+
```
86+
87+
**Document your findings:**
88+
- Total files affected (count)
89+
- Duplicate definitions found (these MUST be listed for consolidation)
90+
- Hardcoded values found (these MUST be listed for refactoring)
91+
- All packages/modules requiring updates
92+
93+
**Include in specification:** Add a "Files Requiring Modification" section OR expand "Existing Code to Leverage" to include all affected files, not just reusable ones.
94+
4795
### Step 3: Create Core Specification
4896

4997
Write the main specification to `agent-os/specs/[current-spec]/spec.md`.
@@ -93,7 +141,9 @@ Follow this structure exactly when creating the content of `spec.md`:
93141
## Important Constraints
94142

95143
1. **Always search for reusable code** before specifying new components
96-
2. **Reference visual assets** when available
97-
3. **Do NOT write actual code** in the spec
98-
4. **Keep each section short**, with clear, direct, skimmable specifications
99-
5. **Do NOT deviate from the template above** and do not add additional sections
144+
2. **Always perform impact analysis** for refactoring tasks - find ALL affected files, not just similar ones
145+
3. **Check for duplicate definitions** - if the same constant/type exists in multiple packages, flag it for consolidation
146+
4. **Reference visual assets** when available
147+
5. **Do NOT write actual code** in the spec
148+
6. **Keep each section short**, with clear, direct, skimmable specifications
149+
7. **Do NOT deviate from the template above** and do not add additional sections

0 commit comments

Comments
 (0)