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/check.js ADDED
@@ -0,0 +1,422 @@
1
+ import { list, section, str } from "./read.js";
2
+ const CLASSES = ["query", "change", "signal"];
3
+ const REASONS = ["side-effect", "different-right", "together", "restricted-state", "intent"];
4
+ const RISKS = ["reads", "changes", "destroys", "changes-rights"];
5
+ const BATCH = ["none", "all-or-nothing", "per-item"];
6
+ const STATUSES = ["rough", "firm", "retired"];
7
+ const COVER = ["honours", "differs", "limited", "not-here"];
8
+ const B_REQUIRED = ["Statement", "Examples", "Changes"];
9
+ const B_OPTIONAL = ["Flow", "Appears when", "Usable when", "Undo", "Differs on"];
10
+ const A_CLASSES = ["show", "prepare", "do"];
11
+ const A_ORDER = ["Sentence", "Inputs", "Unavailable", "Result"];
12
+ const A_RESULTS = ["done", "refused", "waiting", "started", "unknown"];
13
+ const NAME = /^[a-z0-9]+(-[a-z0-9]+)+$/;
14
+ const B_ID = /^B-\p{Nd}+$/u;
15
+ // The unprefixed fields each kind may carry. Unprefixed names are operbe's namespace, so any other
16
+ // is a typo (`aprove:`) or a field that belongs under an architecture's prefix.
17
+ export const KNOWN = {
18
+ "profile": ["operbe", "operations", "behaviors", "client-actions", "uis", "architectures"],
19
+ "operation": ["name", "class", "named-because", "needs", "safe-to-repeat", "taken-back-by", "risk", "many-at-once"],
20
+ "behavior": ["id", "name", "status", "form", "applies-to", "operations", "replaced-by", "client-actions"],
21
+ "client-action": ["name", "class", "status", "form", "behaviors", "operations", "show-because", "local", "available-when", "applies-to", "replaced-by"],
22
+ "architecture": ["architecture", "format"],
23
+ };
24
+ const VERSION = "1"; // the profile's `operbe:` this build reads
25
+ // Lists the way check.py printed them (Python's list form), so messages match.
26
+ const py = (xs) => `[${xs.map((x) => `'${x}'`).join(", ")}]`;
27
+ const sorted = (xs) => [...xs].sort();
28
+ // A form is a whole number a description can hold: digits, and no bigger than a safe integer.
29
+ export const whole = (v) => /^[0-9]+$/.test(v) && Number.isSafeInteger(Number(v));
30
+ const items = (text) => [...text.matchAll(/^- ([^:\n]+):/gm)].map((m) => m[1].trim()); // "- name: ..." list items
31
+ const sends = (cls) => cls === "change" || cls === "signal";
32
+ export function check(m) {
33
+ const out = [...m.findings];
34
+ if (!m.profile)
35
+ return out;
36
+ const p = m.profile;
37
+ // Findings about a record. With a field, the finding points at that field's line.
38
+ const at = (level) => (r, rule, message, field) => {
39
+ const line = field ? r.fields[field]?.line : undefined;
40
+ const record = r.kind === "profile" ? undefined : r.kind === "behavior" ? str(r, "id") || r.stem : str(r, "name") || r.stem;
41
+ out.push({ rule, level, file: r.file, ...(line ? { line } : {}), ...(record ? { record } : {}), ...(field ? { field } : {}), message });
42
+ };
43
+ const err = at("error"), gap = at("gap");
44
+ const need = (r, keys) => { for (const k of keys)
45
+ if (!(k in r.fields))
46
+ err(r, "operbe/field-missing", `missing header field '${k}'`, k); };
47
+ const asList = (r, key) => {
48
+ if (key in r.fields && !Array.isArray(r.fields[key].value))
49
+ err(r, "operbe/not-a-list", `${key} must be a list: [a, b]`, key);
50
+ return list(r, key);
51
+ };
52
+ const has = (r, title) => !!section(r, title);
53
+ const needSections = (r, titles) => { for (const t of titles)
54
+ if (!has(r, t))
55
+ err(r, "operbe/section-missing", `missing or empty section '${t}'`); };
56
+ const appliesTo = (r) => { const a = r.fields["applies-to"]?.value; return a === "all" ? m.uis : Array.isArray(a) ? a : []; };
57
+ const appliesOk = (r) => {
58
+ const a = r.fields["applies-to"]?.value;
59
+ if (a === "all")
60
+ return;
61
+ if (!Array.isArray(a) || !a.length)
62
+ return err(r, "operbe/applies-to", "applies-to must be 'all' or a list of UIs", "applies-to");
63
+ for (const u of a)
64
+ if (!m.uis.includes(u))
65
+ err(r, "operbe/applies-to", `applies-to names '${u}', which is not a UI in operbe.md`, "applies-to");
66
+ };
67
+ const formOf = (r) => (whole(str(r, "form")) ? Number(str(r, "form")) : 0);
68
+ const formOk = (r) => { if (formOf(r) < 1)
69
+ err(r, "operbe/form", "form must be a whole number, 1 or more", "form"); };
70
+ const replacedOk = (r, what) => {
71
+ const retired = str(r, "status") === "retired", by = r.fields["replaced-by"]?.value;
72
+ if (retired && !by)
73
+ err(r, "operbe/replaced-by", `a retired ${what} must say what replaced it`, "replaced-by");
74
+ if (!retired && by)
75
+ err(r, "operbe/replaced-by", `replaced-by is only for a retired ${what}`, "replaced-by");
76
+ };
77
+ const orderOk = (r, order) => {
78
+ const rank = (t) => (order.includes(t) ? order.indexOf(t) : 99);
79
+ const titles = r.sections.map((s) => s.title);
80
+ if (titles.join("\0") !== [...titles].sort((a, b) => rank(a) - rank(b)).join("\0"))
81
+ err(r, "operbe/section-order", "sections are out of order");
82
+ };
83
+ const readable = (r) => { if (!r.readable)
84
+ err(r, "operbe/no-header", "no header between --- lines"); return r.readable; };
85
+ // Fields: unknown unprefixed ones are errors; a prefixed one needs its architecture declared.
86
+ const archs = list(p, "architectures");
87
+ const fieldsOk = (r) => {
88
+ for (const k of Object.keys(r.fields)) {
89
+ const dot = k.indexOf(".");
90
+ if (dot < 0) {
91
+ if (!KNOWN[r.kind].includes(k))
92
+ err(r, "operbe/unknown-field", `'${k}' is not an operbe field; an architecture's field takes its prefix ('${archs[0] ?? "<architecture>"}.${k}')`, k);
93
+ }
94
+ else if (!archs.includes(k.slice(0, dot)))
95
+ err(r, "operbe/undeclared-architecture", `'${k}' belongs to an architecture '${k.slice(0, dot)}' that operbe.md doesn't declare under 'architectures'`, k);
96
+ else {
97
+ const decl = m.architectures.find((a) => a.name === k.slice(0, dot));
98
+ if (decl && !decl.fields.some((f) => f.field === k && f.on === r.kind))
99
+ err(r, "operbe/undeclared-field", `'${k}' isn't declared for a ${r.kind} in ${decl.file}`, k);
100
+ }
101
+ }
102
+ declaredOk(r);
103
+ };
104
+ // What an architecture's declaration asks of each record: its required fields, and their values.
105
+ // Findings carry the architecture's own rule ids (`chugg/field-missing`). A rough record that
106
+ // lacks a required field gets a gap, not an error: it is still being worked out.
107
+ const applies = (d, r) => {
108
+ if (d.required === "yes" || d.required === "no")
109
+ return d.required === "yes";
110
+ const v = r.fields[d.required.when]?.value ?? "";
111
+ return (Array.isArray(v) ? v : [v]).some((x) => d.required.is.includes(x));
112
+ };
113
+ const declaredOk = (r) => {
114
+ for (const a of m.architectures)
115
+ for (const d of a.fields) {
116
+ if (d.on !== r.kind)
117
+ continue;
118
+ const v = r.fields[d.field]?.value;
119
+ if (v === undefined || v === "") {
120
+ if (!applies(d, r))
121
+ continue;
122
+ const why = typeof d.required === "object" ? ` when ${d.required.when} is ${d.required.is.length > 1 ? `[${d.required.is.join(", ")}]` : d.required.is[0]}` : "";
123
+ (str(r, "status") === "rough" ? gap : err)(r, `${a.name}/field-missing`, `missing '${d.field}', which ${a.file} requires${why}`, d.field);
124
+ }
125
+ else if (d.values)
126
+ for (const x of Array.isArray(v) ? v : [v])
127
+ if (!d.values.includes(x))
128
+ err(r, `${a.name}/field-value`, `${d.field} '${x}' must be one of [${d.values.join(", ")}]`, d.field);
129
+ }
130
+ };
131
+ // 0. The profile.
132
+ if (readable(p)) {
133
+ need(p, ["operbe", "operations", "behaviors", "uis"]);
134
+ if ("operbe" in p.fields && str(p, "operbe") !== VERSION)
135
+ err(p, "operbe/version", `this build of operbe reads 'operbe: ${VERSION}'; this project says '${str(p, "operbe")}'`, "operbe");
136
+ for (const t of ["Decisions", "Known deviations"])
137
+ if (!p.sections.some((s) => s.title === t))
138
+ err(p, "operbe/section-missing", `missing section '${t}'`);
139
+ fieldsOk(p);
140
+ }
141
+ const { operations: opsDir, behaviors: behDir, clientActions: actDir } = m.folders;
142
+ for (const d of [opsDir, behDir])
143
+ if (m.absent.includes(d))
144
+ err(p, "operbe/folder-missing", `the folder '${d.split("/").pop()}' it names does not exist`, d === opsDir ? "operations" : "behaviors");
145
+ let actions = actDir !== null;
146
+ if (actDir === "") {
147
+ if (!m.findings.some((f) => f.rule === "operbe/path" && f.field === "client-actions"))
148
+ err(p, "operbe/client-actions-folder", "client-actions is empty; name the folder, or remove the line", "client-actions");
149
+ actions = false;
150
+ }
151
+ else if (actDir !== null && (actDir === opsDir || actDir === behDir)) {
152
+ err(p, "operbe/client-actions-folder", "client-actions must be a folder of its own", "client-actions");
153
+ actions = false;
154
+ }
155
+ else if (actDir !== null && m.absent.includes(actDir)) {
156
+ err(p, "operbe/folder-missing", `the folder '${actDir.split("/").pop()}' it names does not exist`, "client-actions");
157
+ actions = false;
158
+ }
159
+ // The declarations themselves: a `when <field>` names a field the record kind can carry.
160
+ for (const a of m.architectures)
161
+ for (const d of a.fields) {
162
+ if (typeof d.required !== "object")
163
+ continue;
164
+ const w = d.required.when;
165
+ if (!KNOWN[d.on].includes(w) && !m.architectures.some((x) => x.fields.some((f) => f.field === w && f.on === d.on)))
166
+ out.push({ rule: "operbe/declaration", level: "error", file: a.file, line: d.line, message: `'when ${w}' names a field a ${d.on} doesn't have` });
167
+ }
168
+ // 1. Operations.
169
+ const ops = new Map(); // name -> class
170
+ for (const o of m.operations) {
171
+ if (!readable(o))
172
+ continue;
173
+ const name = str(o, "name"), cls = str(o, "class");
174
+ need(o, ["name", "class"]);
175
+ fieldsOk(o);
176
+ if (name !== o.stem)
177
+ err(o, "operbe/name-mismatch", `name '${name}' doesn't match the file name`, "name");
178
+ if (!NAME.test(name))
179
+ err(o, "operbe/name-form", "name must be lowercase words joined by hyphens: a verb, then the thing", "name");
180
+ ops.set(name, cls);
181
+ if (!CLASSES.includes(cls))
182
+ err(o, "operbe/class", `class must be one of ${py(sorted(CLASSES))}`, "class");
183
+ // A stub (name and class, no sections) says its facts live in the project's interface language.
184
+ // Architecture fields don't count: a stub with `chugg.op` is still a stub.
185
+ const stub = Object.keys(o.fields).filter((k) => !k.includes(".")).length <= 2 && !o.sections.length;
186
+ if (stub)
187
+ continue;
188
+ need(o, ["needs", "safe-to-repeat", "taken-back-by", "risk", "many-at-once"]);
189
+ const because = str(o, "named-because");
190
+ if (because && !REASONS.includes(because))
191
+ err(o, "operbe/named-because", `named-because must be empty or one of ${py(sorted(REASONS))}`, "named-because");
192
+ if (because && cls !== "change")
193
+ err(o, "operbe/named-because", "only a change can be named-because", "named-because");
194
+ if (!["yes", "no"].includes(str(o, "safe-to-repeat")))
195
+ err(o, "operbe/safe-to-repeat", "safe-to-repeat must be yes or no", "safe-to-repeat");
196
+ if (!RISKS.includes(str(o, "risk")))
197
+ err(o, "operbe/risk", `risk must be one of ${py(sorted(RISKS))}`, "risk");
198
+ if (cls === "query" && str(o, "safe-to-repeat") === "no")
199
+ err(o, "operbe/query-repeat", "a query is always safe to repeat", "safe-to-repeat");
200
+ if (cls === "query" && str(o, "risk") !== "reads")
201
+ err(o, "operbe/risk", "a query's risk is always 'reads'", "risk");
202
+ if (!BATCH.includes(str(o, "many-at-once")))
203
+ err(o, "operbe/many-at-once", `many-at-once must be one of ${py(sorted(BATCH))}`, "many-at-once");
204
+ needSections(o, ["Sentence", "Holds only if"]);
205
+ }
206
+ for (const o of m.operations) {
207
+ const t = str(o, "taken-back-by");
208
+ if (t && t !== "nothing" && t !== "itself" && !ops.has(t))
209
+ err(o, "operbe/unknown-reference", `taken-back-by '${t}' is not an operation`, "taken-back-by");
210
+ }
211
+ const behaviors = new Map(), names = new Map();
212
+ for (const b of m.behaviors) {
213
+ if (!readable(b))
214
+ continue;
215
+ const id = str(b, "id"), name = str(b, "name"), status = str(b, "status");
216
+ need(b, ["id", "name", "status", "form", "applies-to", "operations"]);
217
+ fieldsOk(b);
218
+ if (id !== b.stem)
219
+ err(b, "operbe/name-mismatch", `id '${id}' doesn't match the file name`, "id");
220
+ if (!B_ID.test(id))
221
+ err(b, "operbe/id-form", "id must be B- and a number", "id");
222
+ if (!name)
223
+ err(b, "operbe/name-empty", "name is empty", "name");
224
+ if (names.has(name))
225
+ err(b, "operbe/name-duplicate", `name '${name}' is already used by ${names.get(name)}`, "name");
226
+ names.set(name, id);
227
+ if (!STATUSES.includes(status))
228
+ err(b, "operbe/status", `status must be one of ${py(sorted(STATUSES))}`, "status");
229
+ formOk(b);
230
+ appliesOk(b);
231
+ const bOps = asList(b, "operations");
232
+ for (const o of bOps)
233
+ if (!ops.has(o))
234
+ err(b, "operbe/unknown-reference", `operation '${o}' is not in the operation list`, "operations");
235
+ replacedOk(b, "behavior");
236
+ needSections(b, B_REQUIRED);
237
+ for (const s of b.sections)
238
+ if (![...B_REQUIRED, ...B_OPTIONAL].includes(s.title))
239
+ err(b, "operbe/section-not-allowed", `section '${s.title}' is not allowed`);
240
+ orderOk(b, ["Statement", ...B_OPTIONAL, "Examples", "Changes"]);
241
+ const examples = section(b, "Examples").match(/^- /gm)?.length ?? 0;
242
+ if (status === "firm" && examples < 2)
243
+ err(b, "operbe/examples", "a firm behavior needs at least two examples");
244
+ behaviors.set(id, { rec: b, name, status, form: formOf(b), uis: appliesTo(b), callable: str(b, "client-actions") !== "none", sends: bOps.some((o) => sends(ops.get(o))) });
245
+ }
246
+ for (const b of m.behaviors) {
247
+ const r = str(b, "replaced-by");
248
+ if (r && !behaviors.has(r))
249
+ err(b, "operbe/unknown-reference", `replaced-by '${r}' is not a behavior`, "replaced-by");
250
+ }
251
+ const acts = new Map();
252
+ if (actions) {
253
+ for (const a of m.clientActions) {
254
+ if (!readable(a))
255
+ continue;
256
+ const name = str(a, "name"), cls = str(a, "class"), status = str(a, "status");
257
+ need(a, ["name", "class", "status", "form", "behaviors", "operations", "available-when", "applies-to"]);
258
+ fieldsOk(a);
259
+ if (name !== a.stem)
260
+ err(a, "operbe/name-mismatch", `name '${name}' doesn't match the file name`, "name");
261
+ if (!NAME.test(name))
262
+ err(a, "operbe/name-form", "name must be lowercase words joined by hyphens: a verb, then the thing", "name");
263
+ if (!A_CLASSES.includes(cls))
264
+ err(a, "operbe/class", `class must be one of ${py(sorted(A_CLASSES))}`, "class");
265
+ if (!STATUSES.includes(status))
266
+ err(a, "operbe/status", `status must be one of ${py(sorted(STATUSES))}`, "status");
267
+ const behs = asList(a, "behaviors");
268
+ if (!behs.length)
269
+ err(a, "operbe/behaviors-empty", "a client action must name at least one behavior it carries out", "behaviors");
270
+ for (const id of behs) {
271
+ const known = behaviors.get(id);
272
+ if (!known)
273
+ err(a, "operbe/unknown-reference", `behavior '${id}' is not in the behavior list`, "behaviors");
274
+ else if (known.status === "retired" && status !== "retired")
275
+ err(a, "operbe/behavior-retired", `behavior '${id}' is retired`, "behaviors");
276
+ else if (!known.callable)
277
+ err(a, "operbe/behavior-not-callable", `behavior '${id}' says 'client-actions: none', but this action carries it out`, "behaviors");
278
+ }
279
+ const used = asList(a, "operations");
280
+ for (const o of used)
281
+ if (!ops.has(o))
282
+ err(a, "operbe/unknown-reference", `operation '${o}' is not in the operation list`, "operations");
283
+ const sent = used.filter((o) => sends(ops.get(o)));
284
+ const local = str(a, "local") === "yes", because = str(a, "show-because").trim();
285
+ // The class must not lie: a show sends only queries, unless the project decided the change is
286
+ // a consequence the person already agreed to, and says so in show-because.
287
+ if (cls === "show" && sent.length && !because)
288
+ err(a, "operbe/show-sends", `a show may send only queries, but lists ${py(sent)}; if the project decided this change is already agreed to, say why in 'show-because'`, "operations");
289
+ if (a.fields["show-because"]?.value && !(cls === "show" && sent.length))
290
+ err(a, "operbe/show-because", "'show-because' is only for a show that lists a change", "show-because");
291
+ if (cls === "do" && !sent.length && !local)
292
+ err(a, "operbe/do-sends", "a do must list at least one operation that is a change or a signal, or say 'local: yes'", "operations");
293
+ if (local && cls !== "do")
294
+ err(a, "operbe/local", "'local: yes' is only for a do", "local");
295
+ if (cls === "prepare" && sent.length)
296
+ gap(a, "operbe/prepare-sends", `a prepare that lists ${py(sent)}; make sure nobody else can see or is bound by what it sends`, "operations");
297
+ if (!a.fields["available-when"]?.value)
298
+ err(a, "operbe/available-when", "available-when is empty; write 'always' if there is no condition", "available-when");
299
+ formOk(a);
300
+ appliesOk(a);
301
+ replacedOk(a, "client action");
302
+ needSections(a, ["Sentence", "Result"]);
303
+ for (const s of a.sections)
304
+ if (!A_ORDER.includes(s.title))
305
+ err(a, "operbe/section-not-allowed", `section '${s.title}' is not allowed`);
306
+ orderOk(a, A_ORDER);
307
+ // Every input in the sentence is stated under Inputs, and nothing else is.
308
+ const braces = new Set([...section(a, "Sentence").matchAll(/\{([^{}]+)\}/g)].map((x) => x[1]));
309
+ const stated = new Set(items(section(a, "Inputs")));
310
+ for (const x of sorted([...braces].filter((x) => !stated.has(x))))
311
+ err(a, "operbe/inputs", `input '{${x}}' in the sentence has no line under Inputs`);
312
+ for (const x of sorted([...stated].filter((x) => !braces.has(x))))
313
+ err(a, "operbe/inputs", `Inputs lists '${x}', which is not in the sentence`);
314
+ const kinds = items(section(a, "Result"));
315
+ for (const k of kinds)
316
+ if (!A_RESULTS.includes(k))
317
+ err(a, "operbe/result", `result '${k}' must be one of ${py(sorted(A_RESULTS))}`);
318
+ if (section(a, "Result") && !kinds.includes("done"))
319
+ err(a, "operbe/result", "Result must say what 'done' reports");
320
+ acts.set(name, { status, behaviors: behs, form: formOf(a), uis: appliesTo(a) });
321
+ }
322
+ for (const a of m.clientActions) {
323
+ const r = str(a, "replaced-by");
324
+ if (r && !acts.has(r))
325
+ err(a, "operbe/unknown-reference", `replaced-by '${r}' is not a client action`, "replaced-by");
326
+ }
327
+ // A firm behavior that sends something should be callable, or say why not.
328
+ const carried = new Set([...acts.values()].filter((a) => a.status !== "retired").flatMap((a) => a.behaviors));
329
+ for (const [id, b] of behaviors)
330
+ if (b.status === "firm" && b.sends && b.callable && !carried.has(id))
331
+ gap(b.rec, "operbe/not-carried", `${id} '${b.name}' is firm, sends a change or a signal, and no client action carries it out (or mark it 'client-actions: none')`);
332
+ }
333
+ // 4. Coverage. A coverage finding is about a file, not a record header, so it is built by hand.
334
+ const table = new Map(); // "id\0ui" -> value
335
+ const key = (id, ui) => `${id}\0${ui}`;
336
+ for (const ui of m.uis) {
337
+ const { file, lines } = m.coverage[ui];
338
+ const cov = (level, rule, message, line, record) => out.push({ rule, level, file, ...(line ? { line } : {}), ...(record ? { record } : {}), message });
339
+ if (!lines) {
340
+ cov("gap", "operbe/coverage-missing", "no coverage file for this UI yet");
341
+ continue;
342
+ }
343
+ for (const { line, cells } of lines) {
344
+ const first = cells[0], known = behaviors.has(first) || acts.has(first);
345
+ if (!known && !B_ID.test(first) && !(acts.size && NAME.test(first)))
346
+ continue; // headings, totals, notes
347
+ if (cells.length < 4) {
348
+ cov("error", "operbe/coverage-row", `${first}: a coverage line has four cells: id, value, form, note`, line, first);
349
+ continue;
350
+ }
351
+ const [id, value, form, note] = cells;
352
+ if (!known) {
353
+ cov("error", "operbe/unknown-reference", `${id} is not a behavior` + (acts.size ? " or a client action" : ""), line, id);
354
+ continue;
355
+ }
356
+ const b = behaviors.get(id) ?? acts.get(id);
357
+ if (table.has(key(id, ui)))
358
+ cov("error", "operbe/coverage-duplicate", `${id} has more than one line`, line, id);
359
+ if (!b.uis.includes(ui))
360
+ cov("error", "operbe/coverage-ui", `${id} doesn't apply to ${ui}`, line, id);
361
+ if (!COVER.includes(value))
362
+ cov("error", "operbe/coverage-value", `${id}: value must be one of ${py(sorted(COVER))}`, line, id);
363
+ if (["differs", "limited", "not-here"].includes(value) && !note)
364
+ cov("error", "operbe/coverage-note", `${id}: '${value}' needs a note`, line, id);
365
+ if (value !== "not-here") {
366
+ if (!whole(form))
367
+ cov("error", "operbe/coverage-form", `${id}: '${value}' needs the form it was built against`, line, id);
368
+ else if (Number(form) > b.form)
369
+ cov("error", "operbe/coverage-form", `${id}: form ${form} is newer than the record (form ${b.form})`, line, id);
370
+ else if (Number(form) < b.form)
371
+ cov("gap", "operbe/coverage-stale", `${id} was built against form ${form}; the record is now form ${b.form}`, line, id);
372
+ }
373
+ if (value === "differs")
374
+ cov("gap", "operbe/coverage-differs", `${id} differs (${note})`, line, id);
375
+ table.set(key(id, ui), value);
376
+ }
377
+ }
378
+ // Only UIs the profile lists: one that it doesn't is already an applies-to error.
379
+ const missing = (ui, id, message) => out.push({ rule: "operbe/not-built", level: "gap", file: m.coverage[ui].file, record: id, message });
380
+ for (const [id, b] of behaviors) // the forward check: firm means every UI builds it
381
+ if (b.status === "firm")
382
+ for (const ui of b.uis)
383
+ if (m.uis.includes(ui) && !table.has(key(id, ui)))
384
+ missing(ui, id, `${id} '${b.name}' is firm and not yet built`);
385
+ for (const [name, a] of acts) // every UI offers each firm client action, or says why not
386
+ for (const ui of a.uis) {
387
+ if (!m.coverage[ui]?.lines)
388
+ continue;
389
+ if (!table.has(key(name, ui))) {
390
+ if (a.status === "firm")
391
+ missing(ui, name, `client action '${name}' is firm and not yet built`);
392
+ }
393
+ else if (table.get(key(name, ui)) !== "not-here")
394
+ for (const id of a.behaviors) // an action built ahead of the behavior it carries out
395
+ if (behaviors.get(id)?.uis.includes(ui) && !table.has(key(id, ui)))
396
+ missing(ui, name, `client action '${name}' is built, but ${id} which it carries out has no coverage line`);
397
+ }
398
+ return out;
399
+ }
400
+ export function counts(m, findings) {
401
+ const tally = (rs) => {
402
+ const t = { firm: 0, rough: 0, retired: 0 };
403
+ for (const r of rs) {
404
+ const s = str(r, "status");
405
+ if (Object.hasOwn(t, s))
406
+ t[s]++;
407
+ }
408
+ return t;
409
+ };
410
+ return {
411
+ errors: findings.filter((f) => f.level === "error").length,
412
+ gaps: findings.filter((f) => f.level === "gap").length,
413
+ behaviors: tally(m.behaviors),
414
+ clientActions: m.folders.clientActions ? tally(m.clientActions) : null,
415
+ };
416
+ }
417
+ // "0 errors · 18 gaps · behaviors 0/240 firm · client actions 0/162 firm"
418
+ export function summary(c) {
419
+ const firm = (t) => `${t.firm}/${t.firm + t.rough} firm`;
420
+ const n = (k, w) => `${k} ${w}${k === 1 ? "" : "s"}`;
421
+ return [n(c.errors, "error"), n(c.gaps, "gap"), ...(c.behaviors ? [`behaviors ${firm(c.behaviors)}`] : []), ...(c.clientActions ? [`client actions ${firm(c.clientActions)}`] : [])].join(" · ");
422
+ }
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};