deploy / plan (push) Successful in 6s
deploy / archied-image (push) Canceled after 0s
deploy / agent-image (push) Canceled after 0s
deploy / dist-zip (push) Canceled after 0s
ci/woodpecker/push/deploy Pipeline was canceled
deploy / gate (push) Canceled after 2m58s
54 lines
1.8 KiB
Go
54 lines
1.8 KiB
Go
package agent
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/samcharles93/archie-core/internal/prompts"
|
|
)
|
|
|
|
// MaxSoulBytes bounds a SOUL document. Its body renders into the prompt ahead
|
|
// of the rules, so an oversized one cannot crowd them out.
|
|
const MaxSoulBytes = 8 << 10
|
|
|
|
// Soul is the control-plane document holding an identity's SOUL text. Empty
|
|
// Text means no stored SOUL: the loader falls back to the identity's file and
|
|
// then the shipped default, and the first save takes ownership.
|
|
type Soul struct {
|
|
Text string `json:"text"`
|
|
}
|
|
|
|
// Validate bounds the SOUL document's size. Empty is valid: it means unowned.
|
|
func (s Soul) Validate() error {
|
|
if len(s.Text) > MaxSoulBytes {
|
|
return fmt.Errorf("soul: %d bytes exceeds the %d-byte limit", len(s.Text), MaxSoulBytes)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ShippedSoul returns the SOUL document this build ships.
|
|
func ShippedSoul() string {
|
|
return prompts.Soul()
|
|
}
|
|
|
|
// SoulMatchesShipped reports whether content equals shipped after line-ending
|
|
// and trailing-whitespace normalisation.
|
|
func SoulMatchesShipped(content, shipped string) bool {
|
|
return normalizeSoul(content) == normalizeSoul(shipped)
|
|
}
|
|
|
|
// normalizeSoul reduces a SOUL body to the content a user authored: a UTF-8
|
|
// BOM is dropped, CRLF and lone CR become LF, and trailing whitespace is
|
|
// removed from every line and from the end of the document. None of that
|
|
// carries intent, so it must not make an untouched template look edited.
|
|
func normalizeSoul(content string) string {
|
|
content = strings.TrimPrefix(content, "\ufeff")
|
|
content = strings.ReplaceAll(content, "\r\n", "\n")
|
|
content = strings.ReplaceAll(content, "\r", "\n")
|
|
lines := strings.Split(content, "\n")
|
|
for index, line := range lines {
|
|
lines[index] = strings.TrimRight(line, " \t")
|
|
}
|
|
return strings.TrimRight(strings.Join(lines, "\n"), "\n")
|
|
}
|