@askexenow/exe-os 0.9.65 → 0.9.67

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 (113) hide show
  1. package/deploy/stack-manifests/v0.9.json +54 -5
  2. package/dist/bin/age-ontology-load.js +61 -0
  3. package/dist/bin/agentic-ontology-backfill.js +4708 -0
  4. package/dist/bin/agentic-reflection-backfill.js +4144 -0
  5. package/dist/bin/{exe-link.js → agentic-semantic-label.js} +1532 -2173
  6. package/dist/bin/backfill-conversations.js +528 -20
  7. package/dist/bin/backfill-responses.js +528 -20
  8. package/dist/bin/backfill-vectors.js +255 -20
  9. package/dist/bin/bulk-sync-postgres.js +4876 -0
  10. package/dist/bin/cleanup-stale-review-tasks.js +529 -21
  11. package/dist/bin/cli.js +3471 -1491
  12. package/dist/bin/exe-agent-config.js +4 -0
  13. package/dist/bin/exe-agent.js +16 -0
  14. package/dist/bin/exe-assign.js +528 -20
  15. package/dist/bin/exe-boot.js +492 -54
  16. package/dist/bin/exe-call.js +16 -0
  17. package/dist/bin/exe-cloud.js +7415 -518
  18. package/dist/bin/exe-dispatch.js +540 -22
  19. package/dist/bin/exe-doctor.js +3404 -1225
  20. package/dist/bin/exe-export-behaviors.js +542 -24
  21. package/dist/bin/exe-forget.js +529 -21
  22. package/dist/bin/exe-gateway.js +595 -25
  23. package/dist/bin/exe-heartbeat.js +541 -24
  24. package/dist/bin/exe-kill.js +529 -21
  25. package/dist/bin/exe-launch-agent.js +2334 -1067
  26. package/dist/bin/exe-new-employee.js +324 -166
  27. package/dist/bin/exe-pending-messages.js +529 -21
  28. package/dist/bin/exe-pending-notifications.js +529 -21
  29. package/dist/bin/exe-pending-reviews.js +529 -21
  30. package/dist/bin/exe-rename.js +529 -21
  31. package/dist/bin/exe-review.js +529 -21
  32. package/dist/bin/exe-search.js +542 -24
  33. package/dist/bin/exe-session-cleanup.js +540 -22
  34. package/dist/bin/exe-settings.js +14 -0
  35. package/dist/bin/exe-start-codex.js +817 -144
  36. package/dist/bin/exe-start-opencode.js +776 -80
  37. package/dist/bin/exe-status.js +529 -21
  38. package/dist/bin/exe-team.js +529 -21
  39. package/dist/bin/git-sweep.js +540 -22
  40. package/dist/bin/graph-backfill.js +580 -21
  41. package/dist/bin/graph-export.js +529 -21
  42. package/dist/bin/graph-layer-benchmark.js +109 -0
  43. package/dist/bin/install.js +420 -289
  44. package/dist/bin/intercom-check.js +540 -22
  45. package/dist/bin/postgres-agentic-reflection-backfill.js +187 -0
  46. package/dist/bin/postgres-agentic-semantic-backfill.js +237 -0
  47. package/dist/bin/scan-tasks.js +540 -22
  48. package/dist/bin/setup.js +790 -206
  49. package/dist/bin/shard-migrate.js +528 -20
  50. package/dist/bin/update.js +4 -0
  51. package/dist/gateway/index.js +593 -23
  52. package/dist/hooks/bug-report-worker.js +651 -64
  53. package/dist/hooks/codex-stop-task-finalizer.js +540 -22
  54. package/dist/hooks/commit-complete.js +540 -22
  55. package/dist/hooks/error-recall.js +542 -24
  56. package/dist/hooks/exe-heartbeat-hook.js +4 -0
  57. package/dist/hooks/ingest-worker.js +4 -0
  58. package/dist/hooks/ingest.js +539 -22
  59. package/dist/hooks/instructions-loaded.js +529 -21
  60. package/dist/hooks/notification.js +529 -21
  61. package/dist/hooks/post-compact.js +529 -21
  62. package/dist/hooks/post-tool-combined.js +543 -25
  63. package/dist/hooks/pre-compact.js +772 -127
  64. package/dist/hooks/pre-tool-use.js +529 -21
  65. package/dist/hooks/prompt-submit.js +543 -25
  66. package/dist/hooks/session-end.js +673 -140
  67. package/dist/hooks/session-start.js +662 -26
  68. package/dist/hooks/stop.js +540 -23
  69. package/dist/hooks/subagent-stop.js +529 -21
  70. package/dist/hooks/summary-worker.js +571 -126
  71. package/dist/index.js +593 -23
  72. package/dist/lib/agent-config.js +4 -0
  73. package/dist/lib/cloud-sync.js +408 -47
  74. package/dist/lib/config.js +25 -1
  75. package/dist/lib/consolidation.js +5 -1
  76. package/dist/lib/database.js +128 -0
  77. package/dist/lib/db-daemon-client.js +4 -0
  78. package/dist/lib/db.js +128 -0
  79. package/dist/lib/device-registry.js +128 -0
  80. package/dist/lib/embedder.js +25 -1
  81. package/dist/lib/employee-templates.js +16 -0
  82. package/dist/lib/employees.js +4 -0
  83. package/dist/lib/exe-daemon-client.js +4 -0
  84. package/dist/lib/exe-daemon.js +3158 -930
  85. package/dist/lib/hybrid-search.js +542 -24
  86. package/dist/lib/identity.js +7 -0
  87. package/dist/lib/keychain.js +178 -22
  88. package/dist/lib/license.js +4 -0
  89. package/dist/lib/messaging.js +7 -0
  90. package/dist/lib/reminders.js +7 -0
  91. package/dist/lib/schedules.js +255 -20
  92. package/dist/lib/skill-learning.js +28 -1
  93. package/dist/lib/status-brief.js +39 -0
  94. package/dist/lib/store.js +528 -20
  95. package/dist/lib/task-router.js +4 -0
  96. package/dist/lib/tasks.js +28 -1
  97. package/dist/lib/tmux-routing.js +28 -1
  98. package/dist/lib/token-spend.js +7 -0
  99. package/dist/mcp/server.js +2739 -813
  100. package/dist/mcp/tools/complete-reminder.js +7 -0
  101. package/dist/mcp/tools/create-reminder.js +7 -0
  102. package/dist/mcp/tools/create-task.js +28 -1
  103. package/dist/mcp/tools/deactivate-behavior.js +7 -0
  104. package/dist/mcp/tools/list-reminders.js +7 -0
  105. package/dist/mcp/tools/list-tasks.js +7 -0
  106. package/dist/mcp/tools/send-message.js +7 -0
  107. package/dist/mcp/tools/update-task.js +28 -1
  108. package/dist/runtime/index.js +540 -22
  109. package/dist/tui/App.js +618 -29
  110. package/package.json +9 -5
  111. package/src/commands/exe/cloud.md +11 -8
  112. package/stack.release.json +3 -3
  113. package/src/commands/exe/link.md +0 -17
