@askexenow/exe-os 0.9.111 → 0.9.112

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 (79) hide show
  1. package/dist/bin/agentic-ontology-backfill.js +8 -1
  2. package/dist/bin/agentic-reflection-backfill.js +8 -1
  3. package/dist/bin/agentic-semantic-label.js +8 -1
  4. package/dist/bin/backfill-conversations.js +8 -1
  5. package/dist/bin/backfill-responses.js +8 -1
  6. package/dist/bin/backfill-vectors.js +8 -1
  7. package/dist/bin/bulk-sync-postgres.js +8 -1
  8. package/dist/bin/cleanup-stale-review-tasks.js +8 -1
  9. package/dist/bin/cli.js +19 -4
  10. package/dist/bin/exe-agent.js +1 -1
  11. package/dist/bin/exe-assign.js +8 -1
  12. package/dist/bin/exe-boot.js +19 -4
  13. package/dist/bin/exe-call.js +1 -1
  14. package/dist/bin/exe-cloud.js +8 -1
  15. package/dist/bin/exe-dispatch.js +460 -5
  16. package/dist/bin/exe-doctor.js +8 -1
  17. package/dist/bin/exe-export-behaviors.js +13 -3
  18. package/dist/bin/exe-forget.js +8 -1
  19. package/dist/bin/exe-gateway.js +19 -4
  20. package/dist/bin/exe-heartbeat.js +8 -1
  21. package/dist/bin/exe-kill.js +8 -1
  22. package/dist/bin/exe-launch-agent.js +13 -3
  23. package/dist/bin/exe-new-employee.js +1 -1
  24. package/dist/bin/exe-pending-messages.js +8 -1
  25. package/dist/bin/exe-pending-notifications.js +8 -1
  26. package/dist/bin/exe-pending-reviews.js +8 -1
  27. package/dist/bin/exe-rename.js +8 -1
  28. package/dist/bin/exe-review.js +8 -1
  29. package/dist/bin/exe-search.js +8 -1
  30. package/dist/bin/exe-session-cleanup.js +460 -5
  31. package/dist/bin/exe-start-codex.js +13 -3
  32. package/dist/bin/exe-start-opencode.js +13 -3
  33. package/dist/bin/exe-status.js +8 -1
  34. package/dist/bin/exe-team.js +8 -1
  35. package/dist/bin/git-sweep.js +460 -5
  36. package/dist/bin/graph-backfill.js +8 -1
  37. package/dist/bin/graph-export.js +8 -1
  38. package/dist/bin/intercom-check.js +460 -5
  39. package/dist/bin/pre-publish.js +1 -1
  40. package/dist/bin/scan-tasks.js +460 -5
  41. package/dist/bin/setup.js +8 -1
  42. package/dist/bin/shard-migrate.js +8 -1
  43. package/dist/gateway/index.js +460 -5
  44. package/dist/hooks/bug-report-worker.js +460 -5
  45. package/dist/hooks/codex-stop-task-finalizer.js +467 -5
  46. package/dist/hooks/commit-complete.js +460 -5
  47. package/dist/hooks/error-recall.js +8 -1
  48. package/dist/hooks/ingest.js +8 -1
  49. package/dist/hooks/instructions-loaded.js +8 -1
  50. package/dist/hooks/notification.js +8 -1
  51. package/dist/hooks/post-compact.js +8 -1
  52. package/dist/hooks/post-tool-combined.js +8 -1
  53. package/dist/hooks/pre-compact.js +460 -5
  54. package/dist/hooks/pre-tool-use.js +8 -1
  55. package/dist/hooks/prompt-submit.js +469 -8
  56. package/dist/hooks/session-end.js +460 -5
  57. package/dist/hooks/session-start.js +8 -1
  58. package/dist/hooks/stop.js +8 -1
  59. package/dist/hooks/subagent-stop.js +8 -1
  60. package/dist/hooks/summary-worker.js +8 -1
  61. package/dist/index.js +469 -8
  62. package/dist/lib/cloud-sync.js +7 -0
  63. package/dist/lib/database.js +7 -0
  64. package/dist/lib/db.js +7 -0
  65. package/dist/lib/device-registry.js +7 -0
  66. package/dist/lib/employee-templates.js +1 -1
  67. package/dist/lib/exe-daemon.js +216 -12
  68. package/dist/lib/hybrid-search.js +8 -1
  69. package/dist/lib/schedules.js +8 -1
  70. package/dist/lib/skill-learning.js +488 -7
  71. package/dist/lib/store.js +8 -1
  72. package/dist/lib/tasks.js +452 -4
  73. package/dist/lib/tmux-routing.js +452 -4
  74. package/dist/mcp/server.js +69 -11
  75. package/dist/mcp/tools/create-task.js +452 -4
  76. package/dist/mcp/tools/update-task.js +452 -4
  77. package/dist/runtime/index.js +469 -8
  78. package/dist/tui/App.js +19 -4
  79. package/package.json +1 -1
@@ -2135,6 +2135,13 @@ async function ensureSchema() {
2135
2135
  } catch (e) {
2136
2136
  logCatchDebug("migration", e);
2137
2137
  }
2138
+ for (const col of ["created_by_agent TEXT", "created_by_device TEXT", "source_session_id TEXT"]) {
2139
+ try {
2140
+ await client.execute({ sql: `ALTER TABLE behaviors ADD COLUMN ${col}`, args: [] });
2141
+ } catch (e) {
2142
+ logCatchDebug("migration", e);
2143
+ }
2144
+ }
2138
2145
  try {
2139
2146
  await client.execute({
2140
2147
  sql: `ALTER TABLE tasks ADD COLUMN blocked_by TEXT`,
@@ -4663,7 +4670,7 @@ var init_platform_procedures = __esm({
4663
4670
  title: "MCP tool dispatch \u2014 all tools use action parameter",
4664
4671
  domain: "tool-use",
4665
4672
  priority: "p0",
4666
- content: 'exe-os MCP tools come in two surfaces depending on EXE_MCP_TOOL_SURFACE config. Consolidated (19 tools): action-based dispatch \u2014 memory(action="recall"), task(action="create"), etc. Legacy (108 tools): one tool per operation \u2014 recall_my_memory, create_task, etc. Both surfaces have identical functionality. Use whichever tool names are available in your session. If you see domain tools (memory, task, config, etc.), use the action parameter. If you see specific tools (recall_my_memory, create_task, etc.), call them directly.'
4673
+ content: 'exe-os MCP tools use consolidated action-based dispatch by default (19 tools). Call domain tools with an action parameter: memory(action="recall"), task(action="create"), config(action="list_employees"), etc. Legacy mode (108 separate tools like recall_my_memory, create_task) is still available via EXE_MCP_TOOL_SURFACE=legacy but will be removed in a future version. If you see specific tool names, call them directly \u2014 both surfaces are identical. Consolidated is the default and recommended surface.'
4667
4674
  },
4668
4675
  {
4669
4676
  title: "MCP tools \u2014 memory, decision, and search",
@@ -6439,6 +6446,23 @@ var init_intercom_queue = __esm({
6439
6446
  });
6440
6447
 
6441
6448
  // src/lib/license.ts
6449
+ var license_exports = {};
6450
+ __export(license_exports, {
6451
+ LICENSE_PUBLIC_KEY_PEM: () => LICENSE_PUBLIC_KEY_PEM,
6452
+ PLAN_LIMITS: () => PLAN_LIMITS,
6453
+ assertVpsLicense: () => assertVpsLicense,
6454
+ checkLicense: () => checkLicense,
6455
+ getCachedLicense: () => getCachedLicense,
6456
+ isFeatureAllowed: () => isFeatureAllowed,
6457
+ loadDeviceId: () => loadDeviceId,
6458
+ loadLicense: () => loadLicense,
6459
+ mirrorLicenseKey: () => mirrorLicenseKey,
6460
+ readCachedLicenseToken: () => readCachedLicenseToken,
6461
+ saveLicense: () => saveLicense,
6462
+ startLicenseRevalidation: () => startLicenseRevalidation,
6463
+ stopLicenseRevalidation: () => stopLicenseRevalidation,
6464
+ validateLicense: () => validateLicense
6465
+ });
6442
6466
  import { readFileSync as readFileSync8, writeFileSync as writeFileSync6, existsSync as existsSync12, mkdirSync as mkdirSync6 } from "fs";
6443
6467
  import { randomUUID as randomUUID3 } from "crypto";
6444
6468
  import { createRequire as createRequire2 } from "module";
@@ -6446,7 +6470,411 @@ import { pathToFileURL as pathToFileURL2 } from "url";
6446
6470
  import os8 from "os";
6447
6471
  import path11 from "path";
6448
6472
  import { jwtVerify, importSPKI } from "jose";
6449
- var LICENSE_PATH, CACHE_PATH, DEVICE_ID_PATH, API_BASE, PLAN_LIMITS;
6473
+ async function fetchRetry(url, init) {
6474
+ try {
6475
+ return await fetch(url, init);
6476
+ } catch {
6477
+ await new Promise((r) => setTimeout(r, RETRY_DELAY_MS));
6478
+ return fetch(url, { ...init, signal: AbortSignal.timeout(1e4) });
6479
+ }
6480
+ }
6481
+ function loadDeviceId() {
6482
+ const deviceJsonPath = path11.join(EXE_AI_DIR, "device.json");
6483
+ try {
6484
+ if (existsSync12(deviceJsonPath)) {
6485
+ const data = JSON.parse(readFileSync8(deviceJsonPath, "utf8"));
6486
+ if (data.deviceId) return data.deviceId;
6487
+ }
6488
+ } catch {
6489
+ }
6490
+ try {
6491
+ if (existsSync12(DEVICE_ID_PATH)) {
6492
+ const id2 = readFileSync8(DEVICE_ID_PATH, "utf8").trim();
6493
+ if (id2) return id2;
6494
+ }
6495
+ } catch {
6496
+ }
6497
+ const id = randomUUID3();
6498
+ mkdirSync6(EXE_AI_DIR, { recursive: true });
6499
+ writeFileSync6(DEVICE_ID_PATH, id, "utf8");
6500
+ return id;
6501
+ }
6502
+ function loadLicense() {
6503
+ try {
6504
+ if (!existsSync12(LICENSE_PATH)) return null;
6505
+ return readFileSync8(LICENSE_PATH, "utf8").trim();
6506
+ } catch {
6507
+ return null;
6508
+ }
6509
+ }
6510
+ function saveLicense(apiKey) {
6511
+ mkdirSync6(EXE_AI_DIR, { recursive: true });
6512
+ writeFileSync6(LICENSE_PATH, apiKey.trim(), { encoding: "utf8", mode: 384 });
6513
+ }
6514
+ async function verifyLicenseJwt(token) {
6515
+ try {
6516
+ const key = await importSPKI(LICENSE_PUBLIC_KEY_PEM, LICENSE_JWT_ALG);
6517
+ const { payload } = await jwtVerify(token, key, {
6518
+ algorithms: [LICENSE_JWT_ALG]
6519
+ });
6520
+ const plan = payload.plan ?? "free";
6521
+ const email = payload.sub ?? "";
6522
+ const limits = PLAN_LIMITS[plan] ?? PLAN_LIMITS.free;
6523
+ return {
6524
+ valid: true,
6525
+ plan,
6526
+ email,
6527
+ expiresAt: payload.exp ? new Date(payload.exp * 1e3).toISOString() : null,
6528
+ deviceLimit: limits.devices,
6529
+ employeeLimit: limits.employees,
6530
+ memoryLimit: limits.memories
6531
+ };
6532
+ } catch {
6533
+ return null;
6534
+ }
6535
+ }
6536
+ async function getCachedLicense() {
6537
+ try {
6538
+ if (!existsSync12(CACHE_PATH)) return null;
6539
+ const raw = JSON.parse(readFileSync8(CACHE_PATH, "utf8"));
6540
+ if (!raw.token || typeof raw.token !== "string") return null;
6541
+ return await verifyLicenseJwt(raw.token);
6542
+ } catch {
6543
+ return null;
6544
+ }
6545
+ }
6546
+ function readCachedLicenseToken() {
6547
+ try {
6548
+ if (!existsSync12(CACHE_PATH)) return null;
6549
+ const raw = JSON.parse(readFileSync8(CACHE_PATH, "utf8"));
6550
+ return typeof raw.token === "string" ? raw.token : null;
6551
+ } catch {
6552
+ return null;
6553
+ }
6554
+ }
6555
+ function getRawCachedPlan() {
6556
+ try {
6557
+ const token = readCachedLicenseToken();
6558
+ if (!token) return null;
6559
+ const parts = token.split(".");
6560
+ if (parts.length !== 3) return null;
6561
+ const payload = JSON.parse(Buffer.from(parts[1], "base64url").toString());
6562
+ const plan = payload.plan ?? "free";
6563
+ const limits = PLAN_LIMITS[plan] ?? PLAN_LIMITS.free;
6564
+ process.stderr.write(
6565
+ `[license] WARN: using unverified cached plan (API unreachable, JWT expired). Plan: ${plan}
6566
+ `
6567
+ );
6568
+ return {
6569
+ valid: true,
6570
+ plan,
6571
+ email: payload.sub ?? "",
6572
+ expiresAt: payload.exp ? new Date(payload.exp * 1e3).toISOString() : null,
6573
+ deviceLimit: limits.devices,
6574
+ employeeLimit: limits.employees,
6575
+ memoryLimit: limits.memories
6576
+ };
6577
+ } catch {
6578
+ return null;
6579
+ }
6580
+ }
6581
+ function cacheResponse(token) {
6582
+ try {
6583
+ writeFileSync6(CACHE_PATH, JSON.stringify({ token }), "utf8");
6584
+ } catch {
6585
+ }
6586
+ }
6587
+ function loadPrismaForLicense() {
6588
+ if (_prismaFailed) return null;
6589
+ const dbUrl = process.env.DATABASE_URL;
6590
+ if (!dbUrl) {
6591
+ const exeDbRoot = process.env.EXE_DB_ROOT ?? path11.join(os8.homedir(), "exe-db");
6592
+ if (!existsSync12(path11.join(exeDbRoot, "package.json"))) {
6593
+ _prismaFailed = true;
6594
+ return null;
6595
+ }
6596
+ }
6597
+ if (!_prismaPromise) {
6598
+ _prismaPromise = (async () => {
6599
+ const explicitPath = process.env.EXE_OS_PRISMA_CLIENT_PATH;
6600
+ if (explicitPath) {
6601
+ const mod2 = await import(pathToFileURL2(explicitPath).href);
6602
+ const Ctor2 = mod2.PrismaClient ?? mod2.default?.PrismaClient;
6603
+ if (!Ctor2) throw new Error(`No PrismaClient at ${explicitPath}`);
6604
+ return new Ctor2();
6605
+ }
6606
+ const exeDbRoot = process.env.EXE_DB_ROOT ?? path11.join(os8.homedir(), "exe-db");
6607
+ const req = createRequire2(path11.join(exeDbRoot, "package.json"));
6608
+ const entry = req.resolve("@prisma/client");
6609
+ const mod = await import(pathToFileURL2(entry).href);
6610
+ const Ctor = mod.PrismaClient ?? mod.default?.PrismaClient;
6611
+ if (!Ctor) throw new Error(`No PrismaClient in ${entry}`);
6612
+ return new Ctor();
6613
+ })().catch((err) => {
6614
+ _prismaFailed = true;
6615
+ _prismaPromise = null;
6616
+ throw err;
6617
+ });
6618
+ }
6619
+ return _prismaPromise;
6620
+ }
6621
+ async function validateViaPostgres(apiKey) {
6622
+ const loader = loadPrismaForLicense();
6623
+ if (!loader) return null;
6624
+ try {
6625
+ const prisma = await loader;
6626
+ const rows = await prisma.$queryRawUnsafe(
6627
+ `SELECT plan, email, status, device_limit, employee_limit, memory_limit, expires_at
6628
+ FROM billing.licenses WHERE key = $1 LIMIT 1`,
6629
+ apiKey
6630
+ );
6631
+ if (!rows || rows.length === 0) return null;
6632
+ const row = rows[0];
6633
+ if (row.status !== "active") return null;
6634
+ if (row.expires_at && new Date(row.expires_at) < /* @__PURE__ */ new Date()) return null;
6635
+ const plan = row.plan;
6636
+ const limits = PLAN_LIMITS[plan] ?? PLAN_LIMITS.free;
6637
+ return {
6638
+ valid: true,
6639
+ plan,
6640
+ email: row.email,
6641
+ expiresAt: row.expires_at ? new Date(row.expires_at).toISOString() : null,
6642
+ deviceLimit: row.device_limit ?? limits.devices,
6643
+ employeeLimit: row.employee_limit ?? limits.employees,
6644
+ memoryLimit: row.memory_limit ?? limits.memories
6645
+ };
6646
+ } catch {
6647
+ return null;
6648
+ }
6649
+ }
6650
+ async function validateViaCFWorker(apiKey, deviceId) {
6651
+ try {
6652
+ const res = await fetchRetry(`${API_BASE}/auth/activate`, {
6653
+ method: "POST",
6654
+ headers: { "Content-Type": "application/json" },
6655
+ body: JSON.stringify({ apiKey, deviceId }),
6656
+ signal: AbortSignal.timeout(1e4)
6657
+ });
6658
+ if (!res.ok) return null;
6659
+ const data = await res.json();
6660
+ if (data.error === "device_limit_exceeded") return null;
6661
+ if (!data.valid) return null;
6662
+ if (data.token) {
6663
+ cacheResponse(data.token);
6664
+ const verified = await verifyLicenseJwt(data.token);
6665
+ if (verified) return verified;
6666
+ }
6667
+ const limits = PLAN_LIMITS[data.plan] ?? PLAN_LIMITS.free;
6668
+ return {
6669
+ valid: data.valid,
6670
+ plan: data.plan,
6671
+ email: data.email,
6672
+ expiresAt: data.expiresAt,
6673
+ deviceLimit: limits.devices,
6674
+ employeeLimit: limits.employees,
6675
+ memoryLimit: limits.memories
6676
+ };
6677
+ } catch {
6678
+ return null;
6679
+ }
6680
+ }
6681
+ async function validateLicense(apiKey, deviceId) {
6682
+ const did = deviceId ?? loadDeviceId();
6683
+ const pgResult = await validateViaPostgres(apiKey);
6684
+ if (pgResult) {
6685
+ try {
6686
+ writeFileSync6(CACHE_PATH, JSON.stringify({ pgLicense: pgResult, ts: Date.now() }), "utf8");
6687
+ } catch {
6688
+ }
6689
+ return pgResult;
6690
+ }
6691
+ const cfResult = await validateViaCFWorker(apiKey, did);
6692
+ if (cfResult) return cfResult;
6693
+ const cached = await getCachedLicense();
6694
+ if (cached) return cached;
6695
+ try {
6696
+ if (existsSync12(CACHE_PATH)) {
6697
+ const raw = JSON.parse(readFileSync8(CACHE_PATH, "utf8"));
6698
+ if (raw.pgLicense && raw.ts && Date.now() - raw.ts < 7 * 24 * 60 * 60 * 1e3) {
6699
+ return raw.pgLicense;
6700
+ }
6701
+ }
6702
+ } catch {
6703
+ }
6704
+ const rawFallback = getRawCachedPlan();
6705
+ if (rawFallback) return rawFallback;
6706
+ return { ...FREE_LICENSE, valid: false };
6707
+ }
6708
+ function getCacheAgeMs() {
6709
+ try {
6710
+ const { statSync: statSync5 } = __require("fs");
6711
+ const s = statSync5(CACHE_PATH);
6712
+ return Date.now() - s.mtimeMs;
6713
+ } catch {
6714
+ return Infinity;
6715
+ }
6716
+ }
6717
+ async function checkLicense() {
6718
+ let key = loadLicense();
6719
+ if (!key) {
6720
+ try {
6721
+ const configPath = path11.join(EXE_AI_DIR, "config.json");
6722
+ if (existsSync12(configPath)) {
6723
+ const raw = JSON.parse(readFileSync8(configPath, "utf8"));
6724
+ const cloud = raw.cloud;
6725
+ if (cloud?.apiKey) {
6726
+ key = cloud.apiKey;
6727
+ saveLicense(key);
6728
+ }
6729
+ }
6730
+ } catch {
6731
+ }
6732
+ }
6733
+ if (!key) return FREE_LICENSE;
6734
+ const cached = await getCachedLicense();
6735
+ if (cached && getCacheAgeMs() < CACHE_MAX_AGE_MS) return cached;
6736
+ const deviceId = loadDeviceId();
6737
+ return validateLicense(key, deviceId);
6738
+ }
6739
+ function isFeatureAllowed(license, feature) {
6740
+ switch (feature) {
6741
+ case "cloud_sync":
6742
+ case "external_agents":
6743
+ case "wiki":
6744
+ return license.plan !== "free";
6745
+ case "unlimited_employees":
6746
+ return license.plan === "team" || license.plan === "agency" || license.plan === "enterprise";
6747
+ }
6748
+ }
6749
+ function mirrorLicenseKey(apiKey) {
6750
+ const trimmed = apiKey.trim();
6751
+ if (!trimmed) return;
6752
+ saveLicense(trimmed);
6753
+ }
6754
+ async function assertVpsLicense(opts) {
6755
+ const env = opts?.env ?? process.env;
6756
+ const inProduction = env.NODE_ENV === "production";
6757
+ if (!opts?.force && !inProduction) {
6758
+ return { ...FREE_LICENSE, plan: "free" };
6759
+ }
6760
+ const envKey = env.EXE_LICENSE_KEY?.trim();
6761
+ if (envKey) {
6762
+ saveLicense(envKey);
6763
+ }
6764
+ const apiKey = envKey ?? loadLicense();
6765
+ if (!apiKey) {
6766
+ throw new Error(
6767
+ "License required: set EXE_LICENSE_KEY env var with your exe_sk_* key. Purchase at https://askexe.com. This VPS image refuses to boot without a valid license."
6768
+ );
6769
+ }
6770
+ const deviceId = loadDeviceId();
6771
+ let backendResponse = null;
6772
+ let explicitRejection = false;
6773
+ let transientFailure = false;
6774
+ try {
6775
+ const res = await fetchRetry(`${API_BASE}/auth/activate`, {
6776
+ method: "POST",
6777
+ headers: { "Content-Type": "application/json" },
6778
+ body: JSON.stringify({ apiKey, deviceId }),
6779
+ signal: AbortSignal.timeout(1e4)
6780
+ });
6781
+ if (res.ok) {
6782
+ backendResponse = await res.json();
6783
+ if (!backendResponse.valid) explicitRejection = true;
6784
+ } else if (res.status === 401 || res.status === 403) {
6785
+ explicitRejection = true;
6786
+ } else {
6787
+ transientFailure = true;
6788
+ }
6789
+ } catch {
6790
+ transientFailure = true;
6791
+ }
6792
+ if (backendResponse?.valid) {
6793
+ if (backendResponse.token) {
6794
+ cacheResponse(backendResponse.token);
6795
+ const verified = await verifyLicenseJwt(backendResponse.token);
6796
+ if (verified) return verified;
6797
+ }
6798
+ const limits = PLAN_LIMITS[backendResponse.plan] ?? PLAN_LIMITS.free;
6799
+ return {
6800
+ valid: true,
6801
+ plan: backendResponse.plan,
6802
+ email: backendResponse.email,
6803
+ expiresAt: backendResponse.expiresAt,
6804
+ deviceLimit: limits.devices,
6805
+ employeeLimit: limits.employees,
6806
+ memoryLimit: limits.memories
6807
+ };
6808
+ }
6809
+ if (explicitRejection) {
6810
+ throw new Error(
6811
+ `License invalid or expired. Renew at https://askexe.com, then restart. Backend rejected key ending in ...${apiKey.slice(-4)}.`
6812
+ );
6813
+ }
6814
+ if (!transientFailure) {
6815
+ throw new Error(
6816
+ "License validation failed: unknown backend state. Restore network connectivity to https://askexe.com/cloud and retry."
6817
+ );
6818
+ }
6819
+ const fresh = await getCachedLicense();
6820
+ if (fresh && fresh.valid) return fresh;
6821
+ const graceDays = opts?.offlineGraceDays ?? 7;
6822
+ const graceMs = graceDays * 24 * 60 * 60 * 1e3;
6823
+ try {
6824
+ const token = readCachedLicenseToken();
6825
+ if (token) {
6826
+ const payloadB64 = token.split(".")[1];
6827
+ if (payloadB64) {
6828
+ const payload = JSON.parse(Buffer.from(payloadB64, "base64url").toString());
6829
+ const expMs = (payload.exp ?? 0) * 1e3;
6830
+ if (Date.now() < expMs + graceMs) {
6831
+ const key = await importSPKI(LICENSE_PUBLIC_KEY_PEM, LICENSE_JWT_ALG);
6832
+ const { payload: verified } = await jwtVerify(token, key, {
6833
+ algorithms: [LICENSE_JWT_ALG],
6834
+ clockTolerance: graceDays * 24 * 60 * 60
6835
+ });
6836
+ const plan = verified.plan ?? "free";
6837
+ const limits = PLAN_LIMITS[plan] ?? PLAN_LIMITS.free;
6838
+ return {
6839
+ valid: true,
6840
+ plan,
6841
+ email: verified.sub ?? "",
6842
+ expiresAt: verified.exp ? new Date(verified.exp * 1e3).toISOString() : null,
6843
+ deviceLimit: limits.devices,
6844
+ employeeLimit: limits.employees,
6845
+ memoryLimit: limits.memories
6846
+ };
6847
+ }
6848
+ }
6849
+ }
6850
+ } catch {
6851
+ }
6852
+ throw new Error(
6853
+ `License validation unreachable for more than ${graceDays} days. Restore network connectivity to https://askexe.com/cloud and retry. This VPS image refuses to boot after the offline grace window.`
6854
+ );
6855
+ }
6856
+ function startLicenseRevalidation(intervalMs = 36e5) {
6857
+ if (_revalTimer) return;
6858
+ _revalTimer = setInterval(async () => {
6859
+ try {
6860
+ const license = await checkLicense();
6861
+ if (!license.valid) {
6862
+ process.stderr.write("[exe-os] License expired or invalid \u2014 features may be restricted\n");
6863
+ }
6864
+ } catch {
6865
+ }
6866
+ }, intervalMs);
6867
+ if (_revalTimer && typeof _revalTimer === "object" && "unref" in _revalTimer) {
6868
+ _revalTimer.unref();
6869
+ }
6870
+ }
6871
+ function stopLicenseRevalidation() {
6872
+ if (_revalTimer) {
6873
+ clearInterval(_revalTimer);
6874
+ _revalTimer = null;
6875
+ }
6876
+ }
6877
+ var LICENSE_PATH, CACHE_PATH, DEVICE_ID_PATH, API_BASE, RETRY_DELAY_MS, LICENSE_PUBLIC_KEY_PEM, LICENSE_JWT_ALG, PLAN_LIMITS, FREE_LICENSE, _prismaPromise, _prismaFailed, CACHE_MAX_AGE_MS, _revalTimer;
6450
6878
  var init_license = __esm({
6451
6879
  "src/lib/license.ts"() {
6452
6880
  "use strict";
@@ -6455,6 +6883,12 @@ var init_license = __esm({
6455
6883
  CACHE_PATH = path11.join(EXE_AI_DIR, "license-cache.json");
6456
6884
  DEVICE_ID_PATH = path11.join(EXE_AI_DIR, "device-id");
6457
6885
  API_BASE = process.env.EXE_CLOUD_ENDPOINT ?? "https://askexe.com/cloud";
6886
+ RETRY_DELAY_MS = 500;
6887
+ LICENSE_PUBLIC_KEY_PEM = `-----BEGIN PUBLIC KEY-----
6888
+ MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEeHztAMOpR/ZMh+rWuOASjEZ54CGY
6889
+ 4uj+UqeKCcvtgNHKmOK278HJaJcANe9xAeji8AFYu27q3WtzCi04pHudow==
6890
+ -----END PUBLIC KEY-----`;
6891
+ LICENSE_JWT_ALG = "ES256";
6458
6892
  PLAN_LIMITS = {
6459
6893
  free: { devices: 1, employees: 1, memories: 5e3 },
6460
6894
  pro: { devices: 3, employees: 5, memories: 1e5 },
@@ -6462,6 +6896,19 @@ var init_license = __esm({
6462
6896
  agency: { devices: 50, employees: 100, memories: 1e7 },
6463
6897
  enterprise: { devices: -1, employees: -1, memories: -1 }
6464
6898
  };
6899
+ FREE_LICENSE = {
6900
+ valid: true,
6901
+ plan: "free",
6902
+ email: "",
6903
+ expiresAt: null,
6904
+ deviceLimit: 1,
6905
+ employeeLimit: 1,
6906
+ memoryLimit: 5e3
6907
+ };
6908
+ _prismaPromise = null;
6909
+ _prismaFailed = false;
6910
+ CACHE_MAX_AGE_MS = 36e5;
6911
+ _revalTimer = null;
6465
6912
  }
6466
6913
  });
6467
6914
 
@@ -7619,10 +8066,18 @@ async function storeBehavior(opts) {
7619
8066
  vector = new Float32Array(vec);
7620
8067
  } catch {
7621
8068
  }
8069
+ let createdByDevice = null;
8070
+ try {
8071
+ const { loadDeviceId: loadDeviceId2 } = await Promise.resolve().then(() => (init_license(), license_exports));
8072
+ createdByDevice = loadDeviceId2() ?? null;
8073
+ } catch {
8074
+ }
8075
+ const createdByAgent = process.env.AGENT_ID ?? null;
8076
+ const sourceSessionId = process.env.CLAUDE_SESSION_ID ?? process.env.SESSION_ID ?? null;
7622
8077
  await client.execute({
7623
- sql: `INSERT INTO behaviors (id, agent_id, project_name, domain, priority, content, active, created_at, updated_at, vector)
7624
- VALUES (?, ?, ?, ?, ?, ?, 1, ?, ?, ?)`,
7625
- args: [id, opts.agentId, opts.projectName ?? null, opts.domain ?? null, opts.priority ?? "p1", opts.content, now, now, vector ? vector.buffer : null]
8078
+ sql: `INSERT INTO behaviors (id, agent_id, project_name, domain, priority, content, active, created_at, updated_at, vector, created_by_agent, created_by_device, source_session_id)
8079
+ VALUES (?, ?, ?, ?, ?, ?, 1, ?, ?, ?, ?, ?, ?)`,
8080
+ args: [id, opts.agentId, opts.projectName ?? null, opts.domain ?? null, opts.priority ?? "p1", opts.content, now, now, vector ? vector.buffer : null, createdByAgent, createdByDevice, sourceSessionId]
7626
8081
  });
7627
8082
  return id;
7628
8083
  }
@@ -323,7 +323,7 @@ var PLATFORM_PROCEDURES = [
323
323
  title: "MCP tool dispatch \u2014 all tools use action parameter",
324
324
  domain: "tool-use",
325
325
  priority: "p0",
326
- content: 'exe-os MCP tools come in two surfaces depending on EXE_MCP_TOOL_SURFACE config. Consolidated (19 tools): action-based dispatch \u2014 memory(action="recall"), task(action="create"), etc. Legacy (108 tools): one tool per operation \u2014 recall_my_memory, create_task, etc. Both surfaces have identical functionality. Use whichever tool names are available in your session. If you see domain tools (memory, task, config, etc.), use the action parameter. If you see specific tools (recall_my_memory, create_task, etc.), call them directly.'
326
+ content: 'exe-os MCP tools use consolidated action-based dispatch by default (19 tools). Call domain tools with an action parameter: memory(action="recall"), task(action="create"), config(action="list_employees"), etc. Legacy mode (108 separate tools like recall_my_memory, create_task) is still available via EXE_MCP_TOOL_SURFACE=legacy but will be removed in a future version. If you see specific tool names, call them directly \u2014 both surfaces are identical. Consolidated is the default and recommended surface.'
327
327
  },
328
328
  {
329
329
  title: "MCP tools \u2014 memory, decision, and search",