@dsh-enhanced/personal-memory 0.1.3

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.
@@ -0,0 +1,87 @@
1
+ import { Context, Service } from '@deepseek-ai/cordis';
2
+ import type { Agent } from '@deepseek-ai/dsh-agent';
3
+ import Schema from '@deepseek-ai/schemastery';
4
+ import { MemoryStore } from './store.js';
5
+ import type { MemoryImportBatchResult, MemoryMutation, MemoryProposalDecisionInput, MemoryProposalResult, MemoryRecord, MemorySearchHit } from './types.js';
6
+ export interface Config {
7
+ databasePath: string;
8
+ approvalMode?: 'delivery-or-headless' | 'delivery-required';
9
+ maxContentBytes?: number;
10
+ maxRecordsPerIdentity?: number;
11
+ searchLimit?: number;
12
+ snapshotLimit?: number;
13
+ snapshotMaxBytes?: number;
14
+ snapshotMaxTokens?: number;
15
+ defaultProposalTtlMs?: number;
16
+ maxImportRecords?: number;
17
+ /**
18
+ * Poll interval for committing proposals that were approved out of band, for
19
+ * example on an approval card after the originating turn ended. `0` disables
20
+ * the timer; `reconcileProposals()` can still be driven by a trusted host.
21
+ */
22
+ reconcileIntervalMs?: number;
23
+ /** Maximum locally pending proposals inspected per reconcile pass. */
24
+ reconcileLimit?: number;
25
+ }
26
+ export interface ServiceSearchRequest {
27
+ query: string;
28
+ limit?: number;
29
+ authorizationIdempotencyKey?: string;
30
+ }
31
+ export interface ServiceProposalInput {
32
+ idempotencyKey: string;
33
+ /** Trusted headless fallback. Agent-facing calls derive this from Delivery. */
34
+ principal?: string;
35
+ ttlMs?: number;
36
+ mutation: MemoryMutation;
37
+ }
38
+ export interface ServiceImportInput {
39
+ json: string;
40
+ idempotencyKey: string;
41
+ /** Trusted headless fallback. Agent-facing calls derive this from Delivery. */
42
+ principal?: string;
43
+ ttlMs?: number;
44
+ }
45
+ export type PersonalMemoryErrorCode = 'disposed' | 'identity-mismatch' | 'invalid-import' | 'missing-identity' | 'missing-approval-route' | 'not-found' | 'policy-denied' | 'unauthorized-principal';
46
+ export declare class PersonalMemoryError extends Error {
47
+ readonly code: PersonalMemoryErrorCode;
48
+ constructor(code: PersonalMemoryErrorCode, message: string);
49
+ }
50
+ declare module '@deepseek-ai/cordis' {
51
+ interface Context {
52
+ personalMemory: PersonalMemoryService;
53
+ }
54
+ }
55
+ export declare class PersonalMemoryService extends Service {
56
+ static Config: Schema<Config>;
57
+ private readonly memoryStore;
58
+ private readonly proposals;
59
+ private readonly policy;
60
+ private delivery;
61
+ private readonly config;
62
+ private readonly sessionSnapshots;
63
+ private active;
64
+ constructor(ctx: Context, input: Config);
65
+ search(agent: Agent | undefined, request: ServiceSearchRequest): MemorySearchHit[];
66
+ read(agent: Agent | undefined, request: {
67
+ ids: readonly string[];
68
+ }): MemoryRecord[];
69
+ propose(agent: Agent | undefined, input: ServiceProposalInput): MemoryProposalResult;
70
+ decideProposal(input: MemoryProposalDecisionInput): MemoryProposalResult;
71
+ /**
72
+ * Commit proposals whose policy decision settled after the originating turn.
73
+ * Without this, an approval granted on a chat card would leave the memory
74
+ * proposal pending forever. Safe to call repeatedly.
75
+ */
76
+ reconcileProposals(limit?: number): MemoryProposalResult[];
77
+ exportJson(agent: Agent | undefined): string;
78
+ proposeImport(agent: Agent | undefined, input: ServiceImportInput): MemoryImportBatchResult;
79
+ getProposal(proposalId: string, principal: string): MemoryProposalResult | undefined;
80
+ health(): ReturnType<MemoryStore['health']>;
81
+ private injectSessionSnapshot;
82
+ private assertMutationIdentity;
83
+ private resolveApprovalRoute;
84
+ private agentContext;
85
+ private assertActive;
86
+ }
87
+ //# sourceMappingURL=service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAEnD,OAAO,MAAM,MAAM,0BAA0B,CAA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AS,GAAG,MAAM;IAU5C,aAAa,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,EAAE,KAAK,EAAE,kBAAkB,GAAG,uBAAuB;IA8C3F,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,oBAAoB,GAAG,SAAS;IAWpF,MAAM,IAAI,UAAU,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;IAK3C,OAAO,CAAC,qBAAqB;IA2B7B,OAAO,CAAC,sBAAsB;IAU9B,OAAO,CAAC,oBAAoB;IA4C5B,OAAO,CAAC,YAAY;IAUpB,OAAO,CAAC,YAAY;CAGrB"}
package/lib/service.js ADDED
@@ -0,0 +1,316 @@
1
+ import { isAbsolute } from 'node:path';
2
+ import { Context, Service } from '@deepseek-ai/cordis';
3
+ import { createUserMessage } from '@deepseek-ai/dsh-llm';
4
+ import Schema from '@deepseek-ai/schemastery';
5
+ import { MemoryProposalManager } from './proposals.js';
6
+ import { MemoryStore } from './store.js';
7
+ import { registerMemoryTools } from './tools.js';
8
+ export class PersonalMemoryError extends Error {
9
+ code;
10
+ constructor(code, message) {
11
+ super(message);
12
+ this.code = code;
13
+ this.name = 'PersonalMemoryError';
14
+ }
15
+ }
16
+ const configSchema = Schema.object({
17
+ databasePath: Schema.string().required(),
18
+ approvalMode: Schema.union(['delivery-or-headless', 'delivery-required'])
19
+ .default('delivery-required'),
20
+ maxContentBytes: Schema.number().step(1).min(1).default(4_096),
21
+ maxRecordsPerIdentity: Schema.number().step(1).min(1).default(1_000),
22
+ searchLimit: Schema.number().step(1).min(1).max(100).default(20),
23
+ snapshotLimit: Schema.number().step(1).min(1).max(100).default(20),
24
+ snapshotMaxBytes: Schema.number().step(1).min(1).default(8_192),
25
+ snapshotMaxTokens: Schema.number().step(1).min(1).default(2_048),
26
+ defaultProposalTtlMs: Schema.number().step(1).min(1).default(900_000),
27
+ maxImportRecords: Schema.number().step(1).min(1).max(1_000).default(100),
28
+ reconcileIntervalMs: Schema.number()
29
+ .step(1)
30
+ .min(0)
31
+ .max(2_147_483_647)
32
+ .default(15_000),
33
+ reconcileLimit: Schema.number().step(1).min(1).max(1_000).default(50),
34
+ });
35
+ function decisionError(decision) {
36
+ return new PersonalMemoryError('policy-denied', `personal-memory policy denied operation: ${decision.reasonCode}`);
37
+ }
38
+ const APPROVAL_SOURCE_ID = 'dsh-enhanced-personal-memory';
39
+ export class PersonalMemoryService extends Service {
40
+ static Config = configSchema;
41
+ memoryStore;
42
+ proposals;
43
+ policy;
44
+ delivery;
45
+ config;
46
+ sessionSnapshots = new WeakMap();
47
+ active = true;
48
+ constructor(ctx, input) {
49
+ super(ctx, 'personalMemory');
50
+ let config;
51
+ try {
52
+ config = PersonalMemoryService.Config(input);
53
+ }
54
+ catch (error) {
55
+ throw new Error(`personal-memory: invalid configuration: ${String(error)}`, { cause: error });
56
+ }
57
+ const policy = ctx.get('assistantPolicy');
58
+ if (policy === undefined)
59
+ throw new Error('personal-memory: assistantPolicy service is required');
60
+ this.config = config;
61
+ this.policy = policy;
62
+ this.delivery = ctx.get('assistantDelivery');
63
+ this.memoryStore = new MemoryStore({
64
+ path: config.databasePath,
65
+ maxContentBytes: config.maxContentBytes,
66
+ maxRecordsPerIdentity: config.maxRecordsPerIdentity,
67
+ });
68
+ this.proposals = new MemoryProposalManager(this.memoryStore, policy);
69
+ ctx.inject(['assistantDelivery'], (deliveryCtx) => {
70
+ const delivery = deliveryCtx.get('assistantDelivery');
71
+ this.delivery = delivery;
72
+ return () => {
73
+ if (this.delivery === delivery)
74
+ this.delivery = undefined;
75
+ };
76
+ });
77
+ ctx.effect(() => () => {
78
+ this.active = false;
79
+ this.memoryStore.close();
80
+ }, 'personal-memory.database');
81
+ if (config.reconcileIntervalMs > 0) {
82
+ ctx.effect(() => {
83
+ const timer = setInterval(() => {
84
+ // A reconcile pass must never take the service down; the next tick retries.
85
+ try {
86
+ this.reconcileProposals();
87
+ }
88
+ catch {
89
+ // Intentionally ignored: the authoritative state stays in the ledger.
90
+ }
91
+ }, config.reconcileIntervalMs);
92
+ timer.unref?.();
93
+ return () => clearInterval(timer);
94
+ }, 'personal-memory.reconcile');
95
+ }
96
+ ctx.on('agent/session-start', ({ agent }) => {
97
+ this.injectSessionSnapshot(agent);
98
+ });
99
+ ctx.inject(['tools'], (toolsCtx) => {
100
+ registerMemoryTools(toolsCtx, this);
101
+ });
102
+ }
103
+ search(agent, request) {
104
+ this.assertActive();
105
+ const context = this.agentContext(agent);
106
+ const authorizationOptions = request.authorizationIdempotencyKey === undefined
107
+ ? {}
108
+ : { idempotencyKey: request.authorizationIdempotencyKey };
109
+ const decision = this.policy.authorizeAgent(agent, 'search', { kind: 'memory', id: 'visible' }, authorizationOptions);
110
+ if (decision.effect !== 'allow')
111
+ throw decisionError(decision);
112
+ return this.memoryStore.search({
113
+ context,
114
+ query: request.query,
115
+ limit: request.limit ?? this.config.searchLimit,
116
+ });
117
+ }
118
+ read(agent, request) {
119
+ this.assertActive();
120
+ const context = this.agentContext(agent);
121
+ const decision = this.policy.authorizeAgent(agent, 'read', { kind: 'memory', id: 'selected' }, {
122
+ idempotencyKey: `memory-read:${request.ids.join(':')}`,
123
+ });
124
+ if (decision.effect !== 'allow')
125
+ throw decisionError(decision);
126
+ try {
127
+ return this.memoryStore.read(context, request.ids);
128
+ }
129
+ catch (error) {
130
+ if (error instanceof Error && 'code' in error && error.code === 'not-found') {
131
+ throw new PersonalMemoryError('not-found', error.message);
132
+ }
133
+ throw error;
134
+ }
135
+ }
136
+ propose(agent, input) {
137
+ this.assertActive();
138
+ const context = this.agentContext(agent);
139
+ this.assertMutationIdentity(context, input.mutation);
140
+ const approval = this.resolveApprovalRoute(agent, context, input.principal);
141
+ const decision = this.policy.authorizeAgent(agent, 'propose', {
142
+ kind: 'memory', id: input.mutation.op,
143
+ }, { idempotencyKey: `memory-propose:${input.idempotencyKey}` });
144
+ if (decision.effect !== 'allow')
145
+ throw decisionError(decision);
146
+ return this.proposals.propose({
147
+ idempotencyKey: input.idempotencyKey,
148
+ requester: `agent:${context.agentPreset}`,
149
+ principal: approval.principal,
150
+ ...(approval.dispatch === undefined ? {} : { dispatch: approval.dispatch }),
151
+ ttlMs: input.ttlMs ?? this.config.defaultProposalTtlMs,
152
+ mutation: input.mutation,
153
+ });
154
+ }
155
+ decideProposal(input) {
156
+ this.assertActive();
157
+ return this.proposals.decide(input);
158
+ }
159
+ /**
160
+ * Commit proposals whose policy decision settled after the originating turn.
161
+ * Without this, an approval granted on a chat card would leave the memory
162
+ * proposal pending forever. Safe to call repeatedly.
163
+ */
164
+ reconcileProposals(limit) {
165
+ this.assertActive();
166
+ return this.proposals.reconcile(limit ?? this.config.reconcileLimit);
167
+ }
168
+ exportJson(agent) {
169
+ this.assertActive();
170
+ const context = this.agentContext(agent);
171
+ const decision = this.policy.authorizeAgent(agent, 'export', { kind: 'memory', id: 'visible' }, {
172
+ idempotencyKey: `memory-export:${String(agent?.id)}`,
173
+ });
174
+ if (decision.effect !== 'allow')
175
+ throw decisionError(decision);
176
+ return JSON.stringify(this.memoryStore.exportDocument(context), null, 2);
177
+ }
178
+ proposeImport(agent, input) {
179
+ this.assertActive();
180
+ const context = this.agentContext(agent);
181
+ let decoded;
182
+ try {
183
+ decoded = JSON.parse(input.json);
184
+ }
185
+ catch (error) {
186
+ throw new PersonalMemoryError('invalid-import', `memory import is not valid JSON: ${String(error)}`);
187
+ }
188
+ const document = decoded;
189
+ if (typeof document !== 'object' || document === null
190
+ || document.format !== 'dsh-personal-memory'
191
+ || document.version !== 1
192
+ || !Array.isArray(document.records)
193
+ || document.records.length > this.config.maxImportRecords) {
194
+ throw new PersonalMemoryError('invalid-import', 'memory import format, version, or record count is invalid');
195
+ }
196
+ let mutations;
197
+ try {
198
+ mutations = document.records.map((value) => {
199
+ if (typeof value !== 'object' || value === null)
200
+ throw new Error('record must be an object');
201
+ const record = value;
202
+ const mutation = this.memoryStore.normalizeMutation({
203
+ op: 'add',
204
+ identity: record.identity,
205
+ entry: record.entry,
206
+ });
207
+ this.assertMutationIdentity(context, mutation);
208
+ return mutation;
209
+ });
210
+ }
211
+ catch (error) {
212
+ throw new PersonalMemoryError('invalid-import', `memory import record is invalid: ${String(error)}`);
213
+ }
214
+ const proposals = mutations.map((mutation, index) => this.propose(agent, {
215
+ idempotencyKey: `${input.idempotencyKey}:${index}`,
216
+ ...(input.principal === undefined ? {} : { principal: input.principal }),
217
+ ...(input.ttlMs === undefined ? {} : { ttlMs: input.ttlMs }),
218
+ mutation,
219
+ }));
220
+ return Object.freeze({ proposals: Object.freeze(proposals) });
221
+ }
222
+ getProposal(proposalId, principal) {
223
+ this.assertActive();
224
+ const proposal = this.proposals.getProposal(proposalId);
225
+ if (proposal === undefined)
226
+ return undefined;
227
+ const stored = this.memoryStore.getProposal(proposalId);
228
+ if (stored?.principal !== principal) {
229
+ throw new PersonalMemoryError('unauthorized-principal', 'memory proposal is bound to another principal');
230
+ }
231
+ return proposal;
232
+ }
233
+ health() {
234
+ this.assertActive();
235
+ return this.memoryStore.health();
236
+ }
237
+ injectSessionSnapshot(agent) {
238
+ if (this.sessionSnapshots.has(agent))
239
+ return;
240
+ let context;
241
+ try {
242
+ context = this.agentContext(agent);
243
+ }
244
+ catch (error) {
245
+ if (error instanceof PersonalMemoryError && error.code === 'missing-identity')
246
+ return;
247
+ throw error;
248
+ }
249
+ const decision = this.policy.authorizeAgent(agent, 'snapshot', { kind: 'memory', id: 'visible' }, {
250
+ idempotencyKey: `memory-snapshot:${agent.id}`,
251
+ });
252
+ if (decision.effect !== 'allow')
253
+ return;
254
+ const snapshot = this.memoryStore.snapshot({
255
+ context,
256
+ limit: this.config.snapshotLimit,
257
+ maxBytes: this.config.snapshotMaxBytes,
258
+ maxTokens: this.config.snapshotMaxTokens,
259
+ });
260
+ this.sessionSnapshots.set(agent, snapshot);
261
+ if (snapshot.text === '')
262
+ return;
263
+ agent.inject(createUserMessage({
264
+ content: [{ type: 'text', text: snapshot.text }],
265
+ source: { kind: 'plugin', plugin: 'personal-memory' },
266
+ }));
267
+ }
268
+ assertMutationIdentity(context, mutation) {
269
+ const identity = mutation.identity;
270
+ if (identity.scope === 'workspace' && identity.workspace !== context.workspace) {
271
+ throw new PersonalMemoryError('identity-mismatch', 'workspace memory must target the current workspace');
272
+ }
273
+ if (identity.owner === 'agent' && identity.agentPreset !== context.agentPreset) {
274
+ throw new PersonalMemoryError('identity-mismatch', 'agent memory must target the current agent preset');
275
+ }
276
+ }
277
+ resolveApprovalRoute(agent, context, explicitPrincipal) {
278
+ if (this.delivery === undefined) {
279
+ if (this.config.approvalMode === 'delivery-required') {
280
+ throw new PersonalMemoryError('missing-approval-route', 'memory proposal requires an authenticated Delivery owner route');
281
+ }
282
+ if (explicitPrincipal === undefined || explicitPrincipal.trim() === '') {
283
+ throw new PersonalMemoryError('missing-approval-route', 'memory proposal requires an authenticated Delivery route or an explicit trusted headless principal');
284
+ }
285
+ return { principal: explicitPrincipal };
286
+ }
287
+ const dispatch = this.delivery.prepareAgentApproval(agent, {
288
+ sourceId: APPROVAL_SOURCE_ID,
289
+ });
290
+ if (dispatch.sourceId !== APPROVAL_SOURCE_ID
291
+ || dispatch.workspace !== context.workspace
292
+ || dispatch.bindingId.trim() === ''
293
+ || dispatch.principal.trim() === '') {
294
+ throw new PersonalMemoryError('missing-approval-route', 'memory proposal Delivery route does not match the current agent workspace');
295
+ }
296
+ if (explicitPrincipal !== undefined && explicitPrincipal !== dispatch.principal) {
297
+ throw new PersonalMemoryError('unauthorized-principal', 'memory proposal principal does not match the authenticated Delivery owner');
298
+ }
299
+ return { principal: dispatch.principal, dispatch };
300
+ }
301
+ agentContext(agent) {
302
+ if (agent === undefined)
303
+ throw new PersonalMemoryError('missing-identity', 'memory operation requires an agent');
304
+ const workspace = agent.session.header.cwd;
305
+ const agentPreset = agent.session.header.agentPreset;
306
+ if (workspace === undefined || !isAbsolute(workspace) || agentPreset === undefined || agentPreset === '') {
307
+ throw new PersonalMemoryError('missing-identity', 'memory operation requires an absolute workspace and agent preset');
308
+ }
309
+ return { workspace, agentPreset };
310
+ }
311
+ assertActive() {
312
+ if (!this.active)
313
+ throw new PersonalMemoryError('disposed', 'personal-memory service is disposed');
314
+ }
315
+ }
316
+ //# sourceMappingURL=service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AACtC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAEtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,MAAM,MAAM,0BAA0B,CAAA;AAG7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAA;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAmEhD,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IACvB;IAArB,YAAqB,IAA6B,EAAE,OAAe;QACjE,KAAK,CAAC,OAAO,CAAC,CAAA;QADK,SAAI,GAAJ,IAAI,CAAyB;QAEhD,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAA;IACnC,CAAC;CACF;AAED,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC;IACjC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACxC,YAAY,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,sBAAsB,EAAE,mBAAmB,CAAU,CAAC;SAC/E,OAAO,CAAC,mBAAmB,CAAC;IAC/B,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;IAC9D,qBAAqB,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC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AAA;QACpD,IAAI,SAAS,KAAK,SAAS,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,WAAW,KAAK,SAAS,IAAI,WAAW,KAAK,EAAE,EAAE,CAAC;YACzG,MAAM,IAAI,mBAAmB,CAAC,kBAAkB,EAAE,kEAAkE,CAAC,CAAA;QACvH,CAAC;QACD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,CAAA;IACnC,CAAC;IAEO,YAAY;QAClB,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,mBAAmB,CAAC,UAAU,EAAE,qCAAqC,CAAC,CAAA;IACpG,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { DatabaseSync } from 'node:sqlite';
2
+ export declare const memorySchemaVersion = 2;
3
+ export declare class MemoryDatabaseError extends Error {
4
+ readonly code: 'invalid-path' | 'schema-too-new';
5
+ constructor(code: 'invalid-path' | 'schema-too-new', message: string);
6
+ }
7
+ export declare function openMemoryDatabase(path: string): DatabaseSync;
8
+ //# sourceMappingURL=sqlite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../src/sqlite.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1C,eAAO,MAAM,mBAAmB,IAAI,CAAA;AAEpC,qBAAa,mBAAoB,SAAQ,KAAK;IAE1C,QAAQ,CAAC,IAAI,EAAE,cAAc,GAAG,gBAAgB;gBAAvC,IAAI,EAAE,cAAc,GAAG,gBAAgB,EAChD,OAAO,EAAE,MAAM;CAKlB;AAwJD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAoB7D"}
package/lib/sqlite.js ADDED
@@ -0,0 +1,181 @@
1
+ import { chmodSync, mkdirSync } from 'node:fs';
2
+ import { dirname, isAbsolute } from 'node:path';
3
+ import { DatabaseSync } from 'node:sqlite';
4
+ export const memorySchemaVersion = 2;
5
+ export class MemoryDatabaseError extends Error {
6
+ code;
7
+ constructor(code, message) {
8
+ super(message);
9
+ this.code = code;
10
+ this.name = 'MemoryDatabaseError';
11
+ }
12
+ }
13
+ function migrate(database) {
14
+ const row = database.prepare('PRAGMA user_version').get();
15
+ if (row.user_version > memorySchemaVersion) {
16
+ throw new MemoryDatabaseError('schema-too-new', `memory schema ${row.user_version} is newer than supported schema ${memorySchemaVersion}`);
17
+ }
18
+ if (row.user_version === memorySchemaVersion)
19
+ return;
20
+ if (row.user_version === 0) {
21
+ database.exec(`
22
+ BEGIN IMMEDIATE;
23
+
24
+ CREATE TABLE schema_meta (
25
+ key TEXT PRIMARY KEY,
26
+ value TEXT NOT NULL
27
+ ) STRICT;
28
+
29
+ CREATE TABLE memory_records (
30
+ id TEXT PRIMARY KEY,
31
+ owner TEXT NOT NULL CHECK (owner IN ('user', 'agent')),
32
+ scope TEXT NOT NULL CHECK (scope IN ('user-global', 'workspace')),
33
+ workspace TEXT NOT NULL,
34
+ agent_preset TEXT NOT NULL,
35
+ kind TEXT NOT NULL CHECK (kind IN ('fact', 'preference', 'instruction', 'experience')),
36
+ content TEXT NOT NULL,
37
+ content_hash TEXT NOT NULL,
38
+ sensitivity TEXT NOT NULL CHECK (sensitivity IN ('private', 'sensitive')),
39
+ trust TEXT NOT NULL CHECK (trust IN ('user-confirmed', 'agent-observed', 'external')),
40
+ confidence REAL NOT NULL CHECK (confidence >= 0 AND confidence <= 1),
41
+ provenance_json TEXT NOT NULL,
42
+ supersedes TEXT,
43
+ expires_at INTEGER,
44
+ status TEXT NOT NULL CHECK (status IN ('active', 'removed')),
45
+ created_at INTEGER NOT NULL,
46
+ updated_at INTEGER NOT NULL,
47
+ version INTEGER NOT NULL CHECK (version >= 1)
48
+ ) STRICT;
49
+
50
+ CREATE INDEX memory_records_scope
51
+ ON memory_records(owner, scope, workspace, agent_preset, status, updated_at DESC);
52
+ CREATE INDEX memory_records_hash
53
+ ON memory_records(owner, scope, workspace, agent_preset, content_hash, status);
54
+
55
+ CREATE TABLE memory_tokens (
56
+ memory_id TEXT NOT NULL,
57
+ token TEXT NOT NULL,
58
+ weight REAL NOT NULL DEFAULT 1,
59
+ PRIMARY KEY (memory_id, token),
60
+ FOREIGN KEY (memory_id) REFERENCES memory_records(id) ON DELETE CASCADE
61
+ ) STRICT;
62
+ CREATE INDEX memory_tokens_token ON memory_tokens(token, memory_id);
63
+
64
+ CREATE TABLE memory_proposals (
65
+ id TEXT PRIMARY KEY,
66
+ policy_proposal_id TEXT NOT NULL UNIQUE,
67
+ idempotency_key TEXT NOT NULL UNIQUE,
68
+ requester TEXT NOT NULL,
69
+ principal TEXT NOT NULL,
70
+ mutation_hash TEXT NOT NULL,
71
+ mutation_json TEXT NOT NULL,
72
+ status TEXT NOT NULL CHECK (status IN ('pending', 'approved', 'rejected', 'expired', 'conflicted')),
73
+ expires_at INTEGER NOT NULL,
74
+ result_memory_id TEXT,
75
+ created_at INTEGER NOT NULL,
76
+ updated_at INTEGER NOT NULL,
77
+ version INTEGER NOT NULL DEFAULT 1
78
+ ) STRICT;
79
+
80
+ CREATE INDEX memory_proposals_reconcile
81
+ ON memory_proposals(status, updated_at, id);
82
+
83
+ CREATE TABLE memory_proposal_intents (
84
+ id TEXT PRIMARY KEY,
85
+ idempotency_key TEXT NOT NULL UNIQUE,
86
+ requester TEXT NOT NULL,
87
+ principal TEXT NOT NULL,
88
+ mutation_hash TEXT NOT NULL,
89
+ mutation_json TEXT NOT NULL,
90
+ ttl_ms INTEGER NOT NULL CHECK (ttl_ms > 0),
91
+ dispatch_source_id TEXT,
92
+ dispatch_binding_id TEXT,
93
+ dispatch_workspace TEXT,
94
+ dispatch_principal TEXT,
95
+ created_at INTEGER NOT NULL,
96
+ updated_at INTEGER NOT NULL,
97
+ CHECK (
98
+ (dispatch_source_id IS NULL AND dispatch_binding_id IS NULL
99
+ AND dispatch_workspace IS NULL AND dispatch_principal IS NULL)
100
+ OR
101
+ (dispatch_source_id IS NOT NULL AND dispatch_binding_id IS NOT NULL
102
+ AND dispatch_workspace IS NOT NULL AND dispatch_principal IS NOT NULL)
103
+ )
104
+ ) STRICT;
105
+
106
+ CREATE INDEX memory_proposal_intents_reconcile
107
+ ON memory_proposal_intents(updated_at, id);
108
+
109
+ CREATE TABLE memory_audit (
110
+ sequence INTEGER PRIMARY KEY AUTOINCREMENT,
111
+ idempotency_key TEXT NOT NULL UNIQUE,
112
+ mutation_hash TEXT NOT NULL,
113
+ operation TEXT NOT NULL,
114
+ memory_id TEXT NOT NULL,
115
+ result_version INTEGER NOT NULL,
116
+ occurred_at INTEGER NOT NULL
117
+ ) STRICT;
118
+
119
+ INSERT INTO schema_meta(key, value) VALUES ('schema-version', '2');
120
+ PRAGMA user_version = 2;
121
+ COMMIT;
122
+ `);
123
+ return;
124
+ }
125
+ database.exec(`
126
+ BEGIN IMMEDIATE;
127
+ CREATE INDEX memory_proposals_reconcile
128
+ ON memory_proposals(status, updated_at, id);
129
+ CREATE TABLE memory_proposal_intents (
130
+ id TEXT PRIMARY KEY,
131
+ idempotency_key TEXT NOT NULL UNIQUE,
132
+ requester TEXT NOT NULL,
133
+ principal TEXT NOT NULL,
134
+ mutation_hash TEXT NOT NULL,
135
+ mutation_json TEXT NOT NULL,
136
+ ttl_ms INTEGER NOT NULL CHECK (ttl_ms > 0),
137
+ dispatch_source_id TEXT,
138
+ dispatch_binding_id TEXT,
139
+ dispatch_workspace TEXT,
140
+ dispatch_principal TEXT,
141
+ created_at INTEGER NOT NULL,
142
+ updated_at INTEGER NOT NULL,
143
+ CHECK (
144
+ (dispatch_source_id IS NULL AND dispatch_binding_id IS NULL
145
+ AND dispatch_workspace IS NULL AND dispatch_principal IS NULL)
146
+ OR
147
+ (dispatch_source_id IS NOT NULL AND dispatch_binding_id IS NOT NULL
148
+ AND dispatch_workspace IS NOT NULL AND dispatch_principal IS NOT NULL)
149
+ )
150
+ ) STRICT;
151
+ CREATE INDEX memory_proposal_intents_reconcile
152
+ ON memory_proposal_intents(updated_at, id);
153
+ UPDATE schema_meta SET value = '2' WHERE key = 'schema-version';
154
+ PRAGMA user_version = 2;
155
+ COMMIT;
156
+ `);
157
+ }
158
+ export function openMemoryDatabase(path) {
159
+ if (path !== ':memory:' && !isAbsolute(path)) {
160
+ throw new MemoryDatabaseError('invalid-path', 'memory database path must be absolute');
161
+ }
162
+ if (path !== ':memory:')
163
+ mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
164
+ const database = new DatabaseSync(path);
165
+ try {
166
+ database.exec('PRAGMA foreign_keys = ON');
167
+ database.exec('PRAGMA busy_timeout = 5000');
168
+ database.exec('PRAGMA synchronous = FULL');
169
+ migrate(database);
170
+ if (path !== ':memory:') {
171
+ database.exec('PRAGMA journal_mode = WAL');
172
+ chmodSync(path, 0o600);
173
+ }
174
+ return database;
175
+ }
176
+ catch (error) {
177
+ database.close();
178
+ throw error;
179
+ }
180
+ }
181
+ //# sourceMappingURL=sqlite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite.js","sourceRoot":"","sources":["../src/sqlite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAC9C,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1C,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAA;AAEpC,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAEjC;IADX,YACW,IAAuC,EAChD,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAA;QAHL,SAAI,GAAJ,IAAI,CAAmC;QAIhD,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAA;IACnC,CAAC;CACF;AAED,SAAS,OAAO,CAAC,QAAsB;IACrC,MAAM,GAAG,GAAG,QAAQ,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC,GAAG,EAA8B,CAAA;IACrF,IAAI,GAAG,CAAC,Y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