config

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package config loads and validates the portable project configuration (.idea-harness/project.yaml and harness.yaml) against embedded JSON Schemas (§28, §30). It also enforces that secrets never live in the portable tree.

Index

Constants

View Source
const Dir = ".idea-harness"

Dir is the portable config directory name inside a project.

Variables

View Source
var Presets = []Preset{
	{Key: "openai", Label: "OpenAI", Type: ProviderOpenAI, BaseURL: "https://api.openai.com/v1", DefaultKeyEnv: "OPENAI_API_KEY", NeedsKey: true},
	{Key: "anthropic", Label: "Anthropic", Type: ProviderAnthropic, BaseURL: "https://api.anthropic.com/v1", DefaultKeyEnv: "ANTHROPIC_API_KEY", NeedsKey: true},
	{Key: "gemini", Label: "Google Gemini", Type: ProviderGemini, BaseURL: "https://generativelanguage.googleapis.com/v1beta", DefaultKeyEnv: "GOOGLE_API_KEY", NeedsKey: true},
	{Key: "deepseek", Label: "DeepSeek", Type: ProviderOpenAI, BaseURL: "https://api.deepseek.com/v1", DefaultKeyEnv: "DEEPSEEK_API_KEY", NeedsKey: true},
	{Key: "openrouter", Label: "OpenRouter", Type: ProviderOpenAI, BaseURL: "https://openrouter.ai/api/v1", DefaultKeyEnv: "OPENROUTER_API_KEY", NeedsKey: true},
	{Key: "ollama", Label: "Ollama (local)", Type: ProviderOpenAI, BaseURL: "http://localhost:11434/v1", DefaultKeyEnv: "", NeedsKey: false},
}

Presets are the built-in providers (§10, §41). OpenRouter and Ollama speak the OpenAI-compatible wire format with different endpoints; Gemini and Anthropic use native APIs.

Functions

func HarnessTopLevelKeys added in v0.4.0

func HarnessTopLevelKeys() []string

HarnessTopLevelKeys returns the field names harness.yaml accepts at its top level, from the schema that validates it.

This exists so advice about harness.yaml can be checked against harness.yaml. `idea reviews` recommended `set tests_cmd in harness.yaml`, built by concatenating a finding category with "_cmd"; the field is `test_cmd`, and following the advice literally made `idea config validate` exit 1 with `additional properties 'tests_cmd' not allowed`. Nothing tied the prose to the schema, so nothing caught it.

func HasErrors

func HasErrors(problems []Problem) bool

HasErrors reports whether any problem is error-severity.

func IsLoopbackHost added in v0.5.0

func IsLoopbackHost(host string) bool

IsLoopbackHost reports whether host names this machine: "localhost" in any case, or any loopback IP (all of 127.0.0.0/8, and ::1).

func LoadDotEnv

func LoadDotEnv(dir string) map[string]string

LoadDotEnv reads a .env file (KEY=VALUE, with optional `export` prefix and quotes) and returns its values. Values are used only as a fallback to the real process environment for secret resolution (§47). No interpolation or shell expansion is performed.

func ParseModelSpec

func ParseModelSpec(spec string) (provider, model string)

ParseModelSpec splits a "provider/model" default-model string into its provider and model parts. A model with no "/" returns ("", model); the caller applies the default provider. Splitting is on the FIRST slash so OpenRouter model ids like "anthropic/claude-3.7-sonnet" remain intact.

func ValidateBaseURL

func ValidateBaseURL(raw string) error

ValidateBaseURL requires https, except on loopback where http is the norm for local runtimes (ollama, LM Studio). Plain http to any other host puts the API key and the prompt on the wire in the clear.

func ValidateProvider

func ValidateProvider(name string, pc ProviderConfig) error

ValidateProvider checks one provider entry on the WRITE path (and, via Problems, on a hand-edited harness.yaml). A provider entry decides where prompts and an API key are sent, so it is validated before it is stored, not when it is first used.

func WriteHarness

func WriteHarness(dir string, h HarnessConfig) error

WriteHarness writes harness.yaml to dir, applying defaults first. It is the single write path for provider/model configuration (§47: no secrets written — only *_env references are permitted).

