@@ -187,9 +187,14 @@ async function statusCommand(options: StatusOptions): Promise<void> {
187187 try {
188188 const projectRoot = process . cwd ( ) ;
189189 const changeName = await validateChangeExists ( options . change , projectRoot ) ;
190- const schemaName = validateSchemaExists ( options . schema ?? DEFAULT_SCHEMA ) ;
191190
192- const context = loadChangeContext ( projectRoot , changeName , schemaName ) ;
191+ // Validate schema if explicitly provided
192+ if ( options . schema ) {
193+ validateSchemaExists ( options . schema ) ;
194+ }
195+
196+ // loadChangeContext will auto-detect schema from metadata if not provided
197+ const context = loadChangeContext ( projectRoot , changeName , options . schema ) ;
193198 const status = formatChangeStatus ( context ) ;
194199
195200 spinner . stop ( ) ;
@@ -252,26 +257,30 @@ async function instructionsCommand(
252257 try {
253258 const projectRoot = process . cwd ( ) ;
254259 const changeName = await validateChangeExists ( options . change , projectRoot ) ;
255- const schemaName = validateSchemaExists ( options . schema ?? DEFAULT_SCHEMA ) ;
260+
261+ // Validate schema if explicitly provided
262+ if ( options . schema ) {
263+ validateSchemaExists ( options . schema ) ;
264+ }
265+
266+ // loadChangeContext will auto-detect schema from metadata if not provided
267+ const context = loadChangeContext ( projectRoot , changeName , options . schema ) ;
256268
257269 if ( ! artifactId ) {
258270 spinner . stop ( ) ;
259- const schema = resolveSchema ( schemaName ) ;
260- const graph = ArtifactGraph . fromSchema ( schema ) ;
261- const validIds = graph . getAllArtifacts ( ) . map ( ( a ) => a . id ) ;
271+ const validIds = context . graph . getAllArtifacts ( ) . map ( ( a ) => a . id ) ;
262272 throw new Error (
263273 `Missing required argument <artifact>. Valid artifacts:\n ${ validIds . join ( '\n ' ) } `
264274 ) ;
265275 }
266276
267- const context = loadChangeContext ( projectRoot , changeName , schemaName ) ;
268277 const artifact = context . graph . getArtifact ( artifactId ) ;
269278
270279 if ( ! artifact ) {
271280 spinner . stop ( ) ;
272281 const validIds = context . graph . getAllArtifacts ( ) . map ( ( a ) => a . id ) ;
273282 throw new Error (
274- `Artifact '${ artifactId } ' not found in schema '${ schemaName } '. Valid artifacts:\n ${ validIds . join ( '\n ' ) } `
283+ `Artifact '${ artifactId } ' not found in schema '${ context . schemaName } '. Valid artifacts:\n ${ validIds . join ( '\n ' ) } `
275284 ) ;
276285 }
277286
@@ -424,8 +433,9 @@ function parseTasksFile(content: string): TaskItem[] {
424433async function generateApplyInstructions (
425434 projectRoot : string ,
426435 changeName : string ,
427- schemaName : string
436+ schemaName ? : string
428437) : Promise < ApplyInstructions > {
438+ // loadChangeContext will auto-detect schema from metadata if not provided
429439 const context = loadChangeContext ( projectRoot , changeName , schemaName ) ;
430440 const changeDir = path . join ( projectRoot , 'openspec' , 'changes' , changeName ) ;
431441
@@ -505,9 +515,14 @@ async function applyInstructionsCommand(options: ApplyInstructionsOptions): Prom
505515 try {
506516 const projectRoot = process . cwd ( ) ;
507517 const changeName = await validateChangeExists ( options . change , projectRoot ) ;
508- const schemaName = validateSchemaExists ( options . schema ?? DEFAULT_SCHEMA ) ;
509518
510- const instructions = await generateApplyInstructions ( projectRoot , changeName , schemaName ) ;
519+ // Validate schema if explicitly provided
520+ if ( options . schema ) {
521+ validateSchemaExists ( options . schema ) ;
522+ }
523+
524+ // generateApplyInstructions uses loadChangeContext which auto-detects schema
525+ const instructions = await generateApplyInstructions ( projectRoot , changeName , options . schema ) ;
511526
512527 spinner . stop ( ) ;
513528
@@ -640,6 +655,7 @@ async function templatesCommand(options: TemplatesOptions): Promise<void> {
640655
641656interface NewChangeOptions {
642657 description ?: string ;
658+ schema ?: string ;
643659}
644660
645661async function newChangeCommand ( name : string | undefined , options : NewChangeOptions ) : Promise < void > {
@@ -652,11 +668,17 @@ async function newChangeCommand(name: string | undefined, options: NewChangeOpti
652668 throw new Error ( validation . error ) ;
653669 }
654670
655- const spinner = ora ( `Creating change '${ name } '...` ) . start ( ) ;
671+ // Validate schema if provided
672+ if ( options . schema ) {
673+ validateSchemaExists ( options . schema ) ;
674+ }
675+
676+ const schemaDisplay = options . schema ? ` with schema '${ options . schema } '` : '' ;
677+ const spinner = ora ( `Creating change '${ name } '${ schemaDisplay } ...` ) . start ( ) ;
656678
657679 try {
658680 const projectRoot = process . cwd ( ) ;
659- await createChange ( projectRoot , name ) ;
681+ await createChange ( projectRoot , name , { schema : options . schema } ) ;
660682
661683 // If description provided, create README.md with description
662684 if ( options . description ) {
@@ -666,7 +688,8 @@ async function newChangeCommand(name: string | undefined, options: NewChangeOpti
666688 await fs . writeFile ( readmePath , `# ${ name } \n\n${ options . description } \n` , 'utf-8' ) ;
667689 }
668690
669- spinner . succeed ( `Created change '${ name } ' at openspec/changes/${ name } /` ) ;
691+ const schemaUsed = options . schema ?? DEFAULT_SCHEMA ;
692+ spinner . succeed ( `Created change '${ name } ' at openspec/changes/${ name } / (schema: ${ schemaUsed } )` ) ;
670693 } catch ( error ) {
671694 spinner . fail ( `Failed to create change '${ name } '` ) ;
672695 throw error ;
@@ -811,7 +834,7 @@ export function registerArtifactWorkflowCommands(program: Command): void {
811834 . command ( 'status' )
812835 . description ( '[Experimental] Display artifact completion status for a change' )
813836 . option ( '--change <id>' , 'Change name to show status for' )
814- . option ( '--schema <name>' , ` Schema to use (default: ${ DEFAULT_SCHEMA } )` )
837+ . option ( '--schema <name>' , ' Schema override (auto-detected from .openspec.yaml)' )
815838 . option ( '--json' , 'Output as JSON' )
816839 . action ( async ( options : StatusOptions ) => {
817840 try {
@@ -828,7 +851,7 @@ export function registerArtifactWorkflowCommands(program: Command): void {
828851 . command ( 'instructions [artifact]' )
829852 . description ( '[Experimental] Output enriched instructions for creating an artifact or applying tasks' )
830853 . option ( '--change <id>' , 'Change name' )
831- . option ( '--schema <name>' , ` Schema to use (default: ${ DEFAULT_SCHEMA } )` )
854+ . option ( '--schema <name>' , ' Schema override (auto-detected from .openspec.yaml)' )
832855 . option ( '--json' , 'Output as JSON' )
833856 . action ( async ( artifactId : string | undefined , options : InstructionsOptions ) => {
834857 try {
@@ -868,6 +891,7 @@ export function registerArtifactWorkflowCommands(program: Command): void {
868891 . command ( 'change <name>' )
869892 . description ( '[Experimental] Create a new change directory' )
870893 . option ( '--description <text>' , 'Description to add to README.md' )
894+ . option ( '--schema <name>' , `Workflow schema to use (default: ${ DEFAULT_SCHEMA } )` )
871895 . action ( async ( name : string , options : NewChangeOptions ) => {
872896 try {
873897 await newChangeCommand ( name , options ) ;
0 commit comments