@askexenow/exe-os 0.8.80 → 0.8.82

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 (110) hide show
  1. package/dist/bin/backfill-conversations.js +359 -267
  2. package/dist/bin/backfill-responses.js +357 -265
  3. package/dist/bin/backfill-vectors.js +339 -264
  4. package/dist/bin/cleanup-stale-review-tasks.js +315 -256
  5. package/dist/bin/cli.js +494 -240
  6. package/dist/bin/exe-agent.js +141 -46
  7. package/dist/bin/exe-assign.js +151 -63
  8. package/dist/bin/exe-boot.js +294 -115
  9. package/dist/bin/exe-call.js +76 -51
  10. package/dist/bin/exe-cloud.js +58 -45
  11. package/dist/bin/exe-dispatch.js +434 -277
  12. package/dist/bin/exe-doctor.js +317 -246
  13. package/dist/bin/exe-export-behaviors.js +328 -248
  14. package/dist/bin/exe-forget.js +314 -231
  15. package/dist/bin/exe-gateway.js +2676 -1402
  16. package/dist/bin/exe-heartbeat.js +329 -264
  17. package/dist/bin/exe-kill.js +324 -244
  18. package/dist/bin/exe-launch-agent.js +574 -463
  19. package/dist/bin/exe-link.js +1055 -95
  20. package/dist/bin/exe-new-employee.js +49 -54
  21. package/dist/bin/exe-pending-messages.js +310 -253
  22. package/dist/bin/exe-pending-notifications.js +299 -228
  23. package/dist/bin/exe-pending-reviews.js +314 -245
  24. package/dist/bin/exe-rename.js +259 -195
  25. package/dist/bin/exe-review.js +140 -64
  26. package/dist/bin/exe-search.js +543 -356
  27. package/dist/bin/exe-session-cleanup.js +463 -382
  28. package/dist/bin/exe-settings.js +129 -99
  29. package/dist/bin/exe-start.sh +6 -6
  30. package/dist/bin/exe-status.js +95 -36
  31. package/dist/bin/exe-team.js +116 -51
  32. package/dist/bin/git-sweep.js +482 -307
  33. package/dist/bin/graph-backfill.js +357 -245
  34. package/dist/bin/graph-export.js +324 -244
  35. package/dist/bin/install.js +33 -10
  36. package/dist/bin/scan-tasks.js +481 -307
  37. package/dist/bin/setup.js +1147 -140
  38. package/dist/bin/shard-migrate.js +321 -241
  39. package/dist/bin/update.js +1 -7
  40. package/dist/bin/wiki-sync.js +318 -238
  41. package/dist/gateway/index.js +2656 -1383
  42. package/dist/hooks/bug-report-worker.js +641 -472
  43. package/dist/hooks/commit-complete.js +482 -307
  44. package/dist/hooks/error-recall.js +363 -135
  45. package/dist/hooks/exe-heartbeat-hook.js +97 -27
  46. package/dist/hooks/ingest-worker.js +584 -397
  47. package/dist/hooks/ingest.js +123 -58
  48. package/dist/hooks/instructions-loaded.js +212 -82
  49. package/dist/hooks/notification.js +200 -70
  50. package/dist/hooks/post-compact.js +199 -81
  51. package/dist/hooks/pre-compact.js +352 -140
  52. package/dist/hooks/pre-tool-use.js +416 -278
  53. package/dist/hooks/prompt-ingest-worker.js +376 -299
  54. package/dist/hooks/prompt-submit.js +414 -188
  55. package/dist/hooks/response-ingest-worker.js +408 -338
  56. package/dist/hooks/session-end.js +209 -83
  57. package/dist/hooks/session-start.js +382 -158
  58. package/dist/hooks/stop.js +209 -83
  59. package/dist/hooks/subagent-stop.js +209 -85
  60. package/dist/hooks/summary-worker.js +606 -510
  61. package/dist/index.js +2133 -855
  62. package/dist/lib/cloud-sync.js +1175 -184
  63. package/dist/lib/config.js +1 -9
  64. package/dist/lib/consolidation.js +71 -34
  65. package/dist/lib/database.js +166 -14
  66. package/dist/lib/device-registry.js +189 -117
  67. package/dist/lib/embedder.js +6 -10
  68. package/dist/lib/employee-templates.js +134 -39
  69. package/dist/lib/employees.js +30 -7
  70. package/dist/lib/exe-daemon-client.js +5 -7
  71. package/dist/lib/exe-daemon.js +514 -152
  72. package/dist/lib/hybrid-search.js +543 -356
  73. package/dist/lib/identity-templates.js +15 -15
  74. package/dist/lib/identity.js +19 -15
  75. package/dist/lib/license.js +1 -7
  76. package/dist/lib/messaging.js +157 -135
  77. package/dist/lib/reminders.js +97 -0
  78. package/dist/lib/schedules.js +302 -231
  79. package/dist/lib/skill-learning.js +33 -27
  80. package/dist/lib/status-brief.js +11 -14
  81. package/dist/lib/store.js +326 -237
  82. package/dist/lib/task-router.js +105 -1
  83. package/dist/lib/tasks.js +233 -116
  84. package/dist/lib/tmux-routing.js +173 -56
  85. package/dist/lib/ws-client.js +13 -3
  86. package/dist/mcp/server.js +2009 -1015
  87. package/dist/mcp/tools/complete-reminder.js +97 -0
  88. package/dist/mcp/tools/create-reminder.js +97 -0
  89. package/dist/mcp/tools/create-task.js +426 -262
  90. package/dist/mcp/tools/deactivate-behavior.js +119 -44
  91. package/dist/mcp/tools/list-reminders.js +97 -0
  92. package/dist/mcp/tools/list-tasks.js +56 -57
  93. package/dist/mcp/tools/send-message.js +206 -143
  94. package/dist/mcp/tools/update-task.js +259 -85
  95. package/dist/runtime/index.js +495 -316
  96. package/dist/tui/App.js +1128 -919
  97. package/package.json +2 -10
  98. package/src/commands/exe/afk.md +8 -8
  99. package/src/commands/exe/assign.md +1 -1
  100. package/src/commands/exe/build-adv.md +1 -1
  101. package/src/commands/exe/call.md +10 -10
  102. package/src/commands/exe/employee-heartbeat.md +9 -6
  103. package/src/commands/exe/heartbeat.md +5 -5
  104. package/src/commands/exe/intercom.md +26 -15
  105. package/src/commands/exe/launch.md +2 -2
  106. package/src/commands/exe/new-employee.md +1 -1
  107. package/src/commands/exe/review.md +2 -2
  108. package/src/commands/exe/schedule.md +1 -1
  109. package/src/commands/exe/sessions.md +2 -2
  110. package/src/commands/exe.md +22 -20
