@skitterbyte/skitterspec-azure-boards 3.1.3 → 3.2.1

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.
Files changed (42) hide show
  1. package/assets/claude-md-section.md +4 -0
  2. package/assets/core/azure-boards.config.md +2 -1
  3. package/assets/core/env.config.json.example +5 -0
  4. package/assets/core/env.config.md +20 -1
  5. package/assets/hooks/run-compact.cjs +162 -0
  6. package/assets/review/page.html +122 -2
  7. package/assets/rules/spec-format.md +6 -0
  8. package/assets/rules/spec-planning.md +9 -0
  9. package/assets/rules/spec-reports.md +5 -0
  10. package/assets/skills/spec/SKILL.md +25 -1
  11. package/assets/skills/spec-bug/SKILL.md +14 -0
  12. package/assets/skills/spec-complete/SKILL.md +9 -0
  13. package/assets/skills/spec-diff/SKILL.md +24 -0
  14. package/assets/skills/spec-hotfix/SKILL.md +14 -0
  15. package/assets/skills/spec-idea/SKILL.md +6 -0
  16. package/assets/skills/spec-next/SKILL.md +18 -1
  17. package/assets/skills/spec-next/autonomous.md +126 -0
  18. package/assets/skills/spec-reviewed/SKILL.md +2 -1
  19. package/assets/skills/spec-start/SKILL.md +8 -0
  20. package/assets/skills/spec-start/isolation.md +1 -1
  21. package/package.json +1 -1
  22. package/src/cli.js +271 -4
  23. package/src/env/classify.js +61 -6
  24. package/src/env/config.js +18 -0
  25. package/src/env/epic.js +1 -1
  26. package/src/env/epicpage.js +1 -1
  27. package/src/env/hooks.js +44 -20
  28. package/src/env/report.js +192 -0
  29. package/src/env/resolve.js +6 -1
  30. package/src/env/review.js +14 -2
  31. package/src/env/run.js +226 -0
  32. package/src/env/runpage.js +229 -0
  33. package/src/env/serve.js +50 -6
  34. package/src/ideacmd.js +5 -2
  35. package/src/provider.js +46 -1
  36. package/src/vendor/azure-boards/api.js +13 -0
  37. package/src/vendor/azure-boards/cli-sync.js +109 -11
  38. package/src/vendor/azure-boards/config.js +47 -2
  39. package/src/vendor/provider-kit/src/apply.js +3 -0
  40. package/src/vendor/sync-core/src/compare.js +32 -1
  41. package/src/vendor/sync-core/src/normalize.js +3 -2
  42. package/src/vendor/sync-core/src/push.js +29 -1
@@ -16,6 +16,15 @@ flight — provisioning, moving it to `in-progress`, getting its branch here —
16
16
  `/spec-start`'s job. Re-run this per phase until the spec is done, then
17
17
  `/spec-complete`.
18
18
 
19
+ **Or let it run.** `--auto`, `--supervised` and `--then pause|push|pr` choose
20
+ whether this run stops on every phase's page or builds every phase to the
21
+ end. Once §1 has named the spec, ask the engine
22
+ (`skitterspec spec-env run resolve <spec> … --json`, passing only the flags
23
+ typed). On `mode: "auto"`, follow
24
+ [`autonomous.md`](autonomous.md) for the whole run. It reuses §2 to §4b
25
+ unchanged and replaces §5 and §6. On `supervised`, the default everywhere
26
+ nothing says otherwise, this file applies exactly as written.
27
+
19
28
  ## 1. Identify the spec in flight
20
29
 
21
30
  **`--worktree <path>` answers before anything else.** When the invocation names a
@@ -461,9 +470,17 @@ the moment the page is about, so render it now — **after** the tests pass and
461
470
  **before** the commit:
462
471
 
463
472
  ```
464
- skitterspec spec-env review <spec> --run-reviewers
473
+ skitterspec spec-env review <spec> --run-reviewers --report <rows.json> --phase <n>
465
474
  ```
466
475
 
476
+ **`--report` puts this phase's report table on the page**, so its Notes and
477
+ Follow-ups are there for anyone who reads the page later, not only in this
478
+ terminal. Write the rows of the block §6 will end with, as JSON in a scratch
479
+ file: `{"title": "<verdict sentence>", "rows": [{"field": "Built", "value":
480
+ "…"}, …]}`, leaving out `Next` and `Review`, which only make sense here. An
481
+ empty `field` continues the row above. The engine orders, escapes and keeps
482
+ them per phase, and a bad file is reported and skipped, never a failed render.
483
+
467
484
  **This is free.** It is the engine reading git and splicing text into a template;
468
485
  the diff never passes through you, so a 266KB patch costs nothing. Report the
469
486
  path it prints and move on.
