shadok-ai 0.20.15 → 0.20.17

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
@@ -454,7 +454,11 @@ Enter to skip; you can add it later from the web UI).
454
454
  served back to the browser by `GET /media/<name>` from the same directory
455
455
  Telegram attachments land in. On a multi-tenant instance each group has its own
456
456
  media directory (`/media/g-<group>/<name>`), readable only by that group's
457
- agents and served only to people who can see that group.
457
+ agents and served only to people who can see that group. Every agent is
458
+ started with that directory as an extra working directory (`--add-dir`), so
459
+ it reads what you sent **without asking for permission** — and nothing is
460
+ written into its project or worktree. An agent started before this change
461
+ needs one *Reload agent* to pick it up.
458
462
  - **Files an agent hands you** — when an agent's result IS a file (a report, an
459
463
  export, a screenshot, an archive) it arrives as a download card in the chat,
460
464
  inline if it is an image, and as an upload in the Telegram topic. It goes
@@ -1162,6 +1166,15 @@ know before opening it up:
1162
1166
  the cockpit renews it — or 30 days after the sign-in at the latest), the open tab
1163
1167
  returns you to the login screen on its next request instead of failing in
1164
1168
  place — a paste that would not send, an agent list that would not refresh.
1169
+ - **Someone forgot their password.** An admin opens *reset password…* on that
1170
+ person's row in the **Users** panel and hands over the link it shows — valid
1171
+ 48 hours, single use, and they choose the new password themselves, so the
1172
+ admin never types or sees it. Their open sessions stop working right away,
1173
+ including a stolen one. Nobody can reset themselves: ask another admin. The
1174
+ instance password (`admin`) is not an account and is not reset here — change
1175
+ `--password` / `SHADOK_GUI_PASSWORD` and restart. With **two-factor** on that
1176
+ same row reads *recover access…* and offers the three levels below, each
1177
+ confirmed with the acting admin's own passkey.
1165
1178
  - **Two-factor sign-in (passkeys).** From the **Users** panel, anyone signed in
1166
1179
  with a named account can register a passkey on their device — the
