@@ -23,6 +23,19 @@ const AGENTS_SOURCE_DIR = getAgentsSourceDir(packageRoot)
2323/** Check for --dry-run flag in command line arguments */
2424const DRY_RUN = process . argv . includes ( "--dry-run" )
2525
26+ /** Check for --verbose flag in command line arguments */
27+ const VERBOSE = process . argv . includes ( "--verbose" )
28+
29+ /**
30+ * Logs verbose output if --verbose flag is set.
31+ * @param {string } message - The message to log
32+ */
33+ function verbose ( message ) {
34+ if ( VERBOSE ) {
35+ console . log ( `[VERBOSE] ${ message } ` )
36+ }
37+ }
38+
2639/** Minimum character count for valid agent files */
2740const MIN_CONTENT_LENGTH = 100
2841
@@ -172,24 +185,37 @@ function main() {
172185 const prefix = DRY_RUN ? "[DRY-RUN] " : ""
173186 console . log ( `${ prefix } opencode-plugin-opencoder: Installing agents...` )
174187
188+ verbose ( `Package root: ${ packageRoot } ` )
189+ verbose ( `Source directory: ${ AGENTS_SOURCE_DIR } ` )
190+ verbose ( `Target directory: ${ AGENTS_TARGET_DIR } ` )
191+ verbose ( `Dry run: ${ DRY_RUN } ` )
192+
175193 // Create target directory if it doesn't exist
176194 if ( ! existsSync ( AGENTS_TARGET_DIR ) ) {
195+ verbose ( `Target directory does not exist, creating...` )
177196 if ( DRY_RUN ) {
178197 console . log ( `${ prefix } Would create ${ AGENTS_TARGET_DIR } ` )
179198 } else {
180199 mkdirSync ( AGENTS_TARGET_DIR , { recursive : true } )
181200 console . log ( ` Created ${ AGENTS_TARGET_DIR } ` )
182201 }
202+ } else {
203+ verbose ( `Target directory already exists` )
183204 }
184205
185206 // Check if source directory exists
207+ verbose ( `Checking source directory exists...` )
186208 if ( ! existsSync ( AGENTS_SOURCE_DIR ) ) {
187209 console . error ( `${ prefix } Error: Source agents directory not found at ${ AGENTS_SOURCE_DIR } ` )
188210 process . exit ( 1 )
189211 }
212+ verbose ( `Source directory found` )
190213
191214 // Copy all .md files from agents/ to target
192- const files = readdirSync ( AGENTS_SOURCE_DIR ) . filter ( ( f ) => f . endsWith ( ".md" ) )
215+ const allFiles = readdirSync ( AGENTS_SOURCE_DIR )
216+ verbose ( `Files in source directory: ${ allFiles . join ( ", " ) || "(none)" } ` )
217+ const files = allFiles . filter ( ( f ) => f . endsWith ( ".md" ) )
218+ verbose ( `Markdown files found: ${ files . length } ` )
193219
194220 if ( files . length === 0 ) {
195221 console . error ( `${ prefix } Error: No agent files found in agents/ directory` )
@@ -202,34 +228,45 @@ function main() {
202228 for ( const file of files ) {
203229 const sourcePath = join ( AGENTS_SOURCE_DIR , file )
204230 const targetPath = join ( AGENTS_TARGET_DIR , file )
231+ verbose ( `Processing: ${ file } ` )
232+ verbose ( ` Source path: ${ sourcePath } ` )
233+ verbose ( ` Target path: ${ targetPath } ` )
205234
206235 try {
207236 if ( DRY_RUN ) {
208237 // In dry-run mode, validate source file but don't copy
238+ verbose ( ` Validating source file (dry-run mode)...` )
209239 const validation = validateAgentContent ( sourcePath )
210240 if ( ! validation . valid ) {
211241 throw new Error ( `Invalid agent file content: ${ validation . error } ` )
212242 }
243+ verbose ( ` Validation passed` )
213244 successes . push ( file )
214245 console . log ( `${ prefix } Would install: ${ file } -> ${ targetPath } ` )
215246 } else {
247+ verbose ( ` Copying file...` )
216248 copyFileSync ( sourcePath , targetPath )
217249
218250 // Verify the copy succeeded by comparing file sizes
219251 const sourceSize = statSync ( sourcePath ) . size
220252 const targetSize = statSync ( targetPath ) . size
253+ verbose ( ` Source size: ${ sourceSize } bytes` )
254+ verbose ( ` Target size: ${ targetSize } bytes` )
221255
222256 if ( sourceSize !== targetSize ) {
223257 throw new Error (
224258 `File size mismatch: source=${ sourceSize } bytes, target=${ targetSize } bytes` ,
225259 )
226260 }
261+ verbose ( ` Size verification passed` )
227262
228263 // Validate content structure
264+ verbose ( ` Validating content structure...` )
229265 const validation = validateAgentContent ( targetPath )
230266 if ( ! validation . valid ) {
231267 throw new Error ( `Invalid agent file content: ${ validation . error } ` )
232268 }
269+ verbose ( ` Validation passed` )
233270
234271 successes . push ( file )
235272 console . log ( ` Installed: ${ file } ` )
@@ -243,6 +280,7 @@ function main() {
243280 }
244281
245282 // Print summary
283+ verbose ( `Installation summary: ${ successes . length } succeeded, ${ failures . length } failed` )
246284 console . log ( "" )
247285 if ( successes . length > 0 && failures . length === 0 ) {
248286 console . log (
0 commit comments