operbe 0.0.0-stage → 1.0.0-rc.2

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.
Files changed (165) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +106 -2
  3. package/conformance/describe/edge/body.json +1 -0
  4. package/conformance/describe/edge/digest +1 -0
  5. package/conformance/describe/edge/project/acme/architecture.md +18 -0
  6. package/conformance/describe/edge/project/behaviors/B-7.md +15 -0
  7. package/conformance/describe/edge/project/behaviors/coverage/web.md +8 -0
  8. package/conformance/describe/edge/project/operations/broken-file.md +1 -0
  9. package/conformance/describe/edge/project/operations/read-note.md +4 -0
  10. package/conformance/describe/edge/project/operations/send-note.md +20 -0
  11. package/conformance/describe/edge/project/operbe.md +15 -0
  12. package/conformance/describe/example/body.json +1 -0
  13. package/conformance/describe/example/digest +1 -0
  14. package/conformance/describe/example/project/behaviors/B-0001.md +36 -0
  15. package/conformance/describe/example/project/behaviors/B-0002.md +21 -0
  16. package/conformance/describe/example/project/behaviors/B-0003.md +19 -0
  17. package/conformance/describe/example/project/behaviors/B-0004.md +18 -0
  18. package/conformance/describe/example/project/behaviors/B-0005.md +18 -0
  19. package/conformance/describe/example/project/behaviors/coverage/desktop.md +8 -0
  20. package/conformance/describe/example/project/behaviors/coverage/phone.md +12 -0
  21. package/conformance/describe/example/project/client-actions/archive-conversation.md +22 -0
  22. package/conformance/describe/example/project/client-actions/show-conversations.md +21 -0
  23. package/conformance/describe/example/project/client-actions/start-retitle.md +22 -0
  24. package/conformance/describe/example/project/client-actions/unarchive-conversation.md +21 -0
  25. package/conformance/describe/example/project/operations/archive-conversation.md +16 -0
  26. package/conformance/describe/example/project/operations/list-conversations.md +16 -0
  27. package/conformance/describe/example/project/operations/set-conversation-title.md +16 -0
  28. package/conformance/describe/example/project/operations/unarchive-conversation.md +16 -0
  29. package/conformance/describe/example/project/operbe.md +15 -0
  30. package/conformance/diff/core/a/behaviors/B-0001.md +36 -0
  31. package/conformance/diff/core/a/behaviors/B-0002.md +21 -0
  32. package/conformance/diff/core/a/behaviors/B-0003.md +19 -0
  33. package/conformance/diff/core/a/behaviors/B-0004.md +18 -0
  34. package/conformance/diff/core/a/behaviors/B-0005.md +18 -0
  35. package/conformance/diff/core/a/behaviors/coverage/desktop.md +8 -0
  36. package/conformance/diff/core/a/behaviors/coverage/phone.md +12 -0
  37. package/conformance/diff/core/a/client-actions/archive-conversation.md +22 -0
  38. package/conformance/diff/core/a/client-actions/show-conversations.md +21 -0
  39. package/conformance/diff/core/a/client-actions/start-retitle.md +22 -0
  40. package/conformance/diff/core/a/client-actions/unarchive-conversation.md +21 -0
  41. package/conformance/diff/core/a/operations/archive-conversation.md +16 -0
  42. package/conformance/diff/core/a/operations/list-conversations.md +16 -0
  43. package/conformance/diff/core/a/operations/set-conversation-title.md +16 -0
  44. package/conformance/diff/core/a/operations/unarchive-conversation.md +16 -0
  45. package/conformance/diff/core/a/operbe.md +15 -0
  46. package/conformance/diff/core/b/behaviors/B-0001.md +36 -0
  47. package/conformance/diff/core/b/behaviors/B-0002.md +22 -0
  48. package/conformance/diff/core/b/behaviors/B-0003.md +19 -0
  49. package/conformance/diff/core/b/behaviors/B-0004.md +18 -0
  50. package/conformance/diff/core/b/behaviors/B-0005.md +18 -0
  51. package/conformance/diff/core/b/behaviors/coverage/desktop.md +8 -0
  52. package/conformance/diff/core/b/behaviors/coverage/phone.md +12 -0
  53. package/conformance/diff/core/b/client-actions/archive-conversation.md +22 -0
  54. package/conformance/diff/core/b/client-actions/show-conversations.md +21 -0
  55. package/conformance/diff/core/b/client-actions/unarchive-conversation.md +21 -0
  56. package/conformance/diff/core/b/operations/archive-conversation.md +16 -0
  57. package/conformance/diff/core/b/operations/list-conversations.md +16 -0
  58. package/conformance/diff/core/b/operations/set-conversation-name.md +16 -0
  59. package/conformance/diff/core/b/operations/unarchive-conversation.md +16 -0
  60. package/conformance/diff/core/b/operbe.md +16 -0
  61. package/conformance/diff/core/changes.json +192 -0
  62. package/conformance/diff/declared/a/acme/architecture.md +18 -0
  63. package/conformance/diff/declared/a/behaviors/B-7.md +15 -0
  64. package/conformance/diff/declared/a/behaviors/coverage/web.md +8 -0
  65. package/conformance/diff/declared/a/operations/broken-file.md +1 -0
  66. package/conformance/diff/declared/a/operations/read-note.md +4 -0
  67. package/conformance/diff/declared/a/operations/send-note.md +20 -0
  68. package/conformance/diff/declared/a/operbe.md +15 -0
  69. package/conformance/diff/declared/b/acme/architecture.md +18 -0
  70. package/conformance/diff/declared/b/behaviors/B-7.md +15 -0
  71. package/conformance/diff/declared/b/behaviors/coverage/web.md +8 -0
  72. package/conformance/diff/declared/b/operations/broken-file.md +1 -0
  73. package/conformance/diff/declared/b/operations/read-note.md +5 -0
  74. package/conformance/diff/declared/b/operations/send-note.md +19 -0
  75. package/conformance/diff/declared/b/operbe.md +15 -0
  76. package/conformance/diff/declared/changes.json +73 -0
  77. package/conformance/diff/reworded/a/behaviors/B-0001.md +36 -0
  78. package/conformance/diff/reworded/a/behaviors/B-0002.md +21 -0
  79. package/conformance/diff/reworded/a/behaviors/B-0003.md +19 -0
  80. package/conformance/diff/reworded/a/behaviors/B-0004.md +18 -0
  81. package/conformance/diff/reworded/a/behaviors/B-0005.md +18 -0
  82. package/conformance/diff/reworded/a/behaviors/coverage/desktop.md +8 -0
  83. package/conformance/diff/reworded/a/behaviors/coverage/phone.md +12 -0
  84. package/conformance/diff/reworded/a/client-actions/archive-conversation.md +22 -0
  85. package/conformance/diff/reworded/a/client-actions/show-conversations.md +21 -0
  86. package/conformance/diff/reworded/a/client-actions/start-retitle.md +22 -0
  87. package/conformance/diff/reworded/a/client-actions/unarchive-conversation.md +21 -0
  88. package/conformance/diff/reworded/a/operations/archive-conversation.md +16 -0
  89. package/conformance/diff/reworded/a/operations/list-conversations.md +16 -0
  90. package/conformance/diff/reworded/a/operations/set-conversation-title.md +16 -0
  91. package/conformance/diff/reworded/a/operations/unarchive-conversation.md +16 -0
  92. package/conformance/diff/reworded/a/operbe.md +18 -0
  93. package/conformance/diff/reworded/b/behaviors/B-0001.md +36 -0
  94. package/conformance/diff/reworded/b/behaviors/B-0002.md +21 -0
  95. package/conformance/diff/reworded/b/behaviors/B-0003.md +19 -0
  96. package/conformance/diff/reworded/b/behaviors/B-0004.md +18 -0
  97. package/conformance/diff/reworded/b/behaviors/B-0005.md +18 -0
  98. package/conformance/diff/reworded/b/behaviors/coverage/desktop.md +8 -0
  99. package/conformance/diff/reworded/b/behaviors/coverage/phone.md +12 -0
  100. package/conformance/diff/reworded/b/client-actions/archive-conversation.md +22 -0
  101. package/conformance/diff/reworded/b/client-actions/show-conversations.md +21 -0
  102. package/conformance/diff/reworded/b/client-actions/start-retitle.md +22 -0
  103. package/conformance/diff/reworded/b/client-actions/unarchive-conversation.md +21 -0
  104. package/conformance/diff/reworded/b/operations/archive-conversation.md +16 -0
  105. package/conformance/diff/reworded/b/operations/list-conversations.md +16 -0
  106. package/conformance/diff/reworded/b/operations/set-conversation-title.md +16 -0
  107. package/conformance/diff/reworded/b/operations/unarchive-conversation.md +16 -0
  108. package/conformance/diff/reworded/b/operbe.md +18 -0
  109. package/conformance/diff/reworded/changes.json +43 -0
  110. package/dist/check.d.ts +21 -0
  111. package/dist/check.js +422 -0
  112. package/dist/cli.d.ts +2 -0
  113. package/dist/cli.js +272 -0
  114. package/dist/describe.d.ts +22 -0
  115. package/dist/describe.js +201 -0
  116. package/dist/diff.d.ts +13 -0
  117. package/dist/diff.js +249 -0
  118. package/dist/findings.d.ts +11 -0
  119. package/dist/findings.js +6 -0
  120. package/dist/index.d.ts +19 -0
  121. package/dist/index.js +11 -0
  122. package/dist/indexes.d.ts +2 -0
  123. package/dist/indexes.js +27 -0
  124. package/dist/jcs.d.ts +1 -0
  125. package/dist/jcs.js +16 -0
  126. package/dist/jj.d.ts +12 -0
  127. package/dist/jj.js +82 -0
  128. package/dist/read.d.ts +83 -0
  129. package/dist/read.js +249 -0
  130. package/dist/reconcile.d.ts +9 -0
  131. package/dist/reconcile.js +46 -0
  132. package/dist/source.d.ts +5 -0
  133. package/dist/source.js +29 -0
  134. package/dist/version.d.ts +1 -0
  135. package/dist/version.js +2 -0
  136. package/package.json +40 -4
  137. package/schema/description.schema.json +481 -0
  138. package/skills/operbe/SKILL.md +69 -0
  139. package/skills/operbe/example/behaviors/B-0001.md +36 -0
  140. package/skills/operbe/example/behaviors/B-0002.md +21 -0
  141. package/skills/operbe/example/behaviors/B-0003.md +19 -0
  142. package/skills/operbe/example/behaviors/B-0004.md +18 -0
  143. package/skills/operbe/example/behaviors/B-0005.md +18 -0
  144. package/skills/operbe/example/behaviors/coverage/desktop.md +8 -0
  145. package/skills/operbe/example/behaviors/coverage/phone.md +12 -0
  146. package/skills/operbe/example/client-actions/archive-conversation.md +22 -0
  147. package/skills/operbe/example/client-actions/show-conversations.md +21 -0
  148. package/skills/operbe/example/client-actions/start-retitle.md +22 -0
  149. package/skills/operbe/example/client-actions/unarchive-conversation.md +21 -0
  150. package/skills/operbe/example/operations/archive-conversation.md +16 -0
  151. package/skills/operbe/example/operations/list-conversations.md +16 -0
  152. package/skills/operbe/example/operations/set-conversation-title.md +16 -0
  153. package/skills/operbe/example/operations/unarchive-conversation.md +16 -0
  154. package/skills/operbe/example/operbe.md +15 -0
  155. package/skills/operbe/references/adopting.md +48 -0
  156. package/skills/operbe/references/behaviors.md +168 -0
  157. package/skills/operbe/references/client-actions.md +211 -0
  158. package/skills/operbe/references/formats.md +408 -0
  159. package/skills/operbe/references/operations.md +146 -0
  160. package/skills/operbe/references/tandem.md +69 -0
  161. package/skills/operbe/templates/behavior.md +18 -0
  162. package/skills/operbe/templates/client-action.md +20 -0
  163. package/skills/operbe/templates/coverage.md +4 -0
  164. package/skills/operbe/templates/operation.md +14 -0
  165. package/skills/operbe/templates/operbe.md +10 -0
