@commonlyai/cli 0.1.249 → 0.1.250

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.249",
3
+ "version": "0.1.250",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI — connect agents, manage pods, iterate fast",
6
6
  "type": "module",
@@ -138,6 +138,7 @@ import {
138
138
  resolveCascadeSettings,
139
139
  } from '../lib/enforcement.js';
140
140
  import { buildReplyReceipt } from '../lib/reply-receipt.js';
141
+ import { savedRuntimeControls, withSavedRuntimeControls, effortRefusedByDevice } from '../lib/seat-runtime-controls.js';
141
142
 
142
143
  const isPodFocusDiagnostic = (error) => (
143
144
  typeof error?.code === 'string'
@@ -1662,6 +1663,10 @@ export const performRun = ({
1662
1663
  // The agent to @mention when the model provider refuses a request's content
1663
1664
  // (lib/content-refusal.js). Null: the refusal notice names no one.
1664
1665
  reportRuntime = false,
1666
+ // D247: a listener seat (no daemon) reads the model and effort its owner
1667
+ // saved on the server before each turn. Off for daemon seats, whose daemon
1668
+ // projects the same values into `environment`.
1669
+ readSavedControls = false,
1665
1670
  resolveOwnProviderKey = null,
1666
1671
  runtimeReportClient = null,
1667
1672
  refusalHandoff = null,
@@ -1765,6 +1770,7 @@ export const performRun = ({
1765
1770
  const runtimeInventoryPromise = reportRuntime ? Promise.resolve(adapter.inventory?.()).then((value) => value || { models: null, efforts: [] })
1766
1771
  .catch(() => ({ models: null, efforts: [] })) : Promise.resolve(null);
1767
1772
  let seatEnvironment = requestedSeatEnvironment;
1773
+ let lastSavedControls = null;
1768
1774
  // OpenCode retains tool-call IDs in its resumed history. A Gemini proxy
1769
1775
  // marks those IDs with signature references, so changing providers must
1770
1776
  // start a fresh session before another upstream can receive them.
@@ -1848,7 +1854,43 @@ export const performRun = ({
1848
1854
  // a conversation that read the workspace, whatever claude's resume would
1849
1855
  // find from another folder.
1850
1856
  let lastPlacementReason = null;
1857
+ // D247: the model and effort this turn spawns with. A listener seat reads
1858
+ // its saved controls first; then an effort is dropped only when the device
1859
+ // listed its levels and this one is not among them.
1860
+ let savedControlsNoticeShown = false;
1861
+ const refreshSeatEnvironment = async () => {
1862
+ const inventory = await runtimeInventoryPromise;
1863
+ let desiredEnvironment = requestedSeatEnvironment;
1864
+ if (readSavedControls) {
1865
+ try {
1866
+ const identity = await client.get('/api/agents/runtime/installations', {}, {
1867
+ signal: AbortSignal.timeout(5000),
1868
+ });
1869
+ lastSavedControls = savedRuntimeControls({
1870
+ installations: identity?.installations, podId, instanceId,
1871
+ ...(identity && 'runtimeSourcePodId' in identity ? { runtimeSourcePodId: identity.runtimeSourcePodId } : {}),
1872
+ });
1873
+ } catch { /* keep the last controls read; a failed read changes nothing */ }
1874
+ desiredEnvironment = withSavedRuntimeControls(requestedSeatEnvironment, lastSavedControls);
1875
+ // A record with no environment (from before attach wrote one) isn't
1876
+ // given one silently. `agent config` writes one to the record, and from
1877
+ // then on saved controls apply. Say so once, with the command.
1878
+ if (!requestedSeatEnvironment && lastSavedControls && !savedControlsNoticeShown) {
1879
+ savedControlsNoticeShown = true;
1880
+ const flag = (name, value) => (value && /^[A-Za-z0-9._:/-]+$/.test(value) ? ` --${name} ${value}` : '');
1881
+ const flags = `${flag('model', lastSavedControls.model)}${flag('effort', lastSavedControls.effort)}` || ' --model <model>';
1882
+ log(`${agentName} has no saved environment on this computer, so the model and effort saved in Commonly `
1883
+ + `don't apply to it yet. Run once: commonly agent config ${agentName}${flags}`);
1884
+ }
1885
+ }
1886
+ // Dropped only when the device listed its levels and this one is not
1887
+ // among them; with nothing reported the harness decides (D247).
1888
+ seatEnvironment = reportRuntime && desiredEnvironment
1889
+ && effortRefusedByDevice(inventory, desiredEnvironment.effort)
1890
+ ? { ...desiredEnvironment, effort: undefined } : desiredEnvironment;
1891
+ };
1851
1892
  const placeTurn = async () => {
1893
+ await refreshSeatEnvironment();
1852
1894
  if (seatEnvironment?.sandbox?.trust !== 'workspace') {
1853
1895
  return { environment: seatEnvironment, cwd: agentCwd, binding: sessionBinding };
1854
1896
  }
@@ -1879,10 +1921,6 @@ export const performRun = ({
1879
1921
  const batchLimit = Math.min(50, Math.max(1, Number(inboxBatchLimit) || 10));
1880
1922
 
1881
1923
  const processEvent = async (event) => {
1882
- const inventory = await runtimeInventoryPromise;
1883
- if (reportRuntime && requestedSeatEnvironment && !inventory?.efforts.includes(requestedSeatEnvironment.effort)) {
1884
- seatEnvironment = { ...requestedSeatEnvironment, effort: undefined };
1885
- }
1886
1924
  const eventPodId = event.podId || podId;
1887
1925
  const prompt = extractPrompt(event);
1888
1926
  if (!prompt || !eventPodId) {
@@ -4451,6 +4489,7 @@ Docs:
4451
4489
  resolveOwnProviderKey: createOwnKeyResolver({ instanceUrl: record.instanceUrl,
4452
4490
  machineId: record.machineId, agentName: record.agentName, instanceId: record.instanceId }),
4453
4491
  reportRuntime: Boolean(record.machineId || process.env.COMMONLY_MANAGED_RUNNER === '1'),
4492
+ readSavedControls: !record.machineId && process.env.COMMONLY_MANAGED_RUNNER !== '1',
4454
4493
  spawnCredentialTtlSeconds: resolveSpawnTtlSeconds(process.env),
4455
4494
  refusalHandoff: opts.refusalHandoff || null,
4456
4495
  log: (line) => console.log(`${stamp()} [${name}] ${line}`),
@@ -968,7 +968,13 @@ export default {
968
968
  // came in with > null. The wrapper persists whichever non-null value
969
969
  // we return so subsequent turns hit `codex exec resume <id>`.
970
970
  const newSessionId = threadId || ctx.sessionId || null;
971
- return { text, newSessionId };
971
+ // D247: the reply receipt names the model and effort this spawn passed
972
+ // (`--model`, `model_reasoning_effort`); codex's own stream does not
973
+ // restate them.
974
+ const effort = ctx.environment?.effort;
975
+ const stats = { ...(seatModel ? { model: String(seatModel) } : {}),
976
+ ...(typeof effort === 'string' && effort ? { effort } : {}) };
977
+ return { text, newSessionId, ...(Object.keys(stats).length ? { stats } : {}) };
972
978
  } finally {
973
979
  try { await rm(dir, { recursive: true, force: true }); } catch { /* ignore */ }
974
980
  }
@@ -11,7 +11,7 @@ export const claudeEffortsFromHelp = (help) => {
11
11
  };
12
12
  export const codexModelsFromCache = (cache) => {
13
13
  const models = Array.isArray(cache?.models) ? cache.models.filter((row) => typeof row.slug === 'string'
14
- && row.slug.length > 0 && row.slug.length <= 256 && row.visibility !== 'hidden') : [];
14
+ && row.slug.length > 0 && row.slug.length <= 256 && row.visibility !== 'hidden' && row.visibility !== 'hide') : [];
15
15
  const levels = models.map((row) => (Array.isArray(row.supported_reasoning_levels)
16
16
  ? row.supported_reasoning_levels.flatMap((level) => typeof level.effort === 'string' ? [level.effort] : []) : []));
17
17
  return { models: models.length ? models.map((row) => row.slug) : null,
@@ -43,6 +43,8 @@ export const buildReplyReceipt = ({ adapterName, stats = {}, durationMs } = {})
43
43
  // carries the account or project it runs in; that is not this reply's to
44
44
  // publish, so such a model id is left out.
45
45
  if (isName(stats?.model) && !/^arn:|(^|\/)projects\//i.test(stats.model)) receipt.model = stats.model;
46
+ // D247: the effort level the adapter passed, as a bare level name.
47
+ if (isName(stats?.effort) && /^[a-z0-9][a-z0-9._-]{0,19}$/i.test(stats.effort)) receipt.effort = stats.effort;
46
48
  if (isCount(stats?.turns)) receipt.turns = stats.turns;
47
49
  if (Array.isArray(stats?.tools)) {
48
50
  const tools = stats.tools.filter(isName);
@@ -0,0 +1,61 @@
1
+ // D247: the model and effort a seat spawns with.
2
+ //
3
+ // Two rules live here so the run loop and its tests share them:
4
+ //
5
+ // 1. A listener seat (`agent run` with no daemon behind it) reads the model and
6
+ // effort its owner saved in Settings or on the add page from
7
+ // GET /api/agents/runtime/installations before each turn. A saved value
8
+ // replaces the one in the local record; an absent one leaves it alone, so an
9
+ // older server changes nothing.
10
+ // 2. An effort is dropped only when the device reported a NON-EMPTY list of
11
+ // levels that leaves it out. A device that reported nothing says nothing
12
+ // about the level, so the level is passed through and the harness decides.
13
+
14
+ const isControl = (value) => typeof value === 'string' && value.length > 0 && value.length <= 256;
15
+
16
+ const controlsOf = (row) => {
17
+ const controls = {};
18
+ if (isControl(row.runtimeControls.model)) controls.model = row.runtimeControls.model;
19
+ if (isControl(row.runtimeControls.effort)) controls.effort = row.runtimeControls.effort;
20
+ return Object.keys(controls).length ? controls : null;
21
+ };
22
+
23
+ /**
24
+ * The saved controls for this seat, or null when none are reported.
25
+ *
26
+ * A server that names `runtimeSourcePodId` (the installation Settings reads)
27
+ * is followed exactly: that row's controls, or null when it has none or the
28
+ * server names no source. An older server names none, and the seat reads its
29
+ * own pod's row, then any row of this instance that has controls.
30
+ */
31
+ export const savedRuntimeControls = ({ installations, podId, instanceId, runtimeSourcePodId } = {}) => {
32
+ if (!Array.isArray(installations)) return null;
33
+ const rows = installations.filter((row) => row?.type === 'installation'
34
+ && row.runtimeControls && typeof row.runtimeControls === 'object');
35
+ const wantedInstance = String(instanceId || 'default');
36
+ if (runtimeSourcePodId !== undefined) {
37
+ const source = runtimeSourcePodId === null ? null
38
+ : rows.find((entry) => String(entry.podId || '') === String(runtimeSourcePodId)
39
+ && String(entry.instanceId || 'default') === wantedInstance);
40
+ return source ? controlsOf(source) : null;
41
+ }
42
+ // /installations returns runtimeControls on every row, `{}` when nothing is
43
+ // saved, so both matches require a value: an empty row in this pod must not
44
+ // hide the controls saved on the identity's other installation.
45
+ const hasControls = (entry) => isControl(entry.runtimeControls.model) || isControl(entry.runtimeControls.effort);
46
+ const row = rows.find((entry) => String(entry.podId || '') === String(podId || '')
47
+ && String(entry.instanceId || 'default') === wantedInstance && hasControls(entry))
48
+ || rows.find((entry) => String(entry.instanceId || 'default') === wantedInstance && hasControls(entry));
49
+ return row ? controlsOf(row) : null;
50
+ };
51
+
52
+ /** The environment with saved controls laid over it. A null environment stays null. */
53
+ export const withSavedRuntimeControls = (environment, controls) => {
54
+ if (!environment || typeof environment !== 'object' || !controls) return environment;
55
+ return { ...environment, ...controls };
56
+ };
57
+
58
+ /** True only when the device listed its effort levels and this one is not among them. */
59
+ export const effortRefusedByDevice = (inventory, effort) => Boolean(effort)
60
+ && Array.isArray(inventory?.efforts) && inventory.efforts.length > 0
61
+ && !inventory.efforts.includes(effort);