claude-memory-layer 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +14 -0
- package/.history/package_20260201114632.json +46 -0
- package/dist/cli/index.js +360 -154
- package/dist/cli/index.js.map +4 -4
- package/dist/core/index.js +337 -161
- package/dist/core/index.js.map +3 -3
- package/dist/hooks/session-end.js +320 -130
- package/dist/hooks/session-end.js.map +4 -4
- package/dist/hooks/session-start.js +331 -138
- package/dist/hooks/session-start.js.map +4 -4
- package/dist/hooks/stop.js +320 -130
- package/dist/hooks/stop.js.map +4 -4
- package/dist/hooks/user-prompt-submit.js +320 -130
- package/dist/hooks/user-prompt-submit.js.map +4 -4
- package/dist/services/memory-service.js +349 -128
- package/dist/services/memory-service.js.map +4 -4
- package/package.json +2 -1
- package/src/cli/index.ts +84 -23
- package/src/core/consolidated-store.ts +33 -18
- package/src/core/continuity-manager.ts +12 -7
- package/src/core/db-wrapper.ts +112 -0
- package/src/core/edge-repo.ts +22 -13
- package/src/core/entity-repo.ts +23 -14
- package/src/core/event-store.ts +98 -72
- package/src/core/task/blocker-resolver.ts +17 -9
- package/src/core/task/task-matcher.ts +8 -6
- package/src/core/task/task-projector.ts +29 -16
- package/src/core/task/task-resolver.ts +17 -9
- package/src/core/vector-outbox.ts +29 -16
- package/src/core/vector-store.ts +23 -12
- package/src/core/vector-worker.ts +7 -4
- package/src/core/working-set-store.ts +31 -18
- package/src/hooks/session-end.ts +3 -2
- package/src/hooks/session-start.ts +12 -8
- package/src/hooks/stop.ts +3 -2
- package/src/hooks/user-prompt-submit.ts +3 -2
- package/src/services/memory-service.ts +158 -6
package/src/core/edge-repo.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* AXIOMMIND Entity-Edge Model
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { Database } from '
|
|
6
|
+
import { dbRun, dbAll, toDate, type Database } from './db-wrapper.js';
|
|
7
7
|
import { randomUUID } from 'crypto';
|
|
8
8
|
import type { Edge, NodeType, RelationType } from './types.js';
|
|
9
9
|
|
|
@@ -26,7 +26,8 @@ export class EdgeRepo {
|
|
|
26
26
|
const edgeId = randomUUID();
|
|
27
27
|
const now = new Date();
|
|
28
28
|
|
|
29
|
-
await
|
|
29
|
+
await dbRun(
|
|
30
|
+
this.db,
|
|
30
31
|
`INSERT INTO edges (edge_id, src_type, src_id, rel_type, dst_type, dst_id, meta_json, created_at)
|
|
31
32
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
32
33
|
ON CONFLICT DO NOTHING`,
|
|
@@ -69,7 +70,8 @@ export class EdgeRepo {
|
|
|
69
70
|
|
|
70
71
|
if (existing) {
|
|
71
72
|
// Update meta_json
|
|
72
|
-
await
|
|
73
|
+
await dbRun(
|
|
74
|
+
this.db,
|
|
73
75
|
`UPDATE edges SET meta_json = ? WHERE edge_id = ?`,
|
|
74
76
|
[JSON.stringify(input.metaJson ?? {}), existing.edgeId]
|
|
75
77
|
);
|
|
@@ -89,7 +91,8 @@ export class EdgeRepo {
|
|
|
89
91
|
dstType: NodeType,
|
|
90
92
|
dstId: string
|
|
91
93
|
): Promise<Edge | null> {
|
|
92
|
-
const rows = await
|
|
94
|
+
const rows = await dbAll<Record<string, unknown>>(
|
|
95
|
+
this.db,
|
|
93
96
|
`SELECT * FROM edges
|
|
94
97
|
WHERE src_type = ? AND src_id = ? AND rel_type = ?
|
|
95
98
|
AND dst_type = ? AND dst_id = ?`,
|
|
@@ -117,7 +120,7 @@ export class EdgeRepo {
|
|
|
117
120
|
|
|
118
121
|
query += ` ORDER BY created_at DESC`;
|
|
119
122
|
|
|
120
|
-
const rows = await
|
|
123
|
+
const rows = await dbAll<Record<string, unknown>>(this.db, query, params);
|
|
121
124
|
return rows.map(row => this.rowToEdge(row));
|
|
122
125
|
}
|
|
123
126
|
|
|
@@ -138,7 +141,7 @@ export class EdgeRepo {
|
|
|
138
141
|
|
|
139
142
|
query += ` ORDER BY created_at DESC`;
|
|
140
143
|
|
|
141
|
-
const rows = await
|
|
144
|
+
const rows = await dbAll<Record<string, unknown>>(this.db, query, params);
|
|
142
145
|
return rows.map(row => this.rowToEdge(row));
|
|
143
146
|
}
|
|
144
147
|
|
|
@@ -155,7 +158,8 @@ export class EdgeRepo {
|
|
|
155
158
|
* Delete edge by ID
|
|
156
159
|
*/
|
|
157
160
|
async delete(edgeId: string): Promise<boolean> {
|
|
158
|
-
|
|
161
|
+
await dbRun(
|
|
162
|
+
this.db,
|
|
159
163
|
`DELETE FROM edges WHERE edge_id = ?`,
|
|
160
164
|
[edgeId]
|
|
161
165
|
);
|
|
@@ -166,7 +170,8 @@ export class EdgeRepo {
|
|
|
166
170
|
* Delete edges by source and relation type
|
|
167
171
|
*/
|
|
168
172
|
async deleteBySrcAndRel(srcId: string, relType: RelationType): Promise<number> {
|
|
169
|
-
await
|
|
173
|
+
await dbRun(
|
|
174
|
+
this.db,
|
|
170
175
|
`DELETE FROM edges WHERE src_id = ? AND rel_type = ?`,
|
|
171
176
|
[srcId, relType]
|
|
172
177
|
);
|
|
@@ -177,7 +182,8 @@ export class EdgeRepo {
|
|
|
177
182
|
* Delete edges by destination and relation type
|
|
178
183
|
*/
|
|
179
184
|
async deleteByDstAndRel(dstId: string, relType: RelationType): Promise<number> {
|
|
180
|
-
await
|
|
185
|
+
await dbRun(
|
|
186
|
+
this.db,
|
|
181
187
|
`DELETE FROM edges WHERE dst_id = ? AND rel_type = ?`,
|
|
182
188
|
[dstId, relType]
|
|
183
189
|
);
|
|
@@ -231,7 +237,8 @@ export class EdgeRepo {
|
|
|
231
237
|
|
|
232
238
|
for (const edge of blockerEdges) {
|
|
233
239
|
// Check if blocker has resolves_to edge
|
|
234
|
-
const resolvesTo = await
|
|
240
|
+
const resolvesTo = await dbAll<Record<string, unknown>>(
|
|
241
|
+
this.db,
|
|
235
242
|
`SELECT dst_id FROM edges
|
|
236
243
|
WHERE src_id = ? AND rel_type = 'resolves_to'
|
|
237
244
|
LIMIT 1`,
|
|
@@ -264,7 +271,8 @@ export class EdgeRepo {
|
|
|
264
271
|
viaEntityId: string;
|
|
265
272
|
relationPath: string;
|
|
266
273
|
}>> {
|
|
267
|
-
const rows = await
|
|
274
|
+
const rows = await dbAll<Record<string, unknown>>(
|
|
275
|
+
this.db,
|
|
268
276
|
`WITH first_hop AS (
|
|
269
277
|
SELECT e1.dst_id AS entity_id
|
|
270
278
|
FROM edges e1
|
|
@@ -295,7 +303,8 @@ export class EdgeRepo {
|
|
|
295
303
|
* Count edges by relation type
|
|
296
304
|
*/
|
|
297
305
|
async countByRelType(): Promise<Array<{ relType: string; count: number }>> {
|
|
298
|
-
const rows = await
|
|
306
|
+
const rows = await dbAll<{ rel_type: string; count: number }>(
|
|
307
|
+
this.db,
|
|
299
308
|
`SELECT rel_type, COUNT(*) as count FROM edges GROUP BY rel_type`
|
|
300
309
|
);
|
|
301
310
|
return rows.map(row => ({
|
|
@@ -318,7 +327,7 @@ export class EdgeRepo {
|
|
|
318
327
|
metaJson: typeof row.meta_json === 'string'
|
|
319
328
|
? JSON.parse(row.meta_json)
|
|
320
329
|
: row.meta_json as Record<string, unknown> | undefined,
|
|
321
|
-
createdAt:
|
|
330
|
+
createdAt: toDate(row.created_at)
|
|
322
331
|
};
|
|
323
332
|
}
|
|
324
333
|
}
|
package/src/core/entity-repo.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* AXIOMMIND Principle 5: Task is Entity
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { Database } from '
|
|
6
|
+
import { dbRun, dbAll, toDate, type Database } from './db-wrapper.js';
|
|
7
7
|
import { randomUUID } from 'crypto';
|
|
8
8
|
import type {
|
|
9
9
|
Entity,
|
|
@@ -48,7 +48,8 @@ export class EntityRepo {
|
|
|
48
48
|
|
|
49
49
|
const now = new Date();
|
|
50
50
|
|
|
51
|
-
await
|
|
51
|
+
await dbRun(
|
|
52
|
+
this.db,
|
|
52
53
|
`INSERT INTO entities (
|
|
53
54
|
entity_id, entity_type, canonical_key, title, stage, status,
|
|
54
55
|
current_json, title_norm, search_text, created_at, updated_at
|
|
@@ -69,7 +70,8 @@ export class EntityRepo {
|
|
|
69
70
|
);
|
|
70
71
|
|
|
71
72
|
// Create primary alias
|
|
72
|
-
await
|
|
73
|
+
await dbRun(
|
|
74
|
+
this.db,
|
|
73
75
|
`INSERT INTO entity_aliases (entity_type, canonical_key, entity_id, is_primary)
|
|
74
76
|
VALUES (?, ?, ?, TRUE)
|
|
75
77
|
ON CONFLICT (entity_type, canonical_key) DO NOTHING`,
|
|
@@ -95,7 +97,8 @@ export class EntityRepo {
|
|
|
95
97
|
* Find entity by ID
|
|
96
98
|
*/
|
|
97
99
|
async findById(entityId: string): Promise<Entity | null> {
|
|
98
|
-
const rows = await
|
|
100
|
+
const rows = await dbAll<Record<string, unknown>>(
|
|
101
|
+
this.db,
|
|
99
102
|
`SELECT * FROM entities WHERE entity_id = ?`,
|
|
100
103
|
[entityId]
|
|
101
104
|
);
|
|
@@ -111,7 +114,8 @@ export class EntityRepo {
|
|
|
111
114
|
entityType: EntityType,
|
|
112
115
|
canonicalKey: string
|
|
113
116
|
): Promise<Entity | null> {
|
|
114
|
-
const rows = await
|
|
117
|
+
const rows = await dbAll<Record<string, unknown>>(
|
|
118
|
+
this.db,
|
|
115
119
|
`SELECT * FROM entities
|
|
116
120
|
WHERE entity_type = ? AND canonical_key = ?`,
|
|
117
121
|
[entityType, canonicalKey]
|
|
@@ -170,7 +174,8 @@ export class EntityRepo {
|
|
|
170
174
|
|
|
171
175
|
values.push(entityId);
|
|
172
176
|
|
|
173
|
-
await
|
|
177
|
+
await dbRun(
|
|
178
|
+
this.db,
|
|
174
179
|
`UPDATE entities SET ${updates.join(', ')} WHERE entity_id = ?`,
|
|
175
180
|
values
|
|
176
181
|
);
|
|
@@ -204,7 +209,7 @@ export class EntityRepo {
|
|
|
204
209
|
params.push(options.offset);
|
|
205
210
|
}
|
|
206
211
|
|
|
207
|
-
const rows = await
|
|
212
|
+
const rows = await dbAll<Record<string, unknown>>(this.db, query, params);
|
|
208
213
|
return rows.map(row => this.rowToEntity(row));
|
|
209
214
|
}
|
|
210
215
|
|
|
@@ -232,7 +237,7 @@ export class EntityRepo {
|
|
|
232
237
|
params.push(options.limit);
|
|
233
238
|
}
|
|
234
239
|
|
|
235
|
-
const rows = await
|
|
240
|
+
const rows = await dbAll<Record<string, unknown>>(this.db, sql, params);
|
|
236
241
|
return rows.map(row => this.rowToEntity(row));
|
|
237
242
|
}
|
|
238
243
|
|
|
@@ -240,7 +245,8 @@ export class EntityRepo {
|
|
|
240
245
|
* Get tasks by status
|
|
241
246
|
*/
|
|
242
247
|
async getTasksByStatus(status: string): Promise<Entity[]> {
|
|
243
|
-
const rows = await
|
|
248
|
+
const rows = await dbAll<Record<string, unknown>>(
|
|
249
|
+
this.db,
|
|
244
250
|
`SELECT * FROM entities
|
|
245
251
|
WHERE entity_type = 'task'
|
|
246
252
|
AND json_extract(current_json, '$.status') = ?
|
|
@@ -267,7 +273,8 @@ export class EntityRepo {
|
|
|
267
273
|
}> = [];
|
|
268
274
|
|
|
269
275
|
for (const task of tasks) {
|
|
270
|
-
const blockerEdges = await
|
|
276
|
+
const blockerEdges = await dbAll<Record<string, unknown>>(
|
|
277
|
+
this.db,
|
|
271
278
|
`SELECT e.dst_id, ent.entity_type, ent.title
|
|
272
279
|
FROM edges e
|
|
273
280
|
JOIN entities ent ON ent.entity_id = e.dst_id
|
|
@@ -296,7 +303,8 @@ export class EntityRepo {
|
|
|
296
303
|
canonicalKey: string,
|
|
297
304
|
entityId: string
|
|
298
305
|
): Promise<void> {
|
|
299
|
-
await
|
|
306
|
+
await dbRun(
|
|
307
|
+
this.db,
|
|
300
308
|
`INSERT INTO entity_aliases (entity_type, canonical_key, entity_id, is_primary)
|
|
301
309
|
VALUES (?, ?, ?, FALSE)
|
|
302
310
|
ON CONFLICT (entity_type, canonical_key) DO NOTHING`,
|
|
@@ -308,7 +316,8 @@ export class EntityRepo {
|
|
|
308
316
|
* Find entity by alias
|
|
309
317
|
*/
|
|
310
318
|
async findByAlias(entityType: EntityType, canonicalKey: string): Promise<Entity | null> {
|
|
311
|
-
const rows = await
|
|
319
|
+
const rows = await dbAll<Record<string, unknown>>(
|
|
320
|
+
this.db,
|
|
312
321
|
`SELECT e.* FROM entities e
|
|
313
322
|
JOIN entity_aliases a ON e.entity_id = a.entity_id
|
|
314
323
|
WHERE a.entity_type = ? AND a.canonical_key = ?`,
|
|
@@ -335,8 +344,8 @@ export class EntityRepo {
|
|
|
335
344
|
: row.current_json as Record<string, unknown>,
|
|
336
345
|
titleNorm: row.title_norm as string | undefined,
|
|
337
346
|
searchText: row.search_text as string | undefined,
|
|
338
|
-
createdAt:
|
|
339
|
-
updatedAt:
|
|
347
|
+
createdAt: toDate(row.created_at),
|
|
348
|
+
updatedAt: toDate(row.updated_at)
|
|
340
349
|
};
|
|
341
350
|
}
|
|
342
351
|
}
|