@skitterbyte/skitterspec-github 2.0.0 → 2.2.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
@@ -119,6 +119,9 @@ const {
119
119
  passesSince,
120
120
  waitForPass,
121
121
  WAIT_HEARTBEAT_MS,
122
+ WAIT_RESHOW_EVERY,
123
+ recordWaitStart,
124
+ reshowDue,
122
125
  waitingPasses,
123
126
  describePending,
124
127
  pendingAge,
@@ -903,7 +906,7 @@ function specEnvUp(dir, config, specArg, flags = {}) {
903
906
  try {
904
907
  spec = resolveSpecWithWorktree(dir, config, specArg)
905
908
  } catch (err) {
906
- const specShaped = typeof specArg === 'string' && /^(feat|bug|hotfix)-./.test(specArg)
909
+ const specShaped = typeof specArg === 'string' && /^(feat|bug|hotfix|chore|issue|incident)-./.test(specArg)
907
910
  if (err.code !== 'SPEC_NOT_FOUND' || !docs || !specShaped || config.mode === 'checkout') {
908
911
  throw err
909
912
  }
@@ -2761,6 +2764,74 @@ function resolveHeartbeatMs(flags) {
2761
2764
  return seconds * 1000
2762
2765
  }
2763
2766
 
2767
+ /**
2768
+ * Every this-many re-arms the stack is printed again. Default 5, `0` disables.
2769
+ * A value that is not a whole number takes the DEFAULT rather than disabling
2770
+ * (`.claude/rules/negative-checks.md` rule 4), the same as `--heartbeat`.
2771
+ */
2772
+ function resolveReshowEvery(flags) {
2773
+ if (flags.reshowEvery === undefined || flags.reshowEvery === null) return WAIT_RESHOW_EVERY
2774
+ const n = Number(flags.reshowEvery)
2775
+ if (!Number.isInteger(n) || n < 0) return WAIT_RESHOW_EVERY
2776
+ return n
2777
+ }
2778
+
2779
+ /**
2780
+ * The review server that is running, read and never touched — or null.
2781
+ *
2782
+ * NOT `ensureReviewServer`. That one adopts, and where a server is stale it
2783
+ * replaces it, and a re-show that restarted the server would kill the link
2784
+ * open on the reader's phone in order to remind them of it. This reads the
2785
+ * pidfile and the settings and stops there.
2786
+ *
2787
+ * WHAT WOULD FOOL THIS: a pidfile left by a crash names a pid the OS may have
2788
+ * reused for something else. `isAlive` cannot tell those apart, so the URL it
2789
+ * offers could point at nothing — the same blind spot every adopt has, and the
2790
+ * cost is a dead link in a reminder, never a lost pass.
2791
+ */
2792
+ function readRunningReviewServer(dir, config) {
2793
+ const abs = (rel) => path.resolve(dir, rel)
2794
+ const settingsFile = `${stateDirLabel(config)}/review-serve.json`
2795
+ const proc = serveProcFor(config, abs(settingsFile), { root: dir })
2796
+ const pid = readPid(abs(proc.pidFile))
2797
+ if (!pid || !isAlive(pid)) return null
2798
+ let settings = null
2799
+ try {
2800
+ settings = JSON.parse(fs.readFileSync(abs(settingsFile), 'utf-8'))
2801
+ } catch {
2802
+ return null
2803
+ }
2804
+ if (!settings || !settings.port) return null
2805
+ return {
2806
+ port: settings.port,
2807
+ token: settings.token || null,
2808
+ loopback: settings.host === '127.0.0.1' || settings.host === 'localhost',
2809
+ }
2810
+ }
2811
+
2812
+ /**
2813
+ * The stack a re-show prints: the same tiers and `live` a render reports, from
2814
+ * the same functions, with nothing rendered and nothing started.
2815
+ */
2816
+ function reshowStack(dir, config, spec, out) {
2817
+ const cfg = withSpecRemote(config, out)
2818
+ const up = readRunningReviewServer(dir, cfg)
2819
+ const served = up ? reviewServedUrls(up, offerableLanAddresses(), spec.folder) : null
2820
+ const tiers = reviewTierStack({ served, fileUrl: reviewFileUrl(out), publishedUrl: readReviewUrl(out), config: cfg })
2821
+ let live = null
2822
+ try {
2823
+ const primaryState = assertPrimaryOnMain(cfg, gitReader(dir))
2824
+ live = liveStateFor(
2825
+ spec,
2826
+ liveContext(dir, cfg, spec, { onBase: primaryState.onBase, primaryBranch: primaryState.branch }),
2827
+ )
2828
+ } catch {
2829
+ // Cannot tell whether it is live — print no line rather than a wrong one.
2830
+ live = null
2831
+ }
2832
+ return { tiers, live }
2833
+ }
2834
+
2764
2835
  async function specEnvReviewWait(dir, config, specArg, flags) {
2765
2836
  let spec
2766
2837
  try {
@@ -2794,10 +2865,28 @@ async function specEnvReviewWait(dir, config, specArg, flags) {
2794
2865
  // SAID BEFORE THE FIRST POLL, not after it. The whole point is that a caller
2795
2866
  // knows the wait is running; a line printed on the way out would arrive only
2796
2867
  // for the waits that already worked.
2868
+ //
2869
+ // WHICH START THIS IS, counted per window. A wait that dies is re-armed on the
2870
+ // same `--since`, and every re-arm leaves a trace in the conversation, so
2871
+ // after enough of them the banner and its links have scrolled out of sight.
2872
+ // Every `reshowEvery`th re-arm prints the stack again, read-only, for the
2873
+ // skill to relay as the banner.
2874
+ const reshowEvery = resolveReshowEvery(flags)
2875
+ const started = recordWaitStart(out, spec.folder, flags.since)
2876
+ const rearm = started ? started.rearm : null
2877
+ const reshow = reshowDue(rearm, reshowEvery)
2878
+ const stack = reshow ? reshowStack(dir, config, spec, out) : null
2879
+
2797
2880
  if (!flags.json) {
2798
2881
  process.stdout.write(
2799
2882
  `spec-env review wait: ${spec.folder} — waiting for a verdict sent since ${flags.since}` +
2800
- `${timeoutMs === null ? '' : ` (up to ${flags.timeout}s)`}\n`,
2883
+ `${timeoutMs === null ? '' : ` (up to ${flags.timeout}s)`}` +
2884
+ `${rearm ? ` (re-arm ${rearm})` : ''}\n` +
2885
+ (stack
2886
+ ? ` re-show: banner (re-arm ${rearm})\n` +
2887
+ stack.tiers.map((t) => reviewTierLine(t) + '\n').join('') +
2888
+ (liveStateLine(stack.live) ? `${liveStateLine(stack.live)}\n` : '')
2889
+ : ''),
2801
2890
  )
2802
2891
  }
2803
2892
 
@@ -2827,7 +2916,20 @@ async function specEnvReviewWait(dir, config, specArg, flags) {
2827
2916
  })
2828
2917
 
2829
2918
  if (flags.json) {
2830
- process.stdout.write(`${JSON.stringify({ spec: spec.folder, since: flags.since, ...result }, null, 2)}\n`)
2919
+ process.stdout.write(
2920
+ `${JSON.stringify(
2921
+ {
2922
+ spec: spec.folder,
2923
+ since: flags.since,
2924
+ rearm,
2925
+ reshow,
2926
+ ...(stack ? { tiers: stack.tiers, live: stack.live } : {}),
2927
+ ...result,
2928
+ },
2929
+ null,
2930
+ 2,
2931
+ )}\n`,
2932
+ )
2831
2933
  }
2832
2934
 
2833
2935
  if (result.state === 'arrived') {
@@ -5617,6 +5719,7 @@ async function specEnv(rest) {
5617
5719
  claim: null,
5618
5720
  offered: false,
5619
5721
  heartbeat: null,
5722
+ reshowEvery: null,
5620
5723
  drop: null,
5621
5724
  buttons: null,
5622
5725
  json: false,
@@ -5652,6 +5755,7 @@ async function specEnv(rest) {
5652
5755
  else if (args[i] === '--claim') flags.claim = args[++i]
5653
5756
  else if (args[i] === '--claim-since') flags.claimSince = args[++i]
5654
5757
  else if (args[i] === '--heartbeat') flags.heartbeat = args[++i]
5758
+ else if (args[i] === '--reshow-every') flags.reshowEvery = args[++i]
5655
5759
  else if (args[i] === '--since') flags.since = args[++i]
5656
5760
  else if (args[i] === '--timeout') flags.timeout = args[++i]
5657
5761
  else if (args[i] === '--drop') flags.drop = args[++i]
@@ -5831,6 +5935,7 @@ async function specEnv(rest) {
5831
5935
  ' review skip [spec] "<reason>" move on without one, on the record\n' +
5832
5936
  ' review gate [spec] --offered record that the bypass was offered (spends it)\n' +
5833
5937
  ' review wait [spec] --heartbeat <secs> proof-of-life cadence on stderr; 0 disables\n' +
5938
+ ' review wait [spec] --reshow-every <n> print the stack again every nth re-arm (5); 0 disables\n' +
5834
5939
  ' review wait [spec] --since <iso> block until a verdict arrives ([--timeout <s>])\n' +
5835
5940
  ' review waiting [--json] every pass waiting, across every spec\n' +
5836
5941
  ' review [spec] --claim-since <iso> claim the one pass that arrived since <iso>\n' +
@@ -4,7 +4,8 @@
4
4
  * Pure spec/branch resolution for per-spec isolation.
5
5
  *
6
6
  * Given a spec argument (a folder name or path) it locates the spec folder under
7
- * `specs/**`, splits the `feat-`/`bug-` prefix into `{ type, slug }`, derives the
7
+ * `specs/**`, splits the `feat-`/`bug-`/`hotfix-`/`chore-`/`issue-`/`incident-` prefix into
8
+ * `{ type, slug }`, derives the
8
9
  * git branch from the config's `branch.pattern` (provider-neutral; `{identifier}`
9
10
  * is filled from a tracker id when one is configured, else it falls back to
10
11
  * `{type}/{slug}`), and expands the config's path/name tokens (`{repo}`,
@@ -294,10 +295,11 @@ function phaseIsDone(text) {
294
295
  return /^#\s.*✅\s*$/m.test(text)
295
296
  }
296
297
 
297
- // Split a `feat-`/`bug-`/`hotfix-` prefix. Unknown prefix → type defaults to
298
- // `feat` and the whole folder name is the slug.
298
+ // Split a `feat-`/`bug-`/`hotfix-`/`chore-`/`issue-`/`incident-` prefix.
299
+ // Unknown prefix → type defaults to `feat` and the whole folder name is the
300
+ // slug.
299
301
  function splitPrefix(folder) {
300
- const m = /^(feat|bug|hotfix)-(.+)$/.exec(folder)
302
+ const m = /^(feat|bug|hotfix|chore|issue|incident)-(.+)$/.exec(folder)
301
303
  if (m) return { type: m[1], slug: m[2] }
302
304
  return { type: 'feat', slug: folder }
303
305
  }
@@ -498,6 +500,12 @@ function assertPrimaryOnMain(config, git) {
498
500
  * was actually created against, and re-deriving it would go wrong the moment a
499
501
  * project changed its pattern under a standing branch.
500
502
  *
503
+ * A `chore-foo` SPEC derives the same `chore/foo` branch as `/no-spec foo`
504
+ * does, deliberately left colliding: both cannot exist at once, and git
505
+ * refuses the second `worktree add -b` loudly rather than either lane
506
+ * silently adopting the other's branch (spec feat-chore-kind-bug-bodies,
507
+ * decision 9).
508
+ *
501
509
  * Pure but for `repoInfo`, like `resolveSpec`.
502
510
  */
503
511
  function resolveSpecless(name, dir, config, entry = {}) {
package/src/env/review.js CHANGED
@@ -1282,6 +1282,81 @@ const WAIT_POLL_MS = 400
1282
1282
  // whatever is supervising the process.
1283
1283
  const WAIT_HEARTBEAT_MS = 5 * 60 * 1000
1284
1284
 
1285
+ // Every this-many re-arms on one window, the wait prints the stack again. A
1286
+ // COUNT, not an interval, and deliberately: what buries the banner is how many
1287
+ // re-arms have scrolled past it, and a death every five minutes and one every
1288
+ // forty-five push it up the same distance each. This is not the count
1289
+ // `spec-reports.md` rejects — that one bounded how long to keep waiting, and
1290
+ // the 12-hour age bound below still does.
1291
+ const WAIT_RESHOW_EVERY = 5
1292
+
1293
+ // How old a window may be before its start count is pruned. The same 12 hours
1294
+ // the skills stop re-arming at: past it nobody is counting, so nothing is kept.
1295
+ const WAIT_WINDOW_MAX_MS = 12 * 60 * 60 * 1000
1296
+
1297
+ // Beside the pending store, under gitignored `.spec-env/`.
1298
+ const WAITS_SUFFIX = '.waits.json'
1299
+
1300
+ function reviewWaitsPath(outPath) {
1301
+ return outPath.replace(/\.html$/, '') + WAITS_SUFFIX
1302
+ }
1303
+
1304
+ /**
1305
+ * Record that a wait started on `since`, and say which start this is.
1306
+ * Returns `{ starts, rearm }` — `rearm` is 0 for the first wait on a window —
1307
+ * or `null` when it cannot tell.
1308
+ *
1309
+ * CANNOT-TELL IS NULL, and null means no re-show (`.claude/rules/negative-checks.md`
1310
+ * rule 4). A store that will not parse, a window that is not a timestamp, a
1311
+ * write that failed: each costs the reader one reminder, never a verdict, so
1312
+ * none of them is worth more than silence. An unreadable store is also never
1313
+ * written over — it may be someone's history.
1314
+ *
1315
+ * WHAT WOULD FOOL THIS: it counts STARTS, so anything that runs `review wait`
1316
+ * on the same window counts too — a second session waiting on one spec, or a
1317
+ * person running it by hand. That over-counts, and the cost is a banner shown
1318
+ * a little early, which is the harmless direction.
1319
+ */
1320
+ function recordWaitStart(outPath, specFolder, since, { now = Date.now() } = {}) {
1321
+ if (!Number.isFinite(Date.parse(since))) return null
1322
+ const file = reviewWaitsPath(outPath)
1323
+ let store = { version: 1, spec: specFolder, windows: {} }
1324
+ let raw = null
1325
+ try {
1326
+ raw = fs.readFileSync(file, 'utf8')
1327
+ } catch {}
1328
+ if (raw !== null) {
1329
+ try {
1330
+ const parsed = JSON.parse(raw)
1331
+ if (!parsed || typeof parsed.windows !== 'object' || parsed.windows === null) return null
1332
+ store = { version: parsed.version || 1, spec: parsed.spec || specFolder, windows: parsed.windows }
1333
+ } catch {
1334
+ return null
1335
+ }
1336
+ }
1337
+ const windows = {}
1338
+ for (const [key, count] of Object.entries(store.windows)) {
1339
+ const at = Date.parse(key)
1340
+ if (Number.isFinite(at) && now - at <= WAIT_WINDOW_MAX_MS) windows[key] = count
1341
+ }
1342
+ const prior = Number.isInteger(windows[since]) && windows[since] > 0 ? windows[since] : 0
1343
+ const starts = prior + 1
1344
+ windows[since] = starts
1345
+ try {
1346
+ fs.mkdirSync(path.dirname(file), { recursive: true })
1347
+ fs.writeFileSync(file, JSON.stringify({ ...store, windows }, null, 2) + '\n')
1348
+ } catch {
1349
+ return null
1350
+ }
1351
+ return { starts, rearm: starts - 1 }
1352
+ }
1353
+
1354
+ // Is this re-arm one that re-shows the stack? Pure. The first wait never does —
1355
+ // the banner is right above it — and `every` of 0 turns it off.
1356
+ function reshowDue(rearm, every = WAIT_RESHOW_EVERY) {
1357
+ return Number.isInteger(every) && every > 0 && Number.isInteger(rearm) && rearm > 0 && rearm % every === 0
1358
+ }
1359
+
1285
1360
  /**
1286
1361
  * Block until exactly one pass arrives inside a window. Impure only in that it
1287
1362
  * reads the store and sleeps; it writes nothing and claims nothing.
@@ -2555,6 +2630,10 @@ module.exports = {
2555
2630
  waitingPasses,
2556
2631
  waitForPass,
2557
2632
  WAIT_HEARTBEAT_MS,
2633
+ WAIT_RESHOW_EVERY,
2634
+ recordWaitStart,
2635
+ reshowDue,
2636
+ reviewWaitsPath,
2558
2637
  WAIT_POLL_MS,
2559
2638
  passState,
2560
2639
  describePending,
@@ -28,6 +28,8 @@ const {
28
28
  validateStates,
29
29
  stateSuggestions,
30
30
  stateNamesFor,
31
+ effectiveStates,
32
+ specHeaders,
31
33
  remoteDescriptionEdited,
32
34
  writeFrontmatter,
33
35
  stampSubIssueId,
@@ -138,9 +140,26 @@ function stateCheckFailure(config, flags) {
138
140
  // issue's own open/closed where the bucket calls for it. Both are idempotent —
139
141
  // a Status already set is left alone, and the issue is only opened or closed
140
142
  // when it is not already.
141
- function applyOps({ adapter, config }) {
143
+ // A spec's KIND, read off its folder prefix — the same convention the
144
+ // lifecycle skills stamp into `> **Type:**`, but greppable with no file read.
145
+ function specKindOf(snapshotDir) {
146
+ const name = path.basename(String(snapshotDir || ''))
147
+ if (name.startsWith('bug-')) return 'bug'
148
+ if (name.startsWith('hotfix-')) return 'hotfix'
149
+ if (name.startsWith('chore-')) return 'chore'
150
+ if (name.startsWith('issue-')) return 'issue'
151
+ if (name.startsWith('incident-')) return 'incident'
152
+ return 'feature'
153
+ }
154
+
155
+ function applyOps({ adapter, config, kind = 'feature', snapshotDir = null }) {
156
+ // Per-kind resolution: GitHub has no work item types, so statesByKind keys
157
+ // the override by the SPEC's kind. Null means "send no Status for this
158
+ // bucket" — the open/close half of settle still runs, since closing is
159
+ // derived from the bucket, not from the Status column.
142
160
  const statusFor = (bucket) => {
143
- const name = config.states && config.states[bucket]
161
+ const name = effectiveStates(config, config.statesByKind, kind)[bucket]
162
+ if (name === null) return null
144
163
  if (!name) {
145
164
  throw new Error(`no state configured for the "${bucket}" bucket — fix ${CONFIG_FILE} -> states`)
146
165
  }
@@ -150,7 +169,8 @@ function applyOps({ adapter, config }) {
150
169
  if (!bucket) return
151
170
  const issue = issueOrRef && issueOrRef.nodeId ? issueOrRef : await adapter.readIssue(issueOrRef)
152
171
  if (!issue) throw new Error(`no GitHub issue found for ${issueOrRef}`)
153
- const changed = await adapter.setStatus(issue, statusFor(bucket))
172
+ const status = statusFor(bucket)
173
+ const changed = status === null ? { changed: false } : await adapter.setStatus(issue, status)
154
174
  const reason = closeReasonForBucket(bucket)
155
175
  const wantOpen = !reason
156
176
  if (issue.open === wantOpen) return
@@ -185,6 +205,22 @@ function applyOps({ adapter, config }) {
185
205
  }
186
206
  const spec = markersFor(config, 'spec')
187
207
  const phase = markersFor(config, 'phase')
208
+ // THIS spec's kind label (github.labelsByKind), beside the spec marker.
209
+ // Unmapped kinds add nothing, so an unconfigured project's payloads are
210
+ // byte-identical to before the key existed.
211
+ const kindLabel = (config.github.labelsByKind || {})[kind]
212
+ if (kindLabel && !spec.labels.some((l) => l.toLowerCase() === kindLabel.toLowerCase())) {
213
+ spec.labels = [...spec.labels, kindLabel]
214
+ }
215
+ // The `Severity:` header's label (github.severityLabels, keyed by the
216
+ // leading digit — "2 - High" → "2"). Opt-in: unset, the header stays
217
+ // repo-only and the payload is byte-identical to before.
218
+ const severity = snapshotDir ? specHeaders(snapshotDir, config).severity : null
219
+ const severityDigit = severity ? (/^([1-4])/.exec(severity) || [])[1] : null
220
+ const severityLabel = severityDigit ? (config.github.severityLabels || {})[severityDigit] : null
221
+ if (severityLabel && !spec.labels.some((l) => l.toLowerCase() === severityLabel.toLowerCase())) {
222
+ spec.labels = [...spec.labels, severityLabel]
223
+ }
188
224
  return {
189
225
  prevalidateStates: (buckets) => {
190
226
  for (const bucket of buckets) statusFor(bucket)
@@ -379,7 +415,7 @@ async function specSyncApply(dir, config, specArg, flags, out, err) {
379
415
  snapshotDir,
380
416
  plan,
381
417
  adapter: cred.adapter,
382
- ops: applyOps({ adapter: cred.adapter, config }),
418
+ ops: applyOps({ adapter: cred.adapter, config, kind: specKindOf(snapshotDir), snapshotDir }),
383
419
  forceNew: !!flags.forceNew,
384
420
  program: PROGRAM,
385
421
  })
@@ -1015,6 +1051,49 @@ async function specSyncPreserve(dir, config, specArg, flags, out) {
1015
1051
  }
1016
1052
  }
1017
1053
 
1054
+ // `comment <spec> --file <f>` — post a file's markdown onto the spec's issue
1055
+ // as a comment: the one surface one-way sync never touches, so no later push
1056
+ // can clobber it. `/spec-complete` posts an incident's log through this.
1057
+ // Misuse (no readable file) exits 1; every cannot-tell exits 0 and says so.
1058
+ async function specSyncComment(dir, config, specArg, flags, out) {
1059
+ const snapshotDir = resolveOrExit(specArg, dir, out)
1060
+ if (!snapshotDir) return 1
1061
+ const done = (msg) => {
1062
+ out.write(`${PROGRAM} comment: ${msg}\n`)
1063
+ return 0
1064
+ }
1065
+ if (!flags.file) {
1066
+ out.write(`${PROGRAM} comment: pass --file <markdown file to post>\n`)
1067
+ return 1
1068
+ }
1069
+ let body
1070
+ try {
1071
+ body = fs.readFileSync(flags.file, 'utf-8')
1072
+ } catch (error) {
1073
+ out.write(`${PROGRAM} comment: cannot read --file: ${error.message}\n`)
1074
+ return 1
1075
+ }
1076
+ if (!body.trim()) {
1077
+ out.write(`${PROGRAM} comment: --file is empty — nothing to post\n`)
1078
+ return 1
1079
+ }
1080
+ const overviewFile = (config.snapshot && config.snapshot.overviewFile) || '00-overview.md'
1081
+ const identifier = specHelpers.linkedIdentifier(path.join(snapshotDir, overviewFile), config)
1082
+ if (!identifier) return done(`${path.basename(snapshotDir)} is not linked — nothing posted`)
1083
+ const cred = apiAdapterFor(config, flags)
1084
+ const transport = kit.resolveTransport(flags, config, cred.ok)
1085
+ if (transport === 'mcp') {
1086
+ return done(`transport = mcp — post the file's contents onto ${identifier} with add_issue_comment yourself`)
1087
+ }
1088
+ if (!cred.ok) return done(`no token — ${cred.error.split('\n')[0]}; nothing posted`)
1089
+ try {
1090
+ await cred.adapter.createComment(identifier, body)
1091
+ return done(`${identifier} — comment posted (${body.length} characters)`)
1092
+ } catch (error) {
1093
+ return done(`could not reach GitHub (${String(error.message).split('\n')[0]}); nothing posted`)
1094
+ }
1095
+ }
1096
+
1018
1097
  // ---------------------------------------------------------------------------
1019
1098
  // Credentials: `status` is a READINESS check (exit 1 with none); `set`
1020
1099
  // prompts for the token hidden; `unset` removes the owner's entry.
@@ -1363,6 +1442,7 @@ const USAGE = `Usage: ${BIN} spec-sync <subcommand>
1363
1442
  ref [<spec>] the Refs: trailer value for this branch
1364
1443
  released [<range>] issues a commit range contains
1365
1444
  preserve <spec> [--text <f>] keep an adopted issue's original report
1445
+ comment <spec> --file <f> post a file onto the issue as a comment
1366
1446
  assign <spec> --to <login> | --release stamp who is building it
1367
1447
  whoami [--set <login>] [--unset] who you are on GitHub (cached)
1368
1448
  users [<query>] the repo's assignable people
@@ -1444,6 +1524,8 @@ async function specSync(rest, io = {}) {
1444
1524
  return specSyncReleased(dir, config, positional[0], flags, out)
1445
1525
  case 'preserve':
1446
1526
  return specSyncPreserve(dir, config, positional[0], flags, out)
1527
+ case 'comment':
1528
+ return specSyncComment(dir, config, positional[0], flags, out)
1447
1529
  case 'release':
1448
1530
  return kit.refuseRemovedVerb(out, PROGRAM, 'release')
1449
1531
  case 'assign':
@@ -1478,6 +1560,7 @@ function parseArgs(args, sub) {
1478
1560
  '--stored': { kind: 'path' },
1479
1561
  '--remote': { kind: 'path' },
1480
1562
  '--text': { kind: 'path' },
1563
+ '--file': { kind: 'path' },
1481
1564
  '--workspace-states': { kind: 'path', name: 'workspaceStates' },
1482
1565
  '--skip-state-check': { kind: 'boolean', name: 'skipStateCheck' },
1483
1566
  '--via': { kind: 'string' },
@@ -54,6 +54,12 @@ const DEFAULT_CONFIG = Object.freeze({
54
54
  statusField: 'Status',
55
55
  labels: Object.freeze({ spec: 'spec', phase: 'phase' }),
56
56
  issueTypes: Object.freeze({ spec: '', phase: '' }),
57
+ // One extra label per SPEC KIND (`feature`/`bug`/`hotfix`/`chore`, from
58
+ // the spec folder's prefix), applied beside `labels.spec` when set —
59
+ // `{ "chore": "chore" }` keeps tooling work filterable out of release
60
+ // views. Empty means no kind label, as before.
61
+ labelsByKind: Object.freeze({}),
62
+ severityLabels: Object.freeze({}),
57
63
  }),
58
64
  // A spec is a GitHub ISSUE; each phase a SUB-ISSUE of it, carrying the
59
65
  // phase's checkboxes in its body as a task list (rendered live by GitHub —
@@ -118,9 +124,10 @@ const LIFECYCLE_BUCKETS = Object.freeze(Object.keys(DEFAULT_CONFIG.states))
118
124
  function defaults() {
119
125
  const g = DEFAULT_CONFIG.github
120
126
  return {
121
- github: { ...g, labels: { ...g.labels }, issueTypes: { ...g.issueTypes } },
127
+ github: { ...g, labels: { ...g.labels }, issueTypes: { ...g.issueTypes }, labelsByKind: { ...g.labelsByKind }, severityLabels: { ...g.severityLabels } },
122
128
  mapping: { ...DEFAULT_CONFIG.mapping },
123
129
  states: { ...DEFAULT_CONFIG.states },
130
+ statesByKind: {},
124
131
  stateAliases: {},
125
132
  snapshot: { ...DEFAULT_CONFIG.snapshot },
126
133
  fields: { ...DEFAULT_CONFIG.fields },
@@ -146,7 +153,7 @@ function defaults() {
146
153
  }
147
154
 
148
155
  const { isObject, stringList, assign } = kitConfig
149
- const { mergeStates, mergeFieldOwnership, mergePhaseMapping, mergeReleaseIgnorePaths, mergeKeyedFields } =
156
+ const { mergeStates, mergeStateOverrides, mergeFieldOwnership, mergePhaseMapping, mergeReleaseIgnorePaths, mergeKeyedFields } =
150
157
  kitConfig.makeMergeHelpers({
151
158
  configFile: CONFIG_FILE,
152
159
  ownership: OWNERSHIP,
@@ -186,6 +193,25 @@ function mergeConfig(base, parsed) {
186
193
  assign(base.github.issueTypes, parsed.github.issueTypes, 'spec', 'string?')
187
194
  assign(base.github.issueTypes, parsed.github.issueTypes, 'phase', 'string?')
188
195
  }
196
+ if (isObject(parsed.github.labelsByKind)) {
197
+ // Only the kinds a spec folder can actually be — an unknown key is
198
+ // dropped, matching Azure's workItemTypeByKind validation.
199
+ const byKind = {}
200
+ for (const kind of ['feature', 'bug', 'hotfix', 'chore', 'issue', 'incident']) {
201
+ const value = parsed.github.labelsByKind[kind]
202
+ if (typeof value === 'string' && value.trim()) byKind[kind] = value.trim()
203
+ }
204
+ base.github.labelsByKind = byKind
205
+ }
206
+ if (isObject(parsed.github.severityLabels)) {
207
+ // Keyed by the Severity header's leading digit ("2 - High" → "2").
208
+ const bySeverity = {}
209
+ for (const digit of ['1', '2', '3', '4']) {
210
+ const value = parsed.github.severityLabels[digit]
211
+ if (typeof value === 'string' && value.trim()) bySeverity[digit] = value.trim()
212
+ }
213
+ base.github.severityLabels = bySeverity
214
+ }
189
215
  }
190
216
 
191
217
  if (isObject(parsed.mapping)) {
@@ -198,6 +224,7 @@ function mergeConfig(base, parsed) {
198
224
  }
199
225
 
200
226
  mergeStates(base, parsed)
227
+ mergeStateOverrides(base, parsed, 'statesByKind')
201
228
 
202
229
  if (isObject(parsed.snapshot)) {
203
230
  assign(base.snapshot, parsed.snapshot, 'overviewFile', 'string')
@@ -193,8 +193,52 @@ function makeMergeHelpers({ configFile, ownership, lifecycleBuckets, phaseMappin
193
193
  base.stateAliases = aliases
194
194
  }
195
195
 
196
+ // Merge (and validate) a per-type/kind state override table — `statesByType`
197
+ // keyed by work item / issue type (Azure, Jira), `statesByKind` keyed by spec
198
+ // kind (GitHub, Linear). Each entry is a PARTIAL bucket map laid over
199
+ // `states` for that type/kind: a bucket set to null means "send no state for
200
+ // this bucket", and a bucket the entry lacks falls through to `states`.
201
+ // An unknown bucket is refused — a typo'd bucket would silently change
202
+ // nothing at push time. Call after mergeStates, so buckets are final.
203
+ function mergeStateOverrides(base, parsed, key) {
204
+ const value = parsed[key]
205
+ if (!isObject(value)) return
206
+ const table = {}
207
+ for (const [name, entry] of Object.entries(value)) {
208
+ if (!isObject(entry)) {
209
+ throw new Error(
210
+ `Invalid ${configFile}: ${key}.${JSON.stringify(name)} = ${JSON.stringify(entry)} ` +
211
+ '(expected an object mapping lifecycle buckets to a state name, or null to send no state)',
212
+ )
213
+ }
214
+ const row = {}
215
+ for (const [bucket, state] of Object.entries(entry)) {
216
+ if (!(bucket in base.states)) {
217
+ throw new Error(
218
+ `Invalid ${configFile}: ${key}.${JSON.stringify(name)}.${bucket} — not a lifecycle bucket ` +
219
+ `(${Object.keys(base.states).join(', ')})`,
220
+ )
221
+ }
222
+ if (state === null) {
223
+ row[bucket] = null
224
+ continue
225
+ }
226
+ if (typeof state !== 'string' || !state.trim()) {
227
+ throw new Error(
228
+ `Invalid ${configFile}: ${key}.${JSON.stringify(name)}.${bucket} = ${JSON.stringify(state)} ` +
229
+ '(expected a state name, or null to send no state)',
230
+ )
231
+ }
232
+ row[bucket] = state.trim()
233
+ }
234
+ if (Object.keys(row).length) table[name] = row
235
+ }
236
+ base[key] = table
237
+ }
238
+
196
239
  return {
197
240
  mergeStates,
241
+ mergeStateOverrides,
198
242
  mergeFieldOwnership,
199
243
  mergePhaseMapping,
200
244
  mergeReleaseIgnorePaths,
@@ -13,7 +13,7 @@
13
13
  * stored matches what was sent — it merges nothing (see `src/verify.js`).
14
14
  */
15
15
 
16
- const { ownsField, normalizeLocal, LIFECYCLE_BUCKETS, lintPhases, readSnapshot, parseFrontmatter, remoteWorkflowState, remoteStateReading, stateNamesFor, titleFromText, validateStates, stateSuggestions, phaseModeFor } = require('./src/normalize.js')
16
+ const { ownsField, normalizeLocal, LIFECYCLE_BUCKETS, lintPhases, readSnapshot, parseFrontmatter, remoteWorkflowState, remoteStateReading, stateNamesFor, titleFromText, validateStates, stateSuggestions, effectiveStates, specHeaders, linkedIncident, phaseModeFor } = require('./src/normalize.js')
17
17
  const { planChanges, snapshotOf, isEmptyPlan, hashField, stableStringify, remoteDescriptionEdited, remoteSubIssueEdited } = require('./src/compare.js')
18
18
  const { readBase, writeBase } = require('./src/base.js')
19
19
  const { push, recordPush, projectionOf } = require('./src/push.js')
@@ -46,6 +46,9 @@ module.exports = {
46
46
  titleFromText,
47
47
  validateStates,
48
48
  stateSuggestions,
49
+ effectiveStates,
50
+ specHeaders,
51
+ linkedIncident,
49
52
  hashField,
50
53
  stableStringify,
51
54
  readBase,