@@ -28,6 +28,7 @@ const AGENTS_SOURCE_DIR = getAgentsSourceDir(packageRoot)
2828const flags = parseCliFlags ( process . argv )
2929const DRY_RUN = flags . dryRun
3030const VERBOSE = flags . verbose
31+ const QUIET = flags . quiet
3132
3233/** Print usage information and exit */
3334if ( flags . help ) {
@@ -38,18 +39,22 @@ Install OpenCoder agents to ~/.config/opencode/agents/
3839Options:
3940 --dry-run Simulate installation without copying files
4041 --verbose Enable verbose output for debugging
42+ --quiet Suppress non-error output (for CI environments)
4143 --help Show this help message and exit
4244
4345Examples:
4446 node postinstall.mjs # Install agents
4547 node postinstall.mjs --dry-run # Preview what would be installed
46- node postinstall.mjs --verbose # Install with detailed logging` )
48+ node postinstall.mjs --verbose # Install with detailed logging
49+ node postinstall.mjs --quiet # Install silently (errors only)` )
4750 process . exit ( 0 )
4851}
4952
50- /** Create logger with verbose flag */
51- const logger = createLogger ( VERBOSE )
53+ /** Create logger with verbose and quiet flags */
54+ const logger = createLogger ( VERBOSE , QUIET )
5255const verbose = logger . verbose
56+ const log = logger . log
57+ const logError = logger . error
5358
5459/**
5560 * Main entry point for the postinstall script.
@@ -79,7 +84,7 @@ const verbose = logger.verbose
7984 */
8085async function main ( ) {
8186 const prefix = DRY_RUN ? "[DRY-RUN] " : ""
82- console . log ( `${ prefix } opencode-plugin-opencoder: Installing agents...` )
87+ log ( `${ prefix } opencode-plugin-opencoder: Installing agents...` )
8388
8489 verbose ( `Package root: ${ packageRoot } ` )
8590 verbose ( `Source directory: ${ AGENTS_SOURCE_DIR } ` )
@@ -90,10 +95,10 @@ async function main() {
9095 if ( ! existsSync ( AGENTS_TARGET_DIR ) ) {
9196 verbose ( `Target directory does not exist, creating...` )
9297 if ( DRY_RUN ) {
93- console . log ( `${ prefix } Would create ${ AGENTS_TARGET_DIR } ` )
98+ log ( `${ prefix } Would create ${ AGENTS_TARGET_DIR } ` )
9499 } else {
95100 mkdirSync ( AGENTS_TARGET_DIR , { recursive : true } )
96- console . log ( ` Created ${ AGENTS_TARGET_DIR } ` )
101+ log ( ` Created ${ AGENTS_TARGET_DIR } ` )
97102 }
98103 } else {
99104 verbose ( `Target directory already exists` )
@@ -102,7 +107,7 @@ async function main() {
102107 // Check if source directory exists
103108 verbose ( `Checking source directory exists...` )
104109 if ( ! existsSync ( AGENTS_SOURCE_DIR ) ) {
105- console . error ( `${ prefix } Error: Source agents directory not found at ${ AGENTS_SOURCE_DIR } ` )
110+ logError ( `${ prefix } Error: Source agents directory not found at ${ AGENTS_SOURCE_DIR } ` )
106111 process . exit ( 1 )
107112 }
108113 verbose ( `Source directory found` )
@@ -114,7 +119,7 @@ async function main() {
114119 verbose ( `Markdown files found: ${ files . length } ` )
115120
116121 if ( files . length === 0 ) {
117- console . error ( `${ prefix } Error: No agent files found in agents/ directory` )
122+ logError ( `${ prefix } Error: No agent files found in agents/ directory` )
118123 process . exit ( 1 )
119124 }
120125
@@ -149,7 +154,7 @@ async function main() {
149154 }
150155 verbose ( ` Validation passed` )
151156 successes . push ( file )
152- console . log ( `${ prefix } Would install: ${ file } -> ${ targetPath } ` )
157+ log ( `${ prefix } Would install: ${ file } -> ${ targetPath } ` )
153158 } else {
154159 verbose ( ` Copying file...` )
155160 await retryOnTransientError ( ( ) => copyFileSync ( sourcePath , targetPath ) )
@@ -176,41 +181,44 @@ async function main() {
176181 verbose ( ` Validation passed` )
177182
178183 successes . push ( file )
179- console . log ( ` Installed: ${ file } ` )
184+ log ( ` Installed: ${ file } ` )
180185 }
181186 } catch ( err ) {
182187 const error = err instanceof Error ? err : new Error ( String ( err ) )
183188 const message = getErrorMessage ( error , file , targetPath )
184189 failures . push ( { file, message } )
185- console . error ( `${ prefix } Failed: ${ file } - ${ message } ` )
190+ logError ( `${ prefix } Failed: ${ file } - ${ message } ` )
186191 }
187192 }
188193
189194 // Print summary
190195 verbose ( `Installation summary: ${ successes . length } succeeded, ${ failures . length } failed` )
191- console . log ( "" )
196+ log ( "" )
192197 if ( successes . length > 0 && failures . length === 0 ) {
198+ // Final success message - always show even in quiet mode
193199 console . log (
194200 `${ prefix } opencode-plugin-opencoder: Successfully installed ${ successes . length } agent(s)` ,
195201 )
196- console . log ( `${ prefix } Location: ${ AGENTS_TARGET_DIR } ` )
202+ log ( `${ prefix } Location: ${ AGENTS_TARGET_DIR } ` )
197203 if ( ! DRY_RUN ) {
198- console . log ( "\nTo use the autonomous development loop, run:" )
199- console . log ( " opencode @opencoder" )
204+ log ( "\nTo use the autonomous development loop, run:" )
205+ log ( " opencode @opencoder" )
200206 }
201207 } else if ( successes . length > 0 && failures . length > 0 ) {
208+ // Final partial success message - always show even in quiet mode
202209 console . log (
203210 `${ prefix } opencode-plugin-opencoder: Installed ${ successes . length } of ${ files . length } agent(s)` ,
204211 )
205- console . log ( `${ prefix } Location: ${ AGENTS_TARGET_DIR } ` )
206- console . error ( `\n${ prefix } ${ failures . length } file(s) failed to install:` )
212+ log ( `${ prefix } Location: ${ AGENTS_TARGET_DIR } ` )
213+ logError ( `\n${ prefix } ${ failures . length } file(s) failed to install:` )
207214 for ( const { file, message } of failures ) {
208- console . error ( `${ prefix } - ${ file } : ${ message } ` )
215+ logError ( `${ prefix } - ${ file } : ${ message } ` )
209216 }
210217 } else {
218+ // Final failure message - always show
211219 console . error ( `${ prefix } opencode-plugin-opencoder: Failed to install any agents` )
212220 for ( const { file, message } of failures ) {
213- console . error ( `${ prefix } - ${ file } : ${ message } ` )
221+ logError ( `${ prefix } - ${ file } : ${ message } ` )
214222 }
215223 process . exit ( 1 )
216224 }
0 commit comments