@@ -0,0 +1,126 @@
1
+ # Autonomous runs — the loop `/spec-next` runs when nobody is stopping it
2
+
3
+ A spec whose run resolves to **auto** is built from its next phase to its last
4
+ without stopping for a verdict at each one. Every phase still gets its page,
5
+ kept as a snapshot the reader can open while the run carries on, and the run
6
+ ends where the operator chose: paused on one final page, pushed, or opened as
7
+ a PR. This file is the whole contract; `SKILL.md` says only when to follow it.
8
+
9
+ ## Resolve once, at the start
10
+
11
+ ```
12
+ skitterspec spec-env run resolve <spec> [--auto|--supervised] [--then pause|push|pr] --phase <first unfinished> --json
13
+ ```
14
+
15
+ Pass through exactly the flags the operator typed, and nothing else. The
16
+ engine applies the precedence: flag > an active run > the spec's
17
+ `> **Run:**` header > `auto` in `env.config.json` > supervised.
18
+ **`mode: "supervised"` means this file does not apply.** Build the phase as `SKILL.md`
19
+ describes and stop on its page. A refusal (`ok: false`) is a typo in the flags.
20
+ Relay it with `⏸` and stop.
21
+
22
+ `mode: "auto"` opened (or resumed) the run record. Keep `then` and
23
+ `maxFixAttempts` from the answer. Naming `push` or `pr`, by flag or by config,
24
+ **is** the operator's consent to push for this run. Nothing else in the run
25
+ pushes.
26
+
27
+ ## Each phase
28
+
29
+ Run `SKILL.md` §2–§4b exactly as written: pre-flight, epic check, blocker
30
+ check, mark started, tracker refresh, build, tests, record progress. Then the
31
+ two places it differs:
32
+
33
+ 1. **Re-read before building.** Start each phase from the spec files and
34
+ `git log`, never from what you remember of the last one. A compaction may
35
+ have happened in between, and the files are the record that survives it.
36
+ 2. **§5 snapshots and commits instead of waiting.** Write this phase's report
37
+ rows (the block you would end with, as JSON, see `--report` in `SKILL.md`
38
+ §5) and render:
39
+
40
+ ```
41
+ skitterspec spec-env review <spec> --run-reviewers --report <file> --phase <n> --snapshot
42
+ ```
43
+
44
+ **Do not arm the gate and do not wait.** Commit through `review.commitWith`
45
+ (`/commit` by default), exactly as a `commit` verdict would, then record it:
46
+
47
+ ```
48
+ skitterspec spec-env run phase <spec> <n> --commit <sha>
49
+ ```
50
+
51
+ That puts `auto-commit` in the review history, so the record says the run
52
+ committed this phase and no verdict did. Reviewer findings are recorded on
53
+ the snapshot and never acted on.
54
+
55
+ Then go straight on to the next phase. Say nothing between phases beyond a
56
+ failure as it happens. The report is the block at the end.
57
+
58
+ ## Stop conditions — the run hands back to a person
59
+
60
+ Stop **before building** a phase when any of these holds, and **after building**
61
+ when the tests stay red:
62
+
63
+ | Condition | Where it is seen |
64
+ |-----------|------------------|
65
+ | Tests red after `maxFixAttempts` fix attempts | §3, after each try |
66
+ | A `Blocked on:` line, or an unmet epic `Waits on:` | §3's `resume` and `epic check` |
67
+ | The phase has steps only a person can do | §3 *Manual steps* |
68
+ | A decision the spec left open, with more than one defensible answer | while building |
69
+
70
+ On a stop:
71
+
72
+ 1. `skitterspec spec-env run stop <spec> --reason "<one clause>"`.
73
+ 2. End exactly as a supervised phase would: the `⏸`/`❌`/`⚠️` block `SKILL.md`
74
+ names for that case, then (where a page was rendered) arm the gate and wait.
75
+ For a blocker or epic wait, nothing was built, so there is no page.
76
+ 3. **The run stays active.** When the operator presses `Commit & Continue`, or
77
+ types `/spec-next`, `run resolve` returns the run's own mode and ending
78
+ (`modeFrom: "run"`), and the loop picks up where it stopped. `--supervised`
79
+ on that command ends autonomy for the rest of the spec.
80
+
81
+ Never step past a stop condition to keep the run going. A run that guesses is
82
+ worse than one that waits.
83
+
84
+ ## The ending — after the last phase
85
+
86
+ `run status --json` names the ending. Then:
87
+
88
+ - **`pause`.** Render the final page, arm the gate for the last phase, and wait
89
+ exactly as `SKILL.md` §5 does:
90
+
91
+ ```
92
+ skitterspec spec-env review <spec> --final --run-reviewers
93
+ ```
94
+
95
+ It shows the whole branch, under one list of every phase's follow-ups and
96
+ notes, the stops and compactions, with links to each snapshot and the run
97
+ index. Its buttons are `Complete`, `Push branch`, `Open PR`,
98
+ `Request changes` and `Discuss`. `/spec-diff` §2a routes them.
99
+ - **`push`.** `skitterspec spec-env integrate <spec> --push`, and run what it
100
+ plans. The spec stays in flight.
101
+ - **`pr`.** Hand off to **`/spec-complete`**, whose PR-mode first run verifies
102
+ every phase, pushes, and opens the PR. Its body lists each phase with its
103
+ commit, from `run status --json`.
104
+
105
+ Then `skitterspec spec-env run end <spec> --outcome <ending>`, and write one
106
+ dated Changelog line on the spec: the phases built, the ending, and the
107
+ compaction summary when there is one.
108
+
109
+ ## Notify
110
+
111
+ On the run's end, and on every stop, send a push notification where the
112
+ harness has one (Claude Code: `PushNotification`). Keep it to one line: the
113
+ spec, what happened, and what it is waiting for. A harness without one sends
114
+ nothing. The block, and the banner when waiting, follow as usual.
115
+
116
+ ## Report
117
+
118
+ One block for the whole run, at its end or its stop. It is not one per phase,
119
+ because each phase's rows are already on its snapshot. Fields as `SKILL.md`
120
+ §6, plus:
121
+
122
+ - `Built` names the phases built in this run, each with its commit.
123
+ - `Notes` carries the compaction summary from `run status`, when there is
124
+ one, and any stop's reason.
125
+ - `Review`, when not waiting, links the run index: the `local` URL with
126
+ `/run` appended, and the same for every tier.
@@ -83,7 +83,8 @@ invocation does, above, and claim the code *there*. Then go to step 4 — a name
83
83
  pass has nothing to disambiguate.
