88import type { PlatformId } from './types'
99import { chmodSync , existsSync , mkdirSync , readFileSync , unlinkSync , writeFileSync } from 'node:fs'
1010import process from 'node:process'
11+ import { createLogger } from '@pleaseai/logger'
1112import { spawn } from 'bun'
1213import {
1314 AST_GREP_VERSION ,
@@ -18,6 +19,8 @@ import {
1819 PLATFORM_CONFIGS ,
1920} from './constants'
2021
22+ const log = createLogger ( 'ast-grep' )
23+
2124/**
2225 * Verify a binary is actually ast-grep by checking --version output
2326 */
@@ -34,7 +37,7 @@ async function verifyAstGrepBinary(binaryPath: string): Promise<boolean> {
3437 return stdout . includes ( 'ast-grep' ) || / ^ \d + \. \d + \. \d + / . test ( stdout . trim ( ) )
3538 }
3639 catch ( e ) {
37- console . error ( `[ast-grep] Binary verification failed for ${ binaryPath } : ${ e instanceof Error ? e . message : String ( e ) } ` )
40+ log . warn ( { binaryPath, err : e } , 'Binary verification failed' )
3841 return false
3942 }
4043}
@@ -81,7 +84,7 @@ export function getCachedBinary(): string | null {
8184 }
8285 catch ( e ) {
8386 // Log warning but continue - will trigger re-download
84- console . warn ( `[ast-grep] Failed to read version marker at ${ versionPath } : ${ e instanceof Error ? e . message : String ( e ) } ` )
87+ log . warn ( { versionPath, err : e } , 'Failed to read version marker' )
8588 return null
8689 }
8790 }
@@ -129,13 +132,13 @@ async function extractZip(archivePath: string, destDir: string): Promise<void> {
129132export async function downloadAstGrepBinary ( platformId ?: PlatformId ) : Promise < string | null > {
130133 const platform = platformId ?? getPlatformId ( )
131134 if ( ! platform ) {
132- console . error ( '[dora] Unsupported platform for ast-grep binary download' )
135+ log . error ( 'Unsupported platform for ast-grep binary download' )
133136 return null
134137 }
135138
136139 const config = PLATFORM_CONFIGS [ platform ]
137140 if ( ! config ) {
138- console . error ( `[dora] No binary configuration for platform: ${ platform } ` )
141+ log . error ( { platform } , ' No binary configuration for platform' )
139142 return null
140143 }
141144
@@ -153,7 +156,7 @@ export async function downloadAstGrepBinary(platformId?: PlatformId): Promise<st
153156 }
154157 }
155158
156- console . log ( `[dora] Downloading ast-grep binary v ${ AST_GREP_VERSION } ...` )
159+ log . info ( { version : AST_GREP_VERSION } , ' Downloading ast-grep binary' )
157160
158161 try {
159162 // Create cache directory
@@ -188,12 +191,12 @@ export async function downloadAstGrepBinary(platformId?: PlatformId): Promise<st
188191 // Write version marker
189192 writeFileSync ( getVersionMarkerPath ( ) , AST_GREP_VERSION )
190193
191- console . log ( `[dora] ast-grep binary ready at ${ binaryPath } ` )
194+ log . info ( { binaryPath } , ' ast-grep binary ready' )
192195
193196 return binaryPath
194197 }
195198 catch ( err ) {
196- console . error ( `[dora] Failed to download ast-grep: ${ err instanceof Error ? err . message : err } ` )
199+ log . error ( { err } , ' Failed to download ast-grep' )
197200 return null
198201 }
199202}
0 commit comments