@richjava/req0 0.6.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.
package/dist/pack.js CHANGED
@@ -9,8 +9,11 @@ import { assertImproveAllowed, emitImproveBrief, improveFindings } from "./impro
9
9
  import { clearImproveLog, readImproveLog, recordImprovePending } from "./improve-log.js";
10
10
  import { beginImproveReview, ImproveReviewPendingError, readImproveSnapshot, rejectImproveReview } from "./improve-review.js";
11
11
  import { emitImplementBrief } from "./implement-brief.js";
12
+ import { appendPlanDecisions, emitImplementPlanBrief, IMPLEMENT_PLAN_BRIEF_FILE, IMPLEMENT_PLAN_FILE, IMPLEMENT_PLAN_STATE_FILE, IMPLEMENT_PLANS_DIR, implementPlanPrompt, MANUAL_STUB_PLAN, readImplementPlanMarkdown, readImplementPlanState, snapshotAcceptedPlan, writeImplementPlanState, } from "./implement-plan.js";
13
+ import { loadSystemMap } from "./system-map.js";
12
14
  import { hasJevAccess, JevRequestError, JevUnavailableError, resolveJevClient } from "./jev.js";
13
15
  import { emitJevPack } from "./jev-pack.js";
16
+ import { loadStandards } from "./standards.js";
14
17
  import { parsePersonasYaml } from "./personas.js";
15
18
  import { emitProofReport } from "./proof-report.js";
16
19
  import { emitQaPlan, emitQaPlanYaml } from "./qa-plan.js";
@@ -18,7 +21,7 @@ import { assertProveAllowed, evaluateProof, persistProofRun, provePlan, ProveLoc
18
21
  import { applyReadyToHealth, attachReady, evaluateBuild, followImplementPid, IMPLEMENT_INTERRUPTED, implementProcessGone, IgnoreBuildLockedError, isFollowedImplement, specHash, unfollowImplementPid, } from "./ready.js";
19
22
  import { ignoreBuildAllowed, packListMeters } from "./stages.js";
20
23
  import { parseRuntimeYaml } from "./runtime.js";
21
- import { inspectProductRepo, needsStackChoice, resolveStackId, StackRequiredError, UnknownStackError, writeAmplifyEnvExampleIfMissing, writeReq0Config, } from "./stack.js";
24
+ import { inspectProductRepo, needsStackChoice, readReq0Config, resolveStackId, StackRequiredError, UnknownStackError, writeAmplifyEnvExampleIfMissing, writeReq0Config, } from "./stack.js";
22
25
  import { loadStarterRequirement, PERSONAS_STUB, RUNTIME_STUB } from "./template.js";
23
26
  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
27
  import { AGENT_QUESTIONS_WAITING, AgentAnswersError, applyAnswers, clearAgentQuestions, isOpenQuestions, readAgentQuestions, withOwnerAnswers, writeAgentQuestions, } from "./agent-questions.js";
@@ -54,11 +57,17 @@ export function packPaths(root) {
54
57
  context: path.join(root, "context"),
55
58
  authorBrief: path.join(derived, AUTHOR_BRIEF_FILE),
56
59
  authorRun: path.join(derived, AUTHOR_RUN_FILE),
60
+ implementPlan: path.join(derived, IMPLEMENT_PLAN_FILE),
61
+ implementPlanState: path.join(derived, IMPLEMENT_PLAN_STATE_FILE),
62
+ implementPlanBrief: path.join(derived, IMPLEMENT_PLAN_BRIEF_FILE),
63
+ implementPlans: path.join(derived, IMPLEMENT_PLANS_DIR),
57
64
  };
58
65
  }
59
66
  export async function withRememberedAnswers(paths, prompt) {
60
67
  const round = await readAgentQuestions(paths);
61
- if (!round || round.status !== "answered" || round.channel !== "implement")
68
+ if (!round || round.status !== "answered")
69
+ return prompt;
70
+ if (round.channel !== "implement" && round.channel !== "plan")
62
71
  return prompt;
63
72
  return withOwnerAnswers(prompt, round);
64
73
  }
