diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-27 06:19:31 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-27 06:19:31 +0200 |
| commit | 6b964400deb653d2c47aa8932ab5444346833b0d (patch) | |
| tree | fdb9166624b91fa11cfa1e9b4a2ca3ad63bf9739 | |
| parent | b67069c110c210b05507fca839d45b43431f5e86 (diff) | |
askcli: show task aliases in output (cd322ed1-882d-40e9-ab98-689acd5f161e)
| -rw-r--r-- | docs/usage.md | 39 | ||||
| -rw-r--r-- | internal/askcli/command_delete.go | 2 | ||||
| -rw-r--r-- | internal/askcli/command_delete_test.go | 21 | ||||
| -rw-r--r-- | internal/askcli/command_dep.go | 13 | ||||
| -rw-r--r-- | internal/askcli/command_dep_test.go | 45 | ||||
| -rw-r--r-- | internal/askcli/command_info_add.go | 8 | ||||
| -rw-r--r-- | internal/askcli/command_info_add_test.go | 42 | ||||
| -rw-r--r-- | internal/askcli/command_list.go | 7 | ||||
| -rw-r--r-- | internal/askcli/command_list_test.go | 91 | ||||
| -rw-r--r-- | internal/askcli/command_urgency.go | 7 | ||||
| -rw-r--r-- | internal/askcli/command_urgency_test.go | 28 | ||||
| -rw-r--r-- | internal/askcli/command_write.go | 16 | ||||
| -rw-r--r-- | internal/askcli/command_write_test.go | 84 | ||||
| -rw-r--r-- | internal/askcli/dispatch.go | 26 | ||||
| -rw-r--r-- | internal/askcli/formatter.go | 66 | ||||
| -rw-r--r-- | internal/askcli/formatter_test.go | 54 | ||||
| -rw-r--r-- | internal/askcli/task_alias_cache.go | 11 |
17 files changed, 447 insertions, 113 deletions
diff --git a/docs/usage.md b/docs/usage.md index 87a6778..3447cd3 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -127,7 +127,7 @@ cat SOMEFILE.txt | hexai --tps-simulation 20 `ask` is a task management CLI for the current git project. It auto-scopes to `project:<repo> +agent` so all operations are confined to the current project. -`ask` never exposes numeric task IDs — it uses UUIDs for all task references. Output is machine-friendly: UUID-only tables, suppressed decorative text, and structured formats. +`ask` never exposes Taskwarrior numeric task IDs. Human-facing output uses stable local alias IDs where practical, while `ask info` shows both the alias ID and the UUID. Commands that accept a task selector support either the alias ID or the UUID. `ask` must be run inside a git repository so the project name can be derived from the repo root. @@ -138,7 +138,7 @@ cat SOMEFILE.txt | hexai --tps-simulation 20 | `ask add "description"` | Create a new task | | `ask add priority:H "description"` | Create task with priority | | `ask add +tag "description"` | Create task with tag | -| `ask list` | List pending tasks only (UUID-only table) | +| `ask list` | List pending tasks only (alias-ID table) | | `ask all` | List all tasks including completed/deleted | | `ask list +READY` | List only ready tasks | | `ask list +BLOCKED` | List blocked tasks | @@ -146,21 +146,21 @@ cat SOMEFILE.txt | hexai --tps-simulation 20 | `ask list started` | List started tasks | | `ask list limit:N` | Limit results | | `ask list sort:priority-,urgency-` | Sort by priority then urgency | -| `ask info [uuid]` | Show task details, or the current started task if UUID is omitted | -| `ask annotate <uuid> "note"` | Add annotation | -| `ask start <uuid>` | Start working on a task | -| `ask stop <uuid>` | Stop work on a task | -| `ask done <uuid>` | Mark task complete | -| `ask priority <uuid> H\|M\|L` | Set priority | -| `ask tag <uuid> +tag` | Add tag | -| `ask tag <uuid> -tag` | Remove tag | -| `ask dep add <uuid> <dep-uuid>` | Add dependency | -| `ask dep rm <uuid> <dep-uuid>` | Remove dependency | -| `ask dep list <uuid>` | List dependencies | +| `ask info [id\|uuid]` | Show task details, or the current started task if no selector is provided | +| `ask annotate <id\|uuid> "note"` | Add annotation | +| `ask start <id\|uuid>` | Start working on a task | +| `ask stop <id\|uuid>` | Stop work on a task | +| `ask done <id\|uuid>` | Mark task complete | +| `ask priority <id\|uuid> H\|M\|L` | Set priority | +| `ask tag <id\|uuid> +tag` | Add tag | +| `ask tag <id\|uuid> -tag` | Remove tag | +| `ask dep add <id\|uuid> <dep-id\|dep-uuid>` | Add dependency | +| `ask dep rm <id\|uuid> <dep-id\|dep-uuid>` | Remove dependency | +| `ask dep list <id\|uuid>` | List dependencies | | `ask urgency` | List tasks by urgency | -| `ask modify <uuid> <args...>` | General-purpose modify | -| `ask denotate <uuid> "text"` | Remove annotation | -| `ask delete <uuid>` | Delete a task | +| `ask modify <id\|uuid> <args...>` | General-purpose modify | +| `ask denotate <id\|uuid> "text"` | Remove annotation | +| `ask delete <id\|uuid>` | Delete a task | ### Examples @@ -171,11 +171,14 @@ ask add priority:H "Implement new feature" # List tasks ask list +READY limit:5 +# Show alias and UUID for a task +ask info 0 + # Start working -ask start 9a3cfcb4-742e-4a38-ac91-e9b36594bff0 +ask start 0 # Done -ask done 9a3cfcb4-742e-4a38-ac91-e9b36594bff0 +ask done 0 ``` ## Hexai Action (TUI) diff --git a/internal/askcli/command_delete.go b/internal/askcli/command_delete.go index 64bcdfc..24753d5 100644 --- a/internal/askcli/command_delete.go +++ b/internal/askcli/command_delete.go @@ -21,6 +21,6 @@ func (d Dispatcher) handleDelete(ctx context.Context, args []string, stdin io.Re if code != 0 { return code, err } - io.WriteString(stdout, FormatSuccess(resolved.UUID)) + io.WriteString(stdout, FormatSuccess(displayResolvedTaskID(resolved))) return 0, nil } diff --git a/internal/askcli/command_delete_test.go b/internal/askcli/command_delete_test.go index ff3f435..7d049c6 100644 --- a/internal/askcli/command_delete_test.go +++ b/internal/askcli/command_delete_test.go @@ -11,6 +11,23 @@ import ( ) func TestHandleDelete_Success(t *testing.T) { + dir := t.TempDir() + oldRoot := taskAliasCacheRoot + oldNow := nowTaskAliasCache + taskAliasCacheRoot = func() (string, error) { return filepath.Join(dir, "hexai"), nil } + nowTaskAliasCache = func() time.Time { return time.Date(2026, 3, 26, 12, 0, 0, 0, time.UTC) } + defer func() { + taskAliasCacheRoot = oldRoot + nowTaskAliasCache = oldNow + }() + + writeTaskAliasCacheForTest(t, taskAliasCache{ + NextID: 1, + Entries: []taskAliasCacheEntry{ + {UUID: "test-uuid-123", Alias: "0", CreatedAt: nowTaskAliasCache()}, + }, + }) + d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) { if len(args) == 2 && args[0] == "uuid:test-uuid-123" && args[1] == "export" { io.WriteString(stdout, `[{"uuid":"test-uuid-123","description":"Task","status":"pending","priority":"M","tags":[],"urgency":0,"depends":[]}]`) @@ -26,8 +43,8 @@ func TestHandleDelete_Success(t *testing.T) { if err != nil { t.Fatalf("delete returned error: %v", err) } - if !strings.Contains(stdout.String(), "ok") || !strings.Contains(stdout.String(), "test-uuid-123") { - t.Fatalf("stdout = %q, want ok + uuid", stdout.String()) + if !strings.Contains(stdout.String(), "ok 0") || strings.Contains(stdout.String(), "test-uuid-123") { + t.Fatalf("stdout = %q, want ok + alias only", stdout.String()) } if stderr.Len() > 0 { t.Fatalf("stderr should be empty, got %q", stderr.String()) diff --git a/internal/askcli/command_dep.go b/internal/askcli/command_dep.go index 403afee..0508b39 100644 --- a/internal/askcli/command_dep.go +++ b/internal/askcli/command_dep.go @@ -53,7 +53,7 @@ func (d Dispatcher) handleDepAddRm(ctx context.Context, args []string, stdout, s if code != 0 { return code, err } - io.WriteString(stdout, FormatSuccess(resolved.UUID)) + io.WriteString(stdout, FormatSuccess(displayResolvedTaskID(resolved))) return 0, nil } @@ -75,7 +75,16 @@ func (d Dispatcher) handleDepList(ctx context.Context, args []string, stdout, st if len(task.Depends) == 0 { io.WriteString(stdout, "no dependencies\n") } else { - io.WriteString(stdout, strings.Join(task.Depends, "\n")+"\n") + aliases, err := ensureTaskAliasesForUUIDs(task.Depends) + if err != nil { + fmt.Fprintf(stderr, "error: failed to load task aliases: %v\n", err) + return 1, nil + } + ids := make([]string, 0, len(task.Depends)) + for _, uuid := range task.Depends { + ids = append(ids, displayTaskAlias(uuid, aliases)) + } + io.WriteString(stdout, strings.Join(ids, "\n")+"\n") } return 0, nil } diff --git a/internal/askcli/command_dep_test.go b/internal/askcli/command_dep_test.go index 8045df3..408ef86 100644 --- a/internal/askcli/command_dep_test.go +++ b/internal/askcli/command_dep_test.go @@ -11,6 +11,24 @@ import ( ) func TestHandleDep_AddSuccess(t *testing.T) { + dir := t.TempDir() + oldRoot := taskAliasCacheRoot + oldNow := nowTaskAliasCache + taskAliasCacheRoot = func() (string, error) { return filepath.Join(dir, "hexai"), nil } + nowTaskAliasCache = func() time.Time { return time.Date(2026, 3, 26, 12, 0, 0, 0, time.UTC) } + defer func() { + taskAliasCacheRoot = oldRoot + nowTaskAliasCache = oldNow + }() + + writeTaskAliasCacheForTest(t, taskAliasCache{ + NextID: 2, + Entries: []taskAliasCacheEntry{ + {UUID: "uuid-1", Alias: "0", CreatedAt: nowTaskAliasCache()}, + {UUID: "uuid-2", Alias: "1", CreatedAt: nowTaskAliasCache()}, + }, + }) + var capturedArgs []string d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) { if len(args) == 2 && args[1] == "export" { @@ -30,8 +48,8 @@ func TestHandleDep_AddSuccess(t *testing.T) { if code != 0 { t.Fatalf("dep add code = %d, want 0", code) } - if !strings.Contains(stdout.String(), "ok") || !strings.Contains(stdout.String(), "uuid-1") { - t.Fatalf("stdout = %q, want ok + uuid", stdout.String()) + if !strings.Contains(stdout.String(), "ok 0") || strings.Contains(stdout.String(), "uuid-1") { + t.Fatalf("stdout = %q, want ok + alias only", stdout.String()) } // Verify uuid:<uuid> is the filter (not a modification argument). if len(capturedArgs) < 3 || capturedArgs[0] != "uuid:uuid-1" || capturedArgs[1] != "modify" { @@ -60,6 +78,25 @@ func TestHandleDep_RmSuccess(t *testing.T) { } func TestHandleDep_ListSuccess(t *testing.T) { + dir := t.TempDir() + oldRoot := taskAliasCacheRoot + oldNow := nowTaskAliasCache + taskAliasCacheRoot = func() (string, error) { return filepath.Join(dir, "hexai"), nil } + nowTaskAliasCache = func() time.Time { return time.Date(2026, 3, 26, 12, 0, 0, 0, time.UTC) } + defer func() { + taskAliasCacheRoot = oldRoot + nowTaskAliasCache = oldNow + }() + + writeTaskAliasCacheForTest(t, taskAliasCache{ + NextID: 3, + Entries: []taskAliasCacheEntry{ + {UUID: "dep-1", Alias: "1", CreatedAt: nowTaskAliasCache()}, + {UUID: "dep-2", Alias: "2", CreatedAt: nowTaskAliasCache()}, + {UUID: "uuid-1", Alias: "0", CreatedAt: nowTaskAliasCache()}, + }, + }) + jsonData := `[{"uuid":"uuid-1","description":"Task","status":"pending","priority":"M","tags":[],"urgency":10,"depends":["dep-1","dep-2"]}]` d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) { io.WriteString(stdout, jsonData) @@ -71,8 +108,8 @@ func TestHandleDep_ListSuccess(t *testing.T) { t.Fatalf("dep list code = %d, want 0", code) } output := stdout.String() - if !strings.Contains(output, "dep-1") || !strings.Contains(output, "dep-2") { - t.Fatalf("stdout = %q, want deps", output) + if !strings.Contains(output, "1") || !strings.Contains(output, "2") || strings.Contains(output, "dep-1") || strings.Contains(output, "dep-2") { + t.Fatalf("stdout = %q, want alias deps only", output) } } diff --git a/internal/askcli/command_info_add.go b/internal/askcli/command_info_add.go index 030cf62..5332e71 100644 --- a/internal/askcli/command_info_add.go +++ b/internal/askcli/command_info_add.go @@ -24,7 +24,13 @@ func (d Dispatcher) handleInfo(ctx context.Context, args []string, stdout, stder stdout.Write(data) io.WriteString(stdout, "\n") } else { - io.WriteString(stdout, FormatTaskInfo(tasks[0])) + allUUIDs := append([]string{tasks[0].UUID}, tasks[0].Depends...) + aliases, err := ensureTaskAliasesForUUIDs(allUUIDs) + if err != nil { + fmt.Fprintf(stderr, "error: failed to load task aliases: %v\n", err) + return 1, nil + } + io.WriteString(stdout, FormatTaskInfo(tasks[0], displayTaskAlias(tasks[0].UUID, aliases), aliases)) } return 0, nil } diff --git a/internal/askcli/command_info_add_test.go b/internal/askcli/command_info_add_test.go index 46996f7..a7a7bc2 100644 --- a/internal/askcli/command_info_add_test.go +++ b/internal/askcli/command_info_add_test.go @@ -11,6 +11,24 @@ import ( ) func TestHandleInfo_Success(t *testing.T) { + dir := t.TempDir() + oldRoot := taskAliasCacheRoot + oldNow := nowTaskAliasCache + taskAliasCacheRoot = func() (string, error) { return filepath.Join(dir, "hexai"), nil } + nowTaskAliasCache = func() time.Time { return time.Date(2026, 3, 26, 12, 0, 0, 0, time.UTC) } + defer func() { + taskAliasCacheRoot = oldRoot + nowTaskAliasCache = oldNow + }() + + writeTaskAliasCacheForTest(t, taskAliasCache{ + NextID: 2, + Entries: []taskAliasCacheEntry{ + {UUID: "dep-1", Alias: "1", CreatedAt: nowTaskAliasCache()}, + {UUID: "test-uuid", Alias: "0", CreatedAt: nowTaskAliasCache()}, + }, + }) + jsonData := `[{"uuid":"test-uuid","description":"Test task","status":"pending","priority":"H","tags":["cli","agent"],"urgency":15.0,"depends":["dep-1"],"annotations":[{"description":"Note 1","entry":"2026-03-22T10:00:00Z"}]}]` d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) { // args[0] is "uuid:<uuid>" (the filter); emit data for any export call @@ -25,6 +43,9 @@ func TestHandleInfo_Success(t *testing.T) { t.Fatalf("info code = %d, want 0", code) } output := stdout.String() + if !strings.Contains(output, "ID: 0") { + t.Fatalf("output missing alias ID: %s", output) + } if !strings.Contains(output, "test-uuid") { t.Fatalf("output missing UUID: %s", output) } @@ -34,6 +55,9 @@ func TestHandleInfo_Success(t *testing.T) { if !strings.Contains(output, "Started: no") { t.Fatalf("output missing explicit started state: %s", output) } + if !strings.Contains(output, "Depends: 1 (dep-1)") { + t.Fatalf("output missing formatted dependency alias: %s", output) + } } func TestHandleInfo_AliasSelector(t *testing.T) { @@ -67,8 +91,8 @@ func TestHandleInfo_AliasSelector(t *testing.T) { if code != 0 { t.Fatalf("info code = %d, want 0", code) } - if !strings.Contains(stdout.String(), "test-uuid") { - t.Fatalf("stdout = %q, want resolved UUID", stdout.String()) + if !strings.Contains(stdout.String(), "ID: 0") || !strings.Contains(stdout.String(), "UUID: test-uuid") { + t.Fatalf("stdout = %q, want alias and UUID", stdout.String()) } } @@ -84,6 +108,16 @@ func TestHandleInfo_NumericID(t *testing.T) { } func TestHandleInfo_MissingUUID(t *testing.T) { + dir := t.TempDir() + oldRoot := taskAliasCacheRoot + oldNow := nowTaskAliasCache + taskAliasCacheRoot = func() (string, error) { return filepath.Join(dir, "hexai"), nil } + nowTaskAliasCache = func() time.Time { return time.Date(2026, 3, 26, 12, 0, 0, 0, time.UTC) } + defer func() { + taskAliasCacheRoot = oldRoot + nowTaskAliasCache = oldNow + }() + jsonData := `[{"uuid":"started-uuid","description":"Started task","status":"pending","priority":"M","start":"2026-03-26T10:00:00Z","urgency":5.0,"depends":[]}]` d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) { if len(args) == 2 && args[0] == "started" && args[1] == "export" { @@ -96,8 +130,8 @@ func TestHandleInfo_MissingUUID(t *testing.T) { if code != 0 { t.Fatalf("info code = %d, want 0 for implicit started task", code) } - if !strings.Contains(stdout.String(), "started-uuid") { - t.Fatalf("output missing started task UUID: %s", stdout.String()) + if !strings.Contains(stdout.String(), "ID: 0") || !strings.Contains(stdout.String(), "UUID: started-uuid") { + t.Fatalf("output missing alias and started task UUID: %s", stdout.String()) } } diff --git a/internal/askcli/command_list.go b/internal/askcli/command_list.go index ef8c22f..c95707e 100644 --- a/internal/askcli/command_list.go +++ b/internal/askcli/command_list.go @@ -61,7 +61,12 @@ func (d Dispatcher) handleListWithFilters(ctx context.Context, initialFilters, e stdout.Write(data) io.WriteString(stdout, "\n") } else { - io.WriteString(stdout, FormatTaskList(tasks)) + aliases, err := ensureTaskAliases(tasks) + if err != nil { + fmt.Fprintf(stderr, "error: failed to load task aliases: %v\n", err) + return 1, nil + } + io.WriteString(stdout, FormatTaskList(tasks, aliases)) } return 0, nil } diff --git a/internal/askcli/command_list_test.go b/internal/askcli/command_list_test.go index dade889..83dc1b8 100644 --- a/internal/askcli/command_list_test.go +++ b/internal/askcli/command_list_test.go @@ -4,11 +4,31 @@ import ( "bytes" "context" "io" + "path/filepath" "strings" "testing" + "time" ) func TestHandleList_Success(t *testing.T) { + dir := t.TempDir() + oldRoot := taskAliasCacheRoot + oldNow := nowTaskAliasCache + taskAliasCacheRoot = func() (string, error) { return filepath.Join(dir, "hexai"), nil } + nowTaskAliasCache = func() time.Time { return time.Date(2026, 3, 26, 12, 0, 0, 0, time.UTC) } + defer func() { + taskAliasCacheRoot = oldRoot + nowTaskAliasCache = oldNow + }() + + writeTaskAliasCacheForTest(t, taskAliasCache{ + NextID: 2, + Entries: []taskAliasCacheEntry{ + {UUID: "uuid-1", Alias: "0", CreatedAt: nowTaskAliasCache()}, + {UUID: "uuid-2", Alias: "1", CreatedAt: nowTaskAliasCache()}, + }, + }) + jsonData := `[{"uuid":"uuid-1","description":"Task 1","status":"pending","priority":"H","tags":["cli"],"start":"2026-03-26T10:00:00Z","urgency":15.0,"depends":[]},{"uuid":"uuid-2","description":"Task 2","status":"completed","priority":"M","tags":["agent"],"urgency":10.0,"depends":[]}]` d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) { for _, arg := range args { @@ -25,8 +45,11 @@ func TestHandleList_Success(t *testing.T) { t.Fatalf("list code = %d, want 0", code) } output := stdout.String() - if !strings.Contains(output, "uuid-1") || !strings.Contains(output, "uuid-2") { - t.Fatalf("output missing UUIDs: %s", output) + if !strings.Contains(output, "ID") || strings.Contains(output, "UUID") { + t.Fatalf("output should use ID column: %s", output) + } + if !strings.Contains(output, "0") || !strings.Contains(output, "1") || strings.Contains(output, "uuid-1") || strings.Contains(output, "uuid-2") { + t.Fatalf("output missing aliases or leaking UUIDs: %s", output) } if !strings.Contains(output, "Started") || !strings.Contains(output, "yes") || !strings.Contains(output, "no") { t.Fatalf("output missing explicit started state: %s", output) @@ -34,6 +57,24 @@ func TestHandleList_Success(t *testing.T) { } func TestHandleList_SortedByPriority(t *testing.T) { + dir := t.TempDir() + oldRoot := taskAliasCacheRoot + oldNow := nowTaskAliasCache + taskAliasCacheRoot = func() (string, error) { return filepath.Join(dir, "hexai"), nil } + nowTaskAliasCache = func() time.Time { return time.Date(2026, 3, 26, 12, 0, 0, 0, time.UTC) } + defer func() { + taskAliasCacheRoot = oldRoot + nowTaskAliasCache = oldNow + }() + + writeTaskAliasCacheForTest(t, taskAliasCache{ + NextID: 2, + Entries: []taskAliasCacheEntry{ + {UUID: "uuid-1", Alias: "0", CreatedAt: nowTaskAliasCache()}, + {UUID: "uuid-2", Alias: "1", CreatedAt: nowTaskAliasCache()}, + }, + }) + jsonData := `[{"uuid":"uuid-2","description":"Task 2","status":"pending","priority":"M","tags":[],"urgency":10.0,"depends":[]},{"uuid":"uuid-1","description":"Task 1","status":"pending","priority":"H","tags":[],"urgency":5.0,"depends":[]}]` d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) { for _, arg := range args { @@ -49,8 +90,8 @@ func TestHandleList_SortedByPriority(t *testing.T) { output := stdout.String() lines := strings.Split(strings.TrimSpace(output), "\n") taskLine1 := lines[2] - if !strings.Contains(taskLine1, "uuid-1") { - t.Fatalf("first task should be H priority (uuid-1), got: %s", taskLine1) + if !strings.Contains(taskLine1, "0") || strings.Contains(taskLine1, "uuid-1") { + t.Fatalf("first task should be H priority alias 0, got: %s", taskLine1) } } @@ -72,6 +113,23 @@ func TestHandleList_EmptyList(t *testing.T) { } func TestHandleAll_Success(t *testing.T) { + dir := t.TempDir() + oldRoot := taskAliasCacheRoot + oldNow := nowTaskAliasCache + taskAliasCacheRoot = func() (string, error) { return filepath.Join(dir, "hexai"), nil } + nowTaskAliasCache = func() time.Time { return time.Date(2026, 3, 26, 12, 0, 0, 0, time.UTC) } + defer func() { + taskAliasCacheRoot = oldRoot + nowTaskAliasCache = oldNow + }() + + writeTaskAliasCacheForTest(t, taskAliasCache{ + NextID: 1, + Entries: []taskAliasCacheEntry{ + {UUID: "uuid-1", Alias: "0", CreatedAt: nowTaskAliasCache()}, + }, + }) + jsonData := `[{"uuid":"uuid-1","description":"Done task","status":"completed","priority":"M","tags":[],"urgency":0.0,"depends":[]}]` d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) { for _, arg := range args { @@ -87,12 +145,29 @@ func TestHandleAll_Success(t *testing.T) { if code != 0 { t.Fatalf("all code = %d, want 0", code) } - if !strings.Contains(stdout.String(), "uuid-1") { - t.Fatalf("output missing uuid-1: %s", stdout.String()) + if !strings.Contains(stdout.String(), "0") || strings.Contains(stdout.String(), "uuid-1") { + t.Fatalf("output should show alias only: %s", stdout.String()) } } func TestHandleReady_Success(t *testing.T) { + dir := t.TempDir() + oldRoot := taskAliasCacheRoot + oldNow := nowTaskAliasCache + taskAliasCacheRoot = func() (string, error) { return filepath.Join(dir, "hexai"), nil } + nowTaskAliasCache = func() time.Time { return time.Date(2026, 3, 26, 12, 0, 0, 0, time.UTC) } + defer func() { + taskAliasCacheRoot = oldRoot + nowTaskAliasCache = oldNow + }() + + writeTaskAliasCacheForTest(t, taskAliasCache{ + NextID: 1, + Entries: []taskAliasCacheEntry{ + {UUID: "uuid-ready", Alias: "0", CreatedAt: nowTaskAliasCache()}, + }, + }) + jsonData := `[{"uuid":"uuid-ready","description":"Ready task","status":"pending","priority":"H","tags":["READY"],"urgency":20.0,"depends":[]}]` d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) { for _, arg := range args { @@ -108,8 +183,8 @@ func TestHandleReady_Success(t *testing.T) { if code != 0 { t.Fatalf("ready code = %d, want 0", code) } - if !strings.Contains(stdout.String(), "uuid-ready") { - t.Fatalf("output missing uuid-ready: %s", stdout.String()) + if !strings.Contains(stdout.String(), "0") || strings.Contains(stdout.String(), "uuid-ready") { + t.Fatalf("output should show alias only: %s", stdout.String()) } } diff --git a/internal/askcli/command_urgency.go b/internal/askcli/command_urgency.go index a228f27..0a6bf65 100644 --- a/internal/askcli/command_urgency.go +++ b/internal/askcli/command_urgency.go @@ -32,7 +32,12 @@ func (d Dispatcher) handleUrgency(ctx context.Context, stdout, stderr io.Writer) stdout.Write(data) io.WriteString(stdout, "\n") } else { - io.WriteString(stdout, FormatTaskList(tasks)) + aliases, err := ensureTaskAliases(tasks) + if err != nil { + fmt.Fprintf(stderr, "error: failed to load task aliases: %v\n", err) + return 1, nil + } + io.WriteString(stdout, FormatTaskList(tasks, aliases)) } return 0, nil } diff --git a/internal/askcli/command_urgency_test.go b/internal/askcli/command_urgency_test.go index 45ec5f5..dd6262d 100644 --- a/internal/askcli/command_urgency_test.go +++ b/internal/askcli/command_urgency_test.go @@ -4,11 +4,31 @@ import ( "bytes" "context" "io" + "path/filepath" "strings" "testing" + "time" ) func TestHandleUrgency_Success(t *testing.T) { + dir := t.TempDir() + oldRoot := taskAliasCacheRoot + oldNow := nowTaskAliasCache + taskAliasCacheRoot = func() (string, error) { return filepath.Join(dir, "hexai"), nil } + nowTaskAliasCache = func() time.Time { return time.Date(2026, 3, 26, 12, 0, 0, 0, time.UTC) } + defer func() { + taskAliasCacheRoot = oldRoot + nowTaskAliasCache = oldNow + }() + + writeTaskAliasCacheForTest(t, taskAliasCache{ + NextID: 2, + Entries: []taskAliasCacheEntry{ + {UUID: "uuid-1", Alias: "0", CreatedAt: nowTaskAliasCache()}, + {UUID: "uuid-2", Alias: "1", CreatedAt: nowTaskAliasCache()}, + }, + }) + jsonData := `[{"uuid":"uuid-2","description":"Task 2","status":"pending","priority":"M","tags":["agent"],"urgency":10.0,"depends":[]},{"uuid":"uuid-1","description":"Task 1","status":"pending","priority":"H","tags":["cli"],"urgency":15.0,"depends":[]}]` d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) { io.WriteString(stdout, jsonData) @@ -26,11 +46,11 @@ func TestHandleUrgency_Success(t *testing.T) { } taskLine1 := lines[2] taskLine2 := lines[3] - if !strings.Contains(taskLine1, "uuid-1") { - t.Fatalf("first task line should contain uuid-1 (urgency 15.0), got: %s", taskLine1) + if !strings.Contains(taskLine1, "0") || strings.Contains(taskLine1, "uuid-1") { + t.Fatalf("first task line should contain alias 0 (urgency 15.0), got: %s", taskLine1) } - if !strings.Contains(taskLine2, "uuid-2") { - t.Fatalf("second task line should contain uuid-2 (urgency 10.0), got: %s", taskLine2) + if !strings.Contains(taskLine2, "1") || strings.Contains(taskLine2, "uuid-2") { + t.Fatalf("second task line should contain alias 1 (urgency 10.0), got: %s", taskLine2) } } diff --git a/internal/askcli/command_write.go b/internal/askcli/command_write.go index afa1475..643f74e 100644 --- a/internal/askcli/command_write.go +++ b/internal/askcli/command_write.go @@ -23,7 +23,7 @@ func (d Dispatcher) handleDenotate(ctx context.Context, args []string, stdout, s if code != 0 { return code, err } - io.WriteString(stdout, FormatSuccess(resolved.UUID)) + io.WriteString(stdout, FormatSuccess(displayResolvedTaskID(resolved))) return 0, nil } @@ -43,7 +43,7 @@ func (d Dispatcher) handleModify(ctx context.Context, args []string, stdout, std if code != 0 { return code, err } - io.WriteString(stdout, FormatSuccess(resolved.UUID)) + io.WriteString(stdout, FormatSuccess(displayResolvedTaskID(resolved))) return 0, nil } @@ -63,7 +63,7 @@ func (d Dispatcher) handleAnnotate(ctx context.Context, args []string, stdout, s if code != 0 { return code, err } - io.WriteString(stdout, FormatSuccess(resolved.UUID)) + io.WriteString(stdout, FormatSuccess(displayResolvedTaskID(resolved))) return 0, nil } @@ -84,7 +84,7 @@ func (d Dispatcher) handleStart(ctx context.Context, args []string, stdout, stde if code != 0 { return code, err } - io.WriteString(stdout, FormatSuccess(resolved.UUID)) + io.WriteString(stdout, FormatSuccess(displayResolvedTaskID(resolved))) return 0, nil } @@ -103,7 +103,7 @@ func (d Dispatcher) handleStop(ctx context.Context, args []string, stdout, stder if code != 0 { return code, err } - io.WriteString(stdout, FormatSuccess(resolved.UUID)) + io.WriteString(stdout, FormatSuccess(displayResolvedTaskID(resolved))) return 0, nil } @@ -122,7 +122,7 @@ func (d Dispatcher) handleDone(ctx context.Context, args []string, stdout, stder if code != 0 { return code, err } - io.WriteString(stdout, FormatSuccess(resolved.UUID)) + io.WriteString(stdout, FormatSuccess(displayResolvedTaskID(resolved))) return 0, nil } @@ -142,7 +142,7 @@ func (d Dispatcher) handlePriority(ctx context.Context, args []string, stdout, s if code != 0 { return code, err } - io.WriteString(stdout, FormatSuccess(resolved.UUID)) + io.WriteString(stdout, FormatSuccess(displayResolvedTaskID(resolved))) return 0, nil } @@ -162,6 +162,6 @@ func (d Dispatcher) handleTag(ctx context.Context, args []string, stdout, stderr if code != 0 { return code, err } - io.WriteString(stdout, FormatSuccess(resolved.UUID)) + io.WriteString(stdout, FormatSuccess(displayResolvedTaskID(resolved))) return 0, nil } diff --git a/internal/askcli/command_write_test.go b/internal/askcli/command_write_test.go index 2ed5fc9..31ea25a 100644 --- a/internal/askcli/command_write_test.go +++ b/internal/askcli/command_write_test.go @@ -49,6 +49,23 @@ func TestHandleStart_AliasSelector(t *testing.T) { } func TestHandleDenotate_Success(t *testing.T) { + dir := t.TempDir() + oldRoot := taskAliasCacheRoot + oldNow := nowTaskAliasCache + taskAliasCacheRoot = func() (string, error) { return filepath.Join(dir, "hexai"), nil } + nowTaskAliasCache = func() time.Time { return time.Date(2026, 3, 26, 12, 0, 0, 0, time.UTC) } + defer func() { + taskAliasCacheRoot = oldRoot + nowTaskAliasCache = oldNow + }() + + writeTaskAliasCacheForTest(t, taskAliasCache{ + NextID: 1, + Entries: []taskAliasCacheEntry{ + {UUID: "test-uuid", Alias: "0", CreatedAt: nowTaskAliasCache()}, + }, + }) + d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) { if len(args) == 2 && args[0] == "uuid:test-uuid" && args[1] == "export" { io.WriteString(stdout, `[{"uuid":"test-uuid","description":"Task","status":"pending","priority":"M","tags":[],"urgency":0,"depends":[]}]`) @@ -64,8 +81,8 @@ func TestHandleDenotate_Success(t *testing.T) { if err != nil { t.Fatalf("denotate returned error: %v", err) } - if !strings.Contains(stdout.String(), "ok") || !strings.Contains(stdout.String(), "test-uuid") { - t.Fatalf("stdout = %q, want ok + uuid", stdout.String()) + if !strings.Contains(stdout.String(), "ok 0") || strings.Contains(stdout.String(), "test-uuid") { + t.Fatalf("stdout = %q, want ok + alias only", stdout.String()) } } @@ -94,6 +111,23 @@ func TestHandleDenotate_MissingArgs(t *testing.T) { } func TestHandleModify_Success(t *testing.T) { + dir := t.TempDir() + oldRoot := taskAliasCacheRoot + oldNow := nowTaskAliasCache + taskAliasCacheRoot = func() (string, error) { return filepath.Join(dir, "hexai"), nil } + nowTaskAliasCache = func() time.Time { return time.Date(2026, 3, 26, 12, 0, 0, 0, time.UTC) } + defer func() { + taskAliasCacheRoot = oldRoot + nowTaskAliasCache = oldNow + }() + + writeTaskAliasCacheForTest(t, taskAliasCache{ + NextID: 1, + Entries: []taskAliasCacheEntry{ + {UUID: "test-uuid", Alias: "0", CreatedAt: nowTaskAliasCache()}, + }, + }) + d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) { if len(args) == 2 && args[0] == "uuid:test-uuid" && args[1] == "export" { io.WriteString(stdout, `[{"uuid":"test-uuid","description":"Task","status":"pending","priority":"M","tags":[],"urgency":0,"depends":[]}]`) @@ -106,8 +140,8 @@ func TestHandleModify_Success(t *testing.T) { if code != 0 { t.Fatalf("modify code = %d, want 0", code) } - if !strings.Contains(stdout.String(), "ok") || !strings.Contains(stdout.String(), "test-uuid") { - t.Fatalf("stdout = %q, want ok + uuid", stdout.String()) + if !strings.Contains(stdout.String(), "ok 0") || strings.Contains(stdout.String(), "test-uuid") { + t.Fatalf("stdout = %q, want ok + alias only", stdout.String()) } } @@ -124,6 +158,23 @@ func TestHandleModify_NumericID(t *testing.T) { } func TestHandleAnnotate_Success(t *testing.T) { + dir := t.TempDir() + oldRoot := taskAliasCacheRoot + oldNow := nowTaskAliasCache + taskAliasCacheRoot = func() (string, error) { return filepath.Join(dir, "hexai"), nil } + nowTaskAliasCache = func() time.Time { return time.Date(2026, 3, 26, 12, 0, 0, 0, time.UTC) } + defer func() { + taskAliasCacheRoot = oldRoot + nowTaskAliasCache = oldNow + }() + + writeTaskAliasCacheForTest(t, taskAliasCache{ + NextID: 1, + Entries: []taskAliasCacheEntry{ + {UUID: "test-uuid", Alias: "0", CreatedAt: nowTaskAliasCache()}, + }, + }) + d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) { if len(args) == 2 && args[0] == "uuid:test-uuid" && args[1] == "export" { io.WriteString(stdout, `[{"uuid":"test-uuid","description":"Task","status":"pending","priority":"M","tags":[],"urgency":0,"depends":[]}]`) @@ -136,8 +187,8 @@ func TestHandleAnnotate_Success(t *testing.T) { if code != 0 { t.Fatalf("annotate code = %d, want 0", code) } - if !strings.Contains(stdout.String(), "ok") || !strings.Contains(stdout.String(), "test-uuid") { - t.Fatalf("stdout = %q, want ok + uuid", stdout.String()) + if !strings.Contains(stdout.String(), "ok 0") || strings.Contains(stdout.String(), "test-uuid") { + t.Fatalf("stdout = %q, want ok + alias only", stdout.String()) } } @@ -154,6 +205,23 @@ func TestHandleAnnotate_MissingArgs(t *testing.T) { } func TestHandleStart_Success(t *testing.T) { + dir := t.TempDir() + oldRoot := taskAliasCacheRoot + oldNow := nowTaskAliasCache + taskAliasCacheRoot = func() (string, error) { return filepath.Join(dir, "hexai"), nil } + nowTaskAliasCache = func() time.Time { return time.Date(2026, 3, 26, 12, 0, 0, 0, time.UTC) } + defer func() { + taskAliasCacheRoot = oldRoot + nowTaskAliasCache = oldNow + }() + + writeTaskAliasCacheForTest(t, taskAliasCache{ + NextID: 1, + Entries: []taskAliasCacheEntry{ + {UUID: "test-uuid", Alias: "0", CreatedAt: nowTaskAliasCache()}, + }, + }) + d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []stri |
