Skip to content

Commit 1650169

Browse files
Copilotneongreen
andcommitted
tak: Support numeric-only IDs and hide suffix in display
Enhancements: 1. Accept bare numbers as task IDs (e.g., "1" for "tak-1") - Updated ResolveTaskID to normalize bare numbers to "tak-N" format - Works in all commands: status, note, view 2. Hide installation suffix in display unless needed for disambiguation - Added FormatTaskID() function to format IDs for display - Suffix only shown when multiple installations have same task number - Updated 'ls' and 'new' commands to use formatted display Changes: - Add strconv import for number parsing - Update ResolveTaskID to handle bare numbers - Add GetAllTaskIDs method to retrieve all task IDs - Add FormatTaskID for smart display formatting - Update ls and new commands to use formatted IDs Co-authored-by: neongreen <1523306+neongreen@users.noreply.github.com>
1 parent ce811b0 commit 1650169

3 files changed

Lines changed: 84 additions & 5 deletions

File tree

tak/db.go

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"math/big"
99
"os"
1010
"path/filepath"
11+
"strconv"
1112
"strings"
1213
"time"
1314

@@ -296,8 +297,8 @@ func generateRandomSuffix(length int) string {
296297
return string(b)
297298
}
298299

299-
// ResolveTaskID resolves a short task ID (e.g., "tak-2") to a full task ID (e.g., "tak-2-abc123")
300-
// If the input is already a full ID, it validates that it exists
300+
// ResolveTaskID resolves a short task ID to a full task ID
301+
// Accepts formats: "1", "tak-1", "tak-1-abc123"
301302
// Returns an error if the ID is ambiguous or doesn't exist
302303
func (d *DB) ResolveTaskID(shortID string) (string, error) {
303304
// Get all task IDs from the database
@@ -333,6 +334,12 @@ func (d *DB) ResolveTaskID(shortID string) (string, error) {
333334
}
334335
}
335336

337+
// Normalize shortID - if it's just a number, prepend "tak-"
338+
normalizedID := shortID
339+
if _, err := strconv.Atoi(shortID); err == nil {
340+
normalizedID = "tak-" + shortID
341+
}
342+
336343
// Try to match as a short ID (without suffix)
337344
var matches []string
338345
for _, fullID := range taskIDs {
@@ -341,7 +348,7 @@ func (d *DB) ResolveTaskID(shortID string) (string, error) {
341348
parts := strings.Split(fullID, "-")
342349
if len(parts) >= 2 {
343350
shortForm := strings.Join(parts[:2], "-") // tak-<number>
344-
if shortForm == shortID {
351+
if shortForm == normalizedID {
345352
matches = append(matches, fullID)
346353
}
347354
}
@@ -357,3 +364,61 @@ func (d *DB) ResolveTaskID(shortID string) (string, error) {
357364

358365
return matches[0], nil
359366
}
367+
368+
// GetAllTaskIDs returns all task IDs in the database
369+
func (d *DB) GetAllTaskIDs() ([]string, error) {
370+
query := `
371+
SELECT DISTINCT json_extract(payload, '$.task_id') as task_id
372+
FROM events
373+
WHERE kind = 'task.created'
374+
`
375+
376+
rows, err := d.db.Query(query)
377+
if err != nil {
378+
return nil, fmt.Errorf("failed to query task IDs: %w", err)
379+
}
380+
defer rows.Close()
381+
382+
var taskIDs []string
383+
for rows.Next() {
384+
var taskID string
385+
if err := rows.Scan(&taskID); err != nil {
386+
return nil, fmt.Errorf("failed to scan task ID: %w", err)
387+
}
388+
taskIDs = append(taskIDs, taskID)
389+
}
390+
391+
return taskIDs, rows.Err()
392+
}
393+
394+
// FormatTaskID formats a task ID for display, hiding the suffix unless needed for disambiguation
395+
func FormatTaskID(fullID string, allTaskIDs []string) string {
396+
// Extract parts: tak-<number>-<suffix>
397+
parts := strings.Split(fullID, "-")
398+
if len(parts) < 3 {
399+
return fullID // Malformed ID, return as-is
400+
}
401+
402+
shortForm := strings.Join(parts[:2], "-") // tak-<number>
403+
404+
// Check if any other task has the same short form but different suffix
405+
needsSuffix := false
406+
for _, otherID := range allTaskIDs {
407+
if otherID == fullID {
408+
continue
409+
}
410+
otherParts := strings.Split(otherID, "-")
411+
if len(otherParts) >= 2 {
412+
otherShortForm := strings.Join(otherParts[:2], "-")
413+
if otherShortForm == shortForm {
414+
needsSuffix = true
415+
break
416+
}
417+
}
418+
}
419+
420+
if needsSuffix {
421+
return fullID
422+
}
423+
return shortForm
424+
}

tak/main.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,14 @@ var newCmd = &cobra.Command{
118118
return err
119119
}
120120

121-
fmt.Printf("Created task %s: %s\n", taskID, title)
121+
// Get all task IDs for formatting (including the one we just created)
122+
allTaskIDs, err := db.GetAllTaskIDs()
123+
if err != nil {
124+
return err
125+
}
126+
127+
displayID := FormatTaskID(taskID, allTaskIDs)
128+
fmt.Printf("Created task %s: %s\n", displayID, title)
122129
return nil
123130
},
124131
}
@@ -317,6 +324,12 @@ var lsCmd = &cobra.Command{
317324

318325
tasks := reducer.GetAllTasks()
319326

327+
// Get all task IDs for formatting
328+
allTaskIDs, err := db.GetAllTaskIDs()
329+
if err != nil {
330+
return err
331+
}
332+
320333
// Filter by axis if specified
321334
if axisFilter != "" {
322335
parts := strings.Split(axisFilter, ":")
@@ -338,7 +351,8 @@ var lsCmd = &cobra.Command{
338351
}
339352

340353
for _, task := range tasks {
341-
fmt.Printf("%s: %s\n", task.TaskID, task.Title)
354+
displayID := FormatTaskID(task.TaskID, allTaskIDs)
355+
fmt.Printf("%s: %s\n", displayID, task.Title)
342356
for axisName, axis := range task.Axes {
343357
fmt.Printf(" %s: %s\n", axisName, axis.Effective)
344358
}

tak/tak

6.05 KB
Binary file not shown.

0 commit comments

Comments
 (0)