operbe 0.0.0-stage → 1.0.0-rc.3

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