Skip to content

hooks: prompt hook for /review and /run; pre_compact before automatic compaction (refs #26) - #37

Merged
blockmandev merged 2 commits into
mainfrom
feat/hook-review-run
Oct 22, 2026
Merged

blockmandev merged 2 commits into
mainfrom
feat/hook-review-run

Conversation

@blockmandev

Copy link
Copy Markdown
Member

The last two hook gaps from #26 item 5.

user_prompt_submit for /review and /run

Before this, the operator's prompt check covered typed lines and -t only.

  • /review now runs the hook on the review prompt it builds, diff included, so a secret scanner sees what will be sent. This is cli::review_turn, which the REPL's /review calls. A refusal sends nothing; the hook's output rides the turn.
  • /run now runs it on each task's instruction, before the worker or the memory engine hears it. This happens in run_memory::Remembered, the one wrapper every /run worker and lane goes through, in the REPL and over --acp.
    • A refused task fails that attempt with the reason.
    • The hook's output reaches the agent through the new TaskWorker::operator_context. AgentBackendWorker appends it right after the task's instruction.
  • As before, project plugins cannot add a prompt hook: from_settings goes through the plugin allowlist.

pre_compact before automatic compaction

The API route compacts on its own near the context window (ApiBackend::compact_if_near_window), and that fired nothing.

  • The backend's toolbox already holds the operator's hooks, the pinned session and the workspace. Toolbox::operator_pre_compact runs pre_compact with trigger: "auto" before the summary is asked for.
  • Manual /compact is unchanged (trigger: "manual"), and nothing fires twice.
  • New AgentEvent::Notice carries what the hooks print. Thinking would have hidden it, because the REPL does not show Thinking. Where it appears:
    • REPL: a line of its own, also during the follow-up pass.
    • --acp: a thought chunk, shown once. The REPL arm stands aside when an observer presents it.
    • -t: a · line, or {"type":"notice"} in stream-json.
    • The transcript and the stop hook do not hear it.
  • wiring.rs's note on run_on_compact no longer says the API backend holds no hooks.

Tests (each with a control that puts the bug back)

  • /review: cli::agent_turn::tests::a_review_refused_by_the_operators_hook_reaches_no_agent, on a real git repo. Exit 2 means no prompt; exit 0 means the prompt carries the diff and the hook's output.
  • /run: cli::run_memory::tests::a_task_refused_by_the_prompt_hook_is_not_worked_and_an_allowed_one_carries_its_context.
  • Worker: agent::worker::tests::the_operators_hook_context_reaches_the_agents_prompt_after_the_task.
  • Automatic compaction: agent::api::tests::the_operators_pre_compact_hook_runs_before_an_automatic_compaction. The hook echoes its stdin; its notice carries "trigger":"auto" and comes before the compaction's own note.
  • REPL notice: cli::agent_turn::tests::a_notice_mid_turn_is_shown_on_its_own_line.
  • --acp notice:
    • acp_agent::workers::tests::a_notice_becomes_a_thought_chunk_for_the_session_and_a_worker
    • acp_agent::worker_tests::a_notice_arrives_as_a_thought_chunk_not_as_the_reply. This test caught the notice being sent twice over --acp, as a thought and as reply text, before the observer fix.

Local Windows gate: fmt, clippy -D warnings, cargo test (2210 lib + 59 bin).

Not covered

  • A CLI agent's own automatic compaction happens inside that agent's process. incode cannot see it, so nothing fires. This is documented in the README.
  • The API route's own "[context near the window]" note is still sent as Thinking, which the REPL does not show. That predates this change and is left as is.

…efs #26)

/review sent its prompt with no hook run, and /run's workers took each
task's instruction straight from the ledger, so the operator's prompt
check covered typed lines and -t only. /review now runs it on the review
prompt (review_turn); /run runs it in run_memory::Remembered, the one
wrapper every worker and lane goes through, on each task's instruction.
A refusal sends nothing; the hook's output rides that turn, carried to
the agent by the new TaskWorker::operator_context.
Automatic compaction runs inside ApiBackend::compact_if_near_window,
which fired nothing, so the operator's pre_compact covered /compact
only. The backend's toolbox already holds the operator's hooks, the
pinned session and the workspace; Toolbox::operator_pre_compact runs
them with trigger auto before the summary is asked for. What they print
travels as the new AgentEvent::Notice, shown by the REPL (a line of its
own, also in the follow-up pass), --acp (a thought, once: the REPL arm
stands aside for an observer) and -t; Thinking, which the REPL does not
show, would have hidden it.
@blockmandev
blockmandev merged commit 2c412ee into main Oct 22, 2026
11 of 12 checks passed
@blockmandev
blockmandev deleted the feat/hook-review-run branch November 15, 2026 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant