feat(v0.6): info source attribution on Agent and Launch session mode
Adds source-attribution rendering to `ctask info` for the two Phase 1
settings whose effective value depends on user-level defaults: the
agent recorded in task.yaml and the configured launch session mode.
cmd/info.go:
- runInfo loads the resolver once (config.LoadResolver) and reuses
it across the rendering — matches the user's correction that "new
doctor/info code should load the resolver once and reuse it".
- Agent line now reads `Agent: <value> (workspace)` when task.yaml
has a non-empty agent (the common case), or `Agent: <value>
(default)` / `Agent: <value> (default — <source label>)` when the
field is empty and the value comes from the resolver fallback
chain. The fallback path is informational only: every workspace
created by recent ctask versions writes the resolved default into
task.yaml at Create time, so the (workspace) branch is what users
normally see.
- New "Launch session mode:" line lives immediately after Agent and
before Created — outside the v0.5.4 Session block per the user's
placement decision ("Keep it outside the Session block because it
represents the configured launch default, not the current session
lease mode"). Format: `Launch session mode: <value> (<source>)`.
- Two small helpers added: agentLineWithSource composes the agent
payload + label; infoSourceLabel renders a single-row source
string (CTASK_X env var / config file / built-in default /
platform override). infoSourceLabel intentionally omits the
override-chain suffix used by doctor — info's row layout has no
room for the extra parenthetical.
cmd/info_attribution_test.go (5 cases):
- TestInfoAgentSourceWorkspace — task.yaml with agent set → "(workspace)"
- TestInfoAgentSourceDefaultForLegacy — empty agent → "(default)"
- TestInfoLaunchSessionModeFromConfig — config session_mode value +
"config file" source label
- TestInfoLaunchSessionModeBuiltinDefault — no config, no env →
"direct (built-in default)"
- TestInfoLaunchSessionModeAfterAgentBeforeCreated — placement check:
Agent < Launch session mode < Created in the rendered output
Smoke-verified against an existing v0.5.x workspace on the installed
binary; render order and source labels match the spec example.
This commit is contained in:
+51
-1
@@ -32,12 +32,20 @@ func runInfo(cmd *cobra.Command, args []string) error {
|
||||
ws := resolveOne(roots, args[0], true)
|
||||
m := ws.Meta
|
||||
|
||||
// v0.6: load the resolver once and reuse it across this info
|
||||
// invocation. The Agent line gains a workspace-vs-default source
|
||||
// label; a new Launch session mode line surfaces the configured
|
||||
// launch default with its own source attribution.
|
||||
resolver := config.LoadResolver()
|
||||
|
||||
fmt.Printf("Task: %s\n", m.Slug)
|
||||
fmt.Printf("Title: %s\n", m.Title)
|
||||
fmt.Printf("Category: %s\n", m.Category)
|
||||
fmt.Printf("Status: %s\n", m.Status)
|
||||
fmt.Printf("Mode: %s\n", m.Mode)
|
||||
fmt.Printf("Agent: %s\n", m.Agent)
|
||||
fmt.Printf("Agent: %s\n", agentLineWithSource(m.Agent, resolver))
|
||||
fmt.Printf("Launch session mode: %s (%s)\n",
|
||||
resolver.SessionMode().Value, infoSourceLabel(resolver.SessionMode()))
|
||||
// v0.5.1: display timestamps in local time. task.yaml stores UTC;
|
||||
// info converts for friendliness so the shown time matches the user's
|
||||
// wall clock.
|
||||
@@ -85,6 +93,48 @@ func runInfo(cmd *cobra.Command, args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// agentLineWithSource builds the value portion of info's Agent line
|
||||
// with v0.6 source attribution. When task.yaml has a non-empty agent
|
||||
// field, that value is workspace state and surfaces as
|
||||
// "<value> (workspace)". When the field is empty (legacy or
|
||||
// hand-crafted task.yaml), the line falls through to the user-level
|
||||
// default chain and is labelled "<value> (default)" plus the source
|
||||
// when the default did NOT come from the built-in.
|
||||
//
|
||||
// The fallback path is informational only: ctask new always writes
|
||||
// the resolved default into task.yaml, so the legacy branch never
|
||||
// fires for workspaces created by recent versions.
|
||||
func agentLineWithSource(workspaceAgent string, r *config.Resolver) string {
|
||||
if workspaceAgent != "" {
|
||||
return workspaceAgent + " (workspace)"
|
||||
}
|
||||
s := r.DefaultAgent()
|
||||
if s.Source == config.Builtin {
|
||||
return s.Value + " (default)"
|
||||
}
|
||||
return fmt.Sprintf("%s (default — %s)", s.Value, infoSourceLabel(s))
|
||||
}
|
||||
|
||||
// infoSourceLabel renders a setting's source for info output. Mirrors
|
||||
// formatSettingSource in doctor.go but without the override-chain
|
||||
// suffix; info lines are single-row and cannot fit the extra "(...)"
|
||||
// payload cleanly. Env-var sources surface their CTASK_X env-var name
|
||||
// (more specific than the bare "env var" label) so the user can spot
|
||||
// which shell variable to inspect.
|
||||
func infoSourceLabel(s config.ResolvedSetting) string {
|
||||
switch s.Source {
|
||||
case config.EnvVar:
|
||||
if s.EnvName != "" {
|
||||
return s.EnvName + " env var"
|
||||
}
|
||||
return "env var"
|
||||
case config.PlatformOverride:
|
||||
return "platform override"
|
||||
default:
|
||||
return s.Source.String()
|
||||
}
|
||||
}
|
||||
|
||||
// printSessionBlock renders the v0.5.4 Session block for `ctask info`.
|
||||
//
|
||||
// Layout (values align at column 14 across the block):
|
||||
|
||||
Reference in New Issue
Block a user