fix: Deduplicate hook entries in settings.json on repeated create_agent_session calls (#299)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
9852c5f03e
commit
63d4179f38
1 changed files with 8 additions and 2 deletions
|
|
@ -67,10 +67,13 @@ create_agent_session() {
|
||||||
if [ -f "$settings" ]; then
|
if [ -f "$settings" ]; then
|
||||||
# Append our Stop hook to existing project settings
|
# Append our Stop hook to existing project settings
|
||||||
jq --arg cmd "$hook_cmd" '
|
jq --arg cmd "$hook_cmd" '
|
||||||
.hooks.Stop = (.hooks.Stop // []) + [{
|
if (.hooks.Stop // [] | any(.[]; .hooks[]?.command == $cmd))
|
||||||
|
then .
|
||||||
|
else .hooks.Stop = (.hooks.Stop // []) + [{
|
||||||
matcher: "",
|
matcher: "",
|
||||||
hooks: [{type: "command", command: $cmd}]
|
hooks: [{type: "command", command: $cmd}]
|
||||||
}]
|
}]
|
||||||
|
end
|
||||||
' "$settings" > "${settings}.tmp" && mv "${settings}.tmp" "$settings"
|
' "$settings" > "${settings}.tmp" && mv "${settings}.tmp" "$settings"
|
||||||
else
|
else
|
||||||
jq -n --arg cmd "$hook_cmd" '{
|
jq -n --arg cmd "$hook_cmd" '{
|
||||||
|
|
@ -95,10 +98,13 @@ create_agent_session() {
|
||||||
local phase_hook_cmd="${phase_hook_script} ${phase_file} ${phase_marker}"
|
local phase_hook_cmd="${phase_hook_script} ${phase_file} ${phase_marker}"
|
||||||
if [ -f "$settings" ]; then
|
if [ -f "$settings" ]; then
|
||||||
jq --arg cmd "$phase_hook_cmd" '
|
jq --arg cmd "$phase_hook_cmd" '
|
||||||
.hooks.PostToolUse = (.hooks.PostToolUse // []) + [{
|
if (.hooks.PostToolUse // [] | any(.[]; .hooks[]?.command == $cmd))
|
||||||
|
then .
|
||||||
|
else .hooks.PostToolUse = (.hooks.PostToolUse // []) + [{
|
||||||
matcher: "Bash|Write",
|
matcher: "Bash|Write",
|
||||||
hooks: [{type: "command", command: $cmd}]
|
hooks: [{type: "command", command: $cmd}]
|
||||||
}]
|
}]
|
||||||
|
end
|
||||||
' "$settings" > "${settings}.tmp" && mv "${settings}.tmp" "$settings"
|
' "$settings" > "${settings}.tmp" && mv "${settings}.tmp" "$settings"
|
||||||
else
|
else
|
||||||
jq -n --arg cmd "$phase_hook_cmd" '{
|
jq -n --arg cmd "$phase_hook_cmd" '{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue