From ecde230744825b1215ac2788516cbcf2de84ba1b Mon Sep 17 00:00:00 2001 From: igorjs <2278164+igorjs@users.noreply.github.com> Date: Fri, 13 Nov 2026 06:55:52 +1100 Subject: [PATCH] feat(cli): nest sanitize and watch service commands, fold watch dry-run sanitize commit-msg and pr-text become sanitize commit and sanitize pr. The watch service commands nest under watch service, and watch dry-run becomes watch once --dry-run. Five alias rows keep the old names working, including for installed git hooks. The CI step uses the new name when the base binary has it. Signed-off-by: igorjs <2278164+igorjs@users.noreply.github.com> --- .github/workflows/commit-message-guard.yml | 13 +++- crates/cli/src/command_index.rs | 10 +-- crates/cli/src/doctor/check.rs | 2 +- crates/cli/src/lib.rs | 40 ++++++---- crates/cli/src/main.rs | 6 +- crates/cli/src/renames.rs | 25 ++++++ crates/cli/src/watch/mod.rs | 38 +++++---- crates/cli/src/watch/service.rs | 4 +- crates/cli/tests/cli_smoke.rs | 9 +-- crates/cli/tests/command_names.rs | 12 +-- crates/cli/tests/command_renames.rs | 77 +++++++++++++++++++ crates/cli/tests/golden/flags.txt | 28 +++---- docs/adr/0055-watch-mode-for-github-events.md | 8 ++ docs/guides/16-watch-acceptance-run.md | 10 +-- docs/internals/01-launcher-and-hooks.md | 4 +- docs/reference/cli-and-config.md | 59 +++++++------- 16 files changed, 229 insertions(+), 116 deletions(-) diff --git a/.github/workflows/commit-message-guard.yml b/.github/workflows/commit-message-guard.yml index f7751fe74..d79b34a80 100644 --- a/.github/workflows/commit-message-guard.yml +++ b/.github/workflows/commit-message-guard.yml @@ -77,8 +77,13 @@ jobs: set -uo pipefail bin="$PWD/target/debug/playbook" - # The first PR that adds the command has a base without it. - if ! "$bin" sanitize pr-text --help >/dev/null 2>&1; then + # The base commit may still know the command as `pr-text`. The first + # PR that adds the command has a base without either name. + if "$bin" sanitize pr --help >/dev/null 2>&1; then + pr_text_cmd=pr + elif "$bin" sanitize pr-text --help >/dev/null 2>&1; then + pr_text_cmd=pr-text + else echo "::notice title=commit-message-guard::the base commit has no sanitize command yet, so nothing was checked" exit 0 fi @@ -91,7 +96,7 @@ jobs: changed=0 edit=(gh pr edit "$PR_NUMBER" --repo "$GITHUB_REPOSITORY") for part in title body; do - "$bin" sanitize pr-text "$work/$part.txt" --check 2> "$work/$part.report" + "$bin" sanitize "$pr_text_cmd" "$work/$part.txt" --check 2> "$work/$part.report" status=$? if [ "$status" -eq 2 ]; then # Exit 1 means something would be removed; 2 means the file could not be read. @@ -99,7 +104,7 @@ jobs: elif [ "$status" -ne 0 ]; then # The report names a line and a shape, never the text. sed "s/^/PR $part: /" "$work/$part.report" - "$bin" sanitize pr-text "$work/$part.txt" 2> /dev/null + "$bin" sanitize "$pr_text_cmd" "$work/$part.txt" 2> /dev/null if [ "$part" = title ] && [ -z "$(cat "$work/title.txt")" ]; then echo "::warning title=commit-message-guard::the PR title is only attribution, so it was left as it is; rename it" elif [ "$part" = title ]; then diff --git a/crates/cli/src/command_index.rs b/crates/cli/src/command_index.rs index e3316527f..f27f870e9 100644 --- a/crates/cli/src/command_index.rs +++ b/crates/cli/src/command_index.rs @@ -316,8 +316,8 @@ pub(crate) const META: &[Meta] = &[ ro("review triage merge"), ro("route").for_agents(), free("sanitize").for_agents(), - free("sanitize commit-msg"), - free("sanitize pr-text"), + free("sanitize commit"), + free("sanitize pr"), free("segment").for_agents(), free("segment branch"), ro("segment size"), @@ -372,16 +372,16 @@ pub(crate) const META: &[Meta] = &[ .purpose("Poll GitHub and propose or run actions by your rules") .for_users(), user("watch approve"), - ro("watch dry-run"), - user("watch install-service"), ro("watch log"), user("watch once"), user("watch pause"), user("watch reject"), user("watch resume"), user("watch retry"), + user("watch service"), + user("watch service install"), + user("watch service uninstall"), ro("watch status"), - user("watch uninstall-service"), free("worktree").for_agents(), free("worktree remove"), free("worktree review"), diff --git a/crates/cli/src/doctor/check.rs b/crates/cli/src/doctor/check.rs index f488a4b5e..b80fa5eea 100644 --- a/crates/cli/src/doctor/check.rs +++ b/crates/cli/src/doctor/check.rs @@ -1115,7 +1115,7 @@ fn attribution_on_row(state: &crate::init::attribution::State, held: &[&str]) -> } } -/// The row for the timer `watch install-service` made: shown only when the +/// The row for the timer `watch service install` made: shown only when the /// timer is installed, and a warning while watch mode is off, because the /// timer then polls nothing. fn watch_service_row(home: &Path) -> Option { diff --git a/crates/cli/src/lib.rs b/crates/cli/src/lib.rs index 5b75ccb30..7bf77f924 100644 --- a/crates/cli/src/lib.rs +++ b/crates/cli/src/lib.rs @@ -1433,8 +1433,8 @@ pub enum AgentsCommand { pub enum SanitizeCommand { /// Clean a commit message file, such as git's `.git/COMMIT_EDITMSG` /// - /// Example: `playbook sanitize commit-msg .git/COMMIT_EDITMSG` - CommitMsg { + /// Example: `playbook sanitize commit .git/COMMIT_EDITMSG` + Commit { /// File holding the message file: PathBuf, /// Report what would be removed, without writing. Exits 1 if anything would be removed, and 2 if FILE cannot be read @@ -1443,8 +1443,8 @@ pub enum SanitizeCommand { }, /// Clean a PR title or body saved to a file /// - /// Example: `playbook sanitize pr-text /tmp/body.md` - PrText { + /// Example: `playbook sanitize pr /tmp/body.md` + Pr { /// File holding the text file: PathBuf, /// Report what would be removed, without writing. Exits 1 if anything would be removed, and 2 if FILE cannot be read @@ -2619,21 +2619,17 @@ pub enum WatchCommand { /// /// A repo watched for the first time starts from now, so turning watch /// mode on never replays old issues. Prints `watch already running` and - /// exits when another watch process holds the lock. + /// exits when another watch process holds the lock. With `--dry-run` it + /// shows the rules and what a poll would propose, and changes nothing. /// /// Example: `playbook watch once --since 2026-11-01T00:00:00Z` Once { /// Replay events from this UTC time, for example 2026-11-01T00:00:00Z #[arg(long)] since: Option, - }, - /// Show the rules and what a poll would propose, and change nothing - /// - /// Example: `playbook watch dry-run` - DryRun { - /// Look at events from this UTC time, for example 2026-11-01T00:00:00Z + /// Show the rules and what a poll would propose, and change nothing #[arg(long)] - since: Option, + dry_run: bool, }, /// Carry out a proposal /// @@ -2691,20 +2687,30 @@ pub enum WatchCommand { #[arg(long)] json: bool, }, + /// Install or remove the timer that runs `watch once` + Service { + #[command(subcommand)] + sub: WatchServiceCommand, + }, +} + +/// `playbook watch service` subcommands. +#[derive(Subcommand, Debug)] +pub enum WatchServiceCommand { /// Install a timer that runs `watch once` every 60 seconds /// /// A launchd agent on macOS and a systemd user timer on Linux. No process /// stays running between polls. The timer finds the GitHub token through /// `gh auth token`, so run `gh auth login` first. /// - /// Example: `playbook watch install-service` - InstallService, - /// Remove the timer that `install-service` made + /// Example: `playbook watch service install` + Install, + /// Remove the timer that `service install` made /// /// The audit log stays unless you ask for it to go. /// - /// Example: `playbook watch uninstall-service --delete-log` - UninstallService { + /// Example: `playbook watch service uninstall --delete-log` + Uninstall { /// Also delete the audit log #[arg(long)] delete_log: bool, diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index eadfd0d65..c01b88f03 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -1160,10 +1160,8 @@ fn real_main() { }, Command::Sanitize { sub } => { let (kind, file, check) = match sub { - SanitizeCommand::CommitMsg { file, check } => { - (sanitize::Kind::CommitMsg, file, check) - } - SanitizeCommand::PrText { file, check } => (sanitize::Kind::PrText, file, check), + SanitizeCommand::Commit { file, check } => (sanitize::Kind::CommitMsg, file, check), + SanitizeCommand::Pr { file, check } => (sanitize::Kind::PrText, file, check), }; match sanitize::run(kind, &file, check) { Ok(lines) => { diff --git a/crates/cli/src/renames.rs b/crates/cli/src/renames.rs index 9d8a9ff42..0bf1cf29a 100644 --- a/crates/cli/src/renames.rs +++ b/crates/cli/src/renames.rs @@ -66,6 +66,31 @@ pub const COMMAND_RENAMES: &[Rename] = &[ new: "doctor migrations", extra: &[], }, + Rename { + old: "sanitize commit-msg", + new: "sanitize commit", + extra: &[], + }, + Rename { + old: "sanitize pr-text", + new: "sanitize pr", + extra: &[], + }, + Rename { + old: "watch dry-run", + new: "watch once", + extra: &["--dry-run"], + }, + Rename { + old: "watch install-service", + new: "watch service install", + extra: &[], + }, + Rename { + old: "watch uninstall-service", + new: "watch service uninstall", + extra: &[], + }, ]; /// Hidden legacy commands that keep their own code and output but print the diff --git a/crates/cli/src/watch/mod.rs b/crates/cli/src/watch/mod.rs index b986e8aba..6cfbd6138 100644 --- a/crates/cli/src/watch/mod.rs +++ b/crates/cli/src/watch/mod.rs @@ -12,7 +12,7 @@ use serde_json::Value; use crate::common::time::parse_iso8601_utc_epoch; use crate::config::{self, store as config_store}; -use crate::WatchCommand; +use crate::{WatchCommand, WatchServiceCommand}; pub mod action; pub mod address; @@ -251,7 +251,7 @@ pub fn once( Ok(pass.out) } -/// `playbook watch dry-run`: what would be proposed. Reads GitHub and the +/// `playbook watch once --dry-run`: what would be proposed. Reads GitHub and the /// stored cursors, and changes nothing. pub fn dry_run( ctx: &Ctx<'_, W, C>, @@ -371,7 +371,7 @@ fn gh_token() -> Option { (output.status.success() && !token.is_empty()).then_some(token) } -/// `install-service` and `uninstall-service`, which need no token. This is the +/// `service install` and `service uninstall`, which need no token. This is the /// only place that builds the real service manager. fn service_command( cmd: Option<&WatchCommand>, @@ -379,8 +379,12 @@ fn service_command( data: &Path, ) -> Option> { let delete_log = match cmd { - Some(WatchCommand::InstallService) => None, - Some(WatchCommand::UninstallService { delete_log }) => Some(*delete_log), + Some(WatchCommand::Service { + sub: WatchServiceCommand::Install, + }) => None, + Some(WatchCommand::Service { + sub: WatchServiceCommand::Uninstall { delete_log }, + }) => Some(*delete_log), _ => return None, }; Some(service_result(delete_log, home, data)) @@ -420,7 +424,7 @@ pub fn run(cmd: Option<&WatchCommand>) -> Result { let home = crate::common::session::home_dir(); let data = playbook_data::data_dir_from(&home); let settings = Settings::load(&home)?; - if matches!(cmd, None | Some(WatchCommand::Once { .. })) && !settings.enabled { + if matches!(cmd, None | Some(WatchCommand::Once { dry_run: false, .. })) && !settings.enabled { return Ok(OFF_MESSAGE.to_string()); } if let Some(out) = service_command(cmd, &home, &data) { @@ -428,9 +432,7 @@ pub fn run(cmd: Option<&WatchCommand>) -> Result { } let needs_token = matches!( cmd, - None | Some( - WatchCommand::Once { .. } | WatchCommand::DryRun { .. } | WatchCommand::Approve { .. } - ) + None | Some(WatchCommand::Once { .. } | WatchCommand::Approve { .. }) ); let token = if !needs_token { String::new() @@ -450,7 +452,7 @@ pub fn run(cmd: Option<&WatchCommand>) -> Result { let write = gh::GhWrite::new(token.clone()); let clock = SystemClock; let me = match cmd { - None | Some(WatchCommand::Once { .. } | WatchCommand::DryRun { .. }) => write.login()?, + None | Some(WatchCommand::Once { .. }) => write.login()?, _ => String::new(), }; let clone = std::env::current_dir().map_err(|e| format!("no current directory: {e}"))?; @@ -483,18 +485,20 @@ pub fn run(cmd: Option<&WatchCommand>) -> Result { return Ok(String::new()); }; match cmd { - WatchCommand::Once { since } => { - once(&ctx, since.as_deref(), || http::UreqHttp::new(&token)) - } - WatchCommand::DryRun { since } => { - dry_run(&ctx, since.as_deref(), || http::UreqHttp::new(&token)) - } + WatchCommand::Once { + since, + dry_run: true, + } => dry_run(&ctx, since.as_deref(), || http::UreqHttp::new(&token)), + WatchCommand::Once { + since, + dry_run: false, + } => once(&ctx, since.as_deref(), || http::UreqHttp::new(&token)), WatchCommand::Approve { id } => approve(&ctx, *id), WatchCommand::Reject { id } => reject(&ctx, *id), WatchCommand::Status { json } => control::status(&ctx, *json), WatchCommand::Pause => control::set_paused(&ctx, true), WatchCommand::Resume => control::set_paused(&ctx, false), - WatchCommand::InstallService | WatchCommand::UninstallService { .. } => { + WatchCommand::Service { .. } => { Err("service commands are handled before the token is read".to_string()) } WatchCommand::Retry { id } => control::retry(&ctx, *id), diff --git a/crates/cli/src/watch/service.rs b/crates/cli/src/watch/service.rs index 2cb9f6eb4..4a1f564d2 100644 --- a/crates/cli/src/watch/service.rs +++ b/crates/cli/src/watch/service.rs @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2026 Igor Santos // SPDX-License-Identifier: Apache-2.0 -//! `watch install-service`: a timer that runs `watch once` every 60 seconds, +//! `watch service install`: a timer that runs `watch once` every 60 seconds, //! a launchd agent on macOS and a systemd user timer on Linux. No process //! stays resident. Every call to `launchctl` or `systemctl` goes through //! [`Manager`], and only `mod.rs` builds the real one. @@ -30,7 +30,7 @@ pub fn kind_here() -> Result { } else if cfg!(target_os = "linux") { Ok(Kind::Systemd) } else { - Err("install-service supports macOS (launchd) and Linux (systemd) only".to_string()) + Err("service install supports macOS (launchd) and Linux (systemd) only".to_string()) } } diff --git a/crates/cli/tests/cli_smoke.rs b/crates/cli/tests/cli_smoke.rs index 0a8164915..125c0ffdc 100644 --- a/crates/cli/tests/cli_smoke.rs +++ b/crates/cli/tests/cli_smoke.rs @@ -575,15 +575,14 @@ fn table() -> Vec { // watch mode: nothing is enabled and no token is set on a fresh home case("watch", &["watch"]).out("watch is off"), case("watch once", &["watch", "once"]).out("watch is off"), - case("watch dry-run", &["watch", "dry-run"]).code(1).err("GITHUB_TOKEN"), case("watch approve", &["watch", "approve", "1"]).code(1).err("GITHUB_TOKEN"), case("watch reject", &["watch", "reject", "1"]).code(1).err("not waiting").grows(), case("watch status", &["watch", "status"]).out("enabled: false").grows(), case("watch pause", &["watch", "pause"]).out("watch paused").grows(), case("watch resume", &["watch", "resume"]).out("watch resumed").grows(), case("watch retry", &["watch", "retry", "1"]).code(1).err("not on the dead list").grows(), - case("watch install-service", &["watch", "install-service"]).code(1).err("not changed"), - case("watch uninstall-service", &["watch", "uninstall-service"]).code(1).err("not changed"), + case("watch service install", &["watch", "service", "install"]).code(1).err("not changed"), + case("watch service uninstall", &["watch", "service", "uninstall"]).code(1).err("not changed"), case("watch log", &["watch", "log"]).grows(), case("sessions sweep", &["sessions", "sweep", "--dry-run"]) .out("No finished or stale sessions") @@ -642,8 +641,8 @@ fn table() -> Vec { case("code read", &["code", "read", "src/lib.rs", "1:5"]).code(1).err("no such file"), case("code refs", &["code", "refs", "foo"]).code(1).err("no index yet"), case("code context", &["code", "context", "foo"]).code(1).err("no index yet"), - case( "sanitize commit-msg", &["sanitize", "commit-msg", "{ROOT}/m.txt"], ).file("m.txt", "feat: add a thing\n"), - case("sanitize pr-text", &["sanitize", "pr-text", "{ROOT}/m.txt"]).file("m.txt", "A plain description.\n"), + case( "sanitize commit", &["sanitize", "commit", "{ROOT}/m.txt"], ).file("m.txt", "feat: add a thing\n"), + case("sanitize pr", &["sanitize", "pr", "{ROOT}/m.txt"]).file("m.txt", "A plain description.\n"), case("ci", &["ci"]).out("ci: 0 passed"), // plans, glossary, skills, adr case("plan checkpoint", &["plan", "checkpoint", "smoke"]).stdin("notes\n").writes(), diff --git a/crates/cli/tests/command_names.rs b/crates/cli/tests/command_names.rs index 9964311a4..9eaa24337 100644 --- a/crates/cli/tests/command_names.rs +++ b/crates/cli/tests/command_names.rs @@ -11,15 +11,7 @@ use std::path::Path; const MAX_DEPTH: usize = 4; /// Hyphenated command paths that exist today. Do not add to this list. -const LEGACY_HYPHENATED: &[&str] = &[ - "pr ci-wait", - "pr land-wait", - "sanitize commit-msg", - "sanitize pr-text", - "watch dry-run", - "watch install-service", - "watch uninstall-service", -]; +const LEGACY_HYPHENATED: &[&str] = &["pr ci-wait", "pr land-wait"]; /// Paths under `cmd` (root excluded) that end in a hyphenated segment outside /// `legacy`, or sit deeper than `MAX_DEPTH`. @@ -142,7 +134,7 @@ fn legacy_list_has_no_stale_entries() { // Assert assert!(found.is_empty(), "stale legacy entries: {found:?}"); - assert_eq!(LEGACY_HYPHENATED.len(), 7); + assert_eq!(LEGACY_HYPHENATED.len(), 2); } /// Helpers users never run. diff --git a/crates/cli/tests/command_renames.rs b/crates/cli/tests/command_renames.rs index a75735e60..38a04a22d 100644 --- a/crates/cli/tests/command_renames.rs +++ b/crates/cli/tests/command_renames.rs @@ -210,10 +210,87 @@ fn the_memory_cc_and_doctor_commands_are_alias_rows() { } } +/// The sanitize and watch rows this table must carry, as (old, new, extra). +const SANITIZE_WATCH_ROWS: [(&str, &str, &[&str]); 5] = [ + ("sanitize commit-msg", "sanitize commit", &[]), + ("sanitize pr-text", "sanitize pr", &[]), + ("watch dry-run", "watch once", &["--dry-run"]), + ("watch install-service", "watch service install", &[]), + ("watch uninstall-service", "watch service uninstall", &[]), +]; + +#[test] +fn the_sanitize_and_watch_commands_are_alias_rows() { + // Arrange + let table = playbook::renames::COMMAND_RENAMES; + + for (old, new, extra) in SANITIZE_WATCH_ROWS { + // Act + let row = table.iter().find(|row| row.old == old); + + // Assert + let row = row.unwrap_or_else(|| panic!("`{old}` has no alias row")); + assert_eq!(row.new, new); + assert_eq!(row.extra, extra); + } +} + +#[test] +fn the_nested_watch_commands_parse() { + for words in [ + &[ + "watch", + "once", + "--dry-run", + "--since", + "2026-11-01T00:00:00Z", + ][..], + &["watch", "service", "install"], + &["watch", "service", "uninstall", "--delete-log"], + ] { + // Arrange + let args = argv(&words.join(" "), &[]); + + // Act + let parsed = Cli::try_parse_from(&args); + + // Assert + assert!(parsed.is_ok(), "{words:?}: {parsed:?}"); + } +} + +const ATTRIBUTION_LINE: &str = "Co-Authored-By: Claude "; + +#[test] +fn old_and_new_sanitize_names_strip_an_attribution_line() { + for (name, text) in [ + ("sanitize commit", "feat: x\n\nbody\n\n"), + ("sanitize commit-msg", "feat: x\n\nbody\n\n"), + ("sanitize pr", "A summary.\n\n"), + ("sanitize pr-text", "A summary.\n\n"), + ] { + // Arrange + let root = scratch("sanitize"); + let file = root.join("message.txt"); + std::fs::write(&file, format!("{text}{ATTRIBUTION_LINE}\n")).unwrap(); + let file_arg = file.to_string_lossy().into_owned(); + + // Act + let output = run(&argv(name, &[&file_arg]), "sanitize"); + + // Assert + assert_eq!(output.status.code(), Some(0), "{name}"); + let after = std::fs::read_to_string(&file).unwrap(); + assert!(!after.contains("Claude"), "{name}: {after}"); + assert!(after.starts_with(text.trim_end()), "{name}: {after}"); + } +} + /// Arguments a row needs to run offline. Most rows need none. fn sample_tail(old: &str) -> &'static [&'static str] { match old { "review triage-merge" => &["--lenses", "a"], + "sanitize commit-msg" | "sanitize pr-text" => &["missing.txt"], _ => &[], } } diff --git a/crates/cli/tests/golden/flags.txt b/crates/cli/tests/golden/flags.txt index fecb0072a..dc325e85d 100644 --- a/crates/cli/tests/golden/flags.txt +++ b/crates/cli/tests/golden/flags.txt @@ -301,11 +301,10 @@ command playbook sessions list subcommands=- aliases=- groups=List[json] arg playbook sessions list id=json long=json short=- value_names=JSON possible=true,false defaults=- aliases=- required=false hidden=false global=false action=SetTrue num_args=- parser=bool conflicts=- command playbook sessions sweep subcommands=- aliases=- groups=Sweep[dry_run] arg playbook sessions sweep id=dry_run long=dry-run short=- value_names=DRY_RUN possible=true,false defaults=- aliases=- required=true hidden=false global=false action=SetTrue num_args=- parser=bool conflicts=- -command playbook watch subcommands=once,dry-run,approve,reject,status,pause,resume,retry,log,install-service,uninstall-service aliases=- groups=Watch[-] -command playbook watch once subcommands=- aliases=- groups=Once[since] +command playbook watch subcommands=once,approve,reject,status,pause,resume,retry,log,service aliases=- groups=Watch[-] +command playbook watch once subcommands=- aliases=- groups=Once[since,dry_run] arg playbook watch once id=since long=since short=- value_names=SINCE possible=- defaults=- aliases=- required=false hidden=false global=false action=Set num_args=- parser=alloc::string::String conflicts=- -command playbook watch dry-run subcommands=- aliases=- groups=DryRun[since] -arg playbook watch dry-run id=since long=since short=- value_names=SINCE possible=- defaults=- aliases=- required=false hidden=false global=false action=Set num_args=- parser=alloc::string::String conflicts=- +arg playbook watch once id=dry_run long=dry-run short=- value_names=DRY_RUN possible=true,false defaults=- aliases=- required=false hidden=false global=false action=SetTrue num_args=- parser=bool conflicts=- command playbook watch approve subcommands=- aliases=- groups=Approve[id] arg playbook watch approve id=id long=- short=- value_names=ID possible=- defaults=- aliases=- required=true hidden=false global=false action=Set num_args=- parser=i64 conflicts=- command playbook watch reject subcommands=- aliases=- groups=Reject[id] @@ -320,9 +319,10 @@ command playbook watch log subcommands=- aliases=- groups=Log[rule,outcome,json] arg playbook watch log id=rule long=rule short=- value_names=RULE possible=- defaults=- aliases=- required=false hidden=false global=false action=Set num_args=- parser=alloc::string::String conflicts=- arg playbook watch log id=outcome long=outcome short=- value_names=OUTCOME possible=- defaults=- aliases=- required=false hidden=false global=false action=Set num_args=- parser=alloc::string::String conflicts=- arg playbook watch log id=json long=json short=- value_names=JSON possible=true,false defaults=- aliases=- required=false hidden=false global=false action=SetTrue num_args=- parser=bool conflicts=- -command playbook watch install-service subcommands=- aliases=- groups=- -command playbook watch uninstall-service subcommands=- aliases=- groups=UninstallService[delete_log] -arg playbook watch uninstall-service id=delete_log long=delete-log short=- value_names=DELETE_LOG possible=true,false defaults=- aliases=- required=false hidden=false global=false action=SetTrue num_args=- parser=bool conflicts=- +command playbook watch service subcommands=install,uninstall aliases=- groups=Service[-] +command playbook watch service install subcommands=- aliases=- groups=- +command playbook watch service uninstall subcommands=- aliases=- groups=Uninstall[delete_log] +arg playbook watch service uninstall id=delete_log long=delete-log short=- value_names=DELETE_LOG possible=true,false defaults=- aliases=- required=false hidden=false global=false action=SetTrue num_args=- parser=bool conflicts=- command playbook eval subcommands=triage,bench aliases=- groups=Eval[-] command playbook eval triage subcommands=- aliases=- groups=Triage[fixtures,prompt] arg playbook eval triage id=fixtures long=- short=- value_names=FIXTURES possible=- defaults=- aliases=- required=false hidden=false global=false action=Set num_args=- parser=std::path::PathBuf conflicts=- @@ -532,13 +532,13 @@ command playbook code context subcommands=- aliases=- groups=Context[query,max_t arg playbook code context id=query long=- short=- value_names=QUERY possible=- defaults=- aliases=- required=true hidden=false global=false action=Set num_args=- parser=alloc::string::String conflicts=- arg playbook code context id=max_tokens long=max-tokens short=- value_names=MAX_TOKENS possible=- defaults=4000 aliases=- required=false hidden=false global=false action=Set num_args=- parser=u32 conflicts=- arg playbook code context id=json long=json short=- value_names=JSON possible=true,false defaults=- aliases=- required=false hidden=false global=false action=SetTrue num_args=- parser=bool conflicts=- -command playbook sanitize subcommands=commit-msg,pr-text aliases=- groups=Sanitize[-] -command playbook sanitize commit-msg subcommands=- aliases=- groups=CommitMsg[file,check] -arg playbook sanitize commit-msg id=file long=- short=- value_names=FILE possible=- defaults=- aliases=- required=true hidden=false global=false action=Set num_args=- parser=std::path::PathBuf conflicts=- -arg playbook sanitize commit-msg id=check long=check short=- value_names=CHECK possible=true,false defaults=- aliases=- required=false hidden=false global=false action=SetTrue num_args=- parser=bool conflicts=- -command playbook sanitize pr-text subcommands=- aliases=- groups=PrText[file,check] -arg playbook sanitize pr-text id=file long=- short=- value_names=FILE possible=- defaults=- aliases=- required=true hidden=false global=false action=Set num_args=- parser=std::path::PathBuf conflicts=- -arg playbook sanitize pr-text id=check long=check short=- value_names=CHECK possible=true,false defaults=- aliases=- required=false hidden=false global=false action=SetTrue num_args=- parser=bool conflicts=- +command playbook sanitize subcommands=commit,pr aliases=- groups=Sanitize[-] +command playbook sanitize commit subcommands=- aliases=- groups=Commit[file,check] +arg playbook sanitize commit id=file long=- short=- value_names=FILE possible=- defaults=- aliases=- required=true hidden=false global=false action=Set num_args=- parser=std::path::PathBuf conflicts=- +arg playbook sanitize commit id=check long=check short=- value_names=CHECK possible=true,false defaults=- aliases=- required=false hidden=false global=false action=SetTrue num_args=- parser=bool conflicts=- +command playbook sanitize pr subcommands=- aliases=- groups=Pr[file,check] +arg playbook sanitize pr id=file long=- short=- value_names=FILE possible=- defaults=- aliases=- required=true hidden=false global=false action=Set num_args=- parser=std::path::PathBuf conflicts=- +arg playbook sanitize pr id=check long=check short=- value_names=CHECK possible=true,false defaults=- aliases=- required=false hidden=false global=false action=SetTrue num_args=- parser=bool conflicts=- command playbook ci subcommands=- aliases=- groups=Ci[json,strict,dir] arg playbook ci id=json long=json short=- value_names=JSON possible=true,false defaults=- aliases=- required=false hidden=false global=false action=SetTrue num_args=- parser=bool conflicts=- arg playbook ci id=strict long=strict short=- value_names=STRICT possible=true,false defaults=- aliases=- required=false hidden=false global=false action=SetTrue num_args=- parser=bool conflicts=- diff --git a/docs/adr/0055-watch-mode-for-github-events.md b/docs/adr/0055-watch-mode-for-github-events.md index 9296472bf..d397a4cb3 100644 --- a/docs/adr/0055-watch-mode-for-github-events.md +++ b/docs/adr/0055-watch-mode-for-github-events.md @@ -382,3 +382,11 @@ Three config keys were renamed. The old names still read and write for now. | `watch.maxCatchupHours` | `watch.catchup.maxHours` | | `watch.limits.actionsPerDay` | `watch.limits.dailyActions` | | `watch.limits.usdPerDay` | `watch.limits.dailyUsd` | + +Three commands were renamed too, and the old names still work for now: + +| Old command | New command | +|---|---| +| `watch dry-run` | `watch once --dry-run` | +| `watch install-service` | `watch service install` | +| `watch uninstall-service` | `watch service uninstall` | diff --git a/docs/guides/16-watch-acceptance-run.md b/docs/guides/16-watch-acceptance-run.md index 4a11e64f2..a524fabe9 100644 --- a/docs/guides/16-watch-acceptance-run.md +++ b/docs/guides/16-watch-acceptance-run.md @@ -20,15 +20,15 @@ playbook config set watch.rule.label-new '{"on":"issue.opened","do":"label","aut playbook config set watch.rule.thanks '{"on":"issue.opened","do":"comment","autonomy":"auto","with":{"text":"Thanks, we will look."}}' --global playbook config set watch.rule.pick-label '{"on":"issue.opened","do":"triage_issue","decide":"model","with":{"labels":["bug","docs"]},"limits":{"usd_per_day":1}}' --global playbook config set watch.enabled true --global -playbook watch dry-run +playbook watch once --dry-run ``` -Expected: `dry-run` lists the three rules with their level and prints no write. Create the labels `triage`, `bug` and `docs` in the repository first, or the label calls fail. +Expected: `--dry-run` lists the three rules with their level and prints no write. Create the labels `triage`, `bug` and `docs` in the repository first, or the label calls fail. ## Run 1. Start the loop in a terminal you will leave open, and note the time: `playbook watch`. -2. Or install the timer instead (one of the two, not both): `playbook watch install-service`, then `playbook doctor check` and expect the row `watch timer installed`. +2. Or install the timer instead (one of the two, not both): `playbook watch service install`, then `playbook doctor check` and expect the row `watch timer installed`. 3. The first poll of each source prints `watching from now` and queues nothing. Wait for it before creating issues. 4. Create 6 issues over the day, a few in the first hour and the rest spread out. Title and body can be anything. 5. Close the laptop lid for at least 2 hours in the middle of the day with the loop (or the timer) installed, then open it. Create 2 more issues while it is asleep, from a phone or another machine. @@ -65,8 +65,8 @@ Paste these into the pull request: ## Clean up ```sh -playbook watch uninstall-service # only if you installed the timer +playbook watch service uninstall # only if you installed the timer playbook config set watch.enabled false --global ``` -The audit log stays until you add `--delete-log` to `uninstall-service`. +The audit log stays until you add `--delete-log` to `watch service uninstall`. diff --git a/docs/internals/01-launcher-and-hooks.md b/docs/internals/01-launcher-and-hooks.md index 44ae28c19..8db68a84a 100644 --- a/docs/internals/01-launcher-and-hooks.md +++ b/docs/internals/01-launcher-and-hooks.md @@ -106,7 +106,7 @@ A tagged handoff with no marker belongs to a session still running and is left a **`commit-message-sanitizer`** (PreToolUse): - Removes AI attribution (a `Claude-Session:` line, a claude.ai link, a "Generated with" footer, an AI credit trailer or `--author`) from the message of a commit, tag, merge or PR. It never blocks: it returns the same command with the message cleaned and no permission decision. -- A message kept in a file is never rewritten on disk. The cleaned text is read from `-F -` or a heredoc. A recognised `git commit` also gets `-s` unless the message already has a sign-off, `commit.signOff` is false, or the repo's own hook adds it. Signing (`-S`) is left to git config. The same rule backs `playbook sanitize commit-msg `. +- A message kept in a file is never rewritten on disk. The cleaned text is read from `-F -` or a heredoc. A recognised `git commit` also gets `-s` unless the message already has a sign-off, `commit.signOff` is false, or the repo's own hook adds it. Signing (`-S`) is left to git config. The same rule backs `playbook sanitize commit `. - It also lints the prose of those messages, of PR text, and of `gh pr comment`, `gh pr review` and `gh issue` text against the writing-style phrase and structure table, and adds the findings to the model's context. `hooks.proseLint.mode` set to `block` denies the call on a hard finding. `playbook prose check` runs the same table on files. It also warns on passive voice, a soft finding that never fails `--strict`. When a file `.facts` sits beside the checked file, it checks that every number, identifier, path and reference in the text appears in the facts, and it checks the text against the length limit of the `kind:` named on the first line of the facts file. Best effort, not a security boundary. **`policy-guard`.** When off it allows every call. When on, it denies: @@ -186,7 +186,7 @@ It reads the command text, so heredoc scripts, script files and paths built at r `playbook setup` does not install a git hook, because a repo may already manage its hooks (a `core.hooksPath`, husky, lefthook) and a second hook would clobber or be clobbered by them. To get the same cleanup for commits made outside an agent, add one line to the repo's own `commit-msg` hook: ```sh -playbook sanitize commit-msg "$1" +playbook sanitize commit "$1" ``` It rewrites the message file in place and always exits 0, even when the file cannot be read or written, so it never blocks a commit. With `--check` it reports instead: exit 1 for something it would remove or a missing `Signed-off-by` line, exit 2 when the file cannot be read, so CI can tell them apart. diff --git a/docs/reference/cli-and-config.md b/docs/reference/cli-and-config.md index c9206404f..9544d5905 100644 --- a/docs/reference/cli-and-config.md +++ b/docs/reference/cli-and-config.md @@ -1280,22 +1280,22 @@ Remove AI attribution lines from message text For callers that are not an agent hook, such as a git `commit-msg` hook or CI. Each subcommand rewrites FILE in place unless `--check` is given, and prints one line per removed line to stderr: its number and the shape of the attribution, never its text. Without `--check` the exit code is always 0, even when FILE cannot be read or written. -Subcommands: `commit-msg`, `pr-text` +Subcommands: `commit`, `pr` -### `playbook sanitize commit-msg` +### `playbook sanitize commit` Clean a commit message file, such as git's `.git/COMMIT_EDITMSG` -Example: `playbook sanitize commit-msg .git/COMMIT_EDITMSG` +Example: `playbook sanitize commit .git/COMMIT_EDITMSG` - ``: File holding the message - `--check`: Report what would be removed, without writing. Exits 1 if anything would be removed, and 2 if FILE cannot be read -### `playbook sanitize pr-text` +### `playbook sanitize pr` Clean a PR title or body saved to a file -Example: `playbook sanitize pr-text /tmp/body.md` +Example: `playbook sanitize pr /tmp/body.md` - ``: File holding the text - `--check`: Report what would be removed, without writing. Exits 1 if anything would be removed, and 2 if FILE cannot be read @@ -1860,7 +1860,7 @@ With no verb it runs in the foreground until you stop it, polling every `watch.p Example: `playbook watch once` -Subcommands: `approve`, `dry-run`, `install-service`, `log`, `once`, `pause`, `reject`, `resume`, `retry`, `status`, `uninstall-service` +Subcommands: `approve`, `log`, `once`, `pause`, `reject`, `resume`, `retry`, `service`, `status` ### `playbook watch approve` @@ -1872,22 +1872,6 @@ Example: `playbook watch approve 3` - ``: Proposal number printed by `watch once` -### `playbook watch dry-run` - -Show the rules and what a poll would propose, and change nothing - -Example: `playbook watch dry-run` - -- `--since `: Look at events from this UTC time, for example 2026-11-01T00:00:00Z - -### `playbook watch install-service` - -Install a timer that runs `watch once` every 60 seconds - -A launchd agent on macOS and a systemd user timer on Linux. No process stays running between polls. The timer finds the GitHub token through `gh auth token`, so run `gh auth login` first. - -Example: `playbook watch install-service` - ### `playbook watch log` Print the audit log, oldest first @@ -1902,11 +1886,12 @@ Example: `playbook watch log --rule triage --outcome done` Poll every repo once and run the items you approved -A repo watched for the first time starts from now, so turning watch mode on never replays old issues. Prints `watch already running` and exits when another watch process holds the lock. +A repo watched for the first time starts from now, so turning watch mode on never replays old issues. Prints `watch already running` and exits when another watch process holds the lock. With `--dry-run` it shows the rules and what a poll would propose, and changes nothing. Example: `playbook watch once --since 2026-11-01T00:00:00Z` - `--since `: Replay events from this UTC time, for example 2026-11-01T00:00:00Z +- `--dry-run`: Show the rules and what a poll would propose, and change nothing ### `playbook watch pause` @@ -1938,24 +1923,38 @@ Example: `playbook watch retry 3` - ``: Number of the dead item, shown by `watch status` -### `playbook watch status` +### `playbook watch service` -Show whether watch runs, the queue, the limits and the dead list +Install or remove the timer that runs `watch once` -Example: `playbook watch status --json` +Subcommands: `install`, `uninstall` -- `--json`: Print the status as JSON +### `playbook watch service install` -### `playbook watch uninstall-service` +Install a timer that runs `watch once` every 60 seconds + +A launchd agent on macOS and a systemd user timer on Linux. No process stays running between polls. The timer finds the GitHub token through `gh auth token`, so run `gh auth login` first. + +Example: `playbook watch service install` -Remove the timer that `install-service` made +### `playbook watch service uninstall` + +Remove the timer that `service install` made The audit log stays unless you ask for it to go. -Example: `playbook watch uninstall-service --delete-log` +Example: `playbook watch service uninstall --delete-log` - `--delete-log`: Also delete the audit log +### `playbook watch status` + +Show whether watch runs, the queue, the limits and the dead list + +Example: `playbook watch status --json` + +- `--json`: Print the status as JSON + ### `playbook worktree` Clean up git worktrees whose branches have landed