Stabilize guarded model delivery
Add validated OpenCode-only delivery capabilities, canonical linked-worktree access checks, isolated candidate verification, and guarded main settlement. Wire the bounded reconnect-foreground controlled HTTP fixture through ordinary server construction so target verification obtains server-controlled provenance and rejects unknown or incompatible fixture evidence. Checked packaged templates and packaged authoring skill references; no updates are needed because this draft-only infrastructure activates no definition. Recorded the stale reference and activation guidance in docs/notes/delivery-stabilization.md for the docs fold.
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
package stage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// VerificationTarget declares the controlled fixture that can substantiate a
|
||||
// target-specific behavior claim. It is intentionally data-only: the runner
|
||||
// does not execute fixture input supplied by a stage result.
|
||||
type VerificationTarget struct {
|
||||
Backend string
|
||||
Revision string
|
||||
Capability string
|
||||
Fixture string
|
||||
}
|
||||
|
||||
// VerificationEvidence is returned by a server-controlled fixture workflow,
|
||||
// never parsed from a model's result.
|
||||
type VerificationEvidence struct {
|
||||
Backend string
|
||||
Revision string
|
||||
Capability string
|
||||
Fixture string
|
||||
}
|
||||
|
||||
// VerificationRunner is the narrow server seam for a controlled fixture or
|
||||
// workflow. The runner selects it during server setup; model output cannot
|
||||
// select a backend, revision, fixture, or executable.
|
||||
type VerificationRunner func(context.Context, VerificationTarget) (VerificationEvidence, error)
|
||||
|
||||
// VerificationTargetFor parses an optional, bounded verification block. A
|
||||
// declared target requires all provenance fields so an old or other-backend
|
||||
// fixture cannot be presented as evidence for the current target.
|
||||
func VerificationTargetFor(def Definition) (*VerificationTarget, error) {
|
||||
text, declared := def.Blocks["verification"]
|
||||
if !declared {
|
||||
return nil, nil
|
||||
}
|
||||
if len(text) > 4096 {
|
||||
return nil, fmt.Errorf("verification block exceeds 4096 bytes")
|
||||
}
|
||||
values := map[string]string{}
|
||||
for _, line := range strings.Split(text, "\n") {
|
||||
line = strings.TrimSpace(line)
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
key, value, ok := strings.Cut(line, "=")
|
||||
key, value = strings.TrimSpace(key), strings.TrimSpace(value)
|
||||
if !ok || value == "" || len(value) > 256 {
|
||||
return nil, fmt.Errorf("invalid verification entry %q", line)
|
||||
}
|
||||
switch key {
|
||||
case "backend", "revision", "capability", "fixture":
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown verification entry %q", key)
|
||||
}
|
||||
if _, exists := values[key]; exists {
|
||||
return nil, fmt.Errorf("duplicate verification entry %q", key)
|
||||
}
|
||||
values[key] = value
|
||||
}
|
||||
target := &VerificationTarget{Backend: values["backend"], Revision: values["revision"], Capability: values["capability"], Fixture: values["fixture"]}
|
||||
if target.Backend == "" || target.Revision == "" || target.Capability == "" || target.Fixture == "" {
|
||||
return nil, fmt.Errorf("verification requires backend, revision, capability, and fixture")
|
||||
}
|
||||
return target, nil
|
||||
}
|
||||
|
||||
// VerifyTargetEvidence compares server-collected controlled-fixture provenance
|
||||
// with the workflow declaration. It deliberately accepts no model result: a
|
||||
// stage cannot substantiate its own target-specific behavior claim.
|
||||
func VerifyTargetEvidence(target VerificationTarget, evidence VerificationEvidence) error {
|
||||
for key, want := range map[string]string{
|
||||
"backend": target.Backend, "revision": target.Revision, "capability": target.Capability, "fixture": target.Fixture,
|
||||
} {
|
||||
got := map[string]string{
|
||||
"backend": evidence.Backend, "revision": evidence.Revision, "capability": evidence.Capability, "fixture": evidence.Fixture,
|
||||
}[key]
|
||||
if got != want {
|
||||
return fmt.Errorf("verification evidence %s does not match declared target", key)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// VerifyTargetResult is retained for callers that only need declaration
|
||||
// validation. Result-provided provenance is intentionally not evidence.
|
||||
func VerifyTargetResult(def Definition, _ Values) error {
|
||||
target, err := VerificationTargetFor(def)
|
||||
if err != nil || target == nil {
|
||||
return err
|
||||
}
|
||||
return fmt.Errorf("verification target %q requires a server-controlled fixture runner", target.Fixture)
|
||||
}
|
||||
Reference in New Issue
Block a user