@oleksandr.rudnychenko/sync_loop 0.2.1
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/README.md +124 -0
- package/bin/cli.js +77 -0
- package/package.json +35 -0
- package/src/init.js +365 -0
- package/src/server.js +208 -0
- package/template/.agent-loop/README.md +75 -0
- package/template/.agent-loop/feedback.md +395 -0
- package/template/.agent-loop/glossary.md +113 -0
- package/template/.agent-loop/patterns/api-standards.md +132 -0
- package/template/.agent-loop/patterns/code-patterns.md +300 -0
- package/template/.agent-loop/patterns/refactoring-workflow.md +114 -0
- package/template/.agent-loop/patterns/testing-guide.md +258 -0
- package/template/.agent-loop/patterns.md +256 -0
- package/template/.agent-loop/reasoning-kernel.md +521 -0
- package/template/.agent-loop/validate-env.md +332 -0
- package/template/.agent-loop/validate-n.md +321 -0
- package/template/AGENTS.md +157 -0
- package/template/README.md +144 -0
- package/template/bootstrap-prompt.md +37 -0
- package/template/protocol-summary.md +54 -0
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
# Validate Environment (NFRs)
|
|
2
|
+
|
|
3
|
+
**Fixed Non-Functional Requirements** for solutions, code, and documentation.
|
|
4
|
+
|
|
5
|
+
This is **Stage 1** of the 2-stage validation integrated into the reasoning kernel.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Position in Reasoning Kernel
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
CHALLENGE-TEST (from reasoning-kernel.md):
|
|
13
|
+
│
|
|
14
|
+
├─► [Stage 1] validate-env.md ◄── YOU ARE HERE
|
|
15
|
+
│ │
|
|
16
|
+
│ ├─► Check NFRs (types, tests, layers, complexity, debug)
|
|
17
|
+
│ └─► FAIL? → feedback.md → patch → retry
|
|
18
|
+
│
|
|
19
|
+
└─► [Stage 2] validate-n.md
|
|
20
|
+
└─► Check neighbors (shapes, boundaries, bridges)
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## NFR Categories
|
|
26
|
+
|
|
27
|
+
### Code NFRs
|
|
28
|
+
|
|
29
|
+
| NFR | Requirement | Evidence | Required |
|
|
30
|
+
|-----|-------------|----------|----------|
|
|
31
|
+
| **Type Safety** | All functions typed, no untyped `Any` | Static type checker output | Yes |
|
|
32
|
+
| **Test Coverage** | Critical paths tested | Test runner result | Yes |
|
|
33
|
+
| **Layer Integrity** | No cross-layer imports | Import analysis | Yes |
|
|
34
|
+
| **Complexity** | Files < 500 LOC, functions < 50 LOC | Size/complexity metrics | Warning |
|
|
35
|
+
| **No Debug Code** | No print(), breakpoint(), TODO | Grep/search | Yes |
|
|
36
|
+
|
|
37
|
+
### Solution NFRs
|
|
38
|
+
|
|
39
|
+
| NFR | Requirement | Evidence |
|
|
40
|
+
|-----|-------------|----------|
|
|
41
|
+
| **Minimal Change** | Smallest diff that solves the problem | Review diff size |
|
|
42
|
+
| **No Regressions** | Existing tests must pass | Test runner |
|
|
43
|
+
| **Backward Compatible** | Public APIs unchanged (unless approved) | Shape check |
|
|
44
|
+
| **Idiomatic** | Follows project patterns from patterns.md | Pattern match |
|
|
45
|
+
|
|
46
|
+
### Documentation NFRs
|
|
47
|
+
|
|
48
|
+
| NFR | Requirement | Evidence |
|
|
49
|
+
|-----|-------------|----------|
|
|
50
|
+
| **Docstrings** | Public functions have docstrings | AST/lint check |
|
|
51
|
+
| **Type Hints** | Parameters and returns annotated | Type checker |
|
|
52
|
+
| **Updated Docs** | README/docs reflect changes | Manual review |
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## 2-Stage Validation Pattern
|
|
57
|
+
|
|
58
|
+
Each NFR check follows this pattern:
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
62
|
+
│ NFR VALIDATION │
|
|
63
|
+
├─────────────────────────────────────────────────────────────┤
|
|
64
|
+
│ │
|
|
65
|
+
│ STAGE 1: CHECK │
|
|
66
|
+
│ ─────────────── │
|
|
67
|
+
│ Run gate command → Collect results │
|
|
68
|
+
│ │
|
|
69
|
+
│ STAGE 2: FEEDBACK (if failed) │
|
|
70
|
+
│ ───────────────────────────── │
|
|
71
|
+
│ Diagnose error → Generate patch → Apply fix → Retry │
|
|
72
|
+
│ │
|
|
73
|
+
└─────────────────────────────────────────────────────────────┘
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## Gate Execution Order
|
|
79
|
+
|
|
80
|
+
1. Run gates in defined order (Type Safety → Tests → Layers → Complexity → Debug)
|
|
81
|
+
2. Stop at first failure
|
|
82
|
+
3. Route to [feedback.md](feedback.md) for diagnosis
|
|
83
|
+
4. Patch minimally at root cause
|
|
84
|
+
5. Retry the same failing gate
|
|
85
|
+
6. Continue only after pass
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## Per-Gate Execution Patterns
|
|
90
|
+
|
|
91
|
+
### Gate 1: Type Safety
|
|
92
|
+
|
|
93
|
+
**Failure class:** Micro (if error on new code only) / Macro (if existing signatures affected)
|
|
94
|
+
|
|
95
|
+
Run static type checker for the project.
|
|
96
|
+
|
|
97
|
+
**Commands:**
|
|
98
|
+
```bash
|
|
99
|
+
# {Fill in with project type check command}
|
|
100
|
+
{typecheck command}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
**2-Stage Pattern:**
|
|
104
|
+
```
|
|
105
|
+
STAGE 1 — CHECK:
|
|
106
|
+
Run type checker → Collect errors
|
|
107
|
+
|
|
108
|
+
STAGE 2 — FEEDBACK (if failed):
|
|
109
|
+
├─► Parse error: e.g. "Missing return type annotation"
|
|
110
|
+
├─► Generate patch: Add return type based on body analysis
|
|
111
|
+
├─► Apply fix
|
|
112
|
+
└─► Retry STAGE 1
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**Auto-fixable:** Missing return types (obvious), simple type narrowing
|
|
116
|
+
**Not auto-fixable:** Complex generics, protocol violations
|
|
117
|
+
|
|
118
|
+
### Gate 2: Test Coverage
|
|
119
|
+
|
|
120
|
+
**Failure class:** Macro (always — test failures require root cause diagnosis)
|
|
121
|
+
|
|
122
|
+
Run the project test suite.
|
|
123
|
+
|
|
124
|
+
**Commands:**
|
|
125
|
+
```bash
|
|
126
|
+
# {Fill in with project test commands}
|
|
127
|
+
{test command}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
**2-Stage Pattern:**
|
|
131
|
+
```
|
|
132
|
+
STAGE 1 — CHECK:
|
|
133
|
+
Run test suite → Collect failures
|
|
134
|
+
|
|
135
|
+
STAGE 2 — FEEDBACK (if failed):
|
|
136
|
+
├─► Identify failing test
|
|
137
|
+
├─► Analyze root cause in SOURCE (never modify test)
|
|
138
|
+
├─► Generate fix for source code
|
|
139
|
+
└─► Retry STAGE 1
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
**Rule:** Never modify tests to make them pass.
|
|
143
|
+
|
|
144
|
+
**Critical Workflow:**
|
|
145
|
+
```
|
|
146
|
+
After ANY of these changes:
|
|
147
|
+
├─► Code refactoring (moved files, renamed modules)
|
|
148
|
+
├─► Import path changes
|
|
149
|
+
├─► Documentation updates (especially imports in docs)
|
|
150
|
+
├─► Type check fixes
|
|
151
|
+
└─► MUST run full test suite
|
|
152
|
+
|
|
153
|
+
Reason: Ensure imports work, examples are valid, no broken references.
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Gate 3: Layer Integrity
|
|
157
|
+
|
|
158
|
+
**Failure class:** Macro (always — requires architectural decision)
|
|
159
|
+
|
|
160
|
+
Verify no cross-layer imports exist in the project architecture.
|
|
161
|
+
|
|
162
|
+
**Project-specific rules:**
|
|
163
|
+
{Fill in during bootstrap — define which layers cannot import from which.}
|
|
164
|
+
|
|
165
|
+
- Routes must NOT contain business logic — delegate to services
|
|
166
|
+
- Services must NOT depend on transport layer
|
|
167
|
+
- Infrastructure utilities must NOT import from domain modules
|
|
168
|
+
|
|
169
|
+
{Add additional project-specific layer rules here.}
|
|
170
|
+
|
|
171
|
+
**2-Stage Pattern:**
|
|
172
|
+
```
|
|
173
|
+
STAGE 1 — CHECK:
|
|
174
|
+
Scan for cross-layer imports (e.g., infra importing domain)
|
|
175
|
+
|
|
176
|
+
STAGE 2 — FEEDBACK (if failed):
|
|
177
|
+
├─► Identify violation location
|
|
178
|
+
├─► Refactor: extract to correct layer OR use dependency injection
|
|
179
|
+
└─► Retry STAGE 1
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
**Not auto-fixable:** Requires architectural decision.
|
|
183
|
+
|
|
184
|
+
### Gate 4: Complexity
|
|
185
|
+
|
|
186
|
+
**Failure class:** Macro (triggers mode switch to OVERDENSE-SPLIT)
|
|
187
|
+
|
|
188
|
+
Check file and function sizes against thresholds.
|
|
189
|
+
|
|
190
|
+
**2-Stage Pattern:**
|
|
191
|
+
```
|
|
192
|
+
STAGE 1 — CHECK:
|
|
193
|
+
Measure file LOC, function LOC, cyclomatic complexity
|
|
194
|
+
|
|
195
|
+
STAGE 2 — FEEDBACK (if exceeded):
|
|
196
|
+
├─► Identify overdense code
|
|
197
|
+
├─► Switch to OVERDENSE-SPLIT mode
|
|
198
|
+
├─► Decompose before proceeding
|
|
199
|
+
└─► Retry STAGE 1
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Gate 5: Debug Hygiene
|
|
203
|
+
|
|
204
|
+
**Failure class:** Micro (always — auto-removable artifacts)
|
|
205
|
+
|
|
206
|
+
Check for debug artifacts left in production code.
|
|
207
|
+
|
|
208
|
+
**Commands:**
|
|
209
|
+
```bash
|
|
210
|
+
# {Fill in with project lint/format commands}
|
|
211
|
+
{lint command}
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
**2-Stage Pattern:**
|
|
215
|
+
```
|
|
216
|
+
STAGE 1 — CHECK:
|
|
217
|
+
Scan for debug artifacts (print, breakpoint, TODO, etc.)
|
|
218
|
+
|
|
219
|
+
STAGE 2 — FEEDBACK (if found):
|
|
220
|
+
├─► Remove or convert to proper logging
|
|
221
|
+
└─► Retry STAGE 1
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
## Auto-Fix Rules
|
|
227
|
+
|
|
228
|
+
| NFR | Auto-Fixable | Condition |
|
|
229
|
+
|-----|--------------|-----------|
|
|
230
|
+
| Type Safety | Partial | Only obvious return types, simple narrowing |
|
|
231
|
+
| Test Coverage | Never | Fix source, not tests |
|
|
232
|
+
| Layer Integrity | Never | Requires architecture decision |
|
|
233
|
+
| Complexity | Via Split | Triggers OVERDENSE-SPLIT mode |
|
|
234
|
+
| Debug Code | Yes | Remove or convert to logging |
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
## Iteration Budget and Escalation
|
|
239
|
+
|
|
240
|
+
- Max 5 full CHALLENGE-TEST iterations
|
|
241
|
+
- Escalate when:
|
|
242
|
+
- Budget exhausted
|
|
243
|
+
- Same gate fails 3+ times with equivalent symptom
|
|
244
|
+
- Required fix exceeds approved scope
|
|
245
|
+
|
|
246
|
+
Escalation report should include failing gate, attempted patches, and blockers.
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
## Output Contract
|
|
251
|
+
|
|
252
|
+
```
|
|
253
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
254
|
+
VALIDATE-ENV (Stage 1 of CHALLENGE-TEST)
|
|
255
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
256
|
+
|
|
257
|
+
NFR: TYPE SAFETY
|
|
258
|
+
Check: [PASS | FAIL]
|
|
259
|
+
Feedback: [applied patch if failed, or "—"]
|
|
260
|
+
Retry: [PASS | SKIP]
|
|
261
|
+
|
|
262
|
+
NFR: TEST COVERAGE
|
|
263
|
+
Check: [PASS | FAIL]
|
|
264
|
+
Feedback: [applied patch if failed, or "—"]
|
|
265
|
+
Retry: [PASS | SKIP]
|
|
266
|
+
|
|
267
|
+
NFR: LAYER INTEGRITY
|
|
268
|
+
Check: [PASS | FAIL]
|
|
269
|
+
Feedback: [applied patch if failed, or "—"]
|
|
270
|
+
Retry: [PASS | SKIP]
|
|
271
|
+
|
|
272
|
+
NFR: COMPLEXITY
|
|
273
|
+
Check: [PASS | WARN | FAIL]
|
|
274
|
+
Feedback: [applied patch if failed, or "—"]
|
|
275
|
+
Retry: [PASS | SKIP]
|
|
276
|
+
|
|
277
|
+
NFR: DEBUG CODE
|
|
278
|
+
Check: [PASS | FAIL]
|
|
279
|
+
Feedback: [applied patch if failed, or "—"]
|
|
280
|
+
Retry: [PASS | SKIP]
|
|
281
|
+
|
|
282
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
283
|
+
STAGE 1 RESULT: [PASS | FAIL]
|
|
284
|
+
PROCEED TO STAGE 2: [YES | NO - escalate]
|
|
285
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
---
|
|
289
|
+
|
|
290
|
+
## Integration with Reasoning Kernel
|
|
291
|
+
|
|
292
|
+
```
|
|
293
|
+
reasoning-kernel.md
|
|
294
|
+
│
|
|
295
|
+
▼
|
|
296
|
+
CHALLENGE-TEST
|
|
297
|
+
│
|
|
298
|
+
├─► Stage 1: validate-env.md (NFRs)
|
|
299
|
+
│ │
|
|
300
|
+
│ └─► Each NFR: CHECK → FEEDBACK → RETRY
|
|
301
|
+
│
|
|
302
|
+
└─► Stage 2: validate-n.md (Neighbors)
|
|
303
|
+
│
|
|
304
|
+
└─► Each check: CHECK → FEEDBACK → RETRY
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
**Flow on failure:**
|
|
308
|
+
1. NFR check fails
|
|
309
|
+
2. Invoke `feedback.md` with error context
|
|
310
|
+
3. Generate and apply patch
|
|
311
|
+
4. Retry the same NFR check
|
|
312
|
+
5. If still fails after 3 retries → escalate
|
|
313
|
+
|
|
314
|
+
---
|
|
315
|
+
|
|
316
|
+
## Common Failure Patterns
|
|
317
|
+
|
|
318
|
+
| Symptom | Likely Cause | Preferred Fix |
|
|
319
|
+
|---------|--------------|---------------|
|
|
320
|
+
| Recurrent type failures | Incomplete interface update | Update all impacted signatures |
|
|
321
|
+
| Passing tests but failing layers | Hidden architectural shortcut | Restore layer boundaries |
|
|
322
|
+
| Complexity spike after quick fix | Accretive patching | Switch to OVERDENSE-SPLIT mode |
|
|
323
|
+
|
|
324
|
+
---
|
|
325
|
+
|
|
326
|
+
## Related Documents
|
|
327
|
+
|
|
328
|
+
| Document | Purpose |
|
|
329
|
+
|----------|---------|
|
|
330
|
+
| [reasoning-kernel.md](reasoning-kernel.md) | Full loop orchestration |
|
|
331
|
+
| [validate-n.md](validate-n.md) | Neighbor compatibility stage |
|
|
332
|
+
| [feedback.md](feedback.md) | Patch generation and escalation |
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
# Validate Neighbors (Stage 2)
|
|
2
|
+
|
|
3
|
+
Validation of **shapes, boundaries, and bridge interfaces** when modifying shared code.
|
|
4
|
+
|
|
5
|
+
This is **Stage 2** of the 2-stage validation integrated into the reasoning kernel.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Position in Reasoning Kernel
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
CHALLENGE-TEST (from reasoning-kernel.md):
|
|
13
|
+
│
|
|
14
|
+
├─► [Stage 1] validate-env.md
|
|
15
|
+
│ └─► Check NFRs (types, tests, layers, docs)
|
|
16
|
+
│
|
|
17
|
+
└─► [Stage 2] validate-n.md ◄── YOU ARE HERE
|
|
18
|
+
│
|
|
19
|
+
├─► Check shapes (function signatures)
|
|
20
|
+
├─► Check boundaries (module exports)
|
|
21
|
+
├─► Check bridges (cross-module contracts)
|
|
22
|
+
└─► FAIL? → feedback.md → patch → retry
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## When to Run
|
|
28
|
+
|
|
29
|
+
- When modifying **any public interface** (function signatures, class APIs)
|
|
30
|
+
- When changing **module boundaries** (adding/removing exports)
|
|
31
|
+
- When creating **new modules** or **moving code between modules**
|
|
32
|
+
- Before merging changes that touch **multiple modules**
|
|
33
|
+
|
|
34
|
+
### Neighbor Map
|
|
35
|
+
|
|
36
|
+
{Fill in during bootstrap with actual project coupling paths.}
|
|
37
|
+
|
|
38
|
+
Key coupling paths to track:
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
routes/* ──► services/* ──► repositories/* / database
|
|
42
|
+
│
|
|
43
|
+
├──► external adapters (APIs, integrations)
|
|
44
|
+
├──► utilities (logging, audit, helpers)
|
|
45
|
+
└──► background workers / job queues
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
When modifying any of these, check all neighbors in the coupling path.
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## Core Concepts
|
|
53
|
+
|
|
54
|
+
### Shapes
|
|
55
|
+
|
|
56
|
+
The **signature contract** of a function, method, or class:
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
# Shape = name + parameters + return type + raises
|
|
60
|
+
def query(
|
|
61
|
+
self,
|
|
62
|
+
collection: str,
|
|
63
|
+
query_text: str,
|
|
64
|
+
*,
|
|
65
|
+
filters: dict | None = None,
|
|
66
|
+
limit: int = 10,
|
|
67
|
+
) -> list[Result]:
|
|
68
|
+
...
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
A shape change is anything that alters the call contract:
|
|
72
|
+
adding/removing parameters, changing types, or modifying return types.
|
|
73
|
+
|
|
74
|
+
### Boundaries
|
|
75
|
+
|
|
76
|
+
The **module interface** — what is exported/public:
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
# module/__init__.py
|
|
80
|
+
from .service import MyService # Public boundary
|
|
81
|
+
from .routes import router # Public boundary
|
|
82
|
+
|
|
83
|
+
# Private (not exported) — can change freely
|
|
84
|
+
# from .internal import _helper
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Boundary changes affect every consumer that imports from the module.
|
|
88
|
+
|
|
89
|
+
### Bridges
|
|
90
|
+
|
|
91
|
+
The **contracts between modules** — how they communicate:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
# Bridge: module_a → module_b
|
|
95
|
+
# Contract: ServiceA.process() returns list[Result]
|
|
96
|
+
# Consumer: ServiceB expects this shape
|
|
97
|
+
|
|
98
|
+
# If ServiceA.process() changes return type:
|
|
99
|
+
# → ServiceB breaks (bridge violation)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## 2-Stage Validation Pattern
|
|
105
|
+
|
|
106
|
+
Each neighbor check follows this pattern:
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
110
|
+
│ NEIGHBOR VALIDATION │
|
|
111
|
+
├─────────────────────────────────────────────────────────────┤
|
|
112
|
+
│ │
|
|
113
|
+
│ STAGE 1: CHECK │
|
|
114
|
+
│ ─────────────── │
|
|
115
|
+
│ Identify neighbors → Analyze shapes → Verify compatibility │
|
|
116
|
+
│ │
|
|
117
|
+
│ STAGE 2: FEEDBACK (if failed) │
|
|
118
|
+
│ ───────────────────────────── │
|
|
119
|
+
│ Diagnose break → Update callers first → Retry │
|
|
120
|
+
│ │
|
|
121
|
+
└─────────────────────────────────────────────────────────────┘
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## Per-Check Execution Patterns
|
|
127
|
+
|
|
128
|
+
### Check 1: Shape Compatibility
|
|
129
|
+
|
|
130
|
+
**2-Stage Pattern:**
|
|
131
|
+
```
|
|
132
|
+
STAGE 1 — CHECK:
|
|
133
|
+
Compare before/after signatures → Classify change type
|
|
134
|
+
|
|
135
|
+
STAGE 2 — FEEDBACK (if BREAKING):
|
|
136
|
+
├─► Identify all callers
|
|
137
|
+
├─► Generate patches for each caller
|
|
138
|
+
├─► Apply caller updates FIRST
|
|
139
|
+
├─► Then apply source change
|
|
140
|
+
└─► Retry STAGE 1
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
For each changed function/class:
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
SHAPE CHECK: [function_name]
|
|
147
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
148
|
+
Before:
|
|
149
|
+
def query(collection: str, query: str) -> list[dict]
|
|
150
|
+
|
|
151
|
+
After:
|
|
152
|
+
def query(collection: str, query: str) -> list[Result]
|
|
153
|
+
|
|
154
|
+
Change Type: [BREAKING | ADDITIVE | COMPATIBLE]
|
|
155
|
+
|
|
156
|
+
Callers Affected:
|
|
157
|
+
- module_a/services.py:45 → NEEDS UPDATE
|
|
158
|
+
- module_b/services.py:78 → COMPATIBLE
|
|
159
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Check 2: Boundary Integrity
|
|
163
|
+
|
|
164
|
+
**2-Stage Pattern:**
|
|
165
|
+
```
|
|
166
|
+
STAGE 1 — CHECK:
|
|
167
|
+
Verify __init__.py exports → Check for accidental exposure
|
|
168
|
+
|
|
169
|
+
STAGE 2 — FEEDBACK (if violation):
|
|
170
|
+
├─► Remove accidental exports OR
|
|
171
|
+
├─► Properly document new exports
|
|
172
|
+
└─► Retry STAGE 1
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
```
|
|
176
|
+
BOUNDARY CHECK: [module]
|
|
177
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
178
|
+
Exports:
|
|
179
|
+
✅ MyService (public, stable)
|
|
180
|
+
✅ router (public, stable)
|
|
181
|
+
⚠️ ResultModel (newly exported — verify callers)
|
|
182
|
+
|
|
183
|
+
Internal (not exported):
|
|
184
|
+
✅ _build_filters (private, can change)
|
|
185
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### Check 3: Bridge Contracts
|
|
189
|
+
|
|
190
|
+
**2-Stage Pattern:**
|
|
191
|
+
```
|
|
192
|
+
STAGE 1 — CHECK:
|
|
193
|
+
Verify cross-module contracts still hold
|
|
194
|
+
|
|
195
|
+
STAGE 2 — FEEDBACK (if broken):
|
|
196
|
+
├─► Analyze contract requirements
|
|
197
|
+
├─► Update either producer or consumers
|
|
198
|
+
└─► Retry STAGE 1
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
```
|
|
202
|
+
BRIDGE CHECK: [source] → [target]
|
|
203
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
204
|
+
Contract: ServiceB calls ServiceA.process()
|
|
205
|
+
Expected: list[Result] with fields [id, text, score]
|
|
206
|
+
Actual: list[Result] with fields [id, text, score, metadata]
|
|
207
|
+
|
|
208
|
+
Compatibility: ✅ ADDITIVE (new field, no breakage)
|
|
209
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
## Change Classification
|
|
215
|
+
|
|
216
|
+
| Type | Description | Action Required |
|
|
217
|
+
|------|-------------|-----------------|
|
|
218
|
+
| **COMPATIBLE** | No signature change | None |
|
|
219
|
+
| **ADDITIVE** | New optional params, new fields | Verify callers handle gracefully |
|
|
220
|
+
| **BREAKING** | Changed types, removed params | Update all callers |
|
|
221
|
+
|
|
222
|
+
### Breaking Change Protocol
|
|
223
|
+
|
|
224
|
+
When a breaking change is detected:
|
|
225
|
+
|
|
226
|
+
1. **Identify all callers** (grep/search for usages)
|
|
227
|
+
2. **Update callers first** (before changing source)
|
|
228
|
+
3. **Run validate-env** (ensure no regressions)
|
|
229
|
+
4. **Apply source change**
|
|
230
|
+
5. **Run validate-env again** (final verification)
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
## Coupling Strength Definitions
|
|
235
|
+
|
|
236
|
+
Track coupling between modules to assess impact:
|
|
237
|
+
|
|
238
|
+
| Coupling | Definition | Example |
|
|
239
|
+
|----------|------------|---------|
|
|
240
|
+
| **Strong** | Direct function calls, shared types | Service calls another service |
|
|
241
|
+
| **Medium** | Shared infrastructure (same DB tables, collections) | Two modules writing the same store |
|
|
242
|
+
| **Weak** | Only via events, tasks, or async messages | Background job triggers downstream module |
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
## Output Contract
|
|
247
|
+
|
|
248
|
+
```
|
|
249
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
250
|
+
VALIDATE-N (Stage 2 of CHALLENGE-TEST)
|
|
251
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
252
|
+
|
|
253
|
+
CHANGED MODULE: [module name]
|
|
254
|
+
|
|
255
|
+
NEIGHBORS:
|
|
256
|
+
- [module1]: [weak | medium | strong] coupling
|
|
257
|
+
- [module2]: [weak | medium | strong] coupling
|
|
258
|
+
|
|
259
|
+
CHECK: SHAPES
|
|
260
|
+
- [function1]: [COMPATIBLE | ADDITIVE | BREAKING]
|
|
261
|
+
- [function2]: [COMPATIBLE | ADDITIVE | BREAKING]
|
|
262
|
+
Feedback: [applied patch or "—"]
|
|
263
|
+
|
|
264
|
+
CHECK: BOUNDARIES
|
|
265
|
+
Status: [INTACT | MODIFIED]
|
|
266
|
+
Feedback: [applied patch or "—"]
|
|
267
|
+
|
|
268
|
+
CHECK: BRIDGES
|
|
269
|
+
Status: [VALID | BROKEN]
|
|
270
|
+
Feedback: [applied patch or "—"]
|
|
271
|
+
|
|
272
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
273
|
+
STAGE 2 RESULT: [PASS | FAIL]
|
|
274
|
+
PROCEED: [YES → UPDATE phase | NO → escalate]
|
|
275
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
---
|
|
279
|
+
|
|
280
|
+
## Typical Corrections
|
|
281
|
+
|
|
282
|
+
| Failure Type | Correction Strategy |
|
|
283
|
+
|--------------|---------------------|
|
|
284
|
+
| Shape mismatch | Align shared model/signature across producer and consumers |
|
|
285
|
+
| Boundary drift | Restore intended exports and update docs |
|
|
286
|
+
| Bridge mismatch | Normalize adapter/mapper at integration boundary |
|
|
287
|
+
|
|
288
|
+
---
|
|
289
|
+
|
|
290
|
+
## Integration with Reasoning Kernel
|
|
291
|
+
|
|
292
|
+
```
|
|
293
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
294
|
+
│ VALIDATION CHAIN │
|
|
295
|
+
├─────────────────────────────────────────────────────────────┤
|
|
296
|
+
│ │
|
|
297
|
+
│ 1. reasoning-kernel.md │
|
|
298
|
+
│ └─► Plan action, identify affected modules │
|
|
299
|
+
│ │
|
|
300
|
+
│ 2. validate-env.md (Stage 1) │
|
|
301
|
+
│ └─► Run quality gates │
|
|
302
|
+
│ │
|
|
303
|
+
│ 3. validate-n.md (THIS — Stage 2) │
|
|
304
|
+
│ └─► Check shapes, boundaries, bridges │
|
|
305
|
+
│ └─► If BREAKING → update callers first │
|
|
306
|
+
│ │
|
|
307
|
+
│ 4. On FAIL → feedback.md │
|
|
308
|
+
│ └─► Apply patches, retry │
|
|
309
|
+
│ │
|
|
310
|
+
└─────────────────────────────────────────────────────────────┘
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
---
|
|
314
|
+
|
|
315
|
+
## Related Documents
|
|
316
|
+
|
|
317
|
+
| Document | Purpose |
|
|
318
|
+
|----------|---------|
|
|
319
|
+
| [validate-env.md](validate-env.md) | Stage 1 gates |
|
|
320
|
+
| [feedback.md](feedback.md) | Retry and escalation logic |
|
|
321
|
+
| [patterns/refactoring-workflow.md](patterns/refactoring-workflow.md) | Safe dependency and import movement |
|