| 332 | } |
| 333 | |
| 334 | async function copyPluginToManagedRoot( |
| 335 | kimiHomeDir: string, |
| 336 | id: string, |
| 337 | sourceRoot: string, |
| 338 | ): Promise<string> { |
| 339 | const managedRoot = path.join(kimiHomeDir, 'plugins', 'managed', id); |
| 340 | const managedDir = path.dirname(managedRoot); |
| 341 | await mkdir(managedDir, { recursive: true }); |
| 342 | const stagingRoot = await mkdtemp(path.join(managedDir, `${id}-`)); |
| 343 | try { |
| 344 | await cp(sourceRoot, stagingRoot, { recursive: true }); |
| 345 | await rm(managedRoot, { recursive: true, force: true }); |
| 346 | await rename(stagingRoot, managedRoot); |
| 347 | } catch (error) { |
| 348 | await rm(stagingRoot, { recursive: true, force: true }); |
| 349 | throw error; |
| 350 | } |
| 351 | return realpath(managedRoot); |
| 352 | } |
| 353 | |
| 354 | async function recordFrom(input: { |
| 355 | id: string; |