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:
@@ -14,6 +14,77 @@ type ArtifactAccess struct {
|
||||
Read []string
|
||||
}
|
||||
|
||||
// LandingAccess is the server-derived external capability for a verified
|
||||
// delivery operation. Empty or malformed values grant nothing.
|
||||
type LandingAccess struct {
|
||||
MainWorktree string
|
||||
GitMetadata string
|
||||
LockPath string
|
||||
}
|
||||
|
||||
func (a LandingAccess) valid() bool {
|
||||
for _, path := range []string{a.MainWorktree, a.GitMetadata, a.LockPath} {
|
||||
if path == "" || !filepath.IsAbs(path) || filepath.Clean(path) != path || strings.ContainsAny(path, "*?\\") {
|
||||
return false
|
||||
}
|
||||
}
|
||||
// The server grants the canonical repository metadata directory as OpenCode
|
||||
// V2's smallest external-directory unit. Keep the lock inside that directory
|
||||
// so a caller cannot turn a valid metadata capability into access elsewhere.
|
||||
return a.GitMetadata == filepath.Join(a.MainWorktree, ".git") &&
|
||||
a.LockPath == filepath.Join(a.GitMetadata, "pipelines-landing.lock")
|
||||
}
|
||||
|
||||
// DeliveryEnabled is the narrow, declarative capability check used before the
|
||||
// runner supplies any landing paths. Only a validated model definition can ask
|
||||
// for it; runtime paths are still derived by the server.
|
||||
func DeliveryEnabled(def Definition) (bool, error) {
|
||||
delivery := def.Configs["delivery"]
|
||||
if delivery == "" {
|
||||
return false, nil
|
||||
}
|
||||
if delivery != "true" {
|
||||
return false, fmt.Errorf("delivery must be true when set")
|
||||
}
|
||||
if EffectiveType(def.Type) != ModelType {
|
||||
return false, fmt.Errorf("delivery is supported only by model stages")
|
||||
}
|
||||
if _, err := (ModelStage{}).Spec(def); err != nil {
|
||||
return false, fmt.Errorf("invalid delivery model stage: %w", err)
|
||||
}
|
||||
if _, err := DeliveryChecks(def); err != nil {
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// DeliveryChecks returns the bounded, definition-declared checks that the
|
||||
// runner executes against a committed delivery candidate before canonical main
|
||||
// is changed. They
|
||||
// are intentionally a block rather than a generic runner setting: each
|
||||
// workflow owns its repository-specific verification commands.
|
||||
func DeliveryChecks(def Definition) ([]string, error) {
|
||||
text := strings.TrimSpace(def.Blocks["checks"])
|
||||
if text == "" {
|
||||
return nil, fmt.Errorf("delivery stages require a nonempty checks block")
|
||||
}
|
||||
var checks []string
|
||||
for _, line := range strings.Split(text, "\n") {
|
||||
check := strings.TrimSpace(line)
|
||||
if check == "" {
|
||||
continue
|
||||
}
|
||||
if len(check) > 4096 {
|
||||
return nil, fmt.Errorf("delivery check exceeds 4096 bytes")
|
||||
}
|
||||
checks = append(checks, check)
|
||||
}
|
||||
if len(checks) == 0 || len(checks) > 20 {
|
||||
return nil, fmt.Errorf("delivery stages require 1 to 20 checks")
|
||||
}
|
||||
return checks, nil
|
||||
}
|
||||
|
||||
// ToolNames validates model-stage permissions, not general graph semantics.
|
||||
// A present empty block explicitly denies all tools.
|
||||
func ToolNames(def Definition) ([]string, bool, error) {
|
||||
@@ -155,6 +226,10 @@ func (c *AgentClient) permissionRules() []map[string]string {
|
||||
allow("external_directory", filepath.ToSlash(filepath.Join(c.ArtifactAccess.Write, "*")))
|
||||
allow("edit", filepath.ToSlash(filepath.Join(c.ArtifactAccess.Write, "*")))
|
||||
}
|
||||
if c.LandingAccess.valid() {
|
||||
allow("external_directory", filepath.ToSlash(filepath.Join(c.LandingAccess.MainWorktree, "*")))
|
||||
allow("external_directory", filepath.ToSlash(filepath.Join(c.LandingAccess.GitMetadata, "*")))
|
||||
}
|
||||
for _, pattern := range []string{"../*", "*/../*"} {
|
||||
rules = append(rules, map[string]string{"action": "external_directory", "resource": pattern, "effect": "deny"})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user