Files
Agent-System/internal/taskrun/backend.go
T
weichenandCursor 7be873073c feat(taskrun): finalize RunManifest in one unit of work
CAS the unique terminal status with the assistant turn, frozen manifest, envelope and FAV staging, and join ctxmgr writes through the same UoW instead of a process mutex.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-15 02:05:58 +00:00

65 lines
1.6 KiB
Go

package taskrun
import (
"errors"
"strings"
)
var (
ErrUnauthorizedBackend = errors.New("taskrun: unauthorized backend")
ErrSensitivePayload = errors.New("taskrun: sensitive input rejected")
)
// Allowed backends are resolved by server policy. Callers cannot inject arbitrary strings.
var allowedBackends = map[string]struct{}{
"stub": {},
"pi-agent": {},
"cursor": {},
}
// ResolveBackend maps a caller hint onto the server allowlist.
// An empty requested value falls back to configured. Unauthorized values are rejected.
func ResolveBackend(requested, configured string) (string, error) {
requested = strings.TrimSpace(requested)
configured = strings.TrimSpace(configured)
if requested == "" {
if configured == "" {
return "stub", nil
}
if _, ok := allowedBackends[configured]; !ok {
return "", ErrUnauthorizedBackend
}
return configured, nil
}
if _, ok := allowedBackends[requested]; !ok {
return "", ErrUnauthorizedBackend
}
return requested, nil
}
func StripSecrets(meta map[string]any) map[string]any {
if meta == nil {
return map[string]any{}
}
out := make(map[string]any, len(meta))
for k, v := range meta {
lk := strings.ToLower(strings.TrimSpace(k))
if lk == "authorization" || lk == "api_key" || lk == "token" || lk == "password" ||
strings.Contains(lk, "secret") || strings.Contains(lk, "credential") {
continue
}
out[k] = v
}
return out
}
func rejectSensitiveText(parts ...string) error {
for _, p := range parts {
low := strings.ToLower(p)
if strings.Contains(low, "api_key=") || strings.Contains(low, "authorization: bearer") {
return ErrSensitivePayload
}
}
return nil
}