@cannbot-ai/install-helper 0.0.2-beta.55 → 0.0.2-beta.57
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/bin/install-helper.js +2 -2
- package/dist/index.js +63 -23
- package/dist/index.js.map +1 -1
- package/dist/locales/en_US.json +1 -0
- package/dist/locales/zh_CN.json +1 -0
- package/package.json +6 -6
package/bin/install-helper.js
CHANGED
|
@@ -33,7 +33,7 @@ if (pkgName) {
|
|
|
33
33
|
const binaryPath = join(dirname(pkgPath), binaryName);
|
|
34
34
|
if (existsSync(binaryPath)) {
|
|
35
35
|
const child = spawn(binaryPath, args, { stdio: "inherit" });
|
|
36
|
-
child.on("exit", (code) => process.exit(code
|
|
36
|
+
child.on("exit", (code, signal) => { process.exit(code ?? (signal ? 1 : 0)); });
|
|
37
37
|
child.on("error", () => runJSFallback());
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
@@ -46,7 +46,7 @@ function runJSFallback() {
|
|
|
46
46
|
const jsPath = join(__dirname, "..", "dist", "index.js");
|
|
47
47
|
if (existsSync(jsPath)) {
|
|
48
48
|
const child = spawn(process.execPath, [jsPath, ...args], { stdio: "inherit" });
|
|
49
|
-
child.on("exit", (code) => process.exit(code
|
|
49
|
+
child.on("exit", (code, signal) => { process.exit(code ?? (signal ? 1 : 0)); });
|
|
50
50
|
child.on("error", () => {
|
|
51
51
|
console.error("install-helper: failed to run");
|
|
52
52
|
process.exit(1);
|
package/dist/index.js
CHANGED
|
@@ -88,6 +88,7 @@ var zh_CN_default = {
|
|
|
88
88
|
error_script_not_found: "\u672A\u627E\u5230\u5B89\u88C5\u811A\u672C: {path}",
|
|
89
89
|
error_unknown: "\u672A\u77E5\u9519\u8BEF",
|
|
90
90
|
error_not_installed: "\u672A\u5B89\u88C5",
|
|
91
|
+
error_no_shell: "\u672A\u627E\u5230 bash \u6216 sh\uFF0C\u65E0\u6CD5\u6267\u884C\u5B89\u88C5\u811A\u672C\u3002\u8BF7\u5B89\u88C5 Git Bash \u6216 WSL",
|
|
91
92
|
error_symlink_windows: "\u521B\u5EFA\u7B26\u53F7\u94FE\u63A5\u5931\u8D25\uFF0C\u8BF7\u4EE5\u7BA1\u7406\u5458\u8EAB\u4EFD\u8FD0\u884C\u6216\u5F00\u542F Windows \u5F00\u53D1\u8005\u6A21\u5F0F",
|
|
92
93
|
quick_start: "\u542F\u52A8\u547D\u4EE4",
|
|
93
94
|
quick_start_hint: "\u8BD5\u8BD5\u8F93\u5165: \u5E2E\u6211\u5F00\u53D1\u4E00\u4E2A Abs \u7B97\u5B50",
|
|
@@ -270,6 +271,7 @@ var en_US_default = {
|
|
|
270
271
|
error_script_not_found: "Script not found: {path}",
|
|
271
272
|
error_unknown: "Unknown error",
|
|
272
273
|
error_not_installed: "Not installed",
|
|
274
|
+
error_no_shell: "bash or sh not found, cannot execute install script. Please install Git Bash or WSL",
|
|
273
275
|
error_symlink_windows: "Failed to create symlink, please run as administrator or enable Windows Developer Mode",
|
|
274
276
|
quick_start: "Launch command",
|
|
275
277
|
quick_start_hint: "Try: help me develop an Abs operator",
|
|
@@ -2269,8 +2271,10 @@ function loadRepoUrl() {
|
|
|
2269
2271
|
var REPO_URL = loadRepoUrl();
|
|
2270
2272
|
var RepositoryManager = class {
|
|
2271
2273
|
repoPath;
|
|
2274
|
+
customPath;
|
|
2272
2275
|
constructor(customPath) {
|
|
2273
2276
|
this.repoPath = customPath;
|
|
2277
|
+
this.customPath = customPath;
|
|
2274
2278
|
}
|
|
2275
2279
|
async ensureRepo() {
|
|
2276
2280
|
if (this.repoPath && this.isValidRepo(this.repoPath)) {
|
|
@@ -2296,7 +2300,10 @@ var RepositoryManager = class {
|
|
|
2296
2300
|
}
|
|
2297
2301
|
async ensureRepoAndScan() {
|
|
2298
2302
|
const repoPath = await this.ensureRepo();
|
|
2299
|
-
|
|
2303
|
+
const isUserProvided = !!this.customPath || !!process.env.CANNBOT_REPO_PATH;
|
|
2304
|
+
if (!isUserProvided) {
|
|
2305
|
+
await this.updateRepo();
|
|
2306
|
+
}
|
|
2300
2307
|
mergeDynamicPlugins(repoPath);
|
|
2301
2308
|
const cache = readScanCache();
|
|
2302
2309
|
if (cache && cache.repoCommit === getCurrentCommit(repoPath)) {
|
|
@@ -2366,8 +2373,8 @@ function createRepositoryManager(customPath) {
|
|
|
2366
2373
|
|
|
2367
2374
|
// src/core/installer.ts
|
|
2368
2375
|
import { existsSync as existsSync13 } from "fs";
|
|
2369
|
-
import { join as join12 } from "path";
|
|
2370
|
-
import { execa as execa4 } from "execa";
|
|
2376
|
+
import { join as join12, basename as basename2 } from "path";
|
|
2377
|
+
import { execa as execa4, execaSync } from "execa";
|
|
2371
2378
|
|
|
2372
2379
|
// src/core/record.ts
|
|
2373
2380
|
import { existsSync as existsSync10, mkdirSync as mkdirSync4, readFileSync as readFileSync7, unlinkSync as unlinkSync2 } from "fs";
|
|
@@ -2405,7 +2412,7 @@ function deleteRecord(pluginId) {
|
|
|
2405
2412
|
unlinkSync2(recordPath);
|
|
2406
2413
|
}
|
|
2407
2414
|
}
|
|
2408
|
-
function scanInstalledFiles(pluginId, displayName, tool, level, installPath, configRoot, manifest) {
|
|
2415
|
+
function scanInstalledFiles(pluginId, displayName, tool, level, installPath, configRoot, manifest, externalRepoNames) {
|
|
2409
2416
|
const files = [];
|
|
2410
2417
|
const directories = [];
|
|
2411
2418
|
if (manifest) {
|
|
@@ -2450,7 +2457,7 @@ function scanInstalledFiles(pluginId, displayName, tool, level, installPath, con
|
|
|
2450
2457
|
if (existsSync10(configFilePath)) {
|
|
2451
2458
|
files.push(configFilePath);
|
|
2452
2459
|
}
|
|
2453
|
-
const repoLinks = ["asc-devkit", "pypto", "tilelang-ascend", "cann-recipes-infer", "cann-samples"];
|
|
2460
|
+
const repoLinks = externalRepoNames && externalRepoNames.length > 0 ? externalRepoNames : ["asc-devkit", "pypto", "tilelang-ascend", "cann-recipes-infer", "cann-samples"];
|
|
2454
2461
|
for (const repoName of repoLinks) {
|
|
2455
2462
|
const repoLinkPath = join9(installPath, repoName);
|
|
2456
2463
|
if (isSymlink(repoLinkPath)) {
|
|
@@ -2700,7 +2707,7 @@ async function showRestorePrompt(backups) {
|
|
|
2700
2707
|
}
|
|
2701
2708
|
|
|
2702
2709
|
// src/core/plugin-installer.ts
|
|
2703
|
-
import { existsSync as existsSync12, mkdirSync as mkdirSync5, symlinkSync, unlinkSync as unlinkSync4, realpathSync, copyFileSync as copyFileSync2, cpSync, writeFileSync as writeFileSync3 } from "fs";
|
|
2710
|
+
import { existsSync as existsSync12, mkdirSync as mkdirSync5, symlinkSync, unlinkSync as unlinkSync4, realpathSync, copyFileSync as copyFileSync2, cpSync, writeFileSync as writeFileSync3, rmSync } from "fs";
|
|
2704
2711
|
import { join as join11, basename } from "path";
|
|
2705
2712
|
import { execa as execa3 } from "execa";
|
|
2706
2713
|
function installLink(source, target) {
|
|
@@ -2734,17 +2741,22 @@ function installConfigFile(pluginDir, configFile, tool, level, configRoot, insta
|
|
|
2734
2741
|
} else {
|
|
2735
2742
|
primaryTarget = join11(configRoot, agentsFileName);
|
|
2736
2743
|
}
|
|
2737
|
-
if (existsSync12(primaryTarget) || isSymlink(primaryTarget)) {
|
|
2738
|
-
unlinkSync4(primaryTarget);
|
|
2739
|
-
}
|
|
2740
2744
|
try {
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2745
|
+
const resolvedSource = realpathSync(sourcePath);
|
|
2746
|
+
if (existsSync12(primaryTarget) || isSymlink(primaryTarget)) {
|
|
2747
|
+
unlinkSync4(primaryTarget);
|
|
2748
|
+
}
|
|
2749
|
+
try {
|
|
2750
|
+
symlinkSync(resolvedSource, primaryTarget);
|
|
2751
|
+
} catch (e) {
|
|
2752
|
+
if (e.code === "EPERM") {
|
|
2753
|
+
copyFileSync2(sourcePath, primaryTarget);
|
|
2754
|
+
} else {
|
|
2755
|
+
throw e;
|
|
2756
|
+
}
|
|
2747
2757
|
}
|
|
2758
|
+
} catch (e) {
|
|
2759
|
+
logger.warn(` Failed to install config file: ${e.message}`);
|
|
2748
2760
|
}
|
|
2749
2761
|
if (isProjectLevel && primaryTarget !== join11(configRoot, agentsFileName)) {
|
|
2750
2762
|
if (configRootConfigLink === false) return;
|
|
@@ -2778,6 +2790,10 @@ async function installExternalRepos(repos, repoPath, configRoot, installPath, le
|
|
|
2778
2790
|
await execa3("git", args, { timeout: 12e4 });
|
|
2779
2791
|
} catch {
|
|
2780
2792
|
logger.warn(` git clone failed: ${repo.url}, clone manually: git clone ${repo.url} ${repo.dir}`);
|
|
2793
|
+
try {
|
|
2794
|
+
rmSync(targetDir, { recursive: true, force: true });
|
|
2795
|
+
} catch {
|
|
2796
|
+
}
|
|
2781
2797
|
continue;
|
|
2782
2798
|
}
|
|
2783
2799
|
}
|
|
@@ -2936,6 +2952,18 @@ async function installViaManifest(plugin, repoPath, tool, level, installPath) {
|
|
|
2936
2952
|
}
|
|
2937
2953
|
|
|
2938
2954
|
// src/core/installer.ts
|
|
2955
|
+
function findShell() {
|
|
2956
|
+
const candidates = process.platform === "win32" ? ["bash", "sh"] : ["bash", "sh"];
|
|
2957
|
+
for (const cmd of candidates) {
|
|
2958
|
+
try {
|
|
2959
|
+
const detectCmd = process.platform === "win32" ? "where" : "which";
|
|
2960
|
+
execaSync(detectCmd, [cmd], { timeout: 3e3 });
|
|
2961
|
+
return cmd;
|
|
2962
|
+
} catch {
|
|
2963
|
+
}
|
|
2964
|
+
}
|
|
2965
|
+
return null;
|
|
2966
|
+
}
|
|
2939
2967
|
async function installPlugin(opts) {
|
|
2940
2968
|
const plugin = getPluginById(opts.pluginId);
|
|
2941
2969
|
if (!plugin) {
|
|
@@ -3011,7 +3039,8 @@ async function installPlugin(opts) {
|
|
|
3011
3039
|
opts.level,
|
|
3012
3040
|
cwd,
|
|
3013
3041
|
configRoot,
|
|
3014
|
-
result.manifest
|
|
3042
|
+
result.manifest,
|
|
3043
|
+
plugin.externalRepos?.map((r) => basename2(r.dir))
|
|
3015
3044
|
);
|
|
3016
3045
|
if (backupInfo) {
|
|
3017
3046
|
record.backup = {
|
|
@@ -3060,7 +3089,17 @@ async function installPlugin(opts) {
|
|
|
3060
3089
|
args.push(opts.installPath);
|
|
3061
3090
|
}
|
|
3062
3091
|
try {
|
|
3063
|
-
const shell =
|
|
3092
|
+
const shell = findShell();
|
|
3093
|
+
if (!shell) {
|
|
3094
|
+
return {
|
|
3095
|
+
success: false,
|
|
3096
|
+
pluginId: opts.pluginId,
|
|
3097
|
+
skillsCount: 0,
|
|
3098
|
+
agentsCount: 0,
|
|
3099
|
+
errors: [t("error_no_shell")],
|
|
3100
|
+
warnings: []
|
|
3101
|
+
};
|
|
3102
|
+
}
|
|
3064
3103
|
const execOptions = {
|
|
3065
3104
|
cwd,
|
|
3066
3105
|
timeout: 3e5,
|
|
@@ -3086,7 +3125,8 @@ async function installPlugin(opts) {
|
|
|
3086
3125
|
opts.level,
|
|
3087
3126
|
cwd,
|
|
3088
3127
|
configRoot,
|
|
3089
|
-
manifest
|
|
3128
|
+
manifest,
|
|
3129
|
+
plugin.externalRepos?.map((r) => basename2(r.dir))
|
|
3090
3130
|
);
|
|
3091
3131
|
if (backupInfo) {
|
|
3092
3132
|
record.backup = {
|
|
@@ -4191,7 +4231,7 @@ async function installPlugins(pluginIds, tool, level, repoPath, installPath, yes
|
|
|
4191
4231
|
|
|
4192
4232
|
// src/commands/uninstall.ts
|
|
4193
4233
|
import { existsSync as existsSync17, unlinkSync as unlinkSync7, rmdirSync as rmdirSync2, readdirSync as readdirSync6 } from "fs";
|
|
4194
|
-
import { resolve, basename as
|
|
4234
|
+
import { resolve, basename as basename3, sep } from "path";
|
|
4195
4235
|
import chalk11 from "chalk";
|
|
4196
4236
|
async function uninstallCommand(names, options) {
|
|
4197
4237
|
const tool = options.tool ? validateTool(options.tool) : "opencode";
|
|
@@ -4225,7 +4265,7 @@ async function uninstallCommand(names, options) {
|
|
|
4225
4265
|
const allowedBases = [resolve(configRoot), resolve(record.installPath)];
|
|
4226
4266
|
const isSafePath = (p) => {
|
|
4227
4267
|
const resolved = resolve(p);
|
|
4228
|
-
return allowedBases.some((base) => resolved === base || resolved.startsWith(base +
|
|
4268
|
+
return allowedBases.some((base) => resolved === base || resolved.startsWith(base + sep));
|
|
4229
4269
|
};
|
|
4230
4270
|
let removedFiles = 0;
|
|
4231
4271
|
let removedDirs = 0;
|
|
@@ -4234,7 +4274,7 @@ async function uninstallCommand(names, options) {
|
|
|
4234
4274
|
try {
|
|
4235
4275
|
if (existsSync17(filePath) || isSymlink(filePath)) {
|
|
4236
4276
|
unlinkSync7(filePath);
|
|
4237
|
-
const name =
|
|
4277
|
+
const name = basename3(filePath);
|
|
4238
4278
|
logger.step(` ${t("uninstall_remove_label")}: ${name}`);
|
|
4239
4279
|
removedFiles++;
|
|
4240
4280
|
}
|
|
@@ -4251,7 +4291,7 @@ async function uninstallCommand(names, options) {
|
|
|
4251
4291
|
const entries = readdirSync6(dirPath);
|
|
4252
4292
|
if (entries.length === 0) {
|
|
4253
4293
|
rmdirSync2(dirPath);
|
|
4254
|
-
const name =
|
|
4294
|
+
const name = basename3(dirPath);
|
|
4255
4295
|
logger.step(` ${t("uninstall_clean_empty_dir")}: ${name}/`);
|
|
4256
4296
|
removedDirs++;
|
|
4257
4297
|
}
|
|
@@ -4553,7 +4593,7 @@ function handleExit(error) {
|
|
|
4553
4593
|
}
|
|
4554
4594
|
process.on("SIGINT", () => {
|
|
4555
4595
|
console.log("\n" + t("init_cancelled"));
|
|
4556
|
-
process.exit(
|
|
4596
|
+
process.exit(130);
|
|
4557
4597
|
});
|
|
4558
4598
|
process.on("uncaughtException", (error) => {
|
|
4559
4599
|
handleExit(error);
|