@mind-fold/open-flow 0.1.17 → 0.2.2

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 (40) hide show
  1. package/dist/configurators/templates.d.ts.map +1 -1
  2. package/dist/configurators/templates.js +17 -6
  3. package/dist/configurators/templates.js.map +1 -1
  4. package/dist/configurators/workflow.d.ts.map +1 -1
  5. package/dist/configurators/workflow.js +82 -6
  6. package/dist/configurators/workflow.js.map +1 -1
  7. package/dist/templates/commands/break-loop.txt +107 -0
  8. package/dist/templates/commands/check-cross-layer.txt +153 -0
  9. package/dist/templates/commands/finish-work.txt +129 -0
  10. package/dist/templates/commands/index.d.ts +9 -5
  11. package/dist/templates/commands/index.d.ts.map +1 -1
  12. package/dist/templates/commands/index.js +16 -5
  13. package/dist/templates/commands/index.js.map +1 -1
  14. package/dist/templates/commands/init-agent.txt +100 -9
  15. package/dist/templates/commands/sync-from-runtime.txt +140 -0
  16. package/dist/templates/markdown/flow.md.txt +96 -84
  17. package/dist/templates/markdown/index.d.ts +21 -4
  18. package/dist/templates/markdown/index.d.ts.map +1 -1
  19. package/dist/templates/markdown/index.js +27 -4
  20. package/dist/templates/markdown/index.js.map +1 -1
  21. package/dist/templates/markdown/structure/backend/database-guidelines.md.txt +247 -0
  22. package/dist/templates/markdown/structure/backend/directory-structure.md.txt +153 -0
  23. package/dist/templates/markdown/structure/backend/error-handling.md.txt +257 -0
  24. package/dist/templates/markdown/structure/backend/index.md.txt +88 -0
  25. package/dist/templates/markdown/structure/backend/logging-guidelines.md.txt +212 -0
  26. package/dist/templates/markdown/structure/backend/quality-guidelines.md.txt +219 -0
  27. package/dist/templates/markdown/structure/backend/type-safety.md.txt +192 -0
  28. package/dist/templates/markdown/structure/flows/code-reuse-thinking-guide.md.txt +343 -0
  29. package/dist/templates/markdown/structure/flows/cross-layer-thinking-guide.md.txt +283 -0
  30. package/dist/templates/markdown/structure/flows/index.md.txt +133 -0
  31. package/dist/templates/markdown/structure/flows/pre-implementation-checklist.md.txt +182 -0
  32. package/dist/templates/markdown/structure/flows/spec-flow-template.md.txt +145 -0
  33. package/dist/templates/markdown/structure/frontend/component-guidelines.md.txt +335 -0
  34. package/dist/templates/markdown/structure/frontend/directory-structure.md.txt +172 -0
  35. package/dist/templates/markdown/structure/frontend/hook-guidelines.md.txt +287 -0
  36. package/dist/templates/markdown/structure/frontend/index.md.txt +91 -0
  37. package/dist/templates/markdown/structure/frontend/quality-guidelines.md.txt +274 -0
  38. package/dist/templates/markdown/structure/frontend/state-management.md.txt +293 -0
  39. package/dist/templates/markdown/structure/frontend/type-safety.md.txt +275 -0
  40. package/package.json +2 -2
