@psiclawops/hypermem 0.1.0 → 0.5.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.
Files changed (93) hide show
  1. package/ARCHITECTURE.md +4 -3
  2. package/README.md +457 -174
  3. package/package.json +15 -5
  4. package/dist/background-indexer.d.ts +0 -117
  5. package/dist/background-indexer.d.ts.map +0 -1
  6. package/dist/background-indexer.js +0 -732
  7. package/dist/compaction-fence.d.ts +0 -89
  8. package/dist/compaction-fence.d.ts.map +0 -1
  9. package/dist/compaction-fence.js +0 -153
  10. package/dist/compositor.d.ts +0 -139
  11. package/dist/compositor.d.ts.map +0 -1
  12. package/dist/compositor.js +0 -1109
  13. package/dist/cross-agent.d.ts +0 -57
  14. package/dist/cross-agent.d.ts.map +0 -1
  15. package/dist/cross-agent.js +0 -254
  16. package/dist/db.d.ts +0 -131
  17. package/dist/db.d.ts.map +0 -1
  18. package/dist/db.js +0 -398
  19. package/dist/desired-state-store.d.ts +0 -100
  20. package/dist/desired-state-store.d.ts.map +0 -1
  21. package/dist/desired-state-store.js +0 -212
  22. package/dist/doc-chunk-store.d.ts +0 -115
  23. package/dist/doc-chunk-store.d.ts.map +0 -1
  24. package/dist/doc-chunk-store.js +0 -278
  25. package/dist/doc-chunker.d.ts +0 -99
  26. package/dist/doc-chunker.d.ts.map +0 -1
  27. package/dist/doc-chunker.js +0 -324
  28. package/dist/episode-store.d.ts +0 -48
  29. package/dist/episode-store.d.ts.map +0 -1
  30. package/dist/episode-store.js +0 -135
  31. package/dist/fact-store.d.ts +0 -57
  32. package/dist/fact-store.d.ts.map +0 -1
  33. package/dist/fact-store.js +0 -175
  34. package/dist/fleet-store.d.ts +0 -144
  35. package/dist/fleet-store.d.ts.map +0 -1
  36. package/dist/fleet-store.js +0 -276
  37. package/dist/hybrid-retrieval.d.ts +0 -60
  38. package/dist/hybrid-retrieval.d.ts.map +0 -1
  39. package/dist/hybrid-retrieval.js +0 -340
  40. package/dist/index.d.ts +0 -611
  41. package/dist/index.d.ts.map +0 -1
  42. package/dist/index.js +0 -1042
  43. package/dist/knowledge-graph.d.ts +0 -110
  44. package/dist/knowledge-graph.d.ts.map +0 -1
  45. package/dist/knowledge-graph.js +0 -305
  46. package/dist/knowledge-store.d.ts +0 -72
  47. package/dist/knowledge-store.d.ts.map +0 -1
  48. package/dist/knowledge-store.js +0 -241
  49. package/dist/library-schema.d.ts +0 -22
  50. package/dist/library-schema.d.ts.map +0 -1
  51. package/dist/library-schema.js +0 -717
  52. package/dist/message-store.d.ts +0 -76
  53. package/dist/message-store.d.ts.map +0 -1
  54. package/dist/message-store.js +0 -273
  55. package/dist/preference-store.d.ts +0 -54
  56. package/dist/preference-store.d.ts.map +0 -1
  57. package/dist/preference-store.js +0 -109
  58. package/dist/preservation-gate.d.ts +0 -82
  59. package/dist/preservation-gate.d.ts.map +0 -1
  60. package/dist/preservation-gate.js +0 -150
  61. package/dist/provider-translator.d.ts +0 -40
  62. package/dist/provider-translator.d.ts.map +0 -1
  63. package/dist/provider-translator.js +0 -349
  64. package/dist/rate-limiter.d.ts +0 -76
  65. package/dist/rate-limiter.d.ts.map +0 -1
  66. package/dist/rate-limiter.js +0 -179
  67. package/dist/redis.d.ts +0 -188
  68. package/dist/redis.d.ts.map +0 -1
  69. package/dist/redis.js +0 -534
  70. package/dist/schema.d.ts +0 -15
  71. package/dist/schema.d.ts.map +0 -1
  72. package/dist/schema.js +0 -203
  73. package/dist/secret-scanner.d.ts +0 -51
  74. package/dist/secret-scanner.d.ts.map +0 -1
  75. package/dist/secret-scanner.js +0 -248
  76. package/dist/seed.d.ts +0 -108
  77. package/dist/seed.d.ts.map +0 -1
  78. package/dist/seed.js +0 -177
  79. package/dist/system-store.d.ts +0 -73
  80. package/dist/system-store.d.ts.map +0 -1
  81. package/dist/system-store.js +0 -182
  82. package/dist/topic-store.d.ts +0 -45
  83. package/dist/topic-store.d.ts.map +0 -1
  84. package/dist/topic-store.js +0 -136
  85. package/dist/types.d.ts +0 -329
  86. package/dist/types.d.ts.map +0 -1
  87. package/dist/types.js +0 -9
  88. package/dist/vector-store.d.ts +0 -132
  89. package/dist/vector-store.d.ts.map +0 -1
  90. package/dist/vector-store.js +0 -498
  91. package/dist/work-store.d.ts +0 -112
  92. package/dist/work-store.d.ts.map +0 -1
  93. package/dist/work-store.js +0 -273
@@ -1,273 +0,0 @@
1
- /**
2
- * HyperMem Work Item Store
3
- *
4
- * Fleet kanban board in SQL. Replaces WORKQUEUE.md.
5
- * Lives in the central library DB.
6
- */
7
- function nowIso() {
8
- return new Date().toISOString();
9
- }
10
- function parseItemRow(row) {
11
- return {
12
- id: row.id,
13
- title: row.title,
14
- description: row.description || null,
15
- status: row.status,
16
- priority: row.priority,
17
- agentId: row.agent_id || null,
18
- createdBy: row.created_by,
19
- domain: row.domain || null,
20
- parentId: row.parent_id || null,
21
- blockedBy: row.blocked_by || null,
22
- sessionKey: row.session_key || null,
23
- createdAt: row.created_at,
24
- updatedAt: row.updated_at,
25
- startedAt: row.started_at || null,
26
- completedAt: row.completed_at || null,
27
- dueAt: row.due_at || null,
28
- metadata: row.metadata ? JSON.parse(row.metadata) : null,
29
- };
30
- }
31
- function parseEventRow(row) {
32
- return {
33
- id: row.id,
34
- workItemId: row.work_item_id,
35
- eventType: row.event_type,
36
- oldStatus: row.old_status || null,
37
- newStatus: row.new_status || null,
38
- agentId: row.agent_id || null,
39
- comment: row.comment || null,
40
- createdAt: row.created_at,
41
- };
42
- }
43
- /**
44
- * Generate a work item ID candidate.
45
- * Uses a 6-hex random suffix (~16.7M daily space).
46
- */
47
- function generateIdCandidate() {
48
- const date = new Date().toISOString().slice(0, 10).replace(/-/g, '');
49
- const suffix = Math.floor(Math.random() * 0xffffff).toString(16).padStart(6, '0');
50
- return `WQ-${date}-${suffix}`;
51
- }
52
- export class WorkStore {
53
- db;
54
- constructor(db) {
55
- this.db = db;
56
- }
57
- /**
58
- * Create a new work item.
59
- */
60
- create(data) {
61
- const now = nowIso();
62
- // Use caller-supplied ID if provided, otherwise generate with retry-on-conflict.
63
- // Random suffix collisions are rare but possible under bulk creation — retry
64
- // up to 10 times before giving up. Each retry picks a new random suffix.
65
- const callerSuppliedId = data.metadata?.id;
66
- let id = callerSuppliedId || generateIdCandidate();
67
- let attempts = 0;
68
- while (attempts < 10) {
69
- const existing = this.db
70
- .prepare('SELECT id FROM work_items WHERE id = ?')
71
- .get(id);
72
- if (!existing)
73
- break;
74
- if (callerSuppliedId) {
75
- throw new Error(`Work item ID already exists: ${id}`);
76
- }
77
- id = generateIdCandidate();
78
- attempts++;
79
- }
80
- this.db.prepare(`
81
- INSERT INTO work_items (id, title, description, status, priority, agent_id,
82
- created_by, domain, parent_id, created_at, updated_at, due_at, metadata)
83
- VALUES (?, ?, ?, 'incoming', ?, ?, ?, ?, ?, ?, ?, ?, ?)
84
- `).run(id, data.title, data.description || null, data.priority || 3, data.agentId || null, data.createdBy, data.domain || null, data.parentId || null, now, now, data.dueAt || null, data.metadata ? JSON.stringify(data.metadata) : null);
85
- this.recordEvent(id, 'created', null, 'incoming', data.createdBy);
86
- return this.getItem(id);
87
- }
88
- /**
89
- * Update the status of a work item.
90
- */
91
- updateStatus(id, newStatus, agentId, comment) {
92
- const now = nowIso();
93
- const current = this.getItem(id);
94
- if (!current)
95
- return null;
96
- const updates = ['status = ?', 'updated_at = ?'];
97
- const params = [newStatus, now];
98
- if (newStatus === 'active' && !current.startedAt) {
99
- updates.push('started_at = ?');
100
- params.push(now);
101
- }
102
- if (newStatus === 'completed' || newStatus === 'cancelled') {
103
- updates.push('completed_at = ?');
104
- params.push(now);
105
- }
106
- params.push(id);
107
- this.db.prepare(`UPDATE work_items SET ${updates.join(', ')} WHERE id = ?`).run(...params);
108
- this.recordEvent(id, 'status_changed', current.status, newStatus, agentId, comment);
109
- return this.getItem(id);
110
- }
111
- /**
112
- * Assign a work item to an agent.
113
- */
114
- assign(id, agentId, assignedBy) {
115
- const now = nowIso();
116
- this.db.prepare('UPDATE work_items SET agent_id = ?, updated_at = ? WHERE id = ?').run(agentId, now, id);
117
- this.recordEvent(id, 'assigned', null, null, assignedBy, `Assigned to ${agentId}`);
118
- return this.getItem(id);
119
- }
120
- /**
121
- * Block a work item.
122
- */
123
- block(id, blockedBy, agentId, reason) {
124
- const now = nowIso();
125
- const current = this.getItem(id);
126
- if (!current)
127
- return null;
128
- this.db.prepare("UPDATE work_items SET status = 'blocked', blocked_by = ?, updated_at = ? WHERE id = ?").run(blockedBy, now, id);
129
- this.recordEvent(id, 'blocked', current.status, 'blocked', agentId, reason || `Blocked by ${blockedBy}`);
130
- return this.getItem(id);
131
- }
132
- /**
133
- * Get a work item by ID.
134
- */
135
- getItem(id) {
136
- const row = this.db.prepare('SELECT * FROM work_items WHERE id = ?')
137
- .get(id);
138
- return row ? parseItemRow(row) : null;
139
- }
140
- /**
141
- * Get active work for an agent.
142
- */
143
- getAgentWork(agentId, status) {
144
- let sql = 'SELECT * FROM work_items WHERE agent_id = ?';
145
- const params = [agentId];
146
- if (status) {
147
- sql += ' AND status = ?';
148
- params.push(status);
149
- }
150
- else {
151
- sql += " AND status NOT IN ('completed', 'cancelled')";
152
- }
153
- sql += ' ORDER BY priority, created_at';
154
- const rows = this.db.prepare(sql).all(...params);
155
- return rows.map(parseItemRow);
156
- }
157
- /**
158
- * Get the fleet kanban — all active work grouped by status.
159
- */
160
- getKanban(opts) {
161
- let sql = "SELECT * FROM work_items WHERE status NOT IN ('completed', 'cancelled')";
162
- const params = [];
163
- if (opts?.domain) {
164
- sql += ' AND domain = ?';
165
- params.push(opts.domain);
166
- }
167
- if (opts?.agentId) {
168
- sql += ' AND agent_id = ?';
169
- params.push(opts.agentId);
170
- }
171
- sql += ' ORDER BY status, priority, created_at';
172
- const rows = this.db.prepare(sql).all(...params);
173
- return rows.map(parseItemRow);
174
- }
175
- /**
176
- * Get blocked items across the fleet.
177
- */
178
- getBlocked() {
179
- const rows = this.db.prepare("SELECT * FROM work_items WHERE status = 'blocked' ORDER BY priority, created_at").all();
180
- return rows.map(parseItemRow);
181
- }
182
- /**
183
- * Get completion stats for the fleet.
184
- */
185
- getStats(opts) {
186
- let sql = 'SELECT status, COUNT(*) as cnt FROM work_items';
187
- const params = [];
188
- const conditions = [];
189
- if (opts?.agentId) {
190
- conditions.push('agent_id = ?');
191
- params.push(opts.agentId);
192
- }
193
- if (opts?.since) {
194
- conditions.push('created_at >= ?');
195
- params.push(opts.since);
196
- }
197
- if (conditions.length)
198
- sql += ' WHERE ' + conditions.join(' AND ');
199
- sql += ' GROUP BY status';
200
- const rows = this.db.prepare(sql).all(...params);
201
- const counts = {};
202
- let total = 0;
203
- for (const r of rows) {
204
- counts[r.status] = r.cnt;
205
- total += r.cnt;
206
- }
207
- // Avg duration for completed items
208
- let avgSql = `
209
- SELECT AVG(julianday(completed_at) - julianday(started_at)) * 24 as avg_hours
210
- FROM work_items WHERE status = 'completed' AND started_at IS NOT NULL
211
- `;
212
- const avgParams = [];
213
- if (opts?.agentId) {
214
- avgSql += ' AND agent_id = ?';
215
- avgParams.push(opts.agentId);
216
- }
217
- if (opts?.since) {
218
- avgSql += ' AND completed_at >= ?';
219
- avgParams.push(opts.since);
220
- }
221
- const avgRow = this.db.prepare(avgSql).get(...avgParams);
222
- return {
223
- total,
224
- incoming: counts['incoming'] || 0,
225
- active: counts['active'] || 0,
226
- blocked: counts['blocked'] || 0,
227
- review: counts['review'] || 0,
228
- completed: counts['completed'] || 0,
229
- cancelled: counts['cancelled'] || 0,
230
- avgDurationHours: avgRow?.avg_hours || null,
231
- };
232
- }
233
- /**
234
- * Get events for a work item.
235
- */
236
- getEvents(workItemId, limit = 50) {
237
- const rows = this.db.prepare('SELECT * FROM work_events WHERE work_item_id = ? ORDER BY created_at DESC LIMIT ?').all(workItemId, limit);
238
- return rows.map(parseEventRow);
239
- }
240
- /**
241
- * Search work items.
242
- */
243
- search(query, limit = 20) {
244
- try {
245
- const rows = this.db.prepare(`
246
- SELECT w.* FROM work_items w
247
- JOIN work_items_fts fts ON w.rowid = fts.rowid
248
- WHERE work_items_fts MATCH ?
249
- ORDER BY rank
250
- LIMIT ?
251
- `).all(query, limit);
252
- return rows.map(parseItemRow);
253
- }
254
- catch {
255
- // FTS fallback
256
- const rows = this.db.prepare(`
257
- SELECT * FROM work_items
258
- WHERE title LIKE ? OR description LIKE ?
259
- ORDER BY priority, created_at DESC
260
- LIMIT ?
261
- `).all(`%${query}%`, `%${query}%`, limit);
262
- return rows.map(parseItemRow);
263
- }
264
- }
265
- // ── Private helpers ─────────────────────────────────────────
266
- recordEvent(workItemId, eventType, oldStatus, newStatus, agentId, comment) {
267
- this.db.prepare(`
268
- INSERT INTO work_events (work_item_id, event_type, old_status, new_status, agent_id, comment, created_at)
269
- VALUES (?, ?, ?, ?, ?, ?, ?)
270
- `).run(workItemId, eventType, oldStatus, newStatus, agentId || null, comment || null, nowIso());
271
- }
272
- }
273
- //# sourceMappingURL=work-store.js.map