@skitterbyte/skitterspec-azure-boards 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/MIGRATION.md +71 -0
- package/assets/core/azure-boards.config.json.example +1 -0
- package/assets/core/azure-boards.config.md +3 -1
- package/assets/core/env.config.md +1 -1
- package/assets/rules/spec-planning.md +52 -11
- package/assets/rules/spec-reports.md +28 -2
- package/assets/skills/no-spec/SKILL.md +2 -2
- package/assets/skills/spec/SKILL.md +47 -8
- package/assets/skills/spec-azure-setup/SKILL.md +3 -0
- package/assets/skills/spec-bug/SKILL.md +6 -2
- package/assets/skills/spec-complete/SKILL.md +39 -0
- package/assets/skills/spec-hotfix/SKILL.md +4 -0
- package/assets/skills/spec-incident/SKILL.md +142 -0
- package/assets/skills/spec-init/SKILL.md +2 -1
- package/assets/skills/spec-next/SKILL.md +2 -2
- package/package.json +1 -1
- package/src/cli.js +108 -3
- package/src/env/resolve.js +12 -4
- package/src/env/review.js +79 -0
- package/src/vendor/azure-boards/api.js +91 -10
- package/src/vendor/azure-boards/cli-sync.js +260 -36
- package/src/vendor/azure-boards/config.js +54 -16
- package/src/vendor/azure-boards/mcp.js +14 -3
- package/src/vendor/provider-kit/src/config.js +44 -0
- package/src/vendor/sync-core/index.js +4 -1
- package/src/vendor/sync-core/src/normalize.js +137 -16
|
@@ -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) {
|
|
@@ -153,25 +190,48 @@ function specKindOf(snapshotDir) {
|
|
|
153
190
|
const name = path.basename(String(snapshotDir || ''))
|
|
154
191
|
if (name.startsWith('bug-')) return 'bug'
|
|
155
192
|
if (name.startsWith('hotfix-')) return 'hotfix'
|
|
193
|
+
if (name.startsWith('chore-')) return 'chore'
|
|
194
|
+
if (name.startsWith('issue-')) return 'issue'
|
|
195
|
+
if (name.startsWith('incident-')) return 'incident'
|
|
156
196
|
return 'feature'
|
|
157
197
|
}
|
|
158
198
|
|
|
159
|
-
function applyOps({ adapter, config, out, kind = 'feature' }) {
|
|
199
|
+
function applyOps({ adapter, config, out, kind = 'feature', snapshotDir = null }) {
|
|
160
200
|
// The mint type for THIS spec's kind (its folder prefix), falling back to
|
|
161
201
|
// the one configured type. The twin search uses the same type, so a bug
|
|
162
202
|
// never refuses over a feature that happens to share its title.
|
|
163
203
|
const mintType =
|
|
164
204
|
(config.azure.workItemTypeByKind && config.azure.workItemTypeByKind[kind]) || config.azure.workItemType
|
|
165
|
-
|
|
166
|
-
|
|
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
|
|
167
225
|
if (!name) {
|
|
168
226
|
throw new Error(`no state configured for the "${bucket}" bucket — fix ${CONFIG_FILE} -> states`)
|
|
169
227
|
}
|
|
170
228
|
return name
|
|
171
229
|
}
|
|
172
|
-
const settle = async (idOrIdentifier, bucket) => {
|
|
230
|
+
const settle = async (idOrIdentifier, bucket, type) => {
|
|
173
231
|
if (!bucket) return
|
|
174
|
-
|
|
232
|
+
const name = stateFor(bucket, type)
|
|
233
|
+
if (name === null) return
|
|
234
|
+
await adapter.transitionTo(apiId(idOrIdentifier), name)
|
|
175
235
|
}
|
|
176
236
|
// Azure refuses the WHOLE patch over one bad `System.AssignedTo` value
|
|
177
237
|
// ("… is an unknown identity", live repro), which used to take the
|
|
@@ -191,9 +251,27 @@ function applyOps({ adapter, config, out, kind = 'feature' }) {
|
|
|
191
251
|
return result
|
|
192
252
|
}
|
|
193
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
|
+
}
|
|
194
269
|
return {
|
|
195
270
|
prevalidateStates: (buckets) => {
|
|
196
|
-
for (const bucket of buckets)
|
|
271
|
+
for (const bucket of buckets) {
|
|
272
|
+
stateFor(bucket, mintType)
|
|
273
|
+
stateFor(bucket, config.azure.childType)
|
|
274
|
+
}
|
|
197
275
|
},
|
|
198
276
|
searchTwin: (title) => adapter.searchIssues({ query: title, workItemType: mintType }),
|
|
199
277
|
twinAdvice: (twin, wanted, specName) =>
|
|
@@ -211,10 +289,12 @@ function applyOps({ adapter, config, out, kind = 'feature' }) {
|
|
|
211
289
|
assigneeId: issue && issue.assignee ? issue.assignee : undefined,
|
|
212
290
|
workItemType: mintType,
|
|
213
291
|
areaPath: config.azure.areaPath || undefined,
|
|
292
|
+
severity: severity != null ? severity : undefined,
|
|
214
293
|
},
|
|
215
|
-
(input) => adapter.createIssue(
|
|
294
|
+
(input) => skippingRefusedSeverity(input, (i) => adapter.createIssue(i)),
|
|
216
295
|
)
|
|
217
|
-
await settle(created.id, issue && issue.state)
|
|
296
|
+
await settle(created.id, issue && issue.state, mintType)
|
|
297
|
+
await relateToIncident(created.id)
|
|
218
298
|
return created
|
|
219
299
|
},
|
|
220
300
|
updateIssue: async (existing, issue) => {
|
|
@@ -223,10 +303,14 @@ function applyOps({ adapter, config, out, kind = 'feature' }) {
|
|
|
223
303
|
// Null is meaningful here — it is how Boards unassigns — so the key is
|
|
224
304
|
// forwarded whenever the plan carries it, never truthiness-tested.
|
|
225
305
|
if ('assignee' in issue) updates.assigneeId = issue.assignee ?? null
|
|
306
|
+
if (severity != null) updates.severity = severity
|
|
226
307
|
if (Object.keys(updates).length) {
|
|
227
|
-
await skippingRefusedAssignee(updates, (input) =>
|
|
308
|
+
await skippingRefusedAssignee(updates, (input) =>
|
|
309
|
+
skippingRefusedSeverity(input, (i) => adapter.updateIssue(apiId(existing.identifier), i)),
|
|
310
|
+
)
|
|
228
311
|
}
|
|
229
|
-
await settle(existing.identifier, issue.state)
|
|
312
|
+
await settle(existing.identifier, issue.state, mintType)
|
|
313
|
+
await relateToIncident(existing.identifier)
|
|
230
314
|
},
|
|
231
315
|
mintSubIssue: async (parentId, sub) => {
|
|
232
316
|
const created = await adapter.createSubIssue(apiId(parentId), {
|
|
@@ -235,7 +319,7 @@ function applyOps({ adapter, config, out, kind = 'feature' }) {
|
|
|
235
319
|
childType: config.azure.childType,
|
|
236
320
|
areaPath: config.azure.areaPath || undefined,
|
|
237
321
|
})
|
|
238
|
-
await settle(created.id, sub.state)
|
|
322
|
+
await settle(created.id, sub.state, config.azure.childType)
|
|
239
323
|
return created
|
|
240
324
|
},
|
|
241
325
|
updateSubIssue: async (sub) => {
|
|
@@ -243,7 +327,7 @@ function applyOps({ adapter, config, out, kind = 'feature' }) {
|
|
|
243
327
|
if (sub.name != null) updates.title = sub.name
|
|
244
328
|
if (sub.goal != null) updates.description = sub.goal
|
|
245
329
|
if (Object.keys(updates).length) await adapter.updateIssue(apiId(sub.id), updates)
|
|
246
|
-
await settle(sub.id, sub.state)
|
|
330
|
+
await settle(sub.id, sub.state, config.azure.childType)
|
|
247
331
|
},
|
|
248
332
|
}
|
|
249
333
|
}
|
|
@@ -259,6 +343,7 @@ function apiAdapterFor(config, flags) {
|
|
|
259
343
|
project: config.azure.project,
|
|
260
344
|
token: cred.token,
|
|
261
345
|
fetch: flags.fetch,
|
|
346
|
+
bodyFieldByType: config.azure.bodyFieldByType,
|
|
262
347
|
}),
|
|
263
348
|
}
|
|
264
349
|
}
|
|
@@ -361,18 +446,14 @@ const assignment = makeAssignmentCommands({
|
|
|
361
446
|
resolveIdentity: (config, env, deps) => resolveIdentity(config, env, deps),
|
|
362
447
|
resolveCredential: (config, env) => resolveCredential(config, env),
|
|
363
448
|
makeAdapter: (config, cred, flags) =>
|
|
364
|
-
makeApiAdapter({ orgUrl: config.azure.orgUrl, project: config.azure.project, token: cred.token, fetch: flags.fetch }),
|
|
449
|
+
makeApiAdapter({ orgUrl: config.azure.orgUrl, project: config.azure.project, token: cred.token, fetch: flags.fetch, bodyFieldByType: config.azure.bodyFieldByType }),
|
|
365
450
|
displayNameOf: (u) => displayNameOf(u),
|
|
366
451
|
usersOverMcp: 'search identities with core_get_identity_ids over MCP, or read them off the org\'s Users page',
|
|
367
452
|
})
|
|
368
453
|
|
|
369
|
-
//
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
// mint types are in the union too, so a `workItemTypeByKind` entry's states
|
|
373
|
-
// are validated before the first write, exactly like the base pair.
|
|
374
|
-
async function unionStates(adapter, config) {
|
|
375
|
-
const types = [
|
|
454
|
+
// Every configured type — the base pair plus the per-kind mint types.
|
|
455
|
+
function configuredTypes(config) {
|
|
456
|
+
return [
|
|
376
457
|
...new Set(
|
|
377
458
|
[
|
|
378
459
|
config.azure.workItemType,
|
|
@@ -381,9 +462,27 @@ async function unionStates(adapter, config) {
|
|
|
381
462
|
].filter(Boolean),
|
|
382
463
|
),
|
|
383
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)
|
|
384
483
|
const byName = new Map()
|
|
385
|
-
for (const
|
|
386
|
-
for (const s of
|
|
484
|
+
for (const states of Object.values(byType)) {
|
|
485
|
+
for (const s of states) {
|
|
387
486
|
if (!byName.has(s.name)) byName.set(s.name, s)
|
|
388
487
|
}
|
|
389
488
|
}
|
|
@@ -459,7 +558,7 @@ function companionCoverageNote(dir, config, snapshotDir, out) {
|
|
|
459
558
|
const rawField = parsed.branch && parsed.branch.identifierField
|
|
460
559
|
const field = typeof rawField === 'string' && rawField ? rawField : config.fields.identifier
|
|
461
560
|
|
|
462
|
-
const slug = path.basename(snapshotDir).replace(/^(feat|bug|hotfix)-/, '')
|
|
561
|
+
const slug = path.basename(snapshotDir).replace(/^(feat|bug|hotfix|chore|issue|incident)-/, '')
|
|
463
562
|
const basePath = `${config.sync.baseDir}/${identifier}.base.json`
|
|
464
563
|
const claimed = patterns.some((p) => {
|
|
465
564
|
if (typeof p !== 'string') return false
|
|
@@ -508,7 +607,7 @@ async function specSyncApply(dir, config, specArg, flags, out, err) {
|
|
|
508
607
|
snapshotDir,
|
|
509
608
|
plan,
|
|
510
609
|
adapter: cred.adapter,
|
|
511
|
-
ops: applyOps({ adapter: cred.adapter, config, out, kind: specKindOf(snapshotDir) }),
|
|
610
|
+
ops: applyOps({ adapter: cred.adapter, config, out, kind: specKindOf(snapshotDir), snapshotDir }),
|
|
512
611
|
forceNew: !!flags.forceNew,
|
|
513
612
|
program: PROGRAM,
|
|
514
613
|
})
|
|
@@ -767,16 +866,24 @@ async function specSyncStates(dir, config, flags, out) {
|
|
|
767
866
|
return 1
|
|
768
867
|
}
|
|
769
868
|
let states
|
|
869
|
+
let byType
|
|
770
870
|
try {
|
|
771
|
-
|
|
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()]
|
|
772
875
|
} catch (error) {
|
|
773
876
|
out.write(`${PROGRAM} states: ${error.message}\n`)
|
|
774
877
|
return 1
|
|
775
878
|
}
|
|
776
879
|
const names = states.map((s) => s.name)
|
|
777
880
|
if (flags.json) {
|
|
778
|
-
// The
|
|
779
|
-
|
|
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')
|
|
780
887
|
return 0
|
|
781
888
|
}
|
|
782
889
|
const catOf = new Map(states.map((s) => [s.name, s.category || null]))
|
|
@@ -808,6 +915,29 @@ async function specSyncStates(dir, config, flags, out) {
|
|
|
808
915
|
}
|
|
809
916
|
}
|
|
810
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
|
+
}
|
|
811
941
|
out.write(lines.join('\n') + '\n')
|
|
812
942
|
return 0
|
|
813
943
|
}
|
|
@@ -1015,6 +1145,49 @@ async function specSyncPreserve(dir, config, specArg, flags, out) {
|
|
|
1015
1145
|
}
|
|
1016
1146
|
}
|
|
1017
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
|
+
|
|
1018
1191
|
// ---------------------------------------------------------------------------
|
|
1019
1192
|
// Credentials: `status` is a READINESS check (exit 1 with none); `set`
|
|
1020
1193
|
// prompts with hidden input; `unset` removes the org's entry.
|
|
@@ -1185,7 +1358,7 @@ async function specSyncInitConfig(dir, flags, out) {
|
|
|
1185
1358
|
if (cred.ok) {
|
|
1186
1359
|
const adapter =
|
|
1187
1360
|
flags.adapter ||
|
|
1188
|
-
makeApiAdapter({ orgUrl: merged.azure.orgUrl, project: merged.azure.project, token: cred.token, fetch: flags.fetch })
|
|
1361
|
+
makeApiAdapter({ orgUrl: merged.azure.orgUrl, project: merged.azure.project, token: cred.token, fetch: flags.fetch, bodyFieldByType: merged.azure.bodyFieldByType })
|
|
1189
1362
|
let names = null
|
|
1190
1363
|
try {
|
|
1191
1364
|
names = (await unionStates(adapter, merged)).map((st) => st.name)
|
|
@@ -1300,25 +1473,72 @@ async function specSyncDoctor(dir, flags, out) {
|
|
|
1300
1473
|
if (flags.remoteCheck && cred.ok) {
|
|
1301
1474
|
const adapter =
|
|
1302
1475
|
flags.adapter ||
|
|
1303
|
-
makeApiAdapter({ orgUrl: config.azure.orgUrl, project: config.azure.project, token: cred.token, fetch: flags.fetch })
|
|
1476
|
+
makeApiAdapter({ orgUrl: config.azure.orgUrl, project: config.azure.project, token: cred.token, fetch: flags.fetch, bodyFieldByType: config.azure.bodyFieldByType })
|
|
1304
1477
|
try {
|
|
1305
1478
|
const viewer = await adapter.readViewer()
|
|
1306
1479
|
checks.push(row('remote', 'Azure reachable', 'ok', viewer ? `as ${viewer.name || viewer.id}` : 'yes'))
|
|
1307
|
-
|
|
1308
|
-
//
|
|
1309
|
-
//
|
|
1310
|
-
|
|
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
|
+
]
|
|
1311
1496
|
checks.push(
|
|
1312
1497
|
missing.length
|
|
1313
1498
|
? row(
|
|
1314
1499
|
'states',
|
|
1315
1500
|
'State names',
|
|
1316
1501
|
'broken',
|
|
1317
|
-
`not in
|
|
1318
|
-
`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)`,
|
|
1319
1504
|
)
|
|
1320
|
-
: row('states', 'State names', 'ok', 'every configured state exists'),
|
|
1505
|
+
: row('states', 'State names', 'ok', 'every configured state exists on its type'),
|
|
1321
1506
|
)
|
|
1507
|
+
// Every mapped type must exist, and carry the body field configured
|
|
1508
|
+
// for it — a missing type fails the first push, and a missing field
|
|
1509
|
+
// silently drops every Bug's body. NO ROW when nothing is mapped: a
|
|
1510
|
+
// line about an unconfigured surface accuses a healthy project.
|
|
1511
|
+
const mappedTypes = [
|
|
1512
|
+
...new Set([
|
|
1513
|
+
...Object.values(config.azure.workItemTypeByKind || {}),
|
|
1514
|
+
...Object.keys(config.azure.bodyFieldByType || {}),
|
|
1515
|
+
]),
|
|
1516
|
+
]
|
|
1517
|
+
if (mappedTypes.length) {
|
|
1518
|
+
const problems = []
|
|
1519
|
+
for (const type of mappedTypes) {
|
|
1520
|
+
const fields = await adapter.listTypeFields(type)
|
|
1521
|
+
if (fields == null) {
|
|
1522
|
+
problems.push(`type "${type}" is not in the project`)
|
|
1523
|
+
continue
|
|
1524
|
+
}
|
|
1525
|
+
const wanted = (config.azure.bodyFieldByType || {})[type]
|
|
1526
|
+
if (wanted && !fields.some((f) => f.toLowerCase() === wanted.toLowerCase())) {
|
|
1527
|
+
problems.push(`type "${type}" has no field ${wanted}`)
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
checks.push(
|
|
1531
|
+
problems.length
|
|
1532
|
+
? row(
|
|
1533
|
+
'types',
|
|
1534
|
+
'Mapped types',
|
|
1535
|
+
'broken',
|
|
1536
|
+
problems.join('; '),
|
|
1537
|
+
`create the type/field in the process, or fix ${CONFIG_FILE} -> azure.workItemTypeByKind / azure.bodyFieldByType`,
|
|
1538
|
+
)
|
|
1539
|
+
: row('types', 'Mapped types', 'ok', 'every mapped type exists and carries its body field'),
|
|
1540
|
+
)
|
|
1541
|
+
}
|
|
1322
1542
|
// The capability probe Decision 8 names: identity search is the op
|
|
1323
1543
|
// that fails first on a narrow token. A 401 here is a WARN, not
|
|
1324
1544
|
// broken — work item sync is whole without it; only `users` search
|
|
@@ -1372,6 +1592,7 @@ const USAGE = `Usage: skitterspec-azure-boards spec-sync <subcommand>
|
|
|
1372
1592
|
ref [<spec>] the Refs: trailer value for this branch
|
|
1373
1593
|
released [<range>] tickets a commit range contains
|
|
1374
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
|
|
1375
1596
|
assign <spec> --to <id> | --release stamp who is building it
|
|
1376
1597
|
whoami [--set <id>] [--unset] who you are on Azure (cached)
|
|
1377
1598
|
users [<query>] search the org's identities
|
|
@@ -1453,6 +1674,8 @@ async function specSync(rest, io = {}) {
|
|
|
1453
1674
|
return kit.refuseRemovedVerb(out, PROGRAM, 'release')
|
|
1454
1675
|
case 'preserve':
|
|
1455
1676
|
return specSyncPreserve(dir, config, positional[0], flags, out)
|
|
1677
|
+
case 'comment':
|
|
1678
|
+
return specSyncComment(dir, config, positional[0], flags, out)
|
|
1456
1679
|
case 'assign':
|
|
1457
1680
|
return assignment.assign(dir, config, positional[0], flags, out)
|
|
1458
1681
|
case 'whoami':
|
|
@@ -1487,6 +1710,7 @@ function parseArgs(args, sub) {
|
|
|
1487
1710
|
'--stored': { kind: 'path' },
|
|
1488
1711
|
'--remote': { kind: 'path' },
|
|
1489
1712
|
'--text': { kind: 'path' },
|
|
1713
|
+
'--file': { kind: 'path' },
|
|
1490
1714
|
'--workspace-states': { kind: 'path', name: 'workspaceStates' },
|
|
1491
1715
|
'--skip-state-check': { kind: 'boolean', name: 'skipStateCheck' },
|
|
1492
1716
|
'--via': { kind: 'string' },
|
|
@@ -45,12 +45,22 @@ const DEFAULT_CONFIG = Object.freeze({
|
|
|
45
45
|
// the Basic, Agile and CMMI backlogs drag-order; a Scrum process ranks by
|
|
46
46
|
// `Microsoft.VSTS.Common.BacklogPriority` instead.
|
|
47
47
|
backlogOrderField: 'Microsoft.VSTS.Common.StackRank',
|
|
48
|
-
// The mint type per SPEC KIND (`feature`/`bug`/`hotfix`, from the
|
|
49
|
-
// folder's prefix), falling back to `workItemType`. In Agile, Scrum
|
|
50
|
-
// CMMI a bug is a work item TYPE, so `/spec-bug` minting a User Story
|
|
48
|
+
// The mint type per SPEC KIND (`feature`/`bug`/`hotfix`/`chore`, from the
|
|
49
|
+
// spec folder's prefix), falling back to `workItemType`. In Agile, Scrum
|
|
50
|
+
// and CMMI a bug is a work item TYPE, so `/spec-bug` minting a User Story
|
|
51
51
|
// files it in the wrong backlog; `{ "bug": "Bug", "hotfix": "Bug" }` is
|
|
52
|
-
// the usual shape there.
|
|
52
|
+
// the usual shape there. `chore` wants a custom inherited type (create
|
|
53
|
+
// `Chore` and its states in the process first); unmapped it falls back to
|
|
54
|
+
// `workItemType`. Empty means one type for everything, as before.
|
|
53
55
|
workItemTypeByKind: Object.freeze({}),
|
|
56
|
+
// The field a TYPE's body is written to and read from, keyed by work item
|
|
57
|
+
// type name — `{ "Bug": "Microsoft.VSTS.TCM.ReproSteps" }` is the shape
|
|
58
|
+
// Agile/Scrum/CMMI want, because their Bug form does not show
|
|
59
|
+
// System.Description at all. Unmapped types keep System.Description. The
|
|
60
|
+
// mapping is symmetric (create, update, read-back, edited-hash compare):
|
|
61
|
+
// a write-only mapping would make `/spec-status` report every Bug as
|
|
62
|
+
// edited. Empty means System.Description everywhere, as before.
|
|
63
|
+
bodyFieldByType: Object.freeze({}),
|
|
54
64
|
}),
|
|
55
65
|
// A spec is a WORK ITEM; each phase a CHILD work item under a hierarchy
|
|
56
66
|
// link. `tasks` selects how the phase's checkboxes reach that child's
|
|
@@ -139,6 +149,7 @@ function defaults() {
|
|
|
139
149
|
azure: { ...DEFAULT_CONFIG.azure },
|
|
140
150
|
mapping: { ...DEFAULT_CONFIG.mapping },
|
|
141
151
|
states: { ...DEFAULT_CONFIG.states },
|
|
152
|
+
statesByType: {},
|
|
142
153
|
stateAliases: {},
|
|
143
154
|
intake: {
|
|
144
155
|
tag: DEFAULT_CONFIG.intake.tag,
|
|
@@ -167,7 +178,7 @@ function defaults() {
|
|
|
167
178
|
}
|
|
168
179
|
|
|
169
180
|
const { isObject, stringList, assign } = kitConfig
|
|
170
|
-
const { mergeStates, mergeFieldOwnership, mergePhaseMapping, mergeReleaseIgnorePaths, mergeKeyedFields } =
|
|
181
|
+
const { mergeStates, mergeStateOverrides, mergeFieldOwnership, mergePhaseMapping, mergeReleaseIgnorePaths, mergeKeyedFields } =
|
|
171
182
|
kitConfig.makeMergeHelpers({
|
|
172
183
|
configFile: CONFIG_FILE,
|
|
173
184
|
ownership: OWNERSHIP,
|
|
@@ -193,12 +204,22 @@ function mergeConfig(base, parsed) {
|
|
|
193
204
|
// Only the kinds a spec folder can actually be — an unknown key is
|
|
194
205
|
// dropped rather than carried into `states` validation it can never pass.
|
|
195
206
|
const byKind = {}
|
|
196
|
-
for (const kind of ['feature', 'bug', 'hotfix']) {
|
|
207
|
+
for (const kind of ['feature', 'bug', 'hotfix', 'chore', 'issue', 'incident']) {
|
|
197
208
|
const value = parsed.azure.workItemTypeByKind[kind]
|
|
198
209
|
if (typeof value === 'string' && value.trim()) byKind[kind] = value.trim()
|
|
199
210
|
}
|
|
200
211
|
base.azure.workItemTypeByKind = byKind
|
|
201
212
|
}
|
|
213
|
+
if (isObject(parsed.azure.bodyFieldByType)) {
|
|
214
|
+
// Keyed by TYPE name (open — any type a project invents), value a field
|
|
215
|
+
// reference name. Blank values are dropped rather than written as an
|
|
216
|
+
// empty field path.
|
|
217
|
+
const byType = {}
|
|
218
|
+
for (const [type, field] of Object.entries(parsed.azure.bodyFieldByType)) {
|
|
219
|
+
if (typeof field === 'string' && field.trim() && String(type).trim()) byType[String(type).trim()] = field.trim()
|
|
220
|
+
}
|
|
221
|
+
base.azure.bodyFieldByType = byType
|
|
222
|
+
}
|
|
202
223
|
// A trailing slash on the org would double up in every composed URL.
|
|
203
224
|
if (base.azure.orgUrl) base.azure.orgUrl = base.azure.orgUrl.replace(/\/+$/, '')
|
|
204
225
|
}
|
|
@@ -216,6 +237,7 @@ function mergeConfig(base, parsed) {
|
|
|
216
237
|
}
|
|
217
238
|
|
|
218
239
|
mergeStates(base, parsed)
|
|
240
|
+
mergeStateOverrides(base, parsed, 'statesByType')
|
|
219
241
|
|
|
220
242
|
if (isObject(parsed.intake)) {
|
|
221
243
|
assign(base.intake, parsed.intake, 'tag', 'string?')
|
|
@@ -299,16 +321,32 @@ function withRuntime(config) {
|
|
|
299
321
|
},
|
|
300
322
|
description(item) {
|
|
301
323
|
const fields = item && item.fields
|
|
302
|
-
if (fields && typeof fields === 'object'
|
|
303
|
-
//
|
|
304
|
-
//
|
|
305
|
-
//
|
|
306
|
-
const
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
324
|
+
if (fields && typeof fields === 'object') {
|
|
325
|
+
// The body field hangs off the item's TYPE (azure.bodyFieldByType),
|
|
326
|
+
// same resolution as the adapter's writes — the hash compare must
|
|
327
|
+
// read the field the push wrote or every mapped Bug reads as edited.
|
|
328
|
+
const type = String(fields['System.WorkItemType'] || '').toLowerCase()
|
|
329
|
+
const mapped = Object.entries(config.azure.bodyFieldByType || {}).find(
|
|
330
|
+
([t]) => t.toLowerCase() === type,
|
|
331
|
+
)
|
|
332
|
+
let field = mapped ? mapped[1] : 'System.Description'
|
|
333
|
+
// An empty mapped field falls back to System.Description — an item
|
|
334
|
+
// minted before the mapping holds its body there (same rule as the
|
|
335
|
+
// adapter's read side).
|
|
336
|
+
if (mapped && (fields[field] == null || fields[field] === '') && fields['System.Description'] != null) {
|
|
337
|
+
field = 'System.Description'
|
|
338
|
+
}
|
|
339
|
+
if (field in fields) {
|
|
340
|
+
// null IS an answer on this branch: the field was fetched and the
|
|
341
|
+
// description is genuinely empty — clearing one is an edit, not a
|
|
342
|
+
// cannot-tell.
|
|
343
|
+
const d = fields[field]
|
|
344
|
+
if (d == null) return ''
|
|
345
|
+
const text = String(d)
|
|
346
|
+
const fmt = item.multilineFieldsFormat && item.multilineFieldsFormat[field]
|
|
347
|
+
if (fmt && String(fmt).toLowerCase() === 'markdown') return text
|
|
348
|
+
return looksLikeHtml(text) ? htmlToText(text) : text
|
|
349
|
+
}
|
|
312
350
|
}
|
|
313
351
|
return item && typeof item.description === 'string' ? item.description : undefined
|
|
314
352
|
},
|
|
@@ -70,7 +70,18 @@ function discoverAzure(toolNames) {
|
|
|
70
70
|
* shapes the engine consumes. Ops the server cannot express are absent — the
|
|
71
71
|
* consumer feature-detects, exactly as with the API adapter's extras.
|
|
72
72
|
*/
|
|
73
|
-
function makeAdapter({ tools, call, orgUrl, project }) {
|
|
73
|
+
function makeAdapter({ tools, call, orgUrl, project, bodyFieldByType = {} }) {
|
|
74
|
+
// Same resolution as the REST adapter: the field a type's body lives in,
|
|
75
|
+
// System.Description unless azure.bodyFieldByType names one, matched
|
|
76
|
+
// case-insensitively. An MCP update cannot resolve the type (the generic
|
|
77
|
+
// update takes raw fields), so only the creates map here; the REST
|
|
78
|
+
// transport is the one that covers updates.
|
|
79
|
+
const bodyFields = Object.entries(bodyFieldByType || {}).map(([t, f]) => [String(t).toLowerCase(), f])
|
|
80
|
+
const bodyFieldFor = (workItemType) => {
|
|
81
|
+
const want = String(workItemType || '').toLowerCase()
|
|
82
|
+
const hit = bodyFields.find(([t]) => t === want)
|
|
83
|
+
return hit ? hit[1] : 'System.Description'
|
|
84
|
+
}
|
|
74
85
|
const org = String(orgUrl || '').replace(/\/+$/, '')
|
|
75
86
|
const urlOf = (id) => (org && project ? `${org}/${encodeURIComponent(project)}/_workitems/edit/${id}` : null)
|
|
76
87
|
const normalize = (raw) => {
|
|
@@ -96,7 +107,7 @@ function makeAdapter({ tools, call, orgUrl, project }) {
|
|
|
96
107
|
action: 'create',
|
|
97
108
|
project,
|
|
98
109
|
workItemType,
|
|
99
|
-
fields: { 'System.Title': title,
|
|
110
|
+
fields: { 'System.Title': title, [bodyFieldFor(workItemType)]: description },
|
|
100
111
|
format: 'markdown',
|
|
101
112
|
}),
|
|
102
113
|
)
|
|
@@ -107,7 +118,7 @@ function makeAdapter({ tools, call, orgUrl, project }) {
|
|
|
107
118
|
project,
|
|
108
119
|
parentId: Number(parentId),
|
|
109
120
|
workItemType: childType,
|
|
110
|
-
fields: { 'System.Title': title,
|
|
121
|
+
fields: { 'System.Title': title, [bodyFieldFor(childType)]: description },
|
|
111
122
|
format: 'markdown',
|
|
112
123
|
}),
|
|
113
124
|
)
|