@alterset/alterspec-client 0.30.0 → 0.32.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
@@ -93,9 +93,8 @@ var WorkChangeSchema = z.object({
93
93
  initiative: InitiativeRef.optional()
94
94
  }).strict();
95
95
  var WorkInitiativeSchema = z.object({ id: InitiativeRef, title: z.string().min(1) }).strict();
96
- var WORK_FORMAT = 8;
97
- var WorkSchema = z.object({
98
- format: z.literal(WORK_FORMAT),
96
+ var WorkV8Schema = z.object({
97
+ format: z.literal(8),
99
98
  /** The alterspec version that wrote the export. */
100
99
  alterspec: z.string(),
101
100
  exported: Day,
@@ -112,8 +111,54 @@ var WorkSchema = z.object({
112
111
  /** The initiatives the changes name, by ID (format 8). Absent when no change names one. */
113
112
  initiatives: z.array(WorkInitiativeSchema).optional()
114
113
  }).strict();
114
+ var Version = z.string().regex(/^[0-9a-f]{12}$/);
115
+ var TaskRef = z.object({ change: ChangeRef, track: TrackCode }).strict();
116
+ var WorkBriefPartSchema = z.object({
117
+ kind: z.enum(["capability", "used_by", "decision", "object"]),
118
+ key: z.string().min(1),
119
+ /** A file path inside the export, never an anchor; `paragraphs` names a decision's paragraphs. */
120
+ path: z.string().min(1),
121
+ bytes: z.number().int().min(0),
122
+ touched: z.boolean().optional(),
123
+ paragraphs: z.array(z.string().min(1)).optional()
124
+ }).strict();
125
+ var WorkTaskV9Schema = WorkTaskSchema.extend({
126
+ /** The version of every object, item and cited decision paragraph (`DEC-573#p3`) of the task, as of this export. */
127
+ versions: z.record(z.string().min(1), Version).optional(),
128
+ /** The tracks whose existing behaviour this task changes; sorted, never its own track. */
129
+ alters: z.array(TrackCode).optional(),
130
+ brief: z.object({ bytes: z.number().int().min(0), parts: z.array(WorkBriefPartSchema) }).strict().optional(),
131
+ /** The signed-off tasks whose cited objects a later edit changed, which this task exists for. A label only. */
132
+ amends: z.array(TaskRef).optional()
133
+ }).strict().refine((t) => !t.alters?.includes(t.track), {
134
+ message: "alters never names the task's own track",
135
+ path: ["alters"]
136
+ });
137
+ var WorkChangeV9Schema = WorkChangeSchema.extend({
138
+ tasks: z.array(WorkTaskV9Schema).optional(),
139
+ released: z.literal(false).optional(),
140
+ coupled: z.literal(true).optional()
141
+ }).strict().refine((c) => c.released === false ? c.tasks === void 0 : c.tasks !== void 0, {
142
+ message: "a held change (released: false) has no tasks; a released one has tasks",
143
+ path: ["tasks"]
144
+ });
145
+ var WorkReleaseSchema = z.object({
146
+ id: z.string().regex(/^R-\d{4}-\d{2}-\d{2}-\d+$/),
147
+ date: Day,
148
+ note: z.string().max(400).refine((t) => !/[\r\n]/.test(t), { message: "one line" }),
149
+ changes: z.array(ChangeRef),
150
+ held: z.array(ChangeRef),
151
+ touches: z.record(ChangeRef, z.array(z.string().min(1)))
152
+ }).strict();
153
+ var WorkV9Schema = WorkV8Schema.extend({
154
+ format: z.literal(9),
155
+ changes: z.array(WorkChangeV9Schema),
156
+ /** The path of every object any task names, every decision any task cites, and every initiative. */
157
+ paths: z.record(z.string().min(1), z.string().min(1)).optional(),
158
+ release: WorkReleaseSchema.optional()
159
+ }).strict();
115
160
  var WorkChangeV7Schema = WorkChangeSchema.omit({ initiative: true }).strict();
116
- var WorkV7Schema = WorkSchema.omit({ initiatives: true }).extend({ format: z.literal(7), changes: z.array(WorkChangeV7Schema) }).strict();
161
+ var WorkV7Schema = WorkV8Schema.omit({ initiatives: true }).extend({ format: z.literal(7), changes: z.array(WorkChangeV7Schema) }).strict();
117
162
  var WorkTaskV6Schema = WorkTaskSchema.omit({ weight: true }).strict();
118
163
  var WorkChangeV6Schema = WorkChangeV7Schema.extend({
119
164
  tasks: z.array(WorkTaskV6Schema),
@@ -157,7 +202,8 @@ var AnyWorkSchema = z.discriminatedUnion("format", [
157
202
  WorkV5Schema,
158
203
  WorkV6Schema,
159
204
  WorkV7Schema,
160
- WorkSchema
205
+ WorkV8Schema,
206
+ WorkV9Schema
161
207
  ]);
162
208
 
163
209
  // src/config.ts
@@ -554,7 +600,7 @@ var Status = z4.enum(["draft", "ready", "signed_off"], {
554
600
  var Scope = z4.enum(["own", "team", "org", "all"]);
555
601
  var Op = z4.enum(["C", "R", "U", "D", "A"]);
556
602
  var Title = z4.string().trim().min(1, { message: "must not be empty" });
557
- var Version = z4.number().int().min(1);
603
+ var Version2 = z4.number().int().min(1);
558
604
  var StateName = z4.string().regex(/^[a-z][a-z0-9_]*$/, {
559
605
  message: "must be a lowercase state name (letters, digits, underscore)"
560
606
  });
@@ -660,6 +706,11 @@ var ChangeSchema = z5.object({
660
706
  * `change new --initiative` and `change initiative`, on an archived proposal too.
661
707
  */
662
708
  initiative: InitiativeId.optional(),
709
+ /**
710
+ * Set when the change alters behaviour another track already built (`alters` in `work.json`): its server task
711
+ * reaches the main branch only after the change's client tasks are done. A hold, never a cycle in `after`.
712
+ */
713
+ coupled: z5.literal(true).optional(),
663
714
  /** The first 16 hex of the sha256 of the change's `delta.json`, written with it at sign-off, never rewritten. */
664
715
  delta: z5.string().regex(/^[0-9a-f]{16}$/).optional(),
665
716
  /**
@@ -1293,6 +1344,65 @@ import { z as z7 } from "zod";
1293
1344
 
1294
1345
  // src/mcp.ts
1295
1346
  import { createInterface } from "readline";
1347
+
1348
+ // src/related.ts
1349
+ var RELATED_FIRST = "RELATED_FIRST";
1350
+ var SHOWN = 10;
1351
+ var str = (v) => typeof v === "string" && v ? v : void 0;
1352
+ function settled(args) {
1353
+ return Boolean(str(args.joins) || str(args.extends) || args.new === true);
1354
+ }
1355
+ function aboutOf(args) {
1356
+ const cites = Array.isArray(args.cites) ? args.cites : [];
1357
+ const refs = [...cites, args.item].flatMap((r) => {
1358
+ const s = str(r);
1359
+ return s && !s.includes("/") ? [s.trim()] : [];
1360
+ });
1361
+ return [...new Set(refs)];
1362
+ }
1363
+ function forwardedArgs(args) {
1364
+ if (!("new" in args)) return args;
1365
+ const rest = { ...args };
1366
+ delete rest.new;
1367
+ return rest;
1368
+ }
1369
+ function stateOf(q) {
1370
+ const answers = Array.isArray(q.answers) ? q.answers : [];
1371
+ const answered = q.status === "answered" || answers.length > 0;
1372
+ if (str(q.merged_into)) return `joined into ${String(q.merged_into)}`;
1373
+ if (answered)
1374
+ return q.reconciled === true ? "answered, the spec says so now" : "answered, not in the export yet";
1375
+ if (q.outcome === "assumed") return "open, working on an assumption";
1376
+ return "open";
1377
+ }
1378
+ var one = (text, max = 160) => {
1379
+ const t = text.replace(/\s+/g, " ").trim();
1380
+ return t.length > max ? `${t.slice(0, max - 1)}\u2026` : t;
1381
+ };
1382
+ function relatedLines(questions) {
1383
+ if (!Array.isArray(questions)) return [];
1384
+ return questions.flatMap((v) => {
1385
+ const q = v;
1386
+ const id = str(q?.id);
1387
+ if (!q || !id) return [];
1388
+ const task = str(q.task);
1389
+ const text = str(q.question) ?? "";
1390
+ return [`- ${id} (${task ? `${task}; ` : ""}${stateOf(q)}): ${one(text)}`];
1391
+ });
1392
+ }
1393
+ function relatedRefusal(questions, about = []) {
1394
+ const lines = relatedLines(questions);
1395
+ if (!lines.length) return void 0;
1396
+ const more = lines.length - SHOWN;
1397
+ return [
1398
+ `Not posted: the dispatcher holds ${lines.length === 1 ? "a question" : `${lines.length} questions`} on the same objects. Read ${lines.length === 1 ? "it" : "them"} first (\`alterspec-client questions <id>\` prints one whole); an answer not in the export yet stands over the export's silence.`,
1399
+ ...lines.slice(0, SHOWN),
1400
+ ...more > 0 ? [`- and ${more} more: \`alterspec-client questions --about ${about.join(" ") || "<ID...>"}\``] : [],
1401
+ 'If one of them answers your question, use that answer and post nothing. Otherwise call `ask` again with `joins: "Q-<n>"` (another asker\u2019s question on the same matter: your task waits on its answer), `extends: "Q-<n>"` (your own earlier question: this is its next part), or `new: true` (none of them is this matter).'
1402
+ ].join("\n");
1403
+ }
1404
+
1405
+ // src/mcp.ts
1296
1406
  var isRequest = (m) => m.method !== void 0 && m.id !== void 0;
1297
1407
  async function callTool(session, name, args = {}) {
1298
1408
  const res = await session.fetch("/mcp", {
@@ -1385,6 +1495,16 @@ function runProxy(opts) {
1385
1495
  return error(id, e.advice);
1386
1496
  }
1387
1497
  }
1498
+ async function earlier(args) {
1499
+ const about = aboutOf(args);
1500
+ if (!about.length) return void 0;
1501
+ try {
1502
+ const answer = await callTool(session, "questions", { about });
1503
+ return relatedRefusal(answer.questions, about);
1504
+ } catch {
1505
+ return void 0;
1506
+ }
1507
+ }
1388
1508
  async function forward(m) {
1389
1509
  try {
1390
1510
  const gated = m.method === "tools/list" || m.method === "tools/call";
@@ -1401,6 +1521,20 @@ function runProxy(opts) {
1401
1521
  isError: true
1402
1522
  });
1403
1523
  }
1524
+ if (r === "developer" && tool === "ask") {
1525
+ const args = m.params?.arguments ?? {};
1526
+ const held = settled(args) ? void 0 : await earlier(args);
1527
+ if (held) {
1528
+ log(`ask held: ${RELATED_FIRST}`);
1529
+ if (!isRequest(m)) return;
1530
+ return result(m.id, {
1531
+ content: [{ type: "text", text: held }],
1532
+ structuredContent: { error: { code: RELATED_FIRST, message: held } },
1533
+ isError: true
1534
+ });
1535
+ }
1536
+ if ("new" in args) m = { ...m, params: { ...m.params, arguments: forwardedArgs(args) } };
1537
+ }
1404
1538
  }
1405
1539
  const headers = {
1406
1540
  "content-type": "application/json",
@@ -1468,7 +1602,7 @@ var QuestionSchema = z7.object({
1468
1602
  developer: z7.string(),
1469
1603
  at: z7.string(),
1470
1604
  question: z7.string(),
1471
- outcome: z7.enum(["spec", "assumed", "open"]),
1605
+ outcome: z7.enum(["spec", "assumed", "open", "proposal"]),
1472
1606
  status: z7.enum(["open", "answered"]),
1473
1607
  cites: z7.array(z7.string()).default([]),
1474
1608
  answer: z7.string().nullish(),
@@ -1476,7 +1610,15 @@ var QuestionSchema = z7.object({
1476
1610
  corrected: z7.boolean().optional(),
1477
1611
  /** The product side's mark: the spec now says what the answer says. */
1478
1612
  reconciled: z7.boolean().optional(),
1479
- answers: z7.array(AnswerSchema).default([])
1613
+ answers: z7.array(AnswerSchema).default([]),
1614
+ /** What an open question waits for (wave contract 2.4). */
1615
+ waits_for: z7.enum(["contradiction", "business"]).nullish(),
1616
+ /** Why an open question carries no reading of the spec. */
1617
+ no_reading: z7.string().nullish(),
1618
+ /** The question this one was joined into. */
1619
+ merged_into: z7.string().nullish(),
1620
+ /** The `REWORK-<n>` item a corrected assumption opened on the asking task. */
1621
+ rework: z7.string().nullish()
1480
1622
  });
1481
1623
  var TaskAnswerSchema = z7.object({
1482
1624
  question: z7.string(),
@@ -1511,7 +1653,7 @@ function missingCites(x, refs) {
1511
1653
  }
1512
1654
  async function listQuestions(session, filter = {}) {
1513
1655
  const answer = await callTool(session, "questions", {
1514
- ...filter.task ? { task: filter.task } : filter.about ? { about: filter.about } : { mine: true },
1656
+ ...filter.ids?.length ? { ids: filter.ids } : filter.task ? { task: filter.task } : filter.about ? { about: filter.about } : { mine: true },
1515
1657
  ...filter.open ? { status: "open" } : {}
1516
1658
  });
1517
1659
  const parsed = z7.array(QuestionSchema).safeParse(answer.questions ?? []);
@@ -1538,18 +1680,24 @@ function sortQuestions(questions) {
1538
1680
  const rank = (q) => isCorrected(q) ? 0 : q.status === "open" ? 1 : 2;
1539
1681
  return [...questions].sort((a, b) => rank(a) - rank(b));
1540
1682
  }
1541
- var one = (text) => text.replace(/\s+/g, " ").trim();
1683
+ var one2 = (text) => text.replace(/\s+/g, " ").trim();
1684
+ function stateOf2(q) {
1685
+ const last = holding(q);
1686
+ return isCorrected(q) ? "ASSUMPTION CORRECTED" : last ? q.outcome === "assumed" ? "assumption confirmed" : q.reconciled ? "answered by the product side" : "answered by the product side, not in the export yet" : q.outcome === "spec" ? "answered from the spec" : q.outcome === "assumed" ? "open, working on an assumption" : q.outcome === "proposal" ? "a proposal for the product side" : q.merged_into ? `joined into ${q.merged_into}` : q.waits_for === "contradiction" ? "open, waiting for the product side on a contradiction" : "open, waiting for the product side";
1687
+ }
1542
1688
  function questionLines(q) {
1543
1689
  const about = [q.task, q.item].filter(Boolean).join(" ");
1544
1690
  const last = holding(q);
1545
- const state = isCorrected(q) ? "ASSUMPTION CORRECTED" : last ? q.outcome === "assumed" ? "assumption confirmed" : "answered by the product side" : q.outcome === "spec" ? "answered from the spec" : q.outcome === "assumed" ? "open, working on an assumption" : "open, waiting for the product side";
1546
- const lines = [`- ${q.id} (${state}${about ? `; ${about}` : ""}): ${one(q.question)}`];
1547
- if (q.outcome === "assumed" && q.assumption) lines.push(` - Assumed: ${one(q.assumption)}`);
1691
+ const lines = [`- ${q.id} (${stateOf2(q)}${about ? `; ${about}` : ""}): ${one2(q.question)}`];
1692
+ if (q.outcome === "assumed" && q.assumption) lines.push(` - Assumed: ${one2(q.assumption)}`);
1693
+ if (q.outcome === "open" && q.assumption) lines.push(` - Reading: ${one2(q.assumption)}`);
1694
+ if (isCorrected(q) && q.rework)
1695
+ lines.push(` - Rework: ${q.rework}, covered with \`Alterspec-Covers: ${q.rework}\`.`);
1548
1696
  if (q.outcome === "spec" && q.answer)
1549
- lines.push(` - From the spec: ${one(q.answer)}${q.cites.length ? ` (${q.cites.join(", ")})` : ""}`);
1697
+ lines.push(` - From the spec: ${one2(q.answer)}${q.cites.length ? ` (${q.cites.join(", ")})` : ""}`);
1550
1698
  if (last)
1551
1699
  lines.push(
1552
- ` - Product side (${last.developer}, ${last.at.slice(0, 10)}): ${one(last.text)}${q.reconciled ? " The spec says so now." : last.change ? ` It comes into the spec with ${last.change}.` : ""}`
1700
+ ` - Product side (${last.developer}, ${last.at.slice(0, 10)}): ${one2(last.text)}${q.reconciled ? " The spec says so now." : `${last.change ? ` It comes into the spec with ${last.change}.` : ""} Not in the export yet: this answer stands over the export\u2019s silence.`}`
1553
1701
  );
1554
1702
  return lines;
1555
1703
  }
@@ -1557,17 +1705,27 @@ function questionsText(questions) {
1557
1705
  if (!questions.length) return "No questions.\n";
1558
1706
  return sortQuestions(questions).flatMap(questionLines).join("\n") + "\n";
1559
1707
  }
1560
- function questionsSection(questions) {
1708
+ function questionLine(q) {
1709
+ const about = [q.task, q.item].filter(Boolean).join(" ");
1710
+ return `- ${q.id} (${about ? `${about}; ` : ""}${stateOf2(q)}): \`alterspec-client questions ${q.id}\``;
1711
+ }
1712
+ function questionsSection(questions, full) {
1561
1713
  if (!questions.length) return [];
1562
1714
  const sorted = sortQuestions(questions);
1715
+ const whole = (q) => !full || full.has(q.id);
1716
+ const lined = sorted.filter((q) => !whole(q)).length;
1563
1717
  const corrected = sorted.filter(isCorrected).length;
1564
1718
  const open = sorted.filter((q) => q.status === "open").length;
1565
1719
  return [
1566
1720
  `## Questions (${open} open${corrected ? `, ${corrected} corrected` : ""})`,
1567
1721
  "",
1568
1722
  corrected ? "A corrected assumption is rework: what was built on it follows the product side\u2019s answer before the task is done." : "What was asked about this change, on any of its tracks (each names the task it was asked on). An open one on an assumption may still be corrected; an item waiting for an answer stays uncovered.",
1723
+ ...lined ? [
1724
+ "",
1725
+ `Whole: the questions asked on this track or answered with a change to an item of this task. The other ${lined} are one line each; read one with \`alterspec-client questions <id>\` when its object is in front of you.`
1726
+ ] : [],
1569
1727
  "",
1570
- ...sorted.flatMap(questionLines),
1728
+ ...sorted.flatMap((q) => whole(q) ? questionLines(q) : [questionLine(q)]),
1571
1729
  ""
1572
1730
  ];
1573
1731
  }
@@ -1597,20 +1755,108 @@ function answersSection(answers) {
1597
1755
  return [`## Built already (${built} of ${answers.length})`, "", how, "", ...answers.map(answerLine), ""];
1598
1756
  }
1599
1757
 
1758
+ // src/ruled.ts
1759
+ var str2 = (v) => typeof v === "string" && v.trim() ? v.trim() : void 0;
1760
+ function rulingOf(v) {
1761
+ if (typeof v === "string")
1762
+ return /^Q-\d+$/.test(v) ? { id: v, path: `alterspec-client questions ${v}` } : void 0;
1763
+ const r = v;
1764
+ if (!r || typeof r !== "object") return void 0;
1765
+ const id = str2(r.id) ?? str2(r.question_id) ?? (/^Q-\d+$/.test(String(r.question)) ? str2(r.question) : void 0);
1766
+ if (!id) return void 0;
1767
+ const answers = Array.isArray(r.answers) ? r.answers : [];
1768
+ const answer = r.answer;
1769
+ const text = r.full === false ? void 0 : str2(answer) ?? str2(answer?.text) ?? str2(r.text) ?? str2(answers.at(-1)?.text);
1770
+ const question = str2(r.title) ?? (str2(r.question) === id ? void 0 : str2(r.question));
1771
+ const about = [str2(r.task), str2(r.item) ?? str2(r.object)].filter(Boolean).join(" ") || void 0;
1772
+ const state = str2(r.state);
1773
+ return {
1774
+ id,
1775
+ ...question ? { question } : {},
1776
+ ...text ? { text } : {},
1777
+ ...about ? { about } : {},
1778
+ ...state ? { state } : {},
1779
+ path: str2(r.path) ?? `alterspec-client questions ${id}`
1780
+ };
1781
+ }
1782
+ function parseRuled(value) {
1783
+ if (!Array.isArray(value)) return void 0;
1784
+ const seen2 = /* @__PURE__ */ new Set();
1785
+ return value.flatMap((v) => {
1786
+ const r = rulingOf(v);
1787
+ if (!r || seen2.has(r.id)) return [];
1788
+ seen2.add(r.id);
1789
+ return [r];
1790
+ });
1791
+ }
1792
+ var one3 = (text) => text.replace(/\s+/g, " ").trim();
1793
+ function rulingLines(r) {
1794
+ const head = `- ${r.id}${r.about || r.state ? ` (${[r.about, r.state].filter(Boolean).join("; ")})` : ""}`;
1795
+ if (!r.text) return [`${head}: ${r.question ? `${one3(r.question)} ` : ""}\`${r.path}\``];
1796
+ return [`${head}${r.question ? `: ${one3(r.question)}` : ""}`, ` - Ruled: ${one3(r.text)}`];
1797
+ }
1798
+ function ruledChangedLines(changed) {
1799
+ if (!changed?.length) return [];
1800
+ return [
1801
+ `**A ruling changed since you last read this brief** (${changed.map((r) => r.id).join(", ")}): the product side replaced an answer this task saw. What you built on the earlier answer follows this one; the tests that checked the earlier answer change with it.`,
1802
+ "",
1803
+ ...changed.flatMap(rulingLines),
1804
+ ""
1805
+ ];
1806
+ }
1807
+ function ruledSection(ruled, shownWhole = /* @__PURE__ */ new Set()) {
1808
+ const list2 = (ruled ?? []).filter((r) => !shownWhole.has(r.id));
1809
+ if (!list2.length) return [];
1810
+ const whole = list2.filter((r) => r.text).length;
1811
+ return [
1812
+ "## Ruled, not in the export yet",
1813
+ "",
1814
+ [
1815
+ "The product side has answered these about this task\u2019s objects; the export will say so once the ruling is groomed and signed off. Build on them as you would on the spec, over the export\u2019s silence or older wording. Name no question number in code or tests: write the behaviour, as the spec will.",
1816
+ whole === list2.length ? "" : whole ? `Whole: the ${whole === 1 ? "ruling" : `${whole} rulings`} that change an item of this task; the others are one line each, read with the command they name when their object is in front of you.` : "None changes an item of this task: each is one line, read with the command it names when its object is in front of you."
1817
+ ].filter(Boolean).join(" "),
1818
+ "",
1819
+ ...list2.flatMap(rulingLines),
1820
+ ""
1821
+ ];
1822
+ }
1823
+
1600
1824
  // src/context.ts
1601
1825
  var ContextError = class extends Error {
1602
1826
  };
1827
+ function parseQuestionsFull(value) {
1828
+ if (!Array.isArray(value)) return void 0;
1829
+ return new Set(
1830
+ value.flatMap((v) => {
1831
+ const id = typeof v === "string" ? v : v?.id;
1832
+ return typeof id === "string" && id ? [id] : [];
1833
+ })
1834
+ );
1835
+ }
1836
+ function parseChangedSince(value) {
1837
+ if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
1838
+ const lists = ["added", "changed", "removed"].map((k) => value[k]);
1839
+ if (!lists.some(Array.isArray)) return void 0;
1840
+ return new Set(
1841
+ lists.flatMap(
1842
+ (l) => Array.isArray(l) ? l.flatMap((v) => {
1843
+ const key = typeof v === "string" ? v : v?.key ?? v?.id;
1844
+ return typeof key === "string" && key ? [key] : [];
1845
+ }) : []
1846
+ )
1847
+ );
1848
+ }
1603
1849
  function parseSiblings(value) {
1604
1850
  if (!Array.isArray(value)) return void 0;
1605
- const str = (v) => typeof v === "string" && v ? v : void 0;
1851
+ const str3 = (v) => typeof v === "string" && v ? v : void 0;
1606
1852
  return value.flatMap((v) => {
1607
- const id = str(v?.id);
1608
- const track = str(v?.track) ?? id?.split("/")[1];
1609
- const status = str(v?.status);
1853
+ const id = str3(v?.id);
1854
+ const track = str3(v?.track) ?? id?.split("/")[1];
1855
+ const status = str3(v?.status);
1610
1856
  if (!id || !track || !status) return [];
1611
- const commit = str(v.commit);
1612
- const branch = str(v.branch);
1613
- const inMain = str(v.in_main_at);
1857
+ const commit = str3(v.commit);
1858
+ const branch = str3(v.branch);
1859
+ const inMain = str3(v.in_main_at);
1614
1860
  return [
1615
1861
  {
1616
1862
  id,
@@ -1937,9 +2183,9 @@ function compatibilityOf(x, change, work, proposal) {
1937
2183
  const text = compatibilityText(sectionText(x, x.sectionShard(proposal, COMPATIBILITY_SECTION)));
1938
2184
  const crosses = (owner, ownerChange, a) => a.change !== ownerChange && a.track !== owner.track;
1939
2185
  const endedBy = x.work.changes.flatMap(
1940
- (other) => other.tasks.filter((t) => t.after.some((a) => a.change === change.id && crosses(t, other.id, a))).map((t) => `${other.id}/${t.track}`)
2186
+ (other) => (other.tasks ?? []).filter((t) => t.after.some((a) => a.change === change.id && crosses(t, other.id, a))).map((t) => `${other.id}/${t.track}`)
1941
2187
  );
1942
- const kept = text ? { text, tracks: change.tasks.filter((t) => t.track !== "BE").map((t) => t.track), endedBy } : void 0;
2188
+ const kept = text ? { text, tracks: (change.tasks ?? []).filter((t) => t.track !== "BE").map((t) => t.track), endedBy } : void 0;
1943
2189
  const byChange = /* @__PURE__ */ new Map();
1944
2190
  for (const a of work.after)
1945
2191
  if (crosses(work, change.id, a)) byChange.set(a.change, [...byChange.get(a.change) ?? [], a.track]);
@@ -1964,10 +2210,10 @@ function taskContext(current, task, exportDir2, state = {}, questions, opts = {}
1964
2210
  };
1965
2211
  const change = x.work.changes.find((c) => c.id === task.change);
1966
2212
  if (!change) throw new ContextError(`${task.change} is not in this export's work.json: pull the export.`);
1967
- const work = change.tasks.find((t) => t.track === task.track);
2213
+ const work = (change.tasks ?? []).find((t) => t.track === task.track);
1968
2214
  if (!work)
1969
2215
  throw new ContextError(
1970
- `${task.change} has no task on ${task.track}: its tracks are ${change.tasks.map((t) => t.track).join(", ") || "none"}.`
2216
+ `${task.change} has no task on ${task.track}: its tracks are ${(change.tasks ?? []).map((t) => t.track).join(", ") || "none"}.`
1971
2217
  );
1972
2218
  const track = x.work.tracks.find((t) => t.code === task.track);
1973
2219
  const proposal = x.proposalPath(task.change);
@@ -1994,6 +2240,7 @@ function taskContext(current, task, exportDir2, state = {}, questions, opts = {}
1994
2240
  ...words2.summary ? { summary: words2.summary } : {},
1995
2241
  ...words2.weight === void 0 ? {} : { weight: words2.weight },
1996
2242
  ...questions ? { questions } : {},
2243
+ ...questions && state.questionsFull ? { questionsFull: [...state.questionsFull].sort() } : {},
1997
2244
  ...state.answers?.length ? { answers: state.answers } : {},
1998
2245
  ...items ? {
1999
2246
  checklist: {
@@ -2024,7 +2271,14 @@ function taskContext(current, task, exportDir2, state = {}, questions, opts = {}
2024
2271
  track,
2025
2272
  after: work.after,
2026
2273
  ...state.startFrom?.length ? { startFrom: state.startFrom } : {},
2027
- ...state.siblings?.length ? { siblings: state.siblings } : {},
2274
+ ...state.siblings?.length ? {
2275
+ siblings: state.siblings.map((s) => {
2276
+ const alters = (change.tasks ?? []).find((t) => t.track === s.track)?.alters;
2277
+ return alters ? { ...s, alters } : s;
2278
+ })
2279
+ } : {},
2280
+ ...state.ruled?.length ? { ruled: state.ruled } : {},
2281
+ ...state.ruledChanged?.length ? { ruledChanged: state.ruledChanged } : {},
2028
2282
  ...compatibilityOf(x, change, work, proposal),
2029
2283
  proposal: {
2030
2284
  path: proposal,
@@ -2072,8 +2326,8 @@ function taskContext(current, task, exportDir2, state = {}, questions, opts = {}
2072
2326
  const idOf2 = (c) => c.slice(4).split(/\s/)[0];
2073
2327
  const listed = onList ? chunks.filter((c) => onList.has(idOf2(c))) : chunks;
2074
2328
  written2.push(...listed);
2075
- const kept = onList ? listed.filter((c) => existed.has(idOf2(c))) : chunks;
2076
- const added2 = listed.length - kept.length;
2329
+ const kept2 = onList ? listed.filter((c) => existed.has(idOf2(c))) : chunks;
2330
+ const added2 = listed.length - kept2.length;
2077
2331
  const title = titleOf(x, id);
2078
2332
  const rest = [
2079
2333
  added2 ? `${added2 === 1 ? "One new criterion is" : `${added2} new criteria are`} whole in its delta above.` : "",
@@ -2084,8 +2338,8 @@ function taskContext(current, task, exportDir2, state = {}, questions, opts = {}
2084
2338
  id,
2085
2339
  path: at(path),
2086
2340
  ...title ? { title } : {},
2087
- ...kept.length ? { text: kept.join("").trim() } : {},
2088
- ...kept.length && rest ? { rest } : {}
2341
+ ...kept2.length ? { text: kept2.join("").trim() } : {},
2342
+ ...kept2.length && rest ? { rest } : {}
2089
2343
  }
2090
2344
  ];
2091
2345
  });
@@ -2219,9 +2473,9 @@ function taskContext(current, task, exportDir2, state = {}, questions, opts = {}
2219
2473
  );
2220
2474
  lost2 = s.later.flatMap((l) => {
2221
2475
  if (l.entry.binary) return [];
2222
- const kept = linesOf2(key, l.entry.exported.after ? l.entry.after : void 0);
2476
+ const kept2 = linesOf2(key, l.entry.exported.after ? l.entry.after : void 0);
2223
2477
  const gone = [...linesOf2(key, l.entry.exported.before ? l.entry.before : void 0)].filter(
2224
- (line) => wrote.includes(line) && !kept.has(line)
2478
+ (line) => wrote.includes(line) && !kept2.has(line)
2225
2479
  );
2226
2480
  return gone.length ? [{ change: l.change, lines: gone }] : [];
2227
2481
  });
@@ -2241,17 +2495,24 @@ function taskContext(current, task, exportDir2, state = {}, questions, opts = {}
2241
2495
  }
2242
2496
  ];
2243
2497
  });
2244
- if (moved.length) {
2245
- ctx.changedSince = moved.sort(
2498
+ const cited = state.changedSince;
2499
+ const kept = cited ? moved.filter((e) => e.entered || cited.has(e.key)) : moved;
2500
+ if (cited) {
2501
+ const elsewhere = moved.length - kept.length;
2502
+ if (elsewhere) ctx.sinceElsewhere = elsewhere;
2503
+ if (!kept.some((e) => !e.entered)) ctx.changedSinceNone = true;
2504
+ }
2505
+ if (kept.length) {
2506
+ ctx.changedSince = kept.sort(
2246
2507
  (a, b) => Number(!!b.own) - Number(!!a.own) || (a.key < b.key ? -1 : a.key > b.key ? 1 : 0)
2247
2508
  );
2248
- const touched = new Set(moved.flatMap((e) => e.changes.map((ch) => ch.id)));
2509
+ const touched = new Set(kept.flatMap((e) => e.changes.map((ch) => ch.id)));
2249
2510
  ctx.later = x.work.changes.filter((c) => touched.has(c.id)).map((c) => {
2250
2511
  const delta2 = x.proposalPath(c.id)?.replace(/proposal\.md$/, "delta.md");
2251
2512
  return {
2252
2513
  id: c.id,
2253
2514
  title: c.title,
2254
- ...c.tasks.some((t) => t.track === task.track) ? { task: `${c.id}/${task.track}` } : {},
2515
+ ...(c.tasks ?? []).some((t) => t.track === task.track) ? { task: `${c.id}/${task.track}` } : {},
2255
2516
  ...delta2 ? { delta: delta2 } : {}
2256
2517
  };
2257
2518
  });
@@ -2324,14 +2585,20 @@ function checklistSection(c) {
2324
2585
  }
2325
2586
  return out;
2326
2587
  }
2588
+ function wholeQuestions(c) {
2589
+ const full = c.questionsFull ? new Set(c.questionsFull) : void 0;
2590
+ return new Set((c.questions ?? []).filter((q) => !full || full.has(q.id)).map((q) => q.id));
2591
+ }
2327
2592
  function renderChecklist(c) {
2328
2593
  const out = [
2329
2594
  `# ${c.task}: ${c.title ?? c.change.title}`,
2330
2595
  "",
2331
2596
  ...c.summary ? [c.summary, ""] : [],
2332
2597
  ...c.weight === void 0 ? [] : [`Task weight ${c.weight} of 100.`, ""],
2598
+ ...ruledChangedLines(c.ruledChanged),
2333
2599
  ...shippedLines(c),
2334
- ...c.questions?.length ? questionsSection(c.questions) : [],
2600
+ ...c.questions?.length ? questionsSection(c.questions, c.questionsFull ? new Set(c.questionsFull) : void 0) : [],
2601
+ ...ruledSection(c.ruled, wholeQuestions(c)),
2335
2602
  ...c.answers?.length ? answersSection(c.answers) : [],
2336
2603
  ...checklistSection(c),
2337
2604
  "",
@@ -2345,8 +2612,9 @@ function shippedLines(c) {
2345
2612
  for (const s of c.siblings ?? []) {
2346
2613
  if (s.status === "done") {
2347
2614
  const where = [s.commit?.slice(0, 12), s.in_main_at ? "in main" : s.branch ?? "main"].filter(Boolean).join(", ");
2615
+ const additive = s.alters !== void 0 && !s.alters.includes(c.track.code);
2348
2616
  out.push(
2349
- `**${s.track} has shipped this change** (${where})` + (kept ? ": the server keeps the old behaviour this change\u2019s Compatibility names until the other tracks\u2019 tasks are done (below)." : ": tests that check the behaviour it removes or changes are expected to fail until this task is done; updating them is part of this task."),
2617
+ `**${s.track} has shipped this change** (${where})` + (kept ? ": the server keeps the old behaviour this change\u2019s Compatibility names until the other tracks\u2019 tasks are done (below)." : additive ? `: it alters nothing ${c.track.code} already does, so no test of yours should fail because of it.` : ": tests that check the behaviour it removes or changes are expected to fail until this task is done; updating them is part of this task. This is not a question of task order: don\u2019t ask about it, fix the tests with the work."),
2350
2618
  ""
2351
2619
  );
2352
2620
  } else if (s.status === "in_progress") out.push(`${s.track} is building this change now.`, "");
@@ -2392,8 +2660,10 @@ function renderContext(c) {
2392
2660
  "",
2393
2661
  `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 predecessor's work is pushed there and not merged yet (fetch it and base your branch on \`origin/${c.startFrom[c.startFrom.length - 1].branch}\`).`
2394
2662
  );
2395
- out.push("", ...shippedLines(c));
2396
- if (c.questions?.length) out.push(...questionsSection(c.questions));
2663
+ out.push("", ...ruledChangedLines(c.ruledChanged), ...shippedLines(c));
2664
+ if (c.questions?.length)
2665
+ out.push(...questionsSection(c.questions, c.questionsFull ? new Set(c.questionsFull) : void 0));
2666
+ out.push(...ruledSection(c.ruled, wholeQuestions(c)));
2397
2667
  if (c.answers?.length) out.push(...answersSection(c.answers));
2398
2668
  out.push(...checklistSection(c));
2399
2669
  out.push("", `## Why (${c.proposal.path})`, "", c.proposal.why || "(none written)");
@@ -2561,8 +2831,20 @@ function renderContext(c) {
2561
2831
  ""
2562
2832
  );
2563
2833
  }
2834
+ if (c.changedSinceNone && !movedSince.length)
2835
+ out.push(
2836
+ "## Changed since (other tasks\u2019 work)",
2837
+ "",
2838
+ `No part of this task changed (the dispatcher\u2019s list).${c.sinceElsewhere ? ` ${c.sinceElsewhere === 1 ? "One other object" : `${c.sinceElsewhere} other objects`} the brief names ${c.sinceElsewhere === 1 ? "was" : "were"}, in other tasks\u2019 work.` : ""}`,
2839
+ ""
2840
+ );
2564
2841
  if (c.changedSince?.length) {
2565
- out.push("## Changed since (other tasks\u2019 work)", "");
2842
+ if (!(c.changedSinceNone && !movedSince.length)) out.push("## Changed since (other tasks\u2019 work)", "");
2843
+ if (c.sinceElsewhere && movedSince.length)
2844
+ out.push(
2845
+ `Only the objects this task cites (the dispatcher\u2019s list); ${c.sinceElsewhere === 1 ? "one other object" : `${c.sinceElsewhere} other objects`} the brief names ${c.sinceElsewhere === 1 ? "was" : "were"} changed in other tasks\u2019 work.`,
2846
+ ""
2847
+ );
2566
2848
  const names = (e) => `${e.key}${e.title ? ` ${e.title}` : ""}${e.own ? " (this task changes it)" : ""}`;
2567
2849
  if (movedSince.length) {
2568
2850
  out.push(
@@ -2683,7 +2965,7 @@ async function listBugs(session, filter = {}) {
2683
2965
  if (!parsed.success) throw new BugsError("The dispatcher\u2019s bugs are not in a form this client reads.");
2684
2966
  return parsed.data;
2685
2967
  }
2686
- var one2 = (text) => text.replace(/\s+/g, " ").trim();
2968
+ var one4 = (text) => text.replace(/\s+/g, " ").trim();
2687
2969
  function bugTaskWords(t) {
2688
2970
  const who = t.developer ? ` (${t.developer})` : "";
2689
2971
  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}\`` : "" : "";
@@ -2691,9 +2973,9 @@ function bugTaskWords(t) {
2691
2973
  }
2692
2974
  function bugLines(b) {
2693
2975
  const state = b.status === "dismissed" ? `dismissed by ${b.dismissed?.by ?? "an admin"}${b.dismissed?.duplicate_of ? `, duplicate of ${b.dismissed.duplicate_of}` : ""}` : b.status;
2694
- const lines = [`- ${b.id} (${state}; ${b.developer}, ${b.at.slice(0, 10)}): ${one2(b.title)}`];
2976
+ const lines = [`- ${b.id} (${state}; ${b.developer}, ${b.at.slice(0, 10)}): ${one4(b.title)}`];
2695
2977
  if (b.cites.length) lines.push(` - Cites: ${b.cites.join(", ")}`);
2696
- if (b.dismissed) lines.push(` - Reason: ${one2(b.dismissed.reason)}`);
2978
+ if (b.dismissed) lines.push(` - Reason: ${one4(b.dismissed.reason)}`);
2697
2979
  else if (b.tasks.length) lines.push(` - Tasks: ${b.tasks.map(bugTaskWords).join("; ")}`);
2698
2980
  return lines;
2699
2981
  }
@@ -3436,7 +3718,7 @@ function lookup(x, opts) {
3436
3718
  }
3437
3719
  if (opts.item) add(opts.item);
3438
3720
  if (!about.size && opts.task) {
3439
- const task = x.work.changes.find((c) => c.id === opts.task.change)?.tasks.find((t) => t.track === opts.task.track);
3721
+ const task = x.work.changes.find((c) => c.id === opts.task.change)?.tasks?.find((t) => t.track === opts.task.track);
3440
3722
  for (const key of task?.objects ?? []) if (x.sources.has(key) && !key.startsWith("file:")) add(key);
3441
3723
  }
3442
3724
  const links = (id) => {
@@ -3838,6 +4120,17 @@ function whoamiText(me) {
3838
4120
  if (role === "developer") {
3839
4121
  const tracks = Array.isArray(me.tracks) ? me.tracks : [];
3840
4122
  if (tracks.length) lines.push(`Tracks: ${tracks.join(", ")}`);
4123
+ const count = (v) => typeof v === "number" ? v : Array.isArray(v) ? v.length : 0;
4124
+ const changed = count(me.ruled_changed);
4125
+ const shipped = count(me.shipped_for_you);
4126
+ if (changed)
4127
+ lines.push(
4128
+ `Rulings changed on your tasks: ${changed} (\`alterspec-client context <task>\` says which and what follows).`
4129
+ );
4130
+ if (shipped)
4131
+ lines.push(
4132
+ `Changes another track has shipped, with a task of yours still open: ${shipped} (the brief says what that means for your tests).`
4133
+ );
3841
4134
  }
3842
4135
  if (latest?.commit)
3843
4136
  lines.push(`Latest ingested export: ${latest.commit}${latest.ordinal ? ` (#${latest.ordinal})` : ""}`);
@@ -3863,6 +4156,10 @@ async function coveredState(loaded, task) {
3863
4156
  const answers = parseAnswers(answer.answers);
3864
4157
  const from = startFrom(task.track, answer.after);
3865
4158
  const siblings = parseSiblings(answer.siblings);
4159
+ const questionsFull = parseQuestionsFull(answer.questions_full);
4160
+ const changedSince = parseChangedSince(answer.changed_since);
4161
+ const ruled = parseRuled(answer.ruled);
4162
+ const ruledChanged = parseRuled(answer.ruled_changed);
3866
4163
  return {
3867
4164
  covered: new Map(items.flatMap((i) => i.covered_commit ? [[i.item, i.covered_commit]] : [])),
3868
4165
  // The dispatcher's list is the checklist: its first item list stands (its spec, section 9), so the brief and
@@ -3876,7 +4173,11 @@ async function coveredState(loaded, task) {
3876
4173
  } : {},
3877
4174
  ...answers ? { answers } : {},
3878
4175
  ...from.length ? { startFrom: from } : {},
3879
- ...siblings?.length ? { siblings } : {}
4176
+ ...siblings?.length ? { siblings } : {},
4177
+ ...questionsFull ? { questionsFull } : {},
4178
+ ...changedSince ? { changedSince } : {},
4179
+ ...ruled?.length ? { ruled } : {},
4180
+ ...ruledChanged?.length ? { ruledChanged } : {}
3880
4181
  };
3881
4182
  } catch (e) {
3882
4183
  return { unknown: e.message.split("\n")[0] };
@@ -4114,9 +4415,17 @@ program.command("cites").description("check that every reference is an ID or a p
4114
4415
  `);
4115
4416
  })
4116
4417
  );
4117
- program.command("questions").description("print the questions the dispatcher keeps: a task\u2019s, or without a task your own").argument("[task]", "the task, e.g. CHG-012/BE").option("--open", "only the ones still open").option("--about <id...>", "everyone\u2019s questions that name these IDs").option("--json", "print them as JSON").action(
4118
- run(async (id, opts) => {
4418
+ program.command("questions").description(
4419
+ "print the questions the dispatcher keeps: some by number, a task\u2019s, or without either your own"
4420
+ ).argument("[ref...]", "a task, e.g. CHG-012/BE, or questions by number, e.g. Q-12 Q-14").option("--open", "only the ones still open").option("--about <id...>", "everyone\u2019s questions that name these IDs").option("--json", "print them as JSON").action(
4421
+ run(async (refs, opts) => {
4422
+ const ids = refs.filter((r) => /^Q-\d+$/i.test(r)).map((r) => r.toUpperCase());
4423
+ const rest = refs.filter((r) => !/^Q-\d+$/i.test(r));
4424
+ if (rest.length > 1 || rest.length && ids.length)
4425
+ throw new Error("Name one task, or questions by number (Q-<n>), not both.");
4426
+ const id = rest[0];
4119
4427
  const questions = await listQuestions(sessionOf(loadConfig()), {
4428
+ ...ids.length ? { ids } : {},
4120
4429
  ...id ? { task: parseTask(id).id } : {},
4121
4430
  ...opts.about ? { about: opts.about } : {},
4122
4431
  ...opts.open ? { open: true } : {}