84
84
 
85
85
  A **verdict word** — `commit`, `commit-continue`, `commit-start`,
86
- `commit-land`, `continue`, `changes`, `discuss` — is the conclusion itself,
86
+ `commit-land`, `complete`, `push`, `pr`, `continue`, `changes`, `discuss` —
87
+ is the conclusion itself,
87
88
  arriving without a pass behind it. It is
88
89
  what a **`file://` page** hands over: that page has no server to POST to and no
89
90
  store to write to, so it copies a command instead of sending anything, and this
@@ -553,6 +553,14 @@ marks phase 1 started, refreshes the mirror again, builds it with tests and
553
553
  reports. Do not stop and ask the operator to run it: the branch is here and they
554
554
  asked to start the spec.
555
555
 
556
+ **An autonomous run does not ask.** `--auto`, `--supervised` and
557
+ `--then pause|push|pr` are passed straight through to `/spec-next`, which
558
+ resolves the run (flag > the spec's `Run:` header > `auto` in
559
+ `env.config.json`). Ask `skitterspec spec-env run resolve <name> … --json`
560
+ here first. When it answers `mode: "auto"`, the operator has already said to
561
+ build it all, so carry on into `/spec-next` with the same flags in either
562
+ mode. On `supervised`, the rest of this step applies.
563
+
556
564
  **`worktree` mode — offer it, then do what they say.** Step 3 left this session
557
565
  standing in the worktree, so both endings happen right here and neither needs a
558
566
  second session opened anywhere. In prose: say the worktree is ready and name its
@@ -31,7 +31,7 @@ host **dev servers** (`dev` in `env.config.json`) on the spec's ports.
31
31
  first.
32
32
 
33
33
  The engine is `skitterspec spec-env
34
- <up|bootstrap|nospec|main|project|down|prune|dev|connect|integrate|disposition|handoff|hotfix|live|review|stage|checks|status|resolve|resume|base>`.
34
+ <up|bootstrap|nospec|main|project|down|prune|dev|connect|integrate|disposition|handoff|hotfix|live|review|stage|checks|status|resolve|resume|run|base>`.
35
35
  `up` plans the fork, and **`bootstrap` runs the worktree's own steps**: seeding
36
36
  the gitignored files, the env file, `setup` and the stack. Never reconstruct
37
37
  those steps as shell commands.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skitterbyte/skitterspec-azure-boards",
3
- "version": "3.1.3",
3
+ "version": "3.2.1",
4
4
  "description": "Spec-driven development for Claude Code, with one-way Azure Boards sync — a superset of @skitterbyte/skitterspec: the base filesystem workflow plus /spec-status · /spec-push · /spec-claim and the spec-sync CLI, mirroring specs to Azure DevOps work items with parent/child hierarchy, assignment and a release work item per tag. The repo is canonical; Boards is a generated mirror. Install this OR the base OR one other superset — exactly one.",
5
5
  "keywords": [
6
6
  "claude",
package/src/cli.js CHANGED
@@ -47,6 +47,7 @@ const SPEC_ENV_VERBS = Object.freeze([
47
47
  'status',
48
48
  'resolve',
49
49
  'resume',
50
+ 'run',
50
51
  'base',
51
52
  'nospec',
52
53
  'main',
@@ -174,6 +175,23 @@ const {
174
175
  grantPermit,
175
176
  permitHonoured,
176
177
  } = require('./env/review.js')
178
+ const {
179
+ ENDINGS,
180
+ parseRunHeader,
181
+ resolveRun,
182
+ runPath,
183
+ readRun,
184
+ writeRun,
185
+ openRun,
186
+ currentPhase,
187
+ recordPhase,
188
+ recordStop,
189
+ recordCompaction,
190
+ endRun,
191
+ compactionSummary,
192
+ } = require('./env/run.js')
193
+ const { reportHtmlFor, readReport, writeReport, validateReport, recordReport, reviewReportPath } = require('./env/report.js')
194
+ const { snapshotPath, pageHeadFor } = require('./env/runpage.js')
177
195
  const {
178
196
  CHECKS_VERSION,
179
197
  BUNDLED_ADAPTERS,
@@ -186,7 +204,7 @@ const {
186
204
  } = require('./env/reviewers.js')
187
205
  const { planUp, planCheckoutUp, resolveStack, worktreeSteps } = require('./env/provision.js')
188
206
  const { runBootstrap, describeStep } = require('./env/bootstrap.js')
189
- const { classifyDirtyTree, dirtyPaths, specDocsIn } = require('./env/classify.js')
207
+ const { classifyDirtyTree, dirtyPaths, specDocsIn, treeReader } = require('./env/classify.js')
190
208
  const { isGitCommit } = require('./env/commitcmd.js')
191
209
  const { planDown, planDownCheckout } = require('./env/teardown.js')
192
210
  const {
@@ -359,6 +377,10 @@ Usage:
359
377
  (prints commands; creates nothing)
360
378
  --reopen: a completed spec, re-opened on a
361
379
  fresh branch from the base
380
+ run <action> [spec] an autonomous run: resolve (mode + ending,
381
+ --auto|--supervised, --then pause|push|pr),
382
+ phase <n> --commit <sha>, stop --reason,
383
+ compacted, end, status
362
384
  base fetch, list baseBranchPattern matches
363
385
  newest-first, mark the base, and name
364
386
  specs forked from an older match
@@ -4719,6 +4741,187 @@ function specEnvResolve(dir, config, specArg, flags = {}) {
4719
4741
  )
4720
4742
  }
4721
4743
 
4744
+ /**
4745
+ * `skitterspec spec-env run <resolve|phase|stop|compacted|end|status> [spec]`
4746
+ * (feat-autonomous-run)
4747
+ *
4748
+ * resolve [spec] [--auto|--supervised] [--then pause|push|pr] [--phase <n>]
4749
+ * which mode and ending this run takes; an autonomous one opens
4750
+ * (or keeps) the run record. A supervised one writes nothing.
4751
+ * phase [spec] <n> [--commit <sha>]
4752
+ * a phase the run committed; also logs `auto-commit` in the
4753
+ * review outcome log, so "nobody pressed a verdict" is on record.
4754
+ * stop [spec] --reason <text> the run stopped on a stop condition
4755
+ * compacted [spec] the context compacted (the hook's call)
4756
+ * end [spec] [--outcome <ending>]
4757
+ * status [spec]
4758
+ *
4759
+ * `--json` on every action. The record lives in the primary checkout's state
4760
+ * dir, beside the review sidecars, so every worktree reads the same one.
4761
+ *
4762
+ * NEVER FATAL BEYOND A TYPO. A flag that contradicts itself refuses (exit 1);
4763
+ * a corrupt record is cannot-tell — reported, never written over — and the
4764
+ * `compacted` action exits 0 and says nothing on every cannot-tell, because a
4765
+ * hook that fails loudly on a session with no run is accusing a healthy one.
4766
+ */
4767
+ function specEnvRun(dir, config, positional, flags = {}) {
4768
+ const action = positional[0] || 'status'
4769
+ const rest = positional.slice(1)
4770
+ const numeric = rest.find((a) => /^\d+$/.test(a))
4771
+ const specArg = rest.find((a) => !/^\d+$/.test(a))
4772
+ const quietOnUnknown = action === 'compacted'
4773
+ const say = (obj, text) => {
4774
+ if (flags.json) process.stdout.write(JSON.stringify(obj, null, 2) + '\n')
4775
+ else if (text) process.stdout.write(text + '\n')
4776
+ }
4777
+ if (!RUN_ACTIONS.includes(action)) {
4778
+ process.exitCode = 1
4779
+ say({ ok: false, reason: `unknown action ${action}` }, `spec-env run: unknown action "${action}" — use ${RUN_ACTIONS.join(', ')}`)
4780
+ return
4781
+ }
4782
+ const stateDir = path.join(dir, stateDirLabel(config))
4783
+ let spec
4784
+ try {
4785
+ spec = resolveSpecWithWorktree(dir, config, specArg)
4786
+ } catch (err) {
4787
+ // THE HOOK'S FALLBACK, and only the hook's. A session compacting in the
4788
+ // primary checkout names no spec and stands in no worktree, so the usual
4789
+ // resolution has nothing to go on. The run record itself is a positive
4790
+ // signal: exactly ONE active run is the run that is compacting. None, or
4791
+ // several, is cannot-tell and records nothing.
4792
+ const sole = quietOnUnknown && !specArg ? soleActiveRun(stateDir) : null
4793
+ if (sole) {
4794
+ try {
4795
+ spec = resolveSpecWithWorktree(dir, config, sole)
4796
+ } catch {
4797
+ return
4798
+ }
4799
+ } else {
4800
+ if (quietOnUnknown) return
4801
+ say({ ok: false, reason: err.message }, `spec-env run: cannot tell which spec — ${err.message}`)
4802
+ return
4803
+ }
4804
+ }
4805
+ const read = readRun(stateDir, spec.folder)
4806
+ if (read.corrupt) {
4807
+ if (quietOnUnknown) return
4808
+ say(
4809
+ { ok: false, spec: spec.folder, corrupt: true },
4810
+ `spec-env run: ${runPath(stateDir, spec.folder)} is not readable JSON — move it aside rather than losing what it holds.`,
4811
+ )
4812
+ return
4813
+ }
4814
+ const at = new Date().toISOString()
4815
+ const active = read.record && read.record.active ? read.record : null
4816
+
4817
+ if (action === 'resolve') {
4818
+ let overview = ''
4819
+ try {
4820
+ overview = fs.readFileSync(path.join(spec.path, '00-overview.md'), 'utf8')
4821
+ } catch {
4822
+ // No overview is no header: the config decides, as for any spec without one.
4823
+ }
4824
+ const header = parseRunHeader(overview)
4825
+ const resolved = resolveRun({ flags, header, config, active })
4826
+ if (!resolved.ok) {
4827
+ process.exitCode = 1
4828
+ say({ ok: false, spec: spec.folder, reason: resolved.reason }, `spec-env run: ${resolved.reason}`)
4829
+ return
4830
+ }
4831
+ let record = null
4832
+ if (resolved.mode === 'auto') {
4833
+ record = openRun(read.record, resolved, { spec: spec.folder, at, startPhase: flags.phase })
4834
+ writeRun(stateDir, spec.folder, record)
4835
+ }
4836
+ const from = { flag: 'flag', run: 'the active run', header: 'the spec header', config: 'env.config.json', default: 'default' }
4837
+ say(
4838
+ { ok: true, spec: spec.folder, ...resolved, resumed: Boolean(active && resolved.mode === 'auto'), record: record ? runPath(stateDir, spec.folder) : null },
4839
+ `spec-env run: ${spec.folder}\n` +
4840
+ ` mode: ${resolved.mode} (${from[resolved.modeFrom]})\n` +
4841
+ (resolved.mode === 'auto'
4842
+ ? ` then: ${resolved.then} (${from[resolved.thenFrom]})\n` +
4843
+ ` fixes: up to ${resolved.maxFixAttempts} at a red phase\n` +
4844
+ ` record: ${active ? 'resumed' : 'opened'} · ${runPath(stateDir, spec.folder)}`
4845
+ : ' record: none — a supervised run stops on every phase'),
4846
+ )
4847
+ return
4848
+ }
4849
+
4850
+ if (action === 'status') {
4851
+ say(
4852
+ { ok: true, spec: spec.folder, record: read.record, compactions: compactionSummary(read.record) || null },
4853
+ read.record
4854
+ ? `spec-env run: ${spec.folder} — ${read.record.active ? 'active' : 'ended'} · ${read.record.mode} · then ${read.record.then}\n` +
4855
+ ` phases: ${(read.record.phases || []).map((p) => `${p.n}${p.commit ? `@${String(p.commit).slice(0, 7)}` : ''}`).join(', ') || 'none yet'}\n` +
4856
+ ` stops: ${(read.record.stops || []).length}` +
4857
+ (compactionSummary(read.record) ? `\n context: ${compactionSummary(read.record)}` : '')
4858
+ : `spec-env run: ${spec.folder} — no run recorded`,
4859
+ )
4860
+ return
4861
+ }
4862
+
4863
+ // Every remaining action writes to an ACTIVE run. Without one there is
4864
+ // nothing to write to, and inventing a run would put an autonomous run in
4865
+ // the record that nobody started.
4866
+ if (!active) {
4867
+ if (quietOnUnknown) return
4868
+ say({ ok: false, spec: spec.folder, reason: 'no active run' }, `spec-env run ${action}: ${spec.folder} has no active run — nothing recorded`)
4869
+ return
4870
+ }
4871
+
4872
+ let record = active
4873
+ if (action === 'phase') {
4874
+ const n = numeric || flags.phase
4875
+ const result = recordPhase(record, { n: Number(n), commit: flags.commit, at })
4876
+ if (!result.ok) {
4877
+ process.exitCode = 1
4878
+ say({ ok: false, spec: spec.folder, reason: result.reason }, `spec-env run phase: ${result.reason}`)
4879
+ return
4880
+ }
4881
+ record = result.record
4882
+ // On the review's own record too, where a reader of the page looks: the
4883
+ // phase was committed by the run, not by a verdict.
4884
+ const out = reviewOutPath(dir, spec.folder)
4885
+ const notesRead = readNotes(out, spec.folder)
4886
+ if (!notesRead.corrupt) {
4887
+ writeNotes(out, appendDecision(notesRead.notes, { verdict: 'auto-commit', at, note: `phase ${n}${flags.commit ? ` · ${flags.commit}` : ''} · autonomous run` }))
4888
+ }
4889
+ } else if (action === 'stop') {
4890
+ record = recordStop(record, { reason: flags.reason, at })
4891
+ } else if (action === 'compacted') {
4892
+ record = recordCompaction(record, { at })
4893
+ } else if (action === 'end') {
4894
+ const outcome = flags.outcome && ENDINGS.includes(flags.outcome) ? flags.outcome : null
4895
+ record = endRun(record, { at, outcome })
4896
+ }
4897
+ writeRun(stateDir, spec.folder, record)
4898
+ const line = {
4899
+ phase: () => `spec-env run: ${spec.folder} — phase ${numeric || flags.phase} recorded`,
4900
+ stop: () => `spec-env run: ${spec.folder} — stopped at phase ${currentPhase(record)}`,
4901
+ compacted: () => `spec-env run: ${spec.folder} — ${compactionSummary(record)}`,
4902
+ end: () => `spec-env run: ${spec.folder} — ended (${record.outcome})` + (compactionSummary(record) ? ` · ${compactionSummary(record)}` : ''),
4903
+ }[action]()
4904
+ say({ ok: true, spec: spec.folder, action, record, compactions: compactionSummary(record) || null }, line)
4905
+ }
4906
+
4907
+ const RUN_ACTIONS = Object.freeze(['resolve', 'phase', 'stop', 'compacted', 'end', 'status'])
4908
+
4909
+ // The one spec with an active run in this state dir, or null when there are
4910
+ // none or several. Never throws: an unreadable record is not an active run.
4911
+ function soleActiveRun(stateDir) {
4912
+ let names
4913
+ try {
4914
+ names = fs.readdirSync(path.join(stateDir, 'runs')).filter((n) => n.endsWith('.json'))
4915
+ } catch {
4916
+ return null
4917
+ }
4918
+ const active = names.map((n) => n.slice(0, -5)).filter((spec) => {
4919
+ const read = readRun(stateDir, spec)
4920
+ return !read.corrupt && read.record && read.record.active
4921
+ })
4922
+ return active.length === 1 ? active[0] : null
4923
+ }
4924
+
4722
4925
  /**
4723
4926
  * `skitterspec spec-env resume <name|#N> [--reopen] [--json]` (feat-spec-resume)
