Skip to content
Merged
Changes from all 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
4 changes: 1 addition & 3 deletions templates/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env bun

import {
type BashToolInput,
type NotificationPayload,
type PostToolUsePayload,
type PreToolUsePayload,
Expand All @@ -25,8 +24,7 @@ async function preToolUse(payload: PreToolUsePayload): Promise<PreToolUseRespons

// Example: Track bash commands
if (payload.tool_name === 'Bash' && payload.tool_input && 'command' in payload.tool_input) {
const bashInput = payload.tool_input as BashToolInput
const command = bashInput.command
const command = (payload.tool_input as {command: string}).command
console.log(`🚀 Running command: ${command}`)
Comment on lines 26 to 28
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Prefer a type-guard to eliminate the unsafe cast

The direct assertion (payload.tool_input as {command: string}).command silently trusts the payload’s shape. A tiny, locally-scoped type-guard keeps the compiler on your side and avoids re-introducing the deprecated double-assertion pattern:

-type BashToolInput = {command: string}
-function isBashToolInput(input: unknown): input is BashToolInput {
-  return !!input && typeof (input as any).command === 'string'
-}
-
-if (payload.tool_name === 'Bash' && isBashToolInput(payload.tool_input)) {
-  const {command} = payload.tool_input
+type BashToolInput = {command: string}
+function isBashToolInput(input: unknown): input is BashToolInput {
+  return !!input && typeof (input as any).command === 'string'
+}
+
+if (payload.tool_name === 'Bash' && isBashToolInput(payload.tool_input)) {
+  const {command} = payload.tool_input
   console.log(`🚀 Running command: ${command}`)

This keeps the file self-contained (no additional import) while giving the compiler a real guard instead of a blind cast.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In templates/hooks/index.ts around lines 26 to 28, replace the direct type
assertion of payload.tool_input with a locally defined type-guard function that
checks if tool_input has a command property of type string. Use this type-guard
to safely access the command property without casting, ensuring type safety and
avoiding deprecated double-assertion patterns.


// Block dangerous commands
Expand Down