Types

type CheckConfig

type CheckConfig struct {
	Image string `json:"image,omitempty" yaml:"image,omitempty"`
}

CheckConfig configures the deterministic build/test check sandbox (review H3). The image must contain the project's toolchain (e.g. golang:1.25, node:22).

type Config

type Config struct {
	Project ProjectConfig
	Harness HarnessConfig
}

Config is the fully-loaded portable configuration for one project.

func Default

func Default() Config

Default returns the default configuration. The network is disabled by default so research never silently exfiltrates local content (§15). The executor defaults to the deterministic internal executor.

func Load

func Load(dir string) (Config, error)

Load reads and validates project.yaml and harness.yaml from dir. Missing files fall back to Default(); present files are strictly validated against the raw document (so unknown fields and inline secrets are rejected, not silently dropped).

func (Config) Problems

func (c Config) Problems() []Problem

Problems reports configuration findings that Load deliberately does not turn into load errors (§D5): a config that is wrong must still open, or upgrading the binary would brick an existing project. Callers render these; nothing here mutates or rejects.

func (Config) ProblemsWithEnv

func (c Config) ProblemsWithEnv(dotEnv map[string]string) []Problem

ProblemsWithEnv is Problems with the project's .env as a fallback for API-key resolution, matching how the daemon resolves keys (runtime.go lookupEnv).

type DemoConfig added in v0.4.0

type DemoConfig struct {
	// BlockReviewCycles makes the demo provider's adversarial reviewer emit a
	// blocking finding for this many review calls before reverting to its usual
	// empty list. Set it to `review.max_cycles` to make the PRD review park the
	// initiative on a human.
	//
	// A count consumed from a queue, not a flag, because all three adversarial
	// reviews share the schema name `review` and a flag would block the plan and
	// change-set reviews too. M1's review cycles are the first calls a run makes,
	// so the queue drains on exactly them.
	BlockReviewCycles int `json:"block_review_cycles,omitempty" yaml:"block_review_cycles,omitempty"`
	// BlockPlanReviewCycles does the same for the M2 execution-plan review.
	// A separate queue from the PRD review's, because they are separate reviews
	// with separate escapes -- and because one shared queue could spill a
	// leftover blocker onto the change-set review, which nothing can clear.
	//
	// Unclamped, unlike BlockReviewCycles: `idea revise-plan` clears a plan
	// review however many times it blocks, so a surplus is survivable here.
	BlockPlanReviewCycles int `json:"block_plan_review_cycles,omitempty" yaml:"block_plan_review_cycles,omitempty"`
	// BlockChangeSetReviewCycles does the same for the M3 change-set review.
	//
	// Its own queue, on its own key, for the reason the plan review needed one:
	// the change-set review shared the `review` key with the PRD review, so
	// there was no way to make it block without a leftover PRD response landing
	// here -- and no way to reach the state where a human must accept a change
	// set the reviewer will not pass. That state was a live-lock the keyed
	// magic path hit every run, and no demo configuration could produce it.
	BlockChangeSetReviewCycles int `json:"block_change_set_review_cycles,omitempty" yaml:"block_change_set_review_cycles,omitempty"`
	// DanglePlanDependency makes the first execution plan name a dependency no
	// task provides, which parks the initiative on `plan_dependencies` -- the
	// one judgment reason whose fix is regenerating the plan and never
	// approving it.
	DanglePlanDependency bool `json:"dangle_plan_dependency,omitempty" yaml:"dangle_plan_dependency,omitempty"`
}

DemoConfig steers the built-in demo provider.

It exists because the demo reviewer returned zero findings unconditionally, so the review loop always converged and `needs_human_judgment` was structurally unreachable on the only path CI, scripts/smoke.sh and six DX audits ever ran. A P0 that fails 4/4 on the README's own quick start survived six rounds in that blind spot.

Declared config rather than a magic string in the idea text: the marker would have ridden into the PRD, the task title, the placeholder file and the change-set patch -- and from there into the *change-set* reviewer, which shares the schema name `review`, where a blocking finding is unrecoverable.

type ExecutorConfig

type ExecutorConfig struct {
	Kind  ExecutorKind `json:"kind" yaml:"kind"`
	Image string       `json:"image,omitempty" yaml:"image,omitempty"`
	Model string       `json:"model,omitempty" yaml:"model,omitempty"`
}

ExecutorConfig selects and configures the execute-pipeline executor. Image is the container image for the container kind; Model is the coding model for the OMP kind. Neither is read by the internal kind.

type ExecutorKind

type ExecutorKind string

ExecutorKind selects the coding executor the execute pipeline uses (§48–§52).

const (
	ExecutorInternal  ExecutorKind = "internal"
	ExecutorContainer ExecutorKind = "container"
	ExecutorOMP       ExecutorKind = "omp"
	ExecutorHermes    ExecutorKind = "hermes"
)

func (ExecutorKind) Valid

func (k ExecutorKind) Valid() bool

type HarnessConfig

type HarnessConfig struct {
	Network      NetworkPolicy             `json:"network" yaml:"network"`
	Review       ReviewConfig              `json:"review" yaml:"review"`
	Research     ResearchConfig            `json:"research" yaml:"research"`
	Providers    map[string]ProviderConfig `json:"providers" yaml:"providers"`
	DefaultModel string                    `json:"default_model" yaml:"default_model"`
	Executor     ExecutorConfig            `json:"executor" yaml:"executor"`
	Check        CheckConfig               `json:"check" yaml:"check"`
	// Models is the per-role model map: role name → "provider/model". Roles
	// without an entry fall back to default_model (§40). The coding "implementer"
	// role is a valid key here, letting OMP/Hermes run different models.
	Models map[string]string `json:"models" yaml:"models"`
	// BuildCmd/TestCmd are the deterministic check commands (review B5). They are
	// config-supplied, never model/agent output; when empty the corresponding
	// check is recorded not_applicable.
	BuildCmd string `json:"build_cmd,omitempty" yaml:"build_cmd,omitempty"`
	TestCmd  string `json:"test_cmd,omitempty" yaml:"test_cmd,omitempty"`
	// CheckTimeoutSeconds bounds each deterministic build/test check. Zero uses
	// the default of 600s (10m) (review SRE).
	CheckTimeoutSeconds int `json:"check_timeout_seconds,omitempty" yaml:"check_timeout_seconds,omitempty"`
	// GitCommit opts into creating a git commit (with repo hooks disabled) for
	// each applied change set (§M7). Off by default: a hook runs arbitrary code
	// under the daemon's privileged environment, so this must never be implied.
	GitCommit bool `json:"git_commit" yaml:"git_commit"`
	// Demo configures the built-in deterministic provider. It does nothing when
	// a real provider is configured.
	Demo DemoConfig `json:"demo,omitempty" yaml:"demo,omitempty"`
}

HarnessConfig is harness.yaml (portable, committable).

type NetworkPolicy

type NetworkPolicy string

NetworkPolicy is the v0.1 network mode (§46).

const (
	NetworkDisabled NetworkPolicy = "disabled"
	NetworkEnabled  NetworkPolicy = "enabled"
)

func (NetworkPolicy) Valid

func (n NetworkPolicy) Valid() bool

type ParseError added in v0.4.0

type ParseError struct {
	// File, relative to the project root — never the absolute path.
	File string
	Msg  string
}

ParseError is a malformed config file: the user's YAML, not the daemon's fault. Both shapes it can take — YAML that does not parse, and YAML that parses but the schema rejects — because the second is the more common one and they are the same problem to a caller: this file has to be edited before any request against this project can succeed.

It used to travel as a bare fmt.Errorf, so every project-scoped handler mapped it to 404 — `config.Load` runs inside EnsureProject, and a failure there is indistinguishable from "no such project" to the caller. That violated the spec's own NotFound contract ("the message names the kind and the reference that was asked for") and leaked an absolute filesystem path into the response, which InternalError explicitly promises never happens.

500 is the wrong repair: internal/daemon/errors.go reserves it for "the daemon's problem", and telling a client to retry a syntax error in a file only the user can fix is worse than the 404 was. So this carries enough for a 4xx that names the file, the line, and nothing else.

func (*ParseError) Error added in v0.4.0