4724
4927
  *
@@ -5140,7 +5343,8 @@ function specEnvStage(dir, config, specArg, flags = {}, invokedFrom = dir) {
5140
5343
  // PROJECT folder in it — what a pathspec is when run from where a session
5141
5344
  // stands. The same thing at the root of a repo (feat-subfolder-project).
5142
5345
  const prefix = prefixOf(config)
5143
- const split = classifyDirtyTree(spec, paths, config)
5346
+ // The same reader the page uses, so an epic stages the members it shows.
5347
+ const split = classifyDirtyTree(spec, paths, config, { readFile: treeReader(tree) })
5144
5348
  const owned = split.owned.map((p) => projectRelative(p, prefix))
5145
5349
  const foreign = split.foreign.map((p) => projectRelative(p, prefix))
5146
5350
  const treeShown = prefix ? projectIn(tree, prefix) : tree
@@ -5870,6 +6074,17 @@ function specEnvReviewSkip(dir, config, rest, flags) {
5870
6074
  }
5871
6075
 
5872
6076
  async function specEnvReview(dir, config, specArg, flags, invokedFrom = dir) {
6077
+ // THE FINAL PAGE of an autonomous run (feat-autonomous-run): the whole
6078
+ // branch, under the ending's buttons. Said as one flag because the two halves
6079
+ // are never wanted apart — a final page of one phase's diff would ask the
6080
+ // reader to judge the run from a part of it.
6081
+ if (flags.final) {
6082
+ if (flags.buttons && flags.buttons !== 'final') {
6083
+ process.stdout.write(`spec-env review: --final and --buttons ${flags.buttons} contradict each other — nothing rendered.\n`)
6084
+ return
6085
+ }
6086
+ flags = { ...flags, buttons: 'final', branch: true }
6087
+ }
5873
6088
  // REFUSED BY NAME, never coerced to the default. A typo'd button set silently
5874
6089
  // rendering the committing page is the same failure the verdict validator
5875
6090
  // refuses for the same reason: a caller asking for the mid-run page and
@@ -6594,7 +6809,47 @@ async function specEnvReview(dir, config, specArg, flags, invokedFrom = dir) {
6594
6809
  }
6595
6810
  }
6596
6811
 
6597
- writeReviewPage(out, renderReviewPage(data, { reviewHtml: renderReviewBlock(data.review) }))
6812
+ // THE PHASE REPORT (feat-autonomous-run). The terminal block's rows, kept
6813
+ // per phase beside the notes so the served page — which re-renders from disk
6814
+ // — shows them too. Best-effort: a report that will not parse is said and
6815
+ // skipped, never a failed render.
6816
+ if (flags.report) {
6817
+ let parsed = null
6818
+ try {
6819
+ parsed = JSON.parse(fs.readFileSync(path.resolve(flags.report), 'utf8'))
6820
+ } catch (err) {
6821
+ process.stdout.write(`spec-env review: --report ${flags.report} is not readable JSON — page rendered without it\n`)
6822
+ }
6823
+ if (parsed !== null) {
6824
+ const valid = validateReport(parsed)
6825
+ const stored = readReport(out, spec.folder)
6826
+ if (!valid.ok) {
6827
+ process.stdout.write(`spec-env review: --report ignored — ${valid.reason}\n`)
6828
+ } else if (stored.corrupt) {
6829
+ process.stdout.write(`spec-env review: ${reviewReportPath(out)} is not readable JSON — move it aside; report not recorded\n`)
6830
+ } else {
6831
+ writeReport(out, recordReport(stored.report, { phase: flags.phase, title: valid.title, rows: valid.rows, at: now }))
6832
+ }
6833
+ }
6834
+ }
6835
+
6836
+ writeReviewPage(out, renderReviewPage(data, { reviewHtml: pageHeadFor(out, spec.folder, buttons) + renderReviewBlock(data.review) }))
6837
+
6838
+ // THE KEPT PHASE PAGE. The same render, read-only, written where the next
6839
+ // phase's render will not reach it — so the run can be read phase by phase
6840
+ // after it has moved on. It needs a phase to be named, because a snapshot of
6841
+ // "whatever phase this is" is one nobody can find again.
6842
+ if (flags.snapshot) {
6843
+ const n = Number(flags.phase)
6844
+ if (!Number.isInteger(n) || n < 1) {
6845
+ process.stdout.write('spec-env review: --snapshot needs --phase <n> — no snapshot kept\n')
6846
+ } else {
6847
+ const snap = snapshotPath(out, n)
6848
+ fs.mkdirSync(path.dirname(snap), { recursive: true })
6849
+ fs.writeFileSync(snap, renderReviewPage({ ...data, buttons: 'snapshot' }, { reviewHtml: reportHtmlFor(out, spec.folder) + renderReviewBlock(data.review) }))
6850
+ if (!flags.json) process.stdout.write(` snapshot: phase ${n} · ${snap}\n`)
6851
+ }
6852
+ }
6598
6853
 
6599
6854
  // RECORD WHAT THIS RENDER DECLARED, for the served copy to read back. The
6600
6855
  // daemon re-renders per request and is not the caller, so without this it can
@@ -8328,6 +8583,14 @@ async function specEnv(rest) {
8328
8583
  else if (args[i] === '--use-fallback') flags.useFallback = true
8329
8584
  else if (args[i] === '--unpin') flags.unpin = true
8330
8585
  else if (args[i] === '--reopen') flags.reopen = true
8586
+ else if (args[i] === '--auto') flags.auto = true
8587
+ else if (args[i] === '--supervised') flags.supervised = true
8588
+ else if (args[i] === '--then') flags.then = args[++i] ?? ''
8589
+ else if (args[i] === '--commit') flags.commit = args[++i]
8590
+ else if (args[i] === '--snapshot') flags.snapshot = true
8591
+ else if (args[i] === '--final') flags.final = true
8592
+ else if (args[i] === '--reason') flags.reason = args[++i]
8593
+ else if (args[i] === '--report') flags.report = args[++i]
8331
8594
  else positional.push(args[i])
8332
8595
  }
8333
8596
  dir = path.resolve(dir)
@@ -8482,6 +8745,9 @@ async function specEnvDispatch(sub, dir, config, positional, flags, present, inv
8482
8745
  case 'resume':
8483
8746
  specEnvResume(dir, config, positional[0], flags)
8484
8747
  break
8748
+ case 'run':
8749
+ specEnvRun(dir, config, positional, flags)
8750
+ break
8485
8751
  case 'base':
8486
8752
  specEnvBase(dir, config, flags)
8487
8753
  break
@@ -8536,7 +8802,7 @@ async function specEnvDispatch(sub, dir, config, positional, flags, present, inv
8536
8802
  break
8537
8803
  default:
8538
8804
  process.stdout.write(
8539
- `Usage: skitterspec spec-env <${SPEC_ENV_VERBS.join('|')}> [spec] [--keep-volumes] [--force] [--also <tag>] [--older-than <days>] [--branch] [--out <file>] [--review <json>] [--run-reviewers] [--notes <json>] [--verdict <word>] [--resolve <json>] [--outcome <text>] [--claim <code>] [--drop <code>] [--buttons <set>] [--json] [--record-primary] [--assert-primary-clean]\n` +
8805
+ `Usage: skitterspec spec-env <${SPEC_ENV_VERBS.join('|')}> [spec] [--keep-volumes] [--force] [--also <tag>] [--older-than <days>] [--branch] [--out <file>] [--review <json>] [--report <json>] [--run-reviewers] [--notes <json>] [--verdict <word>] [--resolve <json>] [--outcome <text>] [--claim <code>] [--drop <code>] [--buttons <set>] [--json] [--record-primary] [--assert-primary-clean]\n` +
8540
8806
  ' review serve [--port <n>] [--host <addr>] [--stop] [--status] serve every diff locally\n' +
8541
8807
  ' review serve --rotate-token mint a new URL token; every handed-out link dies\n' +
8542
8808
  ' review allow network [--off] permit the network and tailnet tiers\n' +
@@ -8741,6 +9007,7 @@ module.exports = {
8741
9007
  run,
8742
9008
  parse,
8743
9009
  HELP,
9010
+ PROVIDER_COMMANDS,
8744
9011
  unknownCommand,
8745
9012
  rankLanAddresses,
8746
9013
  offerableLanAddresses,
@@ -15,9 +15,19 @@
15
15
  * foreign path disqualifies the whole tree.
16
16
  */
17
17
 
18
+ const fs = require('node:fs')
18
19
  const path = require('node:path')
19
- const { BUCKETS, expandTokens, readFrontmatterField } = require('./resolve.js')
20
- const { fromRepoPath, prefixOf } = require('./project.js')
20
+ const { BUCKETS, expandTokens, readFrontmatterField, isEpic } = require('./resolve.js')
21
+ const { fromRepoPath, toRepoPath, prefixOf } = require('./project.js')
22
+
23
+ // The `> **Epic:**` header off an overview, unquoted, or null. The same reading
24
+ // as `epicHeaders` in env/epic.js, kept here so the classifier stays a leaf.
25
+ function epicNamed(text) {
26
+ const m = /^>\s*\*\*Epic:\*\*[ \t]*(.*)$/m.exec(text || '')
27
+ if (!m) return null
28
+ const value = m[1].trim().replace(/^`(.*)`$/, '$1').trim()
29
+ return value || null
30
+ }
21
31
 
22
32
  // git reports repo-relative, forward-slashed paths; an untracked directory comes
23
33
  // back with a trailing slash. Normalise both away so comparisons are exact.
@@ -77,10 +87,23 @@ function expandCompanion(pattern, spec, config) {
77
87
  * (backlog → in-progress), so a tree mid-move is dirty in two buckets at once
78
88
  * and both halves are the same spec's.
79
89
  * - each expandable `spec.companionPaths` entry.
90
+ * - for an EPIC, and only given `readFile`: anything inside another spec's
91
+ * folder whose `00-overview.md`, read from the same tree, carries
92
+ * `> **Epic:** <this epic>`. `/spec` writes an epic WITH its members in one
93
+ * worktree, so those members are the epic's documents being written, not
94
+ * somebody else's work (bug-epic-page-misses-members).
95
+ *
96
+ * WHAT WOULD FOOL THE MEMBER RULE: a member's overview that is not in the tree
97
+ * being read. That reads as null, which is cannot-tell, and cannot-tell stays
98
+ * foreign: a refusal is the safe direction to be wrong in. A spec naming another
99
+ * epic, or none, is foreign as before.
80
100
  *
101
+ * @param {object} [opts]
102
+ * - `readFile` repo-relative path → text, or null. Without it no member is
103
+ * owned, which is the answer every caller had before.
81
104
  * @returns {{owned: string[], foreign: string[]}}
82
105
  */
83
- function classifyDirtyTree(spec, dirtyPaths, config) {
106
+ function classifyDirtyTree(spec, dirtyPaths, config, { readFile = null } = {}) {
84
107
  const owned = []
85
108
  const foreign = []
86
109
  if (!spec) return { owned, foreign: (dirtyPaths || []).map(normalize).filter(Boolean) }
@@ -93,12 +116,30 @@ function classifyDirtyTree(spec, dirtyPaths, config) {
93
116
  }
94
117
 
95
118
  const prefix = prefixOf(config)
119
+ // One read per member folder, however many of its files are dirty.
120
+ const memberFolders = new Map()
121
+ const memberOf = (rel) => {
122
+ if (!readFile || !isEpic(spec.folder) || rel === null) return false
123
+ const m = /^specs\/([^/]+)\/([^/]+)\//.exec(rel)
124
+ if (!m || !BUCKETS.includes(m[1])) return false
125
+ const key = `${m[1]}/${m[2]}`
126
+ if (!memberFolders.has(key)) {
127
+ let text = null
128
+ try {
129
+ text = readFile(toRepoPath(`specs/${key}/00-overview.md`, prefix))
130
+ } catch {
131
+ // unreadable: cannot tell, so not a member
132
+ }
133
+ memberFolders.set(key, epicNamed(text) === spec.folder)
134
+ }
135
+ return memberFolders.get(key)
136
+ }
96
137
  for (const raw of dirtyPaths || []) {
97
138
  const p = normalize(raw)
98
139
  if (!p) continue
99
140
  const rel = fromRepoPath(p, prefix)
100
141
  const inFolder = rel !== null && folders.some((f) => rel === f || rel.startsWith(`${f}/`))
101
- if (inFolder || (rel !== null && companions.has(rel))) owned.push(p)
142
+ if (inFolder || (rel !== null && companions.has(rel)) || memberOf(rel)) owned.push(p)
102
143
  else foreign.push(p)
103
144
  }
104
145
  return { owned, foreign }
@@ -176,9 +217,23 @@ function dirtyPaths(git) {
176
217
  function specDocsIn(tree, spec, config, git) {
177
218
  const paths = dirtyPaths(git)
178
219
  if (paths === null) return { error: 'git could not be read' }
179
- const { owned } = classifyDirtyTree(spec, paths, config)
220
+ const { owned } = classifyDirtyTree(spec, paths, config, { readFile: treeReader(tree) })
180
221
  if (!owned.length) return { empty: true }
181
222
  return { tree, owned }
182
223
  }
183
224
 
184
- module.exports = { classifyDirtyTree, expandCompanion, unquotePath, dirtyPaths, specDocsIn }
225
+ /**
226
+ * `classifyDirtyTree`'s `readFile` for a checkout: repo-relative path → its
227
+ * text in that working tree, or null when it cannot be read (cannot tell).
228
+ */
229
+ function treeReader(root) {
230
+ return (rel) => {
231
+ try {
232
+ return fs.readFileSync(path.join(root, rel), 'utf8')
233
+ } catch {
234
+ return null
235
+ }
236
+ }
237
+ }
238
+
239
+ module.exports = { treeReader, classifyDirtyTree, expandCompanion, unquotePath, dirtyPaths, specDocsIn }