@alterset/alterspec-client 0.17.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";
@@ -58,9 +58,16 @@ var WorkChangeSchema = z.object({
58
58
  /** The change map's level. */
59
59
  level: z.number().int().min(1),
60
60
  /** One per track the change is on; empty = no work. */
61
- tasks: z.array(WorkTaskSchema)
61
+ tasks: z.array(WorkTaskSchema),
62
+ /**
63
+ * The size of the whole change, 1–100 (format 4): reasoned at sign-off against alterspec's change rubric (a
64
+ * wording fix about 1–5, one capability's criteria 10–20, a new capability or flow 30–50, a new module or the
65
+ * application's foundation 80–100), never a sum of the item weights and never anyone's code. Absent: the change
66
+ * was signed off without one. For the lists; progress and ETA keep the item weights.
67
+ */
68
+ weight: WorkWeight.optional()
62
69
  }).strict();
63
- var WORK_FORMAT = 3;
70
+ var WORK_FORMAT = 4;
64
71
  var WorkSchema = z.object({
65
72
  format: z.literal(WORK_FORMAT),
66
73
  /** The alterspec version that wrote the export. */
@@ -72,17 +79,27 @@ var WorkSchema = z.object({
72
79
  /** Every change signed off after the baseline, in the change map's order. */
73
80
  changes: z.array(WorkChangeSchema)
74
81
  }).strict();
82
+ var WorkChangeV3Schema = WorkChangeSchema.omit({ weight: true }).strict();
83
+ var WorkV3Schema = WorkSchema.extend({
84
+ format: z.literal(3),
85
+ changes: z.array(WorkChangeV3Schema)
86
+ }).strict();
75
87
  var WorkTaskV2Schema = WorkTaskSchema.omit({ weights: true });
76
88
  var WorkV2Schema = WorkSchema.extend({
77
89
  format: z.literal(2),
78
- changes: z.array(WorkChangeSchema.extend({ tasks: z.array(WorkTaskV2Schema) }).strict())
90
+ changes: z.array(WorkChangeV3Schema.extend({ tasks: z.array(WorkTaskV2Schema) }).strict())
79
91
  }).strict();
80
92
  var WorkTaskV1Schema = WorkTaskV2Schema.omit({ items: true });
81
93
  var WorkV1Schema = WorkSchema.extend({
82
94
  format: z.literal(1),
83
- changes: z.array(WorkChangeSchema.extend({ tasks: z.array(WorkTaskV1Schema) }).strict())
95
+ changes: z.array(WorkChangeV3Schema.extend({ tasks: z.array(WorkTaskV1Schema) }).strict())
84
96
  }).strict();
85
- var AnyWorkSchema = z.discriminatedUnion("format", [WorkV1Schema, WorkV2Schema, WorkSchema]);
97
+ var AnyWorkSchema = z.discriminatedUnion("format", [
98
+ WorkV1Schema,
99
+ WorkV2Schema,
100
+ WorkV3Schema,
101
+ WorkSchema
102
+ ]);
86
103
 
87
104
  // src/config.ts
88
105
  var CONFIG_FILE = ".alterspec-client.json";
@@ -485,6 +502,15 @@ var ChangeSchema = z5.object({
485
502
  * before weights existed. The dispatcher weighs progress and ETA by it.
486
503
  */
487
504
  weights: z5.record(z5.string(), WorkWeight).optional(),
505
+ /**
506
+ * The size of the whole change, 1–100 (`work.json` format 4, `changes[].weight`): reasoned by the sign-off skill
507
+ * against the change rubric (`_weights.md` "The change's weight"), never a sum of the item weights and never
508
+ * anyone's code. Written by `change weigh` with `change_weight_why`, frozen at sign-off; absent = not weighed.
509
+ * The dispatcher shows it on its lists with the percent complete.
510
+ */
511
+ change_weight: WorkWeight.optional(),
512
+ /** One line: what makes the change that size. */
513
+ change_weight_why: z5.string().optional(),
488
514
  /**
489
515
  * In a team project: the draft IDs the change and what it creates carried until the sign-off numbered them
490
516
  * (draft → final). Written by the CLI at sign-off.
@@ -550,10 +576,10 @@ function parseDelta(json) {
550
576
  }
551
577
  }
552
578
  function exportChange(e) {
553
- const { before, after } = e.exported;
554
- if (before && after) return e.change;
555
- if (after) return "enters the export";
556
- 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";
557
583
  return "not in the export";
558
584
  }
559
585
 
@@ -575,6 +601,8 @@ var shardDir = (path) => `${SHARDS_DIR}/${path.replace(/\.md$/, "")}`;
575
601
  var itemShardName = (key) => `${key.startsWith("term:") ? slug(key.slice(5)) : key}.md`;
576
602
  var itemShardPath = (path, key) => `${shardDir(path)}/${itemShardName(key)}`;
577
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`;
578
606
  var isSectionShard = (name, heading) => new RegExp(`^\\d{2}-${slug(heading)}\\.md$`).test(name);
579
607
 
580
608
  // ../src/lib/frontmatter-split.ts
@@ -611,27 +639,27 @@ function objectParts(text, kind) {
611
639
  const yaml = /^```ya?ml\n([\s\S]*?)\n```[^\S\n]*$/m.exec(t);
612
640
  if (yaml) put("front-matter", FRONT_MATTER_PART, yaml[1]);
613
641
  const body = yaml ? t.slice(yaml.index + yaml[0].length) : t.replace(/^## [^\n]*\n?/, "");
614
- const { sections } = headed(body, "### ");
615
- 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);
616
644
  else for (const b of bullets(body)) put("line", b.heading, b.text);
617
645
  return out;
618
646
  }
619
647
  function headed(text, marker) {
620
- const sections = [];
648
+ const sections2 = [];
621
649
  let intro = "";
622
650
  let fence2 = false;
623
651
  for (const l of text.split("\n")) {
624
652
  if (/^(?:```|~~~)/.test(l)) fence2 = !fence2;
625
653
  if (!fence2 && l.startsWith(marker) && /\S/.test(l.slice(marker.length))) {
626
- sections.push({ heading: l.slice(marker.length).trim(), text: "" });
654
+ sections2.push({ heading: l.slice(marker.length).trim(), text: "" });
627
655
  continue;
628
656
  }
629
- if (sections.length) sections[sections.length - 1].text += `${l}
657
+ if (sections2.length) sections2[sections2.length - 1].text += `${l}
630
658
  `;
631
659
  else intro += `${l}
632
660
  `;
633
661
  }
634
- return { intro, sections };
662
+ return { intro, sections: sections2 };
635
663
  }
636
664
  var BULLET = /^(?:[-*+]|\d+[.)])\s+(.*)$/;
637
665
  function bullets(text) {
@@ -893,6 +921,212 @@ function criterionParts(chunk) {
893
921
  };
894
922
  }
895
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
+
896
1130
  // src/questions.ts
897
1131
  import { z as z7 } from "zod";
898
1132
 
@@ -1108,8 +1342,8 @@ async function taskQuestions(session, task) {
1108
1342
  async function changeQuestions(session, tasks) {
1109
1343
  const lists = await Promise.all(tasks.map((t) => taskQuestions(session, t)));
1110
1344
  if (lists.some((l) => l === void 0)) return void 0;
1111
- const seen = /* @__PURE__ */ new Set();
1112
- 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));
1113
1347
  }
1114
1348
  var holding = (q) => q.answers.at(-1);
1115
1349
  var isCorrected = (q) => q.corrected ?? holding(q)?.verdict === "corrected";
@@ -1179,10 +1413,10 @@ function answersSection(answers) {
1179
1413
  // src/context.ts
1180
1414
  var ContextError = class extends Error {
1181
1415
  };
1182
- function startFrom(track, after) {
1183
- if (!Array.isArray(after)) return [];
1416
+ function startFrom(track, after2) {
1417
+ if (!Array.isArray(after2)) return [];
1184
1418
  const out = [];
1185
- for (const a of after) {
1419
+ for (const a of after2) {
1186
1420
  if (typeof a?.id !== "string" || typeof a.branch !== "string" || !a.branch) continue;
1187
1421
  if (a.id.split("/")[1] !== track) continue;
1188
1422
  out.push({ id: a.id, branch: a.branch, ...typeof a.commit === "string" ? { commit: a.commit } : {} });
@@ -1193,7 +1427,7 @@ var shardText = (x, path) => path ? x.read(path)?.replace(/^<!-- source: [^\n]*-
1193
1427
  var sectionText = (x, path) => shardText(x, path)?.replace(/^## [^\n]*\n*/, "");
1194
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);
1195
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, "");
1196
- function withSections(diff, before, after) {
1430
+ function withSections(diff, before2, after2) {
1197
1431
  const where = (text, line) => {
1198
1432
  const lines2 = text.split("\n");
1199
1433
  if (lines2[0] === "---") {
@@ -1215,7 +1449,7 @@ function withSections(diff, before, after) {
1215
1449
  let k = i + 1;
1216
1450
  while (lines[k]?.startsWith(" ")) k++;
1217
1451
  const skipped = k - i - 1;
1218
- 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);
1219
1453
  return name ? `${header} ${name}` : header;
1220
1454
  }).join("\n");
1221
1455
  }
@@ -1225,21 +1459,33 @@ var firstAddedLine = (a, b) => diffLines(a, b).filter((l) => l.op === "+").map(
1225
1459
  ).find((t) => t && !/^(---|```)/.test(t) && !BOOKKEEPING.test(t));
1226
1460
  var clipped = (line) => line && line.length > 200 ? `${line.slice(0, 199)}\u2026` : line;
1227
1461
  function firstAdded(key, entry) {
1228
- const before = forDiff(key, entry.before);
1229
- const after = forDiff(key, entry.after);
1462
+ const before2 = forDiff(key, entry.before);
1463
+ const after2 = forDiff(key, entry.after);
1230
1464
  return clipped(
1231
- 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 ?? "")
1232
1466
  );
1233
1467
  }
1234
- function objectBrief(x, key, entry, why, later = []) {
1468
+ function currentText(x, key) {
1235
1469
  const file = x.fileOf(key);
1236
- 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);
1237
1479
  const brief = { key, ...held ? { file } : {} };
1238
- 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(/\/[^/]+$/, "");
1239
1481
  if (why) brief.unrecoverable = why;
1240
1482
  if (!entry) return brief;
1241
- 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();
1242
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);
1243
1489
  brief.change = exportChange(entry);
1244
1490
  if (entry.status) brief.status = entry.status;
1245
1491
  if (entry.before !== void 0 || entry.after !== void 0) {
@@ -1334,10 +1580,10 @@ function itemWhat(x, item, entry, track) {
1334
1580
  const k = idKind(key);
1335
1581
  const owner = `${k && KIND_WORDS[k] ? `${KIND_WORDS[k]} ` : ""}${named(x, key)}`;
1336
1582
  const kind2 = entry?.kind === "item" ? "item" : "doc";
1337
- const after = entry?.after !== void 0 ? objectParts(entry.after, kind2).get(slug2) : void 0;
1338
- const before = entry?.before !== void 0 ? objectParts(entry.before, kind2).get(slug2) : void 0;
1339
- const label = !after ? `the part "${slug2}"` : after.label === "front-matter" ? "the front-matter" : after.label === "section" ? `the section "${after.heading}"` : `the line "${after.heading}"`;
1340
- 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;
1341
1587
  return `${label} of ${owner}${line2 ? `: "${line2}"` : ""}`;
1342
1588
  }
1343
1589
  const kind = idKind(item);
@@ -1356,16 +1602,16 @@ function changedAttributes(entry) {
1356
1602
  if (!entry || !entry.exported.before || !entry.exported.after) return void 0;
1357
1603
  if (entry.before === void 0 || entry.after === void 0) return void 0;
1358
1604
  const names = (raw) => new Map([...raw.matchAll(/^ {2}- name: (.+?)\s*$/gm)].map((m) => [m[1], m.index]));
1359
- const before = splitFrontMatter(entry.before).raw ?? "";
1360
- const after = splitFrontMatter(entry.after).raw ?? "";
1605
+ const before2 = splitFrontMatter(entry.before).raw ?? "";
1606
+ const after2 = splitFrontMatter(entry.after).raw ?? "";
1361
1607
  const attr = (raw, from) => {
1362
1608
  const chunk = raw.slice(from).split(/\n(?! {4})/)[0] ?? "";
1363
1609
  return chunk.replace(/^\s*- name: .*\n?/, "");
1364
1610
  };
1365
- const b = names(before);
1366
- const a = names(after);
1611
+ const b = names(before2);
1612
+ const a = names(after2);
1367
1613
  const out = /* @__PURE__ */ new Set();
1368
- 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);
1369
1615
  for (const n of b.keys()) if (!a.has(n)) out.add(n);
1370
1616
  return [...out];
1371
1617
  }
@@ -1402,12 +1648,6 @@ function whereUsed(x, objects, entries, changed) {
1402
1648
  }
1403
1649
  return out;
1404
1650
  }
1405
- function laterChanges(x, change, key) {
1406
- const order = x.work.changes.map((c) => c.id);
1407
- const at = order.indexOf(change);
1408
- const touched = x.sources.get(key)?.changed_by ?? [];
1409
- return touched.filter((c) => order.indexOf(c) > at).sort((a, b) => order.indexOf(a) - order.indexOf(b));
1410
- }
1411
1651
  function lifecycleOf(x, id) {
1412
1652
  const e = x.index()?.entities.find((e2) => e2.id === id);
1413
1653
  if (!e?.states?.length) return void 0;
@@ -1456,7 +1696,15 @@ function reachOf(x, id, kind, changed) {
1456
1696
  screens: screens.map((s) => piece(s.id, s.title))
1457
1697
  };
1458
1698
  }
1459
- 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
+ };
1460
1708
  const change = x.work.changes.find((c) => c.id === task.change);
1461
1709
  if (!change) throw new ContextError(`${task.change} is not in this export's work.json: pull the export.`);
1462
1710
  const work = change.tasks.find((t) => t.track === task.track);
@@ -1510,10 +1758,10 @@ function taskContext(x, task, exportDir2, state = {}, questions) {
1510
1758
  ...dataChangeOf(sectionText(x, x.sectionShard(proposal, DATA_CHANGE_SECTION)))
1511
1759
  },
1512
1760
  ...delta ? { delta: proposal.replace(/proposal\.md$/, "delta.md") } : {},
1513
- objects: work.objects.map(
1514
- (key) => objectBrief(x, key, entries.get(key), lost.get(key), laterChanges(x, change.id, key))
1515
- )
1761
+ objects: work.objects.map((key) => objectBrief(x, key, entries.get(key), lost.get(key), at)),
1762
+ ...opts.pins ? { pins: opts.pins } : {}
1516
1763
  };
1764
+ for (const key of work.objects) names.add(key);
1517
1765
  const added = work.objects.flatMap((key) => {
1518
1766
  const e = entries.get(key);
1519
1767
  return e ? diffLines(forDiff(key, e.before), forDiff(key, e.after)).filter((l) => l.op === "+") : [];
@@ -1530,14 +1778,15 @@ function taskContext(x, task, exportDir2, state = {}, questions) {
1530
1778
  return [
1531
1779
  {
1532
1780
  id,
1533
- path,
1781
+ path: at(path),
1534
1782
  ...title ? { title } : {},
1535
1783
  ...text ? { text } : {},
1536
- ...changed.has(id) ? { changed: true } : {}
1784
+ ...changed.has(id) ? { changed: true } : {},
1785
+ ...since(id)
1537
1786
  }
1538
1787
  ];
1539
1788
  };
1540
- ctx.whereUsed = whereUsed(x, work.objects, entries, changed);
1789
+ ctx.whereUsed = whereUsed(current, work.objects, entries, changed);
1541
1790
  const capabilities = work.objects.filter((k) => /^CAP-/.test(k) && x.fileOf(k) && x.has(x.fileOf(k)));
1542
1791
  const onList = items && new Set(items);
1543
1792
  ctx.acceptance = capabilities.flatMap((id) => {
@@ -1553,12 +1802,12 @@ function taskContext(x, task, exportDir2, state = {}, questions) {
1553
1802
  const title = titleOf(x, id);
1554
1803
  const rest = [
1555
1804
  added2 ? `${added2 === 1 ? "One new criterion is" : `${added2} new criteria are`} whole in its delta above.` : "",
1556
- chunks.length > listed.length ? `Its other criteria: \`${path}\`.` : ""
1805
+ chunks.length > listed.length ? `Its other criteria: \`${at(path)}\`.` : ""
1557
1806
  ].filter(Boolean).join(" ");
1558
1807
  return [
1559
1808
  {
1560
1809
  id,
1561
- path,
1810
+ path: at(path),
1562
1811
  ...title ? { title } : {},
1563
1812
  ...kept.length ? { text: kept.join("").trim() } : {},
1564
1813
  ...kept.length && rest ? { rest } : {}
@@ -1595,23 +1844,24 @@ function taskContext(x, task, exportDir2, state = {}, questions) {
1595
1844
  const file = x.fileOf(id);
1596
1845
  if (!file || !x.has(file)) return [];
1597
1846
  const title = titleOf(x, id);
1598
- const note = lifecycleOf(x, id);
1847
+ const note = lifecycleOf(current, id);
1599
1848
  return [
1600
1849
  {
1601
1850
  id,
1602
- path: file,
1851
+ path: at(file),
1603
1852
  ...title ? { title } : {},
1604
1853
  ...changed.has(id) ? { changed: true } : {},
1605
- ...note ? { note } : {}
1854
+ ...note ? { note } : {},
1855
+ ...since(id)
1606
1856
  }
1607
1857
  ];
1608
1858
  });
1609
- ctx.operations = x.has(OPERATIONS_FILE) ? capabilities.flatMap((id) => {
1610
- const path = x.shards(OPERATIONS_FILE).find((p) => new RegExp(`/\\d{2}-${slug(id)}(-|\\.md$)`).test(p));
1611
- 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) }] : [];
1612
1862
  }) : [];
1613
1863
  } else {
1614
- const existing = (p) => x.has(p) ? p : void 0;
1864
+ const existing = (p) => x.has(p) ? at(p) : void 0;
1615
1865
  const performing = [...x.sources.keys()].filter(
1616
1866
  (id) => /^SCR-/.test(id) && x.has(contractPath(id, track.code)) && idsIn(frontMatterOf(x.read(x.fileOf(id)) ?? ""), ["capability"]).some(
1617
1867
  (c) => capabilities.includes(c)
@@ -1620,12 +1870,17 @@ function taskContext(x, task, exportDir2, state = {}, questions) {
1620
1870
  const screens = [
1621
1871
  .../* @__PURE__ */ new Set([...work.objects.map(screenOf).filter((s) => !!s), ...performing])
1622
1872
  ];
1623
- ctx.screens = screens.map((id) => ({
1624
- id,
1625
- file: x.fileOf(id),
1626
- contract: existing(contractPath(id, track.code)),
1627
- page: existing(mockupPath(track.code, id))
1628
- }));
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}`);
1629
1884
  ctx.design = {
1630
1885
  designSystem: existing(designSystemPath(track.code)),
1631
1886
  patterns: existing(patternsPath(track.code))
@@ -1642,8 +1897,8 @@ function taskContext(x, task, exportDir2, state = {}, questions) {
1642
1897
  ];
1643
1898
  const roles = work.objects.filter((k) => idKind(k) === "role");
1644
1899
  ctx.reach = [
1645
- ...rules.map((id) => reachOf(x, id, "rule", changed)),
1646
- ...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))
1647
1902
  ].filter((r) => !!r);
1648
1903
  if (!ctx.reach.length) delete ctx.reach;
1649
1904
  const glossary = x.fileOf("term:");
@@ -1654,10 +1909,72 @@ function taskContext(x, task, exportDir2, state = {}, questions) {
1654
1909
  const term = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1655
1910
  if (!new RegExp(`(?<![\\w-])${term}(?:s|es)?(?![\\w-])`, "i").test(writtenText)) return [];
1656
1911
  const text = sectionText(x, path);
1657
- return [{ id: name, path, ...text ? { text } : {} }];
1912
+ return [{ id: name, path: at(path), ...text ? { text } : {}, ...since(`term:${name}`) }];
1658
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
+ }
1659
1960
  return ctx;
1660
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
+ }
1661
1978
  var fence = (text, lang = "") => {
1662
1979
  const ticks = "`".repeat(Math.max(3, ...[...text.matchAll(/`+/g)].map((m) => m[0].length + 1)));
1663
1980
  return `${ticks}${lang}
@@ -1670,6 +1987,15 @@ function renderContext(c) {
1670
1987
  "",
1671
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}.`
1672
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
+ }
1673
1999
  if (c.after.length) out.push("", `Waits for: ${c.after.map((a) => `${a.change}/${a.track}`).join(", ")}.`);
1674
2000
  if (c.startFrom?.length)
1675
2001
  out.push(
@@ -1720,13 +2046,16 @@ function renderContext(c) {
1720
2046
  const status = o.status && o.status.before !== o.status.after ? `, ${o.status.before ?? "\u2014"} \u2192 ${o.status.after ?? "\u2014"}` : "";
1721
2047
  out.push(`### ${o.key}`, "", `${o.change ?? "no delta entry"}${status}; ${where}.`);
1722
2048
  if (o.unrecoverable) out.push("", `The delta could not recover it: ${o.unrecoverable}.`);
1723
- if (o.since) {
1724
- 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)
1725
2050
  out.push(
1726
2051
  "",
1727
- 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."
1728
2058
  );
1729
- }
1730
2059
  if (o.diff) out.push("", o.diff.startsWith("@@") ? fence(o.diff, "diff") : o.diff);
1731
2060
  out.push("");
1732
2061
  }
@@ -1787,17 +2116,19 @@ function renderContext(c) {
1787
2116
  if (!list2?.length) return;
1788
2117
  out.push(`## ${title}`, "");
1789
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`;
1790
2120
  for (const p of list2.filter((p2) => p2.text))
1791
2121
  out.push(
1792
2122
  `### ${p.id}${p.title ? ` ${p.title}` : ""} (\`${p.path}\`)`,
1793
2123
  "",
2124
+ ...moved(p) ? [`(${moved(p)})`, ""] : [],
1794
2125
  p.text,
1795
2126
  ...p.rest ? ["", p.rest] : [],
1796
2127
  ""
1797
2128
  );
1798
2129
  for (const p of list2.filter((p2) => !p2.text))
1799
2130
  out.push(
1800
- `- ${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)})` : ""}`
1801
2132
  );
1802
2133
  out.push("");
1803
2134
  };
@@ -1854,18 +2185,64 @@ function renderContext(c) {
1854
2185
  ""
1855
2186
  );
1856
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
+ }
1857
2234
  return out.join("\n").replace(/\n{3,}/g, "\n\n").trimEnd() + "\n";
1858
2235
  }
1859
2236
  function contextStats(markdown) {
1860
- const sections = markdown.split(/^(?=## )/m).map((part, i) => ({
2237
+ const sections2 = markdown.split(/^(?=## )/m).map((part, i) => ({
1861
2238
  name: i === 0 ? "(heading)" : part.split("\n")[0].slice(3),
1862
2239
  chars: part.length
1863
2240
  }));
1864
- 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);
1865
2242
  const row = (name, chars) => `${name.padEnd(width)} ${String(Math.ceil(chars / 4)).padStart(7)} ${String(chars).padStart(8)}`;
1866
2243
  return [
1867
2244
  `${"Section".padEnd(width)} ${"~tokens".padStart(7)} ${"chars".padStart(8)}`,
1868
- ...sections.map((x) => row(x.name, x.chars)),
2245
+ ...sections2.map((x) => row(x.name, x.chars)),
1869
2246
  row("Total", markdown.length)
1870
2247
  ].join("\n") + "\n";
1871
2248
  }
@@ -2052,10 +2429,10 @@ function renderBugContext(c) {
2052
2429
  return out.join("\n");
2053
2430
  }
2054
2431
 
2055
- // src/git.ts
2432
+ // src/pinstore.ts
2056
2433
  import { execFileSync as execFileSync3 } from "child_process";
2057
- import { existsSync as existsSync4 } from "fs";
2058
- 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";
2059
2436
 
2060
2437
  // src/task.ts
2061
2438
  var TRAILER = "Alterspec-Task";
@@ -2082,12 +2459,65 @@ function taskOfBranch(branch) {
2082
2459
  return m ? parseTask(`${m[1]}/${m[2]}`) : void 0;
2083
2460
  }
2084
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
+
2085
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";
2086
2516
  var GitError = class extends Error {
2087
2517
  };
2088
2518
  function git2(cwd, args) {
2089
2519
  try {
2090
- 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();
2091
2521
  } catch (e) {
2092
2522
  const stderr = String(e.stderr ?? "").trim();
2093
2523
  throw new GitError(`git ${args.join(" ")} failed in ${cwd}${stderr ? `: ${stderr}` : ""}`);
@@ -2102,7 +2532,7 @@ var tryGit = (cwd, args) => {
2102
2532
  };
2103
2533
  var isAncestor = (cwd, a, b) => tryGit(cwd, ["merge-base", "--is-ancestor", a, b]) !== void 0;
2104
2534
  function exportHead(dir, latest) {
2105
- 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)
2106
2536
  throw new GitError(`${dir} is not a clone of the export repository.`);
2107
2537
  const pulled = tryGit(dir, ["pull", "--ff-only", "--quiet"]) !== void 0;
2108
2538
  const head = git2(dir, ["rev-parse", "HEAD"]);
@@ -2170,21 +2600,21 @@ function mergedInto(repo, task, target) {
2170
2600
  // src/install.ts
2171
2601
  import { spawnSync } from "child_process";
2172
2602
  import {
2173
- existsSync as existsSync6,
2603
+ existsSync as existsSync7,
2174
2604
  lstatSync,
2175
- mkdirSync as mkdirSync2,
2176
- readFileSync as readFileSync5,
2605
+ mkdirSync as mkdirSync3,
2606
+ readFileSync as readFileSync6,
2177
2607
  readdirSync as readdirSync3,
2178
2608
  realpathSync,
2179
2609
  statSync,
2180
- writeFileSync as writeFileSync4
2610
+ writeFileSync as writeFileSync5
2181
2611
  } from "fs";
2182
- import { join as join6, relative } from "path";
2612
+ import { join as join7, relative } from "path";
2183
2613
  import { fileURLToPath } from "url";
2184
2614
 
2185
2615
  // ../src/install/installer.ts
2186
- import { existsSync as existsSync5, mkdirSync, readFileSync as readFileSync4, readdirSync as readdirSync2, rmSync as rmSync2, writeFileSync as writeFileSync3 } from "fs";
2187
- 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";
2188
2618
 
2189
2619
  // ../src/install/hash.ts
2190
2620
  import { createHash as createHash2 } from "crypto";
@@ -2193,18 +2623,18 @@ var sha256 = (content) => createHash2("sha256").update(content).digest("hex");
2193
2623
  // ../src/install/installer.ts
2194
2624
  var MANIFEST_PATH = ".alterspec/manifest.json";
2195
2625
  function readManifest(root, path = MANIFEST_PATH) {
2196
- const p = join5(root, path);
2197
- if (!existsSync5(p)) return void 0;
2626
+ const p = join6(root, path);
2627
+ if (!existsSync6(p)) return void 0;
2198
2628
  try {
2199
- return JSON.parse(readFileSync4(p, "utf8"));
2629
+ return JSON.parse(readFileSync5(p, "utf8"));
2200
2630
  } catch {
2201
2631
  return void 0;
2202
2632
  }
2203
2633
  }
2204
2634
  function write(root, path, content) {
2205
- const full = join5(root, path);
2206
- mkdirSync(dirname2(full), { recursive: true });
2207
- writeFileSync3(full, content);
2635
+ const full = join6(root, path);
2636
+ mkdirSync2(dirname3(full), { recursive: true });
2637
+ writeFileSync4(full, content);
2208
2638
  }
2209
2639
  function install(root, plan, opts) {
2210
2640
  const result = {
@@ -2221,9 +2651,9 @@ function install(root, plan, opts) {
2221
2651
  const previous = readManifest(root, manifestPath);
2222
2652
  const next = { version: opts.version, files: {} };
2223
2653
  for (const file of plan) {
2224
- const full = join5(root, file.path);
2654
+ const full = join6(root, file.path);
2225
2655
  const newHash = sha256(file.content);
2226
- if (!existsSync5(full)) {
2656
+ if (!existsSync6(full)) {
2227
2657
  write(root, file.path, file.content);
2228
2658
  result.created.push(file.path);
2229
2659
  if (file.policy !== "user") next.files[file.path] = newHash;
@@ -2233,7 +2663,7 @@ function install(root, plan, opts) {
2233
2663
  result.kept.push(file.path);
2234
2664
  continue;
2235
2665
  }
2236
- const diskHash = sha256(readFileSync4(full, "utf8"));
2666
+ const diskHash = sha256(readFileSync5(full, "utf8"));
2237
2667
  if (diskHash === newHash) {
2238
2668
  result.unchanged.push(file.path);
2239
2669
  next.files[file.path] = newHash;
@@ -2258,14 +2688,14 @@ function install(root, plan, opts) {
2258
2688
  const planned = new Set(plan.map((f) => f.path));
2259
2689
  for (const [path, hash] of Object.entries(previous.files)) {
2260
2690
  if (planned.has(path)) continue;
2261
- const full = join5(root, path);
2262
- if (!existsSync5(full)) continue;
2263
- if (sha256(readFileSync4(full, "utf8")) === hash) {
2264
- rmSync2(full);
2691
+ const full = join6(root, path);
2692
+ if (!existsSync6(full)) continue;
2693
+ if (sha256(readFileSync5(full, "utf8")) === hash) {
2694
+ rmSync3(full);
2265
2695
  result.removed.push(path);
2266
- const folder = dirname2(full);
2696
+ const folder = dirname3(full);
2267
2697
  if (emptiedFolder.test(folder) && readdirSync2(folder).length === 0)
2268
- rmSync2(folder, { recursive: true });
2698
+ rmSync3(folder, { recursive: true });
2269
2699
  } else {
2270
2700
  result.conflicts.push(path);
2271
2701
  }
@@ -2284,11 +2714,11 @@ var MCP_JSON = ".mcp.json";
2284
2714
  var MCP_SERVER = "dispatcher";
2285
2715
  var MCP_ENTRY = { command: "npx", args: ["@alterset/alterspec-client", "mcp"] };
2286
2716
  function walk(dir) {
2287
- 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)]);
2288
2718
  }
2289
- var assetFiles = (sub) => walk(join6(ASSETS_DIR, sub)).map((f) => ({
2290
- rel: relative(join6(ASSETS_DIR, sub), f).split("\\").join("/"),
2291
- 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")
2292
2722
  }));
2293
2723
  function buildClientPlan(version) {
2294
2724
  return [
@@ -2312,20 +2742,20 @@ function buildClientPlan(version) {
2312
2742
  ];
2313
2743
  }
2314
2744
  function writeMcpJson(root) {
2315
- const path = join6(root, MCP_JSON);
2745
+ const path = join7(root, MCP_JSON);
2316
2746
  let data = {};
2317
- const before = existsSync6(path) ? readFileSync5(path, "utf8") : void 0;
2318
- if (before !== void 0)
2747
+ const before2 = existsSync7(path) ? readFileSync6(path, "utf8") : void 0;
2748
+ if (before2 !== void 0)
2319
2749
  try {
2320
- data = JSON.parse(before);
2750
+ data = JSON.parse(before2);
2321
2751
  } catch {
2322
2752
  throw new ConfigError(`${path} is not valid JSON: fix it, then run init again.`);
2323
2753
  }
2324
2754
  data.mcpServers = { ...data.mcpServers ?? {}, [MCP_SERVER]: MCP_ENTRY };
2325
- const after = JSON.stringify(data, null, 2) + "\n";
2326
- if (after === before) return "unchanged";
2327
- writeFileSync4(path, after);
2328
- 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";
2329
2759
  }
2330
2760
  var CLAUDE_SETTINGS = ".claude/settings.json";
2331
2761
  var HOOK_COMMAND = "npx @alterset/alterspec-client progress --hook";
@@ -2338,12 +2768,12 @@ var HOOK_ENTRY = {
2338
2768
  };
2339
2769
  var isOurs = (h) => typeof h.command === "string" && h.command.includes("@alterset/alterspec-client progress");
2340
2770
  function writeClaudeSettings(root) {
2341
- const path = join6(root, CLAUDE_SETTINGS);
2342
- 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;
2343
2773
  let data = {};
2344
- if (before !== void 0)
2774
+ if (before2 !== void 0)
2345
2775
  try {
2346
- data = JSON.parse(before);
2776
+ data = JSON.parse(before2);
2347
2777
  } catch {
2348
2778
  throw new ConfigError(`${path} is not valid JSON: fix it, then run init again.`);
2349
2779
  }
@@ -2358,29 +2788,29 @@ function writeClaudeSettings(root) {
2358
2788
  return [HOOK_ENTRY];
2359
2789
  });
2360
2790
  if (!found) groups.push({ matcher: "Bash", hooks: [HOOK_ENTRY] });
2361
- const after = JSON.stringify(data, null, 2) + "\n";
2362
- if (before !== void 0 && JSON.stringify(JSON.parse(before)) === JSON.stringify(data)) return "unchanged";
2363
- mkdirSync2(join6(root, ".claude"), { recursive: true });
2364
- writeFileSync4(path, after);
2365
- 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";
2366
2796
  }
2367
2797
  var CLAUDE_LOCAL_SETTINGS = ".claude/settings.local.json";
2368
2798
  function writeLocalSettings(root) {
2369
- const path = join6(root, CLAUDE_LOCAL_SETTINGS);
2370
- 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;
2371
2801
  let data = {};
2372
- if (before !== void 0)
2802
+ if (before2 !== void 0)
2373
2803
  try {
2374
- data = JSON.parse(before);
2804
+ data = JSON.parse(before2);
2375
2805
  } catch {
2376
2806
  throw new ConfigError(`${path} is not valid JSON: fix it, then run init again.`);
2377
2807
  }
2378
2808
  const enabled = Array.isArray(data.enabledMcpjsonServers) ? data.enabledMcpjsonServers : [];
2379
- if (before !== void 0 && enabled.includes(MCP_SERVER)) return "unchanged";
2809
+ if (before2 !== void 0 && enabled.includes(MCP_SERVER)) return "unchanged";
2380
2810
  data.enabledMcpjsonServers = [...enabled, MCP_SERVER];
2381
- mkdirSync2(join6(root, ".claude"), { recursive: true });
2382
- writeFileSync4(path, JSON.stringify(data, null, 2) + "\n");
2383
- 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";
2384
2814
  }
2385
2815
  function approveHere(configRoot, cwd = process.cwd()) {
2386
2816
  const top = spawnSync("git", ["rev-parse", "--show-toplevel"], {
@@ -2396,10 +2826,10 @@ function approveHere(configRoot, cwd = process.cwd()) {
2396
2826
  }
2397
2827
  };
2398
2828
  if (!top || same(top, configRoot)) return { root: configRoot, outcome: "unchanged" };
2399
- if (!existsSync6(join6(top, MCP_JSON))) return { root: top, outcome: "unchanged" };
2400
- const claude = join6(top, ".claude");
2829
+ if (!existsSync7(join7(top, MCP_JSON))) return { root: top, outcome: "unchanged" };
2830
+ const claude = join7(top, ".claude");
2401
2831
  try {
2402
- if (lstatSync(claude).isSymbolicLink() && !existsSync6(claude)) return { root: top, outcome: "unchanged" };
2832
+ if (lstatSync(claude).isSymbolicLink() && !existsSync7(claude)) return { root: top, outcome: "unchanged" };
2403
2833
  } catch {
2404
2834
  }
2405
2835
  return { root: top, outcome: writeLocalSettings(top) };
@@ -2410,9 +2840,9 @@ function ignoreLocalSettings(root) {
2410
2840
  const status = git4("check-ignore", "-q", CLAUDE_LOCAL_SETTINGS);
2411
2841
  if (status === 0) return "ignored";
2412
2842
  if (status !== 1) return "unknown";
2413
- const path = join6(root, ".gitignore");
2414
- const before = existsSync6(path) ? readFileSync5(path, "utf8") : "";
2415
- 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}
2416
2846
  `);
2417
2847
  return "added";
2418
2848
  }
@@ -2427,8 +2857,8 @@ function initClient(root, opts, version) {
2427
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(", ")})` : ""}.`
2428
2858
  );
2429
2859
  }
2430
- const before = existing && JSON.stringify(existing);
2431
- 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";
2432
2862
  if (config !== "unchanged") writeConfig(root, parsed.data);
2433
2863
  const mcp = writeMcpJson(root);
2434
2864
  const hook = writeClaudeSettings(root);
@@ -2651,7 +3081,7 @@ function lookup(x, opts) {
2651
3081
  if (!isDoc(id)) return [{ id, ...a.title ? { title: a.title } : {}, at: pathOf(id), shards: [] }];
2652
3082
  const folder = `${shardDir(file)}/`;
2653
3083
  const kind = idKind(id);
2654
- const sections = (kind && READ[kind]) ?? [];
3084
+ const sections2 = (kind && READ[kind]) ?? [];
2655
3085
  return [
2656
3086
  {
2657
3087
  id,
@@ -2659,7 +3089,7 @@ function lookup(x, opts) {
2659
3089
  at: folder,
2660
3090
  shards: [
2661
3091
  FRONT_MATTER_SHARD,
2662
- ...sections.flatMap((h) => x.sectionShard(file, h)?.slice(folder.length) ?? [])
3092
+ ...sections2.flatMap((h) => x.sectionShard(file, h)?.slice(folder.length) ?? [])
2663
3093
  ]
2664
3094
  }
2665
3095
  ];
@@ -2691,8 +3121,8 @@ function lookup(x, opts) {
2691
3121
  must(last && x.proposalPath(last), `why ${id} is as it is (${last}, the last change of it)`);
2692
3122
  }
2693
3123
  must("_generated/open-items.md", "what the spec itself holds open");
2694
- const seen = new Set(resolved);
2695
- 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) => {
2696
3126
  const rank = (id) => (ORDER.indexOf(idKind(id)) + 1 || ORDER.length + 1) - 1;
2697
3127
  return rank(a.id) - rank(b.id);
2698
3128
  }).slice(0, NEIGHBOURS);
@@ -2763,11 +3193,11 @@ async function openDispatcher(session, open = openInBrowser) {
2763
3193
  }
2764
3194
 
2765
3195
  // src/progress.ts
2766
- import { execFileSync as execFileSync4 } from "child_process";
3196
+ import { execFileSync as execFileSync5 } from "child_process";
2767
3197
  import { createHash as createHash3 } from "crypto";
2768
- import { existsSync as existsSync7, mkdirSync as mkdirSync3, readFileSync as readFileSync6, writeFileSync as writeFileSync5 } from "fs";
2769
- import { join as join7 } from "path";
2770
- 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();
2771
3201
  function currentTask(repo) {
2772
3202
  try {
2773
3203
  const task = taskOfBranch(git3(repo, ["symbolic-ref", "--short", "HEAD"]));
@@ -2835,7 +3265,7 @@ function progressText(r) {
2835
3265
  }
2836
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).`;
2837
3267
  var THROTTLE_MS = 15 * 6e4;
2838
- var statePath = (repo, task) => join7(
3268
+ var statePath = (repo, task) => join8(
2839
3269
  git3(repo, ["rev-parse", "--path-format=absolute", "--git-common-dir"]),
2840
3270
  "alterspec-client",
2841
3271
  `progress-${folderOf(task)}.json`
@@ -2843,7 +3273,7 @@ var statePath = (repo, task) => join7(
2843
3273
  var hashOf = (covered) => createHash3("sha256").update(JSON.stringify(covered)).digest("hex").slice(0, 16);
2844
3274
  function readState(path) {
2845
3275
  try {
2846
- return existsSync7(path) ? JSON.parse(readFileSync6(path, "utf8")) : void 0;
3276
+ return existsSync8(path) ? JSON.parse(readFileSync7(path, "utf8")) : void 0;
2847
3277
  } catch {
2848
3278
  return void 0;
2849
3279
  }
@@ -2860,8 +3290,8 @@ async function progressHook(opts) {
2860
3290
  if (state?.reported === hash) return "unchanged";
2861
3291
  if (state && now() - Date.parse(state.at) < THROTTLE_MS) return "throttled";
2862
3292
  await reportProgress(opts.session(), task, covered);
2863
- mkdirSync3(join7(path, ".."), { recursive: true });
2864
- 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");
2865
3295
  return "reported";
2866
3296
  } catch {
2867
3297
  return "failed";
@@ -2889,9 +3319,9 @@ async function hookCwd(input, waitMs = 1e3) {
2889
3319
  }
2890
3320
 
2891
3321
  // src/version.ts
2892
- import { readFileSync as readFileSync7 } from "fs";
3322
+ import { readFileSync as readFileSync8 } from "fs";
2893
3323
  function packageVersion() {
2894
- 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"));
2895
3325
  return pkg.version;
2896
3326
  }
2897
3327
 
@@ -2936,7 +3366,7 @@ function approveWorktree(loaded) {
2936
3366
  const { root, outcome } = approveHere(loaded.root);
2937
3367
  if (outcome === "unchanged") return;
2938
3368
  process.stderr.write(
2939
- `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.
2940
3370
  `
2941
3371
  );
2942
3372
  }
@@ -3036,13 +3466,19 @@ program.command("context").description("print a task\u2019s brief, assembled fro
3036
3466
  task.id,
3037
3467
  ...(x.work.changes.find((c) => c.id === task.change)?.tasks ?? []).map((t) => `${task.change}/${t.track}`).filter((t) => t !== task.id)
3038
3468
  ];
3469
+ const pins = pinsDir(loaded.root, task);
3039
3470
  const ctx = taskContext(
3040
3471
  x,
3041
3472
  task,
3042
3473
  dir,
3043
3474
  await coveredState(loaded, task),
3044
- await changeQuestions(sessionOf(loaded), tasks)
3475
+ await changeQuestions(sessionOf(loaded), tasks),
3476
+ { pins, shown: readShown(process.cwd(), task) }
3045
3477
  );
3478
+ if (!opts.stats) {
3479
+ writePins(pins, pinFiles(x, ctx));
3480
+ writeShown(process.cwd(), task, shownOf(ctx));
3481
+ }
3046
3482
  process.stdout.write(
3047
3483
  opts.stats ? contextStats(renderContext(ctx)) : opts.json ? JSON.stringify(ctx, null, 2) + "\n" : renderContext(ctx)
3048
3484
  );