@commonlyai/cli 0.1.273 → 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 +1 -1
- package/src/commands/agent.js +44 -7
- package/src/lib/adapters/claude.js +9 -1
- package/src/lib/adapters/codex.js +84 -30
- package/src/lib/adapters/dsh.js +2 -0
- package/src/lib/adapters/goose.js +17 -11
- package/src/lib/adapters/qwen.js +2 -0
- package/src/lib/sandbox/turn-dir.js +56 -0
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;
|
|
@@ -85,6 +85,7 @@ import {
|
|
|
85
85
|
normalizeSandboxTrust,
|
|
86
86
|
} from '../environment.js';
|
|
87
87
|
import { detectBwrap, wrapArgvWithBwrap } from '../sandbox/bwrap.js';
|
|
88
|
+
import { refuseWorkspaceHoldingTurnDirs } from '../sandbox/turn-dir.js';
|
|
88
89
|
import { holdWorkspaceRealpath, workspacePinDir } from '../sandbox/workspace-pin.js';
|
|
89
90
|
import { PUBLIC_SANDBOX_MODES, resolvePublicSandboxMode } from '../sandbox/mode.js';
|
|
90
91
|
import { UNSANDBOXED_FLAG } from '../sandbox/host-check.js';
|
|
@@ -122,7 +123,7 @@ const DEFAULT_TIMEOUT_MS = (() => {
|
|
|
122
123
|
const buildPrompt = buildMemoryPreamble;
|
|
123
124
|
|
|
124
125
|
// The working habits a private claude seat is taught on a fresh session
|
|
125
|
-
// (TASK-545). Parallel reads live here because
|
|
126
|
+
// (TASK-545). Parallel reads live here because the cue names this CLI's Agent
|
|
126
127
|
// tool; codex is passed row slicing and the background-process cue. A public
|
|
127
128
|
// seat is passed none: its argv allows Read and the MCP under dontAsk, so it
|
|
128
129
|
// has no subagent to spawn or shell to background from, and it answers
|
|
@@ -1657,6 +1658,13 @@ export default {
|
|
|
1657
1658
|
// undefined and '' as absence itself; it does not need a guard, it needs
|
|
1658
1659
|
// the value.
|
|
1659
1660
|
const publicTrust = isConfinedTrust(ctx.environment?.sandbox?.trust);
|
|
1661
|
+
// Only an MCP seat has a per-turn folder (createMcpConfig). Before skills
|
|
1662
|
+
// mount, because they write into the workspace.
|
|
1663
|
+
if (publicTrust && Array.isArray(ctx.environment?.mcp) && ctx.environment.mcp.length > 0) {
|
|
1664
|
+
await refuseWorkspaceHoldingTurnDirs({
|
|
1665
|
+
workspace: ctx.cwd, seat: `${ctx.environment.sandbox.trust} Claude agents`,
|
|
1666
|
+
});
|
|
1667
|
+
}
|
|
1660
1668
|
// Only a stranger-facing seat is witnessed (TASK-256). A workspace seat is
|
|
1661
1669
|
// confined too, but it answers its own team, and an outage it narrates
|
|
1662
1670
|
// there is a signal, not a leak.
|
|
@@ -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';
|
|
@@ -68,7 +70,6 @@ import {
|
|
|
68
70
|
isAbsolute,
|
|
69
71
|
join,
|
|
70
72
|
resolve as pathResolve,
|
|
71
|
-
sep,
|
|
72
73
|
} from 'path';
|
|
73
74
|
import { CREDENTIAL_FILE_VAR, CREDENTIAL_KEY, writeCredentialFile } from '../credential-file.js';
|
|
74
75
|
import { isOurGrantBroker } from '../grant-broker-guard.js';
|
|
@@ -79,6 +80,7 @@ import { prepareMcpSpawn, publicMcpUnavailableError, selectedMcpVersionDir } fro
|
|
|
79
80
|
import { BACKGROUND_PROCESS_CUE, buildMemoryPreamble, ROW_SLICING_CUE } from '../memory-bridge.js';
|
|
80
81
|
import { resolveSkillSource, skillsAsText } from '../skill-prompt.js';
|
|
81
82
|
import { isLegacySandboxTrust, normalizeSandboxTrust, refuseWorkspaceTrust } from '../environment.js';
|
|
83
|
+
import { contains, realpathOfNearest, refuseWorkspaceHoldingTurnDirs } from '../sandbox/turn-dir.js';
|
|
82
84
|
import { adapterFailure, spawnCredentials } from '../upstream-refusal.js';
|
|
83
85
|
import { PUBLIC_SEAT_WITHHELD_TOOLS } from '../public-withheld-tools.js';
|
|
84
86
|
import { resolveLaunch, resolveMcpCommand, resolveWindowsCommandWithReason } from '../windows-command.js';
|
|
@@ -401,8 +403,6 @@ const statOrNull = async (path) => {
|
|
|
401
403
|
// refused. macOS has no arg0 helper and keeps its homes where they were.
|
|
402
404
|
const LEGACY_CODEX_HOMES = (home) => join(home, '.commonly', 'codex-homes');
|
|
403
405
|
|
|
404
|
-
const contains = (outer, inner) => inner === outer || inner.startsWith(outer.endsWith(sep) ? outer : outer + sep);
|
|
405
|
-
|
|
406
406
|
const stateHomeUnderCommonly = (ctx, home) => new Error(
|
|
407
407
|
`XDG_STATE_HOME (${ctx.env?.XDG_STATE_HOME}) puts the public Codex home under ${join(home, '.commonly')}, `
|
|
408
408
|
+ 'which the public sandbox denies on Linux. Point it elsewhere or unset it.',
|
|
@@ -421,26 +421,6 @@ const publicCodexHomesRoot = (ctx) => {
|
|
|
421
421
|
return root;
|
|
422
422
|
};
|
|
423
423
|
|
|
424
|
-
// The real path of a path that may not exist yet: its nearest existing
|
|
425
|
-
// ancestor resolved, with the rest appended.
|
|
426
|
-
const realpathOfNearest = async (path) => {
|
|
427
|
-
const rest = [];
|
|
428
|
-
let current = pathResolve(path);
|
|
429
|
-
for (;;) {
|
|
430
|
-
try {
|
|
431
|
-
return join(await realpath(current), ...rest);
|
|
432
|
-
} catch (err) {
|
|
433
|
-
// Only a missing path walks up. Anything else (EACCES, ELOOP) would leave
|
|
434
|
-
// the containment check comparing a path nobody resolved: fail closed.
|
|
435
|
-
if (err?.code !== 'ENOENT' && err?.code !== 'ENOTDIR') throw err;
|
|
436
|
-
const parent = dirname(current);
|
|
437
|
-
if (parent === current) return join(current, ...rest);
|
|
438
|
-
rest.unshift(basename(current));
|
|
439
|
-
current = parent;
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
};
|
|
443
|
-
|
|
444
424
|
const operatorCodexHome = (ctx) => ctx.env?.CODEX_HOME
|
|
445
425
|
|| process.env.CODEX_HOME
|
|
446
426
|
|| join(homedir(), '.codex');
|
|
@@ -631,12 +611,60 @@ const writePublicCodexInstructions = async (publicHome, ctx) => {
|
|
|
631
611
|
});
|
|
632
612
|
};
|
|
633
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
|
+
|
|
634
661
|
const publicPermissionProfileFlags = (
|
|
635
662
|
mode,
|
|
636
663
|
commitAttributionEnv = null,
|
|
637
664
|
mcpReadDirectories = [],
|
|
638
665
|
codexHelperReadPaths = [],
|
|
639
666
|
platform = process.platform,
|
|
667
|
+
workspacePath = null,
|
|
640
668
|
) => {
|
|
641
669
|
if (!PUBLIC_SANDBOX_MODES.has(mode)) {
|
|
642
670
|
throw new Error(
|
|
@@ -666,6 +694,16 @@ const publicPermissionProfileFlags = (
|
|
|
666
694
|
const gitConfigKeySet = Object.entries(commitAttributionEnv || {})
|
|
667
695
|
.filter(([name]) => /^GIT_CONFIG_KEY_\d+$/.test(name))
|
|
668
696
|
.map(([name, value]) => `${toml(name)}=${toml(value)}`);
|
|
697
|
+
// The profile denies $TMPDIR and /tmp, so a shell heredoc fails. Set for the
|
|
698
|
+
// model's shell alone: codex, its MCP child and the per-turn folder keep the
|
|
699
|
+
// host's temp root, which spawn refuses to find in the workspace. The
|
|
700
|
+
// workspace is the one folder this shell already writes. zsh, the macOS
|
|
701
|
+
// login shell codex runs, takes its heredoc file from TMPPREFIX and ignores
|
|
702
|
+
// TMPDIR. A read-only seat has no such folder, so its heredocs keep failing.
|
|
703
|
+
const shellTmpDir = workspaceAccess === 'write' && workspacePath
|
|
704
|
+
? [`${toml('TMPDIR')}=${toml(workspacePath)}`, `${toml('TMPPREFIX')}=${toml(join(workspacePath, 'zsh'))}`]
|
|
705
|
+
: [];
|
|
706
|
+
const shellSet = [...gitConfigKeySet, ...shellTmpDir];
|
|
669
707
|
const filesystem = [
|
|
670
708
|
'":minimal"="read"',
|
|
671
709
|
'"~/.commonly"="deny"',
|
|
@@ -686,7 +724,7 @@ const publicPermissionProfileFlags = (
|
|
|
686
724
|
...codexHelperReadPaths.map((path) => `${toml(path)}="read"`),
|
|
687
725
|
].join(',');
|
|
688
726
|
const shellEnvironment = [
|
|
689
|
-
'PATH', 'HOME', 'TMPDIR', 'LANG', 'LC_*',
|
|
727
|
+
'PATH', 'HOME', 'TMPDIR', 'TMPPREFIX', 'LANG', 'LC_*',
|
|
690
728
|
...(commitHooksPath ? [
|
|
691
729
|
...gitConfigEnv,
|
|
692
730
|
'COMMONLY_AGENT_GIT_CONFIG_INDEX',
|
|
@@ -715,9 +753,7 @@ const publicPermissionProfileFlags = (
|
|
|
715
753
|
// Codex's default name filter treats GIT_CONFIG_KEY_n as sensitive. Set
|
|
716
754
|
// only those key names after filtering; their corresponding values stay
|
|
717
755
|
// in the allowlisted environment instead of riding argv.
|
|
718
|
-
...(
|
|
719
|
-
? ['-c', `shell_environment_policy.set={${gitConfigKeySet.join(',')}}`]
|
|
720
|
-
: []),
|
|
756
|
+
...(shellSet.length ? ['-c', `shell_environment_policy.set={${shellSet.join(',')}}`] : []),
|
|
721
757
|
];
|
|
722
758
|
};
|
|
723
759
|
|
|
@@ -797,6 +833,8 @@ const buildArgs = ({
|
|
|
797
833
|
codexHelperReadPaths = [],
|
|
798
834
|
modelBaseUrl = null,
|
|
799
835
|
platform = process.platform,
|
|
836
|
+
workspacePath = null,
|
|
837
|
+
zeroAgentDepth = false,
|
|
800
838
|
}) => {
|
|
801
839
|
const publicSandbox = publicSandboxMode !== null;
|
|
802
840
|
// `--dangerously-bypass-approvals-and-sandbox` disables codex CLI's
|
|
@@ -822,7 +860,10 @@ const buildArgs = ({
|
|
|
822
860
|
mcpReadDirectories,
|
|
823
861
|
codexHelperReadPaths,
|
|
824
862
|
platform,
|
|
863
|
+
workspacePath,
|
|
825
864
|
),
|
|
865
|
+
...PUBLIC_BUILTIN_TOOL_FLAGS,
|
|
866
|
+
...(zeroAgentDepth ? ZERO_AGENT_DEPTH_FLAGS : []),
|
|
826
867
|
]
|
|
827
868
|
: ['--dangerously-bypass-approvals-and-sandbox'];
|
|
828
869
|
const common = [
|
|
@@ -1014,9 +1055,10 @@ export default {
|
|
|
1014
1055
|
// undefined and '' as absence itself; it does not need a guard, it needs
|
|
1015
1056
|
// the value.
|
|
1016
1057
|
//
|
|
1017
|
-
//
|
|
1018
|
-
//
|
|
1019
|
-
//
|
|
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.
|
|
1020
1062
|
const fullPrompt = buildPrompt(prompt, ctx.memoryLongTerm, {
|
|
1021
1063
|
freshSession: !ctx.sessionId,
|
|
1022
1064
|
workCues: sandbox?.trust === 'public' ? [] : [ROW_SLICING_CUE, BACKGROUND_PROCESS_CUE],
|
|
@@ -1024,6 +1066,10 @@ export default {
|
|
|
1024
1066
|
memoryReadOnly: sandbox?.trust === 'public',
|
|
1025
1067
|
});
|
|
1026
1068
|
|
|
1069
|
+
const workspacePath = sandbox?.trust === 'public'
|
|
1070
|
+
? await refuseWorkspaceHoldingTurnDirs({ workspace: ctx.cwd, seat: 'public Codex agents' })
|
|
1071
|
+
: null;
|
|
1072
|
+
|
|
1027
1073
|
// Per-spawn temp dir for --output-last-message. Cleaned up in `finally`
|
|
1028
1074
|
// so a crash in the middle of the spawn doesn't leak files in $TMPDIR.
|
|
1029
1075
|
const dir = await mkdtemp(join(tmpdir(), 'commonly-codex-'));
|
|
@@ -1077,6 +1123,12 @@ export default {
|
|
|
1077
1123
|
const publicCodexHome = publicSandboxMode !== null
|
|
1078
1124
|
? await preparePublicCodexHome(ctx, childEnv)
|
|
1079
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);
|
|
1080
1132
|
const args = buildArgs({
|
|
1081
1133
|
sessionId: ctx.sessionId || null,
|
|
1082
1134
|
prompt: fullPrompt,
|
|
@@ -1090,6 +1142,8 @@ export default {
|
|
|
1090
1142
|
codexHelperReadPaths: publicCodexHome?.helperReadPaths || [],
|
|
1091
1143
|
modelBaseUrl,
|
|
1092
1144
|
platform: ctx._platform || process.platform,
|
|
1145
|
+
workspacePath,
|
|
1146
|
+
zeroAgentDepth: acceptsZeroAgentDepth(codexVersion),
|
|
1093
1147
|
});
|
|
1094
1148
|
// childEnv is derived from the process environment, so the bootstrap export has to be
|
|
1095
1149
|
// taken back out: the declaration above moved our server onto the file,
|
package/src/lib/adapters/dsh.js
CHANGED
|
@@ -23,6 +23,7 @@ import { startEgressProxy } from '../egress-proxy.js';
|
|
|
23
23
|
import { startInstanceProxy } from '../instance-proxy.js';
|
|
24
24
|
import { prepareMcpSpawn, selectedMcpVersionDir } from '../mcp-home.js';
|
|
25
25
|
import { detectSeatbelt, wrapArgvWithSeatbelt } from '../sandbox/seatbelt.js';
|
|
26
|
+
import { refuseWorkspaceHoldingTurnDirs } from '../sandbox/turn-dir.js';
|
|
26
27
|
import { buildMemoryPreamble } from '../memory-bridge.js';
|
|
27
28
|
import { commonlyMcpServer } from '../default-environment.js';
|
|
28
29
|
import { effectiveSandboxTrust, refuseWorkspaceTrust, validateEnvironmentSpec } from '../environment.js';
|
|
@@ -370,6 +371,7 @@ export default {
|
|
|
370
371
|
}
|
|
371
372
|
const seatbelt = (ctx._detectSeatbelt || detectSeatbelt)();
|
|
372
373
|
if (!seatbelt.available) throw new Error(`dsh adapter: a confined seat needs Seatbelt: ${seatbelt.error}`);
|
|
374
|
+
await refuseWorkspaceHoldingTurnDirs({ workspace: ctx.cwd, seat: 'confined dsh agents' });
|
|
373
375
|
}
|
|
374
376
|
if (!ctx.environment?.provider || !ctx.environment?.model) {
|
|
375
377
|
throw new Error('dsh requires environment.provider and environment.model');
|
|
@@ -16,6 +16,7 @@ import { resolveProviderKeyFile, startProviderProxy } from '../provider-proxy.js
|
|
|
16
16
|
import { resolvePublicSandboxMode } from '../sandbox/mode.js';
|
|
17
17
|
import { detectBwrap, wrapArgvWithBwrap } from '../sandbox/bwrap.js';
|
|
18
18
|
import { wrapArgvWithSeatbelt } from '../sandbox/seatbelt.js';
|
|
19
|
+
import { refuseWorkspaceHoldingTurnDirs } from '../sandbox/turn-dir.js';
|
|
19
20
|
import { adapterFailure, spawnCredentials } from '../upstream-refusal.js';
|
|
20
21
|
|
|
21
22
|
// A version enters this list only after a real headless turn with that binary.
|
|
@@ -291,26 +292,31 @@ export default {
|
|
|
291
292
|
// eslint-disable-next-line no-console
|
|
292
293
|
console.warn(`[goose] installed ${version || 'unknown'} differs from smoke-tested ${TESTED_GOOSE_VERSIONS.join(', ')}; private seat continues`);
|
|
293
294
|
}
|
|
294
|
-
|
|
295
|
+
if (isPublic) await refuseWorkspaceHoldingTurnDirs({ workspace: ctx.cwd, seat: 'public Goose agents' });
|
|
296
|
+
// Keep child-writable state separate from adapter-owned config and keys, as
|
|
297
|
+
// qwen does (F219). The jail reads tempDir and cannot change it: the
|
|
298
|
+
// Commonly MCP child runs in the jail, so the credential stays readable.
|
|
299
|
+
const tempDir = await mkdtemp(join(tmpdir(), 'commonly-goose-'));
|
|
300
|
+
const home = await mkdtemp(join(tmpdir(), 'commonly-goose-home-'));
|
|
295
301
|
let proxy;
|
|
296
302
|
try {
|
|
297
303
|
const credential = writeCredentialFile(ctx.runtimeToken, {
|
|
298
|
-
root:
|
|
304
|
+
root: tempDir, agentName: ctx.agentName || 'agent',
|
|
299
305
|
});
|
|
306
|
+
// No tokenFile: nothing here reads one, so the token is never on disk.
|
|
300
307
|
if (isPublic) proxy = await startProviderProxy({
|
|
301
|
-
provider: configured, keyFile,
|
|
302
|
-
pinnedModel: model,
|
|
308
|
+
provider: configured, keyFile, adapterLabel: 'Goose', pinnedModel: model,
|
|
303
309
|
});
|
|
304
310
|
const mcpReadDirectories = [];
|
|
305
311
|
const publicExtensions = [];
|
|
306
312
|
// Node's compiled-in OpenSSL config can sit outside the permitted tree
|
|
307
313
|
// (including hostedtoolcache on CI). Use our empty config, retaining
|
|
308
314
|
// Node's bundled TLS roots, instead of granting host configuration reads.
|
|
309
|
-
const opensslConfig = join(
|
|
315
|
+
const opensslConfig = join(tempDir, 'openssl.cnf');
|
|
310
316
|
if (isPublic) await writeFile(opensslConfig, '', { mode: 0o600 });
|
|
311
317
|
// The recipe's own directory is the template include root, so it holds
|
|
312
|
-
// the recipe alone, never the
|
|
313
|
-
const recipeDir = join(
|
|
318
|
+
// the recipe alone, never the credential file.
|
|
319
|
+
const recipeDir = join(tempDir, 'recipe');
|
|
314
320
|
const recipePath = join(recipeDir, 'public-recipe.json');
|
|
315
321
|
const args = [
|
|
316
322
|
'run', '--no-session', ...(!isPublic ? ['--no-profile', '--with-builtin', 'developer'] : []),
|
|
@@ -347,7 +353,7 @@ export default {
|
|
|
347
353
|
...(isPublic ? { OPENSSL_CONF: opensslConfig } : {}),
|
|
348
354
|
OPENAI_HOST: proxy ? new URL(proxy.baseURL).origin : baseUrl.origin,
|
|
349
355
|
OPENAI_BASE_PATH: `${new URL(proxy?.baseURL || baseUrl).pathname.replace(/\/$/, '')}/chat/completions`.replace(/^\//, ''),
|
|
350
|
-
OPENAI_API_KEY: proxy ?
|
|
356
|
+
OPENAI_API_KEY: proxy ? proxy.token : key,
|
|
351
357
|
};
|
|
352
358
|
withholdRuntimeCredential(env, { credentialFile: credential?.path || null });
|
|
353
359
|
const requestedTimeout = Number(ctx.timeoutMs);
|
|
@@ -366,12 +372,12 @@ export default {
|
|
|
366
372
|
...(sandbox.filesystem || {}), 'write-outside': [home],
|
|
367
373
|
} },
|
|
368
374
|
}, { workspacePath: ctx.cwd, homePath: home,
|
|
369
|
-
readOnlyPaths: [binary, process.execPath, ...mcpReadDirectories] });
|
|
375
|
+
readOnlyPaths: [tempDir, binary, process.execPath, ...mcpReadDirectories] });
|
|
370
376
|
} else {
|
|
371
377
|
if ((ctx._platform || process.platform) !== 'darwin') throw new Error('goose adapter: Seatbelt requires macOS');
|
|
372
378
|
[executable, ...spawnArgs] = (ctx._wrapArgvWithSeatbelt || wrapArgvWithSeatbelt)([binary, ...args], {
|
|
373
379
|
workspacePath: ctx.cwd, workspaceAccess: mode === 'read-only' ? 'read' : 'write',
|
|
374
|
-
executablePath: binary, statePath: home, mcpConfigDir:
|
|
380
|
+
executablePath: binary, statePath: home, mcpConfigDir: tempDir,
|
|
375
381
|
// Public seat: the CLI made this workspace, so it is pinned (F197).
|
|
376
382
|
pinWorkspace: true,
|
|
377
383
|
loopbackNetworkPorts: [proxy.port], readOnlyDirectories: mcpReadDirectories,
|
|
@@ -386,7 +392,7 @@ export default {
|
|
|
386
392
|
return { text, newSessionId: null };
|
|
387
393
|
} finally {
|
|
388
394
|
try { await proxy?.close(); } finally {
|
|
389
|
-
await rm(
|
|
395
|
+
await Promise.all([tempDir, home].map((path) => rm(path, { recursive: true, force: true })));
|
|
390
396
|
}
|
|
391
397
|
}
|
|
392
398
|
},
|
package/src/lib/adapters/qwen.js
CHANGED
|
@@ -15,6 +15,7 @@ import { normalizeSandboxTrust, refuseWorkspaceTrust, validateEnvironmentSpec }
|
|
|
15
15
|
import { resolvePublicSandboxMode } from '../sandbox/mode.js';
|
|
16
16
|
import { detectBwrap, wrapArgvWithBwrap } from '../sandbox/bwrap.js';
|
|
17
17
|
import { wrapArgvWithSeatbelt } from '../sandbox/seatbelt.js';
|
|
18
|
+
import { refuseWorkspaceHoldingTurnDirs } from '../sandbox/turn-dir.js';
|
|
18
19
|
import { resolveProviderKeyFile, startProviderProxy } from '../provider-proxy.js';
|
|
19
20
|
import { adapterFailure, spawnCredentials } from '../upstream-refusal.js';
|
|
20
21
|
import { PUBLIC_SEAT_WITHHELD_TOOLS } from '../public-withheld-tools.js';
|
|
@@ -281,6 +282,7 @@ export default {
|
|
|
281
282
|
const executable = symlinkedBinary
|
|
282
283
|
? join(realpathSync(dirname(binary)), basename(binary)) : binary;
|
|
283
284
|
const packageDir = symlinkedBinary ? dirname(realpathSync(executable)) : null;
|
|
285
|
+
if (isPublic) await refuseWorkspaceHoldingTurnDirs({ workspace: ctx.cwd, seat: 'public Qwen agents' });
|
|
284
286
|
const tempDir = await mkdtemp(join(tmpdir(), 'commonly-qwen-'));
|
|
285
287
|
await chmod(tempDir, 0o700);
|
|
286
288
|
// Keep child-writable state separate from adapter-owned config and keys.
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The folder an adapter keeps one turn's credential in sits under the temp
|
|
3
|
+
* root. The sandbox denies that root by leaving it out of every grant, so a
|
|
4
|
+
* workspace that holds it undoes the denial: the workspace grant covers it,
|
|
5
|
+
* and code in the jail can read the credential and replace the turn's files
|
|
6
|
+
* (F219; measured on a real `codex sandbox`, where a workspace of $TMPDIR read
|
|
7
|
+
* the credential and a project folder could not).
|
|
8
|
+
*
|
|
9
|
+
* Checked before the folder exists, against the root, so a refused turn writes
|
|
10
|
+
* nothing. OpenCode has its own check, which also walks links and git worktrees.
|
|
11
|
+
*/
|
|
12
|
+
import { realpath } from 'fs/promises';
|
|
13
|
+
import { tmpdir } from 'os';
|
|
14
|
+
import {
|
|
15
|
+
basename, dirname, join, resolve, sep,
|
|
16
|
+
} from 'path';
|
|
17
|
+
|
|
18
|
+
export const contains = (outer, inner) => inner === outer
|
|
19
|
+
|| inner.startsWith(outer.endsWith(sep) ? outer : outer + sep);
|
|
20
|
+
|
|
21
|
+
// The real path of a path that may not exist yet: its nearest existing
|
|
22
|
+
// ancestor resolved, with the rest appended. realpath(3) also returns the
|
|
23
|
+
// disk's own spelling, which matters on a volume that folds case.
|
|
24
|
+
export const realpathOfNearest = async (path) => {
|
|
25
|
+
const rest = [];
|
|
26
|
+
let current = resolve(path);
|
|
27
|
+
for (;;) {
|
|
28
|
+
try {
|
|
29
|
+
return join(await realpath(current), ...rest);
|
|
30
|
+
} catch (err) {
|
|
31
|
+
// Only a missing path walks up. Anything else (EACCES, ELOOP) would leave
|
|
32
|
+
// the containment check comparing a path nobody resolved: fail closed.
|
|
33
|
+
if (err?.code !== 'ENOENT' && err?.code !== 'ENOTDIR') throw err;
|
|
34
|
+
const parent = dirname(current);
|
|
35
|
+
if (parent === current) return join(current, ...rest);
|
|
36
|
+
rest.unshift(basename(current));
|
|
37
|
+
current = parent;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/** Throws when `workspace` holds the temp root; returns its real path otherwise. */
|
|
43
|
+
export const refuseWorkspaceHoldingTurnDirs = async ({
|
|
44
|
+
workspace, seat, tempRoot = tmpdir(),
|
|
45
|
+
}) => {
|
|
46
|
+
const [realWorkspace, realRoot] = await Promise.all([
|
|
47
|
+
realpathOfNearest(workspace || process.cwd()),
|
|
48
|
+
realpathOfNearest(tempRoot),
|
|
49
|
+
]);
|
|
50
|
+
if (contains(realWorkspace, realRoot)) {
|
|
51
|
+
throw new Error(`${seat} cannot run in ${workspace || process.cwd()}: it contains the temp folder (${tempRoot}) `
|
|
52
|
+
+ 'where each turn keeps the agent\'s credential, which the sandbox would then expose. '
|
|
53
|
+
+ 'Run it in a project folder, or set TMPDIR outside it.');
|
|
54
|
+
}
|
|
55
|
+
return realWorkspace;
|
|
56
|
+
};
|