@theokit/sdk-memory 0.6.0 → 0.6.1
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/CHANGELOG.md +6 -0
- package/dist/index.cjs +145 -501
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +36 -467
- package/dist/index.js.map +1 -1
- package/dist/internal/active-memory/active-memory-cache.d.ts +1 -66
- package/dist/internal/active-memory/active-memory-cache.d.ts.map +1 -1
- package/dist/internal/active-memory/active-memory-types.d.ts +1 -54
- package/dist/internal/active-memory/active-memory-types.d.ts.map +1 -1
- package/dist/internal/adapter-http-error.d.ts.map +1 -1
- package/dist/internal/dreaming/dreaming-phases.d.ts +5 -53
- package/dist/internal/dreaming/dreaming-phases.d.ts.map +1 -1
- package/dist/internal/dreaming/dreaming-run.d.ts +3 -83
- package/dist/internal/dreaming/dreaming-run.d.ts.map +1 -1
- package/dist/internal/index/index-db.d.ts +1 -67
- package/dist/internal/index/index-db.d.ts.map +1 -1
- package/dist/internal/index/index-schema.d.ts +1 -29
- package/dist/internal/index/index-schema.d.ts.map +1 -1
- package/dist/internal/index/memory-index.d.ts +1 -10
- package/dist/internal/index/memory-index.d.ts.map +1 -1
- package/dist/internal/index/sqlite-vec-loader.d.ts +2 -59
- package/dist/internal/index/sqlite-vec-loader.d.ts.map +1 -1
- package/dist/internal/index/vec-index.d.ts +1 -131
- package/dist/internal/index/vec-index.d.ts.map +1 -1
- package/dist/internal/store/chunk-markdown.d.ts +1 -82
- package/dist/internal/store/chunk-markdown.d.ts.map +1 -1
- package/dist/internal/store/reader.d.ts +1 -86
- package/dist/internal/store/reader.d.ts.map +1 -1
- package/package.json +3 -3
|
@@ -1,67 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* TTL-bounded cache for `runActiveMemory` results. Keyed by
|
|
4
|
-
* `sha256(userText + queryMode)` so two identical sends within `cacheTtlMs`
|
|
5
|
-
* (default 15s, matching peer-project's `DEFAULT_CACHE_TTL_MS`) share a single
|
|
6
|
-
* search.
|
|
7
|
-
*
|
|
8
|
-
* Bounded size; oldest entries evicted first when capacity is exceeded.
|
|
9
|
-
*
|
|
10
|
-
* Iter 51 (Stage 3 source-move #8): hybrid copy from sdk-core's
|
|
11
|
-
* `internal/memory/active-memory-cache.ts`. sdk-core retains its copy
|
|
12
|
-
* for v1.x active-memory back-compat; sdk-memory ships the canonical
|
|
13
|
-
* copy that the future `active-memory.ts` move will target as a
|
|
14
|
-
* sibling. Depends only on `node:crypto` + `./active-memory-types.js`
|
|
15
|
-
* (moved iter 48), so no further dependency chain is required.
|
|
16
|
-
*
|
|
17
|
-
* @internal
|
|
18
|
-
*/
|
|
19
|
-
export interface ActiveMemoryCacheOptions {
|
|
20
|
-
ttlMs?: number;
|
|
21
|
-
capacity?: number;
|
|
22
|
-
now?: () => number;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* A bounded, TTL-expiring cache of recall results, so two identical sends in
|
|
26
|
-
* quick succession run one search.
|
|
27
|
-
*
|
|
28
|
-
* Entries expire `ttlMs` after they were written (default 15s) and are dropped
|
|
29
|
-
* on the read that finds them expired. A read that hits also moves the entry to
|
|
30
|
-
* the most-recent position, so eviction under pressure removes the
|
|
31
|
-
* least-recently-read entry rather than the oldest write.
|
|
32
|
-
*
|
|
33
|
-
* The key covers the query text, the query mode, and the tenant triple
|
|
34
|
-
* (`namespace`, `userId`, `scope`) joined by NUL bytes. Passing no tenant
|
|
35
|
-
* context is allowed and hashes as three empty strings — safe only when the
|
|
36
|
-
* process serves a single tenant.
|
|
37
|
-
*
|
|
38
|
-
* Not process-wide: construct one per agent. Nothing here expires in the
|
|
39
|
-
* background, so an untouched entry occupies its slot until it is read or
|
|
40
|
-
* evicted.
|
|
41
|
-
*/
|
|
42
|
-
export declare class ActiveMemoryCache {
|
|
43
|
-
private readonly opts;
|
|
44
|
-
private readonly map;
|
|
45
|
-
constructor(opts?: ActiveMemoryCacheOptions);
|
|
46
|
-
get(userText: string, queryMode: string, tenantCtx?: TenantContext): ActiveMemoryResult | undefined;
|
|
47
|
-
set(userText: string, queryMode: string, result: ActiveMemoryResult, tenantCtx?: TenantContext): void;
|
|
48
|
-
size(): number;
|
|
49
|
-
private now;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* T4.9 — Tenant isolation context for cache key derivation.
|
|
53
|
-
* Pre-T4.9 the key was `sha256(queryMode + userText)` — two users
|
|
54
|
-
* sharing a process with the same query got each other's results.
|
|
55
|
-
* CRITICAL cross-tenant data leak (DR4 finding #9).
|
|
56
|
-
*
|
|
57
|
-
* Synced from sdk-core's `internal/memory/active-memory-cache.ts`
|
|
58
|
-
* per ADR 0002 Stage 4 routing byte-equivalence invariant (iter 112).
|
|
59
|
-
*
|
|
60
|
-
* @internal
|
|
61
|
-
*/
|
|
62
|
-
export interface TenantContext {
|
|
63
|
-
namespace?: string;
|
|
64
|
-
userId?: string;
|
|
65
|
-
scope?: string;
|
|
66
|
-
}
|
|
1
|
+
export { ActiveMemoryCache, type ActiveMemoryCacheOptions, type TenantContext, } from "@theokit/sdk/internal/memory-store";
|
|
67
2
|
//# sourceMappingURL=active-memory-cache.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"active-memory-cache.d.ts","sourceRoot":"","sources":["../../../src/internal/active-memory/active-memory-cache.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"active-memory-cache.d.ts","sourceRoot":"","sources":["../../../src/internal/active-memory/active-memory-cache.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,KAAK,wBAAwB,EAC7B,KAAK,aAAa,GACnB,MAAM,oCAAoC,CAAC"}
|
|
@@ -1,55 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
* Type-leaf — shared types between `active-memory.ts` and
|
|
3
|
-
* `active-memory-cache.ts`. Extracted to break LOW type-only cycle #10
|
|
4
|
-
* (audit `architecture-output/final_report.md`) per plan
|
|
5
|
-
* arch-review-fixes-2026-06-06 § Phase 4 / T4.1 (D438).
|
|
6
|
-
*
|
|
7
|
-
* Internal — `active-memory.ts` re-exports these for in-tree consumers
|
|
8
|
-
* that historically imported from there.
|
|
9
|
-
*
|
|
10
|
-
* **Iter 48 → iter 50 evolution:** the original `MemorySearchHit`
|
|
11
|
-
* import from `./index-manager-contract.js` was temporarily inlined
|
|
12
|
-
* as a duplicate interface because rollup-plugin-dts treeshook it out
|
|
13
|
-
* of sdk-memory's dist (no reachable consumer yet). Iter 50 moved
|
|
14
|
-
* `memory-index.ts` into sdk-memory and the barrel now publicly
|
|
15
|
-
* re-exports `MemorySearchHit` — creating the reachable consumer —
|
|
16
|
-
* so this file restores the canonical import and the inline mirror
|
|
17
|
-
* is gone. Single source of truth is back.
|
|
18
|
-
*
|
|
19
|
-
* @internal
|
|
20
|
-
*/
|
|
21
|
-
import type { MemorySearchHit } from "../index/index-manager-contract.js";
|
|
22
|
-
/**
|
|
23
|
-
* How the recall query is built from the conversation.
|
|
24
|
-
*
|
|
25
|
-
* `message` uses only the incoming user text. `recent` (the default) prepends
|
|
26
|
-
* the last few user turns, so a follow-up like "and the other one?" still
|
|
27
|
-
* carries its subject. `full` prepends every prior user turn, which broadens
|
|
28
|
-
* recall but lets an old topic dominate a long conversation. Assistant turns are
|
|
29
|
-
* never included in any mode.
|
|
30
|
-
*/
|
|
31
|
-
export type ActiveMemoryQueryMode = "message" | "recent" | "full";
|
|
32
|
-
/**
|
|
33
|
-
* Outcome of one recall attempt.
|
|
34
|
-
*
|
|
35
|
-
* `ok` is the only status that carries a summary. `no-recall` means the search
|
|
36
|
-
* ran and matched nothing, or the built query was empty. `skipped` means no
|
|
37
|
-
* search was attempted at all — recall disabled, no index, or the circuit
|
|
38
|
-
* breaker open. `timeout` means the search outlived `timeoutMs`, and `error`
|
|
39
|
-
* that it threw. The four non-`ok` statuses are reported, never thrown: recall
|
|
40
|
-
* failing must not fail the agent run.
|
|
41
|
-
*/
|
|
42
|
-
export type ActiveMemoryStatus = "ok" | "timeout" | "skipped" | "no-recall" | "error";
|
|
43
|
-
/**
|
|
44
|
-
* Result of one recall attempt. `summary` is set only when `status` is `ok`, and
|
|
45
|
-
* is the text the system-prompt pipeline injects. `hits` carries the underlying
|
|
46
|
-
* matches so a caller can render its own block instead. `durationMs` covers the
|
|
47
|
-
* search only, and is 0 on the `skipped` paths.
|
|
48
|
-
*/
|
|
49
|
-
export interface ActiveMemoryResult {
|
|
50
|
-
summary: string | undefined;
|
|
51
|
-
durationMs: number;
|
|
52
|
-
status: ActiveMemoryStatus;
|
|
53
|
-
hits: ReadonlyArray<MemorySearchHit>;
|
|
54
|
-
}
|
|
1
|
+
export type { ActiveMemoryQueryMode, ActiveMemoryResult, ActiveMemoryStatus, } from "@theokit/sdk/internal/memory-store";
|
|
55
2
|
//# sourceMappingURL=active-memory-types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"active-memory-types.d.ts","sourceRoot":"","sources":["../../../src/internal/active-memory/active-memory-types.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"active-memory-types.d.ts","sourceRoot":"","sources":["../../../src/internal/active-memory/active-memory-types.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,qBAAqB,EACrB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,oCAAoC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter-http-error.d.ts","sourceRoot":"","sources":["../../src/internal/adapter-http-error.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAGL,KAAK,SAAS,EACd,KAAK,aAAa,EAGlB,KAAK,iBAAiB,EAEvB,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"adapter-http-error.d.ts","sourceRoot":"","sources":["../../src/internal/adapter-http-error.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAGL,KAAK,SAAS,EACd,KAAK,aAAa,EAGlB,KAAK,iBAAiB,EAEvB,MAAM,qBAAqB,CAAC;AAU7B;;;GAGG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAOhF;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAMlD;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE;IACvC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,GAAG,SAAS,CAAC;IAC7B,IAAI,EAAE,OAAO,CAAC;CACf,GAAG,aAAa,CAWhB;AAED,UAAU,kBAAkB;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,OAAO,GAAG,SAAS,CAAC;IAC7B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,kBAAkB,GAAG,iBAAiB,CAuCpF"}
|
|
@@ -1,57 +1,9 @@
|
|
|
1
|
-
import type { EmbeddingRuntime } from "../embedding/embedding-adapter.js";
|
|
2
|
-
import type { MemoryFact } from "../memory-types.js";
|
|
3
1
|
/**
|
|
4
|
-
* Dreaming/
|
|
2
|
+
* Dreaming phases — re-exported from `@theokit/sdk`, not reimplemented here (B-444).
|
|
5
3
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* - **deep** — pick a representative bullet per cluster (longest text
|
|
10
|
-
* wins) and emit consolidated markdown notes.
|
|
11
|
-
*
|
|
12
|
-
* Iter 54 (Stage 3 source-move #11): hybrid copy from sdk-core's
|
|
13
|
-
* `internal/memory/dreaming/phases.ts`. sdk-core retains its copy
|
|
14
|
-
* for v1.x dreaming back-compat; sdk-memory ships the canonical copy
|
|
15
|
-
* that future `dreaming/run.ts` move will compose with as a sibling.
|
|
16
|
-
* Dependencies (both moved): `EmbeddingRuntime` (iter 45) +
|
|
17
|
-
* `MemoryFact` (iter 52).
|
|
18
|
-
*
|
|
19
|
-
* Flat-naming convention (not `dreaming/phases.ts`): sdk-memory's
|
|
20
|
-
* `internal/` directory stays flat to keep relative-import paths
|
|
21
|
-
* uniform across iter 44-53. The `dreaming-` prefix preserves the
|
|
22
|
-
* topical grouping without a sub-directory.
|
|
23
|
-
*
|
|
24
|
-
* @internal
|
|
25
|
-
*/
|
|
26
|
-
export interface DedupResult {
|
|
27
|
-
kept: MemoryFact[];
|
|
28
|
-
duplicatesRemoved: number;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* A group of facts the REM phase judged related. `representativeText` is the
|
|
32
|
-
* text of the longest member, used as the cluster's heading in the consolidated
|
|
33
|
-
* note — longest, not most central, so it is a readable label rather than a
|
|
34
|
-
* centroid. `members` includes that fact as well.
|
|
35
|
-
*/
|
|
36
|
-
export interface Cluster {
|
|
37
|
-
representativeText: string;
|
|
38
|
-
members: ReadonlyArray<MemoryFact>;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* What {@link remPhase} produced. Every input fact inside the per-sweep cap
|
|
42
|
-
* appears in exactly one cluster, so a fact related to nothing comes back as a
|
|
43
|
-
* cluster of one — the count is not a count of *interesting* groupings. Facts
|
|
44
|
-
* past the cap are counted in `factsLeftOut` and appear in no cluster.
|
|
4
|
+
* This was a copy that had already drifted: it lacked the protected-kind dedup policy. A fix in
|
|
5
|
+
* one copy did not reach the other, and `Memory.runDreamingSweep` runs this package's whenever it
|
|
6
|
+
* is installed.
|
|
45
7
|
*/
|
|
46
|
-
export
|
|
47
|
-
clusters: Cluster[];
|
|
48
|
-
/** How many input facts past the per-sweep cap were not clustered; 0 when none were. */
|
|
49
|
-
factsLeftOut: number;
|
|
50
|
-
}
|
|
51
|
-
/** Light phase — drop facts whose embedding is too similar to one already kept. */
|
|
52
|
-
export declare function lightPhase(facts: ReadonlyArray<MemoryFact>, embedding: EmbeddingRuntime, threshold?: number): Promise<DedupResult>;
|
|
53
|
-
/** REM phase — single-link agglomerative clustering by cosine similarity. */
|
|
54
|
-
export declare function remPhase(facts: ReadonlyArray<MemoryFact>, embedding: EmbeddingRuntime, threshold?: number, maxFactsPerSweep?: number): Promise<ClusterResult>;
|
|
55
|
-
/** Deep phase — render consolidated markdown for the dreamed note. */
|
|
56
|
-
export declare function deepPhase(clusters: ReadonlyArray<Cluster>, timestampMs: number): string;
|
|
8
|
+
export { type Cluster, type ClusterResult, type DedupResult, deepPhase, lightPhase, remPhase, } from "@theokit/sdk/internal/memory-store";
|
|
57
9
|
//# sourceMappingURL=dreaming-phases.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dreaming-phases.d.ts","sourceRoot":"","sources":["../../../src/internal/dreaming/dreaming-phases.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"dreaming-phases.d.ts","sourceRoot":"","sources":["../../../src/internal/dreaming/dreaming-phases.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,SAAS,EACT,UAAU,EACV,QAAQ,GACT,MAAM,oCAAoC,CAAC"}
|
|
@@ -1,86 +1,6 @@
|
|
|
1
|
-
import type { EmbeddingRuntime } from "../embedding/embedding-adapter.js";
|
|
2
1
|
/**
|
|
3
|
-
* Dreaming sweep orchestrator
|
|
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). The sweep holds a
|
|
12
|
-
* mutex for the whole run, so two sweeps over the same workspace serialize.
|
|
13
|
-
* Note the key is `dream:<cwd>`, while `appendFactToMarkdown` locks on the
|
|
14
|
-
* memory directory — different keys, so a concurrent `Remember:` append is NOT
|
|
15
|
-
* excluded by this lock. It cannot corrupt a file (each write is atomic), but a
|
|
16
|
-
* fact appended after the sweep read `MEMORY.md` is simply not in the sweep.
|
|
17
|
-
*
|
|
18
|
-
* Iter 60 (Stage 3 source-move #17): hybrid copy from sdk-core's
|
|
19
|
-
* `internal/memory/dreaming/run.ts`. sdk-core retains its copy for
|
|
20
|
-
* v1.x dreaming back-compat; sdk-memory ships the canonical
|
|
21
|
-
* orchestrator that composes all four sibling moves from iter 45
|
|
22
|
-
* (`EmbeddingRuntime`), iter 54 (`lightPhase`+`remPhase`+`deepPhase`),
|
|
23
|
-
* iter 56 (`memoryDir`+`readFactsFromMarkdown`), and iter 59
|
|
24
|
-
* (`appendDiaryEntry`). Persistence sub-path provides
|
|
25
|
-
* `replaceFileAtomic` + `withCwdMutex`. This closes the dreaming/
|
|
26
|
-
* cluster — 4 files all in sdk-memory now.
|
|
27
|
-
*
|
|
28
|
-
* Flat-naming convention (not `dreaming/run.ts`): sdk-memory's
|
|
29
|
-
* `internal/` directory stays flat. The `dreaming-` prefix preserves
|
|
30
|
-
* the topical grouping (companion to iter 54's `dreaming-phases` and
|
|
31
|
-
* iter 59's `dreaming-diary`).
|
|
32
|
-
*
|
|
33
|
-
* @internal
|
|
2
|
+
* Dreaming sweep orchestrator — re-exported from `@theokit/sdk`, not reimplemented here (B-444).
|
|
3
|
+
* One implementation, so `Memory.runDreamingSweep` answers the same with or without this package.
|
|
34
4
|
*/
|
|
35
|
-
export
|
|
36
|
-
cwd: string;
|
|
37
|
-
embedding: EmbeddingRuntime;
|
|
38
|
-
dedupThreshold?: number;
|
|
39
|
-
clusterThreshold?: number;
|
|
40
|
-
/** Test hook — fixed timestamp for the run. */
|
|
41
|
-
now?: () => number;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* What one sweep did. `skipped` means `MEMORY.md` held no facts; `error` means
|
|
45
|
-
* the sweep threw and the counts are all zero.
|
|
46
|
-
*
|
|
47
|
-
* `factsAfter` is the count that survived in-memory deduplication, not a new
|
|
48
|
-
* size for `MEMORY.md` — the sweep does not rewrite it, so the duplicates it
|
|
49
|
-
* counted are still on disk and will be counted again next time. `notesWritten`
|
|
50
|
-
* is 0 or 1: one consolidated note per sweep, holding every cluster.
|
|
51
|
-
*
|
|
52
|
-
* `diaryEntryHash` is currently always `undefined`, on every path including
|
|
53
|
-
* success, even though the diary entry itself is written with a hash.
|
|
54
|
-
*/
|
|
55
|
-
export interface DreamingResult {
|
|
56
|
-
status: "ok" | "skipped" | "error";
|
|
57
|
-
factsBefore: number;
|
|
58
|
-
factsAfter: number;
|
|
59
|
-
duplicatesRemoved: number;
|
|
60
|
-
clustersCreated: number;
|
|
61
|
-
notesWritten: number;
|
|
62
|
-
diaryEntryHash: string | undefined;
|
|
63
|
-
/**
|
|
64
|
-
* Deduplicated facts past the per-sweep cap that were not clustered. Set on `"ok"`, 0 on
|
|
65
|
-
* `"skipped"`, and absent on `"error"`, where the sweep cannot say how many it left out.
|
|
66
|
-
*/
|
|
67
|
-
factsLeftOut?: number;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Run one consolidation sweep over `MEMORY.md`: drop near-duplicate facts,
|
|
71
|
-
* cluster what is left, write a consolidated note under `notes/`, and append a
|
|
72
|
-
* diary entry.
|
|
73
|
-
*
|
|
74
|
-
* Every fact is embedded on each sweep, and clustering compares every pair, so
|
|
75
|
-
* cost grows with the square of the corpus. That is why the REM phase looks at
|
|
76
|
-
* the first 500 facts only.
|
|
77
|
-
*
|
|
78
|
-
* Never rejects: a failure is written to stderr and reported as
|
|
79
|
-
* `status: "error"`, so a sweep scheduled inside an agent run cannot break it.
|
|
80
|
-
*
|
|
81
|
-
* The sweep is read-only with respect to `MEMORY.md`. It produces a note beside
|
|
82
|
-
* it and leaves the fact list untouched, which means running it twice produces
|
|
83
|
-
* two notes over the same facts.
|
|
84
|
-
*/
|
|
85
|
-
export declare function runDreamingSweep(options: DreamingOptions): Promise<DreamingResult>;
|
|
5
|
+
export { type DreamingOptions, type DreamingResult, runDreamingSweep, } from "@theokit/sdk/internal/memory-store";
|
|
86
6
|
//# sourceMappingURL=dreaming-run.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dreaming-run.d.ts","sourceRoot":"","sources":["../../../src/internal/dreaming/dreaming-run.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dreaming-run.d.ts","sourceRoot":"","sources":["../../../src/internal/dreaming/dreaming-run.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,gBAAgB,GACjB,MAAM,oCAAoC,CAAC"}
|
|
@@ -1,68 +1,2 @@
|
|
|
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/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
|
-
/** Options for {@link openMemoryDb}. */
|
|
41
|
-
export interface OpenDbOptions {
|
|
42
|
-
filePath: string;
|
|
43
|
-
/**
|
|
44
|
-
* When true and opening fails with a corruption error, rename the file aside
|
|
45
|
-
* and create a fresh DB. Default true.
|
|
46
|
-
*/
|
|
47
|
-
recoverCorrupt?: boolean;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Open (or create) the SQLite memory index at `filePath`, applying the pragmas
|
|
51
|
-
* and creating the schema before returning. Parent directories are created as
|
|
52
|
-
* needed, so pointing this at a fresh workspace works.
|
|
53
|
-
*
|
|
54
|
-
* The driver is chosen at runtime: `node:sqlite` where the running Node exposes
|
|
55
|
-
* it, and `better-sqlite3` otherwise. `better-sqlite3` is an optional peer
|
|
56
|
-
* dependency of this package — on a Node build without `node:sqlite` and
|
|
57
|
-
* without it installed, opening fails.
|
|
58
|
-
*
|
|
59
|
-
* A file that is corrupt, truncated or encrypted is renamed aside to
|
|
60
|
-
* `<path>.corrupt-<timestamp>` and rebuilt empty, unless `recoverCorrupt` is
|
|
61
|
-
* `false`. Recovery loses every indexed chunk; the markdown corpus is the source
|
|
62
|
-
* of truth and the next `sync()` rebuilds from it.
|
|
63
|
-
*
|
|
64
|
-
* Loading the sqlite-vec extension is a separate step — this returns an index
|
|
65
|
-
* that can do text search only.
|
|
66
|
-
*/
|
|
67
|
-
export declare function openMemoryDb(opts: OpenDbOptions): Promise<MemoryDb>;
|
|
1
|
+
export { type MemoryDb, type OpenDbOptions, openMemoryDb, } from "@theokit/sdk/internal/memory-store";
|
|
68
2
|
//# sourceMappingURL=index-db.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-db.d.ts","sourceRoot":"","sources":["../../../src/internal/index/index-db.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index-db.d.ts","sourceRoot":"","sources":["../../../src/internal/index/index-db.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,YAAY,GACb,MAAM,oCAAoC,CAAC"}
|
|
@@ -1,30 +1,2 @@
|
|
|
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
|
-
export declare const PRAGMA_STATEMENTS: ReadonlyArray<string>;
|
|
1
|
+
export { PRAGMA_STATEMENTS, SCHEMA_STATEMENTS } from "@theokit/sdk/internal/memory-store";
|
|
30
2
|
//# sourceMappingURL=index-schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-schema.d.ts","sourceRoot":"","sources":["../../../src/internal/index/index-schema.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index-schema.d.ts","sourceRoot":"","sources":["../../../src/internal/index/index-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC"}
|
|
@@ -43,16 +43,7 @@ export interface SyncResult {
|
|
|
43
43
|
chunksWritten: number;
|
|
44
44
|
chunksEmbedded: number;
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
* Common search-options parser used by both `IndexManager.search` and
|
|
48
|
-
* `LanceMemoryAdapter.search`. Returns the normalized cap + minimum-score
|
|
49
|
-
* floor — eliminates jscpd duplication while keeping per-backend search
|
|
50
|
-
* logic distinct.
|
|
51
|
-
*/
|
|
52
|
-
export declare function parseSearchOptions(options?: SearchOptions): {
|
|
53
|
-
maxResults: number;
|
|
54
|
-
minScore: number;
|
|
55
|
-
};
|
|
46
|
+
export { parseSearchOptions } from "@theokit/sdk/internal/memory-store";
|
|
56
47
|
/**
|
|
57
48
|
* The four operations both backends implement, and the type every consumer
|
|
58
49
|
* should hold. `IndexManager.open` returns this rather than a concrete class
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory-index.d.ts","sourceRoot":"","sources":["../../../src/internal/index/memory-index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAW/F;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;CACxB;
|
|
1
|
+
{"version":3,"file":"memory-index.d.ts","sourceRoot":"","sources":["../../../src/internal/index/memory-index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAW/F;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;CACxB;AAKD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAExE;;;;;;;;GAQG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;OAIG;IACH,IAAI,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC;IAE5B;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC,CAAC;IAE3E,4DAA4D;IAC5D,MAAM,IAAI,WAAW,CAAC;IAEtB,0CAA0C;IAC1C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CAC/B"}
|
|
@@ -1,62 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* The canonical sdk-core copy imports `MemoryDb` from `./index-db.js`
|
|
4
|
-
* (sibling). In sdk-memory the same interface lives in sibling
|
|
5
|
-
* `./index-db.js` (moved iter 65) but rollup-plugin-dts treeshakes
|
|
6
|
-
* it out of the bundled .d.ts emit because no PUBLIC type reaches it
|
|
7
|
-
* transitively yet — sqlite-vec-loader's signatures would be the
|
|
8
|
-
* first consumer BUT rollup-dts resolves the import BEFORE the
|
|
9
|
-
* loader's exports are bundled into the public emit. Result:
|
|
10
|
-
* "MemoryDb is not exported by src/internal/index-db.ts" build error.
|
|
11
|
-
*
|
|
12
|
-
* Fix: inline a structural mirror of the minimal MemoryDb shape that
|
|
13
|
-
* sqlite-vec-loader actually needs (just `prepare` for the version
|
|
14
|
-
* probe; everything else delegated via the loader's untyped
|
|
15
|
-
* dynamic-import call to sqlite-vec's native `load`). Mirror is
|
|
16
|
-
* narrower than the canonical contract on purpose — this file's
|
|
17
|
-
* runtime never touches exec/close/pragma/loadExtension directly.
|
|
18
|
-
* When a future move turns MemoryDb into a publicly-reachable type
|
|
19
|
-
* through a different path (e.g. vec-index.ts surfacing the interface
|
|
20
|
-
* from its own typed signatures), this mirror MUST be deleted +
|
|
21
|
-
* the canonical import restored.
|
|
22
|
-
*
|
|
23
|
-
* @internal
|
|
24
|
-
*/
|
|
25
|
-
interface MemoryDb {
|
|
26
|
-
exec(sql: string): void;
|
|
27
|
-
prepare(sql: string): {
|
|
28
|
-
run(...args: unknown[]): {
|
|
29
|
-
changes: number;
|
|
30
|
-
lastInsertRowid: number | bigint;
|
|
31
|
-
};
|
|
32
|
-
get(...args: unknown[]): Record<string, unknown> | undefined;
|
|
33
|
-
all(...args: unknown[]): Array<Record<string, unknown>>;
|
|
34
|
-
};
|
|
35
|
-
pragma(statement: string, options?: {
|
|
36
|
-
simple?: boolean;
|
|
37
|
-
}): unknown;
|
|
38
|
-
close(): void;
|
|
39
|
-
loadExtension(path: string): void;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Load the `sqlite-vec` extension into an opened SQLite connection.
|
|
43
|
-
*
|
|
44
|
-
* Wraps the native `load(db)` call from the `sqlite-vec` npm package with a
|
|
45
|
-
* typed error path (EC-8 of the edge-case review) so callers see a
|
|
46
|
-
* `sqlite_vec_unavailable` ConfigurationError instead of a raw native error.
|
|
47
|
-
*
|
|
48
|
-
* Iter 66 (Stage 3 source-move #23): hybrid copy from sdk-core's
|
|
49
|
-
* `internal/memory/sqlite-vec-loader.ts`. sdk-core retains its copy
|
|
50
|
-
* for v1.x sqlite-vec back-compat; sdk-memory ships the canonical
|
|
51
|
-
* copy that future `vec-index.ts` move will compose with as a
|
|
52
|
-
* sibling. Dependency chain (all resolved):
|
|
53
|
-
* - `@theokit/sdk/errors` for `ConfigurationError` (public)
|
|
54
|
-
* - sibling `./index-db.js` for `MemoryDb` (moved iter 65)
|
|
55
|
-
*
|
|
56
|
-
* @internal
|
|
57
|
-
*/
|
|
58
|
-
export declare function loadSqliteVecExtension(db: MemoryDb): Promise<void>;
|
|
1
|
+
import type { MemoryDb } from "@theokit/sdk/internal/memory-store";
|
|
2
|
+
export { loadSqliteVecExtension } from "@theokit/sdk/internal/memory-store";
|
|
59
3
|
/** Check whether sqlite-vec is loaded by running a tiny version query. */
|
|
60
4
|
export declare function isSqliteVecLoaded(db: MemoryDb): boolean;
|
|
61
|
-
export {};
|
|
62
5
|
//# sourceMappingURL=sqlite-vec-loader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-vec-loader.d.ts","sourceRoot":"","sources":["../../../src/internal/index/sqlite-vec-loader.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sqlite-vec-loader.d.ts","sourceRoot":"","sources":["../../../src/internal/index/sqlite-vec-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAGnE,OAAO,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAE5E,0EAA0E;AAC1E,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,CAOvD"}
|