@bakers-build/addon-codex 0.0.0-stage → 0.1.0-next.38

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 keytec GmbH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
- # Temporary Holding Version
1
+ # @bakers-build/addon-codex
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ bakers.build agent plugin for the Codex CLI.
4
+
5
+ Part of the bakers.build CLI. Install the meta package `@bakers-build/bakers` to get the `bakers` CLI with all addons. Source: https://git.key-tec.de/bakers-build/bakers-build (bakers-cli/).
@@ -0,0 +1,3 @@
1
+ import { type AgentFootprint } from '@bakers-build/conductor/contract';
2
+ /** Parse Codex CLI session JSONL into the agent-neutral bakers.build footprint. */
3
+ export declare function parseCodexTranscript(jsonl: string): AgentFootprint;
@@ -0,0 +1,61 @@
1
+ import { emptyAgentFootprint, } from '@bakers-build/conductor/contract';
2
+ function countWords(text) {
3
+ const trimmed = text.trim();
4
+ return trimmed === '' ? 0 : trimmed.split(/\s+/).length;
5
+ }
6
+ /** Parse Codex CLI session JSONL into the agent-neutral bakers.build footprint. */
7
+ export function parseCodexTranscript(jsonl) {
8
+ const footprint = emptyAgentFootprint();
9
+ let minTs = Number.POSITIVE_INFINITY;
10
+ let maxTs = Number.NEGATIVE_INFINITY;
11
+ for (const raw of jsonl.split('\n')) {
12
+ const line = raw.trim();
13
+ if (line === '')
14
+ continue;
15
+ let entry;
16
+ try {
17
+ entry = JSON.parse(line);
18
+ }
19
+ catch {
20
+ continue;
21
+ }
22
+ if (typeof entry.timestamp === 'string') {
23
+ const timestamp = Date.parse(entry.timestamp);
24
+ if (Number.isFinite(timestamp)) {
25
+ minTs = Math.min(minTs, timestamp);
26
+ maxTs = Math.max(maxTs, timestamp);
27
+ }
28
+ }
29
+ const payload = entry.payload;
30
+ if (!payload || typeof payload !== 'object')
31
+ continue;
32
+ if (entry.type === 'turn_context' && typeof payload.model === 'string') {
33
+ footprint.model = payload.model;
34
+ }
35
+ else if (entry.type === 'event_msg' && payload.type === 'token_count') {
36
+ const total = payload.info?.total_token_usage?.total_tokens;
37
+ if (typeof total === 'number' && Number.isFinite(total)) {
38
+ footprint.tokens = total;
39
+ }
40
+ }
41
+ else if (entry.type === 'event_msg' &&
42
+ payload.type === 'user_message' &&
43
+ typeof payload.message === 'string') {
44
+ footprint.user_prompts += 1;
45
+ footprint.user_prompt_words += countWords(payload.message);
46
+ }
47
+ else if (entry.type === 'response_item' &&
48
+ payload.type === 'message' &&
49
+ payload.role === 'assistant') {
50
+ footprint.agent_turns += 1;
51
+ }
52
+ else if (entry.type === 'response_item' &&
53
+ (payload.type === 'function_call' || payload.type === 'custom_tool_call')) {
54
+ footprint.tool_calls += 1;
55
+ }
56
+ }
57
+ if (Number.isFinite(minTs) && Number.isFinite(maxTs) && maxTs > minTs) {
58
+ footprint.duration_s = Math.floor((maxTs - minTs) / 1000);
59
+ }
60
+ return footprint;
61
+ }
@@ -0,0 +1,22 @@
1
+ import { type AgentFootprint, type AgentPlugin, type AgentRunIdentity, type BbAgent } from '@bakers-build/conductor/contract';
2
+ export { parseCodexTranscript } from './footprint.js';
3
+ export interface CodexAgentOptions {
4
+ model?: string;
5
+ effort?: string;
6
+ args?: string[];
7
+ }
8
+ export declare class CodexAgent implements BbAgent {
9
+ private readonly home;
10
+ readonly id = "codex";
11
+ private readonly args;
12
+ private readonly model;
13
+ private readonly effort;
14
+ private readonly overrides;
15
+ constructor(options?: CodexAgentOptions, home?: string);
16
+ launchCommand(prompt: string, _run?: AgentRunIdentity): string;
17
+ getRunLog(worktreePath: string, run?: AgentRunIdentity): Promise<string>;
18
+ parseFootprint(log: string): AgentFootprint;
19
+ }
20
+ /** Config-facing factory: `codexAgent({ model: 'gpt-5' })`. */
21
+ export declare function codexAgent(options?: CodexAgentOptions): AgentPlugin;
22
+ export default codexAgent;
@@ -0,0 +1,137 @@
1
+ import { readdir, readFile, stat } from 'node:fs/promises';
2
+ import { homedir } from 'node:os';
3
+ import { join } from 'node:path';
4
+ import { resolveAgentCliOptions, } from '@bakers-build/conductor/contract';
5
+ import { shellQuote } from '@bakers-build/core';
6
+ import { parseCodexTranscript } from './footprint.js';
7
+ export { parseCodexTranscript } from './footprint.js';
8
+ const CODEX_RESERVED = [
9
+ '--sandbox',
10
+ '-s',
11
+ '--dangerously-bypass-approvals-and-sandbox',
12
+ '--dangerously-bypass-hook-trust',
13
+ ];
14
+ const CODEX_KNOWN = [
15
+ { kind: 'model', flags: ['--model', '-m'], configKeys: ['model'] },
16
+ { kind: 'effort', flags: [], configKeys: ['model_reasoning_effort'] },
17
+ ];
18
+ export class CodexAgent {
19
+ home;
20
+ id = 'codex';
21
+ args;
22
+ model;
23
+ effort;
24
+ overrides;
25
+ constructor(options = {}, home = homedir()) {
26
+ this.home = home;
27
+ const cli = resolveAgentCliOptions(options, CODEX_RESERVED, CODEX_KNOWN);
28
+ this.args = cli.args;
29
+ this.model = cli.model;
30
+ this.effort = cli.effort;
31
+ this.overrides = cli.overrides;
32
+ }
33
+ launchCommand(prompt, _run) {
34
+ const parts = [
35
+ 'codex',
36
+ '--sandbox danger-full-access',
37
+ '--dangerously-bypass-approvals-and-sandbox',
38
+ '--dangerously-bypass-hook-trust',
39
+ ];
40
+ if (this.model !== undefined && !this.overrides.model) {
41
+ parts.push('--model', shellQuote(this.model));
42
+ }
43
+ if (this.effort !== undefined && !this.overrides.effort) {
44
+ parts.push('-c', shellQuote(`model_reasoning_effort=${JSON.stringify(this.effort)}`));
45
+ }
46
+ if (prompt !== '') {
47
+ parts.push(shellQuote(prompt));
48
+ parts.push(...this.args.map(shellQuote));
49
+ }
50
+ return parts.join(' ');
51
+ }
52
+ async getRunLog(worktreePath, run) {
53
+ const sessionsDir = join(this.home, '.codex', 'sessions');
54
+ let entries;
55
+ try {
56
+ entries = await readdir(sessionsDir, { recursive: true });
57
+ }
58
+ catch {
59
+ return '';
60
+ }
61
+ // Codex has no session-id pin (BB-473): the lower bound below is the
62
+ // only available defence, so a transcript from a PRIOR run left in the
63
+ // same (reused) worktree can never be selected for THIS run even when it
64
+ // is the only/newest cwd-matching transcript around.
65
+ const startedAtMs = run?.startedAt !== undefined ? new Date(run.startedAt).getTime() : null;
66
+ let latest = null;
67
+ for (const name of entries) {
68
+ if (!name.endsWith('.jsonl'))
69
+ continue;
70
+ const path = join(sessionsDir, name);
71
+ try {
72
+ const [metadata, log] = await Promise.all([
73
+ stat(path),
74
+ readFile(path, 'utf8'),
75
+ ]);
76
+ let matches = false;
77
+ // The session's own start, per the `session_meta` line's `timestamp`
78
+ // field — preferred over the file's mtime (BB-473 finding 3), since
79
+ // a still-open or appended-to session's mtime keeps advancing past
80
+ // its own start and would otherwise survive the lower-bound filter.
81
+ // Falls back to the file mtime when the line carries no timestamp.
82
+ let sessionStartMs = null;
83
+ for (const raw of log.split('\n')) {
84
+ try {
85
+ const entry = JSON.parse(raw);
86
+ if (entry.type === 'session_meta') {
87
+ matches = entry.payload?.cwd === worktreePath;
88
+ if (typeof entry.timestamp === 'string') {
89
+ const ts = Date.parse(entry.timestamp);
90
+ if (Number.isFinite(ts)) {
91
+ sessionStartMs = ts;
92
+ }
93
+ }
94
+ break;
95
+ }
96
+ }
97
+ catch {
98
+ // malformed line — skip.
99
+ }
100
+ }
101
+ const comparisonMs = sessionStartMs ?? metadata.mtimeMs;
102
+ if (startedAtMs !== null &&
103
+ Number.isFinite(startedAtMs) &&
104
+ comparisonMs < startedAtMs) {
105
+ continue;
106
+ }
107
+ if (matches && (!latest || metadata.mtimeMs > latest.mtimeMs)) {
108
+ latest = { log, mtimeMs: metadata.mtimeMs };
109
+ }
110
+ }
111
+ catch {
112
+ // A session may disappear or be unreadable while Codex rotates logs.
113
+ }
114
+ }
115
+ return latest?.log ?? '';
116
+ }
117
+ parseFootprint(log) {
118
+ return parseCodexTranscript(log);
119
+ }
120
+ }
121
+ /** Config-facing factory: `codexAgent({ model: 'gpt-5' })`. */
122
+ export function codexAgent(options = {}) {
123
+ const agent = new CodexAgent(options);
124
+ return {
125
+ kind: 'agent',
126
+ id: 'codex',
127
+ requiredModules: [],
128
+ async createAgent() {
129
+ return agent;
130
+ },
131
+ };
132
+ }
133
+ // Default export: this module also exports the `CodexAgent` class, so the
134
+ // config resolver's auto-pick (no `export:`) sees 2 function exports and
135
+ // would otherwise throw "specify export" — see conductor/src/config.ts
136
+ // `loadNamedPlugin`. The default export makes the factory win.
137
+ export default codexAgent;
@@ -0,0 +1,4 @@
1
+ import type { Preset } from '@bakers-build/conductor/contract';
2
+ import { type CodexAgentOptions } from './index.js';
3
+ export declare const agents: Preset<Partial<CodexAgentOptions> | undefined>['agents'];
4
+ export declare const scopes: Preset['scopes'];
@@ -0,0 +1,45 @@
1
+ import codexAgent from './index.js';
2
+ export const agents = (acc, opts) => {
3
+ const model = opts?.model;
4
+ const candidates = [
5
+ ...acc,
6
+ {
7
+ alias: 'codex',
8
+ description: 'Implementation and debugging with the locally configured Codex model.',
9
+ ...(model !== undefined ? { model } : {}),
10
+ agent: codexAgent(opts),
11
+ },
12
+ ];
13
+ if (model !== undefined)
14
+ return candidates;
15
+ return [
16
+ ...candidates,
17
+ ...[
18
+ {
19
+ alias: 'astra',
20
+ model: 'gpt-6-astra',
21
+ description: 'Strong reasoning for complex design, difficult debugging and demanding implementation.',
22
+ },
23
+ {
24
+ alias: 'sol',
25
+ model: 'gpt-5.6-sol',
26
+ description: 'Reliable implementation and routine maintenance from a clear plan.',
27
+ },
28
+ {
29
+ alias: 'terra',
30
+ model: 'gpt-5.6-terra',
31
+ description: 'Balanced reasoning and implementation for everyday coding work.',
32
+ },
33
+ {
34
+ alias: 'luna',
35
+ model: 'gpt-5.6-luna',
36
+ description: 'Fast, economical implementation of small, well-specified changes.',
37
+ },
38
+ ].map((variant) => ({
39
+ ...variant,
40
+ agent: codexAgent({ ...opts, model: variant.model }),
41
+ })),
42
+ ];
43
+ };
44
+ // Agents are per machine: list this addon in ~/.bakers/machine.config.js addons[].
45
+ export const scopes = ['machine'];
package/package.json CHANGED
@@ -1,6 +1,26 @@
1
1
  {
2
2
  "name": "@bakers-build/addon-codex",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0-next.38",
4
+ "description": "bakers.build agent plugin for the Codex CLI.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "exports": {
8
+ ".": "./dist/src/index.js",
9
+ "./preset": "./dist/src/preset.js"
10
+ },
11
+ "files": [
12
+ "dist/src"
13
+ ],
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://git.key-tec.de/bakers-build/bakers-build.git",
20
+ "directory": "bakers-cli/addons/codex"
21
+ },
22
+ "peerDependencies": {
23
+ "@bakers-build/conductor": "^0.1.0-next.38",
24
+ "@bakers-build/core": "^0.1.0-next.38"
25
+ }
26
+ }