Skip to content

fix(cli): let --change find change names that exist on disk - #1375

Merged
clay-good merged 2 commits into
mainfrom
fix/change-lookup-accepts-existing-names
Jul 17, 2026
Merged

fix(cli): let --change find change names that exist on disk#1375
clay-good merged 2 commits into
mainfrom
fix/change-lookup-accepts-existing-names

Conversation

@clay-good

@clay-good clay-good commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Fixes #1308.

What was wrong

Any command taking --change (status, instructions <artifact>, instructions apply) rejected digit-leading change names at parse time:

$ openspec status --change 2026-07-04-voice-copilot-v1
✖ Error: Invalid change name '2026-07-04-voice-copilot-v1': Change name must start with a letter

Meanwhile list, validate, and archive all handled the same change fine, so a change could live its whole lifecycle while being unaddressable by --change. Repos with a date-prefixed naming convention (which the archive flow itself produces) couldn't use the status/instructions workflow at all.

The cause: validateChangeExists() reused validateChangeName() — the creation-time kebab-case rule — as its path-traversal guard, so the lookup path enforced a naming convention on directories that already exist.

How it was fixed

Lookup and creation are now separate rules, matching how the rest of the CLI behaves:

  • Lookup (--change) accepts any directory name that openspec list could return, and only rejects unsafe names: path separators, ./.., null bytes, and hidden (dot-leading) entries.
  • Creation (openspec new change) still enforces kebab-case via validateChangeName() — this PR takes no position on Support numbered change names (NNNNN-slug) for sequencing #1169 (numbered names at creation).

One small function in src/commands/workflow/shared.ts; no other call sites touched.

Replication / proof

Before (repro from the issue, real output):

$ openspec status --change 2026-07-04-voice-copilot-v1
✖ Error: Invalid change name '2026-07-04-voice-copilot-v1': Change name must start with a letter

After:

$ openspec status --change 2026-07-04-voice-copilot-v1
Change: 2026-07-04-voice-copilot-v1
Schema: spec-driven
Progress: 1/4 artifacts complete
...
$ openspec status --change ../foo
✖ Error: Invalid change name '../foo': Change name cannot contain path separators

Tests: new cases for digit-leading names on status and instructions, plus a hidden-name rejection; the existing traversal tests (../foo, /etc/passwd, foo/bar) pass unchanged. Full suite: 1,861 passed (the 17 zsh-installer failures are the known local-environment ones).

Notes

  • Lookup now also accepts other on-disk names the old rule rejected (uppercase, underscores) — intentional, since list/archive already resolve those directories.
  • Includes a patch changeset.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • The --change option now accepts any safe existing change name on disk, including date- or digit-prefixed names.
    • Change lookup resolution is now consistent with other change-related commands (e.g., list/validate/archive).
  • Bug Fixes

    • Unsafe names (hidden entries, path separators, relative segments like ./.., and null characters) are still rejected.
    • The reserved name archive is rejected when provided via --change.
  • Tests

    • Expanded CLI coverage for status and instructions change-name validation and acceptance.
  • Documentation

    • Updated behavior notes for the --change option accordingly.

The --change flag on status and instructions validated names with the
creation-time kebab-case rule, so digit-leading names (e.g. the
date-prefixed convention 2026-07-04-voice-copilot-v1) were rejected at
parse time even though list, validate, and archive all handle them.

Lookup now only guards against unsafe directory names (path separators,
relative segments, null bytes, hidden entries) and otherwise accepts
whatever getAvailableChanges could return. Creating a change still
enforces kebab-case via validateChangeName.

Fixes #1308

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@clay-good
clay-good requested a review from TabishB as a code owner July 16, 2026 14:29
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ae68c097-8c13-4011-a116-c33c2e06525a

📥 Commits

Reviewing files that changed from the base of the PR and between 990cf72 and 2709f60.

📒 Files selected for processing (2)
  • src/commands/workflow/shared.ts
  • test/commands/artifact-workflow.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/commands/workflow/shared.ts
  • test/commands/artifact-workflow.test.ts

📝 Walkthrough

Walkthrough

The --change workflow now separates lookup-name validation from creation-name validation, allowing existing digit-leading or date-prefixed changes while rejecting unsafe names. Status and instructions tests cover these cases, and the changeset documents the behavior.

Changes

Change Lookup

Layer / File(s) Summary
Lookup safety validation
src/commands/workflow/shared.ts
Adds dedicated safety checks for lookup names and updates validateChangeExists to report lookup-specific validation errors.
CLI coverage and behavior notes
test/commands/artifact-workflow.test.ts, .changeset/change-lookup-accepts-existing-names.md
Tests accepted digit-leading names and rejected hidden or reserved names for status and instructions, and documents the lookup rules.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant WorkflowCommand
  participant validateChangeExists
  participant ChangeDirectory
  WorkflowCommand->>validateChangeExists: provide --change name
  validateChangeExists->>validateChangeExists: validate lookup safety
  validateChangeExists->>ChangeDirectory: resolve existing change directory
  ChangeDirectory-->>validateChangeExists: return directory result
Loading

Possibly related issues

Possibly related PRs

Suggested reviewers: tabishb

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: letting --change resolve existing on-disk change names.
Linked Issues check ✅ Passed The PR matches #1308 by allowing digit-leading existing change names for --change in status/instructions while preserving safety checks.
Out of Scope Changes check ✅ Passed The changes are focused on change-name lookup, related tests, and a note update; no unrelated scope is evident.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/change-lookup-accepts-existing-names

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/commands/workflow/shared.ts`:
- Around line 136-160: Update validateChangeLookupName to reject the reserved
change name "archive", matching the exclusion applied by getAvailableChanges
before returning undefined for otherwise safe names.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5486705e-83a4-4323-8ac1-a95959652629

📥 Commits

Reviewing files that changed from the base of the PR and between 0a99f41 and 990cf72.

📒 Files selected for processing (3)
  • .changeset/change-lookup-accepts-existing-names.md
  • src/commands/workflow/shared.ts
  • test/commands/artifact-workflow.test.ts

Comment thread src/commands/workflow/shared.ts
Matches the getAvailableChanges filter so --change archive can't address
the archive directory as if it were a change (CodeRabbit review).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@alfred-openspec alfred-openspec left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the diff, linked issue, surrounding workflow/apply paths, CI, and focused local tests. Looks good to merge.

@clay-good
clay-good added this pull request to the merge queue Jul 17, 2026
Merged via the queue into main with commit 52a8bce Jul 17, 2026
14 checks passed
@clay-good
clay-good deleted the fix/change-lookup-accepts-existing-names branch July 17, 2026 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent change-name validation: --change rejects digit-leading names that list/validate/archive accept

2 participants