103f2cd33e
LaunchOpts gains LaunchDir. session.Run resolves it via workspace.ResolveLaunch, prints any fallback warning, and passes the absolute path as the child process's working directory. Security violations (absolute paths, .. escape) abort the session. The banner gains a 'project dir: <name>/' line when launch_dir is set. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
58 lines
1.5 KiB
Go
58 lines
1.5 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")
|
|
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,
|
|
})
|
|
}
|