@juicesharp/rpiv-pi 2.7.0 → 2.7.1

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/docs/skills.md CHANGED
@@ -53,7 +53,7 @@ whether the model may reach for it on its own.
53
53
  | --- | :---: | --- | --- | --- |
54
54
  | `implement` | — | a `plan` artifact | code changes | Executes a plan phase by phase, verifying each phase against its success criteria before moving on. |
55
55
  | `validate` | — | a `plan` + the working tree | `validation/` | Runs each phase's success criteria against the working tree and reports a `pass` / `fail` verdict. |
56
- | `remediate` | — | a `plan` + its failing `validation` | side-effect | The `validate` repair arm's body: re-runs each failed `verify-at-implement` risk ruling's own prescribed procedure, applies the minimal fix grounded in the failing report, and confirms the procedure passes. Workflow-dispatched only — `build`'s `validate-fix` stage. |
56
+ | `remediate` | — | a `plan` + its failing `validation` | side-effect | The `validate` repair arm's body: re-runs each failed `verify-at-implement` risk ruling's own prescribed procedure and each structured `blockers:` entry's failing command, applies the minimal fix grounded in the failing report, and confirms it passes. Workflow-dispatched only — `build`'s `validate-fix` stage. |
57
57
  | `code-review` | ✓ | the working tree, a branch, or a PR | `reviews/` | Parallel specialist agents audit the diff, compare against peer code, and verify claims. Emits `blockers_count` plus severity-tagged findings. Scope argument accepts `staged`, `working`, a hash, `A..B`, or a branch; empty scope defaults to feature-branch vs default-branch. |
58
58
  | `architecture-review` | — | a file, directory, or module path | `architecture-reviews/` | Top-down, layer-by-layer audit with a uniform 10-dimension checklist per layer, triaged through a developer checkpoint. Emits a phased polish plan `blueprint` can consume per phase. Language-agnostic. |
59
59
  | `grade` | — | one artifact + one dimension name | `verdicts/` | Judges ONE artifact along ONE named quality dimension and writes a verdict JSON. It only judges — no fixes. A panel member, not standalone. |
@@ -69,6 +69,7 @@ import {
69
69
  planSnapshot,
70
70
  REVIEW_PHASE_ITERATE,
71
71
  reconcile,
72
+ remediationOutcome,
72
73
  rulingEffectivePass,
73
74
  SHIP_DIMENSION_FANOUT,
74
75
  SHIP_DIMENSIONS,
@@ -373,6 +374,78 @@ const vetWorkflow = defineWorkflow({
373
374
  },
374
375
  });
375
376
 