@@ -183,10 +192,18 @@ export async function loadPersonas(paths) {
183
192
  export async function compilePack(paths) {
184
193
  const markdown = await readMarkdown(paths);
185
194
  let result = compileMarkdown(paths.id, markdown);
186
- if (result.spec)
187
- result = { ...result, jevPack: emitJevPack(result.spec) };
188
195
  const personas = await loadPersonas(paths);
189
196
  const repo = await inspectProductRepo(paths.root);
197
+ const config = repo.root ? await readReq0Config(repo.root) : null;
198
+ const standards = await loadStandards(repo.root, config);
199
+ const system = await loadSystemMap(repo.root, config);
200
+ const contextFiles = await listContextFiles(paths);
201
+ if (result.spec) {
202
+ result = {
203
+ ...result,
204
+ jevPack: emitJevPack(result.spec, { markdown, contextFiles, standards }),
205
+ };
206
+ }
190
207
  if (repo.root && repo.recorded) {
191
208
  await writeAmplifyEnvExampleIfMissing(repo.root, repo.stack);
192
209
  }
@@ -198,6 +215,8 @@ export async function compilePack(paths) {
198
215
  repo,
199
216
  adapter: repo.adapter,
200
217
  personas,
218
+ standards,
219
+ system,
201
220
  }),
202
221
  };
203
222
  }
@@ -222,6 +241,8 @@ export async function compilePack(paths) {
222
241
  adapter: buildRun.adapter,
223
242
  at: new Date().toISOString(),
224
243
  message: IMPLEMENT_INTERRUPTED,
244
+ ...(buildRun.fromProof ? { fromProof: true } : {}),
245
+ ...(buildRun.phase ? { phase: buildRun.phase } : {}),
225
246
  });
226
247
  }
227
248
  const latestBuildRun = await readBuildRun(paths);
@@ -397,7 +418,8 @@ export async function implementPack(paths, options = {}) {
397
418
  throw new AgentAnswersError("Answer the agent's questions, or Stop, before starting a new Implement.");
398
419
  }
399
420
  assertImplementAllowed(compiled);
