@codyswann/lisa 4.103.11 → 4.103.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/codex/scripts/block-suppress-directives.sh +120 -26
- package/dist/core/nightly-e2e-guard-behavior-certificate.js +2 -2
- package/dist/core/upstream-evidence-manifest.d.ts.map +1 -1
- package/dist/core/upstream-evidence-manifest.js +4 -1
- package/dist/core/upstream-evidence-manifest.js.map +1 -1
- package/dist/opencode/plugin-templates/lisa-block-suppress-directives.ts +72 -22
- package/package.json +4 -4
- package/plugins/lisa/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-agy/plugin.json +1 -1
- package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-agy/plugin.json +1 -1
- package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-agy/plugin.json +1 -1
- package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-agy/plugin.json +1 -1
- package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-agy/plugin.json +1 -1
- package/plugins/lisa-openclaw-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-agy/plugin.json +1 -1
- package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-agy/plugin.json +1 -1
- package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/hooks/block-suppress-directives.sh +104 -14
- package/plugins/lisa-typescript-agy/plugin.json +1 -1
- package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-copilot/hooks/block-suppress-directives.sh +104 -14
- package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-cursor/hooks/block-suppress-directives.sh +104 -14
- package/plugins/lisa-typescript-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-devin/hooks/block-suppress-directives.sh +104 -14
- package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-agy/plugin.json +1 -1
- package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/src/typescript/hooks/block-suppress-directives.sh +104 -14
|
@@ -8,9 +8,16 @@
|
|
|
8
8
|
# base "ASK FIRST" governance rule). The agent should stop and get the user's
|
|
9
9
|
# approval rather than slip a suppression past silently.
|
|
10
10
|
#
|
|
11
|
-
#
|
|
12
|
-
#
|
|
13
|
-
#
|
|
11
|
+
# Refuses directive GROWTH, not presence: a directive in the after text that the
|
|
12
|
+
# before text lacks (new, another copy, or reworded) refuses; keeping or
|
|
13
|
+
# removing one is allowed. Write judges the whole file (disk vs content).
|
|
14
|
+
# Edit/MultiEdit judge each replaced fragment on its own (old_string vs
|
|
15
|
+
# new_string), so a widening done purely by deleting text from an existing
|
|
16
|
+
# directive, or a directive assembled across separate edits, is NOT detected —
|
|
17
|
+
# a pre-existing limit, shared with the presence check this replaced.
|
|
18
|
+
# Scoped to JS/TS files, and matches the directive only in comment syntax
|
|
19
|
+
# (// or /*) so prose, strings, and identifiers that merely mention these
|
|
20
|
+
# tokens are not flagged.
|
|
14
21
|
# Exit code 2 blocks the tool call and surfaces stderr to Claude.
|
|
15
22
|
# Reference: https://docs.claude.com/en/docs/claude-code/hooks
|
|
16
23
|
#
|
|
@@ -99,23 +106,106 @@ if [ -n "${CLAUDE_PROJECT_DIR:-}" ] &&
|
|
|
99
106
|
fi
|
|
100
107
|
fi
|
|
101
108
|
|
|
102
|
-
#
|
|
103
|
-
#
|
|
104
|
-
#
|
|
105
|
-
#
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
109
|
+
# ---------------------------------------------------------------------------
|
|
110
|
+
# Built-in: refuse directive GROWTH, never mere presence (CodySwannGT/lisa#4492).
|
|
111
|
+
#
|
|
112
|
+
# Rewriting a file that already carried an approved, scoped disable used to be
|
|
113
|
+
# refused as if the agent had added it, which taught agents to dodge the hook
|
|
114
|
+
# rather than heed it. The judgement is BEFORE versus AFTER:
|
|
115
|
+
# Write -> before = the file on disk (nothing when it does not exist),
|
|
116
|
+
# after = tool_input.content
|
|
117
|
+
# Edit -> before = tool_input.old_string, after = tool_input.new_string
|
|
118
|
+
# MultiEdit -> each edits[] pair judged the same way, on its own
|
|
119
|
+
# Each directive is taken from its comment opener to the end of its line, so a
|
|
120
|
+
# directive that is added, copied again, or reworded (a `-next-line` disable
|
|
121
|
+
# turned file-wide, a longer rule list) is new text, and is growth.
|
|
122
|
+
# ---------------------------------------------------------------------------
|
|
112
123
|
|
|
113
124
|
# Comment-syntax-only match: a // or /* opener, optional whitespace, then the
|
|
114
125
|
# suppression directive. @ts-expect-error is intentionally NOT matched — it is
|
|
115
126
|
# the safer alternative this hook steers toward.
|
|
116
127
|
DIRECTIVE_RE='(//|/\*)[[:space:]]*(@ts-(ignore|nocheck)|eslint-disable|biome-ignore|prettier-ignore)'
|
|
117
128
|
|
|
118
|
-
|
|
129
|
+
# The directives in $1, one per line and sorted, so the lists are multisets
|
|
130
|
+
# `comm` can subtract. Trailing whitespace (and a CR) is not part of one.
|
|
131
|
+
directives_in() {
|
|
132
|
+
printf '%s\n' "$1" | grep -Eo "${DIRECTIVE_RE}.*" |
|
|
133
|
+
sed 's/[[:space:]]*$//' | LC_ALL=C sort
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
# True when $2 (after) carries a directive $1 (before) does not. `comm -13`
|
|
137
|
+
# pairs repeated lines one-for-one, so a further copy of an existing directive
|
|
138
|
+
# is left over, and counts.
|
|
139
|
+
grows() {
|
|
140
|
+
[ -n "$(LC_ALL=C comm -13 <(directives_in "$1") <(directives_in "$2"))" ]
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
# The file a Write replaces, on stdout. A relative path is the project's, so it
|
|
144
|
+
# resolves against CLAUDE_PROJECT_DIR whichever directory this runs in. Nothing
|
|
145
|
+
# there is a new file (empty before). Something there that is not a readable
|
|
146
|
+
# regular file — a directory, a dangling link, no read permission — cannot be
|
|
147
|
+
# judged, so this fails and the caller refuses.
|
|
148
|
+
read_before() {
|
|
149
|
+
local target="$FILE_PATH"
|
|
150
|
+
case "$target" in
|
|
151
|
+
/*) ;;
|
|
152
|
+
*) target="${CLAUDE_PROJECT_DIR:-.}/$target" ;;
|
|
153
|
+
esac
|
|
154
|
+
[ -e "$target" ] || [ -L "$target" ] || return 0
|
|
155
|
+
[ -f "$target" ] && [ -r "$target" ] || return 1
|
|
156
|
+
cat -- "$target"
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
# The edit object $1: tool_input itself for Edit, edits[$1] for MultiEdit.
|
|
160
|
+
EDIT_AT='.tool_input | (if (.edits // null) != null then .edits[$i] else . end)'
|
|
161
|
+
|
|
162
|
+
# One string field ($2) of edit $1, empty when absent.
|
|
163
|
+
edit_field() {
|
|
164
|
+
printf '%s' "$JSON_INPUT" |
|
|
165
|
+
jq -r --argjson i "$1" --arg f "$2" "$EDIT_AT | .[\$f] // empty"
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
# True when edit $1 grows the directives. One that brings a directive with no
|
|
169
|
+
# old_string to compare against cannot be judged, and counts as growth.
|
|
170
|
+
edit_grows() {
|
|
171
|
+
local new
|
|
172
|
+
new="$(edit_field "$1" new_string)"
|
|
173
|
+
[ -n "$(directives_in "$new")" ] || return 1
|
|
174
|
+
printf '%s' "$JSON_INPUT" |
|
|
175
|
+
jq -e --argjson i "$1" "$EDIT_AT | (.old_string | type) == \"string\"" \
|
|
176
|
+
>/dev/null || return 0
|
|
177
|
+
grows "$(edit_field "$1" old_string)" "$new"
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
# True when any edit grows. An edit count that is not a number is unjudgeable.
|
|
181
|
+
any_edit_grows() {
|
|
182
|
+
local count i=0
|
|
183
|
+
count="$(printf '%s' "$JSON_INPUT" |
|
|
184
|
+
jq '.tool_input | if (.edits // null) != null then (.edits | length) else 1 end')"
|
|
185
|
+
case "$count" in '' | *[!0-9]*) return 0 ;; esac
|
|
186
|
+
while [ "$i" -lt "$count" ]; do
|
|
187
|
+
edit_grows "$i" && return 0
|
|
188
|
+
i=$((i + 1))
|
|
189
|
+
done
|
|
190
|
+
return 1
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
# True when the write grows the directives; Write when content is present.
|
|
194
|
+
write_grows() {
|
|
195
|
+
local before after
|
|
196
|
+
if printf '%s' "$JSON_INPUT" |
|
|
197
|
+
jq -e '(.tool_input.content // null) != null' >/dev/null; then
|
|
198
|
+
after="$(printf '%s' "$JSON_INPUT" | jq -r '.tool_input.content')"
|
|
199
|
+
# Nothing in the new text means nothing can have grown; no read needed.
|
|
200
|
+
[ -n "$(directives_in "$after")" ] || return 1
|
|
201
|
+
before="$(read_before)" || return 0
|
|
202
|
+
grows "$before" "$after"
|
|
203
|
+
return
|
|
204
|
+
fi
|
|
205
|
+
any_edit_grows
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if write_grows; then
|
|
119
209
|
cat >&2 <<MSG
|
|
120
210
|
❌ Blocked: error-suppression directive in $FILE_PATH
|
|
121
211
|
|
|
@@ -8,9 +8,16 @@
|
|
|
8
8
|
# base "ASK FIRST" governance rule). The agent should stop and get the user's
|
|
9
9
|
# approval rather than slip a suppression past silently.
|
|
10
10
|
#
|
|
11
|
-
#
|
|
12
|
-
#
|
|
13
|
-
#
|
|
11
|
+
# Refuses directive GROWTH, not presence: a directive in the after text that the
|
|
12
|
+
# before text lacks (new, another copy, or reworded) refuses; keeping or
|
|
13
|
+
# removing one is allowed. Write judges the whole file (disk vs content).
|
|
14
|
+
# Edit/MultiEdit judge each replaced fragment on its own (old_string vs
|
|
15
|
+
# new_string), so a widening done purely by deleting text from an existing
|
|
16
|
+
# directive, or a directive assembled across separate edits, is NOT detected —
|
|
17
|
+
# a pre-existing limit, shared with the presence check this replaced.
|
|
18
|
+
# Scoped to JS/TS files, and matches the directive only in comment syntax
|
|
19
|
+
# (// or /*) so prose, strings, and identifiers that merely mention these
|
|
20
|
+
# tokens are not flagged.
|
|
14
21
|
# Exit code 2 blocks the tool call and surfaces stderr to Claude.
|
|
15
22
|
# Reference: https://docs.claude.com/en/docs/claude-code/hooks
|
|
16
23
|
#
|
|
@@ -99,23 +106,106 @@ if [ -n "${CLAUDE_PROJECT_DIR:-}" ] &&
|
|
|
99
106
|
fi
|
|
100
107
|
fi
|
|
101
108
|
|
|
102
|
-
#
|
|
103
|
-
#
|
|
104
|
-
#
|
|
105
|
-
#
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
109
|
+
# ---------------------------------------------------------------------------
|
|
110
|
+
# Built-in: refuse directive GROWTH, never mere presence (CodySwannGT/lisa#4492).
|
|
111
|
+
#
|
|
112
|
+
# Rewriting a file that already carried an approved, scoped disable used to be
|
|
113
|
+
# refused as if the agent had added it, which taught agents to dodge the hook
|
|
114
|
+
# rather than heed it. The judgement is BEFORE versus AFTER:
|
|
115
|
+
# Write -> before = the file on disk (nothing when it does not exist),
|
|
116
|
+
# after = tool_input.content
|
|
117
|
+
# Edit -> before = tool_input.old_string, after = tool_input.new_string
|
|
118
|
+
# MultiEdit -> each edits[] pair judged the same way, on its own
|
|
119
|
+
# Each directive is taken from its comment opener to the end of its line, so a
|
|
120
|
+
# directive that is added, copied again, or reworded (a `-next-line` disable
|
|
121
|
+
# turned file-wide, a longer rule list) is new text, and is growth.
|
|
122
|
+
# ---------------------------------------------------------------------------
|
|
112
123
|
|
|
113
124
|
# Comment-syntax-only match: a // or /* opener, optional whitespace, then the
|
|
114
125
|
# suppression directive. @ts-expect-error is intentionally NOT matched — it is
|
|
115
126
|
# the safer alternative this hook steers toward.
|
|
116
127
|
DIRECTIVE_RE='(//|/\*)[[:space:]]*(@ts-(ignore|nocheck)|eslint-disable|biome-ignore|prettier-ignore)'
|
|
117
128
|
|
|
118
|
-
|
|
129
|
+
# The directives in $1, one per line and sorted, so the lists are multisets
|
|
130
|
+
# `comm` can subtract. Trailing whitespace (and a CR) is not part of one.
|
|
131
|
+
directives_in() {
|
|
132
|
+
printf '%s\n' "$1" | grep -Eo "${DIRECTIVE_RE}.*" |
|
|
133
|
+
sed 's/[[:space:]]*$//' | LC_ALL=C sort
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
# True when $2 (after) carries a directive $1 (before) does not. `comm -13`
|
|
137
|
+
# pairs repeated lines one-for-one, so a further copy of an existing directive
|
|
138
|
+
# is left over, and counts.
|
|
139
|
+
grows() {
|
|
140
|
+
[ -n "$(LC_ALL=C comm -13 <(directives_in "$1") <(directives_in "$2"))" ]
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
# The file a Write replaces, on stdout. A relative path is the project's, so it
|
|
144
|
+
# resolves against CLAUDE_PROJECT_DIR whichever directory this runs in. Nothing
|
|
145
|
+
# there is a new file (empty before). Something there that is not a readable
|
|
146
|
+
# regular file — a directory, a dangling link, no read permission — cannot be
|
|
147
|
+
# judged, so this fails and the caller refuses.
|
|
148
|
+
read_before() {
|
|
149
|
+
local target="$FILE_PATH"
|
|
150
|
+
case "$target" in
|
|
151
|
+
/*) ;;
|
|
152
|
+
*) target="${CLAUDE_PROJECT_DIR:-.}/$target" ;;
|
|
153
|
+
esac
|
|
154
|
+
[ -e "$target" ] || [ -L "$target" ] || return 0
|
|
155
|
+
[ -f "$target" ] && [ -r "$target" ] || return 1
|
|
156
|
+
cat -- "$target"
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
# The edit object $1: tool_input itself for Edit, edits[$1] for MultiEdit.
|
|
160
|
+
EDIT_AT='.tool_input | (if (.edits // null) != null then .edits[$i] else . end)'
|
|
161
|
+
|
|
162
|
+
# One string field ($2) of edit $1, empty when absent.
|
|
163
|
+
edit_field() {
|
|
164
|
+
printf '%s' "$JSON_INPUT" |
|
|
165
|
+
jq -r --argjson i "$1" --arg f "$2" "$EDIT_AT | .[\$f] // empty"
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
# True when edit $1 grows the directives. One that brings a directive with no
|
|
169
|
+
# old_string to compare against cannot be judged, and counts as growth.
|
|
170
|
+
edit_grows() {
|
|
171
|
+
local new
|
|
172
|
+
new="$(edit_field "$1" new_string)"
|
|
173
|
+
[ -n "$(directives_in "$new")" ] || return 1
|
|
174
|
+
printf '%s' "$JSON_INPUT" |
|
|
175
|
+
jq -e --argjson i "$1" "$EDIT_AT | (.old_string | type) == \"string\"" \
|
|
176
|
+
>/dev/null || return 0
|
|
177
|
+
grows "$(edit_field "$1" old_string)" "$new"
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
# True when any edit grows. An edit count that is not a number is unjudgeable.
|
|
181
|
+
any_edit_grows() {
|
|
182
|
+
local count i=0
|
|
183
|
+
count="$(printf '%s' "$JSON_INPUT" |
|
|
184
|
+
jq '.tool_input | if (.edits // null) != null then (.edits | length) else 1 end')"
|
|
185
|
+
case "$count" in '' | *[!0-9]*) return 0 ;; esac
|
|
186
|
+
while [ "$i" -lt "$count" ]; do
|
|
187
|
+
edit_grows "$i" && return 0
|
|
188
|
+
i=$((i + 1))
|
|
189
|
+
done
|
|
190
|
+
return 1
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
# True when the write grows the directives; Write when content is present.
|
|
194
|
+
write_grows() {
|
|
195
|
+
local before after
|
|
196
|
+
if printf '%s' "$JSON_INPUT" |
|
|
197
|
+
jq -e '(.tool_input.content // null) != null' >/dev/null; then
|
|
198
|
+
after="$(printf '%s' "$JSON_INPUT" | jq -r '.tool_input.content')"
|
|
199
|
+
# Nothing in the new text means nothing can have grown; no read needed.
|
|
200
|
+
[ -n "$(directives_in "$after")" ] || return 1
|
|
201
|
+
before="$(read_before)" || return 0
|
|
202
|
+
grows "$before" "$after"
|
|
203
|
+
return
|
|
204
|
+
fi
|
|
205
|
+
any_edit_grows
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if write_grows; then
|
|
119
209
|
cat >&2 <<MSG
|
|
120
210
|
❌ Blocked: error-suppression directive in $FILE_PATH
|
|
121
211
|
|
|
@@ -8,9 +8,16 @@
|
|
|
8
8
|
# base "ASK FIRST" governance rule). The agent should stop and get the user's
|
|
9
9
|
# approval rather than slip a suppression past silently.
|
|
10
10
|
#
|
|
11
|
-
#
|
|
12
|
-
#
|
|
13
|
-
#
|
|
11
|
+
# Refuses directive GROWTH, not presence: a directive in the after text that the
|
|
12
|
+
# before text lacks (new, another copy, or reworded) refuses; keeping or
|
|
13
|
+
# removing one is allowed. Write judges the whole file (disk vs content).
|
|
14
|
+
# Edit/MultiEdit judge each replaced fragment on its own (old_string vs
|
|
15
|
+
# new_string), so a widening done purely by deleting text from an existing
|
|
16
|
+
# directive, or a directive assembled across separate edits, is NOT detected —
|
|
17
|
+
# a pre-existing limit, shared with the presence check this replaced.
|
|
18
|
+
# Scoped to JS/TS files, and matches the directive only in comment syntax
|
|
19
|
+
# (// or /*) so prose, strings, and identifiers that merely mention these
|
|
20
|
+
# tokens are not flagged.
|
|
14
21
|
# Exit code 2 blocks the tool call and surfaces stderr to Claude.
|
|
15
22
|
# Reference: https://docs.claude.com/en/docs/claude-code/hooks
|
|
16
23
|
#
|
|
@@ -99,23 +106,106 @@ if [ -n "${CLAUDE_PROJECT_DIR:-}" ] &&
|
|
|
99
106
|
fi
|
|
100
107
|
fi
|
|
101
108
|
|
|
102
|
-
#
|
|
103
|
-
#
|
|
104
|
-
#
|
|
105
|
-
#
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
109
|
+
# ---------------------------------------------------------------------------
|
|
110
|
+
# Built-in: refuse directive GROWTH, never mere presence (CodySwannGT/lisa#4492).
|
|
111
|
+
#
|
|
112
|
+
# Rewriting a file that already carried an approved, scoped disable used to be
|
|
113
|
+
# refused as if the agent had added it, which taught agents to dodge the hook
|
|
114
|
+
# rather than heed it. The judgement is BEFORE versus AFTER:
|
|
115
|
+
# Write -> before = the file on disk (nothing when it does not exist),
|
|
116
|
+
# after = tool_input.content
|
|
117
|
+
# Edit -> before = tool_input.old_string, after = tool_input.new_string
|
|
118
|
+
# MultiEdit -> each edits[] pair judged the same way, on its own
|
|
119
|
+
# Each directive is taken from its comment opener to the end of its line, so a
|
|
120
|
+
# directive that is added, copied again, or reworded (a `-next-line` disable
|
|
121
|
+
# turned file-wide, a longer rule list) is new text, and is growth.
|
|
122
|
+
# ---------------------------------------------------------------------------
|
|
112
123
|
|
|
113
124
|
# Comment-syntax-only match: a // or /* opener, optional whitespace, then the
|
|
114
125
|
# suppression directive. @ts-expect-error is intentionally NOT matched — it is
|
|
115
126
|
# the safer alternative this hook steers toward.
|
|
116
127
|
DIRECTIVE_RE='(//|/\*)[[:space:]]*(@ts-(ignore|nocheck)|eslint-disable|biome-ignore|prettier-ignore)'
|
|
117
128
|
|
|
118
|
-
|
|
129
|
+
# The directives in $1, one per line and sorted, so the lists are multisets
|
|
130
|
+
# `comm` can subtract. Trailing whitespace (and a CR) is not part of one.
|
|
131
|
+
directives_in() {
|
|
132
|
+
printf '%s\n' "$1" | grep -Eo "${DIRECTIVE_RE}.*" |
|
|
133
|
+
sed 's/[[:space:]]*$//' | LC_ALL=C sort
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
# True when $2 (after) carries a directive $1 (before) does not. `comm -13`
|
|
137
|
+
# pairs repeated lines one-for-one, so a further copy of an existing directive
|
|
138
|
+
# is left over, and counts.
|
|
139
|
+
grows() {
|
|
140
|
+
[ -n "$(LC_ALL=C comm -13 <(directives_in "$1") <(directives_in "$2"))" ]
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
# The file a Write replaces, on stdout. A relative path is the project's, so it
|
|
144
|
+
# resolves against CLAUDE_PROJECT_DIR whichever directory this runs in. Nothing
|
|
145
|
+
# there is a new file (empty before). Something there that is not a readable
|
|
146
|
+
# regular file — a directory, a dangling link, no read permission — cannot be
|
|
147
|
+
# judged, so this fails and the caller refuses.
|
|
148
|
+
read_before() {
|
|
149
|
+
local target="$FILE_PATH"
|
|
150
|
+
case "$target" in
|
|
151
|
+
/*) ;;
|
|
152
|
+
*) target="${CLAUDE_PROJECT_DIR:-.}/$target" ;;
|
|
153
|
+
esac
|
|
154
|
+
[ -e "$target" ] || [ -L "$target" ] || return 0
|
|
155
|
+
[ -f "$target" ] && [ -r "$target" ] || return 1
|
|
156
|
+
cat -- "$target"
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
# The edit object $1: tool_input itself for Edit, edits[$1] for MultiEdit.
|
|
160
|
+
EDIT_AT='.tool_input | (if (.edits // null) != null then .edits[$i] else . end)'
|
|
161
|
+
|
|
162
|
+
# One string field ($2) of edit $1, empty when absent.
|
|
163
|
+
edit_field() {
|
|
164
|
+
printf '%s' "$JSON_INPUT" |
|
|
165
|
+
jq -r --argjson i "$1" --arg f "$2" "$EDIT_AT | .[\$f] // empty"
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
# True when edit $1 grows the directives. One that brings a directive with no
|
|
169
|
+
# old_string to compare against cannot be judged, and counts as growth.
|
|
170
|
+
edit_grows() {
|
|
171
|
+
local new
|
|
172
|
+
new="$(edit_field "$1" new_string)"
|
|
173
|
+
[ -n "$(directives_in "$new")" ] || return 1
|
|
174
|
+
printf '%s' "$JSON_INPUT" |
|
|
175
|
+
jq -e --argjson i "$1" "$EDIT_AT | (.old_string | type) == \"string\"" \
|
|
176
|
+
>/dev/null || return 0
|
|
177
|
+
grows "$(edit_field "$1" old_string)" "$new"
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
# True when any edit grows. An edit count that is not a number is unjudgeable.
|
|
181
|
+
any_edit_grows() {
|
|
182
|
+
local count i=0
|
|
183
|
+
count="$(printf '%s' "$JSON_INPUT" |
|
|
184
|
+
jq '.tool_input | if (.edits // null) != null then (.edits | length) else 1 end')"
|
|
185
|
+
case "$count" in '' | *[!0-9]*) return 0 ;; esac
|
|
186
|
+
while [ "$i" -lt "$count" ]; do
|
|
187
|
+
edit_grows "$i" && return 0
|
|
188
|
+
i=$((i + 1))
|
|
189
|
+
done
|
|
190
|
+
return 1
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
# True when the write grows the directives; Write when content is present.
|
|
194
|
+
write_grows() {
|
|
195
|
+
local before after
|
|
196
|
+
if printf '%s' "$JSON_INPUT" |
|
|
197
|
+
jq -e '(.tool_input.content // null) != null' >/dev/null; then
|
|
198
|
+
after="$(printf '%s' "$JSON_INPUT" | jq -r '.tool_input.content')"
|
|
199
|
+
# Nothing in the new text means nothing can have grown; no read needed.
|
|
200
|
+
[ -n "$(directives_in "$after")" ] || return 1
|
|
201
|
+
before="$(read_before)" || return 0
|
|
202
|
+
grows "$before" "$after"
|
|
203
|
+
return
|
|
204
|
+
fi
|
|
205
|
+
any_edit_grows
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if write_grows; then
|
|
119
209
|
cat >&2 <<MSG
|
|
120
210
|
❌ Blocked: error-suppression directive in $FILE_PATH
|
|
121
211
|
|