@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
@@ -3250,7 +3250,7 @@ __export(shard_manager_exports, {
3250
3250
  shardExists: () => shardExists
3251
3251
  });
3252
3252
  import path7 from "path";
3253
- import { existsSync as existsSync7, mkdirSync as mkdirSync2, readdirSync } from "fs";
3253
+ import { existsSync as existsSync7, mkdirSync as mkdirSync2, readdirSync, renameSync as renameSync3, statSync as statSync2 } from "fs";
3254
3254
  import { createClient as createClient2 } from "@libsql/client";
3255
3255
  function initShardManager(encryptionKey) {
3256
3256
  _encryptionKey = encryptionKey;
@@ -3272,7 +3272,7 @@ function getShardClient(projectName) {
3272
3272
  if (!_encryptionKey) {
3273
3273
  throw new Error("Shard manager not initialized. Call initShardManager() first.");
3274
3274
  }
3275
- const safeName = projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
3275
+ const safeName = safeShardName(projectName);
3276
3276
  if (!safeName || safeName === "unknown") {
3277
3277
  throw new Error(`Invalid project name for shard: "${projectName}" (resolved to "${safeName}")`);
3278
3278
  }
@@ -3294,9 +3294,12 @@ function getShardClient(projectName) {
3294
3294
  return client;
3295
3295
  }
3296
3296
  function shardExists(projectName) {
3297
- const safeName = projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
3297
+ const safeName = safeShardName(projectName);
3298
3298
  return existsSync7(path7.join(SHARDS_DIR, `${safeName}.db`));
3299
3299
  }
3300
+ function safeShardName(projectName) {
3301
+ return projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
3302
+ }
3300
3303
  function listShards() {
3301
3304
  if (!existsSync7(SHARDS_DIR)) return [];
3302
3305
  return readdirSync(SHARDS_DIR).filter((f) => f.endsWith(".db")).map((f) => f.replace(".db", ""));
@@ -3390,7 +3393,8 @@ async function ensureShardSchema(client) {
3390
3393
  "ALTER TABLE memories ADD COLUMN token_cost REAL",
3391
3394
  "ALTER TABLE memories ADD COLUMN audience TEXT",
3392
3395
  "ALTER TABLE memories ADD COLUMN language_type TEXT",
3393
- "ALTER TABLE memories ADD COLUMN parent_memory_id TEXT"
3396
+ "ALTER TABLE memories ADD COLUMN parent_memory_id TEXT",
3397
+ "ALTER TABLE memories ADD COLUMN deleted_at TEXT"
3394
3398
  ]) {
3395
3399
  try {
3396
3400
  await client.execute(col);
@@ -3486,9 +3490,32 @@ async function ensureShardSchema(client) {
3486
3490
  }
3487
3491
  }
3488
3492
  async function getReadyShardClient(projectName) {
3489
- const client = getShardClient(projectName);
3490
- await ensureShardSchema(client);
3491
- return client;
3493
+ const safeName = safeShardName(projectName);
3494
+ let client = getShardClient(projectName);
3495
+ try {
3496
+ await ensureShardSchema(client);
3497
+ return client;
3498
+ } catch (err) {
3499
+ const message = err instanceof Error ? err.message : String(err);
3500
+ if (!/SQLITE_NOTADB|file is not a database/i.test(message)) throw err;
3501
+ client.close();
3502
+ _shards.delete(safeName);
3503
+ _shardLastAccess.delete(safeName);
3504
+ const dbPath = path7.join(SHARDS_DIR, `${safeName}.db`);
3505
+ if (existsSync7(dbPath)) {
3506
+ const stat = statSync2(dbPath);
3507
+ const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
3508
+ const archivedPath = path7.join(SHARDS_DIR, `${safeName}.db.broken-${stamp}`);
3509
+ renameSync3(dbPath, archivedPath);
3510
+ process.stderr.write(
3511
+ `[shard-manager] Archived unreadable shard ${safeName}: ${archivedPath} (${stat.size} bytes, mtime ${stat.mtime.toISOString()})
3512
+ `
3513
+ );
3514
+ }
3515
+ client = getShardClient(projectName);
3516
+ await ensureShardSchema(client);
3517
+ return client;
3518
+ }
3492
3519
  }
3493
3520
  function evictLRU() {
3494
3521
  let oldest = null;
@@ -368,7 +368,8 @@ function isMultiInstance(agentName, employees) {
368
368
  return MULTI_INSTANCE_ROLES.has(emp.role.toLowerCase());
369
369
  }
370
370
  function addEmployee(employees, employee) {
371
- const normalized = { ...employee, name: employee.name.toLowerCase() };
371
+ const { systemPrompt: _legacyPrompt, ...rest } = employee;
372
+ const normalized = { ...rest, name: employee.name.toLowerCase() };
372
373
  if (employees.some((e) => e.name.toLowerCase() === normalized.name)) {
373
374
  throw new Error(`Employee '${normalized.name}' already exists`);
374
375
  }
@@ -3349,7 +3349,7 @@ __export(shard_manager_exports, {
3349
3349
  shardExists: () => shardExists
3350
3350
  });
3351
3351
  import path7 from "path";
3352
- import { existsSync as existsSync7, mkdirSync as mkdirSync2, readdirSync } from "fs";
3352
+ import { existsSync as existsSync7, mkdirSync as mkdirSync2, readdirSync, renameSync as renameSync3, statSync as statSync2 } from "fs";
3353
3353
  import { createClient as createClient2 } from "@libsql/client";
3354
3354
  function initShardManager(encryptionKey) {
3355
3355
  _encryptionKey = encryptionKey;
@@ -3371,7 +3371,7 @@ function getShardClient(projectName) {
3371
3371
  if (!_encryptionKey) {
3372
3372
  throw new Error("Shard manager not initialized. Call initShardManager() first.");
3373
3373
  }
3374
- const safeName = projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
3374
+ const safeName = safeShardName(projectName);
3375
3375
  if (!safeName || safeName === "unknown") {
3376
3376
  throw new Error(`Invalid project name for shard: "${projectName}" (resolved to "${safeName}")`);
3377
3377
  }
@@ -3393,9 +3393,12 @@ function getShardClient(projectName) {
3393
3393
  return client;
3394
3394
  }
3395
3395
  function shardExists(projectName) {
3396
- const safeName = projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
3396
+ const safeName = safeShardName(projectName);
3397
3397
  return existsSync7(path7.join(SHARDS_DIR, `${safeName}.db`));
3398
3398
  }
3399
+ function safeShardName(projectName) {
3400
+ return projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
3401
+ }
3399
3402
  function listShards() {
3400
3403
  if (!existsSync7(SHARDS_DIR)) return [];
3401
3404
  return readdirSync(SHARDS_DIR).filter((f) => f.endsWith(".db")).map((f) => f.replace(".db", ""));
@@ -3489,7 +3492,8 @@ async function ensureShardSchema(client) {
3489
3492
  "ALTER TABLE memories ADD COLUMN token_cost REAL",
3490
3493
  "ALTER TABLE memories ADD COLUMN audience TEXT",
3491
3494
  "ALTER TABLE memories ADD COLUMN language_type TEXT",
3492
- "ALTER TABLE memories ADD COLUMN parent_memory_id TEXT"
3495
+ "ALTER TABLE memories ADD COLUMN parent_memory_id TEXT",
3496
+ "ALTER TABLE memories ADD COLUMN deleted_at TEXT"
3493
3497
  ]) {
3494
3498
  try {
3495
3499
  await client.execute(col);
@@ -3585,9 +3589,32 @@ async function ensureShardSchema(client) {
3585
3589
  }
3586
3590
  }
3587
3591
  async function getReadyShardClient(projectName) {
3588
- const client = getShardClient(projectName);
3589
- await ensureShardSchema(client);
3590
- return client;
3592
+ const safeName = safeShardName(projectName);
3593
+ let client = getShardClient(projectName);
3594
+ try {
3595
+ await ensureShardSchema(client);
3596
+ return client;
3597
+ } catch (err) {
3598
+ const message = err instanceof Error ? err.message : String(err);
3599
+ if (!/SQLITE_NOTADB|file is not a database/i.test(message)) throw err;
3600
+ client.close();
3601
+ _shards.delete(safeName);
3602
+ _shardLastAccess.delete(safeName);
3603
+ const dbPath = path7.join(SHARDS_DIR, `${safeName}.db`);
3604
+ if (existsSync7(dbPath)) {
3605
+ const stat = statSync2(dbPath);
3606
+ const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
3607
+ const archivedPath = path7.join(SHARDS_DIR, `${safeName}.db.broken-${stamp}`);
3608
+ renameSync3(dbPath, archivedPath);
3609
+ process.stderr.write(
3610
+ `[shard-manager] Archived unreadable shard ${safeName}: ${archivedPath} (${stat.size} bytes, mtime ${stat.mtime.toISOString()})
3611
+ `
3612
+ );
3613
+ }
3614
+ client = getShardClient(projectName);
3615
+ await ensureShardSchema(client);
3616
+ return client;
3617
+ }
3591
3618
  }
3592
3619
  function evictLRU() {
3593
3620
  let oldest = null;
@@ -4966,7 +4993,7 @@ __export(intercom_queue_exports, {
4966
4993
  queueIntercom: () => queueIntercom,
4967
4994
  readQueue: () => readQueue
4968
4995
  });
4969
- import { readFileSync as readFileSync7, writeFileSync as writeFileSync5, renameSync as renameSync3, existsSync as existsSync10, mkdirSync as mkdirSync4 } from "fs";
4996
+ import { readFileSync as readFileSync7, writeFileSync as writeFileSync5, renameSync as renameSync4, existsSync as existsSync10, mkdirSync as mkdirSync4 } from "fs";
4970
4997
  import path10 from "path";
4971
4998
  import os7 from "os";
4972
4999
  function ensureDir() {
@@ -4985,7 +5012,7 @@ function writeQueue(queue) {
4985
5012
  ensureDir();
4986
5013
  const tmp = `${QUEUE_PATH}.tmp`;
4987
5014
  writeFileSync5(tmp, JSON.stringify(queue, null, 2));
4988
- renameSync3(tmp, QUEUE_PATH);
5015
+ renameSync4(tmp, QUEUE_PATH);
4989
5016
  }
4990
5017
  function queueIntercom(targetSession, reason) {
4991
5018
  const queue = readQueue();
@@ -6955,7 +6955,7 @@ __export(shard_manager_exports, {
6955
6955
  shardExists: () => shardExists
6956
6956
  });
6957
6957
  import path19 from "path";
6958
- import { existsSync as existsSync16, mkdirSync as mkdirSync7, readdirSync as readdirSync4 } from "fs";
6958
+ import { existsSync as existsSync16, mkdirSync as mkdirSync7, readdirSync as readdirSync4, renameSync as renameSync4, statSync as statSync2 } from "fs";
6959
6959
  import { createClient as createClient2 } from "@libsql/client";
6960
6960
  function initShardManager(encryptionKey) {
6961
6961
  _encryptionKey = encryptionKey;
@@ -6977,7 +6977,7 @@ function getShardClient(projectName) {
6977
6977
  if (!_encryptionKey) {
6978
6978
  throw new Error("Shard manager not initialized. Call initShardManager() first.");
6979
6979
  }
6980
- const safeName = projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
6980
+ const safeName = safeShardName(projectName);
6981
6981
  if (!safeName || safeName === "unknown") {
6982
6982
  throw new Error(`Invalid project name for shard: "${projectName}" (resolved to "${safeName}")`);
6983
6983
  }
@@ -6999,9 +6999,12 @@ function getShardClient(projectName) {
6999
6999
  return client;
7000
7000
  }
7001
7001
  function shardExists(projectName) {
7002
- const safeName = projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
7002
+ const safeName = safeShardName(projectName);
7003
7003
  return existsSync16(path19.join(SHARDS_DIR, `${safeName}.db`));
7004
7004
  }
7005
+ function safeShardName(projectName) {
7006
+ return projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
7007
+ }
7005
7008
  function listShards() {
7006
7009
  if (!existsSync16(SHARDS_DIR)) return [];
7007
7010
  return readdirSync4(SHARDS_DIR).filter((f) => f.endsWith(".db")).map((f) => f.replace(".db", ""));
@@ -7095,7 +7098,8 @@ async function ensureShardSchema(client) {
7095
7098
  "ALTER TABLE memories ADD COLUMN token_cost REAL",
7096
7099
  "ALTER TABLE memories ADD COLUMN audience TEXT",
7097
7100
  "ALTER TABLE memories ADD COLUMN language_type TEXT",
7098
- "ALTER TABLE memories ADD COLUMN parent_memory_id TEXT"
7101
+ "ALTER TABLE memories ADD COLUMN parent_memory_id TEXT",
7102
+ "ALTER TABLE memories ADD COLUMN deleted_at TEXT"
7099
7103
  ]) {
7100
7104
  try {
7101
7105
  await client.execute(col);
@@ -7191,9 +7195,32 @@ async function ensureShardSchema(client) {
7191
7195
  }
7192
7196
  }
7193
7197
  async function getReadyShardClient(projectName) {
7194
- const client = getShardClient(projectName);
7195
- await ensureShardSchema(client);
7196
- return client;
7198
+ const safeName = safeShardName(projectName);
7199
+ let client = getShardClient(projectName);
7200
+ try {
7201
+ await ensureShardSchema(client);
7202
+ return client;
7203
+ } catch (err) {
7204
+ const message = err instanceof Error ? err.message : String(err);
7205
+ if (!/SQLITE_NOTADB|file is not a database/i.test(message)) throw err;
7206
+ client.close();
7207
+ _shards.delete(safeName);
7208
+ _shardLastAccess.delete(safeName);
7209
+ const dbPath = path19.join(SHARDS_DIR, `${safeName}.db`);
7210
+ if (existsSync16(dbPath)) {
7211
+ const stat = statSync2(dbPath);
7212
+ const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
7213
+ const archivedPath = path19.join(SHARDS_DIR, `${safeName}.db.broken-${stamp}`);
7214
+ renameSync4(dbPath, archivedPath);
7215
+ process.stderr.write(
7216
+ `[shard-manager] Archived unreadable shard ${safeName}: ${archivedPath} (${stat.size} bytes, mtime ${stat.mtime.toISOString()})
7217
+ `
7218
+ );
7219
+ }
7220
+ client = getShardClient(projectName);
7221
+ await ensureShardSchema(client);
7222
+ return client;
7223
+ }
7197
7224
  }
7198
7225
  function evictLRU() {
7199
7226
  let oldest = null;
package/dist/bin/setup.js CHANGED
@@ -1955,7 +1955,8 @@ function isMultiInstance(agentName, employees) {
1955
1955
  return MULTI_INSTANCE_ROLES.has(emp.role.toLowerCase());
1956
1956
  }
1957
1957
  function addEmployee(employees, employee) {
1958
- const normalized = { ...employee, name: employee.name.toLowerCase() };
1958
+ const { systemPrompt: _legacyPrompt, ...rest } = employee;
1959
+ const normalized = { ...rest, name: employee.name.toLowerCase() };
1959
1960
  if (employees.some((e) => e.name.toLowerCase() === normalized.name)) {
1960
1961
  throw new Error(`Employee '${normalized.name}' already exists`);
1961
1962
  }
@@ -5843,7 +5844,8 @@ __export(employee_templates_exports, {
5843
5844
  });
5844
5845
  function getSessionPrompt(storedPrompt) {
5845
5846
  const markerIndex = storedPrompt.indexOf(PROCEDURES_MARKER);
5846
- const rolePrompt = markerIndex >= 0 ? storedPrompt.slice(0, markerIndex).trimEnd() : storedPrompt;
5847
+ const withoutProcedures = markerIndex >= 0 ? storedPrompt.slice(0, markerIndex).trimEnd() : storedPrompt;
5848
+ const rolePrompt = withoutProcedures.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/, "").replace(/<!--[\s\S]*?-->/g, "").trimStart();
5847
5849
  const globalBlock = getGlobalProceduresBlock();
5848
5850
  return `${globalBlock}${rolePrompt}
5849
5851
  ${BASE_OPERATING_PROCEDURES}`;
@@ -6466,6 +6468,9 @@ function ensureDir() {
6466
6468
  function identityPath(agentId) {
6467
6469
  return path14.join(IDENTITY_DIR2, `${agentId}.md`);
6468
6470
  }
6471
+ function sanitizeIdentityBody(body) {
6472
+ return body.replace(/<!--[\s\S]*?-->/g, "").trim();
6473
+ }
6469
6474
  function parseFrontmatter(raw) {
6470
6475
  const match = raw.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
6471
6476
  if (!match) {
@@ -6478,11 +6483,11 @@ function parseFrontmatter(raw) {
6478
6483
  created_by: "system",
6479
6484
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
6480
6485
  },
6481
- body: raw
6486
+ body: sanitizeIdentityBody(raw)
6482
6487
  };
6483
6488
  }
6484
6489
  const yamlStr = match[1];
6485
- const body = match[2].trim();
6490
+ const body = sanitizeIdentityBody(match[2]);
6486
6491
  const fm = {};
6487
6492
  for (const line of yamlStr.split("\n")) {
6488
6493
  const kv = line.match(/^(\w+):\s*(.+)$/);
@@ -6547,7 +6552,9 @@ function listIdentities() {
6547
6552
  const summary = lines[0]?.trim().slice(0, 120) ?? identity.frontmatter.title;
6548
6553
  results.push({
6549
6554
  agentId,
6550
- title: `${identity.frontmatter.title} (${identity.frontmatter.role.toUpperCase()})`,
6555
+ // User-facing/team-facing title only. `frontmatter.role` is internal
6556
+ // routing metadata and must not leak as an external title.
6557
+ title: identity.frontmatter.title,
6551
6558
  summary
6552
6559
  });
6553
6560
  }
@@ -7859,15 +7866,9 @@ async function runSetupWizard(opts = {}) {
7859
7866
  cooName = (cooNameInput || DEFAULT_COORDINATOR_TEMPLATE_NAME2).toLowerCase();
7860
7867
  let employees = await loadEmployees2(EMPLOYEES_PATH2).catch(() => []);
7861
7868
  if (!employees.some((e) => e.name === cooName)) {
7862
- const { DEFAULT_EXE: DEFAULT_EXE2, personalizePrompt: personalizePrompt2 } = await Promise.resolve().then(() => (init_employee_templates(), employee_templates_exports));
7863
7869
  const cooEmployee = {
7864
7870
  name: cooName,
7865
7871
  role: "COO",
7866
- systemPrompt: personalizePrompt2(
7867
- DEFAULT_EXE2.systemPrompt,
7868
- DEFAULT_COORDINATOR_TEMPLATE_NAME2,
7869
- cooName
7870
- ),
7871
7872
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
7872
7873
  templateName: DEFAULT_COORDINATOR_TEMPLATE_NAME2,
7873
7874
  templateVersion: 1
@@ -7961,12 +7962,12 @@ async function runSetupWizard(opts = {}) {
7961
7962
  const ctoNameInput = await ask(rl, `Name your CTO (default: ${ctoDefault}): `);
7962
7963
  const ctoName = (ctoNameInput || ctoDefault).toLowerCase();
7963
7964
  if (!employees.some((e) => e.name === ctoName)) {
7964
- const { personalizePrompt: personalizeCto } = await Promise.resolve().then(() => (init_employee_templates(), employee_templates_exports));
7965
7965
  const ctoEmployee = {
7966
7966
  name: ctoName,
7967
7967
  role: "CTO",
7968
- systemPrompt: personalizeCto(ctoTemplate?.systemPrompt ?? "", ctoDefault, ctoName),
7969
- createdAt: (/* @__PURE__ */ new Date()).toISOString()
7968
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
7969
+ templateName: ctoDefault,
7970
+ templateVersion: 1
7970
7971
  };
7971
7972
  employees = addEmployee2(employees, ctoEmployee);
7972
7973
  await saveEmployees2(employees, EMPLOYEES_PATH2);
@@ -7984,12 +7985,12 @@ async function runSetupWizard(opts = {}) {
7984
7985
  const cmoNameInput = await ask(rl, `Name your CMO (default: ${cmoDefault}): `);
7985
7986
  const cmoName = (cmoNameInput || cmoDefault).toLowerCase();
7986
7987
  if (!employees.some((e) => e.name === cmoName)) {
7987
- const { personalizePrompt: personalizeCmo } = await Promise.resolve().then(() => (init_employee_templates(), employee_templates_exports));
7988
7988
  const cmoEmployee = {
7989
7989
  name: cmoName,
7990
7990
  role: "CMO",
7991
- systemPrompt: personalizeCmo(cmoTemplate?.systemPrompt ?? "", cmoDefault, cmoName),
7992
- createdAt: (/* @__PURE__ */ new Date()).toISOString()
7991
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
7992
+ templateName: cmoDefault,
7993
+ templateVersion: 1
7993
7994
  };
7994
7995
  employees = addEmployee2(employees, cmoEmployee);
7995
7996
  await saveEmployees2(employees, EMPLOYEES_PATH2);
@@ -2601,7 +2601,7 @@ __export(shard_manager_exports, {
2601
2601
  shardExists: () => shardExists
2602
2602
  });
2603
2603
  import path7 from "path";
2604
- import { existsSync as existsSync7, mkdirSync as mkdirSync2, readdirSync } from "fs";
2604
+ import { existsSync as existsSync7, mkdirSync as mkdirSync2, readdirSync, renameSync as renameSync3, statSync as statSync2 } from "fs";
2605
2605
  import { createClient as createClient2 } from "@libsql/client";
2606
2606
  function initShardManager(encryptionKey) {
2607
2607
  _encryptionKey = encryptionKey;
@@ -2623,7 +2623,7 @@ function getShardClient(projectName) {
2623
2623
  if (!_encryptionKey) {
2624
2624
  throw new Error("Shard manager not initialized. Call initShardManager() first.");
2625
2625
  }
2626
- const safeName = projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
2626
+ const safeName = safeShardName(projectName);
2627
2627
  if (!safeName || safeName === "unknown") {
2628
2628
  throw new Error(`Invalid project name for shard: "${projectName}" (resolved to "${safeName}")`);
2629
2629
  }
@@ -2645,9 +2645,12 @@ function getShardClient(projectName) {
2645
2645
  return client;
2646
2646
  }
2647
2647
  function shardExists(projectName) {
2648
- const safeName = projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
2648
+ const safeName = safeShardName(projectName);
2649
2649
  return existsSync7(path7.join(SHARDS_DIR, `${safeName}.db`));
2650
2650
  }
2651
+ function safeShardName(projectName) {
2652
+ return projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
2653
+ }
2651
2654
  function listShards() {
2652
2655
  if (!existsSync7(SHARDS_DIR)) return [];
2653
2656
  return readdirSync(SHARDS_DIR).filter((f) => f.endsWith(".db")).map((f) => f.replace(".db", ""));
@@ -2741,7 +2744,8 @@ async function ensureShardSchema(client) {
2741
2744
  "ALTER TABLE memories ADD COLUMN token_cost REAL",
2742
2745
  "ALTER TABLE memories ADD COLUMN audience TEXT",
2743
2746
  "ALTER TABLE memories ADD COLUMN language_type TEXT",
2744
- "ALTER TABLE memories ADD COLUMN parent_memory_id TEXT"
2747
+ "ALTER TABLE memories ADD COLUMN parent_memory_id TEXT",
2748
+ "ALTER TABLE memories ADD COLUMN deleted_at TEXT"
2745
2749
  ]) {
2746
2750
  try {
2747
2751
  await client.execute(col);
@@ -2837,9 +2841,32 @@ async function ensureShardSchema(client) {
2837
2841
  }
2838
2842
  }
2839
2843
  async function getReadyShardClient(projectName) {
2840
- const client = getShardClient(projectName);
2841
- await ensureShardSchema(client);
2842
- return client;
2844
+ const safeName = safeShardName(projectName);
2845
+ let client = getShardClient(projectName);
2846
+ try {
2847
+ await ensureShardSchema(client);
2848
+ return client;
2849
+ } catch (err) {
2850
+ const message = err instanceof Error ? err.message : String(err);
2851
+ if (!/SQLITE_NOTADB|file is not a database/i.test(message)) throw err;
2852
+ client.close();
2853
+ _shards.delete(safeName);
2854
+ _shardLastAccess.delete(safeName);
2855
+ const dbPath = path7.join(SHARDS_DIR, `${safeName}.db`);
2856
+ if (existsSync7(dbPath)) {
2857
+ const stat = statSync2(dbPath);
2858
+ const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
2859
+ const archivedPath = path7.join(SHARDS_DIR, `${safeName}.db.broken-${stamp}`);
2860
+ renameSync3(dbPath, archivedPath);
2861
+ process.stderr.write(
2862
+ `[shard-manager] Archived unreadable shard ${safeName}: ${archivedPath} (${stat.size} bytes, mtime ${stat.mtime.toISOString()})
2863
+ `
2864
+ );
2865
+ }
2866
+ client = getShardClient(projectName);
2867
+ await ensureShardSchema(client);
2868
+ return client;
2869
+ }
2843
2870
  }
2844
2871
  function evictLRU() {
2845
2872
  let oldest = null;
@@ -905,7 +905,8 @@ function isMultiInstance(agentName, employees) {
905
905
  return MULTI_INSTANCE_ROLES.has(emp.role.toLowerCase());
906
906
  }
907
907
  function addEmployee(employees, employee) {
908
- const normalized = { ...employee, name: employee.name.toLowerCase() };
908
+ const { systemPrompt: _legacyPrompt, ...rest } = employee;
909
+ const normalized = { ...rest, name: employee.name.toLowerCase() };
909
910
  if (employees.some((e) => e.name.toLowerCase() === normalized.name)) {
910
911
  throw new Error(`Employee '${normalized.name}' already exists`);
911
912
  }
@@ -3907,7 +3908,7 @@ __export(shard_manager_exports, {
3907
3908
  shardExists: () => shardExists
3908
3909
  });
3909
3910
  import path8 from "path";
3910
- import { existsSync as existsSync8, mkdirSync as mkdirSync2, readdirSync } from "fs";
3911
+ import { existsSync as existsSync8, mkdirSync as mkdirSync2, readdirSync, renameSync as renameSync3, statSync as statSync2 } from "fs";
3911
3912
  import { createClient as createClient2 } from "@libsql/client";
3912
3913
  function initShardManager(encryptionKey) {
3913
3914
  _encryptionKey = encryptionKey;
@@ -3929,7 +3930,7 @@ function getShardClient(projectName) {
3929
3930
  if (!_encryptionKey) {
3930
3931
  throw new Error("Shard manager not initialized. Call initShardManager() first.");
3931
3932
  }
3932
- const safeName = projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
3933
+ const safeName = safeShardName(projectName);
3933
3934
  if (!safeName || safeName === "unknown") {
3934
3935
  throw new Error(`Invalid project name for shard: "${projectName}" (resolved to "${safeName}")`);
3935
3936
  }
@@ -3951,9 +3952,12 @@ function getShardClient(projectName) {
3951
3952
  return client;
3952
3953
  }
3953
3954
  function shardExists(projectName) {
3954
- const safeName = projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
3955
+ const safeName = safeShardName(projectName);
3955
3956
  return existsSync8(path8.join(SHARDS_DIR, `${safeName}.db`));
3956
3957
  }
3958
+ function safeShardName(projectName) {
3959
+ return projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
3960
+ }
3957
3961
  function listShards() {
3958
3962
  if (!existsSync8(SHARDS_DIR)) return [];
3959
3963
  return readdirSync(SHARDS_DIR).filter((f) => f.endsWith(".db")).map((f) => f.replace(".db", ""));
@@ -4047,7 +4051,8 @@ async function ensureShardSchema(client) {
4047
4051
  "ALTER TABLE memories ADD COLUMN token_cost REAL",
4048
4052
  "ALTER TABLE memories ADD COLUMN audience TEXT",
4049
4053
  "ALTER TABLE memories ADD COLUMN language_type TEXT",
4050
- "ALTER TABLE memories ADD COLUMN parent_memory_id TEXT"
4054
+ "ALTER TABLE memories ADD COLUMN parent_memory_id TEXT",
4055
+ "ALTER TABLE memories ADD COLUMN deleted_at TEXT"
4051
4056
  ]) {
4052
4057
  try {
4053
4058
  await client.execute(col);
@@ -4143,9 +4148,32 @@ async function ensureShardSchema(client) {
4143
4148
  }
4144
4149
  }
4145
4150
  async function getReadyShardClient(projectName) {
4146
- const client = getShardClient(projectName);
4147
- await ensureShardSchema(client);
4148
- return client;
4151
+ const safeName = safeShardName(projectName);
4152
+ let client = getShardClient(projectName);
4153
+ try {
4154
+ await ensureShardSchema(client);
4155
+ return client;
4156
+ } catch (err) {
4157
+ const message = err instanceof Error ? err.message : String(err);
4158
+ if (!/SQLITE_NOTADB|file is not a database/i.test(message)) throw err;
4159
+ client.close();
4160
+ _shards.delete(safeName);
4161
+ _shardLastAccess.delete(safeName);
4162
+ const dbPath = path8.join(SHARDS_DIR, `${safeName}.db`);
4163
+ if (existsSync8(dbPath)) {
4164
+ const stat = statSync2(dbPath);
4165
+ const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
4166
+ const archivedPath = path8.join(SHARDS_DIR, `${safeName}.db.broken-${stamp}`);
4167
+ renameSync3(dbPath, archivedPath);
4168
+ process.stderr.write(
4169
+ `[shard-manager] Archived unreadable shard ${safeName}: ${archivedPath} (${stat.size} bytes, mtime ${stat.mtime.toISOString()})
4170
+ `
4171
+ );
4172
+ }
4173
+ client = getShardClient(projectName);
4174
+ await ensureShardSchema(client);
4175
+ return client;
4176
+ }
4149
4177
  }
4150
4178
  function evictLRU() {
4151
4179
  let oldest = null;
@@ -6487,7 +6515,7 @@ __export(intercom_queue_exports, {
6487
6515
  queueIntercom: () => queueIntercom,
6488
6516
  readQueue: () => readQueue
6489
6517
  });
6490
- import { readFileSync as readFileSync8, writeFileSync as writeFileSync5, renameSync as renameSync3, existsSync as existsSync10, mkdirSync as mkdirSync5 } from "fs";
6518
+ import { readFileSync as readFileSync8, writeFileSync as writeFileSync5, renameSync as renameSync4, existsSync as existsSync10, mkdirSync as mkdirSync5 } from "fs";
6491
6519
  import path11 from "path";
6492
6520
  import os8 from "os";
6493
6521
  function ensureDir() {
@@ -6506,7 +6534,7 @@ function writeQueue(queue) {
6506
6534
  ensureDir();
6507
6535
  const tmp = `${QUEUE_PATH}.tmp`;
6508
6536
  writeFileSync5(tmp, JSON.stringify(queue, null, 2));
6509
- renameSync3(tmp, QUEUE_PATH);
6537
+ renameSync4(tmp, QUEUE_PATH);
6510
6538
  }
6511
6539
  function queueIntercom(targetSession, reason) {
6512
6540
  const queue = readQueue();
@@ -594,7 +594,8 @@ function isMultiInstance(agentName, employees) {
594
594
  return MULTI_INSTANCE_ROLES.has(emp.role.toLowerCase());
595
595
  }
596
596
  function addEmployee(employees, employee) {
597
- const normalized = { ...employee, name: employee.name.toLowerCase() };
597
+ const { systemPrompt: _legacyPrompt, ...rest } = employee;
598
+ const normalized = { ...rest, name: employee.name.toLowerCase() };
598
599
  if (employees.some((e) => e.name.toLowerCase() === normalized.name)) {
599
600
  throw new Error(`Employee '${normalized.name}' already exists`);
600
601
  }
@@ -3649,7 +3650,7 @@ __export(shard_manager_exports, {
3649
3650
  shardExists: () => shardExists
3650
3651
  });
3651
3652
  import path8 from "path";
3652
- import { existsSync as existsSync8, mkdirSync as mkdirSync2, readdirSync } from "fs";
3653
+ import { existsSync as existsSync8, mkdirSync as mkdirSync2, readdirSync, renameSync as renameSync3, statSync as statSync2 } from "fs";
3653
3654
  import { createClient as createClient2 } from "@libsql/client";
3654
3655
  function initShardManager(encryptionKey) {
3655
3656
  _encryptionKey = encryptionKey;
@@ -3671,7 +3672,7 @@ function getShardClient(projectName) {
3671
3672
  if (!_encryptionKey) {
3672
3673
  throw new Error("Shard manager not initialized. Call initShardManager() first.");
3673
3674
  }
3674
- const safeName = projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
3675
+ const safeName = safeShardName(projectName);
3675
3676
  if (!safeName || safeName === "unknown") {
3676
3677
  throw new Error(`Invalid project name for shard: "${projectName}" (resolved to "${safeName}")`);
3677
3678
  }
@@ -3693,9 +3694,12 @@ function getShardClient(projectName) {
3693
3694
  return client;
3694
3695
  }
3695
3696
  function shardExists(projectName) {
3696
- const safeName = projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
3697
+ const safeName = safeShardName(projectName);
3697
3698
  return existsSync8(path8.join(SHARDS_DIR, `${safeName}.db`));
3698
3699
  }
3700
+ function safeShardName(projectName) {
3701
+ return projectName.replace(/[^a-zA-Z0-9_-]/g, "_");
3702
+ }
3699
3703
  function listShards() {
3700
3704
  if (!existsSync8(SHARDS_DIR)) return [];
3701
3705
  return readdirSync(SHARDS_DIR).filter((f) => f.endsWith(".db")).map((f) => f.replace(".db", ""));
@@ -3789,7 +3793,8 @@ async function ensureShardSchema(client) {
3789
3793
  "ALTER TABLE memories ADD COLUMN token_cost REAL",
3790
3794
  "ALTER TABLE memories ADD COLUMN audience TEXT",
3791
3795
  "ALTER TABLE memories ADD COLUMN language_type TEXT",
3792
- "ALTER TABLE memories ADD COLUMN parent_memory_id TEXT"
3796
+ "ALTER TABLE memories ADD COLUMN parent_memory_id TEXT",
3797
+ "ALTER TABLE memories ADD COLUMN deleted_at TEXT"
3793
3798
  ]) {
3794
3799
  try {
3795
3800
  await client.execute(col);
@@ -3885,9 +3890,32 @@ async function ensureShardSchema(client) {
3885
3890
  }
3886
3891
  }
3887
3892
  async function getReadyShardClient(projectName) {
3888
- const client = getShardClient(projectName);
3889
- await ensureShardSchema(client);
3890
- return client;
3893
+ const safeName = safeShardName(projectName);
3894
+ let client = getShardClient(projectName);
3895
+ try {
3896
+ await ensureShardSchema(client);
3897
+ return client;
3898
+ } catch (err) {
3899
+ const message = err instanceof Error ? err.message : String(err);
3900
+ if (!/SQLITE_NOTADB|file is not a database/i.test(message)) throw err;
3901
+ client.close();
3902
+ _shards.delete(safeName);
3903
+ _shardLastAccess.delete(safeName);
3904
+ const dbPath = path8.join(SHARDS_DIR, `${safeName}.db`);
3905
+ if (existsSync8(dbPath)) {
3906
+ const stat = statSync2(dbPath);
3907
+ const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
3908
+ const archivedPath = path8.join(SHARDS_DIR, `${safeName}.db.broken-${stamp}`);
3909
+ renameSync3(dbPath, archivedPath);
3910
+ process.stderr.write(
3911
+ `[shard-manager] Archived unreadable shard ${safeName}: ${archivedPath} (${stat.size} bytes, mtime ${stat.mtime.toISOString()})
3912
+ `
3913
+ );
3914
+ }
3915
+ client = getShardClient(projectName);
3916
+ await ensureShardSchema(client);
3917
+ return client;
3918
+ }
3891
3919
  }
3892
3920
  function evictLRU() {
3893
3921
  let oldest = null;
@@ -5120,7 +5148,7 @@ __export(intercom_queue_exports, {
5120
5148
  queueIntercom: () => queueIntercom,
5121
5149
  readQueue: () => readQueue
5122
5150
  });
5123
- import { readFileSync as readFileSync7, writeFileSync as writeFileSync5, renameSync as renameSync3, existsSync as existsSync10, mkdirSync as mkdirSync4 } from "fs";
5151
+ import { readFileSync as readFileSync7, writeFileSync as writeFileSync5, renameSync as renameSync4, existsSync as existsSync10, mkdirSync as mkdirSync4 } from "fs";
5124
5152
  import path10 from "path";
5125
5153
  import os7 from "os";
5126
5154
  function ensureDir() {
@@ -5139,7 +5167,7 @@ function writeQueue(queue) {
5139
5167
  ensureDir();
5140
5168
  const tmp = `${QUEUE_PATH}.tmp`;
5141
5169
  writeFileSync5(tmp, JSON.stringify(queue, null, 2));
5142
- renameSync3(tmp, QUEUE_PATH);
5170
+ renameSync4(tmp, QUEUE_PATH);
5143
5171
  }
5144
5172
  function queueIntercom(targetSession, reason) {
5145
5173
  const queue = readQueue();