@hasna/mementos 0.10.5 → 0.10.8

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.
@@ -48,5 +48,16 @@ export declare function listAgentLocks(agentId: string, db?: Database): Resource
48
48
  /**
49
49
  * Delete all expired locks. Called automatically by other lock functions.
50
50
  */
51
+ export interface ExpiredLockInfo {
52
+ id: string;
53
+ resource_type: string;
54
+ resource_id: string;
55
+ agent_id: string;
56
+ lock_type: string;
57
+ }
58
+ /**
59
+ * Clean expired locks and return info about what was cleaned for notification purposes.
60
+ */
61
+ export declare function cleanExpiredLocksWithInfo(db?: Database): ExpiredLockInfo[];
51
62
  export declare function cleanExpiredLocks(db?: Database): number;
52
63
  //# sourceMappingURL=locks.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"locks.d.ts","sourceRoot":"","sources":["../../src/db/locks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGtC,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,GAAG,WAAW,GAAG,MAAM,CAAC;AAC5F,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG,WAAW,CAAC;AAEhD,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,aAAa,EAAE,YAAY,CAAC;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,QAAQ,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB;AAcD;;;;;;;GAOG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,YAAY,EAC1B,UAAU,EAAE,MAAM,EAClB,QAAQ,GAAE,QAAsB,EAChC,UAAU,SAAM,EAChB,EAAE,CAAC,EAAE,QAAQ,GACZ,YAAY,GAAG,IA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,YAAY,GAAG,IAAI,CAcrB;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,QAAQ,GAAG,YAAY,EAAE,CAS7E;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,EAAE,CAAC,EAAE,QAAQ,GAAG,eAAe,EAAE,CAS1E;AAED,wBAAgB,iBAAiB,CAAC,EAAE,CAAC,EAAE,QAAQ,GAAG,MAAM,CAIvD"}
package/dist/mcp/index.js CHANGED
@@ -3257,6 +3257,40 @@ var init_built_in_hooks = __esm(() => {
3257
3257
  });
3258
3258
  });
3259
3259
 
3260
+ // src/mcp/memory-broadcast.ts
3261
+ var exports_memory_broadcast = {};
3262
+ __export(exports_memory_broadcast, {
3263
+ broadcastSharedMemory: () => broadcastSharedMemory
3264
+ });
3265
+ async function broadcastSharedMemory(memory, savingAgentId) {
3266
+ if (!memory.project_id)
3267
+ return;
3268
+ try {
3269
+ const listRes = await fetch(`${CONVERSATIONS_API}/api/v1/agents?active=true&project_id=${memory.project_id}`, {
3270
+ signal: AbortSignal.timeout(3000)
3271
+ });
3272
+ if (!listRes.ok)
3273
+ return;
3274
+ const { agents } = await listRes.json();
3275
+ if (!agents?.length)
3276
+ return;
3277
+ const otherAgents = agents.filter((a) => a.id !== savingAgentId);
3278
+ if (!otherAgents.length)
3279
+ return;
3280
+ const notification = `[Memory Update] Agent ${savingAgentId} saved shared memory: "${memory.key}" \u2014 ${memory.summary || memory.value.slice(0, 100)}. Consider recalling this memory if relevant to your current task.`;
3281
+ await Promise.all(otherAgents.map((agent) => fetch(`${CONVERSATIONS_API}/api/v1/messages`, {
3282
+ method: "POST",
3283
+ headers: { "Content-Type": "application/json" },
3284
+ body: JSON.stringify({ from: savingAgentId, to: agent.id, content: notification }),
3285
+ signal: AbortSignal.timeout(3000)
3286
+ }).catch(() => {})));
3287
+ } catch {}
3288
+ }
3289
+ var CONVERSATIONS_API;
3290
+ var init_memory_broadcast = __esm(() => {
3291
+ CONVERSATIONS_API = process.env.CONVERSATIONS_API_URL || "http://localhost:7020";
3292
+ });
3293
+
3260
3294
  // src/mcp/index.ts
3261
3295
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3262
3296
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
@@ -7483,6 +7517,14 @@ function listAgentLocks(agentId, db) {
7483
7517
  const rows = d.query("SELECT * FROM resource_locks WHERE agent_id = ? AND expires_at > datetime('now') ORDER BY locked_at DESC").all(agentId);
7484
7518
  return rows.map(parseLockRow);
7485
7519
  }
