-
Notifications
You must be signed in to change notification settings - Fork 32
Add hook environment variables and break duration #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Hooks now receive context via environment variables: - POMODORO_ID: Timestamp/ID of the current pomodoro - POMODORO_DIRECTORY: Data directory path - POMODORO_COMMAND: Command that triggered the hook - POMODORO_ARGS: Full command-line arguments including flags This enables hooks to query pomodoro details using the show command: desc=$(pomodoro --directory "$POMODORO_DIRECTORY" show description "$POMODORO_ID") 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add POMODORO_BREAK_DURATION_MINUTES and POMODORO_BREAK_DURATION_SECONDS environment variables to break hooks - Make break and finish --break wait by default (can disable with --wait=false) - Add shouldWait() helper to determine wait behavior based on context - Update hook.Run() to accept breakDuration parameter - Add tests for break duration environment variables 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Replace the 6-parameter function signature with a Params struct for better maintainability and readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances the hook system by adding contextual environment variables and improving the break command behavior. It makes hooks more useful by providing access to pomodoro metadata and makes break commands more user-friendly by waiting by default.
- Add environment variables to hooks:
POMODORO_ID,POMODORO_DIRECTORY,POMODORO_COMMAND,POMODORO_ARGS, and break duration variables - Refactor hook system to use a structured
Paramsapproach instead of just passing hook name - Make break commands wait by default with option to disable via
--wait=false
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| hook/hook.go | Core hook system refactored to use Params struct and add environment variable support |
| cmd/util.go | Added utility functions for wait behavior and command argument extraction |
| cmd/start.go | Updated to use new hook.Params structure with pomodoro metadata |
| cmd/repeat.go | Updated to use new hook.Params structure with pomodoro metadata |
| cmd/finish.go | Updated to use new hook.Params structure and added break duration support |
| cmd/clear.go | Updated to use new hook.Params structure with pomodoro metadata |
| cmd/cancel.go | Updated to use new hook.Params structure with pomodoro metadata |
| cmd/break.go | Updated to use new hook.Params structure and made wait default behavior |
| test/hooks.bats | Added comprehensive tests for new environment variables and break duration features |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| // getCommandArgs extracts the command-specific arguments from os.Args | ||
| func getCommandArgs(cmd *cobra.Command) []string { | ||
| for i, arg := range os.Args { | ||
| if arg == cmd.Name() || (i > 0 && os.Args[i-1] == "pomodoro") { | ||
| if arg == cmd.Name() { | ||
| return os.Args[i+1:] | ||
| } | ||
| } | ||
| } | ||
| return cmd.Flags().Args() | ||
| } |
Copilot
AI
Sep 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The getCommandArgs function has complex logic that may not handle all edge cases correctly. The condition (i > 0 && os.Args[i-1] == "pomodoro") on line 65 doesn't result in any action, making it redundant. Consider simplifying this logic or adding comments to explain the intended behavior for different argument patterns.
| if err := hook.Run(client, hook.Params{ | ||
| Name: "break", | ||
| Command: "break", | ||
| Args: getCommandArgs(cmd), | ||
| BreakDuration: d, | ||
| }); err != nil { |
Copilot
AI
Sep 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PomodoroID field is missing from the hook.Params struct, unlike other commands that include it. This inconsistency means break hooks won't have access to the pomodoro ID environment variable, which could be useful for tracking which pomodoro the break is associated with.
cmd/break.go
Outdated
| Name: "stop", | ||
| Command: "break", | ||
| Args: getCommandArgs(cmd), |
Copilot
AI
Sep 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second hook call is missing both PomodoroID and BreakDuration fields that are provided in other similar hook calls. This creates inconsistency in the environment variables available to the 'stop' hook when called from different commands.
| Name: "stop", | |
| Command: "break", | |
| Args: getCommandArgs(cmd), | |
| Name: "stop", | |
| Command: "break", | |
| Args: getCommandArgs(cmd), | |
| BreakDuration: d, |
Address Copilot feedback: The stop hook called after a break should have access to the break duration environment variables.
- Simplify POMODORO_ID test to check for ID prefix instead of exact format (handles both -HH:MM and Z timezone formats) - Simplify test 42 to just verify POMODORO_ID is set instead of testing the show command within a hook (avoids timing/buffering issues in CI) Fixes test failures in GitHub Actions on both Ubuntu and macOS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Use proper regex to validate RFC3339 timestamp format instead of just checking for '20' prefix. Pattern matches YYYY-MM-DDTHH:MM:SS regardless of timezone format (Z or offset).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| return hook.Run(client, hook.Params{ | ||
| Name: "stop", | ||
| Command: "break", | ||
| Args: getCommandArgs(cmd), | ||
| BreakDuration: d, | ||
| }) |
Copilot
AI
Sep 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PomodoroID field is missing from the hook.Params struct. This will result in an empty POMODORO_ID environment variable being passed to the stop hook, which is inconsistent with other commands that properly set this field.
Summary
POMODORO_ID,POMODORO_DIRECTORY,POMODORO_COMMAND,POMODORO_ARGSPOMODORO_BREAK_DURATION_MINUTES,POMODORO_BREAK_DURATION_SECONDSbreakandfinish --breakwait by default (can disable with--wait=false)hook.Run()to use aParamsstruct for better maintainabilityChanges
Test plan
--wait=falseflag to skip countdown🤖 Generated with Claude Code