claude2codex 0.3.1 → 0.3.3

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 CHANGED
@@ -12,14 +12,15 @@ One real contract round-trip, recorded live: Claude drafts the Goal Contract, `c
12
12
 
13
13
  *Real Codex run (13k tokens, 50s), waits compressed. Replay in your terminal: `asciinema play demo/demo.cast`*
14
14
 
15
- ## The Idea
15
+ ## Why
16
16
 
17
- Software development has distinct roles: **planning** what to build, **building** it, and **reviewing** the result. This project splits those roles between two AI agents:
17
+ In 2025, AI-assisted coding meant writing detailed prompts that told the model *how* to implement things — which files to edit, what patterns to follow, sometimes nearly pseudocode. The engineer was a director; the AI was a typist that needed constant guidance.
18
18
 
19
- - **Claude Code** — the architect and reviewer. Plans the work, writes specifications, reviews results.
20
- - **OpenAI Codex** — the implementer. Receives specifications, writes code, runs tests, reports back.
19
+ That has changed. In 2026, models are [strong enough at implementation](https://www.anthropic.com/institute/recursive-self-improvement) that micromanaging the how is no longer the best use of a human's time. The bottleneck has shifted: when implementation is cheap, the expensive mistakes are **defining the wrong problem** and **failing to catch a bad result**. Getting the implementation steps right matters far less than getting the goal right.
21
20
 
22
- You (the user) are the **commander** — you decide what to build and give final approval. Claude drafts the plan, Codex executes it, Claude verifies the output.
21
+ This is why Goal Contracts are structured the way they are. They don't explain how to write the code — they define **what the code must do** (the Goal), **what to avoid** (Constraints), and **how to prove it worked** (Success Conditions). The engineer's role becomes problem definition, context provision, and verification — the same things that make a good engineering manager effective at delegation.
22
+
23
+ This project is built on that premise: split planning and review (where human judgment still dominates) from implementation (where models now excel), and connect them with a contract format that forces clarity on the parts that matter most.
23
24
 
24
25
  ```mermaid
25
26
  flowchart LR
@@ -30,6 +31,10 @@ flowchart LR
30
31
  Claude -.->|Delta Contract if review fails| Codex
31
32
  ```
32
33
 
34
+ - **You** — decide what to build and give final approval.
35
+ - **Claude Code** — the architect and reviewer. Defines the problem, writes the contract, verifies the result.
36
+ - **OpenAI Codex** — the implementer. Receives the contract, writes code, runs tests, reports back.
37
+
33
38
  ## What is a Goal Contract?
34
39
 
35
40
  A Goal Contract is a structured specification that tells Codex *exactly* what to build. It has three parts:
@@ -125,6 +130,63 @@ Add to your Claude Code MCP settings:
125
130
  }
126
131
  ```
127
132
 
133
+ ### Workflow Prompt (automatic)
134
+
135
+ The server registers an MCP Prompt (`c2c-workflow`) that teaches Claude the full contract workflow — role assignment, Goal/Delta Contract formats, review protocol. **This is loaded automatically when the MCP server is connected.** No extra installation needed.
136
+
137
+ ### Project Setup: CLAUDE.md and AGENTS.md
138
+
139
+ The MCP server handles the workflow protocol. Your project files only need to carry **project-specific context** — don't repeat what the server already provides.
140
+
141
+ **`CLAUDE.md`** (for Claude — the architect/reviewer):
142
+
143
+ ```markdown
144
+ # Claude Code Guidelines
145
+
146
+ The contract workflow is delivered by the MCP Prompt `c2c-workflow`.
147
+
148
+ ## Session Startup
149
+ Read README.md and docs/design.md at session start.
150
+
151
+ ## Review Additions
152
+ - Flag security issues (OWASP top 10).
153
+ - Run integration tests against staging after each task.
154
+
155
+ ## Constraints
156
+ - Do not modify migrations without explicit approval.
157
+ ```
158
+
159
+ **`AGENTS.md`** (for Codex — the implementer):
160
+
161
+ ```markdown
162
+ # Codex Guidelines
163
+
164
+ You are the implementer. The contract protocol is delivered by the c2c bridge.
165
+
166
+ ## Toolchain
167
+ Python 3.12, Poetry. Run from project root.
168
+ - `poetry run pytest` — test suite
169
+ - `poetry run ruff check .` — lint
170
+ - `poetry run mypy .` — typecheck
171
+
172
+ ## Boundaries
173
+ - Do not modify alembic migrations directly.
174
+ - Do not add runtime dependencies without a contract constraint.
175
+ ```
176
+
177
+ **What goes where:**
178
+
179
+ | | MCP server (automatic) | CLAUDE.md | AGENTS.md |
180
+ |---|---|---|---|
181
+ | Role definition | ✓ | — | — |
182
+ | Workflow steps | ✓ | — | — |
183
+ | Contract formats | ✓ | — | — |
184
+ | Review protocol | ✓ | — | — |
185
+ | Session startup | — | ✓ | ✓ |
186
+ | Project-specific review rules | — | ✓ | — |
187
+ | Toolchain & build commands | — | — | ✓ |
188
+ | File/dependency boundaries | — | — | ✓ |
189
+
128
190
  ## Tools Provided
129
191
 
130
192
  | Tool | Description |
package/README.zh-CN.md CHANGED
@@ -6,20 +6,21 @@
6
6
 
7
7
  ## 演示
8
8
 
9
- 一次真实的契约往返实录:Claude 起草 Goal Contract,`codex_estimate` 预估成本,Codex 在 goal loop 下自主实现(`codex_status` 实时流式进度),最后 Claude 独立复核 handoff。
9
+ 一次完整的workflow实践过程:Claude 起草 Goal Contract,`codex_estimate` 预估成本,Codex 在 goal loop 下自主实现(`codex_status` 实时流式进度),最后 Claude 独立复核 handoff。
10
10
 
11
11
  ![c2c 演示 — 完整的 Claude→Codex 契约往返](./demo/demo.gif)
12
12
 
13
- *真实 Codex 运行(13k tokens,50 秒),等待时间已压缩。终端回放:`asciinema play demo/demo.cast`*
13
+ *Codex 运行(13k tokens,50 秒),等待时间已压缩。终端回放:`asciinema play demo/demo.cast`*
14
14
 
15
- ## 核心理念
15
+ ## 为什么做这个项目
16
16
 
17
- 软件开发有不同的角色:**规划**做什么、**动手**写代码、**审查**结果。本项目把这些角色分配给两个 AI 智能体:
17
+ 2025 年,AI 辅助编程的主流方式是写详细的 prompt 告诉模型*怎么*实现——改哪些文件、用什么模式、有时候几乎是伪代码。工程师是导演,AI 是需要不断指导的执行者。
18
18
 
19
- - **Claude Code** — 架构师和审查者。制定计划,撰写规格说明,审查产出。
20
- - **OpenAI Codex** — 实现者。接收规格说明,编写代码,运行测试,报告结果。
19
+ 这已经变了。2026 年,模型的[实现能力已经足够强](https://www.anthropic.com/institute/recursive-self-improvement),事无巨细地指挥"怎么写"不再是人最好的时间投入方式。瓶颈转移了:当实现变得廉价,真正昂贵的错误是**定义了错误的问题**和**没有验收出坏的结果**。把实现步骤写对,远不如把目标定义对重要。
21
20
 
22
- 你(用户)是**指挥官** — 决定做什么并给最终批准。Claude 起草方案,Codex 执行,Claude 核验产出。
21
+ 这就是为什么 Goal Contract 被设计成这样。它不解释怎么写代码——它定义**代码必须做到什么**(Goal),**要避免做什么**(Constraints)和**怎么证明做对了**(Success Conditions)。工程师的角色变成了问题定义、上下文补充和验收——和一个好的工程管理者委派任务时做的事情一样。
22
+
23
+ 这个项目建立在这个前提上:把规划和审查(人的判断力仍然占主导)与实现(模型已经足够强)分开,用一种契约格式把它们连接起来,迫使工程师在最重要的部分(问题定义和验收标准)上做到清晰。
23
24
 
24
25
  ```mermaid
25
26
  flowchart LR
@@ -30,6 +31,10 @@ flowchart LR
30
31
  Claude -.->|Delta Contract 修正| Codex
31
32
  ```
32
33
 
34
+ - **你** — 决定做什么,给最终批准。
35
+ - **Claude Code** — 架构师和审查者。定义问题,撰写契约,验证结果。
36
+ - **OpenAI Codex** — 实现者。接收契约,编写代码,运行测试,报告结果。
37
+
33
38
  ## 什么是 Goal Contract(目标契约)?
34
39
 
35
40
  Goal Contract 是一份结构化规格说明,精确告诉 Codex **要做什么**。它由三部分组成:
@@ -125,6 +130,63 @@ npx claude2codex
125
130
  }
