@usulpro/codex-bee 0.1.1

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 ADDED
@@ -0,0 +1,535 @@
1
+ # codex-bee
2
+
3
+ `codex-bee` is an autonomous wrapper around Codex CLI. The goal is to keep the standard Codex terminal experience intact while adding opt-in continuation modes driven by Stop hooks.
4
+
5
+ When installed globally, the command surface is `bee`.
6
+
7
+ The preferred launch contract is:
8
+
9
+ ```bash
10
+ bee <command> [command args]
11
+ ```
12
+
13
+ The primary target is still Codex-compatible CLIs, so the common form is:
14
+
15
+ ```bash
16
+ bee codex [codex args]
17
+ ```
18
+
19
+ The wrapper also accepts the explicit separator form:
20
+
21
+ ```bash
22
+ bee [wrapper options] -- <command> [command args]
23
+ ```
24
+
25
+ ## Status
26
+
27
+ The interactive PTY baseline is live. The wrapper now boots Codex inside a PTY, keeps the normal terminal workflow visible to the user, validates the effective `codex_hooks` feature and required `SessionStart` / `UserPromptSubmit` / `Stop` hook config before starting an interactive Codex session, can bootstrap the global `~/.codex/hooks.json` hook file when it is missing, writes hook captures back into the live session workspace even when the hook script comes from a global install, surfaces a truthful early session state by moving from `Hooks ready` to `Connected` on `SessionStart` and to a running turn on `UserPromptSubmit`, supports zero-delay one-shot continuation prompts, supports guarded repeat loops with configurable max-injection and max-duration limits, renders continuation prompt templates from Stop payload data on each matched turn, exposes safer helper placeholders for previous assistant messages, supports file-based continuation templates for longer prompts, injects continuation text through bracketed paste so multiline prompts stay intact, exposes a first control overlay checkpoint behind `Ctrl+B`, records runtime events for overlay and watcher activity, includes a first isolated bee-agent continuation mode backed by `codex exec`, bounded transcript context, persistent session notes, and an optional verification-command gate that can stop auto-continue when checks pass or append failing check output to the next injected prompt, and now includes explicit automated coverage plus a review harness for concurrent same-sandbox wrapper runs.
28
+
29
+ ## Project goals
30
+
31
+ - Preserve the native Codex TUI by running Codex inside a PTY wrapper.
32
+ - Detect completed turns through Codex Stop hooks.
33
+ - Forward hook payloads to a wrapper process through an IPC transport that can support multiple parallel sessions.
34
+ - Decide whether to continue automatically, then inject the next prompt back into the PTY.
35
+
36
+ ## Parallel session isolation
37
+
38
+ Parallel wrapper sessions are keyed by a per-process `CODEX_BEE_RUN_ID`, not only by the working directory.
39
+ This matters when multiple `bee codex ...` sessions share the same sandbox, the same repository, or even the same shell location.
40
+
41
+ Current isolation guarantees:
42
+
43
+ - every wrapper run gets its own random run ID
44
+ - the Stop-capture watcher matches captures by both `cwd` and `CODEX_BEE_RUN_ID`
45
+ - runtime events in `.codex/tmp/bee-events.jsonl` are tagged with `runId`
46
+ - startup no longer wipes shared Stop captures, because that broke concurrent runs by deleting evidence that belonged to another live wrapper
47
+
48
+ `last-stop-capture.json` is still a shared convenience pointer inside one sandbox, so it should be treated as "latest overall capture", not "latest capture for my specific run".
49
+ For parallel debugging, prefer `./bee-inspect-events --all` and the full `stop-captures/` directory.
50
+
51
+ ## Planned architecture
52
+
53
+ - `src/cli.ts`: CLI entry point and process bootstrap.
54
+ - `src/auto-continue.ts`: Stateful continuation controller and guardrails.
55
+ - `src/pty-proxy.ts`: PTY spawn, terminal passthrough, and buffered output while the overlay is open.
56
+ - `src/hook-server.ts`: IPC listener for hook payload delivery.
57
+ - `src/continuation.ts`: Continuation decision engine.
58
+ - `src/continuation-watcher.ts`: Stop-capture watcher loop and prompt injection orchestration.
59
+ - `src/bee-agent.ts`: Bee-agent config loading, bounded context packaging, notes persistence, and isolated generator execution.
60
+ - `src/transcript.ts`: Transcript parsing for recent user and assistant turns plus token-count snapshots.
61
+ - `src/verification.ts`: Verification-command execution plus prompt-safe failure summaries.
62
+ - `src/overlay.ts`: Runtime control overlay for prompt and guardrails.
63
+ - `src/runtime-log.ts`: JSONL runtime event logging for live debugging.
64
+ - `hooks/stop-hook.cjs`: Standalone CommonJS hook script that must remain runnable without a build step.
65
+
66
+ ## Requirements
67
+
68
+ - Node.js 20+
69
+ - pnpm 10+
70
+ - Codex CLI installed and authenticated on the target machine
71
+
72
+ The repository now pins the development floor with [`.nvmrc`](/home/usulpro/projects/PrimeUI/open/codex-bee/.nvmrc), so `nvm use` is the expected local bootstrap path.
73
+
74
+ ## Scripts
75
+
76
+ - `pnpm baseline:clear`: Remove stored local Stop hook captures
77
+ - `pnpm baseline:inspect`: Print a summary of the latest local Stop hook capture
78
+ - `pnpm build`: Bundle the CLI with `tsup`
79
+ - `pnpm dev`: Watch-mode build
80
+ - `pnpm package:check`: Pack the project, install the tarball into a temporary prefix, and smoke-test the installed CLI
81
+ - `pnpm publish:local`: Typecheck, pack, smoke-test, and install the tarball globally for local CLI testing
82
+ - `pnpm sandbox:clean`: Remove the disposable live-test sandbox from `CODEX_BEE_SANDBOX_DIR`
83
+ - `pnpm sandbox:prepare`: Recreate the disposable live-test sandbox and its local hook harness
84
+ - `pnpm test`: Run focused automated coverage for continuation rendering, bee-agent context packing, and CLI parsing
85
+ - `pnpm typecheck`: Run TypeScript without emitting files
86
+ - `pnpm ui:demo`: Run the standalone Ink control UI against a mocked runtime host
87
+ - `pnpm ui:dev`: Run the standalone Ink control UI in watch mode for fast iteration
88
+ - `pnpm ui:test`: Run focused UI tests for the renderer-agnostic controller, mocked runtime, and Ink renderer smoke path
89
+
90
+ ## Notes
91
+
92
+ - The hook script in `hooks/stop-hook.cjs` is intentionally plain CommonJS so it can run directly from Codex hooks without depending on the project build.
93
+ - The IPC mechanism is still intentionally undecided until the baseline experiments validate env propagation, process tree behavior, and hook payload shape.
94
+ - Prefer live hook experiments inside the disposable sandbox harness during development, but interactive `bee codex ...` runs now validate and can bootstrap the global `~/.codex/hooks.json` hook file plus the effective `codex_hooks` feature when you launch outside the sandbox.
95
+ - When auto-continue is disabled and stdin/stdout are not TTYs, `bee codex ...` now falls back to direct inherited-stdio passthrough instead of failing on the PTY requirement. This keeps commands such as `bee codex --help` and `bee codex exec ...` usable in non-interactive environments.
96
+ - `--verify-command` currently uses a shell command string (`sh -lc ...`) and is intentionally CLI-first. It is designed for mechanical checks such as `pnpm typecheck`, `pnpm test`, `npm run build`, or `git diff --quiet`.
97
+
98
+ ## Packaging
99
+
100
+ `prepack` now runs `pnpm build`, so `npm pack` and `npm publish` no longer depend on a manual build step.
101
+
102
+ For a reproducible package smoke check that does not rely on Volta global shims, prefer:
103
+
104
+ ```bash
105
+ pnpm package:check
106
+ ```
107
+
108
+ That flow:
109
+
110
+ - builds through the `prepack` lifecycle
111
+ - creates a tarball with `npm pack`
112
+ - installs that tarball into a temporary prefix
113
+ - runs the installed CLI with `--help`
114
+
115
+ For the one-command local release flow, prefer:
116
+
117
+ ```bash
118
+ pnpm publish:local
119
+ ```
120
+
121
+ That flow:
122
+
123
+ - runs `pnpm typecheck`
124
+ - packs the tarball through `npm pack` and `prepack`
125
+ - smoke-tests the packed install in a temporary prefix
126
+ - installs that tarball globally
127
+ - verifies the resulting `bee --help` output
128
+
129
+ If the current environment cannot write to the real global toolchain location, you can redirect the install target just for this command:
130
+
131
+ ```bash
132
+ BEE_PUBLISH_LOCAL_PREFIX=/tmp/codex-bee-local pnpm publish:local
133
+ ```
134
+
135
+ On Volta-managed shells, the active `bee` command may still resolve through `~/.volta/bin/bee` even after a successful tarball install. `pnpm publish:local` now checks `bee --version` and fails if the active PATH entry is still shadowing the freshly installed binary. In that case, either run the installed binary directly from `$(npm prefix -g)/bin/bee`, or keep using an isolated prefix:
136
+
137
+ ```bash
138
+ BEE_PUBLISH_LOCAL_PREFIX=/tmp/codex-bee-local pnpm publish:local
139
+ /tmp/codex-bee-local/bin/bee --version
140
+ ```
141
+
142
+ For manual local global-install experiments, prefer installing the tarball rather than `npm i -g .` when Volta is involved:
143
+
144
+ ```bash
145
+ pnpm package:check
146
+ npm pack
147
+ npm i -g ./usulpro-codex-bee-<version>.tgz
148
+ ```
149
+
150
+ Published installs should still use the registry form:
151
+
152
+ ```bash
153
+ npm i -g @usulpro/codex-bee
154
+ bee codex
155
+ ```
156
+
157
+ ## UI development
158
+
159
+ The current UI iteration path uses `Ink` plus `@inkjs/ui` on top of a renderer-agnostic contract.
160
+ This is the active TUI surface for the project right now, not a disposable reset branch.
161
+
162
+ Read [docs/tui-isolated-development.md](docs/tui-isolated-development.md) before starting the next TUI pass. It is the handoff document for the isolated workflow, file boundaries, and testing loop.
163
+
164
+ Current UI architecture layers:
165
+
166
+ - `src/ui/core/`: renderer-agnostic state, typed intents, controller logic, and derived view helpers
167
+ - `src/ui/runtime/`: host interfaces plus adapters for mocked and future live wrapper runtimes
168
+ - `src/ui/renderers/ink/`: the current Ink renderer
169
+ - `src/ui/dev-harness/`: isolated mocked runtime scenarios and standalone entry point
170
+
171
+ Use the isolated harness when iterating on UI work:
172
+
173
+ ```bash
174
+ pnpm ui:demo
175
+ pnpm ui:demo -- --scenario bee-agent
176
+ pnpm ui:dev
177
+ pnpm ui:test
178
+ ```
179
+
180
+ `pnpm ui:dev` is the fast local loop for UI work. It does not require the PTY wrapper, the sandbox harness, or a live Codex session.
181
+ The current standalone scenarios cover idle, armed static continuation, verification failure, bee-agent mode, and repeat-loop mode.
182
+ The current Ink renderer is the working TUI surface. Use the isolated harness to refine the existing layout, keyboard flow, status reporting, and runtime contract without destabilizing live PTY sessions.
183
+ The live status model now distinguishes early hook readiness from a proven attached session: preflight yields `Hooks ready`, `SessionStart` upgrades that to `Connected`, and `UserPromptSubmit` marks the active turn as running before `Stop` completes it.
184
+ Current keyboard contract inside the standalone shell:
185
+
186
+ - `Tab` switches screens
187
+ - `Ctrl+B` hides or reopens the shell
188
+ - `Ctrl+C` exits `pnpm ui:demo`
189
+
190
+ The selected screen still stays in UI state, so closing and reopening the shell returns to the same screen.
191
+ `pnpm ui:demo` lets the Ink app own `Ctrl+C`, while `pnpm ui:dev` hands `Ctrl+C` back to the outer watch process so you can stop the dev loop cleanly without the renderer swallowing the signal first.
192
+
193
+ The isolated Ink shell remains the safest local workshop for UI changes, but it should track and improve the current product direction rather than reboot it.
194
+ Alternative renderer explorations are currently deprecated unless they are explicitly revived by product direction.
195
+
196
+ ## Sandbox harness
197
+
198
+ Sandbox location comes from `.env`:
199
+
200
+ ```bash
201
+ CODEX_BEE_SANDBOX_DIR=~/projects/PrimeUI/sandboxes/codex-bee-lab
202
+ ```
203
+
204
+ Start by copying `.env.example` to `.env` and adjusting the path if needed.
205
+
206
+ The sandbox is disposable. Each live experiment should start from a fresh harness:
207
+
208
+ ```bash
209
+ pnpm build
210
+ pnpm sandbox:clean
211
+ pnpm sandbox:prepare
212
+ cd "$CODEX_BEE_SANDBOX_DIR"
213
+ ```
214
+
215
+ `pnpm sandbox:prepare` creates:
216
+
217
+ - sandbox-local `.codex/config.toml`
218
+ - sandbox-local `.codex/hooks.json`
219
+ - sandbox-local `hooks/stop-hook.cjs`
220
+ - sandbox-local `logs/`, `artifacts/`, and `prompts/`
221
+ - a `bee` launcher that points back to the built wrapper in this repository
222
+ - `bee-clear-stop-captures`, `bee-inspect-stop-capture`, `bee-inspect-events`, `bee-inspect-transcript`, and `bee-inspect-agent-state` helper launchers for local runtime artifacts
223
+ - a `bee-record-review` launcher that records a review bundle for live PTY sessions
224
+ - a `bee-record-parallel-review` launcher that records two concurrent same-sandbox wrapper runs for isolation checks
225
+ - sample bee-agent prompts and `prompts/bee-agent-demo.json` for the first generated-continuation smoke path
226
+
227
+ All generated sandbox launchers pin their working directory to the sandbox root before they exec Node, so hook capture paths and runtime logs stay isolated even if the launcher is invoked through an absolute path from another shell location.
228
+
229
+ The sandbox also seeds a demo bee-agent config under `prompts/bee-agent-demo.json`. Prompt paths inside a bee-agent config resolve relative to the config file directory, not the process cwd.
230
+
231
+ The sandbox harness captures Stop hook evidence into `.codex/tmp/stop-captures/`, refreshes `.codex/tmp/last-stop-capture.json` on each run, and records wrapper events in `.codex/tmp/bee-events.jsonl`.
232
+
233
+ Example smoke run:
234
+
235
+ ```bash
236
+ cd "$CODEX_BEE_SANDBOX_DIR"
237
+ codex exec --enable codex_hooks "Reply with READY only."
238
+ ./bee-inspect-stop-capture
239
+ ./bee-inspect-events
240
+ ./bee-inspect-transcript
241
+ ```
242
+
243
+ The repository root no longer carries an active `.codex/hooks.json`, so operator sessions in the repo stay isolated from the disposable live-test harness.
244
+
245
+ ## Interactive runs
246
+
247
+ For interactive manual runs, start from the sandbox and use the `codex_bee_live` profile from `~/.codex/config.toml`.
248
+
249
+ Direct Codex session:
250
+
251
+ ```bash
252
+ cd "$CODEX_BEE_SANDBOX_DIR"
253
+ codex -p codex_bee_live
254
+ ```
255
+
256
+ Wrapper session from the sandbox:
257
+
258
+ ```bash
259
+ pnpm build
260
+ pnpm sandbox:clean
261
+ pnpm sandbox:prepare
262
+ cd "$CODEX_BEE_SANDBOX_DIR"
263
+ ./bee codex --profile codex_bee_live
264
+ ```
265
+
266
+ One-shot continuation smoke run through the wrapper:
267
+
268
+ ```bash
269
+ cd "$CODEX_BEE_SANDBOX_DIR"
270
+ ./bee --continue-once "Reply with READY only and stop." codex --profile codex_bee_live
271
+ ```
272
+
273
+ `--continue-once` now defaults to zero extra delay after the matched Stop capture. Keep `--inject-delay-ms` only as a debug override for edge-case PTY timing experiments.
274
+
275
+ Repeat continuation loop smoke run with a three-injection guardrail:
276
+
277
+ ```bash
278
+ cd "$CODEX_BEE_SANDBOX_DIR"
279
+ ./bee --continue-loop "Reply with NEXT only and stop." --max-continues 3 codex --profile codex_bee_live --no-alt-screen "Reply with FIRST only and stop."
280
+ ```
281
+
282
+ `--continue-loop` reuses the same follow-up prompt after each matched Stop event and stops injecting automatically after `--max-continues` is reached.
283
+
284
+ Bee-agent loop smoke run through the wrapper:
285
+
286
+ ```bash
287
+ cd "$CODEX_BEE_SANDBOX_DIR"
288
+ ./bee --continue-loop-agent-file prompts/bee-agent-demo.json --max-continues 2 codex --profile codex_bee_live --no-alt-screen "Reply with FIRST only and stop."
289
+ ```
290
+
291
+ Expected demo sequence with the seeded sandbox bee-agent prompts:
292
+
293
+ - `FIRST`
294
+ - bee-agent generates `Reply with SECOND only and stop.`
295
+ - `SECOND`
296
+ - bee-agent generates `Reply with THIRD only and stop.`
297
+ - `THIRD`
298
+
299
+ After the run:
300
+
301
+ ```bash
302
+ cd "$CODEX_BEE_SANDBOX_DIR"
303
+ ./bee-inspect-agent-state
304
+ ./bee-inspect-events
305
+ ./bee-inspect-transcript
306
+ ```
307
+
308
+ Use this profile for PTY-focused experiments so the session has the same interactive permissions that were already confirmed to work.
309
+
310
+ ## Control overlay
311
+
312
+ `Ctrl+B` opens the first runtime control overlay checkpoint.
313
+
314
+ Current overlay capabilities:
315
+
316
+ - edit the static continuation prompt, including multiline content
317
+ - arm auto-continue directly from the overlay
318
+ - change the repeat guardrail
319
+ - change the session-duration guardrail with values like `90m`, `1.5h`, `5400s`, or `off`
320
+ - disable auto-continue without restarting Codex
321
+
322
+ The overlay now uses the terminal alternate screen buffer so closing it can restore the previous Codex view instead of forcing a redraw guess.
323
+
324
+ Overlay commands:
325
+
326
+ - `E`: edit the continuation prompt
327
+ - `R`: edit max repeats
328
+ - `T`: edit max duration
329
+ - `A`: apply and arm the current draft
330
+ - `D`: disable auto-continue
331
+ - `Q` or `Ctrl+B`: close without applying
332
+
333
+ Prompt editing uses a simple multiline editor:
334
+
335
+ - `Ctrl+D`: save the prompt draft
336
+ - `Esc`: cancel prompt editing
337
+
338
+ Every overlay session now writes runtime events such as `overlay_opened`, `overlay_prompt_updated`, `overlay_apply`, `stop_capture_matched`, and `continuation_prompt_injected` to `.codex/tmp/bee-events.jsonl`.
339
+
340
+ Each event now carries a `runId` and a per-run sequence number. `./bee-inspect-events` shows the latest run by default, including the exact overlay-applied prompt text, matched Stop count, and injected prompt count. Pass `--all` if you need the full history from the current sandbox log.
341
+
342
+ When the overlay arms or disables auto-continue, the wrapper now also prints an explicit stderr confirmation so live runs make it obvious whether the control action actually took effect.
343
+
344
+ ## Review harness
345
+
346
+ `./bee-record-review` is the first semi-manual PTY verification harness.
347
+
348
+ It wraps a live `./bee codex ...` session in terminal recording and saves a review bundle under:
349
+
350
+ ```bash
351
+ logs/reviews/<timestamp>[-label]/
352
+ ```
353
+
354
+ Each review bundle includes:
355
+
356
+ - `terminal.typescript`
357
+ - `command.txt`
358
+ - `metadata.json`
359
+ - `checklist.md`
360
+ - `bee-events.jsonl` when runtime events exist
361
+ - `bee-events-summary.txt`
362
+ - `last-stop-capture.json` when a Stop capture exists
363
+ - `stop-capture-summary.txt`
364
+ - `transcript-summary.txt` and `transcript-summary.json` when a transcript is available
365
+ - `bee-agent-state.txt` when bee-agent state is available
366
+
367
+ Example review recording for the current bee-agent checkpoint:
368
+
369
+ ```bash
370
+ cd "$CODEX_BEE_SANDBOX_DIR"
371
+ ./bee-record-review --label bee-agent-demo --continue-loop-agent-file prompts/bee-agent-demo.json --max-continues 2 codex --profile codex_bee_live --no-alt-screen "Reply with FIRST only and stop."
372
+ ```
373
+
374
+ This still requires a human to visually judge redraw and terminal fidelity, but it now leaves a consistent artifact bundle behind for later inspection instead of relying on memory and ad-hoc screenshots.
375
+
376
+ For same-sandbox concurrency review, use:
377
+
378
+ ```bash
379
+ cd "$CODEX_BEE_SANDBOX_DIR"
380
+ ./bee-record-parallel-review --label same-sandbox
381
+ ```
382
+
383
+ This launches two wrapper sessions in parallel from the same sandbox root:
384
+
385
+ - left: `ALPHA-FIRST -> ALPHA-SECOND`
386
+ - right: `BETA-FIRST -> BETA-SECOND`
387
+
388
+ The review bundle includes separate terminal recordings, shared runtime events, copied Stop captures, and a `parallel-summary.json` token check so you can confirm that each wrapper continued only its own session.
389
+
390
+ ## Continuation prompt templates
391
+
392
+ `--continue-once`, `--continue-loop`, `--continue-once-file`, and `--continue-loop-file` all accept `{{placeholder}}` tokens. The wrapper renders those tokens from the matched Stop capture immediately before each injected prompt, so the rendered prompt can change from turn to turn without adding a second model call.
393
+
394
+ File-based continuation templates are validated before Codex starts and re-read on every matched Stop event. The PTY injection path now uses bracketed paste, so multiline template files can be submitted as one logical prompt instead of breaking on the first newline.
395
+
396
+ Supported placeholders:
397
+
398
+ - `{{captured_at}}`
399
+ - `{{cwd}}`
400
+ - `{{hook_event_name}}`
401
+ - `{{last_assistant_message_excerpt}}`
402
+ - `{{last_assistant_message_json}}`
403
+ - `{{last_assistant_message_single_line}}`
404
+ - `{{last_assistant_message}}`
405
+ - `{{model}}`
406
+ - `{{permission_mode}}`
407
+ - `{{run_id}}`
408
+ - `{{session_id}}`
409
+ - `{{stop_hook_active}}`
410
+ - `{{transcript_path}}`
411
+
412
+ Known placeholders that are missing in a capture render as empty strings. Unknown placeholders stay unchanged in the prompt, and the wrapper prints a warning once per unknown token.
413
+
414
+ Safer helpers for previous assistant content:
415
+
416
+ - `{{last_assistant_message_single_line}}`: collapses whitespace and newlines into a single trimmed line
417
+ - `{{last_assistant_message_json}}`: emits a JSON string literal of the raw message, useful when you need newline-safe quoting
418
+ - `{{last_assistant_message_excerpt}}`: emits a single-line excerpt capped at 280 characters
419
+
420
+ Example loop that proves the prompt template changes on each Stop event:
421
+
422
+ ```bash
423
+ cd "$CODEX_BEE_SANDBOX_DIR"
424
+ ./bee --continue-loop "Reply with TRACE: {{last_assistant_message}} only and stop." --max-continues 3 codex --profile codex_bee_live --no-alt-screen "Reply with FIRST only and stop."
425
+ ```
426
+
427
+ Expected sequence:
428
+
429
+ - `FIRST`
430
+ - `TRACE: FIRST`
431
+ - `TRACE: TRACE: FIRST`
432
+ - `TRACE: TRACE: TRACE: FIRST`
433
+
434
+ Example one-shot prompt that is safer for multiline previous answers:
435
+
436
+ ```bash
437
+ cd "$CODEX_BEE_SANDBOX_DIR"
438
+ ./bee --continue-once "Reply with SAFE {{last_assistant_message_single_line}} only and stop." codex --profile codex_bee_live --no-alt-screen "Reply with exactly two lines: FIRST and SECOND. Stop after that."
439
+ ```
440
+
441
+ Example multiline template file workflow:
442
+
443
+ ```bash
444
+ cat >/tmp/codex-bee-follow-up.txt <<'EOF'
445
+ Reply with the exact token from the next line only.
446
+ SECOND-LINE
447
+ Stop after that.
448
+ EOF
449
+
450
+ cd "$CODEX_BEE_SANDBOX_DIR"
451
+ ./bee --continue-once-file /tmp/codex-bee-follow-up.txt codex --profile codex_bee_live --no-alt-screen "Reply with READY only and stop."
452
+ ```
453
+
454
+ Expected sequence:
455
+
456
+ - `READY`
457
+ - file-based continuation is injected as a single multiline prompt
458
+ - `SECOND-LINE`
459
+
460
+ ## Verification-command gate
461
+
462
+ `--verify-command` adds a simple mechanical gate on top of any continuation mode.
463
+
464
+ Current behavior:
465
+
466
+ - after each matched Stop event, the wrapper runs the configured shell command
467
+ - if the command exits with `0`, auto-continue stops and no new prompt is injected
468
+ - if the command exits with a non-zero code, auto-continue keeps going and appends a verification summary to the next injected prompt
469
+ - the appended summary includes the command text, exit code, and tail excerpts from `stderr` and `stdout`
470
+
471
+ Example loop that keeps Codex working until `pnpm typecheck` passes:
472
+
473
+ ```bash
474
+ cd "$CODEX_BEE_SANDBOX_DIR"
475
+ ./bee --continue-loop "Continue fixing the verification failure." --verify-command "pnpm typecheck" --max-continues 5 codex --profile codex_bee_live --no-alt-screen "Find and fix the type errors, then stop."
476
+ ```
477
+
478
+ This is intentionally a lightweight alternative to bee-agent orchestration. It gives the wrapper a deterministic continue-or-stop signal without requiring a second model call.
479
+
480
+ ## Bee-agent continuation mode
481
+
482
+ `--continue-once-agent-file` and `--continue-loop-agent-file` enable the first AI-assisted continuation flow.
483
+
484
+ Bee-agent config files are JSON and resolve prompt paths relative to the config file directory:
485
+
486
+ ```json
487
+ {
488
+ "systemPromptPath": "bee-agent-system.md",
489
+ "sessionPromptPath": "bee-agent-session.md",
490
+ "model": "gpt-5.4",
491
+ "maxRecentMessages": 6,
492
+ "maxNoteChars": 4000,
493
+ "maxObjectiveChars": 1500,
494
+ "maxLastAssistantChars": 4000
495
+ }
496
+ ```
497
+
498
+ Current bounded bee-agent context includes:
499
+
500
+ - `lastAssistantMessage` from the matched Stop payload
501
+ - recent `user` and `assistant` transcript turns when `transcript_path` is available
502
+ - the first user turn as `sessionObjective`
503
+ - persistent `beeNotes` for the current wrapped session
504
+ - session metadata such as `sessionId`, `cwd`, `model`, and `permissionMode`
505
+
506
+ When transcript artifacts are available, the parser now prefers structured `event_msg` records over raw `response_item.message` entries:
507
+
508
+ - `event_msg.user_message.message` is the cleanest source for operator-visible prompt text
509
+ - `event_msg.task_complete.last_agent_message` is the cleanest source for the final assistant report for each completed turn
510
+ - `event_msg.token_count` exposes per-turn token usage snapshots and the current context-window size
511
+
512
+ This matters because raw `response_item.message role=user` entries often include the initial session context blob, while `user_message` tracks the actual prompts that entered the session.
513
+
514
+ Current bee-agent state lives under:
515
+
516
+ ```bash
517
+ .codex/tmp/bee-agent/<session-id>/
518
+ ```
519
+
520
+ The wrapper stores:
521
+
522
+ - `notes.md`
523
+ - per-run `context.json`
524
+ - per-run `generator-prompt.md`
525
+ - per-run `result.json`
526
+ - per-run `stdout.log` and `stderr.log`
527
+
528
+ The generator run is intentionally isolated with:
529
+
530
+ - `codex exec`
531
+ - `--ephemeral`
532
+ - `--disable codex_hooks`
533
+ - structured JSON output through `--output-schema`
534
+
535
+ If the bee-agent generator fails, the wrapper surfaces the failure and disables auto-continue instead of silently looping on broken state.
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node