Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
96cddc14ad |
@@ -1,7 +1,7 @@
|
||||
# AGENTS.md
|
||||
|
||||
## Project Structure
|
||||
- `src/main.rs` - dispatch, the SIGPIPE reset, and the TUI event loop
|
||||
- `src/main.rs` - `dispatch`, the one mapping from a parsed command to its handler, the SIGPIPE reset, and the TUI event loop
|
||||
- `src/command.rs` - CLI argument definitions using clap derive
|
||||
- `src/completions.rs` - the generated completion script and the fish half that asks the board
|
||||
- `src/handlers.rs` - one `cmd_*` per subcommand
|
||||
@@ -353,15 +353,22 @@ and this file is for what someone changing worklane's own code needs.
|
||||
|
||||
### The Command Prompt
|
||||
- **`prompt: Option<Prompt>` is the whole mode**, the shape `search` and `detail` use: open and content cannot disagree, and closing it leaves nothing to reset. `Prompt` carries the line, the cursor as a byte offset into it, and `refused`, which is `Search::missed` with something to say
|
||||
- **`Board::prompt_key` is third in the pre-dispatch**, beside `search_key` and `picker_key` and on the same contract: while a command is being typed `q` is a letter, `d` leaves the columns alone and `tab` stays out of the project tabs, and `ctrl-c` is the one key declined. It takes no `Size`, because nothing it does measures the board — the keypress that will is 53ffb94, which redraws on what the command wrote. Only one of the two prompts can be open at once: `:` is reachable from the action arms alone, and while either has the keyboard the other's key is a character in a line
|
||||
- **`Board::prompt_key` is third in the pre-dispatch**, beside `search_key` and `picker_key` and on the same contract: while a command is being typed `q` is a letter, `d` leaves the columns alone and `tab` stays out of the project tabs, and `ctrl-c` is the one key declined. It takes a `Size` for enter's sake: running a command reloads the board and then has to bring the ticket it moved back into view, which is the measurement `follow_selection` takes. Only one of the two prompts can be open at once: `:` is reachable from the action arms alone, and while either has the keyboard the other's key is a character in a line
|
||||
- **`esc` and `enter` are the mode's own keys and are answered in `prompt_key`; everything else belongs to the line and goes to `Prompt::key`.** That is also what keeps the borrow straight, since closing the prompt takes the whole board and editing takes only the prompt. Left, right, home, end, backspace and `ctrl-w` behave as they do in a shell, and `ctrl-w` eats the separators behind the cursor before the word behind those, so one press at the end of `mv 1b78a24 ` takes the id. There is deliberately no `tab`: suggesting the selected ticket is 00a14e7, and until then it is a key that must not reach the tabs
|
||||
- **The grammar is clap's, with nothing restated.** The line is tokenised by `split_line`, the binary's own name goes in front, and the arguments go to the same `Cli` definition the shell reaches, so a flag added to a command is typeable here the day it is added. Through `Cli::command().try_get_matches_from_mut` rather than `try_parse_from`, for what the matches give back: `command_name` walks the subcommands to name what resolved (`campaign show`, not `campaign`) instead of a `match` over every variant, which would be a second list of every verb the CLI has and one that goes stale silently
|
||||
- **`refused` is cleared by an edit and not by a movement.** The message is about the line, and moving the cursor does not change the line. `Prompt::key` clears it in the three arms that write to the line
|
||||
- **A line that ends inside a quote never reaches clap.** That is what `Unclosed` is for: a grammar complaint about a sentence nobody finished describes the wrong thing. Enter on an empty line, or one of nothing but separators, closes the prompt with nothing said, the way `esc` does — the bare form of the CLI opens a board and there is one on the screen
|
||||
- **Enter resolves the line and does not run it**, so the notice says `parsed, not run yet` rather than reading like a move that happened, and the prompt's own key is drawn as `↵ check`. Both are replaced by 53ffb94, which is the ticket that runs it; naming the key `run` here would be the fault 1b78a24 was, in the other direction
|
||||
- **Enter runs it, through `main.rs`'s `dispatch` and never through a handler this file names.** That match is the one mapping from a parsed command to the function that performs it: `main` calls it with its own stdout and the working directory, `Board::run` calls it with a buffer and the selected tab's root. A second copy inside `tui.rs` would drift the first time a command was added, and it would drift *silently*, since both halves go on compiling. The match is exhaustive so a new verb cannot fall into an `_` arm and do nothing, and `main_and_the_prompt_run_one_dispatch_table` reads both files as text to pin it. Only `tui` is matched outside the table, in `main`, because the board is that table's caller rather than an entry in it; reached from the prompt it is refused in those words
|
||||
- **`from_arg_matches` on the same matches gives `run` the typed values.** One parse, two readings: `command_name` walks the subcommands to name what resolved and `from_arg_matches` reconstructs the `Cli`. A `match` over every `Command` variant to get one or the other would be a second list of every verb the CLI has
|
||||
- **The handler's own words are what the board reports, word for word.** Those messages are written for a person already, and a second set kept here would go stale the first time one of them changed. The sink is a buffer, so the words come back as text and the board styles them; it is plain for the same reason `Detail` holds spans, since a ratatui paragraph prints an escape rather than obeying it. An error never goes through a sink at all — `color_text` asks the *process* about its stdout, which under the board answers yes about a terminal the message is not going to — so `error_lines` runs `without_escapes` over it and puts each cause on a line of its own
|
||||
- **A handler that errors leaves the prompt open with the line intact.** The usual cause is an ambiguous id, and the fix is two more characters rather than the whole line retyped from `:`. Ambiguity is an `Err` carrying the candidates, not a print and an `exit`, which is what makes it safe to reach from here at all
|
||||
- **The reload after a command is unconditional, and runs whether it failed or not.** `tick` reloads on the digest, which is right for a change made in another pane and needless latency for one the board just made: the reader would watch their own `mv` take up to a poll interval to appear. Either way, because a handler that failed part way through has still written
|
||||
- **The selection is restored by uuid across that reload, never by index.** `mv` puts the card in another column, `set --title` renames its file, and a filter can drop it out of view entirely, so the slot is not the ticket. `Board::reselect` has three answers: the card is in a drawn column and the selection goes to it; it is on the board but in a column the rotation is hiding, which is where `--status done` lands by default, so the notice says where it went and which key shows it; or the filter no longer holds it, which is said too, since a card vanishing from under the highlight reads as a bug in the board
|
||||
- **The merge tab is refused, for now.** It is the one tab that is not a board — its cards came from several `.worklane` directories and it is none of them — so `Board::current_project` answers `None` there and the command is refused rather than landing on whichever project came first. Routing by the card a command names is ebc5755. The project is resolved by index and not by the tab's name, which is a label two projects can share: e1d79c3 is exactly that, and a write routed by name would be that bug with a file changing at the end of it
|
||||
- **`Notice` holds as many lines as the command used, and `Board::notice_on_row` decides where they go.** One line with nothing else holding the row draws on the footer, where a copy's notice has always drawn. Anything else — several lines, or any answer at all while the prompt is still open on an error — draws as a box at the foot of the columns, cut to what the columns leave with the dropped count on its last row. A box rather than more rows of footer, and that is the whole reason it is an overlay: a footer that grew and shrank as notices came and went would reflow the columns on every keypress, moving every card the reader is looking at. `draw` and `draw_footer` both ask `notice_on_row`, so the two cannot come to disagree and draw the message twice or not at all
|
||||
- **What a refused line shows is clap's own message with the usage block cut off**, which is also what drops the `--help` line after it. `--help` is the exception: it parses as an error of the kind that means *print this* and what it would print is a page, so it is caught and answered in a row's worth of words, or clap's help lands on the alternate screen the way an unsunk `println!` would. `--version` goes through the ordinary path, because what it prints is one line by construction. `ColorChoice::Never` on the command, so nothing that reaches the row carries an escape
|
||||
- **The keys' width comes off the row before the line is windowed**, so a long command does not push them off the end; a message takes the row from the keys instead, since the reader has just been told something and `esc` and `enter` still do what they did. `prompt_window` anchors the window on the cursor's right edge, which costs the text *after* the cursor on a long line: keeping both ends needs a scroll offset in state, and the draw is where the width is known and the state is not writable
|
||||
- `: command` is named in every footer state, because the key works in every one of them
|
||||
- `: command` is named in every footer state, because the key works in every one of them, and the prompt's own key is drawn as `↵ run`
|
||||
|
||||
### Splitting a Typed Line
|
||||
- **`split_line` is the whole module, and it knows nothing about `Board`.** The command prompt reads one string and clap reads an argv, so `comment 1b78a24 the offset was never passed` has to be tokenised before anything can parse it: split on whitespace it is five arguments and `comment` takes two. A pure function over the line and the cursor is what makes every rule reachable from a unit test, and it is in a file of its own rather than in `tui.rs`, which is eleven thousand lines already
|
||||
|
||||
Generated
+1
-1
@@ -1503,7 +1503,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "worklane"
|
||||
version = "0.32.15"
|
||||
version = "0.32.16"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"assert_cmd",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "worklane"
|
||||
version = "0.32.15"
|
||||
version = "0.32.16"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
|
||||
+99
-69
@@ -1,3 +1,5 @@
|
||||
use std::path::Path;
|
||||
|
||||
use anyhow::Result;
|
||||
use clap::Parser;
|
||||
|
||||
@@ -50,76 +52,16 @@ fn main() -> Result<()> {
|
||||
let mut sink = Sink::std();
|
||||
|
||||
let result = match cli.command {
|
||||
// The board is the one thing `dispatch` does not run, and it is matched here
|
||||
// rather than there because it is the *caller* of that table rather than an entry
|
||||
// in it: a `tui` reached from the command prompt would enter the alternate screen
|
||||
// a second time from inside the draw loop. `dispatch` refuses it in those words.
|
||||
//
|
||||
// No subcommand opens the board, the way a bare `frig` does, and with no path
|
||||
// it opens the board above the working directory.
|
||||
None => run_tui(&[], &start),
|
||||
Some(Command::Tui { paths }) => run_tui(&paths, &start),
|
||||
Some(Command::Init) => cmd_init(&start, &mut sink),
|
||||
Some(Command::Add(args)) => cmd_add(&args, &start, &mut sink),
|
||||
Some(Command::Ls(args)) => {
|
||||
let worklane_dir = find_worklane_dir(&start)?;
|
||||
cmd_ls(&args, &worklane_dir, &mut sink)
|
||||
}
|
||||
Some(Command::Show { id }) => {
|
||||
let worklane_dir = find_worklane_dir(&start)?;
|
||||
cmd_show(&id, &worklane_dir, &mut sink)
|
||||
}
|
||||
Some(Command::Mv(args)) => cmd_mv(&args, &start, &mut sink),
|
||||
Some(Command::Set(args)) => cmd_set(&args, &start, &mut sink),
|
||||
Some(Command::Append(args)) => cmd_append(&args, &start, &mut sink),
|
||||
Some(Command::Relate(args)) => cmd_relate(&args, &start, &mut sink),
|
||||
Some(Command::Chown(args)) => cmd_chown(&args, &start, &mut sink),
|
||||
Some(Command::Check(args)) => cmd_check(&args, true, &start, &mut sink),
|
||||
Some(Command::Uncheck(args)) => cmd_check(&args, false, &start, &mut sink),
|
||||
Some(Command::Comment {
|
||||
ticket,
|
||||
body,
|
||||
actor,
|
||||
actor_from_git,
|
||||
}) => cmd_comment(&ticket, &body, &actor, actor_from_git, &start, &mut sink),
|
||||
Some(Command::Campaign { command }) => match command {
|
||||
CampaignCommand::Add(args) => cmd_campaign_add(&args, &start, &mut sink),
|
||||
CampaignCommand::Ls { ids } => {
|
||||
let worklane_dir = find_worklane_dir(&start)?;
|
||||
cmd_campaign_ls(&worklane_dir, ids, &mut sink)
|
||||
}
|
||||
CampaignCommand::Set(args) => cmd_campaign_set(&args, &start, &mut sink),
|
||||
CampaignCommand::Append(args) => cmd_campaign_append(&args, &start, &mut sink),
|
||||
CampaignCommand::Show { campaign } => {
|
||||
let worklane_dir = find_worklane_dir(&start)?;
|
||||
cmd_campaign_show(&campaign, &worklane_dir, &mut sink)
|
||||
}
|
||||
},
|
||||
Some(Command::Assign {
|
||||
campaign,
|
||||
ticket,
|
||||
actor,
|
||||
actor_from_git,
|
||||
}) => cmd_assign(&campaign, &ticket, &actor, actor_from_git, &start, &mut sink),
|
||||
// The bare form and `ls` are one arm: `worklane tags` was the listing before the
|
||||
// group existed and the fish completion still calls it that way, so the two
|
||||
// spellings cannot be allowed to drift into two behaviours.
|
||||
Some(Command::Tags { command }) => match command {
|
||||
None | Some(TagCommand::Ls) => {
|
||||
let worklane_dir = find_worklane_dir(&start)?;
|
||||
cmd_tags(&worklane_dir, &mut sink)
|
||||
}
|
||||
Some(TagCommand::Add(args)) => cmd_tag_add(&args, &start, &mut sink),
|
||||
Some(TagCommand::Set(args)) => cmd_tag_set(&args, &start, &mut sink),
|
||||
},
|
||||
// No board either, for the reason `install-skill` has none: a completion script
|
||||
// is generated from the clap definition and is the same wherever it is run.
|
||||
Some(Command::Completions { shell }) => {
|
||||
completions::generate(shell, sink.as_write()).map_err(Into::into)
|
||||
}
|
||||
// No board is looked for: the point of the skill is to teach an agent worklane
|
||||
// before there is a `.worklane` anywhere.
|
||||
Some(Command::InstallSkill { skill, force, print }) => {
|
||||
cmd_install_skill(skill.as_deref(), force, print, &mut sink)
|
||||
}
|
||||
// No board either, and one agent rather than both: opencode loads the tool file,
|
||||
// Claude Code has no path for one.
|
||||
Some(Command::InstallTool { force, print }) => cmd_install_tool(force, print, &mut sink),
|
||||
Some(command) => dispatch(&command, &start, &mut sink),
|
||||
};
|
||||
|
||||
// The board (and every handler) own their own writing, so flush what the last one
|
||||
@@ -128,6 +70,93 @@ fn main() -> Result<()> {
|
||||
result
|
||||
}
|
||||
|
||||
/// Run one parsed command against the board at or above `start`, saying what it did
|
||||
/// through `sink`.
|
||||
///
|
||||
/// **The one mapping from a parsed command to the function that performs it.** `main`
|
||||
/// calls it with the process's stdout and the working directory; the command prompt on
|
||||
/// the board calls it with a buffer and the selected tab's own root, and reads back what
|
||||
/// the handler said. A second copy of this match inside `tui.rs` would be a copy that
|
||||
/// drifted the first time a command was added, and it would drift *silently*, since both
|
||||
/// halves would go on compiling.
|
||||
///
|
||||
/// A command added to [`Command`] therefore lands here once and is runnable from both.
|
||||
/// The match is exhaustive for exactly that reason: there is no `_` arm for a new verb to
|
||||
/// fall into and do nothing.
|
||||
pub fn dispatch(command: &Command, start: &Path, sink: &mut Sink) -> Result<()> {
|
||||
match command {
|
||||
// Reachable only from the prompt, since `main` takes this arm before it gets
|
||||
// here. A board is not something a board can open.
|
||||
Command::Tui { .. } => Err(anyhow::anyhow!("`tui` opens a board, and you are on one")),
|
||||
Command::Init => cmd_init(start, sink),
|
||||
Command::Add(args) => cmd_add(args, start, sink),
|
||||
Command::Ls(args) => {
|
||||
let worklane_dir = find_worklane_dir(start)?;
|
||||
cmd_ls(args, &worklane_dir, sink)
|
||||
}
|
||||
Command::Show { id } => {
|
||||
let worklane_dir = find_worklane_dir(start)?;
|
||||
cmd_show(id, &worklane_dir, sink)
|
||||
}
|
||||
Command::Mv(args) => cmd_mv(args, start, sink),
|
||||
Command::Set(args) => cmd_set(args, start, sink),
|
||||
Command::Append(args) => cmd_append(args, start, sink),
|
||||
Command::Relate(args) => cmd_relate(args, start, sink),
|
||||
Command::Chown(args) => cmd_chown(args, start, sink),
|
||||
Command::Check(args) => cmd_check(args, true, start, sink),
|
||||
Command::Uncheck(args) => cmd_check(args, false, start, sink),
|
||||
Command::Comment {
|
||||
ticket,
|
||||
body,
|
||||
actor,
|
||||
actor_from_git,
|
||||
} => cmd_comment(ticket, body, actor, *actor_from_git, start, sink),
|
||||
Command::Campaign { command } => match command {
|
||||
CampaignCommand::Add(args) => cmd_campaign_add(args, start, sink),
|
||||
CampaignCommand::Ls { ids } => {
|
||||
let worklane_dir = find_worklane_dir(start)?;
|
||||
cmd_campaign_ls(&worklane_dir, *ids, sink)
|
||||
}
|
||||
CampaignCommand::Set(args) => cmd_campaign_set(args, start, sink),
|
||||
CampaignCommand::Append(args) => cmd_campaign_append(args, start, sink),
|
||||
CampaignCommand::Show { campaign } => {
|
||||
let worklane_dir = find_worklane_dir(start)?;
|
||||
cmd_campaign_show(campaign, &worklane_dir, sink)
|
||||
}
|
||||
},
|
||||
Command::Assign {
|
||||
campaign,
|
||||
ticket,
|
||||
actor,
|
||||
actor_from_git,
|
||||
} => cmd_assign(campaign, ticket, actor, *actor_from_git, start, sink),
|
||||
// The bare form and `ls` are one arm: `worklane tags` was the listing before the
|
||||
// group existed and the fish completion still calls it that way, so the two
|
||||
// spellings cannot be allowed to drift into two behaviours.
|
||||
Command::Tags { command } => match command {
|
||||
None | Some(TagCommand::Ls) => {
|
||||
let worklane_dir = find_worklane_dir(start)?;
|
||||
cmd_tags(&worklane_dir, sink)
|
||||
}
|
||||
Some(TagCommand::Add(args)) => cmd_tag_add(args, start, sink),
|
||||
Some(TagCommand::Set(args)) => cmd_tag_set(args, start, sink),
|
||||
},
|
||||
// No board either, for the reason `install-skill` has none: a completion script
|
||||
// is generated from the clap definition and is the same wherever it is run.
|
||||
Command::Completions { shell } => {
|
||||
completions::generate(*shell, sink.as_write()).map_err(Into::into)
|
||||
}
|
||||
// No board is looked for: the point of the skill is to teach an agent worklane
|
||||
// before there is a `.worklane` anywhere.
|
||||
Command::InstallSkill { skill, force, print } => {
|
||||
cmd_install_skill(skill.as_deref(), *force, *print, sink)
|
||||
}
|
||||
// No board either, and one agent rather than both: opencode loads the tool file,
|
||||
// Claude Code has no path for one.
|
||||
Command::InstallTool { force, print } => cmd_install_tool(*force, *print, sink),
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------- tui --
|
||||
|
||||
/// Restore the terminal whatever happens.
|
||||
@@ -222,9 +251,10 @@ fn run_tui(paths: &[std::path::PathBuf], start: &std::path::Path) -> Result<()>
|
||||
|
||||
// And the command prompt, third, on the same contract: while a command is being
|
||||
// typed `q` is a letter, `d` leaves the columns alone and `tab` stays out of the
|
||||
// project tabs. No screen, because nothing it does measures the board yet. The
|
||||
// rule is `Board::prompt_key`, where a test can reach it.
|
||||
if board.prompt_key(key) {
|
||||
// project tabs. It takes the screen because enter runs the command and then has
|
||||
// to bring the ticket it moved back into view. The rule is `Board::prompt_key`,
|
||||
// where a test can reach it.
|
||||
if board.prompt_key(key, screen) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
+742
-79
File diff suppressed because it is too large
Load Diff
+40
-1
@@ -303,6 +303,42 @@ pub fn color_text(text: &str, color: Color) -> String {
|
||||
paint(text, color, should_use_colors())
|
||||
}
|
||||
|
||||
/// `text` with every ANSI escape sequence taken out of it.
|
||||
///
|
||||
/// The inverse of what [`paint`] writes, and the guard at the seam where a handler's
|
||||
/// words become something the board draws: ratatui prints an escape as literal bytes
|
||||
/// rather than obeying it, so a painted status reaches the screen as `\x1b[33m` and
|
||||
/// the word after it.
|
||||
///
|
||||
/// A [`Sink`] the board owns is plain, so this is not about a handler's ordinary
|
||||
/// output. It is about the strings that never go through one: an error message is
|
||||
/// built with `color_text`, which asks the *process* about its stdout, and under the
|
||||
/// board that answers yes about a terminal the message is not going to.
|
||||
pub fn without_escapes(text: &str) -> String {
|
||||
let mut out = String::with_capacity(text.len());
|
||||
let mut chars = text.chars();
|
||||
|
||||
while let Some(c) = chars.next() {
|
||||
if c != '\x1b' {
|
||||
out.push(c);
|
||||
continue;
|
||||
}
|
||||
|
||||
// A CSI sequence is `\x1b[`, then parameter bytes, closed by a final byte in
|
||||
// `@` to `~`. That is every sequence `Color` writes. Anything else is a short
|
||||
// escape whose one following character goes with it, which `next` has taken.
|
||||
if chars.next() == Some('[') {
|
||||
for c in chars.by_ref() {
|
||||
if ('\x40'..='\x7e').contains(&c) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
out
|
||||
}
|
||||
|
||||
/// A destination for a command's output, chosen by the caller.
|
||||
///
|
||||
/// `main` hands a handler its own stdout and nothing about the CLI changes; the
|
||||
@@ -332,7 +368,10 @@ impl<'a> Sink<'a> {
|
||||
|
||||
/// An in-memory buffer, plain, for a test or a caller that colours the text
|
||||
/// itself.
|
||||
#[allow(dead_code)]
|
||||
///
|
||||
/// What the board's command prompt passes: the handler's words come back as text
|
||||
/// and the board styles them with ratatui, which is also why it must not be handed
|
||||
/// a coloured one — a paragraph prints an escape rather than obeying it.
|
||||
pub fn buffer(target: &'a mut Vec<u8>) -> Sink<'a> {
|
||||
Sink {
|
||||
writer: Box::new(target),
|
||||
|
||||
Reference in New Issue
Block a user