(options: ApplyInstructionsOptions)
| 433 | } |
| 434 | |
| 435 | export async function applyInstructionsCommand(options: ApplyInstructionsOptions): Promise<void> { |
| 436 | // Resolve (and banner) before the spinner starts so stderr stays readable. |
| 437 | const root = await resolveRootForCommand(options, { json: options.json }); |
| 438 | if (!root) { |
| 439 | return; |
| 440 | } |
| 441 | |
| 442 | const spinner = options.json ? undefined : ora('Generating apply instructions...').start(); |
| 443 | |
| 444 | try { |
| 445 | const planningHome = toPlanningHome(root); |
| 446 | const projectRoot = root.path; |
| 447 | const changeName = await validateChangeExists( |
| 448 | options.change, |
| 449 | projectRoot, |
| 450 | root.changesDir, |
| 451 | { newChangeHint: withStoreFlag(root, 'openspec new change <name>') } |
| 452 | ); |
| 453 | |
| 454 | // Validate schema if explicitly provided |
| 455 | if (options.schema) { |
| 456 | validateSchemaExists(options.schema, projectRoot); |
| 457 | } |
| 458 | |
| 459 | // generateApplyInstructions uses loadChangeContext which auto-detects schema |
| 460 | const { references } = await loadRootConfigContext(root); |
| 461 | const instructions = await generateApplyInstructions(projectRoot, changeName, options.schema, { |
| 462 | planningHome, |
| 463 | references, |
| 464 | }); |
| 465 | |
| 466 | spinner?.stop(); |
| 467 | |
| 468 | if (options.json) { |
| 469 | console.log(JSON.stringify({ ...instructions, root: toRootOutput(root) }, null, 2)); |
| 470 | return; |
| 471 | } |
| 472 | |
| 473 | printApplyInstructionsText(instructions); |
| 474 | } catch (error) { |
| 475 | spinner?.stop(); |
| 476 | throw error; |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | export function printApplyInstructionsText(instructions: ApplyInstructions): void { |
| 481 | const { changeName, schemaName, contextFiles, progress, tasks, state, missingArtifacts, instruction } = instructions; |
no test coverage detected