@askexenow/exe-os 0.9.38 → 0.9.39

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 (69) hide show
  1. package/dist/bin/backfill-conversations.js +34 -7
  2. package/dist/bin/backfill-responses.js +34 -7
  3. package/dist/bin/backfill-vectors.js +34 -7
  4. package/dist/bin/cleanup-stale-review-tasks.js +35 -8
  5. package/dist/bin/cli.js +72 -42
  6. package/dist/bin/exe-agent.js +11 -3
  7. package/dist/bin/exe-assign.js +34 -7
  8. package/dist/bin/exe-boot.js +48 -18
  9. package/dist/bin/exe-call.js +132 -340
  10. package/dist/bin/exe-dispatch.js +34 -7
  11. package/dist/bin/exe-doctor.js +37 -10
  12. package/dist/bin/exe-export-behaviors.js +36 -9
  13. package/dist/bin/exe-forget.js +34 -7
  14. package/dist/bin/exe-gateway.js +40 -12
  15. package/dist/bin/exe-heartbeat.js +35 -8
  16. package/dist/bin/exe-kill.js +34 -7
  17. package/dist/bin/exe-launch-agent.js +285 -1079
  18. package/dist/bin/exe-new-employee.js +29 -10
  19. package/dist/bin/exe-pending-messages.js +34 -7
  20. package/dist/bin/exe-pending-notifications.js +34 -7
  21. package/dist/bin/exe-pending-reviews.js +34 -7
  22. package/dist/bin/exe-rename.js +41 -13
  23. package/dist/bin/exe-review.js +34 -7
  24. package/dist/bin/exe-search.js +36 -9
  25. package/dist/bin/exe-session-cleanup.js +36 -9
  26. package/dist/bin/exe-start-codex.js +36 -9
  27. package/dist/bin/exe-start-opencode.js +36 -9
  28. package/dist/bin/exe-status.js +35 -8
  29. package/dist/bin/exe-team.js +34 -7
  30. package/dist/bin/git-sweep.js +34 -7
  31. package/dist/bin/graph-backfill.js +34 -7
  32. package/dist/bin/graph-export.js +34 -7
  33. package/dist/bin/install.js +2 -1
  34. package/dist/bin/intercom-check.js +36 -9
  35. package/dist/bin/scan-tasks.js +34 -7
  36. package/dist/bin/setup.js +18 -17
  37. package/dist/bin/shard-migrate.js +34 -7
  38. package/dist/gateway/index.js +38 -10
  39. package/dist/hooks/bug-report-worker.js +38 -10
  40. package/dist/hooks/codex-stop-task-finalizer.js +36 -9
  41. package/dist/hooks/commit-complete.js +34 -7
  42. package/dist/hooks/error-recall.js +36 -9
  43. package/dist/hooks/ingest.js +36 -8
  44. package/dist/hooks/instructions-loaded.js +42 -10
  45. package/dist/hooks/notification.js +34 -7
  46. package/dist/hooks/post-compact.js +34 -7
  47. package/dist/hooks/post-tool-combined.js +37 -10
  48. package/dist/hooks/pre-compact.js +35 -8
  49. package/dist/hooks/pre-tool-use.js +36 -8
  50. package/dist/hooks/prompt-submit.js +41 -13
  51. package/dist/hooks/session-end.js +35 -8
  52. package/dist/hooks/session-start.js +47 -14
  53. package/dist/hooks/stop.js +35 -8
  54. package/dist/hooks/subagent-stop.js +34 -7
  55. package/dist/hooks/summary-worker.js +43 -16
  56. package/dist/index.js +36 -8
  57. package/dist/lib/consolidation.js +2 -1
  58. package/dist/lib/employee-templates.js +2 -1
  59. package/dist/lib/employees.js +2 -1
  60. package/dist/lib/exe-daemon.js +136 -36
  61. package/dist/lib/hybrid-search.js +36 -9
  62. package/dist/lib/identity.js +8 -3
  63. package/dist/lib/schedules.js +34 -7
  64. package/dist/lib/store.js +34 -7
  65. package/dist/mcp/server.js +133 -33
  66. package/dist/mcp/tools/create-task.js +10 -4
  67. package/dist/runtime/index.js +34 -7
  68. package/dist/tui/App.js +40 -11
  69. package/package.json +1 -1
@@ -3333,7 +3333,7 @@ __export(shard_manager_exports, {
3333
3333
  shardExists: () => shardExists
3334
3334
  });
3335
3335
  import path7 from "path";
3336
- import { existsSync as existsSync7, mkdirSync as mkdirSync2, readdirSync } from "fs";
3336
+ import { existsSync as existsSync7, mkdirSync as mkdirSync2, readdirSync, renameSync as renameSync3, statSync as statSync2 } from "fs";
3337
3337
  import { createClient as createClient2 } from "@libsql/client";
3338
3338
  function initShardManager(encryptionKey) {
3339
3339
  _encryptionKey = encryptionKey;
@@ -3355,7 +3355,7 @@ function getShardClient(projectName) {
3355
3355
  if (!_encryptionKey) {
3356
3356
  throw new Error("Shard manager not initialized. Call initShardManager() first.");
3357
3357
  }
3358
- const safeName = projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
3358
+ const safeName = safeShardName(projectName);
3359
3359
  if (!safeName || safeName === "unknown") {
3360
3360
  throw new Error(`Invalid project name for shard: "${projectName}" (resolved to "${safeName}")`);
3361
3361
  }
@@ -3377,9 +3377,12 @@ function getShardClient(projectName) {
3377
3377
  return client;
3378
3378
  }
3379
3379
  function shardExists(projectName) {
3380
- const safeName = projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
3380
+ const safeName = safeShardName(projectName);
3381
3381
  return existsSync7(path7.join(SHARDS_DIR, `${safeName}.db`));
3382
3382
  }
3383
+ function safeShardName(projectName) {
3384
+ return projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
3385
+ }
3383
3386
  function listShards() {
3384
3387
  if (!existsSync7(SHARDS_DIR)) return [];
3385
3388
  return readdirSync(SHARDS_DIR).filter((f) => f.endsWith(".db")).map((f) => f.replace(".db", ""));
@@ -3473,7 +3476,8 @@ async function ensureShardSchema(client) {
3473
3476
  "ALTER TABLE memories ADD COLUMN token_cost REAL",
3474
3477
  "ALTER TABLE memories ADD COLUMN audience TEXT",
3475
3478
  "ALTER TABLE memories ADD COLUMN language_type TEXT",
3476
- "ALTER TABLE memories ADD COLUMN parent_memory_id TEXT"
3479
+ "ALTER TABLE memories ADD COLUMN parent_memory_id TEXT",
3480
+ "ALTER TABLE memories ADD COLUMN deleted_at TEXT"
3477
3481
  ]) {
3478
3482
  try {
3479
3483
  await client.execute(col);
@@ -3569,9 +3573,32 @@ async function ensureShardSchema(client) {
3569
3573
  }
3570
3574
  }
3571
3575
  async function getReadyShardClient(projectName) {
3572
- const client = getShardClient(projectName);
3573
- await ensureShardSchema(client);
3574
- return client;
3576
+ const safeName = safeShardName(projectName);
3577
+ let client = getShardClient(projectName);
3578
+ try {
3579
+ await ensureShardSchema(client);
3580
+ return client;
3581
+ } catch (err) {
3582
+ const message = err instanceof Error ? err.message : String(err);
3583
+ if (!/SQLITE_NOTADB|file is not a database/i.test(message)) throw err;
3584
+ client.close();
3585
+ _shards.delete(safeName);
3586
+ _shardLastAccess.delete(safeName);
3587
+ const dbPath = path7.join(SHARDS_DIR, `${safeName}.db`);
3588
+ if (existsSync7(dbPath)) {
3589
+ const stat = statSync2(dbPath);
3590
+ const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
3591
+ const archivedPath = path7.join(SHARDS_DIR, `${safeName}.db.broken-${stamp}`);
3592
+ renameSync3(dbPath, archivedPath);
3593
+ process.stderr.write(
3594
+ `[shard-manager] Archived unreadable shard ${safeName}: ${archivedPath} (${stat.size} bytes, mtime ${stat.mtime.toISOString()})
3595
+ `
3596
+ );
3597
+ }
3598
+ client = getShardClient(projectName);
3599
+ await ensureShardSchema(client);
3600
+ return client;
3601
+ }
3575
3602
  }
3576
3603
  function evictLRU() {
3577
3604
  let oldest = null;
@@ -4799,7 +4826,7 @@ __export(intercom_queue_exports, {
4799
4826
  queueIntercom: () => queueIntercom,
4800
4827
  readQueue: () => readQueue
4801
4828
  });
4802
- import { readFileSync as readFileSync6, writeFileSync as writeFileSync4, renameSync as renameSync3, existsSync as existsSync9, mkdirSync as mkdirSync3 } from "fs";
4829
+ import { readFileSync as readFileSync6, writeFileSync as writeFileSync4, renameSync as renameSync4, existsSync as existsSync9, mkdirSync as mkdirSync3 } from "fs";
4803
4830
  import path10 from "path";
4804
4831
  import os7 from "os";
4805
4832
  function ensureDir() {
@@ -4818,7 +4845,7 @@ function writeQueue(queue) {
4818
4845
  ensureDir();
4819
4846
  const tmp = `${QUEUE_PATH}.tmp`;
4820
4847
  writeFileSync4(tmp, JSON.stringify(queue, null, 2));
4821
- renameSync3(tmp, QUEUE_PATH);
4848
+ renameSync4(tmp, QUEUE_PATH);
4822
4849
  }
4823
4850
  function queueIntercom(targetSession, reason) {
4824
4851
  const queue = readQueue();
@@ -6949,7 +6949,7 @@ __export(shard_manager_exports, {
6949
6949
  shardExists: () => shardExists
6950
6950
  });
6951
6951
  import path19 from "path";
6952
- import { existsSync as existsSync16, mkdirSync as mkdirSync7, readdirSync as readdirSync4 } from "fs";
6952
+ import { existsSync as existsSync16, mkdirSync as mkdirSync7, readdirSync as readdirSync4, renameSync as renameSync4, statSync as statSync2 } from "fs";
6953
6953
  import { createClient as createClient2 } from "@libsql/client";
6954
6954
  function initShardManager(encryptionKey) {
6955
6955
  _encryptionKey = encryptionKey;
@@ -6971,7 +6971,7 @@ function getShardClient(projectName) {
6971
6971
  if (!_encryptionKey) {
6972
6972
  throw new Error("Shard manager not initialized. Call initShardManager() first.");
6973
6973
  }
6974
- const safeName = projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
6974
+ const safeName = safeShardName(projectName);
6975
6975
  if (!safeName || safeName === "unknown") {
6976
6976
  throw new Error(`Invalid project name for shard: "${projectName}" (resolved to "${safeName}")`);
6977
6977
  }
@@ -6993,9 +6993,12 @@ function getShardClient(projectName) {
6993
6993
  return client;
6994
6994
  }
6995
6995
  function shardExists(projectName) {
6996
- const safeName = projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
6996
+ const safeName = safeShardName(projectName);
6997
6997
  return existsSync16(path19.join(SHARDS_DIR, `${safeName}.db`));
6998
6998
  }
6999
+ function safeShardName(projectName) {
7000
+ return projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
7001
+ }
6999
7002
  function listShards() {
7000
7003
  if (!existsSync16(SHARDS_DIR)) return [];
7001
7004
  return readdirSync4(SHARDS_DIR).filter((f) => f.endsWith(".db")).map((f) => f.replace(".db", ""));
@@ -7089,7 +7092,8 @@ async function ensureShardSchema(client) {
7089
7092
  "ALTER TABLE memories ADD COLUMN token_cost REAL",
7090
7093
  "ALTER TABLE memories ADD COLUMN audience TEXT",
7091
7094
  "ALTER TABLE memories ADD COLUMN language_type TEXT",
7092
- "ALTER TABLE memories ADD COLUMN parent_memory_id TEXT"
7095
+ "ALTER TABLE memories ADD COLUMN parent_memory_id TEXT",
7096
+ "ALTER TABLE memories ADD COLUMN deleted_at TEXT"
7093
7097
  ]) {
7094
7098
  try {
7095
7099
  await client.execute(col);
@@ -7185,9 +7189,32 @@ async function ensureShardSchema(client) {
7185
7189
  }
7186
7190
  }
7187
7191
  async function getReadyShardClient(projectName) {
7188
- const client = getShardClient(projectName);
7189
- await ensureShardSchema(client);
7190
- return client;
7192
+ const safeName = safeShardName(projectName);
7193
+ let client = getShardClient(projectName);
7194
+ try {
7195
+ await ensureShardSchema(client);
7196
+ return client;
7197
+ } catch (err) {
7198
+ const message = err instanceof Error ? err.message : String(err);
7199
+ if (!/SQLITE_NOTADB|file is not a database/i.test(message)) throw err;
7200
+ client.close();
7201
+ _shards.delete(safeName);
7202
+ _shardLastAccess.delete(safeName);
7203
+ const dbPath = path19.join(SHARDS_DIR, `${safeName}.db`);
7204
+ if (existsSync16(dbPath)) {
7205
+ const stat = statSync2(dbPath);
7206
+ const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
7207
+ const archivedPath = path19.join(SHARDS_DIR, `${safeName}.db.broken-${stamp}`);
7208
+ renameSync4(dbPath, archivedPath);
7209
+ process.stderr.write(
7210
+ `[shard-manager] Archived unreadable shard ${safeName}: ${archivedPath} (${stat.size} bytes, mtime ${stat.mtime.toISOString()})
7211
+ `
7212
+ );
7213
+ }
7214
+ client = getShardClient(projectName);
7215
+ await ensureShardSchema(client);
7216
+ return client;
7217
+ }
7191
7218
  }
7192
7219
  function evictLRU() {
7193
7220
  let oldest = null;
@@ -3241,7 +3241,7 @@ __export(shard_manager_exports, {
3241
3241
  shardExists: () => shardExists
3242
3242
  });
3243
3243
  import path7 from "path";
3244
- import { existsSync as existsSync7, mkdirSync as mkdirSync2, readdirSync } from "fs";
3244
+ import { existsSync as existsSync7, mkdirSync as mkdirSync2, readdirSync, renameSync as renameSync3, statSync as statSync2 } from "fs";
3245
3245
  import { createClient as createClient2 } from "@libsql/client";
3246
3246
  function initShardManager(encryptionKey) {
3247
3247
  _encryptionKey = encryptionKey;
@@ -3263,7 +3263,7 @@ function getShardClient(projectName) {
3263
3263
  if (!_encryptionKey) {
3264
3264
  throw new Error("Shard manager not initialized. Call initShardManager() first.");
3265
3265
  }
3266
- const safeName = projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
3266
+ const safeName = safeShardName(projectName);
3267
3267
  if (!safeName || safeName === "unknown") {
3268
3268
  throw new Error(`Invalid project name for shard: "${projectName}" (resolved to "${safeName}")`);
3269
3269
  }
@@ -3285,9 +3285,12 @@ function getShardClient(projectName) {
3285
3285
  return client;
3286
3286
  }
3287
3287
  function shardExists(projectName) {
3288
- const safeName = projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
3288
+ const safeName = safeShardName(projectName);
3289
3289
  return existsSync7(path7.join(SHARDS_DIR, `${safeName}.db`));
3290
3290
  }
3291
+ function safeShardName(projectName) {
3292
+ return projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
3293
+ }
3291
3294
  function listShards() {
3292
3295
  if (!existsSync7(SHARDS_DIR)) return [];
3293
3296
  return readdirSync(SHARDS_DIR).filter((f) => f.endsWith(".db")).map((f) => f.replace(".db", ""));
@@ -3381,7 +3384,8 @@ async function ensureShardSchema(client) {
3381
3384
  "ALTER TABLE memories ADD COLUMN token_cost REAL",
3382
3385
  "ALTER TABLE memories ADD COLUMN audience TEXT",
3383
3386
  "ALTER TABLE memories ADD COLUMN language_type TEXT",
3384
- "ALTER TABLE memories ADD COLUMN parent_memory_id TEXT"
3387
+ "ALTER TABLE memories ADD COLUMN parent_memory_id TEXT",
3388
+ "ALTER TABLE memories ADD COLUMN deleted_at TEXT"
3385
3389
  ]) {
3386
3390
  try {
3387
3391
  await client.execute(col);
@@ -3477,9 +3481,32 @@ async function ensureShardSchema(client) {
3477
3481
  }
3478
3482
  }
3479
3483
  async function getReadyShardClient(projectName) {
3480
- const client = getShardClient(projectName);
3481
- await ensureShardSchema(client);
3482
- return client;
3484
+ const safeName = safeShardName(projectName);
3485
+ let client = getShardClient(projectName);
3486
+ try {
3487
+ await ensureShardSchema(client);
3488
+ return client;
3489
+ } catch (err) {
3490
+ const message = err instanceof Error ? err.message : String(err);
3491
+ if (!/SQLITE_NOTADB|file is not a database/i.test(message)) throw err;
3492
+ client.close();
3493
+ _shards.delete(safeName);
3494
+ _shardLastAccess.delete(safeName);
3495
+ const dbPath = path7.join(SHARDS_DIR, `${safeName}.db`);
3496
+ if (existsSync7(dbPath)) {
3497
+ const stat = statSync2(dbPath);
3498
+ const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
3499
+ const archivedPath = path7.join(SHARDS_DIR, `${safeName}.db.broken-${stamp}`);
3500
+ renameSync3(dbPath, archivedPath);
3501
+ process.stderr.write(
3502
+ `[shard-manager] Archived unreadable shard ${safeName}: ${archivedPath} (${stat.size} bytes, mtime ${stat.mtime.toISOString()})
3503
+ `
3504
+ );
3505
+ }
3506
+ client = getShardClient(projectName);
3507
+ await ensureShardSchema(client);
3508
+ return client;
3509
+ }
3483
3510
  }
3484
3511
  function evictLRU() {
3485
3512
  let oldest = null;
@@ -4754,7 +4781,7 @@ __export(file_grep_exports, {
4754
4781
  grepProjectFiles: () => grepProjectFiles
4755
4782
  });
4756
4783
  import { execSync as execSync4 } from "child_process";
4757
- import { readFileSync as readFileSync5, readdirSync as readdirSync2, statSync as statSync2, existsSync as existsSync9 } from "fs";
4784
+ import { readFileSync as readFileSync5, readdirSync as readdirSync2, statSync as statSync3, existsSync as existsSync9 } from "fs";
4758
4785
  import path10 from "path";
4759
4786
  import crypto3 from "crypto";
4760
4787
  function hasRipgrep() {
@@ -4871,7 +4898,7 @@ function grepWithNodeFs(pattern, projectRoot, patterns) {
4871
4898
  for (const filePath of files.slice(0, MAX_FILES)) {
4872
4899
  const absPath = path10.join(projectRoot, filePath);
4873
4900
  try {
4874
- const stat = statSync2(absPath);
4901
+ const stat = statSync3(absPath);
4875
4902
  if (stat.size > MAX_FILE_SIZE) continue;
4876
4903
  const content = readFileSync5(absPath, "utf8");
4877
4904
  const lines = content.split("\n");
@@ -492,7 +492,8 @@ function isMultiInstance(agentName, employees) {
492
492
  return MULTI_INSTANCE_ROLES.has(emp.role.toLowerCase());
493
493
  }
494
494
  function addEmployee(employees, employee) {
495
- const normalized = { ...employee, name: employee.name.toLowerCase() };
495
+ const { systemPrompt: _legacyPrompt, ...rest } = employee;
496
+ const normalized = { ...rest, name: employee.name.toLowerCase() };
496
497
  if (employees.some((e) => e.name.toLowerCase() === normalized.name)) {
497
498
  throw new Error(`Employee '${normalized.name}' already exists`);
498
499
  }
@@ -3417,7 +3418,7 @@ __export(shard_manager_exports, {
3417
3418
  shardExists: () => shardExists
3418
3419
  });
3419
3420
  import path11 from "path";
3420
- import { existsSync as existsSync10, mkdirSync as mkdirSync5, readdirSync as readdirSync3 } from "fs";
3421
+ import { existsSync as existsSync10, mkdirSync as mkdirSync5, readdirSync as readdirSync3, renameSync as renameSync3, statSync as statSync2 } from "fs";
3421
3422
  import { createClient as createClient2 } from "@libsql/client";
3422
3423
  function initShardManager(encryptionKey) {
3423
3424
  _encryptionKey = encryptionKey;
@@ -3439,7 +3440,7 @@ function getShardClient(projectName) {
3439
3440
  if (!_encryptionKey) {
3440
3441
  throw new Error("Shard manager not initialized. Call initShardManager() first.");
3441
3442
  }
3442
- const safeName = projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
3443
+ const safeName = safeShardName(projectName);
3443
3444
  if (!safeName || safeName === "unknown") {
3444
3445
  throw new Error(`Invalid project name for shard: "${projectName}" (resolved to "${safeName}")`);
3445
3446
  }
@@ -3461,9 +3462,12 @@ function getShardClient(projectName) {
3461
3462
  return client;
3462
3463
  }
3463
3464
  function shardExists(projectName) {
3464
- const safeName = projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
3465
+ const safeName = safeShardName(projectName);
3465
3466
  return existsSync10(path11.join(SHARDS_DIR, `${safeName}.db`));
3466
3467
  }
3468
+ function safeShardName(projectName) {
3469
+ return projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
3470
+ }
3467
3471
  function listShards() {
3468
3472
  if (!existsSync10(SHARDS_DIR)) return [];
3469
3473
  return readdirSync3(SHARDS_DIR).filter((f) => f.endsWith(".db")).map((f) => f.replace(".db", ""));
@@ -3557,7 +3561,8 @@ async function ensureShardSchema(client) {
3557
3561
  "ALTER TABLE memories ADD COLUMN token_cost REAL",
3558
3562
  "ALTER TABLE memories ADD COLUMN audience TEXT",
3559
3563
  "ALTER TABLE memories ADD COLUMN language_type TEXT",
3560
- "ALTER TABLE memories ADD COLUMN parent_memory_id TEXT"
3564
+ "ALTER TABLE memories ADD COLUMN parent_memory_id TEXT",
3565
+ "ALTER TABLE memories ADD COLUMN deleted_at TEXT"
3561
3566
  ]) {
3562
3567
  try {
3563
3568
  await client.execute(col);
@@ -3653,9 +3658,32 @@ async function ensureShardSchema(client) {
3653
3658
  }
3654
3659
  }
3655
3660
  async function getReadyShardClient(projectName) {
3656
- const client = getShardClient(projectName);
3657
- await ensureShardSchema(client);
3658
- return client;
3661
+ const safeName = safeShardName(projectName);
3662
+ let client = getShardClient(projectName);
3663
+ try {
3664
+ await ensureShardSchema(client);
3665
+ return client;
3666
+ } catch (err) {
3667
+ const message = err instanceof Error ? err.message : String(err);
3668
+ if (!/SQLITE_NOTADB|file is not a database/i.test(message)) throw err;
3669
+ client.close();
3670
+ _shards.delete(safeName);
3671
+ _shardLastAccess.delete(safeName);
3672
+ const dbPath = path11.join(SHARDS_DIR, `${safeName}.db`);
3673
+ if (existsSync10(dbPath)) {
3674
+ const stat = statSync2(dbPath);
3675
+ const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
3676
+ const archivedPath = path11.join(SHARDS_DIR, `${safeName}.db.broken-${stamp}`);
3677
+ renameSync3(dbPath, archivedPath);
3678
+ process.stderr.write(
3679
+ `[shard-manager] Archived unreadable shard ${safeName}: ${archivedPath} (${stat.size} bytes, mtime ${stat.mtime.toISOString()})
3680
+ `
3681
+ );
3682
+ }
3683
+ client = getShardClient(projectName);
3684
+ await ensureShardSchema(client);
3685
+ return client;
3686
+ }
3659
3687
  }
3660
3688
  function evictLRU() {
3661
3689
  let oldest = null;
@@ -3252,7 +3252,7 @@ __export(shard_manager_exports, {
3252
3252
  shardExists: () => shardExists
3253
3253
  });
3254
3254
  import path9 from "path";
3255
- import { existsSync as existsSync8, mkdirSync as mkdirSync4, readdirSync as readdirSync3 } from "fs";
3255
+ import { existsSync as existsSync8, mkdirSync as mkdirSync4, readdirSync as readdirSync3, renameSync as renameSync3, statSync as statSync2 } from "fs";
3256
3256
  import { createClient as createClient2 } from "@libsql/client";
3257
3257
  function initShardManager(encryptionKey) {
3258
3258
  _encryptionKey = encryptionKey;
@@ -3274,7 +3274,7 @@ function getShardClient(projectName) {
3274
3274
  if (!_encryptionKey) {
3275
3275
  throw new Error("Shard manager not initialized. Call initShardManager() first.");
3276
3276
  }
3277
- const safeName = projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
3277
+ const safeName = safeShardName(projectName);
3278
3278
  if (!safeName || safeName === "unknown") {
3279
3279
  throw new Error(`Invalid project name for shard: "${projectName}" (resolved to "${safeName}")`);
3280
3280
  }
@@ -3296,9 +3296,12 @@ function getShardClient(projectName) {
3296
3296
  return client;
3297
3297
  }
3298
3298
  function shardExists(projectName) {
3299
- const safeName = projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
3299
+ const safeName = safeShardName(projectName);
3300
3300
  return existsSync8(path9.join(SHARDS_DIR, `${safeName}.db`));
3301
3301
  }
3302
+ function safeShardName(projectName) {
3303
+ return projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
3304
+ }
3302
3305
  function listShards() {
3303
3306
  if (!existsSync8(SHARDS_DIR)) return [];
3304
3307
  return readdirSync3(SHARDS_DIR).filter((f) => f.endsWith(".db")).map((f) => f.replace(".db", ""));
@@ -3392,7 +3395,8 @@ async function ensureShardSchema(client) {
3392
3395
  "ALTER TABLE memories ADD COLUMN token_cost REAL",
3393
3396
  "ALTER TABLE memories ADD COLUMN audience TEXT",
3394
3397
  "ALTER TABLE memories ADD COLUMN language_type TEXT",
3395
- "ALTER TABLE memories ADD COLUMN parent_memory_id TEXT"
3398
+ "ALTER TABLE memories ADD COLUMN parent_memory_id TEXT",
3399
+ "ALTER TABLE memories ADD COLUMN deleted_at TEXT"
3396
3400
  ]) {
3397
3401
  try {
3398
3402
  await client.execute(col);
@@ -3488,9 +3492,32 @@ async function ensureShardSchema(client) {
3488
3492
  }
3489
3493
  }
3490
3494
  async function getReadyShardClient(projectName) {
3491
- const client = getShardClient(projectName);
3492
- await ensureShardSchema(client);
3493
- return client;
3495
+ const safeName = safeShardName(projectName);
3496
+ let client = getShardClient(projectName);
3497
+ try {
3498
+ await ensureShardSchema(client);
3499
+ return client;
3500
+ } catch (err) {
3501
+ const message = err instanceof Error ? err.message : String(err);
3502
+ if (!/SQLITE_NOTADB|file is not a database/i.test(message)) throw err;
3503
+ client.close();
3504
+ _shards.delete(safeName);
3505
+ _shardLastAccess.delete(safeName);
3506
+ const dbPath = path9.join(SHARDS_DIR, `${safeName}.db`);
3507
+ if (existsSync8(dbPath)) {
3508
+ const stat = statSync2(dbPath);
3509
+ const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
3510
+ const archivedPath = path9.join(SHARDS_DIR, `${safeName}.db.broken-${stamp}`);
3511
+ renameSync3(dbPath, archivedPath);
3512
+ process.stderr.write(
3513
+ `[shard-manager] Archived unreadable shard ${safeName}: ${archivedPath} (${stat.size} bytes, mtime ${stat.mtime.toISOString()})
3514
+ `
3515
+ );
3516
+ }
3517
+ client = getShardClient(projectName);
3518
+ await ensureShardSchema(client);
3519
+ return client;
3520
+ }
3494
3521
  }
3495
3522
  function evictLRU() {
3496
3523
  let oldest = null;
@@ -4679,6 +4706,9 @@ function ensureDir() {
4679
4706
  function identityPath(agentId) {
4680
4707
  return path7.join(IDENTITY_DIR2, `${agentId}.md`);
4681
4708
  }
4709
+ function sanitizeIdentityBody(body) {
4710
+ return body.replace(/<!--[\s\S]*?-->/g, "").trim();
4711
+ }
4682
4712
  function parseFrontmatter(raw) {
4683
4713
  const match = raw.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
4684
4714
  if (!match) {
@@ -4691,11 +4721,11 @@ function parseFrontmatter(raw) {
4691
4721
  created_by: "system",
4692
4722
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
4693
4723
  },
4694
- body: raw
4724
+ body: sanitizeIdentityBody(raw)
4695
4725
  };
4696
4726
  }
4697
4727
  const yamlStr = match[1];
4698
- const body = match[2].trim();
4728
+ const body = sanitizeIdentityBody(match[2]);
4699
4729
  const fm = {};
4700
4730
  for (const line of yamlStr.split("\n")) {
4701
4731
  const kv = line.match(/^(\w+):\s*(.+)$/);
@@ -4741,7 +4771,9 @@ function listIdentities() {
4741
4771
  const summary = lines[0]?.trim().slice(0, 120) ?? identity.frontmatter.title;
4742
4772
  results.push({
4743
4773
  agentId,
4744
- title: `${identity.frontmatter.title} (${identity.frontmatter.role.toUpperCase()})`,
4774
+ // User-facing/team-facing title only. `frontmatter.role` is internal
4775
+ // routing metadata and must not leak as an external title.
4776
+ title: identity.frontmatter.title,
4745
4777
  summary
4746
4778
  });
4747
4779
  }
@@ -3252,7 +3252,7 @@ __export(shard_manager_exports, {
3252
3252
  shardExists: () => shardExists
3253
3253
  });
3254
3254
  import path8 from "path";
3255
- import { existsSync as existsSync7, mkdirSync as mkdirSync3, readdirSync as readdirSync2 } from "fs";
3255
+ import { existsSync as existsSync7, mkdirSync as mkdirSync3, readdirSync as readdirSync2, renameSync as renameSync3, statSync as statSync2 } from "fs";
3256
3256
  import { createClient as createClient2 } from "@libsql/client";
3257
3257
  function initShardManager(encryptionKey) {
3258
3258
  _encryptionKey = encryptionKey;
@@ -3274,7 +3274,7 @@ function getShardClient(projectName) {
3274
3274
  if (!_encryptionKey) {
3275
3275
  throw new Error("Shard manager not initialized. Call initShardManager() first.");
3276
3276
  }
3277
- const safeName = projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
3277
+ const safeName = safeShardName(projectName);
3278
3278
  if (!safeName || safeName === "unknown") {
3279
3279
  throw new Error(`Invalid project name for shard: "${projectName}" (resolved to "${safeName}")`);
3280
3280
  }
@@ -3296,9 +3296,12 @@ function getShardClient(projectName) {
3296
3296
  return client;
3297
3297
  }
3298
3298
  function shardExists(projectName) {
3299
- const safeName = projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
3299
+ const safeName = safeShardName(projectName);
3300
3300
  return existsSync7(path8.join(SHARDS_DIR, `${safeName}.db`));
3301
3301
  }
3302
+ function safeShardName(projectName) {
3303
+ return projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
3304
+ }
3302
3305
  function listShards() {
3303
3306
  if (!existsSync7(SHARDS_DIR)) return [];
3304
3307
  return readdirSync2(SHARDS_DIR).filter((f) => f.endsWith(".db")).map((f) => f.replace(".db", ""));
@@ -3392,7 +3395,8 @@ async function ensureShardSchema(client) {
3392
3395
  "ALTER TABLE memories ADD COLUMN token_cost REAL",
3393
3396
  "ALTER TABLE memories ADD COLUMN audience TEXT",
3394
3397
  "ALTER TABLE memories ADD COLUMN language_type TEXT",
3395
- "ALTER TABLE memories ADD COLUMN parent_memory_id TEXT"
3398
+ "ALTER TABLE memories ADD COLUMN parent_memory_id TEXT",
3399
+ "ALTER TABLE memories ADD COLUMN deleted_at TEXT"
3396
3400
  ]) {
3397
3401
  try {
3398
3402
  await client.execute(col);
@@ -3488,9 +3492,32 @@ async function ensureShardSchema(client) {
3488
3492
  }
3489
3493
  }
3490
3494
  async function getReadyShardClient(projectName) {
3491
- const client = getShardClient(projectName);
3492
- await ensureShardSchema(client);
3493
- return client;
3495
+ const safeName = safeShardName(projectName);
3496
+ let client = getShardClient(projectName);
3497
+ try {
3498
+ await ensureShardSchema(client);
3499
+ return client;
3500
+ } catch (err) {
3501
+ const message = err instanceof Error ? err.message : String(err);
3502
+ if (!/SQLITE_NOTADB|file is not a database/i.test(message)) throw err;
3503
+ client.close();
3504
+ _shards.delete(safeName);
3505
+ _shardLastAccess.delete(safeName);
3506
+ const dbPath = path8.join(SHARDS_DIR, `${safeName}.db`);
3507
+ if (existsSync7(dbPath)) {
3508
+ const stat = statSync2(dbPath);
3509
+ const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
3510
+ const archivedPath = path8.join(SHARDS_DIR, `${safeName}.db.broken-${stamp}`);
3511
+ renameSync3(dbPath, archivedPath);
3512
+ process.stderr.write(
3513
+ `[shard-manager] Archived unreadable shard ${safeName}: ${archivedPath} (${stat.size} bytes, mtime ${stat.mtime.toISOString()})
3514
+ `
3515
+ );
3516
+ }
3517
+ client = getShardClient(projectName);
3518
+ await ensureShardSchema(client);
3519
+ return client;
3520
+ }
3494
3521
  }
3495
3522
  function evictLRU() {
3496
3523
  let oldest = null;
@@ -3672,7 +3672,7 @@ __export(shard_manager_exports, {
3672
3672
  shardExists: () => shardExists
3673
3673
  });
3674
3674
  import path14 from "path";
3675
- import { existsSync as existsSync12, mkdirSync as mkdirSync6, readdirSync as readdirSync3 } from "fs";
3675
+ import { existsSync as existsSync12, mkdirSync as mkdirSync6, readdirSync as readdirSync3, renameSync as renameSync4, statSync as statSync2 } from "fs";
3676
3676
  import { createClient as createClient2 } from "@libsql/client";
3677
3677
  function initShardManager(encryptionKey) {
3678
3678
  _encryptionKey = encryptionKey;
@@ -3694,7 +3694,7 @@ function getShardClient(projectName) {
3694
3694
  if (!_encryptionKey) {
3695
3695
  throw new Error("Shard manager not initialized. Call initShardManager() first.");
3696
3696
  }
3697
- const safeName = projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
3697
+ const safeName = safeShardName(projectName);
3698
3698
  if (!safeName || safeName === "unknown") {
3699
3699
  throw new Error(`Invalid project name for shard: "${projectName}" (resolved to "${safeName}")`);
3700
3700
  }
@@ -3716,9 +3716,12 @@ function getShardClient(projectName) {
3716
3716
  return client;
3717
3717
  }
3718
3718
  function shardExists(projectName) {
3719
- const safeName = projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
3719
+ const safeName = safeShardName(projectName);
3720
3720
  return existsSync12(path14.join(SHARDS_DIR, `${safeName}.db`));
3721
3721
  }
3722
+ function safeShardName(projectName) {
3723
+ return projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
3724
+ }
3722
3725
  function listShards() {
3723
3726
  if (!existsSync12(SHARDS_DIR)) return [];
3724
3727
  return readdirSync3(SHARDS_DIR).filter((f) => f.endsWith(".db")).map((f) => f.replace(".db", ""));
@@ -3812,7 +3815,8 @@ async function ensureShardSchema(client) {
3812
3815
  "ALTER TABLE memories ADD COLUMN token_cost REAL",
3813
3816
  "ALTER TABLE memories ADD COLUMN audience TEXT",
3814
3817
  "ALTER TABLE memories ADD COLUMN language_type TEXT",
3815
- "ALTER TABLE memories ADD COLUMN parent_memory_id TEXT"
3818
+ "ALTER TABLE memories ADD COLUMN parent_memory_id TEXT",
3819
+ "ALTER TABLE memories ADD COLUMN deleted_at TEXT"
3816
3820
  ]) {
3817
3821
  try {
3818
3822
  await client.execute(col);
@@ -3908,9 +3912,32 @@ async function ensureShardSchema(client) {
3908
3912
  }
3909
3913
  }
3910
3914
  async function getReadyShardClient(projectName) {
3911
- const client = getShardClient(projectName);
3912
- await ensureShardSchema(client);
3913
- return client;
3915
+ const safeName = safeShardName(projectName);
3916
+ let client = getShardClient(projectName);
3917
+ try {
3918
+ await ensureShardSchema(client);
3919
+ return client;
3920
+ } catch (err) {
3921
+ const message = err instanceof Error ? err.message : String(err);
3922
+ if (!/SQLITE_NOTADB|file is not a database/i.test(message)) throw err;
3923
+ client.close();
3924
+ _shards.delete(safeName);
3925
+ _shardLastAccess.delete(safeName);
3926
+ const dbPath = path14.join(SHARDS_DIR, `${safeName}.db`);
3927
+ if (existsSync12(dbPath)) {
3928
+ const stat = statSync2(dbPath);
3929
+ const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
3930
+ const archivedPath = path14.join(SHARDS_DIR, `${safeName}.db.broken-${stamp}`);
3931
+ renameSync4(dbPath, archivedPath);
3932
+ process.stderr.write(
3933
+ `[shard-manager] Archived unreadable shard ${safeName}: ${archivedPath} (${stat.size} bytes, mtime ${stat.mtime.toISOString()})
3934
+ `
3935
+ );
3936
+ }
3937
+ client = getShardClient(projectName);
3938
+ await ensureShardSchema(client);
3939
+ return client;
3940
+ }
3914
3941
  }
3915
3942
  function evictLRU() {
3916
3943
  let oldest = null;