Skip to content
112 changes: 112 additions & 0 deletions openspec/changes/add-artifact-workflow-cli/design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
## Context

Slice 4 of the artifact workflow POC. The core functionality (ArtifactGraph, InstructionLoader, change-utils) is complete. This slice adds CLI commands to expose the artifact workflow to users.

**Key constraint**: This is experimental. Commands must be isolated for easy removal if the feature doesn't work out.

## Goals / Non-Goals

- **Goals:**
- Expose artifact workflow status and instructions via CLI
- Provide fluid UX with top-level verb commands
- Support both human-readable and JSON output
- Enable agents to programmatically query workflow state
- Keep implementation isolated for easy removal

- **Non-Goals:**
- Interactive artifact creation wizards (future work)
- Schema management commands (deferred)
- Auto-detection of active change (CLI is deterministic, agents infer)

## Decisions

### Command Structure: Top-Level Verbs

Commands are top-level for maximum fluidity:

```
openspec status --change <id>
openspec next --change <id>
openspec instructions <artifact> --change <id>
openspec templates --change <id>
openspec new change <name>
```

**Rationale:**
- Most fluid UX - fewest keystrokes
- Commands are unique enough to avoid conflicts
- Simple mental model for users

**Trade-off accepted:** Slight namespace pollution, but commands are distinct and can be removed cleanly.

### Experimental Isolation

All artifact workflow commands are implemented in a single file:

```
src/commands/artifact-workflow.ts
```

**To remove the feature:**
1. Delete `src/commands/artifact-workflow.ts`
2. Remove ~5 lines from `src/cli/index.ts`

No other files touched, no risk to stable functionality.

### Deterministic CLI with Explicit `--change`

All change-specific commands require `--change <id>`:

```bash
openspec status --change add-auth # explicit, works
openspec status # error: missing --change
```

**Rationale:**
- CLI is pure, testable, no hidden state
- Agents infer change from conversation and pass explicitly
- No config file tracking "active change"
- Consistent with POC design philosophy

### New Change Command Structure

Creating changes uses explicit subcommand:

```bash
openspec new change add-feature
```

**Rationale:**
- `openspec new <name>` is ambiguous (new what?)
- `openspec new change <name>` is clear and extensible
- Can add `openspec new spec <name>` later if needed

### Output Formats

- **Default**: Human-readable text with visual indicators
- Status: `[x]` done, `[ ]` ready, `[-]` blocked
- Colors: green (done), yellow (ready), red (blocked)
- **JSON** (`--json`): Machine-readable for scripts and agents

### Error Handling

- Missing `--change`: Error listing available changes
- Unknown change: Error with suggestion
- Unknown artifact: Error listing valid artifacts
- Missing schema: Error with schema resolution details

## Risks / Trade-offs

| Risk | Mitigation |
|------|------------|
| Top-level commands pollute namespace | Commands are distinct; isolated for easy removal |
| `status` confused with git | Context (`--change`) makes it clear |
| Feature doesn't work out | Single file deletion removes everything |

## Implementation Notes

- All commands in `src/commands/artifact-workflow.ts`
- Imports from `src/core/artifact-graph/` for all operations
- Uses `getActiveChangeIds()` from `item-discovery.ts` for change listing
- Follows existing CLI patterns (ora spinners, commander.js options)
- Help text marks commands as "Experimental"
33 changes: 33 additions & 0 deletions openspec/changes/add-artifact-workflow-cli/proposal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## Why

The ArtifactGraph (Slice 1) and InstructionLoader (Slice 3) provide programmatic APIs for artifact-based workflow management. Users currently have no CLI interface to:
- See artifact completion status for a change
- Discover what artifacts are ready to create
- Get enriched instructions for creating artifacts
- Create new changes with proper validation

This proposal adds CLI commands that expose the artifact workflow functionality to users and agents.

## What Changes

- **NEW**: `openspec status --change <id>` shows artifact completion state
- **NEW**: `openspec next --change <id>` shows artifacts ready to create
- **NEW**: `openspec instructions <artifact> --change <id>` outputs enriched template
- **NEW**: `openspec templates --change <id>` shows resolved template paths
- **NEW**: `openspec new change <name>` creates a new change directory

All commands are top-level for fluid UX. They integrate with existing core modules:
- Uses `loadChangeContext()`, `formatChangeStatus()`, `generateInstructions()` from instruction-loader
- Uses `ArtifactGraph`, `detectCompleted()` from artifact-graph
- Uses `createChange()`, `validateChangeName()` from change-utils

**Experimental isolation**: All commands are implemented in a single file (`src/commands/artifact-workflow.ts`) for easy removal if the feature doesn't work out. Help text marks them as experimental.

## Impact

- Affected specs: NEW `cli-workflow` capability
- Affected code:
- `src/cli/index.ts` - register new commands
- `src/commands/artifact-workflow.ts` - new command implementations
- No changes to existing commands or specs
- Builds on completed Slice 1, 2, and 3 implementations
149 changes: 149 additions & 0 deletions openspec/changes/add-artifact-workflow-cli/specs/cli-workflow/spec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# cli-workflow Specification

## Purpose
CLI commands for artifact workflow operations, exposing the artifact graph and instruction loader functionality to users and agents. Commands are top-level for fluid UX and implemented in isolation for easy removal.

## ADDED Requirements

### Requirement: Status Command
The system SHALL display artifact completion status for a change.

#### Scenario: Show status with all states
- **WHEN** user runs `openspec status --change <id>`
- **THEN** the system displays each artifact with status indicator:
- `[x]` for completed artifacts
- `[ ]` for ready artifacts
- `[-]` for blocked artifacts (with missing dependencies listed)

#### Scenario: Status shows completion summary
- **WHEN** user runs `openspec status --change <id>`
- **THEN** output includes completion percentage and count (e.g., "2/4 artifacts complete")

#### Scenario: Status JSON output
- **WHEN** user runs `openspec status --change <id> --json`
- **THEN** the system outputs JSON with changeName, schemaName, isComplete, and artifacts array

#### Scenario: Missing change parameter
- **WHEN** user runs `openspec status` without `--change`
- **THEN** the system displays an error with list of available changes

#### Scenario: Unknown change
- **WHEN** user runs `openspec status --change unknown-id`
- **THEN** the system displays an error indicating the change does not exist

### Requirement: Next Command
The system SHALL show which artifacts are ready to be created.

#### Scenario: Show ready artifacts
- **WHEN** user runs `openspec next --change <id>`
- **THEN** the system lists artifacts whose dependencies are all satisfied

#### Scenario: No artifacts ready
- **WHEN** all artifacts are either completed or blocked
- **THEN** the system indicates no artifacts are ready (with explanation)

#### Scenario: All artifacts complete
- **WHEN** all artifacts in the change are completed
- **THEN** the system indicates the change is complete

#### Scenario: Next JSON output
- **WHEN** user runs `openspec next --change <id> --json`
- **THEN** the system outputs JSON array of ready artifact IDs

### Requirement: Instructions Command
The system SHALL output enriched instructions for creating an artifact.

#### Scenario: Show enriched instructions
- **WHEN** user runs `openspec instructions <artifact> --change <id>`
- **THEN** the system outputs:
- Artifact metadata (ID, output path, description)
- Template content
- Dependency status (done/missing)
- Unlocked artifacts (what becomes available after completion)

#### Scenario: Instructions JSON output
- **WHEN** user runs `openspec instructions <artifact> --change <id> --json`
- **THEN** the system outputs JSON matching ArtifactInstructions interface

#### Scenario: Unknown artifact
- **WHEN** user runs `openspec instructions unknown-artifact --change <id>`
- **THEN** the system displays an error listing valid artifact IDs for the schema

#### Scenario: Artifact with unmet dependencies
- **WHEN** user requests instructions for a blocked artifact
- **THEN** the system displays instructions with a warning about missing dependencies

### Requirement: Templates Command
The system SHALL show resolved template paths for all artifacts.

#### Scenario: List template paths
- **WHEN** user runs `openspec templates --change <id>`
- **THEN** the system displays each artifact with its resolved template path

#### Scenario: Templates JSON output
- **WHEN** user runs `openspec templates --change <id> --json`
- **THEN** the system outputs JSON mapping artifact IDs to template paths

#### Scenario: Template resolution source
- **WHEN** displaying template paths
- **THEN** the system indicates whether each template is from user override or package built-in

### Requirement: New Change Command
The system SHALL create new change directories with validation.

#### Scenario: Create valid change
- **WHEN** user runs `openspec new change add-feature`
- **THEN** the system creates `openspec/changes/add-feature/` directory

#### Scenario: Invalid change name
- **WHEN** user runs `openspec new change "Add Feature"` with invalid name
- **THEN** the system displays validation error with guidance

#### Scenario: Duplicate change name
- **WHEN** user runs `openspec new change existing-change` for an existing change
- **THEN** the system displays an error indicating the change already exists

#### Scenario: Create with description
- **WHEN** user runs `openspec new change add-feature --description "Add new feature"`
- **THEN** the system creates the change directory with description in README.md

### Requirement: Schema Selection
The system SHALL support custom schema selection for workflow commands.

#### Scenario: Default schema
- **WHEN** user runs workflow commands without `--schema`
- **THEN** the system uses the "spec-driven" schema

#### Scenario: Custom schema
- **WHEN** user runs `openspec status --change <id> --schema tdd`
- **THEN** the system uses the specified schema for artifact graph

#### Scenario: Unknown schema
- **WHEN** user specifies an unknown schema
- **THEN** the system displays an error listing available schemas

### Requirement: Output Formatting
The system SHALL provide consistent output formatting.

#### Scenario: Color output
- **WHEN** terminal supports colors
- **THEN** status indicators use colors: green (done), yellow (ready), red (blocked)

#### Scenario: No color output
- **WHEN** `--no-color` flag is used or NO_COLOR environment variable is set
- **THEN** output uses text-only indicators without ANSI colors

#### Scenario: Progress indication
- **WHEN** loading change state takes time
- **THEN** the system displays a spinner during loading

### Requirement: Experimental Isolation
The system SHALL implement artifact workflow commands in isolation for easy removal.

#### Scenario: Single file implementation
- **WHEN** artifact workflow feature is implemented
- **THEN** all commands are in `src/commands/artifact-workflow.ts`

#### Scenario: Help text marking
- **WHEN** user runs `--help` on any artifact workflow command
- **THEN** help text indicates the command is experimental
48 changes: 48 additions & 0 deletions openspec/changes/add-artifact-workflow-cli/tasks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
## 1. Core Command Implementation

- [ ] 1.1 Create `src/commands/artifact-workflow.ts` with all commands
- [ ] 1.2 Implement `status` command with text output
- [ ] 1.3 Implement `next` command with text output
- [ ] 1.4 Implement `instructions` command with text output
- [ ] 1.5 Implement `templates` command with text output
- [ ] 1.6 Implement `new change` subcommand using createChange()

## 2. CLI Registration

- [ ] 2.1 Register `status` command in `src/cli/index.ts`
- [ ] 2.2 Register `next` command in `src/cli/index.ts`
- [ ] 2.3 Register `instructions` command in `src/cli/index.ts`
- [ ] 2.4 Register `templates` command in `src/cli/index.ts`
- [ ] 2.5 Register `new` command group with `change` subcommand

## 3. Output Formatting

- [ ] 3.1 Add `--json` flag support to all commands
- [ ] 3.2 Add color-coded status indicators (done/ready/blocked)
- [ ] 3.3 Add progress spinner for loading operations
- [ ] 3.4 Support `--no-color` flag

## 4. Error Handling

- [ ] 4.1 Handle missing `--change` parameter with helpful error
- [ ] 4.2 Handle unknown change names with list of available changes
- [ ] 4.3 Handle unknown artifact names with valid options
- [ ] 4.4 Handle schema resolution errors

## 5. Options and Flags

- [ ] 5.1 Add `--schema` option for custom schema selection
- [ ] 5.2 Add `--description` option to `new change` command
- [ ] 5.3 Ensure options follow existing CLI patterns

## 6. Testing

- [ ] 6.1 Add smoke tests for each command
- [ ] 6.2 Test error cases (missing change, unknown artifact)
- [ ] 6.3 Test JSON output format
- [ ] 6.4 Test with different schemas

## 7. Documentation

- [ ] 7.1 Add help text for all commands marked as "Experimental"
- [ ] 7.2 Update AGENTS.md with new commands (post-archive)
Loading