Files
archie/internal/app/controlplane/agent_profiles.go
T
sam cc6d606de4 feat(controlplane): agent profiles as their own live control-plane resource
docs/prds/external-agent-harness.md ("Selection"): a Kit profile is an org
resource that applies without a restart. Profiles were bundled inside
container-runtime-policies (ApplyMode: restart-required), which is correct
for Image/MaxConcurrency/Network but not for Profiles, which nothing
startup-builds: daemon.configFor reads config.Holder fresh per dispatch
(pinTaskProfile -> Containers.Profile).

Split Profiles into its own resource, AgentProfileKind ("agent-profiles"),
ApplyMode: live, seeded from [containers.profiles] and validated with the
same rules the file document uses (config.ValidateAgentProfiles, factored
out of ContainerConfig.ValidateProfiles so the two cannot disagree).
config.ContainerConfig.Profiles is now json:"-" so container-runtime-policies
never carries it (one authoritative resource per field, not two), and
runtime_config.go layers the new resource in by wholesale map replacement
(matching ModelRoleAssignmentsKind's precedent) rather than merging into the
file's map. Added Profiles to reload.go's Containers reloadable-subfield set
to match this.

Deliberately NOT built here: true per-org multi-tenant storage for this
resource (docs/prds/orgs-and-access.md places agent profiles under org
ownership, granted to workspaces). No existing control-plane resource kind
in this registry does real per-org storage yet either -- schedules,
workflow settings, etc. are all single instance-wide documents -- so
agent-profiles follows that same established, tested pattern rather than
inventing org-scoped storage unilaterally for this one resource. Org/
workspace grants over agent-profiles are a follow-on, not a redo: nothing
about this resource's shape needs to change to add that scoping later.
2026-09-27 05:25:38 +10:00

68 lines
2.6 KiB
Go

package controlplane
import "github.com/samcharles93/archie-core/internal/config"
// AgentProfileKind is the control-plane resource for Kit and image agent
// profiles. It exists so a Kit profile applies without a restart
// (docs/prds/external-agent-harness.md, "Selection"): [containers].profiles
// in config.toml is only its seed, ContainerRuntimePoliciesKind carries every
// other container setting and none of this one (config.ContainerConfig.
// Profiles is json:"-"), and this resource's own ApplyMode is "live".
//
// Its document is agentProfile (container_settings.go's snake_case wire
// type), not config.AgentProfile directly: that internal type carries no
// json tags, so encoding/json would fall back to its Go field names --
// "Tools", "Image" -- exactly the defect archie-core-1171 fixed for the rest
// of this document family.
const AgentProfileKind = "agent-profiles"
func agentProfileDefinition() Definition {
return Definition{
Kind: AgentProfileKind,
Title: "Agent profiles",
ApplyMode: "live",
Document: map[string]agentProfile{},
Seed: seedAgentProfiles,
Validate: validateAgentProfiles,
}
}
func seedAgentProfiles(cfg config.Config) any {
return agentProfilesDocument(cfg.Containers.Profiles)
}
// agentProfilesDocument maps the internal type to the document's wire type.
func agentProfilesDocument(profiles map[string]config.AgentProfile) map[string]agentProfile {
if profiles == nil {
return nil
}
out := make(map[string]agentProfile, len(profiles))
for name, p := range profiles {
out[name] = agentProfile{Image: p.Image, Kit: p.Kit, Adapter: p.Adapter, Tools: p.Tools}
}
return out
}
// agentProfilesSettings reverses agentProfilesDocument, for the layering in
// runtime_config.go and for validation against config.ValidateAgentProfiles.
func agentProfilesSettings(profiles map[string]agentProfile) map[string]config.AgentProfile {
if profiles == nil {
return nil
}
out := make(map[string]config.AgentProfile, len(profiles))
for name, p := range profiles {
out[name] = config.AgentProfile{Image: p.Image, Kit: p.Kit, Adapter: p.Adapter, Tools: p.Tools}
}
return out
}
func validateAgentProfiles(input []byte) error {
// The rules live in the config package and are shared with the file
// document's own validation (config.ContainerConfig.ValidateProfiles):
// which profiles are valid cannot differ between the file that seeds
// this resource and the resource that replaces it.
return validateAs(input, func(profiles map[string]agentProfile) error {
return config.ValidateAgentProfiles(agentProfilesSettings(profiles))
})
}