@commonlyai/cli 0.1.364 → 0.1.366

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.366",
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;
@@ -3831,6 +3838,13 @@ export const performRun = ({
3831
3838
  // The arguments of the turn that just threw, for noticeCutOff.
3832
3839
  let failedTurn = null;
3833
3840
  let heldRenewTimer = null;
3841
+ // Renews the rows a tick claimed for its later pods while an earlier pod's
3842
+ // turn runs (F237). Cleared when the tick's groups are done.
3843
+ let laterGroupsRenewTimer = null;
3844
+ const clearLaterGroupsRenewal = () => {
3845
+ if (laterGroupsRenewTimer !== null) clearIntervalImpl(laterGroupsRenewTimer);
3846
+ laterGroupsRenewTimer = null;
3847
+ };
3834
3848
  const clearHeldRenewal = () => {
3835
3849
  if (heldRenewTimer !== null) clearIntervalImpl(heldRenewTimer);
3836
3850
  heldRenewTimer = null;
@@ -4655,8 +4669,70 @@ export const performRun = ({
4655
4669
  // alongside a wake on the same page, and a private wake groups apart
4656
4670
  // from it, so a digest-only group here can be `delivered` to this run.
4657
4671
  const claimedAfter = (groupIndex) => groups.slice(groupIndex + 1).flat();
4672
+ // F237 item 1: the page's groups run one turn at a time, and a later
4673
+ // group's rows were claimed when the page was read. A turn may run 15
4674
+ // minutes and the server requeues a delivered row after 10, so they are
4675
+ // renewed while an earlier group runs. A row the server says is no
4676
+ // longer this runner's is taken out before its group starts: its ack
4677
+ // would be a stale delivery, which stops the run, and the requeue
4678
+ // redelivers it.
4679
+ // Bounded by the running turn's deadline, as processEventBatch bounds
4680
+ // its own renewal: a turn whose child ignores SIGTERM can hang, and the
4681
+ // rows behind it must lapse to the requeue rather than stay with it.
4682
+ let firstWaitingGroup = 1;
4683
+ let runningGroupSince = Date.now();
4684
+ let deadlineLogged = false;
4685
+ // One renewal at a time. A group's turn waits for one still out, so the
4686
+ // groups it names have not started when its answer is applied
4687
+ // (CodeRabbit on #4067).
4688
+ let renewingLater = null;
4689
+ clearLaterGroupsRenewal();
4690
+ if (groups.length > 1) {
4691
+ laterGroupsRenewTimer = setIntervalImpl(async () => {
4692
+ if (!running) {
4693
+ clearLaterGroupsRenewal();
4694
+ return;
4695
+ }
4696
+ if (renewingLater) return;
4697
+ // Skipped, not stopped: the next group restarts the clock, and its
4698
+ // turn needs the rows behind it renewed again.
4699
+ if (Date.now() - runningGroupSince >= effectiveTurnTimeoutMs) {
4700
+ if (!deadlineLogged) {
4701
+ deadlineLogged = true;
4702
+ log('[inbox.batch] turn deadline reached; renewal of the later pods\' rows paused while this turn overruns');
4703
+ }
4704
+ return;
4705
+ }
4706
+ const from = firstWaitingGroup;
4707
+ renewingLater = (async () => {
4708
+ const confirmed = await renewHeldDeliveries(claimedAfter(from - 1));
4709
+ if (confirmed === null) return;
4710
+ let lost = 0;
4711
+ for (let later = from; later < groups.length; later += 1) {
4712
+ const kept = groups[later].filter((event) => stillHeld(event, confirmed));
4713
+ lost += groups[later].length - kept.length;
4714
+ groups[later] = kept;
4715
+ }
4716
+ if (lost) {
4717
+ log(
4718
+ `[inbox.batch] ${countEvents(lost)} no longer held by this runner on the server while `
4719
+ + 'another pod\'s turn ran — not run; the server redelivers it',
4720
+ );
4721
+ }
4722
+ })().finally(() => { renewingLater = null; });
4723
+ await renewingLater;
4724
+ }, DELIVERY_RENEW_INTERVAL_MS);
4725
+ laterGroupsRenewTimer?.unref?.();
4726
+ }
4658
4727
  for (let groupIndex = 0; groupIndex < groups.length; groupIndex += 1) {
4728
+ // renewHeldDeliveries never throws: a failed renewal resolves null.
4729
+ // eslint-disable-next-line no-await-in-loop
4730
+ if (renewingLater) await renewingLater;
4731
+ firstWaitingGroup = groupIndex + 1;
4732
+ runningGroupSince = Date.now();
4733
+ deadlineLogged = false;
4659
4734
  const group = groups[groupIndex];
4735
+ if (group.length === 0) continue;
4660
4736
  if (!running) {
4661
4737
  // Claimed by this tick's poll (or carried into it) and never run:
4662
4738
  // a stop that arrived mid-poll or mid-page (F182). Handed back when
@@ -4994,6 +5070,7 @@ export const performRun = ({
4994
5070
  }
4995
5071
  onError?.(err);
4996
5072
  }
5073
+ clearLaterGroupsRenewal();
4997
5074
  // Notices landing during a turn share one three-second collection window
4998
5075
  // before the next inbox read, independent of the idle polling cadence. A
4999
5076
  // retry scheduled in the same tick keeps its own delay: the failure report
@@ -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