claude-memory-layer 1.0.30 → 1.0.32
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 +12 -5
- package/dist/cli/index.js +4 -3
- package/dist/cli/index.js.map +2 -2
- package/dist/core/index.js +3 -2
- package/dist/core/index.js.map +2 -2
- package/dist/hooks/post-tool-use.js +3 -2
- package/dist/hooks/post-tool-use.js.map +2 -2
- package/dist/hooks/semantic-daemon.js +3 -2
- package/dist/hooks/semantic-daemon.js.map +2 -2
- package/dist/hooks/session-end.js +3 -2
- package/dist/hooks/session-end.js.map +2 -2
- package/dist/hooks/session-start.js +3 -2
- package/dist/hooks/session-start.js.map +2 -2
- package/dist/hooks/stop.js +3 -2
- package/dist/hooks/stop.js.map +2 -2
- package/dist/hooks/user-prompt-submit.js +3 -2
- package/dist/hooks/user-prompt-submit.js.map +2 -2
- package/dist/index.js +3 -2
- package/dist/index.js.map +2 -2
- package/dist/mcp/index.js +3 -2
- package/dist/mcp/index.js.map +2 -2
- package/dist/server/api/index.js +3 -2
- package/dist/server/api/index.js.map +2 -2
- package/dist/server/index.js +3 -2
- package/dist/server/index.js.map +2 -2
- package/dist/services/memory-service.js +3 -2
- package/dist/services/memory-service.js.map +2 -2
- package/package.json +10 -3
- package/scripts/postinstall-embedding-backend.cjs +18 -16
- 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 -233
- 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 -175
- 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 -83
- 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,249 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SharedPromoter - Handles auto-promotion of verified troubleshooting entries
|
|
3
|
-
* Promotes entries from project-local storage to cross-project shared storage
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { randomUUID } from 'crypto';
|
|
7
|
-
import { SharedStore } from './shared-store.js';
|
|
8
|
-
import { SharedVectorStore } from './shared-vector-store.js';
|
|
9
|
-
import { Embedder } from './embedder.js';
|
|
10
|
-
import type { Entry, SharedTroubleshootingInput, SharedStoreConfig } from './types.js';
|
|
11
|
-
|
|
12
|
-
export interface TroubleshootingContent {
|
|
13
|
-
symptoms?: string[];
|
|
14
|
-
rootCause?: string;
|
|
15
|
-
solution?: string;
|
|
16
|
-
technologies?: string[];
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface PromotionResult {
|
|
20
|
-
success: boolean;
|
|
21
|
-
entryId?: string;
|
|
22
|
-
error?: string;
|
|
23
|
-
skipped?: boolean;
|
|
24
|
-
skipReason?: string;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export class SharedPromoter {
|
|
28
|
-
constructor(
|
|
29
|
-
private sharedStore: SharedStore,
|
|
30
|
-
private sharedVectorStore: SharedVectorStore,
|
|
31
|
-
private embedder: Embedder,
|
|
32
|
-
private config?: SharedStoreConfig
|
|
33
|
-
) {}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Check if an entry is eligible for promotion
|
|
37
|
-
*/
|
|
38
|
-
isEligibleForPromotion(entry: Entry): boolean {
|
|
39
|
-
// Must be troubleshooting type
|
|
40
|
-
if (entry.entryType !== 'troubleshooting') {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Must be at least 'verified' stage
|
|
45
|
-
if (entry.stage !== 'verified' && entry.stage !== 'certified') {
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Must be active status
|
|
50
|
-
if (entry.status !== 'active') {
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Promote a verified troubleshooting entry to shared storage
|
|
59
|
-
*/
|
|
60
|
-
async promoteEntry(
|
|
61
|
-
entry: Entry,
|
|
62
|
-
projectHash: string
|
|
63
|
-
): Promise<PromotionResult> {
|
|
64
|
-
// Validate eligibility
|
|
65
|
-
if (!this.isEligibleForPromotion(entry)) {
|
|
66
|
-
return {
|
|
67
|
-
success: false,
|
|
68
|
-
skipped: true,
|
|
69
|
-
skipReason: `Entry not eligible: type=${entry.entryType}, stage=${entry.stage}, status=${entry.status}`
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Check if already promoted
|
|
74
|
-
const exists = await this.sharedStore.exists(projectHash, entry.entryId);
|
|
75
|
-
if (exists) {
|
|
76
|
-
return {
|
|
77
|
-
success: true,
|
|
78
|
-
skipped: true,
|
|
79
|
-
skipReason: 'Entry already exists in shared store'
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
try {
|
|
84
|
-
const content = entry.contentJson as TroubleshootingContent;
|
|
85
|
-
const confidence = this.calculateConfidence(entry);
|
|
86
|
-
|
|
87
|
-
// Check minimum confidence threshold
|
|
88
|
-
const minConfidence = this.config?.minConfidenceForPromotion ?? 0.8;
|
|
89
|
-
if (confidence < minConfidence) {
|
|
90
|
-
return {
|
|
91
|
-
success: false,
|
|
92
|
-
skipped: true,
|
|
93
|
-
skipReason: `Confidence ${confidence} below threshold ${minConfidence}`
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const input: SharedTroubleshootingInput = {
|
|
98
|
-
sourceProjectHash: projectHash,
|
|
99
|
-
sourceEntryId: entry.entryId,
|
|
100
|
-
title: entry.title,
|
|
101
|
-
symptoms: content.symptoms || [],
|
|
102
|
-
rootCause: content.rootCause || '',
|
|
103
|
-
solution: content.solution || '',
|
|
104
|
-
topics: this.extractTopics(entry),
|
|
105
|
-
technologies: content.technologies || [],
|
|
106
|
-
confidence
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
// Promote to shared store
|
|
110
|
-
const entryId = await this.sharedStore.promoteEntry(input);
|
|
111
|
-
|
|
112
|
-
// Create embedding for vector search
|
|
113
|
-
const embeddingContent = this.createEmbeddingContent(input);
|
|
114
|
-
const embedding = await this.embedder.embed(embeddingContent);
|
|
115
|
-
|
|
116
|
-
await this.sharedVectorStore.upsert({
|
|
117
|
-
id: randomUUID(),
|
|
118
|
-
entryId,
|
|
119
|
-
entryType: 'troubleshooting',
|
|
120
|
-
content: embeddingContent,
|
|
121
|
-
vector: embedding.vector,
|
|
122
|
-
topics: input.topics,
|
|
123
|
-
sourceProjectHash: projectHash
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
return {
|
|
127
|
-
success: true,
|
|
128
|
-
entryId
|
|
129
|
-
};
|
|
130
|
-
} catch (error) {
|
|
131
|
-
return {
|
|
132
|
-
success: false,
|
|
133
|
-
error: error instanceof Error ? error.message : String(error)
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Batch promote multiple entries
|
|
140
|
-
*/
|
|
141
|
-
async promoteEntries(
|
|
142
|
-
entries: Entry[],
|
|
143
|
-
projectHash: string
|
|
144
|
-
): Promise<Map<string, PromotionResult>> {
|
|
145
|
-
const results = new Map<string, PromotionResult>();
|
|
146
|
-
|
|
147
|
-
for (const entry of entries) {
|
|
148
|
-
const result = await this.promoteEntry(entry, projectHash);
|
|
149
|
-
results.set(entry.entryId, result);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
return results;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Extract topics from entry
|
|
157
|
-
*/
|
|
158
|
-
private extractTopics(entry: Entry): string[] {
|
|
159
|
-
const topics: string[] = [];
|
|
160
|
-
|
|
161
|
-
// Extract from title (meaningful words)
|
|
162
|
-
const titleWords = entry.title
|
|
163
|
-
.toLowerCase()
|
|
164
|
-
.split(/[\s\-_]+/)
|
|
165
|
-
.filter(w => w.length > 3 && !this.isStopWord(w));
|
|
166
|
-
topics.push(...titleWords);
|
|
167
|
-
|
|
168
|
-
// Extract from content if available
|
|
169
|
-
const content = entry.contentJson as Record<string, unknown>;
|
|
170
|
-
if (content.topics && Array.isArray(content.topics)) {
|
|
171
|
-
topics.push(...content.topics.map(t => String(t).toLowerCase()));
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// Extract technologies as topics
|
|
175
|
-
if (content.technologies && Array.isArray(content.technologies)) {
|
|
176
|
-
topics.push(...content.technologies.map(t => String(t).toLowerCase()));
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// Dedupe and return
|
|
180
|
-
return [...new Set(topics)];
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Check if word is a stop word
|
|
185
|
-
*/
|
|
186
|
-
private isStopWord(word: string): boolean {
|
|
187
|
-
const stopWords = new Set([
|
|
188
|
-
'the', 'and', 'for', 'with', 'this', 'that', 'from', 'have', 'been',
|
|
189
|
-
'were', 'are', 'was', 'had', 'has', 'will', 'would', 'could', 'should',
|
|
190
|
-
'when', 'where', 'what', 'which', 'while', 'error', 'problem', 'issue'
|
|
191
|
-
]);
|
|
192
|
-
return stopWords.has(word);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Calculate confidence score for entry
|
|
197
|
-
*/
|
|
198
|
-
private calculateConfidence(entry: Entry): number {
|
|
199
|
-
let confidence = 0.8; // Base confidence for verified entries
|
|
200
|
-
|
|
201
|
-
// Boost if certified
|
|
202
|
-
if (entry.stage === 'certified') {
|
|
203
|
-
confidence = 0.95;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
// Could add more factors:
|
|
207
|
-
// - Number of evidence items
|
|
208
|
-
// - Age of entry (older verified entries may be more reliable)
|
|
209
|
-
// - Usage count if tracked
|
|
210
|
-
|
|
211
|
-
return Math.min(confidence, 1.0);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Create embedding content from input
|
|
216
|
-
*/
|
|
217
|
-
private createEmbeddingContent(input: SharedTroubleshootingInput): string {
|
|
218
|
-
const parts: string[] = [];
|
|
219
|
-
|
|
220
|
-
parts.push(`Problem: ${input.title}`);
|
|
221
|
-
|
|
222
|
-
if (input.symptoms.length > 0) {
|
|
223
|
-
parts.push(`Symptoms: ${input.symptoms.join(', ')}`);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
if (input.rootCause) {
|
|
227
|
-
parts.push(`Root Cause: ${input.rootCause}`);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
if (input.solution) {
|
|
231
|
-
parts.push(`Solution: ${input.solution}`);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
if (input.technologies && input.technologies.length > 0) {
|
|
235
|
-
parts.push(`Technologies: ${input.technologies.join(', ')}`);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
return parts.join('\n');
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
export function createSharedPromoter(
|
|
243
|
-
sharedStore: SharedStore,
|
|
244
|
-
sharedVectorStore: SharedVectorStore,
|
|
245
|
-
embedder: Embedder,
|
|
246
|
-
config?: SharedStoreConfig
|
|
247
|
-
): SharedPromoter {
|
|
248
|
-
return new SharedPromoter(sharedStore, sharedVectorStore, embedder, config);
|
|
249
|
-
}
|
package/src/core/shared-store.ts
DELETED
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SharedStore - Cross-project troubleshooting knowledge store
|
|
3
|
-
* Manages promotion from verified entries to shared storage
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { randomUUID } from 'crypto';
|
|
7
|
-
import { dbRun, dbAll, toDate, type Database } from './db-wrapper.js';
|
|
8
|
-
import type {
|
|
9
|
-
SharedTroubleshootingEntry,
|
|
10
|
-
SharedTroubleshootingInput
|
|
11
|
-
} from './types.js';
|
|
12
|
-
import { SharedEventStore } from './shared-event-store.js';
|
|
13
|
-
|
|
14
|
-
export class SharedStore {
|
|
15
|
-
constructor(private sharedEventStore: SharedEventStore) {}
|
|
16
|
-
|
|
17
|
-
private get db(): Database {
|
|
18
|
-
return this.sharedEventStore.getDatabase();
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Promote a verified troubleshooting entry to shared storage
|
|
23
|
-
*/
|
|
24
|
-
async promoteEntry(
|
|
25
|
-
input: SharedTroubleshootingInput
|
|
26
|
-
): Promise<string> {
|
|
27
|
-
const entryId = randomUUID();
|
|
28
|
-
|
|
29
|
-
await dbRun(
|
|
30
|
-
this.db,
|
|
31
|
-
`INSERT INTO shared_troubleshooting (
|
|
32
|
-
entry_id, source_project_hash, source_entry_id,
|
|
33
|
-
title, symptoms, root_cause, solution, topics,
|
|
34
|
-
technologies, confidence, promoted_at
|
|
35
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)
|
|
36
|
-
ON CONFLICT (source_project_hash, source_entry_id)
|
|
37
|
-
DO UPDATE SET
|
|
38
|
-
title = excluded.title,
|
|
39
|
-
symptoms = excluded.symptoms,
|
|
40
|
-
root_cause = excluded.root_cause,
|
|
41
|
-
solution = excluded.solution,
|
|
42
|
-
topics = excluded.topics,
|
|
43
|
-
technologies = excluded.technologies,
|
|
44
|
-
confidence = CASE
|
|
45
|
-
WHEN excluded.confidence > shared_troubleshooting.confidence
|
|
46
|
-
THEN excluded.confidence
|
|
47
|
-
ELSE shared_troubleshooting.confidence
|
|
48
|
-
END`,
|
|
49
|
-
[
|
|
50
|
-
entryId,
|
|
51
|
-
input.sourceProjectHash,
|
|
52
|
-
input.sourceEntryId,
|
|
53
|
-
input.title,
|
|
54
|
-
JSON.stringify(input.symptoms),
|
|
55
|
-
input.rootCause,
|
|
56
|
-
input.solution,
|
|
57
|
-
JSON.stringify(input.topics),
|
|
58
|
-
JSON.stringify(input.technologies || []),
|
|
59
|
-
input.confidence
|
|
60
|
-
]
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
return entryId;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Search troubleshooting entries by text query
|
|
68
|
-
*/
|
|
69
|
-
async search(
|
|
70
|
-
query: string,
|
|
71
|
-
options?: { topK?: number; minConfidence?: number }
|
|
72
|
-
): Promise<SharedTroubleshootingEntry[]> {
|
|
73
|
-
const topK = options?.topK || 5;
|
|
74
|
-
const minConfidence = options?.minConfidence || 0.5;
|
|
75
|
-
const searchPattern = `%${query}%`;
|
|
76
|
-
|
|
77
|
-
const rows = await dbAll<Record<string, unknown>>(
|
|
78
|
-
this.db,
|
|
79
|
-
`SELECT * FROM shared_troubleshooting
|
|
80
|
-
WHERE (title LIKE ? OR root_cause LIKE ? OR solution LIKE ?)
|
|
81
|
-
AND confidence >= ?
|
|
82
|
-
ORDER BY confidence DESC, usage_count DESC
|
|
83
|
-
LIMIT ?`,
|
|
84
|
-
[searchPattern, searchPattern, searchPattern, minConfidence, topK]
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
return rows.map(this.rowToEntry);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Search by topics
|
|
92
|
-
*/
|
|
93
|
-
async searchByTopics(
|
|
94
|
-
topics: string[],
|
|
95
|
-
options?: { topK?: number; excludeProjectHash?: string }
|
|
96
|
-
): Promise<SharedTroubleshootingEntry[]> {
|
|
97
|
-
const topK = options?.topK || 5;
|
|
98
|
-
|
|
99
|
-
if (topics.length === 0) {
|
|
100
|
-
return [];
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const topicConditions = topics.map(() => `topics LIKE ?`).join(' OR ');
|
|
104
|
-
const topicParams = topics.map(t => `%"${t}"%`);
|
|
105
|
-
|
|
106
|
-
let query = `SELECT * FROM shared_troubleshooting WHERE (${topicConditions})`;
|
|
107
|
-
const params: unknown[] = [...topicParams];
|
|
108
|
-
|
|
109
|
-
if (options?.excludeProjectHash) {
|
|
110
|
-
query += ` AND source_project_hash != ?`;
|
|
111
|
-
params.push(options.excludeProjectHash);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
query += ` ORDER BY confidence DESC, usage_count DESC LIMIT ?`;
|
|
115
|
-
params.push(topK);
|
|
116
|
-
|
|
117
|
-
const rows = await dbAll<Record<string, unknown>>(this.db, query, params);
|
|
118
|
-
return rows.map(this.rowToEntry);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Record usage of a shared entry (for ranking)
|
|
123
|
-
*/
|
|
124
|
-
async recordUsage(entryId: string): Promise<void> {
|
|
125
|
-
await dbRun(
|
|
126
|
-
this.db,
|
|
127
|
-
`UPDATE shared_troubleshooting
|
|
128
|
-
SET usage_count = usage_count + 1,
|
|
129
|
-
last_used_at = CURRENT_TIMESTAMP
|
|
130
|
-
WHERE entry_id = ?`,
|
|
131
|
-
[entryId]
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Get entry by ID
|
|
137
|
-
*/
|
|
138
|
-
async get(entryId: string): Promise<SharedTroubleshootingEntry | null> {
|
|
139
|
-
const rows = await dbAll<Record<string, unknown>>(
|
|
140
|
-
this.db,
|
|
141
|
-
`SELECT * FROM shared_troubleshooting WHERE entry_id = ?`,
|
|
142
|
-
[entryId]
|
|
143
|
-
);
|
|
144
|
-
|
|
145
|
-
if (rows.length === 0) return null;
|
|
146
|
-
return this.rowToEntry(rows[0]);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Get entry by source (project hash + entry ID)
|
|
151
|
-
*/
|
|
152
|
-
async getBySource(
|
|
153
|
-
projectHash: string,
|
|
154
|
-
sourceEntryId: string
|
|
155
|
-
): Promise<SharedTroubleshootingEntry | null> {
|
|
156
|
-
const rows = await dbAll<Record<string, unknown>>(
|
|
157
|
-
this.db,
|
|
158
|
-
`SELECT * FROM shared_troubleshooting
|
|
159
|
-
WHERE source_project_hash = ? AND source_entry_id = ?`,
|
|
160
|
-
[projectHash, sourceEntryId]
|
|
161
|
-
);
|
|
162
|
-
|
|
163
|
-
if (rows.length === 0) return null;
|
|
164
|
-
return this.rowToEntry(rows[0]);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Check if an entry already exists in shared store
|
|
169
|
-
*/
|
|
170
|
-
async exists(projectHash: string, sourceEntryId: string): Promise<boolean> {
|
|
171
|
-
const result = await dbAll<{ count: number }>(
|
|
172
|
-
this.db,
|
|
173
|
-
`SELECT COUNT(*) as count FROM shared_troubleshooting
|
|
174
|
-
WHERE source_project_hash = ? AND source_entry_id = ?`,
|
|
175
|
-
[projectHash, sourceEntryId]
|
|
176
|
-
);
|
|
177
|
-
return (result[0]?.count || 0) > 0;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Get all entries (with limit for safety)
|
|
182
|
-
*/
|
|
183
|
-
async getAll(options?: { limit?: number }): Promise<SharedTroubleshootingEntry[]> {
|
|
184
|
-
const limit = options?.limit || 100;
|
|
185
|
-
const rows = await dbAll<Record<string, unknown>>(
|
|
186
|
-
this.db,
|
|
187
|
-
`SELECT * FROM shared_troubleshooting
|
|
188
|
-
ORDER BY confidence DESC, usage_count DESC
|
|
189
|
-
LIMIT ?`,
|
|
190
|
-
[limit]
|
|
191
|
-
);
|
|
192
|
-
|
|
193
|
-
return rows.map(this.rowToEntry);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Get total count
|
|
198
|
-
*/
|
|
199
|
-
async count(): Promise<number> {
|
|
200
|
-
const result = await dbAll<{ count: number }>(
|
|
201
|
-
this.db,
|
|
202
|
-
`SELECT COUNT(*) as count FROM shared_troubleshooting`
|
|
203
|
-
);
|
|
204
|
-
return result[0]?.count || 0;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Get statistics
|
|
209
|
-
*/
|
|
210
|
-
async getStats(): Promise<{
|
|
211
|
-
total: number;
|
|
212
|
-
averageConfidence: number;
|
|
213
|
-
topTopics: Array<{ topic: string; count: number }>;
|
|
214
|
-
totalUsageCount: number;
|
|
215
|
-
}> {
|
|
216
|
-
const countResult = await dbAll<{ count: number }>(
|
|
217
|
-
this.db,
|
|
218
|
-
`SELECT COUNT(*) as count FROM shared_troubleshooting`
|
|
219
|
-
);
|
|
220
|
-
const total = countResult[0]?.count || 0;
|
|
221
|
-
|
|
222
|
-
const avgResult = await dbAll<{ avg: number | null }>(
|
|
223
|
-
this.db,
|
|
224
|
-
`SELECT AVG(confidence) as avg FROM shared_troubleshooting`
|
|
225
|
-
);
|
|
226
|
-
const averageConfidence = avgResult[0]?.avg || 0;
|
|
227
|
-
|
|
228
|
-
const usageResult = await dbAll<{ total: number }>(
|
|
229
|
-
this.db,
|
|
230
|
-
`SELECT SUM(usage_count) as total FROM shared_troubleshooting`
|
|
231
|
-
);
|
|
232
|
-
const totalUsageCount = usageResult[0]?.total || 0;
|
|
233
|
-
|
|
234
|
-
// Get topic counts
|
|
235
|
-
const entries = await this.getAll({ limit: 1000 });
|
|
236
|
-
const topicCounts: Record<string, number> = {};
|
|
237
|
-
for (const entry of entries) {
|
|
238
|
-
for (const topic of entry.topics) {
|
|
239
|
-
topicCounts[topic] = (topicCounts[topic] || 0) + 1;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
const topTopics = Object.entries(topicCounts)
|
|
244
|
-
.map(([topic, count]) => ({ topic, count }))
|
|
245
|
-
.sort((a, b) => b.count - a.count)
|
|
246
|
-
.slice(0, 10);
|
|
247
|
-
|
|
248
|
-
return { total, averageConfidence, topTopics, totalUsageCount };
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Delete an entry
|
|
253
|
-
*/
|
|
254
|
-
async delete(entryId: string): Promise<boolean> {
|
|
255
|
-
const before = await this.count();
|
|
256
|
-
await dbRun(
|
|
257
|
-
this.db,
|
|
258
|
-
`DELETE FROM shared_troubleshooting WHERE entry_id = ?`,
|
|
259
|
-
[entryId]
|
|
260
|
-
);
|
|
261
|
-
const after = await this.count();
|
|
262
|
-
return before > after;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
private rowToEntry(row: Record<string, unknown>): SharedTroubleshootingEntry {
|
|
266
|
-
return {
|
|
267
|
-
entryId: row.entry_id as string,
|
|
268
|
-
sourceProjectHash: row.source_project_hash as string,
|
|
269
|
-
sourceEntryId: row.source_entry_id as string,
|
|
270
|
-
title: row.title as string,
|
|
271
|
-
symptoms: JSON.parse(row.symptoms as string || '[]'),
|
|
272
|
-
rootCause: row.root_cause as string,
|
|
273
|
-
solution: row.solution as string,
|
|
274
|
-
topics: JSON.parse(row.topics as string || '[]'),
|
|
275
|
-
technologies: JSON.parse(row.technologies as string || '[]'),
|
|
276
|
-
confidence: row.confidence as number,
|
|
277
|
-
usageCount: row.usage_count as number || 0,
|
|
278
|
-
lastUsedAt: row.last_used_at ? toDate(row.last_used_at) : undefined,
|
|
279
|
-
promotedAt: toDate(row.promoted_at),
|
|
280
|
-
createdAt: toDate(row.created_at)
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
export function createSharedStore(
|
|
286
|
-
sharedEventStore: SharedEventStore
|
|
287
|
-
): SharedStore {
|
|
288
|
-
return new SharedStore(sharedEventStore);
|
|
289
|
-
}
|