@richjava/req0 0.2.0 → 0.4.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/README.md +6 -5
- package/cockpit/app.js +639 -34
- package/cockpit/index.html +51 -3
- package/cockpit/styles.css +109 -5
- package/dist/agent-questions.d.ts +59 -0
- package/dist/agent-questions.js +327 -0
- package/dist/author.d.ts +103 -0
- package/dist/author.js +435 -0
- package/dist/cli.js +6 -2
- package/dist/fix-from-proof.js +2 -0
- package/dist/implement-brief.js +2 -1
- package/dist/implement.d.ts +6 -0
- package/dist/implement.js +71 -20
- package/dist/improve.js +4 -3
- package/dist/pack.d.ts +63 -2
- package/dist/pack.js +330 -13
- package/dist/ready.js +7 -0
- package/dist/server.d.ts +3 -1
- package/dist/server.js +286 -7
- package/dist/types.d.ts +7 -1
- package/package.json +1 -1
package/dist/implement.js
CHANGED
|
@@ -10,6 +10,9 @@ export const IMPLEMENT_MAX_MS = 20 * 60 * 1000;
|
|
|
10
10
|
export const IMPLEMENT_STOPPED = "Owner stopped Implement.";
|
|
11
11
|
export const IMPLEMENT_SANDBOX_CAP = `Stopped after ${IMPLEMENT_SANDBOX_MAX} sandbox deploys. Reimplement or Ignore, then Prove.`;
|
|
12
12
|
export const IMPLEMENT_TIME_CAP = `Stopped after ${IMPLEMENT_MAX_MS / 60_000} minutes. Reimplement or Ignore, then Prove.`;
|
|
13
|
+
/** Cursor `--print` can emit `result` and then hang. Kill the leftover process after this grace. */
|
|
14
|
+
export const IMPLEMENT_EXIT_GRACE_MS = 3_000;
|
|
15
|
+
const AGENT_LOG_LINE_MAX = 65_536;
|
|
13
16
|
export class ImplementLockedError extends Error {
|
|
14
17
|
code = "ready_gate";
|
|
15
18
|
constructor(message = "Implement is locked until Ready is Ready. Check this spec with Jev first.") {
|
|
@@ -41,6 +44,7 @@ export function implementPrompt(briefPath, stackId) {
|
|
|
41
44
|
"Implement this requirement from the brief.",
|
|
42
45
|
`Read ${briefPath} and derived/spec.json.`,
|
|
43
46
|
"Do not invent spec IDs. Implement only the named BR- and UC- IDs.",
|
|
47
|
+
"If a required decision is missing, write derived/agent-questions.json and stop. Do not guess stack, auth, storage, or owner-facing copy. Do not write product code in that same turn.",
|
|
44
48
|
"If this product repo has no customer app, use the stack recorded in req0.json.",
|
|
45
49
|
"Seed the app from existing fixtures/personas.yaml. Do not invent personas.",
|
|
46
50
|
"Finish fixtures/runtime.yaml so baseUrl, startCommand, and resetCommand match the app. Keep login selectors unless you change /login to match.",
|
|
@@ -57,6 +61,7 @@ export function fixFromProofPrompt(briefPath, reportPath, implementBriefPath) {
|
|
|
57
61
|
"Fix the existing product from the last Prove.",
|
|
58
62
|
`Read ${briefPath}, then ${reportPath}, then ${implementBriefPath}.`,
|
|
59
63
|
"Close only the Failed and Needs review cases. Do not invent spec IDs.",
|
|
64
|
+
"If a required decision is missing, write derived/agent-questions.json and stop. Do not guess. Do not write product code in that same turn.",
|
|
60
65
|
"Do not edit requirement.md. Do not scaffold a second application.",
|
|
61
66
|
"Boot or Sign-in observations may be fixtures or runtime.yaml, not a missing control.",
|
|
62
67
|
"Do not treat this launch as proof the app boots.",
|
|
@@ -70,6 +75,7 @@ export function improvePrompt(briefPath) {
|
|
|
70
75
|
"Patch requirement.md only. If the brief asks for a persona, you may also edit fixtures/personas.yaml.",
|
|
71
76
|
"Outcome is what a person sees. Do not paste matrix allow/deny cells into Outcome. Look for is deny; Choose is allow.",
|
|
72
77
|
"Do not invent spec IDs. Do not implement the product app.",
|
|
78
|
+
"If a required decision is missing, write derived/agent-questions.json and stop. Do not guess. Do not patch requirement.md in that same turn.",
|
|
73
79
|
"Stop after the patch so the owner can review the diff, then Check with Jev.",
|
|
74
80
|
].join(" ");
|
|
75
81
|
}
|
|
@@ -288,6 +294,7 @@ function launchLogged(run, bin, args, cwd, logPath, deps) {
|
|
|
288
294
|
sandboxMax: deps.sandboxMax ?? IMPLEMENT_SANDBOX_MAX,
|
|
289
295
|
maxMs: deps.maxMs ?? IMPLEMENT_MAX_MS,
|
|
290
296
|
heartbeatLabel: deps.heartbeatLabel ?? `${deps.cliName ?? "Cursor"} agent still running.`,
|
|
297
|
+
exitGraceMs: deps.exitGraceMs ?? IMPLEMENT_EXIT_GRACE_MS,
|
|
291
298
|
});
|
|
292
299
|
child.once("error", (err) => {
|
|
293
300
|
resolve({
|
|
@@ -310,9 +317,25 @@ export function attachAgentLog(child, logPath, onLogLine, control = {}) {
|
|
|
310
317
|
const sandboxMax = control.sandboxMax ?? IMPLEMENT_SANDBOX_MAX;
|
|
311
318
|
const maxMs = control.maxMs ?? IMPLEMENT_MAX_MS;
|
|
312
319
|
const heartbeatLabel = control.heartbeatLabel ?? "Agent still running.";
|
|
320
|
+
const exitGraceMs = control.exitGraceMs ?? IMPLEMENT_EXIT_GRACE_MS;
|
|
313
321
|
let lastEmit = Date.now();
|
|
314
322
|
let lastShown = "";
|
|
315
323
|
let sandboxStarts = 0;
|
|
324
|
+
let settled = false;
|
|
325
|
+
let heartbeat;
|
|
326
|
+
let deadline;
|
|
327
|
+
let hangKill;
|
|
328
|
+
let settle = () => undefined;
|
|
329
|
+
const finish = (code) => {
|
|
330
|
+
if (settled)
|
|
331
|
+
return;
|
|
332
|
+
settled = true;
|
|
333
|
+
if (heartbeat)
|
|
334
|
+
clearInterval(heartbeat);
|
|
335
|
+
if (deadline)
|
|
336
|
+
clearTimeout(deadline);
|
|
337
|
+
settle({ code });
|
|
338
|
+
};
|
|
316
339
|
const feed = makeLineFeeder((line) => {
|
|
317
340
|
if (isSandboxOnceStart(line)) {
|
|
318
341
|
sandboxStarts += 1;
|
|
@@ -326,16 +349,26 @@ export function attachAgentLog(child, logPath, onLogLine, control = {}) {
|
|
|
326
349
|
return;
|
|
327
350
|
}
|
|
328
351
|
}
|
|
329
|
-
const
|
|
330
|
-
|
|
352
|
+
const raw = redactSecrets(line);
|
|
353
|
+
const outcome = agentStreamOutcome(raw);
|
|
354
|
+
const text = summarizeAgentLine(raw);
|
|
355
|
+
if (text && text !== lastShown) {
|
|
356
|
+
lastShown = text;
|
|
357
|
+
lastEmit = Date.now();
|
|
358
|
+
onLogLine?.(text);
|
|
359
|
+
}
|
|
360
|
+
if (!outcome || settled)
|
|
331
361
|
return;
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
362
|
+
finish(outcome === "success" ? 0 : 1);
|
|
363
|
+
hangKill = setTimeout(() => {
|
|
364
|
+
if (child.exitCode === null || child.exitCode === undefined)
|
|
365
|
+
killImplementTree(child);
|
|
366
|
+
}, Math.max(0, exitGraceMs));
|
|
367
|
+
hangKill.unref?.();
|
|
335
368
|
});
|
|
336
|
-
|
|
369
|
+
heartbeat = onLogLine
|
|
337
370
|
? setInterval(() => {
|
|
338
|
-
if (Date.now() - lastEmit < 20_000)
|
|
371
|
+
if (settled || Date.now() - lastEmit < 20_000)
|
|
339
372
|
return;
|
|
340
373
|
lastEmit = Date.now();
|
|
341
374
|
lastShown = heartbeatLabel;
|
|
@@ -343,16 +376,17 @@ export function attachAgentLog(child, logPath, onLogLine, control = {}) {
|
|
|
343
376
|
}, 5_000)
|
|
344
377
|
: undefined;
|
|
345
378
|
heartbeat?.unref?.();
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
lastShown
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
379
|
+
deadline =
|
|
380
|
+
maxMs > 0
|
|
381
|
+
? setTimeout(() => {
|
|
382
|
+
requestImplementStop(child, stop, IMPLEMENT_TIME_CAP);
|
|
383
|
+
if (IMPLEMENT_TIME_CAP !== lastShown) {
|
|
384
|
+
lastShown = IMPLEMENT_TIME_CAP;
|
|
385
|
+
lastEmit = Date.now();
|
|
386
|
+
onLogLine?.(IMPLEMENT_TIME_CAP);
|
|
387
|
+
}
|
|
388
|
+
}, maxMs)
|
|
389
|
+
: undefined;
|
|
356
390
|
deadline?.unref?.();
|
|
357
391
|
child.stdout?.on("data", (chunk) => {
|
|
358
392
|
stream.write(chunk);
|
|
@@ -363,14 +397,17 @@ export function attachAgentLog(child, logPath, onLogLine, control = {}) {
|
|
|
363
397
|
feed(chunk);
|
|
364
398
|
});
|
|
365
399
|
return new Promise((resolve) => {
|
|
400
|
+
settle = resolve;
|
|
366
401
|
child.once("close", (code) => {
|
|
402
|
+
if (hangKill)
|
|
403
|
+
clearTimeout(hangKill);
|
|
367
404
|
if (heartbeat)
|
|
368
405
|
clearInterval(heartbeat);
|
|
369
406
|
if (deadline)
|
|
370
407
|
clearTimeout(deadline);
|
|
371
408
|
feed("\n");
|
|
372
409
|
stream.end();
|
|
373
|
-
|
|
410
|
+
finish(code);
|
|
374
411
|
});
|
|
375
412
|
});
|
|
376
413
|
}
|
|
@@ -421,6 +458,20 @@ export function isSandboxOnceStart(line) {
|
|
|
421
458
|
return false;
|
|
422
459
|
}
|
|
423
460
|
}
|
|
461
|
+
export function agentStreamOutcome(line) {
|
|
462
|
+
const text = line.trim();
|
|
463
|
+
if (!text.startsWith("{"))
|
|
464
|
+
return null;
|
|
465
|
+
try {
|
|
466
|
+
const event = JSON.parse(text);
|
|
467
|
+
if (event.type !== "result")
|
|
468
|
+
return null;
|
|
469
|
+
return event.is_error === true || event.subtype === "error" ? "error" : "success";
|
|
470
|
+
}
|
|
471
|
+
catch {
|
|
472
|
+
return null;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
424
475
|
export function summarizeAgentLine(line) {
|
|
425
476
|
const text = line.trim();
|
|
426
477
|
if (!text)
|
|
@@ -573,7 +624,7 @@ function makeLineFeeder(onLine) {
|
|
|
573
624
|
for (const line of lines) {
|
|
574
625
|
const text = line.trim();
|
|
575
626
|
if (text)
|
|
576
|
-
onLine(text.slice(0,
|
|
627
|
+
onLine(text.length > AGENT_LOG_LINE_MAX ? text.slice(0, AGENT_LOG_LINE_MAX) : text);
|
|
577
628
|
}
|
|
578
629
|
};
|
|
579
630
|
}
|
|
@@ -590,7 +641,7 @@ async function waitForAgent(child, settleMs, logPath, bin, agentName = "Cursor")
|
|
|
590
641
|
if (settleMs > 0) {
|
|
591
642
|
await new Promise((resolve) => setTimeout(resolve, settleMs));
|
|
592
643
|
}
|
|
593
|
-
if (!child || child.exitCode === null || child.exitCode === undefined) {
|
|
644
|
+
if (!child || child.exitCode === null || child.exitCode === undefined || child.exitCode === 0) {
|
|
594
645
|
return { ok: true, message: "started" };
|
|
595
646
|
}
|
|
596
647
|
const tail = tailLog(logPath);
|
package/dist/improve.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { NOUL_PASS } from "./gates.js";
|
|
2
|
+
import { questionsBriefSection } from "./agent-questions.js";
|
|
2
3
|
export class ImproveLockedError extends Error {
|
|
3
4
|
code = "improve_gate";
|
|
4
5
|
constructor(message = "Improve it is only when Ready is blocked or pack noul is below 0.75.") {
|
|
@@ -52,7 +53,7 @@ export function emitImproveBrief(input) {
|
|
|
52
53
|
`# Improve: ${input.spec?.requirementId ?? "requirement"}`,
|
|
53
54
|
"",
|
|
54
55
|
"Opinionated writer pass. Patch the pack so a coding agent can implement without guessing.",
|
|
55
|
-
"
|
|
56
|
+
"If a required decision is missing, write derived/agent-questions.json and stop. Do not guess. Do not patch requirement.md in that same turn.",
|
|
56
57
|
"",
|
|
57
58
|
"## Goal",
|
|
58
59
|
"",
|
|
@@ -87,8 +88,8 @@ export function emitImproveBrief(input) {
|
|
|
87
88
|
lines.push("");
|
|
88
89
|
}
|
|
89
90
|
lines.push("## Opinionated rules", "", "- Rewrite every Outcome to what a person sees after the steps: a status or label, and whether a named control is present, absent, or disabled.", "- Tighten every rule Observable so a person or test can notice it.", "- `Choose …` is an allow path. `Look for …` is a deny path. Do not invert a use case to match a matrix cell.", "- A matrix allow cell plus a business rule that hides or disables the control is consistent. Keep those Look-for use cases.", "- Do not write matrix talk in Outcome or Entities: no `is allow`, `is deny`, no restating action cells, no `without changing the matrix cell`.", "- Name the exact Choose / Look for / Select controls. State tester preconditions.", personas
|
|
90
|
-
? "- Missing persona: add `email: <role-slug>@example.test` and `password: test-only-not-production` in fixtures/personas.yaml."
|
|
91
|
-
: "- Do not add personas unless a finding is persona_missing.", "- You may edit every section the findings name. This is one pack pass.", "", "## Fence", "", "- Patch `requirement.md` only, then stop.", personas
|
|
91
|
+
? "- Missing persona: prefer asking whether the owner has a real test user. If they do not, add `email: <role-slug>@example.test` and `password: test-only-not-production` in fixtures/personas.yaml."
|
|
92
|
+
: "- Do not add personas unless a finding is persona_missing.", "- You may edit every section the findings name. This is one pack pass.", "", questionsBriefSection().trimEnd(), "", "## Fence", "", "- Patch `requirement.md` only, then stop.", personas
|
|
92
93
|
? "- At least one finding is a missing persona: you may also edit `fixtures/personas.yaml`."
|
|
93
94
|
: "- Do not add files except the patch to `requirement.md`.", "- Do not invent spec IDs.", "- Do not implement the product app.", "- Stop after the patch so the owner can review the diff, then Check with Jev. Do not Check yourself.", "");
|
|
94
95
|
return `${lines.join("\n")}\n`;
|
package/dist/pack.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { type JevClient } from "./jev.js";
|
|
|
3
3
|
import { type PersonasResult } from "./personas.js";
|
|
4
4
|
import { type ProofDriver } from "./proof.js";
|
|
5
5
|
import { type RuntimeResult } from "./runtime.js";
|
|
6
|
+
import { AuthorLockedError, readAuthorRun, type AuthorRun, type AuthorStep } from "./author.js";
|
|
6
7
|
import type { AdapterId, CompileResult, PackListItem, ProgressFn } from "./types.js";
|
|
7
8
|
export declare const REQUIREMENT_FILE = "requirement.md";
|
|
8
9
|
export declare const PERSONAS_FILE: string;
|
|
@@ -29,8 +30,13 @@ export type PackPaths = {
|
|
|
29
30
|
proofRun: string;
|
|
30
31
|
proofReport: string;
|
|
31
32
|
proveLog: string;
|
|
33
|
+
agentQuestions: string;
|
|
34
|
+
context: string;
|
|
35
|
+
authorBrief: string;
|
|
36
|
+
authorRun: string;
|
|
32
37
|
};
|
|
33
38
|
export declare function packPaths(root: string): PackPaths;
|
|
39
|
+
export declare function withRememberedAnswers(paths: PackPaths, prompt: string): Promise<string>;
|
|
34
40
|
export declare function isPackDir(dir: string): Promise<boolean>;
|
|
35
41
|
export declare function resolveCockpitPack(cwd: string): Promise<PackPaths | null>;
|
|
36
42
|
export declare function resolvePack(cwd: string): Promise<PackPaths | null>;
|
|
@@ -41,6 +47,8 @@ export declare function readMarkdown(paths: PackPaths): Promise<string>;
|
|
|
41
47
|
export declare function loadPersonas(paths: PackPaths): Promise<PersonasResult>;
|
|
42
48
|
export declare function compilePack(paths: PackPaths): Promise<CompileResult>;
|
|
43
49
|
export declare function checkPack(paths: PackPaths, client?: JevClient): Promise<CompileResult>;
|
|
50
|
+
export declare function isPackWatchInput(filename: string): boolean;
|
|
51
|
+
export declare function shouldRefreshForWatch(watchPath: string, filename?: string | Buffer | null): boolean;
|
|
44
52
|
export declare function persistDerived(paths: PackPaths, result: CompileResult): Promise<void>;
|
|
45
53
|
export declare function createPack(root: string): Promise<PackPaths>;
|
|
46
54
|
export declare function deletePack(paths: PackPaths): Promise<void>;
|
|
@@ -50,6 +58,8 @@ export declare function implementPack(paths: PackPaths, options?: {
|
|
|
50
58
|
stack?: string;
|
|
51
59
|
fromProof?: boolean;
|
|
52
60
|
onLogLine?: (line: string) => void;
|
|
61
|
+
extraPrompt?: string;
|
|
62
|
+
resume?: boolean;
|
|
53
63
|
}): Promise<{
|
|
54
64
|
result: CompileResult;
|
|
55
65
|
message: string;
|
|
@@ -63,7 +73,7 @@ export declare class StopImplementLockedError extends Error {
|
|
|
63
73
|
readonly code = "stop_implement_gate";
|
|
64
74
|
constructor(message?: string);
|
|
65
75
|
}
|
|
66
|
-
export declare function stopImplement(paths: PackPaths, launch: LaunchAdapterResult, reason?: string): Promise<{
|
|
76
|
+
export declare function stopImplement(paths: PackPaths, launch: LaunchAdapterResult | null, reason?: string): Promise<{
|
|
67
77
|
result: CompileResult;
|
|
68
78
|
message: string;
|
|
69
79
|
}>;
|
|
@@ -77,9 +87,60 @@ export declare function writeImproveBrief(paths: PackPaths, compiled?: CompileRe
|
|
|
77
87
|
}>;
|
|
78
88
|
export declare function launchImprove(paths: PackPaths, options?: {
|
|
79
89
|
adapter?: AdapterId;
|
|
90
|
+
extraPrompt?: string;
|
|
91
|
+
}): Promise<LaunchAdapterResult>;
|
|
92
|
+
export declare function writeAuthorBrief(paths: PackPaths, compiled: CompileResult, run: AuthorRun): Promise<string>;
|
|
93
|
+
export declare function launchAuthor(paths: PackPaths, options?: {
|
|
94
|
+
adapter?: AdapterId;
|
|
95
|
+
extraPrompt?: string;
|
|
96
|
+
onLogLine?: (line: string) => void;
|
|
97
|
+
}): Promise<LaunchAdapterResult>;
|
|
98
|
+
export declare function startAuthor(paths: PackPaths, description: string, options?: {
|
|
99
|
+
adapter?: AdapterId;
|
|
100
|
+
onLogLine?: (line: string) => void;
|
|
80
101
|
}): Promise<{
|
|
81
|
-
|
|
102
|
+
result: CompileResult;
|
|
103
|
+
run: AuthorRun;
|
|
104
|
+
message: string;
|
|
105
|
+
launch?: LaunchAdapterResult;
|
|
106
|
+
}>;
|
|
107
|
+
export declare function resumeAuthor(paths: PackPaths, options?: {
|
|
108
|
+
adapter?: AdapterId;
|
|
109
|
+
extraPrompt?: string;
|
|
110
|
+
onLogLine?: (line: string) => void;
|
|
111
|
+
}): Promise<{
|
|
112
|
+
result: CompileResult;
|
|
113
|
+
run: AuthorRun;
|
|
114
|
+
message: string;
|
|
115
|
+
launch?: LaunchAdapterResult;
|
|
116
|
+
}>;
|
|
117
|
+
export declare function settleAuthor(paths: PackPaths, launch: LaunchAdapterResult): Promise<{
|
|
118
|
+
action: AuthorStep["action"];
|
|
119
|
+
run: AuthorRun;
|
|
120
|
+
result: CompileResult;
|
|
121
|
+
message: string;
|
|
122
|
+
}>;
|
|
123
|
+
export declare function stopAuthor(paths: PackPaths, launch: LaunchAdapterResult | null, reason?: string): Promise<{
|
|
124
|
+
result: CompileResult;
|
|
125
|
+
message: string;
|
|
126
|
+
run: AuthorRun | null;
|
|
127
|
+
}>;
|
|
128
|
+
export declare function saveAuthorArtifact(paths: PackPaths, filename: string, mime: string, data: string): Promise<string>;
|
|
129
|
+
export { readAuthorRun, AuthorLockedError };
|
|
130
|
+
export declare function answerAgentQuestions(paths: PackPaths, answers: Record<string, string>, options?: {
|
|
131
|
+
adapter?: AdapterId;
|
|
132
|
+
onLogLine?: (line: string) => void;
|
|
133
|
+
skipAll?: boolean;
|
|
134
|
+
}): Promise<{
|
|
135
|
+
result: CompileResult;
|
|
136
|
+
message: string;
|
|
137
|
+
channel: "author" | "improve" | "implement";
|
|
138
|
+
launch?: LaunchAdapterResult;
|
|
139
|
+
}>;
|
|
140
|
+
export declare function discardAgentQuestions(paths: PackPaths, launch: LaunchAdapterResult | null): Promise<{
|
|
141
|
+
result: CompileResult;
|
|
82
142
|
message: string;
|
|
143
|
+
channel: "author" | "improve" | "implement";
|
|
83
144
|
}>;
|
|
84
145
|
export declare function improvePack(paths: PackPaths, options?: {
|
|
85
146
|
adapter?: AdapterId;
|