feat(hooks): Add hooks feature implementation plan#321
Open
quangdang46 wants to merge 19 commits into
Open
Conversation
Add .omo/ to gitignore to exclude plan files and agent metadata from version control.
- Add HookResult enum with Continue, Blocked, and Failed variants
- Add HookHandlerConfig enum with Command, Prompt, Agent, and Http variants
- Implement execute_command_hook() async function using tokio::process::Command
- Serialize HookInput to JSON and write to stdin
- Use tokio::time::timeout for timeout handling
- Parse stdout as HookOutput and handle exit codes:
- Exit 0 = continue, Exit 2 = blocked, other = failed
- Timeout treated as failed
- Implement execute_hook() dispatch function that routes to appropriate handler
- Add comprehensive tests for command execution, blocked hooks, and timeouts
- Stub out Prompt, Agent, and HTTP handlers for future implementation
- Add SessionStart, SessionEnd, PermissionRequest, PermissionDenied, ToolError to HookEvent enum - Wire ToolError hook in Registry::execute() error path using fire-and-forget tokio::spawn - Add parsing for new event names in HookEvent::parse() - Follow existing PreToolUse/PostToolUse hook pattern
- get_handler_matcher() now returns cmd.matcher.as_ref() / http.matcher.as_ref() - get_handler_condition() now returns cmd.if_.as_deref() / http.if_.as_deref() - Reorder HookMatcher derive to Serialize, Deserialize (correct order)
Previously load_hooks_config() only supported 2 layers: 1. User level: ~/.jcode/hooks.toml 2. Project level: .jcode/hooks.toml This adds a 3rd layer with highest priority: 3. Environment variable: JCODE_HOOKS_CONFIG - points to an absolute path Layer order (highest to lowest priority): 1. JCODE_HOOKS_CONFIG path (env override) 2. .jcode/hooks.toml (project level) 3. ~/.jcode/hooks.toml (user level) Each layer merges on top of the previous, so env override takes precedence.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hooks Feature Implementation Plan
This PR adds a comprehensive implementation plan for the hooks feature in jcode, based on research of Claude Code, OpenAI Codex, and anomalyco/opencode.
What this PR includes:
.omo/plans/hooks-implementation.md) — detailed ~450 line implementation plan covering:Registry::execute()insrc/tool/mod.rshookscommand with list/add/remove/enable/disableDesign Decisions:
JCODE_HOOKS_*env →~/.jcode/hooks.toml(user) →.jcode/hooks.toml(project wins)command,prompt,agent,httpResearch sources:
Next steps (out of scope for this PR):