@@ -165,13 +165,7 @@ var init_config = __esm({
165
165
  wikiUrl: "",
166
166
  wikiApiKey: "",
167
167
  wikiSyncIntervalMs: 30 * 60 * 1e3,
168
- wikiWorkspaceMapping: {
169
- exe: "Executive",
170
- yoshi: "Engineering",
171
- mari: "Marketing",
172
- tom: "Engineering",
173
- sasha: "Production"
174
- },
168
+ wikiWorkspaceMapping: {},
175
169
  wikiAutoUpdate: true,
176
170
  wikiAutoUpdateThreshold: 0.5,
177
171
  wikiAutoUpdateCreateNew: true,
@@ -243,14 +237,61 @@ var init_session_key = __esm({
243
237
  }
244
238
  });
245
239
 
246
- // src/lib/session-registry.ts
247
- import path3 from "path";
240
+ // src/lib/employees.ts
241
+ import { readFile as readFile2, writeFile as writeFile2, mkdir as mkdir2 } from "fs/promises";
242
+ import { existsSync as existsSync2, symlinkSync, readlinkSync, readFileSync as readFileSync2, renameSync as renameSync2, unlinkSync, writeFileSync } from "fs";
243
+ import { execSync as execSync2 } from "child_process";
244
+ import path2 from "path";
248
245
  import os2 from "os";
246
+ function normalizeRole(role) {
247
+ return (role ?? "").trim().toLowerCase();
248
+ }
249
+ function isCoordinatorRole(role) {
250
+ return normalizeRole(role) === normalizeRole(COORDINATOR_ROLE);
251
+ }
252
+ function getCoordinatorEmployee(employees) {
253
+ return employees.find((e) => isCoordinatorRole(e.role));
254
+ }
255
+ function getCoordinatorName(employees = loadEmployeesSync()) {
256
+ return getCoordinatorEmployee(employees)?.name ?? DEFAULT_COORDINATOR_TEMPLATE_NAME;
257
+ }
258
+ function isCoordinatorName(agentName, employees = loadEmployeesSync()) {
259
+ if (!agentName) return false;
260
+ return agentName.toLowerCase() === getCoordinatorName(employees).toLowerCase();
261
+ }
262
+ function canCoordinate(agentName, agentRole, employees = loadEmployeesSync()) {
263
+ return agentName === "default" || isCoordinatorRole(agentRole) || isCoordinatorName(agentName, employees);
264
+ }
265
+ function loadEmployeesSync(employeesPath = EMPLOYEES_PATH) {
266
+ if (!existsSync2(employeesPath)) return [];
267
+ try {
268
+ return JSON.parse(readFileSync2(employeesPath, "utf-8"));
269
+ } catch {
270
+ return [];
271
+ }
272
+ }
273
+ function getEmployee(employees, name) {
274
+ return employees.find((e) => e.name.toLowerCase() === name.toLowerCase());
275
+ }
276
+ var EMPLOYEES_PATH, DEFAULT_COORDINATOR_TEMPLATE_NAME, COORDINATOR_ROLE;
277
+ var init_employees = __esm({
278
+ "src/lib/employees.ts"() {
279
+ "use strict";
280
+ init_config();
281
+ EMPLOYEES_PATH = path2.join(EXE_AI_DIR, "exe-employees.json");
282
+ DEFAULT_COORDINATOR_TEMPLATE_NAME = "exe";
283
+ COORDINATOR_ROLE = "COO";
284
+ }
285
+ });
286
+
287
+ // src/lib/session-registry.ts
288
+ import path4 from "path";
289
+ import os3 from "os";
249
290
  var REGISTRY_PATH;
250
291
  var init_session_registry = __esm({
251
292
  "src/lib/session-registry.ts"() {
252
293
  "use strict";
253
- REGISTRY_PATH = path3.join(os2.homedir(), ".exe-os", "session-registry.json");
294
+ REGISTRY_PATH = path4.join(os3.homedir(), ".exe-os", "session-registry.json");
254
295
  }
255
296
  });
256
297
 
@@ -362,7 +403,7 @@ var init_transport = __esm({
362
403
  });
363
404
 
364
405
  // src/lib/cc-agent-support.ts
365
- import { execSync as execSync3 } from "child_process";
406
+ import { execSync as execSync4 } from "child_process";
366
407
  var init_cc_agent_support = __esm({
367
408
  "src/lib/cc-agent-support.ts"() {
368
409
  "use strict";
@@ -391,16 +432,16 @@ var init_provider_table = __esm({
391
432
  });
392
433
 
393
434
  // src/lib/intercom-queue.ts
394
- import { readFileSync as readFileSync3, writeFileSync as writeFileSync2, renameSync as renameSync2, existsSync as existsSync2, mkdirSync as mkdirSync2 } from "fs";
395
- import path4 from "path";
396
- import os3 from "os";
435
+ import { readFileSync as readFileSync4, writeFileSync as writeFileSync3, renameSync as renameSync3, existsSync as existsSync3, mkdirSync as mkdirSync2 } from "fs";
436
+ import path5 from "path";
437
+ import os4 from "os";
397
438
  var QUEUE_PATH, TTL_MS, INTERCOM_LOG;
398
439
  var init_intercom_queue = __esm({
399
440
  "src/lib/intercom-queue.ts"() {
400
441
  "use strict";
401
- QUEUE_PATH = path4.join(os3.homedir(), ".exe-os", "intercom-queue.json");
442
+ QUEUE_PATH = path5.join(os4.homedir(), ".exe-os", "intercom-queue.json");
402
443
  TTL_MS = 60 * 60 * 1e3;
403
- INTERCOM_LOG = path4.join(os3.homedir(), ".exe-os", "intercom.log");
444
+ INTERCOM_LOG = path5.join(os4.homedir(), ".exe-os", "intercom.log");
404
445
  }
405
446
  });
406
447
 
@@ -443,7 +484,7 @@ function wrapWithRetry(client) {
443
484
  return (sql) => retryOnBusy(() => target.execute(sql), "execute");
444
485
  }
445
486
  if (prop === "batch") {
446
- return (stmts) => retryOnBusy(() => target.batch(stmts), "batch");
487
+ return (stmts, mode) => retryOnBusy(() => target.batch(stmts, mode), "batch");
447
488
  }
448
489
  return Reflect.get(target, prop, receiver);
449
490
  }
@@ -606,22 +647,24 @@ async function ensureSchema() {
606
647
  ON behaviors(agent_id, active);
607
648
  `);
608
649
  try {
650
+ const coordinatorName = getCoordinatorName();
609
651
  const existing = await client.execute({
610
- sql: "SELECT COUNT(*) as cnt FROM behaviors WHERE agent_id = 'exe'",
611
- args: []
652
+ sql: "SELECT COUNT(*) as cnt FROM behaviors WHERE agent_id = ?",
653
+ args: [coordinatorName]
612
654
  });
613
655
  if (Number(existing.rows[0]?.cnt) === 0) {
614
- await client.executeMultiple(`
615
- INSERT INTO behaviors (id, agent_id, project_name, domain, content, active, created_at, updated_at)
616
- VALUES
617
- (hex(randomblob(16)), 'exe', NULL, 'workflow', 'Don''t ask "keep going?" \u2014 just keep executing phases/plans autonomously', 1, '2026-03-25T00:00:00Z', '2026-03-25T00:00:00Z');
618
- INSERT INTO behaviors (id, agent_id, project_name, domain, content, active, created_at, updated_at)
619
- VALUES
620
- (hex(randomblob(16)), 'exe', NULL, 'tool-use', 'Always use create_task MCP tool, never write .md files directly for task creation', 1, '2026-03-25T00:00:00Z', '2026-03-25T00:00:00Z');
621
- INSERT INTO behaviors (id, agent_id, project_name, domain, content, active, created_at, updated_at)
622
- VALUES
623
- (hex(randomblob(16)), 'exe', NULL, 'workflow', 'Auto-start reviewing when idle and reviews are pending \u2014 never ask founder for permission', 1, '2026-03-25T00:00:00Z', '2026-03-25T00:00:00Z');
624
- `);
656
+ const seededAt = "2026-03-25T00:00:00Z";
657
+ for (const [domain, content] of [
658
+ ["workflow", `Don't ask "keep going?" \u2014 just keep executing phases/plans autonomously`],
659
+ ["tool-use", "Always use create_task MCP tool, never write .md files directly for task creation"],
660
+ ["workflow", "Auto-start reviewing when idle and reviews are pending \u2014 never ask founder for permission"]
661
+ ]) {
662
+ await client.execute({
663
+ sql: `INSERT INTO behaviors (id, agent_id, project_name, domain, content, active, created_at, updated_at)
664
+ VALUES (hex(randomblob(16)), ?, NULL, ?, ?, 1, ?, ?)`,
665
+ args: [coordinatorName, domain, content, seededAt, seededAt]
666
+ });
667
+ }
625
668
  }
626
669
  } catch {
627
670
  }
