@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/stack.js
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { access, readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { parseAdapterId } from "./adapter.js";
|
|
4
|
+
export const REQ0_CONFIG_FILE = "req0.json";
|
|
5
|
+
export const ENV_EXAMPLE_FILE = ".env.example";
|
|
6
|
+
export const AMPLIFY_ENV_EXAMPLE = `# Copy to .env. Names only. Do not put real values in this file.
|
|
7
|
+
# ampx does not read this file. Export the vars, or run: npx ampx configure profile
|
|
8
|
+
AWS_REGION=
|
|
9
|
+
# Named profile (then: npx ampx sandbox --once --profile <name>):
|
|
10
|
+
AWS_PROFILE=
|
|
11
|
+
# Or access keys instead of AWS_PROFILE:
|
|
12
|
+
# AWS_ACCESS_KEY_ID=
|
|
13
|
+
# AWS_SECRET_ACCESS_KEY=
|
|
14
|
+
# AWS_SESSION_TOKEN= # temporary/SSO creds only — not IAM user keys
|
|
15
|
+
`;
|
|
16
|
+
export const DEFAULT_STACK = {
|
|
17
|
+
id: "nextjs-default",
|
|
18
|
+
label: "Next.js App Router, TypeScript, Tailwind, shadcn/ui, Prisma, PostgreSQL, Better Auth",
|
|
19
|
+
};
|
|
20
|
+
export const AMPLIFY_IDENTITY_HINT = "ampx reads AWS_PROFILE, inherited AWS_ACCESS_KEY_ID, or ~/.aws — not the .env file. If none of those exist, stop and tell the owner to run npx ampx configure profile. Do not ask for keys. Do not print env values.";
|
|
21
|
+
export const AMPLIFY_GEN2_STACK = {
|
|
22
|
+
id: "amplify-gen2",
|
|
23
|
+
label: "Amplify Gen 2, Next.js, Cognito, Data, S3",
|
|
24
|
+
};
|
|
25
|
+
export const KNOWN_STACKS = [DEFAULT_STACK, AMPLIFY_GEN2_STACK];
|
|
26
|
+
export const STACK_CHOICE_HINT = `Choose a stack before Implement. Write it in req0.json, pass --stack=${DEFAULT_STACK.id} or --stack=${AMPLIFY_GEN2_STACK.id}, or pick one in the cockpit.`;
|
|
27
|
+
export function isAmplifyStack(stack) {
|
|
28
|
+
return stack.id === AMPLIFY_GEN2_STACK.id;
|
|
29
|
+
}
|
|
30
|
+
export function resolveStackId(id) {
|
|
31
|
+
const trimmed = id.trim();
|
|
32
|
+
return KNOWN_STACKS.find((stack) => stack.id === trimmed) ?? null;
|
|
33
|
+
}
|
|
34
|
+
export function needsStackChoice(repo) {
|
|
35
|
+
return Boolean(repo.root) && repo.implement && repo.empty && !repo.recorded;
|
|
36
|
+
}
|
|
37
|
+
export function needsCodingChoice(repo) {
|
|
38
|
+
return Boolean(repo.root) && repo.implement && repo.adapterRecorded === false;
|
|
39
|
+
}
|
|
40
|
+
export function needsSetupGate(repo) {
|
|
41
|
+
return needsCodingChoice(repo) || needsStackChoice(repo);
|
|
42
|
+
}
|
|
43
|
+
export class StackRequiredError extends Error {
|
|
44
|
+
code = "stack_required";
|
|
45
|
+
constructor(message = STACK_CHOICE_HINT) {
|
|
46
|
+
super(message);
|
|
47
|
+
this.name = "StackRequiredError";
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export class UnknownStackError extends Error {
|
|
51
|
+
code = "unknown_stack";
|
|
52
|
+
constructor(id) {
|
|
53
|
+
super(`Unknown stack "${id}". Use ${DEFAULT_STACK.id} or ${AMPLIFY_GEN2_STACK.id}.`);
|
|
54
|
+
this.name = "UnknownStackError";
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const APP_MANIFESTS = [
|
|
58
|
+
"next.config.js",
|
|
59
|
+
"next.config.mjs",
|
|
60
|
+
"next.config.ts",
|
|
61
|
+
"Cargo.toml",
|
|
62
|
+
"cargo.toml",
|
|
63
|
+
"go.mod",
|
|
64
|
+
"pyproject.toml",
|
|
65
|
+
"Gemfile",
|
|
66
|
+
"composer.json",
|
|
67
|
+
];
|
|
68
|
+
export function findRepoRootFromPack(packRoot) {
|
|
69
|
+
let dir = path.resolve(packRoot);
|
|
70
|
+
for (let i = 0; i < 8; i++) {
|
|
71
|
+
const parent = path.dirname(dir);
|
|
72
|
+
if (path.basename(dir) === "requirements" && path.basename(parent) === "docs") {
|
|
73
|
+
return path.dirname(parent);
|
|
74
|
+
}
|
|
75
|
+
if (parent === dir)
|
|
76
|
+
break;
|
|
77
|
+
dir = parent;
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
export async function readReq0Config(repoRoot) {
|
|
82
|
+
try {
|
|
83
|
+
const raw = JSON.parse(await readFile(path.join(repoRoot, REQ0_CONFIG_FILE), "utf8"));
|
|
84
|
+
return raw && typeof raw === "object" ? raw : null;
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
export async function writeReq0Config(repoRoot, config) {
|
|
91
|
+
const previous = await readReq0Config(repoRoot);
|
|
92
|
+
const next = { ...previous, ...config };
|
|
93
|
+
await writeFile(path.join(repoRoot, REQ0_CONFIG_FILE), `${JSON.stringify(next, null, 2)}\n`, "utf8");
|
|
94
|
+
}
|
|
95
|
+
export async function inspectProductRepo(packRoot) {
|
|
96
|
+
const root = findRepoRootFromPack(packRoot);
|
|
97
|
+
if (!root) {
|
|
98
|
+
return {
|
|
99
|
+
root: null,
|
|
100
|
+
empty: true,
|
|
101
|
+
stack: DEFAULT_STACK,
|
|
102
|
+
recorded: false,
|
|
103
|
+
adapter: "cursor",
|
|
104
|
+
adapterRecorded: false,
|
|
105
|
+
implement: true,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
const config = await readReq0Config(root);
|
|
109
|
+
const implement = config?.implement !== false;
|
|
110
|
+
const empty = !(await hasCustomerApp(root));
|
|
111
|
+
const recorded = resolveRecordedStack(config?.stack);
|
|
112
|
+
const adapter = parseAdapterId(config?.adapter) ?? "cursor";
|
|
113
|
+
const adapterRecorded = config?.implement === false || parseAdapterId(config?.adapter) !== null;
|
|
114
|
+
return {
|
|
115
|
+
root,
|
|
116
|
+
empty,
|
|
117
|
+
stack: recorded ?? DEFAULT_STACK,
|
|
118
|
+
recorded: Boolean(recorded),
|
|
119
|
+
adapter,
|
|
120
|
+
adapterRecorded,
|
|
121
|
+
implement,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function resolveRecordedStack(raw) {
|
|
125
|
+
if (!raw || typeof raw.id !== "string" || !raw.id.trim())
|
|
126
|
+
return null;
|
|
127
|
+
return resolveStackId(raw.id) ?? (typeof raw.label === "string" && raw.label.trim() ? raw : null);
|
|
128
|
+
}
|
|
129
|
+
export async function recordStack(repoRoot, id) {
|
|
130
|
+
const stack = resolveStackId(id);
|
|
131
|
+
if (!stack)
|
|
132
|
+
throw new UnknownStackError(id);
|
|
133
|
+
await writeReq0Config(repoRoot, { stack });
|
|
134
|
+
await writeAmplifyEnvExampleIfMissing(repoRoot, stack);
|
|
135
|
+
return stack;
|
|
136
|
+
}
|
|
137
|
+
export async function recordProjectSetup(repoRoot, input) {
|
|
138
|
+
if (input.coding === "manual") {
|
|
139
|
+
await writeReq0Config(repoRoot, { implement: false });
|
|
140
|
+
return (await readReq0Config(repoRoot)) ?? { implement: false };
|
|
141
|
+
}
|
|
142
|
+
const updates = { adapter: input.coding, implement: true };
|
|
143
|
+
if (input.stack) {
|
|
144
|
+
const stack = resolveStackId(input.stack);
|
|
145
|
+
if (!stack)
|
|
146
|
+
throw new UnknownStackError(input.stack);
|
|
147
|
+
updates.stack = stack;
|
|
148
|
+
await writeReq0Config(repoRoot, updates);
|
|
149
|
+
await writeAmplifyEnvExampleIfMissing(repoRoot, stack);
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
await writeReq0Config(repoRoot, updates);
|
|
153
|
+
}
|
|
154
|
+
return (await readReq0Config(repoRoot)) ?? updates;
|
|
155
|
+
}
|
|
156
|
+
export async function writeAmplifyEnvExampleIfMissing(repoRoot, stack) {
|
|
157
|
+
if (!isAmplifyStack(stack))
|
|
158
|
+
return false;
|
|
159
|
+
const target = path.join(repoRoot, ENV_EXAMPLE_FILE);
|
|
160
|
+
try {
|
|
161
|
+
await access(target);
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
await writeFile(target, AMPLIFY_ENV_EXAMPLE, "utf8");
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function isReq0CliPackageName(name) {
|
|
170
|
+
return name === "req0" || name === "@richjava/req0";
|
|
171
|
+
}
|
|
172
|
+
export async function hasCustomerApp(repoRoot) {
|
|
173
|
+
for (const file of APP_MANIFESTS) {
|
|
174
|
+
try {
|
|
175
|
+
await access(path.join(repoRoot, file));
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
// keep looking
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
try {
|
|
183
|
+
const pkg = JSON.parse(await readFile(path.join(repoRoot, "package.json"), "utf8"));
|
|
184
|
+
return !isReq0CliPackageName(pkg.name);
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
export function stackInstruction(repo, adapter) {
|
|
191
|
+
if (!repo.empty) {
|
|
192
|
+
const recorded = repo.recorded ? `Recorded stack: ${repo.stack.label}.` : "Match the repo you see.";
|
|
193
|
+
const aws = isAmplifyStack(repo.stack) ? ` ${AMPLIFY_IDENTITY_HINT}` : "";
|
|
194
|
+
return [
|
|
195
|
+
"This repo already has a product app. Implement in the existing stack.",
|
|
196
|
+
"Do not scaffold a second application.",
|
|
197
|
+
recorded + aws,
|
|
198
|
+
`Adapter: ${adapter}.`,
|
|
199
|
+
].join(" ");
|
|
200
|
+
}
|
|
201
|
+
if (repo.recorded) {
|
|
202
|
+
const aws = isAmplifyStack(repo.stack) ? AMPLIFY_IDENTITY_HINT : "";
|
|
203
|
+
return [
|
|
204
|
+
"This product repo is empty (no customer app at the repo root).",
|
|
205
|
+
`Recorded stack: ${repo.stack.label}. Use it. Do not ask for another stack.`,
|
|
206
|
+
aws,
|
|
207
|
+
"Req0's own CLI package.json does not count as a customer app.",
|
|
208
|
+
`Adapter: ${adapter}.`,
|
|
209
|
+
]
|
|
210
|
+
.filter(Boolean)
|
|
211
|
+
.join(" ");
|
|
212
|
+
}
|
|
213
|
+
return [
|
|
214
|
+
"This product repo is empty (no customer app at the repo root).",
|
|
215
|
+
`Ask the Requirement Owner which stack to use. Default: ${DEFAULT_STACK.label}. AWS option: ${AMPLIFY_GEN2_STACK.label} (id ${AMPLIFY_GEN2_STACK.id}).`,
|
|
216
|
+
"Record the choice in req0.json at the repo root so later requirements stay consistent.",
|
|
217
|
+
"Req0's own CLI package.json does not count as a customer app.",
|
|
218
|
+
`Adapter: ${adapter}.`,
|
|
219
|
+
].join(" ");
|
|
220
|
+
}
|
package/dist/stages.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { BuildMeter, Health, PackListMeter, PipelineView, ReadyMeter, StageBoard } from "./types.js";
|
|
2
|
+
export declare function buildAllowsProve(build: BuildMeter): boolean;
|
|
3
|
+
export declare function ignoreBuildAllowed(health: Health, ready?: ReadyMeter): boolean;
|
|
4
|
+
export declare function emptyStages(): StageBoard;
|
|
5
|
+
export declare function readyBadge(ready: ReadyMeter): string;
|
|
6
|
+
export declare const SECTION_PURPOSES: Record<string, string>;
|
|
7
|
+
export declare function sectionCatalog(): {
|
|
8
|
+
name: string;
|
|
9
|
+
required: boolean;
|
|
10
|
+
purpose: string;
|
|
11
|
+
}[];
|
|
12
|
+
export declare function pipelineView(health: Health | null, packPresent: boolean): PipelineView;
|
|
13
|
+
export declare function packListMeters(health: Health | null, packPresent: boolean): PackListMeter[];
|
|
14
|
+
export declare function computeStages(health: Health, ready: ReadyMeter): StageBoard;
|
|
15
|
+
export declare function primaryAction(health: Health, ready: ReadyMeter, stages: StageBoard): Health["nextAction"];
|
package/dist/stages.js
ADDED
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
import { adapterDisplayName } from "./adapter.js";
|
|
2
|
+
import { fixFromProofAllowed } from "./fix-from-proof.js";
|
|
3
|
+
import { NOUL_PASS } from "./gates.js";
|
|
4
|
+
import { improveAllowed, improveHint } from "./improve.js";
|
|
5
|
+
import { STACK_CHOICE_HINT } from "./stack.js";
|
|
6
|
+
import { OPTIONAL_H2, REQUIRED_H2 } from "./types.js";
|
|
7
|
+
export function buildAllowsProve(build) {
|
|
8
|
+
if (build.owned === false)
|
|
9
|
+
return true;
|
|
10
|
+
if (build.state === "succeeded")
|
|
11
|
+
return true;
|
|
12
|
+
return build.ignored === true;
|
|
13
|
+
}
|
|
14
|
+
export function ignoreBuildAllowed(health, ready = health.ready) {
|
|
15
|
+
if (health.build.owned === false)
|
|
16
|
+
return false;
|
|
17
|
+
if (ready.state !== "ready")
|
|
18
|
+
return false;
|
|
19
|
+
if (health.build.needsStack)
|
|
20
|
+
return false;
|
|
21
|
+
if (health.build.state === "running")
|
|
22
|
+
return false;
|
|
23
|
+
return health.build.state === "failed" && health.build.ignored !== true;
|
|
24
|
+
}
|
|
25
|
+
export function emptyStages() {
|
|
26
|
+
return {
|
|
27
|
+
ready: { id: "check-jev", label: "Check", enabled: false },
|
|
28
|
+
build: { id: "implement", label: "Implement", enabled: false },
|
|
29
|
+
proof: { id: "prove", label: "Prove", enabled: false },
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export function readyBadge(ready) {
|
|
33
|
+
const state = ready.state === "blocked" ? "Blocked" : ready.state === "ready" ? "Clear" : "Not yet";
|
|
34
|
+
if (ready.jevCurrent && typeof ready.packNoul === "number") {
|
|
35
|
+
return `${state} · ${ready.packNoul.toFixed(2)}`;
|
|
36
|
+
}
|
|
37
|
+
return state;
|
|
38
|
+
}
|
|
39
|
+
export const SECTION_PURPOSES = {
|
|
40
|
+
"Business Rules": "What must be true. Each rule has Id, Statement, and Observable.",
|
|
41
|
+
"Use Cases": "Who does what. Actor, preconditions, steps, and Outcome. Look for is deny; Choose is allow.",
|
|
42
|
+
"Roles & Permissions": "The matrix: which role may perform which action.",
|
|
43
|
+
Overview: "Optional context for the requirement.",
|
|
44
|
+
"Out of scope": "Optional. What this pack does not cover.",
|
|
45
|
+
"Open questions": "Optional. Unresolved questions for the owner.",
|
|
46
|
+
Entities: "Optional. Named things the spec talks about.",
|
|
47
|
+
"UI notes": "Optional. Presentation hints that are not rules.",
|
|
48
|
+
};
|
|
49
|
+
export function sectionCatalog() {
|
|
50
|
+
return [
|
|
51
|
+
...REQUIRED_H2.map((name) => ({ name, required: true, purpose: SECTION_PURPOSES[name] ?? "" })),
|
|
52
|
+
...OPTIONAL_H2.map((name) => ({ name, required: false, purpose: SECTION_PURPOSES[name] ?? "" })),
|
|
53
|
+
];
|
|
54
|
+
}
|
|
55
|
+
export function pipelineView(health, packPresent) {
|
|
56
|
+
const implementOwned = health?.build.owned !== false;
|
|
57
|
+
const specState = health?.spec.state ?? "empty";
|
|
58
|
+
const ready = health?.ready;
|
|
59
|
+
const build = health?.build;
|
|
60
|
+
const proof = health?.proof;
|
|
61
|
+
const defineTone = specState === "empty"
|
|
62
|
+
? "idle"
|
|
63
|
+
: specState === "drafting"
|
|
64
|
+
? "draft"
|
|
65
|
+
: ready?.state === "blocked"
|
|
66
|
+
? "bad"
|
|
67
|
+
: ready?.state === "ready"
|
|
68
|
+
? "ok"
|
|
69
|
+
: "draft";
|
|
70
|
+
const implementTone = build?.state === "running"
|
|
71
|
+
? "progress"
|
|
72
|
+
: build?.state === "failed"
|
|
73
|
+
? "bad"
|
|
74
|
+
: build?.state === "succeeded"
|
|
75
|
+
? "ok"
|
|
76
|
+
: build?.state === "stale"
|
|
77
|
+
? "draft"
|
|
78
|
+
: "idle";
|
|
79
|
+
const qaTone = proof?.state === "passed"
|
|
80
|
+
? "ok"
|
|
81
|
+
: proof?.state === "failed"
|
|
82
|
+
? "bad"
|
|
83
|
+
: proof?.state === "needs_review" || proof?.state === "stale"
|
|
84
|
+
? "draft"
|
|
85
|
+
: "idle";
|
|
86
|
+
const specTone = specState === "empty" ? "idle" : specState === "drafting" ? "draft" : specState === "valid" ? "ok" : "draft";
|
|
87
|
+
const judgmentTone = ready?.state === "blocked" ? "bad" : ready?.state === "ready" ? "ok" : specState === "valid" ? "draft" : "idle";
|
|
88
|
+
const specBadge = specState === "empty" ? "Empty" : specState === "drafting" ? "Drafting" : specState === "valid" ? "Valid" : specState;
|
|
89
|
+
const defineBadge = specState !== "valid" ? specBadge : ready ? readyBadge(ready) : "Not yet";
|
|
90
|
+
const judgmentBadge = ready ? readyBadge(ready) : "Not yet";
|
|
91
|
+
const implementBadge = build?.state === "running"
|
|
92
|
+
? "Implementing"
|
|
93
|
+
: build?.state === "succeeded"
|
|
94
|
+
? "Succeeded"
|
|
95
|
+
: build?.state === "failed"
|
|
96
|
+
? "Failed"
|
|
97
|
+
: build?.state === "stale"
|
|
98
|
+
? "Stale"
|
|
99
|
+
: "Not yet";
|
|
100
|
+
const qaBadge = proof?.state === "passed"
|
|
101
|
+
? "Passed"
|
|
102
|
+
: proof?.state === "failed"
|
|
103
|
+
? "Failed"
|
|
104
|
+
: proof?.state === "needs_review"
|
|
105
|
+
? "Needs review"
|
|
106
|
+
: proof?.state === "stale"
|
|
107
|
+
? "Stale"
|
|
108
|
+
: "Not yet";
|
|
109
|
+
return {
|
|
110
|
+
implementOwned,
|
|
111
|
+
nodes: [
|
|
112
|
+
{
|
|
113
|
+
id: "start",
|
|
114
|
+
label: "Start",
|
|
115
|
+
view: "define",
|
|
116
|
+
tone: packPresent ? "ok" : "idle",
|
|
117
|
+
badge: packPresent ? "Pack" : "Create",
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
id: "define",
|
|
121
|
+
label: "Define",
|
|
122
|
+
view: "define",
|
|
123
|
+
tone: defineTone,
|
|
124
|
+
badge: defineBadge,
|
|
125
|
+
mark: defineTone === "bad" ? "block" : undefined,
|
|
126
|
+
children: [
|
|
127
|
+
{ id: "spec", label: "Spec", view: "spec", tone: specTone, badge: specBadge },
|
|
128
|
+
{
|
|
129
|
+
id: "judgment",
|
|
130
|
+
label: "Judgment",
|
|
131
|
+
view: "judgment",
|
|
132
|
+
tone: judgmentTone,
|
|
133
|
+
badge: judgmentBadge,
|
|
134
|
+
mark: judgmentTone === "bad" ? "block" : undefined,
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
id: "implement",
|
|
140
|
+
label: "Implement",
|
|
141
|
+
view: "implement",
|
|
142
|
+
tone: implementTone,
|
|
143
|
+
badge: implementBadge,
|
|
144
|
+
mark: implementTone === "bad" ? "fail" : undefined,
|
|
145
|
+
hidden: !implementOwned,
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
id: "qa",
|
|
149
|
+
label: "QA",
|
|
150
|
+
view: "qa",
|
|
151
|
+
tone: qaTone,
|
|
152
|
+
badge: qaBadge,
|
|
153
|
+
mark: qaTone === "bad" ? "fail" : undefined,
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
id: "end",
|
|
157
|
+
label: "End",
|
|
158
|
+
view: "qa",
|
|
159
|
+
tone: proof?.state === "passed" ? "ok" : "idle",
|
|
160
|
+
badge: proof?.state === "passed" ? "Passed" : undefined,
|
|
161
|
+
},
|
|
162
|
+
],
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
export function packListMeters(health, packPresent) {
|
|
166
|
+
const view = pipelineView(health, packPresent);
|
|
167
|
+
const define = view.nodes.find((node) => node.id === "define");
|
|
168
|
+
const spec = define?.children?.find((child) => child.id === "spec");
|
|
169
|
+
const judgment = define?.children?.find((child) => child.id === "judgment");
|
|
170
|
+
const implement = view.nodes.find((node) => node.id === "implement");
|
|
171
|
+
const qa = view.nodes.find((node) => node.id === "qa");
|
|
172
|
+
const meters = [];
|
|
173
|
+
if (spec)
|
|
174
|
+
meters.push({ key: "spec", label: spec.label, tone: spec.tone, badge: spec.badge ?? "" });
|
|
175
|
+
if (judgment) {
|
|
176
|
+
meters.push({ key: "ready", label: judgment.label, tone: judgment.tone, badge: judgment.badge ?? "" });
|
|
177
|
+
}
|
|
178
|
+
if (implement && !implement.hidden) {
|
|
179
|
+
meters.push({
|
|
180
|
+
key: "build",
|
|
181
|
+
label: implement.label,
|
|
182
|
+
tone: implement.tone,
|
|
183
|
+
badge: implement.badge ?? "",
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
if (qa)
|
|
187
|
+
meters.push({ key: "proof", label: qa.label, tone: qa.tone, badge: qa.badge ?? "" });
|
|
188
|
+
return meters;
|
|
189
|
+
}
|
|
190
|
+
export function computeStages(health, ready) {
|
|
191
|
+
const specValid = health.spec.state === "valid";
|
|
192
|
+
const jevCurrent = ready.jevCurrent === true;
|
|
193
|
+
let readyAction;
|
|
194
|
+
if (!specValid) {
|
|
195
|
+
readyAction = { id: "check-jev", label: "Check", enabled: false };
|
|
196
|
+
}
|
|
197
|
+
else if (improveAllowed(ready)) {
|
|
198
|
+
readyAction = {
|
|
199
|
+
id: "improve",
|
|
200
|
+
label: "Improve it",
|
|
201
|
+
enabled: true,
|
|
202
|
+
hint: improveHint(ready),
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
else if (!jevCurrent) {
|
|
206
|
+
readyAction = {
|
|
207
|
+
id: "check-jev",
|
|
208
|
+
label: "Check",
|
|
209
|
+
enabled: true,
|
|
210
|
+
hint: ready.reason === "no_api_key" ? "Needs TYPESAFE_API_KEY." : "Re-check after editing the spec.",
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
else if (ready.state === "blocked" || (typeof ready.packNoul === "number" && ready.packNoul < NOUL_PASS)) {
|
|
214
|
+
readyAction = {
|
|
215
|
+
id: "check-jev",
|
|
216
|
+
label: "Check",
|
|
217
|
+
enabled: true,
|
|
218
|
+
hint: "Check with Jev before improving the same findings again.",
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
readyAction = { id: "improve", label: "Improve it", enabled: false };
|
|
223
|
+
}
|
|
224
|
+
const readyOk = ready.state === "ready";
|
|
225
|
+
const implementOwned = health.build.owned !== false;
|
|
226
|
+
const neverSucceeded = health.build.state === "not_yet" || health.build.state === "failed";
|
|
227
|
+
const needsStack = health.build.needsStack === true;
|
|
228
|
+
const agent = adapterDisplayName(health.build.adapter === "copilot" ? "copilot" : "cursor");
|
|
229
|
+
const buildAction = implementOwned
|
|
230
|
+
? {
|
|
231
|
+
id: "implement",
|
|
232
|
+
label: health.build.state === "running" ? "Implementing" : neverSucceeded ? "Implement" : "Reimplement",
|
|
233
|
+
enabled: readyOk && health.build.state !== "running" && !needsStack,
|
|
234
|
+
hint: needsStack
|
|
235
|
+
? STACK_CHOICE_HINT
|
|
236
|
+
: health.build.state === "running"
|
|
237
|
+
? `${agent} agent is running. Activity shows tools and messages as they happen.`
|
|
238
|
+
: health.build.state === "failed"
|
|
239
|
+
? health.build.message
|
|
240
|
+
: neverSucceeded
|
|
241
|
+
? `Starts a ${agent} agent with derived/implement-brief.md.`
|
|
242
|
+
: health.build.message,
|
|
243
|
+
}
|
|
244
|
+
: {
|
|
245
|
+
id: "implement",
|
|
246
|
+
label: "Implement",
|
|
247
|
+
enabled: false,
|
|
248
|
+
hidden: true,
|
|
249
|
+
hint: "Implement is off in req0.json. Build this repo another way, then Prove.",
|
|
250
|
+
};
|
|
251
|
+
const firstProve = health.proof.state === "not_yet";
|
|
252
|
+
const canProve = readyOk && buildAllowsProve(health.build) && health.proof.runtime;
|
|
253
|
+
const proofAction = {
|
|
254
|
+
id: "prove",
|
|
255
|
+
label: firstProve ? "Prove" : "Re-prove",
|
|
256
|
+
enabled: canProve,
|
|
257
|
+
hint: proofHint(health),
|
|
258
|
+
};
|
|
259
|
+
const canFix = fixFromProofAllowed(health, ready) && health.build.state !== "running";
|
|
260
|
+
const fixFromProof = canFix
|
|
261
|
+
? {
|
|
262
|
+
id: "fix-from-proof",
|
|
263
|
+
label: "Fix from proof",
|
|
264
|
+
enabled: true,
|
|
265
|
+
hint: `Starts a ${agent} agent with the last proof-report.md and the implement brief. Does not edit requirement.md.`,
|
|
266
|
+
}
|
|
267
|
+
: undefined;
|
|
268
|
+
const ignoreBuild = ignoreBuildAllowed(health, ready)
|
|
269
|
+
? {
|
|
270
|
+
id: "ignore-build",
|
|
271
|
+
label: "Ignore",
|
|
272
|
+
enabled: true,
|
|
273
|
+
hint: "Unlock Prove. You will be asked whether implementation succeeded.",
|
|
274
|
+
}
|
|
275
|
+
: undefined;
|
|
276
|
+
const stopImplement = implementOwned && health.build.state === "running"
|
|
277
|
+
? {
|
|
278
|
+
id: "stop-implement",
|
|
279
|
+
label: "Stop",
|
|
280
|
+
enabled: true,
|
|
281
|
+
hint: `Stops the ${agent} agent. Build stays failed until you Reimplement or Ignore.`,
|
|
282
|
+
}
|
|
283
|
+
: undefined;
|
|
284
|
+
return {
|
|
285
|
+
ready: readyAction,
|
|
286
|
+
build: buildAction,
|
|
287
|
+
proof: proofAction,
|
|
288
|
+
...(fixFromProof ? { fixFromProof } : {}),
|
|
289
|
+
...(ignoreBuild ? { ignoreBuild } : {}),
|
|
290
|
+
...(stopImplement ? { stopImplement } : {}),
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
export function primaryAction(health, ready, stages) {
|
|
294
|
+
if (health.spec.state === "empty") {
|
|
295
|
+
return { id: "create", label: "Create this requirement", enabled: true };
|
|
296
|
+
}
|
|
297
|
+
if (health.spec.state !== "valid") {
|
|
298
|
+
const first = health.spec.findings.find((finding) => finding.severity === "error");
|
|
299
|
+
return {
|
|
300
|
+
id: "fix-spec",
|
|
301
|
+
label: first ? `Fix: ${truncate(first.message, 72)}` : "Finish the required sections",
|
|
302
|
+
enabled: true,
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
if (stages.ready.enabled)
|
|
306
|
+
return stages.ready;
|
|
307
|
+
const implementOwned = health.build.owned !== false;
|
|
308
|
+
const waitingForBuild = implementOwned &&
|
|
309
|
+
!health.build.ignored &&
|
|
310
|
+
(health.build.state === "not_yet" ||
|
|
311
|
+
health.build.state === "failed" ||
|
|
312
|
+
health.build.state === "stale" ||
|
|
313
|
+
health.build.state === "running");
|
|
314
|
+
if (ready.state === "ready" && waitingForBuild) {
|
|
315
|
+
if (health.build.state === "running" && stages.stopImplement?.enabled) {
|
|
316
|
+
return stages.stopImplement;
|
|
317
|
+
}
|
|
318
|
+
return stages.build;
|
|
319
|
+
}
|
|
320
|
+
if (stages.fixFromProof?.enabled)
|
|
321
|
+
return stages.fixFromProof;
|
|
322
|
+
return stages.proof;
|
|
323
|
+
}
|
|
324
|
+
function proofHint(health) {
|
|
325
|
+
const proof = health.proof;
|
|
326
|
+
if (!proof.runtime) {
|
|
327
|
+
return "Blocked without fixtures/runtime.yaml (baseUrl and deterministic login).";
|
|
328
|
+
}
|
|
329
|
+
if (!buildAllowsProve(health.build)) {
|
|
330
|
+
return "Prove is locked until Build succeeded, or you Ignore a failed Build.";
|
|
331
|
+
}
|
|
332
|
+
if (proof.state === "passed")
|
|
333
|
+
return "Proof passed. Click to re-run.";
|
|
334
|
+
if (proof.state === "failed")
|
|
335
|
+
return proof.message ?? "Proof failed. Click to re-run.";
|
|
336
|
+
if (proof.state === "needs_review")
|
|
337
|
+
return "Proof needs review (noul between 0.15 and 0.75).";
|
|
338
|
+
if (proof.state === "stale") {
|
|
339
|
+
return proof.message ?? "Spec or build changed after the last proof run. Re-prove.";
|
|
340
|
+
}
|
|
341
|
+
return "Runs compiled derived/qa-plan.yaml in a browser. Progress and errors appear in Activity.";
|
|
342
|
+
}
|
|
343
|
+
function truncate(text, max) {
|
|
344
|
+
return text.length <= max ? text : `${text.slice(0, max - 1)}…`;
|
|
345
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const STARTER_TEMPLATE_PATH: string;
|
|
2
|
+
export declare function loadStarterRequirement(): Promise<string>;
|
|
3
|
+
export declare const EMPTY_TEMPLATE = "# Untitled requirement\n\n## Overview\n\nWhat problem does this requirement solve?\n\n## Business Rules\n\n### Rule title\n\nId: BR-001\nStatement:\nObservable:\n\n## Use Cases\n\n### Use case title\n\nId: UC-001\nActor:\nPreconditions:\nSteps:\n1.\nOutcome:\n\n## Roles & Permissions\n\n| Action | RoleA |\n| --- | --- |\n| example-action | allow |\n";
|
|
4
|
+
export declare const PERSONAS_STUB = "# Test-only personas. Never production credentials.\npersonas:\n RoleA:\n email: rolea@example.test\n password: test-only-not-production\n";
|
|
5
|
+
export declare const RUNTIME_STUB = "# How Req0 proves this pack. Test-only. Credentials stay in personas.yaml.\nbaseUrl: http://127.0.0.1:3000\nstartCommand: npm run dev\nresetCommand: npm run db:seed\nlogin:\n path: /login\n email: \"#email\"\n password: \"#password\"\n submit: \"button[type=submit]\"\n";
|
package/dist/template.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
const PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
5
|
+
export const STARTER_TEMPLATE_PATH = path.join(PACKAGE_ROOT, "docs/requirement-template.md");
|
|
6
|
+
export async function loadStarterRequirement() {
|
|
7
|
+
return readFile(STARTER_TEMPLATE_PATH, "utf8");
|
|
8
|
+
}
|
|
9
|
+
export const EMPTY_TEMPLATE = `# Untitled requirement
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
What problem does this requirement solve?
|
|
14
|
+
|
|
15
|
+
## Business Rules
|
|
16
|
+
|
|
17
|
+
### Rule title
|
|
18
|
+
|
|
19
|
+
Id: BR-001
|
|
20
|
+
Statement:
|
|
21
|
+
Observable:
|
|
22
|
+
|
|
23
|
+
## Use Cases
|
|
24
|
+
|
|
25
|
+
### Use case title
|
|
26
|
+
|
|
27
|
+
Id: UC-001
|
|
28
|
+
Actor:
|
|
29
|
+
Preconditions:
|
|
30
|
+
Steps:
|
|
31
|
+
1.
|
|
32
|
+
Outcome:
|
|
33
|
+
|
|
34
|
+
## Roles & Permissions
|
|
35
|
+
|
|
36
|
+
| Action | RoleA |
|
|
37
|
+
| --- | --- |
|
|
38
|
+
| example-action | allow |
|
|
39
|
+
`;
|
|
40
|
+
export const PERSONAS_STUB = `# Test-only personas. Never production credentials.
|
|
41
|
+
personas:
|
|
42
|
+
RoleA:
|
|
43
|
+
email: rolea@example.test
|
|
44
|
+
password: test-only-not-production
|
|
45
|
+
`;
|
|
46
|
+
export const RUNTIME_STUB = `# How Req0 proves this pack. Test-only. Credentials stay in personas.yaml.
|
|
47
|
+
baseUrl: http://127.0.0.1:3000
|
|
48
|
+
startCommand: npm run dev
|
|
49
|
+
resetCommand: npm run db:seed
|
|
50
|
+
login:
|
|
51
|
+
path: /login
|
|
52
|
+
email: "#email"
|
|
53
|
+
password: "#password"
|
|
54
|
+
submit: "button[type=submit]"
|
|
55
|
+
`;
|