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,257 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# RuvNet KB-First Global Installer
|
|
3
|
+
# Version 5.0.0 | Updated 2026-01-02
|
|
4
|
+
#
|
|
5
|
+
# Installs KB-First skill, command, hooks, and auto-detection globally to ~/.claude/
|
|
6
|
+
|
|
7
|
+
set -e
|
|
8
|
+
|
|
9
|
+
echo "╔═══════════════════════════════════════════════════════════════╗"
|
|
10
|
+
echo "║ RuvNet KB-First Application Builder v5.0.0 ║"
|
|
11
|
+
echo "║ Global Installation Script ║"
|
|
12
|
+
echo "╚═══════════════════════════════════════════════════════════════╝"
|
|
13
|
+
echo ""
|
|
14
|
+
|
|
15
|
+
# Determine script location
|
|
16
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
17
|
+
REPO_DIR="$(dirname "$SCRIPT_DIR")"
|
|
18
|
+
|
|
19
|
+
# Target directories
|
|
20
|
+
CLAUDE_DIR="$HOME/.claude"
|
|
21
|
+
SKILLS_DIR="$CLAUDE_DIR/skills"
|
|
22
|
+
COMMANDS_DIR="$CLAUDE_DIR/commands"
|
|
23
|
+
HOOKS_DIR="$CLAUDE_DIR/hooks"
|
|
24
|
+
|
|
25
|
+
# Create directories if needed
|
|
26
|
+
echo "Creating directories..."
|
|
27
|
+
mkdir -p "$SKILLS_DIR"
|
|
28
|
+
mkdir -p "$COMMANDS_DIR"
|
|
29
|
+
mkdir -p "$HOOKS_DIR"
|
|
30
|
+
|
|
31
|
+
# Install skill
|
|
32
|
+
echo "Installing KB-First skill..."
|
|
33
|
+
cp "$SCRIPT_DIR/kb-first-skill.md" "$SKILLS_DIR/kb-first.md"
|
|
34
|
+
echo " ✅ Installed to $SKILLS_DIR/kb-first.md"
|
|
35
|
+
|
|
36
|
+
# Install command
|
|
37
|
+
echo "Installing /kb-first command..."
|
|
38
|
+
cp "$SCRIPT_DIR/kb-first-command.md" "$COMMANDS_DIR/kb-first.md"
|
|
39
|
+
echo " ✅ Installed to $COMMANDS_DIR/kb-first.md"
|
|
40
|
+
|
|
41
|
+
# Install hook scripts
|
|
42
|
+
echo "Installing hook scripts..."
|
|
43
|
+
|
|
44
|
+
if [ -f "$REPO_DIR/phases/01.5-hooks-setup.md" ]; then
|
|
45
|
+
# Extract hook scripts from phase documentation
|
|
46
|
+
# For now, create minimal working hooks
|
|
47
|
+
|
|
48
|
+
cat > "$HOOKS_DIR/pre_tool_use.py" << 'HOOK_EOF'
|
|
49
|
+
#!/usr/bin/env python3
|
|
50
|
+
"""RuVector PreToolUse Hook - KB-First Enforcement"""
|
|
51
|
+
import json
|
|
52
|
+
import sys
|
|
53
|
+
|
|
54
|
+
def main():
|
|
55
|
+
try:
|
|
56
|
+
input_data = json.load(sys.stdin)
|
|
57
|
+
tool_name = input_data.get('tool_name', '')
|
|
58
|
+
tool_input = input_data.get('tool_input', {})
|
|
59
|
+
|
|
60
|
+
if tool_name not in ('Edit', 'Write', 'MultiEdit'):
|
|
61
|
+
print(json.dumps({"decision": "continue"}))
|
|
62
|
+
return
|
|
63
|
+
|
|
64
|
+
file_path = tool_input.get('file_path', '')
|
|
65
|
+
if '/domain/' in file_path or '/src/' in file_path:
|
|
66
|
+
print(json.dumps({
|
|
67
|
+
"decision": "continue",
|
|
68
|
+
"message": "📚 KB-First: Remember to query KB for domain values"
|
|
69
|
+
}))
|
|
70
|
+
else:
|
|
71
|
+
print(json.dumps({"decision": "continue"}))
|
|
72
|
+
except:
|
|
73
|
+
print(json.dumps({"decision": "continue"}))
|
|
74
|
+
|
|
75
|
+
if __name__ == '__main__':
|
|
76
|
+
main()
|
|
77
|
+
HOOK_EOF
|
|
78
|
+
|
|
79
|
+
cat > "$HOOKS_DIR/post_tool_use.py" << 'HOOK_EOF'
|
|
80
|
+
#!/usr/bin/env python3
|
|
81
|
+
"""RuVector PostToolUse Hook - Outcome Recording"""
|
|
82
|
+
import json
|
|
83
|
+
import sys
|
|
84
|
+
|
|
85
|
+
def main():
|
|
86
|
+
try:
|
|
87
|
+
input_data = json.load(sys.stdin)
|
|
88
|
+
# Record outcome for SONA learning (stub)
|
|
89
|
+
except:
|
|
90
|
+
pass
|
|
91
|
+
print(json.dumps({"decision": "continue"}))
|
|
92
|
+
|
|
93
|
+
if __name__ == '__main__':
|
|
94
|
+
main()
|
|
95
|
+
HOOK_EOF
|
|
96
|
+
|
|
97
|
+
cat > "$HOOKS_DIR/session_end.py" << 'HOOK_EOF'
|
|
98
|
+
#!/usr/bin/env python3
|
|
99
|
+
"""RuVector SessionEnd Hook - Pattern Persistence"""
|
|
100
|
+
import json
|
|
101
|
+
import sys
|
|
102
|
+
|
|
103
|
+
def main():
|
|
104
|
+
try:
|
|
105
|
+
input_data = json.load(sys.stdin)
|
|
106
|
+
# Persist patterns (stub)
|
|
107
|
+
except:
|
|
108
|
+
pass
|
|
109
|
+
print(json.dumps({"decision": "continue"}))
|
|
110
|
+
|
|
111
|
+
if __name__ == '__main__':
|
|
112
|
+
main()
|
|
113
|
+
HOOK_EOF
|
|
114
|
+
|
|
115
|
+
chmod +x "$HOOKS_DIR"/*.py
|
|
116
|
+
echo " ✅ Installed hook scripts to $HOOKS_DIR/"
|
|
117
|
+
fi
|
|
118
|
+
|
|
119
|
+
# Update settings.json to register hooks
|
|
120
|
+
echo "Configuring hooks in settings.json..."
|
|
121
|
+
|
|
122
|
+
SETTINGS_FILE="$CLAUDE_DIR/settings.json"
|
|
123
|
+
|
|
124
|
+
if [ -f "$SETTINGS_FILE" ]; then
|
|
125
|
+
# Backup existing
|
|
126
|
+
cp "$SETTINGS_FILE" "$SETTINGS_FILE.bak"
|
|
127
|
+
|
|
128
|
+
# Check if hooks already configured
|
|
129
|
+
if grep -q '"hooks"' "$SETTINGS_FILE"; then
|
|
130
|
+
echo " ⚠️ Hooks already configured in settings.json"
|
|
131
|
+
echo " ℹ️ Review $SETTINGS_FILE to ensure KB-First hooks are active"
|
|
132
|
+
else
|
|
133
|
+
# Add hooks to existing settings
|
|
134
|
+
python3 << PYTHON_EOF
|
|
135
|
+
import json
|
|
136
|
+
|
|
137
|
+
with open('$SETTINGS_FILE', 'r') as f:
|
|
138
|
+
settings = json.load(f)
|
|
139
|
+
|
|
140
|
+
settings['hooks'] = {
|
|
141
|
+
"PreToolUse": [{
|
|
142
|
+
"matcher": "Edit|Write|MultiEdit",
|
|
143
|
+
"hooks": [{"type": "command", "command": "python3 $HOOKS_DIR/pre_tool_use.py"}]
|
|
144
|
+
}],
|
|
145
|
+
"PostToolUse": [{
|
|
146
|
+
"matcher": "*",
|
|
147
|
+
"hooks": [{"type": "command", "command": "python3 $HOOKS_DIR/post_tool_use.py"}]
|
|
148
|
+
}],
|
|
149
|
+
"SessionEnd": [{
|
|
150
|
+
"matcher": "*",
|
|
151
|
+
"hooks": [{"type": "command", "command": "python3 $HOOKS_DIR/session_end.py"}]
|
|
152
|
+
}]
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
with open('$SETTINGS_FILE', 'w') as f:
|
|
156
|
+
json.dump(settings, f, indent=2)
|
|
157
|
+
PYTHON_EOF
|
|
158
|
+
echo " ✅ Hooks configured in settings.json"
|
|
159
|
+
fi
|
|
160
|
+
else
|
|
161
|
+
# Create new settings file
|
|
162
|
+
cat > "$SETTINGS_FILE" << SETTINGS_EOF
|
|
163
|
+
{
|
|
164
|
+
"hooks": {
|
|
165
|
+
"PreToolUse": [{
|
|
166
|
+
"matcher": "Edit|Write|MultiEdit",
|
|
167
|
+
"hooks": [{"type": "command", "command": "python3 $HOOKS_DIR/pre_tool_use.py"}]
|
|
168
|
+
}],
|
|
169
|
+
"PostToolUse": [{
|
|
170
|
+
"matcher": "*",
|
|
171
|
+
"hooks": [{"type": "command", "command": "python3 $HOOKS_DIR/post_tool_use.py"}]
|
|
172
|
+
}],
|
|
173
|
+
"SessionEnd": [{
|
|
174
|
+
"matcher": "*",
|
|
175
|
+
"hooks": [{"type": "command", "command": "python3 $HOOKS_DIR/session_end.py"}]
|
|
176
|
+
}]
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
SETTINGS_EOF
|
|
180
|
+
echo " ✅ Created settings.json with hooks"
|
|
181
|
+
fi
|
|
182
|
+
|
|
183
|
+
# Verify installation
|
|
184
|
+
echo ""
|
|
185
|
+
echo "Verifying installation..."
|
|
186
|
+
echo ""
|
|
187
|
+
|
|
188
|
+
PASS=0
|
|
189
|
+
FAIL=0
|
|
190
|
+
|
|
191
|
+
if [ -f "$SKILLS_DIR/kb-first.md" ]; then
|
|
192
|
+
echo " ✅ Skill installed"
|
|
193
|
+
PASS=$((PASS + 1))
|
|
194
|
+
else
|
|
195
|
+
echo " ❌ Skill not found"
|
|
196
|
+
FAIL=$((FAIL + 1))
|
|
197
|
+
fi
|
|
198
|
+
|
|
199
|
+
if [ -f "$COMMANDS_DIR/kb-first.md" ]; then
|
|
200
|
+
echo " ✅ Command installed"
|
|
201
|
+
PASS=$((PASS + 1))
|
|
202
|
+
else
|
|
203
|
+
echo " ❌ Command not found"
|
|
204
|
+
FAIL=$((FAIL + 1))
|
|
205
|
+
fi
|
|
206
|
+
|
|
207
|
+
if [ -f "$HOOKS_DIR/pre_tool_use.py" ] && [ -x "$HOOKS_DIR/pre_tool_use.py" ]; then
|
|
208
|
+
echo " ✅ Hooks installed and executable"
|
|
209
|
+
PASS=$((PASS + 1))
|
|
210
|
+
else
|
|
211
|
+
echo " ❌ Hooks not installed or not executable"
|
|
212
|
+
FAIL=$((FAIL + 1))
|
|
213
|
+
fi
|
|
214
|
+
|
|
215
|
+
if grep -q '"hooks"' "$SETTINGS_FILE" 2>/dev/null; then
|
|
216
|
+
echo " ✅ Hooks configured in settings.json"
|
|
217
|
+
PASS=$((PASS + 1))
|
|
218
|
+
else
|
|
219
|
+
echo " ❌ Hooks not configured"
|
|
220
|
+
FAIL=$((FAIL + 1))
|
|
221
|
+
fi
|
|
222
|
+
|
|
223
|
+
echo ""
|
|
224
|
+
echo "═══════════════════════════════════════════════════════════════"
|
|
225
|
+
|
|
226
|
+
# Install auto-detection hook
|
|
227
|
+
echo "Installing auto-detection hook..."
|
|
228
|
+
if [ -f "$SCRIPT_DIR/kb-first-autodetect.sh" ]; then
|
|
229
|
+
cp "$SCRIPT_DIR/kb-first-autodetect.sh" "$HOOKS_DIR/kb-first-autodetect.sh"
|
|
230
|
+
chmod +x "$HOOKS_DIR/kb-first-autodetect.sh"
|
|
231
|
+
echo " ✅ Auto-detection hook installed"
|
|
232
|
+
PASS=$((PASS + 1))
|
|
233
|
+
else
|
|
234
|
+
echo " ⚠️ Auto-detection hook not found in install directory"
|
|
235
|
+
fi
|
|
236
|
+
|
|
237
|
+
if [ $FAIL -eq 0 ]; then
|
|
238
|
+
echo "✅ Installation complete! ($PASS checks passed)"
|
|
239
|
+
echo ""
|
|
240
|
+
echo "Usage:"
|
|
241
|
+
echo " /kb-first # Start interactive builder"
|
|
242
|
+
echo " kb-first init # Initialize in current project"
|
|
243
|
+
echo " kb-first score # Score existing KB and app"
|
|
244
|
+
echo " kb-first verify # Run verification checks"
|
|
245
|
+
echo " kb-first status # Show project status"
|
|
246
|
+
echo ""
|
|
247
|
+
echo "NPM Package:"
|
|
248
|
+
echo " npx ruvnet-kb-first init"
|
|
249
|
+
echo " npx ruvnet-kb-first score --detailed"
|
|
250
|
+
echo ""
|
|
251
|
+
echo "Full documentation: $SKILLS_DIR/kb-first.md"
|
|
252
|
+
else
|
|
253
|
+
echo "⚠️ Installation completed with warnings ($PASS passed, $FAIL failed)"
|
|
254
|
+
echo "Review the output above for details."
|
|
255
|
+
fi
|
|
256
|
+
|
|
257
|
+
exit 0
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# KB-First Auto-Detection Hook
|
|
3
|
+
#
|
|
4
|
+
# This hook runs on session start to detect if the current project
|
|
5
|
+
# should be using KB-First methodology.
|
|
6
|
+
#
|
|
7
|
+
# Install to: ~/.claude/hooks/kb-first-autodetect.sh
|
|
8
|
+
# Add to settings.json:
|
|
9
|
+
# "hooks": {
|
|
10
|
+
# "SessionStart": ["~/.claude/hooks/kb-first-autodetect.sh"]
|
|
11
|
+
# }
|
|
12
|
+
#
|
|
13
|
+
# Version: 5.0.0
|
|
14
|
+
# Created: 2026-01-02
|
|
15
|
+
|
|
16
|
+
set -e
|
|
17
|
+
|
|
18
|
+
# Check if we're in a git repository
|
|
19
|
+
if ! git rev-parse --git-dir > /dev/null 2>&1; then
|
|
20
|
+
exit 0
|
|
21
|
+
fi
|
|
22
|
+
|
|
23
|
+
PROJECT_DIR=$(git rev-parse --show-toplevel 2>/dev/null || pwd)
|
|
24
|
+
KB_FIRST_CONFIG="$PROJECT_DIR/.ruvector/config.json"
|
|
25
|
+
|
|
26
|
+
# ============================================
|
|
27
|
+
# Check 1: Already a KB-First Project
|
|
28
|
+
# ============================================
|
|
29
|
+
if [ -f "$KB_FIRST_CONFIG" ]; then
|
|
30
|
+
# Project is already KB-First enabled
|
|
31
|
+
echo "📚 KB-First project detected"
|
|
32
|
+
|
|
33
|
+
# Read current phase
|
|
34
|
+
CURRENT_PHASE=$(cat "$KB_FIRST_CONFIG" | python3 -c "import sys,json; print(json.load(sys.stdin).get('phases',{}).get('current',0))" 2>/dev/null || echo "0")
|
|
35
|
+
|
|
36
|
+
echo " Phase: $CURRENT_PHASE"
|
|
37
|
+
echo " Run: kb-first status"
|
|
38
|
+
exit 0
|
|
39
|
+
fi
|
|
40
|
+
|
|
41
|
+
# ============================================
|
|
42
|
+
# Check 2: Detect KB-First Indicators
|
|
43
|
+
# ============================================
|
|
44
|
+
KB_SCORE=0
|
|
45
|
+
KB_INDICATORS=""
|
|
46
|
+
|
|
47
|
+
# Check for knowledge-intensive directories
|
|
48
|
+
if [ -d "$PROJECT_DIR/docs" ] && [ "$(find "$PROJECT_DIR/docs" -name "*.md" 2>/dev/null | wc -l)" -gt 5 ]; then
|
|
49
|
+
KB_SCORE=$((KB_SCORE + 20))
|
|
50
|
+
KB_INDICATORS="$KB_INDICATORS\n • Extensive documentation"
|
|
51
|
+
fi
|
|
52
|
+
|
|
53
|
+
# Check for domain-specific content
|
|
54
|
+
if grep -rq "knowledge\|domain\|expertise\|specification" "$PROJECT_DIR/README.md" 2>/dev/null; then
|
|
55
|
+
KB_SCORE=$((KB_SCORE + 15))
|
|
56
|
+
KB_INDICATORS="$KB_INDICATORS\n • Domain-specific content in README"
|
|
57
|
+
fi
|
|
58
|
+
|
|
59
|
+
# Check for existing schema/database references
|
|
60
|
+
if find "$PROJECT_DIR" -name "*.sql" -o -name "*schema*" -o -name "*migration*" 2>/dev/null | head -1 | grep -q .; then
|
|
61
|
+
KB_SCORE=$((KB_SCORE + 15))
|
|
62
|
+
KB_INDICATORS="$KB_INDICATORS\n • Database/schema files present"
|
|
63
|
+
fi
|
|
64
|
+
|
|
65
|
+
# Check for API/specification files
|
|
66
|
+
if find "$PROJECT_DIR" -name "openapi*" -o -name "swagger*" -o -name "*.graphql" 2>/dev/null | head -1 | grep -q .; then
|
|
67
|
+
KB_SCORE=$((KB_SCORE + 15))
|
|
68
|
+
KB_INDICATORS="$KB_INDICATORS\n • API specification files"
|
|
69
|
+
fi
|
|
70
|
+
|
|
71
|
+
# Check for vector/embedding references
|
|
72
|
+
if grep -rq "vector\|embedding\|similarity\|semantic" "$PROJECT_DIR" --include="*.json" --include="*.yaml" --include="*.yml" 2>/dev/null; then
|
|
73
|
+
KB_SCORE=$((KB_SCORE + 20))
|
|
74
|
+
KB_INDICATORS="$KB_INDICATORS\n • Vector/embedding references"
|
|
75
|
+
fi
|
|
76
|
+
|
|
77
|
+
# Check for ruvector dependency
|
|
78
|
+
if grep -q "ruvector\|pgvector\|qdrant\|pinecone" "$PROJECT_DIR/package.json" 2>/dev/null; then
|
|
79
|
+
KB_SCORE=$((KB_SCORE + 20))
|
|
80
|
+
KB_INDICATORS="$KB_INDICATORS\n • Vector database dependency"
|
|
81
|
+
fi
|
|
82
|
+
|
|
83
|
+
# Check for existing KB-related files
|
|
84
|
+
if find "$PROJECT_DIR" -name "*knowledge*" -o -name "*kb*" 2>/dev/null | head -1 | grep -q .; then
|
|
85
|
+
KB_SCORE=$((KB_SCORE + 15))
|
|
86
|
+
KB_INDICATORS="$KB_INDICATORS\n • KB-related file names"
|
|
87
|
+
fi
|
|
88
|
+
|
|
89
|
+
# ============================================
|
|
90
|
+
# Output Recommendation
|
|
91
|
+
# ============================================
|
|
92
|
+
if [ $KB_SCORE -ge 50 ]; then
|
|
93
|
+
echo "🔍 KB-First Recommended (Score: $KB_SCORE/100)"
|
|
94
|
+
echo ""
|
|
95
|
+
echo "This project shows indicators of knowledge-intensive work:"
|
|
96
|
+
echo -e "$KB_INDICATORS"
|
|
97
|
+
echo ""
|
|
98
|
+
echo "Initialize KB-First with:"
|
|
99
|
+
echo " npx ruvnet-kb-first init"
|
|
100
|
+
echo ""
|
|
101
|
+
echo "Or skip this check:"
|
|
102
|
+
echo " touch $PROJECT_DIR/.ruvector/.skip-detection"
|
|
103
|
+
elif [ $KB_SCORE -ge 25 ]; then
|
|
104
|
+
echo "💡 KB-First might be beneficial (Score: $KB_SCORE/100)"
|
|
105
|
+
echo " Run: npx ruvnet-kb-first init --help"
|
|
106
|
+
fi
|
|
107
|
+
|
|
108
|
+
exit 0
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
Updated: 2026-01-01 23:55:00 EST | Version 4.2.0
|
|
2
|
+
Created: 2026-01-01 23:55:00 EST
|
|
3
|
+
|
|
4
|
+
# /kb-first
|
|
5
|
+
|
|
6
|
+
Build or transform applications using KB-First architecture.
|
|
7
|
+
|
|
8
|
+
## Usage
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
/kb-first # Start interactive KB-First builder
|
|
12
|
+
/kb-first init # Initialize KB-First in current project
|
|
13
|
+
/kb-first score # Score existing KB and app compliance
|
|
14
|
+
/kb-first plan # Generate transformation plan
|
|
15
|
+
/kb-first transform # Execute KB-First transformation
|
|
16
|
+
/kb-first verify # Run all Phase 8 verification checks
|
|
17
|
+
/kb-first hooks # Configure Claude Code hooks
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Arguments
|
|
21
|
+
|
|
22
|
+
| Argument | Description |
|
|
23
|
+
|----------|-------------|
|
|
24
|
+
| (none) | Start interactive builder, detect greenfield/brownfield |
|
|
25
|
+
| `init` | Initialize KB-First structure in current project |
|
|
26
|
+
| `score` | Score existing KB quality and app compliance |
|
|
27
|
+
| `plan` | Generate transformation plan without executing |
|
|
28
|
+
| `transform` | Execute full KB-First transformation |
|
|
29
|
+
| `verify` | Run all 8 verification scripts |
|
|
30
|
+
| `hooks` | Install and configure RuVector hooks |
|
|
31
|
+
|
|
32
|
+
## Examples
|
|
33
|
+
|
|
34
|
+
### Build a New Application
|
|
35
|
+
```
|
|
36
|
+
/kb-first
|
|
37
|
+
|
|
38
|
+
# Then provide your intentions:
|
|
39
|
+
> I want to build a retirement planning advisor that helps users optimize
|
|
40
|
+
> their Social Security claiming strategy and tax-efficient withdrawals.
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Transform Existing Application
|
|
44
|
+
```
|
|
45
|
+
/kb-first score
|
|
46
|
+
# Shows: KB Quality: 45/100, App Compliance: 30/100
|
|
47
|
+
|
|
48
|
+
/kb-first plan
|
|
49
|
+
# Shows: 15 files need modification, 8 new files needed
|
|
50
|
+
|
|
51
|
+
/kb-first transform
|
|
52
|
+
# Executes the 10-phase build process
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Quick Verification
|
|
56
|
+
```
|
|
57
|
+
/kb-first verify
|
|
58
|
+
# Runs: 8.1-8.8 verification scripts
|
|
59
|
+
# Returns: PASS/FAIL for each check
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## What This Command Does
|
|
65
|
+
|
|
66
|
+
1. **Detects** application type (greenfield vs brownfield)
|
|
67
|
+
2. **Scores** existing KB and app compliance (brownfield only)
|
|
68
|
+
3. **Confirms** transformation scope with user
|
|
69
|
+
4. **Identifies** which intelligence pattern fits
|
|
70
|
+
5. **Executes** the 10-phase build process with HARD quality gates
|
|
71
|
+
6. **Enforces** KB-First rules throughout development
|
|
72
|
+
7. **Verifies** all 8 verification sub-phases pass
|
|
73
|
+
8. **Reports** delta (before/after scores)
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## Skill Reference
|
|
78
|
+
|
|
79
|
+
This command invokes the KB-First Application Builder skill.
|
|
80
|
+
Full documentation: `~/.claude/skills/kb-first.md`
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
Updated: 2026-01-01 23:55:00 EST | Version 4.2.0
|
|
2
|
+
Created: 2026-01-01 23:55:00 EST
|
|
3
|
+
|
|
4
|
+
# KB-First Application Builder
|
|
5
|
+
|
|
6
|
+
Build applications where curated expert knowledge drives intelligent decision-making through GNN reasoning, attention routing, and SONA learning.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Triggers
|
|
11
|
+
|
|
12
|
+
Use this skill when:
|
|
13
|
+
- "Build [description] with KB-First" (greenfield)
|
|
14
|
+
- "Apply KB-First to my existing app" (brownfield)
|
|
15
|
+
- "Score my existing KB"
|
|
16
|
+
- "What's my app compliance score?"
|
|
17
|
+
- "/kb-first" (invoke skill directly)
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## The 10-Phase Build Process
|
|
22
|
+
|
|
23
|
+
| Phase | Name | Sub-Phases | Gate Type |
|
|
24
|
+
|-------|------|------------|-----------|
|
|
25
|
+
| 0 | Assessment | 6 | User Confirmation |
|
|
26
|
+
| 1 | Storage | 6 | Script Check |
|
|
27
|
+
| 1.5 | Hooks Setup | 4 | Hook Verify |
|
|
28
|
+
| 2 | KB Creation | 8 | Score ≥98 |
|
|
29
|
+
| 3 | Persistence | - | SQL Check |
|
|
30
|
+
| 4 | Visualization | - | Manual/Playwright |
|
|
31
|
+
| 5 | Integration | - | Compile Check |
|
|
32
|
+
| 6 | Scaffold | - | File Check |
|
|
33
|
+
| 7 | Build | 7 | Script Check |
|
|
34
|
+
| 8 | Verification | 8 | All Must Pass |
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Critical Rules (NEVER VIOLATE)
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
RULE 1: No hardcoded domain logic
|
|
42
|
+
❌ const rate = 0.04;
|
|
43
|
+
✅ const rate = await kb.search("withdrawal rate");
|
|
44
|
+
|
|
45
|
+
RULE 2: Every domain function queries KB
|
|
46
|
+
Every file in src/domain/ imports from ../kb
|
|
47
|
+
|
|
48
|
+
RULE 3: All responses include kbSources
|
|
49
|
+
Traceability is mandatory
|
|
50
|
+
|
|
51
|
+
RULE 4: Startup verification required
|
|
52
|
+
App exits if KB unavailable
|
|
53
|
+
|
|
54
|
+
RULE 5: No fallback logic
|
|
55
|
+
❌ rules = kb.get() || DEFAULT_RULES
|
|
56
|
+
✅ rules = kb.get(); if (!rules) throw Error("KB missing");
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## Quick Start
|
|
62
|
+
|
|
63
|
+
### Greenfield (New Project)
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
# 1. Clone the KB-First builder
|
|
67
|
+
git clone https://github.com/ruvnet/kb-first-builder.git my-app
|
|
68
|
+
cd my-app
|
|
69
|
+
|
|
70
|
+
# 2. Create your intentions
|
|
71
|
+
cat > PROJECT_INTENTIONS.md << 'EOF'
|
|
72
|
+
# Project Intentions
|
|
73
|
+
|
|
74
|
+
## What I Want to Build
|
|
75
|
+
[Describe your application]
|
|
76
|
+
|
|
77
|
+
## Users
|
|
78
|
+
[Who will use this]
|
|
79
|
+
|
|
80
|
+
## Core Features
|
|
81
|
+
- Feature 1
|
|
82
|
+
- Feature 2
|
|
83
|
+
|
|
84
|
+
## Domain
|
|
85
|
+
[The knowledge domain]
|
|
86
|
+
EOF
|
|
87
|
+
|
|
88
|
+
# 3. Run the builder
|
|
89
|
+
/kb-first
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Brownfield (Existing Project)
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
# 1. Initialize KB-First in your project
|
|
96
|
+
npx kb-first-builder init
|
|
97
|
+
|
|
98
|
+
# 2. Score your current state
|
|
99
|
+
/kb-first score
|
|
100
|
+
|
|
101
|
+
# 3. See the transformation plan
|
|
102
|
+
/kb-first plan
|
|
103
|
+
|
|
104
|
+
# 4. Execute
|
|
105
|
+
/kb-first transform
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## Phase 0: Assessment
|
|
111
|
+
|
|
112
|
+
For brownfield applications, Claude MUST score before any changes:
|
|
113
|
+
|
|
114
|
+
### KB Quality Score (0-100)
|
|
115
|
+
```
|
|
116
|
+
Expert Coverage (0-40):
|
|
117
|
+
- 100+ experts cited = 40 points
|
|
118
|
+
- 50-99 experts = 30 points
|
|
119
|
+
- 20-49 experts = 20 points
|
|
120
|
+
- <20 experts = 10 points
|
|
121
|
+
|
|
122
|
+
Depth Score (0-30):
|
|
123
|
+
- Recursive depth ≥5 = 30 points
|
|
124
|
+
- Depth 3-4 = 20 points
|
|
125
|
+
- Depth 1-2 = 10 points
|
|
126
|
+
|
|
127
|
+
Completeness (0-30):
|
|
128
|
+
- All nodes have content = 30 points
|
|
129
|
+
- >90% = 20 points
|
|
130
|
+
- <90% = 10 points
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### App Compliance Score (0-100)
|
|
134
|
+
```
|
|
135
|
+
KB Imports (0-25):
|
|
136
|
+
- All domain files import kb = 25 points
|
|
137
|
+
|
|
138
|
+
Source Returns (0-25):
|
|
139
|
+
- All responses include kbSources = 25 points
|
|
140
|
+
|
|
141
|
+
No Hardcode (0-20):
|
|
142
|
+
- No hardcoded values in domain = 20 points
|
|
143
|
+
|
|
144
|
+
Startup Verify (0-15):
|
|
145
|
+
- Entry point verifies KB = 15 points
|
|
146
|
+
|
|
147
|
+
No Fallbacks (0-15):
|
|
148
|
+
- No || DEFAULT patterns = 15 points
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## Phase 1.5: Hooks Setup
|
|
154
|
+
|
|
155
|
+
**Without hooks, KB-First is an honor system.**
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
# Install and configure hooks
|
|
159
|
+
npx @ruvector/cli hooks init
|
|
160
|
+
npx @ruvector/cli hooks install
|
|
161
|
+
|
|
162
|
+
# Pre-train ReasoningBank
|
|
163
|
+
npx @ruvector/cli reasoningbank seed --kb-first
|
|
164
|
+
|
|
165
|
+
# Verify
|
|
166
|
+
./scripts/1.5-hooks-verify.sh
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Hooks enforce:
|
|
170
|
+
- PreToolUse: Check KB before any Write/Edit
|
|
171
|
+
- PostToolUse: Record outcomes, trigger SONA learning
|
|
172
|
+
- SessionEnd: Persist patterns
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## Scoring Formula
|
|
177
|
+
|
|
178
|
+
### KB Quality Score
|
|
179
|
+
|
|
180
|
+
| Component | Points | Criteria |
|
|
181
|
+
|-----------|--------|----------|
|
|
182
|
+
| Expert Coverage | 0-40 | Number of cited experts |
|
|
183
|
+
| Depth | 0-30 | Recursive depth of KB tree |
|
|
184
|
+
| Completeness | 0-30 | Nodes with actual content |
|
|
185
|
+
| Attribution | +5 | All nodes have source_expert |
|
|
186
|
+
| Confidence | +5 | All nodes have confidence score |
|
|
187
|
+
|
|
188
|
+
**Target: ≥98/100**
|
|
189
|
+
|
|
190
|
+
### App Compliance Score
|
|
191
|
+
|
|
192
|
+
| Component | Points | Criteria |
|
|
193
|
+
|-----------|--------|----------|
|
|
194
|
+
| KB Imports | 0-25 | All domain files import kb |
|
|
195
|
+
| Source Returns | 0-25 | All responses have kbSources |
|
|
196
|
+
| No Hardcode | 0-20 | No magic numbers in domain |
|
|
197
|
+
| Startup Verify | 0-15 | KB check in entry point |
|
|
198
|
+
| No Fallbacks | 0-15 | No `|| DEFAULT` patterns |
|
|
199
|
+
|
|
200
|
+
**Target: 100/100**
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## Intelligence Patterns
|
|
205
|
+
|
|
206
|
+
### Pattern Selection
|
|
207
|
+
|
|
208
|
+
```
|
|
209
|
+
Q1: Does changing one variable affect many others?
|
|
210
|
+
YES → Decision Web (GNN-first)
|
|
211
|
+
|
|
212
|
+
Q2: Do you need to route queries to different expert domains?
|
|
213
|
+
YES → Combinatorial Routing (Attention-first)
|
|
214
|
+
|
|
215
|
+
Q3: Is "what worked for similar cases" the core value?
|
|
216
|
+
YES → Scenario Learning (SONA-first)
|
|
217
|
+
|
|
218
|
+
Q4: Is this a continuous monitoring/optimization loop?
|
|
219
|
+
YES → Continuous Optimization (Attention + SONA)
|
|
220
|
+
|
|
221
|
+
Otherwise → Standard KB-First (Vector Search primary)
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### Technology Matrix
|
|
225
|
+
|
|
226
|
+
| Pattern | GNN | Attention | SONA | Vector |
|
|
227
|
+
|---------|-----|-----------|------|--------|
|
|
228
|
+
| Decision Web | PRIMARY | Compare | Learn | Foundation |
|
|
229
|
+
| Combinatorial Routing | Networks | PRIMARY | Patterns | Foundation |
|
|
230
|
+
| Scenario Learning | Dynamics | Parameters | PRIMARY | Foundation |
|
|
231
|
+
| Continuous Optimization | Structure | PRIMARY | PRIMARY | Foundation |
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
## Verification Checks (Phase 8)
|
|
236
|
+
|
|
237
|
+
| Check | Script | Purpose |
|
|
238
|
+
|-------|--------|---------|
|
|
239
|
+
| 8.1 | code-scan.sh | No hardcoded values |
|
|
240
|
+
| 8.2 | import-check.sh | KB imports required |
|
|
241
|
+
| 8.3 | source-returns.sh | kbSources in returns |
|
|
242
|
+
| 8.4 | startup-verify.sh | KB connection at startup |
|
|
243
|
+
| 8.5 | fallback-check.sh | No fallback patterns |
|
|
244
|
+
| 8.6 | attribution.sh | Expert attribution |
|
|
245
|
+
| 8.7 | confidence.sh | Confidence scores |
|
|
246
|
+
| 8.8 | gap-logging.sh | Gap detection |
|
|
247
|
+
|
|
248
|
+
All 8 checks must PASS for completion.
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
## Full Documentation
|
|
253
|
+
|
|
254
|
+
For complete documentation, see the KB-First Builder repository:
|
|
255
|
+
- Phases: `./phases/`
|
|
256
|
+
- Scripts: `./scripts/`
|
|
257
|
+
- Templates: `./templates/`
|
|
258
|
+
- References: `./references/`
|
|
259
|
+
|
|
260
|
+
---
|
|
261
|
+
|
|
262
|
+
*KB-First v4.2.0 — Intelligence-First Architecture*
|