@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
@@ -203,6 +203,11 @@ function normalizeAutoUpdate(raw) {
203
203
  const userAU = raw.autoUpdate ?? {};
204
204
  raw.autoUpdate = { ...defaultAU, ...userAU };
205
205
  }
206
+ function normalizeOrchestration(raw) {
207
+ const defaultOrg = DEFAULT_CONFIG.orchestration;
208
+ const userOrg = raw.orchestration ?? {};
209
+ raw.orchestration = { ...defaultOrg, ...userOrg };
210
+ }
206
211
  async function loadConfig() {
207
212
  const dir = process.env.EXE_OS_DIR ?? process.env.EXE_MEM_DIR ?? EXE_AI_DIR;
208
213
  await ensurePrivateDir(dir);
@@ -227,10 +232,15 @@ async function loadConfig() {
227
232
  normalizeScalingRoadmap(migratedCfg);
228
233
  normalizeSessionLifecycle(migratedCfg);
229
234
  normalizeAutoUpdate(migratedCfg);
235
+ normalizeOrchestration(migratedCfg);
230
236
  const config = { ...DEFAULT_CONFIG, dbPath: path.join(dir, "memories.db"), ...migratedCfg };
231
237
  if (config.dbPath.startsWith("~")) {
232
238
  config.dbPath = config.dbPath.replace(/^~/, os.homedir());
233
239
  }
240
+ const envDbPath = path.join(dir, "memories.db");
241
+ if (process.env.EXE_OS_DIR && config.dbPath !== envDbPath && !existsSync2(config.dbPath) && existsSync2(envDbPath)) {
242
+ config.dbPath = envDbPath;
243
+ }
234
244
  return config;
235
245
  } catch {
236
246
  return { ...DEFAULT_CONFIG, dbPath: path.join(dir, "memories.db") };
@@ -250,7 +260,16 @@ function loadConfigSync() {
250
260
  normalizeScalingRoadmap(migratedCfg);
251
261
  normalizeSessionLifecycle(migratedCfg);
252
262
  normalizeAutoUpdate(migratedCfg);
253
- return { ...DEFAULT_CONFIG, dbPath: path.join(dir, "memories.db"), ...migratedCfg };
263
+ normalizeOrchestration(migratedCfg);
264
+ const config = { ...DEFAULT_CONFIG, dbPath: path.join(dir, "memories.db"), ...migratedCfg };
265
+ if (config.dbPath.startsWith("~")) {
266
+ config.dbPath = config.dbPath.replace(/^~/, os.homedir());
267
+ }
268
+ const envDbPath = path.join(dir, "memories.db");
269
+ if (process.env.EXE_OS_DIR && config.dbPath !== envDbPath && !existsSync2(config.dbPath) && existsSync2(envDbPath)) {
270
+ config.dbPath = envDbPath;
271
+ }
272
+ return config;
254
273
  } catch {
255
274
  return { ...DEFAULT_CONFIG, dbPath: path.join(dir, "memories.db") };
256
275
  }
@@ -271,6 +290,7 @@ async function loadConfigFrom(configPath) {
271
290
  normalizeScalingRoadmap(migratedCfg);
272
291
  normalizeSessionLifecycle(migratedCfg);
273
292
  normalizeAutoUpdate(migratedCfg);
293
+ normalizeOrchestration(migratedCfg);
274
294
  return { ...DEFAULT_CONFIG, ...migratedCfg };
275
295
  } catch {
276
296
  return { ...DEFAULT_CONFIG };
@@ -342,6 +362,10 @@ var init_config = __esm({
342
362
  checkOnBoot: true,
343
363
  autoInstall: false,
344
364
  checkIntervalMs: 24 * 60 * 60 * 1e3
365
+ },
366
+ orchestration: {
367
+ phase: "phase_1_coo",
368
+ phaseSetBy: "default"
345
369
  }
346
370
  };
347
371
  CONFIG_MIGRATIONS = [
@@ -1723,6 +1747,9 @@ function getClient() {
1723
1747
  if (_daemonClient && _daemonClient._isDaemonActive()) {
1724
1748
  return _daemonClient;
1725
1749
  }
1750
+ if (!_resilientClient) {
1751
+ return _adapterClient;
1752
+ }
1726
1753
  return _resilientClient;
1727
1754
  }
1728
1755
  async function initDaemonClient() {
@@ -2755,6 +2782,127 @@ async function ensureSchema() {
2755
2782
  VALUES (new.rowid, new.content, new.subject, new.predicate, new.object);
2756
2783
  END;
2757
2784
  `);
2785
+ await client.executeMultiple(`
2786
+ CREATE TABLE IF NOT EXISTS agent_sessions (
2787
+ id TEXT PRIMARY KEY,
2788
+ agent_id TEXT NOT NULL,
2789
+ project_name TEXT,
2790
+ started_at TEXT NOT NULL,
2791
+ last_event_at TEXT NOT NULL,
2792
+ event_count INTEGER NOT NULL DEFAULT 0,
2793
+ properties TEXT DEFAULT '{}'
2794
+ );
2795
+
2796
+ CREATE INDEX IF NOT EXISTS idx_agent_sessions_agent_time
2797
+ ON agent_sessions(agent_id, started_at);
2798
+
2799
+ CREATE TABLE IF NOT EXISTS agent_goals (
2800
+ id TEXT PRIMARY KEY,
2801
+ statement TEXT NOT NULL,
2802
+ owner_agent_id TEXT,
2803
+ project_name TEXT,
2804
+ status TEXT NOT NULL DEFAULT 'open',
2805
+ priority INTEGER NOT NULL DEFAULT 5,
2806
+ success_criteria TEXT,
2807
+ parent_goal_id TEXT,
2808
+ due_at TEXT,
2809
+ achieved_at TEXT,
2810
+ supersedes_id TEXT,
2811
+ created_at TEXT NOT NULL,
2812
+ updated_at TEXT NOT NULL,
2813
+ source_memory_id TEXT
2814
+ );
2815
+
2816
+ CREATE INDEX IF NOT EXISTS idx_agent_goals_project_status
2817
+ ON agent_goals(project_name, status, priority);
2818
+
2819
+ CREATE TABLE IF NOT EXISTS agent_events (
2820
+ id TEXT PRIMARY KEY,
2821
+ event_type TEXT NOT NULL,
2822
+ occurred_at TEXT NOT NULL,
2823
+ sequence_index INTEGER NOT NULL,
2824
+ actor_agent_id TEXT,
2825
+ agent_role TEXT,
2826
+ project_name TEXT,
2827
+ session_id TEXT,
2828
+ task_id TEXT,
2829
+ goal_id TEXT,
2830
+ parent_event_id TEXT,
2831
+ intention TEXT,
2832
+ outcome TEXT,
2833
+ evidence_memory_id TEXT,
2834
+ impact TEXT,
2835
+ payload TEXT DEFAULT '{}',
2836
+ created_at TEXT NOT NULL
2837
+ );
2838
+
2839
+ CREATE INDEX IF NOT EXISTS idx_agent_events_time
2840
+ ON agent_events(occurred_at, sequence_index);
2841
+
2842
+ CREATE INDEX IF NOT EXISTS idx_agent_events_session_seq
2843
+ ON agent_events(session_id, sequence_index);
2844
+
2845
+ CREATE INDEX IF NOT EXISTS idx_agent_events_goal_time
2846
+ ON agent_events(goal_id, occurred_at);
2847
+
2848
+ CREATE INDEX IF NOT EXISTS idx_agent_events_memory
2849
+ ON agent_events(evidence_memory_id);
2850
+
2851
+ CREATE TABLE IF NOT EXISTS agent_goal_links (
2852
+ id TEXT PRIMARY KEY,
2853
+ goal_id TEXT NOT NULL,
2854
+ link_type TEXT NOT NULL,
2855
+ target_id TEXT NOT NULL,
2856
+ target_type TEXT NOT NULL,
2857
+ created_at TEXT NOT NULL
2858
+ );
2859
+
2860
+ CREATE INDEX IF NOT EXISTS idx_agent_goal_links_goal
2861
+ ON agent_goal_links(goal_id, target_type);
2862
+
2863
+ CREATE TABLE IF NOT EXISTS agent_semantic_labels (
2864
+ id TEXT PRIMARY KEY,
2865
+ source_memory_id TEXT NOT NULL,
2866
+ event_id TEXT,
2867
+ labeler TEXT NOT NULL,
2868
+ schema_version INTEGER NOT NULL DEFAULT 1,
2869
+ confidence REAL NOT NULL DEFAULT 0,
2870
+ labels TEXT NOT NULL,
2871
+ created_at TEXT NOT NULL,
2872
+ updated_at TEXT NOT NULL
2873
+ );
2874
+
2875
+ CREATE INDEX IF NOT EXISTS idx_agent_semantic_labels_memory
2876
+ ON agent_semantic_labels(source_memory_id, labeler);
2877
+
2878
+ CREATE INDEX IF NOT EXISTS idx_agent_semantic_labels_event
2879
+ ON agent_semantic_labels(event_id);
2880
+
2881
+ CREATE TABLE IF NOT EXISTS agent_reflection_checkpoints (
2882
+ id TEXT PRIMARY KEY,
2883
+ project_name TEXT,
2884
+ session_id TEXT,
2885
+ window_start_at TEXT NOT NULL,
2886
+ window_end_at TEXT NOT NULL,
2887
+ event_count INTEGER NOT NULL DEFAULT 0,
2888
+ goal_count INTEGER NOT NULL DEFAULT 0,
2889
+ success_count INTEGER NOT NULL DEFAULT 0,
2890
+ failure_count INTEGER NOT NULL DEFAULT 0,
2891
+ risk_count INTEGER NOT NULL DEFAULT 0,
2892
+ summary TEXT NOT NULL,
2893
+ learnings TEXT NOT NULL DEFAULT '[]',
2894
+ next_actions TEXT NOT NULL DEFAULT '[]',
2895
+ evidence_event_ids TEXT NOT NULL DEFAULT '[]',
2896
+ confidence REAL NOT NULL DEFAULT 0,
2897
+ created_at TEXT NOT NULL
2898
+ );
2899
+
2900
+ CREATE INDEX IF NOT EXISTS idx_agent_reflection_project_time
2901
+ ON agent_reflection_checkpoints(project_name, window_end_at);
2902
+
2903
+ CREATE INDEX IF NOT EXISTS idx_agent_reflection_session_time
2904
+ ON agent_reflection_checkpoints(session_id, window_end_at);
2905
+ `);
2758
2906
  try {
2759
2907
  await client.execute({
2760
2908
  sql: `ALTER TABLE memories ADD COLUMN tier INTEGER DEFAULT 3`,
@@ -2904,7 +3052,7 @@ var init_database = __esm({
2904
3052
 
2905
3053
  // src/lib/keychain.ts
2906
3054
  import { readFile as readFile3, writeFile as writeFile3, unlink, mkdir as mkdir3, chmod as chmod2 } from "fs/promises";
2907
- import { existsSync as existsSync6 } from "fs";
3055
+ import { existsSync as existsSync6, statSync as statSync2 } from "fs";
2908
3056
  import { execSync as execSync2 } from "child_process";
2909
3057
  import path6 from "path";
2910
3058
  import os5 from "os";
@@ -2914,29 +3062,65 @@ function getKeyDir() {
2914
3062
  function getKeyPath() {
2915
3063
  return path6.join(getKeyDir(), "master.key");
2916
3064
  }
2917
- function macKeychainGet() {
3065
+ function nativeKeychainAllowed() {
3066
+ return process.env.EXE_OS_DISABLE_NATIVE_KEYCHAIN !== "1";
3067
+ }
3068
+ function linuxSecretAvailable() {
3069
+ if (!nativeKeychainAllowed()) return false;
3070
+ if (process.platform !== "linux") return false;
3071
+ if (linuxSecretAvailability !== null) return linuxSecretAvailability;
3072
+ try {
3073
+ execSync2("command -v secret-tool >/dev/null 2>&1", { timeout: 1e3 });
3074
+ } catch {
3075
+ linuxSecretAvailability = false;
3076
+ return false;
3077
+ }
3078
+ try {
3079
+ execSync2("secret-tool search --all exe-os probe >/dev/null 2>&1", { timeout: 1e3 });
3080
+ linuxSecretAvailability = true;
3081
+ } catch {
3082
+ linuxSecretAvailability = false;
3083
+ }
3084
+ return linuxSecretAvailability;
3085
+ }
3086
+ function isRootOnlyTrustedServerKeyFile(keyPath) {
3087
+ if (process.platform !== "linux") return false;
3088
+ try {
3089
+ const uid = typeof os5.userInfo().uid === "number" ? os5.userInfo().uid : -1;
3090
+ const st = statSync2(keyPath);
3091
+ if (!st.isFile() || (st.mode & 63) !== 0) return false;
3092
+ if (uid === 0) return true;
3093
+ const exeOsDir = process.env.EXE_OS_DIR;
3094
+ return Boolean(exeOsDir && path6.resolve(keyPath).startsWith(path6.resolve(exeOsDir) + path6.sep));
3095
+ } catch {
3096
+ return false;
3097
+ }
3098
+ }
3099
+ function macKeychainGet(service = SERVICE) {
3100
+ if (!nativeKeychainAllowed()) return null;
2918
3101
  if (process.platform !== "darwin") return null;
2919
3102
  try {
2920
3103
  return execSync2(
2921
- `security find-generic-password -s "${SERVICE}" -a "${ACCOUNT}" -w 2>/dev/null`,
3104
+ `security find-generic-password -s "${service}" -a "${ACCOUNT}" -w 2>/dev/null`,
2922
3105
  { encoding: "utf-8", timeout: 5e3 }
2923
3106
  ).trim();
2924
3107
  } catch {
2925
3108
  return null;
2926
3109
  }
2927
3110
  }
2928
- function macKeychainSet(value) {
3111
+ function macKeychainSet(value, service = SERVICE) {
3112
+ if (!nativeKeychainAllowed()) return false;
2929
3113
  if (process.platform !== "darwin") return false;
2930
3114
  try {
2931
3115
  try {
2932
3116
  execSync2(
2933
- `security delete-generic-password -s "${SERVICE}" -a "${ACCOUNT}" 2>/dev/null`,
3117
+ `security delete-generic-password -s "${service}" -a "${ACCOUNT}" 2>/dev/null`,
2934
3118
  { timeout: 5e3 }
2935
3119
  );
2936
3120
  } catch {
2937
3121
  }
2938
3122
  execSync2(
2939
- `security add-generic-password -s "${SERVICE}" -a "${ACCOUNT}" -w "${value}"`,
3123
+ `security add-generic-password -s "${service}" -a "${ACCOUNT}" -w "${value}"`,
2940
3124
  { timeout: 5e3 }
2941
3125
  );
2942
3126
  return true;
@@ -2944,22 +3128,48 @@ function macKeychainSet(value) {
2944
3128
  return false;
2945
3129
  }
2946
3130
  }
2947
- function linuxSecretGet() {
2948
- if (process.platform !== "linux") return null;
3131
+ function macKeychainDelete(service = SERVICE) {
3132
+ if (!nativeKeychainAllowed()) return false;
3133
+ if (process.platform !== "darwin") return false;
3134
+ try {
3135
+ execSync2(
3136
+ `security delete-generic-password -s "${service}" -a "${ACCOUNT}" 2>/dev/null`,
3137
+ { timeout: 5e3 }
3138
+ );
3139
+ return true;
3140
+ } catch {
3141
+ return false;
3142
+ }
3143
+ }
3144
+ function linuxSecretGet(service = SERVICE) {
3145
+ if (!linuxSecretAvailable()) return null;
2949
3146
  try {
2950
3147
  return execSync2(
2951
- `secret-tool lookup service "${SERVICE}" account "${ACCOUNT}" 2>/dev/null`,
3148
+ `secret-tool lookup service "${service}" account "${ACCOUNT}" 2>/dev/null`,
2952
3149
  { encoding: "utf-8", timeout: 5e3 }
2953
3150
  ).trim();
2954
3151
  } catch {
2955
3152
  return null;
2956
3153
  }
2957
3154
  }
2958
- function linuxSecretSet(value) {
3155
+ function linuxSecretSet(value, service = SERVICE) {
3156
+ if (!linuxSecretAvailable()) return false;
3157
+ try {
3158
+ execSync2(
3159
+ `echo -n "${value}" | secret-tool store --label="exe-os master key" service "${service}" account "${ACCOUNT}" 2>/dev/null`,
3160
+ { timeout: 5e3 }
3161
+ );
3162
+ return true;
3163
+ } catch {
3164
+ return false;
3165
+ }
3166
+ }
3167
+ function linuxSecretDelete(service = SERVICE) {
3168
+ if (!nativeKeychainAllowed()) return false;
2959
3169
  if (process.platform !== "linux") return false;
2960
3170
  try {
2961
3171
  execSync2(
2962
- `echo -n "${value}" | secret-tool store --label="exe-os master key" service "${SERVICE}" account "${ACCOUNT}"`,
3172
+ `secret-tool clear service "${service}" account "${ACCOUNT}" 2>/dev/null`,
2963
3173
  { timeout: 5e3 }
2964
3174
  );
2965
3175
  return true;
@@ -2968,6 +3178,7 @@ function linuxSecretSet(value) {
2968
3178
  }
2969
3179
  }
2970
3180
  async function tryKeytar() {
3181
+ if (!nativeKeychainAllowed()) return null;
2971
3182
  try {
2972
3183
  return await import("keytar");
2973
3184
  } catch {
@@ -3041,7 +3252,19 @@ async function writeMachineBoundFileFallback(b64) {
3041
3252
  return "plaintext";
3042
3253
  }
3043
3254
  async function getMasterKey() {
3044
- const nativeValue = macKeychainGet() ?? linuxSecretGet();
3255
+ let nativeValue = macKeychainGet() ?? linuxSecretGet();
3256
+ if (!nativeValue) {
3257
+ const legacyValue = macKeychainGet(LEGACY_SERVICE) ?? linuxSecretGet(LEGACY_SERVICE);
3258
+ if (legacyValue) {
3259
+ const migrated = macKeychainSet(legacyValue) || linuxSecretSet(legacyValue);
3260
+ if (migrated) {
3261
+ macKeychainDelete(LEGACY_SERVICE);
3262
+ linuxSecretDelete(LEGACY_SERVICE);
3263
+ process.stderr.write("[keychain] Migrated keychain service from exe-mem to exe-os.\n");
3264
+ }
3265
+ nativeValue = legacyValue;
3266
+ }
3267
+ }
3045
3268
  if (nativeValue) {
3046
3269
  return Buffer.from(nativeValue, "base64");
3047
3270
  }
@@ -3049,12 +3272,17 @@ async function getMasterKey() {
3049
3272
  if (keytar) {
3050
3273
  try {
3051
3274
  const keytarValue = await keytar.getPassword(SERVICE, ACCOUNT);
3052
- if (keytarValue) {
3053
- const migrated = macKeychainSet(keytarValue) || linuxSecretSet(keytarValue);
3275
+ const legacyKeytarValue = keytarValue ?? await keytar.getPassword(LEGACY_SERVICE, ACCOUNT);
3276
+ if (legacyKeytarValue) {
3277
+ const migrated = macKeychainSet(legacyKeytarValue) || linuxSecretSet(legacyKeytarValue);
3054
3278
  if (migrated) {
3055
3279
  process.stderr.write("[keychain] Migrated key from keytar to native keychain.\n");
3280
+ try {
3281
+ await keytar.deletePassword(LEGACY_SERVICE, ACCOUNT);
3282
+ } catch {
3283
+ }
3056
3284
  }
3057
- return Buffer.from(keytarValue, "base64");
3285
+ return Buffer.from(legacyKeytarValue, "base64");
3058
3286
  }
3059
3287
  } catch {
3060
3288
  }
@@ -3079,7 +3307,7 @@ async function getMasterKey() {
3079
3307
  const decrypted = decryptWithMachineKey(content, machineKey);
3080
3308
  if (!decrypted) {
3081
3309
  process.stderr.write(
3082
- "[keychain] Key decryption failed \u2014 machine may have changed.\n Use your 24-word recovery phrase: exe-os link import\n"
3310
+ "[keychain] Key decryption failed \u2014 machine may have changed.\n Use your 24-word recovery phrase during setup: exe-os setup\n"
3083
3311
  );
3084
3312
  return null;
3085
3313
  }
@@ -3088,6 +3316,9 @@ async function getMasterKey() {
3088
3316
  b64Value = content;
3089
3317
  }
3090
3318
  const key = Buffer.from(b64Value, "base64");
3319
+ if (!content.startsWith(ENCRYPTED_PREFIX) && isRootOnlyTrustedServerKeyFile(keyPath)) {
3320
+ return key;
3321
+ }
3091
3322
  const migrated = macKeychainSet(b64Value) || linuxSecretSet(b64Value);
3092
3323
  if (migrated) {
3093
3324
  process.stderr.write("[keychain] Migrated key from file to native keychain.\n");
@@ -3115,12 +3346,14 @@ async function getMasterKey() {
3115
3346
  return null;
3116
3347
  }
3117
3348
  }
3118
- var SERVICE, ACCOUNT, ENCRYPTED_PREFIX;
3349
+ var SERVICE, LEGACY_SERVICE, ACCOUNT, linuxSecretAvailability, ENCRYPTED_PREFIX;
3119
3350
  var init_keychain = __esm({
3120
3351
  "src/lib/keychain.ts"() {
3121
3352
  "use strict";
3122
- SERVICE = "exe-mem";
3353
+ SERVICE = "exe-os";
3354
+ LEGACY_SERVICE = "exe-mem";
3123
3355
  ACCOUNT = "master-key";
3356
+ linuxSecretAvailability = null;
3124
3357
  ENCRYPTED_PREFIX = "enc:";
3125
3358
  }
3126
3359
  });
@@ -3390,7 +3623,7 @@ __export(shard_manager_exports, {
3390
3623
  shardExists: () => shardExists
3391
3624
  });
3392
3625
  import path7 from "path";
3393
- import { existsSync as existsSync7, mkdirSync as mkdirSync2, readdirSync, renameSync as renameSync3, statSync as statSync2 } from "fs";
3626
+ import { existsSync as existsSync7, mkdirSync as mkdirSync2, readdirSync, renameSync as renameSync3, statSync as statSync3 } from "fs";
3394
3627
  import { createClient as createClient2 } from "@libsql/client";
3395
3628
  function initShardManager(encryptionKey) {
3396
3629
  _encryptionKey = encryptionKey;
@@ -3454,7 +3687,7 @@ async function auditShardHealth(options = {}) {
3454
3687
  const shards = [];
3455
3688
  for (const name of names) {
3456
3689
  const dbPath = path7.join(SHARDS_DIR, `${name}.db`);
3457
- const stat = statSync2(dbPath);
3690
+ const stat = statSync3(dbPath);
3458
3691
  const item = {
3459
3692
  name,
3460
3693
  path: dbPath,
@@ -3707,7 +3940,7 @@ async function getReadyShardClient(projectName) {
3707
3940
  _shardLastAccess.delete(safeName);
3708
3941
  const dbPath = path7.join(SHARDS_DIR, `${safeName}.db`);
3709
3942
  if (existsSync7(dbPath)) {
3710
- const stat = statSync2(dbPath);
3943
+ const stat = statSync3(dbPath);
3711
3944
  const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
3712
3945
  const archivedPath = path7.join(SHARDS_DIR, `${safeName}.db.broken-${stamp}`);
3713
3946
  renameSync3(dbPath, archivedPath);
@@ -3827,6 +4060,12 @@ var init_platform_procedures = __esm({
3827
4060
  priority: "p0",
3828
4061
  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."
3829
4062
  },
4063
+ {
4064
+ title: "Customer orchestration maturity \u2014 recommend, never trap",
4065
+ domain: "workflow",
4066
+ priority: "p1",
4067
+ 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."
4068
+ },
3830
4069
  {
3831
4070
  title: "Single dispatch path \u2014 create_task only",
3832
4071
  domain: "workflow",
@@ -3885,6 +4124,12 @@ var init_platform_procedures = __esm({
3885
4124
  priority: "p0",
3886
4125
  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."
3887
4126
  },
4127
+ {
4128
+ title: "Commit discipline \u2014 never leave verified work floating",
4129
+ domain: "workflow",
4130
+ priority: "p1",
4131
+ 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."
4132
+ },
3888
4133
  {
3889
4134
  title: "Desktop and TUI are the same product",
3890
4135
  domain: "architecture",
@@ -4202,6 +4447,274 @@ var init_memory_cards = __esm({
4202
4447
  }
4203
4448
  });
4204
4449
 
4450
+ // src/lib/agentic-ontology.ts
4451
+ var agentic_ontology_exports = {};
4452
+ __export(agentic_ontology_exports, {
4453
+ clean: () => clean,
4454
+ extractGoalCandidates: () => extractGoalCandidates,
4455
+ inferIntention: () => inferIntention,
4456
+ inferOntologyEventType: () => inferOntologyEventType,
4457
+ inferOutcome: () => inferOutcome,
4458
+ inferSemanticLabel: () => inferSemanticLabel,
4459
+ insertOntologyForBatch: () => insertOntologyForBatch,
4460
+ insertOntologyForMemory: () => insertOntologyForMemory,
4461
+ ontologyPayload: () => ontologyPayload,
4462
+ stableId: () => stableId2
4463
+ });
4464
+ import { createHash as createHash3 } from "crypto";
4465
+ function stableId2(...parts) {
4466
+ return createHash3("sha256").update(parts.map((p) => String(p ?? "")).join("::")).digest("hex").slice(0, 32);
4467
+ }
4468
+ function clean(text, max = 240) {
4469
+ return text.replace(/\u0000/g, "").replace(/```[\s\S]*?```/g, " ").replace(/\s+/g, " ").trim().slice(0, max);
4470
+ }
4471
+ function inferOntologyEventType(row) {
4472
+ const lower = row.raw_text.toLowerCase();
4473
+ if (row.has_error) return "error";
4474
+ if (/\b(done|complete|completed|fixed|resolved|shipped|deployed|pushed|published)\b/.test(lower)) return "milestone";
4475
+ if (/\b(blocked|failed|error|bug|regression|broken)\b/.test(lower)) return "problem";
4476
+ if (/\b(decided|decision|adr|we chose|approved|rejected)\b/.test(lower)) return "decision";
4477
+ if (/\b(goal|need to|we need|want to|trying to|objective)\b/.test(lower)) return "goal_signal";
4478
+ if (["Bash", "Read", "Edit", "Write", "Grep", "Glob"].includes(row.tool_name)) return "tool_action";
4479
+ if (row.tool_name.startsWith("memory_card")) return "memory_card";
4480
+ return "memory_observation";
4481
+ }
4482
+ function inferIntention(row) {
4483
+ if (row.intent) return clean(row.intent, 220);
4484
+ const text = clean(row.raw_text, 1e3);
4485
+ const patterns = [
4486
+ /(?: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,
4487
+ /(?:so that|in order to)\s+([^.!?\n]{8,220})/i,
4488
+ /(?:task|plan):\s*([^.!?\n]{8,220})/i
4489
+ ];
4490
+ for (const p of patterns) {
4491
+ const m = text.match(p);
4492
+ if (m?.[1]) return clean(m[1], 220);
4493
+ }
4494
+ if (["Bash", "Read", "Edit", "Write", "Grep", "Glob"].includes(row.tool_name)) {
4495
+ return `${row.tool_name} during ${row.project_name}`;
4496
+ }
4497
+ return null;
4498
+ }
4499
+ function inferOutcome(row) {
4500
+ if (row.outcome) return clean(row.outcome, 220);
4501
+ if (row.has_error) return "error";
4502
+ const lower = row.raw_text.toLowerCase();
4503
+ if (/\b(done|complete|completed|fixed|resolved|shipped|deployed|pushed|published|passed)\b/.test(lower)) return "success_signal";
4504
+ if (/\b(blocked|failed|error|regression|broken|not working|could not)\b/.test(lower)) return "failure_signal";
4505
+ if (/\b(warning|risk|concern|caveat)\b/.test(lower)) return "risk_signal";
4506
+ return null;
4507
+ }
4508
+ function extractGoalCandidates(row) {
4509
+ const text = clean(row.raw_text, 1600);
4510
+ const patterns = [
4511
+ /(?: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,
4512
+ /(?:success means|success criteria|so that)\s+([^.!?\n]{12,220})/gi
4513
+ ];
4514
+ const out = [];
4515
+ for (const pattern of patterns) {
4516
+ for (const m of text.matchAll(pattern)) {
4517
+ const candidate = clean(m[1] ?? "", 220);
4518
+ if (candidate.length >= 12 && !out.some((x) => x.toLowerCase() === candidate.toLowerCase())) out.push(candidate);
4519
+ if (out.length >= 3) return out;
4520
+ }
4521
+ }
4522
+ return out;
4523
+ }
4524
+ function uniq(values, max = 6) {
4525
+ const out = [];
4526
+ for (const value of values.map((v) => clean(v, 220)).filter(Boolean)) {
4527
+ if (!out.some((x) => x.toLowerCase() === value.toLowerCase())) out.push(value);
4528
+ if (out.length >= max) break;
4529
+ }
4530
+ return out;
4531
+ }
4532
+ function extractMatches(text, patterns, max = 5) {
4533
+ const out = [];
4534
+ for (const pattern of patterns) {
4535
+ for (const match of text.matchAll(pattern)) {
4536
+ const value = match[1] ?? match[0];
4537
+ if (value) out.push(value);
4538
+ if (out.length >= max) return uniq(out, max);
4539
+ }
4540
+ }
4541
+ return uniq(out, max);
4542
+ }
4543
+ function inferSemanticLabel(row) {
4544
+ const text = clean(row.raw_text, 2400);
4545
+ const eventType = inferOntologyEventType(row);
4546
+ const intention = inferIntention(row);
4547
+ const outcome = inferOutcome(row);
4548
+ const goals = extractGoalCandidates(row);
4549
+ const milestones = extractMatches(text, [
4550
+ /\b(?:completed|finished|fixed|resolved|shipped|deployed|published|pushed|passed)\b([^.!?\n]{0,180})/gi,
4551
+ /(?:milestone|done):\s*([^.!?\n]{8,220})/gi
4552
+ ]);
4553
+ const problems = extractMatches(text, [
4554
+ /\b(?:blocked by|failed because|bug|regression|broken|not working|error)\b([^.!?\n]{0,180})/gi,
4555
+ /(?:problem|issue|risk):\s*([^.!?\n]{8,220})/gi
4556
+ ]);
4557
+ const decisions = extractMatches(text, [
4558
+ /(?:decided|decision|adr|we chose|approved|rejected)\s+([^.!?\n]{8,220})/gi
4559
+ ]);
4560
+ const temporalAnchors = extractMatches(text, [
4561
+ /\b(\d{4}-\d{2}-\d{2}(?:[T ][0-9:.+-Z]+)?)\b/g,
4562
+ /\b(today|yesterday|tomorrow|this week|next week|last week|morning|afternoon|tonight)\b/gi
4563
+ ], 8);
4564
+ const nextActions = extractMatches(text, [
4565
+ /(?:next|todo|follow[- ]?up|remaining|need to)\s*:?\s*([^.!?\n]{8,220})/gi
4566
+ ]);
4567
+ const actors = uniq([
4568
+ row.agent_id,
4569
+ ...extractMatches(text, [/\b(?:agent|employee|owner|assignee)[:= ]+([a-zA-Z][a-zA-Z0-9_-]{1,40})/gi], 5)
4570
+ ], 6);
4571
+ const successSignals = milestones.length ? milestones : outcome === "success_signal" ? [clean(text, 180)] : [];
4572
+ const failureSignals = problems.length ? problems : outcome === "failure_signal" || row.has_error ? [clean(text, 180)] : [];
4573
+ const impact = successSignals.length && failureSignals.length ? "mixed" : failureSignals.length ? "negative" : successSignals.length ? "positive" : "neutral";
4574
+ const signalCount = goals.length + milestones.length + problems.length + decisions.length + nextActions.length;
4575
+ return {
4576
+ labeler: "deterministic",
4577
+ schemaVersion: 1,
4578
+ eventType,
4579
+ intention,
4580
+ outcome,
4581
+ impact,
4582
+ confidence: Math.min(0.95, 0.45 + signalCount * 0.08 + (intention ? 0.1 : 0) + (outcome ? 0.1 : 0)),
4583
+ goals,
4584
+ milestones,
4585
+ problems,
4586
+ decisions,
4587
+ actors,
4588
+ temporalAnchors,
4589
+ successSignals,
4590
+ failureSignals,
4591
+ nextActions,
4592
+ summary: clean(text, 280)
4593
+ };
4594
+ }
4595
+ function ontologyPayload(row) {
4596
+ const semantic = inferSemanticLabel(row);
4597
+ return {
4598
+ tool_name: row.tool_name,
4599
+ memory_version: row.version ?? null,
4600
+ domain: row.domain ?? null,
4601
+ trajectory: row.trajectory ? safeJson(row.trajectory) : null,
4602
+ semantic
4603
+ };
4604
+ }
4605
+ function safeJson(value) {
4606
+ try {
4607
+ return JSON.parse(value);
4608
+ } catch {
4609
+ return value.slice(0, 1e3);
4610
+ }
4611
+ }
4612
+ async function resolveClient(client) {
4613
+ if (client) return client;
4614
+ const { getClient: getClient2 } = await Promise.resolve().then(() => (init_database(), database_exports));
4615
+ return getClient2();
4616
+ }
4617
+ async function insertOntologyForMemory(row, client) {
4618
+ const db = await resolveClient(client);
4619
+ const occurredAt = row.timestamp;
4620
+ const sequence = Number(row.version ?? 0) || Math.floor(new Date(occurredAt).getTime() / 1e3);
4621
+ const eventType = inferOntologyEventType(row);
4622
+ const intention = inferIntention(row);
4623
+ const outcome = inferOutcome(row);
4624
+ const eventId = stableId2("event", row.id);
4625
+ const now = (/* @__PURE__ */ new Date()).toISOString();
4626
+ await db.execute({
4627
+ sql: `INSERT INTO agent_sessions (id, agent_id, project_name, started_at, last_event_at, event_count, properties)
4628
+ VALUES (?, ?, ?, ?, ?, 1, ?)
4629
+ ON CONFLICT(id) DO UPDATE SET last_event_at = MAX(last_event_at, excluded.last_event_at),
4630
+ event_count = event_count + 1`,
4631
+ args: [row.session_id, row.agent_id, row.project_name, occurredAt, occurredAt, JSON.stringify({ agent_role: row.agent_role })]
4632
+ });
4633
+ await db.execute({
4634
+ sql: `INSERT OR IGNORE INTO agent_events
4635
+ (id, event_type, occurred_at, sequence_index, actor_agent_id, agent_role, project_name,
4636
+ session_id, task_id, goal_id, parent_event_id, intention, outcome, evidence_memory_id,
4637
+ impact, payload, created_at)
4638
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NULL, NULL, ?, ?, ?, ?, ?, ?)`,
4639
+ args: [
4640
+ eventId,
4641
+ eventType,
4642
+ occurredAt,
4643
+ sequence,
4644
+ row.agent_id,
4645
+ row.agent_role,
4646
+ row.project_name,
4647
+ row.session_id,
4648
+ row.task_id ?? null,
4649
+ intention,
4650
+ outcome,
4651
+ row.id,
4652
+ row.has_error ? "negative" : outcome === "success_signal" ? "positive" : "neutral",
4653
+ JSON.stringify(ontologyPayload(row)),
4654
+ now
4655
+ ]
4656
+ });
4657
+ const semantic = inferSemanticLabel(row);
4658
+ await db.execute({
4659
+ sql: `INSERT INTO agent_semantic_labels
4660
+ (id, source_memory_id, event_id, labeler, schema_version, confidence, labels, created_at, updated_at)
4661
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
4662
+ ON CONFLICT(id) DO UPDATE SET confidence = excluded.confidence,
4663
+ labels = excluded.labels, updated_at = excluded.updated_at`,
4664
+ args: [
4665
+ stableId2("semantic", row.id, semantic.labeler, semantic.schemaVersion),
4666
+ row.id,
4667
+ eventId,
4668
+ semantic.labeler,
4669
+ semantic.schemaVersion,
4670
+ semantic.confidence,
4671
+ JSON.stringify(semantic),
4672
+ now,
4673
+ now
4674
+ ]
4675
+ });
4676
+ for (const statement of extractGoalCandidates(row)) {
4677
+ const goalId = stableId2("goal", row.project_name, statement.toLowerCase());
4678
+ await db.execute({
4679
+ sql: `INSERT INTO agent_goals
4680
+ (id, statement, owner_agent_id, project_name, status, priority, success_criteria,
4681
+ parent_goal_id, due_at, achieved_at, supersedes_id, created_at, updated_at, source_memory_id)
4682
+ VALUES (?, ?, ?, ?, 'open', 5, NULL, NULL, NULL, NULL, NULL, ?, ?, ?)
4683
+ ON CONFLICT(id) DO UPDATE SET updated_at = excluded.updated_at`,
4684
+ args: [goalId, statement, row.agent_id, row.project_name, now, now, row.id]
4685
+ });
4686
+ await db.execute({
4687
+ sql: `INSERT OR IGNORE INTO agent_goal_links
4688
+ (id, goal_id, link_type, target_id, target_type, created_at)
4689
+ VALUES (?, ?, 'evidence', ?, 'memory', ?)`,
4690
+ args: [stableId2("goal_link", goalId, row.id, "memory"), goalId, row.id, now]
4691
+ });
4692
+ await db.execute({
4693
+ sql: `INSERT OR IGNORE INTO agent_goal_links
4694
+ (id, goal_id, link_type, target_id, target_type, created_at)
4695
+ VALUES (?, ?, 'event', ?, 'event', ?)`,
4696
+ args: [stableId2("goal_link", goalId, eventId, "event"), goalId, eventId, now]
4697
+ });
4698
+ }
4699
+ }
4700
+ async function insertOntologyForBatch(rows, client) {
4701
+ const db = await resolveClient(client);
4702
+ let count = 0;
4703
+ for (const row of rows) {
4704
+ try {
4705
+ await insertOntologyForMemory(row, db);
4706
+ count++;
4707
+ } catch {
4708
+ }
4709
+ }
4710
+ return count;
4711
+ }
4712
+ var init_agentic_ontology = __esm({
4713
+ "src/lib/agentic-ontology.ts"() {
4714
+ "use strict";
4715
+ }
4716
+ });
4717
+
4205
4718
  // src/lib/store.ts
4206
4719
  var store_exports = {};
4207
4720
  __export(store_exports, {
@@ -4545,6 +5058,11 @@ async function flushBatch() {
4545
5058
  await insertMemoryCardsForBatch2(batch);
4546
5059
  } catch {
4547
5060
  }
5061
+ try {
5062
+ const { insertOntologyForBatch: insertOntologyForBatch2 } = await Promise.resolve().then(() => (init_agentic_ontology(), agentic_ontology_exports));
5063
+ await insertOntologyForBatch2(batch);
5064
+ } catch {
5065
+ }
4548
5066
  schedulePostWriteMemoryHygiene(batch.map((row) => row.id));
4549
5067
  _pendingRecords.splice(0, batch.length);
4550
5068
  try {
@@ -5163,7 +5681,7 @@ __export(file_grep_exports, {
5163
5681
  grepProjectFiles: () => grepProjectFiles
5164
5682
  });
5165
5683
  import { execSync as execSync4 } from "child_process";
5166
- import { readFileSync as readFileSync5, readdirSync as readdirSync2, statSync as statSync3, existsSync as existsSync9 } from "fs";
5684
+ import { readFileSync as readFileSync5, readdirSync as readdirSync2, statSync as statSync4, existsSync as existsSync9 } from "fs";
5167
5685
  import path10 from "path";
5168
5686
  import crypto2 from "crypto";
5169
5687
  function hasRipgrep() {
@@ -5280,7 +5798,7 @@ function grepWithNodeFs(pattern, projectRoot, patterns) {
5280
5798
  for (const filePath of files.slice(0, MAX_FILES)) {
5281
5799
  const absPath = path10.join(projectRoot, filePath);
5282
5800
  try {
5283
- const stat = statSync3(absPath);
5801
+ const stat = statSync4(absPath);
5284
5802
  if (stat.size > MAX_FILE_SIZE) continue;
5285
5803
  const content = readFileSync5(absPath, "utf8");
5286
5804
  const lines = content.split("\n");