func (e *ParseError) Error() string

type Preset

type Preset struct {
	Key           string
	Label         string
	Type          ProviderType
	BaseURL       string
	DefaultKeyEnv string
	NeedsKey      bool
}

Preset is a well-known provider preset used for config resolution and UI.

func PresetFor

func PresetFor(key string) *Preset

PresetFor returns the preset matching a provider key, or nil for a custom key.

type Problem

type Problem struct {
	Severity Severity `json:"severity"`
	Field    string   `json:"field"`
	Message  string   `json:"message"`
	// EnvDependent marks a problem whose answer depends on which process asked.
	// Only the missing-key check is: it resolves the variable with os.Getenv, so
	// the CLI sees the shell you typed in while the run is made by the daemon,
	// which read its own environment once at start. `idea doctor` drops these
	// and asks the daemon instead.
	//
	// A field rather than matching the message text: the first version of this
	// matched a substring, and rewording the message silently un-marked it.
	EnvDependent bool `json:"-"`
}

Problem is one configuration finding. Field is the harness.yaml path it came from so the operator knows which line to edit.

func UnknownModelProblems

func UnknownModelProblems(field, spec string) []Problem

unknownModelProblems warns when the model half of a spec matches no catalog entry for a provider whose catalog is known.

Nothing validated the model half at all, so `idea model set anthropic/claude-3-7-sonnet` printed success and the first call came back a non-retryable 404 -- and nine such ids shipped in the documentation before an audit caught them by reading.

A warning, not an error: a valid model can postdate the bundled catalog, and refusing it would make the tool unusable the week a provider ships something. openrouter and ollama are skipped entirely: openrouter's ids are arbitrary upstream strings, and ollama serves whatever the operator has pulled locally. For both, the bundled catalog cannot be authoritative by construction, so a warning there would be noise on correct configurations.

type ProjectConfig

type ProjectConfig struct {
	Name string `json:"name" yaml:"name"`
}

ProjectConfig is project.yaml (portable, committable).

type ProviderConfig

type ProviderConfig struct {
	Type      ProviderType `json:"type" yaml:"type"`
	APIKeyEnv string       `json:"api_key_env" yaml:"api_key_env"`
	BaseURL   string       `json:"base_url" yaml:"base_url"`
	Models    []string     `json:"models" yaml:"models"`
}

ProviderConfig describes one model provider (§40). API keys are resolved from the environment variable named by APIKeyEnv — never stored inline. Type and BaseURL are optional: when empty they are derived from the provider key's preset (see providers.go).

type ProviderType

type ProviderType string

ProviderType is the wire protocol a provider speaks.

const (
	ProviderOpenAI    ProviderType = "openai"    // OpenAI-compatible chat completions
	ProviderAnthropic ProviderType = "anthropic" // Anthropic messages API
	ProviderGemini    ProviderType = "gemini"    // Google generative-language API
)

func ResolveProvider

func ResolveProvider(key string, pc ProviderConfig) (ProviderType, string, string)

ResolveProvider derives the effective type, base URL, and key-env name for a provider entry, falling back to the preset for known keys (§40).

func (ProviderType) Valid

func (t ProviderType) Valid() bool

type ResearchConfig

type ResearchConfig struct {
	URLs []string `json:"urls" yaml:"urls"`
}

ResearchConfig controls the research web tool (§46). URLs are seed sources fetched (public-address-only) during the research stage when network is enabled.

type ReviewConfig

type ReviewConfig struct {
	MaxCycles  int     `json:"max_cycles" yaml:"max_cycles"`
	MaxTokens  int64   `json:"max_tokens" yaml:"max_tokens"`
	MaxCostUSD float64 `json:"max_cost_usd" yaml:"max_cost_usd"`
}

ReviewConfig is the review budget (§11, §16).

type Severity

type Severity string

Severity classifies a Problem. An error means the configuration cannot do what it says (a model spec that resolves to no provider, an endpoint that would ship credentials off-box); a warn means it will work but degrade — most commonly demo mode, which is a legitimate way to run the product.

const (
	SeverityError Severity = "error"
	SeverityWarn  Severity = "warn"
)

Jump to

Keyboard shortcuts

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