1167
1180
  fingerprint / face / PIN unlock of the phone or laptop (WebAuthn, user
@@ -74,3 +74,15 @@ export declare function mediaServable(st: {
74
74
  isSymbolicLink: boolean;
75
75
  uid: number;
76
76
  }, multiTenant: boolean, serverUid: number): boolean;
77
+ /**
78
+ * The `--add-dir` pair that lets an agent READ its attachments without a
79
+ * permission prompt. A pasted or Telegram file lands in the media directory,
80
+ * which is outside the agent's working directory, so Claude Code asked before
81
+ * every read of a file the person had just handed over. Writing attachments
82
+ * into the cwd instead was rejected: it litters every worktree (and a worktree
83
+ * holding untracked files is no longer pruned on close, invariant 5) and risks
84
+ * a commit of someone's screenshot. Empty when there is no directory to add —
85
+ * `--add-dir` refuses a path that does not exist, and a refused flag must never
86
+ * cost the spawn.
87
+ */
88
+ export declare function mediaAddDirArgs(dir: string | null | undefined): string[];
@@ -100,4 +100,18 @@ export function mediaServable(st, multiTenant, serverUid) {
100
100
  return false;
101
101
  return !multiTenant || st.uid === serverUid;
102
102
  }
103
+ /**
104
+ * The `--add-dir` pair that lets an agent READ its attachments without a
105
+ * permission prompt. A pasted or Telegram file lands in the media directory,
106
+ * which is outside the agent's working directory, so Claude Code asked before
107
+ * every read of a file the person had just handed over. Writing attachments
108
+ * into the cwd instead was rejected: it litters every worktree (and a worktree
109
+ * holding untracked files is no longer pruned on close, invariant 5) and risks
110
+ * a commit of someone's screenshot. Empty when there is no directory to add —
111
+ * `--add-dir` refuses a path that does not exist, and a refused flag must never
112
+ * cost the spawn.
113
+ */
114
+ export function mediaAddDirArgs(dir) {
115
+ return dir ? ["--add-dir", dir] : [];
116
+ }
103
117
  //# sourceMappingURL=media-scope.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"media-scope.js","sourceRoot":"","sources":["../src/media-scope.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C;;;;;;;;;;;;;;;;;GAiBG;AAEH;0EAC0E;AAC1E,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,CAAC;AACvC,MAAM,CAAC,MAAM,kBAAkB,GAAG,yBAAyB,CAA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;;;;;;;;GAUG;AACH,MAAM,UAAU,eAAe,CAAC,GAA8B;IAC5D,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACvC,CAAC"}
package/dist/server.js CHANGED
@@ -77,7 +77,7 @@ import { RoomStore, canSeeRoom, isRoomId, newRoomId, pageMessages, patchRoomIn,
77
77
  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";
78
78
  import { resolveSpawnIsolation, osUserFor, homeForUser, tierStateDir, tierStateDirAction, runAsUser, provisionGroupUser, teardownGroupUser, reconcileGroupProvisioning, DEFAULT_HOME_BASE, createGroupFlow, deleteGroupFlow, SHARED_POT_GROUP, DEFAULT_SHARED_POT_PATH, } from "./osusers.js";
79
79
  import { mayActOnSession, cronCheckAllowed, mayReachGroup, osUserForChannelGroup, cronCheckEnv, cronCheckCommand, statAsUserArgv, parseStatOutput, readAsUserArgv, writeNewAsUserArgv, sameOfferedFile, } from "./group-exec.js";
80
- import { mediaDirForGroup, mediaFileMode, parseMediaRequest, groupForMediaKey, passwdGid, mediaDirSpec, mediaDirTrusted, mediaServable, } from "./media-scope.js";
80
+ import { mediaDirForGroup, mediaFileMode, parseMediaRequest, groupForMediaKey, passwdGid, mediaDirSpec, mediaDirTrusted, mediaServable, mediaAddDirArgs, } from "./media-scope.js";
81
81
  import { runPrivileged, TREE_OP_TIMEOUT_MS } from "./privileged.js";
82
82
  import { HOME_SKILLS_BASE, missingHomeSkillLinks, rewriteSkillsBase } from "./skill-paths.js";
83
83
  import { instanceKey } from "./paths.js";
@@ -1198,9 +1198,11 @@ function loginHtml(v) {
1198
1198
  const e = escapeXml;
1199
1199
  const accent = accentFor(v.theme);
1200
1200
  const name = v.instance || "Shadok-AI";
1201
- const heading = v.invite ? `Welcome, ${e(v.invite.name)}` : e(name);
1201
+ const heading = v.invite ? `${v.invite.reset ? "Hello again" : "Welcome"}, ${e(v.invite.name)}` : e(name);
1202
1202
  const sub = v.invite
1203
- ? "Choose a password to join this cockpit."
1203
+ ? v.invite.reset
1204
+ ? "Choose a new password. The old one no longer works."
1205
+ : "Choose a password to join this cockpit."
1204
1206
  : v.agent
1205
1207
  ? `Sign in to open <b>${e(v.agent)}</b>.`
1206
1208
  : "Sign in to continue.";
@@ -1209,7 +1211,7 @@ function loginHtml(v) {
1209
1211
  const pw = v.invite
1210
1212
  ? '<input id=pw type=password placeholder="Choose a password (8+ characters)" autofocus autocomplete=new-password>'
1211
1213
  : '<input id=pw type=password placeholder="Password" autofocus autocomplete=current-password>';
1212
- const title = v.invite ? `${e(name)} — choose a password` : `${e(name)} — sign in`;
1214
+ const title = v.invite ? `${e(name)} — ${v.invite.reset ? "new password" : "choose a password"}` : `${e(name)} — sign in`;
1213
1215
  return `<!doctype html><meta charset=utf8><meta name=viewport content="width=device-width,initial-scale=1">
1214
1216
  <meta name=robots content="noindex,nofollow"><link rel=icon href="/icons/icon-192.png">
1215
1217
  <title>${title}</title>${v.meta ? "\n" + v.meta : ""}
@@ -1329,8 +1331,8 @@ function sendLogin(req, res, agentId) {
1329
1331
  /** The page an invited person lands on: the login shell, pointed at the
1330
1332
  * redemption route. Same CSP and same nonce — a page that exempted itself from
1331
1333
  * the policy protecting every other page would be a strange message. */
1332
- function invitePage(name, token) {
1333
- return loginHtml({ ...brandView(), invite: { name, token } });
1334
+ function invitePage(name, token, reset = false) {
1335
+ return loginHtml({ ...brandView(), invite: { name, token, reset } });
1334
1336
  }
1335
1337
  /** This server's same-origin guard (see `originAllowed`). */
1336
1338
  /**
@@ -1736,7 +1738,8 @@ app.get("/invite/:token", (req, res) => {
1736
1738
  const v = inviteVerdict(acct, token, Date.now());
1737
1739
  if (!v.ok)
1738
1740
  return res.status(400).type("text").send(v.error);
1739
- return sendAuthPage(res, invitePage(acct.name, token), 200);
1741
+ // A level-1 reset link wears the same form with a different sentence.
1742
+ return sendAuthPage(res, invitePage(acct.name, token, acct.invite?.reason === "password"), 200);
1740
1743
  });
1741
1744
  app.post("/invite/:token", async (req, res) => {
1742
1745
  const token = String(req.params.token ?? "");
@@ -6822,7 +6825,8 @@ function askRequest(me, kind, target) {
6822
6825
  * 2 lost passkey, password known: two admins, then a device code.
6823
6826
  * 3 lost everything: a full reset, effective in 24 h or at a second admin's approval.
6824
6827
  * With two-factor OFF, levels 2 and 3 have nothing to protect and act at once
6825
- * (a device code / the v1 reset), like before.
6828
+ * (a device code / the v1 reset), like before — and no level asks the issuing
6829
+ * admin for a passkey, since there are none to assert there.
6826
6830
  */
6827
6831
  app.post("/2fa/recover", async (req, res) => {
6828
6832
  const me = tfaPerson(req, res, true);
@@ -6835,7 +6839,26 @@ app.post("/2fa/recover", async (req, res) => {
6835
6839
  const v = resetVerdict({ actor: me, target, accounts: loadAccounts() });
6836
6840
  if (!v.ok)
6837
6841
  return res.status(400).json({ error: v.error });
6838
- if (!(await stepUpOk(req, res, me)))
6842
+ // A FRESH passkey, but only while two-factor is ON — `stepUpIfTwoFactor`, the
6843
+ // same gate as inviting or deleting an account.
6844
+ //
6845
+ // Unconditional, this route could not run at all on an instance with
6846
+ // two-factor off: nobody there HAS a passkey (registering one is what turning
6847
+ // it on requires, not the reverse), and the bootstrap admin — the instance
6848
+ // password, which is who an admin is until named accounts exist — cannot hold
6849
+ // one by construction (invariant 46). So every level answered "confirm with
6850
+ // your passkey first", and a lost password had no remedy short of editing the
6851
+ // account file by hand. The comment above this handler already described the
6852
+ // intent ("with two-factor OFF, levels 2 and 3 ... act at once"); the gate
6853
+ // contradicted it.
6854
+ //
6855
+ // What remains when it is off: an admin, signed in, from a same-origin
6856
+ // browser (`tfaPerson(req, res, true)`) — exactly the bar `DELETE /users`
6857
+ // clears, and that one destroys a private space irreversibly. The assertion
6858
+ // defends the SECOND FACTOR, so it is worth demanding only where there is one;
6859
+ // the routes that could undo it for someone (`/2fa/enabled`,
6860
+ // `/2fa/passkey/delete`, `/2fa/enroll-code`) keep it unconditionally.
6861
+ if (!(await stepUpIfTwoFactor(req, res, me)))
6839
6862
  return;
6840
6863
  const now = Date.now();
6841
6864
  if (level === 1) {
@@ -9350,8 +9373,8 @@ function ensureTierStateDir(user, home) {
9350
9373
  console.log(`osusers: could not secure ${dir} for ${user} — ${e instanceof Error ? e.message : String(e)}`);
9351
9374
  }
9352
9375
  }
9353
- function seedGroupAgentHome(user, home, cwd) {
9354
- const cwds = new Set([cwd]);
9376
+ function seedGroupAgentHome(user, home, cwd, extraTrusted = []) {
9377
+ const cwds = new Set([cwd, ...extraTrusted]);
9355
9378
  const siblings = dropUserCwds().get(user);
9356
9379
  if (siblings)
9357
9380
  for (const c of siblings)
@@ -9515,6 +9538,26 @@ group) {
9515
9538
  // and only for a dropped agent, so a mono-tenant/root spawn stays byte-for-byte
9516
9539
  // as before. See `resolveSpawnModel`.
9517
9540
  const resolvedProfile = effectiveProfile(profile);
9541
+ // The directory this agent's attachments are written to (its group's in
9542
+ // multi-tenant, invariant 60), granted as an extra working directory so
9543
+ // reading a file the person just pasted asks for no permission. Best-effort:
9544
+ // a group that vanished keeps the old behaviour (a prompt), never a failed spawn.
9545
+ let mediaDirArg = null;
9546
+ try {
9547
+ mediaDirArg = DEPLOYMENT_MODE === "multi-tenant" ? mediaDirForGroupId(group ?? null) : mediaDirForSession(null);
9548
+ }
9549
+ catch (e) {
9550
+ console.warn(`media: no --add-dir for ${id.slice(0, 8)} (${e instanceof Error ? e.message : String(e)})`);
9551
+ }
9552
+ // An `--add-dir` directory Claude Code has never seen opens a BLOCKING
9553
+ // "Adding a new directory … do you trust it?" screen at spawn, with "No, exit"
9554
+ // preselected — every agent stopped there, and one Enter ended it (the first
9555
+ // version of this shipped without the seed and was reverted). It reads the
9556
+ // same `projects[<dir>].hasTrustDialogAccepted` a worktree's trust does, so
9557
+ // seed it the same way: here for an agent running as the server user, and in
9558
+ // `seedGroupAgentHome` below for a dropped one, which reads its own HOME.
9559
+ if (mediaDirArg)
9560
+ ensureProjectTrusted(mediaDirArg);
9518
9561
  const spawnModel = resolveSpawnModel({
9519
9562
  requested: model,
9520
9563
  profileModel: resolvedProfile?.model,
@@ -9525,6 +9568,9 @@ group) {
9525
9568
  // (src/prompt-args.ts), which silently dropped the role and the pilot prompt.
9526
9569
  const fullArgs = mergeAppendedPrompts([
9527
9570
  ...args,
9571
+ // A flag+value pair placed early: `--add-dir` is variadic, so it must be
9572
+ // followed by another flag, never by a bare word it would swallow.
9573
+ ...mediaAddDirArgs(mediaDirArg),
9528
9574
  ...permissionModeArgs(permissionMode),
9529
9575
  // A flag+value pair, before the profile's flags: nothing here can land
9530
9576
  // after `--mcp-config`'s variadic JSON as a bare word.
@@ -9568,7 +9614,7 @@ group) {
9568
9614
  // the per-HOME onboarding/trust state needs seeding into the group user's HOME.
9569
9615
  // The group also gets its OWN SSH identity (one key per group).
9570
9616
  if (user && home) {
9571
- seedGroupAgentHome(user, home, cwd);
9617
+ seedGroupAgentHome(user, home, cwd, mediaDirArg ? [mediaDirArg] : []);
9572
9618
  ensureAgentSshKey(user, home);
9573
9619
  }
9574
9620
  // Isolated groups share the subscription token, injected in the forced-last