mulmoclaude 2.10.0 → 2.12.0

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 (52) hide show
  1. package/README.md +15 -0
  2. package/bin/mulmoclaude.js +44 -51
  3. package/client/assets/{JsonEditor-E3FJ7oRf.js → JsonEditor-DnC5hozl.js} +1 -1
  4. package/client/assets/{marp-CmMNIT1E.js → marp-BH7JDaRq.js} +1 -1
  5. package/client/assets/material-symbols-outlined-DzTrJqFk.woff2 +0 -0
  6. package/client/assets/{feat-3497-Cwr8t4l4.js → mulmoclaude2-wt3640-35L_u9kD.js} +940 -929
  7. package/client/assets/mulmoclaude2-wt3640-DzadcIZy.css +2 -0
  8. package/client/assets/vue-i18n-BVPWXOdL.js +3 -0
  9. package/client/index.html +3 -3
  10. package/package.json +22 -22
  11. package/server/agent/backend/claude-code.ts +50 -5
  12. package/server/agent/config.ts +3 -1
  13. package/server/agent/sandboxEnv.ts +148 -0
  14. package/server/agent/sandboxEnvPlan.ts +188 -0
  15. package/server/api/auth/bearerAuth.ts +37 -16
  16. package/server/api/auth/bearerExemption.ts +38 -0
  17. package/server/api/auth/clientTokenAccess.ts +57 -0
  18. package/server/api/auth/clientTokenCli.ts +13 -0
  19. package/server/api/auth/clientTokenCommands.ts +110 -0
  20. package/server/api/auth/clientTokenRule.ts +116 -0
  21. package/server/api/auth/clientTokenScope.ts +73 -0
  22. package/server/api/auth/clientTokenStore.ts +226 -0
  23. package/server/api/auth/clientTokenUsage.ts +85 -0
  24. package/server/api/auth/clientTokenUsageRule.ts +59 -0
  25. package/server/api/auth/ownerTokenHandoff.ts +73 -0
  26. package/server/api/auth/principal.ts +94 -0
  27. package/server/api/routes/clientTokens.ts +85 -0
  28. package/server/api/routes/collections.ts +92 -45
  29. package/server/api/routes/files.ts +4 -6
  30. package/server/build/mcp-server.mjs +777 -768
  31. package/server/events/pub-sub/handshakeAuth.ts +3 -5
  32. package/server/events/pub-sub/index.ts +22 -4
  33. package/server/index.ts +33 -51
  34. package/server/system/env.ts +4 -0
  35. package/server/utils/wait-ready.d.mts +20 -0
  36. package/server/utils/wait-ready.mjs +64 -0
  37. package/src/components/SessionHistoryRow.vue +49 -33
  38. package/src/components/SettingsClientTokensTab.vue +176 -0
  39. package/src/components/SettingsModal.vue +4 -1
  40. package/src/config/apiRoutes.ts +4 -0
  41. package/src/lang/de.ts +25 -0
  42. package/src/lang/en.ts +24 -0
  43. package/src/lang/es.ts +24 -0
  44. package/src/lang/fr.ts +25 -0
  45. package/src/lang/ja.ts +24 -0
  46. package/src/lang/ko.ts +24 -0
  47. package/src/lang/pt-BR.ts +24 -0
  48. package/src/lang/zh.ts +23 -0
  49. package/src/utils/html/customViewSrcdoc.ts +5 -0
  50. package/client/assets/feat-3497-DEfIEPf6.css +0 -2
  51. package/client/assets/material-symbols-outlined-Bn5lkljl.woff2 +0 -0
  52. package/client/assets/vue-i18n-BHWgmfE3.js +0 -3
@@ -1,9 +1,7 @@
1
- import { isAuthorizedToken } from "@mulmoclaude/common/token-guard";
2
1
  import { isRecord } from "../../utils/types.js";
3
2
 
4
3
  // `auth` is whatever the socket.io client put in `io({ auth })`. Only a record