@@ -202,6 +202,11 @@ function normalizeAutoUpdate(raw) {
202
202
  const userAU = raw.autoUpdate ?? {};
203
203
  raw.autoUpdate = { ...defaultAU, ...userAU };
204
204
  }
205
+ function normalizeOrchestration(raw) {
206
+ const defaultOrg = DEFAULT_CONFIG.orchestration;
207
+ const userOrg = raw.orchestration ?? {};
208
+ raw.orchestration = { ...defaultOrg, ...userOrg };
209
+ }
205
210
  async function loadConfig() {
206
211
  const dir = process.env.EXE_OS_DIR ?? process.env.EXE_MEM_DIR ?? EXE_AI_DIR;
207
212
  await ensurePrivateDir(dir);
@@ -226,10 +231,15 @@ async function loadConfig() {
226
231
  normalizeScalingRoadmap(migratedCfg);
227
232
  normalizeSessionLifecycle(migratedCfg);
228
233
  normalizeAutoUpdate(migratedCfg);
234
+ normalizeOrchestration(migratedCfg);
229
235
  const config = { ...DEFAULT_CONFIG, dbPath: path.join(dir, "memories.db"), ...migratedCfg };
230
236
  if (config.dbPath.startsWith("~")) {
231
237
  config.dbPath = config.dbPath.replace(/^~/, os.homedir());
232
238
  }
239
+ const envDbPath = path.join(dir, "memories.db");
240
+ if (process.env.EXE_OS_DIR && config.dbPath !== envDbPath && !existsSync2(config.dbPath) && existsSync2(envDbPath)) {
241
+ config.dbPath = envDbPath;
242
+ }
233
243
  return config;
234
244
  } catch {
235
245
  return { ...DEFAULT_CONFIG, dbPath: path.join(dir, "memories.db") };
@@ -249,7 +259,16 @@ function loadConfigSync() {
249
259
  normalizeScalingRoadmap(migratedCfg);
250
260
  normalizeSessionLifecycle(migratedCfg);
251
261
  normalizeAutoUpdate(migratedCfg);
252
- return { ...DEFAULT_CONFIG, dbPath: path.join(dir, "memories.db"), ...migratedCfg };
262
+ normalizeOrchestration(migratedCfg);
263
+ const config = { ...DEFAULT_CONFIG, dbPath: path.join(dir, "memories.db"), ...migratedCfg };
264
+ if (config.dbPath.startsWith("~")) {
265
+ config.dbPath = config.dbPath.replace(/^~/, os.homedir());
266
+ }
267
+ const envDbPath = path.join(dir, "memories.db");
268
+ if (process.env.EXE_OS_DIR && config.dbPath !== envDbPath && !existsSync2(config.dbPath) && existsSync2(envDbPath)) {
269
+ config.dbPath = envDbPath;
270
+ }
271
+ return config;
253
272
  } catch {
254
273
  return { ...DEFAULT_CONFIG, dbPath: path.join(dir, "memories.db") };
255
274
  }
@@ -270,6 +289,7 @@ async function loadConfigFrom(configPath) {
270
289
  normalizeScalingRoadmap(migratedCfg);
271
290
  normalizeSessionLifecycle(migratedCfg);
272
291
  normalizeAutoUpdate(migratedCfg);
292
+ normalizeOrchestration(migratedCfg);
273
293
  return { ...DEFAULT_CONFIG, ...migratedCfg };
274
294
  } catch {
275
295
  return { ...DEFAULT_CONFIG };
@@ -341,6 +361,10 @@ var init_config = __esm({
341
361
  checkOnBoot: true,
342
362
  autoInstall: false,
343
363
  checkIntervalMs: 24 * 60 * 60 * 1e3
364
+ },
365
+ orchestration: {
366
+ phase: "phase_1_coo",
367
+ phaseSetBy: "default"
344
368
  }
345
369
  };
346
370
  CONFIG_MIGRATIONS = [
@@ -1722,6 +1746,9 @@ function getClient() {
1722
1746
  if (_daemonClient && _daemonClient._isDaemonActive()) {
1723
1747
  return _daemonClient;
1724
1748
  }
1749
+ if (!_resilientClient) {
1750
+ return _adapterClient;
1751
+ }
1725
1752
  return _resilientClient;
1726
1753
  }
1727
1754
  async function initDaemonClient() {
@@ -2754,6 +2781,127 @@ async function ensureSchema() {
2754
2781
  VALUES (new.rowid, new.content, new.subject, new.predicate, new.object);
2755
2782
  END;
2756
2783
  `);
2784
+ await client.executeMultiple(`
2785
+ CREATE TABLE IF NOT EXISTS agent_sessions (
2786
+ id TEXT PRIMARY KEY,
2787
+ agent_id TEXT NOT NULL,
2788
+ project_name TEXT,
2789
+ started_at TEXT NOT NULL,
2790
+ last_event_at TEXT NOT NULL,
2791
+ event_count INTEGER NOT NULL DEFAULT 0,
2792
+ properties TEXT DEFAULT '{}'
2793
+ );
2794
+
2795
+ CREATE INDEX IF NOT EXISTS idx_agent_sessions_agent_time
2796
+ ON agent_sessions(agent_id, started_at);
2797
+
2798
+ CREATE TABLE IF NOT EXISTS agent_goals (
2799
+ id TEXT PRIMARY KEY,
2800
+ statement TEXT NOT NULL,
2801
+ owner_agent_id TEXT,
2802
+ project_name TEXT,
2803
+ status TEXT NOT NULL DEFAULT 'open',
2804
+ priority INTEGER NOT NULL DEFAULT 5,
2805
+ success_criteria TEXT,
2806
+ parent_goal_id TEXT,
2807
+ due_at TEXT,
2808
+ achieved_at TEXT,
2809
+ supersedes_id TEXT,
2810
+ created_at TEXT NOT NULL,
2811
+ updated_at TEXT NOT NULL,
2812
+ source_memory_id TEXT
2813
+ );
2814
+
2815
+ CREATE INDEX IF NOT EXISTS idx_agent_goals_project_status
2816
+ ON agent_goals(project_name, status, priority);
2817
+
2818
+ CREATE TABLE IF NOT EXISTS agent_events (
2819
+ id TEXT PRIMARY KEY,
2820
+ event_type TEXT NOT NULL,
2821
+ occurred_at TEXT NOT NULL,
2822
+ sequence_index INTEGER NOT NULL,
2823
+ actor_agent_id TEXT,
2824
+ agent_role TEXT,
2825
+ project_name TEXT,
2826
+ session_id TEXT,
2827
+ task_id TEXT,
2828
+ goal_id TEXT,
2829
+ parent_event_id TEXT,
2830
+ intention TEXT,
2831
+ outcome TEXT,
2832
+ evidence_memory_id TEXT,
2833
+ impact TEXT,
2834
+ payload TEXT DEFAULT '{}',
2835
+ created_at TEXT NOT NULL
2836
+ );
2837
+
2838
+ CREATE INDEX IF NOT EXISTS idx_agent_events_time
2839
+ ON agent_events(occurred_at, sequence_index);
2840
+
2841
+ CREATE INDEX IF NOT EXISTS idx_agent_events_session_seq
2842
+ ON agent_events(session_id, sequence_index);
2843
+
2844
+ CREATE INDEX IF NOT EXISTS idx_agent_events_goal_time
2845
+ ON agent_events(goal_id, occurred_at);
2846
+
2847
+ CREATE INDEX IF NOT EXISTS idx_agent_events_memory
2848
+ ON agent_events(evidence_memory_id);
2849
+
2850
+ CREATE TABLE IF NOT EXISTS agent_goal_links (
2851
+ id TEXT PRIMARY KEY,
2852
+ goal_id TEXT NOT NULL,
2853
+ link_type TEXT NOT NULL,
2854
+ target_id TEXT NOT NULL,
2855
+ target_type TEXT NOT NULL,
2856
+ created_at TEXT NOT NULL
2857
+ );
2858
+
2859
+ CREATE INDEX IF NOT EXISTS idx_agent_goal_links_goal
2860
+ ON agent_goal_links(goal_id, target_type);
2861
+
2862
+ CREATE TABLE IF NOT EXISTS agent_semantic_labels (
2863
+ id TEXT PRIMARY KEY,
2864
+ source_memory_id TEXT NOT NULL,
2865
+ event_id TEXT,
2866
+ labeler TEXT NOT NULL,
2867
+ schema_version INTEGER NOT NULL DEFAULT 1,
2868
+ confidence REAL NOT NULL DEFAULT 0,
2869
+ labels TEXT NOT NULL,
2870
+ created_at TEXT NOT NULL,
2871
+ updated_at TEXT NOT NULL
2872
+ );
2873
+
2874
+ CREATE INDEX IF NOT EXISTS idx_agent_semantic_labels_memory
2875
+ ON agent_semantic_labels(source_memory_id, labeler);
2876
+
2877
+ CREATE INDEX IF NOT EXISTS idx_agent_semantic_labels_event
2878
+ ON agent_semantic_labels(event_id);
2879
+
2880
+ CREATE TABLE IF NOT EXISTS agent_reflection_checkpoints (
2881
+ id TEXT PRIMARY KEY,
2882
+ project_name TEXT,
2883
+ session_id TEXT,
2884
+ window_start_at TEXT NOT NULL,
2885
+ window_end_at TEXT NOT NULL,
2886
+ event_count INTEGER NOT NULL DEFAULT 0,
2887
+ goal_count INTEGER NOT NULL DEFAULT 0,
2888
+ success_count INTEGER NOT NULL DEFAULT 0,
2889
+ failure_count INTEGER NOT NULL DEFAULT 0,
2890
+ risk_count INTEGER NOT NULL DEFAULT 0,
2891
+ summary TEXT NOT NULL,
2892
+ learnings TEXT NOT NULL DEFAULT '[]',
2893
+ next_actions TEXT NOT NULL DEFAULT '[]',
2894
+ evidence_event_ids TEXT NOT NULL DEFAULT '[]',
2895
+ confidence REAL NOT NULL DEFAULT 0,
2896
+ created_at TEXT NOT NULL
2897
+ );
2898
+
2899
+ CREATE INDEX IF NOT EXISTS idx_agent_reflection_project_time
2900
+ ON agent_reflection_checkpoints(project_name, window_end_at);
2901
+
2902
+ CREATE INDEX IF NOT EXISTS idx_agent_reflection_session_time
2903
+ ON agent_reflection_checkpoints(session_id, window_end_at);
2904
+ `);
2757
2905
  try {
2758
2906
  await client.execute({
2759
2907
  sql: `ALTER TABLE memories ADD COLUMN tier INTEGER DEFAULT 3`,
@@ -2903,7 +3051,7 @@ var init_database = __esm({
2903
3051
 
2904
3052
  // src/lib/keychain.ts
2905
3053
  import { readFile as readFile3, writeFile as writeFile3, unlink, mkdir as mkdir3, chmod as chmod2 } from "fs/promises";
2906
- import { existsSync as existsSync6 } from "fs";
3054
+ import { existsSync as existsSync6, statSync as statSync2 } from "fs";
2907
3055
  import { execSync as execSync2 } from "child_process";
2908
3056
  import path6 from "path";
2909
3057
  import os5 from "os";
@@ -2913,29 +3061,65 @@ function getKeyDir() {
2913
3061
  function getKeyPath() {
2914
3062
  return path6.join(getKeyDir(), "master.key");
2915
3063
  }
2916
- function macKeychainGet() {
3064
+ function nativeKeychainAllowed() {
3065
+ return process.env.EXE_OS_DISABLE_NATIVE_KEYCHAIN !== "1";
3066
+ }
3067
+ function linuxSecretAvailable() {
3068
+ if (!nativeKeychainAllowed()) return false;
3069
+ if (process.platform !== "linux") return false;
3070
+ if (linuxSecretAvailability !== null) return linuxSecretAvailability;
3071
+ try {
3072
+ execSync2("command -v secret-tool >/dev/null 2>&1", { timeout: 1e3 });
3073
+ } catch {
3074
+ linuxSecretAvailability = false;
3075
+ return false;
3076
+ }
3077
+ try {
3078
+ execSync2("secret-tool search --all exe-os probe >/dev/null 2>&1", { timeout: 1e3 });
3079
+ linuxSecretAvailability = true;
3080
+ } catch {
3081
+ linuxSecretAvailability = false;
3082
+ }
3083
+ return linuxSecretAvailability;
3084
+ }
3085
+ function isRootOnlyTrustedServerKeyFile(keyPath) {
3086
+ if (process.platform !== "linux") return false;
3087
+ try {
3088
+ const uid = typeof os5.userInfo().uid === "number" ? os5.userInfo().uid : -1;
3089
+ const st = statSync2(keyPath);
3090
+ if (!st.isFile() || (st.mode & 63) !== 0) return false;
3091
+ if (uid === 0) return true;
3092
+ const exeOsDir = process.env.EXE_OS_DIR;
3093
+ return Boolean(exeOsDir && path6.resolve(keyPath).startsWith(path6.resolve(exeOsDir) + path6.sep));
3094
+ } catch {
3095
+ return false;
3096
+ }
3097
+ }
3098
+ function macKeychainGet(service = SERVICE) {
3099
+ if (!nativeKeychainAllowed()) return null;
2917
3100
  if (process.platform !== "darwin") return null;
2918
3101
  try {
2919
3102
  return execSync2(
2920
- `security find-generic-password -s "${SERVICE}" -a "${ACCOUNT}" -w 2>/dev/null`,
3103
+ `security find-generic-password -s "${service}" -a "${ACCOUNT}" -w 2>/dev/null`,
2921
3104
  { encoding: "utf-8", timeout: 5e3 }
2922
3105
  ).trim();
2923
3106
  } catch {
2924
3107
  return null;
2925
3108
  }
2926
3109
  }
2927
- function macKeychainSet(value) {
3110
+ function macKeychainSet(value, service = SERVICE) {
3111
+ if (!nativeKeychainAllowed()) return false;
2928
3112
  if (process.platform !== "darwin") return false;
2929
3113
  try {
2930
3114
  try {
2931
3115
  execSync2(
2932
- `security delete-generic-password -s "${SERVICE}" -a "${ACCOUNT}" 2>/dev/null`,
3116
+ `security delete-generic-password -s "${service}" -a "${ACCOUNT}" 2>/dev/null`,
2933
3117
  { timeout: 5e3 }
2934
3118
  );
2935
3119
  } catch {
2936
3120
  }
2937
3121
  execSync2(
2938
- `security add-generic-password -s "${SERVICE}" -a "${ACCOUNT}" -w "${value}"`,
3122
+ `security add-generic-password -s "${service}" -a "${ACCOUNT}" -w "${value}"`,
2939
3123
  { timeout: 5e3 }
2940
3124
  );
2941
3125
  return true;
@@ -2943,22 +3127,48 @@ function macKeychainSet(value) {
2943
3127
  return false;
2944
3128
  }
2945
3129
  }
2946
- function linuxSecretGet() {
2947
- if (process.platform !== "linux") return null;
3130
+ function macKeychainDelete(service = SERVICE) {
3131
+ if (!nativeKeychainAllowed()) return false;
3132
+ if (process.platform !== "darwin") return false;
3133
+ try {
3134
+ execSync2(
3135
+ `security delete-generic-password -s "${service}" -a "${ACCOUNT}" 2>/dev/null`,
3136
+ { timeout: 5e3 }
3137
+ );
3138
+ return true;
3139
+ } catch {
3140
+ return false;
3141
+ }
3142
+ }
3143
+ function linuxSecretGet(service = SERVICE) {
3144
+ if (!linuxSecretAvailable()) return null;
2948
3145
  try {
2949
3146
  return execSync2(
2950
- `secret-tool lookup service "${SERVICE}" account "${ACCOUNT}" 2>/dev/null`,
3147
+ `secret-tool lookup service "${service}" account "${ACCOUNT}" 2>/dev/null`,
2951
3148
  { encoding: "utf-8", timeout: 5e3 }
2952
3149
  ).trim();
2953
3150
  } catch {
2954
3151
  return null;
2955
3152
  }
2956
3153
  }
2957
- function linuxSecretSet(value) {
3154
+ function linuxSecretSet(value, service = SERVICE) {
3155
+ if (!linuxSecretAvailable()) return false;
3156
+ try {
3157
+ execSync2(
3158
+ `echo -n "${value}" | secret-tool store --label="exe-os master key" service "${service}" account "${ACCOUNT}" 2>/dev/null`,
3159
+ { timeout: 5e3 }
3160
+ );
3161
+ return true;
3162
+ } catch {
3163
+ return false;
3164
+ }
3165
+ }
3166
+ function linuxSecretDelete(service = SERVICE) {
3167
+ if (!nativeKeychainAllowed()) return false;
2958
3168
  if (process.platform !== "linux") return false;
2959
3169
  try {
2960
3170
  execSync2(
2961
- `echo -n "${value}" | secret-tool store --label="exe-os master key" service "${SERVICE}" account "${ACCOUNT}"`,
3171
+ `secret-tool clear service "${service}" account "${ACCOUNT}" 2>/dev/null`,
2962
3172
  { timeout: 5e3 }
2963
3173
  );
2964
3174
  return true;
@@ -2967,6 +3177,7 @@ function linuxSecretSet(value) {
2967
3177
  }
2968
3178
  }
2969
3179
  async function tryKeytar() {
3180
+ if (!nativeKeychainAllowed()) return null;
2970
3181
  try {
2971
3182
  return await import("keytar");
2972
3183
  } catch {
@@ -3040,7 +3251,19 @@ async function writeMachineBoundFileFallback(b64) {
3040
3251
  return "plaintext";
3041
3252
  }
3042
3253
  async function getMasterKey() {
3043
- const nativeValue = macKeychainGet() ?? linuxSecretGet();
3254
+ let nativeValue = macKeychainGet() ?? linuxSecretGet();
3255
+ if (!nativeValue) {
3256
+ const legacyValue = macKeychainGet(LEGACY_SERVICE) ?? linuxSecretGet(LEGACY_SERVICE);
3257
+ if (legacyValue) {
3258
+ const migrated = macKeychainSet(legacyValue) || linuxSecretSet(legacyValue);
3259
+ if (migrated) {
3260
+ macKeychainDelete(LEGACY_SERVICE);
3261
+ linuxSecretDelete(LEGACY_SERVICE);
3262
+ process.stderr.write("[keychain] Migrated keychain service from exe-mem to exe-os.\n");
3263
+ }
3264
+ nativeValue = legacyValue;
3265
+ }
3266
+ }
3044
3267
  if (nativeValue) {
3045
3268
  return Buffer.from(nativeValue, "base64");
3046
3269
  }
@@ -3048,12 +3271,17 @@ async function getMasterKey() {
3048
3271
  if (keytar) {
3049
3272
  try {
3050
3273
  const keytarValue = await keytar.getPassword(SERVICE, ACCOUNT);
3051
- if (keytarValue) {
3052
- const migrated = macKeychainSet(keytarValue) || linuxSecretSet(keytarValue);
3274
+ const legacyKeytarValue = keytarValue ?? await keytar.getPassword(LEGACY_SERVICE, ACCOUNT);
3275
+ if (legacyKeytarValue) {
3276
+ const migrated = macKeychainSet(legacyKeytarValue) || linuxSecretSet(legacyKeytarValue);
3053
3277
  if (migrated) {
3054
3278
  process.stderr.write("[keychain] Migrated key from keytar to native keychain.\n");
3279
+ try {
3280
+ await keytar.deletePassword(LEGACY_SERVICE, ACCOUNT);
3281
+ } catch {
3282
+ }
3055
3283
  }
3056
- return Buffer.from(keytarValue, "base64");
3284
+ return Buffer.from(legacyKeytarValue, "base64");
3057
3285
  }
3058
3286
  } catch {
3059
3287
  }
@@ -3078,7 +3306,7 @@ async function getMasterKey() {
3078
3306
  const decrypted = decryptWithMachineKey(content, machineKey);
3079
3307
  if (!decrypted) {
3080
3308
  process.stderr.write(
3081
- "[keychain] Key decryption failed \u2014 machine may have changed.\n Use your 24-word recovery phrase: exe-os link import\n"
3309
+ "[keychain] Key decryption failed \u2014 machine may have changed.\n Use your 24-word recovery phrase during setup: exe-os setup\n"
3082
3310
  );
3083
3311
  return null;
3084
3312
  }
@@ -3087,6 +3315,9 @@ async function getMasterKey() {
3087
3315
  b64Value = content;
3088
3316
  }
3089
3317
  const key = Buffer.from(b64Value, "base64");
3318
+ if (!content.startsWith(ENCRYPTED_PREFIX) && isRootOnlyTrustedServerKeyFile(keyPath)) {
3319
+ return key;
3320
+ }
3090
3321
  const migrated = macKeychainSet(b64Value) || linuxSecretSet(b64Value);
3091
3322
  if (migrated) {
3092
3323
  process.stderr.write("[keychain] Migrated key from file to native keychain.\n");
@@ -3114,12 +3345,14 @@ async function getMasterKey() {
3114
3345
  return null;
3115
3346
  }
3116
3347
  }
3117
- var SERVICE, ACCOUNT, ENCRYPTED_PREFIX;
3348
+ var SERVICE, LEGACY_SERVICE, ACCOUNT, linuxSecretAvailability, ENCRYPTED_PREFIX;
3118
3349
  var init_keychain = __esm({
3119
3350
  "src/lib/keychain.ts"() {
3120
3351
  "use strict";
3121
- SERVICE = "exe-mem";
3352
+ SERVICE = "exe-os";
3353
+ LEGACY_SERVICE = "exe-mem";
3122
3354
  ACCOUNT = "master-key";
3355
+ linuxSecretAvailability = null;
3123
3356
  ENCRYPTED_PREFIX = "enc:";
3124
3357
  }
3125
3358
  });
@@ -3389,7 +3622,7 @@ __export(shard_manager_exports, {
3389
3622
  shardExists: () => shardExists
3390
3623
  });
3391
3624
  import path7 from "path";
3392
- import { existsSync as existsSync7, mkdirSync as mkdirSync2, readdirSync, renameSync as renameSync3, statSync as statSync2 } from "fs";
3625
+ import { existsSync as existsSync7, mkdirSync as mkdirSync2, readdirSync, renameSync as renameSync3, statSync as statSync3 } from "fs";
3393
3626
  import { createClient as createClient2 } from "@libsql/client";
3394
3627
  function initShardManager(encryptionKey) {
3395
3628
  _encryptionKey = encryptionKey;
@@ -3453,7 +3686,7 @@ async function auditShardHealth(options = {}) {
3453
3686
  const shards = [];
3454
3687
  for (const name of names) {
3455
3688
  const dbPath = path7.join(SHARDS_DIR, `${name}.db`);
3456
- const stat = statSync2(dbPath);
3689
+ const stat = statSync3(dbPath);
3457
3690
  const item = {
3458
3691
  name,
3459
3692
  path: dbPath,
@@ -3706,7 +3939,7 @@ async function getReadyShardClient(projectName) {
3706
3939
  _shardLastAccess.delete(safeName);
3707
3940
  const dbPath = path7.join(SHARDS_DIR, `${safeName}.db`);
3708
3941
  if (existsSync7(dbPath)) {
3709
- const stat = statSync2(dbPath);
3942
+ const stat = statSync3(dbPath);
3710
3943
  const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
3711
3944
  const archivedPath = path7.join(SHARDS_DIR, `${safeName}.db.broken-${stamp}`);
3712
3945
  renameSync3(dbPath, archivedPath);
@@ -3826,6 +4059,12 @@ var init_platform_procedures = __esm({
3826
4059
  priority: "p0",
3827
4060
  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."
3828
4061
  },
4062
+ {
4063
+ title: "Customer orchestration maturity \u2014 recommend, never trap",
4064
+ domain: "workflow",
4065
+ priority: "p1",
4066
+ 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."
4067
+ },
3829
4068
  {
3830
4069
  title: "Single dispatch path \u2014 create_task only",
3831
4070
  domain: "workflow",
@@ -3884,6 +4123,12 @@ var init_platform_procedures = __esm({
3884
4123
  priority: "p0",
3885
4124
  content: "exe-build-adv is MANDATORY for ALL work touching 3+ files. Run /exe-build-adv --auto BEFORE implementation. Pipeline: Spec \u2192 AC \u2192 Tests \u2192 Evaluate \u2192 Fix. No multi-file feature ships without pipeline artifacts. No exceptions \u2014 managers reject work without them."
3886
4125
  },
4126
+ {
4127
+ title: "Commit discipline \u2014 never leave verified work floating",
4128
+ domain: "workflow",
4129
+ priority: "p1",
4130
+ content: "After any code-change batch passes typecheck/tests/build, run git status, summarize changed files, and commit with a clear message before ending the session. If work must remain uncommitted for review/dogfood, explicitly say so, list the files, and state the blocker. Never imply work is complete while verified changes are still floating locally."
4131
+ },
3887
4132
  {
3888
4133
  title: "Desktop and TUI are the same product",
3889
4134
  domain: "architecture",
@@ -4201,6 +4446,274 @@ var init_memory_cards = __esm({
4201
4446
  }
4202
4447
  });
4203
4448
 
4449
+ // src/lib/agentic-ontology.ts
4450
+ var agentic_ontology_exports = {};
4451
+ __export(agentic_ontology_exports, {
4452
+ clean: () => clean,
4453
+ extractGoalCandidates: () => extractGoalCandidates,
4454
+ inferIntention: () => inferIntention,
4455
+ inferOntologyEventType: () => inferOntologyEventType,
4456
+ inferOutcome: () => inferOutcome,
4457
+ inferSemanticLabel: () => inferSemanticLabel,
4458
+ insertOntologyForBatch: () => insertOntologyForBatch,
4459
+ insertOntologyForMemory: () => insertOntologyForMemory,
4460
+ ontologyPayload: () => ontologyPayload,
4461
+ stableId: () => stableId2
4462
+ });
4463
+ import { createHash as createHash3 } from "crypto";
4464
+ function stableId2(...parts) {
4465
+ return createHash3("sha256").update(parts.map((p) => String(p ?? "")).join("::")).digest("hex").slice(0, 32);
4466
+ }
4467
+ function clean(text, max = 240) {
4468
+ return text.replace(/\u0000/g, "").replace(/```[\s\S]*?```/g, " ").replace(/\s+/g, " ").trim().slice(0, max);
4469
+ }
4470
+ function inferOntologyEventType(row) {
4471
+ const lower = row.raw_text.toLowerCase();
4472
+ if (row.has_error) return "error";
4473
+ if (/\b(done|complete|completed|fixed|resolved|shipped|deployed|pushed|published)\b/.test(lower)) return "milestone";
4474
+ if (/\b(blocked|failed|error|bug|regression|broken)\b/.test(lower)) return "problem";
4475
+ if (/\b(decided|decision|adr|we chose|approved|rejected)\b/.test(lower)) return "decision";
4476
+ if (/\b(goal|need to|we need|want to|trying to|objective)\b/.test(lower)) return "goal_signal";
4477
+ if (["Bash", "Read", "Edit", "Write", "Grep", "Glob"].includes(row.tool_name)) return "tool_action";
4478
+ if (row.tool_name.startsWith("memory_card")) return "memory_card";
4479
+ return "memory_observation";
4480
+ }
4481
+ function inferIntention(row) {
4482
+ if (row.intent) return clean(row.intent, 220);
4483
+ const text = clean(row.raw_text, 1e3);
4484
+ const patterns = [
4485
+ /(?:we need to|need to|let'?s|i want to|we should|goal is to|objective is to|trying to)\s+([^.!?\n]{8,220})/i,
4486
+ /(?:so that|in order to)\s+([^.!?\n]{8,220})/i,
4487
+ /(?:task|plan):\s*([^.!?\n]{8,220})/i
4488
+ ];
4489
+ for (const p of patterns) {
4490
+ const m = text.match(p);
4491
+ if (m?.[1]) return clean(m[1], 220);
4492
+ }
4493
+ if (["Bash", "Read", "Edit", "Write", "Grep", "Glob"].includes(row.tool_name)) {
4494
+ return `${row.tool_name} during ${row.project_name}`;
4495
+ }
4496
+ return null;
4497
+ }
4498
+ function inferOutcome(row) {
4499
+ if (row.outcome) return clean(row.outcome, 220);
4500
+ if (row.has_error) return "error";
4501
+ const lower = row.raw_text.toLowerCase();
4502
+ if (/\b(done|complete|completed|fixed|resolved|shipped|deployed|pushed|published|passed)\b/.test(lower)) return "success_signal";
4503
+ if (/\b(blocked|failed|error|regression|broken|not working|could not)\b/.test(lower)) return "failure_signal";
4504
+ if (/\b(warning|risk|concern|caveat)\b/.test(lower)) return "risk_signal";
4505
+ return null;
4506
+ }
4507
+ function extractGoalCandidates(row) {
4508
+ const text = clean(row.raw_text, 1600);
4509
+ const patterns = [
4510
+ /(?:we need to|need to|i want to|we should|goal is to|objective is to|trying to|let'?s)\s+([^.!?\n]{12,220})/gi,
4511
+ /(?:success means|success criteria|so that)\s+([^.!?\n]{12,220})/gi
4512
+ ];
4513
+ const out = [];
4514
+ for (const pattern of patterns) {
4515
+ for (const m of text.matchAll(pattern)) {
4516
+ const candidate = clean(m[1] ?? "", 220);
4517
+ if (candidate.length >= 12 && !out.some((x) => x.toLowerCase() === candidate.toLowerCase())) out.push(candidate);
4518
+ if (out.length >= 3) return out;
4519
+ }
4520
+ }
4521
+ return out;
4522
+ }
4523
+ function uniq(values, max = 6) {
4524
+ const out = [];
4525
+ for (const value of values.map((v) => clean(v, 220)).filter(Boolean)) {
4526
+ if (!out.some((x) => x.toLowerCase() === value.toLowerCase())) out.push(value);
4527
+ if (out.length >= max) break;
4528
+ }
4529
+ return out;
4530
+ }
4531
+ function extractMatches(text, patterns, max = 5) {
4532
+ const out = [];
4533
+ for (const pattern of patterns) {
4534
+ for (const match of text.matchAll(pattern)) {
4535
+ const value = match[1] ?? match[0];
4536
+ if (value) out.push(value);
4537
+ if (out.length >= max) return uniq(out, max);
4538
+ }
4539
+ }
4540
+ return uniq(out, max);
4541
+ }
4542
+ function inferSemanticLabel(row) {
4543
+ const text = clean(row.raw_text, 2400);
4544
+ const eventType = inferOntologyEventType(row);
4545
+ const intention = inferIntention(row);
4546
+ const outcome = inferOutcome(row);
4547
+ const goals = extractGoalCandidates(row);
4548
+ const milestones = extractMatches(text, [
4549
+ /\b(?:completed|finished|fixed|resolved|shipped|deployed|published|pushed|passed)\b([^.!?\n]{0,180})/gi,
4550
+ /(?:milestone|done):\s*([^.!?\n]{8,220})/gi
4551
+ ]);
4552
+ const problems = extractMatches(text, [
4553
+ /\b(?:blocked by|failed because|bug|regression|broken|not working|error)\b([^.!?\n]{0,180})/gi,
4554
+ /(?:problem|issue|risk):\s*([^.!?\n]{8,220})/gi
4555
+ ]);
4556
+ const decisions = extractMatches(text, [
4557
+ /(?:decided|decision|adr|we chose|approved|rejected)\s+([^.!?\n]{8,220})/gi
4558
+ ]);
4559
+ const temporalAnchors = extractMatches(text, [
4560
+ /\b(\d{4}-\d{2}-\d{2}(?:[T ][0-9:.+-Z]+)?)\b/g,
4561
+ /\b(today|yesterday|tomorrow|this week|next week|last week|morning|afternoon|tonight)\b/gi
4562
+ ], 8);
4563
+ const nextActions = extractMatches(text, [
4564
+ /(?:next|todo|follow[- ]?up|remaining|need to)\s*:?\s*([^.!?\n]{8,220})/gi
4565
+ ]);
4566
+ const actors = uniq([
4567
+ row.agent_id,
4568
+ ...extractMatches(text, [/\b(?:agent|employee|owner|assignee)[:= ]+([a-zA-Z][a-zA-Z0-9_-]{1,40})/gi], 5)
4569
+ ], 6);
4570
+ const successSignals = milestones.length ? milestones : outcome === "success_signal" ? [clean(text, 180)] : [];
4571
+ const failureSignals = problems.length ? problems : outcome === "failure_signal" || row.has_error ? [clean(text, 180)] : [];
4572
+ const impact = successSignals.length && failureSignals.length ? "mixed" : failureSignals.length ? "negative" : successSignals.length ? "positive" : "neutral";
4573
+ const signalCount = goals.length + milestones.length + problems.length + decisions.length + nextActions.length;
4574
+ return {
4575
+ labeler: "deterministic",
4576
+ schemaVersion: 1,
4577
+ eventType,
4578
+ intention,
4579
+ outcome,
4580
+ impact,
4581
+ confidence: Math.min(0.95, 0.45 + signalCount * 0.08 + (intention ? 0.1 : 0) + (outcome ? 0.1 : 0)),
4582
+ goals,
4583
+ milestones,
4584
+ problems,
4585
+ decisions,
4586
+ actors,
4587
+ temporalAnchors,
4588
+ successSignals,
4589
+ failureSignals,
4590
+ nextActions,
4591
+ summary: clean(text, 280)
4592
+ };
4593
+ }
4594
+ function ontologyPayload(row) {
4595
+ const semantic = inferSemanticLabel(row);
4596
+ return {
4597
+ tool_name: row.tool_name,
4598
+ memory_version: row.version ?? null,
4599
+ domain: row.domain ?? null,
4600
+ trajectory: row.trajectory ? safeJson(row.trajectory) : null,
4601
+ semantic
4602
+ };
4603
+ }
4604
+ function safeJson(value) {
4605
+ try {
4606
+ return JSON.parse(value);
4607
+ } catch {
4608
+ return value.slice(0, 1e3);
4609
+ }
4610
+ }
4611
+ async function resolveClient(client) {
4612
+ if (client) return client;
4613
+ const { getClient: getClient2 } = await Promise.resolve().then(() => (init_database(), database_exports));
4614
+ return getClient2();
4615
+ }
4616
+ async function insertOntologyForMemory(row, client) {
4617
+ const db = await resolveClient(client);
4618
+ const occurredAt = row.timestamp;
4619
+ const sequence = Number(row.version ?? 0) || Math.floor(new Date(occurredAt).getTime() / 1e3);
4620
+ const eventType = inferOntologyEventType(row);
4621
+ const intention = inferIntention(row);
4622
+ const outcome = inferOutcome(row);
4623
+ const eventId = stableId2("event", row.id);
4624
+ const now = (/* @__PURE__ */ new Date()).toISOString();
4625
+ await db.execute({
4626
+ sql: `INSERT INTO agent_sessions (id, agent_id, project_name, started_at, last_event_at, event_count, properties)
4627
+ VALUES (?, ?, ?, ?, ?, 1, ?)
4628
+ ON CONFLICT(id) DO UPDATE SET last_event_at = MAX(last_event_at, excluded.last_event_at),
4629
+ event_count = event_count + 1`,
4630
+ args: [row.session_id, row.agent_id, row.project_name, occurredAt, occurredAt, JSON.stringify({ agent_role: row.agent_role })]
4631
+ });
4632
+ await db.execute({
4633
+ sql: `INSERT OR IGNORE INTO agent_events
4634
+ (id, event_type, occurred_at, sequence_index, actor_agent_id, agent_role, project_name,
4635
+ session_id, task_id, goal_id, parent_event_id, intention, outcome, evidence_memory_id,
4636
+ impact, payload, created_at)
4637
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NULL, NULL, ?, ?, ?, ?, ?, ?)`,
4638
+ args: [
4639
+ eventId,
4640
+ eventType,
4641
+ occurredAt,
4642
+ sequence,
4643
+ row.agent_id,
4644
+ row.agent_role,
4645
+ row.project_name,
4646
+ row.session_id,
4647
+ row.task_id ?? null,
4648
+ intention,
4649
+ outcome,
4650
+ row.id,
4651
+ row.has_error ? "negative" : outcome === "success_signal" ? "positive" : "neutral",
4652
+ JSON.stringify(ontologyPayload(row)),
4653
+ now
4654
+ ]
4655
+ });
4656
+ const semantic = inferSemanticLabel(row);
4657
+ await db.execute({
4658
+ sql: `INSERT INTO agent_semantic_labels
4659
+ (id, source_memory_id, event_id, labeler, schema_version, confidence, labels, created_at, updated_at)
4660
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
4661
+ ON CONFLICT(id) DO UPDATE SET confidence = excluded.confidence,
4662
+ labels = excluded.labels, updated_at = excluded.updated_at`,
4663
+ args: [
4664
+ stableId2("semantic", row.id, semantic.labeler, semantic.schemaVersion),
4665
+ row.id,
4666
+ eventId,
4667
+ semantic.labeler,
4668
+ semantic.schemaVersion,
4669
+ semantic.confidence,
4670
+ JSON.stringify(semantic),
4671
+ now,
4672
+ now
4673
+ ]
4674
+ });
4675
+ for (const statement of extractGoalCandidates(row)) {
4676
+ const goalId = stableId2("goal", row.project_name, statement.toLowerCase());
4677
+ await db.execute({
4678
+ sql: `INSERT INTO agent_goals
4679
+ (id, statement, owner_agent_id, project_name, status, priority, success_criteria,
4680
+ parent_goal_id, due_at, achieved_at, supersedes_id, created_at, updated_at, source_memory_id)
4681
+ VALUES (?, ?, ?, ?, 'open', 5, NULL, NULL, NULL, NULL, NULL, ?, ?, ?)
4682
+ ON CONFLICT(id) DO UPDATE SET updated_at = excluded.updated_at`,
4683
+ args: [goalId, statement, row.agent_id, row.project_name, now, now, row.id]
4684
+ });
4685
+ await db.execute({
4686
+ sql: `INSERT OR IGNORE INTO agent_goal_links
4687
+ (id, goal_id, link_type, target_id, target_type, created_at)
4688
+ VALUES (?, ?, 'evidence', ?, 'memory', ?)`,
4689
+ args: [stableId2("goal_link", goalId, row.id, "memory"), goalId, row.id, now]
4690
+ });
4691
+ await db.execute({
4692
+ sql: `INSERT OR IGNORE INTO agent_goal_links
4693
+ (id, goal_id, link_type, target_id, target_type, created_at)
4694
+ VALUES (?, ?, 'event', ?, 'event', ?)`,
4695
+ args: [stableId2("goal_link", goalId, eventId, "event"), goalId, eventId, now]
4696
+ });
4697
+ }
4698
+ }
4699
+ async function insertOntologyForBatch(rows, client) {
4700
+ const db = await resolveClient(client);
4701
+ let count = 0;
4702
+ for (const row of rows) {
4703
+ try {
4704
+ await insertOntologyForMemory(row, db);
4705
+ count++;
4706
+ } catch {
4707
+ }
4708
+ }
4709
+ return count;
4710
+ }
4711
+ var init_agentic_ontology = __esm({
4712
+ "src/lib/agentic-ontology.ts"() {
4713
+ "use strict";
4714
+ }
4715
+ });
4716
+
4204
4717
  // src/lib/store.ts
4205
4718
  var store_exports = {};
4206
4719
  __export(store_exports, {
@@ -4544,6 +5057,11 @@ async function flushBatch() {
4544
5057
  await insertMemoryCardsForBatch2(batch);
4545
5058
  } catch {
4546
5059
  }
5060
+ try {
5061
+ const { insertOntologyForBatch: insertOntologyForBatch2 } = await Promise.resolve().then(() => (init_agentic_ontology(), agentic_ontology_exports));
5062
+ await insertOntologyForBatch2(batch);
5063
+ } catch {
5064
+ }
4547
5065
  schedulePostWriteMemoryHygiene(batch.map((row) => row.id));
4548
5066
  _pendingRecords.splice(0, batch.length);
4549
5067
  try {
@@ -5162,7 +5680,7 @@ __export(file_grep_exports, {
5162
5680
  grepProjectFiles: () => grepProjectFiles
5163
5681
  });
5164
5682
  import { execSync as execSync4 } from "child_process";
5165
- import { readFileSync as readFileSync5, readdirSync as readdirSync2, statSync as statSync3, existsSync as existsSync9 } from "fs";
5683
+ import { readFileSync as readFileSync5, readdirSync as readdirSync2, statSync as statSync4, existsSync as existsSync9 } from "fs";
5166
5684
  import path10 from "path";
5167
5685
  import crypto2 from "crypto";
5168
5686
  function hasRipgrep() {
@@ -5279,7 +5797,7 @@ function grepWithNodeFs(pattern, projectRoot, patterns) {
5279
5797
  for (const filePath of files.slice(0, MAX_FILES)) {
5280
5798
  const absPath = path10.join(projectRoot, filePath);
5281
5799
  try {
5282
- const stat = statSync3(absPath);
5800
+ const stat = statSync4(absPath);
5283
5801
  if (stat.size > MAX_FILE_SIZE) continue;
5284
5802
  const content = readFileSync5(absPath, "utf8");
5285
5803
  const lines = content.split("\n");