@askexenow/exe-os 0.9.60 → 0.9.62

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 (106) hide show
  1. package/deploy/stack-manifests/v0.9.json +62 -13
  2. package/dist/bin/backfill-conversations.js +282 -7
  3. package/dist/bin/backfill-responses.js +282 -7
  4. package/dist/bin/backfill-vectors.js +119 -7
  5. package/dist/bin/cc-doctor.js +376 -0
  6. package/dist/bin/cleanup-stale-review-tasks.js +282 -7
  7. package/dist/bin/cli.js +455 -77
  8. package/dist/bin/customer-readiness.js +33 -0
  9. package/dist/bin/exe-agent-config.js +2 -2
  10. package/dist/bin/exe-agent.js +3 -3
  11. package/dist/bin/exe-assign.js +282 -7
  12. package/dist/bin/exe-boot.js +125 -13
  13. package/dist/bin/exe-call.js +3 -3
  14. package/dist/bin/exe-cloud.js +2 -2
  15. package/dist/bin/exe-dispatch.js +282 -7
  16. package/dist/bin/exe-doctor.js +119 -7
  17. package/dist/bin/exe-export-behaviors.js +282 -7
  18. package/dist/bin/exe-forget.js +336 -7
  19. package/dist/bin/exe-gateway.js +282 -7
  20. package/dist/bin/exe-heartbeat.js +284 -9
  21. package/dist/bin/exe-kill.js +282 -7
  22. package/dist/bin/exe-launch-agent.js +282 -7
  23. package/dist/bin/exe-link.js +121 -9
  24. package/dist/bin/exe-new-employee.js +50 -21
  25. package/dist/bin/exe-pending-messages.js +282 -7
  26. package/dist/bin/exe-pending-notifications.js +282 -7
  27. package/dist/bin/exe-pending-reviews.js +282 -7
  28. package/dist/bin/exe-rename.js +282 -7
  29. package/dist/bin/exe-review.js +282 -7
  30. package/dist/bin/exe-search.js +306 -8
  31. package/dist/bin/exe-session-cleanup.js +282 -7
  32. package/dist/bin/exe-settings.js +2 -2
  33. package/dist/bin/exe-start-codex.js +326 -21
  34. package/dist/bin/exe-start-opencode.js +304 -10
  35. package/dist/bin/exe-status.js +282 -7
  36. package/dist/bin/exe-team.js +282 -7
  37. package/dist/bin/git-sweep.js +282 -7
  38. package/dist/bin/graph-backfill.js +282 -7
  39. package/dist/bin/graph-export.js +282 -7
  40. package/dist/bin/install.js +58 -33
  41. package/dist/bin/intercom-check.js +282 -7
  42. package/dist/bin/pre-build-guard.js +98 -0
  43. package/dist/bin/scan-tasks.js +282 -7
  44. package/dist/bin/setup.js +122 -10
  45. package/dist/bin/shard-migrate.js +282 -7
  46. package/dist/bin/stack-update.js +79 -11
  47. package/dist/bin/update.js +2 -2
  48. package/dist/gateway/index.js +288 -13
  49. package/dist/hooks/bug-report-worker.js +282 -7
  50. package/dist/hooks/codex-stop-task-finalizer.js +282 -7
  51. package/dist/hooks/commit-complete.js +282 -7
  52. package/dist/hooks/error-recall.js +306 -8
  53. package/dist/hooks/exe-heartbeat-hook.js +2 -2
  54. package/dist/hooks/ingest-worker.js +2 -2
  55. package/dist/hooks/ingest.js +282 -7
  56. package/dist/hooks/instructions-loaded.js +282 -7
  57. package/dist/hooks/notification.js +282 -7
  58. package/dist/hooks/post-compact.js +282 -7
  59. package/dist/hooks/post-tool-combined.js +306 -8
  60. package/dist/hooks/pre-compact.js +282 -7
  61. package/dist/hooks/pre-tool-use.js +282 -7
  62. package/dist/hooks/prompt-submit.js +306 -8
  63. package/dist/hooks/session-end.js +282 -7
  64. package/dist/hooks/session-start.js +308 -10
  65. package/dist/hooks/stop.js +282 -7
  66. package/dist/hooks/subagent-stop.js +282 -7
  67. package/dist/hooks/summary-worker.js +125 -13
  68. package/dist/index.js +288 -13
  69. package/dist/lib/agent-config.js +2 -2
  70. package/dist/lib/cloud-sync.js +121 -9
  71. package/dist/lib/config.js +2 -2
  72. package/dist/lib/consolidation.js +2 -2
  73. package/dist/lib/database.js +115 -3
  74. package/dist/lib/db-daemon-client.js +2 -2
  75. package/dist/lib/db.js +115 -3
  76. package/dist/lib/device-registry.js +115 -3
  77. package/dist/lib/embedder.js +2 -2
  78. package/dist/lib/employee-templates.js +3 -3
  79. package/dist/lib/employees.js +2 -2
  80. package/dist/lib/exe-daemon-client.js +2 -2
  81. package/dist/lib/exe-daemon.js +339 -31
  82. package/dist/lib/hybrid-search.js +306 -8
  83. package/dist/lib/identity.js +2 -2
  84. package/dist/lib/license.js +2 -2
  85. package/dist/lib/messaging.js +2 -2
  86. package/dist/lib/reminders.js +2 -2
  87. package/dist/lib/schedules.js +119 -7
  88. package/dist/lib/skill-learning.js +2 -2
  89. package/dist/lib/store.js +282 -7
  90. package/dist/lib/task-router.js +2 -2
  91. package/dist/lib/tasks.js +2 -2
  92. package/dist/lib/tmux-routing.js +2 -2
  93. package/dist/lib/token-spend.js +2 -2
  94. package/dist/mcp/server.js +339 -31
  95. package/dist/mcp/tools/complete-reminder.js +2 -2
  96. package/dist/mcp/tools/create-reminder.js +2 -2
  97. package/dist/mcp/tools/create-task.js +2 -2
  98. package/dist/mcp/tools/deactivate-behavior.js +2 -2
  99. package/dist/mcp/tools/list-reminders.js +2 -2
  100. package/dist/mcp/tools/list-tasks.js +2 -2
  101. package/dist/mcp/tools/send-message.js +2 -2
  102. package/dist/mcp/tools/update-task.js +2 -2
  103. package/dist/runtime/index.js +282 -7
  104. package/dist/tui/App.js +290 -15
  105. package/package.json +3 -2
  106. package/stack.release.json +23 -7
