Skip to content

Commit 81321ce

Browse files
committed
docs: align CLI and app-server runtime behavior
1 parent 3145c04 commit 81321ce

2 files changed

Lines changed: 80 additions & 39 deletions

File tree

README.md

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ Key packages:
148148
| :--- | :--- |
149149
| `io.github.easy4j.codex` | `CodexClient`, `CodexClientConfig` |
150150
| `io.github.easy4j.codex.cli` | `CodexCli`, `CodexCliExecutor`, `CodexCliResult` |
151-
| `io.github.easy4j.codex.appserver` | `CodexAppServerClient`, `CodexAppServerConfig`, `AppServerTurnRequest`, `AppServerTurnResult`, `ThreadMappingCache`, `CodexAppServerException` |
151+
| `io.github.easy4j.codex.appserver` | `CodexAppServerClient`, `CodexAppServerConfig`, `AppServerTurnRequest`, `AppServerTurnResult`, `CodexAppServerListener`, `ThreadMappingStore`, `ThreadMappingCache`, `CodexAppServerException` |
152152
| `io.github.easy4j.codex.model` | `CodexEvent`, `CodexSession`, `CodexDoctorReport` |
153153

154154
## 5. Installation
@@ -227,9 +227,17 @@ There is no configuration file of its own. Key fields:
227227
| `dangerouslyBypassHookTrust` | boolean | `false` | Skip hook trust checks |
228228
| `strictConfig` | boolean | `false` | Fail on unknown config fields |
229229
| `enable` / `disable` | String[] | - | Features to enable / disable |
230+
| `noAltScreen` | boolean | `false` | Pass `--no-alt-screen` to default interactive sessions |
231+
232+
Runtime semantics:
233+
- `localProbeTimeoutSeconds` applies only to CLI availability probing; normal commands continue to use `localTimeoutSeconds`.
234+
- `jsonOutput` controls normal `exec` calls; `execAndParse` always forces `--json` because it promises parsed JSONL events.
235+
- `noAltScreen` is propagated through the default interactive-session options.
230236

231237
### 7.1 `CodexAppServerConfig` (app-server WebSocket route)
232238

