feat(hooks): support multiple client-scoped commands - #758
Conversation
577053c to
3c57514
Compare
Greptile SummaryThis PR adds native support for multiple lifecycle hook commands and client-scoped terminal identity. The main changes are:
Confidence Score: 5/5Safe to merge with low risk. The changes preserve legacy hook behavior, add ordered multi-command execution, and include focused tests for config parsing and hook execution. Files Needing Attention: No files require special attention.
What T-Rex did
|
| Filename | Overview |
|---|---|
| crates/jcode-app-core/src/server/client_lifecycle.rs | Propagates the active client terminal environment through session creation/resume, message processing, clear-session, and cleanup hook execution. |
| crates/jcode-base/src/hooks.rs | Adds task-local client terminal env propagation and executes every configured observer/pre-tool hook independently in declaration order. |
| crates/jcode-config-types/src/lib.rs | Implements backward-compatible hook config deserialization/serialization for either a string or array of command strings. |
| crates/jcode-terminal-launch/src/lib.rs | Adds helper to replace inherited terminal-identifying environment variables with a client-authoritative snapshot and aliases. |
| crates/jcode-base/src/config/env_overrides.rs | Extends lifecycle hook env overrides to accept empty disables, legacy strings, or TOML-style arrays of command strings. |
| crates/jcode-base/src/config_tests.rs | Adds config tests for hook command arrays, legacy first-command compatibility, serialization round trips, and env array overrides. |
| crates/jcode-app-core/src/server/client_lifecycle_tests.rs | Updates lifecycle tests for the new terminal environment parameter on message processing helpers. |
| crates/jcode-base/src/terminal_launch.rs | Re-exports terminal environment application support from the terminal launch crate. |
Sequence Diagram
sequenceDiagram
participant Client
participant Server as handle_client
participant Hooks as hooks task-local
participant Config as HooksConfig
participant Proc as Hook processes
Client->>Server: Subscribe(terminal_env)
Server->>Server: store active_terminal_env
Server->>Hooks: with_client_terminal_env(active_terminal_env)
Server->>Config: hook_commands(event)
Config-->>Server: command list
loop each configured command
Server->>Proc: build process with client terminal env + hook env
alt observer hook
Server->>Proc: spawn detached
else pre_tool gate
Server->>Proc: wait for exit status
Proc-->>Server: allow/block/other
end
end
Comments Outside Diff (1)
-
General comment
Focused client lifecycle Rust test suite fails
- Bug
cargo test -p jcode-app-core client_lifecyclefails with 2 failing tests out of 19 selected tests. Both failures assert thatstop_signal.is_set()should be true but it is not.
- Cause
- The client lifecycle cancel/session-control behavior under test is not setting the stop signal in the failing scenarios:
cancel_without_local_task_still_signals_session_controlatcrates/jcode-app-core/src/server/client_lifecycle_tests.rs:323anddeferred_cancel_reset_does_not_erase_newer_cancelat line 387.
- The client lifecycle cancel/session-control behavior under test is not setting the stop signal in the failing scenarios:
- Fix
- Investigate the cancel/session-control signal path in
crates/jcode-app-core/src/server/client_lifecycle.rsand restore the expected behavior so cancellation without a local task and deferred cancel reset handling both leave the relevant stop signal set as the tests expect.
- Investigate the cancel/session-control signal path in
- Bug
Reviews (1): Last reviewed commit: "feat(hooks): support multiple client-sco..." | Re-trigger Greptile
|
CI note: the remaining failing all-target/build jobs reproduce on the unchanged base commit
Both fail in the pre-existing CLI confidence migration ( The integration-specific local suite and live two-pane Herdr validation are documented in the PR body. |
|
Independent verification of this PR (2026-08-04), run against a fresh clone on macOS aarch64 with cargo 1.96.0. Verdict: no PR-introduced test failures. Every failing test in the crates this PR touches fails identically on the base commit ( Test matrix (head
The two failures flagged by automated review ( Separate note for maintainers: the remaining red CI (Build & Test + Quality Guardrails on all three OSes) comes from a pre-existing This PR is merge-ready from a test standpoint; the pre-existing failures should be tracked separately. |
|
Addendum — root causes of the 5 pre-existing test failures (follow-up to the verification comment above; same 2026-08-04 run, head The two
The three
None of the five touches this PR's eight files. |
|
Ready-to-merge fix for the master CI break (issue #768) — a one-command PR request. The menubar compile fix is complete, verified, and pushed to my fork. It's currently blocked from PR creation only because my account (factnest365-ops) is pull-only on 1jehuang/jcode — GitHub returns FORBIDDEN on CreatePullRequest. Requesting the PR be opened from a write-capable account. Branch: One command to open it (run as any maintainer): This unblocks PR #758's red Build & Test and lets the jcode-herdr integration ship. |
|
Done on our side. Independent verification (fresh clone, macOS aarch64, cargo 1.96.0) confirms this PR introduces zero new test failures — every failure in the touched crates reproduces identically on the base commit (v0.67.0). Ready for merge whenever you are. Note: the separate pre-existing master compile break (#768) has a verified fix ready at factnest365-ops:fix/menubar-ci (one-command PR open posted above) that will turn this PR's CI green once landed. |
Summary
This enables Herdr to append its lifecycle observer without wrapping or replacing an existing user hook. It also lets multiple Jcode clients sharing one server report the correct pane-local identity.
Closes #759.
Validation
cargo check -p jcode-app-corepassedDownstream
Required by herdrdev/herdr#2248 for native lifecycle hook composition and correct multi-pane routing.