@alterset/alterspec-client 0.14.0 → 0.16.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.
package/dist/cli.js CHANGED
@@ -33,7 +33,11 @@ var WorkTaskSchema = z.object({
33
33
  * Sorted, never empty.
34
34
  */
35
35
  items: z.array(z.string().min(1)).min(1),
36
- /** The tasks this one waits for, resolved: the same change's `BE` task, and the track's tasks it builds on. */
36
+ /**
37
+ * The tasks this one waits for, resolved and reduced: the same change's `BE` task, and the track's tasks of the
38
+ * changes it builds on that did the same work (an item of both, a line of a whole object this task edits again,
39
+ * or an object this task names that entered the export with the earlier change).
40
+ */
37
41
  after: z.array(z.object({ change: ChangeRef, track: TrackCode }).strict())
38
42
  }).strict();
39
43
  var WorkChangeSchema = z.object({
@@ -315,9 +319,8 @@ function keyOf(loaded) {
315
319
  }
316
320
  var sessionOf = (loaded) => new Session(loaded.config.dispatcher, keyOf(loaded));
317
321
 
318
- // ../src/export/read.ts
319
- import { existsSync as existsSync3, readFileSync as readFileSync3, readdirSync } from "fs";
320
- import { join as join3 } from "path";
322
+ // src/bugs.ts
323
+ import { z as z8 } from "zod";
321
324
 
322
325
  // ../src/schemas/delta.ts
323
326
  import { z as z6 } from "zod";
@@ -529,6 +532,26 @@ function exportChange(e) {
529
532
  return "not in the export";
530
533
  }
531
534
 
535
+ // ../src/changes/data-change.ts
536
+ var DATA_CHANGE_SECTION = "One-time data change";
537
+ var DATA_CHANGE_ITEM = "data-change";
538
+ var DATA_CHANGE_RE = new RegExp(`^(CHG-\\d{3,})#${DATA_CHANGE_ITEM}$`);
539
+ function dataChangeText(sectionText2) {
540
+ const text = sectionText2?.trim();
541
+ return text && !/^none\b/i.test(text) ? text : void 0;
542
+ }
543
+
544
+ // ../src/export/paths.ts
545
+ var EXPORT_JSON = "export.json";
546
+ var WORK_JSON = "work.json";
547
+ var SHARDS_DIR = "_shards";
548
+ var slug = (text) => text.normalize("NFKD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/[đłøæœßþ]/g, (c) => ({ \u0111: "d", \u0142: "l", \u00F8: "o", \u00E6: "ae", \u0153: "oe", \u00DF: "ss", \u00FE: "th" })[c] ?? c).replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60).replace(/-+$/, "") || "section";
549
+ var shardDir = (path) => `${SHARDS_DIR}/${path.replace(/\.md$/, "")}`;
550
+ var itemShardName = (key) => `${key.startsWith("term:") ? slug(key.slice(5)) : key}.md`;
551
+ var itemShardPath = (path, key) => `${shardDir(path)}/${itemShardName(key)}`;
552
+ var FRONT_MATTER_SHARD = "00-front-matter.yaml";
553
+ var isSectionShard = (name, heading) => new RegExp(`^\\d{2}-${slug(heading)}\\.md$`).test(name);
554
+
532
555
  // ../src/lib/frontmatter-split.ts
533
556
  var FRONT_MATTER = /^---\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/;
534
557
  function splitFrontMatter(source) {
@@ -541,6 +564,79 @@ function splitFrontMatter(source) {
541
564
  };
542
565
  }
543
566
 
567
+ // ../src/changes/parts.ts
568
+ var FRONT_MATTER_PART = "front-matter";
569
+ var itemObject = (item) => item.startsWith("file:") ? item : item.replace(/-AC-\d{2}$/, "").replace(/[.#][^.#]*$/, "");
570
+ var forWork = (text) => text.replace(/^[^\S\n]*<!--[\s\S]*?-->[^\S\n]*\n/gm, "").replace(/<!--[\s\S]*?-->/g, "").replace(/^version:[^\S\n]*\d+[^\S\n]*\n/m, "").replace(/^(?:reviewed|dry|page):[^\n]*\n/gm, "");
571
+ function objectParts(text, kind) {
572
+ const out = /* @__PURE__ */ new Map();
573
+ const put = (label, heading, body2) => {
574
+ const base = label === "front-matter" ? FRONT_MATTER_PART : slug(heading);
575
+ let key = base;
576
+ for (let n = 2; out.has(key); n++) key = `${base}-${n}`;
577
+ out.set(key, { label, heading, text: body2 });
578
+ };
579
+ const t = forWork(text);
580
+ if (kind === "doc") {
581
+ const { raw, body: body2 } = splitFrontMatter(t);
582
+ if (raw) put("front-matter", FRONT_MATTER_PART, raw);
583
+ for (const s of headed(body2, "## ").sections) put("section", s.heading, s.text);
584
+ return out;
585
+ }
586
+ const yaml = /^```ya?ml\n([\s\S]*?)\n```[^\S\n]*$/m.exec(t);
587
+ if (yaml) put("front-matter", FRONT_MATTER_PART, yaml[1]);
588
+ const body = yaml ? t.slice(yaml.index + yaml[0].length) : t.replace(/^## [^\n]*\n?/, "");
589
+ const { sections } = headed(body, "### ");
590
+ if (sections.length) for (const s of sections) put("section", s.heading, s.text);
591
+ else for (const b of bullets(body)) put("line", b.heading, b.text);
592
+ return out;
593
+ }
594
+ function headed(text, marker) {
595
+ const sections = [];
596
+ let intro = "";
597
+ let fence2 = false;
598
+ for (const l of text.split("\n")) {
599
+ if (/^(?:```|~~~)/.test(l)) fence2 = !fence2;
600
+ if (!fence2 && l.startsWith(marker) && /\S/.test(l.slice(marker.length))) {
601
+ sections.push({ heading: l.slice(marker.length).trim(), text: "" });
602
+ continue;
603
+ }
604
+ if (sections.length) sections[sections.length - 1].text += `${l}
605
+ `;
606
+ else intro += `${l}
607
+ `;
608
+ }
609
+ return { intro, sections };
610
+ }
611
+ var BULLET = /^(?:[-*+]|\d+[.)])\s+(.*)$/;
612
+ function bullets(text) {
613
+ const out = [];
614
+ let current;
615
+ let fence2 = false;
616
+ for (const l of text.split("\n")) {
617
+ if (/^(?:```|~~~)/.test(l)) {
618
+ fence2 = !fence2;
619
+ current = void 0;
620
+ continue;
621
+ }
622
+ if (fence2) continue;
623
+ const m = BULLET.exec(l);
624
+ if (m) {
625
+ current = { heading: lead(m[1]), text: `${l}
626
+ ` };
627
+ out.push(current);
628
+ } else if (current && /^\s+\S/.test(l)) current.text += `${l}
629
+ `;
630
+ else current = void 0;
631
+ }
632
+ return out;
633
+ }
634
+ var lead = (s) => s.replace(/\*\*|__|`/g, "").split(/:\s|:$|\s[—–-]\s|\.\s|\.$/)[0].trim().split(/\s+/).slice(0, 8).join(" ");
635
+
636
+ // ../src/export/read.ts
637
+ import { existsSync as existsSync3, readFileSync as readFileSync3, readdirSync } from "fs";
638
+ import { join as join3 } from "path";
639
+
544
640
  // ../src/spec/layout.ts
545
641
  var ROOT_DOCS = {
546
642
  application: "application.md",
@@ -586,17 +682,6 @@ var ARCHIVED_PROPOSAL = new RegExp(
586
682
  String.raw`^(?:${MODULES_DIR}\/(?<mod>[^/]+)\/)?${CHANGES_DIR}\/archive\/(?<change>[^/]+)\/proposal\.md$`
587
683
  );
588
684
 
589
- // ../src/export/paths.ts
590
- var EXPORT_JSON = "export.json";
591
- var WORK_JSON = "work.json";
592
- var SHARDS_DIR = "_shards";
593
- var slug = (text) => text.normalize("NFKD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/[đłøæœßþ]/g, (c) => ({ \u0111: "d", \u0142: "l", \u00F8: "o", \u00E6: "ae", \u0153: "oe", \u00DF: "ss", \u00FE: "th" })[c] ?? c).replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60).replace(/-+$/, "") || "section";
594
- var shardDir = (path) => `${SHARDS_DIR}/${path.replace(/\.md$/, "")}`;
595
- var itemShardName = (key) => `${key.startsWith("term:") ? slug(key.slice(5)) : key}.md`;
596
- var itemShardPath = (path, key) => `${shardDir(path)}/${itemShardName(key)}`;
597
- var FRONT_MATTER_SHARD = "00-front-matter.yaml";
598
- var isSectionShard = (name, heading) => new RegExp(`^\\d{2}-${slug(heading)}\\.md$`).test(name);
599
-
600
685
  // ../src/export/read.ts
601
686
  var ExportReadError = class extends Error {
602
687
  };
@@ -672,15 +757,6 @@ function idsIn(text, kinds) {
672
757
  }
673
758
  var frontMatterOf = (text) => splitFrontMatter(text).raw ?? "";
674
759
 
675
- // ../src/changes/data-change.ts
676
- var DATA_CHANGE_SECTION = "One-time data change";
677
- var DATA_CHANGE_ITEM = "data-change";
678
- var DATA_CHANGE_RE = new RegExp(`^(CHG-\\d{3,})#${DATA_CHANGE_ITEM}$`);
679
- function dataChangeText(sectionText2) {
680
- const text = sectionText2?.trim();
681
- return text && !/^none\b/i.test(text) ? text : void 0;
682
- }
683
-
684
760
  // ../src/lib/diff.ts
685
761
  var linesOf = (text) => text === "" ? [] : text.replace(/\n$/, "").split("\n");
686
762
  function diffLines(a, b) {
@@ -1119,22 +1195,26 @@ function withSections(diff, before, after) {
1119
1195
  }).join("\n");
1120
1196
  }
1121
1197
  var BOOKKEEPING = /^(reviewed|page|dry|status|version|signed_off|base):/;
1198
+ var firstAddedLine = (a, b) => diffLines(a, b).filter((l) => l.op === "+").map(
1199
+ (l) => l.text.replace(/^\s*(?:[-*]|#+|\d+\.)\s+/, "").replace(/\*\*/g, "").trim()
1200
+ ).find((t) => t && !/^(---|```)/.test(t) && !BOOKKEEPING.test(t));
1201
+ var clipped = (line) => line && line.length > 200 ? `${line.slice(0, 199)}\u2026` : line;
1122
1202
  function firstAdded(key, entry) {
1123
- const added = (a, b) => diffLines(a, b).filter((l) => l.op === "+").map(
1124
- (l) => l.text.replace(/^\s*(?:[-*]|#+|\d+\.)\s+/, "").replace(/\*\*/g, "").trim()
1125
- ).find((t) => t && !/^(---|```)/.test(t) && !BOOKKEEPING.test(t));
1126
1203
  const before = forDiff(key, entry.before);
1127
1204
  const after = forDiff(key, entry.after);
1128
- const line = added(splitFrontMatter(before).body, splitFrontMatter(after).body) ?? added(splitFrontMatter(before).raw ?? "", splitFrontMatter(after).raw ?? "");
1129
- return line && line.length > 200 ? `${line.slice(0, 199)}\u2026` : line;
1205
+ return clipped(
1206
+ firstAddedLine(splitFrontMatter(before).body, splitFrontMatter(after).body) ?? firstAddedLine(splitFrontMatter(before).raw ?? "", splitFrontMatter(after).raw ?? "")
1207
+ );
1130
1208
  }
1131
- function objectBrief(x, key, entry, why) {
1209
+ function objectBrief(x, key, entry, why, later = []) {
1132
1210
  const file = x.fileOf(key);
1133
1211
  const held = file !== void 0 && x.has(file);
1134
1212
  const brief = { key, ...held ? { file } : {} };
1135
1213
  if (held && x.shards(file).length) brief.shards = x.shards(file)[0].replace(/\/[^/]+$/, "");
1136
1214
  if (why) brief.unrecoverable = why;
1137
1215
  if (!entry) return brief;
1216
+ const differs = held && entry.exported.after && entry.after !== void 0 && !entry.binary && forDiff(key, entry.after).trim() !== forDiff(key, x.read(file)).trim();
1217
+ if (later.length || differs) brief.since = { changes: later, differs: !!differs };
1138
1218
  brief.change = exportChange(entry);
1139
1219
  if (entry.status) brief.status = entry.status;
1140
1220
  if (entry.before !== void 0 || entry.after !== void 0) {
@@ -1223,6 +1303,18 @@ function itemWhat(x, item, entry, track) {
1223
1303
  if (item.startsWith("term:")) return `glossary term "${item.slice(5)}"`;
1224
1304
  if (DATA_CHANGE_RE.test(item))
1225
1305
  return `the one-time change to the records the product already holds (the proposal's "${DATA_CHANGE_SECTION}", below)`;
1306
+ const part = /^([^#]+)#([^#]+)$/.exec(item);
1307
+ if (part && !/^UX-/.test(item)) {
1308
+ const [, key, slug2] = part;
1309
+ const k = idKind(key);
1310
+ const owner = `${k && KIND_WORDS[k] ? `${KIND_WORDS[k]} ` : ""}${named(x, key)}`;
1311
+ const kind2 = entry?.kind === "item" ? "item" : "doc";
1312
+ const after = entry?.after !== void 0 ? objectParts(entry.after, kind2).get(slug2) : void 0;
1313
+ const before = entry?.before !== void 0 ? objectParts(entry.before, kind2).get(slug2) : void 0;
1314
+ const label = !after ? `the part "${slug2}"` : after.label === "front-matter" ? "the front-matter" : after.label === "section" ? `the section "${after.heading}"` : `the line "${after.heading}"`;
1315
+ const line2 = after ? clipped(firstAddedLine(before?.text ?? "", after.text)) : void 0;
1316
+ return `${label} of ${owner}${line2 ? `: "${line2}"` : ""}`;
1317
+ }
1226
1318
  const kind = idKind(item);
1227
1319
  const what = `${kind && KIND_WORDS[kind] ? `${KIND_WORDS[kind]} ` : ""}${named(x, item)}`;
1228
1320
  if (!entry) return what;
@@ -1285,6 +1377,60 @@ function whereUsed(x, objects, entries, changed) {
1285
1377
  }
1286
1378
  return out;
1287
1379
  }
1380
+ function laterChanges(x, change, key) {
1381
+ const order = x.work.changes.map((c) => c.id);
1382
+ const at = order.indexOf(change);
1383
+ const touched = x.sources.get(key)?.changed_by ?? [];
1384
+ return touched.filter((c) => order.indexOf(c) > at).sort((a, b) => order.indexOf(a) - order.indexOf(b));
1385
+ }
1386
+ function lifecycleOf(x, id) {
1387
+ const e = x.index()?.entities.find((e2) => e2.id === id);
1388
+ if (!e?.states?.length) return void 0;
1389
+ const states = e.states.map((s) => s === e.initial_state ? `${s} (initial)` : s).join(", ");
1390
+ const transitions = (e.transitions ?? []).map((t) => `${t.from}->${t.to}${t.by === "time" ? ` by time${t.at ? ` at ${t.at}` : ""}` : ""}`).join(", ");
1391
+ return `states ${states}${transitions ? `; transitions ${transitions}` : "; no transitions"}`;
1392
+ }
1393
+ function reachOf(x, id, kind, changed) {
1394
+ const index = x.index();
1395
+ if (!index) return void 0;
1396
+ const piece = (pid, title2, scope) => ({
1397
+ id: pid,
1398
+ path: x.fileOf(pid) ?? "",
1399
+ ...title2 ? { title: title2 } : {},
1400
+ ...changed.has(pid) ? { changed: true } : {},
1401
+ ...scope ? { scope } : {}
1402
+ });
1403
+ const screenPiece = (sid) => piece(sid, index.screens.find((s) => s.id === sid)?.title ?? titleOf(x, sid));
1404
+ const title = titleOf(x, id);
1405
+ if (kind === "rule") {
1406
+ const caps2 = index.capabilities.filter((c) => (c.rules ?? []).includes(id));
1407
+ const criteria = caps2.flatMap((c) => {
1408
+ const file = x.fileOf(c.id);
1409
+ const text = file && x.has(file) ? sectionText(x, x.sectionShard(file, "Acceptance criteria")) : void 0;
1410
+ return (text ?? "").split(/^(?=### )/m).filter(
1411
+ (chunk) => chunk.startsWith("### ") && new RegExp(`^\\s*[-*]?\\s*\\**Covers:?\\**[^\\n]*\\b${id}\\b`, "m").test(chunk)
1412
+ ).map((chunk) => chunk.slice(4).split(/\s/)[0]);
1413
+ });
1414
+ const screens2 = [...new Set(caps2.flatMap((c) => c.screens ?? []))].filter((sid) => x.sources.has(sid));
1415
+ return {
1416
+ id,
1417
+ kind,
1418
+ ...title ? { title } : {},
1419
+ capabilities: caps2.map((c) => piece(c.id, c.title)),
1420
+ criteria,
1421
+ screens: screens2.map(screenPiece)
1422
+ };
1423
+ }
1424
+ const caps = index.capabilities.filter((c) => (c.roles ?? []).some((r) => r.role === id));
1425
+ const screens = index.screens.filter((s) => (s.roles ?? []).some((r) => r.role === id));
1426
+ return {
1427
+ id,
1428
+ kind,
1429
+ ...title ? { title } : {},
1430
+ capabilities: caps.map((c) => piece(c.id, c.title, c.roles?.find((r) => r.role === id)?.scope)),
1431
+ screens: screens.map((s) => piece(s.id, s.title))
1432
+ };
1433
+ }
1288
1434
  function taskContext(x, task, exportDir2, state = {}, questions) {
1289
1435
  const change = x.work.changes.find((c) => c.id === task.change);
1290
1436
  if (!change) throw new ContextError(`${task.change} is not in this export's work.json: pull the export.`);
@@ -1310,7 +1456,7 @@ function taskContext(x, task, exportDir2, state = {}, questions) {
1310
1456
  const covered = state.covered?.get(item);
1311
1457
  return {
1312
1458
  item,
1313
- what: itemWhat(x, item, entries.get(item), task.track),
1459
+ what: itemWhat(x, item, entries.get(itemObject(item)), task.track),
1314
1460
  ...covered ? { covered } : {}
1315
1461
  };
1316
1462
  }),
@@ -1336,7 +1482,9 @@ function taskContext(x, task, exportDir2, state = {}, questions) {
1336
1482
  ...dataChangeOf(sectionText(x, x.sectionShard(proposal, DATA_CHANGE_SECTION)))
1337
1483
  },
1338
1484
  ...delta ? { delta: proposal.replace(/proposal\.md$/, "delta.md") } : {},
1339
- objects: work.objects.map((key) => objectBrief(x, key, entries.get(key), lost.get(key)))
1485
+ objects: work.objects.map(
1486
+ (key) => objectBrief(x, key, entries.get(key), lost.get(key), laterChanges(x, change.id, key))
1487
+ )
1340
1488
  };
1341
1489
  const added = work.objects.flatMap((key) => {
1342
1490
  const e = entries.get(key);
@@ -1403,6 +1551,13 @@ function taskContext(x, task, exportDir2, state = {}, questions) {
1403
1551
  };
1404
1552
  ctx.rules = carried("rule");
1405
1553
  ctx.events = carried("event");
1554
+ const whole = (kind) => {
1555
+ const bearing2 = idsIn(written.join("\n"), [kind]);
1556
+ const own = work.objects.filter((k) => idKind(k) === kind);
1557
+ return [.../* @__PURE__ */ new Set([...own, ...bearing2])].flatMap((id) => piece(id, true));
1558
+ };
1559
+ ctx.nfr = whole("nfr");
1560
+ ctx.integrations = whole("integration");
1406
1561
  ctx.entities = [
1407
1562
  .../* @__PURE__ */ new Set([
1408
1563
  ...work.objects.filter((k) => idKind(k) === "entity"),
@@ -1412,7 +1567,16 @@ function taskContext(x, task, exportDir2, state = {}, questions) {
1412
1567
  const file = x.fileOf(id);
1413
1568
  if (!file || !x.has(file)) return [];
1414
1569
  const title = titleOf(x, id);
1415
- return [{ id, path: file, ...title ? { title } : {}, ...changed.has(id) ? { changed: true } : {} }];
1570
+ const note = lifecycleOf(x, id);
1571
+ return [
1572
+ {
1573
+ id,
1574
+ path: file,
1575
+ ...title ? { title } : {},
1576
+ ...changed.has(id) ? { changed: true } : {},
1577
+ ...note ? { note } : {}
1578
+ }
1579
+ ];
1416
1580
  });
1417
1581
  ctx.operations = x.has(OPERATIONS_FILE) ? capabilities.flatMap((id) => {
1418
1582
  const path = x.shards(OPERATIONS_FILE).find((p) => new RegExp(`/\\d{2}-${slug(id)}(-|\\.md$)`).test(p));
@@ -1442,6 +1606,18 @@ function taskContext(x, task, exportDir2, state = {}, questions) {
1442
1606
  const bearing = idsIn(written.join("\n"), ["decision"]);
1443
1607
  const named2 = idsIn(work.objects.map((k) => entries.get(k)?.after ?? "").join("\n"), ["decision"]);
1444
1608
  ctx.decisions = [.../* @__PURE__ */ new Set([...bearing, ...named2])].flatMap((id) => piece(id, bearing.includes(id)));
1609
+ const rules = [
1610
+ .../* @__PURE__ */ new Set([
1611
+ ...work.objects.filter((k) => idKind(k) === "rule"),
1612
+ ...(ctx.rules ?? []).filter((r) => r.text).map((r) => r.id)
1613
+ ])
1614
+ ];
1615
+ const roles = work.objects.filter((k) => idKind(k) === "role");
1616
+ ctx.reach = [
1617
+ ...rules.map((id) => reachOf(x, id, "rule", changed)),
1618
+ ...roles.map((id) => reachOf(x, id, "role", changed))
1619
+ ].filter((r) => !!r);
1620
+ if (!ctx.reach.length) delete ctx.reach;
1445
1621
  const glossary = x.fileOf("term:");
1446
1622
  const writtenText = written.join("\n");
1447
1623
  ctx.terms = (glossary && x.has(glossary) ? x.shards(glossary) : []).filter((path) => !/\/\d{2}-[^/]*$/.test(path)).flatMap((path) => {
@@ -1509,6 +1685,13 @@ function renderContext(c) {
1509
1685
  const status = o.status && o.status.before !== o.status.after ? `, ${o.status.before ?? "\u2014"} \u2192 ${o.status.after ?? "\u2014"}` : "";
1510
1686
  out.push(`### ${o.key}`, "", `${o.change ?? "no delta entry"}${status}; ${where}.`);
1511
1687
  if (o.unrecoverable) out.push("", `The delta could not recover it: ${o.unrecoverable}.`);
1688
+ if (o.since) {
1689
+ const later = o.since.changes.length ? `Changed since this sign-off by ${o.since.changes.join(", ")} (later in the change map; their deltas are next to their proposals). ` : "";
1690
+ out.push(
1691
+ "",
1692
+ o.since.differs ? `${later}The current text differs from this delta\u2019s after: build to the current file, the checklist follows the current text.` : `${later}The current text still equals this delta\u2019s after.`
1693
+ );
1694
+ }
1512
1695
  if (o.diff) out.push("", o.diff.startsWith("@@") ? fence(o.diff, "diff") : o.diff);
1513
1696
  out.push("");
1514
1697
  }
@@ -1538,6 +1721,33 @@ function renderContext(c) {
1538
1721
  }
1539
1722
  out.push("");
1540
1723
  }
1724
+ if (c.reach?.length) {
1725
+ out.push(
1726
+ "## Reach",
1727
+ "",
1728
+ "Where the export enforces, holds or shows the rules and roles this task touches or names; a capability or screen not in the export isn\u2019t listed.",
1729
+ ""
1730
+ );
1731
+ const list2 = (ps) => ps.map((p) => `${p.id}${p.scope ? ` (${p.scope})` : ""}${p.changed ? " (this task changes it)" : ""}`).join(", ");
1732
+ for (const r of c.reach) {
1733
+ const name = `${r.id}${r.title ? ` ${r.title}` : ""}`;
1734
+ if (r.kind === "rule") {
1735
+ const parts = [
1736
+ r.capabilities.length ? `enforced by ${list2(r.capabilities)}` : "no capability lists it",
1737
+ r.criteria?.length ? `covered by ${r.criteria.join(", ")}` : "no criterion covers it",
1738
+ r.screens.length ? `on ${list2(r.screens)}` : "on no screen"
1739
+ ];
1740
+ out.push(`- ${name}: ${parts.join("; ")}.`);
1741
+ } else {
1742
+ const parts = [
1743
+ r.capabilities.length ? `may perform ${list2(r.capabilities)}` : "may perform no capability",
1744
+ r.screens.length ? `on ${list2(r.screens)}` : "on no screen"
1745
+ ];
1746
+ out.push(`- ${name}: ${parts.join("; ")}.`);
1747
+ }
1748
+ }
1749
+ out.push("");
1750
+ }
1541
1751
  const pieces = (title, list2, intro) => {
1542
1752
  if (!list2?.length) return;
1543
1753
  out.push(`## ${title}`, "");
@@ -1552,7 +1762,7 @@ function renderContext(c) {
1552
1762
  );
1553
1763
  for (const p of list2.filter((p2) => !p2.text))
1554
1764
  out.push(
1555
- `- ${p.id}${p.title ? ` ${p.title}` : ""}: \`${p.path}\`${p.changed ? " (this task changes it: its delta is above)" : ""}`
1765
+ `- ${p.id}${p.title ? ` ${p.title}` : ""}: \`${p.path}\`${p.changed ? " (this task changes it: its delta is above)" : ""}${p.note ? `; ${p.note}` : ""}`
1556
1766
  );
1557
1767
  out.push("");
1558
1768
  };
@@ -1574,7 +1784,17 @@ function renderContext(c) {
1574
1784
  pieces(
1575
1785
  "Entities",
1576
1786
  c.entities,
1577
- "The entities the task\u2019s capabilities work with; open one for its attributes, states and transitions."
1787
+ "The entities the task\u2019s capabilities work with, each with its lifecycle; open one for its attributes."
1788
+ );
1789
+ pieces(
1790
+ "Quality requirements",
1791
+ c.nfr,
1792
+ "The quality requirements the task touches or the change\u2019s text names, whole (one the task adds is whole in its delta above)."
1793
+ );
1794
+ pieces(
1795
+ "Integrations",
1796
+ c.integrations,
1797
+ "The integrations the task touches or the change\u2019s text names, whole (one the task adds is whole in its delta above)."
1578
1798
  );
1579
1799
  pieces("Operations for other systems", c.operations);
1580
1800
  pieces(
@@ -1615,6 +1835,188 @@ function contextStats(markdown) {
1615
1835
  ].join("\n") + "\n";
1616
1836
  }
1617
1837
 
1838
+ // src/bugs.ts
1839
+ var BugTaskSchema = z8.object({
1840
+ id: z8.string(),
1841
+ track: z8.string(),
1842
+ status: z8.string(),
1843
+ developer: z8.string().nullish(),
1844
+ items: z8.array(z8.string()).default([]),
1845
+ /** The built tasks it waits for. */
1846
+ after: z8.array(z8.string()).default([]),
1847
+ branch: z8.string().nullish(),
1848
+ in_main: z8.boolean().nullish()
1849
+ });
1850
+ var BugSchema = z8.object({
1851
+ id: z8.string(),
1852
+ title: z8.string(),
1853
+ description: z8.string(),
1854
+ /** The reporter. */
1855
+ developer: z8.string(),
1856
+ at: z8.string(),
1857
+ export: z8.string().nullish(),
1858
+ cites: z8.array(z8.string()).default([]),
1859
+ /** The changes of the tasks it waits for. */
1860
+ origin: z8.array(z8.string()).default([]),
1861
+ status: z8.enum(["open", "done", "dismissed"]).default("open"),
1862
+ dismissed: z8.object({ by: z8.string(), at: z8.string(), reason: z8.string(), duplicate_of: z8.string().nullish() }).nullish(),
1863
+ tasks: z8.array(BugTaskSchema).default([])
1864
+ });
1865
+ var BugsError = class extends Error {
1866
+ };
1867
+ async function listBugs(session, filter = {}) {
1868
+ const answer = await callTool(session, "bugs", {
1869
+ ...filter.about ? { about: filter.about } : { mine: true },
1870
+ ...filter.status ? { status: filter.status } : {},
1871
+ ...filter.track ? { track: filter.track } : {}
1872
+ });
1873
+ const parsed = z8.array(BugSchema).safeParse(answer.bugs ?? []);
1874
+ if (!parsed.success) throw new BugsError("The dispatcher\u2019s bugs are not in a form this client reads.");
1875
+ return parsed.data;
1876
+ }
1877
+ var one2 = (text) => text.replace(/\s+/g, " ").trim();
1878
+ function bugTaskWords(t) {
1879
+ const who = t.developer ? ` (${t.developer})` : "";
1880
+ const where = t.status === "blocked" && t.after.length ? `, after ${t.after.join(", ")}` : t.status === "done" ? t.in_main ? ", in main" : t.branch ? `, on \`${t.branch}\`` : "" : "";
1881
+ return `${t.id} ${t.status}${who}${where}`;
1882
+ }
1883
+ function bugLines(b) {
1884
+ const state = b.status === "dismissed" ? `dismissed by ${b.dismissed?.by ?? "an admin"}${b.dismissed?.duplicate_of ? `, duplicate of ${b.dismissed.duplicate_of}` : ""}` : b.status;
1885
+ const lines = [`- ${b.id} (${state}; ${b.developer}, ${b.at.slice(0, 10)}): ${one2(b.title)}`];
1886
+ if (b.cites.length) lines.push(` - Cites: ${b.cites.join(", ")}`);
1887
+ if (b.dismissed) lines.push(` - Reason: ${one2(b.dismissed.reason)}`);
1888
+ else if (b.tasks.length) lines.push(` - Tasks: ${b.tasks.map(bugTaskWords).join("; ")}`);
1889
+ return lines;
1890
+ }
1891
+ function bugsText(bugs) {
1892
+ if (!bugs.length) return "No bugs.\n";
1893
+ return bugs.flatMap(bugLines).join("\n") + "\n";
1894
+ }
1895
+ function parseBug(raw) {
1896
+ const parsed = BugSchema.safeParse(raw);
1897
+ return parsed.success ? parsed.data : void 0;
1898
+ }
1899
+ async function bugTaskState(session, task) {
1900
+ let answer;
1901
+ try {
1902
+ answer = await callTool(session, "task", { id: task.id });
1903
+ } catch (e) {
1904
+ throw new BugsError(
1905
+ `${task.id} is a bug's task, and only the dispatcher holds a bug: ${e.message.split("\n")[0]}`
1906
+ );
1907
+ }
1908
+ const bug = parseBug(answer.bug);
1909
+ if (!bug) throw new BugsError(`The dispatcher sent no bug for ${task.id} this client reads.`);
1910
+ const items = answer.items ?? [];
1911
+ const from = startFrom(task.track, answer.after);
1912
+ return {
1913
+ bug,
1914
+ objects: z8.array(z8.string()).catch([]).parse(answer.objects),
1915
+ after: (answer.after ?? []).flatMap((a) => a.id ? [a.id] : []),
1916
+ covered: new Map(items.flatMap((i) => i.covered_commit ? [[i.item, i.covered_commit]] : [])),
1917
+ ...from.length ? { startFrom: from } : {}
1918
+ };
1919
+ }
1920
+ var objectOfItem = (item, objects) => [...objects].filter(
1921
+ (o) => item === o || item.startsWith(`${o}-`) || item.startsWith(`${o}.`) || item.startsWith(`${o}#`)
1922
+ ).sort((a, b) => b.length - a.length)[0] ?? item.replace(/(-AC-\d+|\.A\d+|#.+)$/, "");
1923
+ function bugContext(x, task, exportDir2, state, questions) {
1924
+ const track = x.work.tracks.find((t) => t.code === task.track) ?? {
1925
+ code: task.track,
1926
+ kind: "ui",
1927
+ channels: []
1928
+ };
1929
+ const keys = [
1930
+ ...new Set(state.objects.length ? state.objects : state.bug.cites.map((c) => objectOfItem(c, [])))
1931
+ ];
1932
+ const objects = keys.map((key) => {
1933
+ const file = x.fileOf(key);
1934
+ const held = file !== void 0 && x.has(file);
1935
+ const o = { key, ...held ? { file } : {} };
1936
+ if (held && x.shards(file).length) o.shards = x.shards(file)[0].replace(/\/[^/]+$/, "");
1937
+ const by = x.sources.get(key)?.changed_by;
1938
+ if (by?.length) o.changed_by = by;
1939
+ return o;
1940
+ });
1941
+ return {
1942
+ task: task.id,
1943
+ bug: state.bug,
1944
+ track: { code: track.code, kind: track.kind, channels: track.channels },
1945
+ export: exportDir2,
1946
+ ...questions?.length ? { questions } : {},
1947
+ after: state.after,
1948
+ ...state.startFrom?.length ? { startFrom: state.startFrom } : {},
1949
+ checklist: {
1950
+ items: state.bug.cites.map((item) => {
1951
+ const covered = state.covered?.get(item);
1952
+ return { item, what: itemWhat(x, item, void 0, task.track), ...covered ? { covered } : {} };
1953
+ })
1954
+ },
1955
+ objects,
1956
+ origin: state.bug.origin.map((id) => {
1957
+ const change = x.work.changes.find((c) => c.id === id);
1958
+ const proposal = x.proposalPath(id);
1959
+ return { id, ...change ? { title: change.title } : {}, ...proposal ? { proposal } : {} };
1960
+ })
1961
+ };
1962
+ }
1963
+ function renderBugContext(c) {
1964
+ const b = c.bug;
1965
+ const out = [
1966
+ `# ${c.task}: ${b.title}`,
1967
+ "",
1968
+ `Track ${c.track.code} (${c.track.kind}${c.track.channels.length ? `: ${c.track.channels.join(", ")}` : ""}). Bug ${b.id}, raised by ${b.developer} on ${b.at.slice(0, 10)}${b.export ? `, groomed against export ${b.export.slice(0, 12)}` : ""}${b.origin.length ? `, in what ${b.origin.join(", ")} built` : ""}. Paths are relative to the export, ${c.export}.`
1969
+ ];
1970
+ if (c.after.length) out.push("", `Waits for: ${c.after.join(", ")}.`);
1971
+ if (c.startFrom?.length)
1972
+ out.push(
1973
+ "",
1974
+ `Start from ${c.startFrom.map((s) => `\`${s.branch}\` (${s.id}${s.commit ? ` done at ${s.commit.slice(0, 12)}` : ""})`).join(", then ")}, not from the main branch: the work the bug is in is pushed there and not merged yet (fetch it and base your branch on \`origin/${c.startFrom[c.startFrom.length - 1].branch}\`).`
1975
+ );
1976
+ out.push("");
1977
+ if (c.questions?.length) out.push(...questionsSection(c.questions));
1978
+ out.push(
1979
+ "## The bug",
1980
+ "",
1981
+ "The reporter\u2019s words, naming IDs; what the spec says is in the export, under the objects below. The product deviates from the cited items: make it do what they say, and nothing else. The tasks that built them stay as they are; this task is the fix.",
1982
+ "",
1983
+ b.description.trim(),
1984
+ "",
1985
+ `Cites: ${b.cites.join(", ")}.`
1986
+ );
1987
+ const done = c.checklist.items.filter((i) => i.covered).length;
1988
+ out.push(
1989
+ "",
1990
+ `## Checklist (${done} of ${c.checklist.items.length} covered)`,
1991
+ "",
1992
+ "The cited items. Name an item in `Alterspec-Covers` on the commit with which its tests pass again.",
1993
+ "",
1994
+ ...c.checklist.items.map(
1995
+ (i) => `- [${i.covered ? "x" : " "}] \`${i.item}\`: ${i.what}${i.covered ? ` (covered by ${i.covered.slice(0, 12)})` : ""}`
1996
+ )
1997
+ );
1998
+ out.push("", "## The objects", "", "What the spec says now; a bug is fixed against the current text.", "");
1999
+ for (const o of c.objects) {
2000
+ const where = o.file ? `\`${o.file}\`${o.shards ? `, shards in \`${o.shards}/\`` : ""}` : "not in the export now";
2001
+ out.push(
2002
+ `- ${o.key}: ${where}${o.changed_by?.length ? `; last changed by ${o.changed_by.join(", ")}` : ""}.`
2003
+ );
2004
+ }
2005
+ if (c.origin.length) {
2006
+ out.push(
2007
+ "",
2008
+ "## The changes it originates in",
2009
+ "",
2010
+ "What was built and found wanting; their proposals say why.",
2011
+ ""
2012
+ );
2013
+ for (const ch of c.origin)
2014
+ out.push(`- ${ch.id}${ch.title ? ` ${ch.title}` : ""}${ch.proposal ? `: ${ch.proposal}` : ""}`);
2015
+ }
2016
+ out.push("");
2017
+ return out.join("\n");
2018
+ }
2019
+
1618
2020
  // src/git.ts
1619
2021
  import { execFileSync as execFileSync3 } from "child_process";
1620
2022
  import { existsSync as existsSync4 } from "fs";
@@ -1625,16 +2027,23 @@ var TRAILER = "Alterspec-Task";
1625
2027
  var TaskError = class extends Error {
1626
2028
  };
1627
2029
  function parseTask(text) {
1628
- const m = /^(CHG-\d{3})\/([A-Z]{2,5})$/.exec(text.trim().toUpperCase());
2030
+ const m = /^(CHG-\d{3}|BUG-[1-9]\d*)\/([A-Z]{2,5})$/.exec(text.trim().toUpperCase());
1629
2031
  if (!m)
1630
- throw new TaskError(`"${text}" is not a task: write it as CHG-012/BE (the change, a slash, the track).`);
1631
- return { id: `${m[1]}/${m[2]}`, change: m[1], track: m[2] };
2032
+ throw new TaskError(
2033
+ `"${text}" is not a task: write it as CHG-012/BE (the change, a slash, the track), or BUG-3/BE for a bug's.`
2034
+ );
2035
+ return {
2036
+ id: `${m[1]}/${m[2]}`,
2037
+ change: m[1],
2038
+ track: m[2],
2039
+ kind: m[1].startsWith("BUG-") ? "bug" : "change"
2040
+ };
1632
2041
  }
1633
2042
  var branchOf = (t) => `task/${t.change.toLowerCase()}-${t.track.toLowerCase()}`;
1634
2043
  var folderOf = (t) => `${t.change.toLowerCase()}-${t.track.toLowerCase()}`;
1635
2044
  var COVERS = "Alterspec-Covers";
1636
2045
  function taskOfBranch(branch) {
1637
- const m = /^task\/(chg-\d{3})-([a-z]{2,5})$/.exec(branch?.trim() ?? "");
2046
+ const m = /^task\/(chg-\d{3}|bug-[1-9]\d*)-([a-z]{2,5})$/.exec(branch?.trim() ?? "");
1638
2047
  return m ? parseTask(`${m[1]}/${m[2]}`) : void 0;
1639
2048
  }
1640
2049
 
@@ -2566,13 +2975,27 @@ program.command("export-head").description("pull the export clone and print its
2566
2975
  process.stdout.write(JSON.stringify(head, null, 2) + "\n");
2567
2976
  })
2568
2977
  );
2569
- program.command("context").description("print a task\u2019s brief, assembled from the export").argument("<task>", "the task, e.g. CHG-012/BE").option("--json", "print it as JSON").option("--stats", "print its size by section instead").action(
2978
+ program.command("context").description("print a task\u2019s brief, assembled from the export").argument("<task>", "the task, e.g. CHG-012/BE or BUG-3/BE").option("--json", "print it as JSON").option("--stats", "print its size by section instead").action(
2570
2979
  run(async (id, opts) => {
2571
2980
  const loaded = loadConfig();
2572
2981
  approveWorktree(loaded);
2573
2982
  const dir = exportDir(loaded);
2574
2983
  const x = readExport(dir);
2575
2984
  const task = parseTask(id);
2985
+ if (task.kind === "bug") {
2986
+ const session = sessionOf(loaded);
2987
+ const ctx2 = bugContext(
2988
+ x,
2989
+ task,
2990
+ dir,
2991
+ await bugTaskState(session, task),
2992
+ await changeQuestions(session, [task.id])
2993
+ );
2994
+ process.stdout.write(
2995
+ opts.stats ? contextStats(renderBugContext(ctx2)) : opts.json ? JSON.stringify(ctx2, null, 2) + "\n" : renderBugContext(ctx2)
2996
+ );
2997
+ return;
2998
+ }
2576
2999
  const tasks = [
2577
3000
  task.id,
2578
3001
  ...(x.work.changes.find((c) => c.id === task.change)?.tasks ?? []).map((t) => `${task.change}/${t.track}`).filter((t) => t !== task.id)
@@ -2656,6 +3079,18 @@ program.command("questions").description("print the questions the dispatcher kee
2656
3079
  process.stdout.write(opts.json ? JSON.stringify(questions, null, 2) + "\n" : questionsText(questions));
2657
3080
  })
2658
3081
  );
3082
+ program.command("bugs").description("print the bugs the dispatcher keeps: the ones naming some IDs, or without --about your own").option("--about <id...>", "everyone\u2019s bugs whose cites, title or description name these IDs").option("--status <status>", "only the open, done or dismissed ones").option("--track <code>", "only those with a task on this track").option("--json", "print them as JSON").action(
3083
+ run(async (opts) => {
3084
+ if (opts.status && !["open", "done", "dismissed"].includes(opts.status))
3085
+ throw new Error(`--status takes open, done or dismissed, not "${opts.status}".`);
3086
+ const bugs = await listBugs(sessionOf(loadConfig()), {
3087
+ ...opts.about ? { about: opts.about } : {},
3088
+ ...opts.status ? { status: opts.status } : {},
3089
+ ...opts.track ? { track: opts.track.toUpperCase() } : {}
3090
+ });
3091
+ process.stdout.write(opts.json ? JSON.stringify(bugs, null, 2) + "\n" : bugsText(bugs));
3092
+ })
3093
+ );
2659
3094
  program.command("merged").description(
2660
3095
  "print the commit and branch to report done with: the pushed task branch\u2019s head, or the commit on origin/<main> that brought the task in"
2661
3096
  ).argument("<task>", "the task, e.g. CHG-012/BE").option("--json", "print { commit, branch } as JSON").action(