feat(v0.5.3): cmd attach -- always-tmux entry via runWorkspaceEntry
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/warrenronsiek/ctask/internal/config"
|
||||
"github.com/warrenronsiek/ctask/internal/workspace"
|
||||
)
|
||||
|
||||
var attachCmd = &cobra.Command{
|
||||
Use: "attach <workspace>",
|
||||
Short: "Attach to a workspace via tmux (always uses persistent session, regardless of CTASK_SESSION_MODE)",
|
||||
Args: cobra.ExactArgs(1),
|
||||
SilenceUsage: true,
|
||||
RunE: runAttach,
|
||||
}
|
||||
|
||||
var (
|
||||
attachAgent string
|
||||
attachForce bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
attachCmd.Flags().StringVarP(&attachAgent, "agent", "a", "", "Override agent command")
|
||||
attachCmd.Flags().BoolVar(&attachForce, "force", false, "Skip active-session and stale-workspace warnings (owner-create path only)")
|
||||
attachCmd.ValidArgsFunction = completeWorkspaces(completionActive)
|
||||
rootCmd.AddCommand(attachCmd)
|
||||
}
|
||||
|
||||
func runAttach(cmd *cobra.Command, args []string) error {
|
||||
roots := config.SearchRoots()
|
||||
// Active-only resolution per spec §9 (matches resume's completion filter).
|
||||
ws := resolveOne(roots, args[0], false)
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
agent := attachAgent
|
||||
if agent == "" {
|
||||
agent = ws.Meta.Agent
|
||||
}
|
||||
|
||||
return runWorkspaceEntry(WorkspaceEntryOptions{
|
||||
WsPath: ws.Path,
|
||||
WsRoot: ws.Root,
|
||||
WsMeta: ws.Meta,
|
||||
Agent: agent,
|
||||
Shell: false, // attach defaults to agent
|
||||
Force: attachForce,
|
||||
AlwaysPersistent: true, // attach is always tmux, regardless of env
|
||||
CommandName: "attach",
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user