@askexenow/exe-os 0.9.110 → 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
@@ -2681,6 +2681,13 @@ async function ensureSchema() {
2681
2681
  } catch (e) {
2682
2682
  logCatchDebug("migration", e);
2683
2683
  }
2684
+ for (const col of ["created_by_agent TEXT", "created_by_device TEXT", "source_session_id TEXT"]) {
2685
+ try {
2686
+ await client.execute({ sql: `ALTER TABLE behaviors ADD COLUMN ${col}`, args: [] });
2687
+ } catch (e) {
2688
+ logCatchDebug("migration", e);
2689
+ }
2690
+ }
2684
2691
  try {
2685
2692
  await client.execute({
2686
2693
  sql: `ALTER TABLE tasks ADD COLUMN blocked_by TEXT`,
@@ -5222,7 +5229,7 @@ var init_platform_procedures = __esm({
5222
5229
  title: "MCP tool dispatch \u2014 all tools use action parameter",
5223
5230
  domain: "tool-use",
5224
5231
  priority: "p0",
5225
- 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.'
5232
+ 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.'
5226
5233
  },
5227
5234
  {
5228
5235
  title: "MCP tools \u2014 memory, decision, and search",
@@ -8048,6 +8055,23 @@ var init_intercom_queue = __esm({
8048
8055
  });
8049
8056
 
8050
8057
  // src/lib/license.ts
8058
+ var license_exports = {};
8059
+ __export(license_exports, {
8060
+ LICENSE_PUBLIC_KEY_PEM: () => LICENSE_PUBLIC_KEY_PEM,
8061
+ PLAN_LIMITS: () => PLAN_LIMITS,
8062
+ assertVpsLicense: () => assertVpsLicense,
8063
+ checkLicense: () => checkLicense,
8064
+ getCachedLicense: () => getCachedLicense,
8065
+ isFeatureAllowed: () => isFeatureAllowed,
8066
+ loadDeviceId: () => loadDeviceId,
8067
+ loadLicense: () => loadLicense,
8068
+ mirrorLicenseKey: () => mirrorLicenseKey,
8069
+ readCachedLicenseToken: () => readCachedLicenseToken,
8070
+ saveLicense: () => saveLicense,
8071
+ startLicenseRevalidation: () => startLicenseRevalidation,
8072
+ stopLicenseRevalidation: () => stopLicenseRevalidation,
8073
+ validateLicense: () => validateLicense
8074
+ });
8051
8075
  import { readFileSync as readFileSync9, writeFileSync as writeFileSync6, existsSync as existsSync12, mkdirSync as mkdirSync7 } from "fs";
8052
8076
  import { randomUUID as randomUUID11 } from "crypto";
8053
8077
  import { createRequire as createRequire2 } from "module";
@@ -8055,7 +8079,411 @@ import { pathToFileURL as pathToFileURL2 } from "url";
8055
8079
  import os9 from "os";
8056
8080
  import path12 from "path";
8057
8081
  import { jwtVerify, importSPKI } from "jose";
8058
- var LICENSE_PATH, CACHE_PATH, DEVICE_ID_PATH, API_BASE, PLAN_LIMITS;
8082
+ async function fetchRetry(url, init) {
8083
+ try {
8084
+ return await fetch(url, init);
8085
+ } catch {
8086
+ await new Promise((r) => setTimeout(r, RETRY_DELAY_MS));
8087
+ return fetch(url, { ...init, signal: AbortSignal.timeout(1e4) });
8088
+ }
8089
+ }
8090
+ function loadDeviceId() {
8091
+ const deviceJsonPath = path12.join(EXE_AI_DIR, "device.json");
8092
+ try {
8093
+ if (existsSync12(deviceJsonPath)) {
8094
+ const data = JSON.parse(readFileSync9(deviceJsonPath, "utf8"));
8095
+ if (data.deviceId) return data.deviceId;
8096
+ }
8097
+ } catch {
8098
+ }
8099
+ try {
8100
+ if (existsSync12(DEVICE_ID_PATH)) {
8101
+ const id2 = readFileSync9(DEVICE_ID_PATH, "utf8").trim();
8102
+ if (id2) return id2;
8103
+ }
8104
+ } catch {
8105
+ }
8106
+ const id = randomUUID11();
8107
+ mkdirSync7(EXE_AI_DIR, { recursive: true });
8108
+ writeFileSync6(DEVICE_ID_PATH, id, "utf8");
8109
+ return id;
8110
+ }
8111
+ function loadLicense() {
8112
+ try {
8113
+ if (!existsSync12(LICENSE_PATH)) return null;
8114
+ return readFileSync9(LICENSE_PATH, "utf8").trim();
8115
+ } catch {
8116
+ return null;
8117
+ }
8118
+ }
8119
+ function saveLicense(apiKey) {
8120
+ mkdirSync7(EXE_AI_DIR, { recursive: true });
8121
+ writeFileSync6(LICENSE_PATH, apiKey.trim(), { encoding: "utf8", mode: 384 });
8122
+ }
8123
+ async function verifyLicenseJwt(token) {
8124
+ try {
8125
+ const key = await importSPKI(LICENSE_PUBLIC_KEY_PEM, LICENSE_JWT_ALG);
8126
+ const { payload } = await jwtVerify(token, key, {
8127
+ algorithms: [LICENSE_JWT_ALG]
8128
+ });
8129
+ const plan = payload.plan ?? "free";
8130
+ const email = payload.sub ?? "";
8131
+ const limits = PLAN_LIMITS[plan] ?? PLAN_LIMITS.free;
8132
+ return {
8133
+ valid: true,
8134
+ plan,
8135
+ email,
8136
+ expiresAt: payload.exp ? new Date(payload.exp * 1e3).toISOString() : null,
8137
+ deviceLimit: limits.devices,
8138
+ employeeLimit: limits.employees,
8139
+ memoryLimit: limits.memories
8140
+ };
8141
+ } catch {
8142
+ return null;
8143
+ }
8144
+ }
8145
+ async function getCachedLicense() {
8146
+ try {
8147
+ if (!existsSync12(CACHE_PATH)) return null;
8148
+ const raw = JSON.parse(readFileSync9(CACHE_PATH, "utf8"));
8149
+ if (!raw.token || typeof raw.token !== "string") return null;
8150
+ return await verifyLicenseJwt(raw.token);
8151
+ } catch {
8152
+ return null;
8153
+ }
8154
+ }
8155
+ function readCachedLicenseToken() {
8156
+ try {
8157
+ if (!existsSync12(CACHE_PATH)) return null;
8158
+ const raw = JSON.parse(readFileSync9(CACHE_PATH, "utf8"));
8159
+ return typeof raw.token === "string" ? raw.token : null;
8160
+ } catch {
8161
+ return null;
8162
+ }
8163
+ }
8164
+ function getRawCachedPlan() {
8165
+ try {
8166
+ const token = readCachedLicenseToken();
8167
+ if (!token) return null;
8168
+ const parts = token.split(".");
8169
+ if (parts.length !== 3) return null;
8170
+ const payload = JSON.parse(Buffer.from(parts[1], "base64url").toString());
8171
+ const plan = payload.plan ?? "free";
8172
+ const limits = PLAN_LIMITS[plan] ?? PLAN_LIMITS.free;
8173
+ process.stderr.write(
8174
+ `[license] WARN: using unverified cached plan (API unreachable, JWT expired). Plan: ${plan}
8175
+ `
8176
+ );
8177
+ return {
8178
+ valid: true,
8179
+ plan,
8180
+ email: payload.sub ?? "",
8181
+ expiresAt: payload.exp ? new Date(payload.exp * 1e3).toISOString() : null,
8182
+ deviceLimit: limits.devices,
8183
+ employeeLimit: limits.employees,
8184
+ memoryLimit: limits.memories
8185
+ };
8186
+ } catch {
8187
+ return null;
8188
+ }
8189
+ }
8190
+ function cacheResponse(token) {
8191
+ try {
8192
+ writeFileSync6(CACHE_PATH, JSON.stringify({ token }), "utf8");
8193
+ } catch {
8194
+ }
8195
+ }
8196
+ function loadPrismaForLicense() {
8197
+ if (_prismaFailed) return null;
8198
+ const dbUrl = process.env.DATABASE_URL;
8199
+ if (!dbUrl) {
8200
+ const exeDbRoot = process.env.EXE_DB_ROOT ?? path12.join(os9.homedir(), "exe-db");
8201
+ if (!existsSync12(path12.join(exeDbRoot, "package.json"))) {
8202
+ _prismaFailed = true;
8203
+ return null;
8204
+ }
8205
+ }
8206
+ if (!_prismaPromise) {
8207
+ _prismaPromise = (async () => {
8208
+ const explicitPath = process.env.EXE_OS_PRISMA_CLIENT_PATH;
8209
+ if (explicitPath) {
8210
+ const mod2 = await import(pathToFileURL2(explicitPath).href);
8211
+ const Ctor2 = mod2.PrismaClient ?? mod2.default?.PrismaClient;
8212
+ if (!Ctor2) throw new Error(`No PrismaClient at ${explicitPath}`);
8213
+ return new Ctor2();
8214
+ }
8215
+ const exeDbRoot = process.env.EXE_DB_ROOT ?? path12.join(os9.homedir(), "exe-db");
8216
+ const req = createRequire2(path12.join(exeDbRoot, "package.json"));
8217
+ const entry = req.resolve("@prisma/client");
8218
+ const mod = await import(pathToFileURL2(entry).href);
8219
+ const Ctor = mod.PrismaClient ?? mod.default?.PrismaClient;
8220
+ if (!Ctor) throw new Error(`No PrismaClient in ${entry}`);
8221
+ return new Ctor();
8222
+ })().catch((err) => {
8223
+ _prismaFailed = true;
8224
+ _prismaPromise = null;
8225
+ throw err;
8226
+ });
8227
+ }
8228
+ return _prismaPromise;
8229
+ }
8230
+ async function validateViaPostgres(apiKey) {
8231
+ const loader = loadPrismaForLicense();
8232
+ if (!loader) return null;
8233
+ try {
8234
+ const prisma = await loader;
8235
+ const rows = await prisma.$queryRawUnsafe(
8236
+ `SELECT plan, email, status, device_limit, employee_limit, memory_limit, expires_at
8237
+ FROM billing.licenses WHERE key = $1 LIMIT 1`,
8238
+ apiKey
8239
+ );
8240
+ if (!rows || rows.length === 0) return null;
8241
+ const row = rows[0];
8242
+ if (row.status !== "active") return null;
8243
+ if (row.expires_at && new Date(row.expires_at) < /* @__PURE__ */ new Date()) return null;
8244
+ const plan = row.plan;
8245
+ const limits = PLAN_LIMITS[plan] ?? PLAN_LIMITS.free;
8246
+ return {
8247
+ valid: true,
8248
+ plan,
8249
+ email: row.email,
8250
+ expiresAt: row.expires_at ? new Date(row.expires_at).toISOString() : null,
8251
+ deviceLimit: row.device_limit ?? limits.devices,
8252
+ employeeLimit: row.employee_limit ?? limits.employees,
8253
+ memoryLimit: row.memory_limit ?? limits.memories
8254
+ };
8255
+ } catch {
8256
+ return null;
8257
+ }
8258
+ }
8259
+ async function validateViaCFWorker(apiKey, deviceId) {
8260
+ try {
8261
+ const res = await fetchRetry(`${API_BASE}/auth/activate`, {
8262
+ method: "POST",
8263
+ headers: { "Content-Type": "application/json" },
8264
+ body: JSON.stringify({ apiKey, deviceId }),
8265
+ signal: AbortSignal.timeout(1e4)
8266
+ });
8267
+ if (!res.ok) return null;
8268
+ const data = await res.json();
8269
+ if (data.error === "device_limit_exceeded") return null;
8270
+ if (!data.valid) return null;
8271
+ if (data.token) {
8272
+ cacheResponse(data.token);
8273
+ const verified = await verifyLicenseJwt(data.token);
8274
+ if (verified) return verified;
8275
+ }
8276
+ const limits = PLAN_LIMITS[data.plan] ?? PLAN_LIMITS.free;
8277
+ return {
8278
+ valid: data.valid,
8279
+ plan: data.plan,
8280
+ email: data.email,
8281
+ expiresAt: data.expiresAt,
8282
+ deviceLimit: limits.devices,
8283
+ employeeLimit: limits.employees,
8284
+ memoryLimit: limits.memories
8285
+ };
8286
+ } catch {
8287
+ return null;
8288
+ }
8289
+ }
8290
+ async function validateLicense(apiKey, deviceId) {
8291
+ const did = deviceId ?? loadDeviceId();
8292
+ const pgResult = await validateViaPostgres(apiKey);
8293
+ if (pgResult) {
8294
+ try {
8295
+ writeFileSync6(CACHE_PATH, JSON.stringify({ pgLicense: pgResult, ts: Date.now() }), "utf8");
8296
+ } catch {
8297
+ }
8298
+ return pgResult;
8299
+ }
8300
+ const cfResult = await validateViaCFWorker(apiKey, did);
8301
+ if (cfResult) return cfResult;
8302
+ const cached = await getCachedLicense();
8303
+ if (cached) return cached;
8304
+ try {
8305
+ if (existsSync12(CACHE_PATH)) {
8306
+ const raw = JSON.parse(readFileSync9(CACHE_PATH, "utf8"));
8307
+ if (raw.pgLicense && raw.ts && Date.now() - raw.ts < 7 * 24 * 60 * 60 * 1e3) {
8308
+ return raw.pgLicense;
8309
+ }
8310
+ }
8311
+ } catch {
8312
+ }
8313
+ const rawFallback = getRawCachedPlan();
8314
+ if (rawFallback) return rawFallback;
8315
+ return { ...FREE_LICENSE, valid: false };
8316
+ }
8317
+ function getCacheAgeMs() {
8318
+ try {
8319
+ const { statSync: statSync5 } = __require("fs");
8320
+ const s = statSync5(CACHE_PATH);
8321
+ return Date.now() - s.mtimeMs;
8322
+ } catch {
8323
+ return Infinity;
8324
+ }
8325
+ }
8326
+ async function checkLicense() {
8327
+ let key = loadLicense();
8328
+ if (!key) {
8329
+ try {
8330
+ const configPath = path12.join(EXE_AI_DIR, "config.json");
8331
+ if (existsSync12(configPath)) {
8332
+ const raw = JSON.parse(readFileSync9(configPath, "utf8"));
8333
+ const cloud = raw.cloud;
8334
+ if (cloud?.apiKey) {
8335
+ key = cloud.apiKey;
8336
+ saveLicense(key);
8337
+ }
8338
+ }
8339
+ } catch {
8340
+ }
8341
+ }
8342
+ if (!key) return FREE_LICENSE;
8343
+ const cached = await getCachedLicense();
8344
+ if (cached && getCacheAgeMs() < CACHE_MAX_AGE_MS) return cached;
8345
+ const deviceId = loadDeviceId();
8346
+ return validateLicense(key, deviceId);
8347
+ }
8348
+ function isFeatureAllowed(license, feature) {
8349
+ switch (feature) {
8350
+ case "cloud_sync":
8351
+ case "external_agents":
8352
+ case "wiki":
8353
+ return license.plan !== "free";
8354
+ case "unlimited_employees":
8355
+ return license.plan === "team" || license.plan === "agency" || license.plan === "enterprise";
8356
+ }
8357
+ }
8358
+ function mirrorLicenseKey(apiKey) {
8359
+ const trimmed = apiKey.trim();
8360
+ if (!trimmed) return;
8361
+ saveLicense(trimmed);
8362
+ }
8363
+ async function assertVpsLicense(opts) {
8364
+ const env = opts?.env ?? process.env;
8365
+ const inProduction = env.NODE_ENV === "production";
8366
+ if (!opts?.force && !inProduction) {
8367
+ return { ...FREE_LICENSE, plan: "free" };
8368
+ }
8369
+ const envKey = env.EXE_LICENSE_KEY?.trim();
8370
+ if (envKey) {
8371
+ saveLicense(envKey);
8372
+ }
8373
+ const apiKey = envKey ?? loadLicense();
8374
+ if (!apiKey) {
8375
+ throw new Error(
8376
+ "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."
8377
+ );
8378
+ }
8379
+ const deviceId = loadDeviceId();
8380
+ let backendResponse = null;
8381
+ let explicitRejection = false;
8382
+ let transientFailure = false;
8383
+ try {
8384
+ const res = await fetchRetry(`${API_BASE}/auth/activate`, {
8385
+ method: "POST",
8386
+ headers: { "Content-Type": "application/json" },
8387
+ body: JSON.stringify({ apiKey, deviceId }),
8388
+ signal: AbortSignal.timeout(1e4)
8389
+ });
8390
+ if (res.ok) {
8391
+ backendResponse = await res.json();
8392
+ if (!backendResponse.valid) explicitRejection = true;
8393
+ } else if (res.status === 401 || res.status === 403) {
8394
+ explicitRejection = true;
8395
+ } else {
8396
+ transientFailure = true;
8397
+ }
8398
+ } catch {
8399
+ transientFailure = true;
8400
+ }
8401
+ if (backendResponse?.valid) {
8402
+ if (backendResponse.token) {
8403
+ cacheResponse(backendResponse.token);
8404
+ const verified = await verifyLicenseJwt(backendResponse.token);
8405
+ if (verified) return verified;
8406
+ }
8407
+ const limits = PLAN_LIMITS[backendResponse.plan] ?? PLAN_LIMITS.free;
8408
+ return {
8409
+ valid: true,
8410
+ plan: backendResponse.plan,
8411
+ email: backendResponse.email,
8412
+ expiresAt: backendResponse.expiresAt,
8413
+ deviceLimit: limits.devices,
8414
+ employeeLimit: limits.employees,
8415
+ memoryLimit: limits.memories
8416
+ };
8417
+ }
8418
+ if (explicitRejection) {
8419
+ throw new Error(
8420
+ `License invalid or expired. Renew at https://askexe.com, then restart. Backend rejected key ending in ...${apiKey.slice(-4)}.`
8421
+ );
8422
+ }
8423
+ if (!transientFailure) {
8424
+ throw new Error(
8425
+ "License validation failed: unknown backend state. Restore network connectivity to https://askexe.com/cloud and retry."
8426
+ );
8427
+ }
8428
+ const fresh = await getCachedLicense();
8429
+ if (fresh && fresh.valid) return fresh;
8430
+ const graceDays = opts?.offlineGraceDays ?? 7;
8431
+ const graceMs = graceDays * 24 * 60 * 60 * 1e3;
8432
+ try {
8433
+ const token = readCachedLicenseToken();
8434
+ if (token) {
8435
+ const payloadB64 = token.split(".")[1];
8436
+ if (payloadB64) {
8437
+ const payload = JSON.parse(Buffer.from(payloadB64, "base64url").toString());
8438
+ const expMs = (payload.exp ?? 0) * 1e3;
8439
+ if (Date.now() < expMs + graceMs) {
8440
+ const key = await importSPKI(LICENSE_PUBLIC_KEY_PEM, LICENSE_JWT_ALG);
8441
+ const { payload: verified } = await jwtVerify(token, key, {
8442
+ algorithms: [LICENSE_JWT_ALG],
8443
+ clockTolerance: graceDays * 24 * 60 * 60
8444
+ });
8445
+ const plan = verified.plan ?? "free";
8446
+ const limits = PLAN_LIMITS[plan] ?? PLAN_LIMITS.free;
8447
+ return {
8448
+ valid: true,
8449
+ plan,
8450
+ email: verified.sub ?? "",
8451
+ expiresAt: verified.exp ? new Date(verified.exp * 1e3).toISOString() : null,
8452
+ deviceLimit: limits.devices,
8453
+ employeeLimit: limits.employees,
8454
+ memoryLimit: limits.memories
8455
+ };
8456
+ }
8457
+ }
8458
+ }
8459
+ } catch {
8460
+ }
8461
+ throw new Error(
8462
+ `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.`
8463
+ );
8464
+ }
8465
+ function startLicenseRevalidation(intervalMs = 36e5) {
8466
+ if (_revalTimer) return;
8467
+ _revalTimer = setInterval(async () => {
8468
+ try {
8469
+ const license = await checkLicense();
8470
+ if (!license.valid) {
8471
+ process.stderr.write("[exe-os] License expired or invalid \u2014 features may be restricted\n");
8472
+ }
8473
+ } catch {
8474
+ }
8475
+ }, intervalMs);
8476
+ if (_revalTimer && typeof _revalTimer === "object" && "unref" in _revalTimer) {
8477
+ _revalTimer.unref();
8478
+ }
8479
+ }
8480
+ function stopLicenseRevalidation() {
8481
+ if (_revalTimer) {
8482
+ clearInterval(_revalTimer);
8483
+ _revalTimer = null;
8484
+ }
8485
+ }
8486
+ 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;
8059
8487
  var init_license = __esm({
8060
8488
  "src/lib/license.ts"() {
8061
8489
  "use strict";
@@ -8064,6 +8492,12 @@ var init_license = __esm({
8064
8492
  CACHE_PATH = path12.join(EXE_AI_DIR, "license-cache.json");
8065
8493
  DEVICE_ID_PATH = path12.join(EXE_AI_DIR, "device-id");
8066
8494
  API_BASE = process.env.EXE_CLOUD_ENDPOINT ?? "https://askexe.com/cloud";
8495
+ RETRY_DELAY_MS = 500;
8496
+ LICENSE_PUBLIC_KEY_PEM = `-----BEGIN PUBLIC KEY-----
8497
+ MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEeHztAMOpR/ZMh+rWuOASjEZ54CGY
8498
+ 4uj+UqeKCcvtgNHKmOK278HJaJcANe9xAeji8AFYu27q3WtzCi04pHudow==
8499
+ -----END PUBLIC KEY-----`;
8500
+ LICENSE_JWT_ALG = "ES256";
8067
8501
  PLAN_LIMITS = {
8068
8502
  free: { devices: 1, employees: 1, memories: 5e3 },
8069
8503
  pro: { devices: 3, employees: 5, memories: 1e5 },
@@ -8071,6 +8505,19 @@ var init_license = __esm({
8071
8505
  agency: { devices: 50, employees: 100, memories: 1e7 },
8072
8506
  enterprise: { devices: -1, employees: -1, memories: -1 }
8073
8507
  };
8508
+ FREE_LICENSE = {
8509
+ valid: true,
8510
+ plan: "free",
8511
+ email: "",
8512
+ expiresAt: null,
8513
+ deviceLimit: 1,
8514
+ employeeLimit: 1,
8515
+ memoryLimit: 5e3
8516
+ };
8517
+ _prismaPromise = null;
8518
+ _prismaFailed = false;
8519
+ CACHE_MAX_AGE_MS = 36e5;
8520
+ _revalTimer = null;
8074
8521
  }
8075
8522
  });
8076
8523
 
@@ -9549,10 +9996,18 @@ async function storeBehavior(opts) {
9549
9996
  vector = new Float32Array(vec);
9550
9997
  } catch {
9551
9998
  }
9999
+ let createdByDevice = null;
10000
+ try {
10001
+ const { loadDeviceId: loadDeviceId2 } = await Promise.resolve().then(() => (init_license(), license_exports));
10002
+ createdByDevice = loadDeviceId2() ?? null;
10003
+ } catch {
10004
+ }
10005
+ const createdByAgent = process.env.AGENT_ID ?? null;
10006
+ const sourceSessionId = process.env.CLAUDE_SESSION_ID ?? process.env.SESSION_ID ?? null;
9552
10007
  await client.execute({
9553
- sql: `INSERT INTO behaviors (id, agent_id, project_name, domain, priority, content, active, created_at, updated_at, vector)
9554
- VALUES (?, ?, ?, ?, ?, ?, 1, ?, ?, ?)`,
9555
- args: [id, opts.agentId, opts.projectName ?? null, opts.domain ?? null, opts.priority ?? "p1", opts.content, now, now, vector ? vector.buffer : null]
10008
+ 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)
10009
+ VALUES (?, ?, ?, ?, ?, ?, 1, ?, ?, ?, ?, ?, ?)`,
10010
+ args: [id, opts.agentId, opts.projectName ?? null, opts.domain ?? null, opts.priority ?? "p1", opts.content, now, now, vector ? vector.buffer : null, createdByAgent, createdByDevice, sourceSessionId]
9556
10011
  });
9557
10012
  return id;
9558
10013
  }