lody 0.77.2 → 0.78.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -60,10 +60,11 @@ import require$$1$5, { Worker as Worker$1 } from "node:worker_threads";
60
60
  import require$$1$6, { fileURLToPath, pathToFileURL } from "node:url";
61
61
  import require$$1$7 from "node:console";
62
62
  import require$$1$8 from "node:dns";
63
- import { C as CodeCollabV2OpenTextRequestSchema, a as CodeCollabV2RefreshTextRequestSchema, b as CodeCollabV2SaveTextRequestSchema, c as CodeCollabV2OpenCurrentDiffRequestSchema, d as CodeCollabV2OpenAllChangesDiffRequestSchema, e as CodeCollabV2OpenTurnDiffRequestSchema, f as CodeCollabV2InitDirectoryRequestSchema, g as CodeCollabV2OpenTextOkSchema, h as CodeCollabV2RefreshTextResponseSchema, i as CodeCollabV2SaveTextResponseSchema, j as CodeCollabV2OpenCurrentDiffResponseSchema, k as CodeCollabV2OpenAllChangesDiffResponseSchema, l as CodeCollabV2OpenTurnDiffResponseSchema, m as CodeCollabV2InitDirectoryOkSchema, n as CodeCollabV2LspUnsupportedSchema, o as CodeCollabV2ErrorSchema, p as CodeCollabV2RpcContentEnvelopeSchema, q as deriveCodeCollabV2ContentKeyId, r as CodeCollabV2ErrorCodeSchema, s as CodeCollabV2RpcResponseSchema, t as deriveCodeCollabV2ContentKeyBytes, u as readCodeCollabFileIndexSignalFromFlock, w as writeCodeCollabFileIndexSignalToFlock, v as writeCodeCollabFileIndexToFlock, x as buildCodeCollabFileIndexState, y as CODE_COLLAB_V2_TEXT_LIMITS, z as CODE_COLLAB_V2_ALL_CHANGES_DIFF_LIMITS, A as computeAllChanges, B as codeCollabFileIndexStatesEqual, D as scanGitDirectoryEntries, E as closeDirectoryQuietly } from "./chunks/directory-handle-BBQKxZ5F.js";
63
+ import { C as CodeCollabV2OpenTextRequestSchema, a as CodeCollabV2RefreshTextRequestSchema, b as CodeCollabV2SaveTextRequestSchema, c as CodeCollabV2OpenCurrentDiffRequestSchema, d as CodeCollabV2OpenAllChangesDiffRequestSchema, e as CodeCollabV2OpenTurnDiffRequestSchema, f as CodeCollabV2InitDirectoryRequestSchema, g as CodeCollabV2OpenTextOkSchema, h as CodeCollabV2RefreshTextResponseSchema, i as CodeCollabV2SaveTextResponseSchema, j as CodeCollabV2OpenCurrentDiffResponseSchema, k as CodeCollabV2OpenAllChangesDiffResponseSchema, l as CodeCollabV2OpenTurnDiffResponseSchema, m as CodeCollabV2InitDirectoryOkSchema, n as CodeCollabV2LspUnsupportedSchema, o as CodeCollabV2ErrorSchema, p as CodeCollabV2RpcContentEnvelopeSchema, q as deriveCodeCollabV2ContentKeyId, r as CodeCollabV2ErrorCodeSchema, s as CodeCollabV2RpcResponseSchema, t as deriveCodeCollabV2ContentKeyBytes, u as readCodeCollabFileIndexSignalFromFlock, w as writeCodeCollabFileIndexSignalToFlock, v as writeCodeCollabFileIndexToFlock, x as buildCodeCollabFileIndexState, y as CODE_COLLAB_V2_TEXT_LIMITS, z as CODE_COLLAB_V2_ALL_CHANGES_DIFF_LIMITS, A as computeAllChanges, B as codeCollabFileIndexStatesEqual, D as scanGitDirectoryEntries, E as closeDirectoryQuietly } from "./chunks/directory-handle-OPjjCl3O.js";
64
64
  import { C as ClientSideConnection, P as PROTOCOL_VERSION, p as packageJson, n as ndJsonStream } from "./chunks/package-qnDHmQq4.js";
65
65
  import { StringDecoder } from "node:string_decoder";
66
66
  import { pipeline, finished } from "node:stream/promises";
67
+ import { r as runtimeManifest } from "./chunks/runtime-manifest-Fr5DEH54.js";
67
68
  import { AsyncLocalStorage as AsyncLocalStorage$1 } from "async_hooks";
68
69
  import { createRequire } from "module";
69
70
  import { c as computeLineCounts, a as countTextLines } from "./chunks/diff-line-counts-bmGB_T-n.js";
@@ -2292,7 +2293,7 @@ Upgrade Node, then re-run: npx lody@latest`;
2292
2293
  return frames;
2293
2294
  };
2294
2295
  }
2295
- const version$8 = "5.38.8";
2296
+ const version$9 = "5.38.8";
2296
2297
  const FeatureFlagError = {
2297
2298
  ERRORS_WHILE_COMPUTING: "errors_while_computing_flags",
2298
2299
  FLAG_MISSING: "flag_missing",
@@ -3470,7 +3471,7 @@ Upgrade Node, then re-run: npx lody@latest`;
3470
3471
  return this.options.fetch ? this.options.fetch(url, options) : fetch(url, options);
3471
3472
  }
3472
3473
  getLibraryVersion() {
3473
- return version$8;
3474
+ return version$9;
3474
3475
  }
3475
3476
  getCustomUserAgent() {
3476
3477
  return `${this.getLibraryId()}/${this.getLibraryVersion()}`;
@@ -4319,7 +4320,7 @@ Upgrade Node, then re-run: npx lody@latest`;
4319
4320
  throw new Error(`Unrecognized ${PLATFORM_ENV_VAR} value: ${JSON.stringify(raw2)} (expected "local" or "cloud")`);
4320
4321
  }
4321
4322
  const name$2 = "lody";
4322
- const version$7 = "0.76.0";
4323
+ const version$8 = "0.76.0";
4323
4324
  const normalizeRuntimeEnv = (value) => {
4324
4325
  switch (value?.toLowerCase()) {
4325
4326
  case "dev":
@@ -4568,6 +4569,11 @@ Upgrade Node, then re-run: npx lody@latest`;
4568
4569
  agentType: "kimi",
4569
4570
  displayName: "Kimi Code"
4570
4571
  },
4572
+ {
4573
+ runtimeName: "grok-build",
4574
+ agentType: "grok",
4575
+ displayName: "Grok"
4576
+ },
4571
4577
  {
4572
4578
  runtimeName: "claude-code",
4573
4579
  agentType: "claude",
@@ -4585,7 +4591,7 @@ Upgrade Node, then re-run: npx lody@latest`;
4585
4591
  return false;
4586
4592
  }
4587
4593
  const record2 = value;
4588
- return (record2.codexPath === void 0 || typeof record2.codexPath === "string") && (record2.claudeCodeExecutable === void 0 || typeof record2.claudeCodeExecutable === "string") && (record2.kimiPath === void 0 || typeof record2.kimiPath === "string");
4594
+ return (record2.codexPath === void 0 || typeof record2.codexPath === "string") && (record2.claudeCodeExecutable === void 0 || typeof record2.claudeCodeExecutable === "string") && (record2.kimiPath === void 0 || typeof record2.kimiPath === "string") && (record2.grokPath === void 0 || typeof record2.grokPath === "string");
4589
4595
  };
4590
4596
  const hasBuiltinRuntimeOverrideValues = (runtimeOverrides) => !!runtimeOverrides && Object.values(runtimeOverrides).some((value) => typeof value === "string" && value.trim().length > 0);
4591
4597
  const getBuiltinRuntimeOverrideSourceVersionSuffix = (runtimeOverrides) => hasBuiltinRuntimeOverrideValues(runtimeOverrides) ? `+override:${JSON.stringify(runtimeOverrides)}` : "";
@@ -4619,6 +4625,7 @@ Upgrade Node, then re-run: npx lody@latest`;
4619
4625
  const CODEX_AUTO_REVIEW_MODE_ID = "agent-auto-review";
4620
4626
  const BUILTIN_DEFAULT_MODE_IDS = {
4621
4627
  kimi: "auto",
4628
+ grok: "agent",
4622
4629
  claude: "auto",
4623
4630
  codex: CODEX_AUTO_REVIEW_MODE_ID
4624
4631
  };
@@ -11243,6 +11250,7 @@ Requirements:
11243
11250
  const WorktreeCleanupScriptConfigSchema = WorktreeSetupScriptConfigSchema;
11244
11251
  _enum$1([
11245
11252
  "kimi",
11253
+ "grok",
11246
11254
  "claude",
11247
11255
  "codex"
11248
11256
  ]);
@@ -11258,7 +11266,8 @@ Requirements:
11258
11266
  const BuiltinRuntimeOverridesSchema = object$1({
11259
11267
  codexPath: string$1().optional(),
11260
11268
  claudeCodeExecutable: string$1().optional(),
11261
- kimiPath: string$1().optional()
11269
+ kimiPath: string$1().optional(),
11270
+ grokPath: string$1().optional()
11262
11271
  }).strict();
11263
11272
  const AcpConfigOptionValueSchema = union$7([
11264
11273
  string$1(),
@@ -14248,32 +14257,16 @@ Requirements:
14248
14257
  }
14249
14258
  }
14250
14259
  },
