@skitterbyte/skitterspec-github 2.2.0 → 2.4.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.
Files changed (60) hide show
  1. package/assets/claude-md-section.md +20 -1
  2. package/assets/core/env.config.json.example +1 -0
  3. package/assets/core/env.config.md +90 -6
  4. package/assets/core/github.config.json.example +2 -1
  5. package/assets/core/github.config.md +5 -1
  6. package/assets/hooks/main-guard.cjs +18 -2
  7. package/assets/hooks/review-gate.cjs +19 -2
  8. package/assets/rules/commit-trailers.md +24 -1
  9. package/assets/rules/spec-planning.md +131 -18
  10. package/assets/rules/spec-reports.md +1 -1
  11. package/assets/skills/spec/SKILL.md +95 -6
  12. package/assets/skills/spec-bug/SKILL.md +68 -3
  13. package/assets/skills/spec-cancel/SKILL.md +37 -0
  14. package/assets/skills/spec-claim/SKILL.md +41 -2
  15. package/assets/skills/spec-complete/SKILL.md +115 -0
  16. package/assets/skills/spec-github-setup/SKILL.md +31 -4
  17. package/assets/skills/spec-hotfix/SKILL.md +72 -4
  18. package/assets/skills/spec-incident/SKILL.md +44 -0
  19. package/assets/skills/spec-next/SKILL.md +12 -5
  20. package/assets/skills/spec-push/SKILL.md +22 -0
  21. package/assets/skills/spec-review/SKILL.md +34 -0
  22. package/assets/skills/spec-start/SKILL.md +50 -3
  23. package/assets/skills/spec-status/SKILL.md +18 -3
  24. package/assets/skills/spec-sync/SKILL.md +1 -0
  25. package/assets/skills/spec-to-main/SKILL.md +47 -1
  26. package/package.json +1 -1
  27. package/src/cli.js +1091 -39
  28. package/src/env/base.js +104 -0
  29. package/src/env/config.js +75 -3
  30. package/src/env/disposition.js +62 -0
  31. package/src/env/handoff.js +80 -0
  32. package/src/env/host.js +262 -0
  33. package/src/env/hotfix.js +225 -0
  34. package/src/env/hotfixland.js +103 -9
  35. package/src/env/inflight.js +95 -0
  36. package/src/env/integrate.js +130 -4
  37. package/src/env/mainguard.js +6 -0
  38. package/src/env/phases.js +28 -0
  39. package/src/env/provision.js +18 -6
  40. package/src/env/resolve.js +108 -9
  41. package/src/env/serve.js +6 -1
  42. package/src/env/specstate.js +101 -0
  43. package/src/env/teardown.js +42 -0
  44. package/src/vendor/github/api.js +33 -2
  45. package/src/vendor/github/cli-sync.js +62 -3
  46. package/src/vendor/github/config.js +19 -5
  47. package/src/vendor/provider-kit/index.js +4 -0
  48. package/src/vendor/provider-kit/src/apply.js +49 -4
  49. package/src/vendor/provider-kit/src/assignment.js +78 -1
  50. package/src/vendor/provider-kit/src/config.js +34 -1
  51. package/src/vendor/provider-kit/src/list-rows.js +35 -11
  52. package/src/vendor/provider-kit/src/released.js +14 -1
  53. package/src/vendor/provider-kit/src/specs.js +4 -2
  54. package/src/vendor/provider-kit/src/splice.js +64 -0
  55. package/src/vendor/provider-kit/src/status.js +137 -0
  56. package/src/vendor/sync-core/index.js +14 -1
  57. package/src/vendor/sync-core/src/compare.js +17 -5
  58. package/src/vendor/sync-core/src/normalize.js +50 -7
  59. package/src/vendor/sync-core/src/push.js +26 -2
  60. package/src/vendor/sync-core/src/summary.js +257 -0
@@ -35,6 +35,9 @@ const {
35
35
  stampSubIssueId,
36
36
  listPhaseFiles,
37
37
  normalizeLocal,
38
+ descriptionMode,
39
+ progressOf,
40
+ readSnapshot,
38
41
  } = require('../sync-core')
39
42
  const kit = require('../provider-kit')
40
43
  const { GITHUB_REF_RE, IDENTIFIER_RE } = require('../provider-kit/src/released.js')
