codehere 0.2.1 → 0.3.0-rc.1
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/README.md +88 -68
- package/dist/domain/entities/task.js +4 -4
- package/dist/error-handler.js +4 -9
- package/dist/index.js +253 -1219
- package/dist/infrastructure/config/product-context.js +7 -6
- package/dist/infrastructure/hooks/claude-sdk-hook.js +335 -63
- package/dist/infrastructure/observability/execution-tracer.js +11 -6
- package/dist/infrastructure/orchestration/agent-adapter.js +13 -0
- package/dist/infrastructure/orchestration/agent-installer.js +101 -0
- package/dist/infrastructure/orchestration/agents-config-seed.js +56 -0
- package/dist/infrastructure/orchestration/aider-adapter.js +319 -0
- package/dist/infrastructure/orchestration/artifacts-extractor.js +175 -0
- package/dist/infrastructure/orchestration/claude-code-adapter.js +352 -0
- package/dist/infrastructure/orchestration/codex-adapter.js +310 -0
- package/dist/infrastructure/orchestration/generic-cli-adapter.js +553 -0
- package/dist/infrastructure/orchestration/opencode-adapter.js +275 -0
- package/dist/infrastructure/orchestration/progress-aggregator.js +189 -0
- package/dist/infrastructure/orchestration/readiness.js +106 -0
- package/dist/infrastructure/orchestration/session-manager.js +272 -0
- package/dist/infrastructure/orchestration/session-persistence.js +109 -0
- package/dist/infrastructure/protocols/mcp-helpers.js +10 -30
- package/dist/infrastructure/protocols/mcp-server-impl.js +359 -21
- package/dist/infrastructure/protocols/ui-page.js +1827 -0
- package/dist/infrastructure/security/file-collection.js +115 -0
- package/dist/infrastructure/security/trust-scorer.js +301 -56
- package/dist/infrastructure/storage/task-repository.js +8 -7
- package/dist/monitoring.js +10 -49
- package/dist/presentation/cli/commands/help-command.js +96 -139
- package/dist/presentation/cli/commands/hook-command.js +17 -24
- package/dist/presentation/cli/commands/report-command.js +59 -72
- package/dist/presentation/cli/commands/setup-command.js +4 -4
- package/dist/presentation/cli/commands/status-command.js +334 -43
- package/dist/presentation/cli/commands/trust-command.js +115 -99
- package/dist/presentation/cli/error-display.js +17 -21
- package/dist/ui.js +17 -12
- package/package.json +35 -67
- package/dist/agents/base.js +0 -101
- package/dist/agents/orchestrator-model-driven.js +0 -141
- package/dist/agents/react-orchestrator-agent.js +0 -54
- package/dist/application/agents/execution-agent.js +0 -508
- package/dist/application/agents/multi-agent-orchestrator.js +0 -295
- package/dist/application/agents/planning-agent.js +0 -433
- package/dist/application/agents/validation-agent.js +0 -317
- package/dist/application/architectures/plan-and-act.js +0 -242
- package/dist/application/index.js +0 -12
- package/dist/application/services/agent-factory.js +0 -28
- package/dist/application/services/dependency-container.js +0 -596
- package/dist/application/services/git-context-service.js +0 -83
- package/dist/application/services/intelligent-router.js +0 -934
- package/dist/application/services/tool-executor-service.js +0 -94
- package/dist/application/use-cases/ask-question-use-case.js +0 -338
- package/dist/application/use-cases/edit-file-use-case.js +0 -830
- package/dist/application/use-cases/explain-file-use-case.js +0 -50
- package/dist/application/use-cases/index-codebase-use-case.js +0 -113
- package/dist/application/use-cases/planning-use-case.js +0 -276
- package/dist/application/use-cases/react-orchestration-use-case.js +0 -329
- package/dist/application/use-cases/reflexion-use-case.js +0 -30
- package/dist/application/workflows/deterministic-workflows.js +0 -189
- package/dist/ast-parser.js +0 -331
- package/dist/cache.js +0 -180
- package/dist/chat.js +0 -251
- package/dist/code-analysis.js +0 -327
- package/dist/context.js +0 -187
- package/dist/docs.js +0 -146
- package/dist/domain/entities/code-chunk.js +0 -6
- package/dist/domain/entities/decision.js +0 -9
- package/dist/domain/entities/edit.js +0 -6
- package/dist/domain/entities/knowledge-node.js +0 -9
- package/dist/domain/entities/knowledge-preservation.js +0 -10
- package/dist/domain/entities/memory.js +0 -6
- package/dist/domain/entities/pattern.js +0 -7
- package/dist/domain/entities/plan.js +0 -6
- package/dist/domain/entities/query.js +0 -6
- package/dist/domain/errors/embeddings-not-found-error.js +0 -13
- package/dist/domain/index.js +0 -19
- package/dist/domain/interfaces/ai-service.interface.js +0 -6
- package/dist/domain/interfaces/code-analyzer.interface.js +0 -6
- package/dist/domain/interfaces/decision-repository.interface.js +0 -9
- package/dist/domain/interfaces/embedding-repository.interface.js +0 -6
- package/dist/domain/interfaces/knowledge-graph-repository.interface.js +0 -9
- package/dist/domain/interfaces/knowledge-preservation-repository.interface.js +0 -8
- package/dist/domain/interfaces/memory-repository.interface.js +0 -6
- package/dist/domain/interfaces/pattern-repository.interface.js +0 -6
- package/dist/domain/interfaces/verification-service.interface.js +0 -6
- package/dist/domain/services/cross-team-pattern-sharing.js +0 -125
- package/dist/domain/services/decision-recorder.js +0 -223
- package/dist/domain/services/decision-retriever.js +0 -133
- package/dist/domain/services/environment-mode-manager.js +0 -22
- package/dist/domain/services/graded-memory-activation.js +0 -69
- package/dist/domain/services/knowledge-access.js +0 -132
- package/dist/domain/services/knowledge-extractor.js +0 -247
- package/dist/domain/services/knowledge-graph-builder.js +0 -268
- package/dist/domain/services/knowledge-graph-query.js +0 -187
- package/dist/domain/services/memory-retriever.js +0 -82
- package/dist/domain/services/memory-synthesizer.js +0 -91
- package/dist/domain/services/pattern-extractor.js +0 -442
- package/dist/domain/services/query-intent-classifier.js +0 -140
- package/dist/domain/services/react-loop.js +0 -186
- package/dist/domain/services/risk-tier-detector.js +0 -78
- package/dist/edit.js +0 -319
- package/dist/embed.js +0 -459
- package/dist/formatter.js +0 -168
- package/dist/git.js +0 -198
- package/dist/infrastructure/ai/cohere-ai-service.js +0 -607
- package/dist/infrastructure/ai/command-r-evaluation.js +0 -206
- package/dist/infrastructure/ai/model-config.js +0 -84
- package/dist/infrastructure/ai/provider-ai-service.js +0 -477
- package/dist/infrastructure/cache/embedding-cache.js +0 -175
- package/dist/infrastructure/cache/query-result-cache.js +0 -66
- package/dist/infrastructure/cache/response-cache.js +0 -48
- package/dist/infrastructure/cache/security-scan-cache.js +0 -47
- package/dist/infrastructure/chunking/ast-code-chunker.js +0 -19
- package/dist/infrastructure/chunking/code-aware-chunker.js +0 -397
- package/dist/infrastructure/context/context-compressor.js +0 -329
- package/dist/infrastructure/context/conversation-context.js +0 -128
- package/dist/infrastructure/context/session-manager.js +0 -94
- package/dist/infrastructure/cost/cost-tracker.js +0 -360
- package/dist/infrastructure/file-scanner/file-scanner.js +0 -106
- package/dist/infrastructure/governance/nist-ai-rmf.js +0 -292
- package/dist/infrastructure/governance/policy-as-code.js +0 -258
- package/dist/infrastructure/governance/prompt-to-code-lineage.js +0 -239
- package/dist/infrastructure/index.js +0 -7
- package/dist/infrastructure/observability/prompt-versioner.js +0 -145
- package/dist/infrastructure/protocols/a2a-metadata.js +0 -137
- package/dist/infrastructure/protocols/a2a-protocol.js +0 -314
- package/dist/infrastructure/protocols/mcp-oauth.js +0 -184
- package/dist/infrastructure/protocols/mcp-server.js +0 -333
- package/dist/infrastructure/protocols/streaming-handler.js +0 -103
- package/dist/infrastructure/providers/cohere-provider.js +0 -444
- package/dist/infrastructure/providers/fake-provider.js +0 -130
- package/dist/infrastructure/providers/local-llm-provider.js +0 -330
- package/dist/infrastructure/providers/model-config.types.js +0 -9
- package/dist/infrastructure/providers/model-provider.interface.js +0 -8
- package/dist/infrastructure/providers/openai-provider.js +0 -413
- package/dist/infrastructure/providers/openrouter-provider.js +0 -399
- package/dist/infrastructure/providers/operation-provider-resolver.js +0 -105
- package/dist/infrastructure/providers/provider-config-loader.js +0 -120
- package/dist/infrastructure/providers/provider-registry.js +0 -88
- package/dist/infrastructure/safety/pattern-detector.js +0 -133
- package/dist/infrastructure/security/ai-sast-scanner.js +0 -290
- package/dist/infrastructure/security/docker-sandbox.js +0 -178
- package/dist/infrastructure/security/enhanced-security-gate.js +0 -151
- package/dist/infrastructure/security/license-scanner.js +0 -167
- package/dist/infrastructure/security/provider-bias-detector.js +0 -164
- package/dist/infrastructure/security/sandbox-executor.js +0 -64
- package/dist/infrastructure/serialization/toon-serializer.js +0 -119
- package/dist/infrastructure/storage/memory-stream-service.js +0 -204
- package/dist/infrastructure/storage/plan-repository.js +0 -96
- package/dist/infrastructure/storage/sqlite-decision-repository.js +0 -232
- package/dist/infrastructure/storage/sqlite-embedding-repository.js +0 -311
- package/dist/infrastructure/storage/sqlite-knowledge-graph-repository.js +0 -417
- package/dist/infrastructure/storage/sqlite-knowledge-preservation-repository.js +0 -230
- package/dist/infrastructure/storage/sqlite-memory-repository.js +0 -229
- package/dist/infrastructure/storage/sqlite-pattern-repository.js +0 -249
- package/dist/infrastructure/storage/task-helpers.js +0 -197
- package/dist/infrastructure/telemetry/telemetry-service.js +0 -167
- package/dist/infrastructure/ux/appropriate-friction.js +0 -213
- package/dist/infrastructure/ux/bi-directional-learning.js +0 -337
- package/dist/infrastructure/ux/capability-boundaries.js +0 -42
- package/dist/infrastructure/ux/comprehensive-formatter.js +0 -117
- package/dist/infrastructure/ux/contextual-feature-discovery.js +0 -10
- package/dist/infrastructure/ux/expectation-management.js +0 -327
- package/dist/infrastructure/ux/feature-discovery.js +0 -14
- package/dist/infrastructure/ux/feedback-prompt.js +0 -45
- package/dist/infrastructure/ux/hitl-validation.js +0 -297
- package/dist/infrastructure/ux/progress-indicator.js +0 -116
- package/dist/infrastructure/ux/progressive-disclosure.js +0 -236
- package/dist/infrastructure/ux/review-checkpoint.js +0 -72
- package/dist/infrastructure/ux/staged-feature-intro.js +0 -24
- package/dist/infrastructure/ux/stream-markdown.js +0 -151
- package/dist/infrastructure/ux/syntax-highlighter.js +0 -91
- package/dist/infrastructure/ux/team-standards.js +0 -196
- package/dist/infrastructure/ux/transparency.js +0 -71
- package/dist/infrastructure/validation/agent-feedback.js +0 -55
- package/dist/infrastructure/validation/agent-validation-helper.js +0 -137
- package/dist/infrastructure/validation/review-handler.js +0 -40
- package/dist/infrastructure/validation/summary-aggregator.js +0 -70
- package/dist/infrastructure/validation/summary-extractor.js +0 -45
- package/dist/infrastructure/validation/trace-summary.js +0 -52
- package/dist/infrastructure/verification/verification-service.js +0 -47
- package/dist/infrastructure/xai/attention-visualizer.js +0 -172
- package/dist/infrastructure/xai/cot-visualizer.js +0 -283
- package/dist/infrastructure/xai/decision-tree-log.js +0 -212
- package/dist/infrastructure/xai/interactive-xai.js +0 -260
- package/dist/infrastructure/xai/uncertainty-quantifier.js +0 -198
- package/dist/intelligent-retrieval.js +0 -272
- package/dist/intent/classifier.js +0 -2
- package/dist/intent/context.js +0 -2
- package/dist/iterative-refinement.js +0 -189
- package/dist/learning.js +0 -232
- package/dist/log.js +0 -31
- package/dist/migrate.js +0 -133
- package/dist/parallel-processor.js +0 -530
- package/dist/planner.js +0 -198
- package/dist/policy.js +0 -26
- package/dist/presentation/cli/commands/ask-command.js +0 -314
- package/dist/presentation/cli/commands/cost-command.js +0 -191
- package/dist/presentation/cli/commands/decision-command.js +0 -207
- package/dist/presentation/cli/commands/docs-command.js +0 -25
- package/dist/presentation/cli/commands/fix-command.js +0 -53
- package/dist/presentation/cli/commands/knowledge-command.js +0 -129
- package/dist/presentation/cli/commands/learning-dashboard-command.js +0 -183
- package/dist/presentation/cli/commands/models-command.js +0 -194
- package/dist/presentation/cli/commands/orchestrate-command.js +0 -207
- package/dist/presentation/cli/commands/plan-command.js +0 -246
- package/dist/presentation/cli/commands/product-command.js +0 -199
- package/dist/presentation/cli/commands/react-command.js +0 -181
- package/dist/presentation/cli/commands/review-command.js +0 -154
- package/dist/presentation/cli/commands/run-command.js +0 -188
- package/dist/presentation/cli/commands/smart-command.js +0 -395
- package/dist/presentation/cli/commands/suggest-command.js +0 -138
- package/dist/presentation/cli/commands/trace-command.js +0 -129
- package/dist/presentation/cli/commands/undo-command.js +0 -150
- package/dist/query-optimizer.js +0 -205
- package/dist/refactor.js +0 -116
- package/dist/review.js +0 -206
- package/dist/search.js +0 -163
- package/dist/session.js +0 -652
- package/dist/task-verification.js +0 -336
- package/dist/testgen.js +0 -166
- package/dist/token-optimizer.js +0 -277
- package/dist/tools/bash.js +0 -213
- package/dist/tools/edit.js +0 -235
- package/dist/tools/executor.js +0 -153
- package/dist/tools/git-tool.js +0 -292
- package/dist/tools/parser.js +0 -158
- package/dist/tools/registry.js +0 -302
- package/dist/tools/search.js +0 -100
- package/dist/types.js +0 -2
- package/dist/utils/check-api-status.js +0 -100
- package/dist/utils/diff-parser.js +0 -162
- package/dist/verification/backup.js +0 -259
- package/dist/verification/compiler.js +0 -264
- package/dist/verification/index.js +0 -273
- package/dist/verification/test-runner.js +0 -379
|
@@ -1,417 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Infrastructure: SQLiteKnowledgeGraphRepository
|
|
3
|
-
* SQLite implementation of knowledge graph storage
|
|
4
|
-
*
|
|
5
|
-
* Clean Architecture: Infrastructure Layer
|
|
6
|
-
* Pattern: Repository Pattern Implementation
|
|
7
|
-
*/
|
|
8
|
-
import { readFileSync, existsSync, mkdirSync, writeFileSync } from 'fs';
|
|
9
|
-
import { join, dirname } from 'path';
|
|
10
|
-
import { fileURLToPath } from 'url';
|
|
11
|
-
import initSqlJs from 'sql.js';
|
|
12
|
-
import { randomUUID } from 'crypto';
|
|
13
|
-
function getDbPath() {
|
|
14
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
15
|
-
const __dirname = dirname(__filename);
|
|
16
|
-
const agentDir = join(__dirname, '../../..');
|
|
17
|
-
if (existsSync(join(agentDir, 'package.json'))) {
|
|
18
|
-
return join(agentDir, 'data', 'knowledge-graph.sqlite');
|
|
19
|
-
}
|
|
20
|
-
return join(process.cwd(), 'agent', 'data', 'knowledge-graph.sqlite');
|
|
21
|
-
}
|
|
22
|
-
export class SQLiteKnowledgeGraphRepository {
|
|
23
|
-
dbPath;
|
|
24
|
-
db = null;
|
|
25
|
-
constructor() {
|
|
26
|
-
this.dbPath = getDbPath();
|
|
27
|
-
}
|
|
28
|
-
async getDb() {
|
|
29
|
-
if (this.db)
|
|
30
|
-
return this.db;
|
|
31
|
-
const SQL = await initSqlJs();
|
|
32
|
-
const dbDir = dirname(this.dbPath);
|
|
33
|
-
if (!existsSync(dbDir)) {
|
|
34
|
-
mkdirSync(dbDir, { recursive: true });
|
|
35
|
-
}
|
|
36
|
-
if (existsSync(this.dbPath)) {
|
|
37
|
-
const buffer = readFileSync(this.dbPath);
|
|
38
|
-
this.db = new SQL.Database(buffer);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
this.db = new SQL.Database();
|
|
42
|
-
}
|
|
43
|
-
// Create nodes table
|
|
44
|
-
this.db.run(`
|
|
45
|
-
CREATE TABLE IF NOT EXISTS knowledge_nodes (
|
|
46
|
-
id TEXT PRIMARY KEY,
|
|
47
|
-
codebaseId TEXT NOT NULL,
|
|
48
|
-
type TEXT NOT NULL,
|
|
49
|
-
label TEXT NOT NULL,
|
|
50
|
-
content TEXT NOT NULL,
|
|
51
|
-
metadata TEXT,
|
|
52
|
-
createdAt INTEGER NOT NULL,
|
|
53
|
-
lastUpdated INTEGER NOT NULL
|
|
54
|
-
)
|
|
55
|
-
`);
|
|
56
|
-
// Create edges table
|
|
57
|
-
this.db.run(`
|
|
58
|
-
CREATE TABLE IF NOT EXISTS knowledge_edges (
|
|
59
|
-
id TEXT PRIMARY KEY,
|
|
60
|
-
fromNodeId TEXT NOT NULL,
|
|
61
|
-
toNodeId TEXT NOT NULL,
|
|
62
|
-
type TEXT NOT NULL,
|
|
63
|
-
weight REAL,
|
|
64
|
-
metadata TEXT,
|
|
65
|
-
createdAt INTEGER NOT NULL,
|
|
66
|
-
FOREIGN KEY (fromNodeId) REFERENCES knowledge_nodes(id),
|
|
67
|
-
FOREIGN KEY (toNodeId) REFERENCES knowledge_nodes(id)
|
|
68
|
-
)
|
|
69
|
-
`);
|
|
70
|
-
// Create indexes
|
|
71
|
-
this.db.run(`CREATE INDEX IF NOT EXISTS idx_codebase ON knowledge_nodes(codebaseId)`);
|
|
72
|
-
this.db.run(`CREATE INDEX IF NOT EXISTS idx_type ON knowledge_nodes(codebaseId, type)`);
|
|
73
|
-
this.db.run(`CREATE INDEX IF NOT EXISTS idx_from_node ON knowledge_edges(fromNodeId)`);
|
|
74
|
-
this.db.run(`CREATE INDEX IF NOT EXISTS idx_to_node ON knowledge_edges(toNodeId)`);
|
|
75
|
-
this.db.run(`CREATE INDEX IF NOT EXISTS idx_edge_type ON knowledge_edges(type)`);
|
|
76
|
-
this.db.run(`CREATE INDEX IF NOT EXISTS idx_edge_codebase ON knowledge_edges(fromNodeId, toNodeId)`);
|
|
77
|
-
return this.db;
|
|
78
|
-
}
|
|
79
|
-
async storeNode(node) {
|
|
80
|
-
const db = await this.getDb();
|
|
81
|
-
const id = node.id || randomUUID();
|
|
82
|
-
const stmt = db.prepare(`
|
|
83
|
-
INSERT OR REPLACE INTO knowledge_nodes
|
|
84
|
-
(id, codebaseId, type, label, content, metadata, createdAt, lastUpdated)
|
|
85
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
86
|
-
`);
|
|
87
|
-
stmt.run([
|
|
88
|
-
id,
|
|
89
|
-
node.codebaseId,
|
|
90
|
-
node.type,
|
|
91
|
-
node.label,
|
|
92
|
-
node.content,
|
|
93
|
-
JSON.stringify(node.metadata ?? {}),
|
|
94
|
-
node.createdAt.getTime(),
|
|
95
|
-
node.lastUpdated.getTime(),
|
|
96
|
-
]);
|
|
97
|
-
stmt.free();
|
|
98
|
-
this.saveDb();
|
|
99
|
-
}
|
|
100
|
-
async getNodeById(id) {
|
|
101
|
-
const db = await this.getDb();
|
|
102
|
-
const stmt = db.prepare('SELECT * FROM knowledge_nodes WHERE id = ?');
|
|
103
|
-
stmt.bind([id]);
|
|
104
|
-
if (!stmt.step()) {
|
|
105
|
-
stmt.free();
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
|
-
const row = stmt.getAsObject();
|
|
109
|
-
stmt.free();
|
|
110
|
-
return this.mapRowToNode(row);
|
|
111
|
-
}
|
|
112
|
-
async findNodesByCodebase(codebaseId, limit = 100) {
|
|
113
|
-
const db = await this.getDb();
|
|
114
|
-
const stmt = db.prepare(`
|
|
115
|
-
SELECT * FROM knowledge_nodes
|
|
116
|
-
WHERE codebaseId = ?
|
|
117
|
-
ORDER BY lastUpdated DESC
|
|
118
|
-
LIMIT ?
|
|
119
|
-
`);
|
|
120
|
-
stmt.bind([codebaseId, limit]);
|
|
121
|
-
return this.executeAndMapNodes(stmt);
|
|
122
|
-
}
|
|
123
|
-
async findNodesByType(codebaseId, type, limit = 100) {
|
|
124
|
-
const db = await this.getDb();
|
|
125
|
-
const stmt = db.prepare(`
|
|
126
|
-
SELECT * FROM knowledge_nodes
|
|
127
|
-
WHERE codebaseId = ? AND type = ?
|
|
128
|
-
ORDER BY lastUpdated DESC
|
|
129
|
-
LIMIT ?
|
|
130
|
-
`);
|
|
131
|
-
stmt.bind([codebaseId, type, limit]);
|
|
132
|
-
return this.executeAndMapNodes(stmt);
|
|
133
|
-
}
|
|
134
|
-
async searchNodes(codebaseId, query, limit = 50) {
|
|
135
|
-
const db = await this.getDb();
|
|
136
|
-
const searchTerm = `%${query}%`;
|
|
137
|
-
const stmt = db.prepare(`
|
|
138
|
-
SELECT * FROM knowledge_nodes
|
|
139
|
-
WHERE codebaseId = ?
|
|
140
|
-
AND (label LIKE ? OR content LIKE ?)
|
|
141
|
-
ORDER BY lastUpdated DESC
|
|
142
|
-
LIMIT ?
|
|
143
|
-
`);
|
|
144
|
-
stmt.bind([codebaseId, searchTerm, searchTerm, limit]);
|
|
145
|
-
return this.executeAndMapNodes(stmt);
|
|
146
|
-
}
|
|
147
|
-
async updateNode(node) {
|
|
148
|
-
if (!node.id) {
|
|
149
|
-
throw new Error('Node ID required for update');
|
|
150
|
-
}
|
|
151
|
-
await this.storeNode(node); // INSERT OR REPLACE handles update
|
|
152
|
-
}
|
|
153
|
-
async deleteNode(id) {
|
|
154
|
-
const db = await this.getDb();
|
|
155
|
-
// Delete edges first (foreign key constraints)
|
|
156
|
-
const deleteEdgesStmt = db.prepare(`
|
|
157
|
-
DELETE FROM knowledge_edges
|
|
158
|
-
WHERE fromNodeId = ? OR toNodeId = ?
|
|
159
|
-
`);
|
|
160
|
-
deleteEdgesStmt.run([id, id]);
|
|
161
|
-
deleteEdgesStmt.free();
|
|
162
|
-
// Delete node
|
|
163
|
-
const deleteNodeStmt = db.prepare('DELETE FROM knowledge_nodes WHERE id = ?');
|
|
164
|
-
deleteNodeStmt.run([id]);
|
|
165
|
-
deleteNodeStmt.free();
|
|
166
|
-
this.saveDb();
|
|
167
|
-
}
|
|
168
|
-
async storeEdge(edge) {
|
|
169
|
-
const db = await this.getDb();
|
|
170
|
-
const id = edge.id || randomUUID();
|
|
171
|
-
const stmt = db.prepare(`
|
|
172
|
-
INSERT OR REPLACE INTO knowledge_edges
|
|
173
|
-
(id, fromNodeId, toNodeId, type, weight, metadata, createdAt)
|
|
174
|
-
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
175
|
-
`);
|
|
176
|
-
stmt.run([
|
|
177
|
-
id,
|
|
178
|
-
edge.fromNodeId,
|
|
179
|
-
edge.toNodeId,
|
|
180
|
-
edge.type,
|
|
181
|
-
edge.weight ?? null,
|
|
182
|
-
JSON.stringify(edge.metadata ?? {}),
|
|
183
|
-
edge.createdAt.getTime(),
|
|
184
|
-
]);
|
|
185
|
-
stmt.free();
|
|
186
|
-
this.saveDb();
|
|
187
|
-
}
|
|
188
|
-
async getEdgeById(id) {
|
|
189
|
-
const db = await this.getDb();
|
|
190
|
-
const stmt = db.prepare('SELECT * FROM knowledge_edges WHERE id = ?');
|
|
191
|
-
stmt.bind([id]);
|
|
192
|
-
if (!stmt.step()) {
|
|
193
|
-
stmt.free();
|
|
194
|
-
return null;
|
|
195
|
-
}
|
|
196
|
-
const row = stmt.getAsObject();
|
|
197
|
-
stmt.free();
|
|
198
|
-
return this.mapRowToEdge(row);
|
|
199
|
-
}
|
|
200
|
-
async findEdgesByCodebase(codebaseId, limit = 1000) {
|
|
201
|
-
const db = await this.getDb();
|
|
202
|
-
const stmt = db.prepare(`
|
|
203
|
-
SELECT e.* FROM knowledge_edges e
|
|
204
|
-
INNER JOIN knowledge_nodes n1 ON e.fromNodeId = n1.id
|
|
205
|
-
WHERE n1.codebaseId = ?
|
|
206
|
-
ORDER BY e.createdAt DESC
|
|
207
|
-
LIMIT ?
|
|
208
|
-
`);
|
|
209
|
-
stmt.bind([codebaseId, limit]);
|
|
210
|
-
return this.executeAndMapEdges(stmt);
|
|
211
|
-
}
|
|
212
|
-
async findEdgesByType(codebaseId, type, limit = 100) {
|
|
213
|
-
const db = await this.getDb();
|
|
214
|
-
const stmt = db.prepare(`
|
|
215
|
-
SELECT e.* FROM knowledge_edges e
|
|
216
|
-
INNER JOIN knowledge_nodes n1 ON e.fromNodeId = n1.id
|
|
217
|
-
WHERE n1.codebaseId = ? AND e.type = ?
|
|
218
|
-
ORDER BY e.createdAt DESC
|
|
219
|
-
LIMIT ?
|
|
220
|
-
`);
|
|
221
|
-
stmt.bind([codebaseId, type, limit]);
|
|
222
|
-
return this.executeAndMapEdges(stmt);
|
|
223
|
-
}
|
|
224
|
-
async findEdgesFromNode(nodeId, limit = 100) {
|
|
225
|
-
const db = await this.getDb();
|
|
226
|
-
const stmt = db.prepare(`
|
|
227
|
-
SELECT * FROM knowledge_edges
|
|
228
|
-
WHERE fromNodeId = ?
|
|
229
|
-
ORDER BY createdAt DESC
|
|
230
|
-
LIMIT ?
|
|
231
|
-
`);
|
|
232
|
-
stmt.bind([nodeId, limit]);
|
|
233
|
-
return this.executeAndMapEdges(stmt);
|
|
234
|
-
}
|
|
235
|
-
async findEdgesToNode(nodeId, limit = 100) {
|
|
236
|
-
const db = await this.getDb();
|
|
237
|
-
const stmt = db.prepare(`
|
|
238
|
-
SELECT * FROM knowledge_edges
|
|
239
|
-
WHERE toNodeId = ?
|
|
240
|
-
ORDER BY createdAt DESC
|
|
241
|
-
LIMIT ?
|
|
242
|
-
`);
|
|
243
|
-
stmt.bind([nodeId, limit]);
|
|
244
|
-
return this.executeAndMapEdges(stmt);
|
|
245
|
-
}
|
|
246
|
-
async findEdgesBetween(fromNodeId, toNodeId) {
|
|
247
|
-
const db = await this.getDb();
|
|
248
|
-
const stmt = db.prepare(`
|
|
249
|
-
SELECT * FROM knowledge_edges
|
|
250
|
-
WHERE fromNodeId = ? AND toNodeId = ?
|
|
251
|
-
`);
|
|
252
|
-
stmt.bind([fromNodeId, toNodeId]);
|
|
253
|
-
return this.executeAndMapEdges(stmt);
|
|
254
|
-
}
|
|
255
|
-
async updateEdge(edge) {
|
|
256
|
-
if (!edge.id) {
|
|
257
|
-
throw new Error('Edge ID required for update');
|
|
258
|
-
}
|
|
259
|
-
await this.storeEdge(edge); // INSERT OR REPLACE handles update
|
|
260
|
-
}
|
|
261
|
-
async deleteEdge(id) {
|
|
262
|
-
const db = await this.getDb();
|
|
263
|
-
const stmt = db.prepare('DELETE FROM knowledge_edges WHERE id = ?');
|
|
264
|
-
stmt.run([id]);
|
|
265
|
-
stmt.free();
|
|
266
|
-
this.saveDb();
|
|
267
|
-
}
|
|
268
|
-
async getGraphByCodebase(codebaseId) {
|
|
269
|
-
const nodes = await this.findNodesByCodebase(codebaseId);
|
|
270
|
-
const edges = await this.findEdgesByCodebase(codebaseId);
|
|
271
|
-
// Calculate metadata
|
|
272
|
-
const nodeTypes = {};
|
|
273
|
-
const relationshipTypes = {};
|
|
274
|
-
for (const node of nodes) {
|
|
275
|
-
nodeTypes[node.type] = (nodeTypes[node.type] || 0) + 1;
|
|
276
|
-
}
|
|
277
|
-
for (const edge of edges) {
|
|
278
|
-
relationshipTypes[edge.type] = (relationshipTypes[edge.type] || 0) + 1;
|
|
279
|
-
}
|
|
280
|
-
const metadata = {
|
|
281
|
-
nodeCount: nodes.length,
|
|
282
|
-
edgeCount: edges.length,
|
|
283
|
-
nodeTypes,
|
|
284
|
-
relationshipTypes,
|
|
285
|
-
};
|
|
286
|
-
return {
|
|
287
|
-
codebaseId,
|
|
288
|
-
nodes,
|
|
289
|
-
edges,
|
|
290
|
-
metadata,
|
|
291
|
-
createdAt: nodes.length > 0 ? nodes[0].createdAt : new Date(),
|
|
292
|
-
lastUpdated: nodes.length > 0 ? nodes[nodes.length - 1].lastUpdated : new Date(),
|
|
293
|
-
};
|
|
294
|
-
}
|
|
295
|
-
async getNeighbors(nodeId, direction = 'both') {
|
|
296
|
-
const db = await this.getDb();
|
|
297
|
-
const nodeIds = new Set();
|
|
298
|
-
if (direction === 'out' || direction === 'both') {
|
|
299
|
-
const outEdges = await this.findEdgesFromNode(nodeId);
|
|
300
|
-
outEdges.forEach(edge => nodeIds.add(edge.toNodeId));
|
|
301
|
-
}
|
|
302
|
-
if (direction === 'in' || direction === 'both') {
|
|
303
|
-
const inEdges = await this.findEdgesToNode(nodeId);
|
|
304
|
-
inEdges.forEach(edge => nodeIds.add(edge.fromNodeId));
|
|
305
|
-
}
|
|
306
|
-
const neighbors = [];
|
|
307
|
-
for (const id of nodeIds) {
|
|
308
|
-
const node = await this.getNodeById(id);
|
|
309
|
-
if (node) {
|
|
310
|
-
neighbors.push(node);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
return neighbors;
|
|
314
|
-
}
|
|
315
|
-
async getNodesWithinHops(nodeId, maxHops) {
|
|
316
|
-
const visited = new Set();
|
|
317
|
-
const result = [];
|
|
318
|
-
const queue = [{ nodeId, hops: 0 }];
|
|
319
|
-
while (queue.length > 0) {
|
|
320
|
-
const { nodeId: currentId, hops } = queue.shift();
|
|
321
|
-
if (visited.has(currentId) || hops > maxHops) {
|
|
322
|
-
continue;
|
|
323
|
-
}
|
|
324
|
-
visited.add(currentId);
|
|
325
|
-
const node = await this.getNodeById(currentId);
|
|
326
|
-
if (node) {
|
|
327
|
-
result.push(node);
|
|
328
|
-
}
|
|
329
|
-
if (hops < maxHops) {
|
|
330
|
-
const neighbors = await this.getNeighbors(currentId);
|
|
331
|
-
for (const neighbor of neighbors) {
|
|
332
|
-
if (neighbor.id && !visited.has(neighbor.id)) {
|
|
333
|
-
queue.push({ nodeId: neighbor.id, hops: hops + 1 });
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
return result;
|
|
339
|
-
}
|
|
340
|
-
async findShortestPath(fromNodeId, toNodeId) {
|
|
341
|
-
// BFS to find shortest path
|
|
342
|
-
const visited = new Set();
|
|
343
|
-
const queue = [{ nodeId: fromNodeId, path: [fromNodeId] }];
|
|
344
|
-
while (queue.length > 0) {
|
|
345
|
-
const { nodeId: currentId, path } = queue.shift();
|
|
346
|
-
if (visited.has(currentId)) {
|
|
347
|
-
continue;
|
|
348
|
-
}
|
|
349
|
-
visited.add(currentId);
|
|
350
|
-
if (currentId === toNodeId) {
|
|
351
|
-
// Found path, return nodes
|
|
352
|
-
const nodes = [];
|
|
353
|
-
for (const id of path) {
|
|
354
|
-
const node = await this.getNodeById(id);
|
|
355
|
-
if (node) {
|
|
356
|
-
nodes.push(node);
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
return nodes;
|
|
360
|
-
}
|
|
361
|
-
const neighbors = await this.getNeighbors(currentId, 'out');
|
|
362
|
-
for (const neighbor of neighbors) {
|
|
363
|
-
if (neighbor.id && !visited.has(neighbor.id)) {
|
|
364
|
-
queue.push({ nodeId: neighbor.id, path: [...path, neighbor.id] });
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
return null; // No path found
|
|
369
|
-
}
|
|
370
|
-
mapRowToNode(row) {
|
|
371
|
-
return {
|
|
372
|
-
id: row.id,
|
|
373
|
-
codebaseId: row.codebaseId,
|
|
374
|
-
type: row.type,
|
|
375
|
-
label: row.label,
|
|
376
|
-
content: row.content,
|
|
377
|
-
metadata: JSON.parse(row.metadata ?? '{}'),
|
|
378
|
-
createdAt: new Date(row.createdAt),
|
|
379
|
-
lastUpdated: new Date(row.lastUpdated),
|
|
380
|
-
};
|
|
381
|
-
}
|
|
382
|
-
mapRowToEdge(row) {
|
|
383
|
-
return {
|
|
384
|
-
id: row.id,
|
|
385
|
-
fromNodeId: row.fromNodeId,
|
|
386
|
-
toNodeId: row.toNodeId,
|
|
387
|
-
type: row.type,
|
|
388
|
-
weight: row.weight ?? undefined,
|
|
389
|
-
metadata: JSON.parse(row.metadata ?? '{}'),
|
|
390
|
-
createdAt: new Date(row.createdAt),
|
|
391
|
-
};
|
|
392
|
-
}
|
|
393
|
-
executeAndMapNodes(stmt) {
|
|
394
|
-
const nodes = [];
|
|
395
|
-
while (stmt.step()) {
|
|
396
|
-
nodes.push(this.mapRowToNode(stmt.getAsObject()));
|
|
397
|
-
}
|
|
398
|
-
stmt.free();
|
|
399
|
-
return nodes;
|
|
400
|
-
}
|
|
401
|
-
executeAndMapEdges(stmt) {
|
|
402
|
-
const edges = [];
|
|
403
|
-
while (stmt.step()) {
|
|
404
|
-
edges.push(this.mapRowToEdge(stmt.getAsObject()));
|
|
405
|
-
}
|
|
406
|
-
stmt.free();
|
|
407
|
-
return edges;
|
|
408
|
-
}
|
|
409
|
-
saveDb() {
|
|
410
|
-
if (!this.db)
|
|
411
|
-
return;
|
|
412
|
-
const data = this.db.export();
|
|
413
|
-
const buffer = Buffer.from(data);
|
|
414
|
-
writeFileSync(this.dbPath, buffer);
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
//# sourceMappingURL=sqlite-knowledge-graph-repository.js.map
|
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Infrastructure: SQLiteKnowledgePreservationRepository
|
|
3
|
-
* SQLite implementation of knowledge preservation storage
|
|
4
|
-
*
|
|
5
|
-
* Clean Architecture: Infrastructure Layer
|
|
6
|
-
* Pattern: Repository Pattern Implementation
|
|
7
|
-
*/
|
|
8
|
-
import { readFileSync, existsSync, mkdirSync, writeFileSync } from 'fs';
|
|
9
|
-
import { join, dirname } from 'path';
|
|
10
|
-
import { fileURLToPath } from 'url';
|
|
11
|
-
import initSqlJs from 'sql.js';
|
|
12
|
-
import { randomUUID } from 'crypto';
|
|
13
|
-
function getDbPath() {
|
|
14
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
15
|
-
const __dirname = dirname(__filename);
|
|
16
|
-
const agentDir = join(__dirname, '../../..');
|
|
17
|
-
if (existsSync(join(agentDir, 'package.json'))) {
|
|
18
|
-
return join(agentDir, 'data', 'knowledge_preservation.sqlite');
|
|
19
|
-
}
|
|
20
|
-
return join(process.cwd(), 'agent', 'data', 'knowledge_preservation.sqlite');
|
|
21
|
-
}
|
|
22
|
-
export class SQLiteKnowledgePreservationRepository {
|
|
23
|
-
dbPath;
|
|
24
|
-
db = null;
|
|
25
|
-
constructor() {
|
|
26
|
-
this.dbPath = getDbPath();
|
|
27
|
-
}
|
|
28
|
-
async getDb() {
|
|
29
|
-
if (this.db)
|
|
30
|
-
return this.db;
|
|
31
|
-
const SQL = await initSqlJs();
|
|
32
|
-
const dbDir = dirname(this.dbPath);
|
|
33
|
-
if (!existsSync(dbDir)) {
|
|
34
|
-
mkdirSync(dbDir, { recursive: true });
|
|
35
|
-
}
|
|
36
|
-
if (existsSync(this.dbPath)) {
|
|
37
|
-
const buffer = readFileSync(this.dbPath);
|
|
38
|
-
this.db = new SQL.Database(buffer);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
this.db = new SQL.Database();
|
|
42
|
-
}
|
|
43
|
-
// Create knowledge preservation table
|
|
44
|
-
this.db.run(`
|
|
45
|
-
CREATE TABLE IF NOT EXISTS knowledge_preservation (
|
|
46
|
-
id TEXT PRIMARY KEY,
|
|
47
|
-
codebaseId TEXT NOT NULL,
|
|
48
|
-
type TEXT NOT NULL,
|
|
49
|
-
title TEXT NOT NULL,
|
|
50
|
-
content TEXT NOT NULL,
|
|
51
|
-
sourceType TEXT NOT NULL,
|
|
52
|
-
sourceFilepath TEXT,
|
|
53
|
-
sourceLineStart INTEGER,
|
|
54
|
-
sourceLineEnd INTEGER,
|
|
55
|
-
sourceContext TEXT,
|
|
56
|
-
relevanceScore REAL,
|
|
57
|
-
metadata TEXT,
|
|
58
|
-
extractedAt INTEGER NOT NULL
|
|
59
|
-
)
|
|
60
|
-
`);
|
|
61
|
-
// Create indexes
|
|
62
|
-
this.db.run(`CREATE INDEX IF NOT EXISTS idx_codebase ON knowledge_preservation(codebaseId)`);
|
|
63
|
-
this.db.run(`CREATE INDEX IF NOT EXISTS idx_type ON knowledge_preservation(codebaseId, type)`);
|
|
64
|
-
this.db.run(`CREATE INDEX IF NOT EXISTS idx_extracted ON knowledge_preservation(codebaseId, extractedAt DESC)`);
|
|
65
|
-
this.db.run(`CREATE INDEX IF NOT EXISTS idx_relevance ON knowledge_preservation(codebaseId, relevanceScore DESC)`);
|
|
66
|
-
return this.db;
|
|
67
|
-
}
|
|
68
|
-
saveDb() {
|
|
69
|
-
if (!this.db)
|
|
70
|
-
return;
|
|
71
|
-
const data = this.db.export();
|
|
72
|
-
const buffer = Buffer.from(data);
|
|
73
|
-
writeFileSync(this.dbPath, buffer);
|
|
74
|
-
}
|
|
75
|
-
async store(knowledge) {
|
|
76
|
-
const db = await this.getDb();
|
|
77
|
-
const id = knowledge.id || randomUUID();
|
|
78
|
-
const extractedAt = knowledge.extractedAt.getTime();
|
|
79
|
-
const stmt = db.prepare(`
|
|
80
|
-
INSERT OR REPLACE INTO knowledge_preservation
|
|
81
|
-
(id, codebaseId, type, title, content, sourceType, sourceFilepath,
|
|
82
|
-
sourceLineStart, sourceLineEnd, sourceContext, relevanceScore, metadata, extractedAt)
|
|
83
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
84
|
-
`);
|
|
85
|
-
stmt.run([
|
|
86
|
-
id,
|
|
87
|
-
knowledge.codebaseId,
|
|
88
|
-
knowledge.type,
|
|
89
|
-
knowledge.title,
|
|
90
|
-
knowledge.content,
|
|
91
|
-
knowledge.source.type,
|
|
92
|
-
knowledge.source.filepath ?? null,
|
|
93
|
-
knowledge.source.lineNumbers?.start ?? null,
|
|
94
|
-
knowledge.source.lineNumbers?.end ?? null,
|
|
95
|
-
knowledge.source.context ?? null,
|
|
96
|
-
knowledge.relevanceScore ?? null,
|
|
97
|
-
JSON.stringify(knowledge.metadata ?? {}),
|
|
98
|
-
extractedAt,
|
|
99
|
-
]);
|
|
100
|
-
stmt.free();
|
|
101
|
-
this.saveDb();
|
|
102
|
-
}
|
|
103
|
-
async getById(id) {
|
|
104
|
-
const db = await this.getDb();
|
|
105
|
-
const stmt = db.prepare('SELECT * FROM knowledge_preservation WHERE id = ?');
|
|
106
|
-
stmt.bind([id]);
|
|
107
|
-
if (!stmt.step()) {
|
|
108
|
-
stmt.free();
|
|
109
|
-
return null;
|
|
110
|
-
}
|
|
111
|
-
const row = stmt.getAsObject();
|
|
112
|
-
stmt.free();
|
|
113
|
-
return this.mapRowToKnowledge(row);
|
|
114
|
-
}
|
|
115
|
-
async findByCodebase(codebaseId, limit = 100) {
|
|
116
|
-
const db = await this.getDb();
|
|
117
|
-
const stmt = db.prepare(`
|
|
118
|
-
SELECT * FROM knowledge_preservation
|
|
119
|
-
WHERE codebaseId = ?
|
|
120
|
-
ORDER BY extractedAt DESC
|
|
121
|
-
LIMIT ?
|
|
122
|
-
`);
|
|
123
|
-
stmt.bind([codebaseId, limit]);
|
|
124
|
-
return this.executeAndMap(stmt);
|
|
125
|
-
}
|
|
126
|
-
async findByType(codebaseId, type, limit = 100) {
|
|
127
|
-
const db = await this.getDb();
|
|
128
|
-
const stmt = db.prepare(`
|
|
129
|
-
SELECT * FROM knowledge_preservation
|
|
130
|
-
WHERE codebaseId = ? AND type = ?
|
|
131
|
-
ORDER BY extractedAt DESC
|
|
132
|
-
LIMIT ?
|
|
133
|
-
`);
|
|
134
|
-
stmt.bind([codebaseId, type, limit]);
|
|
135
|
-
return this.executeAndMap(stmt);
|
|
136
|
-
}
|
|
137
|
-
async search(codebaseId, query, limit = 50) {
|
|
138
|
-
const db = await this.getDb();
|
|
139
|
-
const searchTerm = `%${query}%`;
|
|
140
|
-
const stmt = db.prepare(`
|
|
141
|
-
SELECT * FROM knowledge_preservation
|
|
142
|
-
WHERE codebaseId = ?
|
|
143
|
-
AND (title LIKE ? OR content LIKE ?)
|
|
144
|
-
ORDER BY relevanceScore DESC, extractedAt DESC
|
|
145
|
-
LIMIT ?
|
|
146
|
-
`);
|
|
147
|
-
stmt.bind([codebaseId, searchTerm, searchTerm, limit]);
|
|
148
|
-
return this.executeAndMap(stmt);
|
|
149
|
-
}
|
|
150
|
-
async findByTags(codebaseId, tags, limit = 50) {
|
|
151
|
-
const db = await this.getDb();
|
|
152
|
-
const tagConditions = tags.map(() => 'json_extract(metadata, "$.tags") LIKE ?').join(' OR ');
|
|
153
|
-
const searchTerms = tags.map(tag => `%"${tag}"%`);
|
|
154
|
-
const stmt = db.prepare(`
|
|
155
|
-
SELECT * FROM knowledge_preservation
|
|
156
|
-
WHERE codebaseId = ?
|
|
157
|
-
AND (${tagConditions})
|
|
158
|
-
ORDER BY extractedAt DESC
|
|
159
|
-
LIMIT ?
|
|
160
|
-
`);
|
|
161
|
-
stmt.bind([codebaseId, ...searchTerms, limit]);
|
|
162
|
-
return this.executeAndMap(stmt);
|
|
163
|
-
}
|
|
164
|
-
async update(knowledge) {
|
|
165
|
-
if (!knowledge.id) {
|
|
166
|
-
throw new Error('Knowledge ID required for update');
|
|
167
|
-
}
|
|
168
|
-
await this.store(knowledge); // INSERT OR REPLACE handles update
|
|
169
|
-
}
|
|
170
|
-
async delete(id) {
|
|
171
|
-
const db = await this.getDb();
|
|
172
|
-
const stmt = db.prepare('DELETE FROM knowledge_preservation WHERE id = ?');
|
|
173
|
-
stmt.run([id]);
|
|
174
|
-
stmt.free();
|
|
175
|
-
this.saveDb();
|
|
176
|
-
}
|
|
177
|
-
async getMostAccessed(codebaseId, limit = 20) {
|
|
178
|
-
const db = await this.getDb();
|
|
179
|
-
const stmt = db.prepare(`
|
|
180
|
-
SELECT * FROM knowledge_preservation
|
|
181
|
-
WHERE codebaseId = ?
|
|
182
|
-
AND json_extract(metadata, "$.usageCount") > 0
|
|
183
|
-
ORDER BY json_extract(metadata, "$.usageCount") DESC
|
|
184
|
-
LIMIT ?
|
|
185
|
-
`);
|
|
186
|
-
stmt.bind([codebaseId, limit]);
|
|
187
|
-
return this.executeAndMap(stmt);
|
|
188
|
-
}
|
|
189
|
-
async getRecent(codebaseId, limit = 20) {
|
|
190
|
-
const db = await this.getDb();
|
|
191
|
-
const stmt = db.prepare(`
|
|
192
|
-
SELECT * FROM knowledge_preservation
|
|
193
|
-
WHERE codebaseId = ?
|
|
194
|
-
ORDER BY extractedAt DESC
|
|
195
|
-
LIMIT ?
|
|
196
|
-
`);
|
|
197
|
-
stmt.bind([codebaseId, limit]);
|
|
198
|
-
return this.executeAndMap(stmt);
|
|
199
|
-
}
|
|
200
|
-
mapRowToKnowledge(row) {
|
|
201
|
-
const metadata = JSON.parse(row.metadata ?? '{}');
|
|
202
|
-
return {
|
|
203
|
-
id: row.id,
|
|
204
|
-
codebaseId: row.codebaseId,
|
|
205
|
-
type: row.type,
|
|
206
|
-
title: row.title,
|
|
207
|
-
content: row.content,
|
|
208
|
-
source: {
|
|
209
|
-
type: row.sourceType,
|
|
210
|
-
filepath: row.sourceFilepath ?? undefined,
|
|
211
|
-
lineNumbers: (row.sourceLineStart !== null && row.sourceLineEnd !== null)
|
|
212
|
-
? { start: row.sourceLineStart, end: row.sourceLineEnd }
|
|
213
|
-
: undefined,
|
|
214
|
-
context: row.sourceContext ?? undefined,
|
|
215
|
-
},
|
|
216
|
-
extractedAt: new Date(row.extractedAt),
|
|
217
|
-
relevanceScore: row.relevanceScore ?? undefined,
|
|
218
|
-
metadata: Object.keys(metadata).length > 0 ? metadata : undefined,
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
executeAndMap(stmt) {
|
|
222
|
-
const knowledge = [];
|
|
223
|
-
while (stmt.step()) {
|
|
224
|
-
knowledge.push(this.mapRowToKnowledge(stmt.getAsObject()));
|
|
225
|
-
}
|
|
226
|
-
stmt.free();
|
|
227
|
-
return knowledge;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
//# sourceMappingURL=sqlite-knowledge-preservation-repository.js.map
|