ARTEX-English/program/fence.go
skilfoy bd502401a3 Add a fail-closed scope gate and an engagement desk.
A loaded range-scope file denies tool input that names anything outside it. Worker text that re-enters the planner is fenced. The desk keeps the engagement graph, run log, fireteam, and score, and only opens when a scope is installed.
2026-10-24 23:49:22 +00:00

39 lines
1,006 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package program
import "strings"
const endMarker = "<<<END UNTRUSTED>>>"
// WrapUntrusted fences text that came from a tool or a worker before that
// text is placed back into a prompt. The body is data. Markers inside the
// body are broken so the body cannot close the fence early.
func WrapUntrusted(text, label string) string {
text = strings.TrimSpace(text)
if text == "" {
return ""
}
if strings.HasPrefix(text, "<<<UNTRUSTED ") {
return text
}
label = cleanLabel(label)
return "<<<UNTRUSTED " + label + ">>>\n" + breakMarkers(text) + "\n" + endMarker
}
func cleanLabel(label string) string {
label = breakMarkers(label)
label = strings.Map(func(r rune) rune {
if r == '<' || r == '>' || r == '\n' || r == '\r' {
return '-'
}
return r
}, label)
if label == "" {
return "TEXT"
}
return label
}
func breakMarkers(text string) string {
text = strings.ReplaceAll(text, endMarker, "‹‹‹END UNTRUSTED›››")
return strings.ReplaceAll(text, "<<<", "‹‹‹")
}