@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.
- package/package.json +1 -1
- package/dist/bin/backfill-responses.js +0 -2064
- package/dist/bin/backfill-vectors.js +0 -1771
- package/dist/bin/cleanup-stale-review-tasks.js +0 -1468
- package/dist/bin/cli.js +0 -21371
- package/dist/bin/exe-agent.js +0 -2016
- package/dist/bin/exe-assign.js +0 -2176
- package/dist/bin/exe-boot.js +0 -6332
- package/dist/bin/exe-call.js +0 -341
- package/dist/bin/exe-cloud.js +0 -861
- package/dist/bin/exe-dispatch.js +0 -1159
- package/dist/bin/exe-doctor.js +0 -1786
- package/dist/bin/exe-export-behaviors.js +0 -1637
- package/dist/bin/exe-forget.js +0 -1784
- package/dist/bin/exe-gateway.js +0 -8140
- package/dist/bin/exe-healthcheck.js +0 -207
- package/dist/bin/exe-heartbeat.js +0 -1778
- package/dist/bin/exe-kill.js +0 -1622
- package/dist/bin/exe-launch-agent.js +0 -1847
- package/dist/bin/exe-link.js +0 -192
- package/dist/bin/exe-new-employee.js +0 -1384
- package/dist/bin/exe-pending-messages.js +0 -1576
- package/dist/bin/exe-pending-notifications.js +0 -1450
- package/dist/bin/exe-pending-reviews.js +0 -1598
- package/dist/bin/exe-repo-drift.js +0 -95
- package/dist/bin/exe-review.js +0 -1742
- package/dist/bin/exe-search.js +0 -3116
- package/dist/bin/exe-session-cleanup.js +0 -3360
- package/dist/bin/exe-settings.js +0 -365
- package/dist/bin/exe-status.js +0 -1661
- package/dist/bin/exe-team.js +0 -1453
- package/dist/bin/git-sweep.js +0 -2441
- package/dist/bin/graph-backfill.js +0 -2111
- package/dist/bin/graph-export.js +0 -1747
- package/dist/bin/install.js +0 -661
- package/dist/bin/list-providers.js +0 -140
- package/dist/bin/scan-tasks.js +0 -2039
- package/dist/bin/setup.js +0 -2717
- package/dist/bin/shard-migrate.js +0 -1637
- package/dist/bin/update.js +0 -98
- package/dist/bin/wiki-sync.js +0 -1657
- package/dist/gateway/index.js +0 -9256
- package/dist/hooks/bug-report-worker.js +0 -2903
- package/dist/hooks/commit-complete.js +0 -2364
- package/dist/hooks/error-recall.js +0 -3327
- package/dist/hooks/exe-heartbeat-hook.js +0 -237
- package/dist/hooks/ingest-worker.js +0 -5065
- package/dist/hooks/ingest.js +0 -695
- package/dist/hooks/instructions-loaded.js +0 -2069
- package/dist/hooks/notification.js +0 -1915
- package/dist/hooks/post-compact.js +0 -1940
- package/dist/hooks/pre-compact.js +0 -1935
- package/dist/hooks/pre-tool-use.js +0 -2380
- package/dist/hooks/prompt-ingest-worker.js +0 -2291
- package/dist/hooks/prompt-submit.js +0 -5189
- package/dist/hooks/response-ingest-worker.js +0 -2431
- package/dist/hooks/session-end.js +0 -2196
- package/dist/hooks/session-start.js +0 -3259
- package/dist/hooks/stop.js +0 -2025
- package/dist/hooks/subagent-stop.js +0 -1915
- package/dist/hooks/summary-worker.js +0 -2931
- package/dist/index.js +0 -12327
- package/dist/lib/cloud-sync.js +0 -500
- package/dist/lib/config.js +0 -235
- package/dist/lib/consolidation.js +0 -481
- package/dist/lib/crypto.js +0 -51
- package/dist/lib/database.js +0 -834
- package/dist/lib/device-registry.js +0 -1009
- package/dist/lib/embedder.js +0 -645
- package/dist/lib/employee-templates.js +0 -570
- package/dist/lib/employees.js +0 -182
- package/dist/lib/error-detector.js +0 -156
- package/dist/lib/exe-daemon-client.js +0 -456
- package/dist/lib/exe-daemon.js +0 -8699
- package/dist/lib/file-grep.js +0 -215
- package/dist/lib/hybrid-search.js +0 -3064
- package/dist/lib/identity-templates.js +0 -441
- package/dist/lib/identity.js +0 -228
- package/dist/lib/keychain.js +0 -145
- package/dist/lib/license.js +0 -382
- package/dist/lib/messaging.js +0 -1389
- package/dist/lib/reminders.js +0 -63
- package/dist/lib/schedules.js +0 -1525
- package/dist/lib/session-registry.js +0 -52
- package/dist/lib/skill-learning.js +0 -488
- package/dist/lib/status-brief.js +0 -240
- package/dist/lib/store.js +0 -1740
- package/dist/lib/task-router.js +0 -128
- package/dist/lib/tasks.js +0 -2585
- package/dist/lib/tmux-routing.js +0 -2969
- package/dist/lib/tmux-status.js +0 -261
- package/dist/lib/tmux-transport.js +0 -83
- package/dist/lib/transport.js +0 -128
- package/dist/lib/ws-auth.js +0 -19
- package/dist/lib/ws-client.js +0 -160
- package/dist/mcp/server.js +0 -10812
- package/dist/mcp/tools/complete-reminder.js +0 -67
- package/dist/mcp/tools/create-reminder.js +0 -52
- package/dist/mcp/tools/create-task.js +0 -1903
- package/dist/mcp/tools/deactivate-behavior.js +0 -268
- package/dist/mcp/tools/list-reminders.js +0 -62
- package/dist/mcp/tools/list-tasks.js +0 -491
- package/dist/mcp/tools/send-message.js +0 -1395
- package/dist/mcp/tools/update-task.js +0 -1807
- package/dist/runtime/index.js +0 -7201
- package/dist/tui/App.js +0 -17874
package/dist/bin/exe-cloud.js
DELETED
|
@@ -1,861 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
5
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
6
|
-
}) : x)(function(x) {
|
|
7
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
8
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
9
|
-
});
|
|
10
|
-
var __esm = (fn, res) => function __init() {
|
|
11
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
12
|
-
};
|
|
13
|
-
var __export = (target, all) => {
|
|
14
|
-
for (var name in all)
|
|
15
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
// src/lib/config.ts
|
|
19
|
-
import { readFile as readFile2, writeFile as writeFile2, mkdir as mkdir2 } from "fs/promises";
|
|
20
|
-
import { readFileSync, existsSync as existsSync2, renameSync } from "fs";
|
|
21
|
-
import path2 from "path";
|
|
22
|
-
import os from "os";
|
|
23
|
-
function resolveDataDir() {
|
|
24
|
-
if (process.env.EXE_OS_DIR) return process.env.EXE_OS_DIR;
|
|
25
|
-
if (process.env.EXE_MEM_DIR) return process.env.EXE_MEM_DIR;
|
|
26
|
-
const newDir = path2.join(os.homedir(), ".exe-os");
|
|
27
|
-
const legacyDir = path2.join(os.homedir(), ".exe-mem");
|
|
28
|
-
if (!existsSync2(newDir) && existsSync2(legacyDir)) {
|
|
29
|
-
try {
|
|
30
|
-
renameSync(legacyDir, newDir);
|
|
31
|
-
process.stderr.write(`[exe-os] Migrated data directory: ~/.exe-mem \u2192 ~/.exe-os
|
|
32
|
-
`);
|
|
33
|
-
} catch {
|
|
34
|
-
return legacyDir;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return newDir;
|
|
38
|
-
}
|
|
39
|
-
function migrateLegacyConfig(raw) {
|
|
40
|
-
if ("r2" in raw) {
|
|
41
|
-
process.stderr.write(
|
|
42
|
-
"[exe-os] Warning: config.json contains deprecated 'r2' field from v1.0. R2 sync has been replaced in v1.1. The 'r2' field will be ignored.\n"
|
|
43
|
-
);
|
|
44
|
-
delete raw.r2;
|
|
45
|
-
}
|
|
46
|
-
if ("syncIntervalMs" in raw) {
|
|
47
|
-
delete raw.syncIntervalMs;
|
|
48
|
-
}
|
|
49
|
-
return raw;
|
|
50
|
-
}
|
|
51
|
-
function migrateConfig(raw) {
|
|
52
|
-
const fromVersion = typeof raw.config_version === "number" ? raw.config_version : 0;
|
|
53
|
-
let currentVersion = fromVersion;
|
|
54
|
-
let migrated = false;
|
|
55
|
-
if (currentVersion > CURRENT_CONFIG_VERSION) {
|
|
56
|
-
return { config: raw, migrated: false, fromVersion };
|
|
57
|
-
}
|
|
58
|
-
for (const migration of CONFIG_MIGRATIONS) {
|
|
59
|
-
if (currentVersion === migration.from && migration.to <= CURRENT_CONFIG_VERSION) {
|
|
60
|
-
raw = migration.migrate(raw);
|
|
61
|
-
currentVersion = migration.to;
|
|
62
|
-
migrated = true;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return { config: raw, migrated, fromVersion };
|
|
66
|
-
}
|
|
67
|
-
function normalizeScalingRoadmap(raw) {
|
|
68
|
-
const defaultAuto = DEFAULT_CONFIG.scalingRoadmap.rerankerAutoTrigger;
|
|
69
|
-
const userRoadmap = raw.scalingRoadmap ?? {};
|
|
70
|
-
const userAuto = userRoadmap.rerankerAutoTrigger ?? {};
|
|
71
|
-
if (userAuto.enabled === void 0 && raw.rerankerEnabled !== void 0) {
|
|
72
|
-
userAuto.enabled = raw.rerankerEnabled;
|
|
73
|
-
}
|
|
74
|
-
raw.scalingRoadmap = {
|
|
75
|
-
...userRoadmap,
|
|
76
|
-
rerankerAutoTrigger: { ...defaultAuto, ...userAuto }
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
function normalizeSessionLifecycle(raw) {
|
|
80
|
-
const defaultSL = DEFAULT_CONFIG.sessionLifecycle;
|
|
81
|
-
const userSL = raw.sessionLifecycle ?? {};
|
|
82
|
-
raw.sessionLifecycle = { ...defaultSL, ...userSL };
|
|
83
|
-
}
|
|
84
|
-
function normalizeAutoUpdate(raw) {
|
|
85
|
-
const defaultAU = DEFAULT_CONFIG.autoUpdate;
|
|
86
|
-
const userAU = raw.autoUpdate ?? {};
|
|
87
|
-
raw.autoUpdate = { ...defaultAU, ...userAU };
|
|
88
|
-
}
|
|
89
|
-
async function loadConfig() {
|
|
90
|
-
const dir = process.env.EXE_OS_DIR ?? process.env.EXE_MEM_DIR ?? EXE_AI_DIR;
|
|
91
|
-
await mkdir2(dir, { recursive: true });
|
|
92
|
-
const configPath = path2.join(dir, "config.json");
|
|
93
|
-
if (!existsSync2(configPath)) {
|
|
94
|
-
return { ...DEFAULT_CONFIG, dbPath: path2.join(dir, "memories.db") };
|
|
95
|
-
}
|
|
96
|
-
const raw = await readFile2(configPath, "utf-8");
|
|
97
|
-
try {
|
|
98
|
-
let parsed = JSON.parse(raw);
|
|
99
|
-
parsed = migrateLegacyConfig(parsed);
|
|
100
|
-
const { config: migratedCfg, migrated, fromVersion } = migrateConfig(parsed);
|
|
101
|
-
if (migrated) {
|
|
102
|
-
process.stderr.write(`[exe-os] Config migrated from v${fromVersion} to v${migratedCfg.config_version}
|
|
103
|
-
`);
|
|
104
|
-
try {
|
|
105
|
-
await writeFile2(configPath, JSON.stringify(migratedCfg, null, 2) + "\n");
|
|
106
|
-
} catch {
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
normalizeScalingRoadmap(migratedCfg);
|
|
110
|
-
normalizeSessionLifecycle(migratedCfg);
|
|
111
|
-
normalizeAutoUpdate(migratedCfg);
|
|
112
|
-
const config = { ...DEFAULT_CONFIG, dbPath: path2.join(dir, "memories.db"), ...migratedCfg };
|
|
113
|
-
if (config.dbPath.startsWith("~")) {
|
|
114
|
-
config.dbPath = config.dbPath.replace(/^~/, os.homedir());
|
|
115
|
-
}
|
|
116
|
-
return config;
|
|
117
|
-
} catch {
|
|
118
|
-
return { ...DEFAULT_CONFIG, dbPath: path2.join(dir, "memories.db") };
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
async function saveConfig(config) {
|
|
122
|
-
const dir = process.env.EXE_OS_DIR ?? process.env.EXE_MEM_DIR ?? EXE_AI_DIR;
|
|
123
|
-
await mkdir2(dir, { recursive: true });
|
|
124
|
-
const configPath = path2.join(dir, "config.json");
|
|
125
|
-
await writeFile2(configPath, JSON.stringify(config, null, 2) + "\n");
|
|
126
|
-
}
|
|
127
|
-
var EXE_AI_DIR, DB_PATH, MODELS_DIR, CONFIG_PATH, LEGACY_LANCE_PATH, CURRENT_CONFIG_VERSION, DEFAULT_CONFIG, CONFIG_MIGRATIONS;
|
|
128
|
-
var init_config = __esm({
|
|
129
|
-
"src/lib/config.ts"() {
|
|
130
|
-
"use strict";
|
|
131
|
-
EXE_AI_DIR = resolveDataDir();
|
|
132
|
-
DB_PATH = path2.join(EXE_AI_DIR, "memories.db");
|
|
133
|
-
MODELS_DIR = path2.join(EXE_AI_DIR, "models");
|
|
134
|
-
CONFIG_PATH = path2.join(EXE_AI_DIR, "config.json");
|
|
135
|
-
LEGACY_LANCE_PATH = path2.join(EXE_AI_DIR, "local.lance");
|
|
136
|
-
CURRENT_CONFIG_VERSION = 1;
|
|
137
|
-
DEFAULT_CONFIG = {
|
|
138
|
-
config_version: CURRENT_CONFIG_VERSION,
|
|
139
|
-
dbPath: DB_PATH,
|
|
140
|
-
modelFile: "jina-embeddings-v5-small-q4_k_m.gguf",
|
|
141
|
-
embeddingDim: 1024,
|
|
142
|
-
batchSize: 20,
|
|
143
|
-
flushIntervalMs: 1e4,
|
|
144
|
-
autoIngestion: true,
|
|
145
|
-
autoRetrieval: true,
|
|
146
|
-
searchMode: "hybrid",
|
|
147
|
-
hookSearchMode: "hybrid",
|
|
148
|
-
fileGrepEnabled: true,
|
|
149
|
-
splashEffect: true,
|
|
150
|
-
consolidationEnabled: true,
|
|
151
|
-
consolidationIntervalMs: 6 * 60 * 60 * 1e3,
|
|
152
|
-
consolidationModel: "claude-haiku-4-5-20251001",
|
|
153
|
-
consolidationMaxCallsPerRun: 20,
|
|
154
|
-
selfQueryRouter: true,
|
|
155
|
-
selfQueryModel: "claude-haiku-4-5-20251001",
|
|
156
|
-
rerankerEnabled: true,
|
|
157
|
-
scalingRoadmap: {
|
|
158
|
-
rerankerAutoTrigger: {
|
|
159
|
-
enabled: true,
|
|
160
|
-
broadQueryMinCardinality: 5e4,
|
|
161
|
-
fetchTopK: 150,
|
|
162
|
-
returnTopK: 5
|
|
163
|
-
}
|
|
164
|
-
},
|
|
165
|
-
graphRagEnabled: true,
|
|
166
|
-
wikiEnabled: false,
|
|
167
|
-
wikiUrl: "",
|
|
168
|
-
wikiApiKey: "",
|
|
169
|
-
wikiSyncIntervalMs: 30 * 60 * 1e3,
|
|
170
|
-
wikiWorkspaceMapping: {
|
|
171
|
-
exe: "Executive",
|
|
172
|
-
yoshi: "Engineering",
|
|
173
|
-
mari: "Marketing",
|
|
174
|
-
tom: "Engineering",
|
|
175
|
-
sasha: "Production"
|
|
176
|
-
},
|
|
177
|
-
wikiAutoUpdate: true,
|
|
178
|
-
wikiAutoUpdateThreshold: 0.5,
|
|
179
|
-
wikiAutoUpdateCreateNew: true,
|
|
180
|
-
skillLearning: true,
|
|
181
|
-
skillThreshold: 3,
|
|
182
|
-
skillModel: "claude-haiku-4-5-20251001",
|
|
183
|
-
exeHeartbeat: {
|
|
184
|
-
enabled: true,
|
|
185
|
-
intervalSeconds: 60,
|
|
186
|
-
staleInProgressThresholdHours: 2
|
|
187
|
-
},
|
|
188
|
-
sessionLifecycle: {
|
|
189
|
-
idleKillEnabled: true,
|
|
190
|
-
idleKillTicksRequired: 3,
|
|
191
|
-
idleKillIntercomAckWindowMs: 1e4,
|
|
192
|
-
maxAutoInstances: 10
|
|
193
|
-
},
|
|
194
|
-
autoUpdate: {
|
|
195
|
-
checkOnBoot: true,
|
|
196
|
-
autoInstall: false,
|
|
197
|
-
checkIntervalMs: 24 * 60 * 60 * 1e3
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
CONFIG_MIGRATIONS = [
|
|
201
|
-
{
|
|
202
|
-
from: 0,
|
|
203
|
-
to: 1,
|
|
204
|
-
migrate: (cfg) => {
|
|
205
|
-
cfg.config_version = 1;
|
|
206
|
-
return cfg;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
];
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
// src/lib/license.ts
|
|
214
|
-
var license_exports = {};
|
|
215
|
-
__export(license_exports, {
|
|
216
|
-
LICENSE_PUBLIC_KEY_PEM: () => LICENSE_PUBLIC_KEY_PEM,
|
|
217
|
-
PLAN_LIMITS: () => PLAN_LIMITS,
|
|
218
|
-
assertVpsLicense: () => assertVpsLicense,
|
|
219
|
-
checkLicense: () => checkLicense,
|
|
220
|
-
getCachedLicense: () => getCachedLicense,
|
|
221
|
-
isFeatureAllowed: () => isFeatureAllowed,
|
|
222
|
-
loadDeviceId: () => loadDeviceId,
|
|
223
|
-
loadLicense: () => loadLicense,
|
|
224
|
-
mirrorLicenseKey: () => mirrorLicenseKey,
|
|
225
|
-
saveLicense: () => saveLicense,
|
|
226
|
-
validateLicense: () => validateLicense
|
|
227
|
-
});
|
|
228
|
-
import { readFileSync as readFileSync2, writeFileSync, existsSync as existsSync3, mkdirSync } from "fs";
|
|
229
|
-
import { randomUUID } from "crypto";
|
|
230
|
-
import path3 from "path";
|
|
231
|
-
import { jwtVerify, importSPKI } from "jose";
|
|
232
|
-
function loadDeviceId() {
|
|
233
|
-
const deviceJsonPath = path3.join(EXE_AI_DIR, "device.json");
|
|
234
|
-
try {
|
|
235
|
-
if (existsSync3(deviceJsonPath)) {
|
|
236
|
-
const data = JSON.parse(readFileSync2(deviceJsonPath, "utf8"));
|
|
237
|
-
if (data.deviceId) return data.deviceId;
|
|
238
|
-
}
|
|
239
|
-
} catch {
|
|
240
|
-
}
|
|
241
|
-
try {
|
|
242
|
-
if (existsSync3(DEVICE_ID_PATH)) {
|
|
243
|
-
const id2 = readFileSync2(DEVICE_ID_PATH, "utf8").trim();
|
|
244
|
-
if (id2) return id2;
|
|
245
|
-
}
|
|
246
|
-
} catch {
|
|
247
|
-
}
|
|
248
|
-
const id = randomUUID();
|
|
249
|
-
mkdirSync(EXE_AI_DIR, { recursive: true });
|
|
250
|
-
writeFileSync(DEVICE_ID_PATH, id, "utf8");
|
|
251
|
-
return id;
|
|
252
|
-
}
|
|
253
|
-
function loadLicense() {
|
|
254
|
-
try {
|
|
255
|
-
if (!existsSync3(LICENSE_PATH)) return null;
|
|
256
|
-
return readFileSync2(LICENSE_PATH, "utf8").trim();
|
|
257
|
-
} catch {
|
|
258
|
-
return null;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
function saveLicense(apiKey) {
|
|
262
|
-
mkdirSync(EXE_AI_DIR, { recursive: true });
|
|
263
|
-
writeFileSync(LICENSE_PATH, apiKey.trim(), "utf8");
|
|
264
|
-
}
|
|
265
|
-
async function verifyLicenseJwt(token) {
|
|
266
|
-
try {
|
|
267
|
-
const key = await importSPKI(LICENSE_PUBLIC_KEY_PEM, LICENSE_JWT_ALG);
|
|
268
|
-
const { payload } = await jwtVerify(token, key, {
|
|
269
|
-
algorithms: [LICENSE_JWT_ALG]
|
|
270
|
-
});
|
|
271
|
-
const plan = payload.plan ?? "free";
|
|
272
|
-
const email = payload.sub ?? "";
|
|
273
|
-
const limits = PLAN_LIMITS[plan] ?? PLAN_LIMITS.free;
|
|
274
|
-
return {
|
|
275
|
-
valid: true,
|
|
276
|
-
plan,
|
|
277
|
-
email,
|
|
278
|
-
expiresAt: payload.exp ? new Date(payload.exp * 1e3).toISOString() : null,
|
|
279
|
-
deviceLimit: limits.devices,
|
|
280
|
-
employeeLimit: limits.employees,
|
|
281
|
-
memoryLimit: limits.memories
|
|
282
|
-
};
|
|
283
|
-
} catch {
|
|
284
|
-
return null;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
async function getCachedLicense() {
|
|
288
|
-
try {
|
|
289
|
-
if (!existsSync3(CACHE_PATH)) return null;
|
|
290
|
-
const raw = JSON.parse(readFileSync2(CACHE_PATH, "utf8"));
|
|
291
|
-
if (!raw.token || typeof raw.token !== "string") return null;
|
|
292
|
-
return await verifyLicenseJwt(raw.token);
|
|
293
|
-
} catch {
|
|
294
|
-
return null;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
function readCachedToken() {
|
|
298
|
-
try {
|
|
299
|
-
if (!existsSync3(CACHE_PATH)) return null;
|
|
300
|
-
const raw = JSON.parse(readFileSync2(CACHE_PATH, "utf8"));
|
|
301
|
-
return typeof raw.token === "string" ? raw.token : null;
|
|
302
|
-
} catch {
|
|
303
|
-
return null;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
function cacheResponse(token) {
|
|
307
|
-
try {
|
|
308
|
-
writeFileSync(CACHE_PATH, JSON.stringify({ token }), "utf8");
|
|
309
|
-
} catch {
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
async function validateLicense(apiKey, deviceId) {
|
|
313
|
-
const did = deviceId ?? loadDeviceId();
|
|
314
|
-
try {
|
|
315
|
-
const res = await fetch(`${API_BASE}/auth/activate`, {
|
|
316
|
-
method: "POST",
|
|
317
|
-
headers: { "Content-Type": "application/json" },
|
|
318
|
-
body: JSON.stringify({ apiKey, deviceId: did }),
|
|
319
|
-
signal: AbortSignal.timeout(1e4)
|
|
320
|
-
});
|
|
321
|
-
if (res.ok) {
|
|
322
|
-
const data = await res.json();
|
|
323
|
-
if (data.error === "device_limit_exceeded") {
|
|
324
|
-
const cached2 = await getCachedLicense();
|
|
325
|
-
if (cached2) return cached2;
|
|
326
|
-
return { ...FREE_LICENSE, valid: false, plan: "free" };
|
|
327
|
-
}
|
|
328
|
-
if (data.token) {
|
|
329
|
-
cacheResponse(data.token);
|
|
330
|
-
const verified = await verifyLicenseJwt(data.token);
|
|
331
|
-
if (verified) return verified;
|
|
332
|
-
}
|
|
333
|
-
const limits = PLAN_LIMITS[data.plan] ?? PLAN_LIMITS.free;
|
|
334
|
-
return {
|
|
335
|
-
valid: data.valid,
|
|
336
|
-
plan: data.plan,
|
|
337
|
-
email: data.email,
|
|
338
|
-
expiresAt: data.expiresAt,
|
|
339
|
-
deviceLimit: limits.devices,
|
|
340
|
-
employeeLimit: limits.employees,
|
|
341
|
-
memoryLimit: limits.memories
|
|
342
|
-
};
|
|
343
|
-
}
|
|
344
|
-
const cached = await getCachedLicense();
|
|
345
|
-
if (cached) return cached;
|
|
346
|
-
return { ...FREE_LICENSE, valid: false, plan: "free" };
|
|
347
|
-
} catch {
|
|
348
|
-
const cached = await getCachedLicense();
|
|
349
|
-
if (cached) return cached;
|
|
350
|
-
return FREE_LICENSE;
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
async function checkLicense() {
|
|
354
|
-
const key = loadLicense();
|
|
355
|
-
if (!key) return FREE_LICENSE;
|
|
356
|
-
const cached = await getCachedLicense();
|
|
357
|
-
if (cached) return cached;
|
|
358
|
-
const deviceId = loadDeviceId();
|
|
359
|
-
return validateLicense(key, deviceId);
|
|
360
|
-
}
|
|
361
|
-
function isFeatureAllowed(license, feature) {
|
|
362
|
-
switch (feature) {
|
|
363
|
-
case "cloud_sync":
|
|
364
|
-
case "external_agents":
|
|
365
|
-
case "wiki":
|
|
366
|
-
return license.plan !== "free";
|
|
367
|
-
case "unlimited_employees":
|
|
368
|
-
return license.plan === "team" || license.plan === "agency" || license.plan === "enterprise";
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
function mirrorLicenseKey(apiKey) {
|
|
372
|
-
const trimmed = apiKey.trim();
|
|
373
|
-
if (!trimmed) return;
|
|
374
|
-
saveLicense(trimmed);
|
|
375
|
-
}
|
|
376
|
-
async function assertVpsLicense(opts) {
|
|
377
|
-
const env = opts?.env ?? process.env;
|
|
378
|
-
const inProduction = env.NODE_ENV === "production";
|
|
379
|
-
if (!opts?.force && !inProduction) {
|
|
380
|
-
return { ...FREE_LICENSE, plan: "free" };
|
|
381
|
-
}
|
|
382
|
-
const envKey = env.EXE_LICENSE_KEY?.trim();
|
|
383
|
-
if (envKey) {
|
|
384
|
-
saveLicense(envKey);
|
|
385
|
-
}
|
|
386
|
-
const apiKey = envKey ?? loadLicense();
|
|
387
|
-
if (!apiKey) {
|
|
388
|
-
throw new Error(
|
|
389
|
-
"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."
|
|
390
|
-
);
|
|
391
|
-
}
|
|
392
|
-
const deviceId = loadDeviceId();
|
|
393
|
-
let backendResponse = null;
|
|
394
|
-
let explicitRejection = false;
|
|
395
|
-
let transientFailure = false;
|
|
396
|
-
try {
|
|
397
|
-
const res = await fetch(`${API_BASE}/auth/activate`, {
|
|
398
|
-
method: "POST",
|
|
399
|
-
headers: { "Content-Type": "application/json" },
|
|
400
|
-
body: JSON.stringify({ apiKey, deviceId }),
|
|
401
|
-
signal: AbortSignal.timeout(1e4)
|
|
402
|
-
});
|
|
403
|
-
if (res.ok) {
|
|
404
|
-
backendResponse = await res.json();
|
|
405
|
-
if (!backendResponse.valid) explicitRejection = true;
|
|
406
|
-
} else if (res.status === 401 || res.status === 403) {
|
|
407
|
-
explicitRejection = true;
|
|
408
|
-
} else {
|
|
409
|
-
transientFailure = true;
|
|
410
|
-
}
|
|
411
|
-
} catch {
|
|
412
|
-
transientFailure = true;
|
|
413
|
-
}
|
|
414
|
-
if (backendResponse?.valid) {
|
|
415
|
-
if (backendResponse.token) {
|
|
416
|
-
cacheResponse(backendResponse.token);
|
|
417
|
-
const verified = await verifyLicenseJwt(backendResponse.token);
|
|
418
|
-
if (verified) return verified;
|
|
419
|
-
}
|
|
420
|
-
const limits = PLAN_LIMITS[backendResponse.plan] ?? PLAN_LIMITS.free;
|
|
421
|
-
return {
|
|
422
|
-
valid: true,
|
|
423
|
-
plan: backendResponse.plan,
|
|
424
|
-
email: backendResponse.email,
|
|
425
|
-
expiresAt: backendResponse.expiresAt,
|
|
426
|
-
deviceLimit: limits.devices,
|
|
427
|
-
employeeLimit: limits.employees,
|
|
428
|
-
memoryLimit: limits.memories
|
|
429
|
-
};
|
|
430
|
-
}
|
|
431
|
-
if (explicitRejection) {
|
|
432
|
-
throw new Error(
|
|
433
|
-
`License invalid or expired. Renew at https://askexe.com, then restart. Backend rejected key ending in ...${apiKey.slice(-4)}.`
|
|
434
|
-
);
|
|
435
|
-
}
|
|
436
|
-
if (!transientFailure) {
|
|
437
|
-
throw new Error(
|
|
438
|
-
"License validation failed: unknown backend state. Restore network connectivity to https://askexe.com/cloud and retry."
|
|
439
|
-
);
|
|
440
|
-
}
|
|
441
|
-
const fresh = await getCachedLicense();
|
|
442
|
-
if (fresh && fresh.valid) return fresh;
|
|
443
|
-
const graceDays = opts?.offlineGraceDays ?? 7;
|
|
444
|
-
const graceMs = graceDays * 24 * 60 * 60 * 1e3;
|
|
445
|
-
try {
|
|
446
|
-
const token = readCachedToken();
|
|
447
|
-
if (token) {
|
|
448
|
-
const payloadB64 = token.split(".")[1];
|
|
449
|
-
if (payloadB64) {
|
|
450
|
-
const payload = JSON.parse(Buffer.from(payloadB64, "base64url").toString());
|
|
451
|
-
const expMs = (payload.exp ?? 0) * 1e3;
|
|
452
|
-
if (Date.now() < expMs + graceMs) {
|
|
453
|
-
const key = await importSPKI(LICENSE_PUBLIC_KEY_PEM, LICENSE_JWT_ALG);
|
|
454
|
-
const { payload: verified } = await jwtVerify(token, key, {
|
|
455
|
-
algorithms: [LICENSE_JWT_ALG],
|
|
456
|
-
clockTolerance: graceDays * 24 * 60 * 60
|
|
457
|
-
});
|
|
458
|
-
const plan = verified.plan ?? "free";
|
|
459
|
-
const limits = PLAN_LIMITS[plan] ?? PLAN_LIMITS.free;
|
|
460
|
-
return {
|
|
461
|
-
valid: true,
|
|
462
|
-
plan,
|
|
463
|
-
email: verified.sub ?? "",
|
|
464
|
-
expiresAt: verified.exp ? new Date(verified.exp * 1e3).toISOString() : null,
|
|
465
|
-
deviceLimit: limits.devices,
|
|
466
|
-
employeeLimit: limits.employees,
|
|
467
|
-
memoryLimit: limits.memories
|
|
468
|
-
};
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
} catch {
|
|
473
|
-
}
|
|
474
|
-
throw new Error(
|
|
475
|
-
`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.`
|
|
476
|
-
);
|
|
477
|
-
}
|
|
478
|
-
var LICENSE_PATH, CACHE_PATH, DEVICE_ID_PATH, API_BASE, LICENSE_PUBLIC_KEY_PEM, LICENSE_JWT_ALG, PLAN_LIMITS, FREE_LICENSE;
|
|
479
|
-
var init_license = __esm({
|
|
480
|
-
"src/lib/license.ts"() {
|
|
481
|
-
"use strict";
|
|
482
|
-
init_config();
|
|
483
|
-
LICENSE_PATH = path3.join(EXE_AI_DIR, "license.key");
|
|
484
|
-
CACHE_PATH = path3.join(EXE_AI_DIR, "license-cache.json");
|
|
485
|
-
DEVICE_ID_PATH = path3.join(EXE_AI_DIR, "device-id");
|
|
486
|
-
API_BASE = "https://askexe.com/cloud";
|
|
487
|
-
LICENSE_PUBLIC_KEY_PEM = `-----BEGIN PUBLIC KEY-----
|
|
488
|
-
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEeHztAMOpR/ZMh+rWuOASjEZ54CGY
|
|
489
|
-
4uj+UqeKCcvtgNHKmOK278HJaJcANe9xAeji8AFYu27q3WtzCi04pHudow==
|
|
490
|
-
-----END PUBLIC KEY-----`;
|
|
491
|
-
LICENSE_JWT_ALG = "ES256";
|
|
492
|
-
PLAN_LIMITS = {
|
|
493
|
-
free: { devices: 1, employees: 1, memories: 5e3 },
|
|
494
|
-
pro: { devices: 2, employees: 5, memories: 1e5 },
|
|
495
|
-
team: { devices: 10, employees: 20, memories: 1e6 },
|
|
496
|
-
agency: { devices: 50, employees: 100, memories: 1e7 },
|
|
497
|
-
enterprise: { devices: -1, employees: -1, memories: -1 }
|
|
498
|
-
};
|
|
499
|
-
FREE_LICENSE = {
|
|
500
|
-
valid: true,
|
|
501
|
-
plan: "free",
|
|
502
|
-
email: "",
|
|
503
|
-
expiresAt: null,
|
|
504
|
-
deviceLimit: 1,
|
|
505
|
-
employeeLimit: 1,
|
|
506
|
-
memoryLimit: 5e3
|
|
507
|
-
};
|
|
508
|
-
}
|
|
509
|
-
});
|
|
510
|
-
|
|
511
|
-
// src/bin/exe-cloud.ts
|
|
512
|
-
import { createInterface } from "readline";
|
|
513
|
-
|
|
514
|
-
// src/lib/keychain.ts
|
|
515
|
-
import { readFile, writeFile, unlink, mkdir, chmod } from "fs/promises";
|
|
516
|
-
import { existsSync } from "fs";
|
|
517
|
-
import path from "path";
|
|
518
|
-
import crypto from "crypto";
|
|
519
|
-
var SERVICE = "exe-mem";
|
|
520
|
-
var ACCOUNT = "master-key";
|
|
521
|
-
function getKeyDir() {
|
|
522
|
-
return process.env.EXE_OS_DIR ?? process.env.EXE_MEM_DIR ?? path.join(process.env.HOME ?? "/tmp", ".exe-os");
|
|
523
|
-
}
|
|
524
|
-
function getKeyPath() {
|
|
525
|
-
return path.join(getKeyDir(), "master.key");
|
|
526
|
-
}
|
|
527
|
-
async function tryKeytar() {
|
|
528
|
-
try {
|
|
529
|
-
return await import("keytar");
|
|
530
|
-
} catch {
|
|
531
|
-
return null;
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
async function getMasterKey() {
|
|
535
|
-
const keytar = await tryKeytar();
|
|
536
|
-
if (keytar) {
|
|
537
|
-
try {
|
|
538
|
-
const stored = await keytar.getPassword(SERVICE, ACCOUNT);
|
|
539
|
-
if (stored) {
|
|
540
|
-
return Buffer.from(stored, "base64");
|
|
541
|
-
}
|
|
542
|
-
} catch {
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
const keyPath = getKeyPath();
|
|
546
|
-
if (!existsSync(keyPath)) {
|
|
547
|
-
return null;
|
|
548
|
-
}
|
|
549
|
-
try {
|
|
550
|
-
const content = await readFile(keyPath, "utf-8");
|
|
551
|
-
return Buffer.from(content.trim(), "base64");
|
|
552
|
-
} catch {
|
|
553
|
-
return null;
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
async function setMasterKey(key) {
|
|
557
|
-
const b64 = key.toString("base64");
|
|
558
|
-
const keytar = await tryKeytar();
|
|
559
|
-
if (keytar) {
|
|
560
|
-
try {
|
|
561
|
-
await keytar.setPassword(SERVICE, ACCOUNT, b64);
|
|
562
|
-
return;
|
|
563
|
-
} catch {
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
const dir = getKeyDir();
|
|
567
|
-
await mkdir(dir, { recursive: true });
|
|
568
|
-
const keyPath = getKeyPath();
|
|
569
|
-
await writeFile(keyPath, b64 + "\n", "utf-8");
|
|
570
|
-
await chmod(keyPath, 384);
|
|
571
|
-
}
|
|
572
|
-
function exportMnemonic(key) {
|
|
573
|
-
if (key.length !== 32) {
|
|
574
|
-
throw new Error(`Key must be 32 bytes, got ${key.length}`);
|
|
575
|
-
}
|
|
576
|
-
const hash = crypto.createHash("sha256").update(key).digest();
|
|
577
|
-
const checksumByte = hash[0];
|
|
578
|
-
let bits = "";
|
|
579
|
-
for (const byte of key) {
|
|
580
|
-
bits += byte.toString(2).padStart(8, "0");
|
|
581
|
-
}
|
|
582
|
-
bits += checksumByte.toString(2).padStart(8, "0");
|
|
583
|
-
const words = [];
|
|
584
|
-
let wordlist;
|
|
585
|
-
try {
|
|
586
|
-
const bip39 = __require("bip39");
|
|
587
|
-
wordlist = bip39.wordlists?.english ?? bip39.default?.wordlists?.english;
|
|
588
|
-
if (!wordlist) throw new Error("no wordlist");
|
|
589
|
-
} catch {
|
|
590
|
-
throw new Error("bip39 package required. Install with: npm install bip39");
|
|
591
|
-
}
|
|
592
|
-
for (let i = 0; i < 264; i += 11) {
|
|
593
|
-
const index = parseInt(bits.slice(i, i + 11), 2);
|
|
594
|
-
words.push(wordlist[index]);
|
|
595
|
-
}
|
|
596
|
-
return words.join(" ");
|
|
597
|
-
}
|
|
598
|
-
function importMnemonic(mnemonic) {
|
|
599
|
-
const words = mnemonic.trim().split(/\s+/);
|
|
600
|
-
if (words.length !== 24) {
|
|
601
|
-
throw new Error(`Expected 24 words, got ${words.length}`);
|
|
602
|
-
}
|
|
603
|
-
let wordlist;
|
|
604
|
-
try {
|
|
605
|
-
const bip39 = __require("bip39");
|
|
606
|
-
wordlist = bip39.wordlists?.english ?? bip39.default?.wordlists?.english;
|
|
607
|
-
if (!wordlist) throw new Error("no wordlist");
|
|
608
|
-
} catch {
|
|
609
|
-
throw new Error("bip39 package required. Install with: npm install bip39");
|
|
610
|
-
}
|
|
611
|
-
let bits = "";
|
|
612
|
-
for (const word of words) {
|
|
613
|
-
const index = wordlist.indexOf(word.toLowerCase());
|
|
614
|
-
if (index === -1) {
|
|
615
|
-
throw new Error(`Invalid BIP39 word: "${word}"`);
|
|
616
|
-
}
|
|
617
|
-
bits += index.toString(2).padStart(11, "0");
|
|
618
|
-
}
|
|
619
|
-
const entropyBits = bits.slice(0, 256);
|
|
620
|
-
const checksumBits = bits.slice(256, 264);
|
|
621
|
-
const key = Buffer.alloc(32);
|
|
622
|
-
for (let i = 0; i < 32; i++) {
|
|
623
|
-
key[i] = parseInt(entropyBits.slice(i * 8, (i + 1) * 8), 2);
|
|
624
|
-
}
|
|
625
|
-
const hash = crypto.createHash("sha256").update(key).digest();
|
|
626
|
-
const expectedChecksum = hash[0].toString(2).padStart(8, "0");
|
|
627
|
-
if (checksumBits !== expectedChecksum) {
|
|
628
|
-
throw new Error("Invalid mnemonic checksum");
|
|
629
|
-
}
|
|
630
|
-
return key;
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
// src/bin/exe-cloud.ts
|
|
634
|
-
init_config();
|
|
635
|
-
|
|
636
|
-
// src/lib/ws-auth.ts
|
|
637
|
-
import crypto2 from "crypto";
|
|
638
|
-
var WS_AUTH_HKDF_INFO = "exe-os-ws-auth-v1";
|
|
639
|
-
var ORG_ID_HKDF_INFO = "exe-os-org-id-v1";
|
|
640
|
-
function deriveWsAuthToken(masterKey) {
|
|
641
|
-
return Buffer.from(crypto2.hkdfSync("sha256", masterKey, "", WS_AUTH_HKDF_INFO, 32));
|
|
642
|
-
}
|
|
643
|
-
function deriveOrgId(masterKey) {
|
|
644
|
-
const raw = Buffer.from(crypto2.hkdfSync("sha256", masterKey, "", ORG_ID_HKDF_INFO, 32));
|
|
645
|
-
return crypto2.createHash("sha256").update(raw).digest("hex").slice(0, 32);
|
|
646
|
-
}
|
|
647
|
-
function hashAuthToken(token) {
|
|
648
|
-
return crypto2.createHash("sha256").update(token).digest("hex");
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
// src/lib/is-main.ts
|
|
652
|
-
import { realpathSync } from "fs";
|
|
653
|
-
import { fileURLToPath } from "url";
|
|
654
|
-
function isMainModule(importMetaUrl) {
|
|
655
|
-
if (process.argv[1] == null) return false;
|
|
656
|
-
try {
|
|
657
|
-
const scriptPath = realpathSync(process.argv[1]);
|
|
658
|
-
const modulePath = realpathSync(fileURLToPath(importMetaUrl));
|
|
659
|
-
return scriptPath === modulePath;
|
|
660
|
-
} catch {
|
|
661
|
-
return importMetaUrl === `file://${process.argv[1]}` || importMetaUrl === new URL(process.argv[1], "file://").href;
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
// src/bin/exe-cloud.ts
|
|
666
|
-
var BAR = "\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550";
|
|
667
|
-
function ask(rl, question) {
|
|
668
|
-
return new Promise((resolve) => {
|
|
669
|
-
rl.question(question, (answer) => resolve(answer.trim()));
|
|
670
|
-
});
|
|
671
|
-
}
|
|
672
|
-
async function setupMode() {
|
|
673
|
-
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
674
|
-
console.log(BAR);
|
|
675
|
-
console.log(" EXE CLOUD SETUP");
|
|
676
|
-
console.log(BAR);
|
|
677
|
-
console.log("");
|
|
678
|
-
console.log("Step 1: Encryption Key");
|
|
679
|
-
const existingKey = await getMasterKey();
|
|
680
|
-
if (existingKey) {
|
|
681
|
-
console.log(" \u2713 Master key already present. Skipping.\n");
|
|
682
|
-
} else {
|
|
683
|
-
const hasPhrase = await ask(rl, " Do you have a 24-word recovery phrase from another device? (y/n) ");
|
|
684
|
-
if (hasPhrase.toLowerCase().startsWith("y")) {
|
|
685
|
-
const mnemonic = await ask(rl, " Paste your 24 words: ");
|
|
686
|
-
try {
|
|
687
|
-
const key = importMnemonic(mnemonic);
|
|
688
|
-
await setMasterKey(key);
|
|
689
|
-
console.log(" \u2713 Key imported.\n");
|
|
690
|
-
} catch (err) {
|
|
691
|
-
console.error(` \u2717 Invalid mnemonic: ${err instanceof Error ? err.message : String(err)}`);
|
|
692
|
-
rl.close();
|
|
693
|
-
process.exit(1);
|
|
694
|
-
}
|
|
695
|
-
} else {
|
|
696
|
-
console.log(" No recovery phrase \u2014 run /exe-setup on your first device to generate one.");
|
|
697
|
-
console.log(" Then use /exe-cloud sync on that device to get the phrase.\n");
|
|
698
|
-
rl.close();
|
|
699
|
-
return;
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
console.log("Step 2: Cloud Sync");
|
|
703
|
-
const config = await loadConfig();
|
|
704
|
-
if (config.cloud?.apiKey) {
|
|
705
|
-
console.log(` \u2713 Cloud already configured (${config.cloud.endpoint}).
|
|
706
|
-
`);
|
|
707
|
-
const masterKey = await getMasterKey();
|
|
708
|
-
if (masterKey) {
|
|
709
|
-
const orgId = deriveOrgId(masterKey);
|
|
710
|
-
const authTokenHash = hashAuthToken(deriveWsAuthToken(masterKey));
|
|
711
|
-
try {
|
|
712
|
-
const regResp = await fetch(`${config.cloud.endpoint}/api/register-org`, {
|
|
713
|
-
method: "POST",
|
|
714
|
-
headers: { Authorization: `Bearer ${config.cloud.apiKey}`, "Content-Type": "application/json" },
|
|
715
|
-
body: JSON.stringify({ orgId, authTokenHash })
|
|
716
|
-
});
|
|
717
|
-
if (regResp.ok) {
|
|
718
|
-
console.log(" \u2713 Org registered for cross-machine messaging.\n");
|
|
719
|
-
}
|
|
720
|
-
} catch {
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
} else {
|
|
724
|
-
const apiKey = await ask(rl, " Paste your API key (exe_sk_...): ");
|
|
725
|
-
if (!apiKey) {
|
|
726
|
-
console.log(" Skipped. Use /exe-settings to configure later.");
|
|
727
|
-
rl.close();
|
|
728
|
-
return;
|
|
729
|
-
}
|
|
730
|
-
const endpoint = await ask(rl, " Endpoint [https://askexe.com/cloud]: ") || "https://askexe.com/cloud";
|
|
731
|
-
console.log(" Validating...");
|
|
732
|
-
try {
|
|
733
|
-
const resp = await fetch(`${endpoint}/auth/verify`, {
|
|
734
|
-
method: "POST",
|
|
735
|
-
headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" }
|
|
736
|
-
});
|
|
737
|
-
if (resp.ok) {
|
|
738
|
-
config.cloud = { apiKey, endpoint };
|
|
739
|
-
await saveConfig(config);
|
|
740
|
-
try {
|
|
741
|
-
const { mirrorLicenseKey: mirrorLicenseKey2 } = await Promise.resolve().then(() => (init_license(), license_exports));
|
|
742
|
-
mirrorLicenseKey2(apiKey);
|
|
743
|
-
} catch {
|
|
744
|
-
}
|
|
745
|
-
console.log(" \u2713 Cloud sync configured.\n");
|
|
746
|
-
const masterKey = await getMasterKey();
|
|
747
|
-
if (masterKey) {
|
|
748
|
-
console.log("Step 3: Cross-Machine Messaging");
|
|
749
|
-
const orgId = deriveOrgId(masterKey);
|
|
750
|
-
const authTokenHash = hashAuthToken(deriveWsAuthToken(masterKey));
|
|
751
|
-
try {
|
|
752
|
-
const regResp = await fetch(`${endpoint}/api/register-org`, {
|
|
753
|
-
method: "POST",
|
|
754
|
-
headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
|
|
755
|
-
body: JSON.stringify({ orgId, authTokenHash })
|
|
756
|
-
});
|
|
757
|
-
if (regResp.ok) {
|
|
758
|
-
console.log(" \u2713 Org registered for cross-machine messaging.\n");
|
|
759
|
-
} else {
|
|
760
|
-
console.log(` \u26A0 Org registration failed (${regResp.status}). WS relay may not work.
|
|
761
|
-
`);
|
|
762
|
-
}
|
|
763
|
-
} catch {
|
|
764
|
-
console.log(" \u26A0 Org registration failed (network). WS relay may not work.\n");
|
|
765
|
-
}
|
|
766
|
-
}
|
|
767
|
-
} else {
|
|
768
|
-
console.log(` \u2717 Validation failed (${resp.status}). Key not saved.`);
|
|
769
|
-
rl.close();
|
|
770
|
-
process.exit(1);
|
|
771
|
-
}
|
|
772
|
-
} catch (err) {
|
|
773
|
-
console.log(` \u2717 Could not reach endpoint: ${err instanceof Error ? err.message : String(err)}`);
|
|
774
|
-
rl.close();
|
|
775
|
-
process.exit(1);
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
console.log(BAR);
|
|
779
|
-
console.log(" Setup complete. Memories will sync now.");
|
|
780
|
-
console.log(BAR);
|
|
781
|
-
rl.close();
|
|
782
|
-
}
|
|
783
|
-
async function syncMode() {
|
|
784
|
-
const key = await getMasterKey();
|
|
785
|
-
if (!key) {
|
|
786
|
-
console.error("No master key found. Run /exe-setup first.");
|
|
787
|
-
process.exit(1);
|
|
788
|
-
}
|
|
789
|
-
const config = await loadConfig();
|
|
790
|
-
const mnemonic = exportMnemonic(key);
|
|
791
|
-
console.log(BAR);
|
|
792
|
-
console.log(" EXE CLOUD \u2014 DEVICE SYNC INFO");
|
|
793
|
-
console.log(BAR);
|
|
794
|
-
console.log("");
|
|
795
|
-
console.log("Run /exe-cloud on the new device and paste these when prompted:\n");
|
|
796
|
-
console.log(" 24-word recovery phrase:");
|
|
797
|
-
console.log(` ${mnemonic}
|
|
798
|
-
`);
|
|
799
|
-
if (config.cloud?.apiKey) {
|
|
800
|
-
console.log(" Cloud API key:");
|
|
801
|
-
console.log(` ${config.cloud.apiKey}
|
|
802
|
-
`);
|
|
803
|
-
console.log(" Endpoint:");
|
|
804
|
-
console.log(` ${config.cloud.endpoint}
|
|
805
|
-
`);
|
|
806
|
-
} else {
|
|
807
|
-
console.log(" Cloud sync: not configured (local-only)\n");
|
|
808
|
-
}
|
|
809
|
-
console.log("\u26A0 Anyone with the recovery phrase can decrypt your memories.");
|
|
810
|
-
console.log(BAR);
|
|
811
|
-
}
|
|
812
|
-
async function statusMode() {
|
|
813
|
-
const key = await getMasterKey();
|
|
814
|
-
const config = await loadConfig();
|
|
815
|
-
console.log(BAR);
|
|
816
|
-
console.log(" EXE CLOUD STATUS");
|
|
817
|
-
console.log(BAR);
|
|
818
|
-
console.log("");
|
|
819
|
-
if (key) {
|
|
820
|
-
const fingerprint = key.toString("hex").slice(0, 8);
|
|
821
|
-
console.log(` Encryption key: \u2713 present (${fingerprint}...)`);
|
|
822
|
-
} else {
|
|
823
|
-
console.log(" Encryption key: \u2717 not found \u2014 run /exe-setup");
|
|
824
|
-
}
|
|
825
|
-
if (config.cloud?.apiKey) {
|
|
826
|
-
const masked = config.cloud.apiKey.slice(0, 10) + "..." + config.cloud.apiKey.slice(-4);
|
|
827
|
-
console.log(` Cloud sync: \u2713 Exe Cloud (${masked})`);
|
|
828
|
-
console.log(` Endpoint: ${config.cloud.endpoint}`);
|
|
829
|
-
} else if (config.turso?.url) {
|
|
830
|
-
console.log(` Cloud sync: \u2713 libSQL (legacy) (${config.turso.url})`);
|
|
831
|
-
} else {
|
|
832
|
-
console.log(" Cloud sync: local-only");
|
|
833
|
-
}
|
|
834
|
-
console.log("");
|
|
835
|
-
console.log(BAR);
|
|
836
|
-
}
|
|
837
|
-
async function main() {
|
|
838
|
-
const mode = process.argv[2]?.toLowerCase();
|
|
839
|
-
if (mode === "sync") {
|
|
840
|
-
await syncMode();
|
|
841
|
-
} else if (mode === "status") {
|
|
842
|
-
await statusMode();
|
|
843
|
-
} else if (!mode || mode === "setup") {
|
|
844
|
-
await setupMode();
|
|
845
|
-
} else {
|
|
846
|
-
console.error("Usage:");
|
|
847
|
-
console.error(" exe-cloud \u2014 full device setup (key + cloud)");
|
|
848
|
-
console.error(" exe-cloud sync \u2014 export info for new device");
|
|
849
|
-
console.error(" exe-cloud status \u2014 show current sync status");
|
|
850
|
-
process.exit(1);
|
|
851
|
-
}
|
|
852
|
-
}
|
|
853
|
-
if (isMainModule(import.meta.url)) {
|
|
854
|
-
main().catch((err) => {
|
|
855
|
-
console.error(err instanceof Error ? err.message : String(err));
|
|
856
|
-
process.exit(1);
|
|
857
|
-
});
|
|
858
|
-
}
|
|
859
|
-
export {
|
|
860
|
-
main
|
|
861
|
-
};
|