From f1a11a387ae76694180b6abea11f92fbd583740b Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Wed, 2 Dec 2026 15:33:04 +1300 Subject: [PATCH] Tokens can approve (sc-8740): a project setting, on by default (projects.tokens_can_approve, migration 000036); off, a project token can't approve, accept a variant or ignore a change over MCP (rejecting and commenting still work), so a team can keep approving with people while CI's agents read and fix; in the project's CI behaviour settings and update_project; the agents docs' 'Keeping approval with people' says so; plugin 0.1.28 --- .claude-plugin/marketplace.json | 2 +- .claude-plugin/plugin.json | 2 +- .cursor-plugin/plugin.json | 2 +- gemini-extension.json | 2 +- server/frontend/content/docs/agents.md | 7 ++-- server/frontend/src/api/types.ts | 2 ++ server/frontend/src/pages/ProjectPage.tsx | 18 ++++++++++ server/migration/src/lib.rs | 2 ++ .../m20261202_000036_tokens_can_approve.rs | 26 ++++++++++++++ server/src/mcp.rs | 18 ++++++++++ server/src/models/_entities/projects.rs | 2 ++ server/src/models/projects.rs | 8 +++++ server/tests/requests/mcp.rs | 34 +++++++++++++++++++ skills/visualci-review/SKILL.md | 7 ++-- 14 files changed, 124 insertions(+), 8 deletions(-) create mode 100644 server/migration/src/m20261202_000036_tokens_can_approve.rs diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json index 282b8c76..23061702 100644 --- a/.claude-plugin/marketplace.json +++ b/.claude-plugin/marketplace.json @@ -5,7 +5,7 @@ "plugins": [ { "name": "visualci", - "version": "0.1.27", + "version": "0.1.28", "description": "Visual regression and snapshot review for PDFs, screenshots, JSON, HTML and text: VisualCI's MCP server and its skills for each CI provider and test tool.", "author": { "name": "DocSpring", "url": "https://visualci.com" }, "homepage": "https://visualci.com/docs/skills/", diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json index 12db3312..1dcbda3c 100644 --- a/.claude-plugin/plugin.json +++ b/.claude-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "visualci", - "version": "0.1.27", + "version": "0.1.28", "description": "Visual regression and snapshot review for PDFs, screenshots, JSON, HTML and text: VisualCI's MCP server and its skills for each CI provider and test tool.", "author": { "name": "DocSpring", "url": "https://visualci.com" }, "homepage": "https://visualci.com/docs/skills/", diff --git a/.cursor-plugin/plugin.json b/.cursor-plugin/plugin.json index dd1ada1c..603f596c 100644 --- a/.cursor-plugin/plugin.json +++ b/.cursor-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "visualci", "displayName": "VisualCI", - "version": "0.1.27", + "version": "0.1.28", "description": "Visual regression and snapshot review for PDFs, screenshots, JSON, HTML and text: VisualCI's MCP server and its skills for each CI provider and test tool.", "author": { "name": "DocSpring" diff --git a/gemini-extension.json b/gemini-extension.json index aac4b8dd..003f6b5f 100644 --- a/gemini-extension.json +++ b/gemini-extension.json @@ -1,6 +1,6 @@ { "name": "visualci", - "version": "0.1.27", + "version": "0.1.28", "description": "Visual regression and snapshot review for PDFs, screenshots, JSON, HTML and text: VisualCI's MCP server and its skills for each CI provider and test tool.", "mcpServers": { "visualci": { diff --git a/server/frontend/content/docs/agents.md b/server/frontend/content/docs/agents.md index eda4473a..ec5629c0 100644 --- a/server/frontend/content/docs/agents.md +++ b/server/frontend/content/docs/agents.md @@ -58,8 +58,11 @@ Pages that legitimately render two ways can be accepted as a variant with `revie ## Keeping approval with people -Some teams want agents to read builds and fix code, but leave approving changes to a person. Take the two review -tools away from the agent in its client: +Some teams want agents to read builds and fix code, but leave approving changes to a person. For agents in CI, +which use the project's token, turn off **Project tokens can approve** in the project's settings (or `update_project` +with `tokens_can_approve: false`): a project token can then still reject changes and comment, but approving, accepting +a variant or ignoring a change takes a person. For agents on people's machines, which use their own token, take the +two review tools away in the agent's client: - **Claude Code:** deny them in `.claude/settings.json`, which the whole team shares through the repository: diff --git a/server/frontend/src/api/types.ts b/server/frontend/src/api/types.ts index 82af4e7f..221c3658 100644 --- a/server/frontend/src/api/types.ts +++ b/server/frontend/src/api/types.ts @@ -230,6 +230,8 @@ export type ProjectSettings = { forge_webhook_at: string | null /** Whether the screenshots visualci.yml's `gallery` names are public. */ gallery_enabled: boolean + /** Whether project tokens (CI's agents) may approve changes; off keeps approving with people. */ + tokens_can_approve: boolean /** Anyone, signed in or not, can read its builds and diffs. */ public: boolean /** GitHub says its repository is public (checked on linking and once a day). Only then can it be public. */ diff --git a/server/frontend/src/pages/ProjectPage.tsx b/server/frontend/src/pages/ProjectPage.tsx index 6eb22183..4515954f 100644 --- a/server/frontend/src/pages/ProjectPage.tsx +++ b/server/frontend/src/pages/ProjectPage.tsx @@ -254,6 +254,7 @@ const toDraft = (s: ProjectSettings): Draft => ({ threshold: s.threshold, ignore_anti_aliasing: s.ignore_anti_aliasing, gallery_enabled: s.gallery_enabled, + tokens_can_approve: s.tokens_can_approve, public: s.public, rules: s.ignore_rules.map((r) => ({ snapshots: r.snapshots, @@ -532,6 +533,23 @@ function Settings({ ))} +
diff --git a/server/migration/src/lib.rs b/server/migration/src/lib.rs index d63488b4..a2816a9c 100644 --- a/server/migration/src/lib.rs +++ b/server/migration/src/lib.rs @@ -39,6 +39,7 @@ mod m20261202_000030_stripe_order; mod m20261202_000033_linked_by; mod m20261202_000034_render_job_token; mod m20261202_000035_invitation_for_user; +mod m20261202_000036_tokens_can_approve; pub struct Migrator; @@ -84,6 +85,7 @@ impl MigratorTrait for Migrator { Box::new(m20261202_000033_linked_by::Migration), Box::new(m20261202_000034_render_job_token::Migration), Box::new(m20261202_000035_invitation_for_user::Migration), + Box::new(m20261202_000036_tokens_can_approve::Migration), // inject-above (do not remove this comment) ] } diff --git a/server/migration/src/m20261202_000036_tokens_can_approve.rs b/server/migration/src/m20261202_000036_tokens_can_approve.rs new file mode 100644 index 00000000..cd2fc5d1 --- /dev/null +++ b/server/migration/src/m20261202_000036_tokens_can_approve.rs @@ -0,0 +1,26 @@ +//! A project can keep approving with people: with `tokens_can_approve` off, a project token (CI's) can't approve +//! changes, accept a variant or ignore a change over MCP; rejecting and commenting still work. +use sea_orm_migration::prelude::*; + +pub struct Migration; + +impl MigrationName for Migration { + fn name(&self) -> &str { + "m20261202_000036_tokens_can_approve" + } +} + +#[async_trait::async_trait] +impl MigrationTrait for Migration { + async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> { + m.get_connection() + .execute_unprepared("ALTER TABLE projects ADD COLUMN tokens_can_approve BOOLEAN NOT NULL DEFAULT true;") + .await?; + Ok(()) + } + + async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> { + m.get_connection().execute_unprepared("ALTER TABLE projects DROP COLUMN tokens_can_approve;").await?; + Ok(()) + } +} diff --git a/server/src/mcp.rs b/server/src/mcp.rs index 3f731052..36906b8a 100644 --- a/server/src/mcp.rs +++ b/server/src/mcp.rs @@ -656,6 +656,16 @@ impl VisualCi { ))) } + /// Why a project token can't approve in this project (its `tokens_can_approve` is off), else `None`. + fn tokens_may_not_approve(&self, rc: &RequestContext, project: &projects::Model) -> Option { + (matches!(principal_of(rc), Some(Principal::Project(_))) && !project.tokens_can_approve).then(|| { + "this project keeps approving with people: a project token can't approve, accept a variant or ignore a \ + change (rejecting and commenting still work); a person approves in the web app, or with their own \ + token" + .to_string() + }) + } + /// The project a tool works on: `org/project`, or the project token's own project. async fn project( &self, @@ -1896,6 +1906,11 @@ impl VisualCi { if let Err(e) = self.need_role(&rc, &project, Role::Member, "review builds").await? { return Ok(tool_error(e)); } + if args.action == "approve" + && let Some(refused) = self.tokens_may_not_approve(&rc, &project) + { + return Ok(tool_error(refused)); + } let Some(build) = self.find_build(&project, &args.build).await else { return Ok(tool_error(format!("no build {} in this project", args.build))); }; @@ -2151,6 +2166,9 @@ impl VisualCi { if let Err(e) = self.need_role(&rc, &project, Role::Member, "review builds").await? { return Ok(tool_error(e)); } + if let Some(refused) = self.tokens_may_not_approve(&rc, &project) { + return Ok(tool_error(refused)); + } let Some(build) = self.find_build(&project, &args.build).await else { return Ok(tool_error(format!("no build {} in this project", args.build))); }; diff --git a/server/src/models/_entities/projects.rs b/server/src/models/_entities/projects.rs index b82fd5cf..3a42b7b9 100644 --- a/server/src/models/_entities/projects.rs +++ b/server/src/models/_entities/projects.rs @@ -27,6 +27,8 @@ pub struct Model { pub forge_installation: Option, /// Whether the gallery (visualci.yml's `gallery`) is public. On by default; nothing is public without a gallery. pub gallery_enabled: bool, + /// Whether project tokens may approve changes over MCP (CI's agents); off keeps approving with people. + pub tokens_can_approve: bool, #[sea_orm(column_type = "Text")] pub default_branch: String, #[sea_orm(column_type = "Text")] diff --git a/server/src/models/projects.rs b/server/src/models/projects.rs index 4382b2ce..d28d1c29 100644 --- a/server/src/models/projects.rs +++ b/server/src/models/projects.rs @@ -134,6 +134,8 @@ pub struct Settings { pub forge_webhook_at: Option, /// Whether the screenshots visualci.yml's `gallery` names are public. pub gallery_enabled: bool, + /// Whether project tokens may approve changes over MCP; off keeps approving with people. + pub tokens_can_approve: bool, /// Whether anyone, signed in or not, can read the project's builds and diffs (open source). Settings, tokens and /// reviewing stay with its members. pub public: bool, @@ -168,6 +170,7 @@ impl From<&Model> for Settings { forge_app_installed: p.forge_installation.is_some(), forge_webhook_at: p.forge_webhook_at.map(|d| d.to_rfc3339()), gallery_enabled: p.gallery_enabled, + tokens_can_approve: p.tokens_can_approve, public: p.public, repository_public: p.repository_public, open_source: p.open_source, @@ -205,6 +208,8 @@ pub struct SettingsChange { pub forge_token: Option, /// `false` takes the public gallery down (visualci.yml's `gallery` decides what's in it); `true` puts it back. pub gallery_enabled: Option, + /// `false`: project tokens can't approve changes (people do); `true` lets CI's agents approve again. + pub tokens_can_approve: Option, /// `true` lets anyone, signed in or not, read the project's builds and diffs (for open source projects); /// settings, tokens and reviewing stay with its members. Only a project linked to a public repository can be /// public. `false` makes it private again. @@ -337,6 +342,9 @@ impl Model { if let Some(v) = p.name { a.name = Set(v); } + if let Some(v) = p.tokens_can_approve { + a.tokens_can_approve = Set(v); + } if let Some(v) = p.gallery_enabled { a.gallery_enabled = Set(v); } diff --git a/server/tests/requests/mcp.rs b/server/tests/requests/mcp.rs index 5ebcec3b..8ad71c9f 100644 --- a/server/tests/requests/mcp.rs +++ b/server/tests/requests/mcp.rs @@ -963,3 +963,37 @@ async fn a_project_token_acts_as_a_member_not_an_admin() { }) .await; } + +/// With "Tokens can approve" off, a project token can't approve, accept a variant or ignore a change; it can still +/// reject. A person's token can turn it off and on. +#[tokio::test] +#[serial] +async fn a_project_can_keep_approving_with_people() { + request::(|request, ctx| async move { + let f = fixture(&ctx).await; + let project = format!("{}/pdfs", f.org); + let (err, s) = call( + &request, + &f.user_token, + "update_project", + serde_json::json!({ "project": project, "tokens_can_approve": false }), + ) + .await; + assert!(!err && s["settings"]["tokens_can_approve"] == false, "{s}"); + let t = &f.project_token; + let (err, r) = call(&request, t, "review", serde_json::json!({ "build": 1, "action": "approve" })).await; + assert!(err && r.to_string().contains("approving with people"), "{r}"); + let (err, r) = call( + &request, + t, + "review_page", + serde_json::json!({ "build": 1, "name": "x", "position": 0, "action": "ignore" }), + ) + .await; + assert!(err && r.to_string().contains("approving with people"), "{r}"); + // Rejecting isn't approving: it reaches the build (there's none here). + let (err, r) = call(&request, t, "review", serde_json::json!({ "build": 1, "action": "reject" })).await; + assert!(err && r.to_string().contains("no build"), "{r}"); + }) + .await; +} diff --git a/skills/visualci-review/SKILL.md b/skills/visualci-review/SKILL.md index 0d00b8da..5ff75eb2 100644 --- a/skills/visualci-review/SKILL.md +++ b/skills/visualci-review/SKILL.md @@ -63,8 +63,11 @@ Pages that legitimately render two ways can be accepted as a variant with `revie ## Keeping approval with people -Some teams want agents to read builds and fix code, but leave approving changes to a person. Take the two review -tools away from the agent in its client: +Some teams want agents to read builds and fix code, but leave approving changes to a person. For agents in CI, +which use the project's token, turn off **Project tokens can approve** in the project's settings (or `update_project` +with `tokens_can_approve: false`): a project token can then still reject changes and comment, but approving, accepting +a variant or ignoring a change takes a person. For agents on people's machines, which use their own token, take the +two review tools away in the agent's client: - **Claude Code:** deny them in `.claude/settings.json`, which the whole team shares through the repository: