@lark-apaas/openclaw-scripts-diagnose-cli 0.1.1-alpha.23 → 0.1.1-alpha.24
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.cjs +99 -6
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -877,6 +877,53 @@ SecretsRule = __decorate([Rule({
|
|
|
877
877
|
skipWhen: ({ hasMiaoda, deps }) => !hasMiaoda || !deps.usesMiaodaSecretProvider
|
|
878
878
|
})], SecretsRule);
|
|
879
879
|
//#endregion
|
|
880
|
+
//#region src/rules/cleanup-install-backup-dirs.ts
|
|
881
|
+
const DIR_PREFIX = ".openclaw-install-";
|
|
882
|
+
function resolveExtensionsDir(configPath) {
|
|
883
|
+
return node_path.default.join(node_path.default.dirname(configPath), "extensions");
|
|
884
|
+
}
|
|
885
|
+
function findLeftoverDirs(extensionsDir) {
|
|
886
|
+
if (!fileExists(extensionsDir)) return [];
|
|
887
|
+
let entries;
|
|
888
|
+
try {
|
|
889
|
+
entries = node_fs.default.readdirSync(extensionsDir, { withFileTypes: true });
|
|
890
|
+
} catch {
|
|
891
|
+
return [];
|
|
892
|
+
}
|
|
893
|
+
return entries.filter((e) => e.isDirectory() && e.name.startsWith(DIR_PREFIX)).map((e) => node_path.default.join(extensionsDir, e.name));
|
|
894
|
+
}
|
|
895
|
+
let CleanupInstallBackupDirsRule = class CleanupInstallBackupDirsRule extends DiagnoseRule {
|
|
896
|
+
validate(ctx) {
|
|
897
|
+
const configPath = ctx.config.__configPath;
|
|
898
|
+
if (!configPath) return { pass: true };
|
|
899
|
+
const dirs = findLeftoverDirs(resolveExtensionsDir(configPath));
|
|
900
|
+
if (dirs.length === 0) return { pass: true };
|
|
901
|
+
return {
|
|
902
|
+
pass: false,
|
|
903
|
+
message: `extensions 目录下发现 ${dirs.length} 个 ${DIR_PREFIX}* 脏目录需要清理`
|
|
904
|
+
};
|
|
905
|
+
}
|
|
906
|
+
repair(ctx) {
|
|
907
|
+
const configPath = ctx.config.__configPath;
|
|
908
|
+
if (!configPath) return;
|
|
909
|
+
const dirs = findLeftoverDirs(resolveExtensionsDir(configPath));
|
|
910
|
+
const failures = [];
|
|
911
|
+
for (const dir of dirs) try {
|
|
912
|
+
node_fs.default.rmSync(dir, {
|
|
913
|
+
recursive: true,
|
|
914
|
+
force: true
|
|
915
|
+
});
|
|
916
|
+
} catch (e) {
|
|
917
|
+
failures.push(`${node_path.default.basename(dir)}: ${e.message}`);
|
|
918
|
+
}
|
|
919
|
+
if (dirs.length > 0 && failures.length === dirs.length) throw new Error(`cleanup_install_backup_dirs: 全部清理失败: ${failures.join("; ")}`);
|
|
920
|
+
}
|
|
921
|
+
};
|
|
922
|
+
CleanupInstallBackupDirsRule = __decorate([Rule({
|
|
923
|
+
key: "cleanup_install_backup_dirs",
|
|
924
|
+
repairMode: "standard"
|
|
925
|
+
})], CleanupInstallBackupDirsRule);
|
|
926
|
+
//#endregion
|
|
880
927
|
//#region src/rules/miaoda-official-plugins-install-spec-unlock.ts
|
|
881
928
|
/**
|
|
882
929
|
* Official miaoda-side plugins that must track manifest — version-locked specs
|
|
@@ -942,19 +989,21 @@ const OLD_PLUGIN_NAMES = Object.freeze([
|
|
|
942
989
|
"miaoda-keepalive"
|
|
943
990
|
]);
|
|
944
991
|
function getPluginMaps(config) {
|
|
992
|
+
const rawAllow = asRecord(config.plugins)?.allow;
|
|
945
993
|
return {
|
|
946
994
|
entries: getNestedMap(config, "plugins", "entries"),
|
|
947
|
-
installs: getNestedMap(config, "plugins", "installs")
|
|
995
|
+
installs: getNestedMap(config, "plugins", "installs"),
|
|
996
|
+
allow: Array.isArray(rawAllow) ? rawAllow : void 0
|
|
948
997
|
};
|
|
949
998
|
}
|
|
950
999
|
function getExtensionsDir(configPath) {
|
|
951
1000
|
return node_path.default.join(node_path.default.dirname(configPath), "extensions");
|
|
952
1001
|
}
|
|
953
|
-
function hasNewMiaoda({ entries, installs }) {
|
|
954
|
-
return asRecord(entries?.[NEW_MIAODA]) != null || asRecord(installs?.[NEW_MIAODA]) != null;
|
|
1002
|
+
function hasNewMiaoda({ entries, installs, allow }) {
|
|
1003
|
+
return asRecord(entries?.[NEW_MIAODA]) != null || asRecord(installs?.[NEW_MIAODA]) != null || (allow?.includes(NEW_MIAODA) ?? false);
|
|
955
1004
|
}
|
|
956
|
-
function findResiduals({ entries, installs }, extensionsDir) {
|
|
957
|
-
return OLD_PLUGIN_NAMES.filter((name) => entries?.[name] != null || installs?.[name] != null || node_fs.default.existsSync(node_path.default.join(extensionsDir, name)));
|
|
1005
|
+
function findResiduals({ entries, installs, allow }, extensionsDir) {
|
|
1006
|
+
return OLD_PLUGIN_NAMES.filter((name) => entries?.[name] != null || installs?.[name] != null || (allow?.includes(name) ?? false) || node_fs.default.existsSync(node_path.default.join(extensionsDir, name)));
|
|
958
1007
|
}
|
|
959
1008
|
let OldMiaodaPluginsCleanupRule = class OldMiaodaPluginsCleanupRule extends DiagnoseRule {
|
|
960
1009
|
validate(ctx) {
|
|
@@ -971,7 +1020,12 @@ let OldMiaodaPluginsCleanupRule = class OldMiaodaPluginsCleanupRule extends Diag
|
|
|
971
1020
|
const maps = getPluginMaps(ctx.config);
|
|
972
1021
|
if (!hasNewMiaoda(maps)) return;
|
|
973
1022
|
const extensionsDir = getExtensionsDir(ctx.configPath);
|
|
974
|
-
const { entries, installs } = maps;
|
|
1023
|
+
const { entries, installs, allow } = maps;
|
|
1024
|
+
const oldSet = new Set(OLD_PLUGIN_NAMES);
|
|
1025
|
+
if (allow) for (let i = allow.length - 1; i >= 0; i--) {
|
|
1026
|
+
const v = allow[i];
|
|
1027
|
+
if (typeof v === "string" && oldSet.has(v)) allow.splice(i, 1);
|
|
1028
|
+
}
|
|
975
1029
|
for (const name of OLD_PLUGIN_NAMES) {
|
|
976
1030
|
if (entries && name in entries) delete entries[name];
|
|
977
1031
|
if (installs && name in installs) delete installs[name];
|
|
@@ -995,6 +1049,45 @@ OldMiaodaPluginsCleanupRule = __decorate([Rule({
|
|
|
995
1049
|
repairMode: "standard"
|
|
996
1050
|
})], OldMiaodaPluginsCleanupRule);
|
|
997
1051
|
//#endregion
|
|
1052
|
+
//#region src/rules/lark-plugin-allow.ts
|
|
1053
|
+
const LARK_PLUGIN = "openclaw-lark";
|
|
1054
|
+
const LARK_PLUGIN_NAMES = [LARK_PLUGIN, "feishu-openclaw-plugin"];
|
|
1055
|
+
let LarkPluginAllowRule = class LarkPluginAllowRule extends DiagnoseRule {
|
|
1056
|
+
validate(ctx) {
|
|
1057
|
+
const allow = getAllow(ctx.config);
|
|
1058
|
+
if (LARK_PLUGIN_NAMES.some((name) => allow.includes(name))) return { pass: true };
|
|
1059
|
+
return {
|
|
1060
|
+
pass: false,
|
|
1061
|
+
message: `plugins.allow 缺少飞书插件 (expected one of: ${LARK_PLUGIN_NAMES.join(", ")})`
|
|
1062
|
+
};
|
|
1063
|
+
}
|
|
1064
|
+
repair(ctx) {
|
|
1065
|
+
if (ctx.config.plugins == null || typeof ctx.config.plugins !== "object" || Array.isArray(ctx.config.plugins)) {
|
|
1066
|
+
ctx.config.plugins = { allow: [LARK_PLUGIN] };
|
|
1067
|
+
return;
|
|
1068
|
+
}
|
|
1069
|
+
const pluginsMap = ctx.config.plugins;
|
|
1070
|
+
const rawAllow = pluginsMap.allow;
|
|
1071
|
+
const original = Array.isArray(rawAllow) ? rawAllow : [];
|
|
1072
|
+
const stringAllow = original.filter((e) => typeof e === "string");
|
|
1073
|
+
if (LARK_PLUGIN_NAMES.some((name) => stringAllow.includes(name))) return;
|
|
1074
|
+
original.push(LARK_PLUGIN);
|
|
1075
|
+
pluginsMap.allow = original;
|
|
1076
|
+
}
|
|
1077
|
+
};
|
|
1078
|
+
LarkPluginAllowRule = __decorate([Rule({
|
|
1079
|
+
key: "lark_plugin_allow",
|
|
1080
|
+
dependsOn: ["config_syntax_check"],
|
|
1081
|
+
repairMode: "standard"
|
|
1082
|
+
})], LarkPluginAllowRule);
|
|
1083
|
+
function getAllow(config) {
|
|
1084
|
+
const plugins = config.plugins;
|
|
1085
|
+
if (plugins == null || typeof plugins !== "object" || Array.isArray(plugins)) return [];
|
|
1086
|
+
const allow = plugins.allow;
|
|
1087
|
+
if (!Array.isArray(allow)) return [];
|
|
1088
|
+
return allow.filter((e) => typeof e === "string");
|
|
1089
|
+
}
|
|
1090
|
+
//#endregion
|
|
998
1091
|
//#region src/check.ts
|
|
999
1092
|
function runCheck(input) {
|
|
1000
1093
|
const result = { failedRules: {
|
package/package.json
CHANGED