diff --git a/CHANGELOG.md b/CHANGELOG.md index 42368ddd..2c7cbb30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ first added in the same Unreleased section is not an entry: edit that entry inst ## Unreleased +### Added + +- `tsk edit --thread ` puts an existing task on a thread, and `--clear-thread` takes it off ([edit](https://gettsk.sh/docs/cli/#edit)). + ## v0.14.0 ### Breaking diff --git a/CONTEXT.md b/CONTEXT.md index 107ed4a4..28e24b79 100644 --- a/CONTEXT.md +++ b/CONTEXT.md @@ -12,8 +12,8 @@ this file names things. - **list command**: `tsk list`, which prints tasks without changing them. - **status command**: `tsk status`, which sets a task's human status. `start` is an alias for `started`. -- **edit command**: `tsk edit`, which changes a task's title, notes, assignee, base, or - `after` list. It never changes scope or thread. +- **edit command**: `tsk edit`, which changes a task's title, notes, assignee, thread, base, + due date, or `after` list. It never changes scope. - **bulk add**: one `add` of many items. It reports each item and makes one durable write of the successes. - **invocation default**: the scope `add` uses when no project or `--desk` is given: the diff --git a/site/public/llms.txt b/site/public/llms.txt index 2c8226a0..d7053949 100644 --- a/site/public/llms.txt +++ b/site/public/llms.txt @@ -14,7 +14,7 @@ The human works the board in a TUI; agents read and write the same tasks with th - Status: `open` (inbox), `ready` (picked), `started`, `blocked`, `review`, `done`. The human owns status; checking every step never completes a task. - Desk and project: a project is a Git repository root, named by its folder or by a title (`tsk project title`). `-p` takes the title or the folder name. The desk holds tasks with no project. -- Thread: a label that groups related work, within a project or across several. +- Thread: a label that groups related work, within a project or across several. `tsk add --thread`, `tsk edit --thread` and `--clear-thread` set it. - Task number: `T12`, `12`, and the task's UUID address the same task. - Notice: `N` rows on the desk (starter tasks, What's new) are for the human only. `tsk list` never shows them. - Agent profile: an `[agent.]` table in `config.toml` holding the command that launches an agent. diff --git a/site/src/content/docs/docs/cli.md b/site/src/content/docs/docs/cli.md index 1ac4e4ee..dc08471e 100644 --- a/site/src/content/docs/docs/cli.md +++ b/site/src/content/docs/docs/cli.md @@ -19,7 +19,7 @@ tsk list | [`tsk add`](#add) | Add a task, or every task in a JSON plan | | [`tsk list`](#list) | Read tasks | | [`tsk status`](#status) | Set a task's status, block it, or put it up for review | -| [`tsk edit`](#edit) | Change a task's title, notes, assignee, base, due date, after list, or who its block or review waits on | +| [`tsk edit`](#edit) | Change a task's title, notes, assignee, thread, base, due date, after list, or who its block or review waits on | | [`tsk steps`](#steps) | Add, toggle, rename, move, or remove a step | | [`tsk checks`](#checks) | Mark a review check open, passed, or failed | | [`tsk reply`](#reply) | Answer a block, or give feedback on a review | @@ -385,10 +385,10 @@ tsk status T12 review --done "Opened PR #42" --check "tests pass" --next "docs" ## edit -Changes a task's title, notes, assignee, dispatch base, due date, the tasks it runs after, or who its open block or review waits on. Scope and thread stay as they are: to move a task, add it again in the right scope and archive the old one. +Changes a task's title, notes, assignee, thread, dispatch base, due date, the tasks it runs after, or who its open block or review waits on. Scope stays as it is: to move a task, add it again in the right scope and archive the old one. ```text -tsk edit [--title ] [--notes <notes> | --append-notes <text>] [--assignee <name> | --unassign] [--base <branch> | --clear-base] [--due <date> | --clear-due] [--after <task>]... [--clear-after] [--on <who>] [--state-dir <dir>] +tsk edit <task> [--title <title>] [--notes <notes> | --append-notes <text>] [--assignee <name> | --unassign] [--thread <name> | --clear-thread] [--base <branch> | --clear-base] [--due <date> | --clear-due] [--after <task>]... [--clear-after] [--on <who>] [--state-dir <dir>] ``` | Flag | Meaning | @@ -398,6 +398,8 @@ tsk edit <task> [--title <title>] [--notes <notes> | --append-notes <text>] [--a | `--append-notes <text>` | Add text below the notes after one blank line, or set it as the notes when there are none | | `--assignee <name>` | Assign an agent profile from [`config.toml`](/docs/storage/#configuration), `me`, or a person ([names](/docs/dispatch/#assignee-names)) | | `--unassign` | Clear the assignee | +| `--thread <name>` | Put the task on this [thread](/docs/capture/#thread-names), replacing any other | +| `--clear-thread` | Take the task off its thread | | `--base <branch>` | Dispatch from this existing branch, not a tag or commit (`unknown-base`) | | `--clear-base` | Dispatch from the project's default branch | | `--due <date>` | Set the day it is due, as `YYYY-MM-DD`. No time of day (`invalid-due`) | diff --git a/skills/tsk-cli/SKILL.md b/skills/tsk-cli/SKILL.md index 39e839e5..ce57f835 100644 --- a/skills/tsk-cli/SKILL.md +++ b/skills/tsk-cli/SKILL.md @@ -1,7 +1,7 @@ --- name: tsk-cli description: Work the user's tsk task board from the command line. Use when asked to add, update, edit, start, block, finish, archive, or restore a task on the board (or "tsk", "the tsk board", "the desk"), to add or tick steps, to answer "what's on the board", "what's next", "what's on deck", "what needs me", or to refine a task ("refine T12", "let's discuss T12", "what's missing from T12", "improve / rewrite this task"). Always `tsk add|list|status|reply|edit|steps|archive|dispatch|clean|trash`, never the TUI. -version: 1.7.0 +version: 1.8.0 --- # tsk: the user's task board @@ -184,8 +184,8 @@ criteria, no design document, no code. It ends with a better task on the board. - Does not exist yet: `tsk add -t "…" -n "…"` in the agreed scope (`--desk`, `-p`), with `--thread` if agreed. - Steps only when the user wants order of work tracked: `tsk steps T12 add "…"` per step. - - Never change status. `edit` cannot change scope or thread: for a scope change re-add in the - right scope and archive the stray; say so before doing it. + - Never change status. `edit --thread` changes the thread; `edit` cannot change scope: re-add + in the right scope and archive the stray, and say so before doing it. 7. **Stop.** The hand-off is the updated or created task. Report its number and title in one line. Do not offer builders, worktrees, or plans, and do not start building unless asked. diff --git a/skills/tsk-coordinator/SKILL.md b/skills/tsk-coordinator/SKILL.md index 2035518f..af9feb82 100644 --- a/skills/tsk-coordinator/SKILL.md +++ b/skills/tsk-coordinator/SKILL.md @@ -1,7 +1,7 @@ --- name: tsk-coordinator description: 'Coordinate a multi-agent build: plan the work, brief builder agents, gate every pull request with an independent review, live-test before merge, and report to the user. Works with any agent and tracker, tuned for the tsk board. Use when asked to coordinate builders or workers, run parallel agents, "move the plan along", or work through a task list on your own.' -version: 1.7.0 +version: 1.8.0 --- # tsk-coordinator: run builders for the user diff --git a/src/cli/edit.rs b/src/cli/edit.rs index d4abde75..a93eb5c3 100644 --- a/src/cli/edit.rs +++ b/src/cli/edit.rs @@ -1,5 +1,5 @@ -//! Headless edits: title, notes, assignee, base, due date, after, and who an open block or -//! review waits on. +//! Headless edits: title, notes, assignee, thread, base, due date, after, and who an open +//! block or review waits on. use std::path::PathBuf; @@ -21,6 +21,8 @@ pub struct EditFields { pub append_notes: Option<String>, /// `None` leaves it unchanged, `Some(None)` clears it. A name is read by the name rule. pub assignee: Option<Option<String>>, + /// `None` leaves it unchanged, `Some(None)` clears it. A name is already normalized. + pub thread: Option<Option<String>>, /// `None` leaves it unchanged, `Some(None)` clears it. pub base: Option<Option<String>>, /// `None` leaves it unchanged, `Some(None)` clears it. A day is `YYYY-MM-DD`. @@ -84,7 +86,7 @@ impl EditError { } } -/// Replace the supplied title and/or notes, keeping scope and thread. +/// Replace the supplied fields, keeping scope. /// /// Whitespace-only notes clear the field. Repeating the stored values writes nothing; a /// repeated append adds its text again. @@ -131,6 +133,7 @@ pub fn run( notes: fields.notes, append_notes: fields.append_notes, assignee, + thread: fields.thread, base: fields.base, due: fields.due, after: fields.after, @@ -167,6 +170,7 @@ struct Edit { notes: Option<String>, append_notes: Option<String>, assignee: Option<Option<Assignee>>, + thread: Option<Option<String>>, base: Option<Option<String>>, due: Option<Option<String>>, after: Option<Vec<u64>>, @@ -225,6 +229,10 @@ fn apply( .assignee .clone() .unwrap_or_else(|| found.assignee.clone()); + let next_thread = fields + .thread + .clone() + .unwrap_or_else(|| found.thread.clone()); let next_base = fields.base.clone().unwrap_or_else(|| found.base.clone()); if let Some(base) = fields.base.as_ref().and_then(|value| value.as_deref()) { if let Err(error) = crate::git_base::validate_task_base(&found.scope, base, true) { @@ -256,6 +264,7 @@ fn apply( let assignee = fields.assignee.clone().flatten(); if next_title == found.title && next_notes == found.notes + && next_thread == found.thread && next_assignee == found.assignee && next_base == found.base && !changed_after @@ -273,6 +282,7 @@ fn apply( } let fields_changed = next_title != found.title || next_notes != found.notes + || next_thread != found.thread || next_assignee != found.assignee || next_base != found.base; let edited = if fields_changed { @@ -281,7 +291,7 @@ fn apply( &next_title, next_notes, found.scope, - found.thread, + next_thread, next_assignee, next_base, ) diff --git a/src/cli/mod.rs b/src/cli/mod.rs index bc600606..89e5b074 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -495,6 +495,8 @@ fn run_edit(args: Vec<String>) -> CliOutput { && input.append_notes.is_none() && input.assignee.is_none() && !input.unassign + && input.thread.is_none() + && !input.clear_thread && input.base.is_none() && !input.clear_base && input.due.is_none() @@ -504,7 +506,7 @@ fn run_edit(args: Vec<String>) -> CliOutput { && input.on.is_none() { return presenter::edit_usage( - "title, notes, append-notes, assignee, base, due, after, on, --unassign, --clear-base, --clear-due, or --clear-after is required", + "title, notes, append-notes, assignee, thread, base, due, after, on, --unassign, --clear-thread, --clear-base, --clear-due, or --clear-after is required", ); } let assignee = if input.unassign { @@ -512,6 +514,11 @@ fn run_edit(args: Vec<String>) -> CliOutput { } else { input.assignee.map(Some) }; + let thread = if input.clear_thread { + Some(None) + } else { + input.thread.map(Some) + }; let base = if input.clear_base { Some(None) } else { @@ -532,6 +539,7 @@ fn run_edit(args: Vec<String>) -> CliOutput { notes: input.notes, append_notes: input.append_notes, assignee, + thread, base, due, after: if input.clear_after { diff --git a/src/cli/parser.rs b/src/cli/parser.rs index 8a44672d..a62fb4ff 100644 --- a/src/cli/parser.rs +++ b/src/cli/parser.rs @@ -732,6 +732,9 @@ pub struct FlagEdit { pub append_notes: Option<String>, pub assignee: Option<String>, pub unassign: bool, + /// `--thread`: normalized at the argv boundary, like `tsk add --thread`. + pub thread: Option<String>, + pub clear_thread: bool, pub base: Option<String>, pub clear_base: bool, /// `--due`: a day as typed. Checked when the edit runs, so a bad date refuses with @@ -754,6 +757,12 @@ pub fn parse_assignee(value: &str) -> Result<String, String> { .map_err(|error| format!("invalid assignee name · {}", thread_refusal_message(error))) } +/// Parse one `--thread` value by the thread rules. +fn parse_thread(value: &str) -> Result<String, String> { + normalize_thread(value) + .map_err(|error| format!("invalid thread name · {}", thread_refusal_message(error))) +} + /// Parse one `--after` value: a task number, with or without its `T`. pub fn parse_after_number(value: &str) -> Result<u64, String> { let digits = value.strip_prefix(['T', 't']).unwrap_or(value); @@ -764,7 +773,7 @@ pub fn parse_after_number(value: &str) -> Result<u64, String> { .ok_or_else(|| format!("invalid --after value {value} · use a task number like T12")) } -/// Parse `tsk edit <task> [--title <title>] [--notes <notes>]` arguments, including argv0. +/// Parse `tsk edit <task> [<field flags>]` arguments, including argv0. pub fn parse_flag_edit(args: &[String]) -> Result<FlagEdit, String> { if args.get(1).map(String::as_str) != Some("edit") { return Err("expected edit command".into()); @@ -777,6 +786,8 @@ pub fn parse_flag_edit(args: &[String]) -> Result<FlagEdit, String> { append_notes: None, assignee: None, unassign: false, + thread: None, + clear_thread: false, base: None, clear_base: false, due: None, @@ -838,6 +849,18 @@ pub fn parse_flag_edit(args: &[String]) -> Result<FlagEdit, String> { parsed.unassign = true; index += 1; } + flag if flag.starts_with("--thread=") => { + parsed.thread = Some(parse_thread(&flag["--thread=".len()..])?); + index += 1; + } + "--thread" => { + parsed.thread = Some(parse_thread(&value(flag)?)?); + index += 2; + } + "--clear-thread" => { + parsed.clear_thread = true; + index += 1; + } flag if flag.starts_with("--base=") => { parsed.base = Some(flag["--base=".len()..].to_owned()); index += 1; @@ -901,6 +924,9 @@ pub fn parse_flag_edit(args: &[String]) -> Result<FlagEdit, String> { if parsed.unassign && parsed.assignee.is_some() { return Err("--unassign cannot be used with --assignee".into()); } + if parsed.clear_thread && parsed.thread.is_some() { + return Err("--clear-thread cannot be used with --thread".into()); + } if parsed.clear_base && parsed.base.is_some() { return Err("--clear-base cannot be used with --base".into()); } @@ -1206,6 +1232,8 @@ mod tests { append_notes: None, assignee: None, unassign: false, + thread: None, + clear_thread: false, base: None, clear_base: false, due: None, @@ -1219,6 +1247,29 @@ mod tests { ); } + #[test] + fn edit_parses_thread_flags_by_the_thread_rules() { + let args = |rest: &[&str]| { + ["tsk", "edit", "T5"] + .iter() + .chain(rest) + .map(|arg| (*arg).to_owned()) + .collect::<Vec<_>>() + }; + let set = parse_flag_edit(&args(&["--thread", "Auth"])).expect("thread"); + assert_eq!(set.thread.as_deref(), Some("auth")); + assert!(!set.clear_thread); + let equals = parse_flag_edit(&args(&["--thread=release"])).expect("thread="); + assert_eq!(equals.thread.as_deref(), Some("release")); + let clear = parse_flag_edit(&args(&["--clear-thread"])).expect("clear"); + assert!(clear.clear_thread); + assert_eq!(clear.thread, None); + let invalid = parse_flag_edit(&args(&["--thread", "two words"])).expect_err("invalid"); + assert!(invalid.starts_with("invalid thread name · "), "{invalid}"); + assert!(parse_flag_edit(&args(&["--thread", "a", "--clear-thread"])).is_err()); + assert!(parse_flag_edit(&args(&["--thread"])).is_err()); + } + #[test] fn edit_parses_repeatable_after_and_status_parses_force() { let args = |command: &str, rest: &[&str]| { @@ -1628,9 +1679,7 @@ pub fn parse_flag_add(args: &[String]) -> Result<FlagAdd, String> { index += 1; } flag if flag.starts_with("--thread=") => { - parsed.thread = Some(normalize_thread(&flag["--thread=".len()..]).map_err( - |error| format!("invalid thread name · {}", thread_refusal_message(error)), - )?); + parsed.thread = Some(parse_thread(&flag["--thread=".len()..])?); parsed.has_item_flags = true; index += 1; } @@ -1650,9 +1699,7 @@ pub fn parse_flag_add(args: &[String]) -> Result<FlagAdd, String> { index += 2; } "--thread" => { - parsed.thread = Some(normalize_thread(&value(flag)?).map_err(|error| { - format!("invalid thread name · {}", thread_refusal_message(error)) - })?); + parsed.thread = Some(parse_thread(&value(flag)?)?); parsed.has_item_flags = true; index += 2; } diff --git a/src/cli/presenter.rs b/src/cli/presenter.rs index f93cbf3f..67a33fc2 100644 --- a/src/cli/presenter.rs +++ b/src/cli/presenter.rs @@ -129,7 +129,7 @@ const STATUS_USAGE: &[&str] = &[ "tsk status <task> review [--done <text>] [--check <text>]... [--next <text>] [--on <who>]", ]; const EDIT_USAGE: &[&str] = &[ - "tsk edit <task> [--title <title>] [--notes <notes> | --append-notes <text>] [--assignee <name> | --unassign] [--base <branch> | --clear-base] [--due <date> | --clear-due] [--after <task>]... [--clear-after] [--on <who>] [--state-dir <dir>]", + "tsk edit <task> [--title <title>] [--notes <notes> | --append-notes <text>] [--assignee <name> | --unassign] [--thread <name> | --clear-thread] [--base <branch> | --clear-base] [--due <date> | --clear-due] [--after <task>]... [--clear-after] [--on <who>] [--state-dir <dir>]", ]; const STEPS_USAGE: &[&str] = &[ "tsk steps <task> add <text> [<place>] [--state-dir <dir>]", @@ -2261,7 +2261,7 @@ pub fn status_rejected(error: StatusError, task: TaskAddress) -> CliOutput { pub fn edit_help() -> CliOutput { help(HelpDoc { usage: lines(EDIT_USAGE), - purpose: "Change a task's title, notes, assignee, dispatch base, due date, the tasks it runs after, or who its open block or review waits on. Scope and thread stay as they are.".into(), + purpose: "Change a task's title, notes, assignee, thread, dispatch base, due date, the tasks it runs after, or who its open block or review waits on. Scope stays as it is.".into(), groups: vec![ group("Arguments", &[("<task>", "a task number or UUID")]), group( @@ -2278,6 +2278,11 @@ pub fn edit_help() -> CliOutput { "assign an agent profile from config.toml, me, or a person's name", ), ("--unassign", "clear the assignee"), + ( + "--thread <name>", + "set or change the thread: letters, numbers, hyphens, dots", + ), + ("--clear-thread", "take the task off its thread"), ( "--base <branch>", "dispatch from this existing branch of the project", @@ -2311,6 +2316,7 @@ pub fn edit_help() -> CliOutput { examples: vec![ "tsk edit T12 --title \"Fix timeout on slow connections\"".into(), "tsk edit T12 --assignee claude --base main".into(), + "tsk edit T12 --thread auth".into(), "tsk edit T205 --after T202 --after T12".into(), "tsk edit T12 --on coordinator".into(), ], diff --git a/src/setup_agent.rs b/src/setup_agent.rs index ebbfe864..aa16ea90 100644 --- a/src/setup_agent.rs +++ b/src/setup_agent.rs @@ -1301,15 +1301,15 @@ mod tests { #[test] fn embedded_skill_declares_semver() { let version = embedded_skill_version(); - assert_eq!(version, "1.7.0"); - assert_eq!(frontmatter_version(SKILL_MD).as_deref(), Some("1.7.0")); + assert_eq!(version, "1.8.0"); + assert_eq!(frontmatter_version(SKILL_MD).as_deref(), Some("1.8.0")); let mut hash: u64 = 0xcbf2_9ce4_8422_2325; for byte in SKILL_MD.bytes() { hash ^= u64::from(byte); hash = hash.wrapping_mul(0x0000_0100_0000_01b3); } assert_eq!( - hash, 0x3f63_e397_8a92_3dc0, + hash, 0xc8df_587c_0ebd_bda3, "skills/tsk-cli/SKILL.md changed: refresh this hash pin, and bump `version:` only if this is the first skill edit since the last release" ); } @@ -1334,7 +1334,7 @@ mod tests { assert!(COORDINATOR_MD.contains("\nname: tsk-coordinator\n")); assert_eq!( fnv1a(COORDINATOR_MD), - 0xac3b_5196_dd50_f2ad, + 0x208c_5e4e_dc95_d234, "skills/tsk-coordinator/SKILL.md changed: refresh this hash pin, and bump both skills' `version:` only if this is the first skill edit since the last release" ); } diff --git a/tests/cli_edit.rs b/tests/cli_edit.rs index f2a7a7da..ff39f81f 100644 --- a/tests/cli_edit.rs +++ b/tests/cli_edit.rs @@ -302,6 +302,82 @@ fn edit_clears_notes_and_keeps_scope_and_thread() { assert_eq!(task.title, "keep scope"); } +#[test] +fn edit_sets_changes_and_clears_the_thread_keeping_scope() { + let dir = temp_state_dir("thread"); + let _guard = TempDirGuard(dir.clone()); + let mut state = DomainState::new(); + state + .create( + "needs a thread", + None, + TaskScope::Project { + path: "/tmp/edit-cli-thread-project".into(), + }, + ProvenanceOrigin::Manual, + None, + ) + .expect("seed"); + TaskStore::new(&dir).save(&state).expect("save seed"); + let load = || TaskStore::new(&dir).load().expect("load").tasks()[0].clone(); + let thread_edits = |task: &tsk_tui::domain::Task| { + task.history + .iter() + .filter(|event| event.kind == TaskEventKind::Edited) + .filter(|event| { + event.detail.as_ref().map(|detail| detail.fields.clone()) + == Some(vec![tsk_tui::domain::EditedField::Thread]) + }) + .count() + }; + + let set = edit(&dir, &["T1", "--thread", "Auth"]); + assert_eq!(set.code, 0, "{:?}", set.stderr); + assert_eq!(set.stdout, "edited T1 needs a thread\n"); + let task = load(); + assert_eq!(task.thread.as_deref(), Some("auth")); + assert_eq!(thread_edits(&task), 1, "the paper trail names the thread"); + assert_eq!( + task.scope, + TaskScope::Project { + path: "/tmp/edit-cli-thread-project".into(), + } + ); + + let before_repeat = fs::read(dir.join("tsk.json")).expect("read store"); + let again = edit(&dir, &["T1", "--thread=auth"]); + assert_eq!(again.code, 0, "{:?}", again.stderr); + assert_eq!( + fs::read(dir.join("tsk.json")).expect("read store"), + before_repeat, + "a repeat writes nothing" + ); + + let changed = edit(&dir, &["T1", "--thread", "release"]); + assert_eq!(changed.code, 0, "{:?}", changed.stderr); + let task = load(); + assert_eq!(task.thread.as_deref(), Some("release")); + assert_eq!(thread_edits(&task), 2); + + let invalid = edit(&dir, &["T1", "--thread", "bad_name"]); + assert_eq!(invalid.code, 2); + assert!( + invalid.stderr.contains("invalid thread name"), + "{}", + invalid.stderr + ); + let both = edit(&dir, &["T1", "--thread", "x", "--clear-thread"]); + assert_eq!(both.code, 2); + assert_eq!(load().thread.as_deref(), Some("release")); + + let cleared = edit(&dir, &["T1", "--clear-thread"]); + assert_eq!(cleared.code, 0, "{:?}", cleared.stderr); + let task = load(); + assert_eq!(task.thread, None); + assert_eq!(thread_edits(&task), 3); + assert_eq!(task.title, "needs a thread"); +} + #[test] fn edit_notes_keeps_newlines_and_tabs_like_add() { let dir = temp_state_dir("multiline"); @@ -445,7 +521,7 @@ fn edit_without_fields_is_usage() { assert!(output .stderr .contains( - "title, notes, append-notes, assignee, base, due, after, on, --unassign, --clear-base, --clear-due, or --clear-after is required" + "title, notes, append-notes, assignee, thread, base, due, after, on, --unassign, --clear-thread, --clear-base, --clear-due, or --clear-after is required" )); } @@ -461,6 +537,8 @@ fn edit_help_names_title_notes_and_equals_forms() { "--title=<value>", "--notes=<value>", "--append-notes <text>", + "--thread <name>", + "--clear-thread", "--append-notes=<value>", "Arguments", "Options",