Skip to content

Commit c7fc311

Browse files
committed
feat(codex): improve session search and workspace tooling
1 parent 9790a40 commit c7fc311

17 files changed

Lines changed: 4309 additions & 179 deletions

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ desktop/.tauri-dev.json
7474
.ai/review-log.jsonl
7575
.rise/
7676
.ai/state.json
77+
.ai/docs/session-changes/
78+
.ai/docs/session-changes-promoted/
7779
.ai/tasks/**/.mooncakes/
7880
.ai/tasks/**/_build/
7981
bench/moon_ffi_boundary/_build/
@@ -90,3 +92,6 @@ docs/commits/*
9092
!docs/commits/
9193
!docs/commits/readme.md
9294
!docs/commits/.gitkeep
95+
96+
# local workspace bootstrap stamp
97+
.flow-workspace-bootstrap.json

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ path = "src/main.rs"
2929
name = "lin"
3030
path = "src/bin/lin.rs"
3131

32+
[[bin]]
33+
name = "flow-workspace-bootstrap"
34+
path = "src/bin/flow-workspace-bootstrap.rs"
35+
3236
[dependencies]
3337
axum = { version = "0.8", default-features = false, features = ["http1", "json", "query", "tokio"] }
3438
tower-http = { version = "0.6", features = ["cors"] }

docs/codex-interface.md

Lines changed: 285 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,285 @@
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`

docs/commands/ai.md

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ Flow reads local session stores, filters by current project path, and gives you
66
When you need to reopen a repo's session from another working directory, use `--path <project-root>` on `resume` or provider-specific `continue`.
77
Cursor transcripts are supported for reading only.
88

9+
Architecture note:
10+
11+
- for the underlying transport split between wrapped Codex CLI, `codexd`, and `codex app-server`, see `docs/codex-interface.md`
12+
913
## Quick Start
1014

1115
```bash
@@ -27,6 +31,12 @@ f ai claude resume <session-id-or-name>
2731
f ai codex resume <session-id-or-name>
2832
f ai codex resume --path ~/work/example-project
2933
f ai codex continue --path ~/work/example-project
34+
f ai codex find --path ~/repos/openai/codex "where does codex store"
35+
f ai codex find --all-history --path ~/repos/openai/codex "older migration plan"
36+
f ai codex find --recent-days 30 --path ~/repos/openai/codex "thread/read"
37+
f ai codex find --json --limit 5 --path ~/repos/openai/codex "thread/read"
38+
f codex connect --path ~/repos/openai/codex --exact-cwd --json "app-server"
39+
f codex connect --all-history --path ~/repos/openai/codex "old designer cutover"
3040
f ai cursor context - /path/to/repo 3
3141
f cursor copy
3242

@@ -101,6 +111,39 @@ Behavior:
101111
This keeps prompt cost flat unless Flow has a strong reason to recover or unroll context.
102112
Use `f codex doctor` to confirm whether wrapper transport, runtime skills, and context budgets are actually active for the current repo.
103113

114+
### Codex connect and find
115+
116+
`f codex connect` and `f ai codex find` now use a Flow-managed local session-search index before
117+
falling back to direct SQLite/transcript scans. The index is repo-scoped at query time, rebuilt
118+
from the Codex state DB when needed, and keeps transcript snippets for better recall on natural
119+
language queries.
120+
121+
By default, search now prefers sessions from roughly the last 7 days for faster and more accurate
122+
ranking on active work, then automatically widens back to the full session history when the recent
123+
window looks weak or sparse.
124+
125+
Useful commands:
126+
127+
```bash
128+
f codex connect --path ~/repos/openai/codex --exact-cwd "app-server"
129+
f codex connect --path ~/repos/openai/codex --exact-cwd --json "thread/read"
130+
f codex connect --all-history --path ~/repos/openai/codex "old migration plan"
131+
f ai codex find --path ~/repos/openai/codex "where does codex store"
132+
f ai codex find --recent-days 30 --path ~/repos/openai/codex "thread/read"
133+
f ai codex find --json --limit 5 --path ~/repos/openai/codex "where does codex store"
134+
```
135+
136+
Behavior:
137+
138+
- `connect` stays the interactive handoff path and returns the exact session match
139+
- `connect --json` prints the selected session instead of attaching
140+
- `find` still resumes the top hit
141+
- `find --json` is read-only and prints ranked candidates for inspection/eval work
142+
- by default both commands prefer the last 7 days first, then widen if the recent window is weak
143+
- use `--recent-days <N>` to widen the preferred recent window without fully disabling recency bias
144+
- use `--all-history` to search the full history immediately
145+
- if confidence is weak or the index misses, Flow still falls back to the older metadata and transcript paths instead of silently opening an arbitrary session
146+
104147
### Codex sessions after a crash or restart
105148

106149
If your Mac restarts and you lose the live Codex terminals, use:
@@ -234,8 +277,8 @@ cat <<'EOF' | f codex runtime write-plan --title "Example Plan"
234277
EOF
235278
```
236279

237-
By default this writes to today's `~/plan/<day-of-month>/` bucket, for example
238-
`~/plan/23/` on the 23rd day of the month.
280+
By default this writes to today's `~/docs/plan/<day-of-month>/` bucket, for
281+
example `~/docs/plan/23/` on the 23rd day of the month.
239282

240283
### Run-owned agent bridge
241284

0 commit comments

Comments
 (0)