@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.
Files changed (70) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +117 -0
  3. package/cockpit/android-chrome-192x192.png +0 -0
  4. package/cockpit/android-chrome-512x512.png +0 -0
  5. package/cockpit/app.js +1710 -0
  6. package/cockpit/apple-touch-icon.png +0 -0
  7. package/cockpit/favicon-16x16.png +0 -0
  8. package/cockpit/favicon-32x32.png +0 -0
  9. package/cockpit/favicon.ico +0 -0
  10. package/cockpit/index.html +180 -0
  11. package/cockpit/markdown-editor.js +93 -0
  12. package/cockpit/req0-logo-horiz.png +0 -0
  13. package/cockpit/req0-logo-stacked.png +0 -0
  14. package/cockpit/site.webmanifest +19 -0
  15. package/cockpit/styles.css +1710 -0
  16. package/cockpit/tokens.css +118 -0
  17. package/dist/adapter.d.ts +5 -0
  18. package/dist/adapter.js +16 -0
  19. package/dist/browser.d.ts +33 -0
  20. package/dist/browser.js +524 -0
  21. package/dist/cli.d.ts +2 -0
  22. package/dist/cli.js +265 -0
  23. package/dist/compile.d.ts +5 -0
  24. package/dist/compile.js +456 -0
  25. package/dist/diff.d.ts +15 -0
  26. package/dist/diff.js +114 -0
  27. package/dist/fix-from-proof.d.ts +13 -0
  28. package/dist/fix-from-proof.js +61 -0
  29. package/dist/gates.d.ts +7 -0
  30. package/dist/gates.js +7 -0
  31. package/dist/implement-brief.d.ts +9 -0
  32. package/dist/implement-brief.js +142 -0
  33. package/dist/implement.d.ts +70 -0
  34. package/dist/implement.js +615 -0
  35. package/dist/improve-log.d.ts +11 -0
  36. package/dist/improve-log.js +38 -0
  37. package/dist/improve-review.d.ts +45 -0
  38. package/dist/improve-review.js +182 -0
  39. package/dist/improve.d.ts +16 -0
  40. package/dist/improve.js +127 -0
  41. package/dist/jev-pack.d.ts +2 -0
  42. package/dist/jev-pack.js +114 -0
  43. package/dist/jev.d.ts +23 -0
  44. package/dist/jev.js +142 -0
  45. package/dist/pack.d.ts +101 -0
  46. package/dist/pack.js +609 -0
  47. package/dist/personas.d.ts +13 -0
  48. package/dist/personas.js +88 -0
  49. package/dist/proof-report.d.ts +8 -0
  50. package/dist/proof-report.js +82 -0
  51. package/dist/proof.d.ts +45 -0
  52. package/dist/proof.js +394 -0
  53. package/dist/qa-plan.d.ts +6 -0
  54. package/dist/qa-plan.js +58 -0
  55. package/dist/ready.d.ts +29 -0
  56. package/dist/ready.js +317 -0
  57. package/dist/runtime.d.ts +25 -0
  58. package/dist/runtime.js +125 -0
  59. package/dist/server.d.ts +15 -0
  60. package/dist/server.js +588 -0
  61. package/dist/stack.d.ts +35 -0
  62. package/dist/stack.js +220 -0
  63. package/dist/stages.d.ts +15 -0
  64. package/dist/stages.js +345 -0
  65. package/dist/template.d.ts +5 -0
  66. package/dist/template.js +55 -0
  67. package/dist/types.d.ts +282 -0
  68. package/dist/types.js +12 -0
  69. package/docs/requirement-template.md +341 -0
  70. package/package.json +81 -0