14251
- {
14252
- id: "grok-build",
14253
- name: "Grok Build",
14254
- version: "1.0.0",
14255
- description: "xAI's coding agent and CLI",
14256
- icon: "https://cdn.agentclientprotocol.com/registry/v1/latest/grok-build.svg",
14257
- distribution: {
14258
- npx: {
14259
- package: "@xai-official/grok@1.0.0",
14260
- args: [
14261
- "agent",
14262
- "stdio"
14263
- ]
14264
- }
14265
- }
14266
- },
14267
14260
  {
14268
14261
  id: "harn",
14269
14262
  name: "Harn",
14270
- version: "0.10.69",
14263
+ version: "0.10.70",
14271
14264
  description: "Harn runs .harn agent pipelines as a native ACP coding agent over stdio.",
14272
14265
  icon: "https://cdn.agentclientprotocol.com/registry/v1/latest/harn.svg",
14273
14266
  distribution: {
14274
14267
  binary: {
14275
14268
  "darwin-aarch64": {
14276
- archive: "https://github.com/burin-labs/harn/releases/download/v0.10.69/harn-aarch64-apple-darwin.tar.gz",
14269
+ archive: "https://github.com/burin-labs/harn/releases/download/v0.10.70/harn-aarch64-apple-darwin.tar.gz",
14277
14270
  cmd: "./harn",
14278
14271
  args: [
14279
14272
  "serve",
@@ -14281,7 +14274,7 @@ Requirements:
14281
14274
  ]
14282
14275
  },
14283
14276
  "darwin-x86_64": {
14284
- archive: "https://github.com/burin-labs/harn/releases/download/v0.10.69/harn-x86_64-apple-darwin.tar.gz",
14277
+ archive: "https://github.com/burin-labs/harn/releases/download/v0.10.70/harn-x86_64-apple-darwin.tar.gz",
14285
14278
  cmd: "./harn",
14286
14279
  args: [
14287
14280
  "serve",
@@ -14289,7 +14282,7 @@ Requirements:
14289
14282
  ]
14290
14283
  },
14291
14284
  "linux-aarch64": {
14292
- archive: "https://github.com/burin-labs/harn/releases/download/v0.10.69/harn-aarch64-unknown-linux-gnu.tar.gz",
14285
+ archive: "https://github.com/burin-labs/harn/releases/download/v0.10.70/harn-aarch64-unknown-linux-gnu.tar.gz",
14293
14286
  cmd: "./harn",
14294
14287
  args: [
14295
14288
  "serve",
@@ -14297,7 +14290,7 @@ Requirements:
14297
14290
  ]
14298
14291
  },
14299
14292
  "linux-x86_64": {
14300
- archive: "https://github.com/burin-labs/harn/releases/download/v0.10.69/harn-x86_64-unknown-linux-gnu.tar.gz",
14293
+ archive: "https://github.com/burin-labs/harn/releases/download/v0.10.70/harn-x86_64-unknown-linux-gnu.tar.gz",
14301
14294
  cmd: "./harn",
14302
14295
  args: [
14303
14296
  "serve",
@@ -14305,7 +14298,7 @@ Requirements:
14305
14298
  ]
14306
14299
  },
14307
14300
  "windows-x86_64": {
14308
- archive: "https://github.com/burin-labs/harn/releases/download/v0.10.69/harn-x86_64-pc-windows-msvc.zip",
14301
+ archive: "https://github.com/burin-labs/harn/releases/download/v0.10.70/harn-x86_64-pc-windows-msvc.zip",
14309
14302
  cmd: "harn.exe",
14310
14303
  args: [
14311
14304
  "serve",
@@ -23210,10 +23203,18 @@ ${context2.authorReply.trim()}
23210
23203
  const exhaustive = room;
23211
23204
  throw new Error(`Unsupported local data-plane room: ${String(exhaustive)}`);
23212
23205
  }
23206
+ function createUtf8StreamDecoder() {
23207
+ const decoder2 = new TextDecoder("utf-8");
23208
+ return (chunk) => decoder2.decode(chunk, {
23209
+ stream: true
23210
+ });
23211
+ }
23213
23212
  function createJsonLineSplitter(options) {
23213
+ const decodeChunk = createUtf8StreamDecoder();
23214
23214
  let buffer2 = "";
23215
23215
  let discardingOversizedLine = false;
23216
- return (chunk) => {
23216
+ return (input2) => {
23217
+ let chunk = typeof input2 === "string" ? input2 : decodeChunk(input2);
23217
23218
  if (discardingOversizedLine) {
23218
23219
  const newlineIndex2 = chunk.indexOf("\n");
23219
23220
  if (newlineIndex2 < 0) {
@@ -24594,6 +24595,7 @@ ${peerId}`;
24594
24595
  };
24595
24596
  const SUPPORTED_CLI_TYPES = [
24596
24597
  "kimi",
24598
+ "grok",
24597
24599
  "claude",
24598
24600
  "codex"
24599
24601
  ];
@@ -24636,7 +24638,7 @@ ${peerId}`;
24636
24638
  const getSessionIdFromRoomId = (roomId) => isSessionDocRoomId(roomId) ? roomId.slice(SESSION_DOC_PREFIX.length) : null;
24637
24639
  const isMachineDocRoomId = (roomId) => roomId.startsWith(MACHINE_DOC_PREFIX);
24638
24640
  const name$1 = "@lody/cli-cloud";
24639
- const version$6 = "0.77.2";
24641
+ const version$7 = "0.78.0";
24640
24642
  const type$2 = "module";
24641
24643
  const scripts = {
24642
24644
  "dev": "node dev.mjs",
@@ -24653,7 +24655,7 @@ ${peerId}`;
24653
24655
  };
24654
24656
  const pkg = {
24655
24657
  name: name$1,
24656
- version: version$6,
24658
+ version: version$7,
24657
24659
  "private": true,
24658
24660
  type: type$2,
24659
24661
  scripts,
@@ -24789,7 +24791,7 @@ ${peerId}`;
24789
24791
  }
24790
24792
  const runtimeEnv = getRuntimeEnv();
24791
24793
  const apiKey = resolveApiKey();
24792
- const release = `${name$2}@${version$7}`;
24794
+ const release = `${name$2}@${version$8}`;
24793
24795
  const distinctId = resolveDistinctId();
24794
24796
  const errorReportingEnabled = runtimeEnv !== "dev" && !!apiKey;
24795
24797
  let client$1 = null;
@@ -24801,9 +24803,9 @@ ${peerId}`;
24801
24803
  }
24802
24804
  const baseExceptionProps = {
24803
24805
  $lib: "lody-cli",
24804
- $lib_version: version$7,
24806
+ $lib_version: version$8,
24805
24807
  platform: "cli",
24806
- app_version: version$7,
24808
+ app_version: version$8,
24807
24809
  env: runtimeEnv,
24808
24810
  release,
24809
24811
  machine_id: distinctId
@@ -30413,9 +30415,9 @@ ${originalIndentation}`;
30413
30415
  })(common$2);
30414
30416
  return common$2;
30415
30417
  }
30416
- const version$5 = "3.19.0";
30418
+ const version$6 = "3.19.0";
30417
30419
  const require$$2$3 = {
30418
- version: version$5
30420
+ version: version$6
30419
30421
  };
30420
30422
  var transports = {};
30421
30423
  var winstonTransport = {
@@ -111070,6 +111072,17 @@ ${incoming}`).output;
111070
111072
  isCodexAgent() {
111071
111073
  return this.options.agentConfig?.agentType === "codex";
111072
111074
  }
111075
+ getGrokClientIdentifier() {
111076
+ return this.options.agentConfig?.cliType === "builtin" && this.options.agentConfig.agentType === "grok" ? `lody:${this.options.sessionId}` : void 0;
111077
+ }
111078
+ getGrokSessionMeta() {
111079
+ const clientIdentifier = this.getGrokClientIdentifier();
111080
+ return clientIdentifier ? {
111081
+ _meta: {
111082
+ clientIdentifier
111083
+ }
111084
+ } : {};
111085
+ }
111073
111086
  isCurrentAcpSession(acpSessionId) {
111074
111087
  return this.acpSessionId !== null && acpSessionId === this.acpSessionId;
111075
111088
  }
@@ -111087,6 +111100,8 @@ ${incoming}`).output;
111087
111100
  async startSession(stream2, workdir, resumeSessionId, timeoutOptions = {}, startupAbort, resolveSessionStart, forkSessionId, forkSessionTurnId) {
111088
111101
  const connection2 = new ClientSideConnection(() => this, stream2);
111089
111102
  this.connection = connection2;
111103
+ const grokClientIdentifier = this.getGrokClientIdentifier();
111104
+ const grokSessionMeta = this.getGrokSessionMeta();
111090
111105
  this.logger.debug(`[${this.options.sessionId}] Starting ACP client (workdir=${workdir} resumeSessionId=${resumeSessionId ?? "none"} forkSessionId=${forkSessionId ?? "none"})`);
111091
111106
  if (resumeSessionId && forkSessionId) {
111092
111107
  throw new Error("[ACP_SESSION_START_INVALID] resumeSessionId and forkSessionId are exclusive");
@@ -111117,6 +111132,11 @@ ${incoming}`).output;
111117
111132
  try {
111118
111133
  initResponse = await withTimeout$2(withAbort(connection2.initialize({
111119
111134
  protocolVersion: PROTOCOL_VERSION,
111135
+ ...grokClientIdentifier ? {
111136
+ _meta: {
111137
+ clientIdentifier: grokClientIdentifier
111138
+ }
111139
+ } : {},
111120
111140
  clientCapabilities: {
111121
111141
  terminal: this.terminalEnabled,
111122
111142
  plan: {},
@@ -111307,7 +111327,8 @@ ${incoming}`).output;
111307
111327
  const loadResponse = await withTimeout$2(withAbort(connection2.loadSession({
111308
111328
  sessionId: resumeSessionId,
111309
111329
  cwd: workdir,
111310
- mcpServers
111330
+ mcpServers,
111331
+ ...grokSessionMeta
111311
111332
  }), startupAbort), this.logger, "connection.loadSession", this.options.sessionId, ACP_LOAD_SESSION_TIMEOUT_MS);
111312
111333
  const loadDurationMs = performance$1.now() - loadStart;
111313
111334
  sessionResponse = {
@@ -111348,7 +111369,8 @@ ${incoming}`).output;
111348
111369
  const resumeResponse = await withTimeout$2(withAbort(connection2.resumeSession({
111349
111370
  sessionId: resumeSessionId,
111350
111371
  cwd: workdir,
111351
- mcpServers
111372
+ mcpServers,
111373
+ ...grokSessionMeta
111352
111374
  }), startupAbort), this.logger, "connection.resumeSession", this.options.sessionId, ACP_RESUME_SESSION_TIMEOUT_MS);
111353
111375
  const resumeDurationMs = performance$1.now() - resumeStart;
111354
111376
  sessionResponse = {
@@ -111387,7 +111409,8 @@ ${incoming}`).output;
111387
111409
  try {
111388
111410
  sessionResponse = await withTimeout$2(withAbort(connection2.newSession({
111389
111411
  cwd: workdir,
111390
- mcpServers
111412
+ mcpServers,
111413
+ ...grokSessionMeta
111391
111414
  }), startupAbort), this.logger, "connection.newSession", this.options.sessionId, ACP_NEW_SESSION_TIMEOUT_MS);
111392
111415
  } catch (error2) {
111393
111416
  if (isAcpAuthenticationRequired(error2)) {
@@ -111453,7 +111476,8 @@ ${incoming}`).output;
111453
111476
  try {
111454
111477
  return await withTimeout$2(connection2.newSession({
111455
111478
  cwd: workdir,
111456
- mcpServers
111479
+ mcpServers,
111480
+ ...this.getGrokSessionMeta()
111457
111481
  }), this.logger, "connection.newSession.editAndResend", this.options.sessionId, timeoutMs);
111458
111482
  } catch (error2) {
111459
111483
  throw new Error(`[ACP_SESSION_PREPARE_FAILED] ${formatErrorMessage(error2)}`, {
@@ -121105,14 +121129,18 @@ ${error2.message}` : execaMessage;
121105
121129
  highWaterMark
121106
121130
  }));
121107
121131
  }
121108
- const version$4 = "1.4.0";
121132
+ const version$5 = "1.4.0";
121109
121133
  const dependencies$1 = {
121110
121134
  "@openai/codex": "^0.147.0"
121111
121135
  };
121112
121136
  const codexPackageJson = {
121113
- version: version$4,
121137
+ version: version$5,
121114
121138
  dependencies: dependencies$1
121115
121139
  };
121140
+ const version$4 = "0.1.0";
121141
+ const grokPackageJson = {
121142
+ version: version$4
121143
+ };
121116
121144
  const version$3 = "2.1.220";
121117
121145
  const platforms = {
121118
121146
  "darwin-arm64": {
@@ -121263,10 +121291,13 @@ ${error2.message}` : execaMessage;
121263
121291
  const CLAUDE_ACP_ADAPTER_VERSION = packageJson.version;
121264
121292
  const CLAUDE_CODE_RUNTIME_VERSION = claudeSdkManifestJson.version;
121265
121293
  const KIMI_CODE_VERSION = kimiCodePackageJson.version;
121294
+ const GROK_ACP_ADAPTER_VERSION = grokPackageJson.version;
121295
+ const GROK_BUILD_RUNTIME_VERSION = runtimeManifest.officialRuntime.version;
121266
121296
  const KIMI_CODE_MIN_NODE_VERSION = resolveMinimumNodeVersion("@moonshot-ai/kimi-code", kimiCodePackageJson.engines.node);
121267
121297
  const BUILTIN_CODEX_CAPABILITY_SOURCE_VERSION = `builtin-codex-acp:${CODEX_ACP_ADAPTER_VERSION}+codex:${CODEX_RUNTIME_VERSION}`;
121268
121298
  const BUILTIN_CLAUDE_CAPABILITY_SOURCE_VERSION = `builtin-claude-acp:${CLAUDE_ACP_ADAPTER_VERSION}+agent-sdk:${CLAUDE_AGENT_SDK_VERSION}+claude-code:${CLAUDE_CODE_RUNTIME_VERSION}`;
121269
121299
  const BUILTIN_KIMI_CAPABILITY_SOURCE_VERSION = `builtin-kimi:${KIMI_CODE_VERSION}`;
121300
+ const BUILTIN_GROK_CAPABILITY_SOURCE_VERSION = `builtin-grok-acp:${GROK_ACP_ADAPTER_VERSION}+official-grok:${GROK_BUILD_RUNTIME_VERSION}`;
121270
121301
  const RUNTIMES = {
121271
121302
  codex: {
121272
121303
  name: "codex",
@@ -121416,6 +121447,66 @@ ${error2.message}` : execaMessage;
121416
121447
  cmd: "package/dist/main.mjs"
121417
121448
  }
121418
121449
  }
121450
+ },
121451
+ "grok-build": {
121452
+ name: "grok-build",
121453
+ version: GROK_BUILD_RUNTIME_VERSION,
121454
+ platforms: {
121455
+ "darwin-arm64": {
121456
+ fileName: `xai-official-grok-darwin-arm64-${GROK_BUILD_RUNTIME_VERSION}.tar.zst`,
121457
+ sha256: "63aa0a0a95e7a555a372f1a501dcf59151376d7e4d900e24e1c591ff6cc8f818",
121458
+ size: 46222120,
121459
+ compression: "zstd",
121460
+ cmd: "grok",
121461
+ executableSha256: "13c7f4f0b9abb00bf38216302ea4bab31f03e13555e3576620eca1de572a8d21",
121462
+ executableSize: 131817232
121463
+ },
121464
+ "darwin-x64": {
121465
+ fileName: `xai-official-grok-darwin-x64-${GROK_BUILD_RUNTIME_VERSION}.tar.zst`,
121466
+ sha256: "7bf0af43ba1f3dc8e860e7f887b75966ece7bb6102cc7a3b2fb5af275f757c8a",
121467
+ size: 50590131,
121468
+ compression: "zstd",
121469
+ cmd: "grok",
121470
+ executableSha256: "a82210a961deac9f0cb72ec6c334196abf76a587be4593bc59db2deab85ee6dc",
121471
+ executableSize: 147358e3
121472
+ },
121473
+ "linux-arm64": {
121474
+ fileName: `xai-official-grok-linux-arm64-${GROK_BUILD_RUNTIME_VERSION}.tar.zst`,
121475
+ sha256: "c888d404ad218caa251cbdbbd0da5836c807957be5a83fd8ab21b69de93469d9",
121476
+ size: 49704069,
121477
+ compression: "zstd",
121478
+ cmd: "grok",
121479
+ executableSha256: "bb7c51116564a2219f6a49850815060f416918ac407f1f2ba82c53c0b0d4383f",
121480
+ executableSize: 133745832
121481
+ },
121482
+ "linux-x64": {
121483
+ fileName: `xai-official-grok-linux-x64-${GROK_BUILD_RUNTIME_VERSION}.tar.zst`,
121484
+ sha256: "7d0bb4309e634e0ecb63403f35fa468120f5ecf2173feb6518371be1633ecd99",
121485
+ size: 53264623,
121486
+ compression: "zstd",
121487
+ cmd: "grok",
121488
+ executableSha256: "28dbc967a5843dae2374b6834dadbab95354e685c7e5c8dc750b92a4e5fc7c3e",
121489
+ executableSize: 163676672
121490
+ },
121491
+ "win32-arm64": {
121492
+ fileName: `xai-official-grok-win32-arm64-${GROK_BUILD_RUNTIME_VERSION}.tar.zst`,
121493
+ sha256: "c821de276cb1fa835567bd6c5589709e6ba29182d6b0c9ad7c160cc3df91145c",
121494
+ size: 45241480,
121495
+ compression: "zstd",
121496
+ cmd: "grok.exe",
121497
+ executableSha256: "9d41447b6eee77cfb7359b7f50935ae64b4e7b7e7ef56c40e6d203f5660317e1",
121498
+ executableSize: 121471488
121499
+ },
121500
+ "win32-x64": {
121501
+ fileName: `xai-official-grok-win32-x64-${GROK_BUILD_RUNTIME_VERSION}.tar.zst`,
121502
+ sha256: "5d66d3e0c1e54b050c76b77dfc1dadefbf3e909459a31b4361d8307a671c179c",
121503
+ size: 48124303,
121504
+ compression: "zstd",
121505
+ cmd: "grok.exe",
121506
+ executableSha256: "d546dbc995c2ce9ba97c044d6af6b53f8c11c414a6355bf006802d07c572f406",
121507
+ executableSize: 139903488
121508
+ }
121509
+ }
121419
121510
  }
121420
121511
  };
121421
121512
  function sanitizeSegment(segment) {
@@ -122144,6 +122235,9 @@ ${error2.message}` : execaMessage;
122144
122235
  if (input2.agentType === "kimi") {
122145
122236
  return `${BUILTIN_KIMI_CAPABILITY_SOURCE_VERSION}${runtimeOverrideSuffix}`;
122146
122237
  }
122238
+ if (input2.agentType === "grok") {
122239
+ return `${BUILTIN_GROK_CAPABILITY_SOURCE_VERSION}${runtimeOverrideSuffix}`;
122240
+ }
122147
122241
  }
122148
122242
  return `builtin:${input2.agentType}:unknown`;
122149
122243
  }
@@ -122328,6 +122422,24 @@ ${error2.message}` : execaMessage;
122328
122422
  }
122329
122423
  };
122330
122424
  }
122425
+ if (input2.agentType === "grok") {
122426
+ const overridePath2 = trimRuntimeOverride(input2.runtimeOverrides?.grokPath);
122427
+ const grokPath = overridePath2 ?? await getManagedAgentRuntimeManager().ensureRuntime("grok-build", {
122428
+ onProgress: input2.onManagedRuntimeProgress,
122429
+ signal: input2.signal
122430
+ });
122431
+ return {
122432
+ command: process.execPath,
122433
+ args: [
122434
+ ...resolveCliAdapterEntry("grok-acp"),
122435
+ ...input2.extraArgs ?? []
122436
+ ],
122437
+ env: {
122438
+ GROK_PATH: grokPath,
122439
+ GROK_DISABLE_AUTOUPDATER: "1"
122440
+ }
122441
+ };
122442
+ }
122331
122443
  const overridePath = trimRuntimeOverride(input2.runtimeOverrides?.claudeCodeExecutable);
122332
122444
  const claudePath = overridePath ?? await getManagedAgentRuntimeManager().ensureRuntime("claude-code", {
122333
122445
  onProgress: input2.onManagedRuntimeProgress,
@@ -122375,6 +122487,24 @@ ${error2.message}` : execaMessage;
122375
122487
  ]
122376
122488
  };
122377
122489
  }
122490
+ if (input2.agentType === "grok") {
122491
+ if (input2.action === "status") return null;
122492
+ const overridePath2 = trimRuntimeOverride(input2.runtimeOverrides?.grokPath);
122493
+ const grokPath = overridePath2 ?? await getManagedAgentRuntimeManager().ensureRuntime("grok-build", {
122494
+ onProgress: input2.onManagedRuntimeProgress,
122495
+ signal: input2.signal
122496
+ });
122497
+ return {
122498
+ command: grokPath,
122499
+ args: [
122500
+ "login",
122501
+ "--device-auth"
122502
+ ],
122503
+ env: {
122504
+ GROK_DISABLE_AUTOUPDATER: "1"
122505
+ }
122506
+ };
122507
+ }
122378
122508
  const overridePath = trimRuntimeOverride(input2.runtimeOverrides?.claudeCodeExecutable);
122379
122509
  const claudePath = overridePath ?? await getManagedAgentRuntimeManager().ensureRuntime("claude-code", {
122380
122510
  onProgress: input2.onManagedRuntimeProgress,
@@ -123696,6 +123826,9 @@ enabled = false
123696
123826
  if (agentType === "codex") {
123697
123827
  return url.hostname === "auth.openai.com" && (url.pathname.startsWith("/codex/device") || url.pathname.startsWith("/oauth/authorize"));
123698
123828
  }
123829
+ if (agentType === "grok") {
123830
+ return hasDomain(url.hostname, "accounts.x.ai") && (url.pathname.startsWith("/oauth2/device") || url.pathname.startsWith("/device"));
123831
+ }
123699
123832
  return hasDomain(url.hostname, "kimi.com") && url.pathname.startsWith("/code/authorize_device");
123700
123833
  }
123701
123834
  function findAuthorizationUrl(agentType, output) {
@@ -123765,6 +123898,18 @@ enabled = false
123765
123898
  ]
123766
123899
  }
123767
123900
  ],
123901
+ grok: [
123902
+ {
123903
+ id: "xai-device-login",
123904
+ name: "xAI",
123905
+ description: "Sign in with an xAI account",
123906
+ type: "terminal",
123907
+ args: [
123908
+ "login",
123909
+ "--device-auth"
123910
+ ]
123911
+ }
123912
+ ],
123768
123913
  claude: [
123769
123914
  {
123770
123915
  id: "claude-ai-login",
@@ -123811,7 +123956,7 @@ enabled = false
123811
123956
  status: "unknown"
123812
123957
  };
123813
123958
  }
123814
- if (options.agentType === "kimi" || options.agentType === "codex") {
123959
+ if (options.agentType === "kimi" || options.agentType === "grok" || options.agentType === "codex") {
123815
123960
  return {
123816
123961
  status: "unknown"
123817
123962
  };
@@ -129381,10 +129526,20 @@ The postId is ${normalizedFeedbackPostId}. Use the feedback-progress-reporter sk
129381
129526
  this.captureStatusChanged(options.sessionId, "idle", void 0, "turn_failed");
129382
129527
  }
129383
129528
  formatMemoryPressureFailureMessage(result) {
129384
- const availableMb = Math.round(result.availableMemoryBytes / 1024 / 1024);
129385
- const thresholdMb = Math.round(result.thresholdBytes / 1024 / 1024);
129386
- const commitText = result.availableCommitBytes !== void 0 && (result.pressureReason === "commit" || result.pressureReason === "physical_and_commit") && result.commitThresholdBytes !== void 0 ? ` Commit headroom is ${Math.round(result.availableCommitBytes / 1024 / 1024)}MB (threshold: ${Math.round(result.commitThresholdBytes / 1024 / 1024)}MB).` : "";
129387
- return `The machine is under memory pressure (${availableMb}MB available, ${thresholdMb}MB required to start a turn). The turn was not started; free memory and retry.${commitText}`;
129529
+ if (result.pressureReason === "darwin_pressure_critical") {
129530
+ return "The machine is at critical memory pressure \u2014 macOS is reclaiming memory and terminating processes to keep up. The turn was not started; free memory and retry.";
129531
+ }
129532
+ const mb = (bytes) => `${Math.round(bytes / 1024 / 1024)}MB`;
129533
+ const availableMb = mb(result.availableMemoryBytes);
129534
+ const marginMb = mb(result.thresholdBytes);
129535
+ const commitText = result.availableCommitBytes !== void 0 && (result.pressureReason === "commit" || result.pressureReason === "physical_and_commit") && result.commitThresholdBytes !== void 0 ? ` Commit headroom is ${mb(result.availableCommitBytes)} (safety margin: ${mb(result.commitThresholdBytes)}).` : "";
129536
+ const cgroup = result.cgroup;
129537
+ if (cgroup) {
129538
+ const hostText = result.hostAvailableBytes !== void 0 ? `host available ${mb(result.hostAvailableBytes)}, ` : "";
129539
+ const stallText = cgroup.psiSomeAvg10 !== null ? `stalled ${cgroup.psiSomeAvg10}% of the last 10s on reclaim` : "PSI unavailable; hard headroom is below the floor";
129540
+ return `The machine is under memory pressure and ${stallText}. cgroup ${cgroup.path}: ${mb(cgroup.currentBytes)} of ${mb(cgroup.maxBytes)} used, ${mb(cgroup.hardHeadroomBytes)} unused plus ${mb(cgroup.reclaimableBytes)} reclaimable cache/slab; ${hostText}safety margin ${marginMb}. The turn was not started; free memory and retry.${commitText}`;
129541
+ }
129542
+ return `The machine is under memory pressure (${availableMb} available, safety margin ${marginMb}). The turn was not started; free memory and retry.${commitText}`;
129388
129543
  }
129389
129544
  recordKnownChatFailureAndHaltEffect(options) {
129390
129545
  return this.tryPromise(() => this.recordKnownChatFailure(options)).pipe(flatMap$2(() => fail(new SessionTurnHalted({
@@ -146288,7 +146443,8 @@ ${edit.newString}` : edit.newString;
146288
146443
  }
146289
146444
  const LEGACY_BUILTIN_AGENT_TYPES = /* @__PURE__ */ new Set([
146290
146445
  "claude",
146291
- "codex"
146446
+ "codex",
146447
+ "grok"
146292
146448
  ]);
146293
146449
  function inferAgentConfigCliType(agentType) {
146294
146450
  const normalized = normalizeCliValue(agentType)?.toLowerCase();
@@ -166940,15 +167096,28 @@ ${escapeHtmlScriptContent(VISUAL_ANNOTATION_INSPECTOR_BROWSER_SCRIPT)}
166940
167096
  }
166941
167097
  const execFileAsync = promisify$1(execFile$1);
166942
167098
  const MEMORY_PROBE_TIMEOUT_MS = 1e3;
167099
+ const DARWIN_PRESSURE_NORMAL = 1;
167100
+ const DARWIN_PRESSURE_WARNING = 2;
167101
+ const DARWIN_PRESSURE_CRITICAL = 4;
166943
167102
  async function getMemoryPressureSnapshot() {
166944
- const windowsStatus = await getWindowsMemoryStatus();
167103
+ const [windowsStatus, darwinPressureLevel] = await Promise.all([
167104
+ getWindowsMemoryStatus(),
167105
+ getDarwinMemoryPressureLevel()
167106
+ ]);
166945
167107
  const systemAvailable = await getSystemAvailableMemoryBytes(windowsStatus);
166946
- const cgroupAvailable = getCgroupAvailableMemoryBytes();
166947
- const availableMemoryBytes = cgroupAvailable !== null ? Math.min(systemAvailable, cgroupAvailable) : systemAvailable;
167108
+ const cgroup = readCgroupMemoryState();
167109
+ const availableMemoryBytes = cgroup !== null ? Math.min(systemAvailable, cgroup.hardHeadroomBytes + cgroup.reclaimableBytes) : systemAvailable;
166948
167110
  const effectiveMemoryLimitBytes = getEffectiveMemoryLimitBytes();
166949
167111
  return {
166950
167112
  availableMemoryBytes,
166951
167113
  effectiveMemoryLimitBytes,
167114
+ ...darwinPressureLevel !== null ? {
167115
+ memoryPressureLevel: darwinPressureLevel
167116
+ } : {},
167117
+ ...cgroup !== null ? {
167118
+ cgroup,
167119
+ hostAvailableBytes: systemAvailable
167120
+ } : {},
166952
167121
  ...windowsStatus ? {
166953
167122
  availableCommitBytes: windowsStatus.availableCommitBytes,
166954
167123
  commitLimitBytes: windowsStatus.commitLimitBytes,
@@ -166958,7 +167127,7 @@ ${escapeHtmlScriptContent(VISUAL_ANNOTATION_INSPECTOR_BROWSER_SCRIPT)}
166958
167127
  }
166959
167128
  function getEffectiveMemoryLimitBytes() {
166960
167129
  const totalMem = os__default$1.totalmem();
166961
- const cgroupMax = getCgroupMemoryMaxBytes();
167130
+ const cgroupMax = findTightestCgroupLimit()?.maxBytes ?? null;
166962
167131
  if (cgroupMax !== null) {
166963
167132
  return Math.min(totalMem, cgroupMax);
166964
167133
  }
@@ -167031,6 +167200,34 @@ $mem | ConvertTo-Json -Compress
167031
167200
  return null;
167032
167201
  }
167033
167202
  }
167203
+ async function getDarwinMemoryPressureLevel() {
167204
+ if (process.platform !== "darwin") {
167205
+ return null;
167206
+ }
167207
+ try {
167208
+ const { stdout } = await execFileAsync("sysctl", [
167209
+ "-n",
167210
+ "kern.memorystatus_vm_pressure_level"
167211
+ ], {
167212
+ encoding: "utf8",
167213
+ timeout: MEMORY_PROBE_TIMEOUT_MS
167214
+ });
167215
+ return parseDarwinPressureLevel(String(stdout ?? ""));
167216
+ } catch {
167217
+ return null;
167218
+ }
167219
+ }
167220
+ function parseDarwinPressureLevel(raw2) {
167221
+ const trimmed2 = raw2.trim();
167222
+ if (!/^\d+$/.test(trimmed2)) {
167223
+ return null;
167224
+ }
167225
+ const value = Number.parseInt(trimmed2, 10);
167226
+ if (value === DARWIN_PRESSURE_NORMAL || value === DARWIN_PRESSURE_WARNING || value === DARWIN_PRESSURE_CRITICAL) {
167227
+ return value;
167228
+ }
167229
+ return null;
167230
+ }
167034
167231
  async function getDarwinAvailableMemoryBytes() {
167035
167232
  if (process.platform !== "darwin") {
167036
167233
  return null;
@@ -167078,23 +167275,20 @@ $mem | ConvertTo-Json -Compress
167078
167275
  const availablePages = freePages + speculativePages + purgeablePages + reclaimableCachedPages;
167079
167276
  return availablePages * pageSize;
167080
167277
  }
167081
- function getCgroupMemoryMaxBytes() {
167278
+ function findTightestCgroupLimit() {
167082
167279
  try {
167083
167280
  const cgroupPath = readSelfCgroupPath();
167084
167281
  if (cgroupPath === null) return null;
167085
167282
  let tightest = null;
167086
167283
  let current2 = cgroupPath;
167087
167284
  for (let depth = 0; depth < 20; depth++) {
167088
- const memMaxPath = `/sys/fs/cgroup${current2 === "/" ? "" : current2}/memory.max`;
167089
- const raw2 = readFileSafe(memMaxPath);
167090
- if (raw2 !== null) {
167091
- const trimmed2 = raw2.trim();
167092
- if (trimmed2 !== "max") {
167093
- const value = parseInt(trimmed2, 10);
167094
- if (Number.isFinite(value) && value > 0) {
167095
- tightest = tightest === null ? value : Math.min(tightest, value);
167096
- }
167097
- }
167285
+ const prefix = `/sys/fs/cgroup${current2 === "/" ? "" : current2}`;
167286
+ const value = parseCgroupLimit(readFileSafe(`${prefix}/memory.max`));
167287
+ if (value !== null && (tightest === null || value < tightest.maxBytes)) {
167288
+ tightest = {
167289
+ prefix,
167290
+ maxBytes: value
167291
+ };
167098
167292
  }
167099
167293
  if (current2 === "/" || current2 === "") break;
167100
167294
  const parent = current2.substring(0, current2.lastIndexOf("/")) || "/";
@@ -167106,42 +167300,72 @@ $mem | ConvertTo-Json -Compress
167106
167300
  return null;
167107
167301
  }
167108
167302
  }
167109
- function getCgroupAvailableMemoryBytes() {
167110
- try {
167111
- const cgroupPath = readSelfCgroupPath();
167112
- if (cgroupPath === null) return null;
167113
- let tightestMax = null;
167114
- let tightestPath = null;
167115
- let current2 = cgroupPath;
167116
- for (let depth = 0; depth < 20; depth++) {
167117
- const prefix = `/sys/fs/cgroup${current2 === "/" ? "" : current2}`;
167118
- const raw2 = readFileSafe(`${prefix}/memory.max`);
167119
- if (raw2 !== null) {
167120
- const trimmed2 = raw2.trim();
167121
- if (trimmed2 !== "max") {
167122
- const value = parseInt(trimmed2, 10);
167123
- if (Number.isFinite(value) && value > 0) {
167124
- if (tightestMax === null || value < tightestMax) {
167125
- tightestMax = value;
167126
- tightestPath = prefix;
167127
- }
167128
- }
167129
- }
167130
- }
167131
- if (current2 === "/" || current2 === "") break;
167132
- const parent = current2.substring(0, current2.lastIndexOf("/")) || "/";
167133
- if (parent === current2) break;
167134
- current2 = parent;
167303
+ function parseCgroupLimit(raw2) {
167304
+ if (raw2 === null) return null;
167305
+ const trimmed2 = raw2.trim();
167306
+ if (trimmed2 === "max") return null;
167307
+ const value = parseInt(trimmed2, 10);
167308
+ return Number.isFinite(value) && value > 0 ? value : null;
167309
+ }
167310
+ function readCgroupMemoryState() {
167311
+ const limit2 = findTightestCgroupLimit();
167312
+ if (limit2 === null) return null;
167313
+ const currentRaw = readFileSafe(`${limit2.prefix}/memory.current`);
167314
+ if (currentRaw === null) return null;
167315
+ const currentBytes = parseInt(currentRaw.trim(), 10);
167316
+ if (!Number.isFinite(currentBytes)) return null;
167317
+ const stat2 = parseCgroupMemoryStat(readFileSafe(`${limit2.prefix}/memory.stat`) ?? "");
167318
+ return {
167319
+ path: limit2.prefix,
167320
+ maxBytes: limit2.maxBytes,
167321
+ highBytes: parseCgroupLimit(readFileSafe(`${limit2.prefix}/memory.high`)),
167322
+ currentBytes,
167323
+ hardHeadroomBytes: Math.max(0, limit2.maxBytes - currentBytes),
167324
+ reclaimableBytes: computeCgroupReclaimableBytes(stat2),
167325
+ stat: stat2,
167326
+ psiSomeAvg10: parseCgroupPressureSomeAvg10(readFileSafe(`${limit2.prefix}/memory.pressure`) ?? ""),
167327
+ events: parseCgroupMemoryEvents(readFileSafe(`${limit2.prefix}/memory.events`) ?? "")
167328
+ };
167329
+ }
167330
+ function parseCgroupMemoryStat(raw2) {
167331
+ const values = /* @__PURE__ */ new Map();
167332
+ for (const line3 of raw2.split("\n")) {
167333
+ const match5 = line3.trim().match(/^([a-z_]+)\s+(\d+)$/);
167334
+ if (match5?.[1] && match5[2]) {
167335
+ values.set(match5[1], parseInt(match5[2], 10));
167135
167336
  }
167136
- if (tightestMax === null || tightestPath === null) return null;
167137
- const currentRaw = readFileSafe(`${tightestPath}/memory.current`);
167138
- if (currentRaw === null) return null;
167139
- const currentUsage = parseInt(currentRaw.trim(), 10);
167140
- if (!Number.isFinite(currentUsage)) return null;
167141
- return Math.max(0, tightestMax - currentUsage);
167142
- } catch {
167143
- return null;
167144
167337
  }
167338
+ return {
167339
+ inactiveFileBytes: values.get("inactive_file") ?? 0,
167340
+ activeFileBytes: values.get("active_file") ?? 0,
167341
+ slabReclaimableBytes: values.get("slab_reclaimable") ?? 0,
167342
+ dirtyBytes: (values.get("file_dirty") ?? 0) + (values.get("file_writeback") ?? 0)
167343
+ };
167344
+ }
167345
+ function computeCgroupReclaimableBytes(stat2) {
167346
+ const cleanInactiveFile = Math.max(0, stat2.inactiveFileBytes - stat2.dirtyBytes);
167347
+ return cleanInactiveFile + Math.floor(stat2.slabReclaimableBytes / 2);
167348
+ }
167349
+ function parseCgroupPressureSomeAvg10(raw2) {
167350
+ const match5 = raw2.match(/^some\s+avg10=([\d.]+)/m);
167351
+ if (!match5?.[1]) return null;
167352
+ const value = Number.parseFloat(match5[1]);
167353
+ return Number.isFinite(value) ? value : null;
167354
+ }
167355
+ function parseCgroupMemoryEvents(raw2) {
167356
+ const read = (key2) => {
167357
+ const match5 = raw2.match(new RegExp(`^${key2}\\s+(\\d+)$`, "m"));
167358
+ if (!match5?.[1]) return null;
167359
+ const value = parseInt(match5[1], 10);
167360
+ return Number.isFinite(value) ? value : null;
167361
+ };
167362
+ const high = read("high");
167363
+ const max2 = read("max");
167364
+ if (high === null || max2 === null) return null;
167365
+ return {
167366
+ high,
167367
+ max: max2
167368
+ };
167145
167369
  }
167146
167370
  function readSelfCgroupPath() {
167147
167371
  try {
@@ -167170,6 +167394,11 @@ $mem | ConvertTo-Json -Compress
167170
167394
  const GIB = 1024 * 1024 * 1024;
167171
167395
  const WINDOWS_COMMIT_THRESHOLD_FLOOR_BYTES = 512 * 1024 * 1024;
167172
167396
  const WINDOWS_COMMIT_THRESHOLD_CEILING_BYTES = 2 * GIB;
167397
+ const DEFAULT_MAX_EVICTIONS_PER_CALL = 3;
167398
+ const DEFAULT_PRESSURE_RECHECK_ATTEMPTS = 2;
167399
+ const DEFAULT_PRESSURE_RECHECK_DELAY_MS = 500;
167400
+ const DEFAULT_PSI_STALL_AVG10 = 10;
167401
+ const DEFAULT_CGROUP_HARD_FLOOR_BYTES = 128 * 1024 * 1024;
167173
167402
  function defaultMemoryThresholdBytes() {
167174
167403
  const tenPercent = Math.floor(getEffectiveMemoryLimitBytes() * 0.1);
167175
167404
  return Math.max(GIB, Math.min(4 * GIB, tenPercent));
@@ -167179,16 +167408,83 @@ $mem | ConvertTo-Json -Compress
167179
167408
  idleTimeoutMs: readEnvNumber$1("LODY_SESSION_GC_IDLE_TIMEOUT_MS", 20 * 60 * 1e3),
167180
167409
  sweepIntervalMs: readEnvNumber$1("LODY_SESSION_GC_SWEEP_INTERVAL_MS", 60 * 1e3),
167181
167410
  enabled: process.env.LODY_SESSION_GC_ENABLED !== "false",
167182
- memoryThresholdBytes: readEnvNumber$1("LODY_SESSION_GC_MEMORY_THRESHOLD_BYTES", defaultMemoryThresholdBytes())
167411
+ memoryThresholdBytes: readEnvNumber$1("LODY_SESSION_GC_MEMORY_THRESHOLD_BYTES", defaultMemoryThresholdBytes()),
167412
+ maxEvictionsPerCall: readEnvNumber$1("LODY_SESSION_GC_MAX_EVICTIONS_PER_CALL", DEFAULT_MAX_EVICTIONS_PER_CALL),
167413
+ pressureRecheckAttempts: readEnvNumber$1("LODY_SESSION_GC_PRESSURE_RECHECK_ATTEMPTS", DEFAULT_PRESSURE_RECHECK_ATTEMPTS),
167414
+ pressureRecheckDelayMs: readEnvNumber$1("LODY_SESSION_GC_PRESSURE_RECHECK_DELAY_MS", DEFAULT_PRESSURE_RECHECK_DELAY_MS)
167183
167415
  };
167184
167416
  }
167185
167417
  function getWindowsCommitThresholdBytes(memoryThresholdBytes) {
167186
167418
  return Math.max(WINDOWS_COMMIT_THRESHOLD_FLOOR_BYTES, Math.min(WINDOWS_COMMIT_THRESHOLD_CEILING_BYTES, memoryThresholdBytes));
167187
167419
  }
167420
+ function evaluateMemoryPressure(snapshot, thresholds2) {
167421
+ if (thresholds2.platform === "darwin") {
167422
+ if (snapshot.memoryPressureLevel === DARWIN_PRESSURE_CRITICAL) {
167423
+ return {
167424
+ evict: true,
167425
+ block: true,
167426
+ reason: "darwin_pressure_critical"
167427
+ };
167428
+ }
167429
+ if (snapshot.memoryPressureLevel === DARWIN_PRESSURE_WARNING) {
167430
+ return {
167431
+ evict: true,
167432
+ block: false,
167433
+ reason: "darwin_pressure_warning"
167434
+ };
167435
+ }
167436
+ return {
167437
+ evict: false,
167438
+ block: false,
167439
+ reason: null
167440
+ };
167441
+ }
167442
+ const commitPressure = snapshot.availableCommitBytes !== void 0 && snapshot.availableCommitBytes < thresholds2.commitThresholdBytes;
167443
+ const cgroup = snapshot.cgroup;
167444
+ if (cgroup) {
167445
+ const hostLow = snapshot.hostAvailableBytes !== void 0 && snapshot.hostAvailableBytes < thresholds2.thresholdBytes;
167446
+ const cgroupLow = cgroup.hardHeadroomBytes + cgroup.reclaimableBytes < thresholds2.thresholdBytes;
167447
+ const stalled = cgroup.psiSomeAvg10 !== null ? cgroup.psiSomeAvg10 >= thresholds2.psiStallAvg10 : cgroup.hardHeadroomBytes < thresholds2.cgroupHardFloorBytes;
167448
+ if (hostLow || cgroupLow && stalled) {
167449
+ return {
167450
+ evict: true,
167451
+ block: true,
167452
+ reason: stalled ? "cgroup_stalled" : "physical"
167453
+ };
167454
+ }
167455
+ if (cgroupLow) {
167456
+ return {
167457
+ evict: true,
167458
+ block: false,
167459
+ reason: "cgroup_low_headroom"
167460
+ };
167461
+ }
167462
+ if (commitPressure) {
167463
+ return {
167464
+ evict: true,
167465
+ block: true,
167466
+ reason: "commit"
167467
+ };
167468
+ }
167469
+ return {
167470
+ evict: false,
167471
+ block: false,
167472
+ reason: null
167473
+ };
167474
+ }
167475
+ const physicalPressure = snapshot.availableMemoryBytes < thresholds2.thresholdBytes;
167476
+ const reason = physicalPressure && commitPressure ? "physical_and_commit" : physicalPressure ? "physical" : commitPressure ? "commit" : null;
167477
+ return {
167478
+ evict: reason !== null,
167479
+ block: reason !== null,
167480
+ reason
167481
+ };
167482
+ }
167188
167483
  class SessionGCManager {
167189
- constructor(config2, deps) {
167484
+ constructor(config2, deps, platform2 = process.platform) {
167190
167485
  this.config = config2;
167191
167486
  this.deps = deps;
167487
+ this.platform = platform2;
167192
167488
  }
167193
167489
  sweepInterval = null;
167194
167490
  start() {
@@ -167196,7 +167492,8 @@ $mem | ConvertTo-Json -Compress
167196
167492
  this.deps.logger.debug("[GC] Session GC is disabled");
167197
167493
  return;
167198
167494
  }
167199
- this.deps.logger.debug(`[GC] Starting session GC (interval=${this.config.sweepIntervalMs}ms, idleTimeout=${this.config.idleTimeoutMs}ms, memoryThreshold=${Math.round(this.config.memoryThresholdBytes / 1024 / 1024)}MB)`);
167495
+ const pressureSignal = this.platform === "darwin" ? "kern.memorystatus_vm_pressure_level" : `available<${Math.round(this.config.memoryThresholdBytes / 1024 / 1024)}MB`;
167496
+ this.deps.logger.debug(`[GC] Starting session GC (interval=${this.config.sweepIntervalMs}ms, idleTimeout=${this.config.idleTimeoutMs}ms, pressureSignal=${pressureSignal}, maxEvictionsPerCall=${this.config.maxEvictionsPerCall})`);
167200
167497
  this.sweepInterval = setInterval(() => void this.sweep(), this.config.sweepIntervalMs);
167201
167498
  }
167202
167499
  stop() {
@@ -167236,48 +167533,39 @@ $mem | ConvertTo-Json -Compress
167236
167533
  async evictForMemoryPressure(excludeSessionId) {
167237
167534
  const thresholdBytes = this.config.memoryThresholdBytes;
167238
167535
  const commitThresholdBytes = getWindowsCommitThresholdBytes(thresholdBytes);
167536
+ const thresholds2 = {
167537
+ platform: this.platform,
167538
+ thresholdBytes,
167539
+ commitThresholdBytes,
167540
+ psiStallAvg10: DEFAULT_PSI_STALL_AVG10,
167541
+ cgroupHardFloorBytes: DEFAULT_CGROUP_HARD_FLOOR_BYTES
167542
+ };
167239
167543
  let memorySnapshot = await this.deps.memoryPressure.getLatest();
167240
- let availableMemory = memorySnapshot.availableMemoryBytes;
167241
- let pressureReason = this.getPressureReason(memorySnapshot, thresholdBytes, commitThresholdBytes);
167242
- if (!this.config.enabled) {
167243
- return {
167244
- availableMemoryBytes: availableMemory,
167245
- thresholdBytes,
167246
- hadMemoryPressure: false,
167247
- stillUnderPressure: false,
167248
- evictedSessionIds: [],
167249
- pressureReason: null,
167250
- ...memorySnapshot.availableCommitBytes !== void 0 ? {
167251
- availableCommitBytes: memorySnapshot.availableCommitBytes,
167252
- commitThresholdBytes,
167253
- commitLimitBytes: memorySnapshot.commitLimitBytes,
167254
- committedBytes: memorySnapshot.committedBytes
167255
- } : {}
167256
- };
167257
- }
167258
- if (pressureReason === null) {
167259
- return {
167260
- availableMemoryBytes: availableMemory,
167544
+ let verdict = evaluateMemoryPressure(memorySnapshot, thresholds2);
167545
+ if (this.config.enabled && verdict.evict) {
167546
+ memorySnapshot = await this.deps.memoryPressure.refresh();
167547
+ verdict = evaluateMemoryPressure(memorySnapshot, thresholds2);
167548
+ }
167549
+ if (!this.config.enabled || !verdict.evict) {
167550
+ return this.buildEvictionResult({
167551
+ snapshot: memorySnapshot,
167261
167552
  thresholdBytes,
167553
+ commitThresholdBytes,
167262
167554
  hadMemoryPressure: false,
167263
- stillUnderPressure: false,
167264
- evictedSessionIds: [],
167265
- pressureReason: null,
167266
- ...memorySnapshot.availableCommitBytes !== void 0 ? {
167267
- availableCommitBytes: memorySnapshot.availableCommitBytes,
167268
- commitThresholdBytes,
167269
- commitLimitBytes: memorySnapshot.commitLimitBytes,
167270
- committedBytes: memorySnapshot.committedBytes
167271
- } : {}
167272
- };
167555
+ verdict: this.config.enabled ? verdict : {
167556
+ evict: false,
167557
+ block: false,
167558
+ reason: null
167559
+ },
167560
+ evictedSessionIds: []
167561
+ });
167273
167562
  }
167274
- const commitText = memorySnapshot.availableCommitBytes !== void 0 ? `, commit headroom ${Math.round(memorySnapshot.availableCommitBytes / 1024 / 1024)}MB (threshold: ${Math.round(commitThresholdBytes / 1024 / 1024)}MB)` : "";
167275
- this.deps.logger.debug(`[GC] Memory pressure detected: ${Math.round(availableMemory / 1024 / 1024)}MB available (threshold: ${Math.round(thresholdBytes / 1024 / 1024)}MB)${commitText}`);
167563
+ this.deps.logger.debug(`[GC] Memory pressure detected (${verdict.reason}): ${this.describeMemoryState(memorySnapshot, thresholdBytes, commitThresholdBytes)}`);
167276
167564
  const sessions = this.getSessionsWithIdleTime();
167277
167565
  sessions.sort((a, b) => b.idleMs - a.idleMs);
167278
167566
  const evictedSessionIds = [];
167279
167567
  for (const { sessionId, idleMs } of sessions) {
167280
- if (pressureReason === null) {
167568
+ if (!verdict.evict || evictedSessionIds.length >= this.config.maxEvictionsPerCall) {
167281
167569
  break;
167282
167570
  }
167283
167571
  if (excludeSessionId && sessionId === excludeSessionId) {
@@ -167294,46 +167582,78 @@ $mem | ConvertTo-Json -Compress
167294
167582
  await this.deps.cleanSession(sessionId);
167295
167583
  evictedSessionIds.push(sessionId);
167296
167584
  memorySnapshot = await this.deps.memoryPressure.refresh();
167297
- availableMemory = memorySnapshot.availableMemoryBytes;
167298
- pressureReason = this.getPressureReason(memorySnapshot, thresholdBytes, commitThresholdBytes);
167585
+ verdict = evaluateMemoryPressure(memorySnapshot, thresholds2);
167299
167586
  } catch (error2) {
167300
167587
  this.deps.logger.error(`[GC] Failed to evict session ${sessionId}: ${formatErrorMessage(error2)}`);
167301
167588
  }
167302
167589
  }
167303
- const stillUnderPressure = pressureReason !== null;
167590
+ for (let attempt = 0; verdict.block && attempt < this.config.pressureRecheckAttempts; attempt++) {
167591
+ await this.sleep(this.config.pressureRecheckDelayMs);
167592
+ memorySnapshot = await this.deps.memoryPressure.refresh();
167593
+ verdict = evaluateMemoryPressure(memorySnapshot, thresholds2);
167594
+ if (!verdict.block) {
167595
+ this.deps.logger.debug(`[GC] Memory pressure cleared on recheck ${attempt + 1}: ${this.describeMemoryState(memorySnapshot, thresholdBytes, commitThresholdBytes)}`);
167596
+ }
167597
+ }
167598
+ const availableMemory = memorySnapshot.availableMemoryBytes;
167599
+ const stillUnderPressure = verdict.block;
167304
167600
  if (evictedSessionIds.length > 0) {
167305
167601
  this.deps.logger.debug(`[GC] Memory pressure eviction complete: evicted ${evictedSessionIds.length} sessions, available memory now ${Math.round(availableMemory / 1024 / 1024)}MB`);
167306
167602
  } else if (stillUnderPressure) {
167307
167603
  this.deps.logger.debug("[GC] Memory pressure persists but no idle sessions were eligible for eviction");
167308
167604
  }
167309
- return {
167310
- availableMemoryBytes: availableMemory,
167605
+ return this.buildEvictionResult({
167606
+ snapshot: memorySnapshot,
167311
167607
  thresholdBytes,
167608
+ commitThresholdBytes,
167312
167609
  hadMemoryPressure: true,
167313
- stillUnderPressure,
167314
- evictedSessionIds,
167315
- pressureReason,
167316
- ...memorySnapshot.availableCommitBytes !== void 0 ? {
167317
- availableCommitBytes: memorySnapshot.availableCommitBytes,
167610
+ verdict,
167611
+ evictedSessionIds
167612
+ });
167613
+ }
167614
+ buildEvictionResult(options) {
167615
+ const { snapshot, thresholdBytes, commitThresholdBytes, verdict } = options;
167616
+ return {
167617
+ availableMemoryBytes: snapshot.availableMemoryBytes,
167618
+ thresholdBytes,
167619
+ hadMemoryPressure: options.hadMemoryPressure,
167620
+ stillUnderPressure: verdict.block,
167621
+ evictedSessionIds: options.evictedSessionIds,
167622
+ pressureReason: verdict.reason,
167623
+ ...snapshot.memoryPressureLevel !== void 0 ? {
167624
+ memoryPressureLevel: snapshot.memoryPressureLevel
167625
+ } : {},
167626
+ ...snapshot.cgroup !== void 0 ? {
167627
+ cgroup: snapshot.cgroup
167628
+ } : {},
167629
+ ...snapshot.hostAvailableBytes !== void 0 ? {
167630
+ hostAvailableBytes: snapshot.hostAvailableBytes
167631
+ } : {},
167632
+ ...snapshot.availableCommitBytes !== void 0 ? {
167633
+ availableCommitBytes: snapshot.availableCommitBytes,
167318
167634
  commitThresholdBytes,
167319
- commitLimitBytes: memorySnapshot.commitLimitBytes,
167320
- committedBytes: memorySnapshot.committedBytes
167635
+ commitLimitBytes: snapshot.commitLimitBytes,
167636
+ committedBytes: snapshot.committedBytes
167321
167637
  } : {}
167322
167638
  };
167323
167639
  }
167324
- getPressureReason(snapshot, thresholdBytes, commitThresholdBytes) {
167325
- const physicalPressure = snapshot.availableMemoryBytes < thresholdBytes;
167326
- const commitPressure = snapshot.availableCommitBytes !== void 0 && snapshot.availableCommitBytes < commitThresholdBytes;
167327
- if (physicalPressure && commitPressure) {
167328
- return "physical_and_commit";
167329
- }
167330
- if (physicalPressure) {
167331
- return "physical";
167640
+ sleep(ms2) {
167641
+ if (this.deps.sleep) return this.deps.sleep(ms2);
167642
+ return new Promise((resolve2) => {
167643
+ setTimeout(resolve2, ms2).unref?.();
167644
+ });
167645
+ }
167646
+ describeMemoryState(snapshot, thresholdBytes, commitThresholdBytes) {
167647
+ if (snapshot.memoryPressureLevel !== void 0) {
167648
+ return `kernel pressure level ${snapshot.memoryPressureLevel}`;
167332
167649
  }
167333
- if (commitPressure) {
167334
- return "commit";
167650
+ const cgroup = snapshot.cgroup;
167651
+ if (cgroup) {
167652
+ const mb = (bytes) => Math.round(bytes / 1024 / 1024);
167653
+ return `cgroup ${cgroup.path}: hard headroom ${mb(cgroup.hardHeadroomBytes)}MB + reclaimable ${mb(cgroup.reclaimableBytes)}MB (of ${mb(cgroup.stat.activeFileBytes)}MB active file cache not counted), host available ${snapshot.hostAvailableBytes !== void 0 ? mb(snapshot.hostAvailableBytes) : "?"}MB, PSI some avg10 ${cgroup.psiSomeAvg10 ?? "?"}, threshold ${mb(thresholdBytes)}MB`;
167335
167654
  }
167336
- return null;
167655
+ const commitText = snapshot.availableCommitBytes !== void 0 ? `, commit headroom ${Math.round(snapshot.availableCommitBytes / 1024 / 1024)}MB (threshold: ${Math.round(commitThresholdBytes / 1024 / 1024)}MB)` : "";
167656
+ return `${Math.round(snapshot.availableMemoryBytes / 1024 / 1024)}MB available (threshold: ${Math.round(thresholdBytes / 1024 / 1024)}MB)${commitText}`;
167337
167657
  }
167338
167658
  async getIdleCandidates() {
167339
167659
  const sessions = this.getSessionsWithIdleTime();
@@ -178064,13 +178384,14 @@ export PATH=${toSingleQuotedShellString(ghShimBinDir)}:"$PATH"
178064
178384
  await removeStaleUnixSocket(socketPath, "local_terminal_socket_in_use");
178065
178385
  const server = net.createServer((socket) => {
178066
178386
  let buffer2 = "";
178387
+ const decodeChunk = createUtf8StreamDecoder();
178067
178388
  const state2 = createTerminalSocketState();
178068
178389
  activeClientSockets$1.add(socket);
178069
178390
  const unsubscribe = config2.terminalPtyService.onEvent((event) => {
178070
178391
  publishTerminalEvent(socket, state2, event);
178071
178392
  });
178072
178393
  socket.on("data", (chunk) => {
178073
- buffer2 += chunk.toString("utf8");
178394
+ buffer2 += decodeChunk(chunk);
178074
178395
  if (buffer2.length > MAX_BUFFER_BYTES) {
178075
178396
  send(socket, {
178076
178397
  type: "error",
@@ -178228,7 +178549,7 @@ export PATH=${toSingleQuotedShellString(ghShimBinDir)}:"$PATH"
178228
178549
  });
178229
178550
  }
178230
178551
  });
178231
- socket.on("data", (chunk) => splitLines(chunk.toString("utf8")));
178552
+ socket.on("data", (chunk) => splitLines(chunk));
178232
178553
  socket.setTimeout(CONNECTION_IDLE_TIMEOUT_MS, () => {
178233
178554
  config2.logger.debug(`[loro-data-plane] connection ${connectionId} idle; dropping`);
178234
178555
  socket.destroy();
@@ -185404,10 +185725,11 @@ Shutting down gracefully${reason}...`);
185404
185725
  function logCliDetectionResults(logger2, availability) {
185405
185726
  logger2.debug("Local agent auth detection results:");
185406
185727
  logger2.debug(`kimi: ${availability.kimi || "not found"}`);
185728
+ logger2.debug(`grok: ${availability.grok || "not found"}`);
185407
185729
  logger2.debug(`claude: ${availability.claude || "not found"}`);
185408
185730
  logger2.debug(`codex: ${availability.codex || "not found"}`);
185409
185731
  }
185410
- const startCommand = new Command("start").description("Start agent service in native mode").option("--machine-name <name>", "Machine name to register (defaults to hostname)").option("--cli-types <types...>", "Specify CLI types to register: `kimi`, `claude`, or `codex`", (value, previous) => {
185732
+ const startCommand = new Command("start").description("Start agent service in native mode").option("--machine-name <name>", "Machine name to register (defaults to hostname)").option("--cli-types <types...>", "Specify CLI types to register: `kimi`, `grok`, `claude`, or `codex`", (value, previous) => {
185411
185733
  if (!previous) {
185412
185734
  return [
185413
185735
  value
@@ -185435,7 +185757,7 @@ Shutting down gracefully${reason}...`);
185435
185757
  });
185436
185758
  scrubLocalSupervisorCapabilityEnv();
185437
185759
  await traceAsync(logger2, "startup.process_resource_profile", void 0, async () => normalizeCurrentProcessResourceProfile(logger2));
185438
- for (const diagnostic of getRuntimeDiagnostics(version$7)) {
185760
+ for (const diagnostic of getRuntimeDiagnostics(version$8)) {
185439
185761
  logger2.info(diagnostic);
185440
185762
  }
185441
185763
  if (options.heartbeatLog) {
@@ -185498,6 +185820,7 @@ Shutting down gracefully${reason}...`);
185498
185820
  const cliDetectionStartedAt = Date.now();
185499
185821
  const cliAvailability = {
185500
185822
  kimi: "managed-runtime",
185823
+ grok: "managed-runtime",
185501
185824
  claude: checkClaude(),
185502
185825
  codex: checkCodex()
185503
185826
  };
@@ -185505,6 +185828,7 @@ Shutting down gracefully${reason}...`);
185505
185828
  logCliDetectionResults(logger2, cliAvailability);
185506
185829
  captureAgentServiceEvent("agent_service_cli_detection", {
185507
185830
  kimi_available: true,
185831
+ grok_available: true,
185508
185832
  claude_available: Boolean(cliAvailability.claude),
185509
185833
  codex_available: Boolean(cliAvailability.codex)
185510
185834
  });
@@ -185515,7 +185839,7 @@ Shutting down gracefully${reason}...`);
185515
185839
  availability: cliAvailability
185516
185840
  });
185517
185841
  if (cliSelection.invalid.length > 0) {
185518
- logger2.error(`Unknown CLI types: ${cliSelection.invalid.join(", ")}. Supported values: kimi, claude, codex.`);
185842
+ logger2.error(`Unknown CLI types: ${cliSelection.invalid.join(", ")}. Supported values: kimi, grok, claude, codex.`);
185519
185843
  process.exit(1);
185520
185844
  }
185521
185845
  if (cliSelection.missing.length > 0) {
@@ -213310,7 +213634,7 @@ ${page}${helpTipBottom}${choiceDescription}${ansiEscapes.cursorHide}`;
213310
213634
  data = createReviewBundleSnapshot(bundle);
213311
213635
  }
213312
213636
  const { injectReviewSnapshot } = await import("./chunks/index-VoI6Ds2-.js");
213313
- const { resolveReviewViewerTemplate } = await import("./chunks/review-viewer-C1f8pVKg.js").then(async (m) => {
213637
+ const { resolveReviewViewerTemplate } = await import("./chunks/review-viewer-Bgp2Thsg.js").then(async (m) => {
213314
213638
  await m.__tla;
213315
213639
  return m;
213316
213640
  });
@@ -214508,6 +214832,76 @@ ${result.stdout ?? ""}`;
214508
214832
  return null;
214509
214833
  }
214510
214834
  }
214835
+ function planDaemonAuthPreflight(input2) {
214836
+ const { existingAuth, validation: validation2, interactive } = input2;
214837
+ const login = (reason) => interactive ? {
214838
+ action: "login",
214839
+ reason
214840
+ } : {
214841
+ action: "abort",
214842
+ reason: "login_required_non_interactive",
214843
+ message: reason === "credentials_rejected" ? "This machine is no longer signed in to Lody." : "This machine is not connected to Lody yet."
214844
+ };
214845
+ if (!existingAuth || !validation2) {
214846
+ return login("missing_credentials");
214847
+ }
214848
+ if (validation2.valid) {
214849
+ return {
214850
+ action: "proceed",
214851
+ user: validation2.user
214852
+ };
214853
+ }
214854
+ if (isTokenValidationUnavailable(validation2)) {
214855
+ return {
214856
+ action: "abort",
214857
+ reason: "backend_unreachable",
214858
+ message: validation2.error ?? validation2.reason
214859
+ };
214860
+ }
214861
+ return login("credentials_rejected");
214862
+ }
214863
+ async function ensureDaemonBackendAuth(options) {
214864
+ const { authClient, logger: logger2, machineName } = options;
214865
+ const interactive = options.interactive ?? process.stdout.isTTY === true;
214866
+ const existingAuth = authClient.getAuthInfo();
214867
+ logger2.info("Checking the connection to Lody\u2026");
214868
+ const validation2 = existingAuth ? await authClient.validateToken(existingAuth.token) : null;
214869
+ const plan = planDaemonAuthPreflight({
214870
+ existingAuth,
214871
+ validation: validation2,
214872
+ interactive
214873
+ });
214874
+ if (plan.action === "abort") {
214875
+ return {
214876
+ status: "failed",
214877
+ reason: plan.reason,
214878
+ message: plan.reason === "backend_unreachable" ? `Could not reach Lody to verify this machine's credentials: ${plan.message}` : plan.message
214879
+ };
214880
+ }
214881
+ if (plan.action === "proceed") {
214882
+ logger2.success(`${chalk.green("\u2713")} Connected as ${chalk.cyan(plan.user.name || plan.user.email)}`);
214883
+ return {
214884
+ status: "authenticated",
214885
+ user: plan.user
214886
+ };
214887
+ }
214888
+ logger2.info(plan.reason === "credentials_rejected" ? "This machine is no longer signed in to Lody. Sign in again to connect it." : "This machine is not connected to Lody yet. Sign in to connect it.");
214889
+ const loginResult = await performLogin(authClient, logger2, {
214890
+ machineName
214891
+ });
214892
+ if (!loginResult.success) {
214893
+ return {
214894
+ status: "failed",
214895
+ reason: "login_failed",
214896
+ message: `Login failed: ${loginResult.error}`
214897
+ };
214898
+ }
214899
+ logger2.success(`${chalk.green("\u2713")} Connected as ${chalk.cyan(loginResult.user.name || loginResult.user.email)}`);
214900
+ return {
214901
+ status: "authenticated",
214902
+ user: loginResult.user
214903
+ };
214904
+ }
214511
214905
  function buildDaemonStartPassthroughArgs(options, unknownArgs) {
214512
214906
  const sanitized = [];
214513
214907
  for (let index = 0; index < unknownArgs.length; index += 1) {
@@ -214661,6 +215055,20 @@ ${result.stdout ?? ""}`;
214661
215055
  }
214662
215056
  }
214663
215057
  }
215058
+ function daemonAuthFailureHint(reason) {
215059
+ switch (reason) {
215060
+ case "backend_unreachable":
215061
+ return `Retry once the connection is back, or start anyway with ${chalk.yellow("--skip-auth-check")}.`;
215062
+ case "login_required_non_interactive":
215063
+ return `Run ${chalk.yellow("lody login")} from a terminal, or pass ${chalk.yellow("--auth <cli_token>")}.`;
215064
+ case "login_failed":
215065
+ return `Run ${chalk.yellow("lody login")} and retry.`;
215066
+ default: {
215067
+ const unreachable = reason;
215068
+ return unreachable;
215069
+ }
215070
+ }
215071
+ }
214664
215072
  function printStartTips() {
214665
215073
  console.log(`Use ${chalk.yellow("lody daemon status")} to check status`);
214666
215074
  console.log(`Use ${chalk.yellow("lody daemon stop")} to stop`);
@@ -214681,7 +215089,7 @@ ${result.stdout ?? ""}`;
214681
215089
  }
214682
215090
  return false;
214683
215091
  }
214684
- const daemonCommand = new Command("daemon").description("Run lody as a background daemon service").addCommand(new Command("start").description("Start lody daemon in the background").option("--auth <credential>", "Connect with a CLI API key or machine connection token").option("--machine-name <name>", "Machine name to register (defaults to hostname)").allowUnknownOption(true).action(async (options, cmd) => {
215092
+ const daemonCommand = new Command("daemon").description("Run lody as a background daemon service").addCommand(new Command("start").description("Start lody daemon in the background").option("--auth <credential>", "Connect with a CLI API key or machine connection token").option("--machine-name <name>", "Machine name to register (defaults to hostname)").option("--skip-auth-check", "Skip the backend connectivity and sign-in check before entering daemon mode").allowUnknownOption(true).action(async (options, cmd) => {
214685
215093
  const readiness = await checkDaemonStartReadiness();
214686
215094
  if (await reportDaemonStartBlocked(readiness, {
214687
215095
  restart: false
@@ -214689,20 +215097,46 @@ ${result.stdout ?? ""}`;
214689
215097
  return;
214690
215098
  }
214691
215099
  const passthroughArgs = buildDaemonStartPassthroughArgs(options, cmd.args);
214692
- if (options.auth) {
215100
+ const platformKind = getCliPlatformKind();
215101
+ if (platformKind === "local" && options.auth) {
215102
+ console.error("--auth is not available on the local platform.");
215103
+ await exitDaemonCommand(1);
215104
+ return;
215105
+ }
215106
+ if (platformKind === "cloud" && (options.auth || !options.skipAuthCheck)) {
214693
215107
  createHybridLogger({
214694
215108
  level: "info"
214695
215109
  });
214696
215110
  const logger2 = getLogger("daemon");
214697
215111
  const authClient = new AuthClient(logger2);
214698
- const loginResult = await performLoginWithAuthCredential(authClient, logger2, {
214699
- credential: options.auth,
214700
- machineName: options.machineName
214701
- });
214702
- if (!loginResult.success) {
214703
- console.error(loginResult.error);
214704
- await exitDaemonCommand(1);
214705
- return;
215112
+ if (options.auth) {
215113
+ const loginResult = await performLoginWithAuthCredential(authClient, logger2, {
215114
+ credential: options.auth,
215115
+ machineName: options.machineName
215116
+ });
215117
+ if (!loginResult.success) {
215118
+ captureDaemonEvent("daemon_start_failed", {
215119
+ reason_code: "auth_credential"
215120
+ });
215121
+ console.error(loginResult.error);
215122
+ await exitDaemonCommand(1);
215123
+ return;
215124
+ }
215125
+ } else {
215126
+ const preflight = await ensureDaemonBackendAuth({
215127
+ authClient,
215128
+ logger: logger2,
215129
+ machineName: options.machineName
215130
+ });
215131
+ if (preflight.status === "failed") {
215132
+ captureDaemonEvent("daemon_start_failed", {
215133
+ reason_code: preflight.reason
215134
+ });
215135
+ console.error(preflight.message);
215136
+ console.error(daemonAuthFailureHint(preflight.reason));
215137
+ await exitDaemonCommand(1);
215138
+ return;
215139
+ }
214706
215140
  }
214707
215141
  }
214708
215142
  captureDaemonEvent("daemon_start_requested");
@@ -214886,9 +215320,9 @@ ${result.stdout ?? ""}`;
214886
215320
  const passthroughArgs = cmd.args;
214887
215321
  captureDaemonEvent("daemon_restart_requested");
214888
215322
  const runningProbeHealth = await fetchLocalProbeHealth();
214889
- const versionMismatchHealth = runningProbeHealth && runningProbeHealth.cliVersion !== version$7 ? runningProbeHealth : null;
215323
+ const versionMismatchHealth = runningProbeHealth && runningProbeHealth.cliVersion !== version$8 ? runningProbeHealth : null;
214890
215324
  if (versionMismatchHealth) {
214891
- console.log(`Running daemon uses lody v${versionMismatchHealth.cliVersion}; current CLI is v${version$7}. Restarting with current CLI.`);
215325
+ console.log(`Running daemon uses lody v${versionMismatchHealth.cliVersion}; current CLI is v${version$8}. Restarting with current CLI.`);
214892
215326
  }
214893
215327
  const stopResult = await stopDaemonProcess();
214894
215328
  captureDaemonEvent("daemon_stop_result", {
@@ -215095,7 +215529,7 @@ ${result.stdout ?? ""}`;
215095
215529
  });
215096
215530
  logger2.info(`Daemon watchdog started (PID ${process.pid})`);
215097
215531
  await normalizeCurrentProcessResourceProfile(logger2);
215098
- for (const diagnostic of getRuntimeDiagnostics(version$7)) {
215532
+ for (const diagnostic of getRuntimeDiagnostics(version$8)) {
215099
215533
  logger2.info(diagnostic);
215100
215534
  }
215101
215535
  const passthroughArgs = cmd.args;
@@ -233492,7 +233926,7 @@ ${result.stdout ?? ""}`;
233492
233926
  cliToken: auth.token,
233493
233927
  source: "mcp",
233494
233928
  feedback: args2.feedback,
233495
- cliVersion: version$7
233929
+ cliVersion: version$8
233496
233930
  }));
233497
233931
  } catch (error2) {
233498
233932
  return mcpErrorResult(error2);
@@ -234214,7 +234648,7 @@ ${lines2.join("\n")}` : ""}${suffix}`);
234214
234648
  cliToken: auth.token,
234215
234649
  source: "cli",
234216
234650
  feedback,
234217
- cliVersion: version$7
234651
+ cliVersion: version$8
234218
234652
  });
234219
234653
  if (options.json) {
234220
234654
  printJson(result);
@@ -234298,7 +234732,7 @@ ${lines2.join("\n")}` : ""}${suffix}`);
234298
234732
  logger: getLogger("http-transport")
234299
234733
  });
234300
234734
  program = new Command();
234301
- program.name("lody").description("Lody Agent CLI tool for managing remote command execution").version(version$7, "-v, --version", "display version number").enablePositionalOptions();
234735
+ program.name("lody").description("Lody Agent CLI tool for managing remote command execution").version(version$8, "-v, --version", "display version number").enablePositionalOptions();
234302
234736
  program.addCommand(loginCommand);
234303
234737
  program.addCommand(logoutCommand);
234304
234738
  program.addCommand(startCommand);