@cmmd-center/forge 0.13.137 → 0.13.139

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bin.cjs CHANGED
@@ -12,7 +12,7 @@ const require_Cache = require("./Cache-D-JaJz5Q.cjs");
12
12
  const require_SqlError = require("./SqlError-BqOsoG0V.cjs");
13
13
  const require_Mime = require("./Mime-Bilnh8zE.cjs");
14
14
  const require_esm = require("./esm-BZhXwX5p.cjs");
15
- const require_runtimeControlAuthority = require("./runtimeControlAuthority-DCitZFTk.cjs");
15
+ const require_runtimeControlAuthority = require("./runtimeControlAuthority-D380Wxs0.cjs");
16
16
  const require_PTY = require("./PTY-C8ypptmz.cjs");
17
17
  const require_settle = require("./settle-B6Rn65UV.cjs");
18
18
  let node_child_process = require("node:child_process");
@@ -66431,7 +66431,7 @@ function normalizeNumberish(value) {
66431
66431
  }
66432
66432
  //#endregion
66433
66433
  //#region package.json
66434
- var version$1 = "0.13.137";
66434
+ var version$1 = "0.13.139";
66435
66435
  //#endregion
66436
66436
  //#region src/sentry.ts
66437
66437
  const SERVER_APP_NAME = "forge-server";
@@ -292019,6 +292019,51 @@ async function maybeRefreshRuntimeProvisioningGrant(input) {
292019
292019
  return "refreshed";
292020
292020
  }
292021
292021
  //#endregion
292022
+ //#region src/runtimeAuth/SidekickHeartbeatAuthorityInstaller.ts
292023
+ const SIDEKICK_HEARTBEAT_OWNER_ID = "runtime-heartbeat";
292024
+ function verifySidekickHeartbeatTicket(ticket, identity) {
292025
+ const claims = require_runtimeControlAuthority.verifyCmmdRuntimeTicket(ticket.token, identity);
292026
+ if (claims === null || claims.scope.length !== 1 || claims.scope[0] !== "sidekick" || claims.machineId !== identity.machineId || claims.credentialEpoch !== identity.credentialEpoch || Date.parse(ticket.expiresAt) !== claims.expiresAtSeconds * 1e3) return null;
292027
+ return claims;
292028
+ }
292029
+ /**
292030
+ * Verifies and installs a `sidekickAuthority` ticket the runtime control
292031
+ * heartbeat delivered (CMMD#5945, forge#3594) into the SAME
292032
+ * `runtimeBrokerAuthority` cache `resolveWorkSessionSidekickRuntimeGrant`
292033
+ * (`cmmdWorkSessionCapabilityBroker.ts`) reads for the Work Session
292034
+ * capability broker. Without this, that cache holds only the original kick
292035
+ * ticket's `sidekick` scope, which expires 15 minutes into a turn with
292036
+ * nothing to replace it — any re-mint of the delegated Sidekick-tool
292037
+ * capability past that point fails closed with `CMMD_AUTH_REQUIRED`. The
292038
+ * 30-second heartbeat tick calling this re-installs a fresh one long before
292039
+ * that TTL is ever in danger.
292040
+ *
292041
+ * Uses the synthetic session id `cmmd-runtime:<runtimeId>:<userId>` — the
292042
+ * SAME one `PipelineProviderAuthorityInstaller` installs `provider`
292043
+ * authority under for automation runs. `readRuntimeBrokerAuthorityForRuntime`
292044
+ * scans every session for a runtime regardless of which one recorded it, so
292045
+ * sharing the id costs nothing and keeps one fewer synthetic session alive
292046
+ * per runtime.
292047
+ *
292048
+ * Never throws: a malformed or wrongly-scoped ticket is a bug on CMMD's side
292049
+ * or a corrupted response in flight, not a reason to crash the heartbeat
292050
+ * loop that is this runtime's own path back to a healthy state. Returns
292051
+ * whether anything was actually installed, purely for logging/tests — the
292052
+ * heartbeat loop that calls this must never let a `false` here interrupt the
292053
+ * heartbeat itself.
292054
+ */
292055
+ function installSidekickHeartbeatAuthority(input) {
292056
+ if (input.ticket === null) return false;
292057
+ const claims = verifySidekickHeartbeatTicket(input.ticket, input.identity);
292058
+ if (claims === null) return false;
292059
+ return recordRuntimeBrokerAuthority({
292060
+ sessionId: AuthSessionId.make(`cmmd-runtime:${input.identity.runtimeId}:${input.identity.userId}`),
292061
+ ownerId: SIDEKICK_HEARTBEAT_OWNER_ID,
292062
+ token: input.ticket.token,
292063
+ claims
292064
+ }).installed;
292065
+ }
292066
+ //#endregion
292022
292067
  //#region src/runtimeDrain/RuntimeDrainReporter.ts
292023
292068
  const HEARTBEAT_INTERVAL = require_Schema$1.seconds(30);
292024
292069
  const HEARTBEAT_TICK_TIMEOUT = require_Schema$1.seconds(60);
@@ -292035,6 +292080,30 @@ function runtimeHeartbeatConfig(config) {
292035
292080
  credentialEpoch
292036
292081
  };
292037
292082
  }
