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,98 +0,0 @@
|
|
|
1
|
-
import { mkdtemp, writeFile } from 'node:fs/promises';
|
|
2
|
-
import { tmpdir } from 'node:os';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
-
import { describe, expect, it } from 'vitest';
|
|
5
|
-
import { readTranscriptTailEntries } from '../../../src/adapters/claude/transcript/transcript-reader.js';
|
|
6
|
-
import {
|
|
7
|
-
extractAssistantTextMessages,
|
|
8
|
-
extractAssistantMessages,
|
|
9
|
-
generateSessionSummary
|
|
10
|
-
} from '../../../src/adapters/claude/transcript/turn-reconstructor.js';
|
|
11
|
-
|
|
12
|
-
describe('Claude transcript reader', () => {
|
|
13
|
-
it('reads JSONL transcript tail entries and skips malformed partial lines', async () => {
|
|
14
|
-
const dir = await mkdtemp(join(tmpdir(), 'cml-transcript-'));
|
|
15
|
-
const transcriptPath = join(dir, 'transcript.jsonl');
|
|
16
|
-
await writeFile(
|
|
17
|
-
transcriptPath,
|
|
18
|
-
[
|
|
19
|
-
'{"type":"user","message":{"content":"hello"}}',
|
|
20
|
-
'not-json',
|
|
21
|
-
'null',
|
|
22
|
-
'42',
|
|
23
|
-
'{"type":"assistant","message":{"content":[{"type":"text","text":"answer"}]}}'
|
|
24
|
-
].join('\n'),
|
|
25
|
-
'utf8'
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
const entries = await readTranscriptTailEntries(transcriptPath);
|
|
29
|
-
|
|
30
|
-
expect(entries.map((entry) => entry.type)).toEqual(['user', 'assistant']);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('skips a partial first line when tail reading starts mid-record', async () => {
|
|
34
|
-
const dir = await mkdtemp(join(tmpdir(), 'cml-transcript-'));
|
|
35
|
-
const transcriptPath = join(dir, 'transcript.jsonl');
|
|
36
|
-
const firstLine = `{"type":"user","message":{"content":"${'x'.repeat(500)}"}}`;
|
|
37
|
-
const secondLine = '{"type":"user","message":{"content":"recent question"}}';
|
|
38
|
-
const thirdLine = '{"type":"assistant","message":{"content":[{"type":"text","text":"recent answer"}]}}';
|
|
39
|
-
await writeFile(transcriptPath, [firstLine, secondLine, thirdLine].join('\n'), 'utf8');
|
|
40
|
-
|
|
41
|
-
const maxBytes = Buffer.byteLength(`${secondLine}\n${thirdLine}`) + 10;
|
|
42
|
-
const entries = await readTranscriptTailEntries(transcriptPath, { maxBytes });
|
|
43
|
-
|
|
44
|
-
expect(entries.map((entry) => entry.type)).toEqual(['user', 'assistant']);
|
|
45
|
-
expect(entries[0]?.message?.content).toBe('recent question');
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('returns an empty entry list for missing transcript files', async () => {
|
|
49
|
-
await expect(readTranscriptTailEntries('/tmp/non-existent-claude-transcript.jsonl')).resolves.toEqual([]);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
describe('Claude turn reconstructor', () => {
|
|
54
|
-
it('extracts assistant text blocks and joins multi-part text content', async () => {
|
|
55
|
-
const messages = extractAssistantTextMessages([
|
|
56
|
-
{ type: 'user', message: { content: 'ignored' } },
|
|
57
|
-
{
|
|
58
|
-
type: 'assistant',
|
|
59
|
-
message: {
|
|
60
|
-
content: [
|
|
61
|
-
{ type: 'text', text: 'first' },
|
|
62
|
-
{ type: 'tool_use', id: 'tool-1' },
|
|
63
|
-
{ type: 'text', text: 'second' }
|
|
64
|
-
]
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
{ type: 'assistant', message: { content: [{ type: 'tool_use', id: 'tool-2' }] } }
|
|
68
|
-
]);
|
|
69
|
-
|
|
70
|
-
expect(messages).toEqual(['first\nsecond']);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('reads assistant text messages from a transcript file', async () => {
|
|
74
|
-
const dir = await mkdtemp(join(tmpdir(), 'cml-transcript-'));
|
|
75
|
-
const transcriptPath = join(dir, 'transcript.jsonl');
|
|
76
|
-
await writeFile(
|
|
77
|
-
transcriptPath,
|
|
78
|
-
'{"type":"assistant","message":{"content":[{"type":"text","text":"final answer"}]}}\n',
|
|
79
|
-
'utf8'
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
await expect(extractAssistantMessages(transcriptPath)).resolves.toEqual(['final answer']);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('generates deterministic summaries from session events', () => {
|
|
86
|
-
const summary = generateSessionSummary([
|
|
87
|
-
{ eventType: 'user_prompt', content: 'How should we refactor transcript parsing?' },
|
|
88
|
-
{ eventType: 'agent_response', content: 'Move it behind adapter modules.' },
|
|
89
|
-
{ eventType: 'tool_observation', content: 'ignored' }
|
|
90
|
-
]);
|
|
91
|
-
|
|
92
|
-
expect(summary).toBe(
|
|
93
|
-
'Session with 1 user prompts and 1 responses.\n' +
|
|
94
|
-
'Topics discussed:\n' +
|
|
95
|
-
'- How should we refactor transcript parsing?'
|
|
96
|
-
);
|
|
97
|
-
});
|
|
98
|
-
});
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { MemoryQueryService } from '../../src/core/engine/memory-query-service.js';
|
|
4
|
-
import type { MemoryEvent } from '../../src/core/types.js';
|
|
5
|
-
import {
|
|
6
|
-
filterHookInjectableMemories,
|
|
7
|
-
getHookInjectionPolicy,
|
|
8
|
-
summarizeHookInjectionConfidence,
|
|
9
|
-
type HookMemoryCandidate
|
|
10
|
-
} from '../../src/adapters/claude/hooks/prompt-injection-policy.js';
|
|
11
|
-
|
|
12
|
-
function event(id: string, content = 'low confidence keyword result'): MemoryEvent {
|
|
13
|
-
return {
|
|
14
|
-
id,
|
|
15
|
-
eventType: 'user_prompt',
|
|
16
|
-
sessionId: 'session-1',
|
|
17
|
-
timestamp: new Date('2026-05-02T00:00:00.000Z'),
|
|
18
|
-
content,
|
|
19
|
-
canonicalKey: `test/${id}`,
|
|
20
|
-
dedupeKey: `session-1:${id}`,
|
|
21
|
-
metadata: {}
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
describe('Claude hook prompt injection policy', () => {
|
|
26
|
-
it('filters low-confidence hook candidates before prompt injection', () => {
|
|
27
|
-
const candidates: HookMemoryCandidate[] = [
|
|
28
|
-
{ id: 'low-semantic', type: 'agent_response', content: 'maybe related', score: 0.58, source: 'semantic' },
|
|
29
|
-
{ id: 'low-keyword', type: 'user_prompt', content: 'weak keyword rescue', score: 0.49, source: 'keyword' },
|
|
30
|
-
{ id: 'high-keyword', type: 'user_prompt', content: 'exact high-confidence keyword', score: 0.84, source: 'keyword' },
|
|
31
|
-
{ id: 'high-semantic', type: 'session_summary', content: 'high semantic match', score: 0.76, source: 'semantic' }
|
|
32
|
-
];
|
|
33
|
-
|
|
34
|
-
expect(filterHookInjectableMemories(candidates, getHookInjectionPolicy())).toEqual([
|
|
35
|
-
candidates[2],
|
|
36
|
-
candidates[3]
|
|
37
|
-
]);
|
|
38
|
-
expect(summarizeHookInjectionConfidence(candidates)).toBe('high');
|
|
39
|
-
expect(summarizeHookInjectionConfidence([])).toBe('none');
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('limits injected hook memories by highest confidence rather than first passing candidate', () => {
|
|
43
|
-
const candidates: HookMemoryCandidate[] = [
|
|
44
|
-
{ id: 'medium-first', type: 'session_summary', content: 'passes but weaker', score: 0.67, source: 'semantic' },
|
|
45
|
-
{ id: 'best-later', type: 'user_prompt', content: 'best exact keyword', score: 0.93, source: 'keyword' },
|
|
46
|
-
{ id: 'second-best-later', type: 'agent_response', content: 'strong semantic match', score: 0.88, source: 'semantic' }
|
|
47
|
-
];
|
|
48
|
-
|
|
49
|
-
expect(filterHookInjectableMemories(candidates, { ...getHookInjectionPolicy(), maxMemories: 2 }))
|
|
50
|
-
.toEqual([candidates[1], candidates[2]]);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('uses bounded hook policy thresholds so unsafe env overrides cannot inject weak memories', () => {
|
|
54
|
-
const policy = getHookInjectionPolicy({
|
|
55
|
-
CLAUDE_MEMORY_HOOK_INJECTION_MIN_SCORE: '-1',
|
|
56
|
-
CLAUDE_MEMORY_HOOK_SEMANTIC_MIN_SCORE: '2',
|
|
57
|
-
CLAUDE_MEMORY_HOOK_KEYWORD_MIN_SCORE: 'not-a-number',
|
|
58
|
-
CLAUDE_MEMORY_HOOK_FALLBACK_KEYWORD_MIN_SCORE: '-0.2',
|
|
59
|
-
CLAUDE_MEMORY_HOOK_MAX_INJECTED: '2'
|
|
60
|
-
} as NodeJS.ProcessEnv);
|
|
61
|
-
|
|
62
|
-
expect(policy).toEqual({
|
|
63
|
-
minScore: 0.65,
|
|
64
|
-
semanticMinScore: 0.65,
|
|
65
|
-
keywordMinScore: 0.7,
|
|
66
|
-
fallbackKeywordMinScore: 0.8,
|
|
67
|
-
maxMemories: 2
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
expect(filterHookInjectableMemories([
|
|
71
|
-
{ id: 'weak-unknown', type: 'user_prompt', content: 'weak unknown source', score: 0.1, source: 'unknown' },
|
|
72
|
-
{ id: 'fallback-too-weak', type: 'user_prompt', content: 'weak fallback', score: 0.79, source: 'keyword', fallback: true }
|
|
73
|
-
], policy)).toEqual([]);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('keeps regular CLI/query search behavior independent from hook injection policy', async () => {
|
|
77
|
-
const memory = event('regular-low');
|
|
78
|
-
const service = new MemoryQueryService(
|
|
79
|
-
async () => {},
|
|
80
|
-
{
|
|
81
|
-
keywordSearch: async () => [{ event: memory, rank: -0.5 }],
|
|
82
|
-
getSessionEvents: async () => [memory],
|
|
83
|
-
getRecentEvents: async () => [memory]
|
|
84
|
-
}
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
const regularResults = await service.keywordSearch('weak keyword rescue', { topK: 1, minScore: 0.2 });
|
|
88
|
-
expect(regularResults).toEqual([{ event: memory, score: 1 }]);
|
|
89
|
-
|
|
90
|
-
const hookCandidates: HookMemoryCandidate[] = regularResults.map((result) => ({
|
|
91
|
-
id: result.event.id,
|
|
92
|
-
type: result.event.eventType,
|
|
93
|
-
content: result.event.content,
|
|
94
|
-
score: 0.5,
|
|
95
|
-
source: 'keyword'
|
|
96
|
-
}));
|
|
97
|
-
expect(filterHookInjectableMemories(hookCandidates, getHookInjectionPolicy())).toEqual([]);
|
|
98
|
-
});
|
|
99
|
-
});
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
-
import { describe, expect, it } from 'vitest';
|
|
3
|
-
|
|
4
|
-
const apiModules = [
|
|
5
|
-
'chat',
|
|
6
|
-
'citations',
|
|
7
|
-
'events',
|
|
8
|
-
'health',
|
|
9
|
-
'projects',
|
|
10
|
-
'search',
|
|
11
|
-
'sessions',
|
|
12
|
-
'stats',
|
|
13
|
-
'turns',
|
|
14
|
-
'utils'
|
|
15
|
-
];
|
|
16
|
-
|
|
17
|
-
describe('app-layer entrypoint boundaries', () => {
|
|
18
|
-
it('keeps CLI implementation under src/apps/cli while preserving src/cli compatibility', () => {
|
|
19
|
-
const packageJson = JSON.parse(readFileSync('package.json', 'utf8')) as {
|
|
20
|
-
scripts?: Record<string, string>;
|
|
21
|
-
};
|
|
22
|
-
const buildScript = readFileSync('scripts/build.ts', 'utf8');
|
|
23
|
-
const cliCompatSource = readFileSync('src/cli/index.ts', 'utf8');
|
|
24
|
-
const cliDisclosureCompatSource = readFileSync('src/cli/retrieval-disclosure-output.ts', 'utf8');
|
|
25
|
-
|
|
26
|
-
expect(packageJson.scripts?.dev).toBe('tsx src/apps/cli/index.ts');
|
|
27
|
-
expect(buildScript).toContain("entryPoints: ['src/apps/cli/index.ts']");
|
|
28
|
-
expect(cliCompatSource).toContain("../apps/cli/index.js");
|
|
29
|
-
expect(cliDisclosureCompatSource).toContain("../apps/cli/retrieval-disclosure-output.js");
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('keeps server implementation under src/apps/server while preserving src/server compatibility', () => {
|
|
33
|
-
const buildScript = readFileSync('scripts/build.ts', 'utf8');
|
|
34
|
-
const serverCompatSource = readFileSync('src/server/index.ts', 'utf8');
|
|
35
|
-
const apiIndexCompatSource = readFileSync('src/server/api/index.ts', 'utf8');
|
|
36
|
-
|
|
37
|
-
expect(buildScript).toContain("entryPoints: ['src/apps/server/index.ts']");
|
|
38
|
-
expect(buildScript).toContain("entryPoints: ['src/apps/server/api/index.ts']");
|
|
39
|
-
expect(serverCompatSource).toContain("../apps/server/index.js");
|
|
40
|
-
expect(apiIndexCompatSource).toContain("../../apps/server/api/index.js");
|
|
41
|
-
|
|
42
|
-
for (const moduleName of apiModules) {
|
|
43
|
-
const compatPath = `src/server/api/${moduleName}.ts`;
|
|
44
|
-
expect(existsSync(compatPath), `${compatPath} should exist`).toBe(true);
|
|
45
|
-
expect(readFileSync(compatPath, 'utf8')).toContain(`../../apps/server/api/${moduleName}.js`);
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
});
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
buildHookCommand,
|
|
5
|
-
getHooksConfig,
|
|
6
|
-
mergePluginHooksIntoSettings,
|
|
7
|
-
removePluginHooksFromSettings,
|
|
8
|
-
type ClaudeSettingsWithHooks
|
|
9
|
-
} from '../../src/apps/cli/claude-settings-hooks.js';
|
|
10
|
-
|
|
11
|
-
describe('Claude Code hook settings helpers', () => {
|
|
12
|
-
it('quotes hook paths so plugin installs work when the path contains spaces', () => {
|
|
13
|
-
expect(buildHookCommand('/tmp/project with spaces/dist', 'user-prompt-submit.js'))
|
|
14
|
-
.toBe("node '/tmp/project with spaces/dist/hooks/user-prompt-submit.js'");
|
|
15
|
-
|
|
16
|
-
const complexCommand = buildHookCommand("/tmp/project with $dollars 'quotes' and `ticks`/dist", 'stop.js');
|
|
17
|
-
expect(complexCommand).toContain("'\\''quotes'\\''");
|
|
18
|
-
expect(complexCommand).toContain('$dollars');
|
|
19
|
-
expect(complexCommand).toContain('`ticks`');
|
|
20
|
-
|
|
21
|
-
expect(getHooksConfig('/tmp/project with spaces/dist').UserPromptSubmit?.[0].hooks[0].command)
|
|
22
|
-
.toBe("node '/tmp/project with spaces/dist/hooks/user-prompt-submit.js'");
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('merges plugin hooks without replacing unrelated hooks in the same categories', () => {
|
|
26
|
-
const settings: ClaudeSettingsWithHooks = {
|
|
27
|
-
theme: 'dark',
|
|
28
|
-
hooks: {
|
|
29
|
-
UserPromptSubmit: [
|
|
30
|
-
{
|
|
31
|
-
matcher: 'existing',
|
|
32
|
-
hooks: [{ type: 'command', command: 'node /other/plugin.js' }]
|
|
33
|
-
}
|
|
34
|
-
],
|
|
35
|
-
Stop: [
|
|
36
|
-
{
|
|
37
|
-
matcher: 'old-plugin',
|
|
38
|
-
hooks: [{ type: 'command', command: 'node /old/claude-memory-layer/dist/hooks/stop.js' }]
|
|
39
|
-
}
|
|
40
|
-
]
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const merged = mergePluginHooksIntoSettings(settings, '/new/plugin dist');
|
|
45
|
-
|
|
46
|
-
expect(merged.theme).toBe('dark');
|
|
47
|
-
expect(merged.hooks?.UserPromptSubmit).toEqual([
|
|
48
|
-
{
|
|
49
|
-
matcher: 'existing',
|
|
50
|
-
hooks: [{ type: 'command', command: 'node /other/plugin.js' }]
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
matcher: '',
|
|
54
|
-
hooks: [{ type: 'command', command: "node '/new/plugin dist/hooks/user-prompt-submit.js'" }]
|
|
55
|
-
}
|
|
56
|
-
]);
|
|
57
|
-
expect(merged.hooks?.Stop).toEqual([
|
|
58
|
-
{
|
|
59
|
-
matcher: '',
|
|
60
|
-
hooks: [{ type: 'command', command: "node '/new/plugin dist/hooks/stop.js'" }]
|
|
61
|
-
}
|
|
62
|
-
]);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('uninstall removes only claude-memory-layer hook commands and leaves other hooks intact', () => {
|
|
66
|
-
const settings: ClaudeSettingsWithHooks = {
|
|
67
|
-
hooks: {
|
|
68
|
-
SessionStart: [
|
|
69
|
-
{
|
|
70
|
-
matcher: 'keep-and-remove',
|
|
71
|
-
hooks: [
|
|
72
|
-
{ type: 'command', command: 'node /opt/claude-memory-layer/dist/hooks/session-start.js' },
|
|
73
|
-
{ type: 'command', command: 'node /other/session-start-helper.js' }
|
|
74
|
-
]
|
|
75
|
-
}
|
|
76
|
-
],
|
|
77
|
-
PostToolUse: [
|
|
78
|
-
{
|
|
79
|
-
matcher: 'keep',
|
|
80
|
-
hooks: [
|
|
81
|
-
{ type: 'command', command: 'node /other/post-tool-use-helper.js' },
|
|
82
|
-
{ type: 'command', command: 'node /other-plugin/hooks/post-tool-use.js' }
|
|
83
|
-
]
|
|
84
|
-
}
|
|
85
|
-
]
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
const removed = removePluginHooksFromSettings(settings, '/opt/claude-memory-layer/dist');
|
|
90
|
-
|
|
91
|
-
expect(removed.hooks?.SessionStart).toEqual([
|
|
92
|
-
{
|
|
93
|
-
matcher: 'keep-and-remove',
|
|
94
|
-
hooks: [{ type: 'command', command: 'node /other/session-start-helper.js' }]
|
|
95
|
-
}
|
|
96
|
-
]);
|
|
97
|
-
expect(removed.hooks?.PostToolUse).toEqual([
|
|
98
|
-
{
|
|
99
|
-
matcher: 'keep',
|
|
100
|
-
hooks: [
|
|
101
|
-
{ type: 'command', command: 'node /other/post-tool-use-helper.js' },
|
|
102
|
-
{ type: 'command', command: 'node /other-plugin/hooks/post-tool-use.js' }
|
|
103
|
-
]
|
|
104
|
-
}
|
|
105
|
-
]);
|
|
106
|
-
});
|
|
107
|
-
});
|
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
formatDisclosureExpansion,
|
|
4
|
-
formatDisclosureSearch,
|
|
5
|
-
formatDisclosureSource,
|
|
6
|
-
formatPlainSearchResults
|
|
7
|
-
} from '../../src/apps/cli/retrieval-disclosure-output.js';
|
|
8
|
-
|
|
9
|
-
describe('retrieval disclosure CLI output', () => {
|
|
10
|
-
it('formats compact search envelopes with type badges, reasons, and source refs', () => {
|
|
11
|
-
const out = formatDisclosureSearch({
|
|
12
|
-
results: [
|
|
13
|
-
{
|
|
14
|
-
id: 'event:e1',
|
|
15
|
-
resultType: 'tool_evidence',
|
|
16
|
-
title: 'Tool evidence',
|
|
17
|
-
snippet: 'Applied checkout fix in src/cart.ts',
|
|
18
|
-
score: 0.91,
|
|
19
|
-
reasons: ['semantic_match', 'tool_followup'],
|
|
20
|
-
sourceRef: 'event:e1',
|
|
21
|
-
sessionId: 'session-1234567890'
|
|
22
|
-
}
|
|
23
|
-
],
|
|
24
|
-
meta: {
|
|
25
|
-
total: 1,
|
|
26
|
-
usedVector: true,
|
|
27
|
-
usedKeyword: true,
|
|
28
|
-
fallbackApplied: false
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
expect(out).toContain('🔎 Progressive Search Results');
|
|
33
|
-
expect(out).toContain('Meta: total=1 vector=yes keyword=yes fallback=no');
|
|
34
|
-
expect(out).toContain('[tool_evidence] Tool evidence');
|
|
35
|
-
expect(out).toContain('event:e1');
|
|
36
|
-
expect(out).toContain('semantic_match, tool_followup');
|
|
37
|
-
expect(out).toContain('session-');
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('formats expand output with target, surrounding results, sources, and expanded context', () => {
|
|
41
|
-
const out = formatDisclosureExpansion({
|
|
42
|
-
target: {
|
|
43
|
-
id: 'event:e2',
|
|
44
|
-
resultType: 'source',
|
|
45
|
-
title: 'Agent response',
|
|
46
|
-
snippet: 'Use the disclosure API',
|
|
47
|
-
score: 1,
|
|
48
|
-
reasons: ['continuity_link'],
|
|
49
|
-
sourceRef: 'event:e2'
|
|
50
|
-
},
|
|
51
|
-
surroundingFacts: [
|
|
52
|
-
{
|
|
53
|
-
id: 'event:e1',
|
|
54
|
-
resultType: 'source',
|
|
55
|
-
snippet: 'Earlier user prompt',
|
|
56
|
-
score: 1,
|
|
57
|
-
reasons: ['continuity_link'],
|
|
58
|
-
sourceRef: 'event:e1'
|
|
59
|
-
}
|
|
60
|
-
],
|
|
61
|
-
relatedSources: [{ sourceRef: 'event:e2', sourceType: 'raw_event', eventIds: ['e2'] }],
|
|
62
|
-
expandedContext: '[agent_response] Use the disclosure API'
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
expect(out).toContain('🧩 Expanded Retrieval Result');
|
|
66
|
-
expect(out).toContain('Target');
|
|
67
|
-
expect(out).toContain('Surrounding');
|
|
68
|
-
expect(out).toContain('Sources');
|
|
69
|
-
expect(out).toContain('[agent_response] Use the disclosure API');
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('formats shared disclosure provenance explicitly in expansion and source output', () => {
|
|
73
|
-
const expansionOut = formatDisclosureExpansion({
|
|
74
|
-
target: {
|
|
75
|
-
id: 'shared:shared-1',
|
|
76
|
-
resultType: 'rule',
|
|
77
|
-
title: 'Shared checkout troubleshooting',
|
|
78
|
-
snippet: 'clear cache and retry',
|
|
79
|
-
score: 0.88,
|
|
80
|
-
reasons: ['semantic_match'],
|
|
81
|
-
sourceRef: 'shared:shared-1',
|
|
82
|
-
metadata: {
|
|
83
|
-
sourceProjectHash: 'project-a',
|
|
84
|
-
sourceEntryId: 'e-shared',
|
|
85
|
-
topics: ['checkout']
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
relatedSources: [
|
|
89
|
-
{
|
|
90
|
-
sourceRef: 'shared:shared-1',
|
|
91
|
-
sourceType: 'shared_troubleshooting',
|
|
92
|
-
eventIds: [],
|
|
93
|
-
metadata: {
|
|
94
|
-
sourceProjectHash: 'project-a',
|
|
95
|
-
sourceEntryId: 'e-shared',
|
|
96
|
-
topics: ['checkout']
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
],
|
|
100
|
-
expandedContext: '[shared_troubleshooting] Shared checkout troubleshooting\nRoot cause: stale cache'
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
const sourceOut = formatDisclosureSource({
|
|
104
|
-
sourceRef: 'shared:shared-1',
|
|
105
|
-
sourceType: 'shared_troubleshooting',
|
|
106
|
-
eventIds: [],
|
|
107
|
-
rawEvents: [],
|
|
108
|
-
metadata: {
|
|
109
|
-
sourceProjectHash: 'project-a',
|
|
110
|
-
sourceEntryId: 'e-shared',
|
|
111
|
-
topics: ['checkout'],
|
|
112
|
-
rootCause: 'stale cache',
|
|
113
|
-
solution: 'clear cache and retry'
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
expect(expansionOut).toContain('shared_troubleshooting');
|
|
118
|
-
expect(expansionOut).toContain('sourceProjectHash: project-a');
|
|
119
|
-
expect(expansionOut).toContain('topics: checkout');
|
|
120
|
-
expect(sourceOut).toContain('Shared Metadata');
|
|
121
|
-
expect(sourceOut).toContain('rootCause: stale cache');
|
|
122
|
-
expect(sourceOut).toContain('No local raw events for this shared source.');
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it('formats source output with source type, event ids, and raw event previews', () => {
|
|
126
|
-
const out = formatDisclosureSource({
|
|
127
|
-
sourceRef: 'event:e3',
|
|
128
|
-
sourceType: 'raw_event',
|
|
129
|
-
eventIds: ['e3'],
|
|
130
|
-
rawEvents: [
|
|
131
|
-
{
|
|
132
|
-
id: 'e3',
|
|
133
|
-
sessionId: 'session-1',
|
|
134
|
-
eventType: 'user_prompt',
|
|
135
|
-
content: 'Show source details',
|
|
136
|
-
canonicalKey: 'canonical/e3',
|
|
137
|
-
dedupeKey: 'session-1:e3',
|
|
138
|
-
timestamp: new Date('2026-02-24T00:00:00.000Z'),
|
|
139
|
-
metadata: {}
|
|
140
|
-
}
|
|
141
|
-
]
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
expect(out).toContain('📎 Retrieval Source');
|
|
145
|
-
expect(out).toContain('sourceType: raw_event');
|
|
146
|
-
expect(out).toContain('eventIds: e3');
|
|
147
|
-
expect(out).toContain('[user_prompt] Show source details');
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
it('formats plain search output with shared memories when includeShared is used', () => {
|
|
151
|
-
const out = formatPlainSearchResults({
|
|
152
|
-
memories: [
|
|
153
|
-
{
|
|
154
|
-
event: {
|
|
155
|
-
id: 'e1',
|
|
156
|
-
sessionId: 'session-1234567890',
|
|
157
|
-
eventType: 'agent_response',
|
|
158
|
-
content: 'Local checkout fix details',
|
|
159
|
-
canonicalKey: 'canonical/e1',
|
|
160
|
-
dedupeKey: 'session-1234567890:e1',
|
|
161
|
-
timestamp: new Date('2026-02-24T00:00:00.000Z'),
|
|
162
|
-
metadata: {}
|
|
163
|
-
},
|
|
164
|
-
score: 0.91
|
|
165
|
-
}
|
|
166
|
-
],
|
|
167
|
-
matchResult: {
|
|
168
|
-
match: {
|
|
169
|
-
event: {
|
|
170
|
-
id: 'e1',
|
|
171
|
-
sessionId: 'session-1234567890',
|
|
172
|
-
eventType: 'agent_response',
|
|
173
|
-
content: 'Local checkout fix details',
|
|
174
|
-
canonicalKey: 'canonical/e1',
|
|
175
|
-
dedupeKey: 'session-1234567890:e1',
|
|
176
|
-
timestamp: new Date('2026-02-24T00:00:00.000Z'),
|
|
177
|
-
metadata: {}
|
|
178
|
-
},
|
|
179
|
-
score: 0.91
|
|
180
|
-
},
|
|
181
|
-
confidence: 'high'
|
|
182
|
-
},
|
|
183
|
-
totalTokens: 10,
|
|
184
|
-
context: 'Local checkout fix details',
|
|
185
|
-
sharedMemories: [
|
|
186
|
-
{
|
|
187
|
-
entryId: 'shared-1',
|
|
188
|
-
sourceProjectHash: 'project-a',
|
|
189
|
-
sourceEntryId: 'e-shared',
|
|
190
|
-
title: 'Shared checkout troubleshooting',
|
|
191
|
-
symptoms: ['checkout fails'],
|
|
192
|
-
rootCause: 'stale cache',
|
|
193
|
-
solution: 'clear cache and retry',
|
|
194
|
-
topics: ['checkout'],
|
|
195
|
-
confidence: 0.88,
|
|
196
|
-
usageCount: 3,
|
|
197
|
-
promotedAt: new Date('2026-02-23T00:00:00.000Z'),
|
|
198
|
-
createdAt: new Date('2026-02-23T00:00:00.000Z')
|
|
199
|
-
}
|
|
200
|
-
]
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
expect(out).toContain('📚 Search Results');
|
|
204
|
-
expect(out).toContain('Total local memories found: 1');
|
|
205
|
-
expect(out).toContain('Shared memories found: 1');
|
|
206
|
-
expect(out).toContain('🌐 Shared Memories');
|
|
207
|
-
expect(out).toContain('Shared checkout troubleshooting');
|
|
208
|
-
expect(out).toContain('Source: shared:shared-1');
|
|
209
|
-
expect(out).toContain('Project: project-a');
|
|
210
|
-
expect(out).toContain('Solution: clear cache and retry');
|
|
211
|
-
});
|
|
212
|
-
});
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import type { ImportResult } from '../../src/services/session-history-importer.js';
|
|
3
|
-
|
|
4
|
-
const { runCodexImportOnce } = await import('../../src/apps/cli/codex-import-runner.js');
|
|
5
|
-
|
|
6
|
-
function makeImportResult(overrides: Partial<ImportResult> = {}): ImportResult {
|
|
7
|
-
return {
|
|
8
|
-
totalSessions: 1,
|
|
9
|
-
totalMessages: 2,
|
|
10
|
-
importedPrompts: 1,
|
|
11
|
-
importedResponses: 1,
|
|
12
|
-
skippedDuplicates: 0,
|
|
13
|
-
errors: [],
|
|
14
|
-
...overrides
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function makeService() {
|
|
19
|
-
return {
|
|
20
|
-
initialize: vi.fn(async () => undefined),
|
|
21
|
-
shutdown: vi.fn(async () => undefined),
|
|
22
|
-
processPendingEmbeddings: vi.fn(async () => 2),
|
|
23
|
-
ensureEmbeddingModelForImport: vi.fn(async () => ({ changed: false, previousModel: null, currentModel: 'test', enqueued: 0 }))
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
describe('Codex import runner', () => {
|
|
28
|
-
let projectService: ReturnType<typeof makeService>;
|
|
29
|
-
let globalService: ReturnType<typeof makeService>;
|
|
30
|
-
let importer: {
|
|
31
|
-
importProject: ReturnType<typeof vi.fn>;
|
|
32
|
-
importAll: ReturnType<typeof vi.fn>;
|
|
33
|
-
importSessionFile: ReturnType<typeof vi.fn>;
|
|
34
|
-
};
|
|
35
|
-
let deps: Parameters<typeof runCodexImportOnce>[1];
|
|
36
|
-
|
|
37
|
-
beforeEach(() => {
|
|
38
|
-
projectService = makeService();
|
|
39
|
-
globalService = makeService();
|
|
40
|
-
importer = {
|
|
41
|
-
importProject: vi.fn(async () => makeImportResult()),
|
|
42
|
-
importAll: vi.fn(async () => makeImportResult({ totalSessions: 3 })),
|
|
43
|
-
importSessionFile: vi.fn(async () => makeImportResult())
|
|
44
|
-
};
|
|
45
|
-
deps = {
|
|
46
|
-
cwd: () => '/repo/current',
|
|
47
|
-
getDefaultMemoryService: vi.fn(() => globalService as never),
|
|
48
|
-
getMemoryServiceForProject: vi.fn(() => projectService as never),
|
|
49
|
-
createImporter: vi.fn(() => importer as never),
|
|
50
|
-
onProgress: vi.fn()
|
|
51
|
-
};
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('imports the current project from Codex sessions into the project-scoped memory service', async () => {
|
|
55
|
-
const outcome = await runCodexImportOnce({ sessionsDir: '/tmp/codex-sessions', limit: '9', sessionLimit: '1' }, deps);
|
|
56
|
-
|
|
57
|
-
expect(deps?.getMemoryServiceForProject).toHaveBeenCalledWith('/repo/current');
|
|
58
|
-
expect(deps?.getDefaultMemoryService).not.toHaveBeenCalled();
|
|
59
|
-
expect(deps?.createImporter).toHaveBeenCalledWith(projectService, { sessionsDir: '/tmp/codex-sessions' });
|
|
60
|
-
expect(projectService.initialize).toHaveBeenCalledTimes(1);
|
|
61
|
-
expect(projectService.ensureEmbeddingModelForImport).toHaveBeenCalledWith({ autoMigrate: true });
|
|
62
|
-
expect(importer.importProject).toHaveBeenCalledWith('/repo/current', expect.objectContaining({
|
|
63
|
-
projectPath: '/repo/current',
|
|
64
|
-
limit: 9,
|
|
65
|
-
sessionLimit: 1,
|
|
66
|
-
onProgress: deps?.onProgress
|
|
67
|
-
}));
|
|
68
|
-
expect(projectService.processPendingEmbeddings).toHaveBeenCalledTimes(1);
|
|
69
|
-
expect(projectService.shutdown).toHaveBeenCalledTimes(1);
|
|
70
|
-
expect(outcome).toMatchObject({ mode: 'project', storageScope: 'project', embedCount: 2 });
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('uses global storage only for explicit all-session imports without a project', async () => {
|
|
74
|
-
const outcome = await runCodexImportOnce({ all: true, processEmbeddings: false }, deps);
|
|
75
|
-
|
|
76
|
-
expect(deps?.getDefaultMemoryService).toHaveBeenCalledTimes(1);
|
|
77
|
-
expect(deps?.getMemoryServiceForProject).not.toHaveBeenCalled();
|
|
78
|
-
expect(importer.importAll).toHaveBeenCalledWith(expect.objectContaining({ force: undefined }));
|
|
79
|
-
expect(globalService.processPendingEmbeddings).not.toHaveBeenCalled();
|
|
80
|
-
expect(globalService.shutdown).toHaveBeenCalledTimes(1);
|
|
81
|
-
expect(outcome).toMatchObject({ mode: 'all', storageScope: 'global', embedCount: 0 });
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('imports a single Codex session file into the selected project scope', async () => {
|
|
85
|
-
await runCodexImportOnce({ project: '/repo/selected', session: '/tmp/session.jsonl', force: true }, deps);
|
|
86
|
-
|
|
87
|
-
expect(deps?.getMemoryServiceForProject).toHaveBeenCalledWith('/repo/selected');
|
|
88
|
-
expect(importer.importSessionFile).toHaveBeenCalledWith('/tmp/session.jsonl', expect.objectContaining({
|
|
89
|
-
projectPath: '/repo/selected',
|
|
90
|
-
force: true
|
|
91
|
-
}));
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it('rejects non-decimal integer limits instead of partially parsing them', async () => {
|
|
95
|
-
await expect(runCodexImportOnce({ limit: '1foo' }, deps)).rejects.toThrow('Invalid --limit');
|
|
96
|
-
await expect(runCodexImportOnce({ sessionLimit: '1.5' }, deps)).rejects.toThrow('Invalid --session-limit');
|
|
97
|
-
await expect(runCodexImportOnce({ sessionLimit: '1e2' }, deps)).rejects.toThrow('Invalid --session-limit');
|
|
98
|
-
});
|
|
99
|
-
});
|