@@ -202,8 +202,8 @@ var init_config = __esm({
202
202
  rerankerAutoTrigger: {
203
203
  enabled: true,
204
204
  broadQueryMinCardinality: 5e4,
205
- fetchTopK: 150,
206
- returnTopK: 5
205
+ fetchTopK: 200,
206
+ returnTopK: 20
207
207
  }
208
208
  },
209
209
  graphRagEnabled: true,
@@ -2808,7 +2808,7 @@ async function ensureSchema() {
2808
2808
  ON session_kills(agent_id);
2809
2809
  `);
2810
2810
  await client.execute(`
2811
- CREATE TABLE IF NOT EXISTS global_procedures (
2811
+ CREATE TABLE IF NOT EXISTS company_procedures (
2812
2812
  id TEXT PRIMARY KEY,
2813
2813
  title TEXT NOT NULL,
2814
2814
  content TEXT NOT NULL,
@@ -2819,6 +2819,73 @@ async function ensureSchema() {
2819
2819
  updated_at TEXT NOT NULL
2820
2820
  )
2821
2821
  `);
2822
+ const legacyProcedureObject = await client.execute({
2823
+ sql: "SELECT type FROM sqlite_master WHERE name = 'global_procedures'",
2824
+ args: []
2825
+ });
2826
+ const legacyProcedureType = legacyProcedureObject.rows[0]?.type == null ? null : String(legacyProcedureObject.rows[0].type);
2827
+ if (legacyProcedureType === "table") {
2828
+ await client.execute(`
2829
+ INSERT OR IGNORE INTO company_procedures
2830
+ (id, title, content, priority, domain, active, created_at, updated_at)
2831
+ SELECT id, title, content, priority, domain, active, created_at, updated_at
2832
+ FROM global_procedures
2833
+ `);
2834
+ await client.executeMultiple(`
2835
+ CREATE TRIGGER IF NOT EXISTS global_procedures_mirror_insert
2836
+ AFTER INSERT ON global_procedures
2837
+ BEGIN
2838
+ INSERT OR IGNORE INTO company_procedures
2839
+ (id, title, content, priority, domain, active, created_at, updated_at)
2840
+ VALUES
2841
+ (NEW.id, NEW.title, NEW.content, NEW.priority, NEW.domain, NEW.active, NEW.created_at, NEW.updated_at);
2842
+ END;
2843
+
2844
+ CREATE TRIGGER IF NOT EXISTS global_procedures_mirror_update
2845
+ AFTER UPDATE ON global_procedures
2846
+ BEGIN
2847
+ UPDATE company_procedures
2848
+ SET title = NEW.title,
2849
+ content = NEW.content,
2850
+ priority = NEW.priority,
2851
+ domain = NEW.domain,
2852
+ active = NEW.active,
2853
+ created_at = NEW.created_at,
2854
+ updated_at = NEW.updated_at
2855
+ WHERE id = OLD.id;
2856
+ END;
2857
+ `);
2858
+ } else {
2859
+ await client.execute(`
2860
+ CREATE VIEW IF NOT EXISTS global_procedures AS
2861
+ SELECT id, title, content, priority, domain, active, created_at, updated_at
2862
+ FROM company_procedures
2863
+ `);
2864
+ await client.executeMultiple(`
2865
+ CREATE TRIGGER IF NOT EXISTS global_procedures_insert
2866
+ INSTEAD OF INSERT ON global_procedures
2867
+ BEGIN
2868
+ INSERT INTO company_procedures
2869
+ (id, title, content, priority, domain, active, created_at, updated_at)
2870
+ VALUES
2871
+ (NEW.id, NEW.title, NEW.content, NEW.priority, NEW.domain, NEW.active, NEW.created_at, NEW.updated_at);
2872
+ END;
2873
+
2874
+ CREATE TRIGGER IF NOT EXISTS global_procedures_update
2875
+ INSTEAD OF UPDATE ON global_procedures
2876
+ BEGIN
2877
+ UPDATE company_procedures
2878
+ SET title = NEW.title,
2879
+ content = NEW.content,
2880
+ priority = NEW.priority,
2881
+ domain = NEW.domain,
2882
+ active = NEW.active,
2883
+ created_at = NEW.created_at,
2884
+ updated_at = NEW.updated_at
2885
+ WHERE id = OLD.id;
2886
+ END;
2887
+ `);
2888
+ }
2822
2889
  await client.executeMultiple(`
2823
2890
  CREATE TABLE IF NOT EXISTS conversations (
2824
2891
  id TEXT PRIMARY KEY,
@@ -2958,6 +3025,51 @@ async function ensureSchema() {
2958
3025
  VALUES (new.rowid, new.content_text, new.sender_name, new.agent_response);
2959
3026
  END;
2960
3027
  `);
3028
+ await client.executeMultiple(`
3029
+ CREATE TABLE IF NOT EXISTS memory_cards (
3030
+ id TEXT PRIMARY KEY,
3031
+ memory_id TEXT NOT NULL,
3032
+ agent_id TEXT NOT NULL,
3033
+ session_id TEXT NOT NULL,
3034
+ project_name TEXT,
3035
+ timestamp TEXT NOT NULL,
3036
+ card_type TEXT NOT NULL,
3037
+ subject TEXT,
3038
+ predicate TEXT,
3039
+ object TEXT,
3040
+ content TEXT NOT NULL,
3041
+ source_ref TEXT,
3042
+ confidence REAL DEFAULT 0.6,
3043
+ active INTEGER DEFAULT 1,
3044
+ created_at TEXT NOT NULL
3045
+ );
3046
+
3047
+ CREATE INDEX IF NOT EXISTS idx_memory_cards_agent
3048
+ ON memory_cards(agent_id, active, timestamp);
3049
+
3050
+ CREATE INDEX IF NOT EXISTS idx_memory_cards_memory
3051
+ ON memory_cards(memory_id);
3052
+
3053
+ CREATE VIRTUAL TABLE IF NOT EXISTS memory_cards_fts
3054
+ USING fts5(content, subject, predicate, object, content='memory_cards', content_rowid='rowid');
3055
+
3056
+ CREATE TRIGGER IF NOT EXISTS memory_cards_fts_ai AFTER INSERT ON memory_cards BEGIN
3057
+ INSERT INTO memory_cards_fts(rowid, content, subject, predicate, object)
3058
+ VALUES (new.rowid, new.content, new.subject, new.predicate, new.object);
3059
+ END;
3060
+
3061
+ CREATE TRIGGER IF NOT EXISTS memory_cards_fts_ad AFTER DELETE ON memory_cards BEGIN
3062
+ INSERT INTO memory_cards_fts(memory_cards_fts, rowid, content, subject, predicate, object)
3063
+ VALUES('delete', old.rowid, old.content, old.subject, old.predicate, old.object);
3064
+ END;
3065
+
3066
+ CREATE TRIGGER IF NOT EXISTS memory_cards_fts_au AFTER UPDATE ON memory_cards BEGIN
3067
+ INSERT INTO memory_cards_fts(memory_cards_fts, rowid, content, subject, predicate, object)
3068
+ VALUES('delete', old.rowid, old.content, old.subject, old.predicate, old.object);
3069
+ INSERT INTO memory_cards_fts(rowid, content, subject, predicate, object)
3070
+ VALUES (new.rowid, new.content, new.subject, new.predicate, new.object);
3071
+ END;
3072
+ `);
2961
3073
  try {
2962
3074
  await client.execute({
2963
3075
  sql: `ALTER TABLE memories ADD COLUMN tier INTEGER DEFAULT 3`,
@@ -4310,7 +4422,7 @@ var init_platform_procedures = __esm({
4310
4422
  title: "MCP tools \u2014 advanced (triggers, skills, orchestration)",
4311
4423
  domain: "tool-use",
4312
4424
  priority: "p1",
4313
- content: "create_trigger: set up a scheduled recurring agent job (cron). list_triggers: view active triggers. load_skill: load a slash-command skill dynamically. apply_starter_pack: import a pre-built behavior + identity pack for a role. export_orchestration: export full org state (tasks, behaviors, identities) as portable JSON. import_orchestration: import org state into a new instance. deploy_client: deploy a customer client instance. query_company_brain: unified RAG query across all company knowledge. create_reminder: set a text reminder (shown in boot brief). list_reminders: view pending reminders. complete_reminder: mark a reminder done. global_procedure: manage customer-owned company procedures (Layer 0; actions: store, list, deactivate). Legacy aliases: store_global_procedure, list_global_procedures, deactivate_global_procedure."
4425
+ content: "create_trigger: set up a scheduled recurring agent job (cron). list_triggers: view active triggers. load_skill: load a slash-command skill dynamically. apply_starter_pack: import a pre-built behavior + identity pack for a role. export_orchestration: export full org state (tasks, behaviors, identities) as portable JSON. import_orchestration: import org state into a new instance. deploy_client: deploy a customer client instance. query_company_brain: unified RAG query across all company knowledge. create_reminder: set a text reminder (shown in boot brief). list_reminders: view pending reminders. complete_reminder: mark a reminder done. company_procedure: manage customer-owned company procedures (Layer 0; actions: store, list, deactivate). Legacy aliases: global_procedure, store_global_procedure, list_global_procedures, deactivate_global_procedure."
4314
4426
  }
4315
4427
  ];
4316
4428
  PLATFORM_PROCEDURE_TITLES = new Set(
@@ -4331,7 +4443,7 @@ import { randomUUID as randomUUID3 } from "crypto";
4331
4443
  async function loadGlobalProcedures() {
4332
4444
  const client = getClient();
4333
4445
  const result = await client.execute({
4334
- sql: "SELECT * FROM global_procedures WHERE active = 1 ORDER BY priority ASC, created_at ASC",
4446
+ sql: "SELECT * FROM company_procedures WHERE active = 1 ORDER BY priority ASC, created_at ASC",
4335
4447
  args: []
4336
4448
  });
4337
4449
  const allRows = result.rows;
@@ -4360,7 +4472,7 @@ async function storeGlobalProcedure(input2) {
4360
4472
  const now = (/* @__PURE__ */ new Date()).toISOString();
4361
4473
  const client = getClient();
4362
4474
  await client.execute({
4363
- sql: `INSERT INTO global_procedures (id, title, content, priority, domain, active, created_at, updated_at)
4475
+ sql: `INSERT INTO company_procedures (id, title, content, priority, domain, active, created_at, updated_at)
4364
4476
  VALUES (?, ?, ?, ?, ?, 1, ?, ?)`,
4365
4477
  args: [id, input2.title, input2.content, input2.priority ?? "p0", input2.domain ?? null, now, now]
4366
4478
  });
@@ -4371,7 +4483,7 @@ async function deactivateGlobalProcedure(id) {
4371
4483
  const now = (/* @__PURE__ */ new Date()).toISOString();
4372
4484
  const client = getClient();
4373
4485
  const result = await client.execute({
4374
- sql: "UPDATE global_procedures SET active = 0, updated_at = ? WHERE id = ?",
4486
+ sql: "UPDATE company_procedures SET active = 0, updated_at = ? WHERE id = ?",
4375
4487
  args: [now, id]
4376
4488
  });
4377
4489
  await loadGlobalProcedures();
@@ -4390,6 +4502,164 @@ ${p.content}`).join("\n\n");
4390
4502
  }
4391
4503
  });
4392
4504
 
4505
+ // src/lib/memory-cards.ts
4506
+ var memory_cards_exports = {};
4507
+ __export(memory_cards_exports, {
4508
+ extractMemoryCards: () => extractMemoryCards,
4509
+ insertMemoryCardsForBatch: () => insertMemoryCardsForBatch,
4510
+ searchMemoryCards: () => searchMemoryCards
4511
+ });
4512
+ import { createHash as createHash2 } from "crypto";
4513
+ function stableId(memoryId, type, content) {
4514
+ return createHash2("sha256").update(`${memoryId}:${type}:${content}`).digest("hex").slice(0, 32);
4515
+ }
4516
+ function cleanText(text) {
4517
+ return text.replace(/```[\s\S]*?```/g, " ").replace(/<[^>]+>/g, " ").replace(/\s+/g, " ").trim();
4518
+ }
4519
+ function splitSentences(text) {
4520
+ return cleanText(text).split(/(?<=[.!?])\s+|\n+/).map((s) => s.trim()).filter((s) => s.length >= 24 && s.length <= MAX_SENTENCE_CHARS);
4521
+ }
4522
+ function inferCardType(sentence, toolName) {
4523
+ const lower = sentence.toLowerCase();
4524
+ if (toolName === "store_decision" || /\b(decided|decision|adr|approved|rejected)\b/.test(lower)) return "decision";
4525
+ if (/\b(prefers|preference|likes|dislikes|wants|doesn't want|does not want)\b/.test(lower)) return "preference";
4526
+ if (/\b(changed|updated|replaced|now|no longer|instead|supersedes)\b/.test(lower)) return "belief_update";
4527
+ if (toolName && ["Read", "Write", "Edit", "Bash"].includes(toolName)) return "code";
4528
+ if (/\b(meeting|deadline|shipped|launched|completed|failed|blocked|assigned|created)\b/.test(lower)) return "event";
4529
+ return "fact";
4530
+ }
4531
+ function extractSubject(sentence, agentId) {
4532
+ const explicit = sentence.match(/\b([A-Z][a-zA-Z0-9_-]{2,}(?:\s+[A-Z][a-zA-Z0-9_-]{2,})?)\b/);
4533
+ return explicit?.[1] ?? agentId;
4534
+ }
4535
+ function predicateFor(type) {
4536
+ switch (type) {
4537
+ case "preference":
4538
+ return "prefers";
4539
+ case "belief_update":
4540
+ return "updated";
4541
+ case "decision":
4542
+ return "decided";
4543
+ case "event":
4544
+ return "happened";
4545
+ case "code":
4546
+ return "implemented";
4547
+ default:
4548
+ return "states";
4549
+ }
4550
+ }
4551
+ function extractMemoryCards(row) {
4552
+ const sentences = splitSentences(row.raw_text);
4553
+ const cards = [];
4554
+ for (const sentence of sentences) {
4555
+ const type = inferCardType(sentence, row.tool_name);
4556
+ const subject = extractSubject(sentence, row.agent_id);
4557
+ const content = sentence.length > MAX_SENTENCE_CHARS ? `${sentence.slice(0, MAX_SENTENCE_CHARS - 1)}\u2026` : sentence;
4558
+ cards.push({
4559
+ id: stableId(row.id, type, content),
4560
+ memory_id: row.id,
4561
+ agent_id: row.agent_id,
4562
+ session_id: row.session_id,
4563
+ project_name: row.project_name ?? null,
4564
+ timestamp: row.timestamp,
4565
+ card_type: type,
4566
+ subject,
4567
+ predicate: predicateFor(type),
4568
+ object: content,
4569
+ content,
4570
+ source_ref: row.id,
4571
+ confidence: type === "fact" ? 0.55 : 0.65
4572
+ });
4573
+ if (cards.length >= MAX_CARDS_PER_MEMORY) break;
4574
+ }
4575
+ return cards;
4576
+ }
4577
+ async function insertMemoryCardsForBatch(rows) {
4578
+ const cards = rows.flatMap(extractMemoryCards);
4579
+ if (cards.length === 0) return 0;
4580
+ const now = (/* @__PURE__ */ new Date()).toISOString();
4581
+ const client = getClient();
4582
+ const stmts = cards.map((card) => ({
4583
+ sql: `INSERT OR IGNORE INTO memory_cards
4584
+ (id, memory_id, agent_id, session_id, project_name, timestamp, card_type,
4585
+ subject, predicate, object, content, source_ref, confidence, active, created_at)
4586
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1, ?)`,
4587
+ args: [
4588
+ card.id,
4589
+ card.memory_id,
4590
+ card.agent_id,
4591
+ card.session_id,
4592
+ card.project_name,
4593
+ card.timestamp,
4594
+ card.card_type,
4595
+ card.subject,
4596
+ card.predicate,
4597
+ card.object,
4598
+ card.content,
4599
+ card.source_ref,
4600
+ card.confidence,
4601
+ now
4602
+ ]
4603
+ }));
4604
+ await client.batch(stmts, "write");
4605
+ return cards.length;
4606
+ }
4607
+ function buildMatchExpr(queryText) {
4608
+ const terms = queryText.toLowerCase().split(/\s+/).filter((t) => t.length >= 3).map((t) => t.replace(/[^a-z0-9_]/g, "")).filter((t) => t.length >= 3).slice(0, 12);
4609
+ if (terms.length === 0) return null;
4610
+ return terms.map((t) => `${t}*`).join(terms.length >= 3 ? " AND " : " OR ");
4611
+ }
4612
+ async function searchMemoryCards(queryText, agentId, options) {
4613
+ const limit = options?.limit ?? 10;
4614
+ const matchExpr = buildMatchExpr(queryText);
4615
+ if (!matchExpr) return [];
4616
+ let sql = `SELECT c.id, c.memory_id, c.agent_id, c.session_id, c.project_name,
4617
+ c.timestamp, c.card_type, c.content, c.source_ref, c.confidence
4618
+ FROM memory_cards c
4619
+ JOIN memory_cards_fts fts ON c.rowid = fts.rowid
4620
+ WHERE memory_cards_fts MATCH ?
4621
+ AND c.agent_id = ?
4622
+ AND COALESCE(c.active, 1) = 1`;
4623
+ const args = [matchExpr, agentId];
4624
+ if (options?.projectName) {
4625
+ sql += ` AND c.project_name = ?`;
4626
+ args.push(options.projectName);
4627
+ }
4628
+ if (options?.since) {
4629
+ sql += ` AND c.timestamp >= ?`;
4630
+ args.push(options.since);
4631
+ }
4632
+ sql += ` ORDER BY rank LIMIT ?`;
4633
+ args.push(limit);
4634
+ const result = await getClient().execute({ sql, args });
4635
+ return result.rows.map((row) => ({
4636
+ id: `card:${String(row.id)}`,
4637
+ agent_id: String(row.agent_id),
4638
+ agent_role: "memory_card",
4639
+ session_id: String(row.session_id),
4640
+ timestamp: String(row.timestamp),
4641
+ tool_name: `memory_card:${String(row.card_type)}`,
4642
+ project_name: row.project_name == null ? "" : String(row.project_name),
4643
+ has_error: false,
4644
+ raw_text: `[${String(row.card_type)}] ${String(row.content)}
4645
+ Source memory: ${String(row.source_ref ?? row.memory_id)}`,
4646
+ vector: [],
4647
+ importance: 6,
4648
+ status: "active",
4649
+ confidence: Number(row.confidence ?? 0.6),
4650
+ last_accessed: String(row.timestamp)
4651
+ }));
4652
+ }
4653
+ var MAX_CARDS_PER_MEMORY, MAX_SENTENCE_CHARS;
4654
+ var init_memory_cards = __esm({
4655
+ "src/lib/memory-cards.ts"() {
4656
+ "use strict";
4657
+ init_database();
4658
+ MAX_CARDS_PER_MEMORY = 6;
4659
+ MAX_SENTENCE_CHARS = 360;
4660
+ }
4661
+ });
4662
+
4393
4663
  // src/lib/store.ts
4394
4664
  var store_exports = {};
4395
4665
  __export(store_exports, {
@@ -4728,6 +4998,11 @@ async function flushBatch() {
4728
4998
  const globalClient = getClient();
4729
4999
  const globalStmts = batch.map(buildStmt);
4730
5000
  await globalClient.batch(globalStmts, "write");
5001
+ try {
5002
+ const { insertMemoryCardsForBatch: insertMemoryCardsForBatch2 } = await Promise.resolve().then(() => (init_memory_cards(), memory_cards_exports));
5003
+ await insertMemoryCardsForBatch2(batch);
5004
+ } catch {
5005
+ }
4731
5006
  schedulePostWriteMemoryHygiene(batch.map((row) => row.id));
4732
5007
  _pendingRecords.splice(0, batch.length);
4733
5008
  try {
@@ -321,8 +321,8 @@ var init_config = __esm({
321
321
  rerankerAutoTrigger: {
322
322
  enabled: true,
323
323
  broadQueryMinCardinality: 5e4,
324
- fetchTopK: 150,
325
- returnTopK: 5
324
+ fetchTopK: 200,
325
+ returnTopK: 20
326
326
  }
327
327
  },
328
328
  graphRagEnabled: true,
@@ -2565,7 +2565,7 @@ async function ensureSchema() {
2565
2565
  ON session_kills(agent_id);
2566
2566
  `);
2567
2567
  await client.execute(`
2568
- CREATE TABLE IF NOT EXISTS global_procedures (
2568
+ CREATE TABLE IF NOT EXISTS company_procedures (
2569
2569
  id TEXT PRIMARY KEY,
2570
2570
  title TEXT NOT NULL,
2571
2571
  content TEXT NOT NULL,
@@ -2576,6 +2576,73 @@ async function ensureSchema() {
2576
2576
  updated_at TEXT NOT NULL
2577
2577
  )
2578
2578
  `);
2579
+ const legacyProcedureObject = await client.execute({
2580
+ sql: "SELECT type FROM sqlite_master WHERE name = 'global_procedures'",
2581
+ args: []
2582
+ });
2583
+ const legacyProcedureType = legacyProcedureObject.rows[0]?.type == null ? null : String(legacyProcedureObject.rows[0].type);
2584
+ if (legacyProcedureType === "table") {
2585
+ await client.execute(`
2586
+ INSERT OR IGNORE INTO company_procedures
2587
+ (id, title, content, priority, domain, active, created_at, updated_at)
2588
+ SELECT id, title, content, priority, domain, active, created_at, updated_at
2589
+ FROM global_procedures
2590
+ `);
2591
+ await client.executeMultiple(`
2592
+ CREATE TRIGGER IF NOT EXISTS global_procedures_mirror_insert
2593
+ AFTER INSERT ON global_procedures
2594
+ BEGIN
2595
+ INSERT OR IGNORE INTO company_procedures
2596
+ (id, title, content, priority, domain, active, created_at, updated_at)
2597
+ VALUES
2598
+ (NEW.id, NEW.title, NEW.content, NEW.priority, NEW.domain, NEW.active, NEW.created_at, NEW.updated_at);
2599
+ END;
2600
+
2601
+ CREATE TRIGGER IF NOT EXISTS global_procedures_mirror_update
2602
+ AFTER UPDATE ON global_procedures
2603
+ BEGIN
2604
+ UPDATE company_procedures
2605
+ SET title = NEW.title,
2606
+ content = NEW.content,
2607
+ priority = NEW.priority,
2608
+ domain = NEW.domain,
2609
+ active = NEW.active,
2610
+ created_at = NEW.created_at,
2611
+ updated_at = NEW.updated_at
2612
+ WHERE id = OLD.id;
2613
+ END;
2614
+ `);
2615
+ } else {
2616
+ await client.execute(`
2617
+ CREATE VIEW IF NOT EXISTS global_procedures AS
2618
+ SELECT id, title, content, priority, domain, active, created_at, updated_at
2619
+ FROM company_procedures
2620
+ `);
2621
+ await client.executeMultiple(`
2622
+ CREATE TRIGGER IF NOT EXISTS global_procedures_insert
2623
+ INSTEAD OF INSERT ON global_procedures
2624
+ BEGIN
2625
+ INSERT INTO company_procedures
2626
+ (id, title, content, priority, domain, active, created_at, updated_at)
2627
+ VALUES
2628
+ (NEW.id, NEW.title, NEW.content, NEW.priority, NEW.domain, NEW.active, NEW.created_at, NEW.updated_at);
2629
+ END;
2630
+
2631
+ CREATE TRIGGER IF NOT EXISTS global_procedures_update
2632
+ INSTEAD OF UPDATE ON global_procedures
2633
+ BEGIN
2634
+ UPDATE company_procedures
2635
+ SET title = NEW.title,
2636
+ content = NEW.content,
2637
+ priority = NEW.priority,
2638
+ domain = NEW.domain,
2639
+ active = NEW.active,
2640
+ created_at = NEW.created_at,
2641
+ updated_at = NEW.updated_at
2642
+ WHERE id = OLD.id;
2643
+ END;
2644
+ `);
2645
+ }
2579
2646
  await client.executeMultiple(`
2580
2647
  CREATE TABLE IF NOT EXISTS conversations (
2581
2648
  id TEXT PRIMARY KEY,
@@ -2715,6 +2782,51 @@ async function ensureSchema() {
2715
2782
  VALUES (new.rowid, new.content_text, new.sender_name, new.agent_response);
2716
2783
  END;
2717
2784
  `);
2785
+ await client.executeMultiple(`
2786
+ CREATE TABLE IF NOT EXISTS memory_cards (
2787
+ id TEXT PRIMARY KEY,
2788
+ memory_id TEXT NOT NULL,
2789
+ agent_id TEXT NOT NULL,
2790
+ session_id TEXT NOT NULL,
2791
+ project_name TEXT,
2792
+ timestamp TEXT NOT NULL,
2793
+ card_type TEXT NOT NULL,
2794
+ subject TEXT,
2795
+ predicate TEXT,
2796
+ object TEXT,
2797
+ content TEXT NOT NULL,
2798
+ source_ref TEXT,
2799
+ confidence REAL DEFAULT 0.6,
2800
+ active INTEGER DEFAULT 1,
2801
+ created_at TEXT NOT NULL
2802
+ );
2803
+
2804
+ CREATE INDEX IF NOT EXISTS idx_memory_cards_agent
2805
+ ON memory_cards(agent_id, active, timestamp);
2806
+
2807
+ CREATE INDEX IF NOT EXISTS idx_memory_cards_memory
2808
+ ON memory_cards(memory_id);
2809
+
2810
+ CREATE VIRTUAL TABLE IF NOT EXISTS memory_cards_fts
2811
+ USING fts5(content, subject, predicate, object, content='memory_cards', content_rowid='rowid');
2812
+
2813
+ CREATE TRIGGER IF NOT EXISTS memory_cards_fts_ai AFTER INSERT ON memory_cards BEGIN
2814
+ INSERT INTO memory_cards_fts(rowid, content, subject, predicate, object)
2815
+ VALUES (new.rowid, new.content, new.subject, new.predicate, new.object);
2816
+ END;
2817
+
2818
+ CREATE TRIGGER IF NOT EXISTS memory_cards_fts_ad AFTER DELETE ON memory_cards BEGIN
2819
+ INSERT INTO memory_cards_fts(memory_cards_fts, rowid, content, subject, predicate, object)
2820
+ VALUES('delete', old.rowid, old.content, old.subject, old.predicate, old.object);
2821
+ END;
2822
+
2823
+ CREATE TRIGGER IF NOT EXISTS memory_cards_fts_au AFTER UPDATE ON memory_cards BEGIN
2824
+ INSERT INTO memory_cards_fts(memory_cards_fts, rowid, content, subject, predicate, object)
2825
+ VALUES('delete', old.rowid, old.content, old.subject, old.predicate, old.object);
2826
+ INSERT INTO memory_cards_fts(rowid, content, subject, predicate, object)
2827
+ VALUES (new.rowid, new.content, new.subject, new.predicate, new.object);
2828
+ END;
2829
+ `);
2718
2830
  try {
2719
2831
  await client.execute({
2720
2832
  sql: `ALTER TABLE memories ADD COLUMN tier INTEGER DEFAULT 3`,
@@ -3828,7 +3940,7 @@ var init_platform_procedures = __esm({
3828
3940
  title: "MCP tools \u2014 advanced (triggers, skills, orchestration)",
3829
3941
  domain: "tool-use",
3830
3942
  priority: "p1",
3831
- content: "create_trigger: set up a scheduled recurring agent job (cron). list_triggers: view active triggers. load_skill: load a slash-command skill dynamically. apply_starter_pack: import a pre-built behavior + identity pack for a role. export_orchestration: export full org state (tasks, behaviors, identities) as portable JSON. import_orchestration: import org state into a new instance. deploy_client: deploy a customer client instance. query_company_brain: unified RAG query across all company knowledge. create_reminder: set a text reminder (shown in boot brief). list_reminders: view pending reminders. complete_reminder: mark a reminder done. global_procedure: manage customer-owned company procedures (Layer 0; actions: store, list, deactivate). Legacy aliases: store_global_procedure, list_global_procedures, deactivate_global_procedure."
3943
+ content: "create_trigger: set up a scheduled recurring agent job (cron). list_triggers: view active triggers. load_skill: load a slash-command skill dynamically. apply_starter_pack: import a pre-built behavior + identity pack for a role. export_orchestration: export full org state (tasks, behaviors, identities) as portable JSON. import_orchestration: import org state into a new instance. deploy_client: deploy a customer client instance. query_company_brain: unified RAG query across all company knowledge. create_reminder: set a text reminder (shown in boot brief). list_reminders: view pending reminders. complete_reminder: mark a reminder done. company_procedure: manage customer-owned company procedures (Layer 0; actions: store, list, deactivate). Legacy aliases: global_procedure, store_global_procedure, list_global_procedures, deactivate_global_procedure."
3832
3944
  }
3833
3945
  ];
3834
3946
  PLATFORM_PROCEDURE_TITLES = new Set(
@@ -3849,7 +3961,7 @@ import { randomUUID as randomUUID2 } from "crypto";
3849
3961
  async function loadGlobalProcedures() {
3850
3962
  const client = getClient();
3851
3963
  const result = await client.execute({
3852
- sql: "SELECT * FROM global_procedures WHERE active = 1 ORDER BY priority ASC, created_at ASC",
3964
+ sql: "SELECT * FROM company_procedures WHERE active = 1 ORDER BY priority ASC, created_at ASC",
3853
3965
  args: []
3854
3966
  });
3855
3967
  const allRows = result.rows;
@@ -3878,7 +3990,7 @@ async function storeGlobalProcedure(input) {
3878
3990
  const now = (/* @__PURE__ */ new Date()).toISOString();
3879
3991
  const client = getClient();
3880
3992
  await client.execute({
3881
- sql: `INSERT INTO global_procedures (id, title, content, priority, domain, active, created_at, updated_at)
3993
+ sql: `INSERT INTO company_procedures (id, title, content, priority, domain, active, created_at, updated_at)
3882
3994
  VALUES (?, ?, ?, ?, ?, 1, ?, ?)`,
3883
3995
  args: [id, input.title, input.content, input.priority ?? "p0", input.domain ?? null, now, now]
3884
3996
  });
@@ -3889,7 +4001,7 @@ async function deactivateGlobalProcedure(id) {
3889
4001
  const now = (/* @__PURE__ */ new Date()).toISOString();
3890
4002
  const client = getClient();
3891
4003
  const result = await client.execute({
3892
- sql: "UPDATE global_procedures SET active = 0, updated_at = ? WHERE id = ?",
4004
+ sql: "UPDATE company_procedures SET active = 0, updated_at = ? WHERE id = ?",
3893
4005
  args: [now, id]
3894
4006
  });
3895
4007
  await loadGlobalProcedures();
@@ -5950,12 +6062,12 @@ async function cloudSync(config) {
5950
6062
  try {
5951
6063
  await cloudPushGlobalProcedures(config);
5952
6064
  } catch (err) {
5953
- logError(`[cloud-sync] Global procedures push: ${err instanceof Error ? err.message : String(err)}`);
6065
+ logError(`[cloud-sync] Company procedures push: ${err instanceof Error ? err.message : String(err)}`);
5954
6066
  }
5955
6067
  try {
5956
6068
  await cloudPullGlobalProcedures(config);
5957
6069
  } catch (err) {
5958
- logError(`[cloud-sync] Global procedures pull: ${err instanceof Error ? err.message : String(err)}`);
6070
+ logError(`[cloud-sync] Company procedures pull: ${err instanceof Error ? err.message : String(err)}`);
5959
6071
  }
5960
6072
  const countRows = async (sql) => {
5961
6073
  try {
@@ -6364,12 +6476,12 @@ async function cloudPullBlob(route, config) {
6364
6476
  }
6365
6477
  async function cloudPushGlobalProcedures(config) {
6366
6478
  const client = getClient();
6367
- const result = await client.execute("SELECT * FROM global_procedures LIMIT 1000");
6479
+ const result = await client.execute("SELECT * FROM company_procedures LIMIT 1000");
6368
6480
  const rows = result.rows;
6369
6481
  const { ok } = await cloudPushBlob(
6370
6482
  "/sync/push-global-procedures",
6371
6483
  rows,
6372
- "last_global_procedures_push_version",
6484
+ "last_company_procedures_push_version",
6373
6485
  config
6374
6486
  );
6375
6487
  return ok;
@@ -6382,7 +6494,7 @@ async function cloudPullGlobalProcedures(config) {
6382
6494
  if (!remoteProcs || remoteProcs.length === 0) return { pulled: 0 };
6383
6495
  const client = getClient();
6384
6496
  const stmts = remoteProcs.map((p) => ({
6385
- sql: `INSERT INTO global_procedures
6497
+ sql: `INSERT INTO company_procedures
6386
6498
  (id, title, content, priority, domain, active, created_at, updated_at)
6387
6499
  VALUES (?, ?, ?, ?, ?, ?, ?, ?)
6388
6500
  ON CONFLICT(id) DO UPDATE SET
@@ -6392,7 +6504,7 @@ async function cloudPullGlobalProcedures(config) {
6392
6504
  domain = excluded.domain,
6393
6505
  active = excluded.active,
6394
6506
  updated_at = excluded.updated_at
6395
- WHERE excluded.updated_at > global_procedures.updated_at`,
6507
+ WHERE excluded.updated_at > company_procedures.updated_at`,
6396
6508
  args: [
6397
6509
  sqlSafe(p.id),
6398
6510
  sqlSafe(p.title),