@gilangjavier/chrona 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/LICENSE +21 -0
- package/README.md +590 -0
- package/dist/chunk-PPAKIDJE.js +391 -0
- package/dist/chunk-PPAKIDJE.js.map +1 -0
- package/dist/cli.cjs +555 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +160 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.cjs +427 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +92 -0
- package/dist/index.d.ts +92 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/package.json +67 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
ChromaStore,
|
|
4
|
+
parseCsv,
|
|
5
|
+
parseJsonObject,
|
|
6
|
+
parseMemoryScope,
|
|
7
|
+
parseMemoryType,
|
|
8
|
+
parseSourceKind,
|
|
9
|
+
toIsoString
|
|
10
|
+
} from "./chunk-PPAKIDJE.js";
|
|
11
|
+
|
|
12
|
+
// src/cli.ts
|
|
13
|
+
import { Command } from "commander";
|
|
14
|
+
import { readFileSync, writeFileSync } from "fs";
|
|
15
|
+
import { resolve } from "path";
|
|
16
|
+
function openStore(options) {
|
|
17
|
+
return new ChromaStore(resolve(options.db ?? process.env.CHRONA_DB ?? ".chrona/chrona.db"));
|
|
18
|
+
}
|
|
19
|
+
function emit(value, asJson) {
|
|
20
|
+
if (asJson) {
|
|
21
|
+
console.log(JSON.stringify(value, null, 2));
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (typeof value === "string") {
|
|
25
|
+
console.log(value);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
console.log(JSON.stringify(value, null, 2));
|
|
29
|
+
}
|
|
30
|
+
function parseScopes(value) {
|
|
31
|
+
const scopes = parseCsv(value).map(parseMemoryScope);
|
|
32
|
+
return scopes.length ? scopes : void 0;
|
|
33
|
+
}
|
|
34
|
+
function parseTypes(value) {
|
|
35
|
+
const types = parseCsv(value).map(parseMemoryType);
|
|
36
|
+
return types.length ? types : void 0;
|
|
37
|
+
}
|
|
38
|
+
function parseTags(value) {
|
|
39
|
+
const tags = parseCsv(value);
|
|
40
|
+
return tags.length ? tags : void 0;
|
|
41
|
+
}
|
|
42
|
+
var program = new Command();
|
|
43
|
+
program.name("chrona").description("Time-aware local memory store for agents").version("0.1.0").option("--db <path>", "Path to the SQLite database").option("--json", "Emit machine-readable JSON");
|
|
44
|
+
program.command("init").description("Create or open the memory database").action(() => {
|
|
45
|
+
const options = program.opts();
|
|
46
|
+
const store = openStore(options);
|
|
47
|
+
store.init();
|
|
48
|
+
emit({ ok: true, db: store.path }, options.json);
|
|
49
|
+
store.close();
|
|
50
|
+
});
|
|
51
|
+
program.command("add").description("Add a memory entry").requiredOption("--type <type>").requiredOption("--text <text>").requiredOption("--source-kind <kind>").requiredOption("--source-value <value>").requiredOption("--confidence <number>").requiredOption("--scope <scope>").option("--id <id>").option("--created-at <iso>").option("--tags <items>", "Comma-separated tags").option("--expires-at <iso>").option("--links <items>", "Comma-separated links").option("--metadata <json>", "Metadata JSON object").action((commandOptions) => {
|
|
52
|
+
const options = program.opts();
|
|
53
|
+
const store = openStore(options);
|
|
54
|
+
const entry = store.add({
|
|
55
|
+
id: commandOptions.id,
|
|
56
|
+
type: parseMemoryType(commandOptions.type),
|
|
57
|
+
text: commandOptions.text,
|
|
58
|
+
createdAt: commandOptions.createdAt,
|
|
59
|
+
source: {
|
|
60
|
+
kind: parseSourceKind(commandOptions.sourceKind),
|
|
61
|
+
value: commandOptions.sourceValue
|
|
62
|
+
},
|
|
63
|
+
confidence: Number(commandOptions.confidence),
|
|
64
|
+
scope: parseMemoryScope(commandOptions.scope),
|
|
65
|
+
tags: parseCsv(commandOptions.tags),
|
|
66
|
+
expiresAt: commandOptions.expiresAt,
|
|
67
|
+
links: parseCsv(commandOptions.links),
|
|
68
|
+
metadata: parseJsonObject(commandOptions.metadata)
|
|
69
|
+
});
|
|
70
|
+
emit(entry, true);
|
|
71
|
+
store.close();
|
|
72
|
+
});
|
|
73
|
+
program.command("search").description("Search memory entries by keyword").argument("<query>").option("--scopes <items>", "Comma-separated scopes").option("--types <items>", "Comma-separated types").option("--tags <items>", "Comma-separated tags").option("--source-kind <kind>").option("--source-value <value>").option("--before <iso>").option("--after <iso>").option("--include-expired", "Include expired entries").option("--limit <number>", "Maximum result count", "50").action((query, commandOptions) => {
|
|
74
|
+
const options = program.opts();
|
|
75
|
+
const store = openStore(options);
|
|
76
|
+
const result = store.search({
|
|
77
|
+
query,
|
|
78
|
+
scopes: parseScopes(commandOptions.scopes),
|
|
79
|
+
types: parseTypes(commandOptions.types),
|
|
80
|
+
tags: parseTags(commandOptions.tags),
|
|
81
|
+
sourceKind: commandOptions.sourceKind ? parseSourceKind(commandOptions.sourceKind) : void 0,
|
|
82
|
+
sourceValue: commandOptions.sourceValue,
|
|
83
|
+
before: commandOptions.before,
|
|
84
|
+
after: commandOptions.after,
|
|
85
|
+
includeExpired: Boolean(commandOptions.includeExpired),
|
|
86
|
+
limit: Number(commandOptions.limit)
|
|
87
|
+
});
|
|
88
|
+
emit(result, true);
|
|
89
|
+
store.close();
|
|
90
|
+
});
|
|
91
|
+
program.command("timeline").description("View time-ordered memory entries").option("--scopes <items>", "Comma-separated scopes").option("--types <items>", "Comma-separated types").option("--tags <items>", "Comma-separated tags").option("--source-kind <kind>").option("--source-value <value>").option("--before <iso>").option("--after <iso>").option("--include-expired", "Include expired entries").option("--order <direction>", "asc or desc", "asc").option("--limit <number>", "Maximum result count", "50").action((commandOptions) => {
|
|
92
|
+
const options = program.opts();
|
|
93
|
+
const store = openStore(options);
|
|
94
|
+
const result = store.timeline({
|
|
95
|
+
scopes: parseScopes(commandOptions.scopes),
|
|
96
|
+
types: parseTypes(commandOptions.types),
|
|
97
|
+
tags: parseTags(commandOptions.tags),
|
|
98
|
+
sourceKind: commandOptions.sourceKind ? parseSourceKind(commandOptions.sourceKind) : void 0,
|
|
99
|
+
sourceValue: commandOptions.sourceValue,
|
|
100
|
+
before: commandOptions.before,
|
|
101
|
+
after: commandOptions.after,
|
|
102
|
+
includeExpired: Boolean(commandOptions.includeExpired),
|
|
103
|
+
order: commandOptions.order === "desc" ? "desc" : "asc",
|
|
104
|
+
limit: Number(commandOptions.limit)
|
|
105
|
+
});
|
|
106
|
+
emit(result, true);
|
|
107
|
+
store.close();
|
|
108
|
+
});
|
|
109
|
+
program.command("get").description("Get a memory entry by id").argument("<id>").action((id) => {
|
|
110
|
+
const options = program.opts();
|
|
111
|
+
const store = openStore(options);
|
|
112
|
+
const result = store.get(id);
|
|
113
|
+
emit(result, true);
|
|
114
|
+
store.close();
|
|
115
|
+
});
|
|
116
|
+
program.command("export").description("Export entries as JSONL").option("--output <path>").option("--scopes <items>", "Comma-separated scopes").option("--types <items>", "Comma-separated types").option("--tags <items>", "Comma-separated tags").option("--source-kind <kind>").option("--source-value <value>").option("--before <iso>").option("--after <iso>").option("--include-expired", "Include expired entries").option("--order <direction>", "asc or desc", "asc").option("--limit <number>", "Maximum result count", "1000").action((commandOptions) => {
|
|
117
|
+
const options = program.opts();
|
|
118
|
+
const store = openStore(options);
|
|
119
|
+
const jsonl = store.exportJsonl({
|
|
120
|
+
scopes: parseScopes(commandOptions.scopes),
|
|
121
|
+
types: parseTypes(commandOptions.types),
|
|
122
|
+
tags: parseTags(commandOptions.tags),
|
|
123
|
+
sourceKind: commandOptions.sourceKind ? parseSourceKind(commandOptions.sourceKind) : void 0,
|
|
124
|
+
sourceValue: commandOptions.sourceValue,
|
|
125
|
+
before: commandOptions.before,
|
|
126
|
+
after: commandOptions.after,
|
|
127
|
+
includeExpired: Boolean(commandOptions.includeExpired),
|
|
128
|
+
order: commandOptions.order === "desc" ? "desc" : "asc",
|
|
129
|
+
limit: Number(commandOptions.limit)
|
|
130
|
+
});
|
|
131
|
+
if (commandOptions.output) {
|
|
132
|
+
writeFileSync(resolve(commandOptions.output), jsonl ? `${jsonl}
|
|
133
|
+
` : "");
|
|
134
|
+
emit({ ok: true, output: resolve(commandOptions.output) }, options.json);
|
|
135
|
+
} else {
|
|
136
|
+
emit(jsonl, false);
|
|
137
|
+
}
|
|
138
|
+
store.close();
|
|
139
|
+
});
|
|
140
|
+
program.command("import").description("Import entries from JSONL").argument("[input]", "Path to JSONL file, or - for stdin", "-").action((input) => {
|
|
141
|
+
const options = program.opts();
|
|
142
|
+
const store = openStore(options);
|
|
143
|
+
const jsonl = input === "-" ? readFileSync(0, "utf8") : readFileSync(resolve(input), "utf8");
|
|
144
|
+
const result = store.importJsonl(jsonl);
|
|
145
|
+
emit(result, true);
|
|
146
|
+
store.close();
|
|
147
|
+
});
|
|
148
|
+
program.command("gc").description("Delete expired entries").option("--now <iso>", "Override current time for deterministic runs").action((commandOptions) => {
|
|
149
|
+
const options = program.opts();
|
|
150
|
+
const store = openStore(options);
|
|
151
|
+
const result = store.gc(commandOptions.now ? toIsoString(commandOptions.now) : /* @__PURE__ */ new Date());
|
|
152
|
+
emit(result, true);
|
|
153
|
+
store.close();
|
|
154
|
+
});
|
|
155
|
+
program.parseAsync(process.argv).catch((error) => {
|
|
156
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
157
|
+
console.error(message);
|
|
158
|
+
process.exitCode = 1;
|
|
159
|
+
});
|
|
160
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { Command } from \"commander\";\nimport { readFileSync, writeFileSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport { ChromaStore } from \"./store.js\";\nimport type { MemoryScope, MemoryType, SourceKind } from \"./types.js\";\nimport { parseCsv, parseJsonObject, toIsoString } from \"./utils.js\";\nimport { parseMemoryScope, parseMemoryType, parseSourceKind } from \"./validate.js\";\n\ninterface CommonOptions {\n db?: string;\n json?: boolean;\n}\n\nfunction openStore(options: CommonOptions): ChromaStore {\n return new ChromaStore(resolve(options.db ?? process.env.CHRONA_DB ?? \".chrona/chrona.db\"));\n}\n\nfunction emit(value: unknown, asJson?: boolean): void {\n if (asJson) {\n console.log(JSON.stringify(value, null, 2));\n return;\n }\n\n if (typeof value === \"string\") {\n console.log(value);\n return;\n }\n\n console.log(JSON.stringify(value, null, 2));\n}\n\nfunction parseScopes(value?: string): MemoryScope[] | undefined {\n const scopes = parseCsv(value).map(parseMemoryScope);\n return scopes.length ? scopes : undefined;\n}\n\nfunction parseTypes(value?: string): MemoryType[] | undefined {\n const types = parseCsv(value).map(parseMemoryType);\n return types.length ? types : undefined;\n}\n\nfunction parseTags(value?: string): string[] | undefined {\n const tags = parseCsv(value);\n return tags.length ? tags : undefined;\n}\n\nconst program = new Command();\n\nprogram\n .name(\"chrona\")\n .description(\"Time-aware local memory store for agents\")\n .version(\"0.1.0\")\n .option(\"--db <path>\", \"Path to the SQLite database\")\n .option(\"--json\", \"Emit machine-readable JSON\");\n\nprogram\n .command(\"init\")\n .description(\"Create or open the memory database\")\n .action(() => {\n const options = program.opts<CommonOptions>();\n const store = openStore(options);\n store.init();\n emit({ ok: true, db: store.path }, options.json);\n store.close();\n });\n\nprogram\n .command(\"add\")\n .description(\"Add a memory entry\")\n .requiredOption(\"--type <type>\")\n .requiredOption(\"--text <text>\")\n .requiredOption(\"--source-kind <kind>\")\n .requiredOption(\"--source-value <value>\")\n .requiredOption(\"--confidence <number>\")\n .requiredOption(\"--scope <scope>\")\n .option(\"--id <id>\")\n .option(\"--created-at <iso>\")\n .option(\"--tags <items>\", \"Comma-separated tags\")\n .option(\"--expires-at <iso>\")\n .option(\"--links <items>\", \"Comma-separated links\")\n .option(\"--metadata <json>\", \"Metadata JSON object\")\n .action((commandOptions) => {\n const options = program.opts<CommonOptions>();\n const store = openStore(options);\n const entry = store.add({\n id: commandOptions.id,\n type: parseMemoryType(commandOptions.type),\n text: commandOptions.text,\n createdAt: commandOptions.createdAt,\n source: {\n kind: parseSourceKind(commandOptions.sourceKind as SourceKind),\n value: commandOptions.sourceValue\n },\n confidence: Number(commandOptions.confidence),\n scope: parseMemoryScope(commandOptions.scope),\n tags: parseCsv(commandOptions.tags),\n expiresAt: commandOptions.expiresAt,\n links: parseCsv(commandOptions.links),\n metadata: parseJsonObject(commandOptions.metadata)\n });\n emit(entry, true);\n store.close();\n });\n\nprogram\n .command(\"search\")\n .description(\"Search memory entries by keyword\")\n .argument(\"<query>\")\n .option(\"--scopes <items>\", \"Comma-separated scopes\")\n .option(\"--types <items>\", \"Comma-separated types\")\n .option(\"--tags <items>\", \"Comma-separated tags\")\n .option(\"--source-kind <kind>\")\n .option(\"--source-value <value>\")\n .option(\"--before <iso>\")\n .option(\"--after <iso>\")\n .option(\"--include-expired\", \"Include expired entries\")\n .option(\"--limit <number>\", \"Maximum result count\", \"50\")\n .action((query, commandOptions) => {\n const options = program.opts<CommonOptions>();\n const store = openStore(options);\n const result = store.search({\n query,\n scopes: parseScopes(commandOptions.scopes),\n types: parseTypes(commandOptions.types),\n tags: parseTags(commandOptions.tags),\n sourceKind: commandOptions.sourceKind ? parseSourceKind(commandOptions.sourceKind as SourceKind) : undefined,\n sourceValue: commandOptions.sourceValue,\n before: commandOptions.before,\n after: commandOptions.after,\n includeExpired: Boolean(commandOptions.includeExpired),\n limit: Number(commandOptions.limit)\n });\n emit(result, true);\n store.close();\n });\n\nprogram\n .command(\"timeline\")\n .description(\"View time-ordered memory entries\")\n .option(\"--scopes <items>\", \"Comma-separated scopes\")\n .option(\"--types <items>\", \"Comma-separated types\")\n .option(\"--tags <items>\", \"Comma-separated tags\")\n .option(\"--source-kind <kind>\")\n .option(\"--source-value <value>\")\n .option(\"--before <iso>\")\n .option(\"--after <iso>\")\n .option(\"--include-expired\", \"Include expired entries\")\n .option(\"--order <direction>\", \"asc or desc\", \"asc\")\n .option(\"--limit <number>\", \"Maximum result count\", \"50\")\n .action((commandOptions) => {\n const options = program.opts<CommonOptions>();\n const store = openStore(options);\n const result = store.timeline({\n scopes: parseScopes(commandOptions.scopes),\n types: parseTypes(commandOptions.types),\n tags: parseTags(commandOptions.tags),\n sourceKind: commandOptions.sourceKind ? parseSourceKind(commandOptions.sourceKind as SourceKind) : undefined,\n sourceValue: commandOptions.sourceValue,\n before: commandOptions.before,\n after: commandOptions.after,\n includeExpired: Boolean(commandOptions.includeExpired),\n order: commandOptions.order === \"desc\" ? \"desc\" : \"asc\",\n limit: Number(commandOptions.limit)\n });\n emit(result, true);\n store.close();\n });\n\nprogram\n .command(\"get\")\n .description(\"Get a memory entry by id\")\n .argument(\"<id>\")\n .action((id) => {\n const options = program.opts<CommonOptions>();\n const store = openStore(options);\n const result = store.get(id);\n emit(result, true);\n store.close();\n });\n\nprogram\n .command(\"export\")\n .description(\"Export entries as JSONL\")\n .option(\"--output <path>\")\n .option(\"--scopes <items>\", \"Comma-separated scopes\")\n .option(\"--types <items>\", \"Comma-separated types\")\n .option(\"--tags <items>\", \"Comma-separated tags\")\n .option(\"--source-kind <kind>\")\n .option(\"--source-value <value>\")\n .option(\"--before <iso>\")\n .option(\"--after <iso>\")\n .option(\"--include-expired\", \"Include expired entries\")\n .option(\"--order <direction>\", \"asc or desc\", \"asc\")\n .option(\"--limit <number>\", \"Maximum result count\", \"1000\")\n .action((commandOptions) => {\n const options = program.opts<CommonOptions>();\n const store = openStore(options);\n const jsonl = store.exportJsonl({\n scopes: parseScopes(commandOptions.scopes),\n types: parseTypes(commandOptions.types),\n tags: parseTags(commandOptions.tags),\n sourceKind: commandOptions.sourceKind ? parseSourceKind(commandOptions.sourceKind as SourceKind) : undefined,\n sourceValue: commandOptions.sourceValue,\n before: commandOptions.before,\n after: commandOptions.after,\n includeExpired: Boolean(commandOptions.includeExpired),\n order: commandOptions.order === \"desc\" ? \"desc\" : \"asc\",\n limit: Number(commandOptions.limit)\n });\n\n if (commandOptions.output) {\n writeFileSync(resolve(commandOptions.output), jsonl ? `${jsonl}\\n` : \"\");\n emit({ ok: true, output: resolve(commandOptions.output) }, options.json);\n } else {\n emit(jsonl, false);\n }\n\n store.close();\n });\n\nprogram\n .command(\"import\")\n .description(\"Import entries from JSONL\")\n .argument(\"[input]\", \"Path to JSONL file, or - for stdin\", \"-\")\n .action((input) => {\n const options = program.opts<CommonOptions>();\n const store = openStore(options);\n const jsonl = input === \"-\" ? readFileSync(0, \"utf8\") : readFileSync(resolve(input), \"utf8\");\n const result = store.importJsonl(jsonl);\n emit(result, true);\n store.close();\n });\n\nprogram\n .command(\"gc\")\n .description(\"Delete expired entries\")\n .option(\"--now <iso>\", \"Override current time for deterministic runs\")\n .action((commandOptions) => {\n const options = program.opts<CommonOptions>();\n const store = openStore(options);\n const result = store.gc(commandOptions.now ? toIsoString(commandOptions.now) : new Date());\n emit(result, true);\n store.close();\n });\n\nprogram.parseAsync(process.argv).catch((error: unknown) => {\n const message = error instanceof Error ? error.message : String(error);\n console.error(message);\n process.exitCode = 1;\n});\n"],"mappings":";;;;;;;;;;;;AACA,SAAS,eAAe;AACxB,SAAS,cAAc,qBAAqB;AAC5C,SAAS,eAAe;AAWxB,SAAS,UAAU,SAAqC;AACtD,SAAO,IAAI,YAAY,QAAQ,QAAQ,MAAM,QAAQ,IAAI,aAAa,mBAAmB,CAAC;AAC5F;AAEA,SAAS,KAAK,OAAgB,QAAwB;AACpD,MAAI,QAAQ;AACV,YAAQ,IAAI,KAAK,UAAU,OAAO,MAAM,CAAC,CAAC;AAC1C;AAAA,EACF;AAEA,MAAI,OAAO,UAAU,UAAU;AAC7B,YAAQ,IAAI,KAAK;AACjB;AAAA,EACF;AAEA,UAAQ,IAAI,KAAK,UAAU,OAAO,MAAM,CAAC,CAAC;AAC5C;AAEA,SAAS,YAAY,OAA2C;AAC9D,QAAM,SAAS,SAAS,KAAK,EAAE,IAAI,gBAAgB;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AAM;AACd,CAAC;AAEH,QACG,QAAQ,IAAI,EACZ,YAAY,wBAAwB,EACpC,OAAO,eAAe,8CAA8C,EACpE,OAAO,CAAC,mBAAmB;AAC1B,QAAM,UAAU,QAAQ,KAAoB;AAC5C,QAAM,QAAQ,UAAU,OAAO;AAC/B,QAAM,SAAS,MAAM,GAAG,eAAe,MAAM,YAAY,eAAe,GAAG,IAAI,oBAAI,KAAK,CAAC;AACzF,OAAK,QAAQ,IAAI;AACjB,QAAM,MAAM;AACd,CAAC;AAEH,QAAQ,WAAW,QAAQ,IAAI,EAAE,MAAM,CAAC,UAAmB;AACzD,QAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AACrE,UAAQ,MAAM,OAAO;AACrB,UAAQ,WAAW;AACrB,CAAC;","names":[]}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
ChromaStore: () => ChromaStore,
|
|
34
|
+
memoryScopes: () => memoryScopes,
|
|
35
|
+
memoryTypes: () => memoryTypes,
|
|
36
|
+
normalizeEntry: () => normalizeEntry,
|
|
37
|
+
parseMemoryScope: () => parseMemoryScope,
|
|
38
|
+
parseMemoryType: () => parseMemoryType,
|
|
39
|
+
parseSourceKind: () => parseSourceKind,
|
|
40
|
+
sourceKinds: () => sourceKinds
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(index_exports);
|
|
43
|
+
|
|
44
|
+
// src/types.ts
|
|
45
|
+
var memoryTypes = ["decision", "preference", "fact", "incident", "constraint"];
|
|
46
|
+
var memoryScopes = ["user", "project", "org", "shared"];
|
|
47
|
+
var sourceKinds = ["tool", "session", "repo"];
|
|
48
|
+
|
|
49
|
+
// src/store.ts
|
|
50
|
+
var import_better_sqlite3 = __toESM(require("better-sqlite3"), 1);
|
|
51
|
+
var import_node_fs = require("fs");
|
|
52
|
+
var import_node_path = require("path");
|
|
53
|
+
|
|
54
|
+
// src/utils.ts
|
|
55
|
+
var import_node_crypto = require("crypto");
|
|
56
|
+
function toIsoString(value) {
|
|
57
|
+
const date = value instanceof Date ? value : value ? new Date(value) : /* @__PURE__ */ new Date();
|
|
58
|
+
const iso = date.toISOString();
|
|
59
|
+
if (Number.isNaN(date.getTime())) {
|
|
60
|
+
throw new Error(`Invalid date: ${String(value)}`);
|
|
61
|
+
}
|
|
62
|
+
return iso;
|
|
63
|
+
}
|
|
64
|
+
function uniqueSorted(values) {
|
|
65
|
+
return [...new Set((values ?? []).map((value) => value.trim()).filter(Boolean))].sort((a, b) => a.localeCompare(b));
|
|
66
|
+
}
|
|
67
|
+
function normalizeConfidence(value) {
|
|
68
|
+
if (!Number.isFinite(value) || value < 0 || value > 1) {
|
|
69
|
+
throw new Error("confidence must be between 0 and 1");
|
|
70
|
+
}
|
|
71
|
+
return Number(value.toFixed(6));
|
|
72
|
+
}
|
|
73
|
+
function parseJsonObject(value) {
|
|
74
|
+
if (value === void 0 || value === null) {
|
|
75
|
+
return void 0;
|
|
76
|
+
}
|
|
77
|
+
if (typeof value === "object" && !Array.isArray(value)) {
|
|
78
|
+
return value;
|
|
79
|
+
}
|
|
80
|
+
if (typeof value !== "string" || value.trim() === "") {
|
|
81
|
+
throw new Error("metadata must be an object or JSON object string");
|
|
82
|
+
}
|
|
83
|
+
const parsed = JSON.parse(value);
|
|
84
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
85
|
+
throw new Error("metadata must be a JSON object");
|
|
86
|
+
}
|
|
87
|
+
return parsed;
|
|
88
|
+
}
|
|
89
|
+
function ensureId(value) {
|
|
90
|
+
return value?.trim() || (0, import_node_crypto.randomUUID)();
|
|
91
|
+
}
|
|
92
|
+
function serializeJson(value) {
|
|
93
|
+
return JSON.stringify(value ?? {});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// src/validate.ts
|
|
97
|
+
function includesValue(values, value, label) {
|
|
98
|
+
if (!values.includes(value)) {
|
|
99
|
+
throw new Error(`Invalid ${label}: ${value}`);
|
|
100
|
+
}
|
|
101
|
+
return value;
|
|
102
|
+
}
|
|
103
|
+
function parseMemoryType(value) {
|
|
104
|
+
return includesValue(memoryTypes, value, "type");
|
|
105
|
+
}
|
|
106
|
+
function parseMemoryScope(value) {
|
|
107
|
+
return includesValue(memoryScopes, value, "scope");
|
|
108
|
+
}
|
|
109
|
+
function parseSourceKind(value) {
|
|
110
|
+
return includesValue(sourceKinds, value, "source kind");
|
|
111
|
+
}
|
|
112
|
+
function normalizeEntry(input) {
|
|
113
|
+
if (!input.text.trim()) {
|
|
114
|
+
throw new Error("text is required");
|
|
115
|
+
}
|
|
116
|
+
if (!input.source?.value?.trim()) {
|
|
117
|
+
throw new Error("source.value is required");
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
id: ensureId(input.id),
|
|
121
|
+
type: parseMemoryType(input.type),
|
|
122
|
+
text: input.text.trim(),
|
|
123
|
+
createdAt: toIsoString(input.createdAt),
|
|
124
|
+
source: {
|
|
125
|
+
kind: parseSourceKind(input.source.kind),
|
|
126
|
+
value: input.source.value.trim()
|
|
127
|
+
},
|
|
128
|
+
confidence: normalizeConfidence(input.confidence),
|
|
129
|
+
scope: parseMemoryScope(input.scope),
|
|
130
|
+
tags: uniqueSorted(input.tags),
|
|
131
|
+
expiresAt: input.expiresAt ? toIsoString(input.expiresAt) : void 0,
|
|
132
|
+
links: uniqueSorted(input.links),
|
|
133
|
+
metadata: parseJsonObject(input.metadata)
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// src/store.ts
|
|
138
|
+
var ChromaStore = class {
|
|
139
|
+
path;
|
|
140
|
+
db;
|
|
141
|
+
constructor(path = (0, import_node_path.resolve)(process.cwd(), ".chrona/chrona.db")) {
|
|
142
|
+
this.path = (0, import_node_path.resolve)(path);
|
|
143
|
+
(0, import_node_fs.mkdirSync)((0, import_node_path.dirname)(this.path), { recursive: true });
|
|
144
|
+
this.db = new import_better_sqlite3.default(this.path);
|
|
145
|
+
this.db.pragma("journal_mode = WAL");
|
|
146
|
+
this.db.pragma("foreign_keys = ON");
|
|
147
|
+
this.db.pragma("busy_timeout = 5000");
|
|
148
|
+
}
|
|
149
|
+
init() {
|
|
150
|
+
this.db.exec(`
|
|
151
|
+
CREATE TABLE IF NOT EXISTS memories (
|
|
152
|
+
id TEXT PRIMARY KEY,
|
|
153
|
+
type TEXT NOT NULL,
|
|
154
|
+
text TEXT NOT NULL,
|
|
155
|
+
created_at TEXT NOT NULL,
|
|
156
|
+
source_kind TEXT NOT NULL,
|
|
157
|
+
source_value TEXT NOT NULL,
|
|
158
|
+
confidence REAL NOT NULL,
|
|
159
|
+
scope TEXT NOT NULL,
|
|
160
|
+
tags_json TEXT NOT NULL,
|
|
161
|
+
expires_at TEXT,
|
|
162
|
+
links_json TEXT NOT NULL,
|
|
163
|
+
metadata_json TEXT NOT NULL
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
CREATE INDEX IF NOT EXISTS idx_memories_created_at ON memories(created_at);
|
|
167
|
+
CREATE INDEX IF NOT EXISTS idx_memories_scope ON memories(scope);
|
|
168
|
+
CREATE INDEX IF NOT EXISTS idx_memories_type ON memories(type);
|
|
169
|
+
CREATE INDEX IF NOT EXISTS idx_memories_expires_at ON memories(expires_at);
|
|
170
|
+
CREATE INDEX IF NOT EXISTS idx_memories_source ON memories(source_kind, source_value);
|
|
171
|
+
`);
|
|
172
|
+
}
|
|
173
|
+
close() {
|
|
174
|
+
this.db.close();
|
|
175
|
+
}
|
|
176
|
+
add(input) {
|
|
177
|
+
const entry = normalizeEntry(input);
|
|
178
|
+
this.init();
|
|
179
|
+
this.db.prepare(`
|
|
180
|
+
INSERT INTO memories (
|
|
181
|
+
id,
|
|
182
|
+
type,
|
|
183
|
+
text,
|
|
184
|
+
created_at,
|
|
185
|
+
source_kind,
|
|
186
|
+
source_value,
|
|
187
|
+
confidence,
|
|
188
|
+
scope,
|
|
189
|
+
tags_json,
|
|
190
|
+
expires_at,
|
|
191
|
+
links_json,
|
|
192
|
+
metadata_json
|
|
193
|
+
) VALUES (
|
|
194
|
+
@id,
|
|
195
|
+
@type,
|
|
196
|
+
@text,
|
|
197
|
+
@created_at,
|
|
198
|
+
@source_kind,
|
|
199
|
+
@source_value,
|
|
200
|
+
@confidence,
|
|
201
|
+
@scope,
|
|
202
|
+
@tags_json,
|
|
203
|
+
@expires_at,
|
|
204
|
+
@links_json,
|
|
205
|
+
@metadata_json
|
|
206
|
+
)
|
|
207
|
+
`).run(this.toRow(entry));
|
|
208
|
+
return entry;
|
|
209
|
+
}
|
|
210
|
+
get(id) {
|
|
211
|
+
this.init();
|
|
212
|
+
const row = this.db.prepare("SELECT * FROM memories WHERE id = ?").get(id);
|
|
213
|
+
return row ? this.fromRow(row) : null;
|
|
214
|
+
}
|
|
215
|
+
search(options) {
|
|
216
|
+
this.init();
|
|
217
|
+
const { sql, params } = this.buildQuery(
|
|
218
|
+
options,
|
|
219
|
+
[
|
|
220
|
+
"(",
|
|
221
|
+
"lower(text) LIKE @query",
|
|
222
|
+
"OR lower(tags_json) LIKE @query",
|
|
223
|
+
"OR lower(source_kind || ':' || source_value) LIKE @query",
|
|
224
|
+
"OR lower(metadata_json) LIKE @query",
|
|
225
|
+
")"
|
|
226
|
+
].join(" "),
|
|
227
|
+
{ query: `%${options.query.toLowerCase()}%` },
|
|
228
|
+
"ORDER BY created_at DESC, confidence DESC, id ASC"
|
|
229
|
+
);
|
|
230
|
+
return this.db.prepare(sql).all(params).map((row) => this.fromRow(row));
|
|
231
|
+
}
|
|
232
|
+
timeline(options = {}) {
|
|
233
|
+
this.init();
|
|
234
|
+
const direction = options.order === "desc" ? "DESC" : "ASC";
|
|
235
|
+
const { sql, params } = this.buildQuery(options, void 0, {}, `ORDER BY created_at ${direction}, id ASC`);
|
|
236
|
+
return this.db.prepare(sql).all(params).map((row) => this.fromRow(row));
|
|
237
|
+
}
|
|
238
|
+
exportJsonl(options = {}) {
|
|
239
|
+
return this.timeline(options).map((entry) => JSON.stringify(entry)).join("\n");
|
|
240
|
+
}
|
|
241
|
+
importJsonl(input) {
|
|
242
|
+
this.init();
|
|
243
|
+
const lines = input.split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
|
|
244
|
+
const ids = [];
|
|
245
|
+
let imported = 0;
|
|
246
|
+
let updated = 0;
|
|
247
|
+
const statement = this.db.prepare(`
|
|
248
|
+
INSERT INTO memories (
|
|
249
|
+
id,
|
|
250
|
+
type,
|
|
251
|
+
text,
|
|
252
|
+
created_at,
|
|
253
|
+
source_kind,
|
|
254
|
+
source_value,
|
|
255
|
+
confidence,
|
|
256
|
+
scope,
|
|
257
|
+
tags_json,
|
|
258
|
+
expires_at,
|
|
259
|
+
links_json,
|
|
260
|
+
metadata_json
|
|
261
|
+
) VALUES (
|
|
262
|
+
@id,
|
|
263
|
+
@type,
|
|
264
|
+
@text,
|
|
265
|
+
@created_at,
|
|
266
|
+
@source_kind,
|
|
267
|
+
@source_value,
|
|
268
|
+
@confidence,
|
|
269
|
+
@scope,
|
|
270
|
+
@tags_json,
|
|
271
|
+
@expires_at,
|
|
272
|
+
@links_json,
|
|
273
|
+
@metadata_json
|
|
274
|
+
)
|
|
275
|
+
ON CONFLICT(id) DO UPDATE SET
|
|
276
|
+
type = excluded.type,
|
|
277
|
+
text = excluded.text,
|
|
278
|
+
created_at = excluded.created_at,
|
|
279
|
+
source_kind = excluded.source_kind,
|
|
280
|
+
source_value = excluded.source_value,
|
|
281
|
+
confidence = excluded.confidence,
|
|
282
|
+
scope = excluded.scope,
|
|
283
|
+
tags_json = excluded.tags_json,
|
|
284
|
+
expires_at = excluded.expires_at,
|
|
285
|
+
links_json = excluded.links_json,
|
|
286
|
+
metadata_json = excluded.metadata_json
|
|
287
|
+
`);
|
|
288
|
+
const transaction = this.db.transaction(() => {
|
|
289
|
+
for (const line of lines) {
|
|
290
|
+
const entry = normalizeEntry(JSON.parse(line));
|
|
291
|
+
const exists = this.get(entry.id);
|
|
292
|
+
statement.run(this.toRow(entry));
|
|
293
|
+
ids.push(entry.id);
|
|
294
|
+
if (exists) {
|
|
295
|
+
updated += 1;
|
|
296
|
+
} else {
|
|
297
|
+
imported += 1;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
transaction();
|
|
302
|
+
return {
|
|
303
|
+
imported,
|
|
304
|
+
updated,
|
|
305
|
+
ids: [...ids].sort((a, b) => a.localeCompare(b))
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
gc(now) {
|
|
309
|
+
this.init();
|
|
310
|
+
const nowIso = toIsoString(now);
|
|
311
|
+
const rows = this.db.prepare(
|
|
312
|
+
"SELECT id FROM memories WHERE expires_at IS NOT NULL AND expires_at <= ? ORDER BY expires_at ASC, id ASC"
|
|
313
|
+
).all(nowIso);
|
|
314
|
+
const ids = rows.map((row) => row.id);
|
|
315
|
+
if (ids.length > 0) {
|
|
316
|
+
this.db.prepare("DELETE FROM memories WHERE expires_at IS NOT NULL AND expires_at <= ?").run(nowIso);
|
|
317
|
+
}
|
|
318
|
+
return {
|
|
319
|
+
deleted: ids.length,
|
|
320
|
+
ids,
|
|
321
|
+
now: nowIso
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
buildQuery(options, extraWhere, extraParams = {}, orderBy = "ORDER BY created_at ASC, id ASC") {
|
|
325
|
+
const where = [];
|
|
326
|
+
const params = { ...extraParams };
|
|
327
|
+
if (!options.includeExpired) {
|
|
328
|
+
where.push("(expires_at IS NULL OR expires_at > @now)");
|
|
329
|
+
params.now = toIsoString();
|
|
330
|
+
}
|
|
331
|
+
if (options.scopes?.length) {
|
|
332
|
+
const placeholders = options.scopes.map((_, index) => `@scope${index}`);
|
|
333
|
+
where.push(`scope IN (${placeholders.join(", ")})`);
|
|
334
|
+
for (const [index, scope] of options.scopes.entries()) {
|
|
335
|
+
params[`scope${index}`] = scope;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
if (options.types?.length) {
|
|
339
|
+
const placeholders = options.types.map((_, index) => `@type${index}`);
|
|
340
|
+
where.push(`type IN (${placeholders.join(", ")})`);
|
|
341
|
+
for (const [index, type] of options.types.entries()) {
|
|
342
|
+
params[`type${index}`] = type;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
if (options.tags?.length) {
|
|
346
|
+
const tagParts = [];
|
|
347
|
+
for (const [index, tag] of options.tags.entries()) {
|
|
348
|
+
const key = `tag${index}`;
|
|
349
|
+
tagParts.push(`lower(tags_json) LIKE @${key}`);
|
|
350
|
+
params[key] = `%${tag.toLowerCase()}%`;
|
|
351
|
+
}
|
|
352
|
+
where.push(`(${tagParts.join(" OR ")})`);
|
|
353
|
+
}
|
|
354
|
+
if (options.sourceKind) {
|
|
355
|
+
where.push("source_kind = @sourceKind");
|
|
356
|
+
params.sourceKind = options.sourceKind;
|
|
357
|
+
}
|
|
358
|
+
if (options.sourceValue) {
|
|
359
|
+
where.push("source_value = @sourceValue");
|
|
360
|
+
params.sourceValue = options.sourceValue;
|
|
361
|
+
}
|
|
362
|
+
if (options.before) {
|
|
363
|
+
where.push("created_at <= @before");
|
|
364
|
+
params.before = toIsoString(options.before);
|
|
365
|
+
}
|
|
366
|
+
if (options.after) {
|
|
367
|
+
where.push("created_at >= @after");
|
|
368
|
+
params.after = toIsoString(options.after);
|
|
369
|
+
}
|
|
370
|
+
if (extraWhere) {
|
|
371
|
+
where.push(extraWhere);
|
|
372
|
+
}
|
|
373
|
+
const limit = Math.max(1, Math.min(options.limit ?? 50, 1e3));
|
|
374
|
+
params.limit = limit;
|
|
375
|
+
const whereSql = where.length ? `WHERE ${where.join(" AND ")}` : "";
|
|
376
|
+
return {
|
|
377
|
+
sql: `SELECT * FROM memories ${whereSql} ${orderBy} LIMIT @limit`,
|
|
378
|
+
params
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
toRow(entry) {
|
|
382
|
+
return {
|
|
383
|
+
id: entry.id,
|
|
384
|
+
type: entry.type,
|
|
385
|
+
text: entry.text,
|
|
386
|
+
created_at: entry.createdAt,
|
|
387
|
+
source_kind: entry.source.kind,
|
|
388
|
+
source_value: entry.source.value,
|
|
389
|
+
confidence: entry.confidence,
|
|
390
|
+
scope: entry.scope,
|
|
391
|
+
tags_json: serializeJson(entry.tags),
|
|
392
|
+
expires_at: entry.expiresAt ?? null,
|
|
393
|
+
links_json: serializeJson(entry.links ?? []),
|
|
394
|
+
metadata_json: serializeJson(entry.metadata ?? {})
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
fromRow(row) {
|
|
398
|
+
return {
|
|
399
|
+
id: row.id,
|
|
400
|
+
type: row.type,
|
|
401
|
+
text: row.text,
|
|
402
|
+
createdAt: row.created_at,
|
|
403
|
+
source: {
|
|
404
|
+
kind: row.source_kind,
|
|
405
|
+
value: row.source_value
|
|
406
|
+
},
|
|
407
|
+
confidence: row.confidence,
|
|
408
|
+
scope: row.scope,
|
|
409
|
+
tags: JSON.parse(row.tags_json),
|
|
410
|
+
expiresAt: row.expires_at ?? void 0,
|
|
411
|
+
links: JSON.parse(row.links_json),
|
|
412
|
+
metadata: JSON.parse(row.metadata_json)
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
417
|
+
0 && (module.exports = {
|
|
418
|
+
ChromaStore,
|
|
419
|
+
memoryScopes,
|
|
420
|
+
memoryTypes,
|
|
421
|
+
normalizeEntry,
|
|
422
|
+
parseMemoryScope,
|
|
423
|
+
parseMemoryType,
|
|
424
|
+
parseSourceKind,
|
|
425
|
+
sourceKinds
|
|
426
|
+
});
|
|
427
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/types.ts","../src/store.ts","../src/utils.ts","../src/validate.ts"],"sourcesContent":["export * from \"./types.js\";\nexport * from \"./store.js\";\nexport * from \"./validate.js\";\n","export const memoryTypes = [\"decision\", \"preference\", \"fact\", \"incident\", \"constraint\"] as const;\nexport const memoryScopes = [\"user\", \"project\", \"org\", \"shared\"] as const;\nexport const sourceKinds = [\"tool\", \"session\", \"repo\"] as const;\n\nexport type MemoryType = (typeof memoryTypes)[number];\nexport type MemoryScope = (typeof memoryScopes)[number];\nexport type SourceKind = (typeof sourceKinds)[number];\n\nexport interface MemorySource {\n kind: SourceKind;\n value: string;\n}\n\nexport interface MemoryEntry {\n id: string;\n type: MemoryType;\n text: string;\n createdAt: string;\n source: MemorySource;\n confidence: number;\n scope: MemoryScope;\n tags: string[];\n expiresAt?: string;\n links?: string[];\n metadata?: Record<string, unknown>;\n}\n\nexport interface AddMemoryInput {\n id?: string;\n type: MemoryType;\n text: string;\n createdAt?: string;\n source: MemorySource;\n confidence: number;\n scope: MemoryScope;\n tags: string[];\n expiresAt?: string;\n links?: string[];\n metadata?: Record<string, unknown>;\n}\n\nexport interface QueryOptions {\n scopes?: MemoryScope[];\n types?: MemoryType[];\n tags?: string[];\n sourceKind?: SourceKind;\n sourceValue?: string;\n before?: string;\n after?: string;\n includeExpired?: boolean;\n limit?: number;\n}\n\nexport interface SearchOptions extends QueryOptions {\n query: string;\n}\n\nexport interface TimelineOptions extends QueryOptions {\n order?: \"asc\" | \"desc\";\n}\n\nexport interface ExportOptions extends TimelineOptions {}\n\nexport interface ImportResult {\n imported: number;\n updated: number;\n ids: string[];\n}\n\nexport interface GcResult {\n deleted: number;\n ids: string[];\n now: string;\n}\n","import Database from \"better-sqlite3\";\nimport { mkdirSync } from \"node:fs\";\nimport { dirname, resolve } from \"node:path\";\nimport type {\n AddMemoryInput,\n ExportOptions,\n GcResult,\n ImportResult,\n MemoryEntry,\n QueryOptions,\n SearchOptions,\n TimelineOptions\n} from \"./types.js\";\nimport { normalizeEntry } from \"./validate.js\";\nimport { serializeJson, toIsoString } from \"./utils.js\";\n\ninterface MemoryRow {\n id: string;\n type: MemoryEntry[\"type\"];\n text: string;\n created_at: string;\n source_kind: MemoryEntry[\"source\"][\"kind\"];\n source_value: string;\n confidence: number;\n scope: MemoryEntry[\"scope\"];\n tags_json: string;\n expires_at: string | null;\n links_json: string;\n metadata_json: string;\n}\n\nexport class ChromaStore {\n readonly path: string;\n readonly db: Database.Database;\n\n constructor(path = resolve(process.cwd(), \".chrona/chrona.db\")) {\n this.path = resolve(path);\n mkdirSync(dirname(this.path), { recursive: true });\n this.db = new Database(this.path);\n this.db.pragma(\"journal_mode = WAL\");\n this.db.pragma(\"foreign_keys = ON\");\n this.db.pragma(\"busy_timeout = 5000\");\n }\n\n init(): void {\n this.db.exec(`\n CREATE TABLE IF NOT EXISTS memories (\n id TEXT PRIMARY KEY,\n type TEXT NOT NULL,\n text TEXT NOT NULL,\n created_at TEXT NOT NULL,\n source_kind TEXT NOT NULL,\n source_value TEXT NOT NULL,\n confidence REAL NOT NULL,\n scope TEXT NOT NULL,\n tags_json TEXT NOT NULL,\n expires_at TEXT,\n links_json TEXT NOT NULL,\n metadata_json TEXT NOT NULL\n );\n\n CREATE INDEX IF NOT EXISTS idx_memories_created_at ON memories(created_at);\n CREATE INDEX IF NOT EXISTS idx_memories_scope ON memories(scope);\n CREATE INDEX IF NOT EXISTS idx_memories_type ON memories(type);\n CREATE INDEX IF NOT EXISTS idx_memories_expires_at ON memories(expires_at);\n CREATE INDEX IF NOT EXISTS idx_memories_source ON memories(source_kind, source_value);\n `);\n }\n\n close(): void {\n this.db.close();\n }\n\n add(input: AddMemoryInput): MemoryEntry {\n const entry = normalizeEntry(input);\n this.init();\n\n this.db.prepare(`\n INSERT INTO memories (\n id,\n type,\n text,\n created_at,\n source_kind,\n source_value,\n confidence,\n scope,\n tags_json,\n expires_at,\n links_json,\n metadata_json\n ) VALUES (\n @id,\n @type,\n @text,\n @created_at,\n @source_kind,\n @source_value,\n @confidence,\n @scope,\n @tags_json,\n @expires_at,\n @links_json,\n @metadata_json\n )\n `).run(this.toRow(entry));\n\n return entry;\n }\n\n get(id: string): MemoryEntry | null {\n this.init();\n const row = this.db.prepare(\"SELECT * FROM memories WHERE id = ?\").get(id) as MemoryRow | undefined;\n return row ? this.fromRow(row) : null;\n }\n\n search(options: SearchOptions): MemoryEntry[] {\n this.init();\n const { sql, params } = this.buildQuery(\n options,\n [\n \"(\",\n \"lower(text) LIKE @query\",\n \"OR lower(tags_json) LIKE @query\",\n \"OR lower(source_kind || ':' || source_value) LIKE @query\",\n \"OR lower(metadata_json) LIKE @query\",\n \")\"\n ].join(\" \"),\n { query: `%${options.query.toLowerCase()}%` },\n \"ORDER BY created_at DESC, confidence DESC, id ASC\"\n );\n\n return this.db.prepare(sql).all(params).map((row) => this.fromRow(row as MemoryRow));\n }\n\n timeline(options: TimelineOptions = {}): MemoryEntry[] {\n this.init();\n const direction = options.order === \"desc\" ? \"DESC\" : \"ASC\";\n const { sql, params } = this.buildQuery(options, undefined, {}, `ORDER BY created_at ${direction}, id ASC`);\n return this.db.prepare(sql).all(params).map((row) => this.fromRow(row as MemoryRow));\n }\n\n exportJsonl(options: ExportOptions = {}): string {\n return this.timeline(options).map((entry) => JSON.stringify(entry)).join(\"\\n\");\n }\n\n importJsonl(input: string): ImportResult {\n this.init();\n const lines = input.split(/\\r?\\n/).map((line) => line.trim()).filter(Boolean);\n const ids: string[] = [];\n let imported = 0;\n let updated = 0;\n\n const statement = this.db.prepare(`\n INSERT INTO memories (\n id,\n type,\n text,\n created_at,\n source_kind,\n source_value,\n confidence,\n scope,\n tags_json,\n expires_at,\n links_json,\n metadata_json\n ) VALUES (\n @id,\n @type,\n @text,\n @created_at,\n @source_kind,\n @source_value,\n @confidence,\n @scope,\n @tags_json,\n @expires_at,\n @links_json,\n @metadata_json\n )\n ON CONFLICT(id) DO UPDATE SET\n type = excluded.type,\n text = excluded.text,\n created_at = excluded.created_at,\n source_kind = excluded.source_kind,\n source_value = excluded.source_value,\n confidence = excluded.confidence,\n scope = excluded.scope,\n tags_json = excluded.tags_json,\n expires_at = excluded.expires_at,\n links_json = excluded.links_json,\n metadata_json = excluded.metadata_json\n `);\n\n const transaction = this.db.transaction(() => {\n for (const line of lines) {\n const entry = normalizeEntry(JSON.parse(line) as AddMemoryInput);\n const exists = this.get(entry.id);\n statement.run(this.toRow(entry));\n ids.push(entry.id);\n if (exists) {\n updated += 1;\n } else {\n imported += 1;\n }\n }\n });\n\n transaction();\n\n return {\n imported,\n updated,\n ids: [...ids].sort((a, b) => a.localeCompare(b))\n };\n }\n\n gc(now?: string | Date): GcResult {\n this.init();\n const nowIso = toIsoString(now);\n const rows = this.db.prepare(\n \"SELECT id FROM memories WHERE expires_at IS NOT NULL AND expires_at <= ? ORDER BY expires_at ASC, id ASC\"\n ).all(nowIso) as Array<{ id: string }>;\n const ids = rows.map((row) => row.id);\n\n if (ids.length > 0) {\n this.db.prepare(\"DELETE FROM memories WHERE expires_at IS NOT NULL AND expires_at <= ?\").run(nowIso);\n }\n\n return {\n deleted: ids.length,\n ids,\n now: nowIso\n };\n }\n\n private buildQuery(\n options: QueryOptions,\n extraWhere?: string,\n extraParams: Record<string, unknown> = {},\n orderBy = \"ORDER BY created_at ASC, id ASC\"\n ): { sql: string; params: Record<string, unknown> } {\n const where: string[] = [];\n const params: Record<string, unknown> = { ...extraParams };\n\n if (!options.includeExpired) {\n where.push(\"(expires_at IS NULL OR expires_at > @now)\");\n params.now = toIsoString();\n }\n\n if (options.scopes?.length) {\n const placeholders = options.scopes.map((_, index) => `@scope${index}`);\n where.push(`scope IN (${placeholders.join(\", \")})`);\n for (const [index, scope] of options.scopes.entries()) {\n params[`scope${index}`] = scope;\n }\n }\n\n if (options.types?.length) {\n const placeholders = options.types.map((_, index) => `@type${index}`);\n where.push(`type IN (${placeholders.join(\", \")})`);\n for (const [index, type] of options.types.entries()) {\n params[`type${index}`] = type;\n }\n }\n\n if (options.tags?.length) {\n const tagParts: string[] = [];\n for (const [index, tag] of options.tags.entries()) {\n const key = `tag${index}`;\n tagParts.push(`lower(tags_json) LIKE @${key}`);\n params[key] = `%${tag.toLowerCase()}%`;\n }\n where.push(`(${tagParts.join(\" OR \")})`);\n }\n\n if (options.sourceKind) {\n where.push(\"source_kind = @sourceKind\");\n params.sourceKind = options.sourceKind;\n }\n\n if (options.sourceValue) {\n where.push(\"source_value = @sourceValue\");\n params.sourceValue = options.sourceValue;\n }\n\n if (options.before) {\n where.push(\"created_at <= @before\");\n params.before = toIsoString(options.before);\n }\n\n if (options.after) {\n where.push(\"created_at >= @after\");\n params.after = toIsoString(options.after);\n }\n\n if (extraWhere) {\n where.push(extraWhere);\n }\n\n const limit = Math.max(1, Math.min(options.limit ?? 50, 1000));\n params.limit = limit;\n const whereSql = where.length ? `WHERE ${where.join(\" AND \")}` : \"\";\n\n return {\n sql: `SELECT * FROM memories ${whereSql} ${orderBy} LIMIT @limit`,\n params\n };\n }\n\n private toRow(entry: MemoryEntry): Record<string, unknown> {\n return {\n id: entry.id,\n type: entry.type,\n text: entry.text,\n created_at: entry.createdAt,\n source_kind: entry.source.kind,\n source_value: entry.source.value,\n confidence: entry.confidence,\n scope: entry.scope,\n tags_json: serializeJson(entry.tags),\n expires_at: entry.expiresAt ?? null,\n links_json: serializeJson(entry.links ?? []),\n metadata_json: serializeJson(entry.metadata ?? {})\n };\n }\n\n private fromRow(row: MemoryRow): MemoryEntry {\n return {\n id: row.id,\n type: row.type,\n text: row.text,\n createdAt: row.created_at,\n source: {\n kind: row.source_kind,\n value: row.source_value\n },\n confidence: row.confidence,\n scope: row.scope,\n tags: JSON.parse(row.tags_json) as string[],\n expiresAt: row.expires_at ?? undefined,\n links: JSON.parse(row.links_json) as string[],\n metadata: JSON.parse(row.metadata_json) as Record<string, unknown>\n };\n }\n}\n","import { randomUUID } from \"node:crypto\";\n\nexport function toIsoString(value?: string | Date): string {\n const date = value instanceof Date ? value : value ? new Date(value) : new Date();\n const iso = date.toISOString();\n\n if (Number.isNaN(date.getTime())) {\n throw new Error(`Invalid date: ${String(value)}`);\n }\n\n return iso;\n}\n\nexport function uniqueSorted(values: string[] | undefined): string[] {\n return [...new Set((values ?? []).map((value) => value.trim()).filter(Boolean))].sort((a, b) => a.localeCompare(b));\n}\n\nexport function normalizeConfidence(value: number): number {\n if (!Number.isFinite(value) || value < 0 || value > 1) {\n throw new Error(\"confidence must be between 0 and 1\");\n }\n\n return Number(value.toFixed(6));\n}\n\nexport function parseJsonObject(value: unknown): Record<string, unknown> | undefined {\n if (value === undefined || value === null) {\n return undefined;\n }\n\n if (typeof value === \"object\" && !Array.isArray(value)) {\n return value as Record<string, unknown>;\n }\n\n if (typeof value !== \"string\" || value.trim() === \"\") {\n throw new Error(\"metadata must be an object or JSON object string\");\n }\n\n const parsed = JSON.parse(value) as unknown;\n\n if (!parsed || typeof parsed !== \"object\" || Array.isArray(parsed)) {\n throw new Error(\"metadata must be a JSON object\");\n }\n\n return parsed as Record<string, unknown>;\n}\n\nexport function parseCsv(value?: string): string[] {\n if (!value) {\n return [];\n }\n\n return value.split(\",\").map((item) => item.trim()).filter(Boolean);\n}\n\nexport function ensureId(value?: string): string {\n return value?.trim() || randomUUID();\n}\n\nexport function serializeJson(value: unknown): string {\n return JSON.stringify(value ?? {});\n}\n","import {\n memoryScopes,\n memoryTypes,\n sourceKinds,\n type AddMemoryInput,\n type MemoryEntry,\n type MemoryScope,\n type MemoryType,\n type SourceKind\n} from \"./types.js\";\nimport { ensureId, normalizeConfidence, parseJsonObject, toIsoString, uniqueSorted } from \"./utils.js\";\n\nfunction includesValue<T extends string>(values: readonly T[], value: string, label: string): T {\n if (!values.includes(value as T)) {\n throw new Error(`Invalid ${label}: ${value}`);\n }\n\n return value as T;\n}\n\nexport function parseMemoryType(value: string): MemoryType {\n return includesValue(memoryTypes, value, \"type\");\n}\n\nexport function parseMemoryScope(value: string): MemoryScope {\n return includesValue(memoryScopes, value, \"scope\");\n}\n\nexport function parseSourceKind(value: string): SourceKind {\n return includesValue(sourceKinds, value, \"source kind\");\n}\n\nexport function normalizeEntry(input: AddMemoryInput | MemoryEntry): MemoryEntry {\n if (!input.text.trim()) {\n throw new Error(\"text is required\");\n }\n\n if (!input.source?.value?.trim()) {\n throw new Error(\"source.value is required\");\n }\n\n return {\n id: ensureId(input.id),\n type: parseMemoryType(input.type),\n text: input.text.trim(),\n createdAt: toIsoString(input.createdAt),\n source: {\n kind: parseSourceKind(input.source.kind),\n value: input.source.value.trim()\n },\n confidence: normalizeConfidence(input.confidence),\n scope: parseMemoryScope(input.scope),\n tags: uniqueSorted(input.tags),\n expiresAt: input.expiresAt ? toIsoString(input.expiresAt) : undefined,\n links: uniqueSorted(input.links),\n metadata: parseJsonObject(input.metadata)\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,cAAc,CAAC,YAAY,cAAc,QAAQ,YAAY,YAAY;AAC/E,IAAM,eAAe,CAAC,QAAQ,WAAW,OAAO,QAAQ;AACxD,IAAM,cAAc,CAAC,QAAQ,WAAW,MAAM;;;ACFrD,4BAAqB;AACrB,qBAA0B;AAC1B,uBAAiC;;;ACFjC,yBAA2B;AAEpB,SAAS,YAAY,OAA+B;AACzD,QAAM,OAAO,iBAAiB,OAAO,QAAQ,QAAQ,IAAI,KAAK,KAAK,IAAI,oBAAI,KAAK;AAChF,QAAM,MAAM,KAAK,YAAY;AAE7B,MAAI,OAAO,MAAM,KAAK,QAAQ,CAAC,GAAG;AAChC,UAAM,IAAI,MAAM,iBAAiB,OAAO,KAAK,CAAC,EAAE;AAAA,EAClD;AAEA,SAAO;AACT;AAEO,SAAS,aAAa,QAAwC;AACnE,SAAO,CAAC,GAAG,IAAI,KAAK,UAAU,CAAC,GAAG,IAAI,CAAC,UAAU,MAAM,KAAK,CAAC,EAAE,OAAO,OAAO,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,MAAM,EAAE,cAAc,CAAC,CAAC;AACpH;AAEO,SAAS,oBAAoB,OAAuB;AACzD,MAAI,CAAC,OAAO,SAAS,KAAK,KAAK,QAAQ,KAAK,QAAQ,GAAG;AACrD,UAAM,IAAI,MAAM,oCAAoC;AAAA,EACtD;AAEA,SAAO,OAAO,MAAM,QAAQ,CAAC,CAAC;AAChC;AAEO,SAAS,gBAAgB,OAA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