Compare commits

...
7 Commits
13 changed files with 932 additions and 179 deletions
+10 -5
View File
@@ -270,7 +270,7 @@ and this file is for what someone changing worklane's own code needs.
- **`Card::campaign` is a resolved `Cell`, not a uuid**, settled at reload the way `project` and `blocked` are. `TicketItem::campaign` already carries the uuid off the pass that builds the card; the name is in another directory, so `columns_of` reads `CampaignIndex` once per project and hands it to every card. Never per draw, the rule `criteria` and `tags` already hold. The merge carries the resolved cell rather than looking it up again, for the reason it carries `blocked`: a campaign is addressed inside one `.worklane`, so a merged lookup could answer one project's uuid with another project's campaign
- **A campaign the board does not hold labels nothing**, the answer `mark_blocked` gives a dangling blocker. `campaign_cells` renders that case as `_missing_` because a metadata table is a place to report a dangling reference; a card is not
- **`c` opens the campaign picker, and taking a campaign filters the tab's columns to its members.** Not a fifth tab: a campaign groups across the flow, so the shape of the answer is the statuses with fewer cards in them, which is what `campaign show` already answers the question in. Every column is kept, empty ones included. The filter is applied in `reload`, where the columns are built, so nothing downstream has to ask whether a campaign is selected — the board simply holds fewer cards, and `first_match`, `column_count` and the copy key all keep working unchanged
- **`Tab::campaign` is a uuid on the tab, not on the `Board`.** A campaign belongs to one `.worklane`, so a filter carried onto another project's tab would empty it and say nothing about why. It is looked up by uuid rather than held as an index, and a selection whose campaign has left the board is cleared by `reload` rather than left filtering the board to nothing
- **A campaign filter is a uuid on the tab, not on the `Board`.** `Tab::filter` is a `Filter`, and a campaign belongs to one `.worklane`, so a filter carried onto another project's tab would empty it and say nothing about why. It is looked up by uuid rather than held as an index, and a selection whose campaign has left the board is cleared by `reload` rather than left filtering the board to nothing
- **The frame above the columns has two heights, and `Chrome` is what every measurement takes.** `Chrome::frame` is an `Option<FrameSize>`, not a bool: `None` for a tab showing the whole board, and `Collapsed` or `Expanded` for one filtered to a campaign or a tag, because both heights have to be measured the same way by everything that measures the board. `screen_rows` grew a row, so the two bools that decide the geometry became one `Chrome`, copied from `Board::chrome`: adjacent same-typed parameters are what the Rust Style rule warns about, and the draw and `follow_selection` have to measure one answer or a keypress scrolls against a board the next frame does not draw. The row indices are named (`TAB_ROW`, `FRAME_ROW`, `BOARD_ROW`, `FOOTER_ROW`), since an index written out by hand goes on meaning what it used to. **Nothing in the geometry is named after campaigns**, because the slot is the tag filter's too: `Chrome::frame` says how tall the frame is and never which filter filled it, so a measurement of the board never has to ask
- **The whole description is carried off the one read, and the cut is on the view.** `section_prose` replaced `section_opening`, which cut to the opening line at read time: the campaign file is only in hand while the campaigns directory is being read, so what that read has to carry is everything a view might want, and `CampaignRow::summary` takes the one line the picker draws back off it. Two fields, one cut from the other, are two strings free to come from different reads of the same file
- **`FRAME_PROSE_ROWS` is the collapsed height, and it is a constant rather than a height fitted to the description.** Three rows of prose plus a border either side. A frame that grew and shrank with the campaign would resize every column whenever the filter changed, and a reader would look for a card where the previous campaign's description had put it. It does not have to be right for the longest description, because scrolling is what covers the rest — which is also why three was affordable where one row was not
@@ -294,16 +294,19 @@ and this file is for what someone changing worklane's own code needs.
- **The footer has three states, because the selection has three places to be.** An open ticket, the frame, and the cards. On the frame it names `↓ board`, `↵ expand` or `↵ collapse`, the two scroll keys and `y copy id` — `y copy tag` on a tag frame — and leaves out `←→` because they do nothing there. It has to say which way `↵` goes, since the key is a toggle and the frame is always at one of its two heights. `↑ frame` is not named on the board, on the same trade `c` is dropped on: the frame is drawn directly above the columns and up is the key that reaches it. Nor is the way to collapse an expanded frame named from the cards, which is the same trade again — the frame is right there and `↑` reaches it
- **`picker: Option<Picker>` is the whole mode**, the shape `search` and `detail` use, and `Board::picker_key` runs beside `search_key` ahead of the action arms for the same reason: an open list owns the keyboard, so `d` must not toggle done and `q` must not quit while a campaign is being chosen. `ctrl-c` is the one key it declines and every other control combination is swallowed, or `ctrl-d` would reach the arm bound to `d`
- **The picker's rows are `Tab::campaigns`, not a copy taken when it opened**, so a campaign filed elsewhere appears in an open picker on the next tick. It opens on the campaign already selected, so `c` on a filtered board says where you are as well as offering somewhere to go, and a board with no campaigns gets a `Notice` rather than an empty box that has to be dismissed to learn it was empty
- **`t` opens the same picker over the tags instead, and taking a tag filters every column to the cards carrying it.** Every tag the board declares or carries, matched whole and case sensitively the way `ls --tag` matches — the box completes the filter, so offering what the filter would refuse is the one bug it must not have. It opens on the tag already applied, the courtesy `c` pays a campaign-filtered board, and a board carrying no tag gets the same `Notice` a board with no campaigns gets
- **A picker row draws a real codename only.** The row opens with the short id, so the card's `~<id>` fallback would print it twice and say nothing the second time
- **One picker serves both lists, and `PickerRow::key` is what keeps it one.** A second picker would have been a second keyboard, query and highlight to keep in step with the first; instead `PickerKind` decides only which list is built and what the answer filters, and everything between the keypress and the filter runs once against the key — a campaign is keyed by its uuid and a tag by itself, both strings the tab can be filtered by. Picking either clears the other without either setter remembering to, because `select_filter` replaces one `Filter`: one field, which is the same reason the frame slot is shared
- **The picker draws two sections, open campaigns above completed, and truncates the completed tail.** One flat list by title put the finished campaigns among the open ones forever, and the tail only grows, so on a board that has run for a while the campaigns worth picking were pushed towards the bottom of the box and eventually off it. Open keeps the index's order, which is by title; completed is by `Created At` newest first, because what a reader recognises about a finished campaign is that it was finished recently. `COMPLETED_SHOWN` of them survive, behind a grey line naming how many older ones are being kept back — rows that are simply gone read as a board that never held them. An unstamped campaign sinks below every stamped one, the rule `by_status_order` holds for a column
- **The tag sections are declared above undeclared, and truncate neither.** The same two-section shape with the opposite reason for the second: a completed campaign is finished with, so its tail is kept back before it pushes the pickable campaigns off the box, while an undeclared tag — a word somebody typed onto a ticket that the board never agreed on — is the row a reader most wants to see. A declared tag no ticket carries stays a row too: `tags.md` is what the board intends, and the vocabulary the listing reports is the one the picker offers. `campaign` and `campaigns` would have sat one under the other here, in different sections, the day the second was invented
- **`picker_list` is the one place that decides what a picker row is**, and `Picker::row` counts *drawn* rows. The sections reorder the campaigns and add rows of their own, so `Tab::campaigns` and the drawn list agree about no number past the first heading, and a row number that meant one thing to the draw and another to a keypress is how a highlight comes to name a campaign nobody chose. The list is derived on every draw and every keypress and never held, which is what keeps a campaign filed elsewhere reaching an open picker on the next tick
- **A heading is drawn only over rows that exist**, the bargain an untagged card's label row already makes, and it says which kind its rows are for as long as they are there — which is what a query filtering down to completed campaigns alone has to go on saying
- **`open` and `completed`, not `open` and `done`.** The split is taken from `Standing::state`, so the section a campaign lands in and the state the frame draws cannot come to disagree about what finished means, but the word is the section's own: a campaign sits in no status directory, so it is not *in* done the way a ticket under that heading is. A campaign with no members is neither, per that method, and lists as open — completed means every member is done, and it holds none to be done
- **Headings and the truncation line take no number: the highlight moves over campaigns only.** `stepped_picker_row` walks past the chrome rather than stopping on it, since a highlight resting on a heading gives `enter` nothing to do, and a step that runs out of campaigns is no move at all, the way a card at the end of a column clamps rather than cycling
- **`/` in the picker is the key it already is on the board**, and `picker_key` can take it because printable keys used to fall through `_ => {}`. Typing filters case insensitively against the short id, the codename and the title — the three things the row draws and the three a campaign is chosen by. Not the summary: a query that matched prose would answer `disk` with every campaign whose description mentions one. **An empty query matches everything**, the opposite of `first_match`'s answer and right for the opposite reason: a jump with nothing typed has nowhere to go, while a filter with nothing typed is not filtering, and pressing `/` must not empty the list
- **`/` in the picker is the key it already is on the board**, and `picker_key` can take it because printable keys used to fall through `_ => {}`. Typing filters case insensitively against the short id, the codename and the title — the three things the row draws and the three a campaign is chosen by. Not the summary: a query that matched prose would answer `disk` with every campaign whose description mentions one. A tag answers by itself or by its annotation, which is a reader who cannot remember the word finding it by what it was for — case insensitive here though `--tag` is not, because matching a tag is the filter and searching for one is a reader typing. **An empty query matches everything**, the opposite of `first_match`'s answer and right for the opposite reason: a jump with nothing typed has nowhere to go, while a filter with nothing typed is not filtering, and pressing `/` must not empty the list
- **A query turns the truncation off**, which is the point of having one: the campaign a reader is searching for is exactly the one the truncation hid
- **The query is a layer, and `esc` takes it off before it takes the picker off**, the order `dismiss` closes the board's own layers in. So the list is whole again after that press, not still filtered with nothing on screen saying why. Movement and `enter` stay live under an open query, because a filtered list nothing can move in is a list nothing can be chosen from; every *printable* key goes into the buffer, so `q` types and so does `j`
- **The highlight follows its campaign, not its row number.** `place_picker` takes a uuid, the answer `Tab::campaign` already gives for the filter: typing, clearing the query and a tick that finishes a campaign all reshape the list, and a number kept across that names whichever campaign now sits at it. One the list no longer holds drops the highlight to the first row that does, which is where an incremental filter puts it. `reload` reads the highlighted uuid before the lists are rebuilt and puts it back after
- **The highlight follows its row, not its row number.** `place_picker` takes a key — a uuid or a tag, whichever list is open — the same string `Tab::filter` holds for either filter: typing, clearing the query and a tick that finishes a campaign all reshape the list, and a number kept across that names whichever campaign now sits at it. One the list no longer holds drops the highlight to the first row that does, which is where an incremental filter puts it. `reload` reads the highlighted key before the lists are rebuilt and puts it back after
- **A miss is a row in the box, `no match` in brightred**, where the search prompt puts its own, and `enter` on it leaves the picker and the query exactly as they are so the query can be corrected in place. An empty box says nothing about why it is empty
- **The picker's footer becomes its query**, the trade `draw_search` makes: with every printable key going into a buffer, a list of keys describes nothing that works. `/ search` is named only on the closed query, and the open one names what `esc` does to *it* rather than what it does to the picker
- **The title says both counts while a query is open**, `campaigns (2 of 6)`. The bare total is what the box is, but over a list a query has cut down it is a lie about what is on screen
@@ -382,7 +385,7 @@ and this file is for what someone changing worklane's own code needs.
- **`colored` still reaches `content_parts`, and it no longer means paint.** It says whether *this* renderer can carry a colour at all, and one thing turns on it: `**bold**` gives its markers up to the colour that replaces them, so a renderer with none has to keep them or the emphasis is lost rather than moved. The board passes `true`, `content_trim` passes the CLI's decision, and a piped `show` still reads its markers. Nothing else in the body consults it
- **Magenta means bold, and `span_from` is where the board learns that.** `Color::Magenta.ansi()` is `\x1b[1;35m`, so the CLI draws every bold run bold as well as magenta, and `From<Color>` can carry only the colour. Without the modifier added on the board's side the same cell would be painted two ways, which is the one thing the shared layout exists to prevent
- **The conversion is pinned from both ends.** `show_prints_the_same_body_it_printed_before_the_cells_conversion` holds a body with one of every painted run and asserts the CLI's output byte for byte, written from what it printed before the change, so the risk in sharing a layout, the CLI's output drifting to suit the board, fails the suite. `the_whole_body_is_styled_in_the_overlay_and_no_escape_reached_it` is the other end and is paired the way the guideline demands: a renderer that dropped every colour passes the absence, and one that went back to painting strings passes the presence
- **The history block arrives as cells too, so nothing in the overlay is flat.** `history_cells` lays the block out once; `format_history` is those cells through `paint_cells` and the board pushes the same ones as a `Cells` part after the body, since the log lives outside the ticket file and `content_parts` never sees it. Pinned from both ends the way the body is: `show_prints_the_same_history_it_printed_before_the_cells_conversion` holds the CLI's output byte for byte, and `the_history_block_is_styled_in_the_overlay_and_no_escape_reached_it` pairs the presence with the absence (f3e099e, closing the gap e4d0bb7 left)
- **The history block arrives as segments too, so nothing in the overlay is flat.** `history_parts` splits the entries into flow runs and quoted runs in one walk; `history_cells` is their flatten, which is what makes the CLI's bytes a property of the segmentation rather than a second walker free to drift from it, and the board reads the same parts and lays each out itself. Pinned from both ends the way the body is: the pins over `format_history` hold the flatten byte for byte, and `the_block_splits_into_flow_and_quoted_parts` pins which runs are whose
### Finding the Board
- **`find_worklane_dir` classifies the entry before it follows it.** `exists()` follows a link, so a `.worklane` that was a dangling symlink answered the same as no `.worklane` at all: the walk carried on up the tree and the first board above the project became the one every write landed in, silently. `classify` reads `symlink_metadata` first and answers one of four, `Absent`, `Board`, `Dangling` or `NotADirectory`, and **`Absent` is the only one the walk carries on from**. A `.worklane` that is there but unusable is this project's board and is reported, not handed upward
@@ -500,7 +503,8 @@ and this file is for what someone changing worklane's own code needs.
### Code Organization
- **`change` and `split_change` are a pair, and they live beside each other in `history.rs`.** The mechanical body is stored as one string, `before → after`, so painting the halves means splitting it, and the separator is a constant the writer and the reader share. A renderer with its own copy of the spacing would go on splitting on a separator the writer no longer emits, and would say so by drawing a whole body as one half. The split is `split_once`, so a value carrying the arrow itself keeps it
- **The history block indents by who is talking.** A comment's body sits at four spaces and the reason under a mechanical row at two; the author line stays at column 0 and is told from a mechanical row by its `From` and its colour instead. The rule a reader learns is that an indented line is somebody's own words and a line of values at column 0 is the tool reporting itself
- **The history block quotes who is talking.** Every line of a comment's body draws behind a grey bar spanning the whole run, paragraph breaks included, the way quoted text is drawn — d447e04, taking the review of 2733b10's answer over that ticket's uniform prefix and b304b17's per-line indent, both of which left the continuation at column 0. The reason under a mechanical row draws the same bar. The author line stays at column 0 and is told from a mechanical row by its `From` and its colour instead; the rule a reader learns is that a barred line is somebody's own words and a line of values at column 0 is the tool reporting itself. With colour off the glyph goes but the width it occupied stays, as spaces derived from the drawn form in `quoted_cells`, so a pipe keeps the column without an escape byte
- **A quote is one segmentation, two shapes, and the shapes split on wrapping.** The CLI prefixes each stored line — `quoted_cells`, which is why a terminal soft-wrapping a wide line draws continuations bare: a pipe has no width to honour, and `show` does not wrap by hand. The board quotes as geometry instead (8020e48): a `HistoryPart::Quoted` run becomes an overlay section laid out as two columns, a two-cell gutter holding the grey bar top to bottom and the body beside it, so a row the prose wraps onto inherits the mark from the gutter rather than from its own first characters. `Detail` holds sections for this reason — flow stretches full width, quotes beside their gutters — and the clamp sums the sections' wrapped heights, so scroll and draw measure one total. The newline history writes after every quote is consumed by the section builder rather than drawn: it used to close the quote's last line and the section boundary does that now, so drawing it would bank a blank row no entry ever had. `QUOTE_BAR` lives in `util.rs` because both renderers draw it, not because they draw it the same way
- **`history.rs` owns the log end to end**: the path, the kinds, the parse, the write, the count and the render. It came out of `util.rs` and `handlers.rs`, where the reader, the writer, the counter and the renderer sat in three files and one of them was 5,500 lines. The test for the reason is the module doc: a reader asking what an entry is has one file to open, the way `campaign.rs` and `tag.rs` answer their own questions
- The body's painters return cells, not strings: `ordered_cells`, `inline_cells`, `metadata_cells`, `metadata_value_cells`, `tag_cells` and `push_heading`. `content_trim_colored` is the CLI entry point and `paint_cells` is the only thing that writes an escape. `colorize_line` is gone: it was a `pub` alias for the bold pass with one caller, and the only thing it added was asking the terminal
- **`inline_cells` walks the line once for both inline markers**, `**bold**` and `[text](url)`, rather than running one pass over the output of the other. A second pass would be scanning text that already holds escape sequences, and `\x1b[36m` carries an opening bracket, so the link scan would take the escape for markup. The source is the only string in which either marker means what it says. It was `colorize_bold` while links lived in a branch of their own in `content_parts`; that branch is gone, which is also what gives the criteria text and the metadata `Other` rows their links, since those already went through this function
@@ -510,6 +514,7 @@ and this file is for what someone changing worklane's own code needs.
- `resolve_ticket()` scans all status directories — it's the single source for ticket lookup by UUID prefix, title, or filename
- `parse_ticket_field()` handles extracting metadata values from markdown format
- `move_ticket_file()` stages the updated content in a temp file under `.worklane/`, renames it over the source, and only then renames the file into the target directory. Do not reorder these: renaming first and writing second leaves a ticket in its new directory claiming the old status, and writing to the target then deleting the source puts it in two directories at once. The temp lives outside the status directories so a leftover is never read as a ticket. A failure at the last step leaves the ticket in its old directory with a Status one move ahead, which the next `mv` corrects
- **A move whose target equals the directory the file already sits in repairs a Status field that disagrees with it, instead of refusing as a no-op.** `resolve_ticket` reads the current status off the directory, so the old comparison was the directory agreeing with itself and could never see the field; a hand-moved file was stuck with moving it away and back to fix it. Now the field is compared first: agreement is the ordinary already-in-status report with nothing written, disagreement rewrites the field alone through the same in-place save every edit uses, and reports it as a correction rather than a move. It is gated on neither `-f` nor the dependency guards behind them, because it is not a transition; it writes no stamp, since presence still answers how far the work got and the work arrived nowhere new; and it logs nothing, because an entry shaped like a transition would record a journey the ticket never took. The mirror case is unchanged: a field ahead of its directory after a crash mid-move is corrected by the next real `mv`, because there the target is a status the ticket is not sitting in
- Field lookup, read and write, is scoped to the lines under the `## Metadata` heading and anchored to the start of the line. Prose above it is free text: tickets in this repo quote field markers in their descriptions, and an unscoped search reads or rewrites those instead. `set_status_field()` carries the same scoping
### Ticket Resolution
Generated
+1 -1
View File
@@ -1503,7 +1503,7 @@ dependencies = [
[[package]]
name = "worklane"
version = "0.32.2"
version = "0.32.7"
dependencies = [
"anyhow",
"assert_cmd",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "worklane"
version = "0.32.2"
version = "0.32.7"
edition = "2024"
[dependencies]
+14 -6
View File
@@ -233,17 +233,25 @@ two exceptions below are files no command owns, and they are marked as such.
first check `worklane ls done`. If it is there and should not be, its file has been moved
into the wrong directory by hand or by a restore.
The repair is two moves, not one:
`mv` reads the current status from the *directory*, so one move puts both halves right:
move the ticket to the status it belongs in and the field travels with it.
```
worklane mv 1b78a24 --status reviewing -f
worklane mv 1b78a24 --status done -f
```
`mv` reads the current status from the *directory*, so moving it to the status the
directory already says it is in is refused as a no-op and the field stays wrong. Moving it
away and back rewrites the field. Check with `worklane show 1b78a24`, whose `Status` line
is read from the file rather than from where it sits.
If the file is where it belongs and only the `Status` field inside is stale — a hand move
that forgot the field, or a half-finished restore — name the directory the file actually
sits in: a move there finds the field disagreeing with the directory and rewrites just
the field, reporting the correction instead of refusing as a no-op.
```
worklane mv 1b78a24 --status done
```
That repair changes only the field: no stamp is written and no history entry either,
because the work went nowhere. Check either repair with `worklane show 1b78a24`, whose
`Status` line is read from the file rather than from where it sits.
### A command says the id matches several tickets
+19 -16
View File
@@ -365,30 +365,33 @@ Read the block before picking a ticket up: it says whether somebody has already
## Who your entries are attributed to
Every comment carries an author, and by default that is the git user of the machine you
are running on, which is the human whose checkout it is and not you. Set
`WORKLANE_ACTOR` in your own environment and it becomes the author of every entry you
write, so a board several agents write to says which of them said what:
Every entry carries an author, and yours comes from `WORKLANE_ACTOR`, which your harness
sets before you run anything. **Assume it is set for you, and never spell yourself out on
a call** — a plain `worklane comment` is already attributed to you, which is what keeps a
board several agents write to saying which of them said what. It is configured once,
where your session's environment lives: `env` in `~/.claude/settings.json` for Claude
Code, and the environment opencode is started with for opencode, since it passes its own
environment to the tools it runs.
**Reach for `--actor` only when the entry is somebody else's action**: the person asked
you to move a ticket, or to put words on the board as their comment, so name them on the
flag — the move was theirs and the words are theirs, and an entry carrying your name
reads later as though you decided both. Otherwise leave it off, unless your instructions
say to use it. It is spelled the same on every command that writes an entry: `comment`,
`mv`, `chown`, `set` and `assign`.
```
WORKLANE_ACTOR=claude worklane comment 1b78a24 "The offset was never passed to the widget."
worklane mv 1b78a24 --status done --actor "Ansho Rei"
```
Set it once where your session's environment is configured, not on each call: `env` in
`~/.claude/settings.json` for Claude Code, and the environment opencode is started with
for opencode, since it passes its own environment to the tools it runs. `--actor`
overrides it for one call and is spelled the same on every command that writes an entry,
`comment`, `mv`, `chown`, `set` and `assign`. An empty value counts as unset and falls
back to the
git user, and with nothing at all the author is `unknown`. It is free text, checked
against nothing: name yourself something a person reading the board will recognise.
Under a missing or empty variable the author falls back to the git user of the machine —
the human whose checkout it is — and with neither, `unknown`. It is free text, checked
against nothing: whatever name you pass, make it one a person reading the board will
recognise.
On `chown`, `--actor` is not the user argument: `worklane chown alice 1b78a24` makes alice
the ticket's owner, and `--actor` says who made that change.
If the variable is not set and you cannot set it, pass `--actor` rather than letting the
comment claim to be the user's.
## Shell completions
```
+21 -8
View File
@@ -162,22 +162,35 @@ fn tag_value(raw: &str) -> Result<String, String> {
Ok(value.to_string())
}
/// Reject an annotation line that would be read back as a tag of its own.
/// Reject an annotation the vocabulary file or the listing cannot carry.
///
/// The vocabulary is one heading per tag with its prose under it, so a line of prose
/// starting with the section marker would split the annotation and declare whatever
/// followed. Refused at parse time, where nothing has been written, rather than escaped on
/// the way in: an annotation is prose, and quietly rewriting prose is worse than asking for
/// a different line.
/// followed. A tab anywhere in the value is refused for the listing's sake rather than the
/// file's: `tags ls` prints one tag, its count and the annotation's opening line as three
/// tab-separated fields, so an annotation holding a tab reads as the start of a fourth
/// field and everything after it is silently gone.
///
/// Both are refused at parse time, where nothing has been written, rather than escaped on
/// the way in: an annotation is prose, and quietly rewriting prose is worse than asking
/// for a different line.
fn annotation_line(raw: &str) -> Result<String, String> {
match raw.lines().any(|line| line.starts_with(crate::tag::SECTION)) {
true => Err(format!(
if raw.lines().any(|line| line.starts_with(crate::tag::SECTION)) {
return Err(format!(
"an annotation line cannot start with '{}', which is how the vocabulary file \
starts a tag",
crate::tag::SECTION
)),
false => Ok(raw.to_string()),
));
}
if raw.contains('\t') {
return Err(
"an annotation cannot contain a tab, which is how `tags ls` separates its fields"
.to_string(),
);
}
Ok(raw.to_string())
}
/// What `--actor` says on every command that writes a history entry.
+42 -11
View File
@@ -378,12 +378,8 @@ pub fn cmd_show(search: &str, worklane_dir: &Path) -> Result<()> {
/// What is being written, for the messages a failure carries.
///
/// A `&str` naming the thing rather than two copies of the write path: a campaign file is
/// a ticket file in every way that matters here, `<uuid>_<slug>.md` in a directory, and the
/// only difference is the word a failure has to use. Every message below puts it
/// mid-sentence so there is no capital to case.
const TICKET: &str = "ticket";
const CAMPAIGN: &str = "campaign";
/// `TICKET` and `CAMPAIGN` live in util.rs beside the writers that now carry the noun
/// too; only the tag is spelled here, being a file no ticket command writes.
const TAG: &str = "tag";
/// Write `content` over `path`, without ever leaving half a file behind.
@@ -651,8 +647,41 @@ pub fn cmd_mv(
}
if current_status == target_status {
// `current_status` is read off the directory, so this comparison is the field's
// only chance to be seen. A ticket whose file sits here and whose Status field
// says something else is a hand-moved file or a partial restore, and refusing it
// as a no-op left a repair nobody could reach without moving the file away and
// back; the mirror case, where the field leads the directory after a crash in
// move_ticket_file, is what the next real mv corrects.
let recorded = parse_ticket_field(&resolved, "Status");
if recorded == target_status {
println!(
"Ticket is already in '{}' status.",
color_text(target_status, Color::Orange)
);
return Ok(());
}
// The repair is not a move, so none of what gates one applies: not `-f`, which
// overrides transitions, and not the dependency guards behind it. Only the field
// is rewritten — no stamp, because the work arrived nowhere new, and no history
// entry, because an entry shaped like a transition would record a journey the
// ticket never took.
let corrected = set_status_field(&resolved, target_status, &title)?;
save_ticket(
&worklane_dir,
&current_status,
&parse_ticket_field(&resolved, "ID"),
&title,
None,
&corrected,
)?;
println!(
"Ticket is already in '{}' status.",
"Corrected Status field on '{}': said {}, but the file sits in {}.",
color_text(&title, Color::Green),
color_text(&recorded, Color::Orange),
color_text(target_status, Color::Orange)
);
return Ok(());
@@ -934,7 +963,7 @@ pub fn cmd_set(args: &SetArgs, start: &Path) -> Result<()> {
let mut cleared: Vec<&str> = Vec::new();
if let Some(new_title) = &args.title {
let next = set_title(&content, new_title)?;
let next = set_title(&content, new_title, TICKET)?;
apply(&mut content, &mut changed, "title", next);
}
@@ -1641,7 +1670,7 @@ pub fn cmd_campaign_set(args: &CampaignSetArgs, start: &Path) -> Result<()> {
let mut changed: Vec<&str> = Vec::new();
if let Some(new_title) = &args.title {
let next = set_title(&content, new_title)?;
let next = set_title(&content, new_title, CAMPAIGN)?;
apply(&mut content, &mut changed, "title", next);
}
@@ -1656,7 +1685,8 @@ pub fn cmd_campaign_set(args: &CampaignSetArgs, start: &Path) -> Result<()> {
}
if let Some(codename) = &args.codename {
let next = set_or_insert_metadata_field(&content, CODENAME_FIELD, codename, &title)?;
let next =
set_or_insert_metadata_field(&content, CODENAME_FIELD, codename, CAMPAIGN, &title)?;
apply(&mut content, &mut changed, "codename", next);
}
@@ -1749,7 +1779,8 @@ pub fn cmd_assign(
let (status, title, original) = resolve_ticket(ticket_id, &worklane_dir)?;
let uuid = parse_ticket_field(&original, "ID");
let content = set_or_insert_metadata_field(&original, CAMPAIGN_FIELD, &campaign.uuid, &title)?;
let content =
set_or_insert_metadata_field(&original, CAMPAIGN_FIELD, &campaign.uuid, TICKET, &title)?;
if content == original {
println!(
+238 -66
View File
@@ -24,8 +24,8 @@ use anyhow::{Result, anyhow};
use chrono::Local;
use crate::util::{
Cell, Color, MISSING, TIMESTAMP_FORMAT, is_unknown_value, paint_cells, should_use_colors,
tag_cells, tag_color,
Cell, Color, MISSING, TIMESTAMP_FORMAT, is_unknown_value, paint_cells, quoted_cells,
should_use_colors, tag_cells, tag_color,
};
/// Where a ticket's history lives, under the board.
@@ -402,24 +402,9 @@ pub fn format_history(entries: &[Entry]) -> String {
/// As above, with the colour decision passed in.
pub fn format_history_with(entries: &[Entry], colored: bool) -> String {
paint_cells(&history_cells(entries), colored)
paint_cells(&history_cells(entries, colored), colored)
}
/// How far the reason under a mechanical row sits from the margin.
///
/// One step, which is where a comment's body used to sit too. It stays here because the
/// reason belongs to the row above it: it is read as part of that transition, not as an
/// entry of its own.
const REASON_INDENT: &str = " ";
/// How far a comment's body sits from the margin.
///
/// One step deeper than a reason, so the column says who is talking: a line indented this
/// far is somebody's own words and a line of values at column 0 is the tool reporting
/// itself. The author line stays at column 0 and is told from a mechanical row by its
/// `From` and its colour instead, which is the trade this shape accepts.
const COMMENT_INDENT: &str = " ";
/// The cells one value in a mechanical body is drawn as, per the Color Guideline.
///
/// Keyed on the kind, because the kind is what says which field the value came from: the
@@ -466,79 +451,135 @@ fn stamp_cells(entry: &Entry) -> Vec<Cell> {
]
}
/// The block laid out once, as [`Cell`]s: the CLI paints them and the board turns the
/// same ones into styled spans, so the two views cannot draw two different blocks.
pub fn history_cells(entries: &[Entry]) -> Vec<Cell> {
/// One segment of the history block: what it is, and how a renderer lays it out.
///
/// [`history_cells`] flattens these into the cells the CLI paints, and the board turns
/// each segment into its own stretch of the overlay instead: the flow runs full width
/// while a quoted run becomes a gutter column with the bar in it and the body beside it,
/// so a row the body wraps keeps the mark. One segmentation, two shapes — neither
/// renderer re-decides which runs are somebody's words.
#[derive(Debug)]
pub enum HistoryPart {
/// Headers, mechanical rows and the blank lines between entries, as they stand.
Flow(Vec<Cell>),
/// A comment's body or a move's reason: plain text, every line of it quoted, in
/// whatever shape the renderer quotes with.
Quoted(String),
}
/// The block as segments, one walk over the entries.
///
/// The order is the entries' own, oldest first, and a quoted run always sits between two
/// flow runs — the header or mechanical row before it and the blank line after it — so a
/// renderer can treat each segment as one unbroken stretch of rows.
pub fn history_parts(entries: &[Entry]) -> Vec<HistoryPart> {
let mut parts = Vec::new();
// The flow accumulating until the next quote closes it, which is why the trailing
// newline of every entry lands in the segment *after* a quote rather than being
// dropped: flattened, the parts are byte for byte the block [`history_cells`] has
// always built, which is what the CLI's pins hold it to.
let mut flow: Vec<Cell> = Vec::new();
if entries.is_empty() {
return vec![Cell::colored("No history yet.", Color::Grey)];
flow.push(Cell::colored("No history yet.", Color::Grey));
parts.push(HistoryPart::Flow(flow));
return parts;
}
let mut cells = Vec::new();
cells.push(Cell::plain("\n"));
cells.push(Cell::colored("HISTORY", Color::Orange));
cells.push(Cell::plain(format!("\n{}\n", "─".repeat(20))));
flow.push(Cell::plain("\n"));
flow.push(Cell::colored("HISTORY", Color::Orange));
flow.push(Cell::plain(format!("\n{}\n", "─".repeat(20))));
for entry in entries {
cells.push(Cell::plain("\n"));
flow.push(Cell::plain("\n"));
match entry.kind {
// As it has always read: a header naming who said it, then the text.
Kind::Comment => {
// Grey on the word, for the reason the kind label is grey: `From` names
// the line, it is not a value in it.
cells.push(Cell::colored("From", Color::Grey));
cells.push(Cell::plain(" "));
cells.extend(stamp_cells(entry));
cells.push(Cell::plain("\n"));
flow.push(Cell::colored("From", Color::Grey));
flow.push(Cell::plain(" "));
flow.extend(stamp_cells(entry));
flow.push(Cell::plain("\n"));
if !entry.body.is_empty() {
cells.push(Cell::plain(format!("{}{}", COMMENT_INDENT, entry.body)));
parts.push(HistoryPart::Flow(std::mem::take(&mut flow)));
parts.push(HistoryPart::Quoted(entry.body.clone()));
}
cells.push(Cell::plain("\n"));
flow.push(Cell::plain("\n"));
}
// One line: a field change is one fact and a paragraph for it would bury the
// comments it sits between. A reason grows an indented line under the row,
// the way a comment's text sits under its From header, so it reads as
// attached to the transition it explains rather than as the next entry.
// comments it sits between. A reason draws behind the same bar the comments
// draw, since it shares their shape and their gap, so it reads as attached
// to the transition it explains rather than as the next entry.
_ => {
let padding = Kind::LABEL_WIDTH.saturating_sub(entry.kind.slug().chars().count());
// Grey, as chrome. It was orange, which means Status everywhere else, so
// an `owner` or `tags` label claimed a meaning belonging to the value
// beside it. The label is not a value at all: it names the row, which is
// what grey already says.
cells.push(Cell::colored(entry.kind.slug(), Color::Grey));
flow.push(Cell::colored(entry.kind.slug(), Color::Grey));
// Measured on the unpainted label and carried in a cell of its own, the
// rule the metadata table follows: measuring a painted string counts its
// escapes towards its width, which tilts the column when colour is on and
// not when it is off.
cells.push(Cell::plain(format!("{} ", " ".repeat(padding))));
flow.push(Cell::plain(format!("{} ", " ".repeat(padding))));
match split_change(&entry.body) {
Some((before, after)) => {
cells.extend(value_cells(entry.kind, before));
cells.push(Cell::plain(CHANGE_SEPARATOR));
cells.extend(value_cells(entry.kind, after));
flow.extend(value_cells(entry.kind, before));
flow.push(Cell::plain(CHANGE_SEPARATOR));
flow.extend(value_cells(entry.kind, after));
}
None => cells.extend(value_cells(entry.kind, &entry.body)),
None => flow.extend(value_cells(entry.kind, &entry.body)),
}
cells.push(Cell::plain(" "));
cells.extend(stamp_cells(entry));
cells.push(Cell::plain("\n"));
flow.push(Cell::plain(" "));
flow.extend(stamp_cells(entry));
flow.push(Cell::plain("\n"));
// The newline is the quote's terminator, so it exists only when there is
// one: a reasoned row draws the reason under itself and this closes it.
if !entry.reason.is_empty() {
cells.push(Cell::plain(format!("{}{}", REASON_INDENT, entry.reason)));
cells.push(Cell::plain("\n"));
parts.push(HistoryPart::Flow(std::mem::take(&mut flow)));
parts.push(HistoryPart::Quoted(entry.reason.clone()));
flow.push(Cell::plain("\n"));
}
}
}
}
if !flow.is_empty() {
parts.push(HistoryPart::Flow(flow));
}
parts
}
/// The block laid out once, as [`Cell`]s: the CLI paints them and the board turns the
/// same ones into styled spans, so the two views cannot draw two different blocks.
///
/// The flatten of [`history_parts`], which is what makes the CLI's bytes a property of
/// the segmentation rather than a second walk that can drift from it: the pins over this
/// function's output are pins over the parts too. The colour decision rides in because
/// the quote bar is a coloured decoration; with it off the cells carry the indent the
/// bar would have provided. The board does not come through here — it lays each part in
/// the shape the section builder gives it — but it reads the same parts.
pub fn history_cells(entries: &[Entry], colored: bool) -> Vec<Cell> {
let mut cells = Vec::new();
for part in history_parts(entries) {
match part {
HistoryPart::Flow(run) => cells.extend(run),
HistoryPart::Quoted(body) => cells.extend(quoted_cells(&body, colored)),
}
}
cells
}
#[cfg(test)]
mod tests {
use super::*;
use crate::util::{Fixture, NOT_SET, paint};
use crate::util::{
BLOCKED_MARK, Fixture, NOT_SET, PRIORITY_RANGE, Priority, QUOTE_BAR, REGRESSION_MARK,
RELATES_MARK, paint, priority_mark, status_dirs, status_mark,
};
/// One entry, spelled the way a file on the board holds it.
fn entry(kind: &str, body: &str, author: &str, time: &str) -> Entry {
@@ -775,12 +816,14 @@ mod tests {
] {
assert!(rendered.contains(row), "missing {row:?} in {rendered}");
}
// The body sits a step deeper than a reason does, and the author line did not move
// The body keeps the width the bar occupied, and the author line did not move
assert!(
rendered
.contains("From Ansho Rei (2026-08-24 12:00:04)\n The offset was never passed"),
.contains("From Ansho Rei (2026-08-24 12:00:04)\n The offset was never passed"),
"{rendered}"
);
// A single line draws no glyph in a pipe, and it is not spared the indent
assert!(!rendered.contains(QUOTE_BAR), "{rendered:?}");
assert!(!rendered.contains('\x1b'), "colour off still painted: {rendered:?}");
}
@@ -788,10 +831,12 @@ mod tests {
/// way `show_prints_the_same_body_it_printed_before_the_cells_conversion` pins the
/// body.
///
/// Rewritten twice, deliberately. `campaign` widened the label column from 6 to 8 and
/// put its own row in the pin (f774a33). Then 2733b10 painted the values: the label
/// went grey as chrome, each value took the meaning it carries in the metadata table,
/// and the actor and the timestamp came apart into two spans.
/// Rewritten three times, deliberately. `campaign` widened the label column from 6
/// to 8 and put its own row in the pin (f774a33). Then 2733b10 painted the values:
/// the label went grey as chrome, each value took the meaning it carries in the
/// metadata table, and the actor and the timestamp came apart into two spans. Then
/// d447e04 put the single-line body behind the grey quote bar, which is what the
/// `{bar}` in the middle of the expected string is.
///
/// Every kind is here rather than a representative one, since what each row proves is
/// different: status is the orange it is three lines above, tags go through the same
@@ -820,8 +865,9 @@ mod tests {
paint(time, Color::Cyan, true)
)
};
let bar = paint(&format!("{QUOTE_BAR} "), Color::Grey, true);
let expected = format!(
"\n{}\n{}\n\n{} {} → {} {}\n\n{} {}\n The offset was never passed\n\n{} {} → {} {}\n\n{} {} → alice {}\n\n{} {} → {}, {} {}\n",
"\n{}\n{}\n\n{} {} → {} {}\n\n{} {}\n{}The offset was never passed\n\n{} {} → {} {}\n\n{} {} → alice {}\n\n{} {} → {}, {} {}\n",
paint("HISTORY", Color::Orange, true),
"─".repeat(20),
paint("status", Color::Grey, true),
@@ -830,6 +876,7 @@ mod tests {
stamp("claude", "2026-08-24 12:00:00"),
paint("From", Color::Grey, true),
stamp("Ansho Rei", "2026-08-24 12:00:01"),
bar,
paint("campaign", Color::Grey, true),
paint(NOT_SET, Color::Grey, true),
paint("v1", tag_color("v1"), true),
@@ -878,10 +925,10 @@ mod tests {
assert!(!rendered.contains(&paint("claude (", Color::Cyan, true)), "still one span");
}
/// The reason is the row's, so it renders indented under the row it explains and
/// before whatever entry follows, in both renderers — this is the one layout they
/// share. Paired with the pin above: an entry without a reason renders exactly as
/// it always did.
/// The reason is the row's, so it renders behind the same bar the comments draw,
/// under the row it explains and before whatever entry follows, in both renderers —
/// this is the one layout they share. Paired with the pin above: an entry without a
/// reason renders exactly as it always did.
#[test]
fn a_reason_renders_indented_under_its_row() {
let entries = vec![
@@ -893,8 +940,9 @@ mod tests {
entry("comment", "And why.", "Ansho Rei", "2026-08-24 12:00:01"),
];
let bar = paint(&format!("{QUOTE_BAR} "), Color::Grey, true);
let expected = format!(
"\n{}\n{}\n\n{} {} → {} {} ({})\n sent back, the first plan was wrong\n\n{} {} ({})\n And why.\n",
"\n{}\n{}\n\n{} {} → {} {} ({})\n{}sent back, the first plan was wrong\n\n{} {} ({})\n{}And why.\n",
paint("HISTORY", Color::Orange, true),
"─".repeat(20),
paint("status", Color::Grey, true),
@@ -902,18 +950,100 @@ mod tests {
paint("backlog", Color::Orange, true),
paint("claude", tag_color("claude"), true),
paint("2026-08-24 12:00:00", Color::Cyan, true),
bar,
paint("From", Color::Grey, true),
paint("Ansho Rei", tag_color("Ansho Rei"), true),
paint("2026-08-24 12:00:01", Color::Cyan, true),
bar,
);
assert_eq!(format_history_with(&entries, true), expected);
// Colour off keeps the reason exactly where a pipe has always read it, at the
// width the bar occupied, and carries no glyph doing it.
let plain = format_history_with(&entries, false);
assert!(
format_history_with(&entries, false)
.contains("claude (2026-08-24 12:00:00)\n sent back, the first plan was wrong"),
"colour off lost the reason: {}",
format_history_with(&entries, false)
plain.contains("claude (2026-08-24 12:00:00)\n sent back, the first plan was wrong"),
"colour off lost the reason: {plain}"
);
assert!(!plain.contains(QUOTE_BAR) && !plain.contains('\x1b'), "{plain:?}");
}
/// The reported shape: every line of a run sits behind the bar, so a two-paragraph
/// comment reads as one voice start to finish. This is what a single prefix got
/// wrong — b304b17's symptom — with every line after the first back at column 0,
/// which 2733b10 had just given a meaning to.
#[test]
fn a_multi_line_comment_draws_every_line_behind_the_bar() {
let entries = vec![entry(
"comment",
"First paragraph.\n\nSecond one, still theirs.",
"Ansho Rei",
"2026-08-24 12:00:00",
)];
let bar = paint(&format!("{QUOTE_BAR} "), Color::Grey, true);
let bare = paint(QUOTE_BAR, Color::Grey, true);
let rendered = format_history_with(&entries, true);
// Both content lines prefixed, and the break between them inside the run as the
// bare glyph rather than a gap running nowhere.
let expected = format!(
"\n{}\n{}\n\n{} {} ({})\n{}First paragraph.\n{}\n{}Second one, still theirs.\n",
paint("HISTORY", Color::Orange, true),
"─".repeat(20),
paint("From", Color::Grey, true),
paint("Ansho Rei", tag_color("Ansho Rei"), true),
paint("2026-08-24 12:00:00", Color::Cyan, true),
bar,
bare,
bar,
);
assert_eq!(rendered, expected);
}
/// Paired with the one above, the way the guideline demands: colour off drops the
/// glyph but keeps the width it occupied, derived from the drawn form, so every
/// content line still starts at the same column and no escape byte reaches a pipe.
/// The flag is the only thing that decides the bar.
#[test]
fn colour_off_keeps_the_indent_and_drops_the_glyph() {
let entries = vec![entry(
"comment",
"First paragraph.\n\nSecond one, still theirs.",
"Ansho Rei",
"2026-08-24 12:00:00",
)];
let rendered = format_history_with(&entries, false);
let expected = format!(
"\nHISTORY\n{}\n\nFrom Ansho Rei (2026-08-24 12:00:00)\n First paragraph.\n\n Second one, still theirs.\n",
"─".repeat(20),
);
assert_eq!(rendered, expected);
}
/// The bar is chrome like the kind label, so it takes grey; it is one cell wide; and
/// it claims nothing another column already means: the circles and the dot belong to
/// the priority meter, the cross and arrows to the relation rows, and the status
/// marks reuse both sets. Pinned against the marks actually defined rather than a
/// list written out here, so a mark added later fails this instead of sharing.
#[test]
fn the_quote_bar_claims_no_glyph_another_column_means() {
assert_eq!(QUOTE_BAR.chars().count(), 1);
let mut taken = String::new();
for level in PRIORITY_RANGE {
taken.push_str(priority_mark(Priority::Level(level)).0);
}
taken.push_str(priority_mark(Priority::Unset).0);
taken.push_str(BLOCKED_MARK);
taken.push_str(RELATES_MARK);
taken.push_str(REGRESSION_MARK);
for status in status_dirs() {
taken.push_str(status_mark(Some(status)).0);
}
assert!(!taken.contains(QUOTE_BAR), "{taken:?} already means something");
}
/// Padded to the longest of the four, so every body starts in the same column
@@ -961,4 +1091,46 @@ mod tests {
fn nothing_recorded_says_so() {
assert_eq!(format_history_with(&[], false), "No history yet.");
}
/// The block as segments: the rows drawn as they stand are flow, a comment's body
/// and a move's reason are quoted, and each quote sits between two flow runs — the
/// row or header before it and the blank after it. This is the one segmentation both
/// renderers read, so it is pinned here rather than left to be discovered on the
/// board; the CLI's byte pins above hold its flatten to what it has always printed.
#[test]
fn the_block_splits_into_flow_and_quoted_parts() {
let entries = vec![
entry("status", "committed → reviewing", "claude", "2026-08-24 12:00:00"),
entry("comment", "First line.\n\nSecond.", "Ansho Rei", "2026-08-24 12:00:01"),
entry("status", "reviewing → backlog", "claude", "2026-08-24 12:00:02"),
]
.into_iter()
.enumerate()
.map(|(at, mut entry)| {
if at == 2 {
entry.reason = "sent back".to_string();
}
entry
})
.collect::<Vec<_>>();
let parts = history_parts(&entries);
let shapes: Vec<&str> = parts
.iter()
.map(|part| match part {
HistoryPart::Flow(_) => "flow",
HistoryPart::Quoted(_) => "quote",
})
.collect();
assert_eq!(shapes, ["flow", "quote", "flow", "quote", "flow"], "{parts:?}");
// The quotes carry the bare words, newlines included; laying them out is the
// renderer's decision.
for part in &parts {
if let HistoryPart::Quoted(body) = part {
assert!(!body.contains(QUOTE_BAR), "{body:?}");
}
}
assert_eq!(parts.len(), 5);
}
}
+6 -5
View File
@@ -489,10 +489,10 @@ mod tests {
///
/// The domain examples are the first thing an edit would quietly drop, since every
/// other skill here is written around this repo, and dropping them leaves a document
/// that teaches a household board to file `cli` tickets. The two-step repair is the
/// second: it looks like a typo until you have watched `mv` refuse the one-step
/// version, which is why the ticket for this skill demanded every repair be run rather
/// than reasoned about.
/// that teaches a household board to file `cli` tickets. The one-move correction is
/// the second: it is the repair `mv` actually performs since it learned to fix a
/// Status field that lags its directory, and an edit back to the old two-step recipe
/// would be teaching a workaround for a bug that no longer exists.
#[test]
fn the_admin_skill_stays_domain_neutral_and_keeps_its_verified_repairs() {
for required in [
@@ -500,7 +500,8 @@ mod tests {
"product strategy", //
"worklane tags add", // the vocabulary is declared through the CLI
"--tags` replaces the whole field", // the destructive one, restated where it bites
"two moves, not one", // the repair `mv` cannot do in one step
"reporting the correction instead of refusing as a no-op", // the repair `mv` does in one step
"no stamp is written and no history entry", // because the work went nowhere
"do not edit a ticket file",
"File exception", // and the three places that rule does not reach
"worklane-plan", // the boundary against the sweep document
+343 -49
View File
@@ -23,7 +23,7 @@ use ratatui::text::{Line, Span, Text};
use ratatui::widgets::{Block, Borders, Clear, Paragraph, Tabs, Wrap};
use crate::campaign::{CAMPAIGNS_DIR, CampaignIndex, Standing};
use crate::history::{history_cells, history_root, read_history};
use crate::history::{HistoryPart, history_parts, history_root, read_history};
use crate::tag::{NO_ANNOTATION, TAGS_FILE, TagIndex};
use crate::util::*;
@@ -590,26 +590,61 @@ pub struct Detail {
/// card that said so, and the id alone is not an address across several boards:
/// acting on the ticket means knowing which project to run the command in.
pub project: Option<String>,
/// The body as the overlay draws it: lines of styled spans, not a string.
/// The body as vertical stretches, each one drawn and measured whole.
///
/// Styled here rather than painted into the text, because ratatui draws an escape
/// sequence in a paragraph as literal bytes, which is 6d327df. It is also the one
/// value the clamp and the draw both measure, so neither can wrap it differently
/// from the other.
pub body: Text<'static>,
/// A flow stretch runs full width; a quoted one is laid out as two columns at draw
/// time — a gutter the bar fills top to bottom, and the body beside it. That is what
/// keeps a comment's bar over every row its prose wraps onto, which a bar riding in
/// the text cannot do: the wrapper folds continuations underneath it. Sections are
/// also what the clamp measures, summed, so the scroll and the draw cannot disagree
/// about where any of them ends.
pub sections: Vec<DetailSection>,
}
/// One vertical stretch of the overlay, drawn and measured as a unit.
#[derive(Debug)]
pub enum DetailSection {
/// Description, metadata, mechanical history rows and the blanks between them:
/// full width, wrapped by the widget as always.
Flow(Text<'static>),
/// Somebody's words, from a [`HistoryPart::Quoted`] run. Carries the body only —
/// the bar is the gutter the draw lays beside it, not text under which a wrapped
/// row would lose it.
Quote(Text<'static>),
}
impl DetailSection {
fn text(&self) -> &Text<'static> {
match self {
DetailSection::Flow(text) | DetailSection::Quote(text) => text,
}
}
/// The width this section wraps at: the gutter takes its two cells from the rest.
fn width(&self, full: u16) -> u16 {
match self {
DetailSection::Flow(_) => full,
DetailSection::Quote(_) => full.saturating_sub(GUTTER_WIDTH),
}
}
}
/// How wide a quoted run's gutter is: the bar and the gap before the body, so a quoted
/// row reads exactly as wide as one the CLI prefixes.
const GUTTER_WIDTH: u16 = 2;
impl Detail {
/// The body as plain text, one line per drawn line.
///
/// Only the suite asks: it is what an assertion about the body reads, and what shows
/// that no escape sequence reached it. Nothing in the draw path needs it, so it is
/// not carried alongside the spans where the two could disagree.
/// not carried alongside the spans where the two could disagree. A quote's rows carry
/// no bar here, since on screen the bar is the gutter and not part of the line.
#[cfg(test)]
pub fn plain(&self) -> String {
self.body
.lines
self.sections
.iter()
.flat_map(|section| section.text().lines.iter())
.map(|line| {
line.spans
.iter()
@@ -1861,7 +1896,7 @@ impl Board {
let text = detail_text_area(Rect::new(0, 0, screen.width, screen.height));
// A screenful less a line, so the eye has something to land on after the jump.
let step = text.height.saturating_sub(1).max(1) as isize;
let last = last_offset(&detail.body, text) as isize;
let last = detail_last_offset(&detail.sections, text) as isize;
self.offset = (self.offset as isize + pages.saturating_mul(step)).clamp(0, last) as u16;
}
@@ -1997,37 +2032,91 @@ fn detail_of(card: &Card) -> Detail {
};
// Colour on, and nothing here is painted: the body arrives as cells, the relations
// as rows and the history block as the cells the CLI paints, and `detail_body`
// turns them all into styled spans. An escape sequence never enters, which is what
// a ratatui paragraph would draw as literal bytes.
// as rows and the history block as segments, and `detail_sections` turns them into
// stretches of spans. An escape sequence never enters, which is what a ratatui
// paragraph would draw as literal bytes.
let mut parts = content_parts(&content, true, &resolved);
let mut block = vec![Cell::plain("\n")];
block.extend(history_cells(&history));
parts.push(BodyPart::Cells(block));
parts.push(BodyPart::Cells(vec![Cell::plain("\n")]));
let sections = detail_sections(&parts, &history_parts(&history));
Detail {
title: ticket.title.clone(),
id: ticket.id.clone(),
project: card.project.clone(),
body: detail_body(&parts),
sections,
}
}
/// The rendered body as lines of spans: the text split where it says, and each relation
/// row styled from the cells the CLI paints.
/// One piece of the overlay, from either source: the ticket's own body or the log.
///
/// A part that does not end on a newline runs on into the next one rather than closing a
/// line, so the seam between text and relations is wherever the body actually put it and
/// not wherever a part happened to end.
fn detail_body(parts: &[BodyPart]) -> Text<'static> {
/// A private fold over the two input shapes, so [`detail_sections`] takes one walk
/// instead of two that could disagree about where a quote begins and ends.
enum Piece {
Cells(Vec<Cell>),
Relations(Vec<RelationRow>),
Quoted(String),
}
/// The overlay as vertical sections.
///
/// Flow pieces accumulate exactly as the one text used to — an unterminated run runs on
/// into the next part, so the seam between text and relations is wherever the body put
/// it. A quoted piece closes what is open, banks it as its own flow section, and becomes
/// a quote section carrying the bare body: the bar is geometry the draw lays beside these
/// rows, which is what keeps it over every row the prose wraps onto.
///
/// The one newline after a quoted run is consumed rather than drawn. It used to close
/// the quote's last line; now the section boundary does that, and drawing the newline
/// would bank a blank row no entry ever had. History always writes exactly that cell
/// after a quote — a comment body and a reason alike — so consuming one leading newline
/// from the next flow piece is exact, not heuristic.
fn detail_sections(parts: &[BodyPart], history: &[HistoryPart]) -> Vec<DetailSection> {
let mut pieces: Vec<Piece> = parts
.iter()
.map(|part| match part {
BodyPart::Cells(cells) => Piece::Cells(cells.clone()),
BodyPart::Relations(rows) => Piece::Relations(rows.clone()),
})
.chain(history.iter().map(|part| match part {
HistoryPart::Flow(cells) => Piece::Cells(cells.clone()),
HistoryPart::Quoted(body) => Piece::Quoted(body.clone()),
}))
.collect();
let mut sections: Vec<DetailSection> = Vec::new();
let mut lines: Vec<Line<'static>> = Vec::new();
let mut open: Vec<Span<'static>> = Vec::new();
// Set while the previous section was a quote, so the next flow piece knows to give
// up the newline that closed the quote before sections existed.
let mut after_quote = false;
for part in parts {
match part {
BodyPart::Cells(cells) => {
for piece in pieces.drain(..) {
match piece {
Piece::Quoted(body) => {
if !open.is_empty() {
lines.push(Line::from(std::mem::take(&mut open)));
}
if !lines.is_empty() {
sections.push(DetailSection::Flow(Text::from(std::mem::take(&mut lines))));
}
sections.push(DetailSection::Quote(Text::from(
body.split('\n')
.map(|line| Line::from(span_from(line, None, None)))
.collect::<Vec<Line<'static>>>(),
)));
after_quote = true;
}
Piece::Cells(cells) => {
for cell in cells {
let mut rest = cell.text.as_str();
if after_quote && rest.starts_with('\n') {
after_quote = false;
rest = &rest[1..];
if rest.is_empty() {
continue;
}
}
while let Some((line, tail)) = rest.split_once('\n') {
if !line.is_empty() {
open.push(span_from(line, cell.color, cell.modifier));
@@ -2042,8 +2131,8 @@ fn detail_body(parts: &[BodyPart]) -> Text<'static> {
}
// One line each, from the same cells `render_relations` paints, so the block
// cannot read differently here than it does in `show`.
BodyPart::Relations(rows) => {
for row in relation_cells(rows) {
Piece::Relations(rows) => {
for row in relation_cells(&rows) {
open.extend(row.into_iter().map(span_of));
lines.push(Line::from(std::mem::take(&mut open)));
}
@@ -2054,8 +2143,11 @@ fn detail_body(parts: &[BodyPart]) -> Text<'static> {
if !open.is_empty() {
lines.push(Line::from(open));
}
if !lines.is_empty() {
sections.push(DetailSection::Flow(Text::from(lines)));
}
Text::from(lines)
sections
}
/// A cell as the board draws it: the same text in the same style, as a span.
@@ -3960,6 +4052,24 @@ fn last_offset(detail: &Text<'static>, text: Rect) -> u16 {
wrapped_height(detail, text.width).saturating_sub(text.height)
}
/// How tall the whole overlay is, section by section.
///
/// Each section wraps at its own width — a quote's body shares its row with the gutter —
/// and the total is what the clamp and the indicator are derived from. One measurement
/// per section by the same [`wrapped_height`], so the draw and the scroll cannot
/// disagree about where any of them ends.
fn detail_height(sections: &[DetailSection], width: u16) -> u16 {
sections
.iter()
.map(|section| wrapped_height(section.text(), section.width(width)))
.fold(0u16, |total, height| total.saturating_add(height))
}
/// The furthest the overlay scrolls: every section's wrapped height less the viewport.
fn detail_last_offset(sections: &[DetailSection], text: Rect) -> u16 {
detail_height(sections, text.width).saturating_sub(text.height)
}
/// The step `scroll_detail` takes, a screenful less the line kept for overlap.
///
/// The page numbers are counted in it rather than in whole screenfuls, so the pages the
@@ -4019,7 +4129,7 @@ fn draw_detail(frame: &mut Frame, detail: &Detail, offset: u16, area: Rect) {
// terminal may have been resized since, and a ticket read to its end can grow
// shorter under a tick. Which is also what repages the indicator, since the wrapped
// count and the viewport both move with the width.
let last = wrapped_height(&detail.body, text.width).saturating_sub(text.height);
let last = detail_last_offset(&detail.sections, text);
let offset = offset.min(last);
let mut block = Block::default()
@@ -4042,13 +4152,68 @@ fn draw_detail(frame: &mut Frame, detail: &Detail, offset: u16, area: Rect) {
}
frame.render_widget(Clear, overlay);
frame.render_widget(
Paragraph::new(detail.body.clone())
.block(block)
.wrap(Wrap { trim: false })
.scroll((offset, 0)),
overlay,
);
frame.render_widget(block, overlay);
// The sections stack into one scroll: `top` walks the virtual rows, each section is
// clipped to what the viewport still holds, and one straddling the top is scrolled
// within itself by however much of it is above. The bar of a quote rides in its own
// column, so scrolling never has to move it.
let mut top: u16 = 0;
for section in &detail.sections {
let height = wrapped_height(section.text(), section.width(text.width));
let bottom = top.saturating_add(height);
let visible = bottom > offset && top < offset.saturating_add(text.height);
if visible {
let within = offset.saturating_sub(top);
let y = text.y + top.max(offset) - offset;
let clip = Rect {
x: text.x,
y,
width: text.width,
height: text.bottom().saturating_sub(y),
};
match section {
DetailSection::Flow(body) => frame.render_widget(
Paragraph::new(body.clone())
.wrap(Wrap { trim: false })
.scroll((within, 0)),
clip,
),
DetailSection::Quote(body) => {
let [bars, prose] =
Layout::horizontal([Constraint::Length(GUTTER_WIDTH), Constraint::Min(0)])
.areas(clip);
frame.render_widget(gutter_bars(clip.height), bars);
frame.render_widget(
Paragraph::new(body.clone())
.wrap(Wrap { trim: false })
.scroll((within, 0)),
prose,
);
}
}
}
top = bottom;
if top >= offset.saturating_add(text.height) {
break;
}
}
}
/// The gutter beside a quoted run: the bar repeated down every row the run occupies.
///
/// Geometry rather than text, which is the whole point — a comment's prose wraps inside
/// the body column and cannot take the mark off any row, paragraph breaks included.
/// Grey, as chrome; [`QUOTE_BAR`] for the same reason the CLI prefixes with it, so both
/// renderers draw one glyph.
fn gutter_bars(height: u16) -> Text<'static> {
let bar = Span::styled(format!("{QUOTE_BAR} "), Style::default().fg(Color::Grey.into()));
Text::from(vec![Line::from(bar); height as usize])
}
/// The overlay's title: the short id and the name of the ticket it has open.
@@ -4188,6 +4353,24 @@ mod tests {
.collect()
}
/// The overlay's text rows, cut out of the drawn screen by the layout's own
/// geometry, right-trimmed so an assertion reads what is on it rather than its
/// padding.
fn overlay_text_rows(lines: &[String], width: u16, height: u16) -> Vec<String> {
let text = detail_text_area(Rect::new(0, 0, width, height));
lines[text.y as usize..(text.y + text.height) as usize]
.iter()
.map(|row| {
row.chars()
.skip(text.x as usize)
.take(text.width as usize)
.collect::<String>()
.trim_end()
.to_string()
})
.collect()
}
/// The column headings, which sit on the top border row.
///
/// That row alone, because the footer names done as well: a whole-screen search for
@@ -5493,11 +5676,105 @@ mod tests {
assert_eq!(span_color(&change, "claude"), Some(tag_color("claude").into()));
assert_eq!(span_color(&change, "2026-08-21 12:00:00"), Some(Color::Cyan.into()));
// The quote's rows carry no bar span any more — the bar is the gutter the draw
// lays beside them — so what says so on screen is a grey bar cell inside the
// overlay, distinct from the border's own verticals by its colour.
let said = body_line(detail, "And why.");
assert!(!said.spans.iter().any(|span| span.content.contains(QUOTE_BAR)));
// Held as text rather than through the borrow: the board is scrolled below.
let plain = detail.plain();
// The log ends the overlay, so the gutter is on the last page.
for _ in 0..20 {
board.scroll_detail(1, SCREEN);
}
let mut terminal = Terminal::new(TestBackend::new(SCREEN.width, SCREEN.height)).unwrap();
terminal.draw(|frame| draw(frame, &board)).unwrap();
let buffer = terminal.backend().buffer().clone();
let overlay = detail_overlay(Rect::new(0, 0, SCREEN.width, SCREEN.height));
let grey: ratatui::style::Color = Color::Grey.into();
let bars = (overlay.y..overlay.bottom())
.flat_map(|y| (overlay.x..overlay.right()).map(move |x| (x, y)))
.filter(|&(x, y)| {
let cell = &buffer[(x, y)];
cell.symbol() == QUOTE_BAR && cell.fg == grey
})
.count();
assert!(bars > 0, "no grey gutter bar reached the screen");
// The other half: the colour arrived as styles, not as bytes.
assert!(!plain.contains('\x1b'), "escapes reached the detail view: {plain:?}");
}
/// The bar is geometry over the rows a comment occupies, not text riding on each
/// stored line's first characters: the reported bug was that ratatui's word wrap
/// folds a long line onto continuation rows the prefix never reaches, so the quote
/// read as ending halfway through. Every drawn row of the run is asserted here,
/// wrapped continuations and the paragraph break included, and no row after it may
/// carry a bar either — a stray one would be a quote wider than its body.
#[test]
fn the_detail_view_draws_every_line_of_a_comment_behind_the_bar() {
let dir = board_dir();
let uuid = "11111111-0000-4000-8000-000000000000";
write_ticket(&dir, "backlog", uuid, "First one", "");
let history = crate::history::history_dir(&dir, uuid);
std::fs::create_dir_all(&history).unwrap();
// One stored line long enough to wrap onto several drawn rows, then a second
// paragraph behind its own break: the two ways the old shape lost the bar.
let long_line = "alpha bravo charlie delta echo foxtrot golf hotel india juliet \
kilo lima mike november oscar papa quebec romeo sierra tango uniform victor \
whiskey xray yankee zulu";
std::fs::write(
history.join("20260821_120000_000000_comment.md"),
format!(
"**Comment**\n{long_line}\n\nSecond paragraph.\n\n**Author**: bob\n**Time**: \
2026-08-21 12:00:00\n"
),
)
.unwrap();
let mut board = one_board(&dir);
board.toggle_detail();
// The log ends the overlay, so the last page is the one that holds the run.
for _ in 0..20 {
board.scroll_detail(1, SCREEN);
}
let screen = render(&board, SCREEN.width, SCREEN.height);
let rows = overlay_text_rows(&screen, SCREEN.width, SCREEN.height);
let header = rows
.iter()
.position(|row| row.starts_with("From bob"))
.expect("the comment's header is not on screen");
// The run: every row after the header up to the first one without a bar.
let mut at = header + 1;
while rows.get(at).is_some_and(|row| row.starts_with(QUOTE_BAR)) {
at += 1;
}
let run = header + 1..at;
assert!(
!detail.plain().contains('\x1b'),
"escapes reached the detail view: {:?}",
detail.plain()
run.len() >= 4,
"the fixture should wrap onto several rows, drew {run:?}:\n{rows:#?}"
);
// Nothing outside the run is quoted: no stray bar above or below the block.
assert!(
rows[at..].iter().all(|row| !row.contains(QUOTE_BAR)),
"a row past the comment carries a bar:\n{rows:#?}"
);
// The break sits inside the run as the bare glyph, and the second paragraph
// follows it behind the same bar.
assert!(
rows[run.clone()].iter().any(|row| row == QUOTE_BAR),
"no bare bar on the paragraph break:\n{rows:#?}"
);
assert!(
rows[run].iter().any(|row| row.starts_with("│ Second")),
"the second paragraph lost the bar:\n{rows:#?}"
);
}
@@ -5523,10 +5800,27 @@ mod tests {
board.toggle_detail();
let plain = board.detail.as_ref().expect("no detail").plain();
let expected = "status reviewing → backlog claude (2026-08-21 12:00:00)\n sent back, wrong \
approach";
// The reason is its own quoted stretch under the row it explains; its rows carry
// no bar in the text, since on screen the bar is the gutter beside them.
let expected = "status reviewing → backlog claude (2026-08-21 12:00:00)\nsent back, wrong \
approach";
assert!(plain.contains(expected), "{plain}");
assert!(!plain.contains('\x1b'), "escapes reached the detail view: {plain:?}");
assert!(!plain.contains(QUOTE_BAR), "the bar reached the text: {plain:?}");
// And on screen the bar stands beside it, once the log is scrolled into view.
for _ in 0..20 {
board.scroll_detail(1, SCREEN);
}
let screen = render(&board, SCREEN.width, SCREEN.height);
let rows = overlay_text_rows(&screen, SCREEN.width, SCREEN.height);
let status = rows
.iter()
.position(|row| row.starts_with("status "))
.expect("the mechanical row is not on screen");
assert!(
rows[status + 1].starts_with(&format!("{QUOTE_BAR} sent back")),
"the reason did not draw behind the bar:\n{rows:#?}"
);
}
/// The reported bug: the modal showed a description, criteria and a metadata
@@ -7386,7 +7680,7 @@ mod tests {
board.toggle_detail();
let area = detail_text_area(Rect::new(0, 0, SCREEN.width, SCREEN.height));
let last = last_offset(&board.detail.as_ref().unwrap().body, area);
let last = detail_last_offset(&board.detail.as_ref().unwrap().sections, area);
assert!(last > 0, "the fixture fits on one screen, so nothing is measured");
// Far past the end, so the clamp is what stops it.
@@ -7412,9 +7706,9 @@ mod tests {
/// is drawn in rather than reading the flattened text.
fn body_line(detail: &Detail, needle: &str) -> Line<'static> {
detail
.body
.lines
.sections
.iter()
.flat_map(|section| section.text().lines.iter())
.find(|line| {
line.spans
.iter()
@@ -7768,7 +8062,7 @@ mod tests {
}
let text = detail_text_area(Rect::new(0, 0, SCREEN.width, SCREEN.height));
let last = last_offset(&board.detail.as_ref().unwrap().body, text);
let last = detail_last_offset(&board.detail.as_ref().unwrap().sections, text);
assert_eq!(board.offset, last, "the fixture did not reach the end");
let screen = render(&board, SCREEN.width, SCREEN.height);
@@ -7800,7 +8094,7 @@ mod tests {
let text = detail_text_area(Rect::new(0, 0, width, height));
assert_eq!(
last_offset(&board.detail.as_ref().unwrap().body, text),
detail_last_offset(&board.detail.as_ref().unwrap().sections, text),
0,
"the fixture scrolls, so it proves nothing"
);
+84 -11
View File
@@ -1514,6 +1514,17 @@ const METADATA_ORDER: [&str; 13] = [
"Status",
];
/// What is being written, for the messages a failure carries.
///
/// A `&str` naming the thing rather than two copies of every message that names its
/// object: a campaign file is a ticket file in every way that matters here,
/// `<uuid>_<slug>.md` in a directory, and the only difference is the word a failure has
/// to use. Every message below puts it mid-sentence so there is no capital to case.
/// Lived in the handlers until the writers here started carrying the noun too; both
/// sides read these through one definition so the words cannot drift apart.
pub const TICKET: &str = "ticket";
pub const CAMPAIGN: &str = "campaign";
/// Rewrite a metadata field, adding the line when the file has no such field yet.
///
/// [`set_metadata_field`] refuses a field that is not already there, which is right for
@@ -1526,6 +1537,7 @@ pub fn set_or_insert_metadata_field(
content: &str,
field: &str,
value: &str,
noun: &str,
title: &str,
) -> Result<String> {
let prefix = format!("**{}**:", field);
@@ -1534,7 +1546,7 @@ pub fn set_or_insert_metadata_field(
metadata_field_body(line).starts_with(&prefix)
}) {
Some(updated) => Ok(updated),
None => insert_metadata_field(content, field, value, title),
None => insert_metadata_field(content, field, value, noun, title),
}
}
@@ -1543,14 +1555,26 @@ pub fn set_or_insert_metadata_field(
/// A file with no Metadata section is an error rather than an insertion. There is no
/// format to guess at there, and per 641e3d5 such a file has no fields at all, so
/// writing one above the prose would be inventing a shape nothing else reads.
fn insert_metadata_field(content: &str, field: &str, value: &str, title: &str) -> Result<String> {
///
/// The noun travels with the call rather than being spelled here, because both a ticket
/// and a campaign reach this: `campaign set --codename` inserts into a campaign, and
/// "Ticket 'v1 release' has no Metadata section" would be wrong about the one file it
/// names.
fn insert_metadata_field(
content: &str,
field: &str,
value: &str,
noun: &str,
title: &str,
) -> Result<String> {
let lines: Vec<&str> = content.lines().collect();
let heading = lines
.iter()
.position(|line| is_metadata_heading(line))
.ok_or_else(|| {
anyhow!(
"Ticket '{}' has no Metadata section, so its {} field cannot be written",
"There is no Metadata section on {} '{}', so its {} field cannot be written",
noun,
title,
field
)
@@ -1640,7 +1664,7 @@ pub fn set_status_stamp(content: &str, target: Status, now: &str, title: &str) -
match target.stamp_field() {
// Inserted on demand, the way Campaign is: every ticket written before these
// fields existed carries none of them.
Some(field) => set_or_insert_metadata_field(&content, field, now, title),
Some(field) => set_or_insert_metadata_field(&content, field, now, TICKET, title),
None => Ok(content),
}
}
@@ -1648,7 +1672,10 @@ pub fn set_status_stamp(content: &str, target: Status, now: &str, title: &str) -
/// Rewrite the title heading, the first `# ` line in the file.
///
/// `## ` headings do not match: the second character has to be a space.
pub fn set_title(content: &str, title: &str) -> Result<String> {
///
/// The noun travels with the call for the same reason [`insert_metadata_field`] carries
/// one: `campaign set --title` rewrites a campaign's heading too.
pub fn set_title(content: &str, title: &str, noun: &str) -> Result<String> {
let mut updated = String::with_capacity(content.len());
let mut found = false;
@@ -1664,7 +1691,7 @@ pub fn set_title(content: &str, title: &str) -> Result<String> {
}
if !found {
return Err(anyhow!("Ticket '{}' has no title heading", title));
return Err(anyhow!("There is no title heading on {} '{}'", noun, title));
}
Ok(updated)
@@ -2552,6 +2579,51 @@ impl Cell {
}
}
/// The bar a quoted run draws behind, the way quoted text is drawn.
///
/// Box-drawing vertical, the family the rule under HISTORY is already rendered from, so
/// it shows wherever that does. One cell wide, grey, and clear of the two vocabularies
/// it sits among: the priority meter owns the circles and the dot and the relation rows
/// own the cross and the arrows, so nothing here may read as a level or as an edge.
/// Grey is the colour chrome takes everywhere else, which names its row rather than
/// holding a value — what a quote bar does. It lives beside [`Cell`] rather than in
/// `history.rs`, because the CLI prefixes stored lines with it while the board paints it
/// as a gutter column, and a glyph two renderers draw is a glyph the palette owns.
pub const QUOTE_BAR: &str = "\u{2502}";
/// One run of text behind [`QUOTE_BAR`], every stored line of it.
///
/// This is the CLI's shape of a quote: the bar rides on each line's first characters,
/// and a line the terminal soft-wraps continues without one, because a pipe has no width
/// to honour. The board quotes the same runs as geometry instead — a gutter column the
/// bar fills top to bottom — which is what keeps a wrapped row under the mark there.
/// With colour off the glyph goes but the width it occupied stays, as plain spaces
/// derived from the drawn form rather than spelled beside it, so a piped `show` keeps
/// every line at the same column without carrying an escape byte.
pub fn quoted_cells(body: &str, colored: bool) -> Vec<Cell> {
let bar = format!("{QUOTE_BAR} ");
let indent = " ".repeat(bar.chars().count());
let mut cells = Vec::new();
for (at, line) in body.split('\n').enumerate() {
if at > 0 {
cells.push(Cell::plain("\n"));
}
match (colored, line.is_empty()) {
// A paragraph break draws the bar alone rather than carrying a gap into
// nothing, which is what keeps it visibly inside the run.
(true, true) => cells.push(Cell::colored(QUOTE_BAR, Color::Grey)),
(true, false) => {
cells.push(Cell::colored(&bar, Color::Grey));
cells.push(Cell::plain(line));
}
(false, false) => cells.push(Cell::plain(format!("{indent}{line}"))),
(false, true) => {}
}
}
cells
}
/// The relations of one ticket, both directions, in the order they are shown.
///
/// Stored first: the relations the ticket holds, then the ones held against it, named
@@ -4162,7 +4234,7 @@ mod tests {
let content = with_metadata("- **ID**: abc\n- **Owner**: alice\n- **Status**: backlog\n");
let updated =
set_or_insert_metadata_field(&content, CAMPAIGN_FIELD, "c-uuid", "T").unwrap();
set_or_insert_metadata_field(&content, CAMPAIGN_FIELD, "c-uuid", TICKET, "T").unwrap();
// Against METADATA_ORDER, so Status stays last where every file keeps it.
assert!(
@@ -4179,7 +4251,7 @@ mod tests {
let content = with_metadata("- **ID**: abc\n- **Owner**: alice\n\n## Notes\nAfter.\n");
let updated =
set_or_insert_metadata_field(&content, CAMPAIGN_FIELD, "c-uuid", "T").unwrap();
set_or_insert_metadata_field(&content, CAMPAIGN_FIELD, "c-uuid", TICKET, "T").unwrap();
assert!(
updated.contains("- **Owner**: alice\n- **Campaign**: c-uuid\n\n## Notes\nAfter.\n"),
@@ -4195,7 +4267,7 @@ mod tests {
with_metadata("- **ID**: abc\n- **Campaign**: first\n- **Status**: backlog\n");
let updated =
set_or_insert_metadata_field(&content, CAMPAIGN_FIELD, "second", "T").unwrap();
set_or_insert_metadata_field(&content, CAMPAIGN_FIELD, "second", TICKET, "T").unwrap();
assert_eq!(updated.matches("**Campaign**:").count(), 1, "{updated}");
assert!(updated.contains("- **Campaign**: second"), "{updated}");
@@ -4208,7 +4280,8 @@ mod tests {
let content = "# T\n\n## Description\n- **Campaign**: not a field\n\n\
## Metadata\n\n- **ID**: abc\n- **Status**: backlog\n";
let updated = set_or_insert_metadata_field(content, CAMPAIGN_FIELD, "c-uuid", "T").unwrap();
let updated =
set_or_insert_metadata_field(content, CAMPAIGN_FIELD, "c-uuid", TICKET, "T").unwrap();
assert!(updated.contains("- **Campaign**: not a field"), "{updated}");
assert!(
@@ -4223,7 +4296,7 @@ mod tests {
fn a_file_with_no_metadata_section_is_an_error_rather_than_an_insertion() {
let content = "# T\n\n## Description\nBody.\n";
let error = set_or_insert_metadata_field(content, CAMPAIGN_FIELD, "c-uuid", "T")
let error = set_or_insert_metadata_field(content, CAMPAIGN_FIELD, "c-uuid", TICKET, "T")
.expect_err("a file with no Metadata section gained a field");
assert!(error.to_string().contains("no Metadata section"), "{error}");
+88
View File
@@ -1145,6 +1145,94 @@ fn mv_does_not_restamp_a_no_op_move() {
assert_eq!(ticket_at(&worklane, "committed", &filename), before);
}
/// A ticket whose file sits in one status directory while its Status field says another
/// is a hand-moved file or a partial restore. Moving it to the status it already sits in
/// is the repair: the field is rewritten to agree with the directory and reported as a
/// correction rather than refused as a no-op.
#[test]
fn mv_repairs_a_lagging_status_field_instead_of_refusing() {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
let filename = stamped_ticket(&worklane, "done");
let drifted = ticket_at(&worklane, "done", &filename)
.replace("- **Status**: done", "- **Status**: backlog");
fs::write(worklane.join("done").join(&filename), &drifted).unwrap();
let out = move_ticket(&temp, "cccc3333", "done", false);
let stderr = String::from_utf8_lossy(&out.stderr);
assert!(out.status.success(), "{stderr}");
let stdout = String::from_utf8_lossy(&out.stdout);
assert!(stdout.contains("Corrected Status field"), "{stdout}");
assert!(stdout.contains("backlog"), "{stdout}");
// Not a move: nothing was relocated and only the field changed, byte for byte.
assert!(worklane.join("done").join(&filename).exists());
assert_eq!(md_files(&worklane.join("backlog")), Vec::<String>::new());
assert_eq!(
ticket_at(&worklane, "done", &filename),
drifted.replace("- **Status**: backlog", "- **Status**: done")
);
}
/// The repair corrects bookkeeping rather than moving work, so it stamps nothing and
/// logs nothing: an entry shaped like a transition would record a journey the ticket
/// never took.
#[test]
fn a_repair_writes_no_stamp_and_no_history_entry() {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
let filename = stamped_ticket(&worklane, "backlog");
// A real move first, so the ticket carries the stamp and the log entry that a
// repair has to leave alone.
let out = move_ticket(&temp, "cccc3333", "committed", false);
assert!(out.status.success(), "{}", String::from_utf8_lossy(&out.stderr));
let history = worklane
.join("history")
.join("cccc3333cccc3333cccc3333cccc3333cccc");
assert_eq!(md_files(&history).len(), 1);
let content = ticket_at(&worklane, "committed", &filename);
assert!(content.contains("Committed On"), "{content}");
let drifted = content.replace("- **Status**: committed", "- **Status**: done");
fs::write(worklane.join("committed").join(&filename), &drifted).unwrap();
let out = move_ticket(&temp, "cccc3333", "committed", false);
assert!(out.status.success(), "{}", String::from_utf8_lossy(&out.stderr));
let repaired = ticket_at(&worklane, "committed", &filename);
assert!(repaired.contains("Committed On"), "{repaired}");
assert!(!repaired.contains("Submitted On"), "{repaired}");
assert_eq!(md_files(&history).len(), 1, "the repair logged an entry");
}
/// The mirror drift, a field ahead of its directory from a crash mid-move, repairs the
/// same way when the caller keeps the ticket where it sits rather than moving it on to
/// where the field claims.
#[test]
fn mv_repairs_a_field_ahead_of_its_directory_too() {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
let filename = stamped_ticket(&worklane, "backlog");
let drifted = ticket_at(&worklane, "backlog", &filename)
.replace("- **Status**: backlog", "- **Status**: done");
fs::write(worklane.join("backlog").join(&filename), &drifted).unwrap();
let out = move_ticket(&temp, "cccc3333", "backlog", false);
let stderr = String::from_utf8_lossy(&out.stderr);
assert!(out.status.success(), "{stderr}");
let stdout = String::from_utf8_lossy(&out.stdout);
assert!(stdout.contains("Corrected Status field"), "{stdout}");
assert!(worklane.join("backlog").join(&filename).exists());
assert!(
ticket_at(&worklane, "backlog", &filename).contains("- **Status**: backlog"),
"{}",
ticket_at(&worklane, "backlog", &filename)
);
}
// ---------------------------------------------------------------- discarded --
/// Discarding is not a stage of work, so it is reachable from wherever the ticket
+65
View File
@@ -316,6 +316,71 @@ fn an_annotation_that_would_read_as_a_heading_is_refused() {
assert!(!temp.path().join(".worklane").join("tags.md").exists());
}
/// A tab anywhere in an annotation is refused by `tags add`, because the listing's fields
/// are tab separated: past the first tab everything after it reads as a fourth field. The
/// refusal says why, and nothing is written — the value parser refuses before the handler
/// runs, so not even a placeholder file is left behind.
#[test]
fn an_annotation_carrying_a_tab_is_refused_by_tags_add() {
let temp = TempDir::new().unwrap();
setup_worklane(&temp);
let out = run(&temp, &["tags", "add", "bug", "-a", "Something\twrong."]);
let stderr = String::from_utf8_lossy(&out.stderr);
assert!(!out.status.success(), "{stderr}");
assert!(
stderr.contains("tab") && stderr.contains("separates its fields"),
"{stderr}"
);
assert!(!temp.path().join(".worklane").join("tags.md").exists());
// No staged write survived either, so the directory holds only the status folders.
let left: Vec<_> = fs::read_dir(temp.path().join(".worklane"))
.unwrap()
.map(|e| e.unwrap().file_name())
.collect();
assert_eq!(left.len(), 4, "{left:?}");
}
/// The same value is refused by `tags set`, and the declaration that is already there is
/// untouched.
#[test]
fn an_annotation_carrying_a_tab_is_refused_by_tags_set() {
let temp = TempDir::new().unwrap();
setup_worklane(&temp);
run(&temp, &["tags", "add", "bug", "-a", "Something wrong."]);
let before = vocabulary(&temp);
let out = run(&temp, &["tags", "set", "bug", "-a", "Now\twith a tab."]);
assert!(!out.status.success(), "{}", String::from_utf8_lossy(&out.stderr));
assert_eq!(vocabulary(&temp), before);
}
/// Ordinary prose is unaffected, paragraphs included: the refusal is for the tab alone,
/// which is what keeps it from standing in front of the command's whole purpose.
#[test]
fn an_annotation_without_a_tab_is_taken_whatever_its_shape() {
let temp = TempDir::new().unwrap();
setup_worklane(&temp);
run(
&temp,
&[
"tags",
"add",
"bug",
"-a",
"A defect.",
"-a",
"",
"-a",
"--plan is prose",
],
);
assert_eq!(declared(&temp, "bug").as_deref(), Some("A defect.\n\n--plan is prose"));
}
/// The file is made on demand, the way `campaign add` makes the campaigns directory: a board
/// that predates the vocabulary must not need `worklane init` run over it.
#[test]