@theokit/sdk-memory 0.1.0

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.
Files changed (99) hide show
  1. package/CHANGELOG.md +112 -0
  2. package/LICENSE +201 -0
  3. package/README.md +86 -0
  4. package/dist/in-memory-provider.d.ts +38 -0
  5. package/dist/in-memory-provider.d.ts.map +1 -0
  6. package/dist/index.cjs +2585 -0
  7. package/dist/index.cjs.map +1 -0
  8. package/dist/index.d.cts +40 -0
  9. package/dist/index.d.ts +40 -0
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +2500 -0
  12. package/dist/index.js.map +1 -0
  13. package/dist/internal/active-memory-cache.d.ts +49 -0
  14. package/dist/internal/active-memory-cache.d.ts.map +1 -0
  15. package/dist/internal/active-memory-types.d.ts +30 -0
  16. package/dist/internal/active-memory-types.d.ts.map +1 -0
  17. package/dist/internal/active-memory.d.ts +108 -0
  18. package/dist/internal/active-memory.d.ts.map +1 -0
  19. package/dist/internal/adapter-catalog.d.ts +82 -0
  20. package/dist/internal/adapter-catalog.d.ts.map +1 -0
  21. package/dist/internal/adapter-http-error.d.ts +63 -0
  22. package/dist/internal/adapter-http-error.d.ts.map +1 -0
  23. package/dist/internal/batch-encoder.d.ts +30 -0
  24. package/dist/internal/batch-encoder.d.ts.map +1 -0
  25. package/dist/internal/chunk-markdown.d.ts +66 -0
  26. package/dist/internal/chunk-markdown.d.ts.map +1 -0
  27. package/dist/internal/circuit-breaker.d.ts +36 -0
  28. package/dist/internal/circuit-breaker.d.ts.map +1 -0
  29. package/dist/internal/composite-scorer.d.ts +19 -0
  30. package/dist/internal/composite-scorer.d.ts.map +1 -0
  31. package/dist/internal/deepinfra-embedding.d.ts +25 -0
  32. package/dist/internal/deepinfra-embedding.d.ts.map +1 -0
  33. package/dist/internal/dreaming-diary.d.ts +38 -0
  34. package/dist/internal/dreaming-diary.d.ts.map +1 -0
  35. package/dist/internal/dreaming-phases.d.ts +43 -0
  36. package/dist/internal/dreaming-phases.d.ts.map +1 -0
  37. package/dist/internal/dreaming-run.d.ts +49 -0
  38. package/dist/internal/dreaming-run.d.ts.map +1 -0
  39. package/dist/internal/embedding-adapter.d.ts +57 -0
  40. package/dist/internal/embedding-adapter.d.ts.map +1 -0
  41. package/dist/internal/embedding-cache.d.ts +16 -0
  42. package/dist/internal/embedding-cache.d.ts.map +1 -0
  43. package/dist/internal/index-db.d.ts +50 -0
  44. package/dist/internal/index-db.d.ts.map +1 -0
  45. package/dist/internal/index-manager-contract.d.ts +70 -0
  46. package/dist/internal/index-manager-contract.d.ts.map +1 -0
  47. package/dist/internal/index-manager-dispatch.d.ts +36 -0
  48. package/dist/internal/index-manager-dispatch.d.ts.map +1 -0
  49. package/dist/internal/index-manager.d.ts +94 -0
  50. package/dist/internal/index-manager.d.ts.map +1 -0
  51. package/dist/internal/index-schema.d.ts +35 -0
  52. package/dist/internal/index-schema.d.ts.map +1 -0
  53. package/dist/internal/lance-index.d.ts +70 -0
  54. package/dist/internal/lance-index.d.ts.map +1 -0
  55. package/dist/internal/lance-memory-adapter.d.ts +102 -0
  56. package/dist/internal/lance-memory-adapter.d.ts.map +1 -0
  57. package/dist/internal/markdown-store.d.ts +17 -0
  58. package/dist/internal/markdown-store.d.ts.map +1 -0
  59. package/dist/internal/memory-index.d.ts +68 -0
  60. package/dist/internal/memory-index.d.ts.map +1 -0
  61. package/dist/internal/memory-scope.d.ts +21 -0
  62. package/dist/internal/memory-scope.d.ts.map +1 -0
  63. package/dist/internal/memory-types.d.ts +95 -0
  64. package/dist/internal/memory-types.d.ts.map +1 -0
  65. package/dist/internal/migrate-sqlite-to-lance.d.ts +49 -0
  66. package/dist/internal/migrate-sqlite-to-lance.d.ts.map +1 -0
  67. package/dist/internal/migration.d.ts +10 -0
  68. package/dist/internal/migration.d.ts.map +1 -0
  69. package/dist/internal/mistral-embedding.d.ts +23 -0
  70. package/dist/internal/mistral-embedding.d.ts.map +1 -0
  71. package/dist/internal/ollama-embedding.d.ts +48 -0
  72. package/dist/internal/ollama-embedding.d.ts.map +1 -0
  73. package/dist/internal/openai-compatible.d.ts +24 -0
  74. package/dist/internal/openai-compatible.d.ts.map +1 -0
  75. package/dist/internal/openai-embedding.d.ts +34 -0
  76. package/dist/internal/openai-embedding.d.ts.map +1 -0
  77. package/dist/internal/openrouter-embedding.d.ts +25 -0
  78. package/dist/internal/openrouter-embedding.d.ts.map +1 -0
  79. package/dist/internal/query-analyzer.d.ts +16 -0
  80. package/dist/internal/query-analyzer.d.ts.map +1 -0
  81. package/dist/internal/reader.d.ts +64 -0
  82. package/dist/internal/reader.d.ts.map +1 -0
  83. package/dist/internal/session-loader.d.ts +25 -0
  84. package/dist/internal/session-loader.d.ts.map +1 -0
  85. package/dist/internal/session-summary-writer.d.ts +43 -0
  86. package/dist/internal/session-summary-writer.d.ts.map +1 -0
  87. package/dist/internal/sqlite-vec-loader.d.ts +62 -0
  88. package/dist/internal/sqlite-vec-loader.d.ts.map +1 -0
  89. package/dist/internal/tools.d.ts +44 -0
  90. package/dist/internal/tools.d.ts.map +1 -0
  91. package/dist/internal/transcript-store.d.ts +36 -0
  92. package/dist/internal/transcript-store.d.ts.map +1 -0
  93. package/dist/internal/vec-index.d.ts +81 -0
  94. package/dist/internal/vec-index.d.ts.map +1 -0
  95. package/dist/internal/voyage-embedding.d.ts +23 -0
  96. package/dist/internal/voyage-embedding.d.ts.map +1 -0
  97. package/dist/internal/wiki-loader.d.ts +24 -0
  98. package/dist/internal/wiki-loader.d.ts.map +1 -0
  99. package/package.json +74 -0
