@richjava/req0 0.3.0 → 0.5.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 +299 -29
- package/cockpit/index.html +18 -1
- package/cockpit/styles.css +37 -0
- package/dist/agent-questions.d.ts +15 -4
- package/dist/agent-questions.js +75 -26
- package/dist/author.d.ts +103 -0
- package/dist/author.js +435 -0
- package/dist/pack.d.ts +45 -2
- package/dist/pack.js +203 -1
- package/dist/server.d.ts +3 -1
- package/dist/server.js +173 -9
- package/dist/types.d.ts +3 -1
- package/package.json +1 -1
package/dist/pack.js
CHANGED
|
@@ -20,6 +20,7 @@ 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";
|
|
23
24
|
import { AGENT_QUESTIONS_WAITING, AgentAnswersError, applyAnswers, clearAgentQuestions, isOpenQuestions, readAgentQuestions, withOwnerAnswers, writeAgentQuestions, } from "./agent-questions.js";
|
|
24
25
|
export const REQUIREMENT_FILE = "requirement.md";
|
|
25
26
|
export const PERSONAS_FILE = path.join("fixtures", "personas.yaml");
|
|
@@ -50,6 +51,9 @@ export function packPaths(root) {
|
|
|
50
51
|
proofReport: path.join(derived, "proof-report.md"),
|
|
51
52
|
proveLog: path.join(derived, "prove-run.log"),
|
|
52
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),
|
|
53
57
|
};
|
|
54
58
|
}
|
|
55
59
|
export async function withRememberedAnswers(paths, prompt) {
|
|
@@ -287,6 +291,9 @@ export function isPackWatchInput(filename) {
|
|
|
287
291
|
if (!relative || relative.split("/").includes("derived"))
|
|
288
292
|
return false;
|
|
289
293
|
const base = path.posix.basename(relative);
|
|
294
|
+
if (relative.split("/").includes("context")) {
|
|
295
|
+
return /\.(png|jpe?g|webp)$/i.test(base);
|
|
296
|
+
}
|
|
290
297
|
return base === REQUIREMENT_FILE || base === path.posix.basename(PERSONAS_FILE) || base === path.posix.basename(RUNTIME_FILE);
|
|
291
298
|
}
|
|
292
299
|
export function shouldRefreshForWatch(watchPath, filename) {
|
|
@@ -586,14 +593,205 @@ export async function launchImprove(paths, options = {}) {
|
|
|
586
593
|
: `Started a ${name} agent. The cockpit will show a diff when the spec changes.`,
|
|
587
594
|
});
|
|
588
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 };
|
|
589
778
|
export async function answerAgentQuestions(paths, answers, options = {}) {
|
|
590
779
|
const open = await readAgentQuestions(paths);
|
|
591
780
|
if (!isOpenQuestions(open)) {
|
|
592
781
|
throw new AgentAnswersError("No open questions to answer.");
|
|
593
782
|
}
|
|
594
|
-
const answered = applyAnswers(open, answers);
|
|
783
|
+
const answered = applyAnswers(open, answers, { skipAll: options.skipAll === true });
|
|
595
784
|
await writeAgentQuestions(paths, answered);
|
|
596
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
|
+
}
|
|
597
795
|
if (answered.channel === "improve") {
|
|
598
796
|
const launch = await launchImprove(paths, { adapter: options.adapter, extraPrompt });
|
|
599
797
|
return {
|
|
@@ -626,6 +824,10 @@ export async function discardAgentQuestions(paths, launch) {
|
|
|
626
824
|
const stopped = await stopImplement(paths, launch);
|
|
627
825
|
return { result: stopped.result, message: stopped.message, channel: "implement" };
|
|
628
826
|
}
|
|
827
|
+
if (open.channel === "author") {
|
|
828
|
+
const stopped = await stopAuthor(paths, launch);
|
|
829
|
+
return { result: stopped.result, message: stopped.message, channel: "author" };
|
|
830
|
+
}
|
|
629
831
|
await clearAgentQuestions(paths);
|
|
630
832
|
if (await readImproveSnapshot(paths)) {
|
|
631
833
|
await rejectImproveReview(paths);
|
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>;
|
package/dist/server.js
CHANGED
|
@@ -3,9 +3,10 @@ import { readFile, stat } from "node:fs/promises";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import { hasJevAccess, JevRequestError, JevUnavailableError } from "./jev.js";
|
|
6
|
-
import { implementPack, finishImplement, ignoreBuild, launchImprove, stopImplement, StopImplementLockedError, writeImproveBrief, checkPack, compilePack, createPack, deletePack, findRequirementsDir, listPacks, provePack, summarizePacks, writeRequirement, answerAgentQuestions, discardAgentQuestions } from "./pack.js";
|
|
6
|
+
import { implementPack, finishImplement, ignoreBuild, launchImprove, stopImplement, StopImplementLockedError, writeImproveBrief, checkPack, compilePack, createPack, deletePack, findRequirementsDir, listPacks, provePack, summarizePacks, writeRequirement, answerAgentQuestions, discardAgentQuestions, startAuthor, settleAuthor, launchAuthor, stopAuthor, saveAuthorArtifact, readAuthorRun } from "./pack.js";
|
|
7
7
|
import { IgnoreBuildLockedError } from "./ready.js";
|
|
8
8
|
import { ImproveLockedError } from "./improve.js";
|
|
9
|
+
import { applyAuthorGate, AuthorArtifactError, AuthorLockedError } from "./author.js";
|
|
9
10
|
import { acceptImproveReview, applyImproveReviewGate, evaluateImproveReview, ImproveLintError, ImproveReviewPendingError, rejectImproveReview, } from "./improve-review.js";
|
|
10
11
|
import { inspectProductRepo, needsStackChoice, recordProjectSetup, recordStack, UnknownStackError } from "./stack.js";
|
|
11
12
|
import { adapterDisplayName, parseAdapterId } from "./adapter.js";
|
|
@@ -13,7 +14,17 @@ import { pipelineView, sectionCatalog } from "./stages.js";
|
|
|
13
14
|
import { AGENT_QUESTIONS_WAITING, AgentAnswersError, applyAgentQuestionsGate, isOpenQuestions, readAgentQuestions, } from "./agent-questions.js";
|
|
14
15
|
const cockpitDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../cockpit");
|
|
15
16
|
export function createAppState(cwd, pack) {
|
|
16
|
-
return {
|
|
17
|
+
return {
|
|
18
|
+
cwd,
|
|
19
|
+
pack,
|
|
20
|
+
last: null,
|
|
21
|
+
implementActivity: [],
|
|
22
|
+
proveActivity: [],
|
|
23
|
+
authorActivity: [],
|
|
24
|
+
busy: null,
|
|
25
|
+
implementLaunch: null,
|
|
26
|
+
authorLaunch: null,
|
|
27
|
+
};
|
|
17
28
|
}
|
|
18
29
|
export async function refresh(state) {
|
|
19
30
|
if (!state.pack) {
|
|
@@ -377,22 +388,29 @@ async function handle(state, req, res) {
|
|
|
377
388
|
for (const [id, value] of Object.entries(raw)) {
|
|
378
389
|
answers[id] = String(value ?? "");
|
|
379
390
|
}
|
|
391
|
+
const skipAll = body["skipAll"] === true;
|
|
380
392
|
const adapter = parseAdapterId(body["adapter"]) ?? "cursor";
|
|
381
393
|
try {
|
|
394
|
+
const round = await readAgentQuestions(state.pack);
|
|
395
|
+
const logChannel = round?.channel === "author" ? "author" : "implement";
|
|
382
396
|
const answered = await answerAgentQuestions(state.pack, answers, {
|
|
383
397
|
adapter,
|
|
384
|
-
|
|
398
|
+
skipAll,
|
|
399
|
+
onLogLine: (line) => pushActivity(state, line, "info", logChannel),
|
|
385
400
|
});
|
|
386
401
|
state.last = answered.result;
|
|
387
402
|
const summary = Object.entries(answers)
|
|
388
403
|
.filter(([, value]) => value.trim())
|
|
389
404
|
.map(([id, value]) => `${id}: ${value.trim()}`)
|
|
390
405
|
.join("; ");
|
|
391
|
-
pushActivity(state, summary ? `Owner answered. ${summary}` : "Owner answered. Continuing.", "ok");
|
|
406
|
+
pushActivity(state, summary ? `Owner answered. ${summary}` : skipAll ? "Owner skipped this round." : "Owner answered. Continuing.", "ok", answered.channel === "author" ? "author" : "implement");
|
|
392
407
|
if (answered.launch?.finished) {
|
|
393
|
-
state.busy =
|
|
408
|
+
state.busy =
|
|
409
|
+
answered.channel === "author" ? "author" : answered.channel === "improve" ? "improve" : "implement";
|
|
394
410
|
if (answered.channel === "implement")
|
|
395
411
|
state.implementLaunch = answered.launch;
|
|
412
|
+
if (answered.channel === "author")
|
|
413
|
+
state.authorLaunch = answered.launch;
|
|
396
414
|
await yieldEventLoop();
|
|
397
415
|
await sendJson(res, {
|
|
398
416
|
...(await snapshot(state)),
|
|
@@ -402,6 +420,9 @@ async function handle(state, req, res) {
|
|
|
402
420
|
if (answered.channel === "implement") {
|
|
403
421
|
void runImplement(state, state.pack, answered.launch, adapter);
|
|
404
422
|
}
|
|
423
|
+
else if (answered.channel === "author") {
|
|
424
|
+
void runAuthor(state, state.pack, answered.launch, adapter);
|
|
425
|
+
}
|
|
405
426
|
else {
|
|
406
427
|
void runImproveWait(state, answered.launch);
|
|
407
428
|
}
|
|
@@ -423,11 +444,14 @@ async function handle(state, req, res) {
|
|
|
423
444
|
return;
|
|
424
445
|
}
|
|
425
446
|
try {
|
|
426
|
-
const discarded = await discardAgentQuestions(state.pack, state.
|
|
447
|
+
const discarded = await discardAgentQuestions(state.pack, discardedLaunch(state, (await readAgentQuestions(state.pack))?.channel));
|
|
427
448
|
state.last = discarded.result;
|
|
428
449
|
state.busy = null;
|
|
429
|
-
|
|
430
|
-
|
|
450
|
+
if (discarded.channel === "implement")
|
|
451
|
+
state.implementLaunch = null;
|
|
452
|
+
if (discarded.channel === "author")
|
|
453
|
+
state.authorLaunch = null;
|
|
454
|
+
pushActivity(state, discarded.message, "ok", discarded.channel === "author" ? "author" : "implement");
|
|
431
455
|
await sendJson(res, { ...(await snapshot(state)), message: discarded.message });
|
|
432
456
|
}
|
|
433
457
|
catch (err) {
|
|
@@ -456,6 +480,91 @@ async function handle(state, req, res) {
|
|
|
456
480
|
void runProve(state, pack);
|
|
457
481
|
return;
|
|
458
482
|
}
|
|
483
|
+
if (req.method === "POST" && url.pathname === "/api/author/start") {
|
|
484
|
+
if (!state.pack) {
|
|
485
|
+
sendJson(res, { error: "No pack selected." }, 400);
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
if (state.busy) {
|
|
489
|
+
sendJson(res, { ...(await snapshot(state)), error: "Another action is already running." }, 409);
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
const body = await readJson(req);
|
|
493
|
+
const description = String(body["description"] ?? "").trim();
|
|
494
|
+
const adapter = parseAdapterId(body["adapter"]) ?? "cursor";
|
|
495
|
+
try {
|
|
496
|
+
clearActivity(state, "author");
|
|
497
|
+
const started = await startAuthor(state.pack, description, {
|
|
498
|
+
adapter,
|
|
499
|
+
onLogLine: (line) => pushActivity(state, line, "info", "author"),
|
|
500
|
+
});
|
|
501
|
+
state.last = started.result;
|
|
502
|
+
pushActivity(state, started.message, started.launch?.ok === false ? "error" : "ok", "author");
|
|
503
|
+
if (started.launch?.finished) {
|
|
504
|
+
state.busy = "author";
|
|
505
|
+
state.authorLaunch = started.launch;
|
|
506
|
+
await yieldEventLoop();
|
|
507
|
+
await sendJson(res, {
|
|
508
|
+
...(await snapshot(state)),
|
|
509
|
+
started: true,
|
|
510
|
+
message: started.message,
|
|
511
|
+
});
|
|
512
|
+
void runAuthor(state, state.pack, started.launch, adapter);
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
await sendJson(res, { ...(await snapshot(state)), message: started.message });
|
|
516
|
+
}
|
|
517
|
+
catch (err) {
|
|
518
|
+
sendJson(res, {
|
|
519
|
+
...(await snapshot(state)),
|
|
520
|
+
error: err instanceof Error ? err.message : "Could not start authoring.",
|
|
521
|
+
}, err instanceof AuthorLockedError || err instanceof AgentAnswersError ? 409 : 500);
|
|
522
|
+
}
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
if (req.method === "POST" && url.pathname === "/api/author/stop") {
|
|
526
|
+
if (!state.pack) {
|
|
527
|
+
sendJson(res, { error: "No pack selected." }, 400);
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
try {
|
|
531
|
+
const stopped = await stopAuthor(state.pack, state.authorLaunch);
|
|
532
|
+
state.last = stopped.result;
|
|
533
|
+
state.busy = null;
|
|
534
|
+
state.authorLaunch = null;
|
|
535
|
+
pushActivity(state, stopped.message, "ok", "author");
|
|
536
|
+
await sendJson(res, { ...(await snapshot(state)), message: stopped.message });
|
|
537
|
+
}
|
|
538
|
+
catch (err) {
|
|
539
|
+
sendJson(res, {
|
|
540
|
+
...(await snapshot(state)),
|
|
541
|
+
error: err instanceof Error ? err.message : "Could not stop authoring.",
|
|
542
|
+
}, 500);
|
|
543
|
+
}
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
if (req.method === "POST" && url.pathname === "/api/author/artifact") {
|
|
547
|
+
if (!state.pack) {
|
|
548
|
+
sendJson(res, { error: "No pack selected." }, 400);
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
const body = await readJson(req);
|
|
552
|
+
const filename = String(body["filename"] ?? "");
|
|
553
|
+
const mime = String(body["mime"] ?? "");
|
|
554
|
+
const data = String(body["data"] ?? "");
|
|
555
|
+
try {
|
|
556
|
+
const saved = await saveAuthorArtifact(state.pack, filename, mime, data);
|
|
557
|
+
pushActivity(state, `Saved context/${saved}.`, "ok", "author");
|
|
558
|
+
await sendJson(res, { ...(await snapshot(state)), filename: saved, message: `Saved context/${saved}.` });
|
|
559
|
+
}
|
|
560
|
+
catch (err) {
|
|
561
|
+
sendJson(res, {
|
|
562
|
+
...(await snapshot(state)),
|
|
563
|
+
error: err instanceof Error ? err.message : "Could not save the upload.",
|
|
564
|
+
}, err instanceof AuthorArtifactError ? 400 : 500);
|
|
565
|
+
}
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
459
568
|
if (req.method === "POST" && url.pathname === "/api/create-in-place") {
|
|
460
569
|
if (!state.pack) {
|
|
461
570
|
sendJson(res, { error: "No pack folder selected." }, 400);
|
|
@@ -488,16 +597,22 @@ async function snapshot(state) {
|
|
|
488
597
|
if (state.pack && !state.last) {
|
|
489
598
|
state.last = await compilePack(state.pack);
|
|
490
599
|
}
|
|
600
|
+
const authorRun = state.pack ? await readAuthorRun(state.pack) : null;
|
|
491
601
|
const improveReview = state.pack ? await evaluateImproveReview(state.pack) : null;
|
|
492
602
|
const agentQuestions = state.pack ? await readAgentQuestions(state.pack) : null;
|
|
493
603
|
const openQuestions = isOpenQuestions(agentQuestions) ? agentQuestions : null;
|
|
494
604
|
if (improveReview?.files.length && !state.implementActivity.some((line) => line.message === "Improve patch ready to review.")) {
|
|
495
605
|
pushActivity(state, "Improve patch ready to review.", "ok");
|
|
496
606
|
}
|
|
497
|
-
if (openQuestions && !state.
|
|
607
|
+
if (openQuestions && openQuestions.channel === "author" && !state.authorActivity.some((line) => line.message === AGENT_QUESTIONS_WAITING)) {
|
|
608
|
+
pushActivity(state, AGENT_QUESTIONS_WAITING, "info", "author");
|
|
609
|
+
}
|
|
610
|
+
else if (openQuestions && openQuestions.channel !== "author" && !state.implementActivity.some((line) => line.message === AGENT_QUESTIONS_WAITING)) {
|
|
498
611
|
pushActivity(state, AGENT_QUESTIONS_WAITING);
|
|
499
612
|
}
|
|
500
613
|
let health = state.last ? applyImproveReviewGate(state.last.health, openQuestions ? null : improveReview) : null;
|
|
614
|
+
if (health)
|
|
615
|
+
health = applyAuthorGate(health, authorRun);
|
|
501
616
|
if (health)
|
|
502
617
|
health = applyAgentQuestionsGate(health, openQuestions);
|
|
503
618
|
let proofReport = "";
|
|
@@ -525,9 +640,11 @@ async function snapshot(state) {
|
|
|
525
640
|
productRepo: await inspectProductRepo(await inspectFrom(state)),
|
|
526
641
|
implementActivity: state.implementActivity,
|
|
527
642
|
proveActivity: state.proveActivity,
|
|
643
|
+
authorActivity: state.authorActivity,
|
|
528
644
|
busy: state.busy,
|
|
529
645
|
improveReview,
|
|
530
646
|
agentQuestions,
|
|
647
|
+
authorRun,
|
|
531
648
|
};
|
|
532
649
|
}
|
|
533
650
|
async function inspectFrom(state) {
|
|
@@ -611,6 +728,47 @@ async function runImplement(state, pack, launch, adapter) {
|
|
|
611
728
|
state.implementLaunch = null;
|
|
612
729
|
}
|
|
613
730
|
}
|
|
731
|
+
async function runAuthor(state, pack, launch, adapter) {
|
|
732
|
+
let current = launch;
|
|
733
|
+
try {
|
|
734
|
+
while (true) {
|
|
735
|
+
const settled = await settleAuthor(pack, current);
|
|
736
|
+
if (state.pack?.root === pack.root)
|
|
737
|
+
state.last = settled.result;
|
|
738
|
+
pushActivity(state, settled.message, settled.action === "done" ? "ok" : settled.action === "capped" ? "error" : "info", "author");
|
|
739
|
+
if (settled.action === "wait_questions" || settled.action === "done" || settled.action === "capped") {
|
|
740
|
+
break;
|
|
741
|
+
}
|
|
742
|
+
if (settled.action !== "relaunch")
|
|
743
|
+
break;
|
|
744
|
+
const next = await launchAuthor(pack, {
|
|
745
|
+
adapter,
|
|
746
|
+
onLogLine: (line) => pushActivity(state, line, "info", "author"),
|
|
747
|
+
});
|
|
748
|
+
pushActivity(state, next.message, next.ok ? "ok" : "error", "author");
|
|
749
|
+
if (!next.finished)
|
|
750
|
+
break;
|
|
751
|
+
current = next;
|
|
752
|
+
state.authorLaunch = next;
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
catch (err) {
|
|
756
|
+
pushActivity(state, err instanceof Error ? err.message : "Authoring failed.", "error", "author");
|
|
757
|
+
}
|
|
758
|
+
finally {
|
|
759
|
+
if (state.busy === "author")
|
|
760
|
+
state.busy = null;
|
|
761
|
+
if (state.authorLaunch === current || state.authorLaunch === launch)
|
|
762
|
+
state.authorLaunch = null;
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
function discardedLaunch(state, channel) {
|
|
766
|
+
if (channel === "author")
|
|
767
|
+
return state.authorLaunch;
|
|
768
|
+
if (channel === "implement")
|
|
769
|
+
return state.implementLaunch;
|
|
770
|
+
return state.implementLaunch;
|
|
771
|
+
}
|
|
614
772
|
async function runProve(state, pack) {
|
|
615
773
|
try {
|
|
616
774
|
const proved = await provePack(pack, {
|
|
@@ -634,6 +792,8 @@ function clearActivity(state, channel) {
|
|
|
634
792
|
state.implementActivity = [];
|
|
635
793
|
if (!channel || channel === "prove")
|
|
636
794
|
state.proveActivity = [];
|
|
795
|
+
if (!channel || channel === "author")
|
|
796
|
+
state.authorActivity = [];
|
|
637
797
|
}
|
|
638
798
|
function pushActivity(state, message, level = "info", channel = "implement") {
|
|
639
799
|
const line = { at: new Date().toISOString(), level, message };
|
|
@@ -641,6 +801,10 @@ function pushActivity(state, message, level = "info", channel = "implement") {
|
|
|
641
801
|
state.proveActivity = [...state.proveActivity, line].slice(-80);
|
|
642
802
|
return;
|
|
643
803
|
}
|
|
804
|
+
if (channel === "author") {
|
|
805
|
+
state.authorActivity = [...state.authorActivity, line].slice(-80);
|
|
806
|
+
return;
|
|
807
|
+
}
|
|
644
808
|
state.implementActivity = [...state.implementActivity, line].slice(-80);
|
|
645
809
|
}
|
|
646
810
|
async function yieldEventLoop() {
|
package/dist/types.d.ts
CHANGED
|
@@ -66,6 +66,8 @@ export type StageBoard = {
|
|
|
66
66
|
ignoreBuild?: StageAction;
|
|
67
67
|
/** Shown while Implement is running. */
|
|
68
68
|
stopImplement?: StageAction;
|
|
69
|
+
/** Shown while authoring is running. */
|
|
70
|
+
stopAuthor?: StageAction;
|
|
69
71
|
};
|
|
70
72
|
/** Cockpit display only. health.json still uses spec / ready / build / proof. */
|
|
71
73
|
export type PipelineTone = "idle" | "draft" | "ok" | "bad" | "progress";
|
|
@@ -241,7 +243,7 @@ export type ProofRun = {
|
|
|
241
243
|
cases: ProofCaseResult[];
|
|
242
244
|
};
|
|
243
245
|
export type ActivityLevel = "info" | "ok" | "error";
|
|
244
|
-
export type ActivityChannel = "implement" | "prove";
|
|
246
|
+
export type ActivityChannel = "implement" | "prove" | "author";
|
|
245
247
|
export type ActivityLine = {
|
|
246
248
|
at: string;
|
|
247
249
|
level: ActivityLevel;
|
package/package.json
CHANGED