Files
archie/modules/judgement/guards.go
T
sam 0dbf241106 feat(judgement): the weakest-link decision, and executing only what was judged (#1986, #1989, #1990, #1988)
A new judgement module assesses one concrete action: hard rules refuse before
any guard runs; every guard sets a ceiling and the action runs at the lowest;
a guard that fails, panics or gives no ceiling holds it at propose and wait;
an advisory verdict is recorded and sets no ceiling. Reversibility and
Precedent (the fresh-install class default) are the first guards. Every
decision is recorded with its verdicts and class, and the run's trail lists
them. Agent tools now offer connector actions too: each call is assessed and
executed only as decided and only with the judged input, and a held action
comes back to the agent as a failed call naming its level and findings.
Tools gain Resolve, so an MCP server's declared effect reaches judgement.
2026-11-16 01:05:29 +11:00

54 lines
2.0 KiB
Go

package judgement
import (
"context"
"errors"
"github.com/samcharles93/archie-core/modules/connectors"
)
// Reversibility sets a ceiling from whether the action can be undone, as the
// connector declares it.
type Reversibility struct{}
// Name is the guard's name in verdicts.
func (Reversibility) Name() string { return "reversibility" }
// Advisory is false: the declaration is data, not a model's opinion.
func (Reversibility) Advisory() bool { return false }
// Judge maps the declared reversibility to a ceiling. An action that declares
// none lacks the evidence this guard needs.
func (Reversibility) Judge(_ context.Context, a Action) (Verdict, error) {
switch {
case a.Effect.ReadOnly:
return Verdict{Ceiling: ActQuietly}, nil
case a.Effect.Reversibility == connectors.UndoneAutomatically:
return Verdict{Ceiling: ActQuietly, Findings: []Finding{{Text: "undone automatically"}}}, nil
case a.Effect.Reversibility == connectors.Recoverable || a.Target.Disposable:
return Verdict{Ceiling: ActAndTell, Findings: []Finding{{Text: "recoverable, or the target is disposable"}}}, nil
case a.Effect.Reversibility == connectors.Irreversible:
return Verdict{Ceiling: ProposeAndWait, Findings: []Finding{{Text: "irreversible"}}}, nil
}
return Verdict{}, errors.New("the connector declares no reversibility for this action")
}
// Precedent sets a ceiling from the action class's earned level. Until a
// class has history, it is the fresh-install default: read-only classes act
// quietly, every other class proposes and waits.
type Precedent struct{}
// Name is the guard's name in verdicts.
func (Precedent) Name() string { return "precedent" }
// Advisory is false.
func (Precedent) Advisory() bool { return false }
// Judge returns the class's level.
func (Precedent) Judge(_ context.Context, a Action) (Verdict, error) {
if a.Effect.ReadOnly {
return Verdict{Ceiling: ActQuietly}, nil
}
return Verdict{Ceiling: ProposeAndWait, Findings: []Finding{{Text: "this action class has no approvals yet"}}}, nil
}