292083
+ /**
292084
+ * The full exact-machine identity `installSidekickHeartbeatAuthority` needs
292085
+ * to verify a delivered `sidekickAuthority` ticket — a superset of
292086
+ * `runtimeHeartbeatConfig` (which the heartbeat request itself needs) with
292087
+ * org, user and the verification public key added, the same fields
292088
+ * `PipelineProviderAuthorityInstaller.ts`'s `resolveExactRuntimeIdentity`
292089
+ * requires for the `provider` scope. Null on any missing field: a runtime
292090
+ * without a complete exact identity gets no `sidekick` re-delivery, exactly
292091
+ * as it gets no control heartbeat at all from `runtimeHeartbeatConfig`.
292092
+ */
292093
+ function sidekickHeartbeatIdentityConfig(config) {
292094
+ const heartbeatConfig = runtimeHeartbeatConfig(config);
292095
+ if (!heartbeatConfig) return null;
292096
+ const orgId = config.forgeCmmdRuntimeOrgId?.trim();
292097
+ const userId = config.forgeCmmdRuntimeUserId?.trim();
292098
+ const publicKeyPem = config.forgeCmmdRuntimePublicKey?.trim();
292099
+ if (!orgId || !userId || !publicKeyPem) return null;
292100
+ return {
292101
+ ...heartbeatConfig,
292102
+ orgId,
292103
+ userId,
292104
+ publicKeyPem
292105
+ };
292106
+ }
292038
292107
  function runtimeGrantRefreshConfig(config) {
292039
292108
  if (config.forgeCmmdRuntimeMode !== true) return null;
292040
292109
  const runtimeId = config.forgeCmmdRuntimeId?.trim();
@@ -292088,12 +292157,21 @@ const makeRuntimeDrainReporter = require_Schema$1.gen(function* () {
292088
292157
  const spriteTaskHoldReactor = yield* SpriteTaskHoldReactor;
292089
292158
  const reportSemaphore = yield* require_Path.make$5(1);
292090
292159
  let heartbeatSilent = false;
292091
- const applyControlPlaneState = (runtime) => drainState.applyControlPlaneState({
292092
- draining: runtime.draining,
292093
- drainReason: runtime.drainReason,
292094
- drainTargetImageRef: runtime.drainTargetImageRef,
292095
- drainTargetImageVersion: runtime.drainTargetImageVersion,
292096
- drainForceRequired: runtime.drainForceRequired
292160
+ const applyControlPlaneState = (runtime) => require_Schema$1.gen(function* () {
292161
+ yield* drainState.applyControlPlaneState({
292162
+ draining: runtime.draining,
292163
+ drainReason: runtime.drainReason,
292164
+ drainTargetImageRef: runtime.drainTargetImageRef,
292165
+ drainTargetImageVersion: runtime.drainTargetImageVersion,
292166
+ drainForceRequired: runtime.drainForceRequired
292167
+ });
292168
+ const sidekickIdentity = sidekickHeartbeatIdentityConfig(serverConfig);
292169
+ if (sidekickIdentity) yield* require_Schema$1.sync(() => {
292170
+ installSidekickHeartbeatAuthority({
292171
+ identity: sidekickIdentity,
292172
+ ticket: runtime.sidekickAuthority
292173
+ });
292174
+ });
292097
292175
  });
292098
292176
  const refreshProvisioningGrantIfNeeded = require_Schema$1.gen(function* () {
292099
292177
  const grantConfig = runtimeGrantRefreshConfig(serverConfig);
@@ -300696,7 +300774,7 @@ function resolveBuildCommitFromEnv(env) {
300696
300774
  * environment descriptor down instead of reporting an honest "unknown".
300697
300775
  */
300698
300776
  function readBakedBuildCommit() {
300699
- return "bcd01e1ae34a37fd182605061608b45892800be2";
300777
+ return "32a98ec9fa40612b5a3e5e87a9c1398870b6a0a3";
300700
300778
  }
300701
300779
  async function resolveServerBuildCommit(input) {
300702
300780
  if (isFullCommitSha(input.baked)) return input.baked;
package/dist/bin.mjs CHANGED
@@ -11,7 +11,7 @@ import { a as make$51, i as keys, n as getOption, o as makeWith$1, r as invalida
11
11
  import { S as layer$9, _ as defaultEscape, a as DeadlockError, b as makeCompiler$1, c as SqlError, d as UnknownError, g as custom, h as make$52, i as ConstraintError, l as SqlSyntaxError, m as SqlClient, n as AuthorizationError, o as LockTimeoutError, r as ConnectionError, s as SerializationError, t as AuthenticationError, u as StatementTimeoutError, v as defaultTransforms, y as fragment } from "./SqlError-BBR7DPrQ.mjs";
12
12
  import { r as wrapper_default, t as Mime_default } from "./Mime-Dq9IoNiV.mjs";
13
13
  import { a as diag, c as SpanKind$1, d as TraceFlags, f as ROOT_CONTEXT, i as propagation, l as isSpanContextValid, m as DiagLogLevel, n as init_esm$1, o as context$1, p as createContextKey, r as trace, s as SpanStatusCode, t as esm_exports$1 } from "./esm-wLIF-u3N.mjs";
14
- import { a as verifyCmmdAuthRuntimeTicket, c as verifyCmmdRuntimeTicket, d as runtimeGrantToken, f as setRuntimeGrantToken, i as sendRuntimeControlHeartbeat, l as verifyCmmdRuntimeTicketRefreshProof, n as bootstrapRuntimeControlAuthorityFromNarrowGrant, o as verifyCmmdClaudeReadinessTicket, p as createReadOnceFileTokenAccessor, r as readRuntimeControlAuthority, s as verifyCmmdClaudeUsageTicket, t as bootstrapRuntimeControlAuthority, u as verifyCmmdScopedRuntimePayload } from "./runtimeControlAuthority-DpRIoWqP.mjs";
14
+ import { a as verifyCmmdAuthRuntimeTicket, c as verifyCmmdRuntimeTicket, d as runtimeGrantToken, f as setRuntimeGrantToken, i as sendRuntimeControlHeartbeat, l as verifyCmmdRuntimeTicketRefreshProof, n as bootstrapRuntimeControlAuthorityFromNarrowGrant, o as verifyCmmdClaudeReadinessTicket, p as createReadOnceFileTokenAccessor, r as readRuntimeControlAuthority, s as verifyCmmdClaudeUsageTicket, t as bootstrapRuntimeControlAuthority, u as verifyCmmdScopedRuntimePayload } from "./runtimeControlAuthority-BtHvsEIc.mjs";
15
15
  import { n as PtySpawnError, t as PtyAdapter } from "./PTY-BRT13Y8S.mjs";
16
16
  import { t as settleValueWithin } from "./settle-BJcmpbvq.mjs";
17
17
  import { createRequire } from "node:module";
@@ -23,7 +23,7 @@ import { createCipheriv, createDecipheriv, createHash, createHmac, createPublicK
23
23
  import * as FS$1 from "node:fs";
24
24
  import fs, { accessSync, chmodSync, constants, createReadStream, existsSync, mkdirSync, mkdtempSync, promises, readFile, readFileSync, readdir, readdirSync, realpathSync, rmSync, statSync, unlinkSync, writeFileSync } from "node:fs";
25
25
  import * as NodeOS from "node:os";
26
- import os, { homedir, networkInterfaces, tmpdir } from "node:os";
26
+ import $U, { homedir, networkInterfaces, tmpdir } from "node:os";
27
27
  import * as Path$1 from "node:path";
28
28
  import path, { basename, delimiter, dirname, extname, isAbsolute, join, posix, relative, resolve, sep } from "node:path";
29
29
  import { pathToFileURL } from "node:url";
@@ -50751,7 +50751,7 @@ function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
50751
50751
  const min = forceColor || 0;
50752
50752
  if (env.TERM === "dumb") return min;
50753
50753
  if (process$1.platform === "win32") {
50754
- const osRelease = os.release().split(".");
50754
+ const osRelease = $U.release().split(".");
50755
50755
  if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) return Number(osRelease[2]) >= 14931 ? 3 : 2;
50756
50756
  return 1;
50757
50757
  }
@@ -53194,7 +53194,7 @@ var require_ProcessDetector = /* @__PURE__ */ __commonJSMin(((exports) => {
53194
53194
  exports.processDetector = void 0;
53195
53195
  const api_1 = (init_esm$1(), __toCommonJS(esm_exports$1));
53196
53196
  const semconv_1 = require_semconv$1();
53197
- const os$4 = __require("os");
53197
+ const os$3 = __require("os");
53198
53198
  /**
53199
53199
  * ProcessDetector will be used to detect the resources related current process running
53200
53200
  * and being instrumented from the NodeJS Process module.
@@ -53216,7 +53216,7 @@ var require_ProcessDetector = /* @__PURE__ */ __commonJSMin(((exports) => {
53216
53216
  };
53217
53217
  if (process.argv.length > 1) attributes[semconv_1.ATTR_PROCESS_COMMAND] = process.argv[1];
53218
53218
  try {
53219
- const userInfo = os$4.userInfo();
53219
+ const userInfo = os$3.userInfo();
53220
53220
  attributes[semconv_1.ATTR_PROCESS_OWNER] = userInfo.username;
53221
53221
  } catch (e) {
53222
53222
  api_1.diag.debug(`error obtaining process owner: ${e}`);
@@ -66139,7 +66139,7 @@ function normalizeNumberish(value) {
66139
66139
  }
66140
66140
  //#endregion
66141
66141
  //#region package.json
66142
- var version$1 = "0.13.137";
66142
+ var version$1 = "0.13.139";
66143
66143
  //#endregion
66144
66144
  //#region src/sentry.ts
66145
66145
  const SERVER_APP_NAME = "forge-server";
@@ -75906,7 +75906,7 @@ var require_node_gyp_build = /* @__PURE__ */ __commonJSMin(((exports, module) =>
75906
75906
  var fs$6 = __require("fs");
75907
75907
  var path$5 = __require("path");
75908
75908
  var url$1 = __require("url");
75909
- var os$3 = __require("os");
75909
+ var os$2 = __require("os");
75910
75910
  var runtimeRequire = typeof __webpack_require__ === "function" ? __non_webpack_require__ : __require;
75911
75911
  var vars = process.config && process.config.variables || {};
75912
75912
  var prebuildsOnly = !!process.env.PREBUILDS_ONLY;
@@ -75914,8 +75914,8 @@ var require_node_gyp_build = /* @__PURE__ */ __commonJSMin(((exports, module) =>
75914
75914
  var abi = versions.modules;
75915
75915
  if (versions.deno || process.isBun) abi = "unsupported";
75916
75916
  var runtime = isElectron() ? "electron" : isNwjs() ? "node-webkit" : "node";
75917
- var arch = process.env.npm_config_arch || os$3.arch();
75918
- var platform = process.env.npm_config_platform || os$3.platform();
75917
+ var arch = process.env.npm_config_arch || os$2.arch();
75918
+ var platform = process.env.npm_config_platform || os$2.platform();
75919
75919
  var libc = process.env.LIBC || (isMusl(platform) ? "musl" : "glibc");
75920
75920
  var armv = process.env.ARM_VERSION || (arch === "arm64" ? "8" : vars.arm_version) || "";
75921
75921
  var uv = (versions.uv || "").split(".")[0];
@@ -93759,7 +93759,7 @@ const launchDetached = (launch) => gen(function* () {
93759
93759
  });
93760
93760
  const OpenLive = effect(Open, gen(function* () {
93761
93761
  const open = yield* tryPromise({
93762
- try: () => import("./open-yHTUkd2Y.mjs"),
93762
+ try: () => import("./open-2-reBrpv.mjs"),
93763
93763
  catch: (cause) => new OpenError$1({
93764
93764
  message: "failed to load browser opener",
93765
93765
  cause
@@ -192145,7 +192145,7 @@ var Vce = {
192145
192145
  function Ve() {
192146
192146
  return Vce;
192147
192147
  }
192148
- var Us = os.homedir(), lk = os.tmpdir(), { env: Vc } = process$1, Yce = (e) => {
192148
+ var Us = $U.homedir(), lk = $U.tmpdir(), { env: Vc } = process$1, Yce = (e) => {
192149
192149
  let t = path.join(Us, "Library");
192150
192150
  return {
192151
192151
  data: path.join(t, "Application Support", e),
@@ -202345,12 +202345,12 @@ function qZ(e, t) {
202345
202345
  }
202346
202346
  return n;
202347
202347
  }
202348
- var os$2 = "https://code.claude.com/docs/en", kKe = [
202348
+ var os$1 = "https://code.claude.com/docs/en", kKe = [
202349
202349
  {
202350
202350
  matches: (e) => e.path === "permissions.defaultMode" && e.code === "invalid_value",
202351
202351
  tip: {
202352
202352
  suggestion: "Valid modes: \"acceptEdits\" (ask before file changes), \"plan\" (analysis only), \"bypassPermissions\" (auto-accept all), or \"default\" (standard behavior)",
202353
- docLink: `${os$2}/iam#permission-modes`
202353
+ docLink: `${os$1}/iam#permission-modes`
202354
202354
  }
202355
202355
  },
202356
202356
  {
@@ -202365,7 +202365,7 @@ var os$2 = "https://code.claude.com/docs/en", kKe = [
202365
202365
  matches: (e) => e.path.startsWith("env.") && e.code === "invalid_type",
202366
202366
  tip: {
202367
202367
  suggestion: "Environment variables must be strings. Wrap numbers and booleans in quotes. Example: \"DEBUG\": \"true\", \"PORT\": \"3000\"",
202368
- docLink: `${os$2}/settings#environment-variables`
202368
+ docLink: `${os$1}/settings#environment-variables`
202369
202369
  }
202370
202370
  },
202371
202371
  {
@@ -202376,14 +202376,14 @@ var os$2 = "https://code.claude.com/docs/en", kKe = [
202376
202376
  matches: (e) => e.path.startsWith("hooks.") && e.code === "invalid_key",
202377
202377
  tip: {
202378
202378
  suggestion: "Not a recognized hook event. Common events: PreToolUse, PostToolUse, UserPromptSubmit, SessionStart, SessionEnd, Stop. Check spelling and capitalization.",
202379
- docLink: `${os$2}/hooks`
202379
+ docLink: `${os$1}/hooks`
202380
202380
  }
202381
202381
  },
202382
202382
  {
202383
202383
  matches: (e) => /\.hooks\.\d+\.command$/.test(e.path) && e.code === "invalid_type" && e.received === "undefined",
202384
202384
  tip: {
202385
202385
  suggestion: "Command hooks require `command`. For exec form (no shell), set `command` to the executable and `args` to its arguments: {\"type\": \"command\", \"command\": \"echo\", \"args\": [\"hi\"]}. For shell form, set `command` to the full shell string: {\"type\": \"command\", \"command\": \"echo hi\"}.",
202386
- docLink: `${os$2}/hooks#exec-form-and-shell-form`
202386
+ docLink: `${os$1}/hooks#exec-form-and-shell-form`
202387
202387
  }
202388
202388
  },
202389
202389
  {
@@ -202398,7 +202398,7 @@ var os$2 = "https://code.claude.com/docs/en", kKe = [
202398
202398
  matches: (e) => e.code === "unrecognized_keys",
202399
202399
  tip: {
202400
202400
  suggestion: "Check for typos or refer to the documentation for valid fields",
202401
- docLink: `${os$2}/settings`
202401
+ docLink: `${os$1}/settings`
202402
202402
  }
202403
202403
  },
202404
202404
  {
@@ -202413,13 +202413,13 @@ var os$2 = "https://code.claude.com/docs/en", kKe = [
202413
202413
  matches: (e) => e.path === "permissions.additionalDirectories" && e.code === "invalid_type",
202414
202414
  tip: {
202415
202415
  suggestion: "Must be an array of directory paths. Example: [\"~/projects\", \"/tmp/workspace\"]. You can also use --add-dir flag or /add-dir command",
202416
- docLink: `${os$2}/iam#working-directories`
202416
+ docLink: `${os$1}/iam#working-directories`
202417
202417
  }
202418
202418
  }
202419
202419
  ], AKe = {
202420
- permissions: `${os$2}/iam#configuring-permissions`,
202421
- env: `${os$2}/settings#environment-variables`,
202422
- hooks: `${os$2}/hooks`
202420
+ permissions: `${os$1}/iam#configuring-permissions`,
202421
+ env: `${os$1}/settings#environment-variables`,
202422
+ hooks: `${os$1}/hooks`
202423
202423
  };
202424
202424
  function GZ(e) {
202425
202425
  let t = kKe.find((r) => r.matches(e));
@@ -271207,7 +271207,7 @@ var import_multicast_dns = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMi
271207
271207
  var dgram = __require("dgram");
271208
271208
  var thunky = require_thunky();
271209
271209
  var events = __require("events");
271210
- var os$1 = __require("os");
271210
+ var os = __require("os");
271211
271211
  var noop = function() {};
271212
271212
  module.exports = function(opts) {
271213
271213
  if (!opts) opts = {};
@@ -271338,14 +271338,14 @@ var import_multicast_dns = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMi
271338
271338
  return that;
271339
271339
  };
271340
271340
  function defaultInterface() {
271341
- var networks = os$1.networkInterfaces();
271341
+ var networks = os.networkInterfaces();
271342
271342
  var names = Object.keys(networks);
271343
271343
  for (var i = 0; i < names.length; i++) {
271344
271344
  var net = networks[names[i]];
271345
271345
  for (var j = 0; j < net.length; j++) {
271346
271346
  var iface = net[j];
271347
271347
  if (isIPv4(iface.family) && !iface.internal) {
271348
- if (os$1.platform() === "darwin" && names[i] === "en0") return iface.address;
271348
+ if (os.platform() === "darwin" && names[i] === "en0") return iface.address;
271349
271349
  return "0.0.0.0";
271350
271350
  }
271351
271351
  }
@@ -271353,7 +271353,7 @@ var import_multicast_dns = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMi
271353
271353
  return "127.0.0.1";
271354
271354
  }
271355
271355
  function allInterfaces() {
271356
- var networks = os$1.networkInterfaces();
271356
+ var networks = os.networkInterfaces();
271357
271357
  var names = Object.keys(networks);
271358
271358
  var res = [];
271359
271359
  for (var i = 0; i < names.length; i++) {
@@ -291502,6 +291502,51 @@ async function maybeRefreshRuntimeProvisioningGrant(input) {
291502
291502
  return "refreshed";
291503
291503
  }
291504
291504
  //#endregion
291505
+ //#region src/runtimeAuth/SidekickHeartbeatAuthorityInstaller.ts
291506
+ const SIDEKICK_HEARTBEAT_OWNER_ID = "runtime-heartbeat";
291507
+ function verifySidekickHeartbeatTicket(ticket, identity) {
291508
+ const claims = verifyCmmdRuntimeTicket(ticket.token, identity);
291509
+ if (claims === null || claims.scope.length !== 1 || claims.scope[0] !== "sidekick" || claims.machineId !== identity.machineId || claims.credentialEpoch !== identity.credentialEpoch || Date.parse(ticket.expiresAt) !== claims.expiresAtSeconds * 1e3) return null;
291510
+ return claims;
291511
+ }
291512
+ /**
291513
+ * Verifies and installs a `sidekickAuthority` ticket the runtime control
291514
+ * heartbeat delivered (CMMD#5945, forge#3594) into the SAME
291515
+ * `runtimeBrokerAuthority` cache `resolveWorkSessionSidekickRuntimeGrant`
291516
+ * (`cmmdWorkSessionCapabilityBroker.ts`) reads for the Work Session
291517
+ * capability broker. Without this, that cache holds only the original kick
291518
+ * ticket's `sidekick` scope, which expires 15 minutes into a turn with
291519
+ * nothing to replace it — any re-mint of the delegated Sidekick-tool
291520
+ * capability past that point fails closed with `CMMD_AUTH_REQUIRED`. The
291521
+ * 30-second heartbeat tick calling this re-installs a fresh one long before
291522
+ * that TTL is ever in danger.
291523
+ *
291524
+ * Uses the synthetic session id `cmmd-runtime:<runtimeId>:<userId>` — the
291525
+ * SAME one `PipelineProviderAuthorityInstaller` installs `provider`
291526
+ * authority under for automation runs. `readRuntimeBrokerAuthorityForRuntime`
291527
+ * scans every session for a runtime regardless of which one recorded it, so
291528
+ * sharing the id costs nothing and keeps one fewer synthetic session alive
291529
+ * per runtime.
291530
+ *
291531
+ * Never throws: a malformed or wrongly-scoped ticket is a bug on CMMD's side
291532
+ * or a corrupted response in flight, not a reason to crash the heartbeat
291533
+ * loop that is this runtime's own path back to a healthy state. Returns
291534
+ * whether anything was actually installed, purely for logging/tests — the
291535
+ * heartbeat loop that calls this must never let a `false` here interrupt the
291536
+ * heartbeat itself.
291537
+ */
291538
+ function installSidekickHeartbeatAuthority(input) {
291539
+ if (input.ticket === null) return false;
291540
+ const claims = verifySidekickHeartbeatTicket(input.ticket, input.identity);
291541
+ if (claims === null) return false;
291542
+ return recordRuntimeBrokerAuthority({
291543
+ sessionId: AuthSessionId.make(`cmmd-runtime:${input.identity.runtimeId}:${input.identity.userId}`),
291544
+ ownerId: SIDEKICK_HEARTBEAT_OWNER_ID,
291545
+ token: input.ticket.token,
291546
+ claims
291547
+ }).installed;
291548
+ }
291549
+ //#endregion
291505
291550
  //#region src/runtimeDrain/RuntimeDrainReporter.ts
291506
291551
  const HEARTBEAT_INTERVAL = seconds(30);
291507
291552
  const HEARTBEAT_TICK_TIMEOUT = seconds(60);
@@ -291518,6 +291563,30 @@ function runtimeHeartbeatConfig(config) {
291518
291563
  credentialEpoch
291519
291564
  };
291520
291565
  }
291566
+ /**
291567
+ * The full exact-machine identity `installSidekickHeartbeatAuthority` needs
291568
+ * to verify a delivered `sidekickAuthority` ticket — a superset of
291569
+ * `runtimeHeartbeatConfig` (which the heartbeat request itself needs) with
291570
+ * org, user and the verification public key added, the same fields
291571
+ * `PipelineProviderAuthorityInstaller.ts`'s `resolveExactRuntimeIdentity`
291572
+ * requires for the `provider` scope. Null on any missing field: a runtime
291573
+ * without a complete exact identity gets no `sidekick` re-delivery, exactly
291574
+ * as it gets no control heartbeat at all from `runtimeHeartbeatConfig`.
291575
+ */
291576
+ function sidekickHeartbeatIdentityConfig(config) {
291577
+ const heartbeatConfig = runtimeHeartbeatConfig(config);
291578
+ if (!heartbeatConfig) return null;
291579
+ const orgId = config.forgeCmmdRuntimeOrgId?.trim();
291580
+ const userId = config.forgeCmmdRuntimeUserId?.trim();
291581
+ const publicKeyPem = config.forgeCmmdRuntimePublicKey?.trim();
291582
+ if (!orgId || !userId || !publicKeyPem) return null;
291583
+ return {
291584
+ ...heartbeatConfig,
291585
+ orgId,
291586
+ userId,
291587
+ publicKeyPem
291588
+ };
291589
+ }
291521
291590
  function runtimeGrantRefreshConfig(config) {
291522
291591
  if (config.forgeCmmdRuntimeMode !== true) return null;
291523
291592
  const runtimeId = config.forgeCmmdRuntimeId?.trim();
@@ -291571,12 +291640,21 @@ const makeRuntimeDrainReporter = gen(function* () {
291571
291640
  const spriteTaskHoldReactor = yield* SpriteTaskHoldReactor;
291572
291641
  const reportSemaphore = yield* make$43(1);
291573
291642
  let heartbeatSilent = false;
291574
- const applyControlPlaneState = (runtime) => drainState.applyControlPlaneState({
291575
- draining: runtime.draining,
291576
- drainReason: runtime.drainReason,
291577
- drainTargetImageRef: runtime.drainTargetImageRef,
291578
- drainTargetImageVersion: runtime.drainTargetImageVersion,
291579
- drainForceRequired: runtime.drainForceRequired
291643
+ const applyControlPlaneState = (runtime) => gen(function* () {
291644
+ yield* drainState.applyControlPlaneState({
291645
+ draining: runtime.draining,
291646
+ drainReason: runtime.drainReason,
291647
+ drainTargetImageRef: runtime.drainTargetImageRef,
291648
+ drainTargetImageVersion: runtime.drainTargetImageVersion,
291649
+ drainForceRequired: runtime.drainForceRequired
291650
+ });
291651
+ const sidekickIdentity = sidekickHeartbeatIdentityConfig(serverConfig);
291652
+ if (sidekickIdentity) yield* sync$1(() => {
291653
+ installSidekickHeartbeatAuthority({
291654
+ identity: sidekickIdentity,
291655
+ ticket: runtime.sidekickAuthority
291656
+ });
291657
+ });
291580
291658
  });
291581
291659
  const refreshProvisioningGrantIfNeeded = gen(function* () {
291582
291660
  const grantConfig = runtimeGrantRefreshConfig(serverConfig);
@@ -300140,7 +300218,7 @@ function resolveBuildCommitFromEnv(env) {
300140
300218
  * environment descriptor down instead of reporting an honest "unknown".
300141
300219
  */
300142
300220
  function readBakedBuildCommit() {
300143
- return "bcd01e1ae34a37fd182605061608b45892800be2";
300221
+ return "32a98ec9fa40612b5a3e5e87a9c1398870b6a0a3";
300144
300222
  }
300145
300223
  async function resolveServerBuildCommit(input) {
300146
300224
  if (isFullCommitSha(input.baked)) return input.baked;
@@ -325668,7 +325746,7 @@ const connectLoginCommand = make$33("login", {
325668
325746
  })).json();
325669
325747
  },
325670
325748
  openBrowser: async (url) => {
325671
- const open = (await import("./open-yHTUkd2Y.mjs")).default;
325749
+ const open = (await import("./open-2-reBrpv.mjs")).default;
325672
325750
  await open(url);
325673
325751
  return true;
325674
325752
  },
@@ -1,4 +1,4 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Ha as t,Mi as n,Ua as r,Wa as i}from"./Stream-mUTFnSY9.js";import{Kr as a,Lr as o,Ls as s,Nn as c,Qn as l,Tn as u,Vn as d,Wn as f,Yo as p,c as m,d as h,fn as g,kn as _,m as v,ns as y,o as b,pi as x,qn as S,qt as C,s as w,t as T,ts as E,u as D,zn as O}from"./WorkerPoolContext-wx5NJQK1.js";import{a as k,c as A,i as j,l as M,n as N,o as P,r as F,s as I,t as L}from"./Virtualizer-CFIPzyOA.js";import{H as R,Hn as z,Wn as ee,j as B}from"./cmmdForgeRuntimeListResource-KXJO7nN7.js";import{On as V,at as H,ot as U}from"./src-e9jwz4Nc.js";import"./cmmdAuthRedirect-Cpw3QgrC.js";import{t as W}from"./utils-MX9zGa4a.js";import{t as G}from"./chevron-left-1XbEOuXj.js";import{t as K}from"./chevron-right-DAF000Jz.js";import{a as q,c as te,d as ne,h as re,i as ie,l as ae,m as oe,n as se,o as J,p as ce,r as le,s as ue,t as de,u as fe}from"./DiffPanel.logic-B0YyP6X_.js";import{n as pe,t as Y}from"./toggle-group-BRN0oZh2.js";var X=e(i(),1),me=typeof window>`u`?X.useEffect:X.useLayoutEffect;function he({fileDiff:e,options:t,editorOptions:n,lineAnnotations:r,selectedLines:i,prerenderedHTML:a,metrics:o,hasGutterRenderUtility:s,hasCustomHeader:c,disableWorkerPool:l,edit:u}){let d=N(),f=i!==void 0,p=(0,X.useContext)(T),h=w(),g=(0,X.useRef)(null),_=m(n=>{if(n!=null){if(g.current!=null)throw Error(`useFileDiffInstance: An instance should not already exist when a node is created`);d==null?g.current=new ne(Z({controlledSelection:f,hasCustomHeader:c,hasGutterRenderUtility:s,options:t}),l?void 0:p,!0):g.current=new fe(Z({controlledSelection:f,hasCustomHeader:c,hasGutterRenderUtility:s,options:t}),d,o,l?void 0:p,!0),g.current.hydrate({fileDiff:e,fileContainer:n,lineAnnotations:r,prerenderedHTML:a})}else{if(g.current==null)throw Error(`useFileDiffInstance: A FileDiff instance should exist when unmounting`);g.current.cleanUp(),g.current=null}});return me(()=>{let{current:n}=g;if(n==null)return;let a=Z({controlledSelection:f,hasCustomHeader:c,hasGutterRenderUtility:s,options:t}),o=a!==void 0&&!C(n.options,a);n.setOptions(a),n.render({forceRender:o,fileDiff:e,lineAnnotations:r}),i!==void 0&&n.setSelectedLines(i)}),me(()=>{if(u&&g.current!=null){if(h===void 0)throw Error(`FileDiff: EditContext is not attached`);let e=h(n??{});if(e==null)throw Error(`FileDiff: EditProvider.createEditor must return an editor instance`);try{return e.edit(g.current)}catch(t){throw e.cleanUp(),t}}},[u]),{ref:_,getHoveredLine:(0,X.useCallback)(()=>g.current?.getHoveredLine(),[])}}function Z({options:e,controlledSelection:t,hasCustomHeader:n,hasGutterRenderUtility:r}){return t||r||n?{...e,controlledSelection:t,renderCustomHeader:n?b:e?.renderCustomHeader,renderGutterUtility:r?b:e?.renderGutterUtility}:e}var Q=r();function ge({fileDiff:e,options:t,editorOptions:n,metrics:r,lineAnnotations:i,selectedLines:a,className:o,style:s,prerenderedHTML:c,renderAnnotation:l,renderCustomHeader:u,renderHeaderPrefix:d,renderHeaderFilenameSuffix:f,renderHeaderMetadata:p,renderGutterUtility:m,disableWorkerPool:h=!1,edit:_=!1}){let{ref:v,getHoveredLine:y}=he({fileDiff:e,options:t,editorOptions:n,metrics:r,lineAnnotations:i,selectedLines:a,prerenderedHTML:c,hasGutterRenderUtility:m!=null,hasCustomHeader:u!=null,disableWorkerPool:h,edit:_});return(0,Q.jsx)(g,{ref:v,className:o,style:s,children:F(ae({fileDiff:e,renderCustomHeader:u,renderHeaderPrefix:d,renderHeaderFilenameSuffix:f,renderHeaderMetadata:p,renderAnnotation:l,renderGutterUtility:m,lineAnnotations:i,getHoveredLine:y}),c)})}var $=t();function _e(e){return e.fromTurnCount===0?V(H)({threadId:e.threadId,toTurnCount:e.toTurnCount}).pipe(n(e=>({kind:`fullThreadDiff`,input:e}))):V(U)({threadId:e.threadId,fromTurnCount:e.fromTurnCount,toTurnCount:e.toTurnCount}).pipe(n(e=>({kind:`turnDiff`,input:e})))}function ve(e){return e instanceof Error?e.message:typeof e==`string`?e:``}function ye(e){let t=ve(e).trim();if(t.length===0)return`Failed to load checkpoint diff.`;let n=t.toLowerCase();if(n.includes(`not a git repository`))return`Turn diffs are unavailable because this project is not a git repository.`;if(n.includes(`checkpoint unavailable for thread`)||n.includes(`checkpoint invariant violation`)){let e=t.indexOf(`:`);if(e>=0){let n=t.slice(e+1).trim();if(n.length>0)return n}}return t}function be(e){let t=ve(e).toLowerCase();return t.includes(`exceeds current turn count`)||t.includes(`checkpoint is unavailable for turn`)||t.includes(`filesystem checkpoint is unavailable`)}function xe(e){let t=_e(e);return E({queryKey:p.checkpointDiff(e),queryFn:async({signal:n})=>{if(!e.environmentId||!e.threadId||t._tag===`None`)throw Error(`Checkpoint diff is unavailable.`);let r=l(e.environmentId);try{return t.value.kind===`fullThreadDiff`?await r.orchestration.getFullThreadDiff(t.value.input,{signal:n}):await r.orchestration.getTurnDiff(t.value.input,{signal:n})}catch(e){throw Error(ye(e),{cause:e})}},enabled:(e.enabled??!0)&&!!e.environmentId&&!!e.threadId&&t._tag===`Some`,staleTime:1/0,retry:(e,t)=>be(t)?e<12:e<3,retryDelay:(e,t)=>be(t)?Math.min(5e3,250*2**(e-1)):Math.min(1e3,100*2**(e-1))})}function Se(e){if(!(!e.canScrollLeft&&!e.canScrollRight))return{maskImage:`linear-gradient(to right, ${e.canScrollLeft?`transparent 24px, black 72px`:`black`}, ${e.canScrollRight?`black calc(100% - 72px), transparent calc(100% - 24px)`:`black`})`}}function Ce(e){return e instanceof Error?e.message:e?`Failed to load checkpoint diff.`:null}function we(e){return{environmentId:e.environmentId??null,threadId:e.threadId,fromTurnCount:e.range?.fromTurnCount??null,toTurnCount:e.range?.toTurnCount??null,cacheScope:e.selectedTurnId?`turn:${e.selectedTurnId}`:e.conversationCacheScope,enabled:e.enabled}}function Te(){let e=(0,$.c)(8),t=(0,X.useRef)(null),[n,r]=(0,X.useState)(!1),[i,a]=(0,X.useState)(!1),o;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(o=()=>{let e=t.current;if(!e){r(!1),a(!1);return}let n=ue({scrollLeft:e.scrollLeft,scrollWidth:e.scrollWidth,clientWidth:e.clientWidth});r(n.canScrollLeft),a(n.canScrollRight)},e[0]=o):o=e[0];let s=o,c;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(c=e=>{t.current?.scrollBy({left:e,behavior:`smooth`})},e[1]=c):c=e[1];let l=c,u;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(u=e=>{let n=t.current;n&&te({scrollWidth:n.scrollWidth,clientWidth:n.clientWidth,deltaX:e.deltaX,deltaY:e.deltaY})&&(e.preventDefault(),n.scrollBy({left:e.deltaY,behavior:`auto`}))},e[2]=u):u=e[2];let d=u,f,p;e[3]===Symbol.for(`react.memo_cache_sentinel`)?(f=()=>{let e=t.current;if(!e)return;let n=window.requestAnimationFrame(s),r=()=>s();e.addEventListener(`scroll`,r,{passive:!0});let i=new ResizeObserver(()=>s());return i.observe(e),()=>{window.cancelAnimationFrame(n),e.removeEventListener(`scroll`,r),i.disconnect()}},p=[s],e[3]=f,e[4]=p):(f=e[3],p=e[4]),(0,X.useEffect)(f,p);let m;return e[5]!==n||e[6]!==i?(m={ref:t,canScrollLeft:n,canScrollRight:i,scrollBy:l,onWheel:d,remeasure:s},e[5]=n,e[6]=i,e[7]=m):m=e[7],m}function Ee(e,t){let n=(0,$.c)(5),r;n[0]===e.current?r=n[1]:(r=()=>{(e.current?.querySelector(`[data-turn-chip-selected='true']`))?.scrollIntoView({block:`nearest`,inline:`nearest`,behavior:`smooth`})},n[0]=e.current,n[1]=r);let i;n[2]!==e||n[3]!==t?(i=[e,t],n[2]=e,n[3]=t,n[4]=i):i=n[4],(0,X.useEffect)(r,i)}var De=`
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Ha as t,Mi as n,Ua as r,Wa as i}from"./Stream-mUTFnSY9.js";import{Kr as a,Lr as o,Ls as s,Nn as c,Qn as l,Tn as u,Vn as d,Wn as f,Yo as p,c as m,d as h,fn as g,kn as _,m as v,ns as y,o as b,pi as x,qn as S,qt as C,s as w,t as T,ts as E,u as D,zn as O}from"./WorkerPoolContext-c-dkhywP.js";import{a as k,c as A,i as j,l as M,n as N,o as P,r as F,s as I,t as L}from"./Virtualizer-CgjRQnFR.js";import{H as R,Hn as z,Wn as ee,j as B}from"./cmmdForgeRuntimeListResource-CrBWc5Ah.js";import{On as V,at as H,ot as U}from"./src-e9jwz4Nc.js";import"./cmmdAuthRedirect-Cpw3QgrC.js";import{t as W}from"./utils-MX9zGa4a.js";import{t as G}from"./chevron-left-1XbEOuXj.js";import{t as K}from"./chevron-right-DAF000Jz.js";import{a as q,c as te,d as ne,h as re,i as ie,l as ae,m as oe,n as se,o as J,p as ce,r as le,s as ue,t as de,u as fe}from"./DiffPanel.logic-mlsQrAeS.js";import{n as pe,t as Y}from"./toggle-group-BRN0oZh2.js";var X=e(i(),1),me=typeof window>`u`?X.useEffect:X.useLayoutEffect;function he({fileDiff:e,options:t,editorOptions:n,lineAnnotations:r,selectedLines:i,prerenderedHTML:a,metrics:o,hasGutterRenderUtility:s,hasCustomHeader:c,disableWorkerPool:l,edit:u}){let d=N(),f=i!==void 0,p=(0,X.useContext)(T),h=w(),g=(0,X.useRef)(null),_=m(n=>{if(n!=null){if(g.current!=null)throw Error(`useFileDiffInstance: An instance should not already exist when a node is created`);d==null?g.current=new ne(Z({controlledSelection:f,hasCustomHeader:c,hasGutterRenderUtility:s,options:t}),l?void 0:p,!0):g.current=new fe(Z({controlledSelection:f,hasCustomHeader:c,hasGutterRenderUtility:s,options:t}),d,o,l?void 0:p,!0),g.current.hydrate({fileDiff:e,fileContainer:n,lineAnnotations:r,prerenderedHTML:a})}else{if(g.current==null)throw Error(`useFileDiffInstance: A FileDiff instance should exist when unmounting`);g.current.cleanUp(),g.current=null}});return me(()=>{let{current:n}=g;if(n==null)return;let a=Z({controlledSelection:f,hasCustomHeader:c,hasGutterRenderUtility:s,options:t}),o=a!==void 0&&!C(n.options,a);n.setOptions(a),n.render({forceRender:o,fileDiff:e,lineAnnotations:r}),i!==void 0&&n.setSelectedLines(i)}),me(()=>{if(u&&g.current!=null){if(h===void 0)throw Error(`FileDiff: EditContext is not attached`);let e=h(n??{});if(e==null)throw Error(`FileDiff: EditProvider.createEditor must return an editor instance`);try{return e.edit(g.current)}catch(t){throw e.cleanUp(),t}}},[u]),{ref:_,getHoveredLine:(0,X.useCallback)(()=>g.current?.getHoveredLine(),[])}}function Z({options:e,controlledSelection:t,hasCustomHeader:n,hasGutterRenderUtility:r}){return t||r||n?{...e,controlledSelection:t,renderCustomHeader:n?b:e?.renderCustomHeader,renderGutterUtility:r?b:e?.renderGutterUtility}:e}var Q=r();function ge({fileDiff:e,options:t,editorOptions:n,metrics:r,lineAnnotations:i,selectedLines:a,className:o,style:s,prerenderedHTML:c,renderAnnotation:l,renderCustomHeader:u,renderHeaderPrefix:d,renderHeaderFilenameSuffix:f,renderHeaderMetadata:p,renderGutterUtility:m,disableWorkerPool:h=!1,edit:_=!1}){let{ref:v,getHoveredLine:y}=he({fileDiff:e,options:t,editorOptions:n,metrics:r,lineAnnotations:i,selectedLines:a,prerenderedHTML:c,hasGutterRenderUtility:m!=null,hasCustomHeader:u!=null,disableWorkerPool:h,edit:_});return(0,Q.jsx)(g,{ref:v,className:o,style:s,children:F(ae({fileDiff:e,renderCustomHeader:u,renderHeaderPrefix:d,renderHeaderFilenameSuffix:f,renderHeaderMetadata:p,renderAnnotation:l,renderGutterUtility:m,lineAnnotations:i,getHoveredLine:y}),c)})}var $=t();function _e(e){return e.fromTurnCount===0?V(H)({threadId:e.threadId,toTurnCount:e.toTurnCount}).pipe(n(e=>({kind:`fullThreadDiff`,input:e}))):V(U)({threadId:e.threadId,fromTurnCount:e.fromTurnCount,toTurnCount:e.toTurnCount}).pipe(n(e=>({kind:`turnDiff`,input:e})))}function ve(e){return e instanceof Error?e.message:typeof e==`string`?e:``}function ye(e){let t=ve(e).trim();if(t.length===0)return`Failed to load checkpoint diff.`;let n=t.toLowerCase();if(n.includes(`not a git repository`))return`Turn diffs are unavailable because this project is not a git repository.`;if(n.includes(`checkpoint unavailable for thread`)||n.includes(`checkpoint invariant violation`)){let e=t.indexOf(`:`);if(e>=0){let n=t.slice(e+1).trim();if(n.length>0)return n}}return t}function be(e){let t=ve(e).toLowerCase();return t.includes(`exceeds current turn count`)||t.includes(`checkpoint is unavailable for turn`)||t.includes(`filesystem checkpoint is unavailable`)}function xe(e){let t=_e(e);return E({queryKey:p.checkpointDiff(e),queryFn:async({signal:n})=>{if(!e.environmentId||!e.threadId||t._tag===`None`)throw Error(`Checkpoint diff is unavailable.`);let r=l(e.environmentId);try{return t.value.kind===`fullThreadDiff`?await r.orchestration.getFullThreadDiff(t.value.input,{signal:n}):await r.orchestration.getTurnDiff(t.value.input,{signal:n})}catch(e){throw Error(ye(e),{cause:e})}},enabled:(e.enabled??!0)&&!!e.environmentId&&!!e.threadId&&t._tag===`Some`,staleTime:1/0,retry:(e,t)=>be(t)?e<12:e<3,retryDelay:(e,t)=>be(t)?Math.min(5e3,250*2**(e-1)):Math.min(1e3,100*2**(e-1))})}function Se(e){if(!(!e.canScrollLeft&&!e.canScrollRight))return{maskImage:`linear-gradient(to right, ${e.canScrollLeft?`transparent 24px, black 72px`:`black`}, ${e.canScrollRight?`black calc(100% - 72px), transparent calc(100% - 24px)`:`black`})`}}function Ce(e){return e instanceof Error?e.message:e?`Failed to load checkpoint diff.`:null}function we(e){return{environmentId:e.environmentId??null,threadId:e.threadId,fromTurnCount:e.range?.fromTurnCount??null,toTurnCount:e.range?.toTurnCount??null,cacheScope:e.selectedTurnId?`turn:${e.selectedTurnId}`:e.conversationCacheScope,enabled:e.enabled}}function Te(){let e=(0,$.c)(8),t=(0,X.useRef)(null),[n,r]=(0,X.useState)(!1),[i,a]=(0,X.useState)(!1),o;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(o=()=>{let e=t.current;if(!e){r(!1),a(!1);return}let n=ue({scrollLeft:e.scrollLeft,scrollWidth:e.scrollWidth,clientWidth:e.clientWidth});r(n.canScrollLeft),a(n.canScrollRight)},e[0]=o):o=e[0];let s=o,c;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(c=e=>{t.current?.scrollBy({left:e,behavior:`smooth`})},e[1]=c):c=e[1];let l=c,u;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(u=e=>{let n=t.current;n&&te({scrollWidth:n.scrollWidth,clientWidth:n.clientWidth,deltaX:e.deltaX,deltaY:e.deltaY})&&(e.preventDefault(),n.scrollBy({left:e.deltaY,behavior:`auto`}))},e[2]=u):u=e[2];let d=u,f,p;e[3]===Symbol.for(`react.memo_cache_sentinel`)?(f=()=>{let e=t.current;if(!e)return;let n=window.requestAnimationFrame(s),r=()=>s();e.addEventListener(`scroll`,r,{passive:!0});let i=new ResizeObserver(()=>s());return i.observe(e),()=>{window.cancelAnimationFrame(n),e.removeEventListener(`scroll`,r),i.disconnect()}},p=[s],e[3]=f,e[4]=p):(f=e[3],p=e[4]),(0,X.useEffect)(f,p);let m;return e[5]!==n||e[6]!==i?(m={ref:t,canScrollLeft:n,canScrollRight:i,scrollBy:l,onWheel:d,remeasure:s},e[5]=n,e[6]=i,e[7]=m):m=e[7],m}function Ee(e,t){let n=(0,$.c)(5),r;n[0]===e.current?r=n[1]:(r=()=>{(e.current?.querySelector(`[data-turn-chip-selected='true']`))?.scrollIntoView({block:`nearest`,inline:`nearest`,behavior:`smooth`})},n[0]=e.current,n[1]=r);let i;n[2]!==e||n[3]!==t?(i=[e,t],n[2]=e,n[3]=t,n[4]=i):i=n[4],(0,X.useEffect)(r,i)}var De=`
2
2
  [data-diffs-header],
3
3
  [data-diff],
4
4
  [data-file],
@@ -61,4 +61,4 @@ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Ha as t,Mi as n,Ua as
61
61
  text-decoration-color: currentColor;
62
62
  }
63
63
  `;function Oe(e){let t=(0,$.c)(44),{mode:n}=e,r=n===void 0?`inline`:n,{resolvedTheme:i}=c(),o=a(),[s,l]=(0,X.useState)(`stacked`),[d,f]=(0,X.useState)(o.diffWordWrap),p=(0,X.useRef)(null),m=(0,X.useRef)(!1),g=Te(),{activeCwd:v,activeThread:y,bodyState:b,diffOpen:x,inferredCheckpointTurnCountByTurnId:C,orderedTurnDiffSummaries:w,renderableFiles:T,renderablePatch:E,selectedFilePath:D,selectedTurn:k,selectedTurnId:A}=Le(i),j,M;t[0]!==x||t[1]!==o.diffWordWrap?(j=()=>{x&&!m.current&&f(o.diffWordWrap),m.current=x},M=[x,o.diffWordWrap],t[0]=x,t[1]=o.diffWordWrap,t[2]=j,t[3]=M):(j=t[2],M=t[3]),(0,X.useEffect)(j,M);let N;t[4]===D?N=t[5]:(N=()=>{!D||!p.current||Array.from(p.current.querySelectorAll(`[data-diff-file-path]`)).find(e=>e.dataset.diffFilePath===D)?.scrollIntoView({block:`nearest`})},t[4]=D,t[5]=N);let P;t[6]!==T||t[7]!==D?(P=[D,T],t[6]=T,t[7]=D,t[8]=P):P=t[8],(0,X.useEffect)(N,P);let F;t[9]===v?F=t[10]:(F=e=>{let t=O();if(!t)return;let n=v?u(e,v):e;_(t,n).catch(ke)},t[9]=v,t[10]=F);let I=F,L;t[11]===y?L=t[12]:(L=e=>{y&&S.getState().openDiff(ee(z(y.environmentId,y.id)),e)},t[11]=y,t[12]=L);let R=L,B;t[13]===y?B=t[14]:(B=()=>{y&&S.getState().openDiff(ee(z(y.environmentId,y.id)))},t[13]=y,t[14]=B);let V=B,H;t[15]===g.remeasure?H=t[16]:(H=()=>{let e=window.requestAnimationFrame(g.remeasure);return()=>window.cancelAnimationFrame(e)},t[15]=g.remeasure,t[16]=H);let U;t[17]!==w||t[18]!==A||t[19]!==g.remeasure?(U=[w,A,g.remeasure],t[17]=w,t[18]=A,t[19]=g.remeasure,t[20]=U):U=t[20],(0,X.useEffect)(H,U),Ee(g.ref,k?.turnId??A);let W;t[21]!==s||t[22]!==d||t[23]!==C||t[24]!==w||t[25]!==R||t[26]!==V||t[27]!==k||t[28]!==A||t[29]!==o||t[30]!==g?(W=(0,Q.jsx)(Ae,{diffRenderMode:s,diffWordWrap:d,inferredCheckpointTurnCountByTurnId:C,orderedTurnDiffSummaries:w,selectTurn:R,selectWholeConversation:V,selectedTurn:k,selectedTurnId:A,setDiffRenderMode:l,setDiffWordWrap:f,settings:o,turnStrip:g}),t[21]=s,t[22]=d,t[23]=C,t[24]=w,t[25]=R,t[26]=V,t[27]=k,t[28]=A,t[29]=o,t[30]=g,t[31]=W):W=t[31];let G=W,K;t[32]!==b||t[33]!==s||t[34]!==d||t[35]!==I||t[36]!==T||t[37]!==E||t[38]!==i?(K=(0,Q.jsx)(je,{bodyState:b,diffRenderMode:s,diffWordWrap:d,openDiffFileInEditor:I,patchViewportRef:p,renderableFiles:T,renderablePatch:E,resolvedTheme:i}),t[32]=b,t[33]=s,t[34]=d,t[35]=I,t[36]=T,t[37]=E,t[38]=i,t[39]=K):K=t[39];let q;return t[40]!==G||t[41]!==r||t[42]!==K?(q=(0,Q.jsx)(h,{mode:r,header:G,children:K}),t[40]=G,t[41]=r,t[42]=K,t[43]=q):q=t[43],q}function ke(e){console.warn(`Failed to open diff file in editor.`,e)}function Ae(e){let t=(0,$.c)(59),{diffRenderMode:n,diffWordWrap:r,inferredCheckpointTurnCountByTurnId:i,orderedTurnDiffSummaries:a,selectTurn:o,selectWholeConversation:s,selectedTurn:c,selectedTurnId:l,setDiffRenderMode:u,setDiffWordWrap:d,settings:f,turnStrip:p}=e,m,h;t[0]===p?(m=t[1],h=t[2]):(m=(0,Q.jsx)(Be,{direction:`left`,strip:p}),h=(0,Q.jsx)(Be,{direction:`right`,strip:p}),t[0]=p,t[1]=m,t[2]=h);let g=p.ref,_;t[3]!==p.canScrollLeft||t[4]!==p.canScrollRight?(_=Se({canScrollLeft:p.canScrollLeft,canScrollRight:p.canScrollRight}),t[3]=p.canScrollLeft,t[4]=p.canScrollRight,t[5]=_):_=t[5];let v=p.onWheel,y=l===null,b=l===null?`border-border bg-accent text-accent-foreground`:`border-border/70 bg-background/70 text-muted-foreground/80 hover:border-border hover:text-foreground/80`,x;t[6]===b?x=t[7]:(x=W(`rounded-md border px-2 py-1 text-left transition-colors`,b),t[6]=b,t[7]=x);let S;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,Q.jsx)(`div`,{className:`text-[10px] leading-tight font-medium`,children:`All turns`}),t[8]=S):S=t[8];let C;t[9]===x?C=t[10]:(C=(0,Q.jsx)(`div`,{className:x,children:S}),t[9]=x,t[10]=C);let w;t[11]!==s||t[12]!==C||t[13]!==y?(w=(0,Q.jsx)(`button`,{type:`button`,className:`shrink-0 rounded-md`,onClick:s,"data-turn-chip-selected":y,children:C}),t[11]=s,t[12]=C,t[13]=y,t[14]=w):w=t[14];let T;if(t[15]!==i||t[16]!==a||t[17]!==o||t[18]!==c?.turnId||t[19]!==f){let e;t[21]!==i||t[22]!==o||t[23]!==c?.turnId||t[24]!==f?(e=e=>(0,Q.jsx)(Ve,{summary:e,selected:e.turnId===c?.turnId,turnCount:e.checkpointTurnCount??i[e.turnId],timestampFormat:f.timestampFormat,onSelect:o},e.turnId),t[21]=i,t[22]=o,t[23]=c?.turnId,t[24]=f,t[25]=e):e=t[25],T=a.map(e),t[15]=i,t[16]=a,t[17]=o,t[18]=c?.turnId,t[19]=f,t[20]=T}else T=t[20];let E;t[26]!==w||t[27]!==T||t[28]!==_||t[29]!==p.onWheel||t[30]!==p.ref?(E=(0,Q.jsxs)(`div`,{ref:g,className:`turn-chip-strip flex gap-1 overflow-x-auto px-8 py-0.5`,style:_,onWheel:v,children:[w,T]}),t[26]=w,t[27]=T,t[28]=_,t[29]=p.onWheel,t[30]=p.ref,t[31]=E):E=t[31];let D;t[32]!==m||t[33]!==E||t[34]!==h?(D=(0,Q.jsxs)(`div`,{className:`relative min-w-0 flex-1 [-webkit-app-region:no-drag]`,children:[m,h,E]}),t[32]=m,t[33]=E,t[34]=h,t[35]=D):D=t[35];let O;t[36]===n?O=t[37]:(O=[n],t[36]=n,t[37]=O);let k;t[38]===u?k=t[39]:(k=e=>{let t=e[0];(t===`stacked`||t===`split`)&&u(t)},t[38]=u,t[39]=k);let A;t[40]===Symbol.for(`react.memo_cache_sentinel`)?(A=(0,Q.jsx)(Y,{"aria-label":`Stacked diff view`,value:`stacked`,children:(0,Q.jsx)(oe,{className:`size-3`})}),t[40]=A):A=t[40];let j;t[41]===Symbol.for(`react.memo_cache_sentinel`)?(j=(0,Q.jsx)(Y,{"aria-label":`Split diff view`,value:`split`,children:(0,Q.jsx)(re,{className:`size-3`})}),t[41]=j):j=t[41];let M;t[42]!==O||t[43]!==k?(M=(0,Q.jsxs)(pe,{className:`shrink-0`,variant:`outline`,size:`xs`,value:O,onValueChange:k,children:[A,j]}),t[42]=O,t[43]=k,t[44]=M):M=t[44];let N=r?`Disable diff line wrapping`:`Enable diff line wrapping`,P=r?`Disable line wrapping`:`Enable line wrapping`,F;t[45]===d?F=t[46]:(F=e=>{d(!!e)},t[45]=d,t[46]=F);let I;t[47]===Symbol.for(`react.memo_cache_sentinel`)?(I=(0,Q.jsx)(ce,{className:`size-3`}),t[47]=I):I=t[47];let L;t[48]!==r||t[49]!==N||t[50]!==P||t[51]!==F?(L=(0,Q.jsx)(Y,{"aria-label":N,title:P,variant:`outline`,size:`xs`,pressed:r,onPressedChange:F,children:I}),t[48]=r,t[49]=N,t[50]=P,t[51]=F,t[52]=L):L=t[52];let R;t[53]!==M||t[54]!==L?(R=(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 [-webkit-app-region:no-drag]`,children:[M,L]}),t[53]=M,t[54]=L,t[55]=R):R=t[55];let z;return t[56]!==D||t[57]!==R?(z=(0,Q.jsxs)(Q.Fragment,{children:[D,R]}),t[56]=D,t[57]=R,t[58]=z):z=t[58],z}function je(e){let t=(0,$.c)(18),{bodyState:n,diffRenderMode:r,diffWordWrap:i,openDiffFileInEditor:a,patchViewportRef:o,renderableFiles:s,renderablePatch:c,resolvedTheme:l}=e;if(n.kind===`no-thread`){let e;return t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,Q.jsx)(Ne,{children:`Select a thread to inspect turn diffs.`}),t[0]=e):e=t[0],e}if(n.kind===`not-git-repo`){let e;return t[1]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,Q.jsx)(Ne,{children:`Turn diffs are unavailable because this project is not a git repository.`}),t[1]=e):e=t[1],e}if(n.kind===`no-completed-turns`){let e;return t[2]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,Q.jsx)(Ne,{children:`No completed turns yet.`}),t[2]=e):e=t[2],e}let u;t[3]!==n.error||t[4]!==c?(u=n.error&&!c&&(0,Q.jsx)(`div`,{className:`px-3`,children:(0,Q.jsx)(`p`,{className:`mb-2 text-[11px] text-destructive-foreground`,children:n.error})}),t[3]=n.error,t[4]=c,t[5]=u):u=t[5];let d;t[6]!==n||t[7]!==r||t[8]!==i||t[9]!==a||t[10]!==s||t[11]!==c||t[12]!==l?(d=c?c.kind===`files`?(0,Q.jsx)(L,{className:`diff-render-surface h-full min-h-0 overflow-auto px-2 pb-2`,config:{overscrollSize:600,intersectionObserverMargin:1200},children:s.map(e=>{let t=J(e),n=`${de(e)}:${l}`;return(0,Q.jsx)(`div`,{"data-diff-file-path":t,className:`diff-render-file mb-2 rounded-md first:mt-2 last:mb-0`,onClickCapture:e=>{(e.nativeEvent.composedPath?.()??[]).some(Me)&&a(t)},children:(0,Q.jsx)(ge,{fileDiff:e,options:{diffStyle:r===`split`?`split`:`unified`,lineDiffType:`none`,overflow:i?`wrap`:`scroll`,theme:v(l),themeType:l,unsafeCSS:De}})},n)})}):(0,Q.jsx)(`div`,{className:`h-full overflow-auto p-2`,children:(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(`p`,{className:`text-[11px] text-muted-foreground/75`,children:c.reason}),(0,Q.jsx)(`pre`,{className:W(`max-h-[72vh] rounded-md border border-border/70 bg-background/70 p-3 font-mono text-[11px] leading-relaxed text-muted-foreground/90`,i?`overflow-auto whitespace-pre-wrap wrap-break-word`:`overflow-auto`),children:c.text})]})}):(0,Q.jsx)(Re,{bodyState:n}),t[6]=n,t[7]=r,t[8]=i,t[9]=a,t[10]=s,t[11]=c,t[12]=l,t[13]=d):d=t[13];let f;return t[14]!==o||t[15]!==u||t[16]!==d?(f=(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsxs)(`div`,{ref:o,className:`diff-panel-viewport min-h-0 min-w-0 flex-1 overflow-hidden`,children:[u,d]})}),t[14]=o,t[15]=u,t[16]=d,t[17]=f):f=t[17],f}function Me(e){return e instanceof Element&&e.hasAttribute(`data-title`)}function Ne(e){let t=(0,$.c)(2),{children:n}=e,r;return t[0]===n?r=t[1]:(r=(0,Q.jsx)(`div`,{className:`flex flex-1 items-center justify-center px-5 text-center text-xs text-muted-foreground/70`,children:n}),t[0]=n,t[1]=r),r}function Pe(){let e=(0,$.c)(19),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t={strict:!1,select:Ie},e[0]=t):t=e[0];let n=s(t),r;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(r={strict:!1,select:Fe},e[1]=r):r=e[1];let i=M(r),a=i.rightPanel===`diff`,c=n?.threadId??null,l,u;e[2]===n?u=e[3]:(u=o(n),e[2]=n,e[3]=u),l=u;let f=R(l),p=He(f),m=f?.worktreePath,h=p?.cwd,g;e[4]!==m||e[5]!==h?(g=P({threadWorktreePath:m,projectCwd:h}),e[4]=m,e[5]=h,e[6]=g):g=e[6];let _=g,v=f?.environmentId??null,y=_??null,b;e[7]!==v||e[8]!==y?(b={environmentId:v,cwd:y},e[7]=v,e[8]=y,e[9]=b):b=e[9];let x=d(b),S;e[10]===x.data?S=e[11]:(S=I(x.data),e[10]=x.data,e[11]=S);let C=S,w;return e[12]!==_||e[13]!==f||e[14]!==c||e[15]!==a||e[16]!==i||e[17]!==C?(w={activeThread:f,activeThreadId:c,activeCwd:_,isGitRepo:C,diffSearch:i,diffOpen:a},e[12]=_,e[13]=f,e[14]=c,e[15]=a,e[16]=i,e[17]=C,e[18]=w):w=e[18],w}function Fe(e){return k(e)}function Ie(e){return x(e)}function Le(e){let{activeThread:t,activeThreadId:n,activeCwd:r,isGitRepo:i,diffSearch:a,diffOpen:o}=Pe(),{turnDiffSummaries:s,inferredCheckpointTurnCountByTurnId:c}=j(t),l=a.diffTurnId??null,u=l===null?null:a.diffFilePath??null,{activeCheckpointRange:d,conversationCacheScope:f,orderedTurnDiffSummaries:p,selectedTurn:m}=(0,X.useMemo)(()=>q({summaries:s,inferredCheckpointTurnCountByTurnId:c,selectedTurnId:l}),[c,l,s]),h=y(xe(we({environmentId:t?.environmentId,threadId:n,range:d,selectedTurnId:m?.turnId,conversationCacheScope:f,enabled:i}))),g=h.isLoading,_=Ce(h.error),v=h.data?.diff,b=typeof v==`string`&&v.trim().length===0,{emptyDiffMessage:x}=(0,X.useMemo)(()=>ie(m),[m]),S=(0,X.useMemo)(()=>se(v,`diff-panel:${e}`),[e,v]),C=(0,X.useMemo)(()=>Ue(S),[S]);return{activeCwd:r,activeThread:t,bodyState:le({hasActiveThread:!!t,isGitRepo:i,turnSummaryCount:p.length,checkpointDiffError:_,hasRenderablePatch:!!S,isLoadingCheckpointDiff:g,hasNoNetChanges:b,emptyDiffMessage:x}),diffOpen:o,inferredCheckpointTurnCountByTurnId:c,orderedTurnDiffSummaries:p,renderableFiles:C,renderablePatch:S,selectedFilePath:u,selectedTurn:m,selectedTurnId:l}}function Re(e){let t=(0,$.c)(4),{bodyState:n}=e;if(n.kind===`loading`){let e;return t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,Q.jsx)(D,{label:`Loading checkpoint diff...`}),t[0]=e):e=t[0],e}let r;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,Q.jsx)(A,{className:`size-7 text-muted-foreground/25`}),t[1]=r):r=t[1];let i=n.kind===`empty`?n.message:`No diff is available for this range.`,a;return t[2]===i?a=t[3]:(a=(0,Q.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-2 px-5 py-2 text-center`,children:[r,(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground/70`,children:i})]}),t[2]=i,t[3]=a),a}var ze=180;function Be(e){let t=(0,$.c)(14),{direction:n,strip:r}=e,i=n===`left`,a=i?r.canScrollLeft:r.canScrollRight,o=i?G:K,s=i?`left-0`:`right-0`,c=a?`border-border/70 hover:border-border hover:text-foreground`:`cursor-not-allowed border-border/40 text-muted-foreground/40`,l;t[0]!==s||t[1]!==c?(l=W(`absolute top-1/2 z-20 inline-flex size-6 -translate-y-1/2 items-center justify-center rounded-md border bg-background/90 text-muted-foreground transition-colors`,s,c),t[0]=s,t[1]=c,t[2]=l):l=t[2];let u;t[3]!==i||t[4]!==r?(u=()=>r.scrollBy(i?-180:ze),t[3]=i,t[4]=r,t[5]=u):u=t[5];let d=!a,f=`Scroll turn list ${n}`,p;t[6]===o?p=t[7]:(p=(0,Q.jsx)(o,{className:`size-3.5`}),t[6]=o,t[7]=p);let m;return t[8]!==l||t[9]!==u||t[10]!==d||t[11]!==f||t[12]!==p?(m=(0,Q.jsx)(`button`,{type:`button`,className:l,onClick:u,disabled:d,"aria-label":f,children:p}),t[8]=l,t[9]=u,t[10]=d,t[11]=f,t[12]=p,t[13]=m):m=t[13],m}function Ve(e){let t=(0,$.c)(23),{summary:n,selected:r,turnCount:i,timestampFormat:a,onSelect:o}=e,s;t[0]!==o||t[1]!==n.turnId?(s=()=>o(n.turnId),t[0]=o,t[1]=n.turnId,t[2]=s):s=t[2];let c=n.turnId,l=r?`border-border bg-accent text-accent-foreground`:`border-border/70 bg-background/70 text-muted-foreground/80 hover:border-border hover:text-foreground/80`,u;t[3]===l?u=t[4]:(u=W(`rounded-md border px-2 py-1 text-left transition-colors`,l),t[3]=l,t[4]=u);let d=i??`?`,p;t[5]===d?p=t[6]:(p=(0,Q.jsxs)(`span`,{className:`text-[10px] leading-tight font-medium`,children:[`Turn `,d]}),t[5]=d,t[6]=p);let m;t[7]!==n.completedAt||t[8]!==a?(m=f(n.completedAt,a),t[7]=n.completedAt,t[8]=a,t[9]=m):m=t[9];let h;t[10]===m?h=t[11]:(h=(0,Q.jsx)(`span`,{className:`text-[9px] leading-tight opacity-70`,children:m}),t[10]=m,t[11]=h);let g;t[12]!==p||t[13]!==h?(g=(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[p,h]}),t[12]=p,t[13]=h,t[14]=g):g=t[14];let _;t[15]!==u||t[16]!==g?(_=(0,Q.jsx)(`div`,{className:u,children:g}),t[15]=u,t[16]=g,t[17]=_):_=t[17];let v;return t[18]!==r||t[19]!==n.turnId||t[20]!==s||t[21]!==_?(v=(0,Q.jsx)(`button`,{type:`button`,className:`shrink-0 rounded-md`,onClick:s,title:c,"data-turn-chip-selected":r,children:_}),t[18]=r,t[19]=n.turnId,t[20]=s,t[21]=_,t[22]=v):v=t[22],v}function He(e){let t=(0,$.c)(3),n=e?.environmentId,r=e?.projectId,i;return t[0]!==n||t[1]!==r?(i=e=>n&&r?B(e,{environmentId:n,projectId:r}):void 0,t[0]=n,t[1]=r,t[2]=i):i=t[2],R(i)}function Ue(e){return!e||e.kind!==`files`?[]:e.files.toSorted((e,t)=>J(e).localeCompare(J(t),void 0,{numeric:!0,sensitivity:`base`}))}export{Oe as default};
64
- //# sourceMappingURL=DiffPanel-B9TB-BHO.js.map
64
+ //# sourceMappingURL=DiffPanel-DzEDIwRS.js.map