@@ -221,7 +224,19 @@ function applyOps({ adapter, config, kind = 'feature', snapshotDir = null }) {
221
224
  if (severityLabel && !spec.labels.some((l) => l.toLowerCase() === severityLabel.toLowerCase())) {
222
225
  spec.labels = [...spec.labels, severityLabel]
223
226
  }
227
+ // `summary.progressField`: mirror % done into a board Number field. Opt-in;
228
+ // a spec with no checkboxes has no progress to send (cannot-tell, not 0).
229
+ const progressField = config.summary && config.summary.progressField
224
230
  return {
231
+ afterIssue: async (issue) => {
232
+ if (!progressField || !snapshotDir || typeof adapter.setNumberField !== 'function') return null
233
+ const progress = progressOf(readSnapshot(snapshotDir, config).phases)
234
+ if (!progress) return null
235
+ const r = await adapter.setNumberField(issue, progressField, progress.percent)
236
+ return r && r.skipped
237
+ ? ` progress: not mirrored — ${r.skipped}`
238
+ : ` progress: ${progress.percent}% → board field "${progressField}"`
239
+ },
225
240
  prevalidateStates: (buckets) => {
226
241
  for (const bucket of buckets) statusFor(bucket)
227
242
  },
@@ -296,6 +311,16 @@ function apiAdapterFor(config, flags) {
296
311
  return { ok: true, adapter: makeApiAdapter({ ...adapterOptions(config), token: cred.token, fetch: flags.fetch }) }
297
312
  }
298
313
 
314
+ // `board <spec>` — has GitHub finished what this repo has not? The kit's
315
+ // (`provider-kit/src/status.js`): one line on a disagreement, silent otherwise.
316
+ async function specSyncBoard(dir, config, specArg, flags, out) {
317
+ const snapshotDir = resolveOrExit(specArg, dir, out)
318
+ if (!snapshotDir) return 1
319
+ const cred = apiAdapterFor(config, flags)
320
+ const credential = kit.resolveTransport(flags, config, cred.ok) === 'mcp' ? { ok: false, error: 'transport = mcp — no API read' } : cred
321
+ return kit.specSyncBoard({ snapshotDir, config, credential, flags, out, tracker: 'GitHub', program: PROGRAM })
322
+ }
323
+
299
324
  // ---------------------------------------------------------------------------
300
325
  // Assignment: `assign`, `whoami` and `users` are the kit's
301
326
  // (`provider-kit/src/assignment.js`); this is GitHub's binding. The id is a
@@ -931,12 +956,16 @@ function specSyncRef(dir, config, specArg, flags, out, err) {
931
956
  // `Refs:` trailers (kit `src/released.js` owns the parsing rules). Refs are
932
957
  // `#N`; an older tracker's `KEY-N` trailer — a repo that moved here from
933
958
  // Linear or Jira — counts as historical, never as a missed trailer.
959
+ // Merge commits are READ, never skipped: a hand merge is where a ticket's only
960
+ // trailer sometimes lives (--no-merges was tried and dropped for exactly that
961
+ // loss). What changes is the counting — a trailer-less merge is transport, not
962
+ // a gap — and %P is what lets ticketsInRange tell the two apart.
934
963
  function readCommitRange(dir, range) {
935
964
  const { execFileSync } = require('node:child_process')
936
965
  const SEP = '\0SKITTERSPEC\0'
937
966
  let raw
938
967
  try {
939
- raw = execFileSync('git', ['-C', dir, 'log', `--format=%x00SKITTERSPEC%x00%H%n%B%x00END%x00`, '--name-only', range], {
968
+ raw = execFileSync('git', ['-C', dir, 'log', `--format=%x00SKITTERSPEC%x00%H %P%n%B%x00END%x00`, '--name-only', range], {
940
969
  encoding: 'utf-8',
941
970
  stdio: ['ignore', 'pipe', 'pipe'],
942
971
  maxBuffer: 64 * 1024 * 1024,
@@ -957,9 +986,10 @@ function readCommitRange(dir, range) {
957
986
  .map((l) => l.trim())
958
987
  .filter(Boolean)
959
988
  const nl = head.indexOf('\n')
960
- const sha = head.slice(0, nl < 0 ? head.length : nl).trim()
989
+ const idLine = head.slice(0, nl < 0 ? head.length : nl).trim()
990
+ const [sha, ...parents] = idLine.split(/\s+/).filter(Boolean)
961
991
  const body = nl < 0 ? '' : head.slice(nl + 1)
962
- commits.push({ sha, subject: body.split('\n')[0] || '', body, paths })
992
+ commits.push({ sha, isMerge: parents.length > 1, subject: body.split('\n')[0] || '', body, paths })
963
993
  }
964
994
  return { ok: true, commits }
965
995
  }
@@ -985,6 +1015,7 @@ function specSyncReleased(dir, config, rangeArg, flags, out) {
985
1015
  for (const t of report.tickets) lines.push(` ${t.ref} (${t.commits} commit(s))${t.spec ? ` ${t.spec}` : ''}`)
986
1016
  if (!report.tickets.length) lines.push(' no referenced issues')
987
1017
  if (report.unreferenced) lines.push(` ${report.unreferenced} commit(s) carry no Refs: trailer`)
1018
+ if (report.merges) lines.push(` ${report.merges} merge commit(s) — transport, not counted as gaps`)
988
1019
  if (report.historical) lines.push(` ${report.historical} commit(s) reference an earlier tracker (KEY-N)`)
989
1020
  if (report.ignored) lines.push(` ${report.ignored} bookkeeping commit(s) ignored`)
990
1021
  out.write(lines.join('\n') + '\n')
@@ -1009,6 +1040,11 @@ async function specSyncPreserve(dir, config, specArg, flags, out) {
1009
1040
  return 0
1010
1041
  }
1011
1042
  if (!identifier) return done(`${path.basename(snapshotDir)} is not linked — nothing to preserve`)
1043
+ // Summary mode splices a block in beside the reporter's text rather than
1044
+ // replacing it, so the original is still in the description itself.
1045
+ if (descriptionMode(config) === 'summary') {
1046
+ return done(`${identifier} — summary mode keeps the original description in place; nothing to preserve`)
1047
+ }
1012
1048
 
1013
1049
  let original = null
1014
1050
  if (flags.text) {
@@ -1225,6 +1261,10 @@ async function specSyncInitConfig(dir, flags, out) {
1225
1261
  // fails HERE rather than on the first push.
1226
1262
  const parsed = { github: { owner: flags.owner, repo: flags.repo, project: flags.project } }
1227
1263
  if (flags.statusField) parsed.github.statusField = flags.statusField
1264
+ // A NEW config carries a summary, not the spec: written explicitly, so the
1265
+ // file says what the ticket gets. A config that predates the key keeps
1266
+ // pushing the spec (the loader's default), so an upgrade rewrites nothing.
1267
+ parsed.mapping = { description: flags.description || 'summary' }
1228
1268
  if (flags.stateNames && Object.keys(flags.stateNames).length) {
1229
1269
  for (const bucket of Object.keys(flags.stateNames)) {
1230
1270
  if (!LIFECYCLE_BUCKETS.includes(bucket)) {
@@ -1320,6 +1360,7 @@ async function specSyncDoctor(dir, flags, out) {
1320
1360
  checks.push(row('tracker', 'GitHub config', 'broken', configGap(loaded.config), `fix ${CONFIG_FILE}`))
1321
1361
  } else {
1322
1362
  checks.push(row('tracker', 'GitHub config', 'ok', `${repoLabel(loaded.config)} · board ${loaded.config.github.project}`))
1363
+ checks.push(kit.ownershipDoctorRow(loaded.config))
1323
1364
  const retired = kit.retiredKeysRow(path.join(dir, CONFIG_FILE), CONFIG_FILE, row)
1324
1365
  if (retired) checks.push(retired)
1325
1366
  // A worktree forks from a COMMIT, so a config that exists only in the
@@ -1435,19 +1476,24 @@ const USAGE = `Usage: ${BIN} spec-sync <subcommand>
1435
1476
  record <spec> write the last-pushed snapshot
1436
1477
  status <spec> [--remote <f>] read-only drift report
1437
1478
  verify <spec> --stored <f> compare a read-back against the repo
1479
+ splice <spec> --live <f> [--phase <ref>] the body to write over MCP (summary mode)
1438
1480
  states [--json] the board's Status options + bucket map
1439
1481
  list [--all | --state NAME|BUCKET | --next N] [--mine | --by USER] the board's issues
1440
1482
  intake [query] [--json] issues waiting to become specs
1441
1483
  linked [--json] specs and their linked issues (offline)
1484
+ ownership [--json] who owns status and assignee (offline)
1485
+ board <spec> [--json] is the issue finished where the spec is not?
1442
1486
  ref [<spec>] the Refs: trailer value for this branch
1443
1487
  released [<range>] issues a commit range contains
1444
1488
  preserve <spec> [--text <f>] keep an adopted issue's original report
1445
1489
  comment <spec> --file <f> post a file onto the issue as a comment
1446
1490
  assign <spec> --to <login> | --release stamp who is building it
1491
+ [--if-unassigned] only when nobody holds the issue
1447
1492
  whoami [--set <login>] [--unset] who you are on GitHub (cached)
1448
1493
  users [<query>] the repo's assignable people
1449
1494
  credentials <status|set|unset> the GitHub token (user-level)
1450
1495
  init-config --owner … --repo … --project N write the config
1496
+ [--description summary|spec] what a ticket body carries (default summary)
1451
1497
  doctor [--check-remote] [--json] readiness report
1452
1498
 
1453
1499
  Not yet shipped for GitHub: retarget, reattach, sanitise.
@@ -1508,10 +1554,19 @@ async function specSync(rest, io = {}) {
1508
1554
  return specSyncRecord(dir, config, positional[0], out)
1509
1555
  case 'status':
1510
1556
  return specSyncStatus(dir, config, positional[0], flags, out, err)
1557
+ case 'splice': {
1558
+ const snapshotDir = resolveOrExit(positional[0], dir, err)
1559
+ if (!snapshotDir) return 1
1560
+ return kit.specSyncSplice({ snapshotDir, config, flags, out, err, program: PROGRAM })
1561
+ }
1511
1562
  case 'verify':
1512
1563
  return specSyncVerify(dir, config, positional[0], flags, out)
1513
1564
  case 'linked':
1514
1565
  return specSyncLinked(dir, config, flags, out)
1566
+ case 'ownership':
1567
+ return kit.specSyncOwnership(config, flags, out, PROGRAM)
1568
+ case 'board':
1569
+ return specSyncBoard(dir, config, positional[0], flags, out)
1515
1570
  case 'states':
1516
1571
  return specSyncStates(dir, config, flags, out)
1517
1572
  case 'list':
@@ -1558,6 +1613,8 @@ function parseArgs(args, sub) {
1558
1613
  '--dir': { kind: 'path', name: 'dirOverride' },
1559
1614
  '--plan': { kind: 'path' },
1560
1615
  '--stored': { kind: 'path' },
1616
+ '--live': { kind: 'path' },
1617
+ '--phase': { kind: 'string' },
1561
1618
  '--remote': { kind: 'path' },
1562
1619
  '--text': { kind: 'path' },
1563
1620
  '--file': { kind: 'path' },
@@ -1576,9 +1633,11 @@ function parseArgs(args, sub) {
1576
1633
  '--repo': { kind: 'string' },
1577
1634
  '--project': { kind: 'string' },
1578
1635
  '--status-field': { kind: 'string', name: 'statusField' },
1636
+ '--description': { kind: 'string' },
1579
1637
  '--to': { kind: 'string' },
1580
1638
  '--name': { kind: 'value' },
1581
1639
  '--release': { kind: 'boolean' },
1640
+ '--if-unassigned': { kind: 'boolean', name: 'ifUnassigned' },
1582
1641
  '--mine': { kind: 'boolean' },
1583
1642
  '--next': { kind: 'number' },
1584
1643
  '--by': { kind: 'string' },
@@ -28,7 +28,7 @@ const CONFIG_FILE = 'specs/.core/github.config.json'
28
28
 
29
29
  const OWNERSHIP = Object.freeze(['both', 'pull', 'push', 'none'])
30
30
  const TASK_MAPPINGS = Object.freeze(['checklist', 'none'])
31
- const PHASE_MAPPINGS = Object.freeze(['subissue', 'deferred', 'inline'])
31
+ const PHASE_MAPPINGS = Object.freeze(['subissue', 'deferred', 'inline', 'none'])
32
32
  const TRANSPORTS = Object.freeze(['api', 'mcp'])
33
33
  const DEFAULT_TOKEN_ENV = 'GITHUB_TOKEN'
34
34
  // Read after `auth.tokenEnv`, because it is the name the GitHub CLI itself
@@ -64,7 +64,13 @@ const DEFAULT_CONFIG = Object.freeze({
64
64
  // A spec is a GitHub ISSUE; each phase a SUB-ISSUE of it, carrying the
65
65
  // phase's checkboxes in its body as a task list (rendered live by GitHub —
66
66
  // still a read-only mirror).
67
- mapping: Object.freeze({ specFolder: 'issue', phases: DEFAULT_PHASE_MODE, tasks: 'checklist' }),
67
+ // `description`: what the ticket body carries — `spec` (the whole overview)
68
+ // or `summary` (a delimited block beside the team's own text). `spec` is the
69
+ // default so a config written before the key pushes what it always pushed.
70
+ mapping: Object.freeze({ specFolder: 'issue', phases: DEFAULT_PHASE_MODE, tasks: 'checklist', description: 'spec' }),
71
+ // The summary block's delimiters (measured 2026-11-08: GitHub keeps HTML comments verbatim and hides them).
72
+ // `progressField`: a board Number field to mirror % done into; empty = off.
73
+ summary: Object.freeze({ delimiter: 'comment', progressField: '' }),
68
74
  // Board STATUS OPTION names — the spec issue's (from the folder bucket) and
69
75
  // each sub-issue's (from the phase emoji) both map through this table. They
70
76
  // must match the Status field's options exactly; the adapter resolves them
@@ -96,11 +102,16 @@ const DEFAULT_CONFIG = Object.freeze({
96
102
  sync: Object.freeze({
97
103
  baseDir: 'specs/.core/github-base',
98
104
  backupDir: 'specs/.core/github-backups',
105
+ // The repo owns the spec's CONTENT (`push`); the tracker owns its STATUS and
106
+ // ASSIGNEE (`pull`) — the board is where a team assigns and moves work, so a
107
+ // repo copy is one somebody has to keep in step by hand. Under `pull` the
108
+ // state is sent only as a transition the repo made (a bucket move), and the
109
+ // assignee not at all. Set either back to `"push"` for the repo-owned behaviour.
99
110
  fieldOwnership: Object.freeze({
100
111
  description: 'push',
101
112
  subIssues: 'push',
102
- workflowState: 'push',
103
- assignee: 'push',
113
+ workflowState: 'pull',
114
+ assignee: 'pull',
104
115
  }),
105
116
  localOnlySections: Object.freeze(['State log', 'Changelog', 'Open questions']),
106
117
  keyedFields: Object.freeze({}),
@@ -126,6 +137,7 @@ function defaults() {
126
137
  return {
127
138
  github: { ...g, labels: { ...g.labels }, issueTypes: { ...g.issueTypes }, labelsByKind: { ...g.labelsByKind }, severityLabels: { ...g.severityLabels } },
128
139
  mapping: { ...DEFAULT_CONFIG.mapping },
140
+ summary: { ...DEFAULT_CONFIG.summary },
129
141
  states: { ...DEFAULT_CONFIG.states },
130
142
  statesByKind: {},
131
143
  stateAliases: {},
@@ -153,7 +165,7 @@ function defaults() {
153
165
  }
154
166
 
155
167
  const { isObject, stringList, assign } = kitConfig
156
- const { mergeStates, mergeStateOverrides, mergeFieldOwnership, mergePhaseMapping, mergeReleaseIgnorePaths, mergeKeyedFields } =
168
+ const { mergeStates, mergeStateOverrides, mergeFieldOwnership, mergePhaseMapping, mergeReleaseIgnorePaths, mergeKeyedFields, mergeDescription } =
157
169
  kitConfig.makeMergeHelpers({
158
170
  configFile: CONFIG_FILE,
159
171
  ownership: OWNERSHIP,
@@ -222,6 +234,8 @@ function mergeConfig(base, parsed) {
222
234
  }
223
235
  mergePhaseMapping(base.mapping, parsed.mapping)
224
236
  }
237
+ mergeDescription(base, parsed)
238
+ if (isObject(parsed.summary)) assign(base.summary, parsed.summary, 'progressField', 'string?')
225
239
 
226
240
  mergeStates(base, parsed)
227
241
  mergeStateOverrides(base, parsed, 'statesByKind')
@@ -24,6 +24,8 @@ const prompt = require('./src/prompt.js')
24
24
  const args = require('./src/args.js')
25
25
  const adapter = require('./src/adapter.js')
26
26
  const apply = require('./src/apply.js')
27
+ const status = require('./src/status.js')
28
+ const splice = require('./src/splice.js')
27
29
 
28
30
  module.exports = {
29
31
  ...config,
@@ -38,4 +40,6 @@ module.exports = {
38
40
  ...args,
39
41
  ...adapter,
40
42
  ...apply,
43
+ ...status,
44
+ ...splice,
41
45
  }
@@ -36,6 +36,7 @@
36
36
  * - `updateSubIssue(sub)` apply a sub-issue update
37
37
  * - `remoteEditedLine(identifier)` the someone-else-edited warning
38
38
  * - `twinAdvice(twin, title, specName)` the refusal message for a twin
39
+ * - `afterIssue(issue)` optional; → a report line or null
39
40
  */
40
41
 
41
42
  const path = require('node:path')
@@ -51,6 +52,8 @@ const {
51
52
  remoteDescriptionEdited,
52
53
  remoteSubIssueEdited,
53
54
  listPhaseFiles,
55
+ descriptionMode,
56
+ spliceBlock,
54
57
  } = require('../../sync-core')
55
58
  const { makeSpecHelpers } = require('./specs.js')
56
59
 
@@ -140,11 +143,23 @@ async function applyInner({ dir, config, snapshotDir, plan, adapter, ops, progre
140
143
  lines.push(ops.remoteEditedLine(identifier))
141
144
  }
142
145
  if (plan.issue) {
143
- await ops.updateIssue(existing, plan.issue)
146
+ const issue = spliced(plan.issue, 'description', existing, config, identifier, lines)
147
+ await ops.updateIssue(existing, issue)
144
148
  lines.push(` issue updated: ${identifier}`)
145
149
  }
146
150
  }
147
151
 
152
+ // A provider's per-push extra on the spec issue (e.g. progress mirrored into
153
+ // a native field). Never fatal: the repo and the block already carry it.
154
+ if (ops.afterIssue && result.issue) {
155
+ try {
156
+ const line = await ops.afterIssue(result.issue)
157
+ if (line) lines.push(line)
158
+ } catch (error) {
159
+ lines.push(` ?? ${result.issue.identifier}: ${String((error && error.message) || error).split('\n')[0]}`)
160
+ }
161
+ }
162
+
148
163
  // 4. Sub-issue creates — each stamped as it lands, for the same reason.
149
164
  for (const sub of (plan.subIssues && plan.subIssues.create) || []) {
150
165
  const created = await ops.mintSubIssue(parentId, sub)
@@ -167,11 +182,15 @@ async function applyInner({ dir, config, snapshotDir, plan, adapter, ops, progre
167
182
  // issue. The read is spent only where the snapshot recorded something to
168
183
  // compare against, so an old snapshot costs no extra calls.
169
184
  const base = readBase(dir, identifier, config)
170
- for (const sub of (plan.subIssues && plan.subIssues.update) || []) {
185
+ const summary = descriptionMode(config) === 'summary'
186
+ for (let sub of (plan.subIssues && plan.subIssues.update) || []) {
171
187
  const streams = base && base.subIssueStreams
172
- if (sub.goal != null && streams && streams[String(sub.id)]) {
188
+ const compare = sub.goal != null && streams && streams[String(sub.id)]
189
+ // Summary mode always reads the live body: the block is spliced into it.
190
+ if (compare || (summary && sub.goal != null)) {
173
191
  const before = await adapter.readIssue(sub.id)
174
- if (remoteSubIssueEdited(base, sub.id, before, config) === true) lines.push(ops.remoteEditedLine(sub.id))
192
+ if (compare && remoteSubIssueEdited(base, sub.id, before, config) === true) lines.push(ops.remoteEditedLine(sub.id))
193
+ sub = spliced(sub, 'goal', before, config, sub.id, lines)
175
194
  }
176
195
  await ops.updateSubIssue(sub)
177
196
  result.subIssues[sub.ref || refById.get(String(sub.id)) || sub.id] = sub.id
@@ -198,6 +217,32 @@ async function applyInner({ dir, config, snapshotDir, plan, adapter, ops, progre
198
217
  return { result, lines, lost }
199
218
  }
200
219
 
220
+ /**
221
+ * Under `mapping.description: "summary"` the planned body is the block alone,
222
+ * and the write must be the block SPLICED into what the tracker holds, so the
223
+ * team's text around it survives. `spec` mode returns the payload untouched.
224
+ *
225
+ * A damaged block (a delimiter someone edited) is cannot-tell: the body is
226
+ * left out of the write entirely and the run says so. Guessing the edges would
227
+ * eat the team's text, and prepending would leave two blocks.
228
+ */
229
+ function spliced(payload, key, live, config, label, lines) {
230
+ if (descriptionMode(config) !== 'summary' || payload[key] == null) return payload
231
+ const hook = config && config.remote && config.remote.description
232
+ const current = live && typeof hook === 'function' ? hook(live) : live ? live.description : undefined
233
+ // Nothing read back is not an empty body: write nothing rather than guess.
234
+ if (typeof current !== 'string') {
235
+ lines.push(` ?? ${label}: could not read its body — summary block not written`)
236
+ return { ...payload, [key]: undefined }
237
+ }
238
+ const next = spliceBlock(current, payload[key], config)
239
+ if (next == null) {
240
+ lines.push(` !! ${label}: its summary block's delimiters were edited — block not written; repair them and re-push`)
241
+ return { ...payload, [key]: undefined }
242
+ }
243
+ return { ...payload, [key]: next }
244
+ }
245
+
201
246
  // The phase file a sub-issue ref names — the ref is the phase-file basename.
202
247
  function resolvePhaseFileIn(snapshotDir, ref) {
203
248
  const want = String(ref).replace(/\.md$/, '')
@@ -13,6 +13,12 @@
13
13
  * the operator is in the tracker, which is the fact assignment rests on.
14
14
  * - `users [<query>]` finds a person to hand a spec to.
15
15
  *
16
+ * Under `sync.fieldOwnership.assignee: "pull"` the TRACKER owns the field, so
17
+ * `assign` writes the ticket directly and stamps nothing into the repo — there
18
+ * is no projection to carry it, and a stamp would be a copy someone has to
19
+ * keep in step. `--if-unassigned` is how `/spec-start` claims a ticket nobody
20
+ * holds without ever taking one from someone who does.
21
+ *
16
22
  * Everything tracker-shaped arrives as a hook (`makeAssignmentCommands`): the
17
23
  * tracker's name for messages, the frontmatter fields, the store scope, how a
18
24
  * credential resolves and how an adapter is made. The behaviour is the Linear
@@ -21,9 +27,10 @@
21
27
 
22
28
  const path = require('node:path')
23
29
 
24
- const { ownsField, writeFrontmatter, deleteFrontmatter, fieldsOf } = require('../../sync-core')
30
+ const { ownsField, ownershipOf, writeFrontmatter, deleteFrontmatter, fieldsOf, readSnapshot } = require('../../sync-core')
25
31
  const { resolveTransport } = require('./transport.js')
26
32
  const { makeSpecHelpers } = require('./specs.js')
33
+ const { readStatus } = require('./status.js')
27
34
 
28
35
  /**
29
36
  * @param {object} p
@@ -58,6 +65,7 @@ function makeAssignmentCommands(p) {
58
65
 
59
66
  const problems = []
60
67
  if (flags.release && flags.to) problems.push('--release and --to are opposites — pass one')
68
+ if (flags.release && flags.ifUnassigned) problems.push('--if-unassigned guards an assignment — it has nothing to say about --release')
61
69
  if (!flags.release && !flags.to) problems.push('nothing to do — pass --to <user-id> or --release')
62
70
  // An unlinked spec has no issue to assign. Refusing beats stamping a field
63
71
  // that would sit in the file doing nothing until someone noticed.
@@ -86,6 +94,19 @@ function makeAssignmentCommands(p) {
86
94
  return 1
87
95
  }
88
96
 
97
+ if (ownershipOf(config, 'assignee') === 'pull') return assignOnTracker(config, identifier, flags, out)
98
+
99
+ // Under `push` the repo's stamp IS the record, so that is what the guard asks.
100
+ if (flags.ifUnassigned) {
101
+ const { frontmatter } = readSnapshot(snapshotDir, config)
102
+ const recorded = frontmatter[fields.assigneeId]
103
+ if (recorded) {
104
+ const shown = (fields.assigneeName && frontmatter[fields.assigneeName]) || recorded
105
+ out.write(`spec-sync assign: ${rel} is already assigned to ${shown} — left alone\n`)
106
+ return 0
107
+ }
108
+ }
109
+
89
110
  if (flags.release) {
90
111
  const removed = deleteFrontmatter(snapshotDir, config, [fields.assigneeId, fields.assigneeName].filter(Boolean))
91
112
  if (flags.json) {
@@ -116,6 +137,62 @@ function makeAssignmentCommands(p) {
116
137
  return 0
117
138
  }
118
139
 
140
+ /**
141
+ * The `pull` half of `assign`: write the ticket, stamp nothing.
142
+ *
143
+ * `--if-unassigned` reads the ticket first and acts only on a POSITIVE
144
+ * "nobody holds it". A read that could not run is cannot-tell, and the
145
+ * harmless branch is to assign nobody: taking a ticket from a colleague is
146
+ * the one mistake here that costs someone else their afternoon.
147
+ *
148
+ * Exits 0 on every cannot-tell (MCP transport, no credential, an unreadable
149
+ * ticket) and 1 only when the tracker refused a write it was asked to make.
150
+ */
151
+ async function assignOnTracker(config, identifier, flags, out) {
152
+ const say = (line) => {
153
+ out.write(`spec-sync assign: ${line}\n`)
154
+ return 0
155
+ }
156
+ const report = (result) => {
157
+ if (flags.json) {
158
+ out.write(JSON.stringify({ issue: identifier, owner: 'tracker', ...result }, null, 2) + '\n')
159
+ return 0
160
+ }
161
+ return say(result.line)
162
+ }
163
+ const cred = flags.adapter ? { ok: true } : p.resolveCredential(config, flags.env || process.env)
164
+ const transport = resolveTransport(flags, config, cred.ok)
165
+ if (transport === 'mcp' || !cred.ok) {
166
+ const what = flags.release ? 'unassign it' : `assign it to ${flags.to}`
167
+ return report({
168
+ written: false,
169
+ line: `${p.tracker} owns the assignee here, and there is no API transport — ${what} on ${identifier} with the tracker's own tool; nothing was written`,
170
+ })
171
+ }
172
+ const adapter = flags.adapter || p.makeAdapter(config, cred, flags)
173
+
174
+ if (flags.ifUnassigned) {
175
+ const now = await readStatus({ adapter, ref: identifier, config })
176
+ if (!now.ok) {
177
+ return report({ written: false, line: `could not read ${identifier} (${now.reason}) — assigned nobody` })
178
+ }
179
+ if (now.assignee) {
180
+ const who = now.assignee.name || now.assignee.id
181
+ return report({ written: false, assignee: now.assignee, line: `${identifier} is already assigned to ${who} — left alone` })
182
+ }
183
+ }
184
+
185
+ try {
186
+ await adapter.updateIssue(identifier, { assigneeId: flags.release ? null : flags.to })
187
+ } catch (error) {
188
+ out.write(`spec-sync assign: ${p.tracker} refused — ${String(error.message).split('\n')[0]}\n`)
189
+ return 1
190
+ }
191
+ if (flags.release) return report({ written: true, released: true, line: `${identifier} unassigned on ${p.tracker}` })
192
+ const who = flags.name ? `${flags.name} (${flags.to})` : flags.to
193
+ return report({ written: true, id: flags.to, name: flags.name || null, line: `${identifier} assigned to ${who} on ${p.tracker}` })
194
+ }
195
+
119
196
  /**
120
197
  * Exit 0 even when the answer is "unknown": this answers a question, and
121
198
  * "nobody is identified here" is a valid answer — a shared key, an offline
@@ -236,6 +236,33 @@ function makeMergeHelpers({ configFile, ownership, lifecycleBuckets, phaseMappin
236
236
  base[key] = table
237
237
  }
238
238
 
239
+ // Merge (and validate) what a ticket's description carries —
240
+ // `mapping.description` (`spec` · `summary`) and the block's delimiter style
241
+ // (`summary.delimiter`: `comment` · `heading`). Loud on a bad value: a typo
242
+ // must not read as a choice to keep pushing the whole spec.
243
+ function mergeDescription(base, parsed) {
244
+ if (isObject(parsed.mapping) && parsed.mapping.description !== undefined) {
245
+ const mode = parsed.mapping.description
246
+ if (!DESCRIPTION_MODES.includes(mode)) {
247
+ throw new Error(
248
+ `Invalid ${configFile}: mapping.description = ${JSON.stringify(mode)} ` +
249
+ `(expected one of ${DESCRIPTION_MODES.join('|')})`,
250
+ )
251
+ }
252
+ base.mapping.description = mode
253
+ }
254
+ if (isObject(parsed.summary) && parsed.summary.delimiter !== undefined) {
255
+ const style = parsed.summary.delimiter
256
+ if (!DELIMITER_STYLES.includes(style)) {
257
+ throw new Error(
258
+ `Invalid ${configFile}: summary.delimiter = ${JSON.stringify(style)} ` +
259
+ `(expected one of ${DELIMITER_STYLES.join('|')})`,
260
+ )
261
+ }
262
+ base.summary = { ...(base.summary || {}), delimiter: style }
263
+ }
264
+ }
265
+
239
266
  return {
240
267
  mergeStates,
241
268
  mergeStateOverrides,
@@ -243,9 +270,15 @@ function makeMergeHelpers({ configFile, ownership, lifecycleBuckets, phaseMappin
243
270
  mergePhaseMapping,
244
271
  mergeReleaseIgnorePaths,
245
272
  mergeKeyedFields,
273
+ mergeDescription,
246
274
  }
247
275
  }
248
276
 
277
+ // What `mapping.description` may be. `spec` is the default and what a config
278
+ // that predates the key gets, so an upgrade rewrites no ticket.
279
+ const DESCRIPTION_MODES = Object.freeze(['spec', 'summary'])
280
+ const DELIMITER_STYLES = Object.freeze(['comment', 'heading'])
281
+
249
282
  // Keys no provider reads any more. The merge already ignores them, as it does
250
283
  // every unknown key — so a config still carrying one is a stale file, not a
251
284
  // broken one, and `doctor` says so as a `warn` without touching the exit code.
@@ -292,4 +325,4 @@ function retiredKeysRow(file, configFile, row) {
292
325
  )
293
326
  }
294
327
 
295
- module.exports = { isObject, stringList, assign, makeMergeHelpers, retiredKeys, retiredKeysRow, RETIRED_KEYS }
328
+ module.exports = { isObject, stringList, assign, makeMergeHelpers, retiredKeys, retiredKeysRow, RETIRED_KEYS, DESCRIPTION_MODES, DELIMITER_STYLES }
@@ -14,22 +14,46 @@ function expandStateArgs(args, config) {
14
14
  return (args || []).flatMap((arg) => (LIFECYCLE_BUCKETS.includes(arg) ? stateNamesFor(arg, config) : [arg]))
15
15
  }
16
16
 
17
- // The spec's status beside the board's, and whether they disagree. A board
18
- // state that maps to no bucket never disagrees: it is somewhere push does not
19
- // manage, which is not a claim about the spec. Nor does a row whose spec is not
20
- // on this machine — there is nothing to disagree WITH.
17
+ // A spec's bucket is a CODE FACT — whether `/spec-start`, `/spec-complete` or
18
+ // `/spec-cancel` has run — and the board holds the planning status. So almost
19
+ // every difference between the two is the board doing its job: a backlog spec
20
+ // the board calls Ready or Blocked, an in-flight one it calls In Review. Neither
21
+ // is a claim about the repo, and flagging them would teach a reader to ignore
22
+ // the column.
23
+ //
24
+ // One difference IS worth a reader's time: the board says the work is finished
25
+ // (Done or Cancelled) and the repo has not done the matching cleanup. Only that
26
+ // pairing disagrees, and it carries the command that would close it.
27
+ const LIVE_BUCKETS = ['backlog', 'in-progress']
28
+ const FINISHED_BUCKETS = ['complete', 'cancelled']
29
+
30
+ // `{ board, cleanup }` when the board has finished what the repo has not, else
31
+ // null. Done against a spec in flight is `/spec-complete`; every other pairing
32
+ // (Cancelled, or Done on a spec that never started) is `/spec-cancel`, because
33
+ // there is no work here to complete.
34
+ function boardDisagreement(specBucket, boardBucket) {
35
+ if (!LIVE_BUCKETS.includes(specBucket) || !FINISHED_BUCKETS.includes(boardBucket)) return null
36
+ const cleanup = specBucket === 'in-progress' && boardBucket === 'complete' ? '/spec-complete' : '/spec-cancel'
37
+ return { board: boardBucket, cleanup }
38
+ }
39
+
40
+ // The spec's status beside the board's, and whether they disagree in the one
41
+ // way above. A board state that maps to no bucket never disagrees: it is
42
+ // somewhere push does not manage, which is not a claim about the spec. Nor does
43
+ // a row whose spec is not on this machine — there is nothing to disagree WITH.
21
44
  function specColumn(stateName, spec, config) {
22
45
  const specStatus = spec ? spec.bucket : null
23
46
  const seen = stateName == null ? null : remoteStateReading({ state: { name: stateName } }, config)
24
- const disagrees = Boolean(specStatus && seen && seen.mapped && seen.bucket !== specStatus)
25
- return { specStatus, disagrees }
47
+ const found = specStatus && seen && seen.mapped ? boardDisagreement(specStatus, seen.bucket) : null
48
+ return found ? { specStatus, disagrees: true, cleanup: found.cleanup } : { specStatus, disagrees: false }
26
49
  }
27
50
 
28
- // The cell itself: `in-progress`, `≠ backlog` when it disagrees, `—` when the
29
- // spec is not here.
30
- function specCell({ specStatus, disagrees }) {
51
+ // The cell itself: `in-progress`, `≠ in-progress → /spec-cancel` when the board
52
+ // finished it, `—` when the spec is not here.
53
+ function specCell({ specStatus, disagrees, cleanup }) {
31
54
  if (!specStatus) return '—'
32
- return disagrees ? `≠ ${specStatus}` : specStatus
55
+ if (!disagrees) return specStatus
56
+ return cleanup ? `≠ ${specStatus} → ${cleanup}` : `≠ ${specStatus}`
33
57
  }
34
58
 
35
- module.exports = { expandStateArgs, specColumn, specCell }
59
+ module.exports = { expandStateArgs, specColumn, specCell, boardDisagreement }
@@ -146,7 +146,10 @@ function ticketsInRange(commits, options = {}) {
146
146
  let unreferenced = 0
147
147
  let ignored = 0
148
148
  let historical = 0
149
+ let merges = 0
150
+ let sawMergeFlag = false
149
151
  for (const commit of commits || []) {
152
+ if (commit && commit.isMerge !== undefined) sawMergeFlag = true
150
153
  if (onlyIgnoredPaths(commit && commit.paths, ignorePaths)) {
151
154
  // Not counted as unreferenced either: that number exists to surface a
152
155
  // MISSED trailer, and a paperwork commit is not a gap someone should hunt.
@@ -157,8 +160,15 @@ function ticketsInRange(commits, options = {}) {
157
160
  if (!refs.length) {
158
161
  // A POSITIVE signal, never an absence: only a trailer that actually
159
162
  // carries an older tracker's ref makes a commit historical. A commit with
160
- // no trailer at all is still the gap `unreferenced` is there to name.
163
+ // no trailer at all is still the gap `unreferenced` is there to name —
164
+ // unless it is a MERGE commit, which is transport: under PR landing the
165
+ // host writes one per merged PR, and counting each as a missed trailer
166
+ // buries the real gaps. A merge that CARRIES a trailer still counted
167
+ // above, deliberately — a hand merge is where a ticket's only trailer
168
+ // sometimes lives, which is why these are read rather than skipped
169
+ // (`--no-merges` was tried and dropped for exactly that loss).
161
170
  if (foreign.some((p) => refsInBody(commit && commit.body, p).length)) historical++
171
+ else if (commit && commit.isMerge) merges++
162
172
  else unreferenced++
163
173
  continue
164
174
  }
@@ -171,6 +181,9 @@ function ticketsInRange(commits, options = {}) {
171
181
  total: (commits || []).length,
172
182
  }
173
183
  if (foreign.length) report.historical = historical
184
+ // Present only when a caller supplied the flag at all, so a provider that
185
+ // passes no parent info sees exactly the report shape it always did.
186
+ if (sawMergeFlag) report.merges = merges
174
187
  return report
175
188
  }
176
189
 
@@ -24,7 +24,7 @@ const {
24
24
  resolvePrimaryCheckout,
25
25
  } = require('../../../env/resolve.js')
26
26
  const { loadEnvConfig } = require('../../../env/config.js')
27
- const { readSnapshot, parseFrontmatter, lintPhases, fieldsOf, projectionOf, compareStored } = require('../../sync-core')
27
+ const { readSnapshot, parseFrontmatter, lintPhases, fieldsOf, projectionOf, compareStored, comparableDescription } = require('../../sync-core')
28
28
 
29
29
  function makeSpecHelpers({ program = 'spec-sync' } = {}) {
30
30
  // Resolve a spec argument to its snapshot dir. Accepts a spec name/folder
@@ -227,7 +227,9 @@ function makeSpecHelpers({ program = 'spec-sync' } = {}) {
227
227
  bad++
228
228
  continue
229
229
  }
230
- const r = compareStored(sent, got, config)
230
+ // Summary mode compares the block alone: the text around it is the
231
+ // team's. Right after a write a missing block IS a loss, so it reads as ''.
232
+ const r = compareStored(sent, comparableDescription(got, config) ?? '', config)
231
233
  if (r.ok) continue
232
234
  bad++
233
235
  lines.push(