|
1 | 1 | #!/usr/bin/env bun |
2 | 2 |
|
3 | | -import * as fs from 'node:fs/promises' |
4 | | -import * as path from 'node:path' |
5 | | - |
6 | 3 | // Input payload types based on official Claude Code schemas |
7 | 4 | export interface PreToolUsePayload { |
8 | 5 | session_id: string |
@@ -143,42 +140,6 @@ export interface HookHandlers { |
143 | 140 | preCompact?: PreCompactHandler |
144 | 141 | } |
145 | 142 |
|
146 | | -// Session management utilities |
147 | | -const SESSIONS_DIR = path.join(process.cwd(), '.claude', 'hooks', 'sessions') |
148 | | - |
149 | | -export async function ensureSessionsDirectory(): Promise<void> { |
150 | | - try { |
151 | | - await fs.mkdir(SESSIONS_DIR, {recursive: true}) |
152 | | - } catch (error) { |
153 | | - console.error('Failed to create sessions directory:', error) |
154 | | - } |
155 | | -} |
156 | | - |
157 | | -export async function saveSessionData(hookType: string, payload: HookPayload): Promise<void> { |
158 | | - try { |
159 | | - const timestamp = new Date().toISOString() |
160 | | - const sessionFile = path.join(SESSIONS_DIR, `${payload.session_id}.json`) |
161 | | - |
162 | | - let sessionData: Array<{timestamp: string; hookType: string; payload: HookPayload}> = [] |
163 | | - try { |
164 | | - const existing = await fs.readFile(sessionFile, 'utf-8') |
165 | | - sessionData = JSON.parse(existing) |
166 | | - } catch { |
167 | | - // File doesn't exist yet |
168 | | - } |
169 | | - |
170 | | - sessionData.push({ |
171 | | - timestamp, |
172 | | - hookType, |
173 | | - payload, |
174 | | - }) |
175 | | - |
176 | | - await fs.writeFile(sessionFile, JSON.stringify(sessionData, null, 2)) |
177 | | - } catch (error) { |
178 | | - console.error('Failed to save session data:', error) |
179 | | - } |
180 | | -} |
181 | | - |
182 | 143 | // Logging utility |
183 | 144 | export function log(...args: unknown[]): void { |
184 | 145 | console.log(`[${new Date().toISOString()}]`, ...args) |
|
0 commit comments