From fd140314c3ecbed01c16123f44de5d66ff3b00f5 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Sat, 3 Oct 2026 21:56:41 +1000 Subject: [PATCH] refactor(config): cut comments down to what the code does --- internal/config/chat_frontends.go | 25 +-- internal/config/config.go | 359 ++++++------------------------ internal/config/curator.go | 6 +- internal/config/holder.go | 60 +---- internal/config/reload.go | 7 +- internal/config/secret_ref.go | 15 +- internal/config/services.go | 50 +---- internal/config/servicespec.go | 22 +- 8 files changed, 102 insertions(+), 442 deletions(-) diff --git a/internal/config/chat_frontends.go b/internal/config/chat_frontends.go index 04bddec1a..bf967f608 100644 --- a/internal/config/chat_frontends.go +++ b/internal/config/chat_frontends.go @@ -2,33 +2,16 @@ package config import "strings" -// ChatFrontEnd is one conversational front-end [chat] can enable. -// -// It carries the answer to "is this front-end configured", and nothing else: -// which process starts it, whether it can be reloaded, and what an operator -// reads about it are channel-lifecycle facts that belong to the daemon, not to -// configuration. ID is the stable identifier every surface keys on (the -// dashboard's channel list, the channel reload route). +// ChatFrontEnd is one conversational front-end [chat] can enable. ID is its +// stable identifier. type ChatFrontEnd struct { ID string Name string Configured bool } -// FrontEnds reports every conversational front-end this configuration enables, -// in the order the dashboard lists them. -// -// This is the single definition of "a chat channel is configured". It exists -// because that question used to be answered twice from the same config and the -// two answers drifted: the daemon's channel status manager counted the inbound -// mail gateway, and the dashboard projection published for the extracted UI -// process did not, so an email-only deployment read as configured on -// /api/channels and unconfigured on the setup checklist at the same time. -// Front-ends are enumerated once here so a front-end added to -// [chat] cannot be counted by one surface and missed by the other. -// -// A whitespace-only value is not configured on any front-end: an env var name -// of " " resolves to nothing, and an address of " " cannot be listened on. +// FrontEnds returns every chat front-end this configuration enables, in +// dashboard order. Whitespace-only values do not count as configured. func (c ChatConfig) FrontEnds() []ChatFrontEnd { return []ChatFrontEnd{ { diff --git a/internal/config/config.go b/internal/config/config.go index aa4c43c24..ffebe3425 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -1,14 +1,5 @@ -// Package config holds archied's configuration types. -// -// Loading them -- locating files, decoding TOML and YAML, applying overlays, -// defaulting and validating -- belongs to -// internal/infrastructure/configuration. This package no longer performs any -// I/O, so importing a settings type no longer drags in a file decoder. -// -// The forge API token is deliberately not part of the file: it comes from a -// configurable env var. -// -// Do not add new fields here that a single domain could own. +// Package config holds archied's configuration types. Loading lives in +// internal/infrastructure/configuration. package config import ( @@ -54,12 +45,9 @@ type Repo struct { Name string `toml:"name" json:"name" yaml:"name"` // Base is the branch PRs target. Defaults to "main". Base string `toml:"base" json:"base" yaml:"base"` - // Gate is the quality-gate command list for this repo, e.g. - // [["go","vet","./..."], ["task","check"]]. By convention the - // LAST command is the test runner -- TDD workflows invert only - // that one with ExpectFailure during the repro stage and re-run - // it in capture-proof. Workflow stages may extend or override - // Gate (a TDD repro stage inverts the test command). + // Gate is the repo's gate command list, e.g. [["go","vet","./..."], + // ["task","check"]]. The last command is the test runner, which TDD's repro + // stage expects to fail. Gate [][]string `toml:"gate" json:"gate" yaml:"gate"` // Protect lists path suffixes agents must never write directly -- // generated files (e.g. "_templ.go") whose sources they should edit @@ -86,11 +74,8 @@ type Repo struct { // being permanently parked (status "dead"). 0 means use the // global Config.MaxRetries. MaxRetries int `toml:"max_retries" json:"max_retries" yaml:"max_retries"` - // AllowConcurrent lets the daemon dispatch multiple tasks for this - // repo at once instead of the default FIFO one-task-per-repo - // serialization. Only safe for repos where concurrent worktrees - // won't collide (e.g. different base branches or packages per - // task). Still bounded by [containers].max_concurrency globally. + // AllowConcurrent lets several tasks run for this repo at once instead of + // one at a time. AllowConcurrent bool `toml:"allow_concurrent" json:"allow_concurrent" yaml:"allow_concurrent"` } @@ -300,20 +285,13 @@ type MCPServer struct { // empty, the client discovers it from the server's "endpoint" SSE event. MessageEndpoint string `toml:"message_endpoint" yaml:"message_endpoint" json:"message_endpoint,omitempty"` - // ParallelToolCalls lifts the client's serialization of tools/call for - // this server only, letting concurrent callers overlap. Default false: - // one call in flight at a time, because most MCP servers are - // single-threaded processes that do not handle concurrent requests - // safely. Set it only for a server whose implementation does. + // ParallelToolCalls allows concurrent tool calls to this server. Default + // false: one call at a time. ParallelToolCalls bool `toml:"parallel_tool_calls" yaml:"parallel_tool_calls" json:"parallel_tool_calls"` } -// ToolPolicy holds tool execution limits. -// -// The size limits use a negative value for "no limit". Defaulting cannot -// distinguish an explicit 0 from an absent key, so zero has to stay available -// as "unset, give me the default" -- which leaves negative as the only way an -// operator can turn a cap off deliberately. +// ToolPolicy holds tool execution limits. A negative size limit means no +// limit; zero means the default. type ToolPolicy struct { // MaxResultChars caps a single tool result before it reaches the model. // Tools that set ToolEntry.MaxResultSizeChars override it. @@ -327,12 +305,8 @@ type ToolPolicy struct { // WebFetchConfig controls the web_fetch tool. type WebFetchConfig struct { - // Enabled advertises the tool to the model. Nil means unset, which - // defaults to true. - // - // This is a pointer rather than a bool because defaulting cannot tell - // `enabled = false` from an absent key, and turning the tool off has to - // be expressible. Use IsEnabled rather than reading it directly. + // Enabled advertises the tool to the model; nil means true. Read it with + // IsEnabled. Enabled *bool `toml:"enabled" yaml:"enabled" json:"enabled"` // Timeout bounds one fetch including redirects. @@ -352,11 +326,7 @@ type WebFetchConfig struct { // absent setting as enabled. func (c WebFetchConfig) IsEnabled() bool { return c.Enabled == nil || *c.Enabled } -// MinimaxConfig controls the generate_video tool -// (internal/tools/minimax). Unlike WebFetchConfig, absent is disabled, not -// enabled: web_fetch needs no credential and is safe as a silent default, -// while this tool spends real API credits per call, so it stays off until -// an operator explicitly turns it on and supplies a key. +// MinimaxConfig controls the generate_video tool. Disabled unless configured. type MinimaxConfig struct { // Enabled advertises the tool. Defaults to false (see the type doc). Enabled bool `toml:"enabled" yaml:"enabled" json:"enabled"` @@ -386,12 +356,8 @@ type ToolsConfig struct { type Config struct { Services Services `toml:"services" yaml:"services"` WorkDir string `toml:"work_dir" yaml:"work_dir"` - // SkillsDir is an optional path to a shared skills directory - // containing */SKILL.md files. When set, the - // daemon builds its workflow registry from the skill catalog - // (plugin-defined workflows override built-ins). When empty, - // only built-in workflows are available. Its skills are also the - // store a Kit's agent-skills@1 mounts, read-only, into the harness. + // SkillsDir is an optional directory of */SKILL.md skills. Its workflows + // override built-ins, and Kits mount it read-only. SkillsDir string `toml:"skills_dir" yaml:"skills_dir"` // WorkflowRoutingFile is an optional path to a YAML file rebinding which // registered workflow an intake Kind (bug/feature/bootstrap) prefers. @@ -401,40 +367,20 @@ type Config struct { // workflows (e.g. A label already owned by the kind set, or a duplicate // binding, is a load failure per the design doc's collision rule. WorkflowLabelsFile string `toml:"workflow_labels_file" yaml:"workflow_labels_file"` - // PlaybookDirs is an optional list of directories of *.yaml/*.yml binding - // files loaded at startup. Each file binds kinds and/or arbitrary labels to - // workflow names; the directories are an additional input to - // WorkflowRoutingFile and WorkflowLabelsFile, which remain supported - // unchanged. A binding key declared by more than one source -- two files, - // or two directories -- is a reported load failure (a collision), not a - // silent pick-one. When empty, no playbook directories are loaded. - // Repo-scoping of playbook dirs is a separate, later decision and is not - // attempted here. + // PlaybookDirs are optional directories of kind/label-to-workflow binding + // files. A key bound in more than one file is a load error. PlaybookDirs []string `toml:"playbook_dirs" yaml:"playbook_dirs"` - // EDAPlaybookDir is an optional path to a directory of rich EDA playbook - // documents (*.yaml/*.yml: trigger + ordered actions with CEL `when` - // conditions, dispatched by the event coordinator). This is DISTINCT - // from PlaybookDirs, which holds FLAT binding files (kind/label -> - // workflow name) consumed by the routing loaders. A playbook here is a - // document (one trigger plus ordered actions: either exactly one - // workflow action or one or more module actions); a binding file there - // is a map of keys. When empty, no EDA playbook documents are loaded. + // EDAPlaybookDir is an optional directory of EDA playbook documents: a + // trigger plus ordered actions with CEL conditions. EDAPlaybookDir string `toml:"eda_playbook_dir" yaml:"eda_playbook_dir"` // MaxRetries caps how many times a parked task is retried before // being permanently parked (status "dead"). Defaults to 3. MaxRetries int `toml:"max_retries" yaml:"max_retries"` - // PluginDir is an optional path to a directory of Yaegi-interpreted - // daemon plugins (*.go files). Each file must export a "Plugin" - // variable satisfying the plugin.Plugin interface. Failed plugins - // are skipped -- the daemon starts with the remaining set. When - // empty, no daemon plugins are loaded. + // PluginDir is an optional directory of Yaegi daemon plugins (*.go), each + // exporting a "Plugin" variable. Failed plugins are skipped. PluginDir string `toml:"plugin_dir" yaml:"plugin_dir"` - // ModuleDir is an optional path to a directory of Yaegi-interpreted - // Module action implementations (*.go files, one per kind: log.go for - // the log kind). Each file must export a "Run" function matching the - // kind's generated contract. A broken module is a startup failure -- - // the daemon does not start with a partial module set. When empty, no - // modules are loaded. + // ModuleDir is an optional directory of Yaegi module implementations, one + // *.go file per kind exporting "Run". A broken module stops startup. ModuleDir string `toml:"module_dir" yaml:"module_dir"` // SecretEngineDir contains Yaegi secret-engine plugins. Built-in env and // bws engines remain available when this is empty. @@ -443,12 +389,8 @@ type Config struct { // embedded NATS store and its endpoint file, the task-log registry, and // the readiness disk probe's data target. Bootstrap-only. StateDir string `toml:"state_dir" yaml:"state_dir"` - // DatabaseURL is the PostgreSQL connection URL the standalone State Store - // process opens at boot. It is bootstrap-only (the same class as - // state_dir and work_dir): the pool is opened once, so a runtime change cannot take - // effect, and it is refused by the runtime overlay. It has no default -- - // an empty value is a startup error for the State Store, which fails - // closed rather than fall back to SQLite (the epic is Postgres-only). + // DatabaseURL is the PostgreSQL URL the State Store opens at boot. Required; + // bootstrap-only. DatabaseURL string `toml:"database_url" yaml:"database_url"` PollInterval Duration `toml:"poll_interval" yaml:"poll_interval"` // Label marks issues archie should pick up. @@ -459,22 +401,14 @@ type Config struct { // A credential binding whose Org does not match a run's identity never // resolves for it, regardless of what the identity is granted. Org string `toml:"org" yaml:"org"` - // GrantedCredentials names the credential@1 services this identity may use, - // by CredentialBinding.Service. Empty grants none -- a binding existing is - // not a grant, the same fail-closed default the proxy itself already - // applies to an unbound required credential. Declared (what a Kit's - // descriptor asks for) and granted (this list) are two separate facts; only - // their intersection resolves, and neither widens the other. + // GrantedCredentials names the credential services this identity may use. + // Empty grants none. GrantedCredentials []string `toml:"granted_credentials" yaml:"granted_credentials"` // BotEmail is the git author email; defaults to the GitHub noreply // address for BotUser. BotEmail string `toml:"bot_email" yaml:"bot_email"` - // DiffCapLines parks a task whose diff exceeds this many changed lines. - // It is a pointer so an explicit 0 ("no cap") is distinguishable from an - // absent key, which takes the default: with a plain int the documented - // way to switch the cap off was indistinguishable from not configuring - // it, and the defaults pass silently rewrote it. Read it through - // [Config.DiffCap]. + // DiffCapLines parks a task whose diff exceeds this many changed lines. Nil + // takes the default; 0 means no cap. Read it with DiffCap. DiffCapLines *int `toml:"diff_cap_lines" yaml:"diff_cap_lines"` Forge Forge `toml:"forge" yaml:"forge"` @@ -508,21 +442,13 @@ type Config struct { // An empty BaseURL disables the sender entirely. Artifacts ArtifactsConfig `toml:"artifacts" yaml:"artifacts"` - // Identities declares multi-identity configurations. When non-empty, - // each identity runs its own poll loop with its own forge client, - // worktree manager, repo list, model/provider config, and NATS subject - // namespace. When empty, the single-identity fields (BotUser, - // Forge, Repos, Models, Providers, Dispatch, PollInterval) are used - // unchanged for backward compatibility. + // Identities declares multiple identities, each with its own forge, repos, + // models and poll loop. Empty uses the single-identity fields. Identities []IdentityConfig `toml:"identities" yaml:"identities"` Repos []Repo `toml:"repos" yaml:"repos"` ModelLimits map[string]ModelLimits `toml:"-" yaml:"-" json:"-"` - // Curators holds curator definitions as seed data ([[curators]]). - // Each entry is a curator.Manifest plus name/enabled/instructions. - // Seed data only: the app layer registers each enabled definition - // through the one generic definition-driven engine, and (once - // persistence lands) a stored definition of the same name wins. + // Curators are curator definitions seeded from [[curators]]. Curators []CuratorDefinition `toml:"curators" yaml:"curators" json:"curators,omitempty"` // Extra holds additional feature configuration from conf.d/ files that @@ -611,18 +537,12 @@ type TaskConfig struct { Review Review `json:"review"` } -// DiffCapOf returns a DiffCapLines value for n. It exists because the field is -// a pointer to keep "absent" distinct from an explicit 0, and a literal config -// cannot take the address of a constant. +// DiffCapOf returns a DiffCapLines value for n. // //go:fix inline func DiffCapOf(n int) *int { return new(n) } -// DiffCap returns the effective changed-line cap: 0 means no cap, which is -// also what an unconfigured value means once a Config has been built by hand -// rather than loaded (tests, archie-agent's reconstructed Config). The loader's -// defaults pass fills the absent case, so a loaded Config never reports 0 -// unless the operator asked for it. +// DiffCap returns the changed-line cap; 0 means no cap. func (c Config) DiffCap() int { if c.DiffCapLines == nil { return 0 @@ -684,13 +604,7 @@ func cloneStringMap(src map[string]string) map[string]string { return dst } -// Clone returns a deep copy of c: every reference-type field (maps, -// slices, and the reference fields nested inside them) is copied, so -// mutating the returned value cannot touch c or anything sharing memory -// with it. It is used before the runtime overlay (or a dashboard PATCH) -// decodes into a snapshot, so a failed or partial decode cannot mutate -// the published config -- Holder.Get returns a shallow copy whose maps -// are shared with the published snapshot. +// Clone returns a deep copy of c. func (c Config) Clone() Config { c.Models = cloneStringMap(c.Models) c.ModelLimits = maps.Clone(c.ModelLimits) @@ -791,15 +705,8 @@ const ( NATSModeExternal = "external" ) -// NATSConfig configures NATS JetStream for task distribution and reaction -// delivery. The mode selects how NATS is provided: -// -// "embedded" – an in-process nats-server (default; no external server) -// "external" – connect to URL (required) -// -// An empty Mode resolves from URL: URL set means "external", URL empty means -// "embedded". Autonomous workflow handoff always uses NATS; there is no -// broker-off execution mode. +// NATSConfig configures NATS JetStream. Mode is "embedded" (default) or +// "external", which requires URL; empty Mode is external when URL is set. type NATSConfig struct { // Mode selects embedded or external. Empty resolves from URL. Mode string `toml:"mode" yaml:"mode"` @@ -815,11 +722,7 @@ type NATSConfig struct { // All fields have defaults; an empty // [capture] section is valid and produces them -- capture is on by default. type CaptureConfig struct { - // Retention is how long a captured event is kept before prune-on-write - // deletes it. Zero or absent means the 7-day default; a positive value - // configured explicitly is used as-is; a deployment that wants no age - // bound sets it very large rather than using a magic "0 = unlimited" - // spelling, since 0 already means "use the default" here. + // Retention is how long a captured event is kept. Zero means 7 days. Retention Duration `toml:"retention" yaml:"retention"` // MaxEvents caps the table at this many newest rows; older rows are // pruned on every insert regardless of age. Zero means the 5000 default. @@ -827,11 +730,8 @@ type CaptureConfig struct { // MaxBodyBytes rejects (413) any single POST body larger than this // before it is read into memory. Zero means the 256 KiB default. MaxBodyBytes int `toml:"max_body_bytes" yaml:"max_body_bytes"` - // RatePerSecond and RateBurst configure the per-remote-address token bucket - // (webhookguard.RateLimiter) applied before a request's body is read. Keyed - // by remote address, not the source path segment, since that segment is - // unregistered and attacker-chosen by design. Zero means the defaults (1 - // req/s, burst 5). + // RatePerSecond and RateBurst configure the per-remote-address rate limit on + // capture requests. Zero means 1 req/s, burst 5. RatePerSecond float64 `toml:"rate_per_second" yaml:"rate_per_second"` RateBurst int `toml:"rate_burst" yaml:"rate_burst"` } @@ -866,43 +766,18 @@ type ContainerConfig struct { VolumeTTL Duration `toml:"volume_ttl" yaml:"volume_ttl"` // PullPolicy controls image pulling: "missing" (default) or "always". PullPolicy string `toml:"pull_policy" yaml:"pull_policy"` - // Network is the Docker network spawned agent containers join. Empty first - // tries the daemon's own network (for containerized composition), then uses - // Docker's default bridge. Embedded NATS binds the selected bridge's host - // gateway; external deployments can set a Compose network explicitly when - // workers must resolve broker service names (e.g. "archie-core_default"). + // Network is the Docker network agent containers join. Empty uses the + // daemon's own network, then the default bridge. Network string `toml:"network" yaml:"network"` - // Profiles are the named agent profiles a workflow selects with - // `profile:`. A workflow that names none runs under the default profile: - // Image and every tool. - // Profiles is excluded from the control-plane JSON document - // (container-runtime-policies): profiles are their own resource, - // AgentProfileKind, seeded from this field but validated and stored - // (and reloaded live) separately -- see internal/app/controlplane. + // Profiles are named agent profiles a workflow selects with `profile:`. + // Stored as their own control-plane resource. Profiles map[string]AgentProfile `toml:"profiles" yaml:"profiles" json:"-"` - // Credentials binds a Kit's credential@1 service names to org secrets. - // A binding names - // where the value comes from; it is not itself a grant -- an identity - // resolves a bound service only when its own Org matches and the service - // is in its GrantedCredentials. - // Credentials is excluded from the control-plane JSON document - // (container-runtime-policies): it is its own resource, CredentialBindingsKind, - // seeded from this field but validated and stored (and reloaded live) - // separately -- see internal/app/controlplane. + // Credentials binds Kit credential service names to org secrets. Stored as + // their own control-plane resource. Credentials []CredentialBinding `toml:"credentials" yaml:"credentials" json:"-"` - // RegistryAuth is the credential a private registry requires when the - // configured image (or a profile's) is pulled. It uses the same - // secret-reference shape as every other credential in this file; the - // resolved value is a Docker registry.AuthConfig JSON document, e.g. - // {"username":"bot","password":"..."} ("identitytoken", - // "registrytoken" and "serveraddress" are honoured when present but - // optional -- the daemon derives the host from the image reference). The - // zero value means anonymous pulls, which is what the pool has always - // done; it never fails a deployment that has no private registry. - // RegistryAuth is file-owned, not part of the control-plane JSON document - // (container-runtime-policies): it is a secret reference, resolved at boot - // and restart-required, so the pool receives the resolved value rather - // than a stored one. See internal/container's encodeRegistryAuth. + // RegistryAuth resolves to a Docker registry.AuthConfig JSON document for + // pulling from a private registry. Zero means anonymous pulls. File-only; + // needs a restart. RegistryAuth SecretRef `toml:"registry_auth" yaml:"registry_auth" json:"-"` } @@ -921,14 +796,8 @@ type CredentialBinding struct { Secret SecretRef `toml:"secret" yaml:"secret"` } -// BoundCredentials returns the credential bindings one run may actually use: -// every declared service (what a Kit's descriptor asks for) that is also -// granted (the run's identity's GrantedCredentials) and belongs to org (the -// run's identity's Org). This is the whole enforcement of "authority is an -// intersection": declared and granted are two independent facts, neither -// widens the other, and only a service present in all three -- org, granted, -// declared -- resolves. A service missing from any one is simply absent from -// the result; the caller (the egress resolver) treats that as unbound. +// BoundCredentials returns the bindings a run may use: services that are +// declared, granted, and belong to org. func (c ContainerConfig) BoundCredentials(org string, granted, declared []string) map[string]CredentialBinding { grantedSet := make(map[string]bool, len(granted)) for _, g := range granted { @@ -966,11 +835,8 @@ func (c ContainerConfig) ValidateCredentialBindings() error { return nil } -// AgentProfile is a named execution environment for an agent. Secrets and -// forge or network access are granted to identities, not profiles. -// A workflow's profile name is not checked -// when the workflow is saved: a name with no profile here parks the task for -// an operator when it is dispatched (daemon pinTaskProfile). +// AgentProfile is a named agent execution environment. A workflow naming an +// unknown profile parks at dispatch. type AgentProfile struct { // Image is the container image; empty means [containers].image. Image string `toml:"image" yaml:"image"` @@ -1014,11 +880,7 @@ func (c ContainerConfig) ValidateProfiles() error { return ValidateAgentProfiles(c.Profiles) } -// ValidateAgentProfiles is ValidateProfiles's rule set, standalone so the -// control-plane AgentProfileKind resource (internal/app/controlplane) can -// apply the same rules to a stored value: the file document and the -// resource that replaces it must not be able to disagree about which -// profiles are valid. +// ValidateAgentProfiles validates agent profiles. func ValidateAgentProfiles(profiles map[string]AgentProfile) error { for name, p := range profiles { if strings.TrimSpace(name) == "" { @@ -1042,12 +904,7 @@ func ValidateAgentProfiles(profiles map[string]AgentProfile) error { return nil } -// Log configures where archied writes its logs. -// -// Without File set, output goes only to stderr -- which under systemd means -// journald holds the sole copy, and running by hand leaves no record at all. -// A file gives a durable copy independent of the supervisor, and is what lets -// the dashboard show history from before it connected. +// Log configures archied's log output. Without File, logs go to stderr only. type Log struct { // File is the log file path. Empty disables file logging. The parent // directory is created if missing. @@ -1068,58 +925,21 @@ type Log struct { // ChatConfig configures conversational front-ends. Empty (Telegram.Token.Key == // "") disables chat entirely. type ChatConfig struct { - // Operator is the display name of the person this deployment assists, - // shown to the chat agent as runtime metadata. Empty tells it nothing. - // - // This belongs in configuration, not in a prompt string: the operator's - // name is deployment data. It was previously compiled into the default - // persona, so every deployment claimed to work for one particular - // person, and that name was sent to the model provider on every turn - // regardless of who was running it. + // Operator is the name of the person this deployment assists, shown to the + // chat agent. Operator string `toml:"operator" yaml:"operator"` // Workspace is the directory the chat agent's file and shell tools are // rooted at. Empty disables those tools entirely, which is the default: // they read, write and execute, so the directory must be a deliberate // choice rather than whatever the daemon happens to start in. Workspace string `toml:"workspace" yaml:"workspace"` - // UnrestrictedFilesystem lifts the workspace jail from the chat agent's - // read, write, edit, find and grep tools, letting them reach any absolute - // path. Relative paths still resolve against Workspace. - // - // Off by default. Turn it on when the agent is a general-purpose operator - // rather than an assistant scoped to one project: partitioning and - // mounting a disk, migrating data between filesystems, or editing service - // units are all cross-filesystem by nature, and a jail makes them - // impossible. - // - // This widens which TOOL can do the work, not what the agent can reach. - // The shell tool has never been confined, so a jailed deployment only - // pushed the agent into doing everything through shell -- losing the - // truncation, line numbering and read-before-write protection the - // dedicated tools give it. Grant it deliberately all the same: it is the - // difference between an agent that can edit /etc directly and one that has - // to be asked to. + // UnrestrictedFilesystem lets the chat agent's file tools reach any absolute + // path. Relative paths still resolve against Workspace. Off by default. UnrestrictedFilesystem bool `toml:"unrestricted_filesystem" yaml:"unrestricted_filesystem"` - // ShowToolCalls renders each completed tool call inline in the reply, - // naming the tool and one line of its result, before the answer built - // from them. It is off by default: it exists to make a wrong tool - // choice visible from the chat, and it narrates every internal step - // to do so, which is a privacy/noise cost on a chat surface anyone - // with dashboard or bot access can read. - // - // One setting, every chat channel: it lived under [chat.telegram] - // alone until the web dashboard grew its own tool narration with no - // way to turn it off, contradicting an operator who had already set - // this to false expecting no tool activity to be shown anywhere. + // ShowToolCalls shows each completed tool call in chat replies, on every + // channel. Off by default. ShowToolCalls bool `toml:"show_tool_calls" yaml:"show_tool_calls"` - // MaxSteps caps how many model/tool round-trips one chat turn may take - // before the runtime stops and returns what it has. Zero uses the - // default. - // - // This is a real task budget, not a safety limit: a single question - // about a codebase routinely costs a read, several greps and a handful - // of edits, and running out mid-turn looks to the user like the agent - // simply gave up. Use /stop to interrupt, not a small step cap. + // MaxSteps caps model/tool round-trips per chat turn. Zero uses the default. MaxSteps int `toml:"max_steps" yaml:"max_steps"` // Models is the optional interactive-chat model catalog. When empty, // chat falls back to the distinct model references assigned to workflow @@ -1130,37 +950,16 @@ type ChatConfig struct { // WebhookAddr is the host:port for the inbound webhook gateway. // Empty disables the webhook gateway. WebhookAddr string `toml:"webhook_addr" yaml:"webhook_addr"` - // Webhook configures the single route the inbound webhook gateway - // serves: its path, HMAC validation, payload text extraction, and - // reply delivery. The gateway implementation (internal/channels/webhook) - // has carried these fields since it was written; this is what lets a - // config value reach them. + // Webhook configures the inbound webhook route. Webhook WebhookRoute `toml:"webhook" yaml:"webhook"` Telegram TelegramConfig `toml:"telegram" yaml:"telegram"` - // RateLimit budgets inbound messages per (channel, sender) across - // every chat channel. Zero MaxRequests (the default) leaves rate - // limiting off entirely -- it is an opt-in control, not a default - // throttle that could surprise an existing deployment. This key seeds - // the Channel settings resource, which the Web UI owns at runtime - // (live for the channel transports): editing the file does not change a - // stored value. + // RateLimit budgets inbound messages per channel and sender. Off unless set. + // Seeds the channel-settings resource. RateLimit RateLimitConfig `toml:"rate_limit" yaml:"rate_limit"` } -// RateLimitConfig configures the sliding-window inbound rate limiter -// (internal/ratelimit) shared by every chat channel. This type is the shape of -// the Channel settings resource (channel-settings, -// internal/app/controlplane); the file key is only that resource's seed, and -// the Web UI owns the value a running deployment limits with. Applied by -// boot.startRateLimiter from the config boot.loadRuntimeConfig layers, so a -// stored change to the limit takes effect on the next Gateway restart; the -// channel transports are the half the Messaging Service reconciles live. -// -// A sender is identified per channel: Telegram by numeric user ID, email by the -// SMTP from address, webhook by the configured route path -- which is a source, -// not a person, so it reaches the limiter through the transport-only -// Inbound.BudgetKey rather than through SenderID. Disabled unless both fields -// are set to a positive value. +// RateLimitConfig configures the inbound chat rate limiter. Disabled unless +// both fields are positive. type RateLimitConfig struct { // Window is the rolling interval MaxRequests is budgeted over. Window time.Duration `toml:"window" yaml:"window"` @@ -1175,12 +974,8 @@ func (c RateLimitConfig) Enabled() bool { return c.Window > 0 && c.MaxRequests > 0 } -// TelegramConfig configures the Telegram Bot API channel. -// -// AllowedUserIDs is a deny-by-default allowlist: a Telegram bot is -// reachable by anyone who knows its handle, so an empty list means the -// gateway answers nobody rather than everybody. Chat tools run with the -// daemon's own authority, so an open bot is an open shell. +// TelegramConfig configures the Telegram channel. An empty AllowedUserIDs +// answers nobody. type TelegramConfig struct { // AllowedUserIDs lists the Telegram user IDs permitted to talk to the // bot. It matches the sender (from.id), not the chat, so adding the @@ -1238,11 +1033,7 @@ type Health struct { // Listen is the address the daemon serves /healthz, /health and // /health/detailed on. Defaulted, never empty in a loaded config. Listen string `toml:"listen" yaml:"listen"` - // DependencyTimeout bounds one readiness probe's call into a service this - // process depends on but does not own, so a hung dependency degrades that - // probe instead of stalling the whole health report. It is the daemon's - // equivalent of the extracted services' -dependency-timeout flag. - // Defaulted, never zero in a loaded config. + // DependencyTimeout bounds one readiness probe's call to a dependency. DependencyTimeout Duration `toml:"dependency_timeout" yaml:"dependency_timeout"` } @@ -1270,11 +1061,7 @@ type Web struct { // Listen is the dashboard address; "off" disables the web UI. // Bind localhost (or a LAN/tailnet address) -- there is no auth. Listen string `toml:"listen" yaml:"listen"` - // TrustForwardedHeaders enables deriving the effective request scheme and - // host from X-Forwarded-Proto and X-Forwarded-Host headers during mutation - // Origin validation. Off by default: trusting forwarded headers - // unconditionally allows untrusted clients to spoof Origin scheme checks - // and bypass CSRF protection. Enable ONLY when archied is deployed behind - // a trusted reverse proxy that overwrites/strips untrusted forwarded headers. + // TrustForwardedHeaders uses X-Forwarded-Proto and X-Forwarded-Host for + // Origin checks. Enable only behind a trusted reverse proxy. TrustForwardedHeaders bool `toml:"trust_forwarded_headers" yaml:"trust_forwarded_headers"` } diff --git a/internal/config/curator.go b/internal/config/curator.go index b64485653..69a8faad4 100644 --- a/internal/config/curator.go +++ b/internal/config/curator.go @@ -1,10 +1,6 @@ package config -// CuratorDefinition is one [[curators]] entry: a curator definition as -// seed data. It carries the curator.Manifest shape verbatim plus the -// identity, lifecycle flag, and free-form instructions the manifest cannot -// express. A definition missing interval is refused by configuration -// validation, never defaulted. +// CuratorDefinition is one [[curators]] entry. Interval is required. type CuratorDefinition struct { Name string `toml:"name" yaml:"name" json:"name"` Enabled bool `toml:"enabled" yaml:"enabled" json:"enabled"` diff --git a/internal/config/holder.go b/internal/config/holder.go index 02f4bece5..710e4e91d 100644 --- a/internal/config/holder.go +++ b/internal/config/holder.go @@ -2,56 +2,9 @@ package config import "sync" -// Holder publishes a Config snapshot to concurrent readers and lets a -// single writer swap the snapshot atomically. -// -// # Immutability invariant -// -// A published Config is immutable. The only way to update the published -// value is to call Set with a freshly constructed Config; in-place -// mutation of a published Config is a bug. The reason this matters: Get -// returns a value copy, but the copy shares its reference-type fields -// (Models, Providers, Repos, Identities, MCPServers, Extra, etc.) with -// the published snapshot. Mutating a map or slice through that copy -// mutates the published snapshot too, and any other reader sees the -// mutation outside the protection of the read lock. -// -// Reload paths (a SIGHUP reload re-calling Loader.Resolve, the UI PATCH -// handler) construct a fresh Config and call Set; they never mutate an -// existing one. Decode paths must finish constructing the new Config -// before Set is called; the existing decode.go:80 cfg.Extra[name] = value -// is fine because it runs pre-publish. -// -// # Torn reads across a field group -// -// A single field read inline (d.Cfg.Get().PollInterval) is fine: the -// value is a primitive, and any other reader sees a whole Config -// snapshot too. The risk is reading two or more fields of the same -// snapshot when a Set could land in between, so each field would -// derive from a different published version. When a logical operation -// needs multiple fields, bind the snapshot to a local first: -// -// cfg := d.Cfg.Get() -// if cfg.PollInterval > 0 { ... } -// for _, r := range cfg.Repos { ... } -// -// A single Get per logical operation is the contract; inline single- -// field access is not a smell. -// -// # Loud failures, not silent degradation -// -// Get panics on a nil receiver. A forgotten NewHolder that publishes -// the zero Holder is a programming error and should crash at the first -// consumer, not boot a daemon that runs forever with PollInterval 0 -// and empty Repos. Set has always panicked on nil for the same reason; -// the asymmetry was wrong. -// -// # Why a pointer -// -// The zero value of Holder is not usable (the mutex is uninitialised); -// construct one with [NewHolder]. Holder is always passed by pointer -// because the embedded sync.RWMutex is itself a non-copyable type, and -// copying a Daemon that embeds a value Holder triggers go vet copylocks. +// Holder publishes a Config to concurrent readers; Set swaps it atomically. +// A published Config must not be mutated: Get's copy shares maps and slices +// with it. Take one Get per operation. Construct with NewHolder. type Holder struct { mu sync.RWMutex cfg Config @@ -62,11 +15,8 @@ func NewHolder(c Config) *Holder { return &Holder{cfg: c} } -// Get returns the currently published Config. The returned value is a -// shallow copy; the reference-type fields inside it are shared with the -// published snapshot and must not be mutated. Get panics on a nil -// receiver; a forgotten NewHolder is a programming error. See the type -// doc comment. +// Get returns the published Config. Its maps and slices must not be mutated. +// Panics on a nil Holder. func (h *Holder) Get() Config { h.mu.RLock() defer h.mu.RUnlock() diff --git a/internal/config/reload.go b/internal/config/reload.go index 6e2c770c3..d91d05dac 100644 --- a/internal/config/reload.go +++ b/internal/config/reload.go @@ -1,10 +1,7 @@ package config -// ReloadStatus is the outcome of the most recent config reload attempt, -// surfaced so the dashboard can tell the operator when the running -// config is stale: a reload that failed validation leaves the daemon -// running on the previous config, and that failure must be visible in -// the UI, not buried in logs. +// ReloadStatus is the outcome of the last config reload, shown on the +// dashboard. type ReloadStatus struct { // LastError is the validation error from the most recent failed // reload attempt. Empty when the most recent attempt succeeded. diff --git a/internal/config/secret_ref.go b/internal/config/secret_ref.go index b9893b305..f74ed59b9 100644 --- a/internal/config/secret_ref.go +++ b/internal/config/secret_ref.go @@ -1,22 +1,11 @@ package config -// SecretRef references a secret stored in a named engine. Legacy environment -// variable fields remain supported where required for backwards compatibility. -// -// Format in TOML/YAML: +// SecretRef references a secret in a named engine: // // [forge] // token = {engine = "env", key = "GITEA_TOKEN"} // -// [providers.deepseek] -// api_key = {engine = "bws", key = "DEEPSEEK_API_KEY"} -// -// The zero value (empty engine, empty key) resolves to "" with no error, -// for config fields where the secret is optional (e.g. an unconfigured -// channel token). -// -// It lives here rather than in internal/secret so the archie-ui process can -// render config projections without linking the secret runtime +// The zero value resolves to "". type SecretRef struct { Engine string `toml:"engine" yaml:"engine" json:"engine"` Key string `toml:"key" yaml:"key" json:"key"` diff --git a/internal/config/services.go b/internal/config/services.go index afca6ed23..cab578f8a 100644 --- a/internal/config/services.go +++ b/internal/config/services.go @@ -5,14 +5,8 @@ import ( "strings" ) -// Services maps a registered service name to its connection settings, keyed by -// the [services.] section it was decoded from. -// -// It was a struct with one field per service. That stated each service's name -// three times over -- here, in the loader's defaulting branches, and at every -// consumer's field access -- so a new service meant editing all three and -// nothing prevented them disagreeing. Which names are legitimate now comes -// from RegisterService; see ServiceSpec. +// Services maps a registered service name to its connection settings. Names +// come from RegisterService. type Services map[string]ServiceConnection // Get returns the connection configured for name, or the zero value when the @@ -22,13 +16,8 @@ func (s Services) Get(name string) ServiceConnection { return s[name] } -// ResolvedToken is the bearer token a client presents when dialling name: the -// explicit target_token if set, otherwise the environment variable the service -// registered. getenv is passed in rather than read directly so this stays free -// of internal/secret, which imports this package. -// -// This replaces two resolvers that were identical apart from the variable name -// each hard-coded. +// ResolvedToken returns name's target_token, or the service's registered +// environment variable. func (s Services) ResolvedToken(name string, getenv func(string) string) string { if token := s[name].TargetToken; token != "" { return token @@ -40,14 +29,8 @@ func (s Services) ResolvedToken(name string, getenv func(string) string) string return getenv(spec.TokenEnv) } -// RequireTarget returns the dial address for name, or an error naming the -// config key when the operator has not supplied one. -// -// A service registered with an empty default target is one the operator must -// configure, so this is the registry's own contract rather than a consumer's -// private rule. It stays a lazy check at composition time, not a load-time -// validation: a process that never dials a given service must still be able to -// load a configuration that omits it. +// RequireTarget returns name's dial address, or an error naming the config +// key. func (s Services) RequireTarget(name string) (string, error) { target := strings.TrimSpace(s[name].Target) if target == "" { @@ -56,24 +39,13 @@ func (s Services) RequireTarget(name string) (string, error) { return target, nil } -// ServiceConnection is a service's gRPC addresses plus the bearer token a -// client presents when the target is non-loopback. A client reads only Target -// and TargetToken; Listen belongs to the process that owns the service. The -// struct does not itself register services or start listeners. Changes require -// a daemon restart. +// ServiceConnection is a service's gRPC addresses and client token. +// Restart-required. type ServiceConnection struct { Target string `toml:"target" yaml:"target"` - // Listen is the address the process that OWNS this service binds - // (archie-state-store, archie-gateway). It is read only by that process; - // every client ignores it. Defaulted from the service's registration, so - // a loaded config is never empty here -- an empty address reaches - // net.Listen as "any free port", which would silently move the service - // off the address its clients dial. + // Listen is the address the owning process binds. Always defaulted. Listen string `toml:"listen" yaml:"listen"` - // TargetToken is the bearer token a client (daemon or agent) presents - // when dialing a non-loopback service target, and the standalone - // archie-state-store server validates. Empty means no token, which is - // the loopback-only, daemon-only listener topology permitted without - // auth. + // TargetToken is the bearer token clients present to a non-loopback target. + // Empty means none. TargetToken string `toml:"target_token" yaml:"target_token"` } diff --git a/internal/config/servicespec.go b/internal/config/servicespec.go index 900aebf01..dffb3f2ad 100644 --- a/internal/config/servicespec.go +++ b/internal/config/servicespec.go @@ -19,11 +19,8 @@ const ( ServiceBoth = "both" ) -// ServiceSpec is everything the codebase knows about one service that is not -// operator input. It exists so a service is declared once: the name, its -// defaults, and the environment variable its token falls back to were -// previously a struct field, a defaulting branch, and a hand-copied resolver -// in three separate packages, with nothing keeping them in step. +// ServiceSpec declares one service: name, defaults and token environment +// variable. type ServiceSpec struct { // Context is ServiceClient, ServiceServer, or ServiceBoth. Context string @@ -56,19 +53,8 @@ var ( serviceRegistry = map[string]ServiceSpec{} ) -// RegisterService declares one service. It is the single entry point the -// design calls for: adding a service is this call plus its consumer, with no -// new struct field, defaulting branch, or accessor anywhere else. -// -// Re-registering a name replaces the previous spec, so a test can install a -// throwaway service without disturbing the built-ins. -// -// It panics on a registration that cannot be honoured. Registrations come from -// this repository's own init(), never from operator input, so an invalid one is -// a programming error: there is no caller positioned to handle an error return, -// and failing at process start is better than a service that binds somewhere -// nobody dials. Context is enforced here rather than merely documented, so -// "hosted" genuinely implies a bind address. +// RegisterService declares one service, replacing any existing spec of that +// name. It panics on an invalid registration. func RegisterService(context, name, target, listen, tokenEnv string) { switch context { case ServiceClient, ServiceServer, ServiceBoth: