mulmoclaude 2.9.0 → 2.11.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 (57) hide show
  1. package/README.md +11 -0
  2. package/bin/mulmoclaude.js +32 -17
  3. package/client/assets/{JsonEditor-E3FJ7oRf.js → JsonEditor-DnC5hozl.js} +1 -1
  4. package/client/assets/{marp-C3oyTBz_.js → marp-DvbfD9EO.js} +1 -1
  5. package/client/assets/material-symbols-outlined-DzTrJqFk.woff2 +0 -0
  6. package/client/assets/{feat-3497-qPLQlhNs.js → mulmoclaude3-BUmaA-ZX.js} +606 -600
  7. package/client/assets/mulmoclaude3-D93Ihflz.css +2 -0
  8. package/client/assets/vue-i18n-BVPWXOdL.js +3 -0
  9. package/client/index.html +3 -3
  10. package/package.json +20 -20
  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 +19 -10
  16. package/server/api/auth/clientTokenAccess.ts +57 -0
  17. package/server/api/auth/clientTokenCli.ts +13 -0
  18. package/server/api/auth/clientTokenCommands.ts +90 -0
  19. package/server/api/auth/clientTokenRule.ts +115 -0
  20. package/server/api/auth/clientTokenStore.ts +178 -0
  21. package/server/api/auth/principal.ts +33 -0
  22. package/server/api/routes/collections.ts +73 -35
  23. package/server/api/routes/files.ts +230 -89
  24. package/server/api/routes/pdf.ts +68 -62
  25. package/server/api/routes/runtime-plugin.ts +33 -32
  26. package/server/build/mcp-server.mjs +618 -609
  27. package/server/events/pub-sub/handshakeAuth.ts +3 -5
  28. package/server/events/pub-sub/index.ts +22 -4
  29. package/server/index.ts +30 -95
  30. package/server/plugins/confined-file-ops.ts +5 -3
  31. package/server/system/config.ts +1 -1
  32. package/server/system/env.ts +4 -0
  33. package/server/system/logs/aaa +737 -0
  34. package/server/system/logs/bb +446 -0
  35. package/server/utils/exif.ts +4 -7
  36. package/server/utils/files/artifactMount.ts +89 -0
  37. package/server/utils/files/attachment-store.ts +17 -29
  38. package/server/utils/files/image-store.ts +7 -13
  39. package/server/utils/files/plugins-io.ts +13 -5
  40. package/server/utils/files/safe.ts +0 -8
  41. package/server/utils/files/sendFileHandle.ts +115 -0
  42. package/server/utils/files/store-files.ts +86 -0
  43. package/server/utils/files/storePaths.ts +23 -0
  44. package/server/utils/files/thumbnail-store.ts +25 -23
  45. package/server/utils/files/upload-io.ts +9 -8
  46. package/server/utils/html/htmlArtifactSplicer.ts +19 -14
  47. package/server/utils/share/packHtml.ts +23 -34
  48. package/server/workspace/photo-locations/index.ts +26 -27
  49. package/server/workspace/photo-locations/list.ts +17 -29
  50. package/server/workspace/photo-locations/store.ts +4 -0
  51. package/server/workspace/wiki-pages/io.ts +9 -8
  52. package/src/components/SessionHistoryRow.vue +11 -1
  53. package/src/utils/html/customViewSrcdoc.ts +5 -0
  54. package/client/assets/feat-3497-CVVJjM2K.css +0 -2
  55. package/client/assets/material-symbols-outlined-Bn5lkljl.woff2 +0 -0
  56. package/client/assets/vue-i18n-BHWgmfE3.js +0 -3
  57. package/server/utils/files/store-resolvers.ts +0 -58
@@ -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
@@ -104,7 +104,7 @@ import { initCollectionChangePublisher } from "./events/collection-change.js";
104
104
  import { initPhotoLocationsChangePublisher } from "./events/photo-locations-change.js";
