* chore: bulk archive completed changes and normalize specs * docs: finalize spec purposes and align init workflow scenarios * test: guard source specs against placeholders and delta headers * docs: resolve remaining spec review nits
10 KiB
CLI Init Specification
Purpose
The openspec init command SHALL create a complete OpenSpec directory structure in any project, enabling immediate adoption of OpenSpec conventions with support for multiple AI coding assistants.
Requirements
Requirement: Progress Indicators
The command SHALL display progress indicators during initialization to provide clear feedback about each step.
Scenario: Displaying initialization progress
- WHEN executing initialization steps
- THEN validate environment silently in background (no output unless error)
- AND display progress with ora spinners:
- Show spinner: "⠋ Creating OpenSpec structure..."
- Then success: "✔ OpenSpec structure created"
- Show spinner: "⠋ Configuring AI tools..."
- Then success: "✔ AI tools configured"
Requirement: Directory Creation
The command SHALL create the OpenSpec directory structure with config file.
Scenario: Creating OpenSpec structure
- WHEN
openspec initis executed - THEN create the following directory structure:
openspec/
├── config.yaml
├── specs/
└── changes/
└── archive/
Requirement: AI Tool Configuration
The command SHALL configure AI coding assistants with skills and slash commands using a searchable multi-select experience.
Scenario: Prompting for AI tool selection
- WHEN run interactively
- THEN display animated welcome screen with OpenSpec logo
- AND present a searchable multi-select that shows all available tools
- AND mark already configured tools with "(configured ✓)" indicator
- AND pre-select configured tools for easy refresh
- AND sort configured tools to appear first in the list
- AND allow filtering by typing to search
Scenario: Selecting tools to configure
- WHEN user selects tools and confirms
- THEN generate skills in
.<tool>/skills/directory for each selected tool - AND generate slash commands in
.<tool>/commands/opsx/directory for each selected tool - AND create
openspec/config.yamlwith default schema setting
Requirement: Interactive Mode
The command SHALL provide an interactive menu for AI tool selection with clear navigation instructions.
Scenario: Displaying interactive menu
- WHEN run in fresh or extend mode
- THEN present a looping select menu that lets users toggle tools with Space and review selections with Enter
- AND when Enter is pressed on a highlighted selectable tool that is not already selected, automatically add it to the selection before moving to review so the highlighted tool is configured
- AND label already configured tools with "(already configured)" while keeping disabled options marked "coming soon"
- AND change the prompt copy in extend mode to "Which AI tools would you like to add or refresh?"
- AND display inline instructions clarifying that Space toggles tools and Enter selects the highlighted tool before reviewing selections
Requirement: Safety Checks
The command SHALL perform safety checks to prevent overwriting existing structures and ensure proper permissions.
Scenario: Detecting existing initialization
- WHEN the
openspec/directory already exists - THEN inform the user that OpenSpec is already initialized, skip recreating the base structure, and enter an extend mode
- AND continue to the AI tool selection step so additional tools can be configured
- AND display the existing-initialization error message only when the user declines to add any AI tools
Requirement: Success Output
The command SHALL provide clear, actionable next steps upon successful initialization.
Scenario: Displaying success message
- WHEN initialization completes successfully
- THEN display categorized summary:
- "Created: " for newly configured tools
- "Refreshed: " for already-configured tools that were updated
- Count of skills and commands generated
- AND display getting started section with:
/opsx:new- Start a new change/opsx:continue- Create the next artifact/opsx:apply- Implement tasks
- AND display links to documentation and feedback
Scenario: Displaying restart instruction
- WHEN initialization completes successfully and tools were created or refreshed
- THEN display instruction to restart IDE for slash commands to take effect
Requirement: Exit Codes
The command SHALL use consistent exit codes to indicate different failure modes.
Scenario: Returning exit codes
- WHEN the command completes
- THEN return appropriate exit code:
- 0: Success
- 1: General error (including when OpenSpec directory already exists)
- 2: Insufficient permissions (reserved for future use)
- 3: User cancelled operation (reserved for future use)
Requirement: Additional AI Tool Initialization
openspec init SHALL allow users to add configuration files for new AI coding assistants after the initial setup.
Scenario: Configuring an extra tool after initial setup
- GIVEN an
openspec/directory already exists and at least one AI tool file is present - WHEN the user runs
openspec initand selects a different supported AI tool - THEN generate that tool's configuration files with OpenSpec markers the same way as during first-time initialization
- AND leave existing tool configuration files unchanged except for managed sections that need refreshing
- AND exit with code 0 and display a success summary highlighting the newly added tool files
Requirement: Success Output Enhancements
openspec init SHALL summarize tool actions when initialization or extend mode completes.
Scenario: Showing tool summary
- WHEN the command completes successfully
- THEN display a categorized summary of tools that were created, refreshed, or skipped (including already-configured skips)
- AND personalize the "Next steps" header using the names of the selected tools, defaulting to a generic label when none remain
Requirement: Exit Code Adjustments
openspec init SHALL treat extend mode without new native tool selections as a successful refresh.
Scenario: Allowing empty extend runs
- WHEN OpenSpec is already initialized and the user selects no additional natively supported tools
- THEN complete successfully without requiring additional tool setup
- AND preserve the existing OpenSpec structure and config files
- AND exit with code 0
Requirement: Non-Interactive Mode
The command SHALL support non-interactive operation through command-line options.
Scenario: Select all tools non-interactively
- WHEN run with
--tools all - THEN automatically select every available AI tool without prompting
- AND proceed with skill and command generation
Scenario: Select specific tools non-interactively
- WHEN run with
--tools claude,cursor - THEN parse the comma-separated tool IDs
- AND generate skills and commands for specified tools only
Scenario: Skip tool configuration non-interactively
- WHEN run with
--tools none - THEN create only the openspec directory structure
- AND skip skill and command generation
- AND create config only when config creation conditions are met
Scenario: Invalid tool specification
- WHEN run with
--tools invalid-tool - THEN fail with exit code 1
- AND display an error listing available values (
all,none, and supported tool IDs)
Scenario: Reserved value combined with tool IDs
- WHEN run with
--tools all,claudeor--tools none,cursor - THEN fail with exit code 1
- AND display an error explaining reserved values cannot be combined with specific tool IDs
Scenario: Missing --tools in non-interactive mode
- GIVEN prompts are unavailable in non-interactive execution
- WHEN user runs
openspec initwithout--tools - THEN fail with exit code 1
- AND instruct to use
--tools all,--tools none, or explicit tool IDs
Requirement: Skill Generation
The command SHALL generate Agent Skills for selected AI tools.
Scenario: Generating skills for a tool
- WHEN a tool is selected during initialization
- THEN create 9 skill directories under
.<tool>/skills/:openspec-explore/SKILL.mdopenspec-new-change/SKILL.mdopenspec-continue-change/SKILL.mdopenspec-apply-change/SKILL.mdopenspec-ff-change/SKILL.mdopenspec-verify-change/SKILL.mdopenspec-sync-specs/SKILL.mdopenspec-archive-change/SKILL.mdopenspec-bulk-archive-change/SKILL.md
- AND each SKILL.md SHALL contain YAML frontmatter with name and description
- AND each SKILL.md SHALL contain the skill instructions
Requirement: Slash Command Generation
The command SHALL generate opsx slash commands for selected AI tools.
Scenario: Generating slash commands for a tool
- WHEN a tool is selected during initialization
- THEN create 9 slash command files using the tool's command adapter:
/opsx:explore/opsx:new/opsx:continue/opsx:apply/opsx:ff/opsx:verify/opsx:sync/opsx:archive/opsx:bulk-archive
- AND use tool-specific path conventions (e.g.,
.claude/commands/opsx/for Claude) - AND include tool-specific frontmatter format
Requirement: Config File Generation
The command SHALL create an OpenSpec config file with schema settings.
Scenario: Creating config.yaml
- WHEN initialization completes
- AND config.yaml does not exist
- THEN create
openspec/config.yamlwith default schema setting - AND display config location in output
Scenario: Preserving existing config.yaml
- WHEN initialization runs in extend mode
- AND
openspec/config.yamlalready exists - THEN preserve the existing config file
- AND display "(exists)" indicator in output
Requirement: Experimental Command Alias
The command SHALL maintain backward compatibility with the experimental command.
Scenario: Running openspec experimental
- WHEN user runs
openspec experimental - THEN delegate to
openspec init - AND the command SHALL be hidden from help output
Why
Manual creation of OpenSpec structure is error-prone and creates adoption friction. A standardized init command ensures:
- Consistent structure across all projects
- Proper AI instruction files are always included
- Quick onboarding for new projects
- Clear conventions from the start