From b56b31d2d9501c2c889f08ad330408edca63b787 Mon Sep 17 00:00:00 2001 From: Ansho Rei Date: Fri, 21 Aug 2026 18:35:26 +0200 Subject: [PATCH] (f39b651) Add chown for the ticket owner, and bump to 0.10.0 The Owner field had no writer after `add`. It was folded into `set` in da03690 and comes out here as its own command, so no field is writable from two places, the same reasoning that keeps status in `mv` alone. `worklane chown alice 641e3d5`, user first, after Unix `chown`. That reverses the ticket-first order `mv`, `comment` and `show` use, deliberately: the name borrows the Unix association, so the argument order borrows it too. The swap is left to resolution rather than checked for. Given `chown 641e3d5 alice` the second argument has to resolve as a ticket, and a bare username does not, so the call fails on its own; a check on the first argument would only fire where resolution already refuses and would stay silent on the one case it cannot catch, a ticket whose title is the username. `cmd_chown` is therefore `set_metadata_field` plus `save_ticket`, with the whole-file no-op comparison `set` uses and the same `report()` line, so an owner set to the value it already holds is reported unchanged and nothing is written. Nothing new writes a file: the update goes through `write_then_replace`, scoped to the lines under `## Metadata`, so a description quoting `**Owner**:` is left as prose and a failure leaves the ticket whole. Tested for the change, the no-op, all three resolution tiers, a swapped call, an empty user, a ticket with no Owner field, and that the tick, the handwritten section and the filename all survive. The skill and the opencode tool carry it too, the tool with the argument order in its description, since that is the one place a model can get it wrong without failing. Co-Authored-By: Claude Opus 5 (1M context) --- .../skill/worklane-kanban-skill/SKILL.md | 23 +- .opencode/tools/worklane.ts | 27 ++ AGENTS.md | 4 +- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 1 + assets/SKILL.md | 12 +- src/command.rs | 20 ++ src/handlers.rs | 28 ++ src/main.rs | 1 + tests/cmd_chown.rs | 282 ++++++++++++++++++ 11 files changed, 394 insertions(+), 8 deletions(-) create mode 100644 tests/cmd_chown.rs diff --git a/.opencode/skill/worklane-kanban-skill/SKILL.md b/.opencode/skill/worklane-kanban-skill/SKILL.md index c7b4290..5c78309 100644 --- a/.opencode/skill/worklane-kanban-skill/SKILL.md +++ b/.opencode/skill/worklane-kanban-skill/SKILL.md @@ -112,8 +112,8 @@ criteria and handwritten sections are left alone. At least one field is required **Options:** `--title`, `--description` (or `-d`), `--acceptance` (or `-a`), `--plan` (or `-p`), `--tags` (or `-g`), `--due`, `--priority` -Owner is not settable here, and neither is status: `mv` owns status. Changing the -title renames the file, keeping the UUID. +Owner is not settable here, and neither is status: `chown` owns owner and `mv` owns +status. Changing the title renames the file, keeping the UUID. ```bash worklane set a1b2c3d4 --priority 1 @@ -138,6 +138,25 @@ worklane append a1b2c3d4 -a "One more criterium" worklane append a1b2c3d4 -p "A later step" ``` +### `worklane chown` + +Set the owner of a ticket. The only command that writes the Owner field: `set` does +not offer it. + +**Positional arguments:** +- ``: The new owner. Free text, checked against nothing +- ``: Ticket UUID prefix (4+ characters) or title + +The user comes first and the ticket second, after Unix `chown`. That is the one +command here that does not start with the ticket, so mind the order: swap the two and +the call fails, because the username has to resolve as a ticket. An owner set to the +value it already holds is reported unchanged and nothing is written. + +```bash +worklane chown alice a1b2c3d4 +worklane chown "Ansho Rei" "A clearer title" +``` + ### `worklane check` and `worklane uncheck` Tick or untick a single acceptance criterion. Every other criterion keeps its state, diff --git a/.opencode/tools/worklane.ts b/.opencode/tools/worklane.ts index 1c97dfa..a376773 100644 --- a/.opencode/tools/worklane.ts +++ b/.opencode/tools/worklane.ts @@ -395,6 +395,33 @@ export const append = tool({ }, }); +export const chown = tool({ + description: + "Change the owner of a worklane ticket. This is the only writer of the Owner field: set does not offer it. The user is free text and is checked against nothing. Note the argument order, user first and ticket second, after Unix chown.", + args: { + user: tool.schema + .string() + .describe("New owner (required). Free text, checked against nothing."), + ticket: tool.schema + .string() + .describe("Ticket UUID prefix (4+ chars) or title substring (required)"), + }, + async execute(args: Record, context: ToolContext) { + if (!args.user) { + return "Error changing owner: user is required"; + } + if (!args.ticket) { + return "Error changing owner: ticket is required"; + } + + try { + return await run(["chown", args.user, args.ticket], context); + } catch (err: any) { + return `Error changing owner: ${err.message}`; + } + }, +}); + /** * check and uncheck differ only in the verb, so the tool is built once. * diff --git a/AGENTS.md b/AGENTS.md index ec18036..71710cd 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -57,7 +57,9 @@ and this file is for what someone changing worklane's own code needs. ### Editing a Ticket - `set` replaces a field, `append` adds to a section. The verb carries the meaning, so no flag needs a replace-or-append prefix, and `append` only offers the sections that hold multiple lines -- **One field, one writer.** `set` has no `--owner` (that is `chown`'s, once it exists) and no `--status` (that is `mv`'s). Do not add either +- **One field, one writer.** `set` has no `--owner` (that is `chown`'s) and no `--status` (that is `mv`'s). Do not add either +- `chown` takes the **user first and the ticket second**, after Unix `chown`, and is the only command that does not start with the ticket. Deliberate: the name borrows the Unix association, so the order borrows it too. A swap is left to `resolve_ticket`, which refuses a bare username as a ticket. No argument is inspected to see whether it *also* names a ticket, since such a check would only fire where resolution already fails and would stay silent on the one case it cannot catch, a ticket whose title is the username +- `cmd_chown` is `set_metadata_field` plus `save_ticket`, with the same whole-file no-op comparison `set` uses and the same `report()` output, so nothing about writing a field lives twice - Sections are a table in `util.rs`: `DESCRIPTION`, `ACCEPTANCE`, `PLAN`, each with a heading, a label, the placeholder `add` writes when empty, and a `SectionKind`. Adding a section later is one entry, not edits in both commands - Everything is targeted line surgery, never a regenerated file. That is what keeps a ticked criterion ticked and a handwritten `## Notes` section intact when an unrelated field changes. `section_body()` finds the lines to touch, `set_metadata_line()` does the metadata, and every other byte is copied through - Appending to a numbered section continues from the count of steps already there and does not renumber what is above it, so a handwritten line in the section survives exactly as written diff --git a/Cargo.lock b/Cargo.lock index c0353cf..43ed466 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1494,7 +1494,7 @@ dependencies = [ [[package]] name = "worklane" -version = "0.9.0" +version = "0.10.0" dependencies = [ "anyhow", "assert_cmd", diff --git a/Cargo.toml b/Cargo.toml index ac8676e..409940a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "worklane" -version = "0.9.0" +version = "0.10.0" edition = "2024" [dependencies] diff --git a/README.md b/README.md index 3f1e3dd..cdbdcba 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ Worklane is a local Kanban flow for agentic software development. | `worklane mv --status [-f]` | Moves ticket between statuses. Default: forward only, one stage at a time. `-f` bypasses both restrictions | | `worklane set ` | Replaces fields with `--title`, `--description`, `--acceptance`, `--plan`, `--tags`, `--due`, `--priority`. At least one required. Changing the title renames the file, keeping the UUID | | `worklane append ` | Adds to a section with `--description`, `--acceptance`, `--plan`. At least one required. The description gains a paragraph; list items go on the end, steps numbered on from the last | +| `worklane chown ` | Sets the Owner field, the only command that writes it. Free text, checked against nothing. User first and ticket second, after Unix `chown` | | `worklane check [criterion]` | Ticks one acceptance criterion, by number as shown by `show` or by a substring. Prompts with the numbered list if omitted, or errors with it when there is no terminal | | `worklane uncheck [criterion]` | Unticks one acceptance criterion, addressed the same way | | `worklane comment ` | Adds a comment to a ticket by UUID or title | diff --git a/assets/SKILL.md b/assets/SKILL.md index 0254010..211bdff 100644 --- a/assets/SKILL.md +++ b/assets/SKILL.md @@ -90,11 +90,17 @@ worklane set 1b78a24 --priority 1 # replace a field worklane set 1b78a24 --title "A better title" # renames the file, keeps the uuid worklane append 1b78a24 --acceptance "One more criterion" worklane append 1b78a24 --description "What was learned since." +worklane chown alice 1b78a24 # hand the ticket to someone ``` -`set` replaces, `append` adds. Neither has `--owner` or `--status`: owner is its own -command's, and status is `mv`'s. A field set to the value it already holds is reported -unchanged and nothing is written. +`set` replaces, `append` adds. Neither has `--owner` or `--status`: owner is `chown`'s +and status is `mv`'s, so each field has exactly one writer. A field set to the value it +already holds is reported unchanged and nothing is written. + +`chown` takes the **user first and the ticket second**, after Unix `chown`, which is the +one command here that does not start with the ticket. The user is free text and is +checked against nothing. Swap the two and the call fails, because the username has to +resolve as a ticket. `worklane init` creates `.worklane/` with the four status directories, for a repo that has no board yet. diff --git a/src/command.rs b/src/command.rs index df37437..5affe98 100644 --- a/src/command.rs +++ b/src/command.rs @@ -109,6 +109,26 @@ pub enum Command { /// Add to a section of an existing ticket Append(AppendArgs), + /// Change the owner of a ticket + /// + /// User first, ticket second, after Unix `chown`. That reverses the ticket-first + /// order `mv`, `comment` and `show` use, deliberately: the name borrows the Unix + /// association, so the argument order borrows it too. + /// + /// A swap is caught by resolution rather than by a check of its own. Given + /// `chown 641e3d5 alice` the second argument has to resolve as a ticket, and a bare + /// username usually will not, so the call fails on its own. It is silently wrong + /// only when both arguments resolve, which needs a ticket whose title matches the + /// username. + Chown { + /// New owner. Free text, like `add --owner`, checked against nothing + #[arg(value_parser = non_empty)] + user: String, + + /// Ticket UUID or title + ticket: String, + }, + /// Open the board view Tui { /// Projects to monitor, each resolved to the first `.worklane` at or above it. diff --git a/src/handlers.rs b/src/handlers.rs index ddad5e5..8af712d 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -691,6 +691,34 @@ pub fn cmd_set(args: &SetArgs, start: &Path) -> Result<()> { Ok(()) } +/// Rewrite the Owner field, the only writer of it. +/// +/// The user comes first at the call site, after Unix `chown`, and the reasoning for +/// reversing the ticket-first order is on the `Chown` variant. A swapped call is left +/// to resolution: nothing here inspects `user` to see whether it also names a ticket, +/// since the check would only fire on the case resolution already refuses and would +/// stay silent on the one it cannot, a ticket whose title is the username. +/// +/// No-op detection compares the whole file, the way `set` does, so an owner set to the +/// value it already holds is reported unchanged and nothing is written. +pub fn cmd_chown(user: &str, ticket_id: &str, start: &Path) -> Result<()> { + let worklane_dir = find_worklane_dir(start)?; + let (status, title, original) = resolve_ticket(ticket_id, &worklane_dir)?; + let uuid = parse_ticket_field(&original, "ID"); + + let content = set_metadata_field(&original, "Owner", user, &title)?; + + if content == original { + report(&[], &title, "Updated"); + return Ok(()); + } + + save_ticket(&worklane_dir, &status, &uuid, &title, None, &content)?; + + report(&["owner"], &title, "Updated"); + Ok(()) +} + pub fn cmd_append(args: &AppendArgs, start: &Path) -> Result<()> { let worklane_dir = find_worklane_dir(start)?; let (status, title, original) = resolve_ticket(&args.ticket, &worklane_dir)?; diff --git a/src/main.rs b/src/main.rs index b11d19e..ed1f2bc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -59,6 +59,7 @@ fn main() -> Result<()> { }) => cmd_mv(&ticket, &status, force, &start), Some(Command::Set(args)) => cmd_set(&args, &start), Some(Command::Append(args)) => cmd_append(&args, &start), + Some(Command::Chown { user, ticket }) => cmd_chown(&user, &ticket, &start), Some(Command::Check(args)) => cmd_check(&args, true, &start), Some(Command::Uncheck(args)) => cmd_check(&args, false, &start), Some(Command::Comment { diff --git a/tests/cmd_chown.rs b/tests/cmd_chown.rs new file mode 100644 index 0000000..1627df1 --- /dev/null +++ b/tests/cmd_chown.rs @@ -0,0 +1,282 @@ +use assert_cmd::Command; +use assert_fs::TempDir; +use assert_fs::fixture::{PathChild, PathCreateDir}; +use std::fs; +use std::path::{Path, PathBuf}; + +const BIN_NAME: &str = env!("CARGO_BIN_EXE_worklane"); +const UUID: &str = "641e3d5c-1b0e-4d2f-9a7e-3c8b5f0a2d61"; + +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() +} + +/// A fully populated ticket, with one criterion already ticked and a section the tool +/// knows nothing about, so every test can check both survive. +fn create_ticket(worklane: &Path) { + fs::write( + worklane + .join("backlog") + .join(format!("{}_original-title.md", UUID)), + format!( + "# Original title\n\ + \n\ + ## Description\n\ + The **Owner**: line quoted here is prose, not metadata.\n\ + \n\ + ## Acceptance Criteria\n\ + - [x] Crit one\n\ + - [ ] Crit two\n\ + \n\ + ## Implementation Plan\n\ + 1. Step one\n\ + \n\ + ## Notes\n\ + A handwritten note the tool knows nothing about.\n\ + \n\ + ## Metadata\n\ + \n\ + - **ID**: {}\n\ + - **Priority**: 3\n\ + - **Tags**: alpha\n\ + - **Due**: 2026-09-01\n\ + - **Owner**: alice\n\ + - **Created At**: 2026-08-21 02:10:17\n\ + - **Status**: backlog\n", + UUID + ), + ) + .unwrap(); +} + +fn run(temp: &TempDir, args: &[&str]) -> std::process::Output { + let mut cmd = Command::cargo_bin(BIN_NAME).unwrap(); + cmd.current_dir(temp.path()).args(args); + cmd.assert().get_output().clone() +} + +fn ticket(worklane: &Path) -> String { + let entry = fs::read_dir(worklane.join("backlog")) + .unwrap() + .filter_map(|e| e.ok()) + .find(|e| e.file_name().to_string_lossy().ends_with(".md")) + .expect("no ticket file"); + fs::read_to_string(entry.path()).unwrap() +} + +fn stray_files(worklane: &Path) -> Vec { + fs::read_dir(worklane) + .unwrap() + .filter_map(|e| e.ok()) + .map(|e| e.file_name().into_string().unwrap()) + .filter(|name| { + !["backlog", "committed", "reviewing", "done", "comments"].contains(&name.as_str()) + }) + .collect() +} + +#[test] +fn chown_sets_the_owner() { + let temp = TempDir::new().unwrap(); + let worklane = setup_worklane(&temp); + create_ticket(&worklane); + + let out = run(&temp, &["chown", "bob", UUID]); + assert!( + out.status.success(), + "{:?}", + String::from_utf8_lossy(&out.stderr) + ); + assert!( + String::from_utf8_lossy(&out.stdout).contains("owner"), + "{:?}", + String::from_utf8_lossy(&out.stdout) + ); + + let content = ticket(&worklane); + assert!(content.contains("- **Owner**: bob"), "{content}"); + + // Every other field is left as it was + assert!(content.contains("- **Priority**: 3"), "{content}"); + assert!(content.contains("- **Tags**: alpha"), "{content}"); + assert!(content.contains("- **Due**: 2026-09-01"), "{content}"); + assert!(content.contains("- **Status**: backlog"), "{content}"); +} + +/// The value is free text, matching `add --owner`, and is checked against nothing: +/// not git, not a list of users. +#[test] +fn chown_accepts_any_user_without_validating_it() { + let temp = TempDir::new().unwrap(); + let worklane = setup_worklane(&temp); + create_ticket(&worklane); + + run(&temp, &["chown", "Nobody At All", UUID]); + + assert!( + ticket(&worklane).contains("- **Owner**: Nobody At All"), + "{}", + ticket(&worklane) + ); +} + +/// The tick and the unknown section are what a regenerated file would lose, and the +/// quoted `**Owner**:` line in the description is what an unscoped rewrite would take +/// instead of the real field. +#[test] +fn chown_leaves_everything_it_was_not_asked_about_alone() { + let temp = TempDir::new().unwrap(); + let worklane = setup_worklane(&temp); + create_ticket(&worklane); + + run(&temp, &["chown", "bob", UUID]); + + let content = ticket(&worklane); + assert!( + content.contains("- [x] Crit one"), + "the tick was lost: {content}" + ); + assert!( + content.contains("## Notes\nA handwritten note the tool knows nothing about.\n"), + "the unknown section was lost: {content}" + ); + assert!( + content.contains("The **Owner**: line quoted here is prose, not metadata.\n"), + "the prose was rewritten as metadata: {content}" + ); +} + +#[test] +fn chown_reports_no_change_and_leaves_the_file_alone() { + let temp = TempDir::new().unwrap(); + let worklane = setup_worklane(&temp); + create_ticket(&worklane); + let before = ticket(&worklane); + + let out = run(&temp, &["chown", "alice", UUID]); + assert!(out.status.success()); + assert!( + String::from_utf8_lossy(&out.stdout).contains("No changes"), + "{:?}", + String::from_utf8_lossy(&out.stdout) + ); + assert_eq!(ticket(&worklane), before, "the file was rewritten anyway"); +} + +/// Resolution is `resolve_ticket`, the same as `mv` and `comment`, so all three tiers +/// reach the ticket. The filename search reaches the middle of the uuid, which the +/// prefix tier cannot. +#[test] +fn chown_resolves_a_uuid_prefix_a_title_or_a_filename() { + for search in ["641e", "Original", "4d2f"] { + let temp = TempDir::new().unwrap(); + let worklane = setup_worklane(&temp); + create_ticket(&worklane); + + let out = run(&temp, &["chown", "bob", search]); + assert!( + out.status.success(), + "{search} did not resolve: {:?}", + String::from_utf8_lossy(&out.stderr) + ); + assert!( + ticket(&worklane).contains("- **Owner**: bob"), + "{search}: {}", + ticket(&worklane) + ); + } +} + +/// The swap is left to resolution rather than checked for: the username has to resolve +/// as a ticket, and a bare one does not. +#[test] +fn chown_refuses_a_swapped_call() { + let temp = TempDir::new().unwrap(); + let worklane = setup_worklane(&temp); + create_ticket(&worklane); + let before = ticket(&worklane); + + let out = run(&temp, &["chown", UUID, "bob"]); + assert_eq!(out.status.code(), Some(1)); + assert!( + String::from_utf8_lossy(&out.stderr).contains("No ticket found matching 'bob'"), + "{:?}", + String::from_utf8_lossy(&out.stderr) + ); + assert_eq!(ticket(&worklane), before); +} + +/// An empty user looks like a way to clear the field, and clearing is not supported. +#[test] +fn chown_refuses_an_empty_user_as_a_usage_error() { + let temp = TempDir::new().unwrap(); + let worklane = setup_worklane(&temp); + create_ticket(&worklane); + let before = ticket(&worklane); + + let out = run(&temp, &["chown", "", UUID]); + assert_eq!(out.status.code(), Some(2)); + assert!( + String::from_utf8_lossy(&out.stderr).contains("clearing a field is not supported"), + "{:?}", + String::from_utf8_lossy(&out.stderr) + ); + assert_eq!(ticket(&worklane), before); +} + +/// A hand-made ticket without the field is refused rather than guessed at, the same +/// as every other metadata field. +#[test] +fn chown_refuses_a_ticket_with_no_owner_field() { + let temp = TempDir::new().unwrap(); + let worklane = setup_worklane(&temp); + fs::write( + worklane.join("backlog").join(format!("{}_bare.md", UUID)), + format!("# Bare\n\n## Metadata\n\n- **ID**: {}\n", UUID), + ) + .unwrap(); + + let out = run(&temp, &["chown", "bob", UUID]); + assert_eq!(out.status.code(), Some(1)); + assert!( + String::from_utf8_lossy(&out.stderr).contains("has no Owner field"), + "{:?}", + String::from_utf8_lossy(&out.stderr) + ); +} + +/// The staged temp file is renamed into place, so a completed write leaves nothing to +/// be read as a stray ticket. +#[test] +fn chown_leaves_nothing_behind() { + let temp = TempDir::new().unwrap(); + let worklane = setup_worklane(&temp); + create_ticket(&worklane); + + run(&temp, &["chown", "bob", UUID]); + assert_eq!(stray_files(&worklane), Vec::::new()); +} + +/// The file keeps its name: the slug follows the title, and the owner is not in it. +#[test] +fn chown_does_not_rename_the_file() { + let temp = TempDir::new().unwrap(); + let worklane = setup_worklane(&temp); + create_ticket(&worklane); + + run(&temp, &["chown", "bob", UUID]); + + let names: Vec = fs::read_dir(worklane.join("backlog")) + .unwrap() + .filter_map(|e| e.ok()) + .map(|e| e.file_name().into_string().unwrap()) + .collect(); + assert_eq!(names, vec![format!("{}_original-title.md", UUID)]); +}