(415e1c3) Fix worklane.ts tool when passed multi-line args
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
import { tool } from "@opencode-ai/plugin"
|
||||
import path from "path"
|
||||
|
||||
function resolveWorklaneDir(context: Parameters<(typeof tool)['prototype'].execute>[1]) {
|
||||
return path.join(context.worktree || context.directory || ".", ".worklane")
|
||||
}
|
||||
|
||||
export const init = tool({
|
||||
description: "Initialize worklane in the current project. Creates the .worklane/ directory with backlog, committed, reviewing, and done subdirectories.",
|
||||
args: {},
|
||||
async execute() {
|
||||
try {
|
||||
const result = await Bun.$`worklane init`.text()
|
||||
return result.trim()
|
||||
} catch (err: any) {
|
||||
return `Error initializing worklane: ${err.message}`
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
export const add = tool({
|
||||
description: "Add a new ticket to the worklane backlog. Supports title, description, acceptance criteria, implementation plan, tags, due date, and owner.",
|
||||
args: {
|
||||
title: tool.schema.string().describe("Ticket title (required)"),
|
||||
description: tool.schema.string().describe("Ticket description"),
|
||||
acceptance: tool.schema.string().describe("Acceptance criteria as comma-separated list"),
|
||||
plan: tool.schema.string().describe("Implementation plan as comma-separated steps"),
|
||||
tags: tool.schema.string().describe("Tags as comma-separated list"),
|
||||
due: tool.schema.string().describe("Due date in YYYY-MM-DD format"),
|
||||
owner: tool.schema.string().describe("Owner name"),
|
||||
},
|
||||
async execute(args) {
|
||||
const cmd: string[] = ["add", "--title", args.title]
|
||||
if (args.description) {
|
||||
args.description
|
||||
.split("\n")
|
||||
.map((l) => l.trim())
|
||||
.filter(Boolean)
|
||||
.forEach((line) => cmd.push("--description", line))
|
||||
}
|
||||
|
||||
if (args.acceptance) {
|
||||
args.acceptance
|
||||
.split("\n")
|
||||
.map((l) => l.trim())
|
||||
.filter(Boolean)
|
||||
.forEach((line) => cmd.push("--acceptance", line))
|
||||
}
|
||||
|
||||
if (args.plan) {
|
||||
args.plan
|
||||
.split("\n")
|
||||
.map((l) => l.trim())
|
||||
.filter(Boolean)
|
||||
.forEach((line) => cmd.push("--plan", line))
|
||||
}
|
||||
|
||||
if (args.tags) cmd.push("--tags", args.tags)
|
||||
if (args.due) cmd.push("--due", args.due)
|
||||
if (args.owner) cmd.push("--owner", args.owner)
|
||||
|
||||
try {
|
||||
const result = await Bun.$`worklane ${cmd}`.text()
|
||||
return result.trim()
|
||||
} catch (err: any) {
|
||||
return `Error adding ticket: ${err.message}`
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
export const ls = tool({
|
||||
description: "List all worklane tickets. Optionally filter by status (backlog, committed, reviewing, done).",
|
||||
args: {
|
||||
status: tool.schema.enum(["backlog", "committed", "reviewing", "done"]).describe("Filter by status").optional(),
|
||||
},
|
||||
async execute(args) {
|
||||
try {
|
||||
const cmd = args.status ? `worklane ls --status ${args.status}` : "worklane ls"
|
||||
const result = await Bun.$`${cmd}`.text()
|
||||
return result.trim()
|
||||
} catch (err: any) {
|
||||
return `Error listing tickets: ${err.message}`
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
export const show = tool({
|
||||
description: "Show a complete ticket by UUID or title. Displays title, description, acceptance criteria, implementation plan, metadata, and comments.",
|
||||
args: {
|
||||
id: tool.schema.string().describe("Ticket UUID (8+ chars) or title substring"),
|
||||
},
|
||||
async execute(args) {
|
||||
try {
|
||||
const result = await Bun.$`worklane show ${args.id}`.text()
|
||||
return result.trim()
|
||||
} catch (err: any) {
|
||||
return `Error showing ticket: ${err.message}`
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
export const mv = tool({
|
||||
description: "Move a ticket to a different status in the workflow (backlog -> committed -> reviewing -> done).",
|
||||
args: {
|
||||
ticket: tool.schema.string().describe("Ticket UUID (8+ chars) or title substring"),
|
||||
status: tool.schema.enum(["backlog", "committed", "reviewing", "done"]).describe("Target status"),
|
||||
force: tool.schema.boolean().describe("Force move (allows non-sequential moves like done -> backlog)").optional(),
|
||||
},
|
||||
async execute(args) {
|
||||
try {
|
||||
const cmd = args.force ? `worklane mv ${args.ticket} --status ${args.status} --force` : `worklane mv ${args.ticket} --status ${args.status}`
|
||||
const result = await Bun.$`${cmd}`.text()
|
||||
return result.trim()
|
||||
} catch (err: any) {
|
||||
return `Error moving ticket: ${err.message}`
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
export const comment = tool({
|
||||
description: "Add a comment to an existing ticket.",
|
||||
args: {
|
||||
ticket: tool.schema.string().describe("Ticket UUID (8+ chars) or title substring"),
|
||||
body: tool.schema.string().describe("Comment body (required)"),
|
||||
owner: tool.schema.string().describe("Comment author").optional(),
|
||||
},
|
||||
async execute(args) {
|
||||
try {
|
||||
const cmd = args.owner
|
||||
? `worklane comment ${args.ticket} --owner ${args.owner} "${args.body}"`
|
||||
: `worklane comment ${args.ticket} "${args.body}"`
|
||||
const result = await Bun.$`${cmd}`.text()
|
||||
return result.trim()
|
||||
} catch (err: any) {
|
||||
return `Error adding comment: ${err.message}`
|
||||
}
|
||||
},
|
||||
})
|
||||
+1
-1
@@ -21,7 +21,7 @@ pub enum Command {
|
||||
|
||||
/// Ticket description
|
||||
#[arg(short, long)]
|
||||
description: Option<String>,
|
||||
description: Vec<String>,
|
||||
|
||||
/// Acceptance criteria (comma-separated)
|
||||
#[arg(short, long)]
|
||||
|
||||
+6
-4
@@ -89,7 +89,7 @@ pub fn cmd_ls(status_filter: &Option<String>, worklane_dir: &Path) -> Result<()>
|
||||
|
||||
pub fn cmd_add(
|
||||
title: &str,
|
||||
description: &Option<String>,
|
||||
description: &[String],
|
||||
acceptance: &[String],
|
||||
plan: &[String],
|
||||
tags: &[String],
|
||||
@@ -119,9 +119,11 @@ pub fn cmd_add(
|
||||
return Err(anyhow!("A ticket with this title already exists."));
|
||||
}
|
||||
|
||||
let description_text = description
|
||||
.as_deref()
|
||||
.unwrap_or("_No description provided._");
|
||||
let description_text = if description.is_empty() {
|
||||
"_No description provided._".to_string()
|
||||
} else {
|
||||
description.join("\n")
|
||||
};
|
||||
|
||||
let mut body = format!(
|
||||
"# {}\n\
|
||||
|
||||
@@ -97,6 +97,35 @@ fn add_formats_ticket_correctly() {
|
||||
assert!(content.contains("backlog"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_joins_multiple_descriptions() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
setup_worklane(&temp);
|
||||
|
||||
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
||||
cmd.current_dir(&temp.path())
|
||||
.args([
|
||||
"add",
|
||||
"--title", "Multi desc ticket",
|
||||
"--description", "Line one",
|
||||
"--description", "Line two",
|
||||
])
|
||||
.assert()
|
||||
.success();
|
||||
|
||||
let files: Vec<_> = fs::read_dir(temp.child(".worklane").join("backlog"))
|
||||
.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("Line one"));
|
||||
assert!(content.contains("Line two"));
|
||||
assert!(content.contains("\n"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_with_optional_fields_uses_defaults() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
|
||||
Reference in New Issue
Block a user