shadok-ai 0.19.22 → 0.19.23
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 +7 -0
- package/dist/server.js +80 -3
- package/dist/server.js.map +1 -1
- package/dist/telegram.js +6 -1
- package/dist/telegram.js.map +1 -1
- package/dist/tg-guests.d.ts +28 -0
- package/dist/tg-guests.js +42 -0
- package/dist/tg-guests.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -331,6 +331,13 @@ Enter to skip; you can add it later from the web UI).
|
|
|
331
331
|
gives it — so the welcome is something you write, by writing the role. If you
|
|
332
332
|
delete someone's agent from the cockpit, their next message simply starts a
|
|
333
333
|
new one.
|
|
334
|
+
Each person's agent works in **its own folder**, named after their Telegram
|
|
335
|
+
id, inside that group's home — so what one agent remembers about the person
|
|
336
|
+
it is talking to (Claude Code keeps a project's memory per directory) is not
|
|
337
|
+
loaded by the next person's agent. Said plainly, because it is not a wall:
|
|
338
|
+
they all run under the SAME Unix user, so an agent that goes looking can
|
|
339
|
+
still read its neighbour's folder. It stops the accident, not a determined
|
|
340
|
+
agent; a real wall would be one group per person.
|
|
334
341
|
They can talk and answer their agent's questions, and nothing else: no
|
|
335
342
|
command reaches the bot. Two things worth knowing before you open it — every
|
|
336
343
|
conversation is a real agent that stays resident, and they all draw on **your**
|
package/dist/server.js
CHANGED
|
@@ -58,7 +58,7 @@ 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, normalizeTgMode, } from "./tg-guests.js";
|
|
61
|
+
import { GUEST_SETUP_OFF, guestGroupChoices, guestPatchFlow, guestSpawnPlan, guestWorkDirName, normalizeTgMode, } from "./tg-guests.js";
|
|
62
62
|
import { migrateTgBindings } from "./channels.js";
|
|
63
63
|
import { RoomStore, canSeeRoom, isRoomId, newRoomId, pageMessages, patchRoomIn, postRefusal, roomGroupFor, roomName, unreadCount, visibleRooms, ROOM_PAGE, } from "./rooms.js";
|
|
64
64
|
import { viewerFor, canResumeAs, canRestartInto, canSeeGroup, membershipVerdict, canSeeSession, spawnGroupFor, listableGroups, visibleChannels, secretOwnGroupIds, ledgerGroupsFor, groupsPutFlow, privateGroupFor, newPrivateGroup, accountDeleteGroups, orphanedGroupsHeal, MAIN_GROUP_ID, groupMoveRefusal, isAgentViewer, canWriteSecretGroup, } from "./groups.js";
|
|
@@ -3444,6 +3444,55 @@ const GROUP_HOME_BASE = (process.env.SHADOK_HOME_BASE ?? "").trim() || DEFAULT_H
|
|
|
3444
3444
|
function agentStateHome(user) {
|
|
3445
3445
|
return user ? homeForUser(user, GROUP_HOME_BASE) : os.homedir();
|
|
3446
3446
|
}
|
|
3447
|
+
/**
|
|
3448
|
+
* The directory a guest's agent works in, created on first use.
|
|
3449
|
+
*
|
|
3450
|
+
* It sits INSIDE the group's home, so it is already behind the group's Unix
|
|
3451
|
+
* wall; what it adds is the thing that was missing, one folder per PERSON
|
|
3452
|
+
* (`guestWorkDirName` says why, and says what this is not). It is owned by the
|
|
3453
|
+
* group's user because the agent runs as that user: its `.claude` project
|
|
3454
|
+
* state, its notes and anything it writes land here.
|
|
3455
|
+
*
|
|
3456
|
+
* The home itself is NEVER created here — `useradd --create-home` owns that. A
|
|
3457
|
+
* recursive mkdir would make a root-owned home the dropped agent cannot even
|
|
3458
|
+
* traverse, and the failure would surface as an agent that will not start, far
|
|
3459
|
+
* from here.
|
|
3460
|
+
*/
|
|
3461
|
+
function ensureGuestWorkDir(home, sub, user) {
|
|
3462
|
+
if (!fs.existsSync(home))
|
|
3463
|
+
throw new Error(`the group's home is missing (${home}) — its OS user is not provisioned`);
|
|
3464
|
+
const dir = path.join(home, sub);
|
|
3465
|
+
// The same person coming back is the common case. `lstat`, never `stat`:
|
|
3466
|
+
// the agents of that group can write in this home, so the name could have
|
|
3467
|
+
// been replaced by a symlink — and a `chown` through one would hand its
|
|
3468
|
+
// TARGET to that Unix user.
|
|
3469
|
+
let st = null;
|
|
3470
|
+
try {
|
|
3471
|
+
st = fs.lstatSync(dir);
|
|
3472
|
+
}
|
|
3473
|
+
catch (e) {
|
|
3474
|
+
if (e.code !== "ENOENT")
|
|
3475
|
+
throw e;
|
|
3476
|
+
}
|
|
3477
|
+
if (st) {
|
|
3478
|
+
if (st.isSymbolicLink() || !st.isDirectory())
|
|
3479
|
+
throw new Error(`${dir} is not a directory`);
|
|
3480
|
+
return dir;
|
|
3481
|
+
}
|
|
3482
|
+
// Fresh: `mkdir` refuses an existing name (a symlink included), so what we
|
|
3483
|
+
// chown below is necessarily the directory we have just created.
|
|
3484
|
+
fs.mkdirSync(dir, { mode: 0o700 });
|
|
3485
|
+
if (user) {
|
|
3486
|
+
const uid = uidOf(user);
|
|
3487
|
+
const gid = gidOf(user);
|
|
3488
|
+
// Unowned by its own agent, the directory is unwritable and every turn
|
|
3489
|
+
// fails later, somewhere else: refuse here instead.
|
|
3490
|
+
if (uid === null || gid === null)
|
|
3491
|
+
throw new Error(`cannot resolve the uid of ${user}`);
|
|
3492
|
+
fs.chownSync(dir, uid, gid);
|
|
3493
|
+
}
|
|
3494
|
+
return dir;
|
|
3495
|
+
}
|
|
3447
3496
|
/** The COMMONS tier for secret resolution: Main plus every PUBLIC non-Main group.
|
|
3448
3497
|
* A public group is visible-to-all ("public = commun"), so its secrets resolve
|
|
3449
3498
|
* for every agent like Main's — not only for an agent that happens to run in it.
|
|
@@ -3799,6 +3848,20 @@ function uidOf(user) {
|
|
|
3799
3848
|
return null;
|
|
3800
3849
|
}
|
|
3801
3850
|
}
|
|
3851
|
+
/** Synchronous primary gid of an OS user, or null if it does not exist.
|
|
3852
|
+
* `useradd` gives each `sk-*` a group of its own, so this is not always the
|
|
3853
|
+
* uid — and a directory chowned to the wrong group is one the agent may not
|
|
3854
|
+
* be able to use. */
|
|
3855
|
+
function gidOf(user) {
|
|
3856
|
+
try {
|
|
3857
|
+
const out = execFileSync("id", ["-g", user], { encoding: "utf8", timeout: 5000 }).trim();
|
|
3858
|
+
const n = Number(out);
|
|
3859
|
+
return Number.isInteger(n) ? n : null;
|
|
3860
|
+
}
|
|
3861
|
+
catch {
|
|
3862
|
+
return null;
|
|
3863
|
+
}
|
|
3864
|
+
}
|
|
3802
3865
|
/** The server's gh auth token, probed once and cached (`undefined` = not probed,
|
|
3803
3866
|
* `null` = none). Best-effort: gh missing or signed out → no token, so a dropped
|
|
3804
3867
|
* agent simply gets no `GH_TOKEN` and gh is reachable-but-unauthenticated rather
|
|
@@ -9846,8 +9909,22 @@ wss.on("connection", (ws, req) => {
|
|
|
9846
9909
|
// operator's launch directory: a stranger has no business holding a
|
|
9847
9910
|
// checkout of someone else's repository, and that home is the only
|
|
9848
9911
|
// directory its Unix user can write in anyway.
|
|
9849
|
-
|
|
9850
|
-
|
|
9912
|
+
//
|
|
9913
|
+
// …and inside that home, in a directory of ITS OWN. Every guest
|
|
9914
|
+
// shares the group's Unix user, so they shared the working
|
|
9915
|
+
// directory too — which is where Claude Code keeps a project's
|
|
9916
|
+
// memory and where `CLAUDE.md` is read, so one person's agent
|
|
9917
|
+
// loaded the notes another person's agent had written, with
|
|
9918
|
+
// nothing on screen to show it (`guestWorkDirName`).
|
|
9919
|
+
if (guestSetup) {
|
|
9920
|
+
const sub = guestWorkDirName(msg.guestKey);
|
|
9921
|
+
// No usable id → REFUSE, never fall back to the shared home: a
|
|
9922
|
+
// silent fallback is exactly the mixing this closes, and it would
|
|
9923
|
+
// come back the day a caller forgets the field (invariant 24).
|
|
9924
|
+
if (!sub)
|
|
9925
|
+
return fail("a guest's agent needs the person it belongs to", "guest-key");
|
|
9926
|
+
effectiveCwd = ensureGuestWorkDir(agentStateHome(earlyUser), sub, earlyUser);
|
|
9927
|
+
}
|
|
9851
9928
|
const early = await connectRefusal(earlyUser);
|
|
9852
9929
|
if (early)
|
|
9853
9930
|
return fail(early.message, early.code, early.user);
|