Skip to content
Merged
Show file tree
Hide file tree
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
39 changes: 0 additions & 39 deletions templates/hooks/lib.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#!/usr/bin/env bun

import * as fs from 'node:fs/promises'
import * as path from 'node:path'

// Input payload types based on official Claude Code schemas
export interface PreToolUsePayload {
session_id: string
Expand Down Expand Up @@ -143,42 +140,6 @@ export interface HookHandlers {
preCompact?: PreCompactHandler
}

// Session management utilities
const SESSIONS_DIR = path.join(process.cwd(), '.claude', 'hooks', 'sessions')

export async function ensureSessionsDirectory(): Promise<void> {
try {
await fs.mkdir(SESSIONS_DIR, {recursive: true})
} catch (error) {
console.error('Failed to create sessions directory:', error)
}
}

export async function saveSessionData(hookType: string, payload: HookPayload): Promise<void> {
try {
const timestamp = new Date().toISOString()
const sessionFile = path.join(SESSIONS_DIR, `${payload.session_id}.json`)

let sessionData: Array<{timestamp: string; hookType: string; payload: HookPayload}> = []
try {
const existing = await fs.readFile(sessionFile, 'utf-8')
sessionData = JSON.parse(existing)
} catch {
// File doesn't exist yet
}

sessionData.push({
timestamp,
hookType,
payload,
})

await fs.writeFile(sessionFile, JSON.stringify(sessionData, null, 2))
} catch (error) {
console.error('Failed to save session data:', error)
}
}

// Logging utility
export function log(...args: unknown[]): void {
console.log(`[${new Date().toISOString()}]`, ...args)
Expand Down
2 changes: 0 additions & 2 deletions test/smoke/generated-files.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,6 @@ describe.skip('Smoke Tests - Generated Files', () => {
it('should export utility functions', () => {
expect(libContent).to.include('export function log')
expect(libContent).to.include('export function runHook')
expect(libContent).to.include('export async function ensureSessionsDirectory')
expect(libContent).to.include('export async function saveSessionData')
})

it('should handle stdin for hook communication', () => {
Expand Down
Loading