hcl

package
v1.133.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package hcl provides an HCL → YAML converter for docker-agent configuration files. The HCL surface mirrors the YAML schema with a few conventions:

  • Top-level keyed maps (agents, models, providers, mcps, rag) are written as labeled blocks, e.g. `agent "root" { ... }` becomes `agents: { root: { ... } }`.
  • Inside an agent, `command "name" { ... }` becomes `commands: { name: { ... } }`.
  • Toolsets use the label as the `type` field: `toolset "mcp" { ... }` becomes `toolsets: [{ type: mcp, ... }]`. At the top level, `toolsets "name" { ... }` instead defines a reusable, named toolset under `toolsets: { name: { ... } }`.
  • Multi-line strings should use heredocs. Because HCL templates expand `${...}` interpolation, any literal `${...}` (such as `${shell({cmd: "..."})}`) must be escaped as `$${...}`.
  • The custom `file("path")` function reads a UTF-8 text file and returns its contents as a string. An optional second argument renders the file as an HCL template, e.g. `file("prompt.md", { name = "Ada" })` expands `${name}` inside the file. Relative paths are resolved from the HCL config file's directory.

The converter does not validate the resulting document against the configuration schema; that is left to the existing YAML/JSON loader.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsHCLSource added in v1.132.0

func IsHCLSource(name string, data []byte) bool

IsHCLSource reports whether a source named name holding data should be parsed as HCL: the .hcl extension wins, otherwise the content is sniffed.

func LabelKeyedMapOutKeys

func LabelKeyedMapOutKeys() map[string]bool

LabelKeyedMapOutKeys returns the set of YAML keys produced by HCL block rules that map a labeled block into a label-keyed map (e.g. agent "x" {} becomes agents.x). It is exported so tests can verify the HCL conventions stay in sync with top-level keyed maps in the JSON schema.

func LooksLikeHCL

func LooksLikeHCL(data []byte) bool

LooksLikeHCL reports whether the given bytes look like an HCL document rather than a YAML one. The detection is heuristic and is intended for callers that do not have a filename hint to rely on (for example, OCI artifacts). It looks for top-level labeled blocks of the docker-agent HCL schema, e.g. `agent "..." {`, which are not valid YAML.

func ToMap

func ToMap(data []byte, filename string) (map[string]any, error)

ToMap parses an HCL document and returns a generic map that mirrors the structure of the equivalent YAML document.

func ToYAML

func ToYAML(data []byte, filename string) ([]byte, error)

ToYAML parses an HCL document and returns an equivalent YAML document that can be fed to the existing docker-agent config loader.

Types

type Source added in v1.132.0

type Source interface {
	Name() string
	ParentDir() string
	Read(ctx context.Context) ([]byte, error)
}

Source mirrors config.Source so this package can decorate agent sources without importing pkg/config.

func NewSource added in v1.132.0

func NewSource(inner Source) Source

NewSource decorates an agent source so HCL documents are transparently converted to YAML on read. Detection uses the source name's .hcl extension or, when that is absent (OCI artifacts, URLs), the content itself; anything else passes through untouched. config.Load only understands YAML, so wrap sources that may carry HCL before loading them.

Jump to

Keyboard shortcuts

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