@mycodemap/mycodemap 0.4.0 → 0.4.2
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/CHANGELOG.md +45 -0
- package/README.md +214 -221
- package/dist/cli/commands/analyze-options.d.ts +36 -0
- package/dist/cli/commands/analyze-options.d.ts.map +1 -0
- package/dist/cli/commands/analyze-options.js +147 -0
- package/dist/cli/commands/analyze-options.js.map +1 -0
- package/dist/cli/commands/analyze.d.ts +93 -4
- package/dist/cli/commands/analyze.d.ts.map +1 -1
- package/dist/cli/commands/analyze.js +592 -176
- package/dist/cli/commands/analyze.js.map +1 -1
- package/dist/cli/commands/ci.d.ts +47 -1
- package/dist/cli/commands/ci.d.ts.map +1 -1
- package/dist/cli/commands/ci.js +208 -1
- package/dist/cli/commands/ci.js.map +1 -1
- package/dist/cli/commands/export.d.ts.map +1 -1
- package/dist/cli/commands/export.js +2 -2
- package/dist/cli/commands/export.js.map +1 -1
- package/dist/cli/commands/generate.d.ts +8 -2
- package/dist/cli/commands/generate.d.ts.map +1 -1
- package/dist/cli/commands/generate.js +151 -22
- package/dist/cli/commands/generate.js.map +1 -1
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +2 -13
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/ship/analyzer.d.ts +1 -1
- package/dist/cli/commands/ship/analyzer.d.ts.map +1 -1
- package/dist/cli/commands/ship/analyzer.js +8 -1
- package/dist/cli/commands/ship/analyzer.js.map +1 -1
- package/dist/cli/commands/ship/checker.d.ts +1 -1
- package/dist/cli/commands/ship/checker.d.ts.map +1 -1
- package/dist/cli/commands/ship/checker.js +17 -6
- package/dist/cli/commands/ship/checker.js.map +1 -1
- package/dist/cli/commands/ship/index.js +2 -2
- package/dist/cli/commands/ship/index.js.map +1 -1
- package/dist/cli/commands/ship/monitor.d.ts +17 -2
- package/dist/cli/commands/ship/monitor.d.ts.map +1 -1
- package/dist/cli/commands/ship/monitor.js +116 -29
- package/dist/cli/commands/ship/monitor.js.map +1 -1
- package/dist/cli/commands/ship/pipeline.d.ts.map +1 -1
- package/dist/cli/commands/ship/pipeline.js +97 -18
- package/dist/cli/commands/ship/pipeline.js.map +1 -1
- package/dist/cli/commands/ship/publisher.d.ts +12 -2
- package/dist/cli/commands/ship/publisher.d.ts.map +1 -1
- package/dist/cli/commands/ship/publisher.js +217 -37
- package/dist/cli/commands/ship/publisher.js.map +1 -1
- package/dist/cli/commands/ship/rules/quality-rules.d.ts +2 -2
- package/dist/cli/commands/ship/rules/quality-rules.d.ts.map +1 -1
- package/dist/cli/commands/ship/rules/quality-rules.js +53 -54
- package/dist/cli/commands/ship/rules/quality-rules.js.map +1 -1
- package/dist/cli/commands/ship/versioner.d.ts +1 -1
- package/dist/cli/commands/ship/versioner.d.ts.map +1 -1
- package/dist/cli/commands/ship/versioner.js +4 -2
- package/dist/cli/commands/ship/versioner.js.map +1 -1
- package/dist/cli/commands/workflow.js +4 -4
- package/dist/cli/commands/workflow.js.map +1 -1
- package/dist/cli/config-loader.d.ts +31 -0
- package/dist/cli/config-loader.d.ts.map +1 -0
- package/dist/cli/config-loader.js +235 -0
- package/dist/cli/config-loader.js.map +1 -0
- package/dist/cli/index.js +19 -64
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/removed-commands.d.ts +9 -0
- package/dist/cli/removed-commands.d.ts.map +1 -0
- package/dist/cli/removed-commands.js +48 -0
- package/dist/cli/removed-commands.js.map +1 -0
- package/dist/cli/storage-runtime.d.ts +8 -0
- package/dist/cli/storage-runtime.d.ts.map +1 -0
- package/dist/cli/storage-runtime.js +14 -0
- package/dist/cli/storage-runtime.js.map +1 -0
- package/dist/cli/tree-sitter-check.d.ts.map +1 -1
- package/dist/cli/tree-sitter-check.js +0 -1
- package/dist/cli/tree-sitter-check.js.map +1 -1
- package/dist/cli-new/commands/export.d.ts.map +1 -1
- package/dist/cli-new/commands/export.js +2 -2
- package/dist/cli-new/commands/export.js.map +1 -1
- package/dist/cli-new/commands/query.d.ts.map +1 -1
- package/dist/cli-new/commands/query.js +5 -4
- package/dist/cli-new/commands/query.js.map +1 -1
- package/dist/cli-new/index.d.ts.map +1 -1
- package/dist/cli-new/index.js +0 -2
- package/dist/cli-new/index.js.map +1 -1
- package/dist/core/analyzer.d.ts.map +1 -1
- package/dist/core/analyzer.js +7 -39
- package/dist/core/analyzer.js.map +1 -1
- package/dist/core/file-discovery.d.ts +17 -0
- package/dist/core/file-discovery.d.ts.map +1 -0
- package/dist/core/file-discovery.js +75 -0
- package/dist/core/file-discovery.js.map +1 -0
- package/dist/core/global-index.d.ts +5 -0
- package/dist/core/global-index.d.ts.map +1 -1
- package/dist/core/global-index.js +71 -21
- package/dist/core/global-index.js.map +1 -1
- package/dist/generator/index.d.ts.map +1 -1
- package/dist/generator/index.js +8 -0
- package/dist/generator/index.js.map +1 -1
- package/dist/infrastructure/parser/implementations/GoParser.d.ts +2 -5
- package/dist/infrastructure/parser/implementations/GoParser.d.ts.map +1 -1
- package/dist/infrastructure/parser/implementations/GoParser.js +2 -5
- package/dist/infrastructure/parser/implementations/GoParser.js.map +1 -1
- package/dist/infrastructure/parser/implementations/PythonParser.d.ts +1 -5
- package/dist/infrastructure/parser/implementations/PythonParser.d.ts.map +1 -1
- package/dist/infrastructure/parser/implementations/PythonParser.js +1 -5
- package/dist/infrastructure/parser/implementations/PythonParser.js.map +1 -1
- package/dist/infrastructure/parser/implementations/TypeScriptParser.d.ts +1 -5
- package/dist/infrastructure/parser/implementations/TypeScriptParser.d.ts.map +1 -1
- package/dist/infrastructure/parser/implementations/TypeScriptParser.js +1 -5
- package/dist/infrastructure/parser/implementations/TypeScriptParser.js.map +1 -1
- package/dist/infrastructure/storage/StorageFactory.d.ts +0 -1
- package/dist/infrastructure/storage/StorageFactory.d.ts.map +1 -1
- package/dist/infrastructure/storage/StorageFactory.js +4 -29
- package/dist/infrastructure/storage/StorageFactory.js.map +1 -1
- package/dist/infrastructure/storage/adapters/FileSystemStorage.d.ts.map +1 -1
- package/dist/infrastructure/storage/adapters/FileSystemStorage.js +24 -137
- package/dist/infrastructure/storage/adapters/FileSystemStorage.js.map +1 -1
- package/dist/infrastructure/storage/adapters/KuzuDBStorage.d.ts +10 -18
- package/dist/infrastructure/storage/adapters/KuzuDBStorage.d.ts.map +1 -1
- package/dist/infrastructure/storage/adapters/KuzuDBStorage.js +103 -146
- package/dist/infrastructure/storage/adapters/KuzuDBStorage.js.map +1 -1
- package/dist/infrastructure/storage/adapters/MemoryStorage.d.ts +0 -1
- package/dist/infrastructure/storage/adapters/MemoryStorage.d.ts.map +1 -1
- package/dist/infrastructure/storage/adapters/MemoryStorage.js +16 -136
- package/dist/infrastructure/storage/adapters/MemoryStorage.js.map +1 -1
- package/dist/infrastructure/storage/graph-helpers.d.ts +16 -0
- package/dist/infrastructure/storage/graph-helpers.d.ts.map +1 -0
- package/dist/infrastructure/storage/graph-helpers.js +161 -0
- package/dist/infrastructure/storage/graph-helpers.js.map +1 -0
- package/dist/infrastructure/storage/index.d.ts.map +1 -1
- package/dist/interface/config/index.d.ts +10 -1
- package/dist/interface/config/index.d.ts.map +1 -1
- package/dist/interface/types/index.d.ts +13 -0
- package/dist/interface/types/index.d.ts.map +1 -1
- package/dist/interface/types/storage.d.ts +1 -4
- package/dist/interface/types/storage.d.ts.map +1 -1
- package/dist/orchestrator/confidence.d.ts +9 -9
- package/dist/orchestrator/confidence.d.ts.map +1 -1
- package/dist/orchestrator/confidence.js +44 -67
- package/dist/orchestrator/confidence.js.map +1 -1
- package/dist/orchestrator/file-header-scanner.d.ts.map +1 -1
- package/dist/orchestrator/file-header-scanner.js +22 -31
- package/dist/orchestrator/file-header-scanner.js.map +1 -1
- package/dist/orchestrator/intent-router.d.ts +2 -11
- package/dist/orchestrator/intent-router.d.ts.map +1 -1
- package/dist/orchestrator/intent-router.js +58 -49
- package/dist/orchestrator/intent-router.js.map +1 -1
- package/dist/orchestrator/tool-orchestrator.d.ts.map +1 -1
- package/dist/orchestrator/tool-orchestrator.js +6 -4
- package/dist/orchestrator/tool-orchestrator.js.map +1 -1
- package/dist/orchestrator/types.d.ts +113 -2
- package/dist/orchestrator/types.d.ts.map +1 -1
- package/dist/orchestrator/types.js +29 -0
- package/dist/orchestrator/types.js.map +1 -1
- package/dist/orchestrator/workflow/config.d.ts +4 -12
- package/dist/orchestrator/workflow/config.d.ts.map +1 -1
- package/dist/orchestrator/workflow/config.js +4 -6
- package/dist/orchestrator/workflow/config.js.map +1 -1
- package/dist/orchestrator/workflow/git-analyzer.d.ts.map +1 -1
- package/dist/orchestrator/workflow/git-analyzer.js +9 -19
- package/dist/orchestrator/workflow/git-analyzer.js.map +1 -1
- package/dist/orchestrator/workflow/phase-inheritance.d.ts.map +1 -1
- package/dist/orchestrator/workflow/phase-inheritance.js +14 -23
- package/dist/orchestrator/workflow/phase-inheritance.js.map +1 -1
- package/dist/orchestrator/workflow/result-fusion.d.ts.map +1 -1
- package/dist/orchestrator/workflow/result-fusion.js +9 -11
- package/dist/orchestrator/workflow/result-fusion.js.map +1 -1
- package/dist/orchestrator/workflow/templates.d.ts +4 -1
- package/dist/orchestrator/workflow/templates.d.ts.map +1 -1
- package/dist/orchestrator/workflow/templates.js +49 -207
- package/dist/orchestrator/workflow/templates.js.map +1 -1
- package/dist/orchestrator/workflow/test-linker.d.ts.map +1 -1
- package/dist/orchestrator/workflow/test-linker.js +12 -24
- package/dist/orchestrator/workflow/test-linker.js.map +1 -1
- package/dist/orchestrator/workflow/types.d.ts +11 -8
- package/dist/orchestrator/workflow/types.d.ts.map +1 -1
- package/dist/orchestrator/workflow/types.js +8 -1
- package/dist/orchestrator/workflow/types.js.map +1 -1
- package/dist/orchestrator/workflow/visualizer.d.ts.map +1 -1
- package/dist/orchestrator/workflow/visualizer.js +7 -9
- package/dist/orchestrator/workflow/visualizer.js.map +1 -1
- package/dist/orchestrator/workflow/workflow-context.d.ts.map +1 -1
- package/dist/orchestrator/workflow/workflow-context.js +3 -5
- package/dist/orchestrator/workflow/workflow-context.js.map +1 -1
- package/dist/orchestrator/workflow/workflow-orchestrator.d.ts +0 -4
- package/dist/orchestrator/workflow/workflow-orchestrator.d.ts.map +1 -1
- package/dist/orchestrator/workflow/workflow-orchestrator.js +7 -99
- package/dist/orchestrator/workflow/workflow-orchestrator.js.map +1 -1
- package/dist/parser/index.d.ts.map +1 -1
- package/dist/parser/index.js +2 -2
- package/dist/parser/index.js.map +1 -1
- package/dist/plugins/index.d.ts +5 -3
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/index.js +19 -8
- package/dist/plugins/index.js.map +1 -1
- package/dist/plugins/plugin-loader.d.ts +21 -6
- package/dist/plugins/plugin-loader.d.ts.map +1 -1
- package/dist/plugins/plugin-loader.js +170 -54
- package/dist/plugins/plugin-loader.js.map +1 -1
- package/dist/plugins/plugin-registry.d.ts +7 -4
- package/dist/plugins/plugin-registry.d.ts.map +1 -1
- package/dist/plugins/plugin-registry.js +62 -14
- package/dist/plugins/plugin-registry.js.map +1 -1
- package/dist/plugins/types.d.ts +16 -6
- package/dist/plugins/types.d.ts.map +1 -1
- package/dist/plugins/types.js +2 -0
- package/dist/plugins/types.js.map +1 -1
- package/dist/server/handlers/AnalysisHandler.d.ts +16 -2
- package/dist/server/handlers/AnalysisHandler.d.ts.map +1 -1
- package/dist/server/handlers/AnalysisHandler.js +31 -47
- package/dist/server/handlers/AnalysisHandler.js.map +1 -1
- package/dist/server/routes/api.d.ts.map +1 -1
- package/dist/server/routes/api.js +31 -12
- package/dist/server/routes/api.js.map +1 -1
- package/docs/AI_ASSISTANT_SETUP.md +3 -1
- package/docs/PUBLISHING.md +18 -4
- package/docs/SETUP_GUIDE.md +41 -17
- package/docs/ai-guide/COMMANDS.md +107 -103
- package/docs/ai-guide/INTEGRATION.md +23 -21
- package/docs/ai-guide/OUTPUT.md +206 -10
- package/docs/ai-guide/PATTERNS.md +64 -15
- package/docs/ai-guide/PROMPTS.md +50 -12
- package/docs/ai-guide/QUICKSTART.md +35 -19
- package/docs/ai-guide/README.md +22 -4
- package/docs/product-specs/MVP3-ARCHITECTURE-COMPARISON.md +159 -434
- package/docs/product-specs/MVP3-ARCHITECTURE-REDESIGN-PRD.md +169 -261
- package/docs/product-specs/MVP3-ARCHITECTURE-REDESIGN-TECH-PRD.md +201 -1259
- package/docs/product-specs/README.md +8 -1
- package/docs/rules/architecture-guardrails.md +1 -2
- package/docs/rules/engineering-with-codex-openai.md +15 -9
- package/docs/rules/validation.md +26 -4
- package/mycodemap.config.schema.json +76 -5
- package/package.json +1 -1
- package/scripts/pre-release-check.js +21 -3
- package/scripts/sync-analyze-docs.js +500 -0
- package/scripts/validate-ai-docs.js +54 -1
- package/scripts/validate-docs.js +746 -26
- package/dist/cli/commands/server.d.ts +0 -9
- package/dist/cli/commands/server.d.ts.map +0 -1
- package/dist/cli/commands/server.js +0 -68
- package/dist/cli/commands/server.js.map +0 -1
- package/dist/cli-new/commands/server.d.ts +0 -13
- package/dist/cli-new/commands/server.d.ts.map +0 -1
- package/dist/cli-new/commands/server.js +0 -94
- package/dist/cli-new/commands/server.js.map +0 -1
- package/dist/infrastructure/storage/adapters/Neo4jStorage.d.ts +0 -49
- package/dist/infrastructure/storage/adapters/Neo4jStorage.d.ts.map +0 -1
- package/dist/infrastructure/storage/adapters/Neo4jStorage.js +0 -222
- package/dist/infrastructure/storage/adapters/Neo4jStorage.js.map +0 -1
|
@@ -5,6 +5,21 @@
|
|
|
5
5
|
// ============================================
|
|
6
6
|
import { join } from 'path';
|
|
7
7
|
import { StorageBase, StorageError } from '../interfaces/StorageBase.js';
|
|
8
|
+
import { calculateImpactInGraph, createEmptyCodeGraph, deleteModuleFromGraph, deserializeCodeGraphSnapshot, detectCyclesInGraph, findCalleesInGraph, findCallersInGraph, findDependenciesInGraph, findDependentsInGraph, getProjectStatisticsFromGraph, serializeCodeGraphSnapshot, upsertModuleInGraph, } from '../graph-helpers.js';
|
|
9
|
+
async function loadKuzuModule() {
|
|
10
|
+
const moduleName = 'kuzu';
|
|
11
|
+
return await import(moduleName);
|
|
12
|
+
}
|
|
13
|
+
function normalizeKuzuResults(result) {
|
|
14
|
+
return Array.isArray(result) ? result : [result];
|
|
15
|
+
}
|
|
16
|
+
async function closeKuzuResults(results) {
|
|
17
|
+
for (const result of results) {
|
|
18
|
+
if (typeof result.close === 'function') {
|
|
19
|
+
await result.close();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
8
23
|
/**
|
|
9
24
|
* KùzuDB 存储适配器(可选依赖)
|
|
10
25
|
*
|
|
@@ -12,224 +27,166 @@ import { StorageBase, StorageError } from '../interfaces/StorageBase.js';
|
|
|
12
27
|
*
|
|
13
28
|
* 特点:
|
|
14
29
|
* - 嵌入式图数据库
|
|
15
|
-
* -
|
|
16
|
-
* -
|
|
17
|
-
* -
|
|
18
|
-
*
|
|
19
|
-
* TODO-DEBT [L1] [日期:2026-03-17] [作者:AI] [原因:MVP阶段暂不实现完整功能]
|
|
20
|
-
* 问题:目前使用内存 fallback 实现
|
|
21
|
-
* 风险:无法持久化到 KùzuDB
|
|
22
|
-
* 偿还计划:V1.0 实现完整 KùzuDB 集成
|
|
30
|
+
* - 本地持久化,无需单独服务进程
|
|
31
|
+
* - 对 CodeGraph 提供 snapshot-backed persistence
|
|
32
|
+
* - 查询/分析接口与共享 storage contract 保持一致
|
|
23
33
|
*/
|
|
24
34
|
export class KuzuDBStorage extends StorageBase {
|
|
25
35
|
type = 'kuzudb';
|
|
26
|
-
/** KùzuDB 数据库实例 */
|
|
27
36
|
db = null;
|
|
28
|
-
/** 连接实例 */
|
|
29
37
|
conn = null;
|
|
30
|
-
/** 内存 fallback */
|
|
31
|
-
memoryGraph = this.createEmptyGraph();
|
|
32
|
-
/** 存储配置 */
|
|
33
38
|
dbConfig;
|
|
34
39
|
constructor(config) {
|
|
35
40
|
super();
|
|
36
41
|
this.dbConfig = config;
|
|
37
42
|
}
|
|
38
|
-
// ============================================
|
|
39
|
-
// 生命周期管理
|
|
40
|
-
// ============================================
|
|
41
43
|
async doInitialize() {
|
|
44
|
+
if (!this.projectPath) {
|
|
45
|
+
throw new StorageError('Project path not set', 'PROJECT_PATH_NOT_SET');
|
|
46
|
+
}
|
|
42
47
|
try {
|
|
43
|
-
|
|
44
|
-
// @ts-expect-error kuzu is optional dependency
|
|
45
|
-
const kuzu = await import('kuzu');
|
|
48
|
+
const kuzu = await loadKuzuModule();
|
|
46
49
|
const dbPath = this.dbConfig.databasePath
|
|
47
50
|
? join(this.projectPath, this.dbConfig.databasePath)
|
|
48
51
|
: join(this.projectPath, '.codemap', 'kuzudb');
|
|
49
52
|
this.db = new kuzu.Database(dbPath);
|
|
50
53
|
this.conn = new kuzu.Connection(this.db);
|
|
51
|
-
|
|
52
|
-
await this.initializeSchema();
|
|
54
|
+
await this.runQuery('CREATE NODE TABLE IF NOT EXISTS Snapshot(id STRING PRIMARY KEY, projectId STRING, graph STRING, updatedAt STRING);');
|
|
53
55
|
}
|
|
54
|
-
catch {
|
|
55
|
-
|
|
56
|
-
// eslint-disable-next-line no-console
|
|
57
|
-
console.warn('KùzuDB not available, falling back to memory mode');
|
|
58
|
-
this.memoryGraph = this.createEmptyGraph();
|
|
56
|
+
catch (error) {
|
|
57
|
+
throw new StorageError('Failed to initialize KùzuDB storage', 'KUZU_INIT_FAILED', error);
|
|
59
58
|
}
|
|
60
59
|
}
|
|
61
60
|
async doClose() {
|
|
62
61
|
if (this.conn && typeof this.conn.close === 'function') {
|
|
63
62
|
await this.conn.close();
|
|
64
63
|
}
|
|
65
|
-
this.db
|
|
64
|
+
if (this.db && typeof this.db.close === 'function') {
|
|
65
|
+
await this.db.close();
|
|
66
|
+
}
|
|
66
67
|
this.conn = null;
|
|
68
|
+
this.db = null;
|
|
67
69
|
}
|
|
68
|
-
// ============================================
|
|
69
|
-
// 项目级别操作
|
|
70
|
-
// ============================================
|
|
71
70
|
async saveCodeGraph(graph) {
|
|
72
71
|
this.ensureInitialized();
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
};
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
// TODO: 实现 KùzuDB 持久化
|
|
84
|
-
throw new StorageError('KùzuDB persistence not yet implemented', 'NOT_IMPLEMENTED');
|
|
72
|
+
await this.runQuery('MATCH (s:Snapshot) DELETE s;');
|
|
73
|
+
await this.executePrepared('CREATE (s:Snapshot {id: $id, projectId: $projectId, graph: $graph, updatedAt: $updatedAt});', {
|
|
74
|
+
id: 'codemap-snapshot',
|
|
75
|
+
projectId: graph.project.id,
|
|
76
|
+
graph: serializeCodeGraphSnapshot(graph),
|
|
77
|
+
updatedAt: new Date().toISOString(),
|
|
78
|
+
});
|
|
85
79
|
}
|
|
86
80
|
async loadCodeGraph() {
|
|
87
81
|
this.ensureInitialized();
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
symbols: [...this.memoryGraph.symbols],
|
|
93
|
-
dependencies: [...this.memoryGraph.dependencies],
|
|
94
|
-
};
|
|
82
|
+
const rows = await this.queryRows('MATCH (s:Snapshot) RETURN s.graph AS graph LIMIT 1;');
|
|
83
|
+
const snapshot = typeof rows[0]?.graph === 'string' ? rows[0].graph : null;
|
|
84
|
+
if (!snapshot) {
|
|
85
|
+
return createEmptyCodeGraph(this.projectPath ?? '');
|
|
95
86
|
}
|
|
96
|
-
|
|
97
|
-
throw new StorageError('KùzuDB loading not yet implemented', 'NOT_IMPLEMENTED');
|
|
87
|
+
return deserializeCodeGraphSnapshot(snapshot, this.projectPath ?? '');
|
|
98
88
|
}
|
|
99
89
|
async deleteProject() {
|
|
100
90
|
this.ensureInitialized();
|
|
101
|
-
|
|
102
|
-
// TODO: 删除 KùzuDB 数据
|
|
91
|
+
await this.runQuery('MATCH (s:Snapshot) DELETE s;');
|
|
103
92
|
}
|
|
104
|
-
// ============================================
|
|
105
|
-
// 增量更新
|
|
106
|
-
// ============================================
|
|
107
93
|
async updateModule(module) {
|
|
108
94
|
this.ensureInitialized();
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if (index >= 0) {
|
|
112
|
-
this.memoryGraph.modules[index] = { ...module };
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
this.memoryGraph.modules.push({ ...module });
|
|
116
|
-
}
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
// TODO: 实现 KùzuDB 更新
|
|
95
|
+
const graph = await this.loadCodeGraph();
|
|
96
|
+
await this.saveCodeGraph(upsertModuleInGraph(graph, module));
|
|
120
97
|
}
|
|
121
98
|
async deleteModule(moduleId) {
|
|
122
99
|
this.ensureInitialized();
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
this.memoryGraph.symbols = this.memoryGraph.symbols.filter(s => s.moduleId !== moduleId);
|
|
126
|
-
this.memoryGraph.dependencies = this.memoryGraph.dependencies.filter(d => d.sourceId !== moduleId && d.targetId !== moduleId);
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
// TODO: 实现 KùzuDB 删除
|
|
100
|
+
const graph = await this.loadCodeGraph();
|
|
101
|
+
await this.saveCodeGraph(deleteModuleFromGraph(graph, moduleId));
|
|
130
102
|
}
|
|
131
|
-
// ============================================
|
|
132
|
-
// 查询操作
|
|
133
|
-
// ============================================
|
|
134
103
|
async findModuleById(id) {
|
|
135
104
|
this.ensureInitialized();
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
// TODO: 实现 KùzuDB 查询
|
|
140
|
-
return null;
|
|
105
|
+
const graph = await this.loadCodeGraph();
|
|
106
|
+
return graph.modules.find(module => module.id === id) ?? null;
|
|
141
107
|
}
|
|
142
108
|
async findModulesByPath(path) {
|
|
143
109
|
this.ensureInitialized();
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
return [];
|
|
110
|
+
const graph = await this.loadCodeGraph();
|
|
111
|
+
return graph.modules.filter(module => module.path.includes(path));
|
|
148
112
|
}
|
|
149
113
|
async findSymbolByName(name) {
|
|
150
114
|
this.ensureInitialized();
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
return [];
|
|
115
|
+
const graph = await this.loadCodeGraph();
|
|
116
|
+
return graph.symbols.filter(symbol => symbol.name.includes(name));
|
|
155
117
|
}
|
|
156
118
|
async findSymbolById(id) {
|
|
157
119
|
this.ensureInitialized();
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
return null;
|
|
120
|
+
const graph = await this.loadCodeGraph();
|
|
121
|
+
return graph.symbols.find(symbol => symbol.id === id) ?? null;
|
|
162
122
|
}
|
|
163
123
|
async findDependencies(moduleId) {
|
|
164
124
|
this.ensureInitialized();
|
|
165
|
-
|
|
166
|
-
return this.memoryGraph.dependencies.filter(d => d.sourceId === moduleId);
|
|
167
|
-
}
|
|
168
|
-
return [];
|
|
125
|
+
return findDependenciesInGraph(await this.loadCodeGraph(), moduleId);
|
|
169
126
|
}
|
|
170
127
|
async findDependents(moduleId) {
|
|
171
128
|
this.ensureInitialized();
|
|
172
|
-
|
|
173
|
-
return this.memoryGraph.dependencies.filter(d => d.targetId === moduleId);
|
|
174
|
-
}
|
|
175
|
-
return [];
|
|
129
|
+
return findDependentsInGraph(await this.loadCodeGraph(), moduleId);
|
|
176
130
|
}
|
|
177
|
-
async findCallers(
|
|
131
|
+
async findCallers(functionId) {
|
|
178
132
|
this.ensureInitialized();
|
|
179
|
-
return
|
|
133
|
+
return findCallersInGraph(await this.loadCodeGraph(), functionId);
|
|
180
134
|
}
|
|
181
|
-
async findCallees(
|
|
135
|
+
async findCallees(functionId) {
|
|
182
136
|
this.ensureInitialized();
|
|
183
|
-
return
|
|
137
|
+
return findCalleesInGraph(await this.loadCodeGraph(), functionId);
|
|
184
138
|
}
|
|
185
|
-
// ============================================
|
|
186
|
-
// 分析操作
|
|
187
|
-
// ============================================
|
|
188
139
|
async detectCycles() {
|
|
189
140
|
this.ensureInitialized();
|
|
190
|
-
return
|
|
141
|
+
return detectCyclesInGraph(await this.loadCodeGraph());
|
|
191
142
|
}
|
|
192
143
|
async calculateImpact(moduleId, depth) {
|
|
193
144
|
this.ensureInitialized();
|
|
194
|
-
return
|
|
195
|
-
rootModule: moduleId,
|
|
196
|
-
affectedModules: [],
|
|
197
|
-
depth,
|
|
198
|
-
};
|
|
145
|
+
return calculateImpactInGraph(await this.loadCodeGraph(), moduleId, depth);
|
|
199
146
|
}
|
|
200
147
|
async getStatistics() {
|
|
201
148
|
this.ensureInitialized();
|
|
202
|
-
return
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
149
|
+
return getProjectStatisticsFromGraph(await this.loadCodeGraph());
|
|
150
|
+
}
|
|
151
|
+
getConnection() {
|
|
152
|
+
if (!this.conn) {
|
|
153
|
+
throw new StorageError('KùzuDB connection not initialized', 'KUZU_CONNECTION_NOT_READY');
|
|
154
|
+
}
|
|
155
|
+
return this.conn;
|
|
156
|
+
}
|
|
157
|
+
async runQuery(statement) {
|
|
158
|
+
const result = await this.getConnection().query(statement);
|
|
159
|
+
await closeKuzuResults(normalizeKuzuResults(result));
|
|
160
|
+
}
|
|
161
|
+
async executePrepared(statement, params) {
|
|
162
|
+
const connection = this.getConnection();
|
|
163
|
+
if (typeof connection.prepare !== 'function' || typeof connection.execute !== 'function') {
|
|
164
|
+
throw new StorageError('KùzuDB prepared execution API is unavailable', 'KUZU_PREPARE_NOT_SUPPORTED');
|
|
165
|
+
}
|
|
166
|
+
const preparedStatement = await connection.prepare(statement);
|
|
167
|
+
if (typeof preparedStatement.isSuccess === 'function' &&
|
|
168
|
+
!preparedStatement.isSuccess()) {
|
|
169
|
+
const reason = typeof preparedStatement.getErrorMessage === 'function'
|
|
170
|
+
? preparedStatement.getErrorMessage()
|
|
171
|
+
: 'Unknown Kùzu prepared statement error';
|
|
172
|
+
throw new StorageError(`Failed to prepare KùzuDB statement: ${reason}`, 'KUZU_PREPARE_FAILED');
|
|
173
|
+
}
|
|
174
|
+
const result = await connection.execute(preparedStatement, params);
|
|
175
|
+
await closeKuzuResults(normalizeKuzuResults(result));
|
|
176
|
+
}
|
|
177
|
+
async queryRows(statement) {
|
|
178
|
+
const result = await this.getConnection().query(statement);
|
|
179
|
+
const results = normalizeKuzuResults(result);
|
|
180
|
+
try {
|
|
181
|
+
const firstResult = results[0];
|
|
182
|
+
if (!firstResult) {
|
|
183
|
+
return [];
|
|
184
|
+
}
|
|
185
|
+
return await firstResult.getAll();
|
|
186
|
+
}
|
|
187
|
+
finally {
|
|
188
|
+
await closeKuzuResults(results);
|
|
189
|
+
}
|
|
233
190
|
}
|
|
234
191
|
}
|
|
235
192
|
//# sourceMappingURL=KuzuDBStorage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KuzuDBStorage.js","sourceRoot":"","sources":["../../../../src/infrastructure/storage/adapters/KuzuDBStorage.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,2EAA2E;AAC3E,+CAA+C;AAC/C,gCAAgC;AAChC,+CAA+C;AAE/C,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAa5B,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"KuzuDBStorage.js","sourceRoot":"","sources":["../../../../src/infrastructure/storage/adapters/KuzuDBStorage.ts"],"names":[],"mappings":"AAAA,gEAAgE;A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,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC;IACvD,CAAC;IAEO,KAAK,CAAC,SAAS,CAAC,SAAiB;QACvC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAC3D,MAAM,OAAO,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC;QAE7C,IAAI,CAAC;YACH,MAAM,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;YAC/B,IAAI,CAAC,WAAW,EAAE,CAAC;gBACjB,OAAO,EAAE,CAAC;YACZ,CAAC;YAED,OAAO,MAAM,WAAW,CAAC,MAAM,EAAE,CAAC;QACpC,CAAC;gBAAS,CAAC;YACT,MAAM,gBAAgB,CAAC,OAAO,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;CACF"}
|
|
@@ -32,6 +32,5 @@ export declare class MemoryStorage extends StorageBase {
|
|
|
32
32
|
detectCycles(): Promise<Cycle[]>;
|
|
33
33
|
calculateImpact(moduleId: string, depth: number): Promise<ImpactResult>;
|
|
34
34
|
getStatistics(): Promise<ProjectStatistics>;
|
|
35
|
-
private createEmptyGraph;
|
|
36
35
|
}
|
|
37
36
|
//# sourceMappingURL=MemoryStorage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MemoryStorage.d.ts","sourceRoot":"","sources":["../../../../src/infrastructure/storage/adapters/MemoryStorage.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,KAAK,EACL,YAAY,EACZ,iBAAiB,EAClB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,KAAK,EACV,SAAS,EACT,MAAM,EACN,MAAM,EACN,UAAU,EACX,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"MemoryStorage.d.ts","sourceRoot":"","sources":["../../../../src/infrastructure/storage/adapters/MemoryStorage.ts"],"names":[],"mappings":"AAMA,OAAO,KAA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CAAC,MAAM,EAAE,CAAC;IAKlD,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IASlD,YAAY,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;IAKhC,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAKvE,aAAa,IAAI,OAAO,CAAC,iBAAiB,CAAC;CAIlD"}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// 内存存储适配器 - 用于测试和轻量级场景的内存存储
|
|
5
5
|
// ============================================
|
|
6
6
|
import { StorageBase } from '../interfaces/StorageBase.js';
|
|
7
|
+
import { calculateImpactInGraph, cloneCodeGraph, createEmptyCodeGraph, deleteModuleFromGraph, detectCyclesInGraph, findCalleesInGraph, findCallersInGraph, findDependenciesInGraph, findDependentsInGraph, getProjectStatisticsFromGraph, upsertModuleInGraph, } from '../graph-helpers.js';
|
|
7
8
|
/**
|
|
8
9
|
* 内存存储适配器
|
|
9
10
|
*
|
|
@@ -16,61 +17,43 @@ import { StorageBase } from '../interfaces/StorageBase.js';
|
|
|
16
17
|
export class MemoryStorage extends StorageBase {
|
|
17
18
|
type = 'memory';
|
|
18
19
|
/** 内存中的代码图 */
|
|
19
|
-
graph =
|
|
20
|
+
graph = createEmptyCodeGraph();
|
|
20
21
|
// ============================================
|
|
21
22
|
// 生命周期管理
|
|
22
23
|
// ============================================
|
|
23
24
|
async doInitialize() {
|
|
24
25
|
// 内存存储无需特殊初始化
|
|
25
|
-
this.graph = this.
|
|
26
|
+
this.graph = createEmptyCodeGraph(this.projectPath ?? '');
|
|
26
27
|
}
|
|
27
28
|
async doClose() {
|
|
28
29
|
// 清理内存
|
|
29
|
-
this.graph = this.
|
|
30
|
+
this.graph = createEmptyCodeGraph(this.projectPath ?? '');
|
|
30
31
|
}
|
|
31
32
|
// ============================================
|
|
32
33
|
// 项目级别操作
|
|
33
34
|
// ============================================
|
|
34
35
|
async saveCodeGraph(graph) {
|
|
35
36
|
this.ensureInitialized();
|
|
36
|
-
this.graph =
|
|
37
|
-
project: { ...graph.project },
|
|
38
|
-
modules: [...graph.modules],
|
|
39
|
-
symbols: [...graph.symbols],
|
|
40
|
-
dependencies: [...graph.dependencies],
|
|
41
|
-
};
|
|
37
|
+
this.graph = cloneCodeGraph(graph);
|
|
42
38
|
}
|
|
43
39
|
async loadCodeGraph() {
|
|
44
40
|
this.ensureInitialized();
|
|
45
|
-
return
|
|
46
|
-
project: { ...this.graph.project },
|
|
47
|
-
modules: [...this.graph.modules],
|
|
48
|
-
symbols: [...this.graph.symbols],
|
|
49
|
-
dependencies: [...this.graph.dependencies],
|
|
50
|
-
};
|
|
41
|
+
return cloneCodeGraph(this.graph);
|
|
51
42
|
}
|
|
52
43
|
async deleteProject() {
|
|
53
44
|
this.ensureInitialized();
|
|
54
|
-
this.graph = this.
|
|
45
|
+
this.graph = createEmptyCodeGraph(this.projectPath ?? '');
|
|
55
46
|
}
|
|
56
47
|
// ============================================
|
|
57
48
|
// 增量更新
|
|
58
49
|
// ============================================
|
|
59
50
|
async updateModule(module) {
|
|
60
51
|
this.ensureInitialized();
|
|
61
|
-
|
|
62
|
-
if (index >= 0) {
|
|
63
|
-
this.graph.modules[index] = { ...module };
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
this.graph.modules.push({ ...module });
|
|
67
|
-
}
|
|
52
|
+
this.graph = upsertModuleInGraph(this.graph, module);
|
|
68
53
|
}
|
|
69
54
|
async deleteModule(moduleId) {
|
|
70
55
|
this.ensureInitialized();
|
|
71
|
-
this.graph
|
|
72
|
-
this.graph.symbols = this.graph.symbols.filter(s => s.moduleId !== moduleId);
|
|
73
|
-
this.graph.dependencies = this.graph.dependencies.filter(d => d.sourceId !== moduleId && d.targetId !== moduleId);
|
|
56
|
+
this.graph = deleteModuleFromGraph(this.graph, moduleId);
|
|
74
57
|
}
|
|
75
58
|
// ============================================
|
|
76
59
|
// 查询操作
|
|
@@ -93,137 +76,34 @@ export class MemoryStorage extends StorageBase {
|
|
|
93
76
|
}
|
|
94
77
|
async findDependencies(moduleId) {
|
|
95
78
|
this.ensureInitialized();
|
|
96
|
-
return this.graph
|
|
79
|
+
return findDependenciesInGraph(this.graph, moduleId);
|
|
97
80
|
}
|
|
98
81
|
async findDependents(moduleId) {
|
|
99
82
|
this.ensureInitialized();
|
|
100
|
-
return this.graph
|
|
83
|
+
return findDependentsInGraph(this.graph, moduleId);
|
|
101
84
|
}
|
|
102
85
|
async findCallers(functionId) {
|
|
103
86
|
this.ensureInitialized();
|
|
104
|
-
|
|
105
|
-
for (const dep of this.graph.dependencies) {
|
|
106
|
-
if (dep.targetId === functionId && dep.type === 'call') {
|
|
107
|
-
callerIds.add(dep.sourceId);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
const results = [];
|
|
111
|
-
for (const id of callerIds) {
|
|
112
|
-
const symbol = this.graph.symbols.find(s => s.id === id);
|
|
113
|
-
if (symbol)
|
|
114
|
-
results.push(symbol);
|
|
115
|
-
}
|
|
116
|
-
return results;
|
|
87
|
+
return findCallersInGraph(this.graph, functionId);
|
|
117
88
|
}
|
|
118
89
|
async findCallees(functionId) {
|
|
119
90
|
this.ensureInitialized();
|
|
120
|
-
|
|
121
|
-
for (const dep of this.graph.dependencies) {
|
|
122
|
-
if (dep.sourceId === functionId && dep.type === 'call') {
|
|
123
|
-
calleeIds.add(dep.targetId);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
const results = [];
|
|
127
|
-
for (const id of calleeIds) {
|
|
128
|
-
const symbol = this.graph.symbols.find(s => s.id === id);
|
|
129
|
-
if (symbol)
|
|
130
|
-
results.push(symbol);
|
|
131
|
-
}
|
|
132
|
-
return results;
|
|
91
|
+
return findCalleesInGraph(this.graph, functionId);
|
|
133
92
|
}
|
|
134
93
|
// ============================================
|
|
135
94
|
// 分析操作
|
|
136
95
|
// ============================================
|
|
137
96
|
async detectCycles() {
|
|
138
97
|
this.ensureInitialized();
|
|
139
|
-
|
|
140
|
-
const visited = new Set();
|
|
141
|
-
const inStack = new Set();
|
|
142
|
-
const dfs = (nodeId, path) => {
|
|
143
|
-
if (inStack.has(nodeId)) {
|
|
144
|
-
const cycleStart = path.indexOf(nodeId);
|
|
145
|
-
const cycleModules = path.slice(cycleStart);
|
|
146
|
-
cycles.push({
|
|
147
|
-
modules: cycleModules,
|
|
148
|
-
length: cycleModules.length,
|
|
149
|
-
});
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
if (visited.has(nodeId)) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
visited.add(nodeId);
|
|
156
|
-
inStack.add(nodeId);
|
|
157
|
-
for (const dep of this.graph.dependencies) {
|
|
158
|
-
if (dep.sourceId === nodeId) {
|
|
159
|
-
dfs(dep.targetId, [...path, nodeId]);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
inStack.delete(nodeId);
|
|
163
|
-
};
|
|
164
|
-
for (const module of this.graph.modules) {
|
|
165
|
-
if (!visited.has(module.id)) {
|
|
166
|
-
dfs(module.id, []);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
return cycles;
|
|
98
|
+
return detectCyclesInGraph(this.graph);
|
|
170
99
|
}
|
|
171
100
|
async calculateImpact(moduleId, depth) {
|
|
172
101
|
this.ensureInitialized();
|
|
173
|
-
|
|
174
|
-
const visited = new Set();
|
|
175
|
-
const queue = [{ id: moduleId, level: 0 }];
|
|
176
|
-
while (queue.length > 0) {
|
|
177
|
-
const { id, level } = queue.shift();
|
|
178
|
-
if (visited.has(id) || level > depth) {
|
|
179
|
-
continue;
|
|
180
|
-
}
|
|
181
|
-
visited.add(id);
|
|
182
|
-
if (level > 0) {
|
|
183
|
-
const module = this.graph.modules.find(m => m.id === id);
|
|
184
|
-
if (module) {
|
|
185
|
-
affectedModules.push({ ...module });
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
for (const dep of this.graph.dependencies) {
|
|
189
|
-
if (dep.targetId === id && !visited.has(dep.sourceId)) {
|
|
190
|
-
queue.push({ id: dep.sourceId, level: level + 1 });
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
return {
|
|
195
|
-
rootModule: moduleId,
|
|
196
|
-
affectedModules,
|
|
197
|
-
depth,
|
|
198
|
-
};
|
|
102
|
+
return calculateImpactInGraph(this.graph, moduleId, depth);
|
|
199
103
|
}
|
|
200
104
|
async getStatistics() {
|
|
201
105
|
this.ensureInitialized();
|
|
202
|
-
|
|
203
|
-
return {
|
|
204
|
-
totalModules: this.graph.modules.length,
|
|
205
|
-
totalSymbols: this.graph.symbols.length,
|
|
206
|
-
totalDependencies: this.graph.dependencies.length,
|
|
207
|
-
totalLines,
|
|
208
|
-
averageComplexity: 0,
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
// ============================================
|
|
212
|
-
// 私有方法
|
|
213
|
-
// ============================================
|
|
214
|
-
createEmptyGraph() {
|
|
215
|
-
return {
|
|
216
|
-
project: {
|
|
217
|
-
id: '',
|
|
218
|
-
name: '',
|
|
219
|
-
rootPath: this.projectPath ?? '',
|
|
220
|
-
createdAt: new Date(),
|
|
221
|
-
updatedAt: new Date(),
|
|
222
|
-
},
|
|
223
|
-
modules: [],
|
|
224
|
-
symbols: [],
|
|
225
|
-
dependencies: [],
|
|
226
|
-
};
|
|
106
|
+
return getProjectStatisticsFromGraph(this.graph);
|
|
227
107
|
}
|
|
228
108
|
}
|
|
229
109
|
//# sourceMappingURL=MemoryStorage.js.map
|