Expand description
Cross-installer helpers.
§Responsibilities
- Resolve
~and well-known directories without pulling external crates (std::env::var("HOME")). - Atomic JSON read/modify/write with timestamped backup files.
- Merge a single mcpServers entry while preserving sibling clients (proxyman, pencil, …) untouched.
§Atomicity model
- We always read the full JSON document, mutate in-memory, then write
a sibling
<file>.spool-tmpandrenameto the destination. - We snapshot the previous bytes to
<file>.bak-spool-<unix-ts>BEFORE writing — never overwriting an existing backup. The backup is created at most once perinstallcall.
§Why not serde_json::Value::as_object_mut directly?
We keep the surrounding object as serde_json::Value to preserve
every key the user (or another tool) may have set. We never re-emit
the document with to_string — we use serde_json::to_string_pretty
to keep diffs readable.
Enums§
- McpMerge
Outcome - Outcome of
merge_mcp_entry. - McpRemove
Outcome - Outcome of
remove_mcp_entry. - Settings
Hook Outcome - Result of
upsert_settings_hook_command.
Functions§
- backup_
file - Snapshot
pathto<path>.bak-spool-<ts>. Returns the backup path orNonewhen the source file does not exist (fresh install). - build_
mcp_ entry - Build the canonical spool mcpServers entry.
- claude_
config_ path - Path to the Claude Code top-level config (
~/.claude.json). - claude_
settings_ path - Path to the Claude Code settings file (
~/.claude/settings.json). - default_
cargo_ binary_ path - Default spool-mcp install path under
~/.cargo/bin/. - ensure_
config_ exists - home_
dir - Returns the absolute home directory by reading
$HOME. - merge_
mcp_ entry - Merge
desiredintodoc.mcpServers.{client_id}. - purge_
settings_ hook_ entries - Remove every spool-* entry from
doc.hooks.{event}. An entry is considered “spool-managed” when any of its innerhooks[].commandstrings contains the markermarker_substring(typicallyspool-). We drop the entire wrapper entry to keep the structure tidy; sibling tools’ entries are not touched. - read_
json_ or_ empty - Read a JSON document from disk; missing files yield an empty object.
- remove_
mcp_ entry - Drop
doc.mcpServers.{client_id}if it exists. - upsert_
settings_ hook_ command - Ensure
doc.hooks.{event}contains an entry referencingcommand_path. Returns whether the document was mutated. - write_
json_ atomic - Write JSON to
pathatomically: write to<path>.spool-tmpthen rename. The parent directory MUST exist.