@gaia-ai/addon-codex 0.6.1
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 +21 -0
- package/README.md +5 -0
- package/dist/src/footprint.d.ts +3 -0
- package/dist/src/footprint.js +61 -0
- package/dist/src/index.d.ts +17 -0
- package/dist/src/index.js +89 -0
- package/dist/src/preset.d.ts +2 -0
- package/dist/src/preset.js +5 -0
- package/package.json +26 -0
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
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { emptyAgentFootprint, } from '@gaia-ai/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 GAIA 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,17 @@
|
|
|
1
|
+
import type { AgentFootprint, AgentPlugin, GaiaAgent } from '@gaia-ai/conductor/contract';
|
|
2
|
+
export { parseCodexTranscript } from './footprint.js';
|
|
3
|
+
export interface CodexAgentOptions {
|
|
4
|
+
model?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class CodexAgent implements GaiaAgent {
|
|
7
|
+
private readonly options;
|
|
8
|
+
private readonly home;
|
|
9
|
+
readonly id = "codex";
|
|
10
|
+
constructor(options: CodexAgentOptions, home?: string);
|
|
11
|
+
launchCommand(prompt: string): string;
|
|
12
|
+
getRunLog(worktreePath: string): Promise<string>;
|
|
13
|
+
parseFootprint(log: string): AgentFootprint;
|
|
14
|
+
}
|
|
15
|
+
/** Config-facing factory: `codexAgent({ model: 'gpt-5' })`. */
|
|
16
|
+
export declare function codexAgent(options?: CodexAgentOptions): AgentPlugin;
|
|
17
|
+
export default codexAgent;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { readdir, readFile, stat } from 'node:fs/promises';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { shellQuote } from '@gaia-ai/core';
|
|
5
|
+
import { parseCodexTranscript } from './footprint.js';
|
|
6
|
+
export { parseCodexTranscript } from './footprint.js';
|
|
7
|
+
export class CodexAgent {
|
|
8
|
+
options;
|
|
9
|
+
home;
|
|
10
|
+
id = 'codex';
|
|
11
|
+
constructor(options, home = homedir()) {
|
|
12
|
+
this.options = options;
|
|
13
|
+
this.home = home;
|
|
14
|
+
}
|
|
15
|
+
launchCommand(prompt) {
|
|
16
|
+
const parts = [
|
|
17
|
+
'codex',
|
|
18
|
+
'--sandbox danger-full-access',
|
|
19
|
+
'--dangerously-bypass-approvals-and-sandbox',
|
|
20
|
+
'--dangerously-bypass-hook-trust',
|
|
21
|
+
];
|
|
22
|
+
if (this.options.model) {
|
|
23
|
+
parts.push('--model', this.options.model);
|
|
24
|
+
}
|
|
25
|
+
if (prompt !== '') {
|
|
26
|
+
parts.push(shellQuote(prompt));
|
|
27
|
+
}
|
|
28
|
+
return parts.join(' ');
|
|
29
|
+
}
|
|
30
|
+
async getRunLog(worktreePath) {
|
|
31
|
+
const sessionsDir = join(this.home, '.codex', 'sessions');
|
|
32
|
+
let entries;
|
|
33
|
+
try {
|
|
34
|
+
entries = await readdir(sessionsDir, { recursive: true });
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return '';
|
|
38
|
+
}
|
|
39
|
+
let latest = null;
|
|
40
|
+
for (const name of entries) {
|
|
41
|
+
if (!name.endsWith('.jsonl'))
|
|
42
|
+
continue;
|
|
43
|
+
const path = join(sessionsDir, name);
|
|
44
|
+
try {
|
|
45
|
+
const [metadata, log] = await Promise.all([
|
|
46
|
+
stat(path),
|
|
47
|
+
readFile(path, 'utf8'),
|
|
48
|
+
]);
|
|
49
|
+
const matches = log.split('\n').some((raw) => {
|
|
50
|
+
try {
|
|
51
|
+
const entry = JSON.parse(raw);
|
|
52
|
+
return (entry.type === 'session_meta' &&
|
|
53
|
+
entry.payload?.cwd === worktreePath);
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
if (matches && (!latest || metadata.mtimeMs > latest.mtimeMs)) {
|
|
60
|
+
latest = { log, mtimeMs: metadata.mtimeMs };
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
// A session may disappear or be unreadable while Codex rotates logs.
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return latest?.log ?? '';
|
|
68
|
+
}
|
|
69
|
+
parseFootprint(log) {
|
|
70
|
+
return parseCodexTranscript(log);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/** Config-facing factory: `codexAgent({ model: 'gpt-5' })`. */
|
|
74
|
+
export function codexAgent(options = {}) {
|
|
75
|
+
const agent = new CodexAgent(options);
|
|
76
|
+
return {
|
|
77
|
+
kind: 'agent',
|
|
78
|
+
id: 'codex',
|
|
79
|
+
requiredModules: [],
|
|
80
|
+
async createAgent() {
|
|
81
|
+
return agent;
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
// Default export: this module also exports the `CodexAgent` class, so the
|
|
86
|
+
// config resolver's auto-pick (no `export:`) sees 2 function exports and
|
|
87
|
+
// would otherwise throw "specify export" — see conductor/src/config.ts
|
|
88
|
+
// `loadNamedPlugin`. The default export makes the factory win.
|
|
89
|
+
export default codexAgent;
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gaia-ai/addon-codex",
|
|
3
|
+
"version": "0.6.1",
|
|
4
|
+
"description": "GAIA 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/keytec/gaia.git",
|
|
20
|
+
"directory": "gaia-cli/addons/codex"
|
|
21
|
+
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"@gaia-ai/conductor": "^0.6.1",
|
|
24
|
+
"@gaia-ai/core": "^0.6.1"
|
|
25
|
+
}
|
|
26
|
+
}
|