Skip to content

Commit 29c021b

Browse files
committed
refactor(hooks): ensure notify-user hook only runs on success
1 parent 04f50eb commit 29c021b

4 files changed

Lines changed: 13 additions & 4 deletions

File tree

.gemini/hooks/journal.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ def main():
114114
f"New changes detected: {', '.join(new_significant_changes[:3])}{'...' if len(new_significant_changes) > 3 else ''}.\n"
115115
f"Please add or update a one-line entry to {journal_file} "
116116
"describing the work you just did. Do not stop until this file is updated."
117-
)
117+
),
118+
continue_flag=False
118119
)
119120

120121
except Exception as e:

.gemini/hooks/make.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def main():
117117
"```\n" + error_message.strip() + "\n```\n"
118118
"Fix these issues and ensure 'make' passes before continuing."
119119
)
120-
utils.send_hook_decision("deny", reason=fail_reason)
120+
utils.send_hook_decision("deny", reason=fail_reason, continue_flag=False)
121121
else:
122122
# make passed
123123
update_last_run_timestamp()

.gemini/hooks/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def log_message(message, mode="a"):
5858
except Exception:
5959
pass
6060

61-
def send_hook_decision(decision, reason=None, system_message=None, hook_output=None):
61+
def send_hook_decision(decision, reason=None, system_message=None, hook_output=None, continue_flag=None):
6262
"""
6363
Prints the standard JSON response for a Gemini CLI hook.
6464
@@ -67,6 +67,7 @@ def send_hook_decision(decision, reason=None, system_message=None, hook_output=N
6767
reason (str, optional): The reason for denial.
6868
system_message (str, optional): A system message to display to the user.
6969
hook_output (dict, optional): Additional context for the UI.
70+
continue_flag (bool, optional): Whether the hook loop should continue.
7071
"""
7172
response = {"decision": decision}
7273
if reason:
@@ -75,5 +76,7 @@ def send_hook_decision(decision, reason=None, system_message=None, hook_output=N
7576
response["systemMessage"] = system_message
7677
if hook_output:
7778
response["hookSpecificOutput"] = hook_output
79+
if continue_flag is not None:
80+
response["continue"] = continue_flag
7881

7982
print(json.dumps(response))

.gemini/settings.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,12 @@
7676
"name": "update-journal-and-changelog",
7777
"type": "command",
7878
"command": "python3 .gemini/hooks/journal.py"
79-
},
79+
}
80+
]
81+
},
82+
{
83+
"matcher": "*",
84+
"hooks": [
8085
{
8186
"name": "notify-user",
8287
"type": "command",

0 commit comments

Comments
 (0)