specrails-core 1.4.0 → 1.6.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/README.md +104 -92
- package/commands/setup.md +136 -23
- package/package.json +1 -1
- package/templates/commands/sr/opsx-diff.md +419 -0
- package/templates/commands/sr/telemetry.md +552 -0
- package/templates/personas/the-maintainer.md +20 -0
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: "OpenSpec Change Diff Visualizer"
|
|
3
|
+
description: "Show a before/after diff of OpenSpec spec changes for a given change. Highlights additions, removals, and behavioral modifications across acceptance criteria, flows, and constraints. Supports markdown and JSON output."
|
|
4
|
+
category: Workflow
|
|
5
|
+
tags: [openspec, diff, specs, visualization, changes]
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
Visualize spec changes for **{{PROJECT_NAME}}**: compare the current specs against a named OpenSpec change to show exactly what behavioral requirements are being added, modified, or removed.
|
|
9
|
+
|
|
10
|
+
**Input:** $ARGUMENTS — accepts:
|
|
11
|
+
- `<change-name>` — the kebab-case name of the change to diff (required). If omitted, interactive selection is offered.
|
|
12
|
+
- `--format json` — emit structured JSON instead of markdown (default: markdown).
|
|
13
|
+
- `--summary-only` — skip inline line-level diff; show only the file-level and behavioral summary.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Phase 0: Argument Parsing
|
|
18
|
+
|
|
19
|
+
Parse `$ARGUMENTS` to set runtime variables.
|
|
20
|
+
|
|
21
|
+
**Variables to set:**
|
|
22
|
+
|
|
23
|
+
- `CHANGE_NAME` — string. Required. If not provided, prompt the user.
|
|
24
|
+
- `FORMAT` — `"markdown"` or `"json"`. Default: `"markdown"`.
|
|
25
|
+
- `SUMMARY_ONLY` — boolean. Default: `false`.
|
|
26
|
+
|
|
27
|
+
**Parsing rules:**
|
|
28
|
+
|
|
29
|
+
1. Scan `$ARGUMENTS` for `--format <value>`. If found and value is `json`, set `FORMAT="json"`. Any other value: print `Error: unknown format "<value>". Valid: markdown, json` and stop. Strip from arguments.
|
|
30
|
+
2. Scan for `--summary-only`. If found, set `SUMMARY_ONLY=true`. Strip from arguments.
|
|
31
|
+
3. Treat the remaining token (if any) as `CHANGE_NAME`. Strip leading/trailing whitespace.
|
|
32
|
+
4. If `CHANGE_NAME` is empty after parsing:
|
|
33
|
+
- Run:
|
|
34
|
+
```bash
|
|
35
|
+
openspec list --json
|
|
36
|
+
```
|
|
37
|
+
- If the result shows available changes, use the **AskUserQuestion tool** (open-ended, show the list) to ask which change to diff.
|
|
38
|
+
- If no changes exist, print:
|
|
39
|
+
```
|
|
40
|
+
Error: no active changes found. Run /opsx:new or /opsx:ff to create one first.
|
|
41
|
+
```
|
|
42
|
+
Stop.
|
|
43
|
+
|
|
44
|
+
**Print active configuration:**
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
Diffing change: <CHANGE_NAME>
|
|
48
|
+
Format: <markdown|json>
|
|
49
|
+
Summary only: <yes|no>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## Phase 1: Locate the Change
|
|
55
|
+
|
|
56
|
+
Find the change directory and enumerate its spec artifacts.
|
|
57
|
+
|
|
58
|
+
### Step 1a: Resolve the change path
|
|
59
|
+
|
|
60
|
+
Check these locations in order:
|
|
61
|
+
|
|
62
|
+
1. `openspec/changes/<CHANGE_NAME>/` — active change.
|
|
63
|
+
2. `openspec/changes/archive/` — glob for directories matching `*<CHANGE_NAME>` or exact `<CHANGE_NAME>`. Take the most recent match (latest date prefix).
|
|
64
|
+
|
|
65
|
+
If neither location yields a directory, print:
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
Error: change "<CHANGE_NAME>" not found.
|
|
69
|
+
Searched:
|
|
70
|
+
- openspec/changes/<CHANGE_NAME>/
|
|
71
|
+
- openspec/changes/archive/*<CHANGE_NAME>*/
|
|
72
|
+
|
|
73
|
+
Run `openspec list` to see available changes.
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Stop.
|
|
77
|
+
|
|
78
|
+
Set `CHANGE_DIR` to the resolved path.
|
|
79
|
+
|
|
80
|
+
**Print:** `Found change at: <CHANGE_DIR>`
|
|
81
|
+
|
|
82
|
+
### Step 1b: Enumerate spec artifacts in the change
|
|
83
|
+
|
|
84
|
+
Collect spec content from the change directory using this priority:
|
|
85
|
+
|
|
86
|
+
1. **Delta-spec file** — `<CHANGE_DIR>/delta-spec.md`. If present, read it. Set `HAS_DELTA_SPEC=true`.
|
|
87
|
+
2. **Inline specs subdirectory** — `<CHANGE_DIR>/specs/`. If present, glob `**/*.md` within it. Each file is an individual spec. Set `HAS_SPEC_DIR=true`.
|
|
88
|
+
3. **Proposal file** — `<CHANGE_DIR>/proposal.md`. Always read if present. Used for context but not as a primary diff source. Set `HAS_PROPOSAL=true`.
|
|
89
|
+
|
|
90
|
+
At least one of `HAS_DELTA_SPEC` or `HAS_SPEC_DIR` must be true to proceed.
|
|
91
|
+
|
|
92
|
+
If neither exists:
|
|
93
|
+
```
|
|
94
|
+
Warning: no spec artifacts found in <CHANGE_DIR>.
|
|
95
|
+
Expected: delta-spec.md or specs/*.md
|
|
96
|
+
|
|
97
|
+
The change may not have reached the spec authoring phase yet.
|
|
98
|
+
Run /opsx:continue to create specs first.
|
|
99
|
+
```
|
|
100
|
+
Stop.
|
|
101
|
+
|
|
102
|
+
Store the collected spec content:
|
|
103
|
+
- `DELTA_SPEC` — string content of delta-spec.md (or `""` if absent).
|
|
104
|
+
- `CHANGE_SPECS` — array of `{ path, content }` objects from the specs/ subdirectory (or `[]` if absent).
|
|
105
|
+
- `PROPOSAL` — string content of proposal.md (or `""` if absent).
|
|
106
|
+
|
|
107
|
+
**Print:** `Spec artifacts: <delta-spec.md present|absent>, <N spec files in specs/>, proposal <present|absent>`
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## Phase 2: Load Baseline Specs
|
|
112
|
+
|
|
113
|
+
Find the current baseline specs to compare against.
|
|
114
|
+
|
|
115
|
+
### Step 2a: Discover baseline spec files
|
|
116
|
+
|
|
117
|
+
Glob for markdown files in `openspec/specs/` (recursively: `openspec/specs/**/*.md`).
|
|
118
|
+
|
|
119
|
+
Store as `BASELINE_SPECS` — array of `{ path, content }` objects.
|
|
120
|
+
|
|
121
|
+
If `openspec/specs/` does not exist or contains no files:
|
|
122
|
+
```
|
|
123
|
+
Note: no baseline specs found in openspec/specs/.
|
|
124
|
+
Diff will show all change specs as net-new additions (no removals or modifications).
|
|
125
|
+
```
|
|
126
|
+
Set `BASELINE_SPECS=[]`.
|
|
127
|
+
|
|
128
|
+
**Print:** `Baseline: <N> spec file(s) found in openspec/specs/`
|
|
129
|
+
|
|
130
|
+
### Step 2b: Match change specs to baseline specs
|
|
131
|
+
|
|
132
|
+
For each entry in `CHANGE_SPECS` (from the change's specs/ subdirectory), attempt to find its counterpart in `BASELINE_SPECS`.
|
|
133
|
+
|
|
134
|
+
**Matching rule:** A change spec at `<CHANGE_DIR>/specs/<spec-name>/spec.md` matches a baseline spec at `openspec/specs/<spec-name>/spec.md` or `openspec/specs/<spec-name>.md`. Match on the spec name segment only.
|
|
135
|
+
|
|
136
|
+
Build `SPEC_PAIRS` — array of:
|
|
137
|
+
```
|
|
138
|
+
{
|
|
139
|
+
specName: string,
|
|
140
|
+
changePath: string | null, // path in change (null if baseline-only)
|
|
141
|
+
baselinePath: string | null, // path in baseline (null if change-only)
|
|
142
|
+
changeContent: string | null,
|
|
143
|
+
baselineContent: string | null,
|
|
144
|
+
matchType: "new" | "modified" | "deleted" | "unchanged"
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
**Match type rules:**
|
|
149
|
+
- `changePath` present, `baselinePath` absent → `"new"`.
|
|
150
|
+
- `changePath` absent, `baselinePath` present (and baseline spec is referenced/affected by delta-spec) → `"deleted"`.
|
|
151
|
+
- Both present and content differs → `"modified"`.
|
|
152
|
+
- Both present and content identical → `"unchanged"`.
|
|
153
|
+
|
|
154
|
+
For the delta-spec flow (when `HAS_DELTA_SPEC=true` and `HAS_SPEC_DIR=false`):
|
|
155
|
+
- The delta-spec itself is the primary artifact. There is no per-file pairing.
|
|
156
|
+
- Set `SPEC_PAIRS=[]` and use the delta-spec content directly in Phase 3.
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## Phase 3: Compute the Diff
|
|
161
|
+
|
|
162
|
+
Produce a structured diff comparing baseline vs. change specs.
|
|
163
|
+
|
|
164
|
+
### Step 3a: Delta-spec analysis (when HAS_DELTA_SPEC=true)
|
|
165
|
+
|
|
166
|
+
Parse the delta-spec sections to extract behavioral elements:
|
|
167
|
+
|
|
168
|
+
**Acceptance criteria / SHALL statements:**
|
|
169
|
+
- Glob for lines matching the pattern: `^\*\*\d+\.\d+\*\*` (numbered normative statements like `**1.1**`).
|
|
170
|
+
- Collect all `{ id, text }` pairs into `DELTA_STATEMENTS`.
|
|
171
|
+
|
|
172
|
+
**Surface impact table:**
|
|
173
|
+
- Find the `## Surface Impact` section (or `### Surface Impact of This Change`).
|
|
174
|
+
- Parse all table rows into `SURFACE_CHANGES`: `[ { category, element, change, severity } ]`.
|
|
175
|
+
|
|
176
|
+
**REST/API contract changes:**
|
|
177
|
+
- Find any section with "REST API", "API Contract", or "Endpoints" in the heading.
|
|
178
|
+
- Extract endpoint definitions: method + path + response shape changes.
|
|
179
|
+
- Store as `API_CHANGES`.
|
|
180
|
+
|
|
181
|
+
**Since there is no true baseline for a delta-spec** (it defines net-new behavior), classify every `DELTA_STATEMENTS` entry as a `"new"` addition. If the "Surface Impact" table includes rows with change type "Removal" or "BREAKING", classify those as `"modified"` or `"deleted"` accordingly.
|
|
182
|
+
|
|
183
|
+
Build `DIFF_RESULT`:
|
|
184
|
+
```
|
|
185
|
+
{
|
|
186
|
+
addedStatements: [{ id, text }],
|
|
187
|
+
modifiedStatements: [{ id, text, changeDescription }],
|
|
188
|
+
removedStatements: [{ id, text }],
|
|
189
|
+
surfaceChanges: [{ category, element, change, severity }],
|
|
190
|
+
apiChanges: [{ method, path, description }],
|
|
191
|
+
specPairs: []
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Step 3b: Spec-file-pair analysis (when HAS_SPEC_DIR=true)
|
|
196
|
+
|
|
197
|
+
For each `SPEC_PAIR` in `SPEC_PAIRS` where `matchType !== "unchanged"`:
|
|
198
|
+
|
|
199
|
+
**Line-level diff:**
|
|
200
|
+
|
|
201
|
+
Compare `baselineContent` and `changeContent` line by line:
|
|
202
|
+
|
|
203
|
+
1. Split each content string into lines.
|
|
204
|
+
2. Identify added lines (present in change, absent in baseline) and removed lines (present in baseline, absent in change).
|
|
205
|
+
3. For each changed block, compute a ±3-line context window.
|
|
206
|
+
4. Mark heading lines (starting with `#`) separately — heading changes indicate structural reorganization.
|
|
207
|
+
5. Mark lines containing normative language (`SHALL`, `MUST`, `SHOULD`, `MAY`, `SHALL NOT`, `MUST NOT`) as behavioral.
|
|
208
|
+
|
|
209
|
+
Produce `{ specName, matchType, addedLines, removedLines, behavioralChanges, headingChanges }`.
|
|
210
|
+
|
|
211
|
+
**Behavioral change classification:**
|
|
212
|
+
|
|
213
|
+
- Line added + contains `SHALL`/`MUST` → new requirement.
|
|
214
|
+
- Line removed + contains `SHALL`/`MUST` → removed requirement.
|
|
215
|
+
- Line modified (matched by proximity) + normative keyword → modified requirement.
|
|
216
|
+
- Other additions/removals → structural/non-normative.
|
|
217
|
+
|
|
218
|
+
Build `DIFF_RESULT` from all `SPEC_PAIRS`.
|
|
219
|
+
|
|
220
|
+
### Step 3c: Compute summary statistics
|
|
221
|
+
|
|
222
|
+
```
|
|
223
|
+
ADDED_COUNT = count(addedStatements) + count(added spec files)
|
|
224
|
+
MODIFIED_COUNT = count(modifiedStatements) + count(modified spec files)
|
|
225
|
+
REMOVED_COUNT = count(removedStatements) + count(deleted spec files)
|
|
226
|
+
TOTAL_CHANGES = ADDED_COUNT + MODIFIED_COUNT + REMOVED_COUNT
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
## Phase 4: Render Output
|
|
232
|
+
|
|
233
|
+
### If FORMAT = "json"
|
|
234
|
+
|
|
235
|
+
Emit a single JSON object:
|
|
236
|
+
|
|
237
|
+
```json
|
|
238
|
+
{
|
|
239
|
+
"schema_version": "1",
|
|
240
|
+
"project": "{{PROJECT_NAME}}",
|
|
241
|
+
"change": "<CHANGE_NAME>",
|
|
242
|
+
"generated_at": "<ISO 8601 timestamp>",
|
|
243
|
+
"source": "<delta-spec | spec-files>",
|
|
244
|
+
"summary": {
|
|
245
|
+
"total_changes": <N>,
|
|
246
|
+
"added": <N>,
|
|
247
|
+
"modified": <N>,
|
|
248
|
+
"removed": <N>
|
|
249
|
+
},
|
|
250
|
+
"added_statements": [
|
|
251
|
+
{ "id": "1.1", "text": "..." }
|
|
252
|
+
],
|
|
253
|
+
"modified_statements": [
|
|
254
|
+
{ "id": "2.3", "text": "...", "change_description": "..." }
|
|
255
|
+
],
|
|
256
|
+
"removed_statements": [
|
|
257
|
+
{ "id": "3.1", "text": "..." }
|
|
258
|
+
],
|
|
259
|
+
"surface_changes": [
|
|
260
|
+
{ "category": "...", "element": "...", "change": "...", "severity": "..." }
|
|
261
|
+
],
|
|
262
|
+
"api_changes": [
|
|
263
|
+
{ "method": "POST", "path": "/api/spawn", "description": "..." }
|
|
264
|
+
],
|
|
265
|
+
"spec_pairs": [
|
|
266
|
+
{
|
|
267
|
+
"spec_name": "...",
|
|
268
|
+
"match_type": "new|modified|deleted",
|
|
269
|
+
"added_lines": ["..."],
|
|
270
|
+
"removed_lines": ["..."],
|
|
271
|
+
"behavioral_changes": ["..."],
|
|
272
|
+
"heading_changes": ["..."]
|
|
273
|
+
}
|
|
274
|
+
]
|
|
275
|
+
}
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
Stop after emitting JSON.
|
|
279
|
+
|
|
280
|
+
### If FORMAT = "markdown"
|
|
281
|
+
|
|
282
|
+
Render the full diff report:
|
|
283
|
+
|
|
284
|
+
```
|
|
285
|
+
## OpenSpec Change Diff — <CHANGE_NAME>
|
|
286
|
+
Project: {{PROJECT_NAME}} | Generated: <YYYY-MM-DD HH:MM>
|
|
287
|
+
|
|
288
|
+
### Summary
|
|
289
|
+
|
|
290
|
+
| Metric | Count |
|
|
291
|
+
|--------|-------|
|
|
292
|
+
| ➕ Added requirements | <N> |
|
|
293
|
+
| ✏️ Modified requirements | <N> |
|
|
294
|
+
| ➖ Removed requirements | <N> |
|
|
295
|
+
| **Total changes** | **<N>** |
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
**If TOTAL_CHANGES = 0:**
|
|
299
|
+
```
|
|
300
|
+
✅ No behavioral differences detected between the change specs and the baseline.
|
|
301
|
+
```
|
|
302
|
+
Stop.
|
|
303
|
+
|
|
304
|
+
---
|
|
305
|
+
|
|
306
|
+
Then render sections:
|
|
307
|
+
|
|
308
|
+
#### Added Requirements
|
|
309
|
+
|
|
310
|
+
```
|
|
311
|
+
### ➕ Added Requirements (<N>)
|
|
312
|
+
|
|
313
|
+
<for each added statement:>
|
|
314
|
+
> **<id>** <text>
|
|
315
|
+
|
|
316
|
+
<if none:>
|
|
317
|
+
_No new requirements._
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
#### Modified Requirements
|
|
321
|
+
|
|
322
|
+
```
|
|
323
|
+
### ✏️ Modified Requirements (<N>)
|
|
324
|
+
|
|
325
|
+
<for each modified statement or spec pair with matchType="modified":>
|
|
326
|
+
#### <spec-name or section heading>
|
|
327
|
+
|
|
328
|
+
\`\`\`diff
|
|
329
|
+
- <removed line>
|
|
330
|
+
+ <added line>
|
|
331
|
+
\`\`\`
|
|
332
|
+
|
|
333
|
+
**Change:** <change_description or inferred summary>
|
|
334
|
+
|
|
335
|
+
<if SUMMARY_ONLY=true: skip inline diff blocks, show only change description>
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
#### Removed Requirements
|
|
339
|
+
|
|
340
|
+
```
|
|
341
|
+
### ➖ Removed Requirements (<N>)
|
|
342
|
+
|
|
343
|
+
<for each removed statement:>
|
|
344
|
+
> ~~**<id>** <text>~~
|
|
345
|
+
|
|
346
|
+
<if none:>
|
|
347
|
+
_No requirements removed._
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
#### Surface Impact (when HAS_DELTA_SPEC=true and SURFACE_CHANGES is non-empty)
|
|
351
|
+
|
|
352
|
+
```
|
|
353
|
+
### 🗺️ Surface Impact
|
|
354
|
+
|
|
355
|
+
| # | Category | Element | Change | Severity |
|
|
356
|
+
|---|----------|---------|--------|----------|
|
|
357
|
+
<rows from SURFACE_CHANGES>
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
#### API Contract Changes (when API_CHANGES is non-empty)
|
|
361
|
+
|
|
362
|
+
```
|
|
363
|
+
### 🔌 API Contract Changes
|
|
364
|
+
|
|
365
|
+
<for each API_CHANGES entry:>
|
|
366
|
+
- **<METHOD> <path>** — <description>
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
#### New Spec Files (when added spec files exist)
|
|
370
|
+
|
|
371
|
+
```
|
|
372
|
+
### 📄 New Spec Files
|
|
373
|
+
|
|
374
|
+
<for each specPair where matchType="new":>
|
|
375
|
+
- `<changePath>` — new spec, no baseline counterpart
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
#### Deleted Spec Files (when deleted spec files exist)
|
|
379
|
+
|
|
380
|
+
```
|
|
381
|
+
### 🗑️ Deleted Spec Files
|
|
382
|
+
|
|
383
|
+
<for each specPair where matchType="deleted":>
|
|
384
|
+
- `<baselinePath>` — removed by this change
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
---
|
|
388
|
+
|
|
389
|
+
Close the report:
|
|
390
|
+
|
|
391
|
+
```
|
|
392
|
+
---
|
|
393
|
+
_Generated by `/sr:opsx-diff` in {{PROJECT_NAME}}_
|
|
394
|
+
_Change source: <CHANGE_DIR>_
|
|
395
|
+
|
|
396
|
+
**Next steps:**
|
|
397
|
+
- Run `/opsx:apply <CHANGE_NAME>` to implement these changes.
|
|
398
|
+
- Run `/opsx:archive <CHANGE_NAME>` after implementation to merge specs into baseline.
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
---
|
|
402
|
+
|
|
403
|
+
## Phase 5: Save Snapshot (optional)
|
|
404
|
+
|
|
405
|
+
After rendering, write a diff snapshot to `.claude/opsx-diff-history/`:
|
|
406
|
+
|
|
407
|
+
1. Filename: `<CHANGE_NAME>-<YYYY-MM-DD>.json`
|
|
408
|
+
2. Directory: `.claude/opsx-diff-history/` (create if absent, idempotent).
|
|
409
|
+
3. Content: the JSON object from Phase 4 (regardless of FORMAT setting).
|
|
410
|
+
|
|
411
|
+
Print: `Snapshot saved: .claude/opsx-diff-history/<CHANGE_NAME>-<YYYY-MM-DD>.json`
|
|
412
|
+
|
|
413
|
+
If the write fails: print `Warning: could not write diff snapshot. Continuing.` Do not abort.
|
|
414
|
+
|
|
415
|
+
**Housekeeping:** If `.claude/opsx-diff-history/` has more than 50 `.json` files, print:
|
|
416
|
+
```
|
|
417
|
+
Note: .claude/opsx-diff-history/ has <N> snapshots. Prune old ones with:
|
|
418
|
+
ls -t .claude/opsx-diff-history/ | tail -n +51 | xargs -I{} rm .claude/opsx-diff-history/{}
|
|
419
|
+
```
|