Commit 576675c2
576675c2fa8fMerged
Scott Nixon <[email protected]> ยท 5 months ago ยท 1 file ยท +1 added
Description
docs: add quality handler design spec
Details
- Commit
- 576675c2fa8f
- Parent
- a9bf1d319f13
docs/superpowers/specs/2026-06-03-quality-handler-design.mdaddedView file
1+
# Quality Handler Design2+
3+
**Date:** 2026-06-034+
**Status:** Approved5+
**Scope:** `crates/attractor-pipeline` only6+
7+
---8+
9+
## Overview10+
11+
Add a `quality` handler to PAS CLI that runs a suite of code quality checks as a pipeline node. Checks are real shell commands (static analysis, type checking, unit tests, lint) that run sequentially and return structured pass/fail output to the pipeline context. This replaces the current practice of using a `diamond` conditional node where Claude reviews its own code โ real tool exit codes replace Claude's self-assessment.12+
13+
The handler is enabled by default. Two mechanisms exist to disable it: a node attribute for static pipeline authoring, and a runtime context flag for callers like Reckoner.14+
15+
---16+
17+
## Problem18+
19+
The current `verify` node in PAS pipelines is a `diamond` (conditional) node where Claude reads its own code changes and outputs `PASS` or `FAIL`. This is unreliable โ Claude has no ground truth. Real quality checks (clippy, cargo test, ruff, tsc) have objective exit codes. The pipeline has no way to run those tools today except through the single-command `tool` handler (parallelogram), which can only run one command and writes no structured failure output for retry nodes to consume.20+
21+
---22+
23+
## Solution24+
25+
A new `quality` handler registered as handler type `"quality"`. Pipeline nodes opt into it via `node_type="quality"` on a `box`-shaped node. The handler runs a pipe-delimited list of commands from the `quality_checks` attribute, accumulates per-check results, writes a failure summary to context, and returns `Success` or `Fail` using the same `Outcome` struct as every other handler.26+
27+
---28+
29+
## DOT Schema30+
31+
```dot32+
verify [33+
shape="box"34+
node_type="quality"35+
label="Verify"36+
quality_checks="cargo fmt --check|cargo clippy -- -D warnings|cargo test --workspace"37+
goal_gate=true38+
retry_target="implement"39+
]40+
```41+
42+
### Node Attributes43+
44+
| Attribute | Type | Required | Default | Description |45+
|---|---|---|---|---|46+
| `quality_checks` | string | yes | โ | Pipe-delimited (`\|`) list of shell commands to run in order |47+
| `node_type` | string | yes | โ | Must be `"quality"` to invoke this handler |48+
| `enabled` | bool | no | `true` | Set `false` to disable all checks; handler returns `Success` immediately |49+
50+
`goal_gate` and `retry_target` are standard `PipelineNode` attributes and work unchanged โ no special treatment needed.51+
52+
### Runtime Context Flag53+
54+
| Key | Type | Description |55+
|---|---|---|56+
| `quality_disabled` | bool | When `true`, handler returns `Success` immediately regardless of `enabled` attribute |57+
58+
---59+
60+
## Execution Model61+
62+
Commands are run sequentially in the order they appear in `quality_checks`. Each command is executed via `tokio::process::Command` with `sh -c`, using the `workdir` from context as the working directory (same as `ToolHandler`).63+
64+
Execution is fail-fast: the first non-zero exit code stops the run. Remaining commands are not executed. The `results` context array contains entries only for commands that were actually run. The overall `Outcome` status is `Fail` if any executed command exited non-zero, `Success` if all exited zero.65+
66+
### Context Updates Written67+
68+
| Key | Type | Contents |69+
|---|---|---|70+
| `{node_id}.results` | JSON array | One object per check: `{cmd, exit_code, passed, stderr}` |71+
| `{node_id}.failure_summary` | string | Concatenated stderr from all failed checks โ intended for use in the retry node's prompt |72+
| `{node_id}.completed` | bool | Always `true` after handler runs |73+
74+
The retry node (`implement`) can reference `verify.failure_summary` in its prompt so Claude receives the actual error output rather than a vague "quality checks failed" message.75+
76+
---77+
78+
## Disable Behaviour79+
80+
Both disable paths return `StageStatus::Success` (not `Skipped`). This is deliberate: `StageStatus::Skipped` does not satisfy a `goal_gate` check in the engine, which would break pipelines that have `goal_gate=true` on the verify node. Returning `Success` means the pipeline continues normally regardless of whether checks actually ran.81+
82+
### Decision order (checked before any commands run)83+
84+
1. `node.raw_attrs["enabled"] == false` โ return `Success`, note: `"quality checks disabled (node)"`85+
2. `context["quality_disabled"] == true` โ return `Success`, note: `"quality checks disabled (runtime)"`86+
3. Run `quality_checks` commands sequentially87+
88+
### Behaviour table89+
90+
| State | Triggered by | Checks run | Returns | `goal_gate` satisfied |91+
|---|---|---|---|---|92+
| Enabled, all pass | default | yes | `Success` | yes |93+
| Enabled, any fail | default | yes | `Fail` | no โ retry |94+
| Disabled (node) | `enabled=false` | no | `Success` | yes |95+
| Disabled (runtime) | `quality_disabled=true` | no | `Success` | yes |96+
97+
---98+
99+
## Implementation100+
101+
### File102+
103+
`crates/attractor-pipeline/src/handlers/quality_handler.rs`104+
105+
### Registration106+
107+
Added to `default_registry()` in `crates/attractor-pipeline/src/handler.rs`:108+
109+
```rust110+
reg.register(crate::handlers::QualityHandler);111+
```112+
113+
Exported from `crates/attractor-pipeline/src/handlers/mod.rs`:114+
115+
```rust116+
pub mod quality_handler;117+
pub use quality_handler::QualityHandler;118+
```119+
120+
No new shape mapping needed in `HandlerRegistry::shape_to_type` โ the `node_type="quality"` attribute on a `box` node is resolved by the existing explicit `node_type` lookup (first priority in `resolve_type()`).121+
122+
### Structure (mirrors ToolHandler)123+
124+
```rust125+
pub struct QualityHandler;126+
127+
impl NodeHandler for QualityHandler {128+
fn handler_type(&self) -> &str { "quality" }129+
130+
async fn execute(&self, node: &PipelineNode, context: &Context, _graph: &PipelineGraph)131+
-> Result<Outcome>132+
{133+
// 1. Check enabled=false node attribute134+
// 2. Check quality_disabled context flag135+
// 3. Read quality_checks from raw_attrs, split on '|'136+
// 4. For each command: spawn via sh -c, capture stdout/stderr, record result137+
// 5. Build results JSON array and failure_summary string138+
// 6. Return Success or Fail with context updates139+
}140+
}141+
```142+
143+
### Timeout144+
145+
Uses `node.timeout` if set, falls back to 10 minutes (double the `ToolHandler` default of 5 min, since test suites can be slow). Applied per individual command, not across the whole suite.146+
147+
### Output truncation148+
149+
Per-command stderr is truncated to 8 KB before being written to context. `failure_summary` is the concatenation of truncated stderr from all failed checks. This keeps context size bounded when a noisy test suite fails.150+
151+
---152+
153+
## What Does Not Change154+
155+
- `goal_gate` + `retry_target` engine mechanics (no changes to `goal_gate.rs`)156+
- `NodeHandler` trait (no changes to `handler.rs` trait definition)157+
- `Context`, `Outcome`, `StageStatus` types (no changes to `attractor-types`)158+
- `HandlerRegistry` shape mappings (no new shape added)159+
- `ToolHandler` (not modified)160+
161+
---162+
163+
## Out of Scope164+
165+
The following are explicitly deferred and not part of this implementation:166+
167+
- `pas.toml` manifest file (SPEC-005) โ commands live inline in the DOT node for now168+
- Per-repo toolchain auto-detection โ pipeline author specifies commands explicitly169+
- Trust model for executing commands โ commands are in the DOT file under version control170+
- LLM enrichment of failure output โ raw stderr is sufficient for retry context171+
- Continue-on-failure mode โ all checks stop at first failure in v1 (configurable later via `fail_fast=false`)172+
173+
---174+
175+
## Example Pipeline176+
177+
```dot178+
digraph CodeFeature {179+
label="Implement and verify a feature"180+
model="sonnet"181+
182+
start [shape="Mdiamond"]183+
implement [shape="box", prompt="Implement the feature per the spec in .pas/spec.md"]184+
verify [shape="box", node_type="quality",185+
quality_checks="cargo fmt --check|cargo clippy -- -D warnings|cargo test --workspace",186+
goal_gate=true, retry_target="implement"]187+
done [shape="Msquare"]188+
189+
start -> implement -> verify -> done190+
}191+
```192+
193+
On failure, `verify.failure_summary` is available in context. The `implement` node prompt should reference it:194+
195+
```dot196+
implement [197+
shape="box"198+
prompt="Implement the feature per .pas/spec.md.199+
If context key 'verify.failure_summary' is set, fix the failures described there first."200+
]201+
```