@askexenow/exe-os 0.9.66 → 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 (99) 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} +1523 -2275
  6. package/dist/bin/backfill-conversations.js +506 -20
  7. package/dist/bin/backfill-responses.js +506 -20
  8. package/dist/bin/backfill-vectors.js +233 -20
  9. package/dist/bin/bulk-sync-postgres.js +4876 -0
  10. package/dist/bin/cleanup-stale-review-tasks.js +507 -21
  11. package/dist/bin/cli.js +2450 -1530
  12. package/dist/bin/exe-assign.js +506 -20
  13. package/dist/bin/exe-boot.js +410 -60
  14. package/dist/bin/exe-cloud.js +795 -105
  15. package/dist/bin/exe-dispatch.js +516 -22
  16. package/dist/bin/exe-doctor.js +587 -30
  17. package/dist/bin/exe-export-behaviors.js +518 -24
  18. package/dist/bin/exe-forget.js +507 -21
  19. package/dist/bin/exe-gateway.js +571 -25
  20. package/dist/bin/exe-heartbeat.js +518 -24
  21. package/dist/bin/exe-kill.js +507 -21
  22. package/dist/bin/exe-launch-agent.js +2312 -1069
  23. package/dist/bin/exe-new-employee.js +197 -165
  24. package/dist/bin/exe-pending-messages.js +507 -21
  25. package/dist/bin/exe-pending-notifications.js +507 -21
  26. package/dist/bin/exe-pending-reviews.js +507 -21
  27. package/dist/bin/exe-rename.js +507 -21
  28. package/dist/bin/exe-review.js +507 -21
  29. package/dist/bin/exe-search.js +518 -24
  30. package/dist/bin/exe-session-cleanup.js +516 -22
  31. package/dist/bin/exe-settings.js +4 -0
  32. package/dist/bin/exe-start-codex.js +682 -143
  33. package/dist/bin/exe-start-opencode.js +627 -79
  34. package/dist/bin/exe-status.js +507 -21
  35. package/dist/bin/exe-team.js +507 -21
  36. package/dist/bin/git-sweep.js +516 -22
  37. package/dist/bin/graph-backfill.js +558 -21
  38. package/dist/bin/graph-export.js +507 -21
  39. package/dist/bin/graph-layer-benchmark.js +109 -0
  40. package/dist/bin/install.js +305 -288
  41. package/dist/bin/intercom-check.js +516 -22
  42. package/dist/bin/postgres-agentic-reflection-backfill.js +187 -0
  43. package/dist/bin/postgres-agentic-semantic-backfill.js +237 -0
  44. package/dist/bin/scan-tasks.js +516 -22
  45. package/dist/bin/setup.js +412 -62
  46. package/dist/bin/shard-migrate.js +506 -20
  47. package/dist/gateway/index.js +569 -23
  48. package/dist/hooks/bug-report-worker.js +519 -25
  49. package/dist/hooks/codex-stop-task-finalizer.js +516 -22
  50. package/dist/hooks/commit-complete.js +516 -22
  51. package/dist/hooks/error-recall.js +518 -24
  52. package/dist/hooks/ingest.js +516 -22
  53. package/dist/hooks/instructions-loaded.js +507 -21
  54. package/dist/hooks/notification.js +507 -21
  55. package/dist/hooks/post-compact.js +507 -21
  56. package/dist/hooks/post-tool-combined.js +519 -25
  57. package/dist/hooks/pre-compact.js +516 -22
  58. package/dist/hooks/pre-tool-use.js +507 -21
  59. package/dist/hooks/prompt-submit.js +519 -25
  60. package/dist/hooks/session-end.js +516 -22
  61. package/dist/hooks/session-start.js +520 -26
  62. package/dist/hooks/stop.js +517 -23
  63. package/dist/hooks/subagent-stop.js +507 -21
  64. package/dist/hooks/summary-worker.js +411 -61
  65. package/dist/index.js +569 -23
  66. package/dist/lib/cloud-sync.js +391 -53
  67. package/dist/lib/config.js +13 -1
  68. package/dist/lib/consolidation.js +1 -1
  69. package/dist/lib/database.js +124 -0
  70. package/dist/lib/db.js +124 -0
  71. package/dist/lib/device-registry.js +124 -0
  72. package/dist/lib/embedder.js +13 -1
  73. package/dist/lib/exe-daemon.js +2184 -561
  74. package/dist/lib/hybrid-search.js +518 -24
  75. package/dist/lib/identity.js +3 -0
  76. package/dist/lib/keychain.js +178 -22
  77. package/dist/lib/messaging.js +3 -0
  78. package/dist/lib/reminders.js +3 -0
  79. package/dist/lib/schedules.js +233 -20
  80. package/dist/lib/skill-learning.js +16 -1
  81. package/dist/lib/store.js +506 -20
  82. package/dist/lib/tasks.js +16 -1
  83. package/dist/lib/tmux-routing.js +16 -1
  84. package/dist/lib/token-spend.js +3 -0
  85. package/dist/mcp/server.js +1757 -428
  86. package/dist/mcp/tools/complete-reminder.js +3 -0
  87. package/dist/mcp/tools/create-reminder.js +3 -0
  88. package/dist/mcp/tools/create-task.js +16 -1
  89. package/dist/mcp/tools/deactivate-behavior.js +3 -0
  90. package/dist/mcp/tools/list-reminders.js +3 -0
  91. package/dist/mcp/tools/list-tasks.js +3 -0
  92. package/dist/mcp/tools/send-message.js +3 -0
  93. package/dist/mcp/tools/update-task.js +16 -1
  94. package/dist/runtime/index.js +516 -22
  95. package/dist/tui/App.js +594 -29
  96. package/package.json +8 -5
  97. package/src/commands/exe/cloud.md +6 -10
  98. package/stack.release.json +3 -3
  99. package/src/commands/exe/link.md +0 -18
@@ -550,6 +550,10 @@ async function loadConfig() {
550
550
  if (config2.dbPath.startsWith("~")) {
551
551
  config2.dbPath = config2.dbPath.replace(/^~/, os2.homedir());
552
552
  }
553
+ const envDbPath = path2.join(dir, "memories.db");
554
+ if (process.env.EXE_OS_DIR && config2.dbPath !== envDbPath && !existsSync2(config2.dbPath) && existsSync2(envDbPath)) {
555
+ config2.dbPath = envDbPath;
556
+ }
553
557
  return config2;
554
558
  } catch {
555
559
  return { ...DEFAULT_CONFIG, dbPath: path2.join(dir, "memories.db") };
@@ -570,7 +574,15 @@ function loadConfigSync() {
570
574
  normalizeSessionLifecycle(migratedCfg);
571
575
  normalizeAutoUpdate(migratedCfg);
572
576
  normalizeOrchestration(migratedCfg);
573
- return { ...DEFAULT_CONFIG, dbPath: path2.join(dir, "memories.db"), ...migratedCfg };
577
+ const config2 = { ...DEFAULT_CONFIG, dbPath: path2.join(dir, "memories.db"), ...migratedCfg };
578
+ if (config2.dbPath.startsWith("~")) {
579
+ config2.dbPath = config2.dbPath.replace(/^~/, os2.homedir());
580
+ }
581
+ const envDbPath = path2.join(dir, "memories.db");
582
+ if (process.env.EXE_OS_DIR && config2.dbPath !== envDbPath && !existsSync2(config2.dbPath) && existsSync2(envDbPath)) {
583
+ config2.dbPath = envDbPath;
584
+ }
585
+ return config2;
574
586
  } catch {
575
587
  return { ...DEFAULT_CONFIG, dbPath: path2.join(dir, "memories.db") };
576
588
  }
@@ -2392,6 +2404,9 @@ function getClient() {
2392
2404
  if (_daemonClient && _daemonClient._isDaemonActive()) {
2393
2405
  return _daemonClient;
2394
2406
  }
2407
+ if (!_resilientClient) {
2408
+ return _adapterClient;
2409
+ }
2395
2410
  return _resilientClient;
2396
2411
  }
2397
2412
  async function initDaemonClient() {
@@ -3424,6 +3439,127 @@ async function ensureSchema() {
3424
3439
  VALUES (new.rowid, new.content, new.subject, new.predicate, new.object);
3425
3440
  END;
3426
3441
  `);
3442
+ await client.executeMultiple(`
3443
+ CREATE TABLE IF NOT EXISTS agent_sessions (
3444
+ id TEXT PRIMARY KEY,
3445
+ agent_id TEXT NOT NULL,
3446
+ project_name TEXT,
3447
+ started_at TEXT NOT NULL,
3448
+ last_event_at TEXT NOT NULL,
3449
+ event_count INTEGER NOT NULL DEFAULT 0,
3450
+ properties TEXT DEFAULT '{}'
3451
+ );
3452
+
3453
+ CREATE INDEX IF NOT EXISTS idx_agent_sessions_agent_time
3454
+ ON agent_sessions(agent_id, started_at);
3455
+
3456
+ CREATE TABLE IF NOT EXISTS agent_goals (
3457
+ id TEXT PRIMARY KEY,
3458
+ statement TEXT NOT NULL,
3459
+ owner_agent_id TEXT,
3460
+ project_name TEXT,
3461
+ status TEXT NOT NULL DEFAULT 'open',
3462
+ priority INTEGER NOT NULL DEFAULT 5,
3463
+ success_criteria TEXT,
3464
+ parent_goal_id TEXT,
3465
+ due_at TEXT,
3466
+ achieved_at TEXT,
3467
+ supersedes_id TEXT,
3468
+ created_at TEXT NOT NULL,
3469
+ updated_at TEXT NOT NULL,
3470
+ source_memory_id TEXT
3471
+ );
3472
+
3473
+ CREATE INDEX IF NOT EXISTS idx_agent_goals_project_status
3474
+ ON agent_goals(project_name, status, priority);
3475
+
3476
+ CREATE TABLE IF NOT EXISTS agent_events (
3477
+ id TEXT PRIMARY KEY,
3478
+ event_type TEXT NOT NULL,
3479
+ occurred_at TEXT NOT NULL,
3480
+ sequence_index INTEGER NOT NULL,
3481
+ actor_agent_id TEXT,
3482
+ agent_role TEXT,
3483
+ project_name TEXT,
3484
+ session_id TEXT,
3485
+ task_id TEXT,
3486
+ goal_id TEXT,
3487
+ parent_event_id TEXT,
3488
+ intention TEXT,
3489
+ outcome TEXT,
3490
+ evidence_memory_id TEXT,
3491
+ impact TEXT,
3492
+ payload TEXT DEFAULT '{}',
3493
+ created_at TEXT NOT NULL
3494
+ );
3495
+
3496
+ CREATE INDEX IF NOT EXISTS idx_agent_events_time
3497
+ ON agent_events(occurred_at, sequence_index);
3498
+
3499
+ CREATE INDEX IF NOT EXISTS idx_agent_events_session_seq
3500
+ ON agent_events(session_id, sequence_index);
3501
+
3502
+ CREATE INDEX IF NOT EXISTS idx_agent_events_goal_time
3503
+ ON agent_events(goal_id, occurred_at);
3504
+
3505
+ CREATE INDEX IF NOT EXISTS idx_agent_events_memory
3506
+ ON agent_events(evidence_memory_id);
3507
+
3508
+ CREATE TABLE IF NOT EXISTS agent_goal_links (
3509
+ id TEXT PRIMARY KEY,
3510
+ goal_id TEXT NOT NULL,
3511
+ link_type TEXT NOT NULL,
3512
+ target_id TEXT NOT NULL,
3513
+ target_type TEXT NOT NULL,
3514
+ created_at TEXT NOT NULL
3515
+ );
3516
+
3517
+ CREATE INDEX IF NOT EXISTS idx_agent_goal_links_goal
3518
+ ON agent_goal_links(goal_id, target_type);
3519
+
3520
+ CREATE TABLE IF NOT EXISTS agent_semantic_labels (
3521
+ id TEXT PRIMARY KEY,
3522
+ source_memory_id TEXT NOT NULL,
3523
+ event_id TEXT,
3524
+ labeler TEXT NOT NULL,
3525
+ schema_version INTEGER NOT NULL DEFAULT 1,
3526
+ confidence REAL NOT NULL DEFAULT 0,
3527
+ labels TEXT NOT NULL,
3528
+ created_at TEXT NOT NULL,
3529
+ updated_at TEXT NOT NULL
3530
+ );
3531
+
3532
+ CREATE INDEX IF NOT EXISTS idx_agent_semantic_labels_memory
3533
+ ON agent_semantic_labels(source_memory_id, labeler);
3534
+
3535
+ CREATE INDEX IF NOT EXISTS idx_agent_semantic_labels_event
3536
+ ON agent_semantic_labels(event_id);
3537
+
3538
+ CREATE TABLE IF NOT EXISTS agent_reflection_checkpoints (
3539
+ id TEXT PRIMARY KEY,
3540
+ project_name TEXT,
3541
+ session_id TEXT,
3542
+ window_start_at TEXT NOT NULL,
3543
+ window_end_at TEXT NOT NULL,
3544
+ event_count INTEGER NOT NULL DEFAULT 0,
3545
+ goal_count INTEGER NOT NULL DEFAULT 0,
3546
+ success_count INTEGER NOT NULL DEFAULT 0,
3547
+ failure_count INTEGER NOT NULL DEFAULT 0,
3548
+ risk_count INTEGER NOT NULL DEFAULT 0,
3549
+ summary TEXT NOT NULL,
3550
+ learnings TEXT NOT NULL DEFAULT '[]',
3551
+ next_actions TEXT NOT NULL DEFAULT '[]',
3552
+ evidence_event_ids TEXT NOT NULL DEFAULT '[]',
3553
+ confidence REAL NOT NULL DEFAULT 0,
3554
+ created_at TEXT NOT NULL
3555
+ );
3556
+
3557
+ CREATE INDEX IF NOT EXISTS idx_agent_reflection_project_time
3558
+ ON agent_reflection_checkpoints(project_name, window_end_at);
3559
+
3560
+ CREATE INDEX IF NOT EXISTS idx_agent_reflection_session_time
3561
+ ON agent_reflection_checkpoints(session_id, window_end_at);
3562
+ `);
3427
3563
  try {
3428
3564
  await client.execute({
3429
3565
  sql: `ALTER TABLE memories ADD COLUMN tier INTEGER DEFAULT 3`,
@@ -3641,7 +3777,7 @@ var init_embedder = __esm({
3641
3777
 
3642
3778
  // src/lib/keychain.ts
3643
3779
  import { readFile as readFile3, writeFile as writeFile3, unlink, mkdir as mkdir3, chmod as chmod2 } from "fs/promises";
3644
- import { existsSync as existsSync7 } from "fs";
3780
+ import { existsSync as existsSync7, statSync as statSync2 } from "fs";
3645
3781
  import { execSync as execSync2 } from "child_process";
3646
3782
  import path8 from "path";
3647
3783
  import os6 from "os";
@@ -3651,29 +3787,78 @@ function getKeyDir() {
3651
3787
  function getKeyPath() {
3652
3788
  return path8.join(getKeyDir(), "master.key");
3653
3789
  }
3654
- function macKeychainGet() {
3790
+ function nativeKeychainAllowed() {
3791
+ return process.env.EXE_OS_DISABLE_NATIVE_KEYCHAIN !== "1";
3792
+ }
3793
+ function linuxSecretAvailable() {
3794
+ if (!nativeKeychainAllowed()) return false;
3795
+ if (process.platform !== "linux") return false;
3796
+ if (linuxSecretAvailability !== null) return linuxSecretAvailability;
3797
+ try {
3798
+ execSync2("command -v secret-tool >/dev/null 2>&1", { timeout: 1e3 });
3799
+ } catch {
3800
+ linuxSecretAvailability = false;
3801
+ return false;
3802
+ }
3803
+ try {
3804
+ execSync2("secret-tool search --all exe-os probe >/dev/null 2>&1", { timeout: 1e3 });
3805
+ linuxSecretAvailability = true;
3806
+ } catch {
3807
+ linuxSecretAvailability = false;
3808
+ }
3809
+ return linuxSecretAvailability;
3810
+ }
3811
+ function isRootOnlyTrustedServerKeyFile(keyPath) {
3812
+ if (process.platform !== "linux") return false;
3813
+ try {
3814
+ const uid = typeof os6.userInfo().uid === "number" ? os6.userInfo().uid : -1;
3815
+ const st = statSync2(keyPath);
3816
+ if (!st.isFile() || (st.mode & 63) !== 0) return false;
3817
+ if (uid === 0) return true;
3818
+ const exeOsDir = process.env.EXE_OS_DIR;
3819
+ return Boolean(exeOsDir && path8.resolve(keyPath).startsWith(path8.resolve(exeOsDir) + path8.sep));
3820
+ } catch {
3821
+ return false;
3822
+ }
3823
+ }
3824
+ function macKeychainGet(service = SERVICE) {
3825
+ if (!nativeKeychainAllowed()) return null;
3655
3826
  if (process.platform !== "darwin") return null;
3656
3827
  try {
3657
3828
  return execSync2(
3658
- `security find-generic-password -s "${SERVICE}" -a "${ACCOUNT}" -w 2>/dev/null`,
3829
+ `security find-generic-password -s "${service}" -a "${ACCOUNT}" -w 2>/dev/null`,
3659
3830
  { encoding: "utf-8", timeout: 5e3 }
3660
3831
  ).trim();
3661
3832
  } catch {
3662
3833
  return null;
3663
3834
  }
3664
3835
  }
3665
- function macKeychainSet(value) {
3836
+ function macKeychainSet(value, service = SERVICE) {
3837
+ if (!nativeKeychainAllowed()) return false;
3666
3838
  if (process.platform !== "darwin") return false;
3667
3839
  try {
3668
3840
  try {
3669
3841
  execSync2(
3670
- `security delete-generic-password -s "${SERVICE}" -a "${ACCOUNT}" 2>/dev/null`,
3842
+ `security delete-generic-password -s "${service}" -a "${ACCOUNT}" 2>/dev/null`,
3671
3843
  { timeout: 5e3 }
3672
3844
  );
3673
3845
  } catch {
3674
3846
  }
3675
3847
  execSync2(
3676
- `security add-generic-password -s "${SERVICE}" -a "${ACCOUNT}" -w "${value}"`,
3848
+ `security add-generic-password -s "${service}" -a "${ACCOUNT}" -w "${value}"`,
3849
+ { timeout: 5e3 }
3850
+ );
3851
+ return true;
3852
+ } catch {
3853
+ return false;
3854
+ }
3855
+ }
3856
+ function macKeychainDelete(service = SERVICE) {
3857
+ if (!nativeKeychainAllowed()) return false;
3858
+ if (process.platform !== "darwin") return false;
3859
+ try {
3860
+ execSync2(
3861
+ `security delete-generic-password -s "${service}" -a "${ACCOUNT}" 2>/dev/null`,
3677
3862
  { timeout: 5e3 }
3678
3863
  );
3679
3864
  return true;
@@ -3681,22 +3866,35 @@ function macKeychainSet(value) {
3681
3866
  return false;
3682
3867
  }
3683
3868
  }
3684
- function linuxSecretGet() {
3685
- if (process.platform !== "linux") return null;
3869
+ function linuxSecretGet(service = SERVICE) {
3870
+ if (!linuxSecretAvailable()) return null;
3686
3871
  try {
3687
3872
  return execSync2(
3688
- `secret-tool lookup service "${SERVICE}" account "${ACCOUNT}" 2>/dev/null`,
3873
+ `secret-tool lookup service "${service}" account "${ACCOUNT}" 2>/dev/null`,
3689
3874
  { encoding: "utf-8", timeout: 5e3 }
3690
3875
  ).trim();
3691
3876
  } catch {
3692
3877
  return null;
3693
3878
  }
3694
3879
  }
3695
- function linuxSecretSet(value) {
3880
+ function linuxSecretSet(value, service = SERVICE) {
3881
+ if (!linuxSecretAvailable()) return false;
3882
+ try {
3883
+ execSync2(
3884
+ `echo -n "${value}" | secret-tool store --label="exe-os master key" service "${service}" account "${ACCOUNT}" 2>/dev/null`,
3885
+ { timeout: 5e3 }
3886
+ );
3887
+ return true;
3888
+ } catch {
3889
+ return false;
3890
+ }
3891
+ }
3892
+ function linuxSecretDelete(service = SERVICE) {
3893
+ if (!nativeKeychainAllowed()) return false;
3696
3894
  if (process.platform !== "linux") return false;
3697
3895
  try {
3698
3896
  execSync2(
3699
- `echo -n "${value}" | secret-tool store --label="exe-os master key" service "${SERVICE}" account "${ACCOUNT}"`,
3897
+ `secret-tool clear service "${service}" account "${ACCOUNT}" 2>/dev/null`,
3700
3898
  { timeout: 5e3 }
3701
3899
  );
3702
3900
  return true;
@@ -3705,6 +3903,7 @@ function linuxSecretSet(value) {
3705
3903
  }
3706
3904
  }
3707
3905
  async function tryKeytar() {
3906
+ if (!nativeKeychainAllowed()) return null;
3708
3907
  try {
3709
3908
  return await import("keytar");
3710
3909
  } catch {
@@ -3778,7 +3977,19 @@ async function writeMachineBoundFileFallback(b64) {
3778
3977
  return "plaintext";
3779
3978
  }
3780
3979
  async function getMasterKey() {
3781
- const nativeValue = macKeychainGet() ?? linuxSecretGet();
3980
+ let nativeValue = macKeychainGet() ?? linuxSecretGet();
3981
+ if (!nativeValue) {
3982
+ const legacyValue = macKeychainGet(LEGACY_SERVICE) ?? linuxSecretGet(LEGACY_SERVICE);
3983
+ if (legacyValue) {
3984
+ const migrated = macKeychainSet(legacyValue) || linuxSecretSet(legacyValue);
3985
+ if (migrated) {
3986
+ macKeychainDelete(LEGACY_SERVICE);
3987
+ linuxSecretDelete(LEGACY_SERVICE);
3988
+ process.stderr.write("[keychain] Migrated keychain service from exe-mem to exe-os.\n");
3989
+ }
3990
+ nativeValue = legacyValue;
3991
+ }
3992
+ }
3782
3993
  if (nativeValue) {
3783
3994
  return Buffer.from(nativeValue, "base64");
3784
3995
  }
@@ -3786,12 +3997,17 @@ async function getMasterKey() {
3786
3997
  if (keytar) {
3787
3998
  try {
3788
3999
  const keytarValue = await keytar.getPassword(SERVICE, ACCOUNT);
3789
- if (keytarValue) {
3790
- const migrated = macKeychainSet(keytarValue) || linuxSecretSet(keytarValue);
4000
+ const legacyKeytarValue = keytarValue ?? await keytar.getPassword(LEGACY_SERVICE, ACCOUNT);
4001
+ if (legacyKeytarValue) {
4002
+ const migrated = macKeychainSet(legacyKeytarValue) || linuxSecretSet(legacyKeytarValue);
3791
4003
  if (migrated) {
3792
4004
  process.stderr.write("[keychain] Migrated key from keytar to native keychain.\n");
4005
+ try {
4006
+ await keytar.deletePassword(LEGACY_SERVICE, ACCOUNT);
4007
+ } catch {
4008
+ }
3793
4009
  }
3794
- return Buffer.from(keytarValue, "base64");
4010
+ return Buffer.from(legacyKeytarValue, "base64");
3795
4011
  }
3796
4012
  } catch {
3797
4013
  }
@@ -3816,7 +4032,7 @@ async function getMasterKey() {
3816
4032
  const decrypted = decryptWithMachineKey(content, machineKey);
3817
4033
  if (!decrypted) {
3818
4034
  process.stderr.write(
3819
- "[keychain] Key decryption failed \u2014 machine may have changed.\n Use your 24-word recovery phrase: exe-os link import\n"
4035
+ "[keychain] Key decryption failed \u2014 machine may have changed.\n Use your 24-word recovery phrase during setup: exe-os setup\n"
3820
4036
  );
3821
4037
  return null;
3822
4038
  }
@@ -3825,6 +4041,9 @@ async function getMasterKey() {
3825
4041
  b64Value = content;
3826
4042
  }
3827
4043
  const key = Buffer.from(b64Value, "base64");
4044
+ if (!content.startsWith(ENCRYPTED_PREFIX) && isRootOnlyTrustedServerKeyFile(keyPath)) {
4045
+ return key;
4046
+ }
3828
4047
  const migrated = macKeychainSet(b64Value) || linuxSecretSet(b64Value);
3829
4048
  if (migrated) {
3830
4049
  process.stderr.write("[keychain] Migrated key from file to native keychain.\n");
@@ -3852,12 +4071,14 @@ async function getMasterKey() {
3852
4071
  return null;
3853
4072
  }
3854
4073
  }
3855
- var SERVICE, ACCOUNT, ENCRYPTED_PREFIX;
4074
+ var SERVICE, LEGACY_SERVICE, ACCOUNT, linuxSecretAvailability, ENCRYPTED_PREFIX;
3856
4075
  var init_keychain = __esm({
3857
4076
  "src/lib/keychain.ts"() {
3858
4077
  "use strict";
3859
- SERVICE = "exe-mem";
4078
+ SERVICE = "exe-os";
4079
+ LEGACY_SERVICE = "exe-mem";
3860
4080
  ACCOUNT = "master-key";
4081
+ linuxSecretAvailability = null;
3861
4082
  ENCRYPTED_PREFIX = "enc:";
3862
4083
  }
3863
4084
  });
@@ -4072,7 +4293,7 @@ __export(shard_manager_exports, {
4072
4293
  shardExists: () => shardExists
4073
4294
  });
4074
4295
  import path9 from "path";
4075
- import { existsSync as existsSync8, mkdirSync as mkdirSync2, readdirSync, renameSync as renameSync3, statSync as statSync2 } from "fs";
4296
+ import { existsSync as existsSync8, mkdirSync as mkdirSync2, readdirSync, renameSync as renameSync3, statSync as statSync3 } from "fs";
4076
4297
  import { createClient as createClient2 } from "@libsql/client";
4077
4298
  function initShardManager(encryptionKey) {
4078
4299
  _encryptionKey = encryptionKey;
@@ -4136,7 +4357,7 @@ async function auditShardHealth(options = {}) {
4136
4357
  const shards = [];
4137
4358
  for (const name of names) {
4138
4359
  const dbPath = path9.join(SHARDS_DIR, `${name}.db`);
4139
- const stat = statSync2(dbPath);
4360
+ const stat = statSync3(dbPath);
4140
4361
  const item = {
4141
4362
  name,
4142
4363
  path: dbPath,
@@ -4389,7 +4610,7 @@ async function getReadyShardClient(projectName) {
4389
4610
  _shardLastAccess.delete(safeName);
4390
4611
  const dbPath = path9.join(SHARDS_DIR, `${safeName}.db`);
4391
4612
  if (existsSync8(dbPath)) {
4392
- const stat = statSync2(dbPath);
4613
+ const stat = statSync3(dbPath);
4393
4614
  const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
4394
4615
  const archivedPath = path9.join(SHARDS_DIR, `${safeName}.db.broken-${stamp}`);
4395
4616
  renameSync3(dbPath, archivedPath);
@@ -4896,6 +5117,274 @@ var init_memory_cards = __esm({
4896
5117
  }
4897
5118
  });
4898
5119
 
5120
+ // src/lib/agentic-ontology.ts
5121
+ var agentic_ontology_exports = {};
5122
+ __export(agentic_ontology_exports, {
5123
+ clean: () => clean,
5124
+ extractGoalCandidates: () => extractGoalCandidates,
5125
+ inferIntention: () => inferIntention,
5126
+ inferOntologyEventType: () => inferOntologyEventType,
5127
+ inferOutcome: () => inferOutcome,
5128
+ inferSemanticLabel: () => inferSemanticLabel,
5129
+ insertOntologyForBatch: () => insertOntologyForBatch,
5130
+ insertOntologyForMemory: () => insertOntologyForMemory,
5131
+ ontologyPayload: () => ontologyPayload,
5132
+ stableId: () => stableId2
5133
+ });
5134
+ import { createHash as createHash3 } from "crypto";
5135
+ function stableId2(...parts) {
5136
+ return createHash3("sha256").update(parts.map((p) => String(p ?? "")).join("::")).digest("hex").slice(0, 32);
5137
+ }
5138
+ function clean(text, max = 240) {
5139
+ return text.replace(/\u0000/g, "").replace(/```[\s\S]*?```/g, " ").replace(/\s+/g, " ").trim().slice(0, max);
5140
+ }
5141
+ function inferOntologyEventType(row) {
5142
+ const lower = row.raw_text.toLowerCase();
5143
+ if (row.has_error) return "error";
5144
+ if (/\b(done|complete|completed|fixed|resolved|shipped|deployed|pushed|published)\b/.test(lower)) return "milestone";
5145
+ if (/\b(blocked|failed|error|bug|regression|broken)\b/.test(lower)) return "problem";
5146
+ if (/\b(decided|decision|adr|we chose|approved|rejected)\b/.test(lower)) return "decision";
5147
+ if (/\b(goal|need to|we need|want to|trying to|objective)\b/.test(lower)) return "goal_signal";
5148
+ if (["Bash", "Read", "Edit", "Write", "Grep", "Glob"].includes(row.tool_name)) return "tool_action";
5149
+ if (row.tool_name.startsWith("memory_card")) return "memory_card";
5150
+ return "memory_observation";
5151
+ }
5152
+ function inferIntention(row) {
5153
+ if (row.intent) return clean(row.intent, 220);
5154
+ const text = clean(row.raw_text, 1e3);
5155
+ const patterns = [
5156
+ /(?: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,
5157
+ /(?:so that|in order to)\s+([^.!?\n]{8,220})/i,
5158
+ /(?:task|plan):\s*([^.!?\n]{8,220})/i
5159
+ ];
5160
+ for (const p of patterns) {
5161
+ const m = text.match(p);
5162
+ if (m?.[1]) return clean(m[1], 220);
5163
+ }
5164
+ if (["Bash", "Read", "Edit", "Write", "Grep", "Glob"].includes(row.tool_name)) {
5165
+ return `${row.tool_name} during ${row.project_name}`;
5166
+ }
5167
+ return null;
5168
+ }
5169
+ function inferOutcome(row) {
5170
+ if (row.outcome) return clean(row.outcome, 220);
5171
+ if (row.has_error) return "error";
5172
+ const lower = row.raw_text.toLowerCase();
5173
+ if (/\b(done|complete|completed|fixed|resolved|shipped|deployed|pushed|published|passed)\b/.test(lower)) return "success_signal";
5174
+ if (/\b(blocked|failed|error|regression|broken|not working|could not)\b/.test(lower)) return "failure_signal";
5175
+ if (/\b(warning|risk|concern|caveat)\b/.test(lower)) return "risk_signal";
5176
+ return null;
5177
+ }
5178
+ function extractGoalCandidates(row) {
5179
+ const text = clean(row.raw_text, 1600);
5180
+ const patterns = [
5181
+ /(?: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,
5182
+ /(?:success means|success criteria|so that)\s+([^.!?\n]{12,220})/gi
5183
+ ];
5184
+ const out = [];
5185
+ for (const pattern of patterns) {
5186
+ for (const m of text.matchAll(pattern)) {
5187
+ const candidate = clean(m[1] ?? "", 220);
5188
+ if (candidate.length >= 12 && !out.some((x) => x.toLowerCase() === candidate.toLowerCase())) out.push(candidate);
5189
+ if (out.length >= 3) return out;
5190
+ }
5191
+ }
5192
+ return out;
5193
+ }
5194
+ function uniq(values, max = 6) {
5195
+ const out = [];
5196
+ for (const value of values.map((v) => clean(v, 220)).filter(Boolean)) {
5197
+ if (!out.some((x) => x.toLowerCase() === value.toLowerCase())) out.push(value);
5198
+ if (out.length >= max) break;
5199
+ }
5200
+ return out;
5201
+ }
5202
+ function extractMatches(text, patterns, max = 5) {
5203
+ const out = [];
5204
+ for (const pattern of patterns) {
5205
+ for (const match of text.matchAll(pattern)) {
5206
+ const value = match[1] ?? match[0];
5207
+ if (value) out.push(value);
5208
+ if (out.length >= max) return uniq(out, max);
5209
+ }
5210
+ }
5211
+ return uniq(out, max);
5212
+ }
5213
+ function inferSemanticLabel(row) {
5214
+ const text = clean(row.raw_text, 2400);
5215
+ const eventType = inferOntologyEventType(row);
5216
+ const intention = inferIntention(row);
5217
+ const outcome = inferOutcome(row);
5218
+ const goals = extractGoalCandidates(row);
5219
+ const milestones = extractMatches(text, [
5220
+ /\b(?:completed|finished|fixed|resolved|shipped|deployed|published|pushed|passed)\b([^.!?\n]{0,180})/gi,
5221
+ /(?:milestone|done):\s*([^.!?\n]{8,220})/gi
5222
+ ]);
5223
+ const problems = extractMatches(text, [
5224
+ /\b(?:blocked by|failed because|bug|regression|broken|not working|error)\b([^.!?\n]{0,180})/gi,
5225
+ /(?:problem|issue|risk):\s*([^.!?\n]{8,220})/gi
5226
+ ]);
5227
+ const decisions = extractMatches(text, [
5228
+ /(?:decided|decision|adr|we chose|approved|rejected)\s+([^.!?\n]{8,220})/gi
5229
+ ]);
5230
+ const temporalAnchors = extractMatches(text, [
5231
+ /\b(\d{4}-\d{2}-\d{2}(?:[T ][0-9:.+-Z]+)?)\b/g,
5232
+ /\b(today|yesterday|tomorrow|this week|next week|last week|morning|afternoon|tonight)\b/gi
5233
+ ], 8);
5234
+ const nextActions = extractMatches(text, [
5235
+ /(?:next|todo|follow[- ]?up|remaining|need to)\s*:?\s*([^.!?\n]{8,220})/gi
5236
+ ]);
5237
+ const actors = uniq([
5238
+ row.agent_id,
5239
+ ...extractMatches(text, [/\b(?:agent|employee|owner|assignee)[:= ]+([a-zA-Z][a-zA-Z0-9_-]{1,40})/gi], 5)
5240
+ ], 6);
5241
+ const successSignals = milestones.length ? milestones : outcome === "success_signal" ? [clean(text, 180)] : [];
5242
+ const failureSignals = problems.length ? problems : outcome === "failure_signal" || row.has_error ? [clean(text, 180)] : [];
5243
+ const impact = successSignals.length && failureSignals.length ? "mixed" : failureSignals.length ? "negative" : successSignals.length ? "positive" : "neutral";
5244
+ const signalCount = goals.length + milestones.length + problems.length + decisions.length + nextActions.length;
5245
+ return {
5246
+ labeler: "deterministic",
5247
+ schemaVersion: 1,
5248
+ eventType,
5249
+ intention,
5250
+ outcome,
5251
+ impact,
5252
+ confidence: Math.min(0.95, 0.45 + signalCount * 0.08 + (intention ? 0.1 : 0) + (outcome ? 0.1 : 0)),
5253
+ goals,
5254
+ milestones,
5255
+ problems,
5256
+ decisions,
5257
+ actors,
5258
+ temporalAnchors,
5259
+ successSignals,
5260
+ failureSignals,
5261
+ nextActions,
5262
+ summary: clean(text, 280)
5263
+ };
5264
+ }
5265
+ function ontologyPayload(row) {
5266
+ const semantic = inferSemanticLabel(row);
5267
+ return {
5268
+ tool_name: row.tool_name,
5269
+ memory_version: row.version ?? null,
5270
+ domain: row.domain ?? null,
5271
+ trajectory: row.trajectory ? safeJson(row.trajectory) : null,
5272
+ semantic
5273
+ };
5274
+ }
5275
+ function safeJson(value) {
5276
+ try {
5277
+ return JSON.parse(value);
5278
+ } catch {
5279
+ return value.slice(0, 1e3);
5280
+ }
5281
+ }
5282
+ async function resolveClient(client) {
5283
+ if (client) return client;
5284
+ const { getClient: getClient2 } = await Promise.resolve().then(() => (init_database(), database_exports));
5285
+ return getClient2();
5286
+ }
5287
+ async function insertOntologyForMemory(row, client) {
5288
+ const db = await resolveClient(client);
5289
+ const occurredAt = row.timestamp;
5290
+ const sequence = Number(row.version ?? 0) || Math.floor(new Date(occurredAt).getTime() / 1e3);
5291
+ const eventType = inferOntologyEventType(row);
5292
+ const intention = inferIntention(row);
5293
+ const outcome = inferOutcome(row);
5294
+ const eventId = stableId2("event", row.id);
5295
+ const now = (/* @__PURE__ */ new Date()).toISOString();
5296
+ await db.execute({
5297
+ sql: `INSERT INTO agent_sessions (id, agent_id, project_name, started_at, last_event_at, event_count, properties)
5298
+ VALUES (?, ?, ?, ?, ?, 1, ?)
5299
+ ON CONFLICT(id) DO UPDATE SET last_event_at = MAX(last_event_at, excluded.last_event_at),
5300
+ event_count = event_count + 1`,
5301
+ args: [row.session_id, row.agent_id, row.project_name, occurredAt, occurredAt, JSON.stringify({ agent_role: row.agent_role })]
5302
+ });
5303
+ await db.execute({
5304
+ sql: `INSERT OR IGNORE INTO agent_events
5305
+ (id, event_type, occurred_at, sequence_index, actor_agent_id, agent_role, project_name,
5306
+ session_id, task_id, goal_id, parent_event_id, intention, outcome, evidence_memory_id,
5307
+ impact, payload, created_at)
5308
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NULL, NULL, ?, ?, ?, ?, ?, ?)`,
5309
+ args: [
5310
+ eventId,
5311
+ eventType,
5312
+ occurredAt,
5313
+ sequence,
5314
+ row.agent_id,
5315
+ row.agent_role,
5316
+ row.project_name,
5317
+ row.session_id,
5318
+ row.task_id ?? null,
5319
+ intention,
5320
+ outcome,
5321
+ row.id,
5322
+ row.has_error ? "negative" : outcome === "success_signal" ? "positive" : "neutral",
5323
+ JSON.stringify(ontologyPayload(row)),
5324
+ now
5325
+ ]
5326
+ });
5327
+ const semantic = inferSemanticLabel(row);
5328
+ await db.execute({
5329
+ sql: `INSERT INTO agent_semantic_labels
5330
+ (id, source_memory_id, event_id, labeler, schema_version, confidence, labels, created_at, updated_at)
5331
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
5332
+ ON CONFLICT(id) DO UPDATE SET confidence = excluded.confidence,
5333
+ labels = excluded.labels, updated_at = excluded.updated_at`,
5334
+ args: [
5335
+ stableId2("semantic", row.id, semantic.labeler, semantic.schemaVersion),
5336
+ row.id,
5337
+ eventId,
5338
+ semantic.labeler,
5339
+ semantic.schemaVersion,
5340
+ semantic.confidence,
5341
+ JSON.stringify(semantic),
5342
+ now,
5343
+ now
5344
+ ]
5345
+ });
5346
+ for (const statement of extractGoalCandidates(row)) {
5347
+ const goalId = stableId2("goal", row.project_name, statement.toLowerCase());
5348
+ await db.execute({
5349
+ sql: `INSERT INTO agent_goals
5350
+ (id, statement, owner_agent_id, project_name, status, priority, success_criteria,
5351
+ parent_goal_id, due_at, achieved_at, supersedes_id, created_at, updated_at, source_memory_id)
5352
+ VALUES (?, ?, ?, ?, 'open', 5, NULL, NULL, NULL, NULL, NULL, ?, ?, ?)
5353
+ ON CONFLICT(id) DO UPDATE SET updated_at = excluded.updated_at`,
5354
+ args: [goalId, statement, row.agent_id, row.project_name, now, now, row.id]
5355
+ });
5356
+ await db.execute({
5357
+ sql: `INSERT OR IGNORE INTO agent_goal_links
5358
+ (id, goal_id, link_type, target_id, target_type, created_at)
5359
+ VALUES (?, ?, 'evidence', ?, 'memory', ?)`,
5360
+ args: [stableId2("goal_link", goalId, row.id, "memory"), goalId, row.id, now]
5361
+ });
5362
+ await db.execute({
5363
+ sql: `INSERT OR IGNORE INTO agent_goal_links
5364
+ (id, goal_id, link_type, target_id, target_type, created_at)
5365
+ VALUES (?, ?, 'event', ?, 'event', ?)`,
5366
+ args: [stableId2("goal_link", goalId, eventId, "event"), goalId, eventId, now]
5367
+ });
5368
+ }
5369
+ }
5370
+ async function insertOntologyForBatch(rows, client) {
5371
+ const db = await resolveClient(client);
5372
+ let count = 0;
5373
+ for (const row of rows) {
5374
+ try {
5375
+ await insertOntologyForMemory(row, db);
5376
+ count++;
5377
+ } catch {
5378
+ }
5379
+ }
5380
+ return count;
5381
+ }
5382
+ var init_agentic_ontology = __esm({
5383
+ "src/lib/agentic-ontology.ts"() {
5384
+ "use strict";
5385
+ }
5386
+ });
5387
+
4899
5388
  // src/lib/store.ts
4900
5389
  var store_exports = {};
4901
5390
  __export(store_exports, {
@@ -5239,6 +5728,11 @@ async function flushBatch() {
5239
5728
  await insertMemoryCardsForBatch2(batch);
5240
5729
  } catch {
5241
5730
  }
5731
+ try {
5732
+ const { insertOntologyForBatch: insertOntologyForBatch2 } = await Promise.resolve().then(() => (init_agentic_ontology(), agentic_ontology_exports));
5733
+ await insertOntologyForBatch2(batch);
5734
+ } catch {
5735
+ }
5242
5736
  schedulePostWriteMemoryHygiene(batch.map((row) => row.id));
5243
5737
  _pendingRecords.splice(0, batch.length);
5244
5738
  try {
@@ -5844,6 +6338,7 @@ __export(graph_rag_exports, {
5844
6338
  extractBatch: () => extractBatch,
5845
6339
  extractFromCode: () => extractFromCode,
5846
6340
  extractFromMemory: () => extractFromMemory,
6341
+ extractHeuristicMemoryGraph: () => extractHeuristicMemoryGraph,
5847
6342
  mergeEntities: () => mergeEntities,
5848
6343
  normalizeEntityName: () => normalizeEntityName,
5849
6344
  registerAlias: () => registerAlias,
@@ -5999,6 +6494,57 @@ function extractFromCode(source, filePath) {
5999
6494
  }
6000
6495
  return { entities, relationships, hyperedges: [] };
6001
6496
  }
6497
+ function pushUniqueEntity(entities, seen, name, type) {
6498
+ const normalized = normalizeEntityName(name);
6499
+ if (!normalized || normalized.length < 2) return;
6500
+ const key = `${normalized.toLowerCase()}::${type.toLowerCase()}`;
6501
+ if (seen.has(key)) return;
6502
+ seen.add(key);
6503
+ entities.push({ name: normalized.slice(0, 160), type });
6504
+ }
6505
+ function pushHeuristicRelationship(relationships, source, sourceType, target, targetType, relationship, confidence = 0.6) {
6506
+ if (!source || !target || source === target) return;
6507
+ relationships.push({
6508
+ source,
6509
+ sourceType,
6510
+ target,
6511
+ targetType,
6512
+ relationship,
6513
+ confidence,
6514
+ confidenceLabel: "inferred"
6515
+ });
6516
+ }
6517
+ function extractHeuristicMemoryGraph(content, agentId) {
6518
+ const entities = [];
6519
+ const relationships = [];
6520
+ const seen = /* @__PURE__ */ new Set();
6521
+ pushUniqueEntity(entities, seen, agentId, "person");
6522
+ const toolMatch = content.match(/^(Bash|Read|Edit|Write|Grep|Glob|AssistantResponse|Tool|Ran|Wrote|Edited):/m);
6523
+ if (toolMatch?.[1]) {
6524
+ pushUniqueEntity(entities, seen, toolMatch[1], "tool");
6525
+ pushHeuristicRelationship(relationships, agentId, "person", toolMatch[1], "tool", "uses", 0.75);
6526
+ }
6527
+ const repoMatches = [...content.matchAll(/\/Users\/[^/\s]+\/([A-Za-z0-9_.-]+)|\/opt\/([A-Za-z0-9_.-]+)/g)].map((m) => m[1] ?? m[2]).filter((repo) => Boolean(repo)).slice(0, 6);
6528
+ for (const repo of repoMatches) {
6529
+ pushUniqueEntity(entities, seen, repo, "project");
6530
+ pushHeuristicRelationship(relationships, agentId, "person", repo, "project", "worked_on", 0.7);
6531
+ }
6532
+ const pathMatches = new Set(
6533
+ (content.match(/(?:\/[\w .@-]+)+(?:\.[A-Za-z0-9]{1,10})|(?:[\w@.-]+\/)+[\w@.-]+\.(?:ts|tsx|js|jsx|json|md|yml|yaml|sql|py|go|rs|sh|css|html)/g) ?? []).slice(0, 10)
6534
+ );
6535
+ for (const filePath of pathMatches) {
6536
+ pushUniqueEntity(entities, seen, filePath, "file");
6537
+ pushHeuristicRelationship(relationships, agentId, "person", filePath, "file", "uses", 0.65);
6538
+ }
6539
+ const backtickTerms = [...content.matchAll(/`([^`\n]{2,80})`/g)].map((m) => m[1]).slice(0, 10);
6540
+ for (const term of backtickTerms) {
6541
+ if (!term || term.length < 2) continue;
6542
+ const type = term.includes("/") || /\.[A-Za-z0-9]{1,10}$/.test(term) ? "file" : "concept";
6543
+ pushUniqueEntity(entities, seen, term, type);
6544
+ pushHeuristicRelationship(relationships, agentId, "person", term, type, "uses", 0.55);
6545
+ }
6546
+ return { entities, relationships, hyperedges: [] };
6547
+ }
6002
6548
  async function extractFromMemory(content, agentId, model = "claude-haiku-4-5-20251001", filePath) {
6003
6549
  if (content.length < 50) {
6004
6550
  return { entities: [], relationships: [], hyperedges: [] };
@@ -6054,7 +6600,7 @@ async function extractFromMemory(content, agentId, model = "claude-haiku-4-5-202
6054
6600
  `
6055
6601
  );
6056
6602
  }
6057
- return { entities: [], relationships: [], hyperedges: [] };
6603
+ return extractHeuristicMemoryGraph(content, agentId);
6058
6604
  }
6059
6605
  async function storeExtraction(client, extraction, memoryId, timestamp) {
6060
6606
  let entitiesStored = 0;
@@ -6830,8 +7376,8 @@ async function validateLicense(apiKey, deviceId) {
6830
7376
  }
6831
7377
  function getCacheAgeMs() {
6832
7378
  try {
6833
- const { statSync: statSync3 } = __require("fs");
6834
- const s = statSync3(CACHE_PATH);
7379
+ const { statSync: statSync4 } = __require("fs");
7380
+ const s = statSync4(CACHE_PATH);
6835
7381
  return Date.now() - s.mtimeMs;
6836
7382
  } catch {
6837
7383
  return Infinity;