@fission-ai/openspec 0.21.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli/index.js CHANGED
@@ -16,6 +16,7 @@ import { CompletionCommand } from '../commands/completion.js';
16
16
  import { FeedbackCommand } from '../commands/feedback.js';
17
17
  import { registerConfigCommand } from '../commands/config.js';
18
18
  import { registerArtifactWorkflowCommands } from '../commands/artifact-workflow.js';
19
+ import { registerSchemaCommand } from '../commands/schema.js';
19
20
  import { maybeShowTelemetryNotice, trackCommand, shutdown } from '../telemetry/index.js';
20
21
  const program = new Command();
21
22
  const require = createRequire(import.meta.url);
@@ -230,6 +231,7 @@ program
230
231
  });
231
232
  registerSpecCommand(program);
232
233
  registerConfigCommand(program);
234
+ registerSchemaCommand(program);
233
235
  // Top-level validate command
234
236
  program
235
237
  .command('validate [item-name]')
@@ -14,8 +14,9 @@ import path from 'path';
14
14
  import * as fs from 'fs';
15
15
  import { loadChangeContext, formatChangeStatus, generateInstructions, listSchemas, listSchemasWithInfo, getSchemaDir, resolveSchema, ArtifactGraph, } from '../core/artifact-graph/index.js';
16
16
  import { createChange, validateChangeName } from '../utils/change-utils.js';
17
- import { getExploreSkillTemplate, getNewChangeSkillTemplate, getContinueChangeSkillTemplate, getApplyChangeSkillTemplate, getFfChangeSkillTemplate, getSyncSpecsSkillTemplate, getArchiveChangeSkillTemplate, getVerifyChangeSkillTemplate, getOpsxExploreCommandTemplate, getOpsxNewCommandTemplate, getOpsxContinueCommandTemplate, getOpsxApplyCommandTemplate, getOpsxFfCommandTemplate, getOpsxSyncCommandTemplate, getOpsxArchiveCommandTemplate, getOpsxVerifyCommandTemplate } from '../core/templates/skill-templates.js';
17
+ import { getExploreSkillTemplate, getNewChangeSkillTemplate, getContinueChangeSkillTemplate, getApplyChangeSkillTemplate, getFfChangeSkillTemplate, getSyncSpecsSkillTemplate, getArchiveChangeSkillTemplate, getBulkArchiveChangeSkillTemplate, getVerifyChangeSkillTemplate, getOpsxExploreCommandTemplate, getOpsxNewCommandTemplate, getOpsxContinueCommandTemplate, getOpsxApplyCommandTemplate, getOpsxFfCommandTemplate, getOpsxSyncCommandTemplate, getOpsxArchiveCommandTemplate, getOpsxBulkArchiveCommandTemplate, getOpsxVerifyCommandTemplate } from '../core/templates/skill-templates.js';
18
18
  import { FileSystemUtils } from '../utils/file-system.js';
19
+ import { serializeConfig } from '../core/config-prompts.js';
19
20
  const DEFAULT_SCHEMA = 'spec-driven';
20
21
  /**
21
22
  * Checks if color output is disabled via NO_COLOR env or --no-color flag.
@@ -97,11 +98,14 @@ async function validateChangeExists(changeName, projectRoot) {
97
98
  }
98
99
  /**
99
100
  * Validates that a schema exists and returns available schemas if not.
101
+ *
102
+ * @param schemaName - The schema name to validate
103
+ * @param projectRoot - Optional project root for project-local schema resolution
100
104
  */
101
- function validateSchemaExists(schemaName) {
102
- const schemaDir = getSchemaDir(schemaName);
105
+ function validateSchemaExists(schemaName, projectRoot) {
106
+ const schemaDir = getSchemaDir(schemaName, projectRoot);
103
107
  if (!schemaDir) {
104
- const availableSchemas = listSchemas();
108
+ const availableSchemas = listSchemas(projectRoot);
105
109
  throw new Error(`Schema '${schemaName}' not found. Available schemas:\n ${availableSchemas.join('\n ')}`);
106
110
  }
107
111
  return schemaName;
@@ -113,7 +117,7 @@ async function statusCommand(options) {
113
117
  const changeName = await validateChangeExists(options.change, projectRoot);
114
118
  // Validate schema if explicitly provided
115
119
  if (options.schema) {
116
- validateSchemaExists(options.schema);
120
+ validateSchemaExists(options.schema, projectRoot);
117
121
  }
118
122
  // loadChangeContext will auto-detect schema from metadata if not provided
119
123
  const context = loadChangeContext(projectRoot, changeName, options.schema);
@@ -158,7 +162,7 @@ async function instructionsCommand(artifactId, options) {
158
162
  const changeName = await validateChangeExists(options.change, projectRoot);
159
163
  // Validate schema if explicitly provided
160
164
  if (options.schema) {
161
- validateSchemaExists(options.schema);
165
+ validateSchemaExists(options.schema, projectRoot);
162
166
  }
163
167
  // loadChangeContext will auto-detect schema from metadata if not provided
164
168
  const context = loadChangeContext(projectRoot, changeName, options.schema);
@@ -173,7 +177,7 @@ async function instructionsCommand(artifactId, options) {
173
177
  const validIds = context.graph.getAllArtifacts().map((a) => a.id);
174
178
  throw new Error(`Artifact '${artifactId}' not found in schema '${context.schemaName}'. Valid artifacts:\n ${validIds.join('\n ')}`);
175
179
  }
176
- const instructions = generateInstructions(context, artifactId);
180
+ const instructions = generateInstructions(context, artifactId, projectRoot);
177
181
  const isBlocked = instructions.dependencies.some((d) => !d.done);
178
182
  spinner.stop();
179
183
  if (options.json) {
@@ -433,7 +437,7 @@ async function applyInstructionsCommand(options) {
433
437
  const changeName = await validateChangeExists(options.change, projectRoot);
434
438
  // Validate schema if explicitly provided
435
439
  if (options.schema) {
436
- validateSchemaExists(options.schema);
440
+ validateSchemaExists(options.schema, projectRoot);
437
441
  }
438
442
  // generateApplyInstructions uses loadChangeContext which auto-detects schema
439
443
  const instructions = await generateApplyInstructions(projectRoot, changeName, options.schema);
@@ -498,18 +502,29 @@ function printApplyInstructionsText(instructions) {
498
502
  async function templatesCommand(options) {
499
503
  const spinner = ora('Loading templates...').start();
500
504
  try {
501
- const schemaName = validateSchemaExists(options.schema ?? DEFAULT_SCHEMA);
502
- const schema = resolveSchema(schemaName);
505
+ const projectRoot = process.cwd();
506
+ const schemaName = validateSchemaExists(options.schema ?? DEFAULT_SCHEMA, projectRoot);
507
+ const schema = resolveSchema(schemaName, projectRoot);
503
508
  const graph = ArtifactGraph.fromSchema(schema);
504
- const schemaDir = getSchemaDir(schemaName);
505
- // Determine if this is a user override or package built-in
506
- const { getUserSchemasDir } = await import('../core/artifact-graph/resolver.js');
509
+ const schemaDir = getSchemaDir(schemaName, projectRoot);
510
+ // Determine the source (project, user, or package)
511
+ const { getUserSchemasDir, getProjectSchemasDir, } = await import('../core/artifact-graph/resolver.js');
512
+ const projectSchemasDir = getProjectSchemasDir(projectRoot);
507
513
  const userSchemasDir = getUserSchemasDir();
508
- const isUserOverride = schemaDir.startsWith(userSchemasDir);
514
+ let source;
515
+ if (schemaDir.startsWith(projectSchemasDir)) {
516
+ source = 'project';
517
+ }
518
+ else if (schemaDir.startsWith(userSchemasDir)) {
519
+ source = 'user';
520
+ }
521
+ else {
522
+ source = 'package';
523
+ }
509
524
  const templates = graph.getAllArtifacts().map((artifact) => ({
510
525
  artifactId: artifact.id,
511
526
  templatePath: path.join(schemaDir, 'templates', artifact.template),
512
- source: isUserOverride ? 'user' : 'package',
527
+ source,
513
528
  }));
514
529
  spinner.stop();
515
530
  if (options.json) {
@@ -521,7 +536,7 @@ async function templatesCommand(options) {
521
536
  return;
522
537
  }
523
538
  console.log(`Schema: ${schemaName}`);
524
- console.log(`Source: ${isUserOverride ? 'user override' : 'package built-in'}`);
539
+ console.log(`Source: ${source}`);
525
540
  console.log();
526
541
  for (const t of templates) {
527
542
  console.log(`${t.artifactId}:`);
@@ -541,15 +556,15 @@ async function newChangeCommand(name, options) {
541
556
  if (!validation.valid) {
542
557
  throw new Error(validation.error);
543
558
  }
559
+ const projectRoot = process.cwd();
544
560
  // Validate schema if provided
545
561
  if (options.schema) {
546
- validateSchemaExists(options.schema);
562
+ validateSchemaExists(options.schema, projectRoot);
547
563
  }
548
564
  const schemaDisplay = options.schema ? ` with schema '${options.schema}'` : '';
549
565
  const spinner = ora(`Creating change '${name}'${schemaDisplay}...`).start();
550
566
  try {
551
- const projectRoot = process.cwd();
552
- await createChange(projectRoot, name, { schema: options.schema });
567
+ const result = await createChange(projectRoot, name, { schema: options.schema });
553
568
  // If description provided, create README.md with description
554
569
  if (options.description) {
555
570
  const { promises: fs } = await import('fs');
@@ -557,8 +572,7 @@ async function newChangeCommand(name, options) {
557
572
  const readmePath = path.join(changeDir, 'README.md');
558
573
  await fs.writeFile(readmePath, `# ${name}\n\n${options.description}\n`, 'utf-8');
559
574
  }
560
- const schemaUsed = options.schema ?? DEFAULT_SCHEMA;
561
- spinner.succeed(`Created change '${name}' at openspec/changes/${name}/ (schema: ${schemaUsed})`);
575
+ spinner.succeed(`Created change '${name}' at openspec/changes/${name}/ (schema: ${result.schema})`);
562
576
  }
563
577
  catch (error) {
564
578
  spinner.fail(`Failed to create change '${name}'`);
@@ -587,6 +601,7 @@ async function artifactExperimentalSetupCommand() {
587
601
  const ffChangeSkill = getFfChangeSkillTemplate();
588
602
  const syncSpecsSkill = getSyncSpecsSkillTemplate();
589
603
  const archiveChangeSkill = getArchiveChangeSkillTemplate();
604
+ const bulkArchiveChangeSkill = getBulkArchiveChangeSkillTemplate();
590
605
  const verifyChangeSkill = getVerifyChangeSkillTemplate();
591
606
  // Get command templates
592
607
  const exploreCommand = getOpsxExploreCommandTemplate();
@@ -596,6 +611,7 @@ async function artifactExperimentalSetupCommand() {
596
611
  const ffCommand = getOpsxFfCommandTemplate();
597
612
  const syncCommand = getOpsxSyncCommandTemplate();
598
613
  const archiveCommand = getOpsxArchiveCommandTemplate();
614
+ const bulkArchiveCommand = getOpsxBulkArchiveCommandTemplate();
599
615
  const verifyCommand = getOpsxVerifyCommandTemplate();
600
616
  // Create skill directories and SKILL.md files
601
617
  const skills = [
@@ -606,6 +622,7 @@ async function artifactExperimentalSetupCommand() {
606
622
  { template: ffChangeSkill, dirName: 'openspec-ff-change' },
607
623
  { template: syncSpecsSkill, dirName: 'openspec-sync-specs' },
608
624
  { template: archiveChangeSkill, dirName: 'openspec-archive-change' },
625
+ { template: bulkArchiveChangeSkill, dirName: 'openspec-bulk-archive-change' },
609
626
  { template: verifyChangeSkill, dirName: 'openspec-verify-change' },
610
627
  ];
611
628
  const createdSkillFiles = [];
@@ -633,6 +650,7 @@ ${template.instructions}
633
650
  { template: ffCommand, fileName: 'ff.md' },
634
651
  { template: syncCommand, fileName: 'sync.md' },
635
652
  { template: archiveCommand, fileName: 'archive.md' },
653
+ { template: bulkArchiveCommand, fileName: 'bulk-archive.md' },
636
654
  { template: verifyCommand, fileName: 'verify.md' },
637
655
  ];
638
656
  const createdCommandFiles = [];
@@ -667,6 +685,68 @@ ${template.content}
667
685
  console.log(chalk.green(' ✓ ' + file));
668
686
  }
669
687
  console.log();
688
+ // Config creation section
689
+ console.log('━'.repeat(70));
690
+ console.log();
691
+ console.log(chalk.bold('📋 Project Configuration (Optional)'));
692
+ console.log();
693
+ console.log('Configure project defaults for OpenSpec workflows.');
694
+ console.log();
695
+ // Check if config already exists
696
+ const configPath = path.join(projectRoot, 'openspec', 'config.yaml');
697
+ const configYmlPath = path.join(projectRoot, 'openspec', 'config.yml');
698
+ const configExists = fs.existsSync(configPath) || fs.existsSync(configYmlPath);
699
+ if (configExists) {
700
+ // Config already exists, skip creation
701
+ console.log(chalk.blue('ℹ️ openspec/config.yaml already exists. Skipping config creation.'));
702
+ console.log();
703
+ console.log(' To update config, edit openspec/config.yaml manually or:');
704
+ console.log(' 1. Delete openspec/config.yaml');
705
+ console.log(' 2. Run openspec artifact-experimental-setup again');
706
+ console.log();
707
+ }
708
+ else if (!process.stdin.isTTY) {
709
+ // Non-interactive mode (CI, automation, piped input)
710
+ console.log(chalk.blue('ℹ️ Skipping config prompts (non-interactive mode)'));
711
+ console.log();
712
+ console.log(' To create config manually, add openspec/config.yaml with:');
713
+ console.log(chalk.dim(' schema: spec-driven'));
714
+ console.log();
715
+ }
716
+ else {
717
+ // Create config with default schema
718
+ const yamlContent = serializeConfig({ schema: DEFAULT_SCHEMA });
719
+ try {
720
+ await FileSystemUtils.writeFile(configPath, yamlContent);
721
+ console.log();
722
+ console.log(chalk.green('✓ Created openspec/config.yaml'));
723
+ console.log();
724
+ console.log(` Default schema: ${chalk.cyan(DEFAULT_SCHEMA)}`);
725
+ console.log();
726
+ console.log(chalk.dim(' Edit the file to add project context and per-artifact rules.'));
727
+ console.log();
728
+ // Git commit suggestion
729
+ console.log(chalk.bold('To share with team:'));
730
+ console.log(chalk.dim(' git add openspec/config.yaml .claude/'));
731
+ console.log(chalk.dim(' git commit -m "Setup OpenSpec experimental workflow"'));
732
+ console.log();
733
+ }
734
+ catch (writeError) {
735
+ // Handle file write errors
736
+ console.error();
737
+ console.error(chalk.red('✗ Failed to write openspec/config.yaml'));
738
+ console.error(chalk.dim(` ${writeError.message}`));
739
+ console.error();
740
+ console.error('Fallback: Create config manually:');
741
+ console.error(chalk.dim(' 1. Create openspec/config.yaml'));
742
+ console.error(chalk.dim(' 2. Copy the following content:'));
743
+ console.error();
744
+ console.error(chalk.dim(yamlContent));
745
+ console.error();
746
+ }
747
+ }
748
+ console.log('━'.repeat(70));
749
+ console.log();
670
750
  console.log(chalk.bold('📖 Usage:'));
671
751
  console.log();
672
752
  console.log(' ' + chalk.cyan('Skills') + ' work automatically in compatible editors:');
@@ -699,7 +779,8 @@ ${template.content}
699
779
  }
700
780
  }
701
781
  async function schemasCommand(options) {
702
- const schemas = listSchemasWithInfo();
782
+ const projectRoot = process.cwd();
783
+ const schemas = listSchemasWithInfo(projectRoot);
703
784
  if (options.json) {
704
785
  console.log(JSON.stringify(schemas, null, 2));
705
786
  return;
@@ -707,7 +788,13 @@ async function schemasCommand(options) {
707
788
  console.log('Available schemas:');
708
789
  console.log();
709
790
  for (const schema of schemas) {
710
- const sourceLabel = schema.source === 'user' ? chalk.dim(' (user override)') : '';
791
+ let sourceLabel = '';
792
+ if (schema.source === 'project') {
793
+ sourceLabel = chalk.cyan(' (project)');
794
+ }
795
+ else if (schema.source === 'user') {
796
+ sourceLabel = chalk.dim(' (user override)');
797
+ }
711
798
  console.log(` ${chalk.bold(schema.name)}${sourceLabel}`);
712
799
  console.log(` ${schema.description}`);
713
800
  console.log(` Artifacts: ${schema.artifacts.join(' → ')}`);
@@ -0,0 +1,6 @@
1
+ import { Command } from 'commander';
2
+ /**
3
+ * Register the schema command and all its subcommands.
4
+ */
5
+ export declare function registerSchemaCommand(program: Command): void;
6
+ //# sourceMappingURL=schema.d.ts.map