finalize_installation

Function finalize_installation 

Source
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

  1. Hook Configuration - Configures Claude Code hooks from source files
  2. MCP Server Setup - Groups and configures MCP servers by tool type
  3. Patch Application - Applies and tracks project/private patches
  4. Artifact Cleanup - Removes old files from previous installations
  5. Lockfile Saving - Writes main lockfile with checksums (unless –no-lock)
  6. Private Lockfile - Saves private patches to separate file

§Arguments

  • lockfile - Mutable lockfile to update with applied patches
  • manifest - Project manifest for configuration
  • project_dir - Project root directory
  • cache - Cache instance for Git operations
  • old_lockfile - Optional previous lockfile for artifact cleanup
  • quiet - Whether to suppress output messages
  • no_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