ARTEX/agent/constraints.go

56 lines
3.5 KiB
Go

package agent
import (
"strings"
"github.com/Autumn-27/artex/db"
)
// constraintBlock renders this task's operation constraints (task_constraints) as a
// high-priority block appended to the planner/worker system prompt. allow/deny are
// grouped; empty string when there are no constraints (or ts is nil). The framing
// deliberately puts these ABOVE the exploration/expansion heuristics so a declared
// boundary wins the tug-of-war against "chase another entry surface".
func constraintBlock(ts *db.ExplorationStore) string {
if ts == nil {
return ""
}
rows, err := ts.ListConstraints()
if err != nil || len(rows) == 0 {
return ""
}
var allow, deny []string
for _, c := range rows {
text := strings.TrimSpace(c.Text)
if text == "" {
continue
}
if c.Kind == "allow" {
allow = append(allow, "- "+text)
} else {
deny = append(deny, "- "+text)
}
}
if len(allow) == 0 && len(deny) == 0 {
return ""
}
var b strings.Builder
b.WriteString("\n\n[Operation constraints (highest priority, above every exploration/expansion heuristic below; before generating any intent or executing any action you must first self-check for violations — if it violates a constraint, do not proceed)]:")
if len(allow) > 0 {
b.WriteString("\nAllowed operations:\n")
b.WriteString(strings.Join(allow, "\n"))
}
if len(deny) > 0 {
b.WriteString("\nForbidden operations:\n")
b.WriteString(strings.Join(deny, "\n"))
}
b.WriteString("\nRestrictions apply to the actual destination and operation, not merely to a URL's spelling or the tool used. A known alias/CNAME, origin IP, Host/SNI override, redirect, proxy/SSRF route, alternative port, tool, or entry point that reaches a denied target for the forbidden operation is still denied, even when that route is separately listed in scope. A scope listing, ordinary allowance, or goal/intent is not an exception to a deny. Do not retry a platform authorization denial through another tool or route. A platform authorization denial is not a target defense or HTTP error to bypass. These techniques remain usable for otherwise-authorized destinations and operations with no applicable denial; merely sharing infrastructure does not establish target equivalence. If a destination's scope is genuinely unclear, stop only that action and report the uncertainty; discovery does not grant authorization.")
b.WriteString("\n(Distinguish target-scope boundaries from method/operation permissions. " +
"Any allow entry naming a target, host, domain, URL, IP address, CIDR, or port is itself a binding target-scope boundary (a whitelist), even without an 'Authorized target scope:' prefix or the word 'only'. " +
"Bare entries such as '10.0.0.0/24' and 'app.example.com' restrict targets to the declared scope; they are not merely additional permissions. " +
"An allowance for an operation or method that does not name a target or port, such as 'Public proxies may be used.', is an additional permission, not a complete whitelist of otherwise-authorized work. " +
"Explicit scope declarations, restrictions (e.g. 'only', 'limited to', or exclusions), and every deny remain binding boundaries. " +
"Permission to use a method by itself neither requires that method nor expands target scope. A goal or assigned intent cannot override those boundaries. " +
"Newly discovered targets, ports, or hosts outside the operator's declared scope must be recorded as out-of-scope facts and skipped; do not spawn intents or execute actions for them.)")
return b.String()
}