@skitterbyte/skitterspec-linear 19.3.0 → 19.5.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 (71) hide show
  1. package/assets/claude-md-section.md +20 -1
  2. package/assets/core/SETUP.md +5 -0
  3. package/assets/core/env.config.json.example +1 -0
  4. package/assets/core/env.config.md +143 -8
  5. package/assets/core/linear.config.json.example +2 -2
  6. package/assets/core/linear.config.md +49 -16
  7. package/assets/hooks/main-guard.cjs +40 -6
  8. package/assets/hooks/review-gate.cjs +42 -7
  9. package/assets/rules/commit-trailers.md +24 -1
  10. package/assets/rules/spec-planning.md +81 -18
  11. package/assets/rules/spec-reports.md +1 -1
  12. package/assets/skills/spec/SKILL.md +55 -2
  13. package/assets/skills/spec-bug/SKILL.md +36 -3
  14. package/assets/skills/spec-cancel/SKILL.md +37 -0
  15. package/assets/skills/spec-claim/SKILL.md +41 -2
  16. package/assets/skills/spec-complete/SKILL.md +115 -0
  17. package/assets/skills/spec-hotfix/SKILL.md +51 -4
  18. package/assets/skills/spec-incident/SKILL.md +22 -0
  19. package/assets/skills/spec-linear-setup/SKILL.md +23 -1
  20. package/assets/skills/spec-next/SKILL.md +12 -5
  21. package/assets/skills/spec-push/SKILL.md +22 -0
  22. package/assets/skills/spec-review/SKILL.md +34 -0
  23. package/assets/skills/spec-start/SKILL.md +50 -3
  24. package/assets/skills/spec-status/SKILL.md +18 -3
  25. package/assets/skills/spec-sync/SKILL.md +1 -0
  26. package/assets/skills/spec-to-main/SKILL.md +47 -1
  27. package/package.json +1 -1
  28. package/src/cli.js +1188 -79
  29. package/src/env/base.js +104 -0
  30. package/src/env/bootstrap.js +22 -3
  31. package/src/env/classify.js +12 -4
  32. package/src/env/config.js +77 -5
  33. package/src/env/disposition.js +62 -0
  34. package/src/env/handoff.js +81 -0
  35. package/src/env/host.js +262 -0
  36. package/src/env/hotfix.js +237 -9
  37. package/src/env/hotfixland.js +105 -10
  38. package/src/env/inflight.js +98 -0
  39. package/src/env/integrate.js +136 -9
  40. package/src/env/live.js +8 -7
  41. package/src/env/mainguard.js +20 -5
  42. package/src/env/phases.js +28 -0
  43. package/src/env/project.js +223 -0
  44. package/src/env/provision.js +30 -8
  45. package/src/env/resolve.js +147 -25
  46. package/src/env/review.js +21 -7
  47. package/src/env/reviewers.js +7 -10
  48. package/src/env/serve.js +27 -11
  49. package/src/env/specstate.js +101 -0
  50. package/src/env/supervise.js +15 -2
  51. package/src/env/teardown.js +46 -3
  52. package/src/init.js +49 -9
  53. package/src/vendor/linear/cli-sanitise.js +8 -3
  54. package/src/vendor/linear/cli-sync.js +64 -10
  55. package/src/vendor/linear/config.js +27 -21
  56. package/src/vendor/linear/doctor.js +2 -0
  57. package/src/vendor/provider-kit/index.js +4 -0
  58. package/src/vendor/provider-kit/src/apply.js +58 -6
  59. package/src/vendor/provider-kit/src/assignment.js +78 -1
  60. package/src/vendor/provider-kit/src/config.js +34 -1
  61. package/src/vendor/provider-kit/src/credentials.js +7 -2
  62. package/src/vendor/provider-kit/src/list-rows.js +35 -11
  63. package/src/vendor/provider-kit/src/released.js +48 -4
  64. package/src/vendor/provider-kit/src/specs.js +18 -7
  65. package/src/vendor/provider-kit/src/splice.js +64 -0
  66. package/src/vendor/provider-kit/src/status.js +137 -0
  67. package/src/vendor/sync-core/index.js +14 -1
  68. package/src/vendor/sync-core/src/compare.js +81 -6
  69. package/src/vendor/sync-core/src/normalize.js +50 -7
  70. package/src/vendor/sync-core/src/push.js +65 -5
  71. package/src/vendor/sync-core/src/summary.js +257 -0
@@ -25,7 +25,7 @@ const path = require('node:path')
25
25
 
26
26
  const { BUCKETS, findSpecFolder, branchFor, splitPrefix, currentBranch } = require('../../env/resolve.js')
27
27
  const { loadEnvConfig } = require('../../env/config.js')
28
- const { ticketsInRange, nameTickets, refuseRemovedVerb } = require('./released.js')
28
+ const { ticketsInRange, nameTickets, refuseRemovedVerb, projectPrefixOf } = require('./released.js')
29
29
  const { retiredKeysRow } = require('../provider-kit/src/config.js')
30
30
  const { doctorRow } = require('../provider-kit/src/doctor.js')
31
31
  const { execFileSync } = require('node:child_process')
@@ -84,7 +84,9 @@ const {
84
84
  } = require('./credentials.js')
85
85
  const { resolveIdentity, displayNameOf } = require('./identity.js')
86
86
  const { makeAssignmentCommands } = require('../provider-kit/src/assignment.js')
87
+ const { specSyncOwnership, specSyncBoard: kitBoard, ownershipDoctorRow } = require('../provider-kit/src/status.js')
87
88
  const { resolveTransport } = require('../provider-kit/src/transport.js')
89
+ const { specSyncSplice } = require('../provider-kit/src/splice.js')
88
90
 
89
91
  // `assign`, `whoami` and `users` are the kit's (`provider-kit/src/assignment.js`),
90
92
  // hoisted when the GitHub provider became their second consumer. What is
@@ -115,6 +117,24 @@ const assignment = makeAssignmentCommands({
115
117
  usersOverMcp: 'search the workspace over MCP with the user-list tool',
116
118
  })
117
119
  const specSyncAssign = (dir, config, specArg, flags, out) => assignment.assign(dir, config, specArg, flags, out)
120
+
121
+ // `board <spec>` — has Linear finished what this repo has not? The kit's
122
+ // (`provider-kit/src/status.js`): one line on a disagreement, silent otherwise.
123
+ async function specSyncBoard(dir, config, specArg, flags, out) {
124
+ const snapshotDir = resolveOrExit(specArg, dir, out)
125
+ if (!snapshotDir) return 1
126
+ const key = resolveApiKey(config, flags.env || process.env)
127
+ const transport = resolveTransport(flags, config, key.ok || !!flags.adapter)
128
+ const credential =
129
+ transport === 'mcp'
130
+ ? { ok: false, error: 'transport = mcp — no API read' }
131
+ : flags.adapter
132
+ ? { ok: true, adapter: flags.adapter }
133
+ : key.ok
134
+ ? { ok: true, adapter: makeApiAdapter({ apiKey: key.key, fetch: flags.fetch }) }
135
+ : { ok: false, error: key.error }
136
+ return kitBoard({ snapshotDir, config, credential, flags, out, tracker: 'Linear', program: 'spec-sync' })
137
+ }
118
138
  const specSyncWhoami = (dir, config, flags, out) => assignment.whoami(dir, config, flags, out)
119
139
  const specSyncUsers = (dir, config, query, flags, out) => assignment.users(dir, config, query, flags, out)
120
140
  const { readAllStdin, promptHidden } = require('../provider-kit/src/prompt.js')
@@ -417,7 +437,7 @@ function specSyncRecord(dir, config, specArg, out) {
417
437
  if (!snapshotDir) return 1
418
438
  const identifier = specIdentifier(snapshotDir, config)
419
439
  const file = recordPush({ dir, snapshotDir, identifier, config })
420
- out.write(`spec-sync record: snapshot written → ${path.relative(dir, file)}\n`)
440
+ out.write(`spec-sync record: snapshot written → ${path.relative(dir, file).split(path.sep).join('/')}\n`)
421
441
  }
422
442
 
423
443
  // `spec-sync status <spec> [--remote file] [--workspace-states file]` — read-only
@@ -883,6 +903,7 @@ function gatherState(dir, flags) {
883
903
  }
884
904
 
885
905
  state._config = config
906
+ if (config) state.ownership = ownershipDoctorRow(config)
886
907
  state.retired = retiredKeysRow(path.join(dir, CONFIG_FILE), CONFIG_FILE, doctorRow)
887
908
  return state
888
909
  }
@@ -1027,7 +1048,10 @@ function readCommitRange(dir, rangeArg, verb) {
1027
1048
 
1028
1049
  // NUL-delimited so a subject or body containing the separator cannot split a
1029
1050
  // record; RS between commits for the same reason.
1030
- const raw = git(['log', '--format=%H%x00%s%x00%b%x1e', range])
1051
+ // %P rides with the sha so a merge commit can be told apart: its trailers
1052
+ // are READ (a hand merge is where a ticket's only trailer sometimes lives),
1053
+ // but a trailer-less merge counts as transport rather than a gap.
1054
+ const raw = git(['log', '--format=%H %P%x00%s%x00%b%x1e', range])
1031
1055
  if (raw === null) {
1032
1056
  return { error: [`spec-sync ${verb}: git could not resolve the range "${range}".`] }
1033
1057
  }
@@ -1037,8 +1061,9 @@ function readCommitRange(dir, rangeArg, verb) {
1037
1061
  .map((r) => r.replace(/^\n/, ''))
1038
1062
  .filter((r) => r.trim())
1039
1063
  .map((record) => {
1040
- const [sha, subject, ...rest] = record.split('\x00')
1041
- return { sha, subject, body: rest.join('\x00') }
1064
+ const [idLine, subject, ...rest] = record.split('\x00')
1065
+ const [sha, ...parents] = String(idLine).trim().split(/\s+/).filter(Boolean)
1066
+ return { sha, isMerge: parents.length > 1, subject, body: rest.join('\x00') }
1042
1067
  })
1043
1068
 
1044
1069
  // What each commit CHANGED, so bookkeeping can be told from shipped work. A
@@ -1060,7 +1085,11 @@ async function specSyncReleased(dir, config, rangeArg, flags, out) {
1060
1085
  }
1061
1086
  const { range, commits } = read
1062
1087
 
1063
- const report = ticketsInRange(commits, { ignorePaths: releaseIgnorePaths(config) })
1088
+ const report = ticketsInRange(commits, {
1089
+ ignorePaths: releaseIgnorePaths(config),
1090
+ // A nested project's commits carry its folder in every path (feat-subfolder-project).
1091
+ prefix: projectPrefixOf(dir),
1092
+ })
1064
1093
  report.tickets = nameTickets(report.tickets, listSpecs(dir, config, { urls: true }))
1065
1094
 
1066
1095
  // Titles are an ENRICHMENT: the scan itself is offline. No key, the MCP
@@ -1104,6 +1133,7 @@ async function specSyncReleased(dir, config, rangeArg, flags, out) {
1104
1133
  // MISSED trailer looks identical, so silence here would read as "everything is
1105
1134
  // accounted for".
1106
1135
  lines.push(` ${report.unreferenced} commit(s) carry no ref`)
1136
+ if (report.merges) lines.push(` ${report.merges} merge commit(s) — transport, not counted as gaps`)
1107
1137
  // A filter that removes commits without saying so reads as "there was nothing
1108
1138
  // there". Named only when it actually fired — on a project with no paperwork
1109
1139
  // in the range there is nothing to disclose.
@@ -1994,6 +2024,7 @@ async function specSyncList(dir, config, flags, out) {
1994
2024
 
1995
2025
  const rows = ordered.map((issue) => {
1996
2026
  const local = byIdentifier.get(issue.identifier) || null
2027
+ const column = specColumn((issue.state && issue.state.name) || null, local, config)
1997
2028
  return {
1998
2029
  identifier: issue.identifier || '',
1999
2030
  title: issue.title || '',
@@ -2004,7 +2035,9 @@ async function specSyncList(dir, config, flags, out) {
2004
2035
  // close, so hiding it would defeat the command.
2005
2036
  spec: local ? local.spec : null,
2006
2037
  bucket: local ? local.bucket : null,
2007
- disagrees: specColumn((issue.state && issue.state.name) || null, local, config).disagrees,
2038
+ disagrees: column.disagrees,
2039
+ // The command that closes it — present only on a disagreeing row.
2040
+ ...(column.cleanup ? { cleanup: column.cleanup } : {}),
2008
2041
  assignee: (issue.assignee && issue.assignee.name) || null,
2009
2042
  // Filled in below for in-progress rows only; `null` on every row that was
2010
2043
  // never looked up, so the shape does not vary by state.
@@ -2140,7 +2173,7 @@ async function specSyncList(dir, config, flags, out) {
2140
2173
  } else {
2141
2174
  const idW = Math.max(...shown.map((r) => r.identifier.length))
2142
2175
  const stW = Math.max(...shown.map((r) => r.state.length))
2143
- const cell = (r) => specCell({ specStatus: r.bucket, disagrees: r.disagrees })
2176
+ const cell = (r) => specCell({ specStatus: r.bucket, disagrees: r.disagrees, cleanup: r.cleanup })
2144
2177
  const bkW = Math.max(...shown.map((r) => cell(r).length))
2145
2178
  const pad = ' '.repeat(idW + stW + bkW + 6)
2146
2179
  const specW = Math.max(...shown.map((r) => (r.spec || UNLINKED).length))
@@ -2622,7 +2655,8 @@ function labelList(value) {
2622
2655
  */
2623
2656
  function specSyncInitConfig(dir, flags, out) {
2624
2657
  const file = path.join(dir, CONFIG_FILE)
2625
- const rel = CONFIG_FILE
2658
+ // Printed, so `/`-separated on every platform.
2659
+ const rel = CONFIG_FILE.split(path.sep).join('/')
2626
2660
  const existed = fs.existsSync(file)
2627
2661
  const fail = (lines, extra = {}) => {
2628
2662
  if (flags.json) {
@@ -2656,6 +2690,10 @@ function specSyncInitConfig(dir, flags, out) {
2656
2690
  if (flags.teamKey) linear.teamKey = flags.teamKey
2657
2691
  if (flags.projectId) linear.projectId = flags.projectId
2658
2692
  draft.linear = linear
2693
+ // A NEW config carries a summary, not the spec: written explicitly, so the
2694
+ // file says what the ticket gets. A config that predates the key keeps
2695
+ // pushing the spec (the loader's default), so an upgrade rewrites nothing.
2696
+ draft.mapping = { description: flags.description || 'summary' }
2659
2697
  const intake = {}
2660
2698
  if (flags.intakeLabel) intake.label = flags.intakeLabel
2661
2699
  if (flags.bugLabels.length) intake.bugLabels = flags.bugLabels
@@ -3317,6 +3355,9 @@ async function specSync(rest, io = {}) {
3317
3355
  else if (args[i] === '--apply') flags.apply = true
3318
3356
  else if (args[i] === '--remote') flags.remote = path.resolve(args[++i])
3319
3357
  else if (args[i] === '--stored') flags.stored = path.resolve(args[++i])
3358
+ else if (args[i] === '--live') flags.live = path.resolve(args[++i])
3359
+ else if (args[i] === '--description') flags.description = args[++i]
3360
+ else if (args[i] === '--phase') flags.phase = args[++i]
3320
3361
  // `preserve --text <file>`: the description to keep, when the caller read it
3321
3362
  // over MCP and the engine cannot.
3322
3363
  else if (args[i] === '--text') flags.text = path.resolve(args[++i])
@@ -3355,6 +3396,7 @@ async function specSync(rest, io = {}) {
3355
3396
  else if (args[i] === '--unset') flags.unset = true
3356
3397
  else if (args[i] === '--to') flags.to = String(args[++i] || '').trim()
3357
3398
  else if (args[i] === '--release') flags.release = true
3399
+ else if (args[i] === '--if-unassigned') flags.ifUnassigned = true
3358
3400
  else if (args[i] === '--no-assign') flags.noAssign = true
3359
3401
  else if (args[i] === '--limit') flags.limit = Number(args[++i]) || 0
3360
3402
  else if (args[i] === '--cursor') flags.cursor = String(args[++i] || '').trim()
@@ -3490,6 +3532,11 @@ async function specSync(rest, io = {}) {
3490
3532
  return (await specSyncRetarget(dir, config, flags, out)) || 0
3491
3533
  case 'apply':
3492
3534
  return (await specSyncApply(dir, config, positional[0], flags, out)) || 0
3535
+ case 'splice': {
3536
+ const snapshotDir = resolveOrExit(positional[0], dir, err)
3537
+ if (!snapshotDir) return 1
3538
+ return specSyncSplice({ snapshotDir, config, flags, out, err, program: 'spec-sync' })
3539
+ }
3493
3540
  case 'verify':
3494
3541
  return specSyncVerify(dir, config, positional[0], flags, out) || 0
3495
3542
  case 'preserve':
@@ -3499,6 +3546,10 @@ async function specSync(rest, io = {}) {
3499
3546
  case 'linked':
3500
3547
  specSyncLinked(dir, config, flags, out)
3501
3548
  return 0
3549
+ case 'ownership':
3550
+ return specSyncOwnership(config, flags, out, 'spec-sync')
3551
+ case 'board':
3552
+ return specSyncBoard(dir, config, positional[0], flags, out)
3502
3553
  case 'credentials':
3503
3554
  return await specSyncCredentials(dir, config, positional[0], flags, out)
3504
3555
  default:
@@ -3510,14 +3561,17 @@ async function specSync(rest, io = {}) {
3510
3561
  ' skitterspec spec-sync projects [--via api|mcp] [--json]\n' +
3511
3562
  ' skitterspec spec-sync whoami [--set <id> [--name N]] [--unset] [--json]\n' +
3512
3563
  ' skitterspec spec-sync users [<name-or-email>] [--limit N] [--cursor C] [--json]\n' +
3513
- ' skitterspec spec-sync assign <spec> --to <id> [--name N] | --release [--json]\n' +
3564
+ ' skitterspec spec-sync assign <spec> --to <id> [--name N] [--if-unassigned] | --release [--json]\n' +
3514
3565
  ' skitterspec spec-sync apply <spec> --plan <file> [--via api|mcp] [--project id] [--json]\n' +
3515
3566
  ' skitterspec spec-sync apply --all <bucket> [--via api|mcp] [--json]\n' +
3516
3567
  ' skitterspec spec-sync verify <spec> --stored <file>\n' +
3568
+ ' skitterspec spec-sync splice <spec> --live <file> [--phase <ref>]\n' +
3517
3569
  ' skitterspec spec-sync preserve <spec> [--text <file>] [--via api|mcp] [--json]\n' +
3518
3570
  ' skitterspec spec-sync comment <spec> --file <file> [--via api|mcp]\n' +
3519
3571
  ' skitterspec spec-sync list [--state <name> …|--all|--in-progress] [--next N] [--mine|--by <user>] [--limit N] [--archived] [--json]\n' +
3520
3572
  ' skitterspec spec-sync linked [--json]\n' +
3573
+ ' skitterspec spec-sync ownership [--json]\n' +
3574
+ ' skitterspec spec-sync board <spec> [--json]\n' +
3521
3575
  ' skitterspec spec-sync ref [<spec>] [--json]\n' +
3522
3576
  ' skitterspec spec-sync released [<range>] [--json]\n' +
3523
3577
  ' skitterspec spec-sync reattach <spec> [--to <ISSUE-REF>] [--json]\n' +
@@ -77,7 +77,7 @@ const TASK_MAPPINGS = Object.freeze(['checklist', 'none'])
77
77
  // flight and something else entirely for work that finished long ago. A bucket
78
78
  // the map omits gets DEFAULT_PHASE_MODE, so a partial map adds an exception
79
79
  // rather than silently suppressing phases everywhere it is silent.
80
- const PHASE_MAPPINGS = Object.freeze(['subissue', 'deferred', 'inline'])
80
+ const PHASE_MAPPINGS = Object.freeze(['subissue', 'deferred', 'inline', 'none'])
81
81
  const DEFAULT_PHASE_MODE = 'subissue'
82
82
 
83
83
  // How `spec-sync apply` reaches Linear. `api` talks to the GraphQL API directly;
@@ -150,7 +150,12 @@ const DEFAULT_CONFIG = Object.freeze({
150
150
  // synced (they live only in the repo phase files).
151
151
  // A spec is an ISSUE; each phase a SUB-ISSUE of it. `tasks` selects how the
152
152
  // phase's checkboxes reach that sub-issue's description — see TASK_MAPPINGS.
153
- mapping: Object.freeze({ specFolder: 'issue', phases: DEFAULT_PHASE_MODE, tasks: 'checklist' }),
153
+ // `description`: what the ticket body carries — `spec` (the whole overview)
154
+ // or `summary` (a delimited block beside the team's own text). `spec` is the
155
+ // default so a config written before the key pushes what it always pushed.
156
+ mapping: Object.freeze({ specFolder: 'issue', phases: DEFAULT_PHASE_MODE, tasks: 'checklist', description: 'spec' }),
157
+ // The summary block's delimiters (provisional until chore-delimiter-spike-providers measures this tracker).
158
+ summary: Object.freeze({ delimiter: 'heading' }),
154
159
  // Linear ISSUE workflow-state names — the spec issue's state (from the folder
155
160
  // bucket) and each sub-issue's state (from the phase emoji) both map through
156
161
  // this one table. They must match the workspace's issue states exactly;
@@ -190,29 +195,28 @@ const DEFAULT_CONFIG = Object.freeze({
190
195
  sync: Object.freeze({
191
196
  baseDir: 'specs/.core/linear-base',
192
197
  backupDir: 'specs/.core/linear-backups',
193
- // One-way (repo → Linear): the projection field set the repo owns and pushes
194
- // — the issue `description`, its `subIssues` (one per phase, name + goal +
195
- // state), and the lifecycle `workflowState`. There is no pull. Priority,
196
- // labels, cycles and comments are Linear-native triage — deliberately NOT in
197
- // the set, so the PM's triage is never touched. The `push` marker is retained
198
- // for shape; any key you add joins the pushed projection.
198
+ // The repo owns the spec's CONTENT and pushes it one way (repo → Linear) —
199
+ // the issue `description` and its `subIssues` (one per phase, name + goal +
200
+ // state). Priority, labels, cycles and comments are Linear-native triage —
201
+ // deliberately NOT in the set, so the PM's triage is never touched.
199
202
  //
200
- // `assignee` ships ON, and the opt-out is `"assignee": "none"`. It was
201
- // opt-in until v16, and the cost of that was silent in exactly the wrong
202
- // direction: a repo that never added the line looked identical to one that
203
- // did not want the feature, so the only signal was noticing an unassigned
204
- // issue weeks later.
203
+ // Linear owns the spec's STATUS and ASSIGNEE (`pull`). The board is where a
204
+ // team assigns and moves work, so a repo copy is one somebody has to keep in
205
+ // step by hand. Under `pull` the state is sent only as a transition the repo
206
+ // made (a spec changing bucket — see `compare.js` `issueChanges`), the
207
+ // assignee is never projected, and `spec-sync assign` writes Linear directly.
208
+ // Set either back to `"push"` for the repo-owned behaviour, or `"none"` to
209
+ // leave it alone entirely.
205
210
  //
206
- // WHAT MAKES ON-BY-DEFAULT SAFE, and it is not this line: a spec that
207
- // records no assignee sends none (so a PM's triage survives), and a snapshot
208
- // with no assignee key means "never pushed" rather than "was null" (so no
209
- // upgrade emits a clear). Flipping the default widens who gets assigned; it
210
- // cannot widen who gets UNassigned. See `compare.js` `issueChanges`.
211
+ // WHAT MAKES `pull` SAFE ON UPGRADE: a pulled field asserts nothing, so the
212
+ // flip can only make pushes send LESS. A state is never re-sent from an old
213
+ // snapshot (cannot-tell routes to silence), and an assignee hash recorded
214
+ // under `push` is never compared again — so nothing is cleared on the board.
211
215
  fieldOwnership: Object.freeze({
212
216
  description: 'push',
213
217
  subIssues: 'push',
214
- workflowState: 'push',
215
- assignee: 'push',
218
+ workflowState: 'pull',
219
+ assignee: 'pull',
216
220
  }),
217
221
  localOnlySections: Object.freeze(['State log', 'Changelog', 'Open questions']),
218
222
  // Fields that are keyed collections (arrays of objects with a stable id),
@@ -283,6 +287,7 @@ function defaults() {
283
287
  preserveOriginal: DEFAULT_CONFIG.intake.preserveOriginal,
284
288
  },
285
289
  mapping: { ...DEFAULT_CONFIG.mapping },
290
+ summary: { ...DEFAULT_CONFIG.summary },
286
291
  states: { ...DEFAULT_CONFIG.states },
287
292
  statesByKind: {},
288
293
  stateAliases: {},
@@ -308,7 +313,7 @@ function defaults() {
308
313
  // vocabularies; `mergeConfig` below is the part that is Linear's — which keys
309
314
  // exist and how they nest.
310
315
  const { isObject, stringList, assign } = kitConfig
311
- const { mergeStates, mergeStateOverrides, mergeFieldOwnership, mergePhaseMapping, mergeReleaseIgnorePaths, mergeKeyedFields } =
316
+ const { mergeStates, mergeStateOverrides, mergeFieldOwnership, mergePhaseMapping, mergeReleaseIgnorePaths, mergeKeyedFields, mergeDescription } =
312
317
  kitConfig.makeMergeHelpers({
313
318
  configFile: CONFIG_FILE,
314
319
  ownership: OWNERSHIP,
@@ -375,6 +380,7 @@ function mergeConfig(base, parsed) {
375
380
  }
376
381
  mergePhaseMapping(base.mapping, parsed.mapping)
377
382
  }
383
+ mergeDescription(base, parsed)
378
384
 
379
385
  mergeStates(base, parsed)
380
386
  mergeStateOverrides(base, parsed, 'statesByKind')
@@ -57,6 +57,8 @@ function runChecks(state = {}) {
57
57
  ]
58
58
  // A retired config key is a stale file, not a broken one (provider-kit
59
59
  // `retiredKeysRow`): present only when the config still carries one.
60
+ // Who owns status and assignee here — a fact, never a fault.
61
+ if (state.ownership) checks.push(state.ownership)
60
62
  if (state.retired) checks.push(state.retired)
61
63
  return combineDoctorChecks(checks)
62
64
  }
@@ -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
 
@@ -80,6 +83,9 @@ async function applyInner({ dir, config, snapshotDir, plan, adapter, ops, progre
80
83
  const identifier = helpers.linkedIdentifier(path.join(snapshotDir, overviewFile), config)
81
84
  const lines = []
82
85
  const result = { issue: null, subIssues: {} }
86
+ // Which items this apply carried a state for — the snapshot records today's
87
+ // state name for these and only these (`recordPush`).
88
+ const sent = { issue: !!(plan.issue && plan.issue.state != null), subIssues: new Set() }
83
89
  // Handed out immediately, so a throw from anywhere below still reports what
84
90
  // had been stamped by the time it happened.
85
91
  if (progress) progress.result = result
@@ -140,11 +146,23 @@ async function applyInner({ dir, config, snapshotDir, plan, adapter, ops, progre
140
146
  lines.push(ops.remoteEditedLine(identifier))
141
147
  }
142
148
  if (plan.issue) {
143
- await ops.updateIssue(existing, plan.issue)
149
+ const issue = spliced(plan.issue, 'description', existing, config, identifier, lines)
150
+ await ops.updateIssue(existing, issue)
144
151
  lines.push(` issue updated: ${identifier}`)
145
152
  }
146
153
  }
147
154
 
155
+ // A provider's per-push extra on the spec issue (e.g. progress mirrored into
156
+ // a native field). Never fatal: the repo and the block already carry it.
157
+ if (ops.afterIssue && result.issue) {
158
+ try {
159
+ const line = await ops.afterIssue(result.issue)
160
+ if (line) lines.push(line)
161
+ } catch (error) {
162
+ lines.push(` ?? ${result.issue.identifier}: ${String((error && error.message) || error).split('\n')[0]}`)
163
+ }
164
+ }
165
+
148
166
  // 4. Sub-issue creates — each stamped as it lands, for the same reason.
149
167
  for (const sub of (plan.subIssues && plan.subIssues.create) || []) {
150
168
  const created = await ops.mintSubIssue(parentId, sub)
@@ -152,6 +170,7 @@ async function applyInner({ dir, config, snapshotDir, plan, adapter, ops, progre
152
170
  const file = resolvePhaseFileIn(snapshotDir, sub.ref)
153
171
  if (!file) throw new Error(`no phase file for ref ${sub.ref}`)
154
172
  stampSubIssueId(snapshotDir, file, created.identifier, config)
173
+ if (sub.state != null) sent.subIssues.add(String(created.identifier))
155
174
  result.subIssues[sub.ref] = created.identifier
156
175
  lines.push(` sub-issue created: ${sub.ref} → ${created.identifier}`)
157
176
  }
@@ -167,13 +186,18 @@ async function applyInner({ dir, config, snapshotDir, plan, adapter, ops, progre
167
186
  // issue. The read is spent only where the snapshot recorded something to
168
187
  // compare against, so an old snapshot costs no extra calls.
169
188
  const base = readBase(dir, identifier, config)
170
- for (const sub of (plan.subIssues && plan.subIssues.update) || []) {
189
+ const summary = descriptionMode(config) === 'summary'
190
+ for (let sub of (plan.subIssues && plan.subIssues.update) || []) {
171
191
  const streams = base && base.subIssueStreams
172
- if (sub.goal != null && streams && streams[String(sub.id)]) {
192
+ const compare = sub.goal != null && streams && streams[String(sub.id)]
193
+ // Summary mode always reads the live body: the block is spliced into it.
194
+ if (compare || (summary && sub.goal != null)) {
173
195
  const before = await adapter.readIssue(sub.id)
174
- if (remoteSubIssueEdited(base, sub.id, before, config) === true) lines.push(ops.remoteEditedLine(sub.id))
196
+ if (compare && remoteSubIssueEdited(base, sub.id, before, config) === true) lines.push(ops.remoteEditedLine(sub.id))
197
+ sub = spliced(sub, 'goal', before, config, sub.id, lines)
175
198
  }
176
199
  await ops.updateSubIssue(sub)
200
+ if (sub.state != null) sent.subIssues.add(String(sub.id))
177
201
  result.subIssues[sub.ref || refById.get(String(sub.id)) || sub.id] = sub.id
178
202
  lines.push(` sub-issue updated: ${sub.id}`)
179
203
  }
@@ -193,11 +217,39 @@ async function applyInner({ dir, config, snapshotDir, plan, adapter, ops, progre
193
217
  const lost = verify.some((l) => l.includes('!!') || l.includes('??'))
194
218
 
195
219
  // 7. Record the snapshot from the now-stamped files, so the next push is empty.
196
- const file = recordPush({ dir, snapshotDir, identifier: helpers.specIdentifier(snapshotDir, config), config })
197
- lines.push(` snapshot: ${path.relative(dir, file)}`)
220
+ const file = recordPush({ dir, snapshotDir, identifier: helpers.specIdentifier(snapshotDir, config), config, sent })
221
+ // A repo path, `/`-separated on every platform — the form every other
222
+ // spec path in this output takes.
223
+ lines.push(` snapshot: ${path.relative(dir, file).split(path.sep).join('/')}`)
198
224
  return { result, lines, lost }
199
225
  }
200
226
 
227
+ /**
228
+ * Under `mapping.description: "summary"` the planned body is the block alone,
229
+ * and the write must be the block SPLICED into what the tracker holds, so the
230
+ * team's text around it survives. `spec` mode returns the payload untouched.
231
+ *
232
+ * A damaged block (a delimiter someone edited) is cannot-tell: the body is
233
+ * left out of the write entirely and the run says so. Guessing the edges would
234
+ * eat the team's text, and prepending would leave two blocks.
235
+ */
236
+ function spliced(payload, key, live, config, label, lines) {
237
+ if (descriptionMode(config) !== 'summary' || payload[key] == null) return payload
238
+ const hook = config && config.remote && config.remote.description
239
+ const current = live && typeof hook === 'function' ? hook(live) : live ? live.description : undefined
240
+ // Nothing read back is not an empty body: write nothing rather than guess.
241
+ if (typeof current !== 'string') {
242
+ lines.push(` ?? ${label}: could not read its body — summary block not written`)
243
+ return { ...payload, [key]: undefined }
244
+ }
245
+ const next = spliceBlock(current, payload[key], config)
246
+ if (next == null) {
247
+ lines.push(` !! ${label}: its summary block's delimiters were edited — block not written; repair them and re-push`)
248
+ return { ...payload, [key]: undefined }
249
+ }
250
+ return { ...payload, [key]: next }
251
+ }
252
+
201
253
  // The phase file a sub-issue ref names — the ref is the phase-file basename.
202
254
  function resolvePhaseFileIn(snapshotDir, ref) {
203
255
  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 }
@@ -63,7 +63,7 @@ function storePath(env = process.env, homedir = os.homedir) {
63
63
  * `absent` (no file — the normal default, not a problem), `permissions`
64
64
  * (group/world readable), `unreadable`, `malformed`.
65
65
  */
66
- function readStore(file, { stat = fs.statSync, read = fs.readFileSync } = {}) {
66
+ function readStore(file, { stat = fs.statSync, read = fs.readFileSync, platform = process.platform } = {}) {
67
67
  let info
68
68
  try {
69
69
  info = stat(file)
@@ -74,7 +74,12 @@ function readStore(file, { stat = fs.statSync, read = fs.readFileSync } = {}) {
74
74
  return { ok: false, code: 'unreadable', path: file, reason: `cannot read ${file}: ${err.message}` }
75
75
  }
76
76
 
77
- if (info.mode & GROUP_OR_WORLD) {
77
+ // ON WINDOWS THE MODE BITS SAY NOTHING. Node reports every file there as
78
+ // 0o666, so this check refused every store on Windows and no stored
79
+ // credential could ever be read (chore-windows-ci). Access there is the
80
+ // profile directory's ACL, which these bits do not describe — cannot tell,
81
+ // and cannot-tell does not accuse (`.claude/rules/negative-checks.md`).
82
+ if (platform !== 'win32' && info.mode & GROUP_OR_WORLD) {
78
83
  const mode = (info.mode & 0o777).toString(8)
79
84
  return {
80
85
  ok: false,