@richjava/req0 0.6.0 → 0.8.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.
@@ -0,0 +1,86 @@
1
+ import { access, 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 STANDARDS_CONVENTION_DIR = "docs/requirement-standards";
6
+ export const STANDARDS_PACK_FILE = "pack.md";
7
+ export const STANDARDS_DOCUMENT_FILE = "document.md";
8
+ export const CONVENTION_PACK_REL = path.join(STANDARDS_CONVENTION_DIR, STANDARDS_PACK_FILE);
9
+ export const CONVENTION_DOCUMENT_REL = path.join(STANDARDS_CONVENTION_DIR, STANDARDS_DOCUMENT_FILE);
10
+ export const PACKAGE_PACK_STANDARD = path.join(PACKAGE_ROOT, CONVENTION_PACK_REL);
11
+ export const PACKAGE_DOCUMENT_STANDARD = path.join(PACKAGE_ROOT, CONVENTION_DOCUMENT_REL);
12
+ async function fileText(filePath) {
13
+ try {
14
+ const text = await readFile(filePath, "utf8");
15
+ return text.trim() ? text : null;
16
+ }
17
+ catch {
18
+ return null;
19
+ }
20
+ }
21
+ async function exists(filePath) {
22
+ try {
23
+ await access(filePath);
24
+ return true;
25
+ }
26
+ catch {
27
+ return false;
28
+ }
29
+ }
30
+ function configuredPath(repoRoot, raw) {
31
+ if (typeof raw !== "string" || !raw.trim())
32
+ return null;
33
+ return path.isAbsolute(raw) ? raw : path.resolve(repoRoot, raw);
34
+ }
35
+ function displayPath(repoRoot, abs) {
36
+ if (!repoRoot)
37
+ return abs;
38
+ const root = path.resolve(repoRoot);
39
+ const resolved = path.resolve(abs);
40
+ const prefix = root.endsWith(path.sep) ? root : `${root}${path.sep}`;
41
+ if (resolved === root || resolved.startsWith(prefix)) {
42
+ return path.relative(root, resolved).split(path.sep).join("/") || ".";
43
+ }
44
+ return abs;
45
+ }
46
+ async function resolveOne(repoRoot, configured, conventionRel, packaged) {
47
+ if (repoRoot) {
48
+ const fromConfig = configuredPath(repoRoot, configured);
49
+ if (fromConfig) {
50
+ const text = await fileText(fromConfig);
51
+ if (text)
52
+ return { path: displayPath(repoRoot, fromConfig), source: "config", text };
53
+ }
54
+ const convention = path.join(repoRoot, conventionRel);
55
+ if (await exists(convention)) {
56
+ const text = await fileText(convention);
57
+ if (text)
58
+ return { path: displayPath(repoRoot, convention), source: "convention", text };
59
+ }
60
+ }
61
+ const packagedText = (await fileText(packaged)) ?? "";
62
+ return { path: displayPath(repoRoot, packaged), source: "package", text: packagedText };
63
+ }
64
+ export async function loadStandards(repoRoot, config) {
65
+ const [pack, document] = await Promise.all([
66
+ resolveOne(repoRoot, config?.standards?.pack, CONVENTION_PACK_REL, PACKAGE_PACK_STANDARD),
67
+ resolveOne(repoRoot, config?.standards?.document, CONVENTION_DOCUMENT_REL, PACKAGE_DOCUMENT_STANDARD),
68
+ ]);
69
+ return { pack, document };
70
+ }
71
+ export function standardsBriefSection(standards) {
72
+ if (!standards)
73
+ return [];
74
+ return [
75
+ "## House standards",
76
+ "",
77
+ "Read both files. Satisfy them in **substance**. Emit **frozen grammar** (the required and optional `##` headings, `BR-NNN` / `UC-NNN`, and matrix `allow`/`deny`). Do not copy these files into the pack. Do not emit headings the compiler rejects.",
78
+ "If a house rule conflicts with the owner, write `derived/agent-questions.json` and stop. Do not guess.",
79
+ "",
80
+ `- Pack standard: \`${standards.pack.path}\``,
81
+ `- Document standard: \`${standards.document.path}\``,
82
+ "",
83
+ "Artifacts live in this pack's `context/` folder. Prefer `{UC-id}__{purpose}.ext` (example: `UC-001__replace-modal.png`) and mention them from the matching use case. Screenshots illustrate; they must not be the only place a behaviour is specified.",
84
+ "",
85
+ ];
86
+ }
@@ -0,0 +1,9 @@
1
+ import type { Req0Config } from "./types.js";
2
+ export declare const CONVENTION_SYSTEM_REL = "docs/system.md";
3
+ export type LoadedSystemMap = {
4
+ path: string;
5
+ text: string;
6
+ exists: boolean;
7
+ };
8
+ export declare function loadSystemMap(repoRoot: string | null, config?: Req0Config | null): Promise<LoadedSystemMap>;
9
+ export declare function systemMapBriefSection(system: LoadedSystemMap | null | undefined): string[];
@@ -0,0 +1,46 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import path from "node:path";
3
+ export const CONVENTION_SYSTEM_REL = "docs/system.md";
4
+ function displayPath(repoRoot, abs) {
5
+ if (!repoRoot)
6
+ return CONVENTION_SYSTEM_REL;
7
+ const root = path.resolve(repoRoot);
8
+ const resolved = path.resolve(abs);
9
+ const prefix = root.endsWith(path.sep) ? root : `${root}${path.sep}`;
10
+ if (resolved === root || resolved.startsWith(prefix)) {
11
+ return path.relative(root, resolved).split(path.sep).join("/") || ".";
12
+ }
13
+ return abs;
14
+ }
15
+ export async function loadSystemMap(repoRoot, config) {
16
+ if (!repoRoot) {
17
+ return { path: CONVENTION_SYSTEM_REL, text: "", exists: false };
18
+ }
19
+ const configured = typeof config?.system === "string" && config.system.trim()
20
+ ? path.isAbsolute(config.system)
21
+ ? config.system
22
+ : path.resolve(repoRoot, config.system)
23
+ : null;
24
+ const abs = configured ?? path.join(repoRoot, CONVENTION_SYSTEM_REL);
25
+ try {
26
+ const text = await readFile(abs, "utf8");
27
+ return { path: displayPath(repoRoot, abs), text, exists: true };
28
+ }
29
+ catch {
30
+ return { path: displayPath(repoRoot, abs), text: "", exists: false };
31
+ }
32
+ }
33
+ export function systemMapBriefSection(system) {
34
+ if (!system)
35
+ return [];
36
+ const pointer = system.exists
37
+ ? `Read \`${system.path}\`. That file is the as-built schema (entities, relationships). Do not treat it as the spec — \`requirement.md\` is the spec.`
38
+ : `\`${system.path}\` does not exist yet. This is the first map. Propose entities in the plan; the coding agent writes the file after a successful Implement.`;
39
+ return [
40
+ "## System map",
41
+ "",
42
+ pointer,
43
+ "Recommended headings (not compiled): Entities, Relationships, Notes. Optional mermaid is illustration only.",
44
+ "",
45
+ ];
46
+ }
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export declare const REQUIRED_H2: readonly ["Business Rules", "Use Cases", "Roles & Permissions"];
2
- export declare const OPTIONAL_H2: readonly ["Overview", "Out of scope", "Open questions", "Entities", "UI notes"];
2
+ export declare const OPTIONAL_H2: readonly ["Overview", "Out of scope", "Open questions", "Entities", "UI notes", "Definitions", "Data Definition", "Verification Scenarios", "Related Requirements", "Implementation Notes"];
3
3
  export type RequiredH2 = (typeof REQUIRED_H2)[number];
4
4
  export type OptionalH2 = (typeof OPTIONAL_H2)[number];
5
5
  export type FindingSeverity = "error" | "warning";
@@ -110,7 +110,7 @@ export type PackListItem = {
110
110
  };
111
111
  export type ReadyState = "not_yet" | "blocked" | "ready";
112
112
  export type ReadyReason = "spec_invalid" | "no_api_key" | "unchecked" | "blockers" | "passed";
113
- export type ReadyFindingKind = "persona_missing" | "untestable_rule" | "matrix_contradiction" | "pack_gate" | "section_score" | "uncertain";
113
+ export type ReadyFindingKind = "persona_missing" | "untestable_rule" | "matrix_contradiction" | "pack_gate" | "section_score" | "standards" | "uncertain";
114
114
  export type ReadyFinding = {
115
115
  id: string;
116
116
  kind: ReadyFindingKind;
@@ -169,6 +169,13 @@ export type Req0Config = {
169
169
  stack?: StackChoice;
170
170
  /** When false, Req0 does not own Implement. Prove uses Ready + runtime.yaml. */
171
171
  implement?: boolean;
172
+ /** Product-repo house standards. Paths are relative to the product root. */
173
+ standards?: {
174
+ pack?: string;
175
+ document?: string;
176
+ };
177
+ /** Product-repo as-built schema map. Relative to the product root. Default docs/system.md. */
178
+ system?: string;
172
179
  };
173
180
  export type ProductRepo = {
174
181
  root: string | null;
@@ -191,6 +198,8 @@ export type BuildMeter = {
191
198
  message?: string;
192
199
  /** Owner ignored a failed Build so Prove can run. */
193
200
  ignored?: boolean;
201
+ /** Plan vs coding. Not a top-level health.json key. */
202
+ phase?: "plan" | "code";
194
203
  };
195
204
  export type BuildRun = {
196
205
  specHash: string;
@@ -206,6 +215,8 @@ export type BuildRun = {
206
215
  waitingOnQuestions?: boolean;
207
216
  /** This run was Fix from proof. Used when resuming after answers. */
208
217
  fromProof?: boolean;
218
+ /** Planner vs coding agent. Not a health.json key. */
219
+ phase?: "plan" | "code";
209
220
  };
210
221
  export type ProofState = "not_yet" | "passed" | "failed" | "needs_review" | "stale";
211
222
  export type ProofFinding = {
package/dist/types.js CHANGED
@@ -9,4 +9,9 @@ export const OPTIONAL_H2 = [
9
9
  "Open questions",
10
10
  "Entities",
11
11
  "UI notes",
12
+ "Definitions",
13
+ "Data Definition",
14
+ "Verification Scenarios",
15
+ "Related Requirements",
16
+ "Implementation Notes",
12
17
  ];
@@ -0,0 +1,81 @@
1
+ # Requirements document authoring standard
2
+
3
+ House style for `docs/requirements/<id>/requirement.md`. This file is prose, not a second compiler. Agents **Read** it, satisfy it in substance, and emit Req0’s frozen grammar.
4
+
5
+ Req0 compiles only these `##` headings. Required: `Business Rules`, `Use Cases`, `Roles & Permissions`. Optional: `Overview`, `Out of scope`, `Open questions`, `Entities`, `UI notes`, `Definitions`, `Data Definition`, `Verification Scenarios`, `Related Requirements`, `Implementation Notes`. IDs are `BR-001` / `UC-001`. Matrix cells are `allow` or `deny`.
6
+
7
+ Do not emit `REQ_016_…`, `BR_016.1`, Yes/No/Conditional cells, or an `Artifacts/` heading. Screenshots live in the pack’s `context/` folder.
8
+
9
+ ## Title
10
+
11
+ The `#` title names the problem or capability, not the solution. Avoid “the system shall”.
12
+
13
+ ## Overview
14
+
15
+ Two to four sentences: who, what capability, what outcome. Not numbered rules. Put the owner’s description here.
16
+
17
+ ## Definitions (optional)
18
+
19
+ Glossary only. A definition is not a business rule. If a term implies behaviour, write a `BR-` rule.
20
+
21
+ ## Data Definition (optional)
22
+
23
+ Identify records, uniqueness, and derived fields. Do not hide behaviour here — behaviour is a business rule or use case.
24
+
25
+ ## Business Rules
26
+
27
+ Each rule is `###` title plus `Id: BR-NNN`, Statement, Observable.
28
+
29
+ - One atomic rule per ID.
30
+ - Statement is a rule, not a wish.
31
+ - Observable is what a person or test notices.
32
+ - Exceptions are sibling `BR-` rules, not footnotes.
33
+ - Association (which user, which record, which role) must be observable, not implied.
34
+
35
+ ## Use Cases
36
+
37
+ Each use case is `###` title plus `Id: UC-NNN`, Actor, Preconditions, numbered Steps, Outcome. Alternate paths are optional.
38
+
39
+ - Title names the intent, not a pixel.
40
+ - Actor is a matrix column.
41
+ - Steps use `Open` / `Choose` / `Look for` / `Select`.
42
+ - `Choose` is allow. `Look for` is deny.
43
+ - Outcome is what a person sees: status, label, control present / absent / disabled.
44
+ - Cover happy path, deny path, and empty or error paths that matter.
45
+ - Mention `context/` screenshots from the matching use case (`UC-001__replace-modal.png`). Do not leave behaviour only in the image.
46
+
47
+ ## Roles & Permissions
48
+
49
+ One markdown table. First column `Action`. Other columns are roles. Cells `allow` or `deny` only.
50
+
51
+ - Every role and action the spec talks about appears.
52
+ - Consistent with the business rules. An allow cell plus a rule that hides or disables a control is consistent — keep the Look-for use case.
53
+
54
+ ## Verification Scenarios (optional)
55
+
56
+ How a person would check the pack. Every `BR-` and `UC-` should be exercisable. Do not put the only acceptance here if a rule or use case should own it.
57
+
58
+ ## Related Requirements (optional)
59
+
60
+ Pointers to other packs. Do not restate this pack’s rules.
61
+
62
+ ## Implementation Notes and UI notes (optional)
63
+
64
+ Hints for builders. **No hidden acceptance.** If a note would fail a test, it belongs in a business rule or use case.
65
+
66
+ ## Out of scope / Open questions / Entities
67
+
68
+ Optional frozen headings. Out of scope is what this pack does not cover. Open questions are unresolved owner decisions. Entities name things the spec talks about.
69
+
70
+ ## Document checklist
71
+
72
+ - [ ] Title names the problem, not the solution.
73
+ - [ ] Overview is intent, not a rule list.
74
+ - [ ] Definitions are glossary; data describes data; neither hides behaviour.
75
+ - [ ] Every business rule has a unique `BR-NNN`, Statement, and Observable.
76
+ - [ ] Every use case has a unique `UC-NNN`, actor, numbered steps, and observable Outcome.
77
+ - [ ] Matrix is complete with `allow` / `deny` only and matches the rules.
78
+ - [ ] Deny, empty, and error paths that matter have use cases.
79
+ - [ ] Implementation notes do not hide acceptance criteria.
80
+ - [ ] Related packs are pointers, not a second spec.
81
+ - [ ] Screenshots in `context/` are referenced; they do not introduce unstated behaviour.
@@ -0,0 +1,54 @@
1
+ # Requirement pack standard
2
+
3
+ House style for a pack under `docs/requirements/<id>/`. This file is prose, not a second compiler. Agents **Read** it, satisfy it in substance, and keep Req0’s folder layout and frozen `requirement.md` grammar.
4
+
5
+ ## Folder
6
+
7
+ ```text
8
+ docs/requirements/<kebab-id>/
9
+ requirement.md # canonical spec; humans and agents write this
10
+ fixtures/personas.yaml # test users per matrix role, never production credentials
11
+ fixtures/runtime.yaml # Prove: app URL and login selectors
12
+ context/ # optional screenshots the authoring agent can Read
13
+ derived/ # generated; do not hand-edit
14
+ ```
15
+
16
+ `<kebab-id>` is the folder name (`invoice-approval`). Do not invent a parallel `Artifacts/` tree or `REQ_016_…` filenames.
17
+
18
+ ## Canonical file
19
+
20
+ `requirement.md` is the spec. Screenshots illustrate. If behaviour appears only in an image, write it into a business rule or use case.
21
+
22
+ ## context/ artifacts
23
+
24
+ - PNG, JPG, or WebP.
25
+ - Name `{UC-id}__{purpose}.{ext}` (example: `UC-001__replace-modal.png`).
26
+ - Every file is referenced from the matching use case (or Overview if it is pack-level context).
27
+ - Keep artifacts current. A renamed use case needs a renamed or updated screenshot.
28
+ - A mock is not a screenshot of production. Say which it is in the use case or Overview.
29
+
30
+ ## Observability of association
31
+
32
+ Rules and outcomes must make the link between actor, record, and permission noticeable. “The right user sees the right invoice” is not observable until the Observable says how.
33
+
34
+ ## Completeness
35
+
36
+ A pack that is safe to hand to an agent has:
37
+
38
+ - Roles in the matrix, each with a persona when Ready is the bar
39
+ - Business rules with Observables
40
+ - Use cases for allow and deny paths that matter
41
+ - A matrix that does not contradict those use cases
42
+ - Artifacts that exist, are named, and are referenced
43
+ - No behaviour that lives only in Implementation Notes or a screenshot
44
+
45
+ ## Pack checklist
46
+
47
+ - [ ] Folder matches `docs/requirements/<id>/` with `requirement.md` and `context/` (not `Artifacts/`).
48
+ - [ ] `requirement.md` is canonical; screenshots do not introduce unstated behaviour.
49
+ - [ ] `context/` files use `{UC-id}__{purpose}.ext` and are referenced.
50
+ - [ ] Referenced artifacts still match the use cases they illustrate.
51
+ - [ ] Association between user, record, and role is observable in rules or outcomes.
52
+ - [ ] Every `BR-` and `UC-` is exercisable through use cases or verification scenarios.
53
+ - [ ] Implementation notes are hints, not a second acceptance list.
54
+ - [ ] Personas and runtime fixtures stay in `fixtures/`, not in the spec.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@richjava/req0",
3
- "version": "0.6.0",
3
+ "version": "0.8.0",
4
4
  "description": "Requirement operating system: spec packs, a local cockpit, Jev, coding-agent implement, and browser proof.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -10,7 +10,9 @@
10
10
  "files": [
11
11
  "dist",
12
12
  "cockpit",
13
- "docs/requirement-template.md"
13
+ "docs/requirement-template.md",
14
+ "docs/requirement-standards/pack.md",
15
+ "docs/requirement-standards/document.md"
14
16
  ],
15
17
  "repository": {
16
18
  "type": "git",