shadok-ai 0.19.16 → 0.19.18

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/README.md CHANGED
@@ -304,6 +304,23 @@ Enter to skip; you can add it later from the web UI).
304
304
  the audio was left unheard — ask and the agent can listen. Telegram caps what
305
305
  a bot may download at 20 MB; past that you get a clear notice instead of
306
306
  silence.
307
+ - **Open the bot to other people** (admin, Telegram panel, privileged
308
+ deployment only) — normally the bot's private messages belong to you alone and
309
+ anyone else is told it is private. Pair the bot's DMs
310
+ first (**Pair Telegram**, then `/setup <code>` in a private chat with it — you
311
+ do NOT need a board group), then tick **Open DMs** and pick a **restricted
312
+ group** and a **profile**: anyone who writes to the bot then gets their own
313
+ agent instead, on that profile, inside that group, and always the same agent
314
+ for the same person. The profile is what decides the job — support, a front
315
+ desk, whatever you set up — and its guardrails are what those people are
316
+ driving, so choose it deliberately. You read and take over those conversations
317
+ from the cockpit, in that group; the group runs under its own Unix user, and
318
+ only its members see it, so whoever you add to the group can read them too.
319
+ They can talk and answer their agent's questions, and nothing else: no
320
+ command reaches the bot. Two things worth knowing before you open it — every
321
+ conversation is a real agent that stays resident, and they all draw on **your**
322
+ Claude subscription, so there is no cap and no queue by design. Untick it and
323
+ every such conversation is closed at once.
307
324
  - **Link to a message** — every message (yours and the agent's) has a 🔗 link
308
325
  button beside copy. It copies a URL like `…/#agent=<session>&msg=<id>`;
309
326
  whoever opens it — someone who already has access to this cockpit, after the
package/dist/config.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { ConfiguredBackend } from "./backend.js";
2
+ import { type GuestSetup } from "./tg-guests.js";
2
3
  /**
3
4
  * Global CLI config at ~/.shadok-ai/config.json (mode 600). The Telegram bot
4
5
  * token is **per launch directory** (`tokens[cwd]`), so each instance you run
@@ -20,6 +21,16 @@ export interface Config {
20
21
  telegramAllowed?: Record<string, string[]>;
21
22
  /** Per launch-directory on/off switch for the Telegram bridge (default on). */
22
23
  telegramEnabled?: Record<string, boolean>;
24
+ /**
25
+ * Per launch-directory open-DM setup: the switch, the restricted group
26
+ * guests' agents are born into, and the profile they run on
27
+ * (`src/tg-guests.ts`). Absent = closed, which is every instance's default.
28
+ */
29
+ telegramGuests?: Record<string, {
30
+ on?: boolean;
31
+ group?: string | null;
32
+ profile?: string | null;
33
+ }>;
23
34
  /** Optional GUI password (also settable via SHADOK_GUI_PASSWORD). */
24
35
  guiPassword?: string;
25
36
  /**
@@ -175,6 +186,23 @@ export interface TelegramConfig {
175
186
  }
176
187
  /** Resolve the effective Telegram config for `cwd`: env overrides config. */
177
188
  export declare function telegramConfig(cfg: Config, cwd: string, env?: NodeJS.ProcessEnv): TelegramConfig;
189
+ /**
190
+ * This directory's open-DM setup, OFF whenever the row is absent or malformed.
191
+ *
192
+ * The file is hand-editable, so a half-written row must read as CLOSED rather
193
+ * than throw or — far worse — open the bot's DMs with a group it cannot honour.
194
+ */
195
+ export declare function guestSetupForCwd(cfg: Config, cwd: string): GuestSetup;
196
+ /**
197
+ * Pure: set this directory's open-DM setup on `cfg` (caller persists).
198
+ *
199
+ * The group and the profile are kept when the switch goes off, so re-enabling
200
+ * needs no retyping — and clearing them is done by saving them as null, never
201
+ * as a side effect of switching off.
202
+ */
203
+ export declare function applyGuestSetup(cfg: Config, cwd: string, s: GuestSetup): Config;
204
+ /** Set this directory's open-DM setup and persist. */
205
+ export declare function setGuestSetupForCwd(cfg: Config, cwd: string, s: GuestSetup): void;
178
206
  export interface TelegramPatch {
179
207
  token?: string | null;
180
208
  enabled?: boolean;
package/dist/config.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import fs from "node:fs";
2
2
  import os from "node:os";
3
3
  import path from "node:path";
4
+ import { GUEST_SETUP_OFF } from "./tg-guests.js";
4
5
  export const SHADOK_DIR = path.join(os.homedir(), ".shadok-ai");
5
6
  const CONFIG_FILE = path.join(SHADOK_DIR, "config.json");
6
7
  const LEGACY_ENV = path.join(SHADOK_DIR, "telegram.env");
@@ -168,6 +169,39 @@ export function telegramConfig(cfg, cwd, env = process.env) {
168
169
  allowedChats,
169
170
  };
170
171
  }
172
+ /**
173
+ * This directory's open-DM setup, OFF whenever the row is absent or malformed.
174
+ *
175
+ * The file is hand-editable, so a half-written row must read as CLOSED rather
176
+ * than throw or — far worse — open the bot's DMs with a group it cannot honour.
177
+ */
178
+ export function guestSetupForCwd(cfg, cwd) {
179
+ const row = cfg.telegramGuests?.[cwd];
180
+ if (!row || typeof row !== "object")
181
+ return { ...GUEST_SETUP_OFF };
182
+ const group = typeof row.group === "string" && row.group.trim() ? row.group.trim() : null;
183
+ const profile = typeof row.profile === "string" && row.profile.trim() ? row.profile.trim() : null;
184
+ // `on` is only ever true with both halves present: the two fields are
185
+ // solidary, and a stored `on` without them would be a door to nowhere.
186
+ const on = row.on === true && !!group && !!profile;
187
+ return { on, group, profile };
188
+ }
189
+ /**
190
+ * Pure: set this directory's open-DM setup on `cfg` (caller persists).
191
+ *
192
+ * The group and the profile are kept when the switch goes off, so re-enabling
193
+ * needs no retyping — and clearing them is done by saving them as null, never
194
+ * as a side effect of switching off.
195
+ */
196
+ export function applyGuestSetup(cfg, cwd, s) {
197
+ cfg.telegramGuests ??= {};
198
+ cfg.telegramGuests[cwd] = { on: s.on, group: s.group, profile: s.profile };
199
+ return cfg;
200
+ }
201
+ /** Set this directory's open-DM setup and persist. */
202
+ export function setGuestSetupForCwd(cfg, cwd, s) {
203
+ saveConfig(applyGuestSetup(cfg, cwd, s));
204
+ }
171
205
  /**
172
206
  * Merge a UI patch into a copy of `cfg` (pure — caller persists). A token is
173
207
  * stored only when NOT under an env override; "" / null removes it. Absent keys
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAiH7B,MAAM,CAAC,MAAM,U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gBAAgB,CAAC,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC;IAChE,CAAC;IAAC,MAAM,CAAC;QACP,iBAAiB;IACnB,CAAC;IACD,IAAI,CAAC,KAAK,IAAI,OAAO,GAAG,CAAC,aAAa,KAAK,QAAQ;QAAE,KAAK,GAAG,GAAG,CAAC,aAAa,CAAC;IAC/E,IAAI,CAAC,KAAK;QAAE,OAAO;IACnB,CAAC,GAAG,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACjC,OAAO,GAAG,CAAC,aAAa,CAAC,CAAC,2BAA2B;IACrD,IAAI,CAAC;QACH,EAAE,CAAC,UAAU,CAAC,UAAU,EAAE,UAAU,GAAG,WAAW,CAAC,CAAC,CAAC,0BAA0B;IACjF,CAAC;IAAC,MAAM,CAAC;QACP,iBAAiB;IACnB,CAAC;IACD,UAAU,CAAC,GAAG,CAAC,CAAC;AAClB,CAAC"}
package/dist/server.js CHANGED
@@ -52,12 +52,13 @@ import { detectFork, rootIdOfFile } from "./forktrace.js";
52
52
  import { computePace, paceBlock, WINDOW_SEC } from "./pace.js";
53
53
  import { getUsage, readOAuthToken, resetUsageCache } from "./usage.js";
54
54
  import { createGauge, usageCandidates } from "./gauge-login.js";
55
- import { loadChannels, loadGroups, saveGroups, loadFolders, saveChannels, saveFolders, normalizeGroups, ensureMainGroup, mainGroupHeal, upsertChannel, removeChannel, mergeClientChannels, channelWriteAllowed, profilePatch, loadTgGroup, saveTgGroup, saveTgOperators, isHomeChannel, homeAdoptionTarget, resolveSessionTarget, resolveResumeId, resumeTarget, } from "./channels.js";
55
+ import { loadChannels, loadGroups, saveGroups, loadFolders, saveChannels, saveFolders, normalizeGroups, ensureMainGroup, mainGroupHeal, upsertChannel, removeChannel, mergeClientChannels, channelWriteAllowed, profilePatch, loadTgGroup, loadTgOwner, saveTgGroup, saveTgOperators, isHomeChannel, homeAdoptionTarget, resolveSessionTarget, resolveResumeId, resumeTarget, } from "./channels.js";
56
56
  import { channelFolder, foldersForViewer, mergeFoldersPut, refileItems } from "./agent-folders.js";
57
57
  import { deliverWithRetry } from "./reload.js";
58
58
  import { startTelegram, renameTelegramTopic, closeTelegramTopic, probeToken, isStalePreface, announceLoggedOut, resetLoggedOutNotice, attachmentPrompt, pasteFileName, mediaDir, } from "./telegram.js";
59
59
  import { transcribe, audioClipExtension } from "./whisper.js";
60
60
  import { cancelPairingCode, issuePairingCode, pairingStatus } from "./tg-pairing.js";
61
+ import { GUEST_SETUP_OFF, guestGroupChoices, guestPatchFlow, guestSpawnPlan } from "./tg-guests.js";
61
62
  import { migrateTgBindings } from "./channels.js";
62
63
  import { RoomStore, canSeeRoom, isRoomId, newRoomId, pageMessages, patchRoomIn, postRefusal, roomGroupFor, roomName, unreadCount, visibleRooms, ROOM_PAGE, } from "./rooms.js";
63
64
  import { viewerFor, canResumeAs, canRestartInto, canSeeGroup, membershipVerdict, canSeeSession, spawnGroupFor, listableGroups, visibleChannels, secretOwnGroupIds, ledgerGroupsFor, groupsPutFlow, privateGroupFor, newPrivateGroup, accountDeleteGroups, MAIN_GROUP_ID, groupMoveRefusal, isAgentViewer, canWriteSecretGroup, } from "./groups.js";
@@ -81,7 +82,7 @@ import { rowKind } from "../context/ledger-skill/ledger-core.mjs";
81
82
  import { profileWriteRefusal, profileDeleteRefusal, promptWriteRefusal, mayReadMcpValues, redactMcpServers, setProfileRefusal, restartAllPlan, monoSecretRefusal, } from "./route-guards.js";
82
83
  import { linkRefusal, markAgentPrompt, notificationText, } from "./kinship.js";
83
84
  import { talkVerdict, talkLetter } from "./talk.js";
84
- import { loadConfig, saveConfig, telegramConfig, applyTelegramPatch, titleForCwd, setTitleForCwd, instanceContextForCwd, setInstanceContextForCwd, themeForCwd, setThemeForCwd, mutedForCwd, setMutedForCwd, agentAuthForCwd, setAgentAuthForCwd, twoFactorForCwd, setTwoFactorForCwd, backendForCwd, setBackendForCwd, } from "./config.js";
85
+ import { loadConfig, saveConfig, telegramConfig, applyTelegramPatch, titleForCwd, setTitleForCwd, instanceContextForCwd, setInstanceContextForCwd, themeForCwd, setThemeForCwd, mutedForCwd, setMutedForCwd, agentAuthForCwd, setAgentAuthForCwd, twoFactorForCwd, setTwoFactorForCwd, backendForCwd, setBackendForCwd, guestSetupForCwd, setGuestSetupForCwd, } from "./config.js";
85
86
  import { secretsFor, secretsForProfile, secretNamesForProfile, secretNames, setSecret, deleteSecret, setSecretSharing, setSecretProfiles, secretWriteVerdict, secretWriteDecision, secretOwnerGroup, visibleSecrets, RESERVED_SECRET_NAMES, MT_CLAUDE_OAUTH_TOKEN_NAME, longLivedTokenInfo, loadVault, recordOrigin, originProfile, ANY_PROFILE, agentOverwriteRefusal, secretNameRefusal, } from "./secrets.js";
86
87
  import { recordSecretAudit, readSecretAudit, filterAudit, spawnActor, httpActor, profileSecretDiff, } from "./secret-audit.js";
87
88
  import { getProfile, profileArgs, resolveSpawnModel, permissionModeArgs, isPermissionMode, isEffortLevel, mcpServersVerdict, envVarsNote, seedDefaultProfiles, migrateToTracking, seedTweakProfile, seedSkillsmithProfile, MANAGED_PROFILE_NAMES, loadProfiles, upsertProfile, removeProfile, promptEditVerdict, secretAttachVerdict, READONLY_DENY, promptOrigin, effectiveProfile, shippedProfile, profileNames, } from "./profiles.js";
@@ -6282,11 +6283,22 @@ app.delete("/profiles", (req, res) => {
6282
6283
  res.json(loadProfiles());
6283
6284
  });
6284
6285
  /** Build the /telegram state view (token is never included). */
6285
- async function telegramState() {
6286
+ async function telegramState(viewer = null) {
6286
6287
  const tc = telegramConfig(loadConfig(), process.cwd());
6287
6288
  const probe = await probeToken(tc.token);
6288
6289
  const groupId = loadTgGroup();
6290
+ // The open-DM setup, plus the groups a picker may offer. The CHOICES are
6291
+ // per-caller (`guestGroupChoices` asks `viewerInGroup`), which is where the
6292
+ // "may I put strangers here?" authorisation lives — a group the caller does
6293
+ // not belong to is never in the list.
6294
+ const guests = guestSetupForCwd(loadConfig(), process.cwd());
6295
+ const guestGroups = guestGroupChoices(loadGroups(), viewer).map((g) => ({ id: g.id, name: g.name }));
6289
6296
  return {
6297
+ guests,
6298
+ guestGroups,
6299
+ // Whether the bot's DMs have an owner: a prerequisite for open DMs, and the
6300
+ // panel must be able to say so instead of letting the save fail.
6301
+ dmOwned: loadTgOwner() !== null,
6290
6302
  hasToken: Boolean(tc.token),
6291
6303
  enabled: tc.enabled,
6292
6304
  running: tgBridge.running(),
@@ -6308,7 +6320,7 @@ async function telegramState() {
6308
6320
  app.get("/telegram", async (req, res) => {
6309
6321
  if (!accountAdmin(req, res, false, "view or change the Telegram configuration"))
6310
6322
  return;
6311
- res.json(await telegramState());
6323
+ res.json(await telegramState(viewerFor(currentAccount(req))));
6312
6324
  });
6313
6325
  app.put("/telegram", async (req, res) => {
6314
6326
  if (!accountAdmin(req, res, true, "view or change the Telegram configuration"))
@@ -6334,12 +6346,46 @@ app.put("/telegram", async (req, res) => {
6334
6346
  saveTgGroup(null);
6335
6347
  saveTgOperators([]);
6336
6348
  }
6349
+ // Open DMs (src/tg-guests.ts): the switch, the restricted group guests' agents
6350
+ // live in, and the profile they run on. The whole decision is the pure
6351
+ // `guestPatchFlow` — a refusal carries no group list, so it cannot half-write.
6352
+ // Enabling also writes the INSTANCE into that group's members: the bridge
6353
+ // drives as the bootstrap admin, and every group question goes through
6354
+ // `memberOf`, so without it the spawn would be accepted and every message
6355
+ // afterwards refused.
6356
+ let guestsChanged = false;
6357
+ if (b.guests && typeof b.guests === "object") {
6358
+ const want = {
6359
+ on: b.guests.on === true,
6360
+ group: typeof b.guests.group === "string" ? String(b.guests.group) : null,
6361
+ profile: typeof b.guests.profile === "string" ? String(b.guests.profile) : null,
6362
+ };
6363
+ const flow = guestPatchFlow({
6364
+ mode: DEPLOYMENT_MODE,
6365
+ previous: guestSetupForCwd(loadConfig(), cwd),
6366
+ want,
6367
+ groups: loadGroups(),
6368
+ profileExists: (n) => !!getProfile(n),
6369
+ // `dmGate` answers `pair` while the bot has no owner, so guests cannot be
6370
+ // recognised before the DMs are paired — enabling first would save a door
6371
+ // that cannot open.
6372
+ hasOwner: loadTgOwner() !== null,
6373
+ });
6374
+ if (!flow.ok)
6375
+ return res.status(flow.status).json({ error: flow.error });
6376
+ saveGroups(flow.groups);
6377
+ setGuestSetupForCwd(loadConfig(), cwd, flow.setup);
6378
+ guestsChanged = true;
6379
+ }
6337
6380
  const hasConfigChange = patch.token !== undefined || patch.enabled !== undefined || patch.allowedChats !== undefined;
6338
6381
  if (hasConfigChange) {
6339
6382
  saveConfig(applyTelegramPatch(loadConfig(), cwd, patch, tc.envOverride));
6340
- restartTelegram();
6341
6383
  }
6342
- res.json(await telegramState());
6384
+ // The bridge reads the guest setup at start, so a guests change restarts it
6385
+ // too — otherwise the panel would save a door the running bridge never opens.
6386
+ if (hasConfigChange || guestsChanged)
6387
+ restartTelegram();
6388
+ res.json(await telegramState(viewerFor(currentAccount(req))));
6343
6389
  });
6344
6390
  // Pairing code for the bot (`src/tg-pairing.ts`): binding the board group or
6345
6391
  // owning the DMs needs a code only this admin-only panel shows. POST issues a
@@ -9637,6 +9683,23 @@ wss.on("connection", (ws, req) => {
9637
9683
  browser: fromBrowser,
9638
9684
  }, msg.origin);
9639
9685
  const cwd = msg.cwd?.trim() || process.cwd();
9686
+ // A GUEST's spawn (open DMs, src/tg-guests.ts). The marker is believed
9687
+ // only on a socket that proved the bridge secret — the same condition
9688
+ // that makes `from` believable (invariant 61) — and never on a resume,
9689
+ // where the channel's stored group is the authority (invariant 1).
9690
+ // Everything that matters is then read from the CONFIGURATION, so no
9691
+ // loopback client can place an agent in that group or pick the role
9692
+ // strangers drive (invariant 49).
9693
+ const guestPlan = guestSpawnPlan({
9694
+ marker: msg.guest,
9695
+ fromBridge: isTelegramBridge,
9696
+ resuming: !!msg.resume,
9697
+ setup: msg.guest === true ? guestSetupForCwd(loadConfig(), process.cwd()) : GUEST_SETUP_OFF,
9698
+ });
9699
+ if (guestPlan.kind === "refused")
9700
+ return fail(guestPlan.message, guestPlan.code);
9701
+ const guestSetup = guestPlan.kind === "guest" ? guestPlan : null;
9702
+ const guestGroupId = guestSetup?.group ?? null;
9640
9703
  // Deterministic id: enforced with --session-id for a new session,
9641
9704
  // known for a resume. NEVER derive it from the most recent file
9642
9705
  // in the directory — with several channels in the same directory
@@ -9709,7 +9772,7 @@ wss.on("connection", (ws, req) => {
9709
9772
  // empty checkouts). Keyed on the same `dropUser` the spawn will use; the
9710
9773
  // late call below re-checks the (resume / live-attach) paths unchanged.
9711
9774
  const connectRefusal = async (dropUser) => {
9712
- const customBackend = sessionBackend(gateProfile(msg)).kind === "custom";
9775
+ const customBackend = sessionBackend(guestSetup ? guestSetup.profile : gateProfile(msg)).kind === "custom";
9713
9776
  const user = dropUser ?? null;
9714
9777
  const agentAuth = agentAuthForCwd(loadConfig(), process.cwd());
9715
9778
  // Probe only what decides: the root sign-in is a ~850ms process spawn,
@@ -9762,16 +9825,22 @@ wss.on("connection", (ws, req) => {
9762
9825
  viewer: viewerFor(me),
9763
9826
  groups: loadGroups(),
9764
9827
  storedGroupId: null,
9765
- requestedGroupId: typeof msg.group === "string" && msg.group.trim() ? msg.group.trim() : null,
9828
+ requestedGroupId: guestGroupId ?? (typeof msg.group === "string" && msg.group.trim() ? msg.group.trim() : null),
9766
9829
  parentGroupId,
9767
9830
  });
9768
9831
  earlyUser = earlyIso.user ?? commonsOsUser({ migrated: groupsMigrated, mode: DEPLOYMENT_MODE });
9832
+ // A guest's agent runs in its GROUP's own home, never in the
9833
+ // operator's launch directory: a stranger has no business holding a
9834
+ // checkout of someone else's repository, and that home is the only
9835
+ // directory its Unix user can write in anyway.
9836
+ if (guestSetup)
9837
+ effectiveCwd = agentStateHome(earlyUser);
9769
9838
  const early = await connectRefusal(earlyUser);
9770
9839
  if (early)
9771
9840
  return fail(early.message, early.code, early.user);
9772
9841
  }
9773
9842
  announceStep("workspace");
9774
- if (msg.worktree && !resumed && isGitRepo(cwd)) {
9843
+ if (msg.worktree && !resumed && !guestSetup && isGitRepo(cwd)) {
9775
9844
  try {
9776
9845
  // Create the checkout under the DROP USER's own home (not the
9777
9846
  // server's `/root`, which that user cannot traverse) and hand it to
@@ -9884,7 +9953,9 @@ wss.on("connection", (ws, req) => {
9884
9953
  // that id is empty): the bridge passes the topic's channel profile, and
9885
9954
  // it gets re-persisted below — so a channel never silently loses its
9886
9955
  // profile (which would leave its cron scripts without secrets).
9887
- let profile = msg.profile ?? null;
9956
+ // A guest's role is the configured one, never the frame's: the profile
9957
+ // IS the job description strangers drive, so it is not theirs to pick.
9958
+ let profile = guestSetup ? guestSetup.profile : msg.profile ?? null;
9888
9959
  if (resumed) {
9889
9960
  const stored = loadChannels().find((c) => c.sessionId === id)?.profile;
9890
9961
  if (stored != null)
@@ -9949,7 +10020,8 @@ wss.on("connection", (ws, req) => {
9949
10020
  // channel record stay byte-for-byte today's.
9950
10021
  // `storedGroupId`/`groupsNow` and the resume people-boundary gate were
9951
10022
  // resolved ABOVE the live-attach branch (see CRIT1 note there).
9952
- const requestedGroupId = !resumed && typeof msg.group === "string" && msg.group.trim() ? msg.group.trim() : null;
10023
+ const requestedGroupId = guestGroupId ??
10024
+ (!resumed && typeof msg.group === "string" && msg.group.trim() ? msg.group.trim() : null);
9953
10025
  const isolation = resolveSpawnIsolation({
9954
10026
  mode: DEPLOYMENT_MODE,
9955
10027
  resumed,
@@ -9963,6 +10035,15 @@ wss.on("connection", (ws, req) => {
9963
10035
  // stored group; a new spawn gets the one the isolation policy derived
9964
10036
  // from the caller's identity. Both null in mono-tenant → secrets = Main.
9965
10037
  const agentGroupId = resumed ? storedGroupId : isolation.groupPatch.group ?? null;
10038
+ // ASSERT the one field this feature's safety rests on (invariant 24): a
10039
+ // guest's agent lands in the configured group or it does not exist.
10040
+ // Silently falling back to the commons — which is what an unseeable
10041
+ // group resolves to — would publish a stranger's conversation to every
10042
+ // account on the instance.
10043
+ if (guestSetup && agentGroupId !== guestSetup.group) {
10044
+ console.log(`telegram: guest spawn refused — resolved group ${agentGroupId ?? "none"} is not the configured ${guestSetup.group}`);
10045
+ return fail("the configured guest group is not usable from here — a guest's agent must never land anywhere else", "guest-group");
10046
+ }
9966
10047
  // T15 carry: a COMMONS agent (no dedicated group user) must not run as
9967
10048
  // root post-migration — drop it to the non-root `main` once migration
9968
10049
  // has completed. Before migration (or mono-tenant) this is null and the