(87862df) Attribute an entry to WORKLANE_ACTOR, not to the git user, and bump to 0.28.0
Every comment the CLI wrote was attributed to the git user, so a board several agents write to read as a list of things one human had done. resolve_actor is now the single source: flag, then WORKLANE_ACTOR, then get_git_user(), then unknown. comment --owner is renamed to --actor with no alias, since it names the writer of the entry and not the ticket's assignee, which is chown's. add --owner and campaign add --owner still default to the git user. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
c2ee165108
commit
a1bdb5df49
+105
@@ -416,6 +416,63 @@ pub fn get_git_user() -> Option<String> {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// The variable that names the writer of an entry, set once per session.
|
||||
///
|
||||
/// A per-call flag can be forgotten on the fortieth call; a variable set by an agent's
|
||||
/// own configuration is inherited by every call it makes.
|
||||
pub const ACTOR_ENV: &str = "WORKLANE_ACTOR";
|
||||
|
||||
/// The author written when nothing names one.
|
||||
pub const UNKNOWN_ACTOR: &str = "unknown";
|
||||
|
||||
/// The actor for the whole run: the variable, then the git user.
|
||||
///
|
||||
/// Split out from the caching wrapper for the reason `colors_wanted` is: a threaded test
|
||||
/// binary cannot mutate the process environment to reach one branch at a time.
|
||||
///
|
||||
/// An empty `WORKLANE_ACTOR` counts as unset, the convention `colors_wanted` follows for
|
||||
/// `NO_COLOR`, so a wrapper script can clear an inherited one. `git_user` is a closure
|
||||
/// rather than a value because the fallback costs a subprocess and the variable usually
|
||||
/// answers first.
|
||||
fn session_actor(env: Option<&str>, git_user: impl FnOnce() -> Option<String>) -> Option<String> {
|
||||
match env.map(str::trim).filter(|value| !value.is_empty()) {
|
||||
Some(value) => Some(value.to_string()),
|
||||
None => git_user(),
|
||||
}
|
||||
}
|
||||
|
||||
/// The actor for one entry: the flag wins, otherwise the session's, otherwise unknown.
|
||||
///
|
||||
/// Free text, validated against nothing, the way the `chown` user is: there is no
|
||||
/// registry of actors to check a name against.
|
||||
fn entry_actor(flag: Option<&str>, session: Option<&str>) -> String {
|
||||
[flag, session]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.map(str::trim)
|
||||
.find(|value| !value.is_empty())
|
||||
.unwrap_or(UNKNOWN_ACTOR)
|
||||
.to_string()
|
||||
}
|
||||
|
||||
/// Who to attribute an entry to, from the flag the call carried.
|
||||
///
|
||||
/// Precedence: flag, then `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>) -> String {
|
||||
// The session half is decided once, the way should_use_colors is: neither input can
|
||||
// change mid-run, and the git user costs a subprocess.
|
||||
static SESSION: OnceLock<Option<String>> = OnceLock::new();
|
||||
|
||||
let session = SESSION.get_or_init(|| {
|
||||
let env = std::env::var(ACTOR_ENV).ok();
|
||||
session_actor(env.as_deref(), get_git_user)
|
||||
});
|
||||
|
||||
entry_actor(flag, session.as_deref())
|
||||
}
|
||||
/// One file a search matched, and where it was found.
|
||||
pub struct Found {
|
||||
/// The name the match is reported under: the status directory for a ticket, and
|
||||
@@ -3377,6 +3434,54 @@ mod tests {
|
||||
assert!(colors_wanted(true, None, None));
|
||||
}
|
||||
|
||||
/// The variable answers when no flag does, and the git user is never asked: the
|
||||
/// closure returns a name that must not appear.
|
||||
#[test]
|
||||
fn the_variable_names_the_actor() {
|
||||
let session = session_actor(Some("claude"), || Some("Ansho Rei".to_string()));
|
||||
assert_eq!(entry_actor(None, session.as_deref()), "claude");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_flag_overrides_the_variable() {
|
||||
let session = session_actor(Some("claude"), || None);
|
||||
assert_eq!(entry_actor(Some("opencode"), session.as_deref()), "opencode");
|
||||
}
|
||||
|
||||
/// With neither supplied the author is still the git user.
|
||||
#[test]
|
||||
fn the_git_user_is_the_fallback() {
|
||||
let session = session_actor(None, || Some("Ansho Rei".to_string()));
|
||||
assert_eq!(entry_actor(None, session.as_deref()), "Ansho Rei");
|
||||
}
|
||||
|
||||
/// An empty variable counts as unset, the way `NO_COLOR` does, so a wrapper script
|
||||
/// can clear an inherited one and get the git user back.
|
||||
#[test]
|
||||
fn an_empty_variable_reads_as_unset() {
|
||||
let session = session_actor(Some(""), || Some("Ansho Rei".to_string()));
|
||||
assert_eq!(entry_actor(None, session.as_deref()), "Ansho Rei");
|
||||
// Whitespace is the same case: a shell that quotes a missing value writes one
|
||||
let session = session_actor(Some(" "), || Some("Ansho Rei".to_string()));
|
||||
assert_eq!(entry_actor(None, session.as_deref()), "Ansho Rei");
|
||||
}
|
||||
|
||||
/// And with nothing at all, including a git that has no user configured.
|
||||
#[test]
|
||||
fn nothing_at_all_is_unknown() {
|
||||
let session = session_actor(None, || None);
|
||||
assert_eq!(entry_actor(None, session.as_deref()), UNKNOWN_ACTOR);
|
||||
// An empty flag falls through rather than writing a blank author
|
||||
assert_eq!(entry_actor(Some(""), None), UNKNOWN_ACTOR);
|
||||
}
|
||||
|
||||
/// Free text, validated against nothing, the way the `chown` user is.
|
||||
#[test]
|
||||
fn an_actor_is_free_text() {
|
||||
let session = session_actor(Some("claude-code, session 3 (opus)"), || None);
|
||||
assert_eq!(entry_actor(None, session.as_deref()), "claude-code, session 3 (opus)");
|
||||
}
|
||||
|
||||
#[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
|
||||
|
||||
Reference in New Issue
Block a user