Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
39ee86e308 |
+42
-15
@@ -38,6 +38,39 @@ async function run(cmd: string[], context: ToolContext): Promise<string> {
|
|||||||
return stdout.trim();
|
return stdout.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description lines as worklane wants them, one --description value per line,
|
||||||
|
* blank ones included.
|
||||||
|
*
|
||||||
|
* cmd_add joins the values with a single newline, so an empty value is how a
|
||||||
|
* paragraph break is spelled. Dropping the blanks here, which is what the old
|
||||||
|
* filter(Boolean) did, collapsed every multi paragraph description into a single
|
||||||
|
* paragraph, against this tool's own instruction to separate paragraphs with
|
||||||
|
* newlines.
|
||||||
|
*
|
||||||
|
* Only the ends are trimmed, and only trailing whitespace within a line. Leading
|
||||||
|
* whitespace is content: it is what makes a nested markdown list or an indented
|
||||||
|
* block survive the trip.
|
||||||
|
*/
|
||||||
|
function descriptionLines(text: string): string[] {
|
||||||
|
const lines = text.split("\n").map((line: string) => line.trimEnd());
|
||||||
|
|
||||||
|
let start = 0;
|
||||||
|
let end = lines.length;
|
||||||
|
while (start < end && lines[start] === "") start++;
|
||||||
|
while (end > start && lines[end - 1] === "") end--;
|
||||||
|
|
||||||
|
return lines.slice(start, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** One value per non-empty line, for the arguments that hold a list of items. */
|
||||||
|
function itemLines(text: string): string[] {
|
||||||
|
return text
|
||||||
|
.split("\n")
|
||||||
|
.map((line: string) => line.trim())
|
||||||
|
.filter(Boolean);
|
||||||
|
}
|
||||||
|
|
||||||
export const init = tool({
|
export const init = tool({
|
||||||
description:
|
description:
|
||||||
"Initialize worklane in the current project. Creates the .worklane/ directory with backlog, committed, reviewing, and done subdirectories.",
|
"Initialize worklane in the current project. Creates the .worklane/ directory with backlog, committed, reviewing, and done subdirectories.",
|
||||||
@@ -87,27 +120,21 @@ export const add = tool({
|
|||||||
}
|
}
|
||||||
const cmd: string[] = ["add", "--title", args.title];
|
const cmd: string[] = ["add", "--title", args.title];
|
||||||
if (args.description) {
|
if (args.description) {
|
||||||
args.description
|
descriptionLines(args.description).forEach((line: string) =>
|
||||||
.split("\n")
|
cmd.push("--description", line),
|
||||||
.map((l: string) => l.trim())
|
);
|
||||||
.filter(Boolean)
|
|
||||||
.forEach((line: string) => cmd.push("--description", line));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Blanks are dropped from these two on purpose: each value is one criterium or
|
||||||
|
// one step, so an empty line between them is spacing rather than content.
|
||||||
if (args.acceptance) {
|
if (args.acceptance) {
|
||||||
args.acceptance
|
itemLines(args.acceptance).forEach((line: string) =>
|
||||||
.split("\n")
|
cmd.push("--acceptance", line),
|
||||||
.map((l: string) => l.trim())
|
);
|
||||||
.filter(Boolean)
|
|
||||||
.forEach((line: string) => cmd.push("--acceptance", line));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.plan) {
|
if (args.plan) {
|
||||||
args.plan
|
itemLines(args.plan).forEach((line: string) => cmd.push("--plan", line));
|
||||||
.split("\n")
|
|
||||||
.map((l: string) => l.trim())
|
|
||||||
.filter(Boolean)
|
|
||||||
.forEach((line: string) => cmd.push("--plan", line));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.tags) cmd.push("--tags", args.tags);
|
if (args.tags) cmd.push("--tags", args.tags);
|
||||||
|
|||||||
@@ -37,6 +37,8 @@
|
|||||||
- The ticket positionals (`show <id>`, `mv <ticket>`, `comment <ticket>`) are also left alone, so a search term starting with a hyphen is a usage error. Reachable now that a hyphen-leading title can be stored: use the UUID, or put the flags first and separate with `--`, as in `mv --status committed -- -leading-title`
|
- The ticket positionals (`show <id>`, `mv <ticket>`, `comment <ticket>`) are also left alone, so a search term starting with a hyphen is a usage error. Reachable now that a hyphen-leading title can be stored: use the UUID, or put the flags first and separate with `--`, as in `mv --status committed -- -leading-title`
|
||||||
- A bare `--` is a value when it follows an option (`--title -- ` stores `--`) and clap's end-of-options marker when it sits in a positional. So a `comment` body of exactly `--` needs its own separator, `comment <ticket> -- --`. Without it the body is reported missing and nothing is written, which is a clear failure rather than a silent drop
|
- A bare `--` is a value when it follows an option (`--title -- ` stores `--`) and clap's end-of-options marker when it sits in a positional. So a `comment` body of exactly `--` needs its own separator, `comment <ticket> -- --`. Without it the body is reported missing and nothing is written, which is a clear failure rather than a silent drop
|
||||||
- `add` has no positionals, so anything after a bare `--` is an unexpected argument and fails
|
- `add` has no positionals, so anything after a bare `--` is an unexpected argument and fails
|
||||||
|
- **A paragraph break in a description is an empty `--description` value.** `cmd_add` joins the values with a single newline, so `-d "First." -d "" -d "Second."` writes the blank line. `trim_blank_ends()` drops blank values at either end, so a break never lands against a section heading, and an all-blank description reads as no description. Interior runs are kept verbatim rather than collapsed
|
||||||
|
- `--acceptance` and `--plan` are lists, one criterium or step per value, so a blank there is spacing rather than content and the opencode wrapper drops it. Only `--description` preserves blanks
|
||||||
|
|
||||||
### Color and Output
|
### Color and Output
|
||||||
- Use `color_text()` helper for colored output — it respects `should_use_colors()` (terminal detection)
|
- Use `color_text()` helper for colored output — it respects `should_use_colors()` (terminal detection)
|
||||||
|
|||||||
Generated
+1
-1
@@ -1029,7 +1029,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "worklane"
|
name = "worklane"
|
||||||
version = "0.4.0"
|
version = "0.4.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"assert_cmd",
|
"assert_cmd",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "worklane"
|
name = "worklane"
|
||||||
version = "0.4.0"
|
version = "0.4.1"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -136,6 +136,9 @@ pub fn cmd_add(
|
|||||||
return Err(anyhow!("A ticket with this title already exists."));
|
return Err(anyhow!("A ticket with this title already exists."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Joined with a single newline, so an empty value is how a caller spells a
|
||||||
|
// paragraph break and an all-blank description is no description at all.
|
||||||
|
let description = trim_blank_ends(description);
|
||||||
let description_text = if description.is_empty() {
|
let description_text = if description.is_empty() {
|
||||||
"_No description provided._".to_string()
|
"_No description provided._".to_string()
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+49
@@ -625,6 +625,27 @@ pub fn format_created_at(created_at: &str) -> String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The slice with blank values trimmed from both ends, interior ones kept.
|
||||||
|
///
|
||||||
|
/// Description values are joined with a single newline, so an empty value is how a
|
||||||
|
/// caller spells a paragraph break. That makes the interior blanks content, while a
|
||||||
|
/// blank at either end would only open or close the section with a gap.
|
||||||
|
pub fn trim_blank_ends(values: &[String]) -> &[String] {
|
||||||
|
let first = values.iter().position(|v| !v.trim().is_empty());
|
||||||
|
|
||||||
|
match first {
|
||||||
|
None => &[],
|
||||||
|
Some(first) => {
|
||||||
|
// Guaranteed to find one, since `first` is itself non-blank.
|
||||||
|
let last = match values.iter().rposition(|v| !v.trim().is_empty()) {
|
||||||
|
Some(last) => last,
|
||||||
|
None => first,
|
||||||
|
};
|
||||||
|
&values[first..=last]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn status_dirs() -> Vec<&'static str> {
|
pub fn status_dirs() -> Vec<&'static str> {
|
||||||
vec!["backlog", "committed", "reviewing", "done"]
|
vec!["backlog", "committed", "reviewing", "done"]
|
||||||
}
|
}
|
||||||
@@ -1115,6 +1136,34 @@ mod tests {
|
|||||||
assert!(rendered.ends_with("after\n"), "{rendered:?}");
|
assert!(rendered.ends_with("after\n"), "{rendered:?}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn blank_values_are_trimmed_from_the_ends_but_kept_inside() {
|
||||||
|
let owned = |values: &[&str]| -> Vec<String> {
|
||||||
|
values.iter().map(|v| v.to_string()).collect()
|
||||||
|
};
|
||||||
|
|
||||||
|
// A break between paragraphs is content
|
||||||
|
let two_paragraphs = owned(&["First.", "", "Second."]);
|
||||||
|
assert_eq!(trim_blank_ends(&two_paragraphs), two_paragraphs.as_slice());
|
||||||
|
|
||||||
|
// A run of them is kept verbatim rather than collapsed
|
||||||
|
let wide = owned(&["A", "", "", "B"]);
|
||||||
|
assert_eq!(trim_blank_ends(&wide), wide.as_slice());
|
||||||
|
|
||||||
|
// The ends are not
|
||||||
|
assert_eq!(
|
||||||
|
trim_blank_ends(&owned(&["", " ", "Only.", "", ""])),
|
||||||
|
owned(&["Only."]).as_slice()
|
||||||
|
);
|
||||||
|
|
||||||
|
// Nothing but blanks is nothing at all
|
||||||
|
assert!(trim_blank_ends(&owned(&["", " ", ""])).is_empty());
|
||||||
|
assert!(trim_blank_ends(&[]).is_empty());
|
||||||
|
|
||||||
|
// A single value survives either way
|
||||||
|
assert_eq!(trim_blank_ends(&owned(&["One."])), owned(&["One."]).as_slice());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn a_level_in_range_parses() {
|
fn a_level_in_range_parses() {
|
||||||
for level in 1..=5u8 {
|
for level in 1..=5u8 {
|
||||||
|
|||||||
@@ -380,3 +380,80 @@ fn only_ticket(worklane: &PathBuf) -> String {
|
|||||||
assert_eq!(files.len(), 1, "expected exactly one ticket");
|
assert_eq!(files.len(), 1, "expected exactly one ticket");
|
||||||
fs::read_to_string(files[0].path()).unwrap()
|
fs::read_to_string(files[0].path()).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The contract the opencode wrapper relies on: values are joined with a single
|
||||||
|
/// newline, so an empty value is how a paragraph break is spelled. The wrapper used
|
||||||
|
/// to drop those blanks, collapsing every multi paragraph description into one.
|
||||||
|
#[test]
|
||||||
|
fn add_keeps_a_paragraph_break_in_the_description() {
|
||||||
|
let temp = TempDir::new().unwrap();
|
||||||
|
let worklane = setup_worklane(&temp);
|
||||||
|
|
||||||
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
||||||
|
cmd.current_dir(&temp.path())
|
||||||
|
.args(["add", "--title", "Two Paras"])
|
||||||
|
.args(["--description", "First paragraph."])
|
||||||
|
.args(["--description", ""])
|
||||||
|
.args(["--description", "Second paragraph."])
|
||||||
|
.assert()
|
||||||
|
.success();
|
||||||
|
|
||||||
|
let content = only_ticket(&worklane);
|
||||||
|
assert!(
|
||||||
|
content.contains("## Description\nFirst paragraph.\n\nSecond paragraph.\n"),
|
||||||
|
"was {content:?}"
|
||||||
|
);
|
||||||
|
|
||||||
|
// And it survives the round trip back out
|
||||||
|
let mut show = Command::cargo_bin(BIN_NAME).unwrap();
|
||||||
|
show.current_dir(&temp.path()).args(["show", "Two Paras"]);
|
||||||
|
let stdout = String::from_utf8(show.assert().success().get_output().stdout.clone()).unwrap();
|
||||||
|
assert!(
|
||||||
|
stdout.contains("First paragraph.\n\nSecond paragraph."),
|
||||||
|
"was {stdout:?}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A break belongs between paragraphs, not against the section headings.
|
||||||
|
#[test]
|
||||||
|
fn add_discards_blank_descriptions_at_either_end() {
|
||||||
|
let temp = TempDir::new().unwrap();
|
||||||
|
let worklane = setup_worklane(&temp);
|
||||||
|
|
||||||
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
||||||
|
cmd.current_dir(&temp.path())
|
||||||
|
.args(["add", "--title", "Padded"])
|
||||||
|
.args(["--description", ""])
|
||||||
|
.args(["--description", " "])
|
||||||
|
.args(["--description", "The only line."])
|
||||||
|
.args(["--description", ""])
|
||||||
|
.assert()
|
||||||
|
.success();
|
||||||
|
|
||||||
|
let content = only_ticket(&worklane);
|
||||||
|
assert!(
|
||||||
|
content.contains("## Description\nThe only line.\n\n## Acceptance Criteria"),
|
||||||
|
"was {content:?}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Nothing but blanks is no description, not an empty section.
|
||||||
|
#[test]
|
||||||
|
fn add_treats_an_all_blank_description_as_none() {
|
||||||
|
let temp = TempDir::new().unwrap();
|
||||||
|
let worklane = setup_worklane(&temp);
|
||||||
|
|
||||||
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
||||||
|
cmd.current_dir(&temp.path())
|
||||||
|
.args(["add", "--title", "Blank"])
|
||||||
|
.args(["--description", ""])
|
||||||
|
.args(["--description", " "])
|
||||||
|
.assert()
|
||||||
|
.success();
|
||||||
|
|
||||||
|
let content = only_ticket(&worklane);
|
||||||
|
assert!(
|
||||||
|
content.contains("## Description\n_No description provided._"),
|
||||||
|
"was {content:?}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user