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/read.js ADDED
@@ -0,0 +1,249 @@
1
+ export const RECORD_KINDS = ["operation", "behavior", "client-action"];
2
+ // --- The header grammar -------------------------------------------------------------------------
3
+ // key: value a key is lowercase words joined by hyphens, optionally prefixed `arch.`
4
+ // key: [a, b] a list; items are split on commas and trimmed, so an item can't hold a comma
5
+ // key: value # note " #" then a space (or the line's end) starts a comment
6
+ // Nothing else: no quotes, no indentation, no multi-line values.
7
+ const KEY = /^[a-z0-9][a-z0-9-]*(\.[a-z0-9][a-z0-9-]*)*$/;
8
+ const QUOTED = /^".*"$|^'.*'$/;
9
+ // A file's lines: a leading byte-order mark dropped (editors on Windows write one; it isn't
10
+ // content), CRLF and CR as LF.
11
+ export const linesOf = (raw) => raw.replace(/^\uFEFF/, "").replace(/\r\n?/g, "\n").split("\n");
12
+ // A map keyed by text from a file. With no prototype, a key such as `constructor` is just a key:
13
+ // it can't read or overwrite anything of Object's (review finding 1).
14
+ export const dict = () => Object.create(null);
15
+ export function parseRecord(raw, file, kind) {
16
+ const stem = file.slice(file.lastIndexOf("/") + 1).replace(/\.md$/, "");
17
+ const rec = { kind, file, stem, readable: false, fields: dict(), sections: [] };
18
+ const findings = [];
19
+ const say = (rule, line, message, field) => findings.push({ rule, level: "error", file, line, ...(field ? { field } : {}), message });
20
+ const lines = linesOf(raw);
21
+ // Text that isn't NFC looks the same as text that is, but compares different (a name, a digest).
22
+ lines.forEach((l, i) => { if (l !== l.normalize("NFC"))
23
+ say("operbe/not-nfc", i + 1, "this line isn't Unicode NFC; retype the accented letters"); });
24
+ const end = lines[0] === "---" ? lines.indexOf("---", 1) : -1;
25
+ if (end < 0)
26
+ return { rec, findings }; // check reports operbe/no-header
27
+ rec.readable = true;
28
+ for (let i = 1; i < end; i++) {
29
+ const n = i + 1, line = lines[i];
30
+ if (!line.trim())
31
+ continue;
32
+ // The comment. " #x" is a trap: it reads as part of the value but would cut it off here.
33
+ let body = line;
34
+ const hash = line.indexOf(" #");
35
+ if (hash >= 0) {
36
+ const after = line[hash + 2];
37
+ if (after !== undefined && after !== " ")
38
+ say("operbe/comment-cuts-value", n, `' #' starts a comment, so the value is cut off at '${line.slice(hash + 1)}'; put a space after '#' if it is a comment`);
39
+ body = line.slice(0, hash);
40
+ }
41
+ const colon = body.indexOf(":");
42
+ const key = colon < 0 ? "" : body.slice(0, colon);
43
+ if (!KEY.test(key)) {
44
+ say("operbe/header-line", n, "a header line is 'key: value', the key in lowercase words joined by hyphens");
45
+ continue;
46
+ }
47
+ if (key in rec.fields) {
48
+ say("operbe/duplicate-key", n, `'${key}' is already set above; this line is ignored`, key);
49
+ continue;
50
+ }
51
+ const text = body.slice(colon + 1).trim();
52
+ let value = text;
53
+ if (text.startsWith("[")) {
54
+ if (!text.endsWith("]"))
55
+ say("operbe/list-syntax", n, "a list starts with '[' and ends with ']'", key);
56
+ else {
57
+ const inner = text.slice(1, -1).trim();
58
+ value = inner ? inner.split(",").map((x) => x.trim()) : [];
59
+ if (value.some((x) => !x))
60
+ say("operbe/list-syntax", n, "a list has an empty item", key);
61
+ if (value.some((x) => /^"|"$/.test(x)))
62
+ say("operbe/quoted-value", n, "quotes aren't part of the header grammar, and a list item can't hold a comma; write the items bare", key);
63
+ }
64
+ }
65
+ else if (QUOTED.test(text))
66
+ say("operbe/quoted-value", n, "quotes aren't part of the header grammar and would be kept as written; write the value bare", key);
67
+ rec.fields[key] = { value, line: n };
68
+ }
69
+ // Sections: each starts at a "## " line and runs to the next one. Text before the first belongs to none.
70
+ // A "## " line inside a fenced code block (``` or ~~~) is text, not a heading.
71
+ let cur = null, fence = "";
72
+ const close = () => { if (cur)
73
+ rec.sections.push({ title: cur.title, line: cur.line, text: cur.body.join("\n").trim() }); };
74
+ for (let i = end + 1; i < lines.length; i++) {
75
+ const f = lines[i].match(/^ {0,3}(`{3,}|~{3,})/)?.[1];
76
+ if (f && (!fence || (f[0] === fence[0] && f.length >= fence.length)))
77
+ fence = fence ? "" : f;
78
+ const m = fence ? null : lines[i].match(/^## +(.+)$/);
79
+ if (!m) {
80
+ cur?.body.push(lines[i]);
81
+ continue;
82
+ }
83
+ close();
84
+ const title = m[1].trim();
85
+ if (rec.sections.some((s) => s.title === title))
86
+ say("operbe/duplicate-section", i + 1, `section '${title}' is already written above; only the first is read`);
87
+ cur = { title, line: i + 1, body: [] };
88
+ }
89
+ close();
90
+ rec.sections = rec.sections.filter((s, i, all) => all.findIndex((t) => t.title === s.title) === i);
91
+ return { rec, findings };
92
+ }
93
+ // --- Field access, shared with check --------------------------------------------------------------
94
+ export const str = (r, k) => { const v = r?.fields[k]?.value; return typeof v === "string" ? v : ""; };
95
+ export const list = (r, k) => { const v = r?.fields[k]?.value; return Array.isArray(v) ? v : []; };
96
+ export const section = (r, title) => r.sections.find((s) => s.title === title)?.text ?? "";
97
+ // Project-relative folder from a profile value: "./ops/" -> "ops". null: it would leave the project
98
+ // ("..", or an absolute path), which read refuses: a profile can't make operbe read outside its root.
99
+ const folder = (v) => (/^[/\\]|^[a-zA-Z]:|(^|[/\\])\.\.([/\\]|$)/.test(v) ? null : v.split("/").filter((p) => p && p !== ".").join("/"));
100
+ // A UI or architecture name becomes one path segment, so it is a plain name: no slash, no dot first.
101
+ const SEGMENT = /^[^/\\.][^/\\]*$/;
102
+ // --- The project ---------------------------------------------------------------------------------
103
+ export function read(src) {
104
+ const findings = [];
105
+ // Every file goes through here. One left mid-merge (git's or jj's conflict markers in the folder)
106
+ // says so, rather than surfacing only as header lines that don't parse.
107
+ const get = (file) => {
108
+ const text = src.read(file);
109
+ const i = text === null ? -1 : linesOf(text).findIndex((l) => /^<{7}( |$)/.test(l));
110
+ if (i >= 0)
111
+ findings.push({ rule: "operbe/conflict", level: "error", file, line: i + 1, message: "this file has conflict markers; resolve the conflict, and check again" });
112
+ return text;
113
+ };
114
+ const empty = { profile: null, uis: [], folders: { operations: "operations", behaviors: "behaviors", clientActions: null }, absent: [], operations: [], behaviors: [], clientActions: [], coverage: {}, architectures: [], findings };
115
+ const raw = get("operbe.md");
116
+ if (raw === null) {
117
+ findings.push({ rule: "operbe/no-profile", level: "error", file: "operbe.md", message: "operbe.md not found; see references/adopting.md" });
118
+ return empty;
119
+ }
120
+ const load = (file, kind) => {
121
+ const text = get(file);
122
+ if (text === null)
123
+ return null;
124
+ const { rec, findings: f } = parseRecord(text, file, kind);
125
+ findings.push(...f);
126
+ return rec;
127
+ };
128
+ const profile = load("operbe.md", "profile");
129
+ const outside = (field, what) => findings.push({ rule: "operbe/path", level: "error", file: "operbe.md", line: profile.fields[field]?.line, field, message: `${what} would be read from outside the project; name something inside it` });
130
+ const dirOf = (field) => { const d = folder(str(profile, field)); if (d === null)
131
+ outside(field, `'${str(profile, field)}'`); return d; };
132
+ const named = (field) => list(profile, field).filter((n) => SEGMENT.test(n) || (outside(field, `'${n}'`), false));
133
+ const uis = named("uis");
134
+ const ops = dirOf("operations") || "operations";
135
+ const behs = dirOf("behaviors") || "behaviors";
136
+ const acts = "client-actions" in profile.fields ? dirOf("client-actions") ?? "" : null;
137
+ // Every .md file in a folder, except the generated files of operbe ≤ 0.2 and a README.
138
+ const records = (dir, kind, keep = () => true) => (src.list(dir) ?? []).filter((f) => f.endsWith(".md") && keep(f)).map((f) => load(`${dir}/${f}`, kind)).filter((r) => r !== null);
139
+ const coverage = dict();
140
+ for (const ui of uis) {
141
+ const file = `${behs}/coverage/${ui}.md`, text = get(file);
142
+ const lines = text === null ? null : linesOf(text);
143
+ if (lines?.at(-1) === "")
144
+ lines.pop();
145
+ coverage[ui] = { file, lines: lines?.map((l, i) => ({ line: i + 1, cells: cellsOf(l) })) ?? null };
146
+ }
147
+ const architectures = named("architectures").flatMap((name) => {
148
+ const file = `${name}/architecture.md`, text = get(file);
149
+ if (text === null)
150
+ return []; // no declaration: operbe stays hands-off
151
+ const { arch, findings: f } = parseArchitecture(text, file, name);
152
+ findings.push(...f);
153
+ return [arch];
154
+ });
155
+ return {
156
+ profile, uis, findings, coverage, architectures,
157
+ folders: { operations: ops, behaviors: behs, clientActions: acts },
158
+ absent: [ops, behs, ...(acts ? [acts] : [])].filter((d) => src.list(d) === null),
159
+ operations: records(ops, "operation"),
160
+ behaviors: records(behs, "behavior", (f) => f.startsWith("B-")),
161
+ clientActions: acts ? records(acts, "client-action", (f) => f !== "INDEX.md" && f !== "README.md") : [],
162
+ };
163
+ }
164
+ // A table row's cells, trimmed. `\|` is a pipe inside a cell, as in GitHub's tables.
165
+ const cellsOf = (l) => l.trim().replace(/^\|+|(?<!\\)\|+$/g, "").split(/(?<!\\)\|/).map((c) => c.trim().replace(/\\\|/g, "|"));
166
+ // "[a, b]" -> ["a", "b"]; anything else -> null.
167
+ const cellList = (c) => (/^\[.*\]$/.test(c) ? c.slice(1, -1).split(",").map((x) => x.trim()).filter(Boolean) : null);
168
+ export function parseArchitecture(raw, file, name) {
169
+ const { rec, findings } = parseRecord(raw, file, "architecture");
170
+ const arch = { name, file, fields: [], diffRules: [] };
171
+ const bad = (line, message) => findings.push({ rule: "operbe/declaration", level: "error", file, line, message });
172
+ if (!rec.readable)
173
+ return { arch, findings };
174
+ if (str(rec, "architecture") !== name)
175
+ bad(rec.fields.architecture?.line ?? 1, `architecture must be '${name}', the folder it is in`);
176
+ if (str(rec, "format") !== "1")
177
+ bad(rec.fields.format?.line ?? 1, "format must be 1, the declaration format this build reads");
178
+ // The tables, by section, with each row's line. The first row names the columns; a |---| row is skipped.
179
+ const tables = dict();
180
+ let title = "", cols = null;
181
+ linesOf(raw).forEach((l, i) => {
182
+ const h = l.match(/^## +(.+)$/);
183
+ if (h) {
184
+ title = h[1].trim();
185
+ cols = null;
186
+ return;
187
+ }
188
+ if (!l.trim().startsWith("|"))
189
+ return;
190
+ const cells = cellsOf(l);
191
+ if (!cols) {
192
+ cols = cells;
193
+ return;
194
+ }
195
+ if (cells.every((c) => /^:?-+:?$/.test(c)))
196
+ return;
197
+ const row = dict();
198
+ cols.forEach((c, k) => { row[c] = cells[k] ?? ""; });
199
+ (tables[title] ??= []).push({ line: i + 1, row });
200
+ });
201
+ for (const { line, row } of tables["Fields"] ?? []) {
202
+ const { field, on, required, values } = row;
203
+ if (!field?.startsWith(`${name}.`)) {
204
+ bad(line, `field '${field ?? ""}' must start with '${name}.'`);
205
+ continue;
206
+ }
207
+ if (!RECORD_KINDS.includes(on)) {
208
+ bad(line, `on must be one of ${RECORD_KINDS.join(", ")}`);
209
+ continue;
210
+ }
211
+ let req;
212
+ const when = required?.match(/^when (\S+) is (.+)$/);
213
+ if (required === "yes" || required === "no")
214
+ req = required;
215
+ else if (when)
216
+ req = { when: when[1], is: cellList(when[2]) ?? [when[2]] };
217
+ else {
218
+ bad(line, "required must be yes, no, 'when <field> is <value>' or 'when <field> is [a, b]'");
219
+ continue;
220
+ }
221
+ const vs = values ? cellList(values) : null;
222
+ if (values && !vs) {
223
+ bad(line, "values must be a list: [a, b]");
224
+ continue;
225
+ }
226
+ if (arch.fields.some((f) => f.field === field && f.on === on)) {
227
+ bad(line, `'${field}' on ${on} is already declared above; this row is ignored`);
228
+ continue;
229
+ }
230
+ arch.fields.push({ field, on: on, required: req, values: vs, line });
231
+ }
232
+ for (const { line, row } of tables["Diff rules"] ?? []) {
233
+ const { field, change, level } = row;
234
+ if (!arch.fields.some((f) => f.field === field)) {
235
+ bad(line, `diff rule for '${field}', which isn't declared under Fields`);
236
+ continue;
237
+ }
238
+ if (!["added", "removed", "changed"].includes(change)) {
239
+ bad(line, "change must be added, removed or changed");
240
+ continue;
241
+ }
242
+ if (!["breaking", "warning", "info"].includes(level)) {
243
+ bad(line, "level must be breaking, warning or info");
244
+ continue;
245
+ }
246
+ arch.diffRules.push({ field, change: change, level: level, line });
247
+ }
248
+ return { arch, findings };
249
+ }
@@ -0,0 +1,9 @@
1
+ import type { Finding } from "./findings.ts";
2
+ import { type Model } from "./read.ts";
3
+ export interface ReconcileQuery {
4
+ kind: "operation" | "client-action";
5
+ ui?: string;
6
+ names: string[];
7
+ via?: string;
8
+ }
9
+ export declare function reconcile(m: Model, q: ReconcileQuery): Finding[];
@@ -0,0 +1,46 @@
1
+ import { str } from "./read.js";
2
+ export function reconcile(m, q) {
3
+ if (q.kind === "client-action" && !q.ui)
4
+ throw new TypeError("reconcile: a client-action query needs `ui`");
5
+ const out = [];
6
+ const folder = (q.kind === "operation" ? m.folders.operations : m.folders.clientActions) ?? "client-actions";
7
+ // Client actions: only those this UI should have. Retired ones are no longer anyone's to build.
8
+ const records = q.kind === "operation" ? m.operations : m.clientActions.filter((a) => {
9
+ const to = a.fields["applies-to"]?.value;
10
+ return str(a, "status") !== "retired" && (to === "all" ? m.uis : Array.isArray(to) ? to : []).includes(q.ui);
11
+ });
12
+ const nameOf = (r) => str(r, "name") || r.stem;
13
+ const say = (r, level, rule, message, field) => {
14
+ const line = r && field ? r.fields[field]?.line : undefined;
15
+ out.push({ rule, level, file: r ? r.file : folder, ...(line ? { line } : {}), ...(r ? { record: nameOf(r) } : {}), ...(field ? { field } : {}), message });
16
+ };
17
+ const code = new Set(q.names), owner = new Map(), matched = new Set(), claimedAny = new Set();
18
+ if (q.via)
19
+ for (const r of records) {
20
+ const v = r.fields[q.via]?.value;
21
+ for (const c of Array.isArray(v) ? v : v ? [v] : []) {
22
+ claimedAny.add(r);
23
+ if (owner.has(c) && owner.get(c) !== r) {
24
+ say(r, "error", "operbe/reconcile-claimed-twice", `${q.via} '${c}' is also claimed by ${nameOf(owner.get(c))}`, q.via);
25
+ continue;
26
+ }
27
+ owner.set(c, r);
28
+ if (!code.has(c))
29
+ say(r, "error", "operbe/reconcile-absent", `${q.via} '${c}' is not a name the code defines`, q.via);
30
+ }
31
+ }
32
+ const byName = new Map(records.map((r) => [nameOf(r), r]));
33
+ for (const n of [...code].sort()) {
34
+ // A record that lists its names in --via answers for those only, never for its own name too.
35
+ const r = owner.get(n) ?? (byName.get(n) && !claimedAny.has(byName.get(n)) ? byName.get(n) : undefined);
36
+ if (r)
37
+ matched.add(r);
38
+ else
39
+ say(null, "error", "operbe/reconcile-unlisted", `'${n}' is in the code${q.ui ? ` (${q.ui})` : ""}, but no ${q.kind} record ${q.via ? `names it in ${q.via} or ` : ""}has that name`);
40
+ }
41
+ // A record whose claims are all absent already has an error for each; don't add a gap on top.
42
+ for (const r of records)
43
+ if (!matched.has(r) && !claimedAny.has(r))
44
+ say(r, "gap", "operbe/reconcile-unbuilt", `no name in the code${q.ui ? ` (${q.ui})` : ""} matches this ${q.kind}${q.via ? ` (by name; it has no ${q.via})` : ""}`);
45
+ return out;
46
+ }
@@ -0,0 +1,5 @@
1
+ export interface Source {
2
+ list(dir: string): string[] | null;
3
+ read(path: string): string | null;
4
+ }
5
+ export declare function folderSource(root: string): Source;
package/dist/source.js ADDED
@@ -0,0 +1,29 @@
1
+ // Where a project's files come from. The core reads only through this, so it never touches the
2
+ // disk itself: a working folder (folderSource, below), a jj commit (operbe/jj), or a test's
3
+ // in-memory files all look the same to it.
4
+ //
5
+ // Paths are project-relative POSIX ("operations/archive-conversation.md"); "" is the root.
6
+ import { readdirSync, readFileSync } from "node:fs";
7
+ import { join } from "node:path";
8
+ // The working folder at `root`.
9
+ export function folderSource(root) {
10
+ const abs = (p) => join(root, ...p.split("/"));
11
+ return {
12
+ list(dir) {
13
+ try {
14
+ return readdirSync(abs(dir), { withFileTypes: true }).filter((e) => !e.isDirectory()).map((e) => e.name).sort();
15
+ }
16
+ catch {
17
+ return null;
18
+ }
19
+ },
20
+ read(path) {
21
+ try {
22
+ return readFileSync(abs(path), "utf8");
23
+ }
24
+ catch {
25
+ return null;
26
+ }
27
+ },
28
+ };
29
+ }
@@ -0,0 +1 @@
1
+ export declare const VERSION = "1.0.0-rc.2";
@@ -0,0 +1,2 @@
1
+ // This build's version, as in package.json (test/describe.ts keeps the two equal).
2
+ export const VERSION = "1.0.0-rc.2";
package/package.json CHANGED
@@ -1,6 +1,42 @@
1
1
  {
2
2
  "name": "operbe",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0-rc.2",
4
+ "description": "operbe, the operations and behaviors method: read, check, reconcile, describe and diff a project's operations, behaviors and client actions.",
5
+ "license": "MIT",
6
+ "author": "Trevor Schoeny",
7
+ "repository": "https://github.com/trevorschoeny/operbe",
8
+ "type": "module",
9
+ "engines": {
10
+ "node": ">=22"
11
+ },
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "default": "./dist/index.js"
16
+ },
17
+ "./jj": {
18
+ "types": "./dist/jj.d.ts",
19
+ "default": "./dist/jj.js"
20
+ }
21
+ },
22
+ "bin": {
23
+ "operbe": "dist/cli.js"
24
+ },
25
+ "files": [
26
+ "dist",
27
+ "skills",
28
+ "schema",
29
+ "conformance",
30
+ "!**/__pycache__"
31
+ ],
32
+ "scripts": {
33
+ "build": "rm -rf dist && tsc",
34
+ "prepare": "npm run build",
35
+ "check": "npm run build && node --disable-warning=ExperimentalWarning test/read.ts && node --disable-warning=ExperimentalWarning test/declare.ts && node --disable-warning=ExperimentalWarning test/describe.ts && node --disable-warning=ExperimentalWarning test/diff.ts && node --disable-warning=ExperimentalWarning test/review.ts && node --disable-warning=ExperimentalWarning test/rename.ts && node --disable-warning=ExperimentalWarning test/tools.ts && node --disable-warning=ExperimentalWarning test/jj.ts && node --disable-warning=ExperimentalWarning test/parity.ts && node --disable-warning=ExperimentalWarning test/pack.ts"
36
+ },
37
+ "devDependencies": {
38
+ "@types/node": "^26.6.11",
39
+ "ajv": "^8.20.0",
40
+ "typescript": "^7.0.2"
41
+ }
42
+ }