dhurandhar 1.0.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.
- package/.dhurandhar-session-start.md +242 -0
- package/LICENSE +21 -0
- package/README.md +416 -0
- package/docs/ARCHITECTURE_V2.md +249 -0
- package/docs/DECISION_REGISTRY.md +357 -0
- package/docs/IMPLEMENTATION_PERSONAS.md +406 -0
- package/docs/PLUGGABLE_STRATEGIES.md +439 -0
- package/docs/SYSTEM_OBSERVER.md +433 -0
- package/docs/TEST_FIRST_AGILE.md +359 -0
- package/docs/architecture.md +279 -0
- package/docs/engineering-first-philosophy.md +263 -0
- package/docs/getting-started.md +218 -0
- package/docs/module-development.md +323 -0
- package/docs/strategy-example.md +299 -0
- package/docs/test-first-example.md +392 -0
- package/package.json +79 -0
- package/src/core/README.md +92 -0
- package/src/core/agent-instructions/backend-developer.md +412 -0
- package/src/core/agent-instructions/devops-engineer.md +372 -0
- package/src/core/agent-instructions/dhurandhar-council.md +547 -0
- package/src/core/agent-instructions/edge-case-hunter.md +322 -0
- package/src/core/agent-instructions/frontend-developer.md +494 -0
- package/src/core/agent-instructions/lead-system-architect.md +631 -0
- package/src/core/agent-instructions/system-observer.md +319 -0
- package/src/core/agent-instructions/test-architect.md +284 -0
- package/src/core/module.yaml +54 -0
- package/src/core/schemas/design-module-schema.yaml +995 -0
- package/src/core/schemas/system-design-map-schema.yaml +324 -0
- package/src/modules/example/README.md +130 -0
- package/src/modules/example/module.yaml +252 -0
- package/tools/cli/commands/audit.js +267 -0
- package/tools/cli/commands/config.js +113 -0
- package/tools/cli/commands/context.js +170 -0
- package/tools/cli/commands/decisions.js +398 -0
- package/tools/cli/commands/entity.js +218 -0
- package/tools/cli/commands/epic.js +125 -0
- package/tools/cli/commands/install.js +172 -0
- package/tools/cli/commands/module.js +109 -0
- package/tools/cli/commands/service.js +167 -0
- package/tools/cli/commands/story.js +225 -0
- package/tools/cli/commands/strategy.js +294 -0
- package/tools/cli/commands/test.js +277 -0
- package/tools/cli/commands/validate.js +107 -0
- package/tools/cli/dhurandhar.js +212 -0
- package/tools/lib/config-manager.js +170 -0
- package/tools/lib/filesystem.js +126 -0
- package/tools/lib/module-installer.js +61 -0
- package/tools/lib/module-manager.js +149 -0
- package/tools/lib/sdm-manager.js +982 -0
- package/tools/lib/test-engine.js +255 -0
- package/tools/lib/test-templates/api-client.template.js +100 -0
- package/tools/lib/test-templates/vitest.config.template.js +37 -0
- package/tools/lib/validators/config-validator.js +113 -0
- package/tools/lib/validators/module-validator.js +137 -0
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
# System Observer & Architectural Drift Detection
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Dhurandhar v2.3 introduces the **System Observer** persona and **Architectural Drift Detection** system to manage the delta between "Intended State" (SDM) and "Current State" (codebase).
|
|
6
|
+
|
|
7
|
+
## Philosophy
|
|
8
|
+
|
|
9
|
+
### Traditional Approach (Anti-Pattern)
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
Developer: "I have 5 services in my codebase"
|
|
13
|
+
Framework: "Great! Which ones?"
|
|
14
|
+
Developer: "auth, user, order, payment, inventory"
|
|
15
|
+
Framework: "Let me add those to the design document..."
|
|
16
|
+
|
|
17
|
+
[Later...]
|
|
18
|
+
|
|
19
|
+
Developer: "I added a notification service"
|
|
20
|
+
Framework: "You should update the design document"
|
|
21
|
+
Developer: "I'll do it later..."
|
|
22
|
+
|
|
23
|
+
[Design document becomes stale, never matches reality]
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Dhurandhar Approach
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
Developer: "I have 5 services in my codebase"
|
|
30
|
+
|
|
31
|
+
System Observer:
|
|
32
|
+
[Scans codebase]
|
|
33
|
+
[Reads SYSTEM_DESIGN_MAP.yaml]
|
|
34
|
+
"Found 5 services in code, 3 in SDM"
|
|
35
|
+
|
|
36
|
+
Unmanaged (in code, not in SDM):
|
|
37
|
+
- notification-service
|
|
38
|
+
- analytics-service
|
|
39
|
+
|
|
40
|
+
Sync SDM to match? (y/n)
|
|
41
|
+
→ y
|
|
42
|
+
|
|
43
|
+
✓ SDM synchronized
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**Direct action. No stale documentation.**
|
|
47
|
+
|
|
48
|
+
## System Observer Persona
|
|
49
|
+
|
|
50
|
+
### Role
|
|
51
|
+
|
|
52
|
+
- **Technical Auditor**: Compare SDM vs codebase
|
|
53
|
+
- **State Synchronizer**: Keep SDM aligned with reality
|
|
54
|
+
- **Session Gatekeeper**: First persona invoked on session start
|
|
55
|
+
- **Evidence-Based Reporter**: Only report verifiable facts
|
|
56
|
+
|
|
57
|
+
### Responsibilities
|
|
58
|
+
|
|
59
|
+
1. **Drift Detection**:
|
|
60
|
+
- Identify unimplemented (SDM → code gaps)
|
|
61
|
+
- Identify unmanaged (code → SDM gaps)
|
|
62
|
+
- Detect strategy violations
|
|
63
|
+
|
|
64
|
+
2. **Session Rehydration**:
|
|
65
|
+
- Load SDM on session start
|
|
66
|
+
- Perform background audit
|
|
67
|
+
- Provide context to other personas
|
|
68
|
+
|
|
69
|
+
3. **Compliance Reporting**:
|
|
70
|
+
- Service implementation status
|
|
71
|
+
- Entity implementation status
|
|
72
|
+
- Story test coverage
|
|
73
|
+
- Strategy compliance percentage
|
|
74
|
+
|
|
75
|
+
## Drift Types
|
|
76
|
+
|
|
77
|
+
### 1. Unimplemented (SDM Ahead of Code)
|
|
78
|
+
|
|
79
|
+
**Definition**: Defined in `SYSTEM_DESIGN_MAP.yaml` but missing in codebase
|
|
80
|
+
|
|
81
|
+
**Examples**:
|
|
82
|
+
- Service defined in SDM but no service directory exists
|
|
83
|
+
- Entity defined but no database schema/model file
|
|
84
|
+
- Story defined but tests not generated
|
|
85
|
+
- API endpoint in SDM but no route handler in code
|
|
86
|
+
|
|
87
|
+
**Detection**:
|
|
88
|
+
```
|
|
89
|
+
SDM: services: [auth-service, user-service, order-service]
|
|
90
|
+
Code: services/ directory contains [auth-service, user-service]
|
|
91
|
+
|
|
92
|
+
Unimplemented: order-service
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### 2. Unmanaged (Code Ahead of SDM)
|
|
96
|
+
|
|
97
|
+
**Definition**: Exists in codebase but not in `SYSTEM_DESIGN_MAP.yaml`
|
|
98
|
+
|
|
99
|
+
**Examples**:
|
|
100
|
+
- Service directory exists but not listed in SDM
|
|
101
|
+
- Database table not mapped to any entity
|
|
102
|
+
- API routes not documented in stories
|
|
103
|
+
- Code implementation without corresponding design
|
|
104
|
+
|
|
105
|
+
**Detection**:
|
|
106
|
+
```
|
|
107
|
+
Code: services/ directory contains [auth, user, notification]
|
|
108
|
+
SDM: services: [auth-service, user-service]
|
|
109
|
+
|
|
110
|
+
Unmanaged: notification
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### 3. Strategy Violations (Implementation Contradicts Strategies)
|
|
114
|
+
|
|
115
|
+
**Definition**: Code implementation violates active `technical_strategies`
|
|
116
|
+
|
|
117
|
+
**Examples**:
|
|
118
|
+
- Shared database when `persistence.model: database_per_service`
|
|
119
|
+
- Synchronous calls when `communication.primary_pattern: asynchronous_events`
|
|
120
|
+
- No circuit breaker when `resilience.circuit_breaker: true`
|
|
121
|
+
- No JWT validation when `security.authentication: jwt_centralized`
|
|
122
|
+
|
|
123
|
+
**Detection**:
|
|
124
|
+
```
|
|
125
|
+
Strategy: persistence.model = database_per_service
|
|
126
|
+
Service: payment-service
|
|
127
|
+
Code: No dedicated database config found
|
|
128
|
+
|
|
129
|
+
Violation: payment-service missing dedicated database
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## CLI Commands
|
|
133
|
+
|
|
134
|
+
### 1. Summary Report
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
dhurandhar audit --summary
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
**Output**:
|
|
141
|
+
```
|
|
142
|
+
📊 System Health Summary
|
|
143
|
+
|
|
144
|
+
Architectural Alignment:
|
|
145
|
+
Services: 4/5 implemented
|
|
146
|
+
Entities: 8/8 implemented
|
|
147
|
+
Stories: 10/12 tested
|
|
148
|
+
Strategy Compliance: 90%
|
|
149
|
+
|
|
150
|
+
Drift Assessment:
|
|
151
|
+
Drift Percentage: 18%
|
|
152
|
+
Status: ⚠ Minor drift detected
|
|
153
|
+
|
|
154
|
+
View details:
|
|
155
|
+
dhurandhar audit --drift
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### 2. Drift Details
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
dhurandhar audit --drift
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
**Output**:
|
|
165
|
+
```
|
|
166
|
+
🔍 Drift Detection Report
|
|
167
|
+
|
|
168
|
+
Unimplemented (Defined in SDM, Missing in Code):
|
|
169
|
+
|
|
170
|
+
Services:
|
|
171
|
+
✗ order-service: Process customer orders
|
|
172
|
+
|
|
173
|
+
Stories (Tests not generated):
|
|
174
|
+
✗ STORY-005: Payment Processing (EPIC-002)
|
|
175
|
+
✗ STORY-008: Order Fulfillment (EPIC-003)
|
|
176
|
+
|
|
177
|
+
Unmanaged (Exists in Code, Not in SDM):
|
|
178
|
+
|
|
179
|
+
Services:
|
|
180
|
+
⚠ notification (services/notification/)
|
|
181
|
+
⚠ analytics (services/analytics/)
|
|
182
|
+
|
|
183
|
+
Entities:
|
|
184
|
+
⚠ Product (models/Product.ts)
|
|
185
|
+
|
|
186
|
+
Strategy Violations:
|
|
187
|
+
|
|
188
|
+
⚡ payment-service: Missing event boundaries
|
|
189
|
+
Strategy: communication
|
|
190
|
+
Expected: asynchronous_events
|
|
191
|
+
Actual: no event_boundaries config
|
|
192
|
+
|
|
193
|
+
⚡ user-service: Missing Redis dependency
|
|
194
|
+
Strategy: state_management
|
|
195
|
+
Expected: distributed_redis
|
|
196
|
+
Actual: no redis dependency
|
|
197
|
+
|
|
198
|
+
Recommendations:
|
|
199
|
+
→ Codebase is ahead of SDM
|
|
200
|
+
Run: dhurandhar audit --sync to update SDM
|
|
201
|
+
|
|
202
|
+
→ Strategy violations detected
|
|
203
|
+
Run: dhurandhar strategy --align to fix
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### 3. Direct-Action Sync
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
dhurandhar audit --sync
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
**Interactive**:
|
|
213
|
+
```
|
|
214
|
+
🔄 Sync SDM to Codebase
|
|
215
|
+
|
|
216
|
+
Sync Analysis:
|
|
217
|
+
Unimplemented (SDM ahead): 1 services, 0 entities
|
|
218
|
+
Unmanaged (Code ahead): 2 services, 1 entities
|
|
219
|
+
|
|
220
|
+
Recommendation: Update SDM to match code
|
|
221
|
+
|
|
222
|
+
? Sync SDM to codebase state? Yes
|
|
223
|
+
|
|
224
|
+
✓ SDM synchronized
|
|
225
|
+
|
|
226
|
+
Changes:
|
|
227
|
+
+ 2 services added to SDM
|
|
228
|
+
+ 1 entities added to SDM
|
|
229
|
+
|
|
230
|
+
Verify changes:
|
|
231
|
+
dhurandhar audit --summary
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
**Direct action. No multi-step interview.**
|
|
235
|
+
|
|
236
|
+
### 4. Full Audit
|
|
237
|
+
|
|
238
|
+
```bash
|
|
239
|
+
dhurandhar audit
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
Combines `--summary` + `--drift` in one report.
|
|
243
|
+
|
|
244
|
+
## Session Rehydration
|
|
245
|
+
|
|
246
|
+
### System Observer as Gatekeeper
|
|
247
|
+
|
|
248
|
+
**Every session starts with System Observer**:
|
|
249
|
+
|
|
250
|
+
```
|
|
251
|
+
[Session Start]
|
|
252
|
+
|
|
253
|
+
System Observer:
|
|
254
|
+
1. Load SYSTEM_DESIGN_MAP.yaml
|
|
255
|
+
2. Perform silent background audit
|
|
256
|
+
3. Generate context summary
|
|
257
|
+
4. Calculate drift percentage
|
|
258
|
+
5. Provide context to other personas
|
|
259
|
+
6. Report to user (if drift > 25%)
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
### Rehydration Report (drift < 25%)
|
|
263
|
+
|
|
264
|
+
```
|
|
265
|
+
[System Observer] Session Ready
|
|
266
|
+
|
|
267
|
+
5 services, 8 entities, 12 stories (all tested)
|
|
268
|
+
Strategy Compliance: 95%
|
|
269
|
+
Drift: 8%
|
|
270
|
+
|
|
271
|
+
Context loaded. What's next?
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
### Rehydration Report (drift >= 25%)
|
|
275
|
+
|
|
276
|
+
```
|
|
277
|
+
[System Observer] Session Rehydrated
|
|
278
|
+
|
|
279
|
+
Project: my-platform
|
|
280
|
+
Architecture: microservices
|
|
281
|
+
|
|
282
|
+
Active Strategies:
|
|
283
|
+
Persistence: database_per_service
|
|
284
|
+
Communication: asynchronous_events (kafka)
|
|
285
|
+
|
|
286
|
+
Architecture Status:
|
|
287
|
+
Services: 3/5 implemented
|
|
288
|
+
Entities: 6/8 implemented
|
|
289
|
+
Stories: 8/12 tested
|
|
290
|
+
Strategy Compliance: 80%
|
|
291
|
+
|
|
292
|
+
Drift: 32%
|
|
293
|
+
|
|
294
|
+
⚠ Significant architectural drift detected
|
|
295
|
+
|
|
296
|
+
Unimplemented:
|
|
297
|
+
- order-service (defined in SDM)
|
|
298
|
+
- payment-service (defined in SDM)
|
|
299
|
+
- STORY-005, STORY-008 (tests not generated)
|
|
300
|
+
|
|
301
|
+
Strategy Violations:
|
|
302
|
+
- user-service: Missing event boundaries
|
|
303
|
+
|
|
304
|
+
Run for details:
|
|
305
|
+
dhurandhar audit --drift
|
|
306
|
+
|
|
307
|
+
Definition of Done:
|
|
308
|
+
EPIC-001 (Authentication): 80% (4/5 stories complete)
|
|
309
|
+
EPIC-002 (Orders): 57% (4/7 stories complete)
|
|
310
|
+
|
|
311
|
+
What's next?
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
## Drift Detection Engine
|
|
315
|
+
|
|
316
|
+
### Implementation
|
|
317
|
+
|
|
318
|
+
**Location**: `tools/lib/sdm-manager.js`
|
|
319
|
+
|
|
320
|
+
**Method**: `performAudit()`
|
|
321
|
+
|
|
322
|
+
**Process**:
|
|
323
|
+
1. Load SDM
|
|
324
|
+
2. Scan codebase:
|
|
325
|
+
- Service directories (`services/`, `cmd/`, `src/services/`)
|
|
326
|
+
- Entity files (`models/`, `entities/`, `schema/`)
|
|
327
|
+
- Test files (`tests/`, `__tests__/`)
|
|
328
|
+
- Config files (`package.json`, `go.mod`, etc.)
|
|
329
|
+
3. Cross-reference:
|
|
330
|
+
- SDM services vs codebase services
|
|
331
|
+
- SDM entities vs codebase entities
|
|
332
|
+
- SDM stories vs test files
|
|
333
|
+
- Active strategies vs service configs
|
|
334
|
+
4. Identify gaps:
|
|
335
|
+
- Unimplemented
|
|
336
|
+
- Unmanaged
|
|
337
|
+
- Strategy violations
|
|
338
|
+
5. Calculate drift percentage
|
|
339
|
+
6. Return audit report
|
|
340
|
+
|
|
341
|
+
### Audit Report Structure
|
|
342
|
+
|
|
343
|
+
```javascript
|
|
344
|
+
{
|
|
345
|
+
timestamp: "2024-01-15T10:30:00Z",
|
|
346
|
+
|
|
347
|
+
summary: {
|
|
348
|
+
total_services: 5,
|
|
349
|
+
implemented_services: 4,
|
|
350
|
+
total_entities: 8,
|
|
351
|
+
implemented_entities: 8,
|
|
352
|
+
total_stories: 12,
|
|
353
|
+
tested_stories: 10,
|
|
354
|
+
strategy_compliance_percentage: 90
|
|
355
|
+
},
|
|
356
|
+
|
|
357
|
+
unimplemented: {
|
|
358
|
+
services: [{ name: "order-service", scope: "..." }],
|
|
359
|
+
entities: [],
|
|
360
|
+
stories: [{ id: "STORY-005", name: "...", epic: "EPIC-002" }]
|
|
361
|
+
},
|
|
362
|
+
|
|
363
|
+
unmanaged: {
|
|
364
|
+
services: [{ name: "notification", path: "services/notification/" }],
|
|
365
|
+
entities: [{ name: "Product", file: "models/Product.ts" }]
|
|
366
|
+
},
|
|
367
|
+
|
|
368
|
+
strategy_violations: [
|
|
369
|
+
{
|
|
370
|
+
service: "payment-service",
|
|
371
|
+
strategy: "communication",
|
|
372
|
+
violation: "Missing event boundaries",
|
|
373
|
+
expected: "asynchronous_events",
|
|
374
|
+
actual: "no event_boundaries config"
|
|
375
|
+
}
|
|
376
|
+
],
|
|
377
|
+
|
|
378
|
+
drift_percentage: 18
|
|
379
|
+
}
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
## Dhurandhar Council Integration
|
|
383
|
+
|
|
384
|
+
The System Observer is part of the **Dhurandhar Council** - a 4-persona system:
|
|
385
|
+
|
|
386
|
+
1. **System Observer**: Audit, drift detection, session rehydration
|
|
387
|
+
2. **Lead System Architect**: Service/entity design, strategy management
|
|
388
|
+
3. **Test Architect**: Story translation, test generation
|
|
389
|
+
4. **Edge Case Hunter**: Boundary conditions, security analysis
|
|
390
|
+
|
|
391
|
+
**Delegation Pattern**:
|
|
392
|
+
```
|
|
393
|
+
System Observer detects drift →
|
|
394
|
+
Unimplemented service → Lead System Architect
|
|
395
|
+
Missing tests → Test Architect
|
|
396
|
+
Strategy violation → Lead System Architect
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
## Benefits
|
|
400
|
+
|
|
401
|
+
### 1. Zero Stale Documentation
|
|
402
|
+
|
|
403
|
+
SDM stays in sync with code through:
|
|
404
|
+
- Automatic drift detection
|
|
405
|
+
- Direct-action sync command
|
|
406
|
+
- Session start audits
|
|
407
|
+
|
|
408
|
+
### 2. Immediate Context
|
|
409
|
+
|
|
410
|
+
Every session starts with:
|
|
411
|
+
- Complete architecture state
|
|
412
|
+
- Drift assessment
|
|
413
|
+
- Definition of Done status
|
|
414
|
+
- Strategy compliance
|
|
415
|
+
|
|
416
|
+
### 3. Evidence-Based Reports
|
|
417
|
+
|
|
418
|
+
System Observer only reports what it can verify:
|
|
419
|
+
- File existence
|
|
420
|
+
- Directory structure
|
|
421
|
+
- Config file contents
|
|
422
|
+
- No speculation
|
|
423
|
+
|
|
424
|
+
### 4. Direct Action
|
|
425
|
+
|
|
426
|
+
`dhurandhar audit --sync` updates SDM without:
|
|
427
|
+
- Multi-step interviews
|
|
428
|
+
- Justification loops
|
|
429
|
+
- Manual editing
|
|
430
|
+
|
|
431
|
+
---
|
|
432
|
+
|
|
433
|
+
**Dhurandhar v2.3: Intent (SDM) ↔ Reality (Code) always aligned**
|