@skitterbyte/skitterspec-azure-boards 2.11.0 → 2.13.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.
@@ -0,0 +1,250 @@
1
+ 'use strict'
2
+
3
+ /**
4
+ * The morning half of the ta-da list (feat-spec-todo, phase 2): where each
5
+ * project was left on the last day with any activity, and what is ahead. It
6
+ * reads the same digest `skitterspec tada` does — once for the lookback, once
7
+ * for the day it found — so the two can never disagree about what happened.
8
+ * Pure: every input arrives already read.
9
+ */
10
+
11
+ const fs = require('node:fs')
12
+ const path = require('node:path')
13
+
14
+ const { localDay } = require('./window.js')
15
+ const { waitingPasses, readGate, gateState } = require('../env/review.js')
16
+
17
+ // Far enough to bridge a long weekend or a week away; past it, "where did I
18
+ // leave off" has no useful answer and the report says so.
19
+ const LOOKBACK_DAYS = 14
20
+
21
+ function daysBefore(d, n) {
22
+ return new Date(d.getFullYear(), d.getMonth(), d.getDate() - n)
23
+ }
24
+
25
+ /** Every instant a digest saw something happen: prompts, sessions, commits, moves. */
26
+ function activityTimes(digest) {
27
+ const times = []
28
+ for (const p of digest.projects) {
29
+ for (const g of p.groups) {
30
+ for (const s of g.sessions) {
31
+ times.push(s.start, s.end)
32
+ for (const pr of s.prompts) times.push(pr.at)
33
+ }
34
+ for (const c of g.commits) times.push(c.at)
35
+ for (const e of g.events) times.push(e.at)
36
+ }
37
+ }
38
+ return times.filter(Boolean)
39
+ }
40
+
41
+ /**
42
+ * The local midnight of the most recent day before `todayStart` with any
43
+ * activity, at most `lookback` days back — so Monday reads Friday and a day
44
+ * off is skipped. Null when nothing falls in the lookback.
45
+ *
46
+ * @param {string[]} times ISO instants (`activityTimes`)
47
+ * @param {Date} todayStart local midnight today
48
+ */
49
+ function lastActiveDay(times, todayStart, lookback = LOOKBACK_DAYS) {
50
+ const floor = daysBefore(todayStart, lookback).getTime()
51
+ const end = todayStart.getTime()
52
+ let best = null
53
+ for (const t of times) {
54
+ const ms = Date.parse(t)
55
+ if (Number.isNaN(ms) || ms < floor || ms >= end) continue
56
+ if (best === null || ms > best) best = ms
57
+ }
58
+ if (best === null) return null
59
+ const d = new Date(best)
60
+ return new Date(d.getFullYear(), d.getMonth(), d.getDate())
61
+ }
62
+
63
+ const EVENT = { written: 'written', started: 'started', completed: 'completed', cancelled: 'cancelled' }
64
+ const eventText = (e) => (e.kind === 'phase-done' ? `phase ${e.phase} done` : EVENT[e.kind] || e.kind)
65
+
66
+ /**
67
+ * Where one group was left: its last move or commit, whichever came later —
68
+ * a commit after a move is the newer fact. Null when the group only has
69
+ * sessions or an in-flight row.
70
+ */
71
+ function leftOf(g) {
72
+ const last = [
73
+ ...g.events.map((e) => ({ at: e.at, text: eventText(e) })),
74
+ ...g.commits.map((c) => ({ at: c.at, text: `${c.sha} ${c.subject}` })),
75
+ ].sort((a, b) => Date.parse(a.at) - Date.parse(b.at))
76
+ return last.length ? last[last.length - 1].text : null
77
+ }
78
+
79
+ // The last thing typed in the group's last session — what was on the
80
+ // person's mind when they stopped.
81
+ function lastPrompt(g) {
82
+ const s = g.sessions[g.sessions.length - 1]
83
+ const p = s && s.prompts[s.prompts.length - 1]
84
+ return p ? `${p.command ? `${p.command} ` : ''}${p.text}`.trim() : null
85
+ }
86
+
87
+ /**
88
+ * What stands in a project's way, read only for the specs in flight there: a
89
+ * pass waiting on the review page, or a gate armed by a phase that ended. A
90
+ * pass for a spec no longer in flight is an old one nobody is waiting on, and
91
+ * is left out rather than reported as a blocker.
92
+ *
93
+ * @param {object} a
94
+ * - `specs` the project's in-flight spec names
95
+ * - `passes` `waitingPasses(...).passes`
96
+ * - `gates` `{ [spec]: gateState(...) }`; a missing or `unknown` state is
97
+ * cannot-tell, and says nothing
98
+ */
99
+ function blockersFrom({ specs, passes = [], gates = {} }) {
100
+ const want = new Set(specs)
101
+ const out = []
102
+ for (const p of passes) {
103
+ if (want.has(p.spec)) out.push({ spec: p.spec, kind: 'verdict', verdict: p.verdict, code: p.code, at: p.at })
104
+ }
105
+ for (const spec of specs) {
106
+ const g = gates[spec]
107
+ if (g && g.state === 'armed') out.push({ spec, kind: 'gate', phase: g.gate ? g.gate.phase : null })
108
+ }
109
+ return out
110
+ }
111
+
112
+ /**
113
+ * `blockersFrom`, read off one repo's review store. A store that does not
114
+ * exist — a repo that never rendered a review — is nothing in the way, not a
115
+ * failure; an unreadable gate is `gateState`'s cannot-tell and says nothing.
116
+ *
117
+ * @param {string} reviews the repo's reviews dir (`<state dir>/reviews`)
118
+ * @param {string[]} specs its in-flight spec names
119
+ * @param {boolean} [required] `review.required`; false opts the gates out
120
+ */
121
+ function readBlockers(reviews, specs, required) {
122
+ if (!fs.existsSync(reviews)) return []
123
+ const gates = {}
124
+ for (const spec of specs) gates[spec] = gateState({ ...readGate(path.join(reviews, `${spec}.html`), spec), required })
125
+ return blockersFrom({ specs, passes: waitingPasses(reviews).passes, gates })
126
+ }
127
+
128
+ /**
129
+ * The to-do: the left-off day's projects, each open spec reduced to where it
130
+ * was left, the specs that day finished by name, today's activity so far, and
131
+ * what is blocking each project.
132
+ *
133
+ * @param {object} a
134
+ * - `leftOff` the digest for the left-off day, or null when none
135
+ * - `leftOffDay` that day's local midnight, or null
136
+ * - `today` today's digest so far
137
+ * - `home` the home project as a digest project (in-flight groups
138
+ * only) for when neither digest lists it, else null
139
+ * - `blockersFor` `(repo, specs) => blockers` — read only for a repo
140
+ */
141
+ function buildTodo({ leftOff, leftOffDay, today, home = null, blockersFor = () => [] }) {
142
+ const projects = new Map()
143
+ const keyOf = (p) => p.repo || p.name
144
+ const entry = (p) => {
145
+ const k = keyOf(p)
146
+ if (!projects.has(k)) projects.set(k, { repo: p.repo, name: p.name, here: false, groups: [], finished: [], today: { commits: 0, moves: 0 } })
147
+ const e = projects.get(k)
148
+ if (p.here) e.here = true
149
+ return e
150
+ }
151
+
152
+ for (const p of leftOff ? leftOff.projects : []) {
153
+ const e = entry(p)
154
+ for (const g of p.groups) {
155
+ // The morning wants what is still open. A spec the day finished is said
156
+ // once, by name; work on no spec is history, not a place to pick up.
157
+ if (!g.inFlight) {
158
+ if (g.spec && g.events.some((ev) => ev.kind === 'completed' || ev.kind === 'cancelled')) e.finished.push(g.spec)
159
+ continue
160
+ }
161
+ const left = leftOf(g)
162
+ const prompt = lastPrompt(g)
163
+ e.groups.push({ spec: g.spec, branch: g.branch, ...(g.ticket ? { ticket: g.ticket } : {}), left, prompt, inFlight: g.inFlight })
164
+ }
165
+ }
166
+ for (const p of today.projects) {
167
+ const e = entry(p)
168
+ const known = new Set(e.groups.map((g) => g.spec).filter(Boolean))
169
+ for (const g of p.groups) {
170
+ e.today.commits += g.commits.length
171
+ e.today.moves += g.events.length
172
+ // What is ahead in a project the left-off day did not touch.
173
+ if (g.spec && g.inFlight && !known.has(g.spec)) {
174
+ e.groups.push({ spec: g.spec, branch: g.branch, ...(g.ticket ? { ticket: g.ticket } : {}), left: null, prompt: null, inFlight: g.inFlight })
175
+ }
176
+ }
177
+ }
178
+ if (home && !projects.has(keyOf(home))) {
179
+ const e = entry({ ...home, here: true })
180
+ for (const g of home.groups) if (g.inFlight) e.groups.push({ spec: g.spec, branch: null, left: null, prompt: null, inFlight: g.inFlight })
181
+ }
182
+ // Ideas are counted for home only: the count is this project's to act on,
183
+ // and asking every project's tracker would turn a morning read into a crawl.
184
+ // Null — could not ask — and zero both print nothing.
185
+ if (home && home.ideas > 0) projects.get(keyOf(home)).ideas = home.ideas
186
+
187
+ const list = [...projects.values()]
188
+ .map((e) => {
189
+ const specs = e.groups.filter((g) => g.spec && g.inFlight).map((g) => g.spec)
190
+ return { ...e, blocked: e.repo && specs.length ? blockersFor(e.repo, specs) : [] }
191
+ })
192
+ .filter((e) => e.groups.length || e.finished.length || e.today.commits || e.today.moves || e.ideas)
193
+ // The home project first: it is the one this session acts on.
194
+ .sort((a, b) => (a.here !== b.here ? (a.here ? -1 : 1) : a.name.localeCompare(b.name)))
195
+
196
+ return {
197
+ kind: 'todo',
198
+ leftOff: leftOffDay ? { day: localDay(leftOffDay) } : null,
199
+ lookbackDays: LOOKBACK_DAYS,
200
+ ...(today.category ? { category: today.category } : {}),
201
+ projects: list,
202
+ notes: [...new Set([...(leftOff ? leftOff.notes : []), ...today.notes])],
203
+ }
204
+ }
205
+
206
+ const ageText = (at, now) => {
207
+ const ms = now - Date.parse(at)
208
+ if (Number.isNaN(ms) || ms < 0) return ''
209
+ const h = Math.floor(ms / 3_600_000)
210
+ return h < 24 ? ` · ${h}h` : ` · ${Math.floor(h / 24)}d`
211
+ }
212
+
213
+ function blockedText(b, now) {
214
+ if (b.kind === 'gate') return `${b.spec} — gate armed${b.phase ? `, phase ${b.phase}` : ''}: a verdict is owed`
215
+ return `${b.spec} — ${b.verdict || 'a'} verdict waiting (${b.code}${b.at ? ageText(b.at, now) : ''})`
216
+ }
217
+
218
+ /**
219
+ * The to-do as text — the same markers as `tada`, plus `left:` for where a
220
+ * group stopped, `finished:` for the specs that day closed, `blocked:` for what stands in a project's way, and `today:`
221
+ * for what has happened since midnight.
222
+ */
223
+ function formatTodo(todo, now = new Date()) {
224
+ const scope = todo.category ? ` · ${todo.category}` : ''
225
+ const head = todo.leftOff
226
+ ? `todo: left off ${todo.leftOff.label || todo.leftOff.day} · today ${todo.todayLabel || ''}`.trimEnd()
227
+ : `todo: nothing in the last ${todo.lookbackDays} days · today ${todo.todayLabel || ''}`.trimEnd()
228
+ const out = [`${head}${scope}`]
229
+ if (todo.projects.length === 0) out.push(' nothing in flight.')
230
+ for (const p of todo.projects) {
231
+ out.push('', `${p.name}${p.here ? ' (here)' : ''}${p.repo ? ` (${p.repo})` : ''}`)
232
+ for (const g of p.groups) {
233
+ out.push(` ${g.spec ? `${g.spec}${g.ticket ? ` [${g.ticket.id}]` : ''}` : `${g.branch || '(no branch)'} — no spec`}`)
234
+ if (g.left) out.push(` left: ${g.left}`)
235
+ if (g.prompt) out.push(` - ${g.prompt}`)
236
+ if (g.inFlight) out.push(` in flight: ${g.inFlight.detail}${g.inFlight.next ? ` · next: ${g.inFlight.next}` : ''}`)
237
+ }
238
+ if (p.finished.length) out.push(` finished: ${p.finished.join(', ')}`)
239
+ for (const b of p.blocked) out.push(` blocked: ${blockedText(b, now)}`)
240
+ if (p.ideas) out.push(` ideas: ${p.ideas} waiting · /spec-idea lists them`)
241
+ if (p.today.commits || p.today.moves) {
242
+ const parts = [p.today.commits && `${p.today.commits} commit${p.today.commits === 1 ? '' : 's'}`, p.today.moves && `${p.today.moves} move${p.today.moves === 1 ? '' : 's'}`]
243
+ out.push(` today: ${parts.filter(Boolean).join(', ')}`)
244
+ }
245
+ }
246
+ for (const n of todo.notes) out.push('', n)
247
+ return out.join('\n') + '\n'
248
+ }
249
+
250
+ module.exports = { LOOKBACK_DAYS, activityTimes, lastActiveDay, leftOf, blockersFrom, readBlockers, buildTodo, formatTodo, blockedText }
@@ -240,6 +240,7 @@ function makeApiAdapter({ orgUrl, project, token, fetch: fetchImpl, sleep, maxRe
240
240
  add('/fields/Microsoft.VSTS.Common.Severity', input.severity)
241
241
  }
242
242
  if (input.areaPath) add('/fields/System.AreaPath', input.areaPath)
243
+ if (input.tags && input.tags.length) add('/fields/System.Tags', input.tags.join('; '))
243
244
  return ops
244
245
  }
