Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions plugins/hookify/core/rule_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def evaluate_rules(self, rules: List[Rule], input_data: Dict[str, Any]) -> Dict[
"reason": combined_message,
"systemMessage": combined_message
}
elif hook_event in ['PreToolUse', 'PostToolUse']:
elif hook_event == 'PreToolUse':
# PreToolUse can deny the tool before it executes
return {
"hookSpecificOutput": {
"hookEventName": hook_event,
Expand All @@ -78,7 +79,7 @@ def evaluate_rules(self, rules: List[Rule], input_data: Dict[str, Any]) -> Dict[
"systemMessage": combined_message
}
else:
# For other events, just show message
# PostToolUse and other events: tool already ran, can only inject a message
return {
"systemMessage": combined_message
}
Expand Down
4 changes: 3 additions & 1 deletion plugins/hookify/hooks/posttooluse.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ def main():

# Determine event type based on tool
tool_name = input_data.get('tool_name', '')
event = None
if tool_name == 'Bash':
event = 'bash'
elif tool_name in ['Edit', 'Write', 'MultiEdit']:
event = 'file'
else:
# Unknown tool: only evaluate event=all rules.
event = 'all'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same concern as pretooluse.py — need to confirm load_rules(event='all') is a valid path and not a silent no-op for unknown tools.


# Load rules
rules = load_rules(event=event)
Expand Down
5 changes: 4 additions & 1 deletion plugins/hookify/hooks/pretooluse.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@ def main():
# For PreToolUse, we use tool_name to determine "bash" vs "file" event
tool_name = input_data.get('tool_name', '')

event = None
if tool_name == 'Bash':
event = 'bash'
elif tool_name in ['Edit', 'Write', 'MultiEdit']:
event = 'file'
else:
# Unknown tool: only evaluate event=all rules to avoid
# bash/file-specific rules running on unrelated tools.
event = 'all'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does load_rules(event='all') actually load? If all is not a recognized event type in the rules config, this will silently load nothing and unknown tools will pass through unfiltered without any rules being evaluated. Worth adding a test or at minimum a comment confirming all is handled correctly in load_rules.


# Load rules
rules = load_rules(event=event)
Expand Down
2 changes: 1 addition & 1 deletion scripts/auto-close-duplicates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ async function autoCloseDuplicates(): Promise<void> {
token
);

if (pageIssues.length === 0) break;
if (pageIssues.length < perPage) break;

// Filter for issues created more than 3 days ago
const oldEnoughIssues = pageIssues.filter(issue =>
Expand Down
2 changes: 1 addition & 1 deletion scripts/backfill-duplicate-comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Environment Variables:
token
);

if (pageIssues.length === 0) break;
if (pageIssues.length < perPage) break;

// Filter to only include issues within the specified range
const filteredIssues = pageIssues.filter(issue =>
Expand Down
21 changes: 17 additions & 4 deletions scripts/sweep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ async function githubRequest<T>(

// --

async function fetchAllPages<T>(baseEndpoint: string): Promise<T[]> {
const all: T[] = [];
for (let page = 1; ; page++) {
const sep = baseEndpoint.includes("?") ? "&" : "?";
const items = await githubRequest<T[]>(`${baseEndpoint}${sep}page=${page}`);
all.push(...items);
if (items.length < 100) break;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The page size is hardcoded to 100 here, but fetchAllPages has no knowledge of what per_page value the caller used in their URL. If a caller ever passes per_page=50, this will silently stop early and miss data. Consider accepting perPage as a parameter:

async function fetchAllPages<T>(baseEndpoint: string, perPage = 100): Promise<T[]> {
  ...
  if (items.length < perPage) break;
}

This makes the contract explicit and safe to reuse.

}
return all;
}

// --

async function markStale(owner: string, repo: string) {
const staleDays = lifecycle.find((l) => l.label === "stale")!.days;
const cutoff = new Date();
Expand All @@ -55,7 +68,7 @@ async function markStale(owner: string, repo: string) {
const issues = await githubRequest<any[]>(
`/repos/${owner}/${repo}/issues?state=open&sort=updated&direction=asc&per_page=100&page=${page}`
);
if (issues.length === 0) break;
if (issues.length < 100) break;

for (const issue of issues) {
if (issue.pull_request) continue;
Expand Down Expand Up @@ -101,7 +114,7 @@ async function closeExpired(owner: string, repo: string) {
const issues = await githubRequest<any[]>(
`/repos/${owner}/${repo}/issues?state=open&labels=${label}&sort=updated&direction=asc&per_page=100&page=${page}`
);
if (issues.length === 0) break;
if (issues.length < 100) break;

for (const issue of issues) {
if (issue.pull_request) continue;
Expand All @@ -112,7 +125,7 @@ async function closeExpired(owner: string, repo: string) {

const base = `/repos/${owner}/${repo}/issues/${issue.number}`;

const events = await githubRequest<any[]>(`${base}/events?per_page=100`);
const events = await fetchAllPages<any>(`${base}/events?per_page=100`);

const labeledAt = events
.filter((e) => e.event === "labeled" && e.label?.name === label)
Expand All @@ -124,7 +137,7 @@ async function closeExpired(owner: string, repo: string) {
// Skip if a non-bot user commented after the label was applied.
// The triage workflow should remove lifecycle labels on human
// activity, but check here too as a safety net.
const comments = await githubRequest<any[]>(
const comments = await fetchAllPages<any>(
`${base}/comments?since=${labeledAt.toISOString()}&per_page=100`
);
const hasHumanComment = comments.some(
Expand Down