Restore td- prefix on displayed task IDs

Amolith created

short() and display_id() now emit td-XXXXXXX instead of bare suffixes.
resolve_task_id() strips the prefix on input so both forms are accepted.

Change summary

src/db.rs        | 14 +++++++++++++-
tests/cli_dep.rs |  4 ++--
tests/cli_log.rs |  4 ++--
3 files changed, 17 insertions(+), 5 deletions(-)

Detailed changes

src/db.rs 🔗

@@ -143,7 +143,17 @@ impl TaskId {
     }
 
     pub fn short(&self) -> String {
-        self.0[self.0.len() - 7..].to_string()
+        format!("td-{}", &self.0[self.0.len() - 7..])
+    }
+
+    /// Return a display-friendly short ID from a raw ULID string.
+    pub fn display_id(raw: &str) -> String {
+        let n = raw.len();
+        if n > 7 {
+            format!("td-{}", &raw[n - 7..])
+        } else {
+            format!("td-{raw}")
+        }
     }
 }
 
@@ -539,6 +549,8 @@ pub fn list_projects() -> Result<Vec<String>> {
 }
 
 pub fn resolve_task_id(store: &Store, raw: &str, include_deleted: bool) -> Result<TaskId> {
+    let raw = raw.strip_prefix("td-").unwrap_or(raw);
+
     if let Ok(id) = TaskId::parse(raw) {
         if store.get_task(&id, include_deleted)?.is_some() {
             return Ok(id);

tests/cli_dep.rs 🔗

@@ -221,7 +221,7 @@ fn dep_add_rejects_nonexistent_child() {
         .current_dir(&tmp)
         .assert()
         .failure()
-        .stderr(predicate::str::contains("task 'td-ghost' not found"));
+        .stderr(predicate::str::contains("task 'ghost' not found"));
 }
 
 #[test]
@@ -234,5 +234,5 @@ fn dep_add_rejects_nonexistent_parent() {
         .current_dir(&tmp)
         .assert()
         .failure()
-        .stderr(predicate::str::contains("task 'td-phantom' not found"));
+        .stderr(predicate::str::contains("task 'phantom' not found"));
 }

tests/cli_log.rs 🔗

@@ -39,7 +39,7 @@ fn log_human_reports_task_id() {
         .assert()
         .success()
         .stdout(predicate::str::contains(format!(
-            "logged to {}",
+            "logged to td-{}",
             &id[id.len() - 7..]
         )));
 }
@@ -70,7 +70,7 @@ fn log_nonexistent_task_fails() {
         .current_dir(&tmp)
         .assert()
         .failure()
-        .stderr(predicate::str::contains("task 'td-nope' not found"));
+        .stderr(predicate::str::contains("task 'nope' not found"));
 }
 
 #[test]