57f345ae2b
Exit 2 for missing required arguments, exit 127 for agent not found. SilenceUsage on all commands to avoid dumping usage on runtime errors. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
70 lines
1.7 KiB
Go
70 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/shell"
|
|
"github.com/warrenronsiek/ctask/internal/workspace"
|
|
)
|
|
|
|
var resumeCmd = &cobra.Command{
|
|
Use: "resume <query>",
|
|
Short: "Reopen an existing workspace and launch the agent",
|
|
Args: cobra.ExactArgs(1),
|
|
SilenceUsage: true,
|
|
RunE: runResume,
|
|
}
|
|
|
|
var (
|
|
resumeContainer bool
|
|
resumeShell bool
|
|
resumeAgent string
|
|
)
|
|
|
|
func init() {
|
|
resumeCmd.Flags().BoolVar(&resumeContainer, "container", false, "Resume in container mode (v0.2)")
|
|
resumeCmd.Flags().BoolVar(&resumeShell, "shell", false, "Open shell instead of agent")
|
|
resumeCmd.Flags().StringVarP(&resumeAgent, "agent", "a", "", "Override agent command")
|
|
rootCmd.AddCommand(resumeCmd)
|
|
}
|
|
|
|
func runResume(cmd *cobra.Command, args []string) error {
|
|
if resumeContainer {
|
|
fmt.Println(shell.ContainerNotice())
|
|
return nil
|
|
}
|
|
|
|
root := config.ResolveRoot()
|
|
ws := resolveOne(root, args[0], false)
|
|
|
|
// Update updated_at
|
|
now := time.Now().UTC().Truncate(time.Second)
|
|
ws.Meta.UpdatedAt = now
|
|
metaPath := filepath.Join(ws.Path, "task.yaml")
|
|
if err := workspace.WriteMeta(metaPath, ws.Meta); err != nil {
|
|
return fmt.Errorf("updating metadata: %w", err)
|
|
}
|
|
|
|
agent := resumeAgent
|
|
if agent == "" {
|
|
agent = ws.Meta.Agent
|
|
}
|
|
|
|
envVars := config.EnvVars(ws.Meta.Slug, ws.Meta.Mode, root, ws.Path, ws.Meta.Category)
|
|
|
|
if resumeShell {
|
|
return shell.ExecShell(ws.Path, envVars, ws.Meta.Slug, ws.Meta.Mode)
|
|
}
|
|
|
|
// Agent mode
|
|
for _, line := range shell.BannerLines(ws.Meta.Mode, ws.Meta.Slug, ws.Path) {
|
|
fmt.Println(line)
|
|
}
|
|
|
|
return shell.ExecAgent(agent, ws.Path, envVars)
|
|
}
|