@skitterbyte/skitterspec 23.15.0 → 23.18.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/src/env/config.js CHANGED
@@ -44,6 +44,8 @@
44
44
  * baseBranch: "", // "" = auto-detect (origin/HEAD → main → master)
45
45
  * baseBranchPattern: "", // glob over remote branch names; newest match
46
46
  * // by commit date is the base (rolling release-candidate)
47
+ * baseBranchFallback: "", // offered as the base while the pattern matches
48
+ * // nothing; "" = the remote's default branch
47
49
  * land: { strategy, remote, draft, specDocs }, // how a branch lands:
48
50
  * // "ff" (default, trunk-based local fast-forward) or "pr"
49
51
  * // (push + pull request; base moves when the host merges)
@@ -65,6 +67,7 @@
65
67
  const { createHash } = require('node:crypto')
66
68
  const { existsSync, readFileSync, realpathSync } = require('node:fs')
67
69
  const { join, resolve, sep } = require('node:path')
70
+ const { readBasePin } = require('./basepin.js')
68
71
 
69
72
  const CONFIG_FILE = join('specs', '.core', 'env.config.json')
70
73
 
@@ -227,6 +230,12 @@ const DEFAULT_CONFIG = Object.freeze({
227
230
  // candidate is all it takes to move every spec onto it. An explicit
228
231
  // `baseBranch` still wins. Empty = off, and resolution is exactly as before.
229
232
  baseBranchPattern: '',
233
+ // The base to offer while `baseBranchPattern` matches nothing — the gap
234
+ // between one release branch merging and the next being cut. Empty = the
235
+ // remote's default branch. Only ever used once someone accepts the offer,
236
+ // which writes a local pin (`env/basepin.js`); never consulted without a
237
+ // pattern.
238
+ baseBranchFallback: '',
230
239
  // How a finished branch reaches the base branch. `strategy: "ff"` (the
231
240
  // default) is trunk-based landing exactly as it has always been: rebase, then
232
241
  // a local `merge --ff-only` — nothing changes for an installed repo on
@@ -428,6 +437,7 @@ function defaults() {
428
437
  spec: { companionPaths: [] },
429
438
  baseBranch: DEFAULT_CONFIG.baseBranch,
430
439
  baseBranchPattern: DEFAULT_CONFIG.baseBranchPattern,
440
+ baseBranchFallback: DEFAULT_CONFIG.baseBranchFallback,
431
441
  land: { ...DEFAULT_CONFIG.land },
432
442
  guards: { ...DEFAULT_CONFIG.guards },
433
443
  teardown: { ...DEFAULT_CONFIG.teardown },
@@ -712,6 +722,11 @@ function mergeConfig(base, parsed) {
712
722
  const pattern = parsed.baseBranchPattern.trim()
713
723
  if (pattern && !/\s/.test(pattern) && !pattern.includes('..')) base.baseBranchPattern = pattern
714
724
  }
725
+ // A branch name, so the same two characters can never be in it.
726
+ if (typeof parsed.baseBranchFallback === 'string') {
727
+ const fallback = parsed.baseBranchFallback.trim()
728
+ if (fallback && !/\s/.test(fallback) && !fallback.includes('..')) base.baseBranchFallback = fallback
729
+ }
715
730
 
716
731
  // Same treatment as `teardown.deleteRemoteBranch` below, for the same reason:
717
732
  // an unrecognised value falls through to the default rather than erroring or
@@ -944,6 +959,27 @@ function applyProviderSpecDocs(config, parsed, dir) {
944
959
  return config
945
960
  }
946
961
 
962
+ /**
963
+ * Attach the gap pin (`env/basepin.js`) to a loaded config as `gapPin`, so every
964
+ * caller that resolves the base from this config honours it with nothing passed
965
+ * — the main guard, the served pages and the dashboard included. Without a
966
+ * pattern there is no gap and nothing is read.
967
+ *
968
+ * Non-enumerable, because it is local state rather than configuration: it must
969
+ * not appear in a config dump, a deep-equal, or anything written back to disk.
970
+ * `dir` is the folder the config was read from — the primary checkout for
971
+ * every caller that anchors there first. One that does not finds no pin, which
972
+ * is the harmless direction: it refuses and offers again.
973
+ */
974
+ function withGapPin(config, dir) {
975
+ if (config.baseBranchPattern) {
976
+ // A getter, read on every resolve: the review server loads its config once
977
+ // and lives for days, and a pin taken after it started must still count.
978
+ Object.defineProperty(config, 'gapPin', { get: () => readBasePin(dir, config), enumerable: false })
979
+ }
980
+ return config
981
+ }
982
+
947
983
  function loadEnvConfig(dir = process.cwd()) {
948
984
  const base = defaults()
949
985
  const file = join(dir, CONFIG_FILE)
@@ -971,7 +1007,7 @@ function loadEnvConfig(dir = process.cwd()) {
971
1007
  }
972
1008
 
973
1009
  return {
974
- config: applyProviderSpecDocs(applyProviderEnvDefaults(mergeConfig(base, parsed), parsed), parsed, dir),
1010
+ config: withGapPin(applyProviderSpecDocs(applyProviderEnvDefaults(mergeConfig(base, parsed), parsed), parsed, dir), dir),
975
1011
  present: true,
976
1012
  unknown: collectUnknownKeys(parsed),
977
1013
  badReviewers: collectBadReviewers(parsed),
@@ -439,15 +439,22 @@ function branchFor(spec, config) {
439
439
  /**
440
440
  * Thrown when `baseBranchPattern` is set and no remote branch matches it. A
441
441
  * refusal, never a fall-through: the default branch is exactly where a rolling
442
- * base must not land. `refused` carries the one-line reason; `pattern` the glob.
442
+ * base must not land unasked. `refused` carries the one-line reason; `pattern`
443
+ * the glob. `offer` is the way out the engine declares
444
+ * (`.claude/rules/offered-unblocks.md`) — pin the fallback for the gap — and is
445
+ * null when no fallback resolves, because guessing a base is worse than asking.
443
446
  */
444
447
  class BaseUnresolvedError extends Error {
445
- constructor(pattern) {
448
+ constructor(pattern, fallback = null) {
446
449
  const refused = `no branch matches ${pattern} — run spec-env base to fetch`
447
450
  super(refused)
448
451
  this.name = 'BaseUnresolvedError'
449
452
  this.refused = refused
450
453
  this.pattern = pattern
454
+ this.fallback = fallback
455
+ this.offer = fallback
456
+ ? { kind: 'satisfy', label: `Use ${fallback} as the base for now`, command: 'skitterspec spec-env base --use-fallback' }
457
+ : null
451
458
  }
452
459
  }
453
460
 
@@ -456,7 +463,8 @@ class BaseUnresolvedError extends Error {
456
463
  * onto). Precedence:
457
464
  * 1. `config.baseBranch` — explicit override
458
465
  * 2. `config.baseBranchPattern` — the newest remote branch matching it, by
459
- * committer date; no match throws `BaseUnresolvedError`
466
+ * committer date; no match takes a gap pin made under that same pattern
467
+ * (`env/basepin.js`), else throws `BaseUnresolvedError`
460
468
  * 3. `origin/HEAD` — the remote's default branch
461
469
  * 4. `main` if it exists locally
462
470
  * 5. `master` if it exists locally
@@ -471,30 +479,40 @@ class BaseUnresolvedError extends Error {
471
479
  * synchronous for every caller, the main-guard hook included. Fetching is left
472
480
  * to the commands that already talk to the remote.
473
481
  */
474
- function resolveBaseBranch(config, git) {
475
- const { base, refused } = describeBaseBranch(config, git)
482
+ function resolveBaseBranch(config, git, pin = (config && config.gapPin) || null) {
483
+ const { base, refused } = describeBaseBranch(config, git, pin)
476
484
  if (refused) throw refused
477
485
  return base
478
486
  }
479
487
 
480
488
  /**
481
489
  * The same resolution as `resolveBaseBranch`, returned as data with HOW it was
482
- * found — `pin` · `pattern` · `origin-head` · `local` · `fallback` — for the
483
- * one surface that reports it (`spec-env base`). A pattern with no match comes
484
- * back as `{ base: null, how: 'pattern', refused }` rather than thrown, so a
485
- * listing can still say what it saw.
490
+ * found — `pin` · `pattern` · `gap-pin` · `origin-head` · `local` · `fallback`
491
+ * — for the surfaces that report it. A pattern with no match comes back as
492
+ * `{ base: null, how: 'pattern', refused }` rather than thrown, so a listing
493
+ * can still say what it saw.
494
+ *
495
+ * `pin` is the gap pin as `readBasePin` returns it, or null. It defaults to
496
+ * the one `loadEnvConfig` attached as `config.gapPin`, so callers need not
497
+ * pass it; it is never read from disk here, so this stays pure. It is honoured only while the
498
+ * pattern has NO match and only when it was made under this same pattern: a
499
+ * match always wins, which is what makes the pin clear itself the moment the
500
+ * next release branch is cut. `stalePin` says a pin was passed and a match
501
+ * overrode it, so the caller can delete the file.
486
502
  */
487
- function describeBaseBranch(config, git) {
503
+ function describeBaseBranch(config, git, pin = (config && config.gapPin) || null) {
488
504
  const explicit = config && typeof config.baseBranch === 'string' && config.baseBranch.trim()
489
505
  if (explicit) return { base: explicit, how: 'pin' }
490
506
 
491
507
  const pattern = config && typeof config.baseBranchPattern === 'string' && config.baseBranchPattern.trim()
492
508
  if (pattern) {
493
509
  try {
494
- return { base: newestMatch(config, git, pattern), how: 'pattern' }
510
+ const base = newestMatch(config, git, pattern)
511
+ return pin ? { base, how: 'pattern', stalePin: true } : { base, how: 'pattern' }
495
512
  } catch (error) {
496
- if (error instanceof BaseUnresolvedError) return { base: null, how: 'pattern', refused: error }
497
- throw error
513
+ if (!(error instanceof BaseUnresolvedError)) throw error
514
+ if (pin && pin.pattern === pattern && pin.base) return { base: pin.base, how: 'gap-pin', pin }
515
+ return { base: null, how: 'pattern', refused: new BaseUnresolvedError(pattern, gapFallback(config, git)) }
498
516
  }
499
517
  }
500
518
 
@@ -518,6 +536,39 @@ function baseRemote(config) {
518
536
  return (config && config.land && typeof config.land.remote === 'string' && config.land.remote.trim()) || 'origin'
519
537
  }
520
538
 
539
+ /**
540
+ * The words that go beside the base wherever one is shown, when a gap pin
541
+ * chose it — `no 20??/Q? branch on origin — pinned for the gap` — else null.
542
+ * One function so the page, the review text and the plans cannot disagree.
543
+ */
544
+ function gapNote(config, git) {
545
+ const { how } = describeBaseBranch(config, git)
546
+ if (how !== 'gap-pin') return null
547
+ return `no ${config.baseBranchPattern.trim()} branch on ${baseRemote(config)} — pinned for the gap`
548
+ }
549
+
550
+ // The branch a gap pin would name: `baseBranchFallback`, else the remote's
551
+ // default branch. Null when neither can be read — and then no offer is made,
552
+ // because a guessed base is worse than a refusal.
553
+ //
554
+ // WHAT WOULD FOOL THIS: an unset `<remote>/HEAD`. A clone made with
555
+ // `git clone` has one, but a repo that added its remote by hand does not until
556
+ // `git remote set-head` runs, so a healthy repo can land here with no offer.
557
+ // That costs a plain refusal, never a wrong base.
558
+ function gapFallback(config, git) {
559
+ const remote = baseRemote(config)
560
+ const named = config && typeof config.baseBranchFallback === 'string' && config.baseBranchFallback.trim()
561
+ if (named) {
562
+ const exists =
563
+ git(['show-ref', '--verify', '--quiet', `refs/remotes/${remote}/${named}`]) !== null ||
564
+ git(['show-ref', '--verify', '--quiet', `refs/heads/${named}`]) !== null
565
+ return exists ? named : null
566
+ }
567
+ const head = git(['symbolic-ref', '--short', `refs/remotes/${remote}/HEAD`])
568
+ if (!head) return null
569
+ return head.startsWith(`${remote}/`) ? head.slice(remote.length + 1) : head
570
+ }
571
+
521
572
  function newestMatch(config, git, pattern) {
522
573
  const remote = baseRemote(config)
523
574
  const prefix = `refs/remotes/${remote}/`
@@ -834,6 +885,8 @@ module.exports = {
834
885
  allSpecs,
835
886
  resolveBaseBranch,
836
887
  describeBaseBranch,
888
+ gapFallback,
889
+ gapNote,
837
890
  baseRemote,
838
891
  BaseUnresolvedError,
839
892
  resolvePrimaryCheckout,
package/src/env/review.js CHANGED
@@ -222,8 +222,13 @@ function numstatFor(git, ref, file, untracked) {
222
222
  * WHAT WOULD FOOL THIS: the bridge variable is an undocumented harness internal
223
223
  * and may be renamed or dropped, so its ABSENCE proves nothing — which is the
224
224
  * whole reason `unknown` exists and the default is not `local`.
225
+ *
226
+ * `platform` is passed in for the same reason as `env`, and defaults to NONE
227
+ * rather than `process.platform`: a caller that names no platform, and every
228
+ * test that states only an environment, gets the platform-free answer on any
229
+ * machine the suite runs on.
225
230
  */
226
- function detectReader(env = {}) {
231
+ function detectReader(env = {}, platform = null) {
227
232
  // SSH first: a standard convention, and the strongest available signal. If the
228
233
  // shell arrived over the network, the page's path is on a machine the reader
229
234
  // is not looking at.
@@ -233,6 +238,20 @@ function detectReader(env = {}) {
233
238
  // produced the original dead link, read on a phone.
234
239
  if (env.CLAUDE_CODE_BRIDGE_SESSION_ID) return { reader: 'remote', why: 'bridge session' }
235
240
 
241
+ // A WINDOWS SESSION WITH NO DESKTOP. Windows sets SESSIONNAME for every
242
+ // interactive logon — `Console` at the desktop, `RDP-Tcp#N` over Remote
243
+ // Desktop — and whatever starts from that desktop inherits it. A process
244
+ // outside any desktop has none: `prlctl exec`'s background logon (a Mac
245
+ // driving the VM), the OpenSSH server, a scheduled task, a service. Nobody is
246
+ // at this machine's browser in any of those.
247
+ //
248
+ // WHAT WOULD FOOL THIS: a scheduled task or service run while someone sits at
249
+ // the desk. That is affordable only because of what it decides — `local` is
250
+ // hidden only while `network` has a URL, and that URL is the same server, so
251
+ // a wrong guess costs the second-best link, never a page that will not open.
252
+ // Elsewhere SESSIONNAME means nothing, so its absence is not evidence.
253
+ if (platform === 'win32' && !env.SESSIONNAME) return { reader: 'remote', why: 'no interactive session' }
254
+
236
255
  // CLAUDE_CODE_ENTRYPOINT IS DELIBERATELY NOT CONSULTED. It describes the
237
256
  // PROCESS, not the reader, and reports `cli` for a bridged session — it said
238
257
  // exactly that for the session this was written from, where the reader was on
@@ -248,10 +267,38 @@ function detectReader(env = {}) {
248
267
  * sniffing: the operator knows where they are reading, and no signal outranks
249
268
  * being told.
250
269
  */
251
- function resolveReader(config, env = {}) {
270
+ function resolveReader(config, env = {}, platform = null) {
271
+ // THE WRAPPER FIRST, because it is the one thing that knows this machine. A
272
+ // committed `review.reader` speaks for every checkout of the repo; a wrapper
273
+ // that runs the engine inside a VM (`prlctl exec`) speaks for this one, and
274
+ // the VM shows nothing else to detect — no SSH, no session variables.
275
+ const told = String(env.SKITTERSPEC_READER || '').trim().toLowerCase()
276
+ if (told === 'local' || told === 'remote') return { reader: told, why: 'SKITTERSPEC_READER' }
252
277
  const setting = (config && config.review && config.review.reader) || 'detect'
253
278
  if (setting === 'local' || setting === 'remote') return { reader: setting, why: 'configured' }
254
- return detectReader(env)
279
+ return detectReader(env, platform)
280
+ }
281
+
282
+ /**
283
+ * Whether the reader's browser is on another machine, so `127.0.0.1` is the
284
+ * wrong one — the question that hides the `local` tier.
285
+ *
286
+ * NARROWER THAN `reader === 'remote'`, deliberately. A bridge session is a
287
+ * reader driving this session from elsewhere, but often from a browser on this
288
+ * same machine, where loopback opens fine; and its variable is an undocumented
289
+ * harness internal. Hiding a working link on that guess is the load-bearing
290
+ * detection `detectReader` warns against, so only the signals someone set on
291
+ * purpose count: the wrapper's variable, the committed setting, and SSH — plus
292
+ * one detection, a Windows session with no desktop, admitted because hiding
293
+ * `local` only ever happens beside a working `network` URL, so being wrong
294
+ * costs the second-best link rather than the loop.
295
+ *
296
+ * WHAT WOULD FOOL THIS: SSH with a `-L` port forward makes the reader's loopback
297
+ * reach this server, so `ssh` is a strong hint rather than proof —
298
+ * `SKITTERSPEC_READER=local` is the way back, and it outranks it.
299
+ */
300
+ function readerOffMachine(reader) {
301
+ return Boolean(reader && reader.reader === 'remote' && reader.why !== 'bridge session')
255
302
  }
256
303
 
257
304
  /**
@@ -269,7 +316,7 @@ function resolveReader(config, env = {}) {
269
316
  * `buttons` is the button set the page renders — see `BUTTON_SETS`. It is the
270
317
  * caller's declaration about the work, not a reading of the gate.
271
318
  */
272
- function collectReview({ spec, git, mode = 'working', ref, base = null, now, notes = null, gate = null, fellBack = false, buttons = null, only = null, treePath = null, live = null, tiers = null, project = null }) {
319
+ function collectReview({ spec, git, mode = 'working', ref, base = null, baseGap = null, now, notes = null, gate = null, fellBack = false, buttons = null, only = null, treePath = null, live = null, tiers = null, project = null }) {
273
320
  // WHICH TREE THE SPEC'S OWN DOCUMENTS ARE READ FROM. Every render but one
274
321
  // reads the spec's worktree, and for those the two are the same path — so
275
322
  // `treePath` left null keeps the existing behaviour exactly. The `docs` mode
@@ -377,6 +424,9 @@ function collectReview({ spec, git, mode = 'working', ref, base = null, now, not
377
424
  // "everything since main, because there was nothing uncommitted" are
378
425
  // different answers to "what am I looking at".
379
426
  fellBack,
427
+ // Set when a gap pin chose `base` (`gapNote`): the page says so beside it,
428
+ // because "since master" reads as a decision nobody made otherwise.
429
+ baseGap: base ? baseGap : null,
380
430
  generatedAt: now,
381
431
  // Is there a phase left for `/spec-next` to build? The page needs it to
382
432
  // know whether offering `Commit & Continue` means anything — and it is read
@@ -721,7 +771,7 @@ function surfacesFor({ live, tiers, buttons = null }) {
721
771
  * pending store, and one wait covers both. `remote` is a second store, which is
722
772
  * why it carries the line saying so.
723
773
  */
724
- function reviewTierStack({ served, fileUrl, publishedUrl, config }) {
774
+ function reviewTierStack({ served, fileUrl, publishedUrl, config, reader = null }) {
725
775
  const tiers = []
726
776
  const loopbackUrl = served && served.loopbackUrl ? served.loopbackUrl : null
727
777
 
@@ -772,9 +822,46 @@ function reviewTierStack({ served, fileUrl, publishedUrl, config }) {
772
822
  tiers.push({ tier: 'remote', unavailable: true, note: 'publishing is an ask — nothing published yet' })
773
823
  }
774
824
 
825
+ // A READER ON ANOTHER MACHINE gets no `local` door: it points at this
826
+ // machine's loopback, so it hangs and never opens — first in the list, and
827
+ // the one habit reaches for. Hidden only when `network` has a URL to take
828
+ // its place; with none, an empty stack is worse than a dead link that says
829
+ // it is dead, so it stays and says so. Kept in `--json` either way, marked,
830
+ // so the decision is visible rather than an absence.
831
+ if (readerOffMachine(reader)) {
832
+ const network = tiers.find((t) => t.tier === 'network')
833
+ const why = `the reader is on another machine (${reader.why})`
834
+ tiers[0] =
835
+ network && network.url
836
+ ? { ...tiers[0], hidden: true, reason: why }
837
+ : { ...tiers[0], note: "not reachable from the reader's machine" }
838
+ }
839
+
775
840
  return tiers
776
841
  }
777
842
 
843
+ /**
844
+ * The stack as printed text: every tier the reader can use, one line each,
845
+ * each ending in a newline. A `hidden` tier prints nothing — it is in `--json`
846
+ * for anyone who asks, and absent from the screen a reader clicks from.
847
+ */
848
+ function reviewStackText(tiers) {
849
+ return tiers
850
+ .filter((t) => !t.hidden)
851
+ .map((t) => reviewTierLine(t) + '\n')
852
+ .join('')
853
+ }
854
+
855
+ /**
856
+ * The served tiers one wait covers, as the stack shows them. `local` and
857
+ * `network` are two doors into one room; with `local` hidden there is one door,
858
+ * and the line must not name one the reader was never shown.
859
+ */
860
+ function waitCovers(tiers) {
861
+ const local = tiers.find((t) => t.tier === 'local')
862
+ return local && local.hidden ? ['network'] : ['local', 'network']
863
+ }
864
+
778
865
  // One tier as a line, padded so the labels form a column the eye can run down.
779
866
  // A tier with alternates renders them as indented `also:` lines of its own —
780
867
  // they are PART of the tier, which is what puts them under `network:` rather
@@ -2632,6 +2719,8 @@ module.exports = {
2632
2719
  surfacesFor,
2633
2720
  reviewTierStack,
2634
2721
  reviewTierLine,
2722
+ reviewStackText,
2723
+ waitCovers,
2635
2724
  isTailnetAddress,
2636
2725
  tailnetLabel,
2637
2726
  COMMITTING,
@@ -2724,6 +2813,7 @@ module.exports = {
2724
2813
  renderReviewFragment,
2725
2814
  detectReader,
2726
2815
  resolveReader,
2816
+ readerOffMachine,
2727
2817
  CHECK_LEVELS,
2728
2818
  loadTemplate,
2729
2819
  TEMPLATE_PATH,
@@ -32,7 +32,7 @@ const fs = require('node:fs')
32
32
  const path = require('node:path')
33
33
  const crypto = require('node:crypto')
34
34
  const { spawn } = require('node:child_process')
35
- const { signalGroup } = require('./supervise.js')
35
+ const { signalGroup, resolveShell } = require('./supervise.js')
36
36
 
37
37
  const BUNDLED_ADAPTERS = { coderabbit: require('./reviewers/coderabbit.js') }
38
38
 
@@ -288,9 +288,10 @@ function runReviewer(entry, ctx) {
288
288
  // Through a shell, deliberately: the config holds a command LINE, with
289
289
  // pipes and quoting the project chose. It is read from a committed config
290
290
  // in the project's own repo — the same trust level as a package script.
291
- // `sh` from PATH on Windows — Git for Windows' — where `/bin/sh` does not
292
- // exist and no reviewer could run at all (chore-windows-ci).
293
- child = spawnFn(process.platform === 'win32' ? 'sh' : '/bin/sh', ['-c', rendered], {
291
+ // Git for Windows' `sh` on Windows, where `/bin/sh` does not exist and no
292
+ // reviewer could run at all (chore-windows-ci) — found off PATH too, and
293
+ // left as a bare `sh` to fail as `did not run` when there is none.
294
+ child = spawnFn(process.platform === 'win32' ? resolveShell() || 'sh' : '/bin/sh', ['-c', rendered], {
294
295
  cwd: worktree,
295
296
  stdio: ['ignore', 'pipe', 'pipe'],
296
297
  // THE CHILD LEADS ITS OWN PROCESS GROUP, and the timeout below depends
package/src/env/serve.js CHANGED
@@ -35,6 +35,7 @@ const {
35
35
  allSpecs,
36
36
  resolveSpec,
37
37
  resolveBaseBranch,
38
+ gapNote,
38
39
  isEpic,
39
40
  } = require('./resolve.js')
40
41
  const { epicTree, worktreeOverview, epicsInFlight, memberReaders, epicAnswer } = require('./epicread.js')
@@ -641,6 +642,7 @@ function renderSpecPage(dir, config, spec, { branch = false } = {}) {
641
642
  mode,
642
643
  ref,
643
644
  base: baseName,
645
+ baseGap: baseName ? gapNote(config, trimmed) : null,
644
646
  now,
645
647
  notes,
646
648
  gate,
@@ -664,6 +666,7 @@ function renderSpecPage(dir, config, spec, { branch = false } = {}) {
664
666
  mode: 'branch',
665
667
  ref: mergeBase,
666
668
  base: fallbackBase,
669
+ baseGap: gapNote(config, trimmed),
667
670
  now,
668
671
  notes,
669
672
  gate,
@@ -67,11 +67,48 @@ function readPid(pidFileAbs) {
67
67
  }
68
68
  }
69
69
 
70
+ /**
71
+ * The shell a planned `command` runs through, or null when there is none.
72
+ *
73
+ * POSIX: `sh` from PATH, as it always was. Windows: `sh` only exists where Git
74
+ * for Windows put its `bin` on PATH, and a `cmd /c` session (a VM driven from
75
+ * another host, a scheduled task) commonly has Git installed and not on PATH.
76
+ * So PATH first, then Git's own install locations, then the `bin` beside a
77
+ * `git.exe` that IS on PATH (`Git\cmd\git.exe` → `Git\bin\sh.exe`).
78
+ *
79
+ * WHAT WOULD FOOL THIS: Git installed somewhere none of those name — a scoop
80
+ * shim, a portable copy. Then the answer is null, and the caller refuses with
81
+ * a reason rather than spawning something that is not there.
82
+ */
83
+ function resolveShell({ platform = process.platform, env = process.env, exists = fs.existsSync } = {}) {
84
+ if (platform !== 'win32') return 'sh'
85
+ const w = path.win32
86
+ const dirs = String(env.PATH || env.Path || '').split(';').filter(Boolean)
87
+ const candidates = dirs.map((d) => w.join(d, 'sh.exe'))
88
+ for (const base of [env.ProgramFiles, env.ProgramW6432, env['ProgramFiles(x86)']]) {
89
+ if (base) candidates.push(w.join(base, 'Git', 'bin', 'sh.exe'))
90
+ }
91
+ if (env.LOCALAPPDATA) candidates.push(w.join(env.LOCALAPPDATA, 'Programs', 'Git', 'bin', 'sh.exe'))
92
+ for (const d of dirs) {
93
+ if (exists(w.join(d, 'git.exe'))) candidates.push(w.join(d, '..', 'bin', 'sh.exe'))
94
+ }
95
+ return candidates.find((c) => exists(c)) || null
96
+ }
97
+
70
98
  /**
71
99
  * Start one planned process detached, appending stdout+stderr to its log and
72
100
  * writing its pid file. Idempotent: if the pid file already names a live
73
101
  * process, nothing is spawned — returns `{ started: false, pid }`.
74
102
  *
103
+ * A proc carrying `argv` is spawned as exactly that, with no shell — the review
104
+ * server and the proxy are `node <script> <file>` and never needed one. A proc
105
+ * carrying only `command` runs through `resolveShell`.
106
+ *
107
+ * NEVER THROWS OVER A SPAWN THAT FAILED. A missing executable is reported as
108
+ * `{ started: false, pid: null, error }` with no pid file written: the ENOENT
109
+ * otherwise arrives as an unhandled 'error' event and takes the CLI down with
110
+ * it (bug-review-serve-spawn-sh).
111
+ *
75
112
  * `spawnImpl` is injectable for tests; defaults to child_process.spawn.
76
113
  */
77
114
  function startProcess(proc, { cwd, rootDir, spawnImpl = spawn }) {
@@ -83,19 +120,44 @@ function startProcess(proc, { cwd, rootDir, spawnImpl = spawn }) {
83
120
  return { started: false, pid: existing, logFile: logAbs, pidFile: pidAbs }
84
121
  }
85
122
 
123
+ const env = { ...process.env, ...proc.env }
124
+ let file
125
+ let args
126
+ if (proc.argv) {
127
+ ;[file, ...args] = proc.argv
128
+ } else {
129
+ file = resolveShell({ env })
130
+ args = ['-c', proc.command]
131
+ if (!file) {
132
+ const error = 'no sh found — install Git for Windows or put its bin folder on PATH'
133
+ return { started: false, pid: null, error, logFile: logAbs, pidFile: pidAbs }
134
+ }
135
+ }
136
+
86
137
  fs.mkdirSync(path.dirname(logAbs), { recursive: true })
87
138
  fs.mkdirSync(path.dirname(pidAbs), { recursive: true })
88
139
 
89
140
  const out = fs.openSync(logAbs, 'a')
90
141
  try {
91
- const child = spawnImpl('sh', ['-c', proc.command], {
92
- cwd,
93
- env: { ...process.env, ...proc.env },
94
- detached: true,
95
- // No console window per dev server on Windows; nothing anywhere else.
96
- windowsHide: true,
97
- stdio: ['ignore', out, out],
98
- })
142
+ let child
143
+ try {
144
+ child = spawnImpl(file, args, {
145
+ cwd,
146
+ env,
147
+ detached: true,
148
+ // No console window per dev server on Windows; nothing anywhere else.
149
+ windowsHide: true,
150
+ stdio: ['ignore', out, out],
151
+ })
152
+ } catch (err) {
153
+ return { started: false, pid: null, error: `spawn ${file}: ${err.message}`, logFile: logAbs, pidFile: pidAbs }
154
+ }
155
+ // A spawn that could not start has no pid, and its error is emitted on the
156
+ // next tick — the listener is what keeps that from being fatal.
157
+ child.on('error', () => {})
158
+ if (!child.pid) {
159
+ return { started: false, pid: null, error: `could not start ${file}`, logFile: logAbs, pidFile: pidAbs }
160
+ }
99
161
  child.unref()
100
162
  fs.writeFileSync(pidAbs, `${child.pid}\n`)
101
163
  return { started: true, pid: child.pid, logFile: logAbs, pidFile: pidAbs }
@@ -167,4 +229,4 @@ async function waitHealthy(
167
229
  // therefore kills the wrapper, leaves the server holding its port, and then
168
230
  // blames whatever it asserts next. Killing the group is what `stopProcess` does
169
231
  // and what a test must do to mean "it died".
170
- module.exports = { startProcess, stopProcess, waitHealthy, isAlive, readPid, signalGroup }
232
+ module.exports = { startProcess, stopProcess, waitHealthy, isAlive, readPid, signalGroup, resolveShell }
package/src/ideacmd.js CHANGED
@@ -154,7 +154,17 @@ function refuse(out, flags, reason, extra = {}) {
154
154
 
155
155
  async function fileStore(sub, positional, flags, { cwd, now, out }) {
156
156
  const ctx = fileContext(cwd)
157
- if (!ctx.base) return refuse(out, flags, ctx.refused ? ctx.refused.message : 'cannot resolve the base branch')
157
+ if (!ctx.base) {
158
+ // A rolling base in its gap carries the engine's offer
159
+ // (`.claude/rules/offered-unblocks.md`): the refusal, then the way out.
160
+ const offer = ctx.refused && ctx.refused.offer
161
+ if (!offer) return refuse(out, flags, ctx.refused ? ctx.refused.message : 'cannot resolve the base branch')
162
+ write(out, flags, { ok: false, refused: ctx.refused.message, offer }, [
163
+ `idea: ${ctx.refused.message}`,
164
+ ` offer: ${offer.label} — ${offer.command}`,
165
+ ])
166
+ return 1
167
+ }
158
168
  const { tip, text } = readOnBase(ctx)
159
169
 
160
170
  if (sub === 'list') {