400
- if (options.fromProof && !options.resume) {
421
+ const fromProof = options.fromProof === true;
422
+ if (fromProof && !options.resume) {
401
423
  assertFixFromProofAllowed(compiled.health, compiled.health.ready);
402
424
  if (!compiled.spec)
403
425
  throw new FixFromProofLockedError();
@@ -418,9 +440,156 @@ export async function implementPack(paths, options = {}) {
418
440
  if (stack)
419
441
  await writeAmplifyEnvExampleIfMissing(repo.root, stack);
420
442
  }
443
+ const previous = await readBuildRun(paths);
444
+ const proof = fromProof || previous?.fromProof === true;
445
+ if (options.code || (options.resume && previous?.phase === "code")) {
446
+ return launchCodePhase(paths, {
447
+ compiled,
448
+ adapter,
449
+ stackId: stack?.id ?? repo.stack.id,
450
+ fromProof: proof,
451
+ extraPrompt: options.extraPrompt,
452
+ onLogLine: options.onLogLine,
453
+ });
454
+ }
455
+ return launchPlanPhase(paths, {
456
+ compiled,
457
+ adapter,
458
+ stackId: stack?.id ?? repo.stack.id,
459
+ fromProof: proof,
460
+ extraPrompt: options.extraPrompt,
461
+ onLogLine: options.onLogLine,
462
+ resume: options.resume === true,
463
+ });
464
+ }
465
+ async function writePlanBrief(paths, compiled, fromProof) {
466
+ if (!compiled.spec)
467
+ return;
468
+ const repo = await inspectProductRepo(paths.root);
469
+ const config = repo.root ? await readReq0Config(repo.root) : null;
470
+ const brief = emitImplementPlanBrief({
471
+ spec: compiled.spec,
472
+ system: await loadSystemMap(repo.root, config),
473
+ standards: await loadStandards(repo.root, config),
474
+ fromProof,
475
+ });
476
+ await mkdir(paths.derived, { recursive: true });
477
+ await writeFile(paths.implementPlanBrief, brief, "utf8");
478
+ }
479
+ async function launchPlanPhase(paths, input) {
480
+ const { compiled, adapter } = input;
481
+ const repo = await inspectProductRepo(paths.root);
482
+ await writePlanBrief(paths, compiled, input.fromProof);
483
+ const specHashValue = compiled.spec ? specHash(compiled.spec) : "";
484
+ const at = new Date().toISOString();
485
+ await writeImplementPlanState(paths, {
486
+ version: 1,
487
+ specHash: specHashValue,
488
+ status: "running",
489
+ at,
490
+ });
491
+ let prompt = implementPlanPrompt(paths.implementPlanBrief);
492
+ if (input.resume)
493
+ prompt = await withRememberedAnswers(paths, prompt);
494
+ if (input.extraPrompt)
495
+ prompt = `${prompt}\n\n${input.extraPrompt}`;
496
+ const launch = await launchAdapter(adapter, repo.root, paths.implementPlanBrief, {
497
+ onLogLine: input.onLogLine,
498
+ prompt,
499
+ });
500
+ const following = launch.ok && adapterLaunchesAgent(adapter) && Boolean(launch.finished);
501
+ if (following)
502
+ followImplementPid(launch.child?.pid);
503
+ await writeBuildRun(paths, {
504
+ specHash: specHashValue,
505
+ state: !launch.ok ? "failed" : following ? "running" : "running",
506
+ adapter,
507
+ at,
508
+ message: launch.message,
509
+ phase: "plan",
510
+ ...(following && launch.child?.pid ? { pid: launch.child.pid } : {}),
511
+ ...(input.fromProof ? { fromProof: true } : {}),
512
+ });
513
+ if (!launch.ok) {
514
+ await writeImplementPlanState(paths, {
515
+ version: 1,
516
+ specHash: specHashValue,
517
+ status: "failed",
518
+ at,
519
+ });
520
+ return { result: await compilePack(paths), message: launch.message, launch };
521
+ }
522
+ if (following) {
523
+ return { result: await compilePack(paths), message: launch.message, launch };
524
+ }
525
+ return settlePlanner(paths, adapter, { fromProof: input.fromProof, onLogLine: input.onLogLine, stackId: input.stackId });
526
+ }
527
+ async function settlePlanner(paths, adapter, input) {
528
+ const compiled = await compilePack(paths);
529
+ const specHashValue = compiled.spec ? specHash(compiled.spec) : "";
530
+ const at = new Date().toISOString();
531
+ if (isOpenQuestions(await readAgentQuestions(paths))) {
532
+ await writeImplementPlanState(paths, {
533
+ version: 1,
534
+ specHash: specHashValue,
535
+ status: "waiting_questions",
536
+ at,
537
+ });
538
+ await writeBuildRun(paths, {
539
+ specHash: specHashValue,
540
+ state: "running",
541
+ adapter,
542
+ at,
543
+ message: AGENT_QUESTIONS_WAITING,
544
+ waitingOnQuestions: true,
545
+ phase: "plan",
546
+ ...(input.fromProof ? { fromProof: true } : {}),
547
+ });
548
+ return { result: await compilePack(paths), message: AGENT_QUESTIONS_WAITING };
549
+ }
550
+ let markdown = await readImplementPlanMarkdown(paths);
551
+ if (!markdown.trim()) {
552
+ if (!adapterLaunchesAgent(adapter)) {
553
+ await mkdir(paths.derived, { recursive: true });
554
+ await writeFile(paths.implementPlan, MANUAL_STUB_PLAN, "utf8");
555
+ markdown = MANUAL_STUB_PLAN;
556
+ }
557
+ }
558
+ if (!markdown.trim()) {
559
+ await writeImplementPlanState(paths, { version: 1, specHash: specHashValue, status: "failed", at });
560
+ await writeBuildRun(paths, {
561
+ specHash: specHashValue,
562
+ state: "failed",
563
+ adapter,
564
+ at,
565
+ message: "Planner finished without derived/implement-plan.md.",
566
+ phase: "plan",
567
+ ...(input.fromProof ? { fromProof: true } : {}),
568
+ });
569
+ return { result: await compilePack(paths), message: "Planner finished without derived/implement-plan.md." };
570
+ }
571
+ const snapshot = await snapshotAcceptedPlan(paths);
572
+ await writeImplementPlanState(paths, {
573
+ version: 1,
574
+ specHash: specHashValue,
575
+ status: "accepted",
576
+ at,
577
+ snapshot,
578
+ });
579
+ return launchCodePhase(paths, {
580
+ compiled,
581
+ adapter,
582
+ stackId: input.stackId,
583
+ fromProof: input.fromProof,
584
+ onLogLine: input.onLogLine,
585
+ });
586
+ }
587
+ async function launchCodePhase(paths, input) {
588
+ const { compiled, adapter } = input;
589
+ const repo = await inspectProductRepo(paths.root);
421
590
  let briefPath = paths.implementBrief;
422
- let prompt = implementPrompt(paths.implementBrief, stack?.id ?? repo.stack.id);
423
- if (options.fromProof && compiled.spec) {
591
+ let prompt = implementPrompt(paths.implementBrief, input.stackId);
592
+ if (input.fromProof && compiled.spec) {
424
593
  const brief = emitFixFromProofBrief({
425
594
  spec: compiled.spec,
426
595
  proof: compiled.health.proof,
@@ -433,23 +602,25 @@ export async function implementPack(paths, options = {}) {
433
602
  prompt = fixFromProofPrompt(paths.fixFromProofBrief, paths.proofReport, paths.implementBrief);
434
603
  }
435
604
  prompt = await withRememberedAnswers(paths, prompt);
436
- if (options.extraPrompt)
437
- prompt = `${prompt}\n\n${options.extraPrompt}`;
605
+ if (input.extraPrompt)
606
+ prompt = `${prompt}\n\n${input.extraPrompt}`;
438
607
  const launch = await launchAdapter(adapter, repo.root, briefPath, {
439
- onLogLine: options.onLogLine,
608
+ onLogLine: input.onLogLine,
440
609
  prompt,
441
610
  });
442
611
  const following = launch.ok && adapterLaunchesAgent(adapter) && Boolean(launch.finished);
443
612
  if (following)
444
613
  followImplementPid(launch.child?.pid);
614
+ const specHashValue = compiled.spec ? specHash(compiled.spec) : "";
445
615
  await writeBuildRun(paths, {
446
- specHash: compiled.spec ? specHash(compiled.spec) : "",
616
+ specHash: specHashValue,
447
617
  state: !launch.ok ? "failed" : following ? "running" : "succeeded",
448
618
  adapter,
449
619
  at: new Date().toISOString(),
450
620
  message: launch.message,
621
+ phase: "code",
451
622
  ...(following && launch.child?.pid ? { pid: launch.child.pid } : {}),
452
- ...(options.fromProof ? { fromProof: true } : {}),
623
+ ...(input.fromProof ? { fromProof: true } : {}),
453
624
  });
454
625
  return { result: await compilePack(paths), message: launch.message, launch };
455
626
  }
@@ -460,7 +631,17 @@ export async function finishImplement(paths, launch, adapter) {
460
631
  const previous = await readBuildRun(paths);
461
632
  const stopped = launch.stop?.reason;
462
633
  const waiting = !stopped && isOpenQuestions(await readAgentQuestions(paths));
634
+ const fromProof = previous?.fromProof === true;
635
+ const phase = previous?.phase ?? "code";
463
636
  if (waiting) {
637
+ if (phase === "plan") {
638
+ await writeImplementPlanState(paths, {
639
+ version: 1,
640
+ specHash: compiled.spec ? specHash(compiled.spec) : previous?.specHash ?? "",
641
+ status: "waiting_questions",
642
+ at: new Date().toISOString(),
643
+ });
644
+ }
464
645
  await writeBuildRun(paths, {
465
646
  specHash: compiled.spec ? specHash(compiled.spec) : previous?.specHash ?? "",
466
647
  state: "running",
@@ -468,10 +649,41 @@ export async function finishImplement(paths, launch, adapter) {
468
649
  at: new Date().toISOString(),
469
650
  message: AGENT_QUESTIONS_WAITING,
470
651
  waitingOnQuestions: true,
471
- ...(previous?.fromProof ? { fromProof: true } : {}),
652
+ phase,
653
+ ...(fromProof ? { fromProof: true } : {}),
472
654
  });
473
655
  return { result: await compilePack(paths), message: AGENT_QUESTIONS_WAITING };
474
656
  }
657
+ if (phase === "plan") {
658
+ const ok = !stopped && launch.ok && done.code === 0;
659
+ if (!ok) {
660
+ const name = adapterDisplayName(adapter);
661
+ const message = stopped
662
+ ? stopped
663
+ : `${name} agent exited (${done.code ?? "unknown"}). ${tailImplementLog(paths)}`.trim();
664
+ await writeImplementPlanState(paths, {
665
+ version: 1,
666
+ specHash: compiled.spec ? specHash(compiled.spec) : previous?.specHash ?? "",
667
+ status: "failed",
668
+ at: new Date().toISOString(),
669
+ });
670
+ await writeBuildRun(paths, {
671
+ specHash: compiled.spec ? specHash(compiled.spec) : "",
672
+ state: "failed",
673
+ adapter,
674
+ at: new Date().toISOString(),
675
+ message,
676
+ phase: "plan",
677
+ ...(fromProof ? { fromProof: true } : {}),
678
+ });
679
+ return { result: await compilePack(paths), message };
680
+ }
681
+ const repo = await inspectProductRepo(paths.root);
682
+ return settlePlanner(paths, adapter, {
683
+ fromProof,
684
+ stackId: repo.stack.id,
685
+ });
686
+ }
475
687
  const ok = !stopped && launch.ok && done.code === 0;
476
688
  const name = adapterDisplayName(adapter);
477
689
  const message = stopped
@@ -485,7 +697,8 @@ export async function finishImplement(paths, launch, adapter) {
485
697
  adapter,
486
698
  at: new Date().toISOString(),
487
699
  message,
488
- ...(previous?.fromProof ? { fromProof: true } : {}),
700
+ phase: "code",
701
+ ...(fromProof ? { fromProof: true } : {}),
489
702
  });
490
703
  return { result: await compilePack(paths), message };
491
704
  }
@@ -508,12 +721,21 @@ export async function stopImplement(paths, launch, reason = IMPLEMENT_STOPPED) {
508
721
  await clearAgentQuestions(paths);
509
722
  const compiled = await compilePack(paths);
510
723
  const previous = await readBuildRun(paths);
724
+ const plan = await readImplementPlanState(paths);
725
+ if (plan && plan.status !== "accepted") {
726
+ await writeImplementPlanState(paths, {
727
+ ...plan,
728
+ status: "failed",
729
+ at: new Date().toISOString(),
730
+ });
731
+ }
511
732
  await writeBuildRun(paths, {
512
733
  specHash: compiled.spec ? specHash(compiled.spec) : "",
513
734
  state: "failed",
514
735
  adapter: previous?.adapter ?? "cursor",
515
736
  at: new Date().toISOString(),
516
737
  message: reason,
738
+ phase: previous?.phase,
517
739
  ...(previous?.fromProof ? { fromProof: true } : {}),
518
740
  });
519
741
  return { result: await compilePack(paths), message: reason };
@@ -566,10 +788,13 @@ export async function writeImproveBrief(paths, compiled) {
566
788
  const result = compiled ?? (await compilePack(paths));
567
789
  assertImproveAllowed(result.health.ready);
568
790
  const findings = improveFindings(result.health.ready);
791
+ const repo = await inspectProductRepo(paths.root);
792
+ const config = repo.root ? await readReq0Config(repo.root) : null;
569
793
  const brief = emitImproveBrief({
570
794
  spec: result.spec,
571
795
  ready: result.health.ready,
572
796
  findings,
797
+ standards: await loadStandards(repo.root, config),
573
798
  });
574
799
  await mkdir(paths.derived, { recursive: true });
575
800
  await writeFile(paths.improveBrief, brief, "utf8");
@@ -607,6 +832,7 @@ export async function writeAuthorBrief(paths, compiled, run) {
607
832
  siblings: await siblingSummaries(paths),
608
833
  product: productBriefBits(repo, await listProductLayout(repo.root)),
609
834
  contextFiles: await listContextFiles(paths),
835
+ standards: await loadStandards(repo.root, repo.root ? await readReq0Config(repo.root) : null),
610
836
  });
611
837
  await mkdir(paths.derived, { recursive: true });
612
838
  await writeFile(paths.authorBrief, brief, "utf8");
@@ -782,6 +1008,9 @@ export async function answerAgentQuestions(paths, answers, options = {}) {
782
1008
  }
783
1009
  const answered = applyAnswers(open, answers, { skipAll: options.skipAll === true });
784
1010
  await writeAgentQuestions(paths, answered);
1011
+ if (answered.channel === "plan") {
1012
+ await appendPlanDecisions(paths, answered);
1013
+ }
785
1014
  const extraPrompt = withOwnerAnswers("", answered).trim();
786
1015
  if (answered.channel === "author") {
787
1016
  const launched = await resumeAuthor(paths, { adapter: options.adapter, extraPrompt, onLogLine: options.onLogLine });
@@ -806,12 +1035,14 @@ export async function answerAgentQuestions(paths, answers, options = {}) {
806
1035
  adapter: options.adapter ?? previous?.adapter,
807
1036
  fromProof: previous?.fromProof === true,
808
1037
  onLogLine: options.onLogLine,
1038
+ extraPrompt,
809
1039
  resume: true,
1040
+ code: answered.channel === "implement",
810
1041
  });
811
1042
  return {
812
1043
  result: launched.result,
813
1044
  message: launched.message,
814
- channel: "implement",
1045
+ channel: answered.channel,
815
1046
  launch: launched.launch,
816
1047
  };
817
1048
  }
@@ -820,9 +1051,9 @@ export async function discardAgentQuestions(paths, launch) {
820
1051
  if (!isOpenQuestions(open)) {
821
1052
  throw new AgentAnswersError("No open questions to discard.");
822
1053
  }
823
- if (open.channel === "implement") {
1054
+ if (open.channel === "implement" || open.channel === "plan") {
824
1055
  const stopped = await stopImplement(paths, launch);
825
- return { result: stopped.result, message: stopped.message, channel: "implement" };
1056
+ return { result: stopped.result, message: stopped.message, channel: open.channel };
826
1057
  }
827
1058
  if (open.channel === "author") {
828
1059
  const stopped = await stopAuthor(paths, launch);
package/dist/ready.js CHANGED
@@ -34,12 +34,14 @@ export function evaluateBuild(spec, run) {
34
34
  state: "running",
35
35
  adapter: run.adapter,
36
36
  message: run.message,
37
+ ...(run.phase ? { phase: run.phase } : {}),
37
38
  };
38
39
  }
39
40
  return {
40
41
  state: "failed",
41
42
  adapter: run.adapter,
42
43
  message: IMPLEMENT_INTERRUPTED,
44
+ ...(run.phase ? { phase: run.phase } : {}),
43
45
  };
44
46
  }
45
47
  return {
@@ -47,6 +49,7 @@ export function evaluateBuild(spec, run) {
47
49
  adapter: run.adapter,
48
50
  message: run.message,
49
51
  ...(run.ignored ? { ignored: true } : {}),
52
+ ...(run.phase ? { phase: run.phase } : {}),
50
53
  };
51
54
  }
52
55
  export class IgnoreBuildLockedError extends Error {
@@ -195,6 +198,16 @@ export function evaluateReady(input) {
195
198
  });
196
199
  }
197
200
  }
201
+ for (const answer of run.answers) {
202
+ if (!answer.id.startsWith("std.") || typeof answer.noul !== "number")
203
+ continue;
204
+ classifyStandardsNoul(findings, {
205
+ id: `ready.${answer.id}`,
206
+ noul: answer.noul,
207
+ failMessage: `${answer.id} does not meet the house standard (noul ${fmt(answer.noul)}).`,
208
+ uncertainMessage: `${answer.id} is uncertain against the house standard (noul ${fmt(answer.noul)}).`,
209
+ });
210
+ }
198
211
  }
199
212
  const blockers = findings.filter((finding) => finding.severity === "blocker").length;
200
213
  const nits = findings.filter((finding) => finding.severity === "nit").length;
@@ -261,6 +274,9 @@ function goingCopy(health, ready) {
261
274
  }
262
275
  if (health.build.state === "running") {
263
276
  const agent = adapterDisplayName(health.build.adapter ?? "cursor");
277
+ if (health.build.phase === "plan") {
278
+ return `${agent} agent is planning this implement pass. Stop ends the run.`;
279
+ }
264
280
  return `${agent} agent is running. Activity shows tools and messages as they happen. Stop ends the run. Build Succeeded is not proof the app boots.`;
265
281
  }
266
282
  if (health.build.state === "stale")
@@ -274,6 +290,17 @@ function goingCopy(health, ready) {
274
290
  }
275
291
  return "The pack is valid. Check it with Jev to turn on Ready.";
276
292
  }
293
+ function classifyStandardsNoul(findings, input) {
294
+ if (input.noul >= NOUL_PASS)
295
+ return;
296
+ findings.push({
297
+ id: input.id,
298
+ kind: "standards",
299
+ severity: "nit",
300
+ message: input.noul <= NOUL_FAIL ? input.failMessage : input.uncertainMessage,
301
+ noul: input.noul,
302
+ });
303
+ }
277
304
  function classifyNoul(findings, input) {
278
305
  const pass = input.yesMeansPass ? input.noul >= NOUL_PASS : input.noul <= NOUL_FAIL;
279
306
  const fail = input.yesMeansPass ? input.noul <= NOUL_FAIL : input.noul >= NOUL_PASS;
package/dist/server.js CHANGED
@@ -407,8 +407,9 @@ async function handle(state, req, res) {
407
407
  if (answered.launch?.finished) {
408
408
  state.busy =
409
409
  answered.channel === "author" ? "author" : answered.channel === "improve" ? "improve" : "implement";
410
- if (answered.channel === "implement")
410
+ if (answered.channel === "implement" || answered.channel === "plan") {
411
411
  state.implementLaunch = answered.launch;
412
+ }
412
413
  if (answered.channel === "author")
413
414
  state.authorLaunch = answered.launch;
414
415
  await yieldEventLoop();
@@ -417,7 +418,7 @@ async function handle(state, req, res) {
417
418
  started: true,
418
419
  message: answered.message,
419
420
  });
420
- if (answered.channel === "implement") {
421
+ if (answered.channel === "implement" || answered.channel === "plan") {
421
422
  void runImplement(state, state.pack, answered.launch, adapter);
422
423
  }
423
424
  else if (answered.channel === "author") {
@@ -447,7 +448,7 @@ async function handle(state, req, res) {
447
448
  const discarded = await discardAgentQuestions(state.pack, discardedLaunch(state, (await readAgentQuestions(state.pack))?.channel));
448
449
  state.last = discarded.result;
449
450
  state.busy = null;
450
- if (discarded.channel === "implement")
451
+ if (discarded.channel === "implement" || discarded.channel === "plan")
451
452
  state.implementLaunch = null;
452
453
  if (discarded.channel === "author")
453
454
  state.authorLaunch = null;
@@ -711,12 +712,22 @@ async function runImprove(state, pack, adapter) {
711
712
  }
712
713
  }
713
714
  async function runImplement(state, pack, launch, adapter) {
715
+ let current = launch;
714
716
  try {
715
- const done = await finishImplement(pack, launch, adapter);
716
- if (state.pack?.root === pack.root)
717
- state.last = done.result;
718
- const waiting = done.message === AGENT_QUESTIONS_WAITING;
719
- pushActivity(state, done.message, done.result.health.build.state === "failed" ? "error" : waiting ? "info" : "ok");
717
+ while (current) {
718
+ const tracked = current;
719
+ const done = await finishImplement(pack, tracked, adapter);
720
+ if (state.pack?.root === pack.root)
721
+ state.last = done.result;
722
+ const waiting = done.message === AGENT_QUESTIONS_WAITING;
723
+ pushActivity(state, done.message, done.result.health.build.state === "failed" ? "error" : waiting ? "info" : "ok");
724
+ if (done.launch?.finished) {
725
+ state.implementLaunch = done.launch;
726
+ current = done.launch;
727
+ continue;
728
+ }
729
+ current = undefined;
730
+ }
720
731
  }
721
732
  catch (err) {
722
733
  pushActivity(state, err instanceof Error ? err.message : "Implement failed.", "error");
@@ -724,7 +735,7 @@ async function runImplement(state, pack, launch, adapter) {
724
735
  finally {
725
736
  if (state.busy === "implement")
726
737
  state.busy = null;
727
- if (state.implementLaunch === launch)
738
+ if (state.implementLaunch === launch || !current)
728
739
  state.implementLaunch = null;
729
740
  }
730
741
  }
@@ -765,7 +776,7 @@ async function runAuthor(state, pack, launch, adapter) {
765
776
  function discardedLaunch(state, channel) {
766
777
  if (channel === "author")
767
778
  return state.authorLaunch;
768
- if (channel === "implement")
779
+ if (channel === "implement" || channel === "plan")
769
780
  return state.implementLaunch;
770
781
  return state.implementLaunch;
771
782
  }
package/dist/stages.js CHANGED
@@ -45,6 +45,11 @@ export const SECTION_PURPOSES = {
45
45
  "Open questions": "Optional. Unresolved questions for the owner.",
46
46
  Entities: "Optional. Named things the spec talks about.",
47
47
  "UI notes": "Optional. Presentation hints that are not rules.",
48
+ Definitions: "Optional glossary. Not business rules.",
49
+ "Data Definition": "Optional. Records, uniqueness, derived fields — not behaviour.",
50
+ "Verification Scenarios": "Optional. How a person would check the pack.",
51
+ "Related Requirements": "Optional pointers to other packs. Do not restate this pack's rules.",
52
+ "Implementation Notes": "Optional builder hints. No hidden acceptance criteria.",
48
53
  };
49
54
  export function sectionCatalog() {
50
55
  return [
@@ -229,7 +234,13 @@ export function computeStages(health, ready) {
229
234
  const buildAction = implementOwned
230
235
  ? {
231
236
  id: "implement",
232
- label: health.build.state === "running" ? "Implementing" : neverSucceeded ? "Implement" : "Reimplement",
237
+ label: health.build.state === "running"
238
+ ? health.build.phase === "plan"
239
+ ? "Planning"
240
+ : "Implementing"
241
+ : neverSucceeded
242
+ ? "Implement"
243
+ : "Reimplement",
233
244
  enabled: readyOk && health.build.state !== "running" && !needsStack,
234
245
  hint: needsStack
235
246
  ? STACK_CHOICE_HINT
@@ -238,7 +249,7 @@ export function computeStages(health, ready) {
238
249
  : health.build.state === "failed"
239
250
  ? health.build.message
240
251
  : neverSucceeded
241
- ? `Starts a ${agent} agent with derived/implement-brief.md.`
252
+ ? `Plans this pass, then starts a ${agent} agent with derived/implement-brief.md.`
242
253
  : health.build.message,
243
254
  }
244
255
  : {
@@ -0,0 +1,20 @@
1
+ import type { Req0Config } from "./types.js";
2
+ export declare const STANDARDS_CONVENTION_DIR = "docs/requirement-standards";
3
+ export declare const STANDARDS_PACK_FILE = "pack.md";
4
+ export declare const STANDARDS_DOCUMENT_FILE = "document.md";
5
+ export declare const CONVENTION_PACK_REL: string;
6
+ export declare const CONVENTION_DOCUMENT_REL: string;
7
+ export declare const PACKAGE_PACK_STANDARD: string;
8
+ export declare const PACKAGE_DOCUMENT_STANDARD: string;
9
+ export type StandardsSource = "config" | "convention" | "package";
10
+ export type ResolvedStandardFile = {
11
+ path: string;
12
+ source: StandardsSource;
13
+ text: string;
14
+ };
15
+ export type LoadedStandards = {
16
+ pack: ResolvedStandardFile;
17
+ document: ResolvedStandardFile;
18
+ };
19
+ export declare function loadStandards(repoRoot: string | null, config?: Req0Config | null): Promise<LoadedStandards>;
20
+ export declare function standardsBriefSection(standards: LoadedStandards | null | undefined): string[];