@askexenow/exe-os 0.9.112 → 0.9.114

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 (96) hide show
  1. package/README.md +9 -7
  2. package/dist/bin/agentic-ontology-backfill.js +78 -23
  3. package/dist/bin/agentic-reflection-backfill.js +53 -13
  4. package/dist/bin/agentic-semantic-label.js +53 -13
  5. package/dist/bin/backfill-conversations.js +77 -22
  6. package/dist/bin/backfill-responses.js +78 -23
  7. package/dist/bin/backfill-vectors.js +53 -13
  8. package/dist/bin/bulk-sync-postgres.js +78 -23
  9. package/dist/bin/cleanup-stale-review-tasks.js +98 -26
  10. package/dist/bin/cli.js +388 -97
  11. package/dist/bin/exe-agent-config.js +7 -1
  12. package/dist/bin/exe-agent.js +55 -2
  13. package/dist/bin/exe-assign.js +78 -23
  14. package/dist/bin/exe-boot.js +524 -161
  15. package/dist/bin/exe-call.js +53 -4
  16. package/dist/bin/exe-cloud.js +127 -26
  17. package/dist/bin/exe-dispatch.js +402 -39
  18. package/dist/bin/exe-doctor.js +76 -21
  19. package/dist/bin/exe-export-behaviors.js +77 -22
  20. package/dist/bin/exe-forget.js +77 -22
  21. package/dist/bin/exe-gateway.js +161 -38
  22. package/dist/bin/exe-heartbeat.js +98 -26
  23. package/dist/bin/exe-kill.js +77 -22
  24. package/dist/bin/exe-launch-agent.js +173 -29
  25. package/dist/bin/exe-new-employee.js +183 -7
  26. package/dist/bin/exe-pending-messages.js +98 -26
  27. package/dist/bin/exe-pending-notifications.js +98 -26
  28. package/dist/bin/exe-pending-reviews.js +98 -26
  29. package/dist/bin/exe-rename.js +77 -22
  30. package/dist/bin/exe-review.js +77 -22
  31. package/dist/bin/exe-search.js +77 -22
  32. package/dist/bin/exe-session-cleanup.js +523 -160
  33. package/dist/bin/exe-settings.js +10 -4
  34. package/dist/bin/exe-start-codex.js +554 -255
  35. package/dist/bin/exe-start-opencode.js +564 -175
  36. package/dist/bin/exe-status.js +98 -26
  37. package/dist/bin/exe-support.js +1 -1
  38. package/dist/bin/exe-team.js +77 -22
  39. package/dist/bin/git-sweep.js +402 -39
  40. package/dist/bin/graph-backfill.js +78 -23
  41. package/dist/bin/graph-export.js +77 -22
  42. package/dist/bin/install.js +70 -4
  43. package/dist/bin/intercom-check.js +523 -160
  44. package/dist/bin/pre-publish.js +13 -1
  45. package/dist/bin/scan-tasks.js +402 -39
  46. package/dist/bin/setup.js +151 -24
  47. package/dist/bin/shard-migrate.js +78 -23
  48. package/dist/bin/stack-update.js +1 -1
  49. package/dist/bin/update.js +3 -3
  50. package/dist/gateway/index.js +161 -38
  51. package/dist/hooks/bug-report-worker.js +161 -38
  52. package/dist/hooks/codex-stop-task-finalizer.js +542 -150
  53. package/dist/hooks/commit-complete.js +402 -39
  54. package/dist/hooks/error-recall.js +77 -22
  55. package/dist/hooks/ingest.js +4592 -251
  56. package/dist/hooks/instructions-loaded.js +77 -22
  57. package/dist/hooks/notification.js +77 -22
  58. package/dist/hooks/post-compact.js +98 -26
  59. package/dist/hooks/post-tool-combined.js +98 -26
  60. package/dist/hooks/pre-compact.js +482 -119
  61. package/dist/hooks/pre-tool-use.js +148 -26
  62. package/dist/hooks/prompt-submit.js +162 -39
  63. package/dist/hooks/session-end.js +484 -124
  64. package/dist/hooks/session-start.js +135 -27
  65. package/dist/hooks/stop.js +97 -25
  66. package/dist/hooks/subagent-stop.js +98 -26
  67. package/dist/hooks/summary-worker.js +107 -18
  68. package/dist/index.js +188 -38
  69. package/dist/lib/agent-config.js +24 -1
  70. package/dist/lib/cloud-sync.js +72 -12
  71. package/dist/lib/consolidation.js +25 -2
  72. package/dist/lib/database.js +16 -0
  73. package/dist/lib/db.js +16 -0
  74. package/dist/lib/device-registry.js +16 -0
  75. package/dist/lib/employee-templates.js +29 -3
  76. package/dist/lib/employees.js +24 -1
  77. package/dist/lib/exe-daemon.js +441 -58
  78. package/dist/lib/hybrid-search.js +77 -22
  79. package/dist/lib/keychain.js +24 -12
  80. package/dist/lib/license.js +3 -3
  81. package/dist/lib/messaging.js +21 -4
  82. package/dist/lib/schedules.js +53 -13
  83. package/dist/lib/skill-learning.js +466 -70
  84. package/dist/lib/status-brief.js +14 -1
  85. package/dist/lib/store.js +78 -23
  86. package/dist/lib/tasks.js +403 -95
  87. package/dist/lib/tmux-routing.js +326 -18
  88. package/dist/mcp/server.js +213 -45
  89. package/dist/mcp/tools/create-task.js +85 -17
  90. package/dist/mcp/tools/deactivate-behavior.js +33 -24
  91. package/dist/mcp/tools/list-tasks.js +21 -4
  92. package/dist/mcp/tools/send-message.js +21 -4
  93. package/dist/mcp/tools/update-task.js +400 -95
  94. package/dist/runtime/index.js +506 -116
  95. package/dist/tui/App.js +268 -69
  96. package/package.json +1 -1
