feat(shell): 插件密码加密、失败熔断与客户端自动更新(v1.11.3)
- 插件配置中 format=password 字段改为 AES-256-GCM 密文落盘(本机密钥,历史明文自动迁移) - 同一插件连续失败 3 次自动禁用(仅统计进程启动后失败),升级自动解除 - 检测到新版本后台下载,空闲窗口提前提示并自动重启升级,设置页可配安全窗口
This commit is contained in:
@@ -19,6 +19,8 @@ const platformAuth = require("./platform-auth");
|
||||
const platformCreds = require("./platform-creds");
|
||||
const sdkResolver = require("./sdk-resolver");
|
||||
const sdkSync = require("./sdk-sync");
|
||||
const localCrypto = require("./local-crypto");
|
||||
const pluginHealth = require("./plugin-health");
|
||||
const { HUB } = require("./hub");
|
||||
const { makeLogger } = require("./logger");
|
||||
|
||||
@@ -229,6 +231,25 @@ function finishRun(runId, plugin, status, error, summary) {
|
||||
peak_mem_mb: run.peak_mem_mb || 0,
|
||||
logs: Array.isArray(run.logs) ? run.logs : [],
|
||||
});
|
||||
// 插件健康熔断:只统计"进程真正跑起来后失败"(run.started 有值);
|
||||
// 入队失败 / SDK 未就绪 / 平台登录失败等前置错误不计入,避免冤枉插件。
|
||||
try {
|
||||
if (status === "done") {
|
||||
pluginHealth.record(plugin.id, true, "");
|
||||
} else if (status === "error" && run.started) {
|
||||
const h = pluginHealth.record(plugin.id, false, error);
|
||||
if (h.tripped) {
|
||||
notifyUser(
|
||||
"插件已自动禁用",
|
||||
`「${run.name || plugin.name || plugin.id}」连续失败 ${h.fails} 次,已停止自动执行;排查后可在场景页手动恢复`,
|
||||
"important"
|
||||
);
|
||||
}
|
||||
}
|
||||
// cancelled(用户取消/排队超时)与 interrupted(客户端退出)不计入插件健康
|
||||
} catch (e) {
|
||||
logger.warning(`插件健康记录失败:${e.message}`);
|
||||
}
|
||||
// 日志集中回传:整次运行日志上送中心机(离线自动暂存补报;失败不阻断运行收尾)
|
||||
try {
|
||||
require("./log-upload").uploadRun({
|
||||
@@ -291,7 +312,8 @@ function loadUiSavedFields(pluginId) {
|
||||
try {
|
||||
const raw = fs.readFileSync(path.join(config.PLUGIN_CONFIG_DIR, `${pluginId}.json`), "utf-8");
|
||||
const v = JSON.parse(raw);
|
||||
return v && typeof v === "object" && !Array.isArray(v) ? v : null;
|
||||
// 密码字段以密文落盘,注入插件前先解密(旧明文数据原样透传)
|
||||
return v && typeof v === "object" && !Array.isArray(v) ? localCrypto.decryptFields(v) : null;
|
||||
} catch (_) {
|
||||
return null; // 无保存配置/损坏:维持空 fields(插件走自身默认值)
|
||||
}
|
||||
@@ -323,6 +345,17 @@ function submitRun(account, plugin, fields, opts) {
|
||||
(!process.env.PYTHON_EXE && !config.pythonEnvRoot() && config.IS_FROZEN)) {
|
||||
throwEnvNotReady();
|
||||
}
|
||||
// 熔断拦截:连续失败到阈值后拒绝执行,避免定时任务每天白跑、失败却无人知晓
|
||||
if (pluginHealth.isTripped(plugin.id)) {
|
||||
const h = pluginHealth.status(plugin.id);
|
||||
throw Object.assign(
|
||||
new Error(
|
||||
`插件「${plugin.name || plugin.id}」连续失败 ${h.fails} 次已自动禁用` +
|
||||
`${h.error ? `(最近错误:${h.error})` : ""},请排查后在场景页点击「恢复」`
|
||||
),
|
||||
{ status: 409 }
|
||||
);
|
||||
}
|
||||
let effFields = fields && typeof fields === "object" && !Array.isArray(fields) ? fields : {};
|
||||
if (Object.keys(effFields).length === 0) {
|
||||
const saved = loadUiSavedFields(plugin.id);
|
||||
|
||||
Reference in New Issue
Block a user