Skip to content

Commit 6efe3ba

Browse files
authored
Merge pull request #161 from helpfulengineering/phase-2
Phase 2
2 parents c9afed2 + e0b7ef1 commit 6efe3ba

159 files changed

Lines changed: 10663 additions & 1155 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.cursorrules

Lines changed: 332 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,332 @@
1+
# Cursor Rules - Unified Repository Map Strategy
2+
3+
## Repository Context
4+
5+
**CRITICAL WORKFLOW: Use the Right Section for the Right Question**
6+
7+
This repository has a unified repository map (`.repo-map.md`) containing two complementary sections. Use them strategically based on question type:
8+
9+
### Available Repository Map
10+
11+
**`.repo-map.md`** - Unified repository map containing:
12+
13+
1. **Aider-style section** (first section)
14+
- **Format**: Hierarchical tree structure organized by file location
15+
- **Best for**: Location questions, file structure, "where does X live?"
16+
- **Shows**: File paths, directory structure, classes organized by file
17+
- **Look for**: Section header "REPOSITORY MAP (Aider Style)"
18+
19+
2. **Sourcegraph-style section** (second section)
20+
- **Format**: Categorized by component role (Services, Models, Utilities, etc.)
21+
- **Best for**: Relationship questions, APIs, dependencies, "what services exist?"
22+
- **Shows**: Exports, imports, docstrings, public APIs, component relationships
23+
- **Look for**: Section header "Repository Code Intelligence Map (Sourcegraph Style)"
24+
25+
### Step 1: Identify Question Type and Select Section(s)
26+
27+
**Use Aider-style section (first section of `.repo-map.md`) when the user asks:**
28+
- ✅ **"Where should I add [component]?"** → Location/structure question
29+
- ✅ **"Where does [functionality] live?"** → File location question
30+
- ✅ **"Show me the structure of [directory]..."** → Hierarchical structure question
31+
- ✅ **"What files exist in [directory]?"** → File listing question
32+
33+
**Use Sourcegraph-style section (second section of `.repo-map.md`) when the user asks:**
34+
- ✅ **"What [services/utilities/models] exist?"** → Component discovery question
35+
- ✅ **"What's the public API of [service]?"** → API/interface question
36+
- ✅ **"What depends on [component]?"** → Dependency question
37+
- ✅ **"What patterns do [services/models] follow?"** → Pattern/relationship question
38+
- ✅ **"How do [component A] and [component B] relate?"** → Relationship question
39+
40+
**Use BOTH sections when:**
41+
- ✅ **"What [utilities/services] exist and where are they?"** → Comprehensive discovery
42+
- ✅ **"I need to add a new [service/model] - what exists and where should it go?"** → Full context needed
43+
44+
**Skip maps when:**
45+
- ❌ **"How does [specific function] work?"** → Implementation detail, use direct search
46+
- ❌ **"Fix this bug in [file]..."** → Specific file issue, use direct search
47+
48+
### Step 2: Execute Repository Map Workflow
49+
50+
**For Aider-style questions (location/structure):**
51+
52+
1. **FIRST**: Read `.repo-map.md` using `read_file`, focusing on the Aider-style section (first section)
53+
2. **THEN**: Use `codebase_search` or `grep` for specific implementation details
54+
3. **FINALLY**: Cross-reference with actual code files
55+
56+
**For Sourcegraph-style questions (relationships/APIs):**
57+
58+
1. **FIRST**: Read `.repo-map.md` using `read_file`, focusing on the Sourcegraph-style section (second section) and relevant categories (Services, Models, Utilities, etc.)
59+
2. **THEN**: Use `codebase_search` or `grep` for specific implementation details
60+
3. **FINALLY**: Cross-reference with actual code files
61+
62+
**For comprehensive questions (use both sections):**
63+
64+
1. **FIRST**: Read `.repo-map.md` Sourcegraph-style section to understand what exists (component discovery)
65+
2. **SECOND**: Read `.repo-map.md` Aider-style section to understand where things are located (file structure)
66+
3. **THEN**: Use `codebase_search` or `grep` for specific implementation details
67+
4. **FINALLY**: Cross-reference with actual code files
68+
69+
**Why this unified dual-section approach matters:**
70+
- Aider section: Fast location discovery, prevents missing files
71+
- Sourcegraph section: Fast component discovery, prevents missing utilities/services
72+
- Together: Complete understanding of both structure and relationships
73+
- Single file: Easier to maintain and keep in sync
74+
- Ensures architectural consistency and reduces duplicate code
75+
76+
### Code Organization Rules
77+
78+
1. **Check the appropriate section(s) first** - Use Aider section for location questions, Sourcegraph section for component/API questions
79+
2. **Follow existing patterns** - Both sections show how similar components are organized; maintain consistency
80+
3. **Understand relationships** - Use Sourcegraph section to understand dependencies and public APIs before modifying code
81+
4. **Avoid duplication** - Use Sourcegraph section to find existing utilities/services before creating new ones
82+
5. **Respect file structure** - Use Aider section to ensure new code goes in the correct location
83+
84+
### Keeping Map Updated
85+
86+
**The repository map should be regenerated when:**
87+
- Adding or removing Python files
88+
- Creating new services, models, or utilities
89+
- Changing public APIs or exports
90+
- Restructuring directories
91+
92+
**To regenerate the unified map:**
93+
```bash
94+
python scripts/generate_repo_map.py
95+
```
96+
97+
**Note:** The map is automatically regenerated by pre-commit hooks (if configured).
98+
99+
### Quick Reference: Section Selection Examples
100+
101+
**Example 1: "Where should I add a new service for handling component validation?"**
102+
- ✅ Use: **Aider section** of `.repo-map.md` (location question)
103+
- Look for: `src/core/services/` structure in Aider section
104+
- Then check: Sourcegraph section "Services" category to see existing service patterns
105+
106+
**Example 2: "What storage-related utilities already exist? I need to cache API responses."**
107+
- ✅ Use: **Sourcegraph section** of `.repo-map.md` (component discovery question)
108+
- Look for: "Services" category → `cache_service.py`, "Utilities" category
109+
- Then check: Aider section to find exact file locations
110+
111+
**Example 3: "I want to add a new CLI command for exporting data. Where does it go and what existing patterns should I follow?"**
112+
- ✅ Use: **BOTH sections** of `.repo-map.md` (comprehensive question)
113+
- Sourcegraph section: "Entry Points" category → `src/cli/main.py` to see CLI structure
114+
- Aider section: `src/cli/` directory structure to find where commands live
115+
- Sourcegraph section: "Utilities" or relevant category to see export patterns
116+
117+
**Example 4: "What's the public API of the cache service?"**
118+
- ✅ Use: **Sourcegraph section** of `.repo-map.md` (API question)
119+
- Look for: "Services" category → `cache_service.py` → **Exports** and **Methods**
120+
121+
**Example 5: "Show me the structure of the generation engine"**
122+
- ✅ Use: **Aider section** of `.repo-map.md` (structure question)
123+
- Look for: `src/core/generation/` tree structure
124+
125+
## Development Philosophy: Incremental, Testable Development
126+
127+
**PRIMARY RULE: Always prefer small, incremental changes over large, sweeping modifications.**
128+
129+
### Change Management Principles
130+
131+
1. **Incremental Development**
132+
- Make the smallest possible change that moves toward the goal
133+
- Each change should be independently testable and verifiable
134+
- Break large features into multiple small, focused changes
135+
- Never refactor multiple components simultaneously unless absolutely necessary
136+
137+
2. **Test-First Approach**
138+
- Write or update tests before implementing changes
139+
- Ensure each change can be validated with existing or new tests
140+
- If tests don't exist, create minimal tests to verify the change works
141+
- Run tests after each small change to catch issues early
142+
143+
3. **Scope Limitation**
144+
- Focus on ONE specific problem or feature at a time
145+
- Avoid "while we're at it" changes that expand scope
146+
- Resist the urge to optimize or refactor unrelated code
147+
- Clearly define the boundaries of each change
148+
149+
### Code Change Guidelines
150+
151+
#### Before Making Changes
152+
- [ ] Understand the current state of the code (use repository maps if needed)
153+
- [ ] Identify the minimal change needed
154+
- [ ] Plan the smallest possible implementation
155+
- [ ] Consider what tests need to be written/updated
156+
157+
#### During Implementation
158+
- [ ] Make ONE focused change at a time
159+
- [ ] Test the change immediately after implementation
160+
- [ ] Fix any issues before proceeding to the next change
161+
- [ ] Document any assumptions or limitations
162+
163+
#### After Each Change
164+
- [ ] Verify the change works as expected
165+
- [ ] Run relevant tests
166+
- [ ] Check for any unintended side effects
167+
- [ ] Commit the change if it's working correctly
168+
169+
### Prohibited Practices
170+
171+
**DO NOT:**
172+
- Make changes to multiple files simultaneously unless they're directly related
173+
- Refactor code that isn't part of the current task
174+
- Add new features while fixing bugs
175+
- Optimize performance unless specifically requested
176+
- Change code style/formatting unless it's the primary task
177+
- Remove "unused" code without explicit confirmation
178+
- Add dependencies without clear justification
179+
180+
### Communication Guidelines
181+
182+
#### When Proposing Changes
183+
- Clearly explain what the change does
184+
- Specify why this particular approach was chosen
185+
- Mention any assumptions or limitations
186+
- Suggest the next small step if the change is part of a larger goal
187+
188+
#### When Uncertain
189+
- Ask for clarification rather than making assumptions
190+
- Propose the smallest possible change and ask for feedback
191+
- Suggest breaking down complex requests into smaller steps
192+
- Offer alternatives if the requested change seems too broad
193+
194+
### Example Workflow
195+
196+
**Instead of:** "I'll refactor the entire authentication system and add new features"
197+
198+
**Do this:**
199+
1. "I'll add a single test for the current authentication behavior"
200+
2. "I'll make one small change to fix the specific bug"
201+
3. "I'll verify the fix works with the test"
202+
4. "I'll commit this change and move to the next small step"
203+
204+
### File-Specific Guidelines
205+
206+
#### For New Features
207+
- Start with a failing test
208+
- Implement the minimal code to make the test pass
209+
- Add one small piece of functionality at a time
210+
- Test each addition before moving to the next
211+
212+
#### For Bug Fixes
213+
- Reproduce the bug with a test
214+
- Make the smallest possible change to fix it
215+
- Verify the fix works and doesn't break existing functionality
216+
- Add regression tests if appropriate
217+
218+
#### For Refactoring
219+
- Ensure comprehensive test coverage exists first
220+
- Refactor one small piece at a time
221+
- Run tests after each small change
222+
- Never refactor and add features simultaneously
223+
224+
### Temporary Test File Management
225+
226+
#### Creating Temporary Tests
227+
- Use descriptive names for temporary test files (e.g., `test_temp_feature_xyz.py`, `temp_validation_abc.js`)
228+
- Clearly mark temporary files with comments indicating their purpose and expected cleanup
229+
- Keep temporary tests focused on the specific change being implemented
230+
- Document what the temporary test is validating
231+
232+
#### Cleanup Protocol
233+
**Temporary test files should be cleaned up when:**
234+
1. ✅ All tests are passing consistently
235+
2. ✅ The changes they were testing are working correctly
236+
3. ✅ The user explicitly agrees to cleanup
237+
4. ✅ The functionality is properly covered by existing or permanent tests
238+
239+
#### Cleanup Process
240+
1. **Before cleanup, verify:**
241+
- All temporary tests are passing
242+
- The implemented changes work as expected
243+
- No regressions have been introduced
244+
- Permanent test coverage exists for the functionality
245+
246+
2. **Request cleanup approval:**
247+
- List the temporary files to be removed
248+
- Confirm what functionality they were testing
249+
- Ask for explicit user approval before deletion
250+
251+
3. **Clean up systematically:**
252+
- Remove temporary test files one at a time
253+
- Run tests after each removal to ensure nothing breaks
254+
- Confirm the workspace is clean and functional
255+
256+
#### Temporary File Naming Convention
257+
- Use prefix: `temp_` or `test_temp_`
258+
- Include purpose: `temp_validation_`, `temp_integration_`, `temp_unit_`
259+
- Add feature identifier: `temp_auth_bug_fix`, `temp_api_endpoint_test`
260+
- Example: `temp_validation_user_registration.py`
261+
262+
#### When NOT to Clean Up
263+
- If tests are still failing and debugging is ongoing
264+
- If the user hasn't explicitly approved cleanup
265+
- If the temporary tests reveal issues that need further investigation
266+
- If permanent test coverage is insufficient
267+
268+
### Success Metrics
269+
270+
A good change should be:
271+
- ✅ **Focused**: Addresses one specific issue
272+
- ✅ **Testable**: Can be verified with automated tests
273+
- ✅ **Reversible**: Can be easily undone if needed
274+
- ✅ **Incremental**: Builds on previous working state
275+
- ✅ **Documented**: Clear purpose and scope
276+
277+
### Emergency Override
278+
279+
If a large change is truly necessary:
280+
1. Explicitly acknowledge this violates the incremental principle
281+
2. Explain why incremental changes aren't feasible
282+
3. Break the large change into the smallest possible phases
283+
4. Ensure comprehensive testing at each phase
284+
5. Get explicit approval before proceeding
285+
286+
---
287+
288+
**Remember: It's better to make 10 small, working changes than 1 large change that requires 10 bug fixes.**
289+
290+
## Development Environment
291+
292+
### Conda Environment
293+
294+
**CRITICAL: This project uses a conda environment named "supply-graph-ai".**
295+
296+
- **Environment Name**: `supply-graph-ai`
297+
- **Always activate this environment** before running any Python commands, tests, or scripts
298+
- **When executing Python code**, ensure the conda environment is active
299+
- **When installing dependencies**, use: `conda activate supply-graph-ai && pip install ...`
300+
- **When running tests**, use: `conda activate supply-graph-ai && pytest ...`
301+
- **When running scripts**, use: `conda activate supply-graph-ai && python ...`
302+
303+
**Activation Command:**
304+
```bash
305+
conda activate supply-graph-ai
306+
```
307+
308+
**Verification:**
309+
Before executing any Python-related commands, verify the environment is active:
310+
```bash
311+
conda info --envs # Should show supply-graph-ai with *
312+
# or
313+
which python # Should point to conda environment
314+
```
315+
316+
**Important Notes:**
317+
- Never assume a different Python environment is active
318+
- Always explicitly activate the conda environment in commands
319+
- If the environment doesn't exist, create it: `conda create -n supply-graph-ai python=3.12`
320+
- Dependencies are managed via `requirements.txt` and `requirements-dev.txt`
321+
322+
## Project Structure (from maps)
323+
324+
The repository follows this structure:
325+
- `src/cli/` - CLI commands and interface
326+
- `src/config/` - Configuration and settings
327+
- `src/core/generation/` - Core BOM generation logic
328+
- `src/core/services/` - Business logic services
329+
- `src/core/storage/` - Data storage and management
330+
- `src/core/models/` - Data models
331+
332+
When creating new code, place it in the appropriate directory according to this structure.

0 commit comments

Comments
 (0)