pub async fn finalize_installation(
lockfile: &mut LockFile,
manifest: &Manifest,
project_dir: &Path,
cache: &Cache,
old_lockfile: Option<&LockFile>,
quiet: bool,
no_lock: bool,
) -> Result<(usize, usize)>Expand description
Finalize installation by configuring hooks, MCP servers, and updating lockfiles.
This function performs the final steps shared by install and update commands after resources are installed. It executes multiple operations in sequence, with each step building on the previous.
§Process Steps
- Hook Configuration - Configures Claude Code hooks from source files
- MCP Server Setup - Groups and configures MCP servers by tool type
- Patch Application - Applies and tracks project/private patches
- Artifact Cleanup - Removes old files from previous installations
- Lockfile Saving - Writes main lockfile with checksums (unless –no-lock)
- Private Lockfile - Saves private patches to separate file
§Arguments
lockfile- Mutable lockfile to update with applied patchesmanifest- Project manifest for configurationproject_dir- Project root directorycache- Cache instance for Git operationsold_lockfile- Optional previous lockfile for artifact cleanupquiet- Whether to suppress output messagesno_lock- Whether to skip lockfile saving (development mode)
§Returns
Returns (hook_count, server_count) tuple:
hook_count: Number of hooks configured (regardless of changed status)server_count: Number of MCP servers configured (regardless of changed status)
§Errors
Returns an error if:
- Hook configuration fails: Invalid hook source files or permission errors
- MCP handler not found: Tool type has no registered MCP handler
- Tool not configured: Tool missing from manifest
[default-tools]section - Lockfile save fails: Permission denied or disk full
§Examples
let mut lockfile = LockFile::default();
let manifest = Manifest::default();
let project_dir = Path::new(".");
let cache = Cache::new()?;
let (hooks, servers) = finalize_installation(
&mut lockfile,
&manifest,
project_dir,
&cache,
None, // no old lockfile (fresh install)
false, // not quiet
false, // create lockfile
).await?;
println!("Configured {} hooks and {} servers", hooks, servers);§Implementation Notes
- Hooks are configured by reading directly from source files (no copying)
- MCP servers are grouped by tool type for batch configuration
- Patch tracking: project patches stored in lockfile, private in separate file
- Artifact cleanup only runs if old lockfile exists (update scenario)
- Private lockfile automatically deleted if empty