@alfe.ai/gateway 0.10.9 → 0.11.1

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/health.js CHANGED
@@ -7,7 +7,7 @@ import { chmodSync, existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSy
7
7
  import { ClaudeCodeApplier, ClaudeCodeMcpSync, HermesApplier, HermesMcpSync, IntegrationManager, IntegrationManagerAdapter, LockManager, McpApplier, NoopOpenClawCliLock, OpenClawApplier, SerialOpenClawCliLock } from "@alfe.ai/integrations";
8
8
  import { execFile, execSync } from "node:child_process";
9
9
  import { promisify } from "node:util";
10
- import { getEndpointFromToken, readConfig } from "@alfe.ai/config";
10
+ import { getEndpointFromToken, readConfig, resolveAgentWorkspace } from "@alfe.ai/config";
11
11
  import { AgentApiClient } from "@alfe.ai/agent-api-client";
12
12
  import { parse } from "smol-toml";
13
13
  import WebSocket from "ws";
@@ -3744,11 +3744,23 @@ function superRefine(fn) {
3744
3744
  * new host, then cut a CLI release so the pin travels with the CLI version. The
3745
3745
  * dashboard still surfaces npm-`latest` as an explicit opt-in upgrade.
3746
3746
  *
3747
- * NOTE: claude-code is self-hosted-only (no managed Docker image), so — unlike
3747
+ * NOTE: managed claude-code agents run on Hetzner VMs provisioned by cloud-init
3748
+ * + `alfe setup --managed` (no Docker image), so — unlike
3748
3749
  * `PINNED_OPENCLAW_VERSION` — there is no `services/compute/Dockerfile` mirror to
3749
3750
  * keep in sync.
3750
3751
  */
3751
- const PINNED_CLAUDE_CODE_HOST_VERSION = "0.1.6";
3752
+ const PINNED_CLAUDE_CODE_HOST_VERSION = "0.1.16";
3753
+ /**
3754
+ * The `@anthropic-ai/claude-code` (the `claude` CLI) version Alfe installs for
3755
+ * the claude-code runtime: always on managed VMs (`alfe setup --managed`), and
3756
+ * on self-hosted machines only when no `claude` is present (a user-installed
3757
+ * `claude` is never replaced). Pinned to npm's `stable` dist-tag as of
3758
+ * 2026-10-14 — `latest` moves daily and the host drives `claude -p` flags
3759
+ * (`--resume`, `--mcp-config`, `--strict-mcp-config`, `--permission-mode`)
3760
+ * whose behaviour must be validated before a bump. The pin travels with the
3761
+ * CLI release.
3762
+ */
3763
+ const PINNED_CLAUDE_CODE_VERSION = "2.1.287";
3752
3764
  //#endregion
3753
3765
  //#region ../../packages-internal/ids/dist/prefixes.js
3754
3766
  const ID_PREFIXES = {
@@ -4384,34 +4396,39 @@ function isClerkReverificationResponse(value) {
4384
4396
  //#region ../../packages-internal/types/dist/models.js
4385
4397
  const AnthropicModel = {
4386
4398
  Opus55: "claude-opus-5-5",
4399
+ Sonnet55: "claude-sonnet-5-5",
4400
+ Haiku55: "claude-haiku-5-5",
4387
4401
  Opus5: "claude-opus-5",
4402
+ Sonnet5: "claude-sonnet-5",
4388
4403
  Opus48: "claude-opus-4-8",
4389
4404
  Opus47: "claude-opus-4-7",
4390
4405
  Opus46: "claude-opus-4-6",
4391
- Sonnet5: "claude-sonnet-5",
4392
4406
  Sonnet46: "claude-sonnet-4-6",
4393
4407
  Haiku45: "claude-haiku-4-5"
4394
4408
  };
4395
4409
  const ANTHROPIC_MODELS = enumValues(AnthropicModel);
4396
4410
  const OpenAIModel = {
4397
4411
  GPT6Astra: "gpt-6-astra",
4398
- GPT4o: "gpt-4o",
4399
- GPT4oMini: "gpt-4o-mini",
4400
- O3: "o3",
4401
- GPT41: "gpt-4.1",
4402
- GPT41Mini: "gpt-4.1-mini",
4403
- GPT41Nano: "gpt-4.1-nano",
4404
- GPT54: "gpt-5.4",
4405
- GPT54Mini: "gpt-5.4-mini",
4406
- GPT54Nano: "gpt-5.4-nano",
4407
- GPT54Pro: "gpt-5.4-pro",
4408
- GPT55: "gpt-5.5",
4409
- GPT55Pro: "gpt-5.5-pro",
4412
+ GPT61Sol: "gpt-6.1-sol",
4413
+ GPT6Sol: "gpt-6-sol",
4414
+ GPT6Luna: "gpt-6-luna",
4410
4415
  GPT56Sol: "gpt-5.6-sol",
4411
4416
  GPT56Terra: "gpt-5.6-terra",
4412
4417
  GPT56Luna: "gpt-5.6-luna",
4413
- O3Mini: "o3-mini",
4418
+ GPT55Pro: "gpt-5.5-pro",
4419
+ GPT55: "gpt-5.5",
4420
+ GPT54Pro: "gpt-5.4-pro",
4421
+ GPT54: "gpt-5.4",
4422
+ GPT54Mini: "gpt-5.4-mini",
4423
+ GPT54Nano: "gpt-5.4-nano",
4414
4424
  O4Mini: "o4-mini",
4425
+ O3: "o3",
4426
+ O3Mini: "o3-mini",
4427
+ GPT41: "gpt-4.1",
4428
+ GPT41Mini: "gpt-4.1-mini",
4429
+ GPT41Nano: "gpt-4.1-nano",
4430
+ GPT4o: "gpt-4o",
4431
+ GPT4oMini: "gpt-4o-mini",
4415
4432
  TextEmbedding3Small: "text-embedding-3-small",
4416
4433
  TextEmbedding3Large: "text-embedding-3-large"
4417
4434
  };
@@ -4439,12 +4456,11 @@ const MiniMaxModel = {
4439
4456
  M3: "MiniMax-M3",
4440
4457
  M27: "MiniMax-M2.7",
4441
4458
  M27HighSpeed: "MiniMax-M2.7-highspeed",
4442
- M25: "MiniMax-M2.5",
4443
- M21: "MiniMax-M2.1",
4444
- M2: "MiniMax-M2"
4459
+ M25: "MiniMax-M2.5"
4445
4460
  };
4446
4461
  const MINIMAX_MODELS = enumValues(MiniMaxModel);
4447
4462
  const MistralModel = {
4463
+ Large4: "mistral-large-4",
4448
4464
  Large: "mistral-large-latest",
4449
4465
  Medium: "mistral-medium-latest",
4450
4466
  Small: "mistral-small-latest",
@@ -4456,11 +4472,11 @@ const MISTRAL_MODELS = enumValues(MistralModel);
4456
4472
  const XAIModel = {
4457
4473
  Grok47: "grok-4.7",
4458
4474
  Grok46: "grok-4.6",
4475
+ GrokBuild01: "grok-build-0.1",
4459
4476
  Grok45: "grok-4.5",
4460
4477
  Grok43: "grok-4.3",
4461
- GrokBuild01: "grok-build-0.1",
4462
- Grok4: "grok-4",
4463
- Grok41Fast: "grok-4.1-fast"
4478
+ Grok41Fast: "grok-4.1-fast",
4479
+ Grok4: "grok-4"
4464
4480
  };
4465
4481
  const XAI_MODELS = enumValues(XAIModel);
4466
4482
  const ZhipuModel = {
@@ -4476,9 +4492,9 @@ const ZhipuModel = {
4476
4492
  const ZHIPU_MODELS = enumValues(ZhipuModel);
4477
4493
  const MoonshotModel = {
4478
4494
  K3: "kimi-k3",
4479
- K26: "kimi-k2.6",
4480
4495
  K27Code: "kimi-k2.7-code",
4481
- K27CodeHighSpeed: "kimi-k2.7-code-highspeed"
4496
+ K27CodeHighSpeed: "kimi-k2.7-code-highspeed",
4497
+ K26: "kimi-k2.6"
4482
4498
  };
4483
4499
  const MOONSHOT_MODELS = enumValues(MoonshotModel);
4484
4500
  const QwenModel = {
@@ -4514,7 +4530,7 @@ _enum(ZHIPU_MODELS);
4514
4530
  _enum(MOONSHOT_MODELS);
4515
4531
  _enum(QWEN_MODELS);
4516
4532
  string().trim().min(1);
4517
- AnthropicModel.Opus55, AnthropicModel.Opus5, AnthropicModel.Opus48, AnthropicModel.Opus47, AnthropicModel.Opus46, AnthropicModel.Sonnet5, AnthropicModel.Sonnet46, AnthropicModel.Haiku45, OpenAIModel.GPT6Astra, OpenAIModel.GPT4o, OpenAIModel.GPT4oMini, OpenAIModel.O3, OpenAIModel.GPT41, OpenAIModel.GPT41Mini, OpenAIModel.GPT41Nano, OpenAIModel.GPT54, OpenAIModel.GPT54Mini, OpenAIModel.GPT54Nano, OpenAIModel.GPT54Pro, OpenAIModel.GPT55, OpenAIModel.GPT55Pro, OpenAIModel.GPT56Sol, OpenAIModel.GPT56Terra, OpenAIModel.GPT56Luna, OpenAIModel.O3Mini, OpenAIModel.O4Mini, OpenAIModel.TextEmbedding3Small, OpenAIModel.TextEmbedding3Large, DeepSeekModel.Flash, DeepSeekModel.V4Pro, DeepSeekModel.V4Flash, GoogleModel.Gemini38Flash, GoogleModel.Gemini37Flash, GoogleModel.Gemini36Flash, GoogleModel.Gemini35Flash, GoogleModel.Gemini35FlashLite, GoogleModel.Gemini31Pro, GoogleModel.Gemini31FlashLite, GoogleModel.Gemini25Pro, GoogleModel.Gemini25Flash, GoogleModel.Gemini25FlashLite, MiniMaxModel.M3, MiniMaxModel.M27, MiniMaxModel.M27HighSpeed, MiniMaxModel.M25, MiniMaxModel.M21, MiniMaxModel.M2, MistralModel.Large, MistralModel.Medium, MistralModel.Small, MistralModel.Codestral, MistralModel.Ministral8b, MistralModel.Ministral3b, XAIModel.Grok47, XAIModel.Grok46, XAIModel.Grok45, XAIModel.Grok43, XAIModel.GrokBuild01, XAIModel.Grok4, XAIModel.Grok41Fast, ZhipuModel.GLM53, ZhipuModel.GLM53Flash, ZhipuModel.GLM53FlashX, ZhipuModel.GLM52, ZhipuModel.GLM51, ZhipuModel.GLM46, ZhipuModel.GLM45, ZhipuModel.GLM45Air, MoonshotModel.K3, MoonshotModel.K26, MoonshotModel.K27Code, MoonshotModel.K27CodeHighSpeed, QwenModel.Qwen38Max, QwenModel.Qwen38Flash, QwenModel.Qwen37Max, QwenModel.Qwen37Plus, QwenModel.Qwen36Flash, QwenModel.Qwen35Flash;
4533
+ AnthropicModel.Opus55, AnthropicModel.Opus5, AnthropicModel.Opus48, AnthropicModel.Opus47, AnthropicModel.Opus46, AnthropicModel.Sonnet55, AnthropicModel.Sonnet5, AnthropicModel.Sonnet46, AnthropicModel.Haiku55, AnthropicModel.Haiku45, OpenAIModel.GPT6Astra, OpenAIModel.GPT61Sol, OpenAIModel.GPT6Sol, OpenAIModel.GPT6Luna, OpenAIModel.GPT4o, OpenAIModel.GPT4oMini, OpenAIModel.O3, OpenAIModel.GPT41, OpenAIModel.GPT41Mini, OpenAIModel.GPT41Nano, OpenAIModel.GPT54, OpenAIModel.GPT54Mini, OpenAIModel.GPT54Nano, OpenAIModel.GPT54Pro, OpenAIModel.GPT55, OpenAIModel.GPT55Pro, OpenAIModel.GPT56Sol, OpenAIModel.GPT56Terra, OpenAIModel.GPT56Luna, OpenAIModel.O3Mini, OpenAIModel.O4Mini, OpenAIModel.TextEmbedding3Small, OpenAIModel.TextEmbedding3Large, DeepSeekModel.Flash, DeepSeekModel.V4Pro, DeepSeekModel.V4Flash, GoogleModel.Gemini38Flash, GoogleModel.Gemini37Flash, GoogleModel.Gemini36Flash, GoogleModel.Gemini35Flash, GoogleModel.Gemini35FlashLite, GoogleModel.Gemini31Pro, GoogleModel.Gemini31FlashLite, GoogleModel.Gemini25Pro, GoogleModel.Gemini25Flash, GoogleModel.Gemini25FlashLite, MiniMaxModel.M3, MiniMaxModel.M27, MiniMaxModel.M27HighSpeed, MiniMaxModel.M25, MistralModel.Large4, MistralModel.Large, MistralModel.Medium, MistralModel.Small, MistralModel.Codestral, MistralModel.Ministral8b, MistralModel.Ministral3b, XAIModel.Grok47, XAIModel.Grok46, XAIModel.Grok45, XAIModel.Grok43, XAIModel.GrokBuild01, XAIModel.Grok4, XAIModel.Grok41Fast, ZhipuModel.GLM53, ZhipuModel.GLM53Flash, ZhipuModel.GLM53FlashX, ZhipuModel.GLM52, ZhipuModel.GLM51, ZhipuModel.GLM46, ZhipuModel.GLM45, ZhipuModel.GLM45Air, MoonshotModel.K3, MoonshotModel.K26, MoonshotModel.K27Code, MoonshotModel.K27CodeHighSpeed, QwenModel.Qwen38Max, QwenModel.Qwen38Flash, QwenModel.Qwen37Max, QwenModel.Qwen37Plus, QwenModel.Qwen36Flash, QwenModel.Qwen35Flash;
4518
4534
  /**
4519
4535
  * Alfe-hosted open-weight models are promoted dynamically only in regions
4520
4536
  * whose private data plane exists. Keep them out of ALL_MODELS so the standard
@@ -4574,7 +4590,7 @@ const AWS_PRIVATE_MODEL_PRICING = {
4574
4590
  [BedrockModel.TitanEmbedTextV2]: { input: .026004 }
4575
4591
  };
4576
4592
  Object.fromEntries(AWS_PRIVATE_BEDROCK_CHAT_MODELS.map((modelId) => [`alfe-bedrock-${modelId}`, AWS_PRIVATE_MODEL_PRICING[modelId]]));
4577
- AnthropicModel.Opus55, AnthropicModel.Opus5, AnthropicModel.Opus48, AnthropicModel.Opus47, AnthropicModel.Opus46, AnthropicModel.Sonnet5, AnthropicModel.Sonnet46, AnthropicModel.Haiku45, OpenAIModel.GPT6Astra, OpenAIModel.GPT4o, OpenAIModel.GPT4oMini, OpenAIModel.O3, OpenAIModel.GPT41, OpenAIModel.GPT41Mini, OpenAIModel.GPT41Nano, OpenAIModel.GPT54, OpenAIModel.GPT54Mini, OpenAIModel.GPT54Nano, OpenAIModel.GPT54Pro, OpenAIModel.GPT55, OpenAIModel.GPT55Pro, OpenAIModel.GPT56Sol, OpenAIModel.GPT56Terra, OpenAIModel.GPT56Luna, OpenAIModel.O3Mini, OpenAIModel.O4Mini, OpenAIModel.TextEmbedding3Small, OpenAIModel.TextEmbedding3Large, DeepSeekModel.Flash, DeepSeekModel.V4Pro, DeepSeekModel.V4Flash, GoogleModel.Gemini38Flash, GoogleModel.Gemini37Flash, GoogleModel.Gemini36Flash, GoogleModel.Gemini35Flash, GoogleModel.Gemini35FlashLite, GoogleModel.Gemini31Pro, GoogleModel.Gemini31FlashLite, GoogleModel.Gemini25Pro, GoogleModel.Gemini25Flash, GoogleModel.Gemini25FlashLite, MiniMaxModel.M3, MiniMaxModel.M27, MiniMaxModel.M27HighSpeed, MiniMaxModel.M25, MiniMaxModel.M21, MiniMaxModel.M2, MistralModel.Large, MistralModel.Medium, MistralModel.Small, MistralModel.Codestral, MistralModel.Ministral8b, MistralModel.Ministral3b, XAIModel.Grok47, XAIModel.Grok46, XAIModel.Grok45, XAIModel.Grok43, XAIModel.GrokBuild01, XAIModel.Grok4, XAIModel.Grok41Fast, ZhipuModel.GLM53, ZhipuModel.GLM53Flash, ZhipuModel.GLM53FlashX, ZhipuModel.GLM52, ZhipuModel.GLM51, ZhipuModel.GLM46, ZhipuModel.GLM45, ZhipuModel.GLM45Air, MoonshotModel.K3, MoonshotModel.K26, MoonshotModel.K27Code, MoonshotModel.K27CodeHighSpeed, QwenModel.Qwen38Max, QwenModel.Qwen38Flash, QwenModel.Qwen37Max, QwenModel.Qwen37Plus, QwenModel.Qwen36Flash, QwenModel.Qwen35Flash;
4593
+ AnthropicModel.Opus55, AnthropicModel.Opus5, AnthropicModel.Opus48, AnthropicModel.Opus47, AnthropicModel.Opus46, AnthropicModel.Sonnet55, AnthropicModel.Sonnet5, AnthropicModel.Sonnet46, AnthropicModel.Haiku55, AnthropicModel.Haiku45, OpenAIModel.GPT6Astra, OpenAIModel.GPT61Sol, OpenAIModel.GPT6Sol, OpenAIModel.GPT6Luna, OpenAIModel.GPT4o, OpenAIModel.GPT4oMini, OpenAIModel.O3, OpenAIModel.GPT41, OpenAIModel.GPT41Mini, OpenAIModel.GPT41Nano, OpenAIModel.GPT54, OpenAIModel.GPT54Mini, OpenAIModel.GPT54Nano, OpenAIModel.GPT54Pro, OpenAIModel.GPT55, OpenAIModel.GPT55Pro, OpenAIModel.GPT56Sol, OpenAIModel.GPT56Terra, OpenAIModel.GPT56Luna, OpenAIModel.O3Mini, OpenAIModel.O4Mini, OpenAIModel.TextEmbedding3Small, OpenAIModel.TextEmbedding3Large, DeepSeekModel.Flash, DeepSeekModel.V4Pro, DeepSeekModel.V4Flash, GoogleModel.Gemini38Flash, GoogleModel.Gemini37Flash, GoogleModel.Gemini36Flash, GoogleModel.Gemini35Flash, GoogleModel.Gemini35FlashLite, GoogleModel.Gemini31Pro, GoogleModel.Gemini31FlashLite, GoogleModel.Gemini25Pro, GoogleModel.Gemini25Flash, GoogleModel.Gemini25FlashLite, MiniMaxModel.M3, MiniMaxModel.M27, MiniMaxModel.M27HighSpeed, MiniMaxModel.M25, MistralModel.Large4, MistralModel.Large, MistralModel.Medium, MistralModel.Small, MistralModel.Codestral, MistralModel.Ministral8b, MistralModel.Ministral3b, XAIModel.Grok47, XAIModel.Grok46, XAIModel.Grok45, XAIModel.Grok43, XAIModel.GrokBuild01, XAIModel.Grok4, XAIModel.Grok41Fast, ZhipuModel.GLM53, ZhipuModel.GLM53Flash, ZhipuModel.GLM53FlashX, ZhipuModel.GLM52, ZhipuModel.GLM51, ZhipuModel.GLM46, ZhipuModel.GLM45, ZhipuModel.GLM45Air, MoonshotModel.K3, MoonshotModel.K26, MoonshotModel.K27Code, MoonshotModel.K27CodeHighSpeed, QwenModel.Qwen38Max, QwenModel.Qwen38Flash, QwenModel.Qwen37Max, QwenModel.Qwen37Plus, QwenModel.Qwen36Flash, QwenModel.Qwen35Flash;
4578
4594
  enumValues({
4579
4595
  Standard: "standard",
4580
4596
  AwsPrivate: "aws_private"
@@ -4726,6 +4742,19 @@ function isRetryAfterSeconds(value) {
4726
4742
  function isProfileErrorList(value) {
4727
4743
  return Array.isArray(value) && value.length > 0 && value.every((entry) => typeof entry === "object" && entry !== null && typeof entry.profile === "string" && typeof entry.message === "string");
4728
4744
  }
4745
+ /**
4746
+ * The integrations service's 409 `CLI_TOO_OLD` names the Alfe CLI the target
4747
+ * integration version needs and the agent's current one. Forward only those
4748
+ * two non-empty strings, and only alongside that code.
4749
+ */
4750
+ function cliTooOldFields(errBody) {
4751
+ if (errBody?.code !== "CLI_TOO_OLD") return {};
4752
+ const { requiredCliVersion, currentCliVersion } = errBody;
4753
+ return {
4754
+ ...typeof requiredCliVersion === "string" && requiredCliVersion !== "" ? { requiredCliVersion } : {},
4755
+ ...typeof currentCliVersion === "string" && currentCliVersion !== "" ? { currentCliVersion } : {}
4756
+ };
4757
+ }
4729
4758
  var AlfeApiClient = class {
4730
4759
  apiBaseUrl;
4731
4760
  getToken;
@@ -4803,7 +4832,8 @@ var AlfeApiClient = class {
4803
4832
  profile,
4804
4833
  message
4805
4834
  })) } : {},
4806
- ...isRetryAfterSeconds(errBody?.retryAfterSeconds) ? { retryAfterSeconds: errBody.retryAfterSeconds } : {}
4835
+ ...isRetryAfterSeconds(errBody?.retryAfterSeconds) ? { retryAfterSeconds: errBody.retryAfterSeconds } : {},
4836
+ ...cliTooOldFields(errBody)
4807
4837
  }
4808
4838
  };
4809
4839
  }
@@ -5530,16 +5560,13 @@ function _resolveManagedGatewayWsUrl(apiEndpoint) {
5530
5560
  * workspace = "~/.openclaw"
5531
5561
  */
5532
5562
  /**
5533
- * Derive the agent workspace path from the runtime's home dir.
5534
- *
5535
- * For openclaw, the agent CWD is `${home}/workspace` (matches OpenClaw's
5536
- * `agents.defaults.workspace` default — see OpenClaw README "Agent workspace
5537
- * + skills"). For other runtimes, default to home itself.
5563
+ * Derive the agent workspace path (the runtime's CWD) from its home dir.
5564
+ * Delegates to the shared `@alfe.ai/config` rule so the daemon, the CLI and
5565
+ * the claude-code host cannot drift: openclaw and claude-code run in
5566
+ * `${home}/workspace`, other runtimes run in the home itself.
5538
5567
  */
5539
5568
  function deriveAgentWorkspace(runtime, home) {
5540
- if (runtime === "openclaw") return join(home, "workspace");
5541
- if (runtime === "claude-code") return join(home, "workspace");
5542
- return home;
5569
+ return resolveAgentWorkspace(runtime, home);
5543
5570
  }
5544
5571
  const UNSAFE_RECORD_KEYS = new Set([
5545
5572
  "__proto__",
@@ -5602,6 +5629,7 @@ async function loadManagedConfig() {
5602
5629
  runtime: identity.runtime,
5603
5630
  gatewayWsUrl
5604
5631
  }, "Managed config resolved");
5632
+ const defaultModel = identity.runtime === "claude-code" ? await resolveClaudeCodeDefaultModel(apiKey, apiEndpoint) : void 0;
5605
5633
  return {
5606
5634
  apiKey,
5607
5635
  apiEndpoint,
@@ -5612,7 +5640,8 @@ async function loadManagedConfig() {
5612
5640
  orgId: identity.orgId,
5613
5641
  runtime: identity.runtime,
5614
5642
  runtimes: buildManagedRuntimes(identity.runtime),
5615
- autoStartRuntime: true
5643
+ autoStartRuntime: true,
5644
+ ...defaultModel ? { defaultModel } : {}
5616
5645
  };
5617
5646
  }
5618
5647
  /**
@@ -5635,6 +5664,13 @@ function buildManagedRuntimes(runtime) {
5635
5664
  agentWorkspace: deriveAgentWorkspace("hermes", home)
5636
5665
  } };
5637
5666
  }
5667
+ if (runtime === "claude-code") {
5668
+ const home = join(homedir(), ".claude-code");
5669
+ return { "claude-code": {
5670
+ workspace: home,
5671
+ agentWorkspace: deriveAgentWorkspace("claude-code", home)
5672
+ } };
5673
+ }
5638
5674
  return {};
5639
5675
  }
5640
5676
  /**
@@ -5657,17 +5693,7 @@ async function loadDaemonConfig() {
5657
5693
  const gatewayWsUrl = alfeConfig.gateway_url ?? deriveGatewayWsUrl(apiEndpoint);
5658
5694
  const runtimes = await loadRuntimeConfigs();
5659
5695
  const runtime = alfeConfig.runtime ?? identity.runtime;
5660
- let defaultModel;
5661
- if (runtime === "claude-code") {
5662
- let timer;
5663
- const ws = await Promise.race([fetchAgentConfig(alfeConfig.api_key, apiEndpoint), new Promise((resolve) => {
5664
- timer = setTimeout(() => {
5665
- resolve(null);
5666
- }, 5e3);
5667
- })]);
5668
- if (timer) clearTimeout(timer);
5669
- defaultModel = ws?.defaultModel;
5670
- }
5696
+ const defaultModel = runtime === "claude-code" ? await resolveClaudeCodeDefaultModel(alfeConfig.api_key, apiEndpoint) : void 0;
5671
5697
  return {
5672
5698
  apiKey: alfeConfig.api_key,
5673
5699
  apiEndpoint,
@@ -5683,6 +5709,38 @@ async function loadDaemonConfig() {
5683
5709
  };
5684
5710
  }
5685
5711
  /**
5712
+ * The claude-code agent's bare `defaultModel`, for `ALFE_DEFAULT_MODEL`.
5713
+ * Bounded so a slow or hung workspace endpoint can't block daemon startup; any
5714
+ * failure or timeout yields `undefined` and the host falls back to the `claude`
5715
+ * CLI default. Shared by the managed and self-hosted config loaders.
5716
+ */
5717
+ async function resolveClaudeCodeDefaultModel(apiKey, apiEndpoint, options = {}) {
5718
+ const fetcher = options.fetcher ?? fetchWorkspaceDefaultModel;
5719
+ let timer;
5720
+ try {
5721
+ return (await Promise.race([fetcher(apiKey, apiEndpoint), new Promise((resolve) => {
5722
+ timer = setTimeout(() => {
5723
+ resolve(null);
5724
+ }, options.timeoutMs ?? 5e3);
5725
+ })]))?.defaultModel ?? void 0;
5726
+ } catch {
5727
+ return;
5728
+ } finally {
5729
+ if (timer) clearTimeout(timer);
5730
+ }
5731
+ }
5732
+ /**
5733
+ * Workspace metadata only. The default model lives on the workspace record, so
5734
+ * it must not wait on (or time out behind) the persona/template file fetch
5735
+ * that `fetchAgentConfig` also performs.
5736
+ */
5737
+ async function fetchWorkspaceDefaultModel(apiKey, apiEndpoint) {
5738
+ return { defaultModel: (await new AgentApiClient({
5739
+ apiKey,
5740
+ apiUrl: apiEndpoint
5741
+ }).getWorkspace()).defaultModel ?? void 0 };
5742
+ }
5743
+ /**
5686
5744
  * Fetch agent workspace config from the API.
5687
5745
  *
5688
5746
  * 1. GET /agents/me/workspace → { templateKey }
@@ -7105,8 +7163,10 @@ var ConfigReconciler = class {
7105
7163
  getApplier;
7106
7164
  verifyRetries;
7107
7165
  verifyRetryDelayMs;
7166
+ onKeysApplied;
7108
7167
  constructor(options) {
7109
7168
  this.getApplier = options.getApplier;
7169
+ this.onKeysApplied = options.onKeysApplied;
7110
7170
  this.verifyRetries = options.verifyRetries ?? DEFAULT_VERIFY_RETRIES;
7111
7171
  this.verifyRetryDelayMs = options.verifyRetryDelayMs ?? DEFAULT_VERIFY_RETRY_DELAY_MS;
7112
7172
  }
@@ -7129,6 +7189,7 @@ var ConfigReconciler = class {
7129
7189
  };
7130
7190
  const failures = [];
7131
7191
  const inconclusiveKeys = [];
7192
+ const changedKeys = [];
7132
7193
  for (const [key, want] of entries) try {
7133
7194
  if (getConfigRaw) {
7134
7195
  let current;
@@ -7149,8 +7210,11 @@ var ConfigReconciler = class {
7149
7210
  if (getConfigRaw) {
7150
7211
  const outcome = await this.verify(getConfigRaw, key, want);
7151
7212
  if (outcome === "mismatched") failures.push(`${key}: verify failed (read-back did not match)`);
7152
- else if (outcome === "inconclusive") inconclusiveKeys.push(key);
7153
- }
7213
+ else {
7214
+ if (outcome === "inconclusive") inconclusiveKeys.push(key);
7215
+ changedKeys.push(key);
7216
+ }
7217
+ } else changedKeys.push(key);
7154
7218
  } catch (err) {
7155
7219
  const msg = err instanceof Error ? err.message : String(err);
7156
7220
  if (getConfigRaw) {
@@ -7160,15 +7224,18 @@ var ConfigReconciler = class {
7160
7224
  key,
7161
7225
  err: msg
7162
7226
  }, "config set errored but value landed — treating as applied");
7227
+ changedKeys.push(key);
7163
7228
  continue;
7164
7229
  }
7165
7230
  if (outcome === "inconclusive") {
7166
7231
  inconclusiveKeys.push(key);
7232
+ changedKeys.push(key);
7167
7233
  continue;
7168
7234
  }
7169
7235
  }
7170
7236
  failures.push(`${key}: ${msg}`);
7171
7237
  }
7238
+ this.notifyKeysApplied(changedKeys);
7172
7239
  if (failures.length > 0) {
7173
7240
  const joined = failures.join("; ");
7174
7241
  const reason = joined.length > 480 ? `${joined.slice(0, 480)}… (truncated)` : joined;
@@ -7198,6 +7265,17 @@ var ConfigReconciler = class {
7198
7265
  status: "applied"
7199
7266
  };
7200
7267
  }
7268
+ notifyKeysApplied(keys) {
7269
+ if (keys.length === 0 || !this.onKeysApplied) return;
7270
+ try {
7271
+ this.onKeysApplied(keys);
7272
+ } catch (err) {
7273
+ log$4.warn({
7274
+ keys,
7275
+ err: err instanceof Error ? err.message : String(err)
7276
+ }, "onKeysApplied hook failed — config report unaffected");
7277
+ }
7278
+ }
7201
7279
  async verify(getConfigRaw, key, want) {
7202
7280
  let observedValue = false;
7203
7281
  for (let attempt = 0; attempt <= this.verifyRetries; attempt++) {
@@ -7216,6 +7294,39 @@ var ConfigReconciler = class {
7216
7294
  return observedValue ? "mismatched" : "inconclusive";
7217
7295
  }
7218
7296
  };
7297
+ /** Extra environment for the runtime child, layered over the daemon's own env. */
7298
+ function buildRuntimeEnv(input) {
7299
+ if (input.runtime !== "claude-code") return {};
7300
+ return {
7301
+ ...input.defaultModel ? { ALFE_DEFAULT_MODEL: input.defaultModel } : {},
7302
+ ...input.managed ? {
7303
+ ALFE_MANAGED: "1",
7304
+ DISABLE_AUTOUPDATER: "1"
7305
+ } : {},
7306
+ ...input.localAiProxyUrl ? { ALFE_LOCAL_AI_PROXY_URL: input.localAiProxyUrl } : {}
7307
+ };
7308
+ }
7309
+ /**
7310
+ * True when a config reconcile that wrote `keys` must restart the runtime child.
7311
+ * Only the claude-code host needs it: it reads its credential once per start.
7312
+ * OpenClaw/Hermes hot-reload their state-shaped keys.
7313
+ */
7314
+ function shouldRestartRuntimeForConfigKeys(runtime, keys) {
7315
+ return runtime === "claude-code" && keys.includes("alfe.claudeCredential.revision");
7316
+ }
7317
+ /**
7318
+ * The `ConfigReconciler.onKeysApplied` hook the daemon installs: restart the
7319
+ * runtime (through the shared, turn-draining restart path) when a reconcile
7320
+ * wrote a new claude-code credential revision. The reconciler value-diffs, so
7321
+ * a reconnect re-sending the same revision does not restart.
7322
+ */
7323
+ function createCredentialRestartHook(runtime, requestRestart, onRestart) {
7324
+ return (keys) => {
7325
+ if (!shouldRestartRuntimeForConfigKeys(runtime, keys)) return;
7326
+ onRestart?.();
7327
+ requestRestart();
7328
+ };
7329
+ }
7219
7330
  //#endregion
7220
7331
  //#region src/command-queue.ts
7221
7332
  const DEFAULT_TTL_MS$1 = 300 * 1e3;
@@ -10264,12 +10375,17 @@ async function startDaemon() {
10264
10375
  const runtimeGate = new RuntimeGate(() => runtimeProcess);
10265
10376
  runtimeGateRef = runtimeGate;
10266
10377
  cloudClient.setIntegrationManager(integrationAdapter, runtimeGate);
10267
- cloudClient.setConfigReconciler(new ConfigReconciler({ getApplier: () => runtimeAppliers.get(config.runtime) }));
10268
10378
  const requestRuntimeRestart = () => {
10269
10379
  logger.info("Runtime state changed — requesting runtime restart");
10270
10380
  runtimeGate.requestRestart();
10271
10381
  };
10272
10382
  cloudClient.setRuntimeRestartNeededHandler(requestRuntimeRestart);
10383
+ cloudClient.setConfigReconciler(new ConfigReconciler({
10384
+ getApplier: () => runtimeAppliers.get(config.runtime),
10385
+ onKeysApplied: createCredentialRestartHook(config.runtime, requestRuntimeRestart, () => {
10386
+ logger.info({ runtime: config.runtime }, "Claude credential changed — restarting runtime to refetch");
10387
+ })
10388
+ }));
10273
10389
  if (config.runtime === "hermes") {
10274
10390
  const hermesCfg = config.runtimes[config.runtime];
10275
10391
  if (hermesCfg) {
@@ -10338,7 +10454,12 @@ async function startDaemon() {
10338
10454
  runtimeProcess = new RuntimeProcess({
10339
10455
  runtime: config.runtime,
10340
10456
  workspace: runtimeCfg.workspace,
10341
- env: config.runtime === "claude-code" && config.defaultModel ? { ALFE_DEFAULT_MODEL: config.defaultModel } : {}
10457
+ env: buildRuntimeEnv({
10458
+ runtime: config.runtime,
10459
+ ...config.defaultModel ? { defaultModel: config.defaultModel } : {},
10460
+ managed,
10461
+ ...aiProxyUrl ? { localAiProxyUrl: aiProxyUrl } : {}
10462
+ })
10342
10463
  });
10343
10464
  runtimeProcess.setTurnActivityProbe(turnActivityProbe);
10344
10465
  if (firstRuntimeStart) {
@@ -10556,7 +10677,7 @@ async function executeCloudCommand(command) {
10556
10677
  pinnedVersion: target.version
10557
10678
  }, "runtime.update requested an OpenClaw version above the pin — upgrading to the pin instead");
10558
10679
  version = target.version;
10559
- } else version = payload?.version ?? (runtime === "claude-code" ? "0.1.6" : void 0);
10680
+ } else version = payload?.version ?? (runtime === "claude-code" ? "0.1.16" : void 0);
10560
10681
  upgradingRuntime = true;
10561
10682
  setTimeout(() => {
10562
10683
  (async () => {
@@ -11031,4 +11152,4 @@ function formatDuration(ms) {
11031
11152
  return `${String(Math.round(seconds / 3600))}h`;
11032
11153
  }
11033
11154
  //#endregion
11034
- export { loadDaemonConfig as _, installService as a, startService as c, uninstallService as d, PROTOCOL_VERSION as f, fetchAgentConfig as g, SOCKET_PATH as h, checkExistingDaemon as i, stopExistingDaemon as l, PID_PATH as m, queryDaemonHealth as n, isServiceInstalled as o, ALFE_DIR as p, startDaemon as r, restartService as s, formatHealthReport as t, stopService as u, resolveAgentIdentity as v, PINNED_CLAUDE_CODE_HOST_VERSION as y };
11155
+ export { loadDaemonConfig as _, installService as a, PINNED_CLAUDE_CODE_VERSION as b, startService as c, uninstallService as d, PROTOCOL_VERSION as f, fetchAgentConfig as g, SOCKET_PATH as h, checkExistingDaemon as i, stopExistingDaemon as l, PID_PATH as m, queryDaemonHealth as n, isServiceInstalled as o, ALFE_DIR as p, startDaemon as r, restartService as s, formatHealthReport as t, stopService as u, resolveAgentIdentity as v, PINNED_CLAUDE_CODE_HOST_VERSION as y };
@@ -145,11 +145,23 @@ declare function remediateManagedNode(runCommand: RemediationCommandRunner, base
145
145
  * new host, then cut a CLI release so the pin travels with the CLI version. The
146
146
  * dashboard still surfaces npm-`latest` as an explicit opt-in upgrade.
147
147
  *
148
- * NOTE: claude-code is self-hosted-only (no managed Docker image), so — unlike
148
+ * NOTE: managed claude-code agents run on Hetzner VMs provisioned by cloud-init
149
+ * + `alfe setup --managed` (no Docker image), so — unlike
149
150
  * `PINNED_OPENCLAW_VERSION` — there is no `services/compute/Dockerfile` mirror to
150
151
  * keep in sync.
151
152
  */
152
- declare const PINNED_CLAUDE_CODE_HOST_VERSION = "0.1.6";
153
+ declare const PINNED_CLAUDE_CODE_HOST_VERSION = "0.1.16";
154
+ /**
155
+ * The `@anthropic-ai/claude-code` (the `claude` CLI) version Alfe installs for
156
+ * the claude-code runtime: always on managed VMs (`alfe setup --managed`), and
157
+ * on self-hosted machines only when no `claude` is present (a user-installed
158
+ * `claude` is never replaced). Pinned to npm's `stable` dist-tag as of
159
+ * 2026-10-14 — `latest` moves daily and the host drives `claude -p` flags
160
+ * (`--resume`, `--mcp-config`, `--strict-mcp-config`, `--permission-mode`)
161
+ * whose behaviour must be validated before a bump. The pin travels with the
162
+ * CLI release.
163
+ */
164
+ declare const PINNED_CLAUDE_CODE_VERSION = "2.1.287";
153
165
  //#endregion
154
166
  //#region src/sentry.d.ts
155
167
  /**
@@ -391,6 +403,13 @@ declare function resolveAgentIdentity(apiKey: string, apiEndpoint: string): Prom
391
403
  * In managed mode, loads from environment variables instead.
392
404
  */
393
405
  declare function loadDaemonConfig(): Promise<DaemonConfig>;
406
+ /**
407
+ * The claude-code agent's bare `defaultModel`, for `ALFE_DEFAULT_MODEL`.
408
+ * Bounded so a slow or hung workspace endpoint can't block daemon startup; any
409
+ * failure or timeout yields `undefined` and the host falls back to the `claude`
410
+ * CLI default. Shared by the managed and self-hosted config loaders.
411
+ */
412
+
394
413
  /**
395
414
  * Fetch agent workspace config from the API.
396
415
  *
@@ -495,4 +514,4 @@ declare function checkExistingDaemon(): Promise<number | null>;
495
514
  */
496
515
  declare function stopExistingDaemon(): Promise<boolean>;
497
516
  //#endregion
498
- export { AGENT_DAEMON_SENTRY_DSN, AGENT_MCP_SENTRY_DSN, AGENT_RUNTIME_SENTRY_DSN, ALFE_DIR, type AgentIdentity, type AgentWorkspaceConfig, type DaemonConfig, type DaemonHealth, type IPCEvent, type IPCRequest, type IPCResponse, type InitAgentSentryOptions, OPENCLAW_MANAGED_NODE_MAJOR, OPENCLAW_NODE_REQUIREMENT, PID_PATH, PINNED_CLAUDE_CODE_HOST_VERSION, PINNED_OPENCLAW_VERSION, PROTOCOL_VERSION, type RemediateManagedNodeOptions, type RemediationCommandRunner, type RuntimeOutputLine, SOCKET_PATH, type SentrySurface, captureCliFailure, captureFatal, captureIntegrationFailure, captureMcpFailure, captureRuntimeCrash, captureRuntimeErrorOutput, checkExistingDaemon, fetchAgentConfig, flushSentry, formatHealthReport, initAgentSentry, installService, isServiceInstalled, loadDaemonConfig, logger, queryDaemonHealth, remediateManagedNode, resolveAgentIdentity, restartService, setAgentContext, startDaemon, startService, stopExistingDaemon, stopService, supportsOpenClawNode, uninstallService };
517
+ export { AGENT_DAEMON_SENTRY_DSN, AGENT_MCP_SENTRY_DSN, AGENT_RUNTIME_SENTRY_DSN, ALFE_DIR, type AgentIdentity, type AgentWorkspaceConfig, type DaemonConfig, type DaemonHealth, type IPCEvent, type IPCRequest, type IPCResponse, type InitAgentSentryOptions, OPENCLAW_MANAGED_NODE_MAJOR, OPENCLAW_NODE_REQUIREMENT, PID_PATH, PINNED_CLAUDE_CODE_HOST_VERSION, PINNED_CLAUDE_CODE_VERSION, PINNED_OPENCLAW_VERSION, PROTOCOL_VERSION, type RemediateManagedNodeOptions, type RemediationCommandRunner, type RuntimeOutputLine, SOCKET_PATH, type SentrySurface, captureCliFailure, captureFatal, captureIntegrationFailure, captureMcpFailure, captureRuntimeCrash, captureRuntimeErrorOutput, checkExistingDaemon, fetchAgentConfig, flushSentry, formatHealthReport, initAgentSentry, installService, isServiceInstalled, loadDaemonConfig, logger, queryDaemonHealth, remediateManagedNode, resolveAgentIdentity, restartService, setAgentContext, startDaemon, startService, stopExistingDaemon, stopService, supportsOpenClawNode, uninstallService };
package/dist/src/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { b as PINNED_OPENCLAW_VERSION, v as OPENCLAW_MANAGED_NODE_MAJOR, w as supportsOpenClawNode, y as OPENCLAW_NODE_REQUIREMENT } from "../runtime-upgrade-recovery.js";
2
- import { _ as loadDaemonConfig, a as installService, c as startService, d as uninstallService, f as PROTOCOL_VERSION, g as fetchAgentConfig, h as SOCKET_PATH, i as checkExistingDaemon, l as stopExistingDaemon, m as PID_PATH, n as queryDaemonHealth, o as isServiceInstalled, p as ALFE_DIR, r as startDaemon, s as restartService, t as formatHealthReport, u as stopService, v as resolveAgentIdentity, y as PINNED_CLAUDE_CODE_HOST_VERSION } from "../health.js";
2
+ import { _ as loadDaemonConfig, a as installService, b as PINNED_CLAUDE_CODE_VERSION, c as startService, d as uninstallService, f as PROTOCOL_VERSION, g as fetchAgentConfig, h as SOCKET_PATH, i as checkExistingDaemon, l as stopExistingDaemon, m as PID_PATH, n as queryDaemonHealth, o as isServiceInstalled, p as ALFE_DIR, r as startDaemon, s as restartService, t as formatHealthReport, u as stopService, v as resolveAgentIdentity, y as PINNED_CLAUDE_CODE_HOST_VERSION } from "../health.js";
3
3
  import { a as captureFatal, d as flushSentry, f as initAgentSentry, h as logger, i as captureCliFailure, l as captureRuntimeCrash, n as AGENT_MCP_SENTRY_DSN, o as captureIntegrationFailure, p as setAgentContext, r as AGENT_RUNTIME_SENTRY_DSN, s as captureMcpFailure, t as AGENT_DAEMON_SENTRY_DSN, u as captureRuntimeErrorOutput } from "../sentry.js";
4
4
  import { n as remediateManagedNode } from "../node-remediation.js";
5
- export { AGENT_DAEMON_SENTRY_DSN, AGENT_MCP_SENTRY_DSN, AGENT_RUNTIME_SENTRY_DSN, ALFE_DIR, OPENCLAW_MANAGED_NODE_MAJOR, OPENCLAW_NODE_REQUIREMENT, PID_PATH, PINNED_CLAUDE_CODE_HOST_VERSION, PINNED_OPENCLAW_VERSION, PROTOCOL_VERSION, SOCKET_PATH, captureCliFailure, captureFatal, captureIntegrationFailure, captureMcpFailure, captureRuntimeCrash, captureRuntimeErrorOutput, checkExistingDaemon, fetchAgentConfig, flushSentry, formatHealthReport, initAgentSentry, installService, isServiceInstalled, loadDaemonConfig, logger, queryDaemonHealth, remediateManagedNode, resolveAgentIdentity, restartService, setAgentContext, startDaemon, startService, stopExistingDaemon, stopService, supportsOpenClawNode, uninstallService };
5
+ export { AGENT_DAEMON_SENTRY_DSN, AGENT_MCP_SENTRY_DSN, AGENT_RUNTIME_SENTRY_DSN, ALFE_DIR, OPENCLAW_MANAGED_NODE_MAJOR, OPENCLAW_NODE_REQUIREMENT, PID_PATH, PINNED_CLAUDE_CODE_HOST_VERSION, PINNED_CLAUDE_CODE_VERSION, PINNED_OPENCLAW_VERSION, PROTOCOL_VERSION, SOCKET_PATH, captureCliFailure, captureFatal, captureIntegrationFailure, captureMcpFailure, captureRuntimeCrash, captureRuntimeErrorOutput, checkExistingDaemon, fetchAgentConfig, flushSentry, formatHealthReport, initAgentSentry, installService, isServiceInstalled, loadDaemonConfig, logger, queryDaemonHealth, remediateManagedNode, resolveAgentIdentity, restartService, setAgentContext, startDaemon, startService, stopExistingDaemon, stopService, supportsOpenClawNode, uninstallService };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alfe.ai/gateway",
3
- "version": "0.10.9",
3
+ "version": "0.11.1",
4
4
  "description": "Alfe local gateway daemon — persistent control plane for agent integrations",
5
5
  "type": "module",
6
6
  "bin": {
@@ -23,11 +23,11 @@
23
23
  "pino-roll": "^1.2.0",
24
24
  "smol-toml": ">=1.6.1",
25
25
  "ws": "^8.18.0",
26
- "@alfe.ai/agent-api-client": "^0.20.0",
26
+ "@alfe.ai/agent-api-client": "^0.21.1",
27
27
  "@alfe.ai/ai-proxy-local": "^0.0.17",
28
- "@alfe.ai/config": "^0.4.1",
29
- "@alfe.ai/integration-manifest": "^0.5.0",
30
- "@alfe.ai/integrations": "^0.6.16",
28
+ "@alfe.ai/config": "^0.4.2",
29
+ "@alfe.ai/integration-manifest": "^0.6.0",
30
+ "@alfe.ai/integrations": "^0.7.1",
31
31
  "@alfe.ai/mcp-bundler": "^0.4.3"
32
32
  },
33
33
  "license": "UNLICENSED",