ruvector 0.1.44 → 0.1.45
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/bin/cli.js +149 -14
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -2267,7 +2267,14 @@ class Intelligence {
|
|
|
2267
2267
|
// Hooks command group
|
|
2268
2268
|
const hooksCmd = program.command('hooks').description('Self-learning intelligence hooks for Claude Code');
|
|
2269
2269
|
|
|
2270
|
-
hooksCmd.command('init')
|
|
2270
|
+
hooksCmd.command('init')
|
|
2271
|
+
.description('Initialize hooks in current project')
|
|
2272
|
+
.option('--force', 'Force overwrite existing settings')
|
|
2273
|
+
.option('--minimal', 'Only basic hooks (no env, permissions, or advanced hooks)')
|
|
2274
|
+
.option('--no-claude-md', 'Skip CLAUDE.md creation')
|
|
2275
|
+
.option('--no-permissions', 'Skip permissions configuration')
|
|
2276
|
+
.option('--no-env', 'Skip environment variables')
|
|
2277
|
+
.action((opts) => {
|
|
2271
2278
|
const settingsPath = path.join(process.cwd(), '.claude', 'settings.json');
|
|
2272
2279
|
const settingsDir = path.dirname(settingsPath);
|
|
2273
2280
|
if (!fs.existsSync(settingsDir)) fs.mkdirSync(settingsDir, { recursive: true });
|
|
@@ -2275,15 +2282,61 @@ hooksCmd.command('init').description('Initialize hooks in current project').opti
|
|
|
2275
2282
|
if (fs.existsSync(settingsPath) && !opts.force) {
|
|
2276
2283
|
try { settings = JSON.parse(fs.readFileSync(settingsPath, 'utf-8')); } catch {}
|
|
2277
2284
|
}
|
|
2285
|
+
|
|
2278
2286
|
// Fix schema if present
|
|
2279
2287
|
if (settings.$schema) {
|
|
2280
2288
|
settings.$schema = 'https://json.schemastore.org/claude-code-settings.json';
|
|
2281
2289
|
}
|
|
2290
|
+
|
|
2282
2291
|
// Clean up invalid hook names
|
|
2283
2292
|
if (settings.hooks) {
|
|
2284
2293
|
if (settings.hooks.Start) { delete settings.hooks.Start; }
|
|
2285
2294
|
if (settings.hooks.End) { delete settings.hooks.End; }
|
|
2286
2295
|
}
|
|
2296
|
+
|
|
2297
|
+
// Environment variables for intelligence (unless --minimal or --no-env)
|
|
2298
|
+
if (!opts.minimal && opts.env !== false) {
|
|
2299
|
+
settings.env = settings.env || {};
|
|
2300
|
+
settings.env.RUVECTOR_INTELLIGENCE_ENABLED = settings.env.RUVECTOR_INTELLIGENCE_ENABLED || 'true';
|
|
2301
|
+
settings.env.RUVECTOR_LEARNING_RATE = settings.env.RUVECTOR_LEARNING_RATE || '0.1';
|
|
2302
|
+
settings.env.RUVECTOR_MEMORY_BACKEND = settings.env.RUVECTOR_MEMORY_BACKEND || 'rvlite';
|
|
2303
|
+
settings.env.INTELLIGENCE_MODE = settings.env.INTELLIGENCE_MODE || 'treatment';
|
|
2304
|
+
console.log(chalk.blue(' ✓ Environment variables configured'));
|
|
2305
|
+
}
|
|
2306
|
+
|
|
2307
|
+
// Permissions (unless --minimal or --no-permissions)
|
|
2308
|
+
if (!opts.minimal && opts.permissions !== false) {
|
|
2309
|
+
settings.permissions = settings.permissions || {};
|
|
2310
|
+
settings.permissions.allow = settings.permissions.allow || [
|
|
2311
|
+
'Bash(npm run:*)',
|
|
2312
|
+
'Bash(npm test:*)',
|
|
2313
|
+
'Bash(npm install:*)',
|
|
2314
|
+
'Bash(npx:*)',
|
|
2315
|
+
'Bash(git status)',
|
|
2316
|
+
'Bash(git diff:*)',
|
|
2317
|
+
'Bash(git log:*)',
|
|
2318
|
+
'Bash(git add:*)',
|
|
2319
|
+
'Bash(git commit:*)',
|
|
2320
|
+
'Bash(git push)',
|
|
2321
|
+
'Bash(git branch:*)',
|
|
2322
|
+
'Bash(git checkout:*)',
|
|
2323
|
+
'Bash(ls:*)',
|
|
2324
|
+
'Bash(pwd)',
|
|
2325
|
+
'Bash(cat:*)',
|
|
2326
|
+
'Bash(mkdir:*)',
|
|
2327
|
+
'Bash(which:*)',
|
|
2328
|
+
'Bash(node:*)',
|
|
2329
|
+
'Bash(ruvector:*)'
|
|
2330
|
+
];
|
|
2331
|
+
settings.permissions.deny = settings.permissions.deny || [
|
|
2332
|
+
'Bash(rm -rf /)',
|
|
2333
|
+
'Bash(sudo rm:*)',
|
|
2334
|
+
'Bash(chmod 777:*)'
|
|
2335
|
+
];
|
|
2336
|
+
console.log(chalk.blue(' ✓ Permissions configured'));
|
|
2337
|
+
}
|
|
2338
|
+
|
|
2339
|
+
// Core hooks (always included)
|
|
2287
2340
|
settings.hooks = settings.hooks || {};
|
|
2288
2341
|
settings.hooks.PreToolUse = [
|
|
2289
2342
|
{ matcher: 'Edit|Write|MultiEdit', hooks: [{ type: 'command', command: 'npx ruvector hooks pre-edit "$TOOL_INPUT_file_path"' }] },
|
|
@@ -2295,53 +2348,135 @@ hooksCmd.command('init').description('Initialize hooks in current project').opti
|
|
|
2295
2348
|
];
|
|
2296
2349
|
settings.hooks.SessionStart = [{ hooks: [{ type: 'command', command: 'npx ruvector hooks session-start' }] }];
|
|
2297
2350
|
settings.hooks.Stop = [{ hooks: [{ type: 'command', command: 'npx ruvector hooks session-end' }] }];
|
|
2351
|
+
console.log(chalk.blue(' ✓ Core hooks (PreToolUse, PostToolUse, SessionStart, Stop)'));
|
|
2352
|
+
|
|
2353
|
+
// Advanced hooks (unless --minimal)
|
|
2354
|
+
if (!opts.minimal) {
|
|
2355
|
+
// UserPromptSubmit - context suggestions on each prompt
|
|
2356
|
+
settings.hooks.UserPromptSubmit = [{
|
|
2357
|
+
hooks: [{
|
|
2358
|
+
type: 'command',
|
|
2359
|
+
timeout: 2000,
|
|
2360
|
+
command: 'npx ruvector hooks suggest-context'
|
|
2361
|
+
}]
|
|
2362
|
+
}];
|
|
2363
|
+
|
|
2364
|
+
// PreCompact - preserve important context before compaction
|
|
2365
|
+
settings.hooks.PreCompact = [
|
|
2366
|
+
{
|
|
2367
|
+
matcher: 'auto',
|
|
2368
|
+
hooks: [{
|
|
2369
|
+
type: 'command',
|
|
2370
|
+
timeout: 3000,
|
|
2371
|
+
command: 'npx ruvector hooks pre-compact --auto'
|
|
2372
|
+
}]
|
|
2373
|
+
},
|
|
2374
|
+
{
|
|
2375
|
+
matcher: 'manual',
|
|
2376
|
+
hooks: [{
|
|
2377
|
+
type: 'command',
|
|
2378
|
+
timeout: 3000,
|
|
2379
|
+
command: 'npx ruvector hooks pre-compact'
|
|
2380
|
+
}]
|
|
2381
|
+
}
|
|
2382
|
+
];
|
|
2383
|
+
|
|
2384
|
+
// Notification - track all notifications for learning
|
|
2385
|
+
settings.hooks.Notification = [{
|
|
2386
|
+
matcher: '.*',
|
|
2387
|
+
hooks: [{
|
|
2388
|
+
type: 'command',
|
|
2389
|
+
timeout: 1000,
|
|
2390
|
+
command: 'npx ruvector hooks track-notification'
|
|
2391
|
+
}]
|
|
2392
|
+
}];
|
|
2393
|
+
console.log(chalk.blue(' ✓ Advanced hooks (UserPromptSubmit, PreCompact, Notification)'));
|
|
2394
|
+
}
|
|
2395
|
+
|
|
2298
2396
|
fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2));
|
|
2299
|
-
console.log(chalk.green('✅ Hooks initialized in .claude/settings.json'));
|
|
2397
|
+
console.log(chalk.green('\n✅ Hooks initialized in .claude/settings.json'));
|
|
2300
2398
|
|
|
2301
2399
|
// Create CLAUDE.md if it doesn't exist (or force)
|
|
2302
2400
|
const claudeMdPath = path.join(process.cwd(), 'CLAUDE.md');
|
|
2303
2401
|
if (opts.claudeMd !== false && (!fs.existsSync(claudeMdPath) || opts.force)) {
|
|
2304
2402
|
const claudeMdContent = `# Claude Code Project Configuration
|
|
2305
2403
|
|
|
2306
|
-
## RuVector Self-Learning
|
|
2404
|
+
## RuVector Self-Learning Intelligence
|
|
2307
2405
|
|
|
2308
|
-
This project uses RuVector's self-learning intelligence hooks for enhanced AI-assisted development.
|
|
2406
|
+
This project uses RuVector's self-learning intelligence hooks for enhanced AI-assisted development with Q-learning, vector memory, and automatic agent routing.
|
|
2309
2407
|
|
|
2310
2408
|
### Active Hooks
|
|
2311
2409
|
|
|
2312
2410
|
| Hook | Trigger | Purpose |
|
|
2313
2411
|
|------|---------|---------|
|
|
2314
|
-
| PreToolUse | Before Edit/Write/Bash | Agent routing,
|
|
2315
|
-
| PostToolUse | After Edit/Write/Bash | Q-learning update, pattern recording |
|
|
2316
|
-
| SessionStart | Conversation begins | Load intelligence, display stats |
|
|
2317
|
-
| Stop | Conversation ends | Save learning data |
|
|
2412
|
+
| **PreToolUse** | Before Edit/Write/Bash | Agent routing, file analysis, command risk assessment |
|
|
2413
|
+
| **PostToolUse** | After Edit/Write/Bash | Q-learning update, pattern recording, outcome tracking |
|
|
2414
|
+
| **SessionStart** | Conversation begins | Load intelligence state, display learning stats |
|
|
2415
|
+
| **Stop** | Conversation ends | Save learning data, export metrics |
|
|
2416
|
+
| **UserPromptSubmit** | User sends message | Context suggestions, pattern recommendations |
|
|
2417
|
+
| **PreCompact** | Before context compaction | Preserve important context and memories |
|
|
2418
|
+
| **Notification** | Any notification | Track events for learning |
|
|
2419
|
+
|
|
2420
|
+
### Environment Variables
|
|
2421
|
+
|
|
2422
|
+
| Variable | Default | Description |
|
|
2423
|
+
|----------|---------|-------------|
|
|
2424
|
+
| \`RUVECTOR_INTELLIGENCE_ENABLED\` | \`true\` | Enable/disable intelligence layer |
|
|
2425
|
+
| \`RUVECTOR_LEARNING_RATE\` | \`0.1\` | Q-learning rate (0.0-1.0) |
|
|
2426
|
+
| \`RUVECTOR_MEMORY_BACKEND\` | \`rvlite\` | Memory storage backend |
|
|
2427
|
+
| \`INTELLIGENCE_MODE\` | \`treatment\` | A/B testing mode (treatment/control) |
|
|
2318
2428
|
|
|
2319
2429
|
### Commands
|
|
2320
2430
|
|
|
2321
2431
|
\`\`\`bash
|
|
2432
|
+
# Initialize hooks in a project
|
|
2433
|
+
npx ruvector hooks init
|
|
2434
|
+
|
|
2322
2435
|
# View learning statistics
|
|
2323
2436
|
npx ruvector hooks stats
|
|
2324
2437
|
|
|
2325
2438
|
# Route a task to best agent
|
|
2326
2439
|
npx ruvector hooks route "implement feature X"
|
|
2327
2440
|
|
|
2328
|
-
# Store context in memory
|
|
2441
|
+
# Store context in vector memory
|
|
2329
2442
|
npx ruvector hooks remember "important context" -t project
|
|
2330
2443
|
|
|
2331
|
-
# Recall from memory
|
|
2444
|
+
# Recall from memory (semantic search)
|
|
2332
2445
|
npx ruvector hooks recall "context query"
|
|
2446
|
+
|
|
2447
|
+
# Manual session management
|
|
2448
|
+
npx ruvector hooks session-start
|
|
2449
|
+
npx ruvector hooks session-end
|
|
2333
2450
|
\`\`\`
|
|
2334
2451
|
|
|
2335
2452
|
### How It Works
|
|
2336
2453
|
|
|
2337
|
-
1. **Pre-edit hooks** analyze files and suggest the best agent
|
|
2454
|
+
1. **Pre-edit hooks** analyze files and suggest the best agent based on learned patterns
|
|
2338
2455
|
2. **Post-edit hooks** record outcomes to improve future suggestions via Q-learning
|
|
2339
|
-
3. **Memory hooks** store and retrieve context using vector embeddings
|
|
2456
|
+
3. **Memory hooks** store and retrieve context using vector embeddings (cosine similarity)
|
|
2340
2457
|
4. **Session hooks** manage learning state across conversations
|
|
2458
|
+
5. **UserPromptSubmit** provides context suggestions on each message
|
|
2459
|
+
6. **PreCompact** preserves critical context before conversation compaction
|
|
2460
|
+
7. **Notification** tracks all events for continuous learning
|
|
2461
|
+
|
|
2462
|
+
### Learning Data
|
|
2463
|
+
|
|
2464
|
+
Stored in \`.ruvector/intelligence.json\`:
|
|
2465
|
+
- **Q-table patterns**: State-action values for agent routing
|
|
2466
|
+
- **Vector memories**: Embeddings for semantic recall
|
|
2467
|
+
- **Trajectories**: Learning history for improvement tracking
|
|
2468
|
+
- **Error patterns**: Known issues and suggested fixes
|
|
2341
2469
|
|
|
2342
|
-
###
|
|
2470
|
+
### Init Options
|
|
2343
2471
|
|
|
2344
|
-
|
|
2472
|
+
\`\`\`bash
|
|
2473
|
+
npx ruvector hooks init # Full configuration
|
|
2474
|
+
npx ruvector hooks init --minimal # Basic hooks only
|
|
2475
|
+
npx ruvector hooks init --no-env # Skip environment variables
|
|
2476
|
+
npx ruvector hooks init --no-permissions # Skip permissions
|
|
2477
|
+
npx ruvector hooks init --no-claude-md # Skip this file
|
|
2478
|
+
npx ruvector hooks init --force # Overwrite existing
|
|
2479
|
+
\`\`\`
|
|
2345
2480
|
|
|
2346
2481
|
---
|
|
2347
2482
|
*Powered by [RuVector](https://github.com/ruvnet/ruvector) self-learning intelligence*
|