@@ -0,0 +1,142 @@
1
+ import { DEFAULT_STACK, isAmplifyStack, stackInstruction } from "./stack.js";
2
+ export function emitImplementBrief(input) {
3
+ const { spec, repo, adapter, personas } = input;
4
+ const lines = [
5
+ `# Implement: ${spec.title}`,
6
+ "",
7
+ "Portable coding-agent brief. Read this file, then the compiled `derived/spec.json`. Do not invent rule, use-case, or role IDs.",
8
+ "",
9
+ "## Stack",
10
+ "",
11
+ stackInstruction(repo, adapter),
12
+ "",
13
+ `Default stack (empty repo only): ${DEFAULT_STACK.label}.`,
14
+ "",
15
+ ];
16
+ if (isAmplifyStack(repo.stack)) {
17
+ lines.push("## AWS", "", "Scaffold Next.js plus `amplify/` (Cognito Auth, Data, S3 Storage). Named BR- and UC- IDs only.", "Map matrix roles to Cognito groups. Seed test users from existing `fixtures/personas.yaml`.", "First-party `/login` with `#email` and `#password`. Do not use Cognito Hosted UI.", "", "1. Identity. `ampx` does not read `.env`. It uses `AWS_PROFILE`, inherited `AWS_ACCESS_KEY_ID`, or `~/.aws`. If this process has none of those, stop. Tell the owner: create a non-root IAM user, attach the Amplify backend deploy policy, run `npx ampx configure profile`, then re-run Implement. Do not ask for keys in chat. Do not print env values. Do not invent pool ids. IAM user keys do not use `AWS_SESSION_TOKEN`; that name is for temporary or SSO creds, and for Lambda `DataClientEnv` at runtime.", "2. Toolchain. Prefer Node 20 or 22. Pin `tsx@4.19.4`. On Node 24, use explicit `.ts` imports under `amplify/` and `allowImportingTsExtensions` in `amplify/tsconfig.json`. After changing Node, tsx, or packages, restart sandbox — do not keep an old watch.", "3. Scaffold. Ship ambient `$amplify/env/<function>` declarations matching `DataClientEnv` (`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_SESSION_TOKEN`, `AWS_REGION`, `AMPLIFY_DATA_DEFAULT_NAME`). No top-level import in that `.d.ts`. Exclude `amplify/` from the Next.js tsconfig. Resolve seed script paths with `fileURLToPath(import.meta.url)`, not `import.meta.dirname`.", "4. Deploy. After scaffolding `amplify/`, run `npx ampx sandbox --once` in the product repo (`--profile <name>` when identity is a profile). Wait until it finishes. `amplify_outputs.json` must have a real `user_pool_id` (`us-east-1_…` or `ap-southeast-2_…`). Never leave `REPLACE_VIA_SANDBOX` — the browser then calls `cognito-idp.replace.amazonaws.com` (`ERR_NAME_NOT_RESOLVED`). That is not a missing persona. A missing seeded user is a real Cognito error against `cognito-idp.<region>.amazonaws.com`. `npm install` is not a deploy. If sandbox says the region is not bootstrapped, stop and tell the owner to create the `CDKToolkit` stack once as root or AdministratorAccess.", "5. App then seed. Restart `npm run dev` after outputs change. Seed Cognito users from `fixtures/personas.yaml` only after those real outputs exist. Point `fixtures/runtime.yaml` `baseUrl` at the running app. `resetCommand` must reseed Cognito users and fixture data.", "6. Gitignore `.env`, `.amplify`, and `amplify_outputs*`. Keep `.env.example` (names only).", "");
18
+ }
19
+ lines.push("## Overview", "", spec.optional.Overview?.trim() || "See the business rules and use cases.", "");
20
+ if (spec.optional["Out of scope"]?.trim()) {
21
+ lines.push("## Out of scope", "", spec.optional["Out of scope"].trim(), "");
22
+ }
23
+ lines.push("## Acceptance criteria (business rules)", "", "Each rule is an acceptance criterion. Implement the Observable, not a paraphrase.", "");
24
+ for (const rule of spec.businessRules) {
25
+ lines.push(`### ${rule.id} — ${rule.title}`, "", `- Statement: ${rule.statement}`, `- Observable: ${rule.observable}`, "");
26
+ }
27
+ lines.push("## Flows (use cases)", "");
28
+ for (const useCase of spec.useCases) {
29
+ lines.push(`### ${useCase.id} — ${useCase.title}`, "", `- Actor: ${useCase.actor}`, `- Preconditions: ${useCase.preconditions}`, "- Steps:");
30
+ useCase.steps.forEach((step, index) => {
31
+ lines.push(` ${index + 1}. ${step}`);
32
+ });
33
+ lines.push(`- Outcome: ${useCase.outcome}`);
34
+ if (useCase.alternatePaths)
35
+ lines.push(`- Alternate paths: ${useCase.alternatePaths}`);
36
+ lines.push("");
37
+ }
38
+ lines.push("## Authorization (roles and permissions)", "", `| Action | ${spec.matrix.roles.join(" | ")} |`, `| --- | ${spec.matrix.roles.map(() => "---").join(" | ")} |`);
39
+ for (const action of spec.matrix.actions) {
40
+ const cells = spec.matrix.roles.map((role) => action.permissions[role] ?? "");
41
+ lines.push(`| ${action.id} | ${cells.join(" | ")} |`);
42
+ }
43
+ lines.push("", "Permission checks belong on the server, not only hidden buttons.", "");
44
+ lines.push("## Personas (test only)", "", "Never production credentials. Seed these users so role QA can log in later.", "");
45
+ if (personas && personas.personas.size > 0) {
46
+ for (const persona of personas.personas.values()) {
47
+ lines.push(`- ${persona.role}: ${persona.email}`);
48
+ }
49
+ lines.push("", "Passwords and extras: `fixtures/personas.yaml`.", "");
50
+ }
51
+ else {
52
+ lines.push("No personas parsed. See `fixtures/personas.yaml`. Ready will block Implement until each matrix role has one.", "");
53
+ }
54
+ if (spec.optional.Entities?.trim()) {
55
+ lines.push("## Entities", "", spec.optional.Entities.trim(), "");
56
+ }
57
+ if (spec.optional["UI notes"]?.trim()) {
58
+ lines.push("## UI notes", "", spec.optional["UI notes"].trim(), "");
59
+ }
60
+ if (spec.optional["Open questions"]?.trim()) {
61
+ lines.push("## Open questions", "", spec.optional["Open questions"].trim(), "");
62
+ }
63
+ lines.push("## Product README", "", "Write `README.md` at the product repo root so a stranger can run the app. If a README already exists, update the setup section. Use this requirement's title and the pack paths below. Do not invent a product name.", "", "~~~~markdown", productReadmeTemplate(spec, repo.stack), "~~~~", "");
64
+ lines.push("## Pack files", "", "- Seed the app from existing `fixtures/personas.yaml`. Do not add roles. Do not invent emails.", "- `fixtures/runtime.yaml` may be a stub. Set `baseUrl`, `startCommand`, and `resetCommand` to the app you started. Keep login selectors unless you change `/login` to match — then change both.", "- Write or update the product-repo `.env.example` with variable names only. No real keys.", "- Write `README.md` at the product repo root using the Product README section. Use this requirement's title and pack paths. Do not invent a product name.", "- The seed/reset script command must match `runtime.yaml` `resetCommand`.", "- First-party `/login` must match those selectors.", "", "## Security baseline", "", "- No production credentials in the spec or this brief.", "- Secrets via environment variables.", "- Personas are test-only.", "", "## Done means", "", isAmplifyStack(repo.stack)
65
+ ? "The app exists in the recorded stack. AWS identity was available (profile or inherited keys). `npx ampx sandbox --once` has been run. `amplify_outputs.json` has real Cognito ids, not `REPLACE_VIA_SANDBOX`. Personas are seeded in Cognito. `fixtures/runtime.yaml` matches that app. Product `.env.example` has names only. Product `README.md` has setup for this stack."
66
+ : "The app exists in the recorded stack. Personas are seeded. `fixtures/runtime.yaml` matches that app. Product `.env.example` has names only. Product `README.md` has setup for this stack.", "A coding-agent run finishing is **Build Succeeded**, not “the app boots.” Boot and login are Proof (Milestone 4).", "");
67
+ return `${lines.join("\n")}\n`;
68
+ }
69
+ export function productReadmeTemplate(spec, stack) {
70
+ const overview = spec.optional.Overview?.trim().split(/\n\n/)[0]?.replace(/\s+/g, " ").trim() ||
71
+ "See the business rules and use cases.";
72
+ const pack = `docs/requirements/${spec.requirementId}`;
73
+ const stackLine = isAmplifyStack(stack)
74
+ ? "Amplify Gen 2 (Cognito Auth, Data, S3) + Next.js App Router."
75
+ : `${stack.label}.`;
76
+ if (isAmplifyStack(stack)) {
77
+ return [
78
+ `# ${spec.title}`,
79
+ "",
80
+ overview,
81
+ "",
82
+ "## Stack",
83
+ "",
84
+ stackLine,
85
+ "",
86
+ "## Setup",
87
+ "",
88
+ "1. Copy `.env.example` to `.env` and set `AWS_REGION` plus `AWS_PROFILE` or access keys. `ampx` does not read `.env` — export the vars or run `npx ampx configure profile`.",
89
+ "2. Deploy the sandbox backend (writes `amplify_outputs.json`):",
90
+ "",
91
+ "```bash",
92
+ "npm run sandbox",
93
+ "```",
94
+ "",
95
+ "3. In another terminal, seed Cognito personas and fixture data:",
96
+ "",
97
+ "```bash",
98
+ "npm run db:seed",
99
+ "```",
100
+ "",
101
+ "4. Start the app (restart after `amplify_outputs.json` changes):",
102
+ "",
103
+ "```bash",
104
+ "npm run dev",
105
+ "```",
106
+ "",
107
+ `Login personas are in \`${pack}/fixtures/personas.yaml\`.`,
108
+ "",
109
+ `Req0 runtime: \`${pack}/fixtures/runtime.yaml\`.`,
110
+ "",
111
+ ].join("\n");
112
+ }
113
+ return [
114
+ `# ${spec.title}`,
115
+ "",
116
+ overview,
117
+ "",
118
+ "## Stack",
119
+ "",
120
+ stackLine,
121
+ "",
122
+ "## Setup",
123
+ "",
124
+ "1. Copy `.env.example` to `.env` and fill the names in that file.",
125
+ "2. Seed fixture data:",
126
+ "",
127
+ "```bash",
128
+ "npm run db:seed",
129
+ "```",
130
+ "",
131
+ "3. Start the app:",
132
+ "",
133
+ "```bash",
134
+ "npm run dev",
135
+ "```",
136
+ "",
137
+ `Login personas are in \`${pack}/fixtures/personas.yaml\`.`,
138
+ "",
139
+ `Req0 runtime: \`${pack}/fixtures/runtime.yaml\`.`,
140
+ "",
141
+ ].join("\n");
142
+ }
@@ -0,0 +1,70 @@
1
+ import { spawn, type ChildProcess } from "node:child_process";
2
+ import type { AdapterId, CompileResult } from "./types.js";
3
+ export declare const IMPLEMENT_AGENT_LOG = "implement-agent.log";
4
+ /** Hard cap on `ampx sandbox --once` starts in one Implement / Fix from proof run. */
5
+ export declare const IMPLEMENT_SANDBOX_MAX = 3;
6
+ /** Wall-clock cap so a debug loop cannot run indefinitely. */
7
+ export declare const IMPLEMENT_MAX_MS: number;
8
+ export declare const IMPLEMENT_STOPPED = "Owner stopped Implement.";
9
+ export declare const IMPLEMENT_SANDBOX_CAP = "Stopped after 3 sandbox deploys. Reimplement or Ignore, then Prove.";
10
+ export declare const IMPLEMENT_TIME_CAP = "Stopped after 20 minutes. Reimplement or Ignore, then Prove.";
11
+ export type ImplementStop = {
12
+ reason?: string;
13
+ };
14
+ export declare class ImplementLockedError extends Error {
15
+ readonly code = "ready_gate";
16
+ constructor(message?: string);
17
+ }
18
+ export declare class ImplementDisabledError extends Error {
19
+ readonly code = "implement_off";
20
+ constructor(message?: string);
21
+ }
22
+ export type LaunchAdapterDeps = {
23
+ spawn?: typeof spawn;
24
+ resolveBin?: () => string | null;
25
+ resolveCopilotBin?: () => string | null;
26
+ agentStatus?: (bin: string) => string;
27
+ settleMs?: number;
28
+ platform?: NodeJS.Platform;
29
+ prompt?: string;
30
+ successMessage?: string;
31
+ openIde?: boolean;
32
+ logFile?: string;
33
+ onLogLine?: (line: string) => void;
34
+ sandboxMax?: number;
35
+ maxMs?: number;
36
+ heartbeatLabel?: string;
37
+ cliName?: string;
38
+ };
39
+ export type LaunchAdapterResult = {
40
+ ok: boolean;
41
+ message: string;
42
+ child?: ChildProcess;
43
+ logPath?: string;
44
+ finished?: Promise<{
45
+ code: number | null;
46
+ }>;
47
+ stop?: ImplementStop;
48
+ };
49
+ export declare function adapterInstructions(adapter: AdapterId, briefPath: string): string;
50
+ export declare function implementPrompt(briefPath: string, stackId?: string): string;
51
+ export declare function fixFromProofPrompt(briefPath: string, reportPath: string, implementBriefPath: string): string;
52
+ export declare function improvePrompt(briefPath: string): string;
53
+ export declare function resolveCursorBin(): string | null;
54
+ export declare function resolveCopilotBin(): string | null;
55
+ export declare function cursorAgentStatus(bin: string): string;
56
+ export declare function assertImplementAllowed(result: CompileResult): void;
57
+ export declare function implementLogPath(briefPath: string, logFile?: string): string;
58
+ export declare function launchAdapter(adapter: AdapterId, repoRoot: string | null, briefPath: string, deps?: LaunchAdapterDeps): Promise<LaunchAdapterResult>;
59
+ export declare function attachAgentLog(child: ChildProcess, logPath: string, onLogLine?: (line: string) => void, control?: {
60
+ stop?: ImplementStop;
61
+ sandboxMax?: number;
62
+ maxMs?: number;
63
+ heartbeatLabel?: string;
64
+ }): Promise<{
65
+ code: number | null;
66
+ }>;
67
+ export declare function requestImplementStop(child: ChildProcess | undefined, stop: ImplementStop, reason: string): void;
68
+ export declare function killImplementTree(child?: ChildProcess): void;
69
+ export declare function isSandboxOnceStart(line: string): boolean;
70
+ export declare function summarizeAgentLine(line: string): string | null;