@botiverse/raft-daemon 0.63.1 → 0.63.2-play.20260620140456

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.
@@ -1,6 +1,6 @@
1
1
  // src/core.ts
2
2
  import path18 from "path";
3
- import os9 from "os";
3
+ import os8 from "os";
4
4
  import { createRequire as createRequire3 } from "module";
5
5
  import { accessSync } from "fs";
6
6
  import { fileURLToPath } from "url";
@@ -1599,12 +1599,12 @@ var DISPLAY_PLAN_CONFIG = {
1599
1599
  var FREE_MONTHLY_FILE_UPLOAD_LIMIT_BYTES = 100 * 1024 * 1024;
1600
1600
 
1601
1601
  // src/agentProcessManager.ts
1602
- import { existsSync as existsSync9, mkdirSync as mkdirSync5, readFileSync as readFileSync6, readdirSync as readdirSync3, statSync, writeFileSync as writeFileSync4 } from "fs";
1602
+ import { existsSync as existsSync8, mkdirSync as mkdirSync4, readFileSync as readFileSync6, readdirSync as readdirSync4, statSync, writeFileSync as writeFileSync4 } from "fs";
1603
1603
  import { mkdir, writeFile, access, readdir as readdir2, stat as stat2, readFile, rm as rm2, lstat, realpath, open } from "fs/promises";
1604
1604
  import { createHash as createHash3, randomUUID as randomUUID5 } from "crypto";
1605
1605
  import path14 from "path";
1606
1606
  import { gzipSync } from "zlib";
1607
- import os7 from "os";
1607
+ import os6 from "os";
1608
1608
 
1609
1609
  // src/proxy.ts
1610
1610
  import { HttpsProxyAgent } from "https-proxy-agent";
@@ -2582,6 +2582,19 @@ function listLegacySlockStatePaths(slockHome = resolveSlockHome(), homeDir = os.
2582
2582
  return candidates.filter((candidate) => existsSync(candidate.path));
2583
2583
  }
2584
2584
 
2585
+ // src/authEnv.ts
2586
+ var DAEMON_API_KEY_ENV = "SLOCK_MACHINE_API_KEY";
2587
+ var SLOCK_AGENT_TOKEN_ENV = "SLOCK_AGENT_TOKEN";
2588
+ function scrubDaemonAuthEnv(env) {
2589
+ delete env[DAEMON_API_KEY_ENV];
2590
+ return env;
2591
+ }
2592
+ function scrubDaemonChildEnv(env) {
2593
+ delete env[DAEMON_API_KEY_ENV];
2594
+ delete env[SLOCK_AGENT_TOKEN_ENV];
2595
+ return env;
2596
+ }
2597
+
2585
2598
  // src/agentCredentialProxy.ts
2586
2599
  import { randomBytes } from "crypto";
2587
2600
  import http from "http";
@@ -4148,7 +4161,9 @@ var LOOPBACK_NO_PROXY = "127.0.0.1,localhost";
4148
4161
  var CLI_TRANSPORT_TRACE_DIR_ENV = "SLOCK_CLI_TRANSPORT_TRACE_DIR";
4149
4162
  var safePathPart = (value) => value.replace(/[^a-zA-Z0-9_.-]/g, "_");
4150
4163
  var RAW_CREDENTIAL_ENV_DENYLIST = [
4151
- "SLOCK_AGENT_CREDENTIAL_KEY"
4164
+ "SLOCK_AGENT_TOKEN",
4165
+ "SLOCK_AGENT_CREDENTIAL_KEY",
4166
+ "SLOCK_AGENT_CREDENTIAL_KEY_FILE"
4152
4167
  ];
4153
4168
  var WORKSPACE_CLI_TRANSPORT_FILENAMES = [
4154
4169
  "agent-token",
@@ -4500,7 +4515,7 @@ set "SLOCK_AGENT_ACTIVE_CAPABILITIES=${DEFAULT_ACTIVE_CAPABILITIES}"\r
4500
4515
  SLOCK_SERVER_URL: ctx.config.serverUrl,
4501
4516
  PATH: `${slockDir}${path2.delimiter}${process.env.PATH ?? ""}`
4502
4517
  };
4503
- delete spawnEnv.SLOCK_AGENT_TOKEN;
4518
+ scrubDaemonChildEnv(spawnEnv);
4504
4519
  for (const key of RAW_CREDENTIAL_ENV_DENYLIST) {
4505
4520
  delete spawnEnv[key];
4506
4521
  }
@@ -4769,12 +4784,101 @@ var ClaudeEventNormalizer = class {
4769
4784
 
4770
4785
  // src/drivers/claudeLaunch.ts
4771
4786
  import { writeFileSync as writeFileSync2 } from "fs";
4772
- import path4 from "path";
4787
+ import path5 from "path";
4788
+
4789
+ // src/drivers/claudeProviderIsolation.ts
4790
+ import { readdirSync as readdirSync2 } from "fs";
4791
+ import path3 from "path";
4792
+ var LEGACY_CLAUDE_PROVIDER_CONFIG_DIR = path3.join(".slock", "claude-provider", "home", ".claude");
4793
+ var warnedLegacyClaudeProviderConfigDirs = /* @__PURE__ */ new Set();
4794
+ var CLAUDE_CUSTOM_PROVIDER_HOST_ENV_KEYS = [
4795
+ "ANTHROPIC_AUTH_TOKEN",
4796
+ "ANTHROPIC_CUSTOM_HEADERS",
4797
+ "CLAUDE_CODE_OAUTH_TOKEN",
4798
+ "CLAUDE_CODE_OAUTH_TOKEN_FILE_DESCRIPTOR",
4799
+ "ANTHROPIC_FEDERATION_RULE_ID",
4800
+ "ANTHROPIC_ORGANIZATION_ID",
4801
+ "ANTHROPIC_MODEL",
4802
+ "ANTHROPIC_SMALL_FAST_MODEL",
4803
+ "ANTHROPIC_SMALL_FAST_MODEL_AWS_REGION",
4804
+ "CLAUDE_CODE_USE_BEDROCK",
4805
+ "CLAUDE_CODE_SKIP_BEDROCK_AUTH",
4806
+ "AWS_BEARER_TOKEN_BEDROCK",
4807
+ "ANTHROPIC_BEDROCK_BASE_URL",
4808
+ "ANTHROPIC_BEDROCK_SERVICE_TIER",
4809
+ "CLAUDE_CODE_USE_MANTLE",
4810
+ "CLAUDE_CODE_SKIP_MANTLE_AUTH",
4811
+ "ANTHROPIC_BEDROCK_MANTLE_API_KEY",
4812
+ "ANTHROPIC_BEDROCK_MANTLE_BASE_URL",
4813
+ "CLAUDE_CODE_USE_VERTEX",
4814
+ "CLAUDE_CODE_SKIP_VERTEX_AUTH",
4815
+ "ANTHROPIC_VERTEX_PROJECT_ID",
4816
+ "ANTHROPIC_VERTEX_BASE_URL",
4817
+ "CLOUD_ML_REGION",
4818
+ "CLAUDE_CODE_USE_FOUNDRY",
4819
+ "CLAUDE_CODE_SKIP_FOUNDRY_AUTH",
4820
+ "ANTHROPIC_FOUNDRY_API_KEY",
4821
+ "ANTHROPIC_FOUNDRY_AUTH_TOKEN",
4822
+ "ANTHROPIC_FOUNDRY_RESOURCE",
4823
+ "ANTHROPIC_FOUNDRY_BASE_URL",
4824
+ "CLAUDE_CODE_USE_ANTHROPIC_AWS",
4825
+ "CLAUDE_CODE_SKIP_ANTHROPIC_AWS_AUTH",
4826
+ "CLAUDE_CODE_USE_GATEWAY",
4827
+ "CLAUDE_CODE_USE_CCR_V2"
4828
+ ];
4829
+ function isClaudeCustomProviderConfig(config) {
4830
+ const launchRuntimeFields = runtimeConfigToLaunchFields(config);
4831
+ return launchRuntimeFields.runtime === "claude" && Boolean(launchRuntimeFields.envVars?.ANTHROPIC_BASE_URL) && Boolean(launchRuntimeFields.envVars?.ANTHROPIC_API_KEY);
4832
+ }
4833
+ function clearInheritedClaudeProviderEnv(explicitEnv) {
4834
+ const env = {};
4835
+ for (const key of CLAUDE_CUSTOM_PROVIDER_HOST_ENV_KEYS) {
4836
+ if (!Object.prototype.hasOwnProperty.call(explicitEnv ?? {}, key)) {
4837
+ env[key] = void 0;
4838
+ }
4839
+ }
4840
+ return env;
4841
+ }
4842
+ var LEGACY_CLAUDE_PROVIDER_CONFIG_ENTRIES = /* @__PURE__ */ new Set([
4843
+ "agents",
4844
+ "commands",
4845
+ "projects",
4846
+ "settings.json",
4847
+ "skills",
4848
+ "todos"
4849
+ ]);
4850
+ function hasLegacyClaudeProviderConfigEntry(directory) {
4851
+ try {
4852
+ return readdirSync2(directory).some((entry) => LEGACY_CLAUDE_PROVIDER_CONFIG_ENTRIES.has(entry));
4853
+ } catch {
4854
+ return false;
4855
+ }
4856
+ }
4857
+ function shouldWarnLegacyClaudeProviderConfigDir(workingDirectory) {
4858
+ const legacyConfigDir = path3.resolve(workingDirectory, LEGACY_CLAUDE_PROVIDER_CONFIG_DIR);
4859
+ if (!hasLegacyClaudeProviderConfigEntry(legacyConfigDir)) {
4860
+ return false;
4861
+ }
4862
+ if (warnedLegacyClaudeProviderConfigDirs.has(legacyConfigDir)) {
4863
+ return false;
4864
+ }
4865
+ warnedLegacyClaudeProviderConfigDirs.add(legacyConfigDir);
4866
+ return true;
4867
+ }
4868
+ function buildClaudeProviderIsolationEnv(ctx) {
4869
+ if (!isClaudeCustomProviderConfig(ctx.config)) {
4870
+ return {};
4871
+ }
4872
+ const launchRuntimeFields = runtimeConfigToLaunchFields(ctx.config);
4873
+ return {
4874
+ ...clearInheritedClaudeProviderEnv(launchRuntimeFields.envVars)
4875
+ };
4876
+ }
4773
4877
 
4774
4878
  // src/drivers/probe.ts
4775
4879
  import { execFileSync } from "child_process";
4776
4880
  import { existsSync as existsSync3 } from "fs";
4777
- import path3 from "path";
4881
+ import path4 from "path";
4778
4882
  function normalizeExecOutput(raw) {
4779
4883
  return Buffer.isBuffer(raw) ? raw.toString("utf8") : String(raw ?? "");
4780
4884
  }
@@ -4907,13 +5011,13 @@ function resolveCommandOnWindows(command, env, execFileSyncFn, existsSyncFn) {
4907
5011
  if (!resolved) return null;
4908
5012
  const lowerResolved = resolved.toLowerCase();
4909
5013
  if (lowerResolved.endsWith(".ps1")) {
4910
- const dir = path3.dirname(resolved);
4911
- const base = path3.basename(resolved, ".ps1");
5014
+ const dir = path4.dirname(resolved);
5015
+ const base = path4.basename(resolved, ".ps1");
4912
5016
  const alternatives = [
4913
- path3.join(dir, `${base}.cmd`),
4914
- path3.join(dir, `${base}.bat`),
4915
- path3.join(dir, `${base}.exe`),
4916
- path3.join(dir, base)
5017
+ path4.join(dir, `${base}.cmd`),
5018
+ path4.join(dir, `${base}.bat`),
5019
+ path4.join(dir, `${base}.exe`),
5020
+ path4.join(dir, base)
4917
5021
  ];
4918
5022
  for (const alt of alternatives) {
4919
5023
  if (existsSyncFn(alt)) return alt;
@@ -4933,7 +5037,7 @@ function requiresWindowsShell(command, platform = process.platform) {
4933
5037
  }
4934
5038
  function resolveCommandOnPath(command, deps = {}) {
4935
5039
  const platform = deps.platform ?? process.platform;
4936
- const env = withWindowsUserEnvironment(deps.env ?? process.env, deps);
5040
+ const env = scrubDaemonChildEnv({ ...withWindowsUserEnvironment(deps.env ?? process.env, deps) });
4937
5041
  const execFileSyncFn = deps.execFileSyncFn ?? execFileSync;
4938
5042
  const existsSyncFn = deps.existsSyncFn ?? existsSync3;
4939
5043
  if (platform === "win32") {
@@ -4959,7 +5063,7 @@ function firstExistingPath(candidates, deps = {}) {
4959
5063
  return null;
4960
5064
  }
4961
5065
  function readCommandVersion(command, args = [], deps = {}) {
4962
- const env = withWindowsUserEnvironment(deps.env ?? process.env, deps);
5066
+ const env = scrubDaemonChildEnv({ ...withWindowsUserEnvironment(deps.env ?? process.env, deps) });
4963
5067
  const execFileSyncFn = deps.execFileSyncFn ?? execFileSync;
4964
5068
  try {
4965
5069
  const output = normalizeExecOutput(execFileSyncFn(command, [...args, "--version"], {
@@ -4974,11 +5078,11 @@ function readCommandVersion(command, args = [], deps = {}) {
4974
5078
  }
4975
5079
  function resolveHomePath(relativePath, deps = {}) {
4976
5080
  const homeDir = deps.homeDir ?? deps.env?.HOME ?? process.env.HOME ?? "";
4977
- return path3.join(homeDir, relativePath);
5081
+ return path4.join(homeDir, relativePath);
4978
5082
  }
4979
5083
 
4980
5084
  // src/drivers/claudeLaunch.ts
4981
- var CLAUDE_DESKTOP_CLI_RELATIVE_PATH = path4.join("Applications", "Claude Code URL Handler.app", "Contents", "MacOS", "claude");
5085
+ var CLAUDE_DESKTOP_CLI_RELATIVE_PATH = path5.join("Applications", "Claude Code URL Handler.app", "Contents", "MacOS", "claude");
4982
5086
  var CLAUDE_DESKTOP_CLI_SYSTEM_PATH = "/Applications/Claude Code URL Handler.app/Contents/MacOS/claude";
4983
5087
  var CLAUDE_SYSTEM_PROMPT_FILE = "claude-system-prompt.md";
4984
5088
  var CLAUDE_DISALLOWED_TOOLS = [
@@ -5033,6 +5137,9 @@ function buildClaudeArgs(config, opts) {
5033
5137
  if (launchRuntimeFields.reasoningEffort) {
5034
5138
  args.push("--effort", launchRuntimeFields.reasoningEffort);
5035
5139
  }
5140
+ if (isClaudeCustomProviderConfig(config)) {
5141
+ args.push("--setting-sources", "project,local");
5142
+ }
5036
5143
  if (launchRuntimeFields.mode.kind === "fast") {
5037
5144
  args.push("--settings", JSON.stringify({ fastMode: true }));
5038
5145
  }
@@ -5042,7 +5149,7 @@ function buildClaudeArgs(config, opts) {
5042
5149
  return args;
5043
5150
  }
5044
5151
  function writeClaudeSystemPromptFile(standingPrompt, slockDir) {
5045
- const systemPromptPath = path4.join(slockDir, CLAUDE_SYSTEM_PROMPT_FILE);
5152
+ const systemPromptPath = path5.join(slockDir, CLAUDE_SYSTEM_PROMPT_FILE);
5046
5153
  writeFileSync2(systemPromptPath, standingPrompt, { mode: 384 });
5047
5154
  return systemPromptPath;
5048
5155
  }
@@ -5057,52 +5164,6 @@ function buildClaudeSpawnSpec(claudeCommand, platform = process.platform) {
5057
5164
  };
5058
5165
  }
5059
5166
 
5060
- // src/drivers/claudeProviderIsolation.ts
5061
- import { existsSync as existsSync4, mkdirSync as mkdirSync2, symlinkSync } from "fs";
5062
- import os2 from "os";
5063
- import path5 from "path";
5064
- function isClaudeCustomProviderConfig(config) {
5065
- const launchRuntimeFields = runtimeConfigToLaunchFields(config);
5066
- return launchRuntimeFields.runtime === "claude" && Boolean(launchRuntimeFields.envVars?.ANTHROPIC_BASE_URL) && Boolean(launchRuntimeFields.envVars?.ANTHROPIC_API_KEY);
5067
- }
5068
- function getClaudeProviderStatePaths(workingDirectory) {
5069
- const root = path5.join(workingDirectory, ".slock", "claude-provider");
5070
- const home = path5.join(root, "home");
5071
- return {
5072
- root,
5073
- home,
5074
- configDir: path5.join(home, ".claude")
5075
- };
5076
- }
5077
- function linkIfPresent(source, target) {
5078
- try {
5079
- if (!existsSync4(source) || existsSync4(target)) return;
5080
- mkdirSync2(path5.dirname(target), { recursive: true, mode: 448 });
5081
- symlinkSync(source, target, "dir");
5082
- } catch {
5083
- }
5084
- }
5085
- function ensureClaudeProviderStatePaths(workingDirectory, hostClaudeHome = path5.join(os2.homedir(), ".claude")) {
5086
- const paths = getClaudeProviderStatePaths(workingDirectory);
5087
- mkdirSync2(paths.home, { recursive: true, mode: 448 });
5088
- mkdirSync2(paths.configDir, { recursive: true, mode: 448 });
5089
- linkIfPresent(path5.join(hostClaudeHome, "skills"), path5.join(paths.configDir, "skills"));
5090
- linkIfPresent(path5.join(hostClaudeHome, "commands"), path5.join(paths.configDir, "commands"));
5091
- return paths;
5092
- }
5093
- function buildClaudeProviderIsolationEnv(ctx) {
5094
- if (!isClaudeCustomProviderConfig(ctx.config)) {
5095
- return {};
5096
- }
5097
- const paths = ensureClaudeProviderStatePaths(ctx.workingDirectory);
5098
- return {
5099
- HOME: paths.home,
5100
- USERPROFILE: paths.home,
5101
- CLAUDE_CONFIG_DIR: paths.configDir,
5102
- CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST: "1"
5103
- };
5104
- }
5105
-
5106
5167
  // src/drivers/claude.ts
5107
5168
  var ClaudeDriver = class {
5108
5169
  id = "claude";
@@ -5140,6 +5201,11 @@ var ClaudeDriver = class {
5140
5201
  ctx,
5141
5202
  buildClaudeProviderIsolationEnv(ctx)
5142
5203
  );
5204
+ if (isClaudeCustomProviderConfig(ctx.config) && shouldWarnLegacyClaudeProviderConfigDir(ctx.workingDirectory)) {
5205
+ logger.warn(
5206
+ `[Agent ${ctx.agentId}] Legacy Claude custom-provider config directory ${LEGACY_CLAUDE_PROVIDER_CONFIG_DIR} is no longer used; custom-provider Claude now uses host Claude state plus explicit provider env.`
5207
+ );
5208
+ }
5143
5209
  const systemPromptPath = writeClaudeSystemPromptFile(ctx.standingPrompt, slockDir);
5144
5210
  const args = this.buildClaudeArgs(ctx.config, {
5145
5211
  standingPromptFilePath: systemPromptPath
@@ -5197,12 +5263,12 @@ var ClaudeDriver = class {
5197
5263
 
5198
5264
  // src/drivers/codex.ts
5199
5265
  import { spawn as spawn2, execFileSync as execFileSync2 } from "child_process";
5200
- import { existsSync as existsSync5, readFileSync as readFileSync2 } from "fs";
5201
- import os4 from "os";
5266
+ import { existsSync as existsSync4, readFileSync as readFileSync2 } from "fs";
5267
+ import os3 from "os";
5202
5268
  import path7 from "path";
5203
5269
 
5204
5270
  // src/drivers/codexHome.ts
5205
- import os3 from "os";
5271
+ import os2 from "os";
5206
5272
  import path6 from "path";
5207
5273
  function readConfiguredCodexHome(env) {
5208
5274
  const raw = env.CODEX_HOME;
@@ -5213,7 +5279,7 @@ function resolveCodexHomeRootFromEnv(env = process.env, opts = {}) {
5213
5279
  if (raw) {
5214
5280
  return path6.resolve(opts.cwd ?? process.cwd(), raw);
5215
5281
  }
5216
- return path6.join(opts.defaultHomeDir ?? os3.homedir(), ".codex");
5282
+ return path6.join(opts.defaultHomeDir ?? os2.homedir(), ".codex");
5217
5283
  }
5218
5284
  function hasConfiguredCodexHome(config, baseEnv = process.env) {
5219
5285
  const launchRuntimeFields = config ? runtimeConfigToLaunchFields(config) : null;
@@ -5844,7 +5910,7 @@ function isWindowsSandboxRunner(commandPath) {
5844
5910
  return path7.basename(commandPath).toLowerCase().startsWith("codex-command-runner");
5845
5911
  }
5846
5912
  function resolveWindowsNpmCodexEntry(deps = {}) {
5847
- const existsSyncFn = deps.existsSyncFn ?? existsSync5;
5913
+ const existsSyncFn = deps.existsSyncFn ?? existsSync4;
5848
5914
  const execFileSyncFn = deps.execFileSyncFn ?? execFileSync2;
5849
5915
  const env = deps.env ?? process.env;
5850
5916
  const winPath = path7.win32;
@@ -5866,7 +5932,7 @@ function resolveWindowsNpmCodexEntry(deps = {}) {
5866
5932
  return null;
5867
5933
  }
5868
5934
  function resolveWindowsCodexDesktopEntry(deps = {}) {
5869
- const existsSyncFn = deps.existsSyncFn ?? existsSync5;
5935
+ const existsSyncFn = deps.existsSyncFn ?? existsSync4;
5870
5936
  const env = deps.env ?? process.env;
5871
5937
  const homeDir = deps.homeDir;
5872
5938
  const winPath = path7.win32;
@@ -6194,7 +6260,7 @@ var CodexDriver = class {
6194
6260
  this.normalizer.reset();
6195
6261
  this.spawnWorkingDirectory = ctx.workingDirectory;
6196
6262
  this.codexHomeRoot = resolveCodexHomeRootFromEnv(spawnEnv, {
6197
- defaultHomeDir: os4.homedir(),
6263
+ defaultHomeDir: os3.homedir(),
6198
6264
  cwd: ctx.workingDirectory
6199
6265
  });
6200
6266
  const args = ["app-server", "--listen", "stdio://"];
@@ -6618,7 +6684,7 @@ function detectCodexModels(home = resolveCodexHomeRootFromEnv()) {
6618
6684
  let configPath = null;
6619
6685
  for (const root of codexStateRootCandidates(home)) {
6620
6686
  const candidate = path7.join(root, "models_cache.json");
6621
- if (existsSync5(candidate)) {
6687
+ if (existsSync4(candidate)) {
6622
6688
  cachePath = candidate;
6623
6689
  configPath = path7.join(root, "config.toml");
6624
6690
  break;
@@ -7077,11 +7143,11 @@ function detectCursorModels(runCommand = runCursorModelsCommand) {
7077
7143
  return parseCursorModelsOutput(String(result.stdout || ""));
7078
7144
  }
7079
7145
  function buildCursorModelProbeEnv(deps = {}) {
7080
- return withWindowsUserEnvironment({
7146
+ return scrubDaemonChildEnv(withWindowsUserEnvironment({
7081
7147
  ...deps.env ?? process.env,
7082
7148
  FORCE_COLOR: "0",
7083
7149
  NO_COLOR: "1"
7084
- }, deps);
7150
+ }, deps));
7085
7151
  }
7086
7152
  function runCursorModelsCommand() {
7087
7153
  return spawnSync("cursor-agent", ["models"], {
@@ -7093,7 +7159,7 @@ function runCursorModelsCommand() {
7093
7159
 
7094
7160
  // src/drivers/gemini.ts
7095
7161
  import { execFileSync as execFileSync3, spawn as spawn6 } from "child_process";
7096
- import { existsSync as existsSync6 } from "fs";
7162
+ import { existsSync as existsSync5 } from "fs";
7097
7163
  import path8 from "path";
7098
7164
  async function buildGeminiSpawnEnv(ctx, platform = process.platform) {
7099
7165
  const { spawnEnv } = await prepareCliTransport(ctx, { NO_COLOR: "1" }, platform);
@@ -7136,8 +7202,8 @@ function resolveGeminiSpawn(commandArgs, deps = {}) {
7136
7202
  return { command: resolveCommandOnPath("gemini", deps) ?? "gemini", args: commandArgs };
7137
7203
  }
7138
7204
  const execFileSyncFn = deps.execFileSyncFn ?? execFileSync3;
7139
- const existsSyncFn = deps.existsSyncFn ?? existsSync6;
7140
- const env = deps.env ?? process.env;
7205
+ const existsSyncFn = deps.existsSyncFn ?? existsSync5;
7206
+ const env = scrubDaemonChildEnv({ ...deps.env ?? process.env });
7141
7207
  const winPath = path8.win32;
7142
7208
  let geminiEntry = null;
7143
7209
  try {
@@ -7274,12 +7340,15 @@ var GeminiDriver = class {
7274
7340
  // src/drivers/kimi.ts
7275
7341
  import { randomUUID as randomUUID2 } from "crypto";
7276
7342
  import { spawn as spawn7 } from "child_process";
7277
- import { existsSync as existsSync7, readFileSync as readFileSync3, writeFileSync as writeFileSync3 } from "fs";
7278
- import os5 from "os";
7343
+ import { chmodSync, existsSync as existsSync6, readFileSync as readFileSync3, writeFileSync as writeFileSync3 } from "fs";
7344
+ import os4 from "os";
7279
7345
  import path9 from "path";
7280
7346
  var KIMI_WIRE_PROTOCOL_VERSION = "1.3";
7281
7347
  var KIMI_SYSTEM_PROMPT_FILE = ".slock-kimi-system.md";
7282
7348
  var KIMI_AGENT_FILE = ".slock-kimi-agent.yaml";
7349
+ var KIMI_GENERATED_CONFIG_FILE = ".slock-kimi-config.toml";
7350
+ var SLOCK_KIMI_CONFIG_CONTENT_ENV = "SLOCK_KIMI_CONFIG_CONTENT";
7351
+ var SLOCK_KIMI_CONFIG_FILE_ENV = "SLOCK_KIMI_CONFIG_FILE";
7283
7352
  function parseToolArguments(raw) {
7284
7353
  if (typeof raw !== "string") return raw;
7285
7354
  try {
@@ -7288,6 +7357,73 @@ function parseToolArguments(raw) {
7288
7357
  return raw;
7289
7358
  }
7290
7359
  }
7360
+ function readKimiConfigSource(home = os4.homedir(), env = process.env) {
7361
+ const inlineConfig = env[SLOCK_KIMI_CONFIG_CONTENT_ENV];
7362
+ if (inlineConfig && inlineConfig.trim()) {
7363
+ return {
7364
+ raw: inlineConfig,
7365
+ explicitPath: null,
7366
+ sourcePath: SLOCK_KIMI_CONFIG_CONTENT_ENV
7367
+ };
7368
+ }
7369
+ const explicitPath = env[SLOCK_KIMI_CONFIG_FILE_ENV];
7370
+ const configPath = explicitPath && explicitPath.trim() ? explicitPath : path9.join(home, ".kimi", "config.toml");
7371
+ try {
7372
+ return {
7373
+ raw: readFileSync3(configPath, "utf8"),
7374
+ explicitPath: explicitPath && explicitPath.trim() ? explicitPath : null,
7375
+ sourcePath: configPath
7376
+ };
7377
+ } catch {
7378
+ return {
7379
+ raw: null,
7380
+ explicitPath: explicitPath && explicitPath.trim() ? explicitPath : null,
7381
+ sourcePath: configPath
7382
+ };
7383
+ }
7384
+ }
7385
+ function buildKimiSpawnEnv(env = process.env) {
7386
+ const spawnEnv = { ...env, FORCE_COLOR: "0", NO_COLOR: "1" };
7387
+ delete spawnEnv[SLOCK_KIMI_CONFIG_CONTENT_ENV];
7388
+ delete spawnEnv[SLOCK_KIMI_CONFIG_FILE_ENV];
7389
+ return scrubDaemonChildEnv(spawnEnv);
7390
+ }
7391
+ function buildKimiEffectiveEnv(ctx, overrideEnv) {
7392
+ return {
7393
+ ...process.env,
7394
+ ...ctx.config.envVars || {},
7395
+ ...overrideEnv || {}
7396
+ };
7397
+ }
7398
+ function buildKimiLaunchOptions(ctx, opts = {}) {
7399
+ const env = buildKimiEffectiveEnv(ctx, opts.env);
7400
+ const source = readKimiConfigSource(opts.home ?? os4.homedir(), env);
7401
+ const args = [];
7402
+ let configFilePath = null;
7403
+ let configContent = null;
7404
+ if (source.explicitPath) {
7405
+ configFilePath = source.explicitPath;
7406
+ } else if (source.raw !== null && source.sourcePath === SLOCK_KIMI_CONFIG_CONTENT_ENV) {
7407
+ configFilePath = path9.join(ctx.workingDirectory, KIMI_GENERATED_CONFIG_FILE);
7408
+ configContent = source.raw;
7409
+ if (opts.writeGeneratedConfig !== false) {
7410
+ writeFileSync3(configFilePath, source.raw, { encoding: "utf8", mode: 384 });
7411
+ chmodSync(configFilePath, 384);
7412
+ }
7413
+ }
7414
+ if (configFilePath) {
7415
+ args.push("--config-file", configFilePath);
7416
+ }
7417
+ if (ctx.config.model && ctx.config.model !== "default") {
7418
+ args.push("--model", ctx.config.model);
7419
+ }
7420
+ return {
7421
+ args,
7422
+ env: buildKimiSpawnEnv(env),
7423
+ configFilePath,
7424
+ configContent
7425
+ };
7426
+ }
7291
7427
  function resolveKimiSpawn(commandArgs, deps = {}) {
7292
7428
  return {
7293
7429
  command: resolveCommandOnPath("kimi", deps) ?? "kimi",
@@ -7311,7 +7447,25 @@ var KimiDriver = class {
7311
7447
  };
7312
7448
  model = {
7313
7449
  detectedModelsVerifiedAs: "launchable",
7314
- toLaunchSpec: (modelId) => ({ args: ["--model", modelId] })
7450
+ toLaunchSpec: (modelId, ctx, opts) => {
7451
+ if (!ctx) return { args: ["--model", modelId] };
7452
+ const launchCtx = {
7453
+ ...ctx,
7454
+ config: {
7455
+ ...ctx.config,
7456
+ model: modelId
7457
+ }
7458
+ };
7459
+ const launch = buildKimiLaunchOptions(launchCtx, {
7460
+ home: opts?.home,
7461
+ writeGeneratedConfig: false
7462
+ });
7463
+ return {
7464
+ args: launch.args,
7465
+ env: launch.env,
7466
+ configFiles: launch.configFilePath ? [launch.configFilePath] : void 0
7467
+ };
7468
+ }
7315
7469
  };
7316
7470
  supportsStdinNotification = true;
7317
7471
  busyDeliveryMode = "direct";
@@ -7325,7 +7479,7 @@ var KimiDriver = class {
7325
7479
  this.promptRequestId = randomUUID2();
7326
7480
  const systemPromptPath = path9.join(ctx.workingDirectory, KIMI_SYSTEM_PROMPT_FILE);
7327
7481
  const agentFilePath = path9.join(ctx.workingDirectory, KIMI_AGENT_FILE);
7328
- if (!isResume || !existsSync7(systemPromptPath)) {
7482
+ if (!isResume || !existsSync6(systemPromptPath)) {
7329
7483
  writeFileSync3(systemPromptPath, ctx.prompt, "utf8");
7330
7484
  }
7331
7485
  writeFileSync3(agentFilePath, [
@@ -7335,21 +7489,23 @@ var KimiDriver = class {
7335
7489
  ` system_prompt_path: ./${KIMI_SYSTEM_PROMPT_FILE}`,
7336
7490
  ""
7337
7491
  ].join("\n"), "utf8");
7492
+ const launch = buildKimiLaunchOptions(ctx);
7338
7493
  const args = [
7339
7494
  "--wire",
7340
7495
  "--yolo",
7341
7496
  "--agent-file",
7342
7497
  agentFilePath,
7343
7498
  "--session",
7344
- this.sessionId
7499
+ this.sessionId,
7500
+ ...launch.args
7345
7501
  ];
7346
7502
  const launchRuntimeFields = runtimeConfigToLaunchFields(ctx.config);
7347
7503
  if (launchRuntimeFields.model && launchRuntimeFields.model !== "default") {
7348
7504
  args.push("--model", launchRuntimeFields.model);
7349
7505
  }
7350
7506
  const spawnEnv = (await prepareCliTransport(ctx, { NO_COLOR: "1" })).spawnEnv;
7351
- const launch = resolveKimiSpawn(args);
7352
- const proc = spawn7(launch.command, launch.args, {
7507
+ const spawnTarget = resolveKimiSpawn(args);
7508
+ const proc = spawn7(spawnTarget.command, spawnTarget.args, {
7353
7509
  cwd: ctx.workingDirectory,
7354
7510
  stdio: ["pipe", "pipe", "pipe"],
7355
7511
  env: spawnEnv,
@@ -7357,7 +7513,7 @@ var KimiDriver = class {
7357
7513
  // and has an 8191-character command-line limit. Kimi's official
7358
7514
  // installer/uv entrypoint is an executable, so launch it directly and
7359
7515
  // keep prompts on stdin / files instead of routing through cmd.exe.
7360
- shell: launch.shell
7516
+ shell: spawnTarget.shell
7361
7517
  });
7362
7518
  proc.stdin?.write(JSON.stringify({
7363
7519
  jsonrpc: "2.0",
@@ -7470,14 +7626,9 @@ var KimiDriver = class {
7470
7626
  return detectKimiModels();
7471
7627
  }
7472
7628
  };
7473
- function detectKimiModels(home = os5.homedir()) {
7474
- const configPath = path9.join(home, ".kimi", "config.toml");
7475
- let raw;
7476
- try {
7477
- raw = readFileSync3(configPath, "utf8");
7478
- } catch {
7479
- return null;
7480
- }
7629
+ function detectKimiModels(home = os4.homedir(), opts = {}) {
7630
+ const raw = readKimiConfigSource(home, opts.env).raw;
7631
+ if (raw === null) return null;
7481
7632
  const models = [];
7482
7633
  const sectionRe = /^\s*\[models(?:\.([^\]]+)|"\.[^"]+"|\."[^"]+")\s*\]\s*$/gm;
7483
7634
  const lineRe = /^\s*\[models\.(.+?)\s*\]\s*$/gm;
@@ -7499,7 +7650,7 @@ function detectKimiModels(home = os5.homedir()) {
7499
7650
  // src/drivers/kimi-sdk.ts
7500
7651
  import { randomUUID as randomUUID3 } from "crypto";
7501
7652
  import { EventEmitter } from "events";
7502
- import { mkdirSync as mkdirSync3, readFileSync as readFileSync4 } from "fs";
7653
+ import { mkdirSync as mkdirSync2, readFileSync as readFileSync4 } from "fs";
7503
7654
  import path10 from "path";
7504
7655
  import { createRequire as createRequire2 } from "module";
7505
7656
  import {
@@ -7648,12 +7799,12 @@ var KIMI_SDK_RUNTIME_SESSION_DESCRIPTOR = {
7648
7799
  };
7649
7800
  async function createKimiAgentSessionForContext(ctx, sessionId) {
7650
7801
  const sessionDir = buildKimiSessionDir(ctx.workingDirectory);
7651
- mkdirSync3(sessionDir, { recursive: true });
7802
+ mkdirSync2(sessionDir, { recursive: true });
7652
7803
  const cliTransport = await prepareCliTransport(ctx, { NO_COLOR: "1" });
7653
7804
  const spawnEnv = cliTransport.spawnEnv;
7654
7805
  const wrapperPath = cliTransport.wrapperPath;
7655
7806
  const homeDir = spawnEnv.KIMI_HOME || (process.env.HOME ? path10.join(process.env.HOME, ".kimi") : path10.join(ctx.workingDirectory, ".kimi"));
7656
- mkdirSync3(homeDir, { recursive: true });
7807
+ mkdirSync2(homeDir, { recursive: true });
7657
7808
  const harness = createKimiHarness({
7658
7809
  homeDir,
7659
7810
  identity: {
@@ -7984,8 +8135,8 @@ var KimiSdkDriver = class {
7984
8135
 
7985
8136
  // src/drivers/opencode.ts
7986
8137
  import { spawn as spawn8, spawnSync as spawnSync2 } from "child_process";
7987
- import { existsSync as existsSync8, readFileSync as readFileSync5 } from "fs";
7988
- import os6 from "os";
8138
+ import { existsSync as existsSync7, readFileSync as readFileSync5 } from "fs";
8139
+ import os5 from "os";
7989
8140
  import path11 from "path";
7990
8141
  var SLOCK_AGENT_NAME = "slock";
7991
8142
  var NO_MESSAGE_PROMPT = "No new messages are pending. Stop now.";
@@ -8014,7 +8165,7 @@ function parseUserOpenCodeConfig(ctx) {
8014
8165
  const raw = runtimeConfigToLaunchFields(ctx.config).envVars?.OPENCODE_CONFIG_CONTENT;
8015
8166
  return parseOpenCodeConfigContent(raw);
8016
8167
  }
8017
- function readLocalOpenCodeConfig(home = os6.homedir()) {
8168
+ function readLocalOpenCodeConfig(home = os5.homedir()) {
8018
8169
  const configPath = path11.join(home, ".config", "opencode", "opencode.json");
8019
8170
  try {
8020
8171
  return parseOpenCodeConfigContent(readFileSync5(configPath, "utf8"));
@@ -8075,7 +8226,7 @@ function mergeOpenCodeConfigs(localConfig, envConfig) {
8075
8226
  }
8076
8227
  };
8077
8228
  }
8078
- function buildOpenCodeConfig(ctx, home = os6.homedir()) {
8229
+ function buildOpenCodeConfig(ctx, home = os5.homedir()) {
8079
8230
  const userConfig = mergeOpenCodeConfigs(readLocalOpenCodeConfig(home), parseUserOpenCodeConfig(ctx));
8080
8231
  const userAgents = recordField(userConfig.agent);
8081
8232
  const userSlockAgent = recordField(userAgents[SLOCK_AGENT_NAME]);
@@ -8093,7 +8244,7 @@ function buildOpenCodeConfig(ctx, home = os6.homedir()) {
8093
8244
  mcp: recordField(userConfig.mcp)
8094
8245
  };
8095
8246
  }
8096
- async function buildOpenCodeLaunchOptions(ctx, home = os6.homedir(), version = null) {
8247
+ async function buildOpenCodeLaunchOptions(ctx, home = os5.homedir(), version = null) {
8097
8248
  const slock = await prepareCliTransport(ctx, { NO_COLOR: "1" });
8098
8249
  const config = buildOpenCodeConfig(ctx, home);
8099
8250
  const env = {
@@ -8192,7 +8343,7 @@ function formatOpenCodeLabelToken(token) {
8192
8343
  if (/^\d/.test(token)) return token;
8193
8344
  return normalized.charAt(0).toUpperCase() + normalized.slice(1);
8194
8345
  }
8195
- function detectOpenCodeModels(home = os6.homedir(), runCommand = runOpenCodeModelsCommand) {
8346
+ function detectOpenCodeModels(home = os5.homedir(), runCommand = runOpenCodeModelsCommand) {
8196
8347
  const commandResult = runCommand(home);
8197
8348
  if (commandResult.error || commandResult.status !== 0) return null;
8198
8349
  return parseOpenCodeModelsOutput(commandResult.stdout);
@@ -8201,7 +8352,7 @@ function runOpenCodeModelsCommand(home, deps = {}) {
8201
8352
  const platform = deps.platform ?? process.platform;
8202
8353
  const spawnSyncFn = deps.spawnSyncFn ?? spawnSync2;
8203
8354
  const result = spawnSyncFn("opencode", ["models"], {
8204
- env: { ...process.env, HOME: home, FORCE_COLOR: "0", NO_COLOR: "1" },
8355
+ env: scrubDaemonChildEnv({ ...process.env, HOME: home, FORCE_COLOR: "0", NO_COLOR: "1" }),
8205
8356
  encoding: "utf8",
8206
8357
  timeout: 5e3,
8207
8358
  shell: platform === "win32"
@@ -8232,7 +8383,7 @@ function openCodeSpecForEntry(entry, commandArgs) {
8232
8383
  return { command: process.execPath, args: [entry, ...commandArgs], shell: false };
8233
8384
  }
8234
8385
  function resolveWindowsOpenCodePackageEntry(commandPath, deps = {}) {
8235
- const existsSyncFn = deps.existsSyncFn ?? existsSync8;
8386
+ const existsSyncFn = deps.existsSyncFn ?? existsSync7;
8236
8387
  const execFileSyncFn = deps.execFileSyncFn;
8237
8388
  const env = deps.env ?? process.env;
8238
8389
  const winPath = path11.win32;
@@ -8393,7 +8544,7 @@ var OpenCodeDriver = class {
8393
8544
  if (unsupportedMessage) {
8394
8545
  throw new Error(unsupportedMessage);
8395
8546
  }
8396
- const launch = await buildOpenCodeLaunchOptions(ctx, os6.homedir(), version);
8547
+ const launch = await buildOpenCodeLaunchOptions(ctx, os5.homedir(), version);
8397
8548
  const spawnSpec = resolveOpenCodeSpawn(launch.args);
8398
8549
  const proc = spawn8(spawnSpec.command, spawnSpec.args, {
8399
8550
  cwd: ctx.workingDirectory,
@@ -8460,7 +8611,7 @@ var OpenCodeDriver = class {
8460
8611
  // src/drivers/pi.ts
8461
8612
  import { randomUUID as randomUUID4 } from "crypto";
8462
8613
  import { EventEmitter as EventEmitter2 } from "events";
8463
- import { mkdirSync as mkdirSync4, readdirSync as readdirSync2 } from "fs";
8614
+ import { mkdirSync as mkdirSync3, readdirSync as readdirSync3 } from "fs";
8464
8615
  import path12 from "path";
8465
8616
  import {
8466
8617
  AuthStorage,
@@ -8504,7 +8655,7 @@ function resolvePiModelFromRegistry(modelId, modelRegistry) {
8504
8655
  function findPiSessionFile(sessionDir, sessionId) {
8505
8656
  let entries;
8506
8657
  try {
8507
- entries = readdirSync2(sessionDir);
8658
+ entries = readdirSync3(sessionDir);
8508
8659
  } catch {
8509
8660
  return null;
8510
8661
  }
@@ -8728,7 +8879,7 @@ var PI_IDLE_PROMPT_RETRY_MS = 25;
8728
8879
  var PI_IDLE_PROMPT_MAX_WAIT_MS = 1e3;
8729
8880
  async function createPiAgentSessionForContext(ctx, sessionId) {
8730
8881
  const sessionDir = buildPiSessionDir(ctx.workingDirectory);
8731
- mkdirSync4(sessionDir, { recursive: true });
8882
+ mkdirSync3(sessionDir, { recursive: true });
8732
8883
  const launchRuntimeFields = runtimeConfigToLaunchFields(ctx.config);
8733
8884
  const requestedModel = launchRuntimeFields.model || "default";
8734
8885
  const traceSpan = ctx.tracer?.startSpan("daemon.pi.session.create", {
@@ -9958,7 +10109,7 @@ function findSessionJsonl(root, predicate) {
9958
10109
  if (depth < 0 || visited >= maxEntries) return null;
9959
10110
  let entries;
9960
10111
  try {
9961
- entries = readdirSync3(dir, { withFileTypes: true }).sort((a, b) => b.name.localeCompare(a.name));
10112
+ entries = readdirSync4(dir, { withFileTypes: true }).sort((a, b) => b.name.localeCompare(a.name));
9962
10113
  } catch {
9963
10114
  return null;
9964
10115
  }
@@ -9985,7 +10136,7 @@ function findKimiSdkSessionDir(sessionId, agentId, homeDir) {
9985
10136
  if (!line.trim()) continue;
9986
10137
  try {
9987
10138
  const entry = JSON.parse(line);
9988
- if (entry.sessionId === sessionId && entry.sessionDir && existsSync9(entry.sessionDir)) {
10139
+ if (entry.sessionId === sessionId && entry.sessionDir && existsSync8(entry.sessionDir)) {
9989
10140
  return entry.sessionDir;
9990
10141
  }
9991
10142
  } catch {
@@ -9996,10 +10147,10 @@ function findKimiSdkSessionDir(sessionId, agentId, homeDir) {
9996
10147
  const sessionsRoot = path14.join(homeDir, ".kimi", "sessions");
9997
10148
  try {
9998
10149
  const prefix = agentId ? `wd_${agentId}_` : `wd_`;
9999
- for (const entry of readdirSync3(sessionsRoot, { withFileTypes: true })) {
10150
+ for (const entry of readdirSync4(sessionsRoot, { withFileTypes: true })) {
10000
10151
  if (!entry.isDirectory() || !entry.name.startsWith(prefix)) continue;
10001
10152
  const candidate = path14.join(sessionsRoot, entry.name, `session_${sessionId}`);
10002
- if (existsSync9(candidate)) return candidate;
10153
+ if (existsSync8(candidate)) return candidate;
10003
10154
  }
10004
10155
  } catch {
10005
10156
  }
@@ -10009,7 +10160,7 @@ function findPiSessionFile2(sessionId, workingDirectory, homeDir) {
10009
10160
  if (workingDirectory) {
10010
10161
  const piSessionsDir = path14.join(workingDirectory, ".pi-sessions");
10011
10162
  try {
10012
- const files = readdirSync3(piSessionsDir, { withFileTypes: true }).filter((e) => e.isFile() && e.name.endsWith(".jsonl")).map((e) => ({ name: e.name, path: path14.join(piSessionsDir, e.name), stat: statSync(path14.join(piSessionsDir, e.name)) })).filter((f) => f.stat.isFile() && f.name.includes(sessionId)).sort((a, b) => b.stat.mtimeMs - a.stat.mtimeMs);
10163
+ const files = readdirSync4(piSessionsDir, { withFileTypes: true }).filter((e) => e.isFile() && e.name.endsWith(".jsonl")).map((e) => ({ name: e.name, path: path14.join(piSessionsDir, e.name), stat: statSync(path14.join(piSessionsDir, e.name)) })).filter((f) => f.stat.isFile() && f.name.includes(sessionId)).sort((a, b) => b.stat.mtimeMs - a.stat.mtimeMs);
10013
10164
  if (files[0]) return files[0].path;
10014
10165
  } catch {
10015
10166
  }
@@ -10031,7 +10182,7 @@ function safeSessionFilename(value) {
10031
10182
  function writeRuntimeSessionHandoff(runtime, sessionId, fallbackDir) {
10032
10183
  try {
10033
10184
  const dir = path14.join(fallbackDir, ".slock", "runtime-sessions");
10034
- mkdirSync5(dir, { recursive: true });
10185
+ mkdirSync4(dir, { recursive: true });
10035
10186
  const filePath = path14.join(dir, `${runtime}-${safeSessionFilename(sessionId)}.jsonl`);
10036
10187
  writeFileSync4(filePath, JSON.stringify({
10037
10188
  type: "runtime_session_handoff",
@@ -10052,28 +10203,22 @@ function writeRuntimeSessionHandoff(runtime, sessionId, fallbackDir) {
10052
10203
  }
10053
10204
  }
10054
10205
  function resolveRuntimeHomeDir(config, defaultHomeDir, workspacePath, opts = {}) {
10055
- if (isClaudeCustomProviderConfig(config)) {
10056
- return getClaudeProviderStatePaths(workspacePath).home;
10057
- }
10058
10206
  if (config.runtime === "codex") {
10059
10207
  return resolveCodexHomeRootFromConfig(config, defaultHomeDir, workspacePath, process.env, opts);
10060
10208
  }
10061
10209
  return defaultHomeDir;
10062
10210
  }
10063
10211
  function ensureRuntimeHomeDir(config, defaultHomeDir, workspacePath, opts = {}) {
10064
- if (isClaudeCustomProviderConfig(config)) {
10065
- return ensureClaudeProviderStatePaths(workspacePath).home;
10066
- }
10067
10212
  if (config.runtime === "codex") {
10068
10213
  const home = resolveCodexHomeRootFromConfig(config, defaultHomeDir, workspacePath, process.env, opts);
10069
10214
  if (opts.agentId) {
10070
- mkdirSync5(home, { recursive: true });
10215
+ mkdirSync4(home, { recursive: true });
10071
10216
  }
10072
10217
  return home;
10073
10218
  }
10074
10219
  return defaultHomeDir;
10075
10220
  }
10076
- function resolveRuntimeSessionRef(runtime, sessionId, homeDir = os7.homedir(), fallbackDir, opts) {
10221
+ function resolveRuntimeSessionRef(runtime, sessionId, homeDir = os6.homedir(), fallbackDir, opts) {
10077
10222
  let resolvedPath = null;
10078
10223
  let lookupMethod = "none";
10079
10224
  if (runtime === "claude") {
@@ -11198,7 +11343,7 @@ var AgentProcessManager = class _AgentProcessManager {
11198
11343
  this.serverUrl = opts.serverUrl;
11199
11344
  this.slockHome = opts.slockHome ? path14.resolve(opts.slockHome) : resolveSlockHome();
11200
11345
  this.dataDir = opts.dataDir || resolveSlockHomePath("agents", this.slockHome);
11201
- this.runtimeSessionHomeDir = opts.runtimeSessionHomeDir || os7.homedir();
11346
+ this.runtimeSessionHomeDir = opts.runtimeSessionHomeDir || os6.homedir();
11202
11347
  this.driverResolver = opts.driverResolver || getDriver;
11203
11348
  this.defaultAgentEnvVarsProvider = opts.defaultAgentEnvVarsProvider || null;
11204
11349
  this.tracer = opts.tracer ?? noopTracer;
@@ -11890,7 +12035,25 @@ var AgentProcessManager = class _AgentProcessManager {
11890
12035
  queue_depth: this.agentStartQueue.length,
11891
12036
  active_starts: this.activeAgentStartCount,
11892
12037
  max_concurrent_starts: this.maxConcurrentAgentStarts,
11893
- min_start_interval_ms: this.agentStartIntervalMs
12038
+ min_start_interval_ms: this.agentStartIntervalMs,
12039
+ ...this.runtimeLaunchPolicyTraceAttrs(config)
12040
+ };
12041
+ }
12042
+ runtimeLaunchPolicyTraceAttrs(config) {
12043
+ if (config.runtime !== "claude") return {};
12044
+ const customProvider = isClaudeCustomProviderConfig(config);
12045
+ if (!customProvider) {
12046
+ return {
12047
+ claude_custom_provider: false
12048
+ };
12049
+ }
12050
+ return {
12051
+ claude_custom_provider: true,
12052
+ claude_custom_provider_settings_sources_policy: "project,local",
12053
+ claude_custom_provider_inherited_provider_scrub: true,
12054
+ claude_custom_provider_host_managed_flag: false,
12055
+ claude_custom_provider_home_override: false,
12056
+ claude_custom_provider_config_dir_override: false
11894
12057
  };
11895
12058
  }
11896
12059
  getDeliveryTraceContext(message) {
@@ -14136,7 +14299,7 @@ Use ${communicationCommand("read_history")} to catch up on the channels listed a
14136
14299
  const config = agent?.config ?? idle?.config ?? null;
14137
14300
  const runtime = runtimeHint || config?.runtime || "claude";
14138
14301
  const workspaceDir = path14.join(this.dataDir, agentId);
14139
- const hostHome = os7.homedir();
14302
+ const hostHome = os6.homedir();
14140
14303
  const home = agent?.runtime.currentRuntimeHomeDir || (config ? ensureRuntimeHomeDir(config, hostHome, workspaceDir, { agentId, slockHome: this.slockHome }) : runtime === "codex" ? resolveCodexHomeRootFromEnv(process.env, { defaultHomeDir: hostHome, cwd: workspaceDir }) : hostHome);
14141
14304
  const paths = _AgentProcessManager.SKILL_PATHS[runtime] || _AgentProcessManager.SKILL_PATHS.claude;
14142
14305
  const globalDirs = runtime === "codex" ? [
@@ -14591,6 +14754,7 @@ Use ${communicationCommand("read_history")} to catch up on the channels listed a
14591
14754
  hasSession: Boolean(ap.sessionId),
14592
14755
  ...this.messagesTraceAttrs(messages),
14593
14756
  ...inputTraceAttrs,
14757
+ ...this.runtimeLaunchPolicyTraceAttrs(ap.config),
14594
14758
  ...this.runtimeProfileTurnControlTraceAttrs(ap.runtimeProfileTurnControl)
14595
14759
  }
14596
14760
  });
@@ -14598,6 +14762,7 @@ Use ${communicationCommand("read_history")} to catch up on the channels listed a
14598
14762
  reason,
14599
14763
  ...this.messagesTraceAttrs(messages),
14600
14764
  ...inputTraceAttrs,
14765
+ ...this.runtimeLaunchPolicyTraceAttrs(ap.config),
14601
14766
  ...this.runtimeProfileTurnControlTraceAttrs(ap.runtimeProfileTurnControl)
14602
14767
  });
14603
14768
  ap.runtimeTraceSpan = span;
@@ -16230,8 +16395,8 @@ var ReminderCache = class {
16230
16395
 
16231
16396
  // src/machineLock.ts
16232
16397
  import { createHash as createHash4, randomUUID as randomUUID6 } from "crypto";
16233
- import { mkdirSync as mkdirSync6, readFileSync as readFileSync7, rmSync as rmSync3, statSync as statSync2, writeFileSync as writeFileSync5 } from "fs";
16234
- import os8 from "os";
16398
+ import { mkdirSync as mkdirSync5, readFileSync as readFileSync7, rmSync as rmSync3, statSync as statSync2, writeFileSync as writeFileSync5 } from "fs";
16399
+ import os7 from "os";
16235
16400
  import path15 from "path";
16236
16401
  var INCOMPLETE_LOCK_STALE_MS = 3e4;
16237
16402
  var DaemonMachineLockConflictError = class extends Error {
@@ -16287,14 +16452,14 @@ function acquireDaemonMachineLock(options) {
16287
16452
  const machineDir = path15.join(rootDir, lockId);
16288
16453
  const lockDir = path15.join(machineDir, "daemon.lock");
16289
16454
  const token = randomUUID6();
16290
- mkdirSync6(machineDir, { recursive: true });
16455
+ mkdirSync5(machineDir, { recursive: true });
16291
16456
  for (let attempt = 0; attempt < 2; attempt += 1) {
16292
16457
  try {
16293
- mkdirSync6(lockDir);
16458
+ mkdirSync5(lockDir);
16294
16459
  const owner = {
16295
16460
  pid: process.pid,
16296
16461
  token,
16297
- hostname: os8.hostname(),
16462
+ hostname: os7.hostname(),
16298
16463
  startedAt: (/* @__PURE__ */ new Date()).toISOString(),
16299
16464
  serverUrl: options.serverUrl,
16300
16465
  apiKeyFingerprint: fingerprint.slice(0, 16)
@@ -16344,8 +16509,8 @@ function acquireDaemonMachineLock(options) {
16344
16509
  throw new DaemonMachineLockConflictError(lockDir, readOwner(lockDir));
16345
16510
  }
16346
16511
 
16347
- // src/localTraceSink.ts
16348
- import { appendFileSync, mkdirSync as mkdirSync7, readdirSync as readdirSync4, rmSync as rmSync4, statSync as statSync3, writeFileSync as writeFileSync6 } from "fs";
16512
+ // ../trace-client/src/localTraceSink.ts
16513
+ import { appendFileSync, mkdirSync as mkdirSync6, readdirSync as readdirSync5, rmSync as rmSync4, statSync as statSync3, writeFileSync as writeFileSync6 } from "fs";
16349
16514
  import path16 from "path";
16350
16515
  var DEFAULT_MAX_FILE_BYTES = 5 * 1024 * 1024;
16351
16516
  var DEFAULT_MAX_FILE_AGE_MS = 5 * 60 * 1e3;
@@ -16409,7 +16574,7 @@ var LocalRotatingTraceSink = class {
16409
16574
  return this.currentFile;
16410
16575
  }
16411
16576
  ensureFile(nextBytes) {
16412
- mkdirSync7(this.traceDir, { recursive: true, mode: 448 });
16577
+ mkdirSync6(this.traceDir, { recursive: true, mode: 448 });
16413
16578
  const nowMs = this.nowMsProvider();
16414
16579
  const shouldRotateForAge = this.currentFileOpenedAtMs !== null && nowMs - this.currentFileOpenedAtMs >= this.maxFileAgeMs;
16415
16580
  if (!this.currentFile || this.currentSize + nextBytes > this.maxFileBytes || shouldRotateForAge) {
@@ -16424,7 +16589,7 @@ var LocalRotatingTraceSink = class {
16424
16589
  }
16425
16590
  }
16426
16591
  pruneOldFiles() {
16427
- const files = readdirSync4(this.traceDir).filter((name) => name.startsWith("daemon-trace-") && name.endsWith(".jsonl")).sort();
16592
+ const files = readdirSync5(this.traceDir).filter((name) => name.startsWith("daemon-trace-") && name.endsWith(".jsonl")).sort();
16428
16593
  const excess = files.length - this.maxFiles;
16429
16594
  if (excess <= 0) return;
16430
16595
  for (const file of files.slice(0, excess)) {
@@ -16515,13 +16680,7 @@ function isDiagnosticErrorAttr(key) {
16515
16680
  return DIAGNOSTIC_ERROR_ATTRS.has(key);
16516
16681
  }
16517
16682
 
16518
- // src/traceBundleUpload.ts
16519
- import { createHash as createHash6, randomUUID as randomUUID7 } from "crypto";
16520
- import { gzipSync as gzipSync2 } from "zlib";
16521
- import { mkdir as mkdir2, readFile as readFile2, readdir as readdir3, stat as stat3, writeFile as writeFile2 } from "fs/promises";
16522
- import path17 from "path";
16523
-
16524
- // src/traceJitter.ts
16683
+ // ../trace-client/src/traceJitter.ts
16525
16684
  import { createHash as createHash5 } from "crypto";
16526
16685
  var INITIAL_UPLOAD_DELAY_SPAN_MS = 3e4;
16527
16686
  var UPLOAD_INTERVAL_JITTER_SPAN_MS = 6e4;
@@ -16550,7 +16709,68 @@ function bucketDelayMs(delayMs) {
16550
16709
  return "10m+";
16551
16710
  }
16552
16711
 
16712
+ // ../trace-client/src/traceClient.ts
16713
+ var MultiSink = class {
16714
+ sinks;
16715
+ onSinkError;
16716
+ constructor(sinks, onSinkError) {
16717
+ this.sinks = sinks;
16718
+ this.onSinkError = onSinkError;
16719
+ }
16720
+ record(span) {
16721
+ for (const sink of this.sinks) {
16722
+ try {
16723
+ sink.record(span);
16724
+ } catch (err) {
16725
+ this.onSinkError?.(sink, err);
16726
+ }
16727
+ }
16728
+ }
16729
+ };
16730
+ var SourceForcingActiveSpan = class {
16731
+ context;
16732
+ inner;
16733
+ constructor(inner) {
16734
+ this.inner = inner;
16735
+ this.context = inner.context;
16736
+ }
16737
+ addEvent(name, attrs) {
16738
+ this.inner.addEvent(name, attrs);
16739
+ }
16740
+ end(status, options) {
16741
+ if (!options?.attrs) {
16742
+ this.inner.end(status, options);
16743
+ return;
16744
+ }
16745
+ const { source: _stripped, ...rest } = options.attrs;
16746
+ this.inner.end(status, { ...options, attrs: rest });
16747
+ }
16748
+ };
16749
+ var SourceForcingTracer = class {
16750
+ inner;
16751
+ source;
16752
+ constructor(inner, source) {
16753
+ this.inner = inner;
16754
+ this.source = source;
16755
+ }
16756
+ startSpan(name, options) {
16757
+ const callerAttrs = options.attrs ?? {};
16758
+ const attrs = { ...callerAttrs, source: this.source };
16759
+ const innerSpan = this.inner.startSpan(name, { ...options, attrs });
16760
+ return new SourceForcingActiveSpan(innerSpan);
16761
+ }
16762
+ };
16763
+ function createTraceClient(options) {
16764
+ const sink = new MultiSink(options.sinks);
16765
+ const baseTracer = new BasicTracer({ sink });
16766
+ return new SourceForcingTracer(baseTracer, options.source);
16767
+ }
16768
+
16553
16769
  // src/traceBundleUpload.ts
16770
+ import { createHash as createHash6, randomUUID as randomUUID7 } from "crypto";
16771
+ import { gzipSync as gzipSync2 } from "zlib";
16772
+ import { mkdir as mkdir2, readFile as readFile2, readdir as readdir3, stat as stat3, writeFile as writeFile2 } from "fs/promises";
16773
+ import path17 from "path";
16554
16774
  var TRACE_UPLOAD_SCOPE = "daemon-trace-bundle:create";
16555
16775
  var DEFAULT_UPLOAD_INTERVAL_MS = 5 * 60 * 1e3;
16556
16776
  var DEFAULT_MIN_FILE_AGE_MS = 60 * 1e3;
@@ -16814,7 +17034,7 @@ var DAEMON_CORE_TRACE_ATTR_CONTRACTS = {
16814
17034
  spanAttrs: ["agentId", "event_kind", "runtime"]
16815
17035
  }
16816
17036
  };
16817
- var DAEMON_CLI_USAGE = "Usage: slock-daemon --server-url <url> --api-key <key>";
17037
+ var DAEMON_CLI_USAGE = `Usage: slock-daemon --server-url <url> (--api-key <key> or ${DAEMON_API_KEY_ENV}=<key>)`;
16818
17038
  var RunnerCredentialMintError2 = class extends Error {
16819
17039
  code;
16820
17040
  retryable;
@@ -16850,9 +17070,9 @@ function runnerCredentialErrorDetail2(error) {
16850
17070
  async function waitForRunnerCredentialRetry2() {
16851
17071
  await new Promise((resolve) => setTimeout(resolve, RUNNER_CREDENTIAL_MINT_RETRY_DELAY_MS2));
16852
17072
  }
16853
- function parseDaemonCliArgs(args) {
17073
+ function parseDaemonCliArgs(args, env = {}) {
16854
17074
  let serverUrl = "";
16855
- let apiKey = "";
17075
+ let apiKey = env[DAEMON_API_KEY_ENV] ?? "";
16856
17076
  for (let i = 0; i < args.length; i++) {
16857
17077
  if (args[i] === "--server-url" && args[i + 1]) serverUrl = args[++i];
16858
17078
  if (args[i] === "--api-key" && args[i + 1]) apiKey = args[++i];
@@ -16889,7 +17109,7 @@ function resolveSlockCliPathOrEmpty(moduleUrl = import.meta.url) {
16889
17109
  }
16890
17110
  async function runBundledSlockCli(argv) {
16891
17111
  process.argv = [process.execPath, "slock", ...argv];
16892
- await import("./dist-5BEASCX5.js");
17112
+ await import("./dist-4KV4FRQE.js");
16893
17113
  }
16894
17114
  function detectRuntimes(tracer = noopTracer) {
16895
17115
  const ids = [];
@@ -17117,8 +17337,9 @@ var DaemonCore = class {
17117
17337
  maxFileAgeJitterMs: jitter.maxFileAgeJitterMs,
17118
17338
  maxFiles: this.options.localTraceMaxFiles ?? readPositiveIntegerEnv3("SLOCK_DAEMON_TRACE_MAX_FILES", 8)
17119
17339
  });
17120
- this.tracer = this.withDaemonTraceScope(new BasicTracer({
17121
- sink: this.localTraceSink
17340
+ this.tracer = this.withDaemonTraceScope(createTraceClient({
17341
+ source: "daemon",
17342
+ sinks: [this.localTraceSink]
17122
17343
  }));
17123
17344
  this.agentManager.setTracer(this.tracer);
17124
17345
  this.agentManager.setCliTransportTraceDir(path18.join(machineDir, "traces"));
@@ -17694,8 +17915,8 @@ var DaemonCore = class {
17694
17915
  capabilities: ["agent:start", "agent:stop", "agent:deliver", "workspace:files"],
17695
17916
  runtimes,
17696
17917
  runningAgents: runningAgentIds,
17697
- hostname: this.options.hostname ?? os9.hostname(),
17698
- os: this.options.osDescription ?? `${os9.platform()} ${os9.arch()}`,
17918
+ hostname: this.options.hostname ?? os8.hostname(),
17919
+ os: this.options.osDescription ?? `${os8.platform()} ${os8.arch()}`,
17699
17920
  daemonVersion: this.daemonVersion,
17700
17921
  ...this.computerVersion ? { computerVersion: this.computerVersion } : {}
17701
17922
  });
@@ -17776,6 +17997,8 @@ var DaemonCore = class {
17776
17997
 
17777
17998
  export {
17778
17999
  subscribeDaemonLogs,
18000
+ DAEMON_API_KEY_ENV,
18001
+ scrubDaemonAuthEnv,
17779
18002
  resolveWorkspaceDirectoryPath,
17780
18003
  scanWorkspaceDirectories,
17781
18004
  deleteWorkspaceDirectory,
package/dist/cli/index.js CHANGED
@@ -18337,6 +18337,7 @@ function formatHeldSendOutput(target, data) {
18337
18337
  ${MESSAGE_HEREDOC_DELIMITER}
18338
18338
  To send the current draft unchanged:
18339
18339
  raft message send --send-draft --target "${target}"
18340
+ You can also choose not to send anything.
18340
18341
  `,
18341
18342
  continueAnywayInstruction: `If repeated updates keep blocking the same draft and this is still the right reply, you may use:
18342
18343
  raft message send --send-draft --anyway --target "${target}"
package/dist/core.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import {
2
+ DAEMON_API_KEY_ENV,
2
3
  DAEMON_CLI_USAGE,
3
4
  DaemonCore,
4
5
  deleteWorkspaceDirectory,
@@ -10,9 +11,11 @@ import {
10
11
  resolveWorkspaceDirectoryPath,
11
12
  runBundledSlockCli,
12
13
  scanWorkspaceDirectories,
14
+ scrubDaemonAuthEnv,
13
15
  subscribeDaemonLogs
14
- } from "./chunk-RENPNQK3.js";
16
+ } from "./chunk-COT7JNSQ.js";
15
17
  export {
18
+ DAEMON_API_KEY_ENV,
16
19
  DAEMON_CLI_USAGE,
17
20
  DaemonCore,
18
21
  deleteWorkspaceDirectory,
@@ -24,5 +27,6 @@ export {
24
27
  resolveWorkspaceDirectoryPath,
25
28
  runBundledSlockCli,
26
29
  scanWorkspaceDirectories,
30
+ scrubDaemonAuthEnv,
27
31
  subscribeDaemonLogs
28
32
  };
@@ -18099,6 +18099,7 @@ function formatHeldSendOutput(target, data) {
18099
18099
  ${MESSAGE_HEREDOC_DELIMITER}
18100
18100
  To send the current draft unchanged:
18101
18101
  raft message send --send-draft --target "${target}"
18102
+ You can also choose not to send anything.
18102
18103
  `,
18103
18104
  continueAnywayInstruction: `If repeated updates keep blocking the same draft and this is still the right reply, you may use:
18104
18105
  raft message send --send-draft --anyway --target "${target}"
package/dist/index.js CHANGED
@@ -2,11 +2,13 @@
2
2
  import {
3
3
  DAEMON_CLI_USAGE,
4
4
  DaemonCore,
5
- parseDaemonCliArgs
6
- } from "./chunk-RENPNQK3.js";
5
+ parseDaemonCliArgs,
6
+ scrubDaemonAuthEnv
7
+ } from "./chunk-COT7JNSQ.js";
7
8
 
8
9
  // src/index.ts
9
- var parsedArgs = parseDaemonCliArgs(process.argv.slice(2));
10
+ var parsedArgs = parseDaemonCliArgs(process.argv.slice(2), process.env);
11
+ scrubDaemonAuthEnv(process.env);
10
12
  if (!parsedArgs) {
11
13
  console.error(DAEMON_CLI_USAGE);
12
14
  process.exit(1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botiverse/raft-daemon",
3
- "version": "0.63.1",
3
+ "version": "0.63.2-play.20260620140456",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "raft-daemon": "dist/raft-daemon.js",
@@ -59,6 +59,7 @@
59
59
  "devDependencies": {
60
60
  "@botiverse/raft": "workspace:*",
61
61
  "@slock-ai/shared": "workspace:*",
62
+ "@slock-ai/trace-client": "workspace:*",
62
63
  "@types/node": "^25.5.0",
63
64
  "@types/ws": "^8.18.1",
64
65
  "tsup": "^8.5.1",