@skitterbyte/skitterspec 23.23.3 → 23.24.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.
@@ -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
@@ -411,6 +411,14 @@ marks phase 1 started, refreshes the mirror again, builds it with tests and
411
411
  reports. Do not stop and ask the operator to run it: the branch is here and they
412
412
  asked to start the spec.
413
413
 
414
+ **An autonomous run does not ask.** `--auto`, `--supervised` and
415
+ `--then pause|push|pr` are passed straight through to `/spec-next`, which
416
+ resolves the run (flag > the spec's `Run:` header > `auto` in
417
+ `env.config.json`). Ask `skitterspec spec-env run resolve <name> … --json`
418
+ here first. When it answers `mode: "auto"`, the operator has already said to
419
+ build it all, so carry on into `/spec-next` with the same flags in either
420
+ mode. On `supervised`, the rest of this step applies.
421
+
414
422
  **`worktree` mode — offer it, then do what they say.** Step 3 left this session
415
423
  standing in the worktree, so both endings happen right here and neither needs a
416
424
  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",
3
- "version": "23.23.3",
3
+ "version": "23.24.0",
4
4
  "description": "Spec-driven development for Claude Code \u2014 a tracker-free filesystem workflow: lifecycle skills and per-spec isolation. For Linear sync, install @skitterbyte/skitterspec-linear instead.",
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,
@@ -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
  *
@@ -5870,6 +6073,17 @@ function specEnvReviewSkip(dir, config, rest, flags) {
5870
6073
  }
5871
6074
 
5872
6075
  async function specEnvReview(dir, config, specArg, flags, invokedFrom = dir) {
6076
+ // THE FINAL PAGE of an autonomous run (feat-autonomous-run): the whole
6077
+ // branch, under the ending's buttons. Said as one flag because the two halves
6078
+ // are never wanted apart — a final page of one phase's diff would ask the
6079
+ // reader to judge the run from a part of it.
6080
+ if (flags.final) {
6081
+ if (flags.buttons && flags.buttons !== 'final') {
6082
+ process.stdout.write(`spec-env review: --final and --buttons ${flags.buttons} contradict each other — nothing rendered.\n`)
6083
+ return
6084
+ }
6085
+ flags = { ...flags, buttons: 'final', branch: true }
6086
+ }
5873
6087
  // REFUSED BY NAME, never coerced to the default. A typo'd button set silently
5874
6088
  // rendering the committing page is the same failure the verdict validator
5875
6089
  // refuses for the same reason: a caller asking for the mid-run page and
@@ -6594,7 +6808,47 @@ async function specEnvReview(dir, config, specArg, flags, invokedFrom = dir) {
6594
6808
  }
6595
6809
  }
6596
6810
 
6597
- writeReviewPage(out, renderReviewPage(data, { reviewHtml: renderReviewBlock(data.review) }))
6811
+ // THE PHASE REPORT (feat-autonomous-run). The terminal block's rows, kept
6812
+ // per phase beside the notes so the served page — which re-renders from disk
6813
+ // — shows them too. Best-effort: a report that will not parse is said and
6814
+ // skipped, never a failed render.
6815
+ if (flags.report) {
6816
+ let parsed = null
6817
+ try {
6818
+ parsed = JSON.parse(fs.readFileSync(path.resolve(flags.report), 'utf8'))
6819
+ } catch (err) {
6820
+ process.stdout.write(`spec-env review: --report ${flags.report} is not readable JSON — page rendered without it\n`)
6821
+ }
6822
+ if (parsed !== null) {
6823
+ const valid = validateReport(parsed)
6824
+ const stored = readReport(out, spec.folder)
6825
+ if (!valid.ok) {
6826
+ process.stdout.write(`spec-env review: --report ignored — ${valid.reason}\n`)
6827
+ } else if (stored.corrupt) {
6828
+ process.stdout.write(`spec-env review: ${reviewReportPath(out)} is not readable JSON — move it aside; report not recorded\n`)
6829
+ } else {
6830
+ writeReport(out, recordReport(stored.report, { phase: flags.phase, title: valid.title, rows: valid.rows, at: now }))
6831
+ }
6832
+ }
6833
+ }
6834
+
6835
+ writeReviewPage(out, renderReviewPage(data, { reviewHtml: pageHeadFor(out, spec.folder, buttons) + renderReviewBlock(data.review) }))
6836
+
6837
+ // THE KEPT PHASE PAGE. The same render, read-only, written where the next
6838
+ // phase's render will not reach it — so the run can be read phase by phase
6839
+ // after it has moved on. It needs a phase to be named, because a snapshot of
6840
+ // "whatever phase this is" is one nobody can find again.
6841
+ if (flags.snapshot) {
6842
+ const n = Number(flags.phase)
6843
+ if (!Number.isInteger(n) || n < 1) {
6844
+ process.stdout.write('spec-env review: --snapshot needs --phase <n> — no snapshot kept\n')
6845
+ } else {
6846
+ const snap = snapshotPath(out, n)
6847
+ fs.mkdirSync(path.dirname(snap), { recursive: true })
6848
+ fs.writeFileSync(snap, renderReviewPage({ ...data, buttons: 'snapshot' }, { reviewHtml: reportHtmlFor(out, spec.folder) + renderReviewBlock(data.review) }))
6849
+ if (!flags.json) process.stdout.write(` snapshot: phase ${n} · ${snap}\n`)
6850
+ }
6851
+ }
6598
6852
 
6599
6853
  // RECORD WHAT THIS RENDER DECLARED, for the served copy to read back. The
6600
6854
  // daemon re-renders per request and is not the caller, so without this it can
@@ -8328,6 +8582,14 @@ async function specEnv(rest) {
8328
8582
  else if (args[i] === '--use-fallback') flags.useFallback = true
8329
8583
  else if (args[i] === '--unpin') flags.unpin = true
8330
8584
  else if (args[i] === '--reopen') flags.reopen = true
8585
+ else if (args[i] === '--auto') flags.auto = true
8586
+ else if (args[i] === '--supervised') flags.supervised = true
8587
+ else if (args[i] === '--then') flags.then = args[++i] ?? ''
8588
+ else if (args[i] === '--commit') flags.commit = args[++i]
8589
+ else if (args[i] === '--snapshot') flags.snapshot = true
8590
+ else if (args[i] === '--final') flags.final = true
8591
+ else if (args[i] === '--reason') flags.reason = args[++i]
8592
+ else if (args[i] === '--report') flags.report = args[++i]
8331
8593
  else positional.push(args[i])
8332
8594
  }
8333
8595
  dir = path.resolve(dir)
@@ -8482,6 +8744,9 @@ async function specEnvDispatch(sub, dir, config, positional, flags, present, inv
8482
8744
  case 'resume':
8483
8745
  specEnvResume(dir, config, positional[0], flags)
8484
8746
  break
8747
+ case 'run':
8748
+ specEnvRun(dir, config, positional, flags)
8749
+ break
8485
8750
  case 'base':
8486
8751
  specEnvBase(dir, config, flags)
8487
8752
  break
@@ -8536,7 +8801,7 @@ async function specEnvDispatch(sub, dir, config, positional, flags, present, inv
8536
8801
  break
8537
8802
  default:
8538
8803
  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` +
8804
+ `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
8805
  ' review serve [--port <n>] [--host <addr>] [--stop] [--status] serve every diff locally\n' +
8541
8806
  ' review serve --rotate-token mint a new URL token; every handed-out link dies\n' +
8542
8807
  ' review allow network [--off] permit the network and tailnet tiers\n' +
package/src/env/config.js CHANGED
@@ -344,6 +344,16 @@ const DEFAULT_CONFIG = Object.freeze({
344
344
  // adapter, `{name, command, format}` is bring-your-own.
345
345
  reviewers: Object.freeze([]),
346
346
  }),
347
+ // Autonomous runs (`spec-env run`, feat-autonomous-run). `default` is the
348
+ // mode a spec runs in when neither its `> **Run:**` header nor a flag says:
349
+ // "supervised" (stop on every phase's page, today's behaviour) or "auto"
350
+ // (build every phase, commit each, stop only on a stop condition). `then` is
351
+ // how an autonomous run ends: "pause" (one final page that waits), "push"
352
+ // (push the branch) or "pr" (`/spec-complete`'s PR run). Configuring push or
353
+ // pr IS the push consent for runs that take it. `maxFixAttempts` bounds the
354
+ // tries at a red phase before the run stops. An unrecognised value falls back
355
+ // to its default — never to "auto": a typo must not make a run unattended.
356
+ auto: Object.freeze({ default: 'supervised', then: 'pause', maxFixAttempts: 3 }),
347
357
  // Live overlay (`spec-env live`). `migrations` is a list of globs marking
348
358
  // migration files; a branch that changes any of them is treated as stateful and
349
359
  // `live take` refuses it (code-only v1). Default: none (nothing is stateful).
@@ -458,6 +468,7 @@ function defaults() {
458
468
  guards: { ...DEFAULT_CONFIG.guards },
459
469
  teardown: { ...DEFAULT_CONFIG.teardown },
460
470
  review: { ...DEFAULT_CONFIG.review, reviewers: [] },
471
+ auto: { ...DEFAULT_CONFIG.auto },
461
472
  live: { migrations: [], afterSwitch: [] },
462
473
  hotfix: { ...DEFAULT_CONFIG.hotfix, targets: [] },
463
474
  }
@@ -858,6 +869,13 @@ function mergeConfig(base, parsed) {
858
869
  }
859
870
  }
860
871
 
872
+ if (isObject(parsed.auto)) {
873
+ if (parsed.auto.default === 'auto' || parsed.auto.default === 'supervised') base.auto.default = parsed.auto.default
874
+ if (['pause', 'push', 'pr'].includes(parsed.auto.then)) base.auto.then = parsed.auto.then
875
+ const n = parsed.auto.maxFixAttempts
876
+ if (Number.isInteger(n) && n >= 0) base.auto.maxFixAttempts = n
877
+ }
878
+
861
879
  if (isObject(parsed.spec) && Array.isArray(parsed.spec.companionPaths)) {
862
880
  base.spec.companionPaths = normalizeFileList(parsed.spec.companionPaths)
863
881
  }
package/src/env/hooks.js CHANGED
@@ -82,7 +82,18 @@ const HOOKS = [
82
82
  matcher: 'Edit|Write|NotebookEdit|MultiEdit|Bash',
83
83
  timeout: HOOK_TIMEOUT,
84
84
  },
85
- ].map((h) => ({ ...h, script: `${h.stem}.cjs`, re: hookStemRe(h.stem) }))
85
+ {
86
+ // Notes a context compaction against the phase an autonomous run is
87
+ // building (feat-autonomous-run). A different EVENT, not a different
88
+ // matcher: it fires before the harness compacts, on either trigger, so it
89
+ // carries no matcher at all. It decides nothing and never blocks.
90
+ key: 'run-compact',
91
+ stem: '.claude/hooks/run-compact',
92
+ event: 'PreCompact',
93
+ matcher: null,
94
+ timeout: HOOK_TIMEOUT,
95
+ },
96
+ ].map((h) => ({ event: 'PreToolUse', ...h, script: `${h.stem}.cjs`, re: hookStemRe(h.stem) }))
86
97
 
