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.
- package/LICENSE +21 -0
- package/README.md +674 -0
- package/SKILL.md +740 -0
- package/bin/kb-first.js +123 -0
- package/install/init-project.sh +435 -0
- package/install/install-global.sh +257 -0
- package/install/kb-first-autodetect.sh +108 -0
- package/install/kb-first-command.md +80 -0
- package/install/kb-first-skill.md +262 -0
- package/package.json +87 -0
- package/phases/00-assessment.md +529 -0
- package/phases/01-storage.md +194 -0
- package/phases/01.5-hooks-setup.md +521 -0
- package/phases/02-kb-creation.md +413 -0
- package/phases/03-persistence.md +125 -0
- package/phases/04-visualization.md +170 -0
- package/phases/05-integration.md +114 -0
- package/phases/06-scaffold.md +130 -0
- package/phases/07-build.md +493 -0
- package/phases/08-verification.md +597 -0
- package/phases/09-security.md +512 -0
- package/phases/10-documentation.md +613 -0
- package/phases/11-deployment.md +670 -0
- package/phases/testing.md +713 -0
- package/scripts/1.5-hooks-verify.sh +252 -0
- package/scripts/8.1-code-scan.sh +58 -0
- package/scripts/8.2-import-check.sh +42 -0
- package/scripts/8.3-source-returns.sh +52 -0
- package/scripts/8.4-startup-verify.sh +65 -0
- package/scripts/8.5-fallback-check.sh +63 -0
- package/scripts/8.6-attribution.sh +56 -0
- package/scripts/8.7-confidence.sh +56 -0
- package/scripts/8.8-gap-logging.sh +70 -0
- package/scripts/9-security-audit.sh +202 -0
- package/scripts/init-project.sh +395 -0
- package/scripts/verify-enforcement.sh +167 -0
- package/src/commands/hooks.js +361 -0
- package/src/commands/init.js +315 -0
- package/src/commands/phase.js +372 -0
- package/src/commands/score.js +380 -0
- package/src/commands/status.js +193 -0
- package/src/commands/verify.js +286 -0
- package/src/index.js +56 -0
- package/src/mcp-server.js +412 -0
- package/templates/attention-router.ts +534 -0
- package/templates/code-analysis.ts +683 -0
- package/templates/federated-kb-learner.ts +649 -0
- package/templates/gnn-engine.ts +1091 -0
- package/templates/intentions.md +277 -0
- package/templates/kb-client.ts +905 -0
- package/templates/schema.sql +303 -0
- package/templates/sona-config.ts +312 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# Phase 5: KB Integration Layer
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
Generate a TypeScript SDK that the application uses to access the knowledge base. This becomes the **only** way the app interacts with the KB.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Output Structure
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
src/kb/
|
|
13
|
+
├── client.ts # Core query functions
|
|
14
|
+
├── types.ts # TypeScript interfaces
|
|
15
|
+
├── tree.ts # Tree navigation functions
|
|
16
|
+
├── validator.ts # Startup verification
|
|
17
|
+
└── index.ts # Single export point
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Template: types.ts
|
|
23
|
+
|
|
24
|
+
See `templates/kb-client.ts` for the full implementation.
|
|
25
|
+
|
|
26
|
+
Key interfaces:
|
|
27
|
+
- `KBNode` — A knowledge base node
|
|
28
|
+
- `KBSource` — Attribution for a response
|
|
29
|
+
- `KBResponse<T>` — Wrapper with sources and confidence
|
|
30
|
+
- `KBHealth` — Connection health status
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Template: client.ts
|
|
35
|
+
|
|
36
|
+
Core functions:
|
|
37
|
+
- `search(query, namespace)` — Semantic search
|
|
38
|
+
- `getByPath(namespace, path)` — Get specific node
|
|
39
|
+
- `getChildren(namespace, path)` — Get child nodes
|
|
40
|
+
- `logGap(query, namespace)` — Log unanswered query
|
|
41
|
+
|
|
42
|
+
Every function returns `KBResponse<T>` with:
|
|
43
|
+
- `data` — The actual result
|
|
44
|
+
- `kbSources` — Expert attribution
|
|
45
|
+
- `confidence` — 0.0-1.0 score
|
|
46
|
+
- `gap` — Whether this was unanswerable
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## Template: validator.ts
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
export async function verifyConnection(): Promise<KBHealth> {
|
|
54
|
+
try {
|
|
55
|
+
const result = await pool.query(`
|
|
56
|
+
SELECT
|
|
57
|
+
COUNT(*) as node_count,
|
|
58
|
+
(SELECT COUNT(*) FROM kb_gaps) as gap_count
|
|
59
|
+
FROM kb_nodes
|
|
60
|
+
`);
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
healthy: true,
|
|
64
|
+
nodeCount: parseInt(result.rows[0].node_count),
|
|
65
|
+
gapCount: parseInt(result.rows[0].gap_count),
|
|
66
|
+
features: await detectFeatures()
|
|
67
|
+
};
|
|
68
|
+
} catch (error) {
|
|
69
|
+
return {
|
|
70
|
+
healthy: false,
|
|
71
|
+
nodeCount: 0,
|
|
72
|
+
gapCount: 0,
|
|
73
|
+
features: {},
|
|
74
|
+
error: error.message
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## Template: index.ts
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
export * from './types';
|
|
86
|
+
export * from './client';
|
|
87
|
+
export * from './tree';
|
|
88
|
+
export { verifyConnection } from './validator';
|
|
89
|
+
|
|
90
|
+
// Re-export as named 'kb'
|
|
91
|
+
import * as client from './client';
|
|
92
|
+
import * as tree from './tree';
|
|
93
|
+
import { verifyConnection } from './validator';
|
|
94
|
+
|
|
95
|
+
export const kb = {
|
|
96
|
+
...client,
|
|
97
|
+
...tree,
|
|
98
|
+
verifyConnection
|
|
99
|
+
};
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## Quality Gate
|
|
105
|
+
|
|
106
|
+
- [ ] All files compile without errors
|
|
107
|
+
- [ ] Exports work correctly
|
|
108
|
+
- [ ] `verifyConnection()` returns health status
|
|
109
|
+
- [ ] `search()` returns results with sources
|
|
110
|
+
- [ ] `logGap()` logs unanswered queries
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
**Proceed to Phase 6: Application Scaffold**
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# Phase 6: Application Scaffold
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
Create the project structure with KB enforcement built in from the start.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Output Structure
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
[PROJECT]/
|
|
13
|
+
├── src/
|
|
14
|
+
│ ├── kb/ # FROM PHASE 5 (treat as read-only)
|
|
15
|
+
│ │ ├── client.ts
|
|
16
|
+
│ │ ├── types.ts
|
|
17
|
+
│ │ ├── tree.ts
|
|
18
|
+
│ │ ├── validator.ts
|
|
19
|
+
│ │ └── index.ts
|
|
20
|
+
│ │
|
|
21
|
+
│ ├── intelligence/ # GNN/Attention/SONA (based on pattern)
|
|
22
|
+
│ │ ├── gnn.ts # If Decision Web
|
|
23
|
+
│ │ ├── attention.ts # If Routing
|
|
24
|
+
│ │ └── sona.ts # If Learning
|
|
25
|
+
│ │
|
|
26
|
+
│ ├── domain/ # Domain logic (MUST use kb/)
|
|
27
|
+
│ │ └── [domain-specific files]
|
|
28
|
+
│ │
|
|
29
|
+
│ ├── api/ # Routes
|
|
30
|
+
│ │ └── routes/
|
|
31
|
+
│ │
|
|
32
|
+
│ ├── components/ # UI components
|
|
33
|
+
│ │
|
|
34
|
+
│ ├── pages/ # Page compositions
|
|
35
|
+
│ │
|
|
36
|
+
│ └── index.ts # Entry point (KB verification FIRST)
|
|
37
|
+
│
|
|
38
|
+
├── visualization/ # From Phase 4
|
|
39
|
+
│
|
|
40
|
+
├── scripts/ # Verification scripts
|
|
41
|
+
│ ├── verify-domain.sh
|
|
42
|
+
│ ├── verify-api.sh
|
|
43
|
+
│ └── verify-entry.sh
|
|
44
|
+
│
|
|
45
|
+
├── KB_ENFORCEMENT.md # Rules document
|
|
46
|
+
│
|
|
47
|
+
├── package.json
|
|
48
|
+
├── tsconfig.json
|
|
49
|
+
└── README.md
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## KB_ENFORCEMENT.md
|
|
55
|
+
|
|
56
|
+
Create this file in the project root and keep it in context throughout development:
|
|
57
|
+
|
|
58
|
+
```markdown
|
|
59
|
+
# KB ENFORCEMENT RULES
|
|
60
|
+
|
|
61
|
+
This document defines the rules for KB-First development.
|
|
62
|
+
ALL code must comply with these rules.
|
|
63
|
+
|
|
64
|
+
## Rule 1: No Hardcoded Domain Logic
|
|
65
|
+
Every domain value comes from the KB.
|
|
66
|
+
|
|
67
|
+
## Rule 2: Every Domain Function Queries KB
|
|
68
|
+
Every file in src/domain/ imports from ../kb
|
|
69
|
+
|
|
70
|
+
## Rule 3: All Responses Include kbSources
|
|
71
|
+
Traceability is mandatory.
|
|
72
|
+
|
|
73
|
+
## Rule 4: Startup Verification Required
|
|
74
|
+
App exits if KB unavailable.
|
|
75
|
+
|
|
76
|
+
## Rule 5: No Fallback Logic
|
|
77
|
+
KB is the source of truth.
|
|
78
|
+
|
|
79
|
+
See phases/07-build.md for full details and examples.
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## Entry Point Template
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
// src/index.ts
|
|
88
|
+
import { kb } from './kb';
|
|
89
|
+
import { initializeApp } from './app';
|
|
90
|
+
|
|
91
|
+
async function main() {
|
|
92
|
+
console.log('Starting application...');
|
|
93
|
+
|
|
94
|
+
// FIRST: Verify KB connection
|
|
95
|
+
console.log('Verifying knowledge base...');
|
|
96
|
+
const health = await kb.verifyConnection();
|
|
97
|
+
|
|
98
|
+
if (!health.healthy) {
|
|
99
|
+
console.error('KB unavailable:', health.error);
|
|
100
|
+
console.error('Cannot start application without knowledge base.');
|
|
101
|
+
process.exit(1);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
console.log(`KB ready: ${health.nodeCount} nodes, ${health.gapCount} logged gaps`);
|
|
105
|
+
|
|
106
|
+
// THEN: Initialize application
|
|
107
|
+
await initializeApp();
|
|
108
|
+
|
|
109
|
+
console.log('Application started successfully');
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
main().catch((error) => {
|
|
113
|
+
console.error('Startup failed:', error);
|
|
114
|
+
process.exit(1);
|
|
115
|
+
});
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## Quality Gate
|
|
121
|
+
|
|
122
|
+
- [ ] Directory structure created
|
|
123
|
+
- [ ] KB_ENFORCEMENT.md in project root
|
|
124
|
+
- [ ] Entry point verifies KB first
|
|
125
|
+
- [ ] Entry point exits on KB failure
|
|
126
|
+
- [ ] Domain directory empty (ready for Phase 7)
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
**Proceed to Phase 7: Application Build**
|