@alterset/alterspec-client 0.8.0 → 0.9.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.
@@ -9,8 +9,11 @@ or whose `Alterspec-Task` trailer the last commit carries; when that doesn't set
9
9
  1. Start as `_shared.md` says (`whoami`, `export-head`).
10
10
  2. Run `alterspec-client context <task>` and read the brief. It opens with the task's checklist: its items, what
11
11
  each is and which the dispatcher holds covered already; that is the work, and its progress. Then why the change
12
- was made, what changed, the delta of each of the task's objects (before and after) and where each is in the export
13
- now; for the backend the changed criteria on the checklist, the operations, and the rules and events those
12
+ was made, what changed, the one-time data change when the proposal declares one (what the release does once to the
13
+ records the product already holds; on the backend it is the `CHG-NNN#data-change` item), the delta of each of the
14
+ task's objects (before and after) and where each is in the export now, and "Where used": for each entity the task
15
+ changes, the screens, capabilities and rules of the export that show, take, return or guard it, per changed
16
+ attribute; for the backend the changed criteria on the checklist, the operations, and the rules and events those
14
17
  criteria or the change's text name, whole, and the capabilities' other criteria, rules and events by their shard
15
18
  paths only, to open when one bears on the work, and its entities by path; the decisions and glossary terms the
16
19
  change's text names, whole, the other decisions by path. Each hunk of a diff names the section it falls in. For a
@@ -169,7 +169,7 @@ server. Then talk to it in plain words; the skills do the rest.
169
169
  | You say or type | What happens |
170
170
  | ---------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
171
171
  | "give me work" / `/alterspec-task-next` | takes the next available task on your track and shows the brief; it creates no branch or worktree, you work wherever you like |
172
- | "let's work on my task" / `/alterspec-task-context` | the task's brief from the spec: why, the checklist, the objects it changes (before and after), the changed acceptance criteria, the rules, events, decisions and glossary terms they and the change name (the rest, and the entities, as paths); for a UI track also the screens, their contracts, mockups and design system |
172
+ | "let's work on my task" / `/alterspec-task-context` | the task's brief from the spec: why, the checklist, the one-time data change if any, the objects it changes (before and after) and where the export uses them, the changed acceptance criteria, the rules, events, decisions and glossary terms they and the change name (the rest, and the entities, as paths); for a UI track also the screens, their contracts, mockups and design system |
173
173
  | "what am I on?" / `/alterspec-task-status` | your tasks with progress and ETA, what's available on your tracks, what is blocked and by what |
174
174
  | "what does RULE-… say?" / `/alterspec-spec-ask` | answers about the product from the spec, citing IDs; reads only |
175
175
  | `/alterspec-task-done CHG-023/BE` | after your branch is merged: reports the task done with the commit that brought it in; refused while the work isn't merged |
