@juicesharp/rpiv-pi 2.3.1 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/docs/workflows.md CHANGED
@@ -49,8 +49,8 @@ code is elaborated into it. Three automated gates plus one human checkpoint.
49
49
 
50
50
  `vet` and `polish` gate on the numeric `blockers_count` a `code-review`
51
51
  artifact reports: greater than zero routes back into a fix stage, zero routes to
52
- `commit`. The runner's default backward-jump budget is 2, so a review loop runs at
53
- most three times before the workflow stops looping.
52
+ `commit`. The runner's default backward-jump budget is 3, so a review loop runs at
53
+ most four times before the workflow stops looping.
54
54
 
55
55
  ## Hand-driven recipes
56
56
 
@@ -656,7 +656,7 @@ const polishWorkflow = defineWorkflow({
656
656
  validate: "code-review",
657
657
  // Backward edge: code-review → blueprint re-plans (implement needs a plan).
658
658
  // The iterate stage re-runs over every review phase; bounded by the
659
- // runner's default maxBackwardJumps (2 → up to 3 review iterations).
659
+ // runner's default maxBackwardJumps (3 → up to 4 review iterations).
660
660
  "code-review": gate("blockers_count", { blueprint: gt(0), commit: eq(0) }, "commit"),
661
661
  commit: "stop",
662
662
  },
@@ -2337,9 +2337,12 @@ const isTestPath = (target: string): boolean => TEST_PATH_RE.test(target);
2337
2337
  * Apply each `#### Reconciliation` directive, write-restricted to test-expectation
2338
2338
  * files (`isTestPath` — reconcile writes ONLY test files; a non-test target is a
2339
2339
  * finding, left untouched, fail-closed). A present `find` is replaced exactly
2340
- * once (`String.replace`, first match); an absent `find` whose `replace` is ALSO
2341
- * absent is a finding (reconcile does not guess); an absent `find` whose `replace`
2342
- * is already present is the idempotent-re-run no-op (a prior successful apply, no
2340
+ * once (`String.replace`, first match); an absent `find` whose `replace` is empty
2341
+ * is the idempotent-re-run no-op for a deletion (find-absent is the deletion's
2342
+ * success condition — the directive was already applied, no finding, no write); an
2343
+ * absent `find` whose non-empty `replace` is ALSO absent is a finding (reconcile
2344
+ * does not guess); an absent `find` whose non-empty `replace` is already present is
2345
+ * the idempotent-re-run no-op for a substitution (a prior successful apply, no
2343
2346
  * finding, no write). Paths resolve through `cwd` (`isAbsolute` short-circuit else
2344
2347
  * `join(cwd, target)`). Fail-soft: a read/apply throw degrades to a finding naming
2345
2348
  * the target, never a terminal throw. Returns findings in DIRECTIVE order and
@@ -2370,6 +2373,11 @@ const applyReconciliationDirectives = (
2370
2373
  // directive was already applied (e.g. a vet review-fix loop re-running
2371
2374
  // reconcile). Treated as satisfied — reconcile must not fail on its own
2372
2375
  // prior successful apply.
2376
+ } else if (d.replace === "") {
2377
+ // Idempotent re-run of a deletion: the find is gone and the replacement is
2378
+ // empty ⇒ find-absent is the deletion's success condition (a prior successful
2379
+ // apply removed it). Treated as satisfied — reconcile must not fail on its
2380
+ // own prior successful apply (e.g. a validate-fix loop re-running reconcile).
2373
2381
  } else {
2374
2382
  findings.push({
2375
2383
  detail: `reconcile: directive find substring not present in ${d.target} (and the replacement is absent — not already applied) — the expected text to replace is absent; the directive is stale or the test no longer matches`,
@@ -3576,7 +3584,7 @@ const vetWorkflow = defineWorkflow({
3576
3584
  // UNCHANGED. The scope-check inserts before validate, so a failing scope
3577
3585
  // verdict halts before re-review, and a passing one flows into validate and
3578
3586
  // back to code-review exactly as today. Bounded by the runner's default
3579
- // maxBackwardJumps (2 → at most 3 review iterations).
3587
+ // maxBackwardJumps (3 → at most 4 review iterations).
3580
3588
  validate: "code-review",
3581
3589
  commit: "stop",
3582
3590
  },
@@ -3788,6 +3796,15 @@ const buildWorkflow = defineWorkflow({
3788
3796
  // `from` form suppresses the READS_DATA outputSchema lint.
3789
3797
  reconcile: produces.script({ reads: ["plans"], run: reconcile }),
3790
3798
  validate: produces({ prompt: VALIDATE_GOAL_PROMPT }),
3799
+ // Repair arm the validate gate dispatches on a `verdict: "fail"`. `acts()`
3800
+ // (not `produces()`) because remediate is `side-effect`/`code-mutation` (the
3801
+ // tools twin of `implement`: re-runs verification commands via `Bash(*)` and
3802
+ // edits the working tree) — NOT produced-validating and NOT routed-on (its
3803
+ // edge is deterministic), so it owns no outcome. `reads: ["plans","validation"]`
3804
+ // ⇒ `stageEntryArgs` derives `--plans <plan> --validation <latest-report>`;
3805
+ // `validation` is validate's own publish bucket, so validate-fix always reads
3806
+ // the latest failing report.
3807
+ "validate-fix": acts({ skill: "remediate", reads: ["plans", "validation"] }),
3791
3808
  commit: acts({ prompt: COMMIT_BASELINE_PROMPT, outcome: gitCommitOutcome }),
3792
3809
  },
3793
3810
  edges: {
@@ -3810,7 +3827,7 @@ const buildWorkflow = defineWorkflow({
3810
3827
  { readsData: false },
3811
3828
  ),
3812
3829
  // Design-readiness gate BEFORE any design. Structure + design-readiness pass⇒ design; any fails ⇒
3813
- // slice-fix and loop back. Bounded by the runner's maxBackwardJumps (default 2).
3830
+ // slice-fix and loop back. Bounded by the runner's maxBackwardJumps (default 3).
3814
3831
  "slice-grade": defineRoute(
3815
3832
  ["slice-design", "slice-fix"],
3816
3833
  ({ state }) => (sliceGatePasses(state) ? "slice-design" : "slice-fix"),
@@ -3940,16 +3957,28 @@ const buildWorkflow = defineWorkflow({
3940
3957
  // `verdict: "pass"`. Sourced from the reconcile channel via the `from` form.
3941
3958
  reconcile: match("verdict", { validate: "pass" }, { from: "reconcile" }),
3942
3959
  // Gate commit on validate's own verdict — an unconditional `validate → commit`
3943
- // let a `verdict: fail` (incomplete goal coverage) commit anyway. `match` with
3944
- // no fallback commits ONLY on an explicit `verdict: "pass"`; every other value
3945
- // (a `fail`, or a missing verdict) routes to STOP — a failed validation halts
3946
- // WITHOUT committing, leaving the report on disk for the user. Safe by
3947
- // construction: the sole path to commit is an explicit pass, so un-anticipated
3948
- // data can never route INTO commit. Sourced from validate's published verdict
3949
- // channel (`from: "validation"` — the bucket its contract's `artifactKind`
3950
- // derives) — a prompt stage owns its message and can't inherit its contract's
3951
- // output schema, so route on the channel, not the raw (un-validated) stage output.
3952
- validate: match("verdict", { commit: "pass" }, { from: "validation" }),
3960
+ // let a `verdict: fail` (incomplete goal coverage) commit anyway. Now the
3961
+ // gate splits: `pass` ⇒ commit; `fail` ⇒ validate-fix (the repair arm above,
3962
+ // which re-runs the failing `verify-at-implement` risk-ruling procedures and
3963
+ // surgically fixes the tree, then re-enters at implement-scope-check to
3964
+ // re-reconcile + re-validate — bounded by the per-destination backward-jump
3965
+ // budget). Deliberately NOT a `fallback`: a missing/unexpected verdict stays
3966
+ // terminal STOP, so un-anticipated data can never route INTO commit OR the
3967
+ // repair arm. Safe by construction: the sole path to commit is an explicit
3968
+ // pass. The `match` branch key (`validate-fix`) doubles as the reachability/
3969
+ // stage declaration, so naming it both routes `fail` and declares the stage
3970
+ // reachable. Sourced from validate's published verdict channel
3971
+ // (`from: "validation"` — the bucket its contract's `artifactKind` derives) —
3972
+ // a prompt stage owns its message and can't inherit its contract's output
3973
+ // schema, so route on the channel, not the raw (un-validated) stage output.
3974
+ validate: match("verdict", { commit: "pass", "validate-fix": "fail" }, { from: "validation" }),
3975
+ // Deterministic re-entry after the repair arm: remediate's code-mutation is
3976
+ // followed by a fresh scope check → reconcile → validate pass, so a fix is
3977
+ // re-verified end-to-end before the gate re-folds. A non-counted edge (a
3978
+ // deterministic hop into the loop body), so it never trips a backward-jump
3979
+ // budget on its own — the budget-consuming decision edge is the validate
3980
+ // gate's `validate-fix` branch above.
3981
+ "validate-fix": "implement-scope-check",
3953
3982
  commit: "stop",
3954
3983
  },
3955
3984
  });
@@ -35,7 +35,7 @@ export const PIPELINE_POINTER = [
35
35
  "Other explicit-only commands: /skill:slice, /skill:revise, /skill:elaborate,",
36
36
  "/skill:architecture-review, /skill:frontend-design",
37
37
  "Workflow-internal (dispatched by lanes — never suggest): amend, design-slice,",
38
- "design-review, synthesize, grade",
38
+ "design-review, synthesize, grade, remediate",
39
39
  ].join("\n");
40
40
 
41
41
  export function injectPipelinePointer(pi: ExtensionAPI): void {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juicesharp/rpiv-pi",
3
- "version": "2.3.1",
3
+ "version": "2.4.0",
4
4
  "description": "A skill-based development workflow for Pi Agent. 27 contract-carrying skills (discover → research → design → plan → implement → validate → code-review → commit, and more), the 15 named subagents they dispatch, and three built-in /wf workflows that chain them end to end in detached parallel runs.",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -49,7 +49,7 @@
49
49
  ]
50
50
  },
51
51
  "dependencies": {
52
- "@juicesharp/rpiv-config": "^2.3.1",
52
+ "@juicesharp/rpiv-config": "^2.4.0",
53
53
  "typebox": "^1.1.24"
54
54
  },
55
55
  "peerDependencies": {
@@ -0,0 +1,73 @@
1
+ ---
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.
4
+ argument-hint: "--plans <plan-path> --validation <report-path>"
5
+ allowed-tools: Read, Edit, Write, Bash(*), Glob, Grep
6
+ shell-timeout: 10
7
+ disable-model-invocation: true
8
+ contract:
9
+ produces:
10
+ kind: side-effect
11
+ meta:
12
+ effect: code-mutation
13
+ consumes:
14
+ reads:
15
+ plans:
16
+ meta:
17
+ artifactKind: plan
18
+ validation:
19
+ meta:
20
+ artifactKind: validation
21
+ ---
22
+
23
+ # Remediate
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.
26
+
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
+
29
+ ## Input
30
+
31
+ `$ARGUMENTS` — flags the orchestrator wires from the gate's channels. Parse flag-style (order-agnostic), exactly like `amend`:
32
+
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 }]`.
35
+
36
+ If `--plans` or `--validation` is missing, print an error and stop — it is a dispatch error, not a failing phase.
37
+
38
+ ## Steps
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.
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
+ - `disposition: verify-at-implement` — the ruling the plan deferred to this exact repair arm;
44
+ - a concrete, non-empty `procedure` — the named command/test the ruling's own verification runs (the `owner` phase promised it);
45
+ - a numeric `owner` phase.
46
+
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.
54
+
55
+ ## Hard rules
56
+
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.
58
+ - **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
+ - **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
+ - **Never touch code a passing ruling owns.** A `pass: true` ruling's cited area is verified-correct; editing it risks regressing a cleared dimension.
61
+ - **No subagents. No self-review. No `ask_user_question`.** Apply the localized fixes and re-run the procedures; the validate gate is the validation.
62
+
63
+ ## Closing block
64
+
65
+ On a fully-cleared run (every failed ruling fixable, every `procedure` now passing), print:
66
+
67
+ ```
68
+ Remediation complete: {N} failed ruling(s) addressed, {M} file(s) changed, {C} command(s) re-run (all pass).
69
+ Rulings: {id1} ✓, {id2} ✓ …
70
+ Outstanding: none.
71
+ ```
72
+
73
+ Omit this block on any drift-escape — print only the `remediation not localized: …` line(s) and stop.