cognitive-core 0.2.1 → 0.2.2
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/dist/atlas.d.ts +10 -0
- package/dist/atlas.d.ts.map +1 -1
- package/dist/atlas.js +65 -0
- package/dist/atlas.js.map +1 -1
- package/dist/learning/pipeline.d.ts +4 -31
- package/dist/learning/pipeline.d.ts.map +1 -1
- package/dist/learning/pipeline.js +12 -64
- package/dist/learning/pipeline.js.map +1 -1
- package/dist/memory/curated-loader.d.ts +21 -4
- package/dist/memory/curated-loader.d.ts.map +1 -1
- package/dist/memory/curated-loader.js +53 -16
- package/dist/memory/curated-loader.js.map +1 -1
- package/dist/memory/index.d.ts +2 -1
- package/dist/memory/index.d.ts.map +1 -1
- package/dist/memory/index.js +3 -1
- package/dist/memory/index.js.map +1 -1
- package/dist/memory/playbook.d.ts +6 -0
- package/dist/memory/playbook.d.ts.map +1 -1
- package/dist/memory/playbook.js +15 -0
- package/dist/memory/playbook.js.map +1 -1
- package/dist/memory/source-resolver.d.ts +120 -0
- package/dist/memory/source-resolver.d.ts.map +1 -0
- package/dist/memory/source-resolver.js +300 -0
- package/dist/memory/source-resolver.js.map +1 -0
- package/dist/types/config.d.ts +141 -0
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/config.js +40 -0
- package/dist/types/config.js.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/workspace/types.d.ts +12 -54
- package/dist/workspace/types.d.ts.map +1 -1
- package/dist/workspace/types.js.map +1 -1
- package/package.json +2 -2
- package/playbooks/compound-engineering/adversarial-review.json +51 -0
- package/playbooks/compound-engineering/agent-native-architecture.json +59 -0
- package/playbooks/compound-engineering/agent-native-review.json +54 -0
- package/playbooks/compound-engineering/api-contract-review.json +52 -0
- package/playbooks/compound-engineering/brainstorm-requirements.json +55 -0
- package/playbooks/compound-engineering/bug-reproduction.json +62 -0
- package/playbooks/compound-engineering/confidence-calibration.json +49 -0
- package/playbooks/compound-engineering/correctness-review.json +49 -0
- package/playbooks/compound-engineering/data-migration-safety.json +59 -0
- package/playbooks/compound-engineering/deployment-verification.json +63 -0
- package/playbooks/compound-engineering/error-recovery-patterns.json +53 -0
- package/playbooks/compound-engineering/implementation-planning.json +64 -0
- package/playbooks/compound-engineering/issue-pattern-analysis.json +53 -0
- package/playbooks/compound-engineering/knowledge-compounding.json +63 -0
- package/playbooks/compound-engineering/learnings-research.json +54 -0
- package/playbooks/compound-engineering/maintainability-review.json +49 -0
- package/playbooks/compound-engineering/performance-review.json +54 -0
- package/playbooks/compound-engineering/plan-adversarial-review.json +56 -0
- package/playbooks/compound-engineering/plan-feasibility-review.json +56 -0
- package/playbooks/compound-engineering/project-standards-review.json +52 -0
- package/playbooks/compound-engineering/reliability-review.json +53 -0
- package/playbooks/compound-engineering/review-orchestration.json +64 -0
- package/playbooks/compound-engineering/security-review.json +54 -0
- package/playbooks/compound-engineering/systematic-execution.json +64 -0
- package/playbooks/compound-engineering/testing-review.json +50 -0
- package/src/atlas.ts +96 -0
- package/src/memory/curated-loader.ts +69 -16
- package/src/memory/index.ts +16 -0
- package/src/memory/playbook.ts +19 -0
- package/src/memory/source-resolver.ts +422 -0
- package/src/types/config.ts +46 -0
- package/src/types/index.ts +4 -0
- package/src/workspace/types.ts +22 -78
- package/tests/integration/curated-sources-e2e.test.ts +502 -0
- package/tests/memory/compound-engineering-seed.test.ts +338 -0
- package/tests/memory/curated-loader-extended.test.ts +225 -0
- package/tests/memory/playbook-quality-validation.test.ts +430 -0
- package/tests/memory/source-resolver.test.ts +700 -0
- package/.claude/settings.local.json +0 -11
- package/dist/learning/llm-extractor.d.ts +0 -88
- package/dist/learning/llm-extractor.d.ts.map +0 -1
- package/dist/learning/llm-extractor.js +0 -372
- package/dist/learning/llm-extractor.js.map +0 -1
- package/dist/learning/loop-coordinator.d.ts +0 -61
- package/dist/learning/loop-coordinator.d.ts.map +0 -1
- package/dist/learning/loop-coordinator.js +0 -96
- package/dist/learning/loop-coordinator.js.map +0 -1
- package/references/agent-workspace/CLAUDE.md +0 -74
- package/references/agent-workspace/README.md +0 -587
- package/references/agent-workspace/media/banner.png +0 -0
- package/references/agent-workspace/package-lock.json +0 -2061
- package/references/agent-workspace/package.json +0 -54
- package/references/agent-workspace/src/handle.ts +0 -122
- package/references/agent-workspace/src/index.ts +0 -32
- package/references/agent-workspace/src/manager.ts +0 -102
- package/references/agent-workspace/src/readers/json.ts +0 -71
- package/references/agent-workspace/src/readers/markdown.ts +0 -37
- package/references/agent-workspace/src/readers/raw.ts +0 -27
- package/references/agent-workspace/src/types.ts +0 -68
- package/references/agent-workspace/src/validation.ts +0 -93
- package/references/agent-workspace/src/writers/json.ts +0 -17
- package/references/agent-workspace/src/writers/markdown.ts +0 -27
- package/references/agent-workspace/src/writers/raw.ts +0 -22
- package/references/agent-workspace/tests/errors.test.ts +0 -652
- package/references/agent-workspace/tests/handle.test.ts +0 -144
- package/references/agent-workspace/tests/manager.test.ts +0 -124
- package/references/agent-workspace/tests/readers.test.ts +0 -205
- package/references/agent-workspace/tests/validation.test.ts +0 -196
- package/references/agent-workspace/tests/writers.test.ts +0 -108
- package/references/agent-workspace/tsconfig.json +0 -20
- package/references/agent-workspace/tsup.config.ts +0 -9
- package/references/minimem/.claude/settings.json +0 -7
- package/references/minimem/.sudocode/issues.jsonl +0 -18
- package/references/minimem/.sudocode/specs.jsonl +0 -1
- package/references/minimem/CLAUDE.md +0 -310
- package/references/minimem/README.md +0 -556
- package/references/minimem/claude-plugin/.claude-plugin/plugin.json +0 -10
- package/references/minimem/claude-plugin/.mcp.json +0 -7
- package/references/minimem/claude-plugin/README.md +0 -158
- package/references/minimem/claude-plugin/commands/recall.md +0 -47
- package/references/minimem/claude-plugin/commands/remember.md +0 -41
- package/references/minimem/claude-plugin/hooks/__tests__/hooks.test.ts +0 -272
- package/references/minimem/claude-plugin/hooks/hooks.json +0 -27
- package/references/minimem/claude-plugin/hooks/session-end.sh +0 -86
- package/references/minimem/claude-plugin/hooks/session-start.sh +0 -85
- package/references/minimem/claude-plugin/skills/memory/SKILL.md +0 -108
- package/references/minimem/package-lock.json +0 -5373
- package/references/minimem/package.json +0 -60
- package/references/minimem/scripts/postbuild.js +0 -35
- package/references/minimem/src/__tests__/edge-cases.test.ts +0 -371
- package/references/minimem/src/__tests__/errors.test.ts +0 -265
- package/references/minimem/src/__tests__/helpers.ts +0 -199
- package/references/minimem/src/__tests__/internal.test.ts +0 -407
- package/references/minimem/src/__tests__/knowledge.test.ts +0 -287
- package/references/minimem/src/__tests__/minimem.integration.test.ts +0 -1127
- package/references/minimem/src/__tests__/session.test.ts +0 -190
- package/references/minimem/src/cli/__tests__/commands.test.ts +0 -759
- package/references/minimem/src/cli/commands/__tests__/conflicts.test.ts +0 -141
- package/references/minimem/src/cli/commands/append.ts +0 -76
- package/references/minimem/src/cli/commands/config.ts +0 -262
- package/references/minimem/src/cli/commands/conflicts.ts +0 -413
- package/references/minimem/src/cli/commands/daemon.ts +0 -169
- package/references/minimem/src/cli/commands/index.ts +0 -12
- package/references/minimem/src/cli/commands/init.ts +0 -88
- package/references/minimem/src/cli/commands/mcp.ts +0 -177
- package/references/minimem/src/cli/commands/push-pull.ts +0 -213
- package/references/minimem/src/cli/commands/search.ts +0 -158
- package/references/minimem/src/cli/commands/status.ts +0 -84
- package/references/minimem/src/cli/commands/sync-init.ts +0 -290
- package/references/minimem/src/cli/commands/sync.ts +0 -70
- package/references/minimem/src/cli/commands/upsert.ts +0 -197
- package/references/minimem/src/cli/config.ts +0 -584
- package/references/minimem/src/cli/index.ts +0 -264
- package/references/minimem/src/cli/shared.ts +0 -161
- package/references/minimem/src/cli/sync/__tests__/central.test.ts +0 -152
- package/references/minimem/src/cli/sync/__tests__/conflicts.test.ts +0 -209
- package/references/minimem/src/cli/sync/__tests__/daemon.test.ts +0 -118
- package/references/minimem/src/cli/sync/__tests__/detection.test.ts +0 -207
- package/references/minimem/src/cli/sync/__tests__/integration.test.ts +0 -476
- package/references/minimem/src/cli/sync/__tests__/registry.test.ts +0 -363
- package/references/minimem/src/cli/sync/__tests__/state.test.ts +0 -255
- package/references/minimem/src/cli/sync/__tests__/validation.test.ts +0 -193
- package/references/minimem/src/cli/sync/__tests__/watcher.test.ts +0 -178
- package/references/minimem/src/cli/sync/central.ts +0 -292
- package/references/minimem/src/cli/sync/conflicts.ts +0 -204
- package/references/minimem/src/cli/sync/daemon.ts +0 -407
- package/references/minimem/src/cli/sync/detection.ts +0 -138
- package/references/minimem/src/cli/sync/index.ts +0 -107
- package/references/minimem/src/cli/sync/operations.ts +0 -373
- package/references/minimem/src/cli/sync/registry.ts +0 -279
- package/references/minimem/src/cli/sync/state.ts +0 -355
- package/references/minimem/src/cli/sync/validation.ts +0 -206
- package/references/minimem/src/cli/sync/watcher.ts +0 -234
- package/references/minimem/src/cli/version.ts +0 -34
- package/references/minimem/src/core/index.ts +0 -9
- package/references/minimem/src/core/indexer.ts +0 -628
- package/references/minimem/src/core/searcher.ts +0 -221
- package/references/minimem/src/db/schema.ts +0 -183
- package/references/minimem/src/db/sqlite-vec.ts +0 -24
- package/references/minimem/src/embeddings/__tests__/embeddings.test.ts +0 -431
- package/references/minimem/src/embeddings/batch-gemini.ts +0 -392
- package/references/minimem/src/embeddings/batch-openai.ts +0 -409
- package/references/minimem/src/embeddings/embeddings.ts +0 -434
- package/references/minimem/src/index.ts +0 -109
- package/references/minimem/src/internal.ts +0 -299
- package/references/minimem/src/minimem.ts +0 -1276
- package/references/minimem/src/search/__tests__/hybrid.test.ts +0 -247
- package/references/minimem/src/search/graph.ts +0 -234
- package/references/minimem/src/search/hybrid.ts +0 -151
- package/references/minimem/src/search/search.ts +0 -256
- package/references/minimem/src/server/__tests__/mcp.test.ts +0 -341
- package/references/minimem/src/server/__tests__/tools.test.ts +0 -364
- package/references/minimem/src/server/mcp.ts +0 -326
- package/references/minimem/src/server/tools.ts +0 -720
- package/references/minimem/src/session.ts +0 -460
- package/references/minimem/tsconfig.json +0 -19
- package/references/minimem/tsup.config.ts +0 -26
- package/references/minimem/vitest.config.ts +0 -24
- package/references/sessionlog/.husky/pre-commit +0 -1
- package/references/sessionlog/.lintstagedrc.json +0 -4
- package/references/sessionlog/.prettierignore +0 -4
- package/references/sessionlog/.prettierrc.json +0 -11
- package/references/sessionlog/LICENSE +0 -21
- package/references/sessionlog/README.md +0 -453
- package/references/sessionlog/eslint.config.js +0 -58
- package/references/sessionlog/package-lock.json +0 -3672
- package/references/sessionlog/package.json +0 -65
- package/references/sessionlog/src/__tests__/agent-hooks.test.ts +0 -570
- package/references/sessionlog/src/__tests__/agent-registry.test.ts +0 -127
- package/references/sessionlog/src/__tests__/claude-code-hooks.test.ts +0 -225
- package/references/sessionlog/src/__tests__/claude-generator.test.ts +0 -46
- package/references/sessionlog/src/__tests__/commit-msg.test.ts +0 -86
- package/references/sessionlog/src/__tests__/cursor-agent.test.ts +0 -224
- package/references/sessionlog/src/__tests__/e2e-live.test.ts +0 -890
- package/references/sessionlog/src/__tests__/event-log.test.ts +0 -183
- package/references/sessionlog/src/__tests__/flush-sentinel.test.ts +0 -105
- package/references/sessionlog/src/__tests__/gemini-agent.test.ts +0 -375
- package/references/sessionlog/src/__tests__/git-hooks.test.ts +0 -78
- package/references/sessionlog/src/__tests__/hook-managers.test.ts +0 -121
- package/references/sessionlog/src/__tests__/lifecycle-tasks.test.ts +0 -759
- package/references/sessionlog/src/__tests__/opencode-agent.test.ts +0 -338
- package/references/sessionlog/src/__tests__/redaction.test.ts +0 -136
- package/references/sessionlog/src/__tests__/session-repo.test.ts +0 -353
- package/references/sessionlog/src/__tests__/session-store.test.ts +0 -166
- package/references/sessionlog/src/__tests__/setup-ccweb.test.ts +0 -466
- package/references/sessionlog/src/__tests__/skill-live.test.ts +0 -461
- package/references/sessionlog/src/__tests__/summarize.test.ts +0 -348
- package/references/sessionlog/src/__tests__/task-plan-e2e.test.ts +0 -610
- package/references/sessionlog/src/__tests__/task-plan-live.test.ts +0 -632
- package/references/sessionlog/src/__tests__/transcript-timestamp.test.ts +0 -121
- package/references/sessionlog/src/__tests__/types.test.ts +0 -166
- package/references/sessionlog/src/__tests__/utils.test.ts +0 -333
- package/references/sessionlog/src/__tests__/validation.test.ts +0 -103
- package/references/sessionlog/src/__tests__/worktree.test.ts +0 -57
- package/references/sessionlog/src/agent/agents/claude-code.ts +0 -1089
- package/references/sessionlog/src/agent/agents/cursor.ts +0 -361
- package/references/sessionlog/src/agent/agents/gemini-cli.ts +0 -632
- package/references/sessionlog/src/agent/agents/opencode.ts +0 -540
- package/references/sessionlog/src/agent/registry.ts +0 -143
- package/references/sessionlog/src/agent/session-types.ts +0 -113
- package/references/sessionlog/src/agent/types.ts +0 -220
- package/references/sessionlog/src/cli.ts +0 -597
- package/references/sessionlog/src/commands/clean.ts +0 -133
- package/references/sessionlog/src/commands/disable.ts +0 -84
- package/references/sessionlog/src/commands/doctor.ts +0 -145
- package/references/sessionlog/src/commands/enable.ts +0 -202
- package/references/sessionlog/src/commands/explain.ts +0 -261
- package/references/sessionlog/src/commands/reset.ts +0 -105
- package/references/sessionlog/src/commands/resume.ts +0 -180
- package/references/sessionlog/src/commands/rewind.ts +0 -195
- package/references/sessionlog/src/commands/setup-ccweb.ts +0 -275
- package/references/sessionlog/src/commands/status.ts +0 -172
- package/references/sessionlog/src/config.ts +0 -165
- package/references/sessionlog/src/events/event-log.ts +0 -126
- package/references/sessionlog/src/git-operations.ts +0 -558
- package/references/sessionlog/src/hooks/git-hooks.ts +0 -165
- package/references/sessionlog/src/hooks/lifecycle.ts +0 -391
- package/references/sessionlog/src/index.ts +0 -650
- package/references/sessionlog/src/security/redaction.ts +0 -283
- package/references/sessionlog/src/session/state-machine.ts +0 -452
- package/references/sessionlog/src/store/checkpoint-store.ts +0 -509
- package/references/sessionlog/src/store/native-store.ts +0 -173
- package/references/sessionlog/src/store/provider-types.ts +0 -99
- package/references/sessionlog/src/store/session-store.ts +0 -266
- package/references/sessionlog/src/strategy/attribution.ts +0 -296
- package/references/sessionlog/src/strategy/common.ts +0 -207
- package/references/sessionlog/src/strategy/content-overlap.ts +0 -228
- package/references/sessionlog/src/strategy/manual-commit.ts +0 -988
- package/references/sessionlog/src/strategy/types.ts +0 -279
- package/references/sessionlog/src/summarize/claude-generator.ts +0 -115
- package/references/sessionlog/src/summarize/summarize.ts +0 -432
- package/references/sessionlog/src/types.ts +0 -508
- package/references/sessionlog/src/utils/chunk-files.ts +0 -49
- package/references/sessionlog/src/utils/commit-message.ts +0 -65
- package/references/sessionlog/src/utils/detect-agent.ts +0 -36
- package/references/sessionlog/src/utils/hook-managers.ts +0 -125
- package/references/sessionlog/src/utils/ide-tags.ts +0 -32
- package/references/sessionlog/src/utils/paths.ts +0 -79
- package/references/sessionlog/src/utils/preview-rewind.ts +0 -80
- package/references/sessionlog/src/utils/rewind-conflict.ts +0 -121
- package/references/sessionlog/src/utils/shadow-branch.ts +0 -109
- package/references/sessionlog/src/utils/string-utils.ts +0 -46
- package/references/sessionlog/src/utils/todo-extract.ts +0 -188
- package/references/sessionlog/src/utils/trailers.ts +0 -187
- package/references/sessionlog/src/utils/transcript-parse.ts +0 -177
- package/references/sessionlog/src/utils/transcript-timestamp.ts +0 -59
- package/references/sessionlog/src/utils/tree-ops.ts +0 -219
- package/references/sessionlog/src/utils/tty.ts +0 -72
- package/references/sessionlog/src/utils/validation.ts +0 -65
- package/references/sessionlog/src/utils/worktree.ts +0 -58
- package/references/sessionlog/src/wire-types.ts +0 -59
- package/references/sessionlog/templates/setup-env.sh +0 -153
- package/references/sessionlog/tsconfig.json +0 -18
- package/references/sessionlog/vitest.config.ts +0 -12
- package/references/skill-tree/.claude/settings.json +0 -6
- package/references/skill-tree/.sudocode/issues.jsonl +0 -19
- package/references/skill-tree/.sudocode/specs.jsonl +0 -3
- package/references/skill-tree/CLAUDE.md +0 -126
- package/references/skill-tree/README.md +0 -372
- package/references/skill-tree/docs/GAPS_v1.md +0 -221
- package/references/skill-tree/docs/INTEGRATION_PLAN.md +0 -467
- package/references/skill-tree/docs/TODOS.md +0 -91
- package/references/skill-tree/docs/anthropic_skill_guide.md +0 -1364
- package/references/skill-tree/docs/design/federated-skill-trees.md +0 -524
- package/references/skill-tree/docs/design/multi-agent-sync.md +0 -759
- package/references/skill-tree/docs/scraper/BRAINSTORM.md +0 -583
- package/references/skill-tree/docs/scraper/POC_PLAN.md +0 -420
- package/references/skill-tree/docs/scraper/README.md +0 -170
- package/references/skill-tree/examples/basic-usage.ts +0 -164
- package/references/skill-tree/package-lock.json +0 -1852
- package/references/skill-tree/package.json +0 -66
- package/references/skill-tree/scraper/README.md +0 -123
- package/references/skill-tree/scraper/docs/DESIGN.md +0 -683
- package/references/skill-tree/scraper/docs/PLAN.md +0 -336
- package/references/skill-tree/scraper/drizzle.config.ts +0 -10
- package/references/skill-tree/scraper/package-lock.json +0 -6329
- package/references/skill-tree/scraper/package.json +0 -68
- package/references/skill-tree/scraper/test/fixtures/invalid-skill/missing-description.md +0 -7
- package/references/skill-tree/scraper/test/fixtures/invalid-skill/missing-name.md +0 -7
- package/references/skill-tree/scraper/test/fixtures/minimal-skill/SKILL.md +0 -27
- package/references/skill-tree/scraper/test/fixtures/skill-json/SKILL.json +0 -21
- package/references/skill-tree/scraper/test/fixtures/skill-with-meta/SKILL.md +0 -54
- package/references/skill-tree/scraper/test/fixtures/skill-with-meta/_meta.json +0 -24
- package/references/skill-tree/scraper/test/fixtures/valid-skill/SKILL.md +0 -93
- package/references/skill-tree/scraper/test/fixtures/valid-skill/_meta.json +0 -22
- package/references/skill-tree/scraper/tsup.config.ts +0 -14
- package/references/skill-tree/scraper/vitest.config.ts +0 -17
- package/references/skill-tree/scripts/convert-to-vitest.ts +0 -166
- package/references/skill-tree/skills/skill-writer/SKILL.md +0 -339
- package/references/skill-tree/skills/skill-writer/references/examples.md +0 -326
- package/references/skill-tree/skills/skill-writer/references/patterns.md +0 -210
- package/references/skill-tree/skills/skill-writer/references/quality-checklist.md +0 -123
- package/references/skill-tree/test/run-all.ts +0 -106
- package/references/skill-tree/test/utils.ts +0 -128
- package/references/skill-tree/vitest.config.ts +0 -16
|
@@ -1,407 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import os from "node:os";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
chunkMarkdown,
|
|
8
|
-
stripPrivateContent,
|
|
9
|
-
extractChunkMetadata,
|
|
10
|
-
hashText,
|
|
11
|
-
buildFileEntry,
|
|
12
|
-
listMemoryFiles,
|
|
13
|
-
cosineSimilarity,
|
|
14
|
-
isMemoryPath,
|
|
15
|
-
normalizeRelPath,
|
|
16
|
-
truncateUtf16Safe,
|
|
17
|
-
} from "../internal.js";
|
|
18
|
-
|
|
19
|
-
describe("chunkMarkdown", () => {
|
|
20
|
-
it("splits overly long lines into max-sized chunks", () => {
|
|
21
|
-
const chunkTokens = 400;
|
|
22
|
-
const maxChars = chunkTokens * 4;
|
|
23
|
-
const content = "a".repeat(maxChars * 3 + 25);
|
|
24
|
-
const chunks = chunkMarkdown(content, { tokens: chunkTokens, overlap: 0 });
|
|
25
|
-
expect(chunks.length).toBeGreaterThan(1);
|
|
26
|
-
for (const chunk of chunks) {
|
|
27
|
-
expect(chunk.text.length).toBeLessThanOrEqual(maxChars);
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it("creates chunks with correct line numbers", () => {
|
|
32
|
-
const content = "line1\nline2\nline3\nline4\nline5";
|
|
33
|
-
const chunks = chunkMarkdown(content, { tokens: 10, overlap: 0 });
|
|
34
|
-
expect(chunks.length).toBeGreaterThan(0);
|
|
35
|
-
expect(chunks[0].startLine).toBe(1);
|
|
36
|
-
expect(chunks[chunks.length - 1].endLine).toBe(5);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it("handles overlap between chunks", () => {
|
|
40
|
-
const lines = Array.from({ length: 20 }, (_, i) => `line ${i + 1}`);
|
|
41
|
-
const content = lines.join("\n");
|
|
42
|
-
const chunksWithOverlap = chunkMarkdown(content, { tokens: 20, overlap: 5 });
|
|
43
|
-
const chunksWithoutOverlap = chunkMarkdown(content, { tokens: 20, overlap: 0 });
|
|
44
|
-
|
|
45
|
-
// With overlap, chunks should share some content
|
|
46
|
-
expect(chunksWithOverlap.length).toBeGreaterThanOrEqual(chunksWithoutOverlap.length);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it("handles empty content gracefully", () => {
|
|
50
|
-
// Empty string splits into one line, which creates one chunk
|
|
51
|
-
const chunks = chunkMarkdown("", { tokens: 256, overlap: 32 });
|
|
52
|
-
expect(chunks.length).toBeLessThanOrEqual(1);
|
|
53
|
-
if (chunks.length > 0) {
|
|
54
|
-
expect(chunks[0].text).toBe("");
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it("assigns hash to each chunk", () => {
|
|
59
|
-
const content = "Hello world\nThis is a test";
|
|
60
|
-
const chunks = chunkMarkdown(content, { tokens: 256, overlap: 0 });
|
|
61
|
-
expect(chunks.length).toBeGreaterThan(0);
|
|
62
|
-
for (const chunk of chunks) {
|
|
63
|
-
expect(chunk.hash).toBeDefined();
|
|
64
|
-
expect(chunk.hash.length).toBe(64); // SHA256 hex length
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
describe("stripPrivateContent", () => {
|
|
70
|
-
it("strips single-line private block", () => {
|
|
71
|
-
const input = "public\n<private>secret</private>\nmore public";
|
|
72
|
-
const result = stripPrivateContent(input);
|
|
73
|
-
expect(result).toBe("public\n\nmore public");
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it("strips multi-line private block preserving line count", () => {
|
|
77
|
-
const input = "line1\n<private>\nsecret1\nsecret2\n</private>\nline6";
|
|
78
|
-
const result = stripPrivateContent(input);
|
|
79
|
-
const lines = result.split("\n");
|
|
80
|
-
// Original has 6 lines, result should too
|
|
81
|
-
expect(lines.length).toBe(6);
|
|
82
|
-
expect(lines[0]).toBe("line1");
|
|
83
|
-
expect(lines[5]).toBe("line6");
|
|
84
|
-
// Middle lines should be empty
|
|
85
|
-
expect(lines[1]).toBe("");
|
|
86
|
-
expect(lines[2]).toBe("");
|
|
87
|
-
expect(lines[3]).toBe("");
|
|
88
|
-
expect(lines[4]).toBe("");
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it("strips multiple private blocks", () => {
|
|
92
|
-
const input = "a\n<private>x</private>\nb\n<private>y</private>\nc";
|
|
93
|
-
const result = stripPrivateContent(input);
|
|
94
|
-
expect(result).toBe("a\n\nb\n\nc");
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it("is case-insensitive", () => {
|
|
98
|
-
const input = "a\n<PRIVATE>secret</PRIVATE>\nb";
|
|
99
|
-
const result = stripPrivateContent(input);
|
|
100
|
-
expect(result).toBe("a\n\nb");
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it("returns content unchanged when no private tags", () => {
|
|
104
|
-
const input = "no secrets here\njust plain text";
|
|
105
|
-
expect(stripPrivateContent(input)).toBe(input);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it("handles empty content", () => {
|
|
109
|
-
expect(stripPrivateContent("")).toBe("");
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it("leaves unclosed private tag unchanged", () => {
|
|
113
|
-
const input = "text\n<private>no closing tag here\nmore text";
|
|
114
|
-
expect(stripPrivateContent(input)).toBe(input);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it("leaves orphaned closing tag unchanged", () => {
|
|
118
|
-
const input = "text\n</private>\nmore text";
|
|
119
|
-
expect(stripPrivateContent(input)).toBe(input);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it("handles mixed case tags", () => {
|
|
123
|
-
expect(stripPrivateContent("a\n<Private>x</Private>\nb")).toBe("a\n\nb");
|
|
124
|
-
expect(stripPrivateContent("a\n<pRiVaTe>x</pRiVaTe>\nb")).toBe("a\n\nb");
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it("handles private block with only newlines inside", () => {
|
|
128
|
-
const input = "a\n<private>\n\n\n</private>\nb";
|
|
129
|
-
const result = stripPrivateContent(input);
|
|
130
|
-
expect(result.split("\n").length).toBe(input.split("\n").length);
|
|
131
|
-
expect(result).not.toContain("<private>");
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it("handles adjacent private blocks", () => {
|
|
135
|
-
const input = "<private>a</private><private>b</private>";
|
|
136
|
-
const result = stripPrivateContent(input);
|
|
137
|
-
expect(result).not.toContain("a");
|
|
138
|
-
expect(result).not.toContain("b");
|
|
139
|
-
expect(result).not.toContain("<private>");
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
describe("chunkMarkdown with private content", () => {
|
|
144
|
-
it("excludes private content from chunks", () => {
|
|
145
|
-
const content = "public info\n<private>API_KEY=sk-123</private>\nmore public";
|
|
146
|
-
const chunks = chunkMarkdown(content, { tokens: 256, overlap: 0 });
|
|
147
|
-
for (const chunk of chunks) {
|
|
148
|
-
expect(chunk.text).not.toContain("API_KEY");
|
|
149
|
-
expect(chunk.text).not.toContain("sk-123");
|
|
150
|
-
expect(chunk.text).not.toContain("<private>");
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it("preserves line numbers when private content is stripped", () => {
|
|
155
|
-
const content = "line1\n<private>\nsecret\n</private>\nline5";
|
|
156
|
-
const chunks = chunkMarkdown(content, { tokens: 256, overlap: 0 });
|
|
157
|
-
// line5 is on line 5 in the original, should stay on line 5
|
|
158
|
-
const allText = chunks.map((c) => c.text).join("\n");
|
|
159
|
-
expect(allText).toContain("line1");
|
|
160
|
-
expect(allText).toContain("line5");
|
|
161
|
-
expect(allText).not.toContain("secret");
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
describe("extractChunkMetadata", () => {
|
|
166
|
-
it("extracts type from HTML comment", () => {
|
|
167
|
-
const text = "### 2026-02-13 14:30\n<!-- type: decision -->\nDecided to use BM25";
|
|
168
|
-
expect(extractChunkMetadata(text)).toEqual({ type: "decision" });
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
it("is case-insensitive", () => {
|
|
172
|
-
const text = "<!-- Type: BugFix -->\nFixed off-by-one error";
|
|
173
|
-
expect(extractChunkMetadata(text)).toEqual({ type: "bugfix" });
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
it("returns empty object when no type comment", () => {
|
|
177
|
-
const text = "Just plain text with no metadata";
|
|
178
|
-
expect(extractChunkMetadata(text)).toEqual({});
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it("extracts first type when multiple present", () => {
|
|
182
|
-
const text = "<!-- type: feature -->\n<!-- type: discovery -->\nSome text";
|
|
183
|
-
expect(extractChunkMetadata(text)).toEqual({ type: "feature" });
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
it("handles various type values", () => {
|
|
187
|
-
expect(extractChunkMetadata("<!-- type: discovery -->")).toEqual({ type: "discovery" });
|
|
188
|
-
expect(extractChunkMetadata("<!-- type: context -->")).toEqual({ type: "context" });
|
|
189
|
-
expect(extractChunkMetadata("<!-- type: note -->")).toEqual({ type: "note" });
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
it("handles hyphenated type values", () => {
|
|
193
|
-
expect(extractChunkMetadata("<!-- type: bug-fix -->")).toEqual({ type: "bug-fix" });
|
|
194
|
-
expect(extractChunkMetadata("<!-- type: api-change -->")).toEqual({ type: "api-change" });
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
it("handles underscored type values", () => {
|
|
198
|
-
expect(extractChunkMetadata("<!-- type: feature_flag -->")).toEqual({ type: "feature_flag" });
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
it("handles whitespace variations in comment", () => {
|
|
202
|
-
expect(extractChunkMetadata("<!--type:decision-->")).toEqual({ type: "decision" });
|
|
203
|
-
expect(extractChunkMetadata("<!-- type: decision -->")).toEqual({ type: "decision" });
|
|
204
|
-
expect(extractChunkMetadata("<!-- type:decision -->")).toEqual({ type: "decision" });
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
it("does not match empty type value", () => {
|
|
208
|
-
expect(extractChunkMetadata("<!-- type: -->")).toEqual({});
|
|
209
|
-
expect(extractChunkMetadata("<!-- type: -->")).toEqual({});
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
it("does not match unclosed comment", () => {
|
|
213
|
-
expect(extractChunkMetadata("<!-- type: decision")).toEqual({});
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
it("does not match partial comment syntax", () => {
|
|
217
|
-
expect(extractChunkMetadata("type: decision")).toEqual({});
|
|
218
|
-
expect(extractChunkMetadata("// type: decision")).toEqual({});
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
it("normalizes mixed case type to lowercase", () => {
|
|
222
|
-
expect(extractChunkMetadata("<!-- type: DeciSion -->")).toEqual({ type: "decision" });
|
|
223
|
-
expect(extractChunkMetadata("<!-- type: BUGFIX -->")).toEqual({ type: "bugfix" });
|
|
224
|
-
});
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
describe("hashText", () => {
|
|
228
|
-
it("returns consistent SHA256 hash", () => {
|
|
229
|
-
const hash1 = hashText("hello world");
|
|
230
|
-
const hash2 = hashText("hello world");
|
|
231
|
-
expect(hash1).toBe(hash2);
|
|
232
|
-
expect(hash1.length).toBe(64);
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
it("returns different hashes for different inputs", () => {
|
|
236
|
-
const hash1 = hashText("hello");
|
|
237
|
-
const hash2 = hashText("world");
|
|
238
|
-
expect(hash1).not.toBe(hash2);
|
|
239
|
-
});
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
describe("cosineSimilarity", () => {
|
|
243
|
-
it("returns 1 for identical vectors", () => {
|
|
244
|
-
const vec = [1, 2, 3, 4, 5];
|
|
245
|
-
expect(cosineSimilarity(vec, vec)).toBeCloseTo(1);
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
it("returns 0 for orthogonal vectors", () => {
|
|
249
|
-
const vec1 = [1, 0, 0];
|
|
250
|
-
const vec2 = [0, 1, 0];
|
|
251
|
-
expect(cosineSimilarity(vec1, vec2)).toBeCloseTo(0);
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
it("returns -1 for opposite vectors", () => {
|
|
255
|
-
const vec1 = [1, 2, 3];
|
|
256
|
-
const vec2 = [-1, -2, -3];
|
|
257
|
-
expect(cosineSimilarity(vec1, vec2)).toBeCloseTo(-1);
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
it("handles empty vectors", () => {
|
|
261
|
-
expect(cosineSimilarity([], [1, 2, 3])).toBe(0);
|
|
262
|
-
expect(cosineSimilarity([1, 2, 3], [])).toBe(0);
|
|
263
|
-
expect(cosineSimilarity([], [])).toBe(0);
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
it("handles zero vectors", () => {
|
|
267
|
-
expect(cosineSimilarity([0, 0, 0], [1, 2, 3])).toBe(0);
|
|
268
|
-
});
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
describe("isMemoryPath", () => {
|
|
272
|
-
it("accepts MEMORY.md", () => {
|
|
273
|
-
expect(isMemoryPath("MEMORY.md")).toBe(true);
|
|
274
|
-
expect(isMemoryPath("memory.md")).toBe(true);
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
it("accepts paths in memory directory", () => {
|
|
278
|
-
expect(isMemoryPath("memory/2024-01-01.md")).toBe(true);
|
|
279
|
-
expect(isMemoryPath("memory/topic/notes.md")).toBe(true);
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
it("rejects non-memory paths", () => {
|
|
283
|
-
expect(isMemoryPath("README.md")).toBe(false);
|
|
284
|
-
expect(isMemoryPath("src/index.ts")).toBe(false);
|
|
285
|
-
expect(isMemoryPath("")).toBe(false);
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
it("handles leading dots and slashes", () => {
|
|
289
|
-
expect(isMemoryPath("./MEMORY.md")).toBe(true);
|
|
290
|
-
expect(isMemoryPath("./memory/test.md")).toBe(true);
|
|
291
|
-
});
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
describe("normalizeRelPath", () => {
|
|
295
|
-
it("removes leading dots and slashes", () => {
|
|
296
|
-
expect(normalizeRelPath("./foo/bar")).toBe("foo/bar");
|
|
297
|
-
expect(normalizeRelPath("../foo/bar")).toBe("foo/bar");
|
|
298
|
-
expect(normalizeRelPath("///foo")).toBe("foo");
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
it("converts backslashes to forward slashes", () => {
|
|
302
|
-
expect(normalizeRelPath("foo\\bar\\baz")).toBe("foo/bar/baz");
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
it("trims whitespace", () => {
|
|
306
|
-
expect(normalizeRelPath(" foo/bar ")).toBe("foo/bar");
|
|
307
|
-
});
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
describe("truncateUtf16Safe", () => {
|
|
311
|
-
it("returns original string if under limit", () => {
|
|
312
|
-
expect(truncateUtf16Safe("hello", 10)).toBe("hello");
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
it("truncates string at limit", () => {
|
|
316
|
-
expect(truncateUtf16Safe("hello world", 5)).toBe("hello");
|
|
317
|
-
});
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
describe("listMemoryFiles", () => {
|
|
321
|
-
let tempDir: string;
|
|
322
|
-
|
|
323
|
-
beforeEach(async () => {
|
|
324
|
-
tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "minimem-test-"));
|
|
325
|
-
});
|
|
326
|
-
|
|
327
|
-
afterEach(async () => {
|
|
328
|
-
await fs.rm(tempDir, { recursive: true, force: true });
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
it("finds MEMORY.md at root", async () => {
|
|
332
|
-
await fs.writeFile(path.join(tempDir, "MEMORY.md"), "# Memory");
|
|
333
|
-
const files = await listMemoryFiles(tempDir);
|
|
334
|
-
expect(files).toHaveLength(1);
|
|
335
|
-
expect(files[0]).toContain("MEMORY.md");
|
|
336
|
-
});
|
|
337
|
-
|
|
338
|
-
it("finds files in memory directory", async () => {
|
|
339
|
-
await fs.mkdir(path.join(tempDir, "memory"));
|
|
340
|
-
await fs.writeFile(path.join(tempDir, "memory", "2024-01-01.md"), "# Log");
|
|
341
|
-
await fs.writeFile(path.join(tempDir, "memory", "notes.md"), "# Notes");
|
|
342
|
-
|
|
343
|
-
const files = await listMemoryFiles(tempDir);
|
|
344
|
-
expect(files).toHaveLength(2);
|
|
345
|
-
});
|
|
346
|
-
|
|
347
|
-
it("recursively finds files in nested directories", async () => {
|
|
348
|
-
await fs.mkdir(path.join(tempDir, "memory", "topics"), { recursive: true });
|
|
349
|
-
await fs.writeFile(path.join(tempDir, "memory", "topics", "project.md"), "# Project");
|
|
350
|
-
|
|
351
|
-
const files = await listMemoryFiles(tempDir);
|
|
352
|
-
expect(files).toHaveLength(1);
|
|
353
|
-
expect(files[0]).toContain("project.md");
|
|
354
|
-
});
|
|
355
|
-
|
|
356
|
-
it("returns empty array when no memory files exist", async () => {
|
|
357
|
-
const files = await listMemoryFiles(tempDir);
|
|
358
|
-
expect(files).toHaveLength(0);
|
|
359
|
-
});
|
|
360
|
-
|
|
361
|
-
it("only includes .md files", async () => {
|
|
362
|
-
await fs.mkdir(path.join(tempDir, "memory"));
|
|
363
|
-
await fs.writeFile(path.join(tempDir, "memory", "notes.md"), "# Notes");
|
|
364
|
-
await fs.writeFile(path.join(tempDir, "memory", "notes.txt"), "text");
|
|
365
|
-
await fs.writeFile(path.join(tempDir, "memory", "data.json"), "{}");
|
|
366
|
-
|
|
367
|
-
const files = await listMemoryFiles(tempDir);
|
|
368
|
-
expect(files).toHaveLength(1);
|
|
369
|
-
expect(files[0]).toContain(".md");
|
|
370
|
-
});
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
describe("buildFileEntry", () => {
|
|
374
|
-
let tempDir: string;
|
|
375
|
-
|
|
376
|
-
beforeEach(async () => {
|
|
377
|
-
tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "minimem-test-"));
|
|
378
|
-
});
|
|
379
|
-
|
|
380
|
-
afterEach(async () => {
|
|
381
|
-
await fs.rm(tempDir, { recursive: true, force: true });
|
|
382
|
-
});
|
|
383
|
-
|
|
384
|
-
it("builds correct file entry", async () => {
|
|
385
|
-
const content = "# Test content";
|
|
386
|
-
const filePath = path.join(tempDir, "test.md");
|
|
387
|
-
await fs.writeFile(filePath, content);
|
|
388
|
-
|
|
389
|
-
const entry = await buildFileEntry(filePath, tempDir);
|
|
390
|
-
|
|
391
|
-
expect(entry.path).toBe("test.md");
|
|
392
|
-
expect(entry.absPath).toBe(filePath);
|
|
393
|
-
expect(entry.hash).toBe(hashText(content));
|
|
394
|
-
expect(entry.size).toBe(content.length);
|
|
395
|
-
expect(entry.mtimeMs).toBeGreaterThan(0);
|
|
396
|
-
});
|
|
397
|
-
|
|
398
|
-
it("handles nested paths", async () => {
|
|
399
|
-
await fs.mkdir(path.join(tempDir, "memory"));
|
|
400
|
-
const filePath = path.join(tempDir, "memory", "2024-01-01.md");
|
|
401
|
-
await fs.writeFile(filePath, "# Log");
|
|
402
|
-
|
|
403
|
-
const entry = await buildFileEntry(filePath, tempDir);
|
|
404
|
-
|
|
405
|
-
expect(entry.path).toBe("memory/2024-01-01.md");
|
|
406
|
-
});
|
|
407
|
-
});
|
|
@@ -1,287 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for knowledge-aware features:
|
|
3
|
-
* - Frontmatter parsing of knowledge fields
|
|
4
|
-
* - Knowledge link types
|
|
5
|
-
* - Graph traversal functions
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
9
|
-
import { DatabaseSync } from "node:sqlite";
|
|
10
|
-
import {
|
|
11
|
-
parseFrontmatter,
|
|
12
|
-
serializeFrontmatter,
|
|
13
|
-
type MemoryFrontmatter,
|
|
14
|
-
} from "../session.js";
|
|
15
|
-
import {
|
|
16
|
-
getLinksFrom,
|
|
17
|
-
getLinksTo,
|
|
18
|
-
getNeighbors,
|
|
19
|
-
getPathBetween,
|
|
20
|
-
type GraphLink,
|
|
21
|
-
} from "../search/graph.js";
|
|
22
|
-
|
|
23
|
-
// =========================================================================
|
|
24
|
-
// Frontmatter parsing
|
|
25
|
-
// =========================================================================
|
|
26
|
-
|
|
27
|
-
describe("Knowledge frontmatter", () => {
|
|
28
|
-
it("parses full knowledge frontmatter with all fields", () => {
|
|
29
|
-
const content = `---
|
|
30
|
-
id: k-abc123
|
|
31
|
-
type: observation
|
|
32
|
-
domain: [database, devops]
|
|
33
|
-
entities: [prisma, postgres]
|
|
34
|
-
confidence: 0.85
|
|
35
|
-
source:
|
|
36
|
-
origin: extracted
|
|
37
|
-
trajectories: [t-001, t-002]
|
|
38
|
-
agentId: agent-v1
|
|
39
|
-
links:
|
|
40
|
-
- target: k-other
|
|
41
|
-
relation: related-to
|
|
42
|
-
layer: semantic
|
|
43
|
-
created: 2025-01-15T10:00:00Z
|
|
44
|
-
updated: 2025-01-15T12:00:00Z
|
|
45
|
-
supersedes: k-old
|
|
46
|
-
---
|
|
47
|
-
# Observation
|
|
48
|
-
|
|
49
|
-
Body content here.`;
|
|
50
|
-
|
|
51
|
-
const { frontmatter, body } = parseFrontmatter(content);
|
|
52
|
-
|
|
53
|
-
expect(frontmatter).toBeDefined();
|
|
54
|
-
expect(frontmatter!.id).toBe("k-abc123");
|
|
55
|
-
expect(frontmatter!.type).toBe("observation");
|
|
56
|
-
expect(frontmatter!.domain).toEqual(["database", "devops"]);
|
|
57
|
-
expect(frontmatter!.entities).toEqual(["prisma", "postgres"]);
|
|
58
|
-
expect(frontmatter!.confidence).toBe(0.85);
|
|
59
|
-
expect(frontmatter!.source?.origin).toBe("extracted");
|
|
60
|
-
expect(frontmatter!.source?.trajectories).toEqual(["t-001", "t-002"]);
|
|
61
|
-
expect(frontmatter!.source?.agentId).toBe("agent-v1");
|
|
62
|
-
expect(frontmatter!.links).toHaveLength(1);
|
|
63
|
-
expect(frontmatter!.links![0].target).toBe("k-other");
|
|
64
|
-
expect(frontmatter!.links![0].relation).toBe("related-to");
|
|
65
|
-
expect(frontmatter!.links![0].layer).toBe("semantic");
|
|
66
|
-
expect(frontmatter!.created).toBe("2025-01-15T10:00:00Z");
|
|
67
|
-
expect(frontmatter!.supersedes).toBe("k-old");
|
|
68
|
-
expect(body).toContain("Body content here.");
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it("parses note with no knowledge fields as standard frontmatter", () => {
|
|
72
|
-
const content = `---
|
|
73
|
-
created: 2025-01-15T10:00:00Z
|
|
74
|
-
tags: [daily, meeting]
|
|
75
|
-
---
|
|
76
|
-
Regular memory content.`;
|
|
77
|
-
|
|
78
|
-
const { frontmatter } = parseFrontmatter(content);
|
|
79
|
-
|
|
80
|
-
expect(frontmatter).toBeDefined();
|
|
81
|
-
expect(frontmatter!.created).toBe("2025-01-15T10:00:00Z");
|
|
82
|
-
expect(frontmatter!.tags).toEqual(["daily", "meeting"]);
|
|
83
|
-
// Knowledge fields should be absent
|
|
84
|
-
expect(frontmatter!.id).toBeUndefined();
|
|
85
|
-
expect(frontmatter!.type).toBeUndefined();
|
|
86
|
-
expect(frontmatter!.domain).toBeUndefined();
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it("parses note with links array", () => {
|
|
90
|
-
const content = `---
|
|
91
|
-
id: k-linked
|
|
92
|
-
type: entity
|
|
93
|
-
links:
|
|
94
|
-
- target: k-dep1
|
|
95
|
-
relation: depends-on
|
|
96
|
-
- target: k-dep2
|
|
97
|
-
relation: supports
|
|
98
|
-
layer: causal
|
|
99
|
-
---
|
|
100
|
-
Entity note.`;
|
|
101
|
-
|
|
102
|
-
const { frontmatter } = parseFrontmatter(content);
|
|
103
|
-
|
|
104
|
-
expect(frontmatter!.links).toHaveLength(2);
|
|
105
|
-
expect(frontmatter!.links![0].target).toBe("k-dep1");
|
|
106
|
-
expect(frontmatter!.links![0].relation).toBe("depends-on");
|
|
107
|
-
expect(frontmatter!.links![0].layer).toBeUndefined();
|
|
108
|
-
expect(frontmatter!.links![1].target).toBe("k-dep2");
|
|
109
|
-
expect(frontmatter!.links![1].relation).toBe("supports");
|
|
110
|
-
expect(frontmatter!.links![1].layer).toBe("causal");
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it("parses note with source object", () => {
|
|
114
|
-
const content = `---
|
|
115
|
-
id: k-sourced
|
|
116
|
-
type: observation
|
|
117
|
-
confidence: 0.7
|
|
118
|
-
source:
|
|
119
|
-
origin: agent-authored
|
|
120
|
-
trajectories: [t-100]
|
|
121
|
-
agentId: claude-v3
|
|
122
|
-
---
|
|
123
|
-
Source test.`;
|
|
124
|
-
|
|
125
|
-
const { frontmatter } = parseFrontmatter(content);
|
|
126
|
-
|
|
127
|
-
expect(frontmatter!.source).toBeDefined();
|
|
128
|
-
expect(frontmatter!.source!.origin).toBe("agent-authored");
|
|
129
|
-
expect(frontmatter!.source!.trajectories).toEqual(["t-100"]);
|
|
130
|
-
expect(frontmatter!.source!.agentId).toBe("claude-v3");
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it("round-trips via serialize then parse", () => {
|
|
134
|
-
const original: MemoryFrontmatter = {
|
|
135
|
-
id: "k-round-trip",
|
|
136
|
-
type: "domain-summary",
|
|
137
|
-
domain: ["testing"],
|
|
138
|
-
entities: ["vitest"],
|
|
139
|
-
confidence: 0.9,
|
|
140
|
-
created: "2025-02-01T00:00:00Z",
|
|
141
|
-
updated: "2025-02-01T12:00:00Z",
|
|
142
|
-
source: {
|
|
143
|
-
origin: "extracted",
|
|
144
|
-
trajectories: ["t-42"],
|
|
145
|
-
},
|
|
146
|
-
links: [
|
|
147
|
-
{ target: "k-other", relation: "related-to", layer: "semantic" },
|
|
148
|
-
],
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
const serialized = serializeFrontmatter(original);
|
|
152
|
-
const { frontmatter } = parseFrontmatter(serialized + "\nBody");
|
|
153
|
-
|
|
154
|
-
expect(frontmatter!.id).toBe("k-round-trip");
|
|
155
|
-
expect(frontmatter!.type).toBe("domain-summary");
|
|
156
|
-
expect(frontmatter!.domain).toEqual(["testing"]);
|
|
157
|
-
expect(frontmatter!.confidence).toBe(0.9);
|
|
158
|
-
expect(frontmatter!.source?.origin).toBe("extracted");
|
|
159
|
-
expect(frontmatter!.links).toHaveLength(1);
|
|
160
|
-
expect(frontmatter!.links![0].target).toBe("k-other");
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
// =========================================================================
|
|
165
|
-
// Graph traversal
|
|
166
|
-
// =========================================================================
|
|
167
|
-
|
|
168
|
-
describe("Knowledge graph", () => {
|
|
169
|
-
let db: DatabaseSync;
|
|
170
|
-
|
|
171
|
-
beforeEach(() => {
|
|
172
|
-
db = new DatabaseSync(":memory:");
|
|
173
|
-
db.exec(`
|
|
174
|
-
CREATE TABLE knowledge_links (
|
|
175
|
-
from_id TEXT NOT NULL,
|
|
176
|
-
to_id TEXT NOT NULL,
|
|
177
|
-
relation TEXT NOT NULL,
|
|
178
|
-
layer TEXT,
|
|
179
|
-
weight REAL DEFAULT 0.5,
|
|
180
|
-
source_path TEXT,
|
|
181
|
-
created_at INTEGER DEFAULT (unixepoch()),
|
|
182
|
-
PRIMARY KEY (from_id, to_id, relation)
|
|
183
|
-
);
|
|
184
|
-
CREATE INDEX idx_links_from ON knowledge_links(from_id);
|
|
185
|
-
CREATE INDEX idx_links_to ON knowledge_links(to_id);
|
|
186
|
-
CREATE INDEX idx_links_layer ON knowledge_links(layer);
|
|
187
|
-
`);
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
afterEach(() => {
|
|
191
|
-
db.close();
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
function insertLink(
|
|
195
|
-
fromId: string,
|
|
196
|
-
toId: string,
|
|
197
|
-
relation: string,
|
|
198
|
-
layer?: string,
|
|
199
|
-
weight = 0.5,
|
|
200
|
-
) {
|
|
201
|
-
db.prepare(
|
|
202
|
-
`INSERT INTO knowledge_links (from_id, to_id, relation, layer, weight) VALUES (?, ?, ?, ?, ?)`,
|
|
203
|
-
).run(fromId, toId, relation, layer ?? null, weight);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
it("getLinksFrom returns outgoing edges", () => {
|
|
207
|
-
insertLink("A", "B", "related-to", "semantic");
|
|
208
|
-
insertLink("A", "C", "depends-on", "causal");
|
|
209
|
-
insertLink("B", "C", "supports");
|
|
210
|
-
|
|
211
|
-
const links = getLinksFrom(db, "A");
|
|
212
|
-
expect(links).toHaveLength(2);
|
|
213
|
-
expect(links.map((l) => l.toId).sort()).toEqual(["B", "C"]);
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
it("getLinksTo returns incoming edges", () => {
|
|
217
|
-
insertLink("A", "C", "related-to");
|
|
218
|
-
insertLink("B", "C", "depends-on");
|
|
219
|
-
|
|
220
|
-
const links = getLinksTo(db, "C");
|
|
221
|
-
expect(links).toHaveLength(2);
|
|
222
|
-
expect(links.map((l) => l.fromId).sort()).toEqual(["A", "B"]);
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
it("getLinksFrom filters by relation and layer", () => {
|
|
226
|
-
insertLink("A", "B", "related-to", "semantic");
|
|
227
|
-
insertLink("A", "C", "depends-on", "causal");
|
|
228
|
-
|
|
229
|
-
const byRelation = getLinksFrom(db, "A", { relation: "related-to" });
|
|
230
|
-
expect(byRelation).toHaveLength(1);
|
|
231
|
-
expect(byRelation[0].toId).toBe("B");
|
|
232
|
-
|
|
233
|
-
const byLayer = getLinksFrom(db, "A", { layer: "causal" });
|
|
234
|
-
expect(byLayer).toHaveLength(1);
|
|
235
|
-
expect(byLayer[0].toId).toBe("C");
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
it("getNeighbors with depth=1 returns direct neighbors", () => {
|
|
239
|
-
insertLink("A", "B", "related-to");
|
|
240
|
-
insertLink("B", "C", "depends-on");
|
|
241
|
-
insertLink("C", "D", "supports");
|
|
242
|
-
|
|
243
|
-
const neighbors = getNeighbors(db, "A", 1);
|
|
244
|
-
expect(neighbors).toHaveLength(1);
|
|
245
|
-
expect(neighbors[0].id).toBe("B");
|
|
246
|
-
expect(neighbors[0].depth).toBe(1);
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
it("getNeighbors with depth=2 returns transitive neighbors", () => {
|
|
250
|
-
insertLink("A", "B", "related-to");
|
|
251
|
-
insertLink("B", "C", "depends-on");
|
|
252
|
-
insertLink("C", "D", "supports");
|
|
253
|
-
|
|
254
|
-
const neighbors = getNeighbors(db, "A", 2);
|
|
255
|
-
expect(neighbors).toHaveLength(2);
|
|
256
|
-
|
|
257
|
-
const ids = neighbors.map((n) => n.id);
|
|
258
|
-
expect(ids).toContain("B");
|
|
259
|
-
expect(ids).toContain("C");
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
it("getPathBetween finds shortest path", () => {
|
|
263
|
-
insertLink("A", "B", "related-to");
|
|
264
|
-
insertLink("B", "C", "depends-on");
|
|
265
|
-
insertLink("C", "D", "supports");
|
|
266
|
-
|
|
267
|
-
const path = getPathBetween(db, "A", "C");
|
|
268
|
-
expect(path).toHaveLength(2);
|
|
269
|
-
expect(path[0].fromId).toBe("A");
|
|
270
|
-
expect(path[0].toId).toBe("B");
|
|
271
|
-
expect(path[1].fromId).toBe("B");
|
|
272
|
-
expect(path[1].toId).toBe("C");
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
it("getPathBetween returns empty for disconnected nodes", () => {
|
|
276
|
-
insertLink("A", "B", "related-to");
|
|
277
|
-
// C is disconnected
|
|
278
|
-
|
|
279
|
-
const path = getPathBetween(db, "A", "C");
|
|
280
|
-
expect(path).toEqual([]);
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
it("getPathBetween handles same node", () => {
|
|
284
|
-
const path = getPathBetween(db, "A", "A");
|
|
285
|
-
expect(path).toEqual([]);
|
|
286
|
-
});
|
|
287
|
-
});
|