toolnet-memory 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +28 -0
- package/README.md +147 -0
- package/bin/toolnet-memory +415 -0
- package/dist/packages/cli/commands.js +1 -0
- package/dist/packages/cli/index.js +1 -0
- package/dist/packages/sdk/client.js +78 -0
- package/dist/packages/sdk/index.js +1 -0
- package/dist/packages/sdk/types.js +1 -0
- package/dist/src/api/index.js +1 -0
- package/dist/src/api/routes/health.js +1 -0
- package/dist/src/api/routes/index.js +1 -0
- package/dist/src/api/routes/memory.js +1 -0
- package/dist/src/api/routes/projects.js +1 -0
- package/dist/src/api/routes/search.js +1 -0
- package/dist/src/api/server.js +1 -0
- package/dist/src/capture/activity-capture.js +21 -0
- package/dist/src/capture/command-capture.js +12 -0
- package/dist/src/capture/error-capture.js +14 -0
- package/dist/src/capture/event-deduplicator.js +28 -0
- package/dist/src/capture/event-queue.js +20 -0
- package/dist/src/capture/file-capture.js +23 -0
- package/dist/src/capture/index.js +8 -0
- package/dist/src/capture/session-capture.js +18 -0
- package/dist/src/capture/tool-capture.js +13 -0
- package/dist/src/code-intelligence/analysis/analysis-engine.js +26 -0
- package/dist/src/code-intelligence/analysis/dead-code-analyzer.js +127 -0
- package/dist/src/code-intelligence/analysis/dependency-analyzer.js +66 -0
- package/dist/src/code-intelligence/analysis/index.js +4 -0
- package/dist/src/code-intelligence/analysis/types.js +1 -0
- package/dist/src/code-intelligence/architecture/architecture-engine.js +48 -0
- package/dist/src/code-intelligence/architecture/clusters.js +322 -0
- package/dist/src/code-intelligence/architecture/entry-points.js +150 -0
- package/dist/src/code-intelligence/architecture/hotspots.js +136 -0
- package/dist/src/code-intelligence/architecture/index.js +6 -0
- package/dist/src/code-intelligence/architecture/layers.js +197 -0
- package/dist/src/code-intelligence/architecture/types.js +1 -0
- package/dist/src/code-intelligence/chunks/index.js +2 -0
- package/dist/src/code-intelligence/chunks/smart-chunker.js +125 -0
- package/dist/src/code-intelligence/chunks/types.js +1 -0
- package/dist/src/code-intelligence/git/git-diff.js +109 -0
- package/dist/src/code-intelligence/git/index.js +1 -0
- package/dist/src/code-intelligence/graph/architecture.js +26 -0
- package/dist/src/code-intelligence/graph/graph-builder.js +213 -0
- package/dist/src/code-intelligence/graph/graph-store.js +57 -0
- package/dist/src/code-intelligence/graph/index.js +1 -0
- package/dist/src/code-intelligence/graph/relationships.js +1 -0
- package/dist/src/code-intelligence/graph/trace.js +65 -0
- package/dist/src/code-intelligence/impact/blast-radius.js +160 -0
- package/dist/src/code-intelligence/impact/change-mapper.js +69 -0
- package/dist/src/code-intelligence/impact/edit-tool-detector.js +92 -0
- package/dist/src/code-intelligence/impact/impact-analyzer.js +60 -0
- package/dist/src/code-intelligence/impact/impact-guard.js +33 -0
- package/dist/src/code-intelligence/impact/index.js +5 -0
- package/dist/src/code-intelligence/incremental/file-hash.js +8 -0
- package/dist/src/code-intelligence/incremental/incremental-indexer.js +106 -0
- package/dist/src/code-intelligence/incremental/manifest-builder.js +19 -0
- package/dist/src/code-intelligence/incremental/manifest.js +31 -0
- package/dist/src/code-intelligence/index.js +23 -0
- package/dist/src/code-intelligence/indexer/file-watcher.js +1 -0
- package/dist/src/code-intelligence/indexer/incremental-indexer.js +1 -0
- package/dist/src/code-intelligence/indexer/index.js +1 -0
- package/dist/src/code-intelligence/indexer/repository-indexer.js +31 -0
- package/dist/src/code-intelligence/indexer/repository-scanner.js +50 -0
- package/dist/src/code-intelligence/parsers/index.js +1 -0
- package/dist/src/code-intelligence/parsers/tree-sitter/index.js +1 -0
- package/dist/src/code-intelligence/parsers/tree-sitter/languages.js +1 -0
- package/dist/src/code-intelligence/parsers/tree-sitter/parser.js +1 -0
- package/dist/src/code-intelligence/parsers/typescript-parser.js +190 -0
- package/dist/src/code-intelligence/query/graph-query-engine.js +275 -0
- package/dist/src/code-intelligence/query/index.js +2 -0
- package/dist/src/code-intelligence/query/types.js +1 -0
- package/dist/src/code-intelligence/resolution/index.js +2 -0
- package/dist/src/code-intelligence/resolution/types.js +1 -0
- package/dist/src/code-intelligence/resolution/typescript-resolver.js +316 -0
- package/dist/src/code-intelligence/rich/index.js +1 -0
- package/dist/src/code-intelligence/rich/rich-graph-enricher.js +463 -0
- package/dist/src/code-intelligence/semantic/index.js +2 -0
- package/dist/src/code-intelligence/semantic/semantic-code-engine.js +213 -0
- package/dist/src/code-intelligence/semantic/source-priority.js +22 -0
- package/dist/src/code-intelligence/symbols/index.js +1 -0
- package/dist/src/code-intelligence/symbols/reference-resolver.js +21 -0
- package/dist/src/code-intelligence/symbols/symbol-extractor.js +1 -0
- package/dist/src/code-intelligence/test-analysis.js +72 -0
- package/dist/src/code-intelligence/test-architecture.js +67 -0
- package/dist/src/code-intelligence/test-impact.js +47 -0
- package/dist/src/code-intelligence/test-incremental.js +24 -0
- package/dist/src/code-intelligence/test-index.js +39 -0
- package/dist/src/code-intelligence/test-resolution.js +54 -0
- package/dist/src/code-intelligence/test-rich-graph.js +48 -0
- package/dist/src/code-intelligence/test-semantic.js +57 -0
- package/dist/src/code-intelligence/test-visualization.js +36 -0
- package/dist/src/code-intelligence/types.js +1 -0
- package/dist/src/code-intelligence/visualization/index.js +2 -0
- package/dist/src/code-intelligence/visualization/types.js +1 -0
- package/dist/src/code-intelligence/visualization/visualization-builder.js +104 -0
- package/dist/src/core/config.js +66 -0
- package/dist/src/core/global-env.js +70 -0
- package/dist/src/core/importance.js +30 -0
- package/dist/src/core/index.js +5 -0
- package/dist/src/core/memory-engine.js +183 -0
- package/dist/src/core/project-manager.js +243 -0
- package/dist/src/core/types.js +1 -0
- package/dist/src/embeddings/batch-embedder.js +1 -0
- package/dist/src/embeddings/cache.js +1 -0
- package/dist/src/embeddings/embedder.js +51 -0
- package/dist/src/embeddings/index.js +4 -0
- package/dist/src/embeddings/local.js +37 -0
- package/dist/src/embeddings/provider.js +1 -0
- package/dist/src/embeddings/remote.js +76 -0
- package/dist/src/embeddings/test-connection.js +16 -0
- package/dist/src/hooks/after-edit.js +3 -0
- package/dist/src/hooks/after-tool.js +3 -0
- package/dist/src/hooks/auto-context.js +68 -0
- package/dist/src/hooks/auto-impact-guard.js +94 -0
- package/dist/src/hooks/auto-retrieval.js +27 -0
- package/dist/src/hooks/before-agent.js +18 -0
- package/dist/src/hooks/before-compact.js +3 -0
- package/dist/src/hooks/before-edit.js +20 -0
- package/dist/src/hooks/index.js +11 -0
- package/dist/src/hooks/runtime.js +110 -0
- package/dist/src/hooks/session-end.js +3 -0
- package/dist/src/hooks/session-start.js +3 -0
- package/dist/src/index.js +22 -0
- package/dist/src/mcp/bootstrap.js +68 -0
- package/dist/src/mcp/context.js +1 -0
- package/dist/src/mcp/index.js +3 -0
- package/dist/src/mcp/server.js +45 -0
- package/dist/src/mcp/tools/analyze-impact.js +41 -0
- package/dist/src/mcp/tools/dead-code.js +55 -0
- package/dist/src/mcp/tools/find-callers.js +24 -0
- package/dist/src/mcp/tools/find-dependencies.js +57 -0
- package/dist/src/mcp/tools/find-symbol.js +7 -0
- package/dist/src/mcp/tools/get-architecture.js +11 -0
- package/dist/src/mcp/tools/graph-dependents.js +24 -0
- package/dist/src/mcp/tools/graph-neighborhood.js +58 -0
- package/dist/src/mcp/tools/graph-path.js +43 -0
- package/dist/src/mcp/tools/graph-query-utils.js +32 -0
- package/dist/src/mcp/tools/impact-guard.js +34 -0
- package/dist/src/mcp/tools/index-repository.js +1 -0
- package/dist/src/mcp/tools/index.js +20 -0
- package/dist/src/mcp/tools/memory-decisions.js +1 -0
- package/dist/src/mcp/tools/memory-forget.js +14 -0
- package/dist/src/mcp/tools/memory-recent.js +1 -0
- package/dist/src/mcp/tools/memory-remember.js +33 -0
- package/dist/src/mcp/tools/memory-rules.js +1 -0
- package/dist/src/mcp/tools/memory-search.js +18 -0
- package/dist/src/mcp/tools/memory-todos.js +1 -0
- package/dist/src/mcp/tools/project-context.js +25 -0
- package/dist/src/mcp/tools/search-code.js +21 -0
- package/dist/src/mcp/tools/semantic-code-search.js +33 -0
- package/dist/src/mcp/tools/snapshot-create.js +13 -0
- package/dist/src/mcp/tools/snapshot-list.js +7 -0
- package/dist/src/mcp/tools/snapshot-restore.js +13 -0
- package/dist/src/mcp/tools/trace-calls.js +37 -0
- package/dist/src/memory/activity.js +5 -0
- package/dist/src/memory/conflict-detector.js +105 -0
- package/dist/src/memory/consolidator.js +104 -0
- package/dist/src/memory/decay.js +59 -0
- package/dist/src/memory/decisions.js +3 -0
- package/dist/src/memory/deduplicate.js +25 -0
- package/dist/src/memory/index.js +11 -0
- package/dist/src/memory/maintenance.js +16 -0
- package/dist/src/memory/remember.js +3 -0
- package/dist/src/memory/rules.js +3 -0
- package/dist/src/memory/search.js +3 -0
- package/dist/src/memory/summaries.js +1 -0
- package/dist/src/memory/todos.js +3 -0
- package/dist/src/processor/decision-extractor.js +13 -0
- package/dist/src/processor/importance-scorer.js +22 -0
- package/dist/src/processor/index.js +7 -0
- package/dist/src/processor/memory-extractor.js +59 -0
- package/dist/src/processor/memory-processor.js +105 -0
- package/dist/src/processor/rule-extractor.js +13 -0
- package/dist/src/processor/summarizer.js +71 -0
- package/dist/src/processor/todo-extractor.js +12 -0
- package/dist/src/production/config-check.js +34 -0
- package/dist/src/production/doctor.js +58 -0
- package/dist/src/production/full-index.js +114 -0
- package/dist/src/production/health.js +58 -0
- package/dist/src/production/index-pipeline.js +151 -0
- package/dist/src/production/index.js +4 -0
- package/dist/src/production/project-lock.js +95 -0
- package/dist/src/production/project-status.js +16 -0
- package/dist/src/production/recovery.js +15 -0
- package/dist/src/production/snapshot-cli.js +58 -0
- package/dist/src/project-manual/cli.js +77 -0
- package/dist/src/project-manual/index.js +2 -0
- package/dist/src/project-manual/manager.js +147 -0
- package/dist/src/project-manual/types.js +1 -0
- package/dist/src/retrieval/bm25/index.js +1 -0
- package/dist/src/retrieval/bm25/search.js +1 -0
- package/dist/src/retrieval/bm25.js +30 -0
- package/dist/src/retrieval/context-budget.js +1 -0
- package/dist/src/retrieval/context-builder.js +22 -0
- package/dist/src/retrieval/graph/index.js +1 -0
- package/dist/src/retrieval/graph/search.js +1 -0
- package/dist/src/retrieval/hybrid/hybrid-search.js +1 -0
- package/dist/src/retrieval/hybrid/index.js +1 -0
- package/dist/src/retrieval/hybrid-search.js +68 -0
- package/dist/src/retrieval/importance.js +16 -0
- package/dist/src/retrieval/index.js +12 -0
- package/dist/src/retrieval/query-analyzer.js +32 -0
- package/dist/src/retrieval/query-classifier.js +1 -0
- package/dist/src/retrieval/query-expansion.js +1 -0
- package/dist/src/retrieval/recency.js +12 -0
- package/dist/src/retrieval/reranker/index.js +1 -0
- package/dist/src/retrieval/reranker/reranker.js +1 -0
- package/dist/src/retrieval/retrieval-engine.js +17 -0
- package/dist/src/retrieval/tokenizer.js +9 -0
- package/dist/src/retrieval/type-priority.js +10 -0
- package/dist/src/retrieval/types.js +1 -0
- package/dist/src/retrieval/vector/index.js +4 -0
- package/dist/src/retrieval/vector/metadata-filter.js +1 -0
- package/dist/src/retrieval/vector/persistence.js +67 -0
- package/dist/src/retrieval/vector/search.js +12 -0
- package/dist/src/retrieval/vector/test-persistence.js +36 -0
- package/dist/src/retrieval/vector/upsert.js +40 -0
- package/dist/src/retrieval/vector/vector-store.js +89 -0
- package/dist/src/retrieval/vector-hybrid-engine.js +91 -0
- package/dist/src/runtime/bootstrap.js +28 -0
- package/dist/src/runtime/graceful.js +17 -0
- package/dist/src/runtime/index.js +3 -0
- package/dist/src/runtime/toolnet-memory-runtime.js +156 -0
- package/dist/src/security/encryption.js +1 -0
- package/dist/src/security/file-filter.js +30 -0
- package/dist/src/security/index.js +3 -0
- package/dist/src/security/sanitizer.js +49 -0
- package/dist/src/security/secret-scanner.js +56 -0
- package/dist/src/session/agy/adapter.js +159 -0
- package/dist/src/session/agy/cli.js +87 -0
- package/dist/src/session/agy/hook-installer.js +62 -0
- package/dist/src/session/agy/hook.js +167 -0
- package/dist/src/session/agy/index.js +5 -0
- package/dist/src/session/agy/project-resolver.js +27 -0
- package/dist/src/session/agy/recovery.js +112 -0
- package/dist/src/session/agy/transcript.js +191 -0
- package/dist/src/session/codex/adapter.js +138 -0
- package/dist/src/session/codex/cli.js +236 -0
- package/dist/src/session/codex/context-hook-installer.js +70 -0
- package/dist/src/session/codex/context-hook.js +69 -0
- package/dist/src/session/codex/discovery.js +138 -0
- package/dist/src/session/codex/index.js +6 -0
- package/dist/src/session/codex/notify-installer.js +135 -0
- package/dist/src/session/codex/project-resolver.js +25 -0
- package/dist/src/session/codex/recovery.js +27 -0
- package/dist/src/session/codex/rollout.js +186 -0
- package/dist/src/session/core.js +239 -0
- package/dist/src/session/identity.js +57 -0
- package/dist/src/session/index.js +9 -0
- package/dist/src/session/learner/cli.js +62 -0
- package/dist/src/session/learner/extractor.js +461 -0
- package/dist/src/session/learner/index.js +4 -0
- package/dist/src/session/learner/journal.js +159 -0
- package/dist/src/session/learner/learner.js +124 -0
- package/dist/src/session/learner/types.js +1 -0
- package/dist/src/session/opencode/adapter.js +553 -0
- package/dist/src/session/opencode/cli.js +121 -0
- package/dist/src/session/opencode/index.js +2 -0
- package/dist/src/session/opencode/plugin-installer.js +230 -0
- package/dist/src/session/store.js +242 -0
- package/dist/src/session/types.js +1 -0
- package/dist/src/session/utils.js +47 -0
- package/dist/src/session/wal.js +303 -0
- package/dist/src/snapshot/index.js +2 -0
- package/dist/src/snapshot/manager.js +130 -0
- package/dist/src/snapshot/test-snapshot.js +28 -0
- package/dist/src/snapshot/types.js +1 -0
- package/dist/src/storage/architecture-store.js +37 -0
- package/dist/src/storage/cleanup-health.js +20 -0
- package/dist/src/storage/code-analysis-store.js +35 -0
- package/dist/src/storage/code-chunk-store.js +25 -0
- package/dist/src/storage/code-graph-store.js +24 -0
- package/dist/src/storage/code-manifest-store.js +24 -0
- package/dist/src/storage/code-vector-store.js +25 -0
- package/dist/src/storage/github/client.js +1 -0
- package/dist/src/storage/github/index.js +1 -0
- package/dist/src/storage/google-drive/client.js +1 -0
- package/dist/src/storage/google-drive/index.js +1 -0
- package/dist/src/storage/huggingface/client.js +116 -0
- package/dist/src/storage/huggingface/index.js +1 -0
- package/dist/src/storage/index.js +16 -0
- package/dist/src/storage/list-bucket-raw.js +14 -0
- package/dist/src/storage/list-bucket-tree.js +38 -0
- package/dist/src/storage/local/client.js +99 -0
- package/dist/src/storage/local/index.js +1 -0
- package/dist/src/storage/memory-store.js +30 -0
- package/dist/src/storage/project/cleanup-layout-v1.js +72 -0
- package/dist/src/storage/project/folder.js +15 -0
- package/dist/src/storage/project/index.js +3 -0
- package/dist/src/storage/project/layout.js +74 -0
- package/dist/src/storage/project/migrate-layout-v2.js +101 -0
- package/dist/src/storage/project/migrate.js +73 -0
- package/dist/src/storage/project/scoped-provider.js +165 -0
- package/dist/src/storage/provider.js +26 -0
- package/dist/src/storage/retrying-provider.js +23 -0
- package/dist/src/storage/test-connection.js +32 -0
- package/dist/src/storage/type-resolution-store.js +26 -0
- package/dist/src/storage/types.js +1 -0
- package/dist/src/storage/vector-store.js +30 -0
- package/dist/src/storage/visualization-store.js +25 -0
- package/dist/src/sync/compressor.js +1 -0
- package/dist/src/sync/conflict-resolver.js +1 -0
- package/dist/src/sync/downloader.js +1 -0
- package/dist/src/sync/index.js +1 -0
- package/dist/src/sync/sync-engine.js +1 -0
- package/dist/src/sync/upload-queue.js +1 -0
- package/dist/src/utils/retry.js +29 -0
- package/dist/src/visualization/server.js +270 -0
- package/dist/src/work-continuity/brief-cache.js +107 -0
- package/dist/src/work-continuity/brief.js +349 -0
- package/dist/src/work-continuity/cli.js +96 -0
- package/dist/src/work-continuity/context-cli.js +106 -0
- package/dist/src/work-continuity/context-runtime-cli.js +88 -0
- package/dist/src/work-continuity/extractor.js +339 -0
- package/dist/src/work-continuity/handoff.js +185 -0
- package/dist/src/work-continuity/index.js +14 -0
- package/dist/src/work-continuity/injection.js +84 -0
- package/dist/src/work-continuity/journal.js +49 -0
- package/dist/src/work-continuity/learner.js +127 -0
- package/dist/src/work-continuity/reducer.js +316 -0
- package/dist/src/work-continuity/semantic-extractor.js +360 -0
- package/dist/src/work-continuity/semantic-journal.js +55 -0
- package/dist/src/work-continuity/semantic-learner.js +125 -0
- package/dist/src/work-continuity/semantic-reducer.js +268 -0
- package/dist/src/work-continuity/semantic-types.js +1 -0
- package/dist/src/work-continuity/types.js +1 -0
- package/dist/visualization/public/index.html +2896 -0
- package/dist/visualization/public/vendor/3d-force-graph.min.js +5 -0
- package/package.json +69 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export class ReferenceResolver {
|
|
2
|
+
graph;
|
|
3
|
+
constructor(graph) {
|
|
4
|
+
this.graph = graph;
|
|
5
|
+
}
|
|
6
|
+
findSymbol(projectId, name) {
|
|
7
|
+
return this.graph.findByName(projectId, name);
|
|
8
|
+
}
|
|
9
|
+
findCallers(projectId, symbolId) {
|
|
10
|
+
const callerIds = this.graph
|
|
11
|
+
.allEdges(projectId)
|
|
12
|
+
.filter((edge) => edge.type ===
|
|
13
|
+
"CALLS" &&
|
|
14
|
+
edge.to ===
|
|
15
|
+
symbolId)
|
|
16
|
+
.map((edge) => edge.from);
|
|
17
|
+
return callerIds
|
|
18
|
+
.map((id) => this.graph.getSymbol(id))
|
|
19
|
+
.filter((symbol) => Boolean(symbol));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import "dotenv/config";
|
|
2
|
+
import { loadConfig, ProjectManager, } from "../core/index.js";
|
|
3
|
+
import { createStorageProvider, withStorageRetry, ProjectScopedStorageProvider, PersistentCodeAnalysisStore, PersistentCodeGraphStore, } from "../storage/index.js";
|
|
4
|
+
import { CodeAnalysisEngine, CodeGraphStore, GraphQueryEngine, } from "./index.js";
|
|
5
|
+
async function main() {
|
|
6
|
+
const config = loadConfig();
|
|
7
|
+
const project = new ProjectManager()
|
|
8
|
+
.detect();
|
|
9
|
+
const rawStorage = withStorageRetry(createStorageProvider({
|
|
10
|
+
provider: config.storage.provider,
|
|
11
|
+
huggingface: config.storage.huggingface,
|
|
12
|
+
localRoot: config.storage.localRoot,
|
|
13
|
+
}), {
|
|
14
|
+
attempts: 3,
|
|
15
|
+
});
|
|
16
|
+
const storage = new ProjectScopedStorageProvider(rawStorage, project.id, project.name, project.remote ?? project.name);
|
|
17
|
+
const graphSnapshot = await new PersistentCodeGraphStore(storage).load(project.id);
|
|
18
|
+
if (!graphSnapshot) {
|
|
19
|
+
throw new Error("Code graph missing");
|
|
20
|
+
}
|
|
21
|
+
const graph = new CodeGraphStore();
|
|
22
|
+
graph.import(graphSnapshot.symbols, graphSnapshot.edges);
|
|
23
|
+
const analysis = new CodeAnalysisEngine(graph).analyze(project.id);
|
|
24
|
+
await new PersistentCodeAnalysisStore(storage).save(analysis);
|
|
25
|
+
const query = new GraphQueryEngine(graph);
|
|
26
|
+
const memoryStore = query.findSymbols(project.id, "MemoryStore")[0];
|
|
27
|
+
console.log({
|
|
28
|
+
ok: true,
|
|
29
|
+
project: project.name,
|
|
30
|
+
summary: analysis.summary,
|
|
31
|
+
highConfidenceDeadCode: analysis.deadCode
|
|
32
|
+
.filter((item) => item.confidence ===
|
|
33
|
+
"high")
|
|
34
|
+
.slice(0, 20)
|
|
35
|
+
.map((item) => ({
|
|
36
|
+
symbol: item.qualifiedName ??
|
|
37
|
+
item.name,
|
|
38
|
+
type: item.type,
|
|
39
|
+
file: item.filePath,
|
|
40
|
+
line: item.startLine,
|
|
41
|
+
score: item.score,
|
|
42
|
+
})),
|
|
43
|
+
topDependencyHubs: analysis.dependencies
|
|
44
|
+
.slice()
|
|
45
|
+
.sort((a, b) => (b.incomingEdges +
|
|
46
|
+
b.outgoingEdges) -
|
|
47
|
+
(a.incomingEdges +
|
|
48
|
+
a.outgoingEdges))
|
|
49
|
+
.slice(0, 15)
|
|
50
|
+
.map((item) => ({
|
|
51
|
+
file: item.filePath,
|
|
52
|
+
dependencies: item.dependencies.length,
|
|
53
|
+
dependents: item.dependents.length,
|
|
54
|
+
incoming: item.incomingEdges,
|
|
55
|
+
outgoing: item.outgoingEdges,
|
|
56
|
+
})),
|
|
57
|
+
memoryStore: memoryStore
|
|
58
|
+
? {
|
|
59
|
+
symbol: memoryStore
|
|
60
|
+
.qualifiedName ??
|
|
61
|
+
memoryStore.name,
|
|
62
|
+
callers: query.callers(project.id, memoryStore.id).length,
|
|
63
|
+
dependents: query.dependents(project.id, memoryStore.id).length,
|
|
64
|
+
dependencies: query.dependencies(project.id, memoryStore.id).length,
|
|
65
|
+
}
|
|
66
|
+
: null,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
main().catch((error) => {
|
|
70
|
+
console.error(error);
|
|
71
|
+
process.exit(1);
|
|
72
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import "dotenv/config";
|
|
2
|
+
import { loadConfig, ProjectManager, } from "../core/index.js";
|
|
3
|
+
import { createStorageProvider, withStorageRetry, ProjectScopedStorageProvider, PersistentArchitectureStore, PersistentCodeGraphStore, } from "../storage/index.js";
|
|
4
|
+
import { ArchitectureEngine, CodeGraphStore, } from "./index.js";
|
|
5
|
+
async function main() {
|
|
6
|
+
const config = loadConfig();
|
|
7
|
+
const project = new ProjectManager()
|
|
8
|
+
.detect();
|
|
9
|
+
const rawStorage = withStorageRetry(createStorageProvider({
|
|
10
|
+
provider: config.storage.provider,
|
|
11
|
+
huggingface: config.storage.huggingface,
|
|
12
|
+
localRoot: config.storage.localRoot,
|
|
13
|
+
}), {
|
|
14
|
+
attempts: 3,
|
|
15
|
+
});
|
|
16
|
+
const storage = new ProjectScopedStorageProvider(rawStorage, project.id, project.name, project.remote ?? project.name);
|
|
17
|
+
const graphSnapshot = await new PersistentCodeGraphStore(storage).load(project.id);
|
|
18
|
+
if (!graphSnapshot) {
|
|
19
|
+
throw new Error("Code graph missing");
|
|
20
|
+
}
|
|
21
|
+
const graph = new CodeGraphStore();
|
|
22
|
+
graph.import(graphSnapshot.symbols, graphSnapshot.edges);
|
|
23
|
+
const architecture = new ArchitectureEngine(graph).analyze(project.id);
|
|
24
|
+
await new PersistentArchitectureStore(storage).save(architecture);
|
|
25
|
+
const layerCounts = architecture.layers
|
|
26
|
+
.reduce((result, item) => {
|
|
27
|
+
result[item.layer] =
|
|
28
|
+
(result[item.layer] ?? 0) + 1;
|
|
29
|
+
return result;
|
|
30
|
+
}, {});
|
|
31
|
+
console.log({
|
|
32
|
+
ok: true,
|
|
33
|
+
project: project.name,
|
|
34
|
+
summary: architecture.summary,
|
|
35
|
+
layers: layerCounts,
|
|
36
|
+
topEntryPoints: architecture.entryPoints
|
|
37
|
+
.slice(0, 10)
|
|
38
|
+
.map((item) => ({
|
|
39
|
+
kind: item.kind,
|
|
40
|
+
file: item.filePath,
|
|
41
|
+
name: item.name,
|
|
42
|
+
score: item.score,
|
|
43
|
+
})),
|
|
44
|
+
topHotspots: architecture.hotspots
|
|
45
|
+
.slice(0, 10)
|
|
46
|
+
.map((item) => ({
|
|
47
|
+
file: item.filePath,
|
|
48
|
+
score: item.score,
|
|
49
|
+
incoming: item.incoming,
|
|
50
|
+
outgoing: item.outgoing,
|
|
51
|
+
})),
|
|
52
|
+
largestClusters: architecture.clusters
|
|
53
|
+
.slice(0, 10)
|
|
54
|
+
.map((item) => ({
|
|
55
|
+
id: item.id,
|
|
56
|
+
label: item.label,
|
|
57
|
+
subsystem: item.subsystem,
|
|
58
|
+
size: item.size,
|
|
59
|
+
cohesion: item.cohesion,
|
|
60
|
+
sample: item.files.slice(0, 5),
|
|
61
|
+
})),
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
main().catch((error) => {
|
|
65
|
+
console.error(error);
|
|
66
|
+
process.exit(1);
|
|
67
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import "dotenv/config";
|
|
2
|
+
import { loadConfig, ProjectManager, } from "../core/index.js";
|
|
3
|
+
import { createStorageProvider, withStorageRetry, ProjectScopedStorageProvider, PersistentCodeGraphStore, } from "../storage/index.js";
|
|
4
|
+
import { CodeGraphStore, ImpactGuard, } from "./index.js";
|
|
5
|
+
async function main() {
|
|
6
|
+
const config = loadConfig();
|
|
7
|
+
const project = new ProjectManager()
|
|
8
|
+
.detect();
|
|
9
|
+
const raw = withStorageRetry(createStorageProvider({
|
|
10
|
+
provider: config.storage.provider,
|
|
11
|
+
huggingface: config.storage.huggingface,
|
|
12
|
+
localRoot: config.storage.localRoot,
|
|
13
|
+
}), {
|
|
14
|
+
attempts: 3,
|
|
15
|
+
});
|
|
16
|
+
const storage = new ProjectScopedStorageProvider(raw, project.id, project.name, project.remote ?? project.name);
|
|
17
|
+
const snapshot = await new PersistentCodeGraphStore(storage).load(project.id);
|
|
18
|
+
if (!snapshot) {
|
|
19
|
+
throw new Error("Code graph missing");
|
|
20
|
+
}
|
|
21
|
+
const graph = new CodeGraphStore();
|
|
22
|
+
graph.import(snapshot.symbols, snapshot.edges);
|
|
23
|
+
const guard = new ImpactGuard(graph);
|
|
24
|
+
const filePath = process.argv[2];
|
|
25
|
+
const result = filePath
|
|
26
|
+
? guard.analyzeFile(project.id, filePath)
|
|
27
|
+
: await guard.analyzeGitDiff(project.id, project.rootPath);
|
|
28
|
+
console.log({
|
|
29
|
+
risk: result.risk,
|
|
30
|
+
riskScore: result.riskScore,
|
|
31
|
+
changedSymbols: result.changedSymbols.map((item) => ({
|
|
32
|
+
symbol: item.symbol
|
|
33
|
+
.qualifiedName,
|
|
34
|
+
file: item.symbol
|
|
35
|
+
.filePath,
|
|
36
|
+
type: item.symbol
|
|
37
|
+
.type,
|
|
38
|
+
})),
|
|
39
|
+
impactedFiles: result.impactedFiles,
|
|
40
|
+
suggestedTests: result.suggestedTests,
|
|
41
|
+
impactedCount: result.impacted.length,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
main().catch((error) => {
|
|
45
|
+
console.error(error);
|
|
46
|
+
process.exit(1);
|
|
47
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import "dotenv/config";
|
|
2
|
+
import { loadConfig, ProjectManager, } from "../core/index.js";
|
|
3
|
+
import { createStorageProvider, ProjectScopedStorageProvider, } from "../storage/index.js";
|
|
4
|
+
import { IncrementalRepositoryIndexer, } from "./incremental/incremental-indexer.js";
|
|
5
|
+
async function main() {
|
|
6
|
+
const config = loadConfig();
|
|
7
|
+
const project = new ProjectManager().detect();
|
|
8
|
+
const rawStorage = createStorageProvider({
|
|
9
|
+
provider: config.storage.provider,
|
|
10
|
+
huggingface: config.storage.huggingface,
|
|
11
|
+
localRoot: config.storage.localRoot,
|
|
12
|
+
});
|
|
13
|
+
const storage = new ProjectScopedStorageProvider(rawStorage, project.id, project.name, project.remote ?? project.name);
|
|
14
|
+
const result = await new IncrementalRepositoryIndexer(storage).index(project.id, project.rootPath);
|
|
15
|
+
console.log({
|
|
16
|
+
ok: true,
|
|
17
|
+
storage: storage.name,
|
|
18
|
+
...result,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
main().catch((error) => {
|
|
22
|
+
console.error(error);
|
|
23
|
+
process.exit(1);
|
|
24
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import "dotenv/config";
|
|
2
|
+
import { loadConfig, ProjectManager, } from "../core/index.js";
|
|
3
|
+
import { RepositoryIndexer, getArchitecture, } from "./index.js";
|
|
4
|
+
import { createStorageProvider, PersistentCodeGraphStore, ProjectScopedStorageProvider, } from "../storage/index.js";
|
|
5
|
+
async function main() {
|
|
6
|
+
const config = loadConfig();
|
|
7
|
+
const project = new ProjectManager()
|
|
8
|
+
.detect();
|
|
9
|
+
const rawStorage = createStorageProvider({
|
|
10
|
+
provider: config.storage.provider,
|
|
11
|
+
huggingface: config.storage.huggingface,
|
|
12
|
+
localRoot: config.storage.localRoot,
|
|
13
|
+
});
|
|
14
|
+
const storage = new ProjectScopedStorageProvider(rawStorage, project.id, project.name, project.remote ?? project.name);
|
|
15
|
+
const result = await new RepositoryIndexer()
|
|
16
|
+
.index(project.id, project.rootPath);
|
|
17
|
+
const architecture = getArchitecture(result.graph, project.id);
|
|
18
|
+
const persistent = new PersistentCodeGraphStore(storage);
|
|
19
|
+
await persistent.save({
|
|
20
|
+
version: 1,
|
|
21
|
+
projectId: project.id,
|
|
22
|
+
updatedAt: new Date()
|
|
23
|
+
.toISOString(),
|
|
24
|
+
files: result.files,
|
|
25
|
+
symbols: result.graph
|
|
26
|
+
.allSymbols(project.id),
|
|
27
|
+
edges: result.graph
|
|
28
|
+
.allEdges(project.id),
|
|
29
|
+
});
|
|
30
|
+
console.log({
|
|
31
|
+
ok: true,
|
|
32
|
+
storage: storage.name,
|
|
33
|
+
...architecture,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
main().catch((error) => {
|
|
37
|
+
console.error(error);
|
|
38
|
+
process.exit(1);
|
|
39
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import "dotenv/config";
|
|
2
|
+
import { loadConfig, ProjectManager, } from "../core/index.js";
|
|
3
|
+
import { createStorageProvider, withStorageRetry, ProjectScopedStorageProvider, PersistentCodeGraphStore, PersistentTypeResolutionStore, } from "../storage/index.js";
|
|
4
|
+
import { CodeGraphStore, TypeScriptTypeResolver, } from "./index.js";
|
|
5
|
+
async function main() {
|
|
6
|
+
const config = loadConfig();
|
|
7
|
+
const project = new ProjectManager()
|
|
8
|
+
.detect();
|
|
9
|
+
const rawStorage = withStorageRetry(createStorageProvider({
|
|
10
|
+
provider: config.storage.provider,
|
|
11
|
+
huggingface: config.storage.huggingface,
|
|
12
|
+
localRoot: config.storage.localRoot,
|
|
13
|
+
}), {
|
|
14
|
+
attempts: 3,
|
|
15
|
+
});
|
|
16
|
+
const storage = new ProjectScopedStorageProvider(rawStorage, project.id, project.name, project.remote ?? project.name);
|
|
17
|
+
const graphSnapshot = await new PersistentCodeGraphStore(storage).load(project.id);
|
|
18
|
+
if (!graphSnapshot) {
|
|
19
|
+
throw new Error("Code graph missing. Run code:index:test first.");
|
|
20
|
+
}
|
|
21
|
+
const graph = new CodeGraphStore();
|
|
22
|
+
graph.import(graphSnapshot.symbols, graphSnapshot.edges);
|
|
23
|
+
const resolver = new TypeScriptTypeResolver(graph);
|
|
24
|
+
const resolution = await resolver.resolveProject(project.id, project.rootPath);
|
|
25
|
+
await new PersistentTypeResolutionStore(storage).save(resolution);
|
|
26
|
+
console.log({
|
|
27
|
+
ok: true,
|
|
28
|
+
project: project.name,
|
|
29
|
+
total: resolution.total,
|
|
30
|
+
exact: resolution.exact,
|
|
31
|
+
high: resolution.high,
|
|
32
|
+
fallback: resolution.fallback,
|
|
33
|
+
exactRate: resolution.total
|
|
34
|
+
? Number(((resolution.exact /
|
|
35
|
+
resolution.total) *
|
|
36
|
+
100).toFixed(2))
|
|
37
|
+
: 0,
|
|
38
|
+
samples: resolution.resolutions
|
|
39
|
+
.filter((item) => item.targetFile)
|
|
40
|
+
.slice(0, 10)
|
|
41
|
+
.map((item) => ({
|
|
42
|
+
expression: item.expression,
|
|
43
|
+
from: `${item.sourceFile}:${item.sourceLine}`,
|
|
44
|
+
to: `${item.targetFile}:${item.targetLine ?? "?"}`,
|
|
45
|
+
target: item.targetQualifiedName ??
|
|
46
|
+
item.targetName,
|
|
47
|
+
confidence: item.confidence,
|
|
48
|
+
})),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
main().catch((error) => {
|
|
52
|
+
console.error(error);
|
|
53
|
+
process.exit(1);
|
|
54
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import "dotenv/config";
|
|
2
|
+
import { loadConfig, ProjectManager, } from "../core/index.js";
|
|
3
|
+
import { createStorageProvider, withStorageRetry, ProjectScopedStorageProvider, PersistentCodeGraphStore, PersistentTypeResolutionStore, } from "../storage/index.js";
|
|
4
|
+
import { CodeGraphStore, RichGraphEnricher, getArchitecture, } from "./index.js";
|
|
5
|
+
async function main() {
|
|
6
|
+
const config = loadConfig();
|
|
7
|
+
const project = new ProjectManager()
|
|
8
|
+
.detect();
|
|
9
|
+
const raw = withStorageRetry(createStorageProvider({
|
|
10
|
+
provider: config.storage.provider,
|
|
11
|
+
huggingface: config.storage.huggingface,
|
|
12
|
+
localRoot: config.storage.localRoot,
|
|
13
|
+
}), {
|
|
14
|
+
attempts: 3,
|
|
15
|
+
});
|
|
16
|
+
const storage = new ProjectScopedStorageProvider(raw, project.id, project.name, project.remote ?? project.name);
|
|
17
|
+
const store = new PersistentCodeGraphStore(storage);
|
|
18
|
+
const snapshot = await store.load(project.id);
|
|
19
|
+
if (!snapshot) {
|
|
20
|
+
throw new Error("Code graph missing");
|
|
21
|
+
}
|
|
22
|
+
const graph = new CodeGraphStore();
|
|
23
|
+
graph.import(snapshot.symbols, snapshot.edges);
|
|
24
|
+
const resolution = await new PersistentTypeResolutionStore(storage).load(project.id);
|
|
25
|
+
const stats = new RichGraphEnricher(graph).enrich(project.id, project.rootPath, resolution);
|
|
26
|
+
const symbols = graph.allSymbols(project.id);
|
|
27
|
+
const edges = graph.allEdges(project.id);
|
|
28
|
+
await store.save({
|
|
29
|
+
version: 1,
|
|
30
|
+
projectId: project.id,
|
|
31
|
+
updatedAt: new Date()
|
|
32
|
+
.toISOString(),
|
|
33
|
+
files: symbols.filter((item) => item.type ===
|
|
34
|
+
"file").length,
|
|
35
|
+
symbols,
|
|
36
|
+
edges,
|
|
37
|
+
});
|
|
38
|
+
console.log({
|
|
39
|
+
ok: true,
|
|
40
|
+
project: project.name,
|
|
41
|
+
added: stats,
|
|
42
|
+
architecture: getArchitecture(graph, project.id),
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
main().catch((error) => {
|
|
46
|
+
console.error(error);
|
|
47
|
+
process.exit(1);
|
|
48
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import "dotenv/config";
|
|
2
|
+
import { loadConfig, ProjectManager, } from "../core/index.js";
|
|
3
|
+
import { createStorageProvider, PersistentCodeGraphStore, ProjectScopedStorageProvider, } from "../storage/index.js";
|
|
4
|
+
import { CodeGraphStore, SemanticCodeEngine, } from "./index.js";
|
|
5
|
+
import { createEmbeddingProvider, } from "../embeddings/index.js";
|
|
6
|
+
async function main() {
|
|
7
|
+
const config = loadConfig();
|
|
8
|
+
const project = new ProjectManager()
|
|
9
|
+
.detect();
|
|
10
|
+
const rawStorage = createStorageProvider({
|
|
11
|
+
provider: config.storage.provider,
|
|
12
|
+
huggingface: config.storage.huggingface,
|
|
13
|
+
localRoot: config.storage.localRoot,
|
|
14
|
+
});
|
|
15
|
+
const storage = new ProjectScopedStorageProvider(rawStorage, project.id, project.name, project.remote ?? project.name);
|
|
16
|
+
const graph = new CodeGraphStore();
|
|
17
|
+
const snapshot = await new PersistentCodeGraphStore(storage).load(project.id);
|
|
18
|
+
if (!snapshot) {
|
|
19
|
+
throw new Error("Code graph missing. Run npm run code:index:test first.");
|
|
20
|
+
}
|
|
21
|
+
graph.import(snapshot.symbols, snapshot.edges);
|
|
22
|
+
const engine = new SemanticCodeEngine({
|
|
23
|
+
projectId: project.id,
|
|
24
|
+
rootPath: project.rootPath,
|
|
25
|
+
model: process.env
|
|
26
|
+
.HF_EMBEDDING_MODEL ??
|
|
27
|
+
"sentence-transformers/all-MiniLM-L6-v2",
|
|
28
|
+
storage,
|
|
29
|
+
embeddings: createEmbeddingProvider(),
|
|
30
|
+
graph,
|
|
31
|
+
});
|
|
32
|
+
const stats = await engine.initialize();
|
|
33
|
+
const query = process.argv
|
|
34
|
+
.slice(2)
|
|
35
|
+
.join(" ") ||
|
|
36
|
+
"memory storage hugging face";
|
|
37
|
+
const results = await engine.search(query, 5);
|
|
38
|
+
console.log({
|
|
39
|
+
ok: true,
|
|
40
|
+
query,
|
|
41
|
+
...stats,
|
|
42
|
+
results: results.map((item) => ({
|
|
43
|
+
score: Number(item.score
|
|
44
|
+
.toFixed(4)),
|
|
45
|
+
file: item.chunk.filePath,
|
|
46
|
+
symbol: item.chunk.symbolName,
|
|
47
|
+
lines: `${item.chunk.startLine}-${item.chunk.endLine}`,
|
|
48
|
+
preview: item.chunk.content
|
|
49
|
+
.replace(/\s+/g, " ")
|
|
50
|
+
.slice(0, 140),
|
|
51
|
+
})),
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
main().catch((error) => {
|
|
55
|
+
console.error(error);
|
|
56
|
+
process.exit(1);
|
|
57
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import "dotenv/config";
|
|
2
|
+
import { loadConfig, ProjectManager, } from "../core/index.js";
|
|
3
|
+
import { createStorageProvider, withStorageRetry, ProjectScopedStorageProvider, PersistentArchitectureStore, PersistentCodeAnalysisStore, PersistentCodeGraphStore, PersistentVisualizationStore, } from "../storage/index.js";
|
|
4
|
+
import { CodeGraphStore, VisualizationBuilder, } from "./index.js";
|
|
5
|
+
async function main() {
|
|
6
|
+
const config = loadConfig();
|
|
7
|
+
const project = new ProjectManager()
|
|
8
|
+
.detect();
|
|
9
|
+
const rawStorage = withStorageRetry(createStorageProvider({
|
|
10
|
+
provider: config.storage.provider,
|
|
11
|
+
huggingface: config.storage.huggingface,
|
|
12
|
+
localRoot: config.storage.localRoot,
|
|
13
|
+
}), {
|
|
14
|
+
attempts: 3,
|
|
15
|
+
});
|
|
16
|
+
const storage = new ProjectScopedStorageProvider(rawStorage, project.id, project.name, project.remote ?? project.name);
|
|
17
|
+
const graphSnapshot = await new PersistentCodeGraphStore(storage).load(project.id);
|
|
18
|
+
if (!graphSnapshot) {
|
|
19
|
+
throw new Error("Code graph missing");
|
|
20
|
+
}
|
|
21
|
+
const architecture = await new PersistentArchitectureStore(storage).load(project.id);
|
|
22
|
+
const analysis = await new PersistentCodeAnalysisStore(storage).load(project.id);
|
|
23
|
+
const graph = new CodeGraphStore();
|
|
24
|
+
graph.import(graphSnapshot.symbols, graphSnapshot.edges);
|
|
25
|
+
const visualization = new VisualizationBuilder(graph).build(project.id, architecture, analysis);
|
|
26
|
+
await new PersistentVisualizationStore(storage).save(visualization);
|
|
27
|
+
console.log({
|
|
28
|
+
ok: true,
|
|
29
|
+
project: project.name,
|
|
30
|
+
...visualization.summary,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
main().catch((error) => {
|
|
34
|
+
console.error(error);
|
|
35
|
+
process.exit(1);
|
|
36
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
export class VisualizationBuilder {
|
|
2
|
+
graph;
|
|
3
|
+
constructor(graph) {
|
|
4
|
+
this.graph = graph;
|
|
5
|
+
}
|
|
6
|
+
build(projectId, architecture, analysis) {
|
|
7
|
+
const symbols = this.graph.allSymbols(projectId);
|
|
8
|
+
const edges = this.graph.allEdges(projectId);
|
|
9
|
+
const layers = new Map(architecture
|
|
10
|
+
?.layers
|
|
11
|
+
.map((item) => [
|
|
12
|
+
item.filePath,
|
|
13
|
+
item.layer,
|
|
14
|
+
]) ??
|
|
15
|
+
[]);
|
|
16
|
+
const clusterByFile = new Map();
|
|
17
|
+
for (const cluster of architecture?.clusters ??
|
|
18
|
+
[]) {
|
|
19
|
+
for (const file of cluster.files) {
|
|
20
|
+
clusterByFile.set(file, {
|
|
21
|
+
id: cluster.id,
|
|
22
|
+
label: cluster.label,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const hotspotByFile = new Map(architecture
|
|
27
|
+
?.hotspots
|
|
28
|
+
.map((item) => [
|
|
29
|
+
item.filePath,
|
|
30
|
+
item.score,
|
|
31
|
+
]) ??
|
|
32
|
+
[]);
|
|
33
|
+
const deadCodeBySymbol = new Map(analysis
|
|
34
|
+
?.deadCode
|
|
35
|
+
.map((item) => [
|
|
36
|
+
item.symbolId,
|
|
37
|
+
{
|
|
38
|
+
confidence: item.confidence,
|
|
39
|
+
score: item.score,
|
|
40
|
+
},
|
|
41
|
+
]) ??
|
|
42
|
+
[]);
|
|
43
|
+
const incoming = new Map();
|
|
44
|
+
const outgoing = new Map();
|
|
45
|
+
for (const edge of edges) {
|
|
46
|
+
outgoing.set(edge.from, (outgoing.get(edge.from) ?? 0) + 1);
|
|
47
|
+
incoming.set(edge.to, (incoming.get(edge.to) ?? 0) + 1);
|
|
48
|
+
}
|
|
49
|
+
const nodes = symbols.map((symbol) => {
|
|
50
|
+
const cluster = clusterByFile.get(symbol.filePath);
|
|
51
|
+
return {
|
|
52
|
+
id: symbol.id,
|
|
53
|
+
name: symbol.name,
|
|
54
|
+
qualifiedName: symbol.qualifiedName,
|
|
55
|
+
type: symbol.type,
|
|
56
|
+
filePath: symbol.filePath,
|
|
57
|
+
layer: layers.get(symbol.filePath),
|
|
58
|
+
cluster: cluster?.id,
|
|
59
|
+
clusterLabel: cluster?.label,
|
|
60
|
+
hotspotScore: hotspotByFile.get(symbol.filePath),
|
|
61
|
+
deadCode: deadCodeBySymbol.get(symbol.id),
|
|
62
|
+
incoming: incoming.get(symbol.id) ?? 0,
|
|
63
|
+
outgoing: outgoing.get(symbol.id) ?? 0,
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
const symbolIds = new Set(nodes.map((node) => node.id));
|
|
67
|
+
const links = edges
|
|
68
|
+
.filter((edge) => symbolIds.has(edge.from) &&
|
|
69
|
+
symbolIds.has(edge.to))
|
|
70
|
+
.map((edge) => ({
|
|
71
|
+
source: edge.from,
|
|
72
|
+
target: edge.to,
|
|
73
|
+
type: edge.type,
|
|
74
|
+
confidence: typeof edge.metadata
|
|
75
|
+
?.confidence ===
|
|
76
|
+
"string"
|
|
77
|
+
? edge.metadata
|
|
78
|
+
.confidence
|
|
79
|
+
: undefined,
|
|
80
|
+
resolver: typeof edge.metadata
|
|
81
|
+
?.resolver ===
|
|
82
|
+
"string"
|
|
83
|
+
? edge.metadata
|
|
84
|
+
.resolver
|
|
85
|
+
: undefined,
|
|
86
|
+
}));
|
|
87
|
+
return {
|
|
88
|
+
version: 1,
|
|
89
|
+
projectId,
|
|
90
|
+
generatedAt: new Date()
|
|
91
|
+
.toISOString(),
|
|
92
|
+
summary: {
|
|
93
|
+
nodes: nodes.length,
|
|
94
|
+
links: links.length,
|
|
95
|
+
files: new Set(nodes.map((node) => node.filePath)).size,
|
|
96
|
+
clusters: new Set(nodes
|
|
97
|
+
.map((node) => node.cluster)
|
|
98
|
+
.filter(Boolean)).size,
|
|
99
|
+
},
|
|
100
|
+
nodes,
|
|
101
|
+
links,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import "./global-env.js";
|
|
2
|
+
function envBool(value, fallback) {
|
|
3
|
+
if (value === undefined) {
|
|
4
|
+
return fallback;
|
|
5
|
+
}
|
|
6
|
+
return [
|
|
7
|
+
"1",
|
|
8
|
+
"true",
|
|
9
|
+
"yes",
|
|
10
|
+
"on",
|
|
11
|
+
].includes(value.toLowerCase());
|
|
12
|
+
}
|
|
13
|
+
function envNumber(value, fallback) {
|
|
14
|
+
if (!value) {
|
|
15
|
+
return fallback;
|
|
16
|
+
}
|
|
17
|
+
const parsed = Number(value);
|
|
18
|
+
return Number.isFinite(parsed)
|
|
19
|
+
? parsed
|
|
20
|
+
: fallback;
|
|
21
|
+
}
|
|
22
|
+
export function loadConfig() {
|
|
23
|
+
return {
|
|
24
|
+
memory: {
|
|
25
|
+
autoCapture: envBool(process.env
|
|
26
|
+
.MEMORY_AUTO_CAPTURE, true),
|
|
27
|
+
autoRetrieve: envBool(process.env
|
|
28
|
+
.MEMORY_AUTO_RETRIEVE, true),
|
|
29
|
+
autoSummarize: envBool(process.env
|
|
30
|
+
.MEMORY_AUTO_SUMMARIZE, true),
|
|
31
|
+
autoSync: envBool(process.env
|
|
32
|
+
.MEMORY_AUTO_SYNC, true),
|
|
33
|
+
},
|
|
34
|
+
retrieval: {
|
|
35
|
+
maxCandidates: envNumber(process.env
|
|
36
|
+
.MEMORY_MAX_CANDIDATES, 50),
|
|
37
|
+
rerankTop: envNumber(process.env
|
|
38
|
+
.MEMORY_RERANK_TOP, 10),
|
|
39
|
+
finalContext: envNumber(process.env
|
|
40
|
+
.MEMORY_FINAL_CONTEXT, 5),
|
|
41
|
+
tokenBudget: envNumber(process.env
|
|
42
|
+
.MEMORY_TOKEN_BUDGET, 2000),
|
|
43
|
+
},
|
|
44
|
+
storage: {
|
|
45
|
+
provider: process.env
|
|
46
|
+
.MEMORY_STORAGE_PROVIDER ??
|
|
47
|
+
"huggingface",
|
|
48
|
+
huggingface: {
|
|
49
|
+
namespace: process.env
|
|
50
|
+
.HF_NAMESPACE,
|
|
51
|
+
bucket: process.env
|
|
52
|
+
.HF_BUCKET,
|
|
53
|
+
accessKeyId: process.env
|
|
54
|
+
.HF_S3_ACCESS_KEY_ID,
|
|
55
|
+
secretAccessKey: process.env
|
|
56
|
+
.HF_S3_SECRET_ACCESS_KEY,
|
|
57
|
+
},
|
|
58
|
+
localRoot: process.env
|
|
59
|
+
.MEMORY_LOCAL_STORAGE_PATH,
|
|
60
|
+
},
|
|
61
|
+
cache: {
|
|
62
|
+
maxMb: envNumber(process.env
|
|
63
|
+
.MEMORY_LOCAL_CACHE_MB, 200),
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|