@cannbot-ai/install-helper 0.0.2-beta.46 → 0.0.2-beta.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2368,7 +2368,7 @@ async function showRestorePrompt(backups) {
2368
2368
 
2369
2369
  // src/core/plugin-installer.ts
2370
2370
  import { existsSync as existsSync12, mkdirSync as mkdirSync5, symlinkSync, unlinkSync as unlinkSync4, realpathSync, copyFileSync as copyFileSync2, cpSync, writeFileSync as writeFileSync3, readFileSync as readFileSync8 } from "fs";
2371
- import { join as join11 } from "path";
2371
+ import { join as join11, basename } from "path";
2372
2372
  import { execa as execa3 } from "execa";
2373
2373
  function readPluginManifest(pluginDir) {
2374
2374
  const manifestPath = join11(pluginDir, "plugin-manifest.json");
@@ -2438,27 +2438,80 @@ function installConfigFile(pluginDir, configFile, tool, level, configRoot, insta
2438
2438
  }
2439
2439
  }
2440
2440
  }
2441
- async function installExternalRepos(repos, repoPath) {
2441
+ async function installExternalRepos(repos, repoPath, configRoot, installPath, level) {
2442
2442
  if (!repos || repos.length === 0) return;
2443
2443
  for (const repo of repos) {
2444
2444
  const targetDir = join11(repoPath, repo.dir);
2445
- if (existsSync12(targetDir)) {
2446
- logger.info(` ${repo.dir} already exists, skipping clone`);
2447
- continue;
2445
+ if (!existsSync12(targetDir)) {
2446
+ const args = ["clone"];
2447
+ if (repo.depth) {
2448
+ args.push("--depth", String(repo.depth));
2449
+ }
2450
+ if (repo.recursive) {
2451
+ args.push("--recursive");
2452
+ }
2453
+ args.push(repo.url, targetDir);
2454
+ try {
2455
+ await execa3("git", args, { timeout: 12e4 });
2456
+ } catch {
2457
+ logger.warn(` git clone failed: ${repo.url}, clone manually: git clone ${repo.url} ${repo.dir}`);
2458
+ continue;
2459
+ }
2460
+ }
2461
+ const linkName = basename(repo.dir);
2462
+ const resolved = realpathSync(targetDir);
2463
+ const configRootLink = join11(configRoot, linkName);
2464
+ try {
2465
+ if (existsSync12(configRootLink) || isSymlink(configRootLink)) {
2466
+ unlinkSync4(configRootLink);
2467
+ }
2468
+ try {
2469
+ symlinkSync(resolved, configRootLink);
2470
+ } catch (e) {
2471
+ if (e.code === "EPERM") {
2472
+ cpSync(resolved, configRootLink, { recursive: true });
2473
+ }
2474
+ }
2475
+ } catch {
2476
+ logger.warn(` Failed to link ${linkName} to config directory`);
2448
2477
  }
2449
- const args = ["clone"];
2450
- if (repo.depth) {
2451
- args.push("--depth", String(repo.depth));
2478
+ if (level === "project") {
2479
+ const projectLink = join11(installPath, linkName);
2480
+ try {
2481
+ if (existsSync12(projectLink) || isSymlink(projectLink)) {
2482
+ unlinkSync4(projectLink);
2483
+ }
2484
+ try {
2485
+ symlinkSync(resolved, projectLink);
2486
+ } catch (e) {
2487
+ if (e.code === "EPERM") {
2488
+ cpSync(resolved, projectLink, { recursive: true });
2489
+ }
2490
+ }
2491
+ } catch {
2492
+ logger.warn(` Failed to link ${linkName} to project directory`);
2493
+ }
2452
2494
  }
2453
- if (repo.recursive) {
2454
- args.push("--recursive");
2495
+ }
2496
+ }
2497
+ function installWorkflows(pluginDir, configRoot) {
2498
+ const workflowsDir = join11(pluginDir, "workflows");
2499
+ if (!existsSync12(workflowsDir)) return;
2500
+ const targetPath = join11(configRoot, "workflows");
2501
+ try {
2502
+ const resolved = realpathSync(workflowsDir);
2503
+ if (existsSync12(targetPath) || isSymlink(targetPath)) {
2504
+ unlinkSync4(targetPath);
2455
2505
  }
2456
- args.push(repo.url, targetDir);
2457
2506
  try {
2458
- await execa3("git", args, { timeout: 12e4 });
2459
- } catch {
2460
- logger.warn(` git clone failed: ${repo.url}, clone manually: git clone ${repo.url} ${repo.dir}`);
2507
+ symlinkSync(resolved, targetPath);
2508
+ } catch (e) {
2509
+ if (e.code === "EPERM") {
2510
+ cpSync(resolved, targetPath, { recursive: true });
2511
+ }
2461
2512
  }
2513
+ } catch {
2514
+ logger.warn(` Failed to link workflows to config directory`);
2462
2515
  }
2463
2516
  }
2464
2517
  function writeCannbotManifest(configRoot, pluginId, version, level, tool, skills, agents) {
@@ -2526,7 +2579,8 @@ async function installViaManifest(manifest, pluginDir, repoPath, tool, level, in
2526
2579
  }
2527
2580
  }
2528
2581
  installConfigFile(pluginDir, manifest.configFile, tool, level, configRoot, cwd);
2529
- await installExternalRepos(manifest.externalRepos, repoPath);
2582
+ installWorkflows(pluginDir, configRoot);
2583
+ await installExternalRepos(manifest.externalRepos, repoPath, configRoot, cwd, level);
2530
2584
  const cannbotManifest = writeCannbotManifest(
2531
2585
  configRoot,
2532
2586
  manifest.id,