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.
This commit is contained in:
2026-04-10 14:40:06 -04:00
parent 3adfe62410
commit 8cda541f2c
5 changed files with 69 additions and 16 deletions
+6 -1
View File
@@ -60,13 +60,18 @@ func ResolveProjectRoot() string {
}
// EnvVars returns the environment variables to export into child sessions.
func EnvVars(slug, mode, root, workspace, category string) map[string]string {
// taskType must be "task" or "project"; an empty value defaults to "task".
func EnvVars(slug, mode, root, workspace, category, taskType string) map[string]string {
if taskType == "" {
taskType = "task"
}
return map[string]string{
"CTASK_TASK": slug,
"CTASK_MODE": mode,
"CTASK_ROOT": root,
"CTASK_WORKSPACE": workspace,
"CTASK_CATEGORY": category,
"CTASK_TYPE": taskType,
}
}
+16 -1
View File
@@ -145,13 +145,14 @@ func TestResolveProjectRootOverride(t *testing.T) {
}
func TestEnvVars(t *testing.T) {
vars := EnvVars("my-slug", "local", "/abs/root", "/abs/root/cat/ws", "general")
vars := EnvVars("my-slug", "local", "/abs/root", "/abs/root/cat/ws", "general", "task")
expected := map[string]string{
"CTASK_TASK": "my-slug",
"CTASK_MODE": "local",
"CTASK_ROOT": "/abs/root",
"CTASK_WORKSPACE": "/abs/root/cat/ws",
"CTASK_CATEGORY": "general",
"CTASK_TYPE": "task",
}
for k, v := range expected {
if vars[k] != v {
@@ -159,3 +160,17 @@ func TestEnvVars(t *testing.T) {
}
}
}
func TestEnvVarsProjectType(t *testing.T) {
vars := EnvVars("p", "local", "/r", "/r/p", "projects", "project")
if vars["CTASK_TYPE"] != "project" {
t.Errorf("CTASK_TYPE: got %q, want \"project\"", vars["CTASK_TYPE"])
}
}
func TestEnvVarsEmptyTypeDefaultsToTask(t *testing.T) {
vars := EnvVars("p", "local", "/r", "/r/p", "general", "")
if vars["CTASK_TYPE"] != "task" {
t.Errorf("CTASK_TYPE empty fallback: got %q, want \"task\"", vars["CTASK_TYPE"])
}
}