Skip to content
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ set as `PROOFLINE_TOKEN`. A token that works in one organization needs no

To register MCP without a prompt, run `proofline agent install CLIENT --yes`. Supported clients include `claude-code` (or `claude`), `cursor`, `codex`, `gemini`, and `kiro`. Without `--yes`, the command previews the entry and asks for confirmation, while `--print` previews without writing. Existing Proofline entries remain unchanged. New entries use this executable's absolute path and store no credentials. Claude Code uses the top-level `mcpServers` in `~/.claude.json`; a custom `CLAUDE_CONFIG_DIR` requires manual configuration with `--print`.

`proofline agent install claude-code --review-hook` adds a Stop hook to `~/.claude/settings.json` instead of the MCP server, with the same preview, `--yes` and `--print`. When Claude Code is about to end a turn, the hook runs `proofline hook agent-stop`, which reviews the checkout's local changes, untracked files included, with the same secret preflight as a local review. Findings at or above the threshold go back to the agent once, as untrusted text with their IDs and the review link, so it can address them before the turn ends; a second stop with the same changes requests no new review. The hook stays silent in a repository Proofline does not know and never prints a credential. Per repository, `git config proofline.hook.agent-stop.mode warn` reports findings to you without holding the agent, and `failOn`, `onIncomplete`, `timeout` (default 300 seconds) and `minInterval` (seconds between reviews, default 0) work as for the Git hooks. `PROOFLINE_AGENT_HOOK_TIMEOUT` and `PROOFLINE_AGENT_HOOK_MIN_INTERVAL` override them per environment, and `--max-findings N` or `PROOFLINE_AGENT_HOOK_MAX_FINDINGS` caps the findings handed to the agent (default 10). `proofline agent uninstall claude-code --review-hook` removes only the entry install wrote; pass the same `--max-findings` it was installed with. Install refuses when `~/.claude` is inside a Git working tree; use `--print` and add the entry by hand.