105
105
  import { getRole, loadAllRoles } from "./workspace/roles.js";
106
106
  import { discoverSkills } from "./workspace/skills/index.js";
107
- import { WORKSPACE_PATHS } from "./workspace/paths.js";
107
+ import { WORKSPACE_DIRS, WORKSPACE_PATHS } from "./workspace/paths.js";
108
108
  import { resolveClientDir } from "./utils/clientDir.js";
109
109
  import { serverError } from "./utils/httpError.js";
110
110
  import { browserVisibleOrigin } from "./utils/forwardedOrigin.js";
@@ -121,7 +121,8 @@ import { buildSandboxStatus } from "./api/sandboxStatus.js";
121
121
  import { buildDiagnosticsMarkdown } from "./utils/diagnostics/collect.js";
122
122
  import { existsSync, readFileSync } from "fs";
123
123
  import { realpath as fsRealpath, stat as fsStat } from "fs/promises";
124
- import { makeCachedRealpath, resolveArtifactRequestPath } from "./utils/files/safe.js";
124
+ import { makeCachedRealpath } from "./utils/files/safe.js";
125
+ import { artifactMount, sendArtifactFile } from "./utils/files/artifactMount.js";
125
126
  import { cpus, loadavg } from "os";
126
127
  import { isDockerAvailable, ensureSandboxImage } from "./system/docker.js";
127
128
  import { maybeRunJournal } from "./workspace/journal/index.js";
@@ -141,6 +142,7 @@ import { connectRelay } from "./events/relay-client.js";
141
142
  import { startConfiguredBridges } from "./bridges/registry.js";
142
143
  import { requireSameOrigin } from "./api/csrfGuard.js";
143
144
  import { bearerAuth } from "./api/auth/bearerAuth.js";
145
+ import { isAuthorizedBearer } from "./api/auth/principal.js";
144
146
  import { isViewDataPath } from "./api/auth/viewToken.js";
145
147
  import { deleteTokenFile, generateAndWriteToken, getCurrentToken } from "./api/auth/token.js";
146
148
  import { boundPortOf, deleteServerPort, publishServerPort, setBoundPort } from "./workspace/serverPort.js";
