|
| 1 | +# Flow Codex Interface |
| 2 | + |
| 3 | +## Short Answer |
| 4 | + |
| 5 | +Partly. |
| 6 | + |
| 7 | +Flow does **not** use `codex app-server` for every Codex command. |
| 8 | +There are multiple Codex lanes: |
| 9 | + |
| 10 | +- the normal Flow session lane uses the regular Codex CLI through the Flow wrapper |
| 11 | +- the run-owned agent lane uses `codex app-server` |
| 12 | +- the native commit review lane uses `codex app-server` |
| 13 | +- a few runtime-management helpers also use `codex app-server` |
| 14 | + |
| 15 | +So the right model is: |
| 16 | + |
| 17 | +- `f codex ...` is the user-facing interface |
| 18 | +- underneath, Flow chooses either: |
| 19 | + - wrapped Codex CLI execution |
| 20 | + - or direct `codex app-server` JSON-RPC |
| 21 | + |
| 22 | +## Main Pieces |
| 23 | + |
| 24 | +### 1. Flow wrapper |
| 25 | + |
| 26 | +File: |
| 27 | + |
| 28 | +- `scripts/codex-flow-wrapper` |
| 29 | + |
| 30 | +Role: |
| 31 | + |
| 32 | +- launches the real `codex` binary |
| 33 | +- materializes temporary runtime skills from Flow state |
| 34 | +- cleans those temporary symlinks up after the Codex process exits |
| 35 | + |
| 36 | +Important point: |
| 37 | + |
| 38 | +- this is still the normal Codex CLI, not app-server |
| 39 | + |
| 40 | +### 2. Flow Codex command layer |
| 41 | + |
| 42 | +Primary file: |
| 43 | + |
| 44 | +- `src/ai.rs` |
| 45 | + |
| 46 | +Role: |
| 47 | + |
| 48 | +- implements `f codex open` |
| 49 | +- implements `f codex resolve` |
| 50 | +- implements `f codex doctor` |
| 51 | +- implements session recovery, reference expansion, and runtime-skill planning |
| 52 | +- implements the Flow bridge into run-owned agents |
| 53 | + |
| 54 | +Important point: |
| 55 | + |
| 56 | +- most of this layer is orchestration and context shaping |
| 57 | +- it does not imply app-server by itself |
| 58 | + |
| 59 | +### 3. Flow codexd daemon |
| 60 | + |
| 61 | +Primary file: |
| 62 | + |
| 63 | +- `src/codexd.rs` |
| 64 | + |
| 65 | +Role: |
| 66 | + |
| 67 | +- local Flow daemon for fast repo/session intelligence |
| 68 | +- caches recent queryable state |
| 69 | +- serves project-ai and related lightweight repo intelligence |
| 70 | + |
| 71 | +Important point: |
| 72 | + |
| 73 | +- `codexd` is a Flow daemon |
| 74 | +- it is **not** the Codex app-server |
| 75 | + |
| 76 | +### 4. Run-owned agent runtime |
| 77 | + |
| 78 | +Primary files: |
| 79 | + |
| 80 | +- `~/run/scripts/agent-router.sh` |
| 81 | +- `~/run/scripts/agent-codex-app-server.py` |
| 82 | + |
| 83 | +Role: |
| 84 | + |
| 85 | +- executes spec-backed agents such as `planner`, `commit`, `input`, and `migration-planner` |
| 86 | +- opens or resumes threads |
| 87 | +- sends turns through `codex app-server` |
| 88 | +- persists artifacts, traces, and per-agent state |
| 89 | + |
| 90 | +Important point: |
| 91 | + |
| 92 | +- this lane is app-server-based by design |
| 93 | + |
| 94 | +## Which Paths Use App-Server |
| 95 | + |
| 96 | +### Uses the normal Codex CLI through the Flow wrapper |
| 97 | + |
| 98 | +- `f codex open` |
| 99 | +- `f codex resume` |
| 100 | +- `f codex continue` |
| 101 | +- `f codex connect` |
| 102 | +- normal interactive Codex sessions launched by Flow |
| 103 | + |
| 104 | +How it works: |
| 105 | + |
| 106 | +1. Flow resolves the repo/path and any compact context to inject. |
| 107 | +2. Flow may prepare runtime skill state. |
| 108 | +3. Flow launches the configured Codex binary, usually `scripts/codex-flow-wrapper`. |
| 109 | +4. The wrapper exposes runtime skills and then execs the real `codex`. |
| 110 | + |
| 111 | +### Uses `codex app-server` |
| 112 | + |
| 113 | +- `f codex agent run ...` |
| 114 | +- Flow native commit review |
| 115 | +- Codex skill reload / force-rescan helper paths |
| 116 | +- run-owned spec agents in `~/run` |
| 117 | + |
| 118 | +How it works: |
| 119 | + |
| 120 | +1. Flow or `~/run` spawns `codex app-server`. |
| 121 | +2. It performs the initialize handshake over stdio JSON-RPC. |
| 122 | +3. It creates or resumes a thread. |
| 123 | +4. It sends structured requests such as: |
| 124 | + - `thread/start` |
| 125 | + - `turn/start` |
| 126 | + - `review/start` |
| 127 | + - `skills/list` |
| 128 | +5. It consumes structured events and results. |
| 129 | + |
| 130 | +## Command Surface Breakdown |
| 131 | + |
| 132 | +### `f codex open` |
| 133 | + |
| 134 | +Primary behavior: |
| 135 | + |
| 136 | +- session recovery |
| 137 | +- compact reference expansion |
| 138 | +- runtime-skill activation |
| 139 | +- normal Codex CLI launch |
| 140 | + |
| 141 | +Transport: |
| 142 | + |
| 143 | +- wrapper + standard Codex CLI |
| 144 | + |
| 145 | +Notable files: |
| 146 | + |
| 147 | +- `src/ai.rs` |
| 148 | +- `scripts/codex-flow-wrapper` |
| 149 | + |
| 150 | +### `f codex doctor` |
| 151 | + |
| 152 | +Primary behavior: |
| 153 | + |
| 154 | +- inspect effective Codex config for a repo/path |
| 155 | +- report wrapper/runtime readiness |
| 156 | +- report run-agent bridge readiness |
| 157 | + |
| 158 | +Transport: |
| 159 | + |
| 160 | +- local Flow inspection only |
| 161 | + |
| 162 | +Important point: |
| 163 | + |
| 164 | +- doctor does not require app-server to explain the current configuration |
| 165 | + |
| 166 | +### `f codex agent list` / `show` |
| 167 | + |
| 168 | +Primary behavior: |
| 169 | + |
| 170 | +- inspect the run-owned agent corpus from `~/run` |
| 171 | + |
| 172 | +Transport: |
| 173 | + |
| 174 | +- Flow shells into `~/run/scripts/agent-router.sh` |
| 175 | +- no app-server turn is needed for `list` or `show` |
| 176 | + |
| 177 | +### `f codex agent run <agent-id> ...` |
| 178 | + |
| 179 | +Primary behavior: |
| 180 | + |
| 181 | +- execute a run-owned agent from Flow |
| 182 | + |
| 183 | +Transport: |
| 184 | + |
| 185 | +- Flow -> `~/run/scripts/agent-router.sh run-json` |
| 186 | +- `agent-router.sh` -> `agent-codex-app-server.py` |
| 187 | +- Python runner -> `codex app-server` |
| 188 | + |
| 189 | +Important point: |
| 190 | + |
| 191 | +- this is the main place where the new Flow-to-run bridge is explicitly app-server-based |
| 192 | + |
| 193 | +### `f commit` Codex review lane |
| 194 | + |
| 195 | +Primary behavior: |
| 196 | + |
| 197 | +- review staged or uncommitted changes using the Codex native review path |
| 198 | + |
| 199 | +Transport: |
| 200 | + |
| 201 | +- direct `codex app-server` |
| 202 | +- uses built-in `review/start` |
| 203 | + |
| 204 | +Important point: |
| 205 | + |
| 206 | +- this is a stronger primitive than sending a freeform review prompt through a normal chat turn |
| 207 | + |
| 208 | +## Why Flow Uses More Than One Lane |
| 209 | + |
| 210 | +Because the best transport depends on the job: |
| 211 | + |
| 212 | +- interactive coding sessions are best served by the normal Codex CLI with Flow-managed runtime context |
| 213 | +- structured agent execution needs thread control, event streaming, and durable artifacts, so app-server is the better substrate |
| 214 | +- native code review has a dedicated app-server method, so Flow should use that instead of imitating review in plain text |
| 215 | + |
| 216 | +## Current Mental Model |
| 217 | + |
| 218 | +Use this rule: |
| 219 | + |
| 220 | +- if you are opening or resuming a normal Codex coding session, think "wrapped Codex CLI" |
| 221 | +- if you are running a reusable Flow/run agent or a native review lane, think "`codex app-server`" |
| 222 | + |
| 223 | +That is the current architecture. |
| 224 | + |
| 225 | +It is intentionally hybrid: |
| 226 | + |
| 227 | +- Flow keeps the common path lightweight |
| 228 | +- app-server is reserved for the places where structured threads, structured review, or structured artifacts materially improve the result |
| 229 | + |
| 230 | +## Concrete Examples |
| 231 | + |
| 232 | +### Example 1: normal coding turn |
| 233 | + |
| 234 | +```bash |
| 235 | +f codex open --path ~/code/flow "continue the codex agent rollout" |
| 236 | +``` |
| 237 | + |
| 238 | +Expected transport: |
| 239 | + |
| 240 | +- Flow orchestration |
| 241 | +- wrapper |
| 242 | +- normal Codex CLI |
| 243 | + |
| 244 | +### Example 2: run-owned planning agent |
| 245 | + |
| 246 | +```bash |
| 247 | +f codex agent run planner --path ~/code/flow "make a 3 phase rollout plan" |
| 248 | +``` |
| 249 | + |
| 250 | +Expected transport: |
| 251 | + |
| 252 | +- Flow bridge |
| 253 | +- `~/run` agent router |
| 254 | +- `codex app-server` |
| 255 | + |
| 256 | +### Example 3: commit review |
| 257 | + |
| 258 | +```bash |
| 259 | +f commit --slow --context --codex |
| 260 | +``` |
| 261 | + |
| 262 | +Expected transport: |
| 263 | + |
| 264 | +- Flow review pipeline |
| 265 | +- direct `codex app-server` |
| 266 | +- native `review/start` |
| 267 | + |
| 268 | +## Non-Goals |
| 269 | + |
| 270 | +What this interface is not doing today: |
| 271 | + |
| 272 | +- it is not making every Flow Codex command app-server-only |
| 273 | +- it is not using `codexkit` as the main Flow executor |
| 274 | +- it is not duplicating run-owned agent specs inside Flow |
| 275 | + |
| 276 | +## Summary |
| 277 | + |
| 278 | +Flow's Codex interface is a control-plane interface, not a single transport. |
| 279 | + |
| 280 | +The stable split today is: |
| 281 | + |
| 282 | +- default session UX: wrapped Codex CLI |
| 283 | +- structured agent execution: `codex app-server` |
| 284 | +- native review: `codex app-server` |
| 285 | +- repo intelligence and readiness checks: Flow-local logic plus `codexd` |
0 commit comments