@@ -0,0 +1,49 @@
1
+ import type { EmbeddingRuntime } from "./embedding-adapter.js";
2
+ /**
3
+ * Dreaming sweep orchestrator (ADR D7 of memory-system-openclaw-parity).
4
+ *
5
+ * Phases:
6
+ * 1. **light** — drop near-duplicate facts via cosine similarity.
7
+ * 2. **REM** — cluster thematically related facts.
8
+ * 3. **deep** — write a `notes/dreamed-<ts>.md` per sweep with consolidated
9
+ * clusters; append a diary entry.
10
+ *
11
+ * All file writes go through `replaceFileAtomic` (EC-3) and the entire sweep
12
+ * holds the per-cwd mutex so a `Remember:` append can't race it.
13
+ *
14
+ * Iter 60 (Stage 3 source-move #17): hybrid copy from sdk-core's
15
+ * `internal/memory/dreaming/run.ts`. sdk-core retains its copy for
16
+ * v1.x dreaming back-compat; sdk-memory ships the canonical
17
+ * orchestrator that composes all four sibling moves from iter 45
18
+ * (`EmbeddingRuntime`), iter 54 (`lightPhase`+`remPhase`+`deepPhase`),
19
+ * iter 56 (`memoryDir`+`readFactsFromMarkdown`), and iter 59
20
+ * (`appendDiaryEntry`). Persistence sub-path provides
21
+ * `replaceFileAtomic` + `withCwdMutex`. This closes the dreaming/
22
+ * cluster — 4 files all in sdk-memory now.
23
+ *
24
+ * Flat-naming convention (not `dreaming/run.ts`): sdk-memory's
25
+ * `internal/` directory stays flat. The `dreaming-` prefix preserves
26
+ * the topical grouping (companion to iter 54's `dreaming-phases` and
27
+ * iter 59's `dreaming-diary`).
28
+ *
29
+ * @internal
30
+ */
31
+ export interface DreamingOptions {
32
+ cwd: string;
33
+ embedding: EmbeddingRuntime;
34
+ dedupThreshold?: number;
35
+ clusterThreshold?: number;
36
+ /** Test hook — fixed timestamp for the run. */
37
+ now?: () => number;
38
+ }
39
+ export interface DreamingResult {
40
+ status: "ok" | "skipped" | "error";
41
+ factsBefore: number;
42
+ factsAfter: number;
43
+ duplicatesRemoved: number;
44
+ clustersCreated: number;
45
+ notesWritten: number;
46
+ diaryEntryHash: string | undefined;
47
+ }
48
+ export declare function runDreamingSweep(options: DreamingOptions): Promise<DreamingResult>;
49
+ //# sourceMappingURL=dreaming-run.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dreaming-run.d.ts","sourceRoot":"","sources":["../../src/internal/dreaming-run.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAG/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,gBAAgB,CAAC;IAC5B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,+CAA+C;IAC/C,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,IAAI,GAAG,SAAS,GAAG,OAAO,CAAC;IACnC,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;CACpC;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC,CAElF"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Memory embedding provider adapter contract (ADR D3 of memory-system-openclaw-parity).
3
+ *
4
+ * Mirrors OpenClaw's `MemoryEmbeddingProviderAdapter` from
5
+ * `referencia/openclaw/extensions/openai/memory-embedding-adapter.ts` so
6
+ * adding a new provider becomes one new file under `adapters/`.
7
+ *
8
+ * @internal
9
+ */
10
+ export interface MemoryEmbeddingProviderAdapter {
11
+ /** Stable provider id (matches OpenClaw's id catalog: "openai", "mistral", …). */
12
+ readonly id: string;
13
+ /** Default model the adapter uses unless the caller overrides via `options.model`. */
14
+ readonly defaultModel: string;
15
+ /** Transport kind. Remote = network HTTP; local = in-process / on-device. */
16
+ readonly transport: "local" | "remote";
17
+ /** Auth provider id used to resolve API keys (mirrors OpenClaw). */
18
+ readonly authProviderId?: string;
19
+ /** Higher priority = auto-select this provider first when multiple are available. */
20
+ readonly autoSelectPriority?: number;
21
+ /** Factory — instantiate a per-agent runtime. */
22
+ create(options: CreateAdapterOptions): Promise<EmbeddingRuntime>;
23
+ }
24
+ export interface CreateAdapterOptions {
25
+ /** Override the adapter's `defaultModel`. */
26
+ model?: string;
27
+ /** Override the API key (else resolved from env). */
28
+ apiKey?: string;
29
+ /** Override the HTTP base URL (else provider default). */
30
+ baseUrl?: string;
31
+ /** Inject a fetch implementation (tests use this to stub HTTP). */
32
+ fetch?: typeof fetch;
33
+ /** Optional cache instance (else a default LRU is created). */
34
+ cache?: EmbeddingCache;
35
+ }
36
+ export interface EmbeddingRuntime {
37
+ readonly id: string;
38
+ readonly model: string;
39
+ readonly dimension: number;
40
+ /** Embed N texts → N vectors of length `dimension`. Handles batching internally. */
41
+ embed(texts: ReadonlyArray<string>): Promise<number[][]>;
42
+ /** Observability — cache hit/miss + call counts. */
43
+ stats(): EmbeddingRuntimeStats;
44
+ }
45
+ export interface EmbeddingRuntimeStats {
46
+ cacheHits: number;
47
+ cacheMisses: number;
48
+ httpCalls: number;
49
+ retries: number;
50
+ }
51
+ export interface EmbeddingCache {
52
+ get(key: string): number[] | undefined;
53
+ set(key: string, value: number[]): void;
54
+ /** Total entries currently held. */
55
+ size(): number;
56
+ }
57
+ //# sourceMappingURL=embedding-adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"embedding-adapter.d.ts","sourceRoot":"","sources":["../../src/internal/embedding-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,WAAW,8BAA8B;IAC7C,kFAAkF;IAClF,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,sFAAsF;IACtF,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,6EAA6E;IAC7E,QAAQ,CAAC,SAAS,EAAE,OAAO,GAAG,QAAQ,CAAC;IACvC,oEAAoE;IACpE,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,qFAAqF;IACrF,QAAQ,CAAC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IACrC,iDAAiD;IACjD,MAAM,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;CAClE;AAED,MAAM,WAAW,oBAAoB;IACnC,6CAA6C;IAC7C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,0DAA0D;IAC1D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mEAAmE;IACnE,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,+DAA+D;IAC/D,KAAK,CAAC,EAAE,cAAc,CAAC;CACxB;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,oFAAoF;IACpF,KAAK,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACzD,oDAAoD;IACpD,KAAK,IAAI,qBAAqB,CAAC;CAChC;AAED,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC;IACvC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IACxC,oCAAoC;IACpC,IAAI,IAAI,MAAM,CAAC;CAChB"}
@@ -0,0 +1,16 @@
1
+ import type { EmbeddingCache } from "./embedding-adapter.js";
2
+ /**
3
+ * Bounded in-memory LRU cache for embeddings, keyed by `sha256(text)` (or any
4
+ * stable key the caller chooses).
5
+ *
6
+ * @internal
7
+ */
8
+ export declare class LruEmbeddingCache implements EmbeddingCache {
9
+ private readonly capacity;
10
+ private readonly map;
11
+ constructor(capacity?: number);
12
+ get(key: string): number[] | undefined;
13
+ set(key: string, value: number[]): void;
14
+ size(): number;
15
+ }
16
+ //# sourceMappingURL=embedding-cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"embedding-cache.d.ts","sourceRoot":"","sources":["../../src/internal/embedding-cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAE7D;;;;;GAKG;AACH,qBAAa,iBAAkB,YAAW,cAAc;IAG1C,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAFrC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAA+B;gBAEtB,QAAQ,GAAE,MAAa;IAEpD,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS;IAStC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI;IAUvC,IAAI,IAAI,MAAM;CAGf"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Thin wrapper around the SQLite driver. Prefers `node:sqlite` when available
3
+ * (Node 22.5+) and falls back to `better-sqlite3`. Both expose nearly the
4
+ * same `prepare/exec/close` surface; we normalize via a minimal adapter.
5
+ *
6
+ * Corrupt-DB recovery (EC-7): when opening fails with a "file is encrypted
7
+ * or is not a database" or "malformed" error, the file is renamed aside to
8
+ * `<path>.corrupt-<ts>` and the schema is rebuilt from scratch.
9
+ *
10
+ * Iter 65 (Stage 3 source-move #22): hybrid copy from sdk-core's
11
+ * `internal/memory/index-db.ts`. sdk-core retains its copy for v1.x
12
+ * sqlite-vec back-compat; sdk-memory ships the canonical copy that
13
+ * future `sqlite-vec-loader`, `vec-index`, `index-manager` moves
14
+ * will compose with. Dependency chain (all resolved):
15
+ * - `@theokit/sdk/errors` for `ConfigurationError` (public)
16
+ * - `@theokit/sdk/internal/persistence` for `applyWalWithFallback`
17
+ * (ADR D63 — NFS/SMB/FUSE-safe WAL adoption)
18
+ * - sibling `./index-schema.js` for SCHEMA + PRAGMA statements (moved iter 49)
19
+ *
20
+ * @internal
21
+ */
22
+ export interface MemoryDb {
23
+ exec(sql: string): void;
24
+ prepare(sql: string): {
25
+ run(...args: unknown[]): {
26
+ changes: number;
27
+ lastInsertRowid: number | bigint;
28
+ };
29
+ get(...args: unknown[]): Record<string, unknown> | undefined;
30
+ all(...args: unknown[]): Array<Record<string, unknown>>;
31
+ };
32
+ /** SQLite `pragma()` access (used by `applyWalWithFallback`). */
33
+ pragma(statement: string, options?: {
34
+ simple?: boolean;
35
+ }): unknown;
36
+ close(): void;
37
+ /** Load a SQLite loadable extension at the given path (used by sqlite-vec). */
38
+ loadExtension(path: string): void;
39
+ }
40
+ export interface OpenDbOptions {
41
+ filePath: string;
42
+ /**
43
+ * When true and opening fails with a corruption error, rename the file aside
44
+ * and create a fresh DB. Default true.
45
+ */
46
+ recoverCorrupt?: boolean;
47
+ }
48
+ export declare function openMemoryDb(opts: OpenDbOptions): Promise<MemoryDb>;
49
+ export declare function defaultIndexPath(cwd: string): string;
50
+ //# sourceMappingURL=index-db.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-db.d.ts","sourceRoot":"","sources":["../../src/internal/index-db.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,MAAM,WAAW,QAAQ;IACvB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG;QACpB,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG;YAAE,OAAO,EAAE,MAAM,CAAC;YAAC,eAAe,EAAE,MAAM,GAAG,MAAM,CAAA;SAAE,CAAC;QAC/E,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;QAC7D,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;KACzD,CAAC;IACF,iEAAiE;IACjE,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC;IACnE,KAAK,IAAI,IAAI,CAAC;IACd,+EAA+E;IAC/E,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACnC;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,wBAAsB,YAAY,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,QAAQ,CAAC,CAWzE;AAqDD,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEpD"}
@@ -0,0 +1,70 @@
1
+ import type { EmbeddingRuntime } from "./embedding-adapter.js";
2
+ /**
3
+ * Memory index manager contract — leaf types shared by `index-manager.ts`
4
+ * (orchestrator), `index-manager-dispatch.ts` (backend dispatch), `lance-memory-adapter.ts`
5
+ * (Lance backend), and `memory-index.ts` (common search-options parsing).
6
+ *
7
+ * **T2.1 / Cycles #11 + #12 + #13 of plan `arch-review-fixes-2026-06-06`
8
+ * (ADR D433):** the previous layout had `index-manager.ts` defining the
9
+ * contract types AND importing runtime from `index-manager-dispatch.ts`;
10
+ * `index-manager-dispatch.ts` importing the types back from `index-manager.ts`;
11
+ * `lance-memory-adapter.ts` and `memory-index.ts` both importing types from
12
+ * `index-manager.ts`. The result was three HIGH-severity cycles
13
+ * (Phase 5 cartographer):
14
+ *
15
+ * #11: index-manager.ts ↔ index-manager-dispatch.ts (2-node)
16
+ * #12: index-manager.ts → index-manager-dispatch.ts → lance-memory-adapter.ts → index-manager.ts (3-node)
17
+ * #13: index-manager.ts → index-manager-dispatch.ts → lance-memory-adapter.ts → memory-index.ts → index-manager.ts (4-node)
18
+ *
19
+ * Single ~60 LOC extraction breaks all three: every cluster member now
20
+ * imports types from this contract; only the orchestrator imports runtime
21
+ * functions from dispatch (one direction, no cycle).
22
+ *
23
+ * **Contract scope:** types only. No runtime code. The single non-cycle
24
+ * import (`EmbeddingRuntime` from `embedding-adapter.ts`) is itself a leaf
25
+ * dependency outside the cluster — does not re-introduce a cycle.
26
+ *
27
+ * @internal — NOT part of the `@theokit/sdk` public API.
28
+ */
29
+ export interface MemorySearchHit {
30
+ /** Path relative to the memory root. */
31
+ path: string;
32
+ startLine: number;
33
+ endLine: number;
34
+ /** Combined score (hybrid when vector backend active, else just textScore). */
35
+ score: number;
36
+ /** FTS5 BM25 score normalized to 0..1 (higher = better). */
37
+ textScore: number;
38
+ /** sqlite-vec distance normalized to 0..1 (higher = better). Omitted when vector backend disabled. */
39
+ vectorScore?: number;
40
+ snippet: string;
41
+ source: "memory" | "sessions" | "wiki";
42
+ /** path:startLine-endLine for citations. */
43
+ citation: string;
44
+ }
45
+ export interface IndexStatus {
46
+ backend: "fts-only" | "hybrid";
47
+ filesIndexed: number;
48
+ chunksIndexed: number;
49
+ lastSyncMs?: number;
50
+ }
51
+ export interface SearchOptions {
52
+ maxResults?: number;
53
+ minScore?: number;
54
+ sources?: ReadonlyArray<"memory" | "sessions" | "wiki">;
55
+ /** 0..1 — vector vs text weight in hybrid scoring (D4). Default 0.6. */
56
+ vectorWeight?: number;
57
+ /** 0..1 — text weight in hybrid scoring. Default 0.4. */
58
+ textWeight?: number;
59
+ }
60
+ /** Vector backend selector. SQLite default; Lance opt-in (ADR D43). */
61
+ export type MemoryBackend = "sqlite-vec" | "lance";
62
+ export interface OpenIndexOptions {
63
+ cwd: string;
64
+ filePath?: string;
65
+ /** When provided, vector index is enabled in hybrid mode. */
66
+ embedding?: EmbeddingRuntime;
67
+ /** Vector backend. Default and only value today: `"sqlite-vec"`. */
68
+ backend?: MemoryBackend;
69
+ }
70
+ //# sourceMappingURL=index-manager-contract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-manager-contract.d.ts","sourceRoot":"","sources":["../../src/internal/index-manager-contract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,MAAM,WAAW,eAAe;IAC9B,wCAAwC;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,+EAA+E;IAC/E,KAAK,EAAE,MAAM,CAAC;IACd,4DAA4D;IAC5D,SAAS,EAAE,MAAM,CAAC;IAClB,sGAAsG;IACtG,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,QAAQ,GAAG,UAAU,GAAG,MAAM,CAAC;IACvC,4CAA4C;IAC5C,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,UAAU,GAAG,QAAQ,CAAC;IAC/B,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,aAAa,CAAC,QAAQ,GAAG,UAAU,GAAG,MAAM,CAAC,CAAC;IACxD,wEAAwE;IACxE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,yDAAyD;IACzD,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,uEAAuE;AACvE,MAAM,MAAM,aAAa,GAAG,YAAY,GAAG,OAAO,CAAC;AAEnD,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6DAA6D;IAC7D,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B,oEAAoE;IACpE,OAAO,CAAC,EAAE,aAAa,CAAC;CACzB"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Dispatch helpers for `IndexManager.open`. Extracted to keep
3
+ * `index-manager.ts` under the G8 400-LoC budget (lancedb-backend-ship-v1-1).
4
+ *
5
+ * Iter 70 (Stage 3 source-move #27): hybrid copy from sdk-core's
6
+ * `internal/memory/index-manager-dispatch.ts`. sdk-core retains
7
+ * its copy for v1.x back-compat; sdk-memory ships the canonical
8
+ * copy that the future `index-manager.ts` move will compose with
9
+ * as a sibling. Dependency chain (all sibling, all moved):
10
+ * - `@theokit/sdk/errors` for `ConfigurationError` (public)
11
+ * - `./index-manager-contract.js` for `MemoryBackend` +
12
+ * `OpenIndexOptions` (moved iter 47)
13
+ * - `./lance-index.js` for `LanceIndex` (moved iter 68)
14
+ * - `./lance-memory-adapter.js` for `LanceMemoryAdapter` (moved iter 69)
15
+ * - `./memory-index.js` for `MemoryIndex` (moved iter 50)
16
+ *
17
+ * @internal
18
+ */
19
+ import type { MemoryBackend, OpenIndexOptions } from "./index-manager-contract.js";
20
+ import type { MemoryIndex } from "./memory-index.js";
21
+ /** Valid backend identifiers — runtime guard against TS-narrowing escapes (EC-1). */
22
+ export declare const VALID_BACKENDS: readonly MemoryBackend[];
23
+ /**
24
+ * EC-1: runtime guard for `opts.backend`. TS union is compile-time only;
25
+ * consumers passing JS `as any` typos must hit a typed error, not silent
26
+ * SQLite fallback.
27
+ */
28
+ export declare function assertValidBackend(backend: string): asserts backend is MemoryBackend;
29
+ /**
30
+ * Lance-path open. Throws `lance_requires_embedding` when no embedding
31
+ * runtime is provided (Lance is vector-only — no FTS fallback).
32
+ * Surfaces `lance_backend_unavailable` from LanceIndex.open when peer
33
+ * dep is absent.
34
+ */
35
+ export declare function openLanceIndex(opts: OpenIndexOptions): Promise<MemoryIndex>;
36
+ //# sourceMappingURL=index-manager-dispatch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-manager-dispatch.d.ts","sourceRoot":"","sources":["../../src/internal/index-manager-dispatch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAGnF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,qFAAqF;AACrF,eAAO,MAAM,cAAc,EAAE,SAAS,aAAa,EAA4B,CAAC;AAEhF;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,IAAI,aAAa,CAOpF;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,WAAW,CAAC,CAajF"}
@@ -0,0 +1,94 @@
1
+ import type { EmbeddingRuntime } from "./embedding-adapter.js";
2
+ import { type MemoryIndex } from "./memory-index.js";
3
+ /**
4
+ * Memory index manager (ADR D2). FTS5-only at Phase 3; vector index lands in
5
+ * Phase 5.
6
+ *
7
+ * Lifecycle:
8
+ * const idx = await IndexManager.open({ cwd });
9
+ * await idx.sync();
10
+ * const hits = await idx.search("query");
11
+ * idx.close();
12
+ *
13
+ * Iter 72 (Stage 3 source-move #29): hybrid copy from sdk-core's
14
+ * `internal/memory/index-manager.ts`. sdk-core retains its copy for
15
+ * v1.x back-compat; sdk-memory ships the canonical orchestrator
16
+ * composing every prior Stage 3 move (sqlite-vec stack iter 47/49/50/53/55-57/62/65-67,
17
+ * lance stack iter 68-70, storage iter 56). The biggest move of the
18
+ * stage at 446 LOC — closes the index/ cluster.
19
+ *
20
+ * @internal
21
+ */
22
+ interface MemorySearchHit {
23
+ readonly path: string;
24
+ readonly startLine: number;
25
+ readonly endLine: number;
26
+ readonly score: number;
27
+ readonly textScore: number;
28
+ readonly vectorScore?: number;
29
+ readonly snippet: string;
30
+ readonly source: "memory" | "sessions" | "wiki";
31
+ readonly citation: string;
32
+ }
33
+ interface IndexStatus {
34
+ backend: "fts-only" | "hybrid";
35
+ filesIndexed: number;
36
+ chunksIndexed: number;
37
+ lastSyncMs?: number;
38
+ }
39
+ interface SearchOptions {
40
+ maxResults?: number;
41
+ minScore?: number;
42
+ vectorWeight?: number;
43
+ textWeight?: number;
44
+ sources?: ReadonlyArray<"memory" | "sessions" | "wiki">;
45
+ }
46
+ interface OpenIndexOptions {
47
+ cwd: string;
48
+ filePath?: string;
49
+ embedding?: EmbeddingRuntime;
50
+ backend?: "sqlite-vec" | "lance";
51
+ }
52
+ export declare class IndexManager implements MemoryIndex {
53
+ private readonly cwd;
54
+ private readonly db;
55
+ private readonly embedding;
56
+ private lastSyncMs;
57
+ private vectorReady;
58
+ private constructor();
59
+ /**
60
+ * Open a memory index. Dispatches to SQLite (default) or Lance (opt-in
61
+ * via `backend: "lance"`). See `openLanceIndex` for Lance-specific
62
+ * preconditions + typed errors.
63
+ */
64
+ static open(opts: OpenIndexOptions & {
65
+ backend: "lance";
66
+ }): Promise<MemoryIndex>;
67
+ static open(opts: Omit<OpenIndexOptions, "backend"> | (OpenIndexOptions & {
68
+ backend?: "sqlite-vec";
69
+ })): Promise<IndexManager>;
70
+ /** Internal SQLite-path open. Renamed from previous public `open`. */
71
+ private static openSqliteInternal;
72
+ private initVectorBackend;
73
+ /** Walk the memory corpus + (re)index changed files. */
74
+ sync(): Promise<{
75
+ filesScanned: number;
76
+ filesUpdated: number;
77
+ chunksWritten: number;
78
+ chunksEmbedded: number;
79
+ }>;
80
+ search(query: string, options?: SearchOptions): Promise<MemorySearchHit[]>;
81
+ status(): IndexStatus;
82
+ private ftsSearch;
83
+ private vectorSearchById;
84
+ private combineHybridScores;
85
+ private mergeHits;
86
+ private fetchChunksByIds;
87
+ private loadFilesIndex;
88
+ private upsertFile;
89
+ private deleteChunksForFile;
90
+ private insertChunk;
91
+ close(): void;
92
+ }
93
+ export {};
94
+ //# sourceMappingURL=index-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-manager.d.ts","sourceRoot":"","sources":["../../src/internal/index-manager.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAI/D,OAAO,EAAE,KAAK,WAAW,EAAsB,MAAM,mBAAmB,CAAC;AAczE;;;;;;;;;;;;;;;;;;GAkBG;AAmBH,UAAU,eAAe;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,QAAQ,GAAG,UAAU,GAAG,MAAM,CAAC;IAChD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED,UAAU,WAAW;IACnB,OAAO,EAAE,UAAU,GAAG,QAAQ,CAAC;IAC/B,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,UAAU,aAAa;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,aAAa,CAAC,QAAQ,GAAG,UAAU,GAAG,MAAM,CAAC,CAAC;CACzD;AAED,UAAU,gBAAgB;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC;CAClC;AAED,qBAAa,YAAa,YAAW,WAAW;IAK5C,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,EAAE;IACnB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAN5B,OAAO,CAAC,UAAU,CAAqB;IACvC,OAAO,CAAC,WAAW,CAAS;IAE5B,OAAO;IAMP;;;;OAIG;WACU,IAAI,CAAC,IAAI,EAAE,gBAAgB,GAAG;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,WAAW,CAAC;WACzE,IAAI,CACf,IAAI,EAAE,IAAI,CAAC,gBAAgB,EAAE,SAAS,CAAC,GAAG,CAAC,gBAAgB,GAAG;QAAE,OAAO,CAAC,EAAE,YAAY,CAAA;KAAE,CAAC,GACxF,OAAO,CAAC,YAAY,CAAC;IAQxB,sEAAsE;mBACjD,kBAAkB;YAQzB,iBAAiB;IAkB/B,wDAAwD;IAClD,IAAI,IAAI,OAAO,CAAC;QACpB,YAAY,EAAE,MAAM,CAAC;QACrB,YAAY,EAAE,MAAM,CAAC;QACrB,aAAa,EAAE,MAAM,CAAC;QACtB,cAAc,EAAE,MAAM,CAAC;KACxB,CAAC;IAkCI,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;IAYpF,MAAM,IAAI,WAAW;IAcrB,OAAO,CAAC,SAAS;YA4CH,gBAAgB;IAiB9B,OAAO,CAAC,mBAAmB;IAa3B,OAAO,CAAC,SAAS;IAejB,OAAO,CAAC,gBAAgB;IAkCxB,OAAO,CAAC,cAAc;IAStB,OAAO,CAAC,UAAU;IAgBlB,OAAO,CAAC,mBAAmB;IAI3B,OAAO,CAAC,WAAW;IAcnB,KAAK,IAAI,IAAI;CAGd"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * SQLite schema for the memory index.
3
+ *
4
+ * Tables:
5
+ * - files — one row per indexed markdown file (path, mtime, hash).
6
+ * - chunks — one row per chunk produced by `chunkMarkdown`.
7
+ * - chunks_fts — FTS5 virtual table mirroring chunks.text for BM25 search.
8
+ * - meta — key/value store; persists the active embedding identity
9
+ * (provider id, model, dimension) so we detect when the
10
+ * index was built against a different embedding setup.
11
+ * - embeddings — sqlite-vec virtual table holding the chunk vectors
12
+ * (created on demand by `vec-index.ts`).
13
+ *
14
+ * Iter 49 (Stage 3 source-move #6): pure SQL-string leaf copied from
15
+ * sdk-core's `internal/memory/index-schema.ts`. Hybrid dual-copy per
16
+ * Phase 2 Stage 1 precedent — sdk-core retains its copy for v1.x
17
+ * back-compat; sdk-memory ships the canonical copy that future
18
+ * sqlite/lance index moves (`index-db`, `index-manager`, `vec-index`,
19
+ * `lance-index`) will target as siblings.
20
+ *
21
+ * @internal
22
+ */
23
+ export declare const SCHEMA_STATEMENTS: ReadonlyArray<string>;
24
+ /**
25
+ * Non-WAL pragmas. WAL is applied separately via
26
+ * `applyWalWithFallback` (T4.2, ADR D63) so NFS/SMB users get a graceful
27
+ * DELETE fallback instead of crashing.
28
+ */
29
+ /**
30
+ * v2 migration: adds created_at, importance, scope columns to chunks.
31
+ * All nullable for backward-compat with existing data (EC-2).
32
+ */
33
+ export declare const MIGRATION_V2_STATEMENTS: ReadonlyArray<string>;
34
+ export declare const PRAGMA_STATEMENTS: ReadonlyArray<string>;
35
+ //# sourceMappingURL=index-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-schema.d.ts","sourceRoot":"","sources":["../../src/internal/index-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,eAAO,MAAM,iBAAiB,EAAE,aAAa,CAAC,MAAM,CAkCnD,CAAC;AAEF;;;;GAIG;AACH;;;GAGG;AACH,eAAO,MAAM,uBAAuB,EAAE,aAAa,CAAC,MAAM,CAIzD,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,aAAa,CAAC,MAAM,CAGnD,CAAC"}
@@ -0,0 +1,70 @@
1
+ import type { EmbeddingRuntime } from "./embedding-adapter.js";
2
+ export interface LanceFactRecord {
3
+ id: string;
4
+ text: string;
5
+ source: "memory" | "sessions" | "wiki";
6
+ embedding: ReadonlyArray<number>;
7
+ namespace: string;
8
+ scope: string;
9
+ user_id: string;
10
+ timestamp: number;
11
+ }
12
+ export interface OpenLanceOptions {
13
+ cwd: string;
14
+ embedding: EmbeddingRuntime;
15
+ /** Override storage location. Default: `<cwd>/.theokit/memory/lance/`. */
16
+ storagePath?: string;
17
+ }
18
+ export interface LanceSearchOptions {
19
+ namespace: string;
20
+ scope?: string;
21
+ limit?: number;
22
+ sources?: ReadonlyArray<"memory" | "sessions" | "wiki">;
23
+ }
24
+ export interface LanceSearchHit {
25
+ id: string;
26
+ text: string;
27
+ source: "memory" | "sessions" | "wiki";
28
+ namespace: string;
29
+ scope: string;
30
+ userId: string;
31
+ score: number;
32
+ }
33
+ /**
34
+ * Lance-backed memory index. Public API mirrors the SQLite one logically:
35
+ * `addFacts`, `search`, `countFacts`, `removeFacts`, `close`.
36
+ *
37
+ * @internal
38
+ */
39
+ export declare class LanceIndex {
40
+ private readonly table;
41
+ private readonly embedding;
42
+ private readonly embeddingDim;
43
+ private constructor();
44
+ static open(opts: OpenLanceOptions): Promise<LanceIndex>;
45
+ addFacts(facts: ReadonlyArray<Omit<LanceFactRecord, "embedding">>): Promise<void>;
46
+ /**
47
+ * Search facts by semantic similarity. EC-1: filters use Lance's
48
+ * SQL string predicate with `'` → `''` escape — bind parameters are
49
+ * not supported by Lance 0.30.
50
+ */
51
+ search(query: string, opts: LanceSearchOptions): Promise<LanceSearchHit[]>;
52
+ countFacts(namespace: string): Promise<number>;
53
+ removeFacts(ids: ReadonlyArray<string>): Promise<void>;
54
+ close(): Promise<void>;
55
+ }
56
+ /**
57
+ * Test helper for {@link LanceIndex}: indicates whether the Lance module
58
+ * is loadable in the current environment. Allows tests to gracefully skip
59
+ * when the optional dep is absent.
60
+ *
61
+ * @internal
62
+ */
63
+ export declare function isLanceAvailable(): boolean;
64
+ /**
65
+ * Test helper: re-export the storage path computation.
66
+ *
67
+ * @internal
68
+ */
69
+ export declare function lanceStoragePath(cwd: string): string;
70
+ //# sourceMappingURL=lance-index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lance-index.d.ts","sourceRoot":"","sources":["../../src/internal/lance-index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AA+D/D,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,QAAQ,GAAG,UAAU,GAAG,MAAM,CAAC;IACvC,SAAS,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,gBAAgB,CAAC;IAC5B,0EAA0E;IAC1E,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,aAAa,CAAC,QAAQ,GAAG,UAAU,GAAG,MAAM,CAAC,CAAC;CACzD;AAED,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,QAAQ,GAAG,UAAU,GAAG,MAAM,CAAC;IACvC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf;AAoBD;;;;;GAKG;AACH,qBAAa,UAAU;IAEnB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,YAAY;IAH/B,OAAO;WAMM,IAAI,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,UAAU,CAAC;IA2CxD,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,IAAI,CAAC,eAAe,EAAE,WAAW,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAWvF;;;;OAIG;IACG,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IA+B1E,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAQ9C,WAAW,CAAC,GAAG,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAUtD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B;AAiCD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,IAAI,OAAO,CAQ1C;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEpD"}
@@ -0,0 +1,102 @@
1
+ /**
2
+ * `LanceMemoryAdapter` — wraps `LanceIndex` to expose the common
3
+ * `MemoryIndex` interface (sync/search/status/close) so consumers of
4
+ * `IndexManager.open({ backend: "lance" })` get a drop-in replacement
5
+ * for the SQLite-backed `IndexManager`.
6
+ *
7
+ * Semantic deltas vs SQLite (documented so callers know what to expect):
8
+ *
9
+ * - `sync()` is a NO-OP. Lance is a pure vector store — there is no
10
+ * markdown corpus to crawl. Returns zero counts. Consumers writing
11
+ * facts use `LanceIndex.addFacts` directly (exposed via the index
12
+ * object returned to advanced callers).
13
+ * - `search()` performs vector-only retrieval. `MemorySearchHit.textScore`
14
+ * is undefined (no FTS5 layer); `vectorScore === score`.
15
+ * - `status()` reports `backend: "hybrid"` only when an embedding runtime
16
+ * is wired (always the case for Lance — embedding is required at open).
17
+ * `chunksIndexed` reflects total Lance row count; `filesIndexed` is 0
18
+ * because Lance does not track file provenance per-row.
19
+ *
20
+ * Ships with the lancedb-backend-ship-v1-1 plan (close D12, supersede via
21
+ * D43). v1.4.0 of `@theokit/sdk`.
22
+ *
23
+ * Iter 69 (Stage 3 source-move #26): hybrid copy from sdk-core's
24
+ * `internal/memory/lance-memory-adapter.ts`. sdk-core retains its
25
+ * copy for v1.x Lance back-compat; sdk-memory ships the canonical
26
+ * copy that the future `index-manager-dispatch.ts` move will compose
27
+ * with as a sibling. Dependency chain (all sibling, all moved):
28
+ * - `IndexStatus`, `MemorySearchHit`, `SearchOptions` from
29
+ * `./index-manager-contract.js` (moved iter 47)
30
+ * - `LanceIndex` from `./lance-index.js` (moved iter 68)
31
+ * - `MemoryIndex`, `parseSearchOptions`, `SyncResult` from
32
+ * `./memory-index.js` (moved iter 50)
33
+ *
34
+ * @internal
35
+ */
36
+ import type { IndexStatus, MemorySearchHit, SearchOptions } from "./index-manager-contract.js";
37
+ import { type MemoryIndex, type SyncResult } from "./memory-index.js";
38
+ /**
39
+ * **Iter 69 rollup-plugin-dts workaround** (mirrors iter 48/53/55/66/67 pattern).
40
+ * Importing `LanceIndex` from sibling `./lance-index.js` fails dts
41
+ * emit with `"LanceIndex" is not exported by "src/internal/lance-index.ts"`
42
+ * because rollup-dts treeshakes the class when it has no public
43
+ * type reaching it transitively — even though the barrel `export *`
44
+ * makes it publicly callable. Same class as iter 66/67's MemoryDb.
45
+ *
46
+ * Fix: inline a structural mirror of the minimal LanceIndex surface
47
+ * the adapter actually uses (search + close + identity for unwrap()
48
+ * via `inner === actual LanceIndex`). The mirror is purely a TYPE —
49
+ * the runtime continues to receive the real LanceIndex instance
50
+ * unchanged. When a future move surfaces LanceIndex through a
51
+ * different publicly-reachable path, this mirror MUST be deleted +
52
+ * the canonical type import restored.
53
+ *
54
+ * @internal
55
+ */
56
+ interface LanceIndex {
57
+ addFacts(facts: ReadonlyArray<{
58
+ id: string;
59
+ text: string;
60
+ source: "memory" | "sessions" | "wiki";
61
+ namespace: string;
62
+ scope: string;
63
+ user_id: string;
64
+ timestamp: number;
65
+ }>): Promise<void>;
66
+ search(query: string, opts: {
67
+ namespace: string;
68
+ scope?: string;
69
+ limit?: number;
70
+ sources?: ReadonlyArray<"memory" | "sessions" | "wiki">;
71
+ }): Promise<ReadonlyArray<{
72
+ id: string;
73
+ text: string;
74
+ source: "memory" | "sessions" | "wiki";
75
+ namespace: string;
76
+ scope: string;
77
+ userId: string;
78
+ score: number;
79
+ }>>;
80
+ countFacts(namespace: string): Promise<number>;
81
+ removeFacts(ids: ReadonlyArray<string>): Promise<void>;
82
+ close(): Promise<void>;
83
+ }
84
+ export declare class LanceMemoryAdapter implements MemoryIndex {
85
+ private readonly inner;
86
+ constructor(inner: LanceIndex);
87
+ /**
88
+ * No-op for Lance — see file header. Returns zero counts so callers'
89
+ * existing logging (`filesScanned: X`) does not break.
90
+ */
91
+ sync(): Promise<SyncResult>;
92
+ search(query: string, options?: SearchOptions): Promise<MemorySearchHit[]>;
93
+ status(): IndexStatus;
94
+ close(): Promise<void>;
95
+ /**
96
+ * Escape hatch for advanced callers (migration tool, benchmark script)
97
+ * that need direct access to addFacts/countFacts/removeFacts.
98
+ */
99
+ unwrap(): LanceIndex;
100
+ }
101
+ export {};
102
+ //# sourceMappingURL=lance-memory-adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lance-memory-adapter.d.ts","sourceRoot":"","sources":["../../src/internal/lance-memory-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC/F,OAAO,EAAE,KAAK,WAAW,EAAsB,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE1F;;;;;;;;;;;;;;;;;GAiBG;AACH,UAAU,UAAU;IAClB,QAAQ,CACN,KAAK,EAAE,aAAa,CAAC;QACnB,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,QAAQ,GAAG,UAAU,GAAG,MAAM,CAAC;QACvC,SAAS,EAAE,MAAM,CAAC;QAClB,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC,GACD,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,MAAM,CACJ,KAAK,EAAE,MAAM,EACb,IAAI,EAAE;QACJ,SAAS,EAAE,MAAM,CAAC;QAClB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,aAAa,CAAC,QAAQ,GAAG,UAAU,GAAG,MAAM,CAAC,CAAC;KACzD,GACA,OAAO,CACR,aAAa,CAAC;QACZ,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,QAAQ,GAAG,UAAU,GAAG,MAAM,CAAC;QACvC,SAAS,EAAE,MAAM,CAAC;QAClB,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,KAAK,EAAE,MAAM,CAAC;KACf,CAAC,CACH,CAAC;IACF,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/C,WAAW,CAAC,GAAG,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAqBD,qBAAa,kBAAmB,YAAW,WAAW;IACxC,OAAO,CAAC,QAAQ,CAAC,KAAK;gBAAL,KAAK,EAAE,UAAU;IAE9C;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,UAAU,CAAC;IAO3B,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;IAepF,MAAM,IAAI,WAAW;IAWf,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B;;;OAGG;IACH,MAAM,IAAI,UAAU;CAGrB"}
@@ -0,0 +1,17 @@
1
+ import { type MemoryConfig, type MemoryFact } from "./memory-types.js";
2
+ export declare function memoryDir(cwd: string): string;
3
+ export declare function memoryMdPath(cwd: string): string;
4
+ export declare function notesDir(cwd: string): string;
5
+ /** Read facts from `MEMORY.md`'s `## Facts` section. Returns `[]` when missing. */
6
+ export declare function readFactsFromMarkdown(cwd: string): Promise<MemoryFact[]>;
7
+ /** Append a fact to `MEMORY.md ## Facts`. Creates the section if missing. Atomic + serialized. */
8
+ export declare function appendFactToMarkdown(cwd: string, fact: MemoryFact): Promise<void>;
9
+ export interface NoteFile {
10
+ slug: string;
11
+ path: string;
12
+ }
13
+ export declare function listNotes(cwd: string): Promise<NoteFile[]>;
14
+ /** Configuration-aware accessors honoring the existing MemoryConfig contract. */
15
+ export declare function readFacts(cwd: string, config: MemoryConfig): Promise<MemoryFact[]>;
16
+ export declare function appendFact(cwd: string, config: MemoryConfig, fact: MemoryFact): Promise<void>;
17
+ //# sourceMappingURL=markdown-store.d.ts.map