fix(acp): uninstall before reinstall on npx agent upgrade

Plain `npm install -g <pkg>@<version>` over an existing install does not
reliably re-resolve platform-specific optionalDependencies, leaving the
native CLI binary missing or stale (e.g. 'Native CLI binary for darwin-x64
not found' after the claude-agent-sdk upgrade). The Upgrade button now
runs npm uninstall -g first as a best-effort step, forcing npm to rebuild
the dependency graph from scratch on the subsequent install. If the clean
upgrade fails midway, the DB and the Settings UI resync to the actual
on-disk state instead of showing a phantom version.
This commit is contained in:
xintaofei
2026-04-25 10:45:49 +08:00
parent 4f0684dd04
commit 5ae081e87a
5 changed files with 82 additions and 4 deletions

View File

@@ -492,6 +492,8 @@ pub async fn acp_detect_agent_local_version(
pub struct AcpPrepareNpxAgentParams {
pub agent_type: AgentType,
pub registry_version: Option<String>,
#[serde(default)]
pub clean_first: bool,
pub task_id: String,
}
@@ -504,6 +506,7 @@ pub async fn acp_prepare_npx_agent(
let result = acp_commands::acp_prepare_npx_agent_core(
params.agent_type,
params.registry_version,
params.clean_first,
params.task_id,
db,
&emitter,