@skitterbyte/skitterspec-github 1.2.1 → 2.0.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.
@@ -27,7 +27,7 @@ const {
27
27
  isEmptyPlan,
28
28
  validateStates,
29
29
  stateSuggestions,
30
- remoteWorkflowState,
30
+ stateNamesFor,
31
31
  remoteDescriptionEdited,
32
32
  writeFrontmatter,
33
33
  stampSubIssueId,
@@ -62,12 +62,13 @@ const { makeApiAdapter } = require('./api.js')
62
62
  const { APPLY_OVER_MCP } = require('./mcp.js')
63
63
  const { resolveIdentity, displayNameOf } = require('./identity.js')
64
64
  const { makeAssignmentCommands } = require('../provider-kit/src/assignment.js')
65
- const { makeReleaseCommands } = require('../provider-kit/src/releases.js')
65
+ const { resolveListAssignee } = require('../provider-kit/src/list-assignee.js')
66
+ const { expandStateArgs, specColumn, specCell } = require('../provider-kit/src/list-rows.js')
66
67
 
67
68
  const PROGRAM = 'spec-sync'
68
69
  const BIN = 'skitterspec-github'
69
70
  const specHelpers = kit.makeSpecHelpers({ program: PROGRAM })
70
- const { resolveSnapshotDir, specIdentifier, listSpecs, resolveOrExit, warnToErr, verifyLines } = specHelpers
71
+ const { resolveSnapshotDir, specIdentifier, listSpecs, listSpecsLive, resolveOrExit, warnToErr, verifyLines } = specHelpers
71
72
 
72
73
  // An issue reference as typed: `#123` or `123`. Stamped as `#123`.
73
74
  const ID_RE = /^#?\d+$/
@@ -247,8 +248,7 @@ function applyOps({ adapter, config }) {
247
248
 
248
249
  function adapterOptions(config) {
249
250
  const g = config.github || {}
250
- const deployedField = (config.releases && config.releases.deployedField) || 'Deployed'
251
- return { owner: g.owner, repo: g.repo, project: g.project, statusField: g.statusField, deployedField }
251
+ return { owner: g.owner, repo: g.repo, project: g.project, statusField: g.statusField }
252
252
  }
253
253
 
254
254
  function apiAdapterFor(config, flags) {
@@ -555,13 +555,9 @@ function specSyncStatus(dir, config, specArg, flags, out, err) {
555
555
  out.write(`${PROGRAM} status: cannot read --remote: ${error.message}\n`)
556
556
  return 1
557
557
  }
558
- const bucket = remoteWorkflowState(remote, config)
559
- const local = r.projection.status
560
- if (bucket && local && bucket !== local) {
561
- lines.push(` drift: the board says "${bucket}", the repo says "${local}" (repo wins on next push)`)
562
- } else if (bucket) {
563
- lines.push(' drift: none — the board agrees with the repo')
564
- }
558
+ // NO STATE LINE, deliberately: skitterspec tells the tracker about its own
559
+ // transitions and never reads a status back. A ticket someone moved there
560
+ // is theirs to have moved, and push resends State only when the spec does.
565
561
  // SILENT ON EVERYTHING EXCEPT A POSITIVE ANSWER: `remoteDescriptionEdited`
566
562
  // returns null for every cannot-tell, and none of those is evidence.
567
563
  if (remoteDescriptionEdited(readBase(dir, identifier, config), remote, config) === true) {
@@ -677,6 +673,12 @@ async function specSyncStates(dir, config, flags, out) {
677
673
  ? `ok · ${issue}`
678
674
  : `MISSING from the board${suggestions.get(bucket) ? ` — closest: "${suggestions.get(bucket)}"` : ''}`
679
675
  lines.push(` ${bucket.padEnd(bw)} -> ${String(name).padEnd(nw)} ${tail}`)
676
+ // Aliases are read-only, so a missing one never blocks a push — but it
677
+ // reads as nothing, so it is still named.
678
+ for (const alias of stateNamesFor(bucket, config).slice(1)) {
679
+ const here = names.includes(alias)
680
+ lines.push(` ${''.padEnd(bw)} ${String(alias).padEnd(nw)} ${here ? 'also reads as ' + bucket : 'alias MISSING — reads as nothing'}`)
681
+ }
680
682
  }
681
683
  if (missing.length) {
682
684
  lines.push(` remap: ${PROGRAM} init-config --force … --state <bucket>="<option>", or add the option on the board`)
@@ -686,6 +688,14 @@ async function specSyncStates(dir, config, flags, out) {
686
688
  }
687
689
 
688
690
  async function specSyncList(dir, config, flags, out) {
691
+ // `--next N` is the top of the backlog in BOARD order, so it fixes the scope
692
+ // itself; with --state or --all one would have to lose, silently.
693
+ const next = Number.isFinite(flags.next) && flags.next > 0 ? flags.next : null
694
+ const scopeFlags = [next !== null && '--next', flags.all === true && '--all', (flags.stateArgs || []).length > 0 && '--state'].filter(Boolean)
695
+ if (scopeFlags.length > 1) {
696
+ out.write(`${PROGRAM} list: ${scopeFlags.join(' and ')} each pick the scope, so they cannot be combined\n`)
697
+ return 1
698
+ }
689
699
  const cred = apiAdapterFor(config, flags)
690
700
  const transport = kit.resolveTransport(flags, config, cred.ok)
691
701
  if (transport === 'mcp' || !cred.ok) {
@@ -699,41 +709,83 @@ async function specSyncList(dir, config, flags, out) {
699
709
  out.write(`${PROGRAM} list: ${gap}\n`)
700
710
  return 1
701
711
  }
712
+ const who = await resolveListAssignee({
713
+ flags,
714
+ config,
715
+ env: flags.env || process.env,
716
+ adapter: cred.adapter,
717
+ resolveIdentity,
718
+ displayNameOf,
719
+ tracker: 'GitHub',
720
+ prog: PROGRAM,
721
+ })
722
+ if (who.code != null) {
723
+ out.write(who.lines.join('\n') + '\n')
724
+ return who.code
725
+ }
726
+ const assignee = who.assignee
702
727
  let issues
703
728
  try {
704
- issues = await cred.adapter.listBoardItems({ label: markersFor(config, 'spec').labels[0] || '' })
705
- const stateNames = flags.stateArgs || []
729
+ // Filtered by assignee, the spec label is dropped: an issue assigned to
730
+ // someone that no spec has adopted yet carries no spec label, and it is
731
+ // exactly the "what's next" row `--mine` exists for.
732
+ issues = await cred.adapter.listBoardItems(
733
+ assignee ? { assignee: assignee.id } : { label: markersFor(config, 'spec').labels[0] || '' },
734
+ )
735
+ const stateNames = next !== null ? stateNamesFor('backlog', config) : expandStateArgs(flags.stateArgs, config)
706
736
  if (stateNames.length) {
707
737
  const want = new Set(stateNames.map((s) => s.toLowerCase()))
708
738
  issues = issues.filter((i) => i.state && want.has(String(i.state.name).toLowerCase()))
709
739
  } else if (!flags.all) {
710
- issues = issues.filter((i) => i.open)
740
+ // Open issues, minus any whose Status is a finished bucket's name — an
741
+ // alias such as "Released" is finished work on an issue nobody closed.
742
+ const terminal = new Set(
743
+ [...stateNamesFor('complete', config), ...stateNamesFor('cancelled', config)].map((s) => s.toLowerCase()),
744
+ )
745
+ issues = issues.filter((i) => i.open && !(i.state && terminal.has(String(i.state.name).toLowerCase())))
746
+ }
747
+ if (next !== null) {
748
+ const order = await cred.adapter.listBoardOrder()
749
+ const rank = new Map(order.map((n, i) => [n, i]))
750
+ issues = issues
751
+ .filter((i) => i.open && rank.has(i.id))
752
+ .sort((a, b) => rank.get(a.id) - rank.get(b.id))
711
753
  }
712
754
  } catch (error) {
713
755
  out.write(`${PROGRAM} list: ${error.message}\n`)
714
756
  return 1
715
757
  }
716
- const linked = new Map(listSpecs(dir, config).filter((s) => s.identifier).map((s) => [s.identifier, s]))
758
+ const linked = new Map(listSpecsLive(dir, config).filter((s) => s.identifier).map((s) => [s.identifier, s]))
717
759
  const rows = issues
718
760
  .filter((i) => !i.parent)
719
- .slice(0, flags.limit || Infinity)
720
- .map((i) => ({
721
- identifier: i.identifier,
722
- title: i.title,
723
- state: i.state ? i.state.name : null,
724
- spec: linked.has(i.identifier) ? linked.get(i.identifier).spec : null,
725
- }))
761
+ .slice(0, next !== null ? next : flags.limit || Infinity)
762
+ .map((i) => {
763
+ const spec = linked.get(i.identifier) || null
764
+ const state = i.state ? i.state.name : null
765
+ return {
766
+ identifier: i.identifier,
767
+ title: i.title,
768
+ state,
769
+ ...specColumn(state, spec, config),
770
+ assignee: (i.assignees || []).map((a) => a.name || a.id).join(', ') || null,
771
+ spec: spec ? spec.spec : null,
772
+ }
773
+ })
726
774
  if (flags.json) {
727
775
  out.write(JSON.stringify(rows, null, 2) + '\n')
728
776
  return 0
729
777
  }
730
778
  if (!rows.length) {
731
- out.write(`${PROGRAM} list: nothing matched\n`)
779
+ out.write(`${PROGRAM} list: nothing matched${assignee ? ` for ${assignee.name}` : ''}\n`)
732
780
  return 0
733
781
  }
734
- const lines = [`${PROGRAM} list: ${repoLabel(config)} · board ${config.github.project}`]
782
+ const lines = [
783
+ `${PROGRAM} list: ${repoLabel(config)} · board ${config.github.project}${assignee ? ` · assigned to ${assignee.name}` : ''}${next !== null ? ` · next ${next} in board order` : ''}`,
784
+ ]
735
785
  for (const r of rows) {
736
- lines.push(` ${r.identifier}\t${r.state || '—'}\t${r.title || ''}${r.spec ? ` -> ${r.spec}` : ''}`)
786
+ lines.push(
787
+ ` ${r.identifier}\t${r.state || '—'}\t${specCell(r)}\t${r.assignee || 'unassigned'}\t${r.title || ''}${r.spec ? ` -> ${r.spec}` : ' (no spec)'}`,
788
+ )
737
789
  }
738
790
  out.write(lines.join('\n') + '\n')
739
791
  return 0
@@ -888,12 +940,13 @@ function specSyncReleased(dir, config, rangeArg, flags, out) {
888
940
  refPattern: GITHUB_REF_RE,
889
941
  foreignPatterns: [IDENTIFIER_RE],
890
942
  })
943
+ report.tickets = kit.nameTickets(report.tickets, listSpecs(dir, config, { urls: true }))
891
944
  if (flags.json) {
892
945
  out.write(JSON.stringify(report, null, 2) + '\n')
893
946
  return 0
894
947
  }
895
948
  const lines = [`${PROGRAM} released: ${range} — ${report.total} commit(s)`]
896
- for (const t of report.tickets) lines.push(` ${t.ref} (${t.commits} commit(s))`)
949
+ for (const t of report.tickets) lines.push(` ${t.ref} (${t.commits} commit(s))${t.spec ? ` ${t.spec}` : ''}`)
897
950
  if (!report.tickets.length) lines.push(' no referenced issues')
898
951
  if (report.unreferenced) lines.push(` ${report.unreferenced} commit(s) carry no Refs: trailer`)
899
952
  if (report.historical) lines.push(` ${report.historical} commit(s) reference an earlier tracker (KEY-N)`)
@@ -902,37 +955,6 @@ function specSyncReleased(dir, config, rangeArg, flags, out) {
902
955
  return 0
903
956
  }
904
957
 
905
- // ---------------------------------------------------------------------------
906
- // `release create | deployed | complete` — the kit's release seam
907
- // (`provider-kit/src/releases.js`) on GitHub Releases plus the board's
908
- // Deployed field. Run by CI on a tag push; dry unless `--apply`.
909
- const releases = makeReleaseCommands({
910
- tracker: 'GitHub',
911
- program: PROGRAM,
912
- readCommits: (dir, range) => readCommitRange(dir, range),
913
- ticketOptions: (config) => ({
914
- ignorePaths: (config.release && config.release.ignorePaths) || [],
915
- refPattern: GITHUB_REF_RE,
916
- foreignPatterns: [IDENTIFIER_RE],
917
- }),
918
- teamKey: () => '',
919
- listSpecs: (dir, config) => listSpecs(dir, config),
920
- series: (config) => (config.releases && config.releases.series) || [],
921
- adapterFor: (config, flags) => {
922
- const got = apiAdapterFor(config, flags)
923
- if (!got.ok) return got
924
- const gap = flags.adapter ? null : configGap(config)
925
- return gap ? { ok: false, error: gap } : got
926
- },
927
- describe: (t) => `${t.ref}${t.title ? ` ${t.title}` : ''}`,
928
- // GitHub's MCP server can READ releases and cannot write one — so over MCP
929
- // this is impossible, not merely slower, and says so (exit 1).
930
- impossibleOverMcp: (config, flags) =>
931
- kit.resolveTransport(flags, config, true) === 'mcp'
932
- ? "transport = mcp — GitHub's MCP server has no release write tool; set a token (CI: a repo secret) and re-run"
933
- : null,
934
- })
935
-
936
958
  // ---------------------------------------------------------------------------
937
959
  // `preserve <spec>` — post the issue's current body back onto the issue as a
938
960
  // comment BEFORE the linking push replaces it. Every cannot-tell exits 0: a
@@ -1219,6 +1241,8 @@ async function specSyncDoctor(dir, flags, out) {
1219
1241
  checks.push(row('tracker', 'GitHub config', 'broken', configGap(loaded.config), `fix ${CONFIG_FILE}`))
1220
1242
  } else {
1221
1243
  checks.push(row('tracker', 'GitHub config', 'ok', `${repoLabel(loaded.config)} · board ${loaded.config.github.project}`))
1244
+ const retired = kit.retiredKeysRow(path.join(dir, CONFIG_FILE), CONFIG_FILE, row)
1245
+ if (retired) checks.push(retired)
1222
1246
  // A worktree forks from a COMMIT, so a config that exists only in the
1223
1247
  // working tree is invisible in every spec worktree — where the sync
1224
1248
  // skills actually run. The positive signal is git tracking the file;
@@ -1290,26 +1314,6 @@ async function specSyncDoctor(dir, flags, out) {
1290
1314
  )
1291
1315
  : row('states', 'Board states', 'ok', `every configured state is a "${config.github.statusField}" option`),
1292
1316
  )
1293
- // Releases: the Deployed field and every env option a series names. Only
1294
- // when a series is configured — a repo that never adopted releases has
1295
- // nothing to be told about here.
1296
- const series = (config.releases && config.releases.series) || []
1297
- if (series.length && adapter.resolveBoard) {
1298
- const field = config.releases.deployedField
1299
- const board = await adapter.resolveBoard()
1300
- const f = board.fields.find((x) => String(x.name).toLowerCase() === String(field).toLowerCase() && x.options)
1301
- if (!f) {
1302
- checks.push(row('releases', 'Deployed field', 'broken', `the board has no single-select "${field}"`, `add it on the board, or set releases.deployedField`))
1303
- } else {
1304
- const have = new Set(f.options.map((o) => o.name.toLowerCase()))
1305
- const absent = series.flatMap((s) => Object.values(s.envs || {})).filter((o) => !have.has(o.toLowerCase()))
1306
- checks.push(
1307
- absent.length
1308
- ? row('releases', 'Deployed field', 'broken', `"${field}" lacks: ${[...new Set(absent)].join(', ')}`, 'add the options on the board, or fix releases.series envs')
1309
- : row('releases', 'Deployed field', 'ok', `"${field}" has every env option`),
1310
- )
1311
- }
1312
- }
1313
1317
  if (adapter.listLabels) {
1314
1318
  const have = new Set((await adapter.listLabels()).map((l) => String(l.name).toLowerCase()))
1315
1319
  const want = ['spec', 'phase'].flatMap((k) => markersFor(config, k).labels)
@@ -1353,12 +1357,11 @@ const USAGE = `Usage: ${BIN} spec-sync <subcommand>
1353
1357
  status <spec> [--remote <f>] read-only drift report
1354
1358
  verify <spec> --stored <f> compare a read-back against the repo
1355
1359
  states [--json] the board's Status options + bucket map
1356
- list [--all | --state NAME] the board's issues for this repo
1360
+ list [--all | --state NAME|BUCKET | --next N] [--mine | --by USER] the board's issues
1357
1361
  intake [query] [--json] issues waiting to become specs
1358
1362
  linked [--json] specs and their linked issues (offline)
1359
1363
  ref [<spec>] the Refs: trailer value for this branch
1360
1364
  released [<range>] issues a commit range contains
1361
- release create|deployed|complete <tag> GitHub Release + Deployed field (CI; --apply)
1362
1365
  preserve <spec> [--text <f>] keep an adopted issue's original report
1363
1366
  assign <spec> --to <login> | --release stamp who is building it
1364
1367
  whoami [--set <login>] [--unset] who you are on GitHub (cached)
@@ -1442,7 +1445,7 @@ async function specSync(rest, io = {}) {
1442
1445
  case 'preserve':
1443
1446
  return specSyncPreserve(dir, config, positional[0], flags, out)
1444
1447
  case 'release':
1445
- return releases.run(dir, config, positional, flags, out)
1448
+ return kit.refuseRemovedVerb(out, PROGRAM, 'release')
1446
1449
  case 'assign':
1447
1450
  return assignment.assign(dir, config, positional[0], flags, out)
1448
1451
  case 'whoami':
@@ -1493,6 +1496,9 @@ function parseArgs(args, sub) {
1493
1496
  '--to': { kind: 'string' },
1494
1497
  '--name': { kind: 'value' },
1495
1498
  '--release': { kind: 'boolean' },
1499
+ '--mine': { kind: 'boolean' },
1500
+ '--next': { kind: 'number' },
1501
+ '--by': { kind: 'string' },
1496
1502
  '--set': { kind: 'string' },
1497
1503
  '--unset': { kind: 'boolean' },
1498
1504
  '--cursor': { kind: 'string' },
@@ -81,12 +81,7 @@ const DEFAULT_CONFIG = Object.freeze({
81
81
  assigneeName: 'github_assignee_name',
82
82
  }),
83
83
  intake: Object.freeze({ label: '', bugLabels: Object.freeze(['bug']), hotfixLabels: Object.freeze([]) }),
84
- release: Object.freeze({ stages: Object.freeze([]), ignorePaths: Object.freeze(['specs/', 'CHANGELOG.md', 'RELEASES.md']) }),
85
- // GitHub Releases, created by CI on a tag push (`spec-sync release …`). Each
86
- // series names a tag prefix and its deploy envs, keyed by what CI says
87
- // (`deployed <tag> test`) and valued by the option of `deployedField` — a
88
- // second single-select on the board, never a Status option.
89
- releases: Object.freeze({ deployedField: 'Deployed', series: Object.freeze([]) }),
84
+ release: Object.freeze({ ignorePaths: Object.freeze(['specs/', 'CHANGELOG.md', 'RELEASES.md']) }),
90
85
  branch: Object.freeze({ pattern: '{type}/{slug}' }),
91
86
  // An env-var NAME, not a value. A classic PAT with `repo` + `project`: the
92
87
  // fine-grained kind is documented only for org-owned boards.
@@ -126,6 +121,7 @@ function defaults() {
126
121
  github: { ...g, labels: { ...g.labels }, issueTypes: { ...g.issueTypes } },
127
122
  mapping: { ...DEFAULT_CONFIG.mapping },
128
123
  states: { ...DEFAULT_CONFIG.states },
124
+ stateAliases: {},
129
125
  snapshot: { ...DEFAULT_CONFIG.snapshot },
130
126
  fields: { ...DEFAULT_CONFIG.fields },
131
127
  intake: {
@@ -134,10 +130,8 @@ function defaults() {
134
130
  hotfixLabels: [...DEFAULT_CONFIG.intake.hotfixLabels],
135
131
  },
136
132
  release: {
137
- stages: DEFAULT_CONFIG.release.stages.map((s) => ({ ...s })),
138
133
  ignorePaths: [...DEFAULT_CONFIG.release.ignorePaths],
139
134
  },
140
- releases: { deployedField: DEFAULT_CONFIG.releases.deployedField, series: [] },
141
135
  branch: { ...DEFAULT_CONFIG.branch },
142
136
  auth: { ...DEFAULT_CONFIG.auth },
143
137
  apply: { ...DEFAULT_CONFIG.apply },
@@ -152,7 +146,7 @@ function defaults() {
152
146
  }
153
147
 
154
148
  const { isObject, stringList, assign } = kitConfig
155
- const { mergeFieldOwnership, mergePhaseMapping, mergeReleaseStages, mergeReleaseIgnorePaths, mergeKeyedFields } =
149
+ const { mergeStates, mergeFieldOwnership, mergePhaseMapping, mergeReleaseIgnorePaths, mergeKeyedFields } =
156
150
  kitConfig.makeMergeHelpers({
157
151
  configFile: CONFIG_FILE,
158
152
  ownership: OWNERSHIP,
@@ -203,11 +197,7 @@ function mergeConfig(base, parsed) {
203
197
  mergePhaseMapping(base.mapping, parsed.mapping)
204
198
  }
205
199
 
206
- if (isObject(parsed.states)) {
207
- for (const key of Object.keys(base.states)) {
208
- assign(base.states, parsed.states, key, 'string')
209
- }
210
- }
200
+ mergeStates(base, parsed)
211
201
 
212
202
  if (isObject(parsed.snapshot)) {
213
203
  assign(base.snapshot, parsed.snapshot, 'overviewFile', 'string')
@@ -220,37 +210,9 @@ function mergeConfig(base, parsed) {
220
210
  }
221
211
 
222
212
  if (isObject(parsed.release)) {
223
- mergeReleaseStages(base.release, parsed.release)
224
213
  mergeReleaseIgnorePaths(base.release, parsed.release)
225
214
  }
226
215
 
227
- if (isObject(parsed.releases)) {
228
- assign(base.releases, parsed.releases, 'deployedField', 'string')
229
- if (parsed.releases.series !== undefined) {
230
- if (!Array.isArray(parsed.releases.series)) throw invalid('releases.series', parsed.releases.series, 'an array of { tagPrefix, envs }')
231
- const seen = new Set()
232
- base.releases.series = parsed.releases.series.map((entry, i) => {
233
- if (!isObject(entry) || typeof entry.tagPrefix !== 'string' || !entry.tagPrefix.trim()) {
234
- throw invalid(`releases.series[${i}]`, entry, '{ tagPrefix: "pkg@", envs: { key: "Option" } }')
235
- }
236
- const tagPrefix = entry.tagPrefix.trim()
237
- if (seen.has(tagPrefix)) throw invalid(`releases.series[${i}].tagPrefix`, tagPrefix, 'a prefix not already listed')
238
- seen.add(tagPrefix)
239
- const envs = {}
240
- if (entry.envs !== undefined) {
241
- if (!isObject(entry.envs)) throw invalid(`releases.series[${i}].envs`, entry.envs, 'an object of { key: "Option" }')
242
- for (const [key, option] of Object.entries(entry.envs)) {
243
- if (!/^[A-Za-z0-9_.-]+$/.test(key) || typeof option !== 'string' || !option.trim()) {
244
- throw invalid(`releases.series[${i}].envs.${key}`, option, 'a key of letters/digits and a non-empty option name')
245
- }
246
- envs[key] = option.trim()
247
- }
248
- }
249
- return { tagPrefix, envs }
250
- })
251
- }
252
- }
253
-
254
216
  if (isObject(parsed.branch)) {
255
217
  assign(base.branch, parsed.branch, 'pattern', 'string')
256
218
  }
@@ -382,10 +344,7 @@ function loadGithubConfig(dir = process.cwd()) {
382
344
  return { config: withRuntime(mergeConfig(base, parsed)), present: true }
383
345
  }
384
346
 
385
- // The declared deployment ladder (possibly empty) and its rungs — same
386
- // accessors the other providers expose, reading this provider's config.
387
- const releaseStages = (config) => (config.release && config.release.stages) || []
388
- const stageFor = (config, key) => releaseStages(config).find((s) => s.key === key) || null
347
+ // The bookkeeping path prefixes `released` ignores.
389
348
  const releaseIgnorePaths = (config) => (config.release && config.release.ignorePaths) || []
390
349
 
391
350
  module.exports = {
@@ -396,8 +355,6 @@ module.exports = {
396
355
  closeReasonFor,
397
356
  closeReasonForBucket,
398
357
  markersFor,
399
- releaseStages,
400
- stageFor,
401
358
  releaseIgnorePaths,
402
359
  DEFAULT_CONFIG,
403
360
  CONFIG_FILE,
@@ -39,10 +39,6 @@ const MATCHERS = {
39
39
  // all: reading an issue and writing one. Everything else degrades per command.
40
40
  const REQUIRED = ['issueRead', 'issueWrite']
41
41
 
42
- // Ops the official server cannot express at all — named so a refusal can say
43
- // so rather than imply a missing connection.
44
- const IMPOSSIBLE_OVER_MCP = Object.freeze(['release create', 'release complete'])
45
-
46
42
  /**
47
43
  * Match the advertised tool list against the matchers.
48
44
  * @param {string[]} toolNames what the connected server advertises
@@ -82,4 +78,4 @@ const APPLY_OVER_MCP =
82
78
  ' (completed / not_planned). Then stamp the returned #numbers with\n' +
83
79
  ' `spec-sync stamp` and record with `spec-sync record`.'
84
80
 
85
- module.exports = { discoverGithub, MATCHERS, REQUIRED, IMPOSSIBLE_OVER_MCP, APPLY_OVER_MCP }
81
+ module.exports = { discoverGithub, MATCHERS, REQUIRED, APPLY_OVER_MCP }
@@ -98,52 +98,6 @@ function makeMergeHelpers({ configFile, ownership, lifecycleBuckets, phaseMappin
98
98
  }
99
99
  }
100
100
 
101
- // Merge (and validate) `release.stages` — the project's deployment ladder.
102
- //
103
- // Loud on a malformed entry: this list names tracker states, and a tracker
104
- // that silently ignores an unknown state would let a half-typed ladder push
105
- // clean and move nothing — so a bad shape fails here, at load, rather than at
106
- // the first deploy nobody is watching. An ABSENT `release` block is not an
107
- // error: it is the opt-out, and the whole feature is unused without it.
108
- function mergeReleaseStages(base, parsed) {
109
- const value = parsed.stages
110
- if (value === undefined) return
111
- if (!Array.isArray(value)) {
112
- throw new Error(
113
- `Invalid ${configFile}: release.stages = ${JSON.stringify(value)} ` +
114
- '(expected an array of { key, state })',
115
- )
116
- }
117
- const stages = []
118
- const seen = new Set()
119
- value.forEach((entry, i) => {
120
- if (!isObject(entry)) {
121
- throw new Error(
122
- `Invalid ${configFile}: release.stages[${i}] = ${JSON.stringify(entry)} ` +
123
- '(expected { key, state })',
124
- )
125
- }
126
- for (const field of ['key', 'state']) {
127
- if (typeof entry[field] !== 'string' || !entry[field].trim()) {
128
- throw new Error(
129
- `Invalid ${configFile}: release.stages[${i}].${field} = ${JSON.stringify(entry[field])} ` +
130
- '(expected a non-empty string)',
131
- )
132
- }
133
- }
134
- const key = entry.key.trim()
135
- if (seen.has(key)) {
136
- throw new Error(
137
- `Invalid ${configFile}: release.stages[${i}].key = ${JSON.stringify(key)} is a duplicate ` +
138
- '(a stage key is how CI names the rung, so it must be unique)',
139
- )
140
- }
141
- seen.add(key)
142
- stages.push({ key, state: entry.state.trim() })
143
- })
144
- base.stages = stages
145
- }
146
-
147
101
  // Merge (and validate) release.ignorePaths — the path prefixes whose commits
148
102
  // are bookkeeping. Loud on anything but an array of non-empty strings: a bad
149
103
  // value that quietly fell back would let a project believe it had opted out
@@ -186,13 +140,112 @@ function makeMergeHelpers({ configFile, ownership, lifecycleBuckets, phaseMappin
186
140
  }
187
141
  }
188
142
 
143
+ // Merge (and validate) `states`. A bucket's value is a string — the one state
144
+ // push writes, exactly as it always was — or a non-empty array whose FIRST
145
+ // name is the one push writes and whose rest are read-only aliases: tracker
146
+ // states that also mean this bucket ("Blocked" for in-progress). The first
147
+ // name lands in `states[bucket]`, so every writer is unchanged; the rest go
148
+ // to `stateAliases[bucket]`, read only by code that interprets a remote state.
149
+ //
150
+ // An ALIAS in two buckets is refused: it would make a remote state mean two
151
+ // things, and which one won would be an accident of iteration order. Two
152
+ // buckets sharing one written name stays legal, as it always was — a tracker
153
+ // with no Cancelled state maps cancelled to "Done" — so only a name that an
154
+ // alias contributes is checked.
155
+ function mergeStates(base, parsed) {
156
+ const value = parsed.states
157
+ if (!isObject(value)) return
158
+ const aliases = {}
159
+ for (const bucket of Object.keys(base.states)) {
160
+ const entry = value[bucket]
161
+ if (entry === undefined) continue
162
+ if (typeof entry === 'string') {
163
+ if (entry.trim()) base.states[bucket] = entry.trim()
164
+ continue
165
+ }
166
+ if (!Array.isArray(entry) || !entry.length || entry.some((n) => typeof n !== 'string' || !n.trim())) {
167
+ throw new Error(
168
+ `Invalid ${configFile}: states.${bucket} = ${JSON.stringify(entry)} ` +
169
+ '(expected a state name, or a non-empty array of them — the first is what push writes)',
170
+ )
171
+ }
172
+ const names = entry.map((n) => n.trim())
173
+ base.states[bucket] = names[0]
174
+ aliases[bucket] = names.slice(1)
175
+ }
176
+ const owner = new Map()
177
+ for (const bucket of Object.keys(base.states)) {
178
+ const key = base.states[bucket].toLowerCase()
179
+ if (!owner.has(key)) owner.set(key, bucket)
180
+ }
181
+ for (const bucket of Object.keys(aliases)) {
182
+ for (const name of aliases[bucket]) {
183
+ const key = name.toLowerCase()
184
+ if (owner.has(key) && owner.get(key) !== bucket) {
185
+ throw new Error(
186
+ `Invalid ${configFile}: states name ${JSON.stringify(name)} is in both ` +
187
+ `${owner.get(key)} and ${bucket} (a tracker state can mean only one bucket)`,
188
+ )
189
+ }
190
+ owner.set(key, bucket)
191
+ }
192
+ }
193
+ base.stateAliases = aliases
194
+ }
195
+
189
196
  return {
197
+ mergeStates,
190
198
  mergeFieldOwnership,
191
199
  mergePhaseMapping,
192
- mergeReleaseStages,
193
200
  mergeReleaseIgnorePaths,
194
201
  mergeKeyedFields,
195
202
  }
196
203
  }
197
204
 
198
- module.exports = { isObject, stringList, assign, makeMergeHelpers }
205
+ // Keys no provider reads any more. The merge already ignores them, as it does
206
+ // every unknown key — so a config still carrying one is a stale file, not a
207
+ // broken one, and `doctor` says so as a `warn` without touching the exit code.
208
+ //
209
+ // WHAT WOULD FOOL THIS: it reads the committed file, so a key set only in a
210
+ // working-tree edit is still reported — which is the file a person would edit.
211
+ const RETIRED_KEYS = Object.freeze([
212
+ { path: ['releases'], name: 'releases' },
213
+ { path: ['release', 'stages'], name: 'release.stages' },
214
+ ])
215
+
216
+ // The retired keys present in a parsed config. Not an object, or none present,
217
+ // is `[]`: nothing to say is the safe answer to every cannot-tell.
218
+ function retiredKeys(parsed) {
219
+ if (!isObject(parsed)) return []
220
+ return RETIRED_KEYS.filter(({ path }) => {
221
+ let node = parsed
222
+ for (const key of path) {
223
+ if (!isObject(node) || !(key in node)) return false
224
+ node = node[key]
225
+ }
226
+ return true
227
+ }).map((k) => k.name)
228
+ }
229
+
230
+ // A doctor row naming the retired keys in the config at `file`, or null when
231
+ // there are none — or when the file cannot be read or parsed, which is the
232
+ // loader's to report, not this row's.
233
+ function retiredKeysRow(file, configFile, row) {
234
+ let parsed = null
235
+ try {
236
+ parsed = JSON.parse(require('node:fs').readFileSync(file, 'utf-8'))
237
+ } catch {
238
+ return null
239
+ }
240
+ const names = retiredKeys(parsed)
241
+ if (!names.length) return null
242
+ return row(
243
+ 'retired',
244
+ 'Retired config',
245
+ 'warn',
246
+ `${names.join(', ')} in ${configFile} is no longer read — release and deploy state is the host project's to write (see \`spec-sync released --json\`)`,
247
+ `remove ${names.join(', ')} from ${configFile}`,
248
+ )
249
+ }
250
+
251
+ module.exports = { isObject, stringList, assign, makeMergeHelpers, retiredKeys, retiredKeysRow, RETIRED_KEYS }
@@ -0,0 +1,71 @@
1
+ 'use strict'
2
+
3
+ /**
4
+ * `spec-sync list --mine | --by <user>` — whose tickets to list.
5
+ *
6
+ * Linear defined the contract (`linear/src/cli-sync.js`, decision 9 of
7
+ * `feat-linear-assignment`); this is the same contract for every provider that
8
+ * lists over the API, so the two sentences below mean the same thing anywhere:
9
+ *
10
+ * - `--mine` with an UNKNOWN identity lists nothing and exits 0. Identity is
11
+ * an ordinary unknown (a bot token, an offline machine). What must never
12
+ * happen is dropping the filter and printing everyone's work under a
13
+ * heading that promised yours.
14
+ * - `--by` that matches nobody, or more than one person, exits 1. The
15
+ * argument is wrong and only the caller can fix it — the same shape as an
16
+ * unknown `--state` — and a fallback to everyone would be the same lie.
17
+ *
18
+ * Returns `{ assignee: { id, name } | null }` to carry on with, or
19
+ * `{ code, lines }` to print and stop.
20
+ */
21
+ async function resolveListAssignee({ flags, config, env, adapter, resolveIdentity, displayNameOf, tracker, prog }) {
22
+ if (flags.mine && flags.by) {
23
+ return {
24
+ code: 1,
25
+ lines: [
26
+ `${prog} list: --mine and --by both filter by assignee, so they cannot be combined`,
27
+ ' use --mine for your own, or --by <user> for someone else.',
28
+ ],
29
+ }
30
+ }
31
+ if (flags.mine) {
32
+ const who = await resolveIdentity(config, env, { adapter })
33
+ if (!who || !who.ok) {
34
+ return {
35
+ code: 0,
36
+ lines: [
37
+ `${prog} list: --mine needs to know who you are, and it does not (${(who && who.reason) || 'no identity'})`,
38
+ ' run `spec-sync whoami --set <id>` to say so, or use --by <user>.',
39
+ ],
40
+ }
41
+ }
42
+ return { assignee: { id: who.id, name: who.name || who.id } }
43
+ }
44
+ if (flags.by) {
45
+ const term = String(flags.by)
46
+ let found
47
+ try {
48
+ found = await adapter.searchUsers(term, { limit: 50 })
49
+ } catch (error) {
50
+ return { code: 1, lines: [`${prog} list: could not search users (${error.message})`] }
51
+ }
52
+ const users = (found && found.users) || []
53
+ if (!users.length) {
54
+ return {
55
+ code: 1,
56
+ lines: [`${prog} list: no ${tracker} user matches ${JSON.stringify(term)}`, ' `spec-sync users <term>` lists who there is.'],
57
+ }
58
+ }
59
+ if (users.length > 1) {
60
+ const lines = [`${prog} list: ${users.length} users match ${JSON.stringify(term)}`]
61
+ for (const u of users.slice(0, 10)) lines.push(` ${displayNameOf(u) || '(unnamed)'}${u.email ? ` ${u.email}` : ''}`)
62
+ if (users.length > 10) lines.push(` … and ${users.length - 10} more`)
63
+ lines.push(' narrow it — an email address matches exactly one person.')
64
+ return { code: 1, lines }
65
+ }
66
+ return { assignee: { id: users[0].id, name: displayNameOf(users[0]) || users[0].id } }
67
+ }
68
+ return { assignee: null }
69
+ }
70
+
71
+ module.exports = { resolveListAssignee }