@@ -387,7 +389,7 @@ app.use("/api", (req, res, next) => {
387
389
  // requireSameOrigin guard above still applies; the listener also
388
390
  // stays loopback-only.
389
391
  //
390
- // Three-layer guard:
392
+ // Guard:
391
393
  // 1. Extension allowlist — reject anything that isn't an image,
392
394
  // video, or audio extension. `saveImage` currently writes `.png`
393
395
  // only, but Stage B (#1011) extends the markdown / wiki rewriter
@@ -396,36 +398,14 @@ app.use("/api", (req, res, next) => {
396
398
  // `artifacts/images/<id>.mp4` (or any user-dropped media file
397
399
  // under that dir) needs to round-trip through this mount the
398
400
  // same way image refs do — otherwise the rewritten URL hits this
399
- // mount and 404s before `express.static` gets a chance.
400
- // 2. realpath-based traversal check via `resolveWithinRoot` — same
401
- // guard `/api/files/raw` uses. Catches symlinks pointing outside
402
- // the images dir, which `express.static` would otherwise follow.
403
- // 3. `dotfiles: deny` + `fallthrough: false` on `express.static`
404
- // itself, plus its built-in `..` normalize for path traversal.
401
+ // mount and 404s.
402
+ // 2. `artifactMount` (server/utils/files/artifactMount.ts): the mount
403
+ // folder must resolve inside the workspace on every request,
404
+ // dotfile / traversal segments are refused, and the file is served
405
+ // from a handle verified to be the in-folder file — never re-opened
406
+ // by path, so a symlink swapped in mid-request is not followed.
405
407
  const IMAGE_EXT_RE = /\.(png|jpe?g|webp|gif|svg|mp4|webm|mov|m4v|ogv|mp3|ogg|oga|wav|m4a|aac)$/i;
406
- const getImagesDirReal = makeCachedRealpath(WORKSPACE_PATHS.images);
407
- app.use(
408
- "/artifacts/images",
409
- async (req, res, next) => {
410
- if (!IMAGE_EXT_RE.test(req.path)) {
411
- res.status(404).end();
412
- return;
413
- }
414
- const root = await getImagesDirReal();
415
- if (!root) {
416
- res.status(404).end();
417
- return;
418
- }
419
- // No explicit dotfile check here: this mount never short-circuits,
420
- // so `express.static`'s `dotfiles: "deny"` below is the authority.
421
- if (resolveArtifactRequestPath(root, req.path, false) === null) {
422
- res.status(404).end();
423
- return;
424
- }
425
- next();
426
- },
427
- express.static(WORKSPACE_PATHS.images, { dotfiles: "deny", fallthrough: false }),
428
- );
408
+ app.use("/artifacts/images", artifactMount(workspacePath, WORKSPACE_DIRS.images, IMAGE_EXT_RE));
429
409
 
430
410
  // Static mount for HTML artifacts. The Files-view preview iframe
431
411
  // switched from `srcdoc` to `src=/artifacts/html/<name>.html` so the
@@ -444,10 +424,7 @@ app.use(
444
424
  // (`previewCsp.ts`) so allowing those extensions would only delivery-
445
425
  // vector for blocked resources.
446
426
  //
447
- // Same three-layer guard as `/artifacts/images`:
448
- // 1. extension allowlist (`.html` / `.htm` plus image types).
449
- // 2. `resolveWithinRoot` symlink-aware traversal check.
450
- // 3. `dotfiles: deny` + `fallthrough: false` on `express.static`.
427
+ // Same guard as `/artifacts/images` (extension allowlist + `artifactMount`).
451
428
  //
452
429
  // Bearer auth skipped for the same reason as /artifacts/images and
453
430
  // /api/files/*: an iframe `src` request can't carry an Authorization
@@ -474,47 +451,23 @@ app.use(
474
451
  // eslint-disable-next-line sonarjs/regex-complexity -- flat extension allowlist with no nested quantifiers, ReDoS-safe; complexity is just the disjunction count
475
452
  const HTML_PREVIEW_EXT_RE = /\.(html?|png|jpe?g|webp|gif|svg|ico|mp4|webm|mov|m4v|ogv|mp3|ogg|oga|wav|m4a|aac)$/i;
476
453
  const HTML_DOCUMENT_EXT_RE = /\.html?$/i;
477
- const getHtmlsDirReal = makeCachedRealpath(WORKSPACE_PATHS.htmls);
478
-
479
454
  app.use(
480
455
  "/artifacts/html",
481
- async (req, res, next) => {
482
- if (!HTML_PREVIEW_EXT_RE.test(req.path)) {
483
- res.status(404).end();
484
- return;
485
- }
486
- const root = await getHtmlsDirReal();
487
- if (!root) {
488
- res.status(404).end();
456
+ artifactMount(workspacePath, WORKSPACE_DIRS.htmls, HTML_PREVIEW_EXT_RE, async (req, res, scope, relPath) => {
457
+ res.setHeader("X-Content-Type-Options", "nosniff");
458
+ if (!HTML_DOCUMENT_EXT_RE.test(req.path)) {
459
+ await sendArtifactFile(req, res, scope, relPath);
489
460
  return;
490
461
  }
491
- // denyDotfiles: the HTML short-circuit below serves the file itself
492
- // (bypassing `express.static`'s `dotfiles: "deny"`), so this mount
493
- // must reject dotfile segments in the guard — without it,
494
- // `/artifacts/html/.hidden.html` would be served (Codex review on
495
- // #1056).
496
- const relPath = resolveArtifactRequestPath(root, req.path, true);
497
- if (relPath === null) {
462
+ res.setHeader("Content-Security-Policy", buildHtmlPreviewCsp(browserVisibleOrigin(req), undefined, readCspExtraSync()));
463
+ const spliced = await readAndInjectHtmlArtifact(scope, relPath);
464
+ if (spliced === null) {
498
465
  res.status(404).end();
499
466
  return;
500
467
  }
501
- if (HTML_DOCUMENT_EXT_RE.test(req.path)) {
502
- const origin = browserVisibleOrigin(req);
503
- res.setHeader("Content-Security-Policy", buildHtmlPreviewCsp(origin, undefined, readCspExtraSync()));
504
- res.setHeader("X-Content-Type-Options", "nosniff");
505
- const spliced = await readAndInjectHtmlArtifact(root, relPath);
506
- if (spliced === null) {
507
- res.status(404).end();
508
- return;
509
- }
510
- res.setHeader("Content-Type", "text/html; charset=utf-8");
511
- res.send(spliced);
512
- return;
513
- }
514
- res.setHeader("X-Content-Type-Options", "nosniff");
515
- next();
516
- },
517
- express.static(WORKSPACE_PATHS.htmls, { dotfiles: "deny", fallthrough: false }),
468
+ res.setHeader("Content-Type", "text/html; charset=utf-8");
469
+ res.send(spliced);
470
+ }),
518
471
  );
519
472
 
520
473
  // Mount for HTML pages OUTSIDE `artifacts/html/` — presentHtml's `path` form
@@ -601,39 +554,20 @@ app.use(HTML_FILE_MOUNT, htmlFileRateLimit, async (req, res, next) => {
601
554
  // header doesn't interfere with the normal View / Preview path.
602
555
  const SVG_RESPONSE_CSP = "default-src 'none'; style-src 'unsafe-inline'; img-src 'self' data:; sandbox";
603
556
 
604
- // Strict three-layer guard mirroring the `/artifacts/images` mount:
605
- // extension allowlist, realpath traversal check, dotfiles deny +
606
- // fallthrough false on `express.static`. Bearer auth bypassed for the
557
+ // Same guard as `/artifacts/images` (extension allowlist + `artifactMount`).
558
+ // Bearer auth bypassed for the
607
559
  // same reason as `/artifacts/images` / `/artifacts/html`: an
608
560
  // `<img src>` request can't carry an Authorization header. Loopback-
609
561
  // only listener + `requireSameOrigin` remain the trust boundary.
610
562
  const SVG_EXT_RE = /\.svg$/i;
611
- const getSvgsDirReal = makeCachedRealpath(WORKSPACE_PATHS.svgs);
612
563
  app.use(
613
564
  "/artifacts/svg",
614
- async (req, res, next) => {
615
- if (!SVG_EXT_RE.test(req.path)) {
616
- res.status(404).end();
617
- return;
618
- }
619
- const root = await getSvgsDirReal();
620
- if (!root) {
621
- res.status(404).end();
622
- return;
623
- }
624
- // denyDotfiles for the same reason as the html mount: this handler
625
- // sets headers and serves via a bearer-bypassed <img> path, so the
626
- // dotfile guard can't be left solely to `express.static`.
627
- if (resolveArtifactRequestPath(root, req.path, true) === null) {
628
- res.status(404).end();
629
- return;
630
- }
565
+ artifactMount(workspacePath, WORKSPACE_DIRS.svgs, SVG_EXT_RE, async (req, res, scope, relPath) => {
631
566
  res.setHeader("X-Content-Type-Options", "nosniff");
632
567
  res.setHeader("Content-Type", "image/svg+xml; charset=utf-8");
633
568
  res.setHeader("Content-Security-Policy", SVG_RESPONSE_CSP);
634
- next();
635
- },
636
- express.static(WORKSPACE_PATHS.svgs, { dotfiles: "deny", fallthrough: false }),
569
+ await sendArtifactFile(req, res, scope, relPath);
570
+ }),
637
571
  );
638
572
 
639
573
  app.get(API_ROUTES.health, (_req: Request, res: Response) => {
@@ -814,6 +748,7 @@ const chatService = createChatService({
814
748
  // Socket.io handshake (see #268 Phase A) needs to validate the
815
749
  // same bearer token the HTTP middleware enforces.
816
750
  tokenProvider: getCurrentToken,
751
+ authorizeToken: isAuthorizedBearer,
817
752
  listSessions: listSessionsForBridge,
818
753
  getSessionHistory: getSessionHistoryForBridge,
819
754
  getSessionRole: getSessionRoleForBridge,
@@ -1539,7 +1474,7 @@ process.on("SIGTERM", () => {
1539
1474
  // (CodeRabbit review on PR #1196). Both `createPubSub` and
1540
1475
  // `initNotifier` are sync, so wiring them up here costs nothing
1541
1476
  // and closes the window.
1542
- const earlyPubsub = createPubSub(httpServer, { tokenProvider: getCurrentToken });
1477
+ const earlyPubsub = createPubSub(httpServer, { authorizeToken: isAuthorizedBearer });
1543
1478
  initNotifier({
1544
1479
  publish: (channel, payload) => earlyPubsub.publish(channel, payload),
1545
1480
  });
@@ -22,8 +22,8 @@ import { ensureInsideBase } from "./runtime-loader.js";
22
22
  //
23
23
  // 1. Replace `\` with `/` (Windows path.join leak repair).
24
24
  // 2. `path.posix.normalize` (folds `..`, `.`, `//`).
25
- // 3. Reject if the normalised form starts with `..` or `/`
26
- // (would escape the scope root or be absolute).
25
+ // 3. Reject if the normalised form starts with `..`, `/` or a
26
+ // drive letter (would escape the scope root or be absolute).
27
27
  // 4. `path.join(scopeRoot, ...segments)` — platform-aware join so
28
28
  // the returned absolute path uses the host OS separator
29
29
  // (backslashes on Windows, forward slashes on POSIX). Critical
@@ -36,11 +36,13 @@ import { ensureInsideBase } from "./runtime-loader.js";
36
36
  /** Resolve a plugin-supplied path to an absolute path inside the
37
37
  * plugin's scope root. Throws on traversal. Lexical only — symlinks
38
38
  * are checked by the FileOps below. Exported for tests. */
39
+ const WINDOWS_DRIVE_RE = /^[a-zA-Z]:/;
40
+
39
41
  export function normalizePluginPath(scopeRoot: string, rel: string): string {
40
42
  const slashed = rel.replace(/\\/g, "/");
41
43
  const normalised = path.posix.normalize(slashed);
42
44
  // `path.posix.normalize` produces `..` alone if the input is `..` itself, hence the equality branch.
43
- if (normalised === ".." || normalised.startsWith("../") || normalised.startsWith("/")) {
45
+ if (normalised === ".." || normalised.startsWith("../") || normalised.startsWith("/") || WINDOWS_DRIVE_RE.test(normalised)) {
44
46
  throw new Error(`path escapes plugin scope: ${rel}`);
45
47
  }
46
48
  const segments = normalised === "." ? [] : normalised.split("/");
@@ -55,7 +55,7 @@ export interface AppSettings {
55
55
 
56
56
  // Photo-EXIF auto-capture (#1222 PR-A). When `autoCapture` is true
57
57
  // (the default), every saved attachment with an image MIME runs
58
- // through `readPhotoExif` and a sidecar JSON lands at
58
+ // through `parsePhotoExif` and a sidecar JSON lands at
59
59
  // `data/locations/<YYYY>/<MM>/<id>.json`. Users opt out via
60
60
  // Settings → Privacy when they don't want GPS metadata captured
61
61
  // automatically (the future `manageMap` `extractExif` tool can
@@ -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