Sync delta specs from a change to main specs.
Store selection: If the user names a store (a store is a standalone OpenSpec repo registered on this machine) or the work lives in one, run
openspec store list --json
to discover registered store ids, then pass
on the commands that read or write specs and changes (
,
,
,
,
,
,
,
,
,
,
). Once selected, treat
as sticky for the rest of the workflow. Every unscoped example of those commands below is shorthand: before running it, append the flag. For example, run
openspec status --change "<name>" --json --store "<id>"
, not the unscoped form shown below. Other commands do not take the flag. Hints printed by commands already carry the flag; keep it on follow-ups. Without a store, commands act on the nearest local
root.
is the spec directory relative to
(for example,
or
). Preserve the full path from each delta spec when resolving its main spec.
-
Select the change
If a name is provided, use it. Otherwise:
- Infer from conversation context if the user mentioned a change
- Auto-select if only one active change exists
- If ambiguous, run to get available changes and ask the user to select one
When prompting, show changes that have delta specs (under
directory).
Always announce: "Using change: <name>" and how to override (e.g.,
/openspec-sync-specs <other>
).
-
Resolve change context
Run:
bash
openspec status --change "<name>" --json
The JSON includes
. Main specs live under
<planningHome.root>/openspec/specs/
— use that (store-aware) root for every main-spec path below, not a hardcoded repo path. When a store is selected it points at the store, not the current repository.
-
Find delta specs
Use
artifactPaths.specs.existingOutputPaths
from the status JSON as the
only source of delta spec paths. If the
entry is missing or
is empty, report that there are no delta specs to sync,
do not infer them from other artifacts, and stop without requesting artifact
instructions or writing a main spec.
Sync every path in
unless the caller narrowed the set.
A caller narrows it by naming an explicit list of complete entries from
— copy those absolute values verbatim. Archive does
this inline, and a user can too (for example, by selecting the entry ending
in
/specs/billing/invoices/spec.md
).
Then sync only the named paths and leave the remaining delta specs untouched:
bulk archive excludes a delta whose implementation it could not find, and
syncing it anyway would write a main spec the caller deliberately withheld.
Carry that narrowed selection through step 4; never widen it back to the full
list. If a named path is not in
, do not sync it —
report it and stop, rather than dropping it silently. If the named list is
empty, report that there is nothing to sync and stop without writing a main
spec.
Each delta spec file contains sections like:
- - New requirements to add
- - Changes to existing requirements
- - Requirements to remove
- - Requirements to rename (FROM:/TO: format)
If no delta specs found, inform user and stop.
-
For each delta spec, apply changes to main specs
Before the first main-spec write, obtain one current specs-rule snapshot:
- If archive invoked this workflow inline and supplied a valid snapshot from
openspec instructions specs --change "<name>" --json
, reuse it and do not
fetch the same instructions again.
- Otherwise run that command once now with the same selected-root flags.
- If the direct lookup exits non-zero or returns invalid artifact-instruction
JSON, report the error and stop before writing any main spec. Do not treat the
failure as an absent rule set.
- A valid response with omitted means no artifact rules are configured
and the existing semantic merge continues.
Apply returned
only to the content and form of the main specs produced
by this merge. Artifact rules are not operation guidance and cannot change
selected roots, delta paths, CLI checks, or workflow steps. Use their text as
constraints without copying it verbatim into a main spec or summary.
For each capability delta spec path selected in step 3 — the full
list, or the narrowed subset when a caller supplied one (these may belong to a selected store, not the repo):
a. Read the delta spec to understand the intended changes
b.
Read the main spec at
<planningHome.root>/openspec/specs/<capability-path>/spec.md
(may not exist yet)
c. Apply changes intelligently:
ADDED Requirements:
- If requirement doesn't exist in main spec → add it
- If requirement already exists → update it to match (treat as implicit MODIFIED)
MODIFIED Requirements:
- Find the requirement in main spec
- Apply the changes - this can be:
- Adding new scenarios the main spec does not have yet
- Modifying existing scenarios
- Changing the requirement description
- Preserve scenarios/content not mentioned in the delta
REMOVED Requirements:
- Remove the entire requirement block from main spec
- Retiring the capability. Delete the whole - and the directory once
nothing else is left in it - only when ALL of these hold:
- removing the requirements this run left no requirement blocks;
- the rest of the spec is well-formed (it still has a );
- the main spec was not already empty before this sync - if you removed
nothing, change nothing;
- every other nonblank line in the whole file is accounted for as the
title, Purpose, Requirements header, or a canonical requirement's
statement, scenarios, or fenced examples;
- the change's declares
retire_capabilities: true
;
- the resolves inside the real specs root (do not follow a
capability-directory symlink to delete an external file).
If removing the selected requirements would leave no requirement blocks and
any retirement condition is not satisfied, do not modify the main spec. Stop
the sync for that capability, report the blocking condition, and tell the user
how to resolve it. Never write or leave an empty section.
When only the marker is missing, say that too - it is the one thing the user
can add to make the retirement go through.
- Deleting the file also deletes its ; any other section blocks
retirement. Name Purpose when you report the retirement. Include a pasteable
only when the spec lived in the caller's checkout;
otherwise give checkout-scoped recovery guidance.
RENAMED Requirements:
- Find the FROM requirement, rename to TO
- The main spec already has one and it is authoritative - leave it alone
(this is what does; it warns and moves on)
d. Create new main spec if capability doesn't exist yet:
- Create
<planningHome.root>/openspec/specs/<capability-path>/spec.md
- Add Purpose section: copy the delta's body verbatim when it has one
(this is what does); only write a brief TBD placeholder when it does not
- Add Requirements section with the ADDED requirements
- Follow the Main Spec Format Reference below
-
Validate updated main specs
Run
openspec validate --specs
with the same selected-root flags used earlier.
If validation fails, report the problems and do not claim the sync succeeded.
-
Show summary
After applying all changes, summarize:
- Which capabilities were updated
- What changes were made (requirements added/modified/removed/renamed)
- Any new main spec left with a TBD Purpose placeholder, so it gets written
now rather than lingering
- Any capability retired, naming the deleted , its Purpose, and
either a pasteable or checkout-scoped recovery guidance
Main specs are what the delta merges INTO. They must never contain delta operation headers (
## ADDED/MODIFIED/REMOVED/RENAMED Requirements
) - after syncing, every requirement lives under a single
section: