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,70 +0,0 @@
|
|
|
1
|
-
import * as fs from 'fs/promises';
|
|
2
|
-
import * as path from 'path';
|
|
3
|
-
import type { MemoryEvent } from './types.js';
|
|
4
|
-
|
|
5
|
-
const DEFAULT_NAMESPACE = 'default';
|
|
6
|
-
const DEFAULT_CATEGORY = 'uncategorized';
|
|
7
|
-
|
|
8
|
-
export function sanitizeSegment(input: unknown, fallback: string): string {
|
|
9
|
-
const raw = String(input ?? '').trim().toLowerCase();
|
|
10
|
-
const safe = raw
|
|
11
|
-
.normalize('NFKD')
|
|
12
|
-
.replace(/[^a-z0-9_-]+/g, '-')
|
|
13
|
-
.replace(/^-+|-+$/g, '');
|
|
14
|
-
|
|
15
|
-
if (!safe || safe === '.' || safe === '..') return fallback;
|
|
16
|
-
return safe;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function getCategorySegments(metadata: Record<string, unknown> | undefined, eventType: string): string[] {
|
|
20
|
-
const raw = metadata?.categoryPath;
|
|
21
|
-
if (Array.isArray(raw) && raw.length > 0) {
|
|
22
|
-
return raw.map((s) => sanitizeSegment(s, DEFAULT_CATEGORY));
|
|
23
|
-
}
|
|
24
|
-
const single = metadata?.category;
|
|
25
|
-
if (typeof single === 'string' && single.trim()) {
|
|
26
|
-
return [sanitizeSegment(single, DEFAULT_CATEGORY)];
|
|
27
|
-
}
|
|
28
|
-
return [sanitizeSegment(eventType, DEFAULT_CATEGORY)];
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function buildMirrorPath(rootDir: string, event: MemoryEvent): string {
|
|
32
|
-
const metadata = event.metadata as Record<string, unknown> | undefined;
|
|
33
|
-
const namespace = sanitizeSegment(metadata?.namespace, DEFAULT_NAMESPACE);
|
|
34
|
-
const categories = getCategorySegments(metadata, event.eventType);
|
|
35
|
-
|
|
36
|
-
const d = event.timestamp;
|
|
37
|
-
const yyyy = d.getFullYear();
|
|
38
|
-
const mm = String(d.getMonth() + 1).padStart(2, '0');
|
|
39
|
-
const dd = String(d.getDate()).padStart(2, '0');
|
|
40
|
-
|
|
41
|
-
return path.join(rootDir, 'memory', namespace, ...categories, `${yyyy}-${mm}-${dd}.md`);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function formatMirrorEntry(event: MemoryEvent): string {
|
|
45
|
-
const category = Array.isArray((event.metadata as any)?.categoryPath)
|
|
46
|
-
? ((event.metadata as any).categoryPath as unknown[]).join('/')
|
|
47
|
-
: String((event.metadata as any)?.category ?? event.eventType);
|
|
48
|
-
|
|
49
|
-
return [
|
|
50
|
-
'',
|
|
51
|
-
`- ts: ${event.timestamp.toISOString()}`,
|
|
52
|
-
` id: ${event.id}`,
|
|
53
|
-
` type: ${event.eventType}`,
|
|
54
|
-
` session: ${event.sessionId}`,
|
|
55
|
-
` category: ${category}`,
|
|
56
|
-
' content: |',
|
|
57
|
-
...event.content.split('\n').map((line) => ` ${line}`)
|
|
58
|
-
].join('\n') + '\n';
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export class MarkdownMirror {
|
|
62
|
-
constructor(private readonly rootDir: string) {}
|
|
63
|
-
|
|
64
|
-
async append(event: MemoryEvent): Promise<string> {
|
|
65
|
-
const outPath = buildMirrorPath(this.rootDir, event);
|
|
66
|
-
await fs.mkdir(path.dirname(outPath), { recursive: true });
|
|
67
|
-
await fs.appendFile(outPath, formatMirrorEntry(event), 'utf8');
|
|
68
|
-
return outPath;
|
|
69
|
-
}
|
|
70
|
-
}
|
package/src/core/matcher.ts
DELETED
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AXIOMMIND Matcher - Weighted scoring with confidence classification
|
|
3
|
-
* Implements matching thresholds: high (≥0.92), suggested (≥0.75), none (<0.75)
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type {
|
|
7
|
-
MemoryMatch,
|
|
8
|
-
MatchResult,
|
|
9
|
-
MatchConfidence
|
|
10
|
-
} from './types.js';
|
|
11
|
-
import { SearchResult } from './vector-store.js';
|
|
12
|
-
|
|
13
|
-
export interface MatchWeights {
|
|
14
|
-
semanticSimilarity: number;
|
|
15
|
-
ftsScore: number;
|
|
16
|
-
recencyBonus: number;
|
|
17
|
-
statusWeight: number;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface MatcherConfig {
|
|
21
|
-
weights: MatchWeights;
|
|
22
|
-
minCombinedScore: number;
|
|
23
|
-
minGap: number;
|
|
24
|
-
suggestionThreshold: number;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const DEFAULT_CONFIG: MatcherConfig = {
|
|
28
|
-
weights: {
|
|
29
|
-
semanticSimilarity: 0.4,
|
|
30
|
-
ftsScore: 0.25,
|
|
31
|
-
recencyBonus: 0.2,
|
|
32
|
-
statusWeight: 0.15
|
|
33
|
-
},
|
|
34
|
-
minCombinedScore: 0.92,
|
|
35
|
-
minGap: 0.03,
|
|
36
|
-
suggestionThreshold: 0.75
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export class Matcher {
|
|
40
|
-
private readonly config: MatcherConfig;
|
|
41
|
-
|
|
42
|
-
constructor(config: Partial<MatcherConfig> = {}) {
|
|
43
|
-
this.config = {
|
|
44
|
-
...DEFAULT_CONFIG,
|
|
45
|
-
...config,
|
|
46
|
-
weights: { ...DEFAULT_CONFIG.weights, ...config.weights }
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Calculate combined score using AXIOMMIND weighted formula
|
|
52
|
-
*/
|
|
53
|
-
calculateCombinedScore(
|
|
54
|
-
semanticScore: number,
|
|
55
|
-
ftsScore: number = 0,
|
|
56
|
-
recencyDays: number = 0,
|
|
57
|
-
isActive: boolean = true
|
|
58
|
-
): number {
|
|
59
|
-
const { weights } = this.config;
|
|
60
|
-
|
|
61
|
-
// Recency bonus: decays over 30 days
|
|
62
|
-
const recencyBonus = Math.max(0, 1 - recencyDays / 30);
|
|
63
|
-
|
|
64
|
-
// Status weight: active events get full weight
|
|
65
|
-
const statusMultiplier = isActive ? 1.0 : 0.7;
|
|
66
|
-
|
|
67
|
-
const combinedScore =
|
|
68
|
-
weights.semanticSimilarity * semanticScore +
|
|
69
|
-
weights.ftsScore * ftsScore +
|
|
70
|
-
weights.recencyBonus * recencyBonus +
|
|
71
|
-
weights.statusWeight * statusMultiplier;
|
|
72
|
-
|
|
73
|
-
return Math.min(1.0, combinedScore);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Classify match confidence based on AXIOMMIND thresholds
|
|
78
|
-
*/
|
|
79
|
-
classifyConfidence(
|
|
80
|
-
topScore: number,
|
|
81
|
-
secondScore: number | null
|
|
82
|
-
): MatchConfidence {
|
|
83
|
-
const { minCombinedScore, minGap, suggestionThreshold } = this.config;
|
|
84
|
-
|
|
85
|
-
// Calculate gap (infinity if no second match)
|
|
86
|
-
const gap = secondScore !== null ? topScore - secondScore : Infinity;
|
|
87
|
-
|
|
88
|
-
// High confidence: score ≥ 0.92 AND gap ≥ 0.03
|
|
89
|
-
if (topScore >= minCombinedScore && gap >= minGap) {
|
|
90
|
-
return 'high';
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// Suggested: score ≥ 0.75
|
|
94
|
-
if (topScore >= suggestionThreshold) {
|
|
95
|
-
return 'suggested';
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// No match
|
|
99
|
-
return 'none';
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Match search results to find best memory
|
|
104
|
-
*/
|
|
105
|
-
matchSearchResults(
|
|
106
|
-
results: SearchResult[],
|
|
107
|
-
getEventAge: (eventId: string) => number
|
|
108
|
-
): MatchResult {
|
|
109
|
-
if (results.length === 0) {
|
|
110
|
-
return {
|
|
111
|
-
match: null,
|
|
112
|
-
confidence: 'none'
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// Calculate combined scores
|
|
117
|
-
const scoredResults = results.map(result => {
|
|
118
|
-
const ageDays = getEventAge(result.eventId);
|
|
119
|
-
const combinedScore = this.calculateCombinedScore(
|
|
120
|
-
result.score,
|
|
121
|
-
result.score, // Reuse the retrieval score as lexical/proxy score when no separate FTS score is provided.
|
|
122
|
-
ageDays,
|
|
123
|
-
true // Assume active
|
|
124
|
-
);
|
|
125
|
-
|
|
126
|
-
return {
|
|
127
|
-
result,
|
|
128
|
-
combinedScore
|
|
129
|
-
};
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
// Sort by combined score
|
|
133
|
-
scoredResults.sort((a, b) => b.combinedScore - a.combinedScore);
|
|
134
|
-
|
|
135
|
-
const topResult = scoredResults[0];
|
|
136
|
-
const secondScore = scoredResults.length > 1 ? scoredResults[1].combinedScore : null;
|
|
137
|
-
|
|
138
|
-
// Classify confidence
|
|
139
|
-
const confidence = this.classifyConfidence(topResult.combinedScore, secondScore);
|
|
140
|
-
|
|
141
|
-
// Build match result
|
|
142
|
-
const match: MemoryMatch = {
|
|
143
|
-
event: {
|
|
144
|
-
id: topResult.result.eventId,
|
|
145
|
-
eventType: topResult.result.eventType as 'user_prompt' | 'agent_response' | 'session_summary',
|
|
146
|
-
sessionId: topResult.result.sessionId,
|
|
147
|
-
timestamp: new Date(topResult.result.timestamp),
|
|
148
|
-
content: topResult.result.content,
|
|
149
|
-
canonicalKey: '', // Would need to be fetched
|
|
150
|
-
dedupeKey: '' // Would need to be fetched
|
|
151
|
-
},
|
|
152
|
-
score: topResult.combinedScore
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
const gap = secondScore !== null ? topResult.combinedScore - secondScore : undefined;
|
|
156
|
-
|
|
157
|
-
// Build alternatives for suggested matches
|
|
158
|
-
const alternatives = confidence === 'suggested'
|
|
159
|
-
? scoredResults.slice(1, 4).map(sr => ({
|
|
160
|
-
event: {
|
|
161
|
-
id: sr.result.eventId,
|
|
162
|
-
eventType: sr.result.eventType as 'user_prompt' | 'agent_response' | 'session_summary',
|
|
163
|
-
sessionId: sr.result.sessionId,
|
|
164
|
-
timestamp: new Date(sr.result.timestamp),
|
|
165
|
-
content: sr.result.content,
|
|
166
|
-
canonicalKey: '',
|
|
167
|
-
dedupeKey: ''
|
|
168
|
-
},
|
|
169
|
-
score: sr.combinedScore
|
|
170
|
-
}))
|
|
171
|
-
: undefined;
|
|
172
|
-
|
|
173
|
-
return {
|
|
174
|
-
match: confidence !== 'none' ? match : null,
|
|
175
|
-
confidence,
|
|
176
|
-
gap,
|
|
177
|
-
alternatives
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Calculate days between two dates
|
|
183
|
-
*/
|
|
184
|
-
static calculateAgeDays(timestamp: Date): number {
|
|
185
|
-
const now = new Date();
|
|
186
|
-
const diffMs = now.getTime() - timestamp.getTime();
|
|
187
|
-
return diffMs / (1000 * 60 * 60 * 24);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Get current configuration
|
|
192
|
-
*/
|
|
193
|
-
getConfig(): Readonly<MatcherConfig> {
|
|
194
|
-
return { ...this.config };
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Default matcher instance
|
|
200
|
-
*/
|
|
201
|
-
let defaultMatcher: Matcher | null = null;
|
|
202
|
-
|
|
203
|
-
export function getDefaultMatcher(): Matcher {
|
|
204
|
-
if (!defaultMatcher) {
|
|
205
|
-
defaultMatcher = new Matcher();
|
|
206
|
-
}
|
|
207
|
-
return defaultMatcher;
|
|
208
|
-
}
|
package/src/core/md-mirror.ts
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import * as fs from 'node:fs';
|
|
2
|
-
import * as path from 'node:path';
|
|
3
|
-
import type { MemoryEventInput } from './types.js';
|
|
4
|
-
|
|
5
|
-
function sanitizeSegment(input: string | undefined, fallback: string): string {
|
|
6
|
-
const v = (input || '').trim().toLowerCase().replace(/[^a-z0-9._-]+/g, '-').replace(/^-+|-+$/g, '');
|
|
7
|
-
return v || fallback;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function getAtPath(obj: Record<string, unknown> | undefined, dotted: string): unknown {
|
|
11
|
-
if (!obj) return undefined;
|
|
12
|
-
return dotted.split('.').reduce<unknown>((acc, key) => {
|
|
13
|
-
if (!acc || typeof acc !== 'object') return undefined;
|
|
14
|
-
return (acc as Record<string, unknown>)[key];
|
|
15
|
-
}, obj);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function buildMirrorPath(rootDir: string, event: MemoryEventInput): string {
|
|
19
|
-
const meta = event.metadata as Record<string, unknown> | undefined;
|
|
20
|
-
|
|
21
|
-
const namespaceRaw = getAtPath(meta, 'namespace') ?? getAtPath(meta, 'scope.namespace') ?? event.eventType;
|
|
22
|
-
const namespace = sanitizeSegment(typeof namespaceRaw === 'string' ? namespaceRaw : undefined, 'general');
|
|
23
|
-
|
|
24
|
-
const categoryRaw = getAtPath(meta, 'categoryPath') ?? getAtPath(meta, 'scope.categoryPath');
|
|
25
|
-
const categoryPath = Array.isArray(categoryRaw) && categoryRaw.length > 0
|
|
26
|
-
? categoryRaw.map((x) => sanitizeSegment(typeof x === 'string' ? x : undefined, 'uncategorized'))
|
|
27
|
-
: ['uncategorized'];
|
|
28
|
-
|
|
29
|
-
const d = event.timestamp;
|
|
30
|
-
const yyyy = d.getFullYear();
|
|
31
|
-
const mm = String(d.getMonth() + 1).padStart(2, '0');
|
|
32
|
-
const dd = String(d.getDate()).padStart(2, '0');
|
|
33
|
-
|
|
34
|
-
return path.join(rootDir, 'memory', namespace, ...categoryPath, `${yyyy}-${mm}-${dd}.md`);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export class MarkdownMirror {
|
|
38
|
-
constructor(private readonly rootDir: string) {}
|
|
39
|
-
|
|
40
|
-
async append(event: MemoryEventInput, eventId?: string): Promise<void> {
|
|
41
|
-
const out = buildMirrorPath(this.rootDir, event);
|
|
42
|
-
fs.mkdirSync(path.dirname(out), { recursive: true });
|
|
43
|
-
|
|
44
|
-
const lines = [
|
|
45
|
-
'',
|
|
46
|
-
`## ${event.timestamp.toISOString()} | ${eventId ?? 'pending-id'}`,
|
|
47
|
-
`- type: ${event.eventType}`,
|
|
48
|
-
`- session: ${event.sessionId}`,
|
|
49
|
-
event.content,
|
|
50
|
-
];
|
|
51
|
-
|
|
52
|
-
await fs.promises.appendFile(out, lines.join('\n'), 'utf8');
|
|
53
|
-
await this.refreshIndex();
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
private async refreshIndex(): Promise<void> {
|
|
57
|
-
const memoryRoot = path.join(this.rootDir, 'memory');
|
|
58
|
-
await fs.promises.mkdir(memoryRoot, { recursive: true });
|
|
59
|
-
|
|
60
|
-
const files: string[] = [];
|
|
61
|
-
await this.walk(memoryRoot, files);
|
|
62
|
-
|
|
63
|
-
const mdFiles = files
|
|
64
|
-
.filter((f) => f.endsWith('.md'))
|
|
65
|
-
.map((f) => path.relative(this.rootDir, f))
|
|
66
|
-
.filter((rel) => rel !== path.join('memory', '_index.md'))
|
|
67
|
-
.sort();
|
|
68
|
-
|
|
69
|
-
const index = [
|
|
70
|
-
'# Memory Index',
|
|
71
|
-
'',
|
|
72
|
-
'Generated automatically by MarkdownMirror.',
|
|
73
|
-
'',
|
|
74
|
-
...mdFiles.map((rel) => `- ${rel}`),
|
|
75
|
-
'',
|
|
76
|
-
].join('\n');
|
|
77
|
-
|
|
78
|
-
await fs.promises.writeFile(path.join(memoryRoot, '_index.md'), index, 'utf8');
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
private async walk(dir: string, out: string[]): Promise<void> {
|
|
82
|
-
const entries = await fs.promises.readdir(dir, { withFileTypes: true });
|
|
83
|
-
for (const e of entries) {
|
|
84
|
-
const full = path.join(dir, e.name);
|
|
85
|
-
if (e.isDirectory()) {
|
|
86
|
-
await this.walk(full, out);
|
|
87
|
-
} else {
|
|
88
|
-
out.push(full);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Metadata Extractor
|
|
3
|
-
* Extracts tool-specific metadata from tool inputs and outputs
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { ToolMetadata } from './types.js';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Get file type from path
|
|
10
|
-
*/
|
|
11
|
-
function getFileType(filePath: string): string | undefined {
|
|
12
|
-
const ext = filePath.split('.').pop()?.toLowerCase();
|
|
13
|
-
if (!ext) return undefined;
|
|
14
|
-
|
|
15
|
-
const typeMap: Record<string, string> = {
|
|
16
|
-
ts: 'typescript',
|
|
17
|
-
tsx: 'typescript',
|
|
18
|
-
js: 'javascript',
|
|
19
|
-
jsx: 'javascript',
|
|
20
|
-
py: 'python',
|
|
21
|
-
rb: 'ruby',
|
|
22
|
-
go: 'go',
|
|
23
|
-
rs: 'rust',
|
|
24
|
-
java: 'java',
|
|
25
|
-
kt: 'kotlin',
|
|
26
|
-
swift: 'swift',
|
|
27
|
-
c: 'c',
|
|
28
|
-
cpp: 'cpp',
|
|
29
|
-
h: 'header',
|
|
30
|
-
hpp: 'header',
|
|
31
|
-
cs: 'csharp',
|
|
32
|
-
php: 'php',
|
|
33
|
-
html: 'html',
|
|
34
|
-
css: 'css',
|
|
35
|
-
scss: 'scss',
|
|
36
|
-
json: 'json',
|
|
37
|
-
yaml: 'yaml',
|
|
38
|
-
yml: 'yaml',
|
|
39
|
-
xml: 'xml',
|
|
40
|
-
md: 'markdown',
|
|
41
|
-
sql: 'sql',
|
|
42
|
-
sh: 'shell',
|
|
43
|
-
bash: 'shell',
|
|
44
|
-
zsh: 'shell'
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
return typeMap[ext];
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Count lines in content
|
|
52
|
-
*/
|
|
53
|
-
function countLines(content: string): number {
|
|
54
|
-
return content.split('\n').length;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Extract bash command (without arguments that might contain secrets)
|
|
59
|
-
*/
|
|
60
|
-
function extractCommand(fullCommand: string): string {
|
|
61
|
-
// Get first word (command name)
|
|
62
|
-
const parts = fullCommand.trim().split(/\s+/);
|
|
63
|
-
const command = parts[0];
|
|
64
|
-
|
|
65
|
-
// For common commands, include safe arguments
|
|
66
|
-
const safeCommands = ['git', 'npm', 'yarn', 'pnpm', 'node', 'python', 'go', 'cargo', 'make'];
|
|
67
|
-
if (safeCommands.includes(command) && parts.length > 1) {
|
|
68
|
-
// Include subcommand for these
|
|
69
|
-
return `${command} ${parts[1]}`;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return command;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Extract metadata from tool usage
|
|
77
|
-
*/
|
|
78
|
-
export function extractMetadata(
|
|
79
|
-
toolName: string,
|
|
80
|
-
input: Record<string, unknown>,
|
|
81
|
-
output: string,
|
|
82
|
-
success: boolean
|
|
83
|
-
): ToolMetadata {
|
|
84
|
-
switch (toolName) {
|
|
85
|
-
case 'Read': {
|
|
86
|
-
const filePath = input.file_path as string | undefined;
|
|
87
|
-
return {
|
|
88
|
-
filePath,
|
|
89
|
-
fileType: filePath ? getFileType(filePath) : undefined,
|
|
90
|
-
lineCount: success ? countLines(output) : undefined
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
case 'Write': {
|
|
95
|
-
const filePath = input.file_path as string | undefined;
|
|
96
|
-
const content = input.content as string | undefined;
|
|
97
|
-
return {
|
|
98
|
-
filePath,
|
|
99
|
-
fileType: filePath ? getFileType(filePath) : undefined,
|
|
100
|
-
lineCount: content ? countLines(content) : undefined
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
case 'Edit': {
|
|
105
|
-
const filePath = input.file_path as string | undefined;
|
|
106
|
-
return {
|
|
107
|
-
filePath,
|
|
108
|
-
fileType: filePath ? getFileType(filePath) : undefined
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
case 'Bash': {
|
|
113
|
-
const fullCommand = input.command as string | undefined;
|
|
114
|
-
return {
|
|
115
|
-
command: fullCommand ? extractCommand(fullCommand) : undefined
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
case 'Grep': {
|
|
120
|
-
const pattern = input.pattern as string | undefined;
|
|
121
|
-
// Count matches from output
|
|
122
|
-
const matchCount = success
|
|
123
|
-
? (output.match(/\n/g) || []).length + (output.trim() ? 1 : 0)
|
|
124
|
-
: undefined;
|
|
125
|
-
return {
|
|
126
|
-
pattern,
|
|
127
|
-
matchCount
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
case 'Glob': {
|
|
132
|
-
const pattern = input.pattern as string | undefined;
|
|
133
|
-
const matchCount = success
|
|
134
|
-
? (output.match(/\n/g) || []).length + (output.trim() ? 1 : 0)
|
|
135
|
-
: undefined;
|
|
136
|
-
return {
|
|
137
|
-
pattern,
|
|
138
|
-
matchCount
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
case 'WebFetch': {
|
|
143
|
-
const url = input.url as string | undefined;
|
|
144
|
-
// Try to extract status code from output
|
|
145
|
-
const statusMatch = output.match(/status:\s*(\d{3})/i);
|
|
146
|
-
return {
|
|
147
|
-
url,
|
|
148
|
-
statusCode: statusMatch ? parseInt(statusMatch[1], 10) : undefined
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
case 'WebSearch': {
|
|
153
|
-
return {};
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
case 'NotebookEdit': {
|
|
157
|
-
const notebookPath = input.notebook_path as string | undefined;
|
|
158
|
-
return {
|
|
159
|
-
filePath: notebookPath,
|
|
160
|
-
fileType: 'jupyter'
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
default:
|
|
165
|
-
return {};
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Create embedding content for tool observation
|
|
171
|
-
*/
|
|
172
|
-
export function createToolObservationEmbedding(
|
|
173
|
-
toolName: string,
|
|
174
|
-
metadata: ToolMetadata,
|
|
175
|
-
success: boolean
|
|
176
|
-
): string {
|
|
177
|
-
const parts: string[] = [];
|
|
178
|
-
|
|
179
|
-
parts.push(`Tool: ${toolName}`);
|
|
180
|
-
|
|
181
|
-
if (metadata.filePath) {
|
|
182
|
-
parts.push(`File: ${metadata.filePath}`);
|
|
183
|
-
}
|
|
184
|
-
if (metadata.command) {
|
|
185
|
-
parts.push(`Command: ${metadata.command}`);
|
|
186
|
-
}
|
|
187
|
-
if (metadata.pattern) {
|
|
188
|
-
parts.push(`Pattern: ${metadata.pattern}`);
|
|
189
|
-
}
|
|
190
|
-
if (metadata.url) {
|
|
191
|
-
// Only include domain for privacy
|
|
192
|
-
try {
|
|
193
|
-
const url = new URL(metadata.url);
|
|
194
|
-
parts.push(`URL: ${url.hostname}`);
|
|
195
|
-
} catch {
|
|
196
|
-
// Invalid URL, skip
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
parts.push(`Result: ${success ? 'Success' : 'Failed'}`);
|
|
201
|
-
|
|
202
|
-
return parts.join('\n');
|
|
203
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
|
|
3
|
-
export const MemoryFactTypeSchema = z.enum([
|
|
4
|
-
'decision',
|
|
5
|
-
'constraint',
|
|
6
|
-
'task_state',
|
|
7
|
-
'tool_observation',
|
|
8
|
-
'preference',
|
|
9
|
-
'code_context',
|
|
10
|
-
'summary_fact'
|
|
11
|
-
]);
|
|
12
|
-
export type MemoryFactType = z.infer<typeof MemoryFactTypeSchema>;
|
|
13
|
-
|
|
14
|
-
export const MemoryFactSchema = z.object({
|
|
15
|
-
factId: z.string(),
|
|
16
|
-
projectHash: z.string(),
|
|
17
|
-
factType: MemoryFactTypeSchema,
|
|
18
|
-
text: z.string(),
|
|
19
|
-
derivedFromEventIds: z.array(z.string()).default([]),
|
|
20
|
-
sourceKind: z.enum(['prompt', 'assistant', 'tool', 'import']),
|
|
21
|
-
confidence: z.number().min(0).max(1),
|
|
22
|
-
importance: z.number().min(0).max(1).default(0.5),
|
|
23
|
-
tags: z.array(z.string()).default([]),
|
|
24
|
-
entityRefs: z.array(z.string()).optional(),
|
|
25
|
-
fileRefs: z.array(z.string()).optional(),
|
|
26
|
-
symbolRefs: z.array(z.string()).optional(),
|
|
27
|
-
createdAt: z.string(),
|
|
28
|
-
updatedAt: z.string()
|
|
29
|
-
});
|
|
30
|
-
export type MemoryFact = z.infer<typeof MemoryFactSchema>;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
|
|
3
|
-
export const MemoryRuleSchema = z.object({
|
|
4
|
-
ruleId: z.string(),
|
|
5
|
-
projectHash: z.string().optional(),
|
|
6
|
-
scope: z.enum(['project', 'shared']),
|
|
7
|
-
ruleType: z.enum(['preference', 'workflow', 'convention', 'constraint']),
|
|
8
|
-
text: z.string(),
|
|
9
|
-
confidence: z.number().min(0).max(1),
|
|
10
|
-
evidenceIds: z.array(z.string()).default([]),
|
|
11
|
-
createdAt: z.string(),
|
|
12
|
-
updatedAt: z.string()
|
|
13
|
-
});
|
|
14
|
-
export type MemoryRule = z.infer<typeof MemoryRuleSchema>;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
|
|
3
|
-
export const MemorySummaryTypeSchema = z.enum([
|
|
4
|
-
'turn',
|
|
5
|
-
'session',
|
|
6
|
-
'project',
|
|
7
|
-
'continuity',
|
|
8
|
-
'timeline_digest'
|
|
9
|
-
]);
|
|
10
|
-
export type MemorySummaryType = z.infer<typeof MemorySummaryTypeSchema>;
|
|
11
|
-
|
|
12
|
-
export const MemorySummarySchema = z.object({
|
|
13
|
-
summaryId: z.string(),
|
|
14
|
-
summaryType: MemorySummaryTypeSchema,
|
|
15
|
-
refId: z.string(),
|
|
16
|
-
text: z.string(),
|
|
17
|
-
sourceEventIds: z.array(z.string()).default([]),
|
|
18
|
-
sourceFactIds: z.array(z.string()).default([]),
|
|
19
|
-
createdAt: z.string()
|
|
20
|
-
});
|
|
21
|
-
export type MemorySummary = z.infer<typeof MemorySummarySchema>;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
|
|
3
|
-
export const RawEventTypeSchema = z.enum([
|
|
4
|
-
'user_prompt',
|
|
5
|
-
'assistant_response',
|
|
6
|
-
'tool_output',
|
|
7
|
-
'session_marker',
|
|
8
|
-
'imported_turn'
|
|
9
|
-
]);
|
|
10
|
-
export type RawEventType = z.infer<typeof RawEventTypeSchema>;
|
|
11
|
-
|
|
12
|
-
export const PrivacyLevelSchema = z.enum(['public', 'internal', 'private', 'masked']);
|
|
13
|
-
export type PrivacyLevel = z.infer<typeof PrivacyLevelSchema>;
|
|
14
|
-
|
|
15
|
-
export const RawEventSchema = z.object({
|
|
16
|
-
eventId: z.string(),
|
|
17
|
-
projectHash: z.string(),
|
|
18
|
-
sessionId: z.string(),
|
|
19
|
-
turnId: z.string().optional(),
|
|
20
|
-
eventType: RawEventTypeSchema,
|
|
21
|
-
content: z.string(),
|
|
22
|
-
toolName: z.string().optional(),
|
|
23
|
-
sourceRef: z.string().optional(),
|
|
24
|
-
metadata: z.record(z.unknown()).default({}),
|
|
25
|
-
privacyLevel: PrivacyLevelSchema.default('internal'),
|
|
26
|
-
createdAt: z.string()
|
|
27
|
-
});
|
|
28
|
-
export type RawEvent = z.infer<typeof RawEventSchema>;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
|
|
3
|
-
export const RetrievalReasonSchema = z.enum([
|
|
4
|
-
'semantic_match',
|
|
5
|
-
'keyword_match',
|
|
6
|
-
'recent_relevance',
|
|
7
|
-
'continuity_link',
|
|
8
|
-
'entity_overlap',
|
|
9
|
-
'tool_followup',
|
|
10
|
-
'summary_fallback'
|
|
11
|
-
]);
|
|
12
|
-
export type RetrievalReason = z.infer<typeof RetrievalReasonSchema>;
|
|
13
|
-
|
|
14
|
-
export const RetrievalResultTypeSchema = z.enum([
|
|
15
|
-
'fact',
|
|
16
|
-
'summary',
|
|
17
|
-
'tool_evidence',
|
|
18
|
-
'rule',
|
|
19
|
-
'source'
|
|
20
|
-
]);
|
|
21
|
-
export type RetrievalResultType = z.infer<typeof RetrievalResultTypeSchema>;
|
|
22
|
-
|
|
23
|
-
export const RetrievalResultEnvelopeSchema = z.object({
|
|
24
|
-
id: z.string(),
|
|
25
|
-
resultType: RetrievalResultTypeSchema,
|
|
26
|
-
title: z.string().optional(),
|
|
27
|
-
snippet: z.string(),
|
|
28
|
-
score: z.number().min(0).max(1),
|
|
29
|
-
reasons: z.array(RetrievalReasonSchema).default([]),
|
|
30
|
-
sourceRef: z.string().optional(),
|
|
31
|
-
sessionId: z.string().optional(),
|
|
32
|
-
turnId: z.string().optional(),
|
|
33
|
-
metadata: z.record(z.unknown()).optional()
|
|
34
|
-
});
|
|
35
|
-
export type RetrievalResultEnvelope = z.infer<typeof RetrievalResultEnvelopeSchema>;
|