Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions .github/workflows/commit-message-guard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -91,15 +96,15 @@ 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.
echo "::warning title=commit-message-guard::the PR $part could not be read, so it was not checked"
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
Expand Down
10 changes: 5 additions & 5 deletions crates/cli/src/command_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/doctor/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Row> {
Expand Down
40 changes: 23 additions & 17 deletions crates/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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<String>,
},
/// 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<String>,
dry_run: bool,
},
/// Carry out a proposal
///
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 2 additions & 4 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
25 changes: 25 additions & 0 deletions crates/cli/src/renames.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 21 additions & 17 deletions crates/cli/src/watch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -251,7 +251,7 @@ pub fn once<W: GithubWrite + RecoverOps, C: Clock, H: Http>(
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<W: GithubWrite, C: Clock, H: Http>(
ctx: &Ctx<'_, W, C>,
Expand Down Expand Up @@ -371,16 +371,20 @@ fn gh_token() -> Option<String> {
(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>,
home: &Path,
data: &Path,
) -> Option<Result<String, String>> {
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))
Expand Down Expand Up @@ -420,17 +424,15 @@ pub fn run(cmd: Option<&WatchCommand>) -> Result<String, String> {
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) {
return out;
}
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()
Expand All @@ -450,7 +452,7 @@ pub fn run(cmd: Option<&WatchCommand>) -> Result<String, String> {
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}"))?;
Expand Down Expand Up @@ -483,18 +485,20 @@ pub fn run(cmd: Option<&WatchCommand>) -> Result<String, String> {
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),
Expand Down
4 changes: 2 additions & 2 deletions crates/cli/src/watch/service.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -30,7 +30,7 @@ pub fn kind_here() -> Result<Kind, String> {
} 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())
}
}

Expand Down
9 changes: 4 additions & 5 deletions crates/cli/tests/cli_smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,15 +575,14 @@ fn table() -> Vec<Case> {
// 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")
Expand Down Expand Up @@ -642,8 +641,8 @@ fn table() -> Vec<Case> {
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(),
Expand Down
12 changes: 2 additions & 10 deletions crates/cli/tests/command_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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.
Expand Down
Loading
Loading