@rubytech/create-realagent-code 0.1.249 → 0.1.251

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. package/dist/index.js +8 -16
  2. package/package.json +1 -1
  3. package/payload/platform/plugins/admin/PLUGIN.md +1 -1
  4. package/payload/platform/plugins/admin/hooks/__tests__/session-end-retrospective.test.sh +3 -3
  5. package/payload/platform/plugins/admin/skills/platform-architecture/SKILL.md +16 -10
  6. package/payload/platform/plugins/docs/PLUGIN.md +2 -2
  7. package/payload/platform/plugins/docs/references/admin-session.md +7 -67
  8. package/payload/platform/plugins/docs/references/admin-ui.md +3 -3
  9. package/payload/platform/plugins/docs/references/deployment.md +1 -1
  10. package/payload/platform/plugins/docs/references/internals.md +8 -2
  11. package/payload/platform/plugins/docs/references/platform.md +3 -3
  12. package/payload/platform/scripts/check-no-legacy-spawn-route.mjs +37 -0
  13. package/payload/platform/services/claude-session-manager/dist/http-server.d.ts.map +1 -1
  14. package/payload/platform/services/claude-session-manager/dist/http-server.js +57 -21
  15. package/payload/platform/services/claude-session-manager/dist/http-server.js.map +1 -1
  16. package/payload/platform/services/claude-session-manager/dist/index.js +1 -0
  17. package/payload/platform/services/claude-session-manager/dist/index.js.map +1 -1
  18. package/payload/platform/services/claude-session-manager/dist/rc-daemon.d.ts +8 -0
  19. package/payload/platform/services/claude-session-manager/dist/rc-daemon.d.ts.map +1 -1
  20. package/payload/platform/services/claude-session-manager/dist/rc-daemon.js +14 -4
  21. package/payload/platform/services/claude-session-manager/dist/rc-daemon.js.map +1 -1
  22. package/payload/server/server.js +120 -121
  23. package/payload/platform/plugins/admin/hooks/__tests__/turn-completed-graph-write.test.sh +0 -601
  24. package/payload/platform/plugins/admin/hooks/turn-completed-graph-write.sh +0 -441
@@ -4202,7 +4202,7 @@ async function managerSpawn(opts) {
4202
4202
  );
4203
4203
  return { error: "claude-auth-dead", status: 503 };
4204
4204
  }
