@skitterbyte/skitterspec-linear 19.10.0 → 19.12.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.
@@ -52,6 +52,7 @@ const path = require('node:path')
52
52
  const {
53
53
  readSnapshot,
54
54
  readBase,
55
+ isEmptyPlan,
55
56
  projectionOf,
56
57
  recordPush,
57
58
  writeFrontmatter,
@@ -85,16 +86,58 @@ async function applySpecPlan(args) {
85
86
  }
86
87
  }
87
88
 
88
- async function applyInner({ dir, config, snapshotDir, plan, adapter, ops, progress, forceNew = false, program = 'spec-sync' }) {
89
+ async function applyInner({
90
+ dir,
91
+ config,
92
+ snapshotDir,
93
+ plan,
94
+ adapter,
95
+ ops,
96
+ progress,
97
+ forceNew = false,
98
+ holdState = false,
99
+ sendHeld = false,
100
+ program = 'spec-sync',
101
+ }) {
89
102
  const fields = fieldsOf(config)
90
103
  const helpers = makeSpecHelpers({ program })
91
104
  const overviewFile = (config.snapshot && config.snapshot.overviewFile) || '00-overview.md'
92
105
  const identifier = helpers.linkedIdentifier(path.join(snapshotDir, overviewFile), config)
93
106
  const lines = []
94
107
  const result = { issue: null, subIssues: {} }
108
+
109
+ // PR-MODE COMPLETION, `branch` lane (spec bug-pr-complete-snapshot-on-base).
110
+ // Run 1 commits the move to ride the PR, but the Done waits for the merge —
111
+ // and run 2 sends it from the base branch, where no spec branch is left to
112
+ // commit a snapshot to. So run 1 HOLDS the state yet records it as sent, and
113
+ // run 2 SENDS only that state: the snapshot it records is byte-identical to
114
+ // the one the merge brought, and the base branch stays clean.
115
+ if (holdState && sendHeld) throw new Error(`${program} apply: --hold-state and --send-held are two runs, not one`)
116
+ if ((holdState || sendHeld) && !identifier) {
117
+ throw new Error(`${program} apply: an unlinked spec has no transition to hold — push it plainly`)
118
+ }
119
+ let heldState = false
120
+ let fellBack = false
121
+ if (holdState && plan.issue && plan.issue.state != null) {
122
+ const { state, stateResend, ...rest } = plan.issue
123
+ plan = { ...plan, issue: Object.keys(rest).length ? rest : undefined }
124
+ heldState = state
125
+ } else if (sendHeld) {
126
+ // A NON-EMPTY PLAN MEANS RUN 1 HELD NOTHING — it predates the hold, so the
127
+ // whole completion is still unsent. Sending the state alone would strand
128
+ // the rest; apply it all, as before, and say which file that leaves dirty.
129
+ if (isEmptyPlan(plan)) {
130
+ const status = projectionOf(snapshotDir, config).status
131
+ if (status != null) plan = { ...plan, issue: { state: status } }
132
+ } else {
133
+ fellBack = true
134
+ }
135
+ }
136
+
95
137
  // Which items this apply carried a state for — the snapshot records today's
96
- // state name for these and only these (`recordPush`).
97
- const sent = { issue: !!(plan.issue && plan.issue.state != null), subIssues: new Set() }
138
+ // state name for these and only these (`recordPush`). A held state counts:
139
+ // run 2 sends it, and what run 2 records has to match what run 1 committed.
140
+ const sent = { issue: !!heldState || !!(plan.issue && plan.issue.state != null), subIssues: new Set() }
98
141
  // Handed out immediately, so a throw from anywhere below still reports what
99
142
  // had been stamped by the time it happened.
100
143
  if (progress) progress.result = result
@@ -268,7 +311,12 @@ async function applyInner({ dir, config, snapshotDir, plan, adapter, ops, progre
268
311
  const file = recordPush({ dir, snapshotDir, identifier: helpers.specIdentifier(snapshotDir, config), config, sent, keepSubIssues })
269
312
  // A repo path, `/`-separated on every platform — the form every other
270
313
  // spec path in this output takes.
271
- lines.push(` snapshot: ${path.relative(dir, file).split(path.sep).join('/')}`)
314
+ const snapshotPath = path.relative(dir, file).split(path.sep).join('/')
315
+ lines.push(` snapshot: ${snapshotPath}`)
316
+ if (heldState) lines.push(` state held: ${identifier} → ${heldState} waits for the merge — run 2 sends it with --send-held`)
317
+ if (fellBack) {
318
+ lines.push(` !! nothing was held for ${identifier} — sent the whole plan; ${snapshotPath} now differs from the merged copy`)
319
+ }
272
320
  return { result, lines, lost }
273
321
  }
274
322
 
@@ -304,4 +352,41 @@ function resolvePhaseFileIn(snapshotDir, ref) {
304
352
  return listPhaseFiles(snapshotDir).find((f) => f.replace(/\.md$/, '') === want) || null
305
353
  }
306
354
 
307
- module.exports = { applySpecPlan }
355
+ /**
356
+ * `--hold-state` / `--send-held` as every provider's `apply` reads them: one
357
+ * spec, one of the two, never both. Returns `{ holdState, sendHeld }`, or
358
+ * `{ error }` for the provider to print and exit 1 on.
359
+ */
360
+ function heldFlags(flags, program) {
361
+ const holdState = !!(flags && flags.holdState)
362
+ const sendHeld = !!(flags && flags.sendHeld)
363
+ if (holdState && sendHeld) return { error: `${program} apply: --hold-state and --send-held are two runs, not one` }
364
+ if ((holdState || sendHeld) && flags.all != null) {
365
+ return { error: `${program} apply --all: --hold-state and --send-held act on one spec at a time` }
366
+ }
367
+ return { holdState, sendHeld }
368
+ }
369
+
370
+ /**
371
+ * What the MCP transport adds to its "nothing written" note, so the hand-applied
372
+ * push ends with the same snapshot the API path would record. Null when neither
373
+ * flag is set.
374
+ */
375
+ function heldOverMcp({ holdState, sendHeld }, program) {
376
+ if (holdState) {
377
+ return (
378
+ " --hold-state: apply the plan WITHOUT the spec issue's state, then record with\n" +
379
+ ` \`${program} record <spec> --held\` — run 2 sends the state after the merge.`
380
+ )
381
+ }
382
+ if (sendHeld) {
383
+ return (
384
+ " --send-held: if `plan` is empty, send the spec issue's state alone and record\n" +
385
+ ' nothing — the merged snapshot already says it. If it is not, run 1 held\n' +
386
+ ' nothing: apply it whole and record as usual.'
387
+ )
388
+ }
389
+ return null
390
+ }
391
+
392
+ module.exports = { applySpecPlan, heldFlags, heldOverMcp }