@skitterbyte/skitterspec-github 2.5.1 → 2.6.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.
@@ -516,6 +516,28 @@ function makeApiAdapter({
516
516
  return child
517
517
  },
518
518
 
519
+ /**
520
+ * Make `ref` a sub-issue of `parentRef` — an epic member under its epic.
521
+ * Idempotent: an issue already under that parent is left alone. One under
522
+ * another parent is MOVED (`replace_parent`), which is what a member that
523
+ * changed epics means. Read back, and refused when GitHub stored anything
524
+ * else, so a link that did not land is never reported as set.
525
+ */
526
+ async setParent(ref, parentRef) {
527
+ const issue = await adapter.readIssue(ref)
528
+ if (!issue) throw new GitHubRefusal(`no GitHub issue ${identifierOf(numberOf(ref))} to put under ${identifierOf(numberOf(parentRef))}`)
529
+ const want = String(numberOf(parentRef))
530
+ if (issue.parent && issue.parent.id === want) return { changed: false }
531
+ await rest('POST', `${repoPath}/issues/${want}/sub_issues`, {
532
+ body: { sub_issue_id: issue.databaseId, ...(issue.parent ? { replace_parent: true } : {}) },
533
+ })
534
+ const back = await adapter.readIssue(ref)
535
+ if (!back || !back.parent || back.parent.id !== want) {
536
+ throw new GitHubRefusal(`${issue.identifier} was linked under #${want} but GitHub reads it back under ${back && back.parent ? back.parent.identifier : 'no parent'}`)
537
+ }
538
+ return { changed: true, moved: !!issue.parent }
539
+ },
540
+
519
541
  async updateIssue(ref, updates) {
520
542
  const body = issuePayload(updates || {})
521
543
  if (!Object.keys(body).length) return {}
@@ -69,6 +69,7 @@ const { resolveIdentity, displayNameOf } = require('./identity.js')
69
69
  const { makeAssignmentCommands } = require('../provider-kit/src/assignment.js')
70
70
  const { resolveListAssignee } = require('../provider-kit/src/list-assignee.js')
71
71
  const { expandStateArgs, specColumn, specCell } = require('../provider-kit/src/list-rows.js')
72
+ const { epicIdentifiers, epicOf, keepSpecIssues, groupUnderEpics } = require('../provider-kit/src/epic-rows.js')
72
73
 
73
74
  const PROGRAM = 'spec-sync'
74
75
  const BIN = 'skitterspec-github'
@@ -152,6 +153,7 @@ function specKindOf(snapshotDir) {
152
153
  if (name.startsWith('chore-')) return 'chore'
153
154
  if (name.startsWith('issue-')) return 'issue'
154
155
  if (name.startsWith('incident-')) return 'incident'
156
+ if (name.startsWith('epic-')) return 'epic'
155
157
  return 'feature'
156
158
  }
157
159
 
@@ -240,6 +242,7 @@ function applyOps({ adapter, config, kind = 'feature', snapshotDir = null }) {
240
242
  prevalidateStates: (buckets) => {
241
243
  for (const bucket of buckets) statusFor(bucket)
242
244
  },
245
+ setParent: (issue, parentIdentifier) => adapter.setParent(issue.id, parentIdentifier),
243
246
  searchTwin: (title) => adapter.searchIssues({ query: title }),
244
247
  twinAdvice: (twin, wanted, specName) =>
245
248
  `${twin.identifier} is already titled "${wanted}" and no spec claims it — ` +
@@ -817,8 +820,11 @@ async function specSyncList(dir, config, flags, out) {
817
820
  return 1
818
821
  }
819
822
  const linked = new Map(listSpecsLive(dir, config).filter((s) => s.identifier).map((s) => [s.identifier, s]))
820
- const rows = issues
821
- .filter((i) => !i.parent)
823
+ // An epic's members are sub-issues too, kept and grouped (provider-kit
824
+ // `epic-rows.js`, which names the blind spot).
825
+ const epics = epicIdentifiers([...linked.values()])
826
+ const parentId = (i) => i.parent.identifier || `#${i.parent.id}`
827
+ let rows = keepSpecIssues(issues, epics, parentId)
822
828
  .slice(0, next !== null ? next : flags.limit || Infinity)
823
829
  .map((i) => {
824
830
  const spec = linked.get(i.identifier) || null
@@ -830,8 +836,12 @@ async function specSyncList(dir, config, flags, out) {
830
836
  ...specColumn(state, spec, config),
831
837
  assignee: (i.assignees || []).map((a) => a.name || a.id).join(', ') || null,
832
838
  spec: spec ? spec.spec : null,
839
+ ...(epicOf(i, epics, parentId) ? { epic: epicOf(i, epics, parentId) } : {}),
833
840
  }
834
841
  })
842
+ // Members listed under their epic's row, where it is in the listing. Board
843
+ // order (`--next`) is the order that was asked for, so it is left alone.
844
+ if (next === null) rows = groupUnderEpics(rows)
835
845
  if (flags.json) {
836
846
  out.write(JSON.stringify(rows, null, 2) + '\n')
837
847
  return 0
@@ -843,9 +853,14 @@ async function specSyncList(dir, config, flags, out) {
843
853
  const lines = [
844
854
  `${PROGRAM} list: ${repoLabel(config)} · board ${config.github.project}${assignee ? ` · assigned to ${assignee.name}` : ''}${next !== null ? ` · next ${next} in board order` : ''}`,
845
855
  ]
856
+ const shown = new Set(rows.map((r) => r.identifier))
846
857
  for (const r of rows) {
858
+ // A member under its epic's row is indented; one whose epic is not in this
859
+ // listing says which epic it belongs to instead.
860
+ const lead = r.epic && shown.has(r.epic) ? ' ' : ' '
861
+ const tail = r.epic && !shown.has(r.epic) ? ` (epic ${r.epic})` : ''
847
862
  lines.push(
848
- ` ${r.identifier}\t${r.state || '—'}\t${specCell(r)}\t${r.assignee || 'unassigned'}\t${r.title || ''}${r.spec ? ` -> ${r.spec}` : ' (no spec)'}`,
863
+ `${lead}${r.identifier}\t${r.state || '—'}\t${specCell(r)}\t${r.assignee || 'unassigned'}\t${r.title || ''}${r.spec ? ` -> ${r.spec}` : ' (no spec)'}${tail}`,
849
864
  )
850
865
  }
851
866
  out.write(lines.join('\n') + '\n')
@@ -209,7 +209,7 @@ function mergeConfig(base, parsed) {
209
209
  // Only the kinds a spec folder can actually be — an unknown key is
210
210
  // dropped, matching Azure's workItemTypeByKind validation.
211
211
  const byKind = {}
212
- for (const kind of ['feature', 'bug', 'hotfix', 'chore', 'issue', 'incident']) {
212
+ for (const kind of ['feature', 'bug', 'hotfix', 'chore', 'issue', 'incident', 'epic']) {
213
213
  const value = parsed.github.labelsByKind[kind]
214
214
  if (typeof value === 'string' && value.trim()) byKind[kind] = value.trim()
215
215
  }
@@ -37,6 +37,10 @@
37
37
  * - `remoteEditedLine(identifier)` the someone-else-edited warning
38
38
  * - `twinAdvice(twin, title, specName)` the refusal message for a twin
39
39
  * - `afterIssue(issue)` optional; → a report line or null
40
+ * - `setParent(issue, parentIdentifier)` optional; make the spec issue a
41
+ * child of its epic's → `{ changed }`.
42
+ * Absent means this tracker cannot
43
+ * express it, and the push says so.
40
44
  */
41
45
 
42
46
  const path = require('node:path')
@@ -54,6 +58,7 @@ const {
54
58
  listPhaseFiles,
55
59
  descriptionMode,
56
60
  spliceBlock,
61
+ linkedEpic,
57
62
  } = require('../../sync-core')
58
63
  const { makeSpecHelpers } = require('./specs.js')
59
64
 
@@ -163,6 +168,25 @@ async function applyInner({ dir, config, snapshotDir, plan, adapter, ops, progre
163
168
  }
164
169
  }
165
170
 
171
+ // An epic member's issue is a child of its epic's (spec feat-epics,
172
+ // Decision 6). Never fatal and never a mint: an epic not linked yet is named
173
+ // and skipped, and a tracker with no way to say "parent" says so.
174
+ const epic = result.issue ? linkedEpic(snapshotDir, config) : null
175
+ if (epic) {
176
+ if (!epic.identifier) {
177
+ lines.push(` !! epic ${epic.name} is not linked yet — parent skipped (push the epic first)`)
178
+ } else if (typeof ops.setParent !== 'function') {
179
+ lines.push(` epic ${epic.identifier}: this tracker cannot express a parent here — skipped`)
180
+ } else {
181
+ try {
182
+ const r = await ops.setParent(result.issue, epic.identifier)
183
+ if (r && r.changed) lines.push(` parent set: ${result.issue.identifier} under epic ${epic.identifier}`)
184
+ } catch (error) {
185
+ lines.push(` ?? parent ${epic.identifier}: ${String((error && error.message) || error).split('\n')[0]}`)
186
+ }
187
+ }
188
+ }
189
+
166
190
  // 4. Sub-issue creates — each stamped as it lands, for the same reason.
167
191
  for (const sub of (plan.subIssues && plan.subIssues.create) || []) {
168
192
  const created = await ops.mintSubIssue(parentId, sub)
@@ -0,0 +1,44 @@
1
+ 'use strict'
2
+
3
+ /**
4
+ * Epic members in a tracker listing (spec feat-epics). A listing keeps only
5
+ * top-level issues because a sub-issue is normally a phase — but an epic's
6
+ * member is a spec that is ALSO a sub-issue, of its epic's issue. These keep
7
+ * such a member and group it under its epic, on a positive signal only: its
8
+ * parent is linked to an `epic-` spec in this checkout.
9
+ *
10
+ * BLIND SPOT: an epic this checkout has no linked copy of reads as an unknown
11
+ * parent, so its members stay filtered out exactly as they were before epics
12
+ * existed — a missing row, never a phase shown as a spec.
13
+ */
14
+
15
+ /** The identifiers of the `epic-` specs in a `listSpecs`-shaped array. */
16
+ function epicIdentifiers(specs) {
17
+ return new Set((specs || []).filter((s) => s && s.identifier && /^epic-/.test(s.spec)).map((s) => s.identifier))
18
+ }
19
+
20
+ /**
21
+ * The epic an issue is a member of, or null. `parentOf(issue)` gives the
22
+ * parent's identifier in the provider's own spelling.
23
+ */
24
+ function epicOf(issue, epics, parentOf) {
25
+ const parent = issue && issue.parent ? parentOf(issue) : null
26
+ return parent && epics.has(parent) ? parent : null
27
+ }
28
+
29
+ /** Top-level issues, plus the members of a linked epic. */
30
+ function keepSpecIssues(issues, epics, parentOf) {
31
+ return (issues || []).filter((i) => !i.parent || epicOf(i, epics, parentOf))
32
+ }
33
+
34
+ /**
35
+ * Rows reordered so each member follows its epic's row. A member whose epic's
36
+ * row is not in the listing keeps its place. Rows carry `epic` when a member.
37
+ */
38
+ function groupUnderEpics(rows) {
39
+ const listed = new Set(rows.map((r) => r.identifier))
40
+ const under = (id) => rows.filter((r) => r.epic === id)
41
+ return rows.filter((r) => !r.epic || !listed.has(r.epic)).flatMap((r) => [r, ...under(r.identifier)])
42
+ }
43
+
44
+ module.exports = { epicIdentifiers, epicOf, keepSpecIssues, groupUnderEpics }
@@ -13,7 +13,7 @@
13
13
  * stored matches what was sent — it merges nothing (see `src/verify.js`).
14
14
  */
15
15
 
16
- const { ownsField, ownershipOf, normalizeLocal, LIFECYCLE_BUCKETS, lintPhases, readSnapshot, parseFrontmatter, remoteWorkflowState, remoteStateReading, stateNamesFor, titleFromText, validateStates, stateSuggestions, effectiveStates, specHeaders, linkedIncident, phaseModeFor } = require('./src/normalize.js')
16
+ const { ownsField, ownershipOf, normalizeLocal, LIFECYCLE_BUCKETS, lintPhases, readSnapshot, parseFrontmatter, remoteWorkflowState, remoteStateReading, stateNamesFor, titleFromText, validateStates, stateSuggestions, effectiveStates, specHeaders, parseWaitsOn, linkedIncident, linkedEpic, phaseModeFor } = require('./src/normalize.js')
17
17
  const { planChanges, snapshotOf, isEmptyPlan, hashField, stableStringify, remoteDescriptionEdited, remoteSubIssueEdited } = require('./src/compare.js')
18
18
  const { readBase, writeBase } = require('./src/base.js')
19
19
  const { push, recordPush, projectionOf } = require('./src/push.js')
@@ -50,7 +50,9 @@ module.exports = {
50
50
  stateSuggestions,
51
51
  effectiveStates,
52
52
  specHeaders,
53
+ parseWaitsOn,
53
54
  linkedIncident,
55
+ linkedEpic,
54
56
  hashField,
55
57
  stableStringify,
56
58
  readBase,
@@ -435,24 +435,68 @@ function readSnapshot(snapshotDir, config) {
435
435
  return { frontmatter: data, title, sections, phases, body }
436
436
  }
437
437
 
438
- // The spec's own `> **Severity:**` and `> **Incident:**` headers, off the
439
- // overview's blockquote block. They are PUSH-TIME EXTRAS, deliberately not
440
- // keys on `normalizeLocal`'s field set: severity lands in a provider-specific
441
- // home (a field, a label) and the incident link as a typed relation, so
442
- // neither belongs in the synced-field hashes a stored base compares.
438
+ // The spec's own `> **Severity:**`, `> **Incident:**`, `> **Epic:**`,
439
+ // `> **Waits on:**` and `> **Lanes:**` headers, off the overview's blockquote
440
+ // block. They are PUSH-TIME EXTRAS, deliberately not keys on `normalizeLocal`'s
441
+ // field set: severity lands in a provider-specific home (a field, a label),
442
+ // the incident and epic links as typed relations, and the waits and lanes are
443
+ // read by `epic status` — none belongs in the synced-field hashes a stored base
444
+ // compares.
443
445
  function specHeaders(snapshotDir, config) {
444
446
  const overviewFile = (config && config.snapshot && config.snapshot.overviewFile) || '00-overview.md'
445
447
  let raw
446
448
  try {
447
449
  raw = fs.readFileSync(path.join(snapshotDir, overviewFile), 'utf-8')
448
450
  } catch {
449
- return { severity: null, incident: null }
451
+ return { severity: null, incident: null, epic: null, waitsOn: [], lanes: null }
450
452
  }
451
453
  const read = (name) => {
452
454
  const m = new RegExp(`^>\\s*\\*\\*${name}:\\*\\*\\s*(.+)$`, 'm').exec(raw)
453
455
  return m ? m[1].trim() : null
454
456
  }
455
- return { severity: read('Severity'), incident: read('Incident') }
457
+ return {
458
+ severity: read('Severity'),
459
+ incident: read('Incident'),
460
+ epic: unquote(read('Epic')) || null,
461
+ waitsOn: parseWaitsOn(read('Waits on')),
462
+ lanes: parseLanes(read('Lanes')),
463
+ }
464
+ }
465
+
466
+ // A header value a hand may have wrapped in backticks, as a spec name usually is.
467
+ function unquote(value) {
468
+ return value == null ? value : value.replace(/^`(.*)`$/, '$1').trim()
469
+ }
470
+
471
+ // `> **Waits on:** <spec>[ phase N], …` → `[{ spec, phase }]`, `phase` null for
472
+ // a whole-spec wait. `none` (or the `—` placeholder) is an empty list.
473
+ //
474
+ // A MALFORMED ENTRY IS KEPT, never dropped: `{ spec: null, phase: null, raw }`.
475
+ // Dropping it would make a wait nobody can read look like no wait at all, and
476
+ // `epic status` would then call the member ready — the accusation running the
477
+ // wrong way. Kept, it reports as cannot-tell (`.claude/rules/negative-checks.md`).
478
+ function parseWaitsOn(value) {
479
+ if (!value) return []
480
+ const trimmed = value.trim()
481
+ if (/^(none|—|-)$/i.test(trimmed)) return []
482
+ return trimmed
483
+ .split(',')
484
+ .map((part) => part.trim())
485
+ .filter(Boolean)
486
+ .map((part) => {
487
+ const m = /^`?([a-z0-9][a-z0-9._-]*)`?(?:\s+phase\s+(\d+))?$/i.exec(part)
488
+ if (!m) return { spec: null, phase: null, raw: part }
489
+ return { spec: m[1], phase: m[2] ? Number(m[2]) : null, raw: part }
490
+ })
491
+ }
492
+
493
+ // `> **Lanes:** N` — a positive whole number, else null. An unreadable cap is
494
+ // no cap, which `epic status` reports as uncapped rather than guessing one.
495
+ function parseLanes(value) {
496
+ if (!value) return null
497
+ const m = /^(\d+)$/.exec(value.trim())
498
+ const n = m ? Number(m[1]) : 0
499
+ return n > 0 ? n : null
456
500
  }
457
501
 
458
502
  // Resolve a fix spec's `> **Incident:**` header to the incident spec it names:
@@ -479,6 +523,39 @@ function linkedIncident(snapshotDir, config) {
479
523
  return { name: incident, identifier: null, found: false }
480
524
  }
481
525
 
526
+ // A member spec's `> **Epic:**` resolved the way `linkedIncident` resolves its
527
+ // header: the epic's folder in any bucket and its stamped identifier, or
528
+ // `identifier: null` when the epic is not linked yet (report and carry on —
529
+ // never mint the other). No header returns null.
530
+ //
531
+ // A FOLDER NOT ON DISK IS NOT PROOF THE EPIC DOES NOT EXIST, for the reason
532
+ // `linkedIncident` gives: buckets are branch-local truth.
533
+ function linkedEpic(snapshotDir, config) {
534
+ const { epic } = specHeaders(snapshotDir, config)
535
+ if (!epic) return null
536
+ const root = path.resolve(snapshotDir, '..', '..', '..')
537
+ const overviewFile = (config && config.snapshot && config.snapshot.overviewFile) || '00-overview.md'
538
+ for (const bucket of ['in-progress', 'backlog', 'complete', 'cancelled']) {
539
+ const file = path.join(root, 'specs', bucket, epic, overviewFile)
540
+ if (!fs.existsSync(file)) continue
541
+ const { data } = parseFrontmatter(fs.readFileSync(file, 'utf-8'))
542
+ const idField = config && config.fields && config.fields.identifier
543
+ const identifier = idField && data[idField] != null ? String(data[idField]) : null
544
+ return { name: epic, identifier, found: true }
545
+ }
546
+ return { name: epic, identifier: null, found: false }
547
+ }
548
+
549
+ // The member's one-line pointer to its epic. Part of the PROJECTION, like the
550
+ // related-incident line, so the stored base, the plan and the tracker hash the
551
+ // same bytes — and so a spec that only GAINS an `Epic:` header still has a
552
+ // change to push, which is what gives the parent link a push to ride on.
553
+ function epicLine(snapshotDir, config) {
554
+ const epic = linkedEpic(snapshotDir, config)
555
+ if (!epic) return ''
556
+ return `\n\nEpic: ${epic.identifier || epic.name}`
557
+ }
558
+
482
559
  // The one-line cross-reference a fix spec's body carries to its incident. Part
483
560
  // of the PROJECTION (not appended at send time), so the stored base, the plan
484
561
  // and what the tracker holds all hash the same bytes — and on GitHub the
@@ -815,7 +892,8 @@ function normalizeLocal(snapshotDir, config) {
815
892
  description: summaryMode
816
893
  ? wrapBlock(
817
894
  dialect.flattenTables(dialect.canonicalize(specBlockInner({ snapshotDir, sections, body, phases }))) +
818
- relatedIncidentLine(snapshotDir, config),
895
+ relatedIncidentLine(snapshotDir, config) +
896
+ epicLine(snapshotDir, config),
819
897
  config,
820
898
  )
821
899
  : withInlinePhases(
@@ -834,7 +912,9 @@ function normalizeLocal(snapshotDir, config) {
834
912
  tasksMode,
835
913
  config.sync.localOnlySections,
836
914
  dialect,
837
- ) + relatedIncidentLine(snapshotDir, config),
915
+ ) +
916
+ relatedIncidentLine(snapshotDir, config) +
917
+ epicLine(snapshotDir, config),
838
918
  // Sub-issue projection: one per phase. `ref` is the phase-file basename — the
839
919
  // local handle the push skill stamps a newly-created sub-issue id back into.
840
920
  // `state` is the phase's status bucket (from its heading emoji), mapped to a
@@ -1131,5 +1211,7 @@ module.exports = {
1131
1211
  remoteStateReading,
1132
1212
  stateNamesFor,
1133
1213
  specHeaders,
1214
+ parseWaitsOn,
1134
1215
  linkedIncident,
1216
+ linkedEpic,
1135
1217
  }