@@ -0,0 +1,133 @@
1
+ # Cross-Layer Flow Specifications
2
+
3
+ > **Purpose**: Document data flows that span multiple layers and thinking guides to prevent common bugs.
4
+
5
+ ---
6
+
7
+ ## Why This Directory?
8
+
9
+ Most bugs happen at **layer boundaries**, not within layers. This directory provides:
10
+
11
+ 1. **Thinking guides** - Checklists to prevent bugs before they happen
12
+ 2. **Flow specs** - Documentation of cross-layer data flows
13
+ 3. **Templates** - For creating new flow documentation
14
+
15
+ ---
16
+
17
+ ## How to Use This Directory
18
+
19
+ ```
20
+ Before writing ANY code
21
+
22
+ ├─ Read: Pre-Implementation Checklist
23
+ │ └─ "Will this constant be used elsewhere?"
24
+ │ └─ "Does this pattern already exist?"
25
+
26
+ ├─ If feature spans 3+ layers
27
+ │ └─ Read: Cross-Layer Thinking Guide
28
+ │ └─ Consider creating a Flow Spec
29
+
30
+ └─ During/After implementation
31
+ └─ Reference: Code Reuse Thinking Guide
32
+ └─ Run: /check-cross-layer command
33
+ ```
34
+
35
+ ---
36
+
37
+ ## Guides
38
+
39
+ ### Pre-Implementation (Read First!)
40
+
41
+ | Document | Purpose | When to Read |
42
+ |----------|---------|--------------|
43
+ | [Pre-Implementation Checklist](./pre-implementation-checklist.md) | **Start here!** Questions before coding | Before writing ANY code |
44
+
45
+ ### During Implementation
46
+
47
+ | Document | Purpose | When to Read |
48
+ |----------|---------|--------------|
49
+ | [Cross-Layer Thinking Guide](./cross-layer-thinking-guide.md) | Data flow across layers | Complex features spanning 3+ layers |
50
+ | [Code Reuse Thinking Guide](./code-reuse-thinking-guide.md) | Pattern recognition, abstraction | When implementing logic/components |
51
+ | [Flow Spec Template](./spec-flow-template.md) | Template for new flow docs | When documenting a new flow |
52
+
53
+ ---
54
+
55
+ ## When to Create a Flow Spec
56
+
57
+ Create a flow spec when a feature:
58
+
59
+ - [ ] Spans 3+ layers (e.g., API → Service → Component → Hook)
60
+ - [ ] Has transformation points where data format changes
61
+ - [ ] Has multiple consumers with different requirements
62
+ - [ ] Involves state that passes through multiple components
63
+ - [ ] Has caused bugs due to missing data or wrong format
64
+
65
+ ---
66
+
67
+ ## Quick Reference: Common Cross-Layer Patterns
68
+
69
+ ### Pattern 1: API → Service → Component
70
+
71
+ ```
72
+ API Route # Validate input, call service
73
+
74
+
75
+ Service Layer # Business logic, database
76
+
77
+
78
+ Response # Format for client
79
+
80
+
81
+ React Query Hook # Cache, loading states
82
+
83
+
84
+ Component # Render UI
85
+ ```
86
+
87
+ **Common Mistake**: Service returns different format than hook expects.
88
+
89
+ ### Pattern 2: User Action → State → API → Refetch
90
+
91
+ ```
92
+ User clicks button # UI Layer
93
+
94
+
95
+ Call mutation hook # React Query mutation
96
+
97
+
98
+ API Request # POST/PATCH/DELETE
99
+
100
+
101
+ Invalidate queries # Trigger refetch
102
+
103
+
104
+ UI updates # New data rendered
105
+ ```
106
+
107
+ **Common Mistake**: Forgetting to invalidate related queries.
108
+
109
+ ---
110
+
111
+ ## Triggers for Using These Guides
112
+
113
+ | Trigger | Action |
114
+ |---------|--------|
115
+ | About to write any code | Read Pre-Implementation Checklist |
116
+ | Feature spans 3+ layers | Read Cross-Layer Thinking Guide |
117
+ | Creating a new utility/constant | Check Code Reuse Guide |
118
+ | Just finished batch modifications | Run /check-cross-layer |
119
+ | Feels like you've seen similar code | **STOP** and search first |
120
+
121
+ ---
122
+
123
+ ## Integration with Commands
124
+
125
+ | Command | Purpose | Timing |
126
+ |---------|---------|--------|
127
+ | `/check-cross-layer` | Verify changes after implementation | After coding |
128
+ | `/finish-work` | Pre-commit checklist | Before commit |
129
+ | `/break-loop` | Post-debug analysis | After fixing bugs |
130
+
131
+ ---
132
+
133
+ **Language**: All documentation must be written in **English**.
@@ -0,0 +1,182 @@
1
+ # Pre-Implementation Checklist
2
+
3
+ > **Purpose**: Ask the right questions **before** writing code to avoid common architectural mistakes.
4
+
5
+ ---
6
+
7
+ ## Why This Checklist?
8
+
9
+ Most code quality issues aren't caught during implementation—they're **designed in** from the start:
10
+
11
+ | Problem | Root Cause | Cost |
12
+ |---------|------------|------|
13
+ | Constants duplicated across 5 files | Didn't ask "will this be used elsewhere?" | Refactoring + testing |
14
+ | Same logic repeated in multiple hooks | Didn't ask "does this pattern exist?" | Creating abstraction later |
15
+ | Cross-layer type mismatches | Didn't ask "who else consumes this?" | Debugging + fixing |
16
+
17
+ **This checklist catches these issues before they become code.**
18
+
19
+ ---
20
+
21
+ ## The Checklist
22
+
23
+ ### 1. Constants & Configuration
24
+
25
+ Before adding any constant or config value:
26
+
27
+ - [ ] **Cross-layer usage?** Will this value be used in both frontend and backend?
28
+ - If yes → Put in shared constants file
29
+ - Example: Batch size used by backend sync AND frontend threshold check
30
+
31
+ - [ ] **Multiple consumers?** Will this value be used in 2+ files within the same layer?
32
+ - If yes → Put in a shared constants file for that layer
33
+ - Example: Don't define `DEBOUNCE_MS = 2000` in each hook file
34
+
35
+ - [ ] **Magic number?** Is this a hardcoded value that could change?
36
+ - If yes → Extract to named constant with comment explaining why
37
+ - Example: `BATCH_SIZE: 15 // API limit constraint`
38
+
39
+ ### 2. Logic & Patterns
40
+
41
+ Before implementing any logic:
42
+
43
+ - [ ] **Pattern exists?** Search for similar patterns in the codebase first
44
+ ```bash
45
+ # Example: Before implementing debounced sync
46
+ grep -r "setTimeout.*sync" src/
47
+ grep -r "debounce" src/
48
+ ```
49
+
50
+ - [ ] **Will repeat?** Will this exact logic be needed in 2+ places?
51
+ - If yes → Create a shared hook/utility **first**, then use it
52
+ - Don't copy-paste and plan to refactor later
53
+
54
+ - [ ] **Callback pattern?** Does the logic need optional callbacks (onStart, onComplete, onError)?
55
+ - If yes → Design the abstraction with callback support from the start
56
+
57
+ ### 3. Types & Interfaces
58
+
59
+ Before defining types:
60
+
61
+ - [ ] **Cross-layer type?** Is this type used across API boundary?
62
+ - If yes → Define in shared types location
63
+ - Never duplicate type definitions between frontend and backend
64
+
65
+ - [ ] **Existing type?** Does a similar type already exist?
66
+ - Search before creating: `grep -r "interface.*YourTypeName" src/`
67
+
68
+ ### 4. UI Components
69
+
70
+ Before creating UI components:
71
+
72
+ - [ ] **Visual-logic consistency?** If there's already a visual distinction (icon, color, label) for a concept, does your logic match?
73
+ - Example: If items show priority icons in a specific order, sorting logic should use the same order
74
+
75
+ - [ ] **State lifecycle?** Will this component unmount during normal user flow?
76
+ - If yes → Consider where state should persist (parent, context, store)
77
+
78
+ ---
79
+
80
+ ## Quick Decision Tree
81
+
82
+ ```
83
+ Adding a value/constant?
84
+ ├── Used in frontend AND backend? → Shared constants
85
+ ├── Used in 2+ files in same layer? → Layer-specific shared constants
86
+ └── Single file only? → Local constant is fine
87
+
88
+ Adding logic/behavior?
89
+ ├── Similar pattern exists? → Extend or reuse existing
90
+ ├── Will be used in 2+ places? → Create shared hook/utility first
91
+ └── Single use only? → Implement directly (but document pattern)
92
+ ```
93
+
94
+ ---
95
+
96
+ ## Anti-Patterns to Avoid
97
+
98
+ ### ❌ Copy-Paste-Modify
99
+
100
+ ```typescript
101
+ // DON'T: Same logic in multiple files
102
+ // file1.ts, file2.ts, file3.ts...
103
+ const DEBOUNCE_MS = 2000;
104
+ const MAX_PENDING = 15;
105
+ const triggerSync = useCallback(() => {
106
+ // 20 lines of identical logic
107
+ }, []);
108
+ ```
109
+
110
+ ### ✅ Shared Abstraction
111
+
112
+ ```typescript
113
+ // DO: Single source of truth
114
+ // useSyncTrigger.ts
115
+ import { SYNC_CONSTANTS } from "@shared/constants";
116
+ export function useSyncTrigger(options) { /* logic once */ }
117
+
118
+ // file1.ts - one line instead of 20+
119
+ const triggerSync = useSyncTrigger({ workspaceId });
120
+ ```
121
+
122
+ ### ❌ Local Constant Aliases
123
+
124
+ ```typescript
125
+ // DON'T: Create local aliases for imported constants
126
+ import { CONSTANTS } from "@shared/constants";
127
+ const DEBOUNCE_MS = CONSTANTS.DEBOUNCE_MS; // Unnecessary!
128
+ ```
129
+
130
+ ### ✅ Direct Usage
131
+
132
+ ```typescript
133
+ // DO: Use imported constants directly
134
+ import { CONSTANTS } from "@shared/constants";
135
+ setTimeout(fn, CONSTANTS.DEBOUNCE_MS);
136
+ ```
137
+
138
+ ---
139
+
140
+ ## When to Use This Checklist
141
+
142
+ | Trigger | Action |
143
+ |---------|--------|
144
+ | About to add a constant | Run through Section 1 |
145
+ | About to implement logic | Run through Section 2 |
146
+ | About to define a type | Run through Section 3 |
147
+ | About to create a component | Run through Section 4 |
148
+ | Feels like you've seen similar code before | **STOP** and search first |
149
+
150
+ ---
151
+
152
+ ## Relationship to Other Guides
153
+
154
+ | Guide | Focus | Timing |
155
+ |-------|-------|--------|
156
+ | **Pre-Implementation Checklist** (this) | Questions before coding | Before writing code |
157
+ | [Code Reuse Thinking Guide](./code-reuse-thinking-guide.md) | Patterns and abstractions | During/after implementation |
158
+ | [Cross-Layer Thinking Guide](./cross-layer-thinking-guide.md) | Data flow across layers | Complex feature planning |
159
+ | `/check-cross-layer` command | Verification check | After implementation (safety net) |
160
+
161
+ **Ideal workflow:**
162
+ 1. Read this checklist before coding
163
+ 2. Reference Code Reuse guide for abstraction patterns
164
+ 3. Run `/check-cross-layer` after implementation as safety net
165
+
166
+ ---
167
+
168
+ ## Lessons Learned
169
+
170
+ | Issue | Lesson |
171
+ |-------|--------|
172
+ | Same constant duplicated in 5+ hooks | Always ask "will this constant be used elsewhere?" before defining |
173
+ | Same logic copied multiple times | If logic will repeat, create abstraction **before** first use |
174
+ | Created local aliases for imported constants | Never create local aliases—use imported constants directly |
175
+
176
+ ---
177
+
178
+ **Core Principle**: 5 minutes of checklist thinking saves 50 minutes of refactoring.
179
+
180
+ ---
181
+
182
+ **Language**: All documentation must be written in **English**.
@@ -0,0 +1,145 @@
1
+ # Flow Spec: [Feature Name]
2
+
3
+ > Template for documenting cross-layer data flows
4
+
5
+ ---
6
+
7
+ ## Overview
8
+
9
+ **Feature**: [Brief description]
10
+ **Layers**: [List layers involved]
11
+ **Last Updated**: [Date]
12
+
13
+ ---
14
+
15
+ ## Data Flow Diagram
16
+
17
+ ```
18
+ [Source]
19
+
20
+
21
+ [Layer 1] ─────────────────────────────┐
22
+ │ │
23
+ │ Data: { field1, field2 } │
24
+ │ Transform: none │
25
+ │ │
26
+ ▼ │
27
+ [Layer 2] ─────────────────────────────┤
28
+ │ │
29
+ │ Data: { field1, field2, extra } │
30
+ │ Transform: add computed field │
31
+ │ │
32
+ ▼ │
33
+ [Layer 3] ─────────────────────────────┘
34
+
35
+
36
+ [Consumer]
37
+ ```
38
+
39
+ ---
40
+
41
+ ## Layer Details
42
+
43
+ ### Layer 1: [Name]
44
+
45
+ **File**: `path/to/file.ts`
46
+
47
+ **Input**:
48
+ ```typescript
49
+ {
50
+ field1: string;
51
+ field2: number;
52
+ }
53
+ ```
54
+
55
+ **Output**:
56
+ ```typescript
57
+ {
58
+ field1: string;
59
+ field2: number;
60
+ }
61
+ ```
62
+
63
+ **Transformation**: None (pass-through)
64
+
65
+ **Error Handling**:
66
+ - Validation errors → 400 response
67
+ - Not found → 404 response
68
+
69
+ ---
70
+
71
+ ### Layer 2: [Name]
72
+
73
+ **File**: `path/to/file.ts`
74
+
75
+ **Input**: Output from Layer 1
76
+
77
+ **Output**:
78
+ ```typescript
79
+ {
80
+ field1: string;
81
+ field2: number;
82
+ computed: string; // Added
83
+ }
84
+ ```
85
+
86
+ **Transformation**:
87
+ - Adds `computed` field based on `field1` and `field2`
88
+
89
+ **Error Handling**:
90
+ - Business logic errors → throw CustomError
91
+
92
+ ---
93
+
94
+ ### Layer 3: [Name]
95
+
96
+ **File**: `path/to/file.ts`
97
+
98
+ **Input**: Output from Layer 2
99
+
100
+ **Output**: Same as input (display only)
101
+
102
+ **Transformation**: None
103
+
104
+ **Error Handling**:
105
+ - Show error message to user
106
+ - Allow retry
107
+
108
+ ---
109
+
110
+ ## Edge Cases
111
+
112
+ | Scenario | Expected Behavior | Layer Handling |
113
+ |----------|-------------------|----------------|
114
+ | Empty data | Show empty state | Component |
115
+ | Network error | Show error + retry | Hook |
116
+ | Validation error | Show field errors | Component |
117
+ | Not found | Redirect to 404 | API |
118
+
119
+ ---
120
+
121
+ ## Testing Checklist
122
+
123
+ - [ ] Happy path: All layers work together
124
+ - [ ] Error at Layer 1: Properly propagates
125
+ - [ ] Error at Layer 2: Properly propagates
126
+ - [ ] Empty data: Handled correctly
127
+ - [ ] Loading state: Displayed correctly
128
+
129
+ ---
130
+
131
+ ## Change Log
132
+
133
+ | Date | Change | Affected Layers |
134
+ |------|--------|-----------------|
135
+ | YYYY-MM-DD | Initial spec | All |
136
+
137
+ ---
138
+
139
+ ## Notes
140
+
141
+ [Any additional context, decisions, or warnings]
142
+
143
+ ---
144
+
145
+ **Language**: All documentation must be written in **English**.