@@ -1313,6 +1356,39 @@ async function ensureSchema() {
1313
1356
  } catch {
1314
1357
  }
1315
1358
  }
1359
+ try {
1360
+ await client.execute({
1361
+ sql: `ALTER TABLE memories ADD COLUMN draft INTEGER DEFAULT 0`,
1362
+ args: []
1363
+ });
1364
+ } catch {
1365
+ }
1366
+ try {
1367
+ await client.execute(
1368
+ `CREATE INDEX IF NOT EXISTS idx_memories_draft ON memories(draft) WHERE draft = 1`
1369
+ );
1370
+ } catch {
1371
+ }
1372
+ try {
1373
+ await client.execute({
1374
+ sql: `ALTER TABLE memories ADD COLUMN memory_type TEXT DEFAULT 'raw'`,
1375
+ args: []
1376
+ });
1377
+ } catch {
1378
+ }
1379
+ try {
1380
+ await client.execute(
1381
+ `CREATE INDEX IF NOT EXISTS idx_memories_type ON memories(memory_type)`
1382
+ );
1383
+ } catch {
1384
+ }
1385
+ try {
1386
+ await client.execute({
1387
+ sql: `ALTER TABLE memories ADD COLUMN trajectory TEXT`,
1388
+ args: []
1389
+ });
1390
+ } catch {
1391
+ }
1316
1392
  }
1317
1393
  async function disposeDatabase() {
1318
1394
  if (_client) {
@@ -1326,6 +1402,7 @@ var init_database = __esm({
1326
1402
  "src/lib/database.ts"() {
1327
1403
  "use strict";
1328
1404
  init_db_retry();
1405
+ init_employees();
1329
1406
  _client = null;
1330
1407
  _resilientClient = null;
1331
1408
  initTurso = initDatabase;
@@ -1333,21 +1410,6 @@ var init_database = __esm({
1333
1410
  }
1334
1411
  });
1335
1412
 
1336
- // src/lib/employees.ts
1337
- import { readFile as readFile2, writeFile as writeFile2, mkdir as mkdir2 } from "fs/promises";
1338
- import { existsSync as existsSync3, symlinkSync, readlinkSync, readFileSync as readFileSync4, renameSync as renameSync3, unlinkSync as unlinkSync2, writeFileSync as writeFileSync3 } from "fs";
1339
- import { execSync as execSync4 } from "child_process";
1340
- import path5 from "path";
1341
- import os4 from "os";
1342
- var EMPLOYEES_PATH;
1343
- var init_employees = __esm({
1344
- "src/lib/employees.ts"() {
1345
- "use strict";
1346
- init_config();
1347
- EMPLOYEES_PATH = path5.join(EXE_AI_DIR, "exe-employees.json");
1348
- }
1349
- });
1350
-
1351
1413
  // src/lib/license.ts
1352
1414
  import { readFileSync as readFileSync5, writeFileSync as writeFileSync4, existsSync as existsSync4, mkdirSync as mkdirSync3 } from "fs";
1353
1415
  import { randomUUID } from "crypto";
@@ -1388,8 +1450,10 @@ function getMySession() {
1388
1450
  return getTransport().getMySession();
1389
1451
  }
1390
1452
  function extractRootExe(name) {
1391
- const match = name.match(/(exe\d+)$/);
1392
- return match?.[1] ?? null;
1453
+ if (!name) return null;
1454
+ if (!name.includes("-")) return name;
1455
+ const parts = name.split("-").filter(Boolean);
1456
+ return parts.length > 0 ? parts[parts.length - 1] : null;
1393
1457
  }
1394
1458
  function getParentExe(sessionKey) {
1395
1459
  try {
@@ -1424,6 +1488,7 @@ var init_tmux_routing = __esm({
1424
1488
  init_provider_table();
1425
1489
  init_intercom_queue();
1426
1490
  init_plan_limits();
1491
+ init_employees();
1427
1492
  SPAWN_LOCK_DIR = path8.join(os5.homedir(), ".exe-os", "spawn-locks");
1428
1493
  SESSION_CACHE = path8.join(os5.homedir(), ".exe-os", "session-cache");
1429
1494
  INTERCOM_LOG2 = path8.join(os5.homedir(), ".exe-os", "intercom.log");
@@ -1691,7 +1756,11 @@ async function ensureShardSchema(client) {
1691
1756
  "ALTER TABLE memories ADD COLUMN source_path TEXT",
1692
1757
  "ALTER TABLE memories ADD COLUMN source_type TEXT DEFAULT 'text'",
1693
1758
  "ALTER TABLE memories ADD COLUMN tier INTEGER DEFAULT 3",
1694
- "ALTER TABLE memories ADD COLUMN supersedes_id TEXT"
1759
+ "ALTER TABLE memories ADD COLUMN supersedes_id TEXT",
1760
+ // MS-11: draft staging, MS-6a: memory_type, MS-7: trajectory
1761
+ "ALTER TABLE memories ADD COLUMN draft INTEGER DEFAULT 0",
1762
+ "ALTER TABLE memories ADD COLUMN memory_type TEXT DEFAULT 'raw'",
1763
+ "ALTER TABLE memories ADD COLUMN trajectory TEXT"
1695
1764
  ]) {
1696
1765
  try {
1697
1766
  await client.execute(col);
@@ -1821,26 +1890,26 @@ var init_platform_procedures = __esm({
1821
1890
  title: "What is exe-os \u2014 the operating model every agent must understand",
1822
1891
  domain: "architecture",
1823
1892
  priority: "p0",
1824
- content: "Exe OS is an AI employee operating system. A founder runs 5-10 AI agents as a real org: COO (exe), CTO (yoshi), CMO (mari), engineers (tom), content (sasha). Each agent has identity, expertise, and experience layers \u2014 persistent memory that makes them better over time. All data is local-first, E2EE, owned by the user. The MCP server is the ONLY data interface \u2014 never access the DB directly."
1893
+ content: "Exe OS is an AI employee operating system. A founder runs 5-10 AI agents as a real org: COO, CTO, CMO, engineers, and content production specialists. Each agent has identity, expertise, and experience layers \u2014 persistent memory that makes them better over time. All data is local-first, E2EE, owned by the user. The MCP server is the ONLY data interface \u2014 never access the DB directly."
1825
1894
  },
1826
1895
  {
1827
1896
  title: "Mode 1 \u2014 how exe-os runs inside Claude Code",
1828
1897
  domain: "architecture",
1829
1898
  priority: "p0",
1830
- content: "Mode 1: exe-os runs AS hooks + MCP + skills inside Claude Code. The founder opens CC, runs /exe to boot the COO. exe manages employees in tmux sessions. Each exeN is a separate CC window/project. Employees (yoshi, tom, mari) run in their own tmux panes via create_task auto-spawn. The founder talks to exe; exe orchestrates the team. CC is the shell, exe-os is the brain."
1899
+ content: "Mode 1: exe-os runs AS hooks + MCP + skills inside Claude Code. The founder opens CC and boots the COO. The COO manages employees in tmux sessions. Each coordinator session is a separate CC window/project. Employees run in their own tmux panes via create_task auto-spawn. The founder talks to the COO; the COO orchestrates the team. CC is the shell, exe-os is the brain."
1831
1900
  },
1832
1901
  {
1833
- title: "Sessions explained \u2014 what exeN means and how projects work",
1902
+ title: "Sessions explained \u2014 coordinator session names and projects",
1834
1903
  domain: "architecture",
1835
1904
  priority: "p0",
1836
- content: "Each exeN (exe1, exe2, exe3) is an isolated project session. exe1 might be exe-os development, exe2 might be exe-wiki. Each session spawns its own employees: exe1\u2192yoshi-exe1\u2192tom-exe1. Sessions share the same memory DB but tasks are scoped to the session that created them. A founder can run multiple projects simultaneously. Sessions never interfere with each other."
1905
+ content: "Each coordinator session is an isolated project session. One might be exe-os development, another might be exe-wiki. Each session spawns its own employees using {employee}-{coordinatorSession}. Sessions share the same memory DB but tasks are scoped to the session that created them. A founder can run multiple projects simultaneously. Sessions never interfere with each other."
1837
1906
  },
1838
1907
  // --- Hierarchy and dispatch ---
1839
1908
  {
1840
1909
  title: "Chain of command \u2014 who talks to whom",
1841
1910
  domain: "workflow",
1842
1911
  priority: "p0",
1843
- content: "Founder \u2192 exe (COO) \u2192 yoshi (CTO) / mari (CMO). Yoshi \u2192 tom (engineer). Mari \u2192 sasha (content). Never skip levels: exe never assigns directly to tom. Tom never reports directly to exe. If you need cross-team info, use ask_team_memory \u2014 don't read other agents' task folders. Each level owns dispatch downward and review upward."
1912
+ content: "Founder -> COO -> CTO/CMO. CTO -> engineers. CMO -> content production. Never skip levels: the COO does not bypass managers for specialist work. Specialists report to their manager. If you need cross-team info, use ask_team_memory \u2014 don't read other agents' task folders. Each level owns dispatch downward and review upward."
1844
1913
  },
1845
1914
  {
1846
1915
  title: "Single dispatch path \u2014 create_task only",
@@ -1850,30 +1919,30 @@ var init_platform_procedures = __esm({
1850
1919
  },
1851
1920
  // --- Session isolation ---
1852
1921
  {
1853
- title: "Session scoping \u2014 stay in your exe boundary",
1922
+ title: "Session scoping \u2014 stay in your coordinator boundary",
1854
1923
  domain: "security",
1855
1924
  priority: "p0",
1856
- content: "Session scoping is mandatory. Managers dispatch to workers within their own exe session ONLY. exe1\u2192yoshi-exe1\u2192tom-exe1. exe2\u2192yoshi-exe2\u2192tom2-exe2. Cross-session dispatch is blocked by the system. Verify session names before dispatch. Tasks are scoped to the creating exe session."
1925
+ content: "Session scoping is mandatory. Managers dispatch to workers within their own coordinator session ONLY. Employee sessions use {employee}-{coordinatorSession}. Cross-session dispatch is blocked by the system. Verify session names before dispatch. Tasks are scoped to the creating coordinator session."
1857
1926
  },
1858
1927
  {
1859
1928
  title: "Session isolation \u2014 never touch another session's work",
1860
1929
  domain: "workflow",
1861
1930
  priority: "p0",
1862
- content: `Sessions are isolated. exeN owns ONLY tasks it dispatched. (1) Never close/update/cancel tasks from another exe session. (2) Never review work from a different session \u2014 report "belongs to exeN" and skip. (3) Ignore other sessions' items in list_tasks results. (4) Employees inherit session: yoshi-exe1 works ONLY on exe1 tasks. Cross-session work is a system violation.`
1931
+ content: "Sessions are isolated. A coordinator session owns ONLY tasks it dispatched. (1) Never close/update/cancel tasks from another coordinator session. (2) Never review work from a different session \u2014 report that it belongs to another session and skip. (3) Ignore other sessions' items in list_tasks results. (4) Employees inherit session: employee sessions work ONLY on their parent coordinator session's tasks. Cross-session work is a system violation."
1863
1932
  },
1864
1933
  // --- Engineering: session scoping in code ---
1865
1934
  {
1866
1935
  title: "Three-dimensional scoping \u2014 session, project, role \u2014 enforced in every query",
1867
1936
  domain: "architecture",
1868
1937
  priority: "p0",
1869
- content: "Every DB query, notification, review count, and task operation MUST be scoped on 3 dimensions: (1) Session \u2014 filter by session_scope matching current exeN. (2) Project \u2014 filter by project_name. (3) Role \u2014 agents only see data at their hierarchy level. When writing ANY function that touches tasks, reviews, messages, or notifications: always accept a sessionScope parameter and pass it to the SQL WHERE clause. Unscoped queries are bugs. Test by running 2+ exe sessions simultaneously."
1938
+ content: "Every DB query, notification, review count, and task operation MUST be scoped on 3 dimensions: (1) Session \u2014 filter by session_scope matching the current coordinator session. (2) Project \u2014 filter by project_name. (3) Role \u2014 agents only see data at their hierarchy level. When writing ANY function that touches tasks, reviews, messages, or notifications: always accept a sessionScope parameter and pass it to the SQL WHERE clause. Unscoped queries are bugs. Test by running 2+ coordinator sessions simultaneously."
1870
1939
  },
1871
1940
  // --- Hard constraints ---
1872
1941
  {
1873
1942
  title: "What you CANNOT do in exe-os \u2014 hard constraints",
1874
1943
  domain: "security",
1875
1944
  priority: "p0",
1876
- content: "NEVER: (1) Access the database directly \u2014 it's SQLCipher encrypted, always fails. Use MCP tools only. (2) Manually spawn tmux sessions \u2014 create_task handles it. (3) Run git checkout main \u2014 agents work in worktrees. (4) Modify another agent's in-progress task. (5) Push to remote \u2014 exe reviews and pushes. (6) Skip update_task(done) \u2014 it's the ONLY way your work gets reviewed. (7) Run git init."
1945
+ content: "NEVER: (1) Access the database directly \u2014 it's SQLCipher encrypted, always fails. Use MCP tools only. (2) Manually spawn tmux sessions \u2014 create_task handles it. (3) Run git checkout main \u2014 agents work in worktrees. (4) Modify another agent's in-progress task. (5) Push to remote \u2014 the COO reviews and pushes. (6) Skip update_task(done) \u2014 it's the ONLY way your work gets reviewed. (7) Run git init."
1877
1946
  },
1878
1947
  // --- Operations ---
1879
1948
  {
@@ -2113,7 +2182,10 @@ async function writeMemory(record) {
2113
2182
  source_path: record.source_path ?? null,
2114
2183
  source_type: record.source_type ?? null,
2115
2184
  tier: record.tier ?? classifyTier(record),
2116
- supersedes_id: record.supersedes_id ?? null
2185
+ supersedes_id: record.supersedes_id ?? null,
2186
+ draft: record.draft ? 1 : 0,
2187
+ memory_type: record.memory_type ?? "raw",
2188
+ trajectory: record.trajectory ? JSON.stringify(record.trajectory) : null
2117
2189
  };
2118
2190
  _pendingRecords.push(dbRow);
2119
2191
  orgBus.emit({
@@ -2168,6 +2240,9 @@ async function flushBatch() {
2168
2240
  const sourceType = row.source_type ?? null;
2169
2241
  const tier = row.tier ?? 3;
2170
2242
  const supersedesId = row.supersedes_id ?? null;
2243
+ const draft = row.draft ? 1 : 0;
2244
+ const memoryType = row.memory_type ?? "raw";
2245
+ const trajectory = row.trajectory ?? null;
2171
2246
  return {
2172
2247
  sql: hasVector ? `INSERT OR IGNORE INTO memories
2173
2248
  (id, agent_id, agent_role, session_id, timestamp,
@@ -2175,15 +2250,15 @@ async function flushBatch() {
2175
2250
  has_error, raw_text, vector, version, task_id, importance, status,
2176
2251
  confidence, last_accessed,
2177
2252
  workspace_id, document_id, user_id, char_offset, page_number,
2178
- source_path, source_type, tier, supersedes_id)
2179
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, vector32(?), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)` : `INSERT OR IGNORE INTO memories
2253
+ source_path, source_type, tier, supersedes_id, draft, memory_type, trajectory)
2254
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, vector32(?), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)` : `INSERT OR IGNORE INTO memories
2180
2255
  (id, agent_id, agent_role, session_id, timestamp,
2181
2256
  tool_name, project_name,
2182
2257
  has_error, raw_text, vector, version, task_id, importance, status,
2183
2258
  confidence, last_accessed,
2184
2259
  workspace_id, document_id, user_id, char_offset, page_number,
2185
- source_path, source_type, tier, supersedes_id)
2186
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
2260
+ source_path, source_type, tier, supersedes_id, draft, memory_type, trajectory)
2261
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
2187
2262
  args: hasVector ? [
2188
2263
  row.id,
2189
2264
  row.agent_id,
@@ -2209,7 +2284,10 @@ async function flushBatch() {
2209
2284
  sourcePath,
2210
2285
  sourceType,
2211
2286
  tier,
2212
- supersedesId
2287
+ supersedesId,
2288
+ draft,
2289
+ memoryType,
2290
+ trajectory
2213
2291
  ] : [
2214
2292
  row.id,
2215
2293
  row.agent_id,
@@ -2234,7 +2312,10 @@ async function flushBatch() {
2234
2312
  sourcePath,
2235
2313
  sourceType,
2236
2314
  tier,
2237
- supersedesId
2315
+ supersedesId,
2316
+ draft,
2317
+ memoryType,
2318
+ trajectory
2238
2319
  ]
2239
2320
  };
2240
2321
  };
@@ -2303,6 +2384,8 @@ async function searchMemories(queryVector, agentId, options) {
2303
2384
  const limit = options?.limit ?? 10;
2304
2385
  const statusFilter = options?.includeArchived ? "" : `
2305
2386
  AND COALESCE(status, 'active') = 'active'`;
2387
+ const draftFilter = options?.includeDrafts ? "" : `
2388
+ AND (draft = 0 OR draft IS NULL)`;
2306
2389
  let sql = `SELECT id, agent_id, agent_role, session_id, timestamp,
2307
2390
  tool_name, project_name,
2308
2391
  has_error, raw_text, vector, importance, status,
@@ -2312,7 +2395,7 @@ async function searchMemories(queryVector, agentId, options) {
2312
2395
  source_path, source_type
2313
2396
  FROM memories
2314
2397
  WHERE agent_id = ?
2315
- AND vector IS NOT NULL${statusFilter}
2398
+ AND vector IS NOT NULL${statusFilter}${draftFilter}
2316
2399
  AND COALESCE(confidence, 0.7) >= 0.3`;
2317
2400
  const args = [agentId];
2318
2401
  const scope = buildWikiScopeFilter(options, "");
@@ -2334,6 +2417,10 @@ async function searchMemories(queryVector, agentId, options) {
2334
2417
  sql += ` AND timestamp >= ?`;
2335
2418
  args.push(options.since);
2336
2419
  }
2420
+ if (options?.memoryType) {
2421
+ sql += ` AND memory_type = ?`;
2422
+ args.push(options.memoryType);
2423
+ }
2337
2424
  sql += ` ORDER BY vector_distance_cos(vector, vector32(?))`;
2338
2425
  args.push(vectorToBlob(queryVector));
2339
2426
  sql += ` LIMIT ?`;
@@ -2716,36 +2803,79 @@ var init_notifications = __esm({
2716
2803
 
2717
2804
  // src/adapters/claude/active-agent.ts
2718
2805
  init_config();
2719
- import { readFileSync as readFileSync2, writeFileSync, mkdirSync, unlinkSync, readdirSync } from "fs";
2720
- import { execSync as execSync2 } from "child_process";
2721
- import path2 from "path";
2806
+ import { readFileSync as readFileSync3, writeFileSync as writeFileSync2, mkdirSync, unlinkSync as unlinkSync2, readdirSync } from "fs";
2807
+ import { execSync as execSync3 } from "child_process";
2808
+ import path3 from "path";
2722
2809
 
2723
2810
  // src/adapters/claude/session-key.ts
2724
2811
  init_session_key();
2725
2812
 
2726
2813
  // src/adapters/claude/active-agent.ts
2727
- var CACHE_DIR = path2.join(EXE_AI_DIR, "session-cache");
2814
+ init_employees();
2815
+ var CACHE_DIR = path3.join(EXE_AI_DIR, "session-cache");
2728
2816
  var STALE_MS = 24 * 60 * 60 * 1e3;
2817
+ function isNameWithOptionalInstance(candidate, baseName) {
2818
+ if (candidate === baseName) return true;
2819
+ if (!candidate.startsWith(baseName)) return false;
2820
+ return /^\d+$/.test(candidate.slice(baseName.length));
2821
+ }
2822
+ function resolveEmployeeFromSessionPrefix(prefix, employees) {
2823
+ const sorted = [...employees].sort((a, b) => b.name.length - a.name.length);
2824
+ for (const employee of sorted) {
2825
+ if (isNameWithOptionalInstance(prefix, employee.name)) {
2826
+ return { agentId: employee.name, agentRole: employee.role };
2827
+ }
2828
+ }
2829
+ return null;
2830
+ }
2831
+ function resolveActiveAgentFromTmuxSession(sessionName) {
2832
+ const employees = loadEmployeesSync();
2833
+ const coordinator = getCoordinatorEmployee(employees);
2834
+ const coordinatorName = coordinator?.name ?? DEFAULT_COORDINATOR_TEMPLATE_NAME;
2835
+ if (isNameWithOptionalInstance(sessionName, coordinatorName)) {
2836
+ return {
2837
+ agentId: coordinatorName,
2838
+ agentRole: coordinator?.role ?? "COO"
2839
+ };
2840
+ }
2841
+ if (isNameWithOptionalInstance(sessionName, DEFAULT_COORDINATOR_TEMPLATE_NAME)) {
2842
+ return {
2843
+ agentId: coordinator?.name ?? DEFAULT_COORDINATOR_TEMPLATE_NAME,
2844
+ agentRole: coordinator?.role ?? "COO"
2845
+ };
2846
+ }
2847
+ if (sessionName.includes("-")) {
2848
+ const prefix = sessionName.split("-")[0] ?? "";
2849
+ const employee = resolveEmployeeFromSessionPrefix(prefix, employees);
2850
+ if (employee) return employee;
2851
+ const legacy = prefix.match(/^([a-zA-Z]+)\d*$/);
2852
+ if (legacy?.[1] && legacy[1] !== DEFAULT_COORDINATOR_TEMPLATE_NAME) {
2853
+ const emp = getEmployee(employees, legacy[1]);
2854
+ return { agentId: emp?.name ?? legacy[1], agentRole: emp?.role ?? "employee" };
2855
+ }
2856
+ }
2857
+ return null;
2858
+ }
2729
2859
  function getMarkerPath() {
2730
- return path2.join(CACHE_DIR, `active-agent-${getSessionKey()}.json`);
2860
+ return path3.join(CACHE_DIR, `active-agent-${getSessionKey()}.json`);
2731
2861
  }
2732
2862
  function clearActiveAgent() {
2733
2863
  try {
2734
- unlinkSync(getMarkerPath());
2864
+ unlinkSync2(getMarkerPath());
2735
2865
  } catch {
2736
2866
  }
2737
2867
  }
2738
2868
  function getActiveAgent() {
2739
2869
  try {
2740
2870
  const markerPath = getMarkerPath();
2741
- const raw = readFileSync2(markerPath, "utf8");
2871
+ const raw = readFileSync3(markerPath, "utf8");
2742
2872
  const data = JSON.parse(raw);
2743
2873
  if (data.agentId) {
2744
2874
  if (data.startedAt) {
2745
2875
  const age = Date.now() - new Date(data.startedAt).getTime();
2746
2876
  if (age > STALE_MS) {
2747
2877
  try {
2748
- unlinkSync(markerPath);
2878
+ unlinkSync2(markerPath);
2749
2879
  } catch {
2750
2880
  }
2751
2881
  } else {
@@ -2764,17 +2894,12 @@ function getActiveAgent() {
2764
2894
  } catch {
2765
2895
  }
2766
2896
  try {
2767
- const sessionName = execSync2(
2897
+ const sessionName = execSync3(
2768
2898
  "tmux display-message -p '#{session_name}' 2>/dev/null",
2769
2899
  { encoding: "utf8", timeout: 2e3 }
2770
2900
  ).trim();
2771
- const empMatch = sessionName.match(/^([a-zA-Z]+)\d*-exe\d+$/);
2772
- if (empMatch && empMatch[1] !== "exe") {
2773
- return { agentId: empMatch[1], agentRole: "employee" };
2774
- }
2775
- if (/^exe\d+$/.test(sessionName)) {
2776
- return { agentId: "exe", agentRole: "COO" };
2777
- }
2901
+ const resolved = resolveActiveAgentFromTmuxSession(sessionName);
2902
+ if (resolved) return resolved;
2778
2903
  } catch {
2779
2904
  }
2780
2905
  return {
@@ -2785,6 +2910,7 @@ function getActiveAgent() {
2785
2910
 
2786
2911
  // src/adapters/claude/hooks/session-end.ts
2787
2912
  init_task_scope();
2913
+ init_employees();
2788
2914
  if (!process.env.AGENT_ID) {
2789
2915
  process.env.AGENT_ID = "default";
2790
2916
  process.env.AGENT_ROLE = "employee";
@@ -2834,7 +2960,7 @@ Orphaned tasks at session end: ${orphanResult.rows.map((r) => `"${String(r.title
2834
2960
  vector: null
2835
2961
  });
2836
2962
  await flushBatch2();
2837
- if (agent.agentRole !== "COO") {
2963
+ if (!canCoordinate(agent.agentId, agent.agentRole)) {
2838
2964
  const inProgress = orphanResult.rows.filter((r) => String(r.status) === "in_progress");
2839
2965
  if (inProgress.length > 0) {
2840
2966
  const titles = inProgress.map((r) => `"${String(r.title)}"`).join(", ");