@commonlyai/cli 0.1.274 → 0.1.276
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 +1 -1
- package/src/commands/agent.js +44 -7
- package/src/lib/adapters/claude.js +1 -1
- package/src/lib/adapters/codex.js +102 -20
package/package.json
CHANGED
package/src/commands/agent.js
CHANGED
|
@@ -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
|
|
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 = [
|
|
@@ -849,33 +901,47 @@ const makeEventParser = () => {
|
|
|
849
901
|
let buffer = '';
|
|
850
902
|
let threadId = null;
|
|
851
903
|
let turnFailedMessage = null;
|
|
904
|
+
let turnCompleted = false;
|
|
905
|
+
|
|
906
|
+
const consumeLine = (raw) => {
|
|
907
|
+
const line = raw.trim();
|
|
908
|
+
if (!line) return;
|
|
909
|
+
try {
|
|
910
|
+
const evt = JSON.parse(line);
|
|
911
|
+
if (evt.type === 'thread.started' && evt.thread_id && !threadId) {
|
|
912
|
+
threadId = evt.thread_id;
|
|
913
|
+
} else if (evt.type === 'turn.completed') {
|
|
914
|
+
turnCompleted = true;
|
|
915
|
+
} else if (evt.type === 'turn.failed') {
|
|
916
|
+
// Capture the most recent — codex may emit multiple before exit.
|
|
917
|
+
turnFailedMessage = evt.error?.message || 'codex turn failed';
|
|
918
|
+
}
|
|
919
|
+
} catch {
|
|
920
|
+
// Non-JSON lines on stdout are unexpected but not fatal — skip.
|
|
921
|
+
}
|
|
922
|
+
};
|
|
852
923
|
|
|
853
924
|
const consume = (chunk) => {
|
|
854
925
|
buffer += chunk.toString();
|
|
855
926
|
let nl;
|
|
856
927
|
// eslint-disable-next-line no-cond-assign
|
|
857
928
|
while ((nl = buffer.indexOf('\n')) !== -1) {
|
|
858
|
-
|
|
929
|
+
consumeLine(buffer.slice(0, nl));
|
|
859
930
|
buffer = buffer.slice(nl + 1);
|
|
860
|
-
if (!line) continue;
|
|
861
|
-
try {
|
|
862
|
-
const evt = JSON.parse(line);
|
|
863
|
-
if (evt.type === 'thread.started' && evt.thread_id && !threadId) {
|
|
864
|
-
threadId = evt.thread_id;
|
|
865
|
-
} else if (evt.type === 'turn.failed') {
|
|
866
|
-
// Capture the most recent — codex may emit multiple before exit.
|
|
867
|
-
turnFailedMessage = evt.error?.message || 'codex turn failed';
|
|
868
|
-
}
|
|
869
|
-
} catch {
|
|
870
|
-
// Non-JSON lines on stdout are unexpected but not fatal — skip.
|
|
871
|
-
}
|
|
872
931
|
}
|
|
873
932
|
};
|
|
874
933
|
|
|
934
|
+
const flush = () => {
|
|
935
|
+
consumeLine(buffer);
|
|
936
|
+
buffer = '';
|
|
937
|
+
};
|
|
938
|
+
|
|
875
939
|
return {
|
|
876
940
|
consume,
|
|
941
|
+
flush,
|
|
877
942
|
get threadId() { return threadId; },
|
|
878
943
|
get turnFailedMessage() { return turnFailedMessage; },
|
|
944
|
+
get turnCompleted() { return turnCompleted; },
|
|
879
945
|
};
|
|
880
946
|
};
|
|
881
947
|
|
|
@@ -934,6 +1000,7 @@ const runCodex = ({
|
|
|
934
1000
|
// eslint-disable-next-line no-console
|
|
935
1001
|
if (reaped) console.warn(`[codex] ${reaped}`);
|
|
936
1002
|
if (timedOut) return reject(new Error(`codex timed out after ${timeoutMs}ms`));
|
|
1003
|
+
events.flush();
|
|
937
1004
|
if (events.turnFailedMessage) {
|
|
938
1005
|
// Surface the model-side failure message verbatim — the run loop posts
|
|
939
1006
|
// it as the agent's reply so the user sees what went wrong rather than
|
|
@@ -950,7 +1017,7 @@ const runCodex = ({
|
|
|
950
1017
|
if (code !== 0) {
|
|
951
1018
|
return reject(adapterFailure('codex', stderr.trim(), { credentials, exitCode: code, limit: 500 }));
|
|
952
1019
|
}
|
|
953
|
-
resolve({ threadId: events.threadId });
|
|
1020
|
+
resolve({ threadId: events.threadId, turnCompleted: events.turnCompleted });
|
|
954
1021
|
});
|
|
955
1022
|
});
|
|
956
1023
|
|
|
@@ -1003,9 +1070,10 @@ export default {
|
|
|
1003
1070
|
// undefined and '' as absence itself; it does not need a guard, it needs
|
|
1004
1071
|
// the value.
|
|
1005
1072
|
//
|
|
1006
|
-
//
|
|
1007
|
-
//
|
|
1008
|
-
//
|
|
1073
|
+
// Of the two habits (TASK-545) a private Codex seat is taught row slicing
|
|
1074
|
+
// alone. claude.js adds parallel reads, whose cue names Claude's Agent tool;
|
|
1075
|
+
// Codex has agent tools of its own, under other names. A public seat answers
|
|
1076
|
+
// strangers rather than working board rows, so it is taught neither.
|
|
1009
1077
|
const fullPrompt = buildPrompt(prompt, ctx.memoryLongTerm, {
|
|
1010
1078
|
freshSession: !ctx.sessionId,
|
|
1011
1079
|
workCues: sandbox?.trust === 'public' ? [] : [ROW_SLICING_CUE, BACKGROUND_PROCESS_CUE],
|
|
@@ -1070,6 +1138,12 @@ export default {
|
|
|
1070
1138
|
const publicCodexHome = publicSandboxMode !== null
|
|
1071
1139
|
? await preparePublicCodexHome(ctx, childEnv)
|
|
1072
1140
|
: null;
|
|
1141
|
+
// 30 s, as in goose: a first launch after an upgrade can be slow, and an
|
|
1142
|
+
// unread version drops agents.max_depth=0 for this turn. A failed probe
|
|
1143
|
+
// isn't cached, so the next turn reads it again.
|
|
1144
|
+
const codexVersion = publicSandboxMode === null ? null
|
|
1145
|
+
: ctx._codexVersion !== undefined ? ctx._codexVersion // test seam only
|
|
1146
|
+
: await probeVersion('codex', { env: childEnv, timeoutMs: 30000, parse: parseCodexVersion }).catch(() => null);
|
|
1073
1147
|
const args = buildArgs({
|
|
1074
1148
|
sessionId: ctx.sessionId || null,
|
|
1075
1149
|
prompt: fullPrompt,
|
|
@@ -1084,6 +1158,7 @@ export default {
|
|
|
1084
1158
|
modelBaseUrl,
|
|
1085
1159
|
platform: ctx._platform || process.platform,
|
|
1086
1160
|
workspacePath,
|
|
1161
|
+
zeroAgentDepth: acceptsZeroAgentDepth(codexVersion),
|
|
1087
1162
|
});
|
|
1088
1163
|
// childEnv is derived from the process environment, so the bootstrap export has to be
|
|
1089
1164
|
// taken back out: the declaration above moved our server onto the file,
|
|
@@ -1109,7 +1184,7 @@ export default {
|
|
|
1109
1184
|
if (ctx.signal?.aborted) {
|
|
1110
1185
|
throw ctx.signal.reason || new Error('codex spawn cancelled before the process started');
|
|
1111
1186
|
}
|
|
1112
|
-
const { threadId } = await runCodex({
|
|
1187
|
+
const { threadId, turnCompleted } = await runCodex({
|
|
1113
1188
|
args,
|
|
1114
1189
|
cwd: ctx.cwd,
|
|
1115
1190
|
env: childEnv,
|
|
@@ -1134,11 +1209,18 @@ export default {
|
|
|
1134
1209
|
try {
|
|
1135
1210
|
text = (await readFile(outputFile, 'utf8')).trim();
|
|
1136
1211
|
} catch {
|
|
1137
|
-
//
|
|
1138
|
-
//
|
|
1212
|
+
// No file: a finished turn with no final message.
|
|
1213
|
+
// The run loop treats empty text as a silent turn and acknowledges it.
|
|
1139
1214
|
text = '';
|
|
1140
1215
|
}
|
|
1141
1216
|
|
|
1217
|
+
// A signal doesn't reach the exit code when codex runs through the npm
|
|
1218
|
+
// launcher: it re-raises SIGTERM or SIGHUP into its own handler and exits
|
|
1219
|
+
// 0. Resolving would read as a turn with nothing to say, and the messages
|
|
1220
|
+
// it held would never be answered. A final message counts as finished,
|
|
1221
|
+
// so a version that doesn't print turn.completed still posts its reply.
|
|
1222
|
+
if (!turnCompleted && !text) throw adapterFailure('codex', 'the turn stopped before it finished');
|
|
1223
|
+
|
|
1142
1224
|
// newSessionId precedence: thread_id from this turn (always emitted on
|
|
1143
1225
|
// a new session, often re-emitted on resume) > the persisted id we
|
|
1144
1226
|
// came in with > null. The wrapper persists whichever non-null value
|