@askexenow/exe-os 0.8.1 → 0.8.2

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 (106) hide show
  1. package/package.json +1 -1
  2. package/dist/bin/backfill-responses.js +0 -2064
  3. package/dist/bin/backfill-vectors.js +0 -1771
  4. package/dist/bin/cleanup-stale-review-tasks.js +0 -1468
  5. package/dist/bin/cli.js +0 -21371
  6. package/dist/bin/exe-agent.js +0 -2016
  7. package/dist/bin/exe-assign.js +0 -2176
  8. package/dist/bin/exe-boot.js +0 -6332
  9. package/dist/bin/exe-call.js +0 -341
  10. package/dist/bin/exe-cloud.js +0 -861
  11. package/dist/bin/exe-dispatch.js +0 -1159
  12. package/dist/bin/exe-doctor.js +0 -1786
  13. package/dist/bin/exe-export-behaviors.js +0 -1637
  14. package/dist/bin/exe-forget.js +0 -1784
  15. package/dist/bin/exe-gateway.js +0 -8140
  16. package/dist/bin/exe-healthcheck.js +0 -207
  17. package/dist/bin/exe-heartbeat.js +0 -1778
  18. package/dist/bin/exe-kill.js +0 -1622
  19. package/dist/bin/exe-launch-agent.js +0 -1847
  20. package/dist/bin/exe-link.js +0 -192
  21. package/dist/bin/exe-new-employee.js +0 -1384
  22. package/dist/bin/exe-pending-messages.js +0 -1576
  23. package/dist/bin/exe-pending-notifications.js +0 -1450
  24. package/dist/bin/exe-pending-reviews.js +0 -1598
  25. package/dist/bin/exe-repo-drift.js +0 -95
  26. package/dist/bin/exe-review.js +0 -1742
  27. package/dist/bin/exe-search.js +0 -3116
  28. package/dist/bin/exe-session-cleanup.js +0 -3360
  29. package/dist/bin/exe-settings.js +0 -365
  30. package/dist/bin/exe-status.js +0 -1661
  31. package/dist/bin/exe-team.js +0 -1453
  32. package/dist/bin/git-sweep.js +0 -2441
  33. package/dist/bin/graph-backfill.js +0 -2111
  34. package/dist/bin/graph-export.js +0 -1747
  35. package/dist/bin/install.js +0 -661
  36. package/dist/bin/list-providers.js +0 -140
  37. package/dist/bin/scan-tasks.js +0 -2039
  38. package/dist/bin/setup.js +0 -2717
  39. package/dist/bin/shard-migrate.js +0 -1637
  40. package/dist/bin/update.js +0 -98
  41. package/dist/bin/wiki-sync.js +0 -1657
  42. package/dist/gateway/index.js +0 -9256
  43. package/dist/hooks/bug-report-worker.js +0 -2903
  44. package/dist/hooks/commit-complete.js +0 -2364
  45. package/dist/hooks/error-recall.js +0 -3327
  46. package/dist/hooks/exe-heartbeat-hook.js +0 -237
  47. package/dist/hooks/ingest-worker.js +0 -5065
  48. package/dist/hooks/ingest.js +0 -695
  49. package/dist/hooks/instructions-loaded.js +0 -2069
  50. package/dist/hooks/notification.js +0 -1915
  51. package/dist/hooks/post-compact.js +0 -1940
  52. package/dist/hooks/pre-compact.js +0 -1935
  53. package/dist/hooks/pre-tool-use.js +0 -2380
  54. package/dist/hooks/prompt-ingest-worker.js +0 -2291
  55. package/dist/hooks/prompt-submit.js +0 -5189
  56. package/dist/hooks/response-ingest-worker.js +0 -2431
  57. package/dist/hooks/session-end.js +0 -2196
  58. package/dist/hooks/session-start.js +0 -3259
  59. package/dist/hooks/stop.js +0 -2025
  60. package/dist/hooks/subagent-stop.js +0 -1915
  61. package/dist/hooks/summary-worker.js +0 -2931
  62. package/dist/index.js +0 -12327
  63. package/dist/lib/cloud-sync.js +0 -500
  64. package/dist/lib/config.js +0 -235
  65. package/dist/lib/consolidation.js +0 -481
  66. package/dist/lib/crypto.js +0 -51
  67. package/dist/lib/database.js +0 -834
  68. package/dist/lib/device-registry.js +0 -1009
  69. package/dist/lib/embedder.js +0 -645
  70. package/dist/lib/employee-templates.js +0 -570
  71. package/dist/lib/employees.js +0 -182
  72. package/dist/lib/error-detector.js +0 -156
  73. package/dist/lib/exe-daemon-client.js +0 -456
  74. package/dist/lib/exe-daemon.js +0 -8699
  75. package/dist/lib/file-grep.js +0 -215
  76. package/dist/lib/hybrid-search.js +0 -3064
  77. package/dist/lib/identity-templates.js +0 -441
  78. package/dist/lib/identity.js +0 -228
  79. package/dist/lib/keychain.js +0 -145
  80. package/dist/lib/license.js +0 -382
  81. package/dist/lib/messaging.js +0 -1389
  82. package/dist/lib/reminders.js +0 -63
  83. package/dist/lib/schedules.js +0 -1525
  84. package/dist/lib/session-registry.js +0 -52
  85. package/dist/lib/skill-learning.js +0 -488
  86. package/dist/lib/status-brief.js +0 -240
  87. package/dist/lib/store.js +0 -1740
  88. package/dist/lib/task-router.js +0 -128
  89. package/dist/lib/tasks.js +0 -2585
  90. package/dist/lib/tmux-routing.js +0 -2969
  91. package/dist/lib/tmux-status.js +0 -261
  92. package/dist/lib/tmux-transport.js +0 -83
  93. package/dist/lib/transport.js +0 -128
  94. package/dist/lib/ws-auth.js +0 -19
  95. package/dist/lib/ws-client.js +0 -160
  96. package/dist/mcp/server.js +0 -10812
  97. package/dist/mcp/tools/complete-reminder.js +0 -67
  98. package/dist/mcp/tools/create-reminder.js +0 -52
  99. package/dist/mcp/tools/create-task.js +0 -1903
  100. package/dist/mcp/tools/deactivate-behavior.js +0 -268
  101. package/dist/mcp/tools/list-reminders.js +0 -62
  102. package/dist/mcp/tools/list-tasks.js +0 -491
  103. package/dist/mcp/tools/send-message.js +0 -1395
  104. package/dist/mcp/tools/update-task.js +0 -1807
  105. package/dist/runtime/index.js +0 -7201
  106. package/dist/tui/App.js +0 -17874
