feat: all six CLI commands (new, list, resume, open, info, archive)
Complete command implementations with all flags per spec. Shared query resolution helper. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+84
@@ -0,0 +1,84 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/warrenronsiek/ctask/internal/config"
|
||||
"github.com/warrenronsiek/ctask/internal/shell"
|
||||
"github.com/warrenronsiek/ctask/internal/workspace"
|
||||
)
|
||||
|
||||
var newCmd = &cobra.Command{
|
||||
Use: "new [title]",
|
||||
Short: "Create a new task workspace and launch the agent",
|
||||
Long: "Create a new task workspace and launch the agent. If title is omitted, generates task-HHMMSS.",
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
RunE: runNew,
|
||||
}
|
||||
|
||||
var (
|
||||
newCategory string
|
||||
newContainer bool
|
||||
newShell bool
|
||||
newAgent string
|
||||
newNoLaunch bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
newCmd.Flags().StringVarP(&newCategory, "category", "c", "general", "Workspace category subdirectory")
|
||||
newCmd.Flags().BoolVar(&newContainer, "container", false, "Launch in container sandbox (v0.2)")
|
||||
newCmd.Flags().BoolVar(&newShell, "shell", false, "Open interactive shell instead of agent")
|
||||
newCmd.Flags().StringVarP(&newAgent, "agent", "a", "", "Command to exec as the agent")
|
||||
newCmd.Flags().BoolVar(&newNoLaunch, "no-launch", false, "Create workspace only, do not launch")
|
||||
rootCmd.AddCommand(newCmd)
|
||||
}
|
||||
|
||||
func runNew(cmd *cobra.Command, args []string) error {
|
||||
if newContainer {
|
||||
fmt.Println(shell.ContainerNotice())
|
||||
return nil
|
||||
}
|
||||
|
||||
root := config.ResolveRoot()
|
||||
agent := newAgent
|
||||
if agent == "" {
|
||||
agent = config.ResolveAgent()
|
||||
}
|
||||
|
||||
title := ""
|
||||
if len(args) > 0 {
|
||||
title = args[0]
|
||||
}
|
||||
|
||||
ws, err := workspace.Create(workspace.CreateOpts{
|
||||
Root: root,
|
||||
Title: title,
|
||||
Category: newCategory,
|
||||
Mode: "local",
|
||||
Agent: agent,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
relPath := workspace.RelativePath(root, ws.Path)
|
||||
fmt.Printf("[ctask] created %s\n", relPath)
|
||||
|
||||
if newNoLaunch {
|
||||
return nil
|
||||
}
|
||||
|
||||
envVars := config.EnvVars(ws.Meta.Slug, ws.Meta.Mode, root, ws.Path, ws.Meta.Category)
|
||||
|
||||
if newShell {
|
||||
return shell.ExecShell(ws.Path, envVars, ws.Meta.Slug, ws.Meta.Mode)
|
||||
}
|
||||
|
||||
// Agent mode: print banner and exec
|
||||
for _, line := range shell.BannerLines(ws.Meta.Mode, ws.Meta.Slug, ws.Path) {
|
||||
fmt.Println(line)
|
||||
}
|
||||
|
||||
return shell.ExecAgent(agent, ws.Path, envVars)
|
||||
}
|
||||
Reference in New Issue
Block a user