@hasna/mementos 0.4.38 → 0.4.41

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 @@
1
+ {"version":3,"file":"memory-lock.d.ts","sourceRoot":"","sources":["../../src/lib/memory-lock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAuC,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAKxF;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,GACxB,MAAM,CAER;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,EACzB,UAAU,SAAmB,EAC7B,EAAE,CAAC,EAAE,QAAQ,GACZ,YAAY,GAAG,IAAI,CAGrB;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,EAAE,CAAC,EAAE,QAAQ,GACZ,OAAO,CAGT;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,EACzB,EAAE,CAAC,EAAE,QAAQ,GACZ,YAAY,GAAG,IAAI,CAIrB;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAC9B,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACpC,EAAE,EAAE,MAAM,CAAC,EACX,UAAU,SAAmB,EAC7B,EAAE,CAAC,EAAE,QAAQ,GACZ,CAAC,CAcH;AAED;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,KAAK;IAChD,SAAgB,QAAQ,EAAG,IAAI,CAAU;IACzC,SAAgB,GAAG,EAAE,MAAM,CAAC;IAC5B,SAAgB,KAAK,EAAE,MAAM,CAAC;IAC9B,SAAgB,iBAAiB,EAAE,MAAM,CAAC;gBAE9B,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM;CAUhE"}
package/dist/mcp/index.js CHANGED
@@ -3989,6 +3989,24 @@ var coerce = {
3989
3989
  };
3990
3990
  var NEVER = INVALID;
3991
3991
  // src/types/index.ts
3992
+ class AgentConflictError extends Error {
3993
+ conflict = true;
3994
+ existing_id;
3995
+ existing_name;
3996
+ last_seen_at;
3997
+ session_hint;
3998
+ working_dir;
3999
+ constructor(opts) {
4000
+ const msg = `Agent "${opts.existing_name}" is already active (session hint: ${opts.session_hint ?? "unknown"}, last seen ${opts.last_seen_at}). Wait 30 minutes or use a different name.`;
4001
+ super(msg);
4002
+ this.name = "AgentConflictError";
4003
+ this.existing_id = opts.existing_id;
4004
+ this.existing_name = opts.existing_name;
4005
+ this.last_seen_at = opts.last_seen_at;
4006
+ this.session_hint = opts.session_hint;
4007
+ this.working_dir = opts.working_dir ?? null;
4008
+ }
4009
+ }
3992
4010
  class EntityNotFoundError extends Error {
3993
4011
  constructor(id) {
3994
4012
  super(`Entity not found: ${id}`);
@@ -4283,6 +4301,28 @@ var MIGRATIONS = [
4283
4301
  ALTER TABLE agents ADD COLUMN active_project_id TEXT REFERENCES projects(id) ON DELETE SET NULL;
4284
4302
  CREATE INDEX IF NOT EXISTS idx_agents_active_project ON agents(active_project_id);
4285
4303
  INSERT OR IGNORE INTO _migrations (id) VALUES (6);
4304
+ `,
4305
+ `
4306
+ ALTER TABLE agents ADD COLUMN session_id TEXT;
4307
+ CREATE INDEX IF NOT EXISTS idx_agents_session ON agents(session_id);
4308
+ INSERT OR IGNORE INTO _migrations (id) VALUES (7);
4309
+ `,
4310
+ `
4311
+ CREATE TABLE IF NOT EXISTS resource_locks (
4312
+ id TEXT PRIMARY KEY,
4313
+ resource_type TEXT NOT NULL CHECK(resource_type IN ('project', 'memory', 'entity', 'agent', 'connector')),
4314
+ resource_id TEXT NOT NULL,
4315
+ agent_id TEXT NOT NULL REFERENCES agents(id) ON DELETE CASCADE,
4316
+ lock_type TEXT NOT NULL DEFAULT 'exclusive' CHECK(lock_type IN ('advisory', 'exclusive')),
4317
+ locked_at TEXT NOT NULL DEFAULT (datetime('now')),
4318
+ expires_at TEXT NOT NULL
4319
+ );
4320
+ CREATE UNIQUE INDEX IF NOT EXISTS idx_resource_locks_exclusive
4321
+ ON resource_locks(resource_type, resource_id)
4322
+ WHERE lock_type = 'exclusive';
4323
+ CREATE INDEX IF NOT EXISTS idx_resource_locks_agent ON resource_locks(agent_id);
4324
+ CREATE INDEX IF NOT EXISTS idx_resource_locks_expires ON resource_locks(expires_at);
4325
+ INSERT OR IGNORE INTO _migrations (id) VALUES (8);
4286
4326
  `
4287
4327
  ];
4288
4328
  var _db = null;
@@ -4365,10 +4405,12 @@ function redactSecrets(text) {
4365
4405
  }
4366
4406
 
4367
4407
  // src/db/agents.ts
4408
+ var CONFLICT_WINDOW_MS = 30 * 60 * 1000;
4368
4409
  function parseAgentRow(row) {
4369
4410
  return {
4370
4411
  id: row["id"],
4371
4412
  name: row["name"],
4413
+ session_id: row["session_id"] || null,
4372
4414
  description: row["description"] || null,
4373
4415
  role: row["role"] || null,
4374
4416
  metadata: JSON.parse(row["metadata"] || "{}"),
@@ -4377,33 +4419,46 @@ function parseAgentRow(row) {
4377
4419
  last_seen_at: row["last_seen_at"]
4378
4420
  };
4379
4421
  }
4380
- function registerAgent(name, description, role, db) {
4422
+ function registerAgent(name, sessionId, description, role, projectId, db) {
4381
4423
  const d = db || getDatabase();
4382
4424
  const timestamp = now();
4383
4425
  const normalizedName = name.trim().toLowerCase();
4384
4426
  const existing = d.query("SELECT * FROM agents WHERE LOWER(name) = ?").get(normalizedName);
4385
4427
  if (existing) {
4386
4428
  const existingId = existing["id"];
4387
- d.run("UPDATE agents SET last_seen_at = ? WHERE id = ?", [
4429
+ const existingSessionId = existing["session_id"] || null;
4430
+ const existingLastSeen = existing["last_seen_at"];
4431
+ if (sessionId && existingSessionId && existingSessionId !== sessionId) {
4432
+ const lastSeenMs = new Date(existingLastSeen).getTime();
4433
+ const nowMs = Date.now();
4434
+ if (nowMs - lastSeenMs < CONFLICT_WINDOW_MS) {
4435
+ throw new AgentConflictError({
4436
+ existing_id: existingId,
4437
+ existing_name: normalizedName,
4438
+ last_seen_at: existingLastSeen,
4439
+ session_hint: existingSessionId.slice(0, 8),
4440
+ working_dir: null
4441
+ });
4442
+ }
4443
+ }
4444
+ d.run("UPDATE agents SET last_seen_at = ?, session_id = ? WHERE id = ?", [
4388
4445
  timestamp,
4446
+ sessionId ?? existingSessionId,
4389
4447
  existingId
4390
4448
  ]);
4391
4449
  if (description) {
4392
- d.run("UPDATE agents SET description = ? WHERE id = ?", [
4393
- description,
4394
- existingId
4395
- ]);
4450
+ d.run("UPDATE agents SET description = ? WHERE id = ?", [description, existingId]);
4396
4451
  }
4397
4452
  if (role) {
4398
- d.run("UPDATE agents SET role = ? WHERE id = ?", [
4399
- role,
4400
- existingId
4401
- ]);
4453
+ d.run("UPDATE agents SET role = ? WHERE id = ?", [role, existingId]);
4454
+ }
4455
+ if (projectId !== undefined) {
4456
+ d.run("UPDATE agents SET active_project_id = ? WHERE id = ?", [projectId, existingId]);
4402
4457
  }
4403
4458
  return getAgent(existingId, d);
4404
4459
  }
4405
4460
  const id = shortUuid();
4406
- d.run("INSERT INTO agents (id, name, description, role, created_at, last_seen_at) VALUES (?, ?, ?, ?, ?, ?)", [id, normalizedName, description || null, role || "agent", timestamp, timestamp]);
4461
+ d.run("INSERT INTO agents (id, name, session_id, description, role, active_project_id, created_at, last_seen_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", [id, normalizedName, sessionId ?? null, description || null, role || "agent", projectId ?? null, timestamp, timestamp]);
4407
4462
  return getAgent(id, d);
4408
4463
  }
4409
4464
  function getAgent(idOrName, db) {
@@ -5433,6 +5488,93 @@ function getMemoryVersions(memoryId, db) {
5433
5488
  }
5434
5489
  }
5435
5490
 
5491
+ // src/db/locks.ts
5492
+ function parseLockRow(row) {
5493
+ return {
5494
+ id: row["id"],
5495
+ resource_type: row["resource_type"],
5496
+ resource_id: row["resource_id"],
5497
+ agent_id: row["agent_id"],
5498
+ lock_type: row["lock_type"],
5499
+ locked_at: row["locked_at"],
5500
+ expires_at: row["expires_at"]
5501
+ };
5502
+ }
5503
+ function acquireLock(agentId, resourceType, resourceId, lockType = "exclusive", ttlSeconds = 300, db) {
5504
+ const d = db || getDatabase();
5505
+ cleanExpiredLocks(d);
5506
+ const ownLock = d.query("SELECT * FROM resource_locks WHERE resource_type = ? AND resource_id = ? AND agent_id = ? AND lock_type = ? AND expires_at > datetime('now')").get(resourceType, resourceId, agentId, lockType);
5507
+ if (ownLock) {
5508
+ const newExpiry = new Date(Date.now() + ttlSeconds * 1000).toISOString();
5509
+ d.run("UPDATE resource_locks SET expires_at = ? WHERE id = ?", [
5510
+ newExpiry,
5511
+ ownLock["id"]
5512
+ ]);
5513
+ return parseLockRow({ ...ownLock, expires_at: newExpiry });
5514
+ }
5515
+ if (lockType === "exclusive") {
5516
+ const existing = d.query("SELECT * FROM resource_locks WHERE resource_type = ? AND resource_id = ? AND lock_type = 'exclusive' AND agent_id != ? AND expires_at > datetime('now')").get(resourceType, resourceId, agentId);
5517
+ if (existing) {
5518
+ return null;
5519
+ }
5520
+ }
5521
+ const id = shortUuid();
5522
+ const lockedAt = now();
5523
+ const expiresAt = new Date(Date.now() + ttlSeconds * 1000).toISOString();
5524
+ d.run("INSERT INTO resource_locks (id, resource_type, resource_id, agent_id, lock_type, locked_at, expires_at) VALUES (?, ?, ?, ?, ?, ?, ?)", [id, resourceType, resourceId, agentId, lockType, lockedAt, expiresAt]);
5525
+ return {
5526
+ id,
5527
+ resource_type: resourceType,
5528
+ resource_id: resourceId,
5529
+ agent_id: agentId,
5530
+ lock_type: lockType,
5531
+ locked_at: lockedAt,
5532
+ expires_at: expiresAt
5533
+ };
5534
+ }
5535
+ function releaseLock(lockId, agentId, db) {
5536
+ const d = db || getDatabase();
5537
+ const result = d.run("DELETE FROM resource_locks WHERE id = ? AND agent_id = ?", [lockId, agentId]);
5538
+ return result.changes > 0;
5539
+ }
5540
+ function checkLock(resourceType, resourceId, lockType, db) {
5541
+ const d = db || getDatabase();
5542
+ cleanExpiredLocks(d);
5543
+ const query = lockType ? "SELECT * FROM resource_locks WHERE resource_type = ? AND resource_id = ? AND lock_type = ? AND expires_at > datetime('now')" : "SELECT * FROM resource_locks WHERE resource_type = ? AND resource_id = ? AND expires_at > datetime('now')";
5544
+ const rows = lockType ? d.query(query).all(resourceType, resourceId, lockType) : d.query(query).all(resourceType, resourceId);
5545
+ return rows.map(parseLockRow);
5546
+ }
5547
+ function listAgentLocks(agentId, db) {
5548
+ const d = db || getDatabase();
5549
+ cleanExpiredLocks(d);
5550
+ const rows = d.query("SELECT * FROM resource_locks WHERE agent_id = ? AND expires_at > datetime('now') ORDER BY locked_at DESC").all(agentId);
5551
+ return rows.map(parseLockRow);
5552
+ }
5553
+ function cleanExpiredLocks(db) {
5554
+ const d = db || getDatabase();
5555
+ const result = d.run("DELETE FROM resource_locks WHERE expires_at <= datetime('now')");
5556
+ return result.changes;
5557
+ }
5558
+
5559
+ // src/lib/memory-lock.ts
5560
+ var MEMORY_WRITE_TTL = 30;
5561
+ function memoryLockId(key, scope, projectId) {
5562
+ return `${scope}:${key}:${projectId ?? ""}`;
5563
+ }
5564
+ function acquireMemoryWriteLock(agentId, key, scope, projectId, ttlSeconds = MEMORY_WRITE_TTL, db) {
5565
+ const d = db || getDatabase();
5566
+ return acquireLock(agentId, "memory", memoryLockId(key, scope, projectId), "exclusive", ttlSeconds, d);
5567
+ }
5568
+ function releaseMemoryWriteLock(lockId, agentId, db) {
5569
+ const d = db || getDatabase();
5570
+ return releaseLock(lockId, agentId, d);
5571
+ }
5572
+ function checkMemoryWriteLock(key, scope, projectId, db) {
5573
+ const d = db || getDatabase();
5574
+ const locks = checkLock("memory", memoryLockId(key, scope, projectId), "exclusive", d);
5575
+ return locks[0] ?? null;
5576
+ }
5577
+
5436
5578
  // src/lib/search.ts
5437
5579
  function parseMemoryRow2(row) {
5438
5580
  return {
@@ -6709,11 +6851,13 @@ ${lines.join(`
6709
6851
  });
6710
6852
  server.tool("register_agent", "Register an agent. Idempotent \u2014 same name returns existing agent.", {
6711
6853
  name: exports_external.string(),
6854
+ session_id: exports_external.string().optional(),
6712
6855
  description: exports_external.string().optional(),
6713
- role: exports_external.string().optional()
6856
+ role: exports_external.string().optional(),
6857
+ project_id: exports_external.string().optional()
6714
6858
  }, async (args) => {
6715
6859
  try {
6716
- const agent = registerAgent(args.name, args.description, args.role);
6860
+ const agent = registerAgent(args.name, args.session_id, args.description, args.role, args.project_id);
6717
6861
  return {
6718
6862
  content: [{
6719
6863
  type: "text",
@@ -7817,6 +7961,103 @@ server.resource("projects", "mementos://projects", { description: "All registere
7817
7961
  const projects = listProjects();
7818
7962
  return { contents: [{ uri: "mementos://projects", text: JSON.stringify(projects, null, 2), mimeType: "application/json" }] };
7819
7963
  });
7964
+ server.tool("memory_lock", "Acquire an exclusive write lock on a memory key to prevent concurrent writes.", {
7965
+ agent_id: exports_external.string(),
7966
+ key: exports_external.string(),
7967
+ scope: exports_external.string().optional().default("shared"),
7968
+ project_id: exports_external.string().optional(),
7969
+ ttl_seconds: exports_external.number().optional().default(30)
7970
+ }, async (args) => {
7971
+ const lock = acquireMemoryWriteLock(args.agent_id, args.key, args.scope, args.project_id, args.ttl_seconds);
7972
+ if (!lock) {
7973
+ const existing = checkMemoryWriteLock(args.key, args.scope, args.project_id);
7974
+ return {
7975
+ content: [{
7976
+ type: "text",
7977
+ text: `Lock conflict: memory key "${args.key}" is write-locked by agent ${existing?.agent_id ?? "unknown"} (expires ${existing?.expires_at ?? "unknown"}). Retry after a few seconds.`
7978
+ }],
7979
+ isError: true
7980
+ };
7981
+ }
7982
+ return {
7983
+ content: [{
7984
+ type: "text",
7985
+ text: `Lock acquired: ${lock.id} on key "${args.key}" (expires ${lock.expires_at})`
7986
+ }]
7987
+ };
7988
+ });
7989
+ server.tool("memory_unlock", "Release a memory write lock.", {
7990
+ lock_id: exports_external.string(),
7991
+ agent_id: exports_external.string()
7992
+ }, async (args) => {
7993
+ const released = releaseMemoryWriteLock(args.lock_id, args.agent_id);
7994
+ return {
7995
+ content: [{
7996
+ type: "text",
7997
+ text: released ? `Lock ${args.lock_id} released.` : `Lock ${args.lock_id} not found or not owned by ${args.agent_id}.`
7998
+ }]
7999
+ };
8000
+ });
8001
+ server.tool("memory_check_lock", "Check if a memory key is currently write-locked.", {
8002
+ key: exports_external.string(),
8003
+ scope: exports_external.string().optional().default("shared"),
8004
+ project_id: exports_external.string().optional()
8005
+ }, async (args) => {
8006
+ const lock = checkMemoryWriteLock(args.key, args.scope, args.project_id);
8007
+ return {
8008
+ content: [{
8009
+ type: "text",
8010
+ text: lock ? `Locked: key "${args.key}" held by agent ${lock.agent_id} (expires ${lock.expires_at})` : `Unlocked: key "${args.key}" is free to write.`
8011
+ }]
8012
+ };
8013
+ });
8014
+ server.tool("resource_lock", "Acquire a lock on any resource (project, memory, entity, agent, connector).", {
8015
+ agent_id: exports_external.string(),
8016
+ resource_type: exports_external.enum(["project", "memory", "entity", "agent", "connector"]),
8017
+ resource_id: exports_external.string(),
8018
+ lock_type: exports_external.enum(["advisory", "exclusive"]).optional().default("exclusive"),
8019
+ ttl_seconds: exports_external.number().optional().default(300)
8020
+ }, async (args) => {
8021
+ const lock = acquireLock(args.agent_id, args.resource_type, args.resource_id, args.lock_type, args.ttl_seconds);
8022
+ if (!lock) {
8023
+ return {
8024
+ content: [{ type: "text", text: `Lock conflict on ${args.resource_type}:${args.resource_id}. Another agent holds an exclusive lock.` }],
8025
+ isError: true
8026
+ };
8027
+ }
8028
+ return {
8029
+ content: [{ type: "text", text: `Lock acquired: ${lock.id} (expires ${lock.expires_at})` }]
8030
+ };
8031
+ });
8032
+ server.tool("resource_unlock", "Release a resource lock.", {
8033
+ lock_id: exports_external.string(),
8034
+ agent_id: exports_external.string()
8035
+ }, async (args) => {
8036
+ const released = releaseLock(args.lock_id, args.agent_id);
8037
+ return {
8038
+ content: [{ type: "text", text: released ? `Released.` : `Not found or not owned.` }]
8039
+ };
8040
+ });
8041
+ server.tool("resource_check_lock", "Check active locks on a resource.", {
8042
+ resource_type: exports_external.enum(["project", "memory", "entity", "agent", "connector"]),
8043
+ resource_id: exports_external.string(),
8044
+ lock_type: exports_external.enum(["advisory", "exclusive"]).optional()
8045
+ }, async (args) => {
8046
+ const locks = checkLock(args.resource_type, args.resource_id, args.lock_type);
8047
+ return {
8048
+ content: [{ type: "text", text: locks.length === 0 ? "No active locks." : JSON.stringify(locks, null, 2) }]
8049
+ };
8050
+ });
8051
+ server.tool("list_agent_locks", "List all active resource locks held by an agent.", { agent_id: exports_external.string() }, async (args) => {
8052
+ const locks = listAgentLocks(args.agent_id);
8053
+ return {
8054
+ content: [{ type: "text", text: locks.length === 0 ? "No active locks." : JSON.stringify(locks, null, 2) }]
8055
+ };
8056
+ });
8057
+ server.tool("clean_expired_locks", "Delete all expired resource locks.", {}, async () => {
8058
+ const count = cleanExpiredLocks();
8059
+ return { content: [{ type: "text", text: `Cleaned ${count} expired lock(s).` }] };
8060
+ });
7820
8061
  async function main() {
7821
8062
  const transport = new StdioServerTransport;
7822
8063
  await server.connect(transport);
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":";AACA;;;GAGG;AAosCH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CA6H9C"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":";AACA;;;GAGG;AAgxCH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CA6H9C"}
@@ -24,6 +24,24 @@ import { dirname as dirname3, extname, join as join3, resolve as resolve3, sep }
24
24
  import { fileURLToPath } from "url";
25
25
 
26
26
  // src/types/index.ts
27
+ class AgentConflictError extends Error {
28
+ conflict = true;
29
+ existing_id;
30
+ existing_name;
31
+ last_seen_at;
32
+ session_hint;
33
+ working_dir;
34
+ constructor(opts) {
35
+ const msg = `Agent "${opts.existing_name}" is already active (session hint: ${opts.session_hint ?? "unknown"}, last seen ${opts.last_seen_at}). Wait 30 minutes or use a different name.`;
36
+ super(msg);
37
+ this.name = "AgentConflictError";
38
+ this.existing_id = opts.existing_id;
39
+ this.existing_name = opts.existing_name;
40
+ this.last_seen_at = opts.last_seen_at;
41
+ this.session_hint = opts.session_hint;
42
+ this.working_dir = opts.working_dir ?? null;
43
+ }
44
+ }
27
45
  class EntityNotFoundError extends Error {
28
46
  constructor(id) {
29
47
  super(`Entity not found: ${id}`);
@@ -311,6 +329,28 @@ var MIGRATIONS = [
311
329
  ALTER TABLE agents ADD COLUMN active_project_id TEXT REFERENCES projects(id) ON DELETE SET NULL;
312
330
  CREATE INDEX IF NOT EXISTS idx_agents_active_project ON agents(active_project_id);
313
331
  INSERT OR IGNORE INTO _migrations (id) VALUES (6);
332
+ `,
333
+ `
334
+ ALTER TABLE agents ADD COLUMN session_id TEXT;
335
+ CREATE INDEX IF NOT EXISTS idx_agents_session ON agents(session_id);
336
+ INSERT OR IGNORE INTO _migrations (id) VALUES (7);
337
+ `,
338
+ `
339
+ CREATE TABLE IF NOT EXISTS resource_locks (
340
+ id TEXT PRIMARY KEY,
341
+ resource_type TEXT NOT NULL CHECK(resource_type IN ('project', 'memory', 'entity', 'agent', 'connector')),
342
+ resource_id TEXT NOT NULL,
343
+ agent_id TEXT NOT NULL REFERENCES agents(id) ON DELETE CASCADE,
344
+ lock_type TEXT NOT NULL DEFAULT 'exclusive' CHECK(lock_type IN ('advisory', 'exclusive')),
345
+ locked_at TEXT NOT NULL DEFAULT (datetime('now')),
346
+ expires_at TEXT NOT NULL
347
+ );
348
+ CREATE UNIQUE INDEX IF NOT EXISTS idx_resource_locks_exclusive
349
+ ON resource_locks(resource_type, resource_id)
350
+ WHERE lock_type = 'exclusive';
351
+ CREATE INDEX IF NOT EXISTS idx_resource_locks_agent ON resource_locks(agent_id);
352
+ CREATE INDEX IF NOT EXISTS idx_resource_locks_expires ON resource_locks(expires_at);
353
+ INSERT OR IGNORE INTO _migrations (id) VALUES (8);
314
354
  `
315
355
  ];
316
356
  var _db = null;
@@ -382,10 +422,12 @@ function redactSecrets(text) {
382
422
  }
383
423
 
384
424
  // src/db/agents.ts
425
+ var CONFLICT_WINDOW_MS = 30 * 60 * 1000;
385
426
  function parseAgentRow(row) {
386
427
  return {
387
428
  id: row["id"],
388
429
  name: row["name"],
430
+ session_id: row["session_id"] || null,
389
431
  description: row["description"] || null,
390
432
  role: row["role"] || null,
391
433
  metadata: JSON.parse(row["metadata"] || "{}"),
@@ -394,33 +436,46 @@ function parseAgentRow(row) {
394
436
  last_seen_at: row["last_seen_at"]
395
437
  };
396
438
  }
397
- function registerAgent(name, description, role, db) {
439
+ function registerAgent(name, sessionId, description, role, projectId, db) {
398
440
  const d = db || getDatabase();
399
441
  const timestamp = now();
400
442
  const normalizedName = name.trim().toLowerCase();
401
443
  const existing = d.query("SELECT * FROM agents WHERE LOWER(name) = ?").get(normalizedName);
402
444
  if (existing) {
403
445
  const existingId = existing["id"];
404
- d.run("UPDATE agents SET last_seen_at = ? WHERE id = ?", [
446
+ const existingSessionId = existing["session_id"] || null;
447
+ const existingLastSeen = existing["last_seen_at"];
448
+ if (sessionId && existingSessionId && existingSessionId !== sessionId) {
449
+ const lastSeenMs = new Date(existingLastSeen).getTime();
450
+ const nowMs = Date.now();
451
+ if (nowMs - lastSeenMs < CONFLICT_WINDOW_MS) {
452
+ throw new AgentConflictError({
453
+ existing_id: existingId,
454
+ existing_name: normalizedName,
455
+ last_seen_at: existingLastSeen,
456
+ session_hint: existingSessionId.slice(0, 8),
457
+ working_dir: null
458
+ });
459
+ }
460
+ }
461
+ d.run("UPDATE agents SET last_seen_at = ?, session_id = ? WHERE id = ?", [
405
462
  timestamp,
463
+ sessionId ?? existingSessionId,
406
464
  existingId
407
465
  ]);
408
466
  if (description) {
409
- d.run("UPDATE agents SET description = ? WHERE id = ?", [
410
- description,
411
- existingId
412
- ]);
467
+ d.run("UPDATE agents SET description = ? WHERE id = ?", [description, existingId]);
413
468
  }
414
469
  if (role) {
415
- d.run("UPDATE agents SET role = ? WHERE id = ?", [
416
- role,
417
- existingId
418
- ]);
470
+ d.run("UPDATE agents SET role = ? WHERE id = ?", [role, existingId]);
471
+ }
472
+ if (projectId !== undefined) {
473
+ d.run("UPDATE agents SET active_project_id = ? WHERE id = ?", [projectId, existingId]);
419
474
  }
420
475
  return getAgent(existingId, d);
421
476
  }
422
477
  const id = shortUuid();
423
- d.run("INSERT INTO agents (id, name, description, role, created_at, last_seen_at) VALUES (?, ?, ?, ?, ?, ?)", [id, normalizedName, description || null, role || "agent", timestamp, timestamp]);
478
+ d.run("INSERT INTO agents (id, name, session_id, description, role, active_project_id, created_at, last_seen_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", [id, normalizedName, sessionId ?? null, description || null, role || "agent", projectId ?? null, timestamp, timestamp]);
424
479
  return getAgent(id, d);
425
480
  }
426
481
  function getAgent(idOrName, db) {
@@ -1496,6 +1551,79 @@ function getMemoryVersions(memoryId, db) {
1496
1551
  }
1497
1552
  }
1498
1553
 
1554
+ // src/db/locks.ts
1555
+ function parseLockRow(row) {
1556
+ return {
1557
+ id: row["id"],
1558
+ resource_type: row["resource_type"],
1559
+ resource_id: row["resource_id"],
1560
+ agent_id: row["agent_id"],
1561
+ lock_type: row["lock_type"],
1562
+ locked_at: row["locked_at"],
1563
+ expires_at: row["expires_at"]
1564
+ };
1565
+ }
1566
+ function acquireLock(agentId, resourceType, resourceId, lockType = "exclusive", ttlSeconds = 300, db) {
1567
+ const d = db || getDatabase();
1568
+ cleanExpiredLocks(d);
1569
+ const ownLock = d.query("SELECT * FROM resource_locks WHERE resource_type = ? AND resource_id = ? AND agent_id = ? AND lock_type = ? AND expires_at > datetime('now')").get(resourceType, resourceId, agentId, lockType);
1570
+ if (ownLock) {
1571
+ const newExpiry = new Date(Date.now() + ttlSeconds * 1000).toISOString();
1572
+ d.run("UPDATE resource_locks SET expires_at = ? WHERE id = ?", [
1573
+ newExpiry,
1574
+ ownLock["id"]
1575
+ ]);
1576
+ return parseLockRow({ ...ownLock, expires_at: newExpiry });
1577
+ }
1578
+ if (lockType === "exclusive") {
1579
+ const existing = d.query("SELECT * FROM resource_locks WHERE resource_type = ? AND resource_id = ? AND lock_type = 'exclusive' AND agent_id != ? AND expires_at > datetime('now')").get(resourceType, resourceId, agentId);
1580
+ if (existing) {
1581
+ return null;
1582
+ }
1583
+ }
1584
+ const id = shortUuid();
1585
+ const lockedAt = now();
1586
+ const expiresAt = new Date(Date.now() + ttlSeconds * 1000).toISOString();
1587
+ d.run("INSERT INTO resource_locks (id, resource_type, resource_id, agent_id, lock_type, locked_at, expires_at) VALUES (?, ?, ?, ?, ?, ?, ?)", [id, resourceType, resourceId, agentId, lockType, lockedAt, expiresAt]);
1588
+ return {
1589
+ id,
1590
+ resource_type: resourceType,
1591
+ resource_id: resourceId,
1592
+ agent_id: agentId,
1593
+ lock_type: lockType,
1594
+ locked_at: lockedAt,
1595
+ expires_at: expiresAt
1596
+ };
1597
+ }
1598
+ function releaseLock(lockId, agentId, db) {
1599
+ const d = db || getDatabase();
1600
+ const result = d.run("DELETE FROM resource_locks WHERE id = ? AND agent_id = ?", [lockId, agentId]);
1601
+ return result.changes > 0;
1602
+ }
1603
+ function releaseAllAgentLocks(agentId, db) {
1604
+ const d = db || getDatabase();
1605
+ const result = d.run("DELETE FROM resource_locks WHERE agent_id = ?", [agentId]);
1606
+ return result.changes;
1607
+ }
1608
+ function checkLock(resourceType, resourceId, lockType, db) {
1609
+ const d = db || getDatabase();
1610
+ cleanExpiredLocks(d);
1611
+ const query = lockType ? "SELECT * FROM resource_locks WHERE resource_type = ? AND resource_id = ? AND lock_type = ? AND expires_at > datetime('now')" : "SELECT * FROM resource_locks WHERE resource_type = ? AND resource_id = ? AND expires_at > datetime('now')";
1612
+ const rows = lockType ? d.query(query).all(resourceType, resourceId, lockType) : d.query(query).all(resourceType, resourceId);
1613
+ return rows.map(parseLockRow);
1614
+ }
1615
+ function listAgentLocks(agentId, db) {
1616
+ const d = db || getDatabase();
1617
+ cleanExpiredLocks(d);
1618
+ const rows = d.query("SELECT * FROM resource_locks WHERE agent_id = ? AND expires_at > datetime('now') ORDER BY locked_at DESC").all(agentId);
1619
+ return rows.map(parseLockRow);
1620
+ }
1621
+ function cleanExpiredLocks(db) {
1622
+ const d = db || getDatabase();
1623
+ const result = d.run("DELETE FROM resource_locks WHERE expires_at <= datetime('now')");
1624
+ return result.changes;
1625
+ }
1626
+
1499
1627
  // src/lib/search.ts
1500
1628
  function parseMemoryRow2(row) {
1501
1629
  return {
@@ -2604,7 +2732,7 @@ addRoute("POST", "/api/agents", async (req) => {
2604
2732
  if (!body || !body["name"]) {
2605
2733
  return errorResponse("Missing required field: name", 400);
2606
2734
  }
2607
- const agent = registerAgent(body["name"], body["description"], body["role"]);
2735
+ const agent = registerAgent(body["name"], body["session_id"], body["description"], body["role"], body["project_id"]);
2608
2736
  return json(agent, 201);
2609
2737
  });
2610
2738
  addRoute("GET", "/api/agents/:id", (_req, _url, params) => {
@@ -2639,6 +2767,47 @@ addRoute("PATCH", "/api/agents/:id", async (req, _url, params) => {
2639
2767
  return errorResponse(e instanceof Error ? e.message : "Update failed", 400);
2640
2768
  }
2641
2769
  });
2770
+ addRoute("POST", "/api/locks", async (req) => {
2771
+ const body = await readJson(req);
2772
+ if (!body?.agent_id || !body?.resource_type || !body?.resource_id) {
2773
+ return errorResponse("Missing required fields: agent_id, resource_type, resource_id", 400);
2774
+ }
2775
+ const lock = acquireLock(body["agent_id"], body["resource_type"], body["resource_id"], body["lock_type"] || "exclusive", body["ttl_seconds"] || 300);
2776
+ if (!lock) {
2777
+ const existing = checkLock(body["resource_type"], body["resource_id"], "exclusive");
2778
+ return errorResponse(`Lock conflict: resource ${body["resource_type"]}:${body["resource_id"]} is held by agent ${existing[0]?.agent_id ?? "unknown"}`, 409);
2779
+ }
2780
+ return json(lock, 201);
2781
+ });
2782
+ addRoute("GET", "/api/locks", (_req, url) => {
2783
+ const resourceType = url.searchParams.get("resource_type");
2784
+ const resourceId = url.searchParams.get("resource_id");
2785
+ const lockType = url.searchParams.get("lock_type");
2786
+ if (!resourceType || !resourceId) {
2787
+ return errorResponse("Missing required query params: resource_type, resource_id", 400);
2788
+ }
2789
+ return json(checkLock(resourceType, resourceId, lockType));
2790
+ });
2791
+ addRoute("DELETE", "/api/locks/:id", async (req, _url, params) => {
2792
+ const body = await readJson(req);
2793
+ if (!body?.agent_id)
2794
+ return errorResponse("Missing required field: agent_id", 400);
2795
+ const released = releaseLock(params["id"], body["agent_id"]);
2796
+ if (!released)
2797
+ return errorResponse("Lock not found or not owned by this agent", 404);
2798
+ return json({ released: true });
2799
+ });
2800
+ addRoute("GET", "/api/agents/:id/locks", (_req, _url, params) => {
2801
+ return json(listAgentLocks(params["id"]));
2802
+ });
2803
+ addRoute("DELETE", "/api/agents/:id/locks", (_req, _url, params) => {
2804
+ const count = releaseAllAgentLocks(params["id"]);
2805
+ return json({ released: count });
2806
+ });
2807
+ addRoute("POST", "/api/locks/clean", () => {
2808
+ const count = cleanExpiredLocks();
2809
+ return json({ cleaned: count });
2810
+ });
2642
2811
  addRoute("GET", "/api/projects", (_req, url) => {
2643
2812
  const q = getSearchParams(url);
2644
2813
  const projects = listProjects();
@@ -85,6 +85,7 @@ export interface MemorySearchResult {
85
85
  export interface Agent {
86
86
  id: string;
87
87
  name: string;
88
+ session_id: string | null;
88
89
  description: string | null;
89
90
  role: string | null;
90
91
  metadata: Record<string, unknown>;
@@ -92,6 +93,22 @@ export interface Agent {
92
93
  created_at: string;
93
94
  last_seen_at: string;
94
95
  }
96
+ export declare class AgentConflictError extends Error {
97
+ readonly conflict: true;
98
+ readonly existing_id: string;
99
+ readonly existing_name: string;
100
+ readonly last_seen_at: string;
101
+ readonly session_hint: string | null;
102
+ readonly working_dir: string | null;
103
+ constructor(opts: {
104
+ existing_id: string;
105
+ existing_name: string;
106
+ last_seen_at: string;
107
+ session_hint: string | null;
108
+ working_dir?: string | null;
109
+ });
110
+ }
111
+ export declare function isAgentConflict(result: unknown): result is AgentConflictError;
95
112
  export interface Project {
96
113
  id: string;
97
114
  name: string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAC;AAM1D,MAAM,MAAM,cAAc,GAAG,YAAY,GAAG,MAAM,GAAG,WAAW,GAAG,SAAS,CAAC;AAM7E,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,UAAU,CAAC;AAM7E,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,UAAU,GAAG,SAAS,CAAC;AAM7D,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,cAAc,CAAC;IACzB,KAAK,EAAE,WAAW,CAAC;IACnB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,YAAY,CAAC;IACrB,MAAM,EAAE,YAAY,CAAC;IACrB,MA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