shadok-ai 0.19.67 β†’ 0.19.68

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
@@ -378,12 +378,17 @@ Enter to skip; you can add it later from the web UI).
378
378
  **Board group** and every such conversation is closed at once.
379
379
  - **Link to a message** β€” every message (yours and the agent's, and a **room**'s
380
380
  too) has a πŸ”— link button beside copy. It copies a URL like
381
- `…/#agent=<session>&msg=<id>` for an agent, `…/#room=<room>&msg=<id>` for a
381
+ `…/a/<session>#msg=<id>` for an agent, `…/#room=<room>&msg=<id>` for a
382
382
  room; whoever opens it β€” someone who already has access to this cockpit, after
383
383
  the usual sign-in β€” lands on that conversation, scrolled to that message,
384
- highlighted. The link lives in the URL's `#` part, so it never reaches the
385
- server or a proxy log. A message older than the history shown, or a
386
- conversation that was closed, says so instead of opening somewhere else.
384
+ highlighted. The message lives in the URL's `#` part, so it never reaches the
385
+ server or a proxy log. The agent's id sits in the path on purpose: pasted into
386
+ Slack, WhatsApp, iMessage or Telegram, the link **previews** as a card naming
387
+ the agent and the cockpit (`/share/card.png`, generated on the fly in the
388
+ cockpit's colour) β€” and that is all it reveals, to anyone holding the link:
389
+ never a message. Older `#agent=<session>&msg=<id>` links still open. A message
390
+ older than the history shown, or a conversation that was closed, says so
391
+ instead of opening somewhere else.
387
392
  - **Run the command an agent asks you to** β€” when an agent writes `! cmd` for
388
393
  you to run (typically because it cannot), a β–Ά run button sits right on that
389
394
  command's code block, beside its copy button β€” so it runs where it was
package/dist/server.js CHANGED
@@ -113,6 +113,7 @@ import { startHeartbeat } from "./heartbeat.js";
113
113
  import { ensureClaude, claudeInstallInProgress, clearAbandonedClaudeReify, claudeCommand, classifyBin, findClaudeBinWithRetry, startWithBusyRetry, liveClaudeDeps, rememberClaudeBin, resolveBin, sampleBin, } from "./claude-bin.js";
114
114
  import { ensureTmux, tmuxInstallCommand } from "./tmux-install.js";
115
115
  import { cspHeader, injectNonce, NONCE_PLACEHOLDER, injectAssetVersion, injectInstanceKey } from "./csp.js";
116
+ import { accentFor, escapeXml, mascotSvg, previewMeta, renderCard, TAGLINE } from "./share-card.js";
116
117
  import { newAttempt, decryptPayload, PendingAttempts } from "./connect-crypto.js";
117
118
  import { accountsFileFor, loadAccountsStore, saveAccountsStore, upsertAccount, resolveAccountId, commonsGroupIds as commonsGroupIdsOf, accountVisible, accountEditVerdict, publicView, normalizeShare, agentAccountView, grantedAreas, patchRaisesAutonomy, policyPatch, } from "./connected-accounts.js";
118
119
  import { fetchMember, createPost, uploadImage, LinkedInError } from "./linkedin.js";
@@ -1130,23 +1131,56 @@ function passwordMatches(input) {
1130
1131
  const b = Buffer.from(GUI_PASSWORD);
1131
1132
  return a.length === b.length && timingSafeEqual(a, b);
1132
1133
  }
1133
- // The submit handler is a nonce-d <script> block, not an inline `onsubmit=`:
1134
- // the CSP forbids handler attributes (that is exactly what neutralises an
1135
- // `<img onerror>` injected elsewhere), and a login page exempting itself from
1136
- // its own policy would send an odd message.
1137
- const LOGIN_HTML = `<!doctype html><meta charset=utf8><meta name=viewport content="width=device-width,initial-scale=1">
1138
- <title>shadok-ai β€” login</title><style>body{margin:0;height:100vh;display:flex;align-items:center;justify-content:center;background:#14161a;color:#e8e8ea;font-family:system-ui}
1139
- form{background:#1b1d22;padding:28px;border-radius:12px;box-shadow:0 10px 40px rgba(0,0,0,.5);width:min(320px,90vw)}
1140
- h1{font-size:16px;margin:0 0 14px;color:#e0a44a}input{width:100%;box-sizing:border-box;padding:9px 11px;border-radius:7px;border:1px solid #333;background:#0d0f12;color:inherit;font-size:14px}
1141
- button{margin-top:12px;width:100%;padding:9px;border-radius:7px;border:none;background:#e0a44a;color:#14161a;font-weight:600;cursor:pointer}.err{color:#e26;font-size:12px;margin-top:8px;min-height:14px}
1142
- input+input{margin-top:8px}.hint{font-size:13px;color:#aab;margin:0 0 10px}.alt{display:block;margin-top:12px;font-size:12px;color:#aab}</style>
1143
- <form id=f data-action="/login">
1144
- <h1>β—† shadok-ai</h1><input id=u placeholder="User (blank = admin)" autocomplete=username><input id=pw type=password placeholder="Password" autofocus autocomplete=current-password><button>Enter</button><div class=err></div></form>
1145
- <form id=pk hidden><h1>β—† second step</h1><p class=hint>Confirm with this device's passkey (fingerprint, face, or device PIN).</p><button id=pkGo type=button>Use my passkey</button><a href=# id=pkCode class=alt>New device? Use a code from another one</a><div class=err></div></form>
1146
- <form id=en hidden><h1>β—† register this device</h1><p class=hint>Enter the code shown on a device already signed in (Users panel β†’ Add a device), or the one an admin gave you.</p><input id=enCode placeholder="Code" autocomplete=one-time-code autocapitalize=characters><input id=enLabel placeholder="Name this device (e.g. MacBook)"><button>Register with my fingerprint / face</button><div class=err></div></form>
1134
+ /**
1135
+ * The login page. A shared link lands here for anyone without a session β€” and
1136
+ * so does a chat app's preview bot, which is why it names the instance and
1137
+ * carries the `og:*` tags. The mascot is the same drawing as the share card's.
1138
+ */
1139
+ function loginHtml(v) {
1140
+ const e = escapeXml;
1141
+ const accent = accentFor(v.theme);
1142
+ const name = v.instance || "Shadok-AI";
1143
+ const heading = v.invite ? `Welcome, ${e(v.invite.name)}` : e(name);
1144
+ const sub = v.invite
1145
+ ? "Choose a password to join this cockpit."
1146
+ : v.agent
1147
+ ? `Sign in to open <b>${e(v.agent)}</b>.`
1148
+ : "Sign in to continue.";
1149
+ const action = v.invite ? `/invite/${encodeURIComponent(v.invite.token)}` : "/login";
1150
+ const user = v.invite ? "" : '<input id=u placeholder="User (blank = admin)" autocomplete=username>';
1151
+ const pw = v.invite
1152
+ ? '<input id=pw type=password placeholder="Choose a password (8+ characters)" autofocus autocomplete=new-password>'
1153
+ : '<input id=pw type=password placeholder="Password" autofocus autocomplete=current-password>';
1154
+ const title = v.invite ? `${e(name)} β€” choose a password` : `${e(name)} β€” sign in`;
1155
+ return `<!doctype html><meta charset=utf8><meta name=viewport content="width=device-width,initial-scale=1">
1156
+ <title>${title}</title>${v.meta ? "\n" + v.meta : ""}
1157
+ <style>@font-face{font-family:Inter;src:url(/fonts/Inter-Regular.ttf);font-weight:400}@font-face{font-family:Inter;src:url(/fonts/Inter-Bold.ttf);font-weight:700}
1158
+ :root{--accent:${accent}}
1159
+ body{margin:0;min-height:100vh;display:flex;align-items:center;justify-content:center;background:radial-gradient(circle at 50% 28%,color-mix(in srgb,var(--accent) 16%,transparent),transparent 55%),#12151c;color:#e8e8ea;font-family:Inter,system-ui,sans-serif}
1160
+ form{background:#1b1f29;border:1px solid #2c3140;padding:30px;border-radius:16px;box-shadow:0 20px 60px rgba(0,0,0,.55);width:min(340px,88vw);text-align:center}
1161
+ .brand{font-size:12px;font-weight:700;letter-spacing:.18em;color:var(--accent);margin-top:4px}
1162
+ h1{font-size:24px;margin:6px 0 4px;color:#f2f2f4;overflow-wrap:anywhere}.sub{font-size:14px;color:#a1a6b3;margin:0 0 20px}.sub b{color:#e8e8ea}
1163
+ input{width:100%;box-sizing:border-box;padding:11px 12px;border-radius:8px;border:1px solid #333a48;background:#0d0f14;color:inherit;font:inherit;font-size:16px}
1164
+ button{margin-top:14px;width:100%;padding:11px;border-radius:8px;border:none;background:var(--accent);color:#12151c;font:inherit;font-weight:700;cursor:pointer}.err{color:#f87171;font-size:13px;margin-top:10px;min-height:16px}
1165
+ input+input{margin-top:9px}.hint{font-size:13px;color:#a1a6b3;margin:0 0 12px}.alt{display:block;margin-top:12px;font-size:12px;color:#a1a6b3}
1166
+ .tag{margin-top:18px;font-size:12px;color:#6b7280}</style>
1167
+ <form id=f data-action="${action}">
1168
+ ${mascotSvg(96)}<div class=brand>SHADOK-AI</div><h1>${heading}</h1><p class=sub>${sub}</p>${user}${pw}<button>Sign in</button><div class=err></div><div class=tag>${e(TAGLINE.join(" "))}</div></form>
1169
+ <form id=pk hidden>${mascotSvg(72)}<h1>Second step</h1><p class=hint>Confirm with this device's passkey (fingerprint, face, or device PIN).</p><button id=pkGo type=button>Use my passkey</button><a href=# id=pkCode class=alt>New device? Use a code from another one</a><div class=err></div></form>
1170
+ <form id=en hidden>${mascotSvg(72)}<h1>Register this device</h1><p class=hint>Enter the code shown on a device already signed in (Users panel β†’ Add a device), or the one an admin gave you.</p><input id=enCode placeholder="Code" autocomplete=one-time-code autocapitalize=characters><input id=enLabel placeholder="Name this device (e.g. MacBook)"><button>Register with my fingerprint / face</button><div class=err></div></form>
1147
1171
  <script src="/vendor/simplewebauthn.js"></script>
1148
1172
  <script nonce="${NONCE_PLACEHOLDER}">
1149
1173
  const $ = (id) => document.getElementById(id);
1174
+ // Where to go once signed in: back to the shared agent link this page answered
1175
+ // for (\`/a/<id>\`, whose hash carries the message), else the cockpit.
1176
+ const home = () => (/^[/]a[/][0-9a-f-]{36}[/]?$/i.test(location.pathname) ? location.pathname : "/") + location.hash;
1177
+ // Signing in on the page a link opened usually means the target IS the current
1178
+ // address, and assigning it is an in-page hash jump, not a load. Reload then.
1179
+ const goHome = () => {
1180
+ const to = home();
1181
+ if (to === location.pathname + location.hash) location.reload();
1182
+ else location.assign(to);
1183
+ };
1150
1184
  const post = (url, body) => fetch(url, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body || {}) })
1151
1185
  .then(async (r) => ({ ok: r.ok, j: await r.json().catch(() => ({})) }));
1152
1186
  const show = (id) => { for (const f of ["f", "pk", "en"]) $(f).hidden = f !== id; };
@@ -1157,7 +1191,7 @@ const webauthn = () => window.isSecureContext && window.SimpleWebAuthnBrowser &&
1157
1191
  function nextStep(j) {
1158
1192
  if (j.next === "passkey") return show("pk");
1159
1193
  if (j.next === "enroll") { show("en"); if (j.code) $("enCode").value = j.code; return; }
1160
- location.assign("/" + location.hash);
1194
+ goHome();
1161
1195
  }
1162
1196
  document.getElementById("f").addEventListener("submit", (e) => {
1163
1197
  e.preventDefault();
@@ -1181,7 +1215,7 @@ $("pkGo").addEventListener("click", async () => {
1181
1215
  try { response = await SimpleWebAuthnBrowser.startAuthentication({ optionsJSON: o.j.options }); }
1182
1216
  catch (err) { return fail("pk", "Cancelled or not available: " + (err && err.message || err)); }
1183
1217
  const r = await post("/login/passkey", { challengeId: o.j.challengeId, response });
1184
- if (r.ok) return location.assign("/" + location.hash);
1218
+ if (r.ok) return goHome();
1185
1219
  fail("pk", r.j.error || "Not accepted");
1186
1220
  });
1187
1221
  $("pkCode").addEventListener("click", (e) => { e.preventDefault(); show("en"); });
@@ -1195,10 +1229,11 @@ $("en").addEventListener("submit", async (e) => {
1195
1229
  try { response = await SimpleWebAuthnBrowser.startRegistration({ optionsJSON: o.j.options }); }
1196
1230
  catch (err) { return fail("en", "Cancelled or not available: " + (err && err.message || err)); }
1197
1231
  const r = await post("/login/enroll", { challengeId: o.j.challengeId, response, code, label: $("enLabel").value });
1198
- if (r.ok) return location.assign("/" + location.hash);
1232
+ if (r.ok) return goHome();
1199
1233
  fail("en", r.j.error || "Not registered");
1200
1234
  });
1201
1235
  </script>`;
1236
+ }
1202
1237
  /** Serves a login-shaped page with its CSP and nonce (these sit outside the
1203
1238
  * gate, so they do not go through the index route). */
1204
1239
  function sendAuthPage(res, html, status) {
@@ -1206,21 +1241,37 @@ function sendAuthPage(res, html, status) {
1206
1241
  res.setHeader("Content-Security-Policy", cspHeader(nonce));
1207
1242
  res.status(status).type("html").send(injectNonce(html, nonce));
1208
1243
  }
1209
- function sendLogin(res) {
1210
- sendAuthPage(res, LOGIN_HTML, 401);
1244
+ /** The instance's title and palette, as the login page and the share card show them. */
1245
+ function brandView() {
1246
+ const cfg = loadConfig();
1247
+ return { instance: titleForCwd(cfg, process.cwd()) || "", theme: themeForCwd(cfg, process.cwd()) };
1248
+ }
1249
+ /** This request's own origin, as a preview bot reached it β€” `og:image` and
1250
+ * `og:url` must be absolute. Behind a TLS proxy, its forwarded scheme. */
1251
+ function requestOrigin(req) {
1252
+ const sock = req.socket;
1253
+ const https = requestIsHttps(!!sock?.encrypted, sock?.remoteAddress, req.headers);
1254
+ return `${https ? "https" : "http"}://${req.headers.host ?? "localhost"}`;
1255
+ }
1256
+ /**
1257
+ * The login page, with the preview of what was shared. Answered **200**, not
1258
+ * 401: a page that renders fine is not an error to a browser either way, but
1259
+ * a preview bot may drop a 401 body without reading its tags β€” and then the
1260
+ * link shows nothing at all. JSON callers still get their 401 from the gate.
1261
+ */
1262
+ function sendLogin(req, res, agentId) {
1263
+ const brand = brandView();
1264
+ const agent = agentId ? loadChannels().find((c) => c.sessionId === agentId)?.name ?? null : null;
1265
+ const origin = requestOrigin(req);
1266
+ const image = `${origin}/share/card.png${agent ? `?a=${agentId}` : ""}`;
1267
+ const meta = previewMeta({ ...brand, agent }, image, origin + req.originalUrl);
1268
+ sendAuthPage(res, loginHtml({ ...brand, agent, meta }), 200);
1211
1269
  }
1212
1270
  /** The page an invited person lands on: the login shell, pointed at the
1213
1271
  * redemption route. Same CSP and same nonce β€” a page that exempted itself from
1214
1272
  * the policy protecting every other page would be a strange message. */
1215
1273
  function invitePage(name, token) {
1216
- return LOGIN_HTML
1217
- .replace("<title>shadok-ai β€” login</title>", "<title>shadok-ai β€” choose a password</title>")
1218
- .replace('data-action="/login"', `data-action="/invite/${encodeURIComponent(token)}"`)
1219
- // The name is the admin's input: it must never be able to close the tag.
1220
- .replace("β—† shadok-ai", `Welcome, ${name.replace(/[<>&"']/g, "")}`)
1221
- .replace('<input id=u placeholder="User (blank = admin)" autocomplete=username>', "")
1222
- .replace('placeholder="Password"', 'placeholder="Choose a password (8+ characters)"')
1223
- .replace("autocomplete=current-password", "autocomplete=new-password");
1274
+ return loginHtml({ ...brandView(), invite: { name, token } });
1224
1275
  }
1225
1276
  /** This server's same-origin guard (see `originAllowed`). */
1226
1277
  /**
@@ -1741,6 +1792,39 @@ app.post("/hooks/:id", express.raw({ type: () => true, limit: "256kb" }), (req,
1741
1792
  });
1742
1793
  // Who am I? The client labels itself with this, and a tab whose session expired
1743
1794
  // finds out here rather than by a silent failure.
1795
+ // A shared link to one agent. The agent rides in the PATH, not the hash, so
1796
+ // the server β€” and a chat app's preview bot β€” can name it: the preview shows
1797
+ // the agent and the instance, never a message (`src/share-card.ts`). Signed
1798
+ // in, it is just the cockpit; the page moves the id back into the hash
1799
+ // (`#agent=`), which is what every deep-link path of the client reads.
1800
+ const SHARE_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
1801
+ app.get("/a/:id", (req, res) => {
1802
+ const id = String(req.params.id ?? "").toLowerCase();
1803
+ if (!SHARE_ID.test(id))
1804
+ return res.redirect(302, "/");
1805
+ if (requestAuthed(req))
1806
+ return sendIndex(res);
1807
+ return sendLogin(req, res, id);
1808
+ });
1809
+ // The preview card itself. Public by design β€” a preview bot carries no
1810
+ // session β€” and it reveals exactly what the login page's tags already say: the
1811
+ // instance's title, and the agent's name for an id that exists. An unknown id
1812
+ // gets the instance card, so probing ids learns nothing a 404 would not.
1813
+ app.get("/share/card.png", async (req, res) => {
1814
+ const id = String(req.query.a ?? "").toLowerCase();
1815
+ const agent = SHARE_ID.test(id) ? loadChannels().find((c) => c.sessionId === id)?.name ?? null : null;
1816
+ try {
1817
+ const png = await renderCard({ ...brandView(), agent });
1818
+ res.setHeader("Cache-Control", "public, max-age=3600");
1819
+ if (png)
1820
+ return res.type("png").send(png);
1821
+ }
1822
+ catch (e) {
1823
+ console.warn(`share card: ${e.message}`);
1824
+ }
1825
+ // No rasteriser on this platform: the plain icon still beats no picture.
1826
+ return res.sendFile(path.join(__dirname, "..", "public", "icons", "icon-512.png"));
1827
+ });
1744
1828
  app.get("/me", (req, res) => {
1745
1829
  const me = currentAccount(req);
1746
1830
  return me ? res.json(me) : res.status(401).json({ error: "unauthorized" });
@@ -1750,7 +1834,8 @@ app.get("/me", (req, res) => {
1750
1834
  app.use((req, res, next) => {
1751
1835
  // `/icons/`: the Home Screen icon is fetched by the OS, which may not carry
1752
1836
  // the session cookie, and it is the same static Shadok for every instance.
1753
- if (req.path === "/me" || req.path === "/logout" || req.path.startsWith("/invite/") || req.path.startsWith("/icons/") || requestAuthed(req))
1837
+ // `/fonts/`: the login page's own typeface, the same for every instance.
1838
+ if (req.path === "/me" || req.path === "/logout" || req.path.startsWith("/invite/") || req.path.startsWith("/icons/") || req.path.startsWith("/fonts/") || requestAuthed(req))
1754
1839
  return next();
1755
1840
  // A peer is a NARROW principal, not a member: over HTTP it may reach ONLY
1756
1841
  // `GET /diff` (of its own agents β€” the handler ownership-checks). Everything
@@ -1759,7 +1844,7 @@ app.use((req, res, next) => {
1759
1844
  if (req.method === "GET" && req.path === "/diff" && peerName(req))
1760
1845
  return next();
1761
1846
  if (req.method === "GET" && (req.headers.accept ?? "").includes("text/html"))
1762
- return sendLogin(res);
1847
+ return sendLogin(req, res);
1763
1848
  return res.status(401).json({ error: "unauthorized" });
1764
1849
  });
1765
1850
  // The page goes through here BEFORE express.static: it must receive its CSP's
@@ -1792,13 +1877,15 @@ app.get("/manifest.webmanifest", (_req, res) => {
1792
1877
  });
1793
1878
  });
1794
1879
  const INDEX_PATH = path.join(__dirname, "..", "public", "index.html");
1795
- app.get(["/", "/index.html"], (_req, res) => {
1880
+ app.get(["/", "/index.html"], (_req, res) => sendIndex(res));
1881
+ function sendIndex(res) {
1796
1882
  let html;
1797
1883
  try {
1798
1884
  html = fs.readFileSync(INDEX_PATH, "utf8");
1799
1885
  }
1800
1886
  catch {
1801
- return res.status(500).type("text").send("index.html not found");
1887
+ res.status(500).type("text").send("index.html not found");
1888
+ return;
1802
1889
  }
1803
1890
  const nonce = randomUUID();
1804
1891
  res.setHeader("Content-Security-Policy", cspHeader(nonce));
@@ -1806,7 +1893,7 @@ app.get(["/", "/index.html"], (_req, res) => {
1806
1893
  // demander que les modules de sa propre version, jamais ceux d'une plus
1807
1894
  // ancienne restΓ©s en cache (cf. invariant 10).
1808
1895
  res.type("html").send(injectInstanceKey(injectAssetVersion(injectNonce(html, nonce), OWN_VERSION), instanceKey()));
1809
- });
1896
+ }
1810
1897
  /**
1811
1898
  * Any file pasted into the composer β€” an image, a PDF, a CSV, anything. The web
1812
1899
  * had no way to hand a file to an agent at all (only Telegram did), so a