@rubytech/create-maxy 1.0.884 → 1.0.885

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.
@@ -42,7 +42,8 @@ import {
42
42
  load,
43
43
  logPath,
44
44
  pickComponentBytes,
45
- preflushSliceOf,
45
+ readBundleSubPlugins,
46
+ reconcileEnabledPlugins,
46
47
  recordFailedAttempt,
47
48
  render,
48
49
  renderLoginPage,
@@ -51,7 +52,6 @@ import {
51
52
  resolveAgentConfig,
52
53
  resolveBrowserTransport,
53
54
  resolveClientIp,
54
- resolveConversationLogPaths,
55
55
  resolveDefaultAgentSlug,
56
56
  resolveEntitlement,
57
57
  resolveUserAccounts,
@@ -76,7 +76,7 @@ import {
76
76
  vncLog,
77
77
  waitForExit,
78
78
  writeChromiumWrapper
79
- } from "./chunk-5PQU2HW2.js";
79
+ } from "./chunk-ZVO5ASQA.js";
80
80
  import {
81
81
  CDP_PORT,
82
82
  COMMERCIAL_MODE,
@@ -90,6 +90,7 @@ import {
90
90
  clearSessionHistory,
91
91
  completeGrantSetup,
92
92
  consumeWantsPriorConversation,
93
+ emitMissingOnResolve,
93
94
  getAccountIdForSession,
94
95
  getActiveClient,
95
96
  getAgentNameForSession,
@@ -97,6 +98,7 @@ import {
97
98
  getGrantForSession,
98
99
  getGroupSlugForSession,
99
100
  getRoleForSession,
101
+ getSessionKeyByConversationId,
100
102
  getSessionMessages,
101
103
  getUserIdForSession,
102
104
  getUserNameForSession,
@@ -104,7 +106,6 @@ import {
104
106
  interruptClient,
105
107
  listAdminSessionsInProgress,
106
108
  mintAdminSessionToken,
107
- preConversationLogStream,
108
109
  registerGrantSession,
109
110
  registerResumedSession,
110
111
  registerSession,
@@ -115,7 +116,7 @@ import {
115
116
  sigtermFlushStreamLogs,
116
117
  unregisterSession,
117
118
  validateSession
118
- } from "./chunk-2INJCOYG.js";
119
+ } from "./chunk-NPKQWE3S.js";
119
120
  import {
120
121
  CLOUDFLARE_TASK_DIAGNOSTICS,
121
122
  appendCloudflareSteps,
@@ -662,8 +663,8 @@ var serveStatic = (options = { root: "" }) => {
662
663
  };
663
664
 
664
665
  // server/index.ts
665
- import { readFileSync as readFileSync18, existsSync as existsSync23, watchFile } from "fs";
666
- import { resolve as resolve21, join as join11, basename as basename4 } from "path";
666
+ import { readFileSync as readFileSync18, existsSync as existsSync24, watchFile } from "fs";
667
+ import { resolve as resolve21, join as join12, basename as basename4 } from "path";
667
668
  import { homedir as homedir3 } from "os";
668
669
 
669
670
  // app/lib/agent-slug-pattern.ts
@@ -4425,9 +4426,8 @@ app3.post("/", async (c) => {
4425
4426
  if (!account) {
4426
4427
  return c.json({ error: "No account configured" }, 500);
4427
4428
  }
4428
- const publicSseConvId = getConversationIdForSession(session_key);
4429
- const sseLog = publicSseConvId ? agentLogStream("sse-events", account.accountDir, publicSseConvId) : preConversationLogStream("sse-events", account.accountDir);
4430
- const sk = publicSseConvId?.slice(0, 8) ?? session_key.slice(0, 8);
4429
+ const sseLog = agentLogStream("sse-events", account.accountDir, session_key);
4430
+ const sk = session_key.slice(0, 8);
4431
4431
  const agentName = getAgentNameForSession(session_key);
4432
4432
  if (!agentName) {
4433
4433
  console.log(`[chat] no agent for session=${sk} \u2014 session expired or server restarted`);
@@ -7474,7 +7474,7 @@ var app11 = new Hono();
7474
7474
  app11.post("/cancel", requireAdminSession, async (c) => {
7475
7475
  const session_key = c.var.cacheKey;
7476
7476
  try {
7477
- const { interruptClient: interruptClient2 } = await import("./client-pool-JAM3QHGW.js");
7477
+ const { interruptClient: interruptClient2 } = await import("./client-pool-QUMX7OUT.js");
7478
7478
  await interruptClient2(session_key);
7479
7479
  return c.json({ ok: true });
7480
7480
  } catch (err) {
@@ -7578,8 +7578,7 @@ app11.post("/", requireAdminSession, async (c) => {
7578
7578
  try {
7579
7579
  const parsed = JSON.parse(message);
7580
7580
  if (parsed._lifecycle) {
7581
- const lifecycleConvId = getConversationIdForSession(session_key);
7582
- const lifecycleLog = lifecycleConvId ? agentLogStream("component-lifecycle", account.accountDir, lifecycleConvId) : preConversationLogStream("component-lifecycle", account.accountDir);
7581
+ const lifecycleLog = agentLogStream("component-lifecycle", account.accountDir, session_key);
7583
7582
  const ts = (/* @__PURE__ */ new Date()).toISOString().slice(11, 23);
7584
7583
  const detail = parsed.filePath ? ` filePath=${parsed.filePath}` : "";
7585
7584
  lifecycleLog.write(`[${ts}] [component:${parsed.component ?? "unknown"}] ${parsed.event ?? "unknown"}${detail}
@@ -7603,8 +7602,7 @@ app11.post("/", requireAdminSession, async (c) => {
7603
7602
  try {
7604
7603
  const parsed = JSON.parse(message);
7605
7604
  if (isComponentDone(parsed)) {
7606
- const componentConvId = getConversationIdForSession(session_key);
7607
- const componentLog = componentConvId ? agentLogStream("component-lifecycle", account.accountDir, componentConvId) : preConversationLogStream("component-lifecycle", account.accountDir);
7605
+ const componentLog = agentLogStream("component-lifecycle", account.accountDir, session_key);
7608
7606
  const ts = (/* @__PURE__ */ new Date()).toISOString().slice(11, 23);
7609
7607
  message = transformComponentDone(parsed);
7610
7608
  componentLog.write(`[${ts}] [component:${parsed.component}] componentDone \u2192 transformed
@@ -7668,11 +7666,11 @@ app11.post("/", requireAdminSession, async (c) => {
7668
7666
  }
7669
7667
  }
7670
7668
  const encoder = new TextEncoder();
7671
- const sseLogStream = agentLogStream("sse-events", account.accountDir, conversationId);
7669
+ const sseLogStream = agentLogStream("sse-events", account.accountDir, session_key);
7672
7670
  const sk = conversationId.slice(0, 8);
7673
- const teeStreamLogPath = resolve8(account.accountDir, "logs", `claude-agent-stream-${conversationId}.log`);
7671
+ const teeStreamLogPath = resolve8(account.accountDir, "logs", `claude-agent-stream-${session_key}.log`);
7674
7672
  try {
7675
- appendFileSync3(teeStreamLogPath, `[${(/* @__PURE__ */ new Date()).toISOString()}] [chat-route-version=task965-mint-at-entry] cacheKey=${session_key.slice(0, 12)}\u2026 conversationId=${conversationId}
7673
+ appendFileSync3(teeStreamLogPath, `[${(/* @__PURE__ */ new Date()).toISOString()}] [chat-route-version=task1006-sessionkey-on-disk] cacheKey=${session_key.slice(0, 12)}\u2026 conversationId=${conversationId}
7676
7674
  `);
7677
7675
  } catch {
7678
7676
  }
@@ -7760,7 +7758,7 @@ app11.post("/", requireAdminSession, async (c) => {
7760
7758
  const reqSignal = c.req.raw?.signal;
7761
7759
  if (reqSignal) {
7762
7760
  reqSignal.addEventListener("abort", () => {
7763
- const abortStreamLog = agentLogStream("claude-agent-stream", account.accountDir, conversationId);
7761
+ const abortStreamLog = agentLogStream("claude-agent-stream", account.accountDir, session_key);
7764
7762
  const ts = (/* @__PURE__ */ new Date()).toISOString().slice(11, 23);
7765
7763
  sseLog.write(`[${ts}] [${sk}] admin: ABORT [operator-cancel] interrupting pool client
7766
7764
  `);
@@ -7976,8 +7974,25 @@ app13.post("/", requireAdminSession, async (c) => {
7976
7974
  var compact_default = app13;
7977
7975
 
7978
7976
  // server/routes/admin/logs.ts
7979
- import { existsSync as existsSync12, readdirSync as readdirSync5, readFileSync as readFileSync11, statSync as statSync6 } from "fs";
7977
+ import { existsSync as existsSync13, readdirSync as readdirSync5, readFileSync as readFileSync11, statSync as statSync6 } from "fs";
7980
7978
  import { resolve as resolve9, basename as basename2 } from "path";
7979
+
7980
+ // app/lib/logs-read-resolve.ts
7981
+ import { existsSync as existsSync12 } from "fs";
7982
+ import { join as join9 } from "path";
7983
+ function resolveSessionLogPaths(filename, logDirs) {
7984
+ const tried = [filename];
7985
+ const hits = [];
7986
+ for (const dir of logDirs) {
7987
+ const fullPath = join9(dir, filename);
7988
+ if (existsSync12(fullPath)) {
7989
+ hits.push({ path: fullPath, dir });
7990
+ }
7991
+ }
7992
+ return { hits, tried };
7993
+ }
7994
+
7995
+ // server/routes/admin/logs.ts
7981
7996
  var TAIL_BYTES = 8192;
7982
7997
  var app14 = new Hono();
7983
7998
  app14.get("/", async (c) => {
@@ -8040,31 +8055,29 @@ app14.get("/", async (c) => {
8040
8055
  }
8041
8056
  const cacheKey = cacheKeyParam ?? null;
8042
8057
  const conversationId = conversationIdParam ?? null;
8043
- const MISSING_SENTINEL = ".task702-identifier-not-supplied.log";
8044
- const fullFilename = conversationId ? `${prefix}-${conversationId}.log` : MISSING_SENTINEL;
8045
- const preflushFilename = cacheKey && typeParam === "public" ? `${prefix}-${preflushSliceOf(cacheKey)}.log` : MISSING_SENTINEL;
8046
- const { hits, stalePreflushPaths, tried } = resolveConversationLogPaths(
8047
- fullFilename,
8048
- preflushFilename,
8049
- logDirs
8050
- );
8051
- const stalePreflushCount = stalePreflushPaths.length;
8058
+ const sessionKeyFromConv = conversationId ? getSessionKeyByConversationId(conversationId) ?? null : null;
8059
+ const primaryId = cacheKey ?? sessionKeyFromConv ?? conversationId;
8060
+ const fallbackId = primaryId !== conversationId && conversationId ? conversationId : null;
8061
+ const tried = [];
8062
+ let hit = null;
8063
+ if (primaryId) {
8064
+ const filename = `${prefix}-${primaryId}.log`;
8065
+ tried.push(filename);
8066
+ const result = resolveSessionLogPaths(filename, logDirs);
8067
+ if (result.hits.length > 0) hit = result.hits[0];
8068
+ }
8069
+ if (!hit && fallbackId) {
8070
+ const filename = `${prefix}-${fallbackId}.log`;
8071
+ tried.push(filename);
8072
+ const result = resolveSessionLogPaths(filename, logDirs);
8073
+ if (result.hits.length > 0) hit = result.hits[0];
8074
+ }
8052
8075
  const cacheKeySlice = cacheKey ? cacheKey.slice(0, 12) : "none";
8053
8076
  const conversationIdSlice = conversationId ? conversationId.slice(0, 12) : "none";
8054
- if (hits.length > 0) {
8055
- const hit = hits[0];
8056
- console.info(`[admin/logs] resolved cacheKey=${cacheKeySlice} conversationId=${conversationIdSlice} shape=${hit.shape} stalePreflushCount=${stalePreflushCount}`);
8077
+ if (hit) {
8078
+ console.info(`[admin/logs] resolved cacheKey=${cacheKeySlice} conversationId=${conversationIdSlice} via=${primaryId === cacheKey ? "cacheKey" : primaryId === sessionKeyFromConv ? "reverse-lookup" : "conversationId-fallback"}`);
8057
8079
  try {
8058
8080
  const filename = basename2(hit.path);
8059
- if (stalePreflushCount > 0 && !download) {
8060
- const content = readFileSync11(hit.path, "utf-8");
8061
- return c.json({
8062
- log: content,
8063
- filename,
8064
- shape: hit.shape,
8065
- warnings: stalePreflushPaths.map((path2) => ({ kind: "stale-preflush", path: path2 }))
8066
- });
8067
- }
8068
8081
  const buffer = readFileSync11(hit.path);
8069
8082
  const onDiskBytes = statSync6(hit.path).size;
8070
8083
  const headers = {
@@ -8083,7 +8096,8 @@ app14.get("/", async (c) => {
8083
8096
  );
8084
8097
  }
8085
8098
  }
8086
- const reason = !conversationId ? "no preflush log on disk for cacheKey and conversationId not derivable" : !cacheKey ? "no full log on disk and cacheKey not derivable" : "no preflush log, no full log";
8099
+ const reason = "no log file on disk for the given identifier(s)";
8100
+ if (primaryId) emitMissingOnResolve(primaryId, "admin-logs-route", reason);
8087
8101
  console.warn(`[admin/logs] not-found tried=[${tried.join(",")}] cacheKey=${cacheKeySlice} conversationId=${conversationIdSlice} reason=${JSON.stringify(reason)}`);
8088
8102
  return c.json(
8089
8103
  {
@@ -8099,7 +8113,7 @@ app14.get("/", async (c) => {
8099
8113
  const seen = /* @__PURE__ */ new Set();
8100
8114
  const logs = {};
8101
8115
  for (const dir of logDirs) {
8102
- if (!existsSync12(dir)) continue;
8116
+ if (!existsSync13(dir)) continue;
8103
8117
  let files;
8104
8118
  try {
8105
8119
  files = readdirSync5(dir).filter((f) => f.endsWith(".log"));
@@ -8150,7 +8164,7 @@ var claude_info_default = app15;
8150
8164
 
8151
8165
  // server/routes/admin/attachment.ts
8152
8166
  import { readFile as readFile2, readdir } from "fs/promises";
8153
- import { existsSync as existsSync13 } from "fs";
8167
+ import { existsSync as existsSync14 } from "fs";
8154
8168
  import { resolve as resolve10 } from "path";
8155
8169
  var app16 = new Hono();
8156
8170
  app16.get("/:attachmentId", requireAdminSession, async (c) => {
@@ -8164,11 +8178,11 @@ app16.get("/:attachmentId", requireAdminSession, async (c) => {
8164
8178
  return new Response("Not found", { status: 404 });
8165
8179
  }
8166
8180
  const dir = resolve10(ATTACHMENTS_ROOT, accountId, attachmentId);
8167
- if (!existsSync13(dir)) {
8181
+ if (!existsSync14(dir)) {
8168
8182
  return new Response("Not found", { status: 404 });
8169
8183
  }
8170
8184
  const metaPath = resolve10(dir, `${attachmentId}.meta.json`);
8171
- if (!existsSync13(metaPath)) {
8185
+ if (!existsSync14(metaPath)) {
8172
8186
  return new Response("Not found", { status: 404 });
8173
8187
  }
8174
8188
  let meta;
@@ -8196,13 +8210,13 @@ var attachment_default = app16;
8196
8210
 
8197
8211
  // server/routes/admin/agents.ts
8198
8212
  import { resolve as resolve11 } from "path";
8199
- import { readdirSync as readdirSync6, readFileSync as readFileSync12, existsSync as existsSync14, rmSync } from "fs";
8213
+ import { readdirSync as readdirSync6, readFileSync as readFileSync12, existsSync as existsSync15, rmSync } from "fs";
8200
8214
  var app17 = new Hono();
8201
8215
  app17.get("/", (c) => {
8202
8216
  const account = resolveAccount();
8203
8217
  if (!account) return c.json({ agents: [] });
8204
8218
  const agentsDir = resolve11(account.accountDir, "agents");
8205
- if (!existsSync14(agentsDir)) return c.json({ agents: [] });
8219
+ if (!existsSync15(agentsDir)) return c.json({ agents: [] });
8206
8220
  const agents = [];
8207
8221
  try {
8208
8222
  const entries = readdirSync6(agentsDir, { withFileTypes: true });
@@ -8210,7 +8224,7 @@ app17.get("/", (c) => {
8210
8224
  if (!entry.isDirectory()) continue;
8211
8225
  if (entry.name === "admin") continue;
8212
8226
  const configPath2 = resolve11(agentsDir, entry.name, "config.json");
8213
- if (!existsSync14(configPath2)) continue;
8227
+ if (!existsSync15(configPath2)) continue;
8214
8228
  try {
8215
8229
  const config = JSON.parse(readFileSync12(configPath2, "utf-8"));
8216
8230
  agents.push({
@@ -8239,7 +8253,7 @@ app17.delete("/:slug", async (c) => {
8239
8253
  return c.json({ error: "Invalid agent slug" }, 400);
8240
8254
  }
8241
8255
  const agentDir = resolve11(account.accountDir, "agents", slug);
8242
- if (!existsSync14(agentDir)) {
8256
+ if (!existsSync15(agentDir)) {
8243
8257
  return c.json({ error: "Agent not found" }, 404);
8244
8258
  }
8245
8259
  try {
@@ -8269,7 +8283,7 @@ app17.post("/:slug/project", async (c) => {
8269
8283
  return c.json({ error: "Invalid agent slug" }, 400);
8270
8284
  }
8271
8285
  const agentDir = resolve11(account.accountDir, "agents", slug);
8272
- if (!existsSync14(agentDir)) {
8286
+ if (!existsSync15(agentDir)) {
8273
8287
  return c.json({ error: "Agent not found on disk" }, 404);
8274
8288
  }
8275
8289
  try {
@@ -8285,7 +8299,7 @@ var agents_default = app17;
8285
8299
  // server/routes/admin/sessions.ts
8286
8300
  import crypto2 from "crypto";
8287
8301
  import { resolve as resolvePath } from "path";
8288
- import { appendFileSync as appendFileSync4, existsSync as existsSync16 } from "fs";
8302
+ import { appendFileSync as appendFileSync4, existsSync as existsSync17 } from "fs";
8289
8303
 
8290
8304
  // app/lib/synthetic-marker.ts
8291
8305
  var CLOUDFLARE_MARKER_PREFIX = "Cloudflare setup completed (actionId: ";
@@ -8297,9 +8311,9 @@ function isSyntheticUserMarker(content) {
8297
8311
  }
8298
8312
 
8299
8313
  // app/lib/claude-agent/jsonl-replay.ts
8300
- import { existsSync as existsSync15, readFileSync as readFileSync13 } from "fs";
8314
+ import { existsSync as existsSync16, readFileSync as readFileSync13 } from "fs";
8301
8315
  function replayJsonl(jsonlPath) {
8302
- if (!existsSync15(jsonlPath)) {
8316
+ if (!existsSync16(jsonlPath)) {
8303
8317
  return { messages: [], jsonlMissing: true, malformedLines: 0 };
8304
8318
  }
8305
8319
  let raw;
@@ -8464,7 +8478,7 @@ function validateAndShapeAttachments(raws, conversationAccountId, conversationId
8464
8478
  let reason = null;
8465
8479
  if (!a.attachmentId || !a.filename || !a.mimeType || !a.storagePath) reason = "schema-fail";
8466
8480
  else if (a.accountId !== conversationAccountId) reason = "account-mismatch";
8467
- else if (!existsSync16(a.storagePath)) reason = "missing-file";
8481
+ else if (!existsSync17(a.storagePath)) reason = "missing-file";
8468
8482
  if (reason) {
8469
8483
  invalid++;
8470
8484
  try {
@@ -9255,12 +9269,12 @@ function isValidDomain(value) {
9255
9269
  }
9256
9270
 
9257
9271
  // app/lib/alias-domains.ts
9258
- import { existsSync as existsSync17, mkdirSync as mkdirSync6, readFileSync as readFileSync14, writeFileSync as writeFileSync7 } from "fs";
9272
+ import { existsSync as existsSync18, mkdirSync as mkdirSync6, readFileSync as readFileSync14, writeFileSync as writeFileSync7 } from "fs";
9259
9273
  import { dirname as dirname5 } from "path";
9260
9274
  import { resolve as resolve12 } from "path";
9261
9275
  var ALIAS_DOMAINS_PATH = resolve12(MAXY_DIR, "alias-domains.json");
9262
9276
  function readExisting() {
9263
- if (!existsSync17(ALIAS_DOMAINS_PATH)) return /* @__PURE__ */ new Set();
9277
+ if (!existsSync18(ALIAS_DOMAINS_PATH)) return /* @__PURE__ */ new Set();
9264
9278
  try {
9265
9279
  const parsed = JSON.parse(readFileSync14(ALIAS_DOMAINS_PATH, "utf-8"));
9266
9280
  if (!Array.isArray(parsed)) return /* @__PURE__ */ new Set();
@@ -9534,8 +9548,8 @@ app23.get("/tunnels", requireAdminSession, async (c) => {
9534
9548
  if (!correlationId) return err("session", "No active conversation for session \u2014 refresh chat.");
9535
9549
  streamLogPath = streamLogPathFor(accountId, correlationId).streamLogPath;
9536
9550
  const certPath = resolve13(homedir2(), brand.configDir, "cloudflared", "cert.pem");
9537
- const { existsSync: existsSync24 } = await import("fs");
9538
- if (!existsSync24(certPath)) {
9551
+ const { existsSync: existsSync25 } = await import("fs");
9552
+ if (!existsSync25(certPath)) {
9539
9553
  return err("cert", `Cloudflare origin certificate is not on disk yet (${certPath}). Complete the Cloudflare login first by submitting the form once \u2014 the OAuth flow writes cert.pem.`);
9540
9554
  }
9541
9555
  const result = await runFormSpawn({
@@ -9859,7 +9873,7 @@ var cloudflare_default = app23;
9859
9873
  import { createReadStream as createReadStream3 } from "fs";
9860
9874
  import { readdir as readdir2, readFile as readFile3, stat as stat3, mkdir as mkdir2, writeFile as writeFile3, unlink as unlink2 } from "fs/promises";
9861
9875
  import { realpathSync as realpathSync3 } from "fs";
9862
- import { basename as basename3, dirname as dirname6, join as join9, resolve as resolve15, sep as sep2 } from "path";
9876
+ import { basename as basename3, dirname as dirname6, join as join10, resolve as resolve15, sep as sep2 } from "path";
9863
9877
  import { Readable as Readable2 } from "stream";
9864
9878
 
9865
9879
  // app/lib/data-path.ts
@@ -10217,7 +10231,7 @@ async function cascadeDeleteDocument(params) {
10217
10231
  var UUID_RE5 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
10218
10232
  async function readMeta(absDir, baseName) {
10219
10233
  try {
10220
- const raw = await readFile3(join9(absDir, `${baseName}.meta.json`), "utf8");
10234
+ const raw = await readFile3(join10(absDir, `${baseName}.meta.json`), "utf8");
10221
10235
  const parsed = JSON.parse(raw);
10222
10236
  if (typeof parsed?.filename === "string") {
10223
10237
  return { filename: parsed.filename, mimeType: typeof parsed.mimeType === "string" ? parsed.mimeType : void 0 };
@@ -10255,7 +10269,7 @@ async function readAccountNames() {
10255
10269
  }
10256
10270
  async function enrich(absolute, entry, accountNames) {
10257
10271
  if (entry.kind === "directory" && UUID_RE5.test(entry.name)) {
10258
- const meta = await readMeta(join9(absolute, entry.name), entry.name);
10272
+ const meta = await readMeta(join10(absolute, entry.name), entry.name);
10259
10273
  if (meta?.filename) {
10260
10274
  entry.displayName = meta.filename;
10261
10275
  entry.mimeType = meta.mimeType;
@@ -10314,7 +10328,7 @@ app24.get("/", requireAdminSession, async (c) => {
10314
10328
  continue;
10315
10329
  }
10316
10330
  try {
10317
- const entryPath = join9(absolute, name);
10331
+ const entryPath = join10(absolute, name);
10318
10332
  const s = await stat3(entryPath);
10319
10333
  entries.push({
10320
10334
  name,
@@ -10487,7 +10501,7 @@ app24.delete("/", requireAdminSession, async (c) => {
10487
10501
  }
10488
10502
  const dot = base.lastIndexOf(".");
10489
10503
  const stem = dot === -1 ? base : base.slice(0, dot);
10490
- const sidecarPath = UUID_RE5.test(stem) && base !== `${stem}.meta.json` ? join9(dirname6(absolute), `${stem}.meta.json`) : null;
10504
+ const sidecarPath = UUID_RE5.test(stem) && base !== `${stem}.meta.json` ? join10(dirname6(absolute), `${stem}.meta.json`) : null;
10491
10505
  await unlink2(absolute);
10492
10506
  if (sidecarPath) {
10493
10507
  try {
@@ -12178,7 +12192,7 @@ var adherence_default = app32;
12178
12192
  import neo4j3 from "neo4j-driver";
12179
12193
  import { readFile as readFile4, readdir as readdir3, stat as stat4 } from "fs/promises";
12180
12194
  import { resolve as resolve16, relative as relative2, isAbsolute } from "path";
12181
- import { existsSync as existsSync18 } from "fs";
12195
+ import { existsSync as existsSync19 } from "fs";
12182
12196
  var LIMIT = 50;
12183
12197
  var TEXT_MIME_PREFIXES = ["text/", "application/json", "application/markdown"];
12184
12198
  var ADMIN_AGENT_FILES = ["IDENTITY.md", "SOUL.md", "KNOWLEDGE.md"];
@@ -12326,7 +12340,7 @@ async function fetchAgentTemplateRows(accountDir) {
12326
12340
  async function unionSpecialistFilenames(overrideDir, bundledDir) {
12327
12341
  const names = /* @__PURE__ */ new Set();
12328
12342
  for (const dir of [overrideDir, bundledDir]) {
12329
- if (!existsSync18(dir)) continue;
12343
+ if (!existsSync19(dir)) continue;
12330
12344
  try {
12331
12345
  const entries = await readdir3(dir);
12332
12346
  for (const entry of entries) {
@@ -12341,7 +12355,7 @@ async function unionSpecialistFilenames(overrideDir, bundledDir) {
12341
12355
  }
12342
12356
  async function readAgentTemplateRow(inp) {
12343
12357
  let chosenPath = null;
12344
- if (existsSync18(inp.overridePath)) {
12358
+ if (existsSync19(inp.overridePath)) {
12345
12359
  try {
12346
12360
  validateFilePathInAccount(inp.overridePath, inp.overrideRoot);
12347
12361
  chosenPath = inp.overridePath;
@@ -12352,7 +12366,7 @@ async function readAgentTemplateRow(inp) {
12352
12366
  );
12353
12367
  return null;
12354
12368
  }
12355
- } else if (existsSync18(inp.bundledPath)) {
12369
+ } else if (existsSync19(inp.bundledPath)) {
12356
12370
  if (!isWithin(inp.bundledPath, inp.bundledRoot)) {
12357
12371
  console.error(
12358
12372
  `[admin/sidebar-artefacts] agent-template-read-failed agent=${inp.displayName} kind=${inp.logName} error="bundled path outside PLATFORM_ROOT"`
@@ -12394,7 +12408,7 @@ var sidebar_artefacts_default = app33;
12394
12408
  // server/routes/admin/sidebar-artefact-save.ts
12395
12409
  import { mkdir as mkdir3, readdir as readdir4, stat as stat5, writeFile as writeFile4 } from "fs/promises";
12396
12410
  import { resolve as resolve17 } from "path";
12397
- import { existsSync as existsSync19 } from "fs";
12411
+ import { existsSync as existsSync20 } from "fs";
12398
12412
  var ADMIN_AGENT_FILES2 = /* @__PURE__ */ new Set(["IDENTITY.md", "SOUL.md", "KNOWLEDGE.md"]);
12399
12413
  var UUID_RE6 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
12400
12414
  var app34 = new Hono();
@@ -12462,7 +12476,7 @@ async function resolveSavePath(id, accountId, accountDir) {
12462
12476
  }
12463
12477
  if (UUID_RE6.test(id)) {
12464
12478
  const dir = resolve17(ATTACHMENTS_ROOT, accountId, id);
12465
- if (!existsSync19(dir)) {
12479
+ if (!existsSync20(dir)) {
12466
12480
  const attShort = id.slice(0, 8);
12467
12481
  if (isHealPending(accountId, id)) {
12468
12482
  console.error(`[admin/sidebar-artefact-save] heal-race attachmentId=${attShort} outcome=503-retry source=heal-pending`);
@@ -12514,7 +12528,7 @@ var sidebar_artefact_save_default = app34;
12514
12528
 
12515
12529
  // server/routes/admin/sidebar-artefact-content.ts
12516
12530
  import { readFile as readFile5, readdir as readdir5 } from "fs/promises";
12517
- import { existsSync as existsSync20 } from "fs";
12531
+ import { existsSync as existsSync21 } from "fs";
12518
12532
  import { resolve as resolve18 } from "path";
12519
12533
  var UUID_RE7 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
12520
12534
  var app35 = new Hono();
@@ -12528,7 +12542,7 @@ app35.get("/", requireAdminSession, async (c) => {
12528
12542
  return new Response("Not found", { status: 404 });
12529
12543
  }
12530
12544
  const dir = resolve18(ATTACHMENTS_ROOT, accountId, id);
12531
- if (!existsSync20(dir)) {
12545
+ if (!existsSync21(dir)) {
12532
12546
  console.error(`[admin/sidebar-artefact-content] not-found id=${id.slice(0, 8)}`);
12533
12547
  return new Response("Not found", { status: 404 });
12534
12548
  }
@@ -12562,12 +12576,12 @@ app35.get("/", requireAdminSession, async (c) => {
12562
12576
  var sidebar_artefact_content_default = app35;
12563
12577
 
12564
12578
  // server/routes/admin/health.ts
12565
- import { existsSync as existsSync21, readFileSync as readFileSync16 } from "fs";
12566
- import { resolve as resolve19, join as join10 } from "path";
12579
+ import { existsSync as existsSync22, readFileSync as readFileSync16 } from "fs";
12580
+ import { resolve as resolve19, join as join11 } from "path";
12567
12581
  var PLATFORM_ROOT6 = process.env.MAXY_PLATFORM_ROOT ?? resolve19(process.cwd(), "..");
12568
12582
  var brandHostname = "maxy";
12569
- var brandJsonPath = join10(PLATFORM_ROOT6, "config", "brand.json");
12570
- if (existsSync21(brandJsonPath)) {
12583
+ var brandJsonPath = join11(PLATFORM_ROOT6, "config", "brand.json");
12584
+ if (existsSync22(brandJsonPath)) {
12571
12585
  try {
12572
12586
  const brand = JSON.parse(readFileSync16(brandJsonPath, "utf-8"));
12573
12587
  if (brand.hostname) brandHostname = brand.hostname;
@@ -12578,7 +12592,7 @@ var VERSION_FILE = resolve19(PLATFORM_ROOT6, `config/.${brandHostname}-version`)
12578
12592
  var PROCESS_STARTED_AT = (/* @__PURE__ */ new Date()).toISOString();
12579
12593
  var PROBE_TIMEOUT_MS = 1e3;
12580
12594
  function readVersion() {
12581
- if (!existsSync21(VERSION_FILE)) return "unknown";
12595
+ if (!existsSync22(VERSION_FILE)) return "unknown";
12582
12596
  return readFileSync16(VERSION_FILE, "utf-8").trim() || "unknown";
12583
12597
  }
12584
12598
  async function probeConversationDb() {
@@ -12661,7 +12675,7 @@ app37.route("/health-brand", health_default2);
12661
12675
  var admin_default = app37;
12662
12676
 
12663
12677
  // server/routes/sites.ts
12664
- import { existsSync as existsSync22, readFileSync as readFileSync17, realpathSync as realpathSync4, statSync as statSync7 } from "fs";
12678
+ import { existsSync as existsSync23, readFileSync as readFileSync17, realpathSync as realpathSync4, statSync as statSync7 } from "fs";
12665
12679
  import { resolve as resolve20 } from "path";
12666
12680
  var SAFE_SEG_RE = /^[a-z0-9_][a-z0-9_.-]{0,99}$/i;
12667
12681
  var MIME = {
@@ -12727,7 +12741,7 @@ app38.get("/:rel{.*}", (c) => {
12727
12741
  }
12728
12742
  let stat6;
12729
12743
  try {
12730
- stat6 = existsSync22(filePath) ? statSync7(filePath) : null;
12744
+ stat6 = existsSync23(filePath) ? statSync7(filePath) : null;
12731
12745
  } catch {
12732
12746
  stat6 = null;
12733
12747
  }
@@ -12746,7 +12760,7 @@ app38.get("/:rel{.*}", (c) => {
12746
12760
  console.error(`[sites] path-traversal-rejected path=${reqPath} reason=escape status=403`);
12747
12761
  return c.text("Forbidden", 403);
12748
12762
  }
12749
- if (!existsSync22(filePath)) {
12763
+ if (!existsSync23(filePath)) {
12750
12764
  console.error(`[sites] not-found path=${reqPath} status=404`);
12751
12765
  return c.text("Not found", 404);
12752
12766
  }
@@ -12881,7 +12895,7 @@ function startGraphHealthTimer() {
12881
12895
  }
12882
12896
 
12883
12897
  // server/index.ts
12884
- import { existsSync as existsSyncBoot, readFileSync as readFileSyncBoot } from "fs";
12898
+ import { existsSync as existsSyncBoot } from "fs";
12885
12899
  import { resolve as resolveBoot } from "path";
12886
12900
  function requestIsTlsTerminated(c) {
12887
12901
  const remote = c.env?.incoming?.socket?.remoteAddress ?? "";
@@ -12897,12 +12911,12 @@ function clientFrom(c) {
12897
12911
  );
12898
12912
  }
12899
12913
  var PLATFORM_ROOT7 = process.env.MAXY_PLATFORM_ROOT || "";
12900
- var BRAND_JSON_PATH = PLATFORM_ROOT7 ? join11(PLATFORM_ROOT7, "config", "brand.json") : "";
12914
+ var BRAND_JSON_PATH = PLATFORM_ROOT7 ? join12(PLATFORM_ROOT7, "config", "brand.json") : "";
12901
12915
  var BRAND = { productName: "Maxy", hostname: "maxy", configDir: ".maxy", domain: "getmaxy.com" };
12902
- if (BRAND_JSON_PATH && !existsSync23(BRAND_JSON_PATH)) {
12916
+ if (BRAND_JSON_PATH && !existsSync24(BRAND_JSON_PATH)) {
12903
12917
  console.error(`[brand] WARNING: brand.json not found at ${BRAND_JSON_PATH} \u2014 using Maxy defaults`);
12904
12918
  }
12905
- if (BRAND_JSON_PATH && existsSync23(BRAND_JSON_PATH)) {
12919
+ if (BRAND_JSON_PATH && existsSync24(BRAND_JSON_PATH)) {
12906
12920
  try {
12907
12921
  const parsed = JSON.parse(readFileSync18(BRAND_JSON_PATH, "utf-8"));
12908
12922
  BRAND = { ...BRAND, ...parsed };
@@ -12923,10 +12937,10 @@ var brandLoginOpts = {
12923
12937
  bodyFont: BRAND.defaultFonts?.body,
12924
12938
  logoContainsName: !!BRAND.logoContainsName
12925
12939
  };
12926
- var ALIAS_DOMAINS_PATH2 = join11(homedir3(), BRAND.configDir, "alias-domains.json");
12940
+ var ALIAS_DOMAINS_PATH2 = join12(homedir3(), BRAND.configDir, "alias-domains.json");
12927
12941
  function loadAliasDomains() {
12928
12942
  try {
12929
- if (!existsSync23(ALIAS_DOMAINS_PATH2)) return null;
12943
+ if (!existsSync24(ALIAS_DOMAINS_PATH2)) return null;
12930
12944
  const parsed = JSON.parse(readFileSync18(ALIAS_DOMAINS_PATH2, "utf-8"));
12931
12945
  if (!Array.isArray(parsed)) {
12932
12946
  console.error("[alias-domains] malformed alias-domains.json \u2014 expected array");
@@ -13306,7 +13320,7 @@ app39.get("/agent-assets/:slug/:filename", (c) => {
13306
13320
  console.error(`[agent-assets] path-traversal-rejected slug=${slug} file=${filename}`);
13307
13321
  return c.text("Forbidden", 403);
13308
13322
  }
13309
- if (!existsSync23(filePath)) {
13323
+ if (!existsSync24(filePath)) {
13310
13324
  console.error(`[agent-assets] serve slug=${slug} file=${filename} status=404`);
13311
13325
  return c.text("Not found", 404);
13312
13326
  }
@@ -13336,7 +13350,7 @@ app39.get("/generated/:filename", (c) => {
13336
13350
  console.error(`[generated] serve file=${filename} status=403`);
13337
13351
  return c.text("Forbidden", 403);
13338
13352
  }
13339
- if (!existsSync23(filePath)) {
13353
+ if (!existsSync24(filePath)) {
13340
13354
  console.error(`[generated] serve file=${filename} status=404`);
13341
13355
  return c.text("Not found", 404);
13342
13356
  }
@@ -13353,7 +13367,7 @@ app39.route("/sites", sites_default);
13353
13367
  var htmlCache = /* @__PURE__ */ new Map();
13354
13368
  var brandLogoPath = "/brand/maxy-monochrome.png";
13355
13369
  var brandIconPath = "/brand/maxy-monochrome.png";
13356
- if (BRAND_JSON_PATH && existsSync23(BRAND_JSON_PATH)) {
13370
+ if (BRAND_JSON_PATH && existsSync24(BRAND_JSON_PATH)) {
13357
13371
  try {
13358
13372
  const fullBrand = JSON.parse(readFileSync18(BRAND_JSON_PATH, "utf-8"));
13359
13373
  if (fullBrand.assets?.logo) brandLogoPath = `/brand/${fullBrand.assets.logo}`;
@@ -13372,8 +13386,8 @@ var brandScript = `<script>window.__BRAND__=${JSON.stringify({
13372
13386
  function readInstalledVersion() {
13373
13387
  try {
13374
13388
  if (!PLATFORM_ROOT7) return "unknown";
13375
- const versionFile = join11(PLATFORM_ROOT7, "config", `.${BRAND.hostname}-version`);
13376
- if (!existsSync23(versionFile)) return "unknown";
13389
+ const versionFile = join12(PLATFORM_ROOT7, "config", `.${BRAND.hostname}-version`);
13390
+ if (!existsSync24(versionFile)) return "unknown";
13377
13391
  const content = readFileSync18(versionFile, "utf-8").trim();
13378
13392
  return content || "unknown";
13379
13393
  } catch {
@@ -13431,15 +13445,15 @@ ${clientErrorReporterScript}
13431
13445
  }
13432
13446
  var brandedHtmlCache = /* @__PURE__ */ new Map();
13433
13447
  function loadBrandingCache(agentSlug) {
13434
- const configDir2 = join11(homedir3(), BRAND.configDir);
13448
+ const configDir2 = join12(homedir3(), BRAND.configDir);
13435
13449
  try {
13436
- const accountJsonPath = join11(configDir2, "account.json");
13437
- if (!existsSync23(accountJsonPath)) return null;
13450
+ const accountJsonPath = join12(configDir2, "account.json");
13451
+ if (!existsSync24(accountJsonPath)) return null;
13438
13452
  const account = JSON.parse(readFileSync18(accountJsonPath, "utf-8"));
13439
13453
  const accountId = account.accountId;
13440
13454
  if (!accountId) return null;
13441
- const cachePath = join11(configDir2, "branding-cache", accountId, `${agentSlug}.json`);
13442
- if (!existsSync23(cachePath)) return null;
13455
+ const cachePath = join12(configDir2, "branding-cache", accountId, `${agentSlug}.json`);
13456
+ if (!existsSync24(cachePath)) return null;
13443
13457
  return JSON.parse(readFileSync18(cachePath, "utf-8"));
13444
13458
  } catch {
13445
13459
  return null;
@@ -13447,9 +13461,9 @@ function loadBrandingCache(agentSlug) {
13447
13461
  }
13448
13462
  function resolveDefaultSlug() {
13449
13463
  try {
13450
- const configDir2 = join11(homedir3(), BRAND.configDir);
13451
- const accountJsonPath = join11(configDir2, "account.json");
13452
- if (!existsSync23(accountJsonPath)) return null;
13464
+ const configDir2 = join12(homedir3(), BRAND.configDir);
13465
+ const accountJsonPath = join12(configDir2, "account.json");
13466
+ if (!existsSync24(accountJsonPath)) return null;
13453
13467
  const account = JSON.parse(readFileSync18(accountJsonPath, "utf-8"));
13454
13468
  return account.defaultAgent || null;
13455
13469
  } catch {
@@ -13629,7 +13643,7 @@ try {
13629
13643
  (async () => {
13630
13644
  try {
13631
13645
  let userId = "";
13632
- if (existsSync23(USERS_FILE)) {
13646
+ if (existsSync24(USERS_FILE)) {
13633
13647
  const users = JSON.parse(readFileSync18(USERS_FILE, "utf-8").trim() || "[]");
13634
13648
  userId = users[0]?.userId ?? "";
13635
13649
  }
@@ -13647,7 +13661,7 @@ try {
13647
13661
  })();
13648
13662
  (async () => {
13649
13663
  try {
13650
- if (!existsSync23(USERS_FILE)) return;
13664
+ if (!existsSync24(USERS_FILE)) return;
13651
13665
  const usersRaw = readFileSync18(USERS_FILE, "utf-8").trim();
13652
13666
  if (!usersRaw) return;
13653
13667
  const users = JSON.parse(usersRaw);
@@ -13700,6 +13714,11 @@ autoDeliverPremiumPlugins(
13700
13714
  bootAccount?.accountDir,
13701
13715
  bootAccount?.config
13702
13716
  );
13717
+ reconcileEnabledPlugins(
13718
+ bootAccount?.accountDir,
13719
+ bootAccount?.config,
13720
+ bootEntitlement?.purchasedPlugins ?? void 0
13721
+ );
13703
13722
  (async () => {
13704
13723
  if (!bootAccount) return;
13705
13724
  try {
@@ -13749,25 +13768,8 @@ if (bootEntitlement?.purchasedPlugins?.length) {
13749
13768
  const enabledSet = new Set(bootEnabled);
13750
13769
  for (const purchased of bootEntitlement.purchasedPlugins) {
13751
13770
  const bundlePath = resolveBoot(PLATFORM_ROOT, "..", "premium-plugins", purchased, "BUNDLE.md");
13752
- if (!existsSyncBoot(bundlePath)) continue;
13753
- try {
13754
- const raw = readFileSyncBoot(bundlePath, "utf-8");
13755
- const fm = raw.match(/^---\n([\s\S]*?)\n---/);
13756
- if (!fm) continue;
13757
- let inPlugins = false;
13758
- for (const line of fm[1].split("\n")) {
13759
- if (/^plugins:/.test(line)) {
13760
- inPlugins = true;
13761
- continue;
13762
- }
13763
- if (inPlugins) {
13764
- const m = line.match(/^\s+- (.+)/);
13765
- if (!m) break;
13766
- const sub = m[1].trim();
13767
- if (!enabledSet.has(sub)) bootEnabledNotDelivered.push(sub);
13768
- }
13769
- }
13770
- } catch {
13771
+ for (const sub of readBundleSubPlugins(bundlePath)) {
13772
+ if (!enabledSet.has(sub)) bootEnabledNotDelivered.push(sub);
13771
13773
  }
13772
13774
  }
13773
13775
  }
@@ -13780,7 +13782,7 @@ if (bootAccountConfig?.whatsapp) {
13780
13782
  }
13781
13783
  init({
13782
13784
  configDir: configDirForWhatsApp,
13783
- platformRoot: resolve21(process.env.MAXY_PLATFORM_ROOT ?? join11(__dirname, "..")),
13785
+ platformRoot: resolve21(process.env.MAXY_PLATFORM_ROOT ?? join12(__dirname, "..")),
13784
13786
  accountConfig: bootAccountConfig,
13785
13787
  onMessage: async (msg) => {
13786
13788
  try {