@skitterbyte/skitterspec-jira 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.
package/src/idea.js ADDED
@@ -0,0 +1,190 @@
1
+ 'use strict'
2
+
3
+ /**
4
+ * Ideas — the inbox for work that is not a spec yet.
5
+ *
6
+ * `/spec-idea` captures a thought without grilling it, somewhere the team can
7
+ * see. Where a ticketing provider can hold ideas, it does (an issue kept off
8
+ * the board); everywhere else they live in one file on the base branch,
9
+ * `specs/ideas.md`. This module is the pure half: the file's format, the id
10
+ * an entry is addressed by, the add/drop planners, and the choice of store.
11
+ * Every git call lives in the CLI.
12
+ */
13
+
14
+ const IDEAS_FILE = 'specs/ideas.md'
15
+
16
+ const PREAMBLE = [
17
+ '# Ideas',
18
+ '',
19
+ 'Captured with `/spec-idea`, not specced yet. Promote one with',
20
+ '`/spec idea:<id>`; discard one with `/spec-idea --drop <id>`.',
21
+ '',
22
+ ].join('\n')
23
+
24
+ // `## <id> · <YYYY-MM-DD> · <author>`
25
+ const HEADER = /^## ([a-z0-9][a-z0-9-]*) · (\d{4}-\d{2}-\d{2}) · (.+)$/
26
+
27
+ // The id is part of a commit subject (`docs(ideas): drop <id>`), and the
28
+ // subject line is held to 50 characters.
29
+ const MAX_ID = 30
30
+
31
+ /**
32
+ * Parse `specs/ideas.md`. Everything before the first `## ` line is the
33
+ * preamble and is kept verbatim. A `## ` line that is not an entry header is
34
+ * reported in `malformed` rather than guessed at, because rewriting the file
35
+ * around a hand edit we did not understand would lose it.
36
+ */
37
+ function parseIdeas(text) {
38
+ const lines = String(text || '').split('\n')
39
+ const first = lines.findIndex((line) => line.startsWith('## '))
40
+ const preamble = first === -1 ? lines.join('\n') : lines.slice(0, first).join('\n')
41
+ const entries = []
42
+ const malformed = []
43
+ if (first === -1) return { preamble, entries, malformed }
44
+
45
+ let current = null
46
+ for (const line of lines.slice(first)) {
47
+ if (line.startsWith('## ')) {
48
+ const m = HEADER.exec(line)
49
+ if (!m) {
50
+ malformed.push(line)
51
+ current = null
52
+ continue
53
+ }
54
+ current = { id: m[1], date: m[2], author: m[3].trim(), lines: [] }
55
+ entries.push(current)
56
+ } else if (current) {
57
+ current.lines.push(line)
58
+ }
59
+ }
60
+ return {
61
+ preamble,
62
+ entries: entries.map(({ lines: body, ...rest }) => ({ ...rest, ...splitText(body.join('\n')) })),
63
+ malformed,
64
+ }
65
+ }
66
+
67
+ /** First non-empty line is the title; whatever follows it is the body. */
68
+ function splitText(text) {
69
+ const lines = String(text || '').replace(/\r\n/g, '\n').split('\n')
70
+ const at = lines.findIndex((line) => line.trim())
71
+ if (at === -1) return { title: '', body: '' }
72
+ return { title: lines[at].trim(), body: lines.slice(at + 1).join('\n').trim() }
73
+ }
74
+
75
+ function formatIdeas({ preamble, entries }) {
76
+ const head = (preamble && preamble.trim() ? preamble : PREAMBLE).replace(/\s+$/, '')
77
+ const blocks = entries.map((e) =>
78
+ [`## ${e.id} · ${e.date} · ${e.author}`, e.title, ...(e.body ? [e.body] : [])].join('\n'),
79
+ )
80
+ return [head, ...blocks].join('\n\n') + '\n'
81
+ }
82
+
83
+ /** A short kebab id from the title, unique among `taken`. */
84
+ function ideaId(title, taken = []) {
85
+ const words = String(title || '')
86
+ .toLowerCase()
87
+ .replace(/[^a-z0-9]+/g, ' ')
88
+ .trim()
89
+ .split(/\s+/)
90
+ .filter(Boolean)
91
+ let stem = ''
92
+ for (const word of words) {
93
+ const next = stem ? `${stem}-${word}` : word
94
+ if (next.length > MAX_ID) break
95
+ stem = next
96
+ }
97
+ if (!stem) stem = words.length ? words[0].slice(0, MAX_ID) : 'idea'
98
+ const used = new Set(taken)
99
+ if (!used.has(stem)) return stem
100
+ for (let n = 2; ; n++) {
101
+ const suffix = `-${n}`
102
+ const candidate = `${stem.slice(0, MAX_ID - suffix.length)}${suffix}`
103
+ if (!used.has(candidate)) return candidate
104
+ }
105
+ }
106
+
107
+ function refuseMalformed(parsed) {
108
+ if (!parsed.malformed.length) return null
109
+ return (
110
+ `${IDEAS_FILE} has ${parsed.malformed.length} heading(s) that are not idea entries ` +
111
+ `(first: "${parsed.malformed[0]}") — fix them by hand; nothing was written`
112
+ )
113
+ }
114
+
115
+ /**
116
+ * Plan an add: `{ id, content, message }`, or `{ refused }`. `text` is what
117
+ * was typed — the first line becomes the title.
118
+ */
119
+ function planAdd(current, { text, author, date }) {
120
+ const { title, body } = splitText(text)
121
+ if (!title) return { refused: 'nothing to capture — give the idea some text' }
122
+ const parsed = parseIdeas(current)
123
+ const bad = refuseMalformed(parsed)
124
+ if (bad) return { refused: bad }
125
+ const id = ideaId(title, parsed.entries.map((e) => e.id))
126
+ // A body line that opens with `## ` would read back as an entry header.
127
+ const safe = body.replace(/^(#+ )/gm, '\\$1')
128
+ const entry = { id, date, author: author || 'unknown', title, body: safe }
129
+ return {
130
+ id,
131
+ entry,
132
+ content: formatIdeas({ preamble: parsed.preamble, entries: [...parsed.entries, entry] }),
133
+ message: `docs(ideas): add ${id}\n\n- Capture "${title}" in ${IDEAS_FILE}\n`,
134
+ }
135
+ }
136
+
137
+ /** Plan a drop: `{ id, content, message }`, or `{ refused }`. */
138
+ function planDrop(current, { id, reason }) {
139
+ const parsed = parseIdeas(current)
140
+ const bad = refuseMalformed(parsed)
141
+ if (bad) return { refused: bad }
142
+ const entry = parsed.entries.find((e) => e.id === id)
143
+ if (!entry) return { refused: `no idea "${id}" — \`skitterspec idea list\` shows them` }
144
+ const why = reason && reason.trim() ? reason.trim() : 'no reason given'
145
+ return {
146
+ id,
147
+ entry,
148
+ content: formatIdeas({ preamble: parsed.preamble, entries: parsed.entries.filter((e) => e !== entry) }),
149
+ message: `docs(ideas): drop ${id}\n\n- Discard "${entry.title}": ${why}\n`,
150
+ }
151
+ }
152
+
153
+ // A provider that can hold ideas registers its store here; one that cannot
154
+ // registers `{ supports: false }`. Left unregistered, the answer is unknown.
155
+ let providerIdeaStore
156
+ function setProviderIdeaStore(store) {
157
+ providerIdeaStore = store
158
+ }
159
+ function getProviderIdeaStore() {
160
+ return providerIdeaStore
161
+ }
162
+
163
+ /**
164
+ * Which store holds ideas: `file`, `provider`, or `unknown`.
165
+ *
166
+ * The file is chosen only on a POSITIVE answer — no provider configured, or a
167
+ * provider that registered `supports: false`. A configured provider that said
168
+ * nothing is unknown, and capture refuses instead of writing to the file:
169
+ * filing there while the team reads the tracker would put one idea in each
170
+ * store with nothing to say which is the real one.
171
+ */
172
+ function selectStore({ providerConfigured, store }) {
173
+ if (!providerConfigured) return 'file'
174
+ if (store && store.supports === true) return 'provider'
175
+ if (store && store.supports === false) return 'file'
176
+ return 'unknown'
177
+ }
178
+
179
+ module.exports = {
180
+ IDEAS_FILE,
181
+ parseIdeas,
182
+ formatIdeas,
183
+ splitText,
184
+ ideaId,
185
+ planAdd,
186
+ planDrop,
187
+ selectStore,
188
+ setProviderIdeaStore,
189
+ getProviderIdeaStore,
190
+ }
package/src/ideacmd.js ADDED
@@ -0,0 +1,242 @@
1
+ 'use strict'
2
+
3
+ /**
4
+ * `skitterspec idea <add|list|drop>` — the side-effecting half of `idea.js`.
5
+ *
6
+ * The file store writes `specs/ideas.md` straight onto the base branch with
7
+ * plumbing — a throwaway index, `commit-tree`, then a fast-forward — so no
8
+ * checkout is switched, no worktree is made, and the primary checkout is never
9
+ * left dirty. Where the base branch is checked out, the fast-forward runs
10
+ * there (`merge --ff-only`) so its working tree follows; elsewhere the ref
11
+ * moves by compare-and-swap. Either way a base that moved underneath us
12
+ * refuses rather than overwriting it.
13
+ *
14
+ * Nothing is pushed. The base branch is shared once it is pushed, and a push
15
+ * is always the operator's to make, so the command prints it instead.
16
+ */
17
+
18
+ const fs = require('node:fs')
19
+ const os = require('node:os')
20
+ const path = require('node:path')
21
+ const { execFileSync } = require('node:child_process')
22
+
23
+ const { IDEAS_FILE, parseIdeas, planAdd, planDrop, selectStore, getProviderIdeaStore } = require('./idea.js')
24
+ const { loadEnvConfig, providerConfigured } = require('./env/config.js')
25
+ const { describeBaseBranch, baseRemote } = require('./env/resolve.js')
26
+ const { primaryAnchor } = require('./env/project.js')
27
+
28
+ const USAGE =
29
+ 'Usage: skitterspec idea add <text> | list [--count] | drop <id> [--reason <why>] [--json] [--dir <path>]\n'
30
+
31
+ function reader(cwd) {
32
+ return (argv) => {
33
+ try {
34
+ return execFileSync('git', ['-C', cwd, ...argv], { stdio: ['ignore', 'pipe', 'ignore'] })
35
+ .toString()
36
+ .trim()
37
+ } catch {
38
+ return null
39
+ }
40
+ }
41
+ }
42
+
43
+ // A mutating call: throws with git's own stderr, which is what gets relayed.
44
+ function git(cwd, argv, { input, env } = {}) {
45
+ try {
46
+ return execFileSync('git', ['-C', cwd, ...argv], {
47
+ input,
48
+ env: env || process.env,
49
+ stdio: ['pipe', 'pipe', 'pipe'],
50
+ })
51
+ .toString()
52
+ .trim()
53
+ } catch (error) {
54
+ throw new Error((error.stderr && error.stderr.toString().trim()) || error.message)
55
+ }
56
+ }
57
+
58
+ function parseArgs(argv) {
59
+ const flags = { json: false, count: false, dir: null, reason: null }
60
+ const positional = []
61
+ for (let i = 0; i < argv.length; i++) {
62
+ const a = argv[i]
63
+ if (a === '--json') flags.json = true
64
+ else if (a === '--count') flags.count = true
65
+ else if (a === '--dir') flags.dir = argv[++i]
66
+ else if (a === '--reason') flags.reason = argv[++i]
67
+ else positional.push(a)
68
+ }
69
+ return { flags, positional }
70
+ }
71
+
72
+ function localDay(now) {
73
+ const pad = (n) => String(n).padStart(2, '0')
74
+ return `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`
75
+ }
76
+
77
+ /** Where the file store lives: the primary checkout, its base branch, the path. */
78
+ function fileContext(from) {
79
+ const anchor = primaryAnchor(from, reader(from))
80
+ const read = reader(anchor.root)
81
+ let config = {}
82
+ try {
83
+ config = loadEnvConfig(anchor.dir).config
84
+ } catch {
85
+ // an unreadable config resolves the base the way a missing one does
86
+ }
87
+ const { base, refused } = describeBaseBranch(config, read)
88
+ return {
89
+ anchor,
90
+ read,
91
+ base,
92
+ refused,
93
+ remote: baseRemote(config),
94
+ rel: anchor.prefix ? `${anchor.prefix}/${IDEAS_FILE}` : IDEAS_FILE,
95
+ }
96
+ }
97
+
98
+ /** The file as the base branch holds it — `''` when it is not there yet. */
99
+ function readOnBase(ctx) {
100
+ const tip = ctx.read(['rev-parse', '--verify', '--quiet', `refs/heads/${ctx.base}^{commit}`])
101
+ if (!tip) return { tip: null, text: null }
102
+ return { tip, text: ctx.read(['show', `${tip}:${ctx.rel}`]) || '' }
103
+ }
104
+
105
+ /** The worktree that has `branch` checked out, else null. */
106
+ function checkedOutAt(ctx, branch) {
107
+ const out = ctx.read(['worktree', 'list', '--porcelain']) || ''
108
+ let at = null
109
+ for (const line of out.split('\n')) {
110
+ if (line.startsWith('worktree ')) at = line.slice('worktree '.length)
111
+ else if (line === `branch refs/heads/${branch}`) return at
112
+ }
113
+ return null
114
+ }
115
+
116
+ /** Commit `content` at `rel` on top of `tip`, then fast-forward the base to it. */
117
+ function landOnBase(ctx, tip, content, message) {
118
+ const root = ctx.anchor.root
119
+ const index = path.join(os.tmpdir(), `skitterspec-idea-${process.pid}-${Date.now()}.index`)
120
+ const env = { ...process.env, GIT_INDEX_FILE: index }
121
+ let commit
122
+ try {
123
+ git(root, ['read-tree', tip], { env })
124
+ const blob = git(root, ['hash-object', '-w', '--stdin'], { input: content })
125
+ git(root, ['update-index', '--add', '--cacheinfo', `100644,${blob},${ctx.rel}`], { env })
126
+ const tree = git(root, ['write-tree'], { env })
127
+ commit = git(root, ['commit-tree', tree, '-p', tip, '-F', '-'], { input: message })
128
+ } finally {
129
+ fs.rmSync(index, { force: true })
130
+ }
131
+
132
+ const at = checkedOutAt(ctx, ctx.base)
133
+ if (at) {
134
+ // Its working tree must follow the ref, so the move happens there — and a
135
+ // local edit to the file is someone's work, which a fast-forward would
136
+ // either refuse over or carry; refuse first, with the reason in words.
137
+ const dirty = reader(at)(['status', '--porcelain', '--', ctx.rel])
138
+ if (dirty) throw new Error(`${ctx.rel} has uncommitted changes in ${at} — commit or discard them first`)
139
+ git(at, ['merge', '--ff-only', '--quiet', commit])
140
+ } else {
141
+ git(root, ['update-ref', '-m', 'skitterspec idea', `refs/heads/${ctx.base}`, commit, tip])
142
+ }
143
+ return commit
144
+ }
145
+
146
+ function write(out, flags, json, lines) {
147
+ out.write(flags.json ? JSON.stringify(json, null, 2) + '\n' : lines.join('\n') + '\n')
148
+ }
149
+
150
+ function refuse(out, flags, reason, extra = {}) {
151
+ write(out, flags, { ok: false, refused: reason, ...extra }, [`idea: ${reason}`])
152
+ return 1
153
+ }
154
+
155
+ async function fileStore(sub, positional, flags, { cwd, now, out }) {
156
+ const ctx = fileContext(cwd)
157
+ if (!ctx.base) return refuse(out, flags, ctx.refused ? ctx.refused.message : 'cannot resolve the base branch')
158
+ const { tip, text } = readOnBase(ctx)
159
+
160
+ if (sub === 'list') {
161
+ const ideas = tip ? parseIdeas(text).entries : []
162
+ if (flags.count) {
163
+ write(out, flags, { store: 'file', count: ideas.length }, [String(ideas.length)])
164
+ return 0
165
+ }
166
+ const lines = ideas.length
167
+ ? [`ideas on ${ctx.base} (${ctx.rel}):`, ...ideas.map((e) => ` ${e.id.padEnd(30)} ${e.date} ${e.title}`)]
168
+ : [`idea: nothing waiting on ${ctx.base}`]
169
+ write(out, flags, { store: 'file', base: ctx.base, file: ctx.rel, ideas }, lines)
170
+ return 0
171
+ }
172
+
173
+ if (!tip) return refuse(out, flags, `the base branch ${ctx.base} has no commits here`)
174
+
175
+ const plan =
176
+ sub === 'add'
177
+ ? planAdd(text, {
178
+ text: positional.join(' '),
179
+ author: ctx.read(['config', 'user.name']),
180
+ date: localDay(now),
181
+ })
182
+ : planDrop(text, { id: positional[0], reason: flags.reason })
183
+ if (plan.refused) return refuse(out, flags, plan.refused, sub === 'add' ? { text: positional.join(' ') } : {})
184
+
185
+ let commit
186
+ try {
187
+ commit = landOnBase(ctx, tip, plan.content, plan.message)
188
+ } catch (error) {
189
+ return refuse(out, flags, `nothing landed — ${error.message}`, sub === 'add' ? { text: positional.join(' ') } : {})
190
+ }
191
+ const push = `git push ${ctx.remote} ${ctx.base}`
192
+ const verb = sub === 'add' ? 'added' : 'dropped'
193
+ write(
194
+ out,
195
+ flags,
196
+ { ok: true, store: 'file', action: sub, id: plan.id, title: plan.entry.title, base: ctx.base, commit, file: ctx.rel, push },
197
+ [
198
+ `idea: ${verb} "${plan.id}" ${sub === 'add' ? 'to' : 'from'} ${ctx.rel} on ${ctx.base} (${commit.slice(0, 7)})`,
199
+ ` title: ${plan.entry.title}`,
200
+ ` pushed: no — ${push} publishes it`,
201
+ ],
202
+ )
203
+ return 0
204
+ }
205
+
206
+ /**
207
+ * Entry point. Resolves to an exit code: 0 for an answer, 1 for a refusal —
208
+ * which for `add` carries the text back, so a refused capture loses nothing.
209
+ */
210
+ async function ideaCommand(argv, { cwd = process.cwd(), now = new Date(), out = process.stdout } = {}) {
211
+ const [sub, ...rest] = argv
212
+ const { flags, positional } = parseArgs(rest)
213
+ const from = path.resolve(flags.dir || cwd)
214
+ if (!['add', 'list', 'drop'].includes(sub)) {
215
+ out.write(USAGE)
216
+ return sub ? 1 : 0
217
+ }
218
+ if (sub === 'add' && !positional.join(' ').trim()) return refuse(out, flags, 'nothing to capture — give the idea some text')
219
+ if (sub === 'drop' && !positional[0]) return refuse(out, flags, 'name the idea to drop — `skitterspec idea list` shows them')
220
+
221
+ const anchor = primaryAnchor(from, reader(from))
222
+ const store = getProviderIdeaStore()
223
+ const where = selectStore({ providerConfigured: providerConfigured(anchor.dir), store })
224
+ if (where === 'provider') return store.run(sub, rest, { cwd: from, out })
225
+ if (where === 'unknown') {
226
+ if (sub === 'list') {
227
+ write(out, flags, { store: 'unknown', count: null }, ['idea: cannot tell where ideas live — the configured provider declares no idea store'])
228
+ return 0
229
+ }
230
+ const text = positional.join(' ')
231
+ return refuse(
232
+ out,
233
+ flags,
234
+ 'cannot tell where ideas live — the configured provider declares no idea store; nothing was written' +
235
+ (sub === 'add' ? `\n your idea, so nothing is lost:\n ${text.replace(/\n/g, '\n ')}` : ''),
236
+ sub === 'add' ? { text } : {},
237
+ )
238
+ }
239
+ return fileStore(sub, positional, flags, { cwd: from, now, out })
240
+ }
241
+
242
+ module.exports = { ideaCommand, USAGE }
package/src/tada/todo.js CHANGED
@@ -179,13 +179,17 @@ function buildTodo({ leftOff, leftOffDay, today, home = null, blockersFor = () =
179
179
  const e = entry({ ...home, here: true })
180
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
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
182
186
 
183
187
  const list = [...projects.values()]
184
188
  .map((e) => {
185
189
  const specs = e.groups.filter((g) => g.spec && g.inFlight).map((g) => g.spec)
186
190
  return { ...e, blocked: e.repo && specs.length ? blockersFor(e.repo, specs) : [] }
187
191
  })
188
- .filter((e) => e.groups.length || e.finished.length || e.today.commits || e.today.moves)
192
+ .filter((e) => e.groups.length || e.finished.length || e.today.commits || e.today.moves || e.ideas)
189
193
  // The home project first: it is the one this session acts on.
190
194
  .sort((a, b) => (a.here !== b.here ? (a.here ? -1 : 1) : a.name.localeCompare(b.name)))
191
195
 
@@ -233,6 +237,7 @@ function formatTodo(todo, now = new Date()) {
233
237
  }
234
238
  if (p.finished.length) out.push(` finished: ${p.finished.join(', ')}`)
235
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`)
236
241
  if (p.today.commits || p.today.moves) {
237
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'}`]
238
243
  out.push(` today: ${parts.filter(Boolean).join(', ')}`)
@@ -318,10 +318,15 @@ function specSyncPlan(dir, config, specArg, flags, out, err) {
318
318
  }
319
319
 
320
320
  async function specSyncApply(dir, config, specArg, flags, out, err) {
321
- if (!flags.plan && !flags.all) {
321
+ if (!flags.plan && !flags.all && !flags.sendHeld) {
322
322
  out.write(`${PROGRAM} apply: pass --plan <file> (from \`plan --json\`), or --all <bucket>\n`)
323
323
  return 1
324
324
  }
325
+ const held = kit.heldFlags(flags, PROGRAM)
326
+ if (held.error) {
327
+ out.write(held.error + '\n')
328
+ return 1
329
+ }
325
330
  const cred = apiAdapterFor(config, flags)
326
331
  const transport = kit.resolveTransport(flags, config, cred.ok)
327
332
  if (transport === 'mcp') {
@@ -335,6 +340,8 @@ async function specSyncApply(dir, config, specArg, flags, out, err) {
335
340
  ' editJiraIssue / transitionJiraIssue), then stamp the returned keys\n' +
336
341
  ' with `spec-sync stamp` and record with `spec-sync record`.\n',
337
342
  )
343
+ const heldNote = kit.heldOverMcp(held, PROGRAM)
344
+ if (heldNote) out.write(heldNote + '\n')
338
345
  return 0
339
346
  }
340
347
  if (!cred.ok) {
@@ -351,6 +358,8 @@ async function specSyncApply(dir, config, specArg, flags, out, err) {
351
358
  adapter: cred.adapter,
352
359
  ops: applyOps({ adapter: cred.adapter, config, kind: specKindOf(snapshotDir), snapshotDir, out }),
353
360
  forceNew: !!flags.forceNew,
361
+ holdState: held.holdState,
362
+ sendHeld: held.sendHeld,
354
363
  program: PROGRAM,
355
364
  })
356
365
 
@@ -386,13 +395,19 @@ async function specSyncApply(dir, config, specArg, flags, out, err) {
386
395
  const snapshotDir = resolveOrExit(specArg, dir, out)
387
396
  if (!snapshotDir) return 1
388
397
  let plan
389
- try {
390
- plan = JSON.parse(fs.readFileSync(flags.plan, 'utf-8'))
391
- } catch (error) {
392
- out.write(`${PROGRAM} apply: cannot read --plan: ${error.message}\n`)
393
- return 1
398
+ if (!flags.plan) {
399
+ // --send-held computes its own. After the merge it is normally empty, and
400
+ // that empty plan is what tells apply that run 1 held the state.
401
+ plan = push({ dir, snapshotDir, identifier: specIdentifier(snapshotDir, config), config }).plan
402
+ } else {
403
+ try {
404
+ plan = JSON.parse(fs.readFileSync(flags.plan, 'utf-8'))
405
+ } catch (error) {
406
+ out.write(`${PROGRAM} apply: cannot read --plan: ${error.message}\n`)
407
+ return 1
408
+ }
394
409
  }
395
- if (isEmptyPlan(plan)) {
410
+ if (!held.sendHeld && isEmptyPlan(plan)) {
396
411
  out.write(`${PROGRAM} apply: empty plan — nothing to do\n`)
397
412
  return 0
398
413
  }
@@ -477,10 +492,13 @@ async function specSyncStamp(dir, config, specArg, flags, out) {
477
492
  return 0
478
493
  }
479
494
 
480
- function specSyncRecord(dir, config, specArg, out) {
495
+ function specSyncRecord(dir, config, specArg, flags, out) {
481
496
  const snapshotDir = resolveOrExit(specArg, dir, out)
482
497
  if (!snapshotDir) return 1
483
- const file = recordPush({ dir, snapshotDir, identifier: specIdentifier(snapshotDir, config), config })
498
+ // --held: the hand-applied twin of `apply --hold-state` — the state was left
499
+ // out on purpose, and is recorded as sent so run 2 rewrites nothing.
500
+ const sent = flags && flags.held ? { issue: true, subIssues: new Set() } : null
501
+ const file = recordPush({ dir, snapshotDir, identifier: specIdentifier(snapshotDir, config), config, sent })
484
502
  out.write(`${PROGRAM} record: snapshot written — ${path.relative(dir, file).split(path.sep).join('/')}\n`)
485
503
  return 0
486
504
  }
@@ -1307,8 +1325,9 @@ const USAGE = `Usage: skitterspec-jira spec-sync <subcommand>
1307
1325
  normalize <spec> print the local projection as JSON
1308
1326
  plan <spec> --workspace-states <f> what a push would change (dry, JSON)
1309
1327
  apply <spec> --plan <f> | --all <b> apply a plan over the API
1328
+ apply <spec> --hold-state | --send-held PR-mode completion: hold Done for run 2, then send it
1310
1329
  stamp <spec> --issue KEY [--sub r=K] write returned keys into the spec
1311
- record <spec> write the last-pushed snapshot
1330
+ record <spec> [--held] write the last-pushed snapshot
1312
1331
  status <spec> [--remote <f>] read-only drift report
1313
1332
  verify <spec> --stored <f> compare a read-back against the repo
1314
1333
  splice <spec> --live <f> [--phase <ref>] the body to write over MCP (summary mode)
@@ -1382,7 +1401,7 @@ async function specSync(rest, io = {}) {
1382
1401
  case 'stamp':
1383
1402
  return specSyncStamp(dir, config, positional[0], flags, out)
1384
1403
  case 'record':
1385
- return specSyncRecord(dir, config, positional[0], out)
1404
+ return specSyncRecord(dir, config, positional[0], flags, out)
1386
1405
  case 'status':
1387
1406
  return specSyncStatus(dir, config, positional[0], flags, out, err)
1388
1407
  case 'splice': {
@@ -1447,6 +1466,9 @@ function parseArgs(args, sub) {
1447
1466
  '--via': { kind: 'string' },
1448
1467
  '--force': { kind: 'boolean' },
1449
1468
  '--force-new': { kind: 'boolean', name: 'forceNew' },
1469
+ '--hold-state': { kind: 'boolean', name: 'holdState' },
1470
+ '--send-held': { kind: 'boolean', name: 'sendHeld' },
1471
+ '--held': { kind: 'boolean' },
1450
1472
  '--issue': { kind: 'string' },
1451
1473
  '--url': { kind: 'value' },
1452
1474
  '--sub': { kind: 'list', name: 'subs' },