@commonlyai/cli 0.1.364 → 0.1.365

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commonlyai/cli",
3
- "version": "0.1.364",
3
+ "version": "0.1.365",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI — connect agents, manage pods, iterate fast",
6
6
  "type": "module",
@@ -1341,7 +1341,11 @@ export const updateAgentConfiguration = async ({
1341
1341
  if (Object.keys(runtime).length) config.runtime = runtime;
1342
1342
  let environment = null;
1343
1343
  if (envPath) {
1344
- environment = await parseEnv(envPath);
1344
+ // As at attach: a replacement spec keeps the Commonly kernel server, so a
1345
+ // seat run in the foreground (which applies no daemon baseline) keeps its
1346
+ // commonly_* tools.
1347
+ environment = withDefaultMcpServer(await parseEnv(envPath),
1348
+ String(runtime.adapter || record.adapter || '').trim().toLowerCase());
1345
1349
  } else if (record.environment && typeof record.environment === 'object' && !Array.isArray(record.environment)) {
1346
1350
  environment = { ...record.environment };
1347
1351
  }
@@ -2294,14 +2298,17 @@ export const performRun = ({
2294
2298
  .catch(() => ({ models: null, efforts: [] })) : Promise.resolve(null);
2295
2299
  let seatEnvironment = requestedSeatEnvironment;
2296
2300
  let lastSavedControls = null;
2297
- // OpenCode retains tool-call IDs in its resumed history. A Gemini proxy
2298
- // marks those IDs with signature references, so changing providers must
2299
- // start a fresh session before another upstream can receive them.
2301
+ // OpenCode retains tool calls in its resumed history, and Gemini's carry
2302
+ // signatures only one upstream can read, so changing providers, or the API
2303
+ // a provider is spoken through, starts a fresh session. The default API is
2304
+ // left out so a seat that never set one keeps its session across upgrades.
2305
+ const providerApi = seatEnvironment?.provider?.api;
2300
2306
  const sessionBinding = adapter?.name === 'opencode'
2301
2307
  ? createHash('sha256').update(JSON.stringify([
2302
2308
  seatEnvironment?.provider?.id || null,
2303
2309
  seatEnvironment?.provider?.baseURL || null,
2304
2310
  seatEnvironment?.provider?.keyFile || null,
2311
+ ...(providerApi && providerApi !== 'openai-chat' ? [providerApi] : []),
2305
2312
  ])).digest('hex')
2306
2313
  : null;
2307
2314
  let running = true;
@@ -50,8 +50,10 @@ import { deliverSeatCredential, withholdRuntimeCredential } from '../mcp-credent
50
50
  import {
51
51
  prepareMcpSpawn, publicMcpUnavailableError, selectedMcpVersionDir,
52
52
  } from '../mcp-home.js';
53
+ import { CLI } from '../cli-hint.js';
53
54
  import { buildMemoryPreamble } from '../memory-bridge.js';
54
55
  import {
56
+ effectiveSandboxTrust,
55
57
  isLegacySandboxTrust,
56
58
  normalizeSandboxTrust,
57
59
  refuseWorkspaceTrust,
@@ -854,6 +856,13 @@ const qualifiedProviderModel = (provider, model) => (
854
856
  provider ? `${provider.id}/${model}` : model
855
857
  );
856
858
 
859
+ // The OpenCode provider package for each shared `provider.api`.
860
+ const OPENCODE_PROVIDER_PACKAGES = Object.freeze({
861
+ 'openai-chat': '@ai-sdk/openai-compatible',
862
+ 'anthropic-messages': '@ai-sdk/anthropic',
863
+ google: '@ai-sdk/google',
864
+ });
865
+
857
866
  const buildProviderConfig = (provider, model, keyFile) => {
858
867
  if (!provider) return undefined;
859
868
  if (!model) throw new Error('OpenCode provider configuration requires environment.model');
@@ -868,10 +877,16 @@ const buildProviderConfig = (provider, model, keyFile) => {
868
877
  }
869
878
  // anthropic-messages: provider.baseURL is the host (as for Claude Code's
870
879
  // ANTHROPIC_BASE_URL); @ai-sdk/anthropic appends /messages to a /v1 base.
880
+ // google: provider.baseURL is the API root with its version
881
+ // (https://generativelanguage.googleapis.com/v1beta); @ai-sdk/google posts
882
+ // models/<id>:streamGenerateContent there and sends the key as
883
+ // x-goog-api-key. It replays Gemini 3's thought signatures, which
884
+ // @ai-sdk/openai-compatible drops (the second tool call is refused).
885
+ const npm = OPENCODE_PROVIDER_PACKAGES[provider.api || 'openai-chat'];
871
886
  const anthropic = provider.api === 'anthropic-messages';
872
887
  return {
873
888
  [provider.id]: {
874
- npm: anthropic ? '@ai-sdk/anthropic' : '@ai-sdk/openai-compatible',
889
+ npm,
875
890
  options: {
876
891
  baseURL: anthropic ? `${provider.baseURL.replace(/\/+$/, '')}/v1` : provider.baseURL,
877
892
  apiKey: `{file:${keyFile}}`,
@@ -881,6 +896,35 @@ const buildProviderConfig = (provider, model, keyFile) => {
881
896
  };
882
897
  };
883
898
 
899
+ // Gemini's OpenAI-compatible endpoint, where Gemini 3 tool calls fail.
900
+ const isGeminiCompatEndpoint = (provider) => {
901
+ try {
902
+ const url = new URL(provider.baseURL);
903
+ return url.hostname.toLowerCase() === 'generativelanguage.googleapis.com'
904
+ && /\/openai\/?$/.test(url.pathname);
905
+ } catch { return false; }
906
+ };
907
+
908
+ // The rule OpenCode adds to the shared provider check (environment.js
909
+ // providerRefusal), at config, attach, run and the daemon's adapter swap.
910
+ const openCodeProviderVerdict = (environment) => {
911
+ const provider = environment?.provider;
912
+ if (!provider || typeof provider !== 'object') return undefined;
913
+ // A public seat reaches its provider only through the local proxy, whose
914
+ // routes cover the OpenAI-compatible and Anthropic wires. Gemini's own API
915
+ // needs routes the proxy doesn't carry.
916
+ if (provider.api === 'google' && effectiveSandboxTrust(environment?.sandbox?.trust) === 'public') {
917
+ return 'provider.api "google" is for private OpenCode seats; a public seat reaches its provider through the local proxy, which does not carry Gemini\'s API. '
918
+ + `A seat a computer's daemon runs is made public, so run a Gemini seat with \`${CLI} agent run <name>\``;
919
+ }
920
+ if ((provider.api || 'openai-chat') === 'openai-chat' && isGeminiCompatEndpoint(provider)) {
921
+ return 'Gemini\'s OpenAI-compatible endpoint drops the thought signatures Gemini 3 needs for a second tool call; '
922
+ + 'in the environment file set provider.api to "google" and provider.baseURL to https://generativelanguage.googleapis.com/v1beta, '
923
+ + `then run \`${CLI} agent config <name> --env <file>\` (the agent starts a fresh session)`;
924
+ }
925
+ return undefined;
926
+ };
927
+
884
928
  const validateProviderEnvironment = async (environment, workspacePath, options = {}) => {
885
929
  if (environment?.provider === undefined) return null;
886
930
  const validation = validateEnvironmentSpec({
@@ -1312,9 +1356,11 @@ export default {
1312
1356
  name: 'opencode',
1313
1357
  runtimeType: 'opencode',
1314
1358
  supportsProvider: true,
1315
- // `provider.api`: an OpenAI-compatible endpoint, or Anthropic's Messages API
1316
- // through OpenCode's own @ai-sdk/anthropic provider.
1317
- providerApis: ['openai-chat', 'anthropic-messages'],
1359
+ // `provider.api`: an OpenAI-compatible endpoint, Anthropic's Messages API
1360
+ // through OpenCode's own @ai-sdk/anthropic provider, or Gemini's own API
1361
+ // through @ai-sdk/google (private seats only).
1362
+ providerApis: Object.keys(OPENCODE_PROVIDER_PACKAGES),
1363
+ providerVerdict: openCodeProviderVerdict,
1318
1364
 
1319
1365
  async validateEnvironment(environment, workspacePath) {
1320
1366
  return validateProviderEnvironment(environment, workspacePath);
@@ -1364,6 +1410,10 @@ export default {
1364
1410
  }
1365
1411
 
1366
1412
  const provider = ctx.environment?.provider;
1413
+ // Attach and config refuse these first; a turn refuses them too, for a
1414
+ // record written by an older CLI.
1415
+ const providerVerdict = openCodeProviderVerdict(ctx.environment);
1416
+ if (providerVerdict) throw new Error(providerVerdict);
1367
1417
  if (isPublic && !provider) {
1368
1418
  throw new Error('public OpenCode seats require environment.provider; the implicit public tier and operator auth.json are unsupported for public trust');
1369
1419
  }
@@ -1384,16 +1434,6 @@ export default {
1384
1434
  : childSourceEnv;
1385
1435
  const binary = ctx._binaryPath || spawnBinaryPath(runtimeEnv);
1386
1436
  const installedVersion = readOpenCodeVersion(binary, runtimeEnv);
1387
- // Trusted seats otherwise allow old binaries. Gemini requires a stable
1388
- // release with native signature replay now that the proxy shim is gone.
1389
- if (provider && new URL(provider.baseURL).hostname.toLowerCase() === 'generativelanguage.googleapis.com'
1390
- && (!installedVersion || isOpenCodePrerelease(installedVersion)
1391
- || compareOpenCodeVersions(installedVersion, TESTED_OPENCODE_VERSIONS[0]) < 0)) {
1392
- throw new Error(
1393
- `Gemini requires stable OpenCode ${TESTED_OPENCODE_VERSIONS[0]} or later for native thought-signature replay; `
1394
- + `installed version is ${installedVersion || 'unknown'}`,
1395
- );
1396
- }
1397
1437
  if (!TESTED_OPENCODE_VERSIONS.includes(installedVersion)) {
1398
1438
  const mismatch = describeOpenCodeVersionMismatch(installedVersion);
1399
1439
  const allowOverride = process.env[ALLOW_UNTESTED_OPENCODE_VERSION_ENV] === '1';
@@ -193,7 +193,9 @@ export const environmentForServer = (environment) => {
193
193
 
194
194
  // ── validateEnvironmentSpec ─────────────────────────────────────────────────
195
195
 
196
- export const PROVIDER_APIS = Object.freeze(['openai-chat', 'anthropic-messages']);
196
+ // `google` is Gemini's own API (generateContent), which carries Gemini 3's
197
+ // thought signatures; its OpenAI-compatible endpoint loses them (docs/cli/opencode.md).
198
+ export const PROVIDER_APIS = Object.freeze(['openai-chat', 'anthropic-messages', 'google']);
197
199
 
198
200
  // One provider check for config, attach, run and the daemon's adapter swap: the adapter must take a
199
201
  // provider block at all, and speak its `provider.api` (default openai-chat). An adapter's