@evident-ai/cli 3.6.1-dev.2fd7890 → 3.6.1-dev.3692523

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/README.md CHANGED
@@ -125,6 +125,10 @@ Options:
125
125
  - `--opencode-config-overlay <path>` — Apply a runner-provided OpenCode config
126
126
  before starting OpenCode. Relative paths are resolved from the working directory;
127
127
  an existing `opencode.jsonc` is replaced before `opencode.json`.
128
+ - `--auto-configure-credentials-proxy` — Install Evident's generated `evident-*`
129
+ OpenCode provider entries for the runner's credential pool. This is off by default;
130
+ without it, the CLI only delivers `EVIDENT_PROXY_TOKEN` and leaves provider
131
+ configuration to you.
128
132
  - `--credential-sync-marker <path>` — Own the interval credential sync and write
129
133
  this marker once the shutdown flush has finished, so the runner image's lifecycle
130
134
  hooks can wait on it.
package/dist/index.js CHANGED
@@ -1442,7 +1442,7 @@ import ora4 from "ora";
1442
1442
  import { select as select4 } from "@inquirer/prompts";
1443
1443
 
1444
1444
  // src/lib/telemetry.ts
1445
- var CLI_VERSION = (true ? "3.6.1-dev.2fd7890" : void 0) ?? process.env.npm_package_version ?? "unknown";
1445
+ var CLI_VERSION = (true ? "3.6.1-dev.3692523" : void 0) ?? process.env.npm_package_version ?? "unknown";
1446
1446
  function getCliVersion() {
1447
1447
  return CLI_VERSION;
1448
1448
  }
@@ -3209,6 +3209,52 @@ async function getModelAttachmentCapability(port, model, client) {
3209
3209
  return null;
3210
3210
  }
3211
3211
  }
3212
+ async function isPinnedProviderLoaded(port, model, client) {
3213
+ if (client?.version === "v2") return null;
3214
+ const { model: baseModel } = splitModelVariant(model);
3215
+ if (!baseModel) return null;
3216
+ const slash = baseModel.indexOf("/");
3217
+ if (slash <= 0) return null;
3218
+ const providerId = baseModel.slice(0, slash);
3219
+ try {
3220
+ const res = await requestWithClient(port, client, "/config/providers");
3221
+ if (!res.ok) {
3222
+ console.error(
3223
+ `[isPinnedProviderLoaded] GET /config/providers returned HTTP ${res.status} (port ${port})`
3224
+ );
3225
+ return null;
3226
+ }
3227
+ const body = await res.json();
3228
+ if (body === null || typeof body !== "object" || Array.isArray(body)) {
3229
+ console.error(
3230
+ `[isPinnedProviderLoaded] GET /config/providers body was not a plain object (port ${port})`
3231
+ );
3232
+ return null;
3233
+ }
3234
+ const providers = body.providers;
3235
+ if (!Array.isArray(providers)) {
3236
+ console.error(
3237
+ `[isPinnedProviderLoaded] GET /config/providers body had no providers array (port ${port})`
3238
+ );
3239
+ return null;
3240
+ }
3241
+ const providerIds = providers.filter(
3242
+ (provider) => provider !== null && typeof provider === "object" && typeof provider.id === "string"
3243
+ ).map((provider) => provider.id);
3244
+ if (providerIds.length === 0) {
3245
+ console.error(
3246
+ `[isPinnedProviderLoaded] GET /config/providers had no provider entries with string ids (port ${port})`
3247
+ );
3248
+ return null;
3249
+ }
3250
+ return providerIds.includes(providerId);
3251
+ } catch (err) {
3252
+ console.error(
3253
+ `[isPinnedProviderLoaded] GET /config/providers failed (port ${port}): ${err instanceof Error ? err.message : String(err)}`
3254
+ );
3255
+ return null;
3256
+ }
3257
+ }
3212
3258
  async function buildFileParts(attachments, capable) {
3213
3259
  const outcomes = [];
3214
3260
  const parts = [];
@@ -5621,7 +5667,11 @@ function isSessionDbProvenanceRecord(value) {
5621
5667
  var OPENCODE2_PACKAGE_SPEC = "@opencode-ai/cli@0.0.0-beta-17823";
5622
5668
 
5623
5669
  // src/lib/opencode/opencode-version-gate.ts
5624
- var QUEUE_VALIDATED_OPENCODE_VERSIONS = ["1.17.11", "1.18.3"];
5670
+ var QUEUE_VALIDATED_OPENCODE_VERSIONS = [
5671
+ "1.17.11",
5672
+ "1.18.3",
5673
+ "1.18.35"
5674
+ ];
5625
5675
  function isQueueValidatedVersion(version2) {
5626
5676
  if (!version2) return false;
5627
5677
  return QUEUE_VALIDATED_OPENCODE_VERSIONS.includes(version2);
@@ -6666,6 +6716,7 @@ function connectTunnel(options) {
6666
6716
  }, 3e4);
6667
6717
  let relaySilenceTimeout;
6668
6718
  let relaySilenceTimedOut = false;
6719
+ let relayConnectionId;
6669
6720
  const clearRelaySilenceTimeout = () => {
6670
6721
  if (relaySilenceTimeout === void 0) return;
6671
6722
  clearTimeout(relaySilenceTimeout);
@@ -6751,7 +6802,8 @@ function connectTunnel(options) {
6751
6802
  armRelaySilenceTimeout();
6752
6803
  forwarder.setBinaryFramesSupported(message.binary_frames === true);
6753
6804
  const connectedAgentId = message.agent_id ?? agentId;
6754
- onConnected?.(connectedAgentId);
6805
+ relayConnectionId = message.connection_id;
6806
+ onConnected?.(connectedAgentId, relayConnectionId);
6755
6807
  resolve5({
6756
6808
  ws,
6757
6809
  close: () => ws.close(1e3, "CLI shutdown")
@@ -6788,7 +6840,7 @@ function connectTunnel(options) {
6788
6840
  clearRelaySilenceTimeout();
6789
6841
  const reasonStr = (relaySilenceTimedOut ? "no relay heartbeat for 90s \u2014 reconnecting" : void 0) || reason.toString() || upgradeRejection || (code === 1006 ? "abnormal closure" : "No reason provided");
6790
6842
  forwarder.abortAll();
6791
- onDisconnected?.(code, reasonStr);
6843
+ onDisconnected?.(code, reasonStr, relayConnectionId);
6792
6844
  });
6793
6845
  });
6794
6846
  }
@@ -6851,7 +6903,7 @@ var RunnerConnection = class _RunnerConnection {
6851
6903
  authHeader: this.opts.getAuthHeader(),
6852
6904
  port: this.opts.port,
6853
6905
  openCodePassword: this.opts.openCodePassword,
6854
- onConnected: (agentId) => {
6906
+ onConnected: (agentId, relayConnectionId) => {
6855
6907
  const attempt = this.reconnectAttempt + 1;
6856
6908
  this.reconnectAttempt = 0;
6857
6909
  this.reconnecting = false;
@@ -6861,13 +6913,17 @@ var RunnerConnection = class _RunnerConnection {
6861
6913
  this.disconnectedAtMs = null;
6862
6914
  events.onConnected(agentId, isReconnect, {
6863
6915
  generation: this.generation,
6916
+ relayConnectionId: relayConnectionId ?? null,
6864
6917
  attempt,
6865
6918
  downtimeMs
6866
6919
  });
6867
6920
  },
6868
- onDisconnected: (code, reason) => {
6921
+ onDisconnected: (code, reason, relayConnectionId) => {
6869
6922
  this.disconnectedAtMs = this.now();
6870
- events.onDisconnected(code, reason, { generation: this.generation });
6923
+ events.onDisconnected(code, reason, {
6924
+ generation: this.generation,
6925
+ relayConnectionId: relayConnectionId ?? null
6926
+ });
6871
6927
  const relayRequestedReconnect = code === 1e3 && _RunnerConnection.RELAY_RECONNECT_CLOSE_REASONS.has(reason);
6872
6928
  if (this.opts.isRunning() && (code !== 1e3 || relayRequestedReconnect) && !this.reconnecting) {
6873
6929
  this.reconnectPromise = this.connectWithRetry(true).catch((err) => {
@@ -8712,6 +8768,47 @@ var ChannelDriver = class _ChannelDriver {
8712
8768
  agent: message.opencode_agent ?? void 0,
8713
8769
  model: message.opencode_model ?? void 0
8714
8770
  };
8771
+ const pinnedProviderLoaded = await isPinnedProviderLoaded(
8772
+ this.port,
8773
+ options.model,
8774
+ this.openCodeClient
8775
+ );
8776
+ if (pinnedProviderLoaded === false) {
8777
+ const dispatchedModel = message.opencode_model;
8778
+ const separator = dispatchedModel?.indexOf("/") ?? -1;
8779
+ const hasProviderAndModel = dispatchedModel !== null && separator > 0 && separator < dispatchedModel.length - 1;
8780
+ const providerId = hasProviderAndModel ? dispatchedModel.slice(0, separator) : null;
8781
+ const modelId = hasProviderAndModel ? dispatchedModel.slice(separator + 1) : null;
8782
+ const errorMessage3 = `Provider namespace not loaded on this runner: ${message.opencode_model}. Refused before dispatch; no turn was started.`;
8783
+ this.log({
8784
+ level: "error",
8785
+ message: `Refusing message ${message.id.slice(0, 8)} in conversation ${conv.id.slice(0, 8)}: provider namespace ${providerId ?? "(unknown)"} is not loaded; no turn was started`,
8786
+ conversation_id: conv.id,
8787
+ message_id: message.id
8788
+ });
8789
+ try {
8790
+ await this.markFailed(conv.id, message.id, sessionId, errorMessage3, void 0, {
8791
+ classification: {
8792
+ kind: "model_auth",
8793
+ providerId,
8794
+ modelId,
8795
+ reason: "missing"
8796
+ },
8797
+ errorShape: { name: null, statusCode: null }
8798
+ });
8799
+ this.signalDispatchNotStarted(conv, message, "model_provider_absent");
8800
+ } catch (markErr) {
8801
+ this.log({
8802
+ level: "warn",
8803
+ message: `markFailed PATCH for refused message ${message.id.slice(0, 8)} (conversation ${conv.id.slice(0, 8)}) failed: ${markErr instanceof Error ? markErr.message : String(markErr)}`,
8804
+ conversation_id: conv.id,
8805
+ message_id: message.id
8806
+ });
8807
+ this.signalDispatchNotStarted(conv, message, "failure_unreported");
8808
+ }
8809
+ await this.repairProviderRegistry(conv.id, message.id);
8810
+ break;
8811
+ }
8715
8812
  let opencodeMessageId;
8716
8813
  let preDispatchUserIds = null;
8717
8814
  try {
@@ -13910,22 +14007,6 @@ function mergeManagedOpenCodeConfigContent(content, managedProviders) {
13910
14007
  }
13911
14008
  return JSON.stringify({ ...config, provider: { ...provider, ...managedProviders } });
13912
14009
  }
13913
- function removeManagedOpenCodeConfigContent(content) {
13914
- if (!content?.trim()) return content;
13915
- const config = parseConfigContent(content);
13916
- if (typeof config.provider !== "object" || config.provider === null || Array.isArray(config.provider)) {
13917
- return content;
13918
- }
13919
- const provider = { ...config.provider };
13920
- let changed = false;
13921
- for (const namespace of CREDENTIAL_PROXY_NATIVE_NAMESPACES) {
13922
- if (namespace in provider) {
13923
- delete provider[namespace];
13924
- changed = true;
13925
- }
13926
- }
13927
- return changed ? JSON.stringify({ ...config, provider }) : content;
13928
- }
13929
14010
  function isFile(filePath) {
13930
14011
  return existsSync2(filePath) && statSync6(filePath).isFile();
13931
14012
  }
@@ -14387,23 +14468,23 @@ async function responseJson(response) {
14387
14468
  function readSetup(value) {
14388
14469
  if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
14389
14470
  const setup = value;
14390
- if (typeof setup.runner_id !== "string" || typeof setup.generation !== "string" || typeof setup.status !== "string" || setup.token_id !== null && typeof setup.token_id !== "string") {
14471
+ if (typeof setup.runner_id !== "string" || typeof setup.generation !== "string" || typeof setup.status !== "string" || setup.token_id !== null && typeof setup.token_id !== "string" || typeof setup.acknowledged_at !== "string" && setup.acknowledged_at !== null) {
14391
14472
  return null;
14392
14473
  }
14393
14474
  return setup;
14394
14475
  }
14395
14476
  function clearLocalSetup(options) {
14396
14477
  const env = options.env ?? process.env;
14397
- (options.store ?? defaultStore).clear(options.agentId);
14398
- delete env.EVIDENT_PROXY_TOKEN;
14399
- try {
14400
- const content = removeManagedOpenCodeConfigContent(env.OPENCODE_CONFIG_CONTENT);
14401
- if (content === void 0) delete env.OPENCODE_CONFIG_CONTENT;
14402
- else env.OPENCODE_CONFIG_CONTENT = content;
14403
- } catch (error2) {
14478
+ const store = options.store ?? defaultStore;
14479
+ const stored = store.get(options.agentId);
14480
+ store.clear(options.agentId);
14481
+ const token = env.EVIDENT_PROXY_TOKEN;
14482
+ if (token !== void 0 && token === stored?.token) {
14483
+ delete env.EVIDENT_PROXY_TOKEN;
14484
+ } else if (token !== void 0) {
14404
14485
  options.log(
14405
- "MANAGED-INFERENCE-CLEANUP-PARTIAL: stored credentials were removed, but malformed OPENCODE_CONFIG_CONTENT could not be inspected",
14406
- "warn"
14486
+ `MANAGED-INFERENCE-CLEANUP-PRESERVED-EXTERNAL-TOKEN: runner=${options.agentId}`,
14487
+ "debug"
14407
14488
  );
14408
14489
  }
14409
14490
  }
@@ -14429,6 +14510,25 @@ async function discoverManagedInferenceSetup(options) {
14429
14510
  const setup = readSetup(body?.setup);
14430
14511
  return setup ? { kind: "setup", setup } : { kind: "failed", reason: "Managed setup discovery returned an invalid response" };
14431
14512
  }
14513
+ async function enrollManagedInferenceSetup(options) {
14514
+ const response = await post(options, "enroll", {});
14515
+ if (!response) {
14516
+ return { kind: "failed", reason: safeFailure("Managed credential enrollment") };
14517
+ }
14518
+ if (response.status === 404) {
14519
+ return { kind: "none" };
14520
+ }
14521
+ const body = await responseJson(response);
14522
+ if (!response.ok) {
14523
+ const serverError = body?.error;
14524
+ return {
14525
+ kind: "failed",
14526
+ reason: typeof serverError === "string" && serverError.trim() ? redactDiagnosticText(serverError).slice(0, 500) : safeFailure("Managed credential enrollment", response.status)
14527
+ };
14528
+ }
14529
+ const setup = readSetup(body?.setup);
14530
+ return setup ? { kind: "setup", setup } : { kind: "failed", reason: "Managed credential enrollment returned an invalid response" };
14531
+ }
14432
14532
  async function post(options, operation, body) {
14433
14533
  const headers = requestHeaders(options);
14434
14534
  try {
@@ -14443,31 +14543,37 @@ async function post(options, operation, body) {
14443
14543
  }
14444
14544
  }
14445
14545
  function applyCredential(options, credential) {
14446
- const { config, unsupportedProviders } = buildCredentialProxyNativeConfig({
14447
- inferenceBaseUrl: credential.inferenceBaseUrl,
14448
- modelDescriptors: credential.modelDescriptors
14449
- });
14450
- if (unsupportedProviders.length > 0 || Object.keys(config.provider).length === 0) {
14451
- return "Managed setup contains unsupported provider descriptors";
14452
- }
14453
14546
  const env = options.env ?? process.env;
14454
14547
  let merged;
14455
- try {
14456
- merged = mergeManagedOpenCodeConfigContent(env.OPENCODE_CONFIG_CONTENT, config.provider);
14457
- } catch (error2) {
14458
- return "OPENCODE_CONFIG_CONTENT is malformed; managed providers were not installed";
14548
+ if (options.autoConfigureCredentialsProxy) {
14549
+ const { config, unsupportedProviders } = buildCredentialProxyNativeConfig({
14550
+ inferenceBaseUrl: credential.inferenceBaseUrl,
14551
+ modelDescriptors: credential.modelDescriptors
14552
+ });
14553
+ if (unsupportedProviders.length > 0 || Object.keys(config.provider).length === 0) {
14554
+ return "Managed setup contains unsupported provider descriptors";
14555
+ }
14556
+ try {
14557
+ merged = mergeManagedOpenCodeConfigContent(env.OPENCODE_CONFIG_CONTENT, config.provider);
14558
+ } catch (error2) {
14559
+ return "OPENCODE_CONFIG_CONTENT is malformed; managed providers were not installed";
14560
+ }
14459
14561
  }
14460
14562
  try {
14461
14563
  (options.store ?? defaultStore).set(options.agentId, credential);
14462
14564
  } catch (error2) {
14565
+ const detail = (error2 instanceof Error ? error2.message : String(error2)).replaceAll(
14566
+ credential.token,
14567
+ "[redacted]"
14568
+ );
14463
14569
  options.log(
14464
- `MANAGED-INFERENCE-STORE-FAILED: runner=${options.agentId} generation=${credential.generation}`,
14570
+ `MANAGED-INFERENCE-STORE-FAILED: runner=${options.agentId} generation=${credential.generation} detail=${redactDiagnosticText(detail)}`,
14465
14571
  "warn"
14466
14572
  );
14467
14573
  return "Managed credentials could not be written to the protected store";
14468
14574
  }
14469
14575
  env.EVIDENT_PROXY_TOKEN = credential.token;
14470
- env.OPENCODE_CONFIG_CONTENT = merged;
14576
+ if (merged !== void 0) env.OPENCODE_CONFIG_CONTENT = merged;
14471
14577
  return null;
14472
14578
  }
14473
14579
  async function reportManagedInferenceApplyFailure(options, failure) {
@@ -14518,7 +14624,7 @@ async function prepareManagedInferenceSetup(options, discovery, health) {
14518
14624
  }
14519
14625
  return reaffirmStored(options, stored);
14520
14626
  }
14521
- if (discovery.setup.status === "acknowledged" && stored?.generation === discovery.setup.generation && stored.tokenId === discovery.setup.token_id) {
14627
+ if (discovery.setup.acknowledged_at !== null && stored?.generation === discovery.setup.generation && stored.tokenId === discovery.setup.token_id) {
14522
14628
  return reaffirmStored(options, stored);
14523
14629
  }
14524
14630
  const response = await post(options, "bootstrap", { generation: discovery.setup.generation });
@@ -14556,7 +14662,7 @@ async function acknowledgeManagedInferenceSetup(options, preparation) {
14556
14662
  const response = await post(options, "acknowledge", {
14557
14663
  generation: preparation.generation,
14558
14664
  token_id: preparation.tokenId,
14559
- config_validated: true
14665
+ config_validated: options.autoConfigureCredentialsProxy === true
14560
14666
  });
14561
14667
  if (!response?.ok) {
14562
14668
  throw new Error(
@@ -16359,13 +16465,17 @@ async function run(options) {
16359
16465
  agentId: state.agentId,
16360
16466
  apiUrl: getApiUrlConfig(),
16361
16467
  getAuthHeader: () => state.authHeader,
16468
+ autoConfigureCredentialsProxy: options.autoConfigureCredentialsProxy,
16362
16469
  log: (message, level = "info") => logActivity(state, {
16363
16470
  type: level === "error" ? "error" : "info",
16364
16471
  level,
16365
16472
  ...level === "error" ? { error: message } : { message }
16366
16473
  })
16367
16474
  };
16368
- const managedDiscovery = await discoverManagedInferenceSetup(managedSetupOptions);
16475
+ let managedDiscovery = await discoverManagedInferenceSetup(managedSetupOptions);
16476
+ if (managedDiscovery.kind === "none") {
16477
+ managedDiscovery = await enrollManagedInferenceSetup(managedSetupOptions);
16478
+ }
16369
16479
  let managedPreparation = { kind: "none" };
16370
16480
  if (managedDiscovery.kind === "failed") {
16371
16481
  managedPreparation = managedDiscovery;
@@ -16689,7 +16799,7 @@ async function run(options) {
16689
16799
  onConnected: (agentId, isReconnect, transition) => {
16690
16800
  state.connected = true;
16691
16801
  state.agentId = agentId;
16692
- const connectionMessage = isReconnect ? `Tunnel reconnected (runner: ${agentId}, generation: ${transition.generation}, attempt: ${transition.attempt}, offline for ${transition.downtimeMs}ms)` : `Tunnel connected (runner: ${agentId}, generation: ${transition.generation})`;
16802
+ const connectionMessage = isReconnect ? `Tunnel reconnected (runner: ${agentId}, generation: ${transition.generation}, relay connection: ${transition.relayConnectionId ?? "unknown"}, attempt: ${transition.attempt}, offline for ${transition.downtimeMs}ms)` : `Tunnel connected (runner: ${agentId}, generation: ${transition.generation}, relay connection: ${transition.relayConnectionId ?? "unknown"})`;
16693
16803
  logActivity(state, {
16694
16804
  type: "info",
16695
16805
  message: connectionMessage
@@ -16722,6 +16832,7 @@ async function run(options) {
16722
16832
  connected: state.opencodeConnected
16723
16833
  }),
16724
16834
  connection_generation: transition.generation,
16835
+ ...transition.relayConnectionId !== null ? { relay_connection_id: transition.relayConnectionId } : {},
16725
16836
  ...isReconnect && transition.downtimeMs !== null ? {
16726
16837
  reconnect_attempt: transition.attempt,
16727
16838
  downtime_ms: transition.downtimeMs
@@ -16752,12 +16863,13 @@ async function run(options) {
16752
16863
  const safeReason2 = redactDiagnosticText(reason).slice(0, MAX_DISCONNECT_REASON_LENGTH);
16753
16864
  logActivity(state, {
16754
16865
  type: "info",
16755
- message: `Tunnel disconnected (generation: ${transition.generation}, code: ${code}, reason: ${safeReason2})`
16866
+ message: `Tunnel disconnected (generation: ${transition.generation}, relay connection: ${transition.relayConnectionId ?? "unknown"}, code: ${code}, reason: ${safeReason2})`
16756
16867
  });
16757
16868
  emitAgentDisconnected(state.agentId, {
16758
16869
  code,
16759
16870
  reason: safeReason2,
16760
- connection_generation: transition.generation
16871
+ connection_generation: transition.generation,
16872
+ ...transition.relayConnectionId !== null ? { relay_connection_id: transition.relayConnectionId } : {}
16761
16873
  });
16762
16874
  if (state.interactive) displayStatus(state);
16763
16875
  },
@@ -16984,6 +17096,9 @@ program.command("run").description("Connect to Evident and process messages").op
16984
17096
  ).option(
16985
17097
  "--opencode-config-overlay <path>",
16986
17098
  "Apply this runner-provided OpenCode config before starting OpenCode."
17099
+ ).option(
17100
+ "--auto-configure-credentials-proxy",
17101
+ "Install Evident's generated OpenCode providers for the runner's credential pool (off by default)."
16987
17102
  ).option(
16988
17103
  "--credential-sync-marker <path>",
16989
17104
  "Own the interval credential sync and write this marker once the shutdown flush has finished, so the runner image's lifecycle hooks can wait on it."
@@ -17027,6 +17142,7 @@ program.command("run").description("Connect to Evident and process messages").op
17027
17142
  restoreSessionDb: options.restoreSessionDb,
17028
17143
  restoreRunnerCredentials: options.restoreRunnerCredentials,
17029
17144
  opencodeConfigOverlay: options.opencodeConfigOverlay,
17145
+ autoConfigureCredentialsProxy: options.autoConfigureCredentialsProxy,
17030
17146
  credentialSyncMarker: options.credentialSyncMarker
17031
17147
  });
17032
17148
  }