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
@@ -0,0 +1,613 @@
1
+ # Phase 10: Documentation & Versioning
2
+
3
+ Updated: 2026-01-02 00:20:00 EST | Version 1.0.0
4
+ Created: 2026-01-02 00:20:00 EST
5
+
6
+ ## Purpose
7
+
8
+ Ensure the application has complete, accurate documentation and proper versioning before production deployment. Good documentation is not optional—it's a quality requirement.
9
+
10
+ ---
11
+
12
+ ## Prerequisites
13
+
14
+ - Phase 9 complete (security audit passed)
15
+ - Application fully functional
16
+ - All tests passing
17
+
18
+ ---
19
+
20
+ ## Why Documentation Matters for KB-First Apps
21
+
22
+ KB-First applications are **knowledge systems**. If the application itself isn't well-documented:
23
+ - Users won't trust the expert knowledge it provides
24
+ - Maintainers won't understand how KB enforcement works
25
+ - Contributors won't know how to add to the KB
26
+ - Operators won't know how to monitor or troubleshoot
27
+
28
+ **The documentation IS part of the product.**
29
+
30
+ ---
31
+
32
+ ## Sub-Phases
33
+
34
+ | Sub-Phase | Name | Purpose |
35
+ |-----------|------|---------|
36
+ | 10.1 | README Complete | Project overview, quick start, usage |
37
+ | 10.2 | API Documentation | All endpoints documented |
38
+ | 10.3 | KB Schema Documentation | Knowledge structure documented |
39
+ | 10.4 | Architecture Docs | System design, decisions, diagrams |
40
+ | 10.5 | Operator Guide | Deployment, monitoring, troubleshooting |
41
+ | 10.6 | Versioning Setup | SemVer, changelog, release process |
42
+
43
+ ---
44
+
45
+ ## 10.1 README Complete
46
+
47
+ The README is the first thing users see. It must answer:
48
+
49
+ 1. **What is this?** (1-2 sentences)
50
+ 2. **Why should I use it?** (key benefits)
51
+ 3. **How do I get started?** (quick start)
52
+ 4. **How do I use it?** (basic usage)
53
+ 5. **Where do I get help?** (links to docs, issues)
54
+
55
+ ### README Template
56
+
57
+ ```markdown
58
+ # [Project Name]
59
+
60
+ [One-line description of what this application does]
61
+
62
+ ## Features
63
+
64
+ - Feature 1: [Brief description]
65
+ - Feature 2: [Brief description]
66
+ - Feature 3: [Brief description]
67
+
68
+ ## Quick Start
69
+
70
+ \`\`\`bash
71
+ # Prerequisites
72
+ - Docker
73
+ - Node.js 18+
74
+
75
+ # Installation
76
+ git clone [repo]
77
+ cd [project]
78
+ npm install
79
+
80
+ # Start
81
+ docker-compose up -d
82
+ npm run start
83
+ \`\`\`
84
+
85
+ ## Usage
86
+
87
+ [Basic usage examples]
88
+
89
+ ## Documentation
90
+
91
+ - [API Reference](docs/api.md)
92
+ - [Architecture](docs/architecture.md)
93
+ - [Operator Guide](docs/operator-guide.md)
94
+ - [Contributing](CONTRIBUTING.md)
95
+
96
+ ## License
97
+
98
+ [License name] - See [LICENSE](LICENSE) for details.
99
+ ```
100
+
101
+ ### Verification
102
+
103
+ ```bash
104
+ #!/bin/bash
105
+ # scripts/10.1-readme-check.sh
106
+
107
+ echo "=== 10.1 README Completeness ==="
108
+
109
+ REQUIRED_SECTIONS=(
110
+ "# " # Title
111
+ "## Features" # or similar
112
+ "## Quick Start\|## Installation\|## Getting Started"
113
+ "## Usage"
114
+ "## Documentation\|## Docs"
115
+ "## License"
116
+ )
117
+
118
+ PASS=0
119
+ FAIL=0
120
+
121
+ for section in "${REQUIRED_SECTIONS[@]}"; do
122
+ if grep -qE "$section" README.md 2>/dev/null; then
123
+ echo "✅ Found: $section"
124
+ PASS=$((PASS + 1))
125
+ else
126
+ echo "❌ Missing: $section"
127
+ FAIL=$((FAIL + 1))
128
+ fi
129
+ done
130
+
131
+ echo ""
132
+ echo "Results: $PASS passed, $FAIL failed"
133
+ [ $FAIL -eq 0 ] && exit 0 || exit 1
134
+ ```
135
+
136
+ ---
137
+
138
+ ## 10.2 API Documentation
139
+
140
+ Every API endpoint must be documented with:
141
+
142
+ 1. **Endpoint** (method, path)
143
+ 2. **Description** (what it does)
144
+ 3. **Authentication** (required or not)
145
+ 4. **Request** (parameters, body schema)
146
+ 5. **Response** (success and error schemas)
147
+ 6. **Example** (curl or code snippet)
148
+
149
+ ### OpenAPI/Swagger
150
+
151
+ Generate from code or write manually:
152
+
153
+ ```yaml
154
+ # openapi.yaml
155
+ openapi: 3.0.0
156
+ info:
157
+ title: [App Name] API
158
+ version: 1.0.0
159
+ description: API for [description]
160
+
161
+ paths:
162
+ /api/search:
163
+ post:
164
+ summary: Search the knowledge base
165
+ description: Semantic search across KB nodes
166
+ security:
167
+ - bearerAuth: []
168
+ requestBody:
169
+ required: true
170
+ content:
171
+ application/json:
172
+ schema:
173
+ type: object
174
+ required:
175
+ - query
176
+ properties:
177
+ query:
178
+ type: string
179
+ description: Search query
180
+ example: "withdrawal rate retirement"
181
+ namespace:
182
+ type: string
183
+ description: KB namespace to search
184
+ limit:
185
+ type: integer
186
+ default: 10
187
+ maximum: 100
188
+ responses:
189
+ '200':
190
+ description: Search results
191
+ content:
192
+ application/json:
193
+ schema:
194
+ type: object
195
+ properties:
196
+ results:
197
+ type: array
198
+ items:
199
+ $ref: '#/components/schemas/KBNode'
200
+ kbSources:
201
+ type: array
202
+ items:
203
+ $ref: '#/components/schemas/KBSource'
204
+ '401':
205
+ description: Unauthorized
206
+ '429':
207
+ description: Rate limit exceeded
208
+
209
+ components:
210
+ schemas:
211
+ KBNode:
212
+ type: object
213
+ properties:
214
+ id:
215
+ type: string
216
+ title:
217
+ type: string
218
+ content:
219
+ type: string
220
+ source_expert:
221
+ type: string
222
+ confidence:
223
+ type: number
224
+ minimum: 0
225
+ maximum: 1
226
+ KBSource:
227
+ type: object
228
+ properties:
229
+ title:
230
+ type: string
231
+ expert:
232
+ type: string
233
+ confidence:
234
+ type: number
235
+ securitySchemes:
236
+ bearerAuth:
237
+ type: http
238
+ scheme: bearer
239
+ ```
240
+
241
+ ### Generate Docs from OpenAPI
242
+
243
+ ```bash
244
+ # Install Swagger UI
245
+ npm install swagger-ui-express
246
+
247
+ # Or generate static docs
248
+ npx redoc-cli bundle openapi.yaml -o docs/api.html
249
+ ```
250
+
251
+ ### Verification
252
+
253
+ ```bash
254
+ #!/bin/bash
255
+ # scripts/10.2-api-docs.sh
256
+
257
+ echo "=== 10.2 API Documentation ==="
258
+
259
+ PASS=0
260
+ FAIL=0
261
+
262
+ # Check for OpenAPI spec
263
+ if [ -f "openapi.yaml" ] || [ -f "openapi.json" ] || [ -f "swagger.yaml" ]; then
264
+ echo "✅ OpenAPI specification found"
265
+ PASS=$((PASS + 1))
266
+ else
267
+ echo "❌ No OpenAPI specification found"
268
+ FAIL=$((FAIL + 1))
269
+ fi
270
+
271
+ # Check for API docs
272
+ if [ -f "docs/api.md" ] || [ -f "docs/api.html" ] || [ -d "docs/api" ]; then
273
+ echo "✅ API documentation found"
274
+ PASS=$((PASS + 1))
275
+ else
276
+ echo "❌ No API documentation found"
277
+ FAIL=$((FAIL + 1))
278
+ fi
279
+
280
+ # Check that all routes are documented
281
+ ROUTES=$(grep -rh "app\.\(get\|post\|put\|delete\|patch\)" src/ 2>/dev/null | wc -l)
282
+ if [ "$ROUTES" -gt 0 ]; then
283
+ echo "ℹ️ Found $ROUTES route definitions - ensure all are documented"
284
+ fi
285
+
286
+ echo ""
287
+ echo "Results: $PASS passed, $FAIL failed"
288
+ [ $FAIL -eq 0 ] && exit 0 || exit 1
289
+ ```
290
+
291
+ ---
292
+
293
+ ## 10.3 KB Schema Documentation
294
+
295
+ Document the knowledge base structure:
296
+
297
+ ### KB Schema Document
298
+
299
+ ```markdown
300
+ # Knowledge Base Schema
301
+
302
+ ## Overview
303
+
304
+ This knowledge base contains [domain] expertise from [X] experts.
305
+
306
+ ## Namespaces
307
+
308
+ | Namespace | Description | Node Count |
309
+ |-----------|-------------|------------|
310
+ | [namespace1] | [description] | [count] |
311
+ | [namespace2] | [description] | [count] |
312
+
313
+ ## Node Structure
314
+
315
+ Each KB node contains:
316
+
317
+ | Field | Type | Description |
318
+ |-------|------|-------------|
319
+ | id | UUID | Unique identifier |
320
+ | title | string | Node title (searchable) |
321
+ | content | text | Full content |
322
+ | path | ltree | Hierarchical path |
323
+ | source_expert | string | Expert attribution |
324
+ | confidence | float | Confidence score (0-1) |
325
+ | embedding | vector(384) | Semantic embedding |
326
+ | namespace | string | Isolation namespace |
327
+ | created_at | timestamp | Creation time |
328
+ | updated_at | timestamp | Last update |
329
+
330
+ ## Topic Hierarchy
331
+
332
+ [Tree diagram or list showing KB structure]
333
+
334
+ ## Expert Sources
335
+
336
+ | Expert | Domain | Node Count | Avg Confidence |
337
+ |--------|--------|------------|----------------|
338
+ | [name] | [domain] | [count] | [avg] |
339
+
340
+ ## Gap Tracking
341
+
342
+ Unanswered queries are logged to `kb_gaps` for KB improvement.
343
+
344
+ | Field | Description |
345
+ |-------|-------------|
346
+ | query | The unanswered query |
347
+ | context | Additional context (JSON) |
348
+ | created_at | When the gap was detected |
349
+ ```
350
+
351
+ ---
352
+
353
+ ## 10.4 Architecture Documentation
354
+
355
+ ### Required Diagrams
356
+
357
+ 1. **System Context** - How the app fits in the larger ecosystem
358
+ 2. **Container Diagram** - Major components (app, DB, external services)
359
+ 3. **Component Diagram** - Internal structure
360
+ 4. **Data Flow** - How data moves through the system
361
+
362
+ ### Architecture Decision Records (ADRs)
363
+
364
+ Document key decisions:
365
+
366
+ ```markdown
367
+ # ADR-001: Use PostgreSQL with pgvector for KB Storage
368
+
369
+ ## Status
370
+ Accepted
371
+
372
+ ## Context
373
+ We need persistent storage for the knowledge base with semantic search capabilities.
374
+
375
+ ## Decision
376
+ Use PostgreSQL with the pgvector extension for vector storage and similarity search.
377
+
378
+ ## Consequences
379
+ - **Positive:** Single database for all data, mature ecosystem, strong consistency
380
+ - **Negative:** Requires vector extension, may need tuning for large KBs
381
+ - **Neutral:** Team already familiar with PostgreSQL
382
+ ```
383
+
384
+ ### Architecture Document Template
385
+
386
+ ```markdown
387
+ # Architecture Documentation
388
+
389
+ ## System Overview
390
+
391
+ [High-level description]
392
+
393
+ ## Components
394
+
395
+ ### Knowledge Base Layer
396
+ - PostgreSQL with pgvector
397
+ - kb_nodes table with embeddings
398
+ - HNSW index for fast search
399
+
400
+ ### Intelligence Layer
401
+ - GNN for decision modeling (if applicable)
402
+ - Attention routing (if applicable)
403
+ - SONA learning (if applicable)
404
+
405
+ ### Application Layer
406
+ - Node.js/Express API
407
+ - React frontend
408
+ - KB client library
409
+
410
+ ### Infrastructure
411
+ - Docker containers
412
+ - [Cloud provider] hosting
413
+ - [CDN] for static assets
414
+
415
+ ## Data Flow
416
+
417
+ [Diagram or description]
418
+
419
+ ## Security Model
420
+
421
+ [Authentication, authorization, encryption]
422
+
423
+ ## Scalability
424
+
425
+ [How the system scales]
426
+ ```
427
+
428
+ ---
429
+
430
+ ## 10.5 Operator Guide
431
+
432
+ For teams deploying and maintaining the application:
433
+
434
+ ```markdown
435
+ # Operator Guide
436
+
437
+ ## Prerequisites
438
+
439
+ - Docker 20+
440
+ - 4GB RAM minimum
441
+ - 20GB disk space
442
+
443
+ ## Deployment
444
+
445
+ ### Environment Variables
446
+
447
+ | Variable | Required | Description | Example |
448
+ |----------|----------|-------------|---------|
449
+ | DATABASE_URL | Yes | PostgreSQL connection | postgres://... |
450
+ | JWT_SECRET | Yes | JWT signing key | [random 256-bit] |
451
+ | ALLOWED_ORIGINS | Yes | CORS origins | https://app.com |
452
+
453
+ ### Docker Deployment
454
+
455
+ \`\`\`bash
456
+ docker-compose up -d
457
+ \`\`\`
458
+
459
+ ### Kubernetes Deployment
460
+
461
+ [Helm chart or kubectl instructions]
462
+
463
+ ## Monitoring
464
+
465
+ ### Health Checks
466
+
467
+ - `/health` - Basic health
468
+ - `/health/db` - Database connectivity
469
+ - `/health/kb` - KB accessibility
470
+
471
+ ### Metrics
472
+
473
+ Prometheus metrics available at `/metrics`:
474
+ - `kb_search_duration_seconds` - Search latency
475
+ - `kb_gap_total` - Gap count
476
+ - `kb_node_count` - Total KB nodes
477
+
478
+ ### Alerts
479
+
480
+ [Recommended alerting thresholds]
481
+
482
+ ## Troubleshooting
483
+
484
+ ### Common Issues
485
+
486
+ #### "KB unavailable" at startup
487
+ 1. Check DATABASE_URL is correct
488
+ 2. Verify PostgreSQL is running
489
+ 3. Check network connectivity
490
+
491
+ #### Slow searches
492
+ 1. Check HNSW index exists
493
+ 2. Monitor query explain plans
494
+ 3. Consider increasing work_mem
495
+
496
+ ## Backup & Recovery
497
+
498
+ ### Backup
499
+
500
+ \`\`\`bash
501
+ pg_dump $DATABASE_URL > backup.sql
502
+ \`\`\`
503
+
504
+ ### Recovery
505
+
506
+ \`\`\`bash
507
+ psql $DATABASE_URL < backup.sql
508
+ \`\`\`
509
+
510
+ ## Updates
511
+
512
+ [Process for updating the application]
513
+ ```
514
+
515
+ ---
516
+
517
+ ## 10.6 Versioning Setup
518
+
519
+ ### Semantic Versioning
520
+
521
+ Use [SemVer](https://semver.org/):
522
+ - **MAJOR** (X.0.0): Breaking changes
523
+ - **MINOR** (0.X.0): New features, backward compatible
524
+ - **PATCH** (0.0.X): Bug fixes, backward compatible
525
+
526
+ ### package.json Version
527
+
528
+ ```json
529
+ {
530
+ "name": "your-app",
531
+ "version": "1.0.0"
532
+ }
533
+ ```
534
+
535
+ ### CHANGELOG.md
536
+
537
+ ```markdown
538
+ # Changelog
539
+
540
+ All notable changes to this project will be documented in this file.
541
+
542
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
543
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
544
+
545
+ ## [Unreleased]
546
+
547
+ ### Added
548
+ - [New feature]
549
+
550
+ ### Changed
551
+ - [Changed feature]
552
+
553
+ ### Fixed
554
+ - [Bug fix]
555
+
556
+ ## [1.0.0] - 2026-01-02
557
+
558
+ ### Added
559
+ - Initial release
560
+ - KB-First architecture implementation
561
+ - Phase 0-11 build process
562
+ - Security hardening
563
+ - Complete documentation
564
+
565
+ [Unreleased]: https://github.com/user/repo/compare/v1.0.0...HEAD
566
+ [1.0.0]: https://github.com/user/repo/releases/tag/v1.0.0
567
+ ```
568
+
569
+ ### Version Bump Script
570
+
571
+ ```bash
572
+ #!/bin/bash
573
+ # scripts/bump-version.sh
574
+
575
+ VERSION_TYPE=${1:-patch} # major, minor, or patch
576
+
577
+ # Bump version
578
+ npm version $VERSION_TYPE --no-git-tag-version
579
+
580
+ # Get new version
581
+ NEW_VERSION=$(node -p "require('./package.json').version")
582
+
583
+ echo "Bumped to version $NEW_VERSION"
584
+ echo ""
585
+ echo "Next steps:"
586
+ echo " 1. Update CHANGELOG.md"
587
+ echo " 2. Commit: git commit -am 'Release v$NEW_VERSION'"
588
+ echo " 3. Tag: git tag v$NEW_VERSION"
589
+ echo " 4. Push: git push && git push --tags"
590
+ ```
591
+
592
+ ---
593
+
594
+ ## Quality Gate Checklist
595
+
596
+ Before proceeding to Phase 11, verify:
597
+
598
+ - [ ] README is complete (10.1 script passes)
599
+ - [ ] API documentation exists (OpenAPI spec or equivalent)
600
+ - [ ] KB schema is documented
601
+ - [ ] Architecture documentation exists with diagrams
602
+ - [ ] Operator guide is complete
603
+ - [ ] CHANGELOG.md exists and is current
604
+ - [ ] Version is set correctly in package.json
605
+ - [ ] All documentation has been reviewed for accuracy
606
+
607
+ ---
608
+
609
+ ## Exit Criteria
610
+
611
+ All documentation is complete and accurate. Versioning is properly configured.
612
+
613
+ **Proceed to Phase 11: Deployment Planning**