hutil

package
v0.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package hutil holds helpers shared by harness adapters.

Index

Constants

This section is empty.

Variables

View Source
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

func CheckHeaderValues(h map[string]string) error

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

func ClientModel(c harness.Context, alias string) string

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

func DeepMerge(dst, src map[string]any) map[string]any

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

func HasAuth(s policy.MCPServer) bool

HasAuth reports whether s declares an MCP authorization mode other than none.

func JSON

func JSON(v any) ([]byte, error)

JSON renders v deterministically: sorted keys (maps), 2-space indent, trailing newline.

func Join

func Join(os harness.OS, parts ...string) string

Join joins path parts with the separator of the target OS.

func MCPTokenHelper added in v0.4.0

func MCPTokenHelper(url string) string

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

func Model(p *policy.Profile, name string) string

Model is the default model alias for harness name: its own harnesses.<name>.model, else the profile's models.default.

func OTELResourceAttributes

func OTELResourceAttributes(name string, t policy.Telemetry, c harness.Context) string

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

func OTELShellWrapper(binary, attrs string) string

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

func PatchBefore(v string, major, minor, patch int) bool

PatchBefore reports whether a "major.minor.patch[...]" version is below major.minor.patch. Unparseable versions report false, like VersionBefore.

func PctEncode

func PctEncode(s string) string

PctEncode percent-encodes s for OTEL resource attributes (RFC 3986 unreserved kept).

func Populated

func Populated(p *policy.Profile) []string

Populated lists the profile fields that are set, by dotted name.

func ProtectedRules added in v0.4.0

func ProtectedRules(paths []string, absPrefix string) []string

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 Protocol

func Protocol(g *policy.Gateway, harnessName, def string) string

Protocol returns the gateway protocol configured for harness, or def.

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 ShQuote

func ShQuote(s string) string

ShQuote single-quotes s for POSIX sh.

func SortedKeys

func SortedKeys[V any](m map[string]V) []string

SortedKeys returns m's keys sorted.

func SplitPaths added in v0.4.0

func SplitPaths(paths []string, home bool) (ok, rest []string)

SplitPaths separates paths a system-wide file can name (absolute, or ~/ when home is true) from the rest (workspace-relative globs).

func VersionBefore

func VersionBefore(v string, major, minor int) bool

VersionBefore reports whether a "major.minor[.patch...]" version is below major.minor. Unparseable versions report false (nothing to warn about).

func WarnUnsupported

func WarnUnsupported(adapter string, p *policy.Profile, handled ...string) []string

WarnUnsupported returns one warning per populated profile field not in handled.

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.

Directories

Path Synopsis
Package hutiltest provides a shared rich fixture and golden-file helper for adapter tests.
Package hutiltest provides a shared rich fixture and golden-file helper for adapter tests.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL