@skitterbyte/skitterspec-github 2.12.0 → 2.15.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/cli.js CHANGED
@@ -51,6 +51,7 @@ const SPEC_ENV_VERBS = Object.freeze([
51
51
  'project',
52
52
  ])
53
53
  const { forkMatch, planBaseReport } = require('./env/base.js')
54
+ const { readBasePin, writeBasePin, clearBasePin } = require('./env/basepin.js')
54
55
  const {
55
56
  readRegistry,
56
57
  writeRegistry,
@@ -66,6 +67,8 @@ const {
66
67
  resolveSpecless,
67
68
  resolveBaseBranch,
68
69
  describeBaseBranch,
70
+ BaseUnresolvedError,
71
+ gapNote,
69
72
  baseRemote,
70
73
  liveWorktreePaths,
71
74
  collectSpecFolders,
@@ -114,6 +117,8 @@ const {
114
117
  collectReview,
115
118
  reviewTierStack,
116
119
  reviewTierLine,
120
+ reviewStackText,
121
+ waitCovers,
117
122
  isTailnetAddress,
118
123
  tailnetLabel,
119
124
  renderReviewPage,
@@ -336,6 +341,8 @@ Usage:
336
341
  base fetch, list baseBranchPattern matches
337
342
  newest-first, mark the base, and name
338
343
  specs forked from an older match
344
+ (--use-fallback pins the fallback
345
+ while nothing matches; --unpin)
339
346
  skitterspec status What is in flight here: every spec with a worktree,
340
347
  its bucket and phase progress read from that
341
348
  worktree (--json). Offline; always exits 0.
@@ -588,6 +595,10 @@ function provisionedSpecs(dir, config) {
588
595
 
589
596
  function specEnvStatus(dir, config) {
590
597
  const provisioned = provisionedSpecs(dir, config)
598
+ // A base held on the fallback is worth one line wherever work is listed: it
599
+ // is the state every fork and land is in until the next release branch.
600
+ const gap = gapNote(config, gitReader(dir))
601
+ if (gap) process.stdout.write(`spec-env: base ${config.gapPin.base} — ${gap}\n`)
591
602
 
592
603
  // REACHED EITHER WAY. This used to return here, so a repo with nothing in
593
604
  // flight could say nothing about a waiting pass — and a repo with nothing in
@@ -1027,8 +1038,9 @@ async function serveTadaPage({ window, flags, recap }) {
1027
1038
  const q = tadaQuery({ ...flags, on: flags.on || (flags.since ? null : localDay(window.since)) })
1028
1039
  const withQ = (u) => (u ? `${u}${q}` : u)
1029
1040
  const page = { ...served, loopbackUrl: withQ(served.loopbackUrl), url: withQ(served.url), alternates: (served.alternates || []).map(withQ) }
1030
- const tiers = reviewTierStack({ served: page, fileUrl: null, publishedUrl: null, config })
1031
- process.stdout.write(`page: ${humanLabel(window)}\n${tiers.map(reviewTierLine).join('\n')}\n`)
1041
+ const reader = resolveReader(config, process.env, process.platform)
1042
+ const tiers = reviewTierStack({ served: page, fileUrl: null, publishedUrl: null, config, reader })
1043
+ process.stdout.write(`page: ${humanLabel(window)}\n${reviewStackText(tiers)}`)
1032
1044
  return true
1033
1045
  }
1034
1046
 
@@ -1132,13 +1144,14 @@ function epicPageTiers(inputs, up, epic) {
1132
1144
  if (!inputs.config) return null
1133
1145
  if (!up) return { off: true, start: 'skitterspec spec-env review serve --host 0.0.0.0' }
1134
1146
  const served = reviewServedUrls(up, offerableLanAddresses(), epic)
1135
- return { tiers: reviewTierStack({ served, fileUrl: null, publishedUrl: null, config: inputs.config }) }
1147
+ const reader = resolveReader(inputs.config, process.env, process.platform)
1148
+ return { tiers: reviewTierStack({ served, fileUrl: null, publishedUrl: null, config: inputs.config, reader }) }
1136
1149
  }
1137
1150
 
1138
1151
  function epicPageLines(page) {
1139
1152
  if (!page) return ''
1140
1153
  if (page.off) return `epic page: no review server running — start it with: ${page.start}\n`
1141
- return `epic page:\n${page.tiers.map(reviewTierLine).join('\n')}\n`
1154
+ return `epic page:\n${reviewStackText(page.tiers)}`
1142
1155
  }
1143
1156
 
1144
1157
  // The working tree `--here` reads: the project folder of the checkout this
@@ -3131,7 +3144,7 @@ function specEnvIntegrate(dir, config, specArg, flags = {}) {
3131
3144
  }
3132
3145
  const cout = [`spec-env integrate: ${spec.folder}`, '', ' mode: checkout',
3133
3146
  ` base: ${base}`, ` branch: ${cplan.branch}`,
3134
- ...retargetLines(retarget),
3147
+ ...retargetLines(retarget), ...gapLines(config, gitReader(dir)),
3135
3148
  ...reverifyLines(dir, spec, base, dir), '',
3136
3149
  ' run these (abort the rebase on conflict):']
3137
3150
  for (const cmd of cplan.commands) cout.push(` ${cmd}`)
@@ -3246,7 +3259,7 @@ function specEnvIntegrate(dir, config, specArg, flags = {}) {
3246
3259
  out.push(` base: ${plan.base}`)
3247
3260
  out.push(` branch: ${plan.branch}`)
3248
3261
  out.push(` worktree: ${spec.worktreePath}`)
3249
- out.push(...retargetLines(retarget))
3262
+ out.push(...retargetLines(retarget), ...gapLines(config, gitReader(dir)))
3250
3263
  if (primarySwitch) out.push(` primary: on ${primarySwitch.from} — switched to ${base} before the land`)
3251
3264
  out.push(...reverifyLines(dir, spec, baseRef, spec.projectPath || spec.worktreePath))
3252
3265
  out.push('')
@@ -3300,6 +3313,13 @@ function retargetLines(retarget) {
3300
3313
  return retarget ? [` retarget: forked from ${retarget.from} · landing onto ${retarget.to}`] : []
3301
3314
  }
3302
3315
 
3316
+ // Said under `base:` when a gap pin chose it, so a land onto the fallback is
3317
+ // never mistaken for a land onto a release branch. Nothing otherwise.
3318
+ function gapLines(config, git) {
3319
+ const note = gapNote(config, git)
3320
+ return note ? [` gap: ${note}`] : []
3321
+ }
3322
+
3303
3323
  // Is the primary checkout sitting on an older rolling-base match? Positive
3304
3324
  // signal only: the branch it has out must itself match `baseBranchPattern`
3305
3325
  // (locally or on the remote). Anything else — a live spec, a detached HEAD, no
@@ -3434,7 +3454,7 @@ function specEnvIntegratePr(dir, config, spec, base, flags, retarget = null) {
3434
3454
  out.push(` base: ${remote}/${base}`)
3435
3455
  out.push(` branch: ${plan.branch}`)
3436
3456
  out.push(checkout ? ` checkout: ${treePath}` : ` worktree: ${treePath}`)
3437
- out.push(...retargetLines(retarget))
3457
+ out.push(...retargetLines(retarget), ...gapLines(config, gitReader(dir)))
3438
3458
  // Silent on cannot-tell: a line about a lookup that failed accuses nothing
3439
3459
  // and helps nobody — the placeholder in the commands already degrades.
3440
3460
  if (pr.state === 'none') out.push(' pr: none yet')
@@ -4466,18 +4486,26 @@ function specEnvResolve(dir, config, specArg, flags = {}) {
4466
4486
  }
4467
4487
 
4468
4488
  /**
4469
- * `skitterspec spec-env base [--json]`
4489
+ * `skitterspec spec-env base [--json] [--use-fallback | --unpin]`
4470
4490
  *
4471
4491
  * Which branch is the base, how it was found, and — under `baseBranchPattern` —
4472
4492
  * every match newest-first plus the provisioned specs that forked from an older
4473
4493
  * one. It fetches first, because the resolver itself never does: a release
4474
4494
  * candidate cut since the last fetch is invisible to it.
4475
4495
  *
4476
- * Lists only and always exits 0. A failed fetch is reported and the listing
4477
- * carries on from the refs already here; nothing is edited, and pinning stays a
4478
- * hand edit of `baseBranch`.
4496
+ * Bare, it lists only and always exits 0; the one thing it writes is deleting a
4497
+ * gap pin a match has retired. A failed fetch is reported and the listing
4498
+ * carries on from the refs already here.
4499
+ *
4500
+ * `--use-fallback` is the offer's command: it writes the gap pin
4501
+ * (`env/basepin.js`) when the pattern matches nothing and a fallback resolves.
4502
+ * `--unpin` removes it. Both exit 1 on a refusal, since a caller retries on 0.
4503
+ * A permanent pin stays a hand edit of `baseBranch`.
4479
4504
  */
4480
4505
  function specEnvBase(dir, config, flags = {}) {
4506
+ if (flags.useFallback) return baseUseFallback(dir, config, flags)
4507
+ if (flags.unpin) return baseUnpin(dir, config, flags)
4508
+
4481
4509
  const pattern = (config.baseBranchPattern || '').trim()
4482
4510
  const remote = baseRemote(config)
4483
4511
  const git = gitReader(dir)
@@ -4485,7 +4513,9 @@ function specEnvBase(dir, config, flags = {}) {
4485
4513
  // No pattern: the base is today's chain, and there is nothing to fetch for —
4486
4514
  // origin/HEAD is not updated by a fetch.
4487
4515
  const fetch = fetchForPattern(dir, config)
4488
- const { base, how } = describeBaseBranch(config, git)
4516
+ const pin = pattern ? readBasePin(dir, config) : null
4517
+ const { base, how, stalePin, refused } = describeBaseBranch(config, git, pin)
4518
+ const pinCleared = Boolean(flags.pinRetired) || (Boolean(stalePin) && clearBasePin(dir, config))
4489
4519
 
4490
4520
  let matches = []
4491
4521
  let forks = []
@@ -4498,10 +4528,74 @@ function specEnvBase(dir, config, flags = {}) {
4498
4528
  }))
4499
4529
  }
4500
4530
 
4501
- const { json, lines } = planBaseReport({ pattern, remote, base, how, fetch, matches, forks })
4531
+ const { json, lines } = planBaseReport({
4532
+ pattern,
4533
+ remote,
4534
+ base,
4535
+ how,
4536
+ fetch,
4537
+ matches,
4538
+ forks,
4539
+ pin,
4540
+ pinCleared,
4541
+ offer: refused ? refused.offer : null,
4542
+ })
4502
4543
  process.stdout.write(flags.json ? JSON.stringify(json, null, 2) + '\n' : lines.join('\n') + '\n')
4503
4544
  }
4504
4545
 
4546
+ // One answer for both pin verbs: a line of text, or `{ ok, ... }` as JSON.
4547
+ function basePinAnswer(flags, ok, line, extra = {}) {
4548
+ if (!ok) process.exitCode = 1
4549
+ process.stdout.write(flags.json ? JSON.stringify({ ok, ...extra, message: line }, null, 2) + '\n' : line + '\n')
4550
+ }
4551
+
4552
+ // WHAT WOULD FOOL THIS: an unfetched remote looks exactly like the gap — no
4553
+ // branch matches in either case. So it fetches first and will not pin on a
4554
+ // failed fetch: a pin made then could hold the base on the fallback while the
4555
+ // next release branch already exists on the remote.
4556
+ function baseUseFallback(dir, config, flags) {
4557
+ const pattern = (config.baseBranchPattern || '').trim()
4558
+ if (!pattern) {
4559
+ return basePinAnswer(flags, false, 'spec-env base: no baseBranchPattern is set — there is no gap to pin.')
4560
+ }
4561
+ const fetch = fetchForPattern(dir, config)
4562
+ if (fetch && !fetch.ok) {
4563
+ return basePinAnswer(
4564
+ flags,
4565
+ false,
4566
+ `spec-env base: fetch from ${baseRemote(config)} failed${fetch.reason ? ` (${fetch.reason})` : ''} — ` +
4567
+ `cannot tell whether a ${pattern} branch exists, so nothing was pinned.`,
4568
+ )
4569
+ }
4570
+ // null, not the attached pin: the question is whether the PATTERN matches.
4571
+ const { base, refused } = describeBaseBranch(config, gitReader(dir), null)
4572
+ if (base) {
4573
+ clearBasePin(dir, config)
4574
+ return basePinAnswer(flags, false, `spec-env base: ${base} matches ${pattern} — no gap to pin; it is the base.`, { base })
4575
+ }
4576
+ if (!refused || !refused.fallback) {
4577
+ return basePinAnswer(
4578
+ flags,
4579
+ false,
4580
+ `spec-env base: no branch matches ${pattern}, and no fallback resolves — set baseBranchFallback, ` +
4581
+ `or run git remote set-head ${baseRemote(config)} --auto.`,
4582
+ )
4583
+ }
4584
+ const pin = writeBasePin(dir, config, { base: refused.fallback, pattern })
4585
+ basePinAnswer(
4586
+ flags,
4587
+ true,
4588
+ `spec-env base: pinned ${pin.base} for the gap — no ${pattern} branch on ${baseRemote(config)}. ` +
4589
+ `It clears itself when one appears.`,
4590
+ { base: pin.base, pin },
4591
+ )
4592
+ }
4593
+
4594
+ function baseUnpin(dir, config, flags) {
4595
+ const removed = clearBasePin(dir, config)
4596
+ basePinAnswer(flags, true, removed ? 'spec-env base: gap pin removed.' : 'spec-env base: no gap pin to remove.', { removed })
4597
+ }
4598
+
4505
4599
  // Fetch the base's remote, but only where `baseBranchPattern` decides the base:
4506
4600
  // the resolver reads remote-tracking refs and never the network, so a release
4507
4601
  // candidate cut since the last fetch is invisible until something fetches. With
@@ -4874,7 +4968,8 @@ function reshowStack(dir, config, spec, out) {
4874
4968
  const cfg = withSpecRemote(config, out)
4875
4969
  const up = readRunningReviewServer(dir, cfg)
4876
4970
  const served = up ? reviewServedUrls(up, offerableLanAddresses(), spec.folder) : null
4877
- const tiers = reviewTierStack({ served, fileUrl: reviewFileUrl(out), publishedUrl: readReviewUrl(out), config: cfg })
4971
+ const reader = resolveReader(cfg, process.env, process.platform)
4972
+ const tiers = reviewTierStack({ served, fileUrl: reviewFileUrl(out), publishedUrl: readReviewUrl(out), config: cfg, reader })
4878
4973
  let live = null
4879
4974
  try {
4880
4975
  const primaryState = assertPrimaryOnMain(cfg, gitReader(dir))
@@ -4941,7 +5036,7 @@ async function specEnvReviewWait(dir, config, specArg, flags) {
4941
5036
  `${rearm ? ` (re-arm ${rearm})` : ''}\n` +
4942
5037
  (stack
4943
5038
  ? ` re-show: banner (re-arm ${rearm})\n` +
4944
- stack.tiers.map((t) => reviewTierLine(t) + '\n').join('') +
5039
+ reviewStackText(stack.tiers) +
4945
5040
  (liveStateLine(stack.live) ? `${liveStateLine(stack.live)}\n` : '')
4946
5041
  : ''),
4947
5042
  )
@@ -6048,12 +6143,16 @@ async function specEnvReview(dir, config, specArg, flags, invokedFrom = dir) {
6048
6143
  // spec with no branch to put live (decision 6), so it carries neither key and
6049
6144
  // renders exactly as it did before this existed.
6050
6145
  const surfaceArgs = docs ? {} : { live, tiers: pageTiers(config) }
6146
+ // The words beside the base when a gap pin chose it; asked only where a base
6147
+ // is shown, which is the branch range.
6148
+ const baseGap = () => gapNote(config, trimmed)
6051
6149
  let data = collectReview({
6052
6150
  spec,
6053
6151
  git,
6054
6152
  mode,
6055
6153
  ref,
6056
6154
  base,
6155
+ baseGap: base ? baseGap() : null,
6057
6156
  now,
6058
6157
  notes,
6059
6158
  gate,
@@ -6097,6 +6196,7 @@ async function specEnvReview(dir, config, specArg, flags, invokedFrom = dir) {
6097
6196
  mode: 'branch',
6098
6197
  ref: mergeBase,
6099
6198
  base: fallbackBase,
6199
+ baseGap: baseGap(),
6100
6200
  now,
6101
6201
  notes,
6102
6202
  gate,
@@ -6212,7 +6312,7 @@ async function specEnvReview(dir, config, specArg, flags, invokedFrom = dir) {
6212
6312
  const url = readReviewUrl(out)
6213
6313
 
6214
6314
  // Resolved before the --json early return, so both outputs agree.
6215
- const reader = resolveReader(config, process.env)
6315
+ const reader = resolveReader(config, process.env, process.platform)
6216
6316
 
6217
6317
  // A remote reader cannot open a path on this machine — that is the whole of
6218
6318
  // what detection established. Serving is how the engine answers it: a local
@@ -6279,6 +6379,10 @@ async function specEnvReview(dir, config, specArg, flags, invokedFrom = dir) {
6279
6379
  }
6280
6380
  }
6281
6381
 
6382
+ // ONE STACK for both outputs, so `--json` and the text cannot disagree about
6383
+ // which tiers exist — or which one is hidden.
6384
+ const stackTiers = reviewTierStack({ served, fileUrl: reviewFileUrl(out), publishedUrl: url, config, reader })
6385
+
6282
6386
  if (flags.json) {
6283
6387
  process.stdout.write(
6284
6388
  JSON.stringify(
@@ -6291,6 +6395,7 @@ async function specEnvReview(dir, config, specArg, flags, invokedFrom = dir) {
6291
6395
  mode,
6292
6396
  base,
6293
6397
  fellBack,
6398
+ baseGap: data.baseGap,
6294
6399
  // The paths a committing verdict on this page must commit, so the
6295
6400
  // skill that routes on it never recomputes the set the reader saw.
6296
6401
  // Absent for every other mode, which keeps their output identical.
@@ -6305,12 +6410,10 @@ async function specEnvReview(dir, config, specArg, flags, invokedFrom = dir) {
6305
6410
  // The same stack the text prints, so a skill reads the tiers rather
6306
6411
  // than parsing prose — and the two can never disagree, because both
6307
6412
  // come from `reviewTierStack`.
6308
- tiers: reviewTierStack({
6309
- served,
6310
- fileUrl: reviewFileUrl(out),
6311
- publishedUrl: url,
6312
- config,
6313
- }),
6413
+ tiers: stackTiers,
6414
+ // Which served tiers one wait covers — the holding line's tiers, so a
6415
+ // banner never names a door the stack did not show.
6416
+ covers: waitCovers(stackTiers),
6314
6417
  // The same answer `live status --json` gives, from the same function,
6315
6418
  // so the page and the command cannot disagree. Always present, unlike
6316
6419
  // the tiers' optional keys: `unavailable` is a state a consumer needs
@@ -6369,6 +6472,7 @@ async function specEnvReview(dir, config, specArg, flags, invokedFrom = dir) {
6369
6472
  `spec-env review: ${spec.folder} (${
6370
6473
  fellBack ? `working tree clean — since ${base}` : mode === 'branch' ? `since ${base}` : 'uncommitted'
6371
6474
  })\n` +
6475
+ (data.baseGap ? ` base: ${base} — ${data.baseGap}\n` : '') +
6372
6476
  ` ${t.files} file${t.files === 1 ? '' : 's'}, +${t.additions} -${t.deletions}\n` +
6373
6477
  (merged
6374
6478
  ? ` merged: ${merged.accepted} accept${merged.accepted === 1 ? '' : 's'}, ` +
@@ -6432,19 +6536,12 @@ async function specEnvReview(dir, config, specArg, flags, invokedFrom = dir) {
6432
6536
  // rendering — `reviewTierLine` carries them, which is what puts them
6433
6537
  // under `network:` rather than dangling after the stack (they used to
6434
6538
  // print below `remote:`, against the comment that placed them).
6435
- reviewTierStack({
6436
- served,
6437
- fileUrl: reviewFileUrl(out),
6438
- publishedUrl: url,
6439
- config,
6440
- })
6441
- .map((t) => reviewTierLine(t) + '\n')
6442
- .join('') +
6539
+ reviewStackText(stackTiers) +
6443
6540
  // WHICH TIERS THE WAIT COVERS, once, next to the stack. `local` and
6444
6541
  // `network` are two doors into one room — the page POSTs to
6445
6542
  // `location.pathname`, so both reach this server and this pending store.
6446
6543
  // `remote` writes to the artifact's own store, which nothing here can see.
6447
- ' the wait covers local + network; a remote verdict needs /spec-reviewed.\n' +
6544
+ ` the wait covers ${waitCovers(stackTiers).join(' + ')}; a remote verdict needs /spec-reviewed.\n` +
6448
6545
  // WHETHER IT IS ALSO RUNNING SOMEWHERE, which is the other way to judge a
6449
6546
  // change. `unavailable` prints nothing — see `liveStateLine`.
6450
6547
  (liveStateLine(live) ? `${liveStateLine(live)}\n` : '') +
@@ -6506,6 +6603,10 @@ async function specEnvDev(dir, config, positional) {
6506
6603
  const out = [`spec-env dev up: ${spec.folder} slot ${slot} (ports from ${plan.portOffset})`]
6507
6604
  for (const proc of plan.procs) {
6508
6605
  const res = startProcess(proc, { cwd: spec.projectPath, rootDir: dir })
6606
+ if (res.error) {
6607
+ out.push(` ${proc.name}: port ${proc.port} NOT STARTED — ${res.error}`)
6608
+ continue
6609
+ }
6509
6610
  let health = ''
6510
6611
  if (proc.health) {
6511
6612
  health = (await waitHealthy(proc.health)) ? ' health: ok' : ' health: TIMEOUT'
@@ -6593,8 +6694,9 @@ function proxyProcFor(config, routesFileAbs) {
6593
6694
  const sdir = stateDirLabel(config)
6594
6695
  return {
6595
6696
  name: 'proxy',
6596
- // Quoted: this runs through `sh -c`, which eats a Windows path's
6597
- // backslashes and splits any path with a space (chore-windows-ci).
6697
+ // `argv` is what runs — node itself, no shell (bug-review-serve-spawn-sh).
6698
+ // `command` is the same thing for a person to read.
6699
+ argv: [process.execPath, path.join(__dirname, 'env', 'proxy.js'), routesFileAbs],
6598
6700
  command: `node ${shellPath(path.join(__dirname, 'env', 'proxy.js'))} ${shellPath(routesFileAbs)}`,
6599
6701
  env: {},
6600
6702
  logFile: `${sdir}/logs/proxy.log`,
@@ -6606,8 +6708,15 @@ function proxyProcFor(config, routesFileAbs) {
6606
6708
  // monorepo developing itself, and a project that installed the package. Naming
6607
6709
  // the distribution here is a path, not provider machinery — `init.js` and
6608
6710
  // `PROVIDER_COMMANDS` above already know package names by name.
6711
+ //
6712
+ // EVERY DISTRIBUTION, not only the base. A project installs exactly one, and a
6713
+ // superset missing here fell through to `__dirname` — the RUNNING copy — so a
6714
+ // worktree's engine saw the primary's server as executing a different script,
6715
+ // called it stale and stopped it (bug-review-serve-spawn-sh).
6609
6716
  const DAEMON_LOCATIONS = [
6610
- path.join('node_modules', '@skitterbyte', 'skitterspec', 'src', 'env', 'serve.js'),
6717
+ ...['skitterspec', 'skitterspec-linear', 'skitterspec-jira', 'skitterspec-github', 'skitterspec-azure-boards'].map(
6718
+ (pkg) => path.join('node_modules', '@skitterbyte', pkg, 'src', 'env', 'serve.js'),
6719
+ ),
6611
6720
  path.join('packages', 'common', 'src', 'env', 'serve.js'),
6612
6721
  ]
6613
6722
 
@@ -6663,8 +6772,10 @@ function serveProcFor(config, settingsFileAbs, { root = null } = {}) {
6663
6772
  const sdir = stateDirLabel(config)
6664
6773
  return {
6665
6774
  name: 'review-serve',
6666
- // Quoted: this runs through `sh -c`, which eats a Windows path's
6667
- // backslashes and splits any path with a space (chore-windows-ci).
6775
+ // `argv` is what runs — node itself, no shell. It used to go through
6776
+ // `sh -c`, and a Windows session without Git's bin on PATH has no `sh`
6777
+ // (bug-review-serve-spawn-sh). `command` is the same thing for a person.
6778
+ argv: [process.execPath, daemonScript(root), settingsFileAbs],
6668
6779
  command: `node ${shellPath(daemonScript(root))} ${shellPath(settingsFileAbs)}`,
6669
6780
  script: daemonScript(root),
6670
6781
  env: {},
@@ -6917,6 +7028,9 @@ async function ensureReviewServer(dir, config, { host = '127.0.0.1', port, resta
6917
7028
  ) + '\n',
6918
7029
  )
6919
7030
  const res = startProcess(proc, { cwd: dir, rootDir: dir })
7031
+ // Nothing was spawned, so there is nothing to wait for — and the reason is
7032
+ // the only thing worth handing back.
7033
+ if (res.error) return { error: `could not start the server (${res.error})`, port: usePort, replaced, engineWas }
6920
7034
  const up = await waitListening([usePort], { host: loopback ? host : '127.0.0.1' })
6921
7035
  // A PORT ANSWERING IS NOT PROOF THAT OUR PROCESS IS ANSWERING IT. `waitListening`
6922
7036
  // connects, and anything already bound satisfies a connect — so on its own it
@@ -7061,6 +7175,11 @@ async function specEnvReviewServe(dir, config, flags) {
7061
7175
  return
7062
7176
  }
7063
7177
 
7178
+ if (started.error) {
7179
+ process.stdout.write(`spec-env review serve: ${started.error} — see ${proc.logFile}\n`)
7180
+ return
7181
+ }
7182
+
7064
7183
  const { port, token, loopback } = started
7065
7184
  const res = { pid: started.pid }
7066
7185
 
@@ -7894,6 +8013,8 @@ async function specEnv(rest) {
7894
8013
  else if (args[i] === '--cwd') flags.cwd = args[++i]
7895
8014
  else if (args[i] === '--command') flags.command = args[++i] ?? ''
7896
8015
  else if (args[i] === '--assert-primary-clean') flags.assertPrimaryClean = true
8016
+ else if (args[i] === '--use-fallback') flags.useFallback = true
8017
+ else if (args[i] === '--unpin') flags.unpin = true
7897
8018
  else positional.push(args[i])
7898
8019
  }
7899
8020
  dir = path.resolve(dir)
@@ -7965,6 +8086,40 @@ async function specEnv(rest) {
7965
8086
  }
7966
8087
  }
7967
8088
 
8089
+ // A gap pin a match has retired is deleted here, the one point every
8090
+ // subcommand passes, so it cannot outlive the gap even when nobody runs
8091
+ // `spec-env base`. Only asked when a pin exists, so the common path pays
8092
+ // nothing. The resolver already ignores it; this just tidies the file.
8093
+ if (config.gapPin && describeBaseBranch(config, gitReader(dir)).stalePin) {
8094
+ clearBasePin(dir, config)
8095
+ flags.pinRetired = true
8096
+ }
8097
+
8098
+ try {
8099
+ await specEnvDispatch(sub, dir, config, positional, flags, present, invokedFrom)
8100
+ } catch (error) {
8101
+ if (!(error instanceof BaseUnresolvedError)) throw error
8102
+ baseRefusal(sub, error, flags)
8103
+ }
8104
+ }
8105
+
8106
+ // A base that will not resolve, said with the way out where the engine has one
8107
+ // (`.claude/rules/offered-unblocks.md`): the refusal first, then the offer.
8108
+ // stdout and exit 1, so a skill reads it whether or not it asked for --json.
8109
+ function baseRefusal(sub, error, flags) {
8110
+ process.exitCode = 1
8111
+ if (flags.json) {
8112
+ const out = { blocked: true, reason: error.refused }
8113
+ if (error.offer) out.offer = error.offer
8114
+ process.stdout.write(JSON.stringify(out, null, 2) + '\n')
8115
+ return
8116
+ }
8117
+ const lines = [`spec-env ${sub}: ${error.refused}`]
8118
+ if (error.offer) lines.push(` offer: ${error.offer.label} — ${error.offer.command}`)
8119
+ process.stdout.write(lines.join('\n') + '\n')
8120
+ }
8121
+
8122
+ async function specEnvDispatch(sub, dir, config, positional, flags, present, invokedFrom) {
7968
8123
  switch (sub) {
7969
8124
  case 'up':
7970
8125
  specEnvUp(dir, config, positional[0], flags)
package/src/env/base.js CHANGED
@@ -5,14 +5,16 @@
5
5
  * which in-flight specs forked from an older one.
6
6
  *
7
7
  * Pure: the CLI fetches, reads refs and computes merge-bases, and hands the
8
- * facts in. Nothing here touches git, and nothing here edits config — pinning
9
- * is a hand edit of `baseBranch`, deliberately without a verb (the pin is the
10
- * exception, so it does not get one).
8
+ * facts in. Nothing here touches git, and nothing here edits config — a
9
+ * permanent pin is a hand edit of `baseBranch`, deliberately without a verb.
10
+ * The gap pin is different (`env/basepin.js`): local, temporary, and retired by
11
+ * the next match, so `--use-fallback` and `--unpin` are its verbs.
11
12
  */
12
13
 
13
14
  const HOW = Object.freeze({
14
15
  pin: 'pinned by baseBranch',
15
16
  pattern: 'newest match',
17
+ 'gap-pin': 'pinned for the gap',
16
18
  'origin-head': 'origin/HEAD',
17
19
  local: 'local branch',
18
20
  fallback: 'nothing detected — default',
@@ -44,7 +46,10 @@ function forkMatch(matches, mergeBase, isAncestor) {
44
46
  /**
45
47
  * Build the report. `facts`:
46
48
  * { pattern, remote, base, how, fetch: { ok, reason } | null,
47
- * matches: [{ name, date }] (newest first), forks: [{ spec, forkedFrom }] }
49
+ * matches: [{ name, date }] (newest first), forks: [{ spec, forkedFrom }],
50
+ * pin: { base, pattern, pinnedAt } | null — the gap pin in force,
51
+ * pinCleared: bool — a match retired a pin on this run,
52
+ * offer: { kind, label, command } | null — no match and no pin }
48
53
  * Returns `{ json, lines }`; the CLI prints one of them and always exits 0.
49
54
  */
50
55
  function planBaseReport(facts) {
@@ -67,6 +72,9 @@ function planBaseReport(facts) {
67
72
  fetch,
68
73
  matches: matches.map((m) => ({ ...m, base: m.name === base })),
69
74
  stale,
75
+ pin: how === 'gap-pin' ? facts.pin || null : null,
76
+ pinCleared: Boolean(facts.pinCleared),
77
+ offer: facts.offer || null,
70
78
  }
71
79
 
72
80
  const lines = []
@@ -75,7 +83,8 @@ function planBaseReport(facts) {
75
83
  return { json, lines }
76
84
  }
77
85
 
78
- if (base) lines.push(`spec-env base: ${base} (${HOW[how]}${how === 'pin' ? ` — ${pattern} not used` : ` for ${pattern}`})`)
86
+ if (how === 'gap-pin') lines.push(`spec-env base: ${base} — no ${pattern} branch on ${remote} (${HOW[how]})`)
87
+ else if (base) lines.push(`spec-env base: ${base} (${HOW[how]}${how === 'pin' ? ` — ${pattern} not used` : ` for ${pattern}`})`)
79
88
  else lines.push(`spec-env base: none — no branch on ${remote} matches ${pattern}`)
80
89
 
81
90
  if (fetch) {
@@ -94,6 +103,13 @@ function planBaseReport(facts) {
94
103
  }
95
104
  }
96
105
 
106
+ if (how === 'gap-pin') {
107
+ const since = facts.pin && facts.pin.pinnedAt ? ` since ${facts.pin.pinnedAt.slice(0, 10)}` : ''
108
+ lines.push(` pinned${since} · clears itself when a ${pattern} branch appears · --unpin removes it now`)
109
+ }
110
+ if (facts.pinCleared) lines.push(` gap pin cleared — ${base} matches ${pattern}`)
111
+ if (!base && facts.offer) lines.push(` offer: ${facts.offer.label} — ${facts.offer.command}`)
112
+
97
113
  if (stale.length) {
98
114
  lines.push(' forked from an older match:')
99
115
  for (const s of stale) lines.push(` ${s.spec} · forked from ${s.forkedFrom}`)
@@ -0,0 +1,62 @@
1
+ 'use strict'
2
+
3
+ /**
4
+ * The gap pin: a local record that someone accepted "use <fallback> as the base
5
+ * for now" while `baseBranchPattern` matched nothing — the gap between one
6
+ * release branch merging and the next being cut.
7
+ *
8
+ * It lives in `.spec-env/base-pin.json` in the primary checkout, gitignored, so
9
+ * accepting the offer changes nobody else's config. It records the pattern it
10
+ * was made under, and the resolver honours it only while that pattern has no
11
+ * match (`describeBaseBranch`), so cutting the next release branch is all it
12
+ * takes to retire it. Callers that see a match override it delete the file.
13
+ *
14
+ * Pure file I/O, no git: the resolver decides what a pin means.
15
+ */
16
+
17
+ const fs = require('node:fs')
18
+ const path = require('node:path')
19
+
20
+ // The state dir sits beside the registry file, e.g. `.spec-env` — the same
21
+ // convention `building.js` and `dev.js` use.
22
+ function pinPath(dir, config) {
23
+ const stateDir = path.posix.dirname((config && config.registry) || '.spec-env/registry.json') || '.spec-env'
24
+ return path.join(dir, stateDir, 'base-pin.json')
25
+ }
26
+
27
+ /**
28
+ * The pin as `{ base, pattern, pinnedAt }`, or null. An unreadable or malformed
29
+ * file is no pin: the resolver then refuses and offers again, which is the
30
+ * harmless direction — a pin read wrongly would decide a base nobody chose.
31
+ */
32
+ function readBasePin(dir, config) {
33
+ let parsed
34
+ try {
35
+ parsed = JSON.parse(fs.readFileSync(pinPath(dir, config), 'utf8'))
36
+ } catch {
37
+ return null
38
+ }
39
+ if (!parsed || typeof parsed.base !== 'string' || typeof parsed.pattern !== 'string') return null
40
+ if (!parsed.base.trim() || !parsed.pattern.trim()) return null
41
+ return { base: parsed.base, pattern: parsed.pattern, pinnedAt: typeof parsed.pinnedAt === 'string' ? parsed.pinnedAt : null }
42
+ }
43
+
44
+ function writeBasePin(dir, config, { base, pattern, pinnedAt = new Date().toISOString() }) {
45
+ const file = pinPath(dir, config)
46
+ fs.mkdirSync(path.dirname(file), { recursive: true })
47
+ const pin = { base, pattern, pinnedAt }
48
+ fs.writeFileSync(file, JSON.stringify(pin, null, 2) + '\n')
49
+ return pin
50
+ }
51
+
52
+ /** Remove the pin. True when there was one to remove. */
53
+ function clearBasePin(dir, config) {
54
+ try {
55
+ fs.unlinkSync(pinPath(dir, config))
56
+ return true
57
+ } catch {
58
+ return false
59
+ }
60
+ }
61
+
62
+ module.exports = { pinPath, readBasePin, writeBasePin, clearBasePin }