Skip to content

Add proofline agent remove to unregister the MCP server - #120

Open
stevyhacker wants to merge 1 commit into
prooflinedev:mainfrom
stevyhacker:agent-remove
Open

stevyhacker wants to merge 1 commit into
prooflinedev:mainfrom
stevyhacker:agent-remove

Conversation

@stevyhacker

Copy link
Copy Markdown

Why

proofline agent install never changes an existing proofline entry, and nothing removes one. If the entry starts an old executable, for example after moving from a source build to the installer, install says the entry stays unchanged and the only fix is hand-editing ~/.claude.json or ~/.codex/config.toml. Anyone uninstalling Proofline has the same problem.

What changes

  • proofline agent remove CLIENT previews the entry and its file, asks [y/N], and removes only the proofline server. --yes skips the prompt and --print previews without writing.
  • When install finds an entry that starts a different executable, it names that path and suggests agent remove and then agent install.
  • README: one paragraph under "MCP agent registration".
flowchart TD
  A["agent remove CLIENT"] --> B{"custom CLAUDE_CONFIG_DIR<br/>or CODEX_HOME?"}
  B -- yes --> X1["refuse, exit 1"]
  B -- no --> C["read the file with install's checks<br/>Git work tree, symlink, regular file, 1 MiB"]
  C -- fails --> X2["refuse, exit 1"]
  C --> D{"parses?"}
  D -- no --> X3["refuse, exit 1, file unchanged"]
  D -- yes --> E{"proofline entry?"}
  E -- no --> X4["nothing to remove, exit 0"]
  E -- yes --> F{"--print?"}
  F -- yes --> X5["print the entry, exit 0"]
  F -- no --> G{"y at the prompt, or --yes?"}
  G -- no --> X6["nothing written, exit 0"]
  G -- yes --> H["lock, re-read, compare with the preview"]
  H -- changed --> X7["refuse, exit 1"]
  H -- same --> W["temp file and atomic rename"]
  style W stroke-width:2px
Loading

What it looks like for an entry left by an older install:

$ proofline agent install gemini --yes
A proofline entry already exists in "/home/dev/.gemini/settings.json"; it stays unchanged.
It starts "/opt/proofline-0.9/bin/proofline", not this executable. To use this one, run `proofline agent remove gemini` and then `proofline agent install gemini`.

$ proofline agent remove gemini --yes
Remove this Gemini CLI server from "/home/dev/.gemini/settings.json":
{
  "mcpServers": {"proofline":{"command":"/opt/proofline-0.9/bin/proofline","args":["--base-url","https://proofline.sh","mcp"]}}
}

Removed the proofline server from "/home/dev/.gemini/settings.json". Sessions that already started may keep it until they restart.

Decisions

  • JSON loses exactly the member's bytes. The file is parsed with borrowed RawValues, so each value's position in the text is known. Remove cuts "proofline": {…} and the comma next to it and keeps every other byte, including indentation, key order and long numbers. Going through serde_json::Value would round numbers like 184467440737095516170, which an existing install test already guards.
  • TOML goes through toml_edit. Comments, blank lines and other servers stay. A [mcp_servers.proofline.env] subtable goes with the entry. In an inline table the space before } is kept.
  • Emptied containers stay. "mcpServers": {} or an empty [mcp_servers] is left in place, since remove only takes out what it was asked to.
  • The preview shows the whole proofline entry and nothing else. Tests plant a secret in another server and check it never reaches stdout, stderr or an error.
  • CLAUDE_CONFIG_DIR refuses even --print. The preview reads ~/.claude.json, which Claude Code ignores while that variable is set. A CODEX_HOME outside ~/.codex refuses the same way.
  • Removal errors give removal advice. A file that can't be parsed or is over 1 MiB says to remove the entry by hand instead of install's "use --print".
  • The install hint resolves symlinks before comparing, so macOS /var and /private/var count as the same file (the path issue behind test(agent): resolve recorded executable path before comparing #116).
  • One new write path. Layout::replace reuses the lock, change checks, temp file and atomic rename, and keeps file permissions. Layout::save is unchanged. The [y/N] prompt moved into a shared confirm().
  • Not changed here: install already writes mcpServers back on one line when it adds an entry.

How it was verified

Run on Linux (Ubuntu 24.04, toolchain 1.100.0 from rust-toolchain.toml).

Check Result
cargo fmt --check clean
cargo clippy --locked --all-targets -- -D warnings clean
cargo test --locked 167 passed, 1 ignored (the pre-commit hook test in tests/hooks.rs, ignored in the source)
New unit tests in src/agent/tests.rs 10
New integration tests in tests/agent_remove.rs 2
cargo deny check not run, no dependency changes

Install-then-remove round trip with a temporary HOME and the built binary copied to $TMP/bin/proofline:

Scenario Result
Codex config.toml with comments, a profile and another server byte-identical to the original
~/.claude.json in Claude Code's own format, reformatted by Claude Code after install byte-identical to the original
~/.claude.json removed right after install same JSON and key order; mcpServers stays on the one line install wrote
Gemini entry pointing at /opt/proofline-0.9/bin/proofline install suggests remove; remove, then install, points it at the new binary
No entry, or no file exit 0, "nothing to remove", no directory created
Unparseable JSON, CLAUDE_CONFIG_DIR, CODEX_HOME, symlinked file, home in a Git work tree exit 1, every file unchanged (cmp)

Not run on macOS or Windows.

Files

File Lines What
src/agent.rs +214 −38 remove subcommand, shared confirm(), install hint
src/agent/config.rs +205 JSON byte splice, TOML removal, recorded command lookup
src/agent/store.rs +28 Layout::replace
src/agent/tests.rs +403 −1 removal tests next to the install tests
tests/agent_remove.rs +105 the binary with --yes, --print and the env refusals
README.md +2 usage paragraph

`agent install` never replaces an existing proofline entry, so an entry
that points at an old executable could only be fixed by editing the
client's file by hand. `agent remove CLIENT` previews the entry and file,
asks [y/N] (or takes --yes, or previews only with --print), and removes
only the proofline server.

JSON files lose exactly the member's bytes; Codex TOML is edited with
toml_edit, so comments and layout stay. The write reuses the installer's
lock, Git working-tree and symlink refusals, 1 MiB limit, change
detection and atomic replace. When install finds an entry for another
executable, it now names that path and suggests remove, then install.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant