claude-memory-layer 1.0.31 → 1.0.33
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 +9 -2
- package/dist/cli/index.js +1110 -72
- package/dist/cli/index.js.map +4 -4
- package/dist/core/index.js +414 -25
- package/dist/core/index.js.map +2 -2
- package/dist/hooks/post-tool-use.js +416 -27
- package/dist/hooks/post-tool-use.js.map +2 -2
- package/dist/hooks/semantic-daemon.js +416 -27
- package/dist/hooks/semantic-daemon.js.map +2 -2
- package/dist/hooks/session-end.js +416 -27
- package/dist/hooks/session-end.js.map +2 -2
- package/dist/hooks/session-start.js +416 -27
- package/dist/hooks/session-start.js.map +2 -2
- package/dist/hooks/stop.js +416 -27
- package/dist/hooks/stop.js.map +2 -2
- package/dist/hooks/user-prompt-submit.js +504 -34
- package/dist/hooks/user-prompt-submit.js.map +2 -2
- package/dist/index.js +416 -27
- package/dist/index.js.map +2 -2
- package/dist/mcp/index.js +407 -32
- package/dist/mcp/index.js.map +2 -2
- package/dist/server/api/index.js +850 -44
- package/dist/server/api/index.js.map +3 -3
- package/dist/server/index.js +1073 -64
- package/dist/server/index.js.map +3 -3
- package/dist/services/memory-service.js +416 -27
- package/dist/services/memory-service.js.map +2 -2
- package/dist/ui/assets/js/bootstrap.js +2 -0
- package/dist/ui/assets/js/overview.js +166 -3
- package/dist/ui/assets/js/state.js +3 -0
- package/dist/ui/index.html +20 -0
- package/dist/ui/style.css +193 -0
- package/package.json +15 -2
- package/scripts/postinstall-embedding-backend.cjs +16 -12
- package/AGENTS.md +0 -71
- package/CLAUDE.md +0 -30
- package/HANDOFF.md +0 -92
- package/Memo.txt +0 -558
- package/benchmarks/replay/anonymized-real-sessions.json +0 -48
- package/config/kpi-thresholds.json +0 -7
- package/context.md +0 -636
- package/docs/ARCHITECTURE_COMPARISON_AND_RECOMMENDATIONS.md +0 -627
- package/docs/HERMES_MEMORY_INGESTION_ANALYSIS.md +0 -440
- package/docs/MCP_MEMORY_SERVICE_COMPARATIVE_REVIEW.md +0 -271
- package/docs/MEMORY_USEFULNESS_AUDIT.md +0 -371
- package/docs/MEMORY_USEFULNESS_AUDIT_RAW.json +0 -80
- package/docs/MEMSEARCH_PROJECT_STRUCTURE_ANALYSIS.md +0 -333
- package/docs/MEMU_ADOPTION.md +0 -40
- package/docs/OPERATIONS.md +0 -18
- package/docs/PRODUCT_VALIDATION_MATRIX.md +0 -82
- package/docs/PROJECT_STRUCTURE_ANALYSIS.md +0 -421
- package/docs/REFACTORING_MILESTONES_AND_ISSUES.md +0 -501
- package/docs/REFACTORING_PLAN_THIN_CORE.md +0 -414
- package/docs/REFERENCE_PROJECT_ANALYSES.md +0 -25
- package/docs/SUPERLOCALMEMORY_PROJECT_STRUCTURE_ANALYSIS.md +0 -452
- package/docs/TARGET_ARCHITECTURE_AND_FOLDER_STRUCTURE.md +0 -446
- package/docs/architecture/comparison-index.md +0 -47
- package/docs/reports/codex-real-data-validation-20260505T040447Z.md +0 -46
- package/plan.md +0 -1642
- package/scripts/build.ts +0 -159
- package/scripts/bump-patch-version.sh +0 -18
- package/scripts/delete-unknown-projects.js +0 -154
- package/scripts/fix-sync-gap.js +0 -32
- package/scripts/generate-session-qrels.ts +0 -126
- package/scripts/heartbeat-memory-orchestrator.sh +0 -28
- package/scripts/replay-retrieval-benchmark.ts +0 -69
- package/scripts/report-sync-gap.js +0 -26
- package/scripts/review-queue-auto-resolve.js +0 -21
- package/scripts/sync-gap-auto-heal.sh +0 -17
- package/spec.md +0 -624
- package/specs/20260207-dashboard-upgrade/context.md +0 -38
- package/specs/20260207-dashboard-upgrade/spec.md +0 -96
- package/specs/citations-system/context.md +0 -243
- package/specs/citations-system/plan.md +0 -495
- package/specs/citations-system/spec.md +0 -371
- package/specs/endless-mode/context.md +0 -305
- package/specs/endless-mode/plan.md +0 -620
- package/specs/endless-mode/spec.md +0 -455
- package/specs/entity-edge-model/context.md +0 -401
- package/specs/entity-edge-model/plan.md +0 -459
- package/specs/entity-edge-model/spec.md +0 -391
- package/specs/evidence-aligner-v2/context.md +0 -401
- package/specs/evidence-aligner-v2/plan.md +0 -303
- package/specs/evidence-aligner-v2/spec.md +0 -312
- package/specs/mcp-desktop-integration/context.md +0 -278
- package/specs/mcp-desktop-integration/plan.md +0 -550
- package/specs/mcp-desktop-integration/spec.md +0 -494
- package/specs/memory-utilization-improvements/context.md +0 -145
- package/specs/memory-utilization-improvements/plan.md +0 -361
- package/specs/memory-utilization-improvements/spec.md +0 -361
- package/specs/post-tool-use-hook/context.md +0 -319
- package/specs/post-tool-use-hook/plan.md +0 -469
- package/specs/post-tool-use-hook/spec.md +0 -364
- package/specs/private-tags/context.md +0 -288
- package/specs/private-tags/plan.md +0 -412
- package/specs/private-tags/spec.md +0 -345
- package/specs/progressive-disclosure/context.md +0 -346
- package/specs/progressive-disclosure/plan.md +0 -663
- package/specs/progressive-disclosure/spec.md +0 -415
- package/specs/selective-tool-observation/context.md +0 -100
- package/specs/selective-tool-observation/plan.md +0 -158
- package/specs/selective-tool-observation/spec.md +0 -127
- package/specs/task-entity-system/context.md +0 -297
- package/specs/task-entity-system/plan.md +0 -301
- package/specs/task-entity-system/spec.md +0 -314
- package/specs/thin-core-refactor/context.md +0 -275
- package/specs/thin-core-refactor/plan.md +0 -536
- package/specs/thin-core-refactor/spec.md +0 -465
- package/specs/vector-outbox-v2/context.md +0 -470
- package/specs/vector-outbox-v2/plan.md +0 -562
- package/specs/vector-outbox-v2/spec.md +0 -466
- package/specs/web-viewer-ui/context.md +0 -384
- package/specs/web-viewer-ui/plan.md +0 -797
- package/specs/web-viewer-ui/spec.md +0 -516
- package/src/adapters/claude/capture/index.ts +0 -3
- package/src/adapters/claude/context/index.ts +0 -3
- package/src/adapters/claude/hooks/index.ts +0 -21
- package/src/adapters/claude/hooks/post-tool-use.ts +0 -239
- package/src/adapters/claude/hooks/prompt-injection-policy.ts +0 -104
- package/src/adapters/claude/hooks/semantic-daemon-client.ts +0 -209
- package/src/adapters/claude/hooks/semantic-daemon.ts +0 -283
- package/src/adapters/claude/hooks/session-end.ts +0 -59
- package/src/adapters/claude/hooks/session-start.ts +0 -73
- package/src/adapters/claude/hooks/stop.ts +0 -128
- package/src/adapters/claude/hooks/user-prompt-submit.ts +0 -361
- package/src/adapters/claude/index.ts +0 -4
- package/src/adapters/claude/transcript/index.ts +0 -4
- package/src/adapters/claude/transcript/transcript-reader.ts +0 -57
- package/src/adapters/claude/transcript/turn-reconstructor.ts +0 -65
- package/src/apps/cli/claude-settings-hooks.ts +0 -138
- package/src/apps/cli/codex-import-runner.ts +0 -125
- package/src/apps/cli/codex-validation-output.ts +0 -95
- package/src/apps/cli/hermes-import-runner.ts +0 -130
- package/src/apps/cli/hermes-validation-output.ts +0 -91
- package/src/apps/cli/index.ts +0 -1735
- package/src/apps/cli/mcp-install.ts +0 -106
- package/src/apps/cli/retrieval-disclosure-output.ts +0 -196
- package/src/apps/dashboard/assets/js/bootstrap.js +0 -244
- package/src/apps/dashboard/assets/js/chat.js +0 -373
- package/src/apps/dashboard/assets/js/disclosure.js +0 -232
- package/src/apps/dashboard/assets/js/modals.js +0 -298
- package/src/apps/dashboard/assets/js/overview.js +0 -655
- package/src/apps/dashboard/assets/js/state.js +0 -72
- package/src/apps/dashboard/assets/js/views.js +0 -468
- package/src/apps/dashboard/index.html +0 -543
- package/src/apps/dashboard/index.ts +0 -3
- package/src/apps/dashboard/style.css +0 -1750
- package/src/apps/index.ts +0 -5
- package/src/apps/server/api/chat.ts +0 -244
- package/src/apps/server/api/citations.ts +0 -105
- package/src/apps/server/api/events.ts +0 -137
- package/src/apps/server/api/health.ts +0 -53
- package/src/apps/server/api/index.ts +0 -26
- package/src/apps/server/api/projects.ts +0 -74
- package/src/apps/server/api/search.ts +0 -184
- package/src/apps/server/api/sessions.ts +0 -115
- package/src/apps/server/api/stats.ts +0 -723
- package/src/apps/server/api/turns.ts +0 -143
- package/src/apps/server/api/utils.ts +0 -65
- package/src/apps/server/index.ts +0 -111
- package/src/cli/index.ts +0 -3
- package/src/cli/retrieval-disclosure-output.ts +0 -2
- package/src/compat/index.ts +0 -5
- package/src/core/canonical-key.ts +0 -186
- package/src/core/citation-generator.ts +0 -63
- package/src/core/consolidated-store.ts +0 -356
- package/src/core/consolidation-worker.ts +0 -493
- package/src/core/context-formatter.ts +0 -276
- package/src/core/continuity-manager.ts +0 -341
- package/src/core/db-wrapper.ts +0 -64
- package/src/core/derive/fact-deriver.ts +0 -170
- package/src/core/derive/index.ts +0 -2
- package/src/core/derive/summary-deriver.ts +0 -76
- package/src/core/edge-repo.ts +0 -333
- package/src/core/embedder.ts +0 -4
- package/src/core/engine/embedding-maintenance-service.ts +0 -187
- package/src/core/engine/endless-memory-services.ts +0 -4
- package/src/core/engine/index.ts +0 -19
- package/src/core/engine/memory-engine-services.ts +0 -170
- package/src/core/engine/memory-ingest-service.ts +0 -317
- package/src/core/engine/memory-query-service.ts +0 -173
- package/src/core/engine/memory-runtime-service.ts +0 -162
- package/src/core/engine/memory-service-composition.ts +0 -231
- package/src/core/engine/retrieval-analytics-service.ts +0 -181
- package/src/core/engine/retrieval-disclosure-service.ts +0 -420
- package/src/core/engine/retrieval-orchestrator.ts +0 -377
- package/src/core/engine/retrieval-services.ts +0 -176
- package/src/core/engine/shared-memory-services.ts +0 -4
- package/src/core/entity-repo.ts +0 -349
- package/src/core/event-store.ts +0 -779
- package/src/core/evidence-aligner.ts +0 -635
- package/src/core/external-market-context.ts +0 -582
- package/src/core/graduation-worker.ts +0 -171
- package/src/core/graduation.ts +0 -377
- package/src/core/index.ts +0 -64
- package/src/core/ingest-interceptor.ts +0 -80
- package/src/core/markdown-mirror.ts +0 -70
- package/src/core/matcher.ts +0 -208
- package/src/core/md-mirror.ts +0 -92
- package/src/core/metadata-extractor.ts +0 -203
- package/src/core/model/memory-fact.ts +0 -30
- package/src/core/model/memory-rule.ts +0 -14
- package/src/core/model/memory-summary.ts +0 -21
- package/src/core/model/raw-event.ts +0 -28
- package/src/core/model/retrieval-result.ts +0 -35
- package/src/core/mongo-sync-config.ts +0 -165
- package/src/core/mongo-sync-worker.ts +0 -381
- package/src/core/privacy/filter.ts +0 -190
- package/src/core/privacy/index.ts +0 -20
- package/src/core/privacy/tag-parser.ts +0 -145
- package/src/core/product-validation-matrix.ts +0 -314
- package/src/core/progressive-retriever.ts +0 -414
- package/src/core/registry/project-path.ts +0 -54
- package/src/core/registry/session-registry.ts +0 -69
- package/src/core/replay-evaluator.ts +0 -625
- package/src/core/retrieval-benchmark.ts +0 -117
- package/src/core/retrieval-quality.ts +0 -109
- package/src/core/retriever.ts +0 -800
- package/src/core/session-qrels.ts +0 -360
- package/src/core/shared-event-store.ts +0 -114
- package/src/core/shared-promoter.ts +0 -249
- package/src/core/shared-store.ts +0 -289
- package/src/core/shared-vector-store.ts +0 -203
- package/src/core/sqlite-event-store.ts +0 -1846
- package/src/core/sqlite-wrapper.ts +0 -116
- package/src/core/sync-worker.ts +0 -228
- package/src/core/tag-taxonomy.ts +0 -51
- package/src/core/task/blocker-resolver.ts +0 -333
- package/src/core/task/index.ts +0 -9
- package/src/core/task/task-matcher.ts +0 -240
- package/src/core/task/task-projector.ts +0 -358
- package/src/core/task/task-resolver.ts +0 -421
- package/src/core/turn-state.ts +0 -207
- package/src/core/types.ts +0 -952
- package/src/core/vector-outbox.ts +0 -299
- package/src/core/vector-store.ts +0 -231
- package/src/core/vector-worker.ts +0 -521
- package/src/core/working-set-store.ts +0 -257
- package/src/extensions/endless-memory/endless-memory-services.ts +0 -350
- package/src/extensions/endless-memory/index.ts +0 -1
- package/src/extensions/index.ts +0 -5
- package/src/extensions/mcp/handlers.ts +0 -960
- package/src/extensions/mcp/index.ts +0 -48
- package/src/extensions/mcp/tools.ts +0 -252
- package/src/extensions/shared-memory/index.ts +0 -1
- package/src/extensions/shared-memory/shared-memory-services.ts +0 -211
- package/src/extensions/vector/embedder.ts +0 -234
- package/src/extensions/vector/index.ts +0 -1
- package/src/hooks/post-tool-use.ts +0 -9
- package/src/hooks/semantic-daemon-client.ts +0 -1
- package/src/hooks/semantic-daemon.ts +0 -11
- package/src/hooks/session-end.ts +0 -9
- package/src/hooks/session-start.ts +0 -9
- package/src/hooks/stop.ts +0 -9
- package/src/hooks/user-prompt-submit.ts +0 -9
- package/src/index.ts +0 -13
- package/src/mcp/handlers.ts +0 -2
- package/src/mcp/index.ts +0 -4
- package/src/mcp/tools.ts +0 -2
- package/src/server/api/chat.ts +0 -2
- package/src/server/api/citations.ts +0 -2
- package/src/server/api/events.ts +0 -2
- package/src/server/api/health.ts +0 -2
- package/src/server/api/index.ts +0 -2
- package/src/server/api/projects.ts +0 -2
- package/src/server/api/search.ts +0 -2
- package/src/server/api/sessions.ts +0 -2
- package/src/server/api/stats.ts +0 -2
- package/src/server/api/turns.ts +0 -2
- package/src/server/api/utils.ts +0 -2
- package/src/server/index.ts +0 -2
- package/src/services/bootstrap-organizer.ts +0 -463
- package/src/services/codex-session-history-importer.ts +0 -966
- package/src/services/hermes-session-history-importer.ts +0 -733
- package/src/services/memory-service-config.ts +0 -36
- package/src/services/memory-service-registry.ts +0 -150
- package/src/services/memory-service.ts +0 -688
- package/src/services/session-history-importer.ts +0 -629
- package/tests/README.md +0 -23
- package/tests/adapters/claude/claude-semantic-daemon-adapter.test.ts +0 -54
- package/tests/adapters/claude/claude-transcript-reconstructor.test.ts +0 -98
- package/tests/adapters/claude-hook-prompt-injection-policy.test.ts +0 -99
- package/tests/apps/app-layer-boundary.test.ts +0 -48
- package/tests/apps/claude-settings-hooks.test.ts +0 -107
- package/tests/apps/cli-disclosure-output.test.ts +0 -212
- package/tests/apps/codex-import-runner.test.ts +0 -99
- package/tests/apps/codex-validation-output.test.ts +0 -100
- package/tests/apps/hermes-import-runner.test.ts +0 -99
- package/tests/apps/mcp-install-command.test.ts +0 -59
- package/tests/apps/package-build-entrypoints.test.ts +0 -30
- package/tests/apps/postinstall-embedding-backend.test.ts +0 -185
- package/tests/apps/search-api-disclosure.test.ts +0 -162
- package/tests/apps/stats-api-lightweight.test.ts +0 -67
- package/tests/apps/ui-disclosure-output.test.ts +0 -140
- package/tests/core/bootstrap-organizer.test.ts +0 -111
- package/tests/core/canonical-key.test.ts +0 -101
- package/tests/core/codex-session-history-importer-validation.test.ts +0 -185
- package/tests/core/consolidation-worker.test.ts +0 -75
- package/tests/core/embedding-maintenance-service.test.ts +0 -282
- package/tests/core/evidence-aligner.test.ts +0 -152
- package/tests/core/external-market-context.test.ts +0 -209
- package/tests/core/fact-deriver.test.ts +0 -79
- package/tests/core/hermes-session-history-importer-validation.test.ts +0 -609
- package/tests/core/ingest-interceptor.test.ts +0 -38
- package/tests/core/markdown-mirror.test.ts +0 -85
- package/tests/core/matcher.test.ts +0 -112
- package/tests/core/md-mirror.test.ts +0 -50
- package/tests/core/memory-engine-services.test.ts +0 -240
- package/tests/core/memory-ingest-service.test.ts +0 -296
- package/tests/core/memory-query-service.test.ts +0 -129
- package/tests/core/memory-runtime-service.test.ts +0 -201
- package/tests/core/memory-service-composition.test.ts +0 -192
- package/tests/core/memory-service-config.test.ts +0 -41
- package/tests/core/memory-service-facade.test.ts +0 -30
- package/tests/core/memory-service-registry.test.ts +0 -206
- package/tests/core/product-validation-matrix.test.ts +0 -61
- package/tests/core/project-registry.test.ts +0 -78
- package/tests/core/replay-evaluator.test.ts +0 -181
- package/tests/core/retrieval-analytics-service.test.ts +0 -210
- package/tests/core/retrieval-benchmark.test.ts +0 -93
- package/tests/core/retrieval-disclosure-service.test.ts +0 -264
- package/tests/core/retrieval-orchestrator.test.ts +0 -403
- package/tests/core/retrieval-quality.test.ts +0 -31
- package/tests/core/retrieval-services.test.ts +0 -185
- package/tests/core/retriever-fallback-chain.test.ts +0 -223
- package/tests/core/retriever-strategy-scope.test.ts +0 -164
- package/tests/core/retriever.memu-adoption.test.ts +0 -122
- package/tests/core/session-history-importer-filter.test.ts +0 -78
- package/tests/core/session-qrels.test.ts +0 -250
- package/tests/core/sqlite-event-store-replication.test.ts +0 -127
- package/tests/core/summary-deriver.test.ts +0 -66
- package/tests/extensions/embedder-warning-suppression.test.ts +0 -84
- package/tests/extensions/endless-memory-extension-boundary.test.ts +0 -17
- package/tests/extensions/endless-memory-services.test.ts +0 -325
- package/tests/extensions/mcp-context-tools.test.ts +0 -905
- package/tests/extensions/mcp-extension-boundary.test.ts +0 -21
- package/tests/extensions/mcp-package-build.test.ts +0 -22
- package/tests/extensions/mcp-project-aware-tools.test.ts +0 -102
- package/tests/extensions/shared-memory-extension-boundary.test.ts +0 -24
- package/tests/extensions/shared-memory-services.test.ts +0 -309
- package/tests/extensions/vector-extension-boundary.test.ts +0 -21
- package/tsconfig.json +0 -24
- package/vitest.config.ts +0 -15
|
@@ -1,463 +0,0 @@
|
|
|
1
|
-
import * as fs from 'node:fs';
|
|
2
|
-
import * as path from 'node:path';
|
|
3
|
-
import { execSync } from 'node:child_process';
|
|
4
|
-
|
|
5
|
-
export interface BootstrapKnowledgeOptions {
|
|
6
|
-
repoPath: string;
|
|
7
|
-
outDir: string;
|
|
8
|
-
since?: string;
|
|
9
|
-
maxCommits?: number;
|
|
10
|
-
incremental?: boolean;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
interface CommitInfo {
|
|
14
|
-
hash: string;
|
|
15
|
-
date: string;
|
|
16
|
-
author: string;
|
|
17
|
-
subject: string;
|
|
18
|
-
files: string[];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
interface ModuleSummary {
|
|
22
|
-
name: string;
|
|
23
|
-
root: string;
|
|
24
|
-
fileCount: number;
|
|
25
|
-
languages: string[];
|
|
26
|
-
entryCandidates: string[];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const EXCLUDED_DIRS = new Set(['.git', 'node_modules', 'dist', 'build', 'coverage', '.next', '.turbo', 'memory']);
|
|
30
|
-
const CODE_EXTENSIONS = new Set([
|
|
31
|
-
'.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs', '.py', '.go', '.rs', '.java', '.kt', '.swift', '.rb', '.php', '.cs',
|
|
32
|
-
'.scala', '.sh', '.zsh', '.yaml', '.yml', '.json', '.sql', '.md'
|
|
33
|
-
]);
|
|
34
|
-
|
|
35
|
-
function safeRel(base: string, target: string): string {
|
|
36
|
-
return path.relative(base, target).replaceAll('\\', '/');
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function mkdirp(dir: string): void {
|
|
40
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function walkCodeFiles(root: string): string[] {
|
|
44
|
-
const out: string[] = [];
|
|
45
|
-
|
|
46
|
-
function walk(dir: string): void {
|
|
47
|
-
const entries = fs.readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name));
|
|
48
|
-
|
|
49
|
-
for (const e of entries) {
|
|
50
|
-
const full = path.join(dir, e.name);
|
|
51
|
-
if (e.isDirectory()) {
|
|
52
|
-
if (!EXCLUDED_DIRS.has(e.name)) walk(full);
|
|
53
|
-
} else if (e.isFile()) {
|
|
54
|
-
const ext = path.extname(e.name).toLowerCase();
|
|
55
|
-
if (CODE_EXTENSIONS.has(ext)) out.push(full);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
walk(root);
|
|
61
|
-
return out.sort();
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function detectLanguage(file: string): string {
|
|
65
|
-
const ext = path.extname(file).toLowerCase();
|
|
66
|
-
const map: Record<string, string> = {
|
|
67
|
-
'.ts': 'TypeScript', '.tsx': 'TypeScript', '.js': 'JavaScript', '.jsx': 'JavaScript', '.mjs': 'JavaScript', '.cjs': 'JavaScript',
|
|
68
|
-
'.py': 'Python', '.go': 'Go', '.rs': 'Rust', '.java': 'Java', '.kt': 'Kotlin', '.swift': 'Swift', '.rb': 'Ruby', '.php': 'PHP',
|
|
69
|
-
'.cs': 'C#', '.scala': 'Scala', '.sh': 'Shell', '.zsh': 'Shell', '.yaml': 'YAML', '.yml': 'YAML', '.json': 'JSON', '.sql': 'SQL', '.md': 'Markdown'
|
|
70
|
-
};
|
|
71
|
-
return map[ext] || 'Other';
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function summarizeModules(repoPath: string, files: string[]): ModuleSummary[] {
|
|
75
|
-
const modules = new Map<string, { files: string[]; langs: Map<string, number> }>();
|
|
76
|
-
|
|
77
|
-
for (const abs of files) {
|
|
78
|
-
const rel = safeRel(repoPath, abs);
|
|
79
|
-
const seg = rel.split('/').filter(Boolean);
|
|
80
|
-
const top = seg[0] || 'root';
|
|
81
|
-
|
|
82
|
-
if (!modules.has(top)) modules.set(top, { files: [], langs: new Map() });
|
|
83
|
-
|
|
84
|
-
const bucket = modules.get(top)!;
|
|
85
|
-
bucket.files.push(rel);
|
|
86
|
-
|
|
87
|
-
const lang = detectLanguage(abs);
|
|
88
|
-
bucket.langs.set(lang, (bucket.langs.get(lang) || 0) + 1);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return [...modules.entries()]
|
|
92
|
-
.map(([name, data]) => ({
|
|
93
|
-
name,
|
|
94
|
-
root: name,
|
|
95
|
-
fileCount: data.files.length,
|
|
96
|
-
languages: [...data.langs.entries()].sort((a, b) => b[1] - a[1]).map(([l]) => l).slice(0, 5),
|
|
97
|
-
entryCandidates: data.files.filter((f) => /(index|main|app|server|cli)\./i.test(path.basename(f))).slice(0, 10)
|
|
98
|
-
}))
|
|
99
|
-
.sort((a, b) => b.fileCount - a.fileCount || a.name.localeCompare(b.name));
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function runGit(repoPath: string, command: string): string {
|
|
103
|
-
return execSync(`git -C ${JSON.stringify(repoPath)} ${command}`, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] });
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function parseGitLog(raw: string): CommitInfo[] {
|
|
107
|
-
const lines = raw.split(/\r?\n/);
|
|
108
|
-
const commits: CommitInfo[] = [];
|
|
109
|
-
let current: CommitInfo | null = null;
|
|
110
|
-
|
|
111
|
-
for (const line of lines) {
|
|
112
|
-
if (!line.trim()) {
|
|
113
|
-
if (current) {
|
|
114
|
-
commits.push(current);
|
|
115
|
-
current = null;
|
|
116
|
-
}
|
|
117
|
-
continue;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (line.includes('\t') && line.split('\t').length >= 4) {
|
|
121
|
-
if (current) commits.push(current);
|
|
122
|
-
const [hash, date, author, ...subjectRest] = line.split('\t');
|
|
123
|
-
current = { hash, date, author, subject: subjectRest.join('\t').trim(), files: [] };
|
|
124
|
-
} else if (current) {
|
|
125
|
-
current.files.push(line.trim());
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (current) commits.push(current);
|
|
130
|
-
return commits;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function getGitCommits(repoPath: string, since = '180 days ago', maxCommits = 1000): CommitInfo[] {
|
|
134
|
-
try {
|
|
135
|
-
const raw = runGit(
|
|
136
|
-
repoPath,
|
|
137
|
-
`log --since=${JSON.stringify(since)} -n ${Math.max(1, maxCommits)} --date=short --pretty=format:%H%x09%ad%x09%an%x09%s --name-only --reverse`
|
|
138
|
-
);
|
|
139
|
-
return parseGitLog(raw);
|
|
140
|
-
} catch {
|
|
141
|
-
return [];
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function getGitCommitsAfterHash(repoPath: string, hash: string, maxCommits = 1000): CommitInfo[] {
|
|
146
|
-
try {
|
|
147
|
-
const raw = runGit(
|
|
148
|
-
repoPath,
|
|
149
|
-
`log ${JSON.stringify(`${hash}..HEAD`)} -n ${Math.max(1, maxCommits)} --date=short --pretty=format:%H%x09%ad%x09%an%x09%s --name-only --reverse`
|
|
150
|
-
);
|
|
151
|
-
return parseGitLog(raw);
|
|
152
|
-
} catch {
|
|
153
|
-
return [];
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function extractDecisions(commits: CommitInfo[]): CommitInfo[] {
|
|
158
|
-
const decisionPattern = /(refactor|migrate|deprecat|remove|replace|introduce|adopt|switch|upgrade|breaking|architecture|feat|fix)/i;
|
|
159
|
-
return commits.filter((c) => decisionPattern.test(c.subject));
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
function buildTimeline(commits: CommitInfo[]): Map<string, CommitInfo[]> {
|
|
163
|
-
const timeline = new Map<string, CommitInfo[]>();
|
|
164
|
-
for (const c of commits) {
|
|
165
|
-
const key = (c.date || '').slice(0, 7) || 'unknown';
|
|
166
|
-
if (!timeline.has(key)) timeline.set(key, []);
|
|
167
|
-
timeline.get(key)!.push(c);
|
|
168
|
-
}
|
|
169
|
-
return new Map([...timeline.entries()].sort((a, b) => a[0].localeCompare(b[0])));
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
function buildGlossary(files: string[]): string[] {
|
|
173
|
-
const stop = new Set(['src', 'test', 'dist', 'lib', 'core', 'index', 'main', 'app', 'server', 'client', 'utils']);
|
|
174
|
-
const freq = new Map<string, number>();
|
|
175
|
-
|
|
176
|
-
for (const f of files) {
|
|
177
|
-
const base = path.basename(f, path.extname(f));
|
|
178
|
-
const tokens = base
|
|
179
|
-
.split(/[^a-zA-Z0-9]+/)
|
|
180
|
-
.flatMap((t) => t.split(/(?=[A-Z])/))
|
|
181
|
-
.map((t) => t.toLowerCase())
|
|
182
|
-
.filter((t) => t.length >= 3 && !stop.has(t));
|
|
183
|
-
|
|
184
|
-
for (const t of tokens) freq.set(t, (freq.get(t) || 0) + 1);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
return [...freq.entries()]
|
|
188
|
-
.filter(([, count]) => count >= 2)
|
|
189
|
-
.sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))
|
|
190
|
-
.slice(0, 80)
|
|
191
|
-
.map(([term]) => term);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
function writeFile(filePath: string, content: string): void {
|
|
195
|
-
mkdirp(path.dirname(filePath));
|
|
196
|
-
fs.writeFileSync(filePath, content, 'utf8');
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
function confidenceByEvidence(sourceCount: number): 'high' | 'mid' | 'low' {
|
|
200
|
-
if (sourceCount >= 3) return 'high';
|
|
201
|
-
if (sourceCount >= 1) return 'mid';
|
|
202
|
-
return 'low';
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
function sourceLine(source: string): string {
|
|
206
|
-
return `- source: ${source}`;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
interface ExistingManifest {
|
|
210
|
-
generatedAt?: string;
|
|
211
|
-
lastCommitDate?: string;
|
|
212
|
-
lastCommitHash?: string;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
function loadExistingManifest(outDir: string): ExistingManifest | null {
|
|
216
|
-
try {
|
|
217
|
-
const p = path.join(outDir, 'sources', 'manifest.json');
|
|
218
|
-
if (!fs.existsSync(p)) return null;
|
|
219
|
-
const data = JSON.parse(fs.readFileSync(p, 'utf8')) as ExistingManifest;
|
|
220
|
-
return data;
|
|
221
|
-
} catch {
|
|
222
|
-
return null;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
function listMarkdownOutputs(outDir: string): string[] {
|
|
227
|
-
const out: string[] = [];
|
|
228
|
-
const stack = [outDir];
|
|
229
|
-
while (stack.length) {
|
|
230
|
-
const dir = stack.pop()!;
|
|
231
|
-
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
232
|
-
const full = path.join(dir, entry.name);
|
|
233
|
-
if (entry.isDirectory()) stack.push(full);
|
|
234
|
-
else if (entry.isFile() && entry.name.endsWith('.md')) out.push(full);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
return out.sort((a, b) => a.localeCompare(b));
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
export async function bootstrapKnowledgeBase(options: BootstrapKnowledgeOptions): Promise<{
|
|
241
|
-
outDir: string;
|
|
242
|
-
fileCount: number;
|
|
243
|
-
moduleCount: number;
|
|
244
|
-
commitCount: number;
|
|
245
|
-
generatedFiles: string[];
|
|
246
|
-
}> {
|
|
247
|
-
const repoPath = path.resolve(options.repoPath);
|
|
248
|
-
const outDir = path.resolve(options.outDir);
|
|
249
|
-
const maxCommits = options.maxCommits ?? 1000;
|
|
250
|
-
|
|
251
|
-
const existingManifest = options.incremental ? loadExistingManifest(outDir) : null;
|
|
252
|
-
const incrementalSince = existingManifest?.lastCommitDate || existingManifest?.generatedAt;
|
|
253
|
-
const since = options.since || incrementalSince || '180 days ago';
|
|
254
|
-
|
|
255
|
-
const codeFiles = walkCodeFiles(repoPath);
|
|
256
|
-
const modules = summarizeModules(repoPath, codeFiles);
|
|
257
|
-
const commits = options.incremental && existingManifest?.lastCommitHash
|
|
258
|
-
? getGitCommitsAfterHash(repoPath, existingManifest.lastCommitHash, maxCommits)
|
|
259
|
-
: getGitCommits(repoPath, since, maxCommits);
|
|
260
|
-
const decisions = extractDecisions(commits);
|
|
261
|
-
const timeline = buildTimeline(commits);
|
|
262
|
-
const glossary = buildGlossary(codeFiles);
|
|
263
|
-
|
|
264
|
-
const generatedFiles: string[] = [];
|
|
265
|
-
|
|
266
|
-
const sections = {
|
|
267
|
-
overview: path.join(outDir, 'overview'),
|
|
268
|
-
modules: path.join(outDir, 'modules'),
|
|
269
|
-
decisions: path.join(outDir, 'decisions'),
|
|
270
|
-
timeline: path.join(outDir, 'timeline'),
|
|
271
|
-
glossary: path.join(outDir, 'glossary'),
|
|
272
|
-
sources: path.join(outDir, 'sources')
|
|
273
|
-
};
|
|
274
|
-
|
|
275
|
-
for (const sectionDir of Object.values(sections)) {
|
|
276
|
-
mkdirp(sectionDir);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
const overviewPath = path.join(sections.overview, 'overview.md');
|
|
280
|
-
const overview = [
|
|
281
|
-
'# Codebase Overview',
|
|
282
|
-
'',
|
|
283
|
-
`- generatedAt: ${new Date().toISOString()}`,
|
|
284
|
-
'- deterministicPipeline: true',
|
|
285
|
-
`- repo: ${repoPath}`,
|
|
286
|
-
`- filesAnalyzed: ${codeFiles.length}`,
|
|
287
|
-
`- commitsAnalyzed: ${commits.length}`,
|
|
288
|
-
`- confidence: ${confidenceByEvidence(modules.length > 0 ? 3 : 0)}`,
|
|
289
|
-
'',
|
|
290
|
-
'## Directory / Module Map',
|
|
291
|
-
...modules.slice(0, 50).map((m) => `- ${m.name}: ${m.fileCount} files (${m.languages.join(', ') || 'n/a'})`),
|
|
292
|
-
'',
|
|
293
|
-
'## Fact',
|
|
294
|
-
'- Generated from deterministic file scan and git history parsing.',
|
|
295
|
-
'',
|
|
296
|
-
'## Inference',
|
|
297
|
-
'- Module responsibilities should be reviewed by maintainers for nuanced boundaries.',
|
|
298
|
-
'',
|
|
299
|
-
'## Sources',
|
|
300
|
-
sourceLine(`repo-scan:${repoPath}`),
|
|
301
|
-
sourceLine(`git-log:since=${since};max=${maxCommits}`),
|
|
302
|
-
''
|
|
303
|
-
].join('\n');
|
|
304
|
-
writeFile(overviewPath, overview);
|
|
305
|
-
generatedFiles.push(overviewPath);
|
|
306
|
-
|
|
307
|
-
const touchedRoots = new Set(
|
|
308
|
-
commits
|
|
309
|
-
.flatMap((c) => c.files)
|
|
310
|
-
.map((f) => f.split('/').filter(Boolean)[0])
|
|
311
|
-
.filter(Boolean)
|
|
312
|
-
);
|
|
313
|
-
const moduleTargets = options.incremental && touchedRoots.size > 0
|
|
314
|
-
? modules.filter((m) => touchedRoots.has(m.root)).slice(0, 200)
|
|
315
|
-
: modules.slice(0, 200);
|
|
316
|
-
|
|
317
|
-
for (const m of moduleTargets) {
|
|
318
|
-
const relatedCommits = commits.filter((c) => c.files.some((f) => f.startsWith(`${m.root}/`))).slice(0, 15);
|
|
319
|
-
const content = [
|
|
320
|
-
`# Module: ${m.name}`,
|
|
321
|
-
'',
|
|
322
|
-
`- responsibility: inferred from top-level path \`${m.root}/\``,
|
|
323
|
-
`- files: ${m.fileCount}`,
|
|
324
|
-
`- languages: ${m.languages.join(', ') || 'n/a'}`,
|
|
325
|
-
`- confidence: ${confidenceByEvidence(relatedCommits.length)}`,
|
|
326
|
-
'',
|
|
327
|
-
'## Entry Candidates',
|
|
328
|
-
...(m.entryCandidates.length > 0 ? m.entryCandidates.map((f) => `- ${f}`) : ['- none detected']),
|
|
329
|
-
'',
|
|
330
|
-
'## Related Commits (recent sample)',
|
|
331
|
-
...(relatedCommits.length > 0
|
|
332
|
-
? relatedCommits.map((c) => `- ${c.date} ${c.hash.slice(0, 8)} ${c.subject}`)
|
|
333
|
-
: ['- none in selected range']),
|
|
334
|
-
'',
|
|
335
|
-
'## Sources',
|
|
336
|
-
sourceLine(`repo-path:${m.root}/**`),
|
|
337
|
-
...relatedCommits.map((c) => sourceLine(`commit:${c.hash}`)),
|
|
338
|
-
''
|
|
339
|
-
].join('\n');
|
|
340
|
-
|
|
341
|
-
const modulePath = path.join(sections.modules, `${m.name.replace(/[^a-z0-9._-]+/gi, '-').toLowerCase()}.md`);
|
|
342
|
-
writeFile(modulePath, content);
|
|
343
|
-
generatedFiles.push(modulePath);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
const decisionsPath = path.join(sections.decisions, 'decisions.md');
|
|
347
|
-
const decisionsMd = [
|
|
348
|
-
'# Decisions (extracted)',
|
|
349
|
-
'',
|
|
350
|
-
`- confidence: ${confidenceByEvidence(decisions.length)}`,
|
|
351
|
-
'',
|
|
352
|
-
...(decisions.length > 0
|
|
353
|
-
? decisions.slice(0, 500).map((d) => [
|
|
354
|
-
`## ${d.date} | ${d.subject}`,
|
|
355
|
-
'- status: active (inferred)',
|
|
356
|
-
sourceLine(`commit:${d.hash}`),
|
|
357
|
-
`- author: ${d.author}`,
|
|
358
|
-
`- changedFiles: ${d.files.length}`,
|
|
359
|
-
`- confidence: ${confidenceByEvidence(d.files.length > 0 ? 2 : 1)}`,
|
|
360
|
-
''
|
|
361
|
-
].join('\n'))
|
|
362
|
-
: ['- No decision-like commits found in selected range.', '']),
|
|
363
|
-
'## Sources',
|
|
364
|
-
sourceLine(`git-log:since=${since};max=${maxCommits}`),
|
|
365
|
-
''
|
|
366
|
-
].join('\n');
|
|
367
|
-
writeFile(decisionsPath, decisionsMd);
|
|
368
|
-
generatedFiles.push(decisionsPath);
|
|
369
|
-
|
|
370
|
-
const timelinePath = path.join(sections.timeline, 'timeline.md');
|
|
371
|
-
const timelineMd = [
|
|
372
|
-
'# Timeline',
|
|
373
|
-
'',
|
|
374
|
-
`- confidence: ${confidenceByEvidence(commits.length > 0 ? 2 : 0)}`,
|
|
375
|
-
'',
|
|
376
|
-
...[...timeline.entries()].flatMap(([month, list]) => [
|
|
377
|
-
`## ${month}`,
|
|
378
|
-
...list.slice(0, 40).map((c) => `- ${c.date} ${c.hash.slice(0, 8)} ${c.subject}`),
|
|
379
|
-
''
|
|
380
|
-
]),
|
|
381
|
-
'## Sources',
|
|
382
|
-
sourceLine(`git-log:since=${since};max=${maxCommits}`),
|
|
383
|
-
''
|
|
384
|
-
].join('\n');
|
|
385
|
-
writeFile(timelinePath, timelineMd);
|
|
386
|
-
generatedFiles.push(timelinePath);
|
|
387
|
-
|
|
388
|
-
const glossaryPath = path.join(sections.glossary, 'glossary.md');
|
|
389
|
-
const glossaryMd = [
|
|
390
|
-
'# Glossary (auto-extracted)',
|
|
391
|
-
'',
|
|
392
|
-
`- confidence: ${confidenceByEvidence(glossary.length > 0 ? 1 : 0)}`,
|
|
393
|
-
'',
|
|
394
|
-
...glossary.map((t) => `- ${t}`),
|
|
395
|
-
'',
|
|
396
|
-
'## Sources',
|
|
397
|
-
sourceLine(`repo-scan:${repoPath}`),
|
|
398
|
-
''
|
|
399
|
-
].join('\n');
|
|
400
|
-
writeFile(glossaryPath, glossaryMd);
|
|
401
|
-
generatedFiles.push(glossaryPath);
|
|
402
|
-
|
|
403
|
-
const outputs = generatedFiles.map((f) => safeRel(outDir, f)).sort((a, b) => a.localeCompare(b));
|
|
404
|
-
const allOutputs = listMarkdownOutputs(outDir).map((f) => safeRel(outDir, f));
|
|
405
|
-
|
|
406
|
-
const sourceItems = [
|
|
407
|
-
...codeFiles.slice(0, 200).map((f) => ({ type: 'file', ref: safeRel(repoPath, f) })),
|
|
408
|
-
...commits.slice(0, 400).map((c) => ({ type: 'commit', ref: c.hash, date: c.date, subject: c.subject }))
|
|
409
|
-
];
|
|
410
|
-
|
|
411
|
-
const latestCommitDate = commits.length > 0 ? commits[commits.length - 1].date : existingManifest?.lastCommitDate;
|
|
412
|
-
const latestCommitHash = commits.length > 0 ? commits[commits.length - 1].hash : existingManifest?.lastCommitHash;
|
|
413
|
-
const manifest = {
|
|
414
|
-
generatedAt: new Date().toISOString(),
|
|
415
|
-
deterministicPipeline: true,
|
|
416
|
-
mode: options.incremental ? 'incremental' : 'full',
|
|
417
|
-
repoPath,
|
|
418
|
-
options: { since, maxCommits, incremental: Boolean(options.incremental) },
|
|
419
|
-
stats: {
|
|
420
|
-
filesAnalyzed: codeFiles.length,
|
|
421
|
-
modules: modules.length,
|
|
422
|
-
modulesGenerated: moduleTargets.length,
|
|
423
|
-
commits: commits.length,
|
|
424
|
-
decisions: decisions.length,
|
|
425
|
-
glossaryTerms: glossary.length
|
|
426
|
-
},
|
|
427
|
-
lastCommitDate: latestCommitDate,
|
|
428
|
-
lastCommitHash: latestCommitHash,
|
|
429
|
-
outputs,
|
|
430
|
-
allOutputs,
|
|
431
|
-
sources: sourceItems
|
|
432
|
-
};
|
|
433
|
-
|
|
434
|
-
const manifestJsonPath = path.join(sections.sources, 'manifest.json');
|
|
435
|
-
writeFile(manifestJsonPath, `${JSON.stringify(manifest, null, 2)}\n`);
|
|
436
|
-
generatedFiles.push(manifestJsonPath);
|
|
437
|
-
|
|
438
|
-
const manifestMdPath = path.join(sections.sources, 'manifest.md');
|
|
439
|
-
const manifestMd = [
|
|
440
|
-
'# Sources Manifest',
|
|
441
|
-
'',
|
|
442
|
-
'- deterministicPipeline: true',
|
|
443
|
-
`- mode: ${options.incremental ? 'incremental' : 'full'}`,
|
|
444
|
-
`- sourceCount: ${sourceItems.length}`,
|
|
445
|
-
'',
|
|
446
|
-
'## Outputs',
|
|
447
|
-
...outputs.map((o) => `- ${o}`),
|
|
448
|
-
'',
|
|
449
|
-
'## Sources (sample)',
|
|
450
|
-
...sourceItems.slice(0, 300).map((s) => `- ${s.type}:${s.ref}`),
|
|
451
|
-
''
|
|
452
|
-
].join('\n');
|
|
453
|
-
writeFile(manifestMdPath, manifestMd);
|
|
454
|
-
generatedFiles.push(manifestMdPath);
|
|
455
|
-
|
|
456
|
-
return {
|
|
457
|
-
outDir,
|
|
458
|
-
fileCount: codeFiles.length,
|
|
459
|
-
moduleCount: modules.length,
|
|
460
|
-
commitCount: commits.length,
|
|
461
|
-
generatedFiles: generatedFiles.sort((a, b) => a.localeCompare(b))
|
|
462
|
-
};
|
|
463
|
-
}
|