`--review-hook` also works for `codex` (a `Stop` hook in `~/.codex/hooks.json`; trust it in Codex's `/hooks` before it runs), `gemini` (an `AfterAgent` hook in `~/.gemini/settings.json`) and `cursor` (a `stop` hook in `~/.cursor/hooks.json`); `uninstall` takes the same agent names. Each entry runs `proofline hook agent-stop --agent <agent>`, which reads that agent's stop input and answers in its own form. Cursor shows the developer nothing from a stop hook, so there notes go unseen and only findings handed to the agent appear. Kiro is not supported: its stop hook has no documented way for a command to keep the agent working. These three agents take the hook as one shell command, so on Windows install refuses and `--print` shows the entry to add by hand.

Native knowledge, plan, fix and configuration commands send the selected organization as `organization_id` in each MCP tool call. These commands need a person's token: a service account key reads only reviews, findings and review guidance over MCP, and the server refuses it the rest. With a `PROOFLINE_TOKEN` that works in more than one organization, select an authorized UUID using `--org ORGANIZATION_ID` or `PROOFLINE_ORGANIZATION_ID`; the flag takes precedence. A token that works in exactly one, such as a personal token, needs neither. A stored device sign-in uses its approved organization and refuses a different selection. For example, `proofline --org ORGANIZATION_ID wiki list --repo owner/name` and `proofline --org ORGANIZATION_ID config get` target that organization with a shared MCP OAuth credential. Selection grants no authority: the server checks each call, and a foreign target returns its refusal with a nonzero exit. MCP OAuth credentials remain limited to MCP and cannot use REST commands. The raw `proofline mcp` bridge preserves the caller's messages and per-call target unchanged. It needs no organization selection and sends the MCP server nothing before the caller's first message, so it works with a service account key or a token that works in several organizations.

## Reviews, history, and reruns
Expand Down
297 changes: 265 additions & 32 deletions src/agent.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! User-level configuration for the existing credential-free MCP launcher.
//! User-level configuration for the existing credential-free MCP launcher,
//! and for the Claude Code Stop hook that runs `proofline hook agent-stop`.

mod config;
mod store;
Expand All @@ -25,6 +26,9 @@ pub(crate) struct AgentArgs {
enum AgentCommand {
/// Add Proofline to a coding agent's user configuration after confirmation.
Install(InstallArgs),
/// Remove the review hook `agent install --review-hook` wrote, after
/// confirmation.
Uninstall(UninstallArgs),
}

#[derive(Debug, Args)]
Expand All @@ -38,6 +42,29 @@ struct InstallArgs {
/// Save the previewed entry without an interactive confirmation.
#[arg(long, conflicts_with = "print")]
yes: bool,
/// Add the review hook to Claude Code's settings instead of the MCP
/// server: Proofline reviews the checkout's changes when the agent stops.
#[arg(long)]
review_hook: bool,
/// The most findings the review hook hands the agent in full, 1 to 100.
#[arg(long, value_name = "N", requires = "review_hook", value_parser = clap::value_parser!(u8).range(1..=100))]
max_findings: Option<u8>,
}

#[derive(Debug, Args)]
struct UninstallArgs {
/// Coding agent whose user configuration holds the entry.
#[arg(value_enum)]
client: Client,
/// Remove the review hook; the MCP server entry is not removed here.
#[arg(long, required = true)]
review_hook: bool,
/// The `--max-findings` the hook was installed with, so the entry matches.
#[arg(long, value_name = "N", value_parser = clap::value_parser!(u8).range(1..=100))]
max_findings: Option<u8>,
/// Remove the entry without an interactive confirmation.
#[arg(long)]
yes: bool,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
Expand Down Expand Up @@ -84,6 +111,27 @@ enum InstallError {
"CLAUDE_CONFIG_DIR selects custom configuration; use --print and configure Claude Code manually"
)]
CustomClaudeHome,
#[error(
"--review-hook supports claude-code, codex, gemini and cursor; Kiro's stop hook has no documented way for a command to keep the agent working"
)]
ReviewHookClient,
#[error(
"{0} runs hooks as one shell string, and how to quote a path in it on Windows is not documented; use --print and add the review hook by hand"
)]
ShellHookWindows(Client),
#[error(
"GEMINI_CLI_HOME selects a different directory; use --print and add the review hook to that user configuration manually"
)]
CustomGeminiHome,
#[error(
"the agent's settings already run a Proofline review hook with other settings; remove it with `proofline agent uninstall {0} --review-hook` and the options it was installed with, then install again. The configuration stays unchanged"
)]
ReviewHookDiffers(String),
#[error(
"could not use {}: {problem}. The file stays unchanged; use --print and add the review hook by hand",
path.display()
)]
Settings { path: PathBuf, problem: String },
#[error("could not find an absolute user home directory")]
Home,
#[error(
Expand Down Expand Up @@ -156,22 +204,46 @@ enum Outcome {
Cancelled,
Existing,
Installed,
Removed,
}

