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.
61 lines
1.8 KiB
Go
61 lines
1.8 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 openCmd = &cobra.Command{
|
|
Use: "open <query>",
|
|
Short: "Open a workspace directory without launching the agent",
|
|
Args: cobra.ExactArgs(1),
|
|
SilenceUsage: true,
|
|
RunE: runOpen,
|
|
}
|
|
|
|
var (
|
|
openAll bool
|
|
openForce bool
|
|
openDirect bool
|
|
)
|
|
|
|
func init() {
|
|
openCmd.Flags().BoolVarP(&openAll, "all", "a", false, "Include archived workspaces in query resolution")
|
|
openCmd.Flags().BoolVar(&openForce, "force", false, "Skip active-session and stale-workspace warnings")
|
|
openCmd.Flags().BoolVar(&openDirect, "direct", false, "Bypass persistent session mode for this command")
|
|
openCmd.ValidArgsFunction = completeWorkspaces(completionActive)
|
|
rootCmd.AddCommand(openCmd)
|
|
}
|
|
|
|
func runOpen(cmd *cobra.Command, args []string) error {
|
|
roots := config.SearchRoots()
|
|
// PRESERVED v0.5.2 behavior: open's archive resolution is opt-in via --all.
|
|
// resolveOne(roots, query, includeArchived) — distinct from resume's
|
|
// archived-inclusive-with-restore-hint behavior.
|
|
ws := resolveOne(roots, args[0], openAll)
|
|
|
|
// 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)
|
|
}
|
|
|
|
return runWorkspaceEntry(WorkspaceEntryOptions{
|
|
WsPath: ws.Path,
|
|
WsRoot: ws.Root,
|
|
WsMeta: ws.Meta,
|
|
Agent: ws.Meta.Agent.Type,
|
|
Shell: true, // open always launches a shell
|
|
Force: openForce,
|
|
Direct: openDirect,
|
|
CommandName: "open",
|
|
})
|
|
}
|