87
98
  function isObject(value) {
88
99
  return value !== null && typeof value === 'object' && !Array.isArray(value)
@@ -105,10 +116,17 @@ function commandFor(script) {
105
116
  }
106
117
 
107
118
  function hookEntry(hook = HOOKS[0]) {
108
- return {
109
- matcher: hook.matcher,
110
- hooks: [{ type: 'command', command: commandFor(hook.script), timeout: hook.timeout }],
111
- }
119
+ const hooks = [{ type: 'command', command: commandFor(hook.script), timeout: hook.timeout }]
120
+ // An event with no matcher (PreCompact here) is written without the key, so
121
+ // it fires on every trigger rather than on a matcher of the empty string.
122
+ return hook.matcher ? { matcher: hook.matcher, hooks } : { hooks }
123
+ }
124
+
125
+ // Every hook entry this package writes, grouped by the event it belongs under.
126
+ function entriesByEvent() {
127
+ const out = {}
128
+ for (const h of HOOKS) (out[h.event] = out[h.event] || []).push(hookEntry(h))
129
+ return out
112
130
  }
113
131
 
114
132
  /**
@@ -149,7 +167,8 @@ function registeredHooks(preToolUse, hook = HOOKS[0]) {
149
167
  */
150
168
  function ensureOneHook(parsed, hook) {
151
169
  const hooks = isObject(parsed.hooks) ? parsed.hooks : {}
152
- const preToolUse = Array.isArray(hooks.PreToolUse) ? hooks.PreToolUse : []
170
+ const event = hook.event || 'PreToolUse'
171
+ const preToolUse = Array.isArray(hooks[event]) ? hooks[event] : []
153
172
 
154
173
  // Registered already — but possibly under a path that no longer exists, since
155
174
  // the script's extension changed. Rewrite the path IN PLACE rather than
@@ -166,7 +185,7 @@ function ensureOneHook(parsed, hook) {
166
185
  return { changed: true, reason: 'migrated' }
167
186
  }
168
187
 
169
- parsed.hooks = { ...hooks, PreToolUse: [...preToolUse, hookEntry(hook)] }
188
+ parsed.hooks = { ...hooks, [event]: [...preToolUse, hookEntry(hook)] }
170
189
  return { changed: true, reason: 'added' }
171
190
  }
172
191
 
@@ -192,7 +211,7 @@ function ensureHooks(dir, { local = false } = {}) {
192
211
  raw = fs.readFileSync(file, 'utf-8')
193
212
  } catch (error) {
194
213
  if (error.code === 'ENOENT') {
195
- writeSettings(file, { hooks: { PreToolUse: HOOKS.map((h) => hookEntry(h)) } })
214
+ writeSettings(file, { hooks: entriesByEvent() })
196
215
  return { changed: true, reason: 'created' }
197
216
  }
198
217
  throw error
@@ -241,25 +260,30 @@ function removeHooks(dir, { local = false, dryRun = false } = {}) {
241
260
  return { removed: 0, emptied: false, reason: error.code === 'ENOENT' ? 'absent' : 'malformed' }
242
261
  }
243
262
  if (!isObject(parsed)) return { removed: 0, emptied: false, reason: 'malformed' }
244
- const pre = isObject(parsed.hooks) && Array.isArray(parsed.hooks.PreToolUse) ? parsed.hooks.PreToolUse : null
245
- if (!pre) return { removed: 0, emptied: false, reason: 'none' }
263
+ if (!isObject(parsed.hooks)) return { removed: 0, emptied: false, reason: 'none' }
246
264
 
247
265
  let removed = 0
248
266
  const ours = (h) => isObject(h) && typeof h.command === 'string' && HOOKS.some((k) => k.re.test(h.command))
249
- const kept = []
250
- for (const group of pre) {
251
- if (!isObject(group) || !Array.isArray(group.hooks)) {
252
- kept.push(group)
253
- continue
267
+ // Every event this package registers under — and only those, so another
268
+ // event's hooks are never even looked at.
269
+ for (const event of [...new Set(HOOKS.map((h) => h.event))]) {
270
+ const pre = Array.isArray(parsed.hooks[event]) ? parsed.hooks[event] : null
271
+ if (!pre) continue
272
+ const kept = []
273
+ for (const group of pre) {
274
+ if (!isObject(group) || !Array.isArray(group.hooks)) {
275
+ kept.push(group)
276
+ continue
277
+ }
278
+ const rest = group.hooks.filter((h) => !ours(h))
279
+ removed += group.hooks.length - rest.length
280
+ if (rest.length) kept.push(rest.length === group.hooks.length ? group : { ...group, hooks: rest })
254
281
  }
255
- const rest = group.hooks.filter((h) => !ours(h))
256
- removed += group.hooks.length - rest.length
257
- if (rest.length) kept.push(rest.length === group.hooks.length ? group : { ...group, hooks: rest })
282
+ if (kept.length) parsed.hooks[event] = kept
283
+ else delete parsed.hooks[event]
258
284
  }
259
285
  if (!removed) return { removed: 0, emptied: false, reason: 'none' }
260
286
 
261
- if (kept.length) parsed.hooks.PreToolUse = kept
262
- else delete parsed.hooks.PreToolUse
263
287
  if (!Object.keys(parsed.hooks).length) delete parsed.hooks
264
288
  const emptied = !Object.keys(parsed).length
265
289
  if (!emptied && !dryRun) writeSettings(file, parsed)