package/dist/diff.js ADDED
@@ -0,0 +1,249 @@
1
+ import { jcs } from "./jcs.js";
2
+ // Compared as JCS bytes, so key order (another tool, another language) never makes a change.
3
+ const same = (x, y) => jcs(x) === jcs(y);
4
+ // A value by a key from the description: own properties only, so `constructor` is just a name.
5
+ const own = (o, k) => (o && Object.hasOwn(o, k) ? o[k] : undefined);
6
+ const LEVELS = ["info", "warning", "breaking"];
7
+ const show = (v) => (v === undefined ? "nothing" : Array.isArray(v) ? `[${v.join(", ")}]` : String(v));
8
+ const RISK = ["reads", "changes", "changes-rights", "destroys"];
9
+ // Coverage, best first. No row at all is worse than every value.
10
+ const COVER = ["honours", "limited", "differs", "not-here"];
11
+ const coverRank = (v) => (v === undefined ? COVER.length : COVER.indexOf(v) < 0 ? COVER.length : COVER.indexOf(v));
12
+ // The level of a change to one of operbe's own header fields, before -> after.
13
+ function coreLevel(what, field, before, after) {
14
+ if (what === "operation")
15
+ switch (field) {
16
+ case "safe-to-repeat": return before === "yes" ? "breaking" : "info"; // callers may have retried it
17
+ case "risk": { // no risk, or one operbe doesn't know, claims nothing
18
+ const x = RISK.indexOf(before), y = RISK.indexOf(after);
19
+ return y < 0 ? "warning" : x < 0 ? (y === 0 ? "info" : "warning") : y > x ? "breaking" : "info";
20
+ }
21
+ case "needs":
22
+ case "taken-back-by":
23
+ case "many-at-once": return "warning";
24
+ default: return "info";
25
+ }
26
+ if (what === "client-action")
27
+ switch (field) {
28
+ case "class": return "breaking"; // a show may now send a change
29
+ case "operations":
30
+ case "available-when":
31
+ case "behaviors": return "warning";
32
+ default: return "info";
33
+ }
34
+ if (field === "applies-to" || field === "operations")
35
+ return "warning"; // a UI may no longer owe it; what it sends changed
36
+ return "info";
37
+ }
38
+ export function diff(a, b) {
39
+ if (a.format !== b.format)
40
+ throw new TypeError(`diff: can't compare ${a.format} with ${b.format}`);
41
+ const out = [];
42
+ const add = (c) => out.push(c);
43
+ const A = a.body, B = b.body;
44
+ // Declared diff rules, from the old side only: field \0 change -> level.
45
+ const rulesOf = (side) => {
46
+ const m = new Map();
47
+ for (const decl of Object.values(side.architectures ?? {}))
48
+ for (const r of decl["diff-rules"] ?? [])
49
+ m.set(`${r.field}\0${r.change}`, r.level);
50
+ return m;
51
+ };
52
+ const rules = rulesOf(A);
53
+ // ext.<arch>.<rest> back to the written field name.
54
+ const extFields = (r) => {
55
+ const m = new Map();
56
+ for (const [arch, fs] of Object.entries(r?.ext ?? {}))
57
+ for (const [k, v] of Object.entries(fs))
58
+ m.set(`${arch}.${k}`, v);
59
+ return m;
60
+ };
61
+ // One kind of record, keyed by name: added, removed, and every field and section changed.
62
+ function records(what, ra, rb) {
63
+ for (const name of [...new Set([...Object.keys(ra), ...Object.keys(rb)])].sort()) {
64
+ const x = own(ra, name), y = own(rb, name);
65
+ const rough = x?.status === "rough"; // the old side: what was built against it
66
+ const lvl = (l) => (rough ? "info" : l);
67
+ if (!x) {
68
+ add({ kind: `${what}.added`, record: name, level: "info", message: `${what} '${name}' was added` });
69
+ continue;
70
+ }
71
+ if (!y) {
72
+ // A rename is a removal plus an addition: names are identities across the boundary.
73
+ const l = what === "behavior" ? "warning" : "breaking";
74
+ add({ kind: `${what}.removed`, record: name, level: lvl(l), message: `${what} '${name}' was removed${what === "behavior" ? " (retire it instead: ids are never reused)" : ""}` });
75
+ continue;
76
+ }
77
+ // Core header fields.
78
+ const core = new Set([...Object.keys(x), ...Object.keys(y)].filter((k) => !["sections", "ext", "effect"].includes(k)));
79
+ for (const f of [...core].sort()) {
80
+ if (same(x[f], y[f]))
81
+ continue;
82
+ if (what === "operation" && f === "class")
83
+ continue; // reported as the effect, below
84
+ let kind = `${what}.field-changed`, l = coreLevel(what, f, x[f], y[f]);
85
+ if (f === "status" && y[f] === "retired") {
86
+ kind = `${what}.retired`;
87
+ l = what === "behavior" ? "info" : "warning";
88
+ }
89
+ if (f === "status" && x[f] === "firm" && y[f] === "rough") {
90
+ kind = `${what}.demoted`;
91
+ l = "warning";
92
+ } // UIs built it as firm
93
+ if (f === "form" && Number(y[f]) > Number(x[f])) {
94
+ kind = `${what}.form-up`;
95
+ l = "warning";
96
+ } // UIs built against the old form are stale
97
+ add({ kind, record: name, field: f, before: x[f], after: y[f], level: lvl(l), message: `${show(x[f])} -> ${show(y[f])}` });
98
+ }
99
+ // M3: a class change that changes the effect, with before and after, always breaking.
100
+ if (what === "operation" && x.class !== y.class) {
101
+ if (x.effect !== y.effect)
102
+ add({ kind: "operation.effect-changed", record: name, field: "effect", before: x.effect, after: y.effect, level: "breaking", message: `class ${show(x.class)} -> ${show(y.class)}: its effect was ${show(x.effect)} and is now ${show(y.effect)}` });
103
+ else
104
+ add({ kind: "operation.field-changed", record: name, field: "class", before: x.class, after: y.class, level: "warning", message: `${show(x.class)} -> ${show(y.class)}` });
105
+ }
106
+ // Sections, by title. A changed precondition is worth a look; other wording is info.
107
+ const sec = (r) => new Map((r.sections ?? []).map((s) => [s.title, s.text]));
108
+ const sx = sec(x), sy = sec(y);
109
+ for (const t of [...new Set([...sx.keys(), ...sy.keys()])].sort()) {
110
+ if (sx.get(t) === sy.get(t))
111
+ continue;
112
+ const l = what === "operation" && t === "Holds only if" ? "warning" : "info";
113
+ add({ kind: `${what}.section-changed`, record: name, field: `section:${t}`, before: sx.get(t), after: sy.get(t), level: lvl(l), message: `section '${t}' ${!sx.has(t) ? "was added" : !sy.has(t) ? "was removed" : "changed"}` });
114
+ }
115
+ // Architecture fields: ranked by the declared rules.
116
+ const ex = extFields(x), ey = extFields(y);
117
+ for (const f of [...new Set([...ex.keys(), ...ey.keys()])].sort()) {
118
+ const before = ex.get(f), after = ey.get(f);
119
+ if (same(before, after))
120
+ continue;
121
+ const change = before === undefined ? "added" : after === undefined ? "removed" : "changed";
122
+ const ruled = rules.get(`${f}\0${change}`);
123
+ add({
124
+ kind: ruled ? `${what}.field-${change}` : `${what}.field-unclassified`, record: name, field: f, before, after,
125
+ level: lvl(ruled ?? "info"),
126
+ message: `${change}: ${show(before)} -> ${show(after)}${ruled ? "" : " (no diff rule covers it)"}`,
127
+ });
128
+ }
129
+ }
130
+ }
131
+ records("operation", A.operations ?? {}, B.operations ?? {});
132
+ records("behavior", A.behaviors ?? {}, B.behaviors ?? {});
133
+ records("client-action", A["client-actions"] ?? {}, B["client-actions"] ?? {});
134
+ // Coverage: per UI and id. Worse (a lower value, or the row gone) is a warning, unless the record is rough.
135
+ const rec = (S, id) => own(S.behaviors, id) ?? own(S["client-actions"], id);
136
+ for (const ui of [...new Set([...Object.keys(A.coverage ?? {}), ...Object.keys(B.coverage ?? {})])].sort()) {
137
+ const ca = own(A.coverage, ui) ?? {}, cb = own(B.coverage, ui) ?? {};
138
+ for (const id of [...new Set([...Object.keys(ca), ...Object.keys(cb)])].sort()) {
139
+ const ra = own(ca, id), rb = own(cb, id), x = ra?.value, y = rb?.value;
140
+ if (same(ra, rb))
141
+ continue;
142
+ const worse = coverRank(y) > coverRank(x), better = coverRank(y) < coverRank(x);
143
+ const gone = y === undefined && !rec(B, id); // the record itself left
144
+ const rough = rec(A, id)?.status === "rough";
145
+ add({
146
+ kind: worse ? "coverage.worse" : better ? "coverage.better" : "coverage.changed", record: id, field: ui, before: ra, after: rb,
147
+ level: worse && !rough && !gone ? "warning" : "info",
148
+ message: `${x ?? "no row"} -> ${y ?? "no row"}`,
149
+ });
150
+ }
151
+ }
152
+ // The profile: its UIs, its known deviations, and every other field and section.
153
+ const P = A.profile ?? {}, Q = B.profile ?? {};
154
+ for (const f of [...new Set([...Object.keys(P), ...Object.keys(Q)])].filter((k) => !["uis", "sections", "ext"].includes(k)).sort())
155
+ if (!same(own(P, f), own(Q, f)))
156
+ add({ kind: "profile.field-changed", record: "profile", field: f, before: own(P, f), after: own(Q, f), level: "info", message: `${show(own(P, f))} -> ${show(own(Q, f))}` });
157
+ for (const ui of P.uis ?? [])
158
+ if (!(Q.uis ?? []).includes(ui))
159
+ add({ kind: "profile.ui-removed", record: "profile", field: ui, level: "warning", message: `UI '${ui}' was removed` });
160
+ for (const ui of Q.uis ?? [])
161
+ if (!(P.uis ?? []).includes(ui))
162
+ add({ kind: "profile.ui-added", record: "profile", field: ui, level: "info", message: `UI '${ui}' was added` });
163
+ const pe = extFields(P), qe = extFields(Q);
164
+ for (const f of [...new Set([...pe.keys(), ...qe.keys()])].sort())
165
+ if (!same(pe.get(f), qe.get(f)))
166
+ add({ kind: "profile.field-changed", record: "profile", field: f, before: pe.get(f), after: qe.get(f), level: "info", message: `${show(pe.get(f))} -> ${show(qe.get(f))}` });
167
+ // Known deviations: the list may only shrink. A deviation is one bullet with its continuation
168
+ // lines, matched across the two sides by its key (formats.md, "Known deviations"): the backticked
169
+ // name it starts with, numbered when several start with the same name (`foo`, `foo` #2), or its
170
+ // whole text when it has no name. A keyed deviation whose text changed was reworded, not added:
171
+ // a warning, since a rewording can widen it.
172
+ const deviations = (p) => {
173
+ const text = (p.sections ?? []).find((s) => s.title === "Known deviations")?.text ?? "";
174
+ const items = [];
175
+ for (const l of text.split("\n")) {
176
+ if (/^[-*]\s+/.test(l))
177
+ items.push(l.replace(/^[-*]\s+/, "").trim());
178
+ else if (l.trim())
179
+ items.length ? (items[items.length - 1] += " " + l.trim()) : items.push(l.trim());
180
+ }
181
+ const seen = new Map();
182
+ return new Map(items.map((d) => {
183
+ const n = /^`[^`]+`/.exec(d)?.[0];
184
+ if (!n)
185
+ return [d, d];
186
+ const k = (seen.get(n) ?? 0) + 1;
187
+ seen.set(n, k);
188
+ return [k > 1 ? `${n} #${k}` : n, d];
189
+ }));
190
+ };
191
+ const da = deviations(P), db = deviations(Q);
192
+ for (const k of [...db.keys()].sort()) {
193
+ const d = db.get(k);
194
+ if (!da.has(k))
195
+ add({ kind: "profile.deviation-added", record: "profile", field: "Known deviations", after: d, level: "breaking", message: `a known deviation was added; the list may only shrink: ${d}` });
196
+ else if (da.get(k) !== d)
197
+ add({ kind: "profile.deviation-changed", record: "profile", field: `Known deviations:${k}`, before: da.get(k), after: d, level: "warning", message: `the known deviation ${k} was reworded; check it did not widen` });
198
+ }
199
+ for (const k of [...da.keys()].sort())
200
+ if (!db.has(k))
201
+ add({ kind: "profile.deviation-removed", record: "profile", field: "Known deviations", before: da.get(k), level: "info", message: `a known deviation was fixed: ${da.get(k)}` });
202
+ const sp = new Map((P.sections ?? []).map((s) => [s.title, s.text])), sq = new Map((Q.sections ?? []).map((s) => [s.title, s.text]));
203
+ for (const t of [...new Set([...sp.keys(), ...sq.keys()])].filter((t) => t !== "Known deviations").sort())
204
+ if (sp.get(t) !== sq.get(t))
205
+ add({ kind: "profile.section-changed", record: "profile", field: `section:${t}`, before: sp.get(t), after: sq.get(t), level: "info", message: `section '${t}' ${!sp.has(t) ? "was added" : !sq.has(t) ? "was removed" : "changed"}` });
206
+ // Declarations themselves. Whatever changed is recorded (info); each loosening is its own change,
207
+ // at least a warning, and breaking when the rule it lowers was breaking.
208
+ for (const arch of [...new Set([...Object.keys(A.architectures ?? {}), ...Object.keys(B.architectures ?? {})])].sort()) {
209
+ const x = own(A.architectures, arch), y = own(B.architectures, arch);
210
+ if (same(x, y))
211
+ continue;
212
+ add({ kind: "architecture.changed", record: arch, before: x, after: y, level: "info", message: `the ${arch} declaration changed` });
213
+ const loosened = (field, message, level = "warning") => add({ kind: "architecture.loosened", record: arch, field, level, message });
214
+ const ry = new Map((y?.["diff-rules"] ?? []).map((r) => [`${r.field}\0${r.change}`, r.level]));
215
+ for (const r of x?.["diff-rules"] ?? []) {
216
+ const now = ry.get(`${r.field}\0${r.change}`) ?? "info"; // a removed rule leaves the change unclassified: info
217
+ if (LEVELS.indexOf(now) < LEVELS.indexOf(r.level))
218
+ loosened(r.field, `the rule for ${r.field} ${r.change} went from ${r.level} to ${ry.has(`${r.field}\0${r.change}`) ? now : "no rule"}`, r.level === "breaking" ? "breaking" : "warning");
219
+ }
220
+ const fy = new Map((y?.fields ?? []).map((f) => [`${f.field}\0${f.on}`, f]));
221
+ for (const f of x?.fields ?? []) {
222
+ const g = fy.get(`${f.field}\0${f.on}`);
223
+ if (!g) {
224
+ loosened(f.field, `${f.field} on ${f.on} is no longer declared`);
225
+ continue;
226
+ }
227
+ if (f.required !== "no" && g.required !== "yes" && !same(f.required, g.required))
228
+ loosened(f.field, `${f.field} on ${f.on}: required ${show(typeof f.required === "object" ? `when ${f.required.when} is ${show(f.required.is)}` : f.required)} -> ${show(typeof g.required === "object" ? `when ${g.required.when} is ${show(g.required.is)}` : g.required)}`);
229
+ if (f.values && (!g.values || g.values.some((v) => !f.values.includes(v))))
230
+ loosened(f.field, `${f.field} on ${f.on}: values ${show(f.values)} -> ${g.values ? show(g.values) : "any"}`);
231
+ }
232
+ }
233
+ // The catch-all: the bodies differ but nothing above said how.
234
+ if (!out.length && !same(A, B))
235
+ add({ kind: "description.changed", record: "profile", level: "warning", message: "the description changed in a way diff has no kind for; compare the two bodies" });
236
+ // Findings: an error that appears is a warning, a gap that appears is info, one that goes is info.
237
+ // A finding is the same one when rule, file, record, field and message match; its line may move.
238
+ const fkey = (f) => JSON.stringify([f.rule, f.file, f.record ?? "", f.field ?? "", f.message]);
239
+ const fa = new Map(a.findings.map((f) => [fkey(f), f])), fb = new Map(b.findings.map((f) => [fkey(f), f]));
240
+ for (const [k, f] of fb)
241
+ if (!fa.has(k))
242
+ add({ kind: "finding.appeared", record: f.record ?? f.file, field: f.rule, after: f, level: f.level === "error" ? "warning" : "info", message: `${f.level} ${f.rule}: ${f.message}` });
243
+ for (const [k, f] of fa)
244
+ if (!fb.has(k))
245
+ add({ kind: "finding.resolved", record: f.record ?? f.file, field: f.rule, before: f, level: "info", message: `${f.level} ${f.rule}: ${f.message}` });
246
+ return out;
247
+ }
248
+ // "2 breaking · 1 warning · 14 info"
249
+ export const diffSummary = (cs) => ["breaking", "warning", "info"].map((l) => `${cs.filter((c) => c.level === l).length} ${l}`).join(" · ");
@@ -0,0 +1,11 @@
1
+ export interface Finding {
2
+ rule: string;
3
+ level: "error" | "gap";
4
+ file: string;
5
+ line?: number;
6
+ record?: string;
7
+ field?: string;
8
+ message: string;
9
+ }
10
+ export declare const sortFindings: (fs: Finding[]) => Finding[];
11
+ export declare const formatFinding: (f: Finding) => string;
@@ -0,0 +1,6 @@
1
+ // Order for printing: by file, then line (a finding with no line first), then as found.
2
+ export const sortFindings = (fs) => fs.map((f, i) => ({ f, i }))
3
+ .sort((a, b) => (a.f.file < b.f.file ? -1 : a.f.file > b.f.file ? 1 : (a.f.line ?? 0) - (b.f.line ?? 0) || a.i - b.i))
4
+ .map(({ f }) => f);
5
+ // One line per finding, in the shape editors and CI problem matchers read: `file:line: level rule: message`.
6
+ export const formatFinding = (f) => `${f.file}${f.line ? `:${f.line}` : ""}: ${f.level} ${f.rule}: ${f.message}`;
@@ -0,0 +1,19 @@
1
+ export type { Source } from "./source.ts";
2
+ export { folderSource } from "./source.ts";
3
+ export type { Finding } from "./findings.ts";
4
+ export { formatFinding, sortFindings } from "./findings.ts";
5
+ export type { Model, Rec, Field, Section, Value, Kind, CoverageLine } from "./read.ts";
6
+ export { read, parseRecord } from "./read.ts";
7
+ export type { Counts } from "./check.ts";
8
+ export { check, counts, summary } from "./check.ts";
9
+ export type { Architecture, DeclaredField, DiffRule, Required, RecordKind } from "./read.ts";
10
+ export { parseArchitecture } from "./read.ts";
11
+ export type { ReconcileQuery } from "./reconcile.ts";
12
+ export { reconcile } from "./reconcile.ts";
13
+ export type { Description } from "./describe.ts";
14
+ export { describe, body, bodyBytes, digestOf, parseDescription, FORMAT } from "./describe.ts";
15
+ export { jcs } from "./jcs.ts";
16
+ export { VERSION } from "./version.ts";
17
+ export type { Change, Level } from "./diff.ts";
18
+ export { diff, diffSummary } from "./diff.ts";
19
+ export { renderIndex } from "./indexes.ts";
package/dist/index.js ADDED
@@ -0,0 +1,11 @@
1
+ export { folderSource } from "./source.js";
2
+ export { formatFinding, sortFindings } from "./findings.js";
3
+ export { read, parseRecord } from "./read.js";
4
+ export { check, counts, summary } from "./check.js";
5
+ export { parseArchitecture } from "./read.js";
6
+ export { reconcile } from "./reconcile.js";
7
+ export { describe, body, bodyBytes, digestOf, parseDescription, FORMAT } from "./describe.js";
8
+ export { jcs } from "./jcs.js";
9
+ export { VERSION } from "./version.js";
10
+ export { diff, diffSummary } from "./diff.js";
11
+ export { renderIndex } from "./indexes.js";
@@ -0,0 +1,2 @@
1
+ import type { Model } from "./read.ts";
2
+ export declare function renderIndex(m: Model): string;
@@ -0,0 +1,27 @@
1
+ // renderIndex: the behavior index, the coverage table and the client action index, as markdown.
2
+ // operbe ≤ 0.2 committed these as INDEX.md and COVERAGE.md; they changed with every behavior edit
3
+ // and made parallel changes conflict, so v1 prints them on demand (`operbe index`) instead.
4
+ // Built from the description's body, so it shows exactly what describe would.
5
+ import { body } from "./describe.js";
6
+ const cmp = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
7
+ export function renderIndex(m) {
8
+ const b = body(m);
9
+ const uis = b.profile?.uis ?? [];
10
+ const applies = (r, ui) => r["applies-to"] === "all" || (Array.isArray(r["applies-to"]) && r["applies-to"].includes(ui));
11
+ // A coverage cell: the value, blank if the UI hasn't built it yet, n/a if it doesn't apply.
12
+ const cell = (id, r, ui) => b.coverage?.[ui]?.[id]?.value ?? (applies(r, ui) ? "" : "n/a");
13
+ const row = (cells) => `| ${cells.join(" | ")} |\n`;
14
+ const head = (cols) => row(cols) + `|${"---|".repeat(cols.length)}\n`;
15
+ const blank = "Blank = not yet built. n/a = doesn't apply to that UI.\n\n";
16
+ const behaviors = Object.entries(b.behaviors ?? {}).sort(([x], [y]) => cmp(x, y));
17
+ let out = "# Behaviors\n\n" + head(["id", "name", "status", "form"]) +
18
+ behaviors.map(([id, r]) => row([id, r.name ?? "", r.status ?? "", r.form ?? ""])).join("");
19
+ out += "\n# Coverage\n\n" + blank + head(["id", "name", ...uis]) +
20
+ behaviors.map(([id, r]) => row([id, r.name ?? "", ...uis.map((u) => cell(id, r, u))])).join("");
21
+ if (b["client-actions"]) {
22
+ const acts = Object.entries(b["client-actions"]).sort(([x], [y]) => cmp(x, y));
23
+ out += "\n# Client actions\n\n" + blank + head(["name", "class", "status", "behaviors", ...uis]) +
24
+ acts.map(([n, r]) => row([n, r.class ?? "", r.status ?? "", (Array.isArray(r.behaviors) ? r.behaviors : []).join(", "), ...uis.map((u) => cell(n, r, u))])).join("");
25
+ }
26
+ return out;
27
+ }
package/dist/jcs.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function jcs(v: unknown): string;
package/dist/jcs.js ADDED
@@ -0,0 +1,16 @@
1
+ // RFC 8785 JSON Canonicalization (JCS), for the values a description holds: objects, arrays,
2
+ // strings, booleans and integers. JCS's string and number forms are exactly ECMAScript's
3
+ // JSON.stringify; what it adds is object keys sorted by UTF-16 code units (JS's default sort)
4
+ // and no whitespace.
5
+ // ponytail: no floats; a body never holds one (formats.md: integers only). A float would need
6
+ // RFC 8785 §3.2.2.3's number form, which JSON.stringify already matches for finite doubles.
7
+ export function jcs(v) {
8
+ if (Array.isArray(v))
9
+ return `[${v.map(jcs).join(",")}]`;
10
+ if (v !== null && typeof v === "object")
11
+ return `{${Object.keys(v).sort().filter((k) => v[k] !== undefined)
12
+ .map((k) => `${JSON.stringify(k)}:${jcs(v[k])}`).join(",")}}`;
13
+ if (typeof v === "number" && !Number.isSafeInteger(v))
14
+ throw new TypeError(`jcs: ${v} is not an integer`);
15
+ return JSON.stringify(v);
16
+ }
package/dist/jj.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import type { Finding } from "./findings.ts";
2
+ import type { Source } from "./source.ts";
3
+ export declare class JjError extends Error {
4
+ }
5
+ export interface JjAt {
6
+ source: Source;
7
+ rev: string;
8
+ commit: string;
9
+ change: string;
10
+ findings: Finding[];
11
+ }
12
+ export declare function jjSource(root: string, rev: string): JjAt;
package/dist/jj.js ADDED
@@ -0,0 +1,82 @@
1
+ // operbe/jj: a Source at a jj revision. A separate subpath: the core never imports this file, so
2
+ // using operbe never needs jj (test/jj.ts proves it). Only the CLI's --at loads it.
3
+ //
4
+ // jjSource(root, rev) -> { source, commit, change, findings }
5
+ //
6
+ // - Every jj call passes --ignore-working-copy: reading must not snapshot the working copy, which
7
+ // would write a jj operation as a side effect.
8
+ // - `rev` must resolve to exactly one commit. None, several, or a divergent change is refused.
9
+ // - All the project's .md files come from one `jj file show` call: a template writes a header with
10
+ // a random marker before each file, and the output is split on it.
11
+ // - A file with a conflict at that revision is a finding (operbe/conflict), with its text as jj
12
+ // prints it (conflict markers and all).
13
+ // - The ids are returned beside the source for a runner to put next to the description. They never
14
+ // go into the description's body: the same files give the same digest whatever commit holds them.
15
+ import { spawnSync } from "node:child_process";
16
+ import { randomBytes } from "node:crypto";
17
+ import { realpathSync } from "node:fs";
18
+ import { relative, sep } from "node:path";
19
+ // Something about jj or the revision, not about the project: the CLI exits 2 on it.
20
+ export class JjError extends Error {
21
+ }
22
+ function jj(cwd, args) {
23
+ const r = spawnSync("jj", ["--ignore-working-copy", "--color=never", ...args], { cwd, encoding: "utf8", maxBuffer: 1 << 30 });
24
+ if (r.error?.code === "ENOENT")
25
+ throw new JjError("--at reads a revision with jj, and jj isn't installed or isn't on PATH (https://jj-vcs.dev)");
26
+ if (r.error)
27
+ throw new JjError(`jj: ${r.error.message}`);
28
+ if (r.status !== 0)
29
+ throw new JjError(`jj: ${r.stderr.trim().replace(/^Error: /, "")}`);
30
+ return r.stdout;
31
+ }
32
+ // A string literal inside a jj template or fileset.
33
+ const lit = (s) => `"${s.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
34
+ export function jjSource(root, rev) {
35
+ // The repo may hold the project in a subfolder: jj paths are repo-relative, a Source's are project-relative.
36
+ let repo;
37
+ try {
38
+ repo = jj(realpathSync(root), ["root"]).trim();
39
+ }
40
+ catch (e) {
41
+ if (e instanceof JjError && /no jj repo/i.test(e.message))
42
+ throw new JjError(`${root} isn't in a jj repo (for a git repo: jj git init --colocate)`);
43
+ throw e;
44
+ }
45
+ const prefix = relative(realpathSync(repo), realpathSync(root)).split(sep).join("/");
46
+ const lines = jj(repo, ["log", "-r", rev, "--no-graph", "-T", 'commit_id ++ " " ++ change_id ++ "\\n"']).split("\n").filter(Boolean);
47
+ if (!lines.length)
48
+ throw new JjError(`'${rev}' names no commit`);
49
+ if (lines.length > 1)
50
+ throw new JjError(`'${rev}' names ${lines.length} commits; --at needs exactly one`);
51
+ const [commit, change] = lines[0].split(" ");
52
+ const mark = `@@operbe-${randomBytes(12).toString("hex")}@@`;
53
+ const fileset = `root-glob:"**/*.md"${prefix ? ` & root:${lit(prefix)}` : ""}`;
54
+ let out = "";
55
+ try {
56
+ out = jj(repo, ["file", "show", "-r", commit, "-T", `${lit(mark)} ++ path ++ ${lit(mark)} ++ conflict ++ "\\n"`, fileset]);
57
+ }
58
+ catch (e) {
59
+ if (!(e instanceof JjError && /no such path|matched no files|doesn't exist/i.test(e.message)))
60
+ throw e;
61
+ } // nothing there: an empty project
62
+ // out = mark path mark conflict \n content mark path mark conflict \n content ...
63
+ const files = new Map(), findings = [];
64
+ const parts = out.split(mark);
65
+ for (let i = 1; i + 1 < parts.length; i += 2) {
66
+ const path = prefix ? parts[i].slice(prefix.length + 1) : parts[i];
67
+ const rest = parts[i + 1], nl = rest.indexOf("\n");
68
+ files.set(path, rest.slice(nl + 1));
69
+ if (rest.slice(0, nl) === "true")
70
+ findings.push({ rule: "operbe/conflict", level: "error", file: path, message: `this file has a jj conflict at ${rev}; resolve it, and describe again` });
71
+ }
72
+ const source = {
73
+ read: (p) => files.get(p) ?? null,
74
+ list: (dir) => {
75
+ const pre = dir ? `${dir}/` : "";
76
+ const under = [...files.keys()].filter((p) => p.startsWith(pre));
77
+ // A folder exists at a revision if any file is under it (jj, like git, keeps no empty folders).
78
+ return under.length ? under.map((p) => p.slice(pre.length)).filter((n) => !n.includes("/")).sort() : null;
79
+ },
80
+ };
81
+ return { source, rev, commit, change, findings };
82
+ }
package/dist/read.d.ts ADDED
@@ -0,0 +1,83 @@
1
+ import type { Finding } from "./findings.ts";
2
+ import type { Source } from "./source.ts";
3
+ export type Value = string | string[];
4
+ export interface Field {
5
+ value: Value;
6
+ line: number;
7
+ }
8
+ export interface Section {
9
+ title: string;
10
+ text: string;
11
+ line: number;
12
+ }
13
+ export type Kind = "profile" | "operation" | "behavior" | "client-action" | "architecture";
14
+ export declare const RECORD_KINDS: readonly ["operation", "behavior", "client-action"];
15
+ export type RecordKind = (typeof RECORD_KINDS)[number];
16
+ export interface Rec {
17
+ kind: Kind;
18
+ file: string;
19
+ stem: string;
20
+ readable: boolean;
21
+ fields: Record<string, Field>;
22
+ sections: Section[];
23
+ }
24
+ export interface CoverageLine {
25
+ line: number;
26
+ cells: string[];
27
+ }
28
+ export interface Model {
29
+ profile: Rec | null;
30
+ uis: string[];
31
+ folders: {
32
+ operations: string;
33
+ behaviors: string;
34
+ clientActions: string | null;
35
+ };
36
+ absent: string[];
37
+ operations: Rec[];
38
+ behaviors: Rec[];
39
+ clientActions: Rec[];
40
+ coverage: Record<string, {
41
+ file: string;
42
+ lines: CoverageLine[] | null;
43
+ }>;
44
+ architectures: Architecture[];
45
+ findings: Finding[];
46
+ }
47
+ export type Required = "yes" | "no" | {
48
+ when: string;
49
+ is: string[];
50
+ };
51
+ export interface DeclaredField {
52
+ field: string;
53
+ on: RecordKind;
54
+ required: Required;
55
+ values: string[] | null;
56
+ line: number;
57
+ }
58
+ export interface DiffRule {
59
+ field: string;
60
+ change: "added" | "removed" | "changed";
61
+ level: "breaking" | "warning" | "info";
62
+ line: number;
63
+ }
64
+ export interface Architecture {
65
+ name: string;
66
+ file: string;
67
+ fields: DeclaredField[];
68
+ diffRules: DiffRule[];
69
+ }
70
+ export declare const linesOf: (raw: string) => string[];
71
+ export declare const dict: <T>() => Record<string, T>;
72
+ export declare function parseRecord(raw: string, file: string, kind: Kind): {
73
+ rec: Rec;
74
+ findings: Finding[];
75
+ };
76
+ export declare const str: (r: Rec | null, k: string) => string;
77
+ export declare const list: (r: Rec | null, k: string) => string[];
78
+ export declare const section: (r: Rec, title: string) => string;
79
+ export declare function read(src: Source): Model;
80
+ export declare function parseArchitecture(raw: string, file: string, name: string): {
81
+ arch: Architecture;
82
+ findings: Finding[];
83
+ };