genesis-ai-cli 7.4.5
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/.env.example +78 -0
- package/README.md +282 -0
- package/dist/src/active-inference/actions.d.ts +75 -0
- package/dist/src/active-inference/actions.js +250 -0
- package/dist/src/active-inference/autonomous-loop.d.ts +103 -0
- package/dist/src/active-inference/autonomous-loop.js +289 -0
- package/dist/src/active-inference/core.d.ts +85 -0
- package/dist/src/active-inference/core.js +555 -0
- package/dist/src/active-inference/demo-autonomous-loop.d.ts +8 -0
- package/dist/src/active-inference/demo-autonomous-loop.js +338 -0
- package/dist/src/active-inference/demo-value-integration.d.ts +8 -0
- package/dist/src/active-inference/demo-value-integration.js +174 -0
- package/dist/src/active-inference/index.d.ts +32 -0
- package/dist/src/active-inference/index.js +88 -0
- package/dist/src/active-inference/integration.d.ts +114 -0
- package/dist/src/active-inference/integration.js +698 -0
- package/dist/src/active-inference/memory-integration.d.ts +51 -0
- package/dist/src/active-inference/memory-integration.js +232 -0
- package/dist/src/active-inference/observations.d.ts +67 -0
- package/dist/src/active-inference/observations.js +147 -0
- package/dist/src/active-inference/test-active-inference.d.ts +8 -0
- package/dist/src/active-inference/test-active-inference.js +320 -0
- package/dist/src/active-inference/test-value-integration.d.ts +6 -0
- package/dist/src/active-inference/test-value-integration.js +168 -0
- package/dist/src/active-inference/types.d.ts +150 -0
- package/dist/src/active-inference/types.js +59 -0
- package/dist/src/active-inference/value-integration.d.ts +164 -0
- package/dist/src/active-inference/value-integration.js +459 -0
- package/dist/src/agents/base-agent.d.ts +53 -0
- package/dist/src/agents/base-agent.js +178 -0
- package/dist/src/agents/builder.d.ts +67 -0
- package/dist/src/agents/builder.js +537 -0
- package/dist/src/agents/critic.d.ts +35 -0
- package/dist/src/agents/critic.js +322 -0
- package/dist/src/agents/ethicist.d.ts +54 -0
- package/dist/src/agents/ethicist.js +393 -0
- package/dist/src/agents/explorer.d.ts +26 -0
- package/dist/src/agents/explorer.js +216 -0
- package/dist/src/agents/feeling.d.ts +41 -0
- package/dist/src/agents/feeling.js +320 -0
- package/dist/src/agents/index.d.ts +111 -0
- package/dist/src/agents/index.js +222 -0
- package/dist/src/agents/memory.d.ts +69 -0
- package/dist/src/agents/memory.js +404 -0
- package/dist/src/agents/message-bus.d.ts +88 -0
- package/dist/src/agents/message-bus.js +267 -0
- package/dist/src/agents/narrator.d.ts +90 -0
- package/dist/src/agents/narrator.js +473 -0
- package/dist/src/agents/planner.d.ts +38 -0
- package/dist/src/agents/planner.js +341 -0
- package/dist/src/agents/predictor.d.ts +73 -0
- package/dist/src/agents/predictor.js +506 -0
- package/dist/src/agents/sensor.d.ts +88 -0
- package/dist/src/agents/sensor.js +377 -0
- package/dist/src/agents/test-agents.d.ts +6 -0
- package/dist/src/agents/test-agents.js +73 -0
- package/dist/src/agents/types.d.ts +194 -0
- package/dist/src/agents/types.js +7 -0
- package/dist/src/brain/index.d.ts +185 -0
- package/dist/src/brain/index.js +843 -0
- package/dist/src/brain/trace.d.ts +91 -0
- package/dist/src/brain/trace.js +327 -0
- package/dist/src/brain/types.d.ts +165 -0
- package/dist/src/brain/types.js +51 -0
- package/dist/src/cli/chat.d.ts +237 -0
- package/dist/src/cli/chat.js +1959 -0
- package/dist/src/cli/dispatcher.d.ts +182 -0
- package/dist/src/cli/dispatcher.js +718 -0
- package/dist/src/cli/human-loop.d.ts +170 -0
- package/dist/src/cli/human-loop.js +543 -0
- package/dist/src/cli/index.d.ts +12 -0
- package/dist/src/cli/index.js +28 -0
- package/dist/src/cli/interactive.d.ts +141 -0
- package/dist/src/cli/interactive.js +757 -0
- package/dist/src/cli/ui.d.ts +205 -0
- package/dist/src/cli/ui.js +632 -0
- package/dist/src/consciousness/attention-schema.d.ts +154 -0
- package/dist/src/consciousness/attention-schema.js +432 -0
- package/dist/src/consciousness/global-workspace.d.ts +149 -0
- package/dist/src/consciousness/global-workspace.js +422 -0
- package/dist/src/consciousness/index.d.ts +186 -0
- package/dist/src/consciousness/index.js +476 -0
- package/dist/src/consciousness/phi-calculator.d.ts +119 -0
- package/dist/src/consciousness/phi-calculator.js +445 -0
- package/dist/src/consciousness/phi-decisions.d.ts +169 -0
- package/dist/src/consciousness/phi-decisions.js +383 -0
- package/dist/src/consciousness/phi-monitor.d.ts +153 -0
- package/dist/src/consciousness/phi-monitor.js +465 -0
- package/dist/src/consciousness/types.d.ts +260 -0
- package/dist/src/consciousness/types.js +44 -0
- package/dist/src/daemon/dream-mode.d.ts +115 -0
- package/dist/src/daemon/dream-mode.js +470 -0
- package/dist/src/daemon/index.d.ts +162 -0
- package/dist/src/daemon/index.js +542 -0
- package/dist/src/daemon/maintenance.d.ts +139 -0
- package/dist/src/daemon/maintenance.js +549 -0
- package/dist/src/daemon/process.d.ts +82 -0
- package/dist/src/daemon/process.js +442 -0
- package/dist/src/daemon/scheduler.d.ts +90 -0
- package/dist/src/daemon/scheduler.js +494 -0
- package/dist/src/daemon/types.d.ts +213 -0
- package/dist/src/daemon/types.js +50 -0
- package/dist/src/epistemic/index.d.ts +74 -0
- package/dist/src/epistemic/index.js +225 -0
- package/dist/src/grounding/epistemic-stack.d.ts +100 -0
- package/dist/src/grounding/epistemic-stack.js +408 -0
- package/dist/src/grounding/feedback.d.ts +98 -0
- package/dist/src/grounding/feedback.js +276 -0
- package/dist/src/grounding/index.d.ts +123 -0
- package/dist/src/grounding/index.js +224 -0
- package/dist/src/grounding/verifier.d.ts +149 -0
- package/dist/src/grounding/verifier.js +484 -0
- package/dist/src/healing/detector.d.ts +110 -0
- package/dist/src/healing/detector.js +436 -0
- package/dist/src/healing/fixer.d.ts +138 -0
- package/dist/src/healing/fixer.js +572 -0
- package/dist/src/healing/index.d.ts +23 -0
- package/dist/src/healing/index.js +43 -0
- package/dist/src/hooks/index.d.ts +135 -0
- package/dist/src/hooks/index.js +317 -0
- package/dist/src/index.d.ts +23 -0
- package/dist/src/index.js +1266 -0
- package/dist/src/kernel/index.d.ts +155 -0
- package/dist/src/kernel/index.js +795 -0
- package/dist/src/kernel/invariants.d.ts +153 -0
- package/dist/src/kernel/invariants.js +355 -0
- package/dist/src/kernel/test-kernel.d.ts +6 -0
- package/dist/src/kernel/test-kernel.js +108 -0
- package/dist/src/kernel/test-real-mcp.d.ts +10 -0
- package/dist/src/kernel/test-real-mcp.js +295 -0
- package/dist/src/llm/index.d.ts +146 -0
- package/dist/src/llm/index.js +428 -0
- package/dist/src/llm/router.d.ts +136 -0
- package/dist/src/llm/router.js +510 -0
- package/dist/src/mcp/index.d.ts +85 -0
- package/dist/src/mcp/index.js +657 -0
- package/dist/src/mcp/resilient.d.ts +139 -0
- package/dist/src/mcp/resilient.js +417 -0
- package/dist/src/memory/cache.d.ts +118 -0
- package/dist/src/memory/cache.js +356 -0
- package/dist/src/memory/cognitive-workspace.d.ts +231 -0
- package/dist/src/memory/cognitive-workspace.js +521 -0
- package/dist/src/memory/consolidation.d.ts +99 -0
- package/dist/src/memory/consolidation.js +443 -0
- package/dist/src/memory/episodic.d.ts +114 -0
- package/dist/src/memory/episodic.js +394 -0
- package/dist/src/memory/forgetting.d.ts +134 -0
- package/dist/src/memory/forgetting.js +324 -0
- package/dist/src/memory/index.d.ts +211 -0
- package/dist/src/memory/index.js +367 -0
- package/dist/src/memory/indexer.d.ts +123 -0
- package/dist/src/memory/indexer.js +479 -0
- package/dist/src/memory/procedural.d.ts +136 -0
- package/dist/src/memory/procedural.js +479 -0
- package/dist/src/memory/semantic.d.ts +132 -0
- package/dist/src/memory/semantic.js +497 -0
- package/dist/src/memory/types.d.ts +193 -0
- package/dist/src/memory/types.js +15 -0
- package/dist/src/orchestrator.d.ts +65 -0
- package/dist/src/orchestrator.js +317 -0
- package/dist/src/persistence/index.d.ts +257 -0
- package/dist/src/persistence/index.js +763 -0
- package/dist/src/pipeline/executor.d.ts +51 -0
- package/dist/src/pipeline/executor.js +695 -0
- package/dist/src/pipeline/index.d.ts +7 -0
- package/dist/src/pipeline/index.js +11 -0
- package/dist/src/self-production.d.ts +67 -0
- package/dist/src/self-production.js +205 -0
- package/dist/src/subagents/executor.d.ts +58 -0
- package/dist/src/subagents/executor.js +283 -0
- package/dist/src/subagents/index.d.ts +37 -0
- package/dist/src/subagents/index.js +53 -0
- package/dist/src/subagents/registry.d.ts +23 -0
- package/dist/src/subagents/registry.js +167 -0
- package/dist/src/subagents/types.d.ts +79 -0
- package/dist/src/subagents/types.js +14 -0
- package/dist/src/tools/bash.d.ts +139 -0
- package/dist/src/tools/bash.js +583 -0
- package/dist/src/tools/edit.d.ts +125 -0
- package/dist/src/tools/edit.js +424 -0
- package/dist/src/tools/git.d.ts +179 -0
- package/dist/src/tools/git.js +504 -0
- package/dist/src/tools/index.d.ts +21 -0
- package/dist/src/tools/index.js +163 -0
- package/dist/src/types.d.ts +145 -0
- package/dist/src/types.js +7 -0
- package/dist/src/world-model/decoder.d.ts +163 -0
- package/dist/src/world-model/decoder.js +517 -0
- package/dist/src/world-model/digital-twin.d.ts +219 -0
- package/dist/src/world-model/digital-twin.js +695 -0
- package/dist/src/world-model/encoder.d.ts +141 -0
- package/dist/src/world-model/encoder.js +564 -0
- package/dist/src/world-model/index.d.ts +221 -0
- package/dist/src/world-model/index.js +772 -0
- package/dist/src/world-model/predictor.d.ts +161 -0
- package/dist/src/world-model/predictor.js +681 -0
- package/dist/src/world-model/test-value-jepa.d.ts +8 -0
- package/dist/src/world-model/test-value-jepa.js +430 -0
- package/dist/src/world-model/types.d.ts +341 -0
- package/dist/src/world-model/types.js +69 -0
- package/dist/src/world-model/value-jepa.d.ts +247 -0
- package/dist/src/world-model/value-jepa.js +622 -0
- package/dist/test/brain.test.d.ts +11 -0
- package/dist/test/brain.test.js +358 -0
- package/dist/test/cli/dispatcher.test.d.ts +4 -0
- package/dist/test/cli/dispatcher.test.js +332 -0
- package/dist/test/cli/human-loop.test.d.ts +4 -0
- package/dist/test/cli/human-loop.test.js +270 -0
- package/dist/test/grounding/feedback.test.d.ts +4 -0
- package/dist/test/grounding/feedback.test.js +462 -0
- package/dist/test/grounding/verifier.test.d.ts +4 -0
- package/dist/test/grounding/verifier.test.js +442 -0
- package/dist/test/grounding.test.d.ts +6 -0
- package/dist/test/grounding.test.js +246 -0
- package/dist/test/healing/detector.test.d.ts +4 -0
- package/dist/test/healing/detector.test.js +266 -0
- package/dist/test/healing/fixer.test.d.ts +4 -0
- package/dist/test/healing/fixer.test.js +369 -0
- package/dist/test/integration.test.d.ts +5 -0
- package/dist/test/integration.test.js +290 -0
- package/dist/test/tools/bash.test.d.ts +4 -0
- package/dist/test/tools/bash.test.js +348 -0
- package/dist/test/tools/edit.test.d.ts +4 -0
- package/dist/test/tools/edit.test.js +350 -0
- package/dist/test/tools/git.test.d.ts +4 -0
- package/dist/test/tools/git.test.js +350 -0
- package/package.json +60 -0
|
@@ -0,0 +1,479 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Genesis 6.8 - Project Indexer
|
|
4
|
+
*
|
|
5
|
+
* Indexes project files for local full-text search.
|
|
6
|
+
* No LLM needed for code search - instant results.
|
|
7
|
+
*
|
|
8
|
+
* Uses JSON storage with in-memory trigram index for fast search.
|
|
9
|
+
*/
|
|
10
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
13
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
14
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(o, k2, desc);
|
|
17
|
+
}) : (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
o[k2] = m[k];
|
|
20
|
+
}));
|
|
21
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
22
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
23
|
+
}) : function(o, v) {
|
|
24
|
+
o["default"] = v;
|
|
25
|
+
});
|
|
26
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
27
|
+
var ownKeys = function(o) {
|
|
28
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
29
|
+
var ar = [];
|
|
30
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
31
|
+
return ar;
|
|
32
|
+
};
|
|
33
|
+
return ownKeys(o);
|
|
34
|
+
};
|
|
35
|
+
return function (mod) {
|
|
36
|
+
if (mod && mod.__esModule) return mod;
|
|
37
|
+
var result = {};
|
|
38
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
39
|
+
__setModuleDefault(result, mod);
|
|
40
|
+
return result;
|
|
41
|
+
};
|
|
42
|
+
})();
|
|
43
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
+
exports.ProjectIndexer = void 0;
|
|
45
|
+
exports.getProjectIndexer = getProjectIndexer;
|
|
46
|
+
exports.resetProjectIndexer = resetProjectIndexer;
|
|
47
|
+
const fs = __importStar(require("fs"));
|
|
48
|
+
const path = __importStar(require("path"));
|
|
49
|
+
const crypto = __importStar(require("crypto"));
|
|
50
|
+
// ============================================================================
|
|
51
|
+
// Default Config
|
|
52
|
+
// ============================================================================
|
|
53
|
+
const DEFAULT_CONFIG = {
|
|
54
|
+
projectRoot: process.cwd(),
|
|
55
|
+
indexPath: path.join(process.cwd(), '.genesis', 'index.json'),
|
|
56
|
+
include: [
|
|
57
|
+
'**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx',
|
|
58
|
+
'**/*.py', '**/*.go', '**/*.rs', '**/*.java',
|
|
59
|
+
'**/*.md', '**/*.json', '**/*.yaml', '**/*.yml',
|
|
60
|
+
'**/*.html', '**/*.css', '**/*.scss',
|
|
61
|
+
],
|
|
62
|
+
exclude: [
|
|
63
|
+
'node_modules/**', 'dist/**', 'build/**', '.git/**',
|
|
64
|
+
'*.min.js', '*.bundle.js', 'package-lock.json',
|
|
65
|
+
'.genesis/**', 'coverage/**', '.next/**',
|
|
66
|
+
],
|
|
67
|
+
maxFileSize: 1024 * 1024, // 1MB
|
|
68
|
+
incremental: true,
|
|
69
|
+
};
|
|
70
|
+
// ============================================================================
|
|
71
|
+
// Language Detection
|
|
72
|
+
// ============================================================================
|
|
73
|
+
const LANGUAGE_MAP = {
|
|
74
|
+
'.ts': 'typescript',
|
|
75
|
+
'.tsx': 'typescript',
|
|
76
|
+
'.js': 'javascript',
|
|
77
|
+
'.jsx': 'javascript',
|
|
78
|
+
'.py': 'python',
|
|
79
|
+
'.go': 'go',
|
|
80
|
+
'.rs': 'rust',
|
|
81
|
+
'.java': 'java',
|
|
82
|
+
'.md': 'markdown',
|
|
83
|
+
'.json': 'json',
|
|
84
|
+
'.yaml': 'yaml',
|
|
85
|
+
'.yml': 'yaml',
|
|
86
|
+
'.html': 'html',
|
|
87
|
+
'.css': 'css',
|
|
88
|
+
'.scss': 'scss',
|
|
89
|
+
};
|
|
90
|
+
function detectLanguage(filePath) {
|
|
91
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
92
|
+
return LANGUAGE_MAP[ext] || 'text';
|
|
93
|
+
}
|
|
94
|
+
// ============================================================================
|
|
95
|
+
// Symbol Extraction
|
|
96
|
+
// ============================================================================
|
|
97
|
+
function extractSymbols(content, language) {
|
|
98
|
+
const symbols = [];
|
|
99
|
+
// TypeScript/JavaScript
|
|
100
|
+
if (language === 'typescript' || language === 'javascript') {
|
|
101
|
+
// Functions
|
|
102
|
+
const funcMatches = content.matchAll(/(?:function|const|let|var)\s+(\w+)\s*(?:=\s*(?:async\s*)?\(|[\(:])/g);
|
|
103
|
+
for (const m of funcMatches)
|
|
104
|
+
symbols.push(m[1]);
|
|
105
|
+
// Classes
|
|
106
|
+
const classMatches = content.matchAll(/class\s+(\w+)/g);
|
|
107
|
+
for (const m of classMatches)
|
|
108
|
+
symbols.push(m[1]);
|
|
109
|
+
// Interfaces/Types
|
|
110
|
+
const typeMatches = content.matchAll(/(?:interface|type)\s+(\w+)/g);
|
|
111
|
+
for (const m of typeMatches)
|
|
112
|
+
symbols.push(m[1]);
|
|
113
|
+
// Exports
|
|
114
|
+
const exportMatches = content.matchAll(/export\s+(?:const|function|class|interface|type)\s+(\w+)/g);
|
|
115
|
+
for (const m of exportMatches)
|
|
116
|
+
symbols.push(m[1]);
|
|
117
|
+
}
|
|
118
|
+
// Python
|
|
119
|
+
if (language === 'python') {
|
|
120
|
+
const defMatches = content.matchAll(/def\s+(\w+)/g);
|
|
121
|
+
for (const m of defMatches)
|
|
122
|
+
symbols.push(m[1]);
|
|
123
|
+
const classMatches = content.matchAll(/class\s+(\w+)/g);
|
|
124
|
+
for (const m of classMatches)
|
|
125
|
+
symbols.push(m[1]);
|
|
126
|
+
}
|
|
127
|
+
// Go
|
|
128
|
+
if (language === 'go') {
|
|
129
|
+
const funcMatches = content.matchAll(/func\s+(?:\([^)]+\)\s+)?(\w+)/g);
|
|
130
|
+
for (const m of funcMatches)
|
|
131
|
+
symbols.push(m[1]);
|
|
132
|
+
const typeMatches = content.matchAll(/type\s+(\w+)/g);
|
|
133
|
+
for (const m of typeMatches)
|
|
134
|
+
symbols.push(m[1]);
|
|
135
|
+
}
|
|
136
|
+
return [...new Set(symbols)];
|
|
137
|
+
}
|
|
138
|
+
// ============================================================================
|
|
139
|
+
// File Matching
|
|
140
|
+
// ============================================================================
|
|
141
|
+
function matchesPattern(filePath, pattern) {
|
|
142
|
+
// Convert glob to regex
|
|
143
|
+
const regex = pattern
|
|
144
|
+
.replace(/\./g, '\\.')
|
|
145
|
+
.replace(/\*\*/g, '{{GLOBSTAR}}')
|
|
146
|
+
.replace(/\*/g, '[^/]*')
|
|
147
|
+
.replace(/{{GLOBSTAR}}/g, '.*');
|
|
148
|
+
return new RegExp(`^${regex}$`).test(filePath);
|
|
149
|
+
}
|
|
150
|
+
function shouldIndex(filePath, config) {
|
|
151
|
+
const relative = path.relative(config.projectRoot, filePath);
|
|
152
|
+
// Check excludes first
|
|
153
|
+
for (const pattern of config.exclude) {
|
|
154
|
+
if (matchesPattern(relative, pattern))
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
// Check includes
|
|
158
|
+
for (const pattern of config.include) {
|
|
159
|
+
if (matchesPattern(relative, pattern))
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
// ============================================================================
|
|
165
|
+
// Project Indexer Class
|
|
166
|
+
// ============================================================================
|
|
167
|
+
class ProjectIndexer {
|
|
168
|
+
config;
|
|
169
|
+
index = new Map();
|
|
170
|
+
trigramIndex = new Map();
|
|
171
|
+
constructor(config) {
|
|
172
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
173
|
+
this.loadIndex();
|
|
174
|
+
}
|
|
175
|
+
// ==========================================================================
|
|
176
|
+
// Index Management
|
|
177
|
+
// ==========================================================================
|
|
178
|
+
/**
|
|
179
|
+
* Load existing index from disk
|
|
180
|
+
*/
|
|
181
|
+
loadIndex() {
|
|
182
|
+
try {
|
|
183
|
+
if (fs.existsSync(this.config.indexPath)) {
|
|
184
|
+
const raw = fs.readFileSync(this.config.indexPath, 'utf-8');
|
|
185
|
+
const data = JSON.parse(raw);
|
|
186
|
+
this.index = new Map(Object.entries(data.files || {}));
|
|
187
|
+
this.rebuildTrigramIndex();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
catch {
|
|
191
|
+
this.index = new Map();
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Save index to disk
|
|
196
|
+
*/
|
|
197
|
+
saveIndex() {
|
|
198
|
+
try {
|
|
199
|
+
const dir = path.dirname(this.config.indexPath);
|
|
200
|
+
if (!fs.existsSync(dir)) {
|
|
201
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
202
|
+
}
|
|
203
|
+
fs.writeFileSync(this.config.indexPath, JSON.stringify({
|
|
204
|
+
files: Object.fromEntries(this.index),
|
|
205
|
+
lastIndexed: Date.now(),
|
|
206
|
+
}, null, 2));
|
|
207
|
+
}
|
|
208
|
+
catch (e) {
|
|
209
|
+
console.error('[Indexer] Failed to save:', e);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Build trigram index for fast search
|
|
214
|
+
*/
|
|
215
|
+
rebuildTrigramIndex() {
|
|
216
|
+
this.trigramIndex.clear();
|
|
217
|
+
for (const [filePath, file] of this.index) {
|
|
218
|
+
const content = file.content.toLowerCase();
|
|
219
|
+
for (let i = 0; i < content.length - 2; i++) {
|
|
220
|
+
const trigram = content.slice(i, i + 3);
|
|
221
|
+
if (!this.trigramIndex.has(trigram)) {
|
|
222
|
+
this.trigramIndex.set(trigram, new Set());
|
|
223
|
+
}
|
|
224
|
+
this.trigramIndex.get(trigram).add(filePath);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Index the entire project
|
|
230
|
+
*/
|
|
231
|
+
async indexProject() {
|
|
232
|
+
console.log(`[Indexer] Indexing project: ${this.config.projectRoot}`);
|
|
233
|
+
const startTime = Date.now();
|
|
234
|
+
const files = this.walkDirectory(this.config.projectRoot);
|
|
235
|
+
let indexed = 0;
|
|
236
|
+
let skipped = 0;
|
|
237
|
+
for (const filePath of files) {
|
|
238
|
+
if (!shouldIndex(filePath, this.config)) {
|
|
239
|
+
skipped++;
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
try {
|
|
243
|
+
const stats = fs.statSync(filePath);
|
|
244
|
+
// Skip large files
|
|
245
|
+
if (stats.size > this.config.maxFileSize) {
|
|
246
|
+
skipped++;
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
// Check if file changed (incremental)
|
|
250
|
+
if (this.config.incremental) {
|
|
251
|
+
const existing = this.index.get(filePath);
|
|
252
|
+
if (existing && existing.mtime === stats.mtimeMs) {
|
|
253
|
+
continue; // Skip unchanged
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
// Index file
|
|
257
|
+
const content = fs.readFileSync(filePath, 'utf-8');
|
|
258
|
+
const hash = crypto.createHash('sha256').update(content).digest('hex').slice(0, 16);
|
|
259
|
+
const language = detectLanguage(filePath);
|
|
260
|
+
const indexedFile = {
|
|
261
|
+
path: path.relative(this.config.projectRoot, filePath),
|
|
262
|
+
content,
|
|
263
|
+
hash,
|
|
264
|
+
size: stats.size,
|
|
265
|
+
mtime: stats.mtimeMs,
|
|
266
|
+
language,
|
|
267
|
+
lines: content.split('\n').length,
|
|
268
|
+
symbols: extractSymbols(content, language),
|
|
269
|
+
};
|
|
270
|
+
this.index.set(filePath, indexedFile);
|
|
271
|
+
indexed++;
|
|
272
|
+
}
|
|
273
|
+
catch (e) {
|
|
274
|
+
// Skip unreadable files
|
|
275
|
+
skipped++;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
this.rebuildTrigramIndex();
|
|
279
|
+
this.saveIndex();
|
|
280
|
+
const duration = Date.now() - startTime;
|
|
281
|
+
console.log(`[Indexer] Indexed ${indexed} files, skipped ${skipped} in ${duration}ms`);
|
|
282
|
+
return this.stats();
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Walk directory recursively
|
|
286
|
+
*/
|
|
287
|
+
walkDirectory(dir) {
|
|
288
|
+
const files = [];
|
|
289
|
+
try {
|
|
290
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
291
|
+
for (const entry of entries) {
|
|
292
|
+
const fullPath = path.join(dir, entry.name);
|
|
293
|
+
// Skip hidden directories and common exclusions
|
|
294
|
+
if (entry.name.startsWith('.') && entry.isDirectory())
|
|
295
|
+
continue;
|
|
296
|
+
if (entry.name === 'node_modules')
|
|
297
|
+
continue;
|
|
298
|
+
if (entry.isDirectory()) {
|
|
299
|
+
files.push(...this.walkDirectory(fullPath));
|
|
300
|
+
}
|
|
301
|
+
else if (entry.isFile()) {
|
|
302
|
+
files.push(fullPath);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
catch {
|
|
307
|
+
// Skip unreadable directories
|
|
308
|
+
}
|
|
309
|
+
return files;
|
|
310
|
+
}
|
|
311
|
+
// ==========================================================================
|
|
312
|
+
// Search
|
|
313
|
+
// ==========================================================================
|
|
314
|
+
/**
|
|
315
|
+
* Search for a string in the codebase
|
|
316
|
+
*/
|
|
317
|
+
search(query, options = {}) {
|
|
318
|
+
const { limit = 20, caseSensitive = false } = options;
|
|
319
|
+
const results = [];
|
|
320
|
+
// Use trigram index for candidate files
|
|
321
|
+
const candidates = this.findCandidates(query.toLowerCase());
|
|
322
|
+
for (const filePath of candidates) {
|
|
323
|
+
const file = this.index.get(filePath);
|
|
324
|
+
if (!file)
|
|
325
|
+
continue;
|
|
326
|
+
const matches = this.findMatches(file.content, query, caseSensitive);
|
|
327
|
+
if (matches.length > 0) {
|
|
328
|
+
results.push({
|
|
329
|
+
path: file.path,
|
|
330
|
+
matches,
|
|
331
|
+
score: matches.length,
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
// Sort by score and limit
|
|
336
|
+
return results
|
|
337
|
+
.sort((a, b) => b.score - a.score)
|
|
338
|
+
.slice(0, limit);
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Find candidate files using trigram index
|
|
342
|
+
*/
|
|
343
|
+
findCandidates(query) {
|
|
344
|
+
if (query.length < 3) {
|
|
345
|
+
// For short queries, check all files
|
|
346
|
+
return new Set(this.index.keys());
|
|
347
|
+
}
|
|
348
|
+
const trigrams = [];
|
|
349
|
+
for (let i = 0; i < query.length - 2; i++) {
|
|
350
|
+
trigrams.push(query.slice(i, i + 3));
|
|
351
|
+
}
|
|
352
|
+
// Files must contain all trigrams
|
|
353
|
+
let candidates = new Set();
|
|
354
|
+
let first = true;
|
|
355
|
+
for (const trigram of trigrams) {
|
|
356
|
+
const files = this.trigramIndex.get(trigram);
|
|
357
|
+
if (!files)
|
|
358
|
+
return new Set(); // No matches
|
|
359
|
+
if (first) {
|
|
360
|
+
candidates = new Set(files);
|
|
361
|
+
first = false;
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
// Intersection - keep only candidates that are also in files
|
|
365
|
+
const intersection = new Set();
|
|
366
|
+
for (const f of candidates) {
|
|
367
|
+
if (files.has(f)) {
|
|
368
|
+
intersection.add(f);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
candidates = intersection;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
return candidates || new Set();
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Find matches in file content
|
|
378
|
+
*/
|
|
379
|
+
findMatches(content, query, caseSensitive) {
|
|
380
|
+
const matches = [];
|
|
381
|
+
const lines = content.split('\n');
|
|
382
|
+
const searchQuery = caseSensitive ? query : query.toLowerCase();
|
|
383
|
+
for (let i = 0; i < lines.length; i++) {
|
|
384
|
+
const line = caseSensitive ? lines[i] : lines[i].toLowerCase();
|
|
385
|
+
if (line.includes(searchQuery)) {
|
|
386
|
+
// Get context (2 lines before and after)
|
|
387
|
+
const context = [];
|
|
388
|
+
for (let j = Math.max(0, i - 2); j <= Math.min(lines.length - 1, i + 2); j++) {
|
|
389
|
+
if (j !== i)
|
|
390
|
+
context.push(lines[j]);
|
|
391
|
+
}
|
|
392
|
+
matches.push({
|
|
393
|
+
line: i + 1,
|
|
394
|
+
content: lines[i],
|
|
395
|
+
context,
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
return matches;
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Search for a symbol (function, class, etc.)
|
|
403
|
+
*/
|
|
404
|
+
searchSymbol(symbol) {
|
|
405
|
+
const results = [];
|
|
406
|
+
for (const [filePath, file] of this.index) {
|
|
407
|
+
if (file.symbols.some(s => s.toLowerCase().includes(symbol.toLowerCase()))) {
|
|
408
|
+
results.push({
|
|
409
|
+
path: file.path,
|
|
410
|
+
matches: [{
|
|
411
|
+
line: 0,
|
|
412
|
+
content: `Symbol: ${file.symbols.filter(s => s.toLowerCase().includes(symbol.toLowerCase())).join(', ')}`,
|
|
413
|
+
context: [],
|
|
414
|
+
}],
|
|
415
|
+
score: 10,
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
return results;
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Get file content
|
|
423
|
+
*/
|
|
424
|
+
getFile(filePath) {
|
|
425
|
+
const absolute = path.isAbsolute(filePath)
|
|
426
|
+
? filePath
|
|
427
|
+
: path.join(this.config.projectRoot, filePath);
|
|
428
|
+
return this.index.get(absolute) || null;
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* List all indexed files
|
|
432
|
+
*/
|
|
433
|
+
listFiles() {
|
|
434
|
+
return Array.from(this.index.values()).map(f => f.path);
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Get index statistics
|
|
438
|
+
*/
|
|
439
|
+
stats() {
|
|
440
|
+
let totalLines = 0;
|
|
441
|
+
let totalBytes = 0;
|
|
442
|
+
const languages = {};
|
|
443
|
+
for (const file of this.index.values()) {
|
|
444
|
+
totalLines += file.lines;
|
|
445
|
+
totalBytes += file.size;
|
|
446
|
+
languages[file.language] = (languages[file.language] || 0) + 1;
|
|
447
|
+
}
|
|
448
|
+
return {
|
|
449
|
+
totalFiles: this.index.size,
|
|
450
|
+
totalLines,
|
|
451
|
+
totalBytes,
|
|
452
|
+
languages,
|
|
453
|
+
lastIndexed: Date.now(),
|
|
454
|
+
indexPath: this.config.indexPath,
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Clear the index
|
|
459
|
+
*/
|
|
460
|
+
clear() {
|
|
461
|
+
this.index.clear();
|
|
462
|
+
this.trigramIndex.clear();
|
|
463
|
+
this.saveIndex();
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
exports.ProjectIndexer = ProjectIndexer;
|
|
467
|
+
// ============================================================================
|
|
468
|
+
// Singleton
|
|
469
|
+
// ============================================================================
|
|
470
|
+
let indexerInstance = null;
|
|
471
|
+
function getProjectIndexer(config) {
|
|
472
|
+
if (!indexerInstance) {
|
|
473
|
+
indexerInstance = new ProjectIndexer(config);
|
|
474
|
+
}
|
|
475
|
+
return indexerInstance;
|
|
476
|
+
}
|
|
477
|
+
function resetProjectIndexer() {
|
|
478
|
+
indexerInstance = null;
|
|
479
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Genesis 6.0 - Procedural Memory Store
|
|
3
|
+
*
|
|
4
|
+
* Stores skills and workflows - know-how.
|
|
5
|
+
* "How to do things"
|
|
6
|
+
*
|
|
7
|
+
* Key features:
|
|
8
|
+
* - Step-by-step procedures
|
|
9
|
+
* - Success rate tracking
|
|
10
|
+
* - Skill improvement over time
|
|
11
|
+
* - Prerequisites and dependencies
|
|
12
|
+
*
|
|
13
|
+
* Reference: Anderson, J. R. (1982). Acquisition of cognitive skill.
|
|
14
|
+
*/
|
|
15
|
+
import { ProceduralMemory, ParameterDef, IMemoryStore, MemoryFilter, StoreStats } from './types.js';
|
|
16
|
+
export interface ProceduralStoreConfig {
|
|
17
|
+
maxSize: number;
|
|
18
|
+
autoForget: boolean;
|
|
19
|
+
forgetThreshold: number;
|
|
20
|
+
minSuccessRate: number;
|
|
21
|
+
}
|
|
22
|
+
export interface CreateProceduralOptions {
|
|
23
|
+
name: string;
|
|
24
|
+
description: string;
|
|
25
|
+
steps: Array<{
|
|
26
|
+
action: string;
|
|
27
|
+
params?: Record<string, any>;
|
|
28
|
+
condition?: string;
|
|
29
|
+
fallback?: string;
|
|
30
|
+
}>;
|
|
31
|
+
requires?: string[];
|
|
32
|
+
inputs?: ParameterDef[];
|
|
33
|
+
outputs?: ParameterDef[];
|
|
34
|
+
importance?: number;
|
|
35
|
+
tags?: string[];
|
|
36
|
+
associations?: string[];
|
|
37
|
+
source?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface ExecutionResult {
|
|
40
|
+
success: boolean;
|
|
41
|
+
duration: number;
|
|
42
|
+
stepResults?: Array<{
|
|
43
|
+
step: number;
|
|
44
|
+
success: boolean;
|
|
45
|
+
error?: string;
|
|
46
|
+
}>;
|
|
47
|
+
error?: string;
|
|
48
|
+
}
|
|
49
|
+
export declare class ProceduralStore implements IMemoryStore<ProceduralMemory> {
|
|
50
|
+
private memories;
|
|
51
|
+
private config;
|
|
52
|
+
private byName;
|
|
53
|
+
private byTag;
|
|
54
|
+
private dependencies;
|
|
55
|
+
constructor(config?: Partial<ProceduralStoreConfig>);
|
|
56
|
+
store(input: Omit<ProceduralMemory, 'id' | 'created' | 'lastAccessed' | 'accessCount'>): ProceduralMemory;
|
|
57
|
+
/**
|
|
58
|
+
* Convenience method to create a procedural memory from options
|
|
59
|
+
*/
|
|
60
|
+
createSkill(options: CreateProceduralOptions): ProceduralMemory;
|
|
61
|
+
/**
|
|
62
|
+
* Improve an existing skill with new information
|
|
63
|
+
*/
|
|
64
|
+
private improveSkill;
|
|
65
|
+
get(id: string): ProceduralMemory | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Get by skill name
|
|
68
|
+
*/
|
|
69
|
+
getByName(name: string): ProceduralMemory | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* Get without updating access (for internal use)
|
|
72
|
+
*/
|
|
73
|
+
peek(id: string): ProceduralMemory | undefined;
|
|
74
|
+
update(id: string, updates: Partial<ProceduralMemory>): ProceduralMemory | undefined;
|
|
75
|
+
delete(id: string): boolean;
|
|
76
|
+
query(filter: MemoryFilter<ProceduralMemory>): ProceduralMemory[];
|
|
77
|
+
/**
|
|
78
|
+
* Search by keyword in name and description
|
|
79
|
+
*/
|
|
80
|
+
search(queryStr: string, limit?: number): ProceduralMemory[];
|
|
81
|
+
/**
|
|
82
|
+
* Record execution of a skill
|
|
83
|
+
*/
|
|
84
|
+
recordExecution(id: string, result: ExecutionResult): void;
|
|
85
|
+
/**
|
|
86
|
+
* Get skills that need practice (low success rate or retention)
|
|
87
|
+
*/
|
|
88
|
+
getSkillsNeedingPractice(): ProceduralMemory[];
|
|
89
|
+
/**
|
|
90
|
+
* Get mastered skills (high success rate and retention)
|
|
91
|
+
*/
|
|
92
|
+
getMasteredSkills(): ProceduralMemory[];
|
|
93
|
+
/**
|
|
94
|
+
* Get prerequisites for a skill
|
|
95
|
+
*/
|
|
96
|
+
getPrerequisites(id: string): ProceduralMemory[];
|
|
97
|
+
/**
|
|
98
|
+
* Get skills that depend on this skill
|
|
99
|
+
*/
|
|
100
|
+
getDependents(id: string): ProceduralMemory[];
|
|
101
|
+
/**
|
|
102
|
+
* Check if all prerequisites are met for a skill
|
|
103
|
+
*/
|
|
104
|
+
canExecute(id: string, minSuccessRate?: number): boolean;
|
|
105
|
+
getAll(): ProceduralMemory[];
|
|
106
|
+
clear(): void;
|
|
107
|
+
count(): number;
|
|
108
|
+
stats(): StoreStats;
|
|
109
|
+
/**
|
|
110
|
+
* Get additional procedural-specific stats
|
|
111
|
+
*/
|
|
112
|
+
proceduralStats(): {
|
|
113
|
+
totalSkills: number;
|
|
114
|
+
mastered: number;
|
|
115
|
+
needsPractice: number;
|
|
116
|
+
avgSuccessRate: number;
|
|
117
|
+
avgExecutions: number;
|
|
118
|
+
mostUsed: ProceduralMemory[];
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Get skills that should be forgotten (low retention AND low success)
|
|
122
|
+
*/
|
|
123
|
+
getForgotten(): ProceduralMemory[];
|
|
124
|
+
/**
|
|
125
|
+
* Run forgetting cycle
|
|
126
|
+
*/
|
|
127
|
+
runForgetting(): {
|
|
128
|
+
forgotten: number;
|
|
129
|
+
ids: string[];
|
|
130
|
+
};
|
|
131
|
+
private accessMemory;
|
|
132
|
+
private updateIndexes;
|
|
133
|
+
private removeFromIndexes;
|
|
134
|
+
private maintainSize;
|
|
135
|
+
}
|
|
136
|
+
export declare function createProceduralStore(config?: Partial<ProceduralStoreConfig>): ProceduralStore;
|