@commonlyai/cli 0.1.274 → 0.1.275

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.274",
3
+ "version": "0.1.275",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI — connect agents, manage pods, iterate fast",
6
6
  "type": "module",
@@ -1598,8 +1598,11 @@ export const runMemoryImport = async ({
1598
1598
  // would also eat a pod that is discussing these words. It speaks only to a
1599
1599
  // request it can't meet, so it gives a heartbeat no reason to post. Every closing
1600
1600
  // line carries it, and it says where the note goes once the agent has posted.
1601
+ // Walked 11-06: a seat offered an export feature that wasn't found, so a next
1602
+ // step has to be one it knows exists.
1601
1603
  const SAY_A_FAILURE = 'If you can\'t do what someone asked of you, don\'t go silent: say in plain words what didn\'t work and what they can do next, '
1602
- + 'without event types, checkpoints, deliveries, retries or other runtime terms unless they asked about them. ';
1604
+ + 'without event types, checkpoints, deliveries, retries, status codes or other runtime terms unless they asked about them. '
1605
+ + 'Only point them to a feature or option you know exists. ';
1603
1606
  const FAILURE_IN_PLAIN_WORDS = SAY_A_FAILURE
1604
1607
  + 'If you already posted in this turn, post the failure note through the tool as well: final text after a tool post is dropped.';
1605
1608
  // A comment drops final text only after a threaded reply to that comment, so
@@ -1619,6 +1622,34 @@ const FINAL_TEXT_IS_POSTED = 'Your final text is posted to the pod unless it is
1619
1622
  + 'If you did nothing, or already posted through a tool, end with NO_REPLY alone, with no summary. '
1620
1623
  + FAILURE_IN_PLAIN_WORDS;
1621
1624
 
1625
+ // Who owes an open question an answer depends on who else is here. Walked 11-06:
1626
+ // "can anyone…" drew an "I can't" from a seat nobody addressed. With another
1627
+ // agent here, that seat should step aside, and a person's message it declines
1628
+ // can go to a peer. One person alone with one seat is talking to it, and silence
1629
+ // is the worst answer a new person can get. A lone seat among several people
1630
+ // isn't told either way: the line may be for one of them (ADR-018 D6.4). With
1631
+ // several people and another agent, the peers line still holds. No line at all
1632
+ // when the server doesn't report the pod, or when an item is owed an answer
1633
+ // whatever the room looks like: a welcome, a reply to this seat, its own thread
1634
+ // or task, a DM.
1635
+ // A heartbeat isn't told to answer: nobody asked it anything this turn.
1636
+ const ROOM_QUESTION_WITH_PEERS = 'Another agent is in this pod, so a question put to the room isn\'t asked of you: '
1637
+ + 'if you can\'t help with it, end with NO_REPLY.';
1638
+ const ROOM_QUESTION_ALONE = 'You are the only agent in this pod, so a question put to the room is asked of you: '
1639
+ + 'answer it, even if the answer is that you can\'t help.';
1640
+ const itemIsNotToTheRoom = ({ event: { payload } }) => Boolean(
1641
+ payload?.welcomeWake || payload?.adjacentReply || payload?.dmKind
1642
+ || payload?.repliesToYourMessage === true || payload?.addressed === true,
1643
+ );
1644
+ const roomQuestionLine = (pod, entries) => {
1645
+ if (!pod || entries.some(itemIsNotToTheRoom)) return '';
1646
+ if (pod.otherAgentsInPod) return ` ${ROOM_QUESTION_WITH_PEERS}`;
1647
+ if (pod.peopleInPod === 1 && entries.some((entry) => entry.event.type !== 'heartbeat')) {
1648
+ return ` ${ROOM_QUESTION_ALONE}`;
1649
+ }
1650
+ return '';
1651
+ };
1652
+
1622
1653
  // The same line for a comment @ (F225), whose final text goes to the comment.
1623
1654
  // A person who @'d the seat is not offered silence, only the tool's exit.
1624
1655
  const FINAL_TEXT_ON_COMMENT = 'Your final text is posted as a reply to this comment unless it is exactly NO_REPLY. '
@@ -3171,7 +3202,7 @@ export const performRun = ({
3171
3202
  // pull, rather than being silently consumed here.
3172
3203
  // `unreadBodiesPodId` is set only for a turn a person's mention woke (ADR-018
3173
3204
  // D9.2): the unread messages this page carried go in as marked data.
3174
- const buildInboxPrompt = (entries, inboxCount = entries.length, { unreadBodiesPodId = null } = {}) => {
3205
+ const buildInboxPrompt = (entries, inboxCount = entries.length, { pod = null, unreadBodiesPodId = null } = {}) => {
3175
3206
  const BODY_LIMIT = batchLimit;
3176
3207
  const wakeEntries = entries.filter((entry) => entry.event.deliveryMode !== 'digest' && !entry.pastCap);
3177
3208
  const digestEntries = entries.filter((entry) => entry.event.deliveryMode === 'digest' && !entry.pastCap);
@@ -3241,7 +3272,8 @@ export const performRun = ({
3241
3272
  + 'For anything else here, post only an action or a materially useful response. '
3242
3273
  + FINAL_TEXT_ANSWERS_A_PERSON
3243
3274
  : 'Do not narrate the inbox. Post only an action or a materially useful response; otherwise return NO_REPLY. '
3244
- + FINAL_TEXT_IS_POSTED),
3275
+ + FINAL_TEXT_IS_POSTED
3276
+ + roomQuestionLine(pod, shownEntries)),
3245
3277
  ].join('\n\n');
3246
3278
  };
3247
3279
 
@@ -3625,13 +3657,18 @@ export const performRun = ({
3625
3657
  }
3626
3658
  }
3627
3659
 
3660
+ // Null until the server says: a failed read or an older server is unknown,
3661
+ // not "alone" and not "with peers".
3662
+ let podAttendance = null;
3628
3663
  const snapshotMessages = async () => {
3629
3664
  try {
3630
- const { messages = [] } = await client.get(
3665
+ const { messages = [], otherAgentsInPod, peopleInPod } = await client.get(
3631
3666
  `/api/agents/runtime/pods/${eventPodId}/messages`, { limit: 10 },
3632
3667
  );
3668
+ podAttendance = typeof otherAgentsInPod === 'boolean' ? { otherAgentsInPod, peopleInPod } : null;
3633
3669
  return messages;
3634
3670
  } catch {
3671
+ podAttendance = null;
3635
3672
  return null;
3636
3673
  }
3637
3674
  };
@@ -3811,7 +3848,7 @@ export const performRun = ({
3811
3848
  },
3812
3849
  },
3813
3850
  eventPodId,
3814
- prompt: buildInboxPrompt([entry], 1),
3851
+ prompt: buildInboxPrompt([entry], 1, { pod: podAttendance }),
3815
3852
  preSpawnIds: before ? new Set(before.map((message) => String(message._id || message.id))) : null,
3816
3853
  snapshotMessages,
3817
3854
  claimKeeper: entry.claimKeeper,
@@ -3819,9 +3856,9 @@ export const performRun = ({
3819
3856
  });
3820
3857
  };
3821
3858
 
3822
- const plainPrompt = buildInboxPrompt(entries, inboxCount);
3859
+ const plainPrompt = buildInboxPrompt(entries, inboxCount, { pod: podAttendance });
3823
3860
  const turnPrompt = personMentioned
3824
- ? buildInboxPrompt(entries, inboxCount, { unreadBodiesPodId: eventPodId })
3861
+ ? buildInboxPrompt(entries, inboxCount, { pod: podAttendance, unreadBodiesPodId: eventPodId })
3825
3862
  : plainPrompt;
3826
3863
 
3827
3864
  let turnResult;
@@ -123,7 +123,7 @@ const DEFAULT_TIMEOUT_MS = (() => {
123
123
  const buildPrompt = buildMemoryPreamble;
124
124
 
125
125
  // The working habits a private claude seat is taught on a fresh session
126
- // (TASK-545). Parallel reads live here because only this CLI has a subagent
126
+ // (TASK-545). Parallel reads live here because the cue names this CLI's Agent
127
127
  // tool; codex is passed row slicing and the background-process cue. A public
128
128
  // seat is passed none: its argv allows Read and the MCP under dontAsk, so it
129
129
  // has no subagent to spawn or shell to background from, and it answers
@@ -42,6 +42,8 @@ import { describeTurnReap, markTurn, turnReapEnabled } from '@commonlyai/seats/t
42
42
  */
43
43
 
44
44
  import { requireSeatModel, seatModelRequired } from './seat-model.js';
45
+ import { probeVersion } from './tested-version.js';
46
+ import { parseVersion } from '../mcp-server-version.js';
45
47
  import { spawn as childSpawn, spawnSync } from 'child_process';
46
48
  import { createHash } from 'crypto';
47
49
  import { accessSync, constants, existsSync, realpathSync } from 'fs';
@@ -609,6 +611,53 @@ const writePublicCodexInstructions = async (publicHome, ctx) => {
609
611
  });
610
612
  };
611
613
 
614
+ // A public Codex seat runs with Commonly's tools, the shell, file edits and
615
+ // view_image. Those three read and write through the permission profile, as
616
+ // measured on each version named below; these keys turn off Codex's other
617
+ // built-ins, which claude.js does with its deny list.
618
+ //
619
+ // - `web_search` is the top-level mode, and "disabled" also drops `web__run`
620
+ // from the `exec` tool of code-mode models.
621
+ // - `features.multi_agent` removes the agent tools from a model on the v1 agent
622
+ // tools, but a thread started without it keeps them when resumed, so
623
+ // `agents.max_depth=0` (below) covers that thread. A model whose catalog entry says
624
+ // `multi_agent_version: "v2"` keeps `collaboration.*` in its tool list whatever
625
+ // these say, so the v2 cap is what stops it: at 1 the root thread fills it, and
626
+ // spawn_agent returns "agent thread limit reached". `agents.max_threads` doesn't
627
+ // do this, and only `model_catalog_json` takes the names out, which replaces
628
+ // the whole catalog.
629
+ // - `features.goals` removes the goal tools. A goal is kept on the thread and
630
+ // comes back in the next turn's context.
631
+ //
632
+ // Measured on codex-cli 0.162.1, against the tool list sent to the model on
633
+ // gpt-5.5, gpt-5.6 and gpt-6 models (adapters.codex.public-tools.test.mjs).
634
+ // 0.133.0, 0.149.1 and 0.159.3 all start with this set, ignoring a key they don't
635
+ // know. Of these, only the `web_search` value could fail a start, as it's an
636
+ // enum, and "disabled" is valid on all four.
637
+ const PUBLIC_BUILTIN_TOOL_FLAGS = Object.freeze([
638
+ '-c', 'web_search="disabled"',
639
+ '-c', 'features.multi_agent=false',
640
+ '-c', 'features.multi_agent_v2.max_concurrent_threads_per_session=1',
641
+ '-c', 'features.goals=false',
642
+ ]);
643
+
644
+ // Unlike the set above, `agents.max_depth=0` can stop a start: codex-cli 0.133.0
645
+ // exits with "agents.max_depth must be at least 1", and 0.149.1 is the oldest
646
+ // version measured to take it. So it goes only to a Codex reporting at least that,
647
+ // and a version that can't be read leaves it out, since a seat that starts matters
648
+ // more than a thread from before these settings.
649
+ const ZERO_AGENT_DEPTH_FLAGS = Object.freeze(['-c', 'agents.max_depth=0']);
650
+ const ZERO_AGENT_DEPTH_MIN_VERSION = [0, 149, 1];
651
+
652
+ const acceptsZeroAgentDepth = (version) => {
653
+ const parsed = parseVersion(version);
654
+ if (!parsed) return false;
655
+ const index = parsed.findIndex((part, i) => part !== ZERO_AGENT_DEPTH_MIN_VERSION[i]);
656
+ return index === -1 || parsed[index] > ZERO_AGENT_DEPTH_MIN_VERSION[index];
657
+ };
658
+
659
+ const parseCodexVersion = (stdout) => String(stdout).match(/\d+\.\d+\.\d+/)?.[0] || null;
660
+
612
661
  const publicPermissionProfileFlags = (
613
662
  mode,
614
663
  commitAttributionEnv = null,
@@ -785,6 +834,7 @@ const buildArgs = ({
785
834
  modelBaseUrl = null,
786
835
  platform = process.platform,
787
836
  workspacePath = null,
837
+ zeroAgentDepth = false,
788
838
  }) => {
789
839
  const publicSandbox = publicSandboxMode !== null;
790
840
  // `--dangerously-bypass-approvals-and-sandbox` disables codex CLI's
@@ -812,6 +862,8 @@ const buildArgs = ({
812
862
  platform,
813
863
  workspacePath,
814
864
  ),
865
+ ...PUBLIC_BUILTIN_TOOL_FLAGS,
866
+ ...(zeroAgentDepth ? ZERO_AGENT_DEPTH_FLAGS : []),
815
867
  ]
816
868
  : ['--dangerously-bypass-approvals-and-sandbox'];
817
869
  const common = [
@@ -1003,9 +1055,10 @@ export default {
1003
1055
  // undefined and '' as absence itself; it does not need a guard, it needs
1004
1056
  // the value.
1005
1057
  //
1006
- // Codex has no subagent tool, so of the two habits (TASK-545) it is
1007
- // taught row slicing alone; claude.js adds parallel reads. A public seat
1008
- // answers strangers rather than working board rows, so it is taught neither.
1058
+ // Of the two habits (TASK-545) a private Codex seat is taught row slicing
1059
+ // alone. claude.js adds parallel reads, whose cue names Claude's Agent tool;
1060
+ // Codex has agent tools of its own, under other names. A public seat answers
1061
+ // strangers rather than working board rows, so it is taught neither.
1009
1062
  const fullPrompt = buildPrompt(prompt, ctx.memoryLongTerm, {
1010
1063
  freshSession: !ctx.sessionId,
1011
1064
  workCues: sandbox?.trust === 'public' ? [] : [ROW_SLICING_CUE, BACKGROUND_PROCESS_CUE],
@@ -1070,6 +1123,12 @@ export default {
1070
1123
  const publicCodexHome = publicSandboxMode !== null
1071
1124
  ? await preparePublicCodexHome(ctx, childEnv)
1072
1125
  : null;
1126
+ // 30 s, as in goose: a first launch after an upgrade can be slow, and an
1127
+ // unread version drops agents.max_depth=0 for this turn. A failed probe
1128
+ // isn't cached, so the next turn reads it again.
1129
+ const codexVersion = publicSandboxMode === null ? null
1130
+ : ctx._codexVersion !== undefined ? ctx._codexVersion // test seam only
1131
+ : await probeVersion('codex', { env: childEnv, timeoutMs: 30000, parse: parseCodexVersion }).catch(() => null);
1073
1132
  const args = buildArgs({
1074
1133
  sessionId: ctx.sessionId || null,
1075
1134
  prompt: fullPrompt,
@@ -1084,6 +1143,7 @@ export default {
1084
1143
  modelBaseUrl,
1085
1144
  platform: ctx._platform || process.platform,
1086
1145
  workspacePath,
1146
+ zeroAgentDepth: acceptsZeroAgentDepth(codexVersion),
1087
1147
  });
1088
1148
  // childEnv is derived from the process environment, so the bootstrap export has to be
1089
1149
  // taken back out: the declaration above moved our server onto the file,