feat: recover inspected quarantined resources
Add local operator inspection and reconciliation for quarantined resource leases, including atomic audit-backed FIFO handoff and recovery protocol support.\n\nPreserve capability tokens in the authoritative store and reject non-loopback or ordinary client transport for recovery mutations.\n\nChecked packaged templates and packaged authoring skill references; none need updating. The task-owned docs note records shared README and skill reference follow-up for docs-fold.
This commit is contained in:
+76
-3
@@ -7,6 +7,7 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
@@ -36,7 +37,7 @@ type App struct {
|
||||
type options struct {
|
||||
harness string
|
||||
url, name, prompt, title, template, workspace, paths, key, opencode, model string
|
||||
option, feedback string
|
||||
option, feedback, evidence, actor string
|
||||
output string
|
||||
conflict string
|
||||
kind string
|
||||
@@ -45,7 +46,9 @@ type options struct {
|
||||
keepSet bool
|
||||
all bool
|
||||
json, source, noOpen, yes, allow, createOnly, force, wait bool
|
||||
version, expected, limit int
|
||||
version, expected, limit, recoverySequence int
|
||||
recoveryRun int64
|
||||
recoveryStage, resource string
|
||||
timeout, waitTimeout time.Duration
|
||||
stageModels stageModelFlags
|
||||
}
|
||||
@@ -177,6 +180,13 @@ func (a App) flags(command string) (*flag.FlagSet, *options) {
|
||||
case "decide":
|
||||
f.StringVar(&o.option, "option", "", "Option key to choose among the waiting stage's edges (required)")
|
||||
f.StringVar(&o.feedback, "feedback", "", "Optional free-text feedback recorded with the decision")
|
||||
case "resource-inspect":
|
||||
f.StringVar(&o.resource, "resource", "", "Exclusive resource key")
|
||||
case "resource-reconcile":
|
||||
f.StringVar(&o.evidence, "evidence", "", "Bounded positive cleanup/restoration evidence (required)")
|
||||
f.StringVar(&o.actor, "actor", "operator", "Bounded operator identity")
|
||||
f.BoolVar(&o.allow, "no-mutating-action", false, "Evidence explicitly records that no mutating action occurred")
|
||||
f.BoolVar(&o.yes, "yes", false, "Confirm reconciliation without prompting")
|
||||
case "debug":
|
||||
f.StringVar(&o.harness, "harness", "", "Debugging harness: configured opencode/pi, or nvim")
|
||||
f.BoolVar(&o.yes, "yes", false, "Approve opening a debugging session without prompting")
|
||||
@@ -462,8 +472,16 @@ func (a App) Run(ctx context.Context, args []string) error {
|
||||
if requestTimeout <= 0 {
|
||||
requestTimeout = 30 * time.Second
|
||||
}
|
||||
connectURL := o.url
|
||||
if command == "resource-inspect" || command == "resource-reconcile" {
|
||||
var transportErr error
|
||||
connectURL, transportErr = operatorTransportURL(o.url)
|
||||
if transportErr != nil {
|
||||
return transportErr
|
||||
}
|
||||
}
|
||||
dialCtx, cancel := context.WithTimeout(ctx, requestTimeout)
|
||||
c, err := client.Open(dialCtx, o.url)
|
||||
c, err := client.Open(dialCtx, connectURL)
|
||||
cancel()
|
||||
if err != nil {
|
||||
if command == "status" && len(pos) == 0 {
|
||||
@@ -897,6 +915,51 @@ func (a App) Run(ctx context.Context, args []string) error {
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("template %q not found", key)
|
||||
case "resource-inspect":
|
||||
if len(pos) > 1 {
|
||||
return fmt.Errorf("resource-inspect takes one resource key")
|
||||
}
|
||||
if o.resource == "" && len(pos) == 1 {
|
||||
o.resource = pos[0]
|
||||
}
|
||||
if strings.TrimSpace(o.resource) == "" {
|
||||
return fmt.Errorf("resource-inspect requires a resource key")
|
||||
}
|
||||
r, err := call(protocol.Message{Type: protocol.InspectResource, Resource: o.resource})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.ResourceInspection == nil {
|
||||
return fmt.Errorf("server did not return resource inspection")
|
||||
}
|
||||
return a.output(r.ResourceInspection)
|
||||
case "resource-reconcile":
|
||||
if len(pos) != 4 {
|
||||
return fmt.Errorf("resource-reconcile requires resource, run-id, stage and sequence")
|
||||
}
|
||||
runID, err := strconv.ParseInt(pos[1], 10, 64)
|
||||
if err != nil || runID <= 0 {
|
||||
return fmt.Errorf("run ID must be positive")
|
||||
}
|
||||
sequence, err := strconv.Atoi(pos[3])
|
||||
if err != nil || sequence <= 0 {
|
||||
return fmt.Errorf("sequence must be positive")
|
||||
}
|
||||
if strings.TrimSpace(o.evidence) == "" {
|
||||
return fmt.Errorf("--evidence is required")
|
||||
}
|
||||
if err := a.confirmAction(fmt.Sprintf("Reconcile quarantined resource %s for run #%d?", pos[0], runID), o.yes); err != nil {
|
||||
return err
|
||||
}
|
||||
r, err := call(protocol.Message{Type: protocol.ReconcileResource, Resource: pos[0], ResourceRecovery: &protocol.ResourceRecoveryRequest{Resource: pos[0], RunID: runID, Stage: pos[2], Sequence: sequence, Actor: o.actor, Evidence: &protocol.ResourceRecoveryEvidence{CleanupConfirmed: true, NoMutatingAction: o.allow, Summary: o.evidence}}})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if o.json {
|
||||
return a.output(r)
|
||||
}
|
||||
_, err = fmt.Fprintf(a.Out, "Reconciled resource %s for run #%d\n", pos[0], runID)
|
||||
return err
|
||||
case "inspect", "cancel", "retry":
|
||||
value, err := one()
|
||||
if err != nil {
|
||||
@@ -1039,6 +1102,16 @@ func (a App) Run(ctx context.Context, args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func operatorTransportURL(raw string) (string, error) {
|
||||
u, err := url.Parse(raw)
|
||||
if err != nil || u.Scheme == "" || u.Host == "" {
|
||||
return "", fmt.Errorf("invalid configured pipeline URL")
|
||||
}
|
||||
u.Path = "/operator-connect"
|
||||
u.RawPath = ""
|
||||
return u.String(), nil
|
||||
}
|
||||
|
||||
func (a App) output(value any) error {
|
||||
encoder := json.NewEncoder(a.Out)
|
||||
encoder.SetIndent("", " ")
|
||||
|
||||
Reference in New Issue
Block a user