5
- // whose `token` passes the shared bearer rule connects; a server with no token
6
- // yet refuses everything, as `bearerAuth` does for HTTP.
7
- export function isAuthorizedPubSubHandshake(auth: unknown, expectedToken: string | null): boolean {
8
- return isRecord(auth) && isAuthorizedToken(auth.token, expectedToken);
4
+ // whose `token` passes `authorizeToken` (the host's bearer rule) connects.
5
+ export function isAuthorizedPubSubHandshake(auth: unknown, authorizeToken: (token: unknown) => boolean): boolean {
6
+ return isRecord(auth) && authorizeToken(auth.token);
9
7
  }
@@ -3,6 +3,7 @@ import { Server as IOServer, type Socket } from "socket.io";
3
3
 
4
4
  import { UNAUTHORIZED_MESSAGE } from "@mulmoclaude/common/token-guard";
5
5
  import { log } from "../../system/logger/index.js";
6
+ import { ONE_SECOND_MS } from "../../utils/time.js";
6
7
  import { isAuthorizedPubSubHandshake } from "./handshakeAuth.js";
7
8
 
8
9
  export interface IPubSub {
@@ -11,9 +12,25 @@ export interface IPubSub {
11
12
  }
12
13
 
13
14
  export interface PubSubOptions {
14
- /** The bearer token a handshake must present. `null` while the server
15
- * has none yet, which refuses every handshake. */
16
- tokenProvider: () => string | null;
15
+ /** Whether a handshake's token is accepted; refuses everything until the
16
+ * server has a token of its own. */
17
+ authorizeToken: (token: unknown) => boolean;
18
+ /** Test seam for how often open sockets are re-checked. */
19
+ revalidateIntervalMs?: number | undefined;
20
+ }
21
+
22
+ // The token is checked at the handshake; this re-checks open sockets so a
23
+ // revoked client token stops receiving events without waiting to reconnect.
24
+ const REVALIDATE_INTERVAL_MS = 5 * ONE_SECOND_MS;
25
+
26
+ function startRevalidation(server: http.Server, ioServer: IOServer, authorizeToken: (token: unknown) => boolean, intervalMs: number): void {
27
+ const timer = setInterval(() => {
28
+ ioServer.sockets.sockets.forEach((socket) => {
29
+ if (!isAuthorizedPubSubHandshake(socket.handshake.auth, authorizeToken)) socket.disconnect(true);
30
+ });
31
+ }, intervalMs);
32
+ timer.unref();
33
+ server.once("close", () => clearInterval(timer));
17
34
  }
18
35
 
19
36
  const logRoomError =
@@ -73,7 +90,7 @@ export function createPubSub(server: http.Server, options: PubSubOptions): IPubS
73
90
  // destroys the client socket, so socket.io does not retry it — the SPA
74
91
  // reads that as "reload for a fresh token" rather than spinning.
75
92
  ioServer.use((socket, next) => {
76
- if (isAuthorizedPubSubHandshake(socket.handshake.auth, options.tokenProvider())) {
93
+ if (isAuthorizedPubSubHandshake(socket.handshake.auth, options.authorizeToken)) {
77
94
  next();
78
95
  return;
79
96
  }
@@ -81,6 +98,7 @@ export function createPubSub(server: http.Server, options: PubSubOptions): IPubS
81
98
  next(new Error(UNAUTHORIZED_MESSAGE));
82
99
  });
83
100
 
101
+ startRevalidation(server, ioServer, options.authorizeToken, options.revalidateIntervalMs ?? REVALIDATE_INTERVAL_MS);
84
102
  ioServer.on("connection", bindRoomEvents);
85
103
 
86
104
  return {
package/server/index.ts CHANGED
@@ -80,6 +80,7 @@ import { fakeEchoBackend } from "./agent/backend/fake-echo.js";
80
80
  import { startMacosReminderAdapter } from "./notifier/macosReminderAdapter.js";
81
81
  import notifierRoutes from "./api/routes/notifier.js";
82
82
  import { createShutdownRouter } from "./api/routes/shutdown.js";
83
+ import { createClientTokensRouter } from "./api/routes/clientTokens.js";
83
84
  import { initNotifier } from "./notifier/engine.js";
84
85
  import { registerSaveAttachmentHook } from "./utils/files/attachment-store.js";
85
86
  import { capturePhotoLocation } from "./workspace/photo-locations/index.js";
@@ -108,6 +109,7 @@ import { WORKSPACE_DIRS, WORKSPACE_PATHS } from "./workspace/paths.js";
108
109
  import { resolveClientDir } from "./utils/clientDir.js";
109
110
  import { serverError } from "./utils/httpError.js";
110
111
  import { browserVisibleOrigin } from "./utils/forwardedOrigin.js";
112
+ import { decideOwnerTokenHandoff } from "./api/auth/ownerTokenHandoff.js";
111
113
  import { makeUuid } from "./utils/id.js";
112
114
  import { mcpToolsRouter, mcpTools, isMcpToolEnabled, MCP_TOOL_PROMPT_FILE_SOURCES } from "./agent/mcp-tools/index.js";
113
115
  import { preflightUserServers, logPreflightResult } from "./agent/mcpPreflight.js";
@@ -142,6 +144,8 @@ import { connectRelay } from "./events/relay-client.js";
142
144
  import { startConfiguredBridges } from "./bridges/registry.js";
143
145
  import { requireSameOrigin } from "./api/csrfGuard.js";
144
146
  import { bearerAuth } from "./api/auth/bearerAuth.js";
147
+ import { isBearerExempt } from "./api/auth/bearerExemption.js";
148
+ import { flushClientTokenUsage, isSocketAuthorizedBearer } from "./api/auth/principal.js";
145
149
  import { isViewDataPath } from "./api/auth/viewToken.js";
146
150
  import { deleteTokenFile, generateAndWriteToken, getCurrentToken } from "./api/auth/token.js";
147
151
  import { boundPortOf, deleteServerPort, publishServerPort, setBoundPort } from "./workspace/serverPort.js";
@@ -168,6 +172,20 @@ import { SCHEDULE_TYPES, MISSED_RUN_POLICIES } from "@receptron/task-scheduler";
168
172
 
169
173
  const HTML_TOKEN_PLACEHOLDER = "__MULMOCLAUDE_AUTH_TOKEN__";
170
174
 
175
+ // Withheld from a page load that came through a tunnel or proxy (#3627); the
176
+ // page then treats itself as signed out.
177
+ function ownerTokenForPage(req: Request): string {
178
+ const handoff = decideOwnerTokenHandoff({
179
+ remoteAddress: req.socket.remoteAddress,
180
+ target: req.originalUrl,
181
+ headers: req.headers,
182
+ rawHeaders: req.rawHeaders,
183
+ });
184
+ if (handoff.ok) return getCurrentToken() ?? "";
185
+ log.warn("auth", "index.html served without the owner token: not a direct localhost load", { reason: handoff.reason, path: req.path });
186
+ return "";
187
+ }
188
+
171
189
  const __filename = fileURLToPath(import.meta.url);
172
190
  const __dirname = path.dirname(__filename);
173
191
 
@@ -324,53 +342,10 @@ app.use((req, res, next) => {
324
342
  // Layered *on top of* CSRF guard so we catch both cross-origin
325
343
  // browser attacks (origin check) and local sibling processes that
326
344
  // bypass browser CORS (bearer check). See #272 and
327
- // plans/done/feat-bearer-token-auth.md.
328
- //
329
- // /api/files/* is exempt because <img src="/api/files/raw?path=...">
330
- // tags in rendered markdown can't attach Authorization headers.
331
- // /api/plugins/runtime/<pkg>/<version>/<file> (#1043 C-2) is exempt
332
- // for the same reason: the frontend dynamic-imports plugin assets
333
- // (`import("/api/plugins/runtime/<pkg>/<ver>/dist/vue.js")`) and the
334
- // browser cannot attach Authorization headers to those module
335
- // requests. The pattern "4+ segments past /plugins/runtime/" only
336
- // matches asset GETs — `/plugins/runtime/list` (3 segments) and
337
- // `/plugins/runtime/<pkg>/dispatch` (3 segments) still require auth.
338
- // Path traversal is hardened separately by `resolveWithinRoot` in
339
- // the asset route handler.
340
- // The CSRF origin check + loopback-only binding still apply.
341
- const RUNTIME_PLUGIN_ASSET_PATH_RE = /^\/plugins\/runtime\/[^/]+\/[^/]+\//;
342
- // Generic OAuth callback receiver for runtime plugins (#1162). Same
343
- // browser-redirect-can't-carry-Authorization-header reason as the
344
- // asset path above. Trust model: registry-membership (the host's
345
- // route handler 404s an unknown :alias) plus the plugin's single-use
346
- // `state` for CSRF.
347
- const RUNTIME_PLUGIN_OAUTH_CALLBACK_RE = /^\/plugins\/runtime\/oauth-callback\/[^/]+$/;
345
+ // plans/done/feat-bearer-token-auth.md. The requests a browser makes
346
+ // without a header are exempt — see `isBearerExempt`.
348
347
  app.use("/api", (req, res, next) => {
349
- if (req.path.startsWith("/files/")) {
350
- next();
351
- return;
352
- }
353
- // Custom-view data endpoints carry a scoped capability token, not the
354
- // global bearer (the sandboxed iframe can't read it). `requireViewToken`
355
- // guards them instead. See server/api/auth/viewToken.ts.
356
- if (isViewDataPath(req.path)) {
357
- next();
358
- return;
359
- }
360
- if ((req.method === "GET" || req.method === "HEAD") && RUNTIME_PLUGIN_ASSET_PATH_RE.test(req.path)) {
361
- // HEAD is bypassed for the same reason as GET: the frontend
362
- // runtime-plugin loader HEAD-probes `dist/vue.js` to distinguish
363
- // "no Vue bundle (404, server-only plugin)" from real load
364
- // failures before `import()`-ing the asset (#1273 follow-up).
365
- // That probe is a raw `fetch`, not the bearer-attaching `apiGet`,
366
- // and the actual `import()` itself can't attach Authorization
367
- // either — so the auth-bypass must cover both verbs or every
368
- // runtime plugin's Vue View silently downgrades to a
369
- // definition-only entry (401 → "unexpected status" → no view).
370
- next();
371
- return;
372
- }
373
- if (req.method === "GET" && RUNTIME_PLUGIN_OAUTH_CALLBACK_RE.test(req.path)) {
348
+ if (isBearerExempt({ method: req.method, path: req.path }, isViewDataPath)) {
374
349
  next();
375
350
  return;
376
351
  }
@@ -488,6 +463,7 @@ const getWorkspaceDirReal = makeCachedRealpath(workspacePath);
488
463
  // runaway loop hammering the filesystem, not to police normal use. Same limiter
489
464
  // the collection view routes use.
490
465
  const HTML_FILE_RATE_LIMIT_PER_MINUTE = 600;
466
+ const INDEX_HTML_RATE_LIMIT_PER_MINUTE = 600;
491
467
  const htmlFileRateLimit = makeViewActionRateLimiter(HTML_FILE_RATE_LIMIT_PER_MINUTE, ONE_MINUTE_MS);
492
468
  app.use(HTML_FILE_MOUNT, htmlFileRateLimit, async (req, res, next) => {
493
469
  if (!HTML_PREVIEW_EXT_RE.test(req.path)) {
@@ -747,6 +723,7 @@ const chatService = createChatService({
747
723
  // Socket.io handshake (see #268 Phase A) needs to validate the
748
724
  // same bearer token the HTTP middleware enforces.
749
725
  tokenProvider: getCurrentToken,
726
+ authorizeToken: isSocketAuthorizedBearer,
750
727
  listSessions: listSessionsForBridge,
751
728
  getSessionHistory: getSessionHistoryForBridge,
752
729
  getSessionRole: getSessionRoleForBridge,
@@ -766,6 +743,7 @@ app.use(createTranslationRouter());
766
743
  app.use(mcpToolsRouter);
767
744
  app.use(schedulerTasksRoutes);
768
745
  app.use(createShutdownRouter());
746
+ app.use(createClientTokensRouter());
769
747
 
770
748
  if (env.isProduction) {
771
749
  // `{ index: false }` so express.static doesn't intercept `GET /`
@@ -782,7 +760,10 @@ if (env.isProduction) {
782
760
  const clientDir = resolveClientDir(process.env.MULMOCLAUDE_CLIENT_DIR, path.join(__dirname, "../client"));
783
761
  app.use(express.static(clientDir, { index: false }));
784
762
  const indexHtmlPath = path.join(clientDir, "index.html");
785
- app.get("/{*splat}", (_req: Request, res: Response) => {
763
+ // Every client-side route lands here, so the bucket is roomy: it bounds a
764
+ // runaway reload loop re-reading index.html, not normal navigation.
765
+ const indexHtmlRateLimit = makeViewActionRateLimiter(INDEX_HTML_RATE_LIMIT_PER_MINUTE, ONE_MINUTE_MS);
766
+ app.get("/{*splat}", indexHtmlRateLimit, (req: Request, res: Response) => {
786
767
  let html: string;
787
768
  try {
788
769
  html = readFileSync(indexHtmlPath, "utf-8");
@@ -791,9 +772,10 @@ if (env.isProduction) {
791
772
  serverError(res, "Internal Server Error");
792
773
  return;
793
774
  }
794
- const token = getCurrentToken() ?? "";
795
- html = html.replace(HTML_TOKEN_PLACEHOLDER, token);
775
+ html = html.replace(HTML_TOKEN_PLACEHOLDER, ownerTokenForPage(req));
796
776
  res.set("Content-Type", "text/html; charset=utf-8");
777
+ // The page may carry the owner token, so no proxy or browser cache may keep it.
778
+ res.set("Cache-Control", "no-store");
797
779
  res.send(html);
798
780
  });
799
781
  }
@@ -1364,7 +1346,7 @@ async function startRuntimeServices(httpServer: ReturnType<typeof app.listen>, p
1364
1346
  // (#3082). That residue is accepted and reasoned about in
1365
1347
  // `docs/bridge-protocol.md`; it is not covered by this cleanup, which only
1366
1348
  // closes the graceful path.
1367
- const shutdownHooks: (() => void)[] = [stopWhisperSidecar];
1349
+ const shutdownHooks: (() => void)[] = [stopWhisperSidecar, flushClientTokenUsage];
1368
1350
  function registerShutdownHook(hook: () => void): void {
1369
1351
  shutdownHooks.push(hook);
1370
1352
  }
@@ -1472,7 +1454,7 @@ process.on("SIGTERM", () => {
1472
1454
  // (CodeRabbit review on PR #1196). Both `createPubSub` and
1473
1455
  // `initNotifier` are sync, so wiring them up here costs nothing
1474
1456
  // and closes the window.
1475
- const earlyPubsub = createPubSub(httpServer, { tokenProvider: getCurrentToken });
1457
+ const earlyPubsub = createPubSub(httpServer, { authorizeToken: isSocketAuthorizedBearer });
1476
1458
  initNotifier({
1477
1459
  publish: (channel, payload) => earlyPubsub.publish(channel, payload),
1478
1460
  });
@@ -96,6 +96,10 @@ export const env = Object.freeze({
96
96
  sandboxSshAgentForward: asFlag(process.env.SANDBOX_SSH_AGENT_FORWARD),
97
97
  sandboxSshAllowedHosts: process.env.SANDBOX_SSH_ALLOWED_HOSTS || "github.com",
98
98
  sandboxMountConfigs: asCsv(process.env.SANDBOX_MOUNT_CONFIGS),
99
+ // Extra env for the Docker sandbox (#3617): host variables by name, and an
100
+ // env file handed to docker as `--env-file`. Both off by default.
101
+ sandboxEnvNames: asCsv(process.env.SANDBOX_ENV),
102
+ sandboxEnvFile: process.env.SANDBOX_ENV_FILE || undefined,
99
103
 
100
104
  // API credentials (undefined when not configured). `GEMINI_API_KEY` is
101
105
  // deliberately NOT here — Settings can write it while the server runs, so
@@ -0,0 +1,20 @@
1
+ // Type declarations for wait-ready.mjs.
2
+
3
+ export const READY_POLL_INTERVAL_MS: number;
4
+
5
+ export const SLOW_START_NOTICE_AFTER_MS: number;
6
+
7
+ export function shouldAnnounceSlowStart(state: { elapsedMs: number; announced: boolean }): boolean;
8
+
9
+ export function slowStartMessage(url: string, options: { willOpenBrowser: boolean }): string;
10
+
11
+ export interface WaitUntilReadyOptions {
12
+ port: number;
13
+ isServerAlive: () => boolean;
14
+ onSlowStart: () => void;
15
+ probe?: (port: number) => Promise<boolean>;
16
+ sleep?: (delayMs: number) => Promise<void>;
17
+ now?: () => number;
18
+ }
19
+
20
+ export function waitUntilReady(options: WaitUntilReadyOptions): Promise<boolean>;
@@ -0,0 +1,64 @@
1
+ // "Has the server we just spawned started answering yet?"
2
+ //
3
+ // There is no deadline on purpose. A fixed window used to give up without a
4
+ // word (#3623), and the server legitimately spends a long time before
5
+ // `listen()` — a first sandbox image build, a slow synced workspace. The
6
+ // launcher exits when the server does, so waiting while it lives cannot hang.
7
+ //
8
+ // Plain `.mjs` for the same reason as `port.mjs`: the npm launcher boots before
9
+ // tsx. Sibling `wait-ready.d.mts` carries the type declarations.
10
+ import { detectRunningServer, SERVER_PRESENCE } from "./launcher/detect-server.mjs";
11
+
12
+ export const READY_POLL_INTERVAL_MS = 300;
13
+ export const SLOW_START_NOTICE_AFTER_MS = 15_000;
14
+
15
+ const MS_PER_SECOND = 1000;
16
+
17
+ /**
18
+ * @param {{ elapsedMs: number, announced: boolean }} state
19
+ * @returns {boolean}
20
+ */
21
+ export function shouldAnnounceSlowStart({ elapsedMs, announced }) {
22
+ return !announced && elapsedMs >= SLOW_START_NOTICE_AFTER_MS;
23
+ }
24
+
25
+ /**
26
+ * @param {string} url
27
+ * @param {{ willOpenBrowser: boolean }} options
28
+ */
29
+ export function slowStartMessage(url, { willOpenBrowser }) {
30
+ const seconds = Math.round(SLOW_START_NOTICE_AFTER_MS / MS_PER_SECOND);
31
+ const prefix = `Still starting after ${seconds}s`;
32
+ if (!willOpenBrowser) return `${prefix} — open ${url} once the server answers.`;
33
+ return `${prefix} — the browser opens once the server answers. To open it yourself: ${url}`;
34
+ }
35
+
36
+ /** @param {number} port */
37
+ async function isMulmoClaudeAnswering(port) {
38
+ return (await detectRunningServer(port)) === SERVER_PRESENCE.mulmoclaude;
39
+ }
40
+
41
+ /** @param {number} delayMs */
42
+ function sleepMs(delayMs) {
43
+ return new Promise((resolve) => setTimeout(resolve, delayMs));
44
+ }
45
+
46
+ /**
47
+ * Resolve true once the server answers, false if it dies first.
48
+ * @param {import("./wait-ready.d.mts").WaitUntilReadyOptions} options
49
+ * @returns {Promise<boolean>}
50
+ */
51
+ export async function waitUntilReady({ port, isServerAlive, onSlowStart, probe = isMulmoClaudeAnswering, sleep = sleepMs, now = Date.now }) {
52
+ const startedAt = now();
53
+ const state = { announced: false };
54
+ while (isServerAlive()) {
55
+ // A server that died mid-probe is not ready, whatever the probe saw.
56
+ if (await probe(port)) return isServerAlive();
57
+ if (shouldAnnounceSlowStart({ elapsedMs: now() - startedAt, announced: state.announced })) {
58
+ state.announced = true;
59
+ onSlowStart();
60
+ }
61
+ await sleep(READY_POLL_INTERVAL_MS);
62
+ }
63
+ return false;
64
+ }
@@ -1,21 +1,60 @@
1
1
  <template>
2
+ <!-- Not a control itself: the open button, the bookmark toggle and the
3
+ menu are siblings inside it, so none nests in another. The card's
4
+ own click is a mouse-only convenience; keyboard users have the open
5
+ button. -->
2
6
  <div
3
- tabindex="0"
4
- role="button"
5
- :aria-label="rowAria"
7
+ class="relative cursor-pointer rounded p-2 text-sm transition-colors"
6
8
  :title="primaryText"
7
- class="relative cursor-pointer rounded p-2 text-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-400"
8
9
  :class="rowClasses"
9
10
  :data-testid="`session-item-${session.id}`"
10
11
  @click="emit('select', session.id)"
11
- @keydown.enter.prevent.self="onActivateKey"
12
- @keydown.space.prevent.self="onActivateKey"
13
12
  >
13
+ <!-- Primary line prefers the AI-generated summary (chat indexer,
14
+ #123) when present — it's typically more informative than
15
+ the first user message. Fall back to the first user message,
16
+ then to a "no messages" placeholder. `line-clamp-2` lets a
17
+ summary wrap so more of it is readable at a glance; the raw
18
+ first-message fallback stays on a single line via `truncate`
19
+ so short prompts don't disturb row heights. -->
20
+ <div class="flex items-start gap-1.5">
21
+ <button
22
+ type="button"
23
+ class="flex-shrink-0 mt-0.5 rounded focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-400"
24
+ :title="bookmarkLabel"
25
+ :aria-label="t('sessionHistoryPanel.bookmark')"
26
+ :aria-pressed="session.isBookmarked === true"
27
+ :data-testid="`session-row-icon-bookmark-${session.id}`"
28
+ @click.stop="emit('toggleBookmark', session)"
29
+ >
30
+ <SessionRoleIcon :session="session" :roles="roles" size="sm" />
31
+ </button>
32
+ <!-- No handler: the click bubbles to the card, which selects, and on to the panel's document listener, which closes an open menu. -->
33
+ <button
34
+ type="button"
35
+ class="flex flex-1 min-w-0 items-start gap-1.5 rounded text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-400"
36
+ :aria-label="rowAria"
37
+ :aria-current="selected ? 'true' : undefined"
38
+ :data-testid="`session-row-open-${session.id}`"
39
+ >
40
+ <span
41
+ class="flex-1 min-w-0"
42
+ :class="[previewClasses, hasVisibleSummary ? 'line-clamp-2' : 'block truncate']"
43
+ :data-testid="`session-row-preview-${session.id}`"
44
+ >
45
+ {{ primaryText }}
46
+ </span>
47
+ <span v-if="session.isRunning" class="flex-shrink-0 flex items-center mt-0.5" :aria-label="t('sessionHistoryPanel.running')">
48
+ <span class="w-1.5 h-1.5 rounded-full bg-yellow-400 animate-pulse" />
49
+ </span>
50
+ </button>
51
+ </div>
14
52
  <!-- Timestamp pill straddling the top border, mirroring the
15
53
  SessionSidebar card design. The kebab "..." button sits
16
54
  next to it on the same border line — clicking opens a
17
- popover with delete + bookmark actions. The running
18
- indicator still renders inline in the meta line below
55
+ popover with delete + bookmark actions. It comes last in the
56
+ markup so the tab order runs bookmark, open, menu. The running
57
+ indicator still renders inline in the meta line
19
58
  (it's a status, not a time); unread is signalled through
20
59
  previewClasses (bold text); bookmark state is signalled
21
60
  via the green role icon. -->
@@ -27,8 +66,6 @@
27
66
  :aria-label="t('sessionHistoryPanel.rowMenuAria')"
28
67
  :data-testid="`session-row-menu-${session.id}`"
29
68
  @click.stop="emit('toggleMenu', session.id)"
30
- @keydown.enter.stop
31
- @keydown.space.stop
32
69
  >
33
70
  <span class="material-icons !text-[14px] leading-none" aria-hidden="true">more_horiz</span>
34
71
  </button>
@@ -59,22 +96,6 @@
59
96
  {{ t("sessionHistoryPanel.delete") }}
60
97
  </button>
61
98
  </div>
62
- <!-- Primary line prefers the AI-generated summary (chat indexer,
63
- #123) when present — it's typically more informative than
64
- the first user message. Fall back to the first user message,
65
- then to a "no messages" placeholder. `line-clamp-2` lets a
66
- summary wrap so more of it is readable at a glance; the raw
67
- first-message fallback stays on a single line via `truncate`
68
- so short prompts don't disturb row heights. -->
69
- <div class="flex items-start gap-1.5">
70
- <SessionRoleIcon :session="session" :roles="roles" size="sm" class="flex-shrink-0 mt-0.5" />
71
- <p class="flex-1 min-w-0" :class="[previewClasses, hasVisibleSummary ? 'line-clamp-2' : 'truncate']">
72
- {{ primaryText }}
73
- </p>
74
- <span v-if="session.isRunning" class="flex-shrink-0 flex items-center mt-0.5" :aria-label="t('sessionHistoryPanel.running')">
75
- <span class="w-1.5 h-1.5 rounded-full bg-yellow-400 animate-pulse" />
76
- </span>
77
- </div>
78
99
  </div>
79
100
  </template>
80
101
 
@@ -123,6 +144,8 @@ const primaryText = computed(() => resolveSessionPrimaryText(props.session) ?? t
123
144
 
124
145
  const rowAria = computed(() => t("sessionHistoryPanel.openRowAria", { preview: primaryText.value }));
125
146
 
147
+ const bookmarkLabel = computed(() => (props.session.isBookmarked ? t("sessionHistoryPanel.unbookmark") : t("sessionHistoryPanel.bookmark")));
148
+
126
149
  const formattedDate = computed(() => formatDate(props.session.updatedAt));
127
150
 
128
151
  const hasVisibleSummary = computed(() => sessionHasVisibleSummary(props.session));
@@ -130,11 +153,4 @@ const hasVisibleSummary = computed(() => sessionHasVisibleSummary(props.session)
130
153
  const rowClasses = computed(() => (props.selected ? "border-2 border-blue-500 hover:bg-gray-50" : "border border-gray-200 hover:bg-gray-50"));
131
154
 
132
155
  const previewClasses = computed(() => (props.session.hasUnread ? "text-gray-900 font-bold" : "text-gray-700"));
133
-
134
- // Held Enter / Space on a native <button> activates once per physical
135
- // press, not per OS auto-repeat tick (#684).
136
- function onActivateKey(event: KeyboardEvent): void {
137
- if (event.repeat) return;
138
- emit("select", props.session.id);
139
- }
140
156
  </script>
@@ -0,0 +1,176 @@
1
+ <template>
2
+ <div ref="tabRoot" class="space-y-3 outline-none" tabindex="-1" data-testid="settings-client-tokens-tab">
3
+ <p class="text-sm text-gray-700">{{ t("settingsModal.clientTokensTab.description") }}</p>
4
+ <p class="text-xs text-gray-500">
5
+ {{ t("settingsModal.clientTokensTab.issueHint") }}
6
+ <code class="rounded bg-gray-100 px-1 py-0.5 font-mono text-gray-800">{{ t("settingsModal.clientTokensTab.issueCommand") }}</code>
7
+ </p>
8
+
9
+ <p v-if="loading" class="text-sm text-gray-500" data-testid="settings-client-tokens-loading">{{ t("settingsModal.clientTokensTab.loading") }}</p>
10
+ <p v-else-if="tokens.length === 0 && !loadError" class="text-sm text-gray-500" data-testid="settings-client-tokens-empty">
11
+ {{ t("settingsModal.clientTokensTab.empty") }}
12
+ </p>
13
+
14
+ <table v-else-if="tokens.length > 0" class="w-full text-sm" data-testid="settings-client-tokens-list">
15
+ <thead>
16
+ <tr class="text-left text-xs text-gray-500 border-b border-gray-200">
17
+ <th class="py-1 pr-3 font-medium">{{ t("settingsModal.clientTokensTab.columnName") }}</th>
18
+ <th class="py-1 pr-3 font-medium">{{ t("settingsModal.clientTokensTab.columnScopes") }}</th>
19
+ <th class="py-1 pr-3 font-medium">{{ t("settingsModal.clientTokensTab.columnCreated") }}</th>
20
+ <th class="py-1 pr-3 font-medium">{{ t("settingsModal.clientTokensTab.columnLastUsed") }}</th>
21
+ <th class="py-1" />
22
+ </tr>
23
+ </thead>
24
+ <tbody>
25
+ <tr v-for="token in tokens" :key="token.id" class="border-b border-gray-100 align-top" :data-testid="`settings-client-token-${token.name}`">
26
+ <td class="py-1.5 pr-3 font-mono text-gray-900">{{ token.name }}</td>
27
+ <td class="py-1.5 pr-3 font-mono text-xs text-gray-700">{{ token.scopes.join(", ") }}</td>
28
+ <td class="py-1.5 pr-3 text-xs text-gray-700">{{ formatIso(token.createdAt) }}</td>
29
+ <td class="py-1.5 pr-3 text-xs text-gray-700" data-testid="settings-client-token-last-used">
30
+ {{ token.lastUsedAt === null ? t("settingsModal.clientTokensTab.neverUsed") : formatIso(token.lastUsedAt) }}
31
+ </td>
32
+ <td class="py-1.5 text-right">
33
+ <div v-if="confirmingName === token.name" class="flex justify-end gap-2">
34
+ <button
35
+ type="button"
36
+ class="rounded bg-red-700 px-2 py-1 text-xs font-medium text-white hover:bg-red-800 disabled:opacity-50"
37
+ :disabled="revokingName !== null"
38
+ :aria-describedby="CONFIRM_BODY_ID"
39
+ data-testid="settings-client-token-confirm-btn"
40
+ @click="revoke(token)"
41
+ >
42
+ {{ revokingName === token.name ? t("settingsModal.clientTokensTab.revoking") : t("settingsModal.clientTokensTab.confirmLabel") }}
43
+ </button>
44
+ <button
45
+ :ref="rememberCancelButton"
46
+ type="button"
47
+ class="rounded border border-gray-300 px-2 py-1 text-xs text-gray-700 hover:bg-gray-100 disabled:opacity-50"
48
+ :disabled="revokingName !== null"
49
+ :aria-describedby="CONFIRM_BODY_ID"
50
+ data-testid="settings-client-token-cancel-btn"
51
+ @click="cancelConfirm(token.name)"
52
+ >
53
+ {{ t("common.cancel") }}
54
+ </button>
55
+ </div>
56
+ <button
57
+ v-else
58
+ :ref="(el) => rememberRevokeButton(token.name, el)"
59
+ type="button"
60
+ class="rounded border border-red-300 bg-red-50 px-2 py-1 text-xs font-medium text-red-800 hover:bg-red-100 disabled:opacity-50"
61
+ :disabled="revokingName !== null"
62
+ data-testid="settings-client-token-revoke-btn"
63
+ @click="openConfirm(token.name)"
64
+ >
65
+ {{ t("settingsModal.clientTokensTab.revokeLabel") }}
66
+ </button>
67
+ </td>
68
+ </tr>
69
+ </tbody>
70
+ </table>
71
+
72
+ <p v-if="confirmingName !== null" :id="CONFIRM_BODY_ID" class="text-xs text-red-900" role="status" data-testid="settings-client-token-confirm-body">
73
+ {{ t("settingsModal.clientTokensTab.confirmBody", { name: confirmingName }) }}
74
+ </p>
75
+ <p class="text-xs text-gray-500">{{ t("settingsModal.clientTokensTab.lastUsedNote") }}</p>
76
+ <p v-if="unreadableEntryCount > 0" class="text-sm text-amber-800" role="status" data-testid="settings-client-tokens-unreadable">
77
+ {{ t("settingsModal.clientTokensTab.unreadableEntries", { count: unreadableEntryCount }) }}
78
+ </p>
79
+ <p v-if="loadError" class="text-sm text-red-700" role="alert" data-testid="settings-client-tokens-error">{{ loadError }}</p>
80
+ <p v-if="revokeError" class="text-sm text-red-700" role="alert" data-testid="settings-client-tokens-revoke-error">{{ revokeError }}</p>
81
+ </div>
82
+ </template>
83
+
84
+ <script setup lang="ts">
85
+ import { nextTick, onMounted, ref, type ComponentPublicInstance } from "vue";
86
+ import { useI18n } from "vue-i18n";
87
+ import { apiDelete, apiGet } from "../utils/api";
88
+ import { API_ROUTES } from "../config/apiRoutes";
89
+ import { formatDateTime } from "../utils/format/date";
90
+
91
+ interface ClientTokenRow {
92
+ name: string;
93
+ id: string;
94
+ createdAt: string;
95
+ scopes: string[];
96
+ lastUsedAt: string | null;
97
+ }
98
+
99
+ const { t } = useI18n();
100
+
101
+ const tokens = ref<ClientTokenRow[]>([]);
102
+ const unreadableEntryCount = ref(0);
103
+ const loading = ref(true);
104
+ const loadError = ref("");
105
+ const revokeError = ref("");
106
+ const confirmingName = ref<string | null>(null);
107
+ const revokingName = ref<string | null>(null);
108
+
109
+ // The confirm swaps out the button that had focus, so focus is moved on purpose:
110
+ // to Cancel when it opens, back to the row's Revoke when cancelled, and to the
111
+ // tab once the row is gone.
112
+ const CONFIRM_BODY_ID = "settings-client-token-confirm-body";
113
+ const tabRoot = ref<HTMLElement | null>(null);
114
+ const revokeButtons = new Map<string, HTMLButtonElement>();
115
+ const cancelButton = ref<HTMLButtonElement | null>(null);
116
+
117
+ type TemplateRef = Element | ComponentPublicInstance | null;
118
+
119
+ function rememberRevokeButton(name: string, element: TemplateRef): void {
120
+ if (element instanceof HTMLButtonElement) revokeButtons.set(name, element);
121
+ else revokeButtons.delete(name);
122
+ }
123
+
124
+ function rememberCancelButton(element: TemplateRef): void {
125
+ cancelButton.value = element instanceof HTMLButtonElement ? element : null;
126
+ }
127
+
128
+ async function openConfirm(name: string): Promise<void> {
129
+ confirmingName.value = name;
130
+ await nextTick();
131
+ cancelButton.value?.focus();
132
+ }
133
+
134
+ async function cancelConfirm(name: string): Promise<void> {
135
+ confirmingName.value = null;
136
+ await nextTick();
137
+ revokeButtons.get(name)?.focus();
138
+ }
139
+
140
+ function formatIso(iso: string): string {
141
+ const epochMs = Date.parse(iso);
142
+ return Number.isNaN(epochMs) ? iso : formatDateTime(epochMs);
143
+ }
144
+
145
+ async function load(): Promise<void> {
146
+ const response = await apiGet<{ tokens: ClientTokenRow[]; unreadableEntryCount: number }>(API_ROUTES.config.clientTokens);
147
+ loading.value = false;
148
+ if (!response.ok) {
149
+ loadError.value = response.error || t("settingsModal.clientTokensTab.loadError");
150
+ return;
151
+ }
152
+ loadError.value = "";
153
+ tokens.value = response.data.tokens;
154
+ unreadableEntryCount.value = response.data.unreadableEntryCount;
155
+ }
156
+
157
+ // Revoking stays disabled until the reload lands, so an older list can never
158
+ // arrive after a newer one and bring a revoked row back.
159
+ async function revoke(token: ClientTokenRow): Promise<void> {
160
+ if (revokingName.value !== null) return;
161
+ revokingName.value = token.name;
162
+ // The id pins the row the user confirmed: a token re-issued under the same
163
+ // name since the list loaded is refused rather than revoked.
164
+ const response = await apiDelete<{ revoked: string }>(API_ROUTES.config.clientToken.replace(":name", encodeURIComponent(token.name)), undefined, {
165
+ query: { id: token.id },
166
+ });
167
+ confirmingName.value = null;
168
+ revokeError.value = response.ok ? "" : response.error || t("settingsModal.clientTokensTab.revokeError");
169
+ await load();
170
+ revokingName.value = null;
171
+ await nextTick();
172
+ (revokeButtons.get(token.name) ?? tabRoot.value)?.focus();
173
+ }
174
+
175
+ onMounted(load);
176
+ </script>