(177665) Add ls command
This commit is contained in:
@@ -4,8 +4,8 @@ name: worklane_kanban
|
|||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
description: >
|
description: >
|
||||||
Creates Kanban-style tickets in Worklane using the `worklane add` CLI command.
|
Creates Kanban-style tickets in Worklane using the `worklane add` CLI command.
|
||||||
Supports title, description, acceptance criteria, implementation plan, tags,
|
Supports listing tickets with `worklane ls`. Both commands support title, description,
|
||||||
due date, and owner assignment.
|
acceptance criteria, implementation plan, tags, due date, owner assignment, and status filtering.
|
||||||
rendering:
|
rendering:
|
||||||
strategy: cli_args
|
strategy: cli_args
|
||||||
join_arrays_with: ","
|
join_arrays_with: ","
|
||||||
@@ -21,45 +21,49 @@ parameters:
|
|||||||
type: string
|
type: string
|
||||||
required: true
|
required: true
|
||||||
cli_flag: "--title"
|
cli_flag: "--title"
|
||||||
|
|
||||||
description:
|
description:
|
||||||
type: string
|
type: string
|
||||||
required: false
|
required: false
|
||||||
cli_flag: "--description"
|
cli_flag: "--description"
|
||||||
|
|
||||||
acceptance:
|
acceptance:
|
||||||
type: array
|
type: array
|
||||||
required: false
|
required: false
|
||||||
description: "List of acceptance criteria"
|
description: "List of acceptance criteria"
|
||||||
cli_flag: "--acceptance"
|
cli_flag: "--acceptance"
|
||||||
format: csv
|
format: csv
|
||||||
|
|
||||||
plan:
|
plan:
|
||||||
type: array
|
type: array
|
||||||
required: false
|
required: false
|
||||||
description: "Step-by-step implementation plan"
|
description: "Step-by-step implementation plan"
|
||||||
cli_flag: "--plan"
|
cli_flag: "--plan"
|
||||||
format: csv
|
format: csv
|
||||||
|
|
||||||
tags:
|
tags:
|
||||||
type: array
|
type: array
|
||||||
required: false
|
required: false
|
||||||
cli_flag: "--tags"
|
cli_flag: "--tags"
|
||||||
format: csv
|
format: csv
|
||||||
|
|
||||||
due:
|
due:
|
||||||
type: string
|
type: string
|
||||||
required: false
|
required: false
|
||||||
description: "Due date in YYYY-MM-DD format"
|
description: "Due date in YYYY-MM-DD format"
|
||||||
cli_flag: "--due"
|
cli_flag: "--due"
|
||||||
|
|
||||||
owner:
|
owner:
|
||||||
type: string
|
type: string
|
||||||
required: false
|
required: false
|
||||||
cli_flag: "--owner"
|
cli_flag: "--owner"
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
command: worklane ls
|
||||||
|
parameters:
|
||||||
|
status:
|
||||||
|
type: string
|
||||||
|
required: false
|
||||||
|
description: "Filter by status (backlog, committed, reviewing, done)"
|
||||||
|
cli_flag: "--status"
|
||||||
```
|
```
|
||||||
|
|
||||||
Example:
|
Example adding a ticket:
|
||||||
```yaml
|
```yaml
|
||||||
input:
|
input:
|
||||||
title: "Implement login API"
|
title: "Implement login API"
|
||||||
@@ -81,7 +85,22 @@ output: >
|
|||||||
--plan "Create auth controller,Add JWT middleware,Write tests"
|
--plan "Create auth controller,Add JWT middleware,Write tests"
|
||||||
--tags "backend,auth"
|
--tags "backend,auth"
|
||||||
--due "2026-06-01"
|
--due "2026-06-01"
|
||||||
--owner "alice"
|
--owner "alice"
|
||||||
|
```
|
||||||
|
|
||||||
|
Example listing tickets:
|
||||||
|
```yaml
|
||||||
|
input:
|
||||||
|
status: "backlog"
|
||||||
|
output: >
|
||||||
|
worklane ls --status backlog
|
||||||
|
```
|
||||||
|
|
||||||
|
Example listing all tickets (no filter):
|
||||||
|
```yaml
|
||||||
|
input: {}
|
||||||
|
output: >
|
||||||
|
worklane ls
|
||||||
```
|
```
|
||||||
|
|
||||||
## Agent Guidance (IMPORTANT — read before generating tickets)
|
## Agent Guidance (IMPORTANT — read before generating tickets)
|
||||||
@@ -143,3 +162,20 @@ When creating a Worklane ticket, the agent MUST:
|
|||||||
* Do not repeat information across fields
|
* Do not repeat information across fields
|
||||||
* Ensure consistency between description, acceptance criteria, and plan
|
* Ensure consistency between description, acceptance criteria, and plan
|
||||||
* If unsure, choose simpler and more testable phrasing
|
* If unsure, choose simpler and more testable phrasing
|
||||||
|
|
||||||
|
## Using `worklane ls`
|
||||||
|
|
||||||
|
The `worklane ls` command lists tickets. Use it to check the state of tickets:
|
||||||
|
|
||||||
|
* `worklane ls` — lists all tickets grouped by status without filtering
|
||||||
|
* `worklane ls --status <STATUS>` — filters tickets by status
|
||||||
|
|
||||||
|
Valid statuses: `backlog`, `committed`, `reviewing`, `done`
|
||||||
|
|
||||||
|
### Usage patterns
|
||||||
|
|
||||||
|
When checking ticket status or filtering work, use `worklane ls` rather than reading from file paths directly. This ensures consistent access to ticket data.
|
||||||
|
|
||||||
|
Example patterns:
|
||||||
|
* Check backlog items: `worklane ls --status backlog`
|
||||||
|
* View all tickets: `worklane ls`
|
||||||
|
|||||||
@@ -44,4 +44,11 @@ pub enum Command {
|
|||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
owner: Option<String>,
|
owner: Option<String>,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/// List tickets, optionally filtered by status
|
||||||
|
Ls {
|
||||||
|
/// Filter by status (backlog, committed, reviewing, done)
|
||||||
|
#[arg(long)]
|
||||||
|
status: Option<String>,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
+113
@@ -55,6 +55,115 @@ fn cmd_init(start: &Path) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn parse_ticket_field(content: &str, field: &str) -> String {
|
||||||
|
let pattern = format!("**{}**", field);
|
||||||
|
content
|
||||||
|
.lines()
|
||||||
|
.find(|line| line.contains(&pattern))
|
||||||
|
.map(|line| {
|
||||||
|
line.split(':').nth(1).unwrap_or("").trim().trim_matches('_').trim()
|
||||||
|
})
|
||||||
|
.unwrap_or("_Not set_")
|
||||||
|
.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn status_dirs() -> Vec<&'static str> {
|
||||||
|
vec!["backlog", "committed", "reviewing", "done"]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn cmd_ls(status_filter: &Option<String>, worklane_dir: &Path) -> Result<()> {
|
||||||
|
if let Some(status) = status_filter {
|
||||||
|
let status_path = worklane_dir.join(status);
|
||||||
|
if !status_path.exists() {
|
||||||
|
return Err(anyhow!(
|
||||||
|
"Status '{}' not found. Valid statuses: backlog, committed, reviewing, done",
|
||||||
|
status
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
let entries: Vec<_> = fs::read_dir(&status_path)?
|
||||||
|
.filter_map(|e| e.ok())
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
if entries.is_empty() {
|
||||||
|
println!("No tickets in '{}' status.", status);
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut items: Vec<_> = entries
|
||||||
|
.iter()
|
||||||
|
.filter_map(|e| {
|
||||||
|
let content = fs::read_to_string(e.path()).ok()?;
|
||||||
|
let title = content
|
||||||
|
.lines()
|
||||||
|
.find(|l| l.starts_with("# "))
|
||||||
|
.map(|l| l[2..].trim())
|
||||||
|
.unwrap_or("_No title_")
|
||||||
|
.to_string();
|
||||||
|
let owner = parse_ticket_field(&content, "Owner");
|
||||||
|
let due = parse_ticket_field(&content, "Due");
|
||||||
|
|
||||||
|
Some((title, owner, due))
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
items.sort_by(|a, b| a.0.to_lowercase().cmp(&b.0.to_lowercase()));
|
||||||
|
|
||||||
|
println!("Tickets in '{}' status:\n", status);
|
||||||
|
for (title, owner, due) in items {
|
||||||
|
println!(" {} | Owner: {} | Due: {}", title, owner, due);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// List all statuses with their ticket counts
|
||||||
|
let statuses = status_dirs();
|
||||||
|
println!("Tickets by status:\n");
|
||||||
|
for status in &statuses {
|
||||||
|
let status_path = worklane_dir.join(status);
|
||||||
|
if !status_path.exists() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let entries: Vec<_> = fs::read_dir(&status_path)?.filter_map(|e| e.ok()).collect();
|
||||||
|
let count = entries.len();
|
||||||
|
let label = if count == 1 { "ticket" } else { "tickets" };
|
||||||
|
println!(" [{}] {} {}", status.to_uppercase(), count, label);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show all tickets grouped by status
|
||||||
|
for status in &statuses {
|
||||||
|
let status_path = worklane_dir.join(status);
|
||||||
|
if !status_path.exists() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let entries: Vec<_> = fs::read_dir(&status_path)?.filter_map(|e| e.ok()).collect();
|
||||||
|
if entries.is_empty() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let mut items: Vec<_> = entries
|
||||||
|
.iter()
|
||||||
|
.filter_map(|e| {
|
||||||
|
let content = fs::read_to_string(e.path()).ok()?;
|
||||||
|
let title = content
|
||||||
|
.lines()
|
||||||
|
.find(|l| l.starts_with("# "))
|
||||||
|
.map(|l| l[2..].trim())
|
||||||
|
.unwrap_or("_No title_")
|
||||||
|
.to_string();
|
||||||
|
let owner = parse_ticket_field(&content, "Owner");
|
||||||
|
let due = parse_ticket_field(&content, "Due");
|
||||||
|
Some((title, owner, due))
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
items.sort_by(|a, b| a.0.to_lowercase().cmp(&b.0.to_lowercase()));
|
||||||
|
println!("\n[{}]", status.to_uppercase());
|
||||||
|
for (title, owner, due) in items {
|
||||||
|
println!(" {} | Owner: {} | Due: {}", title, owner, due);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn cmd_add(
|
fn cmd_add(
|
||||||
title: &str,
|
title: &str,
|
||||||
description: &Option<String>,
|
description: &Option<String>,
|
||||||
@@ -162,5 +271,9 @@ fn main() -> Result<()> {
|
|||||||
} => cmd_add(
|
} => cmd_add(
|
||||||
&title, &description, &acceptance, &plan, &tags, &due, &owner, &start,
|
&title, &description, &acceptance, &plan, &tags, &due, &owner, &start,
|
||||||
),
|
),
|
||||||
|
Command::Ls { status } => {
|
||||||
|
let worklane_dir = find_worklane_dir(&start)?;
|
||||||
|
cmd_ls(&status, &worklane_dir)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+177
@@ -0,0 +1,177 @@
|
|||||||
|
use assert_cmd::Command;
|
||||||
|
use assert_fs::TempDir;
|
||||||
|
use assert_fs::fixture::{PathChild, PathCreateDir};
|
||||||
|
use std::fs;
|
||||||
|
|
||||||
|
const BIN_NAME: &str = env!("CARGO_BIN_EXE_worklane");
|
||||||
|
|
||||||
|
fn setup_worklane(temp: &TempDir) -> std::path::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: &std::path::PathBuf,
|
||||||
|
status: &str,
|
||||||
|
title: &str,
|
||||||
|
owner: &str,
|
||||||
|
due: &str,
|
||||||
|
) {
|
||||||
|
let ticket_body = format!(
|
||||||
|
"# {}\n\
|
||||||
|
\n\
|
||||||
|
## Description\n\
|
||||||
|
test desc\n\
|
||||||
|
\n\
|
||||||
|
## Acceptance Criteria\n\
|
||||||
|
- [ ] test\n\
|
||||||
|
\n\
|
||||||
|
## Implementation Plan\n\
|
||||||
|
- test\n\
|
||||||
|
\n\
|
||||||
|
## Metadata\n\
|
||||||
|
\n\
|
||||||
|
- **ID**: 00000000-0000-0000-0000-000000000001\n\
|
||||||
|
- **Tags**: test\n\
|
||||||
|
- **Due**: {}\n\
|
||||||
|
- **Owner**: {}\n\
|
||||||
|
- **Status**: {}\n\
|
||||||
|
",
|
||||||
|
title, due, owner, status
|
||||||
|
);
|
||||||
|
let slug = title
|
||||||
|
.to_lowercase()
|
||||||
|
.chars()
|
||||||
|
.filter(|c| c.is_alphanumeric() || *c == ' ' || *c == '-' || *c == '_')
|
||||||
|
.map(|c| if c == ' ' { '-' } else { c })
|
||||||
|
.collect::<String>();
|
||||||
|
let filename = format!("00000000-0000-0000-0000-000000000001_{}.md", slug);
|
||||||
|
fs::write(worklane_dir.join(status).join(&filename), ticket_body).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_stdout(cmd: &mut Command) -> String {
|
||||||
|
let assert = cmd.assert();
|
||||||
|
String::from_utf8(assert.get_output().stdout.clone()).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ls_without_status_shows_overview() {
|
||||||
|
let temp = TempDir::new().unwrap();
|
||||||
|
let worklane = setup_worklane(&temp);
|
||||||
|
|
||||||
|
create_ticket(&worklane, "backlog", "Feature A", "alice", "2026-06-01");
|
||||||
|
create_ticket(&worklane, "backlog", "Feature B", "bob", "2026-07-01");
|
||||||
|
create_ticket(&worklane, "committed", "Feature C", "charlie", "2026-08-01");
|
||||||
|
create_ticket(&worklane, "done", "Feature D", "dave", "2026-09-01");
|
||||||
|
|
||||||
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
||||||
|
cmd.current_dir(&temp.path()).arg("ls").assert().success();
|
||||||
|
|
||||||
|
let stdout = get_stdout(&mut cmd);
|
||||||
|
assert!(stdout.contains("BACKLOG"));
|
||||||
|
assert!(stdout.contains("2 tickets"));
|
||||||
|
assert!(stdout.contains("COMMITTED"));
|
||||||
|
assert!(stdout.contains("1 ticket"));
|
||||||
|
assert!(stdout.contains("DONE"));
|
||||||
|
assert!(stdout.contains("Feature A"));
|
||||||
|
assert!(stdout.contains("Feature B"));
|
||||||
|
assert!(stdout.contains("Feature C"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ls_with_status_filters_tickets() {
|
||||||
|
let temp = TempDir::new().unwrap();
|
||||||
|
let worklane = setup_worklane(&temp);
|
||||||
|
|
||||||
|
create_ticket(&worklane, "backlog", "Feature A", "alice", "2026-06-01");
|
||||||
|
create_ticket(&worklane, "committed", "Feature B", "bob", "2026-07-01");
|
||||||
|
create_ticket(&worklane, "reviewing", "Feature C", "charlie", "2026-08-01");
|
||||||
|
|
||||||
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
||||||
|
cmd.current_dir(&temp.path())
|
||||||
|
.arg("ls")
|
||||||
|
.args(["--status", "committed"]);
|
||||||
|
|
||||||
|
cmd.assert().success();
|
||||||
|
|
||||||
|
let stdout = get_stdout(&mut cmd);
|
||||||
|
assert!(stdout.contains("Feature B"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ls_with_invalid_status_fails() {
|
||||||
|
let temp = TempDir::new().unwrap();
|
||||||
|
|
||||||
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
||||||
|
cmd.current_dir(&temp.path())
|
||||||
|
.arg("ls")
|
||||||
|
.args(["--status", "nonexistent"])
|
||||||
|
.assert()
|
||||||
|
.failure();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ls_listed_tickets_sorted_alphabetically() {
|
||||||
|
let temp = TempDir::new().unwrap();
|
||||||
|
let worklane = setup_worklane(&temp);
|
||||||
|
|
||||||
|
create_ticket(&worklane, "backlog", "Zebra", "alice", "2026-06-01");
|
||||||
|
create_ticket(&worklane, "backlog", "Apple", "bob", "2026-07-01");
|
||||||
|
create_ticket(&worklane, "backlog", "Mango", "charlie", "2026-08-01");
|
||||||
|
|
||||||
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
||||||
|
cmd.current_dir(&temp.path())
|
||||||
|
.arg("ls")
|
||||||
|
.args(["--status", "backlog"])
|
||||||
|
.assert()
|
||||||
|
.success();
|
||||||
|
|
||||||
|
let stdout = get_stdout(&mut cmd);
|
||||||
|
let apple_pos = stdout.find("Apple");
|
||||||
|
let mango_pos = stdout.find("Mango");
|
||||||
|
let zebra_pos = stdout.find("Zebra");
|
||||||
|
assert!(apple_pos.is_some() && mango_pos.is_some() && zebra_pos.is_some());
|
||||||
|
assert!(apple_pos.unwrap() < mango_pos.unwrap());
|
||||||
|
assert!(mango_pos.unwrap() < zebra_pos.unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ls_empty_status_shows_message() {
|
||||||
|
let temp = TempDir::new().unwrap();
|
||||||
|
|
||||||
|
// Intentionally leave "done" empty
|
||||||
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
||||||
|
cmd.current_dir(&temp.path())
|
||||||
|
.arg("ls")
|
||||||
|
.args(["--status", "done"])
|
||||||
|
.assert()
|
||||||
|
.success();
|
||||||
|
|
||||||
|
let stdout = get_stdout(&mut cmd);
|
||||||
|
assert!(stdout.contains("No tickets in 'done'"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ls_displays_owner_and_due() {
|
||||||
|
let temp = TempDir::new().unwrap();
|
||||||
|
let worklane = setup_worklane(&temp);
|
||||||
|
|
||||||
|
create_ticket(&worklane, "backlog", "Test ticket", "alice", "2026-12-31");
|
||||||
|
|
||||||
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
||||||
|
cmd.current_dir(&temp.path())
|
||||||
|
.arg("ls")
|
||||||
|
.args(["--status", "backlog"])
|
||||||
|
.assert()
|
||||||
|
.success();
|
||||||
|
|
||||||
|
let stdout = get_stdout(&mut cmd);
|
||||||
|
assert!(stdout.contains("alice"));
|
||||||
|
assert!(stdout.contains("2026-12-31"));
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user