@@ -3174,6 +3174,22 @@ async function ensureSchema() {
3174
3174
  } catch (e) {
3175
3175
  logCatchDebug("migration", e);
3176
3176
  }
3177
+ try {
3178
+ await client.execute({
3179
+ sql: `ALTER TABLE memories ADD COLUMN visibility TEXT DEFAULT 'private'`,
3180
+ args: []
3181
+ });
3182
+ } catch (e) {
3183
+ logCatchDebug("migration", e);
3184
+ }
3185
+ try {
3186
+ await client.execute({
3187
+ sql: `ALTER TABLE memories ADD COLUMN strength REAL DEFAULT 1.0`,
3188
+ args: []
3189
+ });
3190
+ } catch (e) {
3191
+ logCatchDebug("migration", e);
3192
+ }
3177
3193
  }
3178
3194
  async function disposeDatabase() {
3179
3195
  if (_walCheckpointTimer) {
@@ -3740,11 +3756,17 @@ var init_platform_procedures = __esm({
3740
3756
  content: "Founder -> coordinator (the executive agent, internally routed as 'COO') -> CTO/CMO. CTO -> engineers. CMO -> content production. Never skip levels: the coordinator 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."
3741
3757
  },
3742
3758
  {
3743
- title: "Customer orchestration maturity \u2014 recommend, never trap",
3759
+ title: "Orchestration phase guidance \u2014 recommend, never trap",
3744
3760
  domain: "workflow",
3745
3761
  priority: "p1",
3746
3762
  content: "New customers start best in Phase 1: founder \u2194 coordinator/Chief of Staff, building company context. Suggest Phase 2 executives when domain work repeats; suggest Phase 3 parallel execution only when review/permission gates are ready. This is guidance, not a blocker: users may jump phases anytime. Never overwrite their phase, role titles, identities, or custom org design."
3747
3763
  },
3764
+ {
3765
+ title: "Routing slot vs display title \u2014 internal 'coo' is plumbing, not your name",
3766
+ domain: "identity",
3767
+ priority: "p0",
3768
+ content: "These procedures reference 'COO' as a shorthand for the coordinator role. This is an INTERNAL routing slot used by exe-os code (chain-of-command checks, dispatch logic, session detection). It is NOT your display title. Your actual title comes from your identity file's `title:` field \u2014 that is what you use externally: introductions, sign-offs, team comms, and any user-facing text. If your identity says `title: AI Chief of Staff`, you are the AI Chief of Staff. The routing slot stays `role: coo` for code compatibility \u2014 never rename it, but also never introduce yourself as 'COO' unless your identity file explicitly says so. The founder chose your title; respect it."
3769
+ },
3748
3770
  {
3749
3771
  title: "Single dispatch path \u2014 create_task only",
3750
3772
  domain: "workflow",
@@ -3778,6 +3800,12 @@ var init_platform_procedures = __esm({
3778
3800
  priority: "p0",
3779
3801
  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."
3780
3802
  },
3803
+ {
3804
+ title: "Destructive operations \u2014 mandatory reviewer gate",
3805
+ domain: "security",
3806
+ priority: "p0",
3807
+ content: "Before ANY destructive operation (delete, remove, overwrite, drop, reset, force-push, truncate), you MUST: (1) Have your full task spec accessible \u2014 if you cannot read it, STOP and report to your reviewer. Never improvise destructive actions. (2) Confirm with your reviewer (assigned_by or COO) before executing. (3) If the task spec explicitly authorizes the operation, proceed \u2014 but log it. Violation = immediate task failure. This applies to ALL agents regardless of role."
3808
+ },
3781
3809
  {
3782
3810
  title: "Customer patch triage \u2014 upstream bug vs customization",
3783
3811
  domain: "support",
@@ -4063,10 +4091,24 @@ function stableId(memoryId, type, content) {
4063
4091
  return createHash2("sha256").update(`${memoryId}:${type}:${content}`).digest("hex").slice(0, 32);
4064
4092
  }
4065
4093
  function cleanText(text) {
4066
- return text.replace(/```[\s\S]*?```/g, " ").replace(/<[^>]+>/g, " ").replace(/\s+/g, " ").trim();
4067
- }
4068
- function splitSentences(text) {
4069
- return cleanText(text).split(/(?<=[.!?])\s+|\n+/).map((s) => s.trim()).filter((s) => s.length >= 24 && s.length <= MAX_SENTENCE_CHARS);
4094
+ let cleaned = text.replace(
4095
+ /```(\w*)\n(.*?)(?:\n[\s\S]*?)```/g,
4096
+ (_m, lang, firstLine) => `[code${lang ? `:${lang}` : ""}] ${firstLine.trim()}`
4097
+ );
4098
+ cleaned = cleaned.replace(/<[^>]+>/g, " ").replace(/\s+/g, " ").trim();
4099
+ return cleaned;
4100
+ }
4101
+ function splitSegments(text) {
4102
+ const cleaned = cleanText(text);
4103
+ const segments = cleaned.split(/(?<=[.!?:;])\s+|\n{2,}|(?<=\))\s+(?=[A-Z])|\s*[|│]\s*/).map((s) => s.trim()).filter((s) => s.length >= MIN_SEGMENT_CHARS && s.length <= MAX_SEGMENT_CHARS);
4104
+ if (segments.length === 0 && cleaned.length >= MIN_SEGMENT_CHARS) {
4105
+ const lines = cleaned.split(/\n+/).map((l) => l.trim()).filter((l) => l.length >= MIN_SEGMENT_CHARS && l.length <= MAX_SEGMENT_CHARS);
4106
+ if (lines.length > 0) return lines;
4107
+ if (cleaned.length >= MIN_SEGMENT_CHARS) {
4108
+ return [cleaned.slice(0, MAX_SEGMENT_CHARS)];
4109
+ }
4110
+ }
4111
+ return segments;
4070
4112
  }
4071
4113
  function inferCardType(sentence, toolName) {
4072
4114
  const lower = sentence.toLowerCase();
@@ -4098,12 +4140,12 @@ function predicateFor(type) {
4098
4140
  }
4099
4141
  }
4100
4142
  function extractMemoryCards(row) {
4101
- const sentences = splitSentences(row.raw_text);
4143
+ const segments = splitSegments(row.raw_text);
4102
4144
  const cards = [];
4103
- for (const sentence of sentences) {
4145
+ for (const sentence of segments) {
4104
4146
  const type = inferCardType(sentence, row.tool_name);
4105
4147
  const subject = extractSubject(sentence, row.agent_id);
4106
- const content = sentence.length > MAX_SENTENCE_CHARS ? `${sentence.slice(0, MAX_SENTENCE_CHARS - 1)}\u2026` : sentence;
4148
+ const content = sentence.length > MAX_SEGMENT_CHARS ? `${sentence.slice(0, MAX_SEGMENT_CHARS - 1)}\u2026` : sentence;
4107
4149
  cards.push({
4108
4150
  id: stableId(row.id, type, content),
4109
4151
  memory_id: row.id,
@@ -4199,13 +4241,14 @@ Source memory: ${String(row.source_ref ?? row.memory_id)}`,
4199
4241
  last_accessed: String(row.timestamp)
4200
4242
  }));
4201
4243
  }
4202
- var MAX_CARDS_PER_MEMORY, MAX_SENTENCE_CHARS;
4244
+ var MAX_CARDS_PER_MEMORY, MAX_SEGMENT_CHARS, MIN_SEGMENT_CHARS;
4203
4245
  var init_memory_cards = __esm({
4204
4246
  "src/lib/memory-cards.ts"() {
4205
4247
  "use strict";
4206
4248
  init_database();
4207
- MAX_CARDS_PER_MEMORY = 6;
4208
- MAX_SENTENCE_CHARS = 360;
4249
+ MAX_CARDS_PER_MEMORY = 8;
4250
+ MAX_SEGMENT_CHARS = 500;
4251
+ MIN_SEGMENT_CHARS = 20;
4209
4252
  }
4210
4253
  });
4211
4254
 
@@ -4490,7 +4533,7 @@ init_memory();
4490
4533
  init_database();
4491
4534
 
4492
4535
  // src/lib/keychain.ts
4493
- import { readFile as readFile3, writeFile as writeFile3, unlink, mkdir as mkdir3, chmod as chmod2 } from "fs/promises";
4536
+ import { readFile as readFile3, writeFile as writeFile3, unlink, mkdir as mkdir3, chmod as chmod2, rename, copyFile } from "fs/promises";
4494
4537
  import { existsSync as existsSync7, statSync as statSync3 } from "fs";
4495
4538
  import { execSync as execSync3 } from "child_process";
4496
4539
  import path6 from "path";
@@ -4529,12 +4572,14 @@ function linuxSecretAvailable() {
4529
4572
  function isRootOnlyTrustedServerKeyFile(keyPath) {
4530
4573
  if (process.platform !== "linux") return false;
4531
4574
  try {
4532
- const uid = typeof os5.userInfo().uid === "number" ? os5.userInfo().uid : -1;
4533
4575
  const st = statSync3(keyPath);
4534
4576
  if (!st.isFile() || (st.mode & 63) !== 0) return false;
4577
+ const uid = typeof os5.userInfo().uid === "number" ? os5.userInfo().uid : -1;
4535
4578
  if (uid === 0) return true;
4536
4579
  const exeOsDir = process.env.EXE_OS_DIR;
4537
- return Boolean(exeOsDir && path6.resolve(keyPath).startsWith(path6.resolve(exeOsDir) + path6.sep));
4580
+ if (exeOsDir && path6.resolve(keyPath).startsWith(path6.resolve(exeOsDir) + path6.sep)) return true;
4581
+ if (!linuxSecretAvailable()) return true;
4582
+ return false;
4538
4583
  } catch {
4539
4584
  return false;
4540
4585
  }
@@ -4685,15 +4730,25 @@ async function writeMachineBoundFileFallback(b64) {
4685
4730
  await mkdir3(dir, { recursive: true });
4686
4731
  const keyPath = getKeyPath();
4687
4732
  const machineKey = deriveMachineKey();
4688
- if (machineKey) {
4689
- const encrypted = encryptWithMachineKey(b64, machineKey);
4690
- await writeFile3(keyPath, encrypted + "\n", "utf-8");
4691
- await chmod2(keyPath, 384);
4692
- return "encrypted";
4693
- }
4694
- await writeFile3(keyPath, b64 + "\n", "utf-8");
4695
- await chmod2(keyPath, 384);
4696
- return "plaintext";
4733
+ const content = machineKey ? encryptWithMachineKey(b64, machineKey) + "\n" : b64 + "\n";
4734
+ const result = machineKey ? "encrypted" : "plaintext";
4735
+ const tmpPath = keyPath + ".tmp";
4736
+ try {
4737
+ if (existsSync7(keyPath)) {
4738
+ await copyFile(keyPath, keyPath + ".bak").catch(() => {
4739
+ });
4740
+ }
4741
+ await writeFile3(tmpPath, content, "utf-8");
4742
+ await chmod2(tmpPath, 384);
4743
+ await rename(tmpPath, keyPath);
4744
+ } catch (err) {
4745
+ try {
4746
+ await unlink(tmpPath);
4747
+ } catch {
4748
+ }
4749
+ throw err;
4750
+ }
4751
+ return result;
4697
4752
  }
4698
4753
  async function getMasterKey() {
4699
4754
  let nativeValue = macKeychainGet() ?? linuxSecretGet();
@@ -3170,6 +3170,22 @@ async function ensureSchema() {
3170
3170
  } catch (e) {
3171
3171
  logCatchDebug("migration", e);
3172
3172
  }
3173
+ try {
3174
+ await client.execute({
3175
+ sql: `ALTER TABLE memories ADD COLUMN visibility TEXT DEFAULT 'private'`,
3176
+ args: []
3177
+ });
3178
+ } catch (e) {
3179
+ logCatchDebug("migration", e);
3180
+ }
3181
+ try {
3182
+ await client.execute({
3183
+ sql: `ALTER TABLE memories ADD COLUMN strength REAL DEFAULT 1.0`,
3184
+ args: []
3185
+ });
3186
+ } catch (e) {
3187
+ logCatchDebug("migration", e);
3188
+ }
3173
3189
  }
3174
3190
  async function disposeDatabase() {
3175
3191
  if (_walCheckpointTimer) {
@@ -3736,11 +3752,17 @@ var init_platform_procedures = __esm({
3736
3752
  content: "Founder -> coordinator (the executive agent, internally routed as 'COO') -> CTO/CMO. CTO -> engineers. CMO -> content production. Never skip levels: the coordinator 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."
3737
3753
  },
3738
3754
  {
3739
- title: "Customer orchestration maturity \u2014 recommend, never trap",
3755
+ title: "Orchestration phase guidance \u2014 recommend, never trap",
3740
3756
  domain: "workflow",
3741
3757
  priority: "p1",
3742
3758
  content: "New customers start best in Phase 1: founder \u2194 coordinator/Chief of Staff, building company context. Suggest Phase 2 executives when domain work repeats; suggest Phase 3 parallel execution only when review/permission gates are ready. This is guidance, not a blocker: users may jump phases anytime. Never overwrite their phase, role titles, identities, or custom org design."
3743
3759
  },
3760
+ {
3761
+ title: "Routing slot vs display title \u2014 internal 'coo' is plumbing, not your name",
3762
+ domain: "identity",
3763
+ priority: "p0",
3764
+ content: "These procedures reference 'COO' as a shorthand for the coordinator role. This is an INTERNAL routing slot used by exe-os code (chain-of-command checks, dispatch logic, session detection). It is NOT your display title. Your actual title comes from your identity file's `title:` field \u2014 that is what you use externally: introductions, sign-offs, team comms, and any user-facing text. If your identity says `title: AI Chief of Staff`, you are the AI Chief of Staff. The routing slot stays `role: coo` for code compatibility \u2014 never rename it, but also never introduce yourself as 'COO' unless your identity file explicitly says so. The founder chose your title; respect it."
3765
+ },
3744
3766
  {
3745
3767
  title: "Single dispatch path \u2014 create_task only",
3746
3768
  domain: "workflow",
@@ -3774,6 +3796,12 @@ var init_platform_procedures = __esm({
3774
3796
  priority: "p0",
3775
3797
  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."
3776
3798
  },
3799
+ {
3800
+ title: "Destructive operations \u2014 mandatory reviewer gate",
3801
+ domain: "security",
3802
+ priority: "p0",
3803
+ content: "Before ANY destructive operation (delete, remove, overwrite, drop, reset, force-push, truncate), you MUST: (1) Have your full task spec accessible \u2014 if you cannot read it, STOP and report to your reviewer. Never improvise destructive actions. (2) Confirm with your reviewer (assigned_by or COO) before executing. (3) If the task spec explicitly authorizes the operation, proceed \u2014 but log it. Violation = immediate task failure. This applies to ALL agents regardless of role."
3804
+ },
3777
3805
  {
3778
3806
  title: "Customer patch triage \u2014 upstream bug vs customization",
3779
3807
  domain: "support",
@@ -4052,7 +4080,7 @@ init_memory();
4052
4080
  init_database();
4053
4081
 
4054
4082
  // src/lib/keychain.ts
4055
- import { readFile as readFile3, writeFile as writeFile3, unlink, mkdir as mkdir3, chmod as chmod2 } from "fs/promises";
4083
+ import { readFile as readFile3, writeFile as writeFile3, unlink, mkdir as mkdir3, chmod as chmod2, rename, copyFile } from "fs/promises";
4056
4084
  import { existsSync as existsSync7, statSync as statSync3 } from "fs";
4057
4085
  import { execSync as execSync3 } from "child_process";
4058
4086
  import path6 from "path";
@@ -4091,12 +4119,14 @@ function linuxSecretAvailable() {
4091
4119
  function isRootOnlyTrustedServerKeyFile(keyPath) {
4092
4120
  if (process.platform !== "linux") return false;
4093
4121
  try {
4094
- const uid = typeof os5.userInfo().uid === "number" ? os5.userInfo().uid : -1;
4095
4122
  const st = statSync3(keyPath);
4096
4123
  if (!st.isFile() || (st.mode & 63) !== 0) return false;
4124
+ const uid = typeof os5.userInfo().uid === "number" ? os5.userInfo().uid : -1;
4097
4125
  if (uid === 0) return true;
4098
4126
  const exeOsDir = process.env.EXE_OS_DIR;
4099
- return Boolean(exeOsDir && path6.resolve(keyPath).startsWith(path6.resolve(exeOsDir) + path6.sep));
4127
+ if (exeOsDir && path6.resolve(keyPath).startsWith(path6.resolve(exeOsDir) + path6.sep)) return true;
4128
+ if (!linuxSecretAvailable()) return true;
4129
+ return false;
4100
4130
  } catch {
4101
4131
  return false;
4102
4132
  }
@@ -4247,15 +4277,25 @@ async function writeMachineBoundFileFallback(b64) {
4247
4277
  await mkdir3(dir, { recursive: true });
4248
4278
  const keyPath = getKeyPath();
4249
4279
  const machineKey = deriveMachineKey();
4250
- if (machineKey) {
4251
- const encrypted = encryptWithMachineKey(b64, machineKey);
4252
- await writeFile3(keyPath, encrypted + "\n", "utf-8");
4253
- await chmod2(keyPath, 384);
4254
- return "encrypted";
4255
- }
4256
- await writeFile3(keyPath, b64 + "\n", "utf-8");
4257
- await chmod2(keyPath, 384);
4258
- return "plaintext";
4280
+ const content = machineKey ? encryptWithMachineKey(b64, machineKey) + "\n" : b64 + "\n";
4281
+ const result = machineKey ? "encrypted" : "plaintext";
4282
+ const tmpPath = keyPath + ".tmp";
4283
+ try {
4284
+ if (existsSync7(keyPath)) {
4285
+ await copyFile(keyPath, keyPath + ".bak").catch(() => {
4286
+ });
4287
+ }
4288
+ await writeFile3(tmpPath, content, "utf-8");
4289
+ await chmod2(tmpPath, 384);
4290
+ await rename(tmpPath, keyPath);
4291
+ } catch (err) {
4292
+ try {
4293
+ await unlink(tmpPath);
4294
+ } catch {
4295
+ }
4296
+ throw err;
4297
+ }
4298
+ return result;
4259
4299
  }
4260
4300
  async function getMasterKey() {
4261
4301
  let nativeValue = macKeychainGet() ?? linuxSecretGet();
@@ -3034,6 +3034,22 @@ async function ensureSchema() {
3034
3034
  } catch (e) {
3035
3035
  logCatchDebug("migration", e);
3036
3036
  }
3037
+ try {
3038
+ await client.execute({
3039
+ sql: `ALTER TABLE memories ADD COLUMN visibility TEXT DEFAULT 'private'`,
3040
+ args: []
3041
+ });
3042
+ } catch (e) {
3043
+ logCatchDebug("migration", e);
3044
+ }
3045
+ try {
3046
+ await client.execute({
3047
+ sql: `ALTER TABLE memories ADD COLUMN strength REAL DEFAULT 1.0`,
3048
+ args: []
3049
+ });
3050
+ } catch (e) {
3051
+ logCatchDebug("migration", e);
3052
+ }
3037
3053
  }
3038
3054
  async function disposeDatabase() {
3039
3055
  if (_walCheckpointTimer) {
@@ -3085,7 +3101,7 @@ var init_database = __esm({
3085
3101
  });
3086
3102
 
3087
3103
  // src/lib/keychain.ts
3088
- import { readFile as readFile3, writeFile as writeFile3, unlink, mkdir as mkdir3, chmod as chmod2 } from "fs/promises";
3104
+ import { readFile as readFile3, writeFile as writeFile3, unlink, mkdir as mkdir3, chmod as chmod2, rename, copyFile } from "fs/promises";
3089
3105
  import { existsSync as existsSync7, statSync as statSync3 } from "fs";
3090
3106
  import { execSync as execSync3 } from "child_process";
3091
3107
  import path6 from "path";
@@ -3120,12 +3136,14 @@ function linuxSecretAvailable() {
3120
3136
  function isRootOnlyTrustedServerKeyFile(keyPath) {
3121
3137
  if (process.platform !== "linux") return false;
3122
3138
  try {
3123
- const uid = typeof os5.userInfo().uid === "number" ? os5.userInfo().uid : -1;
3124
3139
  const st = statSync3(keyPath);
3125
3140
  if (!st.isFile() || (st.mode & 63) !== 0) return false;
3141
+ const uid = typeof os5.userInfo().uid === "number" ? os5.userInfo().uid : -1;
3126
3142
  if (uid === 0) return true;
3127
3143
  const exeOsDir = process.env.EXE_OS_DIR;
3128
- return Boolean(exeOsDir && path6.resolve(keyPath).startsWith(path6.resolve(exeOsDir) + path6.sep));
3144
+ if (exeOsDir && path6.resolve(keyPath).startsWith(path6.resolve(exeOsDir) + path6.sep)) return true;
3145
+ if (!linuxSecretAvailable()) return true;
3146
+ return false;
3129
3147
  } catch {
3130
3148
  return false;
3131
3149
  }
@@ -3275,15 +3293,25 @@ async function writeMachineBoundFileFallback(b64) {
3275
3293
  await mkdir3(dir, { recursive: true });
3276
3294
  const keyPath = getKeyPath();
3277
3295
  const machineKey = deriveMachineKey();
3278
- if (machineKey) {
3279
- const encrypted = encryptWithMachineKey(b64, machineKey);
3280
- await writeFile3(keyPath, encrypted + "\n", "utf-8");
3281
- await chmod2(keyPath, 384);
3282
- return "encrypted";
3296
+ const content = machineKey ? encryptWithMachineKey(b64, machineKey) + "\n" : b64 + "\n";
3297
+ const result = machineKey ? "encrypted" : "plaintext";
3298
+ const tmpPath = keyPath + ".tmp";
3299
+ try {
3300
+ if (existsSync7(keyPath)) {
3301
+ await copyFile(keyPath, keyPath + ".bak").catch(() => {
3302
+ });
3303
+ }
3304
+ await writeFile3(tmpPath, content, "utf-8");
3305
+ await chmod2(tmpPath, 384);
3306
+ await rename(tmpPath, keyPath);
3307
+ } catch (err) {
3308
+ try {
3309
+ await unlink(tmpPath);
3310
+ } catch {
3311
+ }
3312
+ throw err;
3283
3313
  }
3284
- await writeFile3(keyPath, b64 + "\n", "utf-8");
3285
- await chmod2(keyPath, 384);
3286
- return "plaintext";
3314
+ return result;
3287
3315
  }
3288
3316
  async function getMasterKey() {
3289
3317
  let nativeValue = macKeychainGet() ?? linuxSecretGet();
@@ -3908,11 +3936,17 @@ var init_platform_procedures = __esm({
3908
3936
  content: "Founder -> coordinator (the executive agent, internally routed as 'COO') -> CTO/CMO. CTO -> engineers. CMO -> content production. Never skip levels: the coordinator 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."
3909
3937
  },
3910
3938
  {
3911
- title: "Customer orchestration maturity \u2014 recommend, never trap",
3939
+ title: "Orchestration phase guidance \u2014 recommend, never trap",
3912
3940
  domain: "workflow",
3913
3941
  priority: "p1",
3914
3942
  content: "New customers start best in Phase 1: founder \u2194 coordinator/Chief of Staff, building company context. Suggest Phase 2 executives when domain work repeats; suggest Phase 3 parallel execution only when review/permission gates are ready. This is guidance, not a blocker: users may jump phases anytime. Never overwrite their phase, role titles, identities, or custom org design."
3915
3943
  },
3944
+ {
3945
+ title: "Routing slot vs display title \u2014 internal 'coo' is plumbing, not your name",
3946
+ domain: "identity",
3947
+ priority: "p0",
3948
+ content: "These procedures reference 'COO' as a shorthand for the coordinator role. This is an INTERNAL routing slot used by exe-os code (chain-of-command checks, dispatch logic, session detection). It is NOT your display title. Your actual title comes from your identity file's `title:` field \u2014 that is what you use externally: introductions, sign-offs, team comms, and any user-facing text. If your identity says `title: AI Chief of Staff`, you are the AI Chief of Staff. The routing slot stays `role: coo` for code compatibility \u2014 never rename it, but also never introduce yourself as 'COO' unless your identity file explicitly says so. The founder chose your title; respect it."
3949
+ },
3916
3950
  {
3917
3951
  title: "Single dispatch path \u2014 create_task only",
3918
3952
  domain: "workflow",
@@ -3946,6 +3980,12 @@ var init_platform_procedures = __esm({
3946
3980
  priority: "p0",
3947
3981
  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."
3948
3982
  },
3983
+ {
3984
+ title: "Destructive operations \u2014 mandatory reviewer gate",
3985
+ domain: "security",
3986
+ priority: "p0",
3987
+ content: "Before ANY destructive operation (delete, remove, overwrite, drop, reset, force-push, truncate), you MUST: (1) Have your full task spec accessible \u2014 if you cannot read it, STOP and report to your reviewer. Never improvise destructive actions. (2) Confirm with your reviewer (assigned_by or COO) before executing. (3) If the task spec explicitly authorizes the operation, proceed \u2014 but log it. Violation = immediate task failure. This applies to ALL agents regardless of role."
3988
+ },
3949
3989
  {
3950
3990
  title: "Customer patch triage \u2014 upstream bug vs customization",
3951
3991
  domain: "support",
@@ -4231,10 +4271,24 @@ function stableId(memoryId, type, content) {
4231
4271
  return createHash2("sha256").update(`${memoryId}:${type}:${content}`).digest("hex").slice(0, 32);
4232
4272
  }
4233
4273
  function cleanText(text) {
4234
- return text.replace(/```[\s\S]*?```/g, " ").replace(/<[^>]+>/g, " ").replace(/\s+/g, " ").trim();
4235
- }
4236
- function splitSentences(text) {
4237
- return cleanText(text).split(/(?<=[.!?])\s+|\n+/).map((s) => s.trim()).filter((s) => s.length >= 24 && s.length <= MAX_SENTENCE_CHARS);
4274
+ let cleaned = text.replace(
4275
+ /```(\w*)\n(.*?)(?:\n[\s\S]*?)```/g,
4276
+ (_m, lang, firstLine) => `[code${lang ? `:${lang}` : ""}] ${firstLine.trim()}`
4277
+ );
4278
+ cleaned = cleaned.replace(/<[^>]+>/g, " ").replace(/\s+/g, " ").trim();
4279
+ return cleaned;
4280
+ }
4281
+ function splitSegments(text) {
4282
+ const cleaned = cleanText(text);
4283
+ const segments = cleaned.split(/(?<=[.!?:;])\s+|\n{2,}|(?<=\))\s+(?=[A-Z])|\s*[|│]\s*/).map((s) => s.trim()).filter((s) => s.length >= MIN_SEGMENT_CHARS && s.length <= MAX_SEGMENT_CHARS);
4284
+ if (segments.length === 0 && cleaned.length >= MIN_SEGMENT_CHARS) {
4285
+ const lines = cleaned.split(/\n+/).map((l) => l.trim()).filter((l) => l.length >= MIN_SEGMENT_CHARS && l.length <= MAX_SEGMENT_CHARS);
4286
+ if (lines.length > 0) return lines;
4287
+ if (cleaned.length >= MIN_SEGMENT_CHARS) {
4288
+ return [cleaned.slice(0, MAX_SEGMENT_CHARS)];
4289
+ }
4290
+ }
4291
+ return segments;
4238
4292
  }
4239
4293
  function inferCardType(sentence, toolName) {
4240
4294
  const lower = sentence.toLowerCase();
@@ -4266,12 +4320,12 @@ function predicateFor(type) {
4266
4320
  }
4267
4321
  }
4268
4322
  function extractMemoryCards(row) {
4269
- const sentences = splitSentences(row.raw_text);
4323
+ const segments = splitSegments(row.raw_text);
4270
4324
  const cards = [];
4271
- for (const sentence of sentences) {
4325
+ for (const sentence of segments) {
4272
4326
  const type = inferCardType(sentence, row.tool_name);
4273
4327
  const subject = extractSubject(sentence, row.agent_id);
4274
- const content = sentence.length > MAX_SENTENCE_CHARS ? `${sentence.slice(0, MAX_SENTENCE_CHARS - 1)}\u2026` : sentence;
4328
+ const content = sentence.length > MAX_SEGMENT_CHARS ? `${sentence.slice(0, MAX_SEGMENT_CHARS - 1)}\u2026` : sentence;
4275
4329
  cards.push({
4276
4330
  id: stableId(row.id, type, content),
4277
4331
  memory_id: row.id,
@@ -4367,13 +4421,14 @@ Source memory: ${String(row.source_ref ?? row.memory_id)}`,
4367
4421
  last_accessed: String(row.timestamp)
4368
4422
  }));
4369
4423
  }
4370
- var MAX_CARDS_PER_MEMORY, MAX_SENTENCE_CHARS;
4424
+ var MAX_CARDS_PER_MEMORY, MAX_SEGMENT_CHARS, MIN_SEGMENT_CHARS;
4371
4425
  var init_memory_cards = __esm({
4372
4426
  "src/lib/memory-cards.ts"() {
4373
4427
  "use strict";
4374
4428
  init_database();
4375
- MAX_CARDS_PER_MEMORY = 6;
4376
- MAX_SENTENCE_CHARS = 360;
4429
+ MAX_CARDS_PER_MEMORY = 8;
4430
+ MAX_SEGMENT_CHARS = 500;
4431
+ MIN_SEGMENT_CHARS = 20;
4377
4432
  }
4378
4433
  });
4379
4434
 
@@ -5127,7 +5182,7 @@ import { jwtVerify, importSPKI } from "jose";
5127
5182
  var LICENSE_PATH = path8.join(EXE_AI_DIR, "license.key");
5128
5183
  var CACHE_PATH = path8.join(EXE_AI_DIR, "license-cache.json");
5129
5184
  var DEVICE_ID_PATH = path8.join(EXE_AI_DIR, "device-id");
5130
- var API_BASE = process.env.EXE_CLOUD_ENDPOINT ?? "https://askexe.com/cloud";
5185
+ var API_BASE = process.env.EXE_CLOUD_ENDPOINT ?? "https://cloud.askexe.com";
5131
5186
 
5132
5187
  // src/lib/cloud-sync.ts
5133
5188
  init_config();