@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.
- package/dist/bin/agentic-ontology-backfill.js +8 -1
- package/dist/bin/agentic-reflection-backfill.js +8 -1
- package/dist/bin/agentic-semantic-label.js +8 -1
- package/dist/bin/backfill-conversations.js +8 -1
- package/dist/bin/backfill-responses.js +8 -1
- package/dist/bin/backfill-vectors.js +8 -1
- package/dist/bin/bulk-sync-postgres.js +8 -1
- package/dist/bin/cleanup-stale-review-tasks.js +8 -1
- package/dist/bin/cli.js +19 -4
- package/dist/bin/exe-agent.js +1 -1
- package/dist/bin/exe-assign.js +8 -1
- package/dist/bin/exe-boot.js +19 -4
- package/dist/bin/exe-call.js +1 -1
- package/dist/bin/exe-cloud.js +8 -1
- package/dist/bin/exe-dispatch.js +460 -5
- package/dist/bin/exe-doctor.js +8 -1
- package/dist/bin/exe-export-behaviors.js +13 -3
- package/dist/bin/exe-forget.js +8 -1
- package/dist/bin/exe-gateway.js +19 -4
- package/dist/bin/exe-heartbeat.js +8 -1
- package/dist/bin/exe-kill.js +8 -1
- package/dist/bin/exe-launch-agent.js +13 -3
- package/dist/bin/exe-new-employee.js +1 -1
- package/dist/bin/exe-pending-messages.js +8 -1
- package/dist/bin/exe-pending-notifications.js +8 -1
- package/dist/bin/exe-pending-reviews.js +8 -1
- package/dist/bin/exe-rename.js +8 -1
- package/dist/bin/exe-review.js +8 -1
- package/dist/bin/exe-search.js +8 -1
- package/dist/bin/exe-session-cleanup.js +460 -5
- package/dist/bin/exe-start-codex.js +13 -3
- package/dist/bin/exe-start-opencode.js +13 -3
- package/dist/bin/exe-status.js +8 -1
- package/dist/bin/exe-team.js +8 -1
- package/dist/bin/git-sweep.js +460 -5
- package/dist/bin/graph-backfill.js +8 -1
- package/dist/bin/graph-export.js +8 -1
- package/dist/bin/intercom-check.js +460 -5
- package/dist/bin/pre-publish.js +1 -1
- package/dist/bin/scan-tasks.js +460 -5
- package/dist/bin/setup.js +8 -1
- package/dist/bin/shard-migrate.js +8 -1
- package/dist/gateway/index.js +460 -5
- package/dist/hooks/bug-report-worker.js +460 -5
- package/dist/hooks/codex-stop-task-finalizer.js +467 -5
- package/dist/hooks/commit-complete.js +460 -5
- package/dist/hooks/error-recall.js +8 -1
- package/dist/hooks/ingest.js +8 -1
- package/dist/hooks/instructions-loaded.js +8 -1
- package/dist/hooks/notification.js +8 -1
- package/dist/hooks/post-compact.js +8 -1
- package/dist/hooks/post-tool-combined.js +8 -1
- package/dist/hooks/pre-compact.js +460 -5
- package/dist/hooks/pre-tool-use.js +8 -1
- package/dist/hooks/prompt-submit.js +469 -8
- package/dist/hooks/session-end.js +460 -5
- package/dist/hooks/session-start.js +8 -1
- package/dist/hooks/stop.js +8 -1
- package/dist/hooks/subagent-stop.js +8 -1
- package/dist/hooks/summary-worker.js +8 -1
- package/dist/index.js +469 -8
- package/dist/lib/cloud-sync.js +7 -0
- package/dist/lib/database.js +7 -0
- package/dist/lib/db.js +7 -0
- package/dist/lib/device-registry.js +7 -0
- package/dist/lib/employee-templates.js +1 -1
- package/dist/lib/exe-daemon.js +216 -12
- package/dist/lib/hybrid-search.js +8 -1
- package/dist/lib/schedules.js +8 -1
- package/dist/lib/skill-learning.js +488 -7
- package/dist/lib/store.js +8 -1
- package/dist/lib/tasks.js +452 -4
- package/dist/lib/tmux-routing.js +452 -4
- package/dist/mcp/server.js +69 -11
- package/dist/mcp/tools/create-task.js +452 -4
- package/dist/mcp/tools/update-task.js +452 -4
- package/dist/runtime/index.js +469 -8
- package/dist/tui/App.js +19 -4
- package/package.json +1 -1
|
@@ -2436,6 +2436,13 @@ async function ensureSchema() {
|
|
|
2436
2436
|
} catch (e) {
|
|
2437
2437
|
logCatchDebug("migration", e);
|
|
2438
2438
|
}
|
|
2439
|
+
for (const col of ["created_by_agent TEXT", "created_by_device TEXT", "source_session_id TEXT"]) {
|
|
2440
|
+
try {
|
|
2441
|
+
await client.execute({ sql: `ALTER TABLE behaviors ADD COLUMN ${col}`, args: [] });
|
|
2442
|
+
} catch (e) {
|
|
2443
|
+
logCatchDebug("migration", e);
|
|
2444
|
+
}
|
|
2445
|
+
}
|
|
2439
2446
|
try {
|
|
2440
2447
|
await client.execute({
|
|
2441
2448
|
sql: `ALTER TABLE tasks ADD COLUMN blocked_by TEXT`,
|
|
@@ -4964,7 +4971,7 @@ var init_platform_procedures = __esm({
|
|
|
4964
4971
|
title: "MCP tool dispatch \u2014 all tools use action parameter",
|
|
4965
4972
|
domain: "tool-use",
|
|
4966
4973
|
priority: "p0",
|
|
4967
|
-
content: 'exe-os MCP tools
|
|
4974
|
+
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.'
|
|
4968
4975
|
},
|
|
4969
4976
|
{
|
|
4970
4977
|
title: "MCP tools \u2014 memory, decision, and search",
|
|
@@ -6594,6 +6601,23 @@ var init_intercom_queue = __esm({
|
|
|
6594
6601
|
});
|
|
6595
6602
|
|
|
6596
6603
|
// src/lib/license.ts
|
|
6604
|
+
var license_exports = {};
|
|
6605
|
+
__export(license_exports, {
|
|
6606
|
+
LICENSE_PUBLIC_KEY_PEM: () => LICENSE_PUBLIC_KEY_PEM,
|
|
6607
|
+
PLAN_LIMITS: () => PLAN_LIMITS,
|
|
6608
|
+
assertVpsLicense: () => assertVpsLicense,
|
|
6609
|
+
checkLicense: () => checkLicense,
|
|
6610
|
+
getCachedLicense: () => getCachedLicense,
|
|
6611
|
+
isFeatureAllowed: () => isFeatureAllowed,
|
|
6612
|
+
loadDeviceId: () => loadDeviceId,
|
|
6613
|
+
loadLicense: () => loadLicense,
|
|
6614
|
+
mirrorLicenseKey: () => mirrorLicenseKey,
|
|
6615
|
+
readCachedLicenseToken: () => readCachedLicenseToken,
|
|
6616
|
+
saveLicense: () => saveLicense,
|
|
6617
|
+
startLicenseRevalidation: () => startLicenseRevalidation,
|
|
6618
|
+
stopLicenseRevalidation: () => stopLicenseRevalidation,
|
|
6619
|
+
validateLicense: () => validateLicense
|
|
6620
|
+
});
|
|
6597
6621
|
import { readFileSync as readFileSync8, writeFileSync as writeFileSync6, existsSync as existsSync12, mkdirSync as mkdirSync6 } from "fs";
|
|
6598
6622
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
6599
6623
|
import { createRequire as createRequire2 } from "module";
|
|
@@ -6601,7 +6625,411 @@ import { pathToFileURL as pathToFileURL2 } from "url";
|
|
|
6601
6625
|
import os8 from "os";
|
|
6602
6626
|
import path11 from "path";
|
|
6603
6627
|
import { jwtVerify, importSPKI } from "jose";
|
|
6604
|
-
|
|
6628
|
+
async function fetchRetry(url, init) {
|
|
6629
|
+
try {
|
|
6630
|
+
return await fetch(url, init);
|
|
6631
|
+
} catch {
|
|
6632
|
+
await new Promise((r) => setTimeout(r, RETRY_DELAY_MS));
|
|
6633
|
+
return fetch(url, { ...init, signal: AbortSignal.timeout(1e4) });
|
|
6634
|
+
}
|
|
6635
|
+
}
|
|
6636
|
+
function loadDeviceId() {
|
|
6637
|
+
const deviceJsonPath = path11.join(EXE_AI_DIR, "device.json");
|
|
6638
|
+
try {
|
|
6639
|
+
if (existsSync12(deviceJsonPath)) {
|
|
6640
|
+
const data = JSON.parse(readFileSync8(deviceJsonPath, "utf8"));
|
|
6641
|
+
if (data.deviceId) return data.deviceId;
|
|
6642
|
+
}
|
|
6643
|
+
} catch {
|
|
6644
|
+
}
|
|
6645
|
+
try {
|
|
6646
|
+
if (existsSync12(DEVICE_ID_PATH)) {
|
|
6647
|
+
const id2 = readFileSync8(DEVICE_ID_PATH, "utf8").trim();
|
|
6648
|
+
if (id2) return id2;
|
|
6649
|
+
}
|
|
6650
|
+
} catch {
|
|
6651
|
+
}
|
|
6652
|
+
const id = randomUUID3();
|
|
6653
|
+
mkdirSync6(EXE_AI_DIR, { recursive: true });
|
|
6654
|
+
writeFileSync6(DEVICE_ID_PATH, id, "utf8");
|
|
6655
|
+
return id;
|
|
6656
|
+
}
|
|
6657
|
+
function loadLicense() {
|
|
6658
|
+
try {
|
|
6659
|
+
if (!existsSync12(LICENSE_PATH)) return null;
|
|
6660
|
+
return readFileSync8(LICENSE_PATH, "utf8").trim();
|
|
6661
|
+
} catch {
|
|
6662
|
+
return null;
|
|
6663
|
+
}
|
|
6664
|
+
}
|
|
6665
|
+
function saveLicense(apiKey) {
|
|
6666
|
+
mkdirSync6(EXE_AI_DIR, { recursive: true });
|
|
6667
|
+
writeFileSync6(LICENSE_PATH, apiKey.trim(), { encoding: "utf8", mode: 384 });
|
|
6668
|
+
}
|
|
6669
|
+
async function verifyLicenseJwt(token) {
|
|
6670
|
+
try {
|
|
6671
|
+
const key = await importSPKI(LICENSE_PUBLIC_KEY_PEM, LICENSE_JWT_ALG);
|
|
6672
|
+
const { payload } = await jwtVerify(token, key, {
|
|
6673
|
+
algorithms: [LICENSE_JWT_ALG]
|
|
6674
|
+
});
|
|
6675
|
+
const plan = payload.plan ?? "free";
|
|
6676
|
+
const email = payload.sub ?? "";
|
|
6677
|
+
const limits = PLAN_LIMITS[plan] ?? PLAN_LIMITS.free;
|
|
6678
|
+
return {
|
|
6679
|
+
valid: true,
|
|
6680
|
+
plan,
|
|
6681
|
+
email,
|
|
6682
|
+
expiresAt: payload.exp ? new Date(payload.exp * 1e3).toISOString() : null,
|
|
6683
|
+
deviceLimit: limits.devices,
|
|
6684
|
+
employeeLimit: limits.employees,
|
|
6685
|
+
memoryLimit: limits.memories
|
|
6686
|
+
};
|
|
6687
|
+
} catch {
|
|
6688
|
+
return null;
|
|
6689
|
+
}
|
|
6690
|
+
}
|
|
6691
|
+
async function getCachedLicense() {
|
|
6692
|
+
try {
|
|
6693
|
+
if (!existsSync12(CACHE_PATH)) return null;
|
|
6694
|
+
const raw = JSON.parse(readFileSync8(CACHE_PATH, "utf8"));
|
|
6695
|
+
if (!raw.token || typeof raw.token !== "string") return null;
|
|
6696
|
+
return await verifyLicenseJwt(raw.token);
|
|
6697
|
+
} catch {
|
|
6698
|
+
return null;
|
|
6699
|
+
}
|
|
6700
|
+
}
|
|
6701
|
+
function readCachedLicenseToken() {
|
|
6702
|
+
try {
|
|
6703
|
+
if (!existsSync12(CACHE_PATH)) return null;
|
|
6704
|
+
const raw = JSON.parse(readFileSync8(CACHE_PATH, "utf8"));
|
|
6705
|
+
return typeof raw.token === "string" ? raw.token : null;
|
|
6706
|
+
} catch {
|
|
6707
|
+
return null;
|
|
6708
|
+
}
|
|
6709
|
+
}
|
|
6710
|
+
function getRawCachedPlan() {
|
|
6711
|
+
try {
|
|
6712
|
+
const token = readCachedLicenseToken();
|
|
6713
|
+
if (!token) return null;
|
|
6714
|
+
const parts = token.split(".");
|
|
6715
|
+
if (parts.length !== 3) return null;
|
|
6716
|
+
const payload = JSON.parse(Buffer.from(parts[1], "base64url").toString());
|
|
6717
|
+
const plan = payload.plan ?? "free";
|
|
6718
|
+
const limits = PLAN_LIMITS[plan] ?? PLAN_LIMITS.free;
|
|
6719
|
+
process.stderr.write(
|
|
6720
|
+
`[license] WARN: using unverified cached plan (API unreachable, JWT expired). Plan: ${plan}
|
|
6721
|
+
`
|
|
6722
|
+
);
|
|
6723
|
+
return {
|
|
6724
|
+
valid: true,
|
|
6725
|
+
plan,
|
|
6726
|
+
email: payload.sub ?? "",
|
|
6727
|
+
expiresAt: payload.exp ? new Date(payload.exp * 1e3).toISOString() : null,
|
|
6728
|
+
deviceLimit: limits.devices,
|
|
6729
|
+
employeeLimit: limits.employees,
|
|
6730
|
+
memoryLimit: limits.memories
|
|
6731
|
+
};
|
|
6732
|
+
} catch {
|
|
6733
|
+
return null;
|
|
6734
|
+
}
|
|
6735
|
+
}
|
|
6736
|
+
function cacheResponse(token) {
|
|
6737
|
+
try {
|
|
6738
|
+
writeFileSync6(CACHE_PATH, JSON.stringify({ token }), "utf8");
|
|
6739
|
+
} catch {
|
|
6740
|
+
}
|
|
6741
|
+
}
|
|
6742
|
+
function loadPrismaForLicense() {
|
|
6743
|
+
if (_prismaFailed) return null;
|
|
6744
|
+
const dbUrl = process.env.DATABASE_URL;
|
|
6745
|
+
if (!dbUrl) {
|
|
6746
|
+
const exeDbRoot = process.env.EXE_DB_ROOT ?? path11.join(os8.homedir(), "exe-db");
|
|
6747
|
+
if (!existsSync12(path11.join(exeDbRoot, "package.json"))) {
|
|
6748
|
+
_prismaFailed = true;
|
|
6749
|
+
return null;
|
|
6750
|
+
}
|
|
6751
|
+
}
|
|
6752
|
+
if (!_prismaPromise) {
|
|
6753
|
+
_prismaPromise = (async () => {
|
|
6754
|
+
const explicitPath = process.env.EXE_OS_PRISMA_CLIENT_PATH;
|
|
6755
|
+
if (explicitPath) {
|
|
6756
|
+
const mod2 = await import(pathToFileURL2(explicitPath).href);
|
|
6757
|
+
const Ctor2 = mod2.PrismaClient ?? mod2.default?.PrismaClient;
|
|
6758
|
+
if (!Ctor2) throw new Error(`No PrismaClient at ${explicitPath}`);
|
|
6759
|
+
return new Ctor2();
|
|
6760
|
+
}
|
|
6761
|
+
const exeDbRoot = process.env.EXE_DB_ROOT ?? path11.join(os8.homedir(), "exe-db");
|
|
6762
|
+
const req = createRequire2(path11.join(exeDbRoot, "package.json"));
|
|
6763
|
+
const entry = req.resolve("@prisma/client");
|
|
6764
|
+
const mod = await import(pathToFileURL2(entry).href);
|
|
6765
|
+
const Ctor = mod.PrismaClient ?? mod.default?.PrismaClient;
|
|
6766
|
+
if (!Ctor) throw new Error(`No PrismaClient in ${entry}`);
|
|
6767
|
+
return new Ctor();
|
|
6768
|
+
})().catch((err) => {
|
|
6769
|
+
_prismaFailed = true;
|
|
6770
|
+
_prismaPromise = null;
|
|
6771
|
+
throw err;
|
|
6772
|
+
});
|
|
6773
|
+
}
|
|
6774
|
+
return _prismaPromise;
|
|
6775
|
+
}
|
|
6776
|
+
async function validateViaPostgres(apiKey) {
|
|
6777
|
+
const loader = loadPrismaForLicense();
|
|
6778
|
+
if (!loader) return null;
|
|
6779
|
+
try {
|
|
6780
|
+
const prisma = await loader;
|
|
6781
|
+
const rows = await prisma.$queryRawUnsafe(
|
|
6782
|
+
`SELECT plan, email, status, device_limit, employee_limit, memory_limit, expires_at
|
|
6783
|
+
FROM billing.licenses WHERE key = $1 LIMIT 1`,
|
|
6784
|
+
apiKey
|
|
6785
|
+
);
|
|
6786
|
+
if (!rows || rows.length === 0) return null;
|
|
6787
|
+
const row = rows[0];
|
|
6788
|
+
if (row.status !== "active") return null;
|
|
6789
|
+
if (row.expires_at && new Date(row.expires_at) < /* @__PURE__ */ new Date()) return null;
|
|
6790
|
+
const plan = row.plan;
|
|
6791
|
+
const limits = PLAN_LIMITS[plan] ?? PLAN_LIMITS.free;
|
|
6792
|
+
return {
|
|
6793
|
+
valid: true,
|
|
6794
|
+
plan,
|
|
6795
|
+
email: row.email,
|
|
6796
|
+
expiresAt: row.expires_at ? new Date(row.expires_at).toISOString() : null,
|
|
6797
|
+
deviceLimit: row.device_limit ?? limits.devices,
|
|
6798
|
+
employeeLimit: row.employee_limit ?? limits.employees,
|
|
6799
|
+
memoryLimit: row.memory_limit ?? limits.memories
|
|
6800
|
+
};
|
|
6801
|
+
} catch {
|
|
6802
|
+
return null;
|
|
6803
|
+
}
|
|
6804
|
+
}
|
|
6805
|
+
async function validateViaCFWorker(apiKey, deviceId) {
|
|
6806
|
+
try {
|
|
6807
|
+
const res = await fetchRetry(`${API_BASE}/auth/activate`, {
|
|
6808
|
+
method: "POST",
|
|
6809
|
+
headers: { "Content-Type": "application/json" },
|
|
6810
|
+
body: JSON.stringify({ apiKey, deviceId }),
|
|
6811
|
+
signal: AbortSignal.timeout(1e4)
|
|
6812
|
+
});
|
|
6813
|
+
if (!res.ok) return null;
|
|
6814
|
+
const data = await res.json();
|
|
6815
|
+
if (data.error === "device_limit_exceeded") return null;
|
|
6816
|
+
if (!data.valid) return null;
|
|
6817
|
+
if (data.token) {
|
|
6818
|
+
cacheResponse(data.token);
|
|
6819
|
+
const verified = await verifyLicenseJwt(data.token);
|
|
6820
|
+
if (verified) return verified;
|
|
6821
|
+
}
|
|
6822
|
+
const limits = PLAN_LIMITS[data.plan] ?? PLAN_LIMITS.free;
|
|
6823
|
+
return {
|
|
6824
|
+
valid: data.valid,
|
|
6825
|
+
plan: data.plan,
|
|
6826
|
+
email: data.email,
|
|
6827
|
+
expiresAt: data.expiresAt,
|
|
6828
|
+
deviceLimit: limits.devices,
|
|
6829
|
+
employeeLimit: limits.employees,
|
|
6830
|
+
memoryLimit: limits.memories
|
|
6831
|
+
};
|
|
6832
|
+
} catch {
|
|
6833
|
+
return null;
|
|
6834
|
+
}
|
|
6835
|
+
}
|
|
6836
|
+
async function validateLicense(apiKey, deviceId) {
|
|
6837
|
+
const did = deviceId ?? loadDeviceId();
|
|
6838
|
+
const pgResult = await validateViaPostgres(apiKey);
|
|
6839
|
+
if (pgResult) {
|
|
6840
|
+
try {
|
|
6841
|
+
writeFileSync6(CACHE_PATH, JSON.stringify({ pgLicense: pgResult, ts: Date.now() }), "utf8");
|
|
6842
|
+
} catch {
|
|
6843
|
+
}
|
|
6844
|
+
return pgResult;
|
|
6845
|
+
}
|
|
6846
|
+
const cfResult = await validateViaCFWorker(apiKey, did);
|
|
6847
|
+
if (cfResult) return cfResult;
|
|
6848
|
+
const cached = await getCachedLicense();
|
|
6849
|
+
if (cached) return cached;
|
|
6850
|
+
try {
|
|
6851
|
+
if (existsSync12(CACHE_PATH)) {
|
|
6852
|
+
const raw = JSON.parse(readFileSync8(CACHE_PATH, "utf8"));
|
|
6853
|
+
if (raw.pgLicense && raw.ts && Date.now() - raw.ts < 7 * 24 * 60 * 60 * 1e3) {
|
|
6854
|
+
return raw.pgLicense;
|
|
6855
|
+
}
|
|
6856
|
+
}
|
|
6857
|
+
} catch {
|
|
6858
|
+
}
|
|
6859
|
+
const rawFallback = getRawCachedPlan();
|
|
6860
|
+
if (rawFallback) return rawFallback;
|
|
6861
|
+
return { ...FREE_LICENSE, valid: false };
|
|
6862
|
+
}
|
|
6863
|
+
function getCacheAgeMs() {
|
|
6864
|
+
try {
|
|
6865
|
+
const { statSync: statSync5 } = __require("fs");
|
|
6866
|
+
const s = statSync5(CACHE_PATH);
|
|
6867
|
+
return Date.now() - s.mtimeMs;
|
|
6868
|
+
} catch {
|
|
6869
|
+
return Infinity;
|
|
6870
|
+
}
|
|
6871
|
+
}
|
|
6872
|
+
async function checkLicense() {
|
|
6873
|
+
let key = loadLicense();
|
|
6874
|
+
if (!key) {
|
|
6875
|
+
try {
|
|
6876
|
+
const configPath = path11.join(EXE_AI_DIR, "config.json");
|
|
6877
|
+
if (existsSync12(configPath)) {
|
|
6878
|
+
const raw = JSON.parse(readFileSync8(configPath, "utf8"));
|
|
6879
|
+
const cloud = raw.cloud;
|
|
6880
|
+
if (cloud?.apiKey) {
|
|
6881
|
+
key = cloud.apiKey;
|
|
6882
|
+
saveLicense(key);
|
|
6883
|
+
}
|
|
6884
|
+
}
|
|
6885
|
+
} catch {
|
|
6886
|
+
}
|
|
6887
|
+
}
|
|
6888
|
+
if (!key) return FREE_LICENSE;
|
|
6889
|
+
const cached = await getCachedLicense();
|
|
6890
|
+
if (cached && getCacheAgeMs() < CACHE_MAX_AGE_MS) return cached;
|
|
6891
|
+
const deviceId = loadDeviceId();
|
|
6892
|
+
return validateLicense(key, deviceId);
|
|
6893
|
+
}
|
|
6894
|
+
function isFeatureAllowed(license, feature) {
|
|
6895
|
+
switch (feature) {
|
|
6896
|
+
case "cloud_sync":
|
|
6897
|
+
case "external_agents":
|
|
6898
|
+
case "wiki":
|
|
6899
|
+
return license.plan !== "free";
|
|
6900
|
+
case "unlimited_employees":
|
|
6901
|
+
return license.plan === "team" || license.plan === "agency" || license.plan === "enterprise";
|
|
6902
|
+
}
|
|
6903
|
+
}
|
|
6904
|
+
function mirrorLicenseKey(apiKey) {
|
|
6905
|
+
const trimmed = apiKey.trim();
|
|
6906
|
+
if (!trimmed) return;
|
|
6907
|
+
saveLicense(trimmed);
|
|
6908
|
+
}
|
|
6909
|
+
async function assertVpsLicense(opts) {
|
|
6910
|
+
const env = opts?.env ?? process.env;
|
|
6911
|
+
const inProduction = env.NODE_ENV === "production";
|
|
6912
|
+
if (!opts?.force && !inProduction) {
|
|
6913
|
+
return { ...FREE_LICENSE, plan: "free" };
|
|
6914
|
+
}
|
|
6915
|
+
const envKey = env.EXE_LICENSE_KEY?.trim();
|
|
6916
|
+
if (envKey) {
|
|
6917
|
+
saveLicense(envKey);
|
|
6918
|
+
}
|
|
6919
|
+
const apiKey = envKey ?? loadLicense();
|
|
6920
|
+
if (!apiKey) {
|
|
6921
|
+
throw new Error(
|
|
6922
|
+
"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."
|
|
6923
|
+
);
|
|
6924
|
+
}
|
|
6925
|
+
const deviceId = loadDeviceId();
|
|
6926
|
+
let backendResponse = null;
|
|
6927
|
+
let explicitRejection = false;
|
|
6928
|
+
let transientFailure = false;
|
|
6929
|
+
try {
|
|
6930
|
+
const res = await fetchRetry(`${API_BASE}/auth/activate`, {
|
|
6931
|
+
method: "POST",
|
|
6932
|
+
headers: { "Content-Type": "application/json" },
|
|
6933
|
+
body: JSON.stringify({ apiKey, deviceId }),
|
|
6934
|
+
signal: AbortSignal.timeout(1e4)
|
|
6935
|
+
});
|
|
6936
|
+
if (res.ok) {
|
|
6937
|
+
backendResponse = await res.json();
|
|
6938
|
+
if (!backendResponse.valid) explicitRejection = true;
|
|
6939
|
+
} else if (res.status === 401 || res.status === 403) {
|
|
6940
|
+
explicitRejection = true;
|
|
6941
|
+
} else {
|
|
6942
|
+
transientFailure = true;
|
|
6943
|
+
}
|
|
6944
|
+
} catch {
|
|
6945
|
+
transientFailure = true;
|
|
6946
|
+
}
|
|
6947
|
+
if (backendResponse?.valid) {
|
|
6948
|
+
if (backendResponse.token) {
|
|
6949
|
+
cacheResponse(backendResponse.token);
|
|
6950
|
+
const verified = await verifyLicenseJwt(backendResponse.token);
|
|
6951
|
+
if (verified) return verified;
|
|
6952
|
+
}
|
|
6953
|
+
const limits = PLAN_LIMITS[backendResponse.plan] ?? PLAN_LIMITS.free;
|
|
6954
|
+
return {
|
|
6955
|
+
valid: true,
|
|
6956
|
+
plan: backendResponse.plan,
|
|
6957
|
+
email: backendResponse.email,
|
|
6958
|
+
expiresAt: backendResponse.expiresAt,
|
|
6959
|
+
deviceLimit: limits.devices,
|
|
6960
|
+
employeeLimit: limits.employees,
|
|
6961
|
+
memoryLimit: limits.memories
|
|
6962
|
+
};
|
|
6963
|
+
}
|
|
6964
|
+
if (explicitRejection) {
|
|
6965
|
+
throw new Error(
|
|
6966
|
+
`License invalid or expired. Renew at https://askexe.com, then restart. Backend rejected key ending in ...${apiKey.slice(-4)}.`
|
|
6967
|
+
);
|
|
6968
|
+
}
|
|
6969
|
+
if (!transientFailure) {
|
|
6970
|
+
throw new Error(
|
|
6971
|
+
"License validation failed: unknown backend state. Restore network connectivity to https://askexe.com/cloud and retry."
|
|
6972
|
+
);
|
|
6973
|
+
}
|
|
6974
|
+
const fresh = await getCachedLicense();
|
|
6975
|
+
if (fresh && fresh.valid) return fresh;
|
|
6976
|
+
const graceDays = opts?.offlineGraceDays ?? 7;
|
|
6977
|
+
const graceMs = graceDays * 24 * 60 * 60 * 1e3;
|
|
6978
|
+
try {
|
|
6979
|
+
const token = readCachedLicenseToken();
|
|
6980
|
+
if (token) {
|
|
6981
|
+
const payloadB64 = token.split(".")[1];
|
|
6982
|
+
if (payloadB64) {
|
|
6983
|
+
const payload = JSON.parse(Buffer.from(payloadB64, "base64url").toString());
|
|
6984
|
+
const expMs = (payload.exp ?? 0) * 1e3;
|
|
6985
|
+
if (Date.now() < expMs + graceMs) {
|
|
6986
|
+
const key = await importSPKI(LICENSE_PUBLIC_KEY_PEM, LICENSE_JWT_ALG);
|
|
6987
|
+
const { payload: verified } = await jwtVerify(token, key, {
|
|
6988
|
+
algorithms: [LICENSE_JWT_ALG],
|
|
6989
|
+
clockTolerance: graceDays * 24 * 60 * 60
|
|
6990
|
+
});
|
|
6991
|
+
const plan = verified.plan ?? "free";
|
|
6992
|
+
const limits = PLAN_LIMITS[plan] ?? PLAN_LIMITS.free;
|
|
6993
|
+
return {
|
|
6994
|
+
valid: true,
|
|
6995
|
+
plan,
|
|
6996
|
+
email: verified.sub ?? "",
|
|
6997
|
+
expiresAt: verified.exp ? new Date(verified.exp * 1e3).toISOString() : null,
|
|
6998
|
+
deviceLimit: limits.devices,
|
|
6999
|
+
employeeLimit: limits.employees,
|
|
7000
|
+
memoryLimit: limits.memories
|
|
7001
|
+
};
|
|
7002
|
+
}
|
|
7003
|
+
}
|
|
7004
|
+
}
|
|
7005
|
+
} catch {
|
|
7006
|
+
}
|
|
7007
|
+
throw new Error(
|
|
7008
|
+
`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.`
|
|
7009
|
+
);
|
|
7010
|
+
}
|
|
7011
|
+
function startLicenseRevalidation(intervalMs = 36e5) {
|
|
7012
|
+
if (_revalTimer) return;
|
|
7013
|
+
_revalTimer = setInterval(async () => {
|
|
7014
|
+
try {
|
|
7015
|
+
const license = await checkLicense();
|
|
7016
|
+
if (!license.valid) {
|
|
7017
|
+
process.stderr.write("[exe-os] License expired or invalid \u2014 features may be restricted\n");
|
|
7018
|
+
}
|
|
7019
|
+
} catch {
|
|
7020
|
+
}
|
|
7021
|
+
}, intervalMs);
|
|
7022
|
+
if (_revalTimer && typeof _revalTimer === "object" && "unref" in _revalTimer) {
|
|
7023
|
+
_revalTimer.unref();
|
|
7024
|
+
}
|
|
7025
|
+
}
|
|
7026
|
+
function stopLicenseRevalidation() {
|
|
7027
|
+
if (_revalTimer) {
|
|
7028
|
+
clearInterval(_revalTimer);
|
|
7029
|
+
_revalTimer = null;
|
|
7030
|
+
}
|
|
7031
|
+
}
|
|
7032
|
+
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;
|
|
6605
7033
|
var init_license = __esm({
|
|
6606
7034
|
"src/lib/license.ts"() {
|
|
6607
7035
|
"use strict";
|
|
@@ -6610,6 +7038,12 @@ var init_license = __esm({
|
|
|
6610
7038
|
CACHE_PATH = path11.join(EXE_AI_DIR, "license-cache.json");
|
|
6611
7039
|
DEVICE_ID_PATH = path11.join(EXE_AI_DIR, "device-id");
|
|
6612
7040
|
API_BASE = process.env.EXE_CLOUD_ENDPOINT ?? "https://askexe.com/cloud";
|
|
7041
|
+
RETRY_DELAY_MS = 500;
|
|
7042
|
+
LICENSE_PUBLIC_KEY_PEM = `-----BEGIN PUBLIC KEY-----
|
|
7043
|
+
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEeHztAMOpR/ZMh+rWuOASjEZ54CGY
|
|
7044
|
+
4uj+UqeKCcvtgNHKmOK278HJaJcANe9xAeji8AFYu27q3WtzCi04pHudow==
|
|
7045
|
+
-----END PUBLIC KEY-----`;
|
|
7046
|
+
LICENSE_JWT_ALG = "ES256";
|
|
6613
7047
|
PLAN_LIMITS = {
|
|
6614
7048
|
free: { devices: 1, employees: 1, memories: 5e3 },
|
|
6615
7049
|
pro: { devices: 3, employees: 5, memories: 1e5 },
|
|
@@ -6617,6 +7051,19 @@ var init_license = __esm({
|
|
|
6617
7051
|
agency: { devices: 50, employees: 100, memories: 1e7 },
|
|
6618
7052
|
enterprise: { devices: -1, employees: -1, memories: -1 }
|
|
6619
7053
|
};
|
|
7054
|
+
FREE_LICENSE = {
|
|
7055
|
+
valid: true,
|
|
7056
|
+
plan: "free",
|
|
7057
|
+
email: "",
|
|
7058
|
+
expiresAt: null,
|
|
7059
|
+
deviceLimit: 1,
|
|
7060
|
+
employeeLimit: 1,
|
|
7061
|
+
memoryLimit: 5e3
|
|
7062
|
+
};
|
|
7063
|
+
_prismaPromise = null;
|
|
7064
|
+
_prismaFailed = false;
|
|
7065
|
+
CACHE_MAX_AGE_MS = 36e5;
|
|
7066
|
+
_revalTimer = null;
|
|
6620
7067
|
}
|
|
6621
7068
|
});
|
|
6622
7069
|
|
|
@@ -9315,10 +9762,18 @@ async function storeBehavior(opts) {
|
|
|
9315
9762
|
vector = new Float32Array(vec);
|
|
9316
9763
|
} catch {
|
|
9317
9764
|
}
|
|
9765
|
+
let createdByDevice = null;
|
|
9766
|
+
try {
|
|
9767
|
+
const { loadDeviceId: loadDeviceId2 } = await Promise.resolve().then(() => (init_license(), license_exports));
|
|
9768
|
+
createdByDevice = loadDeviceId2() ?? null;
|
|
9769
|
+
} catch {
|
|
9770
|
+
}
|
|
9771
|
+
const createdByAgent = process.env.AGENT_ID ?? null;
|
|
9772
|
+
const sourceSessionId = process.env.CLAUDE_SESSION_ID ?? process.env.SESSION_ID ?? null;
|
|
9318
9773
|
await client.execute({
|
|
9319
|
-
sql: `INSERT INTO behaviors (id, agent_id, project_name, domain, priority, content, active, created_at, updated_at, vector)
|
|
9320
|
-
VALUES (?, ?, ?, ?, ?, ?, 1, ?, ?, ?)`,
|
|
9321
|
-
args: [id, opts.agentId, opts.projectName ?? null, opts.domain ?? null, opts.priority ?? "p1", opts.content, now, now, vector ? vector.buffer : null]
|
|
9774
|
+
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)
|
|
9775
|
+
VALUES (?, ?, ?, ?, ?, ?, 1, ?, ?, ?, ?, ?, ?)`,
|
|
9776
|
+
args: [id, opts.agentId, opts.projectName ?? null, opts.domain ?? null, opts.priority ?? "p1", opts.content, now, now, vector ? vector.buffer : null, createdByAgent, createdByDevice, sourceSessionId]
|
|
9322
9777
|
});
|
|
9323
9778
|
return id;
|
|
9324
9779
|
}
|