ruvnet-kb-first 5.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.
Files changed (52) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +674 -0
  3. package/SKILL.md +740 -0
  4. package/bin/kb-first.js +123 -0
  5. package/install/init-project.sh +435 -0
  6. package/install/install-global.sh +257 -0
  7. package/install/kb-first-autodetect.sh +108 -0
  8. package/install/kb-first-command.md +80 -0
  9. package/install/kb-first-skill.md +262 -0
  10. package/package.json +87 -0
  11. package/phases/00-assessment.md +529 -0
  12. package/phases/01-storage.md +194 -0
  13. package/phases/01.5-hooks-setup.md +521 -0
  14. package/phases/02-kb-creation.md +413 -0
  15. package/phases/03-persistence.md +125 -0
  16. package/phases/04-visualization.md +170 -0
  17. package/phases/05-integration.md +114 -0
  18. package/phases/06-scaffold.md +130 -0
  19. package/phases/07-build.md +493 -0
  20. package/phases/08-verification.md +597 -0
  21. package/phases/09-security.md +512 -0
  22. package/phases/10-documentation.md +613 -0
  23. package/phases/11-deployment.md +670 -0
  24. package/phases/testing.md +713 -0
  25. package/scripts/1.5-hooks-verify.sh +252 -0
  26. package/scripts/8.1-code-scan.sh +58 -0
  27. package/scripts/8.2-import-check.sh +42 -0
  28. package/scripts/8.3-source-returns.sh +52 -0
  29. package/scripts/8.4-startup-verify.sh +65 -0
  30. package/scripts/8.5-fallback-check.sh +63 -0
  31. package/scripts/8.6-attribution.sh +56 -0
  32. package/scripts/8.7-confidence.sh +56 -0
  33. package/scripts/8.8-gap-logging.sh +70 -0
  34. package/scripts/9-security-audit.sh +202 -0
  35. package/scripts/init-project.sh +395 -0
  36. package/scripts/verify-enforcement.sh +167 -0
  37. package/src/commands/hooks.js +361 -0
  38. package/src/commands/init.js +315 -0
  39. package/src/commands/phase.js +372 -0
  40. package/src/commands/score.js +380 -0
  41. package/src/commands/status.js +193 -0
  42. package/src/commands/verify.js +286 -0
  43. package/src/index.js +56 -0
  44. package/src/mcp-server.js +412 -0
  45. package/templates/attention-router.ts +534 -0
  46. package/templates/code-analysis.ts +683 -0
  47. package/templates/federated-kb-learner.ts +649 -0
  48. package/templates/gnn-engine.ts +1091 -0
  49. package/templates/intentions.md +277 -0
  50. package/templates/kb-client.ts +905 -0
  51. package/templates/schema.sql +303 -0
  52. package/templates/sona-config.ts +312 -0
