@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/ready.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type PersonasResult } from "./personas.js";
|
|
2
|
+
import type { BuildMeter, BuildRun, CompileResult, Health, JevRun, ReadyMeter, SpecAst } from "./types.js";
|
|
3
|
+
export declare function specHash(spec: SpecAst): string;
|
|
4
|
+
/** Pids of implement agents this process launched and is still waiting on. */
|
|
5
|
+
export declare const followedImplementPids: Set<number>;
|
|
6
|
+
export declare const IMPLEMENT_INTERRUPTED = "Implement was interrupted. This Req0 process is not following an implement agent. Reimplement or Fix from proof.";
|
|
7
|
+
export declare function followImplementPid(pid?: number): void;
|
|
8
|
+
export declare function unfollowImplementPid(pid?: number): void;
|
|
9
|
+
export declare function evaluateBuild(spec: SpecAst | null, run: BuildRun | null): BuildMeter;
|
|
10
|
+
export declare class IgnoreBuildLockedError extends Error {
|
|
11
|
+
readonly code = "ignore_build_gate";
|
|
12
|
+
constructor(message?: string);
|
|
13
|
+
}
|
|
14
|
+
export declare function isFollowedImplement(pid?: number): boolean;
|
|
15
|
+
export declare function implementProcessGone(pid?: number): boolean;
|
|
16
|
+
export declare function emptyReady(reason?: ReadyMeter["reason"]): ReadyMeter;
|
|
17
|
+
export declare function attachReady(result: CompileResult, input: {
|
|
18
|
+
personas: PersonasResult;
|
|
19
|
+
jevRun?: JevRun | null;
|
|
20
|
+
hasApiKey: boolean;
|
|
21
|
+
}): CompileResult;
|
|
22
|
+
export declare function evaluateReady(input: {
|
|
23
|
+
spec: SpecAst | null;
|
|
24
|
+
specState: Health["spec"]["state"];
|
|
25
|
+
personas: PersonasResult;
|
|
26
|
+
jevRun?: JevRun | null;
|
|
27
|
+
hasApiKey: boolean;
|
|
28
|
+
}): ReadyMeter;
|
|
29
|
+
export declare function applyReadyToHealth(health: Health, ready: ReadyMeter): Health;
|
package/dist/ready.js
ADDED
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { adapterDisplayName } from "./adapter.js";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { NOUL_FAIL, NOUL_PASS } from "./gates.js";
|
|
4
|
+
import { improveAllowed } from "./improve.js";
|
|
5
|
+
import { missingPersonaRoles } from "./personas.js";
|
|
6
|
+
import { computeStages, primaryAction } from "./stages.js";
|
|
7
|
+
export function specHash(spec) {
|
|
8
|
+
return createHash("sha256").update(JSON.stringify(spec)).digest("hex");
|
|
9
|
+
}
|
|
10
|
+
/** Pids of implement agents this process launched and is still waiting on. */
|
|
11
|
+
export const followedImplementPids = new Set();
|
|
12
|
+
export const IMPLEMENT_INTERRUPTED = "Implement was interrupted. This Req0 process is not following an implement agent. Reimplement or Fix from proof.";
|
|
13
|
+
export function followImplementPid(pid) {
|
|
14
|
+
if (typeof pid === "number" && pid > 0)
|
|
15
|
+
followedImplementPids.add(pid);
|
|
16
|
+
}
|
|
17
|
+
export function unfollowImplementPid(pid) {
|
|
18
|
+
if (typeof pid === "number")
|
|
19
|
+
followedImplementPids.delete(pid);
|
|
20
|
+
}
|
|
21
|
+
export function evaluateBuild(spec, run) {
|
|
22
|
+
if (!run)
|
|
23
|
+
return { state: "not_yet" };
|
|
24
|
+
if (spec && run.specHash !== specHash(spec) && run.state !== "failed") {
|
|
25
|
+
return {
|
|
26
|
+
state: "stale",
|
|
27
|
+
adapter: run.adapter,
|
|
28
|
+
message: "Spec changed after the last implement run.",
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
if (run.state === "running" && !isFollowedImplement(run.pid)) {
|
|
32
|
+
return {
|
|
33
|
+
state: "failed",
|
|
34
|
+
adapter: run.adapter,
|
|
35
|
+
message: IMPLEMENT_INTERRUPTED,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
state: run.state,
|
|
40
|
+
adapter: run.adapter,
|
|
41
|
+
message: run.message,
|
|
42
|
+
...(run.ignored ? { ignored: true } : {}),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export class IgnoreBuildLockedError extends Error {
|
|
46
|
+
code = "ignore_build_gate";
|
|
47
|
+
constructor(message = "Ignore is only when Build failed.") {
|
|
48
|
+
super(message);
|
|
49
|
+
this.name = "IgnoreBuildLockedError";
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export function isFollowedImplement(pid) {
|
|
53
|
+
return typeof pid === "number" && pid > 0 && followedImplementPids.has(pid);
|
|
54
|
+
}
|
|
55
|
+
export function implementProcessGone(pid) {
|
|
56
|
+
if (typeof pid !== "number" || pid <= 0)
|
|
57
|
+
return true;
|
|
58
|
+
try {
|
|
59
|
+
process.kill(pid, 0);
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export function emptyReady(reason = "spec_invalid") {
|
|
67
|
+
return {
|
|
68
|
+
state: "not_yet",
|
|
69
|
+
reason,
|
|
70
|
+
blockers: 0,
|
|
71
|
+
nits: 0,
|
|
72
|
+
jevCurrent: false,
|
|
73
|
+
findings: [],
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
export function attachReady(result, input) {
|
|
77
|
+
const ready = evaluateReady({
|
|
78
|
+
spec: result.spec,
|
|
79
|
+
specState: result.health.spec.state,
|
|
80
|
+
personas: input.personas,
|
|
81
|
+
jevRun: input.jevRun,
|
|
82
|
+
hasApiKey: input.hasApiKey,
|
|
83
|
+
});
|
|
84
|
+
return {
|
|
85
|
+
...result,
|
|
86
|
+
health: applyReadyToHealth(result.health, ready),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
export function evaluateReady(input) {
|
|
90
|
+
if (input.specState !== "valid" || !input.spec) {
|
|
91
|
+
return emptyReady("spec_invalid");
|
|
92
|
+
}
|
|
93
|
+
const findings = [];
|
|
94
|
+
if (input.personas.missingFile) {
|
|
95
|
+
findings.push({
|
|
96
|
+
id: "persona.file",
|
|
97
|
+
kind: "persona_missing",
|
|
98
|
+
severity: "blocker",
|
|
99
|
+
message: "fixtures/personas.yaml is missing. Ready needs a test persona per matrix role.",
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
for (const finding of input.personas.findings) {
|
|
103
|
+
findings.push({
|
|
104
|
+
id: `persona.parse.${finding.line}`,
|
|
105
|
+
kind: "persona_missing",
|
|
106
|
+
severity: "blocker",
|
|
107
|
+
message: finding.message,
|
|
108
|
+
line: finding.line,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
for (const role of missingPersonaRoles(input.spec, input.personas)) {
|
|
112
|
+
findings.push({
|
|
113
|
+
id: `persona.missing.${role}`,
|
|
114
|
+
kind: "persona_missing",
|
|
115
|
+
severity: "blocker",
|
|
116
|
+
message: `Role "${role}" has no persona in fixtures/personas.yaml.`,
|
|
117
|
+
specId: role,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
let packNoul;
|
|
121
|
+
let nextId;
|
|
122
|
+
const run = input.jevRun && input.jevRun.specHash === specHash(input.spec) ? input.jevRun : null;
|
|
123
|
+
if (run) {
|
|
124
|
+
const byId = new Map(run.answers.map((answer) => [answer.id, answer]));
|
|
125
|
+
for (const rule of input.spec.businessRules) {
|
|
126
|
+
const answer = byId.get(`rule.observable.${rule.id}`);
|
|
127
|
+
if (!answer || typeof answer.noul !== "number")
|
|
128
|
+
continue;
|
|
129
|
+
classifyNoul(findings, {
|
|
130
|
+
id: `ready.untestable.${rule.id}`,
|
|
131
|
+
kind: "untestable_rule",
|
|
132
|
+
specId: rule.id,
|
|
133
|
+
line: rule.line,
|
|
134
|
+
noul: answer.noul,
|
|
135
|
+
yesMeansPass: true,
|
|
136
|
+
blockerMessage: `${rule.id} is not testable. Observable does not make Statement noticeable (noul ${fmt(answer.noul)}).`,
|
|
137
|
+
nitMessage: `${rule.id} observability is uncertain (noul ${fmt(answer.noul)}).`,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
for (const useCase of input.spec.useCases) {
|
|
141
|
+
const answer = byId.get(`usecase.contradicts.${useCase.id}`);
|
|
142
|
+
if (!answer || typeof answer.noul !== "number")
|
|
143
|
+
continue;
|
|
144
|
+
classifyNoul(findings, {
|
|
145
|
+
id: `ready.contradict.${useCase.id}`,
|
|
146
|
+
kind: "matrix_contradiction",
|
|
147
|
+
specId: useCase.id,
|
|
148
|
+
line: useCase.line,
|
|
149
|
+
noul: answer.noul,
|
|
150
|
+
yesMeansPass: false,
|
|
151
|
+
blockerMessage: `${useCase.id} contradicts the matrix for ${useCase.actor} (noul ${fmt(answer.noul)}).`,
|
|
152
|
+
nitMessage: `${useCase.id} may contradict the matrix (noul ${fmt(answer.noul)}).`,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
for (const [id, section] of [
|
|
156
|
+
["section.score.business-rules", "Business Rules"],
|
|
157
|
+
["section.score.use-cases", "Use Cases"],
|
|
158
|
+
["section.score.roles-permissions", "Roles & Permissions"],
|
|
159
|
+
]) {
|
|
160
|
+
const answer = byId.get(id);
|
|
161
|
+
if (!answer || typeof answer.score !== "number")
|
|
162
|
+
continue;
|
|
163
|
+
if (answer.score >= 2)
|
|
164
|
+
continue;
|
|
165
|
+
findings.push({
|
|
166
|
+
id: `ready.section.${id}`,
|
|
167
|
+
kind: "section_score",
|
|
168
|
+
severity: "nit",
|
|
169
|
+
message: answer.score < 1
|
|
170
|
+
? `${section} is empty for a coding agent.`
|
|
171
|
+
: `${section} is only partial for a coding agent.`,
|
|
172
|
+
specId: section,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
const choice = byId.get("pack.next-id");
|
|
176
|
+
if (choice?.choice)
|
|
177
|
+
nextId = choice.choice;
|
|
178
|
+
const pack = byId.get("pack.agent-ready");
|
|
179
|
+
if (typeof pack?.noul === "number") {
|
|
180
|
+
packNoul = pack.noul;
|
|
181
|
+
if (pack.noul < NOUL_PASS) {
|
|
182
|
+
findings.push({
|
|
183
|
+
id: "ready.pack-gate",
|
|
184
|
+
kind: "pack_gate",
|
|
185
|
+
severity: "blocker",
|
|
186
|
+
message: `Pack noul ${fmt(pack.noul)} is below the ${NOUL_PASS} gate. Not safe to hand to a coding agent.`,
|
|
187
|
+
noul: pack.noul,
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
const blockers = findings.filter((finding) => finding.severity === "blocker").length;
|
|
193
|
+
const nits = findings.filter((finding) => finding.severity === "nit").length;
|
|
194
|
+
findings.sort((a, b) => Number(b.severity === "blocker") - Number(a.severity === "blocker"));
|
|
195
|
+
const jevCurrent = Boolean(run);
|
|
196
|
+
if (blockers > 0) {
|
|
197
|
+
return {
|
|
198
|
+
state: "blocked",
|
|
199
|
+
reason: "blockers",
|
|
200
|
+
blockers,
|
|
201
|
+
nits,
|
|
202
|
+
nextId: nextId ?? firstSpecId(findings),
|
|
203
|
+
packNoul,
|
|
204
|
+
jevCurrent,
|
|
205
|
+
findings,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
if (run) {
|
|
209
|
+
return {
|
|
210
|
+
state: "ready",
|
|
211
|
+
reason: "passed",
|
|
212
|
+
blockers: 0,
|
|
213
|
+
nits,
|
|
214
|
+
nextId,
|
|
215
|
+
packNoul,
|
|
216
|
+
jevCurrent: true,
|
|
217
|
+
findings,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
return {
|
|
221
|
+
state: "not_yet",
|
|
222
|
+
reason: input.hasApiKey ? "unchecked" : "no_api_key",
|
|
223
|
+
blockers: 0,
|
|
224
|
+
nits: 0,
|
|
225
|
+
findings,
|
|
226
|
+
packNoul,
|
|
227
|
+
jevCurrent: false,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
export function applyReadyToHealth(health, ready) {
|
|
231
|
+
const stages = computeStages(health, ready);
|
|
232
|
+
const nextAction = primaryAction(health, ready, stages);
|
|
233
|
+
return { ...health, ready, stages, nextAction, howThisIsGoing: goingCopy(health, ready) };
|
|
234
|
+
}
|
|
235
|
+
function goingCopy(health, ready) {
|
|
236
|
+
const specState = health.spec.state;
|
|
237
|
+
const errors = health.spec.findings.filter((finding) => finding.severity === "error");
|
|
238
|
+
if (specState === "empty")
|
|
239
|
+
return "Nothing here yet. Create the pack to begin.";
|
|
240
|
+
if (specState !== "valid") {
|
|
241
|
+
const first = errors[0];
|
|
242
|
+
return errors.length === 1
|
|
243
|
+
? `1 compile error. ${first?.message ?? "Keep filling the spec."}`
|
|
244
|
+
: `${errors.length} compile errors. Spec is drafting, not valid.`;
|
|
245
|
+
}
|
|
246
|
+
if (ready.state === "blocked") {
|
|
247
|
+
return ready.nits > 0
|
|
248
|
+
? `${ready.blockers} blocker${ready.blockers === 1 ? "" : "s"}, ${ready.nits} nit${ready.nits === 1 ? "" : "s"}. ${nextLine(ready)}`
|
|
249
|
+
: `${ready.blockers} blocker${ready.blockers === 1 ? "" : "s"}. ${nextLine(ready)}`;
|
|
250
|
+
}
|
|
251
|
+
if (ready.state === "ready") {
|
|
252
|
+
if (health.build.owned === false || health.build.state === "succeeded" || health.build.ignored) {
|
|
253
|
+
return proofGoing(health);
|
|
254
|
+
}
|
|
255
|
+
if (health.build.state === "running") {
|
|
256
|
+
const agent = adapterDisplayName(health.build.adapter === "copilot" ? "copilot" : "cursor");
|
|
257
|
+
return `${agent} agent is running. Activity shows tools and messages as they happen. Stop ends the run. Build Succeeded is not proof the app boots.`;
|
|
258
|
+
}
|
|
259
|
+
if (health.build.state === "stale")
|
|
260
|
+
return "Spec changed after the last implement run. Build is stale.";
|
|
261
|
+
return ready.nits > 0
|
|
262
|
+
? `Ready. Zero blockers, ${ready.nits} nit${ready.nits === 1 ? "" : "s"}. Implementation is next.`
|
|
263
|
+
: "Ready. Zero blockers. Implementation is next.";
|
|
264
|
+
}
|
|
265
|
+
if (ready.reason === "no_api_key") {
|
|
266
|
+
return "The pack is valid. Ready stays Not yet until a TypeSafe API key is set. Persona checks do not need a key.";
|
|
267
|
+
}
|
|
268
|
+
return "The pack is valid. Check it with Jev to turn on Ready.";
|
|
269
|
+
}
|
|
270
|
+
function classifyNoul(findings, input) {
|
|
271
|
+
const pass = input.yesMeansPass ? input.noul >= NOUL_PASS : input.noul <= NOUL_FAIL;
|
|
272
|
+
const fail = input.yesMeansPass ? input.noul <= NOUL_FAIL : input.noul >= NOUL_PASS;
|
|
273
|
+
if (pass)
|
|
274
|
+
return;
|
|
275
|
+
findings.push({
|
|
276
|
+
id: input.id,
|
|
277
|
+
kind: fail ? input.kind : "uncertain",
|
|
278
|
+
severity: fail ? "blocker" : "nit",
|
|
279
|
+
message: fail ? input.blockerMessage : input.nitMessage,
|
|
280
|
+
specId: input.specId,
|
|
281
|
+
line: input.line,
|
|
282
|
+
noul: input.noul,
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
function firstSpecId(findings) {
|
|
286
|
+
return findings.find((finding) => finding.specId)?.specId;
|
|
287
|
+
}
|
|
288
|
+
function nextLine(ready) {
|
|
289
|
+
if (improveAllowed(ready)) {
|
|
290
|
+
return typeof ready.packNoul === "number" && ready.packNoul < NOUL_PASS
|
|
291
|
+
? `Improve it can raise pack noul above ${NOUL_PASS.toFixed(2)}.`
|
|
292
|
+
: "Improve it writes one opinionated pass.";
|
|
293
|
+
}
|
|
294
|
+
if (ready.nextId)
|
|
295
|
+
return `Fix ${ready.nextId} next.`;
|
|
296
|
+
const first = ready.findings.find((finding) => finding.severity === "blocker");
|
|
297
|
+
return first?.message ?? "Fix the blockers.";
|
|
298
|
+
}
|
|
299
|
+
function fmt(noul) {
|
|
300
|
+
return noul.toFixed(2);
|
|
301
|
+
}
|
|
302
|
+
function proofGoing(health) {
|
|
303
|
+
if (!health.proof.runtime)
|
|
304
|
+
return "Proof needs fixtures/runtime.yaml.";
|
|
305
|
+
if (health.proof.state === "failed") {
|
|
306
|
+
const detail = health.proof.message ? `Proof failed: ${health.proof.message}` : "Proof failed.";
|
|
307
|
+
return health.build.owned === false ? detail : `${detail} Fix from proof updates the app from the last report.`;
|
|
308
|
+
}
|
|
309
|
+
if (health.proof.state === "needs_review") {
|
|
310
|
+
return health.build.owned === false
|
|
311
|
+
? "Proof needs review."
|
|
312
|
+
: "Proof needs review. Fix from proof updates the app from the last report.";
|
|
313
|
+
}
|
|
314
|
+
if (health.proof.state === "stale")
|
|
315
|
+
return "Proof is stale.";
|
|
316
|
+
return "";
|
|
317
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Finding } from "./types.js";
|
|
2
|
+
export type RuntimeLogin = {
|
|
3
|
+
path: string;
|
|
4
|
+
email: string;
|
|
5
|
+
password: string;
|
|
6
|
+
submit: string;
|
|
7
|
+
};
|
|
8
|
+
export type RuntimeFixture = {
|
|
9
|
+
baseUrl: string;
|
|
10
|
+
startCommand?: string;
|
|
11
|
+
resetCommand?: string;
|
|
12
|
+
login: RuntimeLogin;
|
|
13
|
+
};
|
|
14
|
+
export type RuntimeResult = {
|
|
15
|
+
ok: true;
|
|
16
|
+
runtime: RuntimeFixture;
|
|
17
|
+
} | {
|
|
18
|
+
ok: false;
|
|
19
|
+
missing: true;
|
|
20
|
+
} | {
|
|
21
|
+
ok: false;
|
|
22
|
+
missing: false;
|
|
23
|
+
findings: Finding[];
|
|
24
|
+
};
|
|
25
|
+
export declare function parseRuntimeYaml(source: string): RuntimeResult;
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
const TOP = /^([A-Za-z][A-Za-z0-9_-]*):[ \t]*(.*)$/;
|
|
2
|
+
export function parseRuntimeYaml(source) {
|
|
3
|
+
const findings = [];
|
|
4
|
+
const lines = source.replace(/^\uFEFF/, "").split(/\r?\n/);
|
|
5
|
+
let baseUrl;
|
|
6
|
+
let startCommand;
|
|
7
|
+
let resetCommand;
|
|
8
|
+
let inLogin = false;
|
|
9
|
+
const login = {};
|
|
10
|
+
for (let i = 0; i < lines.length; i++) {
|
|
11
|
+
const raw = lines[i] ?? "";
|
|
12
|
+
const line = i + 1;
|
|
13
|
+
const trimmed = raw.trim();
|
|
14
|
+
if (!trimmed || trimmed.startsWith("#"))
|
|
15
|
+
continue;
|
|
16
|
+
if (inLogin) {
|
|
17
|
+
const nested = raw.match(/^ {2}([A-Za-z][A-Za-z0-9_-]*):[ \t]*(.*)$/);
|
|
18
|
+
if (nested) {
|
|
19
|
+
const key = (nested[1] ?? "").toLowerCase();
|
|
20
|
+
const value = unquote((nested[2] ?? "").trim());
|
|
21
|
+
if (key === "path" || key === "email" || key === "password" || key === "submit") {
|
|
22
|
+
login[key] = value;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
findings.push({
|
|
26
|
+
line,
|
|
27
|
+
severity: "error",
|
|
28
|
+
message: `Unknown login field "${key}". Use path, email, password, submit.`,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (!raw.startsWith(" "))
|
|
34
|
+
inLogin = false;
|
|
35
|
+
else {
|
|
36
|
+
findings.push({
|
|
37
|
+
line,
|
|
38
|
+
severity: "error",
|
|
39
|
+
message: "Unrecognized runtime.yaml login line. Indent fields two spaces.",
|
|
40
|
+
});
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const top = raw.match(TOP);
|
|
45
|
+
if (!top || raw.startsWith(" ")) {
|
|
46
|
+
findings.push({
|
|
47
|
+
line,
|
|
48
|
+
severity: "error",
|
|
49
|
+
message: "Unrecognized runtime.yaml line. Use top-level baseUrl, optional startCommand, optional resetCommand, and login.",
|
|
50
|
+
});
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const key = (top[1] ?? "").toLowerCase();
|
|
54
|
+
const value = unquote((top[2] ?? "").trim());
|
|
55
|
+
if (key === "baseurl") {
|
|
56
|
+
baseUrl = value;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (key === "startcommand") {
|
|
60
|
+
startCommand = value || undefined;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (key === "resetcommand") {
|
|
64
|
+
resetCommand = value || undefined;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (key === "login") {
|
|
68
|
+
inLogin = true;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
findings.push({
|
|
72
|
+
line,
|
|
73
|
+
severity: "error",
|
|
74
|
+
message: `Unknown runtime field "${key}". Use baseUrl, startCommand, resetCommand, login.`,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
if (!baseUrl) {
|
|
78
|
+
findings.push({
|
|
79
|
+
line: 1,
|
|
80
|
+
severity: "error",
|
|
81
|
+
message: 'fixtures/runtime.yaml must set baseUrl (example: "http://127.0.0.1:3000").',
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
else if (!/^https?:\/\//i.test(baseUrl)) {
|
|
85
|
+
findings.push({
|
|
86
|
+
line: 1,
|
|
87
|
+
severity: "error",
|
|
88
|
+
message: "baseUrl must be an http(s) URL.",
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
for (const field of ["path", "email", "password", "submit"]) {
|
|
92
|
+
if (!login[field]) {
|
|
93
|
+
findings.push({
|
|
94
|
+
line: 1,
|
|
95
|
+
severity: "error",
|
|
96
|
+
message: `login.${field} is required (a CSS selector, or path for login.path).`,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (findings.length) {
|
|
101
|
+
return { ok: false, missing: false, findings };
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
ok: true,
|
|
105
|
+
runtime: {
|
|
106
|
+
baseUrl: baseUrl.replace(/\/$/, ""),
|
|
107
|
+
...(startCommand ? { startCommand } : {}),
|
|
108
|
+
...(resetCommand ? { resetCommand } : {}),
|
|
109
|
+
login: {
|
|
110
|
+
path: login.path.startsWith("/") ? login.path : `/${login.path}`,
|
|
111
|
+
email: login.email,
|
|
112
|
+
password: login.password,
|
|
113
|
+
submit: login.submit,
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function unquote(value) {
|
|
119
|
+
if ((value.startsWith('"') && value.endsWith('"')) ||
|
|
120
|
+
(value.startsWith("'") && value.endsWith("'"))) {
|
|
121
|
+
return value.slice(1, -1);
|
|
122
|
+
}
|
|
123
|
+
const comment = value.indexOf(" #");
|
|
124
|
+
return comment >= 0 ? value.slice(0, comment).trim() : value;
|
|
125
|
+
}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type IncomingMessage, type ServerResponse } from "node:http";
|
|
2
|
+
import type { LaunchAdapterResult } from "./implement.js";
|
|
3
|
+
import type { PackPaths } from "./pack.js";
|
|
4
|
+
import type { ActivityLine, CompileResult } from "./types.js";
|
|
5
|
+
export type AppState = {
|
|
6
|
+
cwd: string;
|
|
7
|
+
pack: PackPaths | null;
|
|
8
|
+
last: CompileResult | null;
|
|
9
|
+
activity: ActivityLine[];
|
|
10
|
+
busy: "prove" | "improve" | "implement" | null;
|
|
11
|
+
implementLaunch: LaunchAdapterResult | null;
|
|
12
|
+
};
|
|
13
|
+
export declare function createAppState(cwd: string, pack: PackPaths | null): AppState;
|
|
14
|
+
export declare function refresh(state: AppState): Promise<CompileResult | null>;
|
|
15
|
+
export declare function createCockpitServer(state: AppState): import("http").Server<typeof IncomingMessage, typeof ServerResponse>;
|