@alterset/alterspec-client 0.18.0 → 0.19.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
@@ -2,7 +2,7 @@
2
2
 
3
3
  // src/cli.ts
4
4
  import { Command } from "commander";
5
- import { join as join8 } from "path";
5
+ import { join as join9 } from "path";
6
6
 
7
7
  // src/config.ts
8
8
  import { execFileSync } from "child_process";
@@ -576,10 +576,10 @@ function parseDelta(json) {
576
576
  }
577
577
  }
578
578
  function exportChange(e) {
579
- const { before, after } = e.exported;
580
- if (before && after) return e.change;
581
- if (after) return "enters the export";
582
- if (before) return "leaves the export";
579
+ const { before: before2, after: after2 } = e.exported;
580
+ if (before2 && after2) return e.change;
581
+ if (after2) return "enters the export";
582
+ if (before2) return "leaves the export";
583
583
  return "not in the export";
584
584
  }
585
585
 
@@ -601,6 +601,8 @@ var shardDir = (path) => `${SHARDS_DIR}/${path.replace(/\.md$/, "")}`;
601
601
  var itemShardName = (key) => `${key.startsWith("term:") ? slug(key.slice(5)) : key}.md`;
602
602
  var itemShardPath = (path, key) => `${shardDir(path)}/${itemShardName(key)}`;
603
603
  var FRONT_MATTER_SHARD = "00-front-matter.yaml";
604
+ var INTRO_SHARD = "01-introduction.md";
605
+ var sectionShardName = (index, heading) => `${String(index + 2).padStart(2, "0")}-${slug(heading)}.md`;
604
606
  var isSectionShard = (name, heading) => new RegExp(`^\\d{2}-${slug(heading)}\\.md$`).test(name);
605
607
 
606
608
  // ../src/lib/frontmatter-split.ts
@@ -637,27 +639,27 @@ function objectParts(text, kind) {
637
639
  const yaml = /^```ya?ml\n([\s\S]*?)\n```[^\S\n]*$/m.exec(t);
638
640
  if (yaml) put("front-matter", FRONT_MATTER_PART, yaml[1]);
639
641
  const body = yaml ? t.slice(yaml.index + yaml[0].length) : t.replace(/^## [^\n]*\n?/, "");
640
- const { sections } = headed(body, "### ");
641
- if (sections.length) for (const s of sections) put("section", s.heading, s.text);
642
+ const { sections: sections2 } = headed(body, "### ");
643
+ if (sections2.length) for (const s of sections2) put("section", s.heading, s.text);
642
644
  else for (const b of bullets(body)) put("line", b.heading, b.text);
643
645
  return out;
644
646
  }
645
647
  function headed(text, marker) {
646
- const sections = [];
648
+ const sections2 = [];
647
649
  let intro = "";
648
650
  let fence2 = false;
649
651
  for (const l of text.split("\n")) {
650
652
  if (/^(?:```|~~~)/.test(l)) fence2 = !fence2;
651
653
  if (!fence2 && l.startsWith(marker) && /\S/.test(l.slice(marker.length))) {
652
- sections.push({ heading: l.slice(marker.length).trim(), text: "" });
654
+ sections2.push({ heading: l.slice(marker.length).trim(), text: "" });
653
655
  continue;
654
656
  }
655
- if (sections.length) sections[sections.length - 1].text += `${l}
657
+ if (sections2.length) sections2[sections2.length - 1].text += `${l}
656
658
  `;
657
659
  else intro += `${l}
658
660
  `;
659
661
  }
660
- return { intro, sections };
662
+ return { intro, sections: sections2 };
661
663
  }
662
664
  var BULLET = /^(?:[-*+]|\d+[.)])\s+(.*)$/;
663
665
  function bullets(text) {
@@ -919,6 +921,212 @@ function criterionParts(chunk) {
919
921
  };
920
922
  }
921
923
 
924
+ // ../src/lib/sections-split.ts
925
+ function sections(body) {
926
+ const lines = body.split("\n");
927
+ const out = [];
928
+ let inFence = false;
929
+ lines.forEach((l, i) => {
930
+ if (l.startsWith("```")) inFence = !inFence;
931
+ if (!inFence && /^## \S/.test(l)) out.push({ heading: l.slice(3).trim(), line: i + 1, text: "" });
932
+ else if (out.length) out[out.length - 1].text += l + "\n";
933
+ });
934
+ return out;
935
+ }
936
+
937
+ // ../src/export/cut.ts
938
+ function cutDocument(content) {
939
+ const out = [];
940
+ const { raw, body } = splitFrontMatter(content);
941
+ if (raw !== void 0 && raw.trim())
942
+ out.push({ name: FRONT_MATTER_SHARD, kind: "front-matter", text: `${raw.trimEnd()}
943
+ ` });
944
+ const parts = sections(body);
945
+ const lines = body.split("\n");
946
+ const intro = lines.slice(0, parts.length ? parts[0].line - 1 : lines.length).join("\n").trim();
947
+ if (intro) out.push({ name: INTRO_SHARD, kind: "introduction", text: `${intro}
948
+ ` });
949
+ parts.forEach((s, i) => {
950
+ const text = s.text.trim();
951
+ out.push({
952
+ name: sectionShardName(i, s.heading),
953
+ kind: "section",
954
+ heading: s.heading,
955
+ text: `## ${s.heading}
956
+ ${text ? `
957
+ ${text}
958
+ ` : ""}`
959
+ });
960
+ });
961
+ return out;
962
+ }
963
+
964
+ // src/pin.ts
965
+ var memos = /* @__PURE__ */ new WeakMap();
966
+ var memoOf = (x) => {
967
+ let m = memos.get(x);
968
+ if (!m) memos.set(x, m = { ancestors: /* @__PURE__ */ new Map(), entries: /* @__PURE__ */ new Map(), history: /* @__PURE__ */ new Map() });
969
+ return m;
970
+ };
971
+ function ancestors(x, change) {
972
+ const memo = memoOf(x).ancestors;
973
+ const known = memo.get(change);
974
+ if (known) return known;
975
+ const out = /* @__PURE__ */ new Set();
976
+ memo.set(change, out);
977
+ for (const d of x.work.changes.find((c) => c.id === change)?.depends_on ?? []) {
978
+ out.add(d);
979
+ for (const a of ancestors(x, d)) out.add(a);
980
+ }
981
+ return out;
982
+ }
983
+ function entriesOf(x, change) {
984
+ const memo = memoOf(x).entries;
985
+ let entries = memo.get(change);
986
+ if (!entries) memo.set(change, entries = new Map(x.delta(change)?.objects.map((e) => [e.key, e])));
987
+ return entries;
988
+ }
989
+ function history(x, key) {
990
+ const memo = memoOf(x).history;
991
+ const known = memo.get(key);
992
+ if (known) return known;
993
+ const order = x.work.changes.map((c) => c.id);
994
+ const touched = x.sources.get(key)?.changed_by ?? order;
995
+ const rest = order.filter((c) => touched.includes(c)).flatMap((change) => {
996
+ const entry = entriesOf(x, change).get(key);
997
+ return entry ? [{ change, entry }] : [];
998
+ });
999
+ const out = [];
1000
+ while (rest.length) {
1001
+ const last = out[out.length - 1]?.entry.fingerprint.after;
1002
+ const follows = last === void 0 ? -1 : rest.findIndex((e) => e.entry.fingerprint.before === last);
1003
+ const head = rest.findIndex(
1004
+ (e) => e.entry.fingerprint.before === void 0 || !rest.some((o) => o !== e && o.entry.fingerprint.after === e.entry.fingerprint.before)
1005
+ );
1006
+ out.push(...rest.splice(follows >= 0 ? follows : Math.max(head, 0), 1));
1007
+ }
1008
+ memo.set(key, out);
1009
+ return out;
1010
+ }
1011
+ var after = (e) => e.exported.after ? e.after : void 0;
1012
+ var before = (e) => e.exported.before ? e.before : void 0;
1013
+ function seen(x, change, key) {
1014
+ const touched = x.sources.get(key)?.changed_by;
1015
+ if (touched) {
1016
+ const built = ancestors(x, change);
1017
+ if (touched.every((c) => c === change || built.has(c))) return { later: [] };
1018
+ }
1019
+ const h = history(x, key);
1020
+ if (!h.length) return { later: [] };
1021
+ let at = h.findIndex((e) => e.change === change);
1022
+ if (at < 0) {
1023
+ const built = ancestors(x, change);
1024
+ const day2 = (id) => x.work.changes.find((c) => c.id === id)?.signed_off;
1025
+ const mine = day2(change);
1026
+ h.forEach((e, i) => {
1027
+ const theirs = day2(e.change);
1028
+ if (built.has(e.change)) at = i;
1029
+ else if (mine && theirs && theirs < mine && !ancestors(x, e.change).has(change)) at = i;
1030
+ });
1031
+ }
1032
+ const later = h.slice(at + 1);
1033
+ if (!later.length) return { later };
1034
+ const text = at >= 0 ? after(h[at].entry) : before(h[0].entry);
1035
+ if (text !== void 0) return { text, later };
1036
+ const held = at >= 0 ? h[at].entry.exported.after : h[0].entry.exported.before;
1037
+ if (held) return { later };
1038
+ const entered = later.findIndex((l) => l.entry.exported.after);
1039
+ return { later: later.slice(Math.max(entered, 0)), absent: true };
1040
+ }
1041
+ function pinnedReader(x, change) {
1042
+ const byFile = /* @__PURE__ */ new Map();
1043
+ for (const s of x.sources.values()) byFile.set(s.file, [...byFile.get(s.file) ?? [], s.id]);
1044
+ const isItem = (file, id) => x.has(itemShardPath(file, id));
1045
+ const keys = /* @__PURE__ */ new Map();
1046
+ const keyOf2 = (path) => {
1047
+ if (keys.has(path)) return keys.get(path);
1048
+ let key;
1049
+ if (path.startsWith(`${SHARDS_DIR}/`)) {
1050
+ const inner = path.slice(SHARDS_DIR.length + 1);
1051
+ const folder = `${inner}.md`;
1052
+ const parent = `${inner.replace(/\/[^/]+$/, "")}.md`;
1053
+ key = byFile.get(folder)?.find((id) => !isItem(folder, id)) ?? byFile.get(parent)?.find((id) => itemShardPath(parent, id) === path) ?? byFile.get(parent)?.find((id) => !isItem(parent, id));
1054
+ } else {
1055
+ key = byFile.get(path)?.find((id) => !isItem(path, id));
1056
+ }
1057
+ keys.set(path, key);
1058
+ return key;
1059
+ };
1060
+ const seenOf = /* @__PURE__ */ new Map();
1061
+ const see = (key) => {
1062
+ let s = seenOf.get(key);
1063
+ if (!s) seenOf.set(key, s = seen(x, change, key));
1064
+ return s;
1065
+ };
1066
+ const files = /* @__PURE__ */ new Map();
1067
+ const none = /* @__PURE__ */ new Map();
1068
+ const pinnedFiles = (key) => {
1069
+ const known = files.get(key);
1070
+ if (known) return known;
1071
+ const s = see(key);
1072
+ const file = x.fileOf(key);
1073
+ let out = none;
1074
+ if (s.text !== void 0 && file) {
1075
+ out = /* @__PURE__ */ new Map();
1076
+ if (isItem(file, key)) out.set(itemShardPath(file, key), `${s.text.trim()}
1077
+ `);
1078
+ else {
1079
+ out.set(file, s.text);
1080
+ if (file.endsWith(".md"))
1081
+ for (const part of cutDocument(s.text)) out.set(`${shardDir(file)}/${part.name}`, part.text);
1082
+ }
1083
+ }
1084
+ files.set(key, out);
1085
+ return out;
1086
+ };
1087
+ const view = (path) => {
1088
+ const key = keyOf2(path);
1089
+ if (!key) return void 0;
1090
+ const pinned = pinnedFiles(key);
1091
+ if (!pinned.size) return void 0;
1092
+ return pinned.get(path) ?? null;
1093
+ };
1094
+ const shards = (file) => {
1095
+ const key = keyOf2(file);
1096
+ const pinned = key ? pinnedFiles(key) : none;
1097
+ return pinned.size ? [...pinned.keys()].filter((p) => p.startsWith(`${shardDir(file)}/`)).sort() : x.shards(file);
1098
+ };
1099
+ return {
1100
+ ...x,
1101
+ current: x,
1102
+ seen: see,
1103
+ keyOf: keyOf2,
1104
+ pinnedFiles,
1105
+ isPinned(path) {
1106
+ const key = keyOf2(path);
1107
+ return !!key && pinnedFiles(key).size > 0;
1108
+ },
1109
+ read(path) {
1110
+ const v = view(path);
1111
+ return v === void 0 ? x.read(path) : v ?? void 0;
1112
+ },
1113
+ has(path) {
1114
+ const v = view(path);
1115
+ return v === void 0 ? x.has(path) : v !== null;
1116
+ },
1117
+ shards,
1118
+ sectionShard(file, heading) {
1119
+ const prefix = `${shardDir(file)}/`;
1120
+ return shards(file).find((p) => isSectionShard(p.slice(prefix.length), heading));
1121
+ },
1122
+ itemShard(file, key) {
1123
+ const path = itemShardPath(file, key);
1124
+ const v = view(path);
1125
+ return (v === void 0 ? x.has(path) : v !== null) ? path : void 0;
1126
+ }
1127
+ };
1128
+ }
1129
+
922
1130
  // src/questions.ts
923
1131
  import { z as z7 } from "zod";
924
1132
 
@@ -1134,8 +1342,8 @@ async function taskQuestions(session, task) {
1134
1342
  async function changeQuestions(session, tasks) {
1135
1343
  const lists = await Promise.all(tasks.map((t) => taskQuestions(session, t)));
1136
1344
  if (lists.some((l) => l === void 0)) return void 0;
1137
- const seen = /* @__PURE__ */ new Set();
1138
- return lists.flat().filter((q) => q && !seen.has(q.id) && seen.add(q.id));
1345
+ const seen2 = /* @__PURE__ */ new Set();
1346
+ return lists.flat().filter((q) => q && !seen2.has(q.id) && seen2.add(q.id));
1139
1347
  }
1140
1348
  var holding = (q) => q.answers.at(-1);
1141
1349
  var isCorrected = (q) => q.corrected ?? holding(q)?.verdict === "corrected";
@@ -1205,10 +1413,10 @@ function answersSection(answers) {
1205
1413
  // src/context.ts
1206
1414
  var ContextError = class extends Error {
1207
1415
  };
1208
- function startFrom(track, after) {
1209
- if (!Array.isArray(after)) return [];
1416
+ function startFrom(track, after2) {
1417
+ if (!Array.isArray(after2)) return [];
1210
1418
  const out = [];
1211
- for (const a of after) {
1419
+ for (const a of after2) {
1212
1420
  if (typeof a?.id !== "string" || typeof a.branch !== "string" || !a.branch) continue;
1213
1421
  if (a.id.split("/")[1] !== track) continue;
1214
1422
  out.push({ id: a.id, branch: a.branch, ...typeof a.commit === "string" ? { commit: a.commit } : {} });
@@ -1219,7 +1427,7 @@ var shardText = (x, path) => path ? x.read(path)?.replace(/^<!-- source: [^\n]*-
1219
1427
  var sectionText = (x, path) => shardText(x, path)?.replace(/^## [^\n]*\n*/, "");
1220
1428
  var screenOf = (key) => /^UX-(SCR-[A-Z]{2,6}-\d{2})-[A-Z]{2,5}$/.exec(key)?.[1] ?? /^file:experience\/[a-z]{2,5}\/mockups\/(SCR-[A-Z]{2,6}-\d{2})\.html$/.exec(key)?.[1] ?? (/^SCR-[A-Z]{2,6}-\d{2}$/.test(key) ? key : void 0);
1221
1429
  var forDiff = (key, text) => key.startsWith("file:") ? 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, "");
1222
- function withSections(diff, before, after) {
1430
+ function withSections(diff, before2, after2) {
1223
1431
  const where = (text, line) => {
1224
1432
  const lines2 = text.split("\n");
1225
1433
  if (lines2[0] === "---") {
@@ -1241,7 +1449,7 @@ function withSections(diff, before, after) {
1241
1449
  let k = i + 1;
1242
1450
  while (lines[k]?.startsWith(" ")) k++;
1243
1451
  const skipped = k - i - 1;
1244
- const name = lines[k]?.startsWith("+") ? where(after, Number(m[2]) + skipped) : where(before, Number(m[1]) + skipped);
1452
+ const name = lines[k]?.startsWith("+") ? where(after2, Number(m[2]) + skipped) : where(before2, Number(m[1]) + skipped);
1245
1453
  return name ? `${header} ${name}` : header;
1246
1454
  }).join("\n");
1247
1455
  }
@@ -1251,21 +1459,33 @@ var firstAddedLine = (a, b) => diffLines(a, b).filter((l) => l.op === "+").map(
1251
1459
  ).find((t) => t && !/^(---|```)/.test(t) && !BOOKKEEPING.test(t));
1252
1460
  var clipped = (line) => line && line.length > 200 ? `${line.slice(0, 199)}\u2026` : line;
1253
1461
  function firstAdded(key, entry) {
1254
- const before = forDiff(key, entry.before);
1255
- const after = forDiff(key, entry.after);
1462
+ const before2 = forDiff(key, entry.before);
1463
+ const after2 = forDiff(key, entry.after);
1256
1464
  return clipped(
1257
- firstAddedLine(splitFrontMatter(before).body, splitFrontMatter(after).body) ?? firstAddedLine(splitFrontMatter(before).raw ?? "", splitFrontMatter(after).raw ?? "")
1465
+ firstAddedLine(splitFrontMatter(before2).body, splitFrontMatter(after2).body) ?? firstAddedLine(splitFrontMatter(before2).raw ?? "", splitFrontMatter(after2).raw ?? "")
1258
1466
  );
1259
1467
  }
1260
- function objectBrief(x, key, entry, why, later = []) {
1468
+ function currentText(x, key) {
1261
1469
  const file = x.fileOf(key);
1262
- const held = file !== void 0 && x.has(file);
1470
+ if (!file || !x.has(file)) return void 0;
1471
+ const shard = x.itemShard(file, key);
1472
+ return shard ? shardText(x, shard) : x.read(file);
1473
+ }
1474
+ var pinnedPath = (x, key) => x.pinnedFiles(key).keys().next().value;
1475
+ function objectBrief(x, key, entry, why, at) {
1476
+ const now = x.current;
1477
+ const file = now.fileOf(key);
1478
+ const held = file !== void 0 && now.has(file);
1263
1479
  const brief = { key, ...held ? { file } : {} };
1264
- if (held && x.shards(file).length) brief.shards = x.shards(file)[0].replace(/\/[^/]+$/, "");
1480
+ if (held && now.shards(file).length) brief.shards = now.shards(file)[0].replace(/\/[^/]+$/, "");
1265
1481
  if (why) brief.unrecoverable = why;
1266
1482
  if (!entry) return brief;
1267
- const differs = held && entry.exported.after && entry.after !== void 0 && !entry.binary && forDiff(key, entry.after).trim() !== forDiff(key, x.read(file)).trim();
1483
+ const later = x.seen(key).later.map((l) => l.change);
1484
+ const text = currentText(now, key);
1485
+ const differs = held && entry.exported.after && entry.after !== void 0 && !entry.binary && text !== void 0 && forDiff(key, entry.after).trim() !== forDiff(key, text).trim();
1268
1486
  if (later.length || differs) brief.since = { changes: later, differs: !!differs };
1487
+ const own = later.length ? pinnedPath(x, key) : void 0;
1488
+ if (own) brief.pinned = at(own);
1269
1489
  brief.change = exportChange(entry);
1270
1490
  if (entry.status) brief.status = entry.status;
1271
1491
  if (entry.before !== void 0 || entry.after !== void 0) {
@@ -1360,10 +1580,10 @@ function itemWhat(x, item, entry, track) {
1360
1580
  const k = idKind(key);
1361
1581
  const owner = `${k && KIND_WORDS[k] ? `${KIND_WORDS[k]} ` : ""}${named(x, key)}`;
1362
1582
  const kind2 = entry?.kind === "item" ? "item" : "doc";
1363
- const after = entry?.after !== void 0 ? objectParts(entry.after, kind2).get(slug2) : void 0;
1364
- const before = entry?.before !== void 0 ? objectParts(entry.before, kind2).get(slug2) : void 0;
1365
- const label = !after ? `the part "${slug2}"` : after.label === "front-matter" ? "the front-matter" : after.label === "section" ? `the section "${after.heading}"` : `the line "${after.heading}"`;
1366
- const line2 = after ? clipped(firstAddedLine(before?.text ?? "", after.text)) : void 0;
1583
+ const after2 = entry?.after !== void 0 ? objectParts(entry.after, kind2).get(slug2) : void 0;
1584
+ const before2 = entry?.before !== void 0 ? objectParts(entry.before, kind2).get(slug2) : void 0;
1585
+ const label = !after2 ? `the part "${slug2}"` : after2.label === "front-matter" ? "the front-matter" : after2.label === "section" ? `the section "${after2.heading}"` : `the line "${after2.heading}"`;
1586
+ const line2 = after2 ? clipped(firstAddedLine(before2?.text ?? "", after2.text)) : void 0;
1367
1587
  return `${label} of ${owner}${line2 ? `: "${line2}"` : ""}`;
1368
1588
  }
1369
1589
  const kind = idKind(item);
@@ -1382,16 +1602,16 @@ function changedAttributes(entry) {
1382
1602
  if (!entry || !entry.exported.before || !entry.exported.after) return void 0;
1383
1603
  if (entry.before === void 0 || entry.after === void 0) return void 0;
1384
1604
  const names = (raw) => new Map([...raw.matchAll(/^ {2}- name: (.+?)\s*$/gm)].map((m) => [m[1], m.index]));
1385
- const before = splitFrontMatter(entry.before).raw ?? "";
1386
- const after = splitFrontMatter(entry.after).raw ?? "";
1605
+ const before2 = splitFrontMatter(entry.before).raw ?? "";
1606
+ const after2 = splitFrontMatter(entry.after).raw ?? "";
1387
1607
  const attr = (raw, from) => {
1388
1608
  const chunk = raw.slice(from).split(/\n(?! {4})/)[0] ?? "";
1389
1609
  return chunk.replace(/^\s*- name: .*\n?/, "");
1390
1610
  };
1391
- const b = names(before);
1392
- const a = names(after);
1611
+ const b = names(before2);
1612
+ const a = names(after2);
1393
1613
  const out = /* @__PURE__ */ new Set();
1394
- for (const [n, i] of a) if (!b.has(n) || attr(before, b.get(n)) !== attr(after, i)) out.add(n);
1614
+ for (const [n, i] of a) if (!b.has(n) || attr(before2, b.get(n)) !== attr(after2, i)) out.add(n);
1395
1615
  for (const n of b.keys()) if (!a.has(n)) out.add(n);
1396
1616
  return [...out];
1397
1617
  }
@@ -1428,12 +1648,6 @@ function whereUsed(x, objects, entries, changed) {
1428
1648
  }
1429
1649
  return out;
1430
1650
  }
1431
- function laterChanges(x, change, key) {
1432
- const order = x.work.changes.map((c) => c.id);
1433
- const at = order.indexOf(change);
1434
- const touched = x.sources.get(key)?.changed_by ?? [];
1435
- return touched.filter((c) => order.indexOf(c) > at).sort((a, b) => order.indexOf(a) - order.indexOf(b));
1436
- }
1437
1651
  function lifecycleOf(x, id) {
1438
1652
  const e = x.index()?.entities.find((e2) => e2.id === id);
1439
1653
  if (!e?.states?.length) return void 0;
@@ -1482,7 +1696,15 @@ function reachOf(x, id, kind, changed) {
1482
1696
  screens: screens.map((s) => piece(s.id, s.title))
1483
1697
  };
1484
1698
  }
1485
- function taskContext(x, task, exportDir2, state = {}, questions) {
1699
+ function taskContext(current, task, exportDir2, state = {}, questions, opts = {}) {
1700
+ const x = pinnedReader(current, task.change);
1701
+ const at = (path) => opts.pins && x.isPinned(path) ? `${opts.pins}/${path}` : path;
1702
+ const names = /* @__PURE__ */ new Set();
1703
+ const since = (key) => {
1704
+ names.add(key);
1705
+ const s = x.seen(key);
1706
+ return s.later.length ? { since: s.later.map((l) => l.change), ...s.absent ? { entered: true } : {} } : {};
1707
+ };
1486
1708
  const change = x.work.changes.find((c) => c.id === task.change);
1487
1709
  if (!change) throw new ContextError(`${task.change} is not in this export's work.json: pull the export.`);
1488
1710
  const work = change.tasks.find((t) => t.track === task.track);
@@ -1536,10 +1758,10 @@ function taskContext(x, task, exportDir2, state = {}, questions) {
1536
1758
  ...dataChangeOf(sectionText(x, x.sectionShard(proposal, DATA_CHANGE_SECTION)))
1537
1759
  },
1538
1760
  ...delta ? { delta: proposal.replace(/proposal\.md$/, "delta.md") } : {},
1539
- objects: work.objects.map(
1540
- (key) => objectBrief(x, key, entries.get(key), lost.get(key), laterChanges(x, change.id, key))
1541
- )
1761
+ objects: work.objects.map((key) => objectBrief(x, key, entries.get(key), lost.get(key), at)),
1762
+ ...opts.pins ? { pins: opts.pins } : {}
1542
1763
  };
1764
+ for (const key of work.objects) names.add(key);
1543
1765
  const added = work.objects.flatMap((key) => {
1544
1766
  const e = entries.get(key);
1545
1767
  return e ? diffLines(forDiff(key, e.before), forDiff(key, e.after)).filter((l) => l.op === "+") : [];
@@ -1556,14 +1778,15 @@ function taskContext(x, task, exportDir2, state = {}, questions) {
1556
1778
  return [
1557
1779
  {
1558
1780
  id,
1559
- path,
1781
+ path: at(path),
1560
1782
  ...title ? { title } : {},
1561
1783
  ...text ? { text } : {},
1562
- ...changed.has(id) ? { changed: true } : {}
1784
+ ...changed.has(id) ? { changed: true } : {},
1785
+ ...since(id)
1563
1786
  }
1564
1787
  ];
1565
1788
  };
1566
- ctx.whereUsed = whereUsed(x, work.objects, entries, changed);
1789
+ ctx.whereUsed = whereUsed(current, work.objects, entries, changed);
1567
1790
  const capabilities = work.objects.filter((k) => /^CAP-/.test(k) && x.fileOf(k) && x.has(x.fileOf(k)));
1568
1791
  const onList = items && new Set(items);
1569
1792
  ctx.acceptance = capabilities.flatMap((id) => {
@@ -1579,12 +1802,12 @@ function taskContext(x, task, exportDir2, state = {}, questions) {
1579
1802
  const title = titleOf(x, id);
1580
1803
  const rest = [
1581
1804
  added2 ? `${added2 === 1 ? "One new criterion is" : `${added2} new criteria are`} whole in its delta above.` : "",
1582
- chunks.length > listed.length ? `Its other criteria: \`${path}\`.` : ""
1805
+ chunks.length > listed.length ? `Its other criteria: \`${at(path)}\`.` : ""
1583
1806
  ].filter(Boolean).join(" ");
1584
1807
  return [
1585
1808
  {
1586
1809
  id,
1587
- path,
1810
+ path: at(path),
1588
1811
  ...title ? { title } : {},
1589
1812
  ...kept.length ? { text: kept.join("").trim() } : {},
1590
1813
  ...kept.length && rest ? { rest } : {}
@@ -1621,23 +1844,24 @@ function taskContext(x, task, exportDir2, state = {}, questions) {
1621
1844
  const file = x.fileOf(id);
1622
1845
  if (!file || !x.has(file)) return [];
1623
1846
  const title = titleOf(x, id);
1624
- const note = lifecycleOf(x, id);
1847
+ const note = lifecycleOf(current, id);
1625
1848
  return [
1626
1849
  {
1627
1850
  id,
1628
- path: file,
1851
+ path: at(file),
1629
1852
  ...title ? { title } : {},
1630
1853
  ...changed.has(id) ? { changed: true } : {},
1631
- ...note ? { note } : {}
1854
+ ...note ? { note } : {},
1855
+ ...since(id)
1632
1856
  }
1633
1857
  ];
1634
1858
  });
1635
- ctx.operations = x.has(OPERATIONS_FILE) ? capabilities.flatMap((id) => {
1636
- const path = x.shards(OPERATIONS_FILE).find((p) => new RegExp(`/\\d{2}-${slug(id)}(-|\\.md$)`).test(p));
1637
- return path ? [{ id, path, text: shardText(x, path) }] : [];
1859
+ ctx.operations = current.has(OPERATIONS_FILE) ? capabilities.flatMap((id) => {
1860
+ const path = current.shards(OPERATIONS_FILE).find((p) => new RegExp(`/\\d{2}-${slug(id)}(-|\\.md$)`).test(p));
1861
+ return path ? [{ id, path, text: shardText(current, path) }] : [];
1638
1862
  }) : [];
1639
1863
  } else {
1640
- const existing = (p) => x.has(p) ? p : void 0;
1864
+ const existing = (p) => x.has(p) ? at(p) : void 0;
1641
1865
  const performing = [...x.sources.keys()].filter(
1642
1866
  (id) => /^SCR-/.test(id) && x.has(contractPath(id, track.code)) && idsIn(frontMatterOf(x.read(x.fileOf(id)) ?? ""), ["capability"]).some(
1643
1867
  (c) => capabilities.includes(c)
@@ -1646,12 +1870,17 @@ function taskContext(x, task, exportDir2, state = {}, questions) {
1646
1870
  const screens = [
1647
1871
  .../* @__PURE__ */ new Set([...work.objects.map(screenOf).filter((s) => !!s), ...performing])
1648
1872
  ];
1649
- ctx.screens = screens.map((id) => ({
1650
- id,
1651
- file: x.fileOf(id),
1652
- contract: existing(contractPath(id, track.code)),
1653
- page: existing(mockupPath(track.code, id))
1654
- }));
1873
+ ctx.screens = screens.map((id) => {
1874
+ for (const key of [id, `UX-${id}-${track.code}`, `file:${mockupPath(track.code, id)}`]) names.add(key);
1875
+ const file = x.fileOf(id);
1876
+ return {
1877
+ id,
1878
+ file: file && at(file),
1879
+ contract: existing(contractPath(id, track.code)),
1880
+ page: existing(mockupPath(track.code, id))
1881
+ };
1882
+ });
1883
+ for (const path of [designSystemPath(track.code), patternsPath(track.code)]) names.add(`file:${path}`);
1655
1884
  ctx.design = {
1656
1885
  designSystem: existing(designSystemPath(track.code)),
1657
1886
  patterns: existing(patternsPath(track.code))
@@ -1668,8 +1897,8 @@ function taskContext(x, task, exportDir2, state = {}, questions) {
1668
1897
  ];
1669
1898
  const roles = work.objects.filter((k) => idKind(k) === "role");
1670
1899
  ctx.reach = [
1671
- ...rules.map((id) => reachOf(x, id, "rule", changed)),
1672
- ...roles.map((id) => reachOf(x, id, "role", changed))
1900
+ ...rules.map((id) => reachOf(current, id, "rule", changed)),
1901
+ ...roles.map((id) => reachOf(current, id, "role", changed))
1673
1902
  ].filter((r) => !!r);
1674
1903
  if (!ctx.reach.length) delete ctx.reach;
1675
1904
  const glossary = x.fileOf("term:");
@@ -1680,10 +1909,72 @@ function taskContext(x, task, exportDir2, state = {}, questions) {
1680
1909
  const term = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1681
1910
  if (!new RegExp(`(?<![\\w-])${term}(?:s|es)?(?![\\w-])`, "i").test(writtenText)) return [];
1682
1911
  const text = sectionText(x, path);
1683
- return [{ id: name, path, ...text ? { text } : {} }];
1912
+ return [{ id: name, path: at(path), ...text ? { text } : {}, ...since(`term:${name}`) }];
1684
1913
  });
1914
+ const moved = [...names].flatMap((key) => {
1915
+ const s = x.seen(key);
1916
+ if (!s.later.length) return [];
1917
+ const now = currentText(current, key);
1918
+ const changes = s.later.map((l) => ({
1919
+ id: l.change,
1920
+ ...opts.shown && !opts.shown.has(shownKey(key, l.change)) ? { fresh: true } : {}
1921
+ }));
1922
+ const first = changes.findIndex((ch) => ch.fresh);
1923
+ const from = first < 0 || s.absent ? void 0 : first === 0 ? s.text : textAfter(s.later[first - 1].entry);
1924
+ let diff;
1925
+ if (from !== void 0 && now !== void 0) {
1926
+ const [a, b] = [forDiff(key, from), forDiff(key, now)];
1927
+ const d = unifiedDiff(a, b);
1928
+ if (d) diff = clippedDiff(key.startsWith("file:") ? d : withSections(d, a, b));
1929
+ }
1930
+ const title = key.includes(":") ? void 0 : titleOf(current, key);
1931
+ const pinned = pinnedPath(x, key);
1932
+ return [
1933
+ {
1934
+ key,
1935
+ ...title ? { title } : {},
1936
+ ...changed.has(key) ? { own: true } : {},
1937
+ changes,
1938
+ ...pinned ? { pinned: at(pinned) } : {},
1939
+ ...diff ? { diff } : {},
1940
+ ...now === void 0 ? { gone: true } : {},
1941
+ ...s.absent ? { entered: true } : {}
1942
+ }
1943
+ ];
1944
+ });
1945
+ if (moved.length) {
1946
+ ctx.changedSince = moved.sort(
1947
+ (a, b) => Number(!!b.own) - Number(!!a.own) || (a.key < b.key ? -1 : a.key > b.key ? 1 : 0)
1948
+ );
1949
+ const touched = new Set(moved.flatMap((e) => e.changes.map((ch) => ch.id)));
1950
+ ctx.later = x.work.changes.filter((c) => touched.has(c.id)).map((c) => {
1951
+ const delta2 = x.proposalPath(c.id)?.replace(/proposal\.md$/, "delta.md");
1952
+ return {
1953
+ id: c.id,
1954
+ title: c.title,
1955
+ ...c.tasks.some((t) => t.track === task.track) ? { task: `${c.id}/${task.track}` } : {},
1956
+ ...delta2 ? { delta: delta2 } : {}
1957
+ };
1958
+ });
1959
+ }
1685
1960
  return ctx;
1686
1961
  }
1962
+ var shownKey = (key, change) => `${key}<${change}`;
1963
+ var shownOf = (c) => (c.changedSince ?? []).flatMap((e) => e.changes.map((ch) => shownKey(e.key, ch.id)));
1964
+ function pinFiles(current, c) {
1965
+ const x = pinnedReader(current, c.change.id);
1966
+ const out = /* @__PURE__ */ new Map();
1967
+ for (const e of c.changedSince ?? []) for (const [path, text] of x.pinnedFiles(e.key)) out.set(path, text);
1968
+ return out;
1969
+ }
1970
+ var textAfter = (e) => e.exported.after ? e.after : void 0;
1971
+ var DIFF_LINES = 40;
1972
+ var NEW_DIFFS = 12;
1973
+ function clippedDiff(diff) {
1974
+ const lines = diff.split("\n");
1975
+ return lines.length <= DIFF_LINES ? diff : `${lines.slice(0, DIFF_LINES).join("\n")}
1976
+ \u2026 ${lines.length - DIFF_LINES} more lines: see the changes\u2019 deltas.`;
1977
+ }
1687
1978
  var fence = (text, lang = "") => {
1688
1979
  const ticks = "`".repeat(Math.max(3, ...[...text.matchAll(/`+/g)].map((m) => m[0].length + 1)));
1689
1980
  return `${ticks}${lang}
@@ -1696,6 +1987,15 @@ function renderContext(c) {
1696
1987
  "",
1697
1988
  `Track ${c.track.code} (${c.track.kind}${c.track.channels.length ? `: ${c.track.channels.join(", ")}` : ""}). Change ${c.change.id}, signed off ${c.change.signed_off}, level ${c.change.level}. Paths are relative to the export, ${c.export}.`
1698
1989
  ];
1990
+ const movedSince = (c.changedSince ?? []).filter((e) => !e.entered);
1991
+ if (movedSince.length) {
1992
+ const n = movedSince.length;
1993
+ const fresh = movedSince.filter((e) => e.changes.some((ch) => ch.fresh)).length;
1994
+ out.push(
1995
+ "",
1996
+ `This brief is the spec as ${c.change.id} saw it at its sign-off. ${n === 1 ? "One object it names was" : `${n} objects it names were`} changed since by later changes${fresh ? ` (${fresh} new since you last read this brief)` : ""}: those are the later changes\u2019 tasks, listed under "Changed since" at the end, never this task\u2019s work.` + (c.pins ? ` An absolute path under ${c.pins} is such an object as ${c.change.id} saw it.` : "")
1997
+ );
1998
+ }
1699
1999
  if (c.after.length) out.push("", `Waits for: ${c.after.map((a) => `${a.change}/${a.track}`).join(", ")}.`);
1700
2000
  if (c.startFrom?.length)
1701
2001
  out.push(
@@ -1746,13 +2046,16 @@ function renderContext(c) {
1746
2046
  const status = o.status && o.status.before !== o.status.after ? `, ${o.status.before ?? "\u2014"} \u2192 ${o.status.after ?? "\u2014"}` : "";
1747
2047
  out.push(`### ${o.key}`, "", `${o.change ?? "no delta entry"}${status}; ${where}.`);
1748
2048
  if (o.unrecoverable) out.push("", `The delta could not recover it: ${o.unrecoverable}.`);
1749
- if (o.since) {
1750
- 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). ` : "";
2049
+ if (o.since?.changes.length)
1751
2050
  out.push(
1752
2051
  "",
1753
- 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.`
2052
+ `Changed since by ${o.since.changes.join(", ")}: their tasks\u2019 work (see "Changed since"). Build it as ${c.change.id} left it${o.pinned ? `: \`${o.pinned}\`` : ""}${o.since.differs ? "" : "; the export\u2019s text equals that again"}.`
2053
+ );
2054
+ else if (o.since)
2055
+ out.push(
2056
+ "",
2057
+ "The export\u2019s text differs from this delta\u2019s after though no later change touched it: build to the export\u2019s file."
1754
2058
  );
1755
- }
1756
2059
  if (o.diff) out.push("", o.diff.startsWith("@@") ? fence(o.diff, "diff") : o.diff);
1757
2060
  out.push("");
1758
2061
  }
@@ -1813,17 +2116,19 @@ function renderContext(c) {
1813
2116
  if (!list2?.length) return;
1814
2117
  out.push(`## ${title}`, "");
1815
2118
  if (intro) out.push(intro, "");
2119
+ const moved = (p) => !p.since?.length ? "" : p.entered ? `signed off since, by ${p.since.join(", ")}; here as the export holds it now` : `changed since by ${p.since.join(", ")}; here as ${c.change.id} saw it`;
1816
2120
  for (const p of list2.filter((p2) => p2.text))
1817
2121
  out.push(
1818
2122
  `### ${p.id}${p.title ? ` ${p.title}` : ""} (\`${p.path}\`)`,
1819
2123
  "",
2124
+ ...moved(p) ? [`(${moved(p)})`, ""] : [],
1820
2125
  p.text,
1821
2126
  ...p.rest ? ["", p.rest] : [],
1822
2127
  ""
1823
2128
  );
1824
2129
  for (const p of list2.filter((p2) => !p2.text))
1825
2130
  out.push(
1826
- `- ${p.id}${p.title ? ` ${p.title}` : ""}: \`${p.path}\`${p.changed ? " (this task changes it: its delta is above)" : ""}${p.note ? `; ${p.note}` : ""}`
2131
+ `- ${p.id}${p.title ? ` ${p.title}` : ""}: \`${p.path}\`${p.changed ? " (this task changes it: its delta is above)" : ""}${p.note ? `; ${p.note}` : ""}${moved(p) ? ` (${moved(p)})` : ""}`
1827
2132
  );
1828
2133
  out.push("");
1829
2134
  };
@@ -1880,18 +2185,64 @@ function renderContext(c) {
1880
2185
  ""
1881
2186
  );
1882
2187
  }
2188
+ if (c.changedSince?.length) {
2189
+ out.push("## Changed since (other tasks\u2019 work)", "");
2190
+ const names = (e) => `${e.key}${e.title ? ` ${e.title}` : ""}${e.own ? " (this task changes it)" : ""}`;
2191
+ if (movedSince.length) {
2192
+ out.push(
2193
+ `Later changes touched what this brief names. Build this task to the text above: what a later change added is built in its own task. Before you build one of this task\u2019s objects listed here, compare the file the brief gives for it with the export\u2019s: a line a later change removed or reversed is not built twice (build that item as the later change says and say so in the commit).`,
2194
+ "",
2195
+ ...(c.later ?? []).map(
2196
+ (l) => `- ${l.id}${l.title ? ` "${l.title}"` : ""}: ${l.task ? `its task ${l.task}` : "no task on this track"}${l.delta ? `; \`${l.delta}\`` : ""}`
2197
+ ),
2198
+ "",
2199
+ "What each touched, in the order it did:",
2200
+ "",
2201
+ ...movedSince.map(
2202
+ (e) => `- ${names(e)}: ${e.changes.map((ch) => `${ch.fresh ? "**new** " : ""}${ch.id}`).join(", ")}${e.gone ? "; the export no longer holds it" : ""}`
2203
+ ),
2204
+ ""
2205
+ );
2206
+ const fresh = movedSince.filter((e) => e.diff);
2207
+ if (fresh.length) {
2208
+ out.push(
2209
+ "New since you last read this brief, from what it showed then to the export\u2019s text now:",
2210
+ ""
2211
+ );
2212
+ for (const e of fresh.slice(0, NEW_DIFFS))
2213
+ out.push(`### ${names(e)}`, "", fence(e.diff, "diff"), "");
2214
+ if (fresh.length > NEW_DIFFS)
2215
+ out.push(
2216
+ `And ${fresh.length - NEW_DIFFS} more: ${fresh.slice(NEW_DIFFS).map((e) => e.key).join(", ")} (see the changes\u2019 deltas).`,
2217
+ ""
2218
+ );
2219
+ }
2220
+ }
2221
+ const entered = c.changedSince.filter((e) => e.entered);
2222
+ if (entered.length)
2223
+ out.push(
2224
+ `Signed off after ${c.change.id}, so the export never held them as it saw them; the brief shows them as the export holds them now:`,
2225
+ "",
2226
+ ...entered.map((e) => {
2227
+ const [first, ...rest] = e.changes;
2228
+ const task = c.later?.find((l) => l.id === first.id)?.task;
2229
+ return `- ${names(e)}: in the export since ${first.id}${task ? ` (its task ${task})` : ""}${rest.length ? `, changed after by ${rest.map((ch) => ch.id).join(", ")}` : ""}`;
2230
+ }),
2231
+ ""
2232
+ );
2233
+ }
1883
2234
  return out.join("\n").replace(/\n{3,}/g, "\n\n").trimEnd() + "\n";
1884
2235
  }
1885
2236
  function contextStats(markdown) {
1886
- const sections = markdown.split(/^(?=## )/m).map((part, i) => ({
2237
+ const sections2 = markdown.split(/^(?=## )/m).map((part, i) => ({
1887
2238
  name: i === 0 ? "(heading)" : part.split("\n")[0].slice(3),
1888
2239
  chars: part.length
1889
2240
  }));
1890
- const width = Math.max(...sections.map((x) => x.name.length), "Total".length);
2241
+ const width = Math.max(...sections2.map((x) => x.name.length), "Total".length);
1891
2242
  const row = (name, chars) => `${name.padEnd(width)} ${String(Math.ceil(chars / 4)).padStart(7)} ${String(chars).padStart(8)}`;
1892
2243
  return [
1893
2244
  `${"Section".padEnd(width)} ${"~tokens".padStart(7)} ${"chars".padStart(8)}`,
1894
- ...sections.map((x) => row(x.name, x.chars)),
2245
+ ...sections2.map((x) => row(x.name, x.chars)),
1895
2246
  row("Total", markdown.length)
1896
2247
  ].join("\n") + "\n";
1897
2248
  }
@@ -2078,10 +2429,10 @@ function renderBugContext(c) {
2078
2429
  return out.join("\n");
2079
2430
  }
2080
2431
 
2081
- // src/git.ts
2432
+ // src/pinstore.ts
2082
2433
  import { execFileSync as execFileSync3 } from "child_process";
2083
- import { existsSync as existsSync4 } from "fs";
2084
- import { join as join4 } from "path";
2434
+ import { existsSync as existsSync4, mkdirSync, readFileSync as readFileSync4, rmSync as rmSync2, writeFileSync as writeFileSync3 } from "fs";
2435
+ import { dirname as dirname2, join as join4 } from "path";
2085
2436
 
2086
2437
  // src/task.ts
2087
2438
  var TRAILER = "Alterspec-Task";
@@ -2108,12 +2459,65 @@ function taskOfBranch(branch) {
2108
2459
  return m ? parseTask(`${m[1]}/${m[2]}`) : void 0;
2109
2460
  }
2110
2461
 
2462
+ // src/pinstore.ts
2463
+ var PINS_DIR = ".alterspec-client/pins";
2464
+ var pinsDir = (root, task) => join4(root, PINS_DIR, folderOf(task));
2465
+ function writePins(dir, files) {
2466
+ rmSync2(dir, { recursive: true, force: true });
2467
+ if (!files.size) return;
2468
+ const root = dirname2(dir);
2469
+ mkdirSync(root, { recursive: true });
2470
+ if (!existsSync4(join4(root, ".gitignore"))) writeFileSync3(join4(root, ".gitignore"), "*\n");
2471
+ for (const [path, text] of files) {
2472
+ const to = join4(dir, path);
2473
+ mkdirSync(dirname2(to), { recursive: true });
2474
+ writeFileSync3(to, text);
2475
+ }
2476
+ }
2477
+ function shownPath(repo, task) {
2478
+ try {
2479
+ const common = execFileSync3("git", ["rev-parse", "--path-format=absolute", "--git-common-dir"], {
2480
+ cwd: repo,
2481
+ encoding: "utf8",
2482
+ stdio: ["ignore", "pipe", "ignore"]
2483
+ }).trim();
2484
+ return common ? join4(common, "alterspec-client", `seen-${folderOf(task)}.json`) : void 0;
2485
+ } catch {
2486
+ return void 0;
2487
+ }
2488
+ }
2489
+ function readShown(repo, task) {
2490
+ const path = shownPath(repo, task);
2491
+ if (!path || !existsSync4(path)) return void 0;
2492
+ try {
2493
+ const data = JSON.parse(readFileSync4(path, "utf8"));
2494
+ return new Set(
2495
+ Array.isArray(data.shown) ? data.shown.filter((s) => typeof s === "string") : []
2496
+ );
2497
+ } catch {
2498
+ return void 0;
2499
+ }
2500
+ }
2501
+ function writeShown(repo, task, shown, now = /* @__PURE__ */ new Date()) {
2502
+ const path = shownPath(repo, task);
2503
+ if (!path) return;
2504
+ try {
2505
+ const all = [.../* @__PURE__ */ new Set([...readShown(repo, task) ?? [], ...shown])].sort();
2506
+ mkdirSync(dirname2(path), { recursive: true });
2507
+ writeFileSync3(path, JSON.stringify({ shown: all, at: now.toISOString() }) + "\n");
2508
+ } catch {
2509
+ }
2510
+ }
2511
+
2111
2512
  // src/git.ts
2513
+ import { execFileSync as execFileSync4 } from "child_process";
2514
+ import { existsSync as existsSync5 } from "fs";
2515
+ import { join as join5 } from "path";
2112
2516
  var GitError = class extends Error {
2113
2517
  };
2114
2518
  function git2(cwd, args) {
2115
2519
  try {
2116
- return execFileSync3("git", args, { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }).trim();
2520
+ return execFileSync4("git", args, { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }).trim();
2117
2521
  } catch (e) {
2118
2522
  const stderr = String(e.stderr ?? "").trim();
2119
2523
  throw new GitError(`git ${args.join(" ")} failed in ${cwd}${stderr ? `: ${stderr}` : ""}`);
@@ -2128,7 +2532,7 @@ var tryGit = (cwd, args) => {
2128
2532
  };
2129
2533
  var isAncestor = (cwd, a, b) => tryGit(cwd, ["merge-base", "--is-ancestor", a, b]) !== void 0;
2130
2534
  function exportHead(dir, latest) {
2131
- if (!existsSync4(join4(dir, ".git")) && tryGit(dir, ["rev-parse", "--git-dir"]) === void 0)
2535
+ if (!existsSync5(join5(dir, ".git")) && tryGit(dir, ["rev-parse", "--git-dir"]) === void 0)
2132
2536
  throw new GitError(`${dir} is not a clone of the export repository.`);
2133
2537
  const pulled = tryGit(dir, ["pull", "--ff-only", "--quiet"]) !== void 0;
2134
2538
  const head = git2(dir, ["rev-parse", "HEAD"]);
@@ -2196,21 +2600,21 @@ function mergedInto(repo, task, target) {
2196
2600
  // src/install.ts
2197
2601
  import { spawnSync } from "child_process";
2198
2602
  import {
2199
- existsSync as existsSync6,
2603
+ existsSync as existsSync7,
2200
2604
  lstatSync,
2201
- mkdirSync as mkdirSync2,
2202
- readFileSync as readFileSync5,
2605
+ mkdirSync as mkdirSync3,
2606
+ readFileSync as readFileSync6,
2203
2607
  readdirSync as readdirSync3,
2204
2608
  realpathSync,
2205
2609
  statSync,
2206
- writeFileSync as writeFileSync4
2610
+ writeFileSync as writeFileSync5
2207
2611
  } from "fs";
2208
- import { join as join6, relative } from "path";
2612
+ import { join as join7, relative } from "path";
2209
2613
  import { fileURLToPath } from "url";
2210
2614
 
2211
2615
  // ../src/install/installer.ts
2212
- import { existsSync as existsSync5, mkdirSync, readFileSync as readFileSync4, readdirSync as readdirSync2, rmSync as rmSync2, writeFileSync as writeFileSync3 } from "fs";
2213
- import { dirname as dirname2, join as join5 } from "path";
2616
+ import { existsSync as existsSync6, mkdirSync as mkdirSync2, readFileSync as readFileSync5, readdirSync as readdirSync2, rmSync as rmSync3, writeFileSync as writeFileSync4 } from "fs";
2617
+ import { dirname as dirname3, join as join6 } from "path";
2214
2618
 
2215
2619
  // ../src/install/hash.ts
2216
2620
  import { createHash as createHash2 } from "crypto";
@@ -2219,18 +2623,18 @@ var sha256 = (content) => createHash2("sha256").update(content).digest("hex");
2219
2623
  // ../src/install/installer.ts
2220
2624
  var MANIFEST_PATH = ".alterspec/manifest.json";
2221
2625
  function readManifest(root, path = MANIFEST_PATH) {
2222
- const p = join5(root, path);
2223
- if (!existsSync5(p)) return void 0;
2626
+ const p = join6(root, path);
2627
+ if (!existsSync6(p)) return void 0;
2224
2628
  try {
2225
- return JSON.parse(readFileSync4(p, "utf8"));
2629
+ return JSON.parse(readFileSync5(p, "utf8"));
2226
2630
  } catch {
2227
2631
  return void 0;
2228
2632
  }
2229
2633
  }
2230
2634
  function write(root, path, content) {
2231
- const full = join5(root, path);
2232
- mkdirSync(dirname2(full), { recursive: true });
2233
- writeFileSync3(full, content);
2635
+ const full = join6(root, path);
2636
+ mkdirSync2(dirname3(full), { recursive: true });
2637
+ writeFileSync4(full, content);
2234
2638
  }
2235
2639
  function install(root, plan, opts) {
2236
2640
  const result = {
@@ -2247,9 +2651,9 @@ function install(root, plan, opts) {
2247
2651
  const previous = readManifest(root, manifestPath);
2248
2652
  const next = { version: opts.version, files: {} };
2249
2653
  for (const file of plan) {
2250
- const full = join5(root, file.path);
2654
+ const full = join6(root, file.path);
2251
2655
  const newHash = sha256(file.content);
2252
- if (!existsSync5(full)) {
2656
+ if (!existsSync6(full)) {
2253
2657
  write(root, file.path, file.content);
2254
2658
  result.created.push(file.path);
2255
2659
  if (file.policy !== "user") next.files[file.path] = newHash;
@@ -2259,7 +2663,7 @@ function install(root, plan, opts) {
2259
2663
  result.kept.push(file.path);
2260
2664
  continue;
2261
2665
  }
2262
- const diskHash = sha256(readFileSync4(full, "utf8"));
2666
+ const diskHash = sha256(readFileSync5(full, "utf8"));
2263
2667
  if (diskHash === newHash) {
2264
2668
  result.unchanged.push(file.path);
2265
2669
  next.files[file.path] = newHash;
@@ -2284,14 +2688,14 @@ function install(root, plan, opts) {
2284
2688
  const planned = new Set(plan.map((f) => f.path));
2285
2689
  for (const [path, hash] of Object.entries(previous.files)) {
2286
2690
  if (planned.has(path)) continue;
2287
- const full = join5(root, path);
2288
- if (!existsSync5(full)) continue;
2289
- if (sha256(readFileSync4(full, "utf8")) === hash) {
2290
- rmSync2(full);
2691
+ const full = join6(root, path);
2692
+ if (!existsSync6(full)) continue;
2693
+ if (sha256(readFileSync5(full, "utf8")) === hash) {
2694
+ rmSync3(full);
2291
2695
  result.removed.push(path);
2292
- const folder = dirname2(full);
2696
+ const folder = dirname3(full);
2293
2697
  if (emptiedFolder.test(folder) && readdirSync2(folder).length === 0)
2294
- rmSync2(folder, { recursive: true });
2698
+ rmSync3(folder, { recursive: true });
2295
2699
  } else {
2296
2700
  result.conflicts.push(path);
2297
2701
  }
@@ -2310,11 +2714,11 @@ var MCP_JSON = ".mcp.json";
2310
2714
  var MCP_SERVER = "dispatcher";
2311
2715
  var MCP_ENTRY = { command: "npx", args: ["@alterset/alterspec-client", "mcp"] };
2312
2716
  function walk(dir) {
2313
- return readdirSync3(dir).sort().flatMap((n) => statSync(join6(dir, n)).isDirectory() ? walk(join6(dir, n)) : [join6(dir, n)]);
2717
+ return readdirSync3(dir).sort().flatMap((n) => statSync(join7(dir, n)).isDirectory() ? walk(join7(dir, n)) : [join7(dir, n)]);
2314
2718
  }
2315
- var assetFiles = (sub) => walk(join6(ASSETS_DIR, sub)).map((f) => ({
2316
- rel: relative(join6(ASSETS_DIR, sub), f).split("\\").join("/"),
2317
- content: readFileSync5(f, "utf8")
2719
+ var assetFiles = (sub) => walk(join7(ASSETS_DIR, sub)).map((f) => ({
2720
+ rel: relative(join7(ASSETS_DIR, sub), f).split("\\").join("/"),
2721
+ content: readFileSync6(f, "utf8")
2318
2722
  }));
2319
2723
  function buildClientPlan(version) {
2320
2724
  return [
@@ -2338,20 +2742,20 @@ function buildClientPlan(version) {
2338
2742
  ];
2339
2743
  }
2340
2744
  function writeMcpJson(root) {
2341
- const path = join6(root, MCP_JSON);
2745
+ const path = join7(root, MCP_JSON);
2342
2746
  let data = {};
2343
- const before = existsSync6(path) ? readFileSync5(path, "utf8") : void 0;
2344
- if (before !== void 0)
2747
+ const before2 = existsSync7(path) ? readFileSync6(path, "utf8") : void 0;
2748
+ if (before2 !== void 0)
2345
2749
  try {
2346
- data = JSON.parse(before);
2750
+ data = JSON.parse(before2);
2347
2751
  } catch {
2348
2752
  throw new ConfigError(`${path} is not valid JSON: fix it, then run init again.`);
2349
2753
  }
2350
2754
  data.mcpServers = { ...data.mcpServers ?? {}, [MCP_SERVER]: MCP_ENTRY };
2351
- const after = JSON.stringify(data, null, 2) + "\n";
2352
- if (after === before) return "unchanged";
2353
- writeFileSync4(path, after);
2354
- return before === void 0 ? "created" : "updated";
2755
+ const after2 = JSON.stringify(data, null, 2) + "\n";
2756
+ if (after2 === before2) return "unchanged";
2757
+ writeFileSync5(path, after2);
2758
+ return before2 === void 0 ? "created" : "updated";
2355
2759
  }
2356
2760
  var CLAUDE_SETTINGS = ".claude/settings.json";
2357
2761
  var HOOK_COMMAND = "npx @alterset/alterspec-client progress --hook";
@@ -2364,12 +2768,12 @@ var HOOK_ENTRY = {
2364
2768
  };
2365
2769
  var isOurs = (h) => typeof h.command === "string" && h.command.includes("@alterset/alterspec-client progress");
2366
2770
  function writeClaudeSettings(root) {
2367
- const path = join6(root, CLAUDE_SETTINGS);
2368
- const before = existsSync6(path) ? readFileSync5(path, "utf8") : void 0;
2771
+ const path = join7(root, CLAUDE_SETTINGS);
2772
+ const before2 = existsSync7(path) ? readFileSync6(path, "utf8") : void 0;
2369
2773
  let data = {};
2370
- if (before !== void 0)
2774
+ if (before2 !== void 0)
2371
2775
  try {
2372
- data = JSON.parse(before);
2776
+ data = JSON.parse(before2);
2373
2777
  } catch {
2374
2778
  throw new ConfigError(`${path} is not valid JSON: fix it, then run init again.`);
2375
2779
  }
@@ -2384,29 +2788,29 @@ function writeClaudeSettings(root) {
2384
2788
  return [HOOK_ENTRY];
2385
2789
  });
2386
2790
  if (!found) groups.push({ matcher: "Bash", hooks: [HOOK_ENTRY] });
2387
- const after = JSON.stringify(data, null, 2) + "\n";
2388
- if (before !== void 0 && JSON.stringify(JSON.parse(before)) === JSON.stringify(data)) return "unchanged";
2389
- mkdirSync2(join6(root, ".claude"), { recursive: true });
2390
- writeFileSync4(path, after);
2391
- return before === void 0 ? "created" : "updated";
2791
+ const after2 = JSON.stringify(data, null, 2) + "\n";
2792
+ if (before2 !== void 0 && JSON.stringify(JSON.parse(before2)) === JSON.stringify(data)) return "unchanged";
2793
+ mkdirSync3(join7(root, ".claude"), { recursive: true });
2794
+ writeFileSync5(path, after2);
2795
+ return before2 === void 0 ? "created" : "updated";
2392
2796
  }
2393
2797
  var CLAUDE_LOCAL_SETTINGS = ".claude/settings.local.json";
2394
2798
  function writeLocalSettings(root) {
2395
- const path = join6(root, CLAUDE_LOCAL_SETTINGS);
2396
- const before = existsSync6(path) ? readFileSync5(path, "utf8") : void 0;
2799
+ const path = join7(root, CLAUDE_LOCAL_SETTINGS);
2800
+ const before2 = existsSync7(path) ? readFileSync6(path, "utf8") : void 0;
2397
2801
  let data = {};
2398
- if (before !== void 0)
2802
+ if (before2 !== void 0)
2399
2803
  try {
2400
- data = JSON.parse(before);
2804
+ data = JSON.parse(before2);
2401
2805
  } catch {
2402
2806
  throw new ConfigError(`${path} is not valid JSON: fix it, then run init again.`);
2403
2807
  }
2404
2808
  const enabled = Array.isArray(data.enabledMcpjsonServers) ? data.enabledMcpjsonServers : [];
2405
- if (before !== void 0 && enabled.includes(MCP_SERVER)) return "unchanged";
2809
+ if (before2 !== void 0 && enabled.includes(MCP_SERVER)) return "unchanged";
2406
2810
  data.enabledMcpjsonServers = [...enabled, MCP_SERVER];
2407
- mkdirSync2(join6(root, ".claude"), { recursive: true });
2408
- writeFileSync4(path, JSON.stringify(data, null, 2) + "\n");
2409
- return before === void 0 ? "created" : "updated";
2811
+ mkdirSync3(join7(root, ".claude"), { recursive: true });
2812
+ writeFileSync5(path, JSON.stringify(data, null, 2) + "\n");
2813
+ return before2 === void 0 ? "created" : "updated";
2410
2814
  }
2411
2815
  function approveHere(configRoot, cwd = process.cwd()) {
2412
2816
  const top = spawnSync("git", ["rev-parse", "--show-toplevel"], {
@@ -2422,10 +2826,10 @@ function approveHere(configRoot, cwd = process.cwd()) {
2422
2826
  }
2423
2827
  };
2424
2828
  if (!top || same(top, configRoot)) return { root: configRoot, outcome: "unchanged" };
2425
- if (!existsSync6(join6(top, MCP_JSON))) return { root: top, outcome: "unchanged" };
2426
- const claude = join6(top, ".claude");
2829
+ if (!existsSync7(join7(top, MCP_JSON))) return { root: top, outcome: "unchanged" };
2830
+ const claude = join7(top, ".claude");
2427
2831
  try {
2428
- if (lstatSync(claude).isSymbolicLink() && !existsSync6(claude)) return { root: top, outcome: "unchanged" };
2832
+ if (lstatSync(claude).isSymbolicLink() && !existsSync7(claude)) return { root: top, outcome: "unchanged" };
2429
2833
  } catch {
2430
2834
  }
2431
2835
  return { root: top, outcome: writeLocalSettings(top) };
@@ -2436,9 +2840,9 @@ function ignoreLocalSettings(root) {
2436
2840
  const status = git4("check-ignore", "-q", CLAUDE_LOCAL_SETTINGS);
2437
2841
  if (status === 0) return "ignored";
2438
2842
  if (status !== 1) return "unknown";
2439
- const path = join6(root, ".gitignore");
2440
- const before = existsSync6(path) ? readFileSync5(path, "utf8") : "";
2441
- writeFileSync4(path, `${before}${before && !before.endsWith("\n") ? "\n" : ""}${CLAUDE_LOCAL_SETTINGS}
2843
+ const path = join7(root, ".gitignore");
2844
+ const before2 = existsSync7(path) ? readFileSync6(path, "utf8") : "";
2845
+ writeFileSync5(path, `${before2}${before2 && !before2.endsWith("\n") ? "\n" : ""}${CLAUDE_LOCAL_SETTINGS}
2442
2846
  `);
2443
2847
  return "added";
2444
2848
  }
@@ -2453,8 +2857,8 @@ function initClient(root, opts, version) {
2453
2857
  existing ? `The configuration would not be valid: ${parsed.error.issues.map((i) => `${i.path.join(".")} ${i.message}`).join("; ")}.` : `init needs --dispatcher <url> and --export <path to your clone of the export>${missing.length ? ` (missing or wrong: ${missing.join(", ")})` : ""}.`
2454
2858
  );
2455
2859
  }
2456
- const before = existing && JSON.stringify(existing);
2457
- const config = !existing ? "created" : before === JSON.stringify(parsed.data) ? "unchanged" : "updated";
2860
+ const before2 = existing && JSON.stringify(existing);
2861
+ const config = !existing ? "created" : before2 === JSON.stringify(parsed.data) ? "unchanged" : "updated";
2458
2862
  if (config !== "unchanged") writeConfig(root, parsed.data);
2459
2863
  const mcp = writeMcpJson(root);
2460
2864
  const hook = writeClaudeSettings(root);
@@ -2677,7 +3081,7 @@ function lookup(x, opts) {
2677
3081
  if (!isDoc(id)) return [{ id, ...a.title ? { title: a.title } : {}, at: pathOf(id), shards: [] }];
2678
3082
  const folder = `${shardDir(file)}/`;
2679
3083
  const kind = idKind(id);
2680
- const sections = (kind && READ[kind]) ?? [];
3084
+ const sections2 = (kind && READ[kind]) ?? [];
2681
3085
  return [
2682
3086
  {
2683
3087
  id,
@@ -2685,7 +3089,7 @@ function lookup(x, opts) {
2685
3089
  at: folder,
2686
3090
  shards: [
2687
3091
  FRONT_MATTER_SHARD,
2688
- ...sections.flatMap((h) => x.sectionShard(file, h)?.slice(folder.length) ?? [])
3092
+ ...sections2.flatMap((h) => x.sectionShard(file, h)?.slice(folder.length) ?? [])
2689
3093
  ]
2690
3094
  }
2691
3095
  ];
@@ -2717,8 +3121,8 @@ function lookup(x, opts) {
2717
3121
  must(last && x.proposalPath(last), `why ${id} is as it is (${last}, the last change of it)`);
2718
3122
  }
2719
3123
  must("_generated/open-items.md", "what the spec itself holds open");
2720
- const seen = new Set(resolved);
2721
- const neighbours = resolved.flatMap((id) => hop.get(id)).filter((l) => !seen.has(l.id) && seen.add(l.id)).map((l) => ({ id: l.id, path: pathOf(l.id) ?? "", why: l.why })).filter((l) => l.path && !check.has(l.path)).sort((a, b) => {
3124
+ const seen2 = new Set(resolved);
3125
+ const neighbours = resolved.flatMap((id) => hop.get(id)).filter((l) => !seen2.has(l.id) && seen2.add(l.id)).map((l) => ({ id: l.id, path: pathOf(l.id) ?? "", why: l.why })).filter((l) => l.path && !check.has(l.path)).sort((a, b) => {
2722
3126
  const rank = (id) => (ORDER.indexOf(idKind(id)) + 1 || ORDER.length + 1) - 1;
2723
3127
  return rank(a.id) - rank(b.id);
2724
3128
  }).slice(0, NEIGHBOURS);
@@ -2789,11 +3193,11 @@ async function openDispatcher(session, open = openInBrowser) {
2789
3193
  }
2790
3194
 
2791
3195
  // src/progress.ts
2792
- import { execFileSync as execFileSync4 } from "child_process";
3196
+ import { execFileSync as execFileSync5 } from "child_process";
2793
3197
  import { createHash as createHash3 } from "crypto";
2794
- import { existsSync as existsSync7, mkdirSync as mkdirSync3, readFileSync as readFileSync6, writeFileSync as writeFileSync5 } from "fs";
2795
- import { join as join7 } from "path";
2796
- var git3 = (cwd, args) => execFileSync4("git", args, { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }).trim();
3198
+ import { existsSync as existsSync8, mkdirSync as mkdirSync4, readFileSync as readFileSync7, writeFileSync as writeFileSync6 } from "fs";
3199
+ import { join as join8 } from "path";
3200
+ var git3 = (cwd, args) => execFileSync5("git", args, { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }).trim();
2797
3201
  function currentTask(repo) {
2798
3202
  try {
2799
3203
  const task = taskOfBranch(git3(repo, ["symbolic-ref", "--short", "HEAD"]));
@@ -2861,7 +3265,7 @@ function progressText(r) {
2861
3265
  }
2862
3266
  var unknownLine = (r) => `${r.task} has no item ${r.unknown.join(", ")}; left out of the report: name only the task's items (context lists them).`;
2863
3267
  var THROTTLE_MS = 15 * 6e4;
2864
- var statePath = (repo, task) => join7(
3268
+ var statePath = (repo, task) => join8(
2865
3269
  git3(repo, ["rev-parse", "--path-format=absolute", "--git-common-dir"]),
2866
3270
  "alterspec-client",
2867
3271
  `progress-${folderOf(task)}.json`
@@ -2869,7 +3273,7 @@ var statePath = (repo, task) => join7(
2869
3273
  var hashOf = (covered) => createHash3("sha256").update(JSON.stringify(covered)).digest("hex").slice(0, 16);
2870
3274
  function readState(path) {
2871
3275
  try {
2872
- return existsSync7(path) ? JSON.parse(readFileSync6(path, "utf8")) : void 0;
3276
+ return existsSync8(path) ? JSON.parse(readFileSync7(path, "utf8")) : void 0;
2873
3277
  } catch {
2874
3278
  return void 0;
2875
3279
  }
@@ -2886,8 +3290,8 @@ async function progressHook(opts) {
2886
3290
  if (state?.reported === hash) return "unchanged";
2887
3291
  if (state && now() - Date.parse(state.at) < THROTTLE_MS) return "throttled";
2888
3292
  await reportProgress(opts.session(), task, covered);
2889
- mkdirSync3(join7(path, ".."), { recursive: true });
2890
- writeFileSync5(path, JSON.stringify({ reported: hash, at: new Date(now()).toISOString() }) + "\n");
3293
+ mkdirSync4(join8(path, ".."), { recursive: true });
3294
+ writeFileSync6(path, JSON.stringify({ reported: hash, at: new Date(now()).toISOString() }) + "\n");
2891
3295
  return "reported";
2892
3296
  } catch {
2893
3297
  return "failed";
@@ -2915,9 +3319,9 @@ async function hookCwd(input, waitMs = 1e3) {
2915
3319
  }
2916
3320
 
2917
3321
  // src/version.ts
2918
- import { readFileSync as readFileSync7 } from "fs";
3322
+ import { readFileSync as readFileSync8 } from "fs";
2919
3323
  function packageVersion() {
2920
- const pkg = JSON.parse(readFileSync7(new URL("../package.json", import.meta.url), "utf8"));
3324
+ const pkg = JSON.parse(readFileSync8(new URL("../package.json", import.meta.url), "utf8"));
2921
3325
  return pkg.version;
2922
3326
  }
2923
3327
 
@@ -2962,7 +3366,7 @@ function approveWorktree(loaded) {
2962
3366
  const { root, outcome } = approveHere(loaded.root);
2963
3367
  if (outcome === "unchanged") return;
2964
3368
  process.stderr.write(
2965
- `Approved the "dispatcher" server for you in ${join8(root, CLAUDE_LOCAL_SETTINGS)} (this checkout had no approval of its own); its tools appear in the next Claude Code session here.
3369
+ `Approved the "dispatcher" server for you in ${join9(root, CLAUDE_LOCAL_SETTINGS)} (this checkout had no approval of its own); its tools appear in the next Claude Code session here.
2966
3370
  `
2967
3371
  );
2968
3372
  }
@@ -3062,13 +3466,19 @@ program.command("context").description("print a task\u2019s brief, assembled fro
3062
3466
  task.id,
3063
3467
  ...(x.work.changes.find((c) => c.id === task.change)?.tasks ?? []).map((t) => `${task.change}/${t.track}`).filter((t) => t !== task.id)
3064
3468
  ];
3469
+ const pins = pinsDir(loaded.root, task);
3065
3470
  const ctx = taskContext(
3066
3471
  x,
3067
3472
  task,
3068
3473
  dir,
3069
3474
  await coveredState(loaded, task),
3070
- await changeQuestions(sessionOf(loaded), tasks)
3475
+ await changeQuestions(sessionOf(loaded), tasks),
3476
+ { pins, shown: readShown(process.cwd(), task) }
3071
3477
  );
3478
+ if (!opts.stats) {
3479
+ writePins(pins, pinFiles(x, ctx));
3480
+ writeShown(process.cwd(), task, shownOf(ctx));
3481
+ }
3072
3482
  process.stdout.write(
3073
3483
  opts.stats ? contextStats(renderContext(ctx)) : opts.json ? JSON.stringify(ctx, null, 2) + "\n" : renderContext(ctx)
3074
3484
  );