@skitterbyte/skitterspec-azure-boards 2.1.0 → 2.3.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.
@@ -28,6 +28,9 @@ const fs = require('node:fs')
28
28
  const path = require('node:path')
29
29
 
30
30
  const {
31
+ effectiveStates,
32
+ specHeaders,
33
+ linkedIncident,
31
34
  push,
32
35
  recordPush,
33
36
  readBase,
@@ -129,6 +132,40 @@ function stateCheckFailure(config, flags) {
129
132
  } catch (error) {
130
133
  return [`${PROGRAM} plan: refusing — --workspace-states is not valid JSON: ${error.message}`]
131
134
  }
135
+ // The keyed shape (`{ "<type>": [names] }`, what `states --json` prints) is
136
+ // checked PER TYPE: each type's effective states — statesByType over states,
137
+ // nulls skipped — against that type's own list, so a state one type lacks
138
+ // refuses before the first write even when another type has it.
139
+ if (names && typeof names === 'object' && !Array.isArray(names)) {
140
+ const lc = (s) => String(s).toLowerCase().trim()
141
+ const types = [
142
+ ...new Set(
143
+ [config.azure.workItemType, config.azure.childType, ...Object.values(config.azure.workItemTypeByKind || {})].filter(Boolean),
144
+ ),
145
+ ]
146
+ const problems = []
147
+ for (const type of types) {
148
+ const have = names[type]
149
+ // A TYPE THE FILE LACKS IS A CANNOT-TELL, not a refusal: an absence
150
+ // here is an older file or a type the fetch could not read, and neither
151
+ // is evidence the config is wrong (negative-checks.md rule 4).
152
+ if (!Array.isArray(have)) continue
153
+ const haveSet = new Set(have.map(lc))
154
+ const effective = effectiveStates(config, config.statesByType, type)
155
+ for (const [bucket, name] of Object.entries(effective)) {
156
+ if (typeof name !== 'string') continue // null = send no state
157
+ if (!haveSet.has(lc(name))) problems.push({ type, bucket, name, available: have })
158
+ }
159
+ }
160
+ if (!problems.length) return null
161
+ const lines = [`${PROGRAM} plan: refusing — configured state name(s) missing from the type that would receive them`, '']
162
+ for (const p of problems) {
163
+ lines.push(` ${p.type}: "${p.name}" (states.${p.bucket}) is not a state this type has`)
164
+ lines.push(` ${p.type} has: ${p.available.join(', ') || '(none reported)'}`)
165
+ }
166
+ lines.push('', ` Fix ${CONFIG_FILE} -> states / statesByType.`)
167
+ return lines
168
+ }
132
169
  const list = Array.isArray(names) ? names : []
133
170
  const missing = validateStates(config, list)
134
171
  if (missing.length) {
@@ -154,25 +191,47 @@ function specKindOf(snapshotDir) {
154
191
  if (name.startsWith('bug-')) return 'bug'
155
192
  if (name.startsWith('hotfix-')) return 'hotfix'
156
193
  if (name.startsWith('chore-')) return 'chore'
194
+ if (name.startsWith('issue-')) return 'issue'
195
+ if (name.startsWith('incident-')) return 'incident'
157
196
  return 'feature'
158
197
  }
159
198
 
160
- function applyOps({ adapter, config, out, kind = 'feature' }) {
199
+ function applyOps({ adapter, config, out, kind = 'feature', snapshotDir = null }) {
161
200
  // The mint type for THIS spec's kind (its folder prefix), falling back to
162
201
  // the one configured type. The twin search uses the same type, so a bug
163
202
  // never refuses over a feature that happens to share its title.
164
203
  const mintType =
165
204
  (config.azure.workItemTypeByKind && config.azure.workItemTypeByKind[kind]) || config.azure.workItemType
166
- const stateFor = (bucket) => {
167
- const name = config.states && config.states[bucket]
205
+ // Push-time extras off the spec's own headers: `Severity:` lands in the
206
+ // built-in field, `Incident:` as a Related link. Neither is a synced field,
207
+ // so neither touches the stored-base hashes.
208
+ const severity = snapshotDir ? specHeaders(snapshotDir, config).severity : null
209
+ const incident = snapshotDir ? linkedIncident(snapshotDir, config) : null
210
+ const relateToIncident = async (idOrIdentifier) => {
211
+ if (!incident) return
212
+ if (!incident.identifier) {
213
+ if (out) out.write(` !! related incident ${incident.name} is not linked yet — link skipped\n`)
214
+ return
215
+ }
216
+ if (typeof adapter.addRelatedLink !== 'function') return
217
+ const r = await adapter.addRelatedLink(apiId(idOrIdentifier), apiId(incident.identifier))
218
+ if (out && r && r.added) out.write(` related link added: ${incident.identifier}\n`)
219
+ }
220
+ // Per-type resolution: statesByType[type] overlays states, and null means
221
+ // "send no state for this bucket" — a deliberate skip, not a gap.
222
+ const stateFor = (bucket, type) => {
223
+ const name = effectiveStates(config, config.statesByType, type)[bucket]
224
+ if (name === null) return null
168
225
  if (!name) {
169
226
  throw new Error(`no state configured for the "${bucket}" bucket — fix ${CONFIG_FILE} -> states`)
170
227
  }
171
228
  return name
172
229
  }
173
- const settle = async (idOrIdentifier, bucket) => {
230
+ const settle = async (idOrIdentifier, bucket, type) => {
174
231
  if (!bucket) return
175
- await adapter.transitionTo(apiId(idOrIdentifier), stateFor(bucket))
232
+ const name = stateFor(bucket, type)
233
+ if (name === null) return
234
+ await adapter.transitionTo(apiId(idOrIdentifier), name)
176
235
  }
177
236
  // Azure refuses the WHOLE patch over one bad `System.AssignedTo` value
178
237
  // ("… is an unknown identity", live repro), which used to take the
@@ -192,9 +251,27 @@ function applyOps({ adapter, config, out, kind = 'feature' }) {
192
251
  return result
193
252
  }
194
253
  }
254
+ // The same shape for Severity: a type without the field refuses the whole
255
+ // patch, and a missing severity field is a cosmetic gap where the rest of
256
+ // the push is not. Only the severity-naming refusal is retried.
257
+ const skippingRefusedSeverity = async (input, send) => {
258
+ if (input.severity === undefined) return send(input)
259
+ try {
260
+ return await send(input)
261
+ } catch (error) {
262
+ if (!/severity/i.test(String(error && error.message))) throw error
263
+ const { severity: dropped, ...rest } = input
264
+ const result = await send(rest)
265
+ if (out) out.write(` !! severity skipped: this type has no Severity field — the rest of the push landed\n`)
266
+ return result
267
+ }
268
+ }
195
269
  return {
196
270
  prevalidateStates: (buckets) => {
197
- for (const bucket of buckets) stateFor(bucket)
271
+ for (const bucket of buckets) {
272
+ stateFor(bucket, mintType)
273
+ stateFor(bucket, config.azure.childType)
274
+ }
198
275
  },
199
276
  searchTwin: (title) => adapter.searchIssues({ query: title, workItemType: mintType }),
200
277
  twinAdvice: (twin, wanted, specName) =>
@@ -212,10 +289,12 @@ function applyOps({ adapter, config, out, kind = 'feature' }) {
212
289
  assigneeId: issue && issue.assignee ? issue.assignee : undefined,
213
290
  workItemType: mintType,
214
291
  areaPath: config.azure.areaPath || undefined,
292
+ severity: severity != null ? severity : undefined,
215
293
  },
216
- (input) => adapter.createIssue(input),
294
+ (input) => skippingRefusedSeverity(input, (i) => adapter.createIssue(i)),
217
295
  )
218
- await settle(created.id, issue && issue.state)
296
+ await settle(created.id, issue && issue.state, mintType)
297
+ await relateToIncident(created.id)
219
298
  return created
220
299
  },
221
300
  updateIssue: async (existing, issue) => {
@@ -224,10 +303,14 @@ function applyOps({ adapter, config, out, kind = 'feature' }) {
224
303
  // Null is meaningful here — it is how Boards unassigns — so the key is
225
304
  // forwarded whenever the plan carries it, never truthiness-tested.
226
305
  if ('assignee' in issue) updates.assigneeId = issue.assignee ?? null
306
+ if (severity != null) updates.severity = severity
227
307
  if (Object.keys(updates).length) {
228
- await skippingRefusedAssignee(updates, (input) => adapter.updateIssue(apiId(existing.identifier), input))
308
+ await skippingRefusedAssignee(updates, (input) =>
309
+ skippingRefusedSeverity(input, (i) => adapter.updateIssue(apiId(existing.identifier), i)),
310
+ )
229
311
  }
230
- await settle(existing.identifier, issue.state)
312
+ await settle(existing.identifier, issue.state, mintType)
313
+ await relateToIncident(existing.identifier)
231
314
  },
232
315
  mintSubIssue: async (parentId, sub) => {
233
316
  const created = await adapter.createSubIssue(apiId(parentId), {
@@ -236,7 +319,7 @@ function applyOps({ adapter, config, out, kind = 'feature' }) {
236
319
  childType: config.azure.childType,
237
320
  areaPath: config.azure.areaPath || undefined,
238
321
  })
239
- await settle(created.id, sub.state)
322
+ await settle(created.id, sub.state, config.azure.childType)
240
323
  return created
241
324
  },
242
325
  updateSubIssue: async (sub) => {
@@ -244,7 +327,7 @@ function applyOps({ adapter, config, out, kind = 'feature' }) {
244
327
  if (sub.name != null) updates.title = sub.name
245
328
  if (sub.goal != null) updates.description = sub.goal
246
329
  if (Object.keys(updates).length) await adapter.updateIssue(apiId(sub.id), updates)
247
- await settle(sub.id, sub.state)
330
+ await settle(sub.id, sub.state, config.azure.childType)
248
331
  },
249
332
  }
250
333
  }
@@ -368,13 +451,9 @@ const assignment = makeAssignmentCommands({
368
451
  usersOverMcp: 'search identities with core_get_identity_ids over MCP, or read them off the org\'s Users page',
369
452
  })
370
453
 
371
- // The state names EVERY configured type can hold, deduped — one map serves the
372
- // spec item and its children, so a name only has to exist on one of them to be
373
- // writable somewhere, and validation checks against the union. The per-kind
374
- // mint types are in the union too, so a `workItemTypeByKind` entry's states
375
- // are validated before the first write, exactly like the base pair.
376
- async function unionStates(adapter, config) {
377
- const types = [
454
+ // Every configured type — the base pair plus the per-kind mint types.
455
+ function configuredTypes(config) {
456
+ return [
378
457
  ...new Set(
379
458
  [
380
459
  config.azure.workItemType,
@@ -383,9 +462,27 @@ async function unionStates(adapter, config) {
383
462
  ].filter(Boolean),
384
463
  ),
385
464
  ]
465
+ }
466
+
467
+ // The state names PER configured type: `{ "<type>": [states] }`. This is what
468
+ // `states --json` prints and what per-type validation consumes — a state one
469
+ // type lacks must refuse even when another type has it.
470
+ async function statesByType(adapter, config) {
471
+ const byType = {}
472
+ for (const type of configuredTypes(config)) {
473
+ byType[type] = await adapter.listIssueStates(type)
474
+ }
475
+ return byType
476
+ }
477
+
478
+ // The same names deduped across types — the display union. Validation no
479
+ // longer checks against this (a union hides exactly the per-type gap the
480
+ // pre-write check exists to catch); the TTY report still lists it.
481
+ async function unionStates(adapter, config) {
482
+ const byType = await statesByType(adapter, config)
386
483
  const byName = new Map()
387
- for (const type of types) {
388
- for (const s of await adapter.listIssueStates(type)) {
484
+ for (const states of Object.values(byType)) {
485
+ for (const s of states) {
389
486
  if (!byName.has(s.name)) byName.set(s.name, s)
390
487
  }
391
488
  }
@@ -461,7 +558,7 @@ function companionCoverageNote(dir, config, snapshotDir, out) {
461
558
  const rawField = parsed.branch && parsed.branch.identifierField
462
559
  const field = typeof rawField === 'string' && rawField ? rawField : config.fields.identifier
463
560
 
464
- const slug = path.basename(snapshotDir).replace(/^(feat|bug|hotfix|chore)-/, '')
561
+ const slug = path.basename(snapshotDir).replace(/^(feat|bug|hotfix|chore|issue|incident)-/, '')
465
562
  const basePath = `${config.sync.baseDir}/${identifier}.base.json`
466
563
  const claimed = patterns.some((p) => {
467
564
  if (typeof p !== 'string') return false
@@ -510,7 +607,7 @@ async function specSyncApply(dir, config, specArg, flags, out, err) {
510
607
  snapshotDir,
511
608
  plan,
512
609
  adapter: cred.adapter,
513
- ops: applyOps({ adapter: cred.adapter, config, out, kind: specKindOf(snapshotDir) }),
610
+ ops: applyOps({ adapter: cred.adapter, config, out, kind: specKindOf(snapshotDir), snapshotDir }),
514
611
  forceNew: !!flags.forceNew,
515
612
  program: PROGRAM,
516
613
  })
@@ -769,16 +866,24 @@ async function specSyncStates(dir, config, flags, out) {
769
866
  return 1
770
867
  }
771
868
  let states
869
+ let byType
772
870
  try {
773
- states = await unionStates(cred.adapter, config)
871
+ byType = await statesByType(cred.adapter, config)
872
+ const byName = new Map()
873
+ for (const list of Object.values(byType)) for (const s of list) if (!byName.has(s.name)) byName.set(s.name, s)
874
+ states = [...byName.values()]
774
875
  } catch (error) {
775
876
  out.write(`${PROGRAM} states: ${error.message}\n`)
776
877
  return 1
777
878
  }
778
879
  const names = states.map((s) => s.name)
779
880
  if (flags.json) {
780
- // The bare array --workspace-states consumes.
781
- out.write(JSON.stringify(names, null, 2) + '\n')
881
+ // The keyed shape --workspace-states consumes: `{ "<type>": [names] }`,
882
+ // so the pre-write check can validate each type against its own states.
883
+ // (A bare array from an older engine is still accepted there.)
884
+ const keyed = {}
885
+ for (const [type, list] of Object.entries(byType)) keyed[type] = list.map((s) => s.name)
886
+ out.write(JSON.stringify(keyed, null, 2) + '\n')
782
887
  return 0
783
888
  }
784
889
  const catOf = new Map(states.map((s) => [s.name, s.category || null]))
@@ -810,6 +915,29 @@ async function specSyncStates(dir, config, flags, out) {
810
915
  }
811
916
  }
812
917
  if (missing.length) lines.push(` remap: ${PROGRAM} init-config --force --state <bucket>="<state>"`)
918
+ // Per-type overrides, each checked against ITS type's own states — the
919
+ // union above cannot see a state one type lacks. Absent entirely when no
920
+ // statesByType is configured.
921
+ const overrideTypes = Object.keys(config.statesByType || {})
922
+ if (overrideTypes.length) {
923
+ lines.push('', ' statesByType overrides, checked per type:')
924
+ const lc = (s) => String(s).toLowerCase().trim()
925
+ for (const type of overrideTypes) {
926
+ const have = new Set((byType[type] || []).map((s) => lc(s.name)))
927
+ const known = type in byType
928
+ for (const [bucket, name] of Object.entries(config.statesByType[type])) {
929
+ const tail =
930
+ name === null
931
+ ? 'sends no state'
932
+ : !known
933
+ ? 'type not configured for push — not checked'
934
+ : have.has(lc(name))
935
+ ? 'ok'
936
+ : 'MISSING from this type'
937
+ lines.push(` ${type}.${bucket} -> ${name === null ? '(none)' : name} ${tail}`)
938
+ }
939
+ }
940
+ }
813
941
  out.write(lines.join('\n') + '\n')
814
942
  return 0
815
943
  }
@@ -1017,6 +1145,49 @@ async function specSyncPreserve(dir, config, specArg, flags, out) {
1017
1145
  }
1018
1146
  }
1019
1147
 
1148
+ // `comment <spec> --file <f>` — post a file's markdown onto the spec's work
1149
+ // item as a comment: the one surface one-way sync never touches, so no later
1150
+ // push can clobber it. `/spec-complete` posts an incident's log through this.
1151
+ // Misuse (no readable file) exits 1; every cannot-tell exits 0 and says so.
1152
+ async function specSyncComment(dir, config, specArg, flags, out) {
1153
+ const snapshotDir = resolveOrExit(specArg, dir, out)
1154
+ if (!snapshotDir) return 1
1155
+ const done = (msg) => {
1156
+ out.write(`${PROGRAM} comment: ${msg}\n`)
1157
+ return 0
1158
+ }
1159
+ if (!flags.file) {
1160
+ out.write(`${PROGRAM} comment: pass --file <markdown file to post>\n`)
1161
+ return 1
1162
+ }
1163
+ let body
1164
+ try {
1165
+ body = fs.readFileSync(flags.file, 'utf-8')
1166
+ } catch (error) {
1167
+ out.write(`${PROGRAM} comment: cannot read --file: ${error.message}\n`)
1168
+ return 1
1169
+ }
1170
+ if (!body.trim()) {
1171
+ out.write(`${PROGRAM} comment: --file is empty — nothing to post\n`)
1172
+ return 1
1173
+ }
1174
+ const overviewFile = (config.snapshot && config.snapshot.overviewFile) || '00-overview.md'
1175
+ const identifier = specHelpers.linkedIdentifier(path.join(snapshotDir, overviewFile), config)
1176
+ if (!identifier) return done(`${path.basename(snapshotDir)} is not linked — nothing posted`)
1177
+ const cred = apiAdapterFor(config, flags)
1178
+ const transport = kit.resolveTransport(flags, config, cred.ok)
1179
+ if (transport === 'mcp') {
1180
+ return done(`transport = mcp — post the file's contents onto ${identifier} with the comment tool yourself`)
1181
+ }
1182
+ if (!cred.ok) return done(`no credentials — ${cred.error.split('\n')[0]}; nothing posted`)
1183
+ try {
1184
+ await cred.adapter.createComment(apiId(identifier), body)
1185
+ return done(`${identifier} — comment posted (${body.length} characters)`)
1186
+ } catch (error) {
1187
+ return done(`could not reach Azure (${String(error.message).split('\n')[0]}); nothing posted`)
1188
+ }
1189
+ }
1190
+
1020
1191
  // ---------------------------------------------------------------------------
1021
1192
  // Credentials: `status` is a READINESS check (exit 1 with none); `set`
1022
1193
  // prompts with hidden input; `unset` removes the org's entry.
@@ -1306,20 +1477,32 @@ async function specSyncDoctor(dir, flags, out) {
1306
1477
  try {
1307
1478
  const viewer = await adapter.readViewer()
1308
1479
  checks.push(row('remote', 'Azure reachable', 'ok', viewer ? `as ${viewer.name || viewer.id}` : 'yes'))
1309
- const states = await unionStates(adapter, config)
1310
- // Deduped: complete and cancelled both map to one state by default,
1311
- // and "not in the project: Done, Done" reads as a stutter, not a fact.
1312
- const missing = [...new Set(validateStates(config, states.map((s) => s.name)))]
1480
+ // PER TYPE, the same check the pre-write gate runs: each type's
1481
+ // effective states (statesByType over states, nulls skipped) against
1482
+ // that type's own list — a union would hide exactly the gap this
1483
+ // exists to catch. Deduped so two buckets on one name read once.
1484
+ const byType = await statesByType(adapter, config)
1485
+ const lc = (s) => String(s).toLowerCase().trim()
1486
+ const missing = [
1487
+ ...new Set(
1488
+ Object.entries(byType).flatMap(([type, list]) => {
1489
+ const have = new Set(list.map((s) => lc(s.name)))
1490
+ return Object.values(effectiveStates(config, config.statesByType, type)).filter(
1491
+ (name) => typeof name === 'string' && !have.has(lc(name)),
1492
+ ).map((name) => `${name} (${type})`)
1493
+ }),
1494
+ ),
1495
+ ]
1313
1496
  checks.push(
1314
1497
  missing.length
1315
1498
  ? row(
1316
1499
  'states',
1317
1500
  'State names',
1318
1501
  'broken',
1319
- `not in these types: ${missing.join(', ')}`,
1320
- `fix ${CONFIG_FILE} -> states (see spec-sync states)`,
1502
+ `not in the type that would receive them: ${missing.join(', ')}`,
1503
+ `fix ${CONFIG_FILE} -> states / statesByType (see spec-sync states)`,
1321
1504
  )
1322
- : row('states', 'State names', 'ok', 'every configured state exists'),
1505
+ : row('states', 'State names', 'ok', 'every configured state exists on its type'),
1323
1506
  )
1324
1507
  // Every mapped type must exist, and carry the body field configured
1325
1508
  // for it — a missing type fails the first push, and a missing field
@@ -1409,6 +1592,7 @@ const USAGE = `Usage: skitterspec-azure-boards spec-sync <subcommand>
1409
1592
  ref [<spec>] the Refs: trailer value for this branch
1410
1593
  released [<range>] tickets a commit range contains
1411
1594
  preserve <spec> [--text <f>] keep an adopted item's original report
1595
+ comment <spec> --file <f> post a file onto the item as a comment
1412
1596
  assign <spec> --to <id> | --release stamp who is building it
1413
1597
  whoami [--set <id>] [--unset] who you are on Azure (cached)
1414
1598
  users [<query>] search the org's identities
@@ -1490,6 +1674,8 @@ async function specSync(rest, io = {}) {
1490
1674
  return kit.refuseRemovedVerb(out, PROGRAM, 'release')
1491
1675
  case 'preserve':
1492
1676
  return specSyncPreserve(dir, config, positional[0], flags, out)
1677
+ case 'comment':
1678
+ return specSyncComment(dir, config, positional[0], flags, out)
1493
1679
  case 'assign':
1494
1680
  return assignment.assign(dir, config, positional[0], flags, out)
1495
1681
  case 'whoami':
@@ -1524,6 +1710,7 @@ function parseArgs(args, sub) {
1524
1710
  '--stored': { kind: 'path' },
1525
1711
  '--remote': { kind: 'path' },
1526
1712
  '--text': { kind: 'path' },
1713
+ '--file': { kind: 'path' },
1527
1714
  '--workspace-states': { kind: 'path', name: 'workspaceStates' },
1528
1715
  '--skip-state-check': { kind: 'boolean', name: 'skipStateCheck' },
1529
1716
  '--via': { kind: 'string' },
@@ -149,6 +149,7 @@ function defaults() {
149
149
  azure: { ...DEFAULT_CONFIG.azure },
150
150
  mapping: { ...DEFAULT_CONFIG.mapping },
151
151
  states: { ...DEFAULT_CONFIG.states },
152
+ statesByType: {},
152
153
  stateAliases: {},
153
154
  intake: {
154
155
  tag: DEFAULT_CONFIG.intake.tag,
@@ -177,7 +178,7 @@ function defaults() {
177
178
  }
178
179
 
179
180
  const { isObject, stringList, assign } = kitConfig
180
- const { mergeStates, mergeFieldOwnership, mergePhaseMapping, mergeReleaseIgnorePaths, mergeKeyedFields } =
181
+ const { mergeStates, mergeStateOverrides, mergeFieldOwnership, mergePhaseMapping, mergeReleaseIgnorePaths, mergeKeyedFields } =
181
182
  kitConfig.makeMergeHelpers({
182
183
  configFile: CONFIG_FILE,
183
184
  ownership: OWNERSHIP,
@@ -203,7 +204,7 @@ function mergeConfig(base, parsed) {
203
204
  // Only the kinds a spec folder can actually be — an unknown key is
204
205
  // dropped rather than carried into `states` validation it can never pass.
205
206
  const byKind = {}
206
- for (const kind of ['feature', 'bug', 'hotfix', 'chore']) {
207
+ for (const kind of ['feature', 'bug', 'hotfix', 'chore', 'issue', 'incident']) {
207
208
  const value = parsed.azure.workItemTypeByKind[kind]
208
209
  if (typeof value === 'string' && value.trim()) byKind[kind] = value.trim()
209
210
  }
@@ -236,6 +237,7 @@ function mergeConfig(base, parsed) {
236
237
  }
237
238
 
238
239
  mergeStates(base, parsed)
240
+ mergeStateOverrides(base, parsed, 'statesByType')
239
241
 
240
242
  if (isObject(parsed.intake)) {
241
243
  assign(base.intake, parsed.intake, 'tag', '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,