239+
> Available on `feature/2.0.x` (JDK 17) and `feature/3.0.x` (JDK 21). The JDK 8 `feature/1.0.x` line intentionally remains CLI-only.
240+
233241
> **Upgrade notes (3.0.x.x.20260630+)**: CLI-route arguments are now passed
234242
> to the child process raw — multi-word prompts no longer arrive at `codex`
235243
> wrapped in embedded literal quotes. Non-zero CLI exits now preserve the real
@@ -311,18 +319,32 @@ try (CodexAppServerClient client = new CodexAppServerClient(config)) {
311319
}
312320
```
313321

314-
Lifecycle calls run over a short-lived connection with the documented
315-
tolerant `initialize` handshake; thread state is server-side, so
316-
`steerTurn` / `interruptTurn` work while the original turn connection is
317-
still streaming. Running turns expose their id via
318-
`AppServerTurnRequest.onTurnStarted` and `AppServerTurnResult.getTurnId()`.
319-
320-
The turn maps to `thread/start` (or `thread/resume` when `sessionKey` already
321-
maps to a thread id) → `turn/start``item/completed` (only agent messages
322-
surface) → `turn/completed`. Unknown notifications are logged at debug level
323-
and never interrupt the turn. Failures — connection, JSON-RPC error,
324-
`turn/failed`, `error`, premature close or read timeout — surface as
325-
`CodexAppServerException`.
322+
Each app-server operation currently uses a request-scoped WebSocket connection.
323+
Every connection performs `initialize``notifications/initialized` before
324+
the first business request, and WebSocket writes are serialized so protocol
325+
frames cannot overtake one another. Send failures fail the owning operation
326+
immediately instead of degrading into a later read timeout.
327+
328+
Turns with the same non-blank `sessionKey` are serialized; different session
329+
keys remain concurrent. The default `ThreadMappingCache` is a bounded in-memory
330+
`ThreadMappingStore`; callers that need persistence may inject another store
331+
implementation.
332+
333+
A turn maps to `thread/start` (or `thread/resume`) → `turn/start`
334+
`item/agentMessage/delta` streaming → `turn/completed`. Existing
335+
`onDelta` callbacks now receive real text deltas when the server emits them;
336+
`item/completed` is retained as a compatibility fallback for servers that do
337+
not stream deltas, without duplicating already-streamed text. The additive
338+
`CodexAppServerListener` exposes turn start, text delta, item completion,
339+
token-usage and warning hooks. Running turns expose their id via
340+
`AppServerTurnRequest.onTurnStarted` / the listener and
341+
`AppServerTurnResult.getTurnId()`.
342+
343+
Unknown notifications are logged at debug level and do not interrupt the turn.
344+
Failures — connection, JSON-RPC error, `turn/failed`, `error`, WebSocket send
345+
failure, premature close or read timeout — surface as
346+
`CodexAppServerException`. Successful completion preserves the server's turn
347+
status when present and otherwise uses `completed` as the neutral fallback.
326348

327349
## 9. Testing & Build
328350

@@ -332,21 +354,21 @@ and never interrupt the turn. Failures — connection, JSON-RPC error,
332354

333355
- The build is configured with the JaCoCo Maven plugin (report + `check` goal with a
334356
90% line-coverage rule bound to the `verify` phase; `haltOnFailure=false`).
335-
- The active branch ships a full test suite (206 tests on `feature/3.0.x`), including
336-
end-to-end WebSocket contract tests against an in-process fake app-server.
357+
- Each maintained branch ships its own full test suite; the 2.0.x/3.0.x lines include end-to-end WebSocket contract tests against an in-process fake app-server plus an opt-in real app-server integration test.
337358
- CI workflow: `.github/workflows/ci.yml`.
338359

339360
## 10. Versioning & Branches
340361

341362
| Branch | JDK | Version | Notes |
342363
| :--- | :--- | :--- | :--- |
343-
| `feature/1.0.x` | 8 | `1.0.x.*` | Current branch, JDK 8 baseline, active development |
344-
| `feature/2.0.x` | 17 | `2.0.x.*` | JDK 17 line |
345-
| `feature/3.0.x` | 21 | `3.0.x.*` | JDK 21 line |
346-
347-
Maintenance policy: the `1.0.x` line receives bug fixes and compatibility updates
348-
for the JDK 8 baseline. New features targeting newer JDKs land on the `2.0.x` /
349-
`3.0.x` lines. Releases are published to the Aliyun Maven repository and as
364+
| `feature/1.0.x` | 8 | `1.0.x.*` | CLI compatibility line; no app-server transport |
365+
| `feature/2.0.x` | 17 | `2.0.x.*` | Canonical App Server protocol/behavior line |
366+
| `feature/3.0.x` | 21 | `3.0.x.*` | JDK 21 / Maven 4 / Jackson 3 forward-port line |
367+
368+
Maintenance policy: shared CLI fixes stay aligned across all three lines.
369+
App Server protocol behavior is validated first on `feature/2.0.x` and then
370+
forward-ported to `feature/3.0.x`; the JDK 8 line intentionally remains
371+
CLI-only. Releases are published to the Aliyun Maven repository and as
350372
GitHub Releases; the project is not yet published to Maven Central.
351373

352374
## 11. Contributing & License

README.zh-CN.md

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ SDK 覆盖:
143143
| :--- | :--- |
144144
| `io.github.easy4j.codex` | `CodexClient``CodexClientConfig` |
145145
| `io.github.easy4j.codex.cli` | `CodexCli``CodexCliExecutor``CodexCliResult` |
146-
| `io.github.easy4j.codex.appserver` | `CodexAppServerClient``CodexAppServerConfig``AppServerTurnRequest``AppServerTurnResult``ThreadMappingCache``CodexAppServerException` |
146+
| `io.github.easy4j.codex.appserver` | `CodexAppServerClient``CodexAppServerConfig``AppServerTurnRequest``AppServerTurnResult``CodexAppServerListener``ThreadMappingStore``ThreadMappingCache``CodexAppServerException` |
147147
| `io.github.easy4j.codex.model` | `CodexEvent``CodexSession``CodexDoctorReport` |
148148

149149
## 5. 安装
@@ -221,9 +221,17 @@ public class CodexDemo {
221221
| `dangerouslyBypassHookTrust` | boolean | `false` | 跳过 hook 信任检查 |
222222
| `strictConfig` | boolean | `false` | 遇到未知配置字段即报错 |
223223
| `enable` / `disable` | String[] | - | 启用 / 禁用的 feature |
224+
| `noAltScreen` | boolean | `false` | 默认交互会话传递 `--no-alt-screen` |
225+
226+
运行时语义:
227+
- `localProbeTimeoutSeconds` 只用于 CLI 可用性探测;普通命令继续使用 `localTimeoutSeconds`
228+
- `jsonOutput` 控制普通 `exec` 是否输出 JSON;`execAndParse` 因承诺解析 JSONL,会始终强制 `--json`
229+
- `noAltScreen` 会进入默认交互会话的全局参数。
224230

225231
### 7.1 `CodexAppServerConfig`(app-server WebSocket 路线)
226232

233+
> `feature/2.0.x`(JDK 17)与 `feature/3.0.x`(JDK 21)提供 App Server 路线;JDK 8 的 `feature/1.0.x` 明确保留为 CLI-only。
234+
227235
> **升级注意(3.0.x.x.20260630+)**:CLI 路线的参数改为原样传给子进程——
228236
> 含空格的多词 prompt 不再被塞进字面双引号后发给 `codex`。CLI 非零退出现在
229237
> 保留真实退出码与两路输出,不再折叠为 `exitCode=-1` 加空输出。通过明文
@@ -303,16 +311,27 @@ try (CodexAppServerClient client = new CodexAppServerClient(config)) {
303311
}
304312
```
305313

