@abelxiaoxing/cadence 2.1.8 → 2.1.10

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.
@@ -325,6 +325,7 @@ var LIMITS = Object.freeze({
325
325
  stopWaitMs: 60000,
326
326
  authValidityMarginMs: 120000,
327
327
  browserLifetimeMs: 12 * 60 * 60 * 1000,
328
+ cookieLifetimeMs: 365 * 24 * 60 * 60 * 1000,
328
329
  terminateGraceMs: 1000,
329
330
  unconfirmedStopMs: 3000,
330
331
  graphBytes: 512 * 1024,
@@ -10451,6 +10452,23 @@ function decodeCookieToken(raw) {
10451
10452
  return raw;
10452
10453
  }
10453
10454
  }
10455
+ function sanitizeNextPath(raw) {
10456
+ const fallback = "/app";
10457
+ if (typeof raw !== "string")
10458
+ return fallback;
10459
+ const value = raw.trim();
10460
+ if (!value.startsWith("/") || value.startsWith("//") || value.includes("\\") || /[\x00-\x1f\x7f]/u.test(value))
10461
+ return fallback;
10462
+ try {
10463
+ const url = new URL(value, "http://cadence.invalid");
10464
+ url.searchParams.delete("token");
10465
+ url.searchParams.delete("auth_error");
10466
+ const path = `${url.pathname}${url.search}${url.hash}`;
10467
+ return path.startsWith("/") && !path.startsWith("//") ? path : fallback;
10468
+ } catch {
10469
+ return fallback;
10470
+ }
10471
+ }
10454
10472
  function cookieTokens(header, name) {
10455
10473
  if (!header)
10456
10474
  return [];
@@ -10758,7 +10776,28 @@ class HttpAuthentication {
10758
10776
  throw new ContractError("forbidden");
10759
10777
  if (!this.material.matches(value))
10760
10778
  throw new ContractError("unauthenticated");
10761
- return buildTokenCookie(this.cookieName, encodeURIComponent(value), LIMITS.browserLifetimeMs / 1000, boundary.secure);
10779
+ return buildTokenCookie(this.cookieName, encodeURIComponent(value), LIMITS.cookieLifetimeMs / 1000, boundary.secure);
10780
+ }
10781
+ login(value, boundary) {
10782
+ this.material.assertCurrent();
10783
+ const origin = boundary.headers.get("origin");
10784
+ if (origin === undefined || origin !== boundary.origin)
10785
+ throw new ContractError("forbidden");
10786
+ if (!this.material.matches(value))
10787
+ throw new ContractError("unauthenticated");
10788
+ return buildTokenCookie(this.cookieName, encodeURIComponent(value), LIMITS.cookieLifetimeMs / 1000, boundary.secure);
10789
+ }
10790
+ clearCookie(secure) {
10791
+ return buildTokenCookie(this.cookieName, "", 0, secure);
10792
+ }
10793
+ carriesCookie(header) {
10794
+ if (!header)
10795
+ return false;
10796
+ for (const part of header.split(";")) {
10797
+ if (part.trim().split("=")[0] === this.cookieName)
10798
+ return true;
10799
+ }
10800
+ return false;
10762
10801
  }
10763
10802
  authenticate(boundary, attachmentId, mutation2 = false, websocket = false) {
10764
10803
  this.material.assertCurrent();
@@ -10794,6 +10833,343 @@ class HttpAuthentication {
10794
10833
  }
10795
10834
  }
10796
10835
 
10836
+ // src/service/auth-form.ts
10837
+ async function readLoginForm(req, signal) {
10838
+ if (req.headers["content-type"] !== "application/x-www-form-urlencoded" || req.headers["content-encoding"] !== undefined || req.headers["transfer-encoding"] !== undefined)
10839
+ throw new ContractError("invalid");
10840
+ const length = req.headers["content-length"];
10841
+ if (length !== undefined && (!/^(0|[1-9][0-9]*)$/.test(length) || Number(length) > LIMITS.controlBytes))
10842
+ throw new ContractError("oversize");
10843
+ const chunks = [];
10844
+ let bytes = 0;
10845
+ for await (const chunk of req.iterator({ destroyOnReturn: false })) {
10846
+ if (signal?.aborted)
10847
+ throw new ContractError("unavailable");
10848
+ bytes += chunk.length;
10849
+ if (bytes > LIMITS.controlBytes)
10850
+ throw new ContractError("oversize");
10851
+ chunks.push(chunk);
10852
+ }
10853
+ let form;
10854
+ try {
10855
+ form = new URLSearchParams(new TextDecoder("utf-8", { fatal: true }).decode(Buffer.concat(chunks)));
10856
+ } catch {
10857
+ throw new ContractError("invalid");
10858
+ }
10859
+ if (form.getAll("password").length !== 1 || form.getAll("next").length > 1 || [...form.keys()].some((key) => key !== "password" && key !== "next"))
10860
+ throw new ContractError("invalid");
10861
+ return {
10862
+ password: form.get("password") ?? "",
10863
+ next: sanitizeNextPath(form.get("next"))
10864
+ };
10865
+ }
10866
+ function loginRetryPath(next) {
10867
+ const target = sanitizeNextPath(next);
10868
+ return target === "/app" ? "/?auth_error=1" : `/?${new URLSearchParams({ auth_error: "1", next: target })}`;
10869
+ }
10870
+ function loginNextPath(url) {
10871
+ return sanitizeNextPath(url.pathname === "/" && url.searchParams.has("auth_error") ? url.searchParams.get("next") : `${url.pathname}${url.search}${url.hash}`);
10872
+ }
10873
+
10874
+ // src/service/auth-page.ts
10875
+ import { createHash as createHash9 } from "node:crypto";
10876
+ var styles = `
10877
+ :root {
10878
+ color-scheme: light dark;
10879
+ font-family:
10880
+ Inter, Geist, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
10881
+ font-synthesis: none;
10882
+ --page: light-dark(#f5f7ff, #020617);
10883
+ --text: light-dark(#0f172a, #e6edf7);
10884
+ --muted: light-dark(#536176, #94a3b8);
10885
+ --glass: light-dark(rgba(255, 255, 255, 0.62), rgba(15, 23, 42, 0.62));
10886
+ --glass-line: light-dark(rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0.1));
10887
+ --field: light-dark(rgba(255, 255, 255, 0.5), rgba(2, 6, 23, 0.48));
10888
+ --field-line: light-dark(rgba(100, 116, 139, 0.28), rgba(255, 255, 255, 0.12));
10889
+ --primary-a: light-dark(#0e7490, #22d3ee);
10890
+ --primary-b: light-dark(#1d4ed8, #60a5fa);
10891
+ --on-primary: light-dark(#ffffff, #082f49);
10892
+ --focus: light-dark(#2563eb, #22d3ee);
10893
+ --glow: light-dark(rgba(37, 99, 235, 0.22), rgba(34, 211, 238, 0.2));
10894
+ --shadow: light-dark(rgba(30, 64, 175, 0.14), rgba(0, 0, 0, 0.42));
10895
+ --mesh-a: light-dark(rgba(147, 197, 253, 0.64), rgba(34, 211, 238, 0.1));
10896
+ --mesh-b: light-dark(rgba(196, 181, 253, 0.58), rgba(37, 99, 235, 0.16));
10897
+ --mesh-c: light-dark(rgba(165, 243, 252, 0.52), rgba(99, 102, 241, 0.1));
10898
+ --grid: light-dark(rgba(37, 99, 235, 0.04), rgba(56, 189, 248, 0.055));
10899
+ --error: light-dark(#b91c1c, #fda4af);
10900
+ --error-bg: light-dark(rgba(254, 226, 226, 0.7), rgba(159, 18, 57, 0.12));
10901
+ }
10902
+ * {
10903
+ box-sizing: border-box;
10904
+ }
10905
+ body {
10906
+ margin: 0;
10907
+ min-height: 100vh;
10908
+ min-height: 100svh;
10909
+ display: grid;
10910
+ place-items: center;
10911
+ padding: 28px 20px;
10912
+ color: var(--text);
10913
+ background: var(--page);
10914
+ }
10915
+ body::before,
10916
+ body::after {
10917
+ content: "";
10918
+ position: fixed;
10919
+ inset: 0;
10920
+ z-index: 0;
10921
+ pointer-events: none;
10922
+ }
10923
+ body::before {
10924
+ background:
10925
+ radial-gradient(circle at 12% 10%, var(--mesh-a), transparent 42%),
10926
+ radial-gradient(circle at 90% 16%, var(--mesh-b), transparent 44%),
10927
+ radial-gradient(circle at 52% 100%, var(--mesh-c), transparent 48%);
10928
+ }
10929
+ body::after {
10930
+ background-image:
10931
+ linear-gradient(var(--grid) 1px, transparent 1px),
10932
+ linear-gradient(90deg, var(--grid) 1px, transparent 1px);
10933
+ background-size: 48px 48px;
10934
+ mask-image: radial-gradient(ellipse at center, #000, transparent 78%);
10935
+ }
10936
+ main {
10937
+ position: relative;
10938
+ z-index: 1;
10939
+ width: min(400px, 100%);
10940
+ padding: 40px;
10941
+ overflow: hidden;
10942
+ border: 1px solid var(--glass-line);
10943
+ border-radius: 28px;
10944
+ background: var(--glass);
10945
+ box-shadow:
10946
+ 0 28px 80px var(--shadow),
10947
+ 0 0 48px var(--glow),
10948
+ inset 0 1px 0 var(--glass-line);
10949
+ backdrop-filter: blur(24px) saturate(140%);
10950
+ -webkit-backdrop-filter: blur(24px) saturate(140%);
10951
+ text-align: center;
10952
+ animation: arrive 0.45s ease-out both;
10953
+ }
10954
+ main::before {
10955
+ content: "";
10956
+ position: absolute;
10957
+ inset: 0 18% auto;
10958
+ height: 1px;
10959
+ background: linear-gradient(90deg, transparent, var(--primary-a), transparent);
10960
+ opacity: 0.75;
10961
+ }
10962
+ .brand {
10963
+ display: grid;
10964
+ justify-items: center;
10965
+ gap: 16px;
10966
+ }
10967
+ .brand-mark {
10968
+ display: grid;
10969
+ place-items: center;
10970
+ width: 52px;
10971
+ height: 52px;
10972
+ border: 1px solid var(--glass-line);
10973
+ border-radius: 16px;
10974
+ color: var(--on-primary);
10975
+ background: linear-gradient(135deg, var(--primary-a), var(--primary-b));
10976
+ box-shadow: 0 10px 32px var(--glow);
10977
+ }
10978
+ .brand-mark svg {
10979
+ width: 30px;
10980
+ height: 30px;
10981
+ }
10982
+ h1 {
10983
+ margin: 0;
10984
+ font-size: 24px;
10985
+ font-weight: 600;
10986
+ line-height: 1.2;
10987
+ letter-spacing: -0.7px;
10988
+ }
10989
+ form {
10990
+ margin-top: 34px;
10991
+ }
10992
+ .field {
10993
+ position: relative;
10994
+ margin-bottom: 14px;
10995
+ }
10996
+ .field > svg {
10997
+ position: absolute;
10998
+ top: 17px;
10999
+ left: 16px;
11000
+ width: 18px;
11001
+ height: 18px;
11002
+ color: var(--muted);
11003
+ pointer-events: none;
11004
+ }
11005
+ input[type="password"] {
11006
+ display: block;
11007
+ width: 100%;
11008
+ height: 52px;
11009
+ padding: 0 16px 0 46px;
11010
+ border: 1px solid var(--field-line);
11011
+ border-radius: 14px;
11012
+ outline: none;
11013
+ background: var(--field);
11014
+ color: var(--text);
11015
+ font: 15px ui-monospace, SFMono-Regular, Consolas, monospace;
11016
+ letter-spacing: 0.5px;
11017
+ transition:
11018
+ border-color 0.2s,
11019
+ box-shadow 0.2s,
11020
+ background 0.2s;
11021
+ }
11022
+ input::placeholder {
11023
+ color: var(--muted);
11024
+ font-family: Inter, Geist, ui-sans-serif, system-ui, sans-serif;
11025
+ letter-spacing: 0;
11026
+ }
11027
+ input:hover {
11028
+ border-color: var(--focus);
11029
+ }
11030
+ input:focus-visible {
11031
+ border-color: var(--focus);
11032
+ box-shadow: 0 0 0 4px var(--glow);
11033
+ }
11034
+ input[aria-invalid="true"] {
11035
+ border-color: var(--error);
11036
+ }
11037
+ button {
11038
+ width: 100%;
11039
+ min-height: 50px;
11040
+ display: flex;
11041
+ align-items: center;
11042
+ justify-content: center;
11043
+ gap: 10px;
11044
+ border: 1px solid var(--glass-line);
11045
+ border-radius: 14px;
11046
+ background: linear-gradient(135deg, var(--primary-a), var(--primary-b));
11047
+ color: var(--on-primary);
11048
+ font: 600 14px Inter, Geist, ui-sans-serif, system-ui, sans-serif;
11049
+ cursor: pointer;
11050
+ box-shadow: 0 10px 28px var(--glow);
11051
+ transition:
11052
+ transform 0.2s,
11053
+ box-shadow 0.2s,
11054
+ filter 0.2s;
11055
+ }
11056
+ button svg {
11057
+ width: 17px;
11058
+ height: 17px;
11059
+ transition: transform 0.2s;
11060
+ }
11061
+ button:hover {
11062
+ filter: brightness(1.06);
11063
+ transform: translateY(-1px);
11064
+ box-shadow: 0 14px 34px var(--glow);
11065
+ }
11066
+ button:hover svg {
11067
+ transform: translateX(3px);
11068
+ }
11069
+ button:active {
11070
+ transform: translateY(0);
11071
+ }
11072
+ button:focus-visible {
11073
+ outline: 2px solid var(--focus);
11074
+ outline-offset: 4px;
11075
+ }
11076
+ .notice {
11077
+ margin: 0 0 16px;
11078
+ padding: 10px 12px;
11079
+ border: 1px solid var(--error);
11080
+ border-radius: 12px;
11081
+ background: var(--error-bg);
11082
+ color: var(--error);
11083
+ font-size: 12px;
11084
+ line-height: 1.5;
11085
+ text-align: left;
11086
+ }
11087
+ .sr-only {
11088
+ position: absolute;
11089
+ width: 1px;
11090
+ height: 1px;
11091
+ padding: 0;
11092
+ margin: -1px;
11093
+ overflow: hidden;
11094
+ clip-path: inset(50%);
11095
+ white-space: nowrap;
11096
+ border: 0;
11097
+ }
11098
+ @keyframes arrive {
11099
+ from {
11100
+ opacity: 0;
11101
+ transform: translateY(8px);
11102
+ }
11103
+ }
11104
+ @media (max-width: 420px) {
11105
+ body {
11106
+ padding: 18px 14px;
11107
+ }
11108
+ main {
11109
+ padding: 32px 24px;
11110
+ border-radius: 24px;
11111
+ }
11112
+ }
11113
+ @media (prefers-reduced-motion: reduce) {
11114
+ *,
11115
+ *::before,
11116
+ *::after {
11117
+ animation: none !important;
11118
+ transition: none !important;
11119
+ }
11120
+ }
11121
+ @media (forced-colors: active) {
11122
+ body::before,
11123
+ body::after,
11124
+ main::before {
11125
+ display: none;
11126
+ }
11127
+ main,
11128
+ input[type="password"],
11129
+ button,
11130
+ .brand-mark,
11131
+ .notice {
11132
+ border: 1px solid CanvasText;
11133
+ }
11134
+ }
11135
+ `;
11136
+ var AUTH_PAGE_CSP = `default-src 'none'; style-src 'sha256-${createHash9("sha256").update(styles).digest("base64")}'; base-uri 'none'; frame-ancestors 'none'; form-action 'self'`;
11137
+ function escapeAttr(value) {
11138
+ return value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
11139
+ }
11140
+ function renderAuthPage(options) {
11141
+ return `<!doctype html>
11142
+ <html lang="en">
11143
+ <head>
11144
+ <meta charset="utf-8">
11145
+ <meta name="viewport" content="width=device-width, initial-scale=1">
11146
+ <meta name="color-scheme" content="light dark">
11147
+ <title>Cadence</title>
11148
+ <style>${styles}</style>
11149
+ </head>
11150
+ <body>
11151
+ <main aria-labelledby="welcome">
11152
+ <div class="brand">
11153
+ <span class="brand-mark" aria-hidden="true"><svg viewBox="0 0 36 36" fill="none"><path d="M25 11a9 9 0 1 0 0 14M12 18h12" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg></span>
11154
+ <h1 id="welcome">Cadence</h1>
11155
+ </div>
11156
+ ${options.authError ? '<p id="auth-notice" class="notice" role="alert">Invalid access token.</p>' : ""}
11157
+ <form method="post" action="/auth">
11158
+ <input type="hidden" name="next" value="${escapeAttr(options.nextPath)}">
11159
+ <label class="sr-only" for="key">Access token</label>
11160
+ <div class="field">
11161
+ <svg viewBox="0 0 24 24" fill="none" aria-hidden="true"><circle cx="8" cy="9" r="4" stroke="currentColor" stroke-width="1.6"/><path d="m11 12 8 8m-3-3 2-2m-5-1 2-2" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/></svg>
11162
+ <input id="key" name="password" type="password" placeholder="Access token" autocomplete="current-password" required autofocus aria-describedby="key-hint${options.authError ? " auth-notice" : ""}"${options.authError ? ' aria-invalid="true"' : ""}>
11163
+ </div>
11164
+ <p id="key-hint" class="sr-only">Use the token provided by your Cadence server.</p>
11165
+ <button type="submit">Enter<svg viewBox="0 0 24 24" fill="none" aria-hidden="true"><path d="M4 12h15m-6-6 6 6-6 6" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
11166
+ </form>
11167
+ </main>
11168
+ </body>
11169
+ </html>
11170
+ `;
11171
+ }
11172
+
10797
11173
  // src/service/autostart.ts
10798
11174
  import { spawnSync as spawnSync3 } from "node:child_process";
10799
11175
  import {
@@ -12631,7 +13007,7 @@ function decodeStartupReport(value) {
12631
13007
  }
12632
13008
 
12633
13009
  // src/service/self-heal.ts
12634
- import { createHash as createHash9, randomUUID as randomUUID11 } from "node:crypto";
13010
+ import { createHash as createHash10, randomUUID as randomUUID11 } from "node:crypto";
12635
13011
  import { lstatSync as lstatSync13, opendirSync as opendirSync7 } from "node:fs";
12636
13012
  import { hostname as hostname7 } from "node:os";
12637
13013
  import { join as join19 } from "node:path";
@@ -13322,7 +13698,7 @@ function liveReservations(c) {
13322
13698
  return out;
13323
13699
  }
13324
13700
  function projectFiles(c, root) {
13325
- const privateRoot = join19(c.files.namespace, createHash9("sha256").update(root).digest("hex"));
13701
+ const privateRoot = join19(c.files.namespace, createHash10("sha256").update(root).digest("hex"));
13326
13702
  return {
13327
13703
  root,
13328
13704
  privateRoot,
@@ -14535,9 +14911,9 @@ class CadencePreferences {
14535
14911
  }
14536
14912
 
14537
14913
  // src/conversation-identity.ts
14538
- import { createHash as createHash10 } from "node:crypto";
14914
+ import { createHash as createHash11 } from "node:crypto";
14539
14915
  function conversationIdentity(identity) {
14540
- const h = createHash10("sha256").update(identity).digest("hex");
14916
+ const h = createHash11("sha256").update(identity).digest("hex");
14541
14917
  return `${h.slice(0, 8)}-${h.slice(8, 12)}-4${h.slice(13, 16)}-8${h.slice(17, 20)}-${h.slice(20, 32)}`;
14542
14918
  }
14543
14919
 
@@ -15526,7 +15902,7 @@ class ConversationControls {
15526
15902
  }
15527
15903
 
15528
15904
  // src/service/workbench-files.ts
15529
- import { createHash as createHash11 } from "node:crypto";
15905
+ import { createHash as createHash12 } from "node:crypto";
15530
15906
  import {
15531
15907
  closeSync as closeSync7,
15532
15908
  constants as constants7,
@@ -15689,7 +16065,7 @@ class WorkbenchFiles {
15689
16065
  kind: "file-part",
15690
16066
  path,
15691
16067
  size: stat.size,
15692
- version: createHash11("sha256").update(`${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeMs}`).digest("hex").slice(0, 32),
16068
+ version: createHash12("sha256").update(`${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeMs}`).digest("hex").slice(0, 32),
15693
16069
  data: buffer.toString("base64"),
15694
16070
  next: end < stat.size ? end : null
15695
16071
  };
@@ -15899,7 +16275,7 @@ async function readGatewayModels(project, input, secrets, read) {
15899
16275
  }
15900
16276
 
15901
16277
  // src/service/http.ts
15902
- import { createHash as createHash12, randomUUID as randomUUID13 } from "node:crypto";
16278
+ import { createHash as createHash13, randomUUID as randomUUID13 } from "node:crypto";
15903
16279
  import {
15904
16280
  createServer
15905
16281
  } from "node:http";
@@ -15988,7 +16364,7 @@ class ServiceHttpServer {
15988
16364
  this.assets.set(asset.path, {
15989
16365
  ...asset,
15990
16366
  bytes: Uint8Array.from(asset.bytes),
15991
- etag: `"${createHash12("sha256").update(asset.bytes).digest("hex")}"`
16367
+ etag: `"${createHash13("sha256").update(asset.bytes).digest("hex")}"`
15992
16368
  });
15993
16369
  }
15994
16370
  this.server = createServer({
@@ -16216,11 +16592,17 @@ Content-Length: 0\r
16216
16592
  res.destroy();
16217
16593
  }, LIMITS.downloadIdleMs);
16218
16594
  const resetIdle = () => timer.refresh();
16595
+ let boundary;
16596
+ let url;
16219
16597
  try {
16220
- const boundary = requestBoundary(req, this.policy, this.origin);
16598
+ boundary = requestBoundary(req, this.policy, this.origin);
16221
16599
  const target = req.url ?? "";
16222
16600
  assertRequestTarget(target);
16223
- const url = new URL(target, this.origin);
16601
+ url = new URL(target, this.origin);
16602
+ if (target === "/auth" && req.method === "POST") {
16603
+ await this.login(req, res, boundary, abort.signal);
16604
+ return;
16605
+ }
16224
16606
  if (url.searchParams.has("token")) {
16225
16607
  if (req.method !== "GET" || !target.startsWith("/?token=") || [...url.searchParams.keys()].length !== 1)
16226
16608
  throw new ContractError("invalid");
@@ -16237,8 +16619,18 @@ Content-Length: 0\r
16237
16619
  return;
16238
16620
  }
16239
16621
  if (target === "/" && req.method === "GET") {
16240
- res.setHeader("Content-Type", "text/plain; charset=utf-8");
16241
- res.end("Cadence: enter with the private link that `cadence server install` printed, http://127.0.0.1:<CADENCE_PORT>/?token=<CADENCE_TOKEN> from ~/.pi/agent/cadence/.env, or that `cadence token-link --workspace <path> --reveal` prints on this machine.\n");
16622
+ if (!this.accepting)
16623
+ unavailable();
16624
+ try {
16625
+ this.options.auth.authenticate(boundary, randomUUID13(), false);
16626
+ } catch (e) {
16627
+ if (e instanceof ContractError && e.code === "unauthenticated")
16628
+ return this.unauthorized(res, boundary, url);
16629
+ throw e;
16630
+ }
16631
+ res.statusCode = 303;
16632
+ res.setHeader("Location", "/app");
16633
+ res.end();
16242
16634
  return;
16243
16635
  }
16244
16636
  if (target.startsWith("/local/v1/admin/")) {
@@ -16328,6 +16720,10 @@ Content-Length: 0\r
16328
16720
  res.destroy();
16329
16721
  else {
16330
16722
  const code2 = e instanceof ContractError ? e.code : "unavailable";
16723
+ if (code2 === "unauthenticated" && boundary && url) {
16724
+ this.unauthorized(res, boundary, url);
16725
+ return;
16726
+ }
16331
16727
  res.setHeader("Connection", "close");
16332
16728
  send(res, errorStatus(code2), refusal(code2, dispatched && !(e instanceof UnacceptedConversationCommand)));
16333
16729
  }
@@ -16339,6 +16735,59 @@ Content-Length: 0\r
16339
16735
  this.reads--;
16340
16736
  }
16341
16737
  }
16738
+ async login(req, res, boundary, signal) {
16739
+ if (!this.accepting)
16740
+ unavailable();
16741
+ if (!boundary.headers.has("origin"))
16742
+ throw new ContractError("forbidden");
16743
+ if (this.bodies >= LIMITS.admissionCount)
16744
+ throw new ContractError("capacity");
16745
+ this.bodies++;
16746
+ let form;
16747
+ try {
16748
+ form = await readLoginForm(req, signal);
16749
+ } finally {
16750
+ this.bodies--;
16751
+ }
16752
+ if (!this.accepting || signal.aborted)
16753
+ unavailable();
16754
+ const { password: submitted, next } = form;
16755
+ try {
16756
+ res.setHeader("Set-Cookie", this.options.auth.login(submitted, boundary));
16757
+ res.statusCode = 303;
16758
+ res.setHeader("Location", next);
16759
+ res.end();
16760
+ } catch (e) {
16761
+ const code2 = e instanceof ContractError ? e.code : "unavailable";
16762
+ if (code2 === "unauthenticated") {
16763
+ if (this.options.auth.carriesCookie(boundary.headers.get("cookie")))
16764
+ res.setHeader("Set-Cookie", this.options.auth.clearCookie(boundary.secure));
16765
+ res.statusCode = 303;
16766
+ res.setHeader("Location", loginRetryPath(next));
16767
+ res.end();
16768
+ return;
16769
+ }
16770
+ res.setHeader("Connection", "close");
16771
+ send(res, errorStatus(code2), refusal(code2));
16772
+ }
16773
+ }
16774
+ unauthorized(res, boundary, url) {
16775
+ if (this.options.auth.carriesCookie(boundary.headers.get("cookie")))
16776
+ res.setHeader("Set-Cookie", this.options.auth.clearCookie(boundary.secure));
16777
+ if ((boundary.headers.get("accept") ?? "").includes("text/html")) {
16778
+ res.setHeader("Referrer-Policy", "same-origin");
16779
+ res.setHeader("Content-Security-Policy", AUTH_PAGE_CSP);
16780
+ res.setHeader("Content-Type", "text/html; charset=utf-8");
16781
+ res.statusCode = 401;
16782
+ res.end(renderAuthPage({
16783
+ authError: url.searchParams.has("auth_error"),
16784
+ nextPath: loginNextPath(url)
16785
+ }));
16786
+ } else {
16787
+ res.setHeader("Connection", "close");
16788
+ send(res, 401, refusal("unauthenticated"));
16789
+ }
16790
+ }
16342
16791
  async manage(req, res, boundary, signal) {
16343
16792
  const operation = req.url?.slice("/local/v1/admin/".length);
16344
16793
  if (![
@@ -16535,7 +16984,7 @@ Content-Length: 0\r
16535
16984
  res.setHeader("Content-Type", operation === "download" && request2.format === "markdown" ? "text/markdown; charset=utf-8" : "application/x-ndjson; charset=utf-8");
16536
16985
  res.setHeader("Content-Disposition", `attachment; filename="cadence-export.${operation === "download" && request2.format === "markdown" ? "md" : "ndjson"}"`);
16537
16986
  let trailer;
16538
- const digest = createHash12("sha256");
16987
+ const digest = createHash13("sha256");
16539
16988
  const write2 = async (frame) => {
16540
16989
  const data2 = Buffer.from(operation === "download" ? encodeExportFrame(frame, request2.format) : `${canonicalJson(frame)}
16541
16990
  `);
@@ -16773,7 +17222,7 @@ Content-Length: 0\r
16773
17222
 
16774
17223
  // src/service/model-preview-process.ts
16775
17224
  import { spawn as spawn4 } from "node:child_process";
16776
- import { createHash as createHash13 } from "node:crypto";
17225
+ import { createHash as createHash14 } from "node:crypto";
16777
17226
  import { fileURLToPath as fileURLToPath3 } from "node:url";
16778
17227
 
16779
17228
  // src/service/model-preview-protocol.ts
@@ -16823,7 +17272,7 @@ class ModelPreviewProcesses {
16823
17272
  });
16824
17273
  const body = canonicalJson(input, PREVIEW_INPUT_BYTES);
16825
17274
  const env = captureEnvironment(hostEnvironment(environment2));
16826
- const key = createHash13("sha256").update(body).update(JSON.stringify(env)).digest("hex");
17275
+ const key = createHash14("sha256").update(body).update(JSON.stringify(env)).digest("hex");
16827
17276
  const previous = this.jobs.get(key);
16828
17277
  if (previous)
16829
17278
  return previous.result;
@@ -16973,7 +17422,7 @@ async function createGateway(value, hostUrl, source) {
16973
17422
  const input = decodeGatewayInput(value), store = new GatewayStore(input.serverConfig, input.stateHome);
16974
17423
  const web = loadWebAssets(source?.webDirectory);
16975
17424
  const build2 = {
16976
- contractHash: "6aa819700494584b707a8e1b44428c532cd7ac7b1c8a28126e401b43f527543b",
17425
+ contractHash: "d70dd3e63843be7df42ff10943fcdc78bcd27b881b0ac8222526e8dad7b0e6e2",
16977
17426
  assets: {
16978
17427
  sourceHash: web.manifest.sourceHash,
16979
17428
  contractHash: web.manifest.contractHash,
@@ -17425,6 +17874,51 @@ Content-Length: 0\r
17425
17874
  const match = /^\/projects\/([a-f0-9]{64})(\/.*)$/.exec(raw);
17426
17875
  return match ? { id: decodeHash(match[1]), tail: match[2] } : null;
17427
17876
  }
17877
+ async function login(req, res, boundary) {
17878
+ assert();
17879
+ if (!boundary.headers.has("origin"))
17880
+ throw new ContractError("forbidden");
17881
+ const { password: submitted, next } = await readLoginForm(req);
17882
+ assert();
17883
+ try {
17884
+ res.setHeader("Set-Cookie", auth.login(submitted, boundary));
17885
+ res.statusCode = 303;
17886
+ res.setHeader("Location", next);
17887
+ res.end();
17888
+ } catch (e) {
17889
+ const code2 = e instanceof ContractError ? e.code : "unavailable";
17890
+ if (code2 === "unauthenticated") {
17891
+ if (auth.carriesCookie(boundary.headers.get("cookie")))
17892
+ res.setHeader("Set-Cookie", auth.clearCookie(boundary.secure));
17893
+ res.statusCode = 303;
17894
+ res.setHeader("Location", loginRetryPath(next));
17895
+ res.end();
17896
+ return;
17897
+ }
17898
+ res.setHeader("Connection", "close");
17899
+ reply(res, code2 === "forbidden" ? 403 : 400, {
17900
+ kind: "error",
17901
+ error: publicError(code2)
17902
+ });
17903
+ }
17904
+ }
17905
+ function unauthorized(res, boundary, url) {
17906
+ if (auth.carriesCookie(boundary.headers.get("cookie")))
17907
+ res.setHeader("Set-Cookie", auth.clearCookie(boundary.secure));
17908
+ if ((boundary.headers.get("accept") ?? "").includes("text/html")) {
17909
+ res.setHeader("Referrer-Policy", "same-origin");
17910
+ res.setHeader("Content-Security-Policy", AUTH_PAGE_CSP);
17911
+ res.setHeader("Content-Type", "text/html; charset=utf-8");
17912
+ res.statusCode = 401;
17913
+ res.end(renderAuthPage({
17914
+ authError: url.searchParams.has("auth_error"),
17915
+ nextPath: loginNextPath(url)
17916
+ }));
17917
+ } else {
17918
+ res.setHeader("Connection", "close");
17919
+ reply(res, 401, { kind: "error", error: publicError("unauthenticated") });
17920
+ }
17921
+ }
17428
17922
  async function handle(req, res) {
17429
17923
  let effect = false;
17430
17924
  if (++pending > 64) {
@@ -17433,10 +17927,17 @@ Content-Length: 0\r
17433
17927
  return;
17434
17928
  }
17435
17929
  fixedHeaders(res);
17930
+ let boundary;
17931
+ let url;
17436
17932
  try {
17437
- const boundary = requestBoundary(req, input.policy, endpoint2), raw = req.url ?? "";
17933
+ boundary = requestBoundary(req, input.policy, endpoint2);
17934
+ const raw = req.url ?? "";
17438
17935
  assertRequestTarget(raw);
17439
- const url = new URL(raw, endpoint2);
17936
+ url = new URL(raw, endpoint2);
17937
+ if (raw === "/auth" && req.method === "POST") {
17938
+ await login(req, res, boundary);
17939
+ return;
17940
+ }
17440
17941
  if (raw === "/healthz" && req.method === "GET") {
17441
17942
  reply(res, 200, { status: "ok" });
17442
17943
  return;
@@ -17452,8 +17953,16 @@ Content-Length: 0\r
17452
17953
  return;
17453
17954
  }
17454
17955
  if (raw === "/" && req.method === "GET") {
17455
- res.end(`Cadence workbench: open the private link. No default workspace is created.
17456
- `);
17956
+ try {
17957
+ auth.authenticate(boundary, randomUUID14(), false);
17958
+ } catch (e) {
17959
+ if (e instanceof ContractError && e.code === "unauthenticated")
17960
+ return unauthorized(res, boundary, url);
17961
+ throw e;
17962
+ }
17963
+ res.statusCode = 303;
17964
+ res.setHeader("Location", "/app");
17965
+ res.end();
17457
17966
  return;
17458
17967
  }
17459
17968
  if (raw.startsWith("/local/v1/admin/")) {
@@ -17771,6 +18280,8 @@ Content-Length: 0\r
17771
18280
  const code2 = error instanceof ContractError ? error.code : "unavailable";
17772
18281
  if (res.headersSent)
17773
18282
  res.destroy();
18283
+ else if (code2 === "unauthenticated" && boundary && url)
18284
+ unauthorized(res, boundary, url);
17774
18285
  else
17775
18286
  reply(res, code2 === "unauthenticated" ? 401 : code2 === "forbidden" ? 403 : 400, {
17776
18287
  kind: "error",
@@ -17859,7 +18370,7 @@ import { join as join45 } from "node:path";
17859
18370
  import { fileURLToPath as fileURLToPath8 } from "node:url";
17860
18371
 
17861
18372
  // src/agent-registry.ts
17862
- import { createHash as createHash14 } from "node:crypto";
18373
+ import { createHash as createHash15 } from "node:crypto";
17863
18374
  import { fileURLToPath as fileURLToPath5 } from "node:url";
17864
18375
  var AGENT_FILES = [
17865
18376
  "design-explorer.md",
@@ -17876,7 +18387,7 @@ function loadAgentDefinitions() {
17876
18387
  role: fileName.replace(/\.md$/, ""),
17877
18388
  fileName,
17878
18389
  path,
17879
- sha256: createHash14("sha256").update(data2).digest("hex"),
18390
+ sha256: createHash15("sha256").update(data2).digest("hex"),
17880
18391
  bytes: data2.length,
17881
18392
  content: data2.toString("utf8")
17882
18393
  };
@@ -18131,7 +18642,7 @@ class HistoryLive {
18131
18642
  }
18132
18643
 
18133
18644
  // src/history/navigation.ts
18134
- import { createHash as createHash15 } from "node:crypto";
18645
+ import { createHash as createHash16 } from "node:crypto";
18135
18646
  import { lstatSync as lstatSync18 } from "node:fs";
18136
18647
  import { dirname as dirname18, join as join29 } from "node:path";
18137
18648
 
@@ -19358,7 +19869,7 @@ class HistoryNavigation {
19358
19869
  continue;
19359
19870
  }
19360
19871
  let pending = Buffer.alloc(0), at2 = offset, bodyBytes = 0;
19361
- const checksum = createHash15("sha256"), rows = [];
19872
+ const checksum = createHash16("sha256"), rows = [];
19362
19873
  while (at2 < size2) {
19363
19874
  const chunk = this.block(path, at2, size2, budget);
19364
19875
  at2 += chunk.length;
@@ -19861,7 +20372,7 @@ function navigationKeys(row) {
19861
20372
  }
19862
20373
 
19863
20374
  // src/history/projection.ts
19864
- import { createHash as createHash21 } from "node:crypto";
20375
+ import { createHash as createHash22 } from "node:crypto";
19865
20376
 
19866
20377
  // src/history/task-folds.ts
19867
20378
  var TASKS = 1024;
@@ -20204,17 +20715,17 @@ function materializeEntity(s, sources) {
20204
20715
  }
20205
20716
 
20206
20717
  // src/history/export.ts
20207
- import { createHash as createHash19, randomUUID as randomUUID15 } from "node:crypto";
20718
+ import { createHash as createHash20, randomUUID as randomUUID15 } from "node:crypto";
20208
20719
  import { readFileSync as readFileSync5 } from "node:fs";
20209
20720
 
20210
20721
  // src/history/search.ts
20211
- import { createHash as createHash18 } from "node:crypto";
20722
+ import { createHash as createHash19 } from "node:crypto";
20212
20723
 
20213
20724
  // src/history/read-proof.ts
20214
20725
  import {
20215
20726
  createCipheriv,
20216
20727
  createDecipheriv,
20217
- createHash as createHash16,
20728
+ createHash as createHash17,
20218
20729
  randomBytes as randomBytes5
20219
20730
  } from "node:crypto";
20220
20731
  var PREFIX = "rp1.";
@@ -20266,7 +20777,7 @@ class HistoryReadProof {
20266
20777
  root: this.files.format.rootIdentity,
20267
20778
  format: material.formatStamp,
20268
20779
  key: material.keyStamp,
20269
- request: createHash16("sha256").update(canonicalJson(readIdentity(request3))).digest("hex")
20780
+ request: createHash17("sha256").update(canonicalJson(readIdentity(request3))).digest("hex")
20270
20781
  }));
20271
20782
  }
20272
20783
  seal(context, plaintext, budget) {
@@ -21038,11 +21549,11 @@ function decodeRetainedProgress(value) {
21038
21549
  }
21039
21550
 
21040
21551
  // src/history/retained-traversal.ts
21041
- import { createHash as createHash17 } from "node:crypto";
21552
+ import { createHash as createHash18 } from "node:crypto";
21042
21553
  function bad5() {
21043
21554
  throw new ContractError("corrupt-selected");
21044
21555
  }
21045
- var fingerprint = (v) => createHash17("sha256").update(canonicalJson(v)).digest("hex");
21556
+ var fingerprint = (v) => createHash18("sha256").update(canonicalJson(v)).digest("hex");
21046
21557
  var ready = (v) => {
21047
21558
  const s = v.state;
21048
21559
  if (s.phase !== "ready")
@@ -21398,11 +21909,11 @@ var digits = (id) => {
21398
21909
  return s.slice(0, 12) + s.slice(13, 16) + s.slice(17);
21399
21910
  };
21400
21911
  var publicTextRef = (id, label, text2, field, batch, row, slot) => ({
21401
- recordId: uuid(address(batch.pointer).toString(16).padStart(14, "0") + createHash18("sha256").update(`${id}/${label}`).digest("hex").slice(0, 16)),
21912
+ recordId: uuid(address(batch.pointer).toString(16).padStart(14, "0") + createHash19("sha256").update(`${id}/${label}`).digest("hex").slice(0, 16)),
21402
21913
  version: batch.rows.indexOf(row) * EVENT_SLOTS + slot + 1,
21403
21914
  field,
21404
21915
  bytes: Buffer.byteLength(text2),
21405
- sha256: createHash18("sha256").update(text2).digest("hex")
21916
+ sha256: createHash19("sha256").update(text2).digest("hex")
21406
21917
  });
21407
21918
  var initial = () => ({
21408
21919
  pos: { segment: 1, offset: 0 },
@@ -21418,7 +21929,7 @@ function scanCursor(base, p) {
21418
21929
  const snapshot = p.snapshot.toString(16).padStart(14, "0");
21419
21930
  if (snapshot.length !== 14)
21420
21931
  throw new ContractError("capacity");
21421
- const binding = createHash18("sha256").update(canonicalJson({
21932
+ const binding = createHash19("sha256").update(canonicalJson({
21422
21933
  ...readIdentity(base),
21423
21934
  recordId: null,
21424
21935
  recordVersion: version,
@@ -21759,7 +22270,7 @@ class RetainedScan {
21759
22270
  graph: {
21760
22271
  recordId: v.intent.operationId,
21761
22272
  revision: graph.revision,
21762
- sha256: createHash18("sha256").update(canonicalJson(graph)).digest("hex")
22273
+ sha256: createHash19("sha256").update(canonicalJson(graph)).digest("hex")
21763
22274
  }
21764
22275
  },
21765
22276
  graph
@@ -22058,7 +22569,7 @@ async function searchQuantum(reader, value, limit = LIMITS.pageEntries) {
22058
22569
  // src/history/export.ts
22059
22570
  var exporterIdentity;
22060
22571
  function buildIdentity() {
22061
- exporterIdentity ??= createHash19("sha256").update(readFileSync5(new URL(import.meta.url))).digest("hex");
22572
+ exporterIdentity ??= createHash20("sha256").update(readFileSync5(new URL(import.meta.url))).digest("hex");
22062
22573
  return exporterIdentity;
22063
22574
  }
22064
22575
  function aborted(signal) {
@@ -22118,7 +22629,7 @@ Coverage: ${canonicalJson(event.coverage)}
22118
22629
  }
22119
22630
  }
22120
22631
  async function* exportHistory(projection, input, signal) {
22121
- const request3 = decodeExportRequest(input), exportId = randomUUID15(), digest = createHash19("sha256");
22632
+ const request3 = decodeExportRequest(input), exportId = randomUUID15(), digest = createHash20("sha256");
22122
22633
  let ordinal = 0, encodedBytes = 0, coverage = { ...COMPLETE, omissions: [] };
22123
22634
  const frame = (event) => {
22124
22635
  aborted(signal);
@@ -22187,7 +22698,7 @@ async function* exportHistory(projection, input, signal) {
22187
22698
  const { detail, owner } = item, original = open2.get(detail.content.recordId);
22188
22699
  if (detail.content.bytes ? !original || original.bytes !== detail.content.bytes || original.content !== canonicalJson(detail.content) : original !== undefined)
22189
22700
  throw new ContractError("corrupt-selected");
22190
- if ((original?.hash ?? createHash19("sha256")).digest("hex") !== detail.content.sha256)
22701
+ if ((original?.hash ?? createHash20("sha256")).digest("hex") !== detail.content.sha256)
22191
22702
  throw new ContractError("corrupt-selected");
22192
22703
  open2.delete(detail.content.recordId);
22193
22704
  const events = [];
@@ -22218,7 +22729,7 @@ async function* exportHistory(projection, input, signal) {
22218
22729
  coverage = combineCoverage(coverage, item.coverage);
22219
22730
  const length = Buffer.byteLength(item.text);
22220
22731
  if (item.inline) {
22221
- if (item.start !== 0 || length !== item.content.bytes || createHash19("sha256").update(item.text).digest("hex") !== item.content.sha256)
22732
+ if (item.start !== 0 || length !== item.content.bytes || createHash20("sha256").update(item.text).digest("hex") !== item.content.sha256)
22222
22733
  throw new ContractError("corrupt-selected");
22223
22734
  } else {
22224
22735
  let original = open2.get(item.content.recordId);
@@ -22228,7 +22739,7 @@ async function* exportHistory(projection, input, signal) {
22228
22739
  original = {
22229
22740
  bytes: 0,
22230
22741
  content: canonicalJson(item.content),
22231
- hash: createHash19("sha256")
22742
+ hash: createHash20("sha256")
22232
22743
  };
22233
22744
  open2.set(item.content.recordId, original);
22234
22745
  }
@@ -22343,7 +22854,7 @@ async function* exportHistory(projection, input, signal) {
22343
22854
  }
22344
22855
 
22345
22856
  // src/history/list-progress.ts
22346
- import { createHash as createHash20 } from "node:crypto";
22857
+ import { createHash as createHash21 } from "node:crypto";
22347
22858
 
22348
22859
  // src/history/detail-progress.ts
22349
22860
  function bad7() {
@@ -22817,7 +23328,7 @@ function fits(link, scope) {
22817
23328
  return scope.kind === "workspace" || (scope.kind === "task" ? link.taskId === scope.id : scope.kind === "run" ? link.runId === scope.id : link.childRunId === scope.id);
22818
23329
  }
22819
23330
  function nextAfter(request3, n) {
22820
- const h = createHash20("sha256").update(canonicalJson({ ...readIdentity(request3), after: null, ordinal: n })).digest("hex");
23331
+ const h = createHash21("sha256").update(canonicalJson({ ...readIdentity(request3), after: null, ordinal: n })).digest("hex");
22821
23332
  return {
22822
23333
  recordId: `${h.slice(0, 8)}-${h.slice(8, 12)}-4${h.slice(13, 16)}-8${h.slice(17, 20)}-${h.slice(20, 32)}`,
22823
23334
  version: 1,
@@ -23201,7 +23712,7 @@ async function read(p, request3, entity) {
23201
23712
  const tasks = [...p.environment.legacyTasks(budget)].sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
23202
23713
  if (tasks.length > 1000)
23203
23714
  throw new ContractError("capacity");
23204
- const sum = createHash20("sha256");
23715
+ const sum = createHash21("sha256");
23205
23716
  for (const task2 of tasks) {
23206
23717
  budget.reserve(0);
23207
23718
  sum.update(JSON.stringify({
@@ -23214,7 +23725,7 @@ async function read(p, request3, entity) {
23214
23725
  if (s.legacy > tasks.length)
23215
23726
  bad9();
23216
23727
  if (!s.legacyIdentity && request3.after?.version === Number.MAX_SAFE_INTEGER) {
23217
- const h = createHash20("sha256").update(canonicalJson({
23728
+ const h = createHash21("sha256").update(canonicalJson({
23218
23729
  ...readIdentity(request3),
23219
23730
  after: null,
23220
23731
  legacy: s.legacy === 0 ? "begin" : identity,
@@ -23494,7 +24005,7 @@ class HistoryProjection {
23494
24005
  };
23495
24006
  cursor(request3, pos, row, item) {
23496
24007
  const offset = pos.offset * (LIMITS.segmentRecords + 1) * ROW_SLOTS + row * ROW_SLOTS + item;
23497
- const digest = createHash21("sha256").update(canonicalJson({
24008
+ const digest = createHash22("sha256").update(canonicalJson({
23498
24009
  ...readIdentity(request3),
23499
24010
  after: null,
23500
24011
  position: { ...pos, row, item }
@@ -23685,7 +24196,7 @@ class HistoryProjection {
23685
24196
  if (legacyPhase)
23686
24197
  this.navigation.snapshot(snapshot, budget);
23687
24198
  const cursor = (offset2, identity2) => {
23688
- const digest2 = createHash21("sha256").update(canonicalJson({ ...request3, after: null, legacy: identity2, offset: offset2 })).digest("hex");
24199
+ const digest2 = createHash22("sha256").update(canonicalJson({ ...request3, after: null, legacy: identity2, offset: offset2 })).digest("hex");
23689
24200
  return {
23690
24201
  recordId: `${digest2.slice(0, 8)}-${digest2.slice(8, 12)}-4${digest2.slice(13, 16)}-8${digest2.slice(17, 20)}-${digest2.slice(20, 32)}`,
23691
24202
  version: legacyVersion,
@@ -23712,7 +24223,7 @@ class HistoryProjection {
23712
24223
  }
23713
24224
  if (legacy.length > 1000)
23714
24225
  throw new ContractError("capacity");
23715
- const items = [...legacy].sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0), digest = createHash21("sha256");
24226
+ const items = [...legacy].sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0), digest = createHash22("sha256");
23716
24227
  for (const item of items) {
23717
24228
  budget.reserve(0);
23718
24229
  if (Buffer.byteLength(item.goal) > 8192)
@@ -23902,7 +24413,7 @@ class HistoryProjection {
23902
24413
  }
23903
24414
 
23904
24415
  // src/history/reader.ts
23905
- import { createHash as createHash22 } from "node:crypto";
24416
+ import { createHash as createHash23 } from "node:crypto";
23906
24417
  import { existsSync as existsSync3 } from "node:fs";
23907
24418
  import { join as join30 } from "node:path";
23908
24419
 
@@ -24564,7 +25075,7 @@ class HistoryReader {
24564
25075
  }
24565
25076
  }
24566
25077
  const text2 = Buffer.concat(pieces);
24567
- if (end !== detail.content.bytes || createHash22("sha256").update(text2).digest("hex") !== detail.content.sha256)
25078
+ if (end !== detail.content.bytes || createHash23("sha256").update(text2).digest("hex") !== detail.content.sha256)
24568
25079
  return;
24569
25080
  return { detail, bytes: text2 };
24570
25081
  } catch {
@@ -24599,7 +25110,7 @@ class HistoryReader {
24599
25110
  if (!current2 || current2.length < expected.bytes || hash(current2.subarray(0, expected.bytes)) !== expected.identity)
24600
25111
  throw new ContractError("corrupt-selected");
24601
25112
  }
24602
- const checksum = createHash22("sha256");
25113
+ const checksum = createHash23("sha256");
24603
25114
  let bytes = 0;
24604
25115
  let cached;
24605
25116
  for (const e of locator.chunks) {
@@ -24873,16 +25384,16 @@ class HistoryReader {
24873
25384
  }
24874
25385
 
24875
25386
  // src/history/recovery.ts
24876
- import { createHash as createHash26, randomUUID as randomUUID19 } from "node:crypto";
25387
+ import { createHash as createHash27, randomUUID as randomUUID19 } from "node:crypto";
24877
25388
  import { lstatSync as lstatSync19, opendirSync as opendirSync11 } from "node:fs";
24878
25389
  import { join as join34, relative as relative7 } from "node:path";
24879
25390
 
24880
25391
  // src/history/writer.ts
24881
- import { createHash as createHash25, randomUUID as randomUUID18 } from "node:crypto";
25392
+ import { createHash as createHash26, randomUUID as randomUUID18 } from "node:crypto";
24882
25393
  import { join as join33 } from "node:path";
24883
25394
 
24884
25395
  // src/task-store.ts
24885
- import { createHash as createHash23, randomUUID as randomUUID16 } from "node:crypto";
25396
+ import { createHash as createHash24, randomUUID as randomUUID16 } from "node:crypto";
24886
25397
  import {
24887
25398
  closeSync as closeSync8,
24888
25399
  fsyncSync as fsyncSync4,
@@ -24970,7 +25481,7 @@ function recordText(record3) {
24970
25481
  `;
24971
25482
  }
24972
25483
  function contentIdentity(text2) {
24973
- return createHash23("sha256").update(text2).digest("hex");
25484
+ return createHash24("sha256").update(text2).digest("hex");
24974
25485
  }
24975
25486
  function savedRecordIdentity(record3) {
24976
25487
  return contentIdentity(recordText(record3));
@@ -25115,11 +25626,11 @@ function legacyTaskStore(c) {
25115
25626
  }
25116
25627
 
25117
25628
  // src/history/plans.ts
25118
- import { createHash as createHash24, randomUUID as randomUUID17 } from "node:crypto";
25629
+ import { createHash as createHash25, randomUUID as randomUUID17 } from "node:crypto";
25119
25630
  function assertPlanContent(plan, reference, secrets) {
25120
25631
  text(plan, 32768);
25121
25632
  const ref = decodeContentRef(reference);
25122
- if (ref.field !== "plan" || ref.bytes !== Buffer.byteLength(plan) || ref.sha256 !== createHash24("sha256").update(plan).digest("hex") || sanitizeText(plan, secrets) !== plan)
25633
+ if (ref.field !== "plan" || ref.bytes !== Buffer.byteLength(plan) || ref.sha256 !== createHash25("sha256").update(plan).digest("hex") || sanitizeText(plan, secrets) !== plan)
25123
25634
  throw new ContractError("invalid");
25124
25635
  }
25125
25636
  function planRecording(plan, graph, operationId, epoch) {
@@ -26768,7 +27279,7 @@ class HistoryWriter {
26768
27279
  recordId: randomUUID18(),
26769
27280
  version: 1,
26770
27281
  bytes: 0,
26771
- hash: createHash25("sha256"),
27282
+ hash: createHash26("sha256"),
26772
27283
  parts: 0,
26773
27284
  ended: null,
26774
27285
  committedSeq: null
@@ -27146,7 +27657,7 @@ function readOperationStateForPublication(files, operationId) {
27146
27657
  // src/history/recovery.ts
27147
27658
  function digestHistory(files, exclude) {
27148
27659
  files.assertFormat();
27149
- const digest = createHash26("sha256");
27660
+ const digest = createHash27("sha256");
27150
27661
  let count2 = 0;
27151
27662
  const walk = (path, depth) => {
27152
27663
  if (depth > 8 || !files.files.directory(path))
@@ -27258,7 +27769,7 @@ async function healHistory(lease, log) {
27258
27769
 
27259
27770
  // src/subagent-process.ts
27260
27771
  import { spawn as spawn5 } from "node:child_process";
27261
- import { createHash as createHash28, randomUUID as randomUUID22 } from "node:crypto";
27772
+ import { createHash as createHash29, randomUUID as randomUUID22 } from "node:crypto";
27262
27773
  import { join as join36 } from "node:path";
27263
27774
  import { StringDecoder } from "node:string_decoder";
27264
27775
  import { fileURLToPath as fileURLToPath6 } from "node:url";
@@ -27400,7 +27911,7 @@ class RunEnvironment {
27400
27911
  }
27401
27912
 
27402
27913
  // src/worker-capture.mjs
27403
- import { createHash as createHash27, randomUUID as randomUUID21 } from "node:crypto";
27914
+ import { createHash as createHash28, randomUUID as randomUUID21 } from "node:crypto";
27404
27915
  var completeCoverage = () => ({
27405
27916
  observed: "complete",
27406
27917
  source: "complete",
@@ -27503,7 +28014,7 @@ class CaptureState {
27503
28014
  final: null,
27504
28015
  stopReason: null,
27505
28016
  finalIndices: new Set,
27506
- finalHash: createHash27("sha256"),
28017
+ finalHash: createHash28("sha256"),
27507
28018
  finalBytes: 0,
27508
28019
  finalIndex: -1
27509
28020
  });
@@ -27530,7 +28041,7 @@ class CaptureState {
27530
28041
  }
27531
28042
  this.details.set(e.detailId, {
27532
28043
  descriptor: e.descriptor,
27533
- hash: createHash27("sha256"),
28044
+ hash: createHash28("sha256"),
27534
28045
  bytes: 0,
27535
28046
  ended: false,
27536
28047
  preview: ""
@@ -28591,7 +29102,7 @@ function launchConversation(prepared, conversation, signal, options) {
28591
29102
  const imageInput = options.images?.length ? JSON.stringify(options.images) : undefined;
28592
29103
  const imageDescriptor = imageInput === undefined ? undefined : {
28593
29104
  bytes: Buffer.byteLength(imageInput),
28594
- sha256: createHash28("sha256").update(imageInput).digest("hex")
29105
+ sha256: createHash29("sha256").update(imageInput).digest("hex")
28595
29106
  };
28596
29107
  return prepared.consume((material) => {
28597
29108
  encoded2 = encodeEnvelope({
@@ -30269,7 +30780,7 @@ For follow-up to a settled or interrupted run, inspect retained outcomes first.
30269
30780
 
30270
30781
  // src/service/project-knowledge.ts
30271
30782
  import { isUtf8 } from "node:buffer";
30272
- import { createHash as createHash30 } from "node:crypto";
30783
+ import { createHash as createHash31 } from "node:crypto";
30273
30784
  import {
30274
30785
  closeSync as closeSync11,
30275
30786
  constants as constants11,
@@ -30287,7 +30798,7 @@ import { dirname as dirname22, posix } from "node:path";
30287
30798
 
30288
30799
  // src/service/workflow-git.ts
30289
30800
  import { spawn as spawn6, spawnSync as spawnSync6 } from "node:child_process";
30290
- import { createHash as createHash29 } from "node:crypto";
30801
+ import { createHash as createHash30 } from "node:crypto";
30291
30802
  import {
30292
30803
  closeSync as closeSync10,
30293
30804
  constants as constants10,
@@ -30449,7 +30960,7 @@ function fileIdentity(p, st, hashBytes) {
30449
30960
  try {
30450
30961
  if (!fstatSync7(fd).isFile())
30451
30962
  throw new ContractError("stale");
30452
- const digest = createHash29("sha256"), buffer = Buffer.alloc(CHUNK);
30963
+ const digest = createHash30("sha256"), buffer = Buffer.alloc(CHUNK);
30453
30964
  for (let n = readSync6(fd, buffer);n > 0; n = readSync6(fd, buffer))
30454
30965
  digest.update(buffer.subarray(0, n));
30455
30966
  return `sha256:${digest.digest("hex")}`;
@@ -30476,7 +30987,7 @@ async function fileIdentityAsync(p, st, hashBytes, signal) {
30476
30987
  const same2 = (a, b) => a.isFile() && b.isFile() && a.dev === b.dev && a.ino === b.ino && a.size === b.size && a.mtimeMs === b.mtimeMs && a.ctimeMs === b.ctimeMs;
30477
30988
  if (!same2(st, before))
30478
30989
  throw new ContractError("stale");
30479
- const digest = createHash29("sha256"), buffer = Buffer.alloc(CHUNK);
30990
+ const digest = createHash30("sha256"), buffer = Buffer.alloc(CHUNK);
30480
30991
  let remaining = before.size;
30481
30992
  while (remaining > 0) {
30482
30993
  if (signal?.aborted)
@@ -31217,7 +31728,7 @@ ${line}`;
31217
31728
  `);
31218
31729
  }
31219
31730
  var roots = ["engineering", "docs", ".trellis/spec", ".cadence/knowledge"];
31220
- var digest = (s) => createHash30("sha256").update(s).digest("hex");
31731
+ var digest = (s) => createHash31("sha256").update(s).digest("hex");
31221
31732
  var markdown2 = (p) => /\.md$/iu.test(p) && !/^(?:\.cadence\/assistant|\.trellis\/(?:workspace|tasks))(?:\/|$)/u.test(p) && !p.split("/").some((part) => part === ".." || part === ".git" || part === "node_modules" || part.startsWith(".env") || part.startsWith(".") && part !== ".cadence" && part !== ".trellis");
31222
31733
  function readKnowledgeFile(root, path) {
31223
31734
  if (!markdown2(path))
@@ -32856,14 +33367,14 @@ import { fileURLToPath as fileURLToPath7 } from "node:url";
32856
33367
 
32857
33368
  // src/task-diff.ts
32858
33369
  import { spawnSync as spawnSync7 } from "node:child_process";
32859
- import { createHash as createHash31 } from "node:crypto";
33370
+ import { createHash as createHash32 } from "node:crypto";
32860
33371
  import { lstatSync as lstatSync25, readdirSync as readdirSync5, readlinkSync as readlinkSync2 } from "node:fs";
32861
33372
  import { join as join41, relative as relative10 } from "node:path";
32862
33373
  var admin = (path) => path === ".cadence/assistant/tasks" || path.startsWith(".cadence/assistant/tasks/");
32863
33374
  var GIT_OUTPUT_BYTES = 16 * 1024 * 1024;
32864
33375
  function captureChanges(root, outputBytes = GIT_OUTPUT_BYTES) {
32865
33376
  const deadline = Date.now() + 3000;
32866
- const hash3 = createHash31("sha256");
33377
+ const hash3 = createHash32("sha256");
32867
33378
  const parts = [];
32868
33379
  let complete = true;
32869
33380
  const limits = [];
@@ -32921,7 +33432,7 @@ function captureChanges(root, outputBytes = GIT_OUTPUT_BYTES) {
32921
33432
  fileBytes += data2.length;
32922
33433
  add(name, data2);
32923
33434
  const binary = data2.includes(0);
32924
- parts.push(`${name} (${binary ? "binary" : "text"}, ${data2.length} bytes, sha256 ${createHash31("sha256").update(data2).digest("hex")})`);
33435
+ parts.push(`${name} (${binary ? "binary" : "text"}, ${data2.length} bytes, sha256 ${createHash32("sha256").update(data2).digest("hex")})`);
32925
33436
  } catch {
32926
33437
  complete = false;
32927
33438
  limits.push(`Unreadable/changing: ${name}`);
@@ -33097,7 +33608,7 @@ function executionDirectory(execution, tree) {
33097
33608
  }
33098
33609
 
33099
33610
  // src/service/investigations.ts
33100
- import { createHash as createHash32 } from "node:crypto";
33611
+ import { createHash as createHash33 } from "node:crypto";
33101
33612
  import { readFileSync as readFileSync7, statSync as statSync4 } from "node:fs";
33102
33613
  var INVESTIGATIONS = {
33103
33614
  cited: 32,
@@ -33113,7 +33624,7 @@ function fileDigest(root, path) {
33113
33624
  const st = statSync4(file);
33114
33625
  if (!st.isFile() || st.size > INVESTIGATIONS.fileBytes)
33115
33626
  return null;
33116
- return createHash32("sha256").update(readFileSync7(file)).digest("hex");
33627
+ return createHash33("sha256").update(readFileSync7(file)).digest("hex");
33117
33628
  } catch {
33118
33629
  return null;
33119
33630
  }
@@ -33141,14 +33652,14 @@ function changedFiles(root, files) {
33141
33652
  return files.filter((file) => fileDigest(root, file.path) !== file.digest).map((file) => file.path);
33142
33653
  }
33143
33654
  function questionKey(question, roots2) {
33144
- return createHash32("sha256").update(JSON.stringify([
33655
+ return createHash33("sha256").update(JSON.stringify([
33145
33656
  question.trim().replace(/\s+/gu, " "),
33146
33657
  [...roots2 ?? []].sort()
33147
33658
  ])).digest("hex");
33148
33659
  }
33149
33660
 
33150
33661
  // src/service/workflow-controller.ts
33151
- import { createHash as createHash33 } from "node:crypto";
33662
+ import { createHash as createHash34 } from "node:crypto";
33152
33663
  var RECOVERY_BYTES = 32768;
33153
33664
 
33154
33665
  class AttemptFailure extends Error {
@@ -33457,7 +33968,7 @@ class DeliveryController {
33457
33968
  this.ports.assertRunning();
33458
33969
  if (decision.action === "blocked")
33459
33970
  break;
33460
- const fingerprint2 = createHash33("sha256").update(canonicalJson({
33971
+ const fingerprint2 = createHash34("sha256").update(canonicalJson({
33461
33972
  stage,
33462
33973
  observation,
33463
33974
  failure: attempt2.identity ?? attempt2.message.replace(/[0-9a-f]{8}-[0-9a-f-]{27,}/gu, "<step>"),
@@ -34404,8 +34915,8 @@ function workflowResultDetail(value, secrets) {
34404
34915
  var runtimeSummary = (runtime) => `${describeWorkerRuntime(runtime)}
34405
34916
  ${RUN_ENVIRONMENT_POLICY}`;
34406
34917
  var OWNER_RUNTIME = Object.freeze({
34407
- version: "2.1.8",
34408
- build: "130758d2c50a6fc52bba2e6de5744a7fbd4b81e20bf5841a7db317a9a4056a99",
34918
+ version: "2.1.10",
34919
+ build: "9d5c50c9e4c178870b59c8c2efd9c0fbaabd00b8eb9c1ca57f5594890e208065",
34409
34920
  entry: fileURLToPath7(import.meta.url),
34410
34921
  pid: process.pid,
34411
34922
  node: process.versions.node,
@@ -37309,7 +37820,7 @@ var processLifetime = {
37309
37820
  }
37310
37821
  };
37311
37822
  async function createServiceHost(value, sourceBuild, lifetime) {
37312
- const embedded = "6aa819700494584b707a8e1b44428c532cd7ac7b1c8a28126e401b43f527543b";
37823
+ const embedded = "d70dd3e63843be7df42ff10943fcdc78bcd27b881b0ac8222526e8dad7b0e6e2";
37313
37824
  if (embedded && sourceBuild)
37314
37825
  throw new ContractError("unsupported-context");
37315
37826
  const contractHash = decodeHash(embedded ?? sourceBuild?.contractHash);