From bc3ee0c53be53411bf8a58d6d1a86ae4394d9c1a Mon Sep 17 00:00:00 2001 From: Ansho Rei Date: Fri, 15 May 2026 03:00:59 +0200 Subject: [PATCH] (339c65a) Add comment command --- .../skill/worklane-kanban-skill/SKILL.md | 63 +++++-- AGENTS.md | 6 +- src/command.rs | 9 + src/main.rs | 43 +++++ tests/cmd_comment.rs | 166 ++++++++++++++++++ 5 files changed, 273 insertions(+), 14 deletions(-) create mode 100644 tests/cmd_comment.rs diff --git a/.opencode/skill/worklane-kanban-skill/SKILL.md b/.opencode/skill/worklane-kanban-skill/SKILL.md index c2e6077..8192fed 100644 --- a/.opencode/skill/worklane-kanban-skill/SKILL.md +++ b/.opencode/skill/worklane-kanban-skill/SKILL.md @@ -15,17 +15,13 @@ rendering: # Worklane Kanban Skill Use this skill when creating, listing, or managing Kanban-style tickets via the `worklane` CLI. +When asked to "create a ticket", use the `worklane add` command. +When asked to "implement", "work on" or "read" a ticket, use the `worklane show` command. + +When using backticks in the command arguments, escape them so the terminal doesn't execute them. ## Commands -### `worklane init` - -Initialize worklane in the current project (creates the worklane data file if it doesn't exist). - -``` -worklane init -``` - ### `worklane add` Add a new ticket to the backlog. @@ -71,9 +67,52 @@ Show the full details of a single ticket by UUID or title. worklane show "ticket title or uuid" ``` +### `worklane mv` + +Move a ticket between statuses. + +**Positional arguments:** +- ``: Ticket UUID (8+ characters) or title + +**Required options:** +- `--status `: Target status (`backlog`, `committed`, `reviewing`, `done`) + +**Options:** +- `-f`: Force move (allows skipping stages and backward moves) + +**Default behavior:** Only allows forward moves, one stage at a time (`backlog` -> `committed` -> `reviewing` -> `done`). + +Examples: + +```bash +worklane mv ticket-id --status committed # Move forward one stage +worklane mv ticket-title --status reviewing -f # Force skip stages +worklane mv a1b2c3d4 --status committed # Move by UUID prefix +worklane mv "My Ticket" --status done -f # Move by title with force +``` + +### `worklane comment` + +Add a comment to a ticket. + +**Positional arguments:** +- ``: Ticket UUID (8+ characters) or title +- ``: Comment text + +Comments are stored as timestamped markdown files in `.worklane/comments//` and include the git author and timestamp. + +Examples: + +```bash +worklane comment ticket-id "Reviewed, looks good" +worklane comment "My Ticket" "Needs changes to the UI" +worklane comment a1b2c3d4 "LGTM, approved" +``` + ## Workflow -1. Run `worklane init` before using other commands (if not already done) -2. Use `worklane add` to create tickets with all relevant details -3. Use `worklane ls [status]` to view tickets by status -4. Use `worklane show ` to view full ticket details +1. Use `worklane add` to create tickets with all relevant details +2. Use `worklane ls [status]` to view tickets by status +3. Use `worklane show ` to view full ticket details +4. Use `worklane mv --status ` to move tickets through the workflow +5. Use `worklane comment ` to add notes to tickets diff --git a/AGENTS.md b/AGENTS.md index d8c87a6..e51a297 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -14,6 +14,7 @@ | `worklane ls` | Lists tickets, optionally filtered by `--status` | | `worklane show ` | Shows ticket by UUID prefix or title | | `worklane mv --status [-f]` | Moves ticket between statuses. Default: forward only, one stage at a time. `-f` bypasses both restrictions | +| `worklane comment ` | Adds a comment to a ticket by UUID or title | ## Ticket File Format Filenames: `_.md` @@ -37,6 +38,7 @@ Tests create temporary `.worklane` directories with all four status folders pre- ## Agent workflow - When working on a ticket use `worklane show [ticketID]` to read the ticket. -- If the ticket is in the backlog, move it to committed using `worklane mv --status committed [ticketID]`. +- If the ticket status says backlog, move it to committed using `worklane mv --status committed [ticketID]`. - When your changes meet the acceptance criteria and the code compiles, move the ticket to reviewing using `worklane mv --status reviewing [ticketID]` -- If you need more information on how to use `worklane`, use the worklane kanban skill +- Use `worklane comment [ticketID] "[body]"` to leave notes on tickets (e.g. "LGTM", "needs fixes", "blocked on X") +- When the ticket is approved, move it to done using `worklane mv --status done [ticketID]` diff --git a/src/command.rs b/src/command.rs index ade5fa7..ceca507 100644 --- a/src/command.rs +++ b/src/command.rs @@ -69,4 +69,13 @@ pub enum Command { #[arg(short, long)] force: bool, }, + + /// Add a comment to a ticket + Comment { + /// Ticket UUID or title + ticket: String, + + /// Comment body (required) + body: String, + }, } diff --git a/src/main.rs b/src/main.rs index b5cddc9..d6b22f5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -535,6 +535,46 @@ fn cmd_mv(ticket_id: &str, target_status: &str, force: bool, start: &Path) -> Re Ok(()) } +fn cmd_comment(ticket_id: &str, body: &str, start: &Path) -> Result<()> { + if body.is_empty() { + return Err(anyhow!("Comment body is required.")); + } + + let worklane_dir = find_worklane_dir(start)?; + let (_status, title, content) = resolve_ticket(ticket_id, &worklane_dir)?; + let ticket_uuid = parse_ticket_field(&content, "ID"); + + if ticket_uuid == "_Not set_" { + return Err(anyhow!("Could not determine ticket ID.")); + } + + let comments_dir = worklane_dir.join("comments").join(&ticket_uuid); + fs::create_dir_all(&comments_dir)?; + + let timestamp = Local::now().format("%Y%m%d_%H%M%S"); + let filename = format!("{}.md", timestamp); + let filepath = comments_dir.join(&filename); + + let author = get_git_user().unwrap_or_else(|| "unknown".to_string()); + + let comment_content = format!( + "**Comment**\n\ + {}\n\ + \n\ + **Author**: {}\n\ + **Time**: {}\n\ + ", + body, + author, + Local::now().format("%Y-%m-%d %H:%M:%S") + ); + + fs::write(&filepath, comment_content)?; + + println!("Comment added to '{}' ({})", title, filename); + Ok(()) +} + fn content_trim_colored(content: &str) -> String { let lines: Vec<&str> = content.trim().lines().collect(); let mut result = String::new(); @@ -732,5 +772,8 @@ fn main() -> Result<()> { Command::Mv { ticket, status, force } => { cmd_mv(&ticket, &status, force, &start) } + Command::Comment { ticket, body } => { + cmd_comment(&ticket, &body, &start) + } } } diff --git a/tests/cmd_comment.rs b/tests/cmd_comment.rs new file mode 100644 index 0000000..70edf23 --- /dev/null +++ b/tests/cmd_comment.rs @@ -0,0 +1,166 @@ +use assert_cmd::Command; +use assert_fs::fixture::{PathChild, PathCreateDir}; +use assert_fs::TempDir; +use std::fs; +use std::path::PathBuf; + +const BIN_NAME: &str = env!("CARGO_BIN_EXE_worklane"); + +fn setup_worklane(temp: &TempDir) -> PathBuf { + let worklane = temp.child(".worklane"); + worklane.create_dir_all().unwrap(); + + for dir in ["backlog", "committed", "reviewing", "done"] { + worklane.child(dir).create_dir_all().unwrap(); + } + + worklane.path().to_path_buf() +} + +fn create_ticket( + worklane_dir: &PathBuf, + status: &str, + title: &str, +) -> String { + let uuid = uuid::Uuid::new_v4().to_string(); + let slug = title + .to_lowercase() + .chars() + .filter(|c| c.is_alphanumeric() || *c == ' ' || *c == '-' || *c == '_') + .map(|c| if c == ' ' { '-' } else { c }) + .collect::(); + let filename = format!("{}_{}.md", uuid, slug); + let content = format!( + "# {}\n\ + \n\ + ## Metadata\n\ + \n\ + - **ID**: {}\n\ + - **Status**: {}\n\ + ", + title, uuid, status + ); + fs::create_dir_all(worklane_dir.join(status)).unwrap(); + fs::write(worklane_dir.join(status).join(&filename), content).unwrap(); + uuid +} + +#[test] +fn comment_creates_file_with_valid_ticket_uuid() { + let temp = TempDir::new().unwrap(); + let worklane = setup_worklane(&temp); + + let uuid = create_ticket(&worklane, "backlog", "Test Ticket"); + + let mut cmd = Command::cargo_bin(BIN_NAME).unwrap(); + cmd.current_dir(&temp.path()) + .arg("comment") + .args([&uuid, "This is a test comment"]) + .assert() + .success(); + + let comments_dir = worklane.join("comments").join(&uuid); + assert!(comments_dir.exists()); + let files: Vec<_> = fs::read_dir(&comments_dir) + .unwrap() + .filter_map(|e| e.ok()) + .collect(); + assert_eq!(files.len(), 1); + let content = fs::read_to_string(files[0].path()).unwrap(); + assert!(content.contains("This is a test comment")); +} + +#[test] +fn comment_creates_file_with_valid_ticket_title() { + let temp = TempDir::new().unwrap(); + let worklane = setup_worklane(&temp); + + create_ticket(&worklane, "committed", "My Ticket"); + + let mut cmd = Command::cargo_bin(BIN_NAME).unwrap(); + cmd.current_dir(&temp.path()) + .arg("comment") + .args(["My Ticket", "Testing title lookup"]) + .assert() + .success(); +} + +#[test] +fn comment_error_when_ticket_not_found() { + let _temp = TempDir::new().unwrap(); + + let mut cmd = Command::cargo_bin(BIN_NAME).unwrap(); + cmd.arg("comment") + .arg("Nonexistent") + .arg("Some comment") + .assert() + .code(1); +} + +#[test] +fn comment_includes_git_user_and_body() { + let temp = TempDir::new().unwrap(); + let worklane = setup_worklane(&temp); + + let uuid = create_ticket(&worklane, "backlog", "Comment Test"); + + let mut cmd = Command::cargo_bin(BIN_NAME).unwrap(); + cmd.current_dir(&temp.path()) + .arg("comment") + .args([&uuid, "My comment body"]) + .assert() + .success(); + + let comments_dir = worklane.join("comments").join(&uuid); + let files: Vec<_> = fs::read_dir(&comments_dir) + .unwrap() + .filter_map(|e| e.ok()) + .collect(); + let content = fs::read_to_string(files[0].path()).unwrap(); + assert!(content.contains("My comment body")); + assert!(content.contains("**Author**")); +} + +#[test] +fn comment_stored_in_timestamped_file() { + let temp = TempDir::new().unwrap(); + let worklane = setup_worklane(&temp); + + let uuid = create_ticket(&worklane, "done", "Timestamp Test"); + + let mut cmd = Command::cargo_bin(BIN_NAME).unwrap(); + cmd.current_dir(&temp.path()) + .arg("comment") + .args([&uuid, "Timestamp test"]) + .assert() + .success(); + + let comments_dir = worklane.join("comments").join(&uuid); + let files: Vec<_> = fs::read_dir(&comments_dir) + .unwrap() + .filter_map(|e| e.ok()) + .collect(); + assert_eq!(files.len(), 1); + let filename = files[0].file_name().into_string().unwrap(); + assert!(filename.ends_with(".md")); +} + +#[test] +fn comment_creates_comments_directory() { + let temp = TempDir::new().unwrap(); + let worklane = setup_worklane(&temp); + + let uuid = create_ticket(&worklane, "reviewing", "Dir Test"); + + let comments_dir = worklane.join("comments").join(&uuid); + assert!(!comments_dir.exists()); + + let mut cmd = Command::cargo_bin(BIN_NAME).unwrap(); + cmd.current_dir(&temp.path()) + .arg("comment") + .args([&uuid, "Create dir test"]) + .assert() + .success(); + + assert!(comments_dir.exists()); +}