From 3e732535f81967b263718ca7f4714da7f6553a24 Mon Sep 17 00:00:00 2001 From: Ansho Rei Date: Tue, 15 Sep 2026 16:23:19 +0200 Subject: [PATCH] (bc86c85) Attribute a command typed at the board to the person, not the variable, and bump to 0.33.5 WORKLANE_ACTOR is set once in the environment an agent runs in, which is right for an agent and wrong for the board: a person who exports it where their own shell picks it up, the obvious way to configure it for the agents on that machine, then moved a ticket with ':' and the board recorded the move as the agent's. Nothing but the reader can type that line, so the prompt asks for --actor-from-git's precedence without the flag. An explicit --actor still wins, which is how the reader puts somebody else's name on their own keystrokes, and a machine with no git user configured reads unknown rather than falling back to the variable, for the reason the flag does. The attribution is a parameter of dispatch rather than a field the prompt writes into what clap parsed: rewriting the arguments would need an arm per entry-writing command, and the command added after it would be attributed to the agent until somebody noticed. no_handler_decides_its_own_attribution reads src for a handler naming an Attribution of its own, which the compiler cannot catch because it compiles. The same command typed in a shell is unchanged, which is what keeps a board several agents write to saying which of them wrote what. Also closes a code fence in the skill that e26e589 left open, duplicating the mv --actor example under it. Co-Authored-By: Claude Opus 5 (1M context) --- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 2 +- assets/SKILL.md | 8 ++- docs/history.md | 2 + docs/tui-prompts.md | 1 + src/handlers.rs | 62 ++++++++++++++--- src/main.rs | 23 ++++--- src/tui.rs | 64 +++++++++++++++-- src/util.rs | 163 ++++++++++++++++++++++++++++++++++++++------ 10 files changed, 282 insertions(+), 47 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f2f8d7f..5db82fa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1563,7 +1563,7 @@ dependencies = [ [[package]] name = "worklane" -version = "0.33.4" +version = "0.33.5" dependencies = [ "anyhow", "assert_cmd", diff --git a/Cargo.toml b/Cargo.toml index 4694a5e..b5513c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "worklane" -version = "0.33.4" +version = "0.33.5" edition = "2024" [dependencies] diff --git a/README.md b/README.md index c1fff46..8b57621 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ Worklane is a local Kanban flow for agentic software development. | Variable | Effect | |----------|--------| -| `WORKLANE_ACTOR` | Who every entry the CLI writes is attributed to: a comment, and the `status`, `owner` and `tags` entries `mv`, `chown` and `set --tags` record. Set it once, in the environment an agent runs in, and every call it makes is attributed to it instead of to the git user of whoever's machine it is on. `--actor` overrides it per call and `--actor-from-git` lifts the git user over it per call (the two flags are refused together), an empty value counts as unset, and with neither supplied the author is the git user and then `unknown`. Free text, checked against nothing | +| `WORKLANE_ACTOR` | Who every entry the CLI writes is attributed to: a comment, and the `status`, `owner` and `tags` entries `mv`, `chown` and `set --tags` record. Set it once, in the environment an agent runs in, and every call it makes is attributed to it instead of to the git user of whoever's machine it is on. `--actor` overrides it per call and `--actor-from-git` lifts the git user over it per call (the two flags are refused together), an empty value counts as unset, and with neither supplied the author is the git user and then `unknown`. A command typed at the board's `:` prompt is attributed to the person instead, the git user and then `unknown`, never this variable: nothing but whoever is sitting at the board can type one. Free text, checked against nothing | | `NO_COLOR` | Set and non-empty turns colour off, whatever the value, per no-color.org. Colour is also off when output is not a terminal, and when `TERM` is `dumb` or empty | | `XDG_CONFIG_HOME` | Where `install-tool` looks for opencode's config root, `$XDG_CONFIG_HOME/opencode`, defaulting to `~/.config`. `install-skill` does not follow it: `~/.claude` is not an XDG path | diff --git a/assets/SKILL.md b/assets/SKILL.md index c156b2f..05cabbe 100644 --- a/assets/SKILL.md +++ b/assets/SKILL.md @@ -417,8 +417,6 @@ is never needed. It cannot be combined with `--actor`, and a machine with no git configured has nobody to name: the entry reads `unknown` rather than falling back to your variable. -``` -worklane mv 1b78a24 --status done --actor "Ansho Rei" ``` worklane mv 1b78a24 --status done --actor "Ansho Rei" ``` @@ -431,6 +429,12 @@ 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. +**An entry made from the board is the person's, not yours.** A command typed at the +board's `:` prompt is attributed to the git user of that machine whatever `WORKLANE_ACTOR` +is set to, because nothing but the person sitting at the board can type one. So an entry +can appear under a name no agent is configured with, and reading it as somebody else's +agent is reading it wrong: that is the person whose board it is, acting for themselves. + ## Shell completions ``` diff --git a/docs/history.md b/docs/history.md index 2e0ae02..f5538de 100644 --- a/docs/history.md +++ b/docs/history.md @@ -5,6 +5,8 @@ Who an entry is attributed to, and what the log does and does not record. ## Who Wrote an Entry - **Identity is supplied, not detected.** Every option that needs no cooperation fails: a harness variable such as `CLAUDECODE` names the tool rather than the instance and breaks across versions, walking the parent process is platform specific and also only names the harness, and a terminal check separates interactive from not, which a human piping output is too. So the actor is `WORKLANE_ACTOR`, set once per session, with `--actor` as the per-call override - **Precedence: flag, then `WORKLANE_ACTOR`, then `get_git_user()`, then `unknown`.** With `--actor-from-git` and no explicit value the git user is lifted *above* the variable rather than added beneath it — the flag says attribute this to the human, and a machine with no git user configured reads `unknown` instead of quietly attributing back to the agent. An explicit `--actor` wins outright either way. `resolve_actor` is the only caller of `get_git_user` for an entry's author, and every entry the CLI writes goes through it. The halves are separate pure functions, `session_actor` (the variable alone now) and `entry_actor`, tested without touching the process environment for the reason `colors_wanted` is split that way +- **A command typed at the board is the person's, not the session's.** `dispatch` takes an `Attribution`, `Session` from `main` and `Person` from the command prompt, and `Person` asks for `--actor-from-git`'s lift without the flag: nothing but the reader can type that line, and a person who exported `WORKLANE_ACTOR` where their own shell picks it up — the obvious way to configure it for the agents on that machine — would otherwise watch their own `mv` recorded as the agent's. An explicit `--actor` still wins there, which is how the reader puts somebody else's name on their own keystrokes, and with no git user configured the entry reads `unknown` rather than falling back to the variable, for the reason the flag does. `entry_actor` takes it beside `from_git` and the two are one branch, since `--actor-from-git` typed at the prompt asks for what the prompt does anyway +- **The attribution is a parameter of `dispatch`, not a field the prompt writes into the parsed arguments.** Rewriting what clap produced would need an arm per entry-writing command, and the command added after it would be attributed to the agent until somebody noticed. A parameter is one edit for both callers, and `no_handler_decides_its_own_attribution` reads `src` for a handler naming an `Attribution` of its own, which the compiler cannot catch because it compiles - **The variable half is cached in a `OnceLock` and the git user in another**, the way `should_use_colors` is: neither input can change mid-run, and the git user costs a subprocess. Two caches rather than one is the whole point: baking the git user into the session's answer would make `--actor-from-git` read whatever the run's *first* call produced, since with the variable set that call never fetched git at all. `entry_actor` takes the git user as a closure so the subprocess is not run when something ahead of it already answered - **The two flags are refused together at parse time**, clap `conflicts_with`: both answer who the entry is attributed to, and last-wins would be a silent answer to a contradictory call. `every_actor_command_takes_actor_from_git` walks the clap definition so the pair travels together onto any command that grows an `--actor` - An **empty `WORKLANE_ACTOR` counts as unset**, the convention `colors_wanted` follows for `NO_COLOR`, so a wrapper script can clear an inherited one. Whitespace counts the same, since a shell quoting a missing value writes one diff --git a/docs/tui-prompts.md b/docs/tui-prompts.md index c58412f..861d9b9 100644 --- a/docs/tui-prompts.md +++ b/docs/tui-prompts.md @@ -24,6 +24,7 @@ The three input modes on the board and the key that copies an id off it. - **`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 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 +- **What it writes is attributed to the person at the board**, through the same `dispatch` parameter, because a line nothing but the reader can type is the reader's action. The rule and its precedence are in [history.md](history.md), which owns attribution; what belongs here is that the board is the one caller that asks for it - **`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 warning goes through the sink's second stream, and never through `eprintln!`.** `Sink` carries two writers because the CLI's two streams are two: `Sink::std` hands the answer to stdout and an aside to stderr, and a shell has to go on reading the same line on the same stream. Under the board neither is a stream at all — stderr is the alternate screen with the columns on it — so `Sink::buffer` *holds* its warnings and `Board::run` reads them back with `Sink::warnings` and puts them above the answer, on both outcomes: a `mv` that warns about a dangling blocker and is then refused by a real one wrote the aside first, and it is the half that says why the refusal names one blocker and the ticket records two. That is c680e24: one `eprintln!` in `check_blockers` outlived fa5662a because a helper had no sink to reach, and ratatui does not repaint a cell it believes is unchanged, so the fragment stayed on the columns until something else redrew them. `no_handler_or_helper_reaches_a_print_macro` walks `src` for the next one, each file cut at its test module, so a print site in a module added tomorrow is caught the day it is added diff --git a/src/handlers.rs b/src/handlers.rs index 5ce0ce7..fefd9c2 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -611,7 +611,7 @@ fn check_dependents(worklane_dir: &Path, uuid: &str, title: &str, sink: &mut Sin /// A status is a [`Status`] rather than a string, so an unknown one is clap's to refuse /// and nothing here has to check. What is left is the order of the flow, which is /// `Status::ALL`. -pub fn cmd_mv(args: &MvArgs, start: &Path, sink: &mut Sink) -> Result<()> { +pub fn cmd_mv(args: &MvArgs, start: &Path, by: Attribution, sink: &mut Sink) -> Result<()> { let MvArgs { ticket: ticket_id, status: target, @@ -758,7 +758,7 @@ pub fn cmd_mv(args: &MvArgs, start: &Path, sink: &mut Sink) -> Result<()> { &parse_ticket_field(&resolved, "ID"), Kind::Status, &change(¤t_status, target_status), - &resolve_actor(actor.as_deref(), *actor_from_git), + &resolve_actor(actor.as_deref(), *actor_from_git, by), &reason, )?; @@ -778,6 +778,7 @@ pub fn cmd_comment( actor: &Option, actor_from_git: bool, start: &Path, + by: Attribution, sink: &mut Sink, ) -> Result<()> { if body.is_empty() { @@ -797,7 +798,7 @@ pub fn cmd_comment( &ticket_uuid, Kind::Comment, body, - &resolve_actor(actor.as_deref(), actor_from_git), + &resolve_actor(actor.as_deref(), actor_from_git, by), "", )?; @@ -976,7 +977,7 @@ fn report_in( Ok(()) } -pub fn cmd_set(args: &SetArgs, start: &Path, sink: &mut Sink) -> Result<()> { +pub fn cmd_set(args: &SetArgs, start: &Path, by: Attribution, sink: &mut Sink) -> Result<()> { if let Some(field) = args.contested() { let name = field.name(); return Err(anyhow!( @@ -1058,7 +1059,7 @@ pub fn cmd_set(args: &SetArgs, start: &Path, sink: &mut Sink) -> Result<()> { &parse_ticket_field(&original, "Tags"), &parse_ticket_field(&content, "Tags"), ), - &resolve_actor(args.actor.as_deref(), args.actor_from_git), + &resolve_actor(args.actor.as_deref(), args.actor_from_git, by), "", )?; } @@ -1089,7 +1090,7 @@ pub fn cmd_set(args: &SetArgs, start: &Path, sink: &mut Sink) -> Result<()> { /// for a ticket it is filing, which is a default for something new; an owner taken away /// says nobody owns this, and putting the person running the command there instead would /// hand them a ticket they were giving up. -pub fn cmd_chown(args: &ChownArgs, start: &Path, sink: &mut Sink) -> Result<()> { +pub fn cmd_chown(args: &ChownArgs, start: &Path, by: Attribution, sink: &mut Sink) -> Result<()> { let (ticket_id, user) = args.target().ok_or_else(|| { anyhow!("chown takes a user and a ticket, or --clear with the ticket alone") })?; @@ -1117,7 +1118,7 @@ pub fn cmd_chown(args: &ChownArgs, start: &Path, sink: &mut Sink) -> Result<()> &parse_ticket_field(&original, "Owner"), &parse_ticket_field(&content, "Owner"), ), - &resolve_actor(args.actor.as_deref(), args.actor_from_git), + &resolve_actor(args.actor.as_deref(), args.actor_from_git, by), "", )?; @@ -1129,7 +1130,7 @@ pub fn cmd_chown(args: &ChownArgs, start: &Path, sink: &mut Sink) -> Result<()> Ok(()) } -pub fn cmd_append(args: &AppendArgs, start: &Path, sink: &mut Sink) -> Result<()> { +pub fn cmd_append(args: &AppendArgs, start: &Path, by: Attribution, sink: &mut Sink) -> Result<()> { let worklane_dir = find_worklane_dir(start)?; let (status, title, original) = resolve_ticket(&args.ticket, &worklane_dir)?; let uuid = parse_ticket_field(&original, "ID"); @@ -1180,7 +1181,7 @@ pub fn cmd_append(args: &AppendArgs, start: &Path, sink: &mut Sink) -> Result<() &parse_ticket_field(&original, "Tags"), &parse_ticket_field(&content, "Tags"), ), - &resolve_actor(args.actor.as_deref(), args.actor_from_git), + &resolve_actor(args.actor.as_deref(), args.actor_from_git, by), "", )?; } @@ -1885,6 +1886,7 @@ pub fn cmd_assign( actor: &Option, actor_from_git: bool, start: &Path, + by: Attribution, sink: &mut Sink, ) -> Result<()> { let worklane_dir = find_worklane_dir(start)?; @@ -1923,7 +1925,7 @@ pub fn cmd_assign( &uuid, Kind::Campaign, &change(&before, campaign.name()), - &resolve_actor(actor.as_deref(), actor_from_git), + &resolve_actor(actor.as_deref(), actor_from_git, by), "", )?; @@ -2387,7 +2389,7 @@ mod sink_tests { let mut sink = Sink::buffer(&mut buf); // A dangling uuid is a bookkeeping fault rather than a dependency, so the // move happens and the warning is the whole of what is said about it. - cmd_mv(&args, &root, &mut sink).unwrap(); + cmd_mv(&args, &root, Attribution::Session, &mut sink).unwrap(); sink.warnings() }; @@ -2475,6 +2477,44 @@ mod sink_tests { ); } + /// A handler takes the attribution `dispatch` was given and never decides one of its + /// own. + /// + /// That parameter is what makes a command added tomorrow attributed correctly from + /// both callers at once. A handler naming `Attribution::Session` outright would be + /// the person's own keystrokes recorded as the agent's again, and it would compile, + /// so the compiler cannot be the thing that catches it. + #[test] + fn no_handler_decides_its_own_attribution() { + let mut deciding: Vec = Vec::new(); + for entry in fs::read_dir(concat!(env!("CARGO_MANIFEST_DIR"), "/src")).unwrap() { + let path = entry.unwrap().path(); + if path.extension().and_then(|ext| ext.to_str()) != Some("rs") { + continue; + } + + let source = fs::read_to_string(&path).unwrap(); + let name = path.file_name().unwrap().to_string_lossy().to_string(); + deciding.extend( + body_of(&source) + .map(str::trim) + .filter(|line| !line.starts_with("//")) + // The definition itself, which is where the parameter is named. + .filter(|line| { + line.contains("resolve_actor(") && !line.contains("fn resolve_actor(") + }) + .filter(|line| !line.ends_with(", by)") && !line.ends_with(", by),")) + .map(|line| format!("{name}: {line}")), + ); + } + + assert!( + deciding.is_empty(), + "a handler passes the attribution it was dispatched with, `by`, so a line \ + typed at the board stays the person's:\n{deciding:#?}" + ); + } + /// A file's lines up to its test module, which in this crate is the only inline /// `mod` at column 0. A file's own assertions are allowed to name a macro the file /// may not call, this test's own body first among them. diff --git a/src/main.rs b/src/main.rs index e114d73..67be71d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -62,7 +62,9 @@ fn main() -> Result<()> { // it opens the board above the working directory. None => run_tui(&[], &start), Some(Command::Tui { paths }) => run_tui(&paths, &start), - Some(command) => dispatch(&command, &start, &mut sink), + // Every call `main` dispatches came from a shell or a script, so the session's + // own chain answers: `WORKLANE_ACTOR` first, which is what it is set for. + Some(command) => dispatch(&command, &start, Attribution::Session, &mut sink), }; // The board (and every handler) own their own writing, so flush what the last one @@ -84,7 +86,12 @@ fn main() -> Result<()> { /// 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<()> { +/// +/// `by` is who the call is being made by, and it is a parameter here rather than a field +/// the prompt writes into the parsed arguments: an entry-writing command added tomorrow +/// is attributed correctly from both callers without an arm anywhere rewriting what clap +/// produced. `main` is the session, the prompt is the person at the board. +pub fn dispatch(command: &Command, start: &Path, by: Attribution, 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. @@ -99,11 +106,11 @@ pub fn dispatch(command: &Command, start: &Path, sink: &mut Sink) -> Result<()> 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::Mv(args) => cmd_mv(args, start, by, sink), + Command::Set(args) => cmd_set(args, start, by, sink), + Command::Append(args) => cmd_append(args, start, by, sink), Command::Relate(args) => cmd_relate(args, start, sink), - Command::Chown(args) => cmd_chown(args, start, sink), + Command::Chown(args) => cmd_chown(args, start, by, sink), Command::Check(args) => cmd_check(args, true, start, sink), Command::Uncheck(args) => cmd_check(args, false, start, sink), Command::Comment { @@ -111,7 +118,7 @@ pub fn dispatch(command: &Command, start: &Path, sink: &mut Sink) -> Result<()> body, actor, actor_from_git, - } => cmd_comment(ticket, body, actor, *actor_from_git, start, sink), + } => cmd_comment(ticket, body, actor, *actor_from_git, start, by, sink), Command::Campaign { command } => match command { CampaignCommand::Add(args) => cmd_campaign_add(args, start, sink), CampaignCommand::Ls { ids } => { @@ -130,7 +137,7 @@ pub fn dispatch(command: &Command, start: &Path, sink: &mut Sink) -> Result<()> ticket, actor, actor_from_git, - } => cmd_assign(campaign, ticket, actor, *actor_from_git, start, sink), + } => cmd_assign(campaign, ticket, actor, *actor_from_git, start, by, 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. diff --git a/src/tui.rs b/src/tui.rs index 2fcc264..165d15c 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -2744,7 +2744,12 @@ impl Board { let mut buffer: Vec = Vec::new(); let (outcome, warned) = { let mut sink = Sink::buffer(&mut buffer); - let outcome = crate::dispatch(command, &root, &mut sink).and_then(|()| sink.flush()); + // The person's, not the session's. Nothing but the reader can type this line, + // so `WORKLANE_ACTOR` — set where the agents on this machine pick it up, and + // inherited by the shell that opened the board — does not describe whoever + // pressed enter. + let outcome = crate::dispatch(command, &root, Attribution::Person, &mut sink) + .and_then(|()| sink.flush()); // Read on both outcomes and reported on both: a `mv` that warns about a // dangling blocker and is then refused by a real one wrote the warning // first, and dropping it there would lose the half that says why the @@ -8422,6 +8427,57 @@ approach"; ); } + /// An entry the prompt writes is the reader's own, whatever `WORKLANE_ACTOR` says. + /// + /// The variable is set in the environment an agent runs in, and a person configuring + /// it for the agents on their machine exports it where their own shell picks it up + /// too — so the shell that opened this board carries it, and without the attribution + /// parameter this entry would name the agent. + /// + /// Read against `get_git_user` rather than a literal, since the name depends on the + /// machine the suite runs on. With no git user configured there is nobody to name and + /// the entry reads `unknown`, which is the same rule and not a fallback to the + /// variable. + #[test] + fn an_entry_written_from_the_prompt_names_the_person() { + let (root, mut board) = runnable(); + let dir = root.join(".worklane"); + + run_line(&mut board, "comment 1111111 \"typed at the board\""); + assert!(board.prompt.is_none(), "the line was refused: {:?}", refused(&board)); + + let log = read_history(&dir, "11111111-0000-4000-8000-000000000000").unwrap(); + let entry = log + .iter() + .find(|entry| entry.body == "typed at the board") + .expect("the comment was not written"); + assert_eq!( + entry.author, + get_git_user().unwrap_or_else(|| UNKNOWN_ACTOR.to_string()), + "the board attributed the reader's own line to somebody else" + ); + + // And `--actor` still wins, which is how the reader puts somebody else's name on + // their own keystrokes. + run_line(&mut board, "comment 1111111 \"for alice\" --actor alice"); + let log = read_history(&dir, "11111111-0000-4000-8000-000000000000").unwrap(); + let entry = log + .iter() + .find(|entry| entry.body == "for alice") + .expect("the second comment was not written"); + assert_eq!(entry.author, "alice", "the flag lost to the board's own attribution"); + + // The two flags together are clap's refusal, reached here because the prompt + // parses against the same definition the shell does rather than a grammar of its + // own. A line it refuses keeps the prompt open with the line intact. + run_line(&mut board, "comment 1111111 both --actor alice --actor-from-git"); + assert!( + refused(&board).is_some_and(|said| said.contains("cannot be used with")), + "the contradictory pair was taken: {:?}", + refused(&board) + ); + } + /// What the handler said is what the board reports, word for word: those messages are /// already written for a person, and a second set kept on the board would go stale the /// first time one of them changed. @@ -8441,7 +8497,7 @@ approach"; .unwrap(); { let mut sink = Sink::buffer(&mut buffer); - crate::dispatch(&command, &root, &mut sink).unwrap(); + crate::dispatch(&command, &root, Attribution::Session, &mut sink).unwrap(); sink.flush().unwrap(); } let said = String::from_utf8(buffer).unwrap().trim_end().to_string(); @@ -8786,8 +8842,8 @@ approach"; // What the board calls instead. assert!( - here.contains("crate::dispatch(command, &root, &mut sink)"), - "the board does not go through the table" + here.contains("crate::dispatch(command, &root, Attribution::Person, &mut sink)"), + "the board does not go through the table, or it does not attribute to the person" ); } diff --git a/src/util.rs b/src/util.rs index 30e9358..f83a5f3 100644 --- a/src/util.rs +++ b/src/util.rs @@ -649,6 +649,32 @@ pub const ACTOR_ENV: &str = "WORKLANE_ACTOR"; /// The author written when nothing names one. pub const UNKNOWN_ACTOR: &str = "unknown"; +/// Who is making the call, which decides whether [`ACTOR_ENV`] describes them. +/// +/// The variable is set once in the environment an agent runs in, so every call that agent +/// makes carries its name, which is exactly what a board several agents write to needs. A +/// line typed at the command prompt is not one of those calls: nothing but the reader can +/// type it, and a person who exported the variable where their own shell picks it up — +/// the obvious way to configure it for the agents on that machine — would otherwise watch +/// their own `mv` recorded as the agent's. +/// +/// So the board attributes to the person, which is `--actor-from-git`'s precedence +/// applied by default rather than asked for. It is a parameter of [`dispatch`] and not a +/// field on the parsed arguments, so a command that grows an `--actor` tomorrow is +/// attributed correctly from both callers without an arm anywhere rewriting what clap +/// produced. +/// +/// [`dispatch`]: crate::dispatch +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum Attribution { + /// The process's own session: the variable, then the git user. Every call from a + /// shell or a script, which is every call `main` dispatches. + Session, + /// The person at the board: the git user, and [`UNKNOWN_ACTOR`] where none is + /// configured, never the variable. + Person, +} + /// The actor for the whole run, from the variable alone. /// /// Split out from the caching wrapper for the reason `colors_wanted` is: a threaded test @@ -675,11 +701,18 @@ fn session_actor(env: Option<&str>) -> Option { /// has nobody to name, which reads [`UNKNOWN_ACTOR`] rather than quietly attributing /// back to the agent. Without it, today's chain: the variable, then the git user. /// +/// [`Attribution::Person`] asks for that same lift without the flag, because a line typed +/// at the board is the reader's own action and there is nothing to say. The two are one +/// branch rather than two: a `--actor-from-git` typed at the prompt asks for what the +/// prompt does anyway, and an explicit `--actor` outranks both, which is how the reader +/// puts somebody else's name on their own keystrokes. +/// /// `git_user` is a closure in both branches so the subprocess it costs is not run when /// something ahead of it already answered. fn entry_actor( flag: Option<&str>, from_git: bool, + by: Attribution, session: Option<&str>, git_user: impl FnOnce() -> Option, ) -> String { @@ -687,7 +720,7 @@ fn entry_actor( return name.to_string(); } - if from_git { + if from_git || matches!(by, Attribution::Person) { return git_user().unwrap_or_else(|| UNKNOWN_ACTOR.to_string()); } @@ -698,13 +731,14 @@ fn entry_actor( git_user().unwrap_or_else(|| UNKNOWN_ACTOR.to_string()) } -/// Who to attribute an entry to, from the flags the call carried. +/// Who to attribute an entry to, from the flags the call carried and who is calling. /// -/// Precedence: flag, then — unless `from_git` lifted it — `WORKLANE_ACTOR`, then the git -/// user, then `unknown`. Every entry the CLI writes goes through here, so a board -/// several agents write to says which of them wrote what instead of attributing all of -/// it to one human. -pub fn resolve_actor(flag: Option<&str>, from_git: bool) -> String { +/// Precedence: flag, then — unless `from_git` or [`Attribution::Person`] lifted it — +/// `WORKLANE_ACTOR`, then the git user, then `unknown`. Every entry the CLI writes goes +/// through here, so a board several agents write to says which of them wrote what +/// instead of attributing all of it to one human, and a line the person typed at the +/// board is theirs rather than whichever agent's variable their shell exports. +pub fn resolve_actor(flag: Option<&str>, from_git: bool, by: Attribution) -> String { // Each half is decided once, the way should_use_colors is: neither input can change // mid-run, and the git user costs a subprocess. They are two caches rather than one, // because baking the git user into the session's answer would leave `--actor-from-git` @@ -718,7 +752,7 @@ pub fn resolve_actor(flag: Option<&str>, from_git: bool) -> String { session_actor(env.as_deref()) }); - entry_actor(flag, from_git, session.as_deref(), || { + entry_actor(flag, from_git, by, session.as_deref(), || { GIT_USER.get_or_init(get_git_user).clone() }) } @@ -4015,14 +4049,17 @@ mod tests { fn the_variable_names_the_actor() { let session = session_actor(Some("claude")); let git_user = || Some("Ansho Rei".to_string()); - assert_eq!(entry_actor(None, false, session.as_deref(), git_user), "claude"); + assert_eq!( + entry_actor(None, false, Attribution::Session, session.as_deref(), git_user), + "claude" + ); } #[test] fn the_flag_overrides_the_variable() { let session = session_actor(Some("claude")); assert_eq!( - entry_actor(Some("opencode"), false, session.as_deref(), || None), + entry_actor(Some("opencode"), false, Attribution::Session, session.as_deref(), || None), "opencode" ); } @@ -4032,7 +4069,13 @@ mod tests { fn the_git_user_is_the_fallback() { let git_user = || Some("Ansho Rei".to_string()); assert_eq!( - entry_actor(None, false, session_actor(None).as_deref(), git_user), + entry_actor( + None, + false, + Attribution::Session, + session_actor(None).as_deref(), + git_user + ), "Ansho Rei" ); } @@ -4045,7 +4088,10 @@ mod tests { let git_user = || Some("Ansho Rei".to_string()); for raw in ["", " "] { let session = session_actor(Some(raw)); - assert_eq!(entry_actor(None, false, session.as_deref(), git_user), "Ansho Rei"); + assert_eq!( + entry_actor(None, false, Attribution::Session, session.as_deref(), git_user), + "Ansho Rei" + ); } } @@ -4053,9 +4099,15 @@ mod tests { #[test] fn nothing_at_all_is_unknown() { let session = session_actor(None); - assert_eq!(entry_actor(None, false, session.as_deref(), || None), UNKNOWN_ACTOR); + assert_eq!( + entry_actor(None, false, Attribution::Session, session.as_deref(), || None), + UNKNOWN_ACTOR + ); // An empty flag falls through rather than writing a blank author - assert_eq!(entry_actor(Some(""), false, None, || None), UNKNOWN_ACTOR); + assert_eq!( + entry_actor(Some(""), false, Attribution::Session, None, || None), + UNKNOWN_ACTOR + ); } /// Free text, validated against nothing, the way the `chown` user is. @@ -4063,7 +4115,7 @@ mod tests { fn an_actor_is_free_text() { let session = session_actor(Some("claude-code, session 3 (opus)")); assert_eq!( - entry_actor(None, false, session.as_deref(), || None), + entry_actor(None, false, Attribution::Session, session.as_deref(), || None), "claude-code, session 3 (opus)" ); } @@ -4074,7 +4126,10 @@ mod tests { fn from_git_lifts_the_git_user_over_the_variable() { let session = session_actor(Some("claude")); let git_user = || Some("Ansho Rei".to_string()); - assert_eq!(entry_actor(None, true, session.as_deref(), git_user), "Ansho Rei"); + assert_eq!( + entry_actor(None, true, Attribution::Session, session.as_deref(), git_user), + "Ansho Rei" + ); } /// An explicit `--actor` still wins outright beside the lift: it names somebody @@ -4084,7 +4139,7 @@ mod tests { let session = session_actor(Some("claude")); let git_user = || Some("Ansho Rei".to_string()); assert_eq!( - entry_actor(Some("opencode"), true, session.as_deref(), git_user), + entry_actor(Some("opencode"), true, Attribution::Session, session.as_deref(), git_user), "opencode" ); } @@ -4094,7 +4149,10 @@ mod tests { #[test] fn from_git_with_no_git_user_is_unknown_not_the_variable() { let session = session_actor(Some("claude")); - assert_eq!(entry_actor(None, true, session.as_deref(), || None), UNKNOWN_ACTOR); + assert_eq!( + entry_actor(None, true, Attribution::Session, session.as_deref(), || None), + UNKNOWN_ACTOR + ); } /// An empty variable still counts as unset with the lift on, which here means the @@ -4103,11 +4161,78 @@ mod tests { fn from_git_leaves_the_empty_variable_unset() { let git_user = || Some("Ansho Rei".to_string()); assert_eq!( - entry_actor(None, true, session_actor(Some("")).as_deref(), git_user), + entry_actor( + None, + true, + Attribution::Session, + session_actor(Some("")).as_deref(), + git_user + ), "Ansho Rei" ); } + /// The board's own case, and the reason this parameter exists: the person who + /// exported `WORKLANE_ACTOR` for the agents on their machine types a command at the + /// prompt, and the entry is theirs. No flag was given and none should have to be. + #[test] + fn a_line_typed_at_the_board_is_the_persons() { + let session = session_actor(Some("claude")); + let git_user = || Some("Ansho Rei".to_string()); + assert_eq!( + entry_actor(None, false, Attribution::Person, session.as_deref(), git_user), + "Ansho Rei" + ); + } + + /// `--actor` still wins there, which is how the reader puts somebody else's name on + /// their own keystrokes. + #[test] + fn the_flag_wins_over_the_board_too() { + let session = session_actor(Some("claude")); + let git_user = || Some("Ansho Rei".to_string()); + assert_eq!( + entry_actor(Some("alice"), false, Attribution::Person, session.as_deref(), git_user), + "alice" + ); + } + + /// And the lift is not a fallback here either. A machine with no git user configured + /// has nobody to name, and writing the variable's value would be the agent's name on + /// the person's move, which is the whole thing this avoids. + #[test] + fn the_board_with_no_git_user_is_unknown_not_the_variable() { + let session = session_actor(Some("claude")); + assert_eq!( + entry_actor(None, false, Attribution::Person, session.as_deref(), || None), + UNKNOWN_ACTOR + ); + } + + /// `--actor-from-git` typed at the prompt asks for what the prompt does anyway, so + /// the two together are the one lift rather than two that could disagree. + #[test] + fn from_git_at_the_board_is_the_same_lift() { + let session = session_actor(Some("claude")); + let git_user = || Some("Ansho Rei".to_string()); + assert_eq!( + entry_actor(None, true, Attribution::Person, session.as_deref(), git_user), + "Ansho Rei" + ); + } + + /// The session's own chain is untouched: the same command typed in a shell is still + /// the variable's, which is what keeps a board several agents write to legible. + #[test] + fn the_session_keeps_the_variable_over_the_git_user() { + let session = session_actor(Some("claude")); + let git_user = || Some("Ansho Rei".to_string()); + assert_eq!( + entry_actor(None, false, Attribution::Session, session.as_deref(), git_user), + "claude" + ); + } + #[test] fn unset_values_are_dimmed_and_set_ones_are_not() { // Both paths, now that the colour decision is a parameter: with colour off the