8120c399df
Replace TaskMeta.Agent (string) with TaskMeta.Agent (AgentSpec) carrying type/command/args/env. Custom UnmarshalYAML preserves the legacy scalar form: a built-in name (claude, opencode) maps to that type; any other scalar maps to type=custom with the scalar as command. A missing agent field leaves Type empty so the resolver fills in default_agent at launch. ValidateAgentSpec enforces: known type (claude|opencode|custom), type=custom requires command, command must be an executable name or path with no whitespace or shell metacharacters. Launch-path wiring (Task 3) and the --agent flag rework (Task 4) are intentionally not part of this commit; cmd/* call sites are patched to the minimum needed for the build to compile.
62 lines
1.7 KiB
Go
62 lines
1.7 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"path/filepath"
|
|
"time"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/warrenronsiek/ctask/internal/config"
|
|
"github.com/warrenronsiek/ctask/internal/workspace"
|
|
)
|
|
|
|
var attachCmd = &cobra.Command{
|
|
Use: "attach <workspace>",
|
|
Short: "Attach to a workspace via tmux (always uses persistent session, regardless of CTASK_SESSION_MODE)",
|
|
Args: cobra.ExactArgs(1),
|
|
SilenceUsage: true,
|
|
RunE: runAttach,
|
|
}
|
|
|
|
var (
|
|
attachAgent string
|
|
attachForce bool
|
|
)
|
|
|
|
func init() {
|
|
attachCmd.Flags().StringVarP(&attachAgent, "agent", "a", "", "Override agent command")
|
|
attachCmd.Flags().BoolVar(&attachForce, "force", false, "Skip active-session and stale-workspace warnings (owner-create path only)")
|
|
attachCmd.ValidArgsFunction = completeWorkspaces(completionActive)
|
|
rootCmd.AddCommand(attachCmd)
|
|
}
|
|
|
|
func runAttach(cmd *cobra.Command, args []string) error {
|
|
roots := config.SearchRoots()
|
|
// Active-only resolution per spec §9 (matches resume's completion filter).
|
|
ws := resolveOne(roots, args[0], false)
|
|
|
|
// updated_at bump (existing v0.4 behavior).
|
|
now := time.Now().UTC().Truncate(time.Second)
|
|
ws.Meta.UpdatedAt = now
|
|
metaPath := filepath.Join(ws.Path, "task.yaml")
|
|
if err := workspace.WriteMetaLocked(metaPath, ws.Meta); err != nil {
|
|
return fmt.Errorf("updating metadata: %w", err)
|
|
}
|
|
|
|
agent := attachAgent
|
|
if agent == "" {
|
|
agent = ws.Meta.Agent.Type
|
|
}
|
|
|
|
return runWorkspaceEntry(WorkspaceEntryOptions{
|
|
WsPath: ws.Path,
|
|
WsRoot: ws.Root,
|
|
WsMeta: ws.Meta,
|
|
Agent: agent,
|
|
Shell: false, // attach defaults to agent
|
|
Force: attachForce,
|
|
AlwaysPersistent: true, // attach is always tmux, regardless of env
|
|
CommandName: "attach",
|
|
})
|
|
}
|