@richjava/req0 0.7.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.
@@ -1,2 +1,85 @@
1
+ import type { LoadedStandards } from "./standards.js";
1
2
  import type { JevPack, SpecAst } from "./types.js";
2
- export declare function emitJevPack(spec: SpecAst): JevPack;
3
+ export type JevPackContext = {
4
+ markdown?: string;
5
+ contextFiles?: string[];
6
+ standards?: LoadedStandards | null;
7
+ };
8
+ export declare const STD_DOCUMENT_QUESTIONS: readonly [{
9
+ readonly id: "std.document.title-names-problem";
10
+ readonly instructions: "Does the title name the problem or capability rather than the solution?";
11
+ readonly pass: "The # title is a problem or capability. It does not prescribe a solution or say 'the system shall'.";
12
+ readonly fail: "The title names a solution, a stack, or a system-shall statement.";
13
+ }, {
14
+ readonly id: "std.document.overview-intent";
15
+ readonly instructions: "Is Overview two to four sentences of actor, capability, and outcome — not a numbered rule list?";
16
+ readonly pass: "Overview states who, what, and the outcome. Numbered rules live under Business Rules.";
17
+ readonly fail: "Overview is missing, or it lists rules, IDs, or implementation steps instead of intent.";
18
+ }, {
19
+ readonly id: "std.document.definitions-glossary";
20
+ readonly instructions: "If Definitions exist, are they glossary only — not hidden business rules?";
21
+ readonly pass: "Definitions (if present) name terms. Behaviour is in BR- rules. Missing Definitions is fine when no glossary is needed.";
22
+ readonly fail: "Definitions contain obligations, permissions, or exceptions that belong in Business Rules.";
23
+ }, {
24
+ readonly id: "std.document.data-not-behaviour";
25
+ readonly instructions: "If Data Definition exists, does it describe data rather than behaviour?";
26
+ readonly pass: "Data Definition (if present) covers records, uniqueness, or derived fields. Behaviour is a rule or use case. Missing Data Definition is fine when data is obvious.";
27
+ readonly fail: "Data Definition hides workflow, permissions, or observables that belong in BR- or UC- entries.";
28
+ }, {
29
+ readonly id: "std.document.rules-atomic-observable";
30
+ readonly instructions: "Is each business rule one atomic obligation with a noticeable Observable, and are exceptions sibling BR- rules?";
31
+ readonly pass: "Each BR-NNN is one rule. Statement plus Observable make association (user, record, role) noticeable. Exceptions are separate IDs.";
32
+ readonly fail: "A rule bundles multiple obligations, lacks a noticeable Observable, or buries exceptions in prose.";
33
+ }, {
34
+ readonly id: "std.document.usecases-complete";
35
+ readonly instructions: "Does each use case have actor, intent-named title, numbered steps, observable Outcome, and deny/empty/error paths that matter?";
36
+ readonly pass: "UC- entries use frozen step verbs, Outcomes a person can see, and cover allow plus material deny or empty paths.";
37
+ readonly fail: "A use case is UI-pixel named, missing Outcome, or omits a deny/empty/error path the rules imply.";
38
+ }, {
39
+ readonly id: "std.document.matrix-allow-deny";
40
+ readonly instructions: "Is the roles matrix complete with allow/deny only and consistent with the business rules?";
41
+ readonly pass: "Every role and action the spec talks about appears. Cells are allow or deny. An allow cell plus a rule that hides a control is consistent.";
42
+ readonly fail: "The matrix omits a role or action, uses other cell values, or contradicts the rules without a Look-for use case.";
43
+ }, {
44
+ readonly id: "std.document.no-hidden-acceptance";
45
+ readonly instructions: "Do Implementation Notes and UI notes avoid hidden acceptance criteria?";
46
+ readonly pass: "Notes are builder hints. Anything a test would fail on lives in a business rule or use case. Missing notes is fine.";
47
+ readonly fail: "Implementation Notes, UI notes, or similar prose is the only place an acceptance criterion appears.";
48
+ }, {
49
+ readonly id: "std.document.related-not-restated";
50
+ readonly instructions: "If Related Requirements exist, are they pointers rather than a restatement of this pack's rules?";
51
+ readonly pass: "Related Requirements (if present) name other packs. This pack's obligations stay in its BR- and UC- entries.";
52
+ readonly fail: "Related Requirements copy or replace this pack's rules.";
53
+ }];
54
+ export declare const STD_PACK_QUESTIONS: readonly [{
55
+ readonly id: "std.pack.screenshots-not-spec";
56
+ readonly instructions: "Is requirement.md the canonical spec, with screenshots only illustrating stated behaviour?";
57
+ readonly pass: "Every behaviour a screenshot shows is also in a business rule or use case. Images do not introduce unstated behaviour.";
58
+ readonly fail: "A screenshot or mock is the only place a behaviour is specified.";
59
+ }, {
60
+ readonly id: "std.pack.artifacts-named-referenced";
61
+ readonly instructions: "Are context/ files named {UC-id}__{purpose}.ext and referenced from the matching use case?";
62
+ readonly pass: "Existing context files follow UC-001__purpose.ext (or are pack-level and mentioned in Overview). Each is referenced. Empty context/ is fine.";
63
+ readonly fail: "A context file exists but is unnamed, unreferenced, or uses a layout other than this pack's context/ folder.";
64
+ }, {
65
+ readonly id: "std.pack.artifacts-current";
66
+ readonly instructions: "Do referenced context/ files still match the use cases they illustrate?";
67
+ readonly pass: "Filenames and mentions line up with current UC- IDs. Empty context/ is fine.";
68
+ readonly fail: "A screenshot name or caption points at a use case that no longer exists or was renamed.";
69
+ }, {
70
+ readonly id: "std.pack.association-observable";
71
+ readonly instructions: "Is the association between actor, record, and permission noticeable in rules or outcomes?";
72
+ readonly pass: "A person or test can tell which user, which record, and which role apply from Observables and Outcomes.";
73
+ readonly fail: "Association is implied ('the right user sees the right record') without a noticeable Observable.";
74
+ }, {
75
+ readonly id: "std.pack.verification-coverage";
76
+ readonly instructions: "Is every BR- and UC- exercisable through use cases or verification scenarios — not only implementation notes?";
77
+ readonly pass: "Each ID can be checked from a use case or Verification Scenarios. Notes are not the only coverage.";
78
+ readonly fail: "A rule or use case has no path a person could follow, or coverage lives only in Implementation Notes.";
79
+ }, {
80
+ readonly id: "std.pack.completeness";
81
+ readonly instructions: "Does the pack have roles, business rules, use cases, a consistent matrix, and referenced artifacts when files exist?";
82
+ readonly pass: "The pack is complete enough that an agent would not invent roles, rules, or screenshot-only behaviour.";
83
+ readonly fail: "A required piece is missing in substance, or artifacts exist without being part of the spec.";
84
+ }];
85
+ export declare function emitJevPack(spec: SpecAst, context?: JevPackContext): JevPack;
package/dist/jev-pack.js CHANGED
@@ -1,6 +1,108 @@
1
1
  import { JEV_CATALOG, SECTION_SCORE_LEVELS } from "./gates.js";
