feat(v0.6): --agent flag on ctask new selects agent type
Resolver gains SetCLIFlagAgent; DefaultAgent now layers CLIFlag above
EnvVar so doctor/info attribution renders the correct precedence chain
(CLIFlag overrides EnvVar overrides ConfigFile overrides Builtin).
ctask new --agent <type> writes agent.type into the new workspace's
task.yaml. Resolution and validation run before workspace.Create, so
--agent custom without a companion command refuses ("type custom
requires command") with no half-created workspace left on disk. The
deferred Phase 1 test TestCLIFlagOverridesEnvVar lands here.
--agent on resume/last/attach is unchanged (one-shot agent.command
override on the AgentSpec — Open Q 1).
This commit is contained in:
@@ -79,6 +79,24 @@ type Resolver struct {
|
||||
envAgent string
|
||||
envSessionMode string
|
||||
envEditor string
|
||||
|
||||
// cliFlagAgent, when non-empty, is the value of the --agent CLI flag.
|
||||
// Set by SetCLIFlagAgent after Cobra parses flags; consulted by
|
||||
// DefaultAgent as the highest-priority layer (SettingSource.CLIFlag).
|
||||
cliFlagAgent string
|
||||
}
|
||||
|
||||
// SetCLIFlagAgent records the value of the --agent CLI flag for
|
||||
// resolution. Cmd-layer code calls this AFTER Cobra parses flags, so the
|
||||
// flag value can participate in source attribution. Empty string means
|
||||
// the flag was not passed; the env-var layer is consulted instead.
|
||||
//
|
||||
// Currently used only by `ctask new` (where --agent is a type selector,
|
||||
// per v0.6 spec §5 + Open Q 1). Other commands' --agent flags act as
|
||||
// one-shot agent.command overrides on the AgentSpec, NOT as resolver
|
||||
// inputs — they do not call this setter.
|
||||
func (r *Resolver) SetCLIFlagAgent(value string) {
|
||||
r.cliFlagAgent = value
|
||||
}
|
||||
|
||||
// configPathForTest, when non-empty, overrides ConfigFilePath() for
|
||||
@@ -223,14 +241,28 @@ func (r *Resolver) SeedDir() ResolvedSetting {
|
||||
defaultSeedDir("seed"), cfgVal, r.envSeedDir, expandPath)
|
||||
}
|
||||
|
||||
// DefaultAgent resolves the default agent command.
|
||||
// DefaultAgent resolves the default agent command. Layering is
|
||||
// Builtin → ConfigFile → EnvVar → CLIFlag: when SetCLIFlagAgent has
|
||||
// recorded a non-empty --agent value, it wins and the previously
|
||||
// resolved setting is chained as Override so doctor/info can render the
|
||||
// full precedence path.
|
||||
func (r *Resolver) DefaultAgent() ResolvedSetting {
|
||||
cfgVal := ""
|
||||
if r.cfg != nil {
|
||||
cfgVal = r.cfg.DefaultAgent
|
||||
}
|
||||
return r.stringSetting("default_agent", "CTASK_AGENT",
|
||||
base := r.stringSetting("default_agent", "CTASK_AGENT",
|
||||
"claude", cfgVal, r.envAgent, nil)
|
||||
if r.cliFlagAgent != "" {
|
||||
prev := base
|
||||
return ResolvedSetting{
|
||||
Key: "default_agent",
|
||||
Value: r.cliFlagAgent,
|
||||
Source: CLIFlag,
|
||||
Override: &prev,
|
||||
}
|
||||
}
|
||||
return base
|
||||
}
|
||||
|
||||
// DefaultCategory resolves the default category for new workspaces.
|
||||
|
||||
Reference in New Issue
Block a user