package/dist/cli.js CHANGED
@@ -28,7 +28,8 @@ var WorkTaskSchema = z.object({
28
28
  /**
29
29
  * The task's checklist, derived from the delta: the acceptance criteria (`<CAP>-AC-NN`), screen actions
30
30
  * (`<SCR>.Ann`) and contract states (`<UX-SCR>#<state>`) the change adds or changes, and every other object as
31
- * its key. Sorted, never empty.
31
+ * its key; on `BE`, `<CHG>#data-change` when the proposal declares a one-time data change (alterspec 0.27.0).
32
+ * Sorted, never empty.
32
33
  */
33
34
  items: z.array(z.string().min(1)).min(1),
34
35
  /** The tasks this one waits for, resolved: the same change's `BE` task, and the track's tasks it builds on. */
@@ -552,6 +553,7 @@ var mockupPath = (code, screenId) => `${surfaceDir(code)}/mockups/${screenId}.ht
552
553
  var patternsPath = (code) => `${surfaceDir(code)}/patterns.md`;
553
554
  var designSystemPath = (code) => `${surfaceDir(code)}/design-system.md`;
554
555
  var OPERATIONS_FILE = "_generated/operations.md";
556
+ var INDEX_FILE = "_generated/index.json";
555
557
  var changesDir = (mod) => mod ? `${moduleDir(mod)}/${CHANGES_DIR}` : CHANGES_DIR;
556
558
  var archiveDir = (mod) => `${changesDir(mod)}/archive`;
557
559
  var CHANGE_PREFIX = String.raw`^(?:${MODULES_DIR}\/[^/]+\/)?${CHANGES_DIR}\/`;
@@ -601,6 +603,14 @@ function readExport(dir) {
601
603
  const folder = shardDir(file);
602
604
  return has(folder) ? readdirSync(join3(dir, folder)).sort().map((n) => `${folder}/${n}`) : [];
603
605
  };
606
+ let indexCache = null;
607
+ const index = () => {
608
+ if (indexCache === null) {
609
+ const text = read(INDEX_FILE);
610
+ indexCache = text ? JSON.parse(text) : void 0;
611
+ }
612
+ return indexCache;
613
+ };
604
614
  const proposalPath = (change) => [archiveDir(), ...modules().map((m) => `${m}/changes/archive`)].map((a) => `${a}/${change}/proposal.md`).find(has);
605
615
  return {
606
616
  dir,
@@ -627,7 +637,8 @@ function readExport(dir) {
627
637
  itemShard(file, key) {
628
638
  const path = itemShardPath(file, key);
629
639
  return has(path) ? path : void 0;
630
- }
640
+ },
641
+ index
631
642
  };
632
643
  }
633
644
  function idsIn(text, kinds) {
@@ -642,6 +653,15 @@ function idsIn(text, kinds) {
642
653
  }
643
654
  var frontMatterOf = (text) => splitFrontMatter(text).raw ?? "";
644
655
 
656
+ // ../src/changes/data-change.ts
657
+ var DATA_CHANGE_SECTION = "One-time data change";
658
+ var DATA_CHANGE_ITEM = "data-change";
659
+ var DATA_CHANGE_RE = new RegExp(`^(CHG-\\d{3,})#${DATA_CHANGE_ITEM}$`);
660
+ function dataChangeText(sectionText2) {
661
+ const text = sectionText2?.trim();
662
+ return text && !/^none\b/i.test(text) ? text : void 0;
663
+ }
664
+
645
665
  // ../src/lib/diff.ts
646
666
  var linesOf = (text) => text === "" ? [] : text.replace(/\n$/, "").split("\n");
647
667
  function diffLines(a, b) {
@@ -889,6 +909,8 @@ function itemWhat(x, item, entry, track) {
889
909
  return `${what2}: \`${path}\`${x.has(path) ? "" : " (not in the export now)"}`;
890
910
  }
891
911
  if (item.startsWith("term:")) return `glossary term "${item.slice(5)}"`;
912
+ if (DATA_CHANGE_RE.test(item))
913
+ return `the one-time change to the records the product already holds (the proposal's "${DATA_CHANGE_SECTION}", below)`;
892
914
  const kind = idKind(item);
893
915
  const what = `${kind && KIND_WORDS[kind] ? `${KIND_WORDS[kind]} ` : ""}${named(x, item)}`;
894
916
  if (!entry) return what;
@@ -897,6 +919,60 @@ function itemWhat(x, item, entry, track) {
897
919
  const line = firstAdded(item, entry);
898
920
  return line ? `${what}, modified: "${line}"` : `${what}, modified (see its delta)`;
899
921
  }
922
+ function dataChangeOf(text) {
923
+ const t = dataChangeText(text);
924
+ return t ? { dataChange: t } : {};
925
+ }
926
+ function changedAttributes(entry) {
927
+ if (!entry || !entry.exported.before || !entry.exported.after) return void 0;
928
+ if (entry.before === void 0 || entry.after === void 0) return void 0;
929
+ const names = (raw) => new Map([...raw.matchAll(/^ {2}- name: (.+?)\s*$/gm)].map((m) => [m[1], m.index]));
930
+ const before = splitFrontMatter(entry.before).raw ?? "";
931
+ const after = splitFrontMatter(entry.after).raw ?? "";
932
+ const attr = (raw, from) => {
933
+ const chunk = raw.slice(from).split(/\n(?! {4})/)[0] ?? "";
934
+ return chunk.replace(/^\s*- name: .*\n?/, "");
935
+ };
936
+ const b = names(before);
937
+ const a = names(after);
938
+ const out = /* @__PURE__ */ new Set();
939
+ for (const [n, i] of a) if (!b.has(n) || attr(before, b.get(n)) !== attr(after, i)) out.add(n);
940
+ for (const n of b.keys()) if (!a.has(n)) out.add(n);
941
+ return [...out];
942
+ }
943
+ function whereUsed(x, objects, entries, changed) {
944
+ const index = x.index();
945
+ if (!index) return [];
946
+ const piece = (id, title, file) => ({
947
+ id,
948
+ path: file ?? "",
949
+ title,
950
+ ...changed.has(id) ? { changed: true } : {}
951
+ });
952
+ const out = [];
953
+ for (const entity of objects.filter((k) => idKind(k) === "entity")) {
954
+ const attributes = changedAttributes(entries.get(entity)) ?? [];
955
+ for (const attribute of attributes)
956
+ out.push({
957
+ entity,
958
+ attribute,
959
+ screens: index.screens.filter((s) => s.fields.some((f) => f.entity === entity && f.attributes.includes(attribute))).map((s) => piece(s.id, s.title, x.fileOf(s.id))),
960
+ capabilities: index.capabilities.filter(
961
+ (c) => [...c.inputs ?? [], ...c.outputs ?? []].some(
962
+ (d) => "entity" in d && d.entity === entity && d.attributes.includes(attribute)
963
+ )
964
+ ).map((c) => piece(c.id, c.title, x.fileOf(c.id))),
965
+ rules: []
966
+ });
967
+ out.push({
968
+ entity,
969
+ screens: index.screens.filter((s) => s.fields.some((f) => f.entity === entity)).map((s) => piece(s.id, s.title, x.fileOf(s.id))),
970
+ capabilities: index.capabilities.filter((c) => c.entities.some((e) => e.entity === entity)).map((c) => piece(c.id, c.title, x.fileOf(c.id))),
971
+ rules: index.rules.filter((r) => r.entities.includes(entity) || (r.guards ?? []).some((g) => g.entity === entity)).map((r) => piece(r.id, r.title, x.fileOf(r.id)))
972
+ });
973
+ }
974
+ return out;
975
+ }
900
976
  function taskContext(x, task, exportDir2, state = {}) {
901
977
  const change = x.work.changes.find((c) => c.id === task.change);
902
978
  if (!change) throw new ContextError(`${task.change} is not in this export's work.json: pull the export.`);
@@ -941,7 +1017,8 @@ function taskContext(x, task, exportDir2, state = {}) {
941
1017
  proposal: {
942
1018
  path: proposal,
943
1019
  why: sectionText(x, x.sectionShard(proposal, "Why")),
944
- what: sectionText(x, x.sectionShard(proposal, "What changes"))
1020
+ what: sectionText(x, x.sectionShard(proposal, "What changes")),
1021
+ ...dataChangeOf(sectionText(x, x.sectionShard(proposal, DATA_CHANGE_SECTION)))
945
1022
  },
946
1023
  ...delta ? { delta: proposal.replace(/proposal\.md$/, "delta.md") } : {},
947
1024
  objects: work.objects.map((key) => objectBrief(x, key, entries.get(key), lost.get(key)))
@@ -969,6 +1046,7 @@ function taskContext(x, task, exportDir2, state = {}) {
969
1046
  }
970
1047
  ];
971
1048
  };
1049
+ ctx.whereUsed = whereUsed(x, work.objects, entries, changed);
972
1050
  const capabilities = work.objects.filter((k) => /^CAP-/.test(k) && x.fileOf(k) && x.has(x.fileOf(k)));
973
1051
  const onList = items && new Set(items);
974
1052
  ctx.acceptance = capabilities.flatMap((id) => {
@@ -1093,6 +1171,15 @@ function renderContext(c) {
1093
1171
  }
1094
1172
  out.push("", `## Why (${c.proposal.path})`, "", c.proposal.why || "(none written)");
1095
1173
  out.push("", "## What changes", "", c.proposal.what || "(none written)");
1174
+ if (c.proposal.dataChange)
1175
+ out.push(
1176
+ "",
1177
+ `## ${DATA_CHANGE_SECTION}`,
1178
+ "",
1179
+ c.track.kind === "backend" ? "What the release does once to the records the product already holds; the backend\u2019s `#data-change` item on the checklist." : "What the release does once to the records the product already holds; the backend\u2019s work, here so the screens read it.",
1180
+ "",
1181
+ c.proposal.dataChange
1182
+ );
1096
1183
  out.push("", "## The task\u2019s objects", "");
1097
1184
  if (c.delta) out.push(`The whole record of the change: ${c.delta}.`, "");
1098
1185
  for (const o of c.objects) {
@@ -1103,6 +1190,32 @@ function renderContext(c) {
1103
1190
  if (o.diff) out.push("", o.diff.startsWith("@@") ? fence(o.diff, "diff") : o.diff);
1104
1191
  out.push("");
1105
1192
  }
1193
+ if (c.whereUsed?.length) {
1194
+ out.push(
1195
+ "## Where used",
1196
+ "",
1197
+ "What the export shows, takes, returns or guards of the entities this task changes, per changed attribute and for the entity as a whole; a screen or capability not in the export isn\u2019t listed.",
1198
+ ""
1199
+ );
1200
+ const list2 = (ps) => ps.map((p) => `${p.id}${p.changed ? " (this task changes it)" : ""}`).join(", ");
1201
+ for (const w of c.whereUsed) {
1202
+ if (w.attribute) {
1203
+ const parts = [
1204
+ w.screens.length ? `shown on ${list2(w.screens)}` : "no screen shows it",
1205
+ w.capabilities.length ? `taken or returned by ${list2(w.capabilities)}` : "no capability takes or returns it"
1206
+ ];
1207
+ out.push(`- ${w.entity}.${w.attribute}: ${parts.join("; ")}.`);
1208
+ } else {
1209
+ const parts = [
1210
+ w.screens.length ? `shown on ${list2(w.screens)}` : "no screen shows it",
1211
+ w.capabilities.length ? `worked with by ${list2(w.capabilities)}` : "no capability works with it",
1212
+ w.rules.length ? `rules about it: ${list2(w.rules)}` : "no rule about it"
1213
+ ];
1214
+ out.push(`- ${w.entity}: ${parts.join("; ")}.`);
1215
+ }
1216
+ }
1217
+ out.push("");
1218
+ }
1106
1219
  const pieces = (title, list2, intro) => {
1107
1220
  if (!list2?.length) return;
1108
1221
  out.push(`## ${title}`, "");