Compare commits

...
1 Commits
Author SHA1 Message Date
Ansho ReiandClaude Opus 5 39ee86e308 (4c516e6) Preserve paragraph breaks in ticket descriptions, and bump to 0.4.1
The opencode add tool split the description on newlines and then dropped the
empty ones with filter(Boolean), so every multi paragraph description arrived as
a single paragraph, against the tool's own instruction to separate paragraphs
with newlines.

cmd_add needed no change for this. Joining the values with a single newline is
what makes an empty value a paragraph break, so the capability was already
there and only the wrapper was throwing it away. Verified by hand before
touching anything.

The wrapper now keeps interior blanks and trims only the ends, and only trims
trailing whitespace within a line, since leading whitespace is what makes a
nested list or an indented block survive. --acceptance and --plan keep dropping
blanks: each value there is one criterium or step, so an empty line is spacing.

trim_blank_ends in cmd_add makes the second criterion hold whoever calls it, not
just the wrapper: blank values at either end are dropped so a break never lands
against a section heading, and an all-blank description reads as none. Interior
runs are kept verbatim rather than collapsed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-21 00:29:22 +02:00
7 changed files with 175 additions and 17 deletions
+42 -15
View File
@@ -38,6 +38,39 @@ async function run(cmd: string[], context: ToolContext): Promise<string> {
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({
description:
"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];
if (args.description) {
args.description
.split("\n")
.map((l: string) => l.trim())
.filter(Boolean)
.forEach((line: string) => cmd.push("--description", line));
descriptionLines(args.description).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) {
args.acceptance
.split("\n")
.map((l: string) => l.trim())
.filter(Boolean)
.forEach((line: string) => cmd.push("--acceptance", line));
itemLines(args.acceptance).forEach((line: string) =>
cmd.push("--acceptance", line),
);
}
if (args.plan) {
args.plan
.split("\n")
.map((l: string) => l.trim())
.filter(Boolean)
.forEach((line: string) => cmd.push("--plan", line));
itemLines(args.plan).forEach((line: string) => cmd.push("--plan", line));
}
if (args.tags) cmd.push("--tags", args.tags);
+2
View File
@@ -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`
- 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
- **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
- Use `color_text()` helper for colored output — it respects `should_use_colors()` (terminal detection)
Generated
+1 -1
View File
@@ -1029,7 +1029,7 @@ dependencies = [
[[package]]
name = "worklane"
version = "0.4.0"
version = "0.4.1"
dependencies = [
"anyhow",
"assert_cmd",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "worklane"
version = "0.4.0"
version = "0.4.1"
edition = "2024"
[dependencies]
+3
View File
@@ -136,6 +136,9 @@ pub fn cmd_add(
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() {
"_No description provided._".to_string()
} else {
+49
View File
@@ -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> {
vec!["backlog", "committed", "reviewing", "done"]
}
@@ -1115,6 +1136,34 @@ mod tests {
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]
fn a_level_in_range_parses() {
for level in 1..=5u8 {
+77
View File
@@ -380,3 +380,80 @@ fn only_ticket(worklane: &PathBuf) -> String {
assert_eq!(files.len(), 1, "expected exactly one ticket");
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:?}"
);
}