@juicesharp/rpiv-pi 2.2.0 → 2.3.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 +9 -8
- package/docs/lanes.md +3 -2
- package/docs/models-config.md +6 -6
- package/docs/workflows.md +4 -18
- package/extensions/rpiv-core/artifact-collector.ts +2 -2
- package/extensions/rpiv-core/built-in-workflows.ts +251 -365
- package/extensions/rpiv-core/index.ts +2 -2
- package/extensions/rpiv-core/lane-console.ts +62 -5
- package/extensions/rpiv-core/lane-list.ts +79 -3
- package/extensions/rpiv-core/lane-progress.ts +8 -1
- package/extensions/rpiv-core/lane-switcher.ts +114 -33
- package/extensions/rpiv-core/lane-usage.ts +25 -0
- package/extensions/rpiv-core/models-config-validate.ts +1 -1
- package/extensions/rpiv-core/models-config.ts +3 -3
- package/extensions/rpiv-core/register-built-in-workflows.ts +2 -2
- package/extensions/rpiv-core/run-lane-registry.ts +80 -4
- package/extensions/rpiv-core/sdk-workflow-host.ts +39 -3
- package/extensions/rpiv-core/subagent-usage.ts +147 -0
- package/package.json +3 -3
- package/skills/blueprint/SKILL.md +1 -1
- package/skills/discover/SKILL.md +1 -1
- package/skills/elaborate/SKILL.md +14 -14
- package/skills/grade/SKILL.md +6 -5
- package/skills/implement/SKILL.md +1 -1
- package/skills/plan/SKILL.md +1 -1
- package/skills/slice/SKILL.md +1 -1
- package/skills/synthesize/SKILL.md +2 -2
|
@@ -50,8 +50,8 @@ import { rpivBucketOutcome } from "./artifact-collector.js";
|
|
|
50
50
|
// code-review stage sources it from the skill's contract `produces.data`
|
|
51
51
|
// (`blockers_count` required), validated by the runtime output loop via
|
|
52
52
|
// `effectiveOutputSchema`. One source of truth, in the skill, not copy-pasted
|
|
53
|
-
// per workflow. Every workflow —
|
|
54
|
-
// same numeric gate: `gate("blockers_count", { <fix>: gt(0), commit: eq(0) }, "commit")`.
|
|
53
|
+
// per workflow. Every workflow with a `code-review` stage — polish AND vet —
|
|
54
|
+
// routes on the same numeric gate: `gate("blockers_count", { <fix>: gt(0), commit: eq(0) }, "commit")`.
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
57
|
* A plan's structured `phases:` frontmatter array — the machine-readable phase
|
|
@@ -320,7 +320,7 @@ const unionDeclaredWriteSet = (
|
|
|
320
320
|
* latest plan published to the named `"plans"` channel. Sourcing from the named
|
|
321
321
|
* channel (not the rolling primary) makes the stage's `reads: ["plans"]`
|
|
322
322
|
* declaration semantically honest. Used by every workflow whose `implement`
|
|
323
|
-
* inherits one plan (
|
|
323
|
+
* inherits one plan (build/vet); polish's accumulating multi-plan
|
|
324
324
|
* variant is `PLANS_PHASE_FANOUT`.
|
|
325
325
|
*/
|
|
326
326
|
const FRONTMATTER_PHASE_FANOUT = fanout({
|
|
@@ -338,25 +338,6 @@ const FRONTMATTER_PHASE_FANOUT = fanout({
|
|
|
338
338
|
},
|
|
339
339
|
});
|
|
340
340
|
|
|
341
|
-
/**
|
|
342
|
-
* `implement`'s serial twin of `FRONTMATTER_PHASE_FANOUT`, for plans that do NOT
|
|
343
|
-
* declare a per-phase write set. `concurrency: 1` serializes the units in the
|
|
344
|
-
* plan's (topological) phase order — the safe model when a fanout's units share a
|
|
345
|
-
* working tree AND their write-sets are unknown (so the scheduler cannot derive
|
|
346
|
-
* dep edges and the lane has no scope floor to guard it). `elaborate` keeps the
|
|
347
|
-
* parallel fanout: it writes ISOLATED per-phase docs.
|
|
348
|
-
*
|
|
349
|
-
* When a plan DOES declare per-phase `files:`, prefer `IMPLEMENT_DAG_FANOUT`:
|
|
350
|
-
* its `implementPhaseDeps` derives dep edges from write-set overlap (units with
|
|
351
|
-
* disjoint `files:` run concurrently; a `files:`-less phase conflicts with every
|
|
352
|
-
* lower phase, degrading to the full chain — one phase per wave — so the
|
|
353
|
-
* all-`files:`-less plan stays serial at any cap), and a lane-level scope floor
|
|
354
|
-
* guards the declared set. Used today by ship/arch (vet moves to the DAG variant
|
|
355
|
-
* once it carries `files:`); `IMPLEMENT_DAG_FANOUT`'s `concurrency: 1` is dropped
|
|
356
|
-
* once build's scope floor lands.
|
|
357
|
-
*/
|
|
358
|
-
const IMPLEMENT_PHASE_FANOUT = { ...FRONTMATTER_PHASE_FANOUT, concurrency: 1 };
|
|
359
|
-
|
|
360
341
|
/**
|
|
361
342
|
* Derive the directed `deps` edges for ONE implement phase under the dep-gated
|
|
362
343
|
* DAG fanout (`IMPLEMENT_DAG_FANOUT`). Edges point strictly downward (toward
|
|
@@ -376,7 +357,10 @@ const IMPLEMENT_PHASE_FANOUT = { ...FRONTMATTER_PHASE_FANOUT, concurrency: 1 };
|
|
|
376
357
|
* runtime closure, so no TDZ (same pattern as `sliceDeps`).
|
|
377
358
|
*/
|
|
378
359
|
const implementPhaseDeps = (records: readonly PhaseRecord[], self: PhaseRecord): string[] => {
|
|
379
|
-
|
|
360
|
+
// Twin-expanded (`withTestTwins`) so a phase declaring `x.ts` conflicts with
|
|
361
|
+
// one declaring `x.test.ts` — the production phase's implicit twin write would
|
|
362
|
+
// otherwise race a concurrent sibling that owns the test explicitly.
|
|
363
|
+
const selfFiles = withTestTwins(phaseFiles(self.entry));
|
|
380
364
|
const explicit = phaseDeps(self.entry);
|
|
381
365
|
const ns = new Set<number>();
|
|
382
366
|
for (const e of explicit) if (e < self.n) ns.add(e);
|
|
@@ -387,7 +371,7 @@ const implementPhaseDeps = (records: readonly PhaseRecord[], self: PhaseRecord):
|
|
|
387
371
|
// clause A — overlap on ≥1 declared write path.
|
|
388
372
|
for (const r of records) {
|
|
389
373
|
if (r.n >= self.n) continue;
|
|
390
|
-
const rFiles = phaseFiles(r.entry);
|
|
374
|
+
const rFiles = withTestTwins(phaseFiles(r.entry));
|
|
391
375
|
if (rFiles.some((f) => selfFiles.includes(f))) ns.add(r.n);
|
|
392
376
|
}
|
|
393
377
|
}
|
|
@@ -402,8 +386,9 @@ const implementPhaseDeps = (records: readonly PhaseRecord[], self: PhaseRecord):
|
|
|
402
386
|
* `units` closure emits the SAME `prompt`/`label` strings AND adds
|
|
403
387
|
* `id: \`phase-${r.n}\`` + `deps: implementPhaseDeps(records, r)`. NO
|
|
404
388
|
* `depArtifactFlag` — implement phases feed each other through the working tree
|
|
405
|
-
* (not published artifacts), so `deps` drive ONLY wave ordering.
|
|
406
|
-
*
|
|
389
|
+
* (not published artifacts), so `deps` drive ONLY wave ordering. NO
|
|
390
|
+
* `concurrency` property is set (the spread overrides only `units`), so the loop
|
|
391
|
+
* inherits the host cap and phases fan out concurrently, bounded by `deps`.
|
|
407
392
|
*/
|
|
408
393
|
const IMPLEMENT_DAG_FANOUT = {
|
|
409
394
|
...FRONTMATTER_PHASE_FANOUT,
|
|
@@ -420,66 +405,6 @@ const IMPLEMENT_DAG_FANOUT = {
|
|
|
420
405
|
},
|
|
421
406
|
};
|
|
422
407
|
|
|
423
|
-
// ===========================================================================
|
|
424
|
-
// ship — blueprint → implement → validate → commit
|
|
425
|
-
// ===========================================================================
|
|
426
|
-
|
|
427
|
-
const shipWorkflow = defineWorkflow({
|
|
428
|
-
name: "ship",
|
|
429
|
-
description:
|
|
430
|
-
"Fast path with no research or review. Best when the change is small and the approach is obvious. Chain: blueprint → implement → validate → commit.",
|
|
431
|
-
start: "blueprint",
|
|
432
|
-
stages: {
|
|
433
|
-
blueprint: produces(),
|
|
434
|
-
implement: acts({ loop: IMPLEMENT_PHASE_FANOUT, reads: ["plans"] }),
|
|
435
|
-
validate: produces(),
|
|
436
|
-
commit: acts({ outcome: gitCommitOutcome }),
|
|
437
|
-
},
|
|
438
|
-
edges: {
|
|
439
|
-
blueprint: "implement",
|
|
440
|
-
implement: "validate",
|
|
441
|
-
validate: "commit",
|
|
442
|
-
commit: "stop",
|
|
443
|
-
},
|
|
444
|
-
});
|
|
445
|
-
|
|
446
|
-
// ===========================================================================
|
|
447
|
-
// arch — research → design → plan → implement → validate → code-review →
|
|
448
|
-
// (design → loop) | commit
|
|
449
|
-
// Loops the full design/plan/implement/validate/review chain until
|
|
450
|
-
// code-review reports zero blockers, bounded by the runner's
|
|
451
|
-
// maxBackwardJumps (default 2 → up to 3 review iterations).
|
|
452
|
-
// ===========================================================================
|
|
453
|
-
|
|
454
|
-
const archWorkflow = defineWorkflow({
|
|
455
|
-
name: "arch",
|
|
456
|
-
description:
|
|
457
|
-
"Design-led pipeline for complex changes touching many files or layers. Best when the approach itself needs to be worked out before planning. Chain: research → design → plan → implement → validate → code-review → (design loop) → commit.",
|
|
458
|
-
start: "research",
|
|
459
|
-
stages: {
|
|
460
|
-
research: produces(),
|
|
461
|
-
design: produces(),
|
|
462
|
-
plan: produces(),
|
|
463
|
-
implement: acts({ loop: IMPLEMENT_PHASE_FANOUT, reads: ["plans"] }),
|
|
464
|
-
validate: produces(),
|
|
465
|
-
"code-review": produces(),
|
|
466
|
-
commit: acts({ outcome: gitCommitOutcome }),
|
|
467
|
-
},
|
|
468
|
-
edges: {
|
|
469
|
-
research: "design",
|
|
470
|
-
design: "plan",
|
|
471
|
-
plan: "implement",
|
|
472
|
-
implement: "validate",
|
|
473
|
-
validate: "code-review",
|
|
474
|
-
// Backward edge: code-review → design re-enters the full
|
|
475
|
-
// design/plan/implement/validate/review cycle. Bounded by the
|
|
476
|
-
// runner's default maxBackwardJumps (2), permitting at most 3
|
|
477
|
-
// review iterations before the guard halts.
|
|
478
|
-
"code-review": gate("blockers_count", { design: gt(0), commit: eq(0) }, "commit"),
|
|
479
|
-
commit: "stop",
|
|
480
|
-
},
|
|
481
|
-
});
|
|
482
|
-
|
|
483
408
|
// ===========================================================================
|
|
484
409
|
// polish — architecture-review → blueprint (iterate, per review phase) →
|
|
485
410
|
// implement → validate → code-review → (blueprint loop) | commit
|
|
@@ -540,6 +465,33 @@ const phaseFiles = (entry: unknown): string[] => {
|
|
|
540
465
|
return Array.isArray(raw) ? raw.filter((f): f is string => typeof f === "string") : [];
|
|
541
466
|
};
|
|
542
467
|
|
|
468
|
+
/**
|
|
469
|
+
* Expand a declared write-set with each production file's co-located test twin
|
|
470
|
+
* (`x.ts → x.test.ts`, likewise tsx/js/jsx). This monorepo's tests are
|
|
471
|
+
* compile-coupled siblings — widening a declared file's signature forces the
|
|
472
|
+
* mechanical follow-up edit in its twin — so requiring every plan author,
|
|
473
|
+
* elaborator, and grader to re-declare the twin is paperwork the convention
|
|
474
|
+
* already guarantees (a live run STOPPED at the scope floor over exactly this:
|
|
475
|
+
* a declared `lane-switcher.ts` signature change whose five-assertion twin fix
|
|
476
|
+
* was undeclared prose). Applied at BOTH consumers of the declared set — the
|
|
477
|
+
* DAG conflict fold (`implementPhaseDeps`) and the scope floors — so the
|
|
478
|
+
* planner and the floor can never disagree; on the DAG side it also closes the
|
|
479
|
+
* latent race where phases declaring `x.ts` and `x.test.ts` counted as
|
|
480
|
+
* disjoint yet predictably collide. Asymmetric by design: declaring a TEST
|
|
481
|
+
* file licenses nothing extra — production writes remain the act that must be
|
|
482
|
+
* declared, and a write to a non-twin test still fails the floor. A file
|
|
483
|
+
* already matching `TEST_PATH_RE` maps to itself (no `x.test.test.ts`).
|
|
484
|
+
*/
|
|
485
|
+
const withTestTwins = (files: readonly string[]): string[] => {
|
|
486
|
+
const out = new Set(files);
|
|
487
|
+
for (const f of files) {
|
|
488
|
+
if (TEST_PATH_RE.test(f)) continue;
|
|
489
|
+
const twin = f.replace(/\.([tj]sx?)$/, ".test.$1");
|
|
490
|
+
if (twin !== f) out.add(twin);
|
|
491
|
+
}
|
|
492
|
+
return [...out];
|
|
493
|
+
};
|
|
494
|
+
|
|
543
495
|
/**
|
|
544
496
|
* Per-review-phase blueprint generator (the `iterate` dual of
|
|
545
497
|
* FRONTMATTER_PHASE_FANOUT). One blueprint pass per review phase, enumerating the
|
|
@@ -666,7 +618,7 @@ const PLANS_PHASE_FANOUT = fanout({
|
|
|
666
618
|
},
|
|
667
619
|
});
|
|
668
620
|
|
|
669
|
-
/** `implement`'s serial twin of `PLANS_PHASE_FANOUT` (polish's multi-plan variant) —
|
|
621
|
+
/** `implement`'s serial twin of `PLANS_PHASE_FANOUT` (polish's multi-plan variant) — serialized (`concurrency: 1`) because the fanout's units share a working tree and their write-sets are unknown, so the scheduler cannot derive dep edges (no scope floor guards it). */
|
|
670
622
|
const IMPLEMENT_PLANS_FANOUT = { ...PLANS_PHASE_FANOUT, concurrency: 1 };
|
|
671
623
|
|
|
672
624
|
/**
|
|
@@ -716,7 +668,7 @@ const polishWorkflow = defineWorkflow({
|
|
|
716
668
|
// → slice-design (fanout) → design-review (one human checkpoint) →
|
|
717
669
|
// subplan (cluster fanout) → plan → plan-grade (plan-fix loop) →
|
|
718
670
|
// code (fanout) → code-splice → code-grade (code-fix loop) →
|
|
719
|
-
// implement → validate → commit
|
|
671
|
+
// implement → implement-scope-check → reconcile → validate → commit
|
|
720
672
|
// The sliced, panel-gated heavy path: capture the user's brief verbatim as the
|
|
721
673
|
// `goal` channel (the north star the judgment seams — the two grade panels'
|
|
722
674
|
// completeness/correctness dimensions and validate — anchor against), research
|
|
@@ -735,7 +687,6 @@ const polishWorkflow = defineWorkflow({
|
|
|
735
687
|
// (per-cluster sub-plans → one plan) so no pass holds every design, gate the
|
|
736
688
|
// plan on quality dimensions BEFORE any code, elaborate code per phase and
|
|
737
689
|
// splice it in, re-grade the code-bearing plan, then implement/validate/commit.
|
|
738
|
-
// The parallel generalization of `arch`.
|
|
739
690
|
// ===========================================================================
|
|
740
691
|
|
|
741
692
|
/**
|
|
@@ -1433,12 +1384,17 @@ type FsHandle = { kind: "fs"; path: string };
|
|
|
1433
1384
|
* passes a `pass:false` verdict rated `low`/`none`; a structural defect MUST
|
|
1434
1385
|
* rate `high` or it ships. The `score` is the binary verdict scale (100 = clean,
|
|
1435
1386
|
* 0 = finding; the gate keys off `severity`, never this number).
|
|
1387
|
+
*
|
|
1388
|
+
* `extra` lets a caller stamp additional gate-readable fields onto the verdict
|
|
1389
|
+
* data (and the persisted JSON, so the trail records them) — currently only
|
|
1390
|
+
* `sliceStructureCheck`'s `citeDischarged` stamp.
|
|
1436
1391
|
*/
|
|
1437
1392
|
const writeStructureVerdict = (
|
|
1438
1393
|
who: string,
|
|
1439
1394
|
handle: FsHandle,
|
|
1440
1395
|
findings: StructureFinding[],
|
|
1441
1396
|
cwd: string,
|
|
1397
|
+
extra?: Record<string, unknown>,
|
|
1442
1398
|
): Omit<Output, "meta"> => {
|
|
1443
1399
|
const pass = findings.length === 0;
|
|
1444
1400
|
const data = {
|
|
@@ -1449,6 +1405,7 @@ const writeStructureVerdict = (
|
|
|
1449
1405
|
artifact: handleToString(handle),
|
|
1450
1406
|
findings,
|
|
1451
1407
|
feedback: pass ? "" : findings.map((f) => f.detail).join(" "),
|
|
1408
|
+
...extra,
|
|
1452
1409
|
};
|
|
1453
1410
|
const rel = join(VERDICT_DIR, `${who}__${basename(handle.path, ".md")}.json`);
|
|
1454
1411
|
mkdirSync(join(cwd, VERDICT_DIR), { recursive: true });
|
|
@@ -1456,6 +1413,95 @@ const writeStructureVerdict = (
|
|
|
1456
1413
|
return { kind: "json", artifacts: [{ handle: { kind: "fs", path: rel } }], data };
|
|
1457
1414
|
};
|
|
1458
1415
|
|
|
1416
|
+
/**
|
|
1417
|
+
* A citation string occurs LIVE in the slice-map text — outside fenced spans
|
|
1418
|
+
* and not as half of an `old→new` refresh-note pair. A re-slice's revision
|
|
1419
|
+
* note legitimately QUOTES the citations it refreshed (contract: only as
|
|
1420
|
+
* arrow pairs or inside a fence — see the slice skill's re-slice mode);
|
|
1421
|
+
* treating a quoted old citation as still-live would forfeit every documented
|
|
1422
|
+
* refresh's discharge, and treating a quoted new one as present would credit
|
|
1423
|
+
* a fix that never touched the live `Draws on` lines.
|
|
1424
|
+
*/
|
|
1425
|
+
const citeOccursLive = (body: string, spans: readonly [number, number][], cite: string): boolean => {
|
|
1426
|
+
for (let i = body.indexOf(cite); i !== -1; i = body.indexOf(cite, i + 1)) {
|
|
1427
|
+
if (spans.some(([s, e]) => i >= s && i < e)) continue;
|
|
1428
|
+
if (body.startsWith("→", i + cite.length)) continue;
|
|
1429
|
+
if (body.endsWith("→", i)) continue;
|
|
1430
|
+
return true;
|
|
1431
|
+
}
|
|
1432
|
+
return false;
|
|
1433
|
+
};
|
|
1434
|
+
|
|
1435
|
+
/**
|
|
1436
|
+
* One cite-remedy finding is satisfied by the slice-map text: the demanded
|
|
1437
|
+
* seed's path occurs live — line suffixes are stripped before matching,
|
|
1438
|
+
* because the fix may cite a corrected range and the citation floor
|
|
1439
|
+
* (`verifyCitations`) verifies whatever range it actually wrote. `Draws on`
|
|
1440
|
+
* and `Out of scope` both satisfy the remedy, so a live occurrence anywhere
|
|
1441
|
+
* in the map is the contract. (The former REFRESH mode — a `stale` drifted
|
|
1442
|
+
* line number to replace — was removed with anchor-precision grading: a
|
|
1443
|
+
* drifted line number is no longer a finding, so nothing demands a refresh.)
|
|
1444
|
+
*
|
|
1445
|
+
* A finding without a concrete string `requires` is unverifiable ⇒ not satisfied.
|
|
1446
|
+
*/
|
|
1447
|
+
const citeFindingSatisfied = (
|
|
1448
|
+
mapBody: string,
|
|
1449
|
+
spans: readonly [number, number][],
|
|
1450
|
+
f: { requires?: unknown },
|
|
1451
|
+
): boolean =>
|
|
1452
|
+
typeof f.requires === "string" &&
|
|
1453
|
+
f.requires.length > 0 &&
|
|
1454
|
+
citeOccursLive(mapBody, spans, f.requires.replace(/:\d[-\d,:]*$/, ""));
|
|
1455
|
+
|
|
1456
|
+
/**
|
|
1457
|
+
* Structural fingerprint of one slice-map round: the `slices` + `coverage`
|
|
1458
|
+
* frontmatter it published on the `slices` channel — no file re-read.
|
|
1459
|
+
* `undefined` when the round carried no `slices` data; a caller must treat
|
|
1460
|
+
* that as "cannot compare", never as "unchanged".
|
|
1461
|
+
*/
|
|
1462
|
+
const sliceShape = (round: Output | undefined): string | undefined => {
|
|
1463
|
+
const d = round?.data as { slices?: unknown; coverage?: unknown } | undefined;
|
|
1464
|
+
return d?.slices === undefined ? undefined : JSON.stringify({ slices: d.slices, coverage: d.coverage ?? null });
|
|
1465
|
+
};
|
|
1466
|
+
|
|
1467
|
+
/** The verdict fields the cite-only discharge consults. */
|
|
1468
|
+
type CiteRemedyVerdict = {
|
|
1469
|
+
pass?: boolean;
|
|
1470
|
+
remedy?: string;
|
|
1471
|
+
findings?: readonly { requires?: unknown }[];
|
|
1472
|
+
};
|
|
1473
|
+
|
|
1474
|
+
/**
|
|
1475
|
+
* Deterministic discharge of a CITE-ONLY `design-readiness` fail — the middle
|
|
1476
|
+
* case between "carry a passing verdict" (impossible on the slice gate: its
|
|
1477
|
+
* lone dimension failed) and "buy a full re-grade panel" (wasteful when the
|
|
1478
|
+
* grader already named the exact citations to add or refresh). A fix that
|
|
1479
|
+
* also restructured forfeits the discharge and takes the normal re-grade.
|
|
1480
|
+
*/
|
|
1481
|
+
const citeRemedyDischarged = (state: RunView, mapBody: string): boolean => {
|
|
1482
|
+
const verdict = latestVerdictPerDimension(state.named["slice-verdicts"]).get("design-readiness");
|
|
1483
|
+
const v = verdict?.data as CiteRemedyVerdict | undefined;
|
|
1484
|
+
if (v?.pass !== false || v.remedy !== "cite") return false;
|
|
1485
|
+
// A fix must have LANDED since the verdict — discharging the judged map
|
|
1486
|
+
// unchanged would contradict the grader, who read it and found the cites
|
|
1487
|
+
// wrong. Basename inequality cannot witness the fix (a re-slice may
|
|
1488
|
+
// legitimately edit the map in place); publication order can: the latest
|
|
1489
|
+
// `slices` round must postdate the verdict.
|
|
1490
|
+
const entries = state.named.slices ?? [];
|
|
1491
|
+
const verdictTs = verdict?.meta?.ts;
|
|
1492
|
+
const currentTs = entries.at(-1)?.meta?.ts;
|
|
1493
|
+
if (typeof verdictTs !== "string" || typeof currentTs !== "string" || currentTs <= verdictTs) return false;
|
|
1494
|
+
const findings = Array.isArray(v.findings) ? v.findings : [];
|
|
1495
|
+
if (findings.length === 0) return false;
|
|
1496
|
+
const spans = fencedSpans(mapBody);
|
|
1497
|
+
if (!findings.every((f) => f != null && citeFindingSatisfied(mapBody, spans, f))) return false;
|
|
1498
|
+
// Shape must match the round the grader judged — located by publication
|
|
1499
|
+
// order, not filename, for the same in-place reason.
|
|
1500
|
+
const judged = [...entries].reverse().find((s) => typeof s.meta?.ts === "string" && s.meta.ts <= verdictTs);
|
|
1501
|
+
const judgedShape = sliceShape(judged);
|
|
1502
|
+
return judgedShape !== undefined && judgedShape === sliceShape(entries.at(-1));
|
|
1503
|
+
};
|
|
1504
|
+
|
|
1459
1505
|
/**
|
|
1460
1506
|
* Deterministic Phase-1 slice-check — the un-gameable floor beneath the LLM
|
|
1461
1507
|
* `design-readiness` panel. It enforces the invariants a prose grader cannot
|
|
@@ -1519,7 +1565,15 @@ const sliceStructureCheck = ({ state, cwd }: ScriptContext): Omit<Output, "meta"
|
|
|
1519
1565
|
// Citation backing — every file:line the map cites must resolve.
|
|
1520
1566
|
findings.push(...verifyCitations(mapBody, cwd));
|
|
1521
1567
|
|
|
1522
|
-
|
|
1568
|
+
// Stamp the cite-only discharge ONLY on a green floor: structure clean +
|
|
1569
|
+
// citation backing verified + demanded seeds present + shape unchanged is
|
|
1570
|
+
// exactly what a fresh design-readiness pass on this map would re-establish,
|
|
1571
|
+
// so the `sliceGatePasses` skip stays provably equivalent to "re-grade, then pass".
|
|
1572
|
+
const discharge =
|
|
1573
|
+
findings.length === 0 && citeRemedyDischarged(state, mapBody)
|
|
1574
|
+
? { citeDischarged: basename(latest.handle.path) }
|
|
1575
|
+
: undefined;
|
|
1576
|
+
return writeStructureVerdict("slice-check", latest.handle, findings, cwd, discharge);
|
|
1523
1577
|
};
|
|
1524
1578
|
|
|
1525
1579
|
/**
|
|
@@ -1904,11 +1958,6 @@ const planCitationCheck =
|
|
|
1904
1958
|
// Plan-time coverage floor: a body edit not declared in its phase's `files:`
|
|
1905
1959
|
// fails structurally, same channel/verdict/route as an unbacked citation.
|
|
1906
1960
|
findings.push(...verifyPhaseFilesCoverage(body, who, latest.handle.path));
|
|
1907
|
-
// AV exit-0 contract floor: an Automated Verification line reconcile's
|
|
1908
|
-
// deterministic re-run can never honor (stdin-reading grep, absence-assertion
|
|
1909
|
-
// prose, out-of-scope Biome paths, unparseable span) fails HERE — into the
|
|
1910
|
-
// plan-fix loop — instead of at reconcile, whose fail route is STOP.
|
|
1911
|
-
findings.push(...verifyAvCommandContract(body));
|
|
1912
1961
|
return writeStructureVerdict(who, latest.handle, findings, cwd);
|
|
1913
1962
|
};
|
|
1914
1963
|
|
|
@@ -2048,7 +2097,8 @@ const codeDemote = demoteDuties("code-demote", "plans", "code-verdicts");
|
|
|
2048
2097
|
* LLM quality gates. After build's `implement` lane runs (now dep-gated and, as
|
|
2049
2098
|
* of this phase's unpin, concurrent up to the host cap), this checks the working
|
|
2050
2099
|
* tree's dirty set against the plan's declared write-set (the union of every
|
|
2051
|
-
* phase's `files
|
|
2100
|
+
* phase's `files:`, twin-expanded via `withTestTwins`): any dirty path the run
|
|
2101
|
+
* wrote that is NOT in `declared`, NOT
|
|
2052
2102
|
* pre-existing at the run-start baseline, and NOT under a bookkeeping tree is a
|
|
2053
2103
|
* scope violation — a phase escaped the upstream write-scope discipline and
|
|
2054
2104
|
* rewrote the wider tree, corrupting (or about to corrupt) a concurrent
|
|
@@ -2090,9 +2140,11 @@ const implementScopeCheck = ({ state, cwd }: ScriptContext): Omit<Output, "meta"
|
|
|
2090
2140
|
}
|
|
2091
2141
|
const body = readArtifactFile(latest.handle.path, cwd);
|
|
2092
2142
|
const records = planPhaseRecords(body, "implement-scope-check", latest.handle.path);
|
|
2093
|
-
// Declared write-set = union of every phase's `files:` (via `phaseFiles`)
|
|
2143
|
+
// Declared write-set = union of every phase's `files:` (via `phaseFiles`),
|
|
2144
|
+
// expanded with co-located test twins (`withTestTwins`) — a signature change
|
|
2145
|
+
// in a declared file legitimately drags its twin's assertions along.
|
|
2094
2146
|
// A `files:`-less plan yields `[]` ⇒ `scopeExcess` returns `[]` ⇒ inert floor.
|
|
2095
|
-
const declared = records.flatMap((r) => phaseFiles(r.entry));
|
|
2147
|
+
const declared = withTestTwins(records.flatMap((r) => phaseFiles(r.entry)));
|
|
2096
2148
|
|
|
2097
2149
|
// Run-start baseline (goal channel, role "baseline") + current dirty set —
|
|
2098
2150
|
// both best-effort (absent / non-repo ⇒ `[]`); see the two helpers' docs.
|
|
@@ -2171,8 +2223,9 @@ const implementScopeCheckVet = ({ state, cwd }: ScriptContext): Omit<Output, "me
|
|
|
2171
2223
|
|
|
2172
2224
|
// Shared core: subtract the run's bookkeeping dirs (`.rpiv/`,
|
|
2173
2225
|
// `thoughts/`) and the run-start baseline; empty-`declared` ⇒ `[]` (degradation
|
|
2174
|
-
// ⇒ inert floor — a fully `files:`-less plan never false-fails).
|
|
2175
|
-
|
|
2226
|
+
// ⇒ inert floor — a fully `files:`-less plan never false-fails). Twin-expanded
|
|
2227
|
+
// like build's floor: a declared file carries its co-located test twin.
|
|
2228
|
+
const excess = scopeExcess(dirty, baseline, withTestTwins([...declared]));
|
|
2176
2229
|
const findings = excess.map((p) => ({
|
|
2177
2230
|
detail: `${p}: written by the implement lane but not declared in any plan iteration's \`files:\` set. A phase may write only its declared paths (the write-scope rule); declare the path in the owning phase's \`files:\` or drop the write.`,
|
|
2178
2231
|
where: p,
|
|
@@ -2268,42 +2321,6 @@ const reconciliationRecords = (
|
|
|
2268
2321
|
return { directives, malformed };
|
|
2269
2322
|
};
|
|
2270
2323
|
|
|
2271
|
-
/** Checkbox-AV line: `- [ ] `<command>`` or `- [x] `<command>``. The first
|
|
2272
|
-
* backtick-wrapped span is the command; prose backticks after it are ignored. */
|
|
2273
|
-
const AV_COMMAND_LINE_RE = /^-\s+\[[ xX]\]\s*`([^`]+)`/;
|
|
2274
|
-
|
|
2275
|
-
/**
|
|
2276
|
-
* Extract every per-phase `#### Automated Verification:` line from a plan body —
|
|
2277
|
-
* both `- [ ]` (pending) and `- [x]` (checked) — as `{ command, tail }`:
|
|
2278
|
-
* `command` is the first backtick span (the ONLY part `reconcile` executes),
|
|
2279
|
-
* `tail` is the prose after it (never executed — `verifyAvCommandContract`
|
|
2280
|
-
* lints it for semantics the exit-0 re-run cannot honor). A section opens at a
|
|
2281
|
-
* `#### Automated Verification:` heading and closes at the next `#{1,4}` heading.
|
|
2282
|
-
* Pure: no I/O, no throw.
|
|
2283
|
-
*/
|
|
2284
|
-
const planVerificationRecords = (body: string): { command: string; tail: string }[] => {
|
|
2285
|
-
const records: { command: string; tail: string }[] = [];
|
|
2286
|
-
let inSection = false;
|
|
2287
|
-
for (const raw of body.split("\n")) {
|
|
2288
|
-
const line = raw.trimEnd();
|
|
2289
|
-
if (/^####\s+Automated Verification\b/.test(line)) {
|
|
2290
|
-
inSection = true;
|
|
2291
|
-
continue;
|
|
2292
|
-
}
|
|
2293
|
-
if (/^#{1,4}\s/.test(line)) {
|
|
2294
|
-
inSection = false;
|
|
2295
|
-
continue;
|
|
2296
|
-
}
|
|
2297
|
-
if (!inSection) continue;
|
|
2298
|
-
const m = AV_COMMAND_LINE_RE.exec(line);
|
|
2299
|
-
if (m) records.push({ command: m[1]!.trim(), tail: line.slice(m[0]!.length) });
|
|
2300
|
-
}
|
|
2301
|
-
return records;
|
|
2302
|
-
};
|
|
2303
|
-
|
|
2304
|
-
/** The command strings alone — `reconcile` re-runs each via `execFileSync`, fail-soft. */
|
|
2305
|
-
const planVerificationCommands = (body: string): string[] => planVerificationRecords(body).map((r) => r.command);
|
|
2306
|
-
|
|
2307
2324
|
/**
|
|
2308
2325
|
* The reconcile write-restriction's static allowlist — a conservative test-path
|
|
2309
2326
|
* classifier. A directive may apply its `find → replace` ONLY to a co-located test
|
|
@@ -2316,161 +2333,6 @@ const planVerificationCommands = (body: string): string[] => planVerificationRec
|
|
|
2316
2333
|
const TEST_PATH_RE = /\.test\.[tj]sx?$/;
|
|
2317
2334
|
const isTestPath = (target: string): boolean => TEST_PATH_RE.test(target);
|
|
2318
2335
|
|
|
2319
|
-
/**
|
|
2320
|
-
* Split an AV command string into `{ exe, args }` for `execFileSync`, honoring
|
|
2321
|
-
* single/double quotes (so `grep -niE "a|b" x` tokenizes with the quotes stripped
|
|
2322
|
-
* and `node -e "process.exit(1)"` keeps `process.exit(1)` as one arg). Returns
|
|
2323
|
-
* `null` for an empty/whitespace command or an unterminated quote (caller flags
|
|
2324
|
-
* it). Minimal — no globbing, env expansion, or shell operators; AV commands are
|
|
2325
|
-
* simple invocations.
|
|
2326
|
-
*/
|
|
2327
|
-
const parseShellCommand = (cmd: string): { exe: string; args: string[] } | null => {
|
|
2328
|
-
const tokens: string[] = [];
|
|
2329
|
-
let cur = "";
|
|
2330
|
-
let quote: '"' | "'" | null = null;
|
|
2331
|
-
for (let i = 0; i < cmd.length; i++) {
|
|
2332
|
-
const ch = cmd[i]!;
|
|
2333
|
-
if (quote) {
|
|
2334
|
-
if (ch === quote) quote = null;
|
|
2335
|
-
else cur += ch;
|
|
2336
|
-
} else if (ch === '"' || ch === "'") {
|
|
2337
|
-
quote = ch;
|
|
2338
|
-
} else if (/\s/.test(ch)) {
|
|
2339
|
-
if (cur !== "") {
|
|
2340
|
-
tokens.push(cur);
|
|
2341
|
-
cur = "";
|
|
2342
|
-
}
|
|
2343
|
-
} else {
|
|
2344
|
-
cur += ch;
|
|
2345
|
-
}
|
|
2346
|
-
}
|
|
2347
|
-
if (quote) return null; // unterminated quote — unparseable
|
|
2348
|
-
if (cur !== "") tokens.push(cur);
|
|
2349
|
-
const [exe, ...args] = tokens;
|
|
2350
|
-
return exe ? { exe, args } : null;
|
|
2351
|
-
};
|
|
2352
|
-
|
|
2353
|
-
/** grep-family executables: exit 1 on zero matches AND read stdin when no file
|
|
2354
|
-
* operand is given — both directly at odds with reconcile's exit-0/no-stdin
|
|
2355
|
-
* re-run harness, hence the two grep-specific lint rules below. */
|
|
2356
|
-
const AV_GREP_FAMILY = new Set(["grep", "egrep", "fgrep", "ggrep", "rg"]);
|
|
2357
|
-
/** grep-family flags that CONSUME the next token (so it is not a file operand). */
|
|
2358
|
-
const AV_GREP_VALUE_FLAGS = new Set([
|
|
2359
|
-
"-e",
|
|
2360
|
-
"--regexp",
|
|
2361
|
-
"-f",
|
|
2362
|
-
"--file",
|
|
2363
|
-
"-m",
|
|
2364
|
-
"--max-count",
|
|
2365
|
-
"-A",
|
|
2366
|
-
"-B",
|
|
2367
|
-
"-C",
|
|
2368
|
-
"--include",
|
|
2369
|
-
"--exclude",
|
|
2370
|
-
"--exclude-dir",
|
|
2371
|
-
"-g",
|
|
2372
|
-
"--glob",
|
|
2373
|
-
"-t",
|
|
2374
|
-
"--type",
|
|
2375
|
-
]);
|
|
2376
|
-
/** Absence-assertion prose on a grep-family AV line — "success" is grep exit 1,
|
|
2377
|
-
* the exact inverse of the exit-0 contract. Deliberately a short literal list
|
|
2378
|
-
* of observed absence phrases, not a general negation detector. */
|
|
2379
|
-
const AV_ABSENCE_PROSE_RE = /returns nothing|no matches|no occurrences|is gone|must be gone/i;
|
|
2380
|
-
/** Extensions Biome's config COULD scope (biome.json includes *.ts/*.js + site
|
|
2381
|
-
* css/html). Fail-open: flag a Biome runner only when NO forwarded path can be
|
|
2382
|
-
* in scope (e.g. all-markdown) — "No files were processed" exits 1 under
|
|
2383
|
-
* `--error-on-warnings` regardless of tree state. */
|
|
2384
|
-
const AV_BIOME_SCOPED_PATH_RE = /\.(?:ts|tsx|js|jsx|mjs|cjs|css|html|json|jsonc)$/i;
|
|
2385
|
-
|
|
2386
|
-
/**
|
|
2387
|
-
* Plan-time lint of `#### Automated Verification:` lines against `reconcile`'s
|
|
2388
|
-
* execution contract: reconcile re-runs ONLY the first backtick span of each
|
|
2389
|
-
* checkbox line via `execFileSync` — arg-array (no shell), stdin ignored, exit 0
|
|
2390
|
-
* the sole pass signal — so prose qualifiers around the span never execute.
|
|
2391
|
-
* Folded into `planCitationCheck` (both the `plan-cite-check` and
|
|
2392
|
-
* `code-cite-check` arms) so a violating AV line fails INTO the plan-fix loop,
|
|
2393
|
-
* not at `reconcile` where the route is STOP with no fix arm (an AV line
|
|
2394
|
-
* correct as prose but unsatisfiable as an exit-0 command would halt there).
|
|
2395
|
-
* Narrow by design — each rule targets an observed
|
|
2396
|
-
* false-class, fail-open otherwise; do NOT widen into a general shell linter:
|
|
2397
|
-
* 1. unparseable command (unterminated quote / empty) — reconcile would flag
|
|
2398
|
-
* it anyway; surfacing it here buys a fix round instead of a halt;
|
|
2399
|
-
* 2. grep-family with no file operand — under reconcile's stdin-ignored
|
|
2400
|
-
* harness it scans an empty stream and exits 1 regardless of tree state
|
|
2401
|
-
* (the file argument usually sits in prose OUTSIDE the span);
|
|
2402
|
-
* 3. grep-family whose prose tail asserts absence ("returns nothing") —
|
|
2403
|
-
* success-by-absence IS grep exit 1, the inverse of the contract;
|
|
2404
|
-
* 4. a Biome runner whose forwarded paths are all outside Biome's possible
|
|
2405
|
-
* scope — "No files were processed" exits 1 under `--error-on-warnings`.
|
|
2406
|
-
*/
|
|
2407
|
-
const verifyAvCommandContract = (body: string): { detail: string; where: string }[] => {
|
|
2408
|
-
const findings: { detail: string; where: string }[] = [];
|
|
2409
|
-
for (const { command, tail } of planVerificationRecords(body)) {
|
|
2410
|
-
const parsed = parseShellCommand(command);
|
|
2411
|
-
if (!parsed) {
|
|
2412
|
-
findings.push({
|
|
2413
|
-
detail: `Automated Verification command is unparseable under reconcile's tokenizer (empty or unterminated quote) — \`${command}\`. Reconcile re-runs the first backtick span verbatim via execFileSync; rewrite the span as a single well-quoted command.`,
|
|
2414
|
-
where: command,
|
|
2415
|
-
});
|
|
2416
|
-
continue;
|
|
2417
|
-
}
|
|
2418
|
-
const exe = parsed.exe.split("/").pop() ?? parsed.exe;
|
|
2419
|
-
if (AV_GREP_FAMILY.has(exe)) {
|
|
2420
|
-
// Count file operands: tokens that are not flags and not a value a flag
|
|
2421
|
-
// consumed. With -e/-f the pattern arrives via flag, so EVERY remaining
|
|
2422
|
-
// operand is a file; otherwise the first operand is the pattern.
|
|
2423
|
-
let patternViaFlag = false;
|
|
2424
|
-
const operands: string[] = [];
|
|
2425
|
-
for (let i = 0; i < parsed.args.length; i++) {
|
|
2426
|
-
const a = parsed.args[i]!;
|
|
2427
|
-
if (a === "--") {
|
|
2428
|
-
operands.push(...parsed.args.slice(i + 1));
|
|
2429
|
-
break;
|
|
2430
|
-
}
|
|
2431
|
-
if (a.startsWith("-")) {
|
|
2432
|
-
if (a === "-e" || a === "--regexp" || a === "-f" || a === "--file") patternViaFlag = true;
|
|
2433
|
-
if (AV_GREP_VALUE_FLAGS.has(a)) i++;
|
|
2434
|
-
continue; // `--include=*.ts` style is self-contained
|
|
2435
|
-
}
|
|
2436
|
-
operands.push(a);
|
|
2437
|
-
}
|
|
2438
|
-
const fileOperands = patternViaFlag ? operands.length : operands.length - 1;
|
|
2439
|
-
if (fileOperands < 1) {
|
|
2440
|
-
findings.push({
|
|
2441
|
-
detail: `Automated Verification \`${command}\` names no file operand — reconcile re-runs it with stdin ignored, so it scans an empty stream and exits non-zero regardless of the tree. Put the target path INSIDE the backtick span (prose like "over \`<file>\`" is never executed).`,
|
|
2442
|
-
where: command,
|
|
2443
|
-
});
|
|
2444
|
-
}
|
|
2445
|
-
if (AV_ABSENCE_PROSE_RE.test(tail)) {
|
|
2446
|
-
findings.push({
|
|
2447
|
-
detail: `Automated Verification \`${command}\` asserts absence in prose ("${AV_ABSENCE_PROSE_RE.exec(tail)?.[0]}") — grep exits 1 on zero matches, so this line's success IS a non-zero exit and reconcile will always fail it. Restate it as a command that exits 0 on success (e.g. a \`node -e\` probe) or move it to Manual Verification.`,
|
|
2448
|
-
where: command,
|
|
2449
|
-
});
|
|
2450
|
-
}
|
|
2451
|
-
}
|
|
2452
|
-
// Biome runners: `npm run check:files -- <paths>` / `npx biome check <paths>`.
|
|
2453
|
-
const isCheckFiles = exe === "npm" && parsed.args[0] === "run" && parsed.args[1] === "check:files";
|
|
2454
|
-
const isBiome = (exe === "npx" && parsed.args[0] === "biome") || exe === "biome";
|
|
2455
|
-
if (isCheckFiles || isBiome) {
|
|
2456
|
-
const paths = parsed.args.filter((a) => !a.startsWith("-") && /[\\/.]/.test(a));
|
|
2457
|
-
// Flag ONLY when every forwarded path carries an out-of-scope extension —
|
|
2458
|
-
// a directory operand (no extension) may legitimately scope, so fail open.
|
|
2459
|
-
if (
|
|
2460
|
-
paths.length > 0 &&
|
|
2461
|
-
paths.every((p) => /\.[a-z\d]+$/i.test(p)) &&
|
|
2462
|
-
!paths.some((p) => AV_BIOME_SCOPED_PATH_RE.test(p))
|
|
2463
|
-
) {
|
|
2464
|
-
findings.push({
|
|
2465
|
-
detail: `Automated Verification \`${command}\` passes Biome only paths outside its configured scope (biome.json covers code files, not e.g. markdown) — Biome reports "No files were processed" and exits non-zero under --error-on-warnings, so reconcile will always fail it. Drop the line for doc-only phases or include an in-scope path.`,
|
|
2466
|
-
where: command,
|
|
2467
|
-
});
|
|
2468
|
-
}
|
|
2469
|
-
}
|
|
2470
|
-
}
|
|
2471
|
-
return findings;
|
|
2472
|
-
};
|
|
2473
|
-
|
|
2474
2336
|
/**
|
|
2475
2337
|
* Apply each `#### Reconciliation` directive, write-restricted to test-expectation
|
|
2476
2338
|
* files (`isTestPath` — reconcile writes ONLY test files; a non-test target is a
|
|
@@ -2524,42 +2386,6 @@ const applyReconciliationDirectives = (
|
|
|
2524
2386
|
return findings;
|
|
2525
2387
|
};
|
|
2526
2388
|
|
|
2527
|
-
/**
|
|
2528
|
-
* Re-run every per-phase `#### Automated Verification:` command via `execFileSync`
|
|
2529
|
-
* — arg-array (no shell), stdin ignored, exit 0 expected. An unparseable command
|
|
2530
|
-
* (`parseShellCommand` ⇒ null) is a finding naming it; a non-zero exit or throw is
|
|
2531
|
-
* a finding naming it (fail-soft — reconcile never throws on AV failure; a thrown
|
|
2532
|
-
* command degrades to the same non-zero finding). Returns findings in COMMAND
|
|
2533
|
-
* order. `reconcile` spreads the return into its findings array.
|
|
2534
|
-
*/
|
|
2535
|
-
const rerunAvCommands = (commands: readonly string[], cwd: string): { detail: string; where: string }[] => {
|
|
2536
|
-
const findings: { detail: string; where: string }[] = [];
|
|
2537
|
-
// Re-run every per-phase AV command (fail-soft: non-zero/throw ⇒ a finding).
|
|
2538
|
-
for (const cmd of commands) {
|
|
2539
|
-
const parsed = parseShellCommand(cmd);
|
|
2540
|
-
if (!parsed) {
|
|
2541
|
-
findings.push({
|
|
2542
|
-
detail: `reconcile: Automated Verification command unparseable — \`${cmd}\``,
|
|
2543
|
-
where: cmd,
|
|
2544
|
-
});
|
|
2545
|
-
continue;
|
|
2546
|
-
}
|
|
2547
|
-
try {
|
|
2548
|
-
execFileSync(parsed.exe, parsed.args, {
|
|
2549
|
-
cwd,
|
|
2550
|
-
encoding: "utf-8",
|
|
2551
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
2552
|
-
});
|
|
2553
|
-
} catch {
|
|
2554
|
-
findings.push({
|
|
2555
|
-
detail: `reconcile: Automated Verification command failed (non-zero) — \`${cmd}\``,
|
|
2556
|
-
where: cmd,
|
|
2557
|
-
});
|
|
2558
|
-
}
|
|
2559
|
-
}
|
|
2560
|
-
return findings;
|
|
2561
|
-
};
|
|
2562
|
-
|
|
2563
2389
|
/**
|
|
2564
2390
|
* Deterministic post-implement reconciliation — the coherence backstop the
|
|
2565
2391
|
* parallel implement lane needs. Sibling phases run concurrently in one tree;
|
|
@@ -2570,20 +2396,26 @@ const rerunAvCommands = (commands: readonly string[], cwd: string): { detail: st
|
|
|
2570
2396
|
* scope floor (which proved the write-set) and before `validate`:
|
|
2571
2397
|
*
|
|
2572
2398
|
* 1. reads the latest plan (`latestFsArtifact(state, "plans")` — latest-wins);
|
|
2573
|
-
* 2. parses every `#### Reconciliation` directive
|
|
2574
|
-
*
|
|
2575
|
-
*
|
|
2576
|
-
* halt — a `produces.script` that throws becomes one);
|
|
2399
|
+
* 2. parses every `#### Reconciliation` directive — fail-soft (a malformed
|
|
2400
|
+
* directive / unreadable plan degrades to a finding, never a terminal
|
|
2401
|
+
* `FAIL_SCRIPT_THREW` halt — a `produces.script` that throws becomes one);
|
|
2577
2402
|
* 3. applies each directive write-restricted to test paths (`isTestPath`); a
|
|
2578
2403
|
* present `find` is replaced exactly once (`String.replace`); an absent `find`
|
|
2579
2404
|
* whose replacement is ALSO absent is a finding (reconcile does not guess);
|
|
2580
|
-
* 4.
|
|
2581
|
-
* finding naming the command);
|
|
2582
|
-
* 5. appends a timestamped `### Reconciliation Log (<iso>)` under the plan's
|
|
2405
|
+
* 4. appends a timestamped `### Reconciliation Log (<iso>)` under the plan's
|
|
2583
2406
|
* `## Synthesis Notes` (best-effort bookkeeping write — non-fatal);
|
|
2584
|
-
*
|
|
2407
|
+
* 5. emits one `{ dimension: "reconcile" }` verdict, basename-keyed off the plan
|
|
2585
2408
|
* ⇒ idempotent across fix rounds (the verdict file is overwritten each round).
|
|
2586
2409
|
*
|
|
2410
|
+
* Reconcile deliberately does NOT re-execute the plan's `#### Automated
|
|
2411
|
+
* Verification:` commands. That re-run (bare `execFileSync`, no shell, exit-0
|
|
2412
|
+
* contract) was measured across the full run history at zero genuine catches and
|
|
2413
|
+
* a 100% false-positive finding rate — stale cross-phase presence probes, agent-
|
|
2414
|
+
* shell-only binaries (`rg`), prose greps — each halting a finished run at a
|
|
2415
|
+
* fail route with no fix arm. The downstream `validate` stage runs the same AV
|
|
2416
|
+
* commands as an agent, with a real shell and the judgment to tell a legitimate
|
|
2417
|
+
* post-rename mismatch from actual plan-vs-tree drift.
|
|
2418
|
+
*
|
|
2587
2419
|
* The route is the `match("verdict", …, { from: "reconcile" })` gate idiom — pass ⇒
|
|
2588
2420
|
* validate, fail/missing ⇒ STOP (no fallback), mirroring `implementScopeCheck`.
|
|
2589
2421
|
* Mirrors `implementScopeCheck`'s `ScriptContext` shape, basename-keyed verdict
|
|
@@ -2607,19 +2439,17 @@ const reconcile = ({ state, cwd }: ScriptContext): Omit<Output, "meta"> => {
|
|
|
2607
2439
|
const planAbs = isAbsolute(planPath) ? planPath : join(cwd, planPath);
|
|
2608
2440
|
const findings: { detail: string; where: string }[] = [];
|
|
2609
2441
|
|
|
2610
|
-
// Fail-soft read + parse: an unreadable plan
|
|
2611
|
-
//
|
|
2612
|
-
//
|
|
2442
|
+
// Fail-soft read + parse: an unreadable plan or malformed directive degrades
|
|
2443
|
+
// to a finding, never a terminal throw. If the read fails there is nothing to
|
|
2444
|
+
// apply.
|
|
2613
2445
|
let body = "";
|
|
2614
2446
|
let directives: ReconciliationDirective[] = [];
|
|
2615
2447
|
let malformed: string[] = [];
|
|
2616
|
-
let commands: string[] = [];
|
|
2617
2448
|
try {
|
|
2618
2449
|
body = readArtifactFile(planPath, cwd);
|
|
2619
2450
|
const parsed = reconciliationRecords(body);
|
|
2620
2451
|
directives = parsed.directives;
|
|
2621
2452
|
malformed = parsed.malformed;
|
|
2622
|
-
commands = planVerificationCommands(body);
|
|
2623
2453
|
} catch (err) {
|
|
2624
2454
|
findings.push({
|
|
2625
2455
|
detail: `reconcile: could not read or parse the plan ${planPath} — ${err instanceof Error ? err.message : String(err)}`,
|
|
@@ -2633,7 +2463,7 @@ const reconcile = ({ state, cwd }: ScriptContext): Omit<Output, "meta"> => {
|
|
|
2633
2463
|
});
|
|
2634
2464
|
}
|
|
2635
2465
|
|
|
2636
|
-
findings.push(...applyReconciliationDirectives(directives, cwd)
|
|
2466
|
+
findings.push(...applyReconciliationDirectives(directives, cwd));
|
|
2637
2467
|
|
|
2638
2468
|
// Best-effort bookkeeping: append a timestamped log under ## Synthesis Notes.
|
|
2639
2469
|
// Non-fatal — a write failure here is silent (the verdict below is the signal).
|
|
@@ -2828,8 +2658,10 @@ const gateTier = (state: RunView, verdictChannel: string): GateTier => {
|
|
|
2828
2658
|
const phases = channelNumber(state, "plans", "phase_count");
|
|
2829
2659
|
const severities = new Set<string>();
|
|
2830
2660
|
for (const o of state.named[verdictChannel] ?? []) {
|
|
2831
|
-
const
|
|
2832
|
-
|
|
2661
|
+
const v = o.data as { severity?: unknown; findings?: unknown } | undefined;
|
|
2662
|
+
const s = v?.severity;
|
|
2663
|
+
// Anchor-nit clamp: an all-drift-nit verdict must not escalate the tier.
|
|
2664
|
+
if (typeof s === "string") severities.add(anchorNitsOnly(v) ? "low" : s);
|
|
2833
2665
|
}
|
|
2834
2666
|
if (
|
|
2835
2667
|
(slices !== undefined && slices >= TIER_STRICT_MIN_SLICES) ||
|
|
@@ -2896,6 +2728,42 @@ const latestVerdictPerDimension = (entries: readonly Output[] = []): Map<string,
|
|
|
2896
2728
|
return latest;
|
|
2897
2729
|
};
|
|
2898
2730
|
|
|
2731
|
+
/**
|
|
2732
|
+
* Anchor-drift-nit phrasing, two tiers: only phrasings naming drift itself
|
|
2733
|
+
* count standalone; the location shapes (off-by-N, "is at line N", "line N is
|
|
2734
|
+
* the/a") also match REAL defects ("line 42 is a comment that falsely claims
|
|
2735
|
+
* X", "the loop bound is off by one") and count ONLY alongside citing-context
|
|
2736
|
+
* vocabulary — every observed drift nit has it, real-defect phrasings don't.
|
|
2737
|
+
* Do NOT widen, and do NOT promote a location shape to standalone.
|
|
2738
|
+
*/
|
|
2739
|
+
const ANCHOR_NIT_DRIFT_RE = /\bdrifted?\s+~?\d+\s+lines?\b|\bcitation (?:is )?drifted\b/i;
|
|
2740
|
+
const ANCHOR_NIT_LOCATION_RE =
|
|
2741
|
+
/\boff[- ]by[- ](?:one|two|three|\d+)\b|(?::\d+|\bline \d+) is (?:the|a)\b|\bis at line \d+\b/i;
|
|
2742
|
+
const ANCHOR_NIT_CITE_CONTEXT_RE = /\bcit(?:es?|ed|ation)\b|\banchor/i;
|
|
2743
|
+
|
|
2744
|
+
const isAnchorNitDetail = (detail: string): boolean =>
|
|
2745
|
+
ANCHOR_NIT_DRIFT_RE.test(detail) || (ANCHOR_NIT_LOCATION_RE.test(detail) && ANCHOR_NIT_CITE_CONTEXT_RE.test(detail));
|
|
2746
|
+
|
|
2747
|
+
/**
|
|
2748
|
+
* TRUE when a verdict carries ≥1 finding and EVERY finding is an anchor-drift
|
|
2749
|
+
* nit (`isAnchorNitDetail`). Such a verdict is severity-clamped to non-blocking
|
|
2750
|
+
* at the gate fold regardless of the grader's own `severity` — line-number
|
|
2751
|
+
* drift was measured at 34% of all grader findings with zero downstream harm,
|
|
2752
|
+
* and a mis-rated all-nit `medium` verdict buys a full fix round + re-grade
|
|
2753
|
+
* panel that repairs nothing. A verdict mixing a drift nit with ANY other
|
|
2754
|
+
* finding is untouched — the other finding may be the real blocker.
|
|
2755
|
+
*/
|
|
2756
|
+
const anchorNitsOnly = (v: { findings?: unknown } | undefined): boolean => {
|
|
2757
|
+
const findings = Array.isArray(v?.findings) ? v.findings : [];
|
|
2758
|
+
return (
|
|
2759
|
+
findings.length > 0 &&
|
|
2760
|
+
findings.every((f) => {
|
|
2761
|
+
const detail = (f as { detail?: unknown } | undefined)?.detail;
|
|
2762
|
+
return typeof detail === "string" && isAnchorNitDetail(detail);
|
|
2763
|
+
})
|
|
2764
|
+
);
|
|
2765
|
+
};
|
|
2766
|
+
|
|
2899
2767
|
/**
|
|
2900
2768
|
* The subset of `dimensions` a re-grade must actually re-run, given the latest
|
|
2901
2769
|
* verdict per dimension accumulated so far. A dimension needs re-grading when it
|
|
@@ -2917,8 +2785,8 @@ const dimensionsToRegrade = (
|
|
|
2917
2785
|
return dimensions.filter((d) => {
|
|
2918
2786
|
const o = latest.get(d);
|
|
2919
2787
|
if (!o) return true; // never graded — must grade at least once
|
|
2920
|
-
const v = o.data as { pass?: boolean; severity?: string } | undefined;
|
|
2921
|
-
const dimPass = v?.pass === true || v?.severity === "low" || v?.severity === "none";
|
|
2788
|
+
const v = o.data as { pass?: boolean; severity?: string; findings?: unknown } | undefined;
|
|
2789
|
+
const dimPass = v?.pass === true || v?.severity === "low" || v?.severity === "none" || anchorNitsOnly(v);
|
|
2922
2790
|
if (!dimPass) return true;
|
|
2923
2791
|
return verdictRiskRulings(o).some((r) => !rulingEffectivePass(r, risks.get(r.id)));
|
|
2924
2792
|
});
|
|
@@ -3251,10 +3119,12 @@ const allDimensionsPass = (entries: readonly Output[] = [], roster?: readonly st
|
|
|
3251
3119
|
const member = roster ? new Set(roster) : undefined;
|
|
3252
3120
|
const latest = new Map<string, boolean>();
|
|
3253
3121
|
for (const o of entries) {
|
|
3254
|
-
const v = o.data as { dimension?: string; pass?: boolean; severity?: string } | undefined;
|
|
3122
|
+
const v = o.data as { dimension?: string; pass?: boolean; severity?: string; findings?: unknown } | undefined;
|
|
3255
3123
|
if (typeof v?.dimension !== "string") continue;
|
|
3256
3124
|
if (member && !member.has(v.dimension)) continue;
|
|
3257
|
-
|
|
3125
|
+
// The anchor-nit clamp: an all-drift-nit verdict never blocks, whatever
|
|
3126
|
+
// severity the grader typed (backstop for the citation-resolution rule).
|
|
3127
|
+
const lowOrNone = v.severity === "low" || v.severity === "none" || anchorNitsOnly(v);
|
|
3258
3128
|
latest.set(v.dimension, v.pass === true || lowOrNone);
|
|
3259
3129
|
}
|
|
3260
3130
|
const verdicts = [...latest.values()];
|
|
@@ -3461,10 +3331,24 @@ const allRiskFlagsPass = (
|
|
|
3461
3331
|
// `units()` uses, so "skip the re-grade" stays provably equivalent to
|
|
3462
3332
|
// "re-grade, then pass". The deterministic cite/structure channels fold
|
|
3463
3333
|
// unfiltered: they re-run every round and carry no tier.
|
|
3334
|
+
// The latest structure verdict carries a `citeDischarged` stamp for the
|
|
3335
|
+
// CURRENT slice map. After a fix for a `remedy: "cite"` fail, the failing
|
|
3336
|
+
// design-readiness verdict is stale (the fix re-sliced to a NEW file) and the
|
|
3337
|
+
// gate's lone dimension has no fresh verdict, so the verdict fold can never
|
|
3338
|
+
// pass — yet the fix is deterministically verifiable: `sliceStructureCheck`
|
|
3339
|
+
// stamps the map basename it verified (demanded seeds present + shape
|
|
3340
|
+
// unchanged, see `citeRemedyDischarged`). Honoring the stamp only for the
|
|
3341
|
+
// current map means it can never carry across a later re-slice.
|
|
3342
|
+
const citeDischargeCoversCurrentMap = (state: RunView): boolean => {
|
|
3343
|
+
const stamp = (state.named["slice-check"]?.at(-1)?.data as { citeDischarged?: unknown } | undefined)?.citeDischarged;
|
|
3344
|
+
const current = latestArtifactPath(state, "slices");
|
|
3345
|
+
return typeof stamp === "string" && current !== undefined && stamp === basename(current);
|
|
3346
|
+
};
|
|
3464
3347
|
const sliceGatePasses = (state: RunView): boolean => {
|
|
3465
3348
|
const fresh = freshVerdicts(state.named["slice-verdicts"], latestArtifactPath(state, "slices"));
|
|
3466
3349
|
const roster = gateRoster(gateTier(state, "slice-verdicts"), SLICE_DIMENSIONS);
|
|
3467
|
-
|
|
3350
|
+
if (!allDimensionsPass(state.named["slice-check"])) return false;
|
|
3351
|
+
return allDimensionsPass(fresh, roster) || citeDischargeCoversCurrentMap(state);
|
|
3468
3352
|
};
|
|
3469
3353
|
// The single authority the new `subplan-check` edge consults — the twin of
|
|
3470
3354
|
// `sliceGatePasses`, but carrying no LLM-verdict roster or risk flags: the
|
|
@@ -3518,9 +3402,11 @@ const confirmDue = (
|
|
|
3518
3402
|
const risks = planAuthoredRisks(state, channel);
|
|
3519
3403
|
const byDim = new Map<string, { blocking: boolean; count: number }>();
|
|
3520
3404
|
for (const o of fresh) {
|
|
3521
|
-
const v = o.data as { dimension?: string; pass?: boolean; severity?: string } | undefined;
|
|
3405
|
+
const v = o.data as { dimension?: string; pass?: boolean; severity?: string; findings?: unknown } | undefined;
|
|
3522
3406
|
if (typeof v?.dimension !== "string" || !roster.has(v.dimension)) continue;
|
|
3523
|
-
|
|
3407
|
+
// anchorNitsOnly keeps this floor coherent with the other three
|
|
3408
|
+
// severity-fold consumers (gateTier/dimensionsToRegrade/allDimensionsPass).
|
|
3409
|
+
const floored = v.pass === true || v.severity === "low" || v.severity === "none" || anchorNitsOnly(v);
|
|
3524
3410
|
const riskFail = verdictRiskRulings(o).some((r) => !rulingEffectivePass(r, risks.get(r.id)));
|
|
3525
3411
|
byDim.set(v.dimension, {
|
|
3526
3412
|
blocking: !floored || riskFail,
|
|
@@ -3613,7 +3499,7 @@ const COMMIT_BASELINE_PROMPT: PromptFn = ({ state }) => {
|
|
|
3613
3499
|
// brief as a goal artifact, review, and if not approved blueprint a fix
|
|
3614
3500
|
// plan, implement it, scope-check it, validate, and re-review. Loops
|
|
3615
3501
|
// until approved. NOTE: defined here (after captureGoal /
|
|
3616
|
-
// implementScopeCheckVet) rather than beside
|
|
3502
|
+
// implementScopeCheckVet) rather than beside polish because its graph
|
|
3617
3503
|
// references those later-declared `const`s — the same precedent
|
|
3618
3504
|
// buildWorkflow follows (defined after its deps).
|
|
3619
3505
|
// ===========================================================================
|
|
@@ -3621,7 +3507,7 @@ const COMMIT_BASELINE_PROMPT: PromptFn = ({ state }) => {
|
|
|
3621
3507
|
const vetWorkflow = defineWorkflow({
|
|
3622
3508
|
name: "vet",
|
|
3623
3509
|
description:
|
|
3624
|
-
"Examine existing changes for approval; loop a fix cycle if not approved. Best when a diff already exists (yours or a teammate's) and you want a structured review with optional repair. Chain: goal → code-review → (blueprint → implement → implement-scope-check → validate → loop) → commit.",
|
|
3510
|
+
"Examine existing changes for approval; loop a fix cycle if not approved. Best when a diff already exists (yours or a teammate's) and you want a structured review with optional repair. Chain: goal → code-review → (blueprint → implement → implement-scope-check → reconcile → validate → loop) → commit.",
|
|
3625
3511
|
start: "goal",
|
|
3626
3512
|
stages: {
|
|
3627
3513
|
// Capture the user's brief verbatim on its own `goal` channel, and snapshot
|
|
@@ -3631,7 +3517,7 @@ const vetWorkflow = defineWorkflow({
|
|
|
3631
3517
|
// rides the channel face. `goal` as start publishes the goal-md as
|
|
3632
3518
|
// `artifacts[0]`; `code-review` is a plain `produces()` SKILL stage (skill
|
|
3633
3519
|
// defaults to its stage key "code-review"), so it inherits that goal-md PATH
|
|
3634
|
-
// as its rolling primary — the same pattern
|
|
3520
|
+
// as its rolling primary — the same pattern polish's code-review uses,
|
|
3635
3521
|
// and the fallback Risk r1's note conceded "likely tolerates a goal-md-path
|
|
3636
3522
|
// arg." The goal-md's CONTENT is the brief (`captureGoal` writes
|
|
3637
3523
|
// `state.originalInput` into it), so the skill still reaches it.
|
|
@@ -3669,7 +3555,7 @@ const vetWorkflow = defineWorkflow({
|
|
|
3669
3555
|
},
|
|
3670
3556
|
edges: {
|
|
3671
3557
|
goal: "code-review",
|
|
3672
|
-
// Same numeric gate as
|
|
3558
|
+
// Same numeric gate as polish: zero remaining blockers → commit;
|
|
3673
3559
|
// any blockers → loop a fix pass through blueprint. The `blockers_count`
|
|
3674
3560
|
// field is sourced + validated from the code-review contract.
|
|
3675
3561
|
"code-review": gate("blockers_count", { blueprint: gt(0), commit: eq(0) }, "commit"),
|
|
@@ -3699,7 +3585,7 @@ const vetWorkflow = defineWorkflow({
|
|
|
3699
3585
|
const buildWorkflow = defineWorkflow({
|
|
3700
3586
|
name: "build",
|
|
3701
3587
|
description:
|
|
3702
|
-
"Ship, sliced: capture the verbatim brief as a goal artifact (the north star the quality gates' completeness/correctness dimensions and validate anchor against) → research the brief → decompose it into vertical slices → two-phase slice gate (a deterministic floor — dependency-cycle freedom + brief-coverage conservation so a slice-fix can't pass by dropping scope — then one LLM design-readiness judgment that each slice is chewable by a single design pass) with a slice-fix loop → design each slice in parallel → one consolidated developer checkpoint (accept or adjust the proposed interfaces/data types, adjustments applied surgically and cascaded to dependents) → synthesize hierarchically (per-cluster sub-plans → one merged plan) → tier-scaled quality-panel gate (a one-slice, <=2-phase run grades correctness+completeness only; larger or previously-failing runs grade the full completeness/correctness/actionability/pattern-following/architecture-fit roster) where a dimension's first blocking verdict gets one confirming second judgment before it buys a plan-fix round → elaborate code per phase in parallel → splice it into the plan → re-grade the code-bearing plan (same tier + confirm contract) → implement → validate → commit. Research-led; three automated gates plus one human design checkpoint, before design, before code, and after the splice.",
|
|
3588
|
+
"Ship, sliced: capture the verbatim brief as a goal artifact (the north star the quality gates' completeness/correctness dimensions and validate anchor against) → research the brief → decompose it into vertical slices → two-phase slice gate (a deterministic floor — dependency-cycle freedom + brief-coverage conservation so a slice-fix can't pass by dropping scope — then one LLM design-readiness judgment that each slice is chewable by a single design pass) with a slice-fix loop → design each slice in parallel → one consolidated developer checkpoint (accept or adjust the proposed interfaces/data types, adjustments applied surgically and cascaded to dependents) → synthesize hierarchically (per-cluster sub-plans → one merged plan) → tier-scaled quality-panel gate (a one-slice, <=2-phase run grades correctness+completeness only; larger or previously-failing runs grade the full completeness/correctness/actionability/pattern-following/architecture-fit roster) where a dimension's first blocking verdict gets one confirming second judgment before it buys a plan-fix round → elaborate code per phase in parallel → splice it into the plan → re-grade the code-bearing plan (same tier + confirm contract) → implement → implement-scope-check → reconcile → validate → commit. Research-led; three automated gates plus one human design checkpoint, before design, before code, and after the splice.",
|
|
3703
3589
|
start: "goal",
|
|
3704
3590
|
stages: {
|
|
3705
3591
|
// The user's brief, verbatim, on its own channel — the judgment seams
|
|
@@ -3907,14 +3793,17 @@ const buildWorkflow = defineWorkflow({
|
|
|
3907
3793
|
edges: {
|
|
3908
3794
|
goal: "research",
|
|
3909
3795
|
// Research's artifact is auto-fed to slice as its argument (the slice skill's
|
|
3910
|
-
// "Fresh" input is a research path)
|
|
3796
|
+
// "Fresh" input is a research path).
|
|
3911
3797
|
research: "slice",
|
|
3912
3798
|
slice: "slice-check",
|
|
3913
3799
|
// Skip the design-readiness re-grade when the gate is already satisfied — after
|
|
3914
3800
|
// a `slice-fix` that only cleared the deterministic structure floor (the common
|
|
3915
3801
|
// case: a bare-basename citation), the accumulated design-readiness verdict
|
|
3916
|
-
// already passes, so re-grading would only re-roll a flappy judgment.
|
|
3917
|
-
//
|
|
3802
|
+
// already passes, so re-grading would only re-roll a flappy judgment. Also
|
|
3803
|
+
// skips after a fix for a `remedy: "cite"` fail once `slice-check` has
|
|
3804
|
+
// deterministically verified the demanded seeds landed on a structurally
|
|
3805
|
+
// unchanged map (the `citeDischarged` stamp — see `citeRemedyDischarged`).
|
|
3806
|
+
// First pass (no verdict yet) ⇒ not satisfied ⇒ into `slice-grade`.
|
|
3918
3807
|
"slice-check": defineRoute(
|
|
3919
3808
|
["slice-design", "slice-grade"],
|
|
3920
3809
|
({ state }) => (sliceGatePasses(state) ? "slice-design" : "slice-grade"),
|
|
@@ -4069,10 +3958,7 @@ const buildWorkflow = defineWorkflow({
|
|
|
4069
3958
|
// Exports
|
|
4070
3959
|
// ===========================================================================
|
|
4071
3960
|
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
polishWorkflow,
|
|
4077
|
-
buildWorkflow,
|
|
4078
|
-
];
|
|
3961
|
+
// Position 0 is load-bearing: `build` is the default `/wf` workflow when no
|
|
3962
|
+
// project/user config sets one (resolve-default.ts resolves
|
|
3963
|
+
// `Map.keys().next().value`), so it MUST stay first in this array.
|
|
3964
|
+
export const builtInWorkflows: readonly Workflow[] = [buildWorkflow, vetWorkflow, polishWorkflow];
|