Add user.prompt_submit and stop project hooks to code-rs#581
Add user.prompt_submit and stop project hooks to code-rs#581voarsh2 wants to merge 1 commit intojust-every:mainfrom
Conversation
Extend code-rs project hooks with two new lifecycle events: - user.prompt_submit - stop This adds minimal upstream-inspired hook semantics for: - blocking a user prompt via exit code 2 + stderr - injecting prompt context into model input via stdout - continuing a turn from a stop hook via stderr - preventing recursive stop-hook continuation loops Also enrich hook payloads with session/turn metadata needed by adapter-backed integrations: - session_id - turn_id - transcript_path - model Includes focused regression coverage for fire/block/injection/stop/ loop-guard behavior, plus a debug-build TUI fix for background-event prelude insertion.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 94f6820a7e
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| "cwd": self.cwd.to_string_lossy(), | ||
| "model": self.client.get_model(), | ||
| "prompt": prompt, | ||
| "items": items, |
There was a problem hiding this comment.
Bound prompt-hook payload before exporting to env
run_user_prompt_submit_hooks serializes the full items array into CODE_HOOK_PAYLOAD, and run_hook_command forwards that JSON verbatim as an environment variable; for multimodal prompts, InputItem::Image carries a base64 data URI that can be very large. On typical OS env-size limits, this can make hook process launch fail (E2BIG), so user.prompt_submit hooks silently stop working precisely when users attach screenshots/images. This is a regression in hook reliability for common image workflows and should be fixed by truncating/omitting large fields before env export.
Useful? React with 👍 / 👎.
Summary
This PR extends
code-rsproject hooks with two new lifecycle events:user.prompt_submitstopThe goal is to bring
code-rscloser to upstream Codex hook behavior forprompt-time context injection and end-of-turn continuation, while staying
inside the existing project-hook architecture.
What changed
New project hook events
Added support for:
user.prompt_submitstopFor compatibility with upstream naming,
UserPromptSubmitandStopareaccepted as config aliases.
Prompt-submit semantics
user.prompt_submitnow supports minimal upstream-inspired behavior:0: continue normally2with non-empty stderr: block the promptThis enables integrations that need to add context at prompt time.
Stop semantics
stopnow supports end-of-turn continuation:0: allow the turn to finish normally2with non-empty stderr: treat stderr as a continuation promptHook payload enrichment
To support integrations that need richer lifecycle metadata, hook payloads now include:
session_idturn_idwhere applicabletranscript_pathmodelThis applies to
session.start,user.prompt_submit, andstop.TUI fix
Also fixes a debug-build TUI assertion where a background event inserted during
prelude/startup could be tagged incorrectly and panic.
Validation
Focused tests
Passed:
cargo test -p code-core --test tool_hooks -- --nocapturecargo test -p code-core project_hook_event_deserializes_upstream_aliases -- --nocaptureCoverage includes:
Build
Passed:
cargo build --bin code --bin code-tui --bin code-execSmoke validation
A built-binary smoke harness was used during development to verify:
user.prompt_submitfiresstopfiresNon-goals
This PR does not add:
This stays within the existing project-hook framework.