Skip to content
Open
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ 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`.

Inspect an existing registration with `proofline agent status CLIENT`. This read-only, offline command reports whether the user-level configuration has a missing, invalid, or valid Proofline registration structure. It exits `0` when printing `Configuration valid:` or `Unable to verify:` (for example, when `CLAUDE_CONFIG_DIR` or a relative `CODEX_HOME` is set), and exits `1` when printing `Missing registration:` or `Invalid registration:`. Executable availability, local and project scopes, and live MCP connectivity are not checked, and the configured command is never executed.

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
84 changes: 51 additions & 33 deletions src/agent.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! User-level configuration for the existing credential-free MCP launcher.

mod config;
mod status;
mod store;

#[cfg(test)]
Expand All @@ -18,30 +19,39 @@ use crate::origin::Origin;
#[derive(Debug, Args)]
pub(crate) struct AgentArgs {
#[command(subcommand)]
command: AgentCommand,
pub(crate) command: AgentCommand,
}

#[derive(Debug, Subcommand)]
enum AgentCommand {
pub(crate) enum AgentCommand {
/// Add Proofline to a coding agent's user configuration after confirmation.
Install(InstallArgs),
/// Inspect a coding agent's existing user configuration for Proofline registration structure.
Status(StatusArgs),
}

#[derive(Debug, Args)]
struct InstallArgs {
pub(crate) struct StatusArgs {
/// Coding agent whose user configuration is inspected.
#[arg(value_enum)]
pub(crate) client: Client,
}

#[derive(Debug, Args)]
pub(crate) struct InstallArgs {
/// Coding agent whose user configuration receives the MCP server.
#[arg(value_enum)]
client: Client,
pub(crate) client: Client,
/// Print the credential-free server entry without writing any file.
#[arg(long)]
print: bool,
pub(crate) print: bool,
/// Save the previewed entry without an interactive confirmation.
#[arg(long, conflicts_with = "print")]
yes: bool,
pub(crate) yes: bool,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
enum Client {
pub(crate) enum Client {
#[value(alias = "claude")]
ClaudeCode,
Codex,
Expand Down Expand Up @@ -158,33 +168,41 @@ enum Outcome {
Installed,
}

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 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);
pub(crate) async fn run(args: AgentArgs, origin: Origin) -> anyhow::Result<crate::Verdict> {
match args.command {
AgentCommand::Install(args) => {
tokio::task::spawn_blocking(move || {
let home = std::env::home_dir().ok_or(InstallError::Home)?;
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();
install(
&home,
codex_home.as_deref(),
&args,
&origin,
&mut stdin.lock(),
&mut stdout.lock(),
&mut stderr.lock(),
)
})
.await
.map_err(InstallError::Task)??;
Ok(crate::Verdict::Done)
}
let stdin = io::stdin();
let stdout = io::stdout();
let stderr = io::stderr();
install(
&home,
codex_home.as_deref(),
&args,
&origin,
&mut stdin.lock(),
&mut stdout.lock(),
&mut stderr.lock(),
)
})
.await
.map_err(InstallError::Task)??;
Ok(())
AgentCommand::Status(args) => status_run(args.client),
}
}

pub(crate) fn status_run(client: Client) -> anyhow::Result<crate::Verdict> {
status::run(client)
}

fn install(
Expand Down
233 changes: 233 additions & 0 deletions src/agent/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,239 @@ pub(super) fn prepare(
}
}

pub(super) fn inspect_registration(client: Client, bytes: &[u8]) -> super::status::Status {
match client {
Client::Codex => inspect_codex(bytes),
Client::ClaudeCode | Client::Cursor | Client::Gemini | Client::Kiro => {
inspect_json(client, bytes)
}
}
}

fn inspect_json(client: Client, bytes: &[u8]) -> super::status::Status {
use super::status::Status;
if serde_json::from_slice::<UniqueJson>(bytes).is_err() {
return Status::Invalid("could not parse configuration file as valid JSON.");
}
let document: Value = match serde_json::from_slice(bytes) {
Ok(v) => v,
Err(_) => return Status::Invalid("could not parse configuration file as valid JSON."),
};
let Some(root) = document.as_object() else {
return Status::Invalid("configuration root must be a JSON object.");
};
let Some(servers) = root.get("mcpServers") else {
return Status::Missing("No Proofline MCP server is registered in the configuration.");
};
let Some(servers_obj) = servers.as_object() else {
return Status::Invalid("mcpServers member must be an object.");
};
let Some(proofline) = servers_obj.get("proofline") else {
return Status::Missing("No Proofline MCP server is registered in the configuration.");
};
validate_json_proofline(client, proofline)
}

const INVALID_ENV_ENTRY: &str = "env contains an invalid environment entry.";

fn valid_env_entry(key: &str, value: &str) -> bool {
!key.is_empty() && !key.contains('\0') && !key.contains('=') && !value.contains('\0')
}

fn validate_json_proofline(_client: Client, proofline: &Value) -> super::status::Status {
use super::status::Status;
let Some(obj) = proofline.as_object() else {
return Status::Invalid("Proofline registration must be an object.");
};
if let Some(transport) = obj.get("type")
&& transport.as_str() != Some("stdio")
{
return Status::Invalid("Proofline registration type must be \"stdio\".");
}
let Some(cmd) = obj.get("command") else {
return Status::Invalid("Proofline registration must include a command field.");
};
let Some(cmd_str) = cmd.as_str() else {
return Status::Invalid("command field must be a string.");
};
if cmd_str.trim().is_empty() {
return Status::Invalid("command field must be a non-empty string.");
}
if cmd_str.contains('\0') {
return Status::Invalid("command field contains an invalid NUL character.");
}
if let Some(args) = obj.get("args") {
let Some(arr) = args.as_array() else {
return Status::Invalid("args field must be an array of strings.");
};
for arg in arr {
let Some(arg_str) = arg.as_str() else {
return Status::Invalid("args elements must be strings.");
};
if arg_str.contains('\0') {
return Status::Invalid("args elements must not contain NUL characters.");
}
}
}
if let Some(env) = obj.get("env") {
let Some(map) = env.as_object() else {
return Status::Invalid("env field must be an object.");
};
for (k, v) in map {
let Some(val_str) = v.as_str() else {
return Status::Invalid(INVALID_ENV_ENTRY);
};
if !valid_env_entry(k, val_str) {
return Status::Invalid(INVALID_ENV_ENTRY);
}
}
}
Status::Valid
}

fn inspect_codex(bytes: &[u8]) -> super::status::Status {
use super::status::Status;
let Ok(raw) = std::str::from_utf8(bytes) else {
return Status::Invalid("configuration file must be valid UTF-8.");
};
let Ok(document) = raw.parse::<DocumentMut>() else {
return Status::Invalid("could not parse configuration file as valid TOML.");
};
let Some(servers) = document.get("mcp_servers") else {
return Status::Missing("No Proofline MCP server is registered in the configuration.");
};
match servers {
Item::Table(servers_tbl) => {
let Some(proofline) = servers_tbl.get("proofline") else {
return Status::Missing(
"No Proofline MCP server is registered in the configuration.",
);
};
match proofline {
Item::Table(p) => validate_toml_table(p),
Item::Value(toml_edit::Value::InlineTable(p)) => validate_toml_inline(p),
_ => Status::Invalid("Proofline registration must be a table."),
}
}
Item::Value(toml_edit::Value::InlineTable(servers_tbl)) => {
let Some(proofline) = servers_tbl.get("proofline") else {
return Status::Missing(
"No Proofline MCP server is registered in the configuration.",
);
};
match proofline {
toml_edit::Value::InlineTable(p) => validate_toml_inline(p),
_ => Status::Invalid("Proofline registration must be a table."),
}
}
_ => Status::Invalid("mcp_servers member must be a table."),
}
}

fn validate_toml_table(proofline: &Table) -> super::status::Status {
use super::status::Status;
let Some(cmd_item) = proofline.get("command") else {
return Status::Invalid("Proofline registration must include a command field.");
};
let Some(cmd_val) = cmd_item.as_value() else {
return Status::Invalid("command field must be a string.");
};
let Some(cmd_str) = cmd_val.as_str() else {
return Status::Invalid("command field must be a string.");
};
if cmd_str.trim().is_empty() {
return Status::Invalid("command field must be a non-empty string.");
}
if cmd_str.contains('\0') {
return Status::Invalid("command field contains an invalid NUL character.");
}
if let Some(args_item) = proofline.get("args") {
let Some(args_val) = args_item.as_value() else {
return Status::Invalid("args field must be an array of strings.");
};
let Some(arr) = args_val.as_array() else {
return Status::Invalid("args field must be an array of strings.");
};
for arg in arr {
let Some(arg_str) = arg.as_str() else {
return Status::Invalid("args elements must be strings.");
};
if arg_str.contains('\0') {
return Status::Invalid("args elements must not contain NUL characters.");
}
}
}
if let Some(env_item) = proofline.get("env") {
match env_item {
Item::Table(tbl) => {
for (k, v) in tbl {
let Some(val_str) = v.as_value().and_then(|v| v.as_str()) else {
return Status::Invalid(INVALID_ENV_ENTRY);
};
if !valid_env_entry(k, val_str) {
return Status::Invalid(INVALID_ENV_ENTRY);
}
}
}
Item::Value(toml_edit::Value::InlineTable(tbl)) => {
for (k, v) in tbl {
let Some(val_str) = v.as_str() else {
return Status::Invalid(INVALID_ENV_ENTRY);
};
if !valid_env_entry(k, val_str) {
return Status::Invalid(INVALID_ENV_ENTRY);
}
}
}
_ => return Status::Invalid("env field must be a table."),
}
}
Status::Valid
}

fn validate_toml_inline(proofline: &InlineTable) -> super::status::Status {
use super::status::Status;
let Some(cmd_val) = proofline.get("command") else {
return Status::Invalid("Proofline registration must include a command field.");
};
let Some(cmd_str) = cmd_val.as_str() else {
return Status::Invalid("command field must be a string.");
};
if cmd_str.trim().is_empty() {
return Status::Invalid("command field must be a non-empty string.");
}
if cmd_str.contains('\0') {
return Status::Invalid("command field contains an invalid NUL character.");
}
if let Some(args_val) = proofline.get("args") {
let Some(arr) = args_val.as_array() else {
return Status::Invalid("args field must be an array of strings.");
};
for arg in arr {
let Some(arg_str) = arg.as_str() else {
return Status::Invalid("args elements must be strings.");
};
if arg_str.contains('\0') {
return Status::Invalid("args elements must not contain NUL characters.");
}
}
}
if let Some(env_val) = proofline.get("env") {
let Some(tbl) = env_val.as_inline_table() else {
return Status::Invalid("env field must be a table.");
};
for (k, v) in tbl {
let Some(val_str) = v.as_str() else {
return Status::Invalid(INVALID_ENV_ENTRY);
};
if !valid_env_entry(k, val_str) {
return Status::Invalid(INVALID_ENV_ENTRY);
}
}
}
Status::Valid
}

fn arguments(origin: &Origin) -> [String; 3] {
["--base-url".to_owned(), origin.as_key(), "mcp".to_owned()]
}
Expand Down
Loading