feat: Make triggers opt-in and fix inject submission#131
Conversation
Triggers are no longer auto-bound to the first idle trigger on spawn. Instead, users explicitly bind via `--trigger <name>` on spawn or `pu trigger assign <agent_id> <trigger_name>` post-hoc. Also switches inject_text from raw write_to_fd to write_chunked_submit, fixing the race where pasted text + Enter was swallowed by the TUI. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe PR extends spawn functionality with optional trigger binding. A new Changes
Sequence DiagramsequenceDiagram
actor User
participant CLI
participant Daemon
participant Engine
participant Manifest
User->>CLI: spawn --trigger "trigger-name"
CLI->>Daemon: Request::Spawn { trigger_name: Some(...) }
Daemon->>Engine: handle_spawn
Engine->>Manifest: spawn agent
Manifest-->>Engine: agent_id
Engine->>Engine: if trigger provided: bind_trigger
Engine->>Manifest: update with trigger metadata
Manifest-->>Engine: success
Engine-->>Daemon: Response::SpawnResult
Daemon-->>CLI: SpawnResult
CLI-->>User: agent created with trigger bound
User->>CLI: trigger assign --agent-id X --trigger-name Y
CLI->>Daemon: Request::AssignTrigger
Daemon->>Engine: handle_assign_trigger
Engine->>Manifest: locate trigger by name
Manifest-->>Engine: trigger data
Engine->>Manifest: validate & update agent binding
Manifest-->>Engine: success
Engine-->>Daemon: Response::AssignTriggerResult
Daemon-->>CLI: AssignTriggerResult
CLI-->>User: trigger assigned
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
- Inline format args in handle_assign_trigger (clippy uninlined_format_args) - Add conflicts_with between --trigger and --no-trigger flags - Validate agent exists before assigning trigger (return NOT_FOUND error instead of silent no-op) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 6
🧹 Nitpick comments (1)
crates/pu-cli/src/output.rs (1)
256-267: Add a smoke test for this new response arm.This branch is the only new human-output path in the file, but there isn’t a matching
print_responsesmoke test alongside the other response variants below. A smallAssignTriggerResultcase would keep this match arm from regressing unnoticed.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@crates/pu-cli/src/output.rs` around lines 256 - 267, Add a smoke test that covers the new Response::AssignTriggerResult arm by calling the same test helper used for other response variants (the print_response test harness) and passing a Response::AssignTriggerResult with example agent_id, trigger_name, and sequence_len; assert that the stdout contains the expected human-readable string (e.g., trigger_name and agent_id) so the match arm in print_response (or the Response::AssignTriggerResult handling in output.rs) is exercised and cannot regress unnoticed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@crates/pu-cli/src/main.rs`:
- Around line 65-70: The two CLI flags are allowed together but should be
mutually exclusive; update the struct field attributes for `no_trigger` and
`trigger` (the `no_trigger: bool` and `trigger: Option<String>` fields in
main.rs) to use clap's conflicts_with so the parser rejects combinations—e.g.
add `conflicts_with = "no_trigger"` to the `trigger` arg (or symmetric
`conflicts_with = "trigger"` on `no_trigger`) so supplying both `--trigger` and
`--no-trigger` fails at parse time.
In `@crates/pu-core/src/protocol.rs`:
- Around line 132-136: The protocol enum has new variants AssignTrigger and
AssignTriggerResult but PROTOCOL_VERSION was not incremented; update the
PROTOCOL_VERSION constant to the next integer and adjust the associated version
assertion test expectation to match the new value (update the test that asserts
PROTOCOL_VERSION to the new number). Ensure both the constant named
PROTOCOL_VERSION and the test that checks the protocol version are changed in
the same commit so the runtime and tests remain consistent.
In `@crates/pu-engine/src/engine.rs`:
- Around line 1166-1200: The current branch that handles an explicit trigger
(when trigger_param is Some) silently logs and proceeds with (None, None) if the
named trigger is missing or has an empty sequence; instead, make this path
return an error consistent with handle_assign_trigger so that `--trigger <name>`
failures are surfaced. Locate the block that computes (trigger_name,
trigger_total) using trigger_param/no_trigger/project_root and change the match
arms for None and Some(_) where total == 0 to return an Err with a clear message
(e.g., "trigger '<name>' not found" or "trigger '<name>' has empty sequence")
rather than logging and falling back; ensure the calling function’s
signature/flow propagates that Result error (or convert to the same error path
used by handle_assign_trigger) so the CLI command fails on invalid trigger
names.
- Around line 246-253: Add Request::AssignTrigger to the project registration
switch so projects modified by trigger assignment are registered for scanning:
update the match that registers projects (the register_project branch) to
include the Request::AssignTrigger arm (same way as other project-scoped
requests), ensuring that when handle_assign_trigger(&project_root, &agent_id,
&trigger_name) is dispatched the project_root is also passed into the project
registration logic so scheduler_tick() will scan the project after persistently
assigning a trigger.
- Around line 1589-1606: Clippy flags uninlined format args in the
Response::Error messages—replace inline-captured identifiers in the format!
calls with explicit format placeholders and arguments; for example, change
format!("trigger lookup failed: {e}") to format!("trigger lookup failed: {}", e)
and ensure any uses like format!("trigger '{}' not found", trigger_name) or
format!("trigger '{}' has empty sequence", trigger_name) use "{}" placeholders
with trigger_name passed as an argument (references: Response::Error
construction, trigger_name, variable e, and sequence_len derived from
trigger.sequence.len()).
---
Nitpick comments:
In `@crates/pu-cli/src/output.rs`:
- Around line 256-267: Add a smoke test that covers the new
Response::AssignTriggerResult arm by calling the same test helper used for other
response variants (the print_response test harness) and passing a
Response::AssignTriggerResult with example agent_id, trigger_name, and
sequence_len; assert that the stdout contains the expected human-readable string
(e.g., trigger_name and agent_id) so the match arm in print_response (or the
Response::AssignTriggerResult handling in output.rs) is exercised and cannot
regress unnoticed.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 0ed27be0-583b-4cb9-b77f-c13e563f7e7e
📒 Files selected for processing (7)
crates/pu-cli/src/commands/spawn.rscrates/pu-cli/src/commands/trigger.rscrates/pu-cli/src/main.rscrates/pu-cli/src/output.rscrates/pu-core/src/protocol.rscrates/pu-engine/src/engine.rscrates/pu-engine/src/test_helpers.rs
- Bump PROTOCOL_VERSION 4 → 5 for AssignTrigger variants - Add AssignTrigger to project registration match - Make --trigger on spawn return error for invalid triggers Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Handle the new Response::AssignTriggerResult variant added in PR #131, delegating to agents::print_assign_trigger_result. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
pu spawn --trigger <name>orpu trigger assign <agent_id> <name>post-hocRequest::AssignTrigger/Response::AssignTriggerResultprotocol types with round-trip testsinject_textfrom rawwrite_to_fdtowrite_chunked_submit, fixing the race where pasted trigger text + Enter was being swallowed by the TUI--triggerand--no-triggerflags are mutually exclusive (clapconflicts_with)pu trigger assignvalidates agent exists before updating manifest (returns NOT_FOUND error instead of silent no-op)Test plan
cargo checkpasses for pu-core, pu-engine, pu-clicargo clippy --all-targetsclean with-D warningscargo fmt --checkpassespu spawn "task" --trigger <name>binds the triggerpu spawn "task"without--triggerdoes NOT auto-bindpu trigger assign <agent_id> <name>binds to an existing idle agentpu trigger assign <agent_id> <bad-name>returns NOT_FOUND error🤖 Generated with Claude Code