@bakers-build/addon-codex 0.7.1-next.6 → 0.7.1-next.7
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/dist/src/index.d.ts +12 -2
- package/dist/src/index.js +76 -6
- package/package.json +4 -4
package/dist/src/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { type AgentFootprint, type AgentPlugin, type AgentRunIdentity, type BbAgent, type ResolvedSecurity, type RunEnvPolicy, type SandboxHost, type SandboxPreflight, type SecurityOptions } from '@bakers-build/conductor/contract';
|
|
1
|
+
import { type AgentFootprint, type AgentPlugin, type AgentRunIdentity, type BbAgent, type MarketplaceDeclaration, type PluginLaunch, type ResolvedSecurity, type RunEnvPolicy, type SandboxHost, type SandboxPreflight, type SecurityOptions } from '@bakers-build/conductor/contract';
|
|
2
2
|
export { parseCodexTranscript } from './footprint.js';
|
|
3
3
|
export interface CodexAgentOptions extends SecurityOptions {
|
|
4
4
|
model?: string;
|
|
5
5
|
effort?: string;
|
|
6
6
|
args?: string[];
|
|
7
|
+
/** False runs this agent in the user's own Codex home, without the project's plugins. */
|
|
8
|
+
plugins?: boolean;
|
|
7
9
|
}
|
|
8
10
|
/**
|
|
9
11
|
* The server ids a Codex `config.toml` declares under `mcp_servers`, in table,
|
|
@@ -24,7 +26,15 @@ export declare class CodexAgent implements BbAgent {
|
|
|
24
26
|
readonly security: ResolvedSecurity;
|
|
25
27
|
private readonly allowWrite;
|
|
26
28
|
readonly runEnvPolicy: RunEnvPolicy;
|
|
29
|
+
readonly pluginsDisabled: boolean;
|
|
30
|
+
/** The Codex home runs read and write: the agent home while plugins are on. */
|
|
31
|
+
configDir: string;
|
|
32
|
+
private pluginsOn;
|
|
27
33
|
constructor(options?: CodexAgentOptions, home?: string);
|
|
34
|
+
private userCodexHome;
|
|
35
|
+
/** Point this agent at the agent home of the project's declared marketplaces. */
|
|
36
|
+
useMarketplaces(marketplaces: readonly MarketplaceDeclaration[]): void;
|
|
37
|
+
installPlugins(marketplaces: readonly MarketplaceDeclaration[], home: string): Promise<PluginLaunch>;
|
|
28
38
|
/** A `config.toml` server the conductor's own replaces, named once per dispatch. */
|
|
29
39
|
get launchWarnings(): readonly string[];
|
|
30
40
|
/** The launch flags a security mode owns (`docs/addons/codex.md`). */
|
|
@@ -32,7 +42,7 @@ export declare class CodexAgent implements BbAgent {
|
|
|
32
42
|
private userMcpServers;
|
|
33
43
|
launchCommand(prompt: string, _run?: AgentRunIdentity, workspacePath?: string, tools?: {
|
|
34
44
|
url: string;
|
|
35
|
-
}, env?: Readonly<Record<string, string
|
|
45
|
+
}, env?: Readonly<Record<string, string>>, pluginArgs?: readonly string[]): string;
|
|
36
46
|
getRunLog(worktreePath: string, run?: AgentRunIdentity): Promise<string>;
|
|
37
47
|
parseFootprint(log: string): AgentFootprint;
|
|
38
48
|
/** Codex brings its own sandbox runner; a missing binary fails at launch as before. */
|
package/dist/src/index.js
CHANGED
|
@@ -1,11 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { existsSync, readFileSync, symlinkSync } from 'node:fs';
|
|
2
3
|
import { readdir, readFile, stat } from 'node:fs/promises';
|
|
3
4
|
import { homedir } from 'node:os';
|
|
4
5
|
import { join } from 'node:path';
|
|
5
|
-
import {
|
|
6
|
+
import { promisify } from 'node:util';
|
|
7
|
+
import { CONDUCTOR_TOKEN_ENV, CONDUCTOR_TOOLS_SERVER, ensureHome, homeKey, homePath, lastLine, resolveAgentCliOptions, resolveSecurityOptions, systemSandboxHost, validateOptionalBoolean, } from '@bakers-build/conductor/contract';
|
|
6
8
|
import { gitSandboxPaths, shellQuote, withoutGitDirs, } from '@bakers-build/core';
|
|
7
9
|
import { parseCodexTranscript } from './footprint.js';
|
|
8
10
|
export { parseCodexTranscript } from './footprint.js';
|
|
11
|
+
const run = promisify(execFile);
|
|
12
|
+
/** Run `codex <args>` in `codexHome`; a failure names `what` and the CLI's output. */
|
|
13
|
+
async function codex(codexHome, what, args) {
|
|
14
|
+
try {
|
|
15
|
+
const { stdout } = await run('codex', args, {
|
|
16
|
+
env: { ...process.env, CODEX_HOME: codexHome },
|
|
17
|
+
});
|
|
18
|
+
return stdout;
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
const { stderr, stdout, message } = error;
|
|
22
|
+
throw new Error(`${what}: codex ${args.join(' ')} failed: ${(stderr || stdout || message).trim()}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const HOOK_TRUST = '--dangerously-bypass-hook-trust';
|
|
9
26
|
const CODEX_RESERVED = [
|
|
10
27
|
'--sandbox',
|
|
11
28
|
'-s',
|
|
@@ -103,6 +120,10 @@ export class CodexAgent {
|
|
|
103
120
|
security;
|
|
104
121
|
allowWrite;
|
|
105
122
|
runEnvPolicy;
|
|
123
|
+
pluginsDisabled;
|
|
124
|
+
/** The Codex home runs read and write: the agent home while plugins are on. */
|
|
125
|
+
configDir;
|
|
126
|
+
pluginsOn = false;
|
|
106
127
|
constructor(options = {}, home = homedir()) {
|
|
107
128
|
this.home = home;
|
|
108
129
|
const cli = resolveAgentCliOptions(options, CODEX_RESERVED, CODEX_KNOWN);
|
|
@@ -116,6 +137,9 @@ export class CodexAgent {
|
|
|
116
137
|
});
|
|
117
138
|
this.runEnvPolicy = this.security.runEnvPolicy;
|
|
118
139
|
this.allowWrite = withoutGitDirs(this.security.sandbox.allow_write);
|
|
140
|
+
this.pluginsDisabled =
|
|
141
|
+
validateOptionalBoolean(options.plugins, 'plugins') === false;
|
|
142
|
+
this.configDir = this.userCodexHome();
|
|
119
143
|
// Codex has no read deny or unsandboxed-command list to map these onto.
|
|
120
144
|
for (const key of ['trusted_commands', 'deny_read']) {
|
|
121
145
|
if (this.security.sandbox[key].length > 0) {
|
|
@@ -131,6 +155,45 @@ export class CodexAgent {
|
|
|
131
155
|
}
|
|
132
156
|
}
|
|
133
157
|
}
|
|
158
|
+
userCodexHome() {
|
|
159
|
+
return process.env.CODEX_HOME || join(this.home, '.codex');
|
|
160
|
+
}
|
|
161
|
+
/** Point this agent at the agent home of the project's declared marketplaces. */
|
|
162
|
+
useMarketplaces(marketplaces) {
|
|
163
|
+
if (this.pluginsDisabled || marketplaces.length === 0)
|
|
164
|
+
return;
|
|
165
|
+
this.pluginsOn = true;
|
|
166
|
+
this.configDir = homePath(this.id, homeKey([...marketplaces]));
|
|
167
|
+
}
|
|
168
|
+
async installPlugins(marketplaces, home) {
|
|
169
|
+
const outcome = await ensureHome(home, async (dir) => {
|
|
170
|
+
const auth = join(this.userCodexHome(), 'auth.json');
|
|
171
|
+
if (!existsSync(auth))
|
|
172
|
+
throw new Error(`codex: no credential file at ${auth}; log in with codex login`);
|
|
173
|
+
symlinkSync(auth, join(dir, 'auth.json'));
|
|
174
|
+
for (const { url, ref, plugins } of marketplaces) {
|
|
175
|
+
const added = await codex(dir, url, [
|
|
176
|
+
'plugin',
|
|
177
|
+
'marketplace',
|
|
178
|
+
'add',
|
|
179
|
+
url,
|
|
180
|
+
'--ref',
|
|
181
|
+
ref,
|
|
182
|
+
]);
|
|
183
|
+
const name = /Added marketplace `([^`]+)`/.exec(added)?.[1];
|
|
184
|
+
if (!name)
|
|
185
|
+
throw new Error(`${url}: codex named no marketplace: ${added.trim()}`);
|
|
186
|
+
for (const plugin of plugins)
|
|
187
|
+
await codex(dir, plugin, ['plugin', 'add', `${plugin}@${name}`]);
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
return {
|
|
191
|
+
env: { CODEX_HOME: home },
|
|
192
|
+
args: [HOOK_TRUST],
|
|
193
|
+
home: outcome,
|
|
194
|
+
trust_bypass: ['hook trust'],
|
|
195
|
+
};
|
|
196
|
+
}
|
|
134
197
|
/** A `config.toml` server the conductor's own replaces, named once per dispatch. */
|
|
135
198
|
get launchWarnings() {
|
|
136
199
|
return this.userMcpServers().includes(CONDUCTOR_TOOLS_SERVER)
|
|
@@ -187,7 +250,7 @@ export class CodexAgent {
|
|
|
187
250
|
return flags;
|
|
188
251
|
}
|
|
189
252
|
userMcpServers() {
|
|
190
|
-
const codexHome =
|
|
253
|
+
const codexHome = this.userCodexHome();
|
|
191
254
|
let toml;
|
|
192
255
|
try {
|
|
193
256
|
toml = readFileSync(join(codexHome, 'config.toml'), 'utf8');
|
|
@@ -197,13 +260,19 @@ export class CodexAgent {
|
|
|
197
260
|
}
|
|
198
261
|
return codexMcpServerIds(toml);
|
|
199
262
|
}
|
|
200
|
-
launchCommand(prompt, _run, workspacePath = process.cwd(), tools, env = {}) {
|
|
263
|
+
launchCommand(prompt, _run, workspacePath = process.cwd(), tools, env = {}, pluginArgs = []) {
|
|
201
264
|
// Quote at assembly; a plain word has nothing for the shell to expand.
|
|
202
265
|
const word = (t) => (/^[\w./=-]+$/.test(t) ? t : shellQuote(t));
|
|
203
266
|
const parts = [
|
|
204
267
|
'codex',
|
|
205
268
|
...this.securityFlags(workspacePath, tools !== undefined).map(word),
|
|
206
269
|
];
|
|
270
|
+
for (const arg of pluginArgs)
|
|
271
|
+
if (!parts.includes(arg))
|
|
272
|
+
parts.push(word(arg));
|
|
273
|
+
// The agent home starts with no trusted project; trust this run's worktree only.
|
|
274
|
+
if (this.pluginsOn)
|
|
275
|
+
parts.push('-c', word(`projects.${JSON.stringify(workspacePath)}.trust_level="trusted"`));
|
|
207
276
|
// Codex's default shell env filter drops `*KEY*` names; without its key a
|
|
208
277
|
// `GIT_CONFIG_COUNT` entry makes every git call fail.
|
|
209
278
|
for (const [name, value] of Object.entries(env)) {
|
|
@@ -229,7 +298,7 @@ export class CodexAgent {
|
|
|
229
298
|
return parts.join(' ');
|
|
230
299
|
}
|
|
231
300
|
async getRunLog(worktreePath, run) {
|
|
232
|
-
const sessionsDir = join(this.
|
|
301
|
+
const sessionsDir = join(this.configDir, 'sessions');
|
|
233
302
|
let entries;
|
|
234
303
|
try {
|
|
235
304
|
entries = await readdir(sessionsDir, { recursive: true });
|
|
@@ -322,7 +391,8 @@ export function codexAgent(options = {}) {
|
|
|
322
391
|
id: 'codex',
|
|
323
392
|
requiredModules: [],
|
|
324
393
|
permissions: agent.security.report,
|
|
325
|
-
async createAgent() {
|
|
394
|
+
async createAgent(config) {
|
|
395
|
+
agent.useMarketplaces(config.marketplaces ?? []);
|
|
326
396
|
return agent;
|
|
327
397
|
},
|
|
328
398
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bakers-build/addon-codex",
|
|
3
|
-
"version": "0.7.1-next.
|
|
3
|
+
"version": "0.7.1-next.7",
|
|
4
4
|
"description": "bakers.build agent plugin for the Codex CLI.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,11 +20,11 @@
|
|
|
20
20
|
"directory": "bakers-cli/addons/codex"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
|
-
"@bakers-build/conductor": "^0.7.1-next.
|
|
24
|
-
"@bakers-build/core": "^0.7.1-next.
|
|
23
|
+
"@bakers-build/conductor": "^0.7.1-next.7",
|
|
24
|
+
"@bakers-build/core": "^0.7.1-next.7"
|
|
25
25
|
},
|
|
26
26
|
"bakersBuild": {
|
|
27
|
-
"commit": "
|
|
27
|
+
"commit": "082d8c57436f78e751f5a9a26a4446cec42209ce",
|
|
28
28
|
"channel": "next"
|
|
29
29
|
}
|
|
30
30
|
}
|