Files
ctask/cmd/open.go
T
typebasedio b923ae8892 feat(v0.5.2): direct lookup includes archived; resume hint for archived
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.
2026-05-07 19:47:24 -04:00

60 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/session"
"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
)
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")
// v0.5.2: completion offers active candidates only (see delete for rationale).
openCmd.ValidArgsFunction = completeWorkspaces(completionActive)
rootCmd.AddCommand(openCmd)
}
func runOpen(cmd *cobra.Command, args []string) error {
roots := config.SearchRoots()
ws := resolveOne(roots, args[0], openAll)
// 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)
}
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: ws.Meta.Agent,
Mode: ws.Meta.Mode,
Slug: ws.Meta.Slug,
Shell: true, // open always launches shell
LaunchDir: ws.Meta.LaunchDir,
Force: openForce,
})
}