Merge main (findings ledger, loop continuation) into usage-limit branch

Keeps the findings ledger, extra visits and on_exhausted=decide alongside the
run budget, failure classes, quota parking and error-loop backoff.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 14:35:54 +00:00
66 changed files with 3565 additions and 148 deletions
+15 -1
View File
@@ -59,6 +59,7 @@ type options struct {
transcripts bool
step int
version, expected, limit, retryVisit int
extraVisits int
timeout, waitTimeout time.Duration
stageModels stageModelFlags
// quotaNow / quotaDefer choose what run and retry do about a known usage
@@ -225,6 +226,7 @@ func (a App) flags(command string) (*flag.FlagSet, *options) {
f.StringVar(&o.retryMode, "mode", "resume", "Retry mode: resume failed stage or restart from entry")
f.StringVar(&o.retryStage, "stage", "", "Retry this recorded stage (required when it was visited more than once)")
f.IntVar(&o.retryVisit, "visit", 0, "1-based occurrence of --stage in the recorded execution")
f.IntVar(&o.extraVisits, "extra-visits", 0, "Grant 1-5 extra visits and continue an exhausted loop; with --stage, only that stage gets them")
f.IntVar(&o.version, "version", 0, "Explicit published version of the same pipeline (default: source version)")
f.StringVar(&o.retryInputFile, "input-file", "", "JSON object merged into the selected stage input; '-' reads stdin")
f.StringVar(&o.notifyMode, "notify", "auto", "Notifications for this retry: auto, on, or off")
@@ -1092,7 +1094,19 @@ func (a App) Run(ctx context.Context, args []string) error {
if err != nil {
return err
}
r, err := call(protocol.Message{Type: typeName, RunID: id, RequestKey: key, RetryMode: o.retryMode, RetryStage: o.retryStage, RetryVisit: o.retryVisit, RetryVersion: o.version, RetryInput: retryInput, NotifyMode: o.notifyMode, QuotaPolicy: policy, BudgetUSD: o.budgetUSD})
message := protocol.Message{Type: typeName, RunID: id, RequestKey: key, RetryMode: o.retryMode, RetryStage: o.retryStage, RetryVisit: o.retryVisit, RetryVersion: o.version, RetryInput: retryInput, NotifyMode: o.notifyMode, QuotaPolicy: policy, BudgetUSD: o.budgetUSD}
if o.extraVisits != 0 {
if o.extraVisits < 1 || o.extraVisits > 5 {
return fmt.Errorf("--extra-visits must be from 1 to 5")
}
if o.retryVisit > 0 {
return fmt.Errorf("--visit cannot be combined with --extra-visits; --stage names the stage that gets the extra visits")
}
// With --extra-visits, --stage names the stage granted the
// visits; the resume point is the exhausted loop itself.
message.RetryExtraVisits, message.RetryExtraStage, message.RetryStage = o.extraVisits, o.retryStage, ""
}
r, err := call(message)
if err != nil {
return quotaHint(err)
}
+2 -2
View File
@@ -29,7 +29,7 @@ var usage = map[string]string{
"resume": "resume <run-id> [--yes] [--json]",
"run-budget": "run-budget [USD|off] [--json]",
"decide": "decide <run-id> [stage] --option KEY [--feedback TEXT] [--json]",
"retry": "retry <run-id> [--yes] [--mode resume|restart] [--stage KEY [--visit N]] [--version N] [--input-file FILE|-] [--budget USD] [--now | --defer] [--json [--wait [--wait-timeout DURATION]]]",
"retry": "retry <run-id> [--yes] [--mode resume|restart] [--stage KEY [--visit N]] [--extra-visits N [--stage KEY]] [--version N] [--input-file FILE|-] [--budget USD] [--now | --defer] [--json [--wait [--wait-timeout DURATION]]]",
"title": "title <run-id> \"<title>\" [--json]",
"debug": "debug <run-id> [--json | --no-open]",
"chat-adopt": "chat-adopt <session-id> [--harness opencode|claude|codex] [--title TEXT] [--json]",
@@ -57,7 +57,7 @@ var notes = map[string]string{
"validate": "Uses the same server parser as submission. Does not persist or activate schedules. Structural validity does not prove runtime/tool availability.",
"submit": "Confirm publication at the prompt, or use --yes for explicit automation; schedules activate on acceptance. Managed drafts provide the name and base-version guard. --force never bypasses validation.",
"run": "Runs in your current directory after action confirmation (--yes skips it). Select a pipeline and compose a multiline task with Ctrl+S. Stage tools are enabled automatically; no file list or typed RUN confirmation. Cancellation does not undo edits. --title sets an explicit run title; without it the title is derived from the prompt. --model PROVIDER/MODEL overrides the model for every stage of that run; --stage-model STAGE=PROVIDER/MODEL overrides one stage and is repeatable, with a repeated key last-wins. Precedence is per-stage > whole-run > the model pinned in the pipeline version; overrides apply to that run only and never change the pinned definition. An unknown stage key or a malformed provider/model is refused before the run starts, naming the valid stage keys. In JSON mode --wait polls until terminal; --wait-timeout bounds only the client wait after admission and is independent of per-request --timeout. A reached wait limit leaves the run active: inspect read-only with `inspect <run-id> --json`, or reattach with --wait reusing the original --request-key (never an automatic replay or cancel).",
"retry": "Resume a failed or interrupted run's stage by default (an interrupted run resumes its unfinished stage, or the one after its last completed stage), restoring the completed prefix handoff; use --mode=restart to start at entry. --stage selects a recorded stage (use --visit for repeated stages). --input-file accepts a bounded JSON object, merged with replacement at the selected stage and shown to it as an Operator correction; the retried stage also sees why the previous attempt failed; '-' reads stdin. Original history and pinned identity are retained; --version selects an explicit published version of the same pipeline only. --wait-timeout leaves an active retry for later read-only inspection or reattachment with the original --request-key, rather than starting a duplicate retry.",
"retry": "Resume a failed or interrupted run's stage by default (an interrupted run resumes its unfinished stage, or the one after its last completed stage), restoring the completed prefix handoff; use --mode=restart to start at entry. --stage selects a recorded stage (use --visit for repeated stages). --extra-visits N (1-5) continues a loop that exhausted its visits (max_visits, the five-visit or 30-step cap) where it stopped, granting N more visits to the exhausted stage(s), or with --stage to that stage only. --input-file accepts a bounded JSON object, merged with replacement at the selected stage and shown to it as an Operator correction; the retried stage also sees why the previous attempt failed; '-' reads stdin. Original history and pinned identity are retained; --version selects an explicit published version of the same pipeline only. --wait-timeout leaves an active retry for later read-only inspection or reattachment with the original --request-key, rather than starting a duplicate retry.",
"list": "Lists active pipelines. Archived pipelines are hidden; --archived lists only them and --all lists both, marking archived ones with their archive time.",
"archive": "Retire a pipeline from lists after confirmation (--yes for scripts). Nothing is deleted: versions, runs, artifacts and search history stay and keep its name. An archived pipeline cannot start runs and its name stays reserved (new/submit say so). Archiving is refused while an enabled schedule points at it, naming the schedule; pause or repoint it first. The latest version is sent as a guard, so a publication in between is refused.",
"unarchive": "Return an archived pipeline to lists; it can run and take new versions again. Schedules stay paused until you enable them.",
+14
View File
@@ -3,6 +3,7 @@ package cli
import (
"encoding/json"
"fmt"
"sort"
"strings"
"unicode/utf8"
@@ -54,6 +55,19 @@ func inspectSummary(d *protocol.RunDetail) string {
if next := waitingHint(d); next != "" {
b.WriteString("\n" + next + "\n")
}
b.WriteString(inspectFindings(d))
if len(d.VisitGrants) > 0 {
keys := make([]string, 0, len(d.VisitGrants))
for key := range d.VisitGrants {
keys = append(keys, key)
}
sort.Strings(keys)
parts := make([]string, 0, len(keys))
for _, key := range keys {
parts = append(parts, fmt.Sprintf("%s +%d", key, d.VisitGrants[key]))
}
b.WriteString("\nextra visits: " + strings.Join(parts, ", ") + "\n")
}
if next := quotaWaitLine(d); next != "" {
b.WriteString("\n" + next + "\n")
}
+66
View File
@@ -0,0 +1,66 @@
package cli
import (
"fmt"
"strings"
"git.a-wan.net/alan/pipelines/internal/findings"
"git.a-wan.net/alan/pipelines/internal/protocol"
)
// inspectFindingsOpenCap bounds the open findings the compact summary lists;
// --json carries the whole ledger with every status change.
const inspectFindingsOpenCap = 20
// inspectFindings is the compact summary's findings section: counts per
// status, then the open findings (most severe first) and the closed ones by
// ID. Empty when the run has no ledger.
func inspectFindings(d *protocol.RunDetail) string {
if len(d.Findings) == 0 {
return ""
}
counts := findings.Counts(d.Findings)
var b strings.Builder
fmt.Fprintf(&b, "\nfindings: %d open, %d fixed, %d dismissed, %d settled\n", counts[protocol.FindingOpen], counts[protocol.FindingFixed], counts[protocol.FindingDismissed], counts[protocol.FindingSettled])
shown := 0
for _, severity := range append(append([]string(nil), findings.Severities...), "") {
for _, item := range d.Findings {
if item.Status != protocol.FindingOpen || (severity != "" && item.Severity != severity) || (severity == "" && findings.SeverityRank(item.Severity) >= 0) {
continue
}
if shown == inspectFindingsOpenCap {
fmt.Fprintf(&b, " … %d more open (--json)\n", counts[protocol.FindingOpen]-shown)
shown++
}
if shown > inspectFindingsOpenCap {
continue
}
shown++
b.WriteString(" " + findingLine(item) + "\n")
}
}
for _, status := range []string{protocol.FindingFixed, protocol.FindingDismissed, protocol.FindingSettled} {
var ids []string
for _, item := range d.Findings {
if item.Status == status {
ids = append(ids, item.ID)
}
}
if len(ids) > 0 {
fmt.Fprintf(&b, " %s: %s\n", status, strings.Join(ids, ", "))
}
}
return b.String()
}
func findingLine(item protocol.Finding) string {
line := fmt.Sprintf("%s %s · %s · %s", item.ID, item.Status, item.Severity, item.Origin)
if item.Location != "" {
line += " · " + item.Location
}
line += " — " + item.Summary
if item.Reason != "" {
line += " (" + item.Reason + ")"
}
return line
}
+33
View File
@@ -0,0 +1,33 @@
package cli
import (
"bytes"
"strings"
"testing"
"git.a-wan.net/alan/pipelines/internal/protocol"
)
func TestInspectShowsFindingsAndVisitGrants(t *testing.T) {
run := sampleRun()
run.Findings = []protocol.Finding{
{ID: "F1", Severity: "nit", Origin: "introduced", Summary: "naming", Status: "open"},
{ID: "F2", Severity: "critical", Origin: "introduced", Location: "a.go:3", Summary: "panic", Status: "open"},
{ID: "F3", Severity: "important", Origin: "pre-existing", Summary: "old", Status: "dismissed", Reason: "not ours"},
{ID: "F4", Severity: "minor", Origin: "introduced", Summary: "doc", Status: "fixed"},
}
run.VisitGrants = map[string]int{"review": 1}
var out bytes.Buffer
if err := (App{Out: &out}).inspect(run, &options{}); err != nil {
t.Fatal(err)
}
text := out.String()
for _, want := range []string{"findings: 2 open, 1 fixed, 1 dismissed, 0 settled", " F2 open · critical · introduced · a.go:3 — panic", " fixed: F4", " dismissed: F3", "extra visits: review +1"} {
if !strings.Contains(text, want) {
t.Fatalf("inspect missing %q:\n%s", want, text)
}
}
if strings.Index(text, "F2 open") > strings.Index(text, "F1 open") {
t.Fatalf("open findings not most severe first:\n%s", text)
}
}