@@ -26,7 +26,7 @@ import {
2626// Imported last on purpose: see the matching note in `src/api.ts` — the
2727// position of `effect/lift.ts` in the module graph keeps the emitted hook
2828// bundles byte-identical.
29- import { runWithPlatform , scopedTempDirectory } from '../effect/platform.ts' ;
29+ import { runWithPlatform , withTempDirectory } from '../effect/platform.ts' ;
3030import { liftPromise } from '../effect/lift.ts' ;
3131
3232const maximumOutputBytes = 1024 * 1024 ;
@@ -261,10 +261,10 @@ const schemaVerbUnavailable = (output: string): boolean =>
261261 / (?: u n r e c o g n i z e d | u n k n o w n | i n v a l i d ) (?: s u b c o m m a n d | c o m m a n d ) | n o s u c h (?: s u b c o m m a n d | c o m m a n d ) / iu. test ( output ) ;
262262
263263/**
264- * Runs the live schema generator into a scoped temp directory and compares
264+ * Runs the live schema generator into a temporary directory and compares
265265 * its output with the pinned revision. Every generator failure is reported
266266 * as a diagnostic (AB6033 / AB6031), never thrown; the directory is removed
267- * when the scope closes, whichever way the program settles.
267+ * whichever way the program settles.
268268 */
269269const schemaGenerationDiagnostics = (
270270 options : Readonly < {
@@ -275,67 +275,69 @@ const schemaGenerationDiagnostics = (
275275 readonly target : string ;
276276 readonly version : string | undefined ;
277277 } > ,
278- ) : Effect . Effect < readonly Diagnostic [ ] , PlatformError , FileSystem . FileSystem > => Effect . scoped ( Effect . gen ( function * ( ) {
279- const outputDirectory = yield * scopedTempDirectory ( { prefix : 'agent-bundle-codex-schema-' } ) ;
280- const started = yield * liftPromise ( ( ) => options . run ( Object . freeze ( {
281- args : Object . freeze ( [ 'app-server' , 'generate-json-schema' , '--out' , outputDirectory ] ) ,
282- cwd : options . cwd ,
283- executable : options . executable ,
284- } ) ) ) . pipe ( Effect . option ) ;
285- if ( Option . isNone ( started ) ) {
286- return freezeDiagnostics ( [ diagnostic (
287- 'AB6033' ,
288- 'Codex CLI schema generation could not be started.' ,
289- 'error' ,
290- options . target ,
291- 'Verify the Codex CLI starts and supports app-server schema generation, then rerun artifact validation.' ,
292- ) ] ) ;
293- }
294- const result : CodexPluginCommandResult = started . value ;
278+ ) : Effect . Effect < readonly Diagnostic [ ] , PlatformError , FileSystem . FileSystem > => withTempDirectory (
279+ { prefix : 'agent-bundle-codex-schema-' } ,
280+ ( outputDirectory ) => Effect . gen ( function * ( ) {
281+ const started = yield * liftPromise ( ( ) => options . run ( Object . freeze ( {
282+ args : Object . freeze ( [ 'app-server' , 'generate-json-schema' , '--out' , outputDirectory ] ) ,
283+ cwd : options . cwd ,
284+ executable : options . executable ,
285+ } ) ) ) . pipe ( Effect . option ) ;
286+ if ( Option . isNone ( started ) ) {
287+ return freezeDiagnostics ( [ diagnostic (
288+ 'AB6033' ,
289+ 'Codex CLI schema generation could not be started.' ,
290+ 'error' ,
291+ options . target ,
292+ 'Verify the Codex CLI starts and supports app-server schema generation, then rerun artifact validation.' ,
293+ ) ] ) ;
294+ }
295+ const result : CodexPluginCommandResult = started . value ;
295296
296- if ( result . termination !== undefined ) {
297- return freezeDiagnostics ( [ diagnostic (
298- 'AB6033' ,
299- commandFailureMessage ( 'schema generation' , result ) ,
300- 'error' ,
301- options . target ,
302- 'Rerun Codex schema generation within the configured time and output bounds.' ,
303- ) ] ) ;
304- }
305- if ( result . exitCode !== 0 ) {
306- const output = `${ result . stdout } \n${ result . stderr } ` ;
307- if ( schemaVerbUnavailable ( output ) ) {
297+ if ( result . termination !== undefined ) {
308298 return freezeDiagnostics ( [ diagnostic (
309- 'AB6031' ,
310- `The Codex ${ options . version ?? 'unknown' } app-server generate-json-schema verb is unavailable; ` +
311- `live schema drift could not be checked against pinned Codex ${ pinnedRevision } .` ,
312- 'info' ,
299+ 'AB6033' ,
300+ commandFailureMessage ( 'schema generation' , result ) ,
301+ 'error' ,
313302 options . target ,
314- 'Use a Codex release that publishes app-server schema generation, or retain validation against the vendored pinned schemas .' ,
303+ 'Rerun Codex schema generation within the configured time and output bounds .' ,
315304 ) ] ) ;
316305 }
317- return freezeDiagnostics ( [ diagnostic (
306+ if ( result . exitCode !== 0 ) {
307+ const output = `${ result . stdout } \n${ result . stderr } ` ;
308+ if ( schemaVerbUnavailable ( output ) ) {
309+ return freezeDiagnostics ( [ diagnostic (
310+ 'AB6031' ,
311+ `The Codex ${ options . version ?? 'unknown' } app-server generate-json-schema verb is unavailable; ` +
312+ `live schema drift could not be checked against pinned Codex ${ pinnedRevision } .` ,
313+ 'info' ,
314+ options . target ,
315+ 'Use a Codex release that publishes app-server schema generation, or retain validation against the vendored pinned schemas.' ,
316+ ) ] ) ;
317+ }
318+ return freezeDiagnostics ( [ diagnostic (
319+ 'AB6033' ,
320+ commandFailureMessage ( 'schema generation' , result ) ,
321+ 'error' ,
322+ options . target ,
323+ 'Run `codex app-server generate-json-schema --out <dir>` successfully, then rerun artifact validation.' ,
324+ ) ] ) ;
325+ }
326+
327+ return yield * liftPromise ( ( ) => compareGeneratedSchemas (
328+ outputDirectory ,
329+ options . version ,
330+ options . strict ,
331+ options . target ,
332+ ) ) . pipe ( Effect . catch ( ( ) => Effect . succeed ( freezeDiagnostics ( [ diagnostic (
318333 'AB6033' ,
319- commandFailureMessage ( ' schema generation' , result ) ,
334+ 'Codex CLI generated schema output could not be inspected.' ,
320335 'error' ,
321336 options . target ,
322- 'Run `codex app-server generate-json-schema --out <dir>` successfully, then rerun artifact validation.' ,
323- ) ] ) ;
324- }
325-
326- return yield * liftPromise ( ( ) => compareGeneratedSchemas (
327- outputDirectory ,
328- options . version ,
329- options . strict ,
330- options . target ,
331- ) ) . pipe ( Effect . catch ( ( ) => Effect . succeed ( freezeDiagnostics ( [ diagnostic (
332- 'AB6033' ,
333- 'Codex CLI generated schema output could not be inspected.' ,
334- 'error' ,
335- options . target ,
336- 'Ensure the generated schema directory is readable, then rerun artifact validation.' ,
337- ) ] ) ) ) ) ;
338- } ) ) ;
337+ 'Ensure the generated schema directory is readable, then rerun artifact validation.' ,
338+ ) ] ) ) ) ) ;
339+ } ) ,
340+ ) ;
339341
340342export const validateCodexPlugin = async (
341343 options : ValidateCodexPluginOptions ,
0 commit comments