Files
ctask/cmd/open.go
T
typebasedio 8cda541f2c feat(v0.3): add --project flag, CTASK_TYPE env, project root semantics
ctask new gains --project, which:
  - records type=project on the workspace
  - defaults the category to "projects"
  - applies general + project seed overlays
  - uses CTASK_PROJECT_ROOT when set, with no doubled "projects/"
    path unless the user explicitly passes -c
  - exports CTASK_TYPE=project into the child session

EnvVars now takes a taskType arg and exports CTASK_TYPE. Empty
type defaults to "task" for safety. resume/open also pass
EffectiveType so the env var is correct on resume of a v0.2
workspace.

Git init for project mode is wired in the next commit.
2026-04-10 14:40:06 -04:00

52 lines
1.3 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
func init() {
openCmd.Flags().BoolVarP(&openAll, "all", "a", false, "Include archived workspaces in query resolution")
rootCmd.AddCommand(openCmd)
}
func runOpen(cmd *cobra.Command, args []string) error {
root := config.ResolveRoot()
ws := resolveOne(root, 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.WriteMeta(metaPath, ws.Meta); err != nil {
return fmt.Errorf("updating metadata: %w", err)
}
envVars := config.EnvVars(ws.Meta.Slug, ws.Meta.Mode, root, ws.Path, ws.Meta.Category, workspace.EffectiveType(ws.Meta))
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
})
}