126
131
  ```
127
132
 
133
+ ### 工作流 Prompt(自动)
134
+
135
+ 服务器注册了一个 MCP Prompt(`c2c-workflow`),教 Claude 完整的契约工作流——角色分配、Goal/Delta Contract 格式、审查协议。**连接 MCP 服务器后自动加载。** 无需额外安装。
136
+
137
+ ### 项目配置:CLAUDE.md 和 AGENTS.md
138
+
139
+ MCP 服务器负责工作流协议。你的项目文件只需要放**项目特有的上下文**——不要重复服务器已经提供的内容。
140
+
141
+ **`CLAUDE.md`**(给 Claude——架构师/审查者):
142
+
143
+ ```markdown
144
+ # Claude Code Guidelines
145
+
146
+ 契约工作流由 MCP Prompt `c2c-workflow` 提供。
147
+
148
+ ## 会话启动
149
+ 开始时阅读 README.md 和 docs/design.md。
150
+
151
+ ## 审查补充
152
+ - 标记安全问题(OWASP top 10)。
153
+ - 每个任务完成后跑一遍 staging 的集成测试。
154
+
155
+ ## 约束
156
+ - 未经明确批准不得修改 migrations。
157
+ ```
158
+
159
+ **`AGENTS.md`**(给 Codex——实现者):
160
+
161
+ ```markdown
162
+ # Codex Guidelines
163
+
164
+ 你是实现者。契约协议由 c2c bridge 提供。
165
+
166
+ ## 工具链
167
+ Python 3.12,Poetry。从项目根目录运行。
168
+ - `poetry run pytest` — 测试套件
169
+ - `poetry run ruff check .` — 代码检查
170
+ - `poetry run mypy .` — 类型检查
171
+
172
+ ## 边界
173
+ - 不要直接修改 alembic migrations。
174
+ - 未经合同约束不得添加运行时依赖。
175
+ ```
176
+
177
+ **什么放哪里:**
178
+
179
+ | | MCP 服务器(自动) | CLAUDE.md | AGENTS.md |
180
+ |---|---|---|---|
181
+ | 角色定义 | ✓ | — | — |
182
+ | 工作流步骤 | ✓ | — | — |
183
+ | 契约格式 | ✓ | — | — |
184
+ | 审查协议 | ✓ | — | — |
185
+ | 会话启动 | — | ✓ | ✓ |
186
+ | 项目特有的审查规则 | — | ✓ | — |
187
+ | 工具链与构建命令 | — | — | ✓ |
188
+ | 文件/依赖边界 | — | — | ✓ |
189
+
128
190
  ## 提供的工具
129
191
 
130
192
  | 工具 | 说明 |
package/dist/server.js CHANGED
@@ -137,6 +137,11 @@ var CodexAppServer = class {
137
137
  stderrTail = [];
138
138
  exitError;
139
139
  exited = false;
140
+ /**
141
+ * Spawns a new Codex child process and sets up event listeners for stdout and stderr streams.
142
+ *
143
+ * @param opts - Configuration options specifying executable path, arguments, environment, and event callbacks
144
+ */
140
145
  constructor(opts) {
141
146
  this.opts = opts;
142
147
  this.proc = spawn(opts.bin, opts.args, {
@@ -158,6 +163,12 @@ var CodexAppServer = class {
158
163
  this.handleExit(null, new Error(`failed to spawn ${opts.bin}: ${err.message}`));
159
164
  });
160
165
  }
166
+ /**
167
+ * Handles Codex child process termination or spawn failure, rejecting pending requests and notifying listeners.
168
+ *
169
+ * @param code - Exit code of the child process, or null if terminated abnormally
170
+ * @param error - Error instance causing process exit, if any (optional)
171
+ */
161
172
  handleExit(code, error) {
162
173
  if (this.exited) return;
163
174
  this.exited = true;
@@ -172,6 +183,11 @@ var CodexAppServer = class {
172
183
  this.pending.clear();
173
184
  this.opts.onExit?.(code, this.exitError);
174
185
  }
186
+ /**
187
+ * Parses a single output line received from Codex stdout and dispatches it as a request response or notification.
188
+ *
189
+ * @param line - Raw text line emitted by the child process stdout
190
+ */
175
191
  handleLine(line) {
176
192
  const trimmed = line.trim();
177
193
  if (!trimmed) return;
@@ -199,10 +215,23 @@ var CodexAppServer = class {
199
215
  this.opts.onNotification?.(msg.method, msg.params);
200
216
  }
201
217
  }
218
+ /**
219
+ * Serializes an object to JSON and writes it to the child process's standard input stream.
220
+ *
221
+ * @param obj - Object to send to the child process
222
+ */
202
223
  send(obj) {
203
224
  if (this.exited) return;
204
225
  this.proc.stdin.write(JSON.stringify(obj) + "\n");
205
226
  }
227
+ /**
228
+ * Sends a correlated JSON-RPC request to Codex and returns a Promise that resolves with the response or times out.
229
+ *
230
+ * @param method - RPC method name to invoke
231
+ * @param params - Optional parameter object passed with the request
232
+ * @param timeoutMs - Maximum time to wait for a response in milliseconds, defaulting to 60,000ms
233
+ * @returns Promise resolving with the response result
234
+ */
206
235
  request(method, params, timeoutMs = 6e4) {
207
236
  if (this.exited) {
208
237
  return Promise.reject(this.exitError ?? new Error("codex app-server is not running"));
@@ -217,17 +246,31 @@ var CodexAppServer = class {
217
246
  this.send({ id, method, ...params !== void 0 ? { params } : {} });
218
247
  });
219
248
  }
249
+ /**
250
+ * Sends a one-way notification message to Codex without waiting for a response.
251
+ *
252
+ * @param method - Notification method name
253
+ * @param params - Optional parameter object passed with the notification
254
+ */
220
255
  notify(method, params) {
221
256
  this.send({ method, ...params !== void 0 ? { params } : {} });
222
257
  }
258
+ /**
259
+ * Sends the initial handshake request to Codex and emits the initialized notification upon response.
260
+ *
261
+ * @returns Promise resolving with the server initialization response payload
262
+ */
223
263
  async initialize() {
224
264
  const result = await this.request("initialize", {
225
- clientInfo: { name: "claude2codex", title: "Claude\u2194Codex Contract Bridge", version: "0.3.1" },
265
+ clientInfo: { name: "claude2codex", title: "Claude\u2194Codex Contract Bridge", version: "0.3.3" },
226
266
  capabilities: { experimentalApi: true }
227
267
  });
228
268
  this.notify("initialized", {});
229
269
  return result;
230
270
  }
271
+ /**
272
+ * Gracefully terminates the running Codex child process via SIGTERM signal.
273
+ */
231
274
  kill() {
232
275
  if (!this.exited) this.proc.kill("SIGTERM");
233
276
  }
@@ -291,8 +334,24 @@ function createJobStore(dir = defaultStateDir()) {
291
334
  warnOnce(error);
292
335
  }
293
336
  return {
337
+ /**
338
+ * Retrieves a job from memory by its unique identifier.
339
+ *
340
+ * @param id - Unique job identifier to look up
341
+ * @returns The matching Job object, or undefined if not found
342
+ */
294
343
  getJob: (id) => records.get(id),
344
+ /**
345
+ * Returns a list of all currently cached jobs.
346
+ *
347
+ * @returns Array of cached Job objects
348
+ */
295
349
  listJobs: () => [...records.values()],
350
+ /**
351
+ * Persists job state and transcript history to memory cache and atomic disk storage.
352
+ *
353
+ * @param job - Job object to be saved
354
+ */
296
355
  save(job) {
297
356
  const record = { ...job, transcript: job.transcript.slice(-200) };
298
357
  records.set(job.id, record);
@@ -871,7 +930,7 @@ function textResult(obj, isError = false) {
871
930
  isError
872
931
  };
873
932
  }
874
- var server = new McpServer({ name: "c2c-codex", version: "0.3.1" });
933
+ var server = new McpServer({ name: "c2c-codex", version: "0.3.3" });
875
934
  var reasoningEffort = z.enum(["low", "medium", "high", "xhigh", "max", "ultra"]);
876
935
  var contextFiles = z.array(z.object({
877
936
  path: z.string().min(1),
@@ -1124,5 +1183,66 @@ server.registerTool(
1124
1183
  });
1125
1184
  }
1126
1185
  );
1186
+ server.registerPrompt("c2c-workflow", {
1187
+ description: "Delegate implementation to Codex via Goal Contracts. Draft, send, poll, review, rework."
1188
+ }, () => ({
1189
+ messages: [{
1190
+ role: "user",
1191
+ content: { type: "text", text: `
1192
+ You are the **architect and reviewer**. Codex is the **implementer**. You draft contracts, delegate via the \`codex\` MCP server, and review the output. You do not implement the task yourself.
1193
+
1194
+ If \`codex_config\` errors, tell the user to install the MCP server (npm: \`claude2codex\`).
1195
+
1196
+ ## Workflow
1197
+
1198
+ 1. **User decides** what to build or fix.
1199
+ 2. **You draft a Goal Contract** (format below). Show it to the user for approval.
1200
+ 3. **You send it** \u2014 \`codex_estimate\` to check budget, then \`codex_implement\`.
1201
+ 4. **You poll** \u2014 \`codex_status\` until terminal. Report progress to the user.
1202
+ 5. **You review** \u2014 \`codex_result\` for the handoff, then verify independently (see Review below).
1203
+ 6. **User approves** your findings.
1204
+
1205
+ If review fails \u2192 draft a **Delta Contract** \u2192 \`codex_rework\` (same \`job_id\`, thread resumes) \u2192 re-enter at step 4.
1206
+
1207
+ ## Goal Contract
1208
+
1209
+ \`\`\`
1210
+ ### Goal
1211
+ What the code must do. First sentence = acceptance test in prose.
1212
+
1213
+ ### Constraints
1214
+ Only what Codex would get wrong without being told. One line of
1215
+ "only modify files needed for this task" covers the rest.
1216
+
1217
+ ### Success Conditions
1218
+ - [ ] Assertions, not paragraphs. At least one is a command whose exit code decides.
1219
+ - [ ] Handoff includes: Changed Files, Validation, Success Conditions, Risks & Deviations.
1220
+ \`\`\`
1221
+
1222
+ **Write lean contracts.** Goal and Success Conditions are what Codex acts on. Constraints are for genuine risks only \u2014 don't front-load your review checklist into the contract.
1223
+
1224
+ ## Delta Contract
1225
+
1226
+ \`\`\`
1227
+ ### Findings
1228
+ - What is wrong, with file/line references.
1229
+
1230
+ ### Failed Success Conditions
1231
+ - [ ] The specific conditions that did not pass.
1232
+
1233
+ ### Constraints
1234
+ - Original constraints still apply. Fix only the findings; do not touch work that passed.
1235
+ \`\`\`
1236
+
1237
+ ## Review
1238
+
1239
+ 1. Handoff must be complete (all four sections). Missing handoff = review failure.
1240
+ 2. Re-run every verification command yourself \u2014 do not trust the handoff's claims.
1241
+ 3. Run the project's own typecheck/build/test/lint.
1242
+ 4. Flag security issues and constraint violations.
1243
+ 5. Report findings to the user. Fix small issues (typos, imports) directly; do not rewrite the implementation.
1244
+ ` }
1245
+ }]
1246
+ }));
1127
1247
  var transport = new StdioServerTransport();
1128
1248
  await server.connect(transport);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude2codex",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "type": "module",
5
5
  "description": "MCP server bridging Claude (architect/reviewer) and Codex (implementer) via Goal/Delta Contracts and Codex's thread-goal loop.",
6
6
  "bin": {