@rubytech/create-realagent-code 0.1.583 → 0.1.585
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/payload/platform/config/brand.json +1 -0
- package/payload/platform/lib/brand-templating/dist/index.d.ts +13 -7
- package/payload/platform/lib/brand-templating/dist/index.d.ts.map +1 -1
- package/payload/platform/lib/brand-templating/dist/index.js +44 -29
- package/payload/platform/lib/brand-templating/dist/index.js.map +1 -1
- package/payload/platform/lib/brand-templating/src/__tests__/brand-templating.test.ts +103 -0
- package/payload/platform/lib/brand-templating/src/index.ts +45 -29
- package/payload/platform/lib/brand-templating/tsconfig.json +2 -1
- package/payload/platform/lib/brand-templating/vitest.config.ts +9 -0
- package/payload/platform/lib/telegram-reach/dist/index.d.ts +6 -0
- package/payload/platform/lib/telegram-reach/dist/index.d.ts.map +1 -1
- package/payload/platform/lib/telegram-reach/dist/index.js +38 -3
- package/payload/platform/lib/telegram-reach/dist/index.js.map +1 -1
- package/payload/platform/lib/telegram-reach/src/__tests__/telegram-reach.test.ts +54 -2
- package/payload/platform/lib/telegram-reach/src/index.ts +38 -4
- package/payload/platform/plugins/admin/skills/platform-architecture/SKILL.md +7 -1
- package/payload/platform/plugins/admin/skills/whats-new/SKILL.md +12 -0
- package/payload/platform/plugins/docs/references/platform.md +2 -0
- package/payload/platform/plugins/docs/references/telegram-guide.md +4 -0
- package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.js +0 -1
- package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.js.map +1 -1
- package/payload/platform/templates/agents/admin/IDENTITY.md +11 -5
- package/payload/server/{chunk-CV6AEMKH.js → chunk-34FPJYHN.js} +1 -1
- package/payload/server/{chunk-SKYZG6OT.js → chunk-6AQYMT6C.js} +27 -21
- package/payload/server/{chunk-BTXRBXMU.js → chunk-GO3EPIXU.js} +1 -1
- package/payload/server/{manager-FQSQSSJ3.js → manager-7BXVB76I.js} +2 -2
- package/payload/server/maxy-edge.js +2 -2
- package/payload/server/server.js +305 -297
package/payload/server/server.js
CHANGED
|
@@ -70,7 +70,7 @@ import {
|
|
|
70
70
|
verifyRemotePassword,
|
|
71
71
|
vncLog,
|
|
72
72
|
walkPremiumBundles
|
|
73
|
-
} from "./chunk-
|
|
73
|
+
} from "./chunk-GO3EPIXU.js";
|
|
74
74
|
import {
|
|
75
75
|
ACCOUNTS_ROOT,
|
|
76
76
|
DATA_ROOT,
|
|
@@ -216,7 +216,7 @@ import {
|
|
|
216
216
|
waitForConnection,
|
|
217
217
|
warnNonUuidAccount,
|
|
218
218
|
writeChatMetadataMerged
|
|
219
|
-
} from "./chunk-
|
|
219
|
+
} from "./chunk-34FPJYHN.js";
|
|
220
220
|
import {
|
|
221
221
|
ACCOUNTS_DIR,
|
|
222
222
|
AGENT_SLUG_PATTERN,
|
|
@@ -281,7 +281,7 @@ import {
|
|
|
281
281
|
verifyAndGetConversationUpdatedAt,
|
|
282
282
|
verifyConversationOwnership,
|
|
283
283
|
writeAdminUserAndPerson
|
|
284
|
-
} from "./chunk-
|
|
284
|
+
} from "./chunk-6AQYMT6C.js";
|
|
285
285
|
import {
|
|
286
286
|
D1_MAX_SQL_STATEMENT_BYTES,
|
|
287
287
|
D1_QUERY_MAX_BODY_BYTES,
|
|
@@ -314,7 +314,9 @@ var require_dist2 = __commonJS({
|
|
|
314
314
|
exports.channelKeyToFileStem = channelKeyToFileStem3;
|
|
315
315
|
exports.fileStemToChannelKey = fileStemToChannelKey3;
|
|
316
316
|
exports.collectTelegramReach = collectTelegramReach2;
|
|
317
|
+
exports.telegramStoreRoot = telegramStoreRoot2;
|
|
317
318
|
var node_fs_1 = __require("fs");
|
|
319
|
+
var node_os_1 = __require("os");
|
|
318
320
|
var node_path_1 = __require("path");
|
|
319
321
|
function isStorableChannelKey3(channelKey) {
|
|
320
322
|
return /^-?\d+:-?\d+$/.test(channelKey) || /^-?\d+:biz:-?\d+$/.test(channelKey);
|
|
@@ -442,6 +444,22 @@ var require_dist2 = __commonJS({
|
|
|
442
444
|
});
|
|
443
445
|
return { bots, storeRows };
|
|
444
446
|
}
|
|
447
|
+
function configDirName2(platformRoot5) {
|
|
448
|
+
const brandPath = (0, node_path_1.join)(platformRoot5, "config", "brand.json");
|
|
449
|
+
if ((0, node_fs_1.existsSync)(brandPath)) {
|
|
450
|
+
try {
|
|
451
|
+
const parsed = JSON.parse((0, node_fs_1.readFileSync)(brandPath, "utf8"));
|
|
452
|
+
if (typeof parsed.configDir === "string")
|
|
453
|
+
return parsed.configDir;
|
|
454
|
+
} catch {
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
return ".maxy";
|
|
458
|
+
}
|
|
459
|
+
function telegramStoreRoot2(platformRoot5) {
|
|
460
|
+
const brandDir = process.env.MAXY_DIR_OVERRIDE ?? (0, node_path_1.resolve)((0, node_os_1.homedir)(), configDirName2(platformRoot5));
|
|
461
|
+
return (0, node_path_1.join)(brandDir, "data", "telegram-messages");
|
|
462
|
+
}
|
|
445
463
|
}
|
|
446
464
|
});
|
|
447
465
|
|
|
@@ -3122,11 +3140,11 @@ var require_dist9 = __commonJS({
|
|
|
3122
3140
|
});
|
|
3123
3141
|
|
|
3124
3142
|
// server/index.ts
|
|
3125
|
-
import { readFileSync as readFileSync62, existsSync as
|
|
3143
|
+
import { readFileSync as readFileSync62, existsSync as existsSync62, watchFile, readdirSync as readdirSync37, statSync as statSync33 } from "fs";
|
|
3126
3144
|
import { spawn as spawn3 } from "child_process";
|
|
3127
3145
|
import { createHash as createHash8 } from "crypto";
|
|
3128
3146
|
import { resolve as resolve55, join as join75, basename as basename19 } from "path";
|
|
3129
|
-
import { homedir as
|
|
3147
|
+
import { homedir as homedir5 } from "os";
|
|
3130
3148
|
|
|
3131
3149
|
// server/lib/route-cache-watchers.ts
|
|
3132
3150
|
import { watch } from "fs";
|
|
@@ -3251,23 +3269,11 @@ function onInvalidate(fn) {
|
|
|
3251
3269
|
var import_dist2 = __toESM(require_dist2(), 1);
|
|
3252
3270
|
var import_dist3 = __toESM(require_dist2(), 1);
|
|
3253
3271
|
import { existsSync, mkdirSync, readFileSync, appendFileSync, readdirSync, statSync } from "fs";
|
|
3254
|
-
import { homedir } from "os";
|
|
3255
3272
|
import { dirname, join, resolve } from "path";
|
|
3256
|
-
function configDirName() {
|
|
3257
|
-
const platformRoot5 = process.env.MAXY_PLATFORM_ROOT ?? resolve(process.cwd(), "..");
|
|
3258
|
-
const brandPath = join(platformRoot5, "config", "brand.json");
|
|
3259
|
-
if (existsSync(brandPath)) {
|
|
3260
|
-
try {
|
|
3261
|
-
return JSON.parse(readFileSync(brandPath, "utf-8")).configDir ?? ".maxy";
|
|
3262
|
-
} catch {
|
|
3263
|
-
}
|
|
3264
|
-
}
|
|
3265
|
-
return ".maxy";
|
|
3266
|
-
}
|
|
3267
3273
|
function isUpdateRecord(r) {
|
|
3268
3274
|
return r.kind === "update";
|
|
3269
3275
|
}
|
|
3270
|
-
var STORE_ROOT2 = () =>
|
|
3276
|
+
var STORE_ROOT2 = () => (0, import_dist2.telegramStoreRoot)(process.env.MAXY_PLATFORM_ROOT ?? resolve(process.cwd(), ".."));
|
|
3271
3277
|
function conversationFile(accountId, channelKey) {
|
|
3272
3278
|
return join(STORE_ROOT2(), accountId, `${(0, import_dist2.channelKeyToFileStem)(channelKey)}.jsonl`);
|
|
3273
3279
|
}
|
|
@@ -6315,7 +6321,7 @@ async function scanAiTitleIncremental(path, size, prior) {
|
|
|
6315
6321
|
|
|
6316
6322
|
// ../services/claude-session-manager/src/jsonl-path.ts
|
|
6317
6323
|
import { existsSync as existsSync4, readdirSync as readdirSync3 } from "fs";
|
|
6318
|
-
import { homedir
|
|
6324
|
+
import { homedir } from "os";
|
|
6319
6325
|
import { join as join9 } from "path";
|
|
6320
6326
|
function findExistingJsonlForSessionId(claudeConfigDir2, sessionId) {
|
|
6321
6327
|
const projectsRoot = join9(claudeConfigDir2, "projects");
|
|
@@ -7359,7 +7365,7 @@ async function defaultHttpGet(url) {
|
|
|
7359
7365
|
}
|
|
7360
7366
|
}
|
|
7361
7367
|
async function defaultResolve(accountId) {
|
|
7362
|
-
const { resolveSocket: resolveSocket2 } = await import("./manager-
|
|
7368
|
+
const { resolveSocket: resolveSocket2 } = await import("./manager-7BXVB76I.js");
|
|
7363
7369
|
return resolveSocket2(accountId);
|
|
7364
7370
|
}
|
|
7365
7371
|
async function fetchAvatar(accountId, jid, deps = {}) {
|
|
@@ -7776,6 +7782,60 @@ function parseInline(text) {
|
|
|
7776
7782
|
return parts;
|
|
7777
7783
|
}
|
|
7778
7784
|
|
|
7785
|
+
// app/lib/telegram/outbound/chunk-text.ts
|
|
7786
|
+
var TELEGRAM_TEXT_LIMIT = 4096;
|
|
7787
|
+
function fenceRanges(text) {
|
|
7788
|
+
const ranges = [];
|
|
7789
|
+
let open3 = -1;
|
|
7790
|
+
let pos = 0;
|
|
7791
|
+
for (const line of text.split("\n")) {
|
|
7792
|
+
if (FENCE.test(line)) {
|
|
7793
|
+
if (open3 === -1) open3 = pos;
|
|
7794
|
+
else {
|
|
7795
|
+
ranges.push([open3, pos + line.length]);
|
|
7796
|
+
open3 = -1;
|
|
7797
|
+
}
|
|
7798
|
+
}
|
|
7799
|
+
pos += line.length + 1;
|
|
7800
|
+
}
|
|
7801
|
+
if (open3 !== -1) ranges.push([open3, text.length]);
|
|
7802
|
+
return ranges;
|
|
7803
|
+
}
|
|
7804
|
+
function surrogateSafe(text, end) {
|
|
7805
|
+
const code = text.charCodeAt(end - 1);
|
|
7806
|
+
return code >= 55296 && code <= 56319 ? end - 1 : end;
|
|
7807
|
+
}
|
|
7808
|
+
function cutPoint(text, start, limit, fences) {
|
|
7809
|
+
const end = start + limit;
|
|
7810
|
+
const insideFence = (cut) => fences.some(([o, c]) => c - o <= limit && o < cut && cut < c);
|
|
7811
|
+
for (const [needle, width] of [
|
|
7812
|
+
["\n\n", 2],
|
|
7813
|
+
["\n", 1],
|
|
7814
|
+
[" ", 1]
|
|
7815
|
+
]) {
|
|
7816
|
+
let idx = text.lastIndexOf(needle, end - width);
|
|
7817
|
+
while (idx > start) {
|
|
7818
|
+
const cut = idx + width;
|
|
7819
|
+
if (!insideFence(cut)) return cut;
|
|
7820
|
+
idx = text.lastIndexOf(needle, idx - 1);
|
|
7821
|
+
}
|
|
7822
|
+
}
|
|
7823
|
+
return surrogateSafe(text, end);
|
|
7824
|
+
}
|
|
7825
|
+
function chunkForTelegram(text, limit = TELEGRAM_TEXT_LIMIT) {
|
|
7826
|
+
if (text.length <= limit) return [text];
|
|
7827
|
+
const fences = fenceRanges(text);
|
|
7828
|
+
const chunks = [];
|
|
7829
|
+
let start = 0;
|
|
7830
|
+
while (text.length - start > limit) {
|
|
7831
|
+
const cut = cutPoint(text, start, limit, fences);
|
|
7832
|
+
chunks.push(text.slice(start, cut));
|
|
7833
|
+
start = cut;
|
|
7834
|
+
}
|
|
7835
|
+
chunks.push(text.slice(start));
|
|
7836
|
+
return chunks;
|
|
7837
|
+
}
|
|
7838
|
+
|
|
7779
7839
|
// app/lib/telegram/outbound/outbound-census.ts
|
|
7780
7840
|
var WINDOW_MS = 60 * 60 * 1e3;
|
|
7781
7841
|
var records = [];
|
|
@@ -7829,30 +7889,31 @@ async function sendTelegramText(botToken, chatId, text, messageThreadId, busines
|
|
|
7829
7889
|
console.error(
|
|
7830
7890
|
`${TAG11} op=error botId=${botId} chatId=${chatId} stage=rich description="${richError}"`
|
|
7831
7891
|
);
|
|
7832
|
-
|
|
7833
|
-
|
|
7834
|
-
|
|
7835
|
-
|
|
7836
|
-
|
|
7837
|
-
|
|
7838
|
-
|
|
7839
|
-
|
|
7840
|
-
|
|
7841
|
-
|
|
7842
|
-
|
|
7892
|
+
const chunks = chunkForTelegram(text);
|
|
7893
|
+
console.error(
|
|
7894
|
+
`${TAG11} op=fallback botId=${botId} chatId=${chatId} chunks=${chunks.length} reason="${richError}"`
|
|
7895
|
+
);
|
|
7896
|
+
for (let i = 0; i < chunks.length; i += 1) {
|
|
7897
|
+
let error = "";
|
|
7898
|
+
try {
|
|
7899
|
+
const data = await post(botToken, "sendMessage", {
|
|
7900
|
+
chat_id: chatId,
|
|
7901
|
+
text: chunks[i],
|
|
7902
|
+
...thread,
|
|
7903
|
+
...businessConnectionId ? { business_connection_id: businessConnectionId } : {}
|
|
7904
|
+
});
|
|
7905
|
+
if (data.ok) continue;
|
|
7906
|
+
error = data.description ?? "send failed";
|
|
7907
|
+
} catch (e) {
|
|
7908
|
+
error = e instanceof Error ? e.message : String(e);
|
|
7843
7909
|
}
|
|
7844
|
-
const error = data.description ?? "send failed";
|
|
7845
7910
|
console.error(
|
|
7846
|
-
`${TAG11} op=error botId=${botId} chatId=${chatId} stage=plain description="${error}"`
|
|
7847
|
-
);
|
|
7848
|
-
return { ok: false, error };
|
|
7849
|
-
} catch (e) {
|
|
7850
|
-
const error = e instanceof Error ? e.message : String(e);
|
|
7851
|
-
console.error(
|
|
7852
|
-
`${TAG11} op=error botId=${botId} chatId=${chatId} stage=plain description="${error}"`
|
|
7911
|
+
`${TAG11} op=error botId=${botId} chatId=${chatId} stage=plain chunk=${i + 1}/${chunks.length} description="${error}"`
|
|
7853
7912
|
);
|
|
7854
7913
|
return { ok: false, error };
|
|
7855
7914
|
}
|
|
7915
|
+
noteTelegramOutbound("fallback", Date.now());
|
|
7916
|
+
return { ok: true };
|
|
7856
7917
|
}
|
|
7857
7918
|
|
|
7858
7919
|
// app/lib/telegram/outbound/send-chat-action.ts
|
|
@@ -13715,6 +13776,7 @@ function runGooglePendingAudit(accountsDir, nowMs, emit, readMtimeMs = (path) =>
|
|
|
13715
13776
|
import { existsSync as existsSync15, readFileSync as readFileSync18, readdirSync as readdirSync11, statSync as statSync10, writeFileSync as writeFileSync8 } from "fs";
|
|
13716
13777
|
import { basename as basename5, join as join23, resolve as resolve16 } from "path";
|
|
13717
13778
|
var TAG23 = "[identity-reconcile]";
|
|
13779
|
+
var ADMIN_IDENTITY_MANDATE_PLACEHOLDER = "{{productMandate}}";
|
|
13718
13780
|
var ADMIN_IDENTITY_RECONCILE_INTERVAL_MS = 36e5;
|
|
13719
13781
|
function adminIdentityTemplatePath(platformRoot5) {
|
|
13720
13782
|
return resolve16(platformRoot5, "templates", "agents", "admin", "IDENTITY.md");
|
|
@@ -13775,7 +13837,24 @@ function reconcileAdminIdentity(accountDir, templatePath) {
|
|
|
13775
13837
|
};
|
|
13776
13838
|
}
|
|
13777
13839
|
function runAdminIdentityReconcile(opts) {
|
|
13778
|
-
const census = {
|
|
13840
|
+
const census = {
|
|
13841
|
+
accounts: 0,
|
|
13842
|
+
current: 0,
|
|
13843
|
+
rewritten: 0,
|
|
13844
|
+
failed: 0,
|
|
13845
|
+
mandatePlaceholder: false
|
|
13846
|
+
};
|
|
13847
|
+
let templateBytes = 0;
|
|
13848
|
+
try {
|
|
13849
|
+
const template = readFileSync18(opts.templatePath, "utf-8");
|
|
13850
|
+
templateBytes = Buffer.byteLength(template);
|
|
13851
|
+
census.mandatePlaceholder = template.includes(ADMIN_IDENTITY_MANDATE_PLACEHOLDER);
|
|
13852
|
+
} catch {
|
|
13853
|
+
census.mandatePlaceholder = false;
|
|
13854
|
+
}
|
|
13855
|
+
opts.emit(
|
|
13856
|
+
`${TAG23} op=template mandatePlaceholder=${census.mandatePlaceholder} bytes=${templateBytes}`
|
|
13857
|
+
);
|
|
13779
13858
|
let entries2 = [];
|
|
13780
13859
|
try {
|
|
13781
13860
|
entries2 = readdirSync11(opts.accountsDir, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name).sort();
|
|
@@ -13795,7 +13874,7 @@ function runAdminIdentityReconcile(opts) {
|
|
|
13795
13874
|
);
|
|
13796
13875
|
}
|
|
13797
13876
|
opts.emit(
|
|
13798
|
-
`${TAG23} op=census accounts=${census.accounts} current=${census.current} rewritten=${census.rewritten} failed=${census.failed}`
|
|
13877
|
+
`${TAG23} op=census accounts=${census.accounts} current=${census.current} rewritten=${census.rewritten} failed=${census.failed} mandatePlaceholder=${census.mandatePlaceholder}`
|
|
13799
13878
|
);
|
|
13800
13879
|
return census;
|
|
13801
13880
|
}
|
|
@@ -15207,6 +15286,7 @@ function runTelegramStoreCensus() {
|
|
|
15207
15286
|
|
|
15208
15287
|
// app/lib/telegram/reach-census.ts
|
|
15209
15288
|
var import_dist4 = __toESM(require_dist2(), 1);
|
|
15289
|
+
import { existsSync as existsSync19 } from "fs";
|
|
15210
15290
|
import { join as join27 } from "path";
|
|
15211
15291
|
function collectTelegramReachCensus(accounts) {
|
|
15212
15292
|
const out = {
|
|
@@ -15231,8 +15311,9 @@ function collectTelegramReachCensus(accounts) {
|
|
|
15231
15311
|
}
|
|
15232
15312
|
function runTelegramReachCensus(accounts) {
|
|
15233
15313
|
const c = collectTelegramReachCensus(accounts);
|
|
15314
|
+
const root = STORE_ROOT2();
|
|
15234
15315
|
console.error(
|
|
15235
|
-
`[telegram-reach-census] accounts=${c.accounts} bots=${c.bots} chatsKnown=${c.chatsKnown} botsWithNoChats=${c.botsWithNoChats}`
|
|
15316
|
+
`[telegram-reach-census] accounts=${c.accounts} bots=${c.bots} chatsKnown=${c.chatsKnown} botsWithNoChats=${c.botsWithNoChats} storeRoot=${root} exists=${existsSync19(root)}`
|
|
15236
15317
|
);
|
|
15237
15318
|
return c;
|
|
15238
15319
|
}
|
|
@@ -15247,10 +15328,6 @@ function noteCheckoutArrived(botId, queryId, now) {
|
|
|
15247
15328
|
arrived += 1;
|
|
15248
15329
|
outstanding.set(queryId, { botId, arrivedAt: now });
|
|
15249
15330
|
}
|
|
15250
|
-
function noteCheckoutAnswered(queryId) {
|
|
15251
|
-
if (!outstanding.delete(queryId)) return;
|
|
15252
|
-
answered += 1;
|
|
15253
|
-
}
|
|
15254
15331
|
function readTelegramCheckoutCensus(now) {
|
|
15255
15332
|
let oldestUnansweredMs = 0;
|
|
15256
15333
|
for (const o of outstanding.values()) {
|
|
@@ -15355,7 +15432,7 @@ function readWaOperatorTurns() {
|
|
|
15355
15432
|
}
|
|
15356
15433
|
|
|
15357
15434
|
// server/routes/session-reader.ts
|
|
15358
|
-
import { readFileSync as readFileSync22, watch as watch4, statSync as statSync15, existsSync as
|
|
15435
|
+
import { readFileSync as readFileSync22, watch as watch4, statSync as statSync15, existsSync as existsSync20, readdirSync as readdirSync14, realpathSync as realpathSync5 } from "fs";
|
|
15359
15436
|
import { isAbsolute as isAbsolute2, join as join29, relative as relative3, resolve as resolve21, sep as sep5 } from "path";
|
|
15360
15437
|
|
|
15361
15438
|
// server/routes/admin/manager-client.ts
|
|
@@ -15572,7 +15649,7 @@ data: ${JSON.stringify(turn)}
|
|
|
15572
15649
|
const sessionKey = c.req.query("session_key") ?? "";
|
|
15573
15650
|
const subagentsDir = resolve21(join29(projectDir, sessionId, "subagents"));
|
|
15574
15651
|
console.log(
|
|
15575
|
-
`[webchat-activity] op=watch-subagents key=${sessionKey} dir=${subagentsDir} exists=${
|
|
15652
|
+
`[webchat-activity] op=watch-subagents key=${sessionKey} dir=${subagentsDir} exists=${existsSync20(subagentsDir)}`
|
|
15576
15653
|
);
|
|
15577
15654
|
const actx = makeActivityCtx({
|
|
15578
15655
|
subagentsDir,
|
|
@@ -15779,7 +15856,7 @@ app7.get("/directives", requireAdminSession, (c) => {
|
|
|
15779
15856
|
const sessionId = c.req.query("sessionId") ?? "";
|
|
15780
15857
|
if (!SESSION_ID_RE2.test(sessionId)) return c.json({ error: "bad session reference" }, 400);
|
|
15781
15858
|
const dir = directiveStoreDir(sessionId);
|
|
15782
|
-
if (!dir || !
|
|
15859
|
+
if (!dir || !existsSync20(dir)) return c.json({ entries: [] });
|
|
15783
15860
|
let names;
|
|
15784
15861
|
try {
|
|
15785
15862
|
names = readdirSync14(dir).filter((n) => DIRECTIVE_NAME_RE.test(n));
|
|
@@ -16675,7 +16752,7 @@ var public_reader_default = app9;
|
|
|
16675
16752
|
// server/routes/webchat.ts
|
|
16676
16753
|
import { basename as basename11, dirname as dirname11 } from "path";
|
|
16677
16754
|
import { join as join34 } from "path";
|
|
16678
|
-
import { existsSync as
|
|
16755
|
+
import { existsSync as existsSync23, readdirSync as readdirSync18, readFileSync as readFileSync27, renameSync as renameSync4, statSync as statSync18, writeFileSync as writeFileSync11 } from "fs";
|
|
16679
16756
|
|
|
16680
16757
|
// server/canonical-webchat-override.ts
|
|
16681
16758
|
import { readFileSync as readFileSync25, writeFileSync as writeFileSync9, renameSync as renameSync2 } from "fs";
|
|
@@ -16787,7 +16864,7 @@ function isNewSessionEffortLevel(value) {
|
|
|
16787
16864
|
}
|
|
16788
16865
|
|
|
16789
16866
|
// ../services/claude-session-manager/src/sidecar-store.ts
|
|
16790
|
-
import { existsSync as
|
|
16867
|
+
import { existsSync as existsSync22, mkdirSync as mkdirSync4, readdirSync as readdirSync17, readFileSync as readFileSync26, renameSync as renameSync3, unlinkSync as unlinkSync2, writeFileSync as writeFileSync10 } from "fs";
|
|
16791
16868
|
import { join as join33 } from "path";
|
|
16792
16869
|
function escapeRegExp(s) {
|
|
16793
16870
|
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
@@ -16808,7 +16885,7 @@ function createSidecarStore(config) {
|
|
|
16808
16885
|
return { ok: true };
|
|
16809
16886
|
} catch (error) {
|
|
16810
16887
|
try {
|
|
16811
|
-
if (
|
|
16888
|
+
if (existsSync22(tmp)) unlinkSync2(tmp);
|
|
16812
16889
|
} catch {
|
|
16813
16890
|
}
|
|
16814
16891
|
return { ok: false, error };
|
|
@@ -16864,7 +16941,7 @@ function createSidecarStore(config) {
|
|
|
16864
16941
|
function clear(sessionsDir, id) {
|
|
16865
16942
|
const path = pathFor(sessionsDir, id);
|
|
16866
16943
|
try {
|
|
16867
|
-
if (
|
|
16944
|
+
if (existsSync22(path)) {
|
|
16868
16945
|
unlinkSync2(path);
|
|
16869
16946
|
return { ok: true, removed: true };
|
|
16870
16947
|
}
|
|
@@ -16960,7 +17037,7 @@ function locateSidecar(sessionId) {
|
|
|
16960
17037
|
}
|
|
16961
17038
|
for (const slug of slugs) {
|
|
16962
17039
|
const metaPath = join34(projectsRoot, slug, `${sessionId}.meta.json`);
|
|
16963
|
-
if (
|
|
17040
|
+
if (existsSync23(metaPath)) return readSidecarMeta(metaPath);
|
|
16964
17041
|
}
|
|
16965
17042
|
return null;
|
|
16966
17043
|
}
|
|
@@ -17553,10 +17630,10 @@ ${note}` : note;
|
|
|
17553
17630
|
import { resolve as resolve24 } from "path";
|
|
17554
17631
|
|
|
17555
17632
|
// app/lib/claude-agent/specialist-roster.ts
|
|
17556
|
-
import { existsSync as
|
|
17633
|
+
import { existsSync as existsSync24, readFileSync as readFileSync28, readdirSync as readdirSync19 } from "fs";
|
|
17557
17634
|
import { join as join35 } from "path";
|
|
17558
17635
|
function listSpecialistCardNames(specialistsDir) {
|
|
17559
|
-
if (!
|
|
17636
|
+
if (!existsSync24(specialistsDir)) return [];
|
|
17560
17637
|
return readdirSync19(specialistsDir).filter((f) => f.endsWith(".md")).map((f) => f.slice(0, -3)).sort();
|
|
17561
17638
|
}
|
|
17562
17639
|
function field(fm, name) {
|
|
@@ -17569,7 +17646,7 @@ function field(fm, name) {
|
|
|
17569
17646
|
return value || null;
|
|
17570
17647
|
}
|
|
17571
17648
|
function readSpecialistRoster(specialistsDir) {
|
|
17572
|
-
if (!
|
|
17649
|
+
if (!existsSync24(specialistsDir)) return { specialists: [], skipped: [] };
|
|
17573
17650
|
const entries2 = readdirSync19(specialistsDir);
|
|
17574
17651
|
const specialists = [];
|
|
17575
17652
|
const skipped = [];
|
|
@@ -17693,13 +17770,13 @@ function r2n(value) {
|
|
|
17693
17770
|
var webchat_greeting_default = app10;
|
|
17694
17771
|
|
|
17695
17772
|
// server/routes/telegram.ts
|
|
17696
|
-
import { homedir as
|
|
17773
|
+
import { homedir as homedir2 } from "os";
|
|
17697
17774
|
import { resolve as resolve25, join as join40 } from "path";
|
|
17698
|
-
import { existsSync as
|
|
17775
|
+
import { existsSync as existsSync28, readFileSync as readFileSync32 } from "fs";
|
|
17699
17776
|
|
|
17700
17777
|
// ../lib/telegram-managed-bot/src/index.ts
|
|
17701
17778
|
import { randomBytes } from "crypto";
|
|
17702
|
-
import { existsSync as
|
|
17779
|
+
import { existsSync as existsSync25, readFileSync as readFileSync29, writeFileSync as writeFileSync12, mkdirSync as mkdirSync5 } from "fs";
|
|
17703
17780
|
import { dirname as dirname12, join as join36 } from "path";
|
|
17704
17781
|
var TELEGRAM_API = "https://api.telegram.org";
|
|
17705
17782
|
var TELEGRAM_ALLOWED_UPDATES = [
|
|
@@ -17768,7 +17845,7 @@ async function setTelegramWebhook(botToken, webhookUrl, secretFilePath, fetchImp
|
|
|
17768
17845
|
}
|
|
17769
17846
|
function writeTelegramBotEntry(accountDir, entry2) {
|
|
17770
17847
|
const configPath3 = join36(accountDir, "account.json");
|
|
17771
|
-
if (!
|
|
17848
|
+
if (!existsSync25(configPath3)) {
|
|
17772
17849
|
return { ok: false, error: `account.json not found at ${configPath3}` };
|
|
17773
17850
|
}
|
|
17774
17851
|
let config;
|
|
@@ -18966,25 +19043,6 @@ async function answerTelegramCallback(botToken, callbackQueryId, text) {
|
|
|
18966
19043
|
}
|
|
18967
19044
|
}
|
|
18968
19045
|
|
|
18969
|
-
// app/lib/telegram/outbound/answer-precheckout.ts
|
|
18970
|
-
async function answerTelegramPreCheckout(botToken, preCheckoutQueryId, ok2, errorMessage) {
|
|
18971
|
-
try {
|
|
18972
|
-
const res = await fetch(`https://api.telegram.org/bot${botToken}/answerPreCheckoutQuery`, {
|
|
18973
|
-
method: "POST",
|
|
18974
|
-
headers: { "Content-Type": "application/json" },
|
|
18975
|
-
body: JSON.stringify({
|
|
18976
|
-
pre_checkout_query_id: preCheckoutQueryId,
|
|
18977
|
-
ok: ok2,
|
|
18978
|
-
...ok2 ? {} : { error_message: errorMessage ?? "This payment cannot be completed." }
|
|
18979
|
-
})
|
|
18980
|
-
});
|
|
18981
|
-
const data = await res.json();
|
|
18982
|
-
return data.ok ? { ok: true } : { ok: false, error: data.description ?? "answer failed" };
|
|
18983
|
-
} catch (e) {
|
|
18984
|
-
return { ok: false, error: e instanceof Error ? e.message : String(e) };
|
|
18985
|
-
}
|
|
18986
|
-
}
|
|
18987
|
-
|
|
18988
19046
|
// app/lib/telegram/inbound/notify-gate.ts
|
|
18989
19047
|
function decideTelegramNotify(input) {
|
|
18990
19048
|
if (input.messageId === null) return { emit: false, reason: "no-id" };
|
|
@@ -19599,7 +19657,7 @@ async function handleDispatchMedia(p) {
|
|
|
19599
19657
|
}
|
|
19600
19658
|
|
|
19601
19659
|
// app/lib/telegram/live-location.ts
|
|
19602
|
-
import { existsSync as
|
|
19660
|
+
import { existsSync as existsSync26, mkdirSync as mkdirSync6, readFileSync as readFileSync30, readdirSync as readdirSync20, statSync as statSync19, writeFileSync as writeFileSync13 } from "fs";
|
|
19603
19661
|
import { join as join38 } from "path";
|
|
19604
19662
|
var TAG32 = "[telegram-inbound]";
|
|
19605
19663
|
var LIVE_LOCATION_FILE = "telegram-live-location.json";
|
|
@@ -19613,7 +19671,7 @@ function isRecord(v) {
|
|
|
19613
19671
|
return typeof r.lat === "number" && Number.isFinite(r.lat) && typeof r.lon === "number" && Number.isFinite(r.lon) && typeof r.at === "number" && Number.isFinite(r.at) && typeof r.botId === "string" && typeof r.livePeriodS === "number" && Number.isFinite(r.livePeriodS);
|
|
19614
19672
|
}
|
|
19615
19673
|
function readAll(path) {
|
|
19616
|
-
if (!
|
|
19674
|
+
if (!existsSync26(path)) return {};
|
|
19617
19675
|
try {
|
|
19618
19676
|
const parsed = JSON.parse(readFileSync30(path, "utf-8"));
|
|
19619
19677
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
|
|
@@ -19683,7 +19741,7 @@ function liveLocationCensusLine(accountsRoot, now) {
|
|
|
19683
19741
|
try {
|
|
19684
19742
|
for (const entry2 of readdirSync20(accountsRoot)) {
|
|
19685
19743
|
const path = join38(accountsRoot, entry2, LIVE_LOCATION_FILE);
|
|
19686
|
-
if (!
|
|
19744
|
+
if (!existsSync26(path) || !statSync19(path).isFile()) continue;
|
|
19687
19745
|
for (const rec of Object.values(readAll(path))) {
|
|
19688
19746
|
records3 += 1;
|
|
19689
19747
|
if (isExpired(rec, now)) expired += 1;
|
|
@@ -19702,7 +19760,7 @@ function liveLocationCensusLine(accountsRoot, now) {
|
|
|
19702
19760
|
}
|
|
19703
19761
|
|
|
19704
19762
|
// app/lib/telegram/business-connection.ts
|
|
19705
|
-
import { existsSync as
|
|
19763
|
+
import { existsSync as existsSync27, mkdirSync as mkdirSync7, readFileSync as readFileSync31, writeFileSync as writeFileSync14 } from "fs";
|
|
19706
19764
|
import { join as join39 } from "path";
|
|
19707
19765
|
var TAG33 = "[telegram-inbound]";
|
|
19708
19766
|
var BUSINESS_CONNECTION_FILE = "telegram-business-connection.json";
|
|
@@ -19715,7 +19773,7 @@ function isRecord2(v) {
|
|
|
19715
19773
|
return typeof r.id === "string" && r.id.length > 0 && typeof r.isEnabled === "boolean";
|
|
19716
19774
|
}
|
|
19717
19775
|
function readAll2(path) {
|
|
19718
|
-
if (!
|
|
19776
|
+
if (!existsSync27(path)) return {};
|
|
19719
19777
|
try {
|
|
19720
19778
|
const parsed = JSON.parse(readFileSync31(path, "utf-8"));
|
|
19721
19779
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
|
|
@@ -19836,10 +19894,10 @@ function entryActive(entry2, accountDir, botId, noteSpecialist) {
|
|
|
19836
19894
|
function logValue2(v) {
|
|
19837
19895
|
return v.replace(/[\r\n]+/g, " ");
|
|
19838
19896
|
}
|
|
19839
|
-
function
|
|
19897
|
+
function configDirName() {
|
|
19840
19898
|
const platformRoot5 = process.env.MAXY_PLATFORM_ROOT ?? resolve25(process.cwd(), "..");
|
|
19841
19899
|
const brandPath = join40(platformRoot5, "config", "brand.json");
|
|
19842
|
-
if (
|
|
19900
|
+
if (existsSync28(brandPath)) {
|
|
19843
19901
|
try {
|
|
19844
19902
|
return JSON.parse(readFileSync32(brandPath, "utf-8")).configDir ?? ".maxy";
|
|
19845
19903
|
} catch {
|
|
@@ -19848,7 +19906,7 @@ function configDirName2() {
|
|
|
19848
19906
|
return ".maxy";
|
|
19849
19907
|
}
|
|
19850
19908
|
function telegramSecretsDir() {
|
|
19851
|
-
return resolve25(
|
|
19909
|
+
return resolve25(homedir2(), configDirName(), "telegram-secrets");
|
|
19852
19910
|
}
|
|
19853
19911
|
function secretPath(botId) {
|
|
19854
19912
|
return resolve25(telegramSecretsDir(), botId);
|
|
@@ -19947,7 +20005,7 @@ app11.post("/", async (c) => {
|
|
|
19947
20005
|
const agentSlug = entryAgentSlug(entry2);
|
|
19948
20006
|
console.error(`${TAG34} op=entry botId=${botId} accountId=${accountId} role=${entry2.role} agent=${agentSlug}`);
|
|
19949
20007
|
const sp = secretPath(botId);
|
|
19950
|
-
if (!
|
|
20008
|
+
if (!existsSync28(sp)) {
|
|
19951
20009
|
console.error(`${TAG34} op=secret botId=${botId} result=missing-file`);
|
|
19952
20010
|
return c.json({ ok: false }, 401);
|
|
19953
20011
|
}
|
|
@@ -20250,69 +20308,19 @@ app11.post("/", async (c) => {
|
|
|
20250
20308
|
return c.json({ ok: true }, 200);
|
|
20251
20309
|
}
|
|
20252
20310
|
if (decision.kind === "checkout") {
|
|
20253
|
-
const cKey = telegramChannelKey(botId, decision.senderId);
|
|
20254
20311
|
if (decision.query === "pre-checkout") {
|
|
20255
20312
|
console.error(
|
|
20256
20313
|
`${TAG34} op=precheckout-received botId=${botId} queryId=${decision.queryId} payload=${logValue2(decision.payload)} amount=${decision.amount ?? "none"} currency=${decision.currency ?? "none"}`
|
|
20257
20314
|
);
|
|
20258
20315
|
noteCheckoutArrived(botId, decision.queryId, Date.now());
|
|
20259
|
-
const answerStartedAt = Date.now();
|
|
20260
|
-
const answered4 = decision.allowed ? await answerTelegramPreCheckout(entry2.token, decision.queryId, true) : await answerTelegramPreCheckout(
|
|
20261
|
-
entry2.token,
|
|
20262
|
-
decision.queryId,
|
|
20263
|
-
false,
|
|
20264
|
-
"This account cannot complete a payment here."
|
|
20265
|
-
);
|
|
20266
|
-
if (answered4.ok) noteCheckoutAnswered(decision.queryId);
|
|
20267
|
-
console.error(
|
|
20268
|
-
`${TAG34} op=precheckout-answered botId=${botId} queryId=${decision.queryId} ms=${Date.now() - answerStartedAt} ok=${answered4.ok} outcome=${!answered4.ok ? "error" : decision.allowed ? "accepted" : "refused"}${answered4.error ? ` error=${logValue2(answered4.error)}` : ""}`
|
|
20269
|
-
);
|
|
20270
20316
|
} else {
|
|
20271
20317
|
console.error(
|
|
20272
20318
|
`${TAG34} op=shipping-received botId=${botId} queryId=${decision.queryId} payload=${logValue2(decision.payload)}`
|
|
20273
20319
|
);
|
|
20274
20320
|
}
|
|
20275
20321
|
console.error(
|
|
20276
|
-
`${TAG34} op=checkout-
|
|
20322
|
+
`${TAG34} op=checkout-ignored botId=${botId} senderId=${decision.senderId} queryId=${decision.queryId} query=${decision.query} allowed=${decision.allowed} reason=payments-removed`
|
|
20277
20323
|
);
|
|
20278
|
-
if (!decision.allowed) return c.json({ ok: true }, 200);
|
|
20279
|
-
const cScope = entry2.role === "admin" ? "admin" : "public";
|
|
20280
|
-
const cSession = telegramAdminSessionId(accountId, decision.senderId, botId);
|
|
20281
|
-
const cAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
20282
|
-
const cBody = decision.query === "pre-checkout" ? `[pre-checkout approved: ${decision.amount ?? 0} ${decision.currency ?? "unknown"}, payload=${decision.payload}]` : `[shipping query: payload=${decision.payload}, queryId=${decision.queryId} \u2014 answer with telegram-invoice answerShipping]`;
|
|
20283
|
-
appendMessage2(accountId, {
|
|
20284
|
-
messageId: `telegram:${accountId}:${cKey}:checkout:${decision.queryId}`,
|
|
20285
|
-
sessionId: cSession,
|
|
20286
|
-
dateSent: cAt,
|
|
20287
|
-
body: cBody,
|
|
20288
|
-
fromMe: false,
|
|
20289
|
-
senderId: decision.senderId,
|
|
20290
|
-
senderName: decision.senderDisplay,
|
|
20291
|
-
chatId: String(decision.chatId),
|
|
20292
|
-
channelKey: cKey,
|
|
20293
|
-
scope: cScope,
|
|
20294
|
-
origin: "inbound",
|
|
20295
|
-
createdAt: cAt
|
|
20296
|
-
});
|
|
20297
|
-
const cActive = entryActive(entry2, accountDir, botId);
|
|
20298
|
-
console.error(`${TAG34} op=agent botId=${botId} slug=${agentSlug} active=${cActive}`);
|
|
20299
|
-
raiseChannelTurn({
|
|
20300
|
-
accountId,
|
|
20301
|
-
accountDir,
|
|
20302
|
-
botId,
|
|
20303
|
-
botToken: entry2.token,
|
|
20304
|
-
role: entry2.role,
|
|
20305
|
-
agentSlug,
|
|
20306
|
-
specialist: entry2.role === "specialist" ? entry2.specialist : null,
|
|
20307
|
-
active: cActive,
|
|
20308
|
-
senderId: decision.senderId,
|
|
20309
|
-
senderDisplay: decision.senderDisplay,
|
|
20310
|
-
chatId: decision.chatId,
|
|
20311
|
-
text: cBody,
|
|
20312
|
-
channelKey: cKey,
|
|
20313
|
-
scope: cScope,
|
|
20314
|
-
sessionId: cSession
|
|
20315
|
-
});
|
|
20316
20324
|
return c.json({ ok: true }, 200);
|
|
20317
20325
|
}
|
|
20318
20326
|
if (decision.kind === "subscription") {
|
|
@@ -20928,7 +20936,7 @@ function mountTelegramRoutes(app81, telegramRoutes) {
|
|
|
20928
20936
|
|
|
20929
20937
|
// server/routes/quickbooks.ts
|
|
20930
20938
|
import { join as join41 } from "path";
|
|
20931
|
-
import { existsSync as
|
|
20939
|
+
import { existsSync as existsSync29, readFileSync as readFileSync33, writeFileSync as writeFileSync15, mkdirSync as mkdirSync8, rmSync as rmSync4, renameSync as renameSync5 } from "fs";
|
|
20932
20940
|
var TAG35 = "[quickbooks]";
|
|
20933
20941
|
var INTUIT_TOKEN_URL = "https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer";
|
|
20934
20942
|
var STATE_RE = /^[A-Za-z0-9_-]+$/;
|
|
@@ -20941,7 +20949,7 @@ function storePath(accountDir) {
|
|
|
20941
20949
|
async function completeConsent(args) {
|
|
20942
20950
|
const { accountDir, code, realmId } = args;
|
|
20943
20951
|
const state = args.state;
|
|
20944
|
-
if (!state || !STATE_RE.test(state) || !
|
|
20952
|
+
if (!state || !STATE_RE.test(state) || !existsSync29(pendingPath(accountDir, state))) {
|
|
20945
20953
|
console.error(`${TAG35} op=callback state=${state ?? ""} stateValid=false realmId=${realmId ?? ""}`);
|
|
20946
20954
|
return { ok: false, status: 400, message: "Invalid or unknown authorization state.", stateValid: false };
|
|
20947
20955
|
}
|
|
@@ -20968,7 +20976,7 @@ async function completeConsent(args) {
|
|
|
20968
20976
|
if (!code || !realmId) {
|
|
20969
20977
|
return { ok: false, status: 400, message: "Missing code or realmId in the callback.", stateValid: true };
|
|
20970
20978
|
}
|
|
20971
|
-
if (!
|
|
20979
|
+
if (!existsSync29(storePath(accountDir))) {
|
|
20972
20980
|
return { ok: false, status: 500, message: "No QuickBooks credentials are stored for this account.", stateValid: true };
|
|
20973
20981
|
}
|
|
20974
20982
|
const store2 = JSON.parse(readFileSync33(storePath(accountDir), "utf-8"));
|
|
@@ -21036,7 +21044,7 @@ var quickbooks_default = app12;
|
|
|
21036
21044
|
|
|
21037
21045
|
// server/routes/onboarding.ts
|
|
21038
21046
|
import { spawn, spawnSync as spawnSync2, execFileSync as execFileSync4 } from "child_process";
|
|
21039
|
-
import { openSync as openSync8, closeSync as closeSync8, appendFileSync as appendFileSync3, writeFileSync as writeFileSync17, writeSync, existsSync as
|
|
21047
|
+
import { openSync as openSync8, closeSync as closeSync8, appendFileSync as appendFileSync3, writeFileSync as writeFileSync17, writeSync, existsSync as existsSync31, readFileSync as readFileSync35, unlinkSync as unlinkSync3 } from "fs";
|
|
21040
21048
|
import { createHash as createHash4, randomUUID as randomUUID4 } from "crypto";
|
|
21041
21049
|
|
|
21042
21050
|
// app/lib/claude-spawn-env.ts
|
|
@@ -21176,7 +21184,7 @@ function readHostCredsBlob(service) {
|
|
|
21176
21184
|
}
|
|
21177
21185
|
|
|
21178
21186
|
// ../lib/admins-write/src/index.ts
|
|
21179
|
-
import { existsSync as
|
|
21187
|
+
import { existsSync as existsSync30, readFileSync as readFileSync34, writeFileSync as writeFileSync16, renameSync as renameSync6, mkdirSync as mkdirSync9, readdirSync as readdirSync21, statSync as statSync20, appendFileSync as appendFileSync2 } from "fs";
|
|
21180
21188
|
import { dirname as dirname13, join as join42 } from "path";
|
|
21181
21189
|
function id8(value) {
|
|
21182
21190
|
return value.slice(0, 8);
|
|
@@ -21218,7 +21226,7 @@ function writeAdminEntry(input) {
|
|
|
21218
21226
|
const result = { usersJsonResult: "noop", accountJsonResult: "noop" };
|
|
21219
21227
|
try {
|
|
21220
21228
|
let users = [];
|
|
21221
|
-
if (
|
|
21229
|
+
if (existsSync30(input.usersFile)) {
|
|
21222
21230
|
const raw = readFileSync34(input.usersFile, "utf-8").trim();
|
|
21223
21231
|
if (raw) {
|
|
21224
21232
|
const parsed = JSON.parse(raw);
|
|
@@ -21262,7 +21270,7 @@ function writeAdminEntry(input) {
|
|
|
21262
21270
|
}
|
|
21263
21271
|
try {
|
|
21264
21272
|
const accountJsonPath = join42(input.accountDir, "account.json");
|
|
21265
|
-
if (!
|
|
21273
|
+
if (!existsSync30(accountJsonPath)) {
|
|
21266
21274
|
throw new Error(`account.json not found at ${accountJsonPath}`);
|
|
21267
21275
|
}
|
|
21268
21276
|
const config = JSON.parse(readFileSync34(accountJsonPath, "utf-8"));
|
|
@@ -21285,7 +21293,7 @@ function writeAdminEntry(input) {
|
|
|
21285
21293
|
function computeAdminStoreDivergence(input) {
|
|
21286
21294
|
const result = { divergences: 0, accountWithoutUsers: [], usersWithoutAccount: [], errors: [] };
|
|
21287
21295
|
const usersUserIds = /* @__PURE__ */ new Set();
|
|
21288
|
-
if (
|
|
21296
|
+
if (existsSync30(input.usersFile)) {
|
|
21289
21297
|
try {
|
|
21290
21298
|
const raw = readFileSync34(input.usersFile, "utf-8").trim();
|
|
21291
21299
|
if (raw) {
|
|
@@ -21299,7 +21307,7 @@ function computeAdminStoreDivergence(input) {
|
|
|
21299
21307
|
}
|
|
21300
21308
|
}
|
|
21301
21309
|
const accountUserIds = /* @__PURE__ */ new Set();
|
|
21302
|
-
if (
|
|
21310
|
+
if (existsSync30(input.accountsDir)) {
|
|
21303
21311
|
let entries2;
|
|
21304
21312
|
try {
|
|
21305
21313
|
entries2 = readdirSync21(input.accountsDir);
|
|
@@ -21316,7 +21324,7 @@ function computeAdminStoreDivergence(input) {
|
|
|
21316
21324
|
continue;
|
|
21317
21325
|
}
|
|
21318
21326
|
const accountJsonPath = join42(accountDir, "account.json");
|
|
21319
|
-
if (!
|
|
21327
|
+
if (!existsSync30(accountJsonPath)) continue;
|
|
21320
21328
|
let admins = [];
|
|
21321
21329
|
try {
|
|
21322
21330
|
const config = JSON.parse(readFileSync34(accountJsonPath, "utf-8"));
|
|
@@ -21367,7 +21375,7 @@ function hashPin2(pin) {
|
|
|
21367
21375
|
return createHash4("sha256").update(pin).digest("hex");
|
|
21368
21376
|
}
|
|
21369
21377
|
function readUsersFile2() {
|
|
21370
|
-
if (!
|
|
21378
|
+
if (!existsSync31(USERS_FILE)) return null;
|
|
21371
21379
|
const raw = readFileSync35(USERS_FILE, "utf-8").trim();
|
|
21372
21380
|
if (!raw) return [];
|
|
21373
21381
|
return JSON.parse(raw);
|
|
@@ -21459,7 +21467,7 @@ app13.post("/claude-auth", async (c) => {
|
|
|
21459
21467
|
} catch (err) {
|
|
21460
21468
|
logoutError = err instanceof Error ? err.message : String(err);
|
|
21461
21469
|
}
|
|
21462
|
-
const credentialsPresent =
|
|
21470
|
+
const credentialsPresent = existsSync31(CLAUDE_CREDENTIALS_FILE);
|
|
21463
21471
|
const ranMs = Date.now() - start;
|
|
21464
21472
|
console.log(`[onboarding] op=claude-logout credentialsPresent=${credentialsPresent} ranMs=${ranMs} logoutError=${logoutError ? JSON.stringify(logoutError.slice(0, 120)) : "none"}`);
|
|
21465
21473
|
return c.json({ logged_out: !credentialsPresent });
|
|
@@ -21617,7 +21625,7 @@ app13.post("/set-pin", async (c) => {
|
|
|
21617
21625
|
console.log(`[set-pin] wrote users.json + account.json admins: userId=${userId.slice(0, 8)}\u2026 role=owner`);
|
|
21618
21626
|
if (process.platform === "linux") {
|
|
21619
21627
|
let installOwner = null;
|
|
21620
|
-
if (
|
|
21628
|
+
if (existsSync31(INSTALL_OWNER_FILE)) {
|
|
21621
21629
|
try {
|
|
21622
21630
|
const raw = readFileSync35(INSTALL_OWNER_FILE, "utf-8").trim();
|
|
21623
21631
|
if (raw.length > 0) installOwner = raw;
|
|
@@ -21765,7 +21773,7 @@ app13.put("/set-pin", requireAdminSession, async (c) => {
|
|
|
21765
21773
|
console.log(`[set-pin] changed PIN in place: userId=${sessionUserId.slice(0, 8)}\u2026`);
|
|
21766
21774
|
if (process.platform === "linux") {
|
|
21767
21775
|
let installOwner = null;
|
|
21768
|
-
if (
|
|
21776
|
+
if (existsSync31(INSTALL_OWNER_FILE)) {
|
|
21769
21777
|
try {
|
|
21770
21778
|
const raw = readFileSync35(INSTALL_OWNER_FILE, "utf-8").trim();
|
|
21771
21779
|
if (raw.length > 0) installOwner = raw;
|
|
@@ -22224,7 +22232,7 @@ app14.post("/probe", async (c) => {
|
|
|
22224
22232
|
var field_default = app14;
|
|
22225
22233
|
|
|
22226
22234
|
// server/routes/client-error.ts
|
|
22227
|
-
import { appendFileSync as appendFileSync4, existsSync as
|
|
22235
|
+
import { appendFileSync as appendFileSync4, existsSync as existsSync32, renameSync as renameSync8, statSync as statSync21 } from "fs";
|
|
22228
22236
|
import { join as join44 } from "path";
|
|
22229
22237
|
var CLIENT_ERRORS_LOG = join44(LOG_DIR, "client-errors.log");
|
|
22230
22238
|
var MAX_LOG_SIZE = 10 * 1024 * 1024;
|
|
@@ -22283,7 +22291,7 @@ function stackHead(stack) {
|
|
|
22283
22291
|
}
|
|
22284
22292
|
function rotateIfNeeded() {
|
|
22285
22293
|
try {
|
|
22286
|
-
if (!
|
|
22294
|
+
if (!existsSync32(CLIENT_ERRORS_LOG)) return;
|
|
22287
22295
|
const stats = statSync21(CLIENT_ERRORS_LOG);
|
|
22288
22296
|
if (stats.size < MAX_LOG_SIZE) return;
|
|
22289
22297
|
renameSync8(CLIENT_ERRORS_LOG, CLIENT_ERRORS_LOG + ".1");
|
|
@@ -22632,18 +22640,18 @@ app17.get("/", requireAdminSession, async (c) => {
|
|
|
22632
22640
|
var accounts_default = app17;
|
|
22633
22641
|
|
|
22634
22642
|
// server/routes/admin/logs.ts
|
|
22635
|
-
import { existsSync as
|
|
22643
|
+
import { existsSync as existsSync34, readdirSync as readdirSync22, readFileSync as readFileSync36, statSync as statSync22 } from "fs";
|
|
22636
22644
|
import { resolve as resolve26, basename as basename13 } from "path";
|
|
22637
22645
|
|
|
22638
22646
|
// app/lib/logs-read-resolve.ts
|
|
22639
|
-
import { existsSync as
|
|
22647
|
+
import { existsSync as existsSync33 } from "fs";
|
|
22640
22648
|
import { join as join45 } from "path";
|
|
22641
22649
|
function resolveSessionLogPaths(filename, logDirs) {
|
|
22642
22650
|
const tried = [filename];
|
|
22643
22651
|
const hits = [];
|
|
22644
22652
|
for (const dir of logDirs) {
|
|
22645
22653
|
const fullPath = join45(dir, filename);
|
|
22646
|
-
if (
|
|
22654
|
+
if (existsSync33(fullPath)) {
|
|
22647
22655
|
hits.push({ path: fullPath, dir });
|
|
22648
22656
|
}
|
|
22649
22657
|
}
|
|
@@ -22768,7 +22776,7 @@ app18.get("/", async (c) => {
|
|
|
22768
22776
|
const seen = /* @__PURE__ */ new Set();
|
|
22769
22777
|
const logs = {};
|
|
22770
22778
|
for (const dir of logDirs) {
|
|
22771
|
-
if (!
|
|
22779
|
+
if (!existsSync34(dir)) continue;
|
|
22772
22780
|
let files;
|
|
22773
22781
|
try {
|
|
22774
22782
|
files = readdirSync22(dir).filter((f) => f.endsWith(".log"));
|
|
@@ -22825,7 +22833,7 @@ var claude_info_default = app19;
|
|
|
22825
22833
|
|
|
22826
22834
|
// server/routes/admin/attachment.ts
|
|
22827
22835
|
import { readFile as readFile7, readdir as readdir2 } from "fs/promises";
|
|
22828
|
-
import { existsSync as
|
|
22836
|
+
import { existsSync as existsSync35 } from "fs";
|
|
22829
22837
|
import { resolve as resolve27 } from "path";
|
|
22830
22838
|
var app20 = new Hono();
|
|
22831
22839
|
var ATTACHMENT_ID_RE2 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
@@ -22848,12 +22856,12 @@ app20.get("/:attachmentId", requireAdminSession, async (c) => {
|
|
|
22848
22856
|
}
|
|
22849
22857
|
let accountId = pinnedAccountId;
|
|
22850
22858
|
let dir = uploadsDirFor(accountId, attachmentId);
|
|
22851
|
-
let found =
|
|
22859
|
+
let found = existsSync35(dir);
|
|
22852
22860
|
if (!found) {
|
|
22853
22861
|
for (const candidate of listValidAccounts()) {
|
|
22854
22862
|
if (candidate.accountId === pinnedAccountId) continue;
|
|
22855
22863
|
const candidateDir = uploadsDirFor(candidate.accountId, attachmentId);
|
|
22856
|
-
if (
|
|
22864
|
+
if (existsSync35(candidateDir)) {
|
|
22857
22865
|
accountId = candidate.accountId;
|
|
22858
22866
|
dir = candidateDir;
|
|
22859
22867
|
found = true;
|
|
@@ -22868,7 +22876,7 @@ app20.get("/:attachmentId", requireAdminSession, async (c) => {
|
|
|
22868
22876
|
return new Response("Not found", { status: 404 });
|
|
22869
22877
|
}
|
|
22870
22878
|
const metaPath = resolve27(dir, `${attachmentId}.meta.json`);
|
|
22871
|
-
if (!
|
|
22879
|
+
if (!existsSync35(metaPath)) {
|
|
22872
22880
|
return new Response("Not found", { status: 404 });
|
|
22873
22881
|
}
|
|
22874
22882
|
let meta;
|
|
@@ -22902,7 +22910,7 @@ var attachment_default = app20;
|
|
|
22902
22910
|
|
|
22903
22911
|
// server/routes/admin/session-upload.ts
|
|
22904
22912
|
import { readFile as readFile8 } from "fs/promises";
|
|
22905
|
-
import { existsSync as
|
|
22913
|
+
import { existsSync as existsSync36, statSync as statSync23 } from "fs";
|
|
22906
22914
|
var app21 = new Hono();
|
|
22907
22915
|
app21.get("/", requireAdminSession, async (c) => {
|
|
22908
22916
|
const cacheKey = c.var.cacheKey;
|
|
@@ -22923,7 +22931,7 @@ app21.get("/", requireAdminSession, async (c) => {
|
|
|
22923
22931
|
return c.json({ error: "Not found" }, 404);
|
|
22924
22932
|
}
|
|
22925
22933
|
const resolution = resolveClaudeUploadsPath(`${sessionId}/${file}`);
|
|
22926
|
-
if (!resolution.ok || !
|
|
22934
|
+
if (!resolution.ok || !existsSync36(resolution.absolute) || !statSync23(resolution.absolute).isFile()) {
|
|
22927
22935
|
console.log(`[session-upload] op=miss session=${short2} file=${file} status=404 reason=absent`);
|
|
22928
22936
|
return c.json({ error: "Not found" }, 404);
|
|
22929
22937
|
}
|
|
@@ -22945,11 +22953,11 @@ var session_upload_default = app21;
|
|
|
22945
22953
|
|
|
22946
22954
|
// server/routes/admin/agents.ts
|
|
22947
22955
|
import { resolve as resolve28 } from "path";
|
|
22948
|
-
import { readdirSync as readdirSync24, readFileSync as readFileSync38, existsSync as
|
|
22956
|
+
import { readdirSync as readdirSync24, readFileSync as readFileSync38, existsSync as existsSync38, rmSync as rmSync5, renameSync as renameSync9, mkdirSync as mkdirSync10, writeFileSync as writeFileSync18, chmodSync } from "fs";
|
|
22949
22957
|
import { execFileSync as execFileSync6 } from "child_process";
|
|
22950
22958
|
|
|
22951
22959
|
// ../services/claude-session-manager/src/tool-surface.ts
|
|
22952
|
-
import { readFileSync as readFileSync37, readdirSync as readdirSync23, statSync as statSync24, existsSync as
|
|
22960
|
+
import { readFileSync as readFileSync37, readdirSync as readdirSync23, statSync as statSync24, existsSync as existsSync37 } from "fs";
|
|
22953
22961
|
import { createHash as createHash5 } from "crypto";
|
|
22954
22962
|
import { join as join46 } from "path";
|
|
22955
22963
|
|
|
@@ -23195,7 +23203,7 @@ function parseMcpBlock(frontmatter, pluginDir) {
|
|
|
23195
23203
|
function loadToolSurface(pluginsRoots) {
|
|
23196
23204
|
const roots = Array.isArray(pluginsRoots) ? pluginsRoots : [pluginsRoots];
|
|
23197
23205
|
for (const r of roots) {
|
|
23198
|
-
if (!
|
|
23206
|
+
if (!existsSync37(r)) throw new ToolSurfaceError("plugins-root-missing", r);
|
|
23199
23207
|
}
|
|
23200
23208
|
const admin = /* @__PURE__ */ new Set();
|
|
23201
23209
|
const pub = /* @__PURE__ */ new Set();
|
|
@@ -23211,7 +23219,7 @@ function loadToolSurface(pluginsRoots) {
|
|
|
23211
23219
|
return;
|
|
23212
23220
|
}
|
|
23213
23221
|
const manifestPath = join46(pluginDir, "PLUGIN.md");
|
|
23214
|
-
if (!
|
|
23222
|
+
if (!existsSync37(manifestPath)) return;
|
|
23215
23223
|
const raw = readFileSync37(manifestPath, "utf-8");
|
|
23216
23224
|
const frontmatter = extractFrontmatter(raw, plugin);
|
|
23217
23225
|
const tools = parseToolsBlock(frontmatter, plugin);
|
|
@@ -23392,7 +23400,7 @@ function agentRiskClass(tools, riskByTool) {
|
|
|
23392
23400
|
// server/routes/admin/agents.ts
|
|
23393
23401
|
var SLUG_UNSAFE = (s) => s.includes("/") || s.includes("..") || s.includes("\\");
|
|
23394
23402
|
function subdirs(dir) {
|
|
23395
|
-
if (!
|
|
23403
|
+
if (!existsSync38(dir)) return [];
|
|
23396
23404
|
try {
|
|
23397
23405
|
return readdirSync24(dir, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name);
|
|
23398
23406
|
} catch {
|
|
@@ -23413,7 +23421,7 @@ var SPECIALISTS_DIR = ["specialists", "agents"];
|
|
|
23413
23421
|
var QUARANTINE_DIR = ["specialists", "agents-disabled"];
|
|
23414
23422
|
var DISABLED_STORE = "agents-disabled.json";
|
|
23415
23423
|
function loadRiskSurface() {
|
|
23416
|
-
const roots = [resolve28(PLATFORM_ROOT, "plugins"), resolve28(PLATFORM_ROOT, "..", "premium-plugins")].filter((r) =>
|
|
23424
|
+
const roots = [resolve28(PLATFORM_ROOT, "plugins"), resolve28(PLATFORM_ROOT, "..", "premium-plugins")].filter((r) => existsSync38(r));
|
|
23417
23425
|
try {
|
|
23418
23426
|
return { riskByTool: loadToolSurface(roots).riskByTool, failed: null };
|
|
23419
23427
|
} catch (err) {
|
|
@@ -23425,7 +23433,7 @@ function loadRiskSurface() {
|
|
|
23425
23433
|
}
|
|
23426
23434
|
function readDisabledStoreStrict(accountDir) {
|
|
23427
23435
|
const p = resolve28(accountDir, DISABLED_STORE);
|
|
23428
|
-
if (!
|
|
23436
|
+
if (!existsSync38(p)) return /* @__PURE__ */ new Set();
|
|
23429
23437
|
const parsed = JSON.parse(readFileSync38(p, "utf-8"));
|
|
23430
23438
|
if (!Array.isArray(parsed.disabled)) throw new Error("disabled is not an array");
|
|
23431
23439
|
return new Set(parsed.disabled.filter((x) => typeof x === "string"));
|
|
@@ -23444,7 +23452,7 @@ function authoredAgentFiles(accountDir) {
|
|
|
23444
23452
|
const byName = /* @__PURE__ */ new Map();
|
|
23445
23453
|
for (const plugin of subdirs(pluginsDir)) {
|
|
23446
23454
|
const dir = resolve28(pluginsDir, plugin, "agents");
|
|
23447
|
-
if (!
|
|
23455
|
+
if (!existsSync38(dir)) continue;
|
|
23448
23456
|
try {
|
|
23449
23457
|
for (const entry2 of readdirSync24(dir)) {
|
|
23450
23458
|
if (!entry2.endsWith(".md")) continue;
|
|
@@ -23518,7 +23526,7 @@ function listShipped(accountDir, riskByTool, disabled, riskSurfaceFailed, author
|
|
|
23518
23526
|
const dirs = shippedSourceDirs(accountDir);
|
|
23519
23527
|
const names = /* @__PURE__ */ new Set();
|
|
23520
23528
|
for (const dir of dirs) {
|
|
23521
|
-
if (!
|
|
23529
|
+
if (!existsSync38(dir)) continue;
|
|
23522
23530
|
try {
|
|
23523
23531
|
for (const entry2 of readdirSync24(dir)) if (entry2.endsWith(".md")) names.add(entry2);
|
|
23524
23532
|
} catch (err) {
|
|
@@ -23530,7 +23538,7 @@ function listShipped(accountDir, riskByTool, disabled, riskSurfaceFailed, author
|
|
|
23530
23538
|
let deduped = 0;
|
|
23531
23539
|
let divergent = 0;
|
|
23532
23540
|
for (const filename of [...names].sort()) {
|
|
23533
|
-
const source = dirs.find((d) =>
|
|
23541
|
+
const source = dirs.find((d) => existsSync38(resolve28(d, filename)));
|
|
23534
23542
|
if (!source) continue;
|
|
23535
23543
|
const authoredPaths = source === dirs[0] || source === dirs[1] ? authoredFiles.get(filename) : void 0;
|
|
23536
23544
|
if (authoredPaths) {
|
|
@@ -23607,7 +23615,7 @@ function listSpecialists(accountDir, riskByTool, riskSurfaceFailed) {
|
|
|
23607
23615
|
let specialistsSkipped = 0;
|
|
23608
23616
|
for (const plugin of subdirs(pluginsDir).sort()) {
|
|
23609
23617
|
const agentsDirP = resolve28(pluginsDir, plugin, "agents");
|
|
23610
|
-
if (!
|
|
23618
|
+
if (!existsSync38(agentsDirP)) continue;
|
|
23611
23619
|
let entries2;
|
|
23612
23620
|
try {
|
|
23613
23621
|
entries2 = readdirSync24(agentsDirP, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name));
|
|
@@ -23649,7 +23657,7 @@ function listSpecialists(accountDir, riskByTool, riskSurfaceFailed) {
|
|
|
23649
23657
|
// have the surface claim an agent is stopped while it is still being
|
|
23650
23658
|
// spawned. Absence from the live dir alone is also not the test: a
|
|
23651
23659
|
// specialist that was never activated was never switched off either.
|
|
23652
|
-
disabled:
|
|
23660
|
+
disabled: existsSync38(resolve28(accountDir, ...QUARANTINE_DIR, entry2.name)) && !existsSync38(resolve28(accountDir, ...SPECIALISTS_DIR, entry2.name))
|
|
23653
23661
|
});
|
|
23654
23662
|
} catch {
|
|
23655
23663
|
specialistsSkipped++;
|
|
@@ -23677,14 +23685,14 @@ app22.get("/", requireAdminSession, (c) => {
|
|
|
23677
23685
|
const agents = [];
|
|
23678
23686
|
let skipped = 0;
|
|
23679
23687
|
const agentsDir = resolve28(account.accountDir, "agents");
|
|
23680
|
-
if (
|
|
23688
|
+
if (existsSync38(agentsDir)) {
|
|
23681
23689
|
try {
|
|
23682
23690
|
const entries2 = readdirSync24(agentsDir, { withFileTypes: true });
|
|
23683
23691
|
for (const entry2 of entries2.sort((a, b) => a.name.localeCompare(b.name))) {
|
|
23684
23692
|
if (!entry2.isDirectory()) continue;
|
|
23685
23693
|
if (entry2.name === "admin") continue;
|
|
23686
23694
|
const configPath3 = resolve28(agentsDir, entry2.name, "config.json");
|
|
23687
|
-
if (!
|
|
23695
|
+
if (!existsSync38(configPath3)) continue;
|
|
23688
23696
|
try {
|
|
23689
23697
|
const config = JSON.parse(readFileSync38(configPath3, "utf-8"));
|
|
23690
23698
|
agents.push({
|
|
@@ -23766,7 +23774,7 @@ app22.get("/:slug", requireAdminSession, (c) => {
|
|
|
23766
23774
|
if (SLUG_UNSAFE(slug)) return c.json({ error: "Invalid agent slug" }, 400);
|
|
23767
23775
|
if (c.req.query("origin") === "shipped") {
|
|
23768
23776
|
const dirs = shippedSourceDirs(account.accountDir);
|
|
23769
|
-
const source = dirs.find((d) =>
|
|
23777
|
+
const source = dirs.find((d) => existsSync38(resolve28(d, `${slug}.md`)));
|
|
23770
23778
|
if (!source) return c.json({ error: "Agent not found" }, 404);
|
|
23771
23779
|
const { fm, body } = splitFrontmatter(readFileSync38(resolve28(source, `${slug}.md`), "utf-8"));
|
|
23772
23780
|
const { riskByTool, failed: failed2 } = loadRiskSurface();
|
|
@@ -23799,7 +23807,7 @@ app22.get("/:slug", requireAdminSession, (c) => {
|
|
|
23799
23807
|
if (pluginParam) {
|
|
23800
23808
|
if (SLUG_UNSAFE(pluginParam)) return c.json({ error: "Invalid plugin" }, 400);
|
|
23801
23809
|
const file = resolve28(account.accountDir, "plugins", pluginParam, "agents", `${slug}.md`);
|
|
23802
|
-
if (!
|
|
23810
|
+
if (!existsSync38(file)) return c.json({ error: "Agent not found" }, 404);
|
|
23803
23811
|
const { fm, body } = splitFrontmatter(readFileSync38(file, "utf-8"));
|
|
23804
23812
|
const skills = subdirs(resolve28(account.accountDir, "plugins", pluginParam, "skills"));
|
|
23805
23813
|
const { riskByTool, failed: failed2 } = loadRiskSurface();
|
|
@@ -23830,7 +23838,7 @@ app22.get("/:slug", requireAdminSession, (c) => {
|
|
|
23830
23838
|
}
|
|
23831
23839
|
const agentDir = resolve28(account.accountDir, "agents", slug);
|
|
23832
23840
|
const configPath3 = resolve28(agentDir, "config.json");
|
|
23833
|
-
if (!
|
|
23841
|
+
if (!existsSync38(configPath3)) return c.json({ error: "Agent not found" }, 404);
|
|
23834
23842
|
let config;
|
|
23835
23843
|
try {
|
|
23836
23844
|
config = JSON.parse(readFileSync38(configPath3, "utf-8"));
|
|
@@ -23843,7 +23851,7 @@ app22.get("/:slug", requireAdminSession, (c) => {
|
|
|
23843
23851
|
for (const { file, key: key2 } of OWNED_DOCS) {
|
|
23844
23852
|
const p = resolve28(agentDir, file);
|
|
23845
23853
|
try {
|
|
23846
|
-
if (
|
|
23854
|
+
if (existsSync38(p)) {
|
|
23847
23855
|
docs[key2] = readFileSync38(p, "utf-8");
|
|
23848
23856
|
present[key2] = true;
|
|
23849
23857
|
} else {
|
|
@@ -23904,7 +23912,7 @@ function reconcileRoutingProse(accountDir, accountId, op, slug) {
|
|
|
23904
23912
|
}
|
|
23905
23913
|
function reconcileAuthoredRoutingLine(accountDir, accountId, op, source) {
|
|
23906
23914
|
const agentsMd = resolve28(accountDir, "agents", "admin", "AGENTS.md");
|
|
23907
|
-
if (!
|
|
23915
|
+
if (!existsSync38(agentsMd) || !existsSync38(source)) return false;
|
|
23908
23916
|
try {
|
|
23909
23917
|
const { fm } = splitFrontmatter(readFileSync38(source, "utf-8"));
|
|
23910
23918
|
if (!fm.name) return false;
|
|
@@ -23933,7 +23941,7 @@ app22.post("/:slug/disable", async (c) => {
|
|
|
23933
23941
|
console.error(`[admin/agents] op=disable accountId=${resolved.accountId.slice(0, 8)} slug=${slug} origin=not-authored eligible=false outcome=refused reason=not-user-created`);
|
|
23934
23942
|
return c.json({ error: "Only an agent you created can be switched off here. A shipped agent is stopped by suspending the routines that dispatch it." }, 404);
|
|
23935
23943
|
}
|
|
23936
|
-
if (!
|
|
23944
|
+
if (!existsSync38(live)) {
|
|
23937
23945
|
console.error(`[admin/agents] op=disable accountId=${resolved.accountId.slice(0, 8)} slug=${slug} origin=specialist eligible=true outcome=refused reason=not-dispatchable`);
|
|
23938
23946
|
return c.json({ error: "This agent is not in the dispatchable set, so there is nothing to switch off." }, 409);
|
|
23939
23947
|
}
|
|
@@ -23962,7 +23970,7 @@ app22.post("/:slug/enable", async (c) => {
|
|
|
23962
23970
|
let restored = false;
|
|
23963
23971
|
try {
|
|
23964
23972
|
if (authored) {
|
|
23965
|
-
if (!
|
|
23973
|
+
if (!existsSync38(quarantined)) {
|
|
23966
23974
|
console.error(`[admin/agents] op=enable accountId=${resolved.accountId.slice(0, 8)} slug=${slug} origin=specialist eligible=true outcome=refused reason=not-disabled`);
|
|
23967
23975
|
return c.json({ error: "This agent is not disabled" }, 404);
|
|
23968
23976
|
}
|
|
@@ -23971,11 +23979,11 @@ app22.post("/:slug/enable", async (c) => {
|
|
|
23971
23979
|
restored = true;
|
|
23972
23980
|
} else {
|
|
23973
23981
|
const disabled = readDisabledStoreStrict(resolved.accountDir);
|
|
23974
|
-
if (!
|
|
23982
|
+
if (!existsSync38(quarantined) && !disabled.has(filename)) {
|
|
23975
23983
|
console.error(`[admin/agents] op=enable accountId=${resolved.accountId.slice(0, 8)} slug=${slug} origin=shipped eligible=true outcome=refused reason=not-disabled`);
|
|
23976
23984
|
return c.json({ error: "This agent is not disabled" }, 404);
|
|
23977
23985
|
}
|
|
23978
|
-
if (
|
|
23986
|
+
if (existsSync38(quarantined)) {
|
|
23979
23987
|
mkdirSync10(resolve28(resolved.accountDir, ...SPECIALISTS_DIR), { recursive: true });
|
|
23980
23988
|
renameSync9(quarantined, live);
|
|
23981
23989
|
restored = true;
|
|
@@ -24018,7 +24026,7 @@ app22.delete("/:slug", async (c) => {
|
|
|
24018
24026
|
return c.json({ error: "Not authorized for this account" }, 403);
|
|
24019
24027
|
}
|
|
24020
24028
|
const agentDir = resolve28(account.accountDir, "agents", slug);
|
|
24021
|
-
if (!
|
|
24029
|
+
if (!existsSync38(agentDir)) {
|
|
24022
24030
|
return c.json({ error: "Agent not found" }, 404);
|
|
24023
24031
|
}
|
|
24024
24032
|
try {
|
|
@@ -24061,7 +24069,7 @@ app22.post("/:slug/project", async (c) => {
|
|
|
24061
24069
|
return c.json({ error: "Not authorized for this account" }, 403);
|
|
24062
24070
|
}
|
|
24063
24071
|
const agentDir = resolve28(account.accountDir, "agents", slug);
|
|
24064
|
-
if (!
|
|
24072
|
+
if (!existsSync38(agentDir)) {
|
|
24065
24073
|
console.error(`[admin/agents] op=project rejected reason=agent-not-on-disk accountId=${account.accountId.slice(0, 8)} slug=${slug} probed=${agentDir}`);
|
|
24066
24074
|
return c.json({ error: "Agent not found on disk" }, 404);
|
|
24067
24075
|
}
|
|
@@ -24080,7 +24088,7 @@ var agents_default = app22;
|
|
|
24080
24088
|
// server/routes/admin/sessions.ts
|
|
24081
24089
|
import crypto2 from "crypto";
|
|
24082
24090
|
import { resolve as resolvePath } from "path";
|
|
24083
|
-
import { existsSync as
|
|
24091
|
+
import { existsSync as existsSync39, mkdirSync as mkdirSync11, createWriteStream } from "fs";
|
|
24084
24092
|
|
|
24085
24093
|
// ../lib/admin-conversation-purge/src/index.ts
|
|
24086
24094
|
async function purgeAdminConversationJsonls(args) {
|
|
@@ -24218,7 +24226,7 @@ var replayJsonl = (..._args) => null;
|
|
|
24218
24226
|
var resolveJsonlPath = (..._args) => null;
|
|
24219
24227
|
|
|
24220
24228
|
// server/routes/admin/sessions.ts
|
|
24221
|
-
import { homedir as
|
|
24229
|
+
import { homedir as homedir3 } from "os";
|
|
24222
24230
|
|
|
24223
24231
|
// app/lib/claude-agent/component-attachment.ts
|
|
24224
24232
|
var pickComponentBytes = (..._args) => null;
|
|
@@ -24240,7 +24248,7 @@ function validateAndShapeAttachments(raws, conversationAccountId, sessionId, mes
|
|
|
24240
24248
|
let reason = null;
|
|
24241
24249
|
if (!a.attachmentId || !a.filename || !a.mimeType || !a.storagePath) reason = "schema-fail";
|
|
24242
24250
|
else if (a.accountId !== conversationAccountId) reason = "account-mismatch";
|
|
24243
|
-
else if (!
|
|
24251
|
+
else if (!existsSync39(a.storagePath)) reason = "missing-file";
|
|
24244
24252
|
if (reason) {
|
|
24245
24253
|
invalid++;
|
|
24246
24254
|
try {
|
|
@@ -24533,7 +24541,7 @@ app23.post("/:id/resume", async (c) => {
|
|
|
24533
24541
|
return c.json({ error: "Failed to load conversation messages" }, 500);
|
|
24534
24542
|
}
|
|
24535
24543
|
if (persistedAgentSessionId) {
|
|
24536
|
-
const jsonlPath = resolveJsonlPath(
|
|
24544
|
+
const jsonlPath = resolveJsonlPath(homedir3(), resolvePath(ACCOUNTS_DIR, accountId), persistedAgentSessionId);
|
|
24537
24545
|
const replay = replayJsonl(jsonlPath);
|
|
24538
24546
|
jsonlMissing = replay.jsonlMissing;
|
|
24539
24547
|
jsonlMalformedLines = replay.malformedLines;
|
|
@@ -24766,7 +24774,7 @@ app23.put("/:id/label", requireAdminSession, async (c) => {
|
|
|
24766
24774
|
var sessions_default = app23;
|
|
24767
24775
|
|
|
24768
24776
|
// app/lib/claude-agent/spawn-context.ts
|
|
24769
|
-
import { existsSync as
|
|
24777
|
+
import { existsSync as existsSync40, readFileSync as readFileSync39, readdirSync as readdirSync25, statSync as statSync25 } from "fs";
|
|
24770
24778
|
import { dirname as dirname15, resolve as resolve29, join as join47 } from "path";
|
|
24771
24779
|
async function resolveOwnerProfileBlock(accountId, userId) {
|
|
24772
24780
|
if (!userId) return { ok: false, reason: "missing-user-id" };
|
|
@@ -24813,7 +24821,7 @@ function extractPluginToolDescriptions(pluginDir) {
|
|
|
24813
24821
|
];
|
|
24814
24822
|
let raw = null;
|
|
24815
24823
|
for (const path of candidates) {
|
|
24816
|
-
if (!
|
|
24824
|
+
if (!existsSync40(path)) continue;
|
|
24817
24825
|
try {
|
|
24818
24826
|
raw = readFileSync39(path, "utf-8");
|
|
24819
24827
|
break;
|
|
@@ -24865,7 +24873,7 @@ function parseSkillPathsFromFrontmatter(fm) {
|
|
|
24865
24873
|
function listPluginDirs(accountPluginsDir) {
|
|
24866
24874
|
const out = /* @__PURE__ */ new Map();
|
|
24867
24875
|
const platformPlugins = resolve29(PLATFORM_ROOT, "plugins");
|
|
24868
|
-
if (
|
|
24876
|
+
if (existsSync40(platformPlugins)) {
|
|
24869
24877
|
for (const name of readdirSync25(platformPlugins)) {
|
|
24870
24878
|
const dir = join47(platformPlugins, name);
|
|
24871
24879
|
try {
|
|
@@ -24875,10 +24883,10 @@ function listPluginDirs(accountPluginsDir) {
|
|
|
24875
24883
|
}
|
|
24876
24884
|
}
|
|
24877
24885
|
const premiumRoot = resolve29(dirname15(PLATFORM_ROOT), "premium-plugins");
|
|
24878
|
-
if (
|
|
24886
|
+
if (existsSync40(premiumRoot)) {
|
|
24879
24887
|
for (const bundle of readdirSync25(premiumRoot)) {
|
|
24880
24888
|
const bundlePlugins = join47(premiumRoot, bundle, "plugins");
|
|
24881
|
-
if (!
|
|
24889
|
+
if (!existsSync40(bundlePlugins)) continue;
|
|
24882
24890
|
try {
|
|
24883
24891
|
for (const name of readdirSync25(bundlePlugins)) {
|
|
24884
24892
|
const dir = join47(bundlePlugins, name);
|
|
@@ -24891,7 +24899,7 @@ function listPluginDirs(accountPluginsDir) {
|
|
|
24891
24899
|
}
|
|
24892
24900
|
}
|
|
24893
24901
|
}
|
|
24894
|
-
if (accountPluginsDir &&
|
|
24902
|
+
if (accountPluginsDir && existsSync40(accountPluginsDir)) {
|
|
24895
24903
|
try {
|
|
24896
24904
|
for (const name of readdirSync25(accountPluginsDir)) {
|
|
24897
24905
|
if (out.has(name)) continue;
|
|
@@ -24910,7 +24918,7 @@ function accountPluginsDirFor(accountId) {
|
|
|
24910
24918
|
return resolve29(PLATFORM_ROOT, "..", "data/accounts", accountId, "plugins");
|
|
24911
24919
|
}
|
|
24912
24920
|
function listAccountPluginNames(accountPluginsDir) {
|
|
24913
|
-
if (!
|
|
24921
|
+
if (!existsSync40(accountPluginsDir)) return [];
|
|
24914
24922
|
try {
|
|
24915
24923
|
return readdirSync25(accountPluginsDir).filter((name) => {
|
|
24916
24924
|
try {
|
|
@@ -24925,7 +24933,7 @@ function listAccountPluginNames(accountPluginsDir) {
|
|
|
24925
24933
|
}
|
|
24926
24934
|
function readEnabledPlugins(accountId) {
|
|
24927
24935
|
const accountFile = resolve29(PLATFORM_ROOT, "..", "data/accounts", accountId, "account.json");
|
|
24928
|
-
if (!
|
|
24936
|
+
if (!existsSync40(accountFile)) return /* @__PURE__ */ new Set();
|
|
24929
24937
|
try {
|
|
24930
24938
|
const parsed = JSON.parse(readFileSync39(accountFile, "utf-8"));
|
|
24931
24939
|
return new Set(
|
|
@@ -24936,7 +24944,7 @@ function readEnabledPlugins(accountId) {
|
|
|
24936
24944
|
}
|
|
24937
24945
|
}
|
|
24938
24946
|
function readFrontmatter(path) {
|
|
24939
|
-
if (!
|
|
24947
|
+
if (!existsSync40(path)) return null;
|
|
24940
24948
|
let raw;
|
|
24941
24949
|
try {
|
|
24942
24950
|
raw = readFileSync39(path, "utf-8");
|
|
@@ -24974,7 +24982,7 @@ ${fm}
|
|
|
24974
24982
|
`plugin-manifest-tool-coverage plugin=${name} tools=${tools.length} with-desc=${withDesc}`
|
|
24975
24983
|
);
|
|
24976
24984
|
if (toolNames.length > 0 && descMap.size === 0) {
|
|
24977
|
-
const hasSource =
|
|
24985
|
+
const hasSource = existsSync40(join47(dir, "mcp/dist/index.js")) || existsSync40(join47(dir, "mcp/src/index.ts"));
|
|
24978
24986
|
if (hasSource) {
|
|
24979
24987
|
console.warn(
|
|
24980
24988
|
`[spawn-context] WARN plugin=${name} mcp source present but tool-description regex matched zero entries \u2014 SDK upgrade may have changed the registration shape`
|
|
@@ -25001,7 +25009,7 @@ ${skillFm}
|
|
|
25001
25009
|
}
|
|
25002
25010
|
function computeSpecialistDomains(accountId) {
|
|
25003
25011
|
const specialistsDir = resolve29(PLATFORM_ROOT, "..", "data/accounts", accountId, "specialists", "agents");
|
|
25004
|
-
if (!
|
|
25012
|
+
if (!existsSync40(specialistsDir)) return [];
|
|
25005
25013
|
let entries2;
|
|
25006
25014
|
try {
|
|
25007
25015
|
entries2 = readdirSync25(specialistsDir);
|
|
@@ -25047,7 +25055,7 @@ ${fm}
|
|
|
25047
25055
|
}
|
|
25048
25056
|
function computeDormantPlugins(accountId) {
|
|
25049
25057
|
const accountFile = resolve29(PLATFORM_ROOT, "..", "data/accounts", accountId, "account.json");
|
|
25050
|
-
if (!
|
|
25058
|
+
if (!existsSync40(accountFile)) return [];
|
|
25051
25059
|
let enabled;
|
|
25052
25060
|
try {
|
|
25053
25061
|
const raw = readFileSync39(accountFile, "utf-8");
|
|
@@ -25062,7 +25070,7 @@ function computeDormantPlugins(accountId) {
|
|
|
25062
25070
|
return [];
|
|
25063
25071
|
}
|
|
25064
25072
|
const pluginsDir = resolve29(PLATFORM_ROOT, "plugins");
|
|
25065
|
-
if (!
|
|
25073
|
+
if (!existsSync40(pluginsDir)) return [];
|
|
25066
25074
|
let entries2;
|
|
25067
25075
|
try {
|
|
25068
25076
|
entries2 = readdirSync25(pluginsDir);
|
|
@@ -25073,7 +25081,7 @@ function computeDormantPlugins(accountId) {
|
|
|
25073
25081
|
for (const name of entries2) {
|
|
25074
25082
|
if (enabled.has(name)) continue;
|
|
25075
25083
|
const manifestPath = resolve29(pluginsDir, name, "PLUGIN.md");
|
|
25076
|
-
if (!
|
|
25084
|
+
if (!existsSync40(manifestPath)) continue;
|
|
25077
25085
|
let manifest;
|
|
25078
25086
|
try {
|
|
25079
25087
|
manifest = readFileSync39(manifestPath, "utf-8");
|
|
@@ -25090,11 +25098,11 @@ function computeDormantPlugins(accountId) {
|
|
|
25090
25098
|
}
|
|
25091
25099
|
|
|
25092
25100
|
// server/routes/admin/claude-sessions.ts
|
|
25093
|
-
import { existsSync as
|
|
25101
|
+
import { existsSync as existsSync41, readFileSync as readFileSync40 } from "fs";
|
|
25094
25102
|
import { resolve as resolve30 } from "path";
|
|
25095
25103
|
function readTunnelState(brandConfigDir) {
|
|
25096
25104
|
const statePath = `${process.env.HOME ?? ""}/${brandConfigDir}/cloudflared/tunnel.state`;
|
|
25097
|
-
if (!
|
|
25105
|
+
if (!existsSync41(statePath)) return null;
|
|
25098
25106
|
try {
|
|
25099
25107
|
const parsed = JSON.parse(readFileSync40(statePath, "utf-8"));
|
|
25100
25108
|
const tunnelId = typeof parsed.tunnelId === "string" ? parsed.tunnelId : null;
|
|
@@ -25553,7 +25561,7 @@ app27.get("/", requireAdminSession, async (c) => {
|
|
|
25553
25561
|
var events_default = app27;
|
|
25554
25562
|
|
|
25555
25563
|
// server/routes/admin/files.ts
|
|
25556
|
-
import { createReadStream as createReadStream2, createWriteStream as createWriteStream2, existsSync as
|
|
25564
|
+
import { createReadStream as createReadStream2, createWriteStream as createWriteStream2, existsSync as existsSync42 } from "fs";
|
|
25557
25565
|
import { readdir as readdir4, readFile as readFile10, stat as stat6, mkdir as mkdir2, unlink as unlink3, rename as rename3, rmdir } from "fs/promises";
|
|
25558
25566
|
import { realpathSync as realpathSync7 } from "fs";
|
|
25559
25567
|
import { randomUUID as randomUUID6 } from "crypto";
|
|
@@ -27100,7 +27108,7 @@ app28.post("/upload", requireAdminSession, async (c) => {
|
|
|
27100
27108
|
});
|
|
27101
27109
|
await unlink3(tmpPath).catch(() => {
|
|
27102
27110
|
});
|
|
27103
|
-
const tempRemoved = !
|
|
27111
|
+
const tempRemoved = !existsSync42(tmpPath);
|
|
27104
27112
|
console.error(`[data-upload] op=cleanup uid=${uid} tempRemoved=${tempRemoved}`);
|
|
27105
27113
|
};
|
|
27106
27114
|
const reader = body.getReader();
|
|
@@ -27174,7 +27182,7 @@ async function discardChunkUpload(uploadId, state) {
|
|
|
27174
27182
|
});
|
|
27175
27183
|
await unlink3(state.tmpPath).catch(() => {
|
|
27176
27184
|
});
|
|
27177
|
-
const tempRemoved = !
|
|
27185
|
+
const tempRemoved = !existsSync42(state.tmpPath);
|
|
27178
27186
|
console.error(`[data-upload] op=cleanup uid=${uploadId} tempRemoved=${tempRemoved}`);
|
|
27179
27187
|
}
|
|
27180
27188
|
async function writeChunkBody(body, out, alreadyReceived, ceiling) {
|
|
@@ -29805,7 +29813,7 @@ var graph_default_view_default = app34;
|
|
|
29805
29813
|
// server/routes/admin/sidebar-artefacts.ts
|
|
29806
29814
|
import { readdir as readdir5, stat as stat7 } from "fs/promises";
|
|
29807
29815
|
import { resolve as resolve34, relative as relative7, isAbsolute as isAbsolute4, sep as sep10, basename as basename16 } from "path";
|
|
29808
|
-
import { existsSync as
|
|
29816
|
+
import { existsSync as existsSync43 } from "fs";
|
|
29809
29817
|
var LIMIT = 50;
|
|
29810
29818
|
var ADMIN_AGENT_FILES = ["IDENTITY.md", "SOUL.md", "KNOWLEDGE.md"];
|
|
29811
29819
|
function toDataRootRelPath(absPath) {
|
|
@@ -29917,7 +29925,7 @@ async function fetchAgentTemplateRows(accountDir) {
|
|
|
29917
29925
|
async function unionSpecialistFilenames(overrideDir, bundledDir) {
|
|
29918
29926
|
const names = /* @__PURE__ */ new Set();
|
|
29919
29927
|
for (const dir of [overrideDir, bundledDir]) {
|
|
29920
|
-
if (!
|
|
29928
|
+
if (!existsSync43(dir)) continue;
|
|
29921
29929
|
try {
|
|
29922
29930
|
const entries2 = await readdir5(dir);
|
|
29923
29931
|
for (const entry2 of entries2) {
|
|
@@ -29932,7 +29940,7 @@ async function unionSpecialistFilenames(overrideDir, bundledDir) {
|
|
|
29932
29940
|
}
|
|
29933
29941
|
async function readAgentTemplateRow(inp) {
|
|
29934
29942
|
let chosenPath = null;
|
|
29935
|
-
if (
|
|
29943
|
+
if (existsSync43(inp.overridePath)) {
|
|
29936
29944
|
try {
|
|
29937
29945
|
validateFilePathInAccount(inp.overridePath, inp.overrideRoot);
|
|
29938
29946
|
chosenPath = inp.overridePath;
|
|
@@ -29943,7 +29951,7 @@ async function readAgentTemplateRow(inp) {
|
|
|
29943
29951
|
);
|
|
29944
29952
|
return null;
|
|
29945
29953
|
}
|
|
29946
|
-
} else if (
|
|
29954
|
+
} else if (existsSync43(inp.bundledPath)) {
|
|
29947
29955
|
if (!isWithin(inp.bundledPath, inp.bundledRoot)) {
|
|
29948
29956
|
console.error(
|
|
29949
29957
|
`[admin/sidebar-artefacts] agent-template-read-failed agent=${inp.displayName} kind=${inp.logName} error="bundled path outside PLATFORM_ROOT"`
|
|
@@ -30738,12 +30746,12 @@ app43.get("/", async (c) => {
|
|
|
30738
30746
|
var system_stats_default = app43;
|
|
30739
30747
|
|
|
30740
30748
|
// server/routes/admin/health.ts
|
|
30741
|
-
import { existsSync as
|
|
30749
|
+
import { existsSync as existsSync44, readFileSync as readFileSync43 } from "fs";
|
|
30742
30750
|
import { resolve as resolve37, join as join55 } from "path";
|
|
30743
30751
|
var PLATFORM_ROOT4 = process.env.MAXY_PLATFORM_ROOT ?? resolve37(process.cwd(), "..");
|
|
30744
30752
|
var brandHostname = "maxy";
|
|
30745
30753
|
var brandJsonPath = join55(PLATFORM_ROOT4, "config", "brand.json");
|
|
30746
|
-
if (
|
|
30754
|
+
if (existsSync44(brandJsonPath)) {
|
|
30747
30755
|
try {
|
|
30748
30756
|
const brand = JSON.parse(readFileSync43(brandJsonPath, "utf-8"));
|
|
30749
30757
|
if (brand.hostname) brandHostname = brand.hostname;
|
|
@@ -30754,7 +30762,7 @@ var VERSION_FILE = resolve37(PLATFORM_ROOT4, `config/.${brandHostname}-version`)
|
|
|
30754
30762
|
var PROCESS_STARTED_AT = (/* @__PURE__ */ new Date()).toISOString();
|
|
30755
30763
|
var PROBE_TIMEOUT_MS = 1e3;
|
|
30756
30764
|
function readVersion() {
|
|
30757
|
-
if (!
|
|
30765
|
+
if (!existsSync44(VERSION_FILE)) return "unknown";
|
|
30758
30766
|
return readFileSync43(VERSION_FILE, "utf-8").trim() || "unknown";
|
|
30759
30767
|
}
|
|
30760
30768
|
async function probeConversationDb() {
|
|
@@ -30810,7 +30818,7 @@ import { randomUUID as randomUUID9 } from "crypto";
|
|
|
30810
30818
|
|
|
30811
30819
|
// ../lib/account-ingest-token/src/index.ts
|
|
30812
30820
|
import { randomBytes as randomBytes2, timingSafeEqual as timingSafeEqual2 } from "crypto";
|
|
30813
|
-
import { existsSync as
|
|
30821
|
+
import { existsSync as existsSync45, readdirSync as readdirSync27, readFileSync as readFileSync44, writeFileSync as writeFileSync20 } from "fs";
|
|
30814
30822
|
import { resolve as resolve38 } from "path";
|
|
30815
30823
|
var UUID_RE4 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
30816
30824
|
var INGEST_TOKEN_FIELD = "ingestToken";
|
|
@@ -30820,7 +30828,7 @@ function configPath2(accountsDir, accountId) {
|
|
|
30820
30828
|
}
|
|
30821
30829
|
function readConfig2(accountsDir, accountId) {
|
|
30822
30830
|
const path = configPath2(accountsDir, accountId);
|
|
30823
|
-
if (!
|
|
30831
|
+
if (!existsSync45(path)) return null;
|
|
30824
30832
|
try {
|
|
30825
30833
|
const parsed = JSON.parse(readFileSync44(path, "utf-8"));
|
|
30826
30834
|
return parsed !== null && typeof parsed === "object" ? parsed : null;
|
|
@@ -30833,7 +30841,7 @@ function readIngestToken(accountsDir, accountId) {
|
|
|
30833
30841
|
return typeof value === "string" && TOKEN_RE.test(value) ? value : null;
|
|
30834
30842
|
}
|
|
30835
30843
|
function listAccountIdsOnDisk(accountsDir) {
|
|
30836
|
-
if (!
|
|
30844
|
+
if (!existsSync45(accountsDir)) return [];
|
|
30837
30845
|
let entries2;
|
|
30838
30846
|
try {
|
|
30839
30847
|
entries2 = readdirSync27(accountsDir);
|
|
@@ -30841,7 +30849,7 @@ function listAccountIdsOnDisk(accountsDir) {
|
|
|
30841
30849
|
return [];
|
|
30842
30850
|
}
|
|
30843
30851
|
return entries2.filter(
|
|
30844
|
-
(name) => UUID_RE4.test(name) &&
|
|
30852
|
+
(name) => UUID_RE4.test(name) && existsSync45(resolve38(accountsDir, name, "account.json"))
|
|
30845
30853
|
);
|
|
30846
30854
|
}
|
|
30847
30855
|
function resolveAccountIdByIngestToken(accountsDir, token) {
|
|
@@ -31673,7 +31681,7 @@ app51.delete("/tabs/:id", requireAdminSession, async (c) => {
|
|
|
31673
31681
|
var browser_default = app51;
|
|
31674
31682
|
|
|
31675
31683
|
// server/routes/admin/calendar.ts
|
|
31676
|
-
import { existsSync as
|
|
31684
|
+
import { existsSync as existsSync46 } from "fs";
|
|
31677
31685
|
import { randomUUID as randomUUID10 } from "crypto";
|
|
31678
31686
|
import { join as join57 } from "path";
|
|
31679
31687
|
|
|
@@ -32343,7 +32351,7 @@ app52.get("/booking-link", requireAdminSession, (c) => {
|
|
|
32343
32351
|
}
|
|
32344
32352
|
const id83 = account.accountId.slice(0, 8);
|
|
32345
32353
|
try {
|
|
32346
|
-
if (!
|
|
32354
|
+
if (!existsSync46(join57(account.accountDir, AVAILABILITY_FILENAME))) {
|
|
32347
32355
|
console.log(`[calendar] op=booking-link accountId=${id83} bookingDomain=none source=availability-config`);
|
|
32348
32356
|
return c.json({ bookingDomain: null });
|
|
32349
32357
|
}
|
|
@@ -32362,7 +32370,7 @@ app52.get("/booking-link", requireAdminSession, (c) => {
|
|
|
32362
32370
|
var calendar_default = app52;
|
|
32363
32371
|
|
|
32364
32372
|
// server/routes/admin/data-portal.ts
|
|
32365
|
-
import { existsSync as
|
|
32373
|
+
import { existsSync as existsSync47, readFileSync as readFileSync46 } from "fs";
|
|
32366
32374
|
import { join as join58 } from "path";
|
|
32367
32375
|
var app53 = new Hono();
|
|
32368
32376
|
var PORTAL_FILENAME = "data-portal.json";
|
|
@@ -32375,7 +32383,7 @@ app53.get("/portal-link", requireAdminSession, (c) => {
|
|
|
32375
32383
|
const id83 = account.accountId.slice(0, 8);
|
|
32376
32384
|
try {
|
|
32377
32385
|
const path = join58(account.accountDir, PORTAL_FILENAME);
|
|
32378
|
-
if (!
|
|
32386
|
+
if (!existsSync47(path)) {
|
|
32379
32387
|
console.log(`[data-portal] op=portal-link accountId=${id83} portalDomain=none source=data-portal-config`);
|
|
32380
32388
|
return c.json({ portalDomain: null });
|
|
32381
32389
|
}
|
|
@@ -32392,7 +32400,7 @@ app53.get("/portal-link", requireAdminSession, (c) => {
|
|
|
32392
32400
|
var data_portal_default = app53;
|
|
32393
32401
|
|
|
32394
32402
|
// server/routes/admin/dispatch-planner.ts
|
|
32395
|
-
import { existsSync as
|
|
32403
|
+
import { existsSync as existsSync48, readFileSync as readFileSync47 } from "fs";
|
|
32396
32404
|
import { join as join59 } from "path";
|
|
32397
32405
|
var app54 = new Hono();
|
|
32398
32406
|
var PORTAL_FILENAME2 = "data-portal.json";
|
|
@@ -32407,10 +32415,10 @@ app54.get("/planner-link", requireAdminSession, (c) => {
|
|
|
32407
32415
|
const id83 = account.accountId.slice(0, 8);
|
|
32408
32416
|
try {
|
|
32409
32417
|
const portalPath = join59(account.accountDir, PORTAL_FILENAME2);
|
|
32410
|
-
const dispatchConfigured =
|
|
32411
|
-
if (!
|
|
32418
|
+
const dispatchConfigured = existsSync48(join59(account.accountDir, "dispatch", "config.json"));
|
|
32419
|
+
if (!existsSync48(portalPath) || !dispatchConfigured) {
|
|
32412
32420
|
console.log(
|
|
32413
|
-
`[dispatch-planner] op=planner-link accountId=${id83} plannerUrl=none portal=${
|
|
32421
|
+
`[dispatch-planner] op=planner-link accountId=${id83} plannerUrl=none portal=${existsSync48(portalPath)} dispatch=${dispatchConfigured}`
|
|
32414
32422
|
);
|
|
32415
32423
|
return c.json({ plannerUrl: null });
|
|
32416
32424
|
}
|
|
@@ -33437,7 +33445,7 @@ app55.delete("/:eventId", requireAdminSession, async (c) => {
|
|
|
33437
33445
|
var routines_default = app55;
|
|
33438
33446
|
|
|
33439
33447
|
// server/routes/admin/skills.ts
|
|
33440
|
-
import { existsSync as
|
|
33448
|
+
import { existsSync as existsSync49, readdirSync as readdirSync28, readFileSync as readFileSync50, rmSync as rmSync6 } from "fs";
|
|
33441
33449
|
import { resolve as resolve41 } from "path";
|
|
33442
33450
|
var app56 = new Hono();
|
|
33443
33451
|
var NAME_RE = /^[a-z0-9][a-z0-9-]*$/;
|
|
@@ -33461,7 +33469,7 @@ function stripQuotes(s) {
|
|
|
33461
33469
|
return s;
|
|
33462
33470
|
}
|
|
33463
33471
|
function subdirs2(dir) {
|
|
33464
|
-
if (!
|
|
33472
|
+
if (!existsSync49(dir)) return [];
|
|
33465
33473
|
try {
|
|
33466
33474
|
return readdirSync28(dir, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name);
|
|
33467
33475
|
} catch {
|
|
@@ -33484,11 +33492,11 @@ app56.get("/", requireAdminSession, async (c) => {
|
|
|
33484
33492
|
const skillsDir = resolve41(pluginsDir, plugin, "skills");
|
|
33485
33493
|
for (const skill of subdirs2(skillsDir)) {
|
|
33486
33494
|
const skillMd = resolve41(skillsDir, skill, "SKILL.md");
|
|
33487
|
-
if (!
|
|
33495
|
+
if (!existsSync49(skillMd)) continue;
|
|
33488
33496
|
try {
|
|
33489
33497
|
const { frontmatter } = splitSkillMd(readFileSync50(skillMd, "utf-8"));
|
|
33490
33498
|
const refsDir = resolve41(skillsDir, skill, "references");
|
|
33491
|
-
const refCount =
|
|
33499
|
+
const refCount = existsSync49(refsDir) ? readdirSync28(refsDir, { withFileTypes: true }).filter((e) => e.isFile()).length : 0;
|
|
33492
33500
|
skills.push({ plugin, skill, description: frontmatter.description, refCount });
|
|
33493
33501
|
} catch (err) {
|
|
33494
33502
|
console.error(`[admin:skills] op=list-skip plugin=${plugin} skill=${skill} reason="${err instanceof Error ? err.message : String(err)}"`);
|
|
@@ -33512,13 +33520,13 @@ app56.get("/:plugin/:skill", requireAdminSession, async (c) => {
|
|
|
33512
33520
|
}
|
|
33513
33521
|
const skillDir = resolve41(acct.accountDir, "plugins", plugin, "skills", skill);
|
|
33514
33522
|
const skillMd = resolve41(skillDir, "SKILL.md");
|
|
33515
|
-
const found =
|
|
33523
|
+
const found = existsSync49(skillMd);
|
|
33516
33524
|
console.log(`[admin:skills] op=get plugin=${plugin} skill=${skill} found=${found}`);
|
|
33517
33525
|
if (!found) return c.json({ error: "Skill not found" }, 404);
|
|
33518
33526
|
try {
|
|
33519
33527
|
const { frontmatter, body } = splitSkillMd(readFileSync50(skillMd, "utf-8"));
|
|
33520
33528
|
const refsDir = resolve41(skillDir, "references");
|
|
33521
|
-
const references =
|
|
33529
|
+
const references = existsSync49(refsDir) ? readdirSync28(refsDir, { withFileTypes: true }).filter((e) => e.isFile()).map((e) => e.name).sort() : [];
|
|
33522
33530
|
return c.json({ skill: { plugin, skill, frontmatter, body, references } });
|
|
33523
33531
|
} catch (err) {
|
|
33524
33532
|
const message = err instanceof Error ? err.message : String(err);
|
|
@@ -33538,7 +33546,7 @@ app56.delete("/:plugin/:skill", requireAdminSession, async (c) => {
|
|
|
33538
33546
|
const pluginDir = resolve41(acct.accountDir, "plugins", plugin);
|
|
33539
33547
|
const skillsDir = resolve41(pluginDir, "skills");
|
|
33540
33548
|
const skillDir = resolve41(skillsDir, skill);
|
|
33541
|
-
if (!
|
|
33549
|
+
if (!existsSync49(resolve41(skillDir, "SKILL.md"))) {
|
|
33542
33550
|
console.error(`[admin:skills] op=delete outcome=rejected reason=not-found plugin=${plugin} skill=${skill}`);
|
|
33543
33551
|
return c.json({ error: "Skill not found" }, 404);
|
|
33544
33552
|
}
|
|
@@ -33546,7 +33554,7 @@ app56.delete("/:plugin/:skill", requireAdminSession, async (c) => {
|
|
|
33546
33554
|
rmSync6(skillDir, { recursive: true, force: true });
|
|
33547
33555
|
const pluginDirRemoved = subdirs2(skillsDir).length === 0;
|
|
33548
33556
|
if (pluginDirRemoved) rmSync6(pluginDir, { recursive: true, force: true });
|
|
33549
|
-
const skillDirGone = !
|
|
33557
|
+
const skillDirGone = !existsSync49(skillDir);
|
|
33550
33558
|
if (!skillDirGone) {
|
|
33551
33559
|
console.error(`[admin:skills] op=delete plugin=${plugin} skill=${skill} outcome=rejected reason=rm-incomplete skillDirGone=false`);
|
|
33552
33560
|
return c.json({ error: "Delete did not remove the skill directory" }, 503);
|
|
@@ -34150,7 +34158,7 @@ app62.post("/", requireAdminSession, async (c) => {
|
|
|
34150
34158
|
var task_delete_default = app62;
|
|
34151
34159
|
|
|
34152
34160
|
// app/lib/admin-roster.ts
|
|
34153
|
-
import { existsSync as
|
|
34161
|
+
import { existsSync as existsSync50, readdirSync as readdirSync29, readFileSync as readFileSync51 } from "fs";
|
|
34154
34162
|
import { resolve as resolve42 } from "path";
|
|
34155
34163
|
function readHouseAdminUserIds(accountsDir = ACCOUNTS_DIR) {
|
|
34156
34164
|
let entries2;
|
|
@@ -34161,7 +34169,7 @@ function readHouseAdminUserIds(accountsDir = ACCOUNTS_DIR) {
|
|
|
34161
34169
|
}
|
|
34162
34170
|
for (const entry2 of entries2) {
|
|
34163
34171
|
const cfgPath = resolve42(accountsDir, entry2, "account.json");
|
|
34164
|
-
if (!
|
|
34172
|
+
if (!existsSync50(cfgPath)) continue;
|
|
34165
34173
|
try {
|
|
34166
34174
|
const cfg = JSON.parse(readFileSync51(cfgPath, "utf-8"));
|
|
34167
34175
|
if (cfg.role !== "house") continue;
|
|
@@ -35005,7 +35013,7 @@ app72.route("/request-magic-link", request_magic_link_default);
|
|
|
35005
35013
|
var access_default = app72;
|
|
35006
35014
|
|
|
35007
35015
|
// server/routes/sites.ts
|
|
35008
|
-
import { existsSync as
|
|
35016
|
+
import { existsSync as existsSync51, readFileSync as readFileSync52, realpathSync as realpathSync8, statSync as statSync27 } from "fs";
|
|
35009
35017
|
import { resolve as resolve45 } from "path";
|
|
35010
35018
|
var SAFE_SEG_RE = /^[a-z0-9_][a-z0-9_.-]{0,99}$/i;
|
|
35011
35019
|
var MIME = {
|
|
@@ -35071,7 +35079,7 @@ app73.get("/:rel{.*}", (c) => {
|
|
|
35071
35079
|
}
|
|
35072
35080
|
let stat11;
|
|
35073
35081
|
try {
|
|
35074
|
-
stat11 =
|
|
35082
|
+
stat11 = existsSync51(filePath) ? statSync27(filePath) : null;
|
|
35075
35083
|
} catch {
|
|
35076
35084
|
stat11 = null;
|
|
35077
35085
|
}
|
|
@@ -35090,7 +35098,7 @@ app73.get("/:rel{.*}", (c) => {
|
|
|
35090
35098
|
console.error(`[sites] path-traversal-rejected path=${reqPath} reason=escape status=403`);
|
|
35091
35099
|
return c.text("Forbidden", 403);
|
|
35092
35100
|
}
|
|
35093
|
-
if (!
|
|
35101
|
+
if (!existsSync51(filePath)) {
|
|
35094
35102
|
console.error(`[sites] not-found path=${reqPath} status=404`);
|
|
35095
35103
|
return c.text("Not found", 404);
|
|
35096
35104
|
}
|
|
@@ -35221,7 +35229,7 @@ var VISITOR_COOKIE_NAME = "mxy_v";
|
|
|
35221
35229
|
var VISITOR_COOKIE_MAX_AGE_SECONDS = Math.floor(DEFAULT_TTL_MS / 1e3);
|
|
35222
35230
|
|
|
35223
35231
|
// app/lib/brand-config.ts
|
|
35224
|
-
import { existsSync as
|
|
35232
|
+
import { existsSync as existsSync52, readFileSync as readFileSync54 } from "fs";
|
|
35225
35233
|
import { join as join61 } from "path";
|
|
35226
35234
|
var cached2 = null;
|
|
35227
35235
|
var cachedAttempted = false;
|
|
@@ -35231,7 +35239,7 @@ function readBrandConfig() {
|
|
|
35231
35239
|
const platformRoot5 = process.env.MAXY_PLATFORM_ROOT;
|
|
35232
35240
|
if (!platformRoot5) return null;
|
|
35233
35241
|
const brandPath = join61(platformRoot5, "config", "brand.json");
|
|
35234
|
-
if (!
|
|
35242
|
+
if (!existsSync52(brandPath)) return null;
|
|
35235
35243
|
try {
|
|
35236
35244
|
cached2 = JSON.parse(readFileSync54(brandPath, "utf-8"));
|
|
35237
35245
|
return cached2;
|
|
@@ -35731,7 +35739,7 @@ var visitor_event_default = app76;
|
|
|
35731
35739
|
|
|
35732
35740
|
// server/routes/session.ts
|
|
35733
35741
|
import { resolve as resolve46 } from "path";
|
|
35734
|
-
import { existsSync as
|
|
35742
|
+
import { existsSync as existsSync53, writeFileSync as writeFileSync22, mkdirSync as mkdirSync13 } from "fs";
|
|
35735
35743
|
var UUID_RE5 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
35736
35744
|
function writeBrandingCache(accountId, agentSlug, branding) {
|
|
35737
35745
|
try {
|
|
@@ -35819,7 +35827,7 @@ app77.post("/", async (c) => {
|
|
|
35819
35827
|
let agentConfig = null;
|
|
35820
35828
|
if (account) {
|
|
35821
35829
|
const agentDir = resolve46(account.accountDir, "agents", agentSlug);
|
|
35822
|
-
if (!
|
|
35830
|
+
if (!existsSync53(agentDir) || !existsSync53(resolve46(agentDir, "config.json"))) {
|
|
35823
35831
|
return c.json({ error: "Agent not found" }, 404);
|
|
35824
35832
|
}
|
|
35825
35833
|
agentConfig = resolveAgentConfig(account.accountDir, agentSlug);
|
|
@@ -36904,7 +36912,7 @@ function startGraphHealthTimer() {
|
|
|
36904
36912
|
}
|
|
36905
36913
|
|
|
36906
36914
|
// app/lib/shared-folder-census.ts
|
|
36907
|
-
import { existsSync as
|
|
36915
|
+
import { existsSync as existsSync54, statSync as statSync29, readdirSync as readdirSync32 } from "fs";
|
|
36908
36916
|
import { join as join65 } from "path";
|
|
36909
36917
|
var import_dist15 = __toESM(require_dist(), 1);
|
|
36910
36918
|
var TAG64 = "[shared-census]";
|
|
@@ -36925,7 +36933,7 @@ function countFiles(dir) {
|
|
|
36925
36933
|
}
|
|
36926
36934
|
function runSharedFolderCensus(dataRoot = DATA_ROOT) {
|
|
36927
36935
|
const root = (0, import_dist15.sharedRoot)(dataRoot);
|
|
36928
|
-
const exists =
|
|
36936
|
+
const exists = existsSync54(root);
|
|
36929
36937
|
let isDir = false;
|
|
36930
36938
|
if (exists) {
|
|
36931
36939
|
try {
|
|
@@ -36950,7 +36958,7 @@ function startSharedFolderCensus() {
|
|
|
36950
36958
|
|
|
36951
36959
|
// app/lib/cred-refresh-census.ts
|
|
36952
36960
|
import { readdirSync as readdirSync33, readFileSync as readFileSync57 } from "fs";
|
|
36953
|
-
import { homedir as
|
|
36961
|
+
import { homedir as homedir4 } from "os";
|
|
36954
36962
|
import { join as join66 } from "path";
|
|
36955
36963
|
var TAG65 = "[claude-auth]";
|
|
36956
36964
|
function refreshTokenLength(raw) {
|
|
@@ -36991,7 +36999,7 @@ function censusResult(rows) {
|
|
|
36991
36999
|
if (rows.length === 0) return "no-brands-found";
|
|
36992
37000
|
return rows.some(isBlank) ? "blank-tokens" : "ok";
|
|
36993
37001
|
}
|
|
36994
|
-
function runCredRefreshCensus(home =
|
|
37002
|
+
function runCredRefreshCensus(home = homedir4()) {
|
|
36995
37003
|
const rows = surveyBrandCredentials(home);
|
|
36996
37004
|
const blank = rows.filter(isBlank).length;
|
|
36997
37005
|
const detail = rows.map((r) => `${r.brand}:${r.refreshTokenLen === null ? "unreadable" : r.refreshTokenLen}`).join(",");
|
|
@@ -37237,7 +37245,7 @@ async function migrateUploads(opts = {}) {
|
|
|
37237
37245
|
|
|
37238
37246
|
// app/lib/migrate-admin-webchat-sidecars.ts
|
|
37239
37247
|
import { readdir as readdir7, readFile as readFile13, rename as rename5, writeFile as writeFile4, unlink as unlink4 } from "fs/promises";
|
|
37240
|
-
import { existsSync as
|
|
37248
|
+
import { existsSync as existsSync55 } from "fs";
|
|
37241
37249
|
import { join as join67 } from "path";
|
|
37242
37250
|
var ADMIN_ROLE2 = "admin";
|
|
37243
37251
|
var WEBCHAT_CHANNEL2 = "webchat";
|
|
@@ -37267,7 +37275,7 @@ async function writeRaw(path, obj) {
|
|
|
37267
37275
|
await rename5(tmp, path);
|
|
37268
37276
|
} catch (err) {
|
|
37269
37277
|
try {
|
|
37270
|
-
if (
|
|
37278
|
+
if (existsSync55(tmp)) await unlink4(tmp);
|
|
37271
37279
|
} catch {
|
|
37272
37280
|
}
|
|
37273
37281
|
throw err;
|
|
@@ -37390,7 +37398,7 @@ async function migrateAdminWebchatSidecars(opts = {}) {
|
|
|
37390
37398
|
|
|
37391
37399
|
// app/lib/migrate-sidecar-account-ids.ts
|
|
37392
37400
|
import { readdir as readdir8, readFile as readFile14, rename as rename6, writeFile as writeFile5, unlink as unlink5 } from "fs/promises";
|
|
37393
|
-
import { existsSync as
|
|
37401
|
+
import { existsSync as existsSync56 } from "fs";
|
|
37394
37402
|
import { join as join68 } from "path";
|
|
37395
37403
|
var SESSION_META_RE2 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.meta\.json$/i;
|
|
37396
37404
|
function projectSlugForCwd(cwd) {
|
|
@@ -37417,7 +37425,7 @@ async function writeRaw2(path, obj) {
|
|
|
37417
37425
|
await rename6(tmp, path);
|
|
37418
37426
|
} catch (err) {
|
|
37419
37427
|
try {
|
|
37420
|
-
if (
|
|
37428
|
+
if (existsSync56(tmp)) await unlink5(tmp);
|
|
37421
37429
|
} catch {
|
|
37422
37430
|
}
|
|
37423
37431
|
throw err;
|
|
@@ -39089,7 +39097,7 @@ function createWebchatChannelRoutes(deps) {
|
|
|
39089
39097
|
}
|
|
39090
39098
|
|
|
39091
39099
|
// app/lib/webchat/gateway/resolve-turn-answer.ts
|
|
39092
|
-
import { existsSync as
|
|
39100
|
+
import { existsSync as existsSync57, openSync as openSync9, readSync as readSync8, closeSync as closeSync9, readdirSync as readdirSync34 } from "fs";
|
|
39093
39101
|
import { join as join69 } from "path";
|
|
39094
39102
|
|
|
39095
39103
|
// app/lib/channel-delivery/outbound-guard.ts
|
|
@@ -39151,7 +39159,7 @@ function resolveTurnAnswer(p) {
|
|
|
39151
39159
|
return segmentText(guardOutbound(p.senderId, parts.join("\n\n"))).join("\n\n");
|
|
39152
39160
|
}
|
|
39153
39161
|
function findJsonl(projectsRoot, sessionId) {
|
|
39154
|
-
if (!
|
|
39162
|
+
if (!existsSync57(projectsRoot)) return null;
|
|
39155
39163
|
let slugs;
|
|
39156
39164
|
try {
|
|
39157
39165
|
slugs = readdirSync34(projectsRoot, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name);
|
|
@@ -39160,7 +39168,7 @@ function findJsonl(projectsRoot, sessionId) {
|
|
|
39160
39168
|
}
|
|
39161
39169
|
for (const slug of slugs) {
|
|
39162
39170
|
const live = join69(projectsRoot, slug, `${sessionId}.jsonl`);
|
|
39163
|
-
if (
|
|
39171
|
+
if (existsSync57(live)) return live;
|
|
39164
39172
|
}
|
|
39165
39173
|
return null;
|
|
39166
39174
|
}
|
|
@@ -42194,7 +42202,7 @@ function businessConnectionCensusLine(c) {
|
|
|
42194
42202
|
}
|
|
42195
42203
|
|
|
42196
42204
|
// app/lib/telegram/business-window-census.ts
|
|
42197
|
-
import { readdirSync as readdirSync36, existsSync as
|
|
42205
|
+
import { readdirSync as readdirSync36, existsSync as existsSync58 } from "fs";
|
|
42198
42206
|
import { join as join72 } from "path";
|
|
42199
42207
|
var BUSINESS_WINDOW_CENSUS_TAG = "[telegram-audit]";
|
|
42200
42208
|
var EXPIRING_SOON_S = 3600;
|
|
@@ -42224,7 +42232,7 @@ function readBusinessChatClocks(accountIds) {
|
|
|
42224
42232
|
const out = [];
|
|
42225
42233
|
for (const accountId of accountIds) {
|
|
42226
42234
|
const dir = join72(STORE_ROOT2(), accountId);
|
|
42227
|
-
if (!
|
|
42235
|
+
if (!existsSync58(dir)) continue;
|
|
42228
42236
|
let names;
|
|
42229
42237
|
try {
|
|
42230
42238
|
names = readdirSync36(dir);
|
|
@@ -42285,7 +42293,7 @@ async function getTelegramBusinessConnection(botToken, connectionId, opts = {})
|
|
|
42285
42293
|
}
|
|
42286
42294
|
|
|
42287
42295
|
// server/telegram-migrate.ts
|
|
42288
|
-
import { readFileSync as readFileSync58, writeFileSync as writeFileSync23, existsSync as
|
|
42296
|
+
import { readFileSync as readFileSync58, writeFileSync as writeFileSync23, existsSync as existsSync59, renameSync as renameSync11, mkdirSync as mkdirSync14 } from "fs";
|
|
42289
42297
|
import { dirname as dirname19, join as join73 } from "path";
|
|
42290
42298
|
function migrateTelegramTwoSlot(input) {
|
|
42291
42299
|
const out = [];
|
|
@@ -42346,7 +42354,7 @@ function migrateTelegramTwoSlot(input) {
|
|
|
42346
42354
|
return out;
|
|
42347
42355
|
}
|
|
42348
42356
|
function moveSecret(from, to) {
|
|
42349
|
-
if (!
|
|
42357
|
+
if (!existsSync59(from)) return;
|
|
42350
42358
|
mkdirSync14(dirname19(to), { recursive: true, mode: 448 });
|
|
42351
42359
|
renameSync11(from, to);
|
|
42352
42360
|
}
|
|
@@ -42432,12 +42440,12 @@ function backfillMisfiledRecords(params) {
|
|
|
42432
42440
|
}
|
|
42433
42441
|
|
|
42434
42442
|
// server/lib/booking-site-accounts.ts
|
|
42435
|
-
import { existsSync as
|
|
42443
|
+
import { existsSync as existsSync60, readFileSync as readFileSync60 } from "fs";
|
|
42436
42444
|
import { resolve as resolve53 } from "path";
|
|
42437
42445
|
function listBookingSiteAccounts(accounts) {
|
|
42438
42446
|
return accounts.filter((a) => {
|
|
42439
42447
|
const availPath = resolve53(a.accountDir, "calendar-availability.json");
|
|
42440
|
-
if (!
|
|
42448
|
+
if (!existsSync60(availPath)) return false;
|
|
42441
42449
|
try {
|
|
42442
42450
|
const cfg = JSON.parse(readFileSync60(availPath, "utf-8"));
|
|
42443
42451
|
return typeof cfg.bookingDbName === "string" && cfg.bookingDbName.length > 0;
|
|
@@ -42477,7 +42485,7 @@ function broadcastAdminShutdown(reason) {
|
|
|
42477
42485
|
|
|
42478
42486
|
// ../lib/entitlement/src/index.ts
|
|
42479
42487
|
import { createPublicKey, createHash as createHash7, verify as cryptoVerify } from "crypto";
|
|
42480
|
-
import { existsSync as
|
|
42488
|
+
import { existsSync as existsSync61, readFileSync as readFileSync61, statSync as statSync32 } from "fs";
|
|
42481
42489
|
import { resolve as resolve54 } from "path";
|
|
42482
42490
|
|
|
42483
42491
|
// ../lib/entitlement/src/canonicalize.ts
|
|
@@ -42526,7 +42534,7 @@ function resolveEntitlement(brand, account) {
|
|
|
42526
42534
|
return logResolved(implicitTrust(account), null);
|
|
42527
42535
|
}
|
|
42528
42536
|
const entitlementPath = resolve54(brand.configDir, "entitlement.json");
|
|
42529
|
-
if (!
|
|
42537
|
+
if (!existsSync61(entitlementPath)) {
|
|
42530
42538
|
return logResolved(anonymousFallback("missing"), { reason: "missing" });
|
|
42531
42539
|
}
|
|
42532
42540
|
const stat11 = statSync32(entitlementPath);
|
|
@@ -42719,10 +42727,10 @@ installMediaDownloadGuard();
|
|
|
42719
42727
|
var PLATFORM_ROOT6 = process.env.MAXY_PLATFORM_ROOT || "";
|
|
42720
42728
|
var BRAND_JSON_PATH = PLATFORM_ROOT6 ? join75(PLATFORM_ROOT6, "config", "brand.json") : "";
|
|
42721
42729
|
var BRAND = { productName: "Maxy", hostname: "maxy", configDir: ".maxy", marketingUrl: "https://getmaxy.com" };
|
|
42722
|
-
if (BRAND_JSON_PATH && !
|
|
42730
|
+
if (BRAND_JSON_PATH && !existsSync62(BRAND_JSON_PATH)) {
|
|
42723
42731
|
console.error(`[brand] WARNING: brand.json not found at ${BRAND_JSON_PATH} \u2014 using Maxy defaults`);
|
|
42724
42732
|
}
|
|
42725
|
-
if (BRAND_JSON_PATH &&
|
|
42733
|
+
if (BRAND_JSON_PATH && existsSync62(BRAND_JSON_PATH)) {
|
|
42726
42734
|
try {
|
|
42727
42735
|
const parsed = JSON.parse(readFileSync62(BRAND_JSON_PATH, "utf-8"));
|
|
42728
42736
|
BRAND = { ...BRAND, ...parsed };
|
|
@@ -42756,10 +42764,10 @@ var brandLoginOpts = {
|
|
|
42756
42764
|
appleTouchIconPath: brandAppIcon512Path,
|
|
42757
42765
|
themeColor: BRAND.defaultColors?.primary
|
|
42758
42766
|
};
|
|
42759
|
-
var ALIAS_DOMAINS_PATH = join75(
|
|
42767
|
+
var ALIAS_DOMAINS_PATH = join75(homedir5(), BRAND.configDir, "alias-domains.json");
|
|
42760
42768
|
function loadAliasDomains() {
|
|
42761
42769
|
try {
|
|
42762
|
-
if (!
|
|
42770
|
+
if (!existsSync62(ALIAS_DOMAINS_PATH)) return null;
|
|
42763
42771
|
const parsed = JSON.parse(readFileSync62(ALIAS_DOMAINS_PATH, "utf-8"));
|
|
42764
42772
|
if (!Array.isArray(parsed)) {
|
|
42765
42773
|
console.error("[alias-domains] malformed alias-domains.json \u2014 expected array");
|
|
@@ -43791,7 +43799,7 @@ app80.get("/agent-assets/:slug/:filename", (c) => {
|
|
|
43791
43799
|
console.error(`[agent-assets] path-traversal-rejected slug=${slug} file=${filename}`);
|
|
43792
43800
|
return c.text("Forbidden", 403);
|
|
43793
43801
|
}
|
|
43794
|
-
if (!
|
|
43802
|
+
if (!existsSync62(filePath)) {
|
|
43795
43803
|
console.error(`[agent-assets] serve slug=${slug} file=${filename} status=404`);
|
|
43796
43804
|
return c.text("Not found", 404);
|
|
43797
43805
|
}
|
|
@@ -43821,7 +43829,7 @@ app80.get("/generated/:filename", (c) => {
|
|
|
43821
43829
|
console.error(`[generated] serve file=${filename} status=403`);
|
|
43822
43830
|
return c.text("Forbidden", 403);
|
|
43823
43831
|
}
|
|
43824
|
-
if (!
|
|
43832
|
+
if (!existsSync62(filePath)) {
|
|
43825
43833
|
console.error(`[generated] serve file=${filename} status=404`);
|
|
43826
43834
|
return c.text("Not found", 404);
|
|
43827
43835
|
}
|
|
@@ -43841,7 +43849,7 @@ app80.route("/v", visitor_consent_default);
|
|
|
43841
43849
|
var htmlCache = /* @__PURE__ */ new Map();
|
|
43842
43850
|
var brandLogoPath = "/brand/maxy-monochrome.png";
|
|
43843
43851
|
var brandIconPath = "/brand/maxy-monochrome.png";
|
|
43844
|
-
if (BRAND_JSON_PATH &&
|
|
43852
|
+
if (BRAND_JSON_PATH && existsSync62(BRAND_JSON_PATH)) {
|
|
43845
43853
|
try {
|
|
43846
43854
|
const fullBrand = JSON.parse(readFileSync62(BRAND_JSON_PATH, "utf-8"));
|
|
43847
43855
|
if (fullBrand.assets?.logo) brandLogoPath = `/brand/${fullBrand.assets.logo}`;
|
|
@@ -43870,7 +43878,7 @@ var brandScript = `<script>window.__BRAND__=${JSON.stringify({
|
|
|
43870
43878
|
var brandThemeColor = BRAND.defaultColors?.primary ?? "#000000";
|
|
43871
43879
|
var brandBackgroundColor = BRAND.defaultColors?.background ?? "#ffffff";
|
|
43872
43880
|
var brandAppIconsExist = [brandAppIcon192Path, brandAppIcon512Path, brandMaskableIconPath].every(
|
|
43873
|
-
(p) =>
|
|
43881
|
+
(p) => existsSync62(resolve55(process.cwd(), "public", p.replace(/^\//, "")))
|
|
43874
43882
|
);
|
|
43875
43883
|
var SW_SOURCE = (() => {
|
|
43876
43884
|
try {
|
|
@@ -43883,7 +43891,7 @@ function readInstalledVersion() {
|
|
|
43883
43891
|
try {
|
|
43884
43892
|
if (!PLATFORM_ROOT6) return "unknown";
|
|
43885
43893
|
const versionFile = join75(PLATFORM_ROOT6, "config", `.${BRAND.hostname}-version`);
|
|
43886
|
-
if (!
|
|
43894
|
+
if (!existsSync62(versionFile)) return "unknown";
|
|
43887
43895
|
const content = readFileSync62(versionFile, "utf-8").trim();
|
|
43888
43896
|
return content || "unknown";
|
|
43889
43897
|
} catch {
|
|
@@ -43912,13 +43920,13 @@ ${clientErrorReporterScript}
|
|
|
43912
43920
|
return html;
|
|
43913
43921
|
}
|
|
43914
43922
|
function loadBrandingCache(agentSlug) {
|
|
43915
|
-
const configDir = join75(
|
|
43923
|
+
const configDir = join75(homedir5(), BRAND.configDir);
|
|
43916
43924
|
try {
|
|
43917
43925
|
const verdict = resolvePublicAddressFromDisk(agentSlug);
|
|
43918
43926
|
const accountId = verdict.kind === "served" ? verdict.owner.accountId : getDefaultAccountId();
|
|
43919
43927
|
if (!accountId) return null;
|
|
43920
43928
|
const cachePath = join75(configDir, "branding-cache", accountId, `${agentSlug}.json`);
|
|
43921
|
-
if (!
|
|
43929
|
+
if (!existsSync62(cachePath)) return null;
|
|
43922
43930
|
return JSON.parse(readFileSync62(cachePath, "utf-8"));
|
|
43923
43931
|
} catch {
|
|
43924
43932
|
return null;
|
|
@@ -44171,7 +44179,7 @@ console.log(`${BRAND.productName} listening on http://${hostname}:${port}`);
|
|
|
44171
44179
|
const reconcilePlatformRoot = process.env.MAXY_PLATFORM_ROOT ?? join75(__dirname, "..");
|
|
44172
44180
|
const reconcileScript = resolve55(reconcilePlatformRoot, "plugins/scheduling/mcp/dist/scripts/reconcile-bookings.js");
|
|
44173
44181
|
const runReconcile = (ctx) => {
|
|
44174
|
-
if (!
|
|
44182
|
+
if (!existsSync62(reconcileScript)) return;
|
|
44175
44183
|
try {
|
|
44176
44184
|
const child = spawn3(process.execPath, [reconcileScript], {
|
|
44177
44185
|
env: { ...process.env, PLATFORM_ROOT: reconcilePlatformRoot },
|
|
@@ -44217,7 +44225,7 @@ console.log(`${BRAND.productName} listening on http://${hostname}:${port}`);
|
|
|
44217
44225
|
firstRunDelayMs: 3e4,
|
|
44218
44226
|
detached: true,
|
|
44219
44227
|
run: (ctx) => {
|
|
44220
|
-
if (!
|
|
44228
|
+
if (!existsSync62(dreamSweepScript)) return;
|
|
44221
44229
|
try {
|
|
44222
44230
|
const child = spawn3(process.execPath, [dreamSweepScript], {
|
|
44223
44231
|
env: { ...process.env, PLATFORM_ROOT: dreamPlatformRoot },
|
|
@@ -44237,7 +44245,7 @@ console.log(`${BRAND.productName} listening on http://${hostname}:${port}`);
|
|
|
44237
44245
|
const outlookScript = resolve55(outlookPlatformRoot, "plugins/outlook/mcp/dist/scripts/complete-registration.js");
|
|
44238
44246
|
const OUTLOOK_COMPLETE_INTERVAL_MS = 3e4;
|
|
44239
44247
|
const runOutlookComplete = (ctx) => {
|
|
44240
|
-
if (!
|
|
44248
|
+
if (!existsSync62(outlookScript)) return;
|
|
44241
44249
|
try {
|
|
44242
44250
|
const child = spawn3(process.execPath, [outlookScript], {
|
|
44243
44251
|
env: { ...process.env, PLATFORM_ROOT: outlookPlatformRoot },
|
|
@@ -44266,12 +44274,12 @@ console.log(`${BRAND.productName} listening on http://${hostname}:${port}`);
|
|
|
44266
44274
|
const STRANDED_UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
44267
44275
|
const runStrandedAudit = () => {
|
|
44268
44276
|
try {
|
|
44269
|
-
if (!
|
|
44277
|
+
if (!existsSync62(strandedAccountsDir)) return;
|
|
44270
44278
|
const now = Date.now();
|
|
44271
44279
|
for (const name of readdirSync37(strandedAccountsDir)) {
|
|
44272
44280
|
if (!STRANDED_UUID_RE.test(name)) continue;
|
|
44273
44281
|
const pendingPath2 = resolve55(strandedAccountsDir, name, "secrets/outlook/pending-devicecode.enc");
|
|
44274
|
-
if (!
|
|
44282
|
+
if (!existsSync62(pendingPath2)) continue;
|
|
44275
44283
|
const ageMs2 = now - statSync33(pendingPath2).mtimeMs;
|
|
44276
44284
|
if (ageMs2 > STRANDED_AGE_MS) {
|
|
44277
44285
|
console.error(`[outlook-mcp] devicecode-stranded account=${name} ageSec=${Math.floor(ageMs2 / 1e3)}`);
|
|
@@ -44308,7 +44316,7 @@ console.log(`${BRAND.productName} listening on http://${hostname}:${port}`);
|
|
|
44308
44316
|
const googleAuditScript = resolve55(googleRoot, "plugins/google/mcp/dist/scripts/account-audit.js");
|
|
44309
44317
|
const GOOGLE_ACCOUNT_AUDIT_INTERVAL_MS = 36e5;
|
|
44310
44318
|
const runGoogleAccountAudit = (ctx) => {
|
|
44311
|
-
if (!
|
|
44319
|
+
if (!existsSync62(googleAuditScript)) return;
|
|
44312
44320
|
try {
|
|
44313
44321
|
const child = spawn3(process.execPath, [googleAuditScript], {
|
|
44314
44322
|
env: { ...process.env, PLATFORM_ROOT: googleRoot },
|
|
@@ -44381,8 +44389,8 @@ registerLoop({
|
|
|
44381
44389
|
accounts: listValidAccounts().map((a) => ({ accountId: a.accountId, accountDir: a.accountDir })),
|
|
44382
44390
|
secretPathFor: secretPath,
|
|
44383
44391
|
legacySecretPathFor: (botType, accountId) => resolve55(
|
|
44384
|
-
|
|
44385
|
-
|
|
44392
|
+
homedir5(),
|
|
44393
|
+
configDirName(),
|
|
44386
44394
|
`${botType === "admin" ? ".telegram-admin-webhook-secret" : ".telegram-webhook-secret"}.${accountId}`
|
|
44387
44395
|
),
|
|
44388
44396
|
// Counted here and nowhere else: the session-key re-key strands these and no
|
|
@@ -44417,7 +44425,7 @@ registerLoop({
|
|
|
44417
44425
|
}
|
|
44418
44426
|
const lines = buildTelegramAuditLines({
|
|
44419
44427
|
accounts,
|
|
44420
|
-
secretFileExists: (botId) =>
|
|
44428
|
+
secretFileExists: (botId) => existsSync62(secretPath(botId)),
|
|
44421
44429
|
agentActive: isActiveAgentSlug,
|
|
44422
44430
|
// Task 2619 — the card set a specialist binding is reconciled against.
|
|
44423
44431
|
specialistCards: (accountDir) => listSpecialistCardNames(join75(accountDir, "specialists", "agents")),
|
|
@@ -44770,7 +44778,7 @@ registerLoop({
|
|
|
44770
44778
|
}
|
|
44771
44779
|
};
|
|
44772
44780
|
const spawnPublish = (account, ctx) => {
|
|
44773
|
-
if (!
|
|
44781
|
+
if (!existsSync62(publishScript)) return;
|
|
44774
44782
|
try {
|
|
44775
44783
|
const child = spawn3(process.execPath, [publishScript], {
|
|
44776
44784
|
env: {
|
|
@@ -44792,7 +44800,7 @@ registerLoop({
|
|
|
44792
44800
|
const availPath = resolve55(account.accountDir, "calendar-availability.json");
|
|
44793
44801
|
let hasBookingSite = false;
|
|
44794
44802
|
try {
|
|
44795
|
-
if (
|
|
44803
|
+
if (existsSync62(availPath)) {
|
|
44796
44804
|
const cfg = JSON.parse(readFileSync62(availPath, "utf-8"));
|
|
44797
44805
|
hasBookingSite = typeof cfg.bookingDbName === "string" && cfg.bookingDbName.length > 0;
|
|
44798
44806
|
}
|
|
@@ -44801,7 +44809,7 @@ registerLoop({
|
|
|
44801
44809
|
if (!hasBookingSite) return;
|
|
44802
44810
|
const statePath = resolve55(account.accountDir, "state", "booking-availability", "last-publish.json");
|
|
44803
44811
|
let lastSuccessAt = null;
|
|
44804
|
-
if (
|
|
44812
|
+
if (existsSync62(statePath)) {
|
|
44805
44813
|
try {
|
|
44806
44814
|
const rec = JSON.parse(readFileSync62(statePath, "utf-8"));
|
|
44807
44815
|
lastSuccessAt = rec.lastSuccessAt ?? null;
|
|
@@ -44843,7 +44851,7 @@ startDispatchTgCensus(() => getSession());
|
|
|
44843
44851
|
const auditLogDir = process.env.LOG_DIR ?? LOG_DIR;
|
|
44844
44852
|
const CONNECTOR_AUDIT_INTERVAL_MS = 3e5;
|
|
44845
44853
|
const runConnectorAudit = (ctx) => {
|
|
44846
|
-
if (!
|
|
44854
|
+
if (!existsSync62(auditScript)) return;
|
|
44847
44855
|
try {
|
|
44848
44856
|
const child = spawn3(process.execPath, [auditScript], {
|
|
44849
44857
|
env: { ...process.env, PLATFORM_ROOT: auditPlatformRoot, LOG_DIR: auditLogDir },
|
|
@@ -44965,7 +44973,7 @@ try {
|
|
|
44965
44973
|
var ADMINUSER_RECONCILE_INTERVAL_MS = 60 * 60 * 1e3;
|
|
44966
44974
|
async function runAdminUserReconcileTick() {
|
|
44967
44975
|
try {
|
|
44968
|
-
if (!
|
|
44976
|
+
if (!existsSync62(USERS_FILE)) {
|
|
44969
44977
|
console.error("[adminuser-self-heal] skip reason=no-users-file");
|
|
44970
44978
|
return;
|
|
44971
44979
|
}
|
|
@@ -45052,7 +45060,7 @@ var runIngestAuditTick = () => {
|
|
|
45052
45060
|
agentExists: (accountId, slug) => {
|
|
45053
45061
|
if (!house) return false;
|
|
45054
45062
|
const dir = isHouseAccountKey(house.accountId, accountId) ? house.accountDir : join75(ACCOUNTS_DIR, accountId);
|
|
45055
|
-
return
|
|
45063
|
+
return existsSync62(join75(dir, "agents", slug, "config.json"));
|
|
45056
45064
|
}
|
|
45057
45065
|
});
|
|
45058
45066
|
} catch (err) {
|
|
@@ -45101,7 +45109,7 @@ registerLoop({
|
|
|
45101
45109
|
houseAccountId: () => resolveAccount()?.accountId ?? null,
|
|
45102
45110
|
activeSlugs: () => listValidAccounts().map((a) => {
|
|
45103
45111
|
const agentsRoot = join75(a.accountDir, "agents");
|
|
45104
|
-
if (!
|
|
45112
|
+
if (!existsSync62(agentsRoot)) return { accountId: a.accountId, slugs: [] };
|
|
45105
45113
|
const slugs = readdirSync37(agentsRoot, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name).filter((slug) => isActiveAgentSlug(a.accountDir, slug));
|
|
45106
45114
|
return { accountId: a.accountId, slugs };
|
|
45107
45115
|
})
|
|
@@ -45115,7 +45123,7 @@ registerLoop({
|
|
|
45115
45123
|
});
|
|
45116
45124
|
var USERS_RECONCILE_INTERVAL_MS = 60 * 60 * 1e3;
|
|
45117
45125
|
function countUsersRows() {
|
|
45118
|
-
if (!
|
|
45126
|
+
if (!existsSync62(USERS_FILE)) return 0;
|
|
45119
45127
|
const raw = readFileSync62(USERS_FILE, "utf-8").trim();
|
|
45120
45128
|
if (!raw) return 0;
|
|
45121
45129
|
const users = JSON.parse(raw);
|