package/SKILL.md ADDED
@@ -0,0 +1,740 @@
1
+ Updated: 2026-01-02 09:45:00 EST | Version 5.0.0
2
+ Created: 2026-01-01 15:00:00 EST
3
+
4
+ # RuvNet KB-First Application Builder v5.0
5
+
6
+ ## Intelligence-First Architecture for Knowledge Applications
7
+
8
+ **Version:** 5.0.0
9
+ **NPM Package:** `ruvnet-kb-first`
10
+ **Purpose:** Build applications where curated expert knowledge drives intelligent decision-making through GNN reasoning, attention routing, and SONA learning.
11
+
12
+ ---
13
+
14
+ ## What's New in v5.0
15
+
16
+ | Feature | Description |
17
+ |---------|-------------|
18
+ | **NPM Package** | `npx ruvnet-kb-first init` - works in any repo |
19
+ | **CLI Commands** | `kb-first init`, `score`, `verify`, `status`, `phase`, `hooks` |
20
+ | **MCP Server** | Deep Claude Code integration via `mcp-server.js` |
21
+ | **Auto-Detection** | Automatic KB-First project detection on session start |
22
+ | **12 Phases** | Complete build process (0-11 + 1.5) with 57 sub-phases |
23
+ | **Dual Binary** | Both `ruvnet-kb-first` and `kb-first` work |
24
+
25
+ ### Quick Start
26
+
27
+ ```bash
28
+ # Option 1: NPX (recommended)
29
+ npx ruvnet-kb-first init
30
+
31
+ # Option 2: Global install
32
+ npm install -g ruvnet-kb-first
33
+ kb-first init
34
+
35
+ # Option 3: Slash command (in Claude Code)
36
+ /kb-first
37
+ ```
38
+
39
+ ### MCP Server Setup
40
+
41
+ Add to your Claude Code settings:
42
+
43
+ ```json
44
+ {
45
+ "mcpServers": {
46
+ "ruvnet-kb-first": {
47
+ "command": "npx",
48
+ "args": ["ruvnet-kb-first", "mcp"]
49
+ }
50
+ }
51
+ }
52
+ ```
53
+
54
+ ---
55
+
56
+ ## What's New in v4.3
57
+
58
+ | Feature | Description |
59
+ |---------|-------------|
60
+ | **Phase 9: Security Audit** | OWASP Top 10, SQL injection, secrets scanning |
61
+ | **Phase 10: Documentation** | Complete docs, API specs, versioning |
62
+ | **Phase 11: Deployment** | Production deployment with public access |
63
+ | **Security Scripts** | Automated security verification (9-security-audit.sh) |
64
+ | **Go-Live Checklist** | Pre-launch and post-launch verification |
65
+
66
+ ## What's New in v4.2
67
+
68
+ | Feature | Description |
69
+ |---------|-------------|
70
+ | **Phase 1.5: Hooks Setup** | Automatic KB enforcement via RuVector hooks |
71
+ | **Hook Pre-training** | ReasoningBank seeded with KB-First patterns |
72
+ | **Hook Verification** | Comprehensive verification script (1.5-hooks-verify.sh) |
73
+ | **Global Skill Install** | Install to ~/.claude/skills/ for all repos |
74
+ | **Init Script** | One-command project initialization |
75
+
76
+ ## What's New in v4.1
77
+
78
+ | Feature | Description |
79
+ |---------|-------------|
80
+ | **Greenfield Support** | Full workflow for new projects via PROJECT_INTENTIONS.md |
81
+ | **Interactive Discovery** | Structured questions when no intentions file exists |
82
+ | **IS/SHOULD/COULD Analysis** | Present vision to user before execution |
83
+ | **User Feedback Loop** | Mandatory feedback before proceeding |
84
+ | **CI/CD Pipeline** | GitHub Actions workflow for quality gates |
85
+ | **Verification Scripts** | 8 executable scripts (8.1-8.8) for Phase 8 |
86
+
87
+ ## What's in v4.0
88
+
89
+ | Feature | Description |
90
+ |---------|-------------|
91
+ | **Phase 0: Assessment** | Mandatory scoring before any changes |
92
+ | **Hard Gates** | DO NOT PROCEED enforcement at every phase boundary |
93
+ | **Scoring Formulas** | Explicit 0-100 scoring for KB quality and app compliance |
94
+ | **Swarm Integration** | Parallel execution configuration for all phases |
95
+ | **Delta Tracking** | Before/after comparison with transformation report |
96
+ | **Phase 8 Sub-Phases** | 8 numbered verification checks (8.1-8.8) |
97
+
98
+ ---
99
+
100
+ ## How to Use This Skill
101
+
102
+ When you invoke this skill, Claude will:
103
+
104
+ 1. **Detect** application type (greenfield vs brownfield)
105
+ 2. **Score** existing KB and app compliance (brownfield only)
106
+ 3. **Confirm** transformation scope with user (brownfield only)
107
+ 4. **Identify** which intelligence pattern fits
108
+ 5. **Execute** the 9-phase build process with HARD quality gates
109
+ 6. **Enforce** KB-First rules throughout development
110
+ 7. **Verify** all 8 verification sub-phases pass
111
+ 8. **Report** delta (before/after scores)
112
+
113
+ **Trigger phrases:**
114
+ - "Build [description] with KB-First" (greenfield)
115
+ - "Apply KB-First to my existing app" (brownfield)
116
+ - "Score my existing KB"
117
+ - "What's my app compliance score?"
118
+ - "/kb-first" (invoke skill directly)
119
+
120
+ ---
121
+
122
+ ## ⛔ Critical Rules (NEVER VIOLATE)
123
+
124
+ ```
125
+ ⛔ NEVER skip Phase 0 for brownfield applications
126
+ ⛔ NEVER assume the KB is "good enough" without scoring
127
+ ⛔ NEVER proceed past a gate without verification
128
+ ⛔ NEVER mark a phase complete without running checks
129
+ ⛔ NEVER skip scoring before AND after transformation
130
+ ```
131
+
132
+ ---
133
+
134
+ ## Part 1: Intelligence Architecture
135
+
136
+ ### The Four Technologies
137
+
138
+ Every KB-First application uses some combination of these:
139
+
140
+ #### 1. GNN — Graph Neural Networks (`@ruvector/gnn`)
141
+
142
+ **What it does:** Sees relationships between decisions and predicts cascading effects.
143
+
144
+ **When it's PRIMARY:**
145
+ - Decisions affect other decisions
146
+ - Need to answer "what happens if I do X?"
147
+ - Many interdependent variables
148
+
149
+ **Example domains:** Retirement planning, medical diagnosis, investment portfolios
150
+
151
+ ```typescript
152
+ // GNN simulates decision cascades
153
+ const impact = await gnn.simulate(graph, {
154
+ node: 'ss_claiming_age',
155
+ newValue: 70
156
+ });
157
+ // Returns: effects on tax bracket, Roth space, Medicare premiums, etc.
158
+ ```
159
+
160
+ #### 2. Attention Mechanisms (`@ruvector/attention`)
161
+
162
+ **What it does:** Routes queries to the right expert, compares options, focuses processing.
163
+
164
+ **When it's PRIMARY:**
165
+ - Multiple expert domains (travel: awards vs cash vs positioning)
166
+ - Need to compare many options efficiently
167
+ - Processing large amounts of content
168
+
169
+ **Key mechanisms:**
170
+ | Mechanism | Purpose |
171
+ |-----------|---------|
172
+ | MoE (Mixture of Experts) | Route query to right specialist |
173
+ | Cross-Attention | Compare two or more options |
174
+ | Flash Attention | Fast processing of large content |
175
+ | Graph Attention | Navigate relationship networks |
176
+ | Hyperbolic | Navigate hierarchies |
177
+
178
+ ```typescript
179
+ // MoE routes to the right expert
180
+ const expert = await attention.routeToExpert(query, experts);
181
+ // Returns: best expert(s) for this query
182
+ ```
183
+
184
+ #### 3. SONA — Self-Optimizing Neural Architecture (`@ruvector/sona`)
185
+
186
+ **What it does:** Learns from outcomes and remembers what worked.
187
+
188
+ **When it's PRIMARY:**
189
+ - "What worked for people like me?" is the core value
190
+ - You have feedback to learn from
191
+ - Building institutional knowledge over time
192
+
193
+ **Three learning loops:**
194
+ | Loop | Timing | Function |
195
+ |------|--------|----------|
196
+ | Instant (MicroLoRA) | Per-request | Fine-tune based on immediate feedback |
197
+ | Background (BaseLoRA) | Hourly | Extract patterns from successful interactions |
198
+ | Deep (EWC++) | Weekly | Consolidate without forgetting |
199
+
200
+ ```typescript
201
+ // SONA recalls similar successful patterns
202
+ const patterns = await sona.recallPatterns(userProfile);
203
+ // Returns: what worked for similar users/situations
204
+ ```
205
+
206
+ #### 4. Vector Search (Foundation)
207
+
208
+ **What it does:** Semantic retrieval from the knowledge base.
209
+
210
+ **Always required.** The foundation for all KB-First applications.
211
+
212
+ ```sql
213
+ SELECT title, content, source_expert, confidence,
214
+ embedding <=> $query_embedding AS distance
215
+ FROM kb_nodes
216
+ WHERE namespace = $namespace
217
+ ORDER BY distance
218
+ LIMIT 10;
219
+ ```
220
+
221
+ ---
222
+
223
+ ### Intelligence Pattern Selection
224
+
225
+ Answer these questions to identify your pattern:
226
+
227
+ ```
228
+ Q1: Does changing one variable affect many others?
229
+ YES → Decision Web (GNN-first)
230
+ NO → Continue to Q2
231
+
232
+ Q2: Do you need to route queries to different expert domains?
233
+ YES → Combinatorial Routing (Attention-first)
234
+ NO → Continue to Q3
235
+
236
+ Q3: Is "what worked for similar cases" the core value?
237
+ YES → Scenario Learning (SONA-first)
238
+ NO → Continue to Q4
239
+
240
+ Q4: Is this a continuous monitoring/optimization loop?
241
+ YES → Continuous Optimization (Attention + SONA)
242
+ NO → Standard KB-First (Vector Search primary)
243
+ ```
244
+
245
+ ### Technology Matrix by Pattern
246
+
247
+ | Pattern | GNN | Attention | SONA | Vector |
248
+ |---------|-----|-----------|------|--------|
249
+ | Decision Web | 🔴 PRIMARY | 🟡 Compare | 🟠 Learn patterns | ✅ Foundation |
250
+ | Combinatorial Routing | 🟠 Networks | 🔴 PRIMARY | 🟡 Success patterns | ✅ Foundation |
251
+ | Scenario Learning | 🟠 Dynamics | 🟡 Parameters | 🔴 PRIMARY | ✅ Foundation |
252
+ | Continuous Optimization | 🟡 Structure | 🔴 PRIMARY | 🔴 PRIMARY | ✅ Foundation |
253
+
254
+ ---
255
+
256
+ ## Part 2: The 9-Phase Build Process
257
+
258
+ Every KB-First application is built through these phases with HARD quality gates.
259
+
260
+ ### Phase Overview
261
+
262
+ | Phase | Name | Sub-Phases | Gate Type |
263
+ |-------|------|------------|-----------|
264
+ | 0 | Assessment | 6 | ⛔ User Confirmation |
265
+ | 1 | Storage | 6 | Script Check |
266
+ | 1.5 | Hooks Setup | 4 | Hook Verify |
267
+ | 2 | KB Creation | 8 | Score ≥98 |
268
+ | 3 | Persistence | - | SQL Check |
269
+ | 4 | Visualization | - | Manual/Playwright |
270
+ | 5 | Integration | - | Compile Check |
271
+ | 6 | Scaffold | - | File Check |
272
+ | 7 | Build | 7 | Script Check |
273
+ | 8 | Verification | 8 | All Must Pass |
274
+ | 9 | Security | 6 | Security Audit |
275
+ | 10 | Documentation | 6 | Docs Complete |
276
+ | 11 | Deployment | 6 | Go-Live Check |
277
+
278
+ **Total Sub-Phases:** 57
279
+
280
+ ---
281
+
282
+ ### Phase 0: Assessment (Brownfield Only)
283
+
284
+ **Purpose:** Score existing KB and app BEFORE making any changes.
285
+
286
+ **⛔ MANDATORY for existing applications. DO NOT SKIP.**
287
+
288
+ | Sub-Phase | Name | Output |
289
+ |-----------|------|--------|
290
+ | 0.1 | Detect Application Type | greenfield/brownfield |
291
+ | 0.2 | Score Existing KB | 0-100 score |
292
+ | 0.3 | Score App Compliance | 0-100 score |
293
+ | 0.4 | Generate Gap Report | Detailed gaps list |
294
+ | 0.5 | Calculate Scope | Effort estimate |
295
+ | 0.6 | Get Confirmation | User types "PROCEED" |
296
+
297
+ **Quality Gate:** ⛔ User must type "PROCEED" to continue.
298
+
299
+ **Detailed instructions:** `./phases/00-assessment.md`
300
+
301
+ ---
302
+
303
+ ### Phase 1: Storage Setup
304
+
305
+ **Purpose:** Ensure persistent storage is available.
306
+
307
+ **Steps:**
308
+ ```bash
309
+ # Check for running storage
310
+ docker ps | grep ruvector-db
311
+
312
+ # If not running, start it
313
+ docker run -d --name ruvector-db \
314
+ --restart unless-stopped \
315
+ -e POSTGRES_PASSWORD=${RUVECTOR_PASSWORD:-secret} \
316
+ -p 5432:5432 \
317
+ -v ~/ruvector-data:/var/lib/postgresql/data \
318
+ ruvnet/ruvector-postgres:latest
319
+
320
+ # Verify connection
321
+ export DATABASE_URL="postgresql://postgres:${RUVECTOR_PASSWORD:-secret}@localhost:5432/postgres"
322
+ psql "$DATABASE_URL" -c "SELECT 1"
323
+
324
+ # Initialize schema
325
+ psql "$DATABASE_URL" -f templates/schema.sql
326
+ ```
327
+
328
+ **Quality Gate:** ✅ Connection verified, schema created.
329
+
330
+ **Detailed instructions:** `./phases/01-storage.md`
331
+
332
+ ---
333
+
334
+ ### Phase 1.5: Hooks Setup
335
+
336
+ **Purpose:** Configure Claude Code hooks for automatic KB enforcement.
337
+
338
+ **⛔ CRITICAL: Without hooks, KB-First is an honor system.**
339
+
340
+ | Sub-Phase | Name | Purpose |
341
+ |-----------|------|---------|
342
+ | 1.5.1 | Install Hooks | Install RuVector hook scripts |
343
+ | 1.5.2 | Configure Settings | Update ~/.claude/settings.json |
344
+ | 1.5.3 | Pre-train ReasoningBank | Seed KB-First patterns |
345
+ | 1.5.4 | Verify Functionality | Test hooks fire correctly |
346
+
347
+ **Quick Setup:**
348
+ ```bash
349
+ # Install and configure hooks
350
+ npx @ruvector/cli hooks init
351
+ npx @ruvector/cli hooks install
352
+
353
+ # Pre-train with KB-First patterns
354
+ npx @ruvector/cli reasoningbank seed --kb-first
355
+
356
+ # Verify
357
+ ./scripts/1.5-hooks-verify.sh
358
+ ```
359
+
360
+ **Quality Gate:** ✅ All checks pass in `./scripts/1.5-hooks-verify.sh`
361
+
362
+ **Detailed instructions:** `./phases/01.5-hooks-setup.md`
363
+
364
+ ---
365
+
366
+ ### Phase 2: World-Class Knowledge Base Creation
367
+
368
+ **Purpose:** Build a KB representing the collective expertise of top 100 world experts.
369
+
370
+ This phase has 8 sub-phases:
371
+
372
+ | Sub-Phase | Purpose | Output |
373
+ |-----------|---------|--------|
374
+ | 2.1 | Domain Scoping | Formal definition, boundaries |
375
+ | 2.2 | Perspective Expansion | User types, questions, edge cases |
376
+ | 2.3 | Expert Discovery | 100 experts, 500+ content items, 1000+ insights |
377
+ | 2.4 | Completeness Audit | 30+ identified gaps |
378
+ | 2.5 | Gap Filling | All gaps addressed with sources |
379
+ | 2.6 | Structure Organization | ≤9 primary nodes, unlimited depth |
380
+ | 2.7 | Recursive Depth | Actual data at all leaf nodes |
381
+ | 2.8 | Quality Loop | Iterate until score ≥98/100 |
382
+
383
+ **Key prompts:**
384
+ - Expert discovery: `./prompts/expert-discovery.md`
385
+ - Completeness audit: `./prompts/completeness-audit.md`
386
+ - Quality critique: `./prompts/quality-critique.md`
387
+
388
+ **Quality Gate:** ✅ KB score ≥98/100, all sub-phases complete.
389
+
390
+ **Detailed instructions:** `./phases/02-kb-creation.md`
391
+
392
+ ---
393
+
394
+ ### Phase 3: Persistence & Verification
395
+
396
+ **Purpose:** Store KB to PostgreSQL with embeddings and verify retrieval.
397
+
398
+ **Steps:**
399
+ 1. Generate embeddings for all content
400
+ 2. Insert nodes with expert attribution
401
+ 3. Create HNSW index for fast search
402
+ 4. Verify semantic search returns relevant results
403
+ 5. Generate KB statistics report
404
+
405
+ ```typescript
406
+ // Verify search quality
407
+ const results = await searchKB("withdrawal rate retirement", namespace);
408
+ assert(results.length > 0);
409
+ assert(results[0].sourceExpert); // Must have attribution
410
+ assert(results[0].confidence >= 0.5); // Must have confidence
411
+ ```
412
+
413
+ **Quality Gate:** ✅ All nodes persisted, semantic search returns relevant results.
414
+
415
+ **Detailed instructions:** `./phases/03-persistence.md`
416
+
417
+ ---
418
+
419
+ ### Phase 4: Visualization
420
+
421
+ **Purpose:** Generate interactive visualization for human verification.
422
+
423
+ **Requirements:**
424
+ - Interactive tree (expandable/collapsible)
425
+ - Click node to see content + sources
426
+ - Search functionality
427
+ - Breadcrumb navigation
428
+ - Statistics display
429
+
430
+ **Quality Gate:** ✅ Full tree renders, navigation works, leaf content visible with sources.
431
+
432
+ **Detailed instructions:** `./phases/04-visualization.md`
433
+
434
+ ---
435
+
436
+ ### Phase 5: KB Integration Layer
437
+
438
+ **Purpose:** Generate TypeScript SDK for application to access KB.
439
+
440
+ **Output structure:**
441
+ ```
442
+ src/kb/
443
+ ├── client.ts # Query functions
444
+ ├── types.ts # TypeScript interfaces
445
+ ├── tree.ts # Tree navigation
446
+ ├── validator.ts # Startup verification
447
+ └── index.ts # Single export
448
+ ```
449
+
450
+ **The SDK enforces:**
451
+ - All queries return sources
452
+ - Confidence scores on all results
453
+ - Gap logging for unanswered queries
454
+ - Connection verification on startup
455
+
456
+ **Quality Gate:** ✅ All files compile, exports work.
457
+
458
+ **Detailed instructions:** `./phases/05-integration.md`
459
+
460
+ ---
461
+
462
+ ### Phase 6: Application Scaffold
463
+
464
+ **Purpose:** Create project structure with KB enforcement built in.
465
+
466
+ **Output structure:**
467
+ ```
468
+ [PROJECT]/
469
+ ├── src/
470
+ │ ├── kb/ # FROM PHASE 5 (read-only)
471
+ │ ├── domain/ # Domain logic (MUST use kb/)
472
+ │ ├── api/ # Routes
473
+ │ ├── components/ # UI
474
+ │ ├── pages/ # Page compositions
475
+ │ └── index.ts # Entry point (KB verification FIRST)
476
+ ├── visualization/ # FROM PHASE 4
477
+ └── KB_ENFORCEMENT.md # Rules document
478
+ ```
479
+
480
+ **Quality Gate:** ✅ Structure complete, entry point verifies KB first.
481
+
482
+ **Detailed instructions:** `./phases/06-scaffold.md`
483
+
484
+ ---
485
+
486
+ ### Phase 7: Application Build (KB Enforced)
487
+
488
+ **Purpose:** Build the application with strict KB enforcement.
489
+
490
+ **⚠️ THIS IS WHERE SHORTCUTS HAPPEN. MAXIMUM ENFORCEMENT.**
491
+
492
+ ### KB Enforcement Rules
493
+
494
+ ```
495
+ RULE 1: No hardcoded domain logic
496
+ ❌ const rate = 0.04;
497
+ ✅ const rate = await kb.search("withdrawal rate");
498
+
499
+ RULE 2: Every domain function queries KB
500
+ Every file in src/domain/ imports from ../kb
501
+
502
+ RULE 3: All responses include kbSources
503
+ Traceability is mandatory
504
+
505
+ RULE 4: Startup verification required
506
+ App exits if KB unavailable
507
+
508
+ RULE 5: No fallback logic
509
+ ❌ rules = kb.get() || DEFAULT_RULES
510
+ ✅ rules = kb.get(); if (!rules) throw Error("KB missing");
511
+ ```
512
+
513
+ ### Build Sequence
514
+
515
+ 1. Generate `KB_ENFORCEMENT.md` (keep in context always)
516
+ 2. Plan domain functions (list them all first)
517
+ 3. Implement ONE function at a time
518
+ 4. **VERIFY after EACH function:**
519
+ - Does it import from kb/?
520
+ - Does it return kbSources?
521
+ - Any hardcoded values?
522
+ - If FAIL → fix before continuing
523
+ 5. Implement API layer
524
+ 6. Implement UI
525
+ 7. Implement pages
526
+ 8. Integration testing
527
+
528
+ **Quality Gate:** ✅ All functions verified, no hardcoded values, all responses have kbSources.
529
+
530
+ **Detailed instructions:** `./phases/07-build.md`
531
+
532
+ ---
533
+
534
+ ### Phase 8: Final Verification
535
+
536
+ **Purpose:** Comprehensive check that all rules are followed.
537
+
538
+ **Verification checklist:**
539
+ ```
540
+ [ ] No hardcoded domain values (grep for patterns)
541
+ [ ] All domain files import from kb/
542
+ [ ] All responses include kbSources array
543
+ [ ] Startup verifies KB connection before anything else
544
+ [ ] No fallback logic (no || DEFAULT patterns)
545
+ [ ] All experts have attribution
546
+ [ ] All nodes have confidence scores
547
+ [ ] Gap logging is active
548
+ [ ] Intelligence layer (GNN/Attention/SONA) properly integrated
549
+ ```
550
+
551
+ **Quality Gate:** ✅ All checks pass.
552
+
553
+ **Detailed instructions:** `./phases/08-verification.md`
554
+
555
+ ---
556
+
557
+ ### Phase 9: Security Audit
558
+
559
+ **Purpose:** Ensure the application has no security vulnerabilities before production.
560
+
561
+ | Sub-Phase | Name | Purpose |
562
+ |-----------|------|---------|
563
+ | 9.1 | Dependency Audit | Check for vulnerable packages |
564
+ | 9.2 | OWASP Top 10 | Common vulnerability scan |
565
+ | 9.3 | SQL Injection | Verify parameterized queries |
566
+ | 9.4 | Auth & Authz | Verify access controls |
567
+ | 9.5 | Secrets | No hardcoded secrets |
568
+ | 9.6 | API Security | Rate limiting, CORS, validation |
569
+
570
+ **Quick Check:**
571
+ ```bash
572
+ ./scripts/9-security-audit.sh
573
+ ```
574
+
575
+ **Quality Gate:** ✅ Security audit passes with 0 critical/high issues.
576
+
577
+ **Detailed instructions:** `./phases/09-security.md`
578
+
579
+ ---
580
+
581
+ ### Phase 10: Documentation & Versioning
582
+
583
+ **Purpose:** Complete documentation and proper versioning before production.
584
+
585
+ | Sub-Phase | Name | Purpose |
586
+ |-----------|------|---------|
587
+ | 10.1 | README | Complete project overview |
588
+ | 10.2 | API Docs | OpenAPI/Swagger specification |
589
+ | 10.3 | KB Schema | Knowledge base structure docs |
590
+ | 10.4 | Architecture | System design and diagrams |
591
+ | 10.5 | Operator Guide | Deployment and operations |
592
+ | 10.6 | Versioning | SemVer, changelog, releases |
593
+
594
+ **Quality Gate:** ✅ All documentation complete and accurate.
595
+
596
+ **Detailed instructions:** `./phases/10-documentation.md`
597
+
598
+ ---
599
+
600
+ ### Phase 11: Deployment Planning
601
+
602
+ **Purpose:** Deploy to production with public access.
603
+
604
+ | Sub-Phase | Name | Purpose |
605
+ |-----------|------|---------|
606
+ | 11.1 | Infrastructure | Select and provision hosting |
607
+ | 11.2 | Environment | Production configuration |
608
+ | 11.3 | CI/CD | Automated deployment pipeline |
609
+ | 11.4 | Database | Production DB setup/migration |
610
+ | 11.5 | Monitoring | Observability and alerting |
611
+ | 11.6 | Go-Live | Final verification and launch |
612
+
613
+ **Quality Gate:** ✅ Application live with monitoring active.
614
+
615
+ **Detailed instructions:** `./phases/11-deployment.md`
616
+
617
+ ---
618
+
619
+ ## Part 3: Pattern Implementation Guides
620
+
621
+ Detailed implementation guides for each pattern:
622
+
623
+ | Pattern | Guide |
624
+ |---------|-------|
625
+ | Decision Web | `./patterns/decision-web.md` |
626
+ | Combinatorial Routing | `./patterns/combinatorial-routing.md` |
627
+ | Scenario Learning | `./patterns/scenario-learning.md` |
628
+ | Continuous Optimization | `./patterns/continuous-optimization.md` |
629
+
630
+ ---
631
+
632
+ ## Part 4: Quick Reference
633
+
634
+ ### SONA Configuration by Domain
635
+
636
+ | Domain Stability | ewc_lambda | base_lora_rank | pattern_threshold |
637
+ |------------------|------------|----------------|-------------------|
638
+ | Very stable (finance, law) | 0.6 | 16 | 0.8 |
639
+ | Moderate (business, travel) | 0.4 | 8-12 | 0.7 |
640
+ | Fast-changing (SEO, markets) | 0.2 | 4-8 | 0.6 |
641
+
642
+ ### Attention Mechanism Selection
643
+
644
+ | Task | Mechanism |
645
+ |------|-----------|
646
+ | Route to expert | MoE |
647
+ | Compare 2 options | Cross-attention |
648
+ | Compare many options | Cross-attention + batching |
649
+ | Process long document | Flash attention |
650
+ | Process 8K+ tokens | Linear attention |
651
+ | Navigate hierarchy | Hyperbolic attention |
652
+ | Navigate graph | Graph attention |
653
+
654
+ ### File References
655
+
656
+ | Reference | Path |
657
+ |-----------|------|
658
+ | PostgreSQL Functions | `./references/ruvector-functions.md` |
659
+ | Attention Mechanisms | `./references/attention-mechanisms.md` |
660
+ | SONA Configuration | `./references/sona-config.md` |
661
+ | Claude Code Hooks | `./references/hooks-integration.md` |
662
+
663
+ ### Templates
664
+
665
+ | Template | Path |
666
+ |----------|------|
667
+ | Database Schema | `./templates/schema.sql` |
668
+ | KB Client | `./templates/kb-client.ts` |
669
+ | GNN Engine | `./templates/gnn-engine.ts` |
670
+ | Attention Router | `./templates/attention-router.ts` |
671
+ | SONA Config | `./templates/sona-config.ts` |
672
+
673
+ ---
674
+
675
+ ## Part 5: Diagnostic Mode
676
+
677
+ When reviewing an existing application, Claude checks:
678
+
679
+ ### 1. Pattern Identification
680
+ - What intelligence pattern does this application need?
681
+ - Is it currently implemented correctly?
682
+
683
+ ### 2. Missing Intelligence
684
+ - **Decision Web apps:** Is GNN implemented? Are relationships modeled?
685
+ - **Routing apps:** Is MoE routing to experts? Are experts defined?
686
+ - **Learning apps:** Is SONA configured? Is outcome tracking present?
687
+ - **Optimization apps:** Is the feedback loop closed?
688
+
689
+ ### 3. KB Enforcement
690
+ - Are all domain values from KB?
691
+ - Do all responses have sources?
692
+ - Is startup verification in place?
693
+ - Is gap logging active?
694
+
695
+ ### 4. Configuration Issues
696
+ - Is SONA ewc_lambda appropriate for domain stability?
697
+ - Are attention mechanisms matching cognitive tasks?
698
+ - Is graph structure complete (for GNN apps)?
699
+
700
+ ### Diagnostic Checklist
701
+
702
+ ```
703
+ INTELLIGENCE LAYER:
704
+ [ ] Primary technology identified and implemented
705
+ [ ] Secondary technology integrated
706
+ [ ] Tertiary technology available
707
+
708
+ KB ENFORCEMENT:
709
+ [ ] No hardcoded domain values
710
+ [ ] All responses have kbSources
711
+ [ ] Expert attribution on all nodes
712
+ [ ] Confidence scores present
713
+ [ ] Gap detection active
714
+ [ ] Startup verification present
715
+
716
+ CONFIGURATION:
717
+ [ ] SONA ewc_lambda matches domain stability
718
+ [ ] Attention mechanisms match tasks
719
+ [ ] Graph relationships complete (if GNN)
720
+ [ ] Expert domains defined (if MoE)
721
+ ```
722
+
723
+ ---
724
+
725
+ ## The Core Principle
726
+
727
+ **Your knowledge base is not just storage. It's the foundation for a reasoning system.**
728
+
729
+ - **Vector search** finds relevant content
730
+ - **GNN** sees how things connect and cascade
731
+ - **Attention** routes to the right expertise and compares options
732
+ - **SONA** remembers what worked
733
+
734
+ The magic happens when these work together. A retirement advisor that just searches is a fancy FAQ. A retirement advisor with GNN modeling decision interdependencies, SONA learning from thousands of users, and cross-attention comparing scenarios — that's an intelligent system that gets smarter over time.
735
+
736
+ **Build intelligence, not just retrieval.**
737
+
738
+ ---
739
+
740
+ *KB-First v3.0 — Intelligence-First Architecture*