Documentation
¶
Overview ¶
Package hutil holds helpers shared by harness adapters.
Index ¶
- Variables
- func CheckHeaderValues(h map[string]string) error
- func ClientModel(c harness.Context, alias string) string
- func DeepMerge(dst, src map[string]any) map[string]any
- func HasAuth(s policy.MCPServer) bool
- func JSON(v any) ([]byte, error)
- func Join(os harness.OS, parts ...string) string
- func MCPTokenHelper(url string) string
- func Model(p *policy.Profile, name string) string
- func OTELResourceAttributes(name string, t policy.Telemetry, c harness.Context) string
- func OTELShellWrapper(binary, attrs string) string
- func PatchBefore(v string, major, minor, patch int) bool
- func PctEncode(s string) string
- func Populated(p *policy.Profile) []string
- func ProtectedRules(paths []string, absPrefix string) []string
- func Protocol(g *policy.Gateway, harnessName, def string) string
- func RenderArtifacts(adapter string, os harness.OS, p *policy.Profile, ad ArtifactDirs) ([]harness.File, []string)
- func ShQuote(s string) string
- func SortedKeys[V any](m map[string]V) []string
- func SplitPaths(paths []string, home bool) (ok, rest []string)
- func VersionBefore(v string, major, minor int) bool
- func WarnUnsupported(adapter string, p *policy.Profile, handled ...string) []string
- type ArtifactDirs
Constants ¶
This section is empty.
Variables ¶
var SandboxPaths = []string{"permissions.sandbox", "egress.allowedDomains", "egress.default", "egress.deniedDomains", "egress.presets",
"sandbox.writableRoots", "sandbox.protectedPaths"}
SandboxPaths are the fields every egress/sandbox-aware adapter handles.
Functions ¶
func CheckHeaderValues ¶
CheckHeaderValues rejects header names or values containing CR or LF, which would let a value smuggle extra headers into newline-joined header lists.
func ClientModel ¶ added in v0.2.0
ClientModel is the model name a client should send for alias. Behind a gateway Halos runs (halo-proxy, kong) that is the alias itself; behind an external gateway nothing translates aliases, so it is the route's primary provider model id. An alias with no route is returned unchanged.
func DeepMerge ¶
DeepMerge merges src into dst recursively (maps merge, everything else is replaced by src) and returns dst. src is never aliased into dst.
func HasAuth ¶ added in v0.4.0
HasAuth reports whether s declares an MCP authorization mode other than none.
func MCPTokenHelper ¶ added in v0.4.0
MCPTokenHelper is the command a harness runs for a header-producing helper (Claude Code headersHelper) for a server with auth mode halos: it prints {"Authorization": "Bearer <token>"}, a token halo-server mints for exactly that server (ADR-0029). url is a validated registry URL (no quotes or spaces).
func Model ¶
Model is the default model alias for harness name: its own harnesses.<name>.model, else the profile's models.default.
func OTELResourceAttributes ¶
OTELResourceAttributes is the OTEL_RESOURCE_ATTRIBUTES value for harness name: the profile's telemetry.attributes plus halo.harness, halo.ring, halo.release and, for a variant release, halo.experiment/halo.variant. halo.* are set last so a profile attribute cannot spoof them.
func OTELShellWrapper ¶
OTELShellWrapper is a /etc/profile.d function that runs binary with the release's OTEL_RESOURCE_ATTRIBUTES, for CLIs whose config has no resource-attribute key (they all honor the env var; test/uat). A function, not an export: every harness sets halo.harness, so one global variable would mislabel the others. Like other profile.d settings it reaches login shells (and, exported, their bash children); an exec that bypasses the shell (timeout, env, xargs) runs the CLI unlabeled.
func PatchBefore ¶ added in v0.4.0
PatchBefore reports whether a "major.minor.patch[...]" version is below major.minor.patch. Unparseable versions report false, like VersionBefore.
func PctEncode ¶
PctEncode percent-encodes s for OTEL resource attributes (RFC 3986 unreserved kept).
func ProtectedRules ¶ added in v0.4.0
ProtectedRules turns sandbox.protectedPaths into Read and Edit permission rules (Claude Code rule syntax, which OpenCode's translation also reads). An absolute path gets absPrefix in front ("/" makes Claude's "//abs"), a relative one matches at any depth ("**/x"), and a path without a glob also covers everything below it.
func RenderArtifacts ¶ added in v0.4.0
func RenderArtifacts(adapter string, os harness.OS, p *policy.Profile, ad ArtifactDirs) ([]harness.File, []string)
RenderArtifacts places p.Resolved per ad and returns the files plus a warning for each artifact it cannot place.
func SortedKeys ¶
SortedKeys returns m's keys sorted.
func SplitPaths ¶ added in v0.4.0
SplitPaths separates paths a system-wide file can name (absolute, or ~/ when home is true) from the rest (workspace-relative globs).
func VersionBefore ¶
VersionBefore reports whether a "major.minor[.patch...]" version is below major.minor. Unparseable versions report false (nothing to warn about).
Types ¶
type ArtifactDirs ¶ added in v0.4.0
type ArtifactDirs struct {
Dirs map[string]string // kind -> directory for directory kinds
Single map[string]string // kind -> directory for one-Markdown-file kinds
Why map[string]string // kind -> why it is not rendered
}
ArtifactDirs says where an adapter places each supply-chain artifact kind (ADR-0028) on one OS: a directory kind lands as <dir>/<name>/<file>, a single-file kind as <dir>/<name>.md. A kind in neither map is warned, never dropped.