@@ -20,6 +20,9 @@ import {
2020const packageRoot = getPackageRoot ( import . meta. url )
2121const AGENTS_SOURCE_DIR = getAgentsSourceDir ( packageRoot )
2222
23+ /** Check for --dry-run flag in command line arguments */
24+ const DRY_RUN = process . argv . includes ( "--dry-run" )
25+
2326/** Minimum character count for valid agent files */
2427const MIN_CONTENT_LENGTH = 100
2528
@@ -89,25 +92,30 @@ function validateAgentContent(filePath) {
8992 * or all file copies failed
9093 */
9194function main ( ) {
92- console . log ( "opencode-plugin-opencoder: Installing agents..." )
95+ const prefix = DRY_RUN ? "[DRY-RUN] " : ""
96+ console . log ( `${ prefix } opencode-plugin-opencoder: Installing agents...` )
9397
9498 // Create target directory if it doesn't exist
9599 if ( ! existsSync ( AGENTS_TARGET_DIR ) ) {
96- mkdirSync ( AGENTS_TARGET_DIR , { recursive : true } )
97- console . log ( ` Created ${ AGENTS_TARGET_DIR } ` )
100+ if ( DRY_RUN ) {
101+ console . log ( `${ prefix } Would create ${ AGENTS_TARGET_DIR } ` )
102+ } else {
103+ mkdirSync ( AGENTS_TARGET_DIR , { recursive : true } )
104+ console . log ( ` Created ${ AGENTS_TARGET_DIR } ` )
105+ }
98106 }
99107
100108 // Check if source directory exists
101109 if ( ! existsSync ( AGENTS_SOURCE_DIR ) ) {
102- console . error ( ` Error: Source agents directory not found at ${ AGENTS_SOURCE_DIR } ` )
110+ console . error ( `${ prefix } Error: Source agents directory not found at ${ AGENTS_SOURCE_DIR } ` )
103111 process . exit ( 1 )
104112 }
105113
106114 // Copy all .md files from agents/ to target
107115 const files = readdirSync ( AGENTS_SOURCE_DIR ) . filter ( ( f ) => f . endsWith ( ".md" ) )
108116
109117 if ( files . length === 0 ) {
110- console . error ( " Error: No agent files found in agents/ directory" )
118+ console . error ( ` ${ prefix } Error: No agent files found in agents/ directory` )
111119 process . exit ( 1 )
112120 }
113121
@@ -119,54 +127,68 @@ function main() {
119127 const targetPath = join ( AGENTS_TARGET_DIR , file )
120128
121129 try {
122- copyFileSync ( sourcePath , targetPath )
123-
124- // Verify the copy succeeded by comparing file sizes
125- const sourceSize = statSync ( sourcePath ) . size
126- const targetSize = statSync ( targetPath ) . size
127-
128- if ( sourceSize !== targetSize ) {
129- throw new Error (
130- `File size mismatch: source=${ sourceSize } bytes, target=${ targetSize } bytes` ,
131- )
132- }
133-
134- // Validate content structure
135- const validation = validateAgentContent ( targetPath )
136- if ( ! validation . valid ) {
137- throw new Error ( `Invalid agent file content: ${ validation . error } ` )
130+ if ( DRY_RUN ) {
131+ // In dry-run mode, validate source file but don't copy
132+ const validation = validateAgentContent ( sourcePath )
133+ if ( ! validation . valid ) {
134+ throw new Error ( `Invalid agent file content: ${ validation . error } ` )
135+ }
136+ successes . push ( file )
137+ console . log ( `${ prefix } Would install: ${ file } -> ${ targetPath } ` )
138+ } else {
139+ copyFileSync ( sourcePath , targetPath )
140+
141+ // Verify the copy succeeded by comparing file sizes
142+ const sourceSize = statSync ( sourcePath ) . size
143+ const targetSize = statSync ( targetPath ) . size
144+
145+ if ( sourceSize !== targetSize ) {
146+ throw new Error (
147+ `File size mismatch: source=${ sourceSize } bytes, target=${ targetSize } bytes` ,
148+ )
149+ }
150+
151+ // Validate content structure
152+ const validation = validateAgentContent ( targetPath )
153+ if ( ! validation . valid ) {
154+ throw new Error ( `Invalid agent file content: ${ validation . error } ` )
155+ }
156+
157+ successes . push ( file )
158+ console . log ( ` Installed: ${ file } ` )
138159 }
139-
140- successes . push ( file )
141- console . log ( ` Installed: ${ file } ` )
142160 } catch ( err ) {
143161 const error = err instanceof Error ? err : new Error ( String ( err ) )
144162 const message = getErrorMessage ( error , file , targetPath )
145163 failures . push ( { file, message } )
146- console . error ( ` Failed: ${ file } - ${ message } ` )
164+ console . error ( `${ prefix } Failed: ${ file } - ${ message } ` )
147165 }
148166 }
149167
150168 // Print summary
151169 console . log ( "" )
152170 if ( successes . length > 0 && failures . length === 0 ) {
153- console . log ( `opencode-plugin-opencoder: Successfully installed ${ successes . length } agent(s)` )
154- console . log ( ` Location: ${ AGENTS_TARGET_DIR } ` )
155- console . log ( "\nTo use the autonomous development loop, run:" )
156- console . log ( " opencode @opencoder" )
171+ console . log (
172+ `${ prefix } opencode-plugin-opencoder: Successfully installed ${ successes . length } agent(s)` ,
173+ )
174+ console . log ( `${ prefix } Location: ${ AGENTS_TARGET_DIR } ` )
175+ if ( ! DRY_RUN ) {
176+ console . log ( "\nTo use the autonomous development loop, run:" )
177+ console . log ( " opencode @opencoder" )
178+ }
157179 } else if ( successes . length > 0 && failures . length > 0 ) {
158180 console . log (
159- `opencode-plugin-opencoder: Installed ${ successes . length } of ${ files . length } agent(s)` ,
181+ `${ prefix } opencode-plugin-opencoder: Installed ${ successes . length } of ${ files . length } agent(s)` ,
160182 )
161- console . log ( ` Location: ${ AGENTS_TARGET_DIR } ` )
162- console . error ( `\n ${ failures . length } file(s) failed to install:` )
183+ console . log ( `${ prefix } Location: ${ AGENTS_TARGET_DIR } ` )
184+ console . error ( `\n${ prefix } ${ failures . length } file(s) failed to install:` )
163185 for ( const { file, message } of failures ) {
164- console . error ( ` - ${ file } : ${ message } ` )
186+ console . error ( `${ prefix } - ${ file } : ${ message } ` )
165187 }
166188 } else {
167- console . error ( " opencode-plugin-opencoder: Failed to install any agents" )
189+ console . error ( ` ${ prefix } opencode-plugin-opencoder: Failed to install any agents` )
168190 for ( const { file, message } of failures ) {
169- console . error ( ` - ${ file } : ${ message } ` )
191+ console . error ( `${ prefix } - ${ file } : ${ message } ` )
170192 }
171193 process . exit ( 1 )
172194 }
0 commit comments