Repository navigation
Conversation
Move HookCommands/HooksConfig into jcode-config-types/src/hooks.rs and split jcode-base hooks into mod/gate/feedback/sync_runner. Synchronous hooks now run in their own process group with bounded readers, so a grandchild holding stdout cannot defeat the timeout. Adds a regression test.
Empty until a feature adds its token; the field is omitted when empty.
…ynchronous hooks Claude-shaped common payload fields with a jcode object, a verdict parser for decision/continue/additionalContext/exit-2 with 10,000 char caps, and a runner that feeds a JSON document on stdin. Used by the upcoming prompt and stop hooks.
…d observers Workers register an identity at spawn; every hook event for that session carries swarm id, coordinator, parent, label, agent id and agent type in env and payload. New observers swarm_member_start and swarm_member_end fire in the coordinator context with SubagentStart/SubagentStop JSON on stdin, once per running to end transition. Observer hooks can now receive a JSON document on stdin. Adds JCODE_SPAWN_SWARM_LABEL and capabilities swarm_identity, swarm_member_events.
[Medium impact] The changes reach incoming message handling and swarm lifecycle reporting. The PR still needs the coordinator origin fix before merging. Findings
Fix with agent prompt### Issue 1
crates/jcode-app-core/src/agent/turn_execution.rs:102-108
`run_swarm_message` still calls `run_once_capture` for its generated `integration_prompt`, without declaring an origin. The new default here marks that prompt-including the workers’ replies-as `origin.kind="person"`. This affects both `swarm_message:` and `swarm_message_async:` requests. A hook that allows only human input therefore admits the unattended integration turn. Declare a host origin for the generated coordinator calls, as the worker call already does.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.SummaryAdds
No new findings were accepted.
|
…isconnects still fire swarm_member_end
03a9cb5 to
bb2ac37
Compare
Synchronous hook run before each new user message is appended. Claude-shaped JSON on stdin with the prompt (never in env), a TurnOrigin-shaped origin and jcode.origin_detail (user, auto, reminder, swarm_message, swarm_spawn, background_task, system, sdk). Plain stdout or additionalContext becomes a hidden reminder after the message, decision block/exit 2/continue false rejects it, and failures fail open. Request::Message gains an optional origin, set to auto by the TUI for client-generated sends and to sdk by the harness API bridge. Adds capabilities user_prompt_submit and prompt_origin.
…sible worker startup as swarm_spawn, forget prompt origins
bb2ac37 to
2de70d2
Compare
…generated ambient and overnight prompts, and never fail over a hook-blocked prompt
2de70d2 to
ebd1474
Compare
…e, bounded transformer output, event guard tests
…rigins, generated CLI and follow-up origins, rebuild on 1jehuang#2035
…on cancel Give the pre_tool gate the same 64 MiB capture limit as the transformer and block (never silently allow) when stdout is still truncated. Add a drop guard in the sync runner that kills the hook's process group if the run future is dropped, so a cancelled turn no longer leaves hook subprocesses running.
…mber_end have fired
…ock cannot let a prompt through
| let default_origin = if display_role.is_some() { | ||
| PromptOrigin::System | ||
| } else { | ||
| PromptOrigin::User | ||
| }; | ||
| let prompt_hook = self | ||
| .run_user_prompt_submit_hook(user_message, default_origin, "capture") |
There was a problem hiding this comment.
Coordinator replies count as people.
run_swarm_message still calls run_once_capture for its generated integration_prompt, without declaring an origin. The new default here marks that prompt—including the workers’ replies—as origin.kind="person". This affects both swarm_message: and swarm_message_async: requests. A hook that allows only human input therefore admits the unattended integration turn. Declare a host origin for the generated coordinator calls, as the worker call already does.
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-app-core/src/agent/turn_execution.rs
Line: 100-106
Comment:
**Coordinator replies count as people.** `run_swarm_message` still calls `run_once_capture` for its generated `integration_prompt`, without declaring an origin. The new default here marks that prompt—including the workers’ replies—as `origin.kind="person"`. This affects both `swarm_message:` and `swarm_message_async:` requests. A hook that allows only human input therefore admits the unattended integration turn. Declare a host origin for the generated coordinator calls, as the worker call already does.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Depends on #2035. Part of #2028. Refs #999.
New commits in this PR:
feat(hooks): user_prompt_submit hook with prompt originanddocs(hooks): document user_prompt_submit in the default config. The earlier commits are the dependency.Problem
A hook cannot see or gate a new user message (#999). Frameworks read the session file to recover the prompt.
Changes
A synchronous
user_prompt_submithook. The prompt arrives on stdin as Claude-shaped JSON (never in env) with anorigin(person, or host-generated: auto-poke, reminder, swarm message, swarm spawn, background task, system, sdk). Stdout oradditionalContextis appended as a hidden reminder after the user message.decision:"block"or exit 2 rejects the message and nothing is sent to the model. It fails open.user_prompt_submit_timeout_msdefaults to 5000 and is capped at 30000.Request::Messagegains an optionalorigin.Test
9 new tests: stdin JSON, added context and blocking; fail-open on timeout and odd exit; origin names round-trip and an unknown name is rejected; only a user message is a person; a pending origin is consumed once while the current persists; the payload carries the prompt, origin and jcode detail; several hooks combine context and the first block wins; and a protocol round trip with a legacy message. Run with
cargo test -p jcode-app-core --lib prompt_hookand-p jcode-protocol.Edge cases
Timeout and odd exit codes fail open, an unknown origin name is rejected, and the first block wins among several hooks (all tested).
Compatibility
New key only. The optional
originwire field is absent for old clients (tested).Docs
docs/HOOKS.mdand the default config.Validation
cargo fmt --check,cargo check --all-targets --all-features,cargo clippy --all-targets --all-features -D warnings, the module-file check, warning budget, sdk parity, the size, test-size, panic, swallowed-error and wildcard-reexport ratchets, and the targeted tests above were run on a Linux arm64 box and compared against a baseline of unmodified master: no regressions. Runtime: stdin carries theUserPromptSubmitevent withorigin.kind=person, hook stdout reaches the model as hidden context, and a blocking hook produces zero model requests with its reason shown.Pre-existing master CI failures
masterat f74bb39 already fails CI independently of this change:cargo clippy --all-targets --all-features -- -D warnings(collapsibleifinruntime_ssh_accounts.rsandtool/todo.rs,type_complexityinruntime_ssh_accounts.rs, anifwith identical blocks intodos_view.rs, a needless borrow inui_header.rs, an unusedaccount_switch_notice), the warning budget, and the code-size, test-size, panic and swallowed-error ratchets (Guardrails and Build & Test are red on master, Format is green). I used "no file is worse than on master and no new lint or test failure" as the bar, and compared this branch against a baseline run of unmodified master: no regressions.AI assistance
This change was developed with AI assistance (Claude) and reviewed and validated by me as described under Validation.