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