7520
+ function cleanExpiredLocksWithInfo(db) {
7521
+ const d = db || getDatabase();
7522
+ const expired = d.query("SELECT id, resource_type, resource_id, agent_id, lock_type FROM resource_locks WHERE expires_at <= datetime('now')").all();
7523
+ if (expired.length > 0) {
7524
+ d.run("DELETE FROM resource_locks WHERE expires_at <= datetime('now')");
7525
+ }
7526
+ return expired;
7527
+ }
7486
7528
  function cleanExpiredLocks(db) {
7487
7529
  const d = db || getDatabase();
7488
7530
  const result = d.run("DELETE FROM resource_locks WHERE expires_at <= datetime('now')");
@@ -9160,6 +9202,12 @@ server.tool("memory_save", "Save/upsert a memory. scope: global=all agents, shar
9160
9202
  const memory = createMemory(input);
9161
9203
  if (args.agent_id)
9162
9204
  touchAgent(args.agent_id);
9205
+ if (memory.scope === "shared" && memory.project_id && args.agent_id) {
9206
+ try {
9207
+ const { broadcastSharedMemory: broadcastSharedMemory2 } = await Promise.resolve().then(() => (init_memory_broadcast(), exports_memory_broadcast));
9208
+ broadcastSharedMemory2(memory, args.agent_id).catch(() => {});
9209
+ } catch {}
9210
+ }
9163
9211
  return { content: [{ type: "text", text: `Saved: ${memory.key} (${memory.id.slice(0, 8)})` }] };
9164
9212
  } catch (e) {
9165
9213
  return { content: [{ type: "text", text: formatError(e) }], isError: true };
@@ -11144,9 +11192,22 @@ server.tool("list_agent_locks", "List all active resource locks held by an agent
11144
11192
  content: [{ type: "text", text: locks.length === 0 ? "No active locks." : JSON.stringify(locks, null, 2) }]
11145
11193
  };
11146
11194
  });
11147
- server.tool("clean_expired_locks", "Delete all expired resource locks.", {}, async () => {
11148
- const count = cleanExpiredLocks();
11149
- return { content: [{ type: "text", text: `Cleaned ${count} expired lock(s).` }] };
11195
+ server.tool("clean_expired_locks", "Delete all expired resource locks. Notifies holding agents via conversations DM.", {}, async () => {
11196
+ const expired = cleanExpiredLocksWithInfo();
11197
+ const count = expired.length;
11198
+ if (count > 0) {
11199
+ const conversationsUrl = process.env.CONVERSATIONS_API_URL || "http://localhost:7020";
11200
+ for (const lock of expired) {
11201
+ const msg = `Your ${lock.lock_type} lock on ${lock.resource_type}/${lock.resource_id} has expired. Another agent may now acquire it.`;
11202
+ fetch(`${conversationsUrl}/api/v1/messages`, {
11203
+ method: "POST",
11204
+ headers: { "Content-Type": "application/json" },
11205
+ body: JSON.stringify({ from: "system", to: lock.agent_id, content: msg }),
11206
+ signal: AbortSignal.timeout(2000)
11207
+ }).catch(() => {});
11208
+ }
11209
+ }
11210
+ return { content: [{ type: "text", text: `Cleaned ${count} expired lock(s)${count > 0 ? ` and notified ${count} agent(s)` : ""}.` }] };
11150
11211
  });
11151
11212
  server.tool("set_focus", "Set focus for an agent on a project. Memory ops will auto-scope to that project's shared + agent private + global memories.", {
11152
11213
  agent_id: exports_external.string(),
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Memory broadcast utility — notifies active agents when shared memories are saved.
3
+ * Uses the conversations MCP service if available.
4
+ * Non-blocking: failures are silently ignored.
5
+ */
6
+ import type { Memory } from '../types/index.js';
7
+ /**
8
+ * Broadcast a newly saved shared memory to all active agents on the project
9
+ * via the conversations MCP send_message endpoint.
10
+ */
11
+ export declare function broadcastSharedMemory(memory: Memory, savingAgentId: string): Promise<void>;
12
+ //# sourceMappingURL=memory-broadcast.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-broadcast.d.ts","sourceRoot":"","sources":["../../src/mcp/memory-broadcast.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAIhD;;;GAGG;AACH,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA4BhG"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hasna/mementos",
3
- "version": "0.10.5",
3
+ "version": "0.10.8",
4
4
  "description": "Universal memory system for AI agents - CLI + MCP server + library API",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",