pub(crate) async fn run(args: AgentArgs, origin: Origin) -> anyhow::Result<()> {
tokio::task::spawn_blocking(move || {
let AgentCommand::Install(args) = args.command;
let home = std::env::home_dir().ok_or(InstallError::Home)?;
let custom_claude_home = std::env::var_os("CLAUDE_CONFIG_DIR").is_some();
let custom_gemini_home = std::env::var_os("GEMINI_CLI_HOME").is_some();
let codex_home = std::env::var_os("CODEX_HOME");
if args.client == Client::ClaudeCode
&& !args.print
&& std::env::var_os("CLAUDE_CONFIG_DIR").is_some()
{
return Err(InstallError::CustomClaudeHome);
}
let stdin = io::stdin();
let stdout = io::stdout();
let stderr = io::stderr();
let args = match args.command {
AgentCommand::Install(args) => args,
AgentCommand::Uninstall(args) => {
if config::hook_file(args.client).is_none() {
return Err(InstallError::ReviewHookClient);
}
if args.client == Client::ClaudeCode && custom_claude_home {
return Err(InstallError::CustomClaudeHome);
}
if args.client == Client::Gemini && custom_gemini_home {
return Err(InstallError::CustomGeminiHome);
}
if args.client == Client::Codex
&& codex_home
.as_deref()
.is_some_and(|selected| Path::new(selected) != home.join(".codex"))
{
return Err(InstallError::CustomCodexHome);
}
return uninstall(&home, &args, &origin, &mut stdin.lock(), &mut stderr.lock());
}
};
if args.client == Client::ClaudeCode && !args.print && custom_claude_home {
return Err(InstallError::CustomClaudeHome);
}
if args.review_hook && args.client == Client::Gemini && !args.print && custom_gemini_home {
return Err(InstallError::CustomGeminiHome);
}
install(
&home,
codex_home.as_deref(),
Expand All @@ -196,7 +268,32 @@ fn install(
output: &mut impl Write,
diagnostics: &mut impl Write,
) -> Result<Outcome, InstallError> {
let snippet = config::snippet(args.client, origin)?;
let hook_file = if args.review_hook {
Some(config::hook_file(args.client).ok_or(InstallError::ReviewHookClient)?)
} else {
None
};
let (snippet, relative, what) = if let Some(file) = hook_file {
(
config::review_hook_snippet(args.client, origin, args.max_findings)?,
file,
"review hook",
)
} else {
(
config::snippet(args.client, origin)?,
args.client.relative_path(),
"server",
)
};
let settings = home.join(relative);
let prepare = |current: Option<&[u8]>| {
if args.review_hook {
config::add_review_hook(args.client, current, &settings, origin, args.max_findings)
} else {
config::prepare(args.client, current, origin)
}
};
if args.print {
output
.write_all(snippet.as_bytes())
Expand All @@ -206,50 +303,46 @@ fn install(
if !home.is_absolute() {
return Err(InstallError::Home);
}
if args.review_hook && cfg!(windows) && config::takes_a_shell_string(args.client) {
return Err(InstallError::ShellHookWindows(args.client));
}
if args.client == Client::Codex
&& codex_home.is_some_and(|selected| Path::new(selected) != home.join(".codex"))
{
return Err(InstallError::CustomCodexHome);
}
let layout = store::Layout::new(home, args.client)?;
let layout = store::Layout::new(home, relative)?;
let before = layout.read()?;
let config::Update::Change(bytes) = config::prepare(args.client, before.bytes(), origin)?
else {
let config::Update::Change(bytes) = prepare(before.bytes())? else {
existing(&layout, diagnostics)?;
return Ok(Outcome::Existing);
};
layout.writable(&before)?;
writeln!(
diagnostics,
"Add this {0} server to {1}:\n{snippet}",
"Add this {0} {what} to {1}:\n{snippet}",
args.client,
layout.target().display()
)
.map_err(|error| InstallError::console("show the proposed server entry", error))?;
if !args.yes {
write!(diagnostics, "Write this entry? [y/N] ")
.and_then(|()| diagnostics.flush())
.map_err(|error| InstallError::console("ask for confirmation", error))?;
let mut answer = String::new();
input
.take(65)
.read_line(&mut answer)
.map_err(|error| InstallError::console("read confirmation", error))?;
if answer.len() > 64
|| !answer.ends_with('\n')
|| !matches!(answer.trim().to_ascii_lowercase().as_str(), "y" | "yes")
{
writeln!(diagnostics, "No configuration was written.").map_err(|error| {
InstallError::console("report the unchanged configuration", error)
})?;
return Ok(Outcome::Cancelled);
}
if !args.yes && !confirm(input, diagnostics, "Write this entry?")? {
return Ok(Outcome::Cancelled);
}
match layout.save(&before, &bytes, origin)? {
match layout.save(&before, &bytes, &prepare)? {
store::Saved::Existing => {
existing(&layout, diagnostics)?;
Ok(Outcome::Existing)
}
store::Saved::Installed if args.review_hook => {
let trust = if args.client == Client::Codex {
" Codex runs it only once you trust it: open `/hooks` in Codex, and again after any reinstall."
} else {
""
};
writeln!(diagnostics, "Added the Proofline review hook to {}. When {} stops in a repository connected to Proofline, the hook reviews its local changes; sign in with `{}` first.{trust}", layout.target().display(), args.client, crate::config::LOGIN)
.map_err(|error| InstallError::console("report the saved configuration", error))?;
Ok(Outcome::Installed)
}
store::Saved::Installed => {
writeln!(diagnostics, "Added Proofline to {}. Sign in to the same console with `{}`, using the same `--base-url`; the coding agent uses the CLI's existing credential.", layout.target().display(), crate::config::LOGIN)
.map_err(|error| InstallError::console("report the saved configuration", error))?;
Expand All @@ -258,6 +351,146 @@ fn install(
}
}

/// Asks `question` and reads a y/yes answer; anything else writes nothing.
fn confirm(
input: &mut impl BufRead,
diagnostics: &mut impl Write,
question: &str,
) -> Result<bool, InstallError> {
write!(diagnostics, "{question} [y/N] ")
.and_then(|()| diagnostics.flush())
.map_err(|error| InstallError::console("ask for confirmation", error))?;
let mut answer = String::new();
input
.take(65)
.read_line(&mut answer)
.map_err(|error| InstallError::console("read confirmation", error))?;
if answer.len() > 64
|| !answer.ends_with('\n')
|| !matches!(answer.trim().to_ascii_lowercase().as_str(), "y" | "yes")
{
writeln!(diagnostics, "No configuration was written.")
.map_err(|error| InstallError::console("report the unchanged configuration", error))?;
return Ok(false);
}
Ok(true)
}

/// Removes the exact review hook `install --review-hook` writes for this
/// executable, base URL and cap, and nothing else.
fn uninstall(
home: &Path,
args: &UninstallArgs,
origin: &Origin,
input: &mut impl BufRead,
diagnostics: &mut impl Write,
) -> Result<Outcome, InstallError> {
if !home.is_absolute() {
return Err(InstallError::Home);
}
let file = config::hook_file(args.client).ok_or(InstallError::ReviewHookClient)?;
let layout = store::Layout::new(home, file)?;
let before = layout.read()?;
let report = |diagnostics: &mut dyn Write, message: String| {
writeln!(diagnostics, "{message}")
.map_err(|error| InstallError::console("report the configuration", error))
};
let bytes = match config::remove_review_hook(
args.client,
before.bytes(),
layout.target(),
origin,
args.max_findings,
)? {
config::Removal::Change(bytes) => bytes,
config::Removal::Absent => {
report(
diagnostics,
format!(
"No Proofline review hook is installed in {}.",
layout.target().display()
),
)?;
return Ok(Outcome::Existing);
}
config::Removal::Edited => {
report(
diagnostics,
format!(
"The Proofline review hook in {} is not the entry this command writes (its path, base URL or --max-findings differ), so it was left unchanged.",
layout.target().display()
),
)?;
return Ok(Outcome::Existing);
}
};
layout.writable(&before)?;
if !args.yes
&& !confirm(
input,
diagnostics,
&format!(
"Remove the Proofline review hook from {}?",
layout.target().display()
),
)?
{
return Ok(Outcome::Cancelled);
}
// The file can change while the prompt waits; remember why nothing was removed.
let edited = std::cell::Cell::new(false);
let prepare = |current: Option<&[u8]>| {
Ok(
match config::remove_review_hook(
args.client,
current,
layout.target(),
origin,
args.max_findings,
)? {
config::Removal::Change(bytes) => config::Update::Change(bytes),
config::Removal::Absent => config::Update::Existing,
config::Removal::Edited => {
edited.set(true);
config::Update::Existing
}
},
)
};
match layout.save(&before, &bytes, &prepare)? {
store::Saved::Existing if edited.get() => {
report(
diagnostics,
format!(
"The Proofline review hook in {} changed while waiting and is not the entry this command writes, so it was left unchanged.",
layout.target().display()
),
)?;
Ok(Outcome::Existing)
}
store::Saved::Existing => {
report(
diagnostics,
format!(
"No Proofline review hook is installed in {}.",
layout.target().display()
),
)?;
Ok(Outcome::Existing)
}
store::Saved::Installed => {
report(
diagnostics,
format!(
"Removed the Proofline review hook from {}.",
layout.target().display()
),
)?;
Ok(Outcome::Removed)
}
}
}

fn existing(layout: &store::Layout, diagnostics: &mut impl Write) -> Result<(), InstallError> {
writeln!(
diagnostics,
Expand Down
Loading