a2a-codex 1.6.0
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/README.md +451 -0
- package/agents/example/config.json +66 -0
- package/agents/example/start.sh +39 -0
- package/agents/example/workspace/.gitkeep +0 -0
- package/agents/multi-agent/config.json +77 -0
- package/agents/multi-agent/start.sh +36 -0
- package/agents/multi-agent/workspace/.gitkeep +0 -0
- package/agents/read-only-reviewer/config.json +50 -0
- package/agents/read-only-reviewer/start.sh +32 -0
- package/agents/read-only-reviewer/workspace/.gitkeep +0 -0
- package/dist/cli.d.ts +17 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +175 -0
- package/dist/cli.js.map +1 -0
- package/dist/codex/backend-paths.d.ts +12 -0
- package/dist/codex/backend-paths.d.ts.map +1 -0
- package/dist/codex/backend-paths.js +14 -0
- package/dist/codex/backend-paths.js.map +1 -0
- package/dist/codex/capabilities.d.ts +21 -0
- package/dist/codex/capabilities.d.ts.map +1 -0
- package/dist/codex/capabilities.js +16 -0
- package/dist/codex/capabilities.js.map +1 -0
- package/dist/codex/client-factory.d.ts +65 -0
- package/dist/codex/client-factory.d.ts.map +1 -0
- package/dist/codex/client-factory.js +36 -0
- package/dist/codex/client-factory.js.map +1 -0
- package/dist/codex/event-mapper.d.ts +33 -0
- package/dist/codex/event-mapper.d.ts.map +1 -0
- package/dist/codex/event-mapper.js +248 -0
- package/dist/codex/event-mapper.js.map +1 -0
- package/dist/codex/executor.d.ts +29 -0
- package/dist/codex/executor.d.ts.map +1 -0
- package/dist/codex/executor.js +282 -0
- package/dist/codex/executor.js.map +1 -0
- package/dist/codex/index.d.ts +8 -0
- package/dist/codex/index.d.ts.map +1 -0
- package/dist/codex/index.js +7 -0
- package/dist/codex/index.js.map +1 -0
- package/dist/codex/mcp-adapter.d.ts +29 -0
- package/dist/codex/mcp-adapter.d.ts.map +1 -0
- package/dist/codex/mcp-adapter.js +104 -0
- package/dist/codex/mcp-adapter.js.map +1 -0
- package/dist/codex/prompt-builder.d.ts +9 -0
- package/dist/codex/prompt-builder.d.ts.map +1 -0
- package/dist/codex/prompt-builder.js +16 -0
- package/dist/codex/prompt-builder.js.map +1 -0
- package/dist/codex/session-manager.d.ts +54 -0
- package/dist/codex/session-manager.d.ts.map +1 -0
- package/dist/codex/session-manager.js +124 -0
- package/dist/codex/session-manager.js.map +1 -0
- package/dist/config/defaults.d.ts +9 -0
- package/dist/config/defaults.d.ts.map +1 -0
- package/dist/config/defaults.js +60 -0
- package/dist/config/defaults.js.map +1 -0
- package/dist/config/loader.d.ts +16 -0
- package/dist/config/loader.d.ts.map +1 -0
- package/dist/config/loader.js +152 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/config/types.d.ts +224 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +8 -0
- package/dist/config/types.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/server/agent-card.d.ts +7 -0
- package/dist/server/agent-card.d.ts.map +1 -0
- package/dist/server/agent-card.js +20 -0
- package/dist/server/agent-card.js.map +1 -0
- package/dist/server/index.d.ts +22 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +123 -0
- package/dist/server/index.js.map +1 -0
- package/dist/utils/logger.d.ts +30 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +64 -0
- package/dist/utils/logger.js.map +1 -0
- package/package.json +73 -0
- package/schemas/agent-config.schema.json +615 -0
package/README.md
ADDED
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
# a2a-codex
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/a2a-codex)
|
|
4
|
+
[](https://github.com/shashikanth-gs/a2a-wrapper/actions/workflows/ci.yml)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
[](https://nodejs.org)
|
|
7
|
+
|
|
8
|
+
OpenAI Codex is a production-grade software engineering agent. It handles repository navigation, multi-step planning, shell command execution, file editing, and sandbox isolation — all the plumbing you'd spend months building from scratch.
|
|
9
|
+
|
|
10
|
+
**a2a-codex** exposes it as a standalone, interoperable agent via the [A2A protocol](https://github.com/google-deepmind/a2a). Drop a JSON config file in, get a fully spec-compliant A2A server out. Any orchestrator that speaks A2A can discover and call it — no Codex-specific integration code required.
|
|
11
|
+
|
|
12
|
+
> **The pattern:** MCP is the vertical rail — how agents access tools. A2A is the horizontal rail — how agents talk to each other. This library adds the horizontal rail to OpenAI Codex.
|
|
13
|
+
|
|
14
|
+
**Features:**
|
|
15
|
+
- Full [A2A v0.3.0](https://github.com/google-deepmind/a2a) protocol — Agent Card, JSON-RPC, REST, streaming
|
|
16
|
+
- Powered by `@openai/codex-sdk` — `o4-mini`, `o3`, `gpt-4o`, and any Codex-compatible model
|
|
17
|
+
- Repository sandboxing — `read-only`, `workspace-write`, `danger-full-access` modes
|
|
18
|
+
- MCP tool support — stdio and Streamable HTTP transports
|
|
19
|
+
- Multi-turn context continuity — each A2A `contextId` maps to a persistent Codex thread
|
|
20
|
+
- AbortController-based cancellation
|
|
21
|
+
- Multi-agent delegation via A2A sub-agents
|
|
22
|
+
- Sideband events — reasoning summaries, command events, file-change events
|
|
23
|
+
- JSON config file with layered overrides (JSON → env vars → CLI flags)
|
|
24
|
+
- Docker-ready with corporate proxy CA support
|
|
25
|
+
- TypeScript source with full type declarations
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
**Option A — OpenAI API key:**
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm install -g a2a-codex
|
|
33
|
+
|
|
34
|
+
export OPENAI_API_KEY=sk-...
|
|
35
|
+
export WORKSPACE_DIR=/path/to/your/repo
|
|
36
|
+
a2a-codex --config agents/example/config.json
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
**Option B — ChatGPT subscription (no API key needed):**
|
|
40
|
+
|
|
41
|
+
If you have a ChatGPT Plus or Pro subscription and have already run `codex login` locally, the Codex CLI reads credentials from `~/.codex/auth.json` automatically — no `OPENAI_API_KEY` required. Specify a model that your subscription supports:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
export WORKSPACE_DIR=/path/to/your/repo
|
|
45
|
+
export CODEX_MODEL=gpt-5.5
|
|
46
|
+
a2a-codex --config agents/example/config.json
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
The agent card is available at `http://localhost:3020/.well-known/agent-card.json`.
|
|
50
|
+
|
|
51
|
+
## Architecture
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
A2A Client (Orchestrator / Inspector / curl)
|
|
55
|
+
│
|
|
56
|
+
│ JSON-RPC or REST over HTTP
|
|
57
|
+
▼
|
|
58
|
+
Express Server (a2a-codex)
|
|
59
|
+
│ ├─ /.well-known/agent-card.json → Agent Card
|
|
60
|
+
│ ├─ /a2a/jsonrpc → JSON-RPC (message/send, message/sendSubscribe, …)
|
|
61
|
+
│ ├─ /a2a/rest → REST handler
|
|
62
|
+
│ ├─ /context → Read context.md
|
|
63
|
+
│ ├─ /context/build → Trigger context discovery
|
|
64
|
+
│ └─ /health → Health check
|
|
65
|
+
▼
|
|
66
|
+
CodexExecutor
|
|
67
|
+
├─ SessionManager (contextId → Codex Thread)
|
|
68
|
+
├─ EventMapper (ThreadEvent → A2A sideband events)
|
|
69
|
+
└─ @openai/codex-sdk
|
|
70
|
+
└─ Codex Thread (sandboxed repository operations)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Required Environment Variables
|
|
74
|
+
|
|
75
|
+
| Variable | Required | Description |
|
|
76
|
+
|---|---|---|
|
|
77
|
+
| `OPENAI_API_KEY` | Yes | Your OpenAI API key |
|
|
78
|
+
| `WORKSPACE_DIR` | Yes* | Absolute path to the Git repository Codex will operate in |
|
|
79
|
+
| `CODEX_MODEL` | No | Override model (e.g. `o4-mini`, `o3`, `gpt-4o`) |
|
|
80
|
+
| `LOG_LEVEL` | No | `debug` \| `info` \| `warn` \| `error` (default: `info`) |
|
|
81
|
+
| `PORT` | No | A2A server port (default: from config, fallback `3020`) |
|
|
82
|
+
| `ADVERTISE_HOST` | No | Hostname embedded in agent card URLs (default: `localhost`) |
|
|
83
|
+
| `STREAM_ARTIFACTS` | No | Set `"true"` to stream artifact chunks (default: buffered) |
|
|
84
|
+
|
|
85
|
+
*Can also be set via `codex.workingDirectory` in `config.json` or the `--workspace` CLI flag.
|
|
86
|
+
|
|
87
|
+
## Configuration Reference
|
|
88
|
+
|
|
89
|
+
All settings live in a single JSON config file. Priority order: **built-in defaults ← config file ← environment variables ← CLI flags**.
|
|
90
|
+
|
|
91
|
+
### Minimal config
|
|
92
|
+
|
|
93
|
+
```json
|
|
94
|
+
{
|
|
95
|
+
"agentCard": {
|
|
96
|
+
"name": "My Codex Agent",
|
|
97
|
+
"description": "Repository-scoped software engineering agent"
|
|
98
|
+
},
|
|
99
|
+
"server": { "port": 3020 },
|
|
100
|
+
"codex": {
|
|
101
|
+
"workingDirectory": "${WORKSPACE_DIR}"
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Full config reference
|
|
107
|
+
|
|
108
|
+
```json
|
|
109
|
+
{
|
|
110
|
+
"agentCard": {
|
|
111
|
+
"name": "Codex Workspace Engineer",
|
|
112
|
+
"description": "...",
|
|
113
|
+
"version": "1.0.0",
|
|
114
|
+
"protocolVersion": "0.3.0",
|
|
115
|
+
"streaming": true,
|
|
116
|
+
"defaultInputModes": ["text"],
|
|
117
|
+
"defaultOutputModes": ["text"],
|
|
118
|
+
"skills": [
|
|
119
|
+
{
|
|
120
|
+
"id": "workspace-engineering",
|
|
121
|
+
"name": "Workspace Engineering",
|
|
122
|
+
"description": "Inspect, modify, and validate code within the configured repository.",
|
|
123
|
+
"tags": ["code", "repository", "tests", "refactoring"]
|
|
124
|
+
}
|
|
125
|
+
]
|
|
126
|
+
},
|
|
127
|
+
|
|
128
|
+
"server": {
|
|
129
|
+
"port": 3020,
|
|
130
|
+
"hostname": "0.0.0.0",
|
|
131
|
+
"advertiseHost": "localhost",
|
|
132
|
+
"advertiseProtocol": "http"
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
"codex": {
|
|
136
|
+
"workingDirectory": "${WORKSPACE_DIR}",
|
|
137
|
+
"model": "${CODEX_MODEL}",
|
|
138
|
+
"sandboxMode": "workspace-write",
|
|
139
|
+
"approvalPolicy": "never",
|
|
140
|
+
"networkAccessEnabled": false,
|
|
141
|
+
"webSearchMode": "disabled",
|
|
142
|
+
"skipGitRepoCheck": false,
|
|
143
|
+
"additionalDirectories": [],
|
|
144
|
+
"developerInstructions": "Operate only within the configured workspace.",
|
|
145
|
+
"baseUrl": "https://api.openai.com/v1",
|
|
146
|
+
"contextFile": "context.md",
|
|
147
|
+
"contextPrompt": "Explore this repository…"
|
|
148
|
+
},
|
|
149
|
+
|
|
150
|
+
"session": {
|
|
151
|
+
"reuseByContext": true,
|
|
152
|
+
"ttl": 3600000,
|
|
153
|
+
"cleanupInterval": 300000
|
|
154
|
+
},
|
|
155
|
+
|
|
156
|
+
"features": {
|
|
157
|
+
"streamArtifactChunks": false,
|
|
158
|
+
"emitReasoningSummaries": true,
|
|
159
|
+
"emitCommandEvents": true,
|
|
160
|
+
"emitFileChangeEvents": true
|
|
161
|
+
},
|
|
162
|
+
|
|
163
|
+
"timeouts": {
|
|
164
|
+
"prompt": 600000
|
|
165
|
+
},
|
|
166
|
+
|
|
167
|
+
"logging": {
|
|
168
|
+
"level": "info"
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Sandbox modes
|
|
174
|
+
|
|
175
|
+
| Mode | File access | When to use |
|
|
176
|
+
|---|---|---|
|
|
177
|
+
| `read-only` | No writes | Code review, repository analysis |
|
|
178
|
+
| `workspace-write` | Writes within `workingDirectory` only (default) | General engineering tasks |
|
|
179
|
+
| `danger-full-access` | Unrestricted | Only inside an isolated container or VM |
|
|
180
|
+
|
|
181
|
+
> **Security note:** Never use `danger-full-access` outside a fully isolated environment. The executor logs a warning on startup if this mode is set.
|
|
182
|
+
|
|
183
|
+
### Approval policy
|
|
184
|
+
|
|
185
|
+
| Policy | Behaviour |
|
|
186
|
+
|---|---|
|
|
187
|
+
| `never` | Auto-approve all tool calls (default — required for headless A2A) |
|
|
188
|
+
| `on-failure` | Approve only when a command fails |
|
|
189
|
+
| `untrusted` | Approve tools from untrusted sources |
|
|
190
|
+
| `on-request` | **Not supported** — interactive approvals are incompatible with headless A2A execution |
|
|
191
|
+
|
|
192
|
+
## AGENTS.md and `.agents/skills/`
|
|
193
|
+
|
|
194
|
+
Codex reads `AGENTS.md` in the workspace root for project-level instructions. Place agent configuration, coding standards, and tool usage rules there. The wrapper materializes memory-backed instructions to that path before each session.
|
|
195
|
+
|
|
196
|
+
Skills can be placed in `.agents/skills/<skill-name>/SKILL.md`. Configure them via the `memory` block in `config.json`.
|
|
197
|
+
|
|
198
|
+
```
|
|
199
|
+
your-repo/
|
|
200
|
+
├── AGENTS.md ← project instructions for Codex
|
|
201
|
+
└── .agents/
|
|
202
|
+
└── skills/
|
|
203
|
+
├── security-audit/
|
|
204
|
+
│ └── SKILL.md ← skill instructions
|
|
205
|
+
└── test-generation/
|
|
206
|
+
└── SKILL.md
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## MCP Support Matrix
|
|
210
|
+
|
|
211
|
+
| Transport | Supported | Notes |
|
|
212
|
+
|---|---|---|
|
|
213
|
+
| `stdio` | Yes | Spawns process at startup; args/env support `${VAR}` substitution |
|
|
214
|
+
| `http` (Streamable HTTP) | Yes | HTTP headers support `${VAR}` substitution for auth tokens |
|
|
215
|
+
| `sse` | **No** | SSE-only MCP servers are not supported; use `http` or `stdio` instead |
|
|
216
|
+
|
|
217
|
+
MCP configuration is baked at SDK construction time. All MCP servers must be declared in `config.json` before the agent starts — runtime registration is not possible.
|
|
218
|
+
|
|
219
|
+
```json
|
|
220
|
+
{
|
|
221
|
+
"mcp": {
|
|
222
|
+
"filesystem": {
|
|
223
|
+
"type": "stdio",
|
|
224
|
+
"command": "npx",
|
|
225
|
+
"args": ["-y", "@modelcontextprotocol/server-filesystem", "${WORKSPACE_DIR}"]
|
|
226
|
+
},
|
|
227
|
+
"linear": {
|
|
228
|
+
"type": "http",
|
|
229
|
+
"url": "https://mcp.linear.app/mcp",
|
|
230
|
+
"headers": { "Authorization": "Bearer ${LINEAR_API_KEY}" }
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
## Sub-Agent Delegation
|
|
237
|
+
|
|
238
|
+
Any `a2a-codex` agent can delegate to other A2A agents. Declare them under `subAgents` — the wrapper bootstraps [`a2a-mcp-skillmap`](https://www.npmjs.com/package/a2a-mcp-skillmap) as a stdio MCP server and makes each remote skill available as a Codex tool.
|
|
239
|
+
|
|
240
|
+
```json
|
|
241
|
+
{
|
|
242
|
+
"subAgents": {
|
|
243
|
+
"agents": [
|
|
244
|
+
{
|
|
245
|
+
"name": "security",
|
|
246
|
+
"agentCardUrl": "http://localhost:3010/.well-known/agent-card.json"
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
"name": "test-engineer",
|
|
250
|
+
"agentCardUrl": "http://localhost:3011/.well-known/agent-card.json"
|
|
251
|
+
}
|
|
252
|
+
],
|
|
253
|
+
"options": {
|
|
254
|
+
"responseMode": "artifact",
|
|
255
|
+
"probeTimeoutMs": 5000,
|
|
256
|
+
"syncBudgetMs": 30000
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
The Codex LLM sees `security__<skillId>` and `test-engineer__<skillId>` tools. MCP calls targeting the `a2a-subagents` server are enriched with `delegation: true` in sideband events for observability.
|
|
263
|
+
|
|
264
|
+
See `agents/multi-agent/config.json` for a bundled lead-engineer example.
|
|
265
|
+
|
|
266
|
+
## Sideband Event Mapping
|
|
267
|
+
|
|
268
|
+
A2A sideband events are emitted through `AgentEventEmitter` for every Codex `ThreadEvent`. Use them for observability, tracing, and orchestration.
|
|
269
|
+
|
|
270
|
+
| Codex event / item | A2A sideband event | Notes |
|
|
271
|
+
|---|---|---|
|
|
272
|
+
| `reasoning` item | `thinking` | Text summary only — raw reasoning never exposed |
|
|
273
|
+
| `command_execution` item | `tool_call_start` + `tool_call_end` | Output truncated at 10,000 chars; controlled by `emitCommandEvents` |
|
|
274
|
+
| `file_change` item | `decision` | Path and operation kind only — file contents never emitted; controlled by `emitFileChangeEvents` |
|
|
275
|
+
| `mcp_tool_call` → `a2a-subagents` | `tool_call_start` + `tool_call_end` | Enriched with `toolKind: "a2a_subagent"`, `delegation: true` |
|
|
276
|
+
| `mcp_tool_call` → other servers | `tool_call_start` + `tool_call_end` | Standard MCP tool call |
|
|
277
|
+
| `todo_list` item | `decision` | Codex's internal planning list |
|
|
278
|
+
| `web_search` item | `tool_call_start` | Web search metadata |
|
|
279
|
+
| `turn.completed` | Status `completed` | Includes token usage |
|
|
280
|
+
| `turn.failed` | Status `failed` | Sanitized error message |
|
|
281
|
+
| `error` | `agent_error` | Sanitized error message |
|
|
282
|
+
|
|
283
|
+
## Buffered vs Streaming Artifacts
|
|
284
|
+
|
|
285
|
+
By default, `a2a-codex` buffers the full response and publishes a single artifact at completion. This is compatible with the A2A Inspector and most orchestrators.
|
|
286
|
+
|
|
287
|
+
Set `features.streamArtifactChunks: true` (or `STREAM_ARTIFACTS=true`) to stream delta chunks as the model generates them. Use this only if your client handles `append: true` artifact updates correctly.
|
|
288
|
+
|
|
289
|
+
## Cancellation
|
|
290
|
+
|
|
291
|
+
Call `tasks/cancel` (JSON-RPC) or `DELETE /a2a/rest/tasks/{taskId}` to cancel an in-flight task. The executor calls `abortController.abort()` on the Codex `runStreamed` call. Cancellation is idempotent — multiple calls for the same task ID are safe.
|
|
292
|
+
|
|
293
|
+
## Context API
|
|
294
|
+
|
|
295
|
+
| Endpoint | Method | Description |
|
|
296
|
+
|---|---|---|
|
|
297
|
+
| `/context` | `GET` | Read the pre-built `context.md` from the workspace |
|
|
298
|
+
| `/context/build` | `POST` | Trigger a read-only Codex thread to explore and describe the repository; writes `context.md` |
|
|
299
|
+
|
|
300
|
+
POST body (optional): `{ "prompt": "Describe the API layer in detail." }`
|
|
301
|
+
|
|
302
|
+
## CLI Reference
|
|
303
|
+
|
|
304
|
+
```
|
|
305
|
+
Usage: a2a-codex [options]
|
|
306
|
+
|
|
307
|
+
Options:
|
|
308
|
+
--agent-json <path> Path to agent JSON config file (alias: --config)
|
|
309
|
+
--config <path> Path to agent JSON config file (alias: --agent-json)
|
|
310
|
+
--port <number> A2A server port (default: 3020)
|
|
311
|
+
--hostname <addr> Bind address (default: 0.0.0.0)
|
|
312
|
+
--advertise-host <host> Hostname for agent card URLs (default: localhost)
|
|
313
|
+
--workspace <path> Workspace directory (Git repo) (alias: --working-dir)
|
|
314
|
+
--working-dir <path> Workspace directory (Git repo) (alias: --workspace)
|
|
315
|
+
--model <model> Codex model (e.g. o4-mini, gpt-4o)
|
|
316
|
+
--sandbox <mode> Sandbox mode (read-only | workspace-write | danger-full-access)
|
|
317
|
+
--agent-name <name> Agent display name
|
|
318
|
+
--agent-description <desc> Agent description
|
|
319
|
+
--stream-artifacts Stream artifact chunks (spec-correct, streaming clients)
|
|
320
|
+
--no-stream-artifacts Buffer artifacts — Inspector-compatible (default)
|
|
321
|
+
--log-level <level> Log level: debug | info | warn | error (default: info)
|
|
322
|
+
--help Show this help message
|
|
323
|
+
--version Show version
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
## Bundled Example Agents
|
|
327
|
+
|
|
328
|
+
| Config | Port | Description |
|
|
329
|
+
|---|---|---|
|
|
330
|
+
| `agents/example/config.json` | 3020 | Workspace engineer — read + write access |
|
|
331
|
+
| `agents/read-only-reviewer/config.json` | 3022 | Code reviewer — read-only, no file writes |
|
|
332
|
+
| `agents/multi-agent/config.json` | 3021 | Lead engineer — delegates to sub-agents on ports 3010 and 3011 |
|
|
333
|
+
|
|
334
|
+
## Security Boundaries
|
|
335
|
+
|
|
336
|
+
```
|
|
337
|
+
OS / Container boundary
|
|
338
|
+
│
|
|
339
|
+
└─ Codex workspace boundary (sandboxMode)
|
|
340
|
+
│
|
|
341
|
+
└─ Individual MCP server permissions
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
1. **OS / container boundary** — The Docker image runs as a non-root `node` user. For `danger-full-access` mode, use an isolated container or VM with no access to host secrets.
|
|
345
|
+
2. **Codex workspace boundary** — `workspace-write` confines all file operations to `workingDirectory`. `read-only` prevents any writes. Both modes prevent access to directories outside the configured paths.
|
|
346
|
+
3. **MCP server permissions** — Each MCP server runs as a separate process (stdio) or connects to an external endpoint (http). Scope their permissions via the `args`, `env`, and `enabledTools` / `disabledTools` settings.
|
|
347
|
+
|
|
348
|
+
## Docker
|
|
349
|
+
|
|
350
|
+
Build from the **monorepo root** (the image needs local `@a2a-wrapper/core` source):
|
|
351
|
+
|
|
352
|
+
```bash
|
|
353
|
+
docker build -f a2a-codex/Dockerfile -t a2a-codex:latest .
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
**Option A — OpenAI API key (recommended for CI / cloud):**
|
|
357
|
+
|
|
358
|
+
```bash
|
|
359
|
+
docker run -p 3020:3020 \
|
|
360
|
+
-e OPENAI_API_KEY=sk-... \
|
|
361
|
+
-e WORKSPACE_DIR=/workspace \
|
|
362
|
+
-v /host/path/to/repo:/workspace \
|
|
363
|
+
a2a-codex:latest
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
**Option B — ChatGPT subscription (mount local credentials):**
|
|
367
|
+
|
|
368
|
+
```bash
|
|
369
|
+
docker run -p 3020:3020 \
|
|
370
|
+
-e WORKSPACE_DIR=/workspace \
|
|
371
|
+
-e CODEX_MODEL=gpt-5.5 \
|
|
372
|
+
-v ~/.codex:/home/node/.codex \
|
|
373
|
+
-v /host/path/to/repo:/workspace \
|
|
374
|
+
a2a-codex:latest
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
The container runs as the `node` user (`HOME=/home/node`), so `~/.codex` maps to `/home/node/.codex`. Mount read-write (not `:ro`) because the Codex CLI writes session state alongside auth tokens.
|
|
378
|
+
|
|
379
|
+
**Shell sandboxing in Docker:** Codex isolates every shell command it runs using Linux user namespaces via `bwrap` (Bubblewrap). Standard Docker containers disable unprivileged namespaces, so shell tool calls fail unless you add `--privileged` or `--security-opt=seccomp:unconfined`. For local development with a ChatGPT subscription, using `server.sh` directly (without Docker) avoids this constraint entirely.
|
|
380
|
+
|
|
381
|
+
To inject a corporate proxy CA certificate, mount it at `/etc/ssl/certs/corporate-ca.crt` — the entrypoint script merges it with the system CA bundle automatically.
|
|
382
|
+
|
|
383
|
+
## Programmatic API
|
|
384
|
+
|
|
385
|
+
```typescript
|
|
386
|
+
import { createA2AServer, resolveConfig } from "a2a-codex";
|
|
387
|
+
|
|
388
|
+
const config = resolveConfig("agents/example/config.json");
|
|
389
|
+
const handle = await createA2AServer(config);
|
|
390
|
+
|
|
391
|
+
// Graceful shutdown
|
|
392
|
+
process.on("SIGTERM", () => handle.shutdown());
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
Or use the executor directly:
|
|
396
|
+
|
|
397
|
+
```typescript
|
|
398
|
+
import { CodexExecutor, resolveConfig } from "a2a-codex";
|
|
399
|
+
|
|
400
|
+
const config = resolveConfig("agents/example/config.json");
|
|
401
|
+
const executor = new CodexExecutor(config);
|
|
402
|
+
await executor.initialize();
|
|
403
|
+
|
|
404
|
+
// Build a context summary of the repository
|
|
405
|
+
const summary = await executor.buildContext();
|
|
406
|
+
console.log(summary);
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
## Live Smoke Test
|
|
410
|
+
|
|
411
|
+
```bash
|
|
412
|
+
# Start an agent with a test repository
|
|
413
|
+
export OPENAI_API_KEY=sk-...
|
|
414
|
+
export WORKSPACE_DIR=/tmp/test-repo
|
|
415
|
+
git init /tmp/test-repo
|
|
416
|
+
echo "console.log('hello')" > /tmp/test-repo/index.js
|
|
417
|
+
|
|
418
|
+
node dist/cli.js --config agents/read-only-reviewer/config.json &
|
|
419
|
+
SERVER_PID=$!
|
|
420
|
+
|
|
421
|
+
# Wait for startup
|
|
422
|
+
sleep 3
|
|
423
|
+
|
|
424
|
+
# Fetch agent card
|
|
425
|
+
curl -s http://localhost:3022/.well-known/agent-card.json | jq .name
|
|
426
|
+
|
|
427
|
+
# Send a task
|
|
428
|
+
curl -s -X POST http://localhost:3022/a2a/jsonrpc \
|
|
429
|
+
-H "Content-Type: application/json" \
|
|
430
|
+
-d '{"jsonrpc":"2.0","id":1,"method":"message/send","params":{"message":{"kind":"message","messageId":"test-1","role":"user","parts":[{"kind":"text","text":"What does this repository do?"}],"contextId":"ctx-1"}}}' \
|
|
431
|
+
| jq .
|
|
432
|
+
|
|
433
|
+
kill $SERVER_PID
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
Set `RUN_CODEX_INTEGRATION_TESTS=true` to include the live integration test in `npm test`.
|
|
437
|
+
|
|
438
|
+
## Known Limitations
|
|
439
|
+
|
|
440
|
+
- **SSE-only MCP not supported.** MCP servers that only expose an SSE transport cannot be used. Use `stdio` or Streamable HTTP (`type: "http"`) instead.
|
|
441
|
+
- **Interactive approvals not supported.** `approvalPolicy: "on-request"` is rejected at startup. Headless A2A execution cannot present approval prompts to a human. Use `"never"` (default) for automated operation.
|
|
442
|
+
- **Buffered mode is the safe default.** `streamArtifactChunks: false` is the default. Some A2A clients (including the A2A Inspector) work best with complete, non-appending artifacts. Enable streaming only if your client handles `append: true` artifact updates.
|
|
443
|
+
- **MCP config is baked at startup.** MCP servers are registered with the Codex SDK at construction time. Runtime MCP registration is not possible — all servers must be declared in `config.json` before the agent starts.
|
|
444
|
+
- **One thread per A2A context.** Each A2A `contextId` maps to exactly one Codex thread. Turns within a context are serialized. Concurrent turns on the same context are queued, not parallelized.
|
|
445
|
+
- **Docker: shell sandboxing requires elevated privileges.** Codex wraps every shell command in `bwrap` (Bubblewrap), which creates Linux user namespaces. Standard Docker containers block unprivileged namespace creation, so shell tool calls fail inside a container unless you run with `--privileged` or `--security-opt=seccomp:unconfined`. For local development, running with `server.sh` directly (no Docker) is recommended.
|
|
446
|
+
- **ChatGPT subscription: OAuth tokens expire.** When using ChatGPT Plus/Pro authentication (via `codex login`), the tokens in `~/.codex/auth.json` are short-lived. When they expire the agent returns auth errors; re-run `codex login` on the host to refresh. For long-running or unattended deployments, `OPENAI_API_KEY` is more reliable.
|
|
447
|
+
- **ChatGPT subscription: model name is required.** The default model in `~/.codex/config.toml` (set by the desktop app) may differ from models available through the API. Always set `CODEX_MODEL` explicitly (e.g. `gpt-5.5`) when using subscription auth — leaving it unset causes the agent to fall back to the local default, which may be unsupported via the API endpoint.
|
|
448
|
+
|
|
449
|
+
## License
|
|
450
|
+
|
|
451
|
+
[MIT](LICENSE) © Shashi Kanth
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$comment": [
|
|
3
|
+
"Codex-backed A2A workspace engineering agent.",
|
|
4
|
+
"Required environment variables:",
|
|
5
|
+
" OPENAI_API_KEY — your OpenAI API key",
|
|
6
|
+
" WORKSPACE_DIR — absolute path to a Git repository",
|
|
7
|
+
"Optional:",
|
|
8
|
+
" CODEX_MODEL — override the model (e.g. o4-mini, gpt-4o)",
|
|
9
|
+
"Do not store credentials in this file."
|
|
10
|
+
],
|
|
11
|
+
"agentCard": {
|
|
12
|
+
"name": "Codex Workspace Engineer",
|
|
13
|
+
"description": "A repository-scoped software engineering agent backed by OpenAI Codex.",
|
|
14
|
+
"version": "1.0.0",
|
|
15
|
+
"protocolVersion": "0.3.0",
|
|
16
|
+
"streaming": true,
|
|
17
|
+
"defaultInputModes": ["text"],
|
|
18
|
+
"defaultOutputModes": ["text"],
|
|
19
|
+
"skills": [
|
|
20
|
+
{
|
|
21
|
+
"id": "workspace-engineering",
|
|
22
|
+
"name": "Workspace Engineering",
|
|
23
|
+
"description": "Inspect, modify, and validate code within the configured repository.",
|
|
24
|
+
"tags": ["code", "repository", "tests", "refactoring"]
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
"server": {
|
|
29
|
+
"port": 3020,
|
|
30
|
+
"hostname": "0.0.0.0",
|
|
31
|
+
"advertiseHost": "localhost",
|
|
32
|
+
"advertiseProtocol": "http"
|
|
33
|
+
},
|
|
34
|
+
"codex": {
|
|
35
|
+
"workingDirectory": "${WORKSPACE_DIR}",
|
|
36
|
+
"model": "${CODEX_MODEL}",
|
|
37
|
+
"sandboxMode": "workspace-write",
|
|
38
|
+
"approvalPolicy": "never",
|
|
39
|
+
"networkAccessEnabled": false,
|
|
40
|
+
"webSearchMode": "disabled",
|
|
41
|
+
"skipGitRepoCheck": false,
|
|
42
|
+
"additionalDirectories": [],
|
|
43
|
+
"developerInstructions": "Operate only within the configured workspace. Make the smallest safe change. Run relevant tests after edits. Never reveal credentials, environment variables, or internal tool configuration."
|
|
44
|
+
},
|
|
45
|
+
"session": {
|
|
46
|
+
"reuseByContext": true,
|
|
47
|
+
"ttl": 3600000,
|
|
48
|
+
"cleanupInterval": 300000
|
|
49
|
+
},
|
|
50
|
+
"features": {
|
|
51
|
+
"streamArtifactChunks": false,
|
|
52
|
+
"emitReasoningSummaries": true,
|
|
53
|
+
"emitCommandEvents": true,
|
|
54
|
+
"emitFileChangeEvents": true
|
|
55
|
+
},
|
|
56
|
+
"events": {
|
|
57
|
+
"enabled": true,
|
|
58
|
+
"transport": "a2a"
|
|
59
|
+
},
|
|
60
|
+
"timeouts": {
|
|
61
|
+
"prompt": 600000
|
|
62
|
+
},
|
|
63
|
+
"logging": {
|
|
64
|
+
"level": "info"
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
###############################################################################
|
|
3
|
+
# Example Agent — start / stop / status / logs
|
|
4
|
+
#
|
|
5
|
+
# Minimal workspace engineering agent backed by OpenAI Codex.
|
|
6
|
+
# Codex can read and write files inside the workspace directory.
|
|
7
|
+
#
|
|
8
|
+
# Copy this directory to create your own agent:
|
|
9
|
+
# cp -r agents/example agents/my-agent
|
|
10
|
+
#
|
|
11
|
+
# Usage:
|
|
12
|
+
# ./start.sh start — Start the agent in the background
|
|
13
|
+
# ./start.sh stop — Stop the running agent
|
|
14
|
+
# ./start.sh restart — Stop then start
|
|
15
|
+
# ./start.sh status — Show running / stopped status
|
|
16
|
+
# ./start.sh logs — Tail the agent log
|
|
17
|
+
# ./start.sh foreground — Run in the foreground (useful for debugging)
|
|
18
|
+
#
|
|
19
|
+
# Required environment:
|
|
20
|
+
# OPENAI_API_KEY Your OpenAI API key
|
|
21
|
+
#
|
|
22
|
+
# The WORKSPACE_DIR defaults to the workspace/ subdirectory in this agent
|
|
23
|
+
# folder. Override by setting the env variable before calling this script:
|
|
24
|
+
# WORKSPACE_DIR=/my/repo ./start.sh start
|
|
25
|
+
###############################################################################
|
|
26
|
+
|
|
27
|
+
set -euo pipefail
|
|
28
|
+
|
|
29
|
+
AGENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
30
|
+
ROOT_DIR="$(cd "${AGENT_DIR}/../.." && pwd)"
|
|
31
|
+
|
|
32
|
+
# CONFIG_FILE points to this agent's JSON configuration.
|
|
33
|
+
export CONFIG_FILE="${AGENT_DIR}/config.json"
|
|
34
|
+
|
|
35
|
+
# WORKSPACE_DIR is the Git repository Codex operates on.
|
|
36
|
+
# Defaults to the bundled workspace/ directory — replace with a real repo path.
|
|
37
|
+
export WORKSPACE_DIR="${WORKSPACE_DIR:-${AGENT_DIR}/workspace}"
|
|
38
|
+
|
|
39
|
+
exec "${ROOT_DIR}/server.sh" "$@"
|
|
File without changes
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$comment": [
|
|
3
|
+
"Codex-backed lead engineering agent that delegates to specialist A2A sub-agents.",
|
|
4
|
+
"Required: OPENAI_API_KEY, WORKSPACE_DIR",
|
|
5
|
+
"Sub-agents must be running before starting this agent.",
|
|
6
|
+
"Update agentCardUrl values to match your deployed sub-agent addresses."
|
|
7
|
+
],
|
|
8
|
+
"agentCard": {
|
|
9
|
+
"name": "Codex Lead Engineer",
|
|
10
|
+
"description": "A Codex-backed parent agent that coordinates repository analysis and delegates specialist tasks to remote A2A agents.",
|
|
11
|
+
"version": "1.0.0",
|
|
12
|
+
"protocolVersion": "0.3.0",
|
|
13
|
+
"streaming": true,
|
|
14
|
+
"defaultInputModes": ["text"],
|
|
15
|
+
"defaultOutputModes": ["text"],
|
|
16
|
+
"skills": [
|
|
17
|
+
{
|
|
18
|
+
"id": "lead-engineering",
|
|
19
|
+
"name": "Lead Engineering",
|
|
20
|
+
"description": "Coordinate repository analysis and delegate specialist tasks via A2A sub-agents.",
|
|
21
|
+
"tags": ["engineering", "delegation", "a2a", "multi-agent"]
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
},
|
|
25
|
+
"server": {
|
|
26
|
+
"port": 3021,
|
|
27
|
+
"hostname": "0.0.0.0",
|
|
28
|
+
"advertiseHost": "localhost",
|
|
29
|
+
"advertiseProtocol": "http"
|
|
30
|
+
},
|
|
31
|
+
"codex": {
|
|
32
|
+
"workingDirectory": "${WORKSPACE_DIR}",
|
|
33
|
+
"sandboxMode": "workspace-write",
|
|
34
|
+
"approvalPolicy": "never",
|
|
35
|
+
"networkAccessEnabled": false,
|
|
36
|
+
"webSearchMode": "disabled",
|
|
37
|
+
"skipGitRepoCheck": false
|
|
38
|
+
},
|
|
39
|
+
"session": {
|
|
40
|
+
"reuseByContext": true,
|
|
41
|
+
"ttl": 3600000,
|
|
42
|
+
"cleanupInterval": 300000
|
|
43
|
+
},
|
|
44
|
+
"features": {
|
|
45
|
+
"streamArtifactChunks": false,
|
|
46
|
+
"emitReasoningSummaries": true,
|
|
47
|
+
"emitCommandEvents": true,
|
|
48
|
+
"emitFileChangeEvents": true
|
|
49
|
+
},
|
|
50
|
+
"events": {
|
|
51
|
+
"enabled": true,
|
|
52
|
+
"transport": "a2a"
|
|
53
|
+
},
|
|
54
|
+
"timeouts": {
|
|
55
|
+
"prompt": 600000
|
|
56
|
+
},
|
|
57
|
+
"logging": {
|
|
58
|
+
"level": "info"
|
|
59
|
+
},
|
|
60
|
+
"subAgents": {
|
|
61
|
+
"agents": [
|
|
62
|
+
{
|
|
63
|
+
"name": "security",
|
|
64
|
+
"agentCardUrl": "http://localhost:3010/.well-known/agent-card.json"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"name": "test-engineer",
|
|
68
|
+
"agentCardUrl": "http://localhost:3011/.well-known/agent-card.json"
|
|
69
|
+
}
|
|
70
|
+
],
|
|
71
|
+
"options": {
|
|
72
|
+
"responseMode": "artifact",
|
|
73
|
+
"probeTimeoutMs": 5000,
|
|
74
|
+
"syncBudgetMs": 30000
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
###############################################################################
|
|
3
|
+
# Multi-Agent Lead Engineer — start / stop / status / logs
|
|
4
|
+
#
|
|
5
|
+
# Demonstrates the `subAgents` config — a Codex lead engineer that delegates
|
|
6
|
+
# specialist tasks to remote A2A sub-agents (security, test-engineer).
|
|
7
|
+
#
|
|
8
|
+
# Sub-agents must be running before starting this agent:
|
|
9
|
+
# # Start the specialist sub-agents first (on ports 3010 and 3011), then:
|
|
10
|
+
# ./start.sh start
|
|
11
|
+
#
|
|
12
|
+
# Update agentCardUrl values in config.json to match your deployed sub-agent
|
|
13
|
+
# addresses before starting.
|
|
14
|
+
#
|
|
15
|
+
# Usage:
|
|
16
|
+
# ./start.sh start — Start the agent in the background
|
|
17
|
+
# ./start.sh stop — Stop the running agent
|
|
18
|
+
# ./start.sh restart — Stop then start
|
|
19
|
+
# ./start.sh status — Show running / stopped status
|
|
20
|
+
# ./start.sh logs — Tail the agent log
|
|
21
|
+
# ./start.sh foreground — Run in the foreground (useful for debugging)
|
|
22
|
+
#
|
|
23
|
+
# Required environment:
|
|
24
|
+
# OPENAI_API_KEY Your OpenAI API key
|
|
25
|
+
# WORKSPACE_DIR Git repository path (defaults to workspace/ below)
|
|
26
|
+
###############################################################################
|
|
27
|
+
|
|
28
|
+
set -euo pipefail
|
|
29
|
+
|
|
30
|
+
AGENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
31
|
+
ROOT_DIR="$(cd "${AGENT_DIR}/../.." && pwd)"
|
|
32
|
+
|
|
33
|
+
export CONFIG_FILE="${AGENT_DIR}/config.json"
|
|
34
|
+
export WORKSPACE_DIR="${WORKSPACE_DIR:-${AGENT_DIR}/workspace}"
|
|
35
|
+
|
|
36
|
+
exec "${ROOT_DIR}/server.sh" "$@"
|
|
File without changes
|