b923ae8892
Apply the v0.5.2 lookup policy to the existing commands and wire
ValidArgsFunction hooks across the workspace-accepting surface.
info: drop the --all/-a flag entirely. Direct lookup is now
archived-inclusive by default — the user typed a name, so we find
the workspace and surface its status in the output. The Status
line already distinguishes active vs archived clearly.
resume: when targeting an archived workspace, fail with a useful
hint instead of letting the resolver report "not found":
[ctask] error: workspace "X" is archived
To restore it:
ctask restore X
This is implemented by resolving archived-inclusive and rejecting
status==archived before any session-launch logic runs. Genuine
not-found and ambiguous-match behavior are unchanged.
Adds ValidArgsFunction hooks to archive (active), delete (active),
open (active), info (any), resume (active). Restore/notes/path
already have hooks from the previous commit. Shell completion now
covers the full direct-lookup surface.
91 lines
2.7 KiB
Go
91 lines
2.7 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"time"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/warrenronsiek/ctask/internal/config"
|
|
"github.com/warrenronsiek/ctask/internal/session"
|
|
"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
|
|
resumeForce bool
|
|
)
|
|
|
|
func init() {
|
|
resumeCmd.Flags().BoolVar(&resumeContainer, "container", false, "Resume in container mode (deferred)")
|
|
resumeCmd.Flags().BoolVar(&resumeShell, "shell", false, "Open shell instead of agent")
|
|
resumeCmd.Flags().StringVarP(&resumeAgent, "agent", "a", "", "Override agent command")
|
|
resumeCmd.Flags().BoolVar(&resumeForce, "force", false, "Skip active-session and stale-workspace warnings")
|
|
resumeCmd.ValidArgsFunction = completeWorkspaces(completionActive)
|
|
rootCmd.AddCommand(resumeCmd)
|
|
}
|
|
|
|
func runResume(cmd *cobra.Command, args []string) error {
|
|
return doResume(args[0], resumeContainer, resumeShell, resumeForce, resumeAgent)
|
|
}
|
|
|
|
// doResume is the shared resume logic used by both resume and last commands.
|
|
func doResume(query string, container, useShell, force bool, agentOverride string) error {
|
|
if container {
|
|
fmt.Println(shell.ContainerNotice())
|
|
return nil
|
|
}
|
|
|
|
roots := config.SearchRoots()
|
|
// v0.5.2: resolve archived-inclusive so we can give a helpful hint when
|
|
// the user resumes an archived workspace. resolveOne still handles
|
|
// not-found and ambiguity exactly as before — this only changes which
|
|
// workspaces are reachable, not how lookup failures are reported.
|
|
ws := resolveOne(roots, query, true)
|
|
|
|
if ws.Meta.Status == "archived" {
|
|
fmt.Fprintf(os.Stderr,
|
|
"[ctask] error: workspace %q is archived\n\nTo restore it:\n ctask restore %s\n",
|
|
query, query)
|
|
return fmt.Errorf("workspace archived")
|
|
}
|
|
|
|
// Update updated_at
|
|
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 := agentOverride
|
|
if agent == "" {
|
|
agent = ws.Meta.Agent
|
|
}
|
|
|
|
envVars := config.EnvVars(ws.Meta.Slug, ws.Meta.Mode, ws.Root, ws.Path, ws.Meta.Category, workspace.EffectiveType(ws.Meta), ws.Meta.LaunchDir)
|
|
|
|
return session.Run(session.LaunchOpts{
|
|
WsDir: ws.Path,
|
|
EnvVars: envVars,
|
|
Agent: agent,
|
|
Mode: ws.Meta.Mode,
|
|
Slug: ws.Meta.Slug,
|
|
Shell: useShell,
|
|
LaunchDir: ws.Meta.LaunchDir,
|
|
Force: force,
|
|
})
|
|
}
|