2
- export function emitJevPack(spec) {
2
+ const JEV_STATE_CLIP = 8_000;
3
+ const STD_STATE_CLIP = 4_000;
4
+ export const STD_DOCUMENT_QUESTIONS = [
5
+ {
6
+ id: "std.document.title-names-problem",
7
+ instructions: "Does the title name the problem or capability rather than the solution?",
8
+ pass: "The # title is a problem or capability. It does not prescribe a solution or say 'the system shall'.",
9
+ fail: "The title names a solution, a stack, or a system-shall statement.",
10
+ },
11
+ {
12
+ id: "std.document.overview-intent",
13
+ instructions: "Is Overview two to four sentences of actor, capability, and outcome — not a numbered rule list?",
14
+ pass: "Overview states who, what, and the outcome. Numbered rules live under Business Rules.",
15
+ fail: "Overview is missing, or it lists rules, IDs, or implementation steps instead of intent.",
16
+ },
17
+ {
18
+ id: "std.document.definitions-glossary",
19
+ instructions: "If Definitions exist, are they glossary only — not hidden business rules?",
20
+ pass: "Definitions (if present) name terms. Behaviour is in BR- rules. Missing Definitions is fine when no glossary is needed.",
21
+ fail: "Definitions contain obligations, permissions, or exceptions that belong in Business Rules.",
22
+ },
23
+ {
24
+ id: "std.document.data-not-behaviour",
25
+ instructions: "If Data Definition exists, does it describe data rather than behaviour?",
26
+ pass: "Data Definition (if present) covers records, uniqueness, or derived fields. Behaviour is a rule or use case. Missing Data Definition is fine when data is obvious.",
27
+ fail: "Data Definition hides workflow, permissions, or observables that belong in BR- or UC- entries.",
28
+ },
29
+ {
30
+ id: "std.document.rules-atomic-observable",
31
+ instructions: "Is each business rule one atomic obligation with a noticeable Observable, and are exceptions sibling BR- rules?",
32
+ pass: "Each BR-NNN is one rule. Statement plus Observable make association (user, record, role) noticeable. Exceptions are separate IDs.",
33
+ fail: "A rule bundles multiple obligations, lacks a noticeable Observable, or buries exceptions in prose.",
34
+ },
35
+ {
36
+ id: "std.document.usecases-complete",
37
+ instructions: "Does each use case have actor, intent-named title, numbered steps, observable Outcome, and deny/empty/error paths that matter?",
38
+ pass: "UC- entries use frozen step verbs, Outcomes a person can see, and cover allow plus material deny or empty paths.",
39
+ fail: "A use case is UI-pixel named, missing Outcome, or omits a deny/empty/error path the rules imply.",
40
+ },
41
+ {
42
+ id: "std.document.matrix-allow-deny",
43
+ instructions: "Is the roles matrix complete with allow/deny only and consistent with the business rules?",
44
+ pass: "Every role and action the spec talks about appears. Cells are allow or deny. An allow cell plus a rule that hides a control is consistent.",
45
+ fail: "The matrix omits a role or action, uses other cell values, or contradicts the rules without a Look-for use case.",
46
+ },
47
+ {
48
+ id: "std.document.no-hidden-acceptance",
49
+ instructions: "Do Implementation Notes and UI notes avoid hidden acceptance criteria?",
50
+ pass: "Notes are builder hints. Anything a test would fail on lives in a business rule or use case. Missing notes is fine.",
51
+ fail: "Implementation Notes, UI notes, or similar prose is the only place an acceptance criterion appears.",
52
+ },
53
+ {
54
+ id: "std.document.related-not-restated",
55
+ instructions: "If Related Requirements exist, are they pointers rather than a restatement of this pack's rules?",
56
+ pass: "Related Requirements (if present) name other packs. This pack's obligations stay in its BR- and UC- entries.",
57
+ fail: "Related Requirements copy or replace this pack's rules.",
58
+ },
59
+ ];
60
+ export const STD_PACK_QUESTIONS = [
61
+ {
62
+ id: "std.pack.screenshots-not-spec",
63
+ instructions: "Is requirement.md the canonical spec, with screenshots only illustrating stated behaviour?",
64
+ pass: "Every behaviour a screenshot shows is also in a business rule or use case. Images do not introduce unstated behaviour.",
65
+ fail: "A screenshot or mock is the only place a behaviour is specified.",
66
+ },
67
+ {
68
+ id: "std.pack.artifacts-named-referenced",
69
+ instructions: "Are context/ files named {UC-id}__{purpose}.ext and referenced from the matching use case?",
70
+ pass: "Existing context files follow UC-001__purpose.ext (or are pack-level and mentioned in Overview). Each is referenced. Empty context/ is fine.",
71
+ fail: "A context file exists but is unnamed, unreferenced, or uses a layout other than this pack's context/ folder.",
72
+ },
73
+ {
74
+ id: "std.pack.artifacts-current",
75
+ instructions: "Do referenced context/ files still match the use cases they illustrate?",
76
+ pass: "Filenames and mentions line up with current UC- IDs. Empty context/ is fine.",
77
+ fail: "A screenshot name or caption points at a use case that no longer exists or was renamed.",
78
+ },
79
+ {
80
+ id: "std.pack.association-observable",
81
+ instructions: "Is the association between actor, record, and permission noticeable in rules or outcomes?",
82
+ pass: "A person or test can tell which user, which record, and which role apply from Observables and Outcomes.",
83
+ fail: "Association is implied ('the right user sees the right record') without a noticeable Observable.",
84
+ },
85
+ {
86
+ id: "std.pack.verification-coverage",
87
+ instructions: "Is every BR- and UC- exercisable through use cases or verification scenarios — not only implementation notes?",
88
+ pass: "Each ID can be checked from a use case or Verification Scenarios. Notes are not the only coverage.",
89
+ fail: "A rule or use case has no path a person could follow, or coverage lives only in Implementation Notes.",
90
+ },
91
+ {
92
+ id: "std.pack.completeness",
93
+ instructions: "Does the pack have roles, business rules, use cases, a consistent matrix, and referenced artifacts when files exist?",
94
+ pass: "The pack is complete enough that an agent would not invent roles, rules, or screenshot-only behaviour.",
95
+ fail: "A required piece is missing in substance, or artifacts exist without being part of the spec.",
96
+ },
97
+ ];
98
+ export function emitJevPack(spec, context = {}) {
3
99
  const questions = [];
100
+ const contextFiles = context.contextFiles ?? [];
101
+ const packStandard = clip(context.standards?.pack.text ?? "", JEV_STATE_CLIP);
102
+ const documentStandard = clip(context.standards?.document.text ?? "", JEV_STATE_CLIP);
103
+ const optionalPresent = Object.entries(spec.optional)
104
+ .filter(([, body]) => body?.trim())
105
+ .map(([name]) => name);
4
106
  for (const rule of spec.businessRules) {
5
107
  questions.push({
6
108
  id: `rule.observable.${rule.id}`,
@@ -86,21 +188,61 @@ export function emitJevPack(spec) {
86
188
  type: "noul",
87
189
  instructions: "Is this pack safe to hand to a coding agent?",
88
190
  criteria: {
89
- true: "Rules are testable, use cases match the matrix, and an agent would not have to invent behavior.",
90
- false: "An agent would have to guess, or the pack still contradicts itself.",
191
+ true: "Rules are testable, use cases match the matrix, house standards are met in substance, and an agent would not have to invent behavior.",
192
+ false: "An agent would have to guess, the pack still contradicts itself, or it ignores the house pack/document standards.",
91
193
  },
92
194
  state: {
93
195
  ruleIds: spec.businessRules.map((rule) => rule.id),
94
196
  useCaseIds: spec.useCases.map((useCase) => useCase.id),
95
197
  roles: spec.matrix.roles,
198
+ optionalPresent,
199
+ contextFiles,
200
+ housePackStandard: packStandard,
201
+ houseDocumentStandard: documentStandard,
202
+ housePackPath: context.standards?.pack.path ?? "",
203
+ houseDocumentPath: context.standards?.document.path ?? "",
96
204
  },
97
205
  });
206
+ const stdState = {
207
+ title: spec.title,
208
+ markdown: clip(context.markdown ?? "", STD_STATE_CLIP),
209
+ ruleIds: spec.businessRules.map((rule) => rule.id),
210
+ useCaseIds: spec.useCases.map((useCase) => useCase.id),
211
+ roles: spec.matrix.roles,
212
+ optionalPresent,
213
+ contextFiles,
214
+ housePackStandard: clip(context.standards?.pack.text ?? "", STD_STATE_CLIP),
215
+ houseDocumentStandard: clip(context.standards?.document.text ?? "", STD_STATE_CLIP),
216
+ };
217
+ for (const item of STD_DOCUMENT_QUESTIONS) {
218
+ questions.push({
219
+ id: item.id,
220
+ type: "noul",
221
+ instructions: item.instructions,
222
+ criteria: { true: item.pass, false: item.fail },
223
+ state: stdState,
224
+ });
225
+ }
226
+ for (const item of STD_PACK_QUESTIONS) {
227
+ questions.push({
228
+ id: item.id,
229
+ type: "noul",
230
+ instructions: item.instructions,
231
+ criteria: { true: item.pass, false: item.fail },
232
+ state: stdState,
233
+ });
234
+ }
98
235
  return {
99
236
  requirementId: spec.requirementId,
100
237
  catalog: JEV_CATALOG,
101
238
  questions,
102
239
  };
103
240
  }
241
+ function clip(text, max) {
242
+ if (text.length <= max)
243
+ return text;
244
+ return `${text.slice(0, max)}\n…[truncated]`;
245
+ }
104
246
  function sectionScore(section, body) {
105
247
  const slug = section.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
106
248
  return {
package/dist/pack.d.ts CHANGED
@@ -34,6 +34,10 @@ export type PackPaths = {
34
34
  context: string;
35
35
  authorBrief: string;
36
36
  authorRun: string;
37
+ implementPlan: string;
38
+ implementPlanState: string;
39
+ implementPlanBrief: string;
40
+ implementPlans: string;
37
41
  };
38
42
  export declare function packPaths(root: string): PackPaths;
39
43
  export declare function withRememberedAnswers(paths: PackPaths, prompt: string): Promise<string>;
@@ -53,14 +57,17 @@ export declare function persistDerived(paths: PackPaths, result: CompileResult):
53
57
  export declare function createPack(root: string): Promise<PackPaths>;
54
58
  export declare function deletePack(paths: PackPaths): Promise<void>;
55
59
  export declare function writeRuntimeStubIfMissing(paths: PackPaths): Promise<boolean>;
56
- export declare function implementPack(paths: PackPaths, options?: {
60
+ type ImplementLaunchOptions = {
57
61
  adapter?: AdapterId;
58
62
  stack?: string;
59
63
  fromProof?: boolean;
60
64
  onLogLine?: (line: string) => void;
61
65
  extraPrompt?: string;
62
66
  resume?: boolean;
63
- }): Promise<{
67
+ /** Resume the coding agent after implement-channel questions. */
68
+ code?: boolean;
69
+ };
70
+ export declare function implementPack(paths: PackPaths, options?: ImplementLaunchOptions): Promise<{
64
71
  result: CompileResult;
65
72
  message: string;
66
73
  launch?: LaunchAdapterResult;
@@ -68,6 +75,7 @@ export declare function implementPack(paths: PackPaths, options?: {
68
75
  export declare function finishImplement(paths: PackPaths, launch: LaunchAdapterResult, adapter: AdapterId): Promise<{
69
76
  result: CompileResult;
70
77
  message: string;
78
+ launch?: LaunchAdapterResult;
71
79
  }>;
72
80
  export declare class StopImplementLockedError extends Error {
73
81
  readonly code = "stop_implement_gate";
@@ -134,13 +142,13 @@ export declare function answerAgentQuestions(paths: PackPaths, answers: Record<s
134
142
  }): Promise<{
135
143
  result: CompileResult;
136
144
  message: string;
137
- channel: "author" | "improve" | "implement";
145
+ channel: "author" | "improve" | "implement" | "plan";
138
146
  launch?: LaunchAdapterResult;
139
147
  }>;
140
148
  export declare function discardAgentQuestions(paths: PackPaths, launch: LaunchAdapterResult | null): Promise<{
141
149
  result: CompileResult;
142
150
  message: string;
143
- channel: "author" | "improve" | "implement";
151
+ channel: "author" | "improve" | "implement" | "plan";
144
152
  }>;
145
153
  export declare function improvePack(paths: PackPaths, options?: {
146
154
  adapter?: AdapterId;