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:
+46
-33
@@ -7,6 +7,7 @@ import (
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
||||
"github.com/warrenronsiek/ctask/internal/agent"
|
||||
"github.com/warrenronsiek/ctask/internal/config"
|
||||
"github.com/warrenronsiek/ctask/internal/session"
|
||||
"github.com/warrenronsiek/ctask/internal/shell"
|
||||
@@ -23,14 +24,14 @@ type WorkspaceEntryOptions struct {
|
||||
WsPath string // absolute workspace directory
|
||||
WsRoot string // top-level root (used for CTASK_ROOT env var)
|
||||
WsMeta *workspace.TaskMeta // workspace metadata
|
||||
Agent string
|
||||
Shell bool // launch interactive shell (open / new --shell)
|
||||
Force bool // bypass v0.4 Layer 1/3 prompts (owner-create only)
|
||||
Direct bool // user passed --direct
|
||||
AlwaysPersistent bool // ctask attach: ignore CTASK_SESSION_MODE
|
||||
CommandName string // for hint rendering: "new" | "resume" | "open" | "attach"
|
||||
TmuxPath string // pre-resolved tmux path; if empty in persistent mode, runWorkspaceEntry resolves
|
||||
NewlyCreated bool // forwarded to LaunchOpts.NewlyCreated
|
||||
ResolvedAgent *agent.Resolved // launch-ready agent (command + args + env)
|
||||
Shell bool // launch interactive shell (open / new --shell)
|
||||
Force bool // bypass v0.4 Layer 1/3 prompts (owner-create only)
|
||||
Direct bool // user passed --direct
|
||||
AlwaysPersistent bool // ctask attach: ignore CTASK_SESSION_MODE
|
||||
CommandName string // for hint rendering: "new" | "resume" | "open" | "attach"
|
||||
TmuxPath string // pre-resolved tmux path; if empty in persistent mode, runWorkspaceEntry resolves
|
||||
NewlyCreated bool // forwarded to LaunchOpts.NewlyCreated
|
||||
}
|
||||
|
||||
// runWorkspaceEntry is the test seam for the persistent-mode dispatcher.
|
||||
@@ -114,6 +115,18 @@ func defaultRunWorkspaceEntry(opts WorkspaceEntryOptions) error {
|
||||
return fmt.Errorf("internal: unreachable persistent dispatch")
|
||||
}
|
||||
|
||||
// resolveEntryAgent builds the launch-ready agent for an entry command
|
||||
// (resume / last / open / attach). It starts from the workspace's
|
||||
// AgentSpec, applies an optional one-shot agent.command override (the
|
||||
// --agent flag — a command override, NOT a type selector, per v0.6
|
||||
// Open Question 1), then resolves against the user-level default_agent.
|
||||
func resolveEntryAgent(spec workspace.AgentSpec, commandOverride string) (*agent.Resolved, error) {
|
||||
if commandOverride != "" {
|
||||
spec.Command = commandOverride
|
||||
}
|
||||
return agent.Resolve(spec, config.LoadResolver().DefaultAgent().Value)
|
||||
}
|
||||
|
||||
func entryEnvVars(opts WorkspaceEntryOptions) map[string]string {
|
||||
return config.EnvVars(
|
||||
opts.WsMeta.Slug, opts.WsMeta.Mode,
|
||||
@@ -127,7 +140,7 @@ func invokeDirectRun(opts WorkspaceEntryOptions) error {
|
||||
return session.Run(session.LaunchOpts{
|
||||
WsDir: opts.WsPath,
|
||||
EnvVars: entryEnvVars(opts),
|
||||
Agent: opts.Agent,
|
||||
ResolvedAgent: opts.ResolvedAgent,
|
||||
Mode: opts.WsMeta.Mode,
|
||||
Slug: opts.WsMeta.Slug,
|
||||
Shell: opts.Shell,
|
||||
@@ -175,35 +188,35 @@ func formatDirectModeTmuxHint(slug string) string {
|
||||
|
||||
func invokePersistentRun(opts WorkspaceEntryOptions, tmuxPath, sessionName string) error {
|
||||
return session.Run(session.LaunchOpts{
|
||||
WsDir: opts.WsPath,
|
||||
EnvVars: entryEnvVars(opts),
|
||||
Agent: opts.Agent,
|
||||
Mode: opts.WsMeta.Mode,
|
||||
Slug: opts.WsMeta.Slug,
|
||||
Shell: opts.Shell,
|
||||
LaunchDir: opts.WsMeta.LaunchDir,
|
||||
Category: opts.WsMeta.Category,
|
||||
SessionMode: "persistent",
|
||||
SessionName: sessionName,
|
||||
TmuxPath: tmuxPath,
|
||||
Force: opts.Force,
|
||||
NewlyCreated: opts.NewlyCreated,
|
||||
WsDir: opts.WsPath,
|
||||
EnvVars: entryEnvVars(opts),
|
||||
ResolvedAgent: opts.ResolvedAgent,
|
||||
Mode: opts.WsMeta.Mode,
|
||||
Slug: opts.WsMeta.Slug,
|
||||
Shell: opts.Shell,
|
||||
LaunchDir: opts.WsMeta.LaunchDir,
|
||||
Category: opts.WsMeta.Category,
|
||||
SessionMode: "persistent",
|
||||
SessionName: sessionName,
|
||||
TmuxPath: tmuxPath,
|
||||
Force: opts.Force,
|
||||
NewlyCreated: opts.NewlyCreated,
|
||||
})
|
||||
}
|
||||
|
||||
func invokePersistentAdoption(opts WorkspaceEntryOptions, tmuxPath, sessionName string) error {
|
||||
return session.AdoptExistingPersistentSession(tmuxPath, sessionName, opts.WsPath, session.LaunchOpts{
|
||||
WsDir: opts.WsPath,
|
||||
EnvVars: entryEnvVars(opts),
|
||||
Agent: opts.Agent,
|
||||
Mode: opts.WsMeta.Mode,
|
||||
Slug: opts.WsMeta.Slug,
|
||||
Shell: opts.Shell,
|
||||
LaunchDir: opts.WsMeta.LaunchDir,
|
||||
Category: opts.WsMeta.Category,
|
||||
SessionMode: "persistent",
|
||||
SessionName: sessionName,
|
||||
TmuxPath: tmuxPath,
|
||||
WsDir: opts.WsPath,
|
||||
EnvVars: entryEnvVars(opts),
|
||||
ResolvedAgent: opts.ResolvedAgent,
|
||||
Mode: opts.WsMeta.Mode,
|
||||
Slug: opts.WsMeta.Slug,
|
||||
Shell: opts.Shell,
|
||||
LaunchDir: opts.WsMeta.LaunchDir,
|
||||
Category: opts.WsMeta.Category,
|
||||
SessionMode: "persistent",
|
||||
SessionName: sessionName,
|
||||
TmuxPath: tmuxPath,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user