( stagingPath: string, installPath: string, )
| 326 | } |
| 327 | |
| 328 | async function installVersionFromPackage( |
| 329 | stagingPath: string, |
| 330 | installPath: string, |
| 331 | ) { |
| 332 | try { |
| 333 | // Extract binary from npm package structure in staging |
| 334 | const nodeModulesDir = join(stagingPath, 'node_modules', '@anthropic-ai') |
| 335 | const entries = await readdir(nodeModulesDir) |
| 336 | const nativePackage = entries.find((entry: string) => |
| 337 | entry.startsWith('claude-cli-native-'), |
| 338 | ) |
| 339 | |
| 340 | if (!nativePackage) { |
| 341 | logEvent('tengu_native_install_package_failure', { |
| 342 | stage_find_package: true, |
| 343 | error_package_not_found: true, |
| 344 | }) |
| 345 | const error = new Error('Could not find platform-specific native package') |
| 346 | throw error |
| 347 | } |
| 348 | |
| 349 | const stagedBinaryPath = join(nodeModulesDir, nativePackage, 'cli') |
| 350 | |
| 351 | try { |
| 352 | await stat(stagedBinaryPath) |
| 353 | } catch { |
| 354 | logEvent('tengu_native_install_package_failure', { |
| 355 | stage_binary_exists: true, |
| 356 | error_binary_not_found: true, |
| 357 | }) |
| 358 | const error = new Error('Native binary not found in staged package') |
| 359 | throw error |
| 360 | } |
| 361 | |
| 362 | await atomicMoveToInstallPath(stagedBinaryPath, installPath) |
| 363 | |
| 364 | // Clean up staging directory |
| 365 | await rm(stagingPath, { recursive: true, force: true }) |
| 366 | |
| 367 | logEvent('tengu_native_install_package_success', {}) |
| 368 | } catch (error) { |
| 369 | // Log if not already logged above |
| 370 | const msg = errorMessage(error) |
| 371 | if ( |
| 372 | !msg.includes('Could not find platform-specific') && |
| 373 | !msg.includes('Native binary not found') |
| 374 | ) { |
| 375 | logEvent('tengu_native_install_package_failure', { |
| 376 | stage_atomic_move: true, |
| 377 | error_move_failed: true, |
| 378 | }) |
| 379 | } |
| 380 | logError(toError(error)) |
| 381 | throw error |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | async function installVersionFromBinary( |
no test coverage detected