Files
w3cjandClaude Opus 5.5 9f51e79421 refactor(agents): one definition per coding agent (#29)
Each coding agent gets one definition, an agents.Def in a new stdlib-only
leaf package, internal/agents, and everything else iterates over
agents.Defs: agentlogin's format per login kind, secrets' login kinds,
settings' [pass-keys], image.SharedTools, the vm package's store tables
and scripts, and cli's help lists. The VM copies of every login file,
their bindings, the store's layout, the scripts and the CLI reference
stay the same byte for byte, as golden tests made before the refactor
show.

The agents' guest variables leave base.sh for /etc/devvm/agents.sh,
written at every launch, so every image rebuilds once. Messages are
merged per agent (login_kept, login_passed, login_withheld,
login_oauth_withheld, agent_login_key_only). The structure test's new
names rule fails on an agent's name or login kind as a literal outside
internal/agents, and literals on one holding an agent's folder. Docs
link the supported coding agents rather than listing them, and
Contributing gains Adding a coding agent.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-07 19:16:40 -07:00

69 lines
1.9 KiB
Go

package settings
import (
"maps"
"regexp"
"slices"
"github.com/devvmhq/devvm/internal/agents"
"github.com/devvmhq/devvm/internal/msg"
"github.com/devvmhq/devvm/internal/paths"
)
// passKeys is config.toml's [pass-keys] table: the providers, per agent,
// whose API keys a VM gets as they are, the ones the VM's proxy can't put
// in, such as a local model server's, which devvm otherwise withholds. Its
// keys are the names of the agents it takes (agents.Def's PassKeys); any
// other is an unknown key (passKeys.unknown).
type passKeys map[string]*list[providerKind]
// unknown is the first of p's keys, sorted, that isn't an agent [pass-keys]
// takes, as its key in config.toml, or "".
func (p passKeys) unknown() string {
for _, k := range slices.Sorted(maps.Keys(p)) {
if d, ok := agents.Get(k); !ok || !d.PassKeys {
return "pass-keys." + k
}
}
return ""
}
// refusal is the message the check refused one of p's lists with.
func (p passKeys) refusal() (msg.M, bool) {
for _, k := range slices.Sorted(maps.Keys(p)) {
if m, ok := p[k].refusal(); ok {
return m, true
}
}
return msg.M{}, false
}
// PassKeys returns the providers whose API keys config.toml's
// [pass-keys] says the agent's VMs get as they are, nil for an agent
// it has no key for. No command saves it.
func PassKeys(d paths.Dirs, agent string) ([]string, error) {
cf, err := decodeConfig(d.ConfigFile())
if err != nil {
return nil, err
}
if l := cf.PassKeys[agent]; l != nil {
return l.v, nil
}
return nil, nil
}
// providerName is a provider's ID, as an agent's login file names it:
// lower case letters, digits, dots, dashes and underscores.
var providerName = regexp.MustCompile(`^[a-z0-9][a-z0-9._-]*$`)
type providerKind struct{}
func (providerKind) parse(v any) (string, error) {
return checked(text(v))(func(s string) error {
if !providerName.MatchString(s) {
return errText("not a provider's ID, such as \"ollama\": " + s)
}
return nil
})
}