4205
- const res = await fetch(`${managerBase()}/spawn`, {
4205
+ const res = await fetch(`${managerBase()}/public-spawn`, {
4206
4206
  method: "POST",
4207
4207
  headers: { "content-type": "application/json" },
4208
4208
  body: JSON.stringify({
@@ -4228,6 +4228,32 @@ async function managerSpawn(opts) {
4228
4228
  if (!r.ok) return { error: `manager-status-${r.status}`, status: r.status };
4229
4229
  return await r.json();
4230
4230
  }
4231
+ async function managerRcSpawn(opts) {
4232
+ const auth = await ensureAuth();
4233
+ if (auth.status === "dead" || auth.status === "missing") {
4234
+ console.log(`[channel-pty-bridge] rc-spawn-refused reason=auth-${auth.status} ${opts.logContext}`);
4235
+ return { error: "claude-auth-dead", status: 503 };
4236
+ }
4237
+ const res = await fetch(`${managerBase()}/rc-spawn`, {
4238
+ method: "POST",
4239
+ headers: { "content-type": "application/json" },
4240
+ body: JSON.stringify({
4241
+ sessionId: opts.sessionId,
4242
+ name: opts.name,
4243
+ initialMessage: opts.initialMessage,
4244
+ closeAfterTurn: opts.closeAfterTurn,
4245
+ sliceToken: opts.sliceToken,
4246
+ personId: opts.personId
4247
+ })
4248
+ }).catch((err) => ({ __throw: err instanceof Error ? err.message : String(err) }));
4249
+ if ("__throw" in res) {
4250
+ return { error: res.__throw, status: 0 };
4251
+ }
4252
+ const r = res;
4253
+ if (!r.ok) return { error: `manager-status-${r.status}`, status: r.status };
4254
+ const out = await r.json();
4255
+ return { sessionId: out.sessionId ?? opts.sessionId, pid: out.spawnedPid ?? null };
4256
+ }
4231
4257
  async function managerWriteInput(sessionId, text) {
4232
4258
  const res = await fetch(`${managerBase()}/${sessionId}/input`, {
4233
4259
  method: "POST",
@@ -4249,7 +4275,19 @@ function managerLogFollowUrl(sessionId) {
4249
4275
  return `${managerBase()}/${sessionId}/log?follow=1`;
4250
4276
  }
4251
4277
 
4278
+ // app/lib/channel-pty-bridge/admin-session-id.ts
4279
+ import { createHash } from "crypto";
4280
+ function adminSessionIdFor(accountId, senderId) {
4281
+ const b = createHash("sha256").update(`${accountId}:admin:${senderId}`).digest().subarray(0, 16);
4282
+ const v = Buffer.from(b);
4283
+ v[6] = v[6] & 15 | 64;
4284
+ v[8] = v[8] & 63 | 128;
4285
+ const h = v.toString("hex");
4286
+ return `${h.slice(0, 8)}-${h.slice(8, 12)}-${h.slice(12, 16)}-${h.slice(16, 20)}-${h.slice(20, 32)}`;
4287
+ }
4288
+
4252
4289
  // app/lib/channel-pty-bridge/public-session-end-review.ts
4290
+ import { randomUUID as randomUUID4 } from "crypto";
4253
4291
  var TAG14 = "[public-session-review]";
4254
4292
  var CONSUMED_CAP = 500;
4255
4293
  var consumed = /* @__PURE__ */ new Set();
@@ -4337,30 +4375,20 @@ function composeInitialMessage(input) {
4337
4375
  ].join("\n");
4338
4376
  }
4339
4377
  async function dispatchReviewer(input, initialMessage) {
4340
- try {
4341
- const res = await fetch(`${managerBase2()}/spawn`, {
4342
- method: "POST",
4343
- headers: { "content-type": "application/json" },
4344
- body: JSON.stringify({
4345
- senderId: `public-session-reviewer-${input.sessionId}`,
4346
- role: "admin",
4347
- channel: "webchat",
4348
- accountId: input.accountId,
4349
- specialist: "public-session-reviewer",
4350
- hidden: true,
4351
- initialMessage,
4352
- sliceToken: input.sliceToken,
4353
- personId: input.personId ?? void 0
4354
- })
4355
- });
4356
- if (!res.ok) {
4357
- return { ok: false, reason: `spawn-status-${res.status}` };
4358
- }
4359
- const body = await res.json();
4360
- return { ok: true, managerSessionId: body.sessionId ?? "unknown" };
4361
- } catch (err) {
4362
- return { ok: false, reason: `spawn-threw-${err instanceof Error ? err.message : String(err)}` };
4378
+ const sessionId = randomUUID4();
4379
+ console.log(`${TAG14} route target=rc-spawn sessionId=${sessionId.slice(0, 8)} sourceSession=${input.sessionId.slice(0, 8)}`);
4380
+ const spawned = await managerRcSpawn({
4381
+ sessionId,
4382
+ initialMessage,
4383
+ closeAfterTurn: true,
4384
+ sliceToken: input.sliceToken,
4385
+ personId: input.personId ?? void 0,
4386
+ logContext: `public-session-end sourceSession=${input.sessionId.slice(0, 8)}`
4387
+ });
4388
+ if ("error" in spawned) {
4389
+ return { ok: false, reason: `rc-spawn-${spawned.status}-${spawned.error}` };
4363
4390
  }
4391
+ return { ok: true, managerSessionId: spawned.sessionId };
4364
4392
  }
4365
4393
  async function firePublicSessionEndReview(input) {
4366
4394
  const sliceShort = input.sliceToken.slice(0, 8);
@@ -4529,7 +4557,7 @@ function tagFor(channel) {
4529
4557
  return `[${channel}-adaptor]`;
4530
4558
  }
4531
4559
  function publicIdleMs() {
4532
- return Number(process.env.CHANNEL_PTY_IDLE_MS ?? String(30 * 6e4));
4560
+ return Number(process.env.CHANNEL_PTY_IDLE_MS ?? String(5 * 6e4));
4533
4561
  }
4534
4562
  var index = /* @__PURE__ */ new Map();
4535
4563
  function indexKey(accountId, agentSlug, senderId, sliceToken = "") {
@@ -4557,18 +4585,30 @@ async function ensureEntry(input) {
4557
4585
  }
4558
4586
  return existing;
4559
4587
  }
4560
- const attachmentDir = input.role === "public" ? resolve4(ATTACHMENTS_ROOT, "public", input.senderId) : void 0;
4561
- const spawned = await managerSpawn({
4562
- senderId: input.senderId,
4563
- role: input.role,
4564
- channel: input.channel,
4565
- accountId: input.accountId,
4566
- agentSlug: input.agentSlug,
4567
- attachmentDir,
4568
- sliceToken: sliceTokenValue.length > 0 ? sliceTokenValue : void 0,
4569
- personId: personIdValue ?? void 0,
4570
- name: nameValue ?? void 0
4571
- });
4588
+ let spawned;
4589
+ if (input.role === "admin") {
4590
+ const adminSessionId = adminSessionIdFor(input.accountId, input.senderId);
4591
+ console.error(`${tag} route role=admin target=rc-spawn senderId=${input.senderId}`);
4592
+ spawned = await managerRcSpawn({
4593
+ sessionId: adminSessionId,
4594
+ name: nameValue ?? void 0,
4595
+ logContext: `channel=${input.channel} senderId=${input.senderId}`
4596
+ });
4597
+ } else {
4598
+ console.error(`${tag} route role=${input.role} target=public-spawn senderId=${input.senderId}`);
4599
+ const attachmentDir = resolve4(ATTACHMENTS_ROOT, "public", input.senderId);
4600
+ spawned = await managerSpawn({
4601
+ senderId: input.senderId,
4602
+ role: input.role,
4603
+ channel: input.channel,
4604
+ accountId: input.accountId,
4605
+ agentSlug: input.agentSlug,
4606
+ attachmentDir,
4607
+ sliceToken: sliceTokenValue.length > 0 ? sliceTokenValue : void 0,
4608
+ personId: personIdValue ?? void 0,
4609
+ name: nameValue ?? void 0
4610
+ });
4611
+ }
4572
4612
  if ("error" in spawned) {
4573
4613
  if (spawned.error !== "claude-auth-dead") {
4574
4614
  console.error(
@@ -4781,10 +4821,10 @@ function handlePublicSessionExit(sessionId) {
4781
4821
  }
4782
4822
 
4783
4823
  // app/lib/access-session-store.ts
4784
- import { randomUUID as randomUUID4 } from "crypto";
4824
+ import { randomUUID as randomUUID5 } from "crypto";
4785
4825
  var sessions = /* @__PURE__ */ new Map();
4786
4826
  function createAccessSession(input) {
4787
- const sessionId = randomUUID4();
4827
+ const sessionId = randomUUID5();
4788
4828
  const session = {
4789
4829
  ...input,
4790
4830
  sessionId,
@@ -5051,7 +5091,7 @@ import { readFile, stat as stat2 } from "fs/promises";
5051
5091
  import { realpathSync as realpathSync2, readdirSync as readdirSync2, readFileSync as readFileSync6, existsSync as existsSync4 } from "fs";
5052
5092
 
5053
5093
  // app/lib/whatsapp/login.ts
5054
- import { randomUUID as randomUUID5 } from "crypto";
5094
+ import { randomUUID as randomUUID6 } from "crypto";
5055
5095
  var TAG15 = "[whatsapp:login]";
5056
5096
  var ACTIVE_LOGIN_TTL_MS = 3 * 6e4;
5057
5097
  var activeLogins = /* @__PURE__ */ new Map();
@@ -5190,7 +5230,7 @@ async function startLogin(opts) {
5190
5230
  const login = {
5191
5231
  accountId,
5192
5232
  authDir,
5193
- id: randomUUID5(),
5233
+ id: randomUUID6(),
5194
5234
  sock,
5195
5235
  startedAt: Date.now(),
5196
5236
  connected: false
@@ -6192,7 +6232,7 @@ var whatsapp_default = app3;
6192
6232
  // server/routes/onboarding.ts
6193
6233
  import { spawn, spawnSync as spawnSync2, execFileSync as execFileSync2 } from "child_process";
6194
6234
  import { openSync, closeSync, writeFileSync as writeFileSync5, writeSync, existsSync as existsSync6, readFileSync as readFileSync8, unlinkSync } from "fs";
6195
- import { createHash, randomUUID as randomUUID6 } from "crypto";
6235
+ import { createHash as createHash2, randomUUID as randomUUID7 } from "crypto";
6196
6236
 
6197
6237
  // ../lib/admins-write/src/index.ts
6198
6238
  import { existsSync as existsSync5, readFileSync as readFileSync7, writeFileSync as writeFileSync4, renameSync, mkdirSync as mkdirSync2, readdirSync as readdirSync3, statSync as statSync2 } from "fs";
@@ -6340,7 +6380,7 @@ function checkAdminAuthInvariant(input) {
6340
6380
 
6341
6381
  // server/routes/onboarding.ts
6342
6382
  function hashPin(pin) {
6343
- return createHash("sha256").update(pin).digest("hex");
6383
+ return createHash2("sha256").update(pin).digest("hex");
6344
6384
  }
6345
6385
  function readUsersFile() {
6346
6386
  if (!existsSync6(USERS_FILE)) return null;
@@ -6468,7 +6508,7 @@ app4.post("/set-pin", async (c) => {
6468
6508
  const hash = hashPin(body.pin);
6469
6509
  const account = resolveAccount();
6470
6510
  const existingOwnerUserId = account?.config.admins?.find((a) => a.role === "owner")?.userId;
6471
- const userId = existingOwnerUserId ?? randomUUID6();
6511
+ const userId = existingOwnerUserId ?? randomUUID7();
6472
6512
  if (existingOwnerUserId) {
6473
6513
  console.log(`[set-pin] reusing existing owner userId=${userId.slice(0, 8)}\u2026 (change-PIN preserves identity)`);
6474
6514
  } else {
@@ -6739,14 +6779,14 @@ app5.post("/", async (c) => {
6739
6779
  var client_error_default = app5;
6740
6780
 
6741
6781
  // server/routes/admin/session.ts
6742
- import { randomUUID as randomUUID7 } from "crypto";
6782
+ import { randomUUID as randomUUID8 } from "crypto";
6743
6783
 
6744
6784
  // app/lib/admin-identity/pin-validator.ts
6745
- import { createHash as createHash2 } from "crypto";
6785
+ import { createHash as createHash3 } from "crypto";
6746
6786
  import { existsSync as existsSync8, readFileSync as readFileSync9, readdirSync as readdirSync4, statSync as statSync4 } from "fs";
6747
6787
  import { join as join8 } from "path";
6748
6788
  function hashPin2(pin) {
6749
- return createHash2("sha256").update(pin).digest("hex");
6789
+ return createHash3("sha256").update(pin).digest("hex");
6750
6790
  }
6751
6791
  function readUsersFile2(usersFilePath) {
6752
6792
  if (!existsSync8(usersFilePath)) return null;
@@ -6813,7 +6853,7 @@ async function resolveUserIdentity(accountId, userId) {
6813
6853
  async function createAdminSession(accountId, thinkingView, userId, userName, role, avatar) {
6814
6854
  const account = resolveAccount();
6815
6855
  const effectiveThinkingView = thinkingView ?? account?.config.thinkingView ?? "default";
6816
- const signedSessionToken = randomUUID7();
6856
+ const signedSessionToken = randomUUID8();
6817
6857
  const cacheKey = fingerprintSessionKey(signedSessionToken);
6818
6858
  registerSession(cacheKey, "admin", accountId, void 0, userId, userName, role);
6819
6859
  if (userId) setWantsPriorConversation(cacheKey);
@@ -8306,7 +8346,6 @@ function managerBase3() {
8306
8346
  return `http://127.0.0.1:${port2}`;
8307
8347
  }
8308
8348
  var app12 = new Hono();
8309
- var UUID_PATTERN = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
8310
8349
  async function performSpawnWithInitialMessage(args) {
8311
8350
  const ownerStart = Date.now();
8312
8351
  const aboutOwner = await resolveOwnerProfileBlock(args.senderId, args.userId);
@@ -8346,7 +8385,7 @@ async function performSpawnWithInitialMessage(args) {
8346
8385
  });
8347
8386
  console.log(`${TAG18} forward-spawn-start managerBase=${managerBase3()} bytes=${upstreamPayload.length} hidden=${args.hidden} specialist=${args.specialist ?? "none"}`);
8348
8387
  const forwardStart = Date.now();
8349
- const upstream = await fetch(`${managerBase3()}/spawn`, {
8388
+ const upstream = await fetch(`${managerBase3()}/public-spawn`, {
8350
8389
  method: "POST",
8351
8390
  headers: { "content-type": "application/json" },
8352
8391
  body: upstreamPayload
@@ -8383,16 +8422,7 @@ function mintTranscriptEdge(sessionId, claudeSessionId, accountId) {
8383
8422
  if (!sessionId || !claudeSessionId) return;
8384
8423
  void linkConversationTranscript(sessionId, claudeSessionId, accountId);
8385
8424
  }
8386
- var requireAdminSessionUnlessLoopbackSpawn = async (c, next) => {
8387
- const remoteAddr = c.env?.incoming?.socket?.remoteAddress ?? "";
8388
- const isLoopback = remoteAddr === "127.0.0.1" || remoteAddr === "::1" || remoteAddr === "::ffff:127.0.0.1";
8389
- const hasForwardedFor = !!c.req.header("x-forwarded-for");
8390
- if (isLoopback && !hasForwardedFor && c.req.method === "POST" && c.req.path === "/api/admin/claude-sessions") {
8391
- return next();
8392
- }
8393
- return requireAdminSession(c, next);
8394
- };
8395
- app12.use("*", requireAdminSessionUnlessLoopbackSpawn);
8425
+ app12.use("*", requireAdminSession);
8396
8426
  app12.post("/", async (c) => {
8397
8427
  const routeStart = Date.now();
8398
8428
  const cacheKey = c.get("cacheKey") ?? "";
@@ -8403,46 +8433,18 @@ app12.post("/", async (c) => {
8403
8433
  }
8404
8434
  const refusal = await refuseIfClaudeAuthDead(c, "spawn", null);
8405
8435
  if (refusal) return refusal;
8406
- let senderId;
8407
- let userId;
8408
- let authSurface;
8409
- if (cacheKey) {
8410
- authSurface = "cookie";
8411
- senderId = getAccountIdForSession(cacheKey) ?? "";
8412
- if (!senderId) {
8413
- console.error(`${TAG18} reject reason=no-account-id cacheKey-prefix=${cacheKey.slice(0, 8)}`);
8414
- return c.json({ error: "admin-account-not-resolved" }, 500);
8415
- }
8416
- userId = getUserIdForSession(cacheKey) ?? void 0;
8417
- } else {
8418
- authSurface = "loopback";
8419
- if (typeof body.adminSessionId !== "string" || !UUID_PATTERN.test(body.adminSessionId)) {
8420
- return c.json({ error: "admin-session-id-required" }, 400);
8421
- }
8422
- const lookupSessionId = body.adminSessionId;
8423
- const operatorMeta = await fetch(
8424
- `${managerBase3()}/${encodeURIComponent(lookupSessionId)}/meta`
8425
- ).then((r) => r.ok ? r.json() : null).catch((err) => {
8426
- console.error(`${TAG18} fetch-failed op=operator-meta-lookup message=${err instanceof Error ? err.message : String(err)}`);
8427
- return null;
8428
- });
8429
- const metaSenderId = operatorMeta && typeof operatorMeta.senderId === "string" && operatorMeta.senderId.length > 0 ? operatorMeta.senderId : null;
8430
- const bodyAccountId = typeof body.accountId === "string" && UUID_PATTERN.test(body.accountId) ? body.accountId : null;
8431
- const operatorSenderId = metaSenderId ?? bodyAccountId;
8432
- if (!operatorSenderId) {
8433
- console.error(`${TAG18} reject reason=no-sender-id adminSessionId=${lookupSessionId.slice(0, 8)} metaSenderId=${metaSenderId ? "present" : "absent"} bodyAccountId=${bodyAccountId ? "present" : "absent"}`);
8434
- return c.json({ error: "admin-session-not-found" }, 404);
8435
- }
8436
- console.log(`${TAG18} loopback-sender-resolved source=${metaSenderId ? "meta" : "body-accountId"} accountId=${operatorSenderId.slice(0, 8)}`);
8437
- senderId = operatorSenderId;
8438
- userId = void 0;
8436
+ const senderId = getAccountIdForSession(cacheKey) ?? "";
8437
+ if (!senderId) {
8438
+ console.error(`${TAG18} reject reason=no-account-id cacheKey-prefix=${cacheKey.slice(0, 8)}`);
8439
+ return c.json({ error: "admin-account-not-resolved" }, 500);
8439
8440
  }
8441
+ const userId = getUserIdForSession(cacheKey) ?? void 0;
8440
8442
  const channel = typeof body.channel === "string" ? body.channel : "browser";
8441
8443
  const initialMessage = typeof body.initialMessage === "string" && body.initialMessage.trim() ? body.initialMessage : null;
8442
8444
  const permissionMode = typeof body.permissionMode === "string" ? body.permissionMode : void 0;
8443
8445
  const specialist = typeof body.specialist === "string" && /^[A-Za-z0-9_-]{1,64}$/.test(body.specialist) ? body.specialist : void 0;
8444
8446
  const model = typeof body.model === "string" && /^[A-Za-z0-9._-]{1,64}$/.test(body.model) ? body.model : void 0;
8445
- console.log(`${TAG18} spawn-request-in surface=${authSurface} accountId=${senderId.slice(0, 8)} userId=${userId ? userId.slice(0, 8) : "absent"} channel=${channel} permissionMode=${permissionMode ?? "default"} specialist=${specialist ?? "none"} model=${model ?? "default"} initialMessage=${initialMessage ? "yes" : "no"}`);
8447
+ console.log(`${TAG18} spawn-request-in surface=cookie accountId=${senderId.slice(0, 8)} userId=${userId ? userId.slice(0, 8) : "absent"} channel=${channel} permissionMode=${permissionMode ?? "default"} specialist=${specialist ?? "none"} model=${model ?? "default"} initialMessage=${initialMessage ? "yes" : "no"}`);
8446
8448
  const conversationNodeId = cacheKey ? getSessionIdForSession(cacheKey) : void 0;
8447
8449
  const { response, claudeSessionId } = await performSpawnWithInitialMessage({
8448
8450
  senderId,
@@ -8461,7 +8463,7 @@ app12.post("/", async (c) => {
8461
8463
  claudeSessionId,
8462
8464
  senderId
8463
8465
  );
8464
- console.log(`${TAG18} route-done surface=${authSurface} status=${response.status} route-ms=${Date.now() - routeStart}`);
8466
+ console.log(`${TAG18} route-done surface=cookie status=${response.status} route-ms=${Date.now() - routeStart}`);
8465
8467
  return response;
8466
8468
  });
8467
8469
  var claude_sessions_default = app12;
@@ -9793,7 +9795,7 @@ function applyBacklinkBoost(hits) {
9793
9795
  }
9794
9796
 
9795
9797
  // ../lib/graph-search/src/dedup.ts
9796
- import { createHash as createHash3 } from "crypto";
9798
+ import { createHash as createHash4 } from "crypto";
9797
9799
  var DEFAULT_LAYERS = [
9798
9800
  "nodeId",
9799
9801
  "slug",
@@ -9820,7 +9822,7 @@ function readContentHash(props) {
9820
9822
  const content = props["content"];
9821
9823
  const source = typeof compiled === "string" && compiled.length > 0 ? compiled : typeof content === "string" && content.length > 0 ? content : null;
9822
9824
  if (source === null) return null;
9823
- return createHash3("sha256").update(source).digest("hex").slice(0, 16);
9825
+ return createHash4("sha256").update(source).digest("hex").slice(0, 16);
9824
9826
  }
9825
9827
  function dedup(hits, layers = DEFAULT_LAYERS) {
9826
9828
  const sorted = [...hits].sort((a, b) => b.score - a.score);
@@ -12565,6 +12567,7 @@ app27.get("/", async (c) => {
12565
12567
  var health_default2 = app27;
12566
12568
 
12567
12569
  // server/routes/admin/linkedin-ingest.ts
12570
+ import { randomUUID as randomUUID9 } from "crypto";
12568
12571
  var TAG20 = "[linkedin-ingest-route]";
12569
12572
  var UUID = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
12570
12573
  var ISO = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?(?:Z|[+-]\d{2}:\d{2})$/;
@@ -12607,11 +12610,14 @@ function buildInitialMessage(env) {
12607
12610
  "sourceUrl=" + env.pageUrl,
12608
12611
  "capturedAt=" + env.capturedAt
12609
12612
  ].join(" \xB7 ");
12613
+ const delegation = "Dispatch `database-operator` via the Task tool to carry out the ingestion described below \u2014 it owns every graph write. Do not call memory-write, memory-update, or any graph tool directly.";
12610
12614
  if (env.kind === "profile" && env.profile) {
12611
12615
  const p = env.profile;
12612
12616
  return [
12613
12617
  header,
12614
12618
  "",
12619
+ delegation,
12620
+ "",
12615
12621
  "Surface: LinkedIn profile. Run the document-ingest skill in document mode against the body below, anchored to a Person subject for this profile.",
12616
12622
  "",
12617
12623
  "Conservative-extraction rules apply (see Task 234 spec):",
@@ -12640,6 +12646,8 @@ function buildInitialMessage(env) {
12640
12646
  return [
12641
12647
  header,
12642
12648
  "",
12649
+ delegation,
12650
+ "",
12643
12651
  "Surface: LinkedIn DM thread. Run the document-ingest skill in document mode against the transcript below.",
12644
12652
  "",
12645
12653
  "Conservative-extraction rules apply (see Task 234 spec):",
@@ -12679,39 +12687,30 @@ app28.post("/", requireAdminSession, async (c) => {
12679
12687
  console.error(TAG20 + " rejected status=500 reason=admin-account-not-resolved");
12680
12688
  return c.json({ ok: false, error: "admin-account-not-resolved" }, 500);
12681
12689
  }
12682
- const userId = getUserIdForSession(cacheKey) ?? void 0;
12683
12690
  const payloadBytes = JSON.stringify(envelope).length;
12684
12691
  console.log(
12685
12692
  TAG20 + " received kind=" + envelope.kind + " account=" + senderId.slice(0, 8) + " pageUrl=" + envelope.pageUrl + " dispatchId=" + envelope.dispatchId + " payloadBytes=" + payloadBytes
12686
12693
  );
12687
12694
  const initialMessage = buildInitialMessage(envelope);
12688
12695
  const spawnStart = Date.now();
12689
- const { response, claudeSessionId } = await performSpawnWithInitialMessage({
12690
- senderId,
12691
- userId,
12692
- role: "admin",
12693
- channel: "linkedin-extension",
12694
- permissionMode: void 0,
12695
- hidden: true,
12696
- specialist: "database-operator",
12697
- model: void 0,
12696
+ const sessionId = randomUUID9();
12697
+ console.log(TAG20 + " route target=rc-spawn dispatchId=" + envelope.dispatchId + " sessionId=" + sessionId.slice(0, 8));
12698
+ const spawned = await managerRcSpawn({
12699
+ sessionId,
12698
12700
  initialMessage,
12699
- // Task 382 — LinkedIn ingest is a hidden autonomous spawn with no
12700
- // parent admin conversation; the database-operator threads
12701
- // `producedByTaskId` via work-create instead. Leave undefined.
12702
- conversationNodeId: void 0
12701
+ closeAfterTurn: true,
12702
+ logContext: "linkedin-ingest dispatchId=" + envelope.dispatchId
12703
12703
  });
12704
- if (!response.ok) {
12705
- const detail = await response.text().catch(() => "");
12704
+ if ("error" in spawned) {
12706
12705
  console.error(
12707
- TAG20 + " dispatch-failed dispatchId=" + envelope.dispatchId + " status=" + response.status + " ms=" + (Date.now() - spawnStart) + " detail=" + detail.slice(0, 200)
12706
+ TAG20 + " dispatch-failed dispatchId=" + envelope.dispatchId + " status=" + spawned.status + " ms=" + (Date.now() - spawnStart) + " message=" + spawned.error
12708
12707
  );
12709
- return c.json({ ok: false, error: "dispatch-failed", upstreamStatus: response.status, detail: detail.slice(0, 500) }, 502);
12708
+ return c.json({ ok: false, error: "dispatch-failed", upstreamStatus: spawned.status, detail: spawned.error }, 502);
12710
12709
  }
12711
12710
  console.log(
12712
- TAG20 + " dispatched dispatchId=" + envelope.dispatchId + " taskId=" + (claudeSessionId ?? "unknown") + " ms=" + (Date.now() - spawnStart)
12711
+ TAG20 + " dispatched dispatchId=" + envelope.dispatchId + " taskId=" + spawned.sessionId + " ms=" + (Date.now() - spawnStart)
12713
12712
  );
12714
- return c.json({ ok: true, dispatchId: envelope.dispatchId, taskId: claudeSessionId }, 202);
12713
+ return c.json({ ok: true, dispatchId: envelope.dispatchId, taskId: spawned.sessionId }, 202);
12715
12714
  });
12716
12715
  var linkedin_ingest_default = app28;
12717
12716
 
@@ -13079,7 +13078,7 @@ var admin_default = app34;
13079
13078
  import neo4j4 from "neo4j-driver";
13080
13079
  import { readFileSync as readFileSync17 } from "fs";
13081
13080
  import { resolve as resolve19 } from "path";
13082
- import { randomUUID as randomUUID8 } from "crypto";
13081
+ import { randomUUID as randomUUID10 } from "crypto";
13083
13082
  var PLATFORM_ROOT7 = process.env.MAXY_PLATFORM_ROOT ?? resolve19(process.cwd(), "..");
13084
13083
  var driver = null;
13085
13084
  function readPassword() {
@@ -13262,7 +13261,7 @@ async function consumeMagicTokenAndActivate(grantId) {
13262
13261
  }
13263
13262
  }
13264
13263
  async function generateNewMagicToken(grantId) {
13265
- const token = randomUUID8();
13264
+ const token = randomUUID10();
13266
13265
  const session = getSession3();
13267
13266
  try {
13268
13267
  const result = await session.run(
@@ -14718,7 +14717,7 @@ function broadcastAdminShutdown(reason) {
14718
14717
  }
14719
14718
 
14720
14719
  // ../lib/entitlement/src/index.ts
14721
- import { createPublicKey, createHash as createHash4, verify as cryptoVerify } from "crypto";
14720
+ import { createPublicKey, createHash as createHash5, verify as cryptoVerify } from "crypto";
14722
14721
  import { existsSync as existsSync22, readFileSync as readFileSync21, statSync as statSync9 } from "fs";
14723
14722
  import { resolve as resolve24 } from "path";
14724
14723
 
@@ -14789,7 +14788,7 @@ function verifyAndResolve(brand, entitlementPath, account) {
14789
14788
  reason: "pubkey-missing"
14790
14789
  });
14791
14790
  }
14792
- const pubkeyHash = createHash4("sha256").update(pubkeyPem).digest("hex");
14791
+ const pubkeyHash = createHash5("sha256").update(pubkeyPem).digest("hex");
14793
14792
  if (pubkeyHash !== PUBKEY_SHA256) {
14794
14793
  return logResolved(anonymousFallback("pubkey-tamper"), {
14795
14794
  reason: "pubkey-tamper"