@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
@@ -515,6 +515,11 @@ function normalizeAutoUpdate(raw) {
515
515
  const userAU = raw.autoUpdate ?? {};
516
516
  raw.autoUpdate = { ...defaultAU, ...userAU };
517
517
  }
518
+ function normalizeOrchestration(raw) {
519
+ const defaultOrg = DEFAULT_CONFIG.orchestration;
520
+ const userOrg = raw.orchestration ?? {};
521
+ raw.orchestration = { ...defaultOrg, ...userOrg };
522
+ }
518
523
  async function loadConfig() {
519
524
  const dir = process.env.EXE_OS_DIR ?? process.env.EXE_MEM_DIR ?? EXE_AI_DIR;
520
525
  await ensurePrivateDir(dir);
@@ -539,10 +544,15 @@ async function loadConfig() {
539
544
  normalizeScalingRoadmap(migratedCfg);
540
545
  normalizeSessionLifecycle(migratedCfg);
541
546
  normalizeAutoUpdate(migratedCfg);
547
+ normalizeOrchestration(migratedCfg);
542
548
  const config2 = { ...DEFAULT_CONFIG, dbPath: path.join(dir, "memories.db"), ...migratedCfg };
543
549
  if (config2.dbPath.startsWith("~")) {
544
550
  config2.dbPath = config2.dbPath.replace(/^~/, os.homedir());
545
551
  }
552
+ const envDbPath = path.join(dir, "memories.db");
553
+ if (process.env.EXE_OS_DIR && config2.dbPath !== envDbPath && !existsSync2(config2.dbPath) && existsSync2(envDbPath)) {
554
+ config2.dbPath = envDbPath;
555
+ }
546
556
  return config2;
547
557
  } catch {
548
558
  return { ...DEFAULT_CONFIG, dbPath: path.join(dir, "memories.db") };
@@ -562,7 +572,16 @@ function loadConfigSync() {
562
572
  normalizeScalingRoadmap(migratedCfg);
563
573
  normalizeSessionLifecycle(migratedCfg);
564
574
  normalizeAutoUpdate(migratedCfg);
565
- return { ...DEFAULT_CONFIG, dbPath: path.join(dir, "memories.db"), ...migratedCfg };
575
+ normalizeOrchestration(migratedCfg);
576
+ const config2 = { ...DEFAULT_CONFIG, dbPath: path.join(dir, "memories.db"), ...migratedCfg };
577
+ if (config2.dbPath.startsWith("~")) {
578
+ config2.dbPath = config2.dbPath.replace(/^~/, os.homedir());
579
+ }
580
+ const envDbPath = path.join(dir, "memories.db");
581
+ if (process.env.EXE_OS_DIR && config2.dbPath !== envDbPath && !existsSync2(config2.dbPath) && existsSync2(envDbPath)) {
582
+ config2.dbPath = envDbPath;
583
+ }
584
+ return config2;
566
585
  } catch {
567
586
  return { ...DEFAULT_CONFIG, dbPath: path.join(dir, "memories.db") };
568
587
  }
@@ -583,6 +602,7 @@ async function loadConfigFrom(configPath) {
583
602
  normalizeScalingRoadmap(migratedCfg);
584
603
  normalizeSessionLifecycle(migratedCfg);
585
604
  normalizeAutoUpdate(migratedCfg);
605
+ normalizeOrchestration(migratedCfg);
586
606
  return { ...DEFAULT_CONFIG, ...migratedCfg };
587
607
  } catch {
588
608
  return { ...DEFAULT_CONFIG };
@@ -654,6 +674,10 @@ var init_config = __esm({
654
674
  checkOnBoot: true,
655
675
  autoInstall: false,
656
676
  checkIntervalMs: 24 * 60 * 60 * 1e3
677
+ },
678
+ orchestration: {
679
+ phase: "phase_1_coo",
680
+ phaseSetBy: "default"
657
681
  }
658
682
  };
659
683
  CONFIG_MIGRATIONS = [
@@ -2379,6 +2403,9 @@ function getClient() {
2379
2403
  if (_daemonClient && _daemonClient._isDaemonActive()) {
2380
2404
  return _daemonClient;
2381
2405
  }
2406
+ if (!_resilientClient) {
2407
+ return _adapterClient;
2408
+ }
2382
2409
  return _resilientClient;
2383
2410
  }
2384
2411
  async function initDaemonClient() {
@@ -3411,6 +3438,127 @@ async function ensureSchema() {
3411
3438
  VALUES (new.rowid, new.content, new.subject, new.predicate, new.object);
3412
3439
  END;
3413
3440
  `);
3441
+ await client.executeMultiple(`
3442
+ CREATE TABLE IF NOT EXISTS agent_sessions (
3443
+ id TEXT PRIMARY KEY,
3444
+ agent_id TEXT NOT NULL,
3445
+ project_name TEXT,
3446
+ started_at TEXT NOT NULL,
3447
+ last_event_at TEXT NOT NULL,
3448
+ event_count INTEGER NOT NULL DEFAULT 0,
3449
+ properties TEXT DEFAULT '{}'
3450
+ );
3451
+
3452
+ CREATE INDEX IF NOT EXISTS idx_agent_sessions_agent_time
3453
+ ON agent_sessions(agent_id, started_at);
3454
+
3455
+ CREATE TABLE IF NOT EXISTS agent_goals (
3456
+ id TEXT PRIMARY KEY,
3457
+ statement TEXT NOT NULL,
3458
+ owner_agent_id TEXT,
3459
+ project_name TEXT,
3460
+ status TEXT NOT NULL DEFAULT 'open',
3461
+ priority INTEGER NOT NULL DEFAULT 5,
3462
+ success_criteria TEXT,
3463
+ parent_goal_id TEXT,
3464
+ due_at TEXT,
3465
+ achieved_at TEXT,
3466
+ supersedes_id TEXT,
3467
+ created_at TEXT NOT NULL,
3468
+ updated_at TEXT NOT NULL,
3469
+ source_memory_id TEXT
3470
+ );
3471
+
3472
+ CREATE INDEX IF NOT EXISTS idx_agent_goals_project_status
3473
+ ON agent_goals(project_name, status, priority);
3474
+
3475
+ CREATE TABLE IF NOT EXISTS agent_events (
3476
+ id TEXT PRIMARY KEY,
3477
+ event_type TEXT NOT NULL,
3478
+ occurred_at TEXT NOT NULL,
3479
+ sequence_index INTEGER NOT NULL,
3480
+ actor_agent_id TEXT,
3481
+ agent_role TEXT,
3482
+ project_name TEXT,
3483
+ session_id TEXT,
3484
+ task_id TEXT,
3485
+ goal_id TEXT,
3486
+ parent_event_id TEXT,
3487
+ intention TEXT,
3488
+ outcome TEXT,
3489
+ evidence_memory_id TEXT,
3490
+ impact TEXT,
3491
+ payload TEXT DEFAULT '{}',
3492
+ created_at TEXT NOT NULL
3493
+ );
3494
+
3495
+ CREATE INDEX IF NOT EXISTS idx_agent_events_time
3496
+ ON agent_events(occurred_at, sequence_index);
3497
+
3498
+ CREATE INDEX IF NOT EXISTS idx_agent_events_session_seq
3499
+ ON agent_events(session_id, sequence_index);
3500
+
3501
+ CREATE INDEX IF NOT EXISTS idx_agent_events_goal_time
3502
+ ON agent_events(goal_id, occurred_at);
3503
+
3504
+ CREATE INDEX IF NOT EXISTS idx_agent_events_memory
3505
+ ON agent_events(evidence_memory_id);
3506
+
3507
+ CREATE TABLE IF NOT EXISTS agent_goal_links (
3508
+ id TEXT PRIMARY KEY,
3509
+ goal_id TEXT NOT NULL,
3510
+ link_type TEXT NOT NULL,
3511
+ target_id TEXT NOT NULL,
3512
+ target_type TEXT NOT NULL,
3513
+ created_at TEXT NOT NULL
3514
+ );
3515
+
3516
+ CREATE INDEX IF NOT EXISTS idx_agent_goal_links_goal
3517
+ ON agent_goal_links(goal_id, target_type);
3518
+
3519
+ CREATE TABLE IF NOT EXISTS agent_semantic_labels (
3520
+ id TEXT PRIMARY KEY,
3521
+ source_memory_id TEXT NOT NULL,
3522
+ event_id TEXT,
3523
+ labeler TEXT NOT NULL,
3524
+ schema_version INTEGER NOT NULL DEFAULT 1,
3525
+ confidence REAL NOT NULL DEFAULT 0,
3526
+ labels TEXT NOT NULL,
3527
+ created_at TEXT NOT NULL,
3528
+ updated_at TEXT NOT NULL
3529
+ );
3530
+
3531
+ CREATE INDEX IF NOT EXISTS idx_agent_semantic_labels_memory
3532
+ ON agent_semantic_labels(source_memory_id, labeler);
3533
+
3534
+ CREATE INDEX IF NOT EXISTS idx_agent_semantic_labels_event
3535
+ ON agent_semantic_labels(event_id);
3536
+
3537
+ CREATE TABLE IF NOT EXISTS agent_reflection_checkpoints (
3538
+ id TEXT PRIMARY KEY,
3539
+ project_name TEXT,
3540
+ session_id TEXT,
3541
+ window_start_at TEXT NOT NULL,
3542
+ window_end_at TEXT NOT NULL,
3543
+ event_count INTEGER NOT NULL DEFAULT 0,
3544
+ goal_count INTEGER NOT NULL DEFAULT 0,
3545
+ success_count INTEGER NOT NULL DEFAULT 0,
3546
+ failure_count INTEGER NOT NULL DEFAULT 0,
3547
+ risk_count INTEGER NOT NULL DEFAULT 0,
3548
+ summary TEXT NOT NULL,
3549
+ learnings TEXT NOT NULL DEFAULT '[]',
3550
+ next_actions TEXT NOT NULL DEFAULT '[]',
3551
+ evidence_event_ids TEXT NOT NULL DEFAULT '[]',
3552
+ confidence REAL NOT NULL DEFAULT 0,
3553
+ created_at TEXT NOT NULL
3554
+ );
3555
+
3556
+ CREATE INDEX IF NOT EXISTS idx_agent_reflection_project_time
3557
+ ON agent_reflection_checkpoints(project_name, window_end_at);
3558
+
3559
+ CREATE INDEX IF NOT EXISTS idx_agent_reflection_session_time
3560
+ ON agent_reflection_checkpoints(session_id, window_end_at);
3561
+ `);
3414
3562
  try {
3415
3563
  await client.execute({
3416
3564
  sql: `ALTER TABLE memories ADD COLUMN tier INTEGER DEFAULT 3`,
@@ -3628,7 +3776,7 @@ var init_embedder = __esm({
3628
3776
 
3629
3777
  // src/lib/keychain.ts
3630
3778
  import { readFile as readFile3, writeFile as writeFile3, unlink, mkdir as mkdir3, chmod as chmod2 } from "fs/promises";
3631
- import { existsSync as existsSync7 } from "fs";
3779
+ import { existsSync as existsSync7, statSync as statSync2 } from "fs";
3632
3780
  import { execSync as execSync2 } from "child_process";
3633
3781
  import path7 from "path";
3634
3782
  import os5 from "os";
@@ -3638,29 +3786,78 @@ function getKeyDir() {
3638
3786
  function getKeyPath() {
3639
3787
  return path7.join(getKeyDir(), "master.key");
3640
3788
  }
3641
- function macKeychainGet() {
3789
+ function nativeKeychainAllowed() {
3790
+ return process.env.EXE_OS_DISABLE_NATIVE_KEYCHAIN !== "1";
3791
+ }
3792
+ function linuxSecretAvailable() {
3793
+ if (!nativeKeychainAllowed()) return false;
3794
+ if (process.platform !== "linux") return false;
3795
+ if (linuxSecretAvailability !== null) return linuxSecretAvailability;
3796
+ try {
3797
+ execSync2("command -v secret-tool >/dev/null 2>&1", { timeout: 1e3 });
3798
+ } catch {
3799
+ linuxSecretAvailability = false;
3800
+ return false;
3801
+ }
3802
+ try {
3803
+ execSync2("secret-tool search --all exe-os probe >/dev/null 2>&1", { timeout: 1e3 });
3804
+ linuxSecretAvailability = true;
3805
+ } catch {
3806
+ linuxSecretAvailability = false;
3807
+ }
3808
+ return linuxSecretAvailability;
3809
+ }
3810
+ function isRootOnlyTrustedServerKeyFile(keyPath) {
3811
+ if (process.platform !== "linux") return false;
3812
+ try {
3813
+ const uid = typeof os5.userInfo().uid === "number" ? os5.userInfo().uid : -1;
3814
+ const st = statSync2(keyPath);
3815
+ if (!st.isFile() || (st.mode & 63) !== 0) return false;
3816
+ if (uid === 0) return true;
3817
+ const exeOsDir = process.env.EXE_OS_DIR;
3818
+ return Boolean(exeOsDir && path7.resolve(keyPath).startsWith(path7.resolve(exeOsDir) + path7.sep));
3819
+ } catch {
3820
+ return false;
3821
+ }
3822
+ }
3823
+ function macKeychainGet(service = SERVICE) {
3824
+ if (!nativeKeychainAllowed()) return null;
3642
3825
  if (process.platform !== "darwin") return null;
3643
3826
  try {
3644
3827
  return execSync2(
3645
- `security find-generic-password -s "${SERVICE}" -a "${ACCOUNT}" -w 2>/dev/null`,
3828
+ `security find-generic-password -s "${service}" -a "${ACCOUNT}" -w 2>/dev/null`,
3646
3829
  { encoding: "utf-8", timeout: 5e3 }
3647
3830
  ).trim();
3648
3831
  } catch {
3649
3832
  return null;
3650
3833
  }
3651
3834
  }
3652
- function macKeychainSet(value) {
3835
+ function macKeychainSet(value, service = SERVICE) {
3836
+ if (!nativeKeychainAllowed()) return false;
3653
3837
  if (process.platform !== "darwin") return false;
3654
3838
  try {
3655
3839
  try {
3656
3840
  execSync2(
3657
- `security delete-generic-password -s "${SERVICE}" -a "${ACCOUNT}" 2>/dev/null`,
3841
+ `security delete-generic-password -s "${service}" -a "${ACCOUNT}" 2>/dev/null`,
3658
3842
  { timeout: 5e3 }
3659
3843
  );
3660
3844
  } catch {
3661
3845
  }
3662
3846
  execSync2(
3663
- `security add-generic-password -s "${SERVICE}" -a "${ACCOUNT}" -w "${value}"`,
3847
+ `security add-generic-password -s "${service}" -a "${ACCOUNT}" -w "${value}"`,
3848
+ { timeout: 5e3 }
3849
+ );
3850
+ return true;
3851
+ } catch {
3852
+ return false;
3853
+ }
3854
+ }
3855
+ function macKeychainDelete(service = SERVICE) {
3856
+ if (!nativeKeychainAllowed()) return false;
3857
+ if (process.platform !== "darwin") return false;
3858
+ try {
3859
+ execSync2(
3860
+ `security delete-generic-password -s "${service}" -a "${ACCOUNT}" 2>/dev/null`,
3664
3861
  { timeout: 5e3 }
3665
3862
  );
3666
3863
  return true;
@@ -3668,22 +3865,35 @@ function macKeychainSet(value) {
3668
3865
  return false;
3669
3866
  }
3670
3867
  }
3671
- function linuxSecretGet() {
3672
- if (process.platform !== "linux") return null;
3868
+ function linuxSecretGet(service = SERVICE) {
3869
+ if (!linuxSecretAvailable()) return null;
3673
3870
  try {
3674
3871
  return execSync2(
3675
- `secret-tool lookup service "${SERVICE}" account "${ACCOUNT}" 2>/dev/null`,
3872
+ `secret-tool lookup service "${service}" account "${ACCOUNT}" 2>/dev/null`,
3676
3873
  { encoding: "utf-8", timeout: 5e3 }
3677
3874
  ).trim();
3678
3875
  } catch {
3679
3876
  return null;
3680
3877
  }
3681
3878
  }
3682
- function linuxSecretSet(value) {
3879
+ function linuxSecretSet(value, service = SERVICE) {
3880
+ if (!linuxSecretAvailable()) return false;
3881
+ try {
3882
+ execSync2(
3883
+ `echo -n "${value}" | secret-tool store --label="exe-os master key" service "${service}" account "${ACCOUNT}" 2>/dev/null`,
3884
+ { timeout: 5e3 }
3885
+ );
3886
+ return true;
3887
+ } catch {
3888
+ return false;
3889
+ }
3890
+ }
3891
+ function linuxSecretDelete(service = SERVICE) {
3892
+ if (!nativeKeychainAllowed()) return false;
3683
3893
  if (process.platform !== "linux") return false;
3684
3894
  try {
3685
3895
  execSync2(
3686
- `echo -n "${value}" | secret-tool store --label="exe-os master key" service "${SERVICE}" account "${ACCOUNT}"`,
3896
+ `secret-tool clear service "${service}" account "${ACCOUNT}" 2>/dev/null`,
3687
3897
  { timeout: 5e3 }
3688
3898
  );
3689
3899
  return true;
@@ -3692,6 +3902,7 @@ function linuxSecretSet(value) {
3692
3902
  }
3693
3903
  }
3694
3904
  async function tryKeytar() {
3905
+ if (!nativeKeychainAllowed()) return null;
3695
3906
  try {
3696
3907
  return await import("keytar");
3697
3908
  } catch {
@@ -3765,7 +3976,19 @@ async function writeMachineBoundFileFallback(b64) {
3765
3976
  return "plaintext";
3766
3977
  }
3767
3978
  async function getMasterKey() {
3768
- const nativeValue = macKeychainGet() ?? linuxSecretGet();
3979
+ let nativeValue = macKeychainGet() ?? linuxSecretGet();
3980
+ if (!nativeValue) {
3981
+ const legacyValue = macKeychainGet(LEGACY_SERVICE) ?? linuxSecretGet(LEGACY_SERVICE);
3982
+ if (legacyValue) {
3983
+ const migrated = macKeychainSet(legacyValue) || linuxSecretSet(legacyValue);
3984
+ if (migrated) {
3985
+ macKeychainDelete(LEGACY_SERVICE);
3986
+ linuxSecretDelete(LEGACY_SERVICE);
3987
+ process.stderr.write("[keychain] Migrated keychain service from exe-mem to exe-os.\n");
3988
+ }
3989
+ nativeValue = legacyValue;
3990
+ }
3991
+ }
3769
3992
  if (nativeValue) {
3770
3993
  return Buffer.from(nativeValue, "base64");
3771
3994
  }
@@ -3773,12 +3996,17 @@ async function getMasterKey() {
3773
3996
  if (keytar) {
3774
3997
  try {
3775
3998
  const keytarValue = await keytar.getPassword(SERVICE, ACCOUNT);
3776
- if (keytarValue) {
3777
- const migrated = macKeychainSet(keytarValue) || linuxSecretSet(keytarValue);
3999
+ const legacyKeytarValue = keytarValue ?? await keytar.getPassword(LEGACY_SERVICE, ACCOUNT);
4000
+ if (legacyKeytarValue) {
4001
+ const migrated = macKeychainSet(legacyKeytarValue) || linuxSecretSet(legacyKeytarValue);
3778
4002
  if (migrated) {
3779
4003
  process.stderr.write("[keychain] Migrated key from keytar to native keychain.\n");
4004
+ try {
4005
+ await keytar.deletePassword(LEGACY_SERVICE, ACCOUNT);
4006
+ } catch {
4007
+ }
3780
4008
  }
3781
- return Buffer.from(keytarValue, "base64");
4009
+ return Buffer.from(legacyKeytarValue, "base64");
3782
4010
  }
3783
4011
  } catch {
3784
4012
  }
@@ -3803,7 +4031,7 @@ async function getMasterKey() {
3803
4031
  const decrypted = decryptWithMachineKey(content, machineKey);
3804
4032
  if (!decrypted) {
3805
4033
  process.stderr.write(
3806
- "[keychain] Key decryption failed \u2014 machine may have changed.\n Use your 24-word recovery phrase: exe-os link import\n"
4034
+ "[keychain] Key decryption failed \u2014 machine may have changed.\n Use your 24-word recovery phrase during setup: exe-os setup\n"
3807
4035
  );
3808
4036
  return null;
3809
4037
  }
@@ -3812,6 +4040,9 @@ async function getMasterKey() {
3812
4040
  b64Value = content;
3813
4041
  }
3814
4042
  const key = Buffer.from(b64Value, "base64");
4043
+ if (!content.startsWith(ENCRYPTED_PREFIX) && isRootOnlyTrustedServerKeyFile(keyPath)) {
4044
+ return key;
4045
+ }
3815
4046
  const migrated = macKeychainSet(b64Value) || linuxSecretSet(b64Value);
3816
4047
  if (migrated) {
3817
4048
  process.stderr.write("[keychain] Migrated key from file to native keychain.\n");
@@ -3839,12 +4070,14 @@ async function getMasterKey() {
3839
4070
  return null;
3840
4071
  }
3841
4072
  }
3842
- var SERVICE, ACCOUNT, ENCRYPTED_PREFIX;
4073
+ var SERVICE, LEGACY_SERVICE, ACCOUNT, linuxSecretAvailability, ENCRYPTED_PREFIX;
3843
4074
  var init_keychain = __esm({
3844
4075
  "src/lib/keychain.ts"() {
3845
4076
  "use strict";
3846
- SERVICE = "exe-mem";
4077
+ SERVICE = "exe-os";
4078
+ LEGACY_SERVICE = "exe-mem";
3847
4079
  ACCOUNT = "master-key";
4080
+ linuxSecretAvailability = null;
3848
4081
  ENCRYPTED_PREFIX = "enc:";
3849
4082
  }
3850
4083
  });
@@ -4059,7 +4292,7 @@ __export(shard_manager_exports, {
4059
4292
  shardExists: () => shardExists
4060
4293
  });
4061
4294
  import path8 from "path";
4062
- import { existsSync as existsSync8, mkdirSync as mkdirSync2, readdirSync, renameSync as renameSync3, statSync as statSync2 } from "fs";
4295
+ import { existsSync as existsSync8, mkdirSync as mkdirSync2, readdirSync, renameSync as renameSync3, statSync as statSync3 } from "fs";
4063
4296
  import { createClient as createClient2 } from "@libsql/client";
4064
4297
  function initShardManager(encryptionKey) {
4065
4298
  _encryptionKey = encryptionKey;
@@ -4123,7 +4356,7 @@ async function auditShardHealth(options = {}) {
4123
4356
  const shards = [];
4124
4357
  for (const name of names) {
4125
4358
  const dbPath = path8.join(SHARDS_DIR, `${name}.db`);
4126
- const stat = statSync2(dbPath);
4359
+ const stat = statSync3(dbPath);
4127
4360
  const item = {
4128
4361
  name,
4129
4362
  path: dbPath,
@@ -4376,7 +4609,7 @@ async function getReadyShardClient(projectName) {
4376
4609
  _shardLastAccess.delete(safeName);
4377
4610
  const dbPath = path8.join(SHARDS_DIR, `${safeName}.db`);
4378
4611
  if (existsSync8(dbPath)) {
4379
- const stat = statSync2(dbPath);
4612
+ const stat = statSync3(dbPath);
4380
4613
  const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
4381
4614
  const archivedPath = path8.join(SHARDS_DIR, `${safeName}.db.broken-${stamp}`);
4382
4615
  renameSync3(dbPath, archivedPath);
@@ -4496,6 +4729,12 @@ var init_platform_procedures = __esm({
4496
4729
  priority: "p0",
4497
4730
  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."
4498
4731
  },
4732
+ {
4733
+ title: "Customer orchestration maturity \u2014 recommend, never trap",
4734
+ domain: "workflow",
4735
+ priority: "p1",
4736
+ 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."
4737
+ },
4499
4738
  {
4500
4739
  title: "Single dispatch path \u2014 create_task only",
4501
4740
  domain: "workflow",
@@ -4554,6 +4793,12 @@ var init_platform_procedures = __esm({
4554
4793
  priority: "p0",
4555
4794
  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."
4556
4795
  },
4796
+ {
4797
+ title: "Commit discipline \u2014 never leave verified work floating",
4798
+ domain: "workflow",
4799
+ priority: "p1",
4800
+ 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."
4801
+ },
4557
4802
  {
4558
4803
  title: "Desktop and TUI are the same product",
4559
4804
  domain: "architecture",
@@ -4871,6 +5116,274 @@ var init_memory_cards = __esm({
4871
5116
  }
4872
5117
  });
4873
5118
 
5119
+ // src/lib/agentic-ontology.ts
5120
+ var agentic_ontology_exports = {};
5121
+ __export(agentic_ontology_exports, {
5122
+ clean: () => clean,
5123
+ extractGoalCandidates: () => extractGoalCandidates,
5124
+ inferIntention: () => inferIntention,
5125
+ inferOntologyEventType: () => inferOntologyEventType,
5126
+ inferOutcome: () => inferOutcome,
5127
+ inferSemanticLabel: () => inferSemanticLabel,
5128
+ insertOntologyForBatch: () => insertOntologyForBatch,
5129
+ insertOntologyForMemory: () => insertOntologyForMemory,
5130
+ ontologyPayload: () => ontologyPayload,
5131
+ stableId: () => stableId2
5132
+ });
5133
+ import { createHash as createHash3 } from "crypto";
5134
+ function stableId2(...parts) {
5135
+ return createHash3("sha256").update(parts.map((p) => String(p ?? "")).join("::")).digest("hex").slice(0, 32);
5136
+ }
5137
+ function clean(text, max = 240) {
5138
+ return text.replace(/\u0000/g, "").replace(/```[\s\S]*?```/g, " ").replace(/\s+/g, " ").trim().slice(0, max);
5139
+ }
5140
+ function inferOntologyEventType(row) {
5141
+ const lower = row.raw_text.toLowerCase();
5142
+ if (row.has_error) return "error";
5143
+ if (/\b(done|complete|completed|fixed|resolved|shipped|deployed|pushed|published)\b/.test(lower)) return "milestone";
5144
+ if (/\b(blocked|failed|error|bug|regression|broken)\b/.test(lower)) return "problem";
5145
+ if (/\b(decided|decision|adr|we chose|approved|rejected)\b/.test(lower)) return "decision";
5146
+ if (/\b(goal|need to|we need|want to|trying to|objective)\b/.test(lower)) return "goal_signal";
5147
+ if (["Bash", "Read", "Edit", "Write", "Grep", "Glob"].includes(row.tool_name)) return "tool_action";
5148
+ if (row.tool_name.startsWith("memory_card")) return "memory_card";
5149
+ return "memory_observation";
5150
+ }
5151
+ function inferIntention(row) {
5152
+ if (row.intent) return clean(row.intent, 220);
5153
+ const text = clean(row.raw_text, 1e3);
5154
+ const patterns = [
5155
+ /(?: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,
5156
+ /(?:so that|in order to)\s+([^.!?\n]{8,220})/i,
5157
+ /(?:task|plan):\s*([^.!?\n]{8,220})/i
5158
+ ];
5159
+ for (const p of patterns) {
5160
+ const m = text.match(p);
5161
+ if (m?.[1]) return clean(m[1], 220);
5162
+ }
5163
+ if (["Bash", "Read", "Edit", "Write", "Grep", "Glob"].includes(row.tool_name)) {
5164
+ return `${row.tool_name} during ${row.project_name}`;
5165
+ }
5166
+ return null;
5167
+ }
5168
+ function inferOutcome(row) {
5169
+ if (row.outcome) return clean(row.outcome, 220);
5170
+ if (row.has_error) return "error";
5171
+ const lower = row.raw_text.toLowerCase();
5172
+ if (/\b(done|complete|completed|fixed|resolved|shipped|deployed|pushed|published|passed)\b/.test(lower)) return "success_signal";
5173
+ if (/\b(blocked|failed|error|regression|broken|not working|could not)\b/.test(lower)) return "failure_signal";
5174
+ if (/\b(warning|risk|concern|caveat)\b/.test(lower)) return "risk_signal";
5175
+ return null;
5176
+ }
5177
+ function extractGoalCandidates(row) {
5178
+ const text = clean(row.raw_text, 1600);
5179
+ const patterns = [
5180
+ /(?: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,
5181
+ /(?:success means|success criteria|so that)\s+([^.!?\n]{12,220})/gi
5182
+ ];
5183
+ const out = [];
5184
+ for (const pattern of patterns) {
5185
+ for (const m of text.matchAll(pattern)) {
5186
+ const candidate = clean(m[1] ?? "", 220);
5187
+ if (candidate.length >= 12 && !out.some((x) => x.toLowerCase() === candidate.toLowerCase())) out.push(candidate);
5188
+ if (out.length >= 3) return out;
5189
+ }
5190
+ }
5191
+ return out;
5192
+ }
5193
+ function uniq(values, max = 6) {
5194
+ const out = [];
5195
+ for (const value of values.map((v) => clean(v, 220)).filter(Boolean)) {
5196
+ if (!out.some((x) => x.toLowerCase() === value.toLowerCase())) out.push(value);
5197
+ if (out.length >= max) break;
5198
+ }
5199
+ return out;
5200
+ }
5201
+ function extractMatches(text, patterns, max = 5) {
5202
+ const out = [];
5203
+ for (const pattern of patterns) {
5204
+ for (const match of text.matchAll(pattern)) {
5205
+ const value = match[1] ?? match[0];
5206
+ if (value) out.push(value);
5207
+ if (out.length >= max) return uniq(out, max);
5208
+ }
5209
+ }
5210
+ return uniq(out, max);
5211
+ }
5212
+ function inferSemanticLabel(row) {
5213
+ const text = clean(row.raw_text, 2400);
5214
+ const eventType = inferOntologyEventType(row);
5215
+ const intention = inferIntention(row);
5216
+ const outcome = inferOutcome(row);
5217
+ const goals = extractGoalCandidates(row);
5218
+ const milestones = extractMatches(text, [
5219
+ /\b(?:completed|finished|fixed|resolved|shipped|deployed|published|pushed|passed)\b([^.!?\n]{0,180})/gi,
5220
+ /(?:milestone|done):\s*([^.!?\n]{8,220})/gi
5221
+ ]);
5222
+ const problems = extractMatches(text, [
5223
+ /\b(?:blocked by|failed because|bug|regression|broken|not working|error)\b([^.!?\n]{0,180})/gi,
5224
+ /(?:problem|issue|risk):\s*([^.!?\n]{8,220})/gi
5225
+ ]);
5226
+ const decisions = extractMatches(text, [
5227
+ /(?:decided|decision|adr|we chose|approved|rejected)\s+([^.!?\n]{8,220})/gi
5228
+ ]);
5229
+ const temporalAnchors = extractMatches(text, [
5230
+ /\b(\d{4}-\d{2}-\d{2}(?:[T ][0-9:.+-Z]+)?)\b/g,
5231
+ /\b(today|yesterday|tomorrow|this week|next week|last week|morning|afternoon|tonight)\b/gi
5232
+ ], 8);
5233
+ const nextActions = extractMatches(text, [
5234
+ /(?:next|todo|follow[- ]?up|remaining|need to)\s*:?\s*([^.!?\n]{8,220})/gi
5235
+ ]);
5236
+ const actors = uniq([
5237
+ row.agent_id,
5238
+ ...extractMatches(text, [/\b(?:agent|employee|owner|assignee)[:= ]+([a-zA-Z][a-zA-Z0-9_-]{1,40})/gi], 5)
5239
+ ], 6);
5240
+ const successSignals = milestones.length ? milestones : outcome === "success_signal" ? [clean(text, 180)] : [];
5241
+ const failureSignals = problems.length ? problems : outcome === "failure_signal" || row.has_error ? [clean(text, 180)] : [];
5242
+ const impact = successSignals.length && failureSignals.length ? "mixed" : failureSignals.length ? "negative" : successSignals.length ? "positive" : "neutral";
5243
+ const signalCount = goals.length + milestones.length + problems.length + decisions.length + nextActions.length;
5244
+ return {
5245
+ labeler: "deterministic",
5246
+ schemaVersion: 1,
5247
+ eventType,
5248
+ intention,
5249
+ outcome,
5250
+ impact,
5251
+ confidence: Math.min(0.95, 0.45 + signalCount * 0.08 + (intention ? 0.1 : 0) + (outcome ? 0.1 : 0)),
5252
+ goals,
5253
+ milestones,
5254
+ problems,
5255
+ decisions,
5256
+ actors,
5257
+ temporalAnchors,
5258
+ successSignals,
5259
+ failureSignals,
5260
+ nextActions,
5261
+ summary: clean(text, 280)
5262
+ };
5263
+ }
5264
+ function ontologyPayload(row) {
5265
+ const semantic = inferSemanticLabel(row);
5266
+ return {
5267
+ tool_name: row.tool_name,
5268
+ memory_version: row.version ?? null,
5269
+ domain: row.domain ?? null,
5270
+ trajectory: row.trajectory ? safeJson(row.trajectory) : null,
5271
+ semantic
5272
+ };
5273
+ }
5274
+ function safeJson(value) {
5275
+ try {
5276
+ return JSON.parse(value);
5277
+ } catch {
5278
+ return value.slice(0, 1e3);
5279
+ }
5280
+ }
5281
+ async function resolveClient(client) {
5282
+ if (client) return client;
5283
+ const { getClient: getClient2 } = await Promise.resolve().then(() => (init_database(), database_exports));
5284
+ return getClient2();
5285
+ }
5286
+ async function insertOntologyForMemory(row, client) {
5287
+ const db = await resolveClient(client);
5288
+ const occurredAt = row.timestamp;
5289
+ const sequence = Number(row.version ?? 0) || Math.floor(new Date(occurredAt).getTime() / 1e3);
5290
+ const eventType = inferOntologyEventType(row);
5291
+ const intention = inferIntention(row);
5292
+ const outcome = inferOutcome(row);
5293
+ const eventId = stableId2("event", row.id);
5294
+ const now = (/* @__PURE__ */ new Date()).toISOString();
5295
+ await db.execute({
5296
+ sql: `INSERT INTO agent_sessions (id, agent_id, project_name, started_at, last_event_at, event_count, properties)
5297
+ VALUES (?, ?, ?, ?, ?, 1, ?)
5298
+ ON CONFLICT(id) DO UPDATE SET last_event_at = MAX(last_event_at, excluded.last_event_at),
5299
+ event_count = event_count + 1`,
5300
+ args: [row.session_id, row.agent_id, row.project_name, occurredAt, occurredAt, JSON.stringify({ agent_role: row.agent_role })]
5301
+ });
5302
+ await db.execute({
5303
+ sql: `INSERT OR IGNORE INTO agent_events
5304
+ (id, event_type, occurred_at, sequence_index, actor_agent_id, agent_role, project_name,
5305
+ session_id, task_id, goal_id, parent_event_id, intention, outcome, evidence_memory_id,
5306
+ impact, payload, created_at)
5307
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NULL, NULL, ?, ?, ?, ?, ?, ?)`,
5308
+ args: [
5309
+ eventId,
5310
+ eventType,
5311
+ occurredAt,
5312
+ sequence,
5313
+ row.agent_id,
5314
+ row.agent_role,
5315
+ row.project_name,
5316
+ row.session_id,
5317
+ row.task_id ?? null,
5318
+ intention,
5319
+ outcome,
5320
+ row.id,
5321
+ row.has_error ? "negative" : outcome === "success_signal" ? "positive" : "neutral",
5322
+ JSON.stringify(ontologyPayload(row)),
5323
+ now
5324
+ ]
5325
+ });
5326
+ const semantic = inferSemanticLabel(row);
5327
+ await db.execute({
5328
+ sql: `INSERT INTO agent_semantic_labels
5329
+ (id, source_memory_id, event_id, labeler, schema_version, confidence, labels, created_at, updated_at)
5330
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
5331
+ ON CONFLICT(id) DO UPDATE SET confidence = excluded.confidence,
5332
+ labels = excluded.labels, updated_at = excluded.updated_at`,
5333
+ args: [
5334
+ stableId2("semantic", row.id, semantic.labeler, semantic.schemaVersion),
5335
+ row.id,
5336
+ eventId,
5337
+ semantic.labeler,
5338
+ semantic.schemaVersion,
5339
+ semantic.confidence,
5340
+ JSON.stringify(semantic),
5341
+ now,
5342
+ now
5343
+ ]
5344
+ });
5345
+ for (const statement of extractGoalCandidates(row)) {
5346
+ const goalId = stableId2("goal", row.project_name, statement.toLowerCase());
5347
+ await db.execute({
5348
+ sql: `INSERT INTO agent_goals
5349
+ (id, statement, owner_agent_id, project_name, status, priority, success_criteria,
5350
+ parent_goal_id, due_at, achieved_at, supersedes_id, created_at, updated_at, source_memory_id)
5351
+ VALUES (?, ?, ?, ?, 'open', 5, NULL, NULL, NULL, NULL, NULL, ?, ?, ?)
5352
+ ON CONFLICT(id) DO UPDATE SET updated_at = excluded.updated_at`,
5353
+ args: [goalId, statement, row.agent_id, row.project_name, now, now, row.id]
5354
+ });
5355
+ await db.execute({
5356
+ sql: `INSERT OR IGNORE INTO agent_goal_links
5357
+ (id, goal_id, link_type, target_id, target_type, created_at)
5358
+ VALUES (?, ?, 'evidence', ?, 'memory', ?)`,
5359
+ args: [stableId2("goal_link", goalId, row.id, "memory"), goalId, row.id, now]
5360
+ });
5361
+ await db.execute({
5362
+ sql: `INSERT OR IGNORE INTO agent_goal_links
5363
+ (id, goal_id, link_type, target_id, target_type, created_at)
5364
+ VALUES (?, ?, 'event', ?, 'event', ?)`,
5365
+ args: [stableId2("goal_link", goalId, eventId, "event"), goalId, eventId, now]
5366
+ });
5367
+ }
5368
+ }
5369
+ async function insertOntologyForBatch(rows, client) {
5370
+ const db = await resolveClient(client);
5371
+ let count = 0;
5372
+ for (const row of rows) {
5373
+ try {
5374
+ await insertOntologyForMemory(row, db);
5375
+ count++;
5376
+ } catch {
5377
+ }
5378
+ }
5379
+ return count;
5380
+ }
5381
+ var init_agentic_ontology = __esm({
5382
+ "src/lib/agentic-ontology.ts"() {
5383
+ "use strict";
5384
+ }
5385
+ });
5386
+
4874
5387
  // src/lib/store.ts
4875
5388
  var store_exports = {};
4876
5389
  __export(store_exports, {
@@ -5214,6 +5727,11 @@ async function flushBatch() {
5214
5727
  await insertMemoryCardsForBatch2(batch);
5215
5728
  } catch {
5216
5729
  }
5730
+ try {
5731
+ const { insertOntologyForBatch: insertOntologyForBatch2 } = await Promise.resolve().then(() => (init_agentic_ontology(), agentic_ontology_exports));
5732
+ await insertOntologyForBatch2(batch);
5733
+ } catch {
5734
+ }
5217
5735
  schedulePostWriteMemoryHygiene(batch.map((row) => row.id));
5218
5736
  _pendingRecords.splice(0, batch.length);
5219
5737
  try {
@@ -5819,6 +6337,7 @@ __export(graph_rag_exports, {
5819
6337
  extractBatch: () => extractBatch,
5820
6338
  extractFromCode: () => extractFromCode,
5821
6339
  extractFromMemory: () => extractFromMemory,
6340
+ extractHeuristicMemoryGraph: () => extractHeuristicMemoryGraph,
5822
6341
  mergeEntities: () => mergeEntities,
5823
6342
  normalizeEntityName: () => normalizeEntityName,
5824
6343
  registerAlias: () => registerAlias,
@@ -5974,6 +6493,57 @@ function extractFromCode(source, filePath) {
5974
6493
  }
5975
6494
  return { entities, relationships, hyperedges: [] };
5976
6495
  }
6496
+ function pushUniqueEntity(entities, seen, name, type) {
6497
+ const normalized = normalizeEntityName(name);
6498
+ if (!normalized || normalized.length < 2) return;
6499
+ const key = `${normalized.toLowerCase()}::${type.toLowerCase()}`;
6500
+ if (seen.has(key)) return;
6501
+ seen.add(key);
6502
+ entities.push({ name: normalized.slice(0, 160), type });
6503
+ }
6504
+ function pushHeuristicRelationship(relationships, source, sourceType, target, targetType, relationship, confidence = 0.6) {
6505
+ if (!source || !target || source === target) return;
6506
+ relationships.push({
6507
+ source,
6508
+ sourceType,
6509
+ target,
6510
+ targetType,
6511
+ relationship,
6512
+ confidence,
6513
+ confidenceLabel: "inferred"
6514
+ });
6515
+ }
6516
+ function extractHeuristicMemoryGraph(content, agentId) {
6517
+ const entities = [];
6518
+ const relationships = [];
6519
+ const seen = /* @__PURE__ */ new Set();
6520
+ pushUniqueEntity(entities, seen, agentId, "person");
6521
+ const toolMatch = content.match(/^(Bash|Read|Edit|Write|Grep|Glob|AssistantResponse|Tool|Ran|Wrote|Edited):/m);
6522
+ if (toolMatch?.[1]) {
6523
+ pushUniqueEntity(entities, seen, toolMatch[1], "tool");
6524
+ pushHeuristicRelationship(relationships, agentId, "person", toolMatch[1], "tool", "uses", 0.75);
6525
+ }
6526
+ 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);
6527
+ for (const repo of repoMatches) {
6528
+ pushUniqueEntity(entities, seen, repo, "project");
6529
+ pushHeuristicRelationship(relationships, agentId, "person", repo, "project", "worked_on", 0.7);
6530
+ }
6531
+ const pathMatches = new Set(
6532
+ (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)
6533
+ );
6534
+ for (const filePath of pathMatches) {
6535
+ pushUniqueEntity(entities, seen, filePath, "file");
6536
+ pushHeuristicRelationship(relationships, agentId, "person", filePath, "file", "uses", 0.65);
6537
+ }
6538
+ const backtickTerms = [...content.matchAll(/`([^`\n]{2,80})`/g)].map((m) => m[1]).slice(0, 10);
6539
+ for (const term of backtickTerms) {
6540
+ if (!term || term.length < 2) continue;
6541
+ const type = term.includes("/") || /\.[A-Za-z0-9]{1,10}$/.test(term) ? "file" : "concept";
6542
+ pushUniqueEntity(entities, seen, term, type);
6543
+ pushHeuristicRelationship(relationships, agentId, "person", term, type, "uses", 0.55);
6544
+ }
6545
+ return { entities, relationships, hyperedges: [] };
6546
+ }
5977
6547
  async function extractFromMemory(content, agentId, model = "claude-haiku-4-5-20251001", filePath) {
5978
6548
  if (content.length < 50) {
5979
6549
  return { entities: [], relationships: [], hyperedges: [] };
@@ -6029,7 +6599,7 @@ async function extractFromMemory(content, agentId, model = "claude-haiku-4-5-202
6029
6599
  `
6030
6600
  );
6031
6601
  }
6032
- return { entities: [], relationships: [], hyperedges: [] };
6602
+ return extractHeuristicMemoryGraph(content, agentId);
6033
6603
  }
6034
6604
  async function storeExtraction(client, extraction, memoryId, timestamp) {
6035
6605
  let entitiesStored = 0;