377
+ /**
378
+ * Build's validate gate — classifies a failing verdict BEFORE routing to the
379
+ * repair arm. `remediate`'s work-list is contractually the report's `pass:
380
+ * false` risk rulings plus its structured `blockers:` entries; a `verdict:
381
+ * fail` carrying NEITHER (run 2026-08-22_12-14-12-64eb: two whole-plan gate
382
+ * failures recorded only in report prose) has no handle the arm may act on,
383
+ * so routing it to `validate-fix` buys a provably futile lap — the arm
384
+ * drift-escapes without an edit and the unchanged tree re-validates to the
385
+ * identical verdict until the backward-jump guard halts the run. Such a fail
386
+ * now STOPs at the gate with a route note naming why (the ship-gate
387
+ * `setRouteNote` pattern; a noted decision stop records as a halt). The
388
+ * repair-arm authority rule the slice gate learned the same way: a gate may
389
+ * only loop into an arm whose authority covers the failure class.
390
+ *
391
+ * Reads the `validation` channel (validate's contract-derived publish bucket
392
+ * — a prompt stage owns its message and can't inherit its contract's output
393
+ * schema, so the gate folds the channel, never the raw stage output). A
394
+ * missing/unexpected verdict stays terminal STOP, exactly as the `match` it
395
+ * replaces — un-anticipated data can never route INTO commit OR the repair arm.
396
+ */
397
+ const validateGate: EdgeFn = defineRoute(
398
+ ["commit", "validate-fix", "stop"],
399
+ ({ state }) => {
400
+ const latest = state.named.validation?.at(-1);
401
+ const data = latest?.data as { verdict?: unknown; blockers?: unknown } | undefined;
402
+ if (data?.verdict === "pass") return "commit";
403
+ if (data?.verdict !== "fail") {
404
+ setRouteNote(
405
+ validateGate,
406
+ `validate verdict ${JSON.stringify(data?.verdict ?? null)} matched no branch — terminated (no fallback)`,
407
+ );
408
+ return "stop";
409
+ }
410
+ // Remediable handles: `pass: false` risk rulings (the arm's original
411
+ // work-list) + structured `blockers:` entries (whole-plan gate failures
412
+ // the validate skill attributes with a runnable command + in-delta file).
413
+ const failedRulings = latest ? verdictRiskRulings(latest).filter((r) => !r.pass).length : 0;
414
+ const blockers = Array.isArray(data.blockers) ? data.blockers.length : 0;
415
+ if (failedRulings + blockers > 0) return "validate-fix";
416
+ setRouteNote(
417
+ validateGate,
418
+ "validate failed with no remediable handle (no pass:false risk ruling, no blockers entry) — the remediation arm cannot act; fix manually or revise the plan",
419
+ );
420
+ return "stop";
421
+ },
422
+ { readsData: false },
423
+ );
424
+
425
+ /**
426
+ * Build's repair-arm progress gate — the deterministic no-op backstop. The
427
+ * `remediation` channel carries `remediationOutcome`'s `{ changed }` (a
428
+ * git-only tree digest snapshotted around the `validate-fix` stage): an
429
+ * unchanged tree makes the re-validate lap provably futile (validate's
430
+ * verdict is a function of the tree), so it STOPs with a note instead of
431
+ * burning a backward-jump on an identical verdict. Only an explicit
432
+ * `changed: false` stops — a missing signal (non-repo, git failure, absent
433
+ * channel) proceeds, the worktree-digest degrade doctrine.
434
+ */
435
+ const validateFixGate: EdgeFn = defineRoute(
436
+ ["implement-scope-check", "stop"],
437
+ ({ state }) => {
438
+ const data = state.named.remediation?.at(-1)?.data as { changed?: unknown } | undefined;
439
+ if (data?.changed !== false) return "implement-scope-check";
440
+ setRouteNote(
441
+ validateFixGate,
442
+ "remediation left the working tree unchanged — re-validating cannot change the verdict; fix manually or revise the plan",
443
+ );
444
+ return "stop";
445
+ },
446
+ { readsData: false },
447
+ );
448
+
376
449
  const buildWorkflow = defineWorkflow({
377
450
  name: "build",
378
451
  description:
@@ -584,15 +657,17 @@ const buildWorkflow = defineWorkflow({
584
657
  // `from` form suppresses the READS_DATA outputSchema lint.
585
658
  reconcile: produces.script({ reads: ["plans"], run: reconcile }),
586
659
  validate: produces({ prompt: VALIDATE_GOAL_PROMPT }),
587
- // Repair arm the validate gate dispatches on a `verdict: "fail"`. `acts()`
588
- // (not `produces()`) because remediate is `side-effect`/`code-mutation` (the
589
- // tools twin of `implement`: re-runs verification commands via `Bash(*)` and
590
- // edits the working tree) — NOT produced-validating and NOT routed-on (its
591
- // edge is deterministic), so it owns no outcome. `reads: ["plans","validation"]`
592
- // ⇒ `stageEntryArgs` derives `--plans <plan> --validation <latest-report>`;
660
+ // Repair arm the validate gate dispatches on a remediable `verdict: "fail"`.
661
+ // `acts()` (not `produces()`) because remediate is `side-effect`/`code-mutation`
662
+ // (the tools twin of `implement`: re-runs verification commands via `Bash(*)`
663
+ // and edits the working tree). `reads: ["plans","validation"]` ⇒
664
+ // `stageEntryArgs` derives `--plans <plan> --validation <latest-report>`;
593
665
  // `validation` is validate's own publish bucket, so validate-fix always reads
594
- // the latest failing report.
595
- "validate-fix": acts({ skill: "remediate", reads: ["plans", "validation"] }),
666
+ // the latest failing report. `remediationOutcome` publishes the deterministic
667
+ // did-anything-change digest verdict on the `remediation` channel (the
668
+ // `commit`/`gitCommitOutcome` pattern) — the arm's OWN edge folds it, so a
669
+ // no-op remediation stops instead of re-validating an unchanged tree.
670
+ "validate-fix": acts({ skill: "remediate", reads: ["plans", "validation"], outcome: remediationOutcome }),
596
671
  commit: acts({ prompt: COMMIT_BASELINE_PROMPT, outcome: gitCommitOutcome }),
597
672
  },
598
673
  edges: {
@@ -749,29 +824,24 @@ const buildWorkflow = defineWorkflow({
749
824
  // manually). Safe by construction: the sole path onward is an explicit
750
825
  // `verdict: "pass"`. Sourced from the reconcile channel via the `from` form.
751
826
  reconcile: match("verdict", { validate: "pass" }, { from: "reconcile" }),
752
- // Gate commit on validate's own verdict — an unconditional `validate → commit`
753
- // let a `verdict: fail` (incomplete goal coverage) commit anyway. Now the
754
- // gate splits: `pass` ⇒ commit; `fail` ⇒ validate-fix (the repair arm above,
755
- // which re-runs the failing `verify-at-implement` risk-ruling procedures and
756
- // surgically fixes the tree, then re-enters at implement-scope-check to
757
- // re-reconcile + re-validate — bounded by the per-destination backward-jump
758
- // budget). Deliberately NOT a `fallback`: a missing/unexpected verdict stays
759
- // terminal STOP, so un-anticipated data can never route INTO commit OR the
760
- // repair arm. Safe by construction: the sole path to commit is an explicit
761
- // pass. The `match` branch key (`validate-fix`) doubles as the reachability/
762
- // stage declaration, so naming it both routes `fail` and declares the stage
763
- // reachable. Sourced from validate's published verdict channel
764
- // (`from: "validation"` — the bucket its contract's `artifactKind` derives) —
765
- // a prompt stage owns its message and can't inherit its contract's output
766
- // schema, so route on the channel, not the raw (un-validated) stage output.
767
- validate: match("verdict", { commit: "pass", "validate-fix": "fail" }, { from: "validation" }),
768
- // Deterministic re-entry after the repair arm: remediate's code-mutation is
769
- // followed by a fresh scope check → reconcile → validate pass, so a fix is
770
- // re-verified end-to-end before the gate re-folds. A non-counted edge (a
771
- // deterministic hop into the loop body), so it never trips a backward-jump
772
- // budget on its own — the budget-consuming decision edge is the validate
773
- // gate's `validate-fix` branch above.
774
- "validate-fix": "implement-scope-check",
827
+ // Gate commit on validate's own verdict — see `validateGate`. `pass` ⇒
828
+ // commit; a `fail` WITH remediable handles (a `pass: false` risk ruling or a
829
+ // structured `blockers:` entry) ⇒ validate-fix, which re-enters at
830
+ // implement-scope-check to re-reconcile + re-validate — bounded by the
831
+ // per-destination backward-jump budget; a `fail` with NO handle ⇒ STOP with
832
+ // a route note (the repair arm cannot act on prose-only failures — looping
833
+ // it re-validated an unchanged tree until the guard halted the run).
834
+ // A missing/unexpected verdict stays terminal STOP, so un-anticipated data
835
+ // can never route INTO commit OR the repair arm. Safe by construction: the
836
+ // sole path to commit is an explicit pass.
837
+ validate: validateGate,
838
+ // Re-entry after the repair arm: remediate's code-mutation is followed by a
839
+ // fresh scope check → reconcile → validate pass, so a fix is re-verified
840
+ // end-to-end before the gate re-folds. Now a decision edge (`validateFixGate`
841
+ // folds the `remediation` channel's deterministic digest verdict): a
842
+ // remediation that changed nothing STOPs here — progress is verified, not
843
+ // assumed — while a real fix proceeds into the loop body.
844
+ "validate-fix": validateFixGate,
775
845
  commit: "stop",
776
846
  },
777
847
  });
@@ -53,6 +53,7 @@ export {
53
53
  } from "./plan-phases.js";
54
54
  export { codeDemote, codeSnapshot, planDemote, planSnapshot } from "./priors.js";
55
55
  export { reconcile } from "./reconcile.js";
56
+ export { remediationOutcome } from "./remediation.js";
56
57
  export { implementScopeCheck, implementScopeCheckVet, ScopeVerdict, scopeQuarantine } from "./scope-checks.js";
57
58
  export {
58
59
  FILE_LINE_CITATION_RE,
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Remediation outcome — the deterministic did-anything-change signal for
3
+ * build's `validate-fix` repair arm.
4
+ *
5
+ * The arm dispatches the `remediate` skill (side-effect, code-mutation). Its
6
+ * printed sentinels ("remediation not localized: …") are prose the router
7
+ * cannot see, so a no-op remediation used to be indistinguishable from a fix
8
+ * and the loop re-validated an unchanged tree until the backward-jump guard
9
+ * halted the run (run 2026-08-22_12-14-12-64eb: four identical validate
10
+ * laps). This outcome closes that gap the way `gitCommitOutcome` reads a
11
+ * commit off git state: snapshot a git-only tree digest before the stage,
12
+ * recompute after, and publish `{ changed }` on the `remediation` channel for
13
+ * the `validate-fix` route to fold.
14
+ *
15
+ * Git-only (status --porcelain + diff HEAD) — deliberately NOT the runner's
16
+ * `computeWorktreeDigest`, which also hashes `.rpiv/artifacts/`: remediate is
17
+ * contractually forbidden from writing artifacts, and validate writes a new
18
+ * timestamped report every lap, so the artifacts component would flip the
19
+ * verdict on churn that is not a code fix. `diff HEAD` (not bare `diff`) for
20
+ * the same staged-content reason the runner's digest documents.
21
+ *
22
+ * Degrade posture mirrors worktree-digest.ts: an `undefined` digest on either
23
+ * side (non-repo / git missing / timeout) reports `changed: true` — a missing
24
+ * signal is NEVER a reason to stop the run.
25
+ */
26
+
27
+ import { execFileSync } from "node:child_process";
28
+ import { createHash } from "node:crypto";
29
+ import {
30
+ type Artifact,
31
+ type CollectContext,
32
+ type Outcome,
33
+ opaque,
34
+ type SnapshotContext,
35
+ } from "@juicesharp/rpiv-workflow/registration";
36
+
37
+ /** Wall-clock ceiling per git subprocess — the digest runs synchronously at
38
+ * the stage seam, so a wedged git (contended index.lock) must be killed here;
39
+ * on expiry the throw degrades to `undefined` (proceed). */
40
+ const GIT_DIGEST_TIMEOUT_MS = 10_000;
41
+
42
+ /**
43
+ * Git-only content fingerprint of `cwd`'s working tree. Returns `undefined`
44
+ * on ANY failure so callers degrade to "proceed", never "stop".
45
+ */
46
+ export const gitTreeDigest = (cwd: string): string | undefined => {
47
+ try {
48
+ const opts = {
49
+ cwd,
50
+ encoding: "utf-8" as const,
51
+ stdio: ["ignore", "pipe", "ignore"] as ["ignore", "pipe", "ignore"],
52
+ timeout: GIT_DIGEST_TIMEOUT_MS,
53
+ };
54
+ const status = execFileSync("git", ["status", "--porcelain"], opts);
55
+ const diff = execFileSync("git", ["diff", "HEAD"], opts);
56
+ return createHash("sha256").update(status).update("\0").update(diff).digest("hex");
57
+ } catch {
58
+ return undefined;
59
+ }
60
+ };
61
+
62
+ /** The `remediation` channel's data: did the repair arm mutate the tree? */
63
+ export interface RemediationData {
64
+ changed: boolean;
65
+ }
66
+
67
+ /**
68
+ * Snapshot the digest pre-stage, recompute post-stage, publish `{ changed }`.
69
+ * One sentinel opaque artifact carries the verdict in `meta` (the
70
+ * `gitCommitOutcome` shape) so the parser stays total.
71
+ */
72
+ export const remediationOutcome: Outcome<string | undefined, "remediation", RemediationData> = {
73
+ name: "remediation",
74
+ collector: {
75
+ snapshot: ({ cwd }: SnapshotContext) => gitTreeDigest(cwd),
76
+ collect(ctx: CollectContext<string | undefined>) {
77
+ const after = gitTreeDigest(ctx.cwd);
78
+ // A missing digest on either side is a missing signal — report changed
79
+ // (proceed), never a fabricated "nothing happened".
80
+ const changed = ctx.snapshot === undefined || after === undefined || ctx.snapshot !== after;
81
+ const artifact: Artifact = {
82
+ handle: opaque(changed ? "remediation-changed" : "remediation-unchanged"),
83
+ role: "remediation",
84
+ meta: { changed },
85
+ };
86
+ return { kind: "ok", artifacts: [artifact] };
87
+ },
88
+ },
89
+ parser: {
90
+ parse(ctx) {
91
+ const changed = (ctx.artifacts[0]?.meta as { changed?: unknown } | undefined)?.changed;
92
+ // Only an explicit `false` reports unchanged — same degrade posture.
93
+ return { kind: "ok", payload: { kind: "remediation", data: { changed: changed !== false } } };
94
+ },
95
+ },
96
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juicesharp/rpiv-pi",
3
- "version": "2.7.0",
3
+ "version": "2.7.1",
4
4
  "description": "A skill-based development workflow for Pi Agent. 29 contract-carrying skills (discover → research → design → plan → implement → validate → code-review → commit, and more), the 15 named subagents they dispatch, and four built-in /wf workflows that chain them end to end in detached parallel runs.",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -50,7 +50,7 @@
50
50
  ]
51
51
  },
52
52
  "dependencies": {
53
- "@juicesharp/rpiv-config": "^2.7.0",
53
+ "@juicesharp/rpiv-config": "^2.7.1",
54
54
  "typebox": "^1.1.24"
55
55
  },
56
56
  "peerDependencies": {
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: remediate
3
- description: Surgically repair a working tree whose validate run returned a failing verdict — re-run each failed verify-at-implement risk ruling's prescribed procedure, apply the minimal localized code fix grounded in the validation report, then confirm the procedure passes. Single-pass, no subagents, no self-review, no questions. Workflow-gated repair arm dispatched after a failing validate; use as a gate's repair stage.
3
+ description: Surgically repair a working tree whose validate run returned a failing verdict — re-run each failed verify-at-implement risk ruling's prescribed procedure and each structured blocker's failing command, apply the minimal localized code fix grounded in the validation report, then confirm it passes. Single-pass, no subagents, no self-review, no questions. Workflow-gated repair arm dispatched after a failing validate; use as a gate's repair stage.
4
4
  argument-hint: "--plans <plan-path> --validation <report-path>"
5
5
  allowed-tools: Read, Edit, Write, Bash(*), Glob, Grep
6
6
  shell-timeout: 10
@@ -22,7 +22,7 @@ contract:
22
22
 
23
23
  # Remediate
24
24
 
25
- You surgically repair a **working tree** that a validate stage judged `verdict: fail`. You do **not** re-validate the whole plan, re-run the project's full build/test suite, or rewrite anything broadly — you clear exactly the localized defects the failing risk rulings prescribe, and re-run each ruling's own `procedure` to confirm it now passes. One pass, non-interactive, side-effect only: you mutate code, never emit an artifact. The workflow loops you straight back to the validate gate, which re-judges; that is the only validation, so you do **not** self-review or ask for approval.
25
+ You surgically repair a **working tree** that a validate stage judged `verdict: fail`. You do **not** re-validate the whole plan, re-run the project's full build/test suite, or rewrite anything broadly — you clear exactly the localized defects the failing risk rulings and structured blockers prescribe, and re-run each item's own `procedure`/`command` to confirm it now passes. One pass, non-interactive, side-effect only: you mutate code, never emit an artifact. The workflow loops you straight back to the validate gate, which re-judges; that is the only validation, so you do **not** self-review or ask for approval.
26
26
 
27
27
  You are the tools/contract twin of `implement` (`Bash(*)` + `code-mutation`, side-effect, not an artifact) and the body-discipline twin of `amend` (single-pass, surgical, no subagents, no self-review, no questions).
28
28
 
@@ -31,30 +31,32 @@ You are the tools/contract twin of `implement` (`Bash(*)` + `code-mutation`, sid
31
31
  `$ARGUMENTS` — flags the orchestrator wires from the gate's channels. Parse flag-style (order-agnostic), exactly like `amend`:
32
32
 
33
33
  - **`--plans <plan-path>`** — the plan under `.rpiv/artifacts/plans/`. Its frontmatter carries the `risks:` array; a ruling's `id` joins to a flag there.
34
- - **`--validation <report-path>`** — the failing validation report under `.rpiv/artifacts/validation/`. Its frontmatter carries `verdict` + `risk_rulings: [{ id, pass }]`.
34
+ - **`--validation <report-path>`** — the failing validation report under `.rpiv/artifacts/validation/`. Its frontmatter carries `verdict` + `risk_rulings: [{ id, pass }]` and, when whole-plan gates failed, `blockers: [{ id, command, file, line }]`.
35
35
 
36
36
  If `--plans` or `--validation` is missing, print an error and stop — it is a dispatch error, not a failing phase.
37
37
 
38
38
  ## Steps
39
39
 
40
- 1. **Read the plan and the report fully** (no limit/offset). From the report's frontmatter read `verdict` and the `risk_rulings: [{ id, pass }]` array; from the plan's frontmatter read the `risks:` array (each flag is `{ id, claim, … }`).
41
- 2. **Build the work-list — ONLY the report's failing risk rulings.** Take every `risk_rulings` entry with `pass === false`, and join each to the plan's `risks:` flag by `id`. A `pass: false` ruling whose `id` matches no plan flag has no `claim`/`procedure`/`owner` to ground a fix — treat it as a drift-escape (step 4). Never source work from the report body's Potential Issues / Deviations prose on its own: those tie to a ruling only when a `risk_rulings` entry names it.
40
+ 1. **Read the plan and the report fully** (no limit/offset). From the report's frontmatter read `verdict`, the `risk_rulings: [{ id, pass }]` array, and the `blockers: [{ id, command, file, line }]` array (absent ⇒ empty); from the plan's frontmatter read the `risks:` array (each flag is `{ id, claim, … }`).
41
+ 2. **Build the work-list — ONLY the report's failing risk rulings + structured blockers.** Take every `risk_rulings` entry with `pass === false`, and join each to the plan's `risks:` flag by `id`. A `pass: false` ruling whose `id` matches no plan flag has no `claim`/`procedure`/`owner` to ground a fix — treat it as a drift-escape (step 4). Then append every `blockers:` entry — each is a whole-plan/automated-command failure validate attributed with a runnable `command` and an in-delta `file`; its `command` plays the role of a ruling's `procedure` and it joins no plan flag. Never source work from the report body's Potential Issues / Deviations prose on its own: those tie to a work item only when a `risk_rulings` or `blockers` entry names it.
42
42
  3. **Partition the work-list into fixable vs drift-escape.** A failed ruling is **fixable** ONLY when its joined plan flag carries ALL of:
43
43
  - `disposition: verify-at-implement` — the ruling the plan deferred to this exact repair arm;
44
44
  - a concrete, non-empty `procedure` — the named command/test the ruling's own verification runs (the `owner` phase promised it);
45
45
  - a numeric `owner` phase.
46
46
 
47
47
  Every other failed ruling — a `claim_type: mechanics` flag (cited `file:line`, no `procedure`), a bare `{ id, claim }` flag, or a flag missing `owner` — is a **drift-escape**: it has no executable procedure a localized fix can discharge, so an open-ended repair would be guessing.
48
- 4. **Drift-escape gate (checked BEFORE any edit).** If the work-list is empty (`verdict: fail` with no `pass: false` risk ruling at all), print `remediation not localized: no-prescribed-rulings`, edit nothing, and stop. If ANY failed ruling is non-fixable, print `remediation not localized: <ruling-id>` for each non-fixable ruling, edit nothing, and stop. Either way, do NOT print the success closing block.
49
- 5. **Repair pass — one cycle per fixable ruling, single-pass (no in-skill retry loop).** For each fixable ruling, in turn:
50
- - **Run `flag.procedure`** via `Bash`, verbatim (the ruling's own verification command). Capture pass/fail.
51
- - **If it passes already** (the tree may have drifted since validate), the ruling is cleared — record it and move on (no edit).
52
- - **If it fails**, Read/Grep the report body items tied to that ruling `id` (Risk Flag Rulings, Potential Issues, Automated Verification Results) and the plan flag's `claim` + cited `file:line`, then apply the **minimal localized code fix** — the smallest edit grounded in the current tree that makes `flag.procedure` pass. Then **re-run `flag.procedure`** and record the result. One fix attempt per ruling; never loop, never widen the edit, never `ask_user_question`.
53
- 6. **Emit the result.** If every fixable ruling's `procedure` now passes, print the success closing block (below) — the run is fully cleared. If a ruling's `procedure` still fails after its one localized fix, it is not localized either: print `remediation not localized: <ruling-id>` for each un-cleared ruling and OMIT the success closing block; the fixes already applied to cleared rulings stand (single-pass), and re-validate will catch what remains.
48
+
49
+ A `blockers` entry is **fixable** when it carries a concrete, non-empty `command` AND a `file` — the command is its procedure, the file its localization. An entry missing either is a **drift-escape**.
50
+ 4. **Drift-escape gate (checked BEFORE any edit).** If the work-list is empty (`verdict: fail` with no `pass: false` risk ruling and no `blockers` entry at all), print `remediation not localized: no-prescribed-rulings`, edit nothing, and stop. If ANY failed ruling or blocker is non-fixable, print `remediation not localized: <item-id>` for each non-fixable item, edit nothing, and stop. Either way, do NOT print the success closing block.
51
+ 5. **Repair pass — one cycle per fixable item (ruling or blocker), single-pass (no in-skill retry loop).** For each fixable item, in turn:
52
+ - **Run its verification command** via `Bash`, verbatim — a ruling's `flag.procedure`, a blocker's `command`. Capture pass/fail.
53
+ - **If it passes already** (the tree may have drifted since validate), the item is cleared — record it and move on (no edit).
54
+ - **If it fails**, Read/Grep the report body items tied to that item's `id` (Risk Flag Rulings, Potential Issues, Automated Verification Results) and its grounding — a ruling's plan-flag `claim` + cited `file:line`, a blocker's own `file`/`line` — then apply the **minimal localized code fix** — the smallest edit grounded in the current tree that makes the command pass. Then **re-run the command** and record the result. One fix attempt per item; never loop, never widen the edit, never `ask_user_question`.
55
+ 6. **Emit the result.** If every fixable item's command now passes, print the success closing block (below) — the run is fully cleared. If an item's command still fails after its one localized fix, it is not localized either: print `remediation not localized: <item-id>` for each un-cleared item and OMIT the success closing block; the fixes already applied to cleared items stand (single-pass), and re-validate will catch what remains.
54
56
 
55
57
  ## Hard rules
56
58
 
57
- - **Drift-escape, never an open-ended repair.** A failed ruling with no executable `procedure` (a `claim_type: mechanics` flag, a bare `{ id, claim }` flag), an empty work-list when `verdict: fail` has no `pass: false` risk ruling, or a fixable ruling whose `procedure` won't clear in one localized fix — each emits `remediation not localized: <ruling-id>` (or `remediation not localized: no-prescribed-rulings` for the empty case), and the success closing block is withheld. The upfront gate (non-fixable / empty) edits nothing and stops. Never `ask_user_question`, never widen into an un-prescribed repair, never re-run the project's whole build/test suite — that is the downstream validate gate's job.
59
+ - **Drift-escape, never an open-ended repair.** A failed ruling with no executable `procedure` (a `claim_type: mechanics` flag, a bare `{ id, claim }` flag), a `blockers` entry missing its `command` or `file`, an empty work-list when `verdict: fail` has no `pass: false` risk ruling and no `blockers` entry, or a fixable item whose command won't clear in one localized fix — each emits `remediation not localized: <item-id>` (or `remediation not localized: no-prescribed-rulings` for the empty case), and the success closing block is withheld. The upfront gate (non-fixable / empty) edits nothing and stops. Never `ask_user_question`, never widen into an un-prescribed repair, never re-run the project's whole build/test suite — that is the downstream validate gate's job.
58
60
  - **Surgical, single-pass.** Touch only the code a fixable ruling's `procedure` gates; leave passing rulings' code and untouched files byte-for-byte. One fix attempt per ruling — no in-skill retry loop. The validate gate re-judges; that is the validation.
59
61
  - **Fix the code, never the plan or any `.rpiv/artifacts/` document.** Remediate mutates the working tree only. Reading the plan/report to locate a ruling is required; editing the plan, the report, or any artifact is out of scope (that is amend's / revise's authority). The embedded code blocks in a spliced plan are the plan's own content too — remediate does not edit them either; it edits the repo files the ruling's `procedure` exercises.
60
62
  - **Never touch code a passing ruling owns.** A `pass: true` ruling's cited area is verified-correct; editing it risks regressing a cleared dimension.
@@ -63,11 +65,11 @@ If `--plans` or `--validation` is missing, print an error and stop — it is a d
63
65
 
64
66
  ## Closing block
65
67
 
66
- On a fully-cleared run (every failed ruling fixable, every `procedure` now passing), print:
68
+ On a fully-cleared run (every failed ruling/blocker fixable, every command now passing), print:
67
69
 
68
70
  ```
69
- Remediation complete: {N} failed ruling(s) addressed, {M} file(s) changed, {C} command(s) re-run (all pass).
70
- Rulings: {id1} ✓, {id2} ✓ …
71
+ Remediation complete: {N} failed item(s) addressed, {M} file(s) changed, {C} command(s) re-run (all pass).
72
+ Items: {id1} ✓, {id2} ✓ …
71
73
  Outstanding: none.
72
74
  ```
73
75
 
@@ -152,6 +152,7 @@ For each phase in the plan:
152
152
  - `verdict: pass` — every phase marked `- [x]` in the plan is verified against the code, every automated command passes (excluding whole-plan failures ruled pre-existing/non-blocking per Step 2.6), no Deviations from Plan and no Potential Issues require action, every plan `risks:` flag ruled `pass`, and every scope-floor finding and quarantine-manifest entry (Step 2.7) is explained.
153
153
  - `verdict: fail` — any phase fails verification, any automated command fails (excluding whole-plan failures ruled pre-existing/non-blocking per Step 2.6), any Deviations / Potential Issues list items that require action, **any plan risk flag ruled `pass: false`** (a flagged risk shipped unaddressed), or **any scope-floor finding or quarantined/refused file you could not rule benign** (Step 2.7).
154
154
  - When the plan carried a `risks:` array, add a `risk_rulings: [{ id, pass }]` field to the report frontmatter — one ruling per flag.
155
+ - When any failure forcing `verdict: fail` is NOT already captured by a `pass: false` risk ruling — a whole-plan gate command, or a phase's automated command failing on files inside the run's delta — add a `blockers:` array to the report frontmatter, one entry per failing command: `blockers: [{ id: b1, command: "<the failing command, verbatim-runnable from the repo root>", file: "<in-delta file the failure attributes to>", line: <line> }]` (`file`/`line` come from Step 2.6's attribution; number ids `b1`, `b2`, …). These structured entries are the ONLY handles the workflow's remediation arm may act on — a blocking failure recorded only in the report prose is invisible to it, and the run stops at the validate gate instead of looping. Omit the field when every blocking failure already rides a failing ruling.
155
156
 
156
157
  3. **Write the artifact** using the Write tool (no Edit — this skill writes once per run). Read `templates/validation.md`, fill every `{placeholder}` with the values determined above and the observations gathered in Step 2, apply the section-omission rules in the template (omit `#### Pattern Conformance:` and `#### Potential Issues:` entirely when empty; keep all other sections and emit `None — …` literals when empty), and Write the result to the target path.
157
158