@@ -1,145 +0,0 @@
1
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
- }) : x)(function(x) {
4
- if (typeof require !== "undefined") return require.apply(this, arguments);
5
- throw Error('Dynamic require of "' + x + '" is not supported');
6
- });
7
-
8
- // src/lib/keychain.ts
9
- import { readFile, writeFile, unlink, mkdir, chmod } from "fs/promises";
10
- import { existsSync } from "fs";
11
- import path from "path";
12
- import crypto from "crypto";
13
- var SERVICE = "exe-mem";
14
- var ACCOUNT = "master-key";
15
- function getKeyDir() {
16
- return process.env.EXE_OS_DIR ?? process.env.EXE_MEM_DIR ?? path.join(process.env.HOME ?? "/tmp", ".exe-os");
17
- }
18
- function getKeyPath() {
19
- return path.join(getKeyDir(), "master.key");
20
- }
21
- async function tryKeytar() {
22
- try {
23
- return await import("keytar");
24
- } catch {
25
- return null;
26
- }
27
- }
28
- async function getMasterKey() {
29
- const keytar = await tryKeytar();
30
- if (keytar) {
31
- try {
32
- const stored = await keytar.getPassword(SERVICE, ACCOUNT);
33
- if (stored) {
34
- return Buffer.from(stored, "base64");
35
- }
36
- } catch {
37
- }
38
- }
39
- const keyPath = getKeyPath();
40
- if (!existsSync(keyPath)) {
41
- return null;
42
- }
43
- try {
44
- const content = await readFile(keyPath, "utf-8");
45
- return Buffer.from(content.trim(), "base64");
46
- } catch {
47
- return null;
48
- }
49
- }
50
- async function setMasterKey(key) {
51
- const b64 = key.toString("base64");
52
- const keytar = await tryKeytar();
53
- if (keytar) {
54
- try {
55
- await keytar.setPassword(SERVICE, ACCOUNT, b64);
56
- return;
57
- } catch {
58
- }
59
- }
60
- const dir = getKeyDir();
61
- await mkdir(dir, { recursive: true });
62
- const keyPath = getKeyPath();
63
- await writeFile(keyPath, b64 + "\n", "utf-8");
64
- await chmod(keyPath, 384);
65
- }
66
- async function deleteMasterKey() {
67
- const keytar = await tryKeytar();
68
- if (keytar) {
69
- try {
70
- await keytar.deletePassword(SERVICE, ACCOUNT);
71
- } catch {
72
- }
73
- }
74
- const keyPath = getKeyPath();
75
- if (existsSync(keyPath)) {
76
- await unlink(keyPath);
77
- }
78
- }
79
- function exportMnemonic(key) {
80
- if (key.length !== 32) {
81
- throw new Error(`Key must be 32 bytes, got ${key.length}`);
82
- }
83
- const hash = crypto.createHash("sha256").update(key).digest();
84
- const checksumByte = hash[0];
85
- let bits = "";
86
- for (const byte of key) {
87
- bits += byte.toString(2).padStart(8, "0");
88
- }
89
- bits += checksumByte.toString(2).padStart(8, "0");
90
- const words = [];
91
- let wordlist;
92
- try {
93
- const bip39 = __require("bip39");
94
- wordlist = bip39.wordlists?.english ?? bip39.default?.wordlists?.english;
95
- if (!wordlist) throw new Error("no wordlist");
96
- } catch {
97
- throw new Error("bip39 package required. Install with: npm install bip39");
98
- }
99
- for (let i = 0; i < 264; i += 11) {
100
- const index = parseInt(bits.slice(i, i + 11), 2);
101
- words.push(wordlist[index]);
102
- }
103
- return words.join(" ");
104
- }
105
- function importMnemonic(mnemonic) {
106
- const words = mnemonic.trim().split(/\s+/);
107
- if (words.length !== 24) {
108
- throw new Error(`Expected 24 words, got ${words.length}`);
109
- }
110
- let wordlist;
111
- try {
112
- const bip39 = __require("bip39");
113
- wordlist = bip39.wordlists?.english ?? bip39.default?.wordlists?.english;
114
- if (!wordlist) throw new Error("no wordlist");
115
- } catch {
116
- throw new Error("bip39 package required. Install with: npm install bip39");
117
- }
118
- let bits = "";
119
- for (const word of words) {
120
- const index = wordlist.indexOf(word.toLowerCase());
121
- if (index === -1) {
122
- throw new Error(`Invalid BIP39 word: "${word}"`);
123
- }
124
- bits += index.toString(2).padStart(11, "0");
125
- }
126
- const entropyBits = bits.slice(0, 256);
127
- const checksumBits = bits.slice(256, 264);
128
- const key = Buffer.alloc(32);
129
- for (let i = 0; i < 32; i++) {
130
- key[i] = parseInt(entropyBits.slice(i * 8, (i + 1) * 8), 2);
131
- }
132
- const hash = crypto.createHash("sha256").update(key).digest();
133
- const expectedChecksum = hash[0].toString(2).padStart(8, "0");
134
- if (checksumBits !== expectedChecksum) {
135
- throw new Error("Invalid mnemonic checksum");
136
- }
137
- return key;
138
- }
139
- export {
140
- deleteMasterKey,
141
- exportMnemonic,
142
- getMasterKey,
143
- importMnemonic,
144
- setMasterKey
145
- };
@@ -1,382 +0,0 @@
1
- // src/lib/license.ts
2
- import { readFileSync as readFileSync2, writeFileSync, existsSync as existsSync2, mkdirSync } from "fs";
3
- import { randomUUID } from "crypto";
4
- import path2 from "path";
5
- import { jwtVerify, importSPKI } from "jose";
6
-
7
- // src/lib/config.ts
8
- import { readFile, writeFile, mkdir } from "fs/promises";
9
- import { readFileSync, existsSync, renameSync } from "fs";
10
- import path from "path";
11
- import os from "os";
12
- function resolveDataDir() {
13
- if (process.env.EXE_OS_DIR) return process.env.EXE_OS_DIR;
14
- if (process.env.EXE_MEM_DIR) return process.env.EXE_MEM_DIR;
15
- const newDir = path.join(os.homedir(), ".exe-os");
16
- const legacyDir = path.join(os.homedir(), ".exe-mem");
17
- if (!existsSync(newDir) && existsSync(legacyDir)) {
18
- try {
19
- renameSync(legacyDir, newDir);
20
- process.stderr.write(`[exe-os] Migrated data directory: ~/.exe-mem \u2192 ~/.exe-os
21
- `);
22
- } catch {
23
- return legacyDir;
24
- }
25
- }
26
- return newDir;
27
- }
28
- var EXE_AI_DIR = resolveDataDir();
29
- var DB_PATH = path.join(EXE_AI_DIR, "memories.db");
30
- var MODELS_DIR = path.join(EXE_AI_DIR, "models");
31
- var CONFIG_PATH = path.join(EXE_AI_DIR, "config.json");
32
- var LEGACY_LANCE_PATH = path.join(EXE_AI_DIR, "local.lance");
33
- var CURRENT_CONFIG_VERSION = 1;
34
- var DEFAULT_CONFIG = {
35
- config_version: CURRENT_CONFIG_VERSION,
36
- dbPath: DB_PATH,
37
- modelFile: "jina-embeddings-v5-small-q4_k_m.gguf",
38
- embeddingDim: 1024,
39
- batchSize: 20,
40
- flushIntervalMs: 1e4,
41
- autoIngestion: true,
42
- autoRetrieval: true,
43
- searchMode: "hybrid",
44
- hookSearchMode: "hybrid",
45
- fileGrepEnabled: true,
46
- splashEffect: true,
47
- consolidationEnabled: true,
48
- consolidationIntervalMs: 6 * 60 * 60 * 1e3,
49
- consolidationModel: "claude-haiku-4-5-20251001",
50
- consolidationMaxCallsPerRun: 20,
51
- selfQueryRouter: true,
52
- selfQueryModel: "claude-haiku-4-5-20251001",
53
- rerankerEnabled: true,
54
- scalingRoadmap: {
55
- rerankerAutoTrigger: {
56
- enabled: true,
57
- broadQueryMinCardinality: 5e4,
58
- fetchTopK: 150,
59
- returnTopK: 5
60
- }
61
- },
62
- graphRagEnabled: true,
63
- wikiEnabled: false,
64
- wikiUrl: "",
65
- wikiApiKey: "",
66
- wikiSyncIntervalMs: 30 * 60 * 1e3,
67
- wikiWorkspaceMapping: {
68
- exe: "Executive",
69
- yoshi: "Engineering",
70
- mari: "Marketing",
71
- tom: "Engineering",
72
- sasha: "Production"
73
- },
74
- wikiAutoUpdate: true,
75
- wikiAutoUpdateThreshold: 0.5,
76
- wikiAutoUpdateCreateNew: true,
77
- skillLearning: true,
78
- skillThreshold: 3,
79
- skillModel: "claude-haiku-4-5-20251001",
80
- exeHeartbeat: {
81
- enabled: true,
82
- intervalSeconds: 60,
83
- staleInProgressThresholdHours: 2
84
- },
85
- sessionLifecycle: {
86
- idleKillEnabled: true,
87
- idleKillTicksRequired: 3,
88
- idleKillIntercomAckWindowMs: 1e4,
89
- maxAutoInstances: 10
90
- },
91
- autoUpdate: {
92
- checkOnBoot: true,
93
- autoInstall: false,
94
- checkIntervalMs: 24 * 60 * 60 * 1e3
95
- }
96
- };
97
-
98
- // src/lib/license.ts
99
- var LICENSE_PATH = path2.join(EXE_AI_DIR, "license.key");
100
- var CACHE_PATH = path2.join(EXE_AI_DIR, "license-cache.json");
101
- var DEVICE_ID_PATH = path2.join(EXE_AI_DIR, "device-id");
102
- var API_BASE = "https://askexe.com/cloud";
103
- var LICENSE_PUBLIC_KEY_PEM = `-----BEGIN PUBLIC KEY-----
104
- MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEeHztAMOpR/ZMh+rWuOASjEZ54CGY
105
- 4uj+UqeKCcvtgNHKmOK278HJaJcANe9xAeji8AFYu27q3WtzCi04pHudow==
106
- -----END PUBLIC KEY-----`;
107
- var LICENSE_JWT_ALG = "ES256";
108
- var PLAN_LIMITS = {
109
- free: { devices: 1, employees: 1, memories: 5e3 },
110
- pro: { devices: 2, employees: 5, memories: 1e5 },
111
- team: { devices: 10, employees: 20, memories: 1e6 },
112
- agency: { devices: 50, employees: 100, memories: 1e7 },
113
- enterprise: { devices: -1, employees: -1, memories: -1 }
114
- };
115
- var FREE_LICENSE = {
116
- valid: true,
117
- plan: "free",
118
- email: "",
119
- expiresAt: null,
120
- deviceLimit: 1,
121
- employeeLimit: 1,
122
- memoryLimit: 5e3
123
- };
124
- function loadDeviceId() {
125
- const deviceJsonPath = path2.join(EXE_AI_DIR, "device.json");
126
- try {
127
- if (existsSync2(deviceJsonPath)) {
128
- const data = JSON.parse(readFileSync2(deviceJsonPath, "utf8"));
129
- if (data.deviceId) return data.deviceId;
130
- }
131
- } catch {
132
- }
133
- try {
134
- if (existsSync2(DEVICE_ID_PATH)) {
135
- const id2 = readFileSync2(DEVICE_ID_PATH, "utf8").trim();
136
- if (id2) return id2;
137
- }
138
- } catch {
139
- }
140
- const id = randomUUID();
141
- mkdirSync(EXE_AI_DIR, { recursive: true });
142
- writeFileSync(DEVICE_ID_PATH, id, "utf8");
143
- return id;
144
- }
145
- function loadLicense() {
146
- try {
147
- if (!existsSync2(LICENSE_PATH)) return null;
148
- return readFileSync2(LICENSE_PATH, "utf8").trim();
149
- } catch {
150
- return null;
151
- }
152
- }
153
- function saveLicense(apiKey) {
154
- mkdirSync(EXE_AI_DIR, { recursive: true });
155
- writeFileSync(LICENSE_PATH, apiKey.trim(), "utf8");
156
- }
157
- async function verifyLicenseJwt(token) {
158
- try {
159
- const key = await importSPKI(LICENSE_PUBLIC_KEY_PEM, LICENSE_JWT_ALG);
160
- const { payload } = await jwtVerify(token, key, {
161
- algorithms: [LICENSE_JWT_ALG]
162
- });
163
- const plan = payload.plan ?? "free";
164
- const email = payload.sub ?? "";
165
- const limits = PLAN_LIMITS[plan] ?? PLAN_LIMITS.free;
166
- return {
167
- valid: true,
168
- plan,
169
- email,
170
- expiresAt: payload.exp ? new Date(payload.exp * 1e3).toISOString() : null,
171
- deviceLimit: limits.devices,
172
- employeeLimit: limits.employees,
173
- memoryLimit: limits.memories
174
- };
175
- } catch {
176
- return null;
177
- }
178
- }
179
- async function getCachedLicense() {
180
- try {
181
- if (!existsSync2(CACHE_PATH)) return null;
182
- const raw = JSON.parse(readFileSync2(CACHE_PATH, "utf8"));
183
- if (!raw.token || typeof raw.token !== "string") return null;
184
- return await verifyLicenseJwt(raw.token);
185
- } catch {
186
- return null;
187
- }
188
- }
189
- function readCachedToken() {
190
- try {
191
- if (!existsSync2(CACHE_PATH)) return null;
192
- const raw = JSON.parse(readFileSync2(CACHE_PATH, "utf8"));
193
- return typeof raw.token === "string" ? raw.token : null;
194
- } catch {
195
- return null;
196
- }
197
- }
198
- function cacheResponse(token) {
199
- try {
200
- writeFileSync(CACHE_PATH, JSON.stringify({ token }), "utf8");
201
- } catch {
202
- }
203
- }
204
- async function validateLicense(apiKey, deviceId) {
205
- const did = deviceId ?? loadDeviceId();
206
- try {
207
- const res = await fetch(`${API_BASE}/auth/activate`, {
208
- method: "POST",
209
- headers: { "Content-Type": "application/json" },
210
- body: JSON.stringify({ apiKey, deviceId: did }),
211
- signal: AbortSignal.timeout(1e4)
212
- });
213
- if (res.ok) {
214
- const data = await res.json();
215
- if (data.error === "device_limit_exceeded") {
216
- const cached2 = await getCachedLicense();
217
- if (cached2) return cached2;
218
- return { ...FREE_LICENSE, valid: false, plan: "free" };
219
- }
220
- if (data.token) {
221
- cacheResponse(data.token);
222
- const verified = await verifyLicenseJwt(data.token);
223
- if (verified) return verified;
224
- }
225
- const limits = PLAN_LIMITS[data.plan] ?? PLAN_LIMITS.free;
226
- return {
227
- valid: data.valid,
228
- plan: data.plan,
229
- email: data.email,
230
- expiresAt: data.expiresAt,
231
- deviceLimit: limits.devices,
232
- employeeLimit: limits.employees,
233
- memoryLimit: limits.memories
234
- };
235
- }
236
- const cached = await getCachedLicense();
237
- if (cached) return cached;
238
- return { ...FREE_LICENSE, valid: false, plan: "free" };
239
- } catch {
240
- const cached = await getCachedLicense();
241
- if (cached) return cached;
242
- return FREE_LICENSE;
243
- }
244
- }
245
- async function checkLicense() {
246
- const key = loadLicense();
247
- if (!key) return FREE_LICENSE;
248
- const cached = await getCachedLicense();
249
- if (cached) return cached;
250
- const deviceId = loadDeviceId();
251
- return validateLicense(key, deviceId);
252
- }
253
- function isFeatureAllowed(license, feature) {
254
- switch (feature) {
255
- case "cloud_sync":
256
- case "external_agents":
257
- case "wiki":
258
- return license.plan !== "free";
259
- case "unlimited_employees":
260
- return license.plan === "team" || license.plan === "agency" || license.plan === "enterprise";
261
- }
262
- }
263
- function mirrorLicenseKey(apiKey) {
264
- const trimmed = apiKey.trim();
265
- if (!trimmed) return;
266
- saveLicense(trimmed);
267
- }
268
- async function assertVpsLicense(opts) {
269
- const env = opts?.env ?? process.env;
270
- const inProduction = env.NODE_ENV === "production";
271
- if (!opts?.force && !inProduction) {
272
- return { ...FREE_LICENSE, plan: "free" };
273
- }
274
- const envKey = env.EXE_LICENSE_KEY?.trim();
275
- if (envKey) {
276
- saveLicense(envKey);
277
- }
278
- const apiKey = envKey ?? loadLicense();
279
- if (!apiKey) {
280
- throw new Error(
281
- "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."
282
- );
283
- }
284
- const deviceId = loadDeviceId();
285
- let backendResponse = null;
286
- let explicitRejection = false;
287
- let transientFailure = false;
288
- try {
289
- const res = await fetch(`${API_BASE}/auth/activate`, {
290
- method: "POST",
291
- headers: { "Content-Type": "application/json" },
292
- body: JSON.stringify({ apiKey, deviceId }),
293
- signal: AbortSignal.timeout(1e4)
294
- });
295
- if (res.ok) {
296
- backendResponse = await res.json();
297
- if (!backendResponse.valid) explicitRejection = true;
298
- } else if (res.status === 401 || res.status === 403) {
299
- explicitRejection = true;
300
- } else {
301
- transientFailure = true;
302
- }
303
- } catch {
304
- transientFailure = true;
305
- }
306
- if (backendResponse?.valid) {
307
- if (backendResponse.token) {
308
- cacheResponse(backendResponse.token);
309
- const verified = await verifyLicenseJwt(backendResponse.token);
310
- if (verified) return verified;
311
- }
312
- const limits = PLAN_LIMITS[backendResponse.plan] ?? PLAN_LIMITS.free;
313
- return {
314
- valid: true,
315
- plan: backendResponse.plan,
316
- email: backendResponse.email,
317
- expiresAt: backendResponse.expiresAt,
318
- deviceLimit: limits.devices,
319
- employeeLimit: limits.employees,
320
- memoryLimit: limits.memories
321
- };
322
- }
323
- if (explicitRejection) {
324
- throw new Error(
325
- `License invalid or expired. Renew at https://askexe.com, then restart. Backend rejected key ending in ...${apiKey.slice(-4)}.`
326
- );
327
- }
328
- if (!transientFailure) {
329
- throw new Error(
330
- "License validation failed: unknown backend state. Restore network connectivity to https://askexe.com/cloud and retry."
331
- );
332
- }
333
- const fresh = await getCachedLicense();
334
- if (fresh && fresh.valid) return fresh;
335
- const graceDays = opts?.offlineGraceDays ?? 7;
336
- const graceMs = graceDays * 24 * 60 * 60 * 1e3;
337
- try {
338
- const token = readCachedToken();
339
- if (token) {
340
- const payloadB64 = token.split(".")[1];
341
- if (payloadB64) {
342
- const payload = JSON.parse(Buffer.from(payloadB64, "base64url").toString());
343
- const expMs = (payload.exp ?? 0) * 1e3;
344
- if (Date.now() < expMs + graceMs) {
345
- const key = await importSPKI(LICENSE_PUBLIC_KEY_PEM, LICENSE_JWT_ALG);
346
- const { payload: verified } = await jwtVerify(token, key, {
347
- algorithms: [LICENSE_JWT_ALG],
348
- clockTolerance: graceDays * 24 * 60 * 60
349
- });
350
- const plan = verified.plan ?? "free";
351
- const limits = PLAN_LIMITS[plan] ?? PLAN_LIMITS.free;
352
- return {
353
- valid: true,
354
- plan,
355
- email: verified.sub ?? "",
356
- expiresAt: verified.exp ? new Date(verified.exp * 1e3).toISOString() : null,
357
- deviceLimit: limits.devices,
358
- employeeLimit: limits.employees,
359
- memoryLimit: limits.memories
360
- };
361
- }
362
- }
363
- }
364
- } catch {
365
- }
366
- throw new Error(
367
- `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.`
368
- );
369
- }
370
- export {
371
- LICENSE_PUBLIC_KEY_PEM,
372
- PLAN_LIMITS,
373
- assertVpsLicense,
374
- checkLicense,
375
- getCachedLicense,
376
- isFeatureAllowed,
377
- loadDeviceId,
378
- loadLicense,
379
- mirrorLicenseKey,
380
- saveLicense,
381
- validateLicense
382
- };