@richjava/req0 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +117 -0
- package/cockpit/android-chrome-192x192.png +0 -0
- package/cockpit/android-chrome-512x512.png +0 -0
- package/cockpit/app.js +1710 -0
- package/cockpit/apple-touch-icon.png +0 -0
- package/cockpit/favicon-16x16.png +0 -0
- package/cockpit/favicon-32x32.png +0 -0
- package/cockpit/favicon.ico +0 -0
- package/cockpit/index.html +180 -0
- package/cockpit/markdown-editor.js +93 -0
- package/cockpit/req0-logo-horiz.png +0 -0
- package/cockpit/req0-logo-stacked.png +0 -0
- package/cockpit/site.webmanifest +19 -0
- package/cockpit/styles.css +1710 -0
- package/cockpit/tokens.css +118 -0
- package/dist/adapter.d.ts +5 -0
- package/dist/adapter.js +16 -0
- package/dist/browser.d.ts +33 -0
- package/dist/browser.js +524 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +265 -0
- package/dist/compile.d.ts +5 -0
- package/dist/compile.js +456 -0
- package/dist/diff.d.ts +15 -0
- package/dist/diff.js +114 -0
- package/dist/fix-from-proof.d.ts +13 -0
- package/dist/fix-from-proof.js +61 -0
- package/dist/gates.d.ts +7 -0
- package/dist/gates.js +7 -0
- package/dist/implement-brief.d.ts +9 -0
- package/dist/implement-brief.js +142 -0
- package/dist/implement.d.ts +70 -0
- package/dist/implement.js +615 -0
- package/dist/improve-log.d.ts +11 -0
- package/dist/improve-log.js +38 -0
- package/dist/improve-review.d.ts +45 -0
- package/dist/improve-review.js +182 -0
- package/dist/improve.d.ts +16 -0
- package/dist/improve.js +127 -0
- package/dist/jev-pack.d.ts +2 -0
- package/dist/jev-pack.js +114 -0
- package/dist/jev.d.ts +23 -0
- package/dist/jev.js +142 -0
- package/dist/pack.d.ts +101 -0
- package/dist/pack.js +609 -0
- package/dist/personas.d.ts +13 -0
- package/dist/personas.js +88 -0
- package/dist/proof-report.d.ts +8 -0
- package/dist/proof-report.js +82 -0
- package/dist/proof.d.ts +45 -0
- package/dist/proof.js +394 -0
- package/dist/qa-plan.d.ts +6 -0
- package/dist/qa-plan.js +58 -0
- package/dist/ready.d.ts +29 -0
- package/dist/ready.js +317 -0
- package/dist/runtime.d.ts +25 -0
- package/dist/runtime.js +125 -0
- package/dist/server.d.ts +15 -0
- package/dist/server.js +588 -0
- package/dist/stack.d.ts +35 -0
- package/dist/stack.js +220 -0
- package/dist/stages.d.ts +15 -0
- package/dist/stages.js +345 -0
- package/dist/template.d.ts +5 -0
- package/dist/template.js +55 -0
- package/dist/types.d.ts +282 -0
- package/dist/types.js +12 -0
- package/docs/requirement-template.md +341 -0
- package/package.json +81 -0
package/dist/compile.js
ADDED
|
@@ -0,0 +1,456 @@
|
|
|
1
|
+
import { emptyReady } from "./ready.js";
|
|
2
|
+
import { emptyStages } from "./stages.js";
|
|
3
|
+
import { OPTIONAL_H2, REQUIRED_H2, } from "./types.js";
|
|
4
|
+
const REQUIRED_SET = new Set(REQUIRED_H2);
|
|
5
|
+
const OPTIONAL_SET = new Set(OPTIONAL_H2);
|
|
6
|
+
const ALLOWED_H2 = new Set([...REQUIRED_H2, ...OPTIONAL_H2]);
|
|
7
|
+
const RULE_ID = /^BR-\d{3}$/;
|
|
8
|
+
const USE_CASE_ID = /^UC-\d{3}$/;
|
|
9
|
+
const ACTION_ID = /^[A-Za-z][A-Za-z0-9-]*$/;
|
|
10
|
+
const FOLDER_ID = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
11
|
+
const FIELD = /^(?:-\s*)?([A-Za-z][A-Za-z ]*):[ \t]*(.*)$/;
|
|
12
|
+
const NUMBERED = /^(\d+)\.\s+(.*)$/;
|
|
13
|
+
const H1 = /^#\s+(.+)$/;
|
|
14
|
+
const H2 = /^##\s+(.+)$/;
|
|
15
|
+
const H3 = /^###\s+(.+)$/;
|
|
16
|
+
export function isRequirementId(id) {
|
|
17
|
+
return FOLDER_ID.test(id);
|
|
18
|
+
}
|
|
19
|
+
export function compileMarkdown(requirementId, markdown) {
|
|
20
|
+
const findings = [];
|
|
21
|
+
const note = (line, message, severity = "error") => {
|
|
22
|
+
findings.push({ line, severity, message });
|
|
23
|
+
};
|
|
24
|
+
if (!isRequirementId(requirementId)) {
|
|
25
|
+
note(1, `Requirement folder must be kebab-case [a-z0-9-]+ (got "${requirementId}").`);
|
|
26
|
+
}
|
|
27
|
+
const trimmed = markdown.replace(/^\uFEFF/, "");
|
|
28
|
+
if (trimmed.trim().length === 0) {
|
|
29
|
+
return {
|
|
30
|
+
spec: null,
|
|
31
|
+
markdown,
|
|
32
|
+
health: buildHealth(requirementId, "empty", [
|
|
33
|
+
{ line: 1, severity: "error", message: "requirement.md is empty. Create the requirement to start." },
|
|
34
|
+
]),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
const lines = trimmed.split(/\r?\n/);
|
|
38
|
+
let title = "";
|
|
39
|
+
let titleLine = 0;
|
|
40
|
+
const h2Blocks = [];
|
|
41
|
+
let current = null;
|
|
42
|
+
const seenH2 = new Map();
|
|
43
|
+
for (let i = 0; i < lines.length; i++) {
|
|
44
|
+
const lineNo = i + 1;
|
|
45
|
+
const raw = lines[i] ?? "";
|
|
46
|
+
const h1 = raw.match(H1);
|
|
47
|
+
const h2 = raw.match(H2);
|
|
48
|
+
if (h1 && !raw.startsWith("##")) {
|
|
49
|
+
if (title) {
|
|
50
|
+
note(lineNo, "Only one top-level heading is allowed.");
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
title = h1[1]?.trim() ?? "";
|
|
54
|
+
titleLine = lineNo;
|
|
55
|
+
}
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (h2) {
|
|
59
|
+
const heading = h2[1]?.trim() ?? "";
|
|
60
|
+
if (!ALLOWED_H2.has(heading)) {
|
|
61
|
+
note(lineNo, `Unknown section "## ${heading}". Allowed optional sections: ${OPTIONAL_H2.join(", ")}.`);
|
|
62
|
+
}
|
|
63
|
+
const prev = seenH2.get(heading);
|
|
64
|
+
if (prev) {
|
|
65
|
+
note(lineNo, `Duplicate section "## ${heading}" (already at line ${prev}).`);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
seenH2.set(heading, lineNo);
|
|
69
|
+
}
|
|
70
|
+
current = { title: heading, line: lineNo, body: [], start: lineNo };
|
|
71
|
+
h2Blocks.push(current);
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (current)
|
|
75
|
+
current.body.push(raw);
|
|
76
|
+
}
|
|
77
|
+
if (!title) {
|
|
78
|
+
note(1, "Missing top-level heading (# Requirement title).");
|
|
79
|
+
}
|
|
80
|
+
for (const required of REQUIRED_H2) {
|
|
81
|
+
if (!seenH2.has(required)) {
|
|
82
|
+
note(titleLine || 1, `Missing required section "## ${required}".`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const optional = {};
|
|
86
|
+
let businessRules = [];
|
|
87
|
+
let useCases = [];
|
|
88
|
+
let matrix = { roles: [], actions: [] };
|
|
89
|
+
for (const block of h2Blocks) {
|
|
90
|
+
if (!ALLOWED_H2.has(block.title))
|
|
91
|
+
continue;
|
|
92
|
+
if (OPTIONAL_SET.has(block.title)) {
|
|
93
|
+
optional[block.title] = block.body.join("\n").trim();
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (block.title === "Business Rules") {
|
|
97
|
+
businessRules = parseRules(block.body, block.line, note);
|
|
98
|
+
}
|
|
99
|
+
else if (block.title === "Use Cases") {
|
|
100
|
+
useCases = parseUseCases(block.body, block.line, note);
|
|
101
|
+
}
|
|
102
|
+
else if (block.title === "Roles & Permissions") {
|
|
103
|
+
matrix = parseMatrix(block.body, block.line, note);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const ids = new Map();
|
|
107
|
+
for (const item of [...businessRules, ...useCases]) {
|
|
108
|
+
const existing = ids.get(item.id);
|
|
109
|
+
if (existing) {
|
|
110
|
+
note(item.line, `Duplicate id ${item.id} (already at line ${existing}).`);
|
|
111
|
+
}
|
|
112
|
+
else if (item.id) {
|
|
113
|
+
ids.set(item.id, item.line);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const roleSet = new Set(matrix.roles);
|
|
117
|
+
for (const uc of useCases) {
|
|
118
|
+
if (uc.actor && roleSet.size > 0 && !roleSet.has(uc.actor)) {
|
|
119
|
+
note(uc.line, `Use case ${uc.id || uc.title} actor "${uc.actor}" is not a column in Roles & Permissions.`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const hasStructure = Boolean(seenH2.get("Business Rules")) &&
|
|
123
|
+
Boolean(seenH2.get("Use Cases")) &&
|
|
124
|
+
Boolean(seenH2.get("Roles & Permissions"));
|
|
125
|
+
const hasContent = businessRules.length > 0 && useCases.length > 0 && matrix.actions.length > 0;
|
|
126
|
+
const errors = findings.filter((f) => f.severity === "error");
|
|
127
|
+
if (hasStructure && !hasContent && errors.length === 0) {
|
|
128
|
+
if (businessRules.length === 0) {
|
|
129
|
+
note(seenH2.get("Business Rules") ?? 1, "Business Rules needs at least one rule.");
|
|
130
|
+
}
|
|
131
|
+
if (useCases.length === 0) {
|
|
132
|
+
note(seenH2.get("Use Cases") ?? 1, "Use Cases needs at least one use case.");
|
|
133
|
+
}
|
|
134
|
+
if (matrix.actions.length === 0) {
|
|
135
|
+
note(seenH2.get("Roles & Permissions") ?? 1, "Roles & Permissions needs at least one action row.");
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const errorCount = findings.filter((f) => f.severity === "error").length;
|
|
139
|
+
const spec = errorCount === 0 && hasContent
|
|
140
|
+
? { requirementId, title, optional, businessRules, useCases, matrix }
|
|
141
|
+
: null;
|
|
142
|
+
let specState = "drafting";
|
|
143
|
+
if (!hasStructure && errorCount > 0 && businessRules.length === 0 && useCases.length === 0) {
|
|
144
|
+
const onlyEmpty = trimmed.trim().length < 80 && !hasStructure;
|
|
145
|
+
if (onlyEmpty && !seenH2.size)
|
|
146
|
+
specState = "empty";
|
|
147
|
+
}
|
|
148
|
+
if (spec)
|
|
149
|
+
specState = "valid";
|
|
150
|
+
if (!spec && looksEmpty(trimmed, seenH2.size))
|
|
151
|
+
specState = "empty";
|
|
152
|
+
return { spec, markdown, health: buildHealth(requirementId, specState, findings) };
|
|
153
|
+
}
|
|
154
|
+
function looksEmpty(markdown, h2Count) {
|
|
155
|
+
const text = markdown.replace(/<!--[\s\S]*?-->/g, "").trim();
|
|
156
|
+
return text.length === 0 || (h2Count === 0 && text.split("\n").length <= 2);
|
|
157
|
+
}
|
|
158
|
+
function parseRules(body, sectionLine, note) {
|
|
159
|
+
const blocks = splitH3(body, sectionLine);
|
|
160
|
+
const rules = [];
|
|
161
|
+
if (blocks.length === 0)
|
|
162
|
+
return rules;
|
|
163
|
+
for (const block of blocks) {
|
|
164
|
+
const fields = collectFields(block.lines, block.line);
|
|
165
|
+
const id = fields.get("id")?.value.trim() ?? "";
|
|
166
|
+
const statement = fields.get("statement")?.value.trim() ?? "";
|
|
167
|
+
const observable = fields.get("observable")?.value.trim() ?? "";
|
|
168
|
+
if (!RULE_ID.test(id)) {
|
|
169
|
+
note(fields.get("id")?.line ?? block.line, `Business rule id must match BR-NNN (got "${id || "missing"}").`);
|
|
170
|
+
}
|
|
171
|
+
if (!statement) {
|
|
172
|
+
note(block.line, `Business rule ${id || block.title} is missing Statement.`);
|
|
173
|
+
}
|
|
174
|
+
if (!observable) {
|
|
175
|
+
note(block.line, `Business rule ${id || block.title} is missing Observable.`);
|
|
176
|
+
}
|
|
177
|
+
rules.push({
|
|
178
|
+
id,
|
|
179
|
+
title: block.title,
|
|
180
|
+
statement,
|
|
181
|
+
observable,
|
|
182
|
+
line: block.line,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
return rules;
|
|
186
|
+
}
|
|
187
|
+
function parseUseCases(body, sectionLine, note) {
|
|
188
|
+
const blocks = splitH3(body, sectionLine);
|
|
189
|
+
const useCases = [];
|
|
190
|
+
for (const block of blocks) {
|
|
191
|
+
const { fields, steps } = collectUseCase(block.lines, block.line);
|
|
192
|
+
const id = fields.get("id")?.value.trim() ?? "";
|
|
193
|
+
const actor = fields.get("actor")?.value.trim() ?? "";
|
|
194
|
+
const preconditions = fields.get("preconditions")?.value.trim() ?? "";
|
|
195
|
+
const outcome = fields.get("outcome")?.value.trim() ?? "";
|
|
196
|
+
const alternatePaths = fields.get("alternate paths")?.value.trim() || undefined;
|
|
197
|
+
if (!USE_CASE_ID.test(id)) {
|
|
198
|
+
note(fields.get("id")?.line ?? block.line, `Use case id must match UC-NNN (got "${id || "missing"}").`);
|
|
199
|
+
}
|
|
200
|
+
if (!actor)
|
|
201
|
+
note(block.line, `Use case ${id || block.title} is missing Actor.`);
|
|
202
|
+
if (!preconditions)
|
|
203
|
+
note(block.line, `Use case ${id || block.title} is missing Preconditions.`);
|
|
204
|
+
if (steps.length === 0)
|
|
205
|
+
note(block.line, `Use case ${id || block.title} needs numbered Steps.`);
|
|
206
|
+
if (!outcome)
|
|
207
|
+
note(block.line, `Use case ${id || block.title} is missing Outcome.`);
|
|
208
|
+
useCases.push({
|
|
209
|
+
id,
|
|
210
|
+
title: block.title,
|
|
211
|
+
actor,
|
|
212
|
+
preconditions,
|
|
213
|
+
steps,
|
|
214
|
+
outcome,
|
|
215
|
+
alternatePaths,
|
|
216
|
+
line: block.line,
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
return useCases;
|
|
220
|
+
}
|
|
221
|
+
function parseMatrix(body, sectionLine, note) {
|
|
222
|
+
const startLine = sectionLine + 1;
|
|
223
|
+
const tableLines = [];
|
|
224
|
+
for (let i = 0; i < body.length; i++) {
|
|
225
|
+
const raw = body[i] ?? "";
|
|
226
|
+
const line = startLine + i;
|
|
227
|
+
if (!raw.trim().startsWith("|"))
|
|
228
|
+
continue;
|
|
229
|
+
const cells = raw
|
|
230
|
+
.split("|")
|
|
231
|
+
.slice(1, -1)
|
|
232
|
+
.map((c) => c.trim());
|
|
233
|
+
if (cells.length === 0)
|
|
234
|
+
continue;
|
|
235
|
+
tableLines.push({ line, cells });
|
|
236
|
+
}
|
|
237
|
+
if (tableLines.length < 2) {
|
|
238
|
+
note(sectionLine, "Roles & Permissions needs a markdown table with a header and at least one action row.");
|
|
239
|
+
return { roles: [], actions: [] };
|
|
240
|
+
}
|
|
241
|
+
const header = tableLines[0];
|
|
242
|
+
if (!header)
|
|
243
|
+
return { roles: [], actions: [] };
|
|
244
|
+
const actionHeader = header.cells[0] ?? "";
|
|
245
|
+
if (actionHeader !== "Action") {
|
|
246
|
+
note(header.line, `First column must be titled "Action" (got "${actionHeader}").`);
|
|
247
|
+
}
|
|
248
|
+
const roles = header.cells.slice(1);
|
|
249
|
+
if (roles.length === 0) {
|
|
250
|
+
note(header.line, "Roles & Permissions table needs at least one role column.");
|
|
251
|
+
}
|
|
252
|
+
const dup = new Map();
|
|
253
|
+
for (const role of roles) {
|
|
254
|
+
if (!role)
|
|
255
|
+
note(header.line, "Role column header cannot be blank.");
|
|
256
|
+
const prev = dup.get(role);
|
|
257
|
+
if (prev)
|
|
258
|
+
note(header.line, `Duplicate role column "${role}".`);
|
|
259
|
+
else
|
|
260
|
+
dup.set(role, 1);
|
|
261
|
+
}
|
|
262
|
+
const maybeSep = tableLines[1];
|
|
263
|
+
const sepIsSep = maybeSep &&
|
|
264
|
+
maybeSep.cells.every((c) => /^:?-{3,}:?$/.test(c.replace(/\s/g, "")) || /^:?-+:?$/.test(c));
|
|
265
|
+
const rows = sepIsSep ? tableLines.slice(2) : tableLines.slice(1);
|
|
266
|
+
if (!sepIsSep) {
|
|
267
|
+
note(maybeSep?.line ?? header.line, "Roles & Permissions table needs a separator row (| --- | --- |).");
|
|
268
|
+
}
|
|
269
|
+
const actions = [];
|
|
270
|
+
const seenActions = new Map();
|
|
271
|
+
for (const row of rows) {
|
|
272
|
+
const actionId = row.cells[0] ?? "";
|
|
273
|
+
if (!ACTION_ID.test(actionId)) {
|
|
274
|
+
note(row.line, `Action id "${actionId}" must be kebab-case or PascalCase (letters, digits, hyphen).`);
|
|
275
|
+
}
|
|
276
|
+
const prev = seenActions.get(actionId);
|
|
277
|
+
if (prev)
|
|
278
|
+
note(row.line, `Duplicate action "${actionId}" (already at line ${prev}).`);
|
|
279
|
+
else
|
|
280
|
+
seenActions.set(actionId, row.line);
|
|
281
|
+
const permissions = {};
|
|
282
|
+
for (let i = 0; i < roles.length; i++) {
|
|
283
|
+
const role = roles[i] ?? "";
|
|
284
|
+
const cell = row.cells[i + 1] ?? "";
|
|
285
|
+
if (cell !== "allow" && cell !== "deny") {
|
|
286
|
+
note(row.line, `Cell for ${role || "role"} / ${actionId || "action"} must be allow or deny (got "${cell || "blank"}").`);
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
permissions[role] = cell;
|
|
290
|
+
}
|
|
291
|
+
actions.push({ id: actionId, permissions, line: row.line });
|
|
292
|
+
}
|
|
293
|
+
return { roles, actions };
|
|
294
|
+
}
|
|
295
|
+
function splitH3(body, sectionLine) {
|
|
296
|
+
const blocks = [];
|
|
297
|
+
let current = null;
|
|
298
|
+
for (let i = 0; i < body.length; i++) {
|
|
299
|
+
const raw = body[i] ?? "";
|
|
300
|
+
const line = sectionLine + 1 + i;
|
|
301
|
+
const h3 = raw.match(H3);
|
|
302
|
+
if (h3) {
|
|
303
|
+
current = { title: h3[1]?.trim() ?? "", line, lines: [] };
|
|
304
|
+
blocks.push(current);
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
if (current)
|
|
308
|
+
current.lines.push(raw);
|
|
309
|
+
}
|
|
310
|
+
return blocks;
|
|
311
|
+
}
|
|
312
|
+
function collectFields(lines, startLine) {
|
|
313
|
+
const fields = new Map();
|
|
314
|
+
let currentKey = null;
|
|
315
|
+
for (let i = 0; i < lines.length; i++) {
|
|
316
|
+
const raw = lines[i] ?? "";
|
|
317
|
+
const line = startLine + 1 + i;
|
|
318
|
+
if (!raw.trim())
|
|
319
|
+
continue;
|
|
320
|
+
const match = raw.trim().match(FIELD);
|
|
321
|
+
if (match) {
|
|
322
|
+
const key = (match[1] ?? "").toLowerCase();
|
|
323
|
+
currentKey = key;
|
|
324
|
+
fields.set(key, { value: match[2] ?? "", line });
|
|
325
|
+
continue;
|
|
326
|
+
}
|
|
327
|
+
if (currentKey) {
|
|
328
|
+
const prev = fields.get(currentKey);
|
|
329
|
+
if (prev)
|
|
330
|
+
prev.value = `${prev.value}\n${raw}`.trim();
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
return fields;
|
|
334
|
+
}
|
|
335
|
+
function collectUseCase(lines, startLine) {
|
|
336
|
+
const fields = new Map();
|
|
337
|
+
const steps = [];
|
|
338
|
+
let currentKey = null;
|
|
339
|
+
let inSteps = false;
|
|
340
|
+
for (let i = 0; i < lines.length; i++) {
|
|
341
|
+
const raw = lines[i] ?? "";
|
|
342
|
+
const line = startLine + 1 + i;
|
|
343
|
+
const trimmed = raw.trim();
|
|
344
|
+
if (!trimmed)
|
|
345
|
+
continue;
|
|
346
|
+
const numbered = trimmed.match(NUMBERED);
|
|
347
|
+
const match = trimmed.match(FIELD);
|
|
348
|
+
if (match && (match[1] ?? "").toLowerCase() === "steps") {
|
|
349
|
+
inSteps = true;
|
|
350
|
+
currentKey = "steps";
|
|
351
|
+
const rest = (match[2] ?? "").trim();
|
|
352
|
+
const maybeNum = rest.match(NUMBERED);
|
|
353
|
+
if (maybeNum?.[2])
|
|
354
|
+
steps.push(maybeNum[2]);
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
if (inSteps && numbered?.[2]) {
|
|
358
|
+
steps.push(numbered[2]);
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
if (match) {
|
|
362
|
+
inSteps = false;
|
|
363
|
+
const key = (match[1] ?? "").toLowerCase();
|
|
364
|
+
currentKey = key;
|
|
365
|
+
fields.set(key, { value: match[2] ?? "", line });
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
if (currentKey && currentKey !== "steps") {
|
|
369
|
+
const prev = fields.get(currentKey);
|
|
370
|
+
if (prev)
|
|
371
|
+
prev.value = `${prev.value}\n${raw}`.trim();
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
return { fields, steps };
|
|
375
|
+
}
|
|
376
|
+
export function buildHealth(requirementId, specState, findings) {
|
|
377
|
+
const errors = findings.filter((f) => f.severity === "error");
|
|
378
|
+
let nextAction;
|
|
379
|
+
let howThisIsGoing;
|
|
380
|
+
if (specState === "empty") {
|
|
381
|
+
nextAction = { id: "create", label: "Create this requirement", enabled: true };
|
|
382
|
+
howThisIsGoing = "Nothing here yet. Create the pack to begin.";
|
|
383
|
+
}
|
|
384
|
+
else if (specState === "valid") {
|
|
385
|
+
nextAction = {
|
|
386
|
+
id: "check-jev",
|
|
387
|
+
label: "Check this spec with Jev",
|
|
388
|
+
enabled: true,
|
|
389
|
+
hint: "Needs TYPESAFE_API_KEY.",
|
|
390
|
+
};
|
|
391
|
+
howThisIsGoing =
|
|
392
|
+
"The pack is valid. Ready stays Not yet until a TypeSafe API key is set. Persona checks do not need a key.";
|
|
393
|
+
}
|
|
394
|
+
else {
|
|
395
|
+
const first = errors[0];
|
|
396
|
+
nextAction = {
|
|
397
|
+
id: "fix-spec",
|
|
398
|
+
label: first ? `Fix: ${truncate(first.message, 72)}` : "Finish the required sections",
|
|
399
|
+
enabled: true,
|
|
400
|
+
};
|
|
401
|
+
howThisIsGoing =
|
|
402
|
+
errors.length === 1
|
|
403
|
+
? `1 compile error. ${first?.message ?? "Keep filling the spec."}`
|
|
404
|
+
: `${errors.length} compile errors. Spec is drafting, not valid.`;
|
|
405
|
+
}
|
|
406
|
+
return {
|
|
407
|
+
requirementId,
|
|
408
|
+
spec: { state: specState, findings },
|
|
409
|
+
ready: emptyReady(specState === "valid" ? "unchecked" : "spec_invalid"),
|
|
410
|
+
build: { state: "not_yet" },
|
|
411
|
+
proof: { state: "not_yet", runtime: false, findings: [] },
|
|
412
|
+
nextAction,
|
|
413
|
+
stages: emptyStages(),
|
|
414
|
+
howThisIsGoing,
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
function truncate(text, max) {
|
|
418
|
+
return text.length <= max ? text : `${text.slice(0, max - 1)}…`;
|
|
419
|
+
}
|
|
420
|
+
export function healthToStatusMarkdown(health) {
|
|
421
|
+
const lines = [
|
|
422
|
+
`# ${health.requirementId}`,
|
|
423
|
+
"",
|
|
424
|
+
health.howThisIsGoing,
|
|
425
|
+
"",
|
|
426
|
+
`- Spec: ${health.spec.state}`,
|
|
427
|
+
`- Ready: ${health.ready.state}${health.ready.reason ? ` (${health.ready.reason})` : ""}${health.ready.jevCurrent && typeof health.ready.packNoul === "number"
|
|
428
|
+
? ` · ${health.ready.packNoul.toFixed(2)}`
|
|
429
|
+
: ""}`,
|
|
430
|
+
`- Build: ${health.build.owned === false ? "external" : health.build.state}`,
|
|
431
|
+
`- Proof: ${health.proof.state}${health.proof.runtime ? "" : " (no runtime)"}`,
|
|
432
|
+
`- Next: ${health.nextAction.label}${health.nextAction.enabled ? "" : " (not yet)"}`,
|
|
433
|
+
];
|
|
434
|
+
if (health.ready.blockers || health.ready.nits) {
|
|
435
|
+
lines.push(`- Ready blockers: ${health.ready.blockers}`, `- Ready nits: ${health.ready.nits}`);
|
|
436
|
+
}
|
|
437
|
+
if (health.spec.findings.length) {
|
|
438
|
+
lines.push("", "## Findings");
|
|
439
|
+
for (const f of health.spec.findings) {
|
|
440
|
+
lines.push(`- L${f.line} ${f.severity}: ${f.message}`);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
if (health.ready.findings.length) {
|
|
444
|
+
lines.push("", "## Ready");
|
|
445
|
+
for (const f of health.ready.findings) {
|
|
446
|
+
lines.push(`- ${f.severity}: ${f.message}`);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
if (health.proof.findings.length) {
|
|
450
|
+
lines.push("", "## Proof");
|
|
451
|
+
for (const f of health.proof.findings) {
|
|
452
|
+
lines.push(`- ${f.severity}: ${f.message}`);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
return `${lines.join("\n")}\n`;
|
|
456
|
+
}
|
package/dist/diff.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type DiffLineKind = "ctx" | "add" | "del";
|
|
2
|
+
export type DiffLine = {
|
|
3
|
+
kind: DiffLineKind;
|
|
4
|
+
text: string;
|
|
5
|
+
oldNo: number | null;
|
|
6
|
+
newNo: number | null;
|
|
7
|
+
};
|
|
8
|
+
export type DiffHunk = {
|
|
9
|
+
header: string;
|
|
10
|
+
oldStart: number;
|
|
11
|
+
newStart: number;
|
|
12
|
+
lines: DiffLine[];
|
|
13
|
+
};
|
|
14
|
+
export declare function splitLines(text: string | null): string[];
|
|
15
|
+
export declare function unifiedDiff(oldText: string | null, newText: string | null, context?: number): DiffHunk[];
|
package/dist/diff.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
export function splitLines(text) {
|
|
2
|
+
if (text == null || text === "")
|
|
3
|
+
return [];
|
|
4
|
+
const parts = text.split("\n");
|
|
5
|
+
if (parts.at(-1) === "")
|
|
6
|
+
parts.pop();
|
|
7
|
+
return parts;
|
|
8
|
+
}
|
|
9
|
+
export function unifiedDiff(oldText, newText, context = 3) {
|
|
10
|
+
if (oldText === newText)
|
|
11
|
+
return [];
|
|
12
|
+
return collapseHunks(lcsEdits(splitLines(oldText), splitLines(newText)), context);
|
|
13
|
+
}
|
|
14
|
+
function lcsEdits(before, after) {
|
|
15
|
+
const n = before.length;
|
|
16
|
+
const m = after.length;
|
|
17
|
+
const dp = Array.from({ length: n + 1 }, () => Array(m + 1).fill(0));
|
|
18
|
+
for (let i = n - 1; i >= 0; i -= 1) {
|
|
19
|
+
const row = dp[i];
|
|
20
|
+
const next = dp[i + 1];
|
|
21
|
+
if (!row)
|
|
22
|
+
continue;
|
|
23
|
+
for (let j = m - 1; j >= 0; j -= 1) {
|
|
24
|
+
row[j] =
|
|
25
|
+
before[i] === after[j]
|
|
26
|
+
? (next?.[j + 1] ?? 0) + 1
|
|
27
|
+
: Math.max(next?.[j] ?? 0, row[j + 1] ?? 0);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const edits = [];
|
|
31
|
+
let i = 0;
|
|
32
|
+
let j = 0;
|
|
33
|
+
while (i < n && j < m) {
|
|
34
|
+
if (before[i] === after[j]) {
|
|
35
|
+
edits.push({ type: "eq", line: before[i] ?? "" });
|
|
36
|
+
i += 1;
|
|
37
|
+
j += 1;
|
|
38
|
+
}
|
|
39
|
+
else if ((dp[i + 1]?.[j] ?? 0) >= (dp[i]?.[j + 1] ?? 0)) {
|
|
40
|
+
edits.push({ type: "del", line: before[i] ?? "" });
|
|
41
|
+
i += 1;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
edits.push({ type: "add", line: after[j] ?? "" });
|
|
45
|
+
j += 1;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
while (i < n) {
|
|
49
|
+
edits.push({ type: "del", line: before[i] ?? "" });
|
|
50
|
+
i += 1;
|
|
51
|
+
}
|
|
52
|
+
while (j < m) {
|
|
53
|
+
edits.push({ type: "add", line: after[j] ?? "" });
|
|
54
|
+
j += 1;
|
|
55
|
+
}
|
|
56
|
+
return edits;
|
|
57
|
+
}
|
|
58
|
+
function collapseHunks(edits, context) {
|
|
59
|
+
let oldNo = 1;
|
|
60
|
+
let newNo = 1;
|
|
61
|
+
const marked = edits.map((edit) => {
|
|
62
|
+
if (edit.type === "eq") {
|
|
63
|
+
const row = { ...edit, oldNo, newNo, change: false };
|
|
64
|
+
oldNo += 1;
|
|
65
|
+
newNo += 1;
|
|
66
|
+
return row;
|
|
67
|
+
}
|
|
68
|
+
if (edit.type === "del") {
|
|
69
|
+
const row = { ...edit, oldNo, newNo: null, change: true };
|
|
70
|
+
oldNo += 1;
|
|
71
|
+
return row;
|
|
72
|
+
}
|
|
73
|
+
const row = { ...edit, oldNo: null, newNo, change: true };
|
|
74
|
+
newNo += 1;
|
|
75
|
+
return row;
|
|
76
|
+
});
|
|
77
|
+
const changeIdx = marked.flatMap((edit, index) => (edit.change ? [index] : []));
|
|
78
|
+
if (changeIdx.length === 0)
|
|
79
|
+
return [];
|
|
80
|
+
const ranges = [];
|
|
81
|
+
let start = Math.max(0, (changeIdx[0] ?? 0) - context);
|
|
82
|
+
let end = Math.min(marked.length, (changeIdx[0] ?? 0) + 1 + context);
|
|
83
|
+
for (const index of changeIdx.slice(1)) {
|
|
84
|
+
const nextStart = Math.max(0, index - context);
|
|
85
|
+
const nextEnd = Math.min(marked.length, index + 1 + context);
|
|
86
|
+
if (nextStart <= end) {
|
|
87
|
+
end = nextEnd;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
ranges.push({ start, end });
|
|
91
|
+
start = nextStart;
|
|
92
|
+
end = nextEnd;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
ranges.push({ start, end });
|
|
96
|
+
return ranges.map((range) => {
|
|
97
|
+
const slice = marked.slice(range.start, range.end);
|
|
98
|
+
const oldLines = slice.filter((edit) => edit.oldNo != null);
|
|
99
|
+
const newLines = slice.filter((edit) => edit.newNo != null);
|
|
100
|
+
const oldStart = oldLines[0]?.oldNo ?? 0;
|
|
101
|
+
const newStart = newLines[0]?.newNo ?? 0;
|
|
102
|
+
return {
|
|
103
|
+
header: `@@ -${oldStart},${oldLines.length} +${newStart},${newLines.length} @@`,
|
|
104
|
+
oldStart,
|
|
105
|
+
newStart,
|
|
106
|
+
lines: slice.map((edit) => ({
|
|
107
|
+
kind: edit.type === "eq" ? "ctx" : edit.type === "del" ? "del" : "add",
|
|
108
|
+
text: edit.line,
|
|
109
|
+
oldNo: edit.oldNo,
|
|
110
|
+
newNo: edit.newNo,
|
|
111
|
+
})),
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Health, ProofMeter, ReadyMeter, SpecAst } from "./types.js";
|
|
2
|
+
export declare class FixFromProofLockedError extends Error {
|
|
3
|
+
readonly code = "fix_from_proof_gate";
|
|
4
|
+
constructor(message?: string);
|
|
5
|
+
}
|
|
6
|
+
export declare function fixFromProofAllowed(health: Health, ready?: ReadyMeter): boolean;
|
|
7
|
+
export declare function assertFixFromProofAllowed(health: Health, ready?: ReadyMeter): void;
|
|
8
|
+
export declare function emitFixFromProofBrief(input: {
|
|
9
|
+
spec: SpecAst;
|
|
10
|
+
proof: ProofMeter;
|
|
11
|
+
reportPath: string;
|
|
12
|
+
implementBriefPath: string;
|
|
13
|
+
}): string;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export class FixFromProofLockedError extends Error {
|
|
2
|
+
code = "fix_from_proof_gate";
|
|
3
|
+
constructor(message = "Fix from proof is only after Ready, a succeeded Build, and a Proof that failed or needs review.") {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = "FixFromProofLockedError";
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export function fixFromProofAllowed(health, ready = health.ready) {
|
|
9
|
+
if (health.build.owned === false)
|
|
10
|
+
return false;
|
|
11
|
+
if (ready.state !== "ready")
|
|
12
|
+
return false;
|
|
13
|
+
if (health.build.state !== "succeeded")
|
|
14
|
+
return false;
|
|
15
|
+
if (health.build.needsStack)
|
|
16
|
+
return false;
|
|
17
|
+
return health.proof.state === "failed" || health.proof.state === "needs_review";
|
|
18
|
+
}
|
|
19
|
+
export function assertFixFromProofAllowed(health, ready = health.ready) {
|
|
20
|
+
if (!fixFromProofAllowed(health, ready)) {
|
|
21
|
+
throw new FixFromProofLockedError();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export function emitFixFromProofBrief(input) {
|
|
25
|
+
const open = input.proof.findings.filter((finding) => finding.severity === "fail" || finding.severity === "review");
|
|
26
|
+
const lines = [
|
|
27
|
+
`# Fix from proof: ${input.spec.title}`,
|
|
28
|
+
"",
|
|
29
|
+
"Portable coding-agent brief. Close the failed and review cases from the last Prove. Do not invent rule, use-case, or role IDs.",
|
|
30
|
+
"",
|
|
31
|
+
"## Read these first",
|
|
32
|
+
"",
|
|
33
|
+
`- Last Prove: \`${input.reportPath}\` — same UC- IDs as requirement.md. Failed and Needs review first.`,
|
|
34
|
+
`- Full implement brief: \`${input.implementBriefPath}\` — stack, business rules, matrix, personas, runtime.`,
|
|
35
|
+
"",
|
|
36
|
+
"## Rules",
|
|
37
|
+
"",
|
|
38
|
+
"- This repo already has a product app. Patch it. Do not scaffold a second application.",
|
|
39
|
+
"- Do not edit `requirement.md`. That is spec Improve, not this action.",
|
|
40
|
+
"- Implement only the named BR- and UC- IDs already in the spec and the proof report.",
|
|
41
|
+
"- Boot or deterministic-login failures may be fixtures, `runtime.yaml`, or a dead sandbox — not a missing button. Check that before changing permissions.",
|
|
42
|
+
"- An observation that is still the Sign in page is a login/reset problem, not an Approve/Assign product bug.",
|
|
43
|
+
"- A mid-band Jev noul (between 0.15 and 0.75) is review, not a license to invent behavior.",
|
|
44
|
+
"",
|
|
45
|
+
"## Cases to close",
|
|
46
|
+
"",
|
|
47
|
+
`Proof is ${input.proof.state}. ${input.proof.message ?? ""}`.trim(),
|
|
48
|
+
"",
|
|
49
|
+
];
|
|
50
|
+
if (open.length === 0) {
|
|
51
|
+
lines.push("No failed or review findings were listed. Read the proof report and close what it marks Failed or Needs review.", "");
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
for (const finding of open) {
|
|
55
|
+
lines.push(`- ${finding.specId}: ${finding.message}`);
|
|
56
|
+
}
|
|
57
|
+
lines.push("");
|
|
58
|
+
}
|
|
59
|
+
lines.push("## Done means", "", "The existing app matches the named cases in the proof report. Personas and `fixtures/runtime.yaml` still match that app. At most 3 `npx ampx sandbox --once` deploys. After the third, stop and report what is still failing. A coding-agent run finishing is **Build Succeeded**, not “the app boots.” Re-prove is next.", "");
|
|
60
|
+
return `${lines.join("\n")}\n`;
|
|
61
|
+
}
|
package/dist/gates.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Ready / Proof confidence gates. One global pair; do not invent per-pack thresholds. */
|
|
2
|
+
export declare const NOUL_PASS = 0.75;
|
|
3
|
+
export declare const NOUL_FAIL = 0.15;
|
|
4
|
+
export declare const JEV_CATALOG: "m2-authoring-v1";
|
|
5
|
+
export declare const JEV_MODEL = "jev-latest";
|
|
6
|
+
export declare const JEV_ENDPOINT = "https://api.typesafe.ai/v1/systemone";
|
|
7
|
+
export declare const SECTION_SCORE_LEVELS: readonly ["empty", "partial", "agent-ready"];
|
package/dist/gates.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Ready / Proof confidence gates. One global pair; do not invent per-pack thresholds. */
|
|
2
|
+
export const NOUL_PASS = 0.75;
|
|
3
|
+
export const NOUL_FAIL = 0.15;
|
|
4
|
+
export const JEV_CATALOG = "m2-authoring-v1";
|
|
5
|
+
export const JEV_MODEL = "jev-latest";
|
|
6
|
+
export const JEV_ENDPOINT = "https://api.typesafe.ai/v1/systemone";
|
|
7
|
+
export const SECTION_SCORE_LEVELS = ["empty", "partial", "agent-ready"];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PersonasResult } from "./personas.js";
|
|
2
|
+
import type { AdapterId, ProductRepo, SpecAst, StackChoice } from "./types.js";
|
|
3
|
+
export declare function emitImplementBrief(input: {
|
|
4
|
+
spec: SpecAst;
|
|
5
|
+
repo: ProductRepo;
|
|
6
|
+
adapter: AdapterId;
|
|
7
|
+
personas?: PersonasResult;
|
|
8
|
+
}): string;
|
|
9
|
+
export declare function productReadmeTemplate(spec: SpecAst, stack: StackChoice): string;
|