feat(v0.6): launch path carries ResolvedAgent (command + args + env)

LaunchOpts.Agent (string) and WorkspaceEntryOptions.Agent (string) are
replaced by *agent.Resolved, carrying Command, Args, and Env. The five
entry commands (new, resume, last, open, attach) each construct an
AgentSpec from the workspace metadata, apply --agent as a one-shot
agent.command override (Open Q 1 — keeps muscle memory for users
passing executable paths), call agent.Resolve, and pass the result
through. resolveEntryAgent centralises the resume/last/open/attach path.

shell.ExecAgent and shell.ExecTmuxAgent gain an args parameter; agent.env
is merged into the env map at the session.Run launch switch, AFTER
ctask's exported CTASK_* vars (per spec §5: agent.env wins on collision).
mergeAgentEnv is the centralised merge.

Lease, manifest, write lock, heartbeat, summary, and provisional
cleanup are unchanged. The Agent string fields on Lease, SessionSummary,
and SessionInfo continue to record the launched command for diagnostics.
This commit is contained in:
2026-05-15 11:08:03 -04:00
parent 24f213449e
commit b75b82e676
15 changed files with 317 additions and 110 deletions
+19 -4
View File
@@ -54,14 +54,29 @@ func ContainerNotice() string {
return "[ctask] container mode is not available in v0.1. Use local mode or see docs for manual container setup."
}
// ExecAgent launches the agent command in the workspace directory.
func ExecAgent(agent string, wsDir string, envVars map[string]string) error {
// execAgentArgs is the pure helper: returns the (path, argv) pair that
// ExecAgent will hand to exec.Command. Extracted so unit tests can
// assert argv shape without spawning a real child.
func execAgentArgs(agent string, args []string) (string, []string, error) {
path, err := exec.LookPath(agent)
if err != nil {
return fmt.Errorf("agent command not found: %s", agent)
return "", nil, fmt.Errorf("agent command not found: %s", agent)
}
return path, args, nil
}
// ExecAgent launches the agent command in the workspace directory.
// args is appended after the executable; envVars is merged into the
// process environment via BuildEnvList (which keeps os.Environ() as the
// base — agent.env entries layered into envVars by the caller take
// precedence on collision, per v0.6 spec §5).
func ExecAgent(agent string, args []string, wsDir string, envVars map[string]string) error {
path, argv, err := execAgentArgs(agent, args)
if err != nil {
return err
}
cmd := exec.Command(path)
cmd := exec.Command(path, argv...)
cmd.Dir = wsDir
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout