@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/pack.js
CHANGED
|
@@ -7,7 +7,7 @@ import { assertImplementAllowed, ImplementDisabledError, fixFromProofPrompt, imp
|
|
|
7
7
|
import { assertFixFromProofAllowed, emitFixFromProofBrief, FixFromProofLockedError } from "./fix-from-proof.js";
|
|
8
8
|
import { assertImproveAllowed, emitImproveBrief, improveFindings } from "./improve.js";
|
|
9
9
|
import { clearImproveLog, readImproveLog, recordImprovePending } from "./improve-log.js";
|
|
10
|
-
import { beginImproveReview, ImproveReviewPendingError, readImproveSnapshot } from "./improve-review.js";
|
|
10
|
+
import { beginImproveReview, ImproveReviewPendingError, readImproveSnapshot, rejectImproveReview } from "./improve-review.js";
|
|
11
11
|
import { emitImplementBrief } from "./implement-brief.js";
|
|
12
12
|
import { hasJevAccess, JevRequestError, JevUnavailableError, resolveJevClient } from "./jev.js";
|
|
13
13
|
import { emitJevPack } from "./jev-pack.js";
|
|
@@ -20,6 +20,8 @@ import { ignoreBuildAllowed, packListMeters } from "./stages.js";
|
|
|
20
20
|
import { parseRuntimeYaml } from "./runtime.js";
|
|
21
21
|
import { inspectProductRepo, needsStackChoice, resolveStackId, StackRequiredError, UnknownStackError, writeAmplifyEnvExampleIfMissing, writeReq0Config, } from "./stack.js";
|
|
22
22
|
import { loadStarterRequirement, PERSONAS_STUB, RUNTIME_STUB } from "./template.js";
|
|
23
|
+
import { authorPrompt, authorQualityTarget, AuthorLockedError, AUTHOR_AGENT_LOG, AUTHOR_BRIEF_FILE, AUTHOR_RUN_FILE, AUTHOR_STOPPED, emitAuthorBrief, isAuthorActive, listContextFiles, listProductLayout, nextAuthorStep, productBriefBits, readAuthorRun, seedAuthorMarkdown, summarizeRequirementMarkdown, writeAuthorArtifact, writeAuthorRun, } from "./author.js";
|
|
24
|
+
import { AGENT_QUESTIONS_WAITING, AgentAnswersError, applyAnswers, clearAgentQuestions, isOpenQuestions, readAgentQuestions, withOwnerAnswers, writeAgentQuestions, } from "./agent-questions.js";
|
|
23
25
|
export const REQUIREMENT_FILE = "requirement.md";
|
|
24
26
|
export const PERSONAS_FILE = path.join("fixtures", "personas.yaml");
|
|
25
27
|
export const RUNTIME_FILE = path.join("fixtures", "runtime.yaml");
|
|
@@ -48,8 +50,18 @@ export function packPaths(root) {
|
|
|
48
50
|
proofRun: path.join(derived, "proof-run.json"),
|
|
49
51
|
proofReport: path.join(derived, "proof-report.md"),
|
|
50
52
|
proveLog: path.join(derived, "prove-run.log"),
|
|
53
|
+
agentQuestions: path.join(derived, "agent-questions.json"),
|
|
54
|
+
context: path.join(root, "context"),
|
|
55
|
+
authorBrief: path.join(derived, AUTHOR_BRIEF_FILE),
|
|
56
|
+
authorRun: path.join(derived, AUTHOR_RUN_FILE),
|
|
51
57
|
};
|
|
52
58
|
}
|
|
59
|
+
export async function withRememberedAnswers(paths, prompt) {
|
|
60
|
+
const round = await readAgentQuestions(paths);
|
|
61
|
+
if (!round || round.status !== "answered" || round.channel !== "implement")
|
|
62
|
+
return prompt;
|
|
63
|
+
return withOwnerAnswers(prompt, round);
|
|
64
|
+
}
|
|
53
65
|
export async function isPackDir(dir) {
|
|
54
66
|
try {
|
|
55
67
|
await access(path.join(dir, REQUIREMENT_FILE));
|
|
@@ -201,6 +213,7 @@ export async function compilePack(paths) {
|
|
|
201
213
|
}
|
|
202
214
|
const buildRun = await readBuildRun(paths);
|
|
203
215
|
if (buildRun?.state === "running" &&
|
|
216
|
+
!buildRun.waitingOnQuestions &&
|
|
204
217
|
!isFollowedImplement(buildRun.pid) &&
|
|
205
218
|
implementProcessGone(buildRun.pid)) {
|
|
206
219
|
await writeBuildRun(paths, {
|
|
@@ -273,22 +286,48 @@ export async function checkPack(paths, client) {
|
|
|
273
286
|
throw new JevRequestError(err instanceof Error ? err.message : "Jev request failed.");
|
|
274
287
|
}
|
|
275
288
|
}
|
|
289
|
+
export function isPackWatchInput(filename) {
|
|
290
|
+
const relative = filename.replaceAll("\\", "/").replace(/^\.\//, "");
|
|
291
|
+
if (!relative || relative.split("/").includes("derived"))
|
|
292
|
+
return false;
|
|
293
|
+
const base = path.posix.basename(relative);
|
|
294
|
+
if (relative.split("/").includes("context")) {
|
|
295
|
+
return /\.(png|jpe?g|webp)$/i.test(base);
|
|
296
|
+
}
|
|
297
|
+
return base === REQUIREMENT_FILE || base === path.posix.basename(PERSONAS_FILE) || base === path.posix.basename(RUNTIME_FILE);
|
|
298
|
+
}
|
|
299
|
+
export function shouldRefreshForWatch(watchPath, filename) {
|
|
300
|
+
const relative = typeof filename === "string" ? filename : Buffer.isBuffer(filename) ? filename.toString("utf8") : "";
|
|
301
|
+
if (relative.trim())
|
|
302
|
+
return isPackWatchInput(relative);
|
|
303
|
+
return isPackWatchInput(path.basename(watchPath));
|
|
304
|
+
}
|
|
276
305
|
export async function persistDerived(paths, result) {
|
|
277
306
|
await mkdir(paths.derived, { recursive: true });
|
|
278
307
|
if (result.spec) {
|
|
279
|
-
await
|
|
308
|
+
await writeIfChanged(paths.spec, `${JSON.stringify(result.spec, null, 2)}\n`);
|
|
280
309
|
}
|
|
281
310
|
if (result.jevPack) {
|
|
282
|
-
await
|
|
311
|
+
await writeIfChanged(paths.jevPack, `${JSON.stringify(result.jevPack, null, 2)}\n`);
|
|
283
312
|
}
|
|
284
313
|
if (result.implementBrief) {
|
|
285
|
-
await
|
|
314
|
+
await writeIfChanged(paths.implementBrief, result.implementBrief);
|
|
286
315
|
}
|
|
287
316
|
if (result.qaPlan) {
|
|
288
|
-
await
|
|
317
|
+
await writeIfChanged(paths.qaPlan, emitQaPlanYaml(result.qaPlan));
|
|
318
|
+
}
|
|
319
|
+
await writeIfChanged(paths.health, `${JSON.stringify(result.health, null, 2)}\n`);
|
|
320
|
+
await writeIfChanged(paths.status, healthToStatusMarkdown(result.health));
|
|
321
|
+
}
|
|
322
|
+
async function writeIfChanged(file, contents) {
|
|
323
|
+
try {
|
|
324
|
+
if ((await readFile(file, "utf8")) === contents)
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
catch {
|
|
328
|
+
// missing
|
|
289
329
|
}
|
|
290
|
-
await writeFile(
|
|
291
|
-
await writeFile(paths.status, healthToStatusMarkdown(result.health), "utf8");
|
|
330
|
+
await writeFile(file, contents, "utf8");
|
|
292
331
|
}
|
|
293
332
|
async function readJevRun(paths, spec) {
|
|
294
333
|
try {
|
|
@@ -344,7 +383,7 @@ export async function writeRuntimeStubIfMissing(paths) {
|
|
|
344
383
|
async function readBuildRun(paths) {
|
|
345
384
|
try {
|
|
346
385
|
const raw = JSON.parse(await readFile(paths.buildRun, "utf8"));
|
|
347
|
-
if (
|
|
386
|
+
if (typeof raw.specHash !== "string" || !raw.state)
|
|
348
387
|
return null;
|
|
349
388
|
return raw;
|
|
350
389
|
}
|
|
@@ -354,8 +393,11 @@ async function readBuildRun(paths) {
|
|
|
354
393
|
}
|
|
355
394
|
export async function implementPack(paths, options = {}) {
|
|
356
395
|
const compiled = await compilePack(paths);
|
|
396
|
+
if (!options.resume && isOpenQuestions(await readAgentQuestions(paths))) {
|
|
397
|
+
throw new AgentAnswersError("Answer the agent's questions, or Stop, before starting a new Implement.");
|
|
398
|
+
}
|
|
357
399
|
assertImplementAllowed(compiled);
|
|
358
|
-
if (options.fromProof) {
|
|
400
|
+
if (options.fromProof && !options.resume) {
|
|
359
401
|
assertFixFromProofAllowed(compiled.health, compiled.health.ready);
|
|
360
402
|
if (!compiled.spec)
|
|
361
403
|
throw new FixFromProofLockedError();
|
|
@@ -390,6 +432,9 @@ export async function implementPack(paths, options = {}) {
|
|
|
390
432
|
briefPath = paths.fixFromProofBrief;
|
|
391
433
|
prompt = fixFromProofPrompt(paths.fixFromProofBrief, paths.proofReport, paths.implementBrief);
|
|
392
434
|
}
|
|
435
|
+
prompt = await withRememberedAnswers(paths, prompt);
|
|
436
|
+
if (options.extraPrompt)
|
|
437
|
+
prompt = `${prompt}\n\n${options.extraPrompt}`;
|
|
393
438
|
const launch = await launchAdapter(adapter, repo.root, briefPath, {
|
|
394
439
|
onLogLine: options.onLogLine,
|
|
395
440
|
prompt,
|
|
@@ -404,6 +449,7 @@ export async function implementPack(paths, options = {}) {
|
|
|
404
449
|
at: new Date().toISOString(),
|
|
405
450
|
message: launch.message,
|
|
406
451
|
...(following && launch.child?.pid ? { pid: launch.child.pid } : {}),
|
|
452
|
+
...(options.fromProof ? { fromProof: true } : {}),
|
|
407
453
|
});
|
|
408
454
|
return { result: await compilePack(paths), message: launch.message, launch };
|
|
409
455
|
}
|
|
@@ -411,7 +457,21 @@ export async function finishImplement(paths, launch, adapter) {
|
|
|
411
457
|
const done = launch.finished ? await launch.finished : { code: launch.ok ? 0 : 1 };
|
|
412
458
|
unfollowImplementPid(launch.child?.pid);
|
|
413
459
|
const compiled = await compilePack(paths);
|
|
460
|
+
const previous = await readBuildRun(paths);
|
|
414
461
|
const stopped = launch.stop?.reason;
|
|
462
|
+
const waiting = !stopped && isOpenQuestions(await readAgentQuestions(paths));
|
|
463
|
+
if (waiting) {
|
|
464
|
+
await writeBuildRun(paths, {
|
|
465
|
+
specHash: compiled.spec ? specHash(compiled.spec) : previous?.specHash ?? "",
|
|
466
|
+
state: "running",
|
|
467
|
+
adapter,
|
|
468
|
+
at: new Date().toISOString(),
|
|
469
|
+
message: AGENT_QUESTIONS_WAITING,
|
|
470
|
+
waitingOnQuestions: true,
|
|
471
|
+
...(previous?.fromProof ? { fromProof: true } : {}),
|
|
472
|
+
});
|
|
473
|
+
return { result: await compilePack(paths), message: AGENT_QUESTIONS_WAITING };
|
|
474
|
+
}
|
|
415
475
|
const ok = !stopped && launch.ok && done.code === 0;
|
|
416
476
|
const name = adapterDisplayName(adapter);
|
|
417
477
|
const message = stopped
|
|
@@ -425,6 +485,7 @@ export async function finishImplement(paths, launch, adapter) {
|
|
|
425
485
|
adapter,
|
|
426
486
|
at: new Date().toISOString(),
|
|
427
487
|
message,
|
|
488
|
+
...(previous?.fromProof ? { fromProof: true } : {}),
|
|
428
489
|
});
|
|
429
490
|
return { result: await compilePack(paths), message };
|
|
430
491
|
}
|
|
@@ -436,11 +497,15 @@ export class StopImplementLockedError extends Error {
|
|
|
436
497
|
}
|
|
437
498
|
}
|
|
438
499
|
export async function stopImplement(paths, launch, reason = IMPLEMENT_STOPPED) {
|
|
439
|
-
|
|
500
|
+
const waiting = isOpenQuestions(await readAgentQuestions(paths));
|
|
501
|
+
if (!waiting && !launch?.child && !launch?.finished) {
|
|
440
502
|
throw new StopImplementLockedError();
|
|
441
503
|
}
|
|
442
|
-
|
|
443
|
-
|
|
504
|
+
if (launch?.child || launch?.finished) {
|
|
505
|
+
const stop = launch.stop ?? (launch.stop = {});
|
|
506
|
+
requestImplementStop(launch.child, stop, reason);
|
|
507
|
+
}
|
|
508
|
+
await clearAgentQuestions(paths);
|
|
444
509
|
const compiled = await compilePack(paths);
|
|
445
510
|
const previous = await readBuildRun(paths);
|
|
446
511
|
await writeBuildRun(paths, {
|
|
@@ -449,6 +514,7 @@ export async function stopImplement(paths, launch, reason = IMPLEMENT_STOPPED) {
|
|
|
449
514
|
adapter: previous?.adapter ?? "cursor",
|
|
450
515
|
at: new Date().toISOString(),
|
|
451
516
|
message: reason,
|
|
517
|
+
...(previous?.fromProof ? { fromProof: true } : {}),
|
|
452
518
|
});
|
|
453
519
|
return { result: await compilePack(paths), message: reason };
|
|
454
520
|
}
|
|
@@ -494,6 +560,9 @@ function tailImplementLog(paths) {
|
|
|
494
560
|
}
|
|
495
561
|
}
|
|
496
562
|
export async function writeImproveBrief(paths, compiled) {
|
|
563
|
+
if (isOpenQuestions(await readAgentQuestions(paths))) {
|
|
564
|
+
throw new AgentAnswersError("Answer the agent's questions, or Stop, before starting a new Improve.");
|
|
565
|
+
}
|
|
497
566
|
const result = compiled ?? (await compilePack(paths));
|
|
498
567
|
assertImproveAllowed(result.health.ready);
|
|
499
568
|
const findings = improveFindings(result.health.ready);
|
|
@@ -513,14 +582,262 @@ export async function launchImprove(paths, options = {}) {
|
|
|
513
582
|
const repo = await inspectProductRepo(paths.root);
|
|
514
583
|
const adapter = options.adapter ?? (repo.adapterRecorded && adapterLaunchesAgent(repo.adapter) ? repo.adapter : "manual");
|
|
515
584
|
const name = adapterDisplayName(adapter);
|
|
585
|
+
const prompt = options.extraPrompt
|
|
586
|
+
? `${improvePrompt(paths.improveBrief)}\n\n${options.extraPrompt}`
|
|
587
|
+
: improvePrompt(paths.improveBrief);
|
|
516
588
|
return launchAdapter(adapter, repo.root, paths.improveBrief, {
|
|
517
|
-
prompt
|
|
589
|
+
prompt,
|
|
518
590
|
openIde: false,
|
|
519
591
|
successMessage: adapter === "manual"
|
|
520
592
|
? "Wrote derived/improve-brief.md. Open it in any coding agent."
|
|
521
593
|
: `Started a ${name} agent. The cockpit will show a diff when the spec changes.`,
|
|
522
594
|
});
|
|
523
595
|
}
|
|
596
|
+
export async function writeAuthorBrief(paths, compiled, run) {
|
|
597
|
+
const repo = await inspectProductRepo(paths.root);
|
|
598
|
+
const brief = emitAuthorBrief({
|
|
599
|
+
id: paths.id,
|
|
600
|
+
description: run.description,
|
|
601
|
+
qualityTarget: run.qualityTarget,
|
|
602
|
+
round: run.round,
|
|
603
|
+
markdown: compiled.markdown,
|
|
604
|
+
compileFindings: compiled.health.spec.findings,
|
|
605
|
+
spec: compiled.spec,
|
|
606
|
+
ready: compiled.spec && compiled.health.spec.state === "valid" ? compiled.health.ready : null,
|
|
607
|
+
siblings: await siblingSummaries(paths),
|
|
608
|
+
product: productBriefBits(repo, await listProductLayout(repo.root)),
|
|
609
|
+
contextFiles: await listContextFiles(paths),
|
|
610
|
+
});
|
|
611
|
+
await mkdir(paths.derived, { recursive: true });
|
|
612
|
+
await writeFile(paths.authorBrief, brief, "utf8");
|
|
613
|
+
return brief;
|
|
614
|
+
}
|
|
615
|
+
export async function launchAuthor(paths, options = {}) {
|
|
616
|
+
const repo = await inspectProductRepo(paths.root);
|
|
617
|
+
const adapter = options.adapter ?? (repo.adapterRecorded && adapterLaunchesAgent(repo.adapter) ? repo.adapter : "manual");
|
|
618
|
+
const name = adapterDisplayName(adapter);
|
|
619
|
+
const prompt = options.extraPrompt
|
|
620
|
+
? `${authorPrompt(paths.authorBrief)}\n\n${options.extraPrompt}`
|
|
621
|
+
: authorPrompt(paths.authorBrief);
|
|
622
|
+
return launchAdapter(adapter, repo.root, paths.authorBrief, {
|
|
623
|
+
prompt,
|
|
624
|
+
openIde: false,
|
|
625
|
+
logFile: AUTHOR_AGENT_LOG,
|
|
626
|
+
heartbeatLabel: "Authoring",
|
|
627
|
+
onLogLine: options.onLogLine,
|
|
628
|
+
successMessage: adapter === "manual"
|
|
629
|
+
? "Wrote derived/author-brief.md. Open it in any coding agent."
|
|
630
|
+
: `Started a ${name} agent to draft requirement.md.`,
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
export async function startAuthor(paths, description, options = {}) {
|
|
634
|
+
const trimmed = description.trim();
|
|
635
|
+
if (!trimmed)
|
|
636
|
+
throw new AuthorLockedError("Describe the requirement first.");
|
|
637
|
+
if (isAuthorActive(await readAuthorRun(paths))) {
|
|
638
|
+
throw new AuthorLockedError();
|
|
639
|
+
}
|
|
640
|
+
const open = await readAgentQuestions(paths);
|
|
641
|
+
if (isOpenQuestions(open) && open.channel !== "author") {
|
|
642
|
+
throw new AgentAnswersError("Answer the agent's questions, or Stop, before authoring.");
|
|
643
|
+
}
|
|
644
|
+
await writeFile(paths.requirement, seedAuthorMarkdown(paths.id, trimmed, await readMarkdown(paths)), "utf8");
|
|
645
|
+
const compiled = await compilePack(paths);
|
|
646
|
+
const run = {
|
|
647
|
+
version: 1,
|
|
648
|
+
status: "running",
|
|
649
|
+
qualityTarget: authorQualityTarget(hasJevAccess()),
|
|
650
|
+
description: trimmed,
|
|
651
|
+
round: 1,
|
|
652
|
+
at: new Date().toISOString(),
|
|
653
|
+
message: "Authoring this requirement.",
|
|
654
|
+
};
|
|
655
|
+
await writeAuthorRun(paths, run);
|
|
656
|
+
await writeAuthorBrief(paths, compiled, run);
|
|
657
|
+
const launch = await launchAuthor(paths, { adapter: options.adapter, onLogLine: options.onLogLine });
|
|
658
|
+
if (!launch.ok || !launch.finished) {
|
|
659
|
+
const next = {
|
|
660
|
+
...run,
|
|
661
|
+
status: launch.ok ? "stopped" : "stopped",
|
|
662
|
+
message: launch.message,
|
|
663
|
+
};
|
|
664
|
+
await writeAuthorRun(paths, next);
|
|
665
|
+
return { result: await compilePack(paths), run: next, message: launch.message, launch };
|
|
666
|
+
}
|
|
667
|
+
return { result: compiled, run, message: launch.message, launch };
|
|
668
|
+
}
|
|
669
|
+
export async function resumeAuthor(paths, options = {}) {
|
|
670
|
+
const current = await readAuthorRun(paths);
|
|
671
|
+
if (!current)
|
|
672
|
+
throw new AuthorLockedError("No authoring run to continue.");
|
|
673
|
+
const compiled = await compilePack(paths);
|
|
674
|
+
const run = {
|
|
675
|
+
...current,
|
|
676
|
+
status: "running",
|
|
677
|
+
at: new Date().toISOString(),
|
|
678
|
+
message: `Authoring round ${current.round}.`,
|
|
679
|
+
};
|
|
680
|
+
await writeAuthorRun(paths, run);
|
|
681
|
+
await writeAuthorBrief(paths, compiled, run);
|
|
682
|
+
const launch = await launchAuthor(paths, options);
|
|
683
|
+
if (!launch.ok || !launch.finished) {
|
|
684
|
+
const next = { ...run, status: "stopped", message: launch.message };
|
|
685
|
+
await writeAuthorRun(paths, next);
|
|
686
|
+
return { result: await compilePack(paths), run: next, message: launch.message, launch };
|
|
687
|
+
}
|
|
688
|
+
return { result: compiled, run, message: launch.message, launch };
|
|
689
|
+
}
|
|
690
|
+
export async function settleAuthor(paths, launch) {
|
|
691
|
+
if (launch.finished)
|
|
692
|
+
await launch.finished;
|
|
693
|
+
const compiled = await compilePack(paths);
|
|
694
|
+
const current = await readAuthorRun(paths);
|
|
695
|
+
if (!current) {
|
|
696
|
+
return {
|
|
697
|
+
action: "done",
|
|
698
|
+
run: {
|
|
699
|
+
version: 1,
|
|
700
|
+
status: "done",
|
|
701
|
+
qualityTarget: authorQualityTarget(hasJevAccess()),
|
|
702
|
+
description: "",
|
|
703
|
+
round: 1,
|
|
704
|
+
at: new Date().toISOString(),
|
|
705
|
+
message: "Authoring is done.",
|
|
706
|
+
},
|
|
707
|
+
result: compiled,
|
|
708
|
+
message: "Authoring is done.",
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
const questions = await readAgentQuestions(paths);
|
|
712
|
+
const openAuthor = isOpenQuestions(questions) && questions.channel === "author";
|
|
713
|
+
let step = nextAuthorStep({
|
|
714
|
+
run: current,
|
|
715
|
+
specState: compiled.health.spec.state,
|
|
716
|
+
readyState: compiled.health.ready.state,
|
|
717
|
+
jevCurrent: compiled.health.ready.jevCurrent === true,
|
|
718
|
+
openQuestions: openAuthor,
|
|
719
|
+
hasApiKey: hasJevAccess(),
|
|
720
|
+
});
|
|
721
|
+
let result = compiled;
|
|
722
|
+
if (step.action === "check") {
|
|
723
|
+
await writeAuthorRun(paths, step.run);
|
|
724
|
+
try {
|
|
725
|
+
result = await checkPack(paths);
|
|
726
|
+
}
|
|
727
|
+
catch {
|
|
728
|
+
result = await compilePack(paths);
|
|
729
|
+
}
|
|
730
|
+
step = nextAuthorStep({
|
|
731
|
+
run: step.run,
|
|
732
|
+
specState: result.health.spec.state,
|
|
733
|
+
readyState: result.health.ready.state,
|
|
734
|
+
jevCurrent: result.health.ready.jevCurrent === true,
|
|
735
|
+
openQuestions: false,
|
|
736
|
+
hasApiKey: hasJevAccess(),
|
|
737
|
+
justChecked: true,
|
|
738
|
+
});
|
|
739
|
+
}
|
|
740
|
+
await writeAuthorRun(paths, step.run);
|
|
741
|
+
if (step.action === "relaunch") {
|
|
742
|
+
result = await compilePack(paths);
|
|
743
|
+
await writeAuthorBrief(paths, result, step.run);
|
|
744
|
+
}
|
|
745
|
+
return { action: step.action, run: step.run, result, message: step.message };
|
|
746
|
+
}
|
|
747
|
+
export async function stopAuthor(paths, launch, reason = AUTHOR_STOPPED) {
|
|
748
|
+
if (launch?.child || launch?.finished) {
|
|
749
|
+
const stop = launch.stop ?? (launch.stop = {});
|
|
750
|
+
requestImplementStop(launch.child, stop, reason);
|
|
751
|
+
}
|
|
752
|
+
await clearAgentQuestions(paths);
|
|
753
|
+
const current = await readAuthorRun(paths);
|
|
754
|
+
const run = current
|
|
755
|
+
? { ...current, status: "stopped", at: new Date().toISOString(), message: reason }
|
|
756
|
+
: null;
|
|
757
|
+
if (run)
|
|
758
|
+
await writeAuthorRun(paths, run);
|
|
759
|
+
return { result: await compilePack(paths), message: reason, run };
|
|
760
|
+
}
|
|
761
|
+
export async function saveAuthorArtifact(paths, filename, mime, data) {
|
|
762
|
+
return writeAuthorArtifact(paths, filename, mime, data);
|
|
763
|
+
}
|
|
764
|
+
async function siblingSummaries(paths) {
|
|
765
|
+
const dir = await findRequirementsDir(paths.root);
|
|
766
|
+
if (!dir)
|
|
767
|
+
return [];
|
|
768
|
+
const packs = await listPacks(dir);
|
|
769
|
+
const summaries = [];
|
|
770
|
+
for (const pack of packs) {
|
|
771
|
+
if (pack.id === paths.id)
|
|
772
|
+
continue;
|
|
773
|
+
summaries.push(summarizeRequirementMarkdown(pack.id, await readMarkdown(pack)));
|
|
774
|
+
}
|
|
775
|
+
return summaries;
|
|
776
|
+
}
|
|
777
|
+
export { readAuthorRun, AuthorLockedError };
|
|
778
|
+
export async function answerAgentQuestions(paths, answers, options = {}) {
|
|
779
|
+
const open = await readAgentQuestions(paths);
|
|
780
|
+
if (!isOpenQuestions(open)) {
|
|
781
|
+
throw new AgentAnswersError("No open questions to answer.");
|
|
782
|
+
}
|
|
783
|
+
const answered = applyAnswers(open, answers, { skipAll: options.skipAll === true });
|
|
784
|
+
await writeAgentQuestions(paths, answered);
|
|
785
|
+
const extraPrompt = withOwnerAnswers("", answered).trim();
|
|
786
|
+
if (answered.channel === "author") {
|
|
787
|
+
const launched = await resumeAuthor(paths, { adapter: options.adapter, extraPrompt, onLogLine: options.onLogLine });
|
|
788
|
+
return {
|
|
789
|
+
result: launched.result,
|
|
790
|
+
message: launched.message,
|
|
791
|
+
channel: "author",
|
|
792
|
+
launch: launched.launch,
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
if (answered.channel === "improve") {
|
|
796
|
+
const launch = await launchImprove(paths, { adapter: options.adapter, extraPrompt });
|
|
797
|
+
return {
|
|
798
|
+
result: await compilePack(paths),
|
|
799
|
+
message: launch.message,
|
|
800
|
+
channel: "improve",
|
|
801
|
+
launch: launch.ok && launch.finished ? launch : undefined,
|
|
802
|
+
};
|
|
803
|
+
}
|
|
804
|
+
const previous = await readBuildRun(paths);
|
|
805
|
+
const launched = await implementPack(paths, {
|
|
806
|
+
adapter: options.adapter ?? previous?.adapter,
|
|
807
|
+
fromProof: previous?.fromProof === true,
|
|
808
|
+
onLogLine: options.onLogLine,
|
|
809
|
+
resume: true,
|
|
810
|
+
});
|
|
811
|
+
return {
|
|
812
|
+
result: launched.result,
|
|
813
|
+
message: launched.message,
|
|
814
|
+
channel: "implement",
|
|
815
|
+
launch: launched.launch,
|
|
816
|
+
};
|
|
817
|
+
}
|
|
818
|
+
export async function discardAgentQuestions(paths, launch) {
|
|
819
|
+
const open = await readAgentQuestions(paths);
|
|
820
|
+
if (!isOpenQuestions(open)) {
|
|
821
|
+
throw new AgentAnswersError("No open questions to discard.");
|
|
822
|
+
}
|
|
823
|
+
if (open.channel === "implement") {
|
|
824
|
+
const stopped = await stopImplement(paths, launch);
|
|
825
|
+
return { result: stopped.result, message: stopped.message, channel: "implement" };
|
|
826
|
+
}
|
|
827
|
+
if (open.channel === "author") {
|
|
828
|
+
const stopped = await stopAuthor(paths, launch);
|
|
829
|
+
return { result: stopped.result, message: stopped.message, channel: "author" };
|
|
830
|
+
}
|
|
831
|
+
await clearAgentQuestions(paths);
|
|
832
|
+
if (await readImproveSnapshot(paths)) {
|
|
833
|
+
await rejectImproveReview(paths);
|
|
834
|
+
}
|
|
835
|
+
return {
|
|
836
|
+
result: await compilePack(paths),
|
|
837
|
+
message: "Discarded the agent's questions.",
|
|
838
|
+
channel: "improve",
|
|
839
|
+
};
|
|
840
|
+
}
|
|
524
841
|
export async function improvePack(paths, options = {}) {
|
|
525
842
|
const written = await writeImproveBrief(paths);
|
|
526
843
|
const launch = await launchImprove(paths, options);
|
package/dist/ready.js
CHANGED
|
@@ -29,6 +29,13 @@ export function evaluateBuild(spec, run) {
|
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
31
|
if (run.state === "running" && !isFollowedImplement(run.pid)) {
|
|
32
|
+
if (run.waitingOnQuestions) {
|
|
33
|
+
return {
|
|
34
|
+
state: "running",
|
|
35
|
+
adapter: run.adapter,
|
|
36
|
+
message: run.message,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
32
39
|
return {
|
|
33
40
|
state: "failed",
|
|
34
41
|
adapter: run.adapter,
|
package/dist/server.d.ts
CHANGED
|
@@ -8,8 +8,10 @@ export type AppState = {
|
|
|
8
8
|
last: CompileResult | null;
|
|
9
9
|
implementActivity: ActivityLine[];
|
|
10
10
|
proveActivity: ActivityLine[];
|
|
11
|
-
|
|
11
|
+
authorActivity: ActivityLine[];
|
|
12
|
+
busy: "prove" | "improve" | "implement" | "author" | null;
|
|
12
13
|
implementLaunch: LaunchAdapterResult | null;
|
|
14
|
+
authorLaunch: LaunchAdapterResult | null;
|
|
13
15
|
};
|
|
14
16
|
export declare function createAppState(cwd: string, pack: PackPaths | null): AppState;
|
|
15
17
|
export declare function refresh(state: AppState): Promise<CompileResult | null>;
|