245
246
 
@@ -298,11 +299,11 @@ function makeApiAdapter({ orgUrl, project, token, fetch: fetchImpl, sleep, maxRe
298
299
  return item
299
300
  },
300
301
 
301
- async createIssue({ title, description, assigneeId, workItemType, areaPath, severity }) {
302
+ async createIssue({ title, description, assigneeId, workItemType, areaPath, severity, tags }) {
302
303
  const created = await request(
303
304
  'POST',
304
305
  `${projectBase}/wit/workitems/$${encodeURIComponent(workItemType)}`,
305
- { body: itemPatch({ title, description, assigneeId, areaPath, severity }, bodyFieldFor(workItemType)), patch: true },
306
+ { body: itemPatch({ title, description, assigneeId, areaPath, severity, tags }, bodyFieldFor(workItemType)), patch: true },
306
307
  )
307
308
  if (!created || created.id == null) throw new Error('Azure DevOps returned no work item for the create')
308
309
  return { id: String(created.id), identifier: identifierOf(created.id), url: urlOf(created.id) }
@@ -451,7 +452,7 @@ function makeApiAdapter({ orgUrl, project, token, fetch: fetchImpl, sleep, maxRe
451
452
  // `states` limits to those state names; `orderBy` is a field reference to
452
453
  // sort by, ascending — `list --next` passes the backlog's rank field, and
453
454
  // WIQL returns ids in that order, which `batchRead` is then made to keep.
454
- async searchIssues({ query, workItemType, assignedTo = null, states = null, orderBy = null, limit = 50 }) {
455
+ async searchIssues({ query, workItemType, assignedTo = null, states = null, orderBy = null, limit = 50, tag = null }) {
455
456
  const q = (v) => `'${String(v).replace(/'/g, "''")}'`
456
457
  const quoted = String(query || '').replace(/'/g, "''")
457
458
  const clauses = [
@@ -460,6 +461,7 @@ function makeApiAdapter({ orgUrl, project, token, fetch: fetchImpl, sleep, maxRe
460
461
  quoted ? `[System.Title] CONTAINS '${quoted}'` : null,
461
462
  assignedTo ? `[System.AssignedTo] = ${q(assignedTo)}` : null,
462
463
  states && states.length ? `[System.State] IN (${states.map(q).join(', ')})` : null,
464
+ tag ? `[System.Tags] CONTAINS ${q(tag)}` : null,
463
465
  ].filter(Boolean)
464
466
  const order = orderBy && /^[A-Za-z0-9_.]+$/.test(orderBy) ? ` ORDER BY [${orderBy}] ASC` : ''
465
467
  const raw = await request('POST', `${projectBase}/wit/wiql`, {
@@ -393,6 +393,112 @@ function applyOps({ adapter, config, out, kind = 'feature', snapshotDir = null }
393
393
  }
394
394
  }
395
395
 
396
+ // `idea add|list|drop` — the store `skitterspec idea` hands Azure Boards: a
397
+ // work item of `azure.workItemType` tagged `intake.ideaTag`, created with NO
398
+ // area path, so it lands at the project root and out of the spec area. `/spec
399
+ // <id>` adopts one like any other item, which is why an adopted one drops out
400
+ // of `list`.
401
+ //
402
+ // "Open" is read from the type's own state CATEGORIES, never from a list of
403
+ // state names: Basic, Agile, Scrum and CMMI spell Done and Removed differently.
404
+ // Without the API a capture REFUSES (exit 1) and hands the text back; a listing
405
+ // exits 0 with `count: null`, because zero ideas and "could not ask" differ.
406
+ async function specSyncIdea(dir, config, positional, flags, out) {
407
+ const [verb, ...words] = positional
408
+ const tag = config.intake.ideaTag
409
+ const type = config.azure.workItemType
410
+ const text = words.join(' ')
411
+ const say = (json, lines) => out.write(flags.json ? JSON.stringify(json, null, 2) + '\n' : lines.join('\n') + '\n')
412
+ const refuse = (reason, extra = {}) => {
413
+ const back = verb === 'add' && text ? `\n your idea, so nothing is lost:\n ${text.replace(/\n/g, '\n ')}` : ''
414
+ say({ ok: false, store: 'azure-boards', refused: reason, ...extra }, [`${PROGRAM} idea: ${reason}${back}`])
415
+ return 1
416
+ }
417
+ if (!['add', 'list', 'drop'].includes(verb)) {
418
+ out.write(`Usage: ${PROGRAM} idea add <text> | list [--count] | drop <id> [--reason <why>] [--json]\n`)
419
+ return verb ? 1 : 0
420
+ }
421
+ if (!tag) return refuse('intake.ideaTag is empty — an idea is a work item carrying that tag, so set one')
422
+
423
+ const cred = apiAdapterFor(config, flags)
424
+ if (kit.resolveTransport(flags, config, cred.ok) === 'mcp' || !cred.ok) {
425
+ const why = cred.ok ? 'pass --via api' : cred.error.split('\n')[0]
426
+ if (verb === 'list') {
427
+ say({ store: 'azure-boards', count: null, ideas: null }, [`${PROGRAM} idea: needs the API transport — ${why}`])
428
+ return 0
429
+ }
430
+ return refuse(`needs the API transport — ${why}; nothing was written`, verb === 'add' ? { text } : {})
431
+ }
432
+ const az = cred.adapter
433
+
434
+ const categories = async () => {
435
+ const states = await az.listIssueStates(type)
436
+ const closed = (s) => /^(completed|removed)$/i.test(String(s.category || ''))
437
+ return { open: states.filter((s) => !closed(s)).map((s) => s.name), states }
438
+ }
439
+ const openIdeas = async () => {
440
+ const { open } = await categories()
441
+ const claimed = new Set(listSpecs(dir, config).map((s) => s.identifier).filter(Boolean))
442
+ const items = await az.searchIssues({ workItemType: type, tag, states: open, limit: 200 })
443
+ return items.filter((i) => !claimed.has(i.identifier))
444
+ }
445
+
446
+ try {
447
+ if (verb === 'add') {
448
+ const lines = text.replace(/\r\n/g, '\n').split('\n')
449
+ const at = lines.findIndex((l) => l.trim())
450
+ if (at === -1) return refuse('nothing to capture — give the idea some text')
451
+ const title = lines[at].trim()
452
+ const description = lines.slice(at + 1).join('\n').trim()
453
+ const made = await az.createIssue({ title, description, workItemType: type, tags: [tag] })
454
+ say({ ok: true, store: 'azure-boards', action: 'add', identifier: made.identifier, url: made.url, title }, [
455
+ `${PROGRAM} idea: filed ${made.identifier} "${title}" (${type}, tagged "${tag}", no area path)`,
456
+ ` url: ${made.url}`,
457
+ ` promote: /spec ${made.identifier}`,
458
+ ])
459
+ return 0
460
+ }
461
+
462
+ if (verb === 'list') {
463
+ const ideas = (await openIdeas()).map((i) => ({ identifier: i.identifier, title: i.title, promote: `/spec ${i.identifier}` }))
464
+ if (flags.count) {
465
+ say({ store: 'azure-boards', count: ideas.length }, [String(ideas.length)])
466
+ return 0
467
+ }
468
+ say(
469
+ { store: 'azure-boards', tag, ideas },
470
+ ideas.length
471
+ ? [`${PROGRAM} idea: "${tag}"`, ...ideas.map((i) => ` ${i.identifier}\t${i.title || ''}`)]
472
+ : [`${PROGRAM} idea: nothing waiting under "${tag}"`],
473
+ )
474
+ return 0
475
+ }
476
+
477
+ // drop. Being in the open-ideas listing is the positive signal that the
478
+ // reference IS an idea; anything else is refused and left alone.
479
+ const ref = String(words[0] || '').replace(/^#/, '')
480
+ if (!ref) return refuse('name the idea to drop — `idea list` shows them')
481
+ const item = (await openIdeas()).find((i) => i.id === ref || i.identifier === words[0])
482
+ if (!item) return refuse(`${words[0]} is not an open idea tagged "${tag}" — left alone`)
483
+ const { states } = await categories()
484
+ const target = states.find((s) => /^removed$/i.test(String(s.category || ''))) || states.find((s) => /^completed$/i.test(String(s.category || '')))
485
+ if (!target) return refuse(`${type} has no Removed or Completed state to move the idea to`)
486
+ const why = flags.reason && String(flags.reason).trim() ? String(flags.reason).trim() : 'no reason given'
487
+ await az.createComment(item.id, `Dropped as an idea: ${why}`)
488
+ await az.transitionTo(item.id, target.name)
489
+ say({ ok: true, store: 'azure-boards', action: 'drop', identifier: item.identifier, title: item.title, reason: why }, [
490
+ `${PROGRAM} idea: dropped ${item.identifier} "${item.title || ''}" — moved to ${target.name} (${why})`,
491
+ ])
492
+ return 0
493
+ } catch (error) {
494
+ if (verb === 'list') {
495
+ say({ store: 'azure-boards', count: null, ideas: null }, [`${PROGRAM} idea: ${error.message}`])
496
+ return 1
497
+ }
498
+ return refuse(`Azure DevOps refused — ${error.message}`, verb === 'add' ? { text } : {})
499
+ }
500
+ }
501
+
396
502
  function apiAdapterFor(config, flags) {
397
503
  if (flags.adapter) return { ok: true, adapter: flags.adapter }
398
504
  const cred = resolveCredential(config, flags.env || process.env)
@@ -655,10 +761,15 @@ function companionCoverageNote(dir, config, snapshotDir, out) {
655
761
  }
656
762
 
657
763
  async function specSyncApply(dir, config, specArg, flags, out, err) {
658
- if (!flags.plan && !flags.all) {
764
+ if (!flags.plan && !flags.all && !flags.sendHeld) {
659
765
  out.write(`${PROGRAM} apply: pass --plan <file> (from \`plan --json\`), or --all <bucket>\n`)
660
766
  return 1
661
767
  }
768
+ const held = kit.heldFlags(flags, PROGRAM)
769
+ if (held.error) {
770
+ out.write(held.error + '\n')
771
+ return 1
772
+ }
662
773
  const cred = apiAdapterFor(config, flags)
663
774
  const transport = kit.resolveTransport(flags, config, cred.ok)
664
775
  if (transport === 'mcp') {
@@ -672,6 +783,8 @@ async function specSyncApply(dir, config, specArg, flags, out, err) {
672
783
  ' create/update/add_child), then stamp the returned ids with\n' +
673
784
  ' `spec-sync stamp` and record with `spec-sync record`.\n',
674
785
  )
786
+ const heldNote = kit.heldOverMcp(held, PROGRAM)
787
+ if (heldNote) out.write(heldNote + '\n')
675
788
  return 0
676
789
  }
677
790
  if (!cred.ok) {
@@ -688,6 +801,8 @@ async function specSyncApply(dir, config, specArg, flags, out, err) {
688
801
  adapter: cred.adapter,
689
802
  ops: applyOps({ adapter: cred.adapter, config, out, kind: specKindOf(snapshotDir), snapshotDir }),
690
803
  forceNew: !!flags.forceNew,
804
+ holdState: held.holdState,
805
+ sendHeld: held.sendHeld,
691
806
  program: PROGRAM,
692
807
  })
693
808
 
@@ -724,13 +839,19 @@ async function specSyncApply(dir, config, specArg, flags, out, err) {
724
839
  const snapshotDir = resolveOrExit(specArg, dir, out)
725
840
  if (!snapshotDir) return 1
726
841
  let plan
727
- try {
728
- plan = JSON.parse(fs.readFileSync(flags.plan, 'utf-8'))
729
- } catch (error) {
730
- out.write(`${PROGRAM} apply: cannot read --plan: ${error.message}\n`)
731
- return 1
842
+ if (!flags.plan) {
843
+ // --send-held computes its own. After the merge it is normally empty, and
844
+ // that empty plan is what tells apply that run 1 held the state.
845
+ plan = push({ dir, snapshotDir, identifier: specIdentifier(snapshotDir, config), config }).plan
846
+ } else {
847
+ try {
848
+ plan = JSON.parse(fs.readFileSync(flags.plan, 'utf-8'))
849
+ } catch (error) {
850
+ out.write(`${PROGRAM} apply: cannot read --plan: ${error.message}\n`)
851
+ return 1
852
+ }
732
853
  }
733
- if (isEmptyPlan(plan)) {
854
+ if (!held.sendHeld && isEmptyPlan(plan)) {
734
855
  out.write(`${PROGRAM} apply: empty plan — nothing to do\n`)
735
856
  return 0
736
857
  }
@@ -823,10 +944,13 @@ async function specSyncStamp(dir, config, specArg, flags, out) {
823
944
  return 0
824
945
  }
825
946
 
826
- function specSyncRecord(dir, config, specArg, out) {
947
+ function specSyncRecord(dir, config, specArg, flags, out) {
827
948
  const snapshotDir = resolveOrExit(specArg, dir, out)
828
949
  if (!snapshotDir) return 1
829
- const file = recordPush({ dir, snapshotDir, identifier: specIdentifier(snapshotDir, config), config })
950
+ // --held: the hand-applied twin of `apply --hold-state` — the state was left
951
+ // out on purpose, and is recorded as sent so run 2 rewrites nothing.
952
+ const sent = flags && flags.held ? { issue: true, subIssues: new Set() } : null
953
+ const file = recordPush({ dir, snapshotDir, identifier: specIdentifier(snapshotDir, config), config, sent })
830
954
  out.write(`${PROGRAM} record: snapshot written — ${path.relative(dir, file).split(path.sep).join('/')}\n`)
831
955
  return 0
832
956
  }
@@ -1786,16 +1910,18 @@ const USAGE = `Usage: skitterspec-azure-boards spec-sync <subcommand>
1786
1910
  normalize <spec> print the local projection as JSON
1787
1911
  plan <spec> --workspace-states <f> what a push would change (dry, JSON)
1788
1912
  apply <spec> --plan <f> | --all <b> apply a plan over the API
1913
+ apply <spec> --hold-state | --send-held PR-mode completion: hold Done for run 2, then send it
1789
1914
  restate <spec> | --all <b> resend child states to today's map (dry)
1790
1915
  [--parents] [--apply] include the spec item; write the moves
1791
1916
  stamp <spec> --issue AB#n [--sub r=n] write returned ids into the spec
1792
- record <spec> write the last-pushed snapshot
1917
+ record <spec> [--held] write the last-pushed snapshot
1793
1918
  status <spec> [--remote <f>] read-only drift report
1794
1919
  verify <spec> --stored <f> compare a read-back against the repo
1795
1920
  splice <spec> --live <f> [--phase <ref>] the body to write over MCP (summary mode)
1796
1921
  states [--json] the configured types' state names
1797
1922
  list [--all | --state NAME|BUCKET | --next N] [--mine | --by USER] tracker listing
1798
1923
  linked [--json] specs and their linked items (offline)
1924
+ idea add|list|drop [--json] ideas: work items tagged intake.ideaTag
1799
1925
  ownership [--json] who owns status and assignee (offline)
1800
1926
  board <spec> [--json] is the item finished where the spec is not?
1801
1927
  ref [<spec>] the Refs: trailer value for this branch
@@ -1867,7 +1993,7 @@ async function specSync(rest, io = {}) {
1867
1993
  case 'stamp':
1868
1994
  return specSyncStamp(dir, config, positional[0], flags, out)
1869
1995
  case 'record':
1870
- return specSyncRecord(dir, config, positional[0], out)
1996
+ return specSyncRecord(dir, config, positional[0], flags, out)
1871
1997
  case 'status':
1872
1998
  return specSyncStatus(dir, config, positional[0], flags, out, err)
1873
1999
  case 'splice': {
@@ -1879,6 +2005,8 @@ async function specSync(rest, io = {}) {
1879
2005
  return specSyncVerify(dir, config, positional[0], flags, out)
1880
2006
  case 'linked':
1881
2007
  return specSyncLinked(dir, config, flags, out)
2008
+ case 'idea':
2009
+ return specSyncIdea(dir, config, positional, flags, out)
1882
2010
  case 'ownership':
1883
2011
  return kit.specSyncOwnership(config, flags, out, PROGRAM)
1884
2012
  case 'board':
@@ -1940,6 +2068,9 @@ function parseArgs(args, sub) {
1940
2068
  '--via': { kind: 'string' },
1941
2069
  '--force': { kind: 'boolean' },
1942
2070
  '--force-new': { kind: 'boolean', name: 'forceNew' },
2071
+ '--hold-state': { kind: 'boolean', name: 'holdState' },
2072
+ '--send-held': { kind: 'boolean', name: 'sendHeld' },
2073
+ '--held': { kind: 'boolean' },
1943
2074
  '--issue': { kind: 'string' },
1944
2075
  '--url': { kind: 'value' },
1945
2076
  '--sub': { kind: 'list', name: 'subs' },
@@ -1954,6 +2085,8 @@ function parseArgs(args, sub) {
1954
2085
  '--name': { kind: 'string' },
1955
2086
  '--release': { kind: 'boolean' },
1956
2087
  '--if-unassigned': { kind: 'boolean', name: 'ifUnassigned' },
2088
+ '--reason': { kind: 'value' },
2089
+ '--count': { kind: 'boolean' },
1957
2090
  '--mine': { kind: 'boolean' },
1958
2091
  '--next': { kind: 'number' },
1959
2092
  '--by': { kind: 'string' },
@@ -93,6 +93,8 @@ const DEFAULT_CONFIG = Object.freeze({
93
93
  // lists route nothing, as before.
94
94
  intake: Object.freeze({
95
95
  tag: '',
96
+ // The tag that marks a work item as an idea (`/spec-idea`).
97
+ ideaTag: 'idea',
96
98
  bugTags: Object.freeze(['bug']),
97
99
  hotfixTags: Object.freeze([]),
98
100
  bugTypes: Object.freeze(['Bug']),
@@ -165,6 +167,7 @@ function defaults() {
165
167
  stateAliases: {},
166
168
  intake: {
167
169
  tag: DEFAULT_CONFIG.intake.tag,
170
+ ideaTag: DEFAULT_CONFIG.intake.ideaTag,
168
171
  bugTags: [...DEFAULT_CONFIG.intake.bugTags],
169
172
  hotfixTags: [...DEFAULT_CONFIG.intake.hotfixTags],
170
173
  bugTypes: [...DEFAULT_CONFIG.intake.bugTypes],
@@ -254,6 +257,7 @@ function mergeConfig(base, parsed) {
254
257
 
255
258
  if (isObject(parsed.intake)) {
256
259
  assign(base.intake, parsed.intake, 'tag', 'string?')
260
+ assign(base.intake, parsed.intake, 'ideaTag', 'string?')
257
261
  if (Array.isArray(parsed.intake.bugTags)) base.intake.bugTags = stringList(parsed.intake.bugTags)
258
262
  if (Array.isArray(parsed.intake.hotfixTags)) base.intake.hotfixTags = stringList(parsed.intake.hotfixTags)
259
263
  if (Array.isArray(parsed.intake.bugTypes)) base.intake.bugTypes = stringList(parsed.intake.bugTypes)