306-
生命周期调用走短连接并带文档规定的容错 `initialize` 握手;线程状态在
307-
服务端,因此原 turn 连接仍在流式输出时 `steerTurn` / `interruptTurn`
308-
同样可用。运行中的 turn 经 `AppServerTurnRequest.onTurnStarted`
309-
`AppServerTurnResult.getTurnId()` 暴露其 id。
314+
当前每次 app-server 操作都使用请求级 WebSocket 短连接。每条连接都会先完成
315+
`initialize``notifications/initialized`,再发送首个业务请求;同一连接上的
316+
WebSocket 写入严格串行,避免协议帧发生越序。发送失败会立即终止当前操作,不再等到
317+
后续读超时才暴露。
318+
319+
相同且非空的 `sessionKey` 会串行执行,不同 session 仍可并发。默认
320+
`ThreadMappingCache` 是有界内存版 `ThreadMappingStore`;需要跨进程/重启持久化
321+
时可以注入自定义 store 实现。
322+
323+
一个 turn 对应:`thread/start`(或 `thread/resume`)→ `turn/start`
324+
`item/agentMessage/delta` 实时文本流 → `turn/completed`。现有 `onDelta`
325+
在服务器提供真实 delta 时会直接接收增量文本;对不提供 delta 的旧服务器,
326+
`item/completed` 仍作为兼容回退,并避免重复追加已经流式输出的内容。新增的
327+
`CodexAppServerListener` 可监听 turn start、文本 delta、item completed、token usage
328+
和 warning。运行中的 turn id 可通过 `AppServerTurnRequest.onTurnStarted` /
329+
listener 与 `AppServerTurnResult.getTurnId()` 获取。
310330

311-
一个 turn 对应:`thread/start``sessionKey` 已有映射时走 `thread/resume`)→
312-
`turn/start``item/completed`(仅 agent 消息对外呈现)→ `turn/completed`
313-
未知通知只记录 debug 日志,不中断 turn。失败——连接、JSON-RPC 错误、
314-
`turn/failed``error`、提前关闭或读超时——统一以 `CodexAppServerException`
315-
抛出。
331+
未知通知只记录 debug 日志,不中断 turn。连接、JSON-RPC 错误、`turn/failed`
332+
`error`、WebSocket 发送失败、提前关闭或读超时统一以
333+
`CodexAppServerException` 暴露。成功完成时优先保留服务器返回的 turn status;
334+
服务器未提供时使用中性的 `completed`
316335

317336
## 9. 测试与构建
318337

@@ -322,20 +341,20 @@ try (CodexAppServerClient client = new CodexAppServerClient(config)) {
322341

323342
- 构建配置了 JaCoCo Maven 插件(报告 + 绑定在 `verify` 阶段的 `check` 目标,
324343
行覆盖率规则为 90%;`haltOnFailure=false`)。
325-
- 活跃分支自带完整测试套件(`feature/3.0.x` 共 206 个测试),含针对进程内
326-
假 app-server 的端到端 WebSocket 契约测试。
344+
- 各维护分支均有完整测试套件;2.0.x / 3.0.x 还包含进程内假 app-server 的端到端 WebSocket 契约测试,以及默认关闭、按需启用的真实 app-server 集成测试。
327345
- CI 工作流:`.github/workflows/ci.yml`
328346

329347
## 10. 版本与分支
330348

331349
| 分支 | JDK | 版本 | 说明 |
332350
| :--- | :--- | :--- | :--- |
333-
| `feature/1.0.x` | 8 | `1.0.x.*` | 当前分支,JDK 8 基线,活跃开发 |
334-
| `feature/2.0.x` | 17 | `2.0.x.*` | JDK 17 版本线 |
335-
| `feature/3.0.x` | 21 | `3.0.x.*` | JDK 21 版本线 |
351+
| `feature/1.0.x` | 8 | `1.0.x.*` | CLI 兼容线;不提供 app-server transport |
352+
| `feature/2.0.x` | 17 | `2.0.x.*` | App Server 协议/行为 canonical 版本线 |
353+
| `feature/3.0.x` | 21 | `3.0.x.*` | JDK 21 / Maven 4 / Jackson 3 forward-port 版本线 |
336354

337-
维护策略:`1.0.x` 版本线接收针对 JDK 8 基线的缺陷修复与兼容性更新;面向新 JDK 的
338-
新特性在 `2.0.x` / `3.0.x` 版本线开发。发布物通过阿里云 Maven 仓库与 GitHub
355+
维护策略:公共 CLI 修复保持三条版本线一致;App Server 协议行为先在
356+
`feature/2.0.x` 验证,再 forward-port 到 `feature/3.0.x`;JDK 8 版本线明确保持
357+
CLI-only。发布物通过阿里云 Maven 仓库与 GitHub
339358
Releases 分发;项目尚未发布到 Maven Central。
340359

341360
## 11. 贡献与许可

0 commit comments

Comments
 (0)