@persql/context 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.
package/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # @persql/context
2
+
3
+ Shared, structured agent context on the [PerSQL](https://persql.com) substrate.
4
+
5
+ One store, readable and writable from every agent surface PerSQL speaks — SDK,
6
+ MCP, published endpoints, CLI — so a fleet of agents (local, cloud, or
7
+ third-party) shares the same durable facts, entities, and relationships.
8
+
9
+ Retrieval is **lexical**: FTS5 with the porter stemmer, BM25-ranked. The way a
10
+ coding agent already retrieves — grep over exact tokens — but over durable,
11
+ shared, structured memory. No vector database. If you need semantic similarity,
12
+ layer one over these rows and keep the source of truth here.
13
+
14
+ ## Install
15
+
16
+ ```sh
17
+ npm install @persql/context @persql/sdk
18
+ ```
19
+
20
+ ## Use
21
+
22
+ ```ts
23
+ import { PerSQL } from "@persql/sdk";
24
+ import { context } from "@persql/context";
25
+
26
+ const persql = new PerSQL({ token: process.env.PERSQL_TOKEN! });
27
+ const ctx = context(persql.database("acme/team-context"), { source: "my-agent" });
28
+
29
+ await ctx.init(); // create the schema once (idempotent)
30
+
31
+ // Write structured facts.
32
+ await ctx.remember({
33
+ topic: "billing",
34
+ body: "Acme prefers net-30 invoicing",
35
+ tags: ["billing", "invoice"],
36
+ });
37
+
38
+ // Recall by keyword — BM25-ranked, most relevant first.
39
+ const hits = await ctx.recall("invoice OR payment");
40
+
41
+ // Relate entities; walk the neighborhood.
42
+ await ctx.link("api worker", "depends_on", "billing meter");
43
+ const graph = await ctx.neighbors("api worker", { depth: 1 });
44
+ ```
45
+
46
+ ## Write-time intelligence (optional)
47
+
48
+ The expensive part — turning a raw dump into clean rows — runs on the **write**
49
+ path, not on every read. Bring your own LLM:
50
+
51
+ ```ts
52
+ const ctx = context(db, {
53
+ extract: async (raw) => myLlm.extract(raw), // -> { facts, entities, edges }
54
+ });
55
+
56
+ await ctx.rememberRaw("long conversation or doc…");
57
+ ```
58
+
59
+ `@persql/context/core` exports the extraction contract (`EXTRACTION_SYSTEM_PROMPT`,
60
+ `EXTRACTION_JSON_SCHEMA`) so your extractor returns exactly the shape `write()`
61
+ persists. The hosted PerSQL Context MCP runs this server-side and meters it; the
62
+ SDK keeps reads cheap and AI-free.
63
+
64
+ ## Surface
65
+
66
+ | | |
67
+ |---|---|
68
+ | `init()` | create schema (idempotent) |
69
+ | `remember(input)` | store a structured fact/episode/artifact → id |
70
+ | `rememberRaw(raw, { extract })` | extract durable context from text, then store |
71
+ | `write(extracted)` | persist an already-extracted `{ facts, entities, edges }` bundle |
72
+ | `recall(query, opts)` | keyword recall, BM25-ranked |
73
+ | `recent(opts)` / `byTag(tag, opts)` | list by recency / tag |
74
+ | `link(src, rel, dst)` | relate two entities |
75
+ | `neighbors(name, { depth })` | the subgraph around an entity |
76
+ | `supersede(oldIds, newId)` / `forget(id)` | replace / delete |
77
+ | `stats()` | counts |
78
+
79
+ ## Cost
80
+
81
+ Memory is rows like any other — metered on rows read, rows written, and storage,
82
+ with no per-table or per-memory fee. Reads are plain SQL (cheap); only
83
+ `rememberRaw`/extraction spends AI tokens, and only on write.
84
+
85
+ ## Schema
86
+
87
+ `@persql/context/core` is zero-dependency and exports the DDL, SQL builders, and
88
+ types — imported by both this SDK and the hosted worker so client-side and
89
+ server-side recall can never drift.
@@ -0,0 +1,339 @@
1
+ // src/core.ts
2
+ var SCHEMA_VERSION = 1;
3
+ var TABLE_PREFIX = "ctx_";
4
+ var T = TABLE_PREFIX;
5
+ var SCHEMA_SQL = [
6
+ `CREATE TABLE IF NOT EXISTS ${T}memory (
7
+ id TEXT PRIMARY KEY,
8
+ kind TEXT NOT NULL DEFAULT 'fact',
9
+ topic TEXT,
10
+ body TEXT NOT NULL,
11
+ tags TEXT,
12
+ source TEXT,
13
+ created_at INTEGER NOT NULL,
14
+ superseded_by TEXT
15
+ )`,
16
+ `CREATE INDEX IF NOT EXISTS ${T}memory_kind ON ${T}memory(kind)`,
17
+ `CREATE INDEX IF NOT EXISTS ${T}memory_created ON ${T}memory(created_at)`,
18
+ `CREATE INDEX IF NOT EXISTS ${T}memory_superseded ON ${T}memory(superseded_by)`,
19
+ // External-content FTS index: body text is not duplicated, only indexed.
20
+ // Porter stemmer so "invoice" recalls "invoicing" without embeddings.
21
+ `CREATE VIRTUAL TABLE IF NOT EXISTS ${T}memory_fts USING fts5(
22
+ topic, body, tags,
23
+ content='${T}memory', content_rowid='rowid',
24
+ tokenize='porter unicode61'
25
+ )`,
26
+ `CREATE TRIGGER IF NOT EXISTS ${T}memory_ai AFTER INSERT ON ${T}memory BEGIN
27
+ INSERT INTO ${T}memory_fts(rowid, topic, body, tags)
28
+ VALUES (new.rowid, new.topic, new.body, new.tags);
29
+ END`,
30
+ `CREATE TRIGGER IF NOT EXISTS ${T}memory_ad AFTER DELETE ON ${T}memory BEGIN
31
+ INSERT INTO ${T}memory_fts(${T}memory_fts, rowid, topic, body, tags)
32
+ VALUES ('delete', old.rowid, old.topic, old.body, old.tags);
33
+ END`,
34
+ `CREATE TRIGGER IF NOT EXISTS ${T}memory_au AFTER UPDATE ON ${T}memory BEGIN
35
+ INSERT INTO ${T}memory_fts(${T}memory_fts, rowid, topic, body, tags)
36
+ VALUES ('delete', old.rowid, old.topic, old.body, old.tags);
37
+ INSERT INTO ${T}memory_fts(rowid, topic, body, tags)
38
+ VALUES (new.rowid, new.topic, new.body, new.tags);
39
+ END`,
40
+ `CREATE TABLE IF NOT EXISTS ${T}entity (
41
+ id TEXT PRIMARY KEY,
42
+ name TEXT NOT NULL,
43
+ kind TEXT,
44
+ body TEXT,
45
+ created_at INTEGER NOT NULL
46
+ )`,
47
+ `CREATE TABLE IF NOT EXISTS ${T}edge (
48
+ id TEXT PRIMARY KEY,
49
+ src TEXT NOT NULL,
50
+ rel TEXT NOT NULL,
51
+ dst TEXT NOT NULL,
52
+ source TEXT,
53
+ created_at INTEGER NOT NULL
54
+ )`,
55
+ `CREATE INDEX IF NOT EXISTS ${T}edge_src ON ${T}edge(src)`,
56
+ `CREATE INDEX IF NOT EXISTS ${T}edge_dst ON ${T}edge(dst)`
57
+ ];
58
+ function buildInit() {
59
+ return SCHEMA_SQL.map((sql) => ({ sql, params: [] }));
60
+ }
61
+ var FTS_OPERATORS = /* @__PURE__ */ new Set(["and", "or", "not", "near"]);
62
+ function normalizeTags(tags) {
63
+ if (!tags) return null;
64
+ const arr = Array.isArray(tags) ? tags : String(tags).split(/[,\s]+/);
65
+ const norm = Array.from(
66
+ new Set(arr.map((t) => t.trim().toLowerCase()).filter(Boolean))
67
+ );
68
+ return norm.length ? norm.join(" ") : null;
69
+ }
70
+ function toFtsQuery(input, opts = {}) {
71
+ if (opts.mode === "raw") return input.trim() || null;
72
+ const tokens = (input.match(/[\p{L}\p{N}_]+/gu) ?? []).filter(
73
+ (t) => !FTS_OPERATORS.has(t.toLowerCase())
74
+ );
75
+ if (!tokens.length) return null;
76
+ const joiner = opts.operator === "and" ? " AND " : " OR ";
77
+ return tokens.map((t) => `"${t}"`).join(joiner);
78
+ }
79
+ function slugId(prefix, s) {
80
+ const base = s.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 96);
81
+ return prefix + (base || "x");
82
+ }
83
+ function entityId(name) {
84
+ return slugId("e_", name);
85
+ }
86
+ function resolveEntityRef(ref) {
87
+ return ref.startsWith("e_") ? ref : entityId(ref);
88
+ }
89
+ function edgeId(srcId, rel, dstId) {
90
+ return slugId("x_", `${srcId}|${rel}|${dstId}`);
91
+ }
92
+ var MEMORY_COLS = "id, kind, topic, body, tags, source, created_at AS createdAt, superseded_by AS supersededBy";
93
+ function buildRemember(input, now, id) {
94
+ return {
95
+ sql: `INSERT INTO ${T}memory (id, kind, topic, body, tags, source, created_at, superseded_by)
96
+ VALUES (?, ?, ?, ?, ?, ?, ?, NULL)`,
97
+ params: [
98
+ id,
99
+ input.kind ?? "fact",
100
+ input.topic ?? null,
101
+ input.body,
102
+ normalizeTags(input.tags),
103
+ input.source ?? null,
104
+ now
105
+ ]
106
+ };
107
+ }
108
+ function buildSupersede(oldId, newId) {
109
+ return {
110
+ sql: `UPDATE ${T}memory SET superseded_by = ? WHERE id = ? AND superseded_by IS NULL`,
111
+ params: [newId, oldId]
112
+ };
113
+ }
114
+ function buildForget(id) {
115
+ return { sql: `DELETE FROM ${T}memory WHERE id = ?`, params: [id] };
116
+ }
117
+ function buildGet(id) {
118
+ return {
119
+ sql: `SELECT ${MEMORY_COLS} FROM ${T}memory WHERE id = ?`,
120
+ params: [id]
121
+ };
122
+ }
123
+ function buildRecall(query, opts = {}) {
124
+ const match = toFtsQuery(query, { operator: opts.operator, mode: opts.mode });
125
+ if (!match) return null;
126
+ const where = [`${T}memory_fts MATCH ?`];
127
+ const params = [match];
128
+ if (!opts.includeSuperseded) where.push("m.superseded_by IS NULL");
129
+ if (opts.kind) {
130
+ where.push("m.kind = ?");
131
+ params.push(opts.kind);
132
+ }
133
+ if (opts.sinceMs != null) {
134
+ where.push("m.created_at >= ?");
135
+ params.push(opts.sinceMs);
136
+ }
137
+ params.push(opts.limit ?? 8);
138
+ return {
139
+ sql: `SELECT m.id, m.kind, m.topic, m.body, m.tags, m.source,
140
+ m.created_at AS createdAt, m.superseded_by AS supersededBy
141
+ FROM ${T}memory_fts
142
+ JOIN ${T}memory m ON m.rowid = ${T}memory_fts.rowid
143
+ WHERE ${where.join(" AND ")}
144
+ ORDER BY ${T}memory_fts.rank
145
+ LIMIT ?`,
146
+ params
147
+ };
148
+ }
149
+ function buildRecent(opts = {}) {
150
+ const where = [];
151
+ const params = [];
152
+ if (!opts.includeSuperseded) where.push("superseded_by IS NULL");
153
+ if (opts.kind) {
154
+ where.push("kind = ?");
155
+ params.push(opts.kind);
156
+ }
157
+ params.push(opts.limit ?? 20);
158
+ return {
159
+ sql: `SELECT ${MEMORY_COLS} FROM ${T}memory
160
+ ${where.length ? "WHERE " + where.join(" AND ") : ""}
161
+ ORDER BY created_at DESC
162
+ LIMIT ?`,
163
+ params
164
+ };
165
+ }
166
+ function buildByTag(tag, opts = {}) {
167
+ const t = tag.trim().toLowerCase();
168
+ const where = ["(' ' || COALESCE(tags, '') || ' ') LIKE ?"];
169
+ const params = [`% ${t} %`];
170
+ if (!opts.includeSuperseded) where.push("superseded_by IS NULL");
171
+ if (opts.kind) {
172
+ where.push("kind = ?");
173
+ params.push(opts.kind);
174
+ }
175
+ params.push(opts.limit ?? 20);
176
+ return {
177
+ sql: `SELECT ${MEMORY_COLS} FROM ${T}memory
178
+ WHERE ${where.join(" AND ")}
179
+ ORDER BY created_at DESC
180
+ LIMIT ?`,
181
+ params
182
+ };
183
+ }
184
+ function buildStats() {
185
+ return {
186
+ sql: `SELECT
187
+ (SELECT count(*) FROM ${T}memory WHERE superseded_by IS NULL) AS facts,
188
+ (SELECT count(*) FROM ${T}memory) AS facts_total,
189
+ (SELECT count(*) FROM ${T}entity) AS entities,
190
+ (SELECT count(*) FROM ${T}edge) AS edges`,
191
+ params: []
192
+ };
193
+ }
194
+ function buildUpsertEntity(e, now) {
195
+ const id = e.id ?? entityId(e.name);
196
+ return {
197
+ sql: `INSERT INTO ${T}entity (id, name, kind, body, created_at)
198
+ VALUES (?, ?, ?, ?, ?)
199
+ ON CONFLICT(id) DO UPDATE SET
200
+ name = excluded.name,
201
+ kind = COALESCE(excluded.kind, ${T}entity.kind),
202
+ body = COALESCE(excluded.body, ${T}entity.body)`,
203
+ params: [id, e.name, e.kind ?? null, e.body ?? null, now]
204
+ };
205
+ }
206
+ function buildUpsertEdge(e, now) {
207
+ const srcId = resolveEntityRef(e.src);
208
+ const dstId = resolveEntityRef(e.dst);
209
+ const id = edgeId(srcId, e.rel, dstId);
210
+ return {
211
+ sql: `INSERT INTO ${T}edge (id, src, rel, dst, source, created_at)
212
+ VALUES (?, ?, ?, ?, ?, ?)
213
+ ON CONFLICT(id) DO UPDATE SET
214
+ source = COALESCE(excluded.source, ${T}edge.source)`,
215
+ params: [id, srcId, e.rel, dstId, e.source ?? null, now]
216
+ };
217
+ }
218
+ function buildNeighborEntities(seedId, depth, limit) {
219
+ return {
220
+ sql: `WITH RECURSIVE reach(id, depth) AS (
221
+ SELECT ?, 0
222
+ UNION
223
+ SELECT CASE WHEN e.src = reach.id THEN e.dst ELSE e.src END,
224
+ reach.depth + 1
225
+ FROM reach
226
+ JOIN ${T}edge e ON (e.src = reach.id OR e.dst = reach.id)
227
+ WHERE reach.depth < ?
228
+ )
229
+ SELECT en.id, en.name, en.kind, en.body,
230
+ en.created_at AS createdAt, MIN(reach.depth) AS depth
231
+ FROM reach
232
+ JOIN ${T}entity en ON en.id = reach.id
233
+ WHERE reach.depth > 0 AND en.id <> ?
234
+ GROUP BY en.id
235
+ ORDER BY depth, en.name
236
+ LIMIT ?`,
237
+ // The seed reappears at depth >0 via a round-trip on undirected edges;
238
+ // exclude it explicitly so it isn't listed as its own neighbor.
239
+ params: [seedId, depth, seedId, limit]
240
+ };
241
+ }
242
+ function buildEdgesAmong(ids) {
243
+ if (!ids.length) {
244
+ return { sql: `SELECT id, src, rel, dst, source, created_at AS createdAt FROM ${T}edge WHERE 0`, params: [] };
245
+ }
246
+ const ph = ids.map(() => "?").join(", ");
247
+ return {
248
+ sql: `SELECT id, src, rel, dst, source, created_at AS createdAt
249
+ FROM ${T}edge
250
+ WHERE src IN (${ph}) AND dst IN (${ph})`,
251
+ params: [...ids, ...ids]
252
+ };
253
+ }
254
+ var EXTRACTION_SYSTEM_PROMPT = `You extract durable, shareable context from raw text for a team of AI agents that will read it later by keyword.
255
+
256
+ Return JSON: { "facts": [...], "entities": [...], "edges": [...] }.
257
+ - facts: atomic, self-contained statements worth remembering across sessions \u2014 decisions, conventions, constraints, identifiers, preferences. Each: { "body": string, "topic"?: string, "tags"?: string[] }. Prefer specific and stable over transient chatter.
258
+ - entities: named things \u2014 services, people, tables, repos, concepts. Each: { "name": string, "kind"?: string, "body"?: short description }.
259
+ - edges: relationships between entities, referencing entity names. Each: { "src": name, "rel": string, "dst": name }.
260
+
261
+ Be conservative: omit anything ephemeral or low-value. Use lowercase tags. If nothing is worth keeping, return empty arrays.`;
262
+ function buildExtractionMessages(raw, opts = {}) {
263
+ return [
264
+ { role: "system", content: EXTRACTION_SYSTEM_PROMPT },
265
+ {
266
+ role: "user",
267
+ content: (opts.hint ? `Context: ${opts.hint}
268
+
269
+ ` : "") + raw
270
+ }
271
+ ];
272
+ }
273
+ var EXTRACTION_JSON_SCHEMA = {
274
+ type: "object",
275
+ properties: {
276
+ facts: {
277
+ type: "array",
278
+ items: {
279
+ type: "object",
280
+ properties: {
281
+ body: { type: "string" },
282
+ topic: { type: "string" },
283
+ tags: { type: "array", items: { type: "string" } }
284
+ },
285
+ required: ["body"]
286
+ }
287
+ },
288
+ entities: {
289
+ type: "array",
290
+ items: {
291
+ type: "object",
292
+ properties: {
293
+ name: { type: "string" },
294
+ kind: { type: "string" },
295
+ body: { type: "string" }
296
+ },
297
+ required: ["name"]
298
+ }
299
+ },
300
+ edges: {
301
+ type: "array",
302
+ items: {
303
+ type: "object",
304
+ properties: {
305
+ src: { type: "string" },
306
+ rel: { type: "string" },
307
+ dst: { type: "string" }
308
+ },
309
+ required: ["src", "rel", "dst"]
310
+ }
311
+ }
312
+ }
313
+ };
314
+
315
+ export {
316
+ SCHEMA_VERSION,
317
+ TABLE_PREFIX,
318
+ SCHEMA_SQL,
319
+ buildInit,
320
+ normalizeTags,
321
+ toFtsQuery,
322
+ entityId,
323
+ buildRemember,
324
+ buildSupersede,
325
+ buildForget,
326
+ buildGet,
327
+ buildRecall,
328
+ buildRecent,
329
+ buildByTag,
330
+ buildStats,
331
+ buildUpsertEntity,
332
+ buildUpsertEdge,
333
+ buildNeighborEntities,
334
+ buildEdgesAmong,
335
+ EXTRACTION_SYSTEM_PROMPT,
336
+ buildExtractionMessages,
337
+ EXTRACTION_JSON_SCHEMA
338
+ };
339
+ //# sourceMappingURL=chunk-RMG66FDI.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core.ts"],"sourcesContent":["/**\n * @persql/context/core — zero-runtime-dependency engine.\n *\n * Schema DDL, SQL builders, and the extraction/compaction contracts shared by\n * the `@persql/context` SDK (client-side, over `@persql/sdk`) and the hosted\n * PerSQL Context worker (server-side, over `@persql/ai`). Keeping both sides on\n * the same builders means client-recall and server-recall can never drift.\n *\n * Retrieval is lexical: FTS5 with the porter stemmer, BM25-ranked. No vectors.\n */\n\nexport const SCHEMA_VERSION = 1;\nexport const TABLE_PREFIX = \"ctx_\";\nconst T = TABLE_PREFIX;\n\nexport type MemoryKind = \"fact\" | \"episode\" | \"artifact\";\n\nexport interface MemoryRow {\n id: string;\n kind: MemoryKind;\n topic: string | null;\n body: string;\n tags: string | null;\n source: string | null;\n createdAt: number;\n supersededBy: string | null;\n}\n\nexport interface Entity {\n id: string;\n name: string;\n kind: string | null;\n body: string | null;\n createdAt: number;\n}\n\nexport interface Edge {\n id: string;\n src: string;\n rel: string;\n dst: string;\n source: string | null;\n createdAt: number;\n}\n\nexport interface RememberInput {\n body: string;\n topic?: string;\n kind?: MemoryKind;\n tags?: string[] | string;\n source?: string;\n supersedes?: string | string[];\n id?: string;\n}\n\nexport interface EntityInput {\n name: string;\n kind?: string;\n body?: string;\n id?: string;\n}\n\nexport interface EdgeInput {\n src: string;\n rel: string;\n dst: string;\n source?: string;\n}\n\nexport interface RecallOptions {\n limit?: number;\n kind?: MemoryKind;\n operator?: \"or\" | \"and\";\n mode?: \"terms\" | \"raw\";\n sinceMs?: number;\n withinDays?: number;\n includeSuperseded?: boolean;\n}\n\nexport interface ListOptions {\n limit?: number;\n kind?: MemoryKind;\n includeSuperseded?: boolean;\n}\n\n/** The shape an extractor (LLM or the hosted worker) returns from raw text. */\nexport interface ExtractedContext {\n facts?: Array<{ body: string; topic?: string; tags?: string[]; kind?: MemoryKind }>;\n entities?: EntityInput[];\n edges?: EdgeInput[];\n}\n\nexport interface SqlStatement {\n sql: string;\n params: unknown[];\n}\n\n// ---------------------------------------------------------------------------\n// Schema\n// ---------------------------------------------------------------------------\n\nexport const SCHEMA_SQL: string[] = [\n `CREATE TABLE IF NOT EXISTS ${T}memory (\n id TEXT PRIMARY KEY,\n kind TEXT NOT NULL DEFAULT 'fact',\n topic TEXT,\n body TEXT NOT NULL,\n tags TEXT,\n source TEXT,\n created_at INTEGER NOT NULL,\n superseded_by TEXT\n )`,\n `CREATE INDEX IF NOT EXISTS ${T}memory_kind ON ${T}memory(kind)`,\n `CREATE INDEX IF NOT EXISTS ${T}memory_created ON ${T}memory(created_at)`,\n `CREATE INDEX IF NOT EXISTS ${T}memory_superseded ON ${T}memory(superseded_by)`,\n // External-content FTS index: body text is not duplicated, only indexed.\n // Porter stemmer so \"invoice\" recalls \"invoicing\" without embeddings.\n `CREATE VIRTUAL TABLE IF NOT EXISTS ${T}memory_fts USING fts5(\n topic, body, tags,\n content='${T}memory', content_rowid='rowid',\n tokenize='porter unicode61'\n )`,\n `CREATE TRIGGER IF NOT EXISTS ${T}memory_ai AFTER INSERT ON ${T}memory BEGIN\n INSERT INTO ${T}memory_fts(rowid, topic, body, tags)\n VALUES (new.rowid, new.topic, new.body, new.tags);\n END`,\n `CREATE TRIGGER IF NOT EXISTS ${T}memory_ad AFTER DELETE ON ${T}memory BEGIN\n INSERT INTO ${T}memory_fts(${T}memory_fts, rowid, topic, body, tags)\n VALUES ('delete', old.rowid, old.topic, old.body, old.tags);\n END`,\n `CREATE TRIGGER IF NOT EXISTS ${T}memory_au AFTER UPDATE ON ${T}memory BEGIN\n INSERT INTO ${T}memory_fts(${T}memory_fts, rowid, topic, body, tags)\n VALUES ('delete', old.rowid, old.topic, old.body, old.tags);\n INSERT INTO ${T}memory_fts(rowid, topic, body, tags)\n VALUES (new.rowid, new.topic, new.body, new.tags);\n END`,\n `CREATE TABLE IF NOT EXISTS ${T}entity (\n id TEXT PRIMARY KEY,\n name TEXT NOT NULL,\n kind TEXT,\n body TEXT,\n created_at INTEGER NOT NULL\n )`,\n `CREATE TABLE IF NOT EXISTS ${T}edge (\n id TEXT PRIMARY KEY,\n src TEXT NOT NULL,\n rel TEXT NOT NULL,\n dst TEXT NOT NULL,\n source TEXT,\n created_at INTEGER NOT NULL\n )`,\n `CREATE INDEX IF NOT EXISTS ${T}edge_src ON ${T}edge(src)`,\n `CREATE INDEX IF NOT EXISTS ${T}edge_dst ON ${T}edge(dst)`,\n];\n\nexport function buildInit(): SqlStatement[] {\n return SCHEMA_SQL.map((sql) => ({ sql, params: [] }));\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\nconst FTS_OPERATORS = new Set([\"and\", \"or\", \"not\", \"near\"]);\n\nexport function normalizeTags(tags?: string[] | string | null): string | null {\n if (!tags) return null;\n const arr = Array.isArray(tags) ? tags : String(tags).split(/[,\\s]+/);\n const norm = Array.from(\n new Set(arr.map((t) => t.trim().toLowerCase()).filter(Boolean))\n );\n return norm.length ? norm.join(\" \") : null;\n}\n\n/**\n * Turn arbitrary user text into a safe FTS5 MATCH expression. `terms` mode\n * (default) extracts word tokens, drops bare boolean operators, and ORs the\n * rest as quoted terms — so a caller can paste \"invoice OR billing\" or just\n * \"invoice billing\" and neither crashes the parser nor injects FTS syntax.\n * `raw` mode passes a hand-written FTS expression through untouched.\n */\nexport function toFtsQuery(\n input: string,\n opts: { operator?: \"or\" | \"and\"; mode?: \"terms\" | \"raw\" } = {}\n): string | null {\n if (opts.mode === \"raw\") return input.trim() || null;\n const tokens = (input.match(/[\\p{L}\\p{N}_]+/gu) ?? []).filter(\n (t) => !FTS_OPERATORS.has(t.toLowerCase())\n );\n if (!tokens.length) return null;\n const joiner = opts.operator === \"and\" ? \" AND \" : \" OR \";\n return tokens.map((t) => `\"${t}\"`).join(joiner);\n}\n\nfunction slugId(prefix: string, s: string): string {\n const base = s\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, \"-\")\n .replace(/^-+|-+$/g, \"\")\n .slice(0, 96);\n return prefix + (base || \"x\");\n}\n\n/** Deterministic id for an entity, keyed on its name (case-insensitive). */\nexport function entityId(name: string): string {\n return slugId(\"e_\", name);\n}\n\nfunction resolveEntityRef(ref: string): string {\n return ref.startsWith(\"e_\") ? ref : entityId(ref);\n}\n\nfunction edgeId(srcId: string, rel: string, dstId: string): string {\n return slugId(\"x_\", `${srcId}|${rel}|${dstId}`);\n}\n\nconst MEMORY_COLS =\n \"id, kind, topic, body, tags, source, created_at AS createdAt, superseded_by AS supersededBy\";\n\n// ---------------------------------------------------------------------------\n// Memory builders\n// ---------------------------------------------------------------------------\n\nexport function buildRemember(\n input: RememberInput,\n now: number,\n id: string\n): SqlStatement {\n return {\n sql: `INSERT INTO ${T}memory (id, kind, topic, body, tags, source, created_at, superseded_by)\n VALUES (?, ?, ?, ?, ?, ?, ?, NULL)`,\n params: [\n id,\n input.kind ?? \"fact\",\n input.topic ?? null,\n input.body,\n normalizeTags(input.tags),\n input.source ?? null,\n now,\n ],\n };\n}\n\nexport function buildSupersede(oldId: string, newId: string): SqlStatement {\n return {\n sql: `UPDATE ${T}memory SET superseded_by = ? WHERE id = ? AND superseded_by IS NULL`,\n params: [newId, oldId],\n };\n}\n\nexport function buildForget(id: string): SqlStatement {\n return { sql: `DELETE FROM ${T}memory WHERE id = ?`, params: [id] };\n}\n\nexport function buildGet(id: string): SqlStatement {\n return {\n sql: `SELECT ${MEMORY_COLS} FROM ${T}memory WHERE id = ?`,\n params: [id],\n };\n}\n\nexport function buildRecall(\n query: string,\n opts: RecallOptions = {}\n): SqlStatement | null {\n const match = toFtsQuery(query, { operator: opts.operator, mode: opts.mode });\n if (!match) return null;\n const where: string[] = [`${T}memory_fts MATCH ?`];\n const params: unknown[] = [match];\n if (!opts.includeSuperseded) where.push(\"m.superseded_by IS NULL\");\n if (opts.kind) {\n where.push(\"m.kind = ?\");\n params.push(opts.kind);\n }\n if (opts.sinceMs != null) {\n where.push(\"m.created_at >= ?\");\n params.push(opts.sinceMs);\n }\n params.push(opts.limit ?? 8);\n return {\n sql: `SELECT m.id, m.kind, m.topic, m.body, m.tags, m.source,\n m.created_at AS createdAt, m.superseded_by AS supersededBy\n FROM ${T}memory_fts\n JOIN ${T}memory m ON m.rowid = ${T}memory_fts.rowid\n WHERE ${where.join(\" AND \")}\n ORDER BY ${T}memory_fts.rank\n LIMIT ?`,\n params,\n };\n}\n\nexport function buildRecent(opts: ListOptions = {}): SqlStatement {\n const where: string[] = [];\n const params: unknown[] = [];\n if (!opts.includeSuperseded) where.push(\"superseded_by IS NULL\");\n if (opts.kind) {\n where.push(\"kind = ?\");\n params.push(opts.kind);\n }\n params.push(opts.limit ?? 20);\n return {\n sql: `SELECT ${MEMORY_COLS} FROM ${T}memory\n ${where.length ? \"WHERE \" + where.join(\" AND \") : \"\"}\n ORDER BY created_at DESC\n LIMIT ?`,\n params,\n };\n}\n\nexport function buildByTag(tag: string, opts: ListOptions = {}): SqlStatement {\n const t = tag.trim().toLowerCase();\n const where: string[] = [\"(' ' || COALESCE(tags, '') || ' ') LIKE ?\"];\n const params: unknown[] = [`% ${t} %`];\n if (!opts.includeSuperseded) where.push(\"superseded_by IS NULL\");\n if (opts.kind) {\n where.push(\"kind = ?\");\n params.push(opts.kind);\n }\n params.push(opts.limit ?? 20);\n return {\n sql: `SELECT ${MEMORY_COLS} FROM ${T}memory\n WHERE ${where.join(\" AND \")}\n ORDER BY created_at DESC\n LIMIT ?`,\n params,\n };\n}\n\nexport function buildStats(): SqlStatement {\n return {\n sql: `SELECT\n (SELECT count(*) FROM ${T}memory WHERE superseded_by IS NULL) AS facts,\n (SELECT count(*) FROM ${T}memory) AS facts_total,\n (SELECT count(*) FROM ${T}entity) AS entities,\n (SELECT count(*) FROM ${T}edge) AS edges`,\n params: [],\n };\n}\n\n// ---------------------------------------------------------------------------\n// Graph builders\n// ---------------------------------------------------------------------------\n\nexport function buildUpsertEntity(e: EntityInput, now: number): SqlStatement {\n const id = e.id ?? entityId(e.name);\n return {\n sql: `INSERT INTO ${T}entity (id, name, kind, body, created_at)\n VALUES (?, ?, ?, ?, ?)\n ON CONFLICT(id) DO UPDATE SET\n name = excluded.name,\n kind = COALESCE(excluded.kind, ${T}entity.kind),\n body = COALESCE(excluded.body, ${T}entity.body)`,\n params: [id, e.name, e.kind ?? null, e.body ?? null, now],\n };\n}\n\nexport function buildUpsertEdge(e: EdgeInput, now: number): SqlStatement {\n const srcId = resolveEntityRef(e.src);\n const dstId = resolveEntityRef(e.dst);\n const id = edgeId(srcId, e.rel, dstId);\n return {\n sql: `INSERT INTO ${T}edge (id, src, rel, dst, source, created_at)\n VALUES (?, ?, ?, ?, ?, ?)\n ON CONFLICT(id) DO UPDATE SET\n source = COALESCE(excluded.source, ${T}edge.source)`,\n params: [id, srcId, e.rel, dstId, e.source ?? null, now],\n };\n}\n\n/** Entities reachable from a seed within `depth` hops (seed excluded). */\nexport function buildNeighborEntities(\n seedId: string,\n depth: number,\n limit: number\n): SqlStatement {\n return {\n sql: `WITH RECURSIVE reach(id, depth) AS (\n SELECT ?, 0\n UNION\n SELECT CASE WHEN e.src = reach.id THEN e.dst ELSE e.src END,\n reach.depth + 1\n FROM reach\n JOIN ${T}edge e ON (e.src = reach.id OR e.dst = reach.id)\n WHERE reach.depth < ?\n )\n SELECT en.id, en.name, en.kind, en.body,\n en.created_at AS createdAt, MIN(reach.depth) AS depth\n FROM reach\n JOIN ${T}entity en ON en.id = reach.id\n WHERE reach.depth > 0 AND en.id <> ?\n GROUP BY en.id\n ORDER BY depth, en.name\n LIMIT ?`,\n // The seed reappears at depth >0 via a round-trip on undirected edges;\n // exclude it explicitly so it isn't listed as its own neighbor.\n params: [seedId, depth, seedId, limit],\n };\n}\n\nexport function buildEdgesAmong(ids: string[]): SqlStatement {\n if (!ids.length) {\n return { sql: `SELECT id, src, rel, dst, source, created_at AS createdAt FROM ${T}edge WHERE 0`, params: [] };\n }\n const ph = ids.map(() => \"?\").join(\", \");\n return {\n sql: `SELECT id, src, rel, dst, source, created_at AS createdAt\n FROM ${T}edge\n WHERE src IN (${ph}) AND dst IN (${ph})`,\n params: [...ids, ...ids],\n };\n}\n\n// ---------------------------------------------------------------------------\n// Extraction / compaction contracts (used by the hosted worker + documented\n// for bring-your-own-LLM callers; kept here so the prompt is versioned with\n// the schema it has to populate).\n// ---------------------------------------------------------------------------\n\nexport const EXTRACTION_SYSTEM_PROMPT = `You extract durable, shareable context from raw text for a team of AI agents that will read it later by keyword.\n\nReturn JSON: { \"facts\": [...], \"entities\": [...], \"edges\": [...] }.\n- facts: atomic, self-contained statements worth remembering across sessions — decisions, conventions, constraints, identifiers, preferences. Each: { \"body\": string, \"topic\"?: string, \"tags\"?: string[] }. Prefer specific and stable over transient chatter.\n- entities: named things — services, people, tables, repos, concepts. Each: { \"name\": string, \"kind\"?: string, \"body\"?: short description }.\n- edges: relationships between entities, referencing entity names. Each: { \"src\": name, \"rel\": string, \"dst\": name }.\n\nBe conservative: omit anything ephemeral or low-value. Use lowercase tags. If nothing is worth keeping, return empty arrays.`;\n\nexport function buildExtractionMessages(\n raw: string,\n opts: { hint?: string } = {}\n): Array<{ role: \"system\" | \"user\"; content: string }> {\n return [\n { role: \"system\", content: EXTRACTION_SYSTEM_PROMPT },\n {\n role: \"user\",\n content: (opts.hint ? `Context: ${opts.hint}\\n\\n` : \"\") + raw,\n },\n ];\n}\n\nexport const EXTRACTION_JSON_SCHEMA = {\n type: \"object\",\n properties: {\n facts: {\n type: \"array\",\n items: {\n type: \"object\",\n properties: {\n body: { type: \"string\" },\n topic: { type: \"string\" },\n tags: { type: \"array\", items: { type: \"string\" } },\n },\n required: [\"body\"],\n },\n },\n entities: {\n type: \"array\",\n items: {\n type: \"object\",\n properties: {\n name: { type: \"string\" },\n kind: { type: \"string\" },\n body: { type: \"string\" },\n },\n required: [\"name\"],\n },\n },\n edges: {\n type: \"array\",\n items: {\n type: \"object\",\n properties: {\n src: { type: \"string\" },\n rel: { type: \"string\" },\n dst: { type: \"string\" },\n },\n required: [\"src\", \"rel\", \"dst\"],\n },\n },\